Bug #6445 Binaries build on 2.6 do not work on 2.4 kernels (bdb mutex/thread/NPTL issue)
Submitted: 4 Nov 2004 22:26 Modified: 11 Jan 2005 17:27
Reporter: Christian Hammers (Silver Quality Contributor) (OCA) Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:4.1.7 OS:Linux (Debian/GNU Linux)
Assigned to: CPU Architecture:Any

[4 Nov 2004 22:26] Christian Hammers
Description:
Selfcompiled binaries build on kernel 2.6 do not work on kernel 2.4 which might become
a problem for distribution packagers (like me).
A binary compiled while running kernel 2.4 works with both kernels.

From what I've read on the Internet there are differences regarding NPLT and LinuxThreads with those kernels...

The only difference in the build log is the following (which is part of the BerkeleyDB
configure output).

--- 4.1-kernel26/log    2004-11-03 22:09:03.000000000 +0100
+++ 4.1-kernel24/log 	2004-11-04 21:29:47.000000000 +0100
@@ -1379,7 +1266,7 @@
 checking for main in -lm... yes
 checking for main in -lsocket... no
 checking for main in -lnsl... yes
-checking for mutexes... POSIX/pthreads/library
+checking for mutexes... x86/gcc-assembly
 checking for getcwd... yes
 checking for getopt... yes
 checking for memcmp... yes
@@ -5685,9 +5572,9 @@
 make[3]: Entering directory `/tmp/buildd/mysql-dfsg-4.1.7/bdb'
 cd build_unix && /usr/bin/make all
 make[4]: Entering directory `/tmp/buildd/mysql-dfsg-4.1.7/bdb/build_unix'
-/bin/sh ./libtool --mode=compile gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc  -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1   ../.././bdb/dist/../mutex/mut_pthread.c
-gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1 ../.././bdb/dist/../mutex/mut_pthread.c -o mut_pthread.o
-echo timestamp > mut_pthread.lo
+/bin/sh ./libtool --mode=compile gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc  -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1   ../.././bdb/dist/../mutex/mut_tas.c
+gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1 ../.././bdb/dist/../mutex/mut_tas.c -o mut_tas.o
+echo timestamp > mut_tas.lo
 /bin/sh ./libtool --mode=compile gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc  -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1   ../.././bdb/dist/../btree/bt_compare.c
 gcc -c -I. -I../.././bdb/dist/.. -I../.././bdb/dist/../dbinc -D_GNU_SOURCE -D_REENTRANT -O3 -DDBUG_OFF -DBIG_JOINS=1 ../.././bdb/dist/../btree/bt_compare.c -o bt_compare.o
 echo timestamp > bt_compare.lo

Later on there's a "-lpthread" in the first variant.

How to repeat:
A mysqld build on a (at least my) host with kernel 2.6.x gives a "[ERROR] bdb: unable to initialize mutex: Function not implemented" error on the same host using kernel 2.4.x.

Suggested fix:
-
[5 Nov 2004 0:37] Christian Hammers
A fix that helps me is below. It's for x86 architecture only, of course...

--- old/configure.orig  2004-11-05 00:33:26.000000000 +0100
+++ new/configure       2004-11-04 23:47:07.000000000 +0100
@@ -36578,7 +36578,7 @@
 
 
       echo "CONFIGURING FOR BERKELEY DB"
-      bdb_conf_flags="--disable-shared"
+      bdb_conf_flags="--disable-shared --with-mutex=x86/gcc-assembly"
       if test $with_debug = "yes"
       then
         bdb_conf_flags="$bdb_conf_flags --enable-debug --enable-diagnostic"
[11 Jan 2005 17:27] Aleksey Kishkin
Checked on slackware, compiled with kernel 2.6.7 and run with kernel 2.4.26. Created a bdb  table and insert one record. All works without problem.

if you have ideas (or even better testcase) what can be a cause of errors you noticed, please post it here and we'll check them.
[11 Jan 2005 17:49] Christian Hammers
Can you provide 
 a) uname -rm
 b) getconf GNU_LIBPTHREAD_VERSION
     to see, which Threads version you kernel is using
 c) your build or at least configure log file? Esp. the line with "checking for mutex" to
     see which variant your build actually contains.
 d) ldd /usr/sbin/mysql | grep thread

For me it's:
  Kernel 2.6: 
   a) 2.6.9-1-k7 i686
   b) NPTL 0.60"
   c) checking for mutexes... x86/gcc-assembly (patched)
      checking for mutexes... POSIX/pthreads/library (unpatched)
   d) libpthread.so.0 => /lib/tls/libpthread.so.0 (symlink to libpthread-0.60.so)
  Kernel 2.4:
    a) 2.4.27-1-k7 i686
    b) linuxthreads-0.10
    c) checking for mutexes... x86/gcc-assembly
    d)  libpthread.so.0 => /lib/libpthread.so.0 (symlink to libpthread-0.10.so)

thanks,
  
-christian-
[11 Jan 2005 18:03] Christian Hammers
ltrace

Attachment: t.ltrace.bz2 (application/octet-stream, text), 40.47 KiB.

[11 Jan 2005 18:04] Christian Hammers
strace

Attachment: t.strace.bz2 (application/octet-stream, text), 5.26 KiB.

[11 Jan 2005 18:06] Christian Hammers
I've just added an strace and ltrace from a crashing mysqld produced with
ltrace -f -s255 -o t.ltrace /usr/sbin/mysqld
strace -f -s255 -o t.strace /usr/sbin/mysqld

In the ltrace you see this interesting part:
2428 strlen("process-private")                                                      = 15
2428 malloc(16)                                                                         = 0x867a1c8
2428 memcpy(0x867a1c8, "process-private", 16)                             = 0x867a1c8
2428 memset(0xbffff550, '\000', 132)                                            = 0xbffff550
2428 malloc(16384)                                                                    = 0x8680490
2428 memset(0x8680490, '\000', 100)                                           = 0x8680490
2428 pthread_mutexattr_init(0xbffff4a8, 0, 100, 0x828bfff, 0)           = 0
2428 pthread_mutexattr_setpshared(0xbffff4a8, 1, 100, 0x828bfff, 0) = 38
2428 pthread_mutexattr_destroy(0xbffff4a8, 1, 100, 0x828bfff, 0)     = 0
2428 sysconf(84, 38, 0xbffff4b8, 0x82a32ab, 0x8680240)                 = 1
2428 strerror(38)                                         = "Function not implemented"

bye,

-christian-