问题
Let's say that libA.so depends on libB.so, libC.so, libD.so. Is there a mapping between the undefined symbols and the required library names:
undefined_symbol_1 comes from libB.so
undefined_symbol_2 comes from libC.so
undefined_symbol_3 comes from libC.so
undefined_symbol_4 comes from libC.so
undefined_symbol_5 comes from libD.so
or are they just kept separately:
Undefined symbols: undefined_symbol_1, undefined_symbol_2, undefined_symbol_3, undefined_symbol_4, undefined_symbol_5;
Required libraries: "libB.so", "libC.so", "libD.so";
System: ubuntu
Tools: g++
回答1:
There is no such mapping in Linux / elf format. The unresolved symbols and required libraries are not dependent.
In fact, you can pre-load (using LD_PRELOAD
) another library that resolves any of the unresolved symbols. This method is often used to replace libc malloc
and friends with another heap implementation without recompiling the executable.
When resolving a symbol the run-time linker walks a list of loaded executables and libraries in the order they were loaded and the first one to resolve the symbol is picked.
Recommended read: How to write shared libraries by Ulrich Drepper.
来源:https://stackoverflow.com/questions/53781204/is-every-undefined-symbol-associated-with-the-library-name-it-comes-from