diff --git a/llvm/docs/HowToCrossCompileBuiltinsOnArm.rst b/llvm/docs/HowToCrossCompileBuiltinsOnArm.rst index 31ead45d052fe..d7759ad8edd06 100644 --- a/llvm/docs/HowToCrossCompileBuiltinsOnArm.rst +++ b/llvm/docs/HowToCrossCompileBuiltinsOnArm.rst @@ -25,12 +25,16 @@ using as many of the LLVM tools as we can, but it is possible to use GNU equivalents. You will need: - * A build of LLVM for the llvm-tools and ``llvm-config``. + * A build of LLVM for the llvm-tools and LLVM CMake files. * A clang executable with support for the ``ARM`` target. - * compiler-rt sources. + * ``compiler-rt`` sources. * The ``qemu-arm`` user mode emulator. * An ``arm-linux-gnueabihf`` sysroot. +.. note:: + An existing sysroot is required because some of the builtins include C library + headers and a sysroot is the easiest way to get those. + In this example we will be using ``ninja`` as the build tool. See https://compiler-rt.llvm.org/ for information about the dependencies @@ -52,78 +56,94 @@ toolchain from https://developer.arm.com/open-source/gnu-toolchain/gnu-a/downloa Building compiler-rt builtins for Arm ===================================== -We will be doing a standalone build of compiler-rt using the following cmake -options:: +We will be doing a standalone build of compiler-rt. The command is shown below. +Shell variables are used to simplify some of the options:: + + LLVM_TOOLCHAIN=/ + TARGET_TRIPLE=arm-none-linux-gnueabihf + GCC_TOOLCHAIN= + SYSROOT=${GCC_TOOLCHAIN}/${TARGET_TRIPLE}/libc + COMPILE_FLAGS="-march=armv7-a" - cmake path/to/compiler-rt \ + cmake ../llvm-project/compiler-rt \ -G Ninja \ - -DCMAKE_AR=/path/to/llvm-ar \ - -DCMAKE_ASM_COMPILER_TARGET="arm-linux-gnueabihf" \ - -DCMAKE_ASM_FLAGS="build-c-flags" \ - -DCMAKE_C_COMPILER=/path/to/clang \ - -DCMAKE_C_COMPILER_TARGET="arm-linux-gnueabihf" \ - -DCMAKE_C_FLAGS="build-c-flags" \ + -DCMAKE_AR=${LLVM_TOOLCHAIN}/bin/llvm-ar \ + -DCMAKE_NM=${LLVM_TOOLCHAIN}/bin/llvm-nm \ + -DCMAKE_RANLIB=${LLVM_TOOLCHAIN}/bin/llvm-ranlib \ + -DLLVM_CMAKE_DIR="${LLVM_TOOLCHAIN}/lib/cmake/llvm" \ + -DCMAKE_SYSROOT="${SYSROOT}" \ + -DCMAKE_ASM_COMPILER_TARGET="${TARGET_TRIPLE}" \ + -DCMAKE_ASM_FLAGS="${COMPILE_FLAGS}" \ + -DCMAKE_C_COMPILER_TARGET="${TARGET_TRIPLE}" \ + -DCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN=${GCC_TOOLCHAIN} \ + -DCMAKE_C_COMPILER=${LLVM_TOOLCHAIN}/bin/clang \ + -DCMAKE_C_FLAGS="${COMPILE_FLAGS}" \ + -DCMAKE_CXX_COMPILER_TARGET="${TARGET_TRIPLE}" \ + -DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=${GCC_TOOLCHAIN} \ + -DCMAKE_CXX_COMPILER=${LLVM_TOOLCHAIN}/bin/clang \ + -DCMAKE_CXX_FLAGS="${COMPILE_FLAGS}" \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ - -DCMAKE_NM=/path/to/llvm-nm \ - -DCMAKE_RANLIB=/path/to/llvm-ranlib \ -DCOMPILER_RT_BUILD_BUILTINS=ON \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ -DCOMPILER_RT_BUILD_MEMPROF=OFF \ -DCOMPILER_RT_BUILD_PROFILE=OFF \ + -DCOMPILER_RT_BUILD_CTX_PROFILE=OFF \ -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_XRAY=OFF \ + -DCOMPILER_RT_BUILD_ORC=OFF \ + -DCOMPILER_RT_BUILD_CRT=OFF \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \ - -DLLVM_CONFIG_PATH=/path/to/llvm-config + -DCOMPILER_RT_EMULATOR="qemu-arm -L ${SYSROOT}" \ + -DCOMPILER_RT_INCLUDE_TESTS=ON \ + -DCOMPILER_RT_TEST_COMPILER=${LLVM_TOOLCHAIN}/bin/clang \ + -DCOMPILER_RT_TEST_COMPILER_CFLAGS="--target=${TARGET_TRIPLE} ${COMPILE_FLAGS} --gcc-toolchain=${GCC_TOOLCHAIN} --sysroot=${SYSROOT} -fuse-ld=lld" -The ``build-c-flags`` need to be sufficient to pass the C-make compiler check, -compile compiler-rt, and if you are running the tests, compile and link the -tests. When cross-compiling with clang we will need to pass sufficient -information to generate code for the Arm architecture we are targeting. +.. note:: + The command above also enables tests. Enabling tests is not required, more details + in the testing section. -We will need to select: - * The Arm target and Armv7-A architecture with ``--target=arm-linux-gnueabihf -march=armv7a``. - * Whether to generate Arm (the default) or Thumb instructions (``-mthumb``). +``CMAKE__