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.
#define GOT_ENTRY_SIZE (LARCH_ELF_WORD_BYTES)
+/* Reserve two entries of GOTPLT for ld.so, one is used for PLT
+ resolver _dl_runtime_resolve, the other is used for link map. */
#define GOTPLT_HEADER_SIZE (GOT_ENTRY_SIZE * 2)
#define elf_backend_want_got_plt 1
MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
-SEPARATE_GOTPLT=0
+# Put .got before .data
+DATA_GOT=" "
+# First two entries for PLT resolver _dl_runtime_resolve and link map.
+SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 16 ? 16 : 0"
INITIAL_READONLY_SECTIONS=".interp : { *(.interp) } ${CREATE_PIE-${INITIAL_READONLY_SECTIONS}}"
INITIAL_READONLY_SECTIONS="${RELOCATING+${CREATE_SHLIB-${INITIAL_READONLY_SECTIONS}}}"
--- /dev/null
+# line 11 test the first two entries of .got.plt in relro region
+# relro segment size is .dynamic size + .got size + 0x10
+# line 13 test .got .got.plt before .got
+# line 15 test .got in relro segment
+#as:
+#ld: -shared -z relro --hash-style=both
+#readelf: -l --wide
+#skip: loongarch32-*-*
+
+#...
+ GNU_RELRO 0x003c10 0x0000000000007c10 0x0000000000007c10 0x0003f0 0x0003f0 R 0x1
+#...
+ 01 .dynamic .got .got.plt .data
+#...
+ 03 .dynamic .got
+#pass
--- /dev/null
+.text
+b foo
+.section .got
+.space 0x2a8, 4
+.data
+.zero 24
run_dump_test "tlsdesc-dso"
run_dump_test "desc-norelax"
run_dump_test "desc-relax"
+ run_dump_test "data-got"
}
if [check_pie_support] {