MIPS/BFD: Fix TLS relocation resolution for regular executables
authorMaciej W. Rozycki <macro@mips.com>
Wed, 11 Jul 2018 16:44:45 +0000 (17:44 +0100)
committerMaciej W. Rozycki <macro@mips.com>
Wed, 11 Jul 2018 16:44:45 +0000 (17:44 +0100)
Correct an issue with commit 0f20cc3522e7 ("TLS support for MIPS"),
<https://sourceware.org/ml/binutils/2005-02/msg00607.html>, where a
condition used to determine whether to use a dynamic symbol for GD, LD
and IE TLS dynamic relocations against a symbol that has been defined
locally has been incorrectly reversed.

It's executables rather than dynamic shared objects where no symbol is
required, because such symbols cannot be preempted and therefore their
values (thread pointer offsets) are fixed at the static link time as is
the associated module ID of the main executable, so the original
condition should have been `shared' instead of `!shared'.  This wrong
condition was then later converted from `!shared' to `!bfd_link_pic',
with commit 0e1862bb401f ("Add output_type to bfd_link_info").

Use the correct `bfd_link_dll' condition then, and adjust code for the
dynamic symbol index possibly being -1 as with symbols that have been
forced local, removing unnecessary dynamic relocations from dynamic
regular executables.  PIE executables are unaffected as the existing
condition excluded them by chance due to the conversion mentioned above.

Adjust test cases accordingly.

bfd/
* elfxx-mips.c (mips_tls_got_relocs): Use `bfd_link_dll' rather
than `!bfd_link_pic' in determining the dynamic symbol index.
Avoid the index of -1.
(mips_elf_initialize_tls_slots): Likewise.  Flatten code by
moving `dyn' to the beginning of the function block.

ld/
* testsuite/ld-mips-elf/tlsdyn-o32.d: Update test for dynamic
relocation removal.
* testsuite/ld-mips-elf/tlsdyn-o32.got: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-1.d: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.

bfd/ChangeLog
bfd/elfxx-mips.c
ld/ChangeLog
ld/testsuite/ld-mips-elf/tlsdyn-o32-1.d
ld/testsuite/ld-mips-elf/tlsdyn-o32-1.got
ld/testsuite/ld-mips-elf/tlsdyn-o32-2.d
ld/testsuite/ld-mips-elf/tlsdyn-o32-2.got
ld/testsuite/ld-mips-elf/tlsdyn-o32-3.d
ld/testsuite/ld-mips-elf/tlsdyn-o32-3.got
ld/testsuite/ld-mips-elf/tlsdyn-o32.d
ld/testsuite/ld-mips-elf/tlsdyn-o32.got

