Skip to content

Commit 83fb493

Browse files
legionusnathanchance
authored andcommitted
modpost: Add modname to mod_device_table alias
At this point, if a symbol is compiled as part of the kernel, information about which module the symbol belongs to is lost. To save this it is possible to add the module name to the alias name. It's not very pretty, but it's possible for now. Cc: Miguel Ojeda <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: [email protected] Signed-off-by: Alexey Gladkov <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Acked-by: Nicolas Schier <[email protected]> Link: https://patch.msgid.link/1a0d0bd87a4981d465b9ed21e14f4e78eaa03ded.1758182101.git.legion@kernel.org Signed-off-by: Nathan Chancellor <[email protected]>
1 parent b88f88c commit 83fb493

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

include/linux/module.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,22 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
244244
/* What your module does. */
245245
#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
246246

247+
/*
248+
* Format: __mod_device_table__kmod_<modname>__<type>__<name>
249+
* Parts of the string `__kmod_` and `__` are used as delimiters when parsing
250+
* a symbol in file2alias.c
251+
*/
252+
#define __mod_device_table(type, name) \
253+
__PASTE(__mod_device_table__, \
254+
__PASTE(__KBUILD_MODNAME, \
255+
__PASTE(__, \
256+
__PASTE(type, \
257+
__PASTE(__, name)))))
258+
247259
#ifdef MODULE
248260
/* Creates an alias so file2alias.c can find device table. */
249261
#define MODULE_DEVICE_TABLE(type, name) \
250-
static typeof(name) __mod_device_table__##type##__##name \
262+
static typeof(name) __mod_device_table(type, name) \
251263
__attribute__ ((used, alias(__stringify(name))))
252264
#else /* !MODULE */
253265
#define MODULE_DEVICE_TABLE(type, name)

rust/kernel/device_id.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ macro_rules! module_device_table {
195195
($table_type: literal, $module_table_name:ident, $table_name:ident) => {
196196
#[rustfmt::skip]
197197
#[export_name =
198-
concat!("__mod_device_table__", $table_type,
199-
"__", module_path!(),
200-
"_", line!(),
201-
"_", stringify!($table_name))
198+
concat!("__mod_device_table__", line!(),
199+
"__kmod_", module_path!(),
200+
"__", $table_type,
201+
"__", stringify!($table_name))
202202
]
203203
static $module_table_name: [::core::mem::MaybeUninit<u8>; $table_name.raw_ids().size()] =
204204
unsafe { ::core::mem::transmute_copy($table_name.raw_ids()) };

scripts/mod/file2alias.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
14761476
{
14771477
void *symval;
14781478
char *zeros = NULL;
1479-
const char *type, *name;
1479+
const char *type, *name, *modname;
14801480
size_t typelen;
14811481
static const char *prefix = "__mod_device_table__";
14821482

@@ -1488,10 +1488,19 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
14881488
if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
14891489
return;
14901490

1491-
/* All our symbols are of form __mod_device_table__<type>__<name>. */
1491+
/* All our symbols are of form __mod_device_table__kmod_<modname>__<type>__<name>. */
14921492
if (!strstarts(symname, prefix))
14931493
return;
1494-
type = symname + strlen(prefix);
1494+
1495+
modname = strstr(symname, "__kmod_");
1496+
if (!modname)
1497+
return;
1498+
modname += strlen("__kmod_");
1499+
1500+
type = strstr(modname, "__");
1501+
if (!type)
1502+
return;
1503+
type += strlen("__");
14951504

14961505
name = strstr(type, "__");
14971506
if (!name)

0 commit comments

Comments
 (0)