Ld-linux.so find shared libraries in order __linux

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.