Building The Linux Kernel With Clang Is Becoming Popular Again

Written by Michael Larabel in Linux Kernel on 21 November 2018 at 05:17 AM EST. 24 Comments
LINUX KERNEL
Years ago there was much interest in the ability to build the mainline Linux kernel with the LLVM Clang compiler as an alternative to using the GCC compiler in order to ensure better code portability, shaking out GCC'isms, possible build speed improvements, and other benefits. But in recent years it seems to have waned in interest but now things are heating up again.

After the formal LLVMLinux project faded away for building the Linux kernel with the LLVM stack and what feels like years since the last presentation on the topic, at last week's Linux Plumbers Conference were three presentations on the topic.

As has been the case for a while, most of the LLVM Clang + Linux effort has been in regards to ARM/AArch64 architectures but one BoF session last week was also in regards to rejuvenating the effort in the x86_64 space. The Clang compiler has been quite popular with the ARM vendors and LLVM's more liberal license has also been attractive to them.

Nick Desaulniers and Greg Hackmann of Google were talking about Clang'ing the Linux kernel at LPC 2018. The reasons they expressed for why they like building the kernel with Clang is to make use of the latest compiler tech, LLVM's various analyzer tools, better warning coverage, shaking out undefined behavior, improving both code-bases (LLVM and Linux), and offering one binary for cross-compiling.

More Clang functionality has been upstreamed in Clang 7~8 for helping with the kernel building process including support for various needed features, rN register naming for AArch64, prototype "asm goto" support, and various fixes.

Nick also pointed out that Google's Pixel 2 and Pixel 3 devices are running their Android Linux kernels built under the Clang compiler. With the new Pixel 3, its Clang'ed kernel is also making use of LTO and CFI. He hints that more Android devices will be coming soon with Clang built kernels.

Helping the situation moving forward is Linaro's kernel continuous integration farm will be increasing their support for Clang.

More details via this slide deck.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week