From nobody Wed Nov 27 18:42:41 2024 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 0B63D213ED7 for ; Tue, 8 Oct 2024 18:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728412752; cv=none; b=TnDFXTR+S5bj+O+oGol8aSFcUoJNF60dHnlfGHdoX3IWwxS9rcxtZKs9vxwFsPuclwLmejQlQICgDhZXuoh8y7uTKMUWe1ZGMf/5HdH8OBsHlsMFceCb0bpkd4b3Jx0Csr2kBXWfbBYlIBK2eEZ7LUj3gOjsArLrtQvNxvBpLjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728412752; c=relaxed/simple; bh=cu13kRY3+mJ5cZSxocHr5Yb/1rJZvzr4RQDiYdBp4Ok=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qlRySq4Tei7TlHSSB8Slz7e6EmOSrLjysIDtgSIWjza91lhAtodc9JY7CLAaXYGuhkgH04C///X0AxIAZK2AlubGFAhY14A9iznJjt09lrYFnQQFRjrQsJjR/fF3oyyWiRw8Ydhb5oaCwiH3RcbVvv5QS1/rXkgG11Yd4gv46Vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=f5epyucS; arc=none smtp.client-ip=209.85.215.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--samitolvanen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f5epyucS" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-70ac9630e3aso5116686a12.1 for ; Tue, 08 Oct 2024 11:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728412750; x=1729017550; 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=ZaLa12BRozVfGYk63WojrW4fg6j3chZ7iM5FcwVR/BA=; b=f5epyucS+JMK/n0rZdTd3t1ea+qMaw4ky80HzghouWdnaSLprCO2CfGmNM5o90wwxZ CjnWqtFsszQK5mGqk8Xbv6Bk5Vkscmg9dipR88dM14s0kBYGIQkUPfId5U7NOzoBO0HF iEdhDFC0Dqjp6RvpLJ+CrKfD3Y33PyQBYbZ1j3aLt3wy3kTl8PyrQTzzzPnfDXYoQleX 4RZwyNIibp7trm/qrIlueNuKbGxjAYcuvkLb2dZsDENwI+NICaNnjIG8vSGZGeShoaHI mAHcc9cguN0NecVU0Ljx5KVWYCT0Zde1D7xJiIuj1Y6VFv81TNlkr8QLA7ujPNI7K6IL 6dMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728412750; x=1729017550; 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=ZaLa12BRozVfGYk63WojrW4fg6j3chZ7iM5FcwVR/BA=; b=Duk+C0KIcglS29oTv3ecAM+90s+vcoVZ2DZpXgxYIbLmS7V1iaNu+Wp/wcMCprX73L QEFeL24m3wGcXd3eXIQD7WwkaZHICJZL2RUuSL0xh7J0EMJIGh8JZKXHqt0ZtIEUfrnu 3e7gRPcj9hsUkl0cgK8SE+dGEzkxYsAXxi9vqikHmjXcILLe5vWL9pqGmXDNN7kkB//o Q0NDF7F0DJCh6i0YvotOCfvHLrcQHS7U4QhsIcV+SEyThzFj3/KxCF/jVOaAFJm5jQIv mDyY/35F0VzrXGeh0ef3aUfG/Dw+ejdkMExhbaNjmjNulL+G+p5LhkFP7joC+L4dYSHo 2pIg== X-Forwarded-Encrypted: i=1; AJvYcCVahXDOEOVjnndm47ajtac7Cin5CvFrdhDbJG+4PuuYsm8PCKFV/PfCgieyzXxJnJompoaNSZ0HUUhsW4M=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8aahDv2IT+pF4/E4lFkMyGutb/zJVNriCxWdWrG06B6dX4lbA d2kR5tPc8G9JF4qS0xUmWLebrLfkyxj+Ub02GWyvCVHZtOSmlaXvaPsYFBCqMPIYwIcUx5DAn2x TlZeR0NR043NT9WYz2iBQPxxvdA== X-Google-Smtp-Source: AGHT+IE1ARsuZR5MICYuQmn5iAsWmKU1pOr38cH5bK+78z1447fX+K+DtRTHFCEh7OVqUA+XdHcAISnHPXeFVjGnjgs= X-Received: from samitolvanen.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4f92]) (user=samitolvanen job=sendgmr) by 2002:a65:6886:0:b0:7e6:b6fb:b115 with SMTP id 41be03b00d2f7-7ea32071cb3mr39a12.1.1728412749298; Tue, 08 Oct 2024 11:39:09 -0700 (PDT) Date: Tue, 8 Oct 2024 18:38:42 +0000 In-Reply-To: <20241008183823.36676-21-samitolvanen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241008183823.36676-21-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=5204; i=samitolvanen@google.com; h=from:subject; bh=cu13kRY3+mJ5cZSxocHr5Yb/1rJZvzr4RQDiYdBp4Ok=; b=owGbwMvMwCEWxa662nLh8irG02pJDOmsNZp8M81P/XzpMEt8kXySwOLzX2ZLdotUP123Sc3/v 7SbXpZxRykLgxgHg6yYIkvL19Vbd393Sn31uUgCZg4rE8gQBi5OAZgIuzLDP8UTt/Omhgg/cNPk KU+Jc7P+3HJEPolDMHvB2w12bvNFzzIyPMmYaeRs7mYZvOt4SdHt7Qbt0r1+l5/PrC3o8PZcWcP EBAA= X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241008183823.36676-39-samitolvanen@google.com> Subject: [PATCH v4 18/19] kbuild: Add gendwarfksyms as an alternative to genksyms From: Sami Tolvanen To: Masahiro Yamada , Luis Chamberlain , Miguel Ojeda , Greg Kroah-Hartman Cc: Matthew Maurer , Alex Gaynor , Gary Guo , Petr Pavlu , Daniel Gomez , Neal Gompa , Hector Martin , Janne Grunau , Miroslav Benes , Asahi Linux , Sedat Dilek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, Sami Tolvanen Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When MODVERSIONS is enabled, allow selecting gendwarfksyms as the implementation, but default to genksyms. Signed-off-by: Sami Tolvanen Acked-by: Neal Gompa --- kernel/module/Kconfig | 25 ++++++++++++++++++++++++- scripts/Makefile | 2 +- scripts/Makefile.build | 39 +++++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index f9e5f82fa88b..e6b2427e5c19 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -169,13 +169,36 @@ config MODVERSIONS make them incompatible with the kernel you are running. If unsure, say N. =20 +choice + prompt "Module versioning implementation" + depends on MODVERSIONS + default GENKSYMS + help + Select the tool used to calculate symbol versions for modules. + + If unsure, select GENKSYMS. + +config GENKSYMS + bool "genksyms (from source code)" + help + Calculate symbol versions from pre-processed source code using + genksyms. + + If unsure, say Y. + config GENDWARFKSYMS - bool + bool "gendwarfksyms (from debugging information)" depends on DEBUG_INFO # Requires full debugging information, split DWARF not supported. depends on !DEBUG_INFO_REDUCED && !DEBUG_INFO_SPLIT # Requires ELF object files. depends on !LTO + help + Calculate symbol versions from DWARF debugging information using + gendwarfksyms. Requires DEBUG_INFO to be enabled. + + If unsure, say N. +endchoice =20 config ASM_MODVERSIONS bool diff --git a/scripts/Makefile b/scripts/Makefile index d7fec46d38c0..8533f4498885 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -53,7 +53,7 @@ hostprogs +=3D unifdef targets +=3D module.lds =20 subdir-$(CONFIG_GCC_PLUGINS) +=3D gcc-plugins -subdir-$(CONFIG_MODVERSIONS) +=3D genksyms +subdir-$(CONFIG_GENKSYMS) +=3D genksyms subdir-$(CONFIG_GENDWARFKSYMS) +=3D gendwarfksyms subdir-$(CONFIG_SECURITY_SELINUX) +=3D selinux subdir-$(CONFIG_SECURITY_IPE) +=3D ipe diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 8f423a1faf50..ae13afb71123 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -107,18 +107,28 @@ cmd_cpp_i_c =3D $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) =20 +gendwarfksyms :=3D scripts/gendwarfksyms/gendwarfksyms +getexportsymbols =3D $(NM) $(1) | sed -n 's/.* __export_symbol_\(.*\)/$(2)= /p' + genksyms =3D scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=3D.symref)), /dev/null) =20 # These mirror gensymtypes_S and co below, keep them in synch. +ifdef CONFIG_GENDWARFKSYMS +symtypes_dep_c =3D $(obj)/%.o +cmd_gensymtypes_c =3D $(if $(skip_gendwarfksyms),, \ + $(call getexportsymbols,$(2:.symtypes=3D.o),\1) | \ + $(gendwarfksyms) $(2:.symtypes=3D.o) $(if $(1), --symtypes $(2))) +else cmd_gensymtypes_c =3D $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms) +endif # CONFIG_GENDWARFKSYMS =20 quiet_cmd_cc_symtypes_c =3D SYM $(quiet_modtag) $@ cmd_cc_symtypes_c =3D $(call cmd_gensymtypes_c,true,$@) >/dev/null =20 -$(obj)/%.symtypes : $(obj)/%.c FORCE +$(obj)/%.symtypes : $(obj)/%.c $(symtypes_dep_c) FORCE $(call cmd,cc_symtypes_c) =20 # LLVM assembly @@ -314,19 +324,32 @@ $(obj)/%.ll: $(obj)/%.rs FORCE # This is convoluted. The .S file must first be preprocessed to run guards= and # expand names, then the resulting exports must be constructed into plain # EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preproce= ssed -# to make the genksyms input. +# to make the genksyms input or compiled into an object for gendwarfksyms. # # These mirror gensymtypes_c and co above, keep them in synch. -cmd_gensymtypes_S =3D = \ - { echo "\#include " ; = \ - echo "\#include " ; = \ - $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/EXPORT_SYMBOL(\1);/p' = ; } | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) +getasmexports =3D \ + { echo "\#include " ; \ + echo "\#include " ; \ + echo "\#include " ; \ + $(call getexportsymbols,$(2:.symtypes=3D.o),EXPORT_SYMBOL(\1);) ; } + +ifdef CONFIG_GENDWARFKSYMS +cmd_gensymtypes_S =3D \ + $(getasmexports) | \ + $(CC) $(c_flags) -c -o $(2:.symtypes=3D.gendwarfksyms.o) -xc -; \ + $(call getexportsymbols,$(2:.symtypes=3D.o),\1) | \ + $(gendwarfksyms) $(2:.symtypes=3D.gendwarfksyms.o) \ + $(if $(1), --symtypes $(2)) +else +cmd_gensymtypes_S =3D \ + $(getasmexports) | \ + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) +endif # CONFIG_GENDWARFKSYMS =20 quiet_cmd_cc_symtypes_S =3D SYM $(quiet_modtag) $@ cmd_cc_symtypes_S =3D $(call cmd_gensymtypes_S,true,$@) >/dev/null =20 -$(obj)/%.symtypes : $(obj)/%.S FORCE +$(obj)/%.symtypes : $(obj)/%.S $(obj)/%.o FORCE $(call cmd,cc_symtypes_S) =20 =20 --=20 2.47.0.rc0.187.ge670bccf7e-goog