Add generated modalias to modules.builtin.modinfo
Subsystems (4)
v3 cover Add generated modalias to modules.builtin.modinfo
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 use this file to create a '.modinfo' section for builtin modules. The modules.builtin.modinfo file becomes a composite file. One part is extracted from vmlinux.o, the other part from .vmlinux.export.o.
Notes:
- v3:
* Add Reviewed-by tag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/[email protected]/
- 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/[email protected]/
Alexey Gladkov (6):
scsi: Define MODULE_DEVICE_TABLE only if necessary
modules: Add macros to specify modinfo prefix
modpost: Make mod_device_table aliases more unique
modpost: Create modalias for builtin modules
kbuild: Move modules.builtin.modinfo to another makefile
kbuild: Create modules.builtin.modinfo for modpost results
drivers/scsi/BusLogic.c | 2 +- include/linux/module.h | 21 +++++++++++----- include/linux/moduleparam.h | 7 ++++-- scripts/Makefile.vmlinux | 48 +++++++++++++++++++++++++++++++++++++ scripts/Makefile.vmlinux_o | 26 +------------------- scripts/mod/file2alias.c | 34 ++++++++++++++++++++++---- scripts/mod/modpost.c | 13 +++++++++- scripts/mod/modpost.h | 2 ++ 8 files changed, 114 insertions(+), 39 deletions(-)
Signature · 1 line
2.49.0
PATCH v3 1/6 scsi: Define MODULE_DEVICE_TABLE only if necessary
Define MODULE_DEVICE_TABLE only if a structure is defined for it.
drivers/scsi/BusLogic.c:3735:26: error: use of undeclared identifier 'blogic_pci_tbl'
3735 | MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);
--- drivers/scsi/BusLogic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/BusLogic.c +1 -1
@@ -3731,8 +3731,8 @@ static const struct pci_device_id blogic_pci_tbl[] = { {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)}, {0, }, }; -#endif MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); +#endif module_init(blogic_init); module_exit(blogic_exit);
Signature · 1 line
2.49.0
James Bottomley
maintainerRe: [PATCH v3 1/6] scsi: Define MODULE_DEVICE_TABLE only if necessary
Quoted 5 lines · Alexey Gladkov
Define
MODULE_DEVICE_TABLEonly if a structure is defined for it.
drivers/scsi/BusLogic.c:3735:26: error: use of undeclared identifier 'blogic_pci_tbl'
3735 |MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);
Well, a) need to cc the scsi list and b) how is this possible when MODULE_DEVICE_TABLE() has an empty definition if MODULE isn't defined (so the guard you move should be over an empty statement)?
Regards,
James
Re: [PATCH v3 1/6] scsi: Define MODULE_DEVICE_TABLE only if necessary
Quoted 8 lines · James Bottomley
Quoted 5 lines · Alexey Gladkov
Define
MODULE_DEVICE_TABLEonly if a structure is defined for it.
drivers/scsi/BusLogic.c:3735:26: error: use of undeclared identifier 'blogic_pci_tbl'
3735 |MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);Well, a) need to cc the scsi list
Sorry. I miss it.
Quoted 3 lines
and b) how is this possible when
MODULE_DEVICE_TABLE()has an empty definition if MODULE isn't defined (so the guard you move should be over an empty statement)?
In the next patch:
[PATCH v3 4/6] modpost: Create modalias for builtin modules
I remove this condition for the MODULE_DEVICE_TABLE macro and it will be always defined.
I put the drivers/scsi/BusLogic.c change before these changes to avoid errors. Besides, even an empty macro uses a structure name that is not defined (if MODULE isn't defined). This seems wrong in any case.
Signature · 1 line
Rgrds, legion
James Bottomley
maintainerRe: [PATCH v3 1/6] scsi: Define MODULE_DEVICE_TABLE only if necessary
Quoted 17 lines · Alexey Gladkov
Quoted 9 lines · James Bottomley
Quoted 6 lines · Alexey Gladkov
Define
MODULE_DEVICE_TABLEonly if a structure is defined for it.
drivers/scsi/BusLogic.c:3735:26: error: use of undeclared identifier
'blogic_pci_tbl'
3735 |MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);Well, a) need to cc the scsi list
Sorry. I miss it.
Quoted 3 lines
and b) how is this possible when
MODULE_DEVICE_TABLE()has an empty definition if MODULE isn't defined (so the guard you move should be over an empty statement)?
Quoted 6 lines
In the next patch:
[PATCH v3 4/6] modpost: Create modalias for builtin modules
I remove this condition for the
MODULE_DEVICE_TABLEmacro and it will be always defined.
Well, why? If there's a reason for the table to always exist, wouldn't the best fix then be to remove the module guards from the PCI table in the buslogic ... they only really exist to prevent a defined but not used error which it sounds like you're getting rid of?
Regards,
James
Re: [PATCH v3 1/6] scsi: Define MODULE_DEVICE_TABLE only if necessary
Quoted 22 lines · James Bottomley
Quoted 21 lines · Alexey Gladkov
Quoted 9 lines · James Bottomley
Quoted 6 lines · Alexey Gladkov
Define
MODULE_DEVICE_TABLEonly if a structure is defined for it.
drivers/scsi/BusLogic.c:3735:26: error: use of undeclared identifier
'blogic_pci_tbl'
3735 |MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);Well, a) need to cc the scsi list
Sorry. I miss it.
Quoted 3 lines
and b) how is this possible when
MODULE_DEVICE_TABLE()has an empty definition if MODULE isn't defined (so the guard you move should be over an empty statement)?In the next patch:
[PATCH v3 4/6] modpost: Create modalias for builtin modules
Quoted 7 lines
Quoted 2 lines
I remove this condition for the
MODULE_DEVICE_TABLEmacro and it will be always defined.Well, why? If there's a reason for the table to always exist, wouldn't the best fix then be to remove the module guards from the PCI table in the buslogic ... they only really exist to prevent a defined but not used error which it sounds like you're getting rid of?
I wanted to keep the original logic and remove the build error. Before my changes blogic_pci_tbl was only used when the module was built separately (MODULE case).
But yes, you are right. In this case, it would be more appropriate to remove the MODULE condition at all since MODULE_DEVICE_TABLE always makes sense after my changes.
Signature · 1 line
Rgrds, legion
PATCH v4 1/6 scsi: Always define blogic_pci_tbl structure
In reply to Alexey GladkovThe 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 v3 2/6 modules: Add macros to specify modinfo prefix
In reply to Alexey GladkovThe __MODULE_INFO macros always use __MODULE_INFO_PREFIX. The only way to use a different prefix is to override __MODULE_INFO_PREFIX, which is not very useful.
The new macro will be used in file2alias.c to generate modalias for builtin modules.
--- include/linux/module.h | 3 +++ include/linux/moduleparam.h | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/module.h +3 -0
@@ -170,6 +170,9 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias) +#define MODULE_ALIAS_MODNAME (_modname, _alias) \ + __MODULE_INFO_WITH_PREFIX(_modname ".", alias, alias, _alias) +/* Soft module dependencies. See man modprobe.d for details. * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz") */
include/linux/moduleparam.h +5 -2
@@ -20,10 +20,13 @@/* 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) \ +#define __MODULE_INFO_WITH_PREFIX (prefix, tag, name, info) \ static const char __UNIQUE_ID(name)[] \ __used __section(".modinfo") __aligned(1) \ - = __MODULE_INFO_PREFIX __stringify(tag) "=" info + = prefix __stringify(tag) "=" info + +#define __MODULE_INFO (tag, name, info) \ + __MODULE_INFO_WITH_PREFIX(__MODULE_INFO_PREFIX, tag, name, info)#define __MODULE_PARM_TYPE (name, _type) \ __MODULE_INFO(parmtype, name##type, #name ":" _type)
Signature · 1 line
2.49.0
Re: [PATCH v3 2/6] modules: Add macros to specify modinfo prefix
Quoted 4 lines · Alexey Gladkov
The
__MODULE_INFOmacros always use__MODULE_INFO_PREFIX. The only way to use a different prefix is to override__MODULE_INFO_PREFIX, which is not very useful.
Not necessarily.
This would be a very special case only used in modpost, and modpost can use MODULE_INFO() instead.
list_for_each_entry_safe(alias, next, &mod->aliases, node) {
- buf_printf(&buf, "MODULE_ALIAS_MODNAME(\"%s\", \"%s\");\n",
+ buf_printf(&buf, "MODULE_INFO(\"%s\".alias, \"%s\");\n",
alias->builtin_modname, alias->str);
list_del(&alias->node);
free(alias->builtin_modname);Quoted 47 lines
The new macro will be used in
file2alias.cto generate modalias for builtin modules.Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 3 +++ include/linux/moduleparam.h | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/linux/module.h +3
-0@@ -170,6 +170,9 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias) +#define MODULE_ALIAS_MODNAME (_modname, _alias) \ + __MODULE_INFO_WITH_PREFIX(_modname ".", alias, alias, _alias) +/* Soft module dependencies. See man modprobe.d for details. * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz") */ include/linux/moduleparam.h +5
-3@@ -20,10 +20,13 @@/* 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) \ +#define __MODULE_INFO_WITH_PREFIX (prefix, tag, name, info) \ static const char __UNIQUE_ID(name)[] \ __used __section(".modinfo") __aligned(1) \ - = __MODULE_INFO_PREFIX __stringify(tag) "=" info + = prefix __stringify(tag) "=" info + +#define __MODULE_INFO (tag, name, info) \ + __MODULE_INFO_WITH_PREFIX(__MODULE_INFO_PREFIX, tag, name, info)#define __MODULE_PARM_TYPE (name, _type) \ __MODULE_INFO(parmtype, name##type, #name ":" _type) --2.49.0
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 2/6] modules: Add macros to specify modinfo prefix
Quoted 12 lines · Masahiro Yamada
Quoted 4 lines · Alexey Gladkov
The
__MODULE_INFOmacros always use__MODULE_INFO_PREFIX. The only way to use a different prefix is to override__MODULE_INFO_PREFIX, which is not very useful.Not necessarily.
This would be a very special case only used in modpost, and modpost can useMODULE_INFO()instead.list_for_each_entry_safe(alias, next, &mod->aliases, node) {
Review
Quoted 5 lines
(quoted diff) +1
-1- buf_printf(&buf, "MODULE_ALIAS_MODNAME(\"%s\", \"%s\");\n", + buf_printf(&buf, "MODULE_INFO(\"%s\".alias, \"%s\");\n", alias->builtin_modname, alias->str); list_del(&alias->node); free(alias->builtin_modname);
You can't do that because a character can't contain quotation marks and periods.
.vmlinux.export.c:16163:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token 16163 | MODULE_INFO(ahci.alias, "pci:v*d*sv*sd*bc01sc06i01*");
| ^././include/linux/compiler_types.h:83:23: note: in definition of macro ‘___PASTE’
83 | #define ___PASTE(a,b) a##b
| ^
The same thing for variant with quotes:
.vmlinux.export.c:16163:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before string constant
16163 | MODULE_INFO("ahci".alias, "pci:v*d*sv*sd*bc01sc06i01*");
| ^~~~~~But I can do something like this to make it work:
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, unused, \"%s\");\n",
alias->builtin_modname, alias->str);Quoted 54 lines
Quoted 48 lines
The new macro will be used in
file2alias.cto generate modalias for builtin modules.Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 3 +++ include/linux/moduleparam.h | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)include/linux/module.h +3
-0@@ -170,6 +170,9 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* For userspace: you can also call me... */ #define MODULE_ALIAS (_alias) MODULE_INFO(alias, _alias) +#define MODULE_ALIAS_MODNAME (_modname, _alias) \ + __MODULE_INFO_WITH_PREFIX(_modname ".", alias, alias, _alias) +/* Soft module dependencies. See man modprobe.d for details. * Example: MODULE_SOFTDEP("pre: module-foo module-bar post: module-baz") */ include/linux/moduleparam.h +5
-3@@ -20,10 +20,13 @@/* 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) \ +#define __MODULE_INFO_WITH_PREFIX (prefix, tag, name, info) \ static const char __UNIQUE_ID(name)[] \ __used __section(".modinfo") __aligned(1) \ - = __MODULE_INFO_PREFIX __stringify(tag) "=" info + = prefix __stringify(tag) "=" info + +#define __MODULE_INFO (tag, name, info) \ + __MODULE_INFO_WITH_PREFIX(__MODULE_INFO_PREFIX, tag, name, info)#define __MODULE_PARM_TYPE (name, _type) \ __MODULE_INFO(parmtype, name##type, #name ":" _type) --2.49.0
Signature · 2 lines
Best Regards Masahiro Yamada
Signature · 1 line
Rgrds, legion
PATCH v3 3/6 modpost: Make mod_device_table aliases more unique
In reply to Alexey GladkovIn order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)
include/linux/module.h +12 -2
@@ -249,10 +249,20 @@ 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__<counter>__kmod_<modname>__<type>__<name> */ +#define __mod_device_table (type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__COUNTER__, \ + __PASTE(__, \ + __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 \ +#define MODULE_DEVICE_TABLE (type, name) \ +extern typeof(name) __mod_device_table(type, name) \ __attribute__ ((unused, alias(__stringify(name))))#else /* !MODULE */ #define MODULE_DEVICE_TABLE (type, name)
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__<counter>__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
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in MODULE_DEVICE_TABLE()?
Quoted 76 lines
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +12
-2@@ -249,10 +249,20 @@ 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__<counter>__kmod_<modname>__<type>__<name> */ +#define __mod_device_table (type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__COUNTER__, \ + __PASTE(__, \ + __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 \ +#define MODULE_DEVICE_TABLE (type, name) \ +extern typeof(name) __mod_device_table(type, name) \ __attribute__ ((unused, alias(__stringify(name))))#else /* !MODULE */ #define MODULE_DEVICE_TABLE (type, name)scripts/mod/file2alias.c +14
-5@@ -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__<counter>__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) --2.49.0
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 9 lines · Masahiro Yamada
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in
MODULE_DEVICE_TABLE()?
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 83 lines
Quoted 77 lines
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +12
-2@@ -249,10 +249,20 @@ 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__<counter>__kmod_<modname>__<type>__<name> */ +#define __mod_device_table (type, name) \ + __PASTE(__mod_device_table__, \ + __PASTE(__COUNTER__, \ + __PASTE(__, \ + __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 \ +#define MODULE_DEVICE_TABLE (type, name) \ +extern typeof(name) __mod_device_table(type, name) \ __attribute__ ((unused, alias(__stringify(name))))#else /* !MODULE */ #define MODULE_DEVICE_TABLE (type, name)scripts/mod/file2alias.c +14
-5@@ -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__<counter>__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) --2.49.0
Signature · 2 lines
Best Regards Masahiro Yamada
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 12 lines · Alexey Gladkov
Quoted 9 lines · Masahiro Yamada
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in
MODULE_DEVICE_TABLE()?
Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#u
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 20 lines · Masahiro Yamada
Quoted 12 lines · Alexey Gladkov
Quoted 9 lines · Masahiro Yamada
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in
MODULE_DEVICE_TABLE()?Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#u
I tested this patch with the config:
make allmodconfig
make mod2yesconfig
and it works.
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 28 lines · Alexey Gladkov
Quoted 20 lines · Masahiro Yamada
Quoted 12 lines · Alexey Gladkov
Quoted 9 lines · Masahiro Yamada
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in
MODULE_DEVICE_TABLE()?Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#u
Quoted 6 lines
I tested this patch with the config:
make allmodconfig
make mod2yesconfigand it works.
Good.
Then, __COUNTER__ is unnecessary.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 31 lines · Masahiro Yamada
Quoted 30 lines · Alexey Gladkov
Quoted 20 lines · Masahiro Yamada
Quoted 12 lines · Alexey Gladkov
Quoted 9 lines · Masahiro Yamada
Quoted 3 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Why must this be unique?
What problem would happen if the same symbol names appear in
MODULE_DEVICE_TABLE()?Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#uI tested this patch with the config:
Quoted 7 lines
Quoted 4 lines
make allmodconfig
make mod2yesconfigand it works.
Good.
Then,__COUNTER__is unnecessary.
I will send a new version asap. Thanks!
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
In reply to Masahiro YamadaQuoted 15 lines · Masahiro Yamada
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#uI tested this patch with the config:
Quoted 7 lines
Quoted 4 lines
make allmodconfig
make mod2yesconfigand it works.
Good.
Then,__COUNTER__is unnecessary.
I didn't immediately notice. The patch you suggested works, but these symbols remain in System.map and it seems in vmlinuz.
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 20 lines · Alexey Gladkov
Quoted 18 lines · Masahiro Yamada
Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#uI tested this patch with the config:
make allmodconfig
make mod2yesconfig
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
and it works.
Good.
Then,__COUNTER__is unnecessary.I didn't immediately notice. The patch you suggested works, but these symbols remain in System.map and it seems in vmlinuz.
Ah, yes, if your patch set is applied.
Currently, MODULE_DEVICE_TABLE() is no-op in vmlinux.
This makes me realize that your v3 4/6 increased the vmlinux image, as MODULE_DEVICE_TABLE() is kept for modpost.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 31 lines · Masahiro Yamada
Quoted 20 lines · Alexey Gladkov
Quoted 18 lines · Masahiro Yamada
Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
Before these patches this was not a problem as non-unique characters are in separate object files when the module is compiled separately.
But when the modules are compiled into the kernel, there is a symbol conflict when linking vmlinuz. We have modules that export multiple device tables from different object files.
Quoted 5 lines
This is because the __mod_device_table__* symbols are global, but I suspect they do not need to be.
Let's test this
https://lore.kernel.org/lkml/[email protected]/T/#uI tested this patch with the config:
make allmodconfig
make mod2yesconfigQuoted 8 lines
Quoted 4 lines
Quoted 1 line
and it works.
Good.
Then,__COUNTER__is unnecessary.I didn't immediately notice. The patch you suggested works, but these symbols remain in System.map and it seems in vmlinuz.
Quoted 7 lines
Ah, yes, if your patch set is applied.
Currently,
MODULE_DEVICE_TABLE()is no-op in vmlinux.This makes me realize that your v3 4/6 increased the vmlinux image, as
MODULE_DEVICE_TABLE()is kept for modpost.
With your patch set, __mod_device_table_* will be
included in vmlinux.
My patch changes them from global to local ('D' is changed to 'd'), but there is no difference in the fact that v3 4/6 will grow the symbol table in vmlinux.
(1) Your patch set
$ arm-linux-gnueabihf-nm vmlinux | grep __mod_device | head -n 10 c0527678 D __mod_device_table__164__kmod_clk_scmi__scmi__scmi_id_table c053f458 D __mod_device_table__164__kmod_reset_scmi__scmi__scmi_id_table c05421bc D __mod_device_table__164__kmod_reset_uniphier_glue__of__uniphier_glue_reset_match c05334ac D __mod_device_table__164__kmod_scmi_pm_domain__scmi__scmi_id_table c054cbd0 D __mod_device_table__164__kmod_twl4030_power__of__twl4030_power_of_match c0548e8c D __mod_device_table__165__kmod_omap3_rom_rng__of__omap_rom_rng_match c05124a0 D __mod_device_table__165__kmod_simple_pm_bus__of__simple_pm_bus_of_match c05559ac D __mod_device_table__165__kmod_timer_ti_dm__of__omap_timer_match c0528a68 D __mod_device_table__166__kmod_adpll__of__ti_adpll_match c0520a68 D __mod_device_table__166__kmod_gpio_en7523__of__airoha_gpio_of_match
(2) Your patch set + my one (extern -> static)
$ arm-linux-gnueabihf-nm vmlinux | grep __mod_device | head -n 10 c0527678 d __mod_device_table__164__kmod_clk_scmi__scmi__scmi_id_table c053f458 d __mod_device_table__164__kmod_reset_scmi__scmi__scmi_id_table c05421bc d __mod_device_table__164__kmod_reset_uniphier_glue__of__uniphier_glue_reset_match c05334ac d __mod_device_table__164__kmod_scmi_pm_domain__scmi__scmi_id_table c054cbd0 d __mod_device_table__164__kmod_twl4030_power__of__twl4030_power_of_match c0548e8c d __mod_device_table__165__kmod_omap3_rom_rng__of__omap_rom_rng_match c05124a0 d __mod_device_table__165__kmod_simple_pm_bus__of__simple_pm_bus_of_match c05559ac d __mod_device_table__165__kmod_timer_ti_dm__of__omap_timer_match c0528a68 d __mod_device_table__166__kmod_adpll__of__ti_adpll_match c0520a68 d __mod_device_table__166__kmod_gpio_en7523__of__airoha_gpio_of_match
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
In reply to Alexey GladkovQuoted 16 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +0
-0
include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 252
Quoted 4 lines
include/linux/module.h +1
-0@@ -249,10 +249,20 @@ 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__<counter>__kmod_<modname>__<type>__<name> */
This format relies on module-name mangling, but
I hope we will be able to stop doing it some day.
Can we come up with a different idea
in case <modname> contains hyphens?
--
Best Regards
Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 20 lines · Masahiro Yamada
Quoted 19 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +0
-0@@ -249,10 +249,20 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* What your module does. */ #define MODULE_DESCRIPTION (_description) MODULE_INFO(description, _description)
Quoted 4 lines
include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 252
Quoted 1 line
include/linux/module.h +1
-0+/* Format: __mod_device_table__<counter>__kmod_<modname>__<type>__<name> */ This format relies on module-name mangling, but
I hope we will be able to stop doing it some day.
I didn't like this approach either when I found out how it was implemented.
We can only add the module name to the structure to which the alias is made. But the problem with this is that right now there is no common structure for DEVICE_TABLE. Each module comes up with its own.
It is possible to add a common structure, but that would be a big refactoring.
Quoted 2 lines
Can we come up with a different idea
in case <modname> contains hyphens?
The hyphen is not a problem for my implementation. In the __KBUILD_MODNAME macro, hyphens are replaced by underscores.
scripts/Makefile.lib:
name-fix-token = $(subst $(comma),_,$(subst -,_,$1)) name-fix = $(call stringify,$(call name-fix-token,$1)) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \ -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 22 lines · Alexey Gladkov
Quoted 20 lines · Masahiro Yamada
Quoted 19 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +0
-0@@ -249,10 +249,20 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* What your module does. */ #define MODULE_DESCRIPTION (_description) MODULE_INFO(description, _description)
Quoted 7 lines
Quoted 4 lines
include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 252
Quoted 1 line
include/linux/module.h +1
-0+/* Format: __mod_device_table__<counter>__kmod_<modname>__<type>__<name> */ This format relies on module-name mangling, but
I hope we will be able to stop doing it some day.I didn't like this approach either when I found out how it was implemented.
Yeah, I dislike it.
I hope we can stop this historical mistake:
https://lore.kernel.org/lkml/[email protected]/
Once we stop doing that, __KBUILD_MODNAME will not match to KBUILD_MODNAME.
Also, you need to be careful about the rust side, as you did not take care of it.
https://github.com/torvalds/linux/blob/v6.15/rust/kernel/device_id.rs#L157
Quoted 7 lines
We can only add the module name to the structure to which the alias is made. But the problem with this is that right now there is no common structure for
DEVICE_TABLE. Each module comes up with its own.It is possible to add a common structure, but that would be a big refactoring.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 31 lines · Masahiro Yamada
Quoted 22 lines · Alexey Gladkov
Quoted 20 lines · Masahiro Yamada
Quoted 19 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +0
-0@@ -249,10 +249,20 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* What your module does. */ #define MODULE_DESCRIPTION (_description) MODULE_INFO(description, _description)Quoted 7 lines
Quoted 4 lines
include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 252
Quoted 1 line
include/linux/module.h +1
-0+/* Format: __mod_device_table__<counter>__kmod_<modname>__<type>__<name> */ This format relies on module-name mangling, but
I hope we will be able to stop doing it some day.I didn't like this approach either when I found out how it was implemented.
Quoted 6 lines
Yeah, I dislike it.
I hope we can stop this historical mistake:
https://lore.kernel.org/lkml/[email protected]/Once we stop doing that,
__KBUILD_MODNAMEwill not match toKBUILD_MODNAME.
Do I understand you correctly that I cannot use __KBUILD_MODNAME now ?
Quoted 4 lines
Also, you need to be careful about the rust side, as you did not take care of it.
https://github.com/torvalds/linux/blob/v6.15/rust/kernel/device_id.rs#L157
Oh. This will make it much more complicated because I don't know rust well. :(
I found a few more issues with modules when they compile as part of the kernel, but was hoping to fix them after these patches.
Signature · 1 line
Rgrds, legion
Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique
Quoted 33 lines · Alexey Gladkov
Quoted 31 lines · Masahiro Yamada
Quoted 29 lines · Alexey Gladkov
Quoted 20 lines · Masahiro Yamada
Quoted 19 lines · Alexey Gladkov
In order to avoid symbol conflicts if they appear in the same binary, a more unique alias identifier can be generated.
Signed-off-by Alexey Gladkov <[email protected]>Reviewed-by Petr Pavlu <[email protected]>--- include/linux/module.h | 14 ++++++++++++-- scripts/mod/file2alias.c | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-)include/linux/module.h +0
-0@@ -249,10 +249,20 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);/* What your module does. */ #define MODULE_DESCRIPTION (_description) MODULE_INFO(description, _description)Quoted 4 lines
include/linux/module.h struct module_kobject *lookup_or_create_module_kobject(const char *name); · line 252
Quoted 1 line
include/linux/module.h +1
-0+/* Format: __mod_device_table__<counter>__kmod_<modname>__<type>__<name> */ This format relies on module-name mangling, but
I hope we will be able to stop doing it some day.I didn't like this approach either when I found out how it was implemented.
Quoted 8 lines
Quoted 6 lines
Yeah, I dislike it.
I hope we can stop this historical mistake:
https://lore.kernel.org/lkml/[email protected]/Once we stop doing that,
__KBUILD_MODNAMEwill not match toKBUILD_MODNAME.Do I understand you correctly that I cannot use
__KBUILD_MODNAMEnow ?
Honestly, I dislike __KBUILD_MODNAME, but I know it is more challenging.
So, at least you need to fix the rust issue.
Quoted 14 lines
Quoted 4 lines
Also, you need to be careful about the rust side, as you did not take care of it.
https://github.com/torvalds/linux/blob/v6.15/rust/kernel/device_id.rs#L157
Oh. This will make it much more complicated because I don't know rust well. :(
I found a few more issues with modules when they compile as part of the kernel, but was hoping to fix them after these patches.
--
Rgrds, legion
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH v3 4/6 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/mod/file2alias.c | 16 ++++++++++++++++ scripts/mod/modpost.c | 13 ++++++++++++- scripts/mod/modpost.h | 2 ++ 4 files changed, 30 insertions(+), 5 deletions(-)
include/linux/module.h +0 -4
@@ -259,14 +259,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) \ extern typeof(name) __mod_device_table(type, name) \ __attribute__ ((unused, 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/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 +12 -1
@@ -2021,11 +2021,22 @@ 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); + +list_for_each_entry_safe (alias, next, &mod->aliases, node) { +buf_printf (&buf,"MODULE_ALIAS_MODNAME(\"%s\", \"%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
PATCH v3 5/6 kbuild: Move modules.builtin.modinfo to another makefile
In reply to Alexey GladkovThe creation of modules.builtin.modinfo is going to depend on .vmlinux.export.o so it is worth moving its creation closer to it.
--- scripts/Makefile.vmlinux | 24 ++++++++++++++++++++++++ scripts/Makefile.vmlinux_o | 26 +------------------------- 2 files changed, 25 insertions(+), 25 deletions(-)
scripts/Makefile.vmlinux +24 -0
@@ -97,6 +97,30 @@ ifdef CONFIG_BUILDTIME_TABLE_SORT $(vmlinux-final): scripts/sorttable endif +# 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) + # 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.49.0
kernel test robot
build botRe: [PATCH v3 5/6] kbuild: Move modules.builtin.modinfo to another makefile
kernel test robot noticed the following build errors:
Hi Alexey,
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-20250528] [cannot apply to mkp-scsi/for-next jejb-scsi/for-next 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/Alexey-Gladkov/scsi-Define-MODULE_DEVICE_TABLE-only-if-necessary/20250528-020814 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/1910073cfee59df4a3edb7f724214eeb4b8a3faa.1748335606.git.legion%40kernel.org patch subject: [PATCH v3 5/6] kbuild: Move modules.builtin.modinfo to another makefile
:::::: branch date: 19 hours ago
:::::: commit date: 19 hours ago
config: x86_64-randconfig-003-20250528 (https://download.01.org/0day-ci/archive/20250528/[email protected]/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250528/[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[3]: *** No rule to make target 'modules.builtin.modinfo', needed by '/tmp/kernel/x86_64-randconfig-003-20250528/clang-20/0f04dfcaa62efc3a521b20ba0b39b2a78c4389db/lib/modules/6.15.0-rc7-00019-g0f04dfcaa62e/modules.builtin.modinfo'. >> make[3]: *** No rule to make target 'modules.builtin', needed by '/tmp/kernel/x86_64-randconfig-003-20250528/clang-20/0f04dfcaa62efc3a521b20ba0b39b2a78c4389db/lib/modules/6.15.0-rc7-00019-g0f04dfcaa62e/modules.builtin'.
make[3]: Target '__modinst' not remade because of errors. make[2]: *** [Makefile:1909: modules_install] Error 2 shuffle=3457807955 make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=3457807955 make[1]: Target 'modules_install' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2 shuffle=3457807955
make: Target 'modules_install' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v3 5/6] kbuild: Move modules.builtin.modinfo to another makefile
Quoted 28 lines · kernel test robot
Hi Alexey,
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-20250528] [cannot apply to mkp-scsi/for-next jejb-scsi/for-next 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/Alexey-Gladkov/scsi-Define-MODULE_DEVICE_TABLE-only-if-necessary/20250528-020814 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/1910073cfee59df4a3edb7f724214eeb4b8a3faa.1748335606.git.legion%40kernel.org patch subject: [PATCH v3 5/6] kbuild: Move modules.builtin.modinfo to another makefile:::::: branch date: 19 hours ago
:::::: commit date: 19 hours ago
config: x86_64-randconfig-003-20250528 (https://download.01.org/0day-ci/archive/20250528/[email protected]/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project58df0ef89dd64126512e4ee27b4ac3fd8ddf6247) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250528/[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 >>):
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
make[3]: *** No rule to make target 'modules.builtin.modinfo', needed by '
/tmp/kernel/x86_64-randconfig-003-20250528/clang-20/0f04dfcaa62efc3a521b20ba0b39b2a78c4389db/lib/modules/6.15.0-rc7-00019-g0f04dfcaa62e/modules.builtin.modinfo'. make[3]: *** No rule to make target 'modules.builtin', needed by '/tmp/kernel/x86_64-randconfig-003-20250528/clang-20/0f04dfcaa62efc3a521b20ba0b39b2a78c4389db/lib/modules/6.15.0-rc7-00019-g0f04dfcaa62e/modules.builtin'.make[3]: Target '
__modinst' not remade because of errors. make[2]: *** [Makefile:1909:modules_install] Error 2 shuffle=3457807955 make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=3457807955 make[1]: Target 'modules_install' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2 shuffle=3457807955
make: Target 'modules_install' not remade because of errors.
Original patch series was for v6.15:
base-commit: 0ff41df1cb268fc69e703a08a57ee14ae967d0ca
But I separately tried testing the patchset with the brunch [1] and the attached config and could not reproduce the problem.
Signature · 1 line
Rgrds, legion
PATCH v3 6/6 kbuild: Create modules.builtin.modinfo for modpost results
In reply to Alexey GladkovCreate modules.builtin.modinfo as a combination of modinfo from vmlinux and the result of generating modalias by modpost.
--- scripts/Makefile.vmlinux | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
scripts/Makefile.vmlinux +27 -3
@@ -70,6 +70,18 @@ endif ifdef CONFIG_MODULES targets += .vmlinux.export.o $(vmlinux-final): .vmlinux.export.o + +# .module.builtin.modinfo.modpost +# --------------------------------------------------------------------------- +__default: .modules.builtin.modinfo.modpost + +OBJCOPYFLAGS_.modules.builtin.modinfo.modpost := -j .modinfo -O binary + +targets += .modules.builtin.modinfo.modpost +.modules.builtin.modinfo.modpost: .vmlinux.export.o FORCE + $(call if_changed,objcopy) + +modules.builtin.modinfo: .modules.builtin.modinfo.modpost endif ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
@@ -97,14 +109,26 @@ ifdef CONFIG_BUILDTIME_TABLE_SORT $(vmlinux-final): scripts/sorttable endif +# .module.builtin.modinfo.vmlinux +# --------------------------------------------------------------------------- +__default: .modules.builtin.modinfo.vmlinux + +OBJCOPYFLAGS_.modules.builtin.modinfo.vmlinux := -j .modinfo -O binary + +targets += .modules.builtin.modinfo.vmlinux +.modules.builtin.modinfo.vmlinux: vmlinux.o FORCE + $(call if_changed,objcopy) + # modules.builtin.modinfo # --------------------------------------------------------------------------- -OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary +quiet_cmd_modules_builtin_modinfo = GEN $@ + cmd_modules_builtin_modinfo = \ + cat $< $(wildcard .modules.builtin.modinfo.modpost) > $@ targets += modules.builtin.modinfo -modules.builtin.modinfo: vmlinux.o FORCE - $(call if_changed,objcopy) +modules.builtin.modinfo: .modules.builtin.modinfo.vmlinux FORCE + $(call if_changed,modules_builtin_modinfo) # modules.builtin # ---------------------------------------------------------------------------
Signature · 1 line
2.49.0
[PATCH v3 7/6] scsi: Always define MODULE_DEVICE_TABLE
In reply to Alexey GladkovSince MODULE_DEVICE_TABLE no longer depends on whether the module is built separately or compiled into the kernel, it now makes sense to always define DEVICE_TABLE. In this case, even if the module is in the kernel, correct module.builtin.modaliases will be generated.
--- 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},
@@ -3732,7 +3731,6 @@ static const struct pci_device_id blogic_pci_tbl[] = { {0, }, };MODULE_DEVICE_TABLE (pci, blogic_pci_tbl); -#endif module_init (blogic_init);module_exit (blogic_exit);
Signature · 1 line
2.49.0
James Bottomley
maintainerRe: [PATCH v3 7/6] scsi: Always define MODULE_DEVICE_TABLE
Quoted 26 lines · Alexey Gladkov
Since
MODULE_DEVICE_TABLEno longer depends on whether the module is built separately or compiled into the kernel, it now makes sense to always defineDEVICE_TABLE. In this case, even if the module is in the
kernel, correct module.builtin.modaliases will be generated.Suggested-by James Bottomley <[email protected]>Signed-off-by Alexey Gladkov <[email protected]>---
drivers/scsi/BusLogic.c | 2 --1 file changed, 2 deletions(-)drivers/scsi/BusLogic.c +0
-0@@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void)
__setup("BusLogic=",blogic_setup);
-#ifdef MODULE
/*static const structpci_device_idblogic_pci_tbl[] = { {PCI_VENDOR_ID_BUSLOGIC,PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
PCI_ANY_ID,PCI_ANY_ID, 0, 0, 0},
drivers/scsi/BusLogic.c static const struct pci_device_id · line 3736
Quoted 5 lines
drivers/scsi/BusLogic.c +0
-1@@ -3732,7 +3731,6 @@ static const struct pci_device_id blogic_pci_tbl[] = { {0, }, }; MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); -#endif
You don't need to do this in two steps. The original problem of defined but not used table stopped being a problem when the structure was converted to static const over ten years ago (the compiler doesn't warn about unused static consts).
Regards,
James
Re: [PATCH v3 7/6] scsi: Always define MODULE_DEVICE_TABLE
Quoted 29 lines · James Bottomley
Quoted 28 lines · Alexey Gladkov
Since
MODULE_DEVICE_TABLEno longer depends on whether the module is built separately or compiled into the kernel, it now makes sense to always defineDEVICE_TABLE. In this case, even if the module is in the
kernel, correct module.builtin.modaliases will be generated.Suggested-by James Bottomley <[email protected]>Signed-off-by Alexey Gladkov <[email protected]>---
drivers/scsi/BusLogic.c | 2 --1 file changed, 2 deletions(-)drivers/scsi/BusLogic.c +0
-0@@ -3715,7 +3715,6 @@ static void __exit blogic_exit(void)
__setup("BusLogic=",blogic_setup);
-#ifdef MODULE
/*static const structpci_device_idblogic_pci_tbl[] = { {PCI_VENDOR_ID_BUSLOGIC,PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
PCI_ANY_ID,PCI_ANY_ID, 0, 0, 0},drivers/scsi/BusLogic.c +0
-0@@ -3732,7 +3731,6 @@ static const struct pci_device_id blogic_pci_tbl[] = { {0, },
Quoted 8 lines
drivers/scsi/BusLogic.c static const struct pci_device_id blogic_pci_tbl[] = { · line 3735
Quoted 3 lines
drivers/scsi/BusLogic.c +0
-1}; MODULE_DEVICE_TABLE(pci, blogic_pci_tbl); -#endif You don't need to do this in two steps. The original problem of defined but not used table stopped being a problem when the structure was converted to static const over ten years ago (the compiler doesn't warn about unused static consts).
Ah. Ok, I will recreate this patch shortly.
Basically my original plan was to fix compilation errors as a first step, and second step make MODULE_DEVICE_TABLE be used independently of MODULE. Because there are a bunch of modules that also use MODULE_DEVICE_TABLE only if MODULE is defined.
Signature · 1 line
Rgrds, legion