* scripttempl/elf.sc: Move non-text .dynamic section before
[deliverable/binutils-gdb.git] / bfd / elf32-hppa.c
index e2f7e10d69bef1c91737ac5072624853d1716e82..7fe328e7039e10bf673e792a0dcc43f4f7a04476 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for HP PA-RISC ELF files.
-   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
    Free Software Foundation, Inc.
 
    Original code by
@@ -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
@@ -66,28 +64,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
    PIC long branch stub:
    :           b,l .+8,%r1
-   :           addil L'X - ($PIC_pcrel$0 - 4),%r1
-   :           be,n R'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
+   :           addil LR'X - ($PIC_pcrel$0 - 4),%r1
+   :           be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
 
    Import stub to call shared library routine from normal object file
    (single sub-space version)
-   :           addil L'lt_ptr+ltoff,%dp        ; get procedure entry point
-   :           ldw R'lt_ptr+ltoff(%r1),%r21
+   :           addil LR'lt_ptr+ltoff,%dp       ; get procedure entry point
+   :           ldw RR'lt_ptr+ltoff(%r1),%r21
    :            bv %r0(%r21)
-   :           ldw R'lt_ptr+ltoff+4(%r1),%r19  ; get new dlt value.
+   :           ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
 
    Import stub to call shared library routine from shared library
    (single sub-space version)
-   :           addil L'ltoff,%r19              ; get procedure entry point
-   :           ldw R'ltoff(%r1),%r21
+   :           addil LR'ltoff,%r19             ; get procedure entry point
+   :           ldw RR'ltoff(%r1),%r21
    :            bv %r0(%r21)
-   :           ldw R'ltoff+4(%r1),%r19         ; get new dlt value.
+   :           ldw RR'ltoff+4(%r1),%r19        ; get new dlt value.
 
    Import stub to call shared library routine from normal object file
    (multiple sub-space support)
-   :           addil L'lt_ptr+ltoff,%dp        ; get procedure entry point
-   :           ldw R'lt_ptr+ltoff(%r1),%r21
-   :           ldw R'lt_ptr+ltoff+4(%r1),%r19  ; get new dlt value.
+   :           addil LR'lt_ptr+ltoff,%dp       ; get procedure entry point
+   :           ldw RR'lt_ptr+ltoff(%r1),%r21
+   :           ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
    :           ldsid (%r21),%r1
    :           mtsp %r1,%sr0
    :           be 0(%sr0,%r21)                 ; branch to target
@@ -95,9 +93,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
    Import stub to call shared library routine from shared library
    (multiple sub-space support)
-   :           addil L'ltoff,%r19              ; get procedure entry point
-   :           ldw R'ltoff(%r1),%r21
-   :           ldw R'ltoff+4(%r1),%r19         ; get new dlt value.
+   :           addil LR'ltoff,%r19             ; get procedure entry point
+   :           ldw RR'ltoff(%r1),%r21
+   :           ldw RR'ltoff+4(%r1),%r19        ; get new dlt value.
    :           ldsid (%r21),%r1
    :           mtsp %r1,%sr0
    :           be 0(%sr0,%r21)                 ; branch to target
@@ -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"
@@ -139,12 +149,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #endif
 
 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
-   shared object's dynamic section.  */
-#ifndef RELATIVE_DYNAMIC_RELOCS
-#define RELATIVE_DYNAMIC_RELOCS 0
+   shared object's dynamic section.  All the relocs of the limited
+   class we are interested in, are absolute.  See check_relocs.  */
+#ifndef IS_ABSOLUTE_RELOC
+#define IS_ABSOLUTE_RELOC(r_type) 1
 #endif
 
-
 enum elf32_hppa_stub_type {
   hppa_stub_long_branch,
   hppa_stub_long_branch_shared,
@@ -154,7 +164,6 @@ enum elf32_hppa_stub_type {
   hppa_stub_none
 };
 
-
 struct elf32_hppa_stub_hash_entry {
 
   /* Base hash table entry structure.  */
@@ -181,11 +190,11 @@ struct elf32_hppa_stub_hash_entry {
   /* The symbol table entry, if any, that this was derived from.  */
   struct elf32_hppa_link_hash_entry *h;
 
-  /* Where this stub is being called from.  */
-  asection *input_section;
+  /* Where this stub is being called from, or, in the case of combined
+     stub sections, the first input section in the group.  */
+  asection *id_sec;
 };
 
-
 struct elf32_hppa_link_hash_entry {
 
   struct elf_link_hash_entry elf;
@@ -200,7 +209,6 @@ struct elf32_hppa_link_hash_entry {
   asection *stub_reloc_sec;
 #endif
 
-#if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
   /* Used to count relocations for delayed sizing of relocation
      sections.  */
   struct elf32_hppa_dyn_reloc_entry {
@@ -214,9 +222,12 @@ struct elf32_hppa_link_hash_entry {
     /* Number of relocs copied in this section.  */
     bfd_size_type count;
   } *reloc_entries;
-#endif
 
   /* Set during a static link if we detect a function is PIC.  */
+  unsigned int maybe_pic_call:1;
+
+  /* Set if the only reason we need a .plt entry is for a non-PIC to
+     PIC function call.  */
   unsigned int pic_call:1;
 
   /* Set if this symbol is used by a plabel reloc.  */
@@ -227,7 +238,6 @@ struct elf32_hppa_link_hash_entry {
   unsigned int plt_abs:1;
 };
 
-
 struct elf32_hppa_link_hash_table {
 
   /* The main hash table.  */
@@ -239,20 +249,23 @@ 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));
 
-  /* Arrays to keep track of which stub sections have been created.  */
-  asection **stub_section_created;
+  /* Array to keep track of which stub sections have been created, and
+     information on stub grouping.  */
+  struct map_stub {
+    /* This is the section to which stubs in the group will be
+       attached.  */
+    asection *link_sec;
+    /* The stub section.  */
+    asection *stub_sec;
 #if ! LONG_BRANCH_PIC_IN_SHLIB
-  asection **reloc_section_created;
+    /* The stub section's reloc section.  */
+    asection *reloc_sec;
 #endif
-  int first_init_sec;
-  int first_fini_sec;
+  } *stub_group;
 
   /* Short-cuts to get to dynamic linker sections.  */
   asection *sgot;
@@ -261,8 +274,23 @@ struct elf32_hppa_link_hash_table {
   asection *srelplt;
   asection *sdynbss;
   asection *srelbss;
-};
 
+  /* Used during a final link to store the base of the text and data
+     segments so that we can perform SEGREL relocations.  */
+  bfd_vma text_segment_base;
+  bfd_vma data_segment_base;
+
+  /* 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) \
@@ -281,7 +309,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 *,
@@ -291,11 +318,11 @@ static char *hppa_stub_name
 static struct elf32_hppa_stub_hash_entry *hppa_get_stub_entry
   PARAMS ((const asection *, const asection *,
           struct elf32_hppa_link_hash_entry *,
-          const Elf_Internal_Rela *, struct bfd_link_info *));
+          const Elf_Internal_Rela *,
+          struct elf32_hppa_link_hash_table *));
 
 static struct elf32_hppa_stub_hash_entry *hppa_add_stub
-  PARAMS ((const char *, asection *, unsigned int,
-          struct bfd_link_info *));
+  PARAMS ((const char *, asection *, struct elf32_hppa_link_hash_table *));
 
 static enum elf32_hppa_stub_type hppa_type_of_stub
   PARAMS ((asection *, const Elf_Internal_Rela *,
@@ -307,7 +334,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 *));
 
@@ -339,24 +365,33 @@ static boolean elf32_hppa_adjust_dynamic_symbol
 static boolean hppa_handle_PIC_calls
   PARAMS ((struct elf_link_hash_entry *, PTR));
 
-#if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
-     || RELATIVE_DYNAMIC_RELOCS)
-static boolean hppa_discard_copies
+static boolean allocate_plt_and_got_and_discard_relocs
   PARAMS ((struct elf_link_hash_entry *, PTR));
-#endif
+
+static boolean clobber_millicode_symbols
+  PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
 
 static boolean elf32_hppa_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 
+static boolean elf32_hppa_final_link
+  PARAMS ((bfd *, struct bfd_link_info *));
+
+static void hppa_record_segment_addr
+  PARAMS ((bfd *, asection *, PTR));
+
 static bfd_reloc_status_type final_link_relocate
   PARAMS ((asection *, bfd_byte *, const Elf_Internal_Rela *,
-          bfd_vma, struct bfd_link_info *, asection *,
+          bfd_vma, struct elf32_hppa_link_hash_table *, asection *,
           struct elf32_hppa_link_hash_entry *));
 
 static boolean elf32_hppa_relocate_section
   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
           bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
 
+static int hppa_unwind_entry_compare
+  PARAMS ((const PTR, const PTR));
+
 static boolean elf32_hppa_finish_dynamic_symbol
   PARAMS ((bfd *, struct bfd_link_info *,
           struct elf_link_hash_entry *, Elf_Internal_Sym *));
@@ -364,10 +399,12 @@ static boolean elf32_hppa_finish_dynamic_symbol
 static boolean elf32_hppa_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 
+static void elf32_hppa_post_process_headers
+  PARAMS ((bfd *, struct bfd_link_info *));
+
 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.  */
@@ -409,13 +446,12 @@ stub_hash_newfunc (entry, table, string)
       ret->target_section = NULL;
       ret->stub_type = hppa_stub_long_branch;
       ret->h = NULL;
-      ret->input_section = NULL;
+      ret->id_sec = NULL;
     }
 
   return (struct bfd_hash_entry *) ret;
 }
 
-
 /* Initialize an entry in the link hash table.  */
 
 static struct bfd_hash_entry *
@@ -451,9 +487,8 @@ hppa_link_hash_newfunc (entry, table, string)
       ret->stub_reloc_sec = NULL;
 #endif
       ret->stub_cache = NULL;
-#if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
       ret->reloc_entries = NULL;
-#endif
+      ret->maybe_pic_call = 0;
       ret->pic_call = 0;
       ret->plabel = 0;
       ret->plt_abs = 0;
@@ -462,7 +497,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).  */
@@ -488,26 +522,25 @@ 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_section_created = NULL;
-#if ! LONG_BRANCH_PIC_IN_SHLIB
-  ret->reloc_section_created = NULL;
-#endif
-  ret->first_init_sec = 0;
-  ret->first_fini_sec = 0;
+  ret->stub_group = NULL;
   ret->sgot = NULL;
   ret->srelgot = NULL;
   ret->splt = NULL;
   ret->srelplt = NULL;
   ret->sdynbss = NULL;
   ret->srelbss = NULL;
+  ret->text_segment_base = (bfd_vma) -1;
+  ret->data_segment_base = (bfd_vma) -1;
+  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 *
@@ -548,39 +581,43 @@ 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.  */
 
 static struct elf32_hppa_stub_hash_entry *
-hppa_get_stub_entry (input_section, sym_sec, hash, rel, info)
+hppa_get_stub_entry (input_section, sym_sec, hash, rel, hplink)
      const asection *input_section;
      const asection *sym_sec;
      struct elf32_hppa_link_hash_entry *hash;
      const Elf_Internal_Rela *rel;
-     struct bfd_link_info *info;
+     struct elf32_hppa_link_hash_table *hplink;
 {
   struct elf32_hppa_stub_hash_entry *stub_entry;
+  const asection *id_sec;
+
+  /* If this input section is part of a group of sections sharing one
+     stub section, then use the id of the first section in the group.
+     Stub names need to include a section id, as there may well be
+     more than one stub used to reach say, printf, and we need to
+     distinguish between them.  */
+  id_sec = hplink->stub_group[input_section->id].link_sec;
 
   if (hash != NULL && hash->stub_cache != NULL
       && hash->stub_cache->h == hash
-      && hash->stub_cache->input_section == input_section)
+      && hash->stub_cache->id_sec == id_sec)
     {
       stub_entry = hash->stub_cache;
     }
   else
     {
-      struct bfd_hash_table *stub_hash_table;
       char *stub_name;
 
-      stub_name = hppa_stub_name (input_section, sym_sec, hash, rel);
+      stub_name = hppa_stub_name (id_sec, sym_sec, hash, rel);
       if (stub_name == NULL)
        return NULL;
 
-      stub_hash_table = &hppa_link_hash_table (info)->stub_hash_table;
-
-      stub_entry = hppa_stub_hash_lookup (stub_hash_table, stub_name,
-                                         false, false);
+      stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table,
+                                         stub_name, false, false);
       if (stub_entry == NULL)
        {
          if (hash == NULL || hash->elf.root.type != bfd_link_hash_undefweak)
@@ -602,71 +639,42 @@ hppa_get_stub_entry (input_section, sym_sec, hash, rel, info)
   return stub_entry;
 }
 
-
 /* Add a new stub entry to the stub hash.  Not all fields of the new
    stub entry are initialised.  */
 
 static struct elf32_hppa_stub_hash_entry *
-hppa_add_stub (stub_name, section, sec_count, info)
+hppa_add_stub (stub_name, section, hplink)
      const char *stub_name;
      asection *section;
-     unsigned int sec_count;
-     struct bfd_link_info *info;
+     struct elf32_hppa_link_hash_table *hplink;
 {
+  asection *link_sec;
   asection *stub_sec;
   struct elf32_hppa_stub_hash_entry *stub_entry;
-  struct elf32_hppa_link_hash_table *hplink;
 
-  hplink = hppa_link_hash_table (info);
-  stub_sec = hplink->stub_section_created[sec_count];
+  link_sec = hplink->stub_group[section->id].link_sec;
+  stub_sec = hplink->stub_group[section->id].stub_sec;
   if (stub_sec == NULL)
     {
-      int special_sec = 0;
-
-      /* We only want one stub for .init and .fini because glibc
-        splits the _init and _fini functions into two parts.  We
-        don't want to put a stub in the middle of a function.
-        It would be better to merge all the stub sections for an
-        output section if the output section + stubs is small enough.
-        This would fix the .init and .fini case and also allow stubs
-        to be merged.  It's more linker work though.  */
-      if (strncmp (section->name, ".init", 5) == 0)
-       {
-         if (hplink->first_init_sec != 0)
-           stub_sec = hplink->stub_section_created[hplink->first_init_sec-1];
-         special_sec = 1;
-       }
-      else if (strncmp (section->name, ".fini", 5) == 0)
-       {
-         if (hplink->first_fini_sec != 0)
-           stub_sec = hplink->stub_section_created[hplink->first_fini_sec-1];
-         special_sec = 2;
-       }
+      stub_sec = hplink->stub_group[link_sec->id].stub_sec;
       if (stub_sec == NULL)
        {
          size_t len;
          char *s_name;
 
-         len = strlen (section->name) + sizeof (STUB_SUFFIX);
+         len = strlen (link_sec->name) + sizeof (STUB_SUFFIX);
          s_name = bfd_alloc (hplink->stub_bfd, len);
          if (s_name == NULL)
            return NULL;
 
-         strcpy (s_name, section->name);
+         strcpy (s_name, link_sec->name);
          strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);
-         stub_sec = (*hplink->add_stub_section) (s_name, section);
+         stub_sec = (*hplink->add_stub_section) (s_name, link_sec);
          if (stub_sec == NULL)
            return NULL;
-
-         if (special_sec != 0)
-           {
-             if (special_sec == 1)
-               hplink->first_init_sec = sec_count + 1;
-             else
-               hplink->first_fini_sec = sec_count + 1;
-           }
+         hplink->stub_group[link_sec->id].stub_sec = stub_sec;
        }
-      hplink->stub_section_created[sec_count] = stub_sec;
+      hplink->stub_group[section->id].stub_sec = stub_sec;
     }
 
   /* Enter this entry into the linker stub hash table.  */
@@ -682,14 +690,13 @@ hppa_add_stub (stub_name, section, sec_count, info)
 
   stub_entry->stub_sec = stub_sec;
 #if ! LONG_BRANCH_PIC_IN_SHLIB
-  stub_entry->reloc_sec = hplink->reloc_section_created[sec_count];
+  stub_entry->reloc_sec = hplink->stub_group[section->id].reloc_sec;
 #endif
   stub_entry->stub_offset = 0;
-  stub_entry->input_section = section;
+  stub_entry->id_sec = link_sec;
   return stub_entry;
 }
 
