History

modpost: pass r_type to addend_*_rel()

All of addend_*_rel() need the Elf_Rela pointer just for calculating ELF_R_TYPE(r->r_info). You can do it on the caller to de-duplicate the code.

Masahiro Yamada committed 3 years ago

Commit 71d965c1 parent a68914a1 file · +11 −13Browse files

Unified · Split

scripts/mod/modpost.c+11−13
@@ -1257,11 +1257,9 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, · 1256 unmodified lines
1257 tosec, taddr);1257 tosec, taddr);
1258}1258}
1259 1259
1260static Elf_Addr addend_386_rel(uint32_t *location, Elf_Rela *r)1260static Elf_Addr addend_386_rel(uint32_t *location, unsigned int r_type)
1261{1261{
1262 unsigned int r_typ = ELF_R_TYPE(r->r_info);1262 switch (r_type) {
1263
1264 switch (r_typ) {
1265 case R_386_32:1263 case R_386_32:
1266 return TO_NATIVE(*location);1264 return TO_NATIVE(*location);
1267 case R_386_PC32:1265 case R_386_PC32:
@@ -1312,13 +1310,12 @@ static int32_t sign_extend32(int32_t value, int index) · 44 unmodified lines
1312 return (int32_t)(value << shift) >> shift;1310 return (int32_t)(value << shift) >> shift;
1313}1311}
1314 1312
1315static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)1313static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, unsigned int r_type)
1316{1314{
1317 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1318 uint32_t inst, upper, lower, sign, j1, j2;1315 uint32_t inst, upper, lower, sign, j1, j2;
1319 int32_t offset;1316 int32_t offset;
1320 1317
1321 switch (r_typ) {1318 switch (r_type) {
1322 case R_ARM_ABS32:1319 case R_ARM_ABS32:
1323 case R_ARM_REL32:1320 case R_ARM_REL32:
1324 inst = TO_NATIVE(*(uint32_t *)loc);1321 inst = TO_NATIVE(*(uint32_t *)loc);
@@ -1397,13 +1394,12 @@ static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) · 72 unmodified lines
1397 return (Elf_Addr)(-1);1394 return (Elf_Addr)(-1);
1398}1395}
1399 1396
1400static Elf_Addr addend_mips_rel(uint32_t *location, Elf_Rela *r)1397static Elf_Addr addend_mips_rel(uint32_t *location, unsigned int r_type)
1401{1398{
1402 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1403 uint32_t inst;1399 uint32_t inst;
1404 1400
1405 inst = TO_NATIVE(*location);1401 inst = TO_NATIVE(*location);
1406 switch (r_typ) {1402 switch (r_type) {
1407 case R_MIPS_LO16:1403 case R_MIPS_LO16:
1408 return inst & 0xffff;1404 return inst & 0xffff;
1409 case R_MIPS_26:1405 case R_MIPS_26:
@@ -1500,6 +1496,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, · 90 unmodified lines
1500 Elf_Sym *tsym;1496 Elf_Sym *tsym;
1501 Elf_Addr taddr = 0;1497 Elf_Addr taddr = 0;
1502 void *loc;1498 void *loc;
1499 unsigned int r_type;
1503 1500
1504 r.r_offset = TO_NATIVE(rel->r_offset);1501 r.r_offset = TO_NATIVE(rel->r_offset);
1505#if KERNEL_ELFCLASS == ELFCLASS641502#if KERNEL_ELFCLASS == ELFCLASS64
@@ -1520,16 +1517,17 @@ static void section_rel(struct module *mod, struct elf_info *elf, · 14 unmodified lines
1520 1517
1521 loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset);1518 loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset);
1522 tsym = elf->symtab_start + r_sym;1519 tsym = elf->symtab_start + r_sym;
1520 r_type = ELF_R_TYPE(r.r_info);
1523 1521
1524 switch (elf->hdr->e_machine) {1522 switch (elf->hdr->e_machine) {
1525 case EM_386:1523 case EM_386:
1526 taddr = addend_386_rel(loc, &r);1524 taddr = addend_386_rel(loc, r_type);
1527 break;1525 break;
1528 case EM_ARM:1526 case EM_ARM:
1529 taddr = addend_arm_rel(loc, tsym, &r);1527 taddr = addend_arm_rel(loc, tsym, r_type);
1530 break;1528 break;
1531 case EM_MIPS:1529 case EM_MIPS:
1532 taddr = addend_mips_rel(loc, &r);1530 taddr = addend_mips_rel(loc, r_type);
1533 break;1531 break;
1534 default:1532 default:
1535 fatal("Please add code to calculate addend for this architecture\n");1533 fatal("Please add code to calculate addend for this architecture\n");