Enable preloading in dlopen-ed shared libraries?

Adhemerval Zanella adhemerval.zanella@linaro.org
Fri Jul 23 21:00:38 GMT 2021

On 14/07/2021 05:44, Fengkai Sun via Libc-help wrote:
> Hi list,
> As I dive a little deeper into the source code, I found that
> `_dl_map_object_deps' is called in both rtld.c and dl-open.c.
> The semantics of two invocations are both clear: rtld.c makes a call like
> this:
> _dl_map_object_deps (main_map, preloads, npreloads, mode == trace, 0);
> because ld.so needs to preload the libraries specified by LD_PRELOAD into
> the global scope for interposing the symbols.
> dl-open.c makes a call like this:
> _dl_map_object_deps (new, NULL, 0, 0,
>       mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT));
> because no dlopen-ed library needs to preload anything.
> However, I think it might be useful to allow users to preload some
> libraries in the local scope after the map of the dlopen-ed library, just
> like how ld.so treats preloaded libs in global scope.

Do you mean by preloading the shared library list using dlmopen in a new
namespace? Or do you mean to use RTLD_DEEPBIND with the preload libraries?

> By doing so, the user can easily provide a different definition of a symbol
> from the one of the main executable, by enabling RTLD_DEEPBIND.
> This is useful under some circumstances. For example, a dlopen-ed library
> may want to use a separate heap from the main heap, and the user can
> provide another malloc implementation for that library.

But how is this different than the malloc() interposition already supported

> The auditing interface can do the similar thing, but after doing some
> experiments, I found that `la_symbind64' cannot catch the bindings of
> global variables, and it cannot hook all of the function bindings.

The rtld-audit currently only works for symbols which requires a PLT call,
the global variables either done with GOT access directly or through copy
relocations.  I am working on extending la_symbind() to work with bind-now
binaries, so it would be called at loading time in symbol resolution instead
on the lazy binding resolution.

> Would it be a good idea to add an interface to enable preloading in the
> local scope of dlopen-ed shared libraries?

I am trying to understand better what you are trying to do here, because 
you are mixing two different usercases here.  The RTLD_DEEPBIND is usually
used for shared libraries to use its direct dependencies over the global
list, the rtld-audit interfaces are loaded in a different namespace.

It means that symbol interposition for heap functions you described does
not fit with the interfaces: LD_PRELOAD are already taking precedence
over the global scope and using a difference namespace meaning a different

More information about the Libc-help mailing list