Skip to content

Compile Linux Kernel With Clang

clang is high performance compiler based on llvm

Clang

traditionally linux kernel has always been compiled with gcc, but there is another player in the game, it is clang which build on top of llvm compiler infrastructure, which generate high performance machine code, it is concedered slightly better than gcc in some points.

to change the C compiler used by Kbuild, you should set LLVM variable wich implies using CC=clang:

make LLVM=1 defconfig
make LLVM=1

note that you should use this option, in both configuring, and compiling the kernel.

LLVM

llvm has it's own utilities, just like gcc does (gas, ld, objdump, objcopy...) linux build system will use them, if you set llvm variable:

make LLVM=1

Resources:

https://www.kernel.org/doc/html/latest/kbuild/llvm.html