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

微笑、不失礼 提交于 2019-12-02 15:40:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!