From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id B2FAD3858CD1 for ; Tue, 9 Apr 2024 06:36:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2FAD3858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B2FAD3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712644592; cv=none; b=Vm2uh0cJWaYdNIluCme73n3auOkJn5qprl/9rNEcJvBSgE2khwx0gLXnVubL/yrww/zSKQd/A0PqrP26EaOG91BssYIDHEXr+Ji+rmvVcV27pa+FVePV+ZWl1EZWJtDy8yh5D7IWT7+24NREApqfY8RVrIrU4BZMahmYTtlY2gQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712644592; c=relaxed/simple; bh=uoyqwAQGXTEAfdIbCMSD7bKVbVXYsDBRSi38s0I1+j4=; h=Subject:To:From:Message-ID:Date:MIME-Version; b=LwUfhNMCG/49Ogj2UrML4L1lmv5v53zCkMqVb7sUpfpDC8HTx4go1Km8yNjRttPqu3kKZ79QC+BnpJrhsRpWCAL75Qj5sFSAtlUSD3UkShqz5hbkGxBe3A7nTcQ6oyPjJo98ZjrZsDk+BukZjD6FICqskvYqVl+qod4dv4lHeHU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.171]) by gateway (Coremail) with SMTP id _____8Bx27rp4RRmGLskAA--.3258S3; Tue, 09 Apr 2024 14:36:26 +0800 (CST) Received: from [10.20.4.171] (unknown [10.20.4.171]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxJBHm4RRm20B2AA--.20348S3; Tue, 09 Apr 2024 14:36:23 +0800 (CST) Subject: Re: [PATCH v2] LoongArch: ld: Move .got .got.plt before .data and protect .got with relro To: Xi Ruoyao , binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, cailulu@loongson.cn, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, hejinyang@loongson.cn References: <20240408064953.3562476-1-mengqinggang@loongson.cn> <1c78cb6c5d6ddfd0e36ec67da8a271842bc84904.camel@xry111.site> From: mengqinggang Message-ID: <2a659053-bdb0-14ff-cbc3-6344c9afc091@loongson.cn> Date: Tue, 9 Apr 2024 14:36:22 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <1c78cb6c5d6ddfd0e36ec67da8a271842bc84904.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8CxJBHm4RRm20B2AA--.20348S3 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZr48Jr4xAr45Jr47Cw4rJFc_yoWrZFyDp3 4kZFyrCFW8J3Z7Grn8G3y5ZF95uryxK3W2g3WftF1j9rs5Jry0qr40vrWagF4UAw48JF10 vry0q343ZFnFq3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCYjI0SjxkI62AI1c AE67vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8C rVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8Zw CIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x02 67AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1QV y3UUUUU== X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,BODY_8BITS,GIT_PATCH_0,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Thank you very much, this patch has been applied. 在 2024/4/8 下午8:14, Xi Ruoyao 写道: > On Mon, 2024-04-08 at 14:49 +0800, mengqinggang wrote: >> 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. >> --- >> Changes v1 -> v2: >> - Add --hash-style=both option in data-got.d. >> >> v1 link: https://sourceware.org/pipermail/binutils/2024-April/133300.html > I've rebuilt the entire base system with v1 applied onto 2.42 without > any problem, so it should be OK. > >>  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-loongarch-elf/ld-loongarch-elf.exp        |  1 + >>  5 files changed, 29 insertions(+), 1 deletion(-) >>  create mode 100644 ld/testsuite/ld-loongarch-elf/data-got.d >>  create mode 100644 ld/testsuite/ld-loongarch-elf/data-got.s >> >> 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 >> >>  #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 >> diff --git a/ld/emulparams/elf64loongarch-defs.sh b/ld/emulparams/elf64loongarch-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=0x120000000 >>  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}}}" >> diff --git a/ld/testsuite/ld-loongarch-elf/data-got.d b/ld/testsuite/ld-loongarch-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=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 >> diff --git a/ld/testsuite/ld-loongarch-elf/data-got.s b/ld/testsuite/ld-loongarch-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/testsuite/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" >>    } >> >>    if [check_pie_support] {