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