Clang LTO Support Merged For Linux 5.12 Including ARM64 + x86_64
Written by Michael Larabel in LLVM on 23 February 2021 at 08:16 PM EST. 14 Comments
LLVM --
Pop open the champagne as the in-development Linux 5.12 kernel will be able to support link-time optimizations (LTO) in conjunction with the LLVM Clang compiler on not only AArch64 (64-bit ARM) but also x86_64.

Last week I noted that Clang LTO support had been submitted but at the time was not clear if Linus Torvalds was willing to land it given his past comments around LTO'ing the kernel. With that pull request it was also just for AArch64 with the x86_64 support not yet squared away.

Years ago Linus Torvalds was unconvinced by GCC LTO support for the kernel and that code ultimately was never mainlined. With Clang the benefits are much the same in allowing for potentially greater performance by allowing the code compiler to apply optimization passes at link-time on the entire kernel rather than being limited on a per source file basis. LTO also has the possibility of providing greater space savings too. Plus in the case of Clang, LTO for the kernel is also needed to support Control Flow Integrity (CFI) for the kernel.

The Clang LTO support for the Linux kernel is well tested both in full LTO mode and LLVM's ThinLTO. Google in fact has been making use of the Clang LTO support for compiling their production Android kernel builds for quite some time now and has proven to be stable and yield the desired benefits.

So today with much excitement was the Clang LTO support merged by Linus Torvalds. That included the core changes plus enabling it for AArch64.

But then making things even more exciting were the "part two" patches getting Clang LTO going on Linux x86_64 kernel builds. Linus already merged that as well.

So long story short, Linux 5.12 will allow Clang LTO-optimized kernel builds for greater performance and enabling additional functionality like CFI. I'll be running some Clang LTO kernel comparison benchmarks after the merge window has passed.

The short steps for enabling a Linux kernel Clang LTO build are:
make LLVM=1 LLVM_IAS=1 defconfig
scripts/config -e LTO_CLANG_THIN
make LLVM=1 LLVM_IAS=1
Related News
About The Author
Author picture

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 or contacted via MichaelLarabel.com.

Popular News This Week