Quiz Entry - updated: 2026.07.10
What happens during symbol relocation?
The linker merges the object files' sections, gives each symbol a final address, and patches every reference to point at that address.
* Same-type sections from every object file collapse into one: all code together, all initialized data together, .bss zero-filled. *
The linker:
- Merges sections - combines all .text sections into one, all .data into one
- Assigns addresses - gives each symbol a final memory address
- Patches references - updates all code that references symbols
Before relocation (separate object files):
main.o: swap.o:
main() swap()
buf[2]={1,2} *bufp0=&buf[0]
static *bufp1
After relocation (single executable):
Executable:
Headers
System code
main() ←─┐
swap() ←─┼── .text (merged)
More code ←─┘
System data
buf[2]={1,2} ←─┐
*bufp0=&buf[0] ←─┼── .data (merged)
*bufp1 ←─┘ .bss (zero-initialized)
Go deeper:
Relocation (computing) (Wikipedia) — merging segments, assigning addresses, and fixing up references.