daily update
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index e6de049abe09c33e087acb41a2297674ce5589b8..adf9d258be3d30bcd20b4e20f1eab70883d63483 100644 (file)
@@ -1,6 +1,6 @@
 /* PowerPC-specific support for 32-bit ELF
    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -25,6 +25,7 @@
    suggestions from the in-progress Embedded PowerPC ABI, and that
    information may also not match.  */
 
+#include <stdarg.h>
 #include "bfd.h"
 #include "sysdep.h"
 #include "bfdlink.h"
@@ -1708,11 +1709,14 @@ struct ppc_elf_obj_tdata
 static bfd_boolean
 ppc_elf_mkobject (bfd *abfd)
 {
-  bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
-  abfd->tdata.any = bfd_zalloc (abfd, amt);
   if (abfd->tdata.any == NULL)
-    return FALSE;
-  return TRUE;
+    {
+      bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
+      abfd->tdata.any = bfd_zalloc (abfd, amt);
+      if (abfd->tdata.any == NULL)
+       return FALSE;
+    }
+  return bfd_elf_mkobject (abfd);
 }
 
 /* Fix bad default arch selected for a 32 bit input bfd when the
@@ -1810,6 +1814,52 @@ ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   return TRUE;
 }
 
+static char *
+ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
+{
+  switch (note_type)
+    {
+    default:
+      return NULL;
+
+    case NT_PRPSINFO:
+      {
+       char data[128];
+       va_list ap;
+
+       va_start (ap, note_type);
+       memset (data, 0, 32);
+       strncpy (data + 32, va_arg (ap, const char *), 16);
+       strncpy (data + 48, va_arg (ap, const char *), 80);
+       va_end (ap);
+       return elfcore_write_note (abfd, buf, bufsiz,
+                                  "CORE", note_type, data, sizeof (data));
+      }
+
+    case NT_PRSTATUS:
+      {
+       char data[268];
+       va_list ap;
+       long pid;
+       int cursig;
+       const void *greg;
+
+       va_start (ap, note_type);
+       memset (data, 0, 72);
+       pid = va_arg (ap, long);
+       bfd_put_32 (abfd, pid, data + 24);
+       cursig = va_arg (ap, int);
+       bfd_put_16 (abfd, cursig, data + 12);
+       greg = va_arg (ap, const void *);
+       memcpy (data + 72, greg, 192);
+       memset (data + 264, 0, 4);
+       va_end (ap);
+       return elfcore_write_note (abfd, buf, bufsiz,
+                                  "CORE", note_type, data, sizeof (data));
+      }
+    }
+}
+
 /* Return address for Ith PLT stub in section PLT, for relocation REL
    or (bfd_vma) -1 if it should not be included.  */
 
@@ -1869,7 +1919,8 @@ ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
    need to bump up the number of section headers.  */
 
 static int
