lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Kurz <n...@verse.com>
Subject Re: [lucy-dev] OFFSET globals
Date Tue, 24 Apr 2012 06:01:42 GMT
On Mon, Apr 23, 2012 at 8:38 PM, Marvin Humphrey <marvin@rectangular.com> wrote:
> On Mon, Apr 23, 2012 at 12:49 PM, Nathan Kurz <nate@verse.com> wrote:
>> On Mon, Apr 23, 2012 at 7:55 AM, Marvin Humphrey <marvin@rectangular.com> wrote:
>>> My understanding is that in the event that two ELF DSOs export the same
>>> symbol, the general rule is that the last library loaded wins[1]:
>>
>> I'm pretty sure that at runtime it's the first definition found that
>> wins, which is why LD_PRELOAD can be used to override functions like
>> malloc().
>>
>>>    http://www.akkadia.org/drepper/dsohowto.pdf
>>
>> "Note that there is no problem if the scope contains more than one
>> definition of the same symbol. The symbol lookup algorithm simply
>> picks up the first definition it finds." p.6, 1.5.2
>
> Ah, that's a better quote than the one I found.  Thanks!
>
> This page has more on symbol resolution, and it's a little more approachable
> than the Drepper:
>
>    http://www.bottomupcs.com/libraries_and_the_linker.html
>
>    It is often very useful for a programmer to be able to override a symbol
>    in a library; that is to subvert the normal symbol with a different
>    definition.
>
>    We mentioned that the order that libraries is searched is given by the
>    order of the DT_NEEDED fields within the library. However, it is possible
>    to insert libraries as the last libraries to be searched; this means that
>    any symbols within them will be found as the final reference.
>
>    This is done via an environment variable called LD_PRELOAD which specifies
>    libraries that the linker should load last.

I've yet to figure out how to reconcile these two quotes.  One seems
to say first, and the other says last.  My best guess is that the
Drepper paper is correct (ie, first reference wins) and the "Computer
Science from the Bottom Up" is mistaken.  But I don't have a lot of
basis for this.

1) http://linux.die.net/man/3/dlsym
The definition of RTLD_DEFAULT refers to the "first occurrence", and
"next" would seem to refer to later libraries.

2) It would sad but not unprecedented that "LD_PRELOAD which specifies
 libraries that the linker should load last."  One would hope that
preloads would happen first.

3) Drepper is probably more of an authority than Wienand, the author
of bottomupcs.com.

4) In a fairly recent blog post
(http://www.technovelty.org/linux/pltgot.html) Wienand also says
"LD_PRELOAD, for example, simply tells the dynamic loader it should
insert a library as first to be looked-up for symbols".

I'll try to write to him (Wienand) and see if he can clarify or fix
the text.  Both bottomupcs.com and his blog at technovelty.org seem to
have a lot of useful information.

--nate

Mime
View raw message