You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL环境下Arm程序链接出现__aeabi_unwind_cpp_pr0错误求助

Troubleshooting Your Cortex-M4 Ada Linker Error in WSL

Hey there, let's break down why your linking step is failing and how to fix it. The core issue here is likely a mismatch between the toolchain you're using and the bare-metal Cortex-M4 environment you're targeting—plus a few common pitfalls with Ada on microcontrollers.

First: Stop Using arm-linux-gnueabi-ld

The gnat-5-arm-linux-gnueabi package you installed is built for Linux-running ARM devices, not bare-metal microcontrollers like the Cortex-M4. That linker expects to link against Linux system libraries and kernel interfaces, which don't exist on your MCU. Even if you installed gcc-arm-none-eabi, you might still be using the wrong linker binary.

Switch entirely to the bare-metal toolchain's linker: use arm-none-eabi-ld instead of arm-linux-gnueabi-ld for your linking step.

Check Your Linker Script (flash.ld)

Bare-metal MCUs rely entirely on the linker script to define memory layout, and a misconfigured script will throw errors every time. Verify these key points:

  • Memory regions: Make sure you've correctly defined your MCU's FLASH and RAM addresses/sizes (e.g., FLASH : ORIGIN = 0x08000000, LENGTH = 1024K for a typical STM32F4).
  • Entry point: Your script should specify the reset handler (usually Reset_Handler) as the entry point, matching the symbol in your assembly startup file.
  • Section placement: Ensure .text (code) goes to FLASH, .data (initialized variables) is loaded to FLASH and copied to RAM at startup, and .bss (uninitialized variables) is placed in RAM and zeroed out.

Add Critical Startup Files & Ada Runtime Libraries

Ada programs need more than just your application code to run on bare metal:

  1. Assembly startup file: You need a small assembly file to initialize the stack pointer, set up the interrupt vector table, and jump to your Ada main procedure. This file is MCU-specific (e.g., startup_stm32f4xx.s for STM32F4 chips).
  2. Bare-metal Ada runtime: The standard Ada runtime is too heavy for microcontrollers—you need a minimal runtime tailored for Cortex-M4. When using arm-none-eabi-gcc, make sure you link against the bare-metal versions of the Ada runtime, along with GCC support libraries.

Example Correct Workflow

Instead of manually calling gcc and ld, use GNAT's build tools to handle runtime linking automatically. Here's a step-by-step:

# 1. Compile your Ada program with the bare-metal toolchain
arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb program.adb

# 2. Compile your MCU-specific startup file
arm-none-eabi-as -mcpu=cortex-m4 -mthumb startup.s -o startup.o

# 3. Link everything together with the correct linker and script
arm-none-eabi-ld -T flash.ld startup.o program.o -o program.elf -lc -lgcc -lgnat

The -lc, -lgcc, and -lgnat flags pull in the bare-metal C library, GCC support routines, and minimal Ada runtime—all required for your program to run.

Verify Your Toolchain Has Ada Support

Note: Some pre-built gcc-arm-none-eabi packages don't include Ada support by default. If you get errors about missing libgnat.a, you'll need to either:

  • Install a GNAT-specific bare-metal toolchain (like GNAT Community for ARM Bareboard)
  • Compile the Ada cross-toolchain from source for arm-none-eabi in WSL

Final Check

After linking, use arm-none-eabi-objdump to inspect the ELF file and confirm the entry point and memory sections are correctly set:

arm-none-eabi-objdump -h program.elf
arm-none-eabi-objdump -d program.elf | grep Reset_Handler

内容的提问来源于stack exchange,提问作者micmys

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:16:36