Dynamically loading objects with different link paths in the same application

Marcus Clyne maccaday@gmail.com
Mon Aug 3 07:42:00 GMT 2009


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?

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?

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?


I hope these questions makes sense.  If they don't, then I can give 
examples etc.

I would be grateful for any insight anyone can give me on this.

Thanks,

Marcus Clyne.



More information about the Gcc-help mailing list