2000-12-14 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / bfd / elf32-hppa.c
index 37edff894f8034ea88b549d758af4e36435ebe9b..3d0c9eec9ce3e7b4b26ecca1f13e368f05255a06 100644 (file)
@@ -35,7 +35,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "elf-hppa.h"
 #include "elf32-hppa.h"
 
-
 /* In order to gain some understanding of code in this file without
    knowing all the intricate details of the linker, note the
    following:
@@ -47,7 +46,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    early in the link process, elf32_hppa_finish_dynamic_sections is
    one of the last functions.  */
 
-
 /* We use two hash tables to hold information for linking PA ELF objects.
 
    The first is the elf32_hppa_link_hash_table which is derived
@@ -120,6 +118,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define GOT_ENTRY_SIZE 4
 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
 
+static const bfd_byte plt_stub[] =
+{
+  0x0e, 0x80, 0x10, 0x96,  /* 1: ldw   0(%r20),%r22            */
+  0xea, 0xc0, 0xc0, 0x00,  /*    bv    %r0(%r22)               */
+  0x0e, 0x88, 0x10, 0x95,  /*    ldw   4(%r20),%r21            */
+#define PLT_STUB_ENTRY (3*4)
+  0xea, 0x9f, 0x1f, 0xdd,  /*    b,l   1b,%r20                 */
+  0xd6, 0x80, 0x1c, 0x1e,  /*    depi  0,31,2,%r20             */
+  0x00, 0xc0, 0xff, 0xee,  /* 9: .word fixup_func              */
+  0xde, 0xad, 0xbe, 0xef   /*    .word fixup_ltp               */
+};
+
 /* Section name for stubs is the associated section name plus this
    string.  */
 #define STUB_SUFFIX ".stub"
@@ -144,7 +154,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define RELATIVE_DYNAMIC_RELOCS 0
 #endif
 
