daily update
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
index 1cfac82c741898de4f2ccb7ef4378595d0b1951a..2c29b571b29b9c0724d6fb5e78679888a7716b4e 100644 (file)
@@ -61,6 +61,7 @@ static bfd_vma opd_entry_value
 #define ELF_ARCH               bfd_arch_powerpc
 #define ELF_MACHINE_CODE       EM_PPC64
 #define ELF_MAXPAGESIZE                0x10000
+#define ELF_COMMONPAGESIZE     0x1000
 #define elf_info_to_howto      ppc64_elf_info_to_howto
 
 #define elf_backend_want_got_sym 0
@@ -2550,13 +2551,16 @@ struct _ppc64_elf_section_data
 static bfd_boolean
 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
 {
-  struct _ppc64_elf_section_data *sdata;
-  bfd_size_type amt = sizeof (*sdata);
+  if (!sec->used_by_bfd)
+    {
+      struct _ppc64_elf_section_data *sdata;
+      bfd_size_type amt = sizeof (*sdata);
 
-  sdata = bfd_zalloc (abfd, amt);
-  if (sdata == NULL)
-    return FALSE;
-  sec->used_by_bfd = sdata;
+      sdata = bfd_zalloc (abfd, amt);
+      if (sdata == NULL)
+       return FALSE;
+      sec->used_by_bfd = sdata;
+    }
 
   return _bfd_elf_new_section_hook (abfd, sec);
 }
@@ -2623,6 +2627,32 @@ compare_symbols (const void *ap, const void *bp)
   if (a->value + a->section->vma > b->value + b->section->vma)
     return 1;
 
+  /* For syms with the same value, prefer strong dynamic global function
+     syms over other syms.  */
+  if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
+    return -1;
+
+  if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
+    return 1;
+
+  if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
+    return -1;
+
+  if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
+    return 1;
+
+  if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
+    return -1;
+
+  if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
+    return 1;
+
+  if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
+    return -1;
+
+  if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
+    return 1;
+
   return 0;
 }
 
@@ -3464,18 +3494,21 @@ ppc64_elf_link_hash_table_create (bfd *abfd)
   if (htab == NULL)
     return NULL;
 
-  if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
+  if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
+                                     sizeof (struct ppc_link_hash_entry)))
     {
       free (htab);
       return NULL;
     }
 
   /* Init the stub hash table too.  */
-  if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
+  if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
+                           sizeof (struct ppc_stub_hash_entry)))
     return NULL;
 
   /* And the branch hash table.  */
-  if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
+  if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
+                           sizeof (struct ppc_branch_hash_entry)))
     return NULL;
 
   /* Initializing two fields of the union is just cosmetic.  We really
@@ -6693,12 +6726,22 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     {
       Elf_Internal_Sym *locsyms = NULL;
+      asection *toc = bfd_get_section_by_name (ibfd, ".toc");
+      unsigned char *toc_ref = NULL;
 
-      for (sec = ibfd->sections; sec != NULL; sec = sec->next)
+      /* Look at all the sections for this file, with TOC last.  */
+      for (sec = (ibfd->sections == toc && toc && toc->next ? toc->next
+                 : ibfd->sections);
+          sec != NULL;
+          sec = (sec == toc ? NULL
+                 : sec->next == NULL ? toc
+                 : sec->next == toc && toc->next ? toc->next
+                 : sec->next))
        if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
          {
            Elf_Internal_Rela *relstart, *rel, *relend;
            int expecting_tls_get_addr;
+           long toc_ref_index = 0;
 
            /* Read the relocations.  */
            relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
@@ -6727,6 +6770,8 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
                  err_free_rel:
                    if (elf_section_data (sec)->relocs != relstart)
                      free (relstart);
+                   if (toc_ref != NULL)
+                     free (toc_ref);
                    if (locsyms != NULL
                        && (elf_tdata (ibfd)->symtab_hdr.contents
                            != (unsigned char *) locsyms))
@@ -6834,8 +6879,12 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
                                                   rel - 1, ibfd);
                            if (retval == 0)
                              goto err_free_rel;
