dlopen, RTLD_LOCAL and identically named libraries

Carlos O'Donell carlos@systemhalted.org
Fri Aug 29 15:17:00 GMT 2014


On Thu, Aug 28, 2014 at 11:54 AM, Mark Boorer <markboo99@gmail.com> wrote:
> I have a question regarding dlopen with RTLD_LOCAL and libraries with
> identical names
>
> I have two versions of a library with the same filename in separate
> directories, and I have two separate "plugins", each linking to one
> version of the library.
>
> plugin1.so -> library1/library.so
> plugin2.so -> library2/library.so

OK. I assume both library.so's have the same SONAME.

> The path to library.so is baked into the RPATH of each plugin, so when
> ran independently, they each call the correct functions. However, when
> I load both plugins one after the other (with RTLD_NOW | RTLD_LOCAL) ,
> only the first version of library.so is used.

As expected.

You have told the OS, by using the same SONAME, that the libraries are
identical.

If the libraries are not identical then they should have distinct
SONAMEs since they are distinct libraries.

> The behaviour is the same if the two versions of library.so share an
> soname as well. It seems as though the basename of the library (or the
> soname) is checked at a global level.
> I would expect that behaviour if library.so was already linked in the
> global scope, but in my case it is not.

That's not how ELF loading works.

> Is this the intended behaviour? I would have thought that RTLD_LOCAL
> would start the library search afresh.

It does, but only for plugin1.so, not for the dependencies.

> Any help/advice would be greatly appreciated :)

Use dlmopen and LM_ID_NEWLM, and tell us how it goes. Those features
aren't all that well exercised, but should do what you want.

I apologize in advance that this is not documented in either the glibc
manual or the linux kernel man pages. I'll try to correct that.

Cheers,
Carlos.



More information about the Libc-help mailing list