Closed faptc closed 1 week ago
does it still happen if you use -target x86_64-linux-gnu.2.2.5
?
Still it is
> zig cc -target x86_64-linux-gnu.2.2.5 -g ./helloworld.c
> ldd ./a.out
linux-vdso.so.1 (0x0000738ea580b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x0000738ea57ed000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000738ea5400000)
/lib64/ld-linux-x86-64.so.2 (0x0000738ea580d000)
> ./a.out # ok
> patchelf --set-interpreter ./ld-2.23.so --set-rpath ./ a.out
> ./a.out
./a.out: relocation error: ./a.out: symbol system, version GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference
system:
library: libpthread.so
versions: 2.2.5
targets: x86_64-linux-gnu
system:
library: libc.so
versions: 2.2.5
targets: x86_64-linux-gnu
The libpthread symbol is being picked by the linker because it happens to come first:
ld.lld ... /home/alexrp/.cache/zig/o/b6afba54524a1bf7e477237233de72d6/libpthread.so.0 /home/alexrp/.cache/zig/o/b6afba54524a1bf7e477237233de72d6/libc.so.6 ...
The reason you're not seeing the same with Clang or GCC, even with -pthread
, is that, since glibc 2.34, libpthread is empty and just forwards to libc (likewise for libdl, librt, and libutil).
Zig Version
0.14.0-dev.829+2e26cf83c
Steps to Reproduce and Observed Behavior
Given this
helloworld.c
file:Build it with
zig cc
libpthread is always linked to the binary by zig, even with
-no-pthread
option.Expected Behavior
No pthread is linked in this case maybe.
Context
I'm trying to build a .c file with glibc 2.25 or lower. If the binary linked with pthread. I cannot run it locally due to this error:
So for the temporary solution, I viewed ouput of
zig cc -v
and manually run ld.lld withoutlibpthread.o
.