resolving weak symbols.
Alan Modra
amodra@gmail.com
Sat Mar 30 01:43:41 GMT 2024
On Thu, Mar 28, 2024 at 06:58:36PM -0400, Tom Kacvinsky wrote:
> HI,
>
> Support I have a static archive libfoo.a that has a weak sym, call it quux.
>
> And the link line I have is
>
> gcc -o foo -L. -lfoo -Wl,--as-needed -lbar -lbaz
>
> Where libbar.so and libbaz.so also have the weak symbol quux.
>
> Then the executable foo has a dynamic dependency on both libbar.so _and_
> libbaz.so.
>
> Is this expected behavior? Is there a way of forcing exactly one of
> libfoo.so and libbaz.so to be used?
Works fine for me on x86_64-linux. You'll notice that I'm not using
gcc to link. Perhaps something in the way your gcc is invoking the
linker is getting in the way. It pays to check what gcc is doing by
adding -v to the gcc command line. It is also worthwhile checking
what you think is going on, by creating a little testcase like the
following.
cat > quux.s <<EOF
.weak quux
.data
quux: .byte 0
EOF
cat > quuxref.s <<EOF
.data
.dc.a quux
EOF
as -o quux.o quux.s
as -o quuxref.o quuxref.s
ld -shared -o lib1.so quux.o
ld -shared -o lib2.so quux.o
ld -o quux quuxref.o --as-needed lib1.so lib2.so
readelf -aW quux | grep NEEDED
ld: warning: type and size of dynamic symbol `quux' are not defined
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000
0x0000000000000001 (NEEDED) Shared library: [lib1.so]
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list