linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo
@ 2025-09-18  8:05 Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 1/8] s390: vmlinux.lds.S: Reorder sections Alexey Gladkov
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov

The modules.builtin.modinfo file is used by userspace (kmod to be specific) to
get information about builtin modules. Among other information about the module,
information about module aliases is stored. This is very important to determine
that a particular modalias will be handled by a module that is inside the
kernel.

There are several mechanisms for creating modalias for modules:

The first is to explicitly specify the MODULE_ALIAS of the macro. In this case,
the aliases go into the '.modinfo' section of the module if it is compiled
separately or into vmlinux.o if it is builtin into the kernel.

The second is the use of MODULE_DEVICE_TABLE followed by the use of the
modpost utility. In this case, vmlinux.o no longer has this information and
does not get it into modules.builtin.modinfo.

For example:

$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.

$ modinfo xhci_pci
name:           xhci_pci
filename:       (builtin)
license:        GPL
file:           drivers/usb/host/xhci-pci
description:    xHCI PCI Host Controller Driver

The builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be
generated by modpost if the module is built separately.

To fix this it is necessary to add the generated by modpost modalias to
modules.builtin.modinfo. Fortunately modpost already generates .vmlinux.export.c
for exported symbols. It is possible to add `.modinfo` for builtin modules and
modify the build system so that `.modinfo` section is extracted from the
intermediate vmlinux after modpost is executed.

---
Notes:
- v8:
  * Fix build warnings about unused variable.
  * Fix objcopy "warning: empty loadable segment detected ...".
  * v7: https://lore.kernel.org/all/cover.1755535876.git.legion@kernel.org/

- v7:
  * Reorder patches to avoid unnecessary linker warnings on s390.
  * Drop the patch for pinctrl since it's already been applied.
  * v6: https://lore.kernel.org/all/cover.1755170493.git.legion@kernel.org/

- v6:
  * Rebase to v6.17-rc1-16-g8742b2d8935f to pick up the fixes made by Masahiro Yamada.
  * Fix an issue on i386 configs caused by the use of string_32.h.
  * v5: https://lore.kernel.org/all/cover.1753354215.git.legion@kernel.org/

- v5:
  * Rebase to v6.16-rc6-281-gf4a40a4282f4 to pick up the fixes made by Masahiro Yamada.
  * Attempt to fix linker warning on s390.
  * Fix typo in pinctrl/meson found by the kernel test robot.
  * v4: https://lore.kernel.org/all/cover.1750511018.git.legion@kernel.org/

- v4:
  * Rework the patchset based on top of Masahiro Yamada's patches.
  * Add removal of unnecessary __mod_device_table__* symbols to avoid symbol
    table growth in vmlinux.
  * rust code takes into account changes in __mod_device_table__*.
  * v3: https://lore.kernel.org/all/cover.1748335606.git.legion@kernel.org/

- v3:
  * Add `Reviewed-by` tag to patches from Petr Pavlu.
  * Rebase to v6.15.
  * v2: https://lore.kernel.org/all/20250509164237.2886508-1-legion@kernel.org/

- v2:
  * Drop patch for mfd because it was already applied and is in linux-next.
  * The generation of aliases for builtin modules has been redone as
    suggested by Masahiro Yamada.
  * Rebase to v6.15-rc5-136-g9c69f8884904
  * v1: https://lore.kernel.org/all/cover.1745591072.git.legion@kernel.org/


Alexey Gladkov (5):
  s390: vmlinux.lds.S: Reorder sections
  scsi: Always define blogic_pci_tbl structure
  modpost: Add modname to mod_device_table alias
  modpost: Create modalias for builtin modules
  kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o

Masahiro Yamada (3):
  kbuild: always create intermediate vmlinux.unstripped
  kbuild: keep .modinfo section in vmlinux.unstripped
  kbuild: extract modules.builtin.modinfo from vmlinux.unstripped

 arch/s390/kernel/vmlinux.lds.S    | 10 ++--
 drivers/scsi/BusLogic.c           |  4 +-
 include/asm-generic/vmlinux.lds.h |  2 +-
 include/linux/module.h            | 18 +++++--
 rust/kernel/device_id.rs          |  8 ++--
 scripts/Makefile.vmlinux          | 79 ++++++++++++++++++++-----------
 scripts/Makefile.vmlinux_o        | 26 +---------
 scripts/link-vmlinux.sh           |  5 +-
 scripts/mksysmap                  |  6 +++
 scripts/mod/file2alias.c          | 34 +++++++++++--
 scripts/mod/modpost.c             | 15 ++++++
 scripts/mod/modpost.h             |  2 +
 12 files changed, 131 insertions(+), 78 deletions(-)


base-commit: aa943a280e88e3585ed5a06d55e78c4123fcead3
-- 
2.51.0


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v8 1/8] s390: vmlinux.lds.S: Reorder sections
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 2/8] kbuild: always create intermediate vmlinux.unstripped Alexey Gladkov
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, linux-s390,
	kernel test robot

In the upcoming changes, the ELF_DETAILS macro will be extended with
the ".modinfo" section, which will cause an error:

