0

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

Alexey
  • 710
  • 3
  • 7
  • 19
  • 2
    It depends on the operating system and tools. Some tools may just list all unresolved symbols, and leave you to figure out which libraries you must find and include in your link. Some tools might keep a cached index of which libraries provide which symbols, and give you a hint. – Sam Varshavchik Dec 14 '18 at 14:04
  • Thank you. I'm currently working in the ubuntu + g++. Can you say something about this particular platform? – Alexey Dec 14 '18 at 14:07
  • 1
    Read Drepper's [How to write shared libraries](https://www.akkadia.org/drepper/dsohowto.pdf) – Basile Starynkevitch Dec 14 '18 at 14:23
  • Very interesting article. A lot of reading though... – Alexey Dec 14 '18 at 14:41

1 Answers1

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.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
  • 1
    @Alexey First, the linker must check whether the libraries satisfy all unresolved symbols (unless `--allow-shlib-undefined`). Second, the run-time linker must be instructed which libraries to load at run-time and where from (e.g. `readelf -d /usr/bin/emacs`). – Maxim Egorushkin Dec 14 '18 at 14:55