Linking Deep Dive
Symbol resolution semantics and link failure diagnosis: why archive order matters, what SONAME and RUNPATH actually control at load time, and how visibility and linker choice change both ABI surface and link speed.
Overview
From translation units to one address space
Linking is where independently compiled translation units become one address space. A translation unit (TU) is one source file, after preprocessing, compiled on its own. Each TU emitted a symbol table (what it defines, what it references) plus relocation records for every address still to be filled in. The linker binds each undefined reference to exactly one definition, lays out sections, applies relocations and records what must still happen at load time.
The static linker takes three kinds of input. Object files carry symbols and relocations. Archives (.a files) hold object files as members, and the linker pulls those members in lazily. Shared objects (.so files) are not copied in at all. The linker writes an executable that lists the shared libraries it still needs as DT_NEEDED entries, and when the program starts, ld.so finds those libraries and binds their symbols.
Each half of that picture has its own rules, and its own way of failing. The build-time half comes first.
Key concepts
- Strong, weak, and common symbols
- Archive extraction semantics
- SONAME and DT_NEEDED
- PIC and PIE
- RPATH, RUNPATH, LD_LIBRARY_PATH
- Symbol visibility
- Link-time optimization (LTO)
- Linker choice
Interview questions
- You get "undefined reference to symbol X" but X is clearly defined in the codebase. Walk through your diagnosis.
- Explain why link order matters for static archives but not for object files, and what --start-group actually does.
- A binary runs on the build machine and dies at startup on the target with a missing shared library. Walk through the search order and the fix.
- Why does symbol visibility matter for a C++ shared library, and how would you control the export surface?
- Static library or shared library? Argue both sides for a component you ship to other teams.
- Link time dominates our edit-test loop. What do you do, and where does LTO fit?
Sign up free to read the full topic
More DevOps topics
- Kubernetes the Hard Way
- Kubescape and Kubernetes Runtime Security
- Kustomization and Reconciliation
- Lease and Reservation Control Planes
- libstdc++, libc++, glibc and Symbol Versioning
- Lifecycle Hooks and Tests
- Linux Cron & Task Scheduling
- Local Kubernetes Cluster Setup (minikube / kind / k3d)
- Log Aggregation
- Microservices Design
- Migration and Production Patterns
- Monitoring and Troubleshooting
Start free on Cariara · Coding problems · System design studio