-
 enum elf32_hppa_stub_type {
   hppa_stub_long_branch,
   hppa_stub_long_branch_shared,
@@ -154,7 +163,6 @@ enum elf32_hppa_stub_type {
   hppa_stub_none
 };
 
-
 struct elf32_hppa_stub_hash_entry {
 
   /* Base hash table entry structure.  */
@@ -186,7 +194,6 @@ struct elf32_hppa_stub_hash_entry {
   asection *id_sec;
 };
 
-
 struct elf32_hppa_link_hash_entry {
 
   struct elf_link_hash_entry elf;
@@ -228,7 +235,6 @@ struct elf32_hppa_link_hash_entry {
   unsigned int plt_abs:1;
 };
 
-
 struct elf32_hppa_link_hash_table {
 
   /* The main hash table.  */
@@ -240,9 +246,6 @@ struct elf32_hppa_link_hash_table {
   /* Linker stub bfd.  */
   bfd *stub_bfd;
 
-  /* Whether we support multiple sub-spaces for shared libs.  */
-  boolean multi_subspace;
-
   /* Linker call-backs.  */
   asection * (*add_stub_section) PARAMS ((const char *, asection *));
   void (*layout_sections_again) PARAMS ((void));
@@ -268,8 +271,18 @@ struct elf32_hppa_link_hash_table {
   asection *srelplt;
   asection *sdynbss;
   asection *srelbss;
-};
 
+  /* Whether we support multiple sub-spaces for shared libs.  */
+  unsigned int multi_subspace:1;
+
+  /* Flags set when PCREL12F and PCREL17F branches detected.  Used to
+     select suitable defaults for the stub group size.  */
+  unsigned int has_12bit_branch:1;
+  unsigned int has_17bit_branch:1;
+
+  /* Set if we need a .plt stub to support lazy dynamic linking.  */
+  unsigned int need_plt_stub:1;
+};
 
 /* Various hash macros and functions.  */
 #define hppa_link_hash_table(p) \
@@ -288,7 +301,6 @@ static struct bfd_hash_entry *hppa_link_hash_newfunc
 static struct bfd_link_hash_table *elf32_hppa_link_hash_table_create
   PARAMS ((bfd *));
 
-
 /* Stub handling functions.  */
 static char *hppa_stub_name
   PARAMS ((const asection *, const asection *,
@@ -314,7 +326,6 @@ static boolean hppa_build_one_stub
 static boolean hppa_size_one_stub
   PARAMS ((struct bfd_hash_entry *, PTR));
 
-
 /* BFD and elf backend functions.  */
 static boolean elf32_hppa_object_p PARAMS ((bfd *));
 
@@ -377,7 +388,6 @@ static boolean elf32_hppa_finish_dynamic_sections
 static int elf32_hppa_elf_get_symbol_type
   PARAMS ((Elf_Internal_Sym *, int));
 
-
 /* Assorted hash table functions.  */
 
 /* Initialize an entry in the stub hash table.  */
@@ -425,7 +435,6 @@ stub_hash_newfunc (entry, table, string)
   return (struct bfd_hash_entry *) ret;
 }
 
-
 /* Initialize an entry in the link hash table.  */
 
 static struct bfd_hash_entry *
@@ -472,7 +481,6 @@ hppa_link_hash_newfunc (entry, table, string)
   return (struct bfd_hash_entry *) ret;
 }
 
-
 /* Create the derived linker hash table.  The PA ELF port uses the derived
    hash table to keep information specific to the PA ELF linker (without
    using static variables).  */
@@ -498,7 +506,6 @@ elf32_hppa_link_hash_table_create (abfd)
     return NULL;
 
   ret->stub_bfd = NULL;
-  ret->multi_subspace = 0;
   ret->add_stub_section = NULL;
   ret->layout_sections_again = NULL;
   ret->stub_group = NULL;
@@ -508,11 +515,14 @@ elf32_hppa_link_hash_table_create (abfd)
   ret->srelplt = NULL;
   ret->sdynbss = NULL;
   ret->srelbss = NULL;
+  ret->multi_subspace = 0;
+  ret->has_12bit_branch = 0;
+  ret->has_17bit_branch = 0;
+  ret->need_plt_stub = 0;
 
   return &ret->root.root;
 }
 
-
 /* Build a name for an entry in the stub hash table.  */
 
 static char *
@@ -553,7 +563,6 @@ hppa_stub_name (input_section, sym_sec, hash, rel)
   return stub_name;
 }
 
-
 /* Look up an entry in the stub hash.  Stub entries are cached because
    creating the stub name takes a bit of time.  */
 
@@ -612,7 +621,6 @@ hppa_get_stub_entry (input_section, sym_sec, hash, rel, hplink)
   return stub_entry;
 }
 
-
 /* Add a new stub entry to the stub hash.  Not all fields of the new
    stub entry are initialised.  */
 
@@ -671,7 +679,6 @@ hppa_add_stub (stub_name, section, hplink)
   return stub_entry;
 }
 
-
 /* Determine the type of stub needed, if any, for a call.  */
 
 static enum elf32_hppa_stub_type
@@ -748,7 +755,6 @@ hppa_type_of_stub (input_sec, rel, hash, destination)
   return hppa_stub_none;
 }
 
-
 /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
    IN_ARG contains the link info pointer.  */
 
@@ -896,11 +902,11 @@ hppa_build_one_stub (gen_entry, in_arg)
                    + stub_sec->output_section->vma);
 
       bfd_put_32 (stub_bfd, (bfd_vma) BL_R1, loc);
-      val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_lsel);
+      val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_lrsel);
       insn = hppa_rebuild_insn ((int) ADDIL_R1, val, 21);
       bfd_put_32 (stub_bfd, insn, loc + 4);
 
-      val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_rsel) >> 2;
+      val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_rrsel) >> 2;
       insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17);
       bfd_put_32 (stub_bfd, insn, loc + 8);
       size = 12;
@@ -918,17 +924,22 @@ hppa_build_one_stub (gen_entry, in_arg)
       if (stub_entry->stub_type == hppa_stub_import_shared)
        insn = ADDIL_R19;
 #endif
-      val = hppa_field_adjust (sym_value, (bfd_signed_vma) 0, e_lsel),
+      val = hppa_field_adjust (sym_value, (bfd_signed_vma) 0, e_lrsel),
       insn = hppa_rebuild_insn ((int) insn, val, 21);
       bfd_put_32 (stub_bfd, insn, loc);
 
