From nobody Sun Feb 8 16:31:15 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8D0D22F1C for ; Sat, 23 Nov 2024 00:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732321168; cv=none; b=EA+45VTe4OOWZ4CDyyqjDa+B0K/jiGXuWNFVEqbZK7MbxdDZ9UhCrs8QF7Pfa4oZ8lKb6GxXRT/hWPsJuYdomIa4Br93W7m113K4wEbVyZLa2kJhNOSRrgza4tNXQn8/D3kM24UtwRrb05nr+33Qc7wI/9gwEE0f87G5K9s3WPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732321168; c=relaxed/simple; bh=PQ7BWLWokR6IGFsP7MriMLRRm+M2pMmO0KrDpLKXuSE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nIaPnghr+TOOhQhR+keeCJIZBaVuZaULG32WstsALPXB+MFgXAfqndwZjc0EnxO9PKn9wo6VqQ4KmjypJPe4vF1FG0yRff1xmovmd5Q7K3r2+59e6rYJ79Apmc8I+TDrSLz6FArTYAt6oTl9+5oc+AKxnvHcC6wWfHGmAtlZOkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NihGDptW; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NihGDptW" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02b5792baaso4158779276.2 for ; Fri, 22 Nov 2024 16:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732321166; x=1732925966; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=D3SgXuWoWK4BO6s3M/0azb/Xt7N95+oJhCSHs7onn8k=; b=NihGDptW9vpAuiqofIJu9xrjbb668IEeziLlXNVE1nj6gRo7lRGbmNH+ZpsxEcaFT7 Pm77HjX4yGO9QbILF1TeEXSNIaIgUWhN+Ot1DgKFNjUTabznvNJVHmtXQ5TOoafnhN9d MhxLBxuiIr431DMrKorX1JXN54IWfJB7f0PaDidBweR3dL/ig0JYfIBXBPRafVcNryiq r2TrqYv6KaBVqBvb/6My58C0AH3LRO/A6iWYuLaIhCZ02haA+xorOV870ML9IeBL1/hH BCREJ7fVPtze2ZUdoJSf8WxoBb9/x9M7RucvWA+e++PJ0u2SxjbfE+QQLKUjtkT3QQbc Id/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732321166; x=1732925966; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D3SgXuWoWK4BO6s3M/0azb/Xt7N95+oJhCSHs7onn8k=; b=I0g5HSk5OMB7Z/SHDlYqUawQBgg1xAp7NlVx1Tb5/IIkCPu4ghs2PbRwYmJwBSbXX4 91zzosvkpm4YQuTKmbaBx9VpYOGNs4oeQ3BLi/xWJp1ungYEZMDRMicfdRCzBnJRAo5R OwzayEIJz/1dZK+sSwufgZins4EJTacJcD0YPIGTnj28EcqwV5wrJB2d8IhZ5+8wQ1MH 2SMjTskvRRQ732+w9gcgPrtdYmffCmQtGRAVCd66syM/moTpjuCluFiQg0GNwVmSWnf8 BWblMBhRpIlOkoizOoNWGNFMPWX35cAebADpAut6GlR/eHVi0KgO3p65AmBcD3+/5Y6l uIAA== X-Forwarded-Encrypted: i=1; AJvYcCXruSZoF9Ys5aSh0lsD0thwc3TtYBYuwDRwe+Kwhpyi2b98/7H3OGjqA5/Zv9KO1UTPm3TuBOmm+qp6P/k=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ04YwfGBDVsTa80AdXrVCk/Xp9xsVjCrWltal4nZpl92aaF5r /bmZ8navdEpDD74vo8PhkF+zDOCo56/WpabJrFwqWZQvcUHWLytO75lrBOyBh3Xhh8IZ+1gDXy6 i9G6/Fw== X-Google-Smtp-Source: AGHT+IFASTUqLlC21MX7tf98zKEIqUbvVG9QZO9snVRK1MZEWyuq2nupvFJacSFrArEoQiOGv1QJT6Re3Cl/ X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a25:8c85:0:b0:e2e:3401:ea0f with SMTP id 3f1490d57ef6-e38f8be09dbmr2980276.7.1732321165984; Fri, 22 Nov 2024 16:19:25 -0800 (PST) Date: Sat, 23 Nov 2024 00:19:02 +0000 In-Reply-To: <20241123-extended-modversions-v9-0-bc0403f054bf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241123-extended-modversions-v9-0-bc0403f054bf@google.com> X-Mailer: b4 0.15-dev Message-ID: <20241123-extended-modversions-v9-5-bc0403f054bf@google.com> Subject: [PATCH v9 5/5] rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS From: Matthew Maurer To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Jonathan Corbet Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, Matthew Maurer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Sami Tolvanen Previously, two things stopped Rust from using MODVERSIONS: 1. Rust symbols are occasionally too long to be represented in the original versions table 2. Rust types cannot be properly hashed by the existing genksyms approach because: * Looking up type definitions in Rust is more complex than C * Type layout is potentially dependent on the compiler in Rust, not just the source type declaration. CONFIG_EXTENDED_MODVERSIONS addresses the first point, and CONFIG_GENDWARFKSYMS the second. If Rust wants to use MODVERSIONS, allow it to do so by selecting both features. Signed-off-by: Sami Tolvanen Co-developed-by: Matthew Maurer Signed-off-by: Matthew Maurer --- init/Kconfig | 3 ++- rust/Makefile | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index a20e6efd3f0fbdd7f0df2448854cc30734a0ee4f..2cfbefe0933ed129fdc1cca4121= 183e6285840d3 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1956,7 +1956,8 @@ config RUST bool "Rust support" depends on HAVE_RUST depends on RUST_IS_AVAILABLE - depends on !MODVERSIONS + select EXTENDED_MODVERSIONS if MODVERSIONS + depends on !MODVERSIONS || GENDWARFKSYMS depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE diff --git a/rust/Makefile b/rust/Makefile index 9da9042fd62796ddb852f4bf7cf46d70f0b8ca97..397ce424a0509c2a1b4ebccd5d4= 30b86b4ecbac6 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -316,10 +316,11 @@ $(obj)/bindings/bindings_helpers_generated.rs: privat= e bindgen_target_extra =3D ; $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FO= RCE $(call if_changed_dep,bindgen) =20 +rust_exports =3D $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$= 3!~/__cfi/ { printf $(2),$(3) }' + quiet_cmd_exports =3D EXPORTS $@ cmd_exports =3D \ - $(NM) -p --defined-only $< \ - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%= s);\n",$$3}' > $@ + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3) > $@ =20 $(obj)/exports_core_generated.h: $(obj)/core.o FORCE $(call if_changed,exports) @@ -388,11 +389,36 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(C= ONFIG_64BIT))),) __ashlti3 __lshrti3 endif =20 +ifdef CONFIG_MODVERSIONS +cmd_gendwarfksyms =3D $(if $(skip_gendwarfksyms),, \ + $(call rust_exports,$@,"%s\n",$$3) | \ + scripts/gendwarfksyms/gendwarfksyms \ + $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) \ + $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=3D.symtypes),) \ + $@ >> $(dot-target).cmd) +endif + define rule_rustc_library $(call cmd_and_fixdep,rustc_library) $(call cmd,gen_objtooldep) + $(call cmd,gendwarfksyms) endef =20 +define rule_rust_cc_library + $(call if_changed_rule,cc_o_c) + $(call cmd,force_checksrc) + $(call cmd,gendwarfksyms) +endef + +# helpers.o uses the same export mechanism as Rust libraries, so ensure sy= mbol +# versions are calculated for the helpers too. +$(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) = FORCE + +$(call if_changed_rule,rust_cc_library) + +# Disable symbol versioning for exports.o to avoid conflicts with the actu= al +# symbol versions generated from Rust objects. +$(obj)/exports.o: private skip_gendwarfksyms =3D 1 + $(obj)/core.o: private skip_clippy =3D 1 $(obj)/core.o: private skip_flags =3D -Wunreachable_pub $(obj)/core.o: private rustc_objcopy =3D $(foreach sym,$(redirect-intrinsi= cs),--redefine-sym $(sym)=3D__rust$(sym)) @@ -404,13 +430,16 @@ ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) $(obj)/core.o: scripts/target.json endif =20 +$(obj)/compiler_builtins.o: private skip_gendwarfksyms =3D 1 $(obj)/compiler_builtins.o: private rustc_objcopy =3D -w -W '__*' $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE +$(call if_changed_rule,rustc_library) =20 +$(obj)/build_error.o: private skip_gendwarfksyms =3D 1 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FOR= CE +$(call if_changed_rule,rustc_library) =20 +$(obj)/ffi.o: private skip_gendwarfksyms =3D 1 $(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_rule,rustc_library) =20 @@ -422,6 +451,7 @@ $(obj)/bindings.o: $(src)/bindings/lib.rs \ +$(call if_changed_rule,rustc_library) =20 $(obj)/uapi.o: private rustc_target_flags =3D --extern ffi +$(obj)/uapi.o: private skip_gendwarfksyms =3D 1 $(obj)/uapi.o: $(src)/uapi/lib.rs \ $(obj)/ffi.o \ $(obj)/uapi/uapi_generated.rs FORCE --=20 2.47.0.371.ga323438b13-goog