History

riscv: switch to relative exception tables

Similar as other architectures such as arm64, x86 and so on, use offsets relative to the exception table entry values rather than absolute addresses for both the exception locationand the fixup. However, RISCV label difference will actually produce two relocations, a pair of R_RISCV_ADD32 and R_RISCV_SUB32. Take below simple code for example: $ cat test.S .section .text 1: nop .section __ex_table,"a" .balign 4 .long (1b - .) .previous $ riscv64-linux-gnu-gcc -c test.S $ riscv64-linux-gnu-readelf -r test.o Relocation section '.rela__ex_table' at offset 0x100 contains 2 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000000 000600000023 R_RISCV_ADD32 0000000000000000 .L1^B1 + 0 000000000000 000500000027 R_RISCV_SUB32 0000000000000000 .L0 + 0 The modpost will complain the R_RISCV_SUB32 relocation, so we need to patch modpost.c to skip this relocation for .rela__ex_table section. After this patch, the __ex_table section size of defconfig vmlinux is reduced from 7072 Bytes to 3536 Bytes.

Jisheng Zhang committed 4 years ago

Commit bb1f85d1 parent f8f2ad07 files · +46 −7Browse files

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

Unified · Split

2 files
  1. scripts/mod/modpost.c +15 −0
  2. scripts/sorttable.c +1 −1
scripts/mod/modpost.c+15−0
@@ -1830,6 +1830,14 @@ static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) · 1829 unmodified lines
18301830 return 0;
18311831 }
18321832
1833+#ifndef EM_RISCV
1834+#define EM_RISCV 243
1835+#endif
1836+
1837+#ifndef R_RISCV_SUB32
1838+#define R_RISCV_SUB32 39
1839+#endif
1840+
18331841 static void section_rela(const char *modname, struct elf_info *elf,
18341842 Elf_Shdr *sechdr)
18351843 {
@@ -1866,6 +1874,13 @@ static void section_rela(const char *modname, struct elf_info *elf, · 30 unmodified lines
18661874 r_sym = ELF_R_SYM(r.r_info);
18671875 #endif
18681876 r.r_addend = TO_NATIVE(rela->r_addend);
1877+ switch (elf->hdr->e_machine) {
1878+ case EM_RISCV:
1879+ if (!strcmp("__ex_table", fromsec) &&
1880+ ELF_R_TYPE(r.r_info) == R_RISCV_SUB32)
1881+ continue;
1882+ break;
1883+ }
18691884 sym = elf->symtab_start + r_sym;
18701885 /* Skip special sections */
18711886 if (is_shndx_special(sym->st_shndx))
scripts/sorttable.c+1−1
@@ -346,6 +346,7 @@ static int do_file(char const *const fname, void *addr) · 345 unmodified lines
346346 case EM_PARISC:
347347 case EM_PPC:
348348 case EM_PPC64:
349+ case EM_RISCV:
349350 custom_sort = sort_relative_table;
350351 break;
351352 case EM_ARCOMPACT:
@@ -353,7 +354,6 @@ static int do_file(char const *const fname, void *addr) · 1 unmodified line
353354 case EM_ARM:
354355 case EM_MICROBLAZE:
355356 case EM_MIPS:
356− case EM_RISCV:
357357 case EM_XTENSA:
358358 break;
359359 default:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t