A linker script tells the linker where to place each section of your binary in the target's address space. For embedded systems, this is not optional — the hardware is not forgiving about misplaced interrupt vectors.
Basic structure for STM32F4:
MEMORY {
FLASH : ORIGIN = 0x08000000, LENGTH = 1024K
RAM : ORIGIN = 0x20000000, LENGTH = 128K
}
SECTIONS {
.text : {
KEEP(*(.vector_table)) /* Interrupt vector table must be first */
*(.text*) /* All code */
*(.rodata*) /* Read-only data (constants, string literals) */
} > FLASH
.data : {
*(.data*) /* Initialised variables */
} > RAM AT > FLASH /* Stored in FLASH, copied to RAM at startup */
.bss : {
*(.bss*) /* Zero-initialised variables */
} > RAM
.stack (NOLOAD) : {
. = ALIGN(8);
. = . + 4096; /* 4KB stack */
_stack_top = .;
} > RAM
}The startup sequence: Before main() runs, startup code (provided by cortex-m-rt) copies .data from FLASH to RAM and zeroes .bss. The linker script defines the symbols (_data_start, _data_end, _bss_start etc.) that startup code uses to know where to copy from and to.
Cerberus-OS extension: The kernel adds per-task stack regions to the linker script, each aligned to PMP region boundaries (power-of-two, naturally aligned). The linker enforces the memory layout that PMP will enforce at runtime.