]> Git Repo - binutils.git/blobdiff - bfd/ecoff.c
* ecoff.c (ecoff_sizeof_headers): Align result to 16 byte
[binutils.git] / bfd / ecoff.c
index 3ff608486b242590d15ac5c0e023f04d06fa946b..c99d72453d64d7edf6f6833b3cbd5aab19ee40d1 100644 (file)
@@ -46,7 +46,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 static int ecoff_get_magic PARAMS ((bfd *abfd));
 static boolean ecoff_slurp_symbolic_header PARAMS ((bfd *abfd));
-static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
+static boolean ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
                                           asymbol *asym, int ext,
                                           asymbol **indirect_ptr_ptr));
 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
@@ -79,7 +79,7 @@ ecoff_mkobject (abfd)
                                bfd_zalloc (abfd, sizeof (ecoff_data_type)));
   if (abfd->tdata.ecoff_obj_data == NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
 
@@ -627,7 +627,7 @@ ecoff_slurp_symbolic_header (abfd)
   external_hdr_size = backend->debug_swap.external_hdr_size;
   if (bfd_get_symcount (abfd) != external_hdr_size)
     {
-      bfd_error = bad_value;
+      bfd_set_error (bfd_error_bad_value);
       return false;
     }
 
@@ -637,7 +637,7 @@ ecoff_slurp_symbolic_header (abfd)
       || (bfd_read (raw, external_hdr_size, 1, abfd)
          != external_hdr_size))
     {
-      bfd_error = system_call_error;
+      bfd_set_error (bfd_error_system_call);
       return false;
     }
   internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
@@ -645,7 +645,7 @@ ecoff_slurp_symbolic_header (abfd)
 
   if (internal_symhdr->magic != backend->debug_swap.sym_magic)
     {
-      bfd_error = bad_value;
+      bfd_set_error (bfd_error_bad_value);
       return false;
     }
 
@@ -730,7 +730,7 @@ ecoff_slurp_symbolic_info (abfd)
   raw = (PTR) bfd_alloc (abfd, raw_size);
   if (raw == NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
   if (bfd_seek (abfd,
@@ -739,7 +739,7 @@ ecoff_slurp_symbolic_info (abfd)
                SEEK_SET) != 0
       || bfd_read (raw, raw_size, 1, abfd) != raw_size)
     {
-      bfd_error = system_call_error;
+      bfd_set_error (bfd_error_system_call);
       bfd_release (abfd, raw);
       return false;
     }
@@ -781,7 +781,7 @@ ecoff_slurp_symbolic_info (abfd)
                               sizeof (struct fdr)));
   if (ecoff_data (abfd)->debug_info.fdr == NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
   external_fdr_size = backend->debug_swap.external_fdr_size;
@@ -817,7 +817,7 @@ ecoff_make_empty_symbol (abfd)
   new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
   if (new == (ecoff_symbol_type *) NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return (asymbol *) NULL;
     }
   memset (new, 0, sizeof *new);
@@ -831,7 +831,7 @@ ecoff_make_empty_symbol (abfd)
 
 /* Set the BFD flags and section for an ECOFF symbol.  */
 
-static void
+static boolean
 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
      bfd *abfd;
      SYMR *ecoff_sym;
@@ -859,7 +859,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->flags = BSF_DEBUGGING;
       asym->section = &bfd_und_section;
       *indirect_ptr_ptr = NULL;
-      return;
+      return true;
     }
 
   if (ECOFF_IS_STAB (ecoff_sym)
@@ -869,7 +869,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       asym->section = &bfd_ind_section;
       /* Pass this symbol on to the next call to this function.  */
       *indirect_ptr_ptr = asym;
-      return;
+      return true;
     }
 
   /* Most symbol types are just for debugging.  */
@@ -885,12 +885,12 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
       if (ECOFF_IS_STAB (ecoff_sym))
        {
          asym->flags = BSF_DEBUGGING;
-         return;
+         return true;
        }
       break;
     default:
       asym->flags = BSF_DEBUGGING;
-      return;
+      return true;
     }
 
   if (ext)
@@ -1042,6 +1042,11 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
                char *copy;
 
                copy = (char *) bfd_alloc (abfd, strlen (name) + 1);
+               if (!copy)
+                 {
+                   bfd_set_error (bfd_error_no_memory);
+                   return false;
+                 }
                strcpy (copy, name);
                section = bfd_make_section (abfd, copy);
              }
@@ -1049,6 +1054,11 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
            /* Build a reloc pointing to this constructor.  */
            reloc_chain =
              (arelent_chain *) bfd_alloc (abfd, sizeof (arelent_chain));
+           if (!reloc_chain)
+             {
+               bfd_set_error (bfd_error_no_memory);
+               return false;
+             }
            reloc_chain->relent.sym_ptr_ptr =
              bfd_get_section (asym)->symbol_ptr_ptr;
            reloc_chain->relent.address = section->_raw_size;
