embedded build_error ai_generated true

ld: section .data overlaps with .bss in region RAM

ID: embedded/linker-section-overlap-ram

Also available as: JSON · Markdown · 中文
92%Fix Rate
84%Confidence
1Evidence
2024-08-05First Seen

Root Cause

The linker script has incorrect memory region definitions or section placement, causing the .data (initialized data) and .bss (zero-initialized data) sections to overlap in RAM, typically due to misaligned start addresses or insufficient region size.

generic

中文

链接脚本中内存区域定义或段放置错误,导致.data段(已初始化数据)与.bss段(零初始化数据)在RAM中重叠,通常由起始地址未对齐或区域大小不足引起。

Official Documentation

https://sourceware.org/binutils/docs/ld/Scripts.html

Workarounds

  1. 95% success Edit the linker script (e.g., STM32FLASH.ld) to add explicit alignment between .data and .bss. Example: .data : { *(.data) } >RAM AT>FLASH . = ALIGN(4); .bss : { *(.bss) } >RAM
    Edit the linker script (e.g., STM32FLASH.ld) to add explicit alignment between .data and .bss. Example: .data : { *(.data) } >RAM AT>FLASH . = ALIGN(4); .bss : { *(.bss) } >RAM
  2. 88% success Use the --print-memory-usage and --print-map flags to inspect section placement, then adjust the RAM region length to accommodate both sections.
    Use the --print-memory-usage and --print-map flags to inspect section placement, then adjust the RAM region length to accommodate both sections.

中文步骤

  1. Edit the linker script (e.g., STM32FLASH.ld) to add explicit alignment between .data and .bss. Example: .data : { *(.data) } >RAM AT>FLASH . = ALIGN(4); .bss : { *(.bss) } >RAM
  2. Use the --print-memory-usage and --print-map flags to inspect section placement, then adjust the RAM region length to accommodate both sections.

Dead Ends

Common approaches that don't work:

  1. 65% fail

    Simply increasing the RAM region size in the linker script without adjusting the section start addresses may shift the overlap but not resolve it.

  2. 80% fail

    Removing the .bss section entirely (by setting all variables to initialized) is not a scalable solution and may cause other linker errors.