Skip to content

kbuild: rust: provide an option to inline C helpers into Rust

Gary Guo linux-kbuild lkml llvm rust-for-linux 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 5 repliesIn review
  2. v23 patches 10 repliesSuperseded
  3. v11 patch 5 repliesApplied

Changes in v3 from the cover letter

- Rebased and add __rust_helper for new helpers.
- Improved commit messages and add several comments, including explaination on why target is considered incompatible by LLVM.
- Drop the ReallocFunc::call patch as it's already taken.
- Link to v2:
https://lore.kernel.org/rust-for-linux/[email protected]/

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE`init/Kconfig+15 -01 reply
2/2kbuild: rust: provide an option to inline C helpers into RustMakefile lib/Kconfig.debug rust/Makefile +30 more+201 -974 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAndreas HindborgTamir Duberstein
1/2R-b R-b
2/2R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/2] kbuild: rust: provide an option to inline C helpers into Rust

Currently we have quite a few helper function to aid calling from Rust into inline/macro functions in C. These functions are typically implemented with macros or inline functions because we want them to be fast, so we want to actually have them inlined without the additional function call overhead. However, we also don't want to re-implement these functions in Rust to avoid accidental behaviour divergence.

This series add an option RUST_INLINE_HELPERS to inline C helpers into Rust. This is similar to LTO, but we perform the extra inlining and optimisation per Rust crate (compilation unit) instead of at final linking time, thus has better compilation speed. It also means that this presented approach work for loadable modules as well.

This option can only be enabled when Clang is used as C compiler, and that the LLVM major version between Clang and Rust matches.

Changes from v2:
- Rebased and add __rust_helper for new helpers.
- Improved commit messages and add several comments, including explaination on why target is considered incompatible by LLVM.
- Drop the ReallocFunc::call patch as it's already taken.
- Link to v2:
https://lore.kernel.org/rust-for-linux/[email protected]/

Changes from v1:
- Added LLVM version compatibility check
- Adapted to account for newly added helpers and removal of alloc crate.
- Added a patch to make ReallocFunc::call which prevents some helpers from being inlined.
- Link to v1:
https://lore.kernel.org/rust-for-linux/[email protected]/

Gary Guo (2):
kbuild: rust: add CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE
kbuild: rust: provide an option to inline C helpers into Rust

 Makefile                     |  4 +++-
 init/Kconfig                 | 15 +++++++++++++
 lib/Kconfig.debug            | 14 ++++++++++++
 rust/Makefile                | 34 ++++++++++++++++++++++++++----
 rust/exports.c               |  5 ++++-
 rust/helpers/blk.c           |  5 +++--
 rust/helpers/bug.c           |  3 ++-
 rust/helpers/build_bug.c     |  3 ++-
 rust/helpers/cred.c          |  5 +++--
 rust/helpers/device.c        |  6 +++---
 rust/helpers/err.c           |  7 +++---
 rust/helpers/fs.c            |  3 ++-
 rust/helpers/helpers.h       | 13 ++++++++++++
 rust/helpers/io.c            | 41 ++++++++++++++++++++----------------
 rust/helpers/jump_label.c    |  3 ++-
 rust/helpers/kunit.c         |  3 ++-
 rust/helpers/mutex.c         | 10 +++++----
 rust/helpers/page.c          |  8 ++++---
 rust/helpers/pci.c           |  8 ++++---
 rust/helpers/pid_namespace.c |  9 +++++---
 rust/helpers/platform.c      |  7 ++++--
 rust/helpers/rbtree.c        |  6 ++++--
 rust/helpers/rcu.c           |  5 +++--
 rust/helpers/refcount.c      |  7 +++---
 rust/helpers/security.c      |  9 +++++---
 rust/helpers/signal.c        |  3 ++-
 rust/helpers/slab.c          |  9 ++++----
 rust/helpers/spinlock.c      | 14 ++++++------
 rust/helpers/task.c          | 23 ++++++++++----------
 rust/helpers/uaccess.c       |  9 ++++----
 rust/helpers/vmalloc.c       |  5 +++--
 rust/helpers/wait.c          |  3 ++-
 rust/helpers/workqueue.c     |  9 +++++---
 scripts/Makefile.build       |  5 ++++-
 34 files changed, 216 insertions(+), 97 deletions(-)
 create mode 100644 rust/helpers/helpers.h

base-commit: cf25bc61f8aecad9b0c45fe32697e35ea4b13378

Signature · 1 line
2.47.2