xref: /OK3568_Linux_fs/u-boot/doc/README.clang (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunThe biggest problem when trying to compile U-Boot with clang is that
2*4882a593Smuzhiyunalmost all archs rely on storing gd in a global register and clang user
3*4882a593Smuzhiyunmanual states: "clang does not support global register variables; this
4*4882a593Smuzhiyunis unlikely to be implemented soon because it requires additional LLVM
5*4882a593Smuzhiyunbackend support."
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunSince version 3.4 the ARM backend can be instructed to leave r9 alone.
8*4882a593SmuzhiyunGlobal registers themselves are not supported so some inline assembly is
9*4882a593Smuzhiyunused to get its value. This does lead to larger code then strictly
10*4882a593Smuzhiyunnecessary, but at least works.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunNOTE: target compilation only work for _some_ ARM boards at the moment.
13*4882a593SmuzhiyunAlso Aarch64 is not supported: Most notably boards which aren't using
14*4882a593Smuzhiyunthe generic board will fail to compile, but since those are expected
15*4882a593Smuzhiyunto be converted this will solve itself. Boards which reassign gd in c
16*4882a593Smuzhiyunwill also fail to compile, but there is in no strict reason to do so
17*4882a593Smuzhiyunin the ARM world, since crt0.S takes care of this. These assignments
18*4882a593Smuzhiyuncan be avoided by changing the init calls but this is not in mainline yet.
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunNOTE: without the -mllvm -arm-use-movt=0 flags U-Boot will compile
21*4882a593Smuzhiyunfine, but llvm might hardcode addresses in movw / movt pairs, which
22*4882a593Smuzhiyuncannot be relocated and U-Boot will fail at runtime.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunDebian (based)
25*4882a593Smuzhiyun--------------
26*4882a593SmuzhiyunBinary packages can be installed as usual, e.g.:
27*4882a593Smuzhiyunsudo apt-get install clang
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunNote that we still use binutils for some tools so we must continue to set
30*4882a593SmuzhiyunCROSS_COMPILE. To compile U-Boot with clang on linux without IAS use e.g.:
31*4882a593Smuzhiyunmake HOSTCC=clang rpi_2_defconfig
32*4882a593Smuzhiyunmake HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- CC=clang -j8
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunIt can also be used to compile sandbox:
35*4882a593Smuzhiyunmake HOSTCC=clang sandbox_defconfig
36*4882a593Smuzhiyunmake HOSTCC=clang CC=clang -j8
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunFreeBSD 11 (Current):
39*4882a593Smuzhiyun--------------------
40*4882a593SmuzhiyunSince llvm 3.4 is currently in the base system, the integrated as is
41*4882a593Smuzhiyunincapable of building U-Boot. Therefore gas from devel/arm-gnueabi-binutils
42*4882a593Smuzhiyunis used instead. It needs a symlinks to be picked up correctly though:
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun# The following commands compile U-Boot using the clang xdev toolchain.
47*4882a593Smuzhiyun# NOTE: CROSS_COMPILE and target differ on purpose!
48*4882a593Smuzhiyunexport CROSS_COMPILE=arm-gnueabi-freebsd-
49*4882a593Smuzhiyungmake rpi_2_defconfig
50*4882a593Smuzhiyungmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd" -j8
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunGiven that U-Boot will default to gcc, above commands can be
53*4882a593Smuzhiyunsimplified with a simple wrapper script, listed below.
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun/usr/local/bin/arm-gnueabi-freebsd-gcc
56*4882a593Smuzhiyun---
57*4882a593Smuzhiyun#!/bin/sh
58*4882a593Smuzhiyun
59*4882a593Smuzhiyunexec clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd "$@"
60