History

LoongArch: Switch to relative exception tables

Similar to other architectures such as arm64, x86, riscv and so on, use offsets relative to the exception table entry values rather than their absolute addresses for both the exception location and the fixup. However, LoongArch label difference because it will actually produce two relocations, a pair of R_LARCH_ADD32 and R_LARCH_SUB32. Take simple code below for example: $ cat test_ex_table.S .section .text 1: nop .section __ex_table,"a" .balign 4 .long (1b - .) .previous $ loongarch64-unknown-linux-gnu-gcc -c test_ex_table.S $ loongarch64-unknown-linux-gnu-readelf -Wr test_ex_table.o Relocation section '.rela__ex_table' at offset 0x100 contains 2 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000000000 0000000600000032 R_LARCH_ADD32 0000000000000000 .L1^B1 + 0 0000000000000000 0000000500000037 R_LARCH_SUB32 0000000000000000 L0^A + 0 The modpost will complain the R_LARCH_SUB32 relocation, so we need to patch modpost.c to skip this relocation for .rela__ex_table section.

Youling Tang committed 3 years ago

Commit 3d36f421 parent 508f28c6 files · +69 −18Browse files

Showing the changes to scripts (2 of 6 files). Show all

Unified · Split

2 files
  1. scripts/mod/modpost.c +13 −0
  2. scripts/sorttable.c +1 −1
scripts/mod/modpost.c+13−0
@@ -1523,6 +1523,14 @@ static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) · 1522 unmodified lines
15231523 #define R_RISCV_SUB32 39
15241524 #endif
15251525
1526+#ifndef EM_LOONGARCH
1527+#define EM_LOONGARCH 258
1528+#endif
1529+
1530+#ifndef R_LARCH_SUB32
1531+#define R_LARCH_SUB32 55
1532+#endif
1533+
15261534 static void section_rela(const char *modname, struct elf_info *elf,
15271535 Elf_Shdr *sechdr)
15281536 {
@@ -1564,6 +1572,11 @@ static void section_rela(const char *modname, struct elf_info *elf, · 35 unmodified lines
15641572 ELF_R_TYPE(r.r_info) == R_RISCV_SUB32)
15651573 continue;
15661574 break;
1575+ case EM_LOONGARCH:
1576+ if (!strcmp("__ex_table", fromsec) &&
1577+ ELF_R_TYPE(r.r_info) == R_LARCH_SUB32)
1578+ continue;
1579+ break;
15671580 }
15681581 sym = elf->symtab_start + r_sym;
15691582 /* Skip special sections */
scripts/sorttable.c+1−1
@@ -312,12 +312,12 @@ static int do_file(char const *const fname, void *addr) · 311 unmodified lines
312312 case EM_PARISC:
313313 case EM_PPC:
314314 case EM_PPC64:
315+ case EM_LOONGARCH:
315316 custom_sort = sort_relative_table;
316317 break;
317318 case EM_ARCOMPACT:
318319 case EM_ARCV2:
319320 case EM_ARM:
320− case EM_LOONGARCH:
321321 case EM_MICROBLAZE:
322322 case EM_MIPS:
323323 case EM_XTENSA: