WIP MachO binutils port assisted by AI I may consider upstreaming this in the future.
0

Configure Feed

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

LoongArch: ld: Move .got .got.plt before .data and protect .got with relro

Move .got .got.plt before .data so .got can be protected with -zrelro.
And the first two entries of .got.plt (_dl_runtime_resolve and link map)
are placed within the relro region.

authored by

mengqinggang and committed by
liuzhensong
(Apr 9, 2024, 2:31 PM +0800) 2bf280a8 edb30f57

+29 -1
+2
bfd/elfnn-loongarch.c
··· 127 127 128 128 #define GOT_ENTRY_SIZE (LARCH_ELF_WORD_BYTES) 129 129 130 + /* Reserve two entries of GOTPLT for ld.so, one is used for PLT 131 + resolver _dl_runtime_resolve, the other is used for link map. */ 130 132 #define GOTPLT_HEADER_SIZE (GOT_ENTRY_SIZE * 2) 131 133 132 134 #define elf_backend_want_got_plt 1
+4 -1
ld/emulparams/elf64loongarch-defs.sh
··· 34 34 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)" 35 35 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)" 36 36 37 - SEPARATE_GOTPLT=0 37 + # Put .got before .data 38 + DATA_GOT=" " 39 + # First two entries for PLT resolver _dl_runtime_resolve and link map. 40 + SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 16 ? 16 : 0" 38 41 INITIAL_READONLY_SECTIONS=".interp : { *(.interp) } ${CREATE_PIE-${INITIAL_READONLY_SECTIONS}}" 39 42 INITIAL_READONLY_SECTIONS="${RELOCATING+${CREATE_SHLIB-${INITIAL_READONLY_SECTIONS}}}"
+16
ld/testsuite/ld-loongarch-elf/data-got.d
··· 1 + # line 11 test the first two entries of .got.plt in relro region 2 + # relro segment size is .dynamic size + .got size + 0x10 3 + # line 13 test .got .got.plt before .got 4 + # line 15 test .got in relro segment 5 + #as: 6 + #ld: -shared -z relro --hash-style=both 7 + #readelf: -l --wide 8 + #skip: loongarch32-*-* 9 + 10 + #... 11 + GNU_RELRO 0x003c10 0x0000000000007c10 0x0000000000007c10 0x0003f0 0x0003f0 R 0x1 12 + #... 13 + 01 .dynamic .got .got.plt .data 14 + #... 15 + 03 .dynamic .got 16 + #pass
+6
ld/testsuite/ld-loongarch-elf/data-got.s
··· 1 + .text 2 + b foo 3 + .section .got 4 + .space 0x2a8, 4 5 + .data 6 + .zero 24
+1
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
··· 133 133 run_dump_test "tlsdesc-dso" 134 134 run_dump_test "desc-norelax" 135 135 run_dump_test "desc-relax" 136 + run_dump_test "data-got" 136 137 } 137 138 138 139 if [check_pie_support] {