Linker Scripts
Purpose
Guide agents through writing and modifying GNU ld linker scripts for embedded targets: MEMORY and SECTIONS commands, VMA vs LMA for code relocation, startup .bss/.data initialization, placing sections in specific regions, and using PROVIDE/KEEP/ALIGN directives.
Triggers
- "How do I write a linker script for my MCU?"
- "How do I place a function in a specific flash/RAM region?"
- "What's the difference between VMA and LMA in a linker script?"
- "How does .bss and .data initialization work at startup?"
- "Linker error: region 'FLASH' overflowed"
- "How do I use weak symbols in a linker script?"
Workflow
1. Linker script anatomy
2. VMA vs LMA
- VMA (Virtual Memory Address): where the section runs at runtime
- LMA (Load Memory Address): where the section is stored in the image (flash)
For .data: stored in flash (LMA), copied to RAM at startup (VMA).
LMA of .data is automatically placed after .text if you use AT(_etext).
3. Startup .bss / .data initialization
The C runtime must copy .data from flash to RAM and zero .bss before main():
Linker script provides _sidata (LMA of .data):
4. Placing code in specific regions
5. KEEP, ALIGN, PROVIDE
6. Weak symbols
7. Common linker errors
For linker script anatomy details, see references/linker-script-anatomy.md [blocked].
Related skills
- Use
skills/embedded/openocd-jtagfor flashing to addresses defined in linker script - Use
skills/embedded/freertosfor FreeRTOS heap placement in specific RAM regions - Use
skills/binaries/linkers-ltofor linker LTO and symbol flags - Use
skills/binaries/elf-inspectionto inspect section sizes and addresses


