This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: Linker version script turning weak symbols into strong symbols


Dave Korn wrote:

> ... and this line from Ulrich Drepper's "How to write shared libraries"(**)
> 
> "  Note that a definition in a DSO being weak has no effects.  Weak
> definitions only play a role in static linking.  "

Well, I don't know how I missed that in my many readings of that
document... but in spite of that, if I don't use the linker version
script it actually works exactly as I wanted it to. I can dlopen()
test2, call into it, and get the test2-local flavor of the function,
then dlclose() test2/dlopen() both test2 and test3, and when I call into
test2, I get the test3 version of the function.

So now I need to figure out if this is an undocumented side effect or
expected behavior I can rely on :-)

To recap:

Main executable (normal, no static linking or anything fancy) has no
definition of 'foo' at all

Shared object number 1 has a weak symbol for 'foo', aliased to
'foo_internal' which is a static function in that object

Shared object number 2 has a normal symbol for foo and provides the
implementation of foo

If the main executable dlopen()s shared object number 2 followed by
shared object number 1, the calls to foo() from object number 1 resolve
to the implementation in object number 2. This is all true if and only
if I don't tell the linker to make all symbols from shared object number
1 'local'; doing so make the weak symbol in that object become strong.

If anyone is interested I'd be happy to provide my small test case for
this; it's tiny and easy to reproduce.

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kpfleming@digium.com
Check us out at www.digium.com & www.asterisk.org


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