Bug #10638 libmysqlclient_r not built with -fno-common
Submitted: 14 May 2005 5:11 Modified: 19 Jul 2005 23:19
Reporter: Tyler Retzlaff Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S2 (Serious)
Version:4.0 OS:MacOS (Mac OS X 10.3)
Assigned to: Bugs System CPU Architecture:Any

[14 May 2005 5:11] Tyler Retzlaff
Description:
The mysql binary package available from this website containing libmysqlclient_r.a has not been built with -fno-common.  As a result it is not possible to link a shared two-level namespace library against libmysqlclient_r.a

The linker will complain about the following (or similar).

ld: common symbols not allowed with MH_DYLIB output format with the -multi_module option
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_charset (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_open (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_error.o) definition of common _errbuff (size 512)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_static.o) definition of common _my_signals (size 4)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _LOCK_gethostbyname_r (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_KEY_mysys (size 4)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_heap (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_isam (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_keycache (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_lock (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_malloc (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_myisam (size 44)
/usr/local/mysql-max-4.0.24-apple-darwin7.7.0-powerpc/lib/libmysqlclient_r.a(my_thr_init.o) definition of common _THR_LOCK_net (size 44)
/usr/bin/libtool: internal link edit command failed
*** Error code 1

How to repeat:
Use libmysqlclient_r interface in modules that will themselves be built into a dynamic shared library on a Mac OS X >10.1 platform.

So to have a specific example.

gcc -c -fPIC -DPIC myuserofmysqlapi1.c
gcc -c -fPIC -DPIC myuserofmysqlapi2.c

gcc -dynamiclib -o libmylib.dylib myuserofmysqlapi1.o myuserofmysqlapi2.o -lmysqlclient_r

Suggested fix:
Repackaging with the globals (mentioned above) initialized, declared as static or the objects in the archive built with -fno-common should resolve the issue.
[1 Jun 2005 19:21] Matthew Lord
I verified the problem on this machine:
Darwin silverbullet 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC  Power Macintosh powerpc

gcc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)

I ran into the same problem with our standard binaries.  I recompiled this way:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer -fno-common" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -fno-common"  ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --libexecdir=/usr/local/mysql/bin --with-comment="Official MySQL-standard binary" --with-extra-charsets=complex --with-server-suffix="-standard" --enable-thread-safe-client --enable-local-infile  --disable-shared --with-embedded-server --with-innodb 

And I was successful.  Notice the only thing I added was "-fno-common" to the CFLAGS and CXXFLAGS.

I will attach test.c.  The way I tested was this:
gcc -c -fPIC -DPIC -I/usr/local/mysql-standard-4.0.24-apple-darwin7.9.0-powerpc/include test.c
gcc -dynamiclib -L/usr/local/mysql-standard-4.0.24-apple-darwin7.9.0-powerpc/lib -o libmylib.dylib test.o -lmysqlclient_r -lz -lm

The standard binaries were installed in here so you can change the paths above to test with them:
/usr/local/mysql-standard-4.0.24-apple-darwin7.7.0-powerpc
[19 Jul 2005 20:53] Matt Wagner
Thank you for your bug report. This issue has already been fixed
in the latest released version of that product, which you can download at 
http://www.mysql.com/downloads/

Additional info:

We've added -fno-common to the CFLAGS and CXXFLAGS when building on OS X to fix this problem. The 4.1.13 binaries are the first published binaries with this flag added. 4.0 will be fixed with the next release. Thank you!
[19 Jul 2005 23:19] Paul DuBois
Noted in 4.0.25, 4.1.13 changelogs.