micmys
micmys

Reputation: 50

Error "__aeabi_unwind_cpp_pr0" while linking for Arm on WSL

Good evening everyone,

I am trying to compile a simple program in Ada for Arm-based microcontroller. I installed gnat-5-arm-linux-gnueabi package on Linux subsystem for Windows.

Now, compiling with arm-linux-gnueabi-gcc-5 -mcpu=cortex-m4 -mthumb program.adb works fine, however linking with arm-linux-gnueabi-ld -T flash.ld -o program.elf program.o results in an error:

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

I have looked through existing solutions, however none of them worked for me. I have tried installing gcc-arm-none-eabi package and using its linker (the same error), as well as using ld (does not recognise arm target).

One of my theories is that I might be using wrong GNAT package or binary, either for compiling or linking. Therefore, if someone knows where to find some descriptions of those, it might also help me :-) (there are quite a few GNAT packages, but only 2 with "arm" in their name)

EDIT: There is a file libgcc_eh.a under /usr/lib/gcc-cross/arm-linux-gnueabi/5/, which contains symbol "unwind"; adding this file to the linker input seems to solve this error, but makes a few new "undefined references" appear:

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'

Upvotes: 2

Views: 1896

Answers (1)

Simon Wright
Simon Wright

Reputation: 25501

When you compile program.adb, the resulting object code will contain references to the runtime system (for, e.g., exception support, text i/o).

The gnat-5-arm-linux-gnueabi package will by default compile for a Linux-based RTS, hence the undefined references.

You could probably get by with this package by specifying an appropriate RTS for your board (--RTS=/where/ever) - if you had one!

I think your best bet for getting started is to download one of the compiler suites from AdaCore]1. This’ll take you to a download page for a host version compatible with your OS; click on the "More packages, platforms, versions and sources" link at the bottom right, and select your platform: either "ARM ELF (hosted on linux)" or "ARM ELF (hosted on windows)".

On Linux, there’s an installation README: (a) you’ll probably need to install as root, (b) the relevant examples are in <installation root>/share/examples/gnat-cross. As I remember, the led-flasher-stm32f4 example is actually for an STM32F429I, which has different and fewer pin assignments for the on-board LEDs! see src/lights.ads.

You should find documentation in <installation root>/share/doc. See gps for the AdaCore IDE, gnat for various components including the Ada Reference Manual (confusingly known as "ARM"), gnat-cross for cross-compilation issues.

Upvotes: 3

Related Questions