How to use `compiler-rt` on 32-bit ARM?

Hi, I’m trying to cross-compile a program to a few Linux architectures, to generate one LTO static binary. To do this I compile llvm, clang, musl, libcxx, libcxxabi, libunwind, compiler-rt, my program’s dependencies, and then my program.

I got it to work for x86_64 and for aarch64. However, for armv7, compiler-rt builds successfully but it doesn’t create a crtbegin object file, so compiling (linking) anything fails. On aarch64, I get a .../lib/linux/clang_rt.crtbegin-aarch64.o file, but there is no equivalent file with armv7.

Is this just something that doesn’t work yet? I understand compiler-rt is a little experimental but I see the documentation mentions that “ARM” is supported. I couldn’t figure out how to use libgcc in this way instead.

Build scripts are here: btdu/ci/docker/llvm-compiler-rt.sh at llvm-musl · CyberShadow/btdu · GitHub


Edit: I see armv7 is in a if(APPLE) block, but arm isn’t. But, arm doesn’t build (error: DMB is only supported on ARMv6+).


Edit: I got it to work by adding -march=armv6.

How does -march=armv6 help with an armv7 build?

I have been using

c_compile_flags=“–target=armv7a-${PRODUCT}-linux-gnueabihf
-mcpu=${CPU}
-mfpu=neon
-m32 -fPIC
-flto=thin
–gcc-toolchain=/opt/${PRODUCT}
–sysroot=${SDK_TARGET_SYSROOT}
-fuse-ld=lld
-Wno-unused-command-line-argument”

cmake -G Ninja -S compiler-rt -B arm-rt
-DCMAKE_BUILD_TYPE=“Release”
-DCMAKE_INSTALL_PREFIX=“/opt/llvm/armv7/${CPU}”
-DCMAKE_AR=“/usr/bin/llvm-ar-${CLANG_VERSION}”
-DCMAKE_ASM_COMPILER_TARGET=“arm-linux-gnueabihf”
-DCMAKE_ASM_FLAGS=“$c_compile_flags”
-DCMAKE_C_COMPILER=“/usr/bin/clang-${CLANG_VERSION}”
-DCMAKE_C_COMPILER_TARGET=“arm-linux-gnueabihf”
-DCMAKE_C_FLAGS=“$c_compile_flags”
-DCMAKE_CXX_COMPILER=“clang+±${CLANG_VERSION}”
-DCMAKE_EXE_LINKER_FLAGS=“-fuse-ld=lld”
-DCMAKE_NM=“/usr/bin/llvm-nm-${CLANG_VERSION}”
-DCMAKE_RANLIB=“/usr/bin/llvm-ranlib-${CLANG_VERSION}”
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
-DCOMPILER_RT_BUILD_BUILTINS=ON
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
-DCOMPILER_RT_BUILD_MEMPROF=OFF
-DCOMPILER_RT_BUILD_PROFILE=OFF
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
-DCOMPILER_RT_BUILD_XRAY=OFF
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON

and my build gives these:

ls lib/arm-linux-gnueabihf
clang_rt.crtbegin.o clang_rt.crtend.o libclang_rt.builtins.a liborc_rt.a

Sorry for the confusion. It helps an “arm” build.

Note that the triple specified in that command in CMAKE_C_COMPILER_TARGET starts with arm-, however --target actually says armv7. If the triple is changed to match, that will cause CMakeLists to not build those object files.

In the end I switched this around and put armv6 in the triple but for compiler-rt I changed the triple to arm-... and put -march=armv6 in cflags.