Bug #13159 libmysqlclient.a in x86_64 RPM not compiled with -fPIC
Submitted: 13 Sep 2005 22:44 Modified: 9 Jun 2006 18:39
Reporter: Frank Maas (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S1 (Critical)
Version:5.0.13 OS:Linux (Linux, Fedora 4)
Assigned to: Kent Boortz CPU Architecture:Any

[13 Sep 2005 22:44] Frank Maas
Description:
In (at least) the x86_64 RPM set, the library "libmysqlclient.a" is not compiled with -fPIC. This makes it impossible (or maybe just hard) to create a shared object using the library, because the linker complains that "relocation against 'a local symbol' cannot be used".

How to repeat:
Try installing DBD::mysql after correcting the 'libs' var so that it contains -L/usr/lib64/mysql

Suggested fix:
Compile the library with -fPIC
[13 Sep 2005 22:45] Frank Maas
Severity set to serious, because this bug prevents the implementation of tools, libraries and such that depend on MySQL
[14 Sep 2005 21:31] Jorge del Conde
Verified using FC4 / AMD64
[30 Sep 2005 11:38] Frank Maas
Updated version - problem persists in 5.0.13

Workaround (at least for DBD::mysql):
=====
- (after patching mysql_config) create Makefile (perl Makefile.PL)
- edit Makefile, look for -L/usr/lib64/mysql and prepend -L/usr/lib64[space]
- do normal make, make test, make install routine
[2 Dec 2005 23:51] Dmitry Koterov
Same effect. 

gcc  -shared dbdimp.o mysql.o  -o blib/arch/auto/DBD/mysql/mysql.so   -L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm
/usr/bin/ld: /usr/lib64/mysql/libmysqlclient.a(libmysql.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/lib64/mysql/libmysqlclient.a: could not read symbols: Bad value

This bug was fixed in 4.1: http://bugs.mysql.com/bug.php?id=8796 ("From now on - that is from 4.1.11 - static client libraries for x86_64 will be built with -fPIC" - ho-ho). And it welcomes us again in 5.0...

Please correct devel RPMs for x68_64, they are unusable now (at least for Perl DBD::mysql)... work of 4 letters...
[2 Dec 2005 23:54] Dmitry Koterov
Frank, seems to me you workaround does not work... maybe if in /usr/lib64 there are some other libmysqlclient.a, compiled correctly, workaround works, but if there is not - no effect.
[4 Dec 2005 14:49] Dmitry Koterov
Workaround (build from source RPM):

1. Open /usr/lib/rpm/rpmrc
2. Add -fPIC flag in this file (e.g.: "optflags: x86_64 -O2 -fPIC")
3. Run rpmbuild --rebuild http://ftp.citkit.ru/pub/MySQL/Downloads/MySQL-5.0/MySQL-5.0.16-0.src.rpm
(for 5.0.16). Do not forget to install gcc-c++ and other devel tools if they are not installed!
4. Get and install just builded RPMs from /usr/src/redhat/RPMS/x86_64

After that DBD::mysql installs OK.
[24 Apr 2006 13:12] Andrei Nazarenko
See bug #18091 also.

It worked fine for all production versions of 5.0.x until 5.0.20.
Now it is not possible to compile anything against libmysqlclient.a  5.0.20(a).
[2 May 2006 14:58] Andrei Nazarenko
Still the same problem with 5.0.21 x86_64 Linux.
Compilation of PHP fails with the relocation error as before.
[5 May 2006 6:35] Leni Neto
I found a way out to compile Mysql5 and PHP5 on Fedora4 64bits, here is how (hope it helps while we wait for a fix).

First of all remove all Mysql and PHP packages you might have installed.
Then manually remove the /usr/lib64/mysql folder, like this:
rm -f /usr/lib64/mysql
Also, remove the following packages: MyODBC, libdbi-dbd-mysql and mysqlclient10

Now lets recompile with -fPIC
- download MySQL-5.0.21-0.src.rpm from mysql's site (wget will do the job)
# vi /usr/lib/rpm/rpmrc
-Add the -fPIC flag. the line will look like this after you add it
   optflags: i686 -O2 -g -march=i686 -fPIC
# rpmbuild --rebuild
# cd /usr/src/redhat/RPMS/x86_64
#rpm -ihv MySQL-server-5.0.21-0.glibc23.x86_64.rpm
#rpm -ihv MySQL-client-5.0.21-0.glibc23.x86_64.rp
#rpm -ivh MySQL-devel-5.0.21-0.glibc23.x86_64.rpm

Now go to your php source folder and run configure to fit your needs (i have php5 compiled with both mysql and mysqli). 
AFTER configure is done, and BEFORE you start compiling, do this:
#cd /usr/lib64/mysql
#rename .a .a_old *.a
#rename .la .la_old *.la
Now let's get back to install 1 more mysql rpm
# cd /usr/src/redhat/RPMS/x86_64
# rpm -ihv MySQL-shared-5.0.15-0.i386.rpm
OK, now get back to your php source folder, and let's get the job done
# make && make install
PHP5 will now successfully compile (at least mysql wont be a problem anymore).
After its done, lets undo the rename we did before
#cd /usr/lib64/mysql
#rename .a_old .a *.a_old
#rename .la_old .la *.la_old
And its all done!
I had a really bad time getting this to work (and i needed it badly), so i hope this help you guys with similar problems.
Cheers from Brazil to all of you, best of Luck

Leni
[5 May 2006 17:01] Andrei Nazarenko
I also had to recompile MySQL from src.rpm following Dmitry Koterov's advice above. This way I was able to get new libmysqlclient.a which could be used to compile PHP5 successfully.
I really hope this is fixed soon. It is a major pain to mess with all those different libraries versions.
[8 May 2006 13:51] Marcel Kirsch
Same problem here!
I was able to rebuild the source-rpm of 5.0.19, so at least I was able to install MySQL. But now I would like to update to version 5.0.21, and it is not possibl to rebuild the source package.
This is a bug, which should be fixed soon, because it is damn uncomfortable to live with these workarounds.
[29 May 2006 19:51] Valeriy Kravchuk
In fact, bug #18091 is a duplicate of this one (or vice versa). I hope, this will be fixed in 5.0.22.
[6 Jun 2006 12:35] Kent Boortz
All binaries are compiled position independent in
4.1.20 and 5.0.22, and will be in 5.1.11 beta.
[9 Jun 2006 18:39] Paul DuBois
Noted in 4.1.20, 5.0.22, 5.1.11 changelogs.