Debugging & Toolchain · Interview question

Explain VMA vs LMA and why .data must be copied at boot.

A strong answer

Every section has two addresses: the VMA (virtual memory address) is where it runs at execution time, and the LMA (load memory address) is where it's stored in the image. For most sections these are the same, code lives in flash and runs from flash, so VMA equals LMA. The .data section, which holds initialized global and static variables, is the exception: those variables must be writable, so at runtime they have to live in RAM (VMA in RAM), but RAM is volatile and powers up with undefined contents, so their initial values can't simply "be there", they must be stored somewhere non-volatile, i.e., flash (LMA in flash). The linker script expresses this with > RAM AT > FLASH, meaning the section's run address is in RAM but its load address is in flash. Because of that split, the startup code at reset must copy the .data section's bytes from its flash load address into its RAM run address before main runs, using the boundary symbols the script provides (_sidata for the flash source, _sdata/_edata for the RAM destination), and separately zero the .bss section. If you forget the AT > FLASH placement or the startup copy, initialized globals come up as garbage because their values were never loaded into RAM. So VMA/LMA is precisely the mechanism that makes int x = 42; actually be 42 at runtime on a device with volatile RAM.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Linker Scripts & Memory Sections

Telling the linker the chip's memory map: MEMORY and SECTIONS place .text in flash and .data/.bss in RAM, and the VMA-vs-LMA split is why startup code must copy initialized data.

More Linker Scripts & Memory Sections questions

Browse all 472 interview questions
Explain VMA vs LMA and why .data must be copied at boot. | EmbeddedPrep.io