There's Interest In Building The Linux Kernel With Clang

Written by Michael Larabel in Software on 5 April 2012 at 02:51 PM EDT. Page 3 of 3. 9 Comments.

Getting back to the QuiC focus on "Clanging" the Linux kernel, there's been the long-standing issues with the Linux kernel relying upon undocumented GCC behavior, Clang C99 vs. GCC GNU89 differences, some Clang/LLVM bugs, and lots of warnings too. There's also several compiler flags from GCC that aren't supported right now by Clang, such as -fconserve-stack, -fdelete-null-pointer-checks, and -fno-inline-functions-called-once. Among the GCC language extensions where Clang is currently getting borked on the kernel are for variable length arrays in structs (VLAIS), not handling explicit register variables, nested functions, and inline syntax handling (GNU89).

On the LLVM bug tracker is the Linux kernel blocker bug to highlight the outstanding issues in using Clang to build the Linux kernel. At this time there's still a handful of open bugs while a majority have been closed.

Charlebois and others have also established an LLVM Linux Foundation area for going over the process of building the Linux kernel with Clang. This is using the latest Git Linux kernel and the latest revisions to LLVM/Clang as well. Sadly the documentation and scripts right now are largely catered to the ARM focus rather than x86/x86_64, but there are some patches and information available. The current build process is also focused on running the built kernel within a QEMU environment.

So there's progress being made so that the Linux kernel can be cleanly built (and work) from LLVM's Clang compiler, but unfortunately it looks like we're still a ways out before it becoming trivial to switch between GCC and Clang for building the vanilla Linux kernel.

If you enjoyed this article consider joining Phoronix Premium to view this site ad-free, multi-page articles on a single page, and other benefits. PayPal or Stripe tips are also graciously accepted. Thanks for your support.


Related Articles
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.