]> Git Repo - binutils.git/blobdiff - bfd/elf64-hppa.c
Include alloca-conf.h
[binutils.git] / bfd / elf64-hppa.c
index b5b9f7f3f5921f7fcc8b7ad24e0562502d438f9d..4c75c0ec7a94ebdfec2eac6e697e36fef58fa3f6 100644 (file)
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+#include "alloca-conf.h"
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
@@ -55,7 +56,7 @@ struct elf64_hppa_dyn_hash_entry
   bfd_vma opd_offset;
   bfd_vma stub_offset;
 
-  /* The symbol table entry, if any, that this was derrived from.  */
+  /* The symbol table entry, if any, that this was derived from.  */
   struct elf_link_hash_entry *h;
 
   /* The index of the (possibly local) symbol in the input bfd and its
@@ -172,8 +173,8 @@ static void elf64_hppa_dyn_hash_traverse
           PTR info));
 
 static const char *get_dyn_name
-  PARAMS ((bfd *abfd, struct elf_link_hash_entry *h,
-          const Elf_Internal_Rela *rel, char **pbuf, size_t *plen));
+  PARAMS ((asection *, struct elf_link_hash_entry *,
+          const Elf_Internal_Rela *, char **, size_t *));
 
 
 /* This must follow the definitions of the various derived linker
@@ -262,7 +263,7 @@ static boolean get_stub
 static boolean
 elf64_hppa_dyn_hash_table_init (ht, abfd, new)
      struct elf64_hppa_dyn_hash_table *ht;
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      new_hash_entry_func new;
 {
   memset (ht, 0, sizeof(*ht));
@@ -399,8 +400,8 @@ elf64_hppa_section_from_shdr (abfd, hdr, name)
    allocate memory as necessary, possibly reusing PBUF/PLEN.  */
 
 static const char *
-get_dyn_name (abfd, h, rel, pbuf, plen)
-     bfd *abfd;
+get_dyn_name (sec, h, rel, pbuf, plen)
+     asection *sec;
      struct elf_link_hash_entry *h;
      const Elf_Internal_Rela *rel;
      char **pbuf;
@@ -416,11 +417,8 @@ get_dyn_name (abfd, h, rel, pbuf, plen)
   if (h)
     nlen = strlen (h->root.root.string);
   else
-    {
-      nlen = sizeof(void*)*2 + 1 + sizeof(bfd_vma)*4 + 1 + 1;
-      nlen += 10;      /* %p slop */
-    }
-  tlen = nlen + 1 + 16 + 1;
+    nlen = 8 + 1 + sizeof (rel->r_info) * 2 - 8;
+  tlen = nlen + 1 + sizeof (rel->r_addend) * 2 + 1;
 
   len = *plen;
   buf = *pbuf;
