Is every undefined symbol associated with the libr

2019-03-04 15:44发布

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条回答
We Are One
2楼-- · 2019-03-04 16:22

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.

查看更多
登录 后发表回答