Bug #24570 Fix udf test in 5.1
Submitted: 24 Nov 2006 12:01 Modified: 14 Sep 2009 7:27
Reporter: Vasil Dimov Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Tests Severity:S3 (Non-critical)
Version:5.1.14-beta BK, 5.0.40 BK OS:FreeBSD (FreeBSD 6.2, 7.0-CURRENT 64-bit)
Assigned to: CPU Architecture:Any
Tags: Contribution

[24 Nov 2006 12:01] Vasil Dimov
Description:
Hi,

I got udf test failing and fixed it:

--- cut ---
$ ./mysql-test-run.pl --mysqld=--binlog-format=mixed --do-test=udf
...
udf                            [ fail ]

Errors are (from /usr/local/devel/mysql/mysql-5.1/mysql-test/var/log/mysqltest-time) :
mysqltest: At line 18: query 'CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"' failed: 1126: Can't open shared library 'udf_example.so' (errno: 2 (null))
(the last lines may be the most important ones)
--- cut ---

Firstly, to get a proper error message we need this fix in order to avoid calling dlerror(3) twice (because the second call returns NULL):

--- sql/sql_udf.cc patch begins here ---
--- mysql-5.1.orig/sql/sql_udf.cc	Fri Nov 10 14:43:48 2006
+++ mysql-5.1/sql/sql_udf.cc	Fri Nov 24 13:34:16 2006
@@ -414,10 +414,11 @@
   {
     if (!(dl = dlopen(udf->dl, RTLD_NOW)))
     {
+      const char *errmsg = dlerror();
       DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)",
-			  udf->dl, errno, dlerror()));
+			  udf->dl, errno, errmsg));
       my_error(ER_CANT_OPEN_LIBRARY, MYF(0),
-               udf->dl, errno, dlerror());
+               udf->dl, errno, errmsg);
       goto err;
     }
     new_dl=1;
--- sql/sql_udf.cc patch ends here ---

Then we get this:

--- cut ---
...
udf                            [ fail ]

Errors are (from /usr/local/devel/mysql/mysql-5.1/mysql-test/var/log/mysqltest-time) :
mysqltest: At line 18: query 'CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"' failed: 1126: Can't open shared library 'udf_example.so' (errno: 2 /usr/local/devel/mysql/mysql-5.1/sql/.libs/udf_example.so: Undefined symbol "safe_mutex_destroy")
(the last lines may be the most important ones)
--- cut ---

safe_mutex_destroy is defined here:

./libmysql_r/.libs/thr_mutex.o:00000000000006c0 T safe_mutex_destroy
./libmysql_r/.libs/libmysqlclient_r.so:0000000000068fb0 T safe_mutex_destroy
./libmysql_r/thr_mutex.o:0000000000000680 T safe_mutex_destroy
./mysys/thr_mutex.o:0000000000000680 T safe_mutex_destroy

So we add libmysqlclient_r.so to the list of libraries required by udf_example.so.
Beware, I am not an automake expert, this may not be the best way to do this:

--- sql/Makefile.am patch begins here ---
--- mysql-5.1.orig/sql/Makefile.am	Mon Nov 20 11:55:07 2006
+++ mysql-5.1/sql/Makefile.am	Fri Nov 24 13:44:26 2006
@@ -183,6 +183,7 @@
 noinst_LTLIBRARIES= udf_example.la
 udf_example_la_SOURCES= udf_example.c
 udf_example_la_LDFLAGS= -module -rpath $(pkglibdir)
+udf_example_la_LIBADD= -lmysqlclient_r -L$(top_builddir)/libmysql_r/.libs
 
 
 # Don't update the files from bitkeeper
--- sql/Makefile.am patch ends here ---

And finally:

--- cut ---
udf                            [ pass ]             39
--- cut ---

How to repeat:
See Description

Suggested fix:
See Description
[24 Nov 2006 12:03] Vasil Dimov
Change "Category" from "Server" to "Server: Tests".
I was unable to select the later in the initial submission.
[24 Nov 2006 12:18] Valeriy Kravchuk
Thank you for a problem report. Please, specify the exact OS and configure command line/build script used.