-
 /* Determine the type of stub needed, if any, for a call.  */
 
 static enum elf32_hppa_stub_type
@@ -713,7 +720,7 @@ hppa_type_of_stub (input_sec, rel, hash, destination)
              && hash->elf.plt.offset != (bfd_vma) -1)
          || hash->elf.root.type == bfd_link_hash_undefweak
          || hash->elf.root.type == bfd_link_hash_undefined
-         || hash->pic_call))
+         || (hash->maybe_pic_call && !(input_sec->flags & SEC_HAS_GOT_REF))))
     {
       /* If output_section is NULL, then it's a symbol defined in a
         shared library.  We will need an import stub.  Decide between
@@ -743,7 +750,7 @@ hppa_type_of_stub (input_sec, rel, hash, destination)
     {
       max_branch_offset = (1 << (12-1)) << 2;
     }
-  else /* R_PARISC_PCREL22F  */
+  else /* R_PARISC_PCREL22F.  */
     {
       max_branch_offset = (1 << (22-1)) << 2;
     }
@@ -753,7 +760,8 @@ hppa_type_of_stub (input_sec, rel, hash, destination)
 #if LONG_BRANCH_VIA_PLT
       if (hash != NULL
          && hash->elf.dynindx != -1
-         && hash->elf.plt.offset != (bfd_vma) -1)
+         && hash->elf.plt.offset != (bfd_vma) -1
+         && hash->elf.type != STT_PARISC_MILLI)
        {
          /* If we are doing a shared link and find we need a long
             branch stub, then go via the .plt if possible.  */
@@ -766,7 +774,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.  */
 
@@ -774,16 +781,16 @@ hppa_type_of_stub (input_sec, rel, hash, destination)
 #define BE_SR4_R1      0xe0202002      /* be,n  RR'XXX(%sr4,%r1)       */
 
 #define BL_R1          0xe8200000      /* b,l   .+8,%r1                */
-#define ADDIL_R1       0x28200000      /* addil L'XXX,%r1,%r1          */
+#define ADDIL_R1       0x28200000      /* addil LR'XXX,%r1,%r1         */
 #define DEPI_R1                0xd4201c1e      /* depi  0,31,2,%r1             */
 
-#define ADDIL_DP       0x2b600000      /* addil L'XXX,%dp,%r1          */
-#define LDW_R1_R21     0x48350000      /* ldw   R'XXX(%sr0,%r1),%r21   */
+#define ADDIL_DP       0x2b600000      /* addil LR'XXX,%dp,%r1         */
+#define LDW_R1_R21     0x48350000      /* ldw   RR'XXX(%sr0,%r1),%r21  */
 #define BV_R0_R21      0xeaa0c000      /* bv    %r0(%r21)              */
-#define LDW_R1_R19     0x48330000      /* ldw   R'XXX(%sr0,%r1),%r19   */
+#define LDW_R1_R19     0x48330000      /* ldw   RR'XXX(%sr0,%r1),%r19  */
 
-#define ADDIL_R19      0x2a600000      /* addil L'XXX,%r19,%r1         */
-#define LDW_R1_DP      0x483b0000      /* ldw   R'XXX(%sr0,%r1),%dp    */
+#define ADDIL_R19      0x2a600000      /* addil LR'XXX,%r19,%r1        */
+#define LDW_R1_DP      0x483b0000      /* ldw   RR'XXX(%sr0,%r1),%dp   */
 
 #define LDSID_R21_R1   0x02a010a1      /* ldsid (%sr0,%r21),%r1        */
 #define MTSP_R1                0x00011820      /* mtsp  %r1,%sr0               */
@@ -819,6 +826,7 @@ hppa_build_one_stub (gen_entry, in_arg)
   bfd_byte *loc;
   bfd_vma sym_value;
   bfd_vma insn;
+  bfd_vma off;
   int val;
   int size;
 
@@ -914,11 +922,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;
@@ -926,7 +934,12 @@ hppa_build_one_stub (gen_entry, in_arg)
 
     case hppa_stub_import:
     case hppa_stub_import_shared:
-      sym_value = (stub_entry->h->elf.plt.offset
+      off = stub_entry->h->elf.plt.offset;
+      if (off >= (bfd_vma) -2)
+       abort ();
+
+      off &= ~ (bfd_vma) 1;
+      sym_value = (off
                   + hplink->splt->output_offset
                   + hplink->splt->output_section->vma
                   - elf_gp (hplink->splt->output_section->owner));
@@ -936,17 +949,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);
 
@@ -960,7 +978,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);
 
@@ -980,8 +998,9 @@ hppa_build_one_stub (gen_entry, in_arg)
          dynobj = hplink->root.dynobj;
          eh = (struct elf32_hppa_link_hash_entry *) stub_entry->h;
 
-         BFD_ASSERT (eh->elf.root.type == bfd_link_hash_defined
-                     || eh->elf.root.type == bfd_link_hash_defweak);
+         if (eh->elf.root.type != bfd_link_hash_defined
+             && eh->elf.root.type != bfd_link_hash_defweak)
+           abort ();
 
          value = (eh->elf.root.u.def.value
                   + eh->elf.root.u.def.section->output_offset
@@ -994,10 +1013,10 @@ hppa_build_one_stub (gen_entry, in_arg)
             <__gp>.  */
 
          bfd_put_32 (hplink->splt->owner, value,
-                     hplink->splt->contents + eh->elf.plt.offset);
+                     hplink->splt->contents + off);
          value = elf_gp (hplink->splt->output_section->owner);
          bfd_put_32 (hplink->splt->owner, value,
-                     hplink->splt->contents + eh->elf.plt.offset + 4);
+                     hplink->splt->contents + off + 4);
        }
       break;
 
