Add libctf to update-copyright.py
[deliverable/binutils-gdb.git] / bfd / ecoff.c
index 1d9e385b2b5b0fdac6e5fa26b5c9c80511649a04..798e37a5e30b79db7045dedbacb2365303ffdb02 100644 (file)
 \f
 /* This stuff is somewhat copied from coffcode.h.  */
 static asection bfd_debug_section =
-{
-  /* name,     id,  section_id, index, next, prev, flags,        */
-     "*DEBUG*", 0,   0,                 0,     NULL, NULL, 0,
-  /* user_set_vma,        */
-     0,
-  /* linker_mark, linker_has_input, gc_mark, compress_status,     */
-     0,                  0,                1,       0,
-  /* segment_mark, sec_info_type, use_rela_p,                     */
-     0,                   0,             0,
-  /* sec_flg0, sec_flg1, sec_flg2, sec_flg3, sec_flg4, sec_flg5,   */
-     0,               0,        0,        0,        0,        0,
-  /* vma, lma, size, rawsize, compressed_size, relax, relax_count, */
-     0,          0,   0,    0,       0,               0,     0,
-  /* output_offset, output_section, alignment_power,              */
-     0,                    NULL,           0,
-  /* relocation, orelocation, reloc_count, filepos, rel_filepos,   */
-     NULL,      NULL,        0,           0,       0,
-  /* line_filepos, userdata, contents, lineno, lineno_count,      */
-     0,                   NULL,     NULL,     NULL,   0,
-  /* entsize, kept_section, moving_line_filepos,                  */
-     0,              NULL,         0,
-  /* target_index, used_by_bfd, constructor_chain, owner,         */
-     0,                   NULL,        NULL,              NULL,
-  /* symbol,                                                      */
-     NULL,
-  /* symbol_ptr_ptr,                                              */
-     NULL,
-  /* map_head, map_tail                                                   */
-     { NULL }, { NULL }
-};
+  BFD_FAKE_SECTION (bfd_debug_section, NULL, "*DEBUG*", 0, 0);
 
 /* Create an ECOFF object.  */
 
@@ -156,14 +127,14 @@ _bfd_ecoff_new_section_hook (bfd *abfd, asection *section)
     { _INIT,   SEC_ALLOC | SEC_CODE | SEC_LOAD },
     { _FINI,   SEC_ALLOC | SEC_CODE | SEC_LOAD },
     { _DATA,   SEC_ALLOC | SEC_DATA | SEC_LOAD },
-    { _SDATA,  SEC_ALLOC | SEC_DATA | SEC_LOAD },
+    { _SDATA,  SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_SMALL_DATA },
     { _RDATA,  SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
-    { _LIT8,   SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
-    { _LIT4,   SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
+    { _LIT8,   SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY | SEC_SMALL_DATA},
+    { _LIT4,   SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY | SEC_SMALL_DATA},
     { _RCONST, SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
     { _PDATA,  SEC_ALLOC | SEC_DATA | SEC_LOAD | SEC_READONLY},
     { _BSS,    SEC_ALLOC},
-    { _SBSS,   SEC_ALLOC},
+    { _SBSS,   SEC_ALLOC | SEC_SMALL_DATA},
     /* An Irix 4 shared libary.  */
     { _LIB,    SEC_COFF_SHARED_LIBRARY}
   };
@@ -412,16 +383,19 @@ _bfd_ecoff_styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
          || styp_flags == STYP_PDATA
          || styp_flags == STYP_RCONST)
        sec_flags |= SEC_READONLY;
+      if (styp_flags & STYP_SDATA)
+       sec_flags |= SEC_SMALL_DATA;
     }
-  else if ((styp_flags & STYP_BSS)
-          || (styp_flags & STYP_SBSS))
+  else if (styp_flags & STYP_SBSS)
+    sec_flags |= SEC_ALLOC | SEC_SMALL_DATA;
+  else if (styp_flags & STYP_BSS)
     sec_flags |= SEC_ALLOC;
   else if ((styp_flags & STYP_INFO) || styp_flags == STYP_COMMENT)
     sec_flags |= SEC_NEVER_LOAD;
   else if ((styp_flags & STYP_LITA)
           || (styp_flags & STYP_LIT8)
           || (styp_flags & STYP_LIT4))
-    sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
+    sec_flags |= SEC_DATA |SEC_SMALL_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
   else if (styp_flags & STYP_ECOFF_LIB)
     sec_flags |= SEC_COFF_SHARED_LIBRARY;
   else
@@ -465,13 +439,12 @@ ecoff_slurp_symbolic_header (bfd *abfd)
     }
 
   /* Read the symbolic information header.  */