I was not able to repeat:

openxs@suse:~/work/mysql-5.1/mysql-test> ./mysql-test-run.pl --mysqld=--binlog-
format=mixed --do-test=udf
Logging: ./mysql-test-run.pl --mysqld=--binlog-format=mixed --do-test=udf
MySQL Version 5.1.14
mysql-test-run: WARNING: Could not parse variable list line : ndb-report-thresh-
binlog-epoch-slip3

mysql-test-run: WARNING: Could not parse variable list line : ndb-report-thresh-
binlog-mem-usage10

Using binlog format 'mixed'
Using ndbcluster when necessary, mysqld supports it
Setting mysqld to support SSL connections
Binaries are debug compiled
Killing Possible Leftover Processes
mysql-test-run: *** ERROR(child): can't redirect STDOUT to "/home/openxs/work/my
sql-5.1/mysql-test/var/log/mysqladmin.log": No such file or directory
mysql-test-run: *** ERROR(child): can't redirect STDOUT to "/home/openxs/work/my
sql-5.1/mysql-test/var/log/mysqladmin.log": No such file or directory
mysql-test-run: *** ERROR(child): can't redirect STDOUT to "/home/openxs/work/my
sql-5.1/mysql-test/var/log/mysqladmin.log": No such file or directory
mysql-test-run: *** ERROR(child): can't redirect STDOUT to "/home/openxs/work/my
sql-5.1/mysql-test/var/log/mysqladmin.log": No such file or directory
mysql-test-run: *** ERROR(child): can't redirect STDOUT to "/home/openxs/work/my
sql-5.1/mysql-test/var/log/mysqladmin.log": No such file or directory
Removing Stale Files
Installing Master Database
Installing Master Database
=======================================================
Starting Tests in the 'main' suite

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

udf                            [ pass ]            203
-------------------------------------------------------
Stopping All Servers
All 1 tests were successful.
The servers were restarted 1 times
Spent 0.203 seconds actually executing testcases

on Linux with:

openxs@suse:~/work/mysql-5.1/mysql-test> bk changes | head
ChangeSet@1.2373, 2006-11-23 16:21:53+01:00, mats@romeo.(none) +1 -0
  BUG#24488 (Valgrind warnings on invalid read in mysql_client_binlog_statement)
:
  Disabling debug printouts for valgrind builds that print unallocated memory.
...

built using BUILD/compile-pentium-valgrind-max.
[24 Nov 2006 13:07] Vasil Dimov
Sorry, I missed it again, here it is:

FreeBSD 6.2-PRERELEASE/amd64

$ gcc -v
Using built-in specs.
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 3.4.6 [FreeBSD] 20060305
$

MySQL is compiled with the BUILD/compile-amd64-debug-max script.

Can you provide the output of the following commands:

$ ldd ./sql/.libs/udf_example.so
$ nm ./sql/.libs/udf_example.so |grep safe_mutex_destroy

Thanks
[24 Nov 2006 13:12] Valeriy Kravchuk
OK, I'll try on FreeBSD. I have the following results:

openxs@suse:~/work/mysql-5.1> ldd ./sql/.libs/udf_example.so
        linux-gate.so.1 =>  (0xffffe000)
        libpthread.so.0 => /lib/tls/libpthread.so.0 (0x40018000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x4002a000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x4005c000)
        libm.so.6 => /lib/tls/libm.so.6 (0x40071000)
        libc.so.6 => /lib/tls/libc.so.6 (0x40094000)
        /lib/ld-linux.so.2 (0x80000000)
openxs@suse:~/work/mysql-5.1> nm ./sql/.libs/udf_example.so |grep safe_mutex_destroy
         U safe_mutex_destroy
[24 Nov 2006 14:43] Vasil Dimov
So you also do not have safe_mutex_destroy defined in udf_example.so and do not have mysqlclient_r (which defines it) in the list of libraries referenced by udf_example.so.

