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 v8 17/18] kbuild: Add gendwarfksyms as an alternative to genksyms
Date: Fri, 3 Jan 2025 20:45:39 +0000 [thread overview]
Message-ID: <20250103204521.1885406-37-samitolvanen@google.com> (raw)
In-Reply-To: <20250103204521.1885406-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 | 22 ++++++++++++++++++++++
scripts/Makefile | 2 +-
scripts/Makefile.build | 35 +++++++++++++++++++++++++++++------
3 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig
index 4637f063d0fc..d443fc504ffc 100644
--- a/kernel/module/Kconfig
+++ b/kernel/module/Kconfig
@@ -169,6 +169,22 @@ config MODVERSIONS
make them incompatible with the kernel you are running. If
unsure, say N.
+choice
+ prompt "Module versioning implementation"
+ depends on MODVERSIONS
+ 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 "gendwarfksyms (from debugging information)"
depends on DEBUG_INFO
@@ -176,6 +192,12 @@ config GENDWARFKSYMS
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 c16e4cf54d77..81d9dacad03c 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
@@ -286,14 +297,26 @@ $(obj)/%.rs: $(obj)/%.rs.S 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.1.613.gc27f4b7a9f-goog
next prev parent reply other threads:[~2025-01-03 20:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 20:45 [PATCH v8 00/18] Implement DWARF modversions Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 01/18] tools: Add gendwarfksyms Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 02/18] gendwarfksyms: Add address matching Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 03/18] gendwarfksyms: Expand base_type Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 04/18] gendwarfksyms: Add a cache for processed DIEs Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 05/18] gendwarfksyms: Expand type modifiers and typedefs Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 06/18] gendwarfksyms: Expand subroutine_type Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 07/18] gendwarfksyms: Expand array_type Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 08/18] gendwarfksyms: Expand structure types Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 09/18] gendwarfksyms: Limit structure expansion Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 10/18] gendwarfksyms: Add die_map debugging Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 11/18] gendwarfksyms: Add symtypes output Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 12/18] gendwarfksyms: Add symbol versioning Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 13/18] gendwarfksyms: Add support for kABI rules Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 14/18] gendwarfksyms: Add support for reserved and ignored fields Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 15/18] gendwarfksyms: Add support for symbol type pointers Sami Tolvanen
2025-01-03 20:45 ` [PATCH v8 16/18] export: Add __gendwarfksyms_ptr_ references to exported symbols Sami Tolvanen
2025-01-03 20:45 ` Sami Tolvanen [this message]
2025-01-03 20:45 ` [PATCH v8 18/18] Documentation/kbuild: Add DWARF module versioning Sami Tolvanen
2025-01-10 17:36 ` [PATCH v8 00/18] Implement DWARF modversions Masahiro Yamada
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=20250103204521.1885406-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).