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?


On Mon, Jul 02, 2001 at 12:38:32PM -0700, Ulrich Drepper wrote:
> 
> In
> general, weak references are treated exactly like normal references in
> ld with one exception: weak references for symbols from archives.

Here's somthing I'm not quite clear on.  Consider the following:

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.

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?  What if libfoo.so is brought
in by ld.so for some other reference, say in libc.so?  If the libfoo.so
foo should override foo.o foo even in this case, then ld needs to emit
dynamic relocations for all references to weak syms.  How about the
case where the reference to foo in main.o is weak, and foo.o and
libfoo.so are both left off the ld command line, but libfoo.so is brought
in by ld.so?  Should the undef weak ref be satisfied?

Now, if the answer to the above is that references to weak syms don't
always need dynamic relocs, consider the case where we have

main.o with an undef ref to foo
libbar.so with weak define of foo
libfoo.so with strong define of foo

and similar conditions re. ld command lines.  Why should this be any
different from the first scenario where the weak define of foo was in
a normal object file?

Alan


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