-      val = hppa_field_adjust (sym_value, (bfd_signed_vma) 0, e_rsel);
+      /* It is critical to use lrsel/rrsel here because we are using
+        two different offsets (+0 and +4) from sym_value.  If we use
+        lsel/rsel then with unfortunate sym_values we will round
+        sym_value+4 up to the next 2k block leading to a mis-match
+        between the lsel and rsel value.  */
+      val = hppa_field_adjust (sym_value, (bfd_signed_vma) 0, e_rrsel);
       insn = hppa_rebuild_insn ((int) LDW_R1_R21, val, 14);
       bfd_put_32 (stub_bfd, insn, loc + 4);
 
       if (hplink->multi_subspace)
        {
-         val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rsel);
+         val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
          insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
          bfd_put_32 (stub_bfd, insn, loc + 8);
 
@@ -942,7 +953,7 @@ hppa_build_one_stub (gen_entry, in_arg)
       else
        {
          bfd_put_32 (stub_bfd, (bfd_vma) BV_R0_R21, loc + 8);
-         val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rsel);
+         val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
          insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
          bfd_put_32 (stub_bfd, insn, loc + 12);
 
@@ -1054,7 +1065,6 @@ hppa_build_one_stub (gen_entry, in_arg)
 #undef LDSID_RP_R1
 #undef BE_SR0_RP
 
-
 /* As above, but don't actually build the stub.  Just bump offset so
    we know stub section sizes.  */
 
@@ -1095,7 +1105,6 @@ hppa_size_one_stub (gen_entry, in_arg)
   return true;
 }
 
-
 /* Return nonzero if ABFD represents an HPPA ELF32 file.
    Additionally we set the default architecture and machine.  */
 
@@ -1119,7 +1128,6 @@ elf32_hppa_object_p (abfd)
   return true;
 }
 
-
 /* Undo the generic ELF code's subtraction of section->vma from the
    value of each external symbol.  */
 
@@ -1137,7 +1145,6 @@ elf32_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
   return true;
 }
 
-
 /* Create the .plt and .got sections, and set up our hash table
    short-cuts to various dynamic sections.  */
 
@@ -1146,8 +1153,6 @@ elf32_hppa_create_dynamic_sections (abfd, info)
      bfd *abfd;
      struct bfd_link_info *info;
 {
-  flagword flags;
-  asection *s;
   struct elf32_hppa_link_hash_table *hplink;
 
   /* Don't try to create the .plt and .got twice.  */
@@ -1159,14 +1164,7 @@ elf32_hppa_create_dynamic_sections (abfd, info)
   if (! _bfd_elf_create_dynamic_sections (abfd, info))
     return false;
 
-  /* Our .plt just contains pointers.  I suppose we should be using
-     .plt.got but .plt.got doesn't make too much sense without a .plt
-     section.  Set the flags to say the .plt isn't executable.  */
-  s = bfd_get_section_by_name (abfd, ".plt");
-  flags = bfd_get_section_flags (abfd, s);
-  if (! bfd_set_section_flags (abfd, s, flags & ~SEC_CODE))
-    return false;
-  hplink->splt = s;
+  hplink->splt = bfd_get_section_by_name (abfd, ".plt");
   hplink->srelplt = bfd_get_section_by_name (abfd, ".rela.plt");
 
   hplink->sgot = bfd_get_section_by_name (abfd, ".got");
@@ -1188,7 +1186,6 @@ elf32_hppa_create_dynamic_sections (abfd, info)
   return true;
 }
 
-
 /* Look through the relocs for a section during the first phase, and
    allocate space in the global offset table or procedure linkage
    table.  At this point we haven't necessarily read all the input
@@ -1278,11 +1275,15 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
          break;
 
        case R_PARISC_PCREL12F:
+         hplink->has_12bit_branch = 1;
+         /* Fall thru.  */
        case R_PARISC_PCREL17C:
        case R_PARISC_PCREL17F:
+         hplink->has_17bit_branch = 1;
+         /* Fall thru.  */
        case R_PARISC_PCREL22F:
-         /* Handle calls, and function pointers as they might need to
-            go through the .plt, and might require long branch stubs.  */
+         /* Function calls might need to go through the .plt, and
+            might require long branch stubs.  */
          if (h == NULL)
            {
              /* We know local syms won't need a .plt entry, and if
@@ -1329,7 +1330,8 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
 
        case R_PARISC_DIR17F: /* Used for external branches.  */
        case R_PARISC_DIR17R:
-       case R_PARISC_DIR14R: /* Used for load/store from absolute locn.  */
+       case R_PARISC_DIR14F: /* Used for load/store from absolute locn.  */
+       case R_PARISC_DIR14R:
        case R_PARISC_DIR21L: /* As above, and for ext branches too.  */
 #if 1
          /* Help debug shared library creation.  Any of the above
@@ -1362,7 +1364,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
             used.  Record for later use during GC.  */
        case R_PARISC_GNU_VTENTRY:
          if (!_bfd_elf32_gc_record_vtentry (abfd, sec,
-                                            &h->elf, rel->r_offset))
+                                            &h->elf, rel->r_addend))
            return false;
          continue;
 
@@ -1465,10 +1467,9 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                  else
                    h->elf.plt.refcount += 1;
 
-                 /* If this .plt entry is for a plabel, we need an
-                    extra word for ld.so.  adjust_dynamic_symbol will
-                    also keep the entry even if it appears to be
-                    local.  */
+                 /* If this .plt entry is for a plabel, mark it so
+                    that adjust_dynamic_symbol will keep the entry
+                    even if it appears to be local.  */
                  if (need_entry & PLT_PLABEL)
                    h->plabel = 1;
                }
@@ -1537,8 +1538,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                  || is_absolute_reloc (r_type)
                  || (h != NULL
                      && ((h->elf.elf_link_hash_flags
-                          & ELF_LINK_HASH_DEF_REGULAR) == 0
-                         || h->elf.root.type == bfd_link_hash_defweak)))
+                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
 #endif
              )
            {
@@ -1674,7 +1674,6 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
   return true;
 }
 
-
 /* Return the section that should be marked against garbage collection
    for a given relocation.  */
 
@@ -1723,7 +1722,6 @@ elf32_hppa_gc_mark_hook (abfd, info, rel, h, sym)
   return NULL;
 }
 
-
 /* Update the got and plt entry reference counts for the section being
    removed.  */
 
@@ -1833,7 +1831,6 @@ elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
   return true;
 }
 
-
 /* Our own version of hide_symbol, so that we can keep plt entries for
    plabels.  */
 
@@ -1850,7 +1847,6 @@ elf32_hppa_hide_symbol (info, h)
     }
 }
 
-
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
    dynamic object, but we're not including those sections.  We have to
@@ -1933,6 +1929,8 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
          /* We also need to make an entry in the .rela.plt section.  */
          s = hplink->srelplt;
          s->_raw_size += sizeof (Elf32_External_Rela);
+
+         hplink->need_plt_stub = 1;
        }
       return true;
     }
@@ -2017,7 +2015,6 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
   return true;
 }
 
-
 /* Called via elf_link_hash_traverse to create .plt entries for an
    application that uses statically linked PIC functions.  Similar to
    the first part of elf32_hppa_adjust_dynamic_symbol.  */
@@ -2057,7 +2054,6 @@ hppa_handle_PIC_calls (h, inf)
   return true;
 }
 
