]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Use more appropriate assertions for the relocation of TLS LE
authorLulu Cai <cailulu@loongson.cn>
Tue, 16 Sep 2025 06:26:19 +0000 (14:26 +0800)
committercailulu <cailulu@loongson.cn>
Fri, 19 Sep 2025 02:37:21 +0000 (10:37 +0800)
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.

bfd/elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
ld/testsuite/ld-loongarch-elf/undefweak_le.s [new file with mode: 0644]

index c7b3711de86bf7ba9863871889a19baa72fd3a23..53cdb783859461ee714136b3f1518b3705dd4a25 100644 (file)
@@ -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);
index a33727f2efd83976f128615005170b5e1363d1f7..5bc48b28ca8534e458cd77952b303588fbfdb67c 100644 (file)
@@ -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 (file)
index 0000000..6e73018
--- /dev/null
@@ -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