>> s390x-linux-ld: .tmp_vmlinux1: warning: allocated section `.modinfo' not in segment
>> s390x-linux-ld: .tmp_vmlinux2: warning: allocated section `.modinfo' not in segment
>> s390x-linux-ld: vmlinux.unstripped: warning: allocated section `.modinfo' not in segment

This happens because the .vmlinux.info use :NONE to override the default
segment and tell the linker to not put the section in any segment at all.

To avoid this, we need to change the sections order that will be placed
in the default segment.

Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: linux-s390@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202506062053.zbkFBEnJ-lkp@intel.com/
Signed-off-by: Alexey Gladkov <legion@kernel.org>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/kernel/vmlinux.lds.S | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index 1c606dfa595d8..feecf1a6ddb44 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -209,6 +209,11 @@ SECTIONS
 	. = ALIGN(PAGE_SIZE);
 	_end = . ;
 
+	/* Debugging sections.	*/
+	STABS_DEBUG
+	DWARF_DEBUG
+	ELF_DETAILS
+
 	/*
 	 * uncompressed image info used by the decompressor
 	 * it should match struct vmlinux_info
@@ -239,11 +244,6 @@ SECTIONS
 #endif
 	} :NONE
 
-	/* Debugging sections.	*/
-	STABS_DEBUG
-	DWARF_DEBUG
-	ELF_DETAILS
-
 	/*
 	 * Make sure that the .got.plt is either completely empty or it
 	 * contains only the three reserved double words.
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 2/8] kbuild: always create intermediate vmlinux.unstripped
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 1/8] s390: vmlinux.lds.S: Reorder sections Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped Alexey Gladkov
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Masahiro Yamada,
	Nicolas Schier

From: Masahiro Yamada <masahiroy@kernel.org>

Generate the intermediate vmlinux.unstripped regardless of
CONFIG_ARCH_VMLINUX_NEEDS_RELOCS.

If CONFIG_ARCH_VMLINUX_NEEDS_RELOCS is unset, vmlinux.unstripped and
vmlinux are identiacal.

This simplifies the build rule, and allows to strip more sections
by adding them to remove-section-y.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
---
 scripts/Makefile.vmlinux | 45 ++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index b64862dc6f08d..4f2d4c3fb7372 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -9,20 +9,6 @@ include $(srctree)/scripts/Makefile.lib
 
 targets :=
 
-ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS
-vmlinux-final := vmlinux.unstripped
-
-quiet_cmd_strip_relocs = RSTRIP  $@
-      cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' --remove-section=!'.rel*.dyn' $< $@
-
-vmlinux: $(vmlinux-final) FORCE
-	$(call if_changed,strip_relocs)
-
-targets += vmlinux
-else
-vmlinux-final := vmlinux
-endif
-
 %.o: %.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
@@ -61,19 +47,19 @@ targets += .builtin-dtbs-list
 
 ifdef CONFIG_GENERIC_BUILTIN_DTB
 targets += .builtin-dtbs.S .builtin-dtbs.o
-$(vmlinux-final): .builtin-dtbs.o
+vmlinux.unstripped: .builtin-dtbs.o
 endif
 
-# vmlinux
+# vmlinux.unstripped
 # ---------------------------------------------------------------------------
 
 ifdef CONFIG_MODULES
 targets += .vmlinux.export.o
-$(vmlinux-final): .vmlinux.export.o
+vmlinux.unstripped: .vmlinux.export.o
 endif
 
 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
-$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o
+vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o
 
 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
 	$(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
@@ -86,17 +72,30 @@ cmd_link_vmlinux =							\
 	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
 	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
-targets += $(vmlinux-final)
-$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
+targets += vmlinux.unstripped
+vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
 	+$(call if_changed_dep,link_vmlinux)
 ifdef CONFIG_DEBUG_INFO_BTF
-$(vmlinux-final): $(RESOLVE_BTFIDS)
+vmlinux.unstripped: $(RESOLVE_BTFIDS)
 endif
 
 ifdef CONFIG_BUILDTIME_TABLE_SORT
-$(vmlinux-final): scripts/sorttable
+vmlinux.unstripped: scripts/sorttable
 endif
 
+# vmlinux
+# ---------------------------------------------------------------------------
+
+remove-section-y                                   :=
+remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
+
+quiet_cmd_strip_relocs = OBJCOPY $@
+      cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
+
+targets += vmlinux
+vmlinux: vmlinux.unstripped FORCE
+	$(call if_changed,strip_relocs)
+
 # modules.builtin.ranges
 # ---------------------------------------------------------------------------
 ifdef CONFIG_BUILTIN_MODULE_RANGES
@@ -110,7 +109,7 @@ modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \
 			modules.builtin vmlinux.map vmlinux.o.map FORCE
 	$(call if_changed,modules_builtin_ranges)
 
-vmlinux.map: $(vmlinux-final)
+vmlinux.map: vmlinux.unstripped
 	@:
 
 endif
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 1/8] s390: vmlinux.lds.S: Reorder sections Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 2/8] kbuild: always create intermediate vmlinux.unstripped Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-24  6:29   ` Nicolas Schier
  2025-09-18  8:05 ` [PATCH v8 4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped Alexey Gladkov
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Masahiro Yamada,
	Alexey Gladkov

From: Masahiro Yamada <masahiroy@kernel.org>

Keep the .modinfo section during linking, but strip it from the final
vmlinux.

Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.

This change will allow the next commit to extract the .modinfo section
from the vmlinux.unstripped intermediate.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Alexey Gladkov <legion@kernel.org>
---
 include/asm-generic/vmlinux.lds.h | 2 +-
 scripts/Makefile.vmlinux          | 7 +++++--
 scripts/mksysmap                  | 3 +++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index ae2d2359b79e9..cfa63860dfd4c 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
 
 /* Required sections not related to debugging. */
 #define ELF_DETAILS							\
+		.modinfo : { *(.modinfo) }				\
 		.comment 0 : { *(.comment) }				\
 		.symtab 0 : { *(.symtab) }				\
 		.strtab 0 : { *(.strtab) }				\
@@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
 	*(.discard.*)							\
 	*(.export_symbol)						\
 	*(.no_trim_symbol)						\
-	*(.modinfo)							\
 	/* ld.bfd warns about .gnu.version* even when not emitted */	\
 	*(.gnu.version*)						\
 
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 4f2d4c3fb7372..70856dab0f541 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -86,11 +86,14 @@ endif
 # vmlinux
 # ---------------------------------------------------------------------------
 
-remove-section-y                                   :=
+remove-section-y                                   := .modinfo
 remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
 
+# To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
+# it is necessary to remove the PT_LOAD flag from the segment.
 quiet_cmd_strip_relocs = OBJCOPY $@
-      cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
+      cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
+                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $@
 
 targets += vmlinux
 vmlinux: vmlinux.unstripped FORCE
diff --git a/scripts/mksysmap b/scripts/mksysmap
index 3accbdb269ac7..a607a0059d119 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -79,6 +79,9 @@
 / _SDA_BASE_$/d
 / _SDA2_BASE_$/d
 
+# MODULE_INFO()
+/ __UNIQUE_ID_modinfo[0-9]*$/d
+
 # ---------------------------------------------------------------------------
 # Ignored patterns
 #  (symbols that contain the pattern are ignored)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (2 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 5/8] scsi: Always define blogic_pci_tbl structure Alexey Gladkov
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Masahiro Yamada,
	Alexey Gladkov, Nicolas Schier

From: Masahiro Yamada <masahiroy@kernel.org>

Currently, we assume all the data for modules.builtin.modinfo are
available in vmlinux.o.

This makes it impossible for modpost, which is invoked after vmlinux.o,
to add additional module info.

This commit moves the modules.builtin.modinfo rule after modpost.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Alexey Gladkov <legion@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
---
 scripts/Makefile.vmlinux   | 26 ++++++++++++++++++++++++++
 scripts/Makefile.vmlinux_o | 26 +-------------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 70856dab0f541..ce79461714979 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -99,6 +99,32 @@ targets += vmlinux
 vmlinux: vmlinux.unstripped FORCE
 	$(call if_changed,strip_relocs)
 
+# modules.builtin.modinfo
+# ---------------------------------------------------------------------------
+
+OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
+
+targets += modules.builtin.modinfo
+modules.builtin.modinfo: vmlinux.unstripped FORCE
+	$(call if_changed,objcopy)
+
+# modules.builtin
+# ---------------------------------------------------------------------------
+
+__default: modules.builtin
+
+# The second line aids cases where multiple modules share the same object.
+
+quiet_cmd_modules_builtin = GEN     $@
+      cmd_modules_builtin = \
+	tr '\0' '\n' < $< | \
+	sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
+	tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
+
+targets += modules.builtin
+modules.builtin: modules.builtin.modinfo FORCE
+	$(call if_changed,modules_builtin)
+
 # modules.builtin.ranges
 # ---------------------------------------------------------------------------
 ifdef CONFIG_BUILTIN_MODULE_RANGES
diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o
index b024ffb3e2018..23c8751285d79 100644
--- a/scripts/Makefile.vmlinux_o
+++ b/scripts/Makefile.vmlinux_o
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 PHONY := __default
-__default: vmlinux.o modules.builtin.modinfo modules.builtin
+__default: vmlinux.o
 
 include include/config/auto.conf
 include $(srctree)/scripts/Kbuild.include
@@ -73,30 +73,6 @@ vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE
 
 targets += vmlinux.o
 
-# modules.builtin.modinfo
-# ---------------------------------------------------------------------------
-
-OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
-
-targets += modules.builtin.modinfo
-modules.builtin.modinfo: vmlinux.o FORCE
-	$(call if_changed,objcopy)
-
-# modules.builtin
-# ---------------------------------------------------------------------------
-
-# The second line aids cases where multiple modules share the same object.
-
-quiet_cmd_modules_builtin = GEN     $@
-      cmd_modules_builtin = \
-	tr '\0' '\n' < $< | \
-	sed -n 's/^[[:alnum:]:_]*\.file=//p' | \
-	tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@
-
-targets += modules.builtin
-modules.builtin: modules.builtin.modinfo FORCE
-	$(call if_changed,modules_builtin)
-
 # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
 # ---------------------------------------------------------------------------
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 5/8] scsi: Always define blogic_pci_tbl structure
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (3 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-18  8:05 ` [PATCH v8 6/8] modpost: Add modname to mod_device_table alias Alexey Gladkov
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov,
	Khalid Aziz, Martin K. Petersen, linux-scsi, James Bottomley,
	Arnd Bergmann, Damien Le Moal

The blogic_pci_tbl structure is used by the MODULE_DEVICE_TABLE macro.
There is no longer a need to protect it with the MODULE condition, since
this no longer causes the compiler to warn about an unused variable.

To avoid warnings when -Wunused-const-variable option is used, mark it
as __maybe_unused for such configuration.

Cc: Khalid Aziz <khalid@gonehiking.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Suggested-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Alexey Gladkov <legion@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/scsi/BusLogic.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 1f100270cd385..82597bd96525b 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void)
 
 __setup("BusLogic=", blogic_setup);
 
-#ifdef MODULE
 /*static const struct pci_device_id blogic_pci_tbl[] = {
 	{ PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
@@ -3725,13 +3724,12 @@ __setup("BusLogic=", blogic_setup);
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 	{ }
 };*/
-static const struct pci_device_id blogic_pci_tbl[] = {
+static const struct pci_device_id blogic_pci_tbl[] __maybe_unused = {
 	{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER)},
 	{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC)},
 	{PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)},
 	{0, },
 };
-#endif
 MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);
 
 module_init(blogic_init);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 6/8] modpost: Add modname to mod_device_table alias
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (4 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 5/8] scsi: Always define blogic_pci_tbl structure Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-24  6:31   ` Nicolas Schier
  2025-09-18  8:05 ` [PATCH v8 7/8] modpost: Create modalias for builtin modules Alexey Gladkov
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov,
	Miguel Ojeda, Andreas Hindborg, Danilo Krummrich, Alex Gaynor,
	rust-for-linux

At this point, if a symbol is compiled as part of the kernel,
information about which module the symbol belongs to is lost.

To save this it is possible to add the module name to the alias name.
It's not very pretty, but it's possible for now.

Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: rust-for-linux@vger.kernel.org
Signed-off-by: Alexey Gladkov <legion@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
---
 include/linux/module.h   | 14 +++++++++++++-
 rust/kernel/device_id.rs |  8 ++++----
 scripts/mod/file2alias.c | 15 ++++++++++++---
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index 3319a5269d286..e31ee29fac6b7 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -244,10 +244,22 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
 /* What your module does. */
 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
 
+/*
+ * Format: __mod_device_table__kmod_<modname>__<type>__<name>
+ * Parts of the string `__kmod_` and `__` are used as delimiters when parsing
+ * a symbol in file2alias.c
+ */
+#define __mod_device_table(type, name)	\
+	__PASTE(__mod_device_table__,	\
+	__PASTE(__KBUILD_MODNAME,	\
+	__PASTE(__,			\
+	__PASTE(type,			\
+	__PASTE(__, name)))))
+
 #ifdef MODULE
 /* Creates an alias so file2alias.c can find device table. */
 #define MODULE_DEVICE_TABLE(type, name)					\
-static typeof(name) __mod_device_table__##type##__##name		\
+static typeof(name) __mod_device_table(type, name)			\
   __attribute__ ((used, alias(__stringify(name))))
 #else  /* !MODULE */
 #define MODULE_DEVICE_TABLE(type, name)
diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs
index 70d57814ff79b..62c42da12e9de 100644
--- a/rust/kernel/device_id.rs
+++ b/rust/kernel/device_id.rs
@@ -195,10 +195,10 @@ macro_rules! module_device_table {
     ($table_type: literal, $module_table_name:ident, $table_name:ident) => {
         #[rustfmt::skip]
         #[export_name =
-            concat!("__mod_device_table__", $table_type,
-                    "__", module_path!(),
-                    "_", line!(),
-                    "_", stringify!($table_name))
+            concat!("__mod_device_table__", line!(),
+                    "__kmod_", module_path!(),
+                    "__", $table_type,
+                    "__", stringify!($table_name))
         ]
         static $module_table_name: [::core::mem::MaybeUninit<u8>; $table_name.raw_ids().size()] =
             unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) };
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 00586119a25b7..1260bc2287fba 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1476,7 +1476,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 {
 	void *symval;
 	char *zeros = NULL;
-	const char *type, *name;
+	const char *type, *name, *modname;
 	size_t typelen;
 	static const char *prefix = "__mod_device_table__";
 
@@ -1488,10 +1488,19 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 	if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
 		return;
 
-	/* All our symbols are of form __mod_device_table__<type>__<name>. */
+	/* All our symbols are of form __mod_device_table__kmod_<modname>__<type>__<name>. */
 	if (!strstarts(symname, prefix))
 		return;
-	type = symname + strlen(prefix);
+
+	modname = strstr(symname, "__kmod_");
+	if (!modname)
+		return;
+	modname += strlen("__kmod_");
+
+	type = strstr(modname, "__");
+	if (!type)
+		return;
+	type += strlen("__");
 
 	name = strstr(type, "__");
 	if (!name)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (5 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 6/8] modpost: Add modname to mod_device_table alias Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-24  6:38   ` Nicolas Schier
  2025-10-07  1:16   ` Charles Mirabile
  2025-09-18  8:05 ` [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o Alexey Gladkov
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov,
	Masahiro Yamada, Stephen Rothwell

For some modules, modalias is generated using the modpost utility and
the section is added to the module file.

When a module is added inside vmlinux, modpost does not generate
modalias for such modules and the information is lost.

As a result kmod (which uses modules.builtin.modinfo in userspace)
cannot determine that modalias is handled by a builtin kernel module.

$ cat /sys/devices/pci0000:00/0000:00:14.0/modalias
pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30

$ modinfo xhci_pci
name:           xhci_pci
filename:       (builtin)
license:        GPL
file:           drivers/usb/host/xhci-pci
description:    xHCI PCI Host Controller Driver

Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by
modpost if the module is built separately.

To fix this it is necessary to generate the same modalias for vmlinux as
for the individual modules. Fortunately '.vmlinux.export.o' is already
generated from which '.modinfo' can be extracted in the same way as for
vmlinux.o.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Alexey Gladkov <legion@kernel.org>
Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 include/linux/module.h   |  4 ----
 scripts/Makefile.vmlinux |  4 +++-
 scripts/mksysmap         |  3 +++
 scripts/mod/file2alias.c | 19 ++++++++++++++++++-
 scripts/mod/modpost.c    | 15 +++++++++++++++
 scripts/mod/modpost.h    |  2 ++
 6 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index e31ee29fac6b7..e135cc79aceea 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -256,14 +256,10 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
 	__PASTE(type,			\
 	__PASTE(__, name)))))
 
-#ifdef MODULE
 /* Creates an alias so file2alias.c can find device table. */
 #define MODULE_DEVICE_TABLE(type, name)					\
 static typeof(name) __mod_device_table(type, name)			\
   __attribute__ ((used, alias(__stringify(name))))
-#else  /* !MODULE */
-#define MODULE_DEVICE_TABLE(type, name)
-#endif
 
 /* Version of form [<epoch>:]<version>[-<extra-version>].
  * Or for CVS/RCS ID version, everything but the number is stripped.
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index ce79461714979..1e5e37aadcd05 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -89,11 +89,13 @@ endif
 remove-section-y                                   := .modinfo
 remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
 
+remove-symbols := -w --strip-symbol='__mod_device_table__*'
+
 # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
 # it is necessary to remove the PT_LOAD flag from the segment.
 quiet_cmd_strip_relocs = OBJCOPY $@
       cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
-                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $@
+                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@
 
 targets += vmlinux
 vmlinux: vmlinux.unstripped FORCE
diff --git a/scripts/mksysmap b/scripts/mksysmap
index a607a0059d119..c4531eacde202 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -59,6 +59,9 @@
 # EXPORT_SYMBOL (namespace)
 / __kstrtabns_/d
 
+# MODULE_DEVICE_TABLE (symbol name)
+/ __mod_device_table__/d
+
 # ---------------------------------------------------------------------------
 # Ignored suffixes
 #  (do not forget '$' after each pattern)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 1260bc2287fba..7da9735e7ab3e 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1477,7 +1477,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 	void *symval;
 	char *zeros = NULL;
 	const char *type, *name, *modname;
-	size_t typelen;
+	size_t typelen, modnamelen;
 	static const char *prefix = "__mod_device_table__";
 
 	/* We're looking for a section relative symbol */
@@ -1500,6 +1500,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 	type = strstr(modname, "__");
 	if (!type)
 		return;
+	modnamelen = type - modname;
 	type += strlen("__");
 
 	name = strstr(type, "__");
@@ -1526,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 		}
 	}
 
+	if (mod->is_vmlinux) {
+		struct module_alias *alias;
+
+		/*
+		 * If this is vmlinux, record the name of the builtin module.
+		 * Traverse the linked list in the reverse order, and set the
+		 * builtin_modname unless it has already been set in the
+		 * previous call.
+		 */
+		list_for_each_entry_reverse(alias, &mod->aliases, node) {
+			if (alias->builtin_modname)
+				break;
+			alias->builtin_modname = xstrndup(modname, modnamelen);
+		}
+	}
+
 	free(zeros);
 }
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 5ca7c268294eb..47c8aa2a69392 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2067,11 +2067,26 @@ static void write_if_changed(struct buffer *b, const char *fname)
 static void write_vmlinux_export_c_file(struct module *mod)
 {
 	struct buffer buf = { };
+	struct module_alias *alias, *next;
 
 	buf_printf(&buf,
 		   "#include <linux/export-internal.h>\n");
 
 	add_exported_symbols(&buf, mod);
+
+	buf_printf(&buf,
+		   "#include <linux/module.h>\n"
+		   "#undef __MODULE_INFO_PREFIX\n"
+		   "#define __MODULE_INFO_PREFIX\n");
+
+	list_for_each_entry_safe(alias, next, &mod->aliases, node) {
+		buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n",
+			   alias->builtin_modname, alias->str);
+		list_del(&alias->node);
+		free(alias->builtin_modname);
+		free(alias);
+	}
+
 	write_if_changed(&buf, ".vmlinux.export.c");
 	free(buf.p);
 }
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 9133e4c3803f0..2aecb8f25c87e 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len);
  * struct module_alias - auto-generated MODULE_ALIAS()
  *
  * @node: linked to module::aliases
+ * @modname: name of the builtin module (only for vmlinux)
  * @str: a string for MODULE_ALIAS()
  */
 struct module_alias {
 	struct list_head node;
+	char *builtin_modname;
 	char str[];
 };
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (6 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 7/8] modpost: Create modalias for builtin modules Alexey Gladkov
@ 2025-09-18  8:05 ` Alexey Gladkov
  2025-09-24  6:39   ` Nicolas Schier
  2025-09-18 17:35 ` [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Nathan Chancellor
  2025-09-24 16:17 ` Nathan Chancellor
  9 siblings, 1 reply; 22+ messages in thread
From: Alexey Gladkov @ 2025-09-18  8:05 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez
  Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov

Since .vmlinux.export.c is used to add generated by modpost modaliases
for builtin modules the .vmlinux.export.o is no longer optional and
should always be created. The generation of this file is not dependent
on CONFIG_MODULES.

Signed-off-by: Alexey Gladkov <legion@kernel.org>
---
 scripts/Makefile.vmlinux | 9 ++-------
 scripts/link-vmlinux.sh  | 5 +----
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index 1e5e37aadcd05..7c6ae9886f8f7 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -53,11 +53,6 @@ endif
 # vmlinux.unstripped
 # ---------------------------------------------------------------------------
 
-ifdef CONFIG_MODULES
-targets += .vmlinux.export.o
-vmlinux.unstripped: .vmlinux.export.o
-endif
-
 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
 vmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o
 
@@ -72,8 +67,8 @@ cmd_link_vmlinux =							\
 	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
 	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
-targets += vmlinux.unstripped
-vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
+targets += vmlinux.unstripped .vmlinux.export.o
+vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE
 	+$(call if_changed_dep,link_vmlinux)
 ifdef CONFIG_DEBUG_INFO_BTF
 vmlinux.unstripped: $(RESOLVE_BTFIDS)
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 51367c2bfc21e..433849ff7529e 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -73,10 +73,7 @@ vmlinux_link()
 		objs="${objs} .builtin-dtbs.o"
 	fi
 
-	if is_enabled CONFIG_MODULES; then
-		objs="${objs} .vmlinux.export.o"
-	fi
-
+	objs="${objs} .vmlinux.export.o"
 	objs="${objs} init/version-timestamp.o"
 
 	if [ "${SRCARCH}" = "um" ]; then
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (7 preceding siblings ...)
  2025-09-18  8:05 ` [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o Alexey Gladkov
@ 2025-09-18 17:35 ` Nathan Chancellor
  2025-09-24 16:17 ` Nathan Chancellor
  9 siblings, 0 replies; 22+ messages in thread
From: Nathan Chancellor @ 2025-09-18 17:35 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Nicolas Schier, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
	Daniel Gomez, linux-kernel, linux-modules, linux-kbuild

Hi Alexey,

On Thu, Sep 18, 2025 at 10:05:44AM +0200, Alexey Gladkov wrote:
> The modules.builtin.modinfo file is used by userspace (kmod to be specific) to
> get information about builtin modules. Among other information about the module,
> information about module aliases is stored. This is very important to determine
> that a particular modalias will be handled by a module that is inside the
> kernel.
> 
> There are several mechanisms for creating modalias for modules:
> 
> The first is to explicitly specify the MODULE_ALIAS of the macro. In this case,
> the aliases go into the '.modinfo' section of the module if it is compiled
> separately or into vmlinux.o if it is builtin into the kernel.
> 
> The second is the use of MODULE_DEVICE_TABLE followed by the use of the
> modpost utility. In this case, vmlinux.o no longer has this information and
> does not get it into modules.builtin.modinfo.
> 
> For example:
> 
> $ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
> modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.
> 
> $ modinfo xhci_pci
> name:           xhci_pci
> filename:       (builtin)
> license:        GPL
> file:           drivers/usb/host/xhci-pci
> description:    xHCI PCI Host Controller Driver
> 
> The builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be
> generated by modpost if the module is built separately.
> 
> To fix this it is necessary to add the generated by modpost modalias to
> modules.builtin.modinfo. Fortunately modpost already generates .vmlinux.export.c
> for exported symbols. It is possible to add `.modinfo` for builtin modules and
> modify the build system so that `.modinfo` section is extracted from the
> intermediate vmlinux after modpost is executed.

This seems good to me now. I have tentatively merged this into
kbuild-next so that it can get some more soak testing in -next, as I am
going to be paying less attention to email starting on Sunday for a week
or so, so I would like to be able to deal with regressions promptly.

  https://git.kernel.org/kbuild/l/kbuild-next

Don't consider the commit hashes stable just yet, as I would like to
give Nicolas the chance to provide tags if he would like but I did not
want to wait for the soak testing.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
  2025-09-18  8:05 ` [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped Alexey Gladkov
@ 2025-09-24  6:29   ` Nicolas Schier
  0 siblings, 0 replies; 22+ messages in thread
From: Nicolas Schier @ 2025-09-24  6:29 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
	Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
	Masahiro Yamada

On Thu, Sep 18, 2025 at 10:05:47AM +0200, Alexey Gladkov wrote:
> From: Masahiro Yamada <masahiroy@kernel.org>
> 
> Keep the .modinfo section during linking, but strip it from the final
> vmlinux.
> 
> Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
> 
> This change will allow the next commit to extract the .modinfo section
> from the vmlinux.unstripped intermediate.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> ---
>  include/asm-generic/vmlinux.lds.h | 2 +-
>  scripts/Makefile.vmlinux          | 7 +++++--
>  scripts/mksysmap                  | 3 +++
>  3 files changed, 9 insertions(+), 3 deletions(-)
> 

Thanks!

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 6/8] modpost: Add modname to mod_device_table alias
  2025-09-18  8:05 ` [PATCH v8 6/8] modpost: Add modname to mod_device_table alias Alexey Gladkov
@ 2025-09-24  6:31   ` Nicolas Schier
  0 siblings, 0 replies; 22+ messages in thread
From: Nicolas Schier @ 2025-09-24  6:31 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
	Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
	Miguel Ojeda, Andreas Hindborg, Danilo Krummrich, Alex Gaynor,
	rust-for-linux

On Thu, Sep 18, 2025 at 10:05:50AM +0200, Alexey Gladkov wrote:
> At this point, if a symbol is compiled as part of the kernel,
> information about which module the symbol belongs to is lost.
> 
> To save this it is possible to add the module name to the alias name.
> It's not very pretty, but it's possible for now.
> 
> Cc: Miguel Ojeda <ojeda@kernel.org>
> Cc: Andreas Hindborg <a.hindborg@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Alex Gaynor <alex.gaynor@gmail.com>
> Cc: rust-for-linux@vger.kernel.org
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> Acked-by: Danilo Krummrich <dakr@kernel.org>
> ---
>  include/linux/module.h   | 14 +++++++++++++-
>  rust/kernel/device_id.rs |  8 ++++----
>  scripts/mod/file2alias.c | 15 ++++++++++++---
>  3 files changed, 29 insertions(+), 8 deletions(-)
> 

Acked-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-09-18  8:05 ` [PATCH v8 7/8] modpost: Create modalias for builtin modules Alexey Gladkov
@ 2025-09-24  6:38   ` Nicolas Schier
  2025-10-07  1:16   ` Charles Mirabile
  1 sibling, 0 replies; 22+ messages in thread
From: Nicolas Schier @ 2025-09-24  6:38 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
	Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
	Masahiro Yamada, Stephen Rothwell

On Thu, Sep 18, 2025 at 10:05:51AM +0200, Alexey Gladkov wrote:
> For some modules, modalias is generated using the modpost utility and
> the section is added to the module file.
> 
> When a module is added inside vmlinux, modpost does not generate
> modalias for such modules and the information is lost.
> 
> As a result kmod (which uses modules.builtin.modinfo in userspace)
> cannot determine that modalias is handled by a builtin kernel module.
> 
> $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias
> pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
> 
> $ modinfo xhci_pci
> name:           xhci_pci
> filename:       (builtin)
> license:        GPL
> file:           drivers/usb/host/xhci-pci
> description:    xHCI PCI Host Controller Driver
> 
> Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by
> modpost if the module is built separately.
> 
> To fix this it is necessary to generate the same modalias for vmlinux as
> for the individual modules. Fortunately '.vmlinux.export.o' is already
> generated from which '.modinfo' can be extracted in the same way as for
> vmlinux.o.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  include/linux/module.h   |  4 ----
>  scripts/Makefile.vmlinux |  4 +++-
>  scripts/mksysmap         |  3 +++
>  scripts/mod/file2alias.c | 19 ++++++++++++++++++-
>  scripts/mod/modpost.c    | 15 +++++++++++++++
>  scripts/mod/modpost.h    |  2 ++
>  6 files changed, 41 insertions(+), 6 deletions(-)
> 

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o
  2025-09-18  8:05 ` [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o Alexey Gladkov
@ 2025-09-24  6:39   ` Nicolas Schier
  0 siblings, 0 replies; 22+ messages in thread
From: Nicolas Schier @ 2025-09-24  6:39 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
	Daniel Gomez, linux-kernel, linux-modules, linux-kbuild

On Thu, Sep 18, 2025 at 10:05:52AM +0200, Alexey Gladkov wrote:
> Since .vmlinux.export.c is used to add generated by modpost modaliases
> for builtin modules the .vmlinux.export.o is no longer optional and
> should always be created. The generation of this file is not dependent
> on CONFIG_MODULES.
> 
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> ---
>  scripts/Makefile.vmlinux | 9 ++-------
>  scripts/link-vmlinux.sh  | 5 +----
>  2 files changed, 3 insertions(+), 11 deletions(-)
> 

Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo
  2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
                   ` (8 preceding siblings ...)
  2025-09-18 17:35 ` [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Nathan Chancellor
@ 2025-09-24 16:17 ` Nathan Chancellor
  9 siblings, 0 replies; 22+ messages in thread
From: Nathan Chancellor @ 2025-09-24 16:17 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
	Sami Tolvanen, Daniel Gomez, Alexey Gladkov
  Cc: linux-kernel, linux-modules, linux-kbuild


On Thu, 18 Sep 2025 10:05:44 +0200, Alexey Gladkov wrote:
> The modules.builtin.modinfo file is used by userspace (kmod to be specific) to
> get information about builtin modules. Among other information about the module,
> information about module aliases is stored. This is very important to determine
> that a particular modalias will be handled by a module that is inside the
> kernel.
> 
> There are several mechanisms for creating modalias for modules:
> 
> [...]

Applied, thanks!

[1/8] s390: vmlinux.lds.S: Reorder sections
      https://git.kernel.org/kbuild/c/8d18ef04f940a
[2/8] kbuild: always create intermediate vmlinux.unstripped
      https://git.kernel.org/kbuild/c/0ce5139fd96e9
[3/8] kbuild: keep .modinfo section in vmlinux.unstripped
      https://git.kernel.org/kbuild/c/3e86e4d74c049
[4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
      https://git.kernel.org/kbuild/c/39cfd5b12160b
[5/8] scsi: Always define blogic_pci_tbl structure
      https://git.kernel.org/kbuild/c/b88f88c26705a
[6/8] modpost: Add modname to mod_device_table alias
      https://git.kernel.org/kbuild/c/83fb49389bbe0
[7/8] modpost: Create modalias for builtin modules
      https://git.kernel.org/kbuild/c/5ab23c7923a1d
[8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o
      https://git.kernel.org/kbuild/c/3328d39a8dca2

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-09-18  8:05 ` [PATCH v8 7/8] modpost: Create modalias for builtin modules Alexey Gladkov
  2025-09-24  6:38   ` Nicolas Schier
@ 2025-10-07  1:16   ` Charles Mirabile
  2025-10-07 10:15     ` Alexey Gladkov
  1 sibling, 1 reply; 22+ messages in thread
From: Charles Mirabile @ 2025-10-07  1:16 UTC (permalink / raw)
  To: legion
  Cc: da.gomez, linux-kbuild, linux-kernel, linux-modules, masahiroy,
	mcgrof, nathan, nicolas.schier, petr.pavlu, samitolvanen, sfr

On Thu, Sep 18, 2025 at 10:05:51AM +0200, Alexey Gladkov wrote:
> For some modules, modalias is generated using the modpost utility and
> the section is added to the module file.
> 
> When a module is added inside vmlinux, modpost does not generate
> modalias for such modules and the information is lost.
> 
> As a result kmod (which uses modules.builtin.modinfo in userspace)
> cannot determine that modalias is handled by a builtin kernel module.
> 
> $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias
> pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
> 
> $ modinfo xhci_pci
> name:           xhci_pci
> filename:       (builtin)
> license:        GPL
> file:           drivers/usb/host/xhci-pci
> description:    xHCI PCI Host Controller Driver
> 
> Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by
> modpost if the module is built separately.
> 
> To fix this it is necessary to generate the same modalias for vmlinux as
> for the individual modules. Fortunately '.vmlinux.export.o' is already
> generated from which '.modinfo' can be extracted in the same way as for
> vmlinux.o.

Hi -

This patch broke RISC-V builds for me. During the final objcopy where the new
symbols are supposed to be stripped, an error occurs producing lots of error
messages similar to this one:

riscv64-linux-gnu-objcopy: not stripping symbol `__mod_device_table__...'
because it is named in a relocation

It does not occur using defconfig, but I was able to bisect my way to this
commit and then reduce my config delta w.r.t defconfig until I landed on:

cat > .config <<'EOF'
CONFIG_RELOCATABLE=y
CONFIG_KASAN=y
EOF
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make olddefconfig
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make -j $(nproc)
...
  LD      vmlinux.unstripped
  NM      System.map
  SORTTAB vmlinux.unstripped
  CHKREL  vmlinux.unstripped
  OBJCOPY vmlinux
  OBJCOPY modules.builtin.modinfo
  GEN     modules.builtin
riscv64-linux-gnu-objcopy: not stripping symbol `<long symbol name>'
because it is named in a relocation
<repeats with different symbol names about a dozen times>
make[3]: *** [scripts/Makefile.vmlinux:97: vmlinux] Error 1
make[3]: *** Deleting file 'vmlinux'
make[2]: *** [Makefile:1242: vmlinux] Error 2
make[1]: *** [/tmp/linux/Makefile:369: __build_one_by_one] Error 2
make: *** [Makefile:248: __sub-make] Error 2

I confirmed that reverting this commit fixes the issue.

> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  include/linux/module.h   |  4 ----
>  scripts/Makefile.vmlinux |  4 +++-
>  scripts/mksysmap         |  3 +++
>  scripts/mod/file2alias.c | 19 ++++++++++++++++++-
>  scripts/mod/modpost.c    | 15 +++++++++++++++
>  scripts/mod/modpost.h    |  2 ++
>  6 files changed, 41 insertions(+), 6 deletions(-)
> 
> diff --git a/include/linux/module.h b/include/linux/module.h
> index e31ee29fac6b7..e135cc79aceea 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -256,14 +256,10 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
>  	__PASTE(type,			\
>  	__PASTE(__, name)))))
>  
> -#ifdef MODULE
>  /* Creates an alias so file2alias.c can find device table. */
>  #define MODULE_DEVICE_TABLE(type, name)					\
>  static typeof(name) __mod_device_table(type, name)			\
>    __attribute__ ((used, alias(__stringify(name))))
> -#else  /* !MODULE */
> -#define MODULE_DEVICE_TABLE(type, name)
> -#endif
>  
>  /* Version of form [<epoch>:]<version>[-<extra-version>].
>   * Or for CVS/RCS ID version, everything but the number is stripped.
> diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> index ce79461714979..1e5e37aadcd05 100644
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -89,11 +89,13 @@ endif
>  remove-section-y                                   := .modinfo
>  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
>  
> +remove-symbols := -w --strip-symbol='__mod_device_table__*'
> +
>  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
>  # it is necessary to remove the PT_LOAD flag from the segment.
>  quiet_cmd_strip_relocs = OBJCOPY $@
>        cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
> -                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $@
> +                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@
>  
>  targets += vmlinux
>  vmlinux: vmlinux.unstripped FORCE
> diff --git a/scripts/mksysmap b/scripts/mksysmap
> index a607a0059d119..c4531eacde202 100755
> --- a/scripts/mksysmap
> +++ b/scripts/mksysmap
> @@ -59,6 +59,9 @@
>  # EXPORT_SYMBOL (namespace)
>  / __kstrtabns_/d
>  
> +# MODULE_DEVICE_TABLE (symbol name)
> +/ __mod_device_table__/d
> +
>  # ---------------------------------------------------------------------------
>  # Ignored suffixes
>  #  (do not forget '$' after each pattern)
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index 1260bc2287fba..7da9735e7ab3e 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -1477,7 +1477,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
>  	void *symval;
>  	char *zeros = NULL;
>  	const char *type, *name, *modname;
> -	size_t typelen;
> +	size_t typelen, modnamelen;
>  	static const char *prefix = "__mod_device_table__";
>  
>  	/* We're looking for a section relative symbol */
> @@ -1500,6 +1500,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
>  	type = strstr(modname, "__");
>  	if (!type)
>  		return;
> +	modnamelen = type - modname;
>  	type += strlen("__");
>  
>  	name = strstr(type, "__");
> @@ -1526,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
>  		}
>  	}
>  
> +	if (mod->is_vmlinux) {
> +		struct module_alias *alias;
> +
> +		/*
> +		 * If this is vmlinux, record the name of the builtin module.
> +		 * Traverse the linked list in the reverse order, and set the
> +		 * builtin_modname unless it has already been set in the
> +		 * previous call.
> +		 */
> +		list_for_each_entry_reverse(alias, &mod->aliases, node) {
> +			if (alias->builtin_modname)
> +				break;
> +			alias->builtin_modname = xstrndup(modname, modnamelen);
> +		}
> +	}
> +
>  	free(zeros);
>  }
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 5ca7c268294eb..47c8aa2a69392 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -2067,11 +2067,26 @@ static void write_if_changed(struct buffer *b, const char *fname)
>  static void write_vmlinux_export_c_file(struct module *mod)
>  {
>  	struct buffer buf = { };
> +	struct module_alias *alias, *next;
>  
>  	buf_printf(&buf,
>  		   "#include <linux/export-internal.h>\n");
>  
>  	add_exported_symbols(&buf, mod);
> +
> +	buf_printf(&buf,
> +		   "#include <linux/module.h>\n"
> +		   "#undef __MODULE_INFO_PREFIX\n"
> +		   "#define __MODULE_INFO_PREFIX\n");
> +
> +	list_for_each_entry_safe(alias, next, &mod->aliases, node) {
> +		buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n",
> +			   alias->builtin_modname, alias->str);
> +		list_del(&alias->node);
> +		free(alias->builtin_modname);
> +		free(alias);
> +	}
> +
>  	write_if_changed(&buf, ".vmlinux.export.c");
>  	free(buf.p);
>  }
> diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
> index 9133e4c3803f0..2aecb8f25c87e 100644
> --- a/scripts/mod/modpost.h
> +++ b/scripts/mod/modpost.h
> @@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len);
>   * struct module_alias - auto-generated MODULE_ALIAS()
>   *
>   * @node: linked to module::aliases
> + * @modname: name of the builtin module (only for vmlinux)
>   * @str: a string for MODULE_ALIAS()
>   */
>  struct module_alias {
>  	struct list_head node;
> +	char *builtin_modname;
>  	char str[];
>  };
>  
> -- 
> 2.51.0
> 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-07  1:16   ` Charles Mirabile
@ 2025-10-07 10:15     ` Alexey Gladkov
  2025-10-09 19:52       ` Nicolas Schier
  0 siblings, 1 reply; 22+ messages in thread
From: Alexey Gladkov @ 2025-10-07 10:15 UTC (permalink / raw)
  To: Charles Mirabile
  Cc: da.gomez, linux-kbuild, linux-kernel, linux-modules, masahiroy,
	mcgrof, nathan, nicolas.schier, petr.pavlu, samitolvanen, sfr

On Mon, Oct 06, 2025 at 09:16:37PM -0400, Charles Mirabile wrote:
> On Thu, Sep 18, 2025 at 10:05:51AM +0200, Alexey Gladkov wrote:
> > For some modules, modalias is generated using the modpost utility and
> > the section is added to the module file.
> > 
> > When a module is added inside vmlinux, modpost does not generate
> > modalias for such modules and the information is lost.
> > 
> > As a result kmod (which uses modules.builtin.modinfo in userspace)
> > cannot determine that modalias is handled by a builtin kernel module.
> > 
> > $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias
> > pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
> > 
> > $ modinfo xhci_pci
> > name:           xhci_pci
> > filename:       (builtin)
> > license:        GPL
> > file:           drivers/usb/host/xhci-pci
> > description:    xHCI PCI Host Controller Driver
> > 
> > Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by
> > modpost if the module is built separately.
> > 
> > To fix this it is necessary to generate the same modalias for vmlinux as
> > for the individual modules. Fortunately '.vmlinux.export.o' is already
> > generated from which '.modinfo' can be extracted in the same way as for
> > vmlinux.o.
> 
> Hi -
> 
> This patch broke RISC-V builds for me. During the final objcopy where the new
> symbols are supposed to be stripped, an error occurs producing lots of error
> messages similar to this one:
> 
> riscv64-linux-gnu-objcopy: not stripping symbol `__mod_device_table__...'
> because it is named in a relocation
> 
> It does not occur using defconfig, but I was able to bisect my way to this
> commit and then reduce my config delta w.r.t defconfig until I landed on:
> 
> cat > .config <<'EOF'
> CONFIG_RELOCATABLE=y
> CONFIG_KASAN=y
> EOF
> ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make olddefconfig
> ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make -j $(nproc)
> ...
>   LD      vmlinux.unstripped
>   NM      System.map
>   SORTTAB vmlinux.unstripped
>   CHKREL  vmlinux.unstripped
>   OBJCOPY vmlinux
>   OBJCOPY modules.builtin.modinfo
>   GEN     modules.builtin
> riscv64-linux-gnu-objcopy: not stripping symbol `<long symbol name>'
> because it is named in a relocation
> <repeats with different symbol names about a dozen times>
> make[3]: *** [scripts/Makefile.vmlinux:97: vmlinux] Error 1
> make[3]: *** Deleting file 'vmlinux'
> make[2]: *** [Makefile:1242: vmlinux] Error 2
> make[1]: *** [/tmp/linux/Makefile:369: __build_one_by_one] Error 2
> make: *** [Makefile:248: __sub-make] Error 2
> 
> I confirmed that reverting this commit fixes the issue.

Hm. Indeed. I haven't found a good solution yet, but you can use the
following patch to unlock compilation. It won't solve the problem, it will
only hide it.

--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -84,7 +84,7 @@ endif
 remove-section-y                                   := .modinfo
 remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'

-remove-symbols := -w --strip-symbol='__mod_device_table__*'
+remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'

 # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
 # it is necessary to remove the PT_LOAD flag from the segment.

> > 
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > Signed-off-by: Alexey Gladkov <legion@kernel.org>
> > Tested-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > ---
> >  include/linux/module.h   |  4 ----
> >  scripts/Makefile.vmlinux |  4 +++-
> >  scripts/mksysmap         |  3 +++
> >  scripts/mod/file2alias.c | 19 ++++++++++++++++++-
> >  scripts/mod/modpost.c    | 15 +++++++++++++++
> >  scripts/mod/modpost.h    |  2 ++
> >  6 files changed, 41 insertions(+), 6 deletions(-)
> > 
> > diff --git a/include/linux/module.h b/include/linux/module.h
> > index e31ee29fac6b7..e135cc79aceea 100644
> > --- a/include/linux/module.h
> > +++ b/include/linux/module.h
> > @@ -256,14 +256,10 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
> >  	__PASTE(type,			\
> >  	__PASTE(__, name)))))
> >  
> > -#ifdef MODULE
> >  /* Creates an alias so file2alias.c can find device table. */
> >  #define MODULE_DEVICE_TABLE(type, name)					\
> >  static typeof(name) __mod_device_table(type, name)			\
> >    __attribute__ ((used, alias(__stringify(name))))
> > -#else  /* !MODULE */
> > -#define MODULE_DEVICE_TABLE(type, name)
> > -#endif
> >  
> >  /* Version of form [<epoch>:]<version>[-<extra-version>].
> >   * Or for CVS/RCS ID version, everything but the number is stripped.
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index ce79461714979..1e5e37aadcd05 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -89,11 +89,13 @@ endif
> >  remove-section-y                                   := .modinfo
> >  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> >  
> > +remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > +
> >  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
> >  # it is necessary to remove the PT_LOAD flag from the segment.
> >  quiet_cmd_strip_relocs = OBJCOPY $@
> >        cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
> > -                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $@
> > +                         $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@
> >  
> >  targets += vmlinux
> >  vmlinux: vmlinux.unstripped FORCE
> > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > index a607a0059d119..c4531eacde202 100755
> > --- a/scripts/mksysmap
> > +++ b/scripts/mksysmap
> > @@ -59,6 +59,9 @@
> >  # EXPORT_SYMBOL (namespace)
> >  / __kstrtabns_/d
> >  
> > +# MODULE_DEVICE_TABLE (symbol name)
> > +/ __mod_device_table__/d
> > +
> >  # ---------------------------------------------------------------------------
> >  # Ignored suffixes
> >  #  (do not forget '$' after each pattern)
> > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> > index 1260bc2287fba..7da9735e7ab3e 100644
> > --- a/scripts/mod/file2alias.c
> > +++ b/scripts/mod/file2alias.c
> > @@ -1477,7 +1477,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> >  	void *symval;
> >  	char *zeros = NULL;
> >  	const char *type, *name, *modname;
> > -	size_t typelen;
> > +	size_t typelen, modnamelen;
> >  	static const char *prefix = "__mod_device_table__";
> >  
> >  	/* We're looking for a section relative symbol */
> > @@ -1500,6 +1500,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> >  	type = strstr(modname, "__");
> >  	if (!type)
> >  		return;
> > +	modnamelen = type - modname;
> >  	type += strlen("__");
> >  
> >  	name = strstr(type, "__");
> > @@ -1526,5 +1527,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> >  		}
> >  	}
> >  
> > +	if (mod->is_vmlinux) {
> > +		struct module_alias *alias;
> > +
> > +		/*
> > +		 * If this is vmlinux, record the name of the builtin module.
> > +		 * Traverse the linked list in the reverse order, and set the
> > +		 * builtin_modname unless it has already been set in the
> > +		 * previous call.
> > +		 */
> > +		list_for_each_entry_reverse(alias, &mod->aliases, node) {
> > +			if (alias->builtin_modname)
> > +				break;
> > +			alias->builtin_modname = xstrndup(modname, modnamelen);
> > +		}
> > +	}
> > +
> >  	free(zeros);
> >  }
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 5ca7c268294eb..47c8aa2a69392 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -2067,11 +2067,26 @@ static void write_if_changed(struct buffer *b, const char *fname)
> >  static void write_vmlinux_export_c_file(struct module *mod)
> >  {
> >  	struct buffer buf = { };
> > +	struct module_alias *alias, *next;
> >  
> >  	buf_printf(&buf,
> >  		   "#include <linux/export-internal.h>\n");
> >  
> >  	add_exported_symbols(&buf, mod);
> > +
> > +	buf_printf(&buf,
> > +		   "#include <linux/module.h>\n"
> > +		   "#undef __MODULE_INFO_PREFIX\n"
> > +		   "#define __MODULE_INFO_PREFIX\n");
> > +
> > +	list_for_each_entry_safe(alias, next, &mod->aliases, node) {
> > +		buf_printf(&buf, "MODULE_INFO(%s.alias, \"%s\");\n",
> > +			   alias->builtin_modname, alias->str);
> > +		list_del(&alias->node);
> > +		free(alias->builtin_modname);
> > +		free(alias);
> > +	}
> > +
> >  	write_if_changed(&buf, ".vmlinux.export.c");
> >  	free(buf.p);
> >  }
> > diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
> > index 9133e4c3803f0..2aecb8f25c87e 100644
> > --- a/scripts/mod/modpost.h
> > +++ b/scripts/mod/modpost.h
> > @@ -99,10 +99,12 @@ buf_write(struct buffer *buf, const char *s, int len);
> >   * struct module_alias - auto-generated MODULE_ALIAS()
> >   *
> >   * @node: linked to module::aliases
> > + * @modname: name of the builtin module (only for vmlinux)
> >   * @str: a string for MODULE_ALIAS()
> >   */
> >  struct module_alias {
> >  	struct list_head node;
> > +	char *builtin_modname;
> >  	char str[];
> >  };
> >  
> > -- 
> > 2.51.0
> > 
> 

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-07 10:15     ` Alexey Gladkov
@ 2025-10-09 19:52       ` Nicolas Schier
  2025-10-10  5:37         ` Nathan Chancellor
  0 siblings, 1 reply; 22+ messages in thread
From: Nicolas Schier @ 2025-10-09 19:52 UTC (permalink / raw)
  To: Alexey Gladkov
  Cc: Charles Mirabile, da.gomez, linux-kbuild, linux-kernel,
	linux-modules, masahiroy, mcgrof, nathan, petr.pavlu,
	samitolvanen, sfr

On Tue, Oct 07, 2025 at 12:15:21PM +0200, Alexey Gladkov wrote:
> On Mon, Oct 06, 2025 at 09:16:37PM -0400, Charles Mirabile wrote:
> > On Thu, Sep 18, 2025 at 10:05:51AM +0200, Alexey Gladkov wrote:
> > > For some modules, modalias is generated using the modpost utility and
> > > the section is added to the module file.
> > > 
> > > When a module is added inside vmlinux, modpost does not generate
> > > modalias for such modules and the information is lost.
> > > 
> > > As a result kmod (which uses modules.builtin.modinfo in userspace)
> > > cannot determine that modalias is handled by a builtin kernel module.
> > > 
> > > $ cat /sys/devices/pci0000:00/0000:00:14.0/modalias
> > > pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
> > > 
> > > $ modinfo xhci_pci
> > > name:           xhci_pci
> > > filename:       (builtin)
> > > license:        GPL
> > > file:           drivers/usb/host/xhci-pci
> > > description:    xHCI PCI Host Controller Driver
> > > 
> > > Missing modalias "pci:v*d*sv*sd*bc0Csc03i30*" which will be generated by
> > > modpost if the module is built separately.
> > > 
> > > To fix this it is necessary to generate the same modalias for vmlinux as
> > > for the individual modules. Fortunately '.vmlinux.export.o' is already
> > > generated from which '.modinfo' can be extracted in the same way as for
> > > vmlinux.o.
> > 
> > Hi -
> > 
> > This patch broke RISC-V builds for me. During the final objcopy where the new
> > symbols are supposed to be stripped, an error occurs producing lots of error
> > messages similar to this one:
> > 
> > riscv64-linux-gnu-objcopy: not stripping symbol `__mod_device_table__...'
> > because it is named in a relocation
> > 
> > It does not occur using defconfig, but I was able to bisect my way to this
> > commit and then reduce my config delta w.r.t defconfig until I landed on:
> > 
> > cat > .config <<'EOF'
> > CONFIG_RELOCATABLE=y
> > CONFIG_KASAN=y
> > EOF
> > ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make olddefconfig
> > ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make -j $(nproc)
> > ...
> >   LD      vmlinux.unstripped
> >   NM      System.map
> >   SORTTAB vmlinux.unstripped
> >   CHKREL  vmlinux.unstripped
> >   OBJCOPY vmlinux
> >   OBJCOPY modules.builtin.modinfo
> >   GEN     modules.builtin
> > riscv64-linux-gnu-objcopy: not stripping symbol `<long symbol name>'
> > because it is named in a relocation
> > <repeats with different symbol names about a dozen times>
> > make[3]: *** [scripts/Makefile.vmlinux:97: vmlinux] Error 1
> > make[3]: *** Deleting file 'vmlinux'
> > make[2]: *** [Makefile:1242: vmlinux] Error 2
> > make[1]: *** [/tmp/linux/Makefile:369: __build_one_by_one] Error 2
> > make: *** [Makefile:248: __sub-make] Error 2
> > 
> > I confirmed that reverting this commit fixes the issue.

