public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Fengkai Sun <qcloud1014@gmail.com>
To: libc-help@sourceware.org
Subject: Why does dynamic linker search global scope before local scope?
Date: Sun, 27 Jun 2021 22:29:40 +0800	[thread overview]
Message-ID: <CAF6YOcNG2FyGpLrCeGt6cE2jpTeoekKw_ns5mgtSP-N0bAYZ_A@mail.gmail.com> (raw)

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

             reply	other threads:[~2021-06-27 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-27 14:29 Fengkai Sun [this message]
2021-06-27 14:44 ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAF6YOcNG2FyGpLrCeGt6cE2jpTeoekKw_ns5mgtSP-N0bAYZ_A@mail.gmail.com \
    --to=qcloud1014@gmail.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).