how to build libcrypto.so with gcc 4.8.5 toolchain

I’m trying to build libcrypto.so.1.0.0 on CentOS 7 with gcc 4.8.5 toolchain. I’m getting the error below that I’m not clear what to do with.

/usr/bin/ld: libcrypto.a(e_gost_err.o): relocation R_X86_64_32 against `.data’ can not be used when making a shared object; recompile with -fPIC

Any suggestions?

[user@rsn-xp openssl-1.0.0s]$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

[user@rsn-xp openssl-1.0.0s]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[user@rsn-xp openssl-1.0.0s]$ make libcrypto.so.1.0.0
make[1]: Entering directory `/home/user/src/openssl/openssl-1.0.0s'
make[2]: Entering directory `/home/user/src/openssl/openssl-1.0.0s'
/usr/bin/ld: libcrypto.a(e_gost_err.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
libcrypto.a(e_gost_err.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [link_a.gnu] Error 1
make[2]: Leaving directory `/home/user/src/openssl/openssl-1.0.0s'
make[1]: *** [do_linux-shared] Error 2
make[1]: Leaving directory `/home/user/src/openssl/openssl-1.0.0s'
make: *** [libcrypto.so.1.0.0] Error 2
[user@rsn-xp openssl-1.0.0s]$ 

Solution:

The error is more or less clear on what to do now: recompile with -fPIC. So make sure that -fPIC is included in your CFLAGS (e.g. CFLAGS=-fPIC make ...).
The underlying problem is, that you (most likely unintentionally) try to mix relocatable and not relocatable code.

Advertisements