Skip to content

Inline helpers into Rust without full LTO

Alice Ryhl driver-core linux-arm-kernel linux-iommu linux-kbuild linux-mm linux-um lkml llvm rust-for-linux soc 2 versions – Applied

Status from this message: Applied to `rust-next` -- thanks everyone!

Get series with b4
b4 am [email protected] change-id 20251202-inline-helpers-996f4db65e18

Versions newest first

  1. v2 Latest3 patches 53 repliesApplied
  2. v14 patches 24 repliesSuperseded

Changes in v2 from the cover letter

- Dropped merged patches.
- Generate two copies of helpers.bc, one for built-in and one for modules.
- Remove unused llvm-as tool.
- Add $(cmd_ld_single) to avoid breaking CONFIG_LTO builds (note that
LTO does not happen over the language boundary, except for helpers).
- Improve Kconfig help message.
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`init/Kconfig+15 -05 replies
2/3rust: helpers: #define __rust_helperrust/helpers/helpers.c+29 -01 reply
3/3build: rust: provide an option to inline C helpers into RustMakefile lib/Kconfig.debug rust/Makefile +2 more+52 -76 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAndreas HindborgNicolas SchierNathan Chancellor
SeriesT-b R-b
1/3R-b R-b T-b R-b T-b
2/3R-b T-b
3/3R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/3] Inline helpers into Rust without full LTO

Currently the only way for Rust code to call a static inline function is to go through a helper in rust/helpers/. This introduces performance costs due to additional function calls and also clutters backtraces and flame graphs with helper symbols.

To get rid of these helper symbols, provide functionality to inline helpers into Rust using llvm-link. This option complements full LTO, by being much cheaper and avoiding incompatibility with BTF.

I ran a microbenchmark showing the benefit of this. All the benchmark does is call refcount_inc() in a loop. This was chosen since refcounting is quite hot in Binder. The results are that Rust spends 6.35 ns per call vs 5.73 ns per call in C. When enabling this option, the two languages become equally fast, and disassembly confirms the exact same machine code is used (in particular there is no call to rust_helper_refcount_inc). Benchmarking Binder also results in an improvement from this change.

This patch is complementary to:
https://lore.kernel.org/all/[email protected]/

---
Changes in v2:
- Dropped merged patches.
- Generate two copies of helpers.bc, one for built-in and one for modules.
- Remove unused llvm-as tool.
- Add $(cmd_ld_single) to avoid breaking CONFIG_LTO builds (note that
LTO does not happen over the language boundary, except for helpers).
- Improve Kconfig help message.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Gary Guo (3):
kbuild: rust: add CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE
rust: helpers: #define __rust_helper
build: rust: provide an option to inline C helpers into Rust

 Makefile               |  3 ++-
 init/Kconfig           | 15 +++++++++++++++
 lib/Kconfig.debug      | 15 +++++++++++++++
 rust/Makefile          | 29 +++++++++++++++++++++++++----
 rust/exports.c         |  5 ++++-
 rust/helpers/helpers.c | 29 +++++++++++++++++++++++++++++
 scripts/Makefile.build |  7 ++++++-
 7 files changed, 96 insertions(+), 7 deletions(-)

---
base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215
change-id: 20251202-inline-helpers-996f4db65e18

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>