Manually compile OpenSSL: symbol can not be used w

2019-08-24 10:15发布

问题:

My OpenSSL seems to be too old. And there's no place where they explain how to install a more recent OpenSSL library.

openssl version -a
OpenSSL 1.0.1t  3 May 2016
built on: Fri Mar 30 13:47:53 2018
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx)
compiler: gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/lib/ssl"

When I want to manually install a more recent OpenSSL library, I get this error:

root@mycomputer:/local/install/openssl-1.0.2o# ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib

[...compile stuff...]

make[3]: Entering directory `/local/install/openssl-1.0.2o'
make[4]: Entering directory `/local/install/openssl-1.0.2o'
/usr/bin/ld: libcrypto.a(rsaz_exp.o): relocation R_X86_64_32 against `.rodata' 
    can not be used when making a shared object; recompile with -fPIC
libcrypto.a(rsaz_exp.o): could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[4]: *** [link_a.gnu] Error 1
make[4]: Leaving directory `/local/install/openssl-1.0.2o'
make[3]: *** [do_linux-shared] Error 2
make[3]: Leaving directory `/local/install/openssl-1.0.2o'
make[2]: *** [libcrypto.so.1.0.0] Error 2
make[2]: Leaving directory `/local/install/openssl-1.0.2o'
make[1]: *** [shared] Error 2
make[1]: Leaving directory `/local/install/openssl-1.0.2o/crypto'
make: *** [build_crypto] Error 1

回答1:

The linker error:

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

is saying that the object file rsaz_exp.o in the archive libcrypto.a has not been compiled as Position Independent Code, and it must be to be linked into a shared object. It suggests you recompile that object file with -fPIC. Which would mean rebuilding your libcrypto.a from source, with the -fPIC compilation option.

If you don't want to do that, provide your linkage with a shared libcrypto.so to link against instead.