Dynamic library loading inner workings

Andreas Fink andreas.fink85@googlemail.com
Thu Dec 2 22:13:00 GMT 2010

On Thu, 2 Dec 2010 15:24:54 -0500
"Carlos O'Donell" <carlos@systemhalted.org> wrote:

> On Thu, Dec 2, 2010 at 1:07 PM, Andreas Fink
> > Yes I know, that the libraries don't need to be unloaded from memory (as defined in the standard), but on linux they are unloaded,
> > and if they are not unload from memory there is no way to reopen from harddisk!
> Order of library loading matters. Order of library loading changes
> relocation processing ordering. If any relocations are left
> referencing a library it will not be unloaded, otherwise the program
> might crash if it tries to use the relocated reference.
> My first guess would be that there is a relocation that is processed
> and it prevents one of the libraries from being unloaded.
> You can see all of this by running your application with LD_DEBUG=all
> environment variable set.
> Cheers,
> Carlos.

Hello Carlos,

Thanks for the relocation keyword. I tried what you've suggested and I was running it with LD_DEBUG=all. I think this is the line which is interesting:
file=/usr/lib/qt4/libQtGui.so [0];  needed by /usr/lib64/qt4/libQtCore.so.4 [0] (relocation dependency)

Several questions come to my mind:
- Do I understand it correctly, that libQtCore.so needs libQtGui.so, so this is the reason why unloading libQtGui will fail?
- What is a relocation dependency (maybe you have some informative link, couldn't find anything useful with google except the dl-lookup.c)?
- Why can't there be a simple reference counting for dependent libraries (libQtGui needs libQtCore --> increase reference counter, libQtXml needs libQtCore --> increase reference counter, etc)
- Is there any way to make this work in a generic manner (in this case preloading libQtCore would solve it, but what if I have different libraries with the same behaviour)?

Hopefully you'll have some time to answer my questions, since I'm really interested in trying to understand why the linker works as it works.


More information about the Libc-help mailing list