embedded build_error ai_generated true

ld:段.data与段.bss在RAM区域发生重叠

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

ID: embedded/linker-section-overlap-ram

其他格式: JSON · Markdown 中文 · English
92%修复率
84%置信度
1证据数
2024-08-05首次发现

根因分析

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

English

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

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 65% 失败

    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% 失败

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