* bfd/elf.c (INCLUDE_SECTION_IN_SEGMENT): Don't put empty sections into
[deliverable/binutils-gdb.git] / bfd / elf64-hppa.c
index 6ef19c046775b4148e598413fcee3b56cfb11b27..8bc830c110342371fd463d7bc80b0b9881d1a73e 100644 (file)
@@ -1,5 +1,6 @@
 /* Support for HPPA 64-bit ELF
-   Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004
+   Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -173,7 +174,7 @@ static void elf64_hppa_dyn_hash_traverse
           PTR info));
 
 static const char *get_dyn_name
-  PARAMS ((asection *, struct elf_link_hash_entry *,
+  PARAMS ((bfd *, struct elf_link_hash_entry *,
           const Elf_Internal_Rela *, char **, size_t *));
 
 /* This must follow the definitions of the various derived linker
@@ -202,8 +203,8 @@ static bfd_boolean elf64_hppa_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 
 static bfd_boolean elf64_hppa_link_output_symbol_hook
-  PARAMS ((bfd *abfd, struct bfd_link_info *, const char *,
-          Elf_Internal_Sym *, asection *input_sec));
+  PARAMS ((struct bfd_link_info *, const char *, Elf_Internal_Sym *,
+          asection *, struct elf_link_hash_entry *));
 
 static bfd_boolean elf64_hppa_finish_dynamic_symbol
   PARAMS ((bfd *, struct bfd_link_info *,
@@ -446,13 +447,14 @@ elf64_hppa_section_from_shdr (abfd, hdr, name)
    allocate memory as necessary, possibly reusing PBUF/PLEN.  */
 
 static const char *
-get_dyn_name (sec, h, rel, pbuf, plen)
-     asection *sec;
+get_dyn_name (abfd, h, rel, pbuf, plen)
+     bfd *abfd;
      struct elf_link_hash_entry *h;
      const Elf_Internal_Rela *rel;
      char **pbuf;
      size_t *plen;
 {
+  asection *sec = abfd->sections;
   size_t nlen, tlen;
   char *buf;
   size_t len;
@@ -741,7 +743,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
                 || h->root.type == bfd_link_hash_warning)
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
 
-         h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
+         h->ref_regular = 1;
        }
 
       /* We can only get preliminary data on whether a symbol is
@@ -750,8 +752,9 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
         this may help reduce memory usage and processing time later.  */
       maybe_dynamic = FALSE;
       if (h && ((info->shared
-                && (!info->symbolic || info->unresolved_syms_in_shared_libs == RM_IGNORE))
-               || ! (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
+                && (!info->symbolic
+                    || info->unresolved_syms_in_shared_libs == RM_IGNORE))
+               || !h->def_regular
                || h->root.type == bfd_link_hash_defweak))
        maybe_dynamic = TRUE;
 
@@ -858,7 +861,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
        continue;
 
       /* Collect a canonical name for this address.  */
-      addr_name = get_dyn_name (sec, h, rel, &buf, &buf_len);
+      addr_name = get_dyn_name (abfd, h, rel, &buf, &buf_len);
 
       /* Collect the canonical entry data for this address.  */
       dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
@@ -911,7 +914,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
          /* This could be a local function that had its address taken, in
             which case H will be NULL.  */
          if (h)
-           h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+           h->needs_plt = 1;
        }
 
       /* Add a new dynamic relocation to the chain of dynamic
@@ -931,7 +934,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs)
             section symbol for this section ends up in the dynamic
             symbol table.  */
          if (info->shared && dynrel_type == R_PARISC_FPTR64
-             && ! (_bfd_elf64_link_record_local_dynamic_symbol
+             && ! (bfd_elf_link_record_local_dynamic_symbol
                    (info, abfd, sec_symndx)))
            return FALSE;
        }
@@ -975,7 +978,7 @@ elf64_hppa_dynamic_symbol_p (h, info)
     return FALSE;
 }
 
-/* Mark all funtions exported by this file so that we can later allocate
+/* Mark all functions exported by this file so that we can later allocate
    entries in .opd for them.  */
 
 static bfd_boolean
