Linker and loader
In short: The linker joins several compiled object files and libraries into one executable program. The operating system’s loader brings this program into memory and starts it.
In more detail: Each source file is compiled separately into machine code with open references (symbols). The linker resolves these references, for example a call to a function from another file. Statically linked libraries are built in permanently, dynamic ones are bound at start or load time.
In Depth
- Static linking: Everything in one file, larger, no run-time dependencies.
- Dynamic linking:
.so/.dll: smaller, shared, but version problems (“DLL hell”). - Position-independent code (PIC) and ASLR: Random load addresses make attacks harder.
- File formats: ELF (Linux), PE (Windows), Mach-O (macOS).
- Symbols: Names of functions and variables. Undefined reference = symbol missing.
- Loader: Maps segments into memory, sets permissions (executable, writable), resolves dynamic references.
- Tools:
ldd,nm,objdump,readelf.
See also: Intermediate representation and compiler optimisation, Virtual memory and paging