Skip to content

Commit 1c4a758

Browse files
committed
modpost: fix section mismatch message for RELA
The section mismatch check prints a bogus symbol name on some architectures. [test code] #include <linux/init.h> int __initdata foo; int get_foo(void) { return foo; } If you compile it with GCC for riscv or loongarch, modpost will show an incorrect symbol name: WARNING: modpost: vmlinux: section mismatch in reference: get_foo+0x8 (section: .text) -> done (section: .init.data) To get the correct symbol address, the st_value must be added. This issue has never been noticed since commit 93684d3 ("kbuild: include symbol names in section mismatch warnings") presumably because st_value becomes zero on most architectures when the referenced symbol is looked up. It is not true for riscv or loongarch, at least. With this fix, modpost will show the correct symbol name: WARNING: modpost: vmlinux: section mismatch in reference: get_foo+0x8 (section: .text) -> foo (section: .init.data) Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent b85ea95 commit 1c4a758

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scripts/mod/modpost.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,13 +1383,15 @@ static void section_rela(struct module *mod, struct elf_info *elf,
13831383
const Elf_Rela *rela;
13841384

13851385
for (rela = start; rela < stop; rela++) {
1386+
Elf_Sym *tsym;
13861387
Elf_Addr taddr, r_offset;
13871388
unsigned int r_type, r_sym;
13881389

13891390
r_offset = TO_NATIVE(rela->r_offset);
13901391
get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym);
13911392

1392-
taddr = TO_NATIVE(rela->r_addend);
1393+
tsym = elf->symtab_start + r_sym;
1394+
taddr = tsym->st_value + TO_NATIVE(rela->r_addend);
13931395

13941396
switch (elf->hdr->e_machine) {
13951397
case EM_RISCV:
@@ -1404,7 +1406,7 @@ static void section_rela(struct module *mod, struct elf_info *elf,
14041406
break;
14051407
}
14061408

1407-
check_section_mismatch(mod, elf, elf->symtab_start + r_sym,
1409+
check_section_mismatch(mod, elf, tsym,
14081410
fsecndx, fromsec, r_offset, taddr);
14091411
}
14101412
}

0 commit comments

Comments
 (0)