linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sami Tolvanen <samitolvanen@google.com>
To: Masahiro Yamada <masahiroy@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	 Miguel Ojeda <ojeda@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Matthew Maurer <mmaurer@google.com>,
	Alex Gaynor <alex.gaynor@gmail.com>,  Gary Guo <gary@garyguo.net>,
	Petr Pavlu <petr.pavlu@suse.com>,
	 Daniel Gomez <da.gomez@samsung.com>, Neal Gompa <neal@gompa.dev>,
	Hector Martin <marcan@marcan.st>,  Janne Grunau <j@jannau.net>,
	Miroslav Benes <mbenes@suse.cz>,
	Asahi Linux <asahi@lists.linux.dev>,
	 Sedat Dilek <sedat.dilek@gmail.com>,
	linux-kbuild@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-modules@vger.kernel.org,  rust-for-linux@vger.kernel.org,
	Sami Tolvanen <samitolvanen@google.com>
Subject: [PATCH v6 17/18] kbuild: Add gendwarfksyms as an alternative to genksyms
Date: Thu, 21 Nov 2024 20:42:38 +0000	[thread overview]
Message-ID: <20241121204220.2378181-37-samitolvanen@google.com> (raw)
In-Reply-To: <20241121204220.2378181-20-samitolvanen@google.com>

When MODVERSIONS is enabled, allow selecting gendwarfksyms as the
implementation, but default to genksyms.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 kernel/module/Kconfig  | 25 ++++++++++++++++++++++++-
 scripts/Makefile       |  2 +-
 scripts/Makefile.build | 35 +++++++++++++++++++++++++++++------
 3 files changed, 54 insertions(+), 8 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 f41ce2131979..d6b211a7b261 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -107,13 +107,24 @@ cmd_cpp_i_c       = $(CPP) $(c_flags) -o $@ $<
 $(obj)/%.i: $(obj)/%.c FORCE
 	$(call if_changed_dep,cpp_i_c)
 
+getexportsymbols = $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/$(1)/p'
+
+gendwarfksyms = $(objtree)/scripts/gendwarfksyms/gendwarfksyms	\
+	$(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes))	\
+	$(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable)
+
 genksyms = $(objtree)/scripts/genksyms/genksyms		\
 	$(if $(KBUILD_SYMTYPES), -T $(@:.o=.symtypes))	\
 	$(if $(KBUILD_PRESERVE), -p)			\
 	$(addprefix -r , $(wildcard $(@:.o=.symref)))
 
 # These mirror gensymtypes_S and co below, keep them in synch.
+ifdef CONFIG_GENDWARFKSYMS
+cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),,	\
+	$(call getexportsymbols,\1) | $(gendwarfksyms) $@)
+else
 cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
+endif # CONFIG_GENDWARFKSYMS
 
 # LLVM assembly
 # Generate .ll files from .c
@@ -279,14 +290,26 @@ $(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 <linux/kernel.h>" ;                                    \
-     echo "\#include <asm/asm-prototypes.h>" ;                              \
-     $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/EXPORT_SYMBOL(\1);/p' ; } | \
-    $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
+getasmexports =								\
+   { echo "\#include <linux/kernel.h>" ;				\
+     echo "\#include <linux/string.h>" ;				\
+     echo "\#include <asm/asm-prototypes.h>" ;				\
+     $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
+
+ifdef CONFIG_GENDWARFKSYMS
+cmd_gensymtypes_S =							\
+	$(getasmexports) |						\
+	$(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -;		\
+	$(call getexportsymbols,\1) |					\
+	$(gendwarfksyms) $(@:.o=.gendwarfksyms.o)
+else
+cmd_gensymtypes_S =							\
+	$(getasmexports) |						\
+	$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
+endif # CONFIG_GENDWARFKSYMS
 
 quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
 cmd_cpp_s_S       = $(CPP) $(a_flags) -o $@ $<
-- 
2.47.0.371.ga323438b13-goog


  parent reply	other threads:[~2024-11-21 20:43 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-21 20:42 [PATCH v6 00/18] Implement DWARF modversions Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 01/18] tools: Add gendwarfksyms Sami Tolvanen
2024-11-25 23:29   ` Luis Chamberlain
2024-11-26  3:50     ` Masahiro Yamada
2024-11-26 18:26       ` Luis Chamberlain
2024-12-05  3:46         ` Masahiro Yamada
2024-12-05 15:51           ` Sami Tolvanen
2024-11-26 13:35   ` Masahiro Yamada
2024-12-04 14:13   ` Daniel Gomez
2024-12-05  3:28     ` Masahiro Yamada
2024-11-21 20:42 ` [PATCH v6 02/18] gendwarfksyms: Add address matching Sami Tolvanen
2024-12-02 16:08   ` Petr Pavlu
2024-11-21 20:42 ` [PATCH v6 03/18] gendwarfksyms: Expand base_type Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 04/18] gendwarfksyms: Add a cache for processed DIEs Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 05/18] gendwarfksyms: Expand type modifiers and typedefs Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 06/18] gendwarfksyms: Expand subroutine_type Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 07/18] gendwarfksyms: Expand array_type Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 08/18] gendwarfksyms: Expand structure types Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 09/18] gendwarfksyms: Limit structure expansion Sami Tolvanen
2024-12-02 16:14   ` Petr Pavlu
2024-11-21 20:42 ` [PATCH v6 10/18] gendwarfksyms: Add die_map debugging Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 11/18] gendwarfksyms: Add symtypes output Sami Tolvanen
2024-12-03 11:54   ` Petr Pavlu
2024-11-21 20:42 ` [PATCH v6 12/18] gendwarfksyms: Add symbol versioning Sami Tolvanen
2024-12-03 11:55   ` Petr Pavlu
2024-11-21 20:42 ` [PATCH v6 13/18] gendwarfksyms: Add support for kABI rules Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 14/18] gendwarfksyms: Add support for reserved and ignored fields Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 15/18] gendwarfksyms: Add support for symbol type pointers Sami Tolvanen
2024-11-21 20:42 ` [PATCH v6 16/18] export: Add __gendwarfksyms_ptr_ references to exported symbols Sami Tolvanen
2024-11-21 20:42 ` Sami Tolvanen [this message]
2024-11-26 17:07   ` [PATCH v6 17/18] kbuild: Add gendwarfksyms as an alternative to genksyms Masahiro Yamada
2024-11-21 20:42 ` [PATCH v6 18/18] Documentation/kbuild: Add DWARF module versioning Sami Tolvanen
2024-12-14 11:33   ` Masahiro Yamada
2024-12-14 13:04     ` Sedat Dilek
2024-12-17  0:28     ` Sami Tolvanen
2024-11-22  1:51 ` [PATCH v6 00/18] Implement DWARF modversions Sedat Dilek
2024-11-23 11:22   ` Sedat Dilek
2024-11-25  9:34     ` Sami Tolvanen
2024-11-25  9:21   ` Sami Tolvanen
2024-11-25 13:28 ` Neal Gompa
2024-11-25 14:41   ` Miguel Ojeda
2024-11-25 15:34     ` Sami Tolvanen
2024-12-10 12:41       ` Neal Gompa
2024-12-10 14:27         ` Masahiro Yamada
2024-12-11  4:19           ` Luis Chamberlain
2024-11-26 18:30 ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241121204220.2378181-37-samitolvanen@google.com \
    --to=samitolvanen@google.com \
    --cc=alex.gaynor@gmail.com \
    --cc=asahi@lists.linux.dev \
    --cc=da.gomez@samsung.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=j@jannau.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=masahiroy@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mcgrof@kernel.org \
    --cc=mmaurer@google.com \
    --cc=neal@gompa.dev \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sedat.dilek@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).