From http://www.iteedu.com/os/linux/mklinuxdiary/ch4mksystem/4.php
ld-linux.so Find shared libraries in order
One of the glibc installed libraries is ld-linux.so.x, where X is a number and the name is different on different platforms. You can use LDD to view:
#ldd/bin/cat
linux-gate.so.1 => (0x00bfe000)
libc.so.6 => (/lib/libc.so.6) 0x00a4a000
Ld-linux.so.2 (0x00a28000)
The last one that didn't => was. The first one is not the actual library file, you cannot find it, it is a virtual library file for interacting with the kernel.
Ld-linux.so is a library dedicated to finding library files. Cat as an example, cat first told ld-linux.so it needs to libc.so.6 this library file, ld-linux.so will be in a certain order to find Libc.so.6 library and then call the cat.
And how did ld-linux.so find it? In fact, the location of the ld-linux.so is written dead in the program, GCC in compiling the program is written dead in the inside. GCC writes the location of the ld-linux.so in the program can be changed by modifying the GCC spec file. ld-linux.so The order in which the shared libraries are found at run time
(1) ld-linux.so.6 is specified in the executable target file and can be viewed using the readelf command
(2) ld-linux.so.6 is searched by default in/usr/lib and Lib, and when GLIBC is installed to/usr/local, it looks for/usr/local/lib
(3) The path set in the LD_LIBRARY_PATH environment variable
(4) The path specified in/etc/ld.so.conf (or/usr/local/etc/ld.so.conf), which is compiled by the ldconfig generating binary Ld.so.cache , ld-linux.so the order in which the shared libraries are found
(1) The ld-linux.so.6 is set by the GCC spec file
(2) GCC--print-search-dirs print out the path, mainly libgcc_s.so and other libraries. Can be set by Gcc_exec_prefix.
(3) The path set in the LIBRARY_PATH environment variable, or the-l/usr/local/lib specified in the compiled command line
(4) The default search path order set by the LD in Binutils, specified when compiling binutils . (You can pass "LD--verbose | grep search "to view)
(5) The Search path order for binary programs is set in the PATH environment variable. General/usr/local/bin higher than/usr/bin
(6) The search path order of the header files at compile time, similar to the lookup order of the library. General/usr/local/include higher than/usr/include