]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Merge patch series "Allow inlining C helpers into Rust when using LTO"
authorChristian Brauner <brauner@kernel.org>
Thu, 4 Dec 2025 10:04:24 +0000 (11:04 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 15 Dec 2025 13:13:04 +0000 (14:13 +0100)
Alice Ryhl <aliceryhl@google.com> says:

This patch series adds __rust_helper to every single rust helper.

These changes were generated by adding __rust_helper and running
ClangFormat. Unrelated formatting changes were removed manually.

Why is __rust_helper needed?
============================

Currently, C helpers cannot be inlined into Rust even when using LTO
because LLVM detects slightly different options on the codegen units.

* LLVM doesn't want to inline functions compiled with
  `-fno-delete-null-pointer-checks` with code compiled without. The C
  CGUs all have this enabled and Rust CGUs don't. Inlining is okay since
  this is one of the hardening features that does not change the ABI,
  and we shouldn't have null pointer dereferences in these helpers.

* LLVM doesn't want to inline functions with different list of builtins. C
  side has `-fno-builtin-wcslen`; `wcslen` is not a Rust builtin, so
  they should be compatible, but LLVM does not perform inlining due to
  attributes mismatch.

* clang and Rust doesn't have the exact target string. Clang generates
  `+cmov,+cx8,+fxsr` but Rust doesn't enable them (in fact, Rust will
  complain if `-Ctarget-feature=+cmov,+cx8,+fxsr` is used). x86-64
  always enable these features, so they are in fact the same target
  string, but LLVM doesn't understand this and so inlining is inhibited.
  This can be bypassed with `--ignore-tti-inline-compatible`, but this
  is a hidden option.

(This analysis was written by Gary Guo.)

How is this fixed?
==================

To fix this we need to add __always_inline to all helpers when compiling
with LTO. However, it should not be added when running bindgen as
bindgen will ignore functions marked inline. To achieve this, we are
using a #define called __rust_helper that is defined differently
depending on whether bindgen is running or not.

Note that __rust_helper is currently always #defined to nothing.
Changing it to __always_inline will happen separately in another patch
series.

* patches from https://patch.msgid.link/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com:
  rust: poll: add __rust_helper to helpers
  rust: pid_namespace: add __rust_helper to helpers
  rust: fs: add __rust_helper to helpers

Link: https://patch.msgid.link/20251202-define-rust-helper-v1-0-a2e13cbc17a6@google.com
Signed-off-by: Christian Brauner <brauner@kernel.org>

Trivial merge