clang.rst 2.5 KB

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