The .data section holds initialized writable static data. Its initial values are stored in nonvolatile FLASH, but the data must reside in RAM while the program runs. Before application code uses it, startup code copies those values into RAM. section 4.1.1 section 1.2.2
The load memory address (LMA) identifies the FLASH location holding the initial values; the virtual memory address (VMA) identifies their execution location in RAM. In contrast, .bss occupies RAM and is initialized to zero, while code and read-only data generally remain in FLASH. section 4.1.1
An initialized mutable static
In Rust, `static mut X: u32 = 42;` is an example of data placed in .data. Startup must copy the initial value 42 from FLASH to X’s RAM location before application code uses it. section 4.1.1
A linker script assigns .data to RAM while specifying FLASH as its load region. The startup routine uses linker-exported symbols to locate the FLASH source and the RAM boundaries, copies the data, and then zeroes .bss before transferring control to main. section 4.1.3 section 4.3.2
.data :
{
*(.data .data.*)
} > RAM AT > FLASH
.bss (NOLOAD) :
{
. = ALIGN(8);
*(.bss .bss.*)
} > RAM
}
The linker directives place .data in RAM with a FLASH load address and mark .bss as NOLOAD. section 4.1.3
After building, run `cargo objdump --bin your_app_name -- -h` to inspect section headers. Check that .data has a RAM VMA and a FLASH LMA. Runtime crates such as cortex-m-rt and riscv-rt can perform the copy and .bss initialization instead of requiring a custom reset handler. section 4.1.5 section 1.3.3
Idx Name Size VMA LMA File off Algn 0 .vector_table 00000040 08000000 08000000 00010000 2**2 1 .text 00001a00 08000040 08000040 00010040 2**2 2 .rodata 00000200 08001a40 08001a40 00011a40 2**2 3 .data 00000100 20000000 08001c40 00014000 2**2 4 .bss 00000080 20000100 20000100 00014100 2**2
The example headers show .data with VMA 0x20000000 in RAM and LMA 0x08001c40 in FLASH. section 4.1.5
