From: Alan Modra <amodra@gmail.com>
To: Tom Kacvinsky <tkacvins@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: resolving weak symbols.
Date: Sat, 30 Mar 2024 12:13:41 +1030 [thread overview]
Message-ID: <ZgduTeQccipSJwcI@squeak.grove.modra.org> (raw)
In-Reply-To: <CAG_eJLcsR4FAOos9OrwkHC8Eh-0PfUOc=iq+EW=LPXf5W+ejtw@mail.gmail.com>
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
next prev parent reply other threads:[~2024-03-30 1:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 22:58 Tom Kacvinsky
2024-03-30 1:43 ` Alan Modra [this message]
2024-04-12 16:01 ` Nick Clifton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZgduTeQccipSJwcI@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=tkacvins@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).