daily update
[deliverable/binutils-gdb.git] / bfd / ecoff.c
index 4d9b3d49d5e777e5871a8bdcb42bde1f97a897db..eba6236fd6b18b9920a9479d5266a8f92b55f178 100644 (file)
@@ -1,6 +1,6 @@
 /* Generic ECOFF (Extended-COFF) routines.
    Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-   2002, 2003 Free Software Foundation, Inc.
+   2002, 2003, 2004 Free Software Foundation, Inc.
    Original version by Per Bothner.
    Full support added by Ian Lance Taylor, ian@cygnus.com.
 
@@ -74,35 +74,32 @@ static unsigned int ecoff_armap_hash
   PARAMS ((const char *, unsigned int *, unsigned int, unsigned int));
 \f
 /* This stuff is somewhat copied from coffcode.h.  */
-
 static asection bfd_debug_section =
 {
-  /* name,   id,  index, next, flags, user_set_vma, reloc_done,    */
-  "*DEBUG*", 0,   0,     NULL, 0,     0,            0,
+  /* name,      id,  index, next, flags, user_set_vma,             */
+     "*DEBUG*", 0,   0,     NULL, 0,     0,
   /* linker_mark, linker_has_input, gc_mark, segment_mark,         */
      0,           0,                0,       0,
-  /* sec_info_type, use_rela_p, has_tls_reloc,                     */
-     0,                    0,          0,
-  /* need_finalize_relax, has_gp_reloc,                            */
+  /* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc,       */
+     0,                    0,          0,             0,
+  /* need_finalize_relax, reloc_done,                              */
      0,                          0,
-  /* flag13, flag14, flag15, flag16, flag20, flag24,               */
-     0,      0,      0,      0,      0,             0,
-  /* vma, lma, _cooked_size, _raw_size,                            */
-     0,   0,   0,            0,
+  /* vma, lma, size, rawsize,                                      */
+     0,   0,   0,    0,
   /* output_offset, output_section, alignment_power,               */
      0,             NULL,           0,
   /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */
      NULL,       NULL,        0,           0,       0,
   /* line_filepos, userdata, contents, lineno, lineno_count,       */
      0,            NULL,     NULL,     NULL,   0,
-  /* entsize, comdat, moving_line_filepos,                         */
-     0,       NULL,   0,
+  /* entsize, kept_section, moving_line_filepos,                  */
+     0,       NULL,         0,
   /* target_index, used_by_bfd, constructor_chain, owner,          */
      0,            NULL,        NULL,              NULL,
   /* symbol,                                                       */
-     (struct symbol_cache_entry *) NULL,
+     (struct bfd_symbol *) NULL,
   /* symbol_ptr_ptr,                                               */
-     (struct symbol_cache_entry **) NULL,
+     (struct bfd_symbol **) NULL,
   /* link_order_head, link_order_tail                              */
      NULL,            NULL
 };
@@ -908,7 +905,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, weak)
              return FALSE;
            reloc_chain->relent.sym_ptr_ptr =
              bfd_get_section (asym)->symbol_ptr_ptr;
-           reloc_chain->relent.address = section->_raw_size;
+           reloc_chain->relent.address = section->size;
            reloc_chain->relent.addend = asym->value;
            reloc_chain->relent.howto =
              ecoff_backend (abfd)->constructor_reloc;
@@ -928,7 +925,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, weak)
 
            reloc_chain->next = section->constructor_chain;
            section->constructor_chain = reloc_chain;
-           section->_raw_size += bitsize / 8;
+           section->size += bitsize / 8;
 
 #endif /* 0 */
 
@@ -1062,7 +1059,7 @@ _bfd_ecoff_get_symtab_upper_bound (abfd)
 /* Get the canonical symbols.  */
 
 long
-_bfd_ecoff_get_symtab (abfd, alocation)
+_bfd_ecoff_canonicalize_symtab (abfd, alocation)
      bfd *abfd;
      asymbol **alocation;
 {
@@ -2118,7 +2115,7 @@ ecoff_compute_section_file_positions (abfd)
         really in the section.  Each entry is 8 bytes.  We store this
         away in line_filepos before increasing the section size.  */
       if (strcmp (current->name, _PDATA) == 0)
-       current->line_filepos = current->_raw_size / 8;
+       current->line_filepos = current->size / 8;
 
       alignment_power = current->alignment_power;
 
@@ -2179,16 +2176,16 @@ ecoff_compute_section_file_positions (abfd)
       if ((current->flags & (SEC_HAS_CONTENTS | SEC_LOAD)) != 0)
        current->filepos = file_sofar;
 
-      sofar += current->_raw_size;
+      sofar += current->size;
       if ((current->flags & SEC_HAS_CONTENTS) != 0)
-       file_sofar += current->_raw_size;
+       file_sofar += current->size;
 
       /* Make sure that this section is of the right size too.  */
       old_sofar = sofar;
       sofar = BFD_ALIGN (sofar, 1 << alignment_power);
       if ((current->flags & SEC_HAS_CONTENTS) != 0)
        file_sofar = BFD_ALIGN (file_sofar, 1 << alignment_power);
-      current->_raw_size += sofar - old_sofar;
+      current->size += sofar - old_sofar;
     }
 
   free (sorted_hdrs);
@@ -2262,7 +2259,7 @@ bfd_boolean
 _bfd_ecoff_set_section_contents (abfd, section, location, offset, count)
      bfd *abfd;
      asection *section;
-     PTR location;
+     const PTR location;
      file_ptr offset;
      bfd_size_type count;
 {
@@ -2550,7 +2547,7 @@ _bfd_ecoff_write_object_contents (abfd)
        section.s_vaddr = vma;
 
       section.s_paddr = current->lma;
-      section.s_size = bfd_get_section_size_before_reloc (current);
+      section.s_size = current->size;
 
       /* If this section is unloadable then the scnptr will be 0.  */
       if ((current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
@@ -2601,7 +2598,7 @@ _bfd_ecoff_write_object_contents (abfd)
          || (section.s_flags & STYP_ECOFF_FINI) != 0
          || section.s_flags == STYP_RCONST)
        {
-         text_size += bfd_get_section_size_before_reloc (current);
+         text_size += current->size;
          if (! set_text_start || text_start > vma)
            {
              text_start = vma;
@@ -2617,7 +2614,7 @@ _bfd_ecoff_write_object_contents (abfd)
               || section.s_flags == STYP_XDATA
               || (section.s_flags & STYP_GOT) != 0)
        {
-         data_size += bfd_get_section_size_before_reloc (current);
+         data_size += current->size;
          if (! set_data_start || data_start > vma)
            {
              data_start = vma;
@@ -2626,7 +2623,7 @@ _bfd_ecoff_write_object_contents (abfd)
        }
       else if ((section.s_flags & STYP_BSS) != 0
               || (section.s_flags & STYP_SBSS) != 0)
-       bss_size += bfd_get_section_size_before_reloc (current);
+       bss_size += current->size;
       else if (section.s_flags == 0
               || (section.s_flags & STYP_ECOFF_LIB) != 0
               || section.s_flags == STYP_COMMENT)
@@ -3566,9 +3563,9 @@ ecoff_link_add_archive_symbols (abfd, info)
             entry if it is the tail, because that would lose any
             entries we add to the list later on.  */
          if (*pundef != info->hash->undefs_tail)
-           *pundef = (*pundef)->next;
+           *pundef = (*pundef)->und_next;
          else
-           pundef = &(*pundef)->next;
+           pundef = &(*pundef)->und_next;
          continue;
        }
 
@@ -3578,7 +3575,7 @@ ecoff_link_add_archive_symbols (abfd, info)
         other object format.  */
       if (h->type != bfd_link_hash_undefined)
        {
-         pundef = &(*pundef)->next;
+         pundef = &(*pundef)->und_next;
          continue;
        }
 
@@ -3590,7 +3587,7 @@ ecoff_link_add_archive_symbols (abfd, info)
       if (file_offset == 0)
        {
          /* Nothing in this slot.  */
-         pundef = &(*pundef)->next;
+         pundef = &(*pundef)->und_next;
          continue;
        }
 
@@ -3621,7 +3618,7 @@ ecoff_link_add_archive_symbols (abfd, info)
 
          if (! found)
            {
-             pundef = &(*pundef)->next;
+             pundef = &(*pundef)->und_next;
              continue;
            }
 
@@ -3643,7 +3640,7 @@ ecoff_link_add_archive_symbols (abfd, info)
       if (! ecoff_link_add_object_symbols (element, info))
        return FALSE;
 
-      pundef = &(*pundef)->next;
+      pundef = &(*pundef)->und_next;
     }
 
   return TRUE;
@@ -4129,7 +4126,7 @@ _bfd_ecoff_bfd_final_link (abfd, info)
 
       if (bfd_get_flavour (input_bfd) == bfd_target_ecoff_flavour)
        {
-         /* Abitrarily set the symbolic header vstamp to the vstamp
+         /* Arbitrarily set the symbolic header vstamp to the vstamp
             of the first object file in the link.  */
          if (symhdr->vstamp == 0)
            symhdr->vstamp
@@ -4160,7 +4157,7 @@ _bfd_ecoff_bfd_final_link (abfd, info)
                            ecoff_link_write_external,
                            (PTR) &einfo);
 
-  if (info->relocateable)
+  if (info->relocatable)
     {
       /* We need to make a pass over the link_orders to count up the
         number of relocations we will need to output, so that we know
@@ -4190,7 +4187,7 @@ _bfd_ecoff_bfd_final_link (abfd, info)
 
   bfd_ecoff_debug_free (handle, abfd, debug, &backend->debug_swap, info);
 
-  if (info->relocateable)
+  if (info->relocatable)
     {
       /* Now reset the reloc_count field of the sections in the output
         BFD to 0, so that we can use them to keep track of how many
@@ -4210,7 +4207,7 @@ _bfd_ecoff_bfd_final_link (abfd, info)
        ecoff_data (abfd)->gp = (h->u.def.value
                                 + h->u.def.section->output_section->vma
                                 + h->u.def.section->output_offset);
-      else if (info->relocateable)
+      else if (info->relocatable)
        {
          bfd_vma lo;
 
@@ -4526,14 +4523,10 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
 {
   asection *input_section;
   bfd *input_bfd;
-  struct ecoff_section_tdata *section_tdata;
-  bfd_size_type raw_size;
-  bfd_size_type cooked_size;
   bfd_byte *contents = NULL;
   bfd_size_type external_reloc_size;
   bfd_size_type external_relocs_size;
   PTR external_relocs = NULL;
-  bfd_size_type amt;
 
   BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
 
@@ -4542,57 +4535,28 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
 
   input_section = link_order->u.indirect.section;
   input_bfd = input_section->owner;
-  section_tdata = ecoff_section_data (input_bfd, input_section);
-
-  raw_size = input_section->_raw_size;
-  cooked_size = input_section->_cooked_size;
-  if (cooked_size == 0)
-    cooked_size = raw_size;
 
   BFD_ASSERT (input_section->output_section == output_section);
   BFD_ASSERT (input_section->output_offset == link_order->offset);
-  BFD_ASSERT (cooked_size == link_order->size);
+  BFD_ASSERT (input_section->size == link_order->size);
 
-  /* Get the section contents.  We allocate memory for the larger of
-     the size before relocating and the size after relocating.  */
-  amt = raw_size >= cooked_size ? raw_size : cooked_size;
-  contents = (bfd_byte *) bfd_malloc (amt);
-  if (contents == NULL && amt != 0)
+  /* Get the section contents.  */
+  if (!bfd_malloc_and_get_section (input_bfd, input_section, &contents))
     goto error_return;
 
-  /* If we are relaxing, the contents may have already been read into
-     memory, in which case we copy them into our new buffer.  We don't
-     simply reuse the old buffer in case cooked_size > raw_size.  */
-  if (section_tdata != (struct ecoff_section_tdata *) NULL
-      && section_tdata->contents != (bfd_byte *) NULL)
-    memcpy (contents, section_tdata->contents, (size_t) raw_size);
-  else
-    {
-      if (! bfd_get_section_contents (input_bfd, input_section,
-                                     (PTR) contents,
-                                     (file_ptr) 0, raw_size))
-       goto error_return;
-    }
-
   /* Get the relocs.  If we are relaxing MIPS code, they will already
      have been read in.  Otherwise, we read them in now.  */
   external_reloc_size = ecoff_backend (input_bfd)->external_reloc_size;
   external_relocs_size = external_reloc_size * input_section->reloc_count;
 
-  if (section_tdata != (struct ecoff_section_tdata *) NULL
-      && section_tdata->external_relocs != NULL)
-    external_relocs = section_tdata->external_relocs;
-  else
-    {
-      external_relocs = (PTR) bfd_malloc (external_relocs_size);
-      if (external_relocs == NULL && external_relocs_size != 0)
-       goto error_return;
+  external_relocs = (PTR) bfd_malloc (external_relocs_size);
+  if (external_relocs == NULL && external_relocs_size != 0)
+    goto error_return;
 
-      if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
-         || (bfd_bread (external_relocs, external_relocs_size, input_bfd)
-             != external_relocs_size))
-       goto error_return;
-    }
+  if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
+      || (bfd_bread (external_relocs, external_relocs_size, input_bfd)
+         != external_relocs_size))
+    goto error_return;
 
   /* Relocate the section contents.  */
   if (! ((*ecoff_backend (input_bfd)->relocate_section)
@@ -4603,16 +4567,16 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
   /* Write out the relocated section.  */
   if (! bfd_set_section_contents (output_bfd,
                                  output_section,
-                                 (PTR) contents,
-                                 (file_ptr) input_section->output_offset,
-                                 cooked_size))
+                                 contents,
+                                 input_section->output_offset,
+                                 input_section->size))
     goto error_return;
 
-  /* If we are producing relocateable output, the relocs were
+  /* If we are producing relocatable output, the relocs were
      modified, and we write them out now.  We use the reloc_count
      field of output_section to keep track of the number of relocs we
      have output so far.  */
-  if (info->relocateable)
+  if (info->relocatable)
     {
       file_ptr pos = (output_section->rel_filepos
                      + output_section->reloc_count * external_reloc_size);
@@ -4625,14 +4589,14 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order)
 
   if (contents != NULL)
     free (contents);
-  if (external_relocs != NULL && section_tdata == NULL)
+  if (external_relocs != NULL)
     free (external_relocs);
   return TRUE;
 
  error_return:
   if (contents != NULL)
     free (contents);
-  if (external_relocs != NULL && section_tdata == NULL)
+  if (external_relocs != NULL)
     free (external_relocs);
   return FALSE;
 }
This page took 0.029334 seconds and 4 git commands to generate.