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
1830 return 0;1830 return 0;
1831}1831}
1832 1832
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
1833static void section_rela(const char *modname, struct elf_info *elf,1841static void section_rela(const char *modname, struct elf_info *elf,
1834 Elf_Shdr *sechdr)1842 Elf_Shdr *sechdr)
1835{1843{
@@ -1866,6 +1874,13 @@ static void section_rela(const char *modname, struct elf_info *elf, · 30 unmodified lines
1866 r_sym = ELF_R_SYM(r.r_info);1874 r_sym = ELF_R_SYM(r.r_info);
1867#endif1875#endif
1868 r.r_addend = TO_NATIVE(rela->r_addend);1876 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 }
1869 sym = elf->symtab_start + r_sym;1884 sym = elf->symtab_start + r_sym;
1870 /* Skip special sections */1885 /* Skip special sections */
1871 if (is_shndx_special(sym->st_shndx))1886 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
346 case EM_PARISC:346 case EM_PARISC:
347 case EM_PPC:347 case EM_PPC:
348 case EM_PPC64:348 case EM_PPC64:
349 case EM_RISCV:
349 custom_sort = sort_relative_table;350 custom_sort = sort_relative_table;
350 break;351 break;
351 case EM_ARCOMPACT:352 case EM_ARCOMPACT:
@@ -353,7 +354,6 @@ static int do_file(char const *const fname, void *addr) · 1 unmodified line
353 case EM_ARM:354 case EM_ARM:
354 case EM_MICROBLAZE:355 case EM_MICROBLAZE:
355 case EM_MIPS:356 case EM_MIPS:
356 case EM_RISCV:
357 case EM_XTENSA:357 case EM_XTENSA:
358 break;358 break;
359 default:359 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