-ppc_elf_additional_program_headers (bfd *abfd)
+ppc_elf_additional_program_headers (bfd *abfd,
+                                   struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   asection *s;
   int ret = 0;
@@ -1892,21 +1943,21 @@ ppc_elf_additional_program_headers (bfd *abfd)
 
 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
 {
-  { ".plt",              4,  0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
-  { ".sbss",             5, -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
-  { ".sbss2",            6, -2, SHT_PROGBITS, SHF_ALLOC },
-  { ".sdata",            6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
-  { ".sdata2",           7, -2, SHT_PROGBITS, SHF_ALLOC },
-  { ".tags",             5,  0, SHT_ORDERED,  SHF_ALLOC },
-  { ".PPC.EMB.apuinfo", 16,  0, SHT_NOTE,     0 },
-  { ".PPC.EMB.sbss0",   14,  0, SHT_PROGBITS, SHF_ALLOC },
-  { ".PPC.EMB.sdata0",  15,  0, SHT_PROGBITS, SHF_ALLOC },
-  { NULL,                0,  0, 0,            0 }
+  { STRING_COMMA_LEN (".plt"),             0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
+  { STRING_COMMA_LEN (".sbss"),           -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sbss2"),          -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".sdata"),          -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sdata2"),         -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".tags"),            0, SHT_ORDERED,  SHF_ALLOC },
+  { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE,     0 },
+  { STRING_COMMA_LEN (".PPC.EMB.sbss0"),   0, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".PPC.EMB.sdata0"),  0, SHT_PROGBITS, SHF_ALLOC },
+  { NULL,                              0,  0, 0,            0 }
 };
 
 /* This is what we want for new plt/got.  */
 static struct bfd_elf_special_section ppc_alt_plt =
-  { ".plt",              4,  0, SHT_PROGBITS, SHF_ALLOC };
+  { STRING_COMMA_LEN (".plt"),             0, SHT_PROGBITS, SHF_ALLOC };
 
 static const struct bfd_elf_special_section *
 ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
@@ -2147,6 +2198,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
 
 static bfd_boolean
 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
+                      struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
                       asection *asec,
                       bfd_byte *contents ATTRIBUTE_UNUSED)
 {
@@ -2313,6 +2365,13 @@ struct ppc_elf_link_hash_entry
 
 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
 
+enum ppc_elf_plt_type {
+  PLT_UNSET,
+  PLT_OLD,
+  PLT_NEW,
+  PLT_VXWORKS
+};
+
 /* PPC ELF linker hash table.  */
 
 struct ppc_elf_link_hash_table
@@ -2349,9 +2408,11 @@ struct ppc_elf_link_hash_table
   /* Non-zero if allocating the header left a gap.  */
   unsigned int got_gap;
 
-  /* Whether to use new plt/got layout or not.  */
-  unsigned int new_plt:1;
-  unsigned int old_plt:1;
+  /* The type of PLT we have chosen to use.  */
+  enum ppc_elf_plt_type plt_type;
+
+  /* Whether we can use the new PLT layout.  */
+  unsigned int can_use_new_plt:1;
 
   /* Set if we should emit symbols for stubs.  */
   unsigned int emit_stub_syms:1;
@@ -2365,9 +2426,6 @@ struct ppc_elf_link_hash_table
   /* The .got.plt section (VxWorks only)*/
   asection *sgotplt;
 
-  /* Short-cuts to frequently used symbols on VxWorks targets.  */
-  struct elf_link_hash_entry *hplt;
-
   /* True if the target system is VxWorks.  */
   int is_vxworks;
 
@@ -2424,8 +2482,9 @@ ppc_elf_link_hash_table_create (bfd *abfd)
   if (ret == NULL)
     return NULL;
 
-  if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
-                                      ppc_elf_link_hash_newfunc))
+  if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
+                                     ppc_elf_link_hash_newfunc,
+                                     sizeof (struct ppc_elf_link_hash_entry)))
     {
       free (ret);
       return NULL;
@@ -2542,19 +2601,9 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
        return FALSE;
     }
 
-  /* Create the section for VxWorks static plt relocations.  */
-  if (htab->is_vxworks && !info->shared)
-    {
-      s = bfd_make_section (abfd, ".rela.plt.unloaded");
-      flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_READONLY
-              | SEC_LINKER_CREATED);
-      if (s == NULL
-         || ! bfd_set_section_flags (abfd, s, flags)
-         || ! bfd_set_section_alignment (abfd, s,
-                 get_elf_backend_data (abfd)->s->log_file_align))
-       return FALSE;
-      htab->srelplt2 = s;
-    }
+  if (htab->is_vxworks
+      && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
+    return FALSE;
 
   htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
   htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
@@ -2562,6 +2611,9 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
     abort ();
 
   flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
+  if (htab->plt_type == PLT_VXWORKS)
+    /* The VxWorks PLT is a loaded section with contents.  */
+    flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
   return bfd_set_section_flags (abfd, s, flags);
 }
 
@@ -2680,9 +2732,12 @@ static bfd_boolean
 is_ppc_elf_target (const struct bfd_target *targ)
 {
   extern const bfd_target bfd_elf32_powerpc_vec;
+  extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
   extern const bfd_target bfd_elf32_powerpcle_vec;
 
-  return targ == &bfd_elf32_powerpc_vec || targ == &bfd_elf32_powerpcle_vec;
+  return (targ == &bfd_elf32_powerpc_vec
+         || targ == &bfd_elf32_powerpc_vxworks_vec
+         || targ == &bfd_elf32_powerpcle_vec);
 }
 
 /* Hook called by the linker routine which adds symbols from an object
@@ -3248,7 +3303,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_REL16_LO:
        case R_PPC_REL16_HI:
        case R_PPC_REL16_HA:
-         htab->new_plt = 1;
+         htab->can_use_new_plt = 1;
          break;
 
          /* These are just markers.  */
