Commit 856567d5 authored by Masahiro Yamada's avatar Masahiro Yamada

modpost: squash extable_mismatch_handler() into default_mismatch_handler()

Merging these two reduces several lines of code. The extable section
mismatch is already distinguished by EXTABLE_TO_NON_TEXT.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent f4c35484
...@@ -881,27 +881,14 @@ enum mismatch { ...@@ -881,27 +881,14 @@ enum mismatch {
* targeting sections in this array (white-list). Can be empty. * targeting sections in this array (white-list). Can be empty.
* *
* @mismatch: Type of mismatch. * @mismatch: Type of mismatch.
*
* @handler: Specific handler to call when a match is found. If NULL,
* default_mismatch_handler() will be called.
*
*/ */
struct sectioncheck { struct sectioncheck {
const char *fromsec[20]; const char *fromsec[20];
const char *bad_tosec[20]; const char *bad_tosec[20];
const char *good_tosec[20]; const char *good_tosec[20];
enum mismatch mismatch; enum mismatch mismatch;
void (*handler)(const char *modname, struct elf_info *elf,
const struct sectioncheck* const mismatch,
Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
}; };
static void extable_mismatch_handler(const char *modname, struct elf_info *elf,
const struct sectioncheck* const mismatch,
Elf_Rela *r, Elf_Sym *sym,
const char *fromsec);
static const struct sectioncheck sectioncheck[] = { static const struct sectioncheck sectioncheck[] = {
/* Do not reference init/exit code/data from /* Do not reference init/exit code/data from
* normal code and data * normal code and data
...@@ -974,7 +961,6 @@ static const struct sectioncheck sectioncheck[] = { ...@@ -974,7 +961,6 @@ static const struct sectioncheck sectioncheck[] = {
.bad_tosec = { ".altinstr_replacement", NULL }, .bad_tosec = { ".altinstr_replacement", NULL },
.good_tosec = {ALL_TEXT_SECTIONS , NULL}, .good_tosec = {ALL_TEXT_SECTIONS , NULL},
.mismatch = EXTABLE_TO_NON_TEXT, .mismatch = EXTABLE_TO_NON_TEXT,
.handler = extable_mismatch_handler,
} }
}; };
...@@ -1255,24 +1241,8 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, ...@@ -1255,24 +1241,8 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
modname, tosym, tosec); modname, tosym, tosec);
break; break;
case EXTABLE_TO_NON_TEXT: case EXTABLE_TO_NON_TEXT:
fatal("There's a special handler for this mismatch type, we should never get here.\n");
break;
}
}
static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
const struct sectioncheck* const mismatch,
Elf_Rela* r, Elf_Sym* sym,
const char *fromsec)
{
const char* tosec = sec_name(elf, get_secindex(elf, sym));
Elf_Sym *tosym = find_elf_symbol(elf, r->r_addend, sym);
const char *tosym_name = sym_name(elf, tosym);
sec_mismatch_count++;
warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n", warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n",
modname, fromsec, (long)r->r_offset, tosec, tosym_name); modname, fromsec, (long)r->r_offset, tosec, tosym);
if (match(tosec, mismatch->bad_tosec)) if (match(tosec, mismatch->bad_tosec))
fatal("The relocation at %s+0x%lx references\n" fatal("The relocation at %s+0x%lx references\n"
...@@ -1293,6 +1263,8 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf, ...@@ -1293,6 +1263,8 @@ static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
else else
error("%s+0x%lx references non-executable section '%s'\n", error("%s+0x%lx references non-executable section '%s'\n",
fromsec, (long)r->r_offset, tosec); fromsec, (long)r->r_offset, tosec);
break;
}
} }
static void check_section_mismatch(const char *modname, struct elf_info *elf, static void check_section_mismatch(const char *modname, struct elf_info *elf,
...@@ -1301,14 +1273,10 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf, ...@@ -1301,14 +1273,10 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
const char *tosec = sec_name(elf, get_secindex(elf, sym)); const char *tosec = sec_name(elf, get_secindex(elf, sym));
const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
if (mismatch) { if (!mismatch)
if (mismatch->handler) return;
mismatch->handler(modname, elf, mismatch,
r, sym, fromsec); default_mismatch_handler(modname, elf, mismatch, r, sym, fromsec);
else
default_mismatch_handler(modname, elf, mismatch,
r, sym, fromsec);
}
} }
static unsigned int *reloc_location(struct elf_info *elf, static unsigned int *reloc_location(struct elf_info *elf,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment