diff options
Diffstat (limited to 'bfd/ecoff.c')
-rw-r--r-- | bfd/ecoff.c | 106 |
1 files changed, 35 insertions, 71 deletions
diff --git a/bfd/ecoff.c b/bfd/ecoff.c index cfc5ae1b9fa..eba6236fd6b 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -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,29 +74,26 @@ static unsigned int ecoff_armap_hash PARAMS ((const char *, unsigned int *, unsigned int, unsigned int)); /* 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, kept_section, moving_line_filepos, */ - 0, NULL, NULL, 0, + /* entsize, kept_section, moving_line_filepos, */ + 0, NULL, 0, /* target_index, used_by_bfd, constructor_chain, owner, */ 0, NULL, NULL, NULL, /* symbol, */ @@ -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 */ @@ -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); @@ -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) @@ -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,9 +4567,9 @@ 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 relocatable output, the relocs were @@ -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; } |