Thanks for the report!

> 
> Hm. Indeed. I haven't found a good solution yet, but you can use the
> following patch to unlock compilation. It won't solve the problem, it will
> only hide it.
> 
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -84,7 +84,7 @@ endif
>  remove-section-y                                   := .modinfo
>  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> 
> -remove-symbols := -w --strip-symbol='__mod_device_table__*'
> +remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'
> 
>  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
>  # it is necessary to remove the PT_LOAD flag from the segment.
> 

Is it problematic to hide that?  Otherwise we'd have to revert the
patch, right?

Kind regards,
Nicolas


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-09 19:52       ` Nicolas Schier
@ 2025-10-10  5:37         ` Nathan Chancellor
  2025-10-10  8:02           ` Alexey Gladkov
  2025-10-10 13:24           ` Charles Mirabile
  0 siblings, 2 replies; 22+ messages in thread
From: Nathan Chancellor @ 2025-10-10  5:37 UTC (permalink / raw)
  To: Nicolas Schier
  Cc: Alexey Gladkov, Charles Mirabile, da.gomez, linux-kbuild,
	linux-kernel, linux-modules, masahiroy, mcgrof, petr.pavlu,
	samitolvanen, sfr

On Thu, Oct 09, 2025 at 09:52:08PM +0200, Nicolas Schier wrote:
> On Tue, Oct 07, 2025 at 12:15:21PM +0200, Alexey Gladkov wrote:
> > Hm. Indeed. I haven't found a good solution yet, but you can use the
> > following patch to unlock compilation. It won't solve the problem, it will
> > only hide it.
> > 
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -84,7 +84,7 @@ endif
> >  remove-section-y                                   := .modinfo
> >  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > 
> > -remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > +remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'
> > 
> >  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
> >  # it is necessary to remove the PT_LOAD flag from the segment.
> > 
> 
> Is it problematic to hide that?  Otherwise we'd have to revert the
> patch, right?

