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:

>> If so, is there some
>> reasonable method to avoid it? We use this version-script method to
>> ensure that modules that are built for Asterisk do not accidentally
>> expose any symbols to the global namespace unless explicitly allowed,
>> but it appears to be interfering with our use of weak symbols.
> 
>   If you've made it local so that it isn't exposed in the namespace, isn't it
> not going to be able to satisfy any undefined references anyway?  So does it
> matter if it's not weak?

Well, yes. Maybe I'm going about this the wrong way, so I'll explain a
bit of background.

Module test2 may or may not use a function provided by test3; both
modules are loaded at runtime via dlopen(). In the past, without weak
symbols, either both modules had to be loaded (with RTLD_NOW, dlopen()
would fail due to a missing symbol, or with RTLD_LAZY, any access to the
symbol provided by test3 would result in the program exiting due to the
missing symbol), or we had to have some sort of 'registration' mechanism
in the main executable so that test2 would have something to fallback
onto if test3 was not loaded prior to test2 being loaded.

My intent here is that test2 will be able to call this function even if
test3 is not loaded; the 'local', static version in test2 would provide
safe behavior (returning an error code, for example) in that case.
However, if test3 *is* loaded, then when test2 gets loaded, the linker
should override test2's weak definition for that symbol with the strong
definition from test3.

The actual weak symbol in test2 will never be used by any other module;
any module that calls test3's symbol would have its own weak symbol and
aliased-away local implementation of the function. It is possible that I
 misunderstood how this should be done, but I thought that weak symbols
were *always* local to the translation unit they are defined in.

-- 
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]