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
