This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index b84b863952fa7ffcedf089b05f029eacc59de910..6dc3effc3f14e4a47e5711b6e31e1f476432b522 100644 (file)
@@ -80,8 +80,6 @@ static boolean ppc_elf_gc_sweep_hook PARAMS ((bfd *abfd,
 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
                                                      struct elf_link_hash_entry *));
 
-static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
-
 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
 
 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
@@ -1231,7 +1229,7 @@ error_return:
 \f
 static reloc_howto_type *
 ppc_elf_reloc_type_lookup (abfd, code)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      bfd_reloc_code_real_type code;
 {
   enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
@@ -1307,7 +1305,7 @@ ppc_elf_reloc_type_lookup (abfd, code)
 
 static void
 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      arelent *cache_ptr;
      Elf32_Internal_Rela *dst;
 {
@@ -1323,13 +1321,13 @@ ppc_elf_info_to_howto (abfd, cache_ptr, dst)
 static bfd_reloc_status_type
 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
                         output_bfd, error_message)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      arelent *reloc_entry;
      asymbol *symbol;
-     PTR data;
+     PTR data ATTRIBUTE_UNUSED;
      asection *input_section;
      bfd *output_bfd;
-     char **error_message;
+     char **error_message ATTRIBUTE_UNUSED;
 {
   bfd_vma relocation;
 
@@ -1401,21 +1399,8 @@ ppc_elf_merge_private_bfd_data (ibfd, obfd)
   boolean error;
 
   /* Check if we have the same endianess */
-  if (ibfd->xvec->byteorder != obfd->xvec->byteorder
-      && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
-    {
-      const char *msg;
-
-      if (bfd_big_endian (ibfd))
-       msg = _("%s: compiled for a big endian system and target is little endian");
-      else
-       msg = _("%s: compiled for a little endian system and target is big endian");
-
-      (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
-
-      bfd_set_error (bfd_error_wrong_format);
-      return false;
-    }
+  if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
+    return false;
 
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -1523,7 +1508,7 @@ ppc_elf_section_from_shdr (abfd, hdr, name)
 
 static boolean
 ppc_elf_fake_sections (abfd, shdr, asect)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      Elf32_Internal_Shdr *shdr;
      asection *asect;
 {
@@ -1640,7 +1625,7 @@ ppc_elf_additional_program_headers (abfd)
 
 static boolean
 ppc_elf_modify_segment_map (abfd)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
 {
   return true;
 }
@@ -1880,27 +1865,6 @@ ppc_elf_adjust_dynamic_symbol (info, h)
   return true;
 }
 
-\f
-/* Increment the index of a dynamic symbol by a given amount.  Called
-   via elf_link_hash_traverse.  */
-
-static boolean
-ppc_elf_adjust_dynindx (h, cparg)
-     struct elf_link_hash_entry *h;
-     PTR cparg;
-{
-  int *cp = (int *) cparg;
-
-#ifdef DEBUG
-  fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
-#endif
-
-  if (h->dynindx != -1)
-    h->dynindx += *cp;
-
-  return true;
-}
-
 \f
 /* Set the sizes of the dynamic sections.  */
 
@@ -2035,7 +1999,7 @@ ppc_elf_size_dynamic_sections (output_bfd, info)
 
       if (strip)
        {
-         _bfd_strip_section_from_output (s);
+         _bfd_strip_section_from_output (info, s);
          continue;
        }
 
@@ -2083,43 +2047,6 @@ ppc_elf_size_dynamic_sections (output_bfd, info)
        }
     }
 
-  /* If we are generating a shared library, we generate a section
-     symbol for each output section.  These are local symbols, which
-     means that they must come first in the dynamic symbol table.
-     That means we must increment the dynamic symbol index of every
-     other dynamic symbol.
-
-     FIXME: We assume that there will never be relocations to
-     locations in linker-created sections that do not have
-     externally-visible names. Instead, we should work out precisely
-     which sections relocations are targetted at.  */
-  if (info->shared)
-    {
-      int c;
-
-      for (c = 0, s = output_bfd->sections; s != NULL; s = s->next)
-       {
-         if ((s->flags & SEC_LINKER_CREATED) != 0
-             || (s->flags & SEC_ALLOC) == 0)
-           {
-             elf_section_data (s)->dynindx = -1;
-             continue;
-           }
-
-         /* These symbols will have no names, so we don't need to
-            fiddle with dynstr_index.  */
-
-         elf_section_data (s)->dynindx = c + 1;
-
-         c++;
-       }
-
-      elf_link_hash_traverse (elf_hash_table (info),
-                             ppc_elf_adjust_dynindx,
-                             (PTR) &c);
-      elf_hash_table (info)->dynsymcount += c;
-    }
-
   return true;
 }
 
@@ -2523,7 +2450,7 @@ ppc_elf_check_relocs (abfd, info, sec, relocs)
 static asection *
 ppc_elf_gc_mark_hook (abfd, info, rel, h, sym)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      Elf_Internal_Rela *rel;
      struct elf_link_hash_entry *h;
      Elf_Internal_Sym *sym;
@@ -2570,7 +2497,7 @@ ppc_elf_gc_mark_hook (abfd, info, rel, h, sym)
 static boolean
 ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      asection *sec;
      const Elf_Internal_Rela *relocs;
 {
@@ -2600,7 +2527,7 @@ ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
            if (h->got.refcount > 0)
              h->got.refcount--;
          }
-       else
+       else if (local_got_refcounts != NULL)
          {
            if (local_got_refcounts[r_symndx] > 0)
              local_got_refcounts[r_symndx]--;
@@ -2637,8 +2564,8 @@ ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
      bfd *abfd;
      struct bfd_link_info *info;
      const Elf_Internal_Sym *sym;
-     const char **namep;
-     flagword *flagsp;
+     const char **namep ATTRIBUTE_UNUSED;
+     flagword *flagsp ATTRIBUTE_UNUSED;
      asection **secp;
      bfd_vma *valp;
 {
@@ -2924,54 +2851,6 @@ ppc_elf_finish_dynamic_sections (output_bfd, info)
       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
     }
 
-  if (info->shared)
-    {
-      asection *sdynsym;
-      asection *s;
-      Elf_Internal_Sym sym;
-      int maxdindx = 0;
-
-      /* Set up the section symbols for the output sections.  */
-
-      sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
-      BFD_ASSERT (sdynsym != NULL);
-
-      sym.st_size = 0;
-      sym.st_name = 0;
-      sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
-      sym.st_other = 0;
-
-      for (s = output_bfd->sections; s != NULL; s = s->next)
-       {
-         int indx, dindx;
-
-         sym.st_value = s->vma;
-
-         indx = elf_section_data (s)->this_idx;
-         dindx = elf_section_data (s)->dynindx;
-         if (dindx != -1)
-           {
-             BFD_ASSERT(indx > 0);
-             BFD_ASSERT(dindx > 0);
-
-             if (dindx > maxdindx)
-               maxdindx = dindx;
-
-             sym.st_shndx = indx;
-
-             bfd_elf32_swap_symbol_out (output_bfd, &sym,
-                                        (PTR) (((Elf32_External_Sym *)
-                                                sdynsym->contents)
-                                               + dindx));
-           }
-       }
-
-      /* Set the sh_info field of the output .dynsym section to the
-         index of the first global symbol.  */
-      elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
-       maxdindx + 1;
-    }
-
   return true;
 }
 
@@ -3130,6 +3009,7 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              sec = h->root.u.def.section;
              if ((r_type == R_PPC_PLT32
+                  && splt != NULL
                   && h->plt.offset != (bfd_vma) -1)
                  || (r_type == R_PPC_LOCAL24PC
                      && sec->output_section == NULL)
@@ -3146,7 +3026,14 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                      && ((! info->symbolic && h->dynindx != -1)
                          || (h->elf_link_hash_flags
                              & ELF_LINK_HASH_DEF_REGULAR) == 0)
-                     && (input_section->flags & SEC_ALLOC) != 0
+                     && ((input_section->flags & SEC_ALLOC) != 0
+                         /* Testing SEC_DEBUGGING here may be wrong.
+                             It's here to avoid a crash when
+                             generating a shared library with DWARF
+                             debugging information.  */
+                         || ((input_section->flags & SEC_DEBUGGING) != 0
+                             && (h->elf_link_hash_flags
+                                 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
                      && (r_type == R_PPC_ADDR32
                          || r_type == R_PPC_ADDR24
                          || r_type == R_PPC_ADDR16
@@ -3189,6 +3076,14 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                      obscure cases sec->output_section will be NULL.  */
                  relocation = 0;
                }
+             else if (sec->output_section == NULL)
+               {
+                  (*_bfd_error_handler)
+                    (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
+                     bfd_get_filename (input_bfd), h->root.root.string,
+                     bfd_get_section_name (input_bfd, input_section));
+                 relocation = 0;
+               }
              else
                relocation = (h->root.u.def.value
                              + sec->output_section->vma
@@ -3196,17 +3091,22 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
-         else if (info->shared && !info->symbolic && !info->no_undefined)
+         else if (info->shared && !info->symbolic
+                  && !info->no_undefined
+                  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
            {
-             (*info->callbacks->undefined_symbol)(info,
-                                                  h->root.root.string,
-                                                  input_bfd,
-                                                  input_section,
-                                                  rel->r_offset);
-             ret = false;
-             continue;
+             if (! (*info->callbacks->undefined_symbol)(info,
+                                                        h->root.root.string,
+                                                        input_bfd,
+                                                        input_section,
+                                                        rel->r_offset,
+                                                        (!info->shared
+                                                         || info->no_undefined
+                                                         || ELF_ST_VISIBILITY (h->other))))
+               return false;
+             relocation = 0;
            }
        }
 
@@ -3230,12 +3130,13 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  || h->root.type == bfd_link_hash_defweak)
              && sec->output_section == NULL)
            {
-             (*info->callbacks->undefined_symbol) (info,
-                                                   h->root.root.string,
-                                                   input_bfd,
-                                                   input_section,
-                                                   rel->r_offset);
-             ret = false;
+             if (! (*info->callbacks->undefined_symbol) (info,
+                                                         h->root.root.string,
+                                                         input_bfd,
+                                                         input_section,
+                                                         rel->r_offset,
+                                                         true))
+               return false;
              continue;
            }
          break;
@@ -3784,14 +3685,14 @@ ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                name = bfd_section_name (input_bfd, sec);
            }
 
-         (*info->callbacks->reloc_overflow)(info,
-                                            name,
-                                            howto->name,
-                                            (bfd_vma) 0,
-                                            input_bfd,
-                                            input_section,
-                                            offset);
-         ret = false;
+         if (! (*info->callbacks->reloc_overflow)(info,
+                                                  name,
+                                                  howto->name,
+                                                  (bfd_vma) 0,
+                                                  input_bfd,
+                                                  input_section,
+                                                  offset))
+           return false;
        }
       else
        ret = false;
This page took 0.031313 seconds and 4 git commands to generate.