# arm-none-eabi-ld：段 .data 的 VMA 0x20000000 与段 .bss 的 VMA 0x20000000 在 RAM 区域重叠

- **ID:** `embedded/arm-gcc-section-overlap-in-ram`
- **领域:** embedded
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ARM GCC 12.3.1 | active | — | — |
| GNU ld 2.40 | active | — | — |
| STM32CubeIDE 1.14.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **Increase RAM size in linker script (e.g., change RAM length from 64K to 128K)** — Overlap is due to address assignment, not insufficient total RAM; increasing size does not separate overlapping addresses. (90% 失败率)
- **Move all variables to .data section by removing __attribute__((section(".bss")))** — This may shift the problem but not resolve the underlying VMA collision; .data and .bss still share same base address. (80% 失败率)
