From patchwork Tue Oct 8 18:38:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 13826818 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 C800421B43A for ; Tue, 8 Oct 2024 18:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728412752; cv=none; b=pRXlJJ7urwLvYdS7DzmKe+4RqkknxTNd7EsUTd7LartUXX5k3dfMUd2+JjxMIgrWFHpsYRoUWz9K+U6m2I2BLDSO2x8d5Ud48HzJo/whD9LPIS7LKUQZVgfTxR2NQHlpl0hdXVfY+fFSShmvkYPkNW8667OH13fkOLPEL/pFt2E= 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.201 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-f201.google.com with SMTP id 41be03b00d2f7-70ac9630e3aso5116688a12.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=vt4VTpv+ij069X7H/7myuO9EseASGTgDab6iUaj6E4BUsFKqCF8aMu0MxqLuDxqpvu orE3HtIn72JbfAXurWNFQAL/TbBidTgK3eco8nBdF5M0097IMxa3qaBElTzNVHfYfbU9 oBgQKdMsoVDbC2ijri+RsE0QwtjyyKYSJCvn/i2lkFm84WjWrsxTi20vEynkPuMYPACR TP9DEgYcW9LzZPH+k8rsL5QVOYjh7y9xRJKNlCS5ruvUqF6O68C2kEZPnxWKl2mzZIuA x7mEkNWUq7c1WgFoKMWhDIVGQYKZvL1wzgZLo2+vGJJxNAlGQxgPllqSQjo5SWiiWLmr hXhg== X-Forwarded-Encrypted: i=1; AJvYcCXjZCzePdftLSDj8hYsqDcyW2vOJ1NCZZPdfgfW6M8wE72cHoJQmcJN52u9AQJdHLz+EHZ+YGG0bxAKoKbc@vger.kernel.org X-Gm-Message-State: AOJu0YzO4JtteMQH4j1nLYWjGM2q06PoAN9VDQ/wPhAMKv6ZWKYsaAgL u/JqoRDEuEdFhf145WWvHftmI38r8KW7EvVsBBY3qc/scxvLoyBIITdx+1evNQVO6n4Sb9dm6Qn fKgQIr8KGCx6PCY5lvCaiMaM6lQ== 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-modules@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 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. +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 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 += unifdef targets += module.lds subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins -subdir-$(CONFIG_MODVERSIONS) += genksyms +subdir-$(CONFIG_GENKSYMS) += genksyms subdir-$(CONFIG_GENDWARFKSYMS) += gendwarfksyms subdir-$(CONFIG_SECURITY_SELINUX) += selinux subdir-$(CONFIG_SECURITY_IPE) += 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 = $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) +gendwarfksyms := scripts/gendwarfksyms/gendwarfksyms +getexportsymbols = $(NM) $(1) | sed -n 's/.* __export_symbol_\(.*\)/$(2)/p' + genksyms = scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) # These mirror gensymtypes_S and co below, keep them in synch. +ifdef CONFIG_GENDWARFKSYMS +symtypes_dep_c = $(obj)/%.o +cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),, \ + $(call getexportsymbols,$(2:.symtypes=.o),\1) | \ + $(gendwarfksyms) $(2:.symtypes=.o) $(if $(1), --symtypes $(2))) +else cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms) +endif # CONFIG_GENDWARFKSYMS quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null -$(obj)/%.symtypes : $(obj)/%.c FORCE +$(obj)/%.symtypes : $(obj)/%.c $(symtypes_dep_c) FORCE $(call cmd,cc_symtypes_c) # 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 preprocessed -# 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 = \ - { echo "\#include " ; \ - echo "\#include " ; \ - $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/EXPORT_SYMBOL(\1);/p' ; } | \ - $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) +getasmexports = \ + { echo "\#include " ; \ + echo "\#include " ; \ + echo "\#include " ; \ + $(call getexportsymbols,$(2:.symtypes=.o),EXPORT_SYMBOL(\1);) ; } + +ifdef CONFIG_GENDWARFKSYMS +cmd_gensymtypes_S = \ + $(getasmexports) | \ + $(CC) $(c_flags) -c -o $(2:.symtypes=.gendwarfksyms.o) -xc -; \ + $(call getexportsymbols,$(2:.symtypes=.o),\1) | \ + $(gendwarfksyms) $(2:.symtypes=.gendwarfksyms.o) \ + $(if $(1), --symtypes $(2)) +else +cmd_gensymtypes_S = \ + $(getasmexports) | \ + $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) +endif # CONFIG_GENDWARFKSYMS quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null -$(obj)/%.symtypes : $(obj)/%.S FORCE +$(obj)/%.symtypes : $(obj)/%.S $(obj)/%.o FORCE $(call cmd,cc_symtypes_S)