4 The biggest problem when trying to compile U-Boot with Clang is that almost all
5 archs rely on storing gd in a global register and the Clang 3.5 user manual
6 states: "Clang does not support global register variables; this is unlikely to
7 be implemented soon because it requires additional LLVM backend support."
9 The 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
11 supported inline assembly is needed to get and set the r9 or x18 value. This
12 leads to larger code then strictly necessary, but at least works.
14 **NOTE:** target compilation only work for _some_ ARM boards at the moment.
15 Also AArch64 is not supported currently due to a lack of private libgcc
16 support. Boards which reassign gd in c will also fail to compile, but there is
17 in no strict reason to do so in the ARM world, since crt0.S takes care of this.
18 These assignments can be avoided by changing the init calls but this is not in
25 Required packages can be installed via apt, e.g.
29 sudo apt-get install clang
31 Note that we still use binutils for some tools so we must continue to set
32 CROSS_COMPILE. To compile U-Boot with Clang on Linux without IAS use e.g.
36 make HOSTCC=clang rpi_2_defconfig
37 make HOSTCC=clang CROSS_COMPILE=arm-linux-gnueabi- \
38 CC="clang -target arm-linux-gnueabi" -j8
40 It can also be used to compile sandbox:
44 make HOSTCC=clang sandbox_defconfig
45 make HOSTCC=clang CC=clang -j8
51 Since llvm 3.4 is currently in the base system, the integrated assembler as
52 is incapable of building U-Boot. Therefore gas from devel/arm-gnueabi-binutils
53 is used instead. It needs a symlink to be picked up correctly though:
57 ln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as
59 The following commands compile U-Boot using the Clang xdev toolchain.
61 **NOTE:** CROSS_COMPILE and target differ on purpose!
65 export CROSS_COMPILE=arm-gnueabi-freebsd-
67 gmake CC="clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd" -j8
69 Given that U-Boot will default to gcc, above commands can be
70 simplified with a simple wrapper script - saved as
71 /usr/local/bin/arm-gnueabi-freebsd-gcc - listed below:
76 exec clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd "$@"
82 When build U-boot for `xenguest_arm64_defconfig` target, it reports linkage
87 aarch64-linux-gnu-ld.bfd: drivers/xen/hypervisor.o: in function `do_hypervisor_callback':
88 /home/leoy/Dev2/u-boot/drivers/xen/hypervisor.c:188: undefined reference to `__aarch64_swp8_acq_rel'
89 aarch64-linux-gnu-ld.bfd: drivers/xen/hypervisor.o: in function `synch_test_and_set_bit':
90 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:40: undefined reference to `__aarch64_ldset1_acq_rel'
91 aarch64-linux-gnu-ld.bfd: drivers/xen/hypervisor.o: in function `synch_test_and_clear_bit':
92 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:28: undefined reference to `__aarch64_ldclr1_acq_rel'
93 aarch64-linux-gnu-ld.bfd: drivers/xen/hypervisor.o: in function `synch_test_and_set_bit':
94 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:40: undefined reference to `__aarch64_ldset1_acq_rel'
95 aarch64-linux-gnu-ld.bfd: drivers/xen/hypervisor.o: in function `synch_test_and_clear_bit':
96 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:28: undefined reference to `__aarch64_ldclr1_acq_rel'
97 aarch64-linux-gnu-ld.bfd: drivers/xen/events.o: in function `synch_test_and_clear_bit':
98 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:28: undefined reference to `__aarch64_ldclr1_acq_rel'
99 aarch64-linux-gnu-ld.bfd: drivers/xen/events.o: in function `synch_test_and_set_bit':
100 /home/leoy/Dev2/u-boot/./arch/arm/include/asm/xen/system.h:40: undefined reference to `__aarch64_ldset1_acq_rel'
101 aarch64-linux-gnu-ld.bfd: drivers/xen/gnttab.o: in function `gnttab_end_access':
102 /home/leoy/Dev2/u-boot/drivers/xen/gnttab.c:109: undefined reference to `__aarch64_cas2_acq_rel'
105 To fix the failure, we need to append option `-mno-outline-atomics` in Clang
106 command to not generate local calls to out-of-line atomic operations:
110 make HOSTCC=clang xenguest_arm64_defconfig
111 make HOSTCC=clang CROSS_COMPILE=aarch64-linux-gnu- \
112 CC="clang -target aarch64-linux-gnueabi -mno-outline-atomics" -j8