gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / som.c
index d7d4d8f845f37938a7aa7519ae82738a4ac82992..887d9b187ef88b2b9d255f4243d3bf1cb4995325 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -1945,7 +1945,7 @@ som_swap_lst_header_in (struct som_external_lst_header *src,
 /* Perform some initialization for an object.  Save results of this
    initialization in the BFD.  */
 
-static const bfd_target *
+static bfd_cleanup
 som_object_setup (bfd *abfd,
                  struct som_header *file_hdrp,
                  struct som_exec_auxhdr *aux_hdrp,
@@ -2060,7 +2060,7 @@ som_object_setup (bfd *abfd,
                                  + current_offset);
   obj_som_exec_data (abfd)->system_id = file_hdrp->system_id;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 /* Convert all of the space and subspace info into BFD sections.  Each space
@@ -2088,14 +2088,11 @@ setup_sections (bfd *abfd,
       bfd_set_error (bfd_error_no_memory);
       goto error_return;
     }
-  space_strings = bfd_malloc (amt + 1);
-  if (space_strings == NULL)
-    goto error_return;
-
   if (bfd_seek (abfd, current_offset + file_hdr->space_strings_location,
                SEEK_SET) != 0)
     goto error_return;
-  if (bfd_bread (space_strings, amt, abfd) != amt)
+  space_strings = (char *) _bfd_malloc_and_read (abfd, amt + 1, amt);
+  if (space_strings == NULL)
     goto error_return;
   /* Make sure that the string table is NUL terminated.  */
   space_strings[amt] = 0;
@@ -2200,6 +2197,9 @@ setup_sections (bfd *abfd,
          som_swap_subspace_dictionary_in (&ext_subspace, &subspace);
 
          /* Setup the subspace name string.  */
+         if (subspace.name >= file_hdr->space_strings_size)
+           goto error_return;
+
          subspace_name = subspace.name + space_strings;
 
          amt = strlen (subspace_name) + 1;
@@ -2369,27 +2369,20 @@ setup_sections (bfd *abfd,
   for (i = 0; i < total_subspaces; i++)
     subspace_sections[i]->target_index = i;
 
-  if (space_strings != NULL)
-    free (space_strings);
-
-  if (subspace_sections != NULL)
-    free (subspace_sections);
-
+  free (space_strings);
+  free (subspace_sections);
   return TRUE;
 
  error_return:
-  if (space_strings != NULL)
-    free (space_strings);
-
-  if (subspace_sections != NULL)
-    free (subspace_sections);
+  free (space_strings);
+  free (subspace_sections);
   return FALSE;
 }
 
 
 /* Read in a SOM object and make it into a BFD.  */
 
-static const bfd_target *
+static bfd_cleanup
 som_object_p (bfd *abfd)
 {
   struct som_external_header ext_file_hdr;
@@ -4528,12 +4521,11 @@ som_build_and_write_symbol_table (bfd *abfd)
   if (bfd_bwrite ((void *) som_symtab, symtab_size, abfd) != symtab_size)
     goto error_return;
 
-  if (som_symtab != NULL)
-    free (som_symtab);
+  free (som_symtab);
   return TRUE;
+
  error_return:
-  if (som_symtab != NULL)
-    free (som_symtab);
+  free (som_symtab);
   return FALSE;
 }
 
@@ -4578,15 +4570,11 @@ som_slurp_string_table (bfd *abfd)
     }
 
   /* Allocate and read in the string table.  */
-  amt = obj_som_stringtab_size (abfd);
-  stringtab = bfd_zmalloc (amt);
-  if (stringtab == NULL)
-    return FALSE;
-
   if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) != 0)
     return FALSE;
-
-  if (bfd_bread (stringtab, amt, abfd) != amt)
+  amt = obj_som_stringtab_size (abfd);
+  stringtab = (char *) _bfd_malloc_and_read (abfd, amt, amt);
+  if (stringtab == NULL)
     return FALSE;
 
   /* Save our results and return success.  */
@@ -4659,7 +4647,7 @@ som_slurp_symbol_table (bfd *abfd)
   size_t symsize = sizeof (struct som_external_symbol_dictionary_record);
   char *stringtab;
   struct som_external_symbol_dictionary_record *buf = NULL, *bufp, *endbufp;
-  som_symbol_type *sym, *symbase;
+  som_symbol_type *sym, *symbase = NULL;
   size_t amt;
 
   /* Return saved value if it exists.  */
@@ -4675,27 +4663,26 @@ som_slurp_symbol_table (bfd *abfd)
 
   stringtab = obj_som_stringtab (abfd);
 
