mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: guolongqiang <guolongqiang@huawei.com>
Cc: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: Re: [musl] Questions about dlopen
Date: Wed, 2 Nov 2022 08:56:28 -0400	[thread overview]
Message-ID: <20221102125627.GD29905@brightrain.aerifal.cx> (raw)
In-Reply-To: <d2b3c2be87bc40b19ed0e7c60fcda73d@huawei.com>

On Wed, Nov 02, 2022 at 03:16:56AM +0000, guolongqiang wrote:
> Dear maintainer,
> 
> How does RTLD_LAZY option in dlopen work on musl libc? As I can't
> find any runtime resolve interface.

We intentionally do not have any runtime resolve interface. This is
because, in implementations that do use one, it's historically been a
gigantic source of bugs. This is partly because it runs in an
extremely restricted context where it can't make any assumptions about
availability of locks or having consistent state, and partly because
it has to be able to save and restore the entire register file, even
registers that didn't exist when it was written, because the
application's calling convention might be using them to pass
arguments.

RTLD_LAZY does not carry a contract for dlopen to do lazy resolution,
it just allows it. Originally, we just completely ignored it.

Because some software (notably, X.org server modules) was written to
depend on RTLD_LAZY, commit 6476b8135760659b25c93ff9308425ca98a9e777
introduced a "deferred relocation" feature that behaves the same from
the standpoint of the application. Since the set of available symbols
to bind to only changes when new libraries are loaded with dlopen, it
works like this:

- If RTLD_LAZY was passed to dlopen, missing symbols are not treated
  as an error.

- Instead, the relocations referring to them are saved in a list to be
  reprocessed later.

- After each subsequent dlopen, all these deferred relocation lists
  are re-processed and any relocations referring to symbols that are
  now defined get applied, and removed from the list.

> But I find that we support dlopen5, which depends on caller
> providing a resolve hook.

I know you said in the follow-up to disregard dlopen5. Regarding a
resolve hook, there is no resolve function so nothing to hook. More
broadly, musl does not provide or support any kind of hooking of
internals.

Rich

      parent reply	other threads:[~2022-11-02 12:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02  3:16 guolongqiang
2022-11-02  3:26 ` [musl] 答复: " guolongqiang
2022-11-02 12:56 ` Rich Felker [this message]

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=20221102125627.GD29905@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=guolongqiang@huawei.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).