@@ -3276,8 +3331,8 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* This refers only to functions defined in the shared library.  */
        case R_PPC_LOCAL24PC:
-         if (h && h == htab->elf.hgot)
-           htab->old_plt = 1;
+         if (h && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
+           htab->plt_type = PLT_OLD;
          break;
 
          /* This relocation describes the C++ object vtable hierarchy.
@@ -3318,7 +3373,7 @@ ppc_elf_check_relocs (bfd *abfd,
              && got2 != NULL
              && (sec->flags & SEC_CODE) != 0
              && (info->shared || info->pie)
-             && !htab->old_plt)
+             && htab->plt_type == PLT_UNSET)
            {
              /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
                 the start of a function, which assembles to a REL32
@@ -3331,9 +3386,11 @@ ppc_elf_check_relocs (bfd *abfd,
              s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
                                             r_symndx);
              if (s == got2)
-               htab->old_plt = 1;
+               htab->plt_type = PLT_OLD;
            }
-         /* fall through */
+         if (h == NULL || h == htab->elf.hgot)
+           break;
+         goto dodyn1;
 
        case R_PPC_REL24:
        case R_PPC_REL14:
@@ -3343,7 +3400,8 @@ ppc_elf_check_relocs (bfd *abfd,
            break;
          if (h == htab->elf.hgot)
            {
-             htab->old_plt = 1;
+             if (htab->plt_type == PLT_UNSET)
+               htab->plt_type = PLT_OLD;
              break;
            }
          /* fall through */
@@ -3359,6 +3417,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
+       dodyn1:
          if (h != NULL && !info->shared)
            {
              /* We may need a plt entry if the symbol turns out to be
@@ -3425,7 +3484,7 @@ ppc_elf_check_relocs (bfd *abfd,
                  if (name == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                              && strcmp (bfd_get_section_name (abfd, sec),
                                         name + 5) == 0);
 
@@ -3603,22 +3662,16 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
   flagword flags;
 
   htab = ppc_elf_hash_table (info);
-  if (force_old_plt || !htab->new_plt)
-    htab->old_plt = 1;
+
+  if (htab->plt_type == PLT_UNSET)
+    htab->plt_type = (force_old_plt || !htab->can_use_new_plt
+                     ? PLT_OLD : PLT_NEW);
 
   htab->emit_stub_syms = emit_stub_syms;
 
-  if (htab->is_vxworks)
-    {
-      /* The VxWorks PLT is a loaded section with contents.  */
-      flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED
-             | SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
+  BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
 
-      if (htab->plt != NULL
-         && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
-       return -1;
-    }
-  else if (!htab->old_plt)
+  if (htab->plt_type == PLT_NEW)
     {
       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
@@ -3640,7 +3693,7 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
          && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
        return -1;
     }
-  return !htab->old_plt;
+  return htab->plt_type == PLT_NEW;
 }
 \f
 /* Return the section that should be marked against GC for a given
@@ -3648,38 +3701,20 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
 
 static asection *
 ppc_elf_gc_mark_hook (asection *sec,
-                     struct bfd_link_info *info ATTRIBUTE_UNUSED,
+                     struct bfd_link_info *info,
                      Elf_Internal_Rela *rel,
                      struct elf_link_hash_entry *h,
                      Elf_Internal_Sym *sym)
 {
   if (h != NULL)
-    {
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       case R_PPC_GNU_VTINHERIT:
-       case R_PPC_GNU_VTENTRY:
-         break;
-
-       default:
-         switch (h->root.type)
-           {
-           case bfd_link_hash_defined:
-           case bfd_link_hash_defweak:
-             return h->root.u.def.section;
-
-           case bfd_link_hash_common:
-             return h->root.u.c.p->section;
-
-           default:
-             break;
-           }
-       }
-    }
-  else
-    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
+    switch (ELF32_R_TYPE (rel->r_info))
+      {
+      case R_PPC_GNU_VTINHERIT:
+      case R_PPC_GNU_VTENTRY:
+       return NULL;
+      }
 
-  return NULL;
+  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
 
 /* Update the got, plt and dynamic reloc reference counts for the
@@ -3828,7 +3863,7 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
   struct ppc_elf_link_hash_table *htab;
 
   htab = ppc_elf_hash_table (info);
-  if (!htab->old_plt
+  if (htab->plt_type == PLT_NEW
       && htab->plt != NULL
       && htab->plt->output_section != NULL)
     {
@@ -4272,31 +4307,32 @@ static bfd_vma
 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
 {
   bfd_vma where;
-  unsigned int max_before_header = 32768;
+  unsigned int max_before_header;
 
-  if (htab->old_plt)
-    max_before_header = 32764;
-
-  if (htab->is_vxworks)
+  if (htab->plt_type == PLT_VXWORKS)
     {
       where = htab->got->size;
       htab->got->size += need;
     }
-  else if (need <= htab->got_gap)
-    {
-      where = max_before_header - htab->got_gap;
-      htab->got_gap -= need;
-    }
   else
     {
-      if (htab->got->size + need > max_before_header
-         && htab->got->size <= max_before_header)
+      max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
+      if (need <= htab->got_gap)
        {
-         htab->got_gap = max_before_header - htab->got->size;
-         htab->got->size = max_before_header + htab->got_header_size;
+         where = max_before_header - htab->got_gap;
+         htab->got_gap -= need;
+       }
+      else
+       {
+         if (htab->got->size + need > max_before_header
+             && htab->got->size <= max_before_header)
+           {
+             htab->got_gap = max_before_header - htab->got->size;
+             htab->got->size = max_before_header + htab->got_header_size;
+           }
+         where = htab->got->size;
+         htab->got->size += need;
        }
-      where = htab->got->size;
-      htab->got->size += need;
     }
   return where;
 }
@@ -4343,7 +4379,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
              {
                asection *s = htab->plt;
 
-               if (!(htab->old_plt || htab->is_vxworks))
+               if (htab->plt_type == PLT_NEW)
                  {
                    if (!doneone)
                      {
@@ -4407,7 +4443,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                        s->size += htab->plt_entry_size;
                        /* After the 8192nd entry, room for two entries
                           is allocated.  */
-                       if (!htab->is_vxworks
+                       if (htab->plt_type == PLT_OLD
                            && (s->size - htab->plt_initial_entry_size)
                                / htab->plt_entry_size
                               > PLT_NUM_SINGLE_ENTRIES)
@@ -4421,7 +4457,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                  {
                    htab->relplt->size += sizeof (Elf32_External_Rela);
 
-                   if (htab->is_vxworks)
+                   if (htab->plt_type == PLT_VXWORKS)
                      {
                        /* Allocate space for the unloaded relocations.  */
                        if (!info->shared)
@@ -4546,20 +4582,20 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 
       /* Also discard relocs on undefined weak syms with non-default
         visibility.  */
-      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+      if (eh->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
-       eh->dyn_relocs = NULL;
-
-      /* Make sure undefined weak symbols are output as a dynamic symbol
-        in PIEs.  */
-      if (info->pie
-         && eh->dyn_relocs != NULL
-         && h->dynindx == -1
-         && h->root.type == bfd_link_hash_undefweak
-         && !h->forced_local)
        {
-         if (! bfd_elf_link_record_dynamic_symbol (info, h))
-           return FALSE;
+         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+           eh->dyn_relocs = NULL;
+
+         /* Make sure undefined weak symbols are output as a dynamic
+            symbol in PIEs.  */
+         else if (h->dynindx == -1
+                  && !h->forced_local)
+           {
+             if (! bfd_elf_link_record_dynamic_symbol (info, h))
+               return FALSE;
+           }
        }
     }
   else if (ELIMINATE_COPY_RELOCS)
@@ -4662,9 +4698,9 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
     }
 
-  if (htab->old_plt)
+  if (htab->plt_type == PLT_OLD)
     htab->got_header_size = 16;
-  else
+  else if (htab->plt_type == PLT_NEW)
     htab->got_header_size = 12;
 
   /* Set up .got offsets for local syms, and space for local dynamic
@@ -4760,29 +4796,10 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   else
     htab->tlsld_got.offset = (bfd_vma) -1;
 
-  if (htab->is_vxworks)
-    {
-      /* Save the PLT symbol in the hash table for easy access.
-        Mark GOT and PLT syms as having relocations; they might not,
-        but we won't know for sure until we build the GOT in
-        finish_dynamic_symbol.  */
-
-      if (htab->elf.hgot)
-       htab->elf.hgot->indx = -2;
-      htab->hplt = elf_link_hash_lookup (elf_hash_table (info),
-                                        "_PROCEDURE_LINKAGE_TABLE_",
-                                        FALSE, FALSE, FALSE);
-      if (htab->hplt)
-       htab->hplt->indx = -2;
-      /* If the PLT is executable then give the symbol function type.  */
-      if (htab->hplt && htab->plt->flags & SEC_CODE)
-       htab->hplt->type = STT_FUNC;
-    }
-
   /* Allocate space for global sym dynamic relocs.  */
   elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
 
-  if (htab->got != NULL && !htab->is_vxworks)
+  if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
     {
       unsigned int g_o_t = 32768;
 
@@ -4793,7 +4810,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (htab->got->size <= 32768)
        {
          g_o_t = htab->got->size;
-         if (htab->old_plt)
+         if (htab->plt_type == PLT_OLD)
            g_o_t += 4;
          htab->got->size += htab->got_header_size;
        }
@@ -4867,7 +4884,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* We'd like to strip these sections if they aren't needed, but if
             we've exported dynamic symbols from them we must leave them.
             It's too late to tell BFD to get rid of the symbols.  */
-         if ((s == htab->plt || s == htab->got) && htab->hplt != NULL)
+         if ((s == htab->plt || s == htab->got) && htab->elf.hplt != NULL)
            strip_section = FALSE;
          /* Strip this section if we don't need it; see the
             comment below.  */
@@ -4877,7 +4894,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          /* Strip these too.  */
        }
-      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
+      else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
        {
          if (s->size != 0)
            {
@@ -5129,7 +5146,7 @@ ppc_elf_relax_section (bfd *abfd,
 
              if (ent != NULL)
                {
-                 if (!htab->old_plt)
+                 if (htab->plt_type == PLT_NEW)
                    {
                      tsec = htab->glink;
                      toff = ent->glink_offset;
@@ -5198,6 +5215,10 @@ ppc_elf_relax_section (bfd *abfd,
       else if (r_type != R_PPC_PLTREL24)
        toff += irel->r_addend;
 
+      /* Attempted -shared link of non-pic code loses.  */
+      if (tsec->output_section == NULL)
+       continue;
+
       symaddr = tsec->output_section->vma + tsec->output_offset + toff;
 
       roff = irel->r_offset;
@@ -5531,6 +5552,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
   asection *got2, *sreloc = NULL;
   bfd_vma *local_got_offsets;
   bfd_boolean ret = TRUE;
+  bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
 
 #ifdef DEBUG
   _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
@@ -5542,29 +5564,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
   got2 = bfd_get_section_by_name (input_bfd, ".got2");
 
-  if (info->relocatable)
-    {
-      if (got2 == NULL)
-       return TRUE;
-
-      rel = relocs;
-      relend = relocs + input_section->reloc_count;
-      for (; rel < relend; rel++)
-       {
-         enum elf_ppc_reloc_type r_type;
-
-         r_type = ELF32_R_TYPE (rel->r_info);
-         if (r_type == R_PPC_PLTREL24
-             && rel->r_addend >= 32768)
-           {
-             /* R_PPC_PLTREL24 is rather special.  If non-zero, the
-                addend specifies the GOT pointer offset within .got2.  */
-             rel->r_addend += got2->output_offset;
-           }
-       }
-      return TRUE;
-    }
-
   /* Initialize howto table if not already done.  */
   if (!ppc_elf_howto_table[R_PPC_ADDR32])
     ppc_elf_howto_init ();
@@ -5618,6 +5617,33 @@ ppc_elf_relocate_section (bfd *output_bfd,
          sym_name = h->root.root.string;
        }
 
+      if (sec != NULL && elf_discarded_section (sec))
+       {
+         /* For relocs against symbols from removed linkonce sections,
+            or sections discarded by a linker script, we just want the
+            section contents zeroed.  Avoid any special processing.  */
+         howto = NULL;
+         if (r_type < R_PPC_max)
+           howto = ppc_elf_howto_table[r_type];
+         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+         rel->r_info = 0;
+         rel->r_addend = 0;
+         continue;
+       }
+
+      if (info->relocatable)
+       {
+         if (got2 != NULL
+             && r_type == R_PPC_PLTREL24
+             && rel->r_addend >= 32768)
+           {
+             /* R_PPC_PLTREL24 is rather special.  If non-zero, the
+                addend specifies the GOT pointer offset within .got2.  */
+             rel->r_addend += got2->output_offset;
+           }
+         continue;
+       }
+
       /* TLS optimizations.  Replace instruction sequences and relocs
         based on information we collected in tls_optimize.  We edit
         RELOCS so that --emit-relocs will output something sensible
@@ -5657,10 +5683,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
              && (tls_mask & TLS_TPREL) == 0)
            {
              bfd_vma insn;
-             insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
+             insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
              insn &= 31 << 21;
              insn |= 0x3c020000;       /* addis 0,2,0 */
-             bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
+             bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
              r_type = R_PPC_TPREL16_HA;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
            }
@@ -5704,9 +5730,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
              bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
              r_type = R_PPC_TPREL16_LO;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
+
              /* Was PPC_TLS which sits on insn boundary, now
-                PPC_TPREL16_LO which is at insn+2.  */
-             rel->r_offset += 2;
+                PPC_TPREL16_LO which is at low-order half-word.  */
+             rel->r_offset += d_offset;
            }
          break;
 
@@ -5728,7 +5755,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              else
                {
                  bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
-                 rel->r_offset -= 2;
+                 rel->r_offset -= d_offset;
                  r_type = R_PPC_NONE;
                }
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -5777,7 +5804,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  /* OK, it checks out.  Replace the call.  */
                  offset = rel[1].r_offset;
                  insn1 = bfd_get_32 (output_bfd,
-                                     contents + rel->r_offset - 2);
+                                     contents + rel->r_offset - d_offset);
                  if ((tls_mask & tls_gd) != 0)
                    {
                      /* IE */
@@ -5785,6 +5812,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      insn1 |= 32 << 26;        /* lwz */
                      insn2 = 0x7c631214;       /* add 3,3,2 */
                      rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
+                     rel[1].r_addend = 0;
                      r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
                                + R_PPC_GOT_TPREL16);
                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -5799,15 +5827,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
                          /* Was an LD reloc.  */
                          r_symndx = 0;
                          rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
-                         rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
                        }
                      r_type = R_PPC_TPREL16_HA;
                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
                      rel[1].r_info = ELF32_R_INFO (r_symndx,
                                                    R_PPC_TPREL16_LO);
-                     rel[1].r_offset += 2;
+                     rel[1].r_offset += d_offset;
+                     rel[1].r_addend = rel->r_addend;
                    }
-                 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
+                 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - d_offset);
                  bfd_put_32 (output_bfd, insn2, contents + offset);
                  if (tls_gd == 0)
                    {
@@ -6201,14 +6229,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
-         /* r_symndx will be zero only for relocs against symbols
-            from removed linkonce sections, or sections discarded by
-            a linker script.  */
        dodyn:
-         if (r_symndx == 0)
-           break;
-         /* Fall thru.  */
-
          if ((input_section->flags & SEC_ALLOC) == 0)
            break;
          /* Fall thru.  */
@@ -6250,7 +6271,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  if (name == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                              && strcmp (bfd_get_section_name (input_bfd,
                                                               input_section),
                                         name + 5) == 0);
@@ -6306,10 +6327,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
                             but ld.so expects buggy relocs.  */
                          osec = sec->output_section;
                          indx = elf_section_data (osec)->dynindx;
-                         BFD_ASSERT (indx > 0);
+                         if (indx == 0)
+                           {
+                             osec = htab->elf.text_index_section;
+                             indx = elf_section_data (osec)->dynindx;
+                           }
+                         BFD_ASSERT (indx != 0);
 #ifdef DEBUG
-                         if (indx <= 0)
-                           printf ("indx=%d section=%s flags=%08x name=%s\n",
+                         if (indx == 0)
+                           printf ("indx=%ld section=%s flags=%08x name=%s\n",
                                    indx, osec->name, osec->flags,
                                    h->root.root.string);
 #endif
@@ -6344,7 +6370,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            struct plt_entry *ent = find_plt_ent (h, got2, addend);
 
-           if (!htab->old_plt)
+           if (htab->plt_type == PLT_NEW)
              relocation = (htab->glink->output_section->vma
                            + htab->glink->output_offset
                            + ent->glink_offset);
@@ -6434,7 +6460,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              }
 
            unresolved_reloc = FALSE;
-           if (!htab->old_plt)
+           if (htab->plt_type == PLT_NEW)
              relocation = (htab->glink->output_section->vma
                            + htab->glink->output_offset
                            + ent->glink_offset);
@@ -6453,9 +6479,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (! ((strncmp (name, ".sdata", 6) == 0
+           if (! ((CONST_STRNEQ (name, ".sdata")
                    && (name[6] == 0 || name[6] == '.'))
-                  || (strncmp (name, ".sbss", 5) == 0
+                  || (CONST_STRNEQ (name, ".sbss")
                       && (name[5] == 0 || name[5] == '.'))))
              {
                (*_bfd_error_handler)
@@ -6481,8 +6507,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (! (strncmp (name, ".sdata2", 7) == 0
-                  || strncmp (name, ".sbss2", 6) == 0))
+           if (! (CONST_STRNEQ (name, ".sdata2")
+                  || CONST_STRNEQ (name, ".sbss2")))
              {
                (*_bfd_error_handler)
                  (_("%B: the target (%s) of a %s relocation is "
@@ -6513,9 +6539,9 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (((strncmp (name, ".sdata", 6) == 0
+           if (((CONST_STRNEQ (name, ".sdata")
                  && (name[6] == 0 || name[6] == '.'))
-                || (strncmp (name, ".sbss", 5) == 0
+                || (CONST_STRNEQ (name, ".sbss")
                     && (name[5] == 0 || name[5] == '.'))))
              {
                reg = 13;
@@ -6525,8 +6551,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
                           + sh->root.u.def.section->output_section->vma);
              }
 
-           else if (strncmp (name, ".sdata2", 7) == 0
-                    || strncmp (name, ".sbss2", 6) == 0)
+           else if (CONST_STRNEQ (name, ".sdata2")
+                    || CONST_STRNEQ (name, ".sbss2"))
              {
                reg = 2;
                sh = htab->sdata[1].sym;
@@ -6617,25 +6643,28 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC_ADDR16_HA:
        case R_PPC_REL16_HA:
-       case R_PPC_GOT16_HA:
-       case R_PPC_PLT16_HA:
        case R_PPC_SECTOFF_HA:
        case R_PPC_TPREL16_HA:
        case R_PPC_DTPREL16_HA:
-       case R_PPC_GOT_TLSGD16_HA:
-       case R_PPC_GOT_TLSLD16_HA:
-       case R_PPC_GOT_TPREL16_HA:
-       case R_PPC_GOT_DTPREL16_HA:
        case R_PPC_EMB_NADDR16_HA:
        case R_PPC_EMB_RELST_HA:
          /* It's just possible that this symbol is a weak symbol
             that's not actually defined anywhere.  In that case,
             'sec' would be NULL, and we should leave the symbol
             alone (it will be set to zero elsewhere in the link).  */
-         if (sec != NULL)
-           /* Add 0x10000 if sign bit in 0:15 is set.
-              Bits 0:15 are not used.  */
-           addend += 0x8000;
+         if (sec == NULL)
+           break;
+         /* Fall thru */
+
+       case R_PPC_PLT16_HA:
+       case R_PPC_GOT16_HA:
+       case R_PPC_GOT_TLSGD16_HA:
+       case R_PPC_GOT_TLSLD16_HA:
+       case R_PPC_GOT_TPREL16_HA:
+       case R_PPC_GOT_DTPREL16_HA:
+         /* Add 0x10000 if sign bit in 0:15 is set.
+            Bits 0:15 are not used.  */
+         addend += 0x8000;
          break;
        }
 
@@ -6754,20 +6783,20 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
            bfd_byte *loc;
            bfd_vma reloc_index;
 
-           if (!(htab->old_plt || htab->is_vxworks))
+           if (htab->plt_type == PLT_NEW)
              reloc_index = ent->plt.offset / 4;
            else
              {
                reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
                               / htab->plt_slot_size);
                if (reloc_index > PLT_NUM_SINGLE_ENTRIES
-                   && !htab->is_vxworks)
+                   && htab->plt_type == PLT_OLD)
                  reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
              }
 
            /* This symbol has an entry in the procedure linkage table.
               Set it up.  */
-           if (htab->is_vxworks)
+           if (htab->plt_type == PLT_VXWORKS)
              {
                bfd_vma got_offset;
                const bfd_vma *plt_entry;
@@ -6880,7 +6909,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->sgotplt->output_section->vma
                                     + htab->sgotplt->output_offset
                                     + got_offset);
-                   rela.r_info = ELF32_R_INFO (htab->hplt->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
                                                R_PPC_ADDR32);
                    rela.r_addend = ent->plt.offset + 16;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -6901,7 +6930,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                rela.r_offset = (htab->plt->output_section->vma
                                 + htab->plt->output_offset
                                 + ent->plt.offset);
-               if (htab->old_plt)
+               if (htab->plt_type == PLT_OLD)
                  {
                    /* We don't need to fill in the .plt.  The ppc dynamic
                       linker will fill it in.  */
@@ -6939,7 +6968,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
            doneone = TRUE;
          }
 
-       if (!htab->old_plt)
+       if (htab->plt_type == PLT_NEW)
          {
            bfd_vma plt;
            unsigned char *p;
@@ -7161,7 +7190,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       bfd_vma val;
 
       p += htab->elf.hgot->root.u.def.value;
-      if (htab->old_plt && !htab->is_vxworks)
+      if (htab->plt_type == PLT_OLD)
        bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
 
       val = 0;
@@ -7248,7 +7277,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
              loc += sizeof (Elf32_External_Rela);
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hplt->indx, R_PPC_ADDR32);
+             rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
            }
@@ -7448,6 +7477,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define ELF_MAXPAGESIZE                0x10000
 #endif
 #define ELF_MINPAGESIZE                0x1000
+#define ELF_COMMONPAGESIZE     0x1000
 #define elf_info_to_howto      ppc_elf_info_to_howto
 
 #ifdef  EM_CYGNUS_POWERPC
@@ -7487,6 +7517,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
 #define elf_backend_grok_prstatus              ppc_elf_grok_prstatus
 #define elf_backend_grok_psinfo                        ppc_elf_grok_psinfo
+#define elf_backend_write_core_note            ppc_elf_write_core_note
 #define elf_backend_reloc_type_class           ppc_elf_reloc_type_class
 #define elf_backend_begin_write_processing     ppc_elf_begin_write_processing
 #define elf_backend_final_write_processing     ppc_elf_final_write_processing
@@ -7494,6 +7525,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_get_sec_type_attr          ppc_elf_get_sec_type_attr
 #define elf_backend_plt_sym_val                        ppc_elf_plt_sym_val
 #define elf_backend_action_discarded           ppc_elf_action_discarded
+#define elf_backend_init_index_section         _bfd_elf_init_1_index_section
 
 #include "elf32-target.h"
 
@@ -7533,6 +7565,7 @@ ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
       struct ppc_elf_link_hash_table *htab
         = (struct ppc_elf_link_hash_table *)ret;
       htab->is_vxworks = 1;
+      htab->plt_type = PLT_VXWORKS;
       htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
       htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
       htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
@@ -7557,23 +7590,6 @@ ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
   return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
 }
 
-/* Tweak magic VxWorks symbols as they are written to the output file.  */
-static bfd_boolean
-elf_i386_vxworks_link_output_symbol_hook (struct bfd_link_info *info
-                                          ATTRIBUTE_UNUSED,
-                                        const char *name,
-                                        Elf_Internal_Sym *sym,
-                                        asection *input_sec ATTRIBUTE_UNUSED,
-                                        struct elf_link_hash_entry *h
-                                          ATTRIBUTE_UNUSED)
-{
-  /* Ignore the first dummy symbol.  */
-  if (!name)
-    return TRUE;
-
-  return elf_vxworks_link_output_symbol_hook (name, sym);
-}
-
 static void
 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
 {
@@ -7604,7 +7620,7 @@ ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
   ppc_elf_vxworks_add_symbol_hook
 #undef elf_backend_link_output_symbol_hook
 #define elf_backend_link_output_symbol_hook \
-  elf_i386_vxworks_link_output_symbol_hook
+  elf_vxworks_link_output_symbol_hook
 #undef elf_backend_final_write_processing
 #define elf_backend_final_write_processing \
   ppc_elf_vxworks_final_write_processing
This page took 0.049581 seconds and 4 git commands to generate.