OSDN Git Service

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