This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: dlopen, RTLD_LOCAL and identically named libraries
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Mark Boorer <markboo99 at gmail dot com>
- Cc: "libc-help at sourceware dot org" <libc-help at sourceware dot org>
- Date: Fri, 29 Aug 2014 11:17:34 -0400
- Subject: Re: dlopen, RTLD_LOCAL and identically named libraries
- Authentication-results: sourceware.org; auth=none
- References: <CAAKyH8y7AwES2S4SFJYnTmAnGDchQv5eB1wNnm-rbA_+XKeRqA at mail dot gmail dot com>
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.