What does .rodata and -fPIC mean when compiling OpenSSL?

shevy picture shevy · Aug 23, 2014 · Viewed 7k times · Source

I am trying to compile openssl but encountering an error. The CFLAGS in use are:

-O2 -fPIC -fno-strict-overflow

Can someone explain to me please what is .rodata and what the following sentence means?

/usr/bin/ld: libcrypto.a(wp_block.o): relocation R_X86_64_32S against `.rodata'
can not be used when making a shared object; recompile with -fPIC
libcrypto.a(wp_block.o): error adding symbols: Bad value

I am unsure what is libcrypto.a but apparently it is part of openssl.

How could this possibly be fixed?

Answer

jww picture jww · Aug 23, 2014

/usr/bin/ld: libcrypto.a(wp_block.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC libcrypto.a(wp_block.o): error adding symbols: Bad value

Effectively, it means you are building a shared object, but you did not specify -fPIC. PIC is position independent code, and it ensures addresses are relative to the program counter, so the code can be easily relocated (the module's base address can be changed easily and stuff just works).

I believe I've seen this issue on Fedora. Since you claim you are using it in your CFLAGS, try this instead:

$ make clean && make dclean
$ export CFLAGS="-fPIC"
$ ./config shared no-ssl2 ...
$ make
...

The make clean && make dclean will ensure all artifacts (including old object files) are cleaned.

Newer versions of OpenSSL respond to make distclean, not make dclean.


I am unsure what is libcrypto.a but apparently it is part of openssl.

That's the library where OpenSSL places the crypto and helper stuff, like AES, Cameilla, SHA, big integers, etc. libssl.a is where the SSL and TLS stuff goes. libssl.a depends upon libcrypto.a.


Newer version of OpenSSL cannot find their shared libraries after install. Also see Issue 3993, libssl.so.1.1: cannot open shared object file in the OpenSSL bug tracker.

You want to use static linking so the libraries do not break your executable. If so, then you may want to find uses of -lssl and -lcrypto in the Makefiles, and change them to -l:libssl.a and -l:libcrypto.a.