AMD/Intel Benchmarks: Building The Mainline Linux x86_64 Kernel With LLVM Clang

Written by Michael Larabel in Software on 12 September 2019 at 10:31 AM EDT. Page 1 of 4. 23 Comments.

With the upcoming LLVM Clang 9.0 compiler release there is an amazing achievement more than a decade in the making... The mainline Clang compiler can finally build the mainline Linux x86_64 kernel. The AArch64 state has been in better shape in recent years with multiple Arm vendors using Clang as their default compiler including to build the Linux kernel, but finally in 2019 the mainline Clang can build mainline Linux x86_64. There are a few caveats, but in this article is my experience in doing so with LLVM Clang and the Linux 5.3 kernel as well as running some preliminary benchmarks on AMD and Intel hardware.

It has taken years of work to address various GCC'isms within the Linux kernel to improve its code portability for different compilers. There's also been various features implemented in LLVM/Clang to help in building the Linux kernel. The most recent addition was finally supporting "asm goto" for satisfying Linux x86_64 kernel builds. LLVM Clang 9.0 will soon be released with this support and for today's testing I was using the Linux 5.3 development code as of earlier this week.

While everything mainline should work for both the kernel and compiler, it's not without some caveats. There still might be some modules not building correctly or with future kernel patches causing problems as most kernel developers are just focused on the standard GCC compiler. The main caveat I encountered was the AMDGPU kernel module failing to build with Clang. AMDGPU was failing to build with the latest code on the Clang 9.0 branch so I switched over to LLVM Clang 10.0 Git/SVN master. AMDGPU still failed to build but I stuck with using that latest Clang code anyhow for the best support/features. When building the Linux kernel without AMDGPU support, it built fine without errors. This kernel configuration was the same otherwise to Ubuntu's mainline kernel PPA Kconfig configurations, so AMDGPU seems to be the main culprit for users to potentially hit. With the mainline Clang compiler and kernel source, it's as easy as pointing CC to the Clang binary.

For comparison to the Clang 10 SVN kernel build, the same kernel sources / Kconfig were re-built using the GCC 9.1 compiler for the latest look at the GCC performance on the same systems. An AMD Ryzen 9 3900X and Core i9 9900K systems were used for benchmarking these two kernel builds from the different compilers. During the benchmarking process, the same (GCC) compiler was used throughout with just changing the kernel build between testing.

GCC vs. LLVM Clang - Linux Kernel Build Performance

The Clang-built kernel of Linux 5.3 was working out very well on the Ryzen 9 3900X system. On the Intel Core i9 9900K system, there were stability issues encountered in demanding multi-threaded tests. The main culprits were Blender and GeekBench 5 causing the Clang-built kernel to cause the system to reset during testing while this behavior wasn't seen when the kernel was built under GCC, so likely some problematic code generation on the Clang side.

For those wondering how the Clang-built Linux kernel performs, here are those benchmarks via the Phoronix Test Suite.

Related Articles