Quiz Entry - updated: 2026.07.14
What is the purpose of the .text, .data, .rodata, and .bss sections?
Programs are split into sections by content type so the OS can give each the right permissions — code read-only and executable, constants read-only, variables writable.
* Each section gets the permissions it needs: code read-only and executable, constants read-only, globals writable; .bss takes no disk space. *
Separating sections is both a security and an efficiency measure: code never needs to be writable, and uninitialized data needn't occupy space in the file.
| Section | Contents | Characteristics |
|---|---|---|
.text |
Machine code | Read-only, executable |
.rodata |
Constants, string literals | Read-only, non-executable |
.data |
Initialized globals | Read-write, non-executable |
.bss |
Uninitialized globals | Read-write, zero-filled, takes no file space |
int initialized = 42; // .data
const char *msg = "hello"; // pointer in .data, string in .rodata
int uninitialized; // .bss
void func() { } // .text
Why it pays off:
- Security: keeping
.textread-only-and-executable (and data non-executable) blocks whole classes of exploits. - Memory:
.bssrecords only a size, not bytes, so a big zero-initialized array costs nothing on disk. - Sharing: read-only
.text/.rodatacan be shared between processes.
Inspect them with objdump -h program or readelf -S program.
Go deeper:
Data segment (Wikipedia) — the .text/.data/.bss roles and permissions.
.bss (Wikipedia) — why .bss records only a size, taking no file space.