public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Why does dynamic linker search global scope before local scope?
@ 2021-06-27 14:29 Fengkai Sun
  2021-06-27 14:44 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Fengkai Sun @ 2021-06-27 14:29 UTC (permalink / raw)
  To: libc-help

Hi list,

After reading some LD_DEBUG messages, I've found that the dynamic linker
searches the global scope before the local scope, and the flag
RTLD_DEEPBIND can change this behavior.

I'm really curious about the reason why the dynamic linker won't search the
local scope first by default. To me, the static linker finds out the
dependencies of a DSO, and there is a very high probability that they are
defined in one of the DT_NEEDED entries. One can use the symbols in the
global scope to do interposition, but that is quite rare, so always
searching in the global scope seems tedious.

Currently, LD_PRELOAD is in the global scope, after the main executable.
Though the use of RTLD_DEEPBIND may invalidate the preload semantics, it's
just a design choice. The dynamic linker can search local scope first, and
add LD_PRELOAD somewhere in the local scope.

So I'm wondering why the dynamic linker is designed like this in the first
place.

Thanks for your time.


Best
Fengkai

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-27 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 14:29 Why does dynamic linker search global scope before local scope? Fengkai Sun
2021-06-27 14:44 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).