Hello everyone,
So here’s my situation - I am running an RTOS on an embedded system with an ARM Cortex M7. I have a freestanding GCC toolchain built for this target. What I would like to do is cross-compile LLVM to produce only the static runtime libraries: libcxxabi, libcxx, compiler-rt, and libunwind using that toolchain.
Here is my attempt to configure LLVM to get what I want:
#!/bin/bash
mkdir build-arm
cd build-arm
cmake -DCMAKE_TOOLCHAIN_FILE=../arm-toolchain.cmake \
-DCMAKE_CROSSCOMPILING=True \
-DCMAKE_INSTALL_PREFIX=output \
-DLLVM_TABLEGEN=../build-host/bin/llvm-tblgen \
-DCLANG_TABLEGEN=../build-host/bin/clang-tblgen \
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-none-eabi \
-DLLVM_TARGET_ARCH=ARM \
-DLLVM_TARGETS_TO_BUILD=ARM \
-DLLVM_BUILD_STATIC=True \
-DLLVM_ENABLE_PROJECTS="compiler-rt;libcxx;libcxxabi;libunwind" ../llvm
However, this results in the following error:
CMake Error at cmake/modules/CheckAtomic.cmake:56 (message):
Host compiler must support std::atomic!
Call Stack (most recent call first):
cmake/config-ix.cmake:364 (include)
CMakeLists.txt:681 (include)
Is what I’m trying to do supported? Could someone help me chip away at this? I’m really trying to get a full LLVM stack running on this thing!
Any help would be appreciated!
Best,
Anthony
Hello Anthony,
In my experience I've had most success with building the static runtime libraries standalone, i.e. building each library one at a time by pointing cmake at the directory rather than using the integrated build in the top level llvm dir. In my case I do:
compiler-rt built-ins (limited support for sanitizers on a Cortex-M7)
libunwind
libcxxabi
libcxx
Any remaining components of compiler-rt.
There have been posts on llvm-dev about cross-compiling for Arm, hopefully others may be able to share their experiences as well.
Apologies not got a lot of time left today, have to leave the virtual office. Arm does have a recipe for building a LLVM toolchain (initially targeting cortex-m0), this is likely doing both more and less than you want, but it may be possible to get some ideas from it GitHub - ARM-software/LLVM-embedded-toolchain-for-Arm: A project dedicated to build LLVM toolchain for 32-bit Arm embedded targets.
Peter
Thanks Peter!
We are actually already building libcxx and libcxxabi by just bypassing the build system altogether. It’s a little kludgey, so I was trying to just tap into the LLVM build system, and then get to use all the pieces. I started at the top level thinking that was the cleanest way. But if you’ve had success individually driving the CMake in the libraries, I’ll try that instead.
Also, thanks for the reference, that looks relevant.
Best,
Anthony