tpoechtrager/apple-libtapi

need to build static libs with -fPIC for making a shared object

HinTak opened this issue · 6 comments

This happens during osxcross build, but I assume it should be filed here:

[100%] Linking CXX shared library ../../../../lib/libtapi.so
/usr/bin/ld: ../../../../lib/libLLVMSupport.a(regcomp.c.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../../../../lib/libLLVMSupport.a(regerror.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile
 with -fPIC
/usr/bin/ld: ../../../../lib/libLLVMSupport.a(regexec.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -
fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [projects/libtapi/tools/libtapi/CMakeFiles/libtapi.dir/build.make:157: lib/libtapi.so.6.0.1] Error 1

I suppose there are two answers to this - add -fPIC to the building of libLLVMSupport.a (this I did), or disable the building of shared libtapi.so and make sure the rest works with a static libtapi.a

What OS are you on and what compiler do you use?

That would be clang-9 on x86_64 linux . I have seen the "relocation R_X86_64_32S ... when making a shared object, recompile using -fPIC" in the past. PIC (position-independent code) for everything (including bits from a consistuting static object archive) that goes into a shared library seems quite reasonable?

Arch Linux I suppose? File a pull request please.

Fedora, actually. That Arch Linux patch is interesting - I came across those // ... lines while looking for something else (or maybe this), but never looked any further as they look like c++ comments. I guess llvm/clang must be abusing the c++ comment system and put "functional" comments there.

Anyway, I'll have a better look at that change, and if it is adaptable to fedora in a simple way, I'll make a pull.

Have you found a solution?

[100%] Linking CXX shared library ../../../../lib/libtapi.so
/usr/bin/ld: ../../../../lib/libLLVMSupport.a(PrettyStackTrace.cpp.o): relocation R_X86_64_TPOFF32 against `_ZL20PrettyStackTraceHead' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: failed to set dynamic section sizes: bad value

Sorry haven't revisited this, but apparently I "...add -fPIC to the building of libLLVMSupport.a (this I did).."