From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87ABF382F15 for ; Wed, 12 Aug 2026 20:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786565792; cv=none; b=FxIBs3/MDSvonH3gxEEG+5ldl5GlY8QbQzn9WVdZ6U++88Ob1Lj4nnIBTeV9a8npU7qYZL3v1xpvbQ47s4hIE3bXBg0xi1xEZbe4UjhOV8ot11NraP9Sf81VfZPDWqMSVodWt2Gy8YU6JJbyYsOoxRjS2/1lk9vAN/W67wfJTb4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786565792; c=relaxed/simple; bh=AiVQmdE36y6QXny0Mmw4Gw6HubeIeMk4S/c50LTZycs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=l+KhSdFwJz6I/qJSMFeLGj4uVJEsj4G1Antp5/Vm1/JVAa1Oc0WRoK8Rbm5GQIfuHPbJQAHNNFhcxigqNTok7F1QOJfd145ENBk8tXVZEtNSkJDPBoGSNbsPd//UhNLPCNs2uAUCP9fEhXGf+MS4AjjrgW0zvUvijtD7yyF2pwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KF9dWu1u; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KF9dWu1u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786565789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gbcpa277ERO4n9n/VE9xEGfG5jSz1Qxd5sN8vPZTwBk=; b=KF9dWu1uIDyrw0R+zS2N4yzyQ0LaaYZheRZXXPYIHQ9VXKvq2PNv7ftb2c3gyr1nIq29YM vElbb6okF2Bky59yIOaOJyiWd5T8urcQZNw1/O9nnWqILzgQMlgKEfKJEe6H1X3JIC9YCG Ny7EhncavddCjjhykACSMMHcZmh6LnM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-Rs2ig2MqOKyLS9wXj7Lc7A-1; Wed, 12 Aug 2026 16:16:24 -0400 X-MC-Unique: Rs2ig2MqOKyLS9wXj7Lc7A-1 X-Mimecast-MFC-AGG-ID: Rs2ig2MqOKyLS9wXj7Lc7A_1786565780 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A9E0C19560B5; Wed, 12 Aug 2026 20:16:19 +0000 (UTC) Received: from paumurph-thinkpadp1gen7.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C6151800348; Wed, 12 Aug 2026 20:16:14 +0000 (UTC) From: Paul Murphy To: Nathan Chancellor , Nicolas Schier , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , Nick Desaulniers , Bill Wendling , Justin Stitt , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Luis Augenstein , Steven Rostedt , Masahiro Yamada , Andrew Jones , 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 Message-ID: <20260812201613.1783592-1-murp@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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 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