@@ -1072,7 +1091,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.  */
 
@@ -1113,7 +1131,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.  */
 
@@ -1121,8 +1138,22 @@ static boolean
 elf32_hppa_object_p (abfd)
      bfd *abfd;
 {
-  unsigned int flags = elf_elfheader (abfd)->e_flags;
+  Elf_Internal_Ehdr * i_ehdrp;
+  unsigned int flags;
+
+  i_ehdrp = elf_elfheader (abfd);
+  if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0)
+    {
+      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX)
+       return false;
+    }
+  else
+    {
+      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
+       return false;
+    }
 
+  flags = i_ehdrp->e_flags;
   switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
     {
     case EFA_PARISC_1_0:
@@ -1137,7 +1168,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.  */
 
@@ -1155,7 +1185,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.  */
 
@@ -1164,8 +1193,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.  */
@@ -1177,14 +1204,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");
@@ -1206,7 +1226,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
@@ -1285,22 +1304,38 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
        case R_PARISC_PLABEL21L:
        case R_PARISC_PLABEL32:
          /* If the addend is non-zero, we break badly.  */
-         BFD_ASSERT (rel->r_addend == 0);
+         if (rel->r_addend != 0)
+           abort ();
 
          /* If we are creating a shared library, then we need to
             create a PLT entry for all PLABELs, because PLABELs with
             local symbols may be passed via a pointer to another
             object.  Additionally, output a dynamic relocation
-            pointing to the PLT entry.  */
+            pointing to the PLT entry.
+            For executables, the original 32-bit ABI allowed two
+            different styles of PLABELs (function pointers):  For
+            global functions, the PLABEL word points into the .plt
+            two bytes past a (function address, gp) pair, and for
+            local functions the PLABEL points directly at the
+            function.  The magic +2 for the first type allows us to
+            differentiate between the two.  As you can imagine, this
+            is a real pain when it comes to generating code to call
+            functions indirectly or to compare function pointers.
+            We avoid the mess by always pointing a PLABEL into the
+            .plt, even for local functions.  */
          need_entry = PLT_PLABEL | NEED_PLT | NEED_DYNREL;
          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
@@ -1318,11 +1353,13 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                 where a symbol is forced local by versioning, or due
                 to symbolic linking, and we lose the .plt entry.  */
              need_entry = NEED_PLT | NEED_STUBREL;
+             if (h->elf.type == STT_PARISC_MILLI)
+               need_entry = NEED_STUBREL;
            }
          break;
 
        case R_PARISC_SEGBASE: /* Used to set segment base.  */
-       case R_PARISC_SEGREL32: /* Relative reloc.  */
+       case R_PARISC_SEGREL32: /* Relative reloc, used for unwind.  */
        case R_PARISC_PCREL14F: /* PC relative load/store.  */
        case R_PARISC_PCREL14R:
        case R_PARISC_PCREL17R: /* External branches.  */
@@ -1347,7 +1384,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
@@ -1363,7 +1401,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
          /* Fall through.  */
 #endif
 
-       case R_PARISC_DIR32: /* .word, PARISC.unwind relocs.  */
+       case R_PARISC_DIR32: /* .word relocs.  */
          /* We may want to output a dynamic relocation later.  */
          need_entry = NEED_DYNREL;
          break;
@@ -1380,7 +1418,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;
 
@@ -1392,7 +1430,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
       if (need_entry & NEED_GOT)
        {
          /* Allocate space for a GOT entry, as well as a dynamic
-             relocation for this entry.  */
+            relocation for this entry.  */
          if (dynobj == NULL)
            hplink->root.dynobj = dynobj = abfd;
 
@@ -1405,20 +1443,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
          if (h != NULL)
            {
              if (h->elf.got.refcount == -1)
-               {
-                 h->elf.got.refcount = 1;
-
-                 /* Make sure this symbol is output as a dynamic symbol.  */
-                 if (h->elf.dynindx == -1)
-                   {
-                     if (! bfd_elf32_link_record_dynamic_symbol (info,
-                                                                 &h->elf))
-                       return false;
-                   }
-
-                 hplink->sgot->_raw_size += GOT_ENTRY_SIZE;
-                 hplink->srelgot->_raw_size += sizeof (Elf32_External_Rela);
-               }
+               h->elf.got.refcount = 1;
              else
                h->elf.got.refcount += 1;
            }
@@ -1442,20 +1467,7 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                  memset (local_got_refcounts, -1, size);
                }
              if (local_got_refcounts[r_symndx] == -1)
-               {
-                 local_got_refcounts[r_symndx] = 1;
-
-                 hplink->sgot->_raw_size += GOT_ENTRY_SIZE;
-                 if (info->shared)
-                   {
-                     /* If we are generating a shared object, we need to
-                        output a reloc so that the dynamic linker can
-                        adjust this GOT entry (because the address
-                        the shared library is loaded at is not fixed).  */
-                     hplink->srelgot->_raw_size +=
-                       sizeof (Elf32_External_Rela);
-                   }
-               }
+               local_got_refcounts[r_symndx] = 1;
              else
                local_got_refcounts[r_symndx] += 1;
            }
@@ -1483,16 +1495,15 @@ 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;
                }
              else if (need_entry & PLT_PLABEL)
                {
-                 int indx;
+                 bfd_signed_vma *local_plt_refcounts;
 
                  if (local_got_refcounts == NULL)
                    {
@@ -1508,11 +1519,12 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                      elf_local_got_refcounts (abfd) = local_got_refcounts;
                      memset (local_got_refcounts, -1, size);
                    }
-                 indx = r_symndx + symtab_hdr->sh_info;
-                 if (local_got_refcounts[indx] == -1)
-                   local_got_refcounts[indx] = 1;
+                 local_plt_refcounts = (local_got_refcounts
+                                        + symtab_hdr->sh_info);
+                 if (local_plt_refcounts[r_symndx] == -1)
+                   local_plt_refcounts[r_symndx] = 1;
                  else
-                   local_got_refcounts[indx] += 1;
+                   local_plt_refcounts[r_symndx] += 1;
                }
            }
        }
@@ -1522,7 +1534,10 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
          /* Flag this symbol as having a non-got, non-plt reference
             so that we generate copy relocs if it turns out to be
             dynamic.  */
-         if (h != NULL)
+         if (need_entry == NEED_DYNREL
+             && h != NULL
+             && !info->shared
+             && (sec->flags & SEC_READONLY) != 0)
            h->elf.elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
 
          /* If we are creating a shared library then we need to copy
@@ -1548,17 +1563,21 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
             is absolute too, as in that case it is the reloc in the
             stub we will be creating, rather than copying the PCREL
             reloc in the branch.  */
