x86-64: Set tlsdesc_plt if GOT_TLS_GDESC_P is true
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 3 Sep 2017 17:18:24 +0000 (10:18 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 3 Sep 2017 17:18:38 +0000 (10:18 -0700)
We need to set tlsdesc_plt for x86-64 if GOT_TLS_GDESC_P is true when
allocating dynamic relocations so that _bfd_x86_elf_size_dynamic_sections
will generate TLSDESC_PLT and TLSDESC_GOT in x86-64 output.

bfd/

PR ld/22071
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Set tlsdesc_plt
for x86-64 if GOT_TLS_GDESC_P is true.

ld/

PR ld/22071
* testsuite/ld-x86-64/pr22071.d: New file.
* testsuite/ld-x86-64/pr22071.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr22071.

bfd/ChangeLog
bfd/elfxx-x86.c
ld/ChangeLog
ld/testsuite/ld-x86-64/pr22071.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr22071.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 958b89d273e7ef9701fad0460275e55daef70fc2..3b3a53cf134a0d92efdd04a68bbca05217b670ed 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22071
+       * elfxx-x86.c (elf_x86_allocate_dynrelocs): Set tlsdesc_plt
+       for x86-64 if GOT_TLS_GDESC_P is true.
+
 2017-09-03  Alan Modra  <amodra@gmail.com>
 
        PR 22067
index cac451d2084b722efe842d8f1076d921f559b848..a7e9eda47f06b0ab822b1706480d9289b2bd3bab 100644 (file)
@@ -368,7 +368,11 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h,
                   || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
        htab->elf.srelgot->size += htab->sizeof_reloc;
       if (GOT_TLS_GDESC_P (tls_type))
-       htab->elf.srelplt->size += htab->sizeof_reloc;
+       {
+         htab->elf.srelplt->size += htab->sizeof_reloc;
+         if (bed->target_id == X86_64_ELF_DATA)
+           htab->tlsdesc_plt = (bfd_vma) -1;
+       }
     }
   else
     h->got.offset = (bfd_vma) -1;
index 8ff54cc85ed68ccb2e1c9f6aa91ae8eda72aa474..1fbec40dd41c20345c364c44b91de9e08eae365a 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22071
+       * testsuite/ld-x86-64/pr22071.d: New file.
+       * testsuite/ld-x86-64/pr22071.s: Likewise.
+       * testsuite/ld-x86-64/x86-64.exp: Run pr22071.
+
 2017-09-02  Alan Modra  <amodra@gmail.com>
 
        * ldlang.h (lang_input_statement_type): Expand comments.
diff --git a/ld/testsuite/ld-x86-64/pr22071.d b/ld/testsuite/ld-x86-64/pr22071.d
new file mode 100644 (file)
index 0000000..741a722
--- /dev/null
@@ -0,0 +1,8 @@
+#as: --64
+#ld: -melf_x86_64 -shared
+#readelf: -d --wide
+
+#...
+.*\(TLSDESC_PLT\).*
+.*\(TLSDESC_GOT\).*
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr22071.s b/ld/testsuite/ld-x86-64/pr22071.s
new file mode 100644 (file)
index 0000000..0e0b4e0
--- /dev/null
@@ -0,0 +1,78 @@
+       .text
+       .p2align 4,,15
+       .globl  get_ld
+       .type   get_ld, @function
+get_ld:
+       subq    $8, %rsp
+       leaq    _TLS_MODULE_BASE_@TLSDESC(%rip), %rax
+       call    *_TLS_MODULE_BASE_@TLSCALL(%rax)
+       addq    $8, %rsp
+       addq    $ld@dtpoff, %rax
+       addq    %fs:0, %rax
+       ret
+       .size   get_ld, .-get_ld
+       .p2align 4,,15
+       .globl  set_ld
+       .type   set_ld, @function
+set_ld:
+       subq    $8, %rsp
+       leaq    _TLS_MODULE_BASE_@TLSDESC(%rip), %rax
+       call    *_TLS_MODULE_BASE_@TLSCALL(%rax)
+       movl    %edi, %fs:ld@dtpoff(%rax)
+       addq    $8, %rsp
+       ret
+       .size   set_ld, .-set_ld
+       .p2align 4,,15
+       .globl  test_ld
+       .type   test_ld, @function
+test_ld:
+       subq    $8, %rsp
+       leaq    _TLS_MODULE_BASE_@TLSDESC(%rip), %rax
+       call    *_TLS_MODULE_BASE_@TLSCALL(%rax)
+       cmpl    %edi, %fs:ld@dtpoff(%rax)
+       sete    %al
+       addq    $8, %rsp
+       movzbl  %al, %eax
+       ret
+       .size   test_ld, .-test_ld
+       .p2align 4,,15
+       .globl  get_gd
+       .type   get_gd, @function
+get_gd:
+       subq    $8, %rsp
+       leaq    gd@TLSDESC(%rip), %rax
+       call    *gd@TLSCALL(%rax)
+       addq    $8, %rsp
+       addq    %fs:0, %rax
+       ret
+       .size   get_gd, .-get_gd
+       .p2align 4,,15
+       .globl  set_gd
+       .type   set_gd, @function
+set_gd:
+       subq    $8, %rsp
+       leaq    gd@TLSDESC(%rip), %rax
+       call    *gd@TLSCALL(%rax)
+       movl    %edi, %fs:(%rax)
+       addq    $8, %rsp
+       ret
+       .size   set_gd, .-set_gd
+       .p2align 4,,15
+       .globl  test_gd
+       .type   test_gd, @function
+test_gd:
+       subq    $8, %rsp
+       leaq    gd@TLSDESC(%rip), %rax
+       call    *gd@TLSCALL(%rax)
+       cmpl    %edi, %fs:(%rax)
+       sete    %al
+       addq    $8, %rsp
+       movzbl  %al, %eax
+       ret
+       .size   test_gd, .-test_gd
+       .section        .tbss,"awT",@nobits
+       .align 4
+       .type   ld, @object
+       .size   ld, 4
+ld:
+       .zero   4
index 83822dcfe9669579518931bd3acc8b6a34e2811b..46b3ec7979af42f28353c9a28d1e491f020cf390 100644 (file)
@@ -368,6 +368,7 @@ run_dump_test "property-x86-shstk5"
 run_dump_test "property-x86-shstk5-x32"
 run_dump_test "pr21884"
 run_dump_test "pr21884-nacl"
+run_dump_test "pr22071"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return