Segment Types
Why This Matters
Not all segments are created equal. Some contain code, some tell the dynamic linker where to find shared libraries, and some carry debugging information. Understanding segment types tells you what each part of the file is for.
A Simple Model
Think of segment types as labels on shipping boxes:
- PT_LOAD — "Load this into memory" (code, data, BSS)
- PT_DYNAMIC — "This has dynamic linker info"
- PT_INTERP — "This is the path to the dynamic linker"
- PT_NOTE — "This has metadata/notes"
- PT_GNU_STACK — "This controls stack permissions"
The Actual Detail
| Type | Value | Purpose |
|---|---|---|
| PT_NULL | 0 | Unused entry |
| PT_LOAD | 1 | Loadable segment — mapped into memory |
| PT_DYNAMIC | 2 | Dynamic linking information |
| PT_INTERP | 3 | Path to interpreter (dynamic linker) |
| PT_NOTE | 4 | Notes (build ID, ABI info) |
| PT_PHDR | 6 | Program header table itself |
| PT_TLS | 7 | Thread-local storage |
| PT_GNU_EH_FRAME | 0x6474e550 | Exception handling frame |
| PT_GNU_STACK | 0x6474e551 | Stack permissions (NX bit) |
| PT_GNU_RELRO | 0x6474e552 | Read-only after relocation |
A typical executable has 2-4 PT_LOAD segments (read-only, read-execute, read-write) plus PT_DYNAMIC, PT_INTERP, PT_NOTE, and PT_GNU_STACK.
A Real Example
$ readelf -l /bin/ls Type Offset VirtAddr Flg What PHDR ... 0x...0040 R Program headers INTERP ... 0x...02b8 R /lib64/ld-linux-x86-64.so.2 LOAD 0x000000 0x0000000000000000 R Read-only (headers) LOAD 0x001000 0x0000000000001000 R E Executable code LOAD 0x003000 0x0000000000003000 R Read-only data LOAD 0x003dc0 0x0000000000004dc0 RW Read-write data DYNAMIC ... 0x...4e28 RW Dynamic section GNU_STACK ... 0x0000000000000000 RW Stack (NX enabled)
Check Your Understanding
Which segment type tells the kernel where the dynamic linker is?
Apply It
If a program has 3 PT_LOAD segments, how many memory regions does the kernel map?
Connect
Segments tell the loader what to load. But how does the loader map file offsets to virtual addresses? That's memory mapping (next concept).