kbuild: generate module.builtin.modinfo from vmlinux.unstripped instead of vmlinux.o
Subsystems (10)
cover kbuild: generate module.builtin.modinfo from vmlinux.unstripped instead of vmlinux.o
Currently, modules.builtin.modinfo is generated from vmlinux.o, which occurs before modpost. So, we cannot include modpost-processed data into modules.builtin.modinfo.
This patch set allows to generate modules.builtin.modinfo from vmlinux.unstripped.
I think this patch set will be useful to clean up this:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#m98813857abf2101bdf67f1b8529a44f5c7f4746d
The original approach generates modules.builtin.modinfo from two files and then cancatenates them into a single file.
I prefer generating modules.builtin.modinfo from a single point.
I think 1/4 is a good cleanup regardless of modules.builtin.modinfo
Masahiro Yamada (4):
module: remove meaningless 'name' parameter from __MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 3 -- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- scripts/Makefile.vmlinux | 73 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 3 ++ 8 files changed, 63 insertions(+), 61 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 module: remove meaningless 'name' parameter from __MODULE_INFO()
The symbol names in the .modinfo section are never used and already randomized by the __UNIQUE_ID() macro.
Therefore, the second parameter of __MODULE_INFO() is meaningless and can be removed to simplify the code.
With this change, the symbol names in the .modinfo section will be prefixed with __UNIQUE_ID_modinfo, making it clearer that they originate from MODULE_INFO().
[Before]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_license560 0000000000000011 r __UNIQUE_ID_file559 0000000000000030 r __UNIQUE_ID_description558 0000000000000074 r __UNIQUE_ID_license580 000000000000008e r __UNIQUE_ID_file579 00000000000000bd r __UNIQUE_ID_description578 00000000000000e6 r __UNIQUE_ID_license581 00000000000000ff r __UNIQUE_ID_file580 0000000000000134 r __UNIQUE_ID_description579 0000000000000179 r __UNIQUE_ID_uncore_no_discover578
[After]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_modinfo560 0000000000000011 r __UNIQUE_ID_modinfo559 0000000000000030 r __UNIQUE_ID_modinfo558 0000000000000074 r __UNIQUE_ID_modinfo580 000000000000008e r __UNIQUE_ID_modinfo579 00000000000000bd r __UNIQUE_ID_modinfo578 00000000000000e6 r __UNIQUE_ID_modinfo581 00000000000000ff r __UNIQUE_ID_modinfo580 0000000000000134 r __UNIQUE_ID_modinfo579 0000000000000179 r __UNIQUE_ID_modinfo578
---
include/crypto/algapi.h | 4 ++-- include/linux/module.h | 3 --- include/linux/moduleparam.h | 9 +++++---- include/net/tcp.h | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-)
include/crypto/algapi.h +2 -2
@@ -43,8 +43,8 @@* alias. */ #define MODULE_ALIAS_CRYPTO (name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_crypto, "crypto-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "crypto-" name)struct crypto_aead ;struct crypto_instance ;
include/linux/module.h +0 -3
@@ -164,9 +164,6 @@ extern void cleanup_module(void);struct module_kobject *lookup_or_create_module_kobject (const char *name); -/* Generic info of form tag = "info" */ -#define MODULE_INFO (tag, info) __MODULE_INFO(tag, tag, info) -/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias)
include/linux/moduleparam.h +5 -4
@@ -20,18 +20,19 @@/* Chosen so that structs with an unsigned long line up. */ #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) -#define __MODULE_INFO (tag, name, info) \ - static const char __UNIQUE_ID(name)[] \ +/* Generic info of form tag = "info" */ +#define MODULE_INFO (tag, info) \ + static const char __UNIQUE_ID(modinfo)[] \ __used __section(".modinfo") __aligned(1) \ = __MODULE_INFO_PREFIX __stringify(tag) "=" info#define __MODULE_PARM_TYPE (name, _type) \ - __MODULE_INFO(parmtype, name##type, #name ":" _type) + MODULE_INFO(parmtype, #name ":" _type)/* One for each parameter, describing how to use it. Some files do multiple of these per line, so can't just use MODULE_INFO. */ #define MODULE_PARM_DESC (_parm, desc) \ - __MODULE_INFO(parm, _parm, #_parm ":" desc) + MODULE_INFO(parm, #_parm ":" desc)struct kernel_param ;
include/net/tcp.h +2 -2
@@ -2661,8 +2661,8 @@ void tcp_update_ulp(struct sock *sk, struct proto *p, void (*write_space)(struct sock *sk));#define MODULE_ALIAS_TCP_ULP (name) \ - __MODULE_INFO(alias, alias_userspace, name); \ - __MODULE_INFO(alias, alias_tcp_ulp, "tcp-ulp-" name) + MODULE_INFO(alias, name); \ + MODULE_INFO(alias, "tcp-ulp-" name)#ifdef CONFIG_NET_SOCK_MSG struct sk_msg ;
Signature · 1 line
2.43.0
Re: [PATCH 1/4] module: remove meaningless 'name' parameter from __MODULE_INFO()
Quoted 63 lines · Masahiro Yamada
The symbol names in the .modinfo section are never used and already randomized by the
__UNIQUE_ID()macro.Therefore, the second parameter of
__MODULE_INFO()is meaningless and can be removed to simplify the code.With this change, the symbol names in the .modinfo section will be prefixed with
__UNIQUE_ID_modinfo, making it clearer that they originate fromMODULE_INFO().[Before]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_license560 0000000000000011 r __UNIQUE_ID_file559 0000000000000030 r __UNIQUE_ID_description558 0000000000000074 r __UNIQUE_ID_license580 000000000000008e r __UNIQUE_ID_file579 00000000000000bd r __UNIQUE_ID_description578 00000000000000e6 r __UNIQUE_ID_license581 00000000000000ff r __UNIQUE_ID_file580 0000000000000134 r __UNIQUE_ID_description579 0000000000000179 r __UNIQUE_ID_uncore_no_discover578[After]
$ objcopy -j .modinfo vmlinux.o modinfo.o $ nm -n modinfo.o | head -n10 0000000000000000 r __UNIQUE_ID_modinfo560 0000000000000011 r __UNIQUE_ID_modinfo559 0000000000000030 r __UNIQUE_ID_modinfo558 0000000000000074 r __UNIQUE_ID_modinfo580 000000000000008e r __UNIQUE_ID_modinfo579 00000000000000bd r __UNIQUE_ID_modinfo578 00000000000000e6 r __UNIQUE_ID_modinfo581 00000000000000ff r __UNIQUE_ID_modinfo580 0000000000000134 r __UNIQUE_ID_modinfo579 0000000000000179 r __UNIQUE_ID_modinfo578Signed-off-by Masahiro Yamada <[email protected]>---
[...]include/linux/module.h +0
-3@@ -164,9 +164,6 @@ extern void cleanup_module(void);struct module_kobject *lookup_or_create_module_kobject (const char *name); -/* Generic info of form tag = "info" */ -#define MODULE_INFO (tag, info) __MODULE_INFO(tag, tag, info) -/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias)include/linux/moduleparam.h +0
-0@@ -20,18 +20,19 @@/* Chosen so that structs with an unsigned long line up. */
include/linux/moduleparam.h line 28
Quoted 10 lines
include/linux/moduleparam.h +3
-2#define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) -#define __MODULE_INFO (tag, name, info) \ - static const char __UNIQUE_ID(name)[] \ +/* Generic info of form tag = "info" */ +#define MODULE_INFO (tag, info) \ + static const char __UNIQUE_ID(modinfo)[] \ __used __section(".modinfo") __aligned(1) \ = __MODULE_INFO_PREFIX __stringify(tag) "=" info
One nit is that MODULE_INFO() is now defined in moduleparam.h, even though it is a general macro for adding module information and not specifically tied to parameters. I realize it is needed in moduleparam.h and that the dependency is from module.h to moduleparam.h, not the other way around. We could potentially keep the MODULE_INFO() (in module.h) -> __MODULE_INFO() (moduleparam.h) split solely for this, but it is probably unnecessary.
The overall change looks ok to me.
Signature · 2 lines
Thanks, Petr
PATCH 2/4 kbuild: always create intermediate vmlinux.unstripped
In reply to Masahiro YamadaGenerate 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.
---
scripts/Makefile.vmlinux | 45 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
scripts/Makefile.vmlinux +22 -23
@@ -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
Signature · 1 line
2.43.0
PATCH 3/4 kbuild: keep .modinfo section in vmlinux.unstripped
In reply to Masahiro YamadaKeep 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.
---
include/asm-generic/vmlinux.lds.h | 2 +- scripts/Makefile.vmlinux | 2 +- scripts/mksysmap | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-)
include/asm-generic/vmlinux.lds.h +1 -1
@@ -830,6 +830,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) } \
@@ -1043,7 +1044,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*) \
scripts/Makefile.vmlinux +1 -1
@@ -86,7 +86,7 @@ endif # vmlinux # --------------------------------------------------------------------------- -remove-section-y := +remove-section-y := .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' quiet_cmd_strip_relocs = OBJCOPY $@
scripts/mksysmap +3 -0
@@ -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)
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH 3/4] kbuild: keep .modinfo section in vmlinux.unstripped
kernel test robot noticed the following build warnings:
Hi Masahiro,
kernel test robot noticed the following build warnings:
[auto build test WARNING on masahiroy-kbuild/for-next]
[also build test WARNING on masahiroy-kbuild/fixes linus/master v6.15 next-20250606]
[cannot apply to herbert-cryptodev-2.6/master herbert-crypto-2.6/master arnd-asm-generic/master mcgrof/modules-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/module-remove-meaningless-name-parameter-from-__MODULE_INFO/20250606-121255 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/20250606041029.614348-4-masahiroy%40kernel.org patch subject: [PATCH 3/4] kbuild: keep .modinfo section in vmlinux.unstripped config: s390-randconfig-002-20250606 (https://download.01.org/0day-ci/archive/20250606/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250606/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> 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
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 4/4 kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
In reply to Masahiro YamadaCurrently, 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.
---
scripts/Makefile.vmlinux | 28 +++++++++++++++++++++++++++- scripts/Makefile.vmlinux_o | 26 +------------------------- 2 files changed, 28 insertions(+), 26 deletions(-)
scripts/Makefile.vmlinux +27 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only PHONY := __default -__default: vmlinux +__default: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include
@@ -96,6 +96,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
scripts/Makefile.vmlinux_o +1 -25
@@ -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. # ---------------------------------------------------------------------------
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH 4/4] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
kernel test robot noticed the following build errors:
Hi Masahiro,
kernel test robot noticed the following build errors:
[auto build test ERROR on masahiroy-kbuild/for-next]
[also build test ERROR on masahiroy-kbuild/fixes linus/master v6.15 next-20250606]
[cannot apply to herbert-cryptodev-2.6/master herbert-crypto-2.6/master arnd-asm-generic/master mcgrof/modules-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/module-remove-meaningless-name-parameter-from-__MODULE_INFO/20250606-121255 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/20250606041029.614348-5-masahiroy%40kernel.org patch subject: [PATCH 4/4] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: i386-buildonly-randconfig-004-20250606 (https://download.01.org/0day-ci/archive/20250606/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250606/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
All errors (new ones prefixed by >>):
>> make[4]: *** No rule to make target 'vmlinux', needed by 'arch/x86/boot/compressed/vmlinux.bin'.
make[4]: Target 'arch/x86/boot/compressed/vmlinux' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 4/4] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
In reply to Masahiro YamadaQuoted 20 lines · Masahiro Yamada
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 <[email protected]>---
scripts/Makefile.vmlinux | 28 +++++++++++++++++++++++++++- scripts/Makefile.vmlinux_o | 26 +------------------------- 2 files changed, 28 insertions(+), 26 deletions(-)scripts/Makefile.vmlinux +0
-0
scripts/Makefile.vmlinux line 4
Quoted 5 lines
scripts/Makefile.vmlinux +1
-1@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only PHONY := __default -__default: vmlinux +__default:
I found the problem. The problem I was talking about earlier [1] is caused by this hunk. If I revert it, everything will work.
Quoted 82 lines
scripts/Makefile.vmlinux +26
-0include include/config/auto.conf include $(srctree)/scripts/Kbuild.include@@ -96,6 +96,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_RANGESscripts/Makefile.vmlinux_o +1
-25@@ -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. # ---------------------------------------------------------------------------Signature · 1 line
2.43.0
Signature · 1 line
Rgrds, legion
Quoted 26 lines · Masahiro Yamada
Currently, modules.builtin.modinfo is generated from vmlinux.o, which occurs before modpost. So, we cannot include modpost-processed data into modules.builtin.modinfo.
This patch set allows to generate modules.builtin.modinfo from vmlinux.unstripped.
I think this patch set will be useful to clean up this:
https://lore.kernel.org/linux-kbuild/[email protected]/T/#m98813857abf2101bdf67f1b8529a44f5c7f4746d
The original approach generates modules.builtin.modinfo from two files and then cancatenates them into a single file.
I prefer generating modules.builtin.modinfo from a single point.
I think 1/4 is a good cleanup regardless of modules.builtin.modinfo
Masahiro Yamada (4):
module: remove meaningless 'name' parameter from__MODULE_INFO()
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
Quoted 9 lines
include/asm-generic/vmlinux.lds.h | 2 +- include/crypto/algapi.h | 4 +- include/linux/module.h | 3 -- include/linux/moduleparam.h | 9 ++-- include/net/tcp.h | 4 +- scripts/Makefile.vmlinux | 73 +++++++++++++++++++++---------- scripts/Makefile.vmlinux_o | 26 +---------- scripts/mksysmap | 3 ++ 8 files changed, 63 insertions(+), 61 deletions(-)
Hm. It doesn't work for me :(
I haven't been able to figure out what's wrong yet.
make[3]: *** No rule to make target 'vmlinux', needed by 'arch/x86/boot/compressed/../voffset.h'. Stop. make[2]: *** [arch/x86/boot/Makefile:96: arch/x86/boot/compressed/vmlinux] Error 2 make[1]: *** [arch/x86/Makefile:320: bzImage] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Signature · 1 line
Rgrds, legion
cover Add generated modalias to modules.builtin.modinfo
In reply to Masahiro YamadaIf these changes will be applied, the patchset [1] that adds the modpost generated aliases to modules.builtin.modinfo will look much smaller.
[1] https://lore.kernel.org/all/[email protected]/T/#m515563dbddb2f2fcd10b0f198db69aee533db088
Alexey Gladkov (3):
scsi: Always define blogic_pci_tbl structure
modpost: Add modname to mod_device_table alias
modpost: Create modalias for builtin modules
drivers/scsi/BusLogic.c | 2 -- include/linux/module.h | 18 +++++++++++------- rust/kernel/device_id.rs | 8 ++++---- scripts/Makefile.vmlinux | 5 ++++- scripts/mksysmap | 3 +++ scripts/mod/file2alias.c | 34 ++++++++++++++++++++++++++++++---- scripts/mod/modpost.c | 17 ++++++++++++++++- scripts/mod/modpost.h | 2 ++ 8 files changed, 70 insertions(+), 19 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/3 scsi: Always define blogic_pci_tbl structure
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.
--- drivers/scsi/BusLogic.c | 2 -- 1 file changed, 2 deletions(-)
drivers/scsi/BusLogic.c +0 -2
@@ -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},
@@ -3731,7 +3730,6 @@ static const struct pci_device_id blogic_pci_tbl[] = { {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, {0, }, }; -#endifMODULE_DEVICE_TABLE (pci, blogic_pci_tbl);module_init (blogic_init);
Signature · 1 line
2.49.0
PATCH 2/3 modpost: Add modname to mod_device_table alias
In reply to Alexey GladkovAt 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.
--- include/linux/module.h | 14 +++++++++++--- rust/kernel/device_id.rs | 8 ++++---- scripts/mod/file2alias.c | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 11 deletions(-)
include/linux/module.h +11 -3
@@ -243,11 +243,19 @@ 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> */ +#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) \ -extern typeof(name) __mod_device_table__##type##__##name \ - __attribute__ ((unused, alias(__stringify(name)))) +#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
rust/kernel/device_id.rs +4 -4
@@ -154,10 +154,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 ()) };
scripts/mod/file2alias.c +14 -4
@@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, {void *symval;char *zeros =NULL ; -const char *type, *name; -size_t typelen; +const char *type, *name, *modname; +size_t typelen, modnamelen;static const char *prefix ="__mod_device_table__" ;/* We're looking for a section relative symbol */
@@ -1488,10 +1488,20 @@ 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 ; + modnamelen = type - modname; + type +=strlen ("__" ); name =strstr (type,"__" );if (!name)
Signature · 1 line
2.49.0
PATCH 3/3 modpost: Create modalias for builtin modules
In reply to Alexey GladkovFor 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.
--- include/linux/module.h | 4 ---- scripts/Makefile.vmlinux | 5 ++++- scripts/mksysmap | 3 +++ scripts/mod/file2alias.c | 16 ++++++++++++++++ scripts/mod/modpost.c | 17 ++++++++++++++++- scripts/mod/modpost.h | 2 ++ 6 files changed, 41 insertions(+), 6 deletions(-)
include/linux/module.h +0 -4
@@ -251,14 +251,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.
scripts/Makefile.vmlinux +4 -1
@@ -89,8 +89,11 @@ endif remove-section-y := .modinfo remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' +remove-symbols := -w --strip-symbol='__mod_device_table__*' + quiet_cmd_strip_relocs = OBJCOPY $@ - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@ + cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \ + $(remove-symbols) $< $@ targets += vmlinux vmlinux: vmlinux.unstripped FORCE
scripts/mksysmap +3 -0
@@ -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)
scripts/mod/file2alias.c +16 -0
@@ -1527,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); }
scripts/mod/modpost.c +16 -1
@@ -2021,11 +2021,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" ); +"#include <linux/export-internal.h>\n" +"#include <linux/module.h>\n" );add_exported_symbols (&buf, mod); + +buf_printf (&buf, +"#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); }
scripts/mod/modpost.h +2 -0
@@ -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[]; };
Signature · 1 line
2.49.0