Heinrich Schuchardt | ac49e7b | 2020-07-25 09:55:46 +0200 | [diff] [blame] | 1 | Building with Clang |
| 2 | =================== |
| 3 | |
| 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." |
| 8 | |
| 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. |
| 13 | |
| 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 |
| 19 | mainline yet. |
| 20 | |
| 21 | |
| 22 | Debian based |
| 23 | ------------ |
| 24 | |
| 25 | Required packages can be installed via apt, e.g. |
| 26 | |
| 27 | .. code-block:: bash |
| 28 | |
| 29 | sudo apt-get install clang |
| 30 | |
| 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. |
| 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 | |
| 40 | It 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 | |
| 48 | FreeBSD 11 |
| 49 | ---------- |
| 50 | |
| 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: |
| 54 | |
| 55 | .. code-block:: bash |
| 56 | |
| 57 | ln -s /usr/local/bin/arm-gnueabi-freebsd-as /usr/bin/arm-freebsd-eabi-as |
| 58 | |
| 59 | The 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 | |
| 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: |
| 72 | |
| 73 | .. code-block:: bash |
| 74 | |
| 75 | #!/bin/sh |
| 76 | exec clang -target arm-freebsd-eabi --sysroot /usr/arm-freebsd "$@" |