-  raw = bfd_malloc (external_hdr_size);
+  if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) != 0)
+    goto error_return;
+  raw = _bfd_malloc_and_read (abfd, external_hdr_size, external_hdr_size);
   if (raw == NULL)
     goto error_return;
 
-  if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) != 0
-      || bfd_bread (raw, external_hdr_size, abfd) != external_hdr_size)
-    goto error_return;
   internal_symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
   (*backend->debug_swap.swap_hdr_in) (abfd, raw, internal_symhdr);
 
@@ -484,12 +457,10 @@ ecoff_slurp_symbolic_header (bfd *abfd)
   /* Now we can get the correct number of symbols.  */
   abfd->symcount = internal_symhdr->isymMax + internal_symhdr->iextMax;
 
-  if (raw != NULL)
-    free (raw);
+  free (raw);
   return TRUE;
  error_return:
-  if (raw != NULL)
-    free (raw);
+  free (raw);
   return FALSE;
 }
 
@@ -571,18 +542,13 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
       ecoff_data (abfd)->sym_filepos = 0;
       return TRUE;
     }
-  raw = bfd_alloc (abfd, raw_size);
-  if (raw == NULL)
-    return FALSE;
-
   pos = ecoff_data (abfd)->sym_filepos;
   pos += backend->debug_swap.external_hdr_size;
-  if (bfd_seek (abfd, pos, SEEK_SET) != 0
-      || bfd_bread (raw, raw_size, abfd) != raw_size)
-    {
-      bfd_release (abfd, raw);
-      return FALSE;
-    }
+  if (bfd_seek (abfd, pos, SEEK_SET) != 0)
+    return FALSE;
+  raw = _bfd_alloc_and_read (abfd, raw_size, raw_size);
+  if (raw == NULL)
+    return FALSE;
 
   ecoff_data (abfd)->raw_syments = raw;
 
@@ -647,8 +613,11 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
    faster assembler code.  This is what we use for the small common
    section.  */
 static asection ecoff_scom_section;
-static asymbol ecoff_scom_symbol;
-static asymbol *ecoff_scom_symbol_ptr;
+static const asymbol ecoff_scom_symbol =
+  GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section);
+static asection ecoff_scom_section =
+  BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol,
+                   SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA);
 
 /* Create an empty symbol.  */
 
@@ -790,19 +759,6 @@ ecoff_set_symbol_info (bfd *abfd,
        }
       /* Fall through.  */
     case scSCommon:
-      if (ecoff_scom_section.name == NULL)
-       {
-         /* Initialize the small common section.  */
-         ecoff_scom_section.name = SCOMMON;
-         ecoff_scom_section.flags = SEC_IS_COMMON;
-         ecoff_scom_section.output_section = &ecoff_scom_section;
-         ecoff_scom_section.symbol = &ecoff_scom_symbol;
-         ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
-         ecoff_scom_symbol.name = SCOMMON;
-         ecoff_scom_symbol.flags = BSF_SECTION_SYM;
-         ecoff_scom_symbol.section = &ecoff_scom_section;
-         ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
-       }
       asym->section = &ecoff_scom_section;
       asym->flags = 0;
       break;