@@ -1012,7 +1015,7 @@ elf64_hppa_mark_exported_functions (h, data)
       dyn_h->want_opd = 1;
       /* Put a flag here for output_symbol_hook.  */
       dyn_h->st_shndx = -1;
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+      h->needs_plt = 1;
     }
 
   return TRUE;
@@ -1042,7 +1045,7 @@ allocate_global_data_dlt (dyn_h, data)
              bfd *owner;
              owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
 
-             if (! (_bfd_elf64_link_record_local_dynamic_symbol
+             if (! (bfd_elf_link_record_local_dynamic_symbol
                     (x->info, owner, dyn_h->sym_indx)))
                return FALSE;
            }
@@ -1146,7 +1149,7 @@ allocate_global_data_opd (dyn_h, data)
              bfd *owner;
              owner = (h ? h->root.u.def.section->owner : dyn_h->owner);
 
-             if (!_bfd_elf64_link_record_local_dynamic_symbol
+             if (!bfd_elf_link_record_local_dynamic_symbol
                    (x->info, owner, dyn_h->sym_indx))
                return FALSE;
            }
@@ -1172,7 +1175,7 @@ allocate_global_data_opd (dyn_h, data)
              nh->root.u.def.value = h->root.u.def.value;
              nh->root.u.def.section = h->root.u.def.section;
 
-             if (! bfd_elf64_link_record_dynamic_symbol (x->info, nh))
+             if (! bfd_elf_link_record_dynamic_symbol (x->info, nh))
                return FALSE;
 
             }
@@ -1211,7 +1214,7 @@ elf64_hppa_post_process_headers (abfd, link_info)
 }
 
 /* Create function descriptor section (.opd).  This section is called .opd
-   because it contains "official prodecure descriptors".  The "official"
+   because it contains "official procedure descriptors".  The "official"
    refers to the fact that these descriptors are used when taking the address
    of a procedure, thus ensuring a unique address for each procedure.  */
 
@@ -1501,14 +1504,14 @@ allocate_dynrel_entries (dyn_h, data)
       if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
        continue;
 
-      hppa_info->other_rel_sec->_raw_size += sizeof (Elf64_External_Rela);
+      hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela);
 
       /* Make sure this symbol gets into the dynamic symbol table if it is
         not already recorded.  ?!? This should not be in the loop since
         the symbol need only be added once.  */
       if (dyn_h->h == 0
          || (dyn_h->h->dynindx == -1 && dyn_h->h->type != STT_PARISC_MILLI))
-       if (!_bfd_elf64_link_record_local_dynamic_symbol
+       if (!bfd_elf_link_record_local_dynamic_symbol
            (x->info, rent->sec->owner, dyn_h->sym_indx))
          return FALSE;
     }
@@ -1516,13 +1519,13 @@ allocate_dynrel_entries (dyn_h, data)
   /* Take care of the GOT and PLT relocations.  */
 
   if ((dynamic_symbol || shared) && dyn_h->want_dlt)
-    hppa_info->dlt_rel_sec->_raw_size += sizeof (Elf64_External_Rela);
+    hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela);
 
   /* If we are building a shared library, then every symbol that has an
      opd entry will need an EPLT relocation to relocate the symbol's address
      and __gp value based on the runtime load address.  */
   if (shared && dyn_h->want_opd)
-    hppa_info->opd_rel_sec->_raw_size += sizeof (Elf64_External_Rela);
+    hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela);
 
   if (dyn_h->want_plt && dynamic_symbol)
     {
@@ -1536,7 +1539,7 @@ allocate_dynrel_entries (dyn_h, data)
       else if (shared)
        t = 2 * sizeof (Elf64_External_Rela);
 
-      hppa_info->plt_rel_sec->_raw_size += t;
+      hppa_info->plt_rel_sec->size += t;
     }
 
   return TRUE;
