Commit 315f8edb authored by Gary Guo's avatar Gary Guo Committed by Matthew Maurer
Browse files

FROMLIST: build: rust: provide an option to inline C helpers into Rust

A new experimental Kconfig option, `RUST_INLINE_HELPERS` is added to
allow C helpers (which were created to allow Rust to call into
inline/macro C functions without having to re-implement the logic in
Rust) to be inlined into Rust crates without performing global LTO.

If the option is enabled, the following is performed:
* For helpers, instead of compiling them to an object file to be linked
  into vmlinux, they're compiled to LLVM IR.
* The LLVM IR is patched to add `linkonce_odr` linkage. This linkage
  means that functions are inlineable (effect of `_odr`), and the
  symbols generated will have weak linkage if emitted into object file
  (important since as later described, we might have multiple copies of
  the same symbol) and it will may be discarded if it is not invoked or
  all invocations are inlined.
* The LLVM IR is compiled to bitcode (This is step is not necessary, but
  is a performance optimisation to prevent LLVM from always have to
  reparse the same IR).
* When a Rust crate is compiled, instead of generating an object file, we
  ask LLVM bitcode to be generated.
* llvm-link is invoked to combine the helper bitcode with the crate
  bitcode. This step is similar to LTO, but this is much faster since it
  only needs to inline the helpers.
* clang is invoked to turn the combined bitcode into a final object file.

Bug: 454054050
Link: https://lore.kernel.org/all/20250319205141.3528424-3-gary@garyguo.net/


Change-Id: I7201dfe429e5e5d592c0904138a226319a8b3d23
Co-developed-by: default avatarBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: default avatarBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: default avatarGary Guo <gary@garyguo.net>
[ maurer - fixed conflicts and matched __rust_helpers to helpers/* ]
Signed-off-by: default avatarMatthew Maurer <mmaurer@google.com>
parent 9077fcbc
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment