How to properly add a new section in internal RAM without breaking this linker script?

2026-09-08

Stack Overflow: View Question

Tags: c, linker, embedded, advice

Score: 0 | Views: 115

The asker is working on a Cortex-M7 firmware project and needs to introduce a brand-new output section — .new_section — that must live at the very beginning of internal RAM. The existing linker script already places .relocate, .bss, and the stack in RAM, all driven by symbols like _srelocate, _erelocate, and _sstack that the C runtime uses during startup to copy initialised data from flash and zero out BSS.

What makes this interesting is that a linker script is not just a layout description — it is a contract with the startup code. Naively prepending a new section changes the addresses that _srelocate and _sbss resolve to, which can silently break the boot process: the copy loop will write to the wrong place, or BSS clearing will trample your new section. On top of that, the Cortex-M7 has tight rules for the vector table (must be at the start of RAM if remapped) and for MPU-protected regions (base must be aligned to region size).

Direction toward a solution:

Gotchas:

The challenge: Linker scripts are a silent contract with startup code and the MPU — moving one symbol by a few bytes can break boot in ways that only surface after the CPU is already running.

All newsletters