From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7867) id 004B13858CD1; Tue, 9 Apr 2024 06:31:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 004B13858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712644316; bh=BEmoHh253u93gKtSyl0mC4JH+SOeBmqyh3ytkeT3e3o=; h=From:To:Subject:Date:From; b=R2B+gjhSY6yBIoPJRhaxBpk+tqnM6F1z6RzF3qE1GGyk3sP4DuxeGSKsFIBwFqWyQ zcrgCcm8q0x1QrEMsqHkeKonicHHxyoIGOAlm9E8Ass18SkRQqqVHNACwVoOxF6mrN pfvdSorATGcWpPzSzS8XOP91h1MUddPXjL7+YXj4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: liu & zhensong To: binutils-cvs@sourceware.org Subject: [binutils-gdb] LoongArch: ld: Move .got .got.plt before .data and protect .got with relro X-Act-Checkin: binutils-gdb X-Git-Author: mengqinggang X-Git-Refname: refs/heads/master X-Git-Oldrev: edb30f5782826af431e26aac4362cca687e77913 X-Git-Newrev: 2bf280a827577eaf26d657af9f5e29dbf77e6ee2 Message-Id: <20240409063156.004B13858CD1@sourceware.org> Date: Tue, 9 Apr 2024 06:31:55 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2bf280a82757= 7eaf26d657af9f5e29dbf77e6ee2 commit 2bf280a827577eaf26d657af9f5e29dbf77e6ee2 Author: mengqinggang Date: Wed Apr 3 10:20:27 2024 +0800 LoongArch: ld: Move .got .got.plt before .data and protect .got with re= lro =20 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. Diff: --- bfd/elfnn-loongarch.c | 2 ++ ld/emulparams/elf64loongarch-defs.sh | 5 ++++- ld/testsuite/ld-loongarch-elf/data-got.d | 16 ++++++++++++++++ ld/testsuite/ld-loongarch-elf/data-got.s | 6 ++++++ ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index eb70799b06a..e8632905019 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -127,6 +127,8 @@ struct loongarch_elf_link_hash_table =20 #define GOT_ENTRY_SIZE (LARCH_ELF_WORD_BYTES) =20 +/* 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) =20 #define elf_backend_want_got_plt 1 diff --git a/ld/emulparams/elf64loongarch-defs.sh b/ld/emulparams/elf64loon= garch-defs.sh index c793f5d8388..a8147bf71d7 100644 --- a/ld/emulparams/elf64loongarch-defs.sh +++ b/ld/emulparams/elf64loongarch-defs.sh @@ -34,6 +34,9 @@ TEXT_START_ADDR=3D0x120000000 MAXPAGESIZE=3D"CONSTANT (MAXPAGESIZE)" COMMONPAGESIZE=3D"CONSTANT (COMMONPAGESIZE)" =20 -SEPARATE_GOTPLT=3D0 +# Put .got before .data +DATA_GOT=3D" " +# First two entries for PLT resolver _dl_runtime_resolve and link map. +SEPARATE_GOTPLT=3D"SIZEOF (.got.plt) >=3D 16 ? 16 : 0" INITIAL_READONLY_SECTIONS=3D".interp : { *(.interp) } ${CREATE_PIE= -${INITIAL_READONLY_SECTIONS}}" INITIAL_READONLY_SECTIONS=3D"${RELOCATING+${CREATE_SHLIB-${INITIAL_READONL= Y_SECTIONS}}}" diff --git a/ld/testsuite/ld-loongarch-elf/data-got.d b/ld/testsuite/ld-loo= ngarch-elf/data-got.d new file mode 100644 index 00000000000..a754478a655 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/data-got.d @@ -0,0 +1,16 @@ +# 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=3Dboth +#readelf: -l --wide +#skip: loongarch32-*-* + +#... + GNU_RELRO 0x003c10 0x0000000000007c10 0x0000000000007c10 0x0003f0 0= x0003f0 R 0x1 +#... + 01 .dynamic .got .got.plt .data=20 +#... + 03 .dynamic .got=20 +#pass diff --git a/ld/testsuite/ld-loongarch-elf/data-got.s b/ld/testsuite/ld-loo= ngarch-elf/data-got.s new file mode 100644 index 00000000000..364fcf64c0e --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/data-got.s @@ -0,0 +1,6 @@ +.text +b foo +.section .got +.space 0x2a8, 4 +.data +.zero 24 diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsu= ite/ld-loongarch-elf/ld-loongarch-elf.exp index 759acab80d4..c2d616b8d0a 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -133,6 +133,7 @@ if [istarget "loongarch64-*-*"] { run_dump_test "tlsdesc-dso" run_dump_test "desc-norelax" run_dump_test "desc-relax" + run_dump_test "data-got" } =20 if [check_pie_support] {