Linux 7.0 Readying Improvement For Rust + LTO Kernel Builds
- Reference: 0001605252
- News link: https://www.phoronix.com/news/Linux-Rust-LTO-Inline-Coming
- Source link:
This work to inline C helpers into Rust when using LTO involves adding a "__rust_helper" annotation to every Rust helper within the kernel. This "__rust_helper" is needed since C helpers cannot be inlined into Rust when using LTO because LLVM detects slightly different options on the code generation units.
In turn when using LTO for the kernel builds, "__always_inline" will be added to the helpers except when running bindgen to avoid an issue there with ignoring functions markd as inline. There is a [1]46 patch series for applying this "__rust_helper" where needed throughout the kernel code. Those patches don't need to be merged in one-go and thus left up to the individual subsystem maintainers for taking the patches but at least some of them are set for merging with Linux 7.0.
Via the [2]vfs-7.0.rust Git branch of VFS.git, the patches there have been taken for inlining the C helpers into Rust. We'll see if the full patch series via the different branches all get accepted for this next kernel cycle or will take longer to upstream it all. A separate patch will then take to wiring up the "__rust_helper" behavior.
Separately, for those wondering about the performance benefits of using Link Time Optimizations when building the Linux kernel with LLVM/Clang, recently I ran some fresh benchmarks within [3]Some Meaningful Performance Benefits For Clang + LTO Built Linux Kernels .
[1] https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/commit/?h=vfs-7.0.rust&id=5334fc280735dcf5882511a219a99b5759e14870
[3] https://www.phoronix.com/review/linux-kernel-llvm-clang-lto