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

Open
opened 2020-04-17 15:02:57 -05:00 by HinTak · 6 comments
HinTak commented 2020-04-17 15:02:57 -05:00 (Migrated from github.com)

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

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
tpoechtrager commented 2020-04-17 15:08:54 -05:00 (Migrated from github.com)

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

What OS are you on and what compiler do you use?
HinTak commented 2020-04-17 15:14:30 -05:00 (Migrated from github.com)

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?

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?
tpoechtrager commented 2020-04-17 15:25:50 -05:00 (Migrated from github.com)

Arch Linux I suppose? File a pull request please.

[Arch Linux I suppose?](https://git.archlinux.org/svntogit/packages.git/tree/trunk/enable-SSP-and-PIE-by-default.patch?h=packages/clang) File a pull request please.
HinTak commented 2020-04-17 16:33:50 -05:00 (Migrated from github.com)

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.

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.
kiufta commented 2022-09-06 10:04:26 -05:00 (Migrated from github.com)

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
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 ```
HinTak commented 2022-09-06 13:41:32 -05:00 (Migrated from github.com)

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

Sorry haven't revisited this, but apparently I "...add -fPIC to the building of libLLVMSupport.a (this I did).."
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
miles/apple-libtapi#11
No description provided.