@@ -1556,12 +1559,12 @@ elf64_hppa_adjust_dynamic_symbol (info, h)
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->weakdef != NULL)
+  if (h->u.weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || h->weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->weakdef->root.u.def.section;
-      h->root.u.def.value = h->weakdef->root.u.def.value;
+      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
+                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
+      h->root.u.def.section = h->u.weakdef->root.u.def.section;
+      h->root.u.def.value = h->u.weakdef->root.u.def.value;
       return TRUE;
     }
 
@@ -1646,7 +1649,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
-         s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+         s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
     }
@@ -1659,7 +1662,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
         below.  */
       s = bfd_get_section_by_name (dynobj, ".rela.dlt");
       if (s != NULL)
-       s->_raw_size = 0;
+       s->size = 0;
     }
 
   /* Allocate the GOT entries.  */
@@ -1670,17 +1673,17 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
       data.ofs = 0x0;
       elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
                                    allocate_global_data_dlt, &data);
-      hppa_info->dlt_sec->_raw_size = data.ofs;
+      hppa_info->dlt_sec->size = data.ofs;
 
       data.ofs = 0x0;
       elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
                                    allocate_global_data_plt, &data);
-      hppa_info->plt_sec->_raw_size = data.ofs;
+      hppa_info->plt_sec->size = data.ofs;
 
       data.ofs = 0x0;
       elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
                                    allocate_global_data_stub, &data);
-      hppa_info->stub_sec->_raw_size = data.ofs;
+      hppa_info->stub_sec->size = data.ofs;
     }
 
   /* Allocate space for entries in the .opd section.  */
@@ -1689,7 +1692,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
       data.ofs = 0;
       elf64_hppa_dyn_hash_traverse (&hppa_info->dyn_hash_table,
                                    allocate_global_data_opd, &data);
-      hppa_info->opd_sec->_raw_size = data.ofs;
+      hppa_info->opd_sec->size = data.ofs;
     }
 
   /* Now allocate space for dynamic relocations, if necessary.  */
@@ -1718,7 +1721,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
       if (strcmp (name, ".plt") == 0)
        {
          /* Strip this section if we don't need it; see the comment below.  */
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              strip = TRUE;
            }
@@ -1731,7 +1734,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
       else if (strcmp (name, ".dlt") == 0)
        {
          /* Strip this section if we don't need it; see the comment below.  */
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              strip = TRUE;
            }
@@ -1739,7 +1742,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
       else if (strcmp (name, ".opd") == 0)
        {
          /* Strip this section if we don't need it; see the comment below.  */
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              strip = TRUE;
            }
@@ -1753,7 +1756,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
             sections.  The linker does that before adjust_dynamic_symbol
             is called, and it is that function which decides whether
             anything needs to go into these sections.  */
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* If we don't need this section, strip it from the
                 output file.  This is mostly to handle .rela.bss and
@@ -1819,8 +1822,8 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
         garbage.  */
       if (s->contents == NULL)
        {
-         s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
-         if (s->contents == NULL && s->_raw_size != 0)
+         s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
+         if (s->contents == NULL && s->size != 0)
            return FALSE;
        }
     }
@@ -1831,7 +1834,7 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
         the PLT, it is how we communicate the __gp value of a load
         module to the dynamic linker.  */
 #define add_dynamic_entry(TAG, VAL) \
-  bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
       if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
          || !add_dynamic_entry (DT_PLTGOT, 0))
@@ -1893,12 +1896,12 @@ elf64_hppa_size_dynamic_sections (output_bfd, info)
    table.  Ick.  */
 
 static bfd_boolean
-elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
-     bfd *abfd ATTRIBUTE_UNUSED;
+elf64_hppa_link_output_symbol_hook (info, name, sym, input_sec, h)
      struct bfd_link_info *info;
      const char *name;
      Elf_Internal_Sym *sym;
      asection *input_sec ATTRIBUTE_UNUSED;
+     struct elf_link_hash_entry *h;
 {
   struct elf64_hppa_link_hash_table *hppa_info;
   struct elf64_hppa_dyn_hash_entry *dyn_h;
@@ -1912,6 +1915,8 @@ elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
   hppa_info = elf64_hppa_hash_table (info);
   dyn_h = elf64_hppa_dyn_hash_lookup (&hppa_info->dyn_hash_table,
                                      name, FALSE, FALSE);
+  if (!dyn_h || dyn_h->h != h)
+    return TRUE;
 
   /* Function symbols for which we created .opd entries *may* have been
      munged by finish_dynamic_symbol and have to be un-munged here.
@@ -1920,7 +1925,7 @@ elf64_hppa_link_output_symbol_hook (abfd, info, name, sym, input_sec)
      into non-dynamic ones, so we initialize st_shndx to -1 in
      mark_exported_functions and check to see if it was overwritten
      here instead of just checking dyn_h->h->dynindx.  */
-  if (dyn_h && dyn_h->want_opd && dyn_h->st_shndx != -1)
+  if (dyn_h->want_opd && dyn_h->st_shndx != -1)
     {
       /* Restore the saved value and section index.  */
       sym->st_value = dyn_h->st_value;
@@ -1964,7 +1969,7 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
      the original values (in elf64_hppa_link_output_symbol_hook).  */
   if (dyn_h && dyn_h->want_opd)
     {
-      BFD_ASSERT (sopd != NULL)
+      BFD_ASSERT (sopd != NULL);
 
       /* Save away the original value and section index so that we
         can restore them later.  */
@@ -1988,7 +1993,7 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
       Elf_Internal_Rela rel;
       bfd_byte *loc;
 
-      BFD_ASSERT (splt != NULL && spltrel != NULL)
+      BFD_ASSERT (splt != NULL && spltrel != NULL);
 
       /* We do not actually care about the value in the PLT entry
         if we are creating a shared library and the symbol is
@@ -2038,7 +2043,7 @@ elf64_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
       int insn;
       unsigned int max_offset;
 
-      BFD_ASSERT (stub != NULL)
+      BFD_ASSERT (stub != NULL);
 
       /* Install the generic stub template.
 
@@ -2281,7 +2286,7 @@ elf64_hppa_finalize_dlt (dyn_h, data)
       bfd_put_64 (sdlt->owner, value, sdlt->contents + dyn_h->dlt_offset);
     }
 
-  /* Create a relocation for the DLT entry assocated with this symbol.
+  /* Create a relocation for the DLT entry associated with this symbol.
      When building a shared library the symbol does not have to be dynamic.  */
   if (dyn_h->want_dlt
       && (elf64_hppa_dynamic_symbol_p (dyn_h->h, info) || info->shared))
@@ -2494,7 +2499,7 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (sdyn != NULL);
 
       dyncon = (Elf64_External_Dyn *) sdyn->contents;
-      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -2533,15 +2538,15 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
 
            case DT_PLTRELSZ:
              s = hppa_info->plt_rel_sec;
-             dyn.d_un.d_val = s->_raw_size;
+             dyn.d_un.d_val = s->size;
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
            case DT_RELA:
              s = hppa_info->other_rel_sec;
-             if (! s || ! s->_raw_size)
+             if (! s || ! s->size)
                s = hppa_info->dlt_rel_sec;
-             if (! s || ! s->_raw_size)
+             if (! s || ! s->size)
                s = hppa_info->opd_rel_sec;
              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
@@ -2549,16 +2554,16 @@ elf64_hppa_finish_dynamic_sections (output_bfd, info)
 
            case DT_RELASZ:
              s = hppa_info->other_rel_sec;
-             dyn.d_un.d_val = s->_raw_size;
+             dyn.d_un.d_val = s->size;
              s = hppa_info->dlt_rel_sec;
-             dyn.d_un.d_val += s->_raw_size;
+             dyn.d_un.d_val += s->size;
              s = hppa_info->opd_rel_sec;
-             dyn.d_un.d_val += s->_raw_size;
+             dyn.d_un.d_val += s->size;
              /* There is some question about whether or not the size of
                 the PLT relocs should be included here.  HP's tools do
                 it, so we'll emulate them.  */
              s = hppa_info->plt_rel_sec;
-             dyn.d_un.d_val += s->_raw_size;
+             dyn.d_un.d_val += s->size;
              bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
This page took 0.038203 seconds and 4 git commands to generate.