What Happens After The Compiler in C++ (How Linking Works)
summary
Walks through real object files and executables produced by Compiler Explorer and inspects them with objdump and readelf, showing raw bytes, relocations (e.g. call E8 with a zero operand patched to -0x21), how the linker lays out .text/.data/.bss/.rodata, why -fPIC changes code shape, how writable globals use a per-process global offset table (GOT) and lazy function resolution uses the procedure linkage table (PLT) with the loader fixing addresses at runtime.
AI-written summary · about
chapters (21)
- 0:00Linking in C++
- 1:25Simple C++ program example
- 3:10Refactoring and compiler output
- 5:37Inspecting object files
- 9:49Linker resolves addresses
- 11:34Understanding relocations
- 17:01Relocations for function calls
- 19:27Linking object files
- 22:57Data access in compiled code
- 27:31Global variables and static storage
- 31:41Static globals need relocations
- 33:10ELF global data sections
- 39:58Static vs dynamic linking
- 41:03Dynamic linking and relocations
- 42:29Shared libraries at load time
- 44:33Global Offset Table (GOT)
- 47:24Role of -fPIC
- 50:15Populating GOT at startup
- 52:21Function calls in shared libraries
- 53:46Lazy loading with PLT/GOT
- 57:37Summary of linking
related talks
24m(Ab)using Compiler Tools
16mMind the Gap (Between Your Code and Your Toolchain)
01h 02m“Everything You Ever Wanted to Know about DLLs”
58mStorage Duration and Linkage in C and C++
37mBehind Enemy Lines - Reverse Engineering C++ in Modern Ages
01h 26mC++ Under the Hood: (Internal Class Mechanisms)
59mHello World From Scratch
01h 27mDangerous Optimizations! in C++ - Part Deux
