Compiling compiler-rt for baremetal CortexM on Ubuntu Linux

Hello,
I want to build LLVM/Compiler-rt for baremetal targets like Cortex-M3. By adopting CMake options from http://llvm.1065342.n5.nabble.com/llvm-dev-Compiling-for-baremetal-ARMv4-on-Ubuntu-Linux-tp124226p124500.html, I can only build “libclang_rt.builtins-x86_64.a” in lib/linux, but what I want to build is “libclang_rt.builtins.arm.a”.

My CMake options are:
cmake -G Ninja DBAREMETAL_ARMV6M_SYSROOT=${ARMEABI5GCC} -DBAREMETAL_ARMV7M_SYSROOT=${ARMEABI5GCC} -DBAREMETAL_ARMV7EM_SYSROOT=${ARMEABI5GCC} -DCMAKE_BUILD_TYPE=Release -C/home/llvm-project/clang/cmake/caches/BaremetalARM.cmake /home/llvm-project/llvm/runtimes/compiler-rt

with
echo $ARMEABI5GCC
/home/gcc-arm-none-eabi-5_4-2016q3/arm-none-eabi

Does anyone know how to fix this problem?
Thanks in advance!
Xia Zhou

Hello,
I want to build LLVM/Compiler-rt for baremetal targets like Cortex-M3. By adopting CMake options from http://llvm.1065342.n5.nabble.com/llvm-dev-Compiling-for-baremetal-ARMv4-on-Ubuntu-Linux-tp124226p124500.html, I can only build "libclang_rt.builtins-x86_64.a" in lib/linux, but what I want to build is "libclang_rt.builtins.arm.a".

My CMake options are:
cmake -G Ninja DBAREMETAL_ARMV6M_SYSROOT=${ARMEABI5GCC} -DBAREMETAL_ARMV7M_SYSROOT=${ARMEABI5GCC} -DBAREMETAL_ARMV7EM_SYSROOT=${ARMEABI5GCC} -DCMAKE_BUILD_TYPE=Release -C/home/llvm-project/clang/cmake/caches/BaremetalARM.cmake /home/llvm-project/llvm/runtimes/compiler-rt

with
echo $ARMEABI5GCC
/home/gcc-arm-none-eabi-5_4-2016q3/arm-none-eabi

Does anyone know how to fix this problem?

I can get you a bit further but it looks like that particular CMake
recipe has bitrotted as it doesn't work at all with the monorepo
layout, and looks like it has some problems even with the old
directory layout.

Going from a monorepo I did the following:
cd /path/to/llvm-project/llvm/runtimes
ln -s /path/to/llvm-project/compiler-rt compiler-rt
cd /path/to/llvm-project/llvm/tools
ln -s /path/to/llvm-project/clang clang
ln -s /path/to/llvm-project/lld lld
cmake -G Ninja DBAREMETAL_ARMV6M_SYSROOT=${ARMEABI5GCC}
-DBAREMETAL_ARMV7M_SYSROOT=${ARMEABI5GCC}
-DBAREMETAL_ARMV7EM_SYSROOT=${ARMEABI5GCC} -DCMAKE_BUILD_TYPE=Release
-C/path/to/llvm-project/clang/cmake/caches/BaremetalARM.cmake
/path/to/llvm-project/llvm

This will attempt to build the builtins for cortex-m, unfortunately it
will fail due to a couple of reasons:
- Several CMAKE variables passed in by the recipe are ignored by the
builtins, which is likely the root cause of the failures.
- The -DCMAKE_SYSROOT= $ARMEABI5GCC is passed through correctly,
unfortunately this doesn't result in a --sysroot=$ARMEABI5GCC being
passed to the compile commands so they fail with can't find stddef.h

I strongly recommend not using the recipe and instead feeding the
CMake for the builtins directly. There is some information in
https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html

Peter

Thanks for the info.