This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Dynamically loading objects with different link paths in the sameapplication



On Mon, 03 Aug 2009 09:42:51 +0300, Marcus Clyne <maccaday@gmail.com>
wrote:
> Hi,
>
> I have a question regarding dynamic linking.
>
> I'm developing an application that will be loading / unloading many
> shared objects using dlopen, dlsym etc, which I will call the
> 'top-level' shared objects.  The top-level shared objects that I want to
> load will often have libraries that they depend on, and those libraries
> may also have dependencies etc.  When loading each of the top-level
> shared objects, I will wish to specify an LDPATH that will be used for
> loading all the dependencies.  It may be that the dependencies of the
> top-level shared objects (or dependencies of those) will overlap (at
> least in name), but it won't automatically be the case that I'd want
> them to use the same libraries.
>
> What I'd like to know is :
>
> 1) If a library has already been loaded into an application, but using a
> different LPATH to the current one (or perhaps the same LPATH but there
> are newly-created symbolic links on the filesystem that would resolve
> paths to a different location), will the symbols of that loaded library
> automatically be used when resolving the symbols of a newly loaded
> library (or dependencies thereof) without checking whether the symbols
> of libraries that that library required resolve to the same ones based
> on the current LPATH, or will all the symbols be fully re-checked based
> on libraries loaded be checked against the current LPATH and file path
> resolution?

If you open the same inode with dlopen(), you will always get the same
handle. The reference count will be increased, so that dlopen() and
dlclose() calls shall be balanced. It works even if you are using different
paths, at least in principles.

>From http://www.opengroup.org/onlinepubs/9699919799/functions/dlopen.html
| Only a single copy of an object file is brought
| into the address space, even if dlopen()
| is invoked multiple times in reference to the file,
| and even if different pathnames are used to reference the file.

> 2) Can I assume that if the answer to 1 is that they don't resolve to
> the same symbols, that there will be two copies of a particular library
> in memory?  If so, is it just the parts that has different symbol
> resolutions that would be copied (e.g. one or two functions from a
> library that have different symbol resolutions), or will the whole
> library be copied with all the resolved symbols?

This is not applicable.

> 3) If a library is used in two different dynamic loadings, and all the
> symbols resolve to the same symbols, will there be one or two copies of
> the library stored in memory?

There will be only one instance.

--
RÃmi Denis-Courmont
-- 
RÃmi Denis-Courmont


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]