[llvm-dev] Exceptions not working when cross compiling for ARM Cortex M4 with clang and precompiled libraries from ARM GNU GCC Toolchain

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 26 04:07:39 PST 2021


Thanks for the reproducer.

I think I’ve worked out where your GOT entry is coming from. There is a R_ARM_TARGET2 relocation which takes on a different value based on the target. For Linux targets this defaults to R_ARM_GOT_PREL. For embedded systems I think R_ARM_ABS32 is what an embedded build of GNU ld will use.

Can you add -Wl,--target2=abs  to your command line (option is supported by GNU ld and LLD; documented https://sourceware.org/binutils/docs/ld/ARM.html). That should make the GOT unnecessary. Ideally we should add that flag to the bare-metal driver for Arm Targets.

There is a chance that this will make everything magically work. If the unwinder is expecting R_ARM_TARGET2 to be resolved as R_ARM_ABS32 then even if lld correctly resolves R_ARM_GOT_PREL it won’t be what the unwinder is expecting.

My apologies I don’t have a lot of spare time today to try and see if I can spot anything else.

Peter

P.S. I’ve removed the message text from before your previous reply as it exceeded the unmoderated message size limit and I don’t expect too many of them to be around today.

From: Kacper Kowalski <kacper.s.kowalski at gmail.com>
Sent: 26 November 2021 11:21
To: Peter Smith <Peter.Smith at arm.com>
Cc: Eli Friedman <efriedma at quicinc.com>; llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Exceptions not working when cross compiling for ARM Cortex M4 with clang and precompiled libraries from ARM GNU GCC Toolchain

Hello Peter, Eli,

I have linked the binary using the verbose option and could see I was missing "crti.o", "crtbegin.o", "crt0.o", "crtend.o" and "crtn.o" object files. GCC from the ARM GNU GCC Toolchain figures it out on its own for the specific architecture, even if the "-nostdlib" command line is used. "-nostartfiles" prevents it from linking those object files on its own.

After linking "crt*" objects for the Clang build the error recurred. I get the "got" section with one entry and the exceptions are not working properly. I am able to use the same set of arguments for GCC, though, except the "--target" option. Linking the final executable with Clang:

> /home/kacper/Workspace/Aura/device/../build/common_dependencies/llvm-src/bin/clang++ --target=armv7em-none-eabi -Wall -Wextra -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nodefaultlibs --sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -fno-pic -fdata-sections -ffunction-sections -isystem /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/include/c++/10.3.1/ -isystem /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/include/c++/10.3.1//arm-none-eabi/thumb/v7e-m+fp/hard/ -g -Wall -Wextra -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nodefaultlibs --sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -fno-pic  -Wl,--sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -Wl,--gc-sections -Wl,-Map=output.map -Wl,-nostdlib -L/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/lib/thumb/v7e-m+fp/hard/ -L/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard/ -o test_logs_uncaught_exception /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crti.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/lib/thumb/v7e-m+fp/hard/crt0.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtbegin.o CMakeFiles/test_logs_uncaught_exception.dir/test_logs_uncaught_exception.cpp.obj ../../../libdevice_specific.a ../../../cube/libcube.a ../setup/libdevice_test_setup.a ../../../_deps/unity_project-build/libunity.a libtest_logs_uncaught_exception_runner.a ../../../_deps/unity_project-build/libunity.a ../setup/libunity_putchar.a ../../../serial_logger/libserial_logger.a ../../../cube/libcube.a ../../../libfreertos.a ../../../_deps/printf_library-build/lib/libprintf.a -lstdc++ -lm -lc -Wl,--start-group -lgcc -lg -lc -Wl,--end-group -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtend.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtn.o -T/home/kacper/Workspace/Aura/device/cube/Aura/STM32L432KCUx_FLASH.ld

With GCC:

>  /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/bin/arm-none-eabi-g++ --target=armv7em-none-eabi -Wall -Wextra -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nodefaultlibs --sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -fno-pic -fdata-sections -ffunction-sections -isystem /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/include/c++/10.3.1/ -isystem /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/include/c++/10.3.1//arm-none-eabi/thumb/v7e-m+fp/hard/ -g -Wall -Wextra -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nodefaultlibs --sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -fno-pic  -Wl,--sysroot=/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi -Wl,--gc-sections -Wl,-Map=output.map -Wl,-nostdlib -L/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/lib/thumb/v7e-m+fp/hard/ -L/home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard/ -o test_logs_uncaught_exception /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crti.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/arm-none-eabi/lib/thumb/v7e-m+fp/hard/crt0.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtbegin.o CMakeFiles/test_logs_uncaught_exception.dir/test_logs_uncaught_exception.cpp.obj ../../../libdevice_specific.a ../../../cube/libcube.a ../setup/libdevice_test_setup.a ../../../_deps/unity_project-build/libunity.a libtest_logs_uncaught_exception_runner.a ../../../_deps/unity_project-build/libunity.a ../setup/libunity_putchar.a ../../../serial_logger/libserial_logger.a ../../../cube/libcube.a ../../../libfreertos.a ../../../_deps/printf_library-build/lib/libprintf.a -lstdc++ -lm -lc -Wl,--start-group -lgcc -lg -lc -Wl,--end-group -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtend.o /home/kacper/Workspace/Aura/device/../build/common_dependencies/armgnutoolchain-src/lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m+fp/hard//crtn.o -T/home/kacper/Workspace/Aura/device/cube/Aura/STM32L432KCUx_FLASH.ld -nostartfiles

For GCC everything works as expected, for Clang doesn't. Using "-Wl,--reproduce" generates "-Bstatic" file which can be found here:
https://drive.google.com/file/d/1Wvx4JPXpPWefV1AZCp4czWOqCXV3Rukx/view?usp=sharing

I will try to compile libcxx and libcxxabi to be tinier according to Peter's tips and will try to figure out whether aligned allocation could be omitted somehow.

Kind regards,
Kacper


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211126/ebf52ab9/attachment.html>


More information about the llvm-dev mailing list