This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How should the GNU linker treat weak references?


Alan Modra <amodra@bigpond.net.au> writes:

> main.o with an undef ref to foo
> foo.o with weak define of foo
> libfoo.so with strong define of foo
> 
> Linking these should lead to foo being satisfied by the definition in
> libfoo.so, as I'm sure you'll agree.

No.  Since foo.o is linked in its definition is found first.  Always.
All object files given at the ld command line are unconditionally used.

Note that glibc's ld.so in the moment still has a problem with
handling weak definitions.  Finding a weak definition does not
immediately stop the search but instead a latter strong definition can
overwrite it.  This interpretation of the ELF spec, which is very very
weak in this area, is wrong.  I have already code in place to change
this but cannot do it right away since we need the old behavior as a
work-around for a different problem.


> It gets a little more interesting if libfoo.so isn't included on the ld
> command line.  Suppose we link with just main.o and foo.o (and shared
> libraries such as libc.so and libgcc.so).  Should foo.o then always
> satisfy the reference to foo in main.o?

Yes.

> What if libfoo.so is brought in by ld.so for some other reference,
> say in libc.so?

Doesn't matter, see above.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]