Home / Learn Embedded C / Linker Sections: .data, .bss and .text
Linker Sections: .data, .bss and .text
How the linker buckets your code and variables into named regions.
How to think about this
What it is
The linker organizes a compiled program into named sections: .text (executable code), .data (initialized globals, copied from flash to RAM at startup), .bss (zero-initialized globals, no flash space needed), and .rodata (const/read-only data).
Why it matters
Understanding these sections explains real numbers you see in a build's size report, and why an uninitialized global costs RAM but no flash, while an initialized one costs both.
Mechanically speaking
At startup, before main() runs, startup code copies .data from flash into RAM and zeroes out .bss — this is part of why embedded programs have "startup code" at all (covered in the Build Systems group).
Shows up in
- Build-size optimization
- Reading build reports
- Startup code
Try it
This sandbox cannot show you the real section sizes, but a real build's "size" report (covered in Build Systems) breaks exactly these three apart.
| Section | Lives in | Costs flash? | Costs RAM? |
|---|---|---|---|
| .text | Flash | Yes | No |
| .rodata (const) | Flash | Yes | No |
| .data (initialized globals) | Flash (template) + RAM (live copy) | Yes | Yes |
| .bss (zeroed globals) | RAM only | No | Yes |
Try it: tallying a rough flash/RAM budget by section
Note data_bytes counts toward BOTH totals: its initial value is stored in flash, and a live writable copy also lives in RAM.
Check yourself
1. Why does an uninitialized global variable cost RAM but essentially no flash?
.bss just records a size to zero out; there is no initial value to store in flash at all.