-
 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
      || RELATIVE_DYNAMIC_RELOCS)
 /* This function is called via elf_link_hash_traverse to discard space
@@ -2096,7 +2092,7 @@ hppa_discard_copies (h, inf)
      any relocs.  */
   if (eh->elf.dynindx == -1
       || ((eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-         && eh->elf.root.type != bfd_link_hash_defweak
+         && !is_absolute_reloc (r_type)
          && info->symbolic))
     {
       for (s = eh->reloc_entries; s != NULL; s = s->next)
@@ -2108,7 +2104,6 @@ hppa_discard_copies (h, inf)
 }
 #endif
 
-
 /* This function is called via elf_link_hash_traverse to force
    millicode symbols local so they do not end up as globals in the
    dynamic symbol table.  We ought to be able to do this in
@@ -2128,7 +2123,6 @@ clobber_millicode_symbols (h, info)
   return true;
 }
 
-
 /* Set the sizes of the dynamic sections.  */
 
 static boolean
@@ -2174,7 +2168,7 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
            {
              struct elf_link_hash_entry *h;
 
-             h = elf_link_hash_lookup (&hplink->root, 
+             h = elf_link_hash_lookup (&hplink->root,
                                        funcname,
                                        false, false, false);
              if (h != NULL
@@ -2296,28 +2290,22 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
          if (s->_raw_size != 0)
            {
              asection *target;
+             const char *outname;
 
              /* Remember whether there are any reloc sections other
                 than .rela.plt.  */
              if (strcmp (name+5, ".plt") != 0)
-               {
-                 const char *outname;
-
-                 relocs = true;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  The entries in the .rela.plt section
-                    really apply to the .got section, which we
-                    created ourselves and so know is not readonly.  */
-                 outname = bfd_get_section_name (output_bfd,
-                                                 s->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 5);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = true;
-               }
+               relocs = true;
+
+             /* If this relocation section applies to a read only
+                section, then we probably need a DT_TEXTREL entry.  */
+             outname = bfd_get_section_name (output_bfd,
+                                             s->output_section);
+             target = bfd_get_section_by_name (output_bfd, outname + 5);
+             if (target != NULL
+                 && (target->flags & SEC_READONLY) != 0
+                 && (target->flags & SEC_ALLOC) != 0)
+               reltext = true;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -2325,7 +2313,22 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
            }
        }
       else if (strcmp (name, ".plt") == 0)
-       ;
+       {
+         if (hplink->need_plt_stub)
+           {
+             /* Make space for the plt stub at the end of the .plt
+                section.  We want this stub right at the end, up
+                against the .got section.  */
+             int gotalign = bfd_section_alignment (dynobj, hplink->sgot);
+             int pltalign = bfd_section_alignment (dynobj, s);
+             bfd_size_type mask;
+
+             if (gotalign > pltalign)
+               bfd_set_section_alignment (dynobj, s, gotalign);
+             mask = ((bfd_size_type) 1 << gotalign) - 1;
+             s->_raw_size = (s->_raw_size + sizeof (plt_stub) + mask) & ~mask;
+           }
+       }
       else if (strcmp (name, ".got") == 0)
        ;
       else
@@ -2404,7 +2407,6 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
   return true;
 }
 
-
 /* External entry points for sizing and building linker stubs.  */
 
 /* Determine and set the size of the stub section for a final link.
@@ -2414,12 +2416,13 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
    instruction.  */
 
 boolean
-elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
+elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
                       add_stub_section, layout_sections_again)
      bfd *output_bfd;
      bfd *stub_bfd;
      struct bfd_link_info *info;
      boolean multi_subspace;
+     bfd_signed_vma group_size;
      asection * (*add_stub_section) PARAMS ((const char *, asection *));
      void (*layout_sections_again) PARAMS ((void));
 {
@@ -2430,6 +2433,8 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
   unsigned int bfd_indx, bfd_count;
   int top_id, top_index;
   struct elf32_hppa_link_hash_table *hplink;
+  bfd_size_type stub_group_size;
+  boolean stubs_always_before_branch;
   boolean stub_changed = 0;
   boolean ret = 0;
 
@@ -2440,8 +2445,22 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
   hplink->multi_subspace = multi_subspace;
   hplink->add_stub_section = add_stub_section;
   hplink->layout_sections_again = layout_sections_again;
+  stubs_always_before_branch = group_size < 0;
+  if (group_size < 0)
+    stub_group_size = -group_size;
+  else
+    stub_group_size = group_size;
+  if (stub_group_size == 1)
+    {
+      /* Default values.  */
+      stub_group_size = 8000000;
+      if (hplink->has_17bit_branch || hplink->multi_subspace)
+       stub_group_size = 250000;
+      if (hplink->has_12bit_branch)
+       stub_group_size = 7812;
+    }
 
-  /* Count the number of input BFDs and find the top section id.  */
+  /* Count the number of input BFDs and find the top input section id.  */
   for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
        input_bfd != NULL;
        input_bfd = input_bfd->link_next)
@@ -2461,11 +2480,12 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
   if (hplink->stub_group == NULL)
     return false;
 
-  /* Now make a list of input sections for each output section.
-     We can't use output_bfd->section_count here as some sections may
-     have been removed, and _bfd_strip_section_from_output doesn't
-     renumber the indices.  Sections may also be re-ordered, so the
-     last section index isn't necessarily the biggest.  */
+  /* Make a list of input sections for each output section included in
+     the link.
+
+     We can't use output_bfd->section_count here to find the top output
+     section index as some sections may have been removed, and
+     _bfd_strip_section_from_output doesn't renumber the indices.  */
   for (section = output_bfd->sections, top_index = 0;
        section != NULL;
        section = section->next)
@@ -2473,11 +2493,28 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
       if (top_index < section->index)
        top_index = section->index;
     }
+
   input_list
-    = (asection **) bfd_zmalloc (sizeof (asection *) * (top_index + 1));
+    = (asection **) bfd_malloc (sizeof (asection *) * (top_index + 1));
   if (input_list == NULL)
     return false;
 
+  /* For sections we aren't interested in, mark their entries with a
+     value we can check later.  */
+  list = input_list + top_index;
+  do
+    *list = bfd_abs_section_ptr;
+  while (list-- != input_list);
+
+  for (section = output_bfd->sections;
+       section != NULL;
+       section = section->next)
+    {
+      if ((section->flags & SEC_CODE) != 0)
+       input_list[section->index] = NULL;
+    }
+
+  /* Now actually build the lists.  */
   for (input_bfd = info->input_bfds;
        input_bfd != NULL;
        input_bfd = input_bfd->link_next)
@@ -2487,15 +2524,19 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
           section = section->next)
        {
          if (section->output_section != NULL
-             && section->output_section->owner == output_bfd)
+             && section->output_section->owner == output_bfd
+             && section->output_section->index <= top_index)
            {
              list = input_list + section->output_section->index;
-             /* Steal the link_sec pointer for our list.  */
+             if (*list != bfd_abs_section_ptr)
+               {
+                 /* Steal the link_sec pointer for our list.  */
 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
-             /* This happens to make the list in reverse order, which
-                is what we want.  */
-             PREV_SEC (section) = *list;
-             *list = section;
+                 /* This happens to make the list in reverse order,
+                    which is what we want.  */
+                 PREV_SEC (section) = *list;
+                 *list = section;
+               }
            }
        }
     }
@@ -2506,10 +2547,12 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
      .fini output sections respectively, because glibc splits the
      _init and _fini functions into multiple parts.  Putting a stub in
      the middle of a function is not a good idea.  */
-  list = input_list + output_bfd->section_count;
-  while (list-- != input_list)
+  list = input_list + top_index;
+  do
     {
       asection *tail = *list;
+      if (tail == bfd_abs_section_ptr)
+       continue;
       while (tail != NULL)
        {
          asection *curr;
@@ -2523,7 +2566,7 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
            total = tail->_raw_size;
          while ((prev = PREV_SEC (curr)) != NULL
                 && ((total += curr->output_offset - prev->output_offset)
-                    < 250000))
+                    < stub_group_size))
            curr = prev;
 
          /* OK, the size from the start of CURR to the end is less
@@ -2547,19 +2590,24 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
 
          /* But wait, there's more!  Input sections up to 250000
             bytes before the stub section can be handled by it too.  */
-         total = 0;
-         while (prev != NULL
-                && ((total += tail->output_offset - prev->output_offset)
-                    < 250000))
+         if (!stubs_always_before_branch)
            {
-             tail = prev;
-             prev = PREV_SEC (tail);
-             hplink->stub_group[tail->id].link_sec = curr;
+             total = 0;
+             while (prev != NULL
+                    && ((total += tail->output_offset - prev->output_offset)
+                        < stub_group_size))
+               {
+                 tail = prev;
+                 prev = PREV_SEC (tail);
+                 hplink->stub_group[tail->id].link_sec = curr;
+               }
            }
          tail = prev;
        }
     }