@@ -1100,7 +1056,7 @@ ecoff_emit_aggregate (bfd *abfd,
 /* Convert the type information to string format.  */
 
 static char *
-ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
+ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx, char *buff)
 {
   union aux_ext *aux_ptr;
   int bigendian;
@@ -1115,9 +1071,8 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
   unsigned int basic_type;
   int i;
   char buffer1[1024];
-  static char buffer2[1024];
   char *p1 = buffer1;
-  char *p2 = buffer2;
+  char *p2 = buff;
   RNDXR rndx;
 
   aux_ptr = ecoff_data (abfd)->debug_info.external_aux + fdr->iauxBase;
@@ -1283,7 +1238,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
       break;
     }
 
-  p1 += strlen (buffer1);
+  p1 += strlen (p1);
 
   /* If this is a bitfield, get the bitsize.  */
   if (u.ti.fBitfield)
@@ -1292,7 +1247,6 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
 
       bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
       sprintf (p1, " : %d", bitsize);
-      p1 += strlen (buffer1);
     }
 
   /* Deal with any qualifiers.  */
@@ -1376,7 +1330,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
                               (long) (qualifiers[j].stride));
 
                    else
-                     sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
+                     sprintf (p2, " {%ld bits}", (long) qualifiers[j].stride);
 
                    p2 += strlen (p2);
                    strcpy (p2, "] of ");
@@ -1389,7 +1343,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
     }
 
   strcpy (p2, buffer1);
-  return buffer2;
+  return buff;
 }
 
 /* Return information about ECOFF symbol SYMBOL in RET.  */
