https://sourceware.org/bugzilla/show_bug.cgi?id=25593

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Richard Biener from comment #0)
> echo 'void foo() {}' > libt.c
> echo 'void foo(); int main() { foo(); }' > t.c
> gcc -o libt.so -shared libt.c -Wl,-soname,libt.so -fPIC -flto
> gcc -c t.c -flto
> gcc -Wl,--as-needed t.o libt.so
> readelf -d a.out | grep NEEDED
>  0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
>  0x0000000000000001 (NEEDED)             Shared library: [libt.so]
> 
> but libc has to come last so the program can use RTLD_NEXT to arrive at
> symbols from libc.  Works fine with gold.

[hjl@gnu-cfl-2 pr25593]$ make 
gcc  -flto   -c -o t.o t.c
gcc  -fPIC   -c -o libt.o libt.c
ld -shared -o libt.so libt.o
gcc  -Wl,--as-needed -o x t.o libt.so
readelf -d x | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libt.so]
[hjl@gnu-cfl-2 pr25593]$ rm libt.so
[hjl@gnu-cfl-2 pr25593]$ make LD=ld.gold 
ld.gold -shared -o libt.so libt.o
gcc  -Wl,--as-needed -o x t.o libt.so
readelf -d x | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libt.so]
[hjl@gnu-cfl-2 pr25593]$ rm libt.so
[hjl@gnu-cfl-2 pr25593]$ make LD=gcc
gcc -shared -o libt.so libt.o
gcc  -Wl,--as-needed -o x t.o libt.so
readelf -d x | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libt.so]
[hjl@gnu-cfl-2 pr25593]$ gcc  -Wl,--as-needed -o x t.o libt.so -fuse-ld=gold
[hjl@gnu-cfl-2 pr25593]$ make
readelf -d x | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libt.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
[hjl@gnu-cfl-2 pr25593]$ 

ld needs to check DT_NEEDED of libt.so.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to