From b848c43c43d4658fe380d2939d49de56fefcff18a1c71f38d6513f4711307731 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Wed, 27 Sep 2023 13:28:24 +0000 Subject: [PATCH] Accepting request 1113839 from home:Andreas_Schwab:Factory - riscv-relro.patch: RISC-V: Protect .got with relro OBS-URL: https://build.opensuse.org/request/show/1113839 OBS-URL: https://build.opensuse.org/package/show/devel:gcc/binutils?expand=0&rev=455 --- binutils.changes | 5 +++++ binutils.spec | 2 ++ riscv-relro.patch | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 riscv-relro.patch diff --git a/binutils.changes b/binutils.changes index 5585587..a5cfc2c 100644 --- a/binutils.changes +++ b/binutils.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Mon Sep 25 11:12:43 UTC 2023 - Andreas Schwab + +- riscv-relro.patch: RISC-V: Protect .got with relro + ------------------------------------------------------------------- Thu Sep 14 12:27:48 UTC 2023 - Michael Matz diff --git a/binutils.spec b/binutils.spec index 11a5210..571d51f 100644 --- a/binutils.spec +++ b/binutils.spec @@ -154,6 +154,7 @@ Patch42: binutils-compat-old-behaviour.diff Patch43: binutils-revert-hlasm-insns.diff Patch44: binutils-revert-rela.diff Patch45: binutils-old-makeinfo.diff +Patch46: riscv-relro.patch Patch100: add-ulp-section.diff Patch90: cross-avr-nesc-as.patch Patch92: cross-avr-omit_section_dynsym.patch @@ -283,6 +284,7 @@ cp ld/ldgram.y ld/ldgram.y.orig %if %{suse_version} < 1500 %patch45 -p1 %endif +%patch46 -p1 %patch100 -p1 %if "%{TARGET}" == "avr" cp gas/config/tc-avr.h gas/config/tc-avr-nesc.h diff --git a/riscv-relro.patch b/riscv-relro.patch new file mode 100644 index 0000000..2bc913c --- /dev/null +++ b/riscv-relro.patch @@ -0,0 +1,57 @@ +From 7345d05aafde53a48d5a587a6d9c1778db78e0f3 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Thu, 21 Sep 2023 16:49:41 +0200 +Subject: [PATCH] RISC-V: Protect .got with relro + +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 | 4 ++++ + ld/emulparams/elf64lriscv-defs.sh | 1 + + ld/testsuite/ld-elf/binutils.exp | 1 - + 3 files changed, 5 insertions(+), 1 deletion(-) + +diff --git a/ld/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh +index b823cedacab..016556168c3 100644 +--- a/ld/emulparams/elf32lriscv-defs.sh ++++ b/ld/emulparams/elf32lriscv-defs.sh +@@ -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" +diff --git a/ld/emulparams/elf64lriscv-defs.sh b/ld/emulparams/elf64lriscv-defs.sh +index 84a700a5f58..ca15338428f 100644 +--- a/ld/emulparams/elf64lriscv-defs.sh ++++ b/ld/emulparams/elf64lriscv-defs.sh +@@ -1,2 +1,3 @@ + source_sh ${srcdir}/emulparams/elf32lriscv-defs.sh + ELFSIZE=64 ++SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 16 ? 16 : 0" +diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp +index 674e8e9a575..b38e29ed6fb 100644 +--- a/ld/testsuite/ld-elf/binutils.exp ++++ b/ld/testsuite/ld-elf/binutils.exp +@@ -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. +-- +2.42.0 +