https://inai.de/documents/Linkers.pdf
Linker data types
- symbols - name + value (static objects in source)
- symbol for each global and static variable in C eg
- references to names in other object files (undefined symbols)
- each symbol is assigned an address, undefined symbols are resolved
- relocations - symbol + offset (+ optional addend)
- contents - what memory should look like when program executes
- machine code (text), data, rdata, bss
Linker steps
- Read input object files + symbols
- Build symbol table
- Decide where contents go in executable
- Read contents and relocations, apply relocations to contents
- Write complete symbol table with final symbol values
(?) ELF loading subsystem on linux - reading
Address spaces
- Load memory address - where program is loaded
- Virtual memory address -where program is when it runs Same on unix, but not in embedded systems (eg load mem → ROM, virt mem → RAM)
Object files
- record oriented - series of records of varying size (eg Mach-O)
- section oriented - section table, symbols appear later or in a special section (ELF) debugging information in object file. ELF → DWARF or stabs strings
Shared Libraries
- Linker does not know what virt address shared lib will run at, hence it must be position independent after dynamic linker has finished loading it.
position independent code in a shared library starts faster and runs slightly slower.
PLT - Procedure Linkage Table GOT - Global Offset Table