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.

Quick summaryHow the linker buckets your code and variables into named regions.

How to think about this

Common linker sections.text — your compiled, executable code (in flash).rodata — const data (in flash).data — initialized globals (template in flash, live copy in RAM).bss — zero-initialized/uninitialized globals (RAM only, no flash…
Common linker sections

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

Three globals that end up in three different sectionsC: edit and run

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.

SectionLives inCosts flash?Costs RAM?
.textFlashYesNo
.rodata (const)FlashYesNo
.data (initialized globals)Flash (template) + RAM (live copy)YesYes
.bss (zeroed globals)RAM onlyNoYes

Try it: tallying a rough flash/RAM budget by section

Adding up simulated section sizesC: edit and run

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?