-  if (_bfd_mul_overflow (symbol_count, sizeof (som_symbol_type), &amt))
+  /* Read in the external SOM representation.  */
+  if (_bfd_mul_overflow (symbol_count, symsize, &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
       goto error_return;
     }
-  symbase = bfd_zmalloc (amt);
-  if (symbase == NULL)
+  if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) != 0)
+    goto error_return;
+  buf = (struct som_external_symbol_dictionary_record *)
+    _bfd_malloc_and_read (abfd, amt, amt);
+  if (buf == NULL)
     goto error_return;
 
-  /* Read in the external SOM representation.  */
-  if (_bfd_mul_overflow (symbol_count, symsize, &amt))
+  if (_bfd_mul_overflow (symbol_count, sizeof (som_symbol_type), &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
       goto error_return;
     }
-  buf = bfd_malloc (amt);
-  if (buf == NULL)
-    goto error_return;
-  if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) != 0)
-    goto error_return;
-  if (bfd_bread (buf, amt, abfd) != amt)
+  symbase = bfd_zmalloc (amt);
+  if (symbase == NULL)
     goto error_return;
 
   /* Iterate over all the symbols and internalize them.  */
@@ -4832,13 +4819,12 @@ som_slurp_symbol_table (bfd *abfd)
   /* Save our results and return success.  */
   obj_som_symtab (abfd) = symbase;
  successful_return:
-  if (buf != NULL)
-    free (buf);
+  free (buf);
   return (TRUE);
 
  error_return:
-  if (buf != NULL)
-    free (buf);
+  free (symbase);
+  free (buf);
   return FALSE;
 }
 
@@ -5233,8 +5219,7 @@ som_set_reloc_info (unsigned char *fixup,
                      if (!bfd_malloc_and_get_section (section->owner, section,
                                                       &contents))
                        {
-                         if (contents != NULL)
-                           free (contents);
+                         free (contents);
                          return (unsigned) -1;
                        }
                      section->contents = contents;
@@ -5295,17 +5280,13 @@ som_slurp_reloc_table (bfd *abfd,
      parsed.  We must do so now to know how many relocations exist.  */
   if (section->reloc_count == (unsigned) -1)
     {
-      amt = fixup_stream_size;
-      external_relocs = bfd_malloc (amt);
-      if (external_relocs == NULL)
-       return FALSE;
       /* Read in the external forms.  */
-      if (bfd_seek (abfd,
-                   obj_som_reloc_filepos (abfd) + section->rel_filepos,
-                   SEEK_SET)
-         != 0)
+      if (bfd_seek (abfd, obj_som_reloc_filepos (abfd) + section->rel_filepos,
+                   SEEK_SET) != 0)
        return FALSE;
-      if (bfd_bread (external_relocs, amt, abfd) != amt)
+      amt = fixup_stream_size;
+      external_relocs = _bfd_malloc_and_read (abfd, amt, amt);
+      if (external_relocs == NULL)
        return FALSE;
 
       /* Let callers know how many relocations found.
@@ -5919,23 +5900,20 @@ som_bfd_count_ar_symbols (bfd *abfd,
 
   lst_filepos = bfd_tell (abfd) - sizeof (struct som_external_lst_header);
 
+  /* Read in the hash table.  The hash table is an array of 32-bit
+     file offsets which point to the hash chains.  */
   if (_bfd_mul_overflow (lst_header->hash_size, 4, &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
       return FALSE;
     }
-  hash_table = bfd_malloc (amt);
+  hash_table = _bfd_malloc_and_read (abfd, amt, amt);
   if (hash_table == NULL && lst_header->hash_size != 0)
     goto error_return;
 
   /* Don't forget to initialize the counter!  */
   *count = 0;
 
-  /* Read in the hash table.  The hash table is an array of 32-bit
-     file offsets which point to the hash chains.  */
-  if (bfd_bread ((void *) hash_table, amt, abfd) != amt)
-    goto error_return;
-
   /* Walk each chain counting the number of symbols found on that particular
      chain.  */
   for (i = 0; i < lst_header->hash_size; i++)
@@ -5987,13 +5965,11 @@ som_bfd_count_ar_symbols (bfd *abfd,
          (*count)++;
        }
     }
-  if (hash_table != NULL)
-    free (hash_table);
+  free (hash_table);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
+  free (hash_table);
   return FALSE;
 }
 
@@ -6014,20 +5990,18 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
   unsigned int string_loc;
 
   lst_filepos = bfd_tell (abfd) - sizeof (struct som_external_lst_header);
+
+  /* Read in the hash table.  The has table is an array of 32bit file offsets
+     which point to the hash chains.  */
   if (_bfd_mul_overflow (lst_header->hash_size, 4, &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
       return FALSE;
     }
-  hash_table = bfd_malloc (amt);
+  hash_table = _bfd_malloc_and_read (abfd, amt, amt);
   if (hash_table == NULL && lst_header->hash_size != 0)
     goto error_return;
 
-  /* Read in the hash table.  The has table is an array of 32bit file offsets
-     which point to the hash chains.  */
-  if (bfd_bread ((void *) hash_table, amt, abfd) != amt)
-    goto error_return;
-
   /* Seek to and read in the SOM dictionary.  We will need this to fill
      in the carsym's filepos field.  */
   if (bfd_seek (abfd, lst_filepos + lst_header->dir_loc, SEEK_SET) != 0)
@@ -6039,13 +6013,11 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
       bfd_set_error (bfd_error_file_too_big);
       goto error_return;
     }
-  som_dict = bfd_malloc (amt);
+  som_dict = (struct som_external_som_entry *)
+    _bfd_malloc_and_read (abfd, amt, amt);
   if (som_dict == NULL && lst_header->module_count != 0)
     goto error_return;
 
-  if (bfd_bread ((void *) som_dict, amt, abfd) != amt)
-    goto error_return;
-
   string_loc = lst_header->string_loc;
 
   /* Walk each chain filling in the carsyms as we go along.  */
@@ -6092,12 +6064,9 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
          bfd_set_error (bfd_error_no_memory);
          goto error_return;
        }
-      name = bfd_zalloc (abfd, (bfd_size_type) len + 1);
+      name = (char *) _bfd_alloc_and_read (abfd, len + 1, len);
       if (!name)
        goto error_return;
-      if (bfd_bread (name, (bfd_size_type) len, abfd) != len)
-       goto error_return;
-
       name[len] = 0;
       set->name = name;
 
@@ -6146,12 +6115,9 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
              bfd_set_error (bfd_error_no_memory);
              goto error_return;
            }
