[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ffea56aecdd48eb37b7420f91abfd2dfff75c3b7.1745591072.git.legion@kernel.org>
Date: Sat, 26 Apr 2025 18:16:35 +0200
From: Alexey Gladkov <legion@...nel.org>
To: Luis Chamberlain <mcgrof@...nel.org>,
Petr Pavlu <petr.pavlu@...e.com>,
Sami Tolvanen <samitolvanen@...gle.com>,
Daniel Gomez <da.gomez@...sung.com>,
Masahiro Yamada <masahiroy@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nicolas Schier <nicolas.schier@...ux.dev>
Cc: linux-kernel@...r.kernel.org,
linux-modules@...r.kernel.org,
linux-kbuild@...r.kernel.org,
Alexey Gladkov <legion@...nel.org>
Subject: [PATCH v1 4/7] modpost: Make mod_device_table aliases more unique
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 <legion@...nel.org>
---
include/linux/module.h | 14 ++++++++++++--
scripts/mod/file2alias.c | 18 ++++++++++++++----
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/include/linux/module.h b/include/linux/module.h
index e987fd62c734..7250b4a527ec 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -247,10 +247,20 @@ extern void cleanup_module(void);
/* 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)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 00586119a25b..dff1799a4c79 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -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
Powered by blists - more mailing lists