embedded build_error ai_generated true

arm-none-eabi-ld: section .data VMA 0x20000000 overlaps section .bss VMA 0x20000000 in region RAM

ID: embedded/arm-gcc-section-overlap-in-ram

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-11-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
ARM GCC 12.3.1 active
GNU ld 2.40 active
STM32CubeIDE 1.14.0 active

Root Cause

Linker script defines .data and .bss sections with overlapping virtual memory addresses in RAM region, typically due to incorrect LMA/VMA alignment or missing section padding.

generic

中文

链接脚本在 RAM 区域中为 .data 和 .bss 段定义了重叠的虚拟内存地址,通常是由于 LMA/VMA 对齐错误或缺少段填充。

Official Documentation

https://gcc.gnu.org/onlinedocs/gcc-12.3.0/gnu_lnk.html

Workarounds

  1. 95% success Edit linker script (.ld file) to add explicit alignment and gap between .data and .bss sections: . = ALIGN(4); .data : { *(.data) } >RAM AT>FLASH; . = ALIGN(4); .bss : { *(.bss) } >RAM; Ensure .bss VMA starts after .data end address, e.g., .bss VMA = .data VMA + SIZEOF(.data) + 4.
    Edit linker script (.ld file) to add explicit alignment and gap between .data and .bss sections: . = ALIGN(4); .data : { *(.data) } >RAM AT>FLASH; . = ALIGN(4); .bss : { *(.bss) } >RAM; Ensure .bss VMA starts after .data end address, e.g., .bss VMA = .data VMA + SIZEOF(.data) + 4.
  2. 90% success Use the linker script's built-in PROVIDE and ASSERT to detect overlap at build time: add ASSERT(SIZEOF(.data) + SIZEOF(.bss) <= LENGTH(RAM), "RAM overflow"); in the script.
    Use the linker script's built-in PROVIDE and ASSERT to detect overlap at build time: add ASSERT(SIZEOF(.data) + SIZEOF(.bss) <= LENGTH(RAM), "RAM overflow"); in the script.

中文步骤

  1. Edit linker script (.ld file) to add explicit alignment and gap between .data and .bss sections: . = ALIGN(4); .data : { *(.data) } >RAM AT>FLASH; . = ALIGN(4); .bss : { *(.bss) } >RAM; Ensure .bss VMA starts after .data end address, e.g., .bss VMA = .data VMA + SIZEOF(.data) + 4.
  2. Use the linker script's built-in PROVIDE and ASSERT to detect overlap at build time: add ASSERT(SIZEOF(.data) + SIZEOF(.bss) <= LENGTH(RAM), "RAM overflow"); in the script.

Dead Ends

Common approaches that don't work:

  1. Increase RAM size in linker script (e.g., change RAM length from 64K to 128K) 90% fail

    Overlap is due to address assignment, not insufficient total RAM; increasing size does not separate overlapping addresses.

  2. Move all variables to .data section by removing __attribute__((section(".bss"))) 80% fail

    This may shift the problem but not resolve the underlying VMA collision; .data and .bss still share same base address.