ld.so is the UNIX/Linux helper program which loads the shared library files (.so files) needed by dynamically linked programs, and does all the fiddly stuff need to get them to work with the program. Ordinarily you don't have to care at all about ld.so, except that sometimes you want to tell it where to look for .so files, in what order to look for them, and extra libraries that you want to be forced to load.

These are the means of controlling ld.so, in the order that they are used (first to last):

  • The libraries listed in the file /etc/ld.so.preload are loaded first. These libraries can override the functions that are defined in libraries that are loaded later. This file affects every dynamically linked program that runs; ld.so has no affected on statically linked programs.
  • The environmental variable LD_PRELOAD, which acts just like the /etc/ld.so.prelaod file, except that it isn't global. Also, for security reasons, if the program being affected is SETUID or SETGID, the libraries are only loaded if they are in /lib or /usr/lib, plus they have have the proper SETUID/SETGID file permission bits set; the libraries listed in /etc/ld.so.preload are always loaded.

    The libraries in LD_PRELOAD must be separated by spaces (whitespace), and not by colons (":").
  • Libraries are searched searched for in /lib, then /usr/lib.
  • Libraries are searched for in the the directories listed in the colon separated environmental variables LD_LIBRARY_PATH. This is ignored if the program is SETUID or SETGID, for security reasons.
  • Libraries are searched for in the directories listed in the file /etc/ld.so.conf. Actually, the libraries are searched for in the index file /etc/ld.so.cache, which is created when the program ldconfig looks through all the directories listed in /etc/ld.so.conf. If you add any libraries to directories other than /lib or /usr/lib, you will need to run ldconfig.

The program ldd can be used to list which shared libraries a program depends on.