-         name = bfd_zalloc (abfd, (bfd_size_type) len + 1);
+         name = (char *) _bfd_alloc_and_read (abfd, len + 1, len);
          if (!name)
            goto error_return;
-
-         if (bfd_bread (name, (bfd_size_type) len, abfd) != len)
-           goto error_return;
          name[len] = 0;
          set->name = name;
 
@@ -6172,17 +6138,13 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
     }
   /* If we haven't died by now, then we successfully read the entire
      archive symbol table.  */
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
+  free (hash_table);
+  free (som_dict);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
+  free (hash_table);
+  free (som_dict);
   return FALSE;
 }
 
@@ -6631,29 +6593,19 @@ som_bfd_ar_write_symbol_stuff (bfd *abfd,
   if (bfd_bwrite ((void *) strings, amt, abfd) != amt)
     goto error_return;
 
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
-  if (last_hash_entry != NULL)
-    free (last_hash_entry);
-  if (lst_syms != NULL)
-    free (lst_syms);
-  if (strings != NULL)
-    free (strings);
+  free (hash_table);
+  free (som_dict);
+  free (last_hash_entry);
+  free (lst_syms);
+  free (strings);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
-  if (last_hash_entry != NULL)
-    free (last_hash_entry);
-  if (lst_syms != NULL)
-    free (lst_syms);
-  if (strings != NULL)
-    free (strings);
+  free (hash_table);
+  free (som_dict);
+  free (last_hash_entry);
+  free (lst_syms);
+  free (strings);
 
   return FALSE;
 }
@@ -6680,7 +6632,7 @@ som_write_armap (bfd *abfd,
   unsigned int module_count;
 
   /* We'll use this for the archive's date and mode later.  */
-  if (stat (abfd->filename, &statbuf) != 0)
+  if (stat (bfd_get_filename (abfd), &statbuf) != 0)
     {
       bfd_set_error (bfd_error_system_call);
       return FALSE;
@@ -6805,7 +6757,7 @@ som_bfd_free_cached_info (bfd *abfd)
     {
       asection *o;
 
-#define FREE(x) if (x != NULL) { free (x); x = NULL; }
+#define FREE(x) do { free (x); x = NULL; } while (0)
       /* Free the native string and symbol tables.  */
       FREE (obj_som_symtab (abfd));
       FREE (obj_som_stringtab (abfd));
This page took 0.029447 seconds and 4 git commands to generate.