@@ -1079,6 +1089,7 @@ ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext, indirect_ptr_ptr)
          break;
        }
     }
+  return true;
 }
 
 /* Read an ECOFF symbol table.  */
@@ -1119,7 +1130,7 @@ ecoff_slurp_symbol_table (abfd)
   internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
   if (internal == NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
 
@@ -1136,8 +1147,9 @@ ecoff_slurp_symbol_table (abfd)
       (*swap_ext_in) (abfd, (PTR) eraw_src, &internal_esym);
       internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
                                   + internal_esym.asym.iss);
-      ecoff_set_symbol_info (abfd, &internal_esym.asym,
-                            &internal_ptr->symbol, 1, &indirect_ptr);
+      if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
+                            &internal_ptr->symbol, 1, &indirect_ptr))
+       return false;
       /* The alpha uses a negative ifd field for section symbols.  */
       if (internal_esym.ifd >= 0)
        internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
@@ -1171,8 +1183,9 @@ ecoff_slurp_symbol_table (abfd)
          internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ss
                                       + fdr_ptr->issBase
                                       + internal_sym.iss);
-         ecoff_set_symbol_info (abfd, &internal_sym,
-                                &internal_ptr->symbol, 0, &indirect_ptr);
+         if (!ecoff_set_symbol_info (abfd, &internal_sym,
+                                     &internal_ptr->symbol, 0, &indirect_ptr))
+           return false;
          internal_ptr->fdr = fdr_ptr;
          internal_ptr->local = true;
          internal_ptr->native = (PTR) lraw_src;
@@ -1795,7 +1808,7 @@ ecoff_slurp_reloc_table (abfd, section, symbols)
   if (internal_relocs == (arelent *) NULL
       || external_relocs == (char *) NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
   if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
@@ -1803,7 +1816,7 @@ ecoff_slurp_reloc_table (abfd, section, symbols)
   if (bfd_read (external_relocs, 1, external_relocs_size, abfd)
       != external_relocs_size)
     {
-      bfd_error = system_call_error;
+      bfd_set_error (bfd_error_system_call);
       return false;
     }
 
@@ -2127,9 +2140,10 @@ ecoff_sizeof_headers (abfd, reloc)
     if (strcmp (current->name, REGINFO) != 0)
       ++c;
 
-  return (bfd_coff_filhsz (abfd)
-         + bfd_coff_aoutsz (abfd)
-         + c * bfd_coff_scnhsz (abfd));
+  ret = (bfd_coff_filhsz (abfd)
+        + bfd_coff_aoutsz (abfd)
+        + c * bfd_coff_scnhsz (abfd));
+  return BFD_ALIGN (ret, 16);
 }
 
 /* Get the contents of a section.  This is where we handle reading the
@@ -2463,17 +2477,17 @@ ecoff_write_object_contents (abfd)
   asection *current;
   unsigned int count;
   bfd_size_type reloc_size;
-  unsigned long text_size;
-  unsigned long text_start;
-  unsigned long data_size;
-  unsigned long data_start;
-  unsigned long bss_size;
+  bfd_size_type text_size;
+  bfd_vma text_start;
+  bfd_size_type data_size;
+  bfd_vma data_start;
+  bfd_size_type bss_size;
   PTR buff;
   struct internal_filehdr internal_f;
   struct internal_aouthdr internal_a;
   int i;
 
-  bfd_error = system_call_error;
+  bfd_set_error (bfd_error_system_call);
 
   /* Determine where the sections and relocs will go in the output
      file.  */
@@ -2729,7 +2743,7 @@ ecoff_write_object_contents (abfd)
          buff = bfd_alloc (abfd, current->reloc_count * external_reloc_size);
          if (buff == NULL)
            {
-             bfd_error = no_memory;
+             bfd_set_error (bfd_error_no_memory);
              return false;
            }
 
@@ -2818,24 +2832,28 @@ ecoff_write_object_contents (abfd)
              == false)
            return false;
        }
-      else if ((abfd->flags & EXEC_P) != 0
-              && (abfd->flags & D_PAGED) != 0)
-       {
-         char c;
+    }
 
-         /* A demand paged executable must occupy an even number of
-            pages.  */
-         if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
-                       SEEK_SET) != 0)
-           return false;
-         if (bfd_read (&c, 1, 1, abfd) == 0)
-           c = 0;
-         if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
-                       SEEK_SET) != 0)
-           return false;
-         if (bfd_write (&c, 1, 1, abfd) != 1)
-           return false;      
-       }
+  /* The .bss section of a demand paged executable must receive an
+     entire page.  If there are symbols, the symbols will start on the
+     next page.  If there are no symbols, we must fill out the page by
+     hand.  */
+  if (bfd_get_symcount (abfd) == 0
+      && (abfd->flags & EXEC_P) != 0
+      && (abfd->flags & D_PAGED) != 0)
+    {
+      char c;
+
+      if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
+                   SEEK_SET) != 0)
+       return false;
+      if (bfd_read (&c, 1, 1, abfd) == 0)
+       c = 0;
+      if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos - 1,
+                   SEEK_SET) != 0)
+       return false;
+      if (bfd_write (&c, 1, 1, abfd) != 1)
+       return false;      
     }
 
   return true;