Yeah, I would much prefer to ending up with pointless
__mod_device_table__ symbols in the final binary than erroring out
during the build... Does this happen with other architectures? I have
not seen any reports yet but I have not tested anything yet. Why is
RISC-V special here?

It seems like the relocation comes from the .LASANLOC4 symbol in
.data.rel.local?

  $ llvm-objdump -Dr drivers/irqchip/irq-riscv-aplic-main.o
  ...
  Disassembly of section .data.rel.local:
  ...
  0000000000000130 <.LASANLOC4>:
  ...
       1c0: 0000          unimp
          00000000000001c0:  R_RISCV_64   __mod_device_table__kmod_irq_riscv_aplic_main__acpi__aplic_acpi_match
  ...

I cannot find much information about this ASANLOC outside of its
location within the GCC sources, do we even need it? I don't see a way
to opt out of this section altogether or on a per-variable basis, I
wonder if there is some way to strip it out...

I plan to send the initial 6.18 Kbuild fixes pull request on Saturday.
If we cannot figure out a real solution before then, maybe we can just
switch to '--strip-unneeded-symbol' with a comment to upgrade that to
'--strip-symbol' when possible?

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-10  5:37         ` Nathan Chancellor
@ 2025-10-10  8:02           ` Alexey Gladkov
  2025-10-10 10:58             ` Alexey Gladkov
  2025-10-10 13:24           ` Charles Mirabile
  1 sibling, 1 reply; 22+ messages in thread