But you do not get undefined reference which is strange, because RTLD_NOW is explicitly specified in the dlopen() invocation (sql/sql_udf.cc:415).

Maybe this has something to do with this piece of code in include/my_global.h:

1459 /* FreeBSD 2.2.2 does not define RTLD_NOW) */
1460 #ifndef RTLD_NOW
1461 #define RTLD_NOW 1
1462 #endif

which is totally bogus because both Linux and FreeBSD define RTLD_NOW as 2 and RTLD_LAZY as 1
[24 Nov 2006 14:58] Vasil Dimov
Hi Valeriy,

Just a blind test - can you try compiling MySQL with the following patch on your Linux box:

--- sql/sql_udf.cc	Fri Nov 24 14:08:44 2006
+++ sql/sql_udf.cc.rtld_now	Fri Nov 24 16:55:14 2006
@@ -412,6 +412,9 @@
   }
   if (!(dl = find_udf_dl(udf->dl)))
   {
+#if RTLD_NOW != 2
+#error RTLD_NOW is not 2
+#endif
     if (!(dl = dlopen(udf->dl, RTLD_NOW)))
     {
       const char *errmsg = dlerror();
[30 Dec 2006 13:19] Valeriy Kravchuk
I tried to compile with your patch on Linux (5.1.15-BK), and get no errors at compile time, and the same (pass) result for udf test. 

Will really need to test on FreeBSD 6.1 at least. Sorry, but only next year :) In the meantime you can also try with 5.1.14 (offical binaries for FreeBSD 6.x 64-bit) or with 5.1.15-BK.
[31 Jan 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[21 Apr 2007 16:38] Vasil Dimov
I just encountered the exact same problem on FreeBSD 7.0-CURRENT amd64 with MySQL 5.0.40 sources from BK. MySQL was configured as:

./configure --with-debug=full --with-innodb --prefix=/tmp/inst-5.0

$ ldd ./sql/.libs/udf_example.so.0 ./sql/.libs/udf_example.so.0:
        libcrypt.so.3 => /lib/libcrypt.so.3 (0x800e00000)
        libm.so.4 => /lib/libm.so.4 (0x800f19000)
        libpthread.so.2 => /lib/libpthread.so.2 (0x801035000)

$ nm ./sql/.libs/udf_example.so.0 |grep safe_mutex_destroy
                 U safe_mutex_destroy
$

udf                            [ fail ]

Errors are (from /usr/local/devel/innodb/phantom/mysql-5.0/mysql-test/var/log/mysqltest-time) :
mysqltest: At line 18: query 'CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB"' failed: 1126: Can't open shared library 'udf_example.so' (errno: 2 /usr/local/devel/innodb/phantom/mysql-5.0/sql/.libs/udf_example.so: Undefined symbol "safe_mutex_destroy")
(the last lines may be the most important ones)
Result from queries before failure can be found in r/udf.log

Aborting: udf failed in default mode. To continue, re-run with '--force'.

Here is the patch to fix this on 5.0:

--- ../../../mysql-5.0/sql/Makefile.am	Thu Feb 15 16:05:17 2007
+++ ./Makefile.am	Sat Apr 21 19:18:43 2007
@@ -169,7 +169,7 @@
 # For testing of udf_example.so
 noinst_LTLIBRARIES= udf_example.la
 udf_example_la_SOURCES= udf_example.c
-udf_example_la_LDFLAGS= -module -rpath $(pkglibdir)
+udf_example_la_LDFLAGS= -lmysys -module -rpath $(pkglibdir)
 
 
 # Don't update the files from bitkeeper
[8 Jul 2007 15:31] Valeriy Kravchuk
Please, try to repeat with a newer version, 5.0.46-BK or 5.1.20 just released, and inform about the results.
[8 Aug 2007 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[14 Aug 2009 7:27] Sveta Smirnova
I can not repeat described behavior on BSD box with version 5.1.37. Additionally several bugs in this test were fixed lately. Please try current version 5.1.37 and inform if bug is still repeatable in your environment.
[14 Sep 2009 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".