Skip to content

Commit b31db65

Browse files
committed
modpost: factor out inst location calculation to section_rel()
All the addend_*_rel() functions calculate the instruction location in the same way. Factor out the similar code to the caller. Squash reloc_location() too. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 25a21fb commit b31db65

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

scripts/mod/modpost.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,16 +1256,9 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf,
12561256
tosec, taddr);
12571257
}
12581258

1259-
static unsigned int *reloc_location(struct elf_info *elf,
1260-
Elf_Shdr *sechdr, Elf_Rela *r)
1261-
{
1262-
return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset);
1263-
}
1264-
1265-
static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1259+
static int addend_386_rel(uint32_t *location, Elf_Rela *r)
12661260
{
12671261
unsigned int r_typ = ELF_R_TYPE(r->r_info);
1268-
unsigned int *location = reloc_location(elf, sechdr, r);
12691262

12701263
switch (r_typ) {
12711264
case R_386_32:
@@ -1302,11 +1295,10 @@ static int32_t sign_extend32(int32_t value, int index)
13021295
return (int32_t)(value << shift) >> shift;
13031296
}
13041297

1305-
static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1298+
static int addend_arm_rel(void *loc, struct elf_info *elf, Elf_Rela *r)
13061299
{
13071300
unsigned int r_typ = ELF_R_TYPE(r->r_info);
13081301
Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info);
1309-
void *loc = reloc_location(elf, sechdr, r);
13101302
uint32_t inst, upper, lower, sign, j1, j2;
13111303
int32_t offset;
13121304

@@ -1396,11 +1388,10 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
13961388
return 0;
13971389
}
13981390

1399-
static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1391+
static int addend_mips_rel(uint32_t *location, Elf_Rela *r)
14001392
{
14011393
unsigned int r_typ = ELF_R_TYPE(r->r_info);
1402-
unsigned int *location = reloc_location(elf, sechdr, r);
1403-
unsigned int inst;
1394+
uint32_t inst;
14041395

14051396
if (r_typ == R_MIPS_HI16)
14061397
return 1; /* skip this */
@@ -1502,6 +1493,8 @@ static void section_rel(struct module *mod, struct elf_info *elf,
15021493
return;
15031494

15041495
for (rel = start; rel < stop; rel++) {
1496+
void *loc;
1497+
15051498
r.r_offset = TO_NATIVE(rel->r_offset);
15061499
#if KERNEL_ELFCLASS == ELFCLASS64
15071500
if (elf->hdr->e_machine == EM_MIPS) {
@@ -1519,17 +1512,20 @@ static void section_rel(struct module *mod, struct elf_info *elf,
15191512
r_sym = ELF_R_SYM(r.r_info);
15201513
#endif
15211514
r.r_addend = 0;
1515+
1516+
loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset);
1517+
15221518
switch (elf->hdr->e_machine) {
15231519
case EM_386:
1524-
if (addend_386_rel(elf, sechdr, &r))
1520+
if (addend_386_rel(loc, &r))
15251521
continue;
15261522
break;
15271523
case EM_ARM:
1528-
if (addend_arm_rel(elf, sechdr, &r))
1524+
if (addend_arm_rel(loc, elf, &r))
15291525
continue;
15301526
break;
15311527
case EM_MIPS:
1532-
if (addend_mips_rel(elf, sechdr, &r))
1528+
if (addend_mips_rel(loc, &r))
15331529
continue;
15341530
break;
15351531
default:

0 commit comments

Comments
 (0)