[llvm-dev] Cross Compiling Runtime Libraries with Freestanding Toolchain

405 views
Skip to first unread message

Anthony Merlino via llvm-dev

unread,
Jan 15, 2021, 12:51:23 PM1/15/21
to llvm...@lists.llvm.org
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





Peter Smith via llvm-dev

unread,
Jan 15, 2021, 1:27:23 PM1/15/21
to llvm...@lists.llvm.org, Anthony Merlino
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 https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/

Peter

________________________________________
From: llvm-dev <llvm-dev...@lists.llvm.org> on behalf of Anthony Merlino via llvm-dev <llvm...@lists.llvm.org>
Sent: 15 January 2021 17:51
To: llvm...@lists.llvm.org
Subject: [llvm-dev] Cross Compiling Runtime Libraries with Freestanding Toolchain

Hello everyone,

```
#!/bin/bash

mkdir build-arm
cd build-arm

Best,
Anthony

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Anthony Merlino via llvm-dev

unread,
Jan 15, 2021, 2:05:27 PM1/15/21
to Peter Smith, llvm...@lists.llvm.org
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
Reply all
Reply to author
Forward
0 new messages