liveBook · Manning

Bss section

As explained in Embedded Software with Rust

The .bss section represents zero-initialized or uninitialized static storage that is cleared during startup.

The .bss section reserves RAM for zero-initialized static storage. It has no load image in FLASH: startup code clears the reserved RAM before application code uses it. section 4.1.1 section 4.1.3

static mut COUNTER: u32 = 0;           // -> .bss
static BUFFER: [u8; 1024] = [0; 1024]; // -> .bss
static FLAG: bool = false;             // -> .bss
static mut X: u32 = 42;                // -> .data
static TABLE: [i32; 3] = [1, 2, 3];    // -> .rodata

These Rust declarations contrast zero-initialized statics in .bss with initialized data in .data and read-only data in .rodata. section 4.1.1

This differs from .data, whose initial values are stored in FLASH and copied to RAM. The reset handler must both copy .data and clear .bss before calling main; otherwise, application code cannot rely on the expected initial values. section 1.2.2 section 4.3.2

.data :
  {
    *(.data .data.*)
  } > RAM AT > FLASH

  .bss (NOLOAD) :
  {
    . = ALIGN(8);
    *(.bss .bss.*)
  } > RAM
}

A linker script can collect .bss inputs into a NOLOAD output section in RAM, with alignment specified before the inputs. section 4.1.3

For a custom startup routine, the linker supplies symbols marking the start and end of .bss. The reset handler uses those boundaries to clear the region. Alternatively, runtime crates such as cortex-m-rt and riscv-rt perform this initialization as part of their startup sequence. section 4.3.2 section 1.3.3

cargo objdump --bin your_app_name -- -h

After building, inspect the section headers to check that .bss is mapped to the intended RAM region. section 4.1.5

How Embedded Software with Rust covers it

How deep it goes
Explains RAM placement, linker mapping, startup clearing, and section-header inspection, with a Rust reset-handler example.
Examples
Uses Rust statics, a linker script, a reset routine, and cargo objdump output to illustrate placement and initialization.
What you can do after
Operate/configure a bare-metal startup layout that reserves and clears .bss, and inspect its placement with cargo objdump.
How it connects
Connects startup initialization with linker scripts, reset handlers, RAM, FLASH, and the .data section.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.