3

For any dynamic executable on Linux there is a dynamic linker that stores the current symbol bindings somewhere. So when a new library is loaded it knows whether to bind the symbol or not.

For example when two shared objects contain the same symbol, the first one loaded will bind the symbol and subsequent loads won't rebind the symbol.

So this means there should be a register somewhere in memory that stores the current bindings. How can I access it? What format does it have? How portable is it (what's the chance my program that lists the symbols will work on other computers)?

1 Answer 1

3

The structure holding the list of loaded shared objects is called link_map and is stored inside the dynamic linker (rtld or ld.so, depending on the platform).

AFAIK there is no official standard for it but the most common implementation (glibc) uses the GOT[1] entry to store a pointer to the link map and the PLT stubs passes it to the dynamic symbol resolver (by jumping to the address in GOT[2]).

Here's a great article giving the overview of all this as well as more references to other places:

http://s.eresi-project.org/inc/articles/elf-rtld.txt

I would recommend you installing symbols+sources for glibc and stepping through the dynamic calls in gdb to see how they're resolved, or even just reading the source code "offline".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.