objtool/klp: Fix module name normalization for paths with dots

When .modinfo has no "name=" tag, __find_modname() falls back to
converting the object's build-tree path to a runtime module name by
stripping directory components, converting '-' to '_' and truncating the
file extension.

It does all that in a single pass over the entire path, so the first dot
anywhere in the path ends the name.  For an object built in a directory
whose name contains a dot, e.g. "drivers/foo-1.0/bar.o", the result is a
bogus module name.

Strip the directory components up front so only the basename is scanned
for the extension separator.

Fixes: dd590d4d57 ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Sashiko <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Cc: [email protected]
Link: https://patch.msgid.link/9017b4609553bed16674e8f924d34691cbc2b2c1.1785727106.git.jpoimboe@kernel.org
This commit is contained in:
Josh Poimboeuf
2026-08-03 07:12:38 +02:00
committed by Ingo Molnar
parent 075b74841b
commit 165affd6f0
+6 -4
View File
@@ -1140,7 +1140,7 @@ static struct export *find_export(struct symbol *sym)
static const char *__find_modname(struct elfs *e)
{
struct section *sec;
char *name;
char *name, *slash;
sec = find_section_by_name(e->orig, ".modinfo");
if (!sec) {
@@ -1158,10 +1158,12 @@ static const char *__find_modname(struct elfs *e)
return NULL;
}
slash = strrchr(name, '/');
if (slash)
name = slash + 1;
for (char *c = name; *c; c++) {
if (*c == '/')
name = c + 1;
else if (*c == '-')
if (*c == '-')
*c = '_';
else if (*c == '.') {
*c = '\0';