在 WSL 上链接 Arm 时出现错误“__aeabi_unwind_cpp_pr0”

Error "__aeabi_unwind_cpp_pr0" while linking for Arm on WSL

大家晚上好,

我正在尝试在 Ada 中为基于 Arm 的微控制器编译一个简单的程序。 我为 Windows.

在 Linux 子系统上安装了 gnat-5-arm-linux-gnueabi

现在,用 arm-linux-gnueabi-gcc-5 -mcpu=cortex-m4 -mthumb program.adb 编译工作正常,但是用 arm-linux-gnueabi-ld -T flash.ld -o program.elf program.o 链接会导致错误:

program.o:(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'

我查看了现有的解决方案,但是 none 对我有用。我已经尝试安装 gcc-arm-none-eabi 包并使用它的链接器(同样的错误),以及使用 ld (不识别 arm 目标)。

我的一个理论是我可能在编译或链接时使用了错误的 GNAT 包或二进制文件。因此,如果有人知道在哪里可以找到这些的一些描述,它也可能对我有帮助:-)(有很多 GNAT 包,但只有 2 个名称中带有 "arm")

编辑:/usr/lib/gcc-cross/arm-linux-gnueabi/5/下有一个文件libgcc_eh.a,其中包含符号"unwind";将此文件添加到链接器输入似乎可以解决此错误,但会出现一些新的 "undefined references":

Incl/libgcc_eh.a(unwind-arm.o): In function 'get_eit_entry':
(.text+0x238): undefined reference to '__exidx_start'
Incl/libgcc_eh.a(unwind-arm.o): In function 'get_eit_entry':
(.text+0x23c): undefined reference to '__exidx_end'
Incl/libgcc_eh.a(unwind-arm.o): In function 'unwind_phase2':
(.text+0x334): undefined reference to 'abort'
Incl/libgcc_eh.a(unwind-arm.o): In function 'unwind_phase2_forced':
(.text+0x424): undefined reference to 'memcpy'
Incl/libgcc_eh.a(unwind-arm.o): In function 'unwind_phase2_forced':
(.text+0x478): undefined reference to 'memcpy'
Incl/libgcc_eh.a(unwind-arm.o): In function '__gnu_Unwind_Resume':
(.text+0x5b8): undefined reference to 'abort'
Incl/libgcc_eh.a(unwind-arm.o): In function '__gnu_Unwind_Resume':
(.text+0x5f4): undefined reference to 'abort'
Incl/libgcc_eh.a(pr-support.o): In function '_Unwind_GetTextRelBase':
(.text+0x4f0): undefined reference to 'abort'

编译 program.adb 时,生成的目标代码将包含对运行时系统的引用(例如,异常支持,文本 i/o)。

gnat-5-arm-linux-gnueabi 包默认编译为基于 Linux 的 RTS,因此存在未定义的引用。

您可以通过为您的开发板指定合适的 RTS (--RTS=/where/ever) 来使用此软件包 - 如果您有的话!

我认为入门的最佳选择是从 AdaCore 下载其中一个编译器套件]1。这会将您带到与您的 OS 兼容的主机版本的下载页面;单击右下角的 "More packages, platforms, versions and sources" link,然后 select 您的平台:"ARM ELF (hosted on linux)" 或 "ARM ELF (hosted on windows)".

在 Linux 上,有一个安装自述文件:(a) 您可能需要以 root 身份安装,(b) 相关示例在 <installation root>/share/examples/gnat-cross 中。我记得,led-flasher-stm32f4 示例实际上是针对 STM32F429I 的,它具有不同且更少的板载 LED 引脚分配!参见 src/lights.ads

您应该在 <installation root>/share/doc 中找到文档。请参阅 gps 了解 AdaCore IDE,gnat 了解各种组件,包括 Ada 参考手册(容易混淆地称为 "ARM"),gnat-cross 了解交叉编译问题。