Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

modpost: clean up MIPS64 little endian relocation code

MIPS64 little endian target has an odd encoding of r_info.

This commit makes the special handling less ugly. It is still ugly,
but #if conditionals will go away, at least.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+43 -55
+43 -33
scripts/mod/modpost.c
··· 1426 1426 #define R_LARCH_SUB32 55 1427 1427 #endif 1428 1428 1429 + static void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, 1430 + unsigned int *r_type, unsigned int *r_sym) 1431 + { 1432 + typedef struct { 1433 + Elf64_Word r_sym; /* Symbol index */ 1434 + unsigned char r_ssym; /* Special symbol for 2nd relocation */ 1435 + unsigned char r_type3; /* 3rd relocation type */ 1436 + unsigned char r_type2; /* 2nd relocation type */ 1437 + unsigned char r_type; /* 1st relocation type */ 1438 + } Elf64_Mips_R_Info; 1439 + 1440 + bool is_64bit = (elf->hdr->e_ident[EI_CLASS] == ELFCLASS64); 1441 + 1442 + if (elf->hdr->e_machine == EM_MIPS && is_64bit) { 1443 + Elf64_Mips_R_Info *mips64_r_info = (void *)&r_info; 1444 + 1445 + *r_type = mips64_r_info->r_type; 1446 + *r_sym = TO_NATIVE(mips64_r_info->r_sym); 1447 + return; 1448 + } 1449 + 1450 + if (is_64bit) { 1451 + Elf64_Xword r_info64 = r_info; 1452 + 1453 + r_info = TO_NATIVE(r_info64); 1454 + } else { 1455 + Elf32_Word r_info32 = r_info; 1456 + 1457 + r_info = TO_NATIVE(r_info32); 1458 + } 1459 + 1460 + *r_type = ELF_R_TYPE(r_info); 1461 + *r_sym = ELF_R_SYM(r_info); 1462 + } 1463 + 1429 1464 static void section_rela(struct module *mod, struct elf_info *elf, 1430 1465 Elf_Shdr *sechdr) 1431 1466 { ··· 1477 1442 return; 1478 1443 1479 1444 for (rela = start; rela < stop; rela++) { 1445 + unsigned int r_type; 1446 + 1480 1447 r.r_offset = TO_NATIVE(rela->r_offset); 1481 - #if KERNEL_ELFCLASS == ELFCLASS64 1482 - if (elf->hdr->e_machine == EM_MIPS) { 1483 - unsigned int r_typ; 1484 - r_sym = ELF64_MIPS_R_SYM(rela->r_info); 1485 - r_sym = TO_NATIVE(r_sym); 1486 - r_typ = ELF64_MIPS_R_TYPE(rela->r_info); 1487 - r.r_info = ELF64_R_INFO(r_sym, r_typ); 1488 - } else { 1489 - r.r_info = TO_NATIVE(rela->r_info); 1490 - r_sym = ELF_R_SYM(r.r_info); 1491 - } 1492 - #else 1493 - r.r_info = TO_NATIVE(rela->r_info); 1494 - r_sym = ELF_R_SYM(r.r_info); 1495 - #endif 1448 + get_rel_type_and_sym(elf, rela->r_info, &r_type, &r_sym); 1449 + 1496 1450 r.r_addend = TO_NATIVE(rela->r_addend); 1497 1451 switch (elf->hdr->e_machine) { 1498 1452 case EM_RISCV: 1499 1453 if (!strcmp("__ex_table", fromsec) && 1500 - ELF_R_TYPE(r.r_info) == R_RISCV_SUB32) 1454 + r_type == R_RISCV_SUB32) 1501 1455 continue; 1502 1456 break; 1503 1457 case EM_LOONGARCH: 1504 1458 if (!strcmp("__ex_table", fromsec) && 1505 - ELF_R_TYPE(r.r_info) == R_LARCH_SUB32) 1459 + r_type == R_LARCH_SUB32) 1506 1460 continue; 1507 1461 break; 1508 1462 } ··· 1523 1499 unsigned int r_type; 1524 1500 1525 1501 r.r_offset = TO_NATIVE(rel->r_offset); 1526 - #if KERNEL_ELFCLASS == ELFCLASS64 1527 - if (elf->hdr->e_machine == EM_MIPS) { 1528 - unsigned int r_typ; 1529 - r_sym = ELF64_MIPS_R_SYM(rel->r_info); 1530 - r_sym = TO_NATIVE(r_sym); 1531 - r_typ = ELF64_MIPS_R_TYPE(rel->r_info); 1532 - r.r_info = ELF64_R_INFO(r_sym, r_typ); 1533 - } else { 1534 - r.r_info = TO_NATIVE(rel->r_info); 1535 - r_sym = ELF_R_SYM(r.r_info); 1536 - } 1537 - #else 1538 - r.r_info = TO_NATIVE(rel->r_info); 1539 - r_sym = ELF_R_SYM(r.r_info); 1540 - #endif 1502 + 1503 + get_rel_type_and_sym(elf, rel->r_info, &r_type, &r_sym); 1541 1504 1542 1505 loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); 1543 1506 tsym = elf->symtab_start + r_sym; 1544 - r_type = ELF_R_TYPE(r.r_info); 1545 1507 1546 1508 switch (elf->hdr->e_machine) { 1547 1509 case EM_386:
-22
scripts/mod/modpost.h
··· 50 50 #define ELF_R_TYPE ELF64_R_TYPE 51 51 #endif 52 52 53 - /* The 64-bit MIPS ELF ABI uses an unusual reloc format. */ 54 - typedef struct 55 - { 56 - Elf32_Word r_sym; /* Symbol index */ 57 - unsigned char r_ssym; /* Special symbol for 2nd relocation */ 58 - unsigned char r_type3; /* 3rd relocation type */ 59 - unsigned char r_type2; /* 2nd relocation type */ 60 - unsigned char r_type1; /* 1st relocation type */ 61 - } _Elf64_Mips_R_Info; 62 - 63 - typedef union 64 - { 65 - Elf64_Xword r_info_number; 66 - _Elf64_Mips_R_Info r_info_fields; 67 - } _Elf64_Mips_R_Info_union; 68 - 69 - #define ELF64_MIPS_R_SYM(i) \ 70 - ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym) 71 - 72 - #define ELF64_MIPS_R_TYPE(i) \ 73 - ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1) 74 - 75 53 #if KERNEL_ELFDATA != HOST_ELFDATA 76 54 77 55 static inline void __endian(const void *src, void *dest, unsigned int size)