daily update
[deliverable/binutils-gdb.git] / bfd / aoutx.h
index e07d7bef39f24af21d1cde640dcd0d07b00885f9..c53ceacc03bf05ca3198206204ba2bc52897ba67 100644 (file)
@@ -1,6 +1,6 @@
 /* BFD semi-generic back-end for a.out binaries.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -786,6 +786,8 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        case bfd_mach_mips9000:
        case bfd_mach_mips10000:
        case bfd_mach_mips12000:
+       case bfd_mach_mips14000:
+       case bfd_mach_mips16000:
        case bfd_mach_mips16:
        case bfd_mach_mipsisa32:
        case bfd_mach_mipsisa32r2:
@@ -793,6 +795,7 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        case bfd_mach_mipsisa64:
        case bfd_mach_mipsisa64r2:
        case bfd_mach_mips_sb1:
+       case bfd_mach_mips_xlr:
          /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc.  */
          arch_flags = M_MIPS2;
          break;
@@ -1291,9 +1294,10 @@ aout_get_external_symbols (bfd *abfd)
     {
       bfd_size_type count;
       struct external_nlist *syms;
-      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),
@@ -1306,16 +1310,19 @@ 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;
-      if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
-         || bfd_bread (syms, amt, abfd) != amt)
-       {
-         free (syms);
-         return FALSE;
-       }
+      {
+       bfd_size_type amt;
+       amt = exec_hdr (abfd)->a_syms;
+       if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
+           || bfd_bread (syms, amt, abfd) != amt)
+         {
+           free (syms);
+           return FALSE;
+         }
+      }
 #endif
 
       obj_aout_external_syms (abfd) = syms;
@@ -1661,12 +1668,12 @@ NAME (aout, make_empty_symbol) (bfd *abfd)
 {
   bfd_size_type amt = sizeof (aout_symbol_type);
 
-  aout_symbol_type *new = bfd_zalloc (abfd, amt);
-  if (!new)
+  aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt);
+  if (!new_symbol)
     return NULL;
-  new->symbol.the_bfd = abfd;
+  new_symbol->symbol.the_bfd = abfd;
 
-  return &new->symbol;
+  return &new_symbol->symbol;
 }
 
 /* Translate a set of internal symbols into external symbols.  */
@@ -1739,9 +1746,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.  */
@@ -2159,7 +2169,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
@@ -2227,9 +2240,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
@@ -2948,13 +2966,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;
 
@@ -3960,11 +3981,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
@@ -4283,7 +4314,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)
        {
@@ -5554,22 +5591,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;
     }
 
This page took 0.026826 seconds and 4 git commands to generate.