* configure: Regenerate.
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
index 59ae522578670a28217551a2d01fa16d0e9b03a6..02d2913d3b6dc43b24527bd8e6d1e6b650044145 100644 (file)
@@ -92,9 +92,6 @@ static boolean ppc64_elf_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 
 
-/* Branch prediction bit for branch taken relocs.  */
-#define BRANCH_PREDICT_BIT 0x200000
-
 /* Mask to set RA in memory instructions.  */
 #define RA_REGISTER_MASK 0x001f0000
 
@@ -1642,6 +1639,9 @@ struct ppc_link_hash_table
   asection *sdynbss;
   asection *srelbss;
   asection *sglink;
+
+  /* Small local sym to section mapping cache.  */
+  struct sym_sec_cache sym_sec;
 };
 
 /* Get the ppc64 ELF linker hash table from a link_info structure.  */
@@ -1704,6 +1704,7 @@ ppc64_elf_link_hash_table_create (abfd)
   htab->sdynbss = NULL;
   htab->srelbss = NULL;
   htab->sglink = NULL;
+  htab->sym_sec.abfd = NULL;
 
   return &htab->elf.root;
 }
@@ -2038,6 +2039,9 @@ ppc64_elf_check_relocs (abfd, info, sec, relocs)
                      || (h->elf_link_hash_flags
                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
            {
+             struct ppc_dyn_relocs *p;
+             struct ppc_dyn_relocs **head;
+
              /* We must copy these reloc types into the output file.
                 Create a reloc section in dynobj and make room for
                 this reloc.  */
@@ -2088,35 +2092,42 @@ ppc64_elf_check_relocs (abfd, info, sec, relocs)
                 relocations we need for this symbol.  */
              if (h != NULL)
                {
-                 struct ppc_link_hash_entry *eh;
-                 struct ppc_dyn_relocs *p;
-
-                 eh = (struct ppc_link_hash_entry *) h;
-                 p = eh->dyn_relocs;
-
-                 if (p == NULL || p->sec != sec)
-                   {
-                     p = ((struct ppc_dyn_relocs *)
-                          bfd_alloc (htab->elf.dynobj,
-                                     (bfd_size_type) sizeof *p));
-                     if (p == NULL)
-                       return false;
-                     p->next = eh->dyn_relocs;
-                     eh->dyn_relocs = p;
-                     p->sec = sec;
-                     p->count = 0;
-                     p->pc_count = 0;
-                   }
-
-                 p->count += 1;
-                 if (!IS_ABSOLUTE_RELOC (r_type))
-                   p->pc_count += 1;
+                 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
                }
              else
                {
-                 /* Track dynamic relocs needed for local syms too.  */
-                 elf_section_data (sec)->local_dynrel += 1;
+                 /* Track dynamic relocs needed for local syms too.
+                    We really need local syms available to do this
+                    easily.  Oh well.  */
+
+                 asection *s;
+                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
+                                                sec, r_symndx);
+                 if (s == NULL)
+                   return false;
+
+                 head = ((struct ppc_dyn_relocs **)
+                         &elf_section_data (s)->local_dynrel);
+               }
+
+             p = *head;
+             if (p == NULL || p->sec != sec)
+               {
+                 p = ((struct ppc_dyn_relocs *)
+                      bfd_alloc (htab->elf.dynobj,
+                                 (bfd_size_type) sizeof *p));
+                 if (p == NULL)
+                   return false;
+                 p->next = *head;
+                 *head = p;
+                 p->sec = sec;
+                 p->count = 0;
+                 p->pc_count = 0;
                }
+
+             p->count += 1;
+             if (!IS_ABSOLUTE_RELOC (r_type))
+               p->pc_count += 1;
            }
          break;
 
@@ -2193,6 +2204,8 @@ ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
 
+  elf_section_data (sec)->local_dynrel = NULL;
+
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
   local_got_refcounts = elf_local_got_refcounts (abfd);
@@ -2663,7 +2676,7 @@ allocate_dynrelocs (h, inf)
          if (h->dynindx == -1
              && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
            {
-             if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+             if (! bfd_elf64_link_record_dynamic_symbol (info, h))
                return false;
            }
 
@@ -2675,7 +2688,7 @@ allocate_dynrelocs (h, inf)
 
       eh->dyn_relocs = NULL;
 
-    keep:
+    keep: ;
     }
 
   /* Finally, allocate space.  */
