Alexey
Alexey

Reputation: 800

Is every undefined symbol associated with the library name it comes from?

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++

Upvotes: 0

Views: 575

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136286

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.

Upvotes: 1

Related Questions