X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Fcofflink.c;h=27ac20e80da814065c61f250c0eac5072e7615f5;hb=5dbc8b372f3a15fa4dce65d460a3cce7ed081f6c;hp=7bcc1ca77da436f38ce46a3606605e8f0374bac9;hpb=e6f7f6d14f7e1acba0cf41726616a270e7d3c121;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/cofflink.c b/bfd/cofflink.c index 7bcc1ca77d..27ac20e80d 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -1,5 +1,5 @@ /* COFF specific linker code. - Copyright (C) 1994-2019 Free Software Foundation, Inc. + Copyright (C) 1994-2020 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -109,7 +109,7 @@ struct bfd_link_hash_table * _bfd_coff_link_hash_table_create (bfd *abfd) { struct coff_link_hash_table *ret; - bfd_size_type amt = sizeof (struct coff_link_hash_table); + size_t amt = sizeof (struct coff_link_hash_table); ret = (struct coff_link_hash_table *) bfd_malloc (amt); if (ret == NULL) @@ -689,7 +689,7 @@ _bfd_coff_final_link (bfd *abfd, rel_filepos += o->reloc_count * relsz; /* In PE COFF, if there are at least 0xffff relocations an extra relocation will be written out to encode the count. */ - if (obj_pe (abfd) && o->reloc_count >= 0xffff) + if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff) rel_filepos += relsz; } @@ -993,41 +993,20 @@ _bfd_coff_final_link (bfd *abfd, coff_debug_merge_hash_table_free (&flaginfo.debug_merge); debug_merge_allocated = FALSE; - if (flaginfo.internal_syms != NULL) - { - free (flaginfo.internal_syms); - flaginfo.internal_syms = NULL; - } - if (flaginfo.sec_ptrs != NULL) - { - free (flaginfo.sec_ptrs); - flaginfo.sec_ptrs = NULL; - } - if (flaginfo.sym_indices != NULL) - { - free (flaginfo.sym_indices); - flaginfo.sym_indices = NULL; - } - if (flaginfo.linenos != NULL) - { - free (flaginfo.linenos); - flaginfo.linenos = NULL; - } - if (flaginfo.contents != NULL) - { - free (flaginfo.contents); - flaginfo.contents = NULL; - } - if (flaginfo.external_relocs != NULL) - { - free (flaginfo.external_relocs); - flaginfo.external_relocs = NULL; - } - if (flaginfo.internal_relocs != NULL) - { - free (flaginfo.internal_relocs); - flaginfo.internal_relocs = NULL; - } + free (flaginfo.internal_syms); + flaginfo.internal_syms = NULL; + free (flaginfo.sec_ptrs); + flaginfo.sec_ptrs = NULL; + free (flaginfo.sym_indices); + flaginfo.sym_indices = NULL; + free (flaginfo.linenos); + flaginfo.linenos = NULL; + free (flaginfo.contents); + flaginfo.contents = NULL; + free (flaginfo.external_relocs); + flaginfo.external_relocs = NULL; + free (flaginfo.internal_relocs); + flaginfo.internal_relocs = NULL; /* The value of the last C_FILE symbol is supposed to be the symbol index of the first external symbol. Write it out again if @@ -1066,11 +1045,8 @@ _bfd_coff_final_link (bfd *abfd, goto error_return; /* The outsyms buffer is used by _bfd_coff_write_global_sym. */ - if (flaginfo.outsyms != NULL) - { - free (flaginfo.outsyms); - flaginfo.outsyms = NULL; - } + free (flaginfo.outsyms); + flaginfo.outsyms = NULL; if (bfd_link_relocatable (info) && max_output_reloc_count > 0) { @@ -1108,7 +1084,7 @@ _bfd_coff_final_link (bfd *abfd, if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0) goto error_return; - if (obj_pe (abfd) && o->reloc_count >= 0xffff) + if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff) { /* In PE COFF, write the count of relocs as the first reloc. The header overflow bit will be set @@ -1141,10 +1117,8 @@ _bfd_coff_final_link (bfd *abfd, for (i = 0; i < abfd->section_count; i++) { - if (flaginfo.section_info[i].relocs != NULL) - free (flaginfo.section_info[i].relocs); - if (flaginfo.section_info[i].rel_hashes != NULL) - free (flaginfo.section_info[i].rel_hashes); + free (flaginfo.section_info[i].relocs); + free (flaginfo.section_info[i].rel_hashes); } free (flaginfo.section_info); flaginfo.section_info = NULL; @@ -1203,31 +1177,20 @@ _bfd_coff_final_link (bfd *abfd, for (i = 0; i < abfd->section_count; i++) { - if (flaginfo.section_info[i].relocs != NULL) - free (flaginfo.section_info[i].relocs); - if (flaginfo.section_info[i].rel_hashes != NULL) - free (flaginfo.section_info[i].rel_hashes); + free (flaginfo.section_info[i].relocs); + free (flaginfo.section_info[i].rel_hashes); } free (flaginfo.section_info); } - if (flaginfo.internal_syms != NULL) - free (flaginfo.internal_syms); - if (flaginfo.sec_ptrs != NULL) - free (flaginfo.sec_ptrs); - if (flaginfo.sym_indices != NULL) - free (flaginfo.sym_indices); - if (flaginfo.outsyms != NULL) - free (flaginfo.outsyms); - if (flaginfo.linenos != NULL) - free (flaginfo.linenos); - if (flaginfo.contents != NULL) - free (flaginfo.contents); - if (flaginfo.external_relocs != NULL) - free (flaginfo.external_relocs); - if (flaginfo.internal_relocs != NULL) - free (flaginfo.internal_relocs); - if (external_relocs != NULL) - free (external_relocs); + free (flaginfo.internal_syms); + free (flaginfo.sec_ptrs); + free (flaginfo.sym_indices); + free (flaginfo.outsyms); + free (flaginfo.linenos); + free (flaginfo.contents); + free (flaginfo.external_relocs); + free (flaginfo.internal_relocs); + free (external_relocs); return FALSE; } @@ -1286,8 +1249,7 @@ process_embedded_commands (bfd *output_bfd, if (!bfd_malloc_and_get_section (abfd, sec, ©)) { - if (copy != NULL) - free (copy); + free (copy); return 0; } e = (char *) copy + sec->size; @@ -1647,7 +1609,7 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd) struct coff_debug_merge_element **epp; bfd_byte *esl, *eslend; struct internal_syment *islp; - bfd_size_type amt; + size_t amt; name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf); if (name == NULL) @@ -2541,7 +2503,8 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd) /* Write out the modified section contents. */ if (secdata == NULL || secdata->stab_info == NULL) { - file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd); + file_ptr loc = (o->output_offset + * bfd_octets_per_byte (output_bfd, o)); if (! bfd_set_section_contents (output_bfd, o->output_section, contents, loc, o->size)) return FALSE; @@ -2833,7 +2796,7 @@ _bfd_coff_reloc_link_order (bfd *output_bfd, return FALSE; rstat = _bfd_relocate_contents (howto, output_bfd, - (bfd_vma) link_order->u.reloc.p->addend,\ + (bfd_vma) link_order->u.reloc.p->addend, buf); switch (rstat) { @@ -2846,14 +2809,14 @@ _bfd_coff_reloc_link_order (bfd *output_bfd, (*flaginfo->info->callbacks->reloc_overflow) (flaginfo->info, NULL, (link_order->type == bfd_section_reloc_link_order - ? bfd_section_name (output_bfd, - link_order->u.reloc.p->u.section) + ? bfd_section_name (link_order->u.reloc.p->u.section) : link_order->u.reloc.p->u.name), howto->name, link_order->u.reloc.p->addend, (bfd *) NULL, (asection *) NULL, (bfd_vma) 0); break; } - loc = link_order->offset * bfd_octets_per_byte (output_bfd); + loc = link_order->offset * bfd_octets_per_byte (output_bfd, + output_section); ok = bfd_set_section_contents (output_bfd, output_section, buf, loc, size); free (buf);