* elf.c (assign_file_positions_for_segments): Set next_file_pos even
[deliverable/binutils-gdb.git] / bfd / xcofflink.c
index ccd82befdac005dd0cd6ec120670154d3edce466..8142e168331334dded1312055dfbdb984bc52504 100644 (file)
@@ -1,5 +1,5 @@
 /* POWER/PowerPC XCOFF linker support.
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
 
@@ -171,15 +171,14 @@ xcoff_get_section_contents (abfd, sec)
 
   if (coff_section_data (abfd, sec)->contents == NULL)
     {
-      coff_section_data (abfd, sec)->contents = ((bfd_byte *)
-                                                bfd_malloc (sec->_raw_size));
-      if (coff_section_data (abfd, sec)->contents == NULL)
-       return FALSE;
-
-      if (! bfd_get_section_contents (abfd, sec,
-                                     coff_section_data (abfd, sec)->contents,
-                                     (file_ptr) 0, sec->_raw_size))
-       return FALSE;
+      bfd_byte *contents;
+      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
+       {
+         if (contents != NULL)
+           free (contents);
+         return FALSE;
+       }
+      coff_section_data (abfd, sec)->contents = contents;
     }
 
   return TRUE;
@@ -1241,8 +1240,8 @@ xcoff_link_add_symbols (abfd, info)
              if (enclosing == NULL)
                {
                  (*_bfd_error_handler)
-                   (_("%s: `%s' has line numbers but no enclosing section"),
-                    bfd_archive_filename (abfd), name);
+                   (_("%B: `%s' has line numbers but no enclosing section"),
+                    abfd, name);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -1294,8 +1293,8 @@ xcoff_link_add_symbols (abfd, info)
       if (sym.n_numaux == 0)
        {
          (*_bfd_error_handler)
-           (_("%s: class %d symbol `%s' has no aux entries"),
-            bfd_archive_filename (abfd), sym.n_sclass, name);
+           (_("%B: class %d symbol `%s' has no aux entries"),
+            abfd, sym.n_sclass, name);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
        }
@@ -1317,8 +1316,8 @@ xcoff_link_add_symbols (abfd, info)
        {
        default:
          (*_bfd_error_handler)
-           (_("%s: symbol `%s' has unrecognized csect type %d"),
-            bfd_archive_filename (abfd), name, smtyp);
+           (_("%B: symbol `%s' has unrecognized csect type %d"),
+            abfd, name, smtyp);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
 
@@ -1329,8 +1328,8 @@ xcoff_link_add_symbols (abfd, info)
              || aux.x_csect.x_scnlen.l != 0)
            {
              (*_bfd_error_handler)
-               (_("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
-                bfd_archive_filename (abfd), name, sym.n_sclass, sym.n_scnum,
+               (_("%B: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
+                abfd, name, sym.n_sclass, sym.n_scnum,
                 aux.x_csect.x_scnlen.l);
              bfd_set_error (bfd_error_bad_value);
              goto error_return;
@@ -1365,9 +1364,8 @@ xcoff_link_add_symbols (abfd, info)
                  || aux.x_csect.x_scnlen.l != 0)
                {
                  (*_bfd_error_handler)
-                   (_("%s: XMC_TC0 symbol `%s' is class %d scnlen %d"),
-                    bfd_archive_filename (abfd), name, sym.n_sclass,
-                    aux.x_csect.x_scnlen.l);
+                   (_("%B: XMC_TC0 symbol `%s' is class %d scnlen %d"),
+                    abfd, name, sym.n_sclass, aux.x_csect.x_scnlen.l);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -1514,11 +1512,11 @@ xcoff_link_add_symbols (abfd, info)
            if (! bfd_is_abs_section (enclosing)
                && ((bfd_vma) sym.n_value < enclosing->vma
                    || ((bfd_vma) sym.n_value + aux.x_csect.x_scnlen.l
-                       > enclosing->vma + enclosing->_raw_size)))
+                       > enclosing->vma + enclosing->size)))
              {
                (*_bfd_error_handler)
-                 (_("%s: csect `%s' not in enclosing section"),
-                  bfd_archive_filename (abfd), name);
+                 (_("%B: csect `%s' not in enclosing section"),
+                  abfd, name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
              }
@@ -1526,7 +1524,7 @@ xcoff_link_add_symbols (abfd, info)
            csect->filepos = (enclosing->filepos
                              + sym.n_value
                              - enclosing->vma);
-           csect->_raw_size = aux.x_csect.x_scnlen.l;
+           csect->size = aux.x_csect.x_scnlen.l;
            csect->flags |= SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
            csect->alignment_power = SMTYP_ALIGN (aux.x_csect.x_smtyp);
 
@@ -1563,7 +1561,7 @@ xcoff_link_add_symbols (abfd, info)
                                      + relindx * bfd_coff_relsz (abfd));
                while (relindx < enclosing->reloc_count
                       && *rel_csect == NULL
-                      && rel->r_vaddr < csect->vma + csect->_raw_size)
+                      && rel->r_vaddr < csect->vma + csect->size)
                  {
 
                    *rel_csect = csect;
@@ -1624,8 +1622,8 @@ xcoff_link_add_symbols (abfd, info)
            if (bad)
              {
                (*_bfd_error_handler)
-                 (_("%s: misplaced XTY_LD `%s'"),
-                  bfd_archive_filename (abfd), name);
+                 (_("%B: misplaced XTY_LD `%s'"),
+                  abfd, name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
              }
@@ -1664,7 +1662,7 @@ xcoff_link_add_symbols (abfd, info)
          if (csect == NULL)
            goto error_return;
          csect->vma = sym.n_value;
-         csect->_raw_size = aux.x_csect.x_scnlen.l;
+         csect->size = aux.x_csect.x_scnlen.l;
          csect->flags |= SEC_ALLOC;
          csect->alignment_power = SMTYP_ALIGN (aux.x_csect.x_smtyp);
          /* There are a number of other fields and section flags
@@ -1690,7 +1688,7 @@ xcoff_link_add_symbols (abfd, info)
          if (sym.n_sclass == C_EXT)
            {
              csect->flags |= SEC_IS_COMMON;
-             csect->_raw_size = 0;
+             csect->size = 0;
              section = csect;
              value = aux.x_csect.x_scnlen.l;
            }
@@ -1827,7 +1825,7 @@ xcoff_link_add_symbols (abfd, info)
                      section = bfd_und_section_ptr;
                      value = 0;
                    }
-                 else if ((*sym_hash)->root.und_next != NULL
+                 else if ((*sym_hash)->root.u.undef.next != NULL
                           || info->hash->undefs_tail == &(*sym_hash)->root)
                    {
                      /* This symbol has been referenced.  In this
@@ -1895,7 +1893,7 @@ xcoff_link_add_symbols (abfd, info)
                  || (*sym_hash)->root.u.c.p->section != csect)
                {
                  /* We don't need the common csect we just created.  */
-                 csect->_raw_size = 0;
+                 csect->size = 0;
                }
              else
                {
@@ -1937,7 +1935,7 @@ xcoff_link_add_symbols (abfd, info)
         the .debug section, since we need to read it below in
         bfd_xcoff_size_dynamic_sections.  */
       if (strcmp (bfd_get_section_name (abfd, o), ".debug") != 0)
-       o->_raw_size = 0;
+       o->size = 0;
       o->lineno_count = 0;
 
       if ((o->flags & SEC_RELOC) != 0)
@@ -1955,8 +1953,8 @@ xcoff_link_add_symbols (abfd, info)
              if (*rel_csect == NULL)
                {
                  (*_bfd_error_handler)
-                   (_("%s: reloc %s:%d not in csect"),
-                    bfd_archive_filename (abfd), o->name, i);
+                   (_("%B: reloc %s:%d not in csect"),
+                    abfd, o->name, i);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -2511,7 +2509,7 @@ xcoff_sweep (info)
                o->flags |= SEC_MARK;
              else
                {
-                 o->_raw_size = 0;
+                 o->size = 0;
                  o->reloc_count = 0;
                  o->lineno_count = 0;
                }
@@ -3035,8 +3033,8 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
   /* We now know the final size of the .loader section.  Allocate
      space for it.  */
   lsec = xcoff_hash_table (info)->loader_section;
-  lsec->_raw_size = stoff + ldhdr->l_stlen;
-  lsec->contents = (bfd_byte *) bfd_zalloc (output_bfd, lsec->_raw_size);
+  lsec->size = stoff + ldhdr->l_stlen;
+  lsec->contents = (bfd_byte *) bfd_zalloc (output_bfd, lsec->size);
   if (lsec->contents == NULL)
     goto error_return;
 
@@ -3085,23 +3083,23 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
 
   /* Allocate space for the magic sections.  */
   sec = xcoff_hash_table (info)->linkage_section;
-  if (sec->_raw_size > 0)
+  if (sec->size > 0)
     {
-      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        goto error_return;
     }
   sec = xcoff_hash_table (info)->toc_section;
-  if (sec->_raw_size > 0)
+  if (sec->size > 0)
     {
-      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        goto error_return;
     }
   sec = xcoff_hash_table (info)->descriptor_section;
-  if (sec->_raw_size > 0)
+  if (sec->size > 0)
     {
-      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->_raw_size);
+      sec->contents = (bfd_byte *) bfd_zalloc (output_bfd, sec->size);
       if (sec->contents == NULL)
        goto error_return;
     }
@@ -3122,14 +3120,14 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
       if (sub->xvec != info->hash->creator)
        continue;
       subdeb = bfd_get_section_by_name (sub, ".debug");
-      if (subdeb == NULL || subdeb->_raw_size == 0)
+      if (subdeb == NULL || subdeb->size == 0)
        continue;
 
       if (info->strip == strip_all
          || info->strip == strip_debugger
          || info->discard == discard_all)
        {
-         subdeb->_raw_size = 0;
+         subdeb->size = 0;
          continue;
        }
 
@@ -3148,11 +3146,7 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
         bfd_alloc, because I expect that, when linking many files
         together, many of the strings will be the same.  Storing the
         strings in the hash table should save space in this case.  */
-      debug_contents = (bfd_byte *) bfd_malloc (subdeb->_raw_size);
-      if (debug_contents == NULL)
-       goto error_return;
-      if (! bfd_get_section_contents (sub, subdeb, (PTR) debug_contents,
-                                     (file_ptr) 0, subdeb->_raw_size))
+      if (!bfd_malloc_and_get_section (sub, subdeb, &debug_contents))
        goto error_return;
 
       csectpp = xcoff_data (sub)->csects;
@@ -3200,7 +3194,7 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
 
       /* Clear the size of subdeb, so that it is not included directly
         in the output file.  */
-      subdeb->_raw_size = 0;
+      subdeb->size = 0;
 
       if (! info->keep_memory)
        {
@@ -3210,7 +3204,7 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
     }
 
   if (info->strip != strip_all)
-    xcoff_hash_table (info)->debug_section->_raw_size =
+    xcoff_hash_table (info)->debug_section->size =
       _bfd_stringtab_size (debug_strtab);
 
   return TRUE;
@@ -3369,10 +3363,10 @@ xcoff_build_ldsyms (h, p)
       sec = xcoff_hash_table (ldinfo->info)->linkage_section;
       h->root.type = bfd_link_hash_defined;
       h->root.u.def.section = sec;
-      h->root.u.def.value = sec->_raw_size;
+      h->root.u.def.value = sec->size;
       h->smclas = XMC_GL;
       h->flags |= XCOFF_DEF_REGULAR;
-      sec->_raw_size += bfd_xcoff_glink_code_size(ldinfo->output_bfd);
+      sec->size += bfd_xcoff_glink_code_size(ldinfo->output_bfd);
 
       /* The global linkage code requires a TOC entry for the
         descriptor.  */
@@ -3396,8 +3390,8 @@ xcoff_build_ldsyms (h, p)
            return FALSE;
 
          hds->toc_section = xcoff_hash_table (ldinfo->info)->toc_section;
-         hds->u.toc_offset = hds->toc_section->_raw_size;
-         hds->toc_section->_raw_size += byte_size;
+         hds->u.toc_offset = hds->toc_section->size;
+         hds->toc_section->size += byte_size;
          ++xcoff_hash_table (ldinfo->info)->ldrel_count;
          ++hds->toc_section->reloc_count;
          hds->indx = -2;
@@ -3432,13 +3426,13 @@ xcoff_build_ldsyms (h, p)
          sec = xcoff_hash_table (ldinfo->info)->descriptor_section;
          h->root.type = bfd_link_hash_defined;
          h->root.u.def.section = sec;
-         h->root.u.def.value = sec->_raw_size;
+         h->root.u.def.value = sec->size;
          h->smclas = XMC_DS;
          h->flags |= XCOFF_DEF_REGULAR;
 
          /* The size of the function descriptor depends if this is an
             xcoff32 (12) or xcoff64 (24).  */
-         sec->_raw_size +=
+         sec->size +=
            bfd_xcoff_function_descriptor_size(ldinfo->output_bfd);
 
          /* A function descriptor uses two relocs: one for the
@@ -3465,10 +3459,10 @@ xcoff_build_ldsyms (h, p)
   if (h->root.type == bfd_link_hash_common
       && (! xcoff_hash_table (ldinfo->info)->gc
          || (h->flags & XCOFF_MARK) != 0)
-      && h->root.u.c.p->section->_raw_size == 0)
+      && h->root.u.c.p->section->size == 0)
     {
       BFD_ASSERT (bfd_is_com_section (h->root.u.c.p->section));
-      h->root.u.c.p->section->_raw_size = h->root.u.c.size;
+      h->root.u.c.p->section->size = h->root.u.c.size;
     }
 
   /* We need to add a symbol to the .loader section if it is mentioned
@@ -3618,8 +3612,10 @@ _bfd_xcoff_bfd_final_link (abfd, info)
 
              o->reloc_count += sec->reloc_count;
 
-             if (sec->_raw_size > max_contents_size)
-               max_contents_size = sec->_raw_size;
+             if (sec->rawsize > max_contents_size)
+               max_contents_size = sec->rawsize;
+             if (sec->size > max_contents_size)
+               max_contents_size = sec->size;
              if (sec->lineno_count > max_lineno_count)
                max_lineno_count = sec->lineno_count;
              if (coff_section_data (sec->owner, sec) != NULL
@@ -3722,11 +3718,11 @@ _bfd_xcoff_bfd_final_link (abfd, info)
                {
                  bfd_vma pageoff;
 
-                 BFD_ASSERT (o->_raw_size == 0);
+                 BFD_ASSERT (o->size == 0);
                  pageoff = sofar & (file_align - 1);
                  if (pageoff != 0)
                    {
-                     o->_raw_size = file_align - pageoff;
+                     o->size = file_align - pageoff;
                      sofar += file_align - pageoff;
                      o->flags |= SEC_HAS_CONTENTS;
                    }
@@ -3734,7 +3730,7 @@ _bfd_xcoff_bfd_final_link (abfd, info)
              else
                {
                  if ((o->flags & SEC_HAS_CONTENTS) != 0)
-                   sofar += BFD_ALIGN (o->_raw_size,
+                   sofar += BFD_ALIGN (o->size,
                                        1 << o->alignment_power);
                }
            }
@@ -4083,27 +4079,27 @@ _bfd_xcoff_bfd_final_link (abfd, info)
                  + xcoff_hash_table (info)->ldhdr.l_impoff));
   o = xcoff_hash_table (info)->loader_section;
   if (! bfd_set_section_contents (abfd, o->output_section, o->contents,
-                                 (file_ptr) o->output_offset, o->_raw_size))
+                                 (file_ptr) o->output_offset, o->size))
     goto error_return;
 
   /* Write out the magic sections.  */
   o = xcoff_hash_table (info)->linkage_section;
-  if (o->_raw_size > 0
+  if (o->size > 0
       && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
                                     (file_ptr) o->output_offset,
-                                    o->_raw_size))
+                                    o->size))
     goto error_return;
   o = xcoff_hash_table (info)->toc_section;
-  if (o->_raw_size > 0
+  if (o->size > 0
       && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
                                     (file_ptr) o->output_offset,
-                                    o->_raw_size))
+                                    o->size))
     goto error_return;
   o = xcoff_hash_table (info)->descriptor_section;
-  if (o->_raw_size > 0
+  if (o->size > 0
       && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
                                     (file_ptr) o->output_offset,
-                                    o->_raw_size))
+                                    o->size))
     goto error_return;
 
   /* Write out the string table.  */
@@ -4128,7 +4124,7 @@ _bfd_xcoff_bfd_final_link (abfd, info)
       struct bfd_strtab_hash *debug_strtab;
 
       debug_strtab = xcoff_hash_table (info)->debug_strtab;
-      BFD_ASSERT (o->output_section->_raw_size - o->output_offset
+      BFD_ASSERT (o->output_section->size - o->output_offset
                  >= _bfd_stringtab_size (debug_strtab));
       pos = o->output_section->filepos + o->output_offset;
       if (bfd_seek (abfd, pos, SEEK_SET) != 0)
@@ -4423,7 +4419,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
                 output section, as it does in the default linker
                 script.  */
              tocend = ((*csectpp)->output_section->vma
-                       + (*csectpp)->output_section->_raw_size);
+                       + (*csectpp)->output_section->size);
              for (inp = finfo->info->input_bfds;
                   inp != NULL;
                   inp = inp->link_next)
@@ -4435,7 +4431,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
                        bfd_vma new_toc_end;
                        new_toc_end = (o->output_section->vma
                                       + o->output_offset
-                                      + o->_cooked_size);
+                                      + o->size);
                        if (new_toc_end > tocend)
                          tocend = new_toc_end;
                      }
@@ -5053,7 +5049,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
        }
 
       if ((o->flags & SEC_HAS_CONTENTS) == 0
-         || o->_raw_size == 0
+         || o->size == 0
          || (o->flags & SEC_IN_MEMORY) != 0)
        continue;
 
@@ -5062,12 +5058,13 @@ xcoff_link_input_bfd (finfo, input_bfd)
       if (coff_section_data (input_bfd, o) != NULL
          && coff_section_data (input_bfd, o)->contents != NULL)
        contents = coff_section_data (input_bfd, o)->contents;
-      else {
-       if (! bfd_get_section_contents (input_bfd, o, finfo->contents,
-                                       (file_ptr) 0, o->_raw_size))
-         return FALSE;
-       contents = finfo->contents;
-      }
+      else
+       {
+         bfd_size_type sz = o->rawsize ? o->rawsize : o->size;
+         if (!bfd_get_section_contents (input_bfd, o, finfo->contents, 0, sz))
+           return FALSE;
+         contents = finfo->contents;
+       }
 
       if ((o->flags & SEC_RELOC) != 0)
        {
@@ -5285,9 +5282,8 @@ xcoff_link_input_bfd (finfo, input_bfd)
                      else
                        {
                          (*_bfd_error_handler)
-                           (_("%s: loader reloc in unrecognized section `%s'"),
-                            bfd_archive_filename (input_bfd),
-                            sec->name);
+                           (_("%B: loader reloc in unrecognized section `%A'"),
+                            input_bfd, sec);
                          bfd_set_error (bfd_error_nonrepresentable_section);
                          return FALSE;
                        }
@@ -5307,8 +5303,8 @@ xcoff_link_input_bfd (finfo, input_bfd)
                      if (h->ldindx < 0 && ! quiet)
                        {
                          (*_bfd_error_handler)
-                           (_("%s: `%s' in loader reloc but not loader sym"),
-                            bfd_archive_filename (input_bfd),
+                           (_("%B: `%s' in loader reloc but not loader sym"),
+                            input_bfd,
                             h->root.root.string);
                          bfd_set_error (bfd_error_bad_value);
                          return FALSE;
@@ -5322,10 +5318,8 @@ xcoff_link_input_bfd (finfo, input_bfd)
                      && ! quiet)
                    {
                      (*_bfd_error_handler)
-                       (_("%s: loader reloc in read-only section %s"),
-                        bfd_archive_filename (input_bfd),
-                        bfd_get_section_name (finfo->output_bfd,
-                                              o->output_section));
+                       (_("%B: loader reloc in read-only section %A"),
+                        input_bfd, o->output_section);
                      bfd_set_error (bfd_error_invalid_operation);
                      return FALSE;
                    }
@@ -5352,9 +5346,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
       /* Write out the modified section contents.  */
       if (! bfd_set_section_contents (output_bfd, o->output_section,
                                      contents, (file_ptr) o->output_offset,
-                                     (o->_cooked_size != 0
-                                      ? o->_cooked_size
-                                      : o->_raw_size)))
+                                     o->size))
        return FALSE;
     }
 
@@ -6051,7 +6043,7 @@ xcoff_reloc_link_order (output_bfd, finfo, output_section, link_order)
          abort ();
        case bfd_reloc_overflow:
          if (! ((*finfo->info->callbacks->reloc_overflow)
-                (finfo->info, link_order->u.reloc.p->u.name,
+                (finfo->info, NULL, link_order->u.reloc.p->u.name,
                  howto->name, addend, (bfd *) NULL, (asection *) NULL,
                  (bfd_vma) 0)))
            {
This page took 0.032945 seconds and 4 git commands to generate.