blob: 1d35616eb5efc0337675863c12bc191912a764d6 [file] [log] [blame]
Heinrich Schuchardt7f89e852020-07-25 09:55:46 +02001Building with Clang
2===================
3
4The biggest problem when trying to compile U-Boot with Clang is that almost all
5archs rely on storing gd in a global register and the Clang 3.5 user manual
6states: "Clang does not support global register variables; this is unlikely to
7be implemented soon because it requires additional LLVM backend support."
8
9The ARM backend can be instructed not to use the r9 and x18 registers using
10-ffixed-r9 or -ffixed-x18 respectively. As global registers themselves are not
11supported inline assembly is needed to get and set the r9 or x18 value. This
12leads to larger code then strictly necessary, but at least works.
13
14**NOTE:** target compilation only work for _some_ ARM boards at the moment.
15Also AArch64 is not supported currently due to a lack of private libgcc
16support. Boards which reassign gd in c will also fail to compile, but there is
17in no strict reason to do so in the ARM world, since crt0.S takes care of this.
18These assignments can be avoided by changing the init calls but this is not in
19mainline yet.
20
21
22Debian based
23------------
24
25Required packages can be installed via apt, e.g.
26
27.. code-block:: bash
28
29 sudo apt-get install clang
30
31Note that we still use binutils for some tools so we must continue to set
32CROSS_COMPILE. To compile U-Boot with Clang on Linux without IAS use e.g.
33
34.. code-block:: bash
35
36 make HOSTCC=clang rpi_2_defconfig
37 make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- \
38 CC="clang -target arm-linux-gnueabi" -j8
39
40It can also be used to compile sandbox:
41
42.. code-block:: bash
43
44 make HOSTCC=clang sandbox_defconfig
45 make HOSTCC=clang CC=clang -j8
46
47
48FreeBSD 11
49----------
50
51Since llvm 3.4 is currently in the base system, the integrated assembler as
52is incapable of building U-Boot. Therefore gas from devel/arm-gnueabi-binutils
53is used instead. It needs a symlink to be picked up correctly though:
54
55.. code-block:: bash
56
57 ln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as
58
59The following commands compile U-Boot using the Clang xdev toolchain.
60
61**NOTE:** CROSS_COMPILE and target differ on purpose!
62
63.. code-block:: bash
64
65 export CROSS_COMPILE=arm-gnueabi-freebsd-
66 gmake rpi_2_defconfig
67 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd" -j8
68
69Given that U-Boot will default to gcc, above commands can be
70simplified with a simple wrapper script - saved as
71/usr/local/bin/arm-gnueabi-freebsd-gcc - listed below:
72
73.. code-block:: bash
74
75 #!/bin/sh
76 exec clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd "$@"