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