← New search

Other meanings of Dynamic linker

Computer Science

Dynamic linker

A dynamic linker is a program that loads and links shared libraries at runtime, resolving symbols and relocations when a program starts or when libraries are loaded on demand. It is a core component of modern operating systems, enabling code reuse, smaller executables, and runtime extensibility.

1970s
First dynamic linking systems
Origin
ELF
Executable and Linkable Format
Common format
ld.so
Typical Unix dynamic linker
Example
1

Function and operation

The dynamic linker, often invoked as ld.so on Unix-like systems, runs before the main program's entry point. It reads the executable's dynamic section, loads required shared libraries into memory, and resolves symbol references (e.g., function calls) to their definitions in those libraries. This process is called dynamic linking or runtime linking.

It also handles relocations—adjusting addresses in code and data to reflect where libraries are loaded. Modern linkers support lazy binding, where symbol resolution is deferred until the first call, improving startup performance. The linker maintains a global symbol table and uses a hash table for efficient lookup.

2

Historical development

Dynamic linking emerged in the 1960s with systems like Multics, which used dynamic linking for system libraries. Early Unix systems used static linking, but by the 1980s, SunOS introduced shared libraries with a dynamic linker. The ELF format, standardized in the late 1980s, became the basis for most modern Unix-like systems.

Windows uses a similar mechanism with its Portable Executable (PE) format and the ntdll.dll loader. The dynamic linker has evolved to support features like symbol versioning, thread-local storage, and security hardening such as RELRO (RELocation Read-Only) and ASLR (Address Space Layout Randomization).

3

Lesser-known aspects

Beyond basic loading, the dynamic linker supports interposition, allowing a library to override symbols from another, which is used by tools like LD_PRELOAD for debugging or instrumentation. It also handles constructor and destructor functions, executing initialization code in libraries.

On Linux, the dynamic linker can be invoked manually with ld.so to run a program with custom library paths. The dlopen and dlsym functions allow programs to load libraries at runtime and look up symbols, enabling plugin architectures. Some systems use static-pie executables that combine static and dynamic linking for security.

4

Security and performance considerations

Dynamic linking introduces security risks, such as library hijacking via LD_LIBRARY_PATH or LD_PRELOAD. Modern systems mitigate these with secure execution modes, stripping environment variables for setuid programs. RELRO and GOT (Global Offset Table) hardening prevent certain attacks.

Performance overhead is minimal but non-zero; lazy binding reduces startup cost but can cause runtime delays. The linker's hash table and caching (e.g., ld.so.cache) speed up library lookup. On some systems, prelinking precomputes relocations to further reduce startup time.

Glossary

Shared library
A file containing code and data that can be loaded by multiple programs at runtime.
Symbol resolution
The process of matching a symbol reference to its definition in a library.
Relocation
Adjusting addresses in code/data to reflect the actual load address.
Lazy binding
Deferring symbol resolution until the first call to a function.
LD_PRELOAD
An environment variable that forces the dynamic linker to load a specified library before others.

Dynamic linking is a fundamental mechanism in modern operating systems, balancing flexibility and performance.