x86: Check the versioned __tls_get_addr symbol
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 20 Jan 2018 22:25:24 +0000 (14:25 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 20 Jan 2018 22:29:36 +0000 (14:29 -0800)
We need to check the versioned __tls_get_addr symbol when looking up
"__tls_get_addr".

bfd/

PR ld/22721
* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Check the
versioned __tls_get_addr symbol.

ld/

PR ld/22721
* testsuite/ld-plugin/lto.exp: Run PR ld/22721 tests.
* testsuite/ld-plugin/pr22721.t: New file.
* testsuite/ld-plugin/pr22721a.s: Likewise.
* testsuite/ld-plugin/pr22721b.c: Likewise.

bfd/ChangeLog
bfd/elfxx-x86.c
ld/ChangeLog
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr22721.t [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22721a.s [new file with mode: 0644]
ld/testsuite/ld-plugin/pr22721b.c [new file with mode: 0644]

index 13c2ea6..3d07aac 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22721
+       * elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Check the
+       versioned __tls_get_addr symbol.
+
 2018-01-19  Nick Clifton  <nickc@redhat.com>
 
        * po/fr.po: Updated French translation.
index a9ee4ba..a7db5d9 100644 (file)
@@ -856,7 +856,16 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
                                    htab->tls_get_addr,
                                    FALSE, FALSE, FALSE);
          if (h != NULL)
-           elf_x86_hash_entry (h)->tls_get_addr = 1;
+           {
+             elf_x86_hash_entry (h)->tls_get_addr = 1;
+
+             /* Check the versioned __tls_get_addr symbol.  */
+             while (h->root.type == bfd_link_hash_indirect)
+               {
+                 h = (struct elf_link_hash_entry *) h->root.u.i.link;
+                 elf_x86_hash_entry (h)->tls_get_addr = 1;
+               }
+           }
 
          /* "__ehdr_start" will be defined by linker as a hidden symbol
             later if it is referenced and not defined.  */
index 6be1624..b33714b 100644 (file)
@@ -1,3 +1,11 @@
+2018-01-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22721
+       * testsuite/ld-plugin/lto.exp: Run PR ld/22721 tests.
+       * testsuite/ld-plugin/pr22721.t: New file.
+       * testsuite/ld-plugin/pr22721a.s: Likewise.
+       * testsuite/ld-plugin/pr22721b.c: Likewise.
+
 2018-01-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-elf/group1.d: Also xfail Solaris.
index 93f9649..896f453 100644 (file)
@@ -510,6 +510,32 @@ if { [at_least_gcc_version 4 7] } {
        } {
            fail $testname
        }
+
+       run_cc_link_tests [list \
+           [list \
+               "Build pr22721a.so" \
+               "-shared -nostdlib -nostartfiles -Wl,-version-script,pr22721.t" \
+               "" \
+               {pr22721a.s} \
+               {} \
+               "pr22721a.so" \
+           ] \
+           [list \
+               "Build pr22721b.o" \
+               "$plug_opt" \
+               "-O2 -fPIC -flto $lto_no_fat" \
+               {pr22721b.c} \
+           ] \
+           [list \
+               "Build PR ld/pr22721" \
+               "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
+               -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
+               "" \
+               {dummy.c} \
+               {} \
+               "pr22721.exe"
+           ] \
+       ]
     }
     set testname "PR ld/12942 (3)"
     set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
diff --git a/ld/testsuite/ld-plugin/pr22721.t b/ld/testsuite/ld-plugin/pr22721.t
new file mode 100644 (file)
index 0000000..9269529
--- /dev/null
@@ -0,0 +1,7 @@
+SUNWprivate_1.1 {
+global:
+  __tls_get_addr;
+  ___tls_get_addr;
+local:
+  *;
+};
diff --git a/ld/testsuite/ld-plugin/pr22721a.s b/ld/testsuite/ld-plugin/pr22721a.s
new file mode 100644 (file)
index 0000000..e06079e
--- /dev/null
@@ -0,0 +1,8 @@
+       .text
+       .globl __tls_get_addr
+       .globl ___tls_get_addr
+       .type   __tls_get_addr,%function
+       .set ___tls_get_addr, __tls_get_addr
+__tls_get_addr:
+       .byte 0
+       .size   __tls_get_addr, .-__tls_get_addr
diff --git a/ld/testsuite/ld-plugin/pr22721b.c b/ld/testsuite/ld-plugin/pr22721b.c
new file mode 100644 (file)
index 0000000..ec42cdc
--- /dev/null
@@ -0,0 +1,7 @@
+__thread int foo_var = 1;
+
+int
+_start (void)
+{
+  return foo_var;
+}