Dynamic linker
From Wikipedia, the free encyclopedia
In computing, a dynamic linker is the part of an operating system (OS) that loads and links the shared libraries for an executable when it is run. Such linkers typically also have a shared library that is linked with the executable when it is compiled and may determine the actions of the linker.
Contents |
[edit] Unix and Unix-likes
On Unix and Unix-like operating systems, the dynamic linker shared libraries vary. Two common ones are ld.so on BSD and ld-linux.so on Linux. These typically change their behaviour based on a common set of environment variables, including LD_LIBRARY_PATH and LD_PRELOAD.
LD_PRELOAD instructs the loader to load additional libraries into a program, beyond what was specified when it was compiled. It allows users to add or replace functionality when they run a program and can be used for beneficial purposes, such as implementing userspace virtual file systems or debuggers, or malicious purposes, to run code the program authors didn't intend. For this reason, LD_PRELOAD is often ignored when a program is running setuid and under a few other circumstances. More generally, this technique is called DLL injection.
[edit] Mac OS X
On the Mac OS X operating system, dynamic libraries are stored in a format known as a "dylib" (for dynamically linked/loaded shared library.) These libraries are linked at run-time by Mac OS X's dynamic linker, dyld. At the beginning of every Mac OS X executable (a Mach-O binary) are a set of load commands. If an application needs to use a dynamic library, it specifies in its load commands the dynamic linker to use (always dyld) and the path where the library to be used is most likely located. dyld is called and attempts to find the library specified. If it is not in the expected location, certain other paths are searched (set by the DYLD_LIBRARY_PATH environment variable). If the library is not found there, the application fails and does not launch. After the library is found, dyld will either link the unresolved symbols immediately or only when they are called depending on whether or not lazy linking was specified in the source code of the application. There is currently no way to remove a library from an application once it has been loaded in. However, libraries in Mac OS X are shared between applications - one version of the library is loaded into memory and all applications use it, therefore there is no need to unload a library (as, supposing that another application is using it, which might not in reality be the case in a statistically insignificant number of cases, it will not save resources.)