Is it possible to recursively populate missing shared objects when calling dlmopen(LM_ID_NEWLM)?

Issue

When a shared library is opened with dlmopen(LM_ID_NEWLM), there are no existing shared libraries in the new namespace so many libraries will crash or at least give unresolved symbols.

Is it possible to load a .so with LM_ID_NEWLM and pull in all of the .so’s that were already linked to the running application?

I could walk /proc/$$/maps and pull them in first, but it seems like that should be unnecessary.

Ideas?

Solution

No, there is no API to copy shared libraries to new namespace from default one. You can either use /proc/self/maps as you suggested or better yet, use dl_iterate_phdr (/proc may not always be mounted).

As a side note, if your library fails to load due to unresolved symbols it means that it should be fixed to include its dependencies.

Answered By – yugr

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published