• Home
  • Raw
  • Download

Lines Matching +full:bare +full:- +full:cross +full:- +full:build

2 How to Cross Compile Compiler-rt Builtins For Arm
9 of compiler-rt for an Arm target, from an x86_64 Linux machine.
12 apply to other targets supported by compiler-rt. Further contributions for other
22 In this use case we'll be using cmake on a Debian-based Linux system,
23 cross-compiling from an x86_64 host to a hard-float Armv7-A target. We'll be
27 * ``A build of LLVM/clang for the llvm-tools and llvm-config``
29 * ``compiler-rt sources``
30 * ``The qemu-arm user mode emulator``
31 * ``An arm-linux-gnueabihf sysroot``
35 See https://compiler-rt.llvm.org/ for more information about the dependencies
39 the source for LLVM and compiler-rt. Note that the getting started guide
40 places compiler-rt in the projects subdirectory, but this is not essential and
41 if you are using the BaremetalARM.cmake cache for v6-M, v7-M and v7-EM then
42 compiler-rt must be placed in the runtimes directory.
44 ``qemu-arm`` should be available as a package for your Linux distribution.
46 The most complicated of the prerequisites to satisfy is the arm-linux-gnueabihf
50 to supply a sysroot is to download the arm-linux-gnueabihf toolchain. This can
52 * https://developer.arm.com/open-source/gnu-toolchain/gnu-a/downloads for gcc 8 and above
55 Building compiler-rt builtins for Arm
57 We will be doing a standalone build of compiler-rt using the following cmake
60 * ``path/to/compiler-rt``
61 * ``-G Ninja``
62 * ``-DCOMPILER_RT_BUILD_BUILTINS=ON``
63 * ``-DCOMPILER_RT_BUILD_SANITIZERS=OFF``
64 * ``-DCOMPILER_RT_BUILD_XRAY=OFF``
65 * ``-DCOMPILER_RT_BUILD_LIBFUZZER=OFF``
66 * ``-DCOMPILER_RT_BUILD_PROFILE=OFF``
67 * ``-DCMAKE_C_COMPILER=/path/to/clang``
68 * ``-DCMAKE_AR=/path/to/llvm-ar``
69 * ``-DCMAKE_NM=/path/to/llvm-nm``
70 * ``-DCMAKE_RANLIB=/path/to/llvm-ranlib``
71 * ``-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld"``
72 * ``-DCMAKE_C_COMPILER_TARGET="arm-linux-gnueabihf"``
73 * ``-DCMAKE_ASM_COMPILER_TARGET="arm-linux-gnueabihf"``
74 * ``-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON``
75 * ``-DLLVM_CONFIG_PATH=/path/to/llvm-config``
76 * ``-DCMAKE_C_FLAGS="build-c-flags"``
77 * ``-DCMAKE_ASM_FLAGS="build-c-flags"``
79 The ``build-c-flags`` need to be sufficient to pass the C-make compiler check,
80 compile compiler-rt, and if you are running the tests, compile and link the
81 tests. When cross-compiling with clang we will need to pass sufficient
83 need to select the Arm target, select the Armv7-A architecture and choose
87 * ``--target=arm-linux-gnueabihf``
88 * ``-march=armv7a``
89 * ``-mthumb``
91 When using a GCC arm-linux-gnueabihf toolchain the following flags are
94 * ``--gcc-toolchain=/path/to/dir/toolchain``
95 * ``--sysroot=/path/to/toolchain/arm-linux-gnueabihf/libc``
99 these options individually which can be used to simplify the ``build-c-flags``:
101 * ``-DCMAKE_C_COMPILER_TARGET="arm-linux-gnueabihf"``
102 * ``-DCMAKE_ASM_COMPILER_TARGET="arm-linux-gnueabihf"``
103 * ``-DCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN=/path/to/dir/toolchain``
104 * ``-DCMAKE_SYSROOT=/path/to/dir/toolchain/arm-linux-gnueabihf/libc``
108 Testing compiler-rt builtins using qemu-arm
112 cmake that we wish to run the tests on ``qemu-arm``.
114 * ``-DCOMPILER_RT_EMULATOR="qemu-arm -L /path/to/armhf/sysroot``
115 * ``-DCOMPILER_RT_INCLUDE_TESTS=ON``
116 * ``-DCOMPILER_RT_TEST_COMPILER="/path/to/clang"``
117 * ``-DCOMPILER_RT_TEST_COMPILER_CFLAGS="test-c-flags"``
120 ``--sysroot`` in the "build-c-flags".
122 The "test-c-flags" need to include the target, architecture, gcc-toolchain,
125 you have put all of these in "build-c-flags" then these can be repeated. If you
126 wish to use lld to link the tests then add ``"-fuse-ld=lld``.
129 ``ninja check-builtins``
135 ---------------------------------
139 This stage can often fail at link time if the ``--sysroot`` and
140 ``--gcc-toolchain`` options are not passed to the compiler. Check the
143 It can be useful to build a simple example outside of cmake with your toolchain
144 …ample: ``clang --target=arm-linux-gnueabi -march=armv7a --gcc-toolchain=/path/to/gcc-toolchain --s…
147 --------------------------------
149 arm-linux-gnueabi and arm-linux-gnueabihf. In many cases clang can successfully
150 use this multiarch support when -gcc-toolchain and --sysroot are not supplied.
152 ``/usr/include/arm-linux-gnueabihf`` leading to errors when compiling the hosts
155 The multiarch support is not sufficient to build the builtins you will need to
156 use a separate arm-linux-gnueabihf toolchain.
159 -------------------------
165 ``--target`` or if it is set incorrectly. The cause is usually
166 ``CMAKE_ASM_FLAGS`` not containing ``--target`` or ``CMAKE_ASM_COMPILER_TARGET`` not being present.
169 --------------------------
170 The ``--target=arm-linux-gnueabihf`` will default to arm architecture v4t which
174 The cause is usually a missing ``-march=armv7a`` from the ``CMAKE_ASM_FLAGS``.
176 Compiler-rt builds but the tests fail to build
177 ----------------------------------------------
178 The flags used to build the tests are not the same as those used to build the
191 Arm Soft-Float Target
192 ---------------------
193 The instructions for the Arm hard-float target can be used for the soft-float
194 target by substituting soft-float equivalents for the sysroot and target. The
197 * ``-DCMAKE_C_COMPILER_TARGET=arm-linux-gnueabi``
200 may need extra c-flags such as ``-mfloat-abi=softfp`` for use of floating-point
201 instructions, and ``-mfloat-abi=soft -mfpu=none`` for software floating-point
204 You will need to use an arm-linux-gnueabi GNU toolchain for soft-float.
207 --------------
211 * ``-DCMAKE_C_COMPILER_TARGET=aarch64-linux-gnu``
212 * ``-DCOMPILER_RT_EMULATOR="qemu-aarch64 -L /path/to/aarch64/sysroot``
215 ``"--sysroot=/path/to/aarch64/sysroot --gcc-toolchain=/path/to/gcc-toolchain"``
217 Armv6-m, Armv7-m and Armv7E-M targets
218 -------------------------------------
219 To build and test the libraries using a similar method to Armv7-A is possible
222 * There isn't a ``qemu-arm`` user-mode emulator for bare-metal systems. The ``qemu-system-arm`` can…
223 * The targets to compile compiler-rt have the suffix -none-eabi. This uses the BareMetal driver in …
225 As the Armv6-M, Armv7-M and Armv7E-M builds of compiler-rt only use instructions
226 that are supported on Armv7-A we can still get most of the value of running the
227 tests using the same ``qemu-arm`` that we used for Armv7-A by building and
228 running the test cases for Armv7-A but using the builtins compiled for
229 Armv6-M, Armv7-M or Armv7E-M. This will test that the builtins can be linked
231 builtins use instructions that are supported on Armv7-A but not Armv6-M,
232 Armv7-M and Armv7E-M.
239 * ``-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY``
240 * ``-DCOMPILER_RT_OS_DIR="baremetal"``
241 * ``-DCOMPILER_RT_BUILD_BUILTINS=ON``
242 * ``-DCOMPILER_RT_BUILD_SANITIZERS=OFF``
243 * ``-DCOMPILER_RT_BUILD_XRAY=OFF``
244 * ``-DCOMPILER_RT_BUILD_LIBFUZZER=OFF``
245 * ``-DCOMPILER_RT_BUILD_PROFILE=OFF``
246 * ``-DCMAKE_C_COMPILER=${host_install_dir}/bin/clang``
247 * ``-DCMAKE_C_COMPILER_TARGET="your *-none-eabi target"``
248 * ``-DCMAKE_ASM_COMPILER_TARGET="your *-none-eabi target"``
249 * ``-DCMAKE_AR=/path/to/llvm-ar``
250 * ``-DCMAKE_NM=/path/to/llvm-nm``
251 * ``-DCMAKE_RANLIB=/path/to/llvm-ranlib``
252 * ``-DCOMPILER_RT_BAREMETAL_BUILD=ON``
253 * ``-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON``
254 * ``-DLLVM_CONFIG_PATH=/path/to/llvm-config``
255 * ``-DCMAKE_C_FLAGS="build-c-flags"``
256 * ``-DCMAKE_ASM_FLAGS="build-c-flags"``
257 * ``-DCOMPILER_RT_EMULATOR="qemu-arm -L /path/to/armv7-A/sysroot"``
258 * ``-DCOMPILER_RT_INCLUDE_TESTS=ON``
259 * ``-DCOMPILER_RT_TEST_COMPILER="/path/to/clang"``
260 * ``-DCOMPILER_RT_TEST_COMPILER_CFLAGS="test-c-flags"``
262 The Armv6-M builtins will use the soft-float ABI. When compiling the tests for
263 Armv7-A we must include ``"-mthumb -mfloat-abi=soft -mfpu=none"`` in the
264 test-c-flags. We must use an Armv7-A soft-float abi sysroot for ``qemu-arm``.
267 mismatches between the M-profile objects from compiler-rt and the A-profile
269 BuildAttribute so it can be used to link the tests by adding -fuse-ld=lld to the
273 -------------------------------
274 If you wish to build, but not test compiler-rt for Armv6-M, Armv7-M or Armv7E-M
277 You will need a bare metal sysroot such as that provided by the GNU ARM
282 * ``-DBAREMETAL_ARMV6M_SYSROOT=/path/to/bare/metal/toolchain/arm-none-eabi``
283 * ``-DBAREMETAL_ARMV7M_SYSROOT=/path/to/bare/metal/toolchain/arm-none-eabi``
284 * ``-DBAREMETAL_ARMV7EM_SYSROOT=/path/to/bare/metal/toolchain/arm-none-eabi``
285 * ``-C /path/to/llvm/source/tools/clang/cmake/caches/BaremetalARM.cmake``
288 **Note** that for the recipe to work the compiler-rt source must be checked out