xref: /aosp_15_r20/external/llvm/docs/HowToBuildOnARM.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker===================================================================
2*9880d681SAndroid Build Coastguard WorkerHow To Build On ARM
3*9880d681SAndroid Build Coastguard Worker===================================================================
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard WorkerIntroduction
6*9880d681SAndroid Build Coastguard Worker============
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard WorkerThis document contains information about building/testing LLVM and
9*9880d681SAndroid Build Coastguard WorkerClang on an ARM machine.
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard WorkerThis document is *NOT* tailored to help you cross-compile LLVM/Clang
12*9880d681SAndroid Build Coastguard Workerto ARM on another architecture, for example an x86_64 machine. To find
13*9880d681SAndroid Build Coastguard Workerout more about cross-compiling, please check :doc:`HowToCrossCompileLLVM`.
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard WorkerNotes On Building LLVM/Clang on ARM
16*9880d681SAndroid Build Coastguard Worker=====================================
17*9880d681SAndroid Build Coastguard WorkerHere are some notes on building/testing LLVM/Clang on ARM. Note that
18*9880d681SAndroid Build Coastguard WorkerARM encompasses a wide variety of CPUs; this advice is primarily based
19*9880d681SAndroid Build Coastguard Workeron the ARMv6 and ARMv7 architectures and may be inapplicable to older chips.
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker#. The most popular Linaro/Ubuntu OS's for ARM boards, e.g., the
22*9880d681SAndroid Build Coastguard Worker   Pandaboard, have become hard-float platforms. There are a number of
23*9880d681SAndroid Build Coastguard Worker   choices when using CMake. Autoconf usage is deprecated as of 3.8.
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker   Building LLVM/Clang in ``Relese`` mode is preferred since it consumes
26*9880d681SAndroid Build Coastguard Worker   a lot less memory. Otherwise, the building process will very likely
27*9880d681SAndroid Build Coastguard Worker   fail due to insufficient memory. It's also a lot quicker to only build
28*9880d681SAndroid Build Coastguard Worker   the relevant back-ends (ARM and AArch64), since it's very unlikely that
29*9880d681SAndroid Build Coastguard Worker   you'll use an ARM board to cross-compile to other arches. If you're
30*9880d681SAndroid Build Coastguard Worker   running Compiler-RT tests, also include the x86 back-end, or some tests
31*9880d681SAndroid Build Coastguard Worker   will fail.
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker   .. code-block:: bash
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker     cmake $LLVM_SRC_DIR -DCMAKE_BUILD_TYPE=Release \
36*9880d681SAndroid Build Coastguard Worker                         -DLLVM_TARGETS_TO_BUILD="ARM;X86;AArch64"
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Worker   Other options you can use are:
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker   .. code-block:: bash
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker     Use Ninja instead of Make: "-G Ninja"
43*9880d681SAndroid Build Coastguard Worker     Build with assertions on: "-DLLVM_ENABLE_ASSERTIONS=True"
44*9880d681SAndroid Build Coastguard Worker     Force Python2: "-DPYTHON_EXECUTABLE=/usr/bin/python2"
45*9880d681SAndroid Build Coastguard Worker     Local (non-sudo) install path: "-DCMAKE_INSTALL_PREFIX=$HOME/llvm/instal"
46*9880d681SAndroid Build Coastguard Worker     CPU flags: "DCMAKE_C_FLAGS=-mcpu=cortex-a15" (same for CXX_FLAGS)
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker   After that, just typing ``make -jN`` or ``ninja`` will build everything.
49*9880d681SAndroid Build Coastguard Worker   ``make -jN check-all`` or ``ninja check-all`` will run all compiler tests. For
50*9880d681SAndroid Build Coastguard Worker   running the test suite, please refer to :doc:`TestingGuide`.
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker#. If you are building LLVM/Clang on an ARM board with 1G of memory or less,
53*9880d681SAndroid Build Coastguard Worker   please use ``gold`` rather then GNU ``ld``. In any case it is probably a good
54*9880d681SAndroid Build Coastguard Worker   idea to set up a swap partition, too.
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker   .. code-block:: bash
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker     $ sudo ln -sf /usr/bin/ld /usr/bin/ld.gold
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker#. ARM development boards can be unstable and you may experience that cores
61*9880d681SAndroid Build Coastguard Worker   are disappearing, caches being flushed on every big.LITTLE switch, and
62*9880d681SAndroid Build Coastguard Worker   other similar issues.  To help ease the effect of this, set the Linux
63*9880d681SAndroid Build Coastguard Worker   scheduler to "performance" on **all** cores using this little script:
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker   .. code-block:: bash
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker      # The code below requires the package 'cpufrequtils' to be installed.
68*9880d681SAndroid Build Coastguard Worker      for ((cpu=0; cpu<`grep -c proc /proc/cpuinfo`; cpu++)); do
69*9880d681SAndroid Build Coastguard Worker          sudo cpufreq-set -c $cpu -g performance
70*9880d681SAndroid Build Coastguard Worker      done
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker   Remember to turn that off after the build, or you may risk burning your
73*9880d681SAndroid Build Coastguard Worker   CPU. Most modern kernels don't need that, so only use it if you have
74*9880d681SAndroid Build Coastguard Worker   problems.
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker#. Running the build on SD cards is ok, but they are more prone to failures
77*9880d681SAndroid Build Coastguard Worker   than good quality USB sticks, and those are more prone to failures than
78*9880d681SAndroid Build Coastguard Worker   external hard-drives (those are also a lot faster). So, at least, you
79*9880d681SAndroid Build Coastguard Worker   should consider to buy a fast USB stick.  On systems with a fast eMMC,
80*9880d681SAndroid Build Coastguard Worker   that's a good option too.
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Worker#. Make sure you have a decent power supply (dozens of dollars worth) that can
83*9880d681SAndroid Build Coastguard Worker   provide *at least* 4 amperes, this is especially important if you use USB
84*9880d681SAndroid Build Coastguard Worker   devices with your board. Externally powered USB/SATA harddrives are even
85*9880d681SAndroid Build Coastguard Worker   better than having a good power supply.
86