* elf-hppa.h (elf_hppa_reloc_final_type): New function stripped
[deliverable/binutils-gdb.git] / bfd / elf32-hppa.c
index 934c8e82b8a052ca35a517a8f05b84cc68c51723..ce3a9b85c8a190e18968444a77c8371d1f63db61 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
-   Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
+   2002 Free Software Foundation, Inc.
 
    Original code by
        Center for Software Science
@@ -32,8 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "libhppa.h"
 #include "elf32-hppa.h"
 #define ARCH_SIZE              32
-#include "elf-hppa.h"
 #include "elf32-hppa.h"
+#include "elf-hppa.h"
 
 /* In order to gain some understanding of code in this file without
    knowing all the intricate details of the linker, note the
@@ -335,7 +335,7 @@ static boolean elf32_hppa_gc_sweep_hook
           asection *, const Elf_Internal_Rela *));
 
 static void elf32_hppa_hide_symbol
-  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
 
 static boolean elf32_hppa_adjust_dynamic_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
@@ -1638,13 +1638,7 @@ elf32_hppa_gc_mark_hook (abfd, info, rel, h, sym)
     }
   else
     {
-      if (!(elf_bad_symtab (abfd)
-           && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
-         && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
-               && sym->st_shndx != SHN_COMMON))
-       {
-         return bfd_section_from_elf_index (abfd, sym->st_shndx);
-       }
+      return bfd_section_from_elf_index (abfd, sym->st_shndx);
     }
 
   return NULL;
@@ -1792,12 +1786,22 @@ elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
    plabels.  */
 
 static void
-elf32_hppa_hide_symbol (info, h)
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
+elf32_hppa_hide_symbol (info, h, force_local)
+     struct bfd_link_info *info;
      struct elf_link_hash_entry *h;
+     boolean force_local;
 {
-  if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
-    h->dynindx = -1;
+  if (force_local)
+    {
+      h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
+      if (h->dynindx != -1)
+       {
+         h->dynindx = -1;
+         _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+                                 h->dynstr_index);
+       }
+    }
+
   if (! ((struct elf32_hppa_link_hash_entry *) h)->plabel)
     {
       h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
@@ -2212,12 +2216,7 @@ clobber_millicode_symbols (h, info)
   if (h->type == STT_PARISC_MILLI
       && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     {
-      struct elf32_hppa_link_hash_table *htab;
-
-      h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
-      elf32_hppa_hide_symbol (info, h);
-      htab = hppa_link_hash_table (info);
-      _bfd_elf_strtab_delref (htab->elf.dynstr, h->dynstr_index);
+      elf32_hppa_hide_symbol (info, h, true);
 
       /* ?!? We only want to remove these from the dynamic symbol table.
         Therefore we do not leave ELF_LINK_FORCED_LOCAL set.  */
@@ -2330,10 +2329,12 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
                     linker script /DISCARD/, so we'll be discarding
                     the relocs too.  */
                }
-             else
+             else if (p->count != 0)
                {
                  srel = elf_section_data (p->sec)->sreloc;
                  srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
+                 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
+                   info->flags |= DF_TEXTREL;
                }
            }
        }
@@ -2506,7 +2507,9 @@ elf32_hppa_size_dynamic_sections (output_bfd, info)
 
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
-         elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, (PTR) info);
+         if ((info->flags & DF_TEXTREL) == 0)
+           elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
+                                   (PTR) info);
 
          if ((info->flags & DF_TEXTREL) != 0)
            {
@@ -2741,8 +2744,10 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
        input_bfd = input_bfd->link_next, bfd_indx++)
     {
       Elf_Internal_Shdr *symtab_hdr;
+      Elf_Internal_Shdr *shndx_hdr;
       Elf_Internal_Sym *isym;
       Elf32_External_Sym *ext_syms, *esym, *end_sy;
+      Elf_External_Sym_Shndx *shndx_buf, *shndx;
       bfd_size_type sec_size;
 
       /* We'll need the symbol table in a second.  */
@@ -2756,32 +2761,50 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
       sec_size *= sizeof (Elf_Internal_Sym);
       local_syms = (Elf_Internal_Sym *) bfd_malloc (sec_size);
       if (local_syms == NULL)
-       {
-         goto error_ret_free_local;
-       }
+       goto error_ret_free_local;
+
       all_local_syms[bfd_indx] = local_syms;
       sec_size = symtab_hdr->sh_info;
       sec_size *= sizeof (Elf32_External_Sym);
       ext_syms = (Elf32_External_Sym *) bfd_malloc (sec_size);
       if (ext_syms == NULL)
-       {
-         goto error_ret_free_local;
-       }
+       goto error_ret_free_local;
 
       if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
-         || (bfd_bread (ext_syms, sec_size, input_bfd) != sec_size))
+         || bfd_bread ((PTR) ext_syms, sec_size, input_bfd) != sec_size)
        {
+       error_ret_free_ext_syms:
          free (ext_syms);
          goto error_ret_free_local;
        }
 
+      shndx_buf = NULL;
+      shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
+      if (shndx_hdr->sh_size != 0)
+       {
+         sec_size = symtab_hdr->sh_info;
+         sec_size *= sizeof (Elf_External_Sym_Shndx);
+         shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (sec_size);
+         if (shndx_buf == NULL)
+           goto error_ret_free_ext_syms;
+
+         if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
+             || bfd_bread ((PTR) shndx_buf, sec_size, input_bfd) != sec_size)
+           {
+             free (shndx_buf);
+             goto error_ret_free_ext_syms;
+           }
+       }
+
       /* Swap the local symbols in.  */
-      isym = local_syms;
-      esym = ext_syms;
-      for (end_sy = esym + symtab_hdr->sh_info; esym < end_sy; esym++, isym++)
-       bfd_elf32_swap_symbol_in (input_bfd, esym, isym);
+      for (esym = ext_syms, end_sy = esym + symtab_hdr->sh_info,
+            isym = local_syms, shndx = shndx_buf;
+          esym < end_sy;
+          esym++, isym++, shndx = (shndx ? shndx + 1 : NULL))
+       bfd_elf32_swap_symbol_in (input_bfd, esym, shndx, isym);
 
       /* Now we can free the external symbols.  */
+      free (shndx_buf);
       free (ext_syms);
 
       if (info->shared && htab->multi_subspace)
@@ -2914,9 +2937,9 @@ elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
              /* Read in the external relocs.  */
              input_rel_hdr = &elf_section_data (section)->rel_hdr;
              if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
-                 || bfd_bread (external_relocs,
-                              input_rel_hdr->sh_size,
-                              input_bfd) != input_rel_hdr->sh_size)
+                 || bfd_bread ((PTR) external_relocs,
+                               input_rel_hdr->sh_size,
+                               input_bfd) != input_rel_hdr->sh_size)
                {
                  free (external_relocs);
                error_ret_free_internal:
This page took 0.028077 seconds and 4 git commands to generate.