Linking #
Memory #
Process memory layout:
Process creation #
Linkers #
- Unix:
ld
- Windows:
LINK.exe
What does it do?
- Combine object files (compiled from source)
- Computes memory layout
- Fix memory addresses
- Produces executable
Problems it has to deal with:
- Assembler doesn’t know where code or data will go in memory
- Makes a guess: Assume sections will be located at
0
, write everything as such
- Makes a guess: Assume sections will be located at
- Assembler doesn’t know addresses of external objects
- Makes a guess: Assume
0
and leave a note for the linker
- Makes a guess: Assume
Object file #
Contains:
- Code and data sections
- Size
- Starting address
- Initial contents
- Symbol table
- Name and location for each of the methods and variables
- Unresolved references: info for linker
- Location of the reference
- What should the reference point to
- Additional info:
- Debugging info
Linking operation #
- Read in section sizes, computes memory layout
- Reads symbols, build symbol table
- Read section data, fix addresses, write executable
Dynamic linking #
- Shared libraries, don’t know locations at link time
At startup, dynamic loader scans jump table (for example, maps printf
to libc.so
)
- Loads file into memory (
mmap
) - Looks up symbols
- Fills address in jump table