Compiling the Linux Kernel with Clang
Linux Plumbers Conf
14 Nov 2018
What is Clang and LLVM?
LLVM Optimizer
LLVM x86 Backend
LLVM ARM Backend
LLVM WebAssembly Backend
Clang�(C/C++/ObjC/ObjC++/�OpenMP/OpenCL/CUDA)�Compiler
Rust
Compiler
Swift
Compiler
LLVM IR →
LLVM IR →
...
...
A fix in one part of LLVM benefits all
Alternatives to GCC and Binutils
clang | gcc |
clang++ | g++ |
clang (“integrated assembler”) | as |
ld.lld | ld.bfd , ld.gold |
llvm-objdump, llvm-objcopy, llvm-*, etc | objdump, objcopy, strip, readelf, etc |
Compiler_RT | libgcc |
libc++ | libstdc++ |
Why build the kernel with Clang?
Proprietary + Confidential
Priorities
Proprietary + Confidential
Recent Clang features for kernel
Proprietary + Confidential
Give it a shot
$ make CC=clang HOSTCC=clang
Example cross compiling (arm64/aarch64):
$ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang HOSTCC=clang
Link with LLD
$ make LD=ld.lld
Note: LLVM moves quickly! If your distro’s clang doesn’t work, try the latest release at https://releases.llvm.org/ or from the AOSP prebuilts/clang/host/linux-x86 project.
Proprietary + Confidential
Distros shipping Clang built kernels
Proprietary + Confidential
Continuous Automated Testing
Report bugs
Problematic code for Clang
Thanks
Thanks to the many people making this all work.
We’re proud to present this work on their behalf and lucky to have such interest and support.
If you’re interested in how you can help, we want to enable you to be successful, get in touch!