How To Build On ARM

Introduction

This document contains information about building/testing LLVM andClang on an ARM machine.

This document is NOT tailored to help you cross-compile LLVM/Clangto ARM on another architecture, for example an x86_64 machine. To findout more about cross-compiling, please check How To Cross-Compile Clang/LLVM using Clang/LLVM.

Notes On Building LLVM/Clang on ARM

Here are some notes on building/testing LLVM/Clang on ARM. Note thatARM encompasses a wide variety of CPUs; this advice is primarily basedon the ARMv6 and ARMv7 architectures and may be inapplicable to older chips.

  • The most popular Linaro/Ubuntu OS’s for ARM boards, e.g., thePandaboard, have become hard-float platforms. There are a number ofchoices when using CMake. Autoconf usage is deprecated as of 3.8.

Building LLVM/Clang in Release mode is preferred since it consumesa lot less memory. Otherwise, the building process will very likelyfail due to insufficient memory. It’s also a lot quicker to only buildthe relevant back-ends (ARM and AArch64), since it’s very unlikely thatyou’ll use an ARM board to cross-compile to other arches. If you’rerunning Compiler-RT tests, also include the x86 back-end, or some testswill fail.

  1. cmake $LLVM_SRC_DIR -DCMAKE_BUILD_TYPE=Release \
  2. -DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"

Other options you can use are:

  1. Use Ninja instead of Make: "-G Ninja"
  2. Build with assertions on: "-DLLVM_ENABLE_ASSERTIONS=True"
  3. Force Python2: "-DPYTHON_EXECUTABLE=/usr/bin/python2"
  4. Local (non-sudo) install path: "-DCMAKE_INSTALL_PREFIX=$HOME/llvm/install"
  5. CPU flags: "DCMAKE_C_FLAGS=-mcpu=cortex-a15" (same for CXX_FLAGS)

After that, just typing make -jN or ninja will build everything.make -jN check-all or ninja check-all will run all compiler tests. Forrunning the test suite, please refer to LLVM Testing Infrastructure Guide.

  • If you are building LLVM/Clang on an ARM board with 1G of memory or less,please use gold rather then GNU ld. In any case it is probably a goodidea to set up a swap partition, too.
  1. $ sudo ln -sf /usr/bin/ld /usr/bin/ld.gold
  • ARM development boards can be unstable and you may experience that coresare disappearing, caches being flushed on every big.LITTLE switch, andother similar issues. To help ease the effect of this, set the Linuxscheduler to “performance” on all cores using this little script:
  1. # The code below requires the package 'cpufrequtils' to be installed.
  2. for ((cpu=0; cpu<`grep -c proc /proc/cpuinfo`; cpu++)); do
  3. sudo cpufreq-set -c $cpu -g performance
  4. done

Remember to turn that off after the build, or you may risk burning yourCPU. Most modern kernels don’t need that, so only use it if you haveproblems.

  • Running the build on SD cards is ok, but they are more prone to failuresthan good quality USB sticks, and those are more prone to failures thanexternal hard-drives (those are also a lot faster). So, at least, youshould consider to buy a fast USB stick. On systems with a fast eMMC,that’s a good option too.

  • Make sure you have a decent power supply (dozens of dollars worth) that canprovide at least 4 amperes, this is especially important if you use USBdevices with your board. Externally powered USB/SATA harddrives are evenbetter than having a good power supply.