dlmopen in LD_PRELOAD

Florian Weimer fweimer@redhat.com
Mon Jun 17 18:40:00 GMT 2019


* Baojun Wang:

> Can `dlmopen` be called in a DSO being `LD_PRELOAD`-ed? The idea is to
> create a minimal DSO used for `LD_PRELOAD`, then inside the DSO
> (.init_array), call `dlmopen` to open the DSO that I'm really interested
> in. hence the DSO being `LD_PRELOAD` acts like a mini loader only.
>
> I did exactly above, but ran into issue (segfault) with stack overflow:

Does the library you load via dlmopen contain its own definition of
malloc, perhaps indirectly?

I expect what happens that with regular LD_PRELOAD, its TLS usage gets
promoted to the static TLS allocation, which is allocated by the dynamic
loader by the bootstrap/minimal malloc.  With the indirection through
dlmopen, dynamic TLS will be allocated with malloc, which does not work
if malloc itself uses dynamic TLS.  You can try to build that malloc
with initial-exec TLS, but dlmopen'ing that could then fail because the
static TLS reserve could be exhausted.

Thanks,
Florian



More information about the Libc-help mailing list