]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
i386: Add GLIBC_ABI_GNU_TLS dependency only if used
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 8 Dec 2025 02:06:43 +0000 (10:06 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 10 Dec 2025 23:09:03 +0000 (07:09 +0800)
Add GLIBC_ABI_GNU_TLS version dependency only if ___tls_get_addr is
referenced by regular object.

bfd/

PR ld/33287
PR ld/33702
* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set
has_tls_get_addr_call only if referenced by regular object.

ld/

PR ld/33287
PR ld/33702
* testsuite/ld-i386/i386.exp: Run PR ld/33702 test.
* testsuite/ld-i386/no-tls.c: New file.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit d9b7ca8816e1b088122a389ff8962785f8c7b10e)

bfd/elfxx-x86.c
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/no-tls.c [new file with mode: 0644]

index 095dccbcfd6ece685aa8980e4f02996d84afbbb1..fb96dcaa1b859ae5148e9514e78d2c5b9ac875d9 100644 (file)
@@ -883,7 +883,8 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
                  elf_x86_hash_entry (h)->tls_get_addr = 1;
                }
 
-             htab->has_tls_get_addr_call = 1;
+             if (h->ref_regular)
+               htab->has_tls_get_addr_call = 1;
            }
 
          /* Pass NULL for __ehdr_start which will be defined by
index 4a657636a28157e3fd6f43610ffc5ff763021894..947c20849c949007a13bef27a5e0f0c2b6362750 100644 (file)
@@ -1516,6 +1516,7 @@ run_ld_link_tests [list \
 
 # The musl C library does not support --gnu-tls-tag nor --gnu2-tls-tag.
 if { ![istarget *-*-musl]
+     && [istarget "i?86-*-linux*"]
      && [check_compiler_available] } {
     run_cc_link_tests [list \
        [list \
@@ -1550,6 +1551,15 @@ if { ![istarget *-*-musl]
            {{readelf {-W --version-info} gnu2-tls-1b.rd}} \
            "gnu2-tls-1b.so" \
        ] \
+       [list \
+           "Build no-tls" \
+           "-Wl,--gnu-tls-tag,--gnu2-tls-tag" \
+           "" \
+           { no-tls.c } \
+           {{readelf {-W --version-info} gnu-tls-1b.rd} \
+            {readelf {-W --version-info} gnu2-tls-1b.rd}} \
+           "no-tls" \
+       ] \
     ]
 }
 
diff --git a/ld/testsuite/ld-i386/no-tls.c b/ld/testsuite/ld-i386/no-tls.c
new file mode 100644 (file)
index 0000000..a9bce4a
--- /dev/null
@@ -0,0 +1,5 @@
+int
+main ()
+{
+  return 0;
+}