| Message ID | 20250917022237.506797-1-cailulu@loongson.cn |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> 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 6E502385840C for <patchwork@sourceware.org>; Wed, 17 Sep 2025 02:24:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E502385840C X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 076D93858D33 for <binutils@sourceware.org>; Wed, 17 Sep 2025 02:23:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 076D93858D33 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 076D93858D33 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=1758075827; cv=none; b=KEPSfnAFztZojAI3h5z8/ZkhLTCdhvo83P17e60XEovt6vjsBoIJ35m0fu+ymzaO/qin/7Wb6at/m6lXJxrxObj+0zd8qvfByBvSOW/fAgmSLokdhdgRDhPv6ujSMyVotEZ1Tnm0cqT9secf7EjZVmNFmw8H/BBEWDOoouNPTyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758075827; c=relaxed/simple; bh=eLGtTa6LejtmTdCLRErNB/wY2pFcyA08vNjNMT5J8+k=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=yFkZyaxUMCT2yq9lmYJ9cli3+Usok98t6AvI3CqF9aFOpip3coBinqPjjhs6zvIncdaB3c8eau39X5c2JWTKwqawpMyz2gkdulyhHMI3KIWNh7FzgaPIf6rjPvO/fmOOPp7QP0tKIJLPygGA7rweGqrjiIEI1GazFwrE1xWV3s8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 076D93858D33 Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8Bx2tGvG8poJDQLAA--.24355S3; Wed, 17 Sep 2025 10:23:44 +0800 (CST) Received: from 5.. (unknown [10.2.6.5]) by front1 (Coremail) with SMTP id qMiowJDxbMGtG8pobH6aAA--.45980S4; Wed, 17 Sep 2025 10:23:42 +0800 (CST) From: Lulu Cai <cailulu@loongson.cn> To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, luweining@loongson.cn, hejinyang@loongson.cn, hjl.tools@gmail.com, Lulu Cai <cailulu@loongson.cn> Subject: [PATCH v2] LoongArch: Use more appropriate assertions for the relocation of TLS LE Date: Wed, 17 Sep 2025 10:22:37 +0800 Message-Id: <20250917022237.506797-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qMiowJDxbMGtG8pobH6aAA--.45980S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAgEIB2jI-AwUwgAAsK X-Coremail-Antispam: 1Uk129KBj93XoWxWrWfCF17CrW3WFW7CF4fXrc_yoW5GF1Up3 4DZFyrKF4fJFnrWF95Cay5WFn5Wrn7GryIqa93tF1jvrs0q348Xr1SyrW3XFW5Xa17Gw45 Xr10v34ruF40vrcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUyEb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8r9N3UUUUU== X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
[v2] LoongArch: Use more appropriate assertions for the relocation of TLS LE
|
|
Commit Message
Lulu Cai
Sept. 17, 2025, 2:22 a.m. UTC
PR ld/33427
Patches introduced in the GCC mainline:
commit 8cad8f94b450be9b73d07bdeef7fa1778d3f2b96
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri Sep 5 15:40:51 2025 -0700
c: Update TLS model after processing a TLS variable
Set a tentative TLS model in grokvardecl and update TLS mode with
the default TLS access model after a TLS variable has been fully
processed if the default TLS access model is stronger,
triggered a linker error when building glibc using build-many-glibcs.py.
See: https://sourceware.org/pipermail/binutils/2025-September/144225.html
This fix uses more appropriate assertions.
---
Changes from v1:
- Added the bug ID
---
bfd/elfnn-loongarch.c | 2 +-
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 12 ++++++++++++
ld/testsuite/ld-loongarch-elf/undefweak_le.s | 7 +++++++
3 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-loongarch-elf/undefweak_le.s
Comments
On Wed, 2025-09-17 at 10:22 +0800, Lulu Cai wrote: > PR ld/33427 > > Patches introduced in the GCC mainline: > > commit 8cad8f94b450be9b73d07bdeef7fa1778d3f2b96 > Author: H.J. Lu <hjl.tools@gmail.com> > Date: Fri Sep 5 15:40:51 2025 -0700 > > c: Update TLS model after processing a TLS variable > > Set a tentative TLS model in grokvardecl and update TLS mode with > the default TLS access model after a TLS variable has been fully > processed if the default TLS access model is stronger, > > triggered a linker error when building glibc using build-many-glibcs.py. > > See: https://sourceware.org/pipermail/binutils/2025-September/144225.html > > This fix uses more appropriate assertions. > > --- > Changes from v1: > - Added the bug ID > --- > bfd/elfnn-loongarch.c | 2 +- > ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 12 ++++++++++++ > ld/testsuite/ld-loongarch-elf/undefweak_le.s | 7 +++++++ > 3 files changed, 20 insertions(+), 1 deletion(-) > create mode 100644 ld/testsuite/ld-loongarch-elf/undefweak_le.s > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > index 8beb3d84079..d10f9f6bd0f 100644 > --- a/bfd/elfnn-loongarch.c > +++ b/bfd/elfnn-loongarch.c > @@ -4401,7 +4401,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, > case R_LARCH_TLS_LE_LO12_R: > case R_LARCH_TLS_LE64_LO20: > case R_LARCH_TLS_LE64_HI12: > - BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec); > + BFD_ASSERT (bfd_link_executable (info)); > > relocation += rel->r_addend; > relocation = tlsoff (info, relocation); > diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp > index a33727f2efd..5bc48b28ca8 100644 > --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp > +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp > @@ -172,6 +172,18 @@ if [istarget "loongarch64-*-*"] { > "desc-ie-norelax" \ > ] \ > ] \ > + > + run_ld_link_tests \ > + [list \ > + [list \ > + "undefind weak with tls le" \ > + "" "-e0" \ > + "" \ > + {undefweak_le.s} \ > + {} \ > + "undefweak_le" \ > + ] \ > + ] > } > > if [istarget "loongarch64-*-*"] { > diff --git a/ld/testsuite/ld-loongarch-elf/undefweak_le.s b/ld/testsuite/ld-loongarch-elf/undefweak_le.s > new file mode 100644 > index 00000000000..6e730182448 > --- /dev/null > +++ b/ld/testsuite/ld-loongarch-elf/undefweak_le.s > @@ -0,0 +1,7 @@ > +_start: > + lu12i.w $t0,%le_hi20_r(undefweak_le) > + add.d $t0,$t0,$tp,%le_add_r(undefweak_le) > + ld.d $t0,$t0,%le_lo12_r(undefweak_le) > + > + .weak undefweak_le > + .hidden undefweak_le Well, the test case: extern __thread int x [[gnu::weak]]; int main() {__builtin_printf("%p\n", &x);} seems not working on both loongarch64 and x86_64 even before the GCC and Binutils change. On loongarch64 it triggers a segfault in Glibc _dl_relocate_object_no_relro, on x86_64 the output is something like 0x7fc1f8299740 instead of (nil) that people expect for a undefweak symbol. Should the issue be fixed or should we just consider undefweak thread- local symbols invalid?
On 9/28/25 11:49 AM, Xi Ruoyao wrote: > On Wed, 2025-09-17 at 10:22 +0800, Lulu Cai wrote: >> PR ld/33427 >> >> Patches introduced in the GCC mainline: >> >> commit 8cad8f94b450be9b73d07bdeef7fa1778d3f2b96 >> Author: H.J. Lu <hjl.tools@gmail.com> >> Date: Fri Sep 5 15:40:51 2025 -0700 >> >> c: Update TLS model after processing a TLS variable >> >> Set a tentative TLS model in grokvardecl and update TLS mode with >> the default TLS access model after a TLS variable has been fully >> processed if the default TLS access model is stronger, >> >> triggered a linker error when building glibc using build-many-glibcs.py. >> >> See: https://sourceware.org/pipermail/binutils/2025-September/144225.html >> >> This fix uses more appropriate assertions. >> >> --- >> Changes from v1: >> - Added the bug ID >> --- >> bfd/elfnn-loongarch.c | 2 +- >> ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 12 ++++++++++++ >> ld/testsuite/ld-loongarch-elf/undefweak_le.s | 7 +++++++ >> 3 files changed, 20 insertions(+), 1 deletion(-) >> create mode 100644 ld/testsuite/ld-loongarch-elf/undefweak_le.s >> >> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c >> index 8beb3d84079..d10f9f6bd0f 100644 >> --- a/bfd/elfnn-loongarch.c >> +++ b/bfd/elfnn-loongarch.c >> @@ -4401,7 +4401,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, >> case R_LARCH_TLS_LE_LO12_R: >> case R_LARCH_TLS_LE64_LO20: >> case R_LARCH_TLS_LE64_HI12: >> - BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec); >> + BFD_ASSERT (bfd_link_executable (info)); >> >> relocation += rel->r_addend; >> relocation = tlsoff (info, relocation); >> diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp >> index a33727f2efd..5bc48b28ca8 100644 >> --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp >> +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp >> @@ -172,6 +172,18 @@ if [istarget "loongarch64-*-*"] { >> "desc-ie-norelax" \ >> ] \ >> ] \ >> + >> + run_ld_link_tests \ >> + [list \ >> + [list \ >> + "undefind weak with tls le" \ >> + "" "-e0" \ >> + "" \ >> + {undefweak_le.s} \ >> + {} \ >> + "undefweak_le" \ >> + ] \ >> + ] >> } >> >> if [istarget "loongarch64-*-*"] { >> diff --git a/ld/testsuite/ld-loongarch-elf/undefweak_le.s b/ld/testsuite/ld-loongarch-elf/undefweak_le.s >> new file mode 100644 >> index 00000000000..6e730182448 >> --- /dev/null >> +++ b/ld/testsuite/ld-loongarch-elf/undefweak_le.s >> @@ -0,0 +1,7 @@ >> +_start: >> + lu12i.w $t0,%le_hi20_r(undefweak_le) >> + add.d $t0,$t0,$tp,%le_add_r(undefweak_le) >> + ld.d $t0,$t0,%le_lo12_r(undefweak_le) >> + >> + .weak undefweak_le >> + .hidden undefweak_le > Well, the test case: > > extern __thread int x [[gnu::weak]]; > int main() {__builtin_printf("%p\n", &x);} > > seems not working on both loongarch64 and x86_64 even before the GCC and > Binutils change. On loongarch64 it triggers a segfault in Glibc > _dl_relocate_object_no_relro, on x86_64 the output is something like > 0x7fc1f8299740 instead of (nil) that people expect for a undefweak > symbol. > > Should the issue be fixed or should we just consider undefweak thread- > local symbols invalid? > We think this might need to be fixed; at least, it shouldn’t directly trigger a segfault. We might handle this matter later.
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 8beb3d84079..d10f9f6bd0f 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -4401,7 +4401,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, case R_LARCH_TLS_LE_LO12_R: case R_LARCH_TLS_LE64_LO20: case R_LARCH_TLS_LE64_HI12: - BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec); + BFD_ASSERT (bfd_link_executable (info)); relocation += rel->r_addend; relocation = tlsoff (info, relocation); diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index a33727f2efd..5bc48b28ca8 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -172,6 +172,18 @@ if [istarget "loongarch64-*-*"] { "desc-ie-norelax" \ ] \ ] \ + + run_ld_link_tests \ + [list \ + [list \ + "undefind weak with tls le" \ + "" "-e0" \ + "" \ + {undefweak_le.s} \ + {} \ + "undefweak_le" \ + ] \ + ] } if [istarget "loongarch64-*-*"] { diff --git a/ld/testsuite/ld-loongarch-elf/undefweak_le.s b/ld/testsuite/ld-loongarch-elf/undefweak_le.s new file mode 100644 index 00000000000..6e730182448 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/undefweak_le.s @@ -0,0 +1,7 @@ +_start: + lu12i.w $t0,%le_hi20_r(undefweak_le) + add.d $t0,$t0,$tp,%le_add_r(undefweak_le) + ld.d $t0,$t0,%le_lo12_r(undefweak_le) + + .weak undefweak_le + .hidden undefweak_le