ld.so
Load shared libraries for program execution
SYNOPSIS
/lib/ld-linux.so.X [OPTIONS] PROGRAM [ARGUMENTS]
ld.so [OPTIONS] PROGRAM [ARGUMENTS]
PARAMETERS
--list, -l
Lists the dynamic dependencies of the specified executable. This functionality is similar to ldd(1).
--verify, -v
Verifies the dynamic dependencies of the executable without actually executing the program itself.
--library-path PATH
Overrides the default library search path. PATH should be a colon-separated list of directories to search.
--inhibit-rpath LIST
Ignores RPATH/RUNPATH information for the shared objects specified in LIST.
--audit LIST
Specifies a list of shared object auditors to be used by the dynamic linker.
--preload LIST
Preloads shared objects specified in LIST before any other libraries, including libc. Useful for overriding functions.
--argv0 STRING
Sets the argv[0] argument for the executed program to STRING.
--help
Displays a help message showing available options and exits.
--version
Displays version information of the dynamic linker and exits.
DESCRIPTION
ld.so, often symbolically linked to ld-linux.so.X, is the program responsible for loading shared libraries (also known as shared objects or dynamic-link libraries) that an executable requires at runtime. When a dynamically linked program is executed, the Linux kernel first loads ld.so. This linker/loader then takes over, locating all necessary shared libraries, loading them into the program's memory space, and resolving all symbolic references (like function calls and variable accesses) from the executable to the loaded libraries. While not typically invoked directly by users for everyday tasks, it can be manually executed to debug programs, test with custom library versions, or override default system library paths, offering powerful control over the runtime environment.
CAVEATS
ld.so is a critical, low-level component of the Linux operating system. Direct or incorrect manipulation, particularly through environment variables like LD_LIBRARY_PATH, can lead to system instability, security vulnerabilities, or prevent programs from executing correctly. The exact path to ld.so (e.g., /lib/ld-linux.so.2 or /lib64/ld-linux-x86-64.so.2) varies depending on the system's architecture and glibc version. It is generally not advisable for casual users to directly interact with this command.
ENVIRONMENT VARIABLES
ld.so's behavior can be significantly influenced by various environment variables, typically used for debugging or development:
LD_LIBRARY_PATH: A colon-separated list of directories that ld.so searches for shared libraries before the standard system paths. Primarily used for development and testing.
LD_PRELOAD: A space-separated list of shared libraries to be loaded before any other libraries (including libc). Useful for overriding functions in standard libraries or injecting custom code.
LD_DEBUG: If set, enables verbose debugging output from the dynamic linker, showing details about library loading, symbol resolution, and more.
LD_BIND_NOW: If set to a non-null string, the dynamic linker resolves all symbols when the program starts, rather than lazily. This can impact startup time but prevents potential runtime stalls.
LD_TRACE_LOADED_OBJECTS: If set to a non-null string, the program will print its dynamic dependencies and then exit, mimicking the behavior of ldd(1).
CONFIGURATION FILES
The dynamic linker's search paths and other configurations are primarily managed through:
/etc/ld.so.conf: A file that lists directories containing shared libraries. It can also include other configuration files from specified directories.
/etc/ld.so.cache: A compiled binary cache generated by the ldconfig(8) utility based on /etc/ld.so.conf. This cache speeds up the dynamic linker's search for libraries by avoiding filesystem scans.
LIBRARY SEARCH ORDER
When looking for a shared library, ld.so follows a specific search order to find the correct shared object:
1. Libraries specified in the RPATH or RUNPATH of the executable itself (if present).
2. Directories specified in the LD_LIBRARY_PATH environment variable.
3. The cached list of libraries found in /etc/ld.so.cache.
4. The default system library directories, such as /lib, /usr/lib, /lib64, or /usr/lib64.
HISTORY
The concept of dynamic linking predates Linux, offering efficiency benefits by sharing code among multiple applications. In Linux, ld.so is part of the GNU C Library (glibc). Early Linux systems used a different executable format (a.out) with its own dynamic linker. With the adoption of the ELF (Executable and Linkable Format) for binaries, ld-linux.so became the standard dynamic linker/loader. The name ld.so is commonly a symbolic link pointing to the architecture-specific ld-linux.so.X (e.g., ld-linux-x86-64.so.2). Its ongoing development within glibc has consistently focused on performance, security enhancements, and new features like symbol versioning and auditing hooks.