Reputation: 14652
I was reading APUE and see following:
Several more segment types exist in an a.out, containing the symbol table, debugging information, linkage tables for dynamic shared libraries, and the like. These additional sections don’t get loaded as part of the program’s image executed by a process.
But, how does a process find necessary .so
if linkage tables for dynamic shared libraries is not loaded to the program's image?
Upvotes: 0
Views: 325
Reputation: 3302
The dynamic linker is loaded as the program interpreter through the .interp (PT_INTERP
) section added to the program headers during linking.
The dynamic linker reads the DT_NEEDED
ELF tags (added during static linking) to figure out what shared libraries that it needs to resolve.
Finally, on resolving the library deps, from ld.so(8)
:
When resolving library dependencies, the dynamic linker first inspects each dependency string to see if it contains a slash (this can occur if a library pathname containing slashes was specified at link time). If a slash is found, then the dependency string is interpreted as a (relative or absolute) pathname, and the library is loaded using that pathname.
If a library dependency does not contain a slash, then it is searched for in the following order:
(ELF only) Using the directories specified in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated.
Using the environment variable LD_LIBRARY_PATH. Except if the executable is a set-user-ID/set-group-ID binary, in which case it is ignored.
(ELF only) Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present.
From the cache file /etc/ld.so.cache, which contains a compiled list of candidate libraries previously found in the augmented library path. If, however, the binary was linked with the -z nodeflib linker option, libraries in the default library paths are skipped. Libraries installed in hardware capability directories (see below) are preferred to other libraries.
In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped.
Upvotes: 1