From nobody Mon Nov 25 05:47:59 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 AF6A0235A10 for ; Wed, 30 Oct 2024 17:01:54 +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=1730307717; cv=none; b=i293wmxuVfd7M6r458pvGoxldTj7NqB+CVxOYg2DbWNeVj/SjZSGuhkqF5IllqIGEgT165UvNiGXRmmmNq3X1kCQfex10nn9xHJummpeiwI3M4bZTITxW9ciKMdGvLgXkMZOwCZF/rQtSjD0kVXpgYobedrCbC5AO5smxAZp0w8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730307717; c=relaxed/simple; bh=QeqSbCsPj7qrRhglch9sMXx52tVBAJeYNKhv77vFEtY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KsKm1kXeHAgMWVZg35s8xLG8u2PY7fzxLs7j5baHMMQXK2YF8CNmRk58zEZpSkSdBdcZKxcxiKJJzIFOO7rMw+/qMmn4hQ2M4wLigvsULwYe0YVygefaGSj/C0+dSXcPj20xcBFawvdRX7GLiX7UQQhoAm3B8XwoOrRHV7Lzhmk= 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=E/yLFwsn; 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="E/yLFwsn" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7c6a9c1a9b8so97159a12.0 for ; Wed, 30 Oct 2024 10:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730307714; x=1730912514; 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=vIug+S7emoCYpKR4nFVHSEuFz95qB3OCAjrjCPUc3mI=; b=E/yLFwsnPfXkLQ8oO0KVY8rqiMALVcI5cR0jtp9TXF89Ji9Uw0kCRP/2vXNVUq2HBb KgK+RJbhqFcbeuJ3AePuf/j6KHtm2H/keV/TLJbLHJMrE2xg1RflPzLm40D45OsCiwkl 0e3UThmny87lmZaEvFSDJmJzXXe1x+W5o5tpTQV7lo3gcJnC2wwSXIE0Y18JiDk+YrxU SLN6KZHRVdgp/s/V0Agg9YvuKXC/vU39fBVpGNwhm4IvinGMB/lFAwU9mIyen/GMbj3v /e+u5zuQurYQ8ior8gQahtNL/3Y7qG6aR0zAmji08bK9HlAplCJvVUlJ+UeVAiOTRtUZ o3/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730307714; x=1730912514; 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=vIug+S7emoCYpKR4nFVHSEuFz95qB3OCAjrjCPUc3mI=; b=MxwVvrOUfE05xjr38xJBn/KTU7ii117DGAmc52avyKRU/eGXUERzZ5qUlH2/mRVghy xYDB6dIsC2XnBpYr/Txd5Y6egh5Nqx7d4nhvsuzb0czNVDLaO45OocqPnc9YXmnIA+9q GRehkqRk4N6b/AWSBHhVKYsHfic62INN4SQztpCvRY94fMxeeYvQAvZ9tqixe5B62Zcp hccO2NFy8sKcDZq6bnuprGbCGVOSCMzZXFHN3bqsfMJrRYUGb8mC2fegPYCFq37ORuHY oYl+niG+fUZlfCkdki/ZhysGBKPw4/m5XTp24UOgHg+U++D23tLvOGoetJ5UCE/23cIT bO/w== X-Forwarded-Encrypted: i=1; AJvYcCXa4bShM6D5SjV+RNmKXbVEeuKhQs6NALWLnjhjTW+sOJRTIQ2L96YovTpQBhfrUe5g7S2ASZN7D+prq60=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3PWXymXE9OnklFjfTc3r/jdiBURQst3FXTvsBKZdX0Bsc1xOh hcLlSK08TyhDTS6QBdxbZ/53tYsaF0GaQzQdb01aogcWIGZQnqRsqfaetD2+hISBjE+H9OxZCJa 7fvejfypgK9/PjiDai2gr0v0y+w== X-Google-Smtp-Source: AGHT+IGkDgNvAc7QgTxnQXGlbFGgIkGE0d3gPCPIyv5YYRky9bix4wE6z0LYzBTK9o7Os12OXUE3m3rVYuFt1FFJpko= X-Received: from samitolvanen.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4f92]) (user=samitolvanen job=sendgmr) by 2002:a63:385c:0:b0:7ea:999a:7930 with SMTP id 41be03b00d2f7-7edd7b6c7e8mr24309a12.1.1730307713761; Wed, 30 Oct 2024 10:01:53 -0700 (PDT) Date: Wed, 30 Oct 2024 17:01:25 +0000 In-Reply-To: <20241030170106.1501763-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: <20241030170106.1501763-21-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=5224; i=samitolvanen@google.com; h=from:subject; bh=QeqSbCsPj7qrRhglch9sMXx52tVBAJeYNKhv77vFEtY=; b=owGbwMvMwCEWxa662nLh8irG02pJDOlKadF1rBc3yhe9XddxbnWVwLU5KVcTNX9bF8fP+PppU XPyuUaGjlIWBjEOBlkxRZaWr6u37v7ulPrqc5EEzBxWJpAhDFycAjCRx/YM/9TTmtNefL30t+W6 eoXo54yVemacOnyVt9Ys16uTN742v4CR4VSKdZ5pC+ON3Yz2vtwLlp795LKJfe7E0vKLc6bybFn IzgwA X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241030170106.1501763-39-samitolvanen@google.com> Subject: [PATCH v5 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 | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 58 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..d2a0440cdb79 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -107,18 +107,31 @@ cmd_cpp_i_c =3D $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) =20 +getexportsymbols =3D $(NM) $(1) | sed -n 's/.* __export_symbol_\(.*\)/$(2)= /p' + +gendwarfksyms =3D scripts/gendwarfksyms/gendwarfksyms \ + $(if $(1), --symtypes $(2)) \ + $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) + 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)) +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 +327,31 @@ $(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) +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.163.g1226f6d8fa-goog