From: Alexey Gladkov @ 2025-10-10  8:02 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, Charles Mirabile, da.gomez, linux-kbuild,
	linux-kernel, linux-modules, masahiroy, mcgrof, petr.pavlu,
	samitolvanen, sfr

On Thu, Oct 09, 2025 at 10:37:36PM -0700, Nathan Chancellor wrote:
> On Thu, Oct 09, 2025 at 09:52:08PM +0200, Nicolas Schier wrote:
> > On Tue, Oct 07, 2025 at 12:15:21PM +0200, Alexey Gladkov wrote:
> > > Hm. Indeed. I haven't found a good solution yet, but you can use the
> > > following patch to unlock compilation. It won't solve the problem, it will
> > > only hide it.
> > > 
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -84,7 +84,7 @@ endif
> > >  remove-section-y                                   := .modinfo
> > >  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > 
> > > -remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > > +remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'
> > > 
> > >  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
> > >  # it is necessary to remove the PT_LOAD flag from the segment.
> > > 
> > 
> > Is it problematic to hide that?  Otherwise we'd have to revert the
> > patch, right?
> 
> Yeah, I would much prefer to ending up with pointless
> __mod_device_table__ symbols in the final binary than erroring out
> during the build...

This is a very unpleasant problem, but it does not seem fatal. There will
not be many such characters in the final vmlinux. In the configuration
from the bug report, there are only:

$ nm vmlinux.unstripped.riscv |grep -c __mod_device_table__
17

Of course, this does not mean that the problem does not need to be solved.

> Does this happen with other architectures? I have
> not seen any reports yet but I have not tested anything yet.

LDFLAGS_vmlinux for riscv was taken from arm64. I suspect that there may
be the same problem there. But I haven't checked yet whether the problem
actually exists on arm64.

> Why is RISC-V special here?

This problem on riscv only occurs when CONFIG_RELOCATABLE=y is specified.
Without this parameter, everything will compile as expected.
 