+  while (list-- != input_list);
   free (input_list);
+#undef PREV_SEC
 
   /* We want to read in symbol extension records only once.  To do this
      we need to read in the local symbols in parallel and save them for
@@ -2989,7 +3037,6 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace,
   return ret;
 }
 
-
 /* For a final link, this function is called after we have sized the
    stubs to provide a value for __gp.  */
 
@@ -3059,7 +3106,6 @@ elf32_hppa_set_gp (abfd, info)
   return true;
 }
 
-
 /* Build all the stubs associated with the current output file.  The
    stubs are kept in a hash table attached to the main linker hash
    table.  We also set up the .plt entries for statically linked PIC
@@ -3098,7 +3144,6 @@ elf32_hppa_build_stubs (info)
   return true;
 }
 
-
 /* Perform a relocation as part of a final link.  */
 
 static bfd_reloc_status_type
@@ -3231,6 +3276,7 @@ final_link_relocate (input_section, contents, rel, value, hplink, sym_sec, h)
   switch (r_type)
     {
     case R_PARISC_DIR32:
+    case R_PARISC_DIR14F:
     case R_PARISC_DIR17F:
     case R_PARISC_PCREL17C:
     case R_PARISC_PCREL14F:
@@ -3350,7 +3396,6 @@ final_link_relocate (input_section, contents, rel, value, hplink, sym_sec, h)
   return bfd_reloc_ok;
 }
 
-
 /* Relocate an HPPA ELF section.  */
 
 static boolean
@@ -3663,6 +3708,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_PARISC_DIR17F:
        case R_PARISC_DIR17R:
+       case R_PARISC_DIR14F:
        case R_PARISC_DIR14R:
        case R_PARISC_DIR21L:
        case R_PARISC_DPREL14F:
@@ -3681,7 +3727,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
              && (is_absolute_reloc (r_type)
                  || ((!info->symbolic
                       || (h != NULL
-                          && ((h->elf.elf_link_hash_flags 
+                          && ((h->elf.elf_link_hash_flags
                                & ELF_LINK_HASH_DEF_REGULAR) == 0
                               || h->elf.root.type == bfd_link_hash_defweak)))
                      && (h == NULL || h->elf.dynindx != -1)))
@@ -3826,7 +3872,6 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
   return true;
 }
 
-
 /* Finish up dynamic symbol handling.  We set the contents of various
    dynamic sections here.  */
 
@@ -3846,7 +3891,6 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
   if (h->plt.offset != (bfd_vma) -1)
     {
       bfd_vma value;
-      Elf_Internal_Rela rel;
 
       /* This symbol has an entry in the procedure linkage table.  Set
         it up.
@@ -3854,15 +3898,7 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
         The format of a plt entry is
         <funcaddr>
         <__gp>
-        <used by ld.so>
-
-        The last field is present only for plt entries that are used
-        by global plabels.  */
-
-      /* We do not actually care about the value in the PLT entry if
-        we are creating a shared library and the symbol is still
-        undefined;  We create a dynamic relocation to fill in the
-        correct value.  */
+      */
       value = 0;
       if (h->root.type == bfd_link_hash_defined
          || h->root.type == bfd_link_hash_defweak)
@@ -3873,22 +3909,10 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
                      + h->root.u.def.section->output_section->vma);
        }
 