@@ -437,11 +435,14 @@ get_dyn_name (abfd, h, rel, pbuf, plen)
   if (h)
     {
       memcpy (buf, h->root.root.string, nlen);
+      buf[nlen++] = '+';
       sprintf_vma (buf + nlen, rel->r_addend);
     }
   else
     {
-      nlen = sprintf (buf, "%p:%lx", abfd, ELF64_R_SYM (rel->r_info));
+      nlen = sprintf (buf, "%x:%lx",
+                     sec->id & 0xffffffff,
+                     (long) ELF64_R_SYM (rel->r_info));
       if (rel->r_addend)
        {
          buf[nlen++] = '+';
@@ -574,8 +575,8 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
  
   if (info->shared && hppa_info->section_syms_bfd != abfd)
     {
-      int i, highest_shndx;
-      asection *section;
+      unsigned long i;
+      int highest_shndx;
       Elf_Internal_Sym *local_syms, *isym;
       Elf64_External_Sym *ext_syms, *esym;
 
@@ -748,6 +749,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
        /* These are function calls.  Depending on their precise target we
           may need to make a stub for them.  The stub uses the PLT, so we
           need to create PLT entries for these symbols too.  */
+       case R_PARISC_PCREL12F:
        case R_PARISC_PCREL17F:
        case R_PARISC_PCREL22F:
        case R_PARISC_PCREL32:
@@ -818,7 +820,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
        continue;
 
       /* Collect a canonical name for this address.  */
-      addr_name = get_dyn_name (abfd, h, rel, &buf, &buf_len);
+      addr_name = get_dyn_name (sec, h, rel, &buf, &buf_len);
 
       /* Collect the canonical entry data for this address.  */
       dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
@@ -978,6 +980,8 @@ elf64_hppa_mark_exported_functions (h, data)
        return false;
 
       dyn_h->want_opd = 1;
+      /* Put a flag here for output_symbol_hook.  */
+      dyn_h->st_shndx = -1;
       h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
     }
 
@@ -1177,7 +1181,7 @@ elf64_hppa_post_process_headers (abfd, link_info)
 static boolean
 get_opd (abfd, info, hppa_info)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf64_hppa_link_hash_table *hppa_info;
 {
   asection *opd;
@@ -1215,7 +1219,7 @@ get_opd (abfd, info, hppa_info)
 static boolean
 get_plt (abfd, info, hppa_info)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf64_hppa_link_hash_table *hppa_info;
 {
   asection *plt;
@@ -1253,7 +1257,7 @@ get_plt (abfd, info, hppa_info)
 static boolean
 get_dlt (abfd, info, hppa_info)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf64_hppa_link_hash_table *hppa_info;
 {
   asection *dlt;
@@ -1291,7 +1295,7 @@ get_dlt (abfd, info, hppa_info)
 static boolean
 get_stub (abfd, info, hppa_info)
      bfd *abfd;
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf64_hppa_link_hash_table *hppa_info;
 {
   asection *stub;
@@ -1510,7 +1514,7 @@ allocate_dynrel_entries (dyn_h, data)
 
 static boolean
 elf64_hppa_adjust_dynamic_symbol (info, h)
-     struct bfd_link_info *info;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf_link_hash_entry *h;
 {
   /* ??? Undefined symbols with PLT entries should be re-defined
@@ -1551,7 +1555,6 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
   boolean plt;
   boolean relocs;
   boolean reltext;
-  boolean stubs;
   struct elf64_hppa_allocate_data data;
   struct elf64_hppa_link_hash_table *hppa_info;
 
@@ -1738,10 +1741,14 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
        }
 
       /* Allocate memory for the section contents if it has not
-        been allocated already.  */
+        been allocated already.  We use bfd_zalloc here in case
+        unused entries are not reclaimed before the section's
+        contents are written out.  This should not happen, but this
+        way if it does, we get a R_PARISC_NONE reloc instead of
+        garbage.  */
       if (s->contents == NULL)
        {
-         s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
+         s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
          if (s->contents == NULL && s->_raw_size != 0)
            return false;
        }
@@ -1790,6 +1797,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
        {
          if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
            return false;
+         info->flags |= DF_TEXTREL;
        }
     }
 
@@ -1807,11 +1815,11 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
 
 static boolean
 elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
      const char *name;
      Elf_Internal_Sym *sym;
-     asection *input_sec;
+     asection *input_sec ATTRIBUTE_UNUSED;
 {
   struct elf64_hppa_link_hash_table *hppa_info;
   struct elf64_hppa_dyn_hash_entry *dyn_h;
@@ -1826,9 +1834,14 @@ elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
   dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
                                      name, false, false);
 
-  /* Function symbols for which we created .opd entries were munged
-     by finish_dynamic_symbol and have to be un-munged here.  */
-  if (dyn_h && dyn_h->want_opd)
+  /* Function symbols for which we created .opd entries *may* have been
+     munged by finish_dynamic_symbol and have to be un-munged here.
+
+     Note that finish_dynamic_symbol sometimes turns dynamic symbols
+     into non-dynamic ones, so we initialize st_shndx to -1 in
+     mark_exported_functions and check to see if it was overwritten
+     here instead of just checking dyn_h->h->dynindx.  */
+  if (dyn_h && dyn_h->want_opd && dyn_h->st_shndx != -1)
     {
       /* Restore the saved value and section index.  */
       sym->st_value = dyn_h->st_value;
@@ -2038,7 +2051,6 @@ elf64_hppa_finalize_opd (dyn_h, data)
   if (info->shared && dyn_h && dyn_h->want_opd)
     {
       Elf64_Internal_Rela rel;
-      bfd_vma value;
       int dynindx;
 
       /* We may need to do a relocation against a local symbol, in
@@ -2287,8 +2299,6 @@ elf64_hppa_finalize_dynreloc (dyn_h, data)
          if (info->shared && rent->type == R_PARISC_FPTR64)
            {
              bfd_vma value, value2;
-             asymbol *sym;
-             int elf_index;
 
              /* First compute the address of the opd entry for this symbol.  */
              value = (dyn_h->opd_offset
@@ -2366,7 +2376,6 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       Elf64_External_Dyn *dyncon, *dynconend;
-      struct elf_link_hash_entry *h;
 
       BFD_ASSERT (sdyn != NULL);
 
@@ -2488,7 +2497,7 @@ static boolean
 elf64_hppa_modify_segment_map (abfd)
      bfd *abfd;
 {
-  struct elf_segment_map *m, **pm;
+  struct elf_segment_map *m;
   asection *s;
 
   s = bfd_get_section_by_name (abfd, ".interp");
@@ -2517,7 +2526,7 @@ elf64_hppa_modify_segment_map (abfd)
   for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
     if (m->p_type == PT_LOAD)
       {
-        int i;
+       unsigned int i;
 
        for (i = 0; i < m->count; i++)
          {
This page took 0.032705 seconds and 4 git commands to generate.