Linux kbuild/kconfig development
 help / color / mirror / Atom feed
* [PATCH v2] rust: enable fentry support
@ 2026-08-12 20:16 Paul Murphy
  0 siblings, 0 replies; only message in thread
From: Paul Murphy @ 2026-08-12 20:16 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan,
	Nick Desaulniers, Bill Wendling, Justin Stitt,
	Thomas Weißschuh, Luis Augenstein, Steven Rostedt,
	Masahiro Yamada, Andrew Jones, linux-kbuild, linux-kernel,
	rust-for-linux, llvm

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-12 20:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12 20:16 [PATCH v2] rust: enable fentry support Paul Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox