From patchwork Wed Jun 19 06:04:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 92412 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C5523884585 for ; Wed, 19 Jun 2024 06:05:28 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 38BFF3882AEC for ; Wed, 19 Jun 2024 06:04:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38BFF3882AEC Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 38BFF3882AEC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718777096; cv=none; b=a4vnQ5UAeEjhx9eO/R1++SuuOg3jTVssbhXcwBWWDGDm/CWTSW4jCJfL0kdJuSvyOmWhwDEOsy4rgTRTpGbzgQnGP8aW4J4lRseWpRAklrUk/J/CjXuAbWSVuYiK2AZBIt/oWP8RPsIdbG7IIapjV+H+QYvkYMjvwwAb6iM7pdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718777096; c=relaxed/simple; bh=HU67wBtFnphP7UFqYZ0Q25Q8dNsHa3+//Vb2tGDoQSw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FI3kKg1bTxZ8j/EFB6YR0DBoRgFTwqNZW/A49lcdlsYFk2FBx9/DOxhgCrbC0NANAoyzxjpS2dM69Gr9XuyNBHoEIwEMph8Cp5eMRI58cw+RxWFF77nbMywbi24DQVgV6IukTJpzOX3fZeNBgg1T6XPJ9gY057UGAT+CuYOdpk8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1718777092; bh=HU67wBtFnphP7UFqYZ0Q25Q8dNsHa3+//Vb2tGDoQSw=; h=From:To:Cc:Subject:Date:From; b=fnuH6rW635Tuiaiw+BuFe0JJyOlvPBRtrBOIeVW6MvXTFxyqiY7BDDhUvJCT5nkhX hADxxarwei4Rknay9VMxZYXKPFpTJK7bdrWfmx4yOB/OGNLiQHbncxcAtV4doiOmLB JUWxqZISYDpM7T1lPS5oi4hKcAngF7cPE7yOtbqo= Received: from stargazer.. (unknown [IPv6:240e:358:1185:bc00:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 8DB581A3EF4; Wed, 19 Jun 2024 02:04:47 -0400 (EDT) From: Xi Ruoyao To: binutils@sourceware.org Cc: Lulu Cai , xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, mengqinggang@loongson.cn, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, Xi Ruoyao Subject: [PATCH] LoongArch: TLS IE needs only one dynamic reloc Date: Wed, 19 Jun 2024 14:04:18 +0800 Message-ID: <20240619060418.105632-1-xry111@xry111.site> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org As the comment in the code says, TLS_IE needs only one dynamic reloc. But commit b67a17aa7c0c ("LoongArch: Fix the issue of excessive relocation generated by GD and IE") has incorrectly allocated the space for two dynamic relocs, causing libc.so to contain 8 R_LARCH_NONE. Adjust tlsdesc-dso.d for the offset changes and add two tests to ensure there are no R_LARCH_NONE with TLS. Signed-off-by: Xi Ruoyao --- bfd/elfnn-loongarch.c | 2 +- ld/testsuite/ld-loongarch-elf/desc-ie-reloc.d | 9 ++ ld/testsuite/ld-loongarch-elf/desc-ie.d | 8 +- .../ld-loongarch-elf/ld-loongarch-elf.exp | 2 + .../ld-loongarch-elf/tlsdesc-dso-reloc.d | 9 ++ ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d | 86 +++++++++---------- 6 files changed, 68 insertions(+), 48 deletions(-) create mode 100644 ld/testsuite/ld-loongarch-elf/desc-ie-reloc.d create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc-dso-reloc.d diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 93c036f6a53..b1720760475 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -1353,7 +1353,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) { s->size += GOT_ENTRY_SIZE; if (need_reloc) - htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela); + htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); } /* TLS_DESC needs one dynamic reloc and two GOT slot. */ diff --git a/ld/testsuite/ld-loongarch-elf/desc-ie-reloc.d b/ld/testsuite/ld-loongarch-elf/desc-ie-reloc.d new file mode 100644 index 00000000000..c7a2f8edb8a --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/desc-ie-reloc.d @@ -0,0 +1,9 @@ +#source: desc-ie.s +#as: +#ld: -shared -z norelro --hash-style=both +#readelf: -Wr + +#failif +#... +.* +R_LARCH_NONE +.* +#... diff --git a/ld/testsuite/ld-loongarch-elf/desc-ie.d b/ld/testsuite/ld-loongarch-elf/desc-ie.d index c833b233d42..0759404b89a 100644 --- a/ld/testsuite/ld-loongarch-elf/desc-ie.d +++ b/ld/testsuite/ld-loongarch-elf/desc-ie.d @@ -8,7 +8,7 @@ Disassembly of section .text: [0-9a-f]+ : - +[0-9a-f]+: 1a000084 pcalau12i \$a0, .* - +[0-9a-f]+: 28cd0084 ld.d \$a0, \$a0, .* - +[0-9a-f]+: 1a000084 pcalau12i \$a0, .* - +[0-9a-f]+: 28cd0084 ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index 40f56576cbc..d833a89246e 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -130,7 +130,9 @@ if [istarget "loongarch64-*-*"] { if [istarget "loongarch64-*-*"] { if [check_shared_lib_support] { run_dump_test "desc-ie" + run_dump_test "desc-ie-reloc" run_dump_test "tlsdesc-dso" + run_dump_test "tlsdesc-dso-reloc" run_dump_test "desc-norelax" run_dump_test "desc-relax" run_dump_test "data-got" diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc-dso-reloc.d b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso-reloc.d new file mode 100644 index 00000000000..d5afa7c3657 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso-reloc.d @@ -0,0 +1,9 @@ +#source: tlsdesc-dso.s +#as: +#ld: -shared -z norelro --hash-style=both +#readelf: -Wr + +#failif +#... +.* +R_LARCH_NONE +.* +#... diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d index 8f66302f1cf..d6997ec9455 100644 --- a/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d +++ b/ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d @@ -9,52 +9,52 @@ Disassembly of section .text: [0-9a-f]+ : - +[0-9a-f]+: 18021584 pcaddi \$a0, 4268 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28dd4084 ld.d \$a0, \$a0, 1872 - +[0-9a-f]+: 18021364 pcaddi \$a0, 4251 - +[0-9a-f]+: 180213c4 pcaddi \$a0, 4254 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28dc0084 ld.d \$a0, \$a0, 1792 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28dc0084 ld.d \$a0, \$a0, 1792 - +[0-9a-f]+: 18021364 pcaddi \$a0, 4251 - +[0-9a-f]+: 180213c4 pcaddi \$a0, 4254 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28dce084 ld.d \$a0, \$a0, 1848 + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* [0-9a-f]+ : - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28daa084 ld.d \$a0, \$a0, 1704 - +[0-9a-f]+: 18020de4 pcaddi \$a0, 4207 - +[0-9a-f]+: 18020f04 pcaddi \$a0, 4216 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 - +[0-9a-f]+: 18020e24 pcaddi \$a0, 4209 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28db4084 ld.d \$a0, \$a0, 1744 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28db4084 ld.d \$a0, \$a0, 1744 - +[0-9a-f]+: 18020f44 pcaddi \$a0, 4218 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 - +[0-9a-f]+: 18020e64 pcaddi \$a0, 4211 - +[0-9a-f]+: 1a000084 pcalau12i \$a0, 4 - +[0-9a-f]+: 28dba084 ld.d \$a0, \$a0, 1768 + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .* [0-9a-f]+ : - +[0-9a-f]+: 18020ec4 pcaddi \$a0, 4214 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* [0-9a-f]+ : - +[0-9a-f]+: 18021224 pcaddi \$a0, 4241 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 - +[0-9a-f]+: 18021144 pcaddi \$a0, 4234 - +[0-9a-f]+: 28c00081 ld.d \$ra, \$a0, 0 - +[0-9a-f]+: 4c000021 jirl \$ra, \$ra, 0 + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .* + +[0-9a-f]+: [0-9a-f]+ pcaddi \$a0, .* + +[0-9a-f]+: [0-9a-f]+ ld.d \$ra, \$a0, .* + +[0-9a-f]+: [0-9a-f]+ jirl \$ra, \$ra, .*