RISC-V: Protect .got with relro
authorAndreas Schwab <schwab@suse.de>
Thu, 21 Sep 2023 14:49:41 +0000 (16:49 +0200)
committerAndreas Schwab <schwab@suse.de>
Mon, 25 Sep 2023 10:36:58 +0000 (12:36 +0200)
Move .got before .data so that it can be protected with -zrelro.  Also
separate .got.plt from .got if -znow is not in effect; the first two words
of .got.plt are placed within the relro region.

ld:
PR ld/30877
* emulparams/elf32lriscv-defs.sh (DATA_GOT, SEPARATE_GOTPLT):
Define.
* emulparams/elf64lriscv-defs.sh (SEPARATE_GOTPLT): Define.
* testsuite/ld-elf/binutils.exp (binutils_test): Remove riscv*-*-*
from relro_got expression.

ld/emulparams/elf32lriscv-defs.sh
ld/emulparams/elf64lriscv-defs.sh
ld/testsuite/ld-elf/binutils.exp

index b823cedacab9be67b098891d49baa090629bb8f7..016556168c30a6a05349d725c112e97137b5359f 100644 (file)
@@ -47,3 +47,7 @@ INITIAL_READONLY_SECTIONS="${RELOCATING+${CREATE_SHLIB-${INITIAL_READONLY_SECTIO
 OTHER_END_SYMBOLS="${CREATE_SHLIB-__BSS_END__ = .;
     __global_pointer$ = MIN(__SDATA_BEGIN__ + 0x800,
                            MAX(__DATA_BEGIN__ + 0x800, __BSS_END__ - 0x800));}"
+
+# Put .got before .data
+DATA_GOT=" "
+SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 8 ? 8 : 0"
index 84a700a5f587f5634448504f7425e137556d6069..ca15338428f9c281ba4a505923784ee7954c4eec 100644 (file)
@@ -1,2 +1,3 @@
 source_sh ${srcdir}/emulparams/elf32lriscv-defs.sh
 ELFSIZE=64
+SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 16 ? 16 : 0"
index 674e8e9a5754d8e4cef6b7707c51cdf5455911d3..b38e29ed6fb1628e6e4d6a52f48ce4c664c1ed6a 100644 (file)
@@ -95,7 +95,6 @@ proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "
                              || [istarget "mips*-*-*"] \
                              || [istarget "nios2*-*-*"] \
                              || [istarget "or1k-*-*"] \
-                             || [istarget "riscv*-*-*"] \
                              || [istarget "sh*-*-*"] \
                              || [istarget "x86_64-*-rdos*"])]
        # Check if GNU_RELRO segment is generated.