From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Gary Guo" <gary@garyguo.net>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
=?utf-8?Q?Bj=C3=B6rn?= Roy Baron <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Nicolas Schier" <nicolas@fjasle.eu>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Dirk Behme" <dirk.behme@de.bosch.com>,
"Tamir Duberstein" <tamird@gmail.com>,
"Christian Brauner" <brauner@kernel.org>,
"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
"Paul Moore" <paul@paul-moore.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Steven Rostedt (Google)" <rostedt@goodmis.org>,
"Matt Gilbride" <mattgilbride@google.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Eder Zulian" <ezulian@redhat.com>,
"Filipe Xavier" <felipe_life@live.com>,
rust-for-linux@vger.kernel.org, llvm@lists.linux.dev,
"Kees Cook" <kees@kernel.org>, "Daniel Xu" <dxu@dxuuu.xyz>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] kbuild: rust: provide an option to inline C helpers into Rust
Date: Tue, 07 Jan 2025 12:31:32 +0100 [thread overview]
Message-ID: <87msg26fxt.fsf@kernel.org> (raw)
In-Reply-To: <20250105194054.545201-3-gary@garyguo.net> (Gary Guo's message of "Sun, 05 Jan 2025 19:40:05 +0000")
"Gary Guo" <gary@garyguo.net> writes:
> A new Kconfig option, `RUST_INLINE_HELPERS` is added to allow C helpers
> (which was 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 a global LTO.
>
> If the option is enabled, the following is performed:
> * For helpers, instead of compiling them to object file to be linked
> into vmlinux, we compile them to LLVM IR.
> * The LLVM IR is patched to add `linkonce_odr` linkage. This linkage
> means that the function is 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 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 object file.
>
> Some caveats with the option:
> * clang and Rust doesn't have the exact target string. Manual inspection
> shows that they should be compatible, but since they are not exactly
> the same LLVM seems to prefer not inlining them. This is bypassed with
> `--ignore-tti-inline-compatible`.
> * LLVM doesn't want to inline functions combined with
> `-fno-delete-null-pointer-checks` with code compiled without. So we
> remove this command when compiling helpers. I think this should be
> okay since this is one of the hardening features and we shouldn't have
> null pointer dereferences in these helpers.
>
> The checks can also be bypassed with force inlining (`__always_inline`)
> but the behaviour is the same with extra options.
>
> Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Tested with downstream rnull tree, works as expected.
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-01-07 11:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250105194054.545201-1-gary@garyguo.net>
2025-01-05 19:40 ` [PATCH v2 1/3] kbuild: rust: add `CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE` Gary Guo
2025-01-06 9:02 ` Alice Ryhl
2025-01-07 11:29 ` Andreas Hindborg
2025-01-05 19:40 ` [PATCH v2 2/3] kbuild: rust: provide an option to inline C helpers into Rust Gary Guo
2025-01-06 6:08 ` Randy Dunlap
2025-01-07 11:31 ` Andreas Hindborg [this message]
2025-03-06 23:00 ` Tamir Duberstein
2025-03-19 21:31 ` Gary Guo
2025-01-05 19:40 ` [PATCH v2 3/3] rust: alloc: make `ReallocFunc::call` inline Gary Guo
2025-01-06 17:42 ` Boqun Feng
2025-01-07 10:15 ` Danilo Krummrich
2025-01-07 10:21 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87msg26fxt.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=dakr@kernel.org \
--cc=dirk.behme@de.bosch.com \
--cc=dxu@dxuuu.xyz \
--cc=ezulian@redhat.com \
--cc=felipe_life@live.com \
--cc=gary@garyguo.net \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=masahiroy@kernel.org \
--cc=mattgilbride@google.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nicolas@fjasle.eu \
--cc=ojeda@kernel.org \
--cc=paul@paul-moore.com \
--cc=rostedt@goodmis.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
--cc=yakoyoku@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).