Clang LTO Support Looks Like It Could Land For Linux 5.12

Written by Michael Larabel in Linux Kernel on 11 January 2021 at 03:18 PM EST. 25 Comments
LINUX KERNEL
The support for Clang LTO of the Linux kernel for link-time optimizations when using that GCC alternative compiler looks like it will land with Linux 5.12.

For a number of months the Clang LTO wiring to the Linux kernel has been undergoing rounds of review and of interest from multiple parties. Vendors like Google already make use of Clang link-time optimizations as part of their kernel builds on mobile devices. There's been much interest and it looks like for Linux 5.12 that work will likely land -- it's been queued into a "-next" branch ahead of the Linux 5.12 merge window in February.

Kees Cook of Google has queued the work by Sami Tolvanen (also of Google) for Clang LTO'ing the kernel. The patches are currently part of for-next/kspp. So barring any major issues from coming up or new criticism coming to light, the work will likely be sent in for the next merge window (5.12).

This support allows both "full" link-time optimizations as well as LLVM's ThinLTO support. For the moment though this support is just in place for 64-bit ARM (AArch64) and not x86_64. The support can be configured via Kconfig on supported architectures.

The Clang LTO full build of the Linux kernel should yield "the best runtime performance" but quite time consuming as well as a lot of RAM consumption thus ThinLTO also being supported.

This work also lays the groundwork for potentially supporting GCC LTO of the Linux kernel too thanks to some common "CONFIG_LTO" knobs being added but the GCC compiler support isn't part of this pull. In the past from Intel and others we have seen GCC LTO for the Linux kernel proposed albeit never made it to mainline for merging.

Compiler link-time optimizations are great in the name of performance while this LTO support in the kernel is also needed for Clang Control-Flow Integrity (CFI) enforcement as a security feature. Google has been Clang LTO'ing (with CFI) their Linux kernel builds for Android devices since 2018.
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