@@ -1558,13 +1512,16 @@ _bfd_ecoff_print_symbol (bfd *abfd,
                if (ECOFF_IS_STAB (&ecoff_ext.asym))
                  ;
                else if (ecoffsymbol (symbol)->local)
-                 /* xgettext:c-format */
-                 fprintf (file, _("\n      End+1 symbol: %-7ld   Type:  %s"),
-                          ((long)
-                           (AUX_GET_ISYM (bigendian,
-                                          &aux_base[ecoff_ext.asym.index])
-                            + sym_base)),
-                          ecoff_type_to_string (abfd, fdr, indx + 1));
+                 {
+                   char buff[1024];
+                   /* xgettext:c-format */
+                   fprintf (file, _("\n      End+1 symbol: %-7ld   Type:  %s"),
+                            ((long)
+                             (AUX_GET_ISYM (bigendian,
+                                            &aux_base[ecoff_ext.asym.index])
+                              + sym_base)),
+                            ecoff_type_to_string (abfd, fdr, indx + 1, buff));
+                 }
                else
                  fprintf (file, _("\n      Local symbol: %ld"),
                           ((long) indx
@@ -1590,8 +1547,11 @@ _bfd_ecoff_print_symbol (bfd *abfd,
 
              default:
                if (! ECOFF_IS_STAB (&ecoff_ext.asym))
-                 fprintf (file, _("\n      Type: %s"),
-                          ecoff_type_to_string (abfd, fdr, indx));
+                 {
+                   char buff[1024];
+                   fprintf (file, _("\n      Type: %s"),
+                            ecoff_type_to_string (abfd, fdr, indx, buff));
+                 }
                break;
              }
          }
@@ -1611,7 +1571,7 @@ ecoff_slurp_reloc_table (bfd *abfd,
   arelent *internal_relocs;
   bfd_size_type external_reloc_size;
   bfd_size_type amt;
-  char *external_relocs;
+  bfd_byte *external_relocs;
   arelent *rptr;
   unsigned int i;
 
@@ -1625,12 +1585,10 @@ ecoff_slurp_reloc_table (bfd *abfd,
 
   external_reloc_size = backend->external_reloc_size;
   amt = external_reloc_size * section->reloc_count;
-  external_relocs = (char *) bfd_alloc (abfd, amt);
-  if (external_relocs == NULL)
-    return FALSE;
   if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
     return FALSE;
-  if (bfd_bread (external_relocs, amt, abfd) != amt)
+  external_relocs = _bfd_malloc_and_read (abfd, amt, amt);
+  if (external_relocs == NULL)
     return FALSE;
 
   amt = section->reloc_count;
@@ -1638,7 +1596,7 @@ ecoff_slurp_reloc_table (bfd *abfd,
   internal_relocs = (arelent *) bfd_alloc (abfd, amt);
   if (internal_relocs == NULL)
     {
-      bfd_release (abfd, external_relocs);
+      free (external_relocs);
       return FALSE;
     }
 
@@ -1706,7 +1664,7 @@ ecoff_slurp_reloc_table (bfd *abfd,
       (*backend->adjust_reloc_in) (abfd, &intern, rptr);
     }
 
-  bfd_release (abfd, external_relocs);
+  free (external_relocs);
 
   section->relocation = internal_relocs;
 
@@ -2800,14 +2758,12 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
 
   if (reloc_buff != NULL)
     bfd_release (abfd, reloc_buff);
-  if (buff != NULL)
-    free (buff);
+  free (buff);
   return TRUE;
  error_return:
   if (reloc_buff != NULL)
     bfd_release (abfd, reloc_buff);
-  if (buff != NULL)
-    free (buff);
+  free (buff);
   return FALSE;
 }
 \f
@@ -2886,7 +2842,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   char nextname[17];
   unsigned int i;
   struct areltdata *mapdata;
-  bfd_size_type parsed_size;
+  bfd_size_type parsed_size, stringsize;
   char *raw_armap;
   struct artdata *ardata;
   unsigned int count;
@@ -2898,9 +2854,9 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   /* Get the name of the first element.  */
   i = bfd_bread ((void *) nextname, (bfd_size_type) 16, abfd);
   if (i == 0)
-      return TRUE;
+    return TRUE;
   if (i != 16)
-      return FALSE;
+    return FALSE;
 
   if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
     return FALSE;
@@ -2945,21 +2901,22 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   parsed_size = mapdata->parsed_size;
   free (mapdata);
 
-  raw_armap = (char *) bfd_alloc (abfd, parsed_size);
-  if (raw_armap == NULL)
-    return FALSE;
-
-  if (bfd_bread ((void *) raw_armap, parsed_size, abfd) != parsed_size)
+  if (parsed_size + 1 < 9)
     {
-      if (bfd_get_error () != bfd_error_system_call)
-       bfd_set_error (bfd_error_malformed_archive);
-      bfd_release (abfd, (void *) raw_armap);
+      bfd_set_error (bfd_error_malformed_archive);
       return FALSE;
     }
 
+  raw_armap = (char *) _bfd_alloc_and_read (abfd, parsed_size + 1, parsed_size);
+  if (raw_armap == NULL)
+    return FALSE;
+  raw_armap[parsed_size] = 0;
+
   ardata->tdata = (void *) raw_armap;
 
   count = H_GET_32 (abfd, raw_armap);
+  if ((parsed_size - 8) / 8 < count)
+    goto error_malformed;
 
   ardata->symdef_count = 0;
   ardata->cache = NULL;
@@ -2967,6 +2924,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   /* This code used to overlay the symdefs over the raw archive data,
      but that doesn't work on a 64 bit host.  */
   stringbase = raw_armap + count * 8 + 8;
+  stringsize = parsed_size - (count * 8 + 8);
 
 #ifdef CHECK_ARMAP_HASH
   {
@@ -3014,7 +2972,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   amt *= sizeof (carsym);
   symdef_ptr = (carsym *) bfd_alloc (abfd, amt);
   if (!symdef_ptr)
-    return FALSE;
+    goto error_exit;
 
   ardata->symdefs = symdef_ptr;
 
@@ -3027,6 +2985,8 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
       if (file_offset == 0)
        continue;
       name_offset = H_GET_32 (abfd, raw_ptr);
+      if (name_offset > stringsize)
+       goto error_malformed;
       symdef_ptr->name = stringbase + name_offset;
       symdef_ptr->file_offset = file_offset;
       ++symdef_ptr;
@@ -3035,10 +2995,17 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   ardata->first_file_filepos = bfd_tell (abfd);
   /* Pad to an even boundary.  */
   ardata->first_file_filepos += ardata->first_file_filepos % 2;
-
   abfd->has_armap = TRUE;
-
   return TRUE;
+
+ error_malformed:
+  bfd_set_error (bfd_error_malformed_archive);
+ error_exit:
+  ardata->symdef_count = 0;
+  ardata->symdefs = NULL;
+  ardata->tdata = NULL;
+  bfd_release (abfd, raw_armap);
+  return FALSE;
 }
 
 /* Write out an armap.  */
@@ -3098,7 +3065,7 @@ _bfd_ecoff_write_armap (bfd *abfd,
      complain that the index is out of date.  Actually, the Ultrix
      linker just checks the archive name; the GNU linker may check the
      date.  */
-  stat (abfd->filename, &statbuf);
+  stat (bfd_get_filename (abfd), &statbuf);
   _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
                    (long) (statbuf.st_mtime + 60));
 
@@ -3396,19 +3363,6 @@ ecoff_link_add_externals (bfd *abfd,
            }
          /* Fall through.  */
        case scSCommon:
-         if (ecoff_scom_section.name == NULL)
-           {
-             /* Initialize the small common section.  */
-             ecoff_scom_section.name = SCOMMON;
-             ecoff_scom_section.flags = SEC_IS_COMMON;
-             ecoff_scom_section.output_section = &ecoff_scom_section;
-             ecoff_scom_section.symbol = &ecoff_scom_symbol;
-             ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
-             ecoff_scom_symbol.name = SCOMMON;
-             ecoff_scom_symbol.flags = BSF_SECTION_SYM;
-             ecoff_scom_symbol.section = &ecoff_scom_section;
-             ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
-           }
          section = &ecoff_scom_section;
          break;
        case scSUndefined:
@@ -3503,38 +3457,30 @@ ecoff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
   symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
 
   /* Read in the external symbols and external strings.  */
+  if (bfd_seek (abfd, symhdr->cbExtOffset, SEEK_SET) != 0)
+    return FALSE;
   external_ext_size = ecoff_backend (abfd)->debug_swap.external_ext_size;
   esize = symhdr->iextMax * external_ext_size;
-  external_ext = bfd_malloc (esize);
+  external_ext = _bfd_malloc_and_read (abfd, esize, esize);
   if (external_ext == NULL && esize != 0)
     goto error_return;
 
-  if (bfd_seek (abfd, (file_ptr) symhdr->cbExtOffset, SEEK_SET) != 0
-      || bfd_bread (external_ext, esize, abfd) != esize)
+  if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0)
     goto error_return;
-
-  ssext = (char *) bfd_malloc ((bfd_size_type) symhdr->issExtMax);
+  ssext = (char *) _bfd_malloc_and_read (abfd, symhdr->issExtMax,
+                                        symhdr->issExtMax);
   if (ssext == NULL && symhdr->issExtMax != 0)
     goto error_return;
 
-  if (bfd_seek (abfd, (file_ptr) symhdr->cbSsExtOffset, SEEK_SET) != 0
-      || (bfd_bread (ssext, (bfd_size_type) symhdr->issExtMax, abfd)
-         != (bfd_size_type) symhdr->issExtMax))
-    goto error_return;
-
   result = ecoff_link_add_externals (abfd, info, external_ext, ssext);
 
-  if (ssext != NULL)
-    free (ssext);
-  if (external_ext != NULL)
-    free (external_ext);
+  free (ssext);
+  free (external_ext);
   return result;
 
  error_return:
-  if (ssext != NULL)
-    free (ssext);
-  if (external_ext != NULL)
-    free (external_ext);
+  free (ssext);
+  free (external_ext);
   return FALSE;
 }
 
@@ -3775,14 +3721,13 @@ ecoff_final_link_debug_accumulate (bfd *output_bfd,
          ret = FALSE;                                                  \
          goto return_something;                                        \
        }                                                               \
-      debug->ptr = (type) bfd_malloc (amt);                            \
-      if (debug->ptr == NULL)                                          \
+      if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0)         \
        {                                                               \
          ret = FALSE;                                                  \
          goto return_something;                                        \
        }                                                               \
-      if (bfd_seek (input_bfd, symhdr->offset, SEEK_SET) != 0          \
-         || bfd_bread (debug->ptr, amt, input_bfd) != amt)             \
+      debug->ptr = (type) _bfd_malloc_and_read (input_bfd, amt, amt);  \
+      if (debug->ptr == NULL)                                          \
        {                                                               \
          ret = FALSE;                                                  \
          goto return_something;                                        \
@@ -3817,24 +3762,15 @@ ecoff_final_link_debug_accumulate (bfd *output_bfd,
  return_something:
   if (ecoff_data (input_bfd)->raw_syments == NULL)
     {
-      if (debug->line != NULL)
-       free (debug->line);
-      if (debug->external_dnr != NULL)
-       free (debug->external_dnr);
-      if (debug->external_pdr != NULL)
-       free (debug->external_pdr);
-      if (debug->external_sym != NULL)
-       free (debug->external_sym);
-      if (debug->external_opt != NULL)
-       free (debug->external_opt);
-      if (debug->external_aux != NULL)
-       free (debug->external_aux);
-      if (debug->ss != NULL)
-       free (debug->ss);
-      if (debug->external_fdr != NULL)
-       free (debug->external_fdr);
-      if (debug->external_rfd != NULL)
-       free (debug->external_rfd);
+      free (debug->line);
+      free (debug->external_dnr);
+      free (debug->external_pdr);
+      free (debug->external_sym);
+      free (debug->external_opt);
+      free (debug->external_aux);
+      free (debug->ss);
+      free (debug->external_fdr);
+      free (debug->external_rfd);
 
       /* Make sure we don't accidentally follow one of these pointers
         into freed memory.  */
@@ -3887,13 +3823,11 @@ ecoff_indirect_link_order (bfd *output_bfd,
   external_reloc_size = ecoff_backend (input_bfd)->external_reloc_size;
   external_relocs_size = external_reloc_size * input_section->reloc_count;
 
-  external_relocs = bfd_malloc (external_relocs_size);
-  if (external_relocs == NULL && external_relocs_size != 0)
+  if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0)
     goto error_return;
-
-  if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
-      || (bfd_bread (external_relocs, external_relocs_size, input_bfd)
-         != external_relocs_size))
+  external_relocs = _bfd_malloc_and_read (input_bfd, external_relocs_size,
+                                         external_relocs_size);
+  if (external_relocs == NULL && external_relocs_size != 0)
     goto error_return;
 
   /* Relocate the section contents.  */
@@ -3925,17 +3859,13 @@ ecoff_indirect_link_order (bfd *output_bfd,
       output_section->reloc_count += input_section->reloc_count;
     }
 
-  if (contents != NULL)
-    free (contents);
-  if (external_relocs != NULL)
-    free (external_relocs);
+  free (contents);
+  free (external_relocs);
   return TRUE;
 
  error_return:
-  if (contents != NULL)
-    free (contents);
-  if (external_relocs != NULL)
-    free (external_relocs);
+  free (contents);
+  free (external_relocs);
   return FALSE;
 }
 
This page took 0.030381 seconds and 4 git commands to generate.