Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20221102125627.GD29905@brightrain.aerifal.cx>
Date: Wed, 2 Nov 2022 08:56:28 -0400
From: Rich Felker <dalias@...c.org>
To: guolongqiang <guolongqiang@...wei.com>
Cc: "musl@...ts.openwall.com" <musl@...ts.openwall.com>
Subject: Re: Questions about dlopen

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.