[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #8 from Ismael Luceno  ---
# For completeness, this is from the glibc system that's otherwise equal to the
musl-libc one:
$ gcc -v test.c -lxml2 2>&1 | awk
'$1~/collect2$/{for(i=1;i<=NF;i++)print$i;exit}'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/collect2
-plugin
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccweSB2s.res
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
--build-id
--eh-frame-hdr
--hash-style=gnu
-m
elf_x86_64
-dynamic-linker
/lib/ld-linux-x86-64.so.2
-pie
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtbeginS.o
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/lib/../lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib
-L/lib/../lib
-L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../..
/tmp/ccQzormI.o
-lxml2
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
-lc
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crtn.o

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #9 from Ismael Luceno  ---
(In reply to Fangrui Song from comment #7)
> -Wl,-t,-y,lzma_end is also useful
> 
> When linking an executable, something like --no-allow-shlib-undefined is the
> default (the opposite allow-shlib-undefine is used when linking a DSO), if
> all of libxml2.so's DT_NEEDED libs are loaded, there can be an undefined
> reference.

# With glibc:
$ gcc test.c -lxml2  -Wl,-t,-y,lzma_end
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtbeginS.o
/tmp/ccDXrw7S.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libxml2.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libc.so
/lib/libc.so.6
/usr/lib/libc_nonshared.a
/lib64/ld-linux-x86-64.so.2
/usr/lib/libc_nonshared.a
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crtn.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld:
/lib/liblzma.so.5: definition of lzma_end

# With musl-libc:
$ gcc test.c -lxml2  -Wl,-t,-y,lzma_end
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginS.o
/tmp/ccnhkcpO.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libc.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crtn.o
/usr/bin/ld: /lib/liblzma.so.5: definition of lzma_end
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_properties_decode@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_code@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_auto_decoder@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_end@XZ_5.0'
collect2: error: ld returned 1 exit status

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread nsz at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #10 from Szabolcs Nagy  ---
> /usr/bin/ld: /lib/liblzma.so.5: definition of lzma_end
...
> /usr/bin/ld:
> /usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so:
> undefined reference to `lzma_end@XZ_5.0'

you need to check the symbol versions and symbol table.

readelf -sW /lib/liblzma.so.5 |grep lzma_end

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

Ismael Luceno  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #11 from Ismael Luceno  ---
Nevermind. The issue was on the libxml2 build.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24836] --as-needed leaves unused direct dependencies

2019-07-30 Thread crusader.mike at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24836

--- Comment #11 from crusader.mike at gmail dot com ---
> ... it would be possible ... a lot of work for little gain
Well, in my case (which I believe isn't very rare) majority of functionality is
locked in a few large static libs (of dubious quality) and all minor tools link
them and (due to various effects) end up having dummy dependencies, forcing me
to package unnecessary libs in deliverables (plus some waste at runtime).
Fixing this is not huge, but nice to have.

In terms of work -- what about associating a counter with every lib, which goes
up for every resolved symbol and goes down for every symbol marked for garbage
collection? At the end -- remove all DT_NEEDED entries with counter at 0. Well,
(since I am ignorant wrt ld implementation) it is probably a dumb idea, so I
'll leave this problem with those who know what they are doing.


> ... to do better than just removing DT_NEEDED entries would basically require 
> iterating the link
What do you mean by "to do better"?


> ... that should help explain the various destructor ...
Thank you, Alan. Now it makes sense.


Can you comment on #7? I.e. why elf executable ends up having large .dynsym
table? is there a way to to trim it down only to stuff used by it's shared
libs? Thank you.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils