Building The Linux Kernel With LLVM's Clang Yields Comparable Performance
With the upstream Linux kernel nearly compatible with LLVM's Clang compiler as an alternative to using GCC, I benchmarked the latest "LLVMLinux" code that's the Linux kernel compiled under Clang with some out-of-tree patches to see how its performance compares to a conventionally built kernel with GCC 4.8.
On an ASUS Zenbook Prime (UX32VDA) ultrabook I used the latest LLVMLinux code as of 26 May to build a 64-bit (x86_64) kernel using the LLVM/Clang 3.5 state it uses by default and was for the Linux 3.14 kernel target. After building and testing this Clang-compiled kernel, I then compared its performance to a Linux 3.14.0 vanilla kernel compiled by the GCC 4.8.2 compiler and using the same config settings. The same host compiler (GCC 4.8.2) was used when building the actual tests and the only changed factor was whether the Linux 3.14.0 kernel image was built using LLVMLinux with Clang or the upstream sources with GCC 4.8.2.
The LLVMLinux build process overall went smooth, aside from a few hiccups. The v3.14 kernel build originally failed due to a series file not being present within the Linux 3.14 kernel patches directory, but after making up my own replacement file with the patch file names, that worked. When it came to installing the kernel, the documentation cites installing from the src/ directory but with the latest LLVMLinux state for x86_64 it's actually within the build/ directory. The general build instructions for a Clang-compiled LLVMLinux kernel can be found via the project's Wiki.
Hopefully with the upcoming Linux 3.16 kernel we will see the upstream code even closer to being able to be built under the LLVM Clang compiler over GCC. All of our initial benchmarking for this article was done using the Phoronix Test Suite, of course.
We have covered the LLVMLinux project many times with an increasing number of developers from the x86 and ARM world being interested in building the kernel with Clang. Among the reasons for wanting to build the Linux kernel with Clang is for possible performance advantages, faster kernel compilation times when debugging the kernel, using Clang's static analysis abilities on the kernel code itself, improving the quality of LLVM and Clang by finding missing/broken compiler features, and improving the overall code quality of the Linux kernel by making the code compatible with more compilers.
Latest Linux Hardware Reviews
Latest Linux Articles
Latest Linux News
Latest Forum Discussions