> It seems like the relocation comes from the .LASANLOC4 symbol in
> .data.rel.local?
> 
>   $ llvm-objdump -Dr drivers/irqchip/irq-riscv-aplic-main.o
>   ...
>   Disassembly of section .data.rel.local:
>   ...
>   0000000000000130 <.LASANLOC4>:
>   ...
>        1c0: 0000          unimp
>           00000000000001c0:  R_RISCV_64   __mod_device_table__kmod_irq_riscv_aplic_main__acpi__aplic_acpi_match
>   ...
> 
> I cannot find much information about this ASANLOC outside of its
> location within the GCC sources, do we even need it? I don't see a way
> to opt out of this section altogether or on a per-variable basis, I
> wonder if there is some way to strip it out...

The aplic_acpi_match structure is indeed used, but they are used
themselves, not their alias, which is generated by the MODULE_DEVICE_TABLE
macro.

I also asked the guys from binutils for help:

https://sourceware.org/pipermail/binutils/2025-October/144782.html

> I plan to send the initial 6.18 Kbuild fixes pull request on Saturday.
> If we cannot figure out a real solution before then, maybe we can just
> switch to '--strip-unneeded-symbol' with a comment to upgrade that to
> '--strip-symbol' when possible?

Yes, that would be great.



Maybe I'm looking in the wrong direction, but still.

On riscv:

* with CONFIG_RELOCATABLE=y (where the error appears):

vmlinux.unstripped: ELF 64-bit LSB shared object, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), dynamically linked, not stripped

* without CONFIG_RELOCATABLE:

vmlinux.unstripped: ELF 64-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, not stripped

On x64_64:

* with and without CONFIG_RELOCATABLE=y:

vmlinux.unstripped: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-10  8:02           ` Alexey Gladkov
@ 2025-10-10 10:58             ` Alexey Gladkov
  0 siblings, 0 replies; 22+ messages in thread
From: Alexey Gladkov @ 2025-10-10 10:58 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, Charles Mirabile, da.gomez, linux-kbuild,
	linux-kernel, linux-modules, masahiroy, mcgrof, petr.pavlu,
	samitolvanen, sfr

On Fri, Oct 10, 2025 at 10:02:20AM +0200, Alexey Gladkov wrote:
> On Thu, Oct 09, 2025 at 10:37:36PM -0700, Nathan Chancellor wrote:
> > On Thu, Oct 09, 2025 at 09:52:08PM +0200, Nicolas Schier wrote:
> > > On Tue, Oct 07, 2025 at 12:15:21PM +0200, Alexey Gladkov wrote:
> > > > Hm. Indeed. I haven't found a good solution yet, but you can use the
> > > > following patch to unlock compilation. It won't solve the problem, it will
> > > > only hide it.
> > > > 
> > > > --- a/scripts/Makefile.vmlinux
> > > > +++ b/scripts/Makefile.vmlinux
> > > > @@ -84,7 +84,7 @@ endif
> > > >  remove-section-y                                   := .modinfo
> > > >  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > > 
> > > > -remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > > > +remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'
> > > > 
> > > >  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
> > > >  # it is necessary to remove the PT_LOAD flag from the segment.
> > > > 
> > > 
> > > Is it problematic to hide that?  Otherwise we'd have to revert the
> > > patch, right?
> > 
> > Yeah, I would much prefer to ending up with pointless
> > __mod_device_table__ symbols in the final binary than erroring out
> > during the build...
> 
> This is a very unpleasant problem, but it does not seem fatal. There will
> not be many such characters in the final vmlinux. In the configuration
> from the bug report, there are only:
> 
> $ nm vmlinux.unstripped.riscv |grep -c __mod_device_table__
> 17
> 
> Of course, this does not mean that the problem does not need to be solved.
> 
> > Does this happen with other architectures? I have
> > not seen any reports yet but I have not tested anything yet.
> 
> LDFLAGS_vmlinux for riscv was taken from arm64. I suspect that there may
> be the same problem there. But I haven't checked yet whether the problem
> actually exists on arm64.

I tried to compile the kernel for arm64 with CONFIG_RELOCATABLE=y.
It works without errors and the symbols are removed.

vmlinux.unstripped: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped

-- 
Rgrds, legion


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v8 7/8] modpost: Create modalias for builtin modules
  2025-10-10  5:37         ` Nathan Chancellor
  2025-10-10  8:02           ` Alexey Gladkov
@ 2025-10-10 13:24           ` Charles Mirabile
  1 sibling, 0 replies; 22+ messages in thread
From: Charles Mirabile @ 2025-10-10 13:24 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, Alexey Gladkov, da.gomez, linux-kbuild,
	linux-kernel, linux-modules, masahiroy, mcgrof, petr.pavlu,
	samitolvanen, sfr

On Fri, Oct 10, 2025 at 1:37 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Thu, Oct 09, 2025 at 09:52:08PM +0200, Nicolas Schier wrote:
> > On Tue, Oct 07, 2025 at 12:15:21PM +0200, Alexey Gladkov wrote:
> > > Hm. Indeed. I haven't found a good solution yet, but you can use the
> > > following patch to unlock compilation. It won't solve the problem, it will
> > > only hide it.
> > >
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -84,7 +84,7 @@ endif
> > >  remove-section-y                                   := .modinfo
> > >  remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > >
> > > -remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > > +remove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*'
> > >
> > >  # To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy,
> > >  # it is necessary to remove the PT_LOAD flag from the segment.
> > >
> >
> > Is it problematic to hide that?  Otherwise we'd have to revert the
> > patch, right?
>
> Yeah, I would much prefer to ending up with pointless
> __mod_device_table__ symbols in the final binary than erroring out
> during the build... Does this happen with other architectures? I have
> not seen any reports yet but I have not tested anything yet. Why is
> RISC-V special here?
>
> It seems like the relocation comes from the .LASANLOC4 symbol in
> .data.rel.local?
>
>   $ llvm-objdump -Dr drivers/irqchip/irq-riscv-aplic-main.o
>   ...
>   Disassembly of section .data.rel.local:
>   ...
>   0000000000000130 <.LASANLOC4>:
>   ...
>        1c0: 0000          unimp
>           00000000000001c0:  R_RISCV_64   __mod_device_table__kmod_irq_riscv_aplic_main__acpi__aplic_acpi_match
>   ...
>
> I cannot find much information about this ASANLOC outside of its
> location within the GCC sources, do we even need it? I don't see a way
> to opt out of this section altogether or on a per-variable basis, I
> wonder if there is some way to strip it out...

It seems from reading the gcc source that these are emitted to contain
information about where global declarations came from, presumably to
allow nicer ASAN error messages. (i.e. memory corruption affected this
symbol defined here). I don't think that KASAN uses these, but I am
not sure. I also don't know how they could be removed. I found a hit
using grep.app https://grep.app/search?case=true&q=ASANLOC in the
apache/nuttx repository where they seem to be doing something with
these symbols in a linker script, but I am not familiar enough with
linker scripts, or that project to fully understand what is going on.


>
> I plan to send the initial 6.18 Kbuild fixes pull request on Saturday.
> If we cannot figure out a real solution before then, maybe we can just
> switch to '--strip-unneeded-symbol' with a comment to upgrade that to
> '--strip-symbol' when possible?
>
> Cheers,
> Nathan
>


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-10-10 13:25 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18  8:05 [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Alexey Gladkov
2025-09-18  8:05 ` [PATCH v8 1/8] s390: vmlinux.lds.S: Reorder sections Alexey Gladkov
2025-09-18  8:05 ` [PATCH v8 2/8] kbuild: always create intermediate vmlinux.unstripped Alexey Gladkov
2025-09-18  8:05 ` [PATCH v8 3/8] kbuild: keep .modinfo section in vmlinux.unstripped Alexey Gladkov
2025-09-24  6:29   ` Nicolas Schier
2025-09-18  8:05 ` [PATCH v8 4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped Alexey Gladkov
2025-09-18  8:05 ` [PATCH v8 5/8] scsi: Always define blogic_pci_tbl structure Alexey Gladkov
2025-09-18  8:05 ` [PATCH v8 6/8] modpost: Add modname to mod_device_table alias Alexey Gladkov
2025-09-24  6:31   ` Nicolas Schier
2025-09-18  8:05 ` [PATCH v8 7/8] modpost: Create modalias for builtin modules Alexey Gladkov
2025-09-24  6:38   ` Nicolas Schier
2025-10-07  1:16   ` Charles Mirabile
2025-10-07 10:15     ` Alexey Gladkov
2025-10-09 19:52       ` Nicolas Schier
2025-10-10  5:37         ` Nathan Chancellor
2025-10-10  8:02           ` Alexey Gladkov
2025-10-10 10:58             ` Alexey Gladkov
2025-10-10 13:24           ` Charles Mirabile
2025-09-18  8:05 ` [PATCH v8 8/8] kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o Alexey Gladkov
2025-09-24  6:39   ` Nicolas Schier
2025-09-18 17:35 ` [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo Nathan Chancellor
2025-09-24 16:17 ` Nathan Chancellor

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).