-         if ((sec->flags & SEC_ALLOC) != 0
-             && info->shared
-#if RELATIVE_DYNAMIC_RELOCS
-             && (!info->symbolic
-                 || 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)))
-#endif
-             )
+         if ((info->shared
+              && (sec->flags & SEC_ALLOC) != 0
+              && (IS_ABSOLUTE_RELOC (r_type)
+                  || (h != NULL
+                      && (!info->symbolic
+                          || h->elf.root.type == bfd_link_hash_defweak
+                          || (h->elf.elf_link_hash_flags
+                              & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+             || (!info->shared
+                 && (sec->flags & SEC_ALLOC) != 0
+                 && h != NULL
+                 && (h->elf.elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
+                 && (h->elf.root.type == bfd_link_hash_defweak
+                     || (h->elf.elf_link_hash_flags
+                         & ELF_LINK_HASH_DEF_REGULAR) == 0)))
            {
              boolean doit;
              asection *srel;
@@ -1646,16 +1665,13 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                {
                  srel->_raw_size += sizeof (Elf32_External_Rela);
 
-#if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
                  /* Keep track of relocations we have entered for
                     this global symbol, so that we can discard them
                     later if necessary.  */
-                 if (h != NULL
-                     && (0
-#if RELATIVE_DYNAMIC_RELOCS
-                         || ! is_absolute_reloc (rtype)
-#endif
-                         || (need_entry & NEED_STUBREL)))
+                 if (!info->shared
+                     || (h != NULL
+                         && (! IS_ABSOLUTE_RELOC (rtype)
+                             || (need_entry & NEED_STUBREL))))
                    {
                      struct elf32_hppa_dyn_reloc_entry *p;
 
@@ -1679,11 +1695,10 @@ elf32_hppa_check_relocs (abfd, info, sec, relocs)
                         set.  Leave the count at zero for the
                         NEED_STUBREL case as we only ever have one
                         stub reloc per section per symbol, and this
-                        simplifies code in hppa_discard_copies.  */
+                        simplifies code to discard unneeded relocs.  */
                      if (! (need_entry & NEED_STUBREL))
                        ++p->count;
                    }
-#endif
                }
            }
        }
@@ -1692,7 +1707,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.  */
 
@@ -1741,7 +1755,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.  */
 
@@ -1761,8 +1774,6 @@ elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
   struct elf_link_hash_entry *h;
   struct elf32_hppa_link_hash_table *hplink;
   bfd *dynobj;
-  asection *sgot;
-  asection *srelgot;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
@@ -1775,9 +1786,6 @@ elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
   if (dynobj == NULL)
     return true;
 
-  sgot = hplink->sgot;
-  srelgot = hplink->srelgot;
-
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; rel++)
     switch ((unsigned int) ELF32_R_TYPE (rel->r_info))
@@ -1790,27 +1798,12 @@ elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
          {
            h = sym_hashes[r_symndx - symtab_hdr->sh_info];
            if (h->got.refcount > 0)
-             {
-               h->got.refcount -= 1;
-               if (h->got.refcount == 0)
-                 {
-                   sgot->_raw_size -= GOT_ENTRY_SIZE;
-                   srelgot->_raw_size -= sizeof (Elf32_External_Rela);
-                 }
-             }
+             h->got.refcount -= 1;
          }
        else if (local_got_refcounts != NULL)
          {
            if (local_got_refcounts[r_symndx] > 0)
-             {
-               local_got_refcounts[r_symndx] -= 1;
-               if (local_got_refcounts[r_symndx] == 0)
-                 {
-                   sgot->_raw_size -= GOT_ENTRY_SIZE;
-                   if (info->shared)
-                     srelgot->_raw_size -= sizeof (Elf32_External_Rela);
-                 }
-             }
+             local_got_refcounts[r_symndx] -= 1;
          }
        break;
 
@@ -1851,7 +1844,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.  */
 
@@ -1860,7 +1852,8 @@ elf32_hppa_hide_symbol (info, h)
      struct bfd_link_info *info ATTRIBUTE_UNUSED;
      struct elf_link_hash_entry *h;
 {
-  h->dynindx = -1;
+  if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
+    h->dynindx = -1;
   if (! ((struct elf32_hppa_link_hash_entry *) h)->plabel)
     {
       h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
@@ -1868,6 +1861,16 @@ elf32_hppa_hide_symbol (info, h)
     }
 }
 
+/* This is the condition under which elf32_hppa_finish_dynamic_symbol
+   will be called from elflink.h.  If elflink.h doesn't call our
+   finish_dynamic_symbol routine, we'll need to do something about
+   initializing any .plt and .got entries in elf32_hppa_relocate_section.  */
+#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
+  ((DYN)                                                               \
+   && ((INFO)->shared                                                  \
+       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)     \
+   && ((H)->dynindx != -1                                              \
+       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
 
 /* Adjust a symbol defined by a dynamic object and referenced by a
    regular object.  The current definition is in some section of the
@@ -1893,6 +1896,14 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
   if (h->type == STT_FUNC
       || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
     {
+      if (!info->shared
+         && h->plt.refcount > 0
+         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
+         && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0)
+       {
+         ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;
+       }
+
       if (h->plt.refcount <= 0
          || ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
              && h->root.type != bfd_link_hash_defweak
@@ -1909,49 +1920,15 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
 
          /* As a special sop to the hppa ABI, we keep a .plt entry
             for functions in sections containing PIC code.  */
-         if (!info->shared
-             && h->plt.refcount > 0
-             && (h->root.type == bfd_link_hash_defined
-                 || h->root.type == bfd_link_hash_defweak)
-             && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0)
-           {
-             ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
-           }
+         if (((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call)
+           ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
          else
            {
              h->plt.offset = (bfd_vma) -1;
              h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
-             return true;
            }
        }
 
-      /* Make an entry in the .plt section.  */
-      s = hplink->splt;
-      h->plt.offset = s->_raw_size;
-      if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
-         && ((struct elf32_hppa_link_hash_entry *) h)->plabel
-         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
-       {
-         /* Add some extra space for the dynamic linker to use.  */
-         s->_raw_size += PLABEL_PLT_ENTRY_SIZE;
-       }
-      else
-       s->_raw_size += PLT_ENTRY_SIZE;
-
-      if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
-       {
-         /* Make sure this symbol is output as a dynamic symbol.  */
-         if (h->dynindx == -1
-             && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
-           {
-             if (! bfd_elf32_link_record_dynamic_symbol (info, h))
-               return false;
-           }
-
-         /* We also need to make an entry in the .rela.plt section.  */
-         s = hplink->srelplt;
-         s->_raw_size += sizeof (Elf32_External_Rela);
-       }
       return true;
     }
 
@@ -1960,8 +1937,9 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
      real definition first, and we can just use the same value.  */
   if (h->weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || h->weakdef->root.type == bfd_link_hash_defweak);
+      if (h->weakdef->root.type != bfd_link_hash_defined
+         && h->weakdef->root.type != bfd_link_hash_defweak)
+       abort ();
       h->root.u.def.section = h->weakdef->root.u.def.section;
       h->root.u.def.value = h->weakdef->root.u.def.value;
       return true;
@@ -2035,7 +2013,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.  */
@@ -2043,13 +2020,8 @@ elf32_hppa_adjust_dynamic_symbol (info, h)
 static boolean
 hppa_handle_PIC_calls (h, inf)
      struct elf_link_hash_entry *h;
-     PTR inf;
+     PTR inf ATTRIBUTE_UNUSED;
 {
-  struct bfd_link_info *info;
-  bfd *dynobj;
-  struct elf32_hppa_link_hash_table *hplink;
-  asection *s;
-
   if (! (h->plt.refcount > 0
         && (h->root.type == bfd_link_hash_defined
             || h->root.type == bfd_link_hash_defweak)
@@ -2061,71 +2033,192 @@ hppa_handle_PIC_calls (h, inf)
     }
 
   h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+  ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;
   ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
 
-  info = (struct bfd_link_info *) inf;
-  hplink = hppa_link_hash_table (info);
-  dynobj = hplink->root.dynobj;
-
-  /* Make an entry in the .plt section.  */
-  s = hplink->splt;
-  h->plt.offset = s->_raw_size;
-  s->_raw_size += PLT_ENTRY_SIZE;
-
   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
-   we allocated for relocs that it turned out we didn't need.  */
+/* Allocate space in .plt, .got and associated reloc sections for
+   global syms.  */
 
 static boolean
-hppa_discard_copies (h, inf)
+allocate_plt_and_got_and_discard_relocs (h, inf)
      struct elf_link_hash_entry *h;
      PTR inf;
 {
-  struct elf32_hppa_dyn_reloc_entry *s;
-  struct elf32_hppa_link_hash_entry *eh;
   struct bfd_link_info *info;
+  struct elf32_hppa_link_hash_table *hplink;
+  asection *s;
+  struct elf32_hppa_link_hash_entry *eh;
+
+  if (h->root.type == bfd_link_hash_indirect
+      || h->root.type == bfd_link_hash_warning)
+    return true;
 
-  eh = (struct elf32_hppa_link_hash_entry *) h;
   info = (struct bfd_link_info *) inf;
+  hplink = hppa_link_hash_table (info);
+  if ((hplink->root.dynamic_sections_created
+       && h->plt.refcount > 0)
+      || ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
+    {
+      /* Make sure this symbol is output as a dynamic symbol.
+        Undefined weak syms won't yet be marked as dynamic.  */
+      if (h->dynindx == -1
+         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
+         && h->type != STT_PARISC_MILLI
+         && !((struct elf32_hppa_link_hash_entry *) h)->pic_call)
+       {
+         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+           return false;
+       }
+
+      /* Make an entry in the .plt section.  */
+      s = hplink->splt;
+      h->plt.offset = s->_raw_size;
+      if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
+         && ((struct elf32_hppa_link_hash_entry *) h)->plabel
+         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
+       {
+         /* Add some extra space for the dynamic linker to use.  */
+         s->_raw_size += PLABEL_PLT_ENTRY_SIZE;
+       }
+      else
+       s->_raw_size += PLT_ENTRY_SIZE;
+
+      if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call
+         && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
+       {
+         /* We also need to make an entry in the .rela.plt section.  */
+         hplink->srelplt->_raw_size += sizeof (Elf32_External_Rela);
+         hplink->need_plt_stub = 1;
+       }
+    }
+  else
+    {
+      h->plt.offset = (bfd_vma) -1;
+      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+    }
+
+  if (h->got.refcount > 0)
+    {
+      boolean dyn;
+
+      /* Make sure this symbol is output as a dynamic symbol.
+        Undefined weak syms won't yet be marked as dynamic.  */
+      if (h->dynindx == -1
+         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
+         && h->type != STT_PARISC_MILLI)
+       {
+         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+           return false;
+       }
+
+      s = hplink->sgot;
+      h->got.offset = s->_raw_size;
+      s->_raw_size += GOT_ENTRY_SIZE;
+      dyn = hplink->root.dynamic_sections_created;
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+       hplink->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+    }
+  else
+    h->got.offset = (bfd_vma) -1;
+
+  /* If this is a -Bsymbolic shared link, then we need to discard all
+     space allocated for dynamic relocs against symbols defined in a
+     regular object.  For the normal shared case, discard space for
+     relocs that have become local due to symbol visibility changes.
+     For the non-shared case, discard space for symbols which turn out
+     to need copy relocs or are not dynamic.  We also need to lose
+     relocs we've allocated for long branch stubs if we know we won't
+     be generating a stub.  */
+
+  eh = (struct elf32_hppa_link_hash_entry *) h;
+  if (eh->reloc_entries == NULL)
+    return true;
+
+  /* First handle the non-shared case.  */
+  if (!info->shared
+      && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
+      && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
+         || (hplink->root.dynamic_sections_created
+             && (h->root.type == bfd_link_hash_undefweak
+                 || h->root.type == bfd_link_hash_undefined))))
+    {
+      /* Make sure this symbol is output as a dynamic symbol.
+        Undefined weak syms won't yet be marked as dynamic.  */
+      if (h->dynindx == -1
+         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
+         && h->type != STT_PARISC_MILLI)
+       {
+         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+           return false;
+       }
+
+      /* If that succeeded, we know we'll be keeping all the relocs.  */
+      if (h->dynindx != -1)
+       return true;
+    }
 
 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
   /* Handle the stub reloc case.  If we have a plt entry for the
-     function, we won't be needing long branch stubs.  s->count will
+     function, we won't be needing long branch stubs.  c->count will
      only be zero for stub relocs, which provides a handy way of
      flagging these relocs, and means we need do nothing special for
      the forced local and symbolic link case.  */
   if (eh->stub_reloc_sec != NULL
       && eh->elf.plt.offset != (bfd_vma) -1)
     {
-      for (s = eh->reloc_entries; s != NULL; s = s->next)
-       if (s->count == 0)
-         s->section->_raw_size -= sizeof (Elf32_External_Rela);
+      struct elf32_hppa_dyn_reloc_entry *c;
+
+      for (c = eh->reloc_entries; c != NULL; c = c->next)
+       if (c->count == 0)
+         c->section->_raw_size -= sizeof (Elf32_External_Rela);
     }
 #endif
 
-#if RELATIVE_DYNAMIC_RELOCS
-  /* If a symbol has been forced local or we have found a regular
+  /* Discard any relocs in the non-shared case.  For the shared case,
+     if a symbol has been forced local or we have found a regular
      definition for the symbolic link case, then we won't be needing
      any relocs.  */
-  if (eh->elf.dynindx == -1
+  if (!info->shared
       || ((eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-         && eh->elf.root.type != bfd_link_hash_defweak
-         && info->symbolic))
+         && ((eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
+             || info->symbolic)))
     {
-      for (s = eh->reloc_entries; s != NULL; s = s->next)
-       s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
+      struct elf32_hppa_dyn_reloc_entry *c;
+
+      for (c = eh->reloc_entries; c != NULL; c = c->next)
+       c->section->_raw_size -= c->count * sizeof (Elf32_External_Rela);
     }
-#endif
 
   return true;
 }
-#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
+   adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
+   for all dynamic symbols.  Arguably, this is a bug in
+   elf_adjust_dynamic_symbol.  */
+
+static boolean
+clobber_millicode_symbols (h, info)
+     struct elf_link_hash_entry *h;
+     struct bfd_link_info *info;
+{
+  /* We only want to remove these from the dynamic symbol table.
+     Therefore we do not leave ELF_LINK_FORCED_LOCAL set.  */
+  if (h->type == STT_PARISC_MILLI)
+    {
+      unsigned short oldflags = h->elf_link_hash_flags;
+      h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
+      elf32_hppa_hide_symbol (info, h);
+      h->elf_link_hash_flags &= ~ELF_LINK_FORCED_LOCAL;
+      h->elf_link_hash_flags |= oldflags & ELF_LINK_FORCED_LOCAL;
+    }
+  return true;
+}
 
 /* Set the sizes of the dynamic sections.  */
 
@@ -2136,137 +2229,112 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
 {
   struct elf32_hppa_link_hash_table *hplink;
   bfd *dynobj;
+  bfd *i;
   asection *s;
   boolean relocs;
   boolean reltext;
 
   hplink = hppa_link_hash_table (info);
   dynobj = hplink->root.dynobj;
-  BFD_ASSERT (dynobj != NULL);
+  if (dynobj == NULL)
+    abort ();
 
   if (hplink->root.dynamic_sections_created)
     {
-      const char *funcname;
-      bfd *i;
-
       /* Set the contents of the .interp section to the interpreter.  */
       if (! info->shared)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
-         BFD_ASSERT (s != NULL);
+         if (s == NULL)
+           abort ();
          s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
 
-      /* DT_INIT and DT_FINI need a .plt entry.  Make sure they have
-        one.  */
-      funcname = info->init_function;
-      while (1)
-       {
-         if (funcname != NULL)
-           {
-             struct elf_link_hash_entry *h;
-
-             h = elf_link_hash_lookup (&hplink->root, 
-                                       funcname,
-                                       false, false, false);
-             if (h != NULL
-                 && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
-                                               | ELF_LINK_HASH_DEF_REGULAR)))
-               {
-                 if (h->plt.refcount <= 0)
-                   {
-                     h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-
-                     /* Make an entry in the .plt section.  We know
-                        the function doesn't have a plabel by the
-                        refcount  */
-                     s = hplink->splt;
-                     h->plt.offset = s->_raw_size;
-                     s->_raw_size += PLT_ENTRY_SIZE;
-
-                     /* Make sure this symbol is output as a dynamic
-                        symbol.  */
-                     if (h->dynindx == -1)
-                       {
-                         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
-                           return false;
-                       }
+      /* Force millicode symbols local.  */
+      elf_link_hash_traverse (&hplink->root,
+                             clobber_millicode_symbols,
+                             info);
+    }
+  else
+    {
+      /* Run through the function symbols, looking for any that are
+        PIC, and allocate space for the necessary .plt entries so
+        that %r19 will be set up.  */
+      if (! info->shared)
+       elf_link_hash_traverse (&hplink->root,
+                               hppa_handle_PIC_calls,
+                               info);
+    }
 
-                     /* Make an entry for the reloc too.  */
-                     s = hplink->srelplt;
-                     s->_raw_size += sizeof (Elf32_External_Rela);
-                   }
+  /* Set up .got and .plt offsets for local syms.  */
+  for (i = info->input_bfds; i; i = i->link_next)
+    {
+      bfd_signed_vma *local_got;
+      bfd_signed_vma *end_local_got;
+      bfd_signed_vma *local_plt;
+      bfd_signed_vma *end_local_plt;
+      bfd_size_type locsymcount;
+      Elf_Internal_Shdr *symtab_hdr;
+      asection *srel;
 
-                 ((struct elf32_hppa_link_hash_entry *) h)->plt_abs = 1;
-               }
+      if (bfd_get_flavour (i) != bfd_target_elf_flavour)
+       continue;
+
+      local_got = elf_local_got_refcounts (i);
+      if (!local_got)
+       continue;
+
+      symtab_hdr = &elf_tdata (i)->symtab_hdr;
+      locsymcount = symtab_hdr->sh_info;
+      end_local_got = local_got + locsymcount;
+      s = hplink->sgot;
+      srel = hplink->srelgot;
+      for (; local_got < end_local_got; ++local_got)
+       {
+         if (*local_got > 0)
+           {
+             *local_got = s->_raw_size;
+             s->_raw_size += GOT_ENTRY_SIZE;
+             if (info->shared)
+               srel->_raw_size += sizeof (Elf32_External_Rela);
            }
-         if (funcname == info->fini_function)
-           break;
-         funcname = info->fini_function;
+         else
+           *local_got = (bfd_vma) -1;
        }
 
-      /* Set up .plt offsets for local plabels.  */
-      for (i = info->input_bfds; i; i = i->link_next)
+      local_plt = end_local_got;
+      end_local_plt = local_plt + locsymcount;
+      if (! hplink->root.dynamic_sections_created)
        {
-         bfd_signed_vma *local_plt;
-         bfd_signed_vma *end_local_plt;
-         bfd_size_type locsymcount;
-         Elf_Internal_Shdr *symtab_hdr;
-
-         local_plt = elf_local_got_refcounts (i);
-         if (!local_plt)
-           continue;
-
-         symtab_hdr = &elf_tdata (i)->symtab_hdr;
-         locsymcount = symtab_hdr->sh_info;
-         local_plt += locsymcount;
-         end_local_plt = local_plt + locsymcount;
-
+         /* Won't be used, but be safe.  */
+         for (; local_plt < end_local_plt; ++local_plt)
+           *local_plt = (bfd_vma) -1;
+       }
+      else
+       {
+         s = hplink->splt;
+         srel = hplink->srelplt;
          for (; local_plt < end_local_plt; ++local_plt)
            {
              if (*local_plt > 0)
                {
-                 s = hplink->splt;
                  *local_plt = s->_raw_size;
                  s->_raw_size += PLT_ENTRY_SIZE;
                  if (info->shared)
-                   hplink->srelplt->_raw_size += sizeof (Elf32_External_Rela);
+                   srel->_raw_size += sizeof (Elf32_External_Rela);
                }
              else
                *local_plt = (bfd_vma) -1;
            }
        }
     }
-  else
-    {
-      /* Run through the function symbols, looking for any that are
-        PIC, and allocate space for the necessary .plt entries so
-        that %r19 will be set up.  */
-      if (! info->shared)
-       elf_link_hash_traverse (&hplink->root,
-                               hppa_handle_PIC_calls,
-                               info);
 
-      /* We may have created entries in the .rela.got section.
-        However, if we are not creating the dynamic sections, we will
-        not actually use these entries.  Reset the size of .rela.got,
-        which will cause it to get stripped from the output file
-        below.  */
-      hplink->srelgot->_raw_size = 0;
-    }
-
-#if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
-     || RELATIVE_DYNAMIC_RELOCS)
-  /* If this is a -Bsymbolic shared link, then we need to discard all
-     relocs against symbols defined in a regular object.  We also need
-     to lose relocs we've allocated for long branch stubs if we know
-     we won't be generating a stub.  */
-  if (info->shared)
-    elf_link_hash_traverse (&hplink->root,
-                           hppa_discard_copies,
-                           info);
-#endif
+  /* Allocate global sym .plt and .got entries.  Also discard all
+     unneeded relocs.  */
+  elf_link_hash_traverse (&hplink->root,
+                         allocate_plt_and_got_and_discard_relocs,
+                         (PTR) info);
 
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
@@ -2275,52 +2343,55 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
   reltext = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
-      const char *name;
-
       if ((s->flags & SEC_LINKER_CREATED) == 0)
        continue;
 
-      /* It's OK to base decisions on the section name, because none
-        of the dynobj section names depend upon the input files.  */
-      name = bfd_get_section_name (dynobj, s);
-
-      if (strncmp (name, ".rela", 5) == 0)
+      if (s == hplink->splt)
+       {
+         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 (s == hplink->sgot)
+       ;
+      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
        {
          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;
-               }
+             if (s != hplink->srelplt)
+               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.  */
              s->reloc_count = 0;
            }
        }
-      else if (strcmp (name, ".plt") == 0)
-       ;
-      else if (strcmp (name, ".got") == 0)
-       ;
       else
        {
          /* It's not one of our sections, so don't allocate space.  */
@@ -2397,7 +2468,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.
@@ -2407,20 +2477,27 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
    instruction.  */
 
 boolean
-elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
+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;
-     boolean multi_subspace;
      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));
 {
   bfd *input_bfd;
   asection *section;
+  asection **input_list, **list;
   Elf_Internal_Sym *local_syms, **all_local_syms;
-  unsigned int i, indx, bfd_count, sec_count;
+  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;
 
   hplink = hppa_link_hash_table (info);
 
@@ -2429,27 +2506,169 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
   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 the total number of input sections.  */
-  for (input_bfd = info->input_bfds, bfd_count = 0, sec_count = 0;
+  /* 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)
     {
       bfd_count += 1;
-      sec_count += input_bfd->section_count;
+      for (section = input_bfd->sections;
+          section != NULL;
+          section = section->next)
+       {
+         if (top_id < section->id)
+           top_id = section->id;
+       }
     }
 
-  hplink->stub_section_created
-    = (asection **) bfd_zmalloc (sizeof (asection *) * sec_count);
-  if (hplink->stub_section_created == NULL)
+  hplink->stub_group
+    = (struct map_stub *) bfd_zmalloc (sizeof (struct map_stub) * (top_id + 1));
+  if (hplink->stub_group == NULL)
     return false;
 
-#if ! LONG_BRANCH_PIC_IN_SHLIB
-  hplink->reloc_section_created
-    = (asection **) bfd_zmalloc (sizeof (asection *) * sec_count);
-  if (hplink->reloc_section_created == NULL)
-    goto error_ret_free_stub;
-#endif
+  /* 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)
+    {
+      if (top_index < section->index)
+       top_index = section->index;
+    }
+
+  input_list
+    = (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)
+    {
+      for (section = input_bfd->sections;
+          section != NULL;
+          section = section->next)
+       {
+         if (section->output_section != NULL
+             && section->output_section->owner == output_bfd
+             && section->output_section->index <= top_index)
+           {
+             list = input_list + section->output_section->index;
+             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;
+               }
+           }
+       }
+    }
+
+  /* See whether we can group stub sections together.  Grouping stub
+     sections may result in fewer stubs.  More importantly, we need to
+     put all .init* and .fini* stubs at the beginning of the .init or
+     .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 + top_index;
+  do
+    {
+      asection *tail = *list;
+      if (tail == bfd_abs_section_ptr)
+       continue;
+      while (tail != NULL)
+       {
+         asection *curr;
+         asection *prev;
+         bfd_size_type total;
+
+         curr = tail;
+         if (tail->_cooked_size)
+           total = tail->_cooked_size;
+         else
+           total = tail->_raw_size;
+         while ((prev = PREV_SEC (curr)) != NULL
+                && ((total += curr->output_offset - prev->output_offset)
+                    < stub_group_size))
+           curr = prev;
+
+         /* OK, the size from the start of CURR to the end is less
+            than 250000 bytes and thus can be handled by one stub
+            section.  (or the tail section is itself larger than
+            250000 bytes, in which case we may be toast.)
+            We should really be keeping track of the total size of
+            stubs added here, as stubs contribute to the final output
+            section size.  That's a little tricky, and this way will
+            only break if stubs added total more than 12144 bytes, or
+            1518 long branch stubs.  It seems unlikely for more than
+            1518 different functions to be called, especially from
+            code only 250000 bytes long.  */
+         do
+           {
+             prev = PREV_SEC (tail);
+             /* Set up this stub group.  */
+             hplink->stub_group[tail->id].link_sec = curr;
+           }
+         while (tail != curr && (tail = prev) != NULL);
+
+         /* But wait, there's more!  Input sections up to 250000
+            bytes before the stub section can be handled by it too.  */
+         if (!stubs_always_before_branch)
+           {
+             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
@@ -2458,18 +2677,18 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
     = (Elf_Internal_Sym **) bfd_zmalloc (sizeof (Elf_Internal_Sym *)
                                         * bfd_count);
   if (all_local_syms == NULL)
-    goto error_ret_free_reloc;
+    return false;
 
   /* Walk over all the input BFDs, swapping in local symbols.
      If we are creating a shared library, create hash entries for the
      export stubs.  */
-  for (input_bfd = info->input_bfds, indx = 0, sec_count = 0;
+  for (input_bfd = info->input_bfds, bfd_indx = 0;
        input_bfd != NULL;
-       input_bfd = input_bfd->link_next, indx++)
+       input_bfd = input_bfd->link_next, bfd_indx++)
     {
       Elf_Internal_Shdr *symtab_hdr;
       Elf_Internal_Sym *isym;
-      Elf32_External_Sym *ext_syms, *esym;
+      Elf32_External_Sym *ext_syms, *esym, *end_sy;
 
       /* We'll need the symbol table in a second.  */
       symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -2484,7 +2703,7 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
        {
          goto error_ret_free_local;
        }
-      all_local_syms[indx] = local_syms;
+      all_local_syms[bfd_indx] = local_syms;
       ext_syms = (Elf32_External_Sym *)
        bfd_malloc (symtab_hdr->sh_info * sizeof (Elf32_External_Sym));
       if (ext_syms == NULL)
@@ -2505,28 +2724,52 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
       /* Swap the local symbols in.  */
       isym = local_syms;
       esym = ext_syms;
-      for (i = 0; i < symtab_hdr->sh_info; i++, esym++, isym++)
+      for (end_sy = esym + symtab_hdr->sh_info; esym < end_sy; esym++, isym++)
        bfd_elf32_swap_symbol_in (input_bfd, esym, isym);
 
       /* Now we can free the external symbols.  */
       free (ext_syms);
 
+#if ! LONG_BRANCH_PIC_IN_SHLIB
+      /* If this is a shared link, find all the stub reloc sections.  */
+      if (info->shared)
+       for (section = input_bfd->sections;
+            section != NULL;
+            section = section->next)
+         {
+           char *name;
+           asection *reloc_sec;
+
+           name = bfd_malloc (strlen (section->name)
+                              + sizeof STUB_SUFFIX
+                              + 5);
+           if (name == NULL)
+             return false;
+           sprintf (name, ".rela%s%s", section->name, STUB_SUFFIX);
+           reloc_sec = bfd_get_section_by_name (hplink->root.dynobj, name);
+           hplink->stub_group[section->id].reloc_sec = reloc_sec;
+           free (name);
+         }
+#endif
+
       if (info->shared && hplink->multi_subspace)
        {
-         unsigned int symndx;
+         struct elf_link_hash_entry **sym_hashes;
+         struct elf_link_hash_entry **end_hashes;
          unsigned int symcount;
 
          symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
                      - symtab_hdr->sh_info);
+         sym_hashes = elf_sym_hashes (input_bfd);
+         end_hashes = sym_hashes + symcount;
 
          /* Look through the global syms for functions;  We need to
             build export stubs for all globally visible functions.  */
-         for (symndx = 0; symndx < symcount; symndx++)
+         for (; sym_hashes < end_hashes; sym_hashes++)
            {
              struct elf32_hppa_link_hash_entry *hash;
 
-             hash = ((struct elf32_hppa_link_hash_entry *)
-                     elf_sym_hashes (input_bfd)[symndx]);
+             hash = (struct elf32_hppa_link_hash_entry *) *sym_hashes;
 
              while (hash->elf.root.type == bfd_link_hash_indirect
                     || hash->elf.root.type == bfd_link_hash_warning)
@@ -2540,6 +2783,8 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                   || hash->elf.root.type == bfd_link_hash_defweak)
                  && hash->elf.type == STT_FUNC
                  && hash->elf.root.u.def.section->output_section != NULL
+                 && (hash->elf.root.u.def.section->output_section->owner
+                     == output_bfd)
                  && hash->elf.root.u.def.section->owner == input_bfd
                  && (hash->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
                  && !(hash->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
@@ -2556,10 +2801,7 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                                                      false, false);
                  if (stub_entry == NULL)
                    {
-                     stub_entry = hppa_add_stub (stub_name,
-                                                 sec,
-                                                 sec_count + sec->index,
-                                                 info);
+                     stub_entry = hppa_add_stub (stub_name, sec, hplink);
                      if (!stub_entry)
                        goto error_ret_free_local;
 
@@ -2578,39 +2820,15 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                }
            }
        }
-#if LONG_BRANCH_PIC_IN_SHLIB
-      sec_count += input_bfd->section_count;
-#else
-      if (! info->shared)
-       sec_count += input_bfd->section_count;
-      else
-       for (section = input_bfd->sections;
-            section != NULL;
-            section = section->next, sec_count++)
-         {
-           char *name;
-           asection *reloc_sec;
-
-           name = bfd_malloc (strlen (section->name)
-                              + sizeof STUB_SUFFIX
-                              + 5);
-           if (name == NULL)
-             return false;
-           sprintf (name, ".rela%s%s", section->name, STUB_SUFFIX);
-           reloc_sec = bfd_get_section_by_name (hplink->root.dynobj, name);
-           hplink->reloc_section_created[sec_count] = reloc_sec;
-           free (name);
-         }
-#endif
     }
 
   while (1)
     {
       asection *stub_sec;
 
-      for (input_bfd = info->input_bfds, indx = 0, sec_count = 0;
+      for (input_bfd = info->input_bfds, bfd_indx = 0;
           input_bfd != NULL;
-          input_bfd = input_bfd->link_next, indx++)
+          input_bfd = input_bfd->link_next, bfd_indx++)
        {
          Elf_Internal_Shdr *symtab_hdr;
 
@@ -2619,12 +2837,12 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
          if (symtab_hdr->sh_info == 0)
            continue;
 
-         local_syms = all_local_syms[indx];
+         local_syms = all_local_syms[bfd_indx];
 
          /* Walk over each section attached to the input bfd.  */
          for (section = input_bfd->sections;
               section != NULL;
-              section = section->next, sec_count++)
+              section = section->next)
            {
              Elf_Internal_Shdr *input_rel_hdr;
              Elf32_External_Rela *external_relocs, *erelaend, *erela;
@@ -2636,6 +2854,12 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                  || section->reloc_count == 0)
                continue;
 
+             /* If this section is a link-once section that will be
+                discarded, then don't create any stubs.  */
+             if (section->output_section == NULL
+                 || section->output_section->owner != output_bfd)
+               continue;
+
              /* Allocate space for the external relocations.  */
              external_relocs
                = ((Elf32_External_Rela *)
@@ -2692,6 +2916,7 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                  bfd_vma destination;
                  struct elf32_hppa_link_hash_entry *hash;
                  char *stub_name;
+                 const asection *id_sec;
 
                  r_type = ELF32_R_TYPE (irela->r_info);
                  r_indx = ELF32_R_SYM (irela->r_info);
@@ -2779,8 +3004,11 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                  if (stub_type == hppa_stub_none)
                    continue;
 
+                 /* Support for grouping stub sections.  */
+                 id_sec = hplink->stub_group[section->id].link_sec;
+
                  /* Get the name of this stub.  */
-                 stub_name = hppa_stub_name (section, sym_sec, hash, irela);
+                 stub_name = hppa_stub_name (id_sec, sym_sec, hash, irela);
                  if (!stub_name)
                    goto error_ret_free_internal;
 
@@ -2794,8 +3022,7 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
                      continue;
                    }
 
-                 stub_entry = hppa_add_stub (stub_name, section,
-                                             sec_count, info);
+                 stub_entry = hppa_add_stub (stub_name, section, hplink);
                  if (stub_entry == NULL)
                    {
                      free (stub_name);
@@ -2835,15 +3062,20 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
          stub_sec->_cooked_size = 0;
        }
 #if ! LONG_BRANCH_PIC_IN_SHLIB
-      for (i = 0; i < sec_count; i++)
-       {
-         stub_sec = hplink->reloc_section_created[i];
-         if (stub_sec != NULL)
-           {
-             stub_sec->_raw_size = 0;
-             stub_sec->_cooked_size = 0;
-           }
-       }
+      {
+       int i;
+
+       for (i = top_id; i >= 0; --i)
+         {
+           /* This will probably hit the same section many times..  */
+           stub_sec = hplink->stub_group[i].reloc_sec;
+           if (stub_sec != NULL)
+             {
+               stub_sec->_raw_size = 0;
+               stub_sec->_cooked_size = 0;
+             }
+         }
+      }
 #endif
 
       bfd_hash_traverse (&hplink->stub_hash_table,
@@ -2855,33 +3087,17 @@ elf32_hppa_size_stubs (stub_bfd, multi_subspace, info,
       stub_changed = 0;
     }
 
-  /* We're done with the local symbols, free them.  */
-  for (i = 0; i < bfd_count; i++)
-    if (all_local_syms[i])
-      free (all_local_syms[i]);
-  free (all_local_syms);
-#if ! LONG_BRANCH_PIC_IN_SHLIB
-  free (hplink->reloc_section_created);
-#endif
-  free (hplink->stub_section_created);
-  return true;
+  ret = 1;
 
  error_ret_free_local:
-  for (i = 0; i < bfd_count; i++)
-    if (all_local_syms[i])
-      free (all_local_syms[i]);
+  while (bfd_count-- > 0)
+    if (all_local_syms[bfd_count])
+      free (all_local_syms[bfd_count]);
   free (all_local_syms);
 
- error_ret_free_reloc:
-#if ! LONG_BRANCH_PIC_IN_SHLIB
-  free (hplink->reloc_section_created);
- error_ret_free_stub:
-#endif
-  free (hplink->stub_section_created);
-  return false;
+  return ret;
 }
 
-
 /* For a final link, this function is called after we have sized the
    stubs to provide a value for __gp.  */
 
@@ -2899,7 +3115,9 @@ elf32_hppa_set_gp (abfd, info)
   h = elf_link_hash_lookup (&hplink->root, "$global$",
                            false, false, false);
 
-  if (h != NULL && h->root.type == bfd_link_hash_defined)
+  if (h != NULL
+      && (h->root.type == bfd_link_hash_defined
+         || h->root.type == bfd_link_hash_defweak))
     {
       gp_val = h->root.u.def.value;
       sec = h->root.u.def.section;
@@ -2942,16 +3160,25 @@ elf32_hppa_set_gp (abfd, info)
              sec = bfd_get_section_by_name (abfd, ".data");
            }
        }
+
+      if (h != NULL)
+       {
+         h->root.type = bfd_link_hash_defined;
+         h->root.u.def.value = gp_val;
+         if (sec != NULL)
+           h->root.u.def.section = sec;
+         else
+           h->root.u.def.section = bfd_abs_section_ptr;
+       }
     }
 
-  if (sec != NULL)
+  if (sec != NULL && sec->output_section != NULL)
     gp_val += sec->output_section->vma + sec->output_offset;
 
   elf_gp (abfd) = gp_val;
   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
@@ -2990,16 +3217,84 @@ elf32_hppa_build_stubs (info)
   return true;
 }
 
+/* Perform a final link.  */
+
+static boolean
+elf32_hppa_final_link (abfd, info)
+     bfd *abfd;
+     struct bfd_link_info *info;
+{
+  asection *s;
+
+  /* Invoke the regular ELF linker to do all the work.  */
+  if (!bfd_elf32_bfd_final_link (abfd, info))
+    return false;
+
+  /* If we're producing a final executable, sort the contents of the
+     unwind section.  Magic section names, but this is much safer than
+     having elf32_hppa_relocate_section remember where SEGREL32 relocs
+     occurred.  Consider what happens if someone inept creates a
+     linker script that puts unwind information in .text.  */
+  s = bfd_get_section_by_name (abfd, ".PARISC.unwind");
+  if (s != NULL)
+    {
+      bfd_size_type size;
+      char *contents;
+
+      size = s->_raw_size;
+      contents = bfd_malloc (size);
+      if (contents == NULL)
+       return false;
+
+      if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size))
+       return false;
+
+      qsort (contents, size / 16, 16, hppa_unwind_entry_compare);
+
+      if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
+       return false;
+    }
+  return true;
+}
+
+/* Record the lowest address for the data and text segments.  */
+
+static void
+hppa_record_segment_addr (abfd, section, data)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     asection *section;
+     PTR data;
+{
+  struct elf32_hppa_link_hash_table *hplink;
+
+  hplink = (struct elf32_hppa_link_hash_table *) data;
+
+  if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
+    {
+      bfd_vma value = section->vma - section->filepos;
+
+      if ((section->flags & SEC_READONLY) != 0)
+       {
+         if (value < hplink->text_segment_base)
+           hplink->text_segment_base = value;
+       }
+      else
+       {
+         if (value < hplink->data_segment_base)
+           hplink->data_segment_base = value;
+       }
+    }
+}
 
 /* Perform a relocation as part of a final link.  */
 
 static bfd_reloc_status_type
-final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
+final_link_relocate (input_section, contents, rel, value, hplink, sym_sec, h)
      asection *input_section;
      bfd_byte *contents;
      const Elf_Internal_Rela *rel;
      bfd_vma value;
-     struct bfd_link_info *info;
+     struct elf32_hppa_link_hash_table *hplink;
      asection *sym_sec;
      struct elf32_hppa_link_hash_entry *h;
 {
@@ -3039,14 +3334,15 @@ final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
         find the import stub in the stub hash.  */
       if (sym_sec == NULL
          || sym_sec->output_section == NULL
-         || (h != NULL &&
-             (h->pic_call
-              || (h->elf.root.type == bfd_link_hash_defweak
-                  && h->elf.dynindx != -1
-                  && h->elf.plt.offset != (bfd_vma) -1))))
+         || (h != NULL
+             && ((h->maybe_pic_call
+                  && !(input_section->flags & SEC_HAS_GOT_REF))
+                 || (h->elf.root.type == bfd_link_hash_defweak
+                     && h->elf.dynindx != -1
+                     && h->elf.plt.offset != (bfd_vma) -1))))
        {
          stub_entry = hppa_get_stub_entry (input_section, sym_sec,
-                                           h, rel, info);
+                                           h, rel, hplink);
          if (stub_entry != NULL)
            {
              value = (stub_entry->stub_offset
@@ -3057,10 +3353,13 @@ final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
          else if (sym_sec == NULL && h != NULL
                   && h->elf.root.type == bfd_link_hash_undefweak)
            {
-             /* It's OK if undefined weak.  Make undefined weak
-                branches go nowhere.  */
+             /* It's OK if undefined weak.  Calls to undefined weak
+                symbols behave as if the "called" function
+                immediately returns.  We can thus call to a weak
+                function without first checking whether the function
+                is defined.  */
              value = location;
-             addend = 0;
+             addend = 8;
            }
          else
            return bfd_reloc_notsupported;
@@ -3116,6 +3415,13 @@ final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
       value -= elf_gp (input_section->output_section->owner);
       break;
 
+    case R_PARISC_SEGREL32:
+      if ((sym_sec->flags & SEC_CODE) != 0)
+       value -= hplink->text_segment_base;
+      else
+       value -= hplink->data_segment_base;
+      break;
+
     default:
       break;
     }
@@ -3123,6 +3429,7 @@ final_link_relocate (input_section, contents, rel, value, info, 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:
@@ -3181,7 +3488,7 @@ final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
       if (value + addend + max_branch_offset >= 2*max_branch_offset)
        {
          stub_entry = hppa_get_stub_entry (input_section, sym_sec,
-                                           h, rel, info);
+                                           h, rel, hplink);
          if (stub_entry == NULL)
            return bfd_reloc_notsupported;
 
@@ -3242,7 +3549,6 @@ final_link_relocate (input_section, contents, rel, value, info, sym_sec, h)
   return bfd_reloc_ok;
 }
 
-
 /* Relocate an HPPA ELF section.  */
 
 static boolean
@@ -3286,6 +3592,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
       bfd_reloc_status_type r;
       const char *sym_name;
       boolean plabel;
+      bfd_vma off;
 
       r_type = ELF32_R_TYPE (rel->r_info);
       if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
@@ -3358,7 +3665,8 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
          else if (h->elf.root.type == bfd_link_hash_undefweak)
            ;
          else if (info->shared && !info->no_undefined
-                  && ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT)
+                  && ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
+                  && h->elf.type != STT_PARISC_MILLI)
            {
              if (info->symbolic)
                if (!((*info->callbacks->undefined_symbol)
@@ -3376,8 +3684,8 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
        }
 
       /* Do any required modifications to the relocation value, and
-         determine what types of dynamic info we need to output, if
-         any.  */
+        determine what types of dynamic info we need to output, if
+        any.  */
       plabel = 0;
       switch (r_type)
        {
@@ -3388,16 +3696,11 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
             offset table.  */
          if (h != NULL)
            {
-             bfd_vma off;
+             boolean dyn;
 
              off = h->elf.got.offset;
-             BFD_ASSERT (off != (bfd_vma) -1);
-
-             if (! hplink->root.dynamic_sections_created
-                 || (info->shared
-                     && (info->symbolic || h->elf.dynindx == -1)
-                     && (h->elf.elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) != 0))
+             dyn = hplink->root.dynamic_sections_created;
+             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &h->elf))
                {
                  /* This is actually a static link, or it is a
                     -Bsymbolic link and the symbol is defined
@@ -3420,16 +3723,12 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
                      h->elf.got.offset |= 1;
                    }
                }
-
-             relocation = off;
            }
          else
            {
              /* Local symbol case.  */
-             bfd_vma off;
-
-             BFD_ASSERT (local_got_offsets != NULL
-                         && local_got_offsets[r_symndx] != (bfd_vma) -1);
+             if (local_got_offsets == NULL)
+               abort ();
 
              off = local_got_offsets[r_symndx];
 
@@ -3445,10 +3744,10 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
 
                  if (info->shared)
                    {
-                     /* Output a dynamic *ABS* relocation for this
-                        GOT entry.  In this case it is relative to
-                        the base of the object because the symbol
-                        index is zero.  */
+                     /* Output a dynamic relocation for this GOT
+                        entry.  In this case it is relative to the
+                        base of the object because the symbol index
+                        is zero.  */
                      Elf_Internal_Rela outrel;
                      asection *srelgot = hplink->srelgot;
 
@@ -3466,13 +3765,24 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
 
                  local_got_offsets[r_symndx] |= 1;
                }
-
-             relocation = off;
            }
 
+         if (off >= (bfd_vma) -2)
+           abort ();
+
          /* Add the base of the GOT to the relocation value.  */
-         relocation += (hplink->sgot->output_offset
-                        + hplink->sgot->output_section->vma);
+         relocation = (off
+                       + hplink->sgot->output_offset
+                       + hplink->sgot->output_section->vma);
+         break;
+
+       case R_PARISC_SEGREL32:
+         /* If this is the first SEGREL relocation, then initialize
+            the segment base values.  */
+         if (hplink->text_segment_base == (bfd_vma) -1)
+           bfd_map_over_sections (output_bfd,
+                                  hppa_record_segment_addr,
+                                  hplink);
          break;
 
        case R_PARISC_PLABEL14R:
@@ -3480,20 +3790,39 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_PARISC_PLABEL32:
          if (hplink->root.dynamic_sections_created)
            {
-             bfd_vma off;
-
              /* If we have a global symbol with a PLT slot, then
                 redirect this relocation to it.  */
              if (h != NULL)
                {
                  off = h->elf.plt.offset;
+                 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, &h->elf))
+                   {
+                     /* In a non-shared link, adjust_dynamic_symbols
+                        isn't called for symbols forced local.  We
+                        need to write out the plt entry here.  */ 
+                     if ((off & 1) != 0)
+                       off &= ~1;
+                     else
+                       {
+                         bfd_put_32 (output_bfd,
+                                     relocation,
+                                     hplink->splt->contents + off);
+                         bfd_put_32 (output_bfd,
+                                     elf_gp (hplink->splt->output_section->owner),
+                                     hplink->splt->contents + off + 4);
+                         h->elf.plt.offset |= 1;
+                       }
+                   }
                }
              else
                {
-                 int indx;
+                 bfd_vma *local_plt_offsets;
+
+                 if (local_got_offsets == NULL)
+                   abort ();
 
-                 indx = r_symndx + symtab_hdr->sh_info;
-                 off = local_got_offsets[indx];
+                 local_plt_offsets = local_got_offsets + symtab_hdr->sh_info;
+                 off = local_plt_offsets[r_symndx];
 
                  /* As for the local .got entry case, we use the last
                     bit to record whether we've already initialised
@@ -3528,11 +3857,12 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
                          ++srelplt->reloc_count;
                        }
 
-                     local_got_offsets[indx] |= 1;
+                     local_plt_offsets[r_symndx] |= 1;
                    }
                }
 
-             BFD_ASSERT (off < (bfd_vma) -2);
+             if (off >= (bfd_vma) -2)
+               abort ();
 
              /* PLABELs contain function pointers.  Relocation is to
                 the entry for the function in the .plt.  The magic +2
@@ -3555,6 +3885,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:
@@ -3566,19 +3897,30 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
             hppa_discard_copies.  ie. We need exactly the same
             condition as in check_relocs, with some extra conditions
             (dynindx test in this case) to cater for relocs removed
-            by hppa_discard_copies.  */
-         if ((input_section->flags & SEC_ALLOC) != 0
-             && info->shared
-#if RELATIVE_DYNAMIC_RELOCS
-             && (is_absolute_reloc (r_type)
-                 || ((!info->symbolic
-                      || (h != NULL
-                          && ((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)))
-#endif
-             )
+            by hppa_discard_copies.  If you squint, the non-shared
+            test here does indeed match the one in check_relocs, the
+            difference being that here we test DEF_DYNAMIC rather
+            than a maybe-DEF_DYNAMIC via !DEF_REGULAR.  Common syms
+            end up with !DEF_REGULAR, which is why we can't use that
+            here.  Conversely, DEF_DYNAMIC can't be used in
+            check_relocs as there all files have not been loaded.  */
+         if ((info->shared
+              && (input_section->flags & SEC_ALLOC) != 0
+              && (IS_ABSOLUTE_RELOC (r_type)
+                  || (h != NULL
+                      && h->elf.dynindx != -1
+                      && (!info->symbolic
+                          || (h->elf.elf_link_hash_flags
+                              & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+             || (!info->shared
+                 && (input_section->flags & SEC_ALLOC) != 0
+                 && h != NULL
+                 && h->elf.dynindx != -1
+                 && (h->elf.elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
+                 && ((h->elf.elf_link_hash_flags
+                      & ELF_LINK_HASH_DEF_DYNAMIC) != 0
+                     || h->elf.root.type == bfd_link_hash_undefweak
+                     || h->elf.root.type == bfd_link_hash_undefined)))
            {
              Elf_Internal_Rela outrel;
              boolean skip;
@@ -3598,7 +3940,8 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
                  if (name == NULL)
                    return false;
                  sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
+                 if (sreloc == NULL)
+                   abort ();
                }
 
              outrel.r_offset = rel->r_offset;
@@ -3628,6 +3971,8 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
              else if (h != NULL
                       && h->elf.dynindx != -1
                       && (plabel
+                          || !IS_ABSOLUTE_RELOC (r_type)
+                          || !info->shared
                           || !info->symbolic
                           || (h->elf.elf_link_hash_flags
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))
@@ -3662,7 +4007,13 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
 
                  outrel.r_info = ELF32_R_INFO (indx, r_type);
                }
-
+#if 0
+             /* EH info can cause unaligned DIR32 relocs.
+                Tweak the reloc type for the dynamic linker.  */
+             if (r_type == R_PARISC_DIR32 && (outrel.r_offset & 3) != 0)
+               outrel.r_info = ELF32_R_INFO (ELF32_R_SYM (outrel.r_info),
+                                             R_PARISC_DIR32U);
+#endif
              bfd_elf32_swap_reloca_out (output_bfd, &outrel,
                                         ((Elf32_External_Rela *)
                                          sreloc->contents
@@ -3676,7 +4027,7 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
        }
 
       r = final_link_relocate (input_section, contents, rel, relocation,
-                              info, sym_sec, h);
+                              hplink, sym_sec, h);
 
       if (r == bfd_reloc_ok)
        continue;
@@ -3718,6 +4069,31 @@ elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
   return true;
 }
 
+/* Comparison function for qsort to sort unwind section during a
+   final link.  */
+
+static int
+hppa_unwind_entry_compare (a, b)
+     const PTR a;
+     const PTR b;
+{
+  const bfd_byte *ap, *bp;
+  unsigned long av, bv;
+
+  ap = (const bfd_byte *) a;
+  av = (unsigned long) ap[0] << 24;
+  av |= (unsigned long) ap[1] << 16;
+  av |= (unsigned long) ap[2] << 8;
+  av |= (unsigned long) ap[3];
+
+  bp = (const bfd_byte *) b;
+  bv = (unsigned long) bp[0] << 24;
+  bv |= (unsigned long) bp[1] << 16;
+  bv |= (unsigned long) bp[2] << 8;
+  bv |= (unsigned long) bp[3];
+
+  return av < bv ? -1 : av > bv ? 1 : 0;
+}
 
 /* Finish up dynamic symbol handling.  We set the contents of various
    dynamic sections here.  */
@@ -3735,15 +4111,12 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
   hplink = hppa_link_hash_table (info);
   dynobj = hplink->root.dynobj;
 
-  /* Millicode symbols should not be put in the dynamic
-     symbol table under any circumstances.  */
-  if (ELF_ST_TYPE (sym->st_info) == STT_PARISC_MILLI)
-    h->dynindx = -1;
-
   if (h->plt.offset != (bfd_vma) -1)
     {
       bfd_vma value;
-      Elf_Internal_Rela rel;
+
+      if (h->plt.offset & 1)
+       abort ();
 
       /* This symbol has an entry in the procedure linkage table.  Set
         it up.
@@ -3751,15 +4124,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)
@@ -3770,22 +4135,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
@@ -3793,6 +4146,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 not done for plt entries
+                with a base-relative 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;
            }
@@ -3812,6 +4174,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
@@ -3831,15 +4207,14 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
                      + hplink->sgot->output_offset
                      + hplink->sgot->output_section->vma);
 
-      /* If this is a static link, or it is a -Bsymbolic link and the
-        symbol is defined locally or was forced to be local because
-        of a version file, we just want to emit a RELATIVE reloc.
-        The entry in the global offset table will already have been
-        initialized in the relocate_section function.  */
-      if (! hplink->root.dynamic_sections_created
-         || (info->shared
-             && (info->symbolic || h->dynindx == -1)
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+      /* If this is a -Bsymbolic link and the symbol is defined
+        locally or was forced to be local because of a version file,
+        we just want to emit a RELATIVE reloc.  The entry in the
+        global offset table will already have been initialized in the
+        relocate_section function.  */
+      if (info->shared
+         && (info->symbolic || h->dynindx == -1)
+         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
        {
          rel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
          rel.r_addend = (h->root.u.def.value
@@ -3848,7 +4223,8 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
        }
       else
        {
-         BFD_ASSERT((h->got.offset & 1) == 0);
+         if ((h->got.offset & 1) != 0)
+           abort ();
          bfd_put_32 (output_bfd, (bfd_vma) 0,
                      hplink->sgot->contents + h->got.offset);
          rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_DIR32);
@@ -3869,9 +4245,10 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
 
       /* This symbol needs a copy reloc.  Set it up.  */
 
-      BFD_ASSERT (h->dynindx != -1
-                 && (h->root.type == bfd_link_hash_defined
-                     || h->root.type == bfd_link_hash_defweak));
+      if (! (h->dynindx != -1
+            && (h->root.type == bfd_link_hash_defined
+                || h->root.type == bfd_link_hash_defweak)))
+       abort ();
 
       s = hplink->srelbss;
 
@@ -3897,7 +4274,6 @@ elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
   return true;
 }
 
-
 /* Finish up the dynamic sections.  */
 
 static boolean
@@ -3918,7 +4294,8 @@ elf32_hppa_finish_dynamic_sections (output_bfd, info)
     {
       Elf32_External_Dyn *dyncon, *dynconend;
 
-      BFD_ASSERT (sdyn != NULL);
+      if (sdyn == NULL)
+       abort ();
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
@@ -3954,36 +4331,11 @@ elf32_hppa_finish_dynamic_sections (output_bfd, info)
                dyn.d_un.d_val = s->_raw_size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
-
-           case DT_INIT:
-           case DT_FINI:
-             {
-               struct elf_link_hash_entry *h;
-               const char *funcname;
-               if (dyn.d_tag == DT_INIT)
-                 funcname = info->init_function;
-               else
-                 funcname = info->fini_function;
-
-               h = elf_link_hash_lookup (&hplink->root, funcname,
-                                         false, false, false);
-
-               /* This is a function pointer.  The magic +2 offset
-                  signals to $$dyncall that the function pointer
-                  is in the .plt and thus has a gp pointer too.  */
-               dyn.d_un.d_ptr = (h->plt.offset
-                                 + hplink->splt->output_offset
-                                 + hplink->splt->output_section->vma
-                                 + 2);
-               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
-               break;
-             }
            }
        }
     }
 
-  if (hplink->sgot->_raw_size != 0)
+  if (hplink->sgot != NULL && hplink->sgot->_raw_size != 0)
     {
       /* Fill in the first entry in the global offset table.
         We use it to point to our dynamic section, if we have one.  */
@@ -3994,21 +4346,62 @@ 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;
+  if (hplink->splt != NULL && hplink->splt->_raw_size != 0)
+    {
+      /* 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;
 }
 
+/* Tweak the OSABI field of the elf header.  */
+
+static void
+elf32_hppa_post_process_headers (abfd, link_info)
+     bfd *abfd;
+     struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
+{
+  Elf_Internal_Ehdr * i_ehdrp;
+
+  i_ehdrp = elf_elfheader (abfd);
+
+  if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0)
+    {
+      i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_LINUX;
+    }
+  else
+    {
+      i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_HPUX;
+    }
+}
 
 /* Called when writing out an object file to decide the type of a
    symbol.  */
@@ -4023,7 +4416,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
@@ -4031,7 +4423,7 @@ elf32_hppa_elf_get_symbol_type (elf_sym, type)
 #define elf_info_to_howto_rel               elf_hppa_info_to_howto_rel
 
 /* Stuff for the BFD linker.  */
-#define bfd_elf32_bfd_final_link            _bfd_elf32_gc_common_final_link
+#define bfd_elf32_bfd_final_link            elf32_hppa_final_link
 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
 #define elf_backend_add_symbol_hook         elf32_hppa_add_symbol_hook
 #define elf_backend_adjust_dynamic_symbol    elf32_hppa_adjust_dynamic_symbol
@@ -4047,6 +4439,7 @@ elf32_hppa_elf_get_symbol_type (elf_sym, type)
 #define elf_backend_gc_sweep_hook           elf32_hppa_gc_sweep_hook
 #define elf_backend_object_p                elf32_hppa_object_p
 #define elf_backend_final_write_processing   elf_hppa_final_write_processing
+#define elf_backend_post_process_headers     elf32_hppa_post_process_headers
 #define elf_backend_get_symbol_type         elf32_hppa_elf_get_symbol_type
 
 #define elf_backend_can_gc_sections         1
@@ -4063,3 +4456,11 @@ elf32_hppa_elf_get_symbol_type (elf_sym, type)
 #define ELF_MAXPAGESIZE                0x1000
 
 #include "elf32-target.h"
+
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM                 bfd_elf32_hppa_linux_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME                        "elf32-hppa-linux"
+
+#define INCLUDED_TARGET_FILE 1
+#include "elf32-target.h"
This page took 0.058854 seconds and 4 git commands to generate.