All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Murphy <murp@redhat.com>
To: "Nathan Chancellor" <nathan@kernel.org>,
	"Nicolas Schier" <nsc@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Luis Augenstein" <luis.augenstein@tngtech.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Andrew Jones" <andrew.jones@linux.dev>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH v2] rust: enable fentry support
Date: Wed, 12 Aug 2026 15:16:06 -0500	[thread overview]
Message-ID: <20260812201613.1783592-1-murp@redhat.com> (raw)

Turn it on if CONFIG_HAVE_FENTRY=y and rustc supports a compatible
fentry option. Nightly rustc supports fentry, fentry-record, and
fentry-nop-record. These are equivalent gcc's -mfentry, -mfentry
-mrecord-mcount, and -mfentry -mnop-mcount -mrecord-mcount.

Rust 1.98 adds support for x86 and s390x targets for
-Zinstrument-mcount=fentry.

Rust nightly supports all three options on s390. x86 supports only
fentry (this is a limitation of the x86 llvm backend). The expanded
options should arrive with Rust 1.99.

Signed-off-by: Paul Murphy <murp@redhat.com>
Link: https://github.com/rust-lang/rust/pull/152122
Link: https://github.com/rust-lang/rust/pull/158036
Link: https://github.com/rust-lang/rust/pull/160184

---

Changes in v2:
- Refactor for consistency
- Export RUSTC_FLAGS_FTRACE
- When FTRACE_MCOUNT_USE_CC is set, use rust's extended fentry support
  if supported or not at all.
- Link to v1: https://lore.kernel.org/rust-for-linux/20260724170132.3783816-1-murp@redhat.com/
---
 Makefile                        | 20 +++++++++++++++++++-
 scripts/generate_rust_target.rs |  2 ++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index bfb47ad8cb9a..7ece5a327c53 100644
--- a/Makefile
+++ b/Makefile
@@ -832,9 +832,11 @@ endif # KBUILD_EXTMOD
 # Defaults to vmlinux, but the arch makefile usually adds further targets
 all: vmlinux
 
-# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
+# The arch Makefiles can override CC_FLAGS_FTRACE or RUSTC_FLAGS_FTRACE.
+# We may also append them later.
 ifdef CONFIG_FUNCTION_TRACER
   CC_FLAGS_FTRACE := -pg
+  RUSTC_FLAGS_FTRACE :=
 endif
 
 ifdef CONFIG_TRACEPOINTS
@@ -1053,10 +1055,26 @@ ifdef CONFIG_HAVE_FENTRY
     CC_FLAGS_FTRACE	+= -mfentry
     CC_FLAGS_USING	+= -DCC_USING_FENTRY
   endif
+  ifdef CONFIG_FTRACE_MCOUNT_USE_CC
+    # Support for mcount record/nop is not gated by rustc version for all architectures.
+    ifdef CONFIG_HAVE_NOP_MCOUNT
+      ifeq ($(call rustc-option-yn, -Zinstrument-mcount=fentry-nop-record),y)
+        RUSTC_FLAGS_FTRACE += -Zinstrument-mcount=fentry-nop-record
+      endif
+    else
+      ifeq ($(call rustc-option-yn, -Zinstrument-mcount=fentry-record),y)
+        RUSTC_FLAGS_FTRACE += -Zinstrument-mcount=fentry-record
+      endif
+    endif
+  else
+      RUSTC_FLAGS_FTRACE += $(if $(call rustc-min-version,109800),-Zinstrument-mcount=fentry,)
+  endif
 endif
 export CC_FLAGS_FTRACE
+export RUSTC_FLAGS_FTRACE
 KBUILD_CFLAGS	+= $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
 KBUILD_AFLAGS	+= $(CC_FLAGS_USING)
+KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_FTRACE)
 endif
 
 # We trigger additional mismatches with less inlining
diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
index 3bf296581a88..eb80a06d50d3 100644
--- a/scripts/generate_rust_target.rs
+++ b/scripts/generate_rust_target.rs
@@ -198,6 +198,7 @@ fn main() {
         ts.push("arch", "x86_64");
         if cfg.rustc_version_atleast(1, 98, 0) {
             ts.push("rustc-abi", "softfloat");
+            ts.push("supports-fentry", true);
         } else if cfg.rustc_version_atleast(1, 86, 0) {
             ts.push("rustc-abi", "x86-softfloat");
         }
@@ -240,6 +241,7 @@ fn main() {
         ts.push("arch", "x86");
         if cfg.rustc_version_atleast(1, 98, 0) {
             ts.push("rustc-abi", "softfloat");
+            ts.push("supports-fentry", true);
         } else if cfg.rustc_version_atleast(1, 86, 0) {
             ts.push("rustc-abi", "x86-softfloat");
         }

base-commit: 7059bdf4f04a3e14f4fafb3ac35fdca913e3e21a
-- 
2.55.0


                 reply	other threads:[~2026-08-12 20:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260812201613.1783592-1-murp@redhat.com \
    --to=murp@redhat.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=andrew.jones@linux.dev \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=justinstitt@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=llvm@lists.linux.dev \
    --cc=lossin@kernel.org \
    --cc=luis.augenstein@tngtech.com \
    --cc=masahiroy@kernel.org \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.