Skip to content

Commit

Permalink
modpost: improve the section mismatch warning format
Browse files Browse the repository at this point in the history
This commit improves the section mismatch warning format when there is
no suitable symbol name to print.

The section mismatch warning prints the reference source in the form
of <symbol_name>+<offset> and the reference destination in the form
of <symbol_name>.

However, there are some corner cases where <symbol_name> becomes
"(unknown)", as reported in commit 23dfd91 ("modpost: fix null
pointer dereference").

In such cases, it is better to print the symbol address.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
masahir0y committed Sep 1, 2024
1 parent a46078d commit 7a7f974
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,7 @@ static char *get_modinfo(struct elf_info *info, const char *tag)

static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
{
if (sym)
return elf->strtab + sym->st_name;
else
return "(unknown)";
return sym ? elf->strtab + sym->st_name : "";
}

/*
Expand Down Expand Up @@ -1013,6 +1010,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
Elf_Sym *from;
const char *tosym;
const char *fromsym;
char taddr_str[16];

from = find_fromsym(elf, faddr, fsecndx);
fromsym = sym_name(elf, from);
Expand All @@ -1026,10 +1024,17 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,

sec_mismatch_count++;

warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
modname, fromsym,
(unsigned int)(faddr - (from ? from->st_value : 0)),
fromsec, tosym, tosec);
if (!tosym[0])
snprintf(taddr_str, sizeof(taddr_str), "0x%x", (unsigned int)taddr);

/*
* The format for the reference source: <symbol_name>+<offset> or <address>
* The format for the reference destination: <symbol_name> or <address>
*/
warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n",
modname, fromsym, fromsym[0] ? "+" : "",
(unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)),
fromsec, tosym[0] ? tosym : taddr_str, tosec);

if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
if (match(tosec, mismatch->bad_tosec))
Expand Down

0 comments on commit 7a7f974

Please sign in to comment.