index 402cdc49deb32a5a7b2565a0e07ad45e1fd5215f..d4e2c21efbaf7c186a072189b92a913bf563f048 100644 (file)
@@ -1,3 +1,11 @@
+2018-07-11  Maciej W. Rozycki  <macro@mips.com>
+
+       * elfxx-mips.c (mips_tls_got_relocs): Use `bfd_link_dll' rather
+       than `!bfd_link_pic' in determining the dynamic symbol index.
+       Avoid the index of -1.
+       (mips_elf_initialize_tls_slots): Likewise.  Flatten code by
+       moving `dyn' to the beginning of the function block.
+
 2018-07-11  Maciej W. Rozycki  <macro@mips.com>
            Rich Felker  <bugdal@aerifal.cx>
 
index a35390783b22fed07592510336b9c849ecaebe37..d91942301c3223b615c81e1b362e44452dcd7a73 100644 (file)
@@ -3251,8 +3251,10 @@ mips_tls_got_relocs (struct bfd_link_info *info, unsigned char tls_type,
   bfd_boolean need_relocs = FALSE;
   bfd_boolean dyn = elf_hash_table (info)->dynamic_sections_created;
 
-  if (h && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
-      && (!bfd_link_pic (info) || !SYMBOL_REFERENCES_LOCAL (info, h)))
+  if (h != NULL
+      && h->dynindx != -1
+      && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
+      && (bfd_link_dll (info) || !SYMBOL_REFERENCES_LOCAL (info, h)))
     indx = h->dynindx;
 
   if ((bfd_link_dll (info) || indx != 0)
@@ -3340,6 +3342,7 @@ mips_elf_initialize_tls_slots (bfd *abfd, struct bfd_link_info *info,
                               struct mips_elf_link_hash_entry *h,
                               bfd_vma value)
 {
+  bfd_boolean dyn = elf_hash_table (info)->dynamic_sections_created;
   struct mips_elf_link_hash_table *htab;
   int indx;
   asection *sreloc, *sgot;
@@ -3353,16 +3356,11 @@ mips_elf_initialize_tls_slots (bfd *abfd, struct bfd_link_info *info,
   sgot = htab->root.sgot;
 
   indx = 0;
-  if (h != NULL)
-    {
-      bfd_boolean dyn = elf_hash_table (info)->dynamic_sections_created;
-
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info),
-                                          &h->root)
-         && (!bfd_link_pic (info)
-             || !SYMBOL_REFERENCES_LOCAL (info, &h->root)))
-       indx = h->root.dynindx;
-    }
+  if (h != NULL
+      && h->root.dynindx != -1
+      && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), &h->root)
+      && (bfd_link_dll (info) || !SYMBOL_REFERENCES_LOCAL (info, &h->root)))
+    indx = h->root.dynindx;
 
   if (entry->tls_initialized)
     return;
index ea5468f7bf59cd469c529cd9304396a8a8479e96..9eb2fe072258f5899df6d8847eaa676f9ef4f470 100644 (file)
@@ -1,3 +1,15 @@
+2018-07-11  Maciej W. Rozycki  <macro@mips.com>
+
+       * testsuite/ld-mips-elf/tlsdyn-o32.d: Update test for dynamic
+       relocation removal.
+       * testsuite/ld-mips-elf/tlsdyn-o32.got: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-1.d: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
+       * testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
+
 2018-07-11  Maciej W. Rozycki  <macro@mips.com>
 
        PR ld/22570
index 17e42d01f841a6d75158b30901d99f35720b4de8..47af4530f8faf2b12a814bb39abe2101ce89a13c 100644 (file)
@@ -5,7 +5,7 @@ Disassembly of section .text:
 
 .* <__start>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7b80        addiu   gp,gp,31616
+  .*:  279c7ba0        addiu   gp,gp,31648
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
@@ -55,7 +55,7 @@ Disassembly of section .text:
 
 .* <other>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7ac0        addiu   gp,gp,31424
+  .*:  279c7ae0        addiu   gp,gp,31456
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
index 508fed2d719f416c0dd0629750660eb304d9edba..9160225056ee41e0ba8b6eeea9c3edc6146957b2 100644 (file)
@@ -4,15 +4,12 @@
 DYNAMIC RELOCATION RECORDS
 OFFSET   TYPE              VALUE 
 00000000 R_MIPS_NONE       \*ABS\*
-10000038 R_MIPS_TLS_DTPMOD32  tlsbin_gd@@Base
-1000003c R_MIPS_TLS_DTPREL32  tlsbin_gd@@Base
 1000002c R_MIPS_TLS_DTPMOD32  tlsvar_gd@VER_1
 10000030 R_MIPS_TLS_DTPREL32  tlsvar_gd@VER_1
 10000040 R_MIPS_TLS_TPREL32  tlsvar_ie@VER_1
-10000034 R_MIPS_TLS_TPREL32  tlsbin_ie@@Base
 
 
 Contents of section .got:
- 10000020 00000000 80000000 0040053c 00000000  .........@......
- 10000030 00000000 00000000 00000000 00000000  ................
+ 10000020 00000000 80000000 0040051c 00000000  .........@......
+ 10000030 00000000 ffff900c 00000001 ffff8008  ................
  10000040 00000000 00000001 00000000           ............    
index 17e42d01f841a6d75158b30901d99f35720b4de8..47af4530f8faf2b12a814bb39abe2101ce89a13c 100644 (file)
@@ -5,7 +5,7 @@ Disassembly of section .text:
 
 .* <__start>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7b80        addiu   gp,gp,31616
+  .*:  279c7ba0        addiu   gp,gp,31648
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
@@ -55,7 +55,7 @@ Disassembly of section .text:
 
 .* <other>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7ac0        addiu   gp,gp,31424
+  .*:  279c7ae0        addiu   gp,gp,31456
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
index 4a97099885dab3bc2d6a7aa73ea77de84ca7b713..c7bfec9af73d14fa86650c598c7e370bf586826e 100644 (file)
@@ -4,15 +4,12 @@
 DYNAMIC RELOCATION RECORDS
 OFFSET   TYPE              VALUE 
 00000000 R_MIPS_NONE       \*ABS\*
-10000038 R_MIPS_TLS_DTPMOD32  tlsbin_gd@@Base
-1000003c R_MIPS_TLS_DTPREL32  tlsbin_gd@@Base
 1000002c R_MIPS_TLS_DTPMOD32  tlsvar_gd@VER_1
 10000030 R_MIPS_TLS_DTPREL32  tlsvar_gd@VER_1
 10000040 R_MIPS_TLS_TPREL32  tlsvar_ie@VER_1
-10000034 R_MIPS_TLS_TPREL32  tlsbin_ie@@Base
 
 
 Contents of section .got:
- 10000020 00000000 80000000 0040053c 00000000  .*
- 10000030 00000000 00000000 00000000 00000000  .*
+ 10000020 00000000 80000000 0040051c 00000000  .*
+ 10000030 00000000 ffff900c 00000001 ffff8008  .*
  10000040 00000000 00000001 00000000           .*
index fb3750a95d6a07c92c0e323e527b80a547c80f06..db2f56c105d6b3b6b171ba3d689d0862b1b7d45b 100644 (file)
@@ -5,7 +5,7 @@ Disassembly of section .text:
 
 .* <other>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7b80        addiu   gp,gp,31616
+  .*:  279c7ba0        addiu   gp,gp,31648
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
@@ -51,7 +51,7 @@ Disassembly of section .text:
 
 .* <__start>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7ad0        addiu   gp,gp,31440
+  .*:  279c7af0        addiu   gp,gp,31472
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
index d96375cdf6efd58d4b9e65d5dffefb25bc01db18..87b54f5a1ac479fda0cae160c9865114b7516c6e 100644 (file)
@@ -4,15 +4,12 @@
 DYNAMIC RELOCATION RECORDS
 OFFSET   TYPE              VALUE 
 00000000 R_MIPS_NONE       \*ABS\*
-10000038 R_MIPS_TLS_DTPMOD32  tlsbin_gd@@Base
-1000003c R_MIPS_TLS_DTPREL32  tlsbin_gd@@Base
 1000002c R_MIPS_TLS_DTPMOD32  tlsvar_gd@VER_1
 10000030 R_MIPS_TLS_DTPREL32  tlsvar_gd@VER_1
 10000040 R_MIPS_TLS_TPREL32  tlsvar_ie@VER_1
-10000034 R_MIPS_TLS_TPREL32  tlsbin_ie@@Base
 
 
 Contents of section .got:
- 10000020 00000000 80000000 004005ec 00000000  .*
- 10000030 00000000 00000000 00000000 00000000  .*
+ 10000020 00000000 80000000 004005cc 00000000  .*
+ 10000030 00000000 ffff900c 00000001 ffff8008  .*
  10000040 00000000 00000001 00000000           .*
index e3f9ccbacf1329dec287e2c34f2f94f95ef0b46c..688721f8ca3141bf6b9534e7a488dca7417ecdae 100644 (file)
@@ -5,7 +5,7 @@ Disassembly of section .text:
 
 .* <__start>:
   .*:  3c1c0fc0        lui     gp,0xfc0
-  .*:  279c7be0        addiu   gp,gp,31712
+  .*:  279c7c00        addiu   gp,gp,31744
   .*:  0399e021        addu    gp,gp,t9
   .*:  27bdfff0        addiu   sp,sp,-16
   .*:  afbe0008        sw      s8,8\(sp\)
index 7942188441e544ad1a83d77ee10676ed7d75648e..7c8f93b52753c99bf4e8d5cf0dc0fd9cb20e9f4b 100644 (file)
@@ -4,15 +4,12 @@ tmpdir/tls-dynamic-o32:     file format elf32-tradbigmips
 DYNAMIC RELOCATION RECORDS
 OFFSET   TYPE              VALUE 
 00000000 R_MIPS_NONE       \*ABS\*
-10000044 R_MIPS_TLS_DTPMOD32  tlsbin_gd
-10000048 R_MIPS_TLS_DTPREL32  tlsbin_gd
 10000030 R_MIPS_TLS_DTPMOD32  tlsvar_gd
 10000034 R_MIPS_TLS_DTPREL32  tlsvar_gd
-1000002c R_MIPS_TLS_TPREL32  tlsbin_ie
 10000040 R_MIPS_TLS_TPREL32  tlsvar_ie
 
 
 Contents of section .got:
- 10000020 00000000 80000000 004004dc 00000000  .........@......
+ 10000020 00000000 80000000 004004bc ffff900c  .........@......
  10000030 00000000 00000000 00000001 00000000  ................
- 10000040 00000000 00000000 00000000           ............    
+ 10000040 00000000 00000001 ffff8008           ............    
This page took 0.038186 seconds and 4 git commands to generate.