GCC “Cannot Move Location Counter Backwards” Error: Causes, Meaning, and Fixes
If you work in embedded systems development or handle bare-metal projects, you’ve likely encountered the frustrating GCC “cannot move location counter backwards” error. This warning occurs when the linker cannot place a section at a lower memory address than it has already processed, disrupting your memory address layout.
Understanding this error is essential because it relates to linker script structure, section order, and correct placement of Flash and RAM sections. Even experienced developers can spend hours debugging it. By learning the causes and solutions, you can prevent wasted time, maintain a clean location counter, and ensure that your firmware or low-level projects compile reliably without memory conflicts.
What the Error Means
The cannot move location counter backwards error indicates a mismatch between section placement and memory progression. Essentially, the linker refuses to place a section at a lower memory address than it already processed. This is common when working with custom linker scripts or manually assigned memory addresses in embedded systems. The error often highlights problems in linker script section ordering, where .data, .text, or .bss sections are incorrectly sequenced.

For example, if your .text section starts at 0x08004000 and your .data section is forced to 0x08002000, the linker cannot reverse the location counter. This situation can also arise if manual modification of location counter commands are used incorrectly in scripts. Understanding the forward-only progression of addresses is key to avoiding this error. It is a safety mechanism that preserves the integrity of the memory address layout.
Where This Error Usually Appears
This error is most common in embedded systems development where memory-mapped hardware requires precise placement. Developers working on microcontrollers, ARM boards, or other bare-metal projects often face this issue. Desktop applications rarely trigger this error unless custom memory sections are defined in a linker script.
It also appears in projects that modify the location counter manually or rely on hardcoded addresses. Misplacing sections in Flash and RAM sections or using improper section alignment can lead to immediate failures. This problem becomes more visible when working with linker symbols or splitting memory into multiple segments that require careful ordering. Understanding where the error occurs helps you trace and fix it quickly.
Common Causes of the Error
The most frequent cause is incorrect linker script section ordering. If sections are declared out of memory sequence, the location counter cannot progress logically. Placing .text after .data or .bss in memory triggers the error because addresses must increase sequentially.

Another cause is overlapping memory regions. If two sections share the same space or the memory region is too small for its contents, the linker cannot place them properly. Misused alignment directives in linker scripts or attempting forcing addresses in linker script also leads to the GCC linker error. Careful examination of section order, memory regions, and alignment rules is necessary to avoid these issues.
How to Diagnose the Problem
To diagnose linker script problems, start by examining the error output. The linker usually specifies which section caused the conflict. Next, generate a map file using the -Map=output.map option. This linker map file analysis visually shows section placement in memory and highlights address conflicts.
Check the order of your sections, any manual modification of location counter, and whether memory regions are correctly defined. Comparing Flash vs RAM memory mapping in the map file can reveal overlaps or misalignments. Regularly analyzing these files is critical in embedded project linker issues, helping you pinpoint exact causes and save debugging time.
How to Fix the Error
Fixing this error usually starts with reordering sections in the linker script. Ensure that addresses increase logically from start to end. For example, place .text first in Flash, followed by .data and .bss in RAM.
Avoid forcing addresses in linker script unless absolutely necessary. Instead, rely on defined memory regions and linker symbols to assign addresses dynamically. Check section sizes to confirm they fit within memory limits. Small mistakes in section alignment or overlaps often cause the linker to attempt to move backward, triggering the error. A properly organized linker script prevents these issues.
Best Practices to Avoid the Error
To prevent the cannot move location counter backwards error, always design memory layout carefully. Keep custom linker scripts minimal and well-documented. Define memory regions clearly and avoid unnecessary hardcoded addresses.

Regularly generate map files to visualize memory allocation and verify section ordering. Follow memory layout best practices, such as incremental builds, testing after small script changes, and aligning sections according to hardware requirements. These steps ensure smooth builds in embedded systems development and reduce resolving GCC linker errors time.
Conclusion
The GCC “cannot move location counter backwards” error is a clear indicator of mismanaged memory layout. Understanding location counter explanation, proper linker script section ordering, and careful Flash vs RAM memory mapping are key to resolving it.
By following best practices, analyzing linker map file analysis, and avoiding manual modification of location counter, developers can prevent this error in bare-metal projects. Proper memory planning ensures reliable builds, reduces debugging time, and keeps embedded applications running smoothly.
Meta Description
Learn why GCC “cannot move location counter backwards” occurs, its causes, and effective fixes for embedded and bare-metal projects.
FAQs
GCC cannot move location counter backwards in Mbed OS?
This occurs when the linker script tries to place a section at a lower memory address than the current location counter, often due to misordered sections or overlapping Flash and RAM sections.
GCC cannot move location counter backwards in Mbed?
It happens when linker script section ordering conflicts with memory layout, usually in bare-metal projects or custom memory maps.
Arduino cannot move location counter backwards?
On Arduino, this error appears when manually modifying memory addresses in linker scripts or when section placement in memory violates the forward-only progression rule of the location counter.