llvm.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ==============================
  2. Building Linux with Clang/LLVM
  3. ==============================
  4. This document covers how to build the Linux kernel with Clang and LLVM
  5. utilities.
  6. About
  7. -----
  8. The Linux kernel has always traditionally been compiled with GNU toolchains
  9. such as GCC and binutils. Ongoing work has allowed for `Clang
  10. <https://clang.llvm.org/>`_ and `LLVM <https://llvm.org/>`_ utilities to be
  11. used as viable substitutes. Distributions such as `Android
  12. <https://www.android.com/>`_, `ChromeOS
  13. <https://www.chromium.org/chromium-os>`_, and `OpenMandriva
  14. <https://www.openmandriva.org/>`_ use Clang built kernels. `LLVM is a
  15. collection of toolchain components implemented in terms of C++ objects
  16. <https://www.aosabook.org/en/llvm.html>`_. Clang is a front-end to LLVM that
  17. supports C and the GNU C extensions required by the kernel, and is pronounced
  18. "klang," not "see-lang."
  19. Clang
  20. -----
  21. The compiler used can be swapped out via `CC=` command line argument to `make`.
  22. `CC=` should be set when selecting a config and during a build.
  23. make CC=clang defconfig
  24. make CC=clang
  25. Cross Compiling
  26. ---------------
  27. A single Clang compiler binary will typically contain all supported backends,
  28. which can help simplify cross compiling.
  29. ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang
  30. `CROSS_COMPILE` is not used to prefix the Clang compiler binary, instead
  31. `CROSS_COMPILE` is used to set a command line flag: `--target <triple>`. For
  32. example:
  33. clang --target aarch64-linux-gnu foo.c
  34. LLVM Utilities
  35. --------------
  36. LLVM has substitutes for GNU binutils utilities. Kbuild supports `LLVM=1`
  37. to enable them.
  38. make LLVM=1
  39. They can be enabled individually. The full list of the parameters:
  40. make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\
  41. OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \\
  42. READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \\
  43. HOSTLD=ld.lld
  44. Currently, the integrated assembler is disabled by default. You can pass
  45. `LLVM_IAS=1` to enable it.
  46. Getting Help
  47. ------------
  48. - `Website <https://clangbuiltlinux.github.io/>`_
  49. - `Mailing List <https://groups.google.com/forum/#!forum/clang-built-linux>`_: <clang-built-linux@googlegroups.com>
  50. - `Issue Tracker <https://github.com/ClangBuiltLinux/linux/issues>`_
  51. - IRC: #clangbuiltlinux on chat.freenode.net
  52. - `Telegram <https://t.me/ClangBuiltLinux>`_: @ClangBuiltLinux
  53. - `Wiki <https://github.com/ClangBuiltLinux/linux/wiki>`_
  54. - `Beginner Bugs <https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22>`_
  55. Getting LLVM
  56. -------------
  57. - http://releases.llvm.org/download.html
  58. - https://github.com/llvm/llvm-project
  59. - https://llvm.org/docs/GettingStarted.html
  60. - https://llvm.org/docs/CMake.html
  61. - https://apt.llvm.org/
  62. - https://www.archlinux.org/packages/extra/x86_64/llvm/
  63. - https://github.com/ClangBuiltLinux/tc-build
  64. - https://github.com/ClangBuiltLinux/linux/wiki/Building-Clang-from-source
  65. - https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/