musl-cross-make
musl-cross-make copied to clipboard
Libs are compiled without `-fPIC` flag
After compilation I found generated libs were not compiled with -fPIC
flag and I don't know where to add it.
The problem is, without the flag, it's not possible to build SOs using any function from any lib, which is necessary for many project, i.e. LLVM. Even the toolchain itself doesn't use or generate any SO, but still we need it to support the usage.
A small test:
a.c
#include <stdio.h>
void f() { printf("hello\n"); }
$ /opt/cross/bin/x86_64-linux-musl-gcc -shared a.c -o liba.so
/opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/bin/ld: /tmp/ccCNRLay.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/lib/libc.a(__stdout_write.o): relocation R_X86_64_32S against symbol `__stdio_write' can not be used when making a shared object; recompile with -fPIC
/opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/bin/ld: /opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/lib/libc.a(ofl.o): relocation R_X86_64_32 against `.bss.ofl_lock' can not be used when making a shared object; recompile with -fPIC
/opt/cross/bin/../lib/gcc/x86_64-linux-musl/6.4.0/../../../../x86_64-linux-musl/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
I had the same issue. I found a solution here: http://www.openwall.com/lists/musl/2017/12/21/1
I simply added this line in my config.mak:
GCC_CONFIG += --enable-default-pie