* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): Add input_bfd, input_section
[deliverable/binutils-gdb.git] / bfd / elf32-hppa.c
index 924f7af49f085df897bf6cc3c45d57fe962bf0f4..63b98e568e3d323d56ee3fb5fd0c70ec63c11f64 100644 (file)
@@ -1,6 +1,6 @@
 /* BFD back-end for HP PA-RISC ELF files.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
-   2002, 2003 Free Software Foundation, Inc.
+   2002, 2003, 2004 Free Software Foundation, Inc.
 
    Original code by
        Center for Software Science
@@ -141,6 +141,12 @@ static const bfd_byte plt_stub[] =
 #define IS_ABSOLUTE_RELOC(r_type) 1
 #endif
 
+/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
+   copying dynamic variables from a shared lib into an app's dynbss
+   section, and instead use a dynamic relocation to point into the
+   shared lib.  */
+#define ELIMINATE_COPY_RELOCS 1
+
 enum elf32_hppa_stub_type {
   hppa_stub_long_branch,
   hppa_stub_long_branch_shared,
@@ -203,10 +209,6 @@ struct elf32_hppa_link_hash_entry {
 #endif
   } *dyn_relocs;
 
-  /* 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.  */
   unsigned int plabel:1;
 };
@@ -345,7 +347,6 @@ hppa_link_hash_newfunc (struct bfd_hash_entry *entry,
       eh = (struct elf32_hppa_link_hash_entry *) entry;
       eh->stub_cache = NULL;
       eh->dyn_relocs = NULL;
-      eh->pic_call = 0;
       eh->plabel = 0;
     }
 
