Quiz Entry - updated: 2026.07.10
What is the Global Offset Table (GOT) and how is it used?
The Global Offset Table is a per-process table of addresses; PIC code reads each external symbol's real location from it after the dynamic linker fills it in.
* Shared code stays read-only by reaching external data indirectly: it reads the address from the per-process GOT, which the dynamic linker fills in at load. *
Problem: Shared library code doesn't know where external variables are located at compile time.
Solution: Indirect access through GOT:
- Each external symbol gets a GOT entry
- Code references symbols via GOT
- Dynamic linker fills GOT entries at load time
Memory layout:
Library code (.text) - read-only, shared
↓
references
↓
GOT (.got) - read-write, per-process
↓
contains addresses of
↓
External data
Example:
// Library code wants to access external 'buf'
extern int buf[];
int x = buf[0];
Generated PIC code:
# Get GOT base
lea _GLOBAL_OFFSET_TABLE_(%rip), %rbx
# Load address of buf from GOT
mov buf@GOT(%rbx), %rax
# Access buf[0]
mov (%rax), %eax
Tip: The GOT is in the data segment, so each process can have different values (pointing to different memory locations).
Go deeper:
Position-independent code — the GOT (Wikipedia) — how indirect data references keep code shareable.