bfd/
[binutils-gdb.git] / bfd / elfxx-mips.c
index b281971bc53113e00fc501bc7d1688b55c524795..3073f526d1f9b79af3778600ba9da96f50486359 100644 (file)
@@ -2982,6 +2982,10 @@ mips_elf_count_global_tls_entries (void *arg1, void *arg2)
     = (struct mips_elf_link_hash_entry *) arg1;
   struct mips_elf_count_tls_arg *arg = arg2;
 
+  if (hm->root.root.type == bfd_link_hash_indirect
+      || hm->root.root.type == bfd_link_hash_warning)
+    return 1;
+
   if (hm->tls_type & GOT_TLS_GD)
     arg->needed += 2;
   if (hm->tls_type & GOT_TLS_IE)
@@ -3000,6 +3004,10 @@ mips_elf_count_global_tls_relocs (void *arg1, void *arg2)
     = (struct mips_elf_link_hash_entry *) arg1;
   struct mips_elf_count_tls_arg *arg = arg2;
 
+  if (hm->root.root.type == bfd_link_hash_indirect
+      || hm->root.root.type == bfd_link_hash_warning)
+    return 1;
+
   arg->needed += mips_tls_got_relocs (arg->info, hm->tls_type, &hm->root);
 
   return 1;
@@ -3640,15 +3648,11 @@ mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry *h, void *data)
       break;
 
     case GGA_NORMAL:
-      BFD_ASSERT (h->tls_type == GOT_NORMAL);
-
       h->root.dynindx = --hsd->min_got_dynindx;
       hsd->low = (struct elf_link_hash_entry *) h;
       break;
 
     case GGA_RELOC_ONLY:
-      BFD_ASSERT (h->tls_type == GOT_NORMAL);
-
       if (hsd->max_unref_got_dynindx == hsd->min_got_dynindx)
        hsd->low = (struct elf_link_hash_entry *) h;
       h->root.dynindx = hsd->max_unref_got_dynindx++;
@@ -4002,8 +4006,6 @@ mips_elf_recreate_got (void **entryp, void *data)
     }
   if (*slot == NULL)
     *slot = entry;
-  else
-    free (entry);
   return 1;
 }
 
@@ -4027,8 +4029,6 @@ mips_elf_resolve_final_got_entries (struct mips_got_info *g)
       if (new_got == NULL)
        return FALSE;
 
-      /* Each entry in g->got_entries has either been copied to new_got
-        or freed.  Now delete the hash table itself.  */
       htab_delete (g->got_entries);
       g->got_entries = new_got;
     }
@@ -4279,10 +4279,10 @@ mips_elf_merge_got_with (struct mips_elf_bfd2got_hash *bfd2got,
   estimate += from->local_gotno + to->local_gotno;
   estimate += from->tls_gotno + to->tls_gotno;
 
-  /* If we're merging with the primary got, we will always have
-     the full set of global entries.  Otherwise estimate those
+  /* If we're merging with the primary got, any TLS relocations will
+     come after the full set of global entries.  Otherwise estimate those
      conservatively as well.  */
-  if (to == arg->primary)
+  if (to == arg->primary && from->tls_gotno + to->tls_gotno)
     estimate += arg->global_count;
   else
     estimate += from->global_gotno + to->global_gotno;
@@ -4696,6 +4696,7 @@ mips_elf_multi_got (bfd *abfd, struct bfd_link_info *info,
         all non-TLS entries.  */
       g->tls_assigned_gotno = g->local_gotno + g->global_gotno;
       htab_traverse (g->got_entries, mips_elf_initialize_tls_index, g);
+      BFD_ASSERT (g->tls_assigned_gotno == assign);
 
       /* Move onto the next GOT.  It will be a secondary GOT if nonull.  */
       g = gn;
@@ -8964,6 +8965,8 @@ mips_elf_lay_out_got (bfd *output_bfd, struct bfd_link_info *info)
       /* Set up TLS entries.  */
       g->tls_assigned_gotno = g->global_gotno + g->local_gotno;
       htab_traverse (g->got_entries, mips_elf_initialize_tls_index, g);
+      BFD_ASSERT (g->tls_assigned_gotno
+                 == g->global_gotno + g->local_gotno + g->tls_gotno);
 
       /* Allocate room for the TLS relocations.  */
       arg.info = info;