@@ -556,7 +557,8 @@ static enum elf32_hppa_stub_type
 hppa_type_of_stub (asection *input_sec,
                   const Elf_Internal_Rela *rel,
                   struct elf32_hppa_link_hash_entry *hash,
-                  bfd_vma destination)
+                  bfd_vma destination,
+                  struct bfd_link_info *info)
 {
   bfd_vma location;
   bfd_vma branch_offset;
@@ -565,8 +567,11 @@ hppa_type_of_stub (asection *input_sec,
 
   if (hash != NULL
       && hash->elf.plt.offset != (bfd_vma) -1
-      && (hash->elf.dynindx != -1 || hash->pic_call)
-      && !hash->plabel)
+      && hash->elf.dynindx != -1
+      && !hash->plabel
+      && (info->shared
+         || !(hash->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
+         || hash->elf.root.type == bfd_link_hash_defweak))
     {
       /* We need an import stub.  Decide between hppa_stub_import
         and hppa_stub_import_shared later.  */
@@ -769,39 +774,6 @@ hppa_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
          size = 16;
        }
 
-      if (!info->shared
-         && stub_entry->h != NULL
-         && stub_entry->h->pic_call)
-       {
-         /* Build the .plt entry needed to call a PIC function from
-            statically linked code.  We don't need any relocs.  */
-         bfd *dynobj;
-         struct elf32_hppa_link_hash_entry *eh;
-         bfd_vma value;
-
-         dynobj = htab->elf.dynobj;
-         eh = (struct elf32_hppa_link_hash_entry *) stub_entry->h;
-
-         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
-                  + eh->elf.root.u.def.section->output_section->vma);
-
-         /* Fill in the entry in the procedure linkage table.
-
-            The format of a plt entry is
-            <funcaddr>
-            <__gp>.  */
-
-         bfd_put_32 (htab->splt->owner, value,
-                     htab->splt->contents + off);
-         value = elf_gp (htab->splt->output_section->owner);
-         bfd_put_32 (htab->splt->owner, value,
-                     htab->splt->contents + off + 4);
-       }
       break;
 
     case hppa_stub_export:
@@ -863,7 +835,6 @@ hppa_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 #undef BL_R1
 #undef ADDIL_R1
 #undef DEPI_R1
-#undef ADDIL_DP
 #undef LDW_R1_R21
 #undef LDW_R1_DLT
 #undef LDW_R1_R19
@@ -1038,7 +1009,19 @@ elf32_hppa_copy_indirect_symbol (const struct elf_backend_data *bed,
       eind->dyn_relocs = NULL;
     }
 
-  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+  if (ELIMINATE_COPY_RELOCS
+      && ind->root.type != bfd_link_hash_indirect
+      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+    /* If called to transfer flags for a weakdef during processing
+       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+    dir->elf_link_hash_flags |=
+      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+                                  | ELF_LINK_HASH_REF_REGULAR
+                                  | ELF_LINK_HASH_REF_REGULAR_NONWEAK
+                                  | ELF_LINK_HASH_NEEDS_PLT));
+  else
+    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 
 /* Look through the relocs for a section during the first phase, and
@@ -1100,9 +1083,6 @@ elf32_hppa_check_relocs (bfd *abfd,
        case R_PARISC_DLTIND21L:
          /* This symbol requires a global offset table entry.  */
          need_entry = NEED_GOT;
-
-         /* Mark this section as containing PIC code.  */
-         sec->flags |= SEC_HAS_GOT_REF;
          break;
 
        case R_PARISC_PLABEL14R: /* "Official" procedure labels.  */
@@ -1167,12 +1147,13 @@ elf32_hppa_check_relocs (bfd *abfd,
            }
          break;
 
-       case R_PARISC_SEGBASE: /* Used to set segment base.  */
+       case R_PARISC_SEGBASE:  /* Used to set segment base.  */
        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.  */
        case R_PARISC_PCREL21L: /* As above, and for load/store too.  */
+       case R_PARISC_PCREL32:
          /* We don't need to propagate the relocation if linking a
             shared object since these are section relative.  */
          continue;
@@ -1370,7 +1351,8 @@ elf32_hppa_check_relocs (bfd *abfd,
                           || h->elf.root.type == bfd_link_hash_defweak
                           || (h->elf.elf_link_hash_flags
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
-             || (!info->shared
+             || (ELIMINATE_COPY_RELOCS
+                 && !info->shared
                  && (sec->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && (h->elf.root.type == bfd_link_hash_defweak
@@ -1661,8 +1643,6 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
                                  struct elf_link_hash_entry *h)
 {
   struct elf32_hppa_link_hash_table *htab;
-  struct elf32_hppa_link_hash_entry *eh;
-  struct elf32_hppa_dyn_reloc_entry *p;
   asection *s;
   unsigned int power_of_two;
 
@@ -1685,18 +1665,8 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
             used by a plabel relocation.  Either this object is the
             application or we are doing a shared symbolic link.  */
 
-         /* 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->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)->pic_call = 1;
-         else
-           {
-             h->plt.offset = (bfd_vma) -1;
-             h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
-           }
+         h->plt.offset = (bfd_vma) -1;
+         h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
        }
 
       return TRUE;
@@ -1714,6 +1684,10 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
        abort ();
       h->root.u.def.section = h->weakdef->root.u.def.section;
       h->root.u.def.value = h->weakdef->root.u.def.value;
+      if (ELIMINATE_COPY_RELOCS)
+       h->elf_link_hash_flags
+         = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
+            | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
       return TRUE;
     }
 
@@ -1732,20 +1706,26 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
   if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
     return TRUE;
 
-  eh = (struct elf32_hppa_link_hash_entry *) h;
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  if (ELIMINATE_COPY_RELOCS)
     {
-      s = p->sec->output_section;
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-       break;
-    }
+      struct elf32_hppa_link_hash_entry *eh;
+      struct elf32_hppa_dyn_reloc_entry *p;
 
-  /* If we didn't find any dynamic relocs in read-only sections, then
-     we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
-  if (p == NULL)
-    {
-      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
-      return TRUE;
+      eh = (struct elf32_hppa_link_hash_entry *) h;
+      for (p = eh->dyn_relocs; p != NULL; p = p->next)
+       {
+         s = p->sec->output_section;
+         if (s != NULL && (s->flags & SEC_READONLY) != 0)
+           break;
+       }
+
+      /* If we didn't find any dynamic relocs in read-only sections, then
+        we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
+      if (p == NULL)
+       {
+         h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
+         return TRUE;
+       }
     }
 
   /* We must allocate the symbol in our .dynbss section, which will
@@ -1796,34 +1776,8 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
   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.  */
-
-static bfd_boolean
-mark_PIC_calls (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
-{
-  if (h->root.type == bfd_link_hash_warning)
-    h = (struct elf_link_hash_entry *) h->root.u.i.link;
-
-  if (! (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))
-    {
-      h->plt.offset = (bfd_vma) -1;
-      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
-      return TRUE;
-    }
-
-  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-  ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
-
-  return TRUE;
-}
-
 /* Allocate space in the .plt for entries that won't have relocations.
-   ie. pic_call and plabel entries.  */
+   ie. plabel entries.  */
 
 static bfd_boolean
 allocate_plt_static (struct elf_link_hash_entry *h, void *inf)
@@ -1840,16 +1794,7 @@ allocate_plt_static (struct elf_link_hash_entry *h, void *inf)
 
   info = inf;
   htab = hppa_link_hash_table (info);
-  if (((struct elf32_hppa_link_hash_entry *) h)->pic_call)
-    {
-      /* Make an entry in the .plt section for non-pic code that is
-        calling pic code.  */
-      ((struct elf32_hppa_link_hash_entry *) h)->plabel = 0;
-      s = htab->splt;
-      h->plt.offset = s->_raw_size;
-      s->_raw_size += PLT_ENTRY_SIZE;
-    }
-  else if (htab->elf.dynamic_sections_created
+  if (htab->elf.dynamic_sections_created
           && h->plt.refcount > 0)
     {
       /* Make sure this symbol is output as a dynamic symbol.
@@ -1916,7 +1861,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   htab = hppa_link_hash_table (info);
   if (htab->elf.dynamic_sections_created
       && h->plt.offset != (bfd_vma) -1
-      && !((struct elf32_hppa_link_hash_entry *) h)->pic_call
       && !((struct elf32_hppa_link_hash_entry *) h)->plabel)
     {
       /* Make an entry in the .plt section.  */
@@ -1967,9 +1911,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   if (info->shared)
     {
 #if RELATIVE_DYNRELOCS
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-         && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
-             || info->symbolic))
+      if (SYMBOL_CALLS_LOCAL (info, h))
        {
          struct elf32_hppa_dyn_reloc_entry **pp;
 
@@ -1984,6 +1926,12 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
            }
        }
 #endif
+
+      /* Also discard relocs on undefined weak syms with non-default
+        visibility.  */
+      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+         && h->root.type == bfd_link_hash_undefweak)
+       eh->dyn_relocs = NULL;
     }
   else
     {
@@ -1991,7 +1939,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
         symbols which turn out to need copy relocs or are not
         dynamic.  */
       if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
-         && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
+         && ((ELIMINATE_COPY_RELOCS
+              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
               && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
              || (htab->elf.dynamic_sections_created
                  && (h->root.type == bfd_link_hash_undefweak
@@ -2100,7 +2049,7 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -2114,14 +2063,6 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
                              clobber_millicode_symbols,
                              info);
     }
-  else
-    {
-      /* Run through the function symbols, looking for any that are
-        PIC, and mark them as needing .plt entries so that %r19 will
-        be set up.  */
-      if (! info->shared)
-       elf_link_hash_traverse (&htab->elf, mark_PIC_calls, info);
-    }
 
   /* Set up .got and .plt offsets for local syms, and space for local
      dynamic relocs.  */
@@ -2365,9 +2306,6 @@ elf32_hppa_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info)
   bfd_size_type amt;
   struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
 
-  if (htab->elf.root.creator->flavour != bfd_target_elf_flavour)
-    return 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;
@@ -2855,8 +2793,7 @@ elf32_hppa_size_stubs
                        }
                      else if (hash->elf.root.type == bfd_link_hash_undefined)
                        {
-                         if (! (info->shared
-                                && info->unresolved_syms_in_objects == RM_IGNORE
+                         if (! (info->unresolved_syms_in_objects == RM_IGNORE
                                 && (ELF_ST_VISIBILITY (hash->elf.other)
                                     == STV_DEFAULT)
                                 && hash->elf.type != STT_PARISC_MILLI))
@@ -2871,7 +2808,7 @@ elf32_hppa_size_stubs
 
                  /* Determine what (if any) linker stub is needed.  */
                  stub_type = hppa_type_of_stub (section, irela, hash,
-                                                destination);
+                                                destination, info);
                  if (stub_type == hppa_stub_none)
                    continue;
 
@@ -2971,21 +2908,8 @@ elf32_hppa_set_gp (bfd *abfd, struct bfd_link_info *info)
     }
   else
     {
-      asection *splt;
-      asection *sgot;
-
-      if (htab->elf.root.creator->flavour == bfd_target_elf_flavour)
-       {
-         splt = htab->splt;
-         sgot = htab->sgot;
-       }
-      else
-       {
-         /* If we're not elf, look up the output sections in the
-            hope we may actually find them.  */
-         splt = bfd_get_section_by_name (abfd, ".plt");
-         sgot = bfd_get_section_by_name (abfd, ".got");
-       }
+      asection *splt = bfd_get_section_by_name (abfd, ".plt");
+      asection *sgot = bfd_get_section_by_name (abfd, ".got");
 
       /* Choose to point our LTP at, in this order, one of .plt, .got,
         or .data, if these sections exist.  In the case of choosing
@@ -3126,10 +3050,12 @@ final_link_relocate (asection *input_section,
                     bfd_vma value,
                     struct elf32_hppa_link_hash_table *htab,
                     asection *sym_sec,
-                    struct elf32_hppa_link_hash_entry *h)
+                    struct elf32_hppa_link_hash_entry *h,
+                    struct bfd_link_info *info)
 {
   int insn;
   unsigned int r_type = ELF32_R_TYPE (rel->r_info);
+  unsigned int orig_r_type = r_type;
   reloc_howto_type *howto = elf_hppa_howto_table + r_type;
   int r_format = howto->bitsize;
   enum hppa_reloc_field_selector_type_alt r_field;
@@ -3152,6 +3078,26 @@ final_link_relocate (asection *input_section,
              input_section->output_offset +
              input_section->output_section->vma);
 
+  /* If we are not building a shared library, convert DLTIND relocs to
+     DPREL relocs.  */
+  if (!info->shared)
+    {
+      switch (r_type)
+       {
+         case R_PARISC_DLTIND21L:
+           r_type = R_PARISC_DPREL21L;
+           break;
+
+         case R_PARISC_DLTIND14R:
+           r_type = R_PARISC_DPREL14R;
+           break;
+
+         case R_PARISC_DLTIND14F:
+           r_type = R_PARISC_DPREL14F;
+           break;
+       }
+    }
+
   switch (r_type)
     {
     case R_PARISC_PCREL12F:
@@ -3163,8 +3109,11 @@ final_link_relocate (asection *input_section,
          || sym_sec->output_section == NULL
          || (h != NULL
              && h->elf.plt.offset != (bfd_vma) -1
-             && (h->elf.dynindx != -1 || h->pic_call)
-             && !h->plabel))
+             && h->elf.dynindx != -1
+             && !h->plabel
+             && (info->shared
+                 || !(h->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
+                 || h->elf.root.type == bfd_link_hash_defweak)))
        {
          stub_entry = hppa_get_stub_entry (input_section, sym_sec,
                                            h, rel, htab);
@@ -3196,6 +3145,7 @@ final_link_relocate (asection *input_section,
     case R_PARISC_PCREL17R:
     case R_PARISC_PCREL14R:
     case R_PARISC_PCREL14F:
+    case R_PARISC_PCREL32:
       /* Make it a pc relative offset.  */
       value -= location;
       addend -= 8;
@@ -3204,6 +3154,38 @@ final_link_relocate (asection *input_section,
     case R_PARISC_DPREL21L:
     case R_PARISC_DPREL14R:
     case R_PARISC_DPREL14F:
+      /* Convert instructions that use the linkage table pointer (r19) to
+        instructions that use the global data pointer (dp).  This is the
+        most efficient way of using PIC code in an incomplete executable,
+        but the user must follow the standard runtime conventions for
+        accessing data for this to work.  */
+      if (orig_r_type == R_PARISC_DLTIND21L)
+       {
+         /* Convert addil instructions if the original reloc was a
+            DLTIND21L.  GCC sometimes uses a register other than r19 for
+            the operation, so we must convert any addil instruction
+            that uses this relocation.  */
+         if ((insn & 0xfc000000) == ((int) OP_ADDIL << 26))
+           insn = ADDIL_DP;
+         else
+           /* We must have a ldil instruction.  It's too hard to find
+              and convert the associated add instruction, so issue an
+              error.  */
+           (*_bfd_error_handler)
+             (_("%s(%s+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
+              bfd_archive_filename (input_bfd),
+              input_section->name,
+              (long) rel->r_offset,
+              howto->name,
+              insn);
+       }
+      else if (orig_r_type == R_PARISC_DLTIND14F)
+       {
+         /* This must be a format 1 load/store.  Change the base
+            register to dp.  */
+         insn = (insn & 0xfc1ffff) | (27 << 21);
+       }
+
     /* For all the DP relative relocations, we need to examine the symbol's
        section.  If it has no section or if it's a code section, then
        "data pointer relative" makes no sense.  In that case we don't
@@ -3257,6 +3239,7 @@ final_link_relocate (asection *input_section,
     case R_PARISC_DIR17F:
     case R_PARISC_PCREL17C:
     case R_PARISC_PCREL14F:
+    case R_PARISC_PCREL32:
     case R_PARISC_DPREL14F:
     case R_PARISC_PLABEL32:
     case R_PARISC_DLTIND14F:
@@ -3443,32 +3426,31 @@ elf32_hppa_relocate_section (bfd *output_bfd,
          /* This is a local symbol, h defaults to NULL.  */
          sym = local_syms + r_symndx;
          sym_sec = local_sections[r_symndx];
-         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel);
        }
       else
        {
          struct elf_link_hash_entry *hh;
          bfd_boolean unresolved_reloc;
+         struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
 
-         RELOC_FOR_GLOBAL_SYMBOL (hh, elf_sym_hashes (input_bfd), r_symndx, symtab_hdr,
-                                  relocation, sym_sec, unresolved_reloc, info,
-                                  warned_undef);
+         RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+                                  r_symndx, symtab_hdr, sym_hashes,
+                                  hh, sym_sec, relocation,
+                                  unresolved_reloc, warned_undef);
 
          if (relocation == 0
              && hh->root.type != bfd_link_hash_defined
              && hh->root.type != bfd_link_hash_defweak
              && hh->root.type != bfd_link_hash_undefweak)
-           {  
-             if (!info->executable
-                 && info->unresolved_syms_in_objects == RM_IGNORE
+           {
+             if (info->unresolved_syms_in_objects == RM_IGNORE
                  && ELF_ST_VISIBILITY (hh->other) == STV_DEFAULT
                  && hh->type == STT_PARISC_MILLI)
                {
                  if (! info->callbacks->undefined_symbol
                      (info, hh->root.root.string, input_bfd,
-                      input_section, rel->r_offset,
-                      ((info->shared && info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
-                       || (!info->shared && info->unresolved_syms_in_objects == RM_GENERATE_ERROR))))
+                      input_section, rel->r_offset, FALSE))
                    return FALSE;
                  warned_undef = TRUE;
                }
@@ -3706,18 +3688,18 @@ elf32_hppa_relocate_section (bfd *output_bfd,
             Conversely, DEF_DYNAMIC can't be used in check_relocs as
             there all files have not been loaded.  */
          if ((info->shared
+              && (h == NULL
+                  || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
+                  || h->elf.root.type != bfd_link_hash_undefweak)
               && (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))))
+                  || !SYMBOL_CALLS_LOCAL (info, &h->elf)))
              || (!info->shared
                  && 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
+                 && ((ELIMINATE_COPY_RELOCS
+                      && (h->elf.elf_link_hash_flags
+                          & ELF_LINK_HASH_DEF_DYNAMIC) != 0
                       && (h->elf.elf_link_hash_flags
                           & ELF_LINK_HASH_DEF_REGULAR) == 0)
                      || h->elf.root.type == bfd_link_hash_undefweak
@@ -3774,6 +3756,11 @@ elf32_hppa_relocate_section (bfd *output_bfd,
                      && sym_sec->output_section != NULL
                      && ! bfd_is_abs_section (sym_sec))
                    {
+                     /* Skip this relocation if the output section has
+                        been discarded.  */
+                     if (bfd_is_abs_section (sym_sec->output_section))
+                       break;
+
                      indx = elf_section_data (sym_sec->output_section)->dynindx;
                      /* We are turning this relocation into one
                         against a section symbol, so subtract out the
@@ -3806,7 +3793,7 @@ elf32_hppa_relocate_section (bfd *output_bfd,
        }
 
       r = final_link_relocate (input_section, contents, rel, relocation,
-                              htab, sym_sec, h);
+                              htab, sym_sec, h, info);
 
       if (r == bfd_reloc_ok)
        continue;
@@ -3863,6 +3850,8 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
                                  Elf_Internal_Sym *sym)
 {
   struct elf32_hppa_link_hash_table *htab;
+  Elf_Internal_Rela rel;
+  bfd_byte *loc;
 
   htab = hppa_link_hash_table (info);
 
@@ -3890,43 +3879,27 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
                      + h->root.u.def.section->output_section->vma);
        }
 
-      if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
+      /* Create a dynamic IPLT relocation for this entry.  */
+      rel.r_offset = (h->plt.offset
+                     + htab->splt->output_offset
+                     + htab->splt->output_section->vma);
+      if (h->dynindx != -1)
        {
-         Elf_Internal_Rela rel;
-         bfd_byte *loc;
-
-         /* Create a dynamic IPLT relocation for this entry.  */
-         rel.r_offset = (h->plt.offset
-                         + htab->splt->output_offset
-                         + htab->splt->output_section->vma);
-         if (h->dynindx != -1)
-           {
-             rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_IPLT);
-             rel.r_addend = 0;
-           }
-         else
-           {
-             /* This symbol has been marked to become local, and is
-                used by a plabel so must be kept in the .plt.  */
-             rel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
-             rel.r_addend = value;
-           }
-
-         loc = htab->srelplt->contents;
-         loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
-         bfd_elf32_swap_reloca_out (htab->splt->output_section->owner,
-                                    &rel, loc);
+         rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_IPLT);
+         rel.r_addend = 0;
        }
       else
        {
-         bfd_put_32 (htab->splt->owner,
-                     value,
-                     htab->splt->contents + h->plt.offset);
-         bfd_put_32 (htab->splt->owner,
-                     elf_gp (htab->splt->output_section->owner),
-                     htab->splt->contents + h->plt.offset + 4);
+         /* This symbol has been marked to become local, and is
+            used by a plabel so must be kept in the .plt.  */
+         rel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
+         rel.r_addend = value;
        }
 
+      loc = htab->srelplt->contents;
+      loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
+      bfd_elf32_swap_reloca_out (htab->splt->output_section->owner, &rel, loc);
+
       if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
        {
          /* Mark the symbol as undefined, rather than as defined in
@@ -3937,9 +3910,6 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
 
   if (h->got.offset != (bfd_vma) -1)
     {
-      Elf_Internal_Rela rel;
-      bfd_byte *loc;
-
       /* This symbol has an entry in the global offset table.  Set it
         up.  */
 
@@ -3978,8 +3948,6 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
   if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
     {
       asection *s;
-      Elf_Internal_Rela rel;
-      bfd_byte *loc;
 
       /* This symbol needs a copy reloc.  Set it up.  */
 
This page took 0.04065 seconds and 4 git commands to generate.