bfd/
[binutils-gdb.git] / bfd / elf32-ppc.c
index 82de7df90799c7a68badf9e33618221cc38f9e31..53412c9d6ef048fb9ce384937e110210d3d929c9 100644 (file)
@@ -2581,6 +2581,15 @@ ppc_elf_check_relocs (bfd *abfd,
   if (info->relocatable)
     return TRUE;
 
+  /* Don't do anything special with non-loaded, non-alloced sections.
+     In particular, any relocs in such sections should not affect GOT
+     and PLT reference counting (ie. we don't allow them to create GOT
+     or PLT entries), there's no possibility or desire to optimize TLS
+     relocs, and there's not much point in propagating relocs to shared
+     libs that the dynamic linker won't relocate.  */
+  if ((sec->flags & SEC_ALLOC) == 0)
+    return TRUE;
+
 #ifdef DEBUG
   _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
                      sec, abfd);
@@ -2902,7 +2911,6 @@ ppc_elf_check_relocs (bfd *abfd,
                           || !h->def_regular))))
              || (ELIMINATE_COPY_RELOCS
                  && !info->shared
-                 && (sec->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && (h->root.type == bfd_link_hash_defweak
                      || !h->def_regular)))
@@ -2941,9 +2949,8 @@ ppc_elf_check_relocs (bfd *abfd,
 
                      sreloc = bfd_make_section (htab->elf.dynobj, name);
                      flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                     if ((sec->flags & SEC_ALLOC) != 0)
-                       flags |= SEC_ALLOC | SEC_LOAD;
+                              | SEC_IN_MEMORY | SEC_LINKER_CREATED
+                              | SEC_ALLOC | SEC_LOAD);
                      if (sreloc == NULL
                          || ! bfd_set_section_flags (htab->elf.dynobj,
                                                      sreloc, flags)
@@ -3147,6 +3154,9 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
 
+  if ((sec->flags & SEC_ALLOC) == 0)
+    return TRUE;
+
   elf_section_data (sec)->local_dynrel = NULL;
 
   htab = ppc_elf_hash_table (info);
@@ -4185,8 +4195,11 @@ ppc_elf_relax_section (bfd *abfd,
 
   *again = FALSE;
 
-  /* Nothing to do if there are no relocations.  */
-  if ((isec->flags & SEC_RELOC) == 0 || isec->reloc_count == 0)
+  /* Nothing to do if there are no relocations, and no need to do
+     anything with non-alloc sections.  */
+  if ((isec->flags & SEC_ALLOC) == 0
+      || (isec->flags & SEC_RELOC) == 0
+      || isec->reloc_count == 0)
     return TRUE;
 
   trampoff = (isec->size + 3) & (bfd_vma) -4;
@@ -4545,26 +4558,6 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set SYM_NAME to VAL if the symbol exists and is undefined.  */
-
-static void
-set_linker_sym (struct ppc_elf_link_hash_table *htab,
-               const char *sym_name,
-               bfd_vma val)
-{
-  struct elf_link_hash_entry *h;
-  h = elf_link_hash_lookup (&htab->elf, sym_name, FALSE, FALSE, FALSE);
-  if (h != NULL && h->root.type == bfd_link_hash_undefined)
-    {
-      h->root.type = bfd_link_hash_defined;
-      h->root.u.def.section = bfd_abs_section_ptr;
-      h->root.u.def.value = val;
-      h->def_regular = 1;
-      h->type = STT_OBJECT;
-      h->other = STV_HIDDEN;
-    }
-}
-
 /* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
    set here rather than via PROVIDE in the default linker script,
    because using PROVIDE inside an output section statement results in
@@ -4599,19 +4592,19 @@ ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
        val = s->vma + 32768;
       lsect->sym_val = val;
 
-      set_linker_sym (htab, lsect->sym_name, val);
+      _bfd_elf_provide_symbol (info, lsect->sym_name, val);
     }
 
   s = bfd_get_section_by_name (obfd, ".sbss");
   val = 0;
   if (s != NULL)
     val = s->vma;
-  set_linker_sym (htab, "__sbss_start", val);
-  set_linker_sym (htab, "___sbss_start", val);
+  _bfd_elf_provide_symbol (info, "__sbss_start", val);
+  _bfd_elf_provide_symbol (info, "___sbss_start", val);
   if (s != NULL)
     val += s->size;
-  set_linker_sym (htab, "__sbss_end", val);
-  set_linker_sym (htab, "___sbss_end", val);
+  _bfd_elf_provide_symbol (info, "__sbss_end", val);
+  _bfd_elf_provide_symbol (info, "___sbss_end", val);
   return TRUE;
 }
 \f
@@ -4776,7 +4769,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym);
+         sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
 
          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
        }
@@ -5374,6 +5367,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
            break;
          /* Fall thru.  */
 
+         if ((input_section->flags & SEC_ALLOC) == 0)
+           break;
+         /* Fall thru.  */
+
          if ((info->shared
               && (h == NULL
                   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
@@ -5382,7 +5379,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
                   || !SYMBOL_CALLS_LOCAL (info, h)))
              || (ELIMINATE_COPY_RELOCS
                  && !info->shared
-                 && (input_section->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && h->dynindx != -1
                  && !h->non_got_ref
@@ -5806,8 +5802,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
       if (r != bfd_reloc_ok)
        {
-         if (sym_name == NULL)
-           sym_name = "(null)";
          if (r == bfd_reloc_overflow)
            {
              if (warned)