@@ -2963,7 +2981,7 @@ ecoff_slurp_armap (abfd)
       || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
          ^ (abfd->xvec->byteorder_big_p != false)))
     {
-      bfd_error = wrong_format;
+      bfd_set_error (bfd_error_wrong_format);
       return false;
     }
 
@@ -2978,13 +2996,13 @@ ecoff_slurp_armap (abfd)
   raw_armap = (char *) bfd_alloc (abfd, parsed_size);
   if (raw_armap == (char *) NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return false;
     }
     
   if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
     {
-      bfd_error = malformed_archive;
+      bfd_set_error (bfd_error_malformed_archive);
       bfd_release (abfd, (PTR) raw_armap);
       return false;
     }
@@ -3047,6 +3065,12 @@ ecoff_slurp_armap (abfd)
   symdef_ptr = ((struct symdef *)
                bfd_alloc (abfd,
                           ardata->symdef_count * sizeof (struct symdef)));
+  if (!symdef_ptr)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return false;
+    }
+
   ardata->symdefs = (carsym *) symdef_ptr;
 
   raw_ptr = raw_armap + 4;
@@ -3158,6 +3182,11 @@ ecoff_write_armap (abfd, elength, map, orl_count, stridx)
     return false;
   
   hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
+  if (!hashtable)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return false;
+    }
 
   current = abfd->archive_head;
   last_elt = current;
@@ -3244,7 +3273,7 @@ ecoff_archive_p (abfd)
   if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
       || strncmp (armag, ARMAG, SARMAG) != 0)
     {
-      bfd_error = wrong_format;
+      bfd_set_error (bfd_error_wrong_format);
       return (bfd_target *) NULL;
     }
 
@@ -3256,7 +3285,7 @@ ecoff_archive_p (abfd)
 
   if (bfd_ardata (abfd) == (struct artdata *) NULL)
     {
-      bfd_error = no_memory;
+      bfd_set_error (bfd_error_no_memory);
       return (bfd_target *) NULL;
     }
 
@@ -3308,15 +3337,23 @@ ecoff_link_hash_newfunc (entry, table, string)
   if (ret == (struct ecoff_link_hash_entry *) NULL)
     ret = ((struct ecoff_link_hash_entry *)
           bfd_hash_allocate (table, sizeof (struct ecoff_link_hash_entry)));
+  if (ret == (struct ecoff_link_hash_entry *) NULL)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return NULL;
+    }
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct ecoff_link_hash_entry *)
         _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
                                 table, string));
 
-  /* Set local fields.  */
-  ret->indx = -1;
-  ret->abfd = NULL;
+  if (ret)
+    {
+      /* Set local fields.  */
+      ret->indx = -1;
+      ret->abfd = NULL;
+    }
   memset (&ret->esym, 0, sizeof ret->esym);
 
   return (struct bfd_hash_entry *) ret;
@@ -3334,7 +3371,7 @@ ecoff_bfd_link_hash_table_create (abfd)
         malloc (sizeof (struct ecoff_link_hash_table)));
   if (!ret)
       {
-       bfd_error = no_memory;
+       bfd_set_error (bfd_error_no_memory);
        return NULL;
       }
   if (! _bfd_link_hash_table_init (&ret->root, abfd,
@@ -3380,7 +3417,7 @@ ecoff_bfd_link_add_symbols (abfd, info)
     case bfd_archive:
       return ecoff_link_add_archive_symbols (abfd, info);
     default:
-      bfd_error = wrong_format;
+      bfd_set_error (bfd_error_wrong_format);
       return false;
     }
 }
@@ -3407,7 +3444,7 @@ ecoff_link_add_archive_symbols (abfd, info)
 
   if (! bfd_has_map (abfd))
     {
-      bfd_error = no_symbols;
+      bfd_set_error (bfd_error_no_symbols);
       return false;
     }
 
@@ -3710,6 +3747,11 @@ ecoff_link_add_externals (abfd, info, external_ext, ssext)
   sym_hash = ((struct ecoff_link_hash_entry **)
              bfd_alloc (abfd,
                         ext_count * sizeof (struct bfd_link_hash_entry *)));
+  if (!sym_hash)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return false;
+    }
   ecoff_data (abfd)->sym_hashes = sym_hash;
 
   ext_ptr = (char *) external_ext;
@@ -3895,7 +3937,6 @@ ecoff_bfd_final_link (abfd, info)
   /* We accumulate the debugging information counts in the symbolic
      header.  */
   symhdr = &debug->symbolic_header;
-  symhdr->magic = backend->debug_swap.sym_magic;
   symhdr->vstamp = 0;
   symhdr->ilineMax = 0;
   symhdr->cbLine = 0;
This page took 0.038702 seconds and 4 git commands to generate.