Skip to content

Commit 12ca2c6

Browse files
committed
modpost: detect section mismatch for R_ARM_{MOVW_ABS_NC,MOVT_ABS}
For ARM defconfig (i.e. multi_v7_defconfig), modpost fails to detect some types of section mismatches. [test code] #include <linux/init.h> int __initdata foo; int get_foo(void) { return foo; } It is apparently a bad reference, but modpost does not report anything. The test code above produces the following relocations. Relocation section '.rel.text' at offset 0x200 contains 2 entries: Offset Info Type Sym.Value Sym. Name 00000000 0000062b R_ARM_MOVW_ABS_NC 00000000 .LANCHOR0 00000004 0000062c R_ARM_MOVT_ABS 00000000 .LANCHOR0 Currently, R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS are just skipped. Add code to handle them. I checked arch/arm/kernel/module.c to learn how the offset is encoded in the instruction. The referenced symbol in relocation might be a local anchor. If is_valid_name() returns false, let's search for a better symbol name. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 56a24b8 commit 12ca2c6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/mod/modpost.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
10781078
/**
10791079
* Find symbol based on relocation record info.
10801080
* In some cases the symbol supplied is a valid symbol so
1081-
* return refsym. If st_name != 0 we assume this is a valid symbol.
1081+
* return refsym. If is_valid_name() == true, we assume this is a valid symbol.
10821082
* In other cases the symbol needs to be looked up in the symbol table
10831083
* based on section and address.
10841084
* **/
@@ -1091,7 +1091,7 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf64_Sword addr,
10911091
Elf64_Sword d;
10921092
unsigned int relsym_secindex;
10931093

1094-
if (relsym->st_name != 0)
1094+
if (is_valid_name(elf, relsym))
10951095
return relsym;
10961096

10971097
/*
@@ -1297,6 +1297,13 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
12971297
inst = TO_NATIVE(*(uint32_t *)loc);
12981298
r->r_addend = inst + sym->st_value;
12991299
break;
1300+
case R_ARM_MOVW_ABS_NC:
1301+
case R_ARM_MOVT_ABS:
1302+
inst = TO_NATIVE(*(uint32_t *)loc);
1303+
offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff),
1304+
15);
1305+
r->r_addend = offset + sym->st_value;
1306+
break;
13001307
case R_ARM_PC24:
13011308
case R_ARM_CALL:
13021309
case R_ARM_JUMP24:

0 commit comments

Comments
 (0)