X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Faoutx.h;h=b469b77c6263e38cb336541c8d31e43c16ca9b9a;hb=6b2f2842e1fb409fafa384eefe492ba5de50d9af;hp=09331aa0ca24d2924de8a3b87b256262aa0f9726;hpb=22184a77bedbe9a50b48f0bc50ff1f8898699a39;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/aoutx.h b/bfd/aoutx.h index 09331aa0ca..b469b77c62 100644 --- a/bfd/aoutx.h +++ b/bfd/aoutx.h @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -18,7 +18,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ /* SECTION @@ -1293,6 +1294,8 @@ aout_get_external_symbols (bfd *abfd) bfd_size_type amt; count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE; + if (count == 0) + return TRUE; /* Nothing to do. */ #ifdef USE_MMAP if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd), @@ -1305,7 +1308,7 @@ aout_get_external_symbols (bfd *abfd) later on. If we put them on the objalloc it might not be possible to free them. */ syms = bfd_malloc (count * EXTERNAL_NLIST_SIZE); - if (syms == NULL && count != 0) + if (syms == NULL) return FALSE; amt = exec_hdr (abfd)->a_syms; @@ -1738,9 +1741,12 @@ NAME (aout, slurp_symbol_table) (bfd *abfd) return FALSE; cached_size = obj_aout_external_sym_count (abfd); + if (cached_size == 0) + return TRUE; /* Nothing to do. */ + cached_size *= sizeof (aout_symbol_type); cached = bfd_zmalloc (cached_size); - if (cached == NULL && cached_size != 0) + if (cached == NULL) return FALSE; /* Convert from external symbol information to internal. */ @@ -2158,7 +2164,10 @@ NAME (aout, swap_ext_reloc_in) (bfd *abfd, >> RELOC_EXT_BITS_TYPE_SH_LITTLE); } - cache_ptr->howto = howto_table_ext + r_type; + if (r_type < TABLE_SIZE (howto_table_ext)) + cache_ptr->howto = howto_table_ext + r_type; + else + cache_ptr->howto = NULL; /* Base relative relocs are always against the symbol table, regardless of the setting of r_extern. r_extern just reflects @@ -2226,9 +2235,14 @@ NAME (aout, swap_std_reloc_in) (bfd *abfd, howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel + 16 * r_jmptable + 32 * r_relative); - BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std)); - cache_ptr->howto = howto_table_std + howto_idx; - BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1); + if (howto_idx < TABLE_SIZE (howto_table_std)) + { + cache_ptr->howto = howto_table_std + howto_idx; + if (cache_ptr->howto->type == (unsigned int) -1) + cache_ptr->howto = NULL; + } + else + cache_ptr->howto = NULL; /* Base relative relocs are always against the symbol table, regardless of the setting of r_extern. r_extern just reflects @@ -2279,20 +2293,25 @@ NAME (aout, slurp_reloc_table) (bfd *abfd, sec_ptr asect, asymbol **symbols) return FALSE; } + if (reloc_size == 0) + return TRUE; /* Nothing to be done. */ + if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0) return FALSE; each_size = obj_reloc_entry_size (abfd); count = reloc_size / each_size; + if (count == 0) + return TRUE; /* Nothing to be done. */ amt = count * sizeof (arelent); reloc_cache = bfd_zmalloc (amt); - if (reloc_cache == NULL && count != 0) + if (reloc_cache == NULL) return FALSE; relocs = bfd_malloc (reloc_size); - if (relocs == NULL && reloc_size != 0) + if (relocs == NULL) { free (reloc_cache); return FALSE; @@ -2942,13 +2961,16 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info) return FALSE; } + if (sym_count == 0) + return TRUE; /* Nothing to do. */ + /* We keep a list of the linker hash table entries that correspond to particular symbols. We could just look them up in the hash table, but keeping the list is more efficient. Perhaps this should be conditional on info->keep_memory. */ amt = sym_count * sizeof (struct aout_link_hash_entry *); sym_hash = bfd_alloc (abfd, amt); - if (sym_hash == NULL && sym_count != 0) + if (sym_hash == NULL) return FALSE; obj_aout_sym_hashes (abfd) = sym_hash; @@ -3954,11 +3976,21 @@ aout_link_input_section_std (struct aout_final_link_info *finfo, howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel + 16 * r_jmptable + 32 * r_relative); - BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std)); - howto = howto_table_std + howto_idx; + if (howto_idx < TABLE_SIZE (howto_table_std)) + howto = howto_table_std + howto_idx; + else + howto = NULL; } #endif + if (howto == NULL) + { + (*finfo->info->callbacks->einfo) + (_("%P: %B: unexpected relocation type\n"), input_bfd); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + if (relocatable) { /* We are generating a relocatable output file, and must @@ -4277,7 +4309,13 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo, r_addend = GET_SWORD (input_bfd, rel->r_addend); - BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext)); + if (r_type >= TABLE_SIZE (howto_table_ext)) + { + (*finfo->info->callbacks->einfo) + (_("%P: %B: unexpected relocation type\n"), input_bfd); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } if (relocatable) { @@ -5548,22 +5586,19 @@ NAME (aout, final_link) (bfd *abfd, exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd); /* Write out the string table, unless there are no symbols. */ + if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0) + goto error_return; if (abfd->symcount > 0) { - if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0 - || ! emit_stringtab (abfd, aout_info.strtab)) + if (!emit_stringtab (abfd, aout_info.strtab)) goto error_return; } - else if (obj_textsec (abfd)->reloc_count == 0 - && obj_datasec (abfd)->reloc_count == 0) + else { - bfd_byte b; - file_ptr pos; + bfd_byte b[BYTES_IN_WORD]; - b = 0; - pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1; - if (bfd_seek (abfd, pos, SEEK_SET) != 0 - || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1) + memset (b, 0, BYTES_IN_WORD); + if (bfd_bwrite (b, (bfd_size_type) BYTES_IN_WORD, abfd) != BYTES_IN_WORD) goto error_return; }