@@ -2762,12 +2775,26 @@ ppc64_elf_size_dynamic_sections (output_bfd, info)
 
       for (s = ibfd->sections; s != NULL; s = s->next)
        {
-         bfd_size_type count = elf_section_data (s)->local_dynrel;
+         struct ppc_dyn_relocs *p;
 
-         if (count != 0)
+         for (p = *((struct ppc_dyn_relocs **)
+                    &elf_section_data (s)->local_dynrel);
+              p != NULL;
+              p = p->next)
            {
-             srel = elf_section_data (s)->sreloc;
-             srel->_raw_size += count * sizeof (Elf64_External_Rela);
+             if (!bfd_is_abs_section (p->sec)
+                 && bfd_is_abs_section (p->sec->output_section))
+               {
+                 /* Input section has been discarded, either because
+                    it is a copy of a linkonce section or due to
+                    linker script /DISCARD/, so we'll be discarding
+                    the relocs too.  */
+               }
+             else
+               {
+                 srel = elf_section_data (p->sec)->sreloc;
+                 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
+               }
            }
        }
 
@@ -3113,9 +3140,8 @@ ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          sec = local_sections[r_symndx];
          sym_name = "<local symbol>";
 
-         relocation = (sec->output_section->vma
-                       + sec->output_offset
-                       + sym->st_value);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+         addend = rel->r_addend;
        }
       else
        {
@@ -3161,6 +3187,7 @@ ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        }
 
       /* First handle relocations that tweak non-addend part of insn.  */
+      insn = 0;
       switch (r_type)
        {
        default:
@@ -3169,22 +3196,23 @@ ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          /* Branch taken prediction relocations.  */
        case R_PPC64_ADDR14_BRTAKEN:
        case R_PPC64_REL14_BRTAKEN:
-         insn = bfd_get_32 (output_bfd, contents + offset);
-         if ((relocation - offset) & 0x8000)
-           insn &= ~BRANCH_PREDICT_BIT;
-         else
-           insn |= BRANCH_PREDICT_BIT;
-         bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
-         break;
+         insn = 0x01 << 21; /* Set 't' bit, lowest bit of BO field. */
+         /* Fall thru. */
 
-         /* Branch not taken predicition relocations.  */
+         /* Branch not taken prediction relocations.  */
        case R_PPC64_ADDR14_BRNTAKEN:
        case R_PPC64_REL14_BRNTAKEN:
-         insn = bfd_get_32 (output_bfd, contents + offset);
-         if ((relocation - offset) & 0x8000)
-           insn |= BRANCH_PREDICT_BIT;
+         insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
+         /* Set 'a' bit.  This is 0b00010 in BO field for branch on CR(BI)
+            insns (BO == 001at or 011at), and 0b01000 for branch on CTR
+            insns (BO == 1a00t or 1a01t).  */
+         if ((insn & (0x14 << 21)) == (0x04 << 21))
+           insn |= 0x02 << 21;
+         else if ((insn & (0x14 << 21)) == (0x10 << 21))
+           insn |= 0x08 << 21;
          else
-           insn &= ~BRANCH_PREDICT_BIT;
+           break;
+
          bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
          break;
 
@@ -3430,8 +3458,14 @@ ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_PPC64_UADDR32:
        case R_PPC64_UADDR64:
        case R_PPC64_TOC:
+         /* r_symndx will be zero only for relocs against symbols
+            from removed linkonce sections, or sections discarded by
+            a linker script.  */
+         if (r_symndx == 0
+             || (input_section->flags & SEC_ALLOC) == 0)
+           break;
+
          if ((info->shared
-              && (input_section->flags & SEC_ALLOC) != 0
               && (IS_ABSOLUTE_RELOC (r_type)
                   || (h != NULL
                       && h->dynindx != -1
@@ -3439,7 +3473,6 @@ ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                           || (h->elf_link_hash_flags
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
              || (!info->shared
-                 && (input_section->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && h->dynindx != -1
                  && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
This page took 0.02807 seconds and 4 git commands to generate.