-      bfd_put_32 (hplink->splt->owner,
-                 value,
-                 hplink->splt->contents + h->plt.offset);
-      bfd_put_32 (hplink->splt->owner,
-                 elf_gp (hplink->splt->output_section->owner),
-                 hplink->splt->contents + h->plt.offset + 4);
-      if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
-         && ((struct elf32_hppa_link_hash_entry *) h)->plabel
-         && h->dynindx != -1)
-       {
-         memset (hplink->splt->contents + h->plt.offset + 8,
-                 0, PLABEL_PLT_ENTRY_SIZE - PLT_ENTRY_SIZE);
-       }
-
       if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
        {
+         Elf_Internal_Rela rel;
+
          /* Create a dynamic IPLT relocation for this entry.  */
          rel.r_offset = (h->plt.offset
                          + hplink->splt->output_offset
@@ -3896,6 +3920,15 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
          if (! ((struct elf32_hppa_link_hash_entry *) h)->plt_abs
              && h->dynindx != -1)
            {
+             /* To support lazy linking, the function pointer is
+                initialised to point to a special stub stored at the
+                end of the .plt.  This is only done for plt entries
+                with a non-*ABS* dynamic relocation.  */
+             value = (hplink->splt->output_offset
+                      + hplink->splt->output_section->vma
+                      + hplink->splt->_raw_size
+                      - sizeof (plt_stub)
+                      + PLT_STUB_ENTRY);
              rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_IPLT);
              rel.r_addend = 0;
            }
@@ -3915,6 +3948,20 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
          hplink->srelplt->reloc_count++;
        }
 
+      bfd_put_32 (hplink->splt->owner,
+                 value,
+                 hplink->splt->contents + h->plt.offset);
+      bfd_put_32 (hplink->splt->owner,
+                 elf_gp (hplink->splt->output_section->owner),
+                 hplink->splt->contents + h->plt.offset + 4);
+      if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
+         && ((struct elf32_hppa_link_hash_entry *) h)->plabel
+         && h->dynindx != -1)
+       {
+         memset (hplink->splt->contents + h->plt.offset + 8,
+                 0, PLABEL_PLT_ENTRY_SIZE - PLT_ENTRY_SIZE);
+       }
+
       if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
        {
          /* Mark the symbol as undefined, rather than as defined in
@@ -4000,7 +4047,6 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
   return true;
 }
 
-
 /* Finish up the dynamic sections.  */
 
 static boolean
@@ -4063,7 +4109,7 @@ elf32_hppa_finish_dynamic_sections (output_bfd, info)
              {
                struct elf_link_hash_entry *h;
                const char *funcname;
+
                if (dyn.d_tag == DT_INIT)
                  funcname = info->init_function;
                else
@@ -4097,22 +4143,42 @@ elf32_hppa_finish_dynamic_sections (output_bfd, info)
                  hplink->sgot->contents);
 
       /* The second entry is reserved for use by the dynamic linker.  */
-      bfd_put_32 (output_bfd, (bfd_vma) 0, hplink->sgot->contents + 4);
+      memset (hplink->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
 
       /* Set .got entry size.  */
       elf_section_data (hplink->sgot->output_section)
        ->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
     }
 
-  /* Set plt entry size.  */
   if (hplink->splt->_raw_size != 0)
-    elf_section_data (hplink->splt->output_section)
-      ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
+    {
+      /* Set plt entry size.  */
+      elf_section_data (hplink->splt->output_section)
+       ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
+
+      if (hplink->need_plt_stub)
+       {
+         /* Set up the .plt stub.  */
+         memcpy (hplink->splt->contents
+                 + hplink->splt->_raw_size - sizeof (plt_stub),
+                 plt_stub, sizeof (plt_stub));
+
+         if ((hplink->splt->output_offset
+              + hplink->splt->output_section->vma
+              + hplink->splt->_raw_size)
+             != (hplink->sgot->output_offset
+                 + hplink->sgot->output_section->vma))
+           {
+             (*_bfd_error_handler)
+               (_(".got section not immediately after .plt section"));
+             return false;
+           }
+       }
+    }
 
   return true;
 }
 
-
 /* Called when writing out an object file to decide the type of a
    symbol.  */
 static int
@@ -4126,7 +4192,6 @@ elf32_hppa_elf_get_symbol_type (elf_sym, type)
     return type;
 }
 
-
 /* Misc BFD support code.  */
 #define bfd_elf32_bfd_is_local_label_name    elf_hppa_is_local_label_name
 #define bfd_elf32_bfd_reloc_type_lookup             elf_hppa_reloc_type_lookup
This page took 0.035955 seconds and 4 git commands to generate.