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

- **ID:** `embedded/linker-section-overlap-ram`
- **领域:** embedded
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

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

## 解决方案

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.
   ```

## 无效尝试

- **** — Simply increasing the RAM region size in the linker script without adjusting the section start addresses may shift the overlap but not resolve it. (65% 失败率)
- **** — Removing the .bss section entirely (by setting all variables to initialized) is not a scalable solution and may cause other linker errors. (80% 失败率)
