rust: enable fentry support
PATCH v2 1/1 rust: enable fentry support
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.
---
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/[email protected]/
--- Makefile | 20 +++++++++++++++++++- scripts/generate_rust_target.rs | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-)
Makefile +19 -1
@@ -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
scripts/generate_rust_target.rs +2 -0
@@ -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
Signature · 1 line
2.55.0