-                           if (toc_tls != NULL)
-                             expecting_tls_get_addr = retval > 1;
+                           if (retval > 1 && toc_tls != NULL)
+                             {
+                               expecting_tls_get_addr = 1;
+                               if (toc_ref != NULL)
+                                 toc_ref[toc_ref_index] = 1;
+                             }
                          }
 
                        if (expecting_tls_get_addr)
@@ -6853,8 +6902,40 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
                    expecting_tls_get_addr = 0;
                    continue;
 
+                 case R_PPC64_TOC16:
+                 case R_PPC64_TOC16_LO:
+                 case R_PPC64_TLS:
+                   expecting_tls_get_addr = 0;
+                   if (sym_sec == toc && toc != NULL)
+                     {
+                       /* Mark this toc entry as referenced by a TLS
+                          code sequence.  We can do that now in the
+                          case of R_PPC64_TLS, and after checking for
+                          tls_get_addr for the TOC16 relocs.  */
+                       if (toc_ref == NULL)
+                         {
+                           toc_ref = bfd_zmalloc (toc->size / 8);
+                           if (toc_ref == NULL)
+                             goto err_free_rel;
+                         }
+                       if (h != NULL)
+                         value = h->root.u.def.value;
+                       else
+                         value = sym->st_value;
+                       value += rel->r_addend;
+                       BFD_ASSERT (value < toc->size && value % 8 == 0);
+                       toc_ref_index = value / 8;
+                       if (r_type == R_PPC64_TLS)
+                         toc_ref[toc_ref_index] = 1;
+                     }
+                   continue;
+
                  case R_PPC64_TPREL64:
                    expecting_tls_get_addr = 0;
+                   if (sec != toc
+                       || toc_ref == NULL
+                       || !toc_ref[rel->r_offset / 8])
+                     continue;
                    if (ok_tprel)
                      {
                        /* IE -> LE */
@@ -6867,6 +6948,10 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
 
                  case R_PPC64_DTPMOD64:
                    expecting_tls_get_addr = 0;
+                   if (sec != toc
+                       || toc_ref == NULL
+                       || !toc_ref[rel->r_offset / 8])
+                     continue;
                    if (rel + 1 < relend
                        && (rel[1].r_info
                            == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
@@ -6945,6 +7030,9 @@ ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
              free (relstart);
          }
 
+      if (toc_ref != NULL)
+       free (toc_ref);
+
       if (locsyms != NULL
          && (elf_tdata (ibfd)->symtab_hdr.contents
              != (unsigned char *) locsyms))
@@ -7140,13 +7228,14 @@ ppc64_elf_edit_toc (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
          return FALSE;
        }
 
-      /* Now check all kept sections that might reference the toc.  */
-      for (sec = ibfd->sections;
+      /* Now check all kept sections that might reference the toc.
+        Check the toc itself last.  */
+      for (sec = (ibfd->sections == toc && toc->next ? toc->next
+                 : ibfd->sections);
           sec != NULL;
-          /* Check the toc itself last.  */
           sec = (sec == toc ? NULL
-                 : sec->next == toc && sec->next->next ? sec->next->next
                  : sec->next == NULL ? toc
+                 : sec->next == toc && toc->next ? toc->next
                  : sec->next))
        {
          int repeat;
@@ -11040,13 +11129,11 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
                                 Elf_Internal_Sym *sym)
 {
   struct ppc_link_hash_table *htab;
-  bfd *dynobj;
   struct plt_entry *ent;
   Elf_Internal_Rela rela;
   bfd_byte *loc;
 
   htab = ppc_hash_table (info);
-  dynobj = htab->elf.dynobj;
 
   for (ent = h->plt.plist; ent != NULL; ent = ent->next)
     if (ent->plt.offset != (bfd_vma) -1)
This page took 0.052646 seconds and 4 git commands to generate.