s/boolean/bfd_boolean/ s/true/TRUE/ s/false/FALSE/. Simplify
[deliverable/binutils-gdb.git] / bfd / ecofflink.c
index b8b0631ade1d5cf7c9579576e69608467f3e2619..2ff5d1b2067dae84119dc5bb1ff62bc8c45f7869 100644 (file)
@@ -1,5 +1,6 @@
 /* Routines to link ECOFF debugging information.
-   Copyright 1993 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -22,34 +23,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "sysdep.h"
 #include "bfdlink.h"
 #include "libbfd.h"
-#include "obstack.h"
+#include "objalloc.h"
 #include "aout/stab_gnu.h"
 #include "coff/internal.h"
 #include "coff/sym.h"
 #include "coff/symconst.h"
 #include "coff/ecoff.h"
+#include "libcoff.h"
+#include "libecoff.h"
 \f
-static boolean ecoff_add_bytes PARAMS ((char **buf, char **bufend,
-                                       size_t need));
+static bfd_boolean ecoff_add_bytes
+  PARAMS ((char **buf, char **bufend, size_t need));
 static struct bfd_hash_entry *string_hash_newfunc
   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
           const char *));
-static void ecoff_align_debug PARAMS ((bfd *abfd,
-                                      struct ecoff_debug_info *debug,
-                                      const struct ecoff_debug_swap *swap));
-static boolean ecoff_write_symhdr PARAMS ((bfd *, struct ecoff_debug_info *,
-                                          const struct ecoff_debug_swap *,
-                                          file_ptr where));
-static int cmp_fdrtab_entry PARAMS ((const PTR, const PTR));
-static boolean mk_fdrtab PARAMS ((bfd *,
-                                 struct ecoff_debug_info * const,
-                                 const struct ecoff_debug_swap * const,
-                                 struct ecoff_find_line *));
-static long fdrtab_lookup PARAMS ((struct ecoff_find_line *, bfd_vma));
-
-/* Obstack allocation and deallocation routines.  */
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
+static void ecoff_align_debug
+  PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
+          const struct ecoff_debug_swap *swap));
+static bfd_boolean ecoff_write_symhdr
+  PARAMS ((bfd *, struct ecoff_debug_info *, const struct ecoff_debug_swap *,
+          file_ptr where));
+static int cmp_fdrtab_entry
+  PARAMS ((const PTR, const PTR));
+static bfd_boolean mk_fdrtab
+  PARAMS ((bfd *, struct ecoff_debug_info * const,
+          const struct ecoff_debug_swap * const, struct ecoff_find_line *));
+static long fdrtab_lookup
+  PARAMS ((struct ecoff_find_line *, bfd_vma));
+static bfd_boolean lookup_line
+  PARAMS ((bfd *, struct ecoff_debug_info * const,
+          const struct ecoff_debug_swap * const, struct ecoff_find_line *));
 \f
 /* Routines to swap auxiliary information in and out.  I am assuming
    that the auxiliary information format is always going to be target
@@ -68,8 +71,8 @@ _bfd_ecoff_swap_tir_in (bigend, ext_copy, intern)
   struct tir_ext ext[1];
 
   *ext = *ext_copy;            /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
+
+  /* now the fun stuff...  */
   if (bigend) {
     intern->fBitfield   = 0 != (ext->t_bits1[0] & TIR_BITS1_FBITFIELD_BIG);
     intern->continued   = 0 != (ext->t_bits1[0] & TIR_BITS1_CONTINUED_BIG);
@@ -108,7 +111,7 @@ _bfd_ecoff_swap_tir_in (bigend, ext_copy, intern)
 
 #ifdef TEST
   if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
+    abort ();
 #endif
 }
 
@@ -125,8 +128,8 @@ _bfd_ecoff_swap_tir_out (bigend, intern_copy, ext)
   TIR intern[1];
 
   *intern = *intern_copy;      /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
+
+  /* now the fun stuff...  */
   if (bigend) {
     ext->t_bits1[0] = ((intern->fBitfield ? TIR_BITS1_FBITFIELD_BIG : 0)
                       | (intern->continued ? TIR_BITS1_CONTINUED_BIG : 0)
@@ -165,7 +168,7 @@ _bfd_ecoff_swap_tir_out (bigend, intern_copy, ext)
 
 #ifdef TEST
   if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
+    abort ();
 #endif
 }
 
@@ -181,8 +184,8 @@ _bfd_ecoff_swap_rndx_in (bigend, ext_copy, intern)
   struct rndx_ext ext[1];
 
   *ext = *ext_copy;            /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
+
+  /* now the fun stuff...  */
   if (bigend) {
     intern->rfd   = (ext->r_bits[0] << RNDX_BITS0_RFD_SH_LEFT_BIG)
                  | ((ext->r_bits[1] & RNDX_BITS1_RFD_BIG)
@@ -204,7 +207,7 @@ _bfd_ecoff_swap_rndx_in (bigend, ext_copy, intern)
 
 #ifdef TEST
   if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
+    abort ();
 #endif
 }
 
@@ -220,8 +223,8 @@ _bfd_ecoff_swap_rndx_out (bigend, intern_copy, ext)
   RNDXR intern[1];
 
   *intern = *intern_copy;      /* Make it reasonable to do in-place.  */
-  
-  /* now the fun stuff... */
+
+  /* now the fun stuff...  */
   if (bigend) {
     ext->r_bits[0] = intern->rfd >> RNDX_BITS0_RFD_SH_LEFT_BIG;
     ext->r_bits[1] = (((intern->rfd << RNDX_BITS1_RFD_SH_BIG)
@@ -242,7 +245,7 @@ _bfd_ecoff_swap_rndx_out (bigend, intern_copy, ext)
 
 #ifdef TEST
   if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
-    abort();
+    abort ();
 #endif
 }
 \f
@@ -251,7 +254,7 @@ _bfd_ecoff_swap_rndx_out (bigend, intern_copy, ext)
 
 /* Add bytes to a buffer.  Return success.  */
 
-static boolean
+static bfd_boolean
 ecoff_add_bytes (buf, bufend, need)
      char **buf;
      char **bufend;
@@ -270,18 +273,12 @@ ecoff_add_bytes (buf, bufend, need)
       if (want < ALLOC_SIZE)
        want = ALLOC_SIZE;
     }
-  if (*buf == NULL)
-    newbuf = (char *) malloc (have + want);
-  else
-    newbuf = (char *) realloc (*buf, have + want);
+  newbuf = (char *) bfd_realloc (*buf, (bfd_size_type) have + want);
   if (newbuf == NULL)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return false;
-    }
+    return FALSE;
   *buf = newbuf;
   *bufend = *buf + have + want;
-  return true;
+  return TRUE;
 }
 
 /* We keep a hash table which maps strings to numbers.  We use it to
@@ -351,7 +348,7 @@ struct shuffle
   /* The length of the information.  */
   unsigned long size;
   /* Whether this information comes from a file or not.  */
-  boolean filep;
+  bfd_boolean filep;
   union
     {
       struct
@@ -398,18 +395,17 @@ struct accumulate
   struct shuffle *rfd_end;
   /* The size of the largest file shuffle.  */
   unsigned long largest_file_shuffle;
-  /* An obstack for debugging information.  */
-  struct obstack memory;
+  /* An objalloc for debugging information.  */
+  struct objalloc *memory;
 };
 
 /* Add a file entry to a shuffle list.  */
 
-static boolean add_file_shuffle PARAMS ((struct accumulate *,
-                                     struct shuffle **,
-                                     struct shuffle **, bfd *, file_ptr,
-                                     unsigned long));
+static bfd_boolean add_file_shuffle
+  PARAMS ((struct accumulate *, struct shuffle **, struct shuffle **,
+          bfd *, file_ptr, unsigned long));
 
-static boolean
+static bfd_boolean
 add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
      struct accumulate *ainfo;
      struct shuffle **head;
@@ -429,19 +425,19 @@ add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
       (*tail)->size += size;
       if ((*tail)->size > ainfo->largest_file_shuffle)
        ainfo->largest_file_shuffle = (*tail)->size;
-      return true;
+      return TRUE;
     }
 
-  n = (struct shuffle *) obstack_alloc (&ainfo->memory,
-                                       sizeof (struct shuffle));
+  n = (struct shuffle *) objalloc_alloc (ainfo->memory,
+                                        sizeof (struct shuffle));
   if (!n)
     {
       bfd_set_error (bfd_error_no_memory);
-      return false;
+      return FALSE;
     }
   n->next = NULL;
   n->size = size;
-  n->filep = true;
+  n->filep = TRUE;
   n->u.file.input_bfd = input_bfd;
   n->u.file.offset = offset;
   if (*head == (struct shuffle *) NULL)
@@ -451,17 +447,16 @@ add_file_shuffle (ainfo, head, tail, input_bfd, offset, size)
   *tail = n;
   if (size > ainfo->largest_file_shuffle)
     ainfo->largest_file_shuffle = size;
-  return true;
+  return TRUE;
 }
 
 /* Add a memory entry to a shuffle list.  */
 
-static boolean add_memory_shuffle PARAMS ((struct accumulate *,
-                                          struct shuffle **head,
-                                          struct shuffle **tail,
-                                          bfd_byte *data, unsigned long size));
+static bfd_boolean add_memory_shuffle
+  PARAMS ((struct accumulate *, struct shuffle **head, struct shuffle **tail,
+          bfd_byte *data, unsigned long size));
 
-static boolean
+static bfd_boolean
 add_memory_shuffle (ainfo, head, tail, data, size)
      struct accumulate *ainfo;
      struct shuffle **head;
@@ -470,45 +465,42 @@ add_memory_shuffle (ainfo, head, tail, data, size)
      unsigned long size;
 {
   struct shuffle *n;
-     
-  n = (struct shuffle *) obstack_alloc (&ainfo->memory,
-                                       sizeof (struct shuffle));
+
+  n = (struct shuffle *) objalloc_alloc (ainfo->memory,
+                                        sizeof (struct shuffle));
   if (!n)
     {
       bfd_set_error (bfd_error_no_memory);
-      return false;
+      return FALSE;
     }
   n->next = NULL;
   n->size = size;
-  n->filep = false;
+  n->filep = FALSE;
   n->u.memory = (PTR) data;
   if (*head == (struct shuffle *) NULL)
     *head = n;
   if (*tail != (struct shuffle *) NULL)
     (*tail)->next = n;
   *tail = n;
-  return true;
+  return TRUE;
 }
 
 /* Initialize the FDR hash table.  This returns a handle which is then
    passed in to bfd_ecoff_debug_accumulate, et. al.  */
 
-/*ARGSUSED*/
 PTR
 bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct ecoff_debug_info *output_debug;
-     const struct ecoff_debug_swap *output_swap;
+     const struct ecoff_debug_swap *output_swap ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   struct accumulate *ainfo;
+  bfd_size_type amt = sizeof (struct accumulate);
 
-  ainfo = (struct accumulate *) malloc (sizeof (struct accumulate));
+  ainfo = (struct accumulate *) bfd_malloc (amt);
   if (!ainfo)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      return NULL;
-    }
+    return NULL;
   if (! bfd_hash_table_init_n (&ainfo->fdr_hash.table, string_hash_newfunc,
                               1021))
     return NULL;
@@ -543,7 +535,8 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
       output_debug->symbolic_header.issMax = 1;
     }
 
-  if (!obstack_begin (&ainfo->memory, 4050))
+  ainfo->memory = objalloc_create ();
+  if (ainfo->memory == NULL)
     {
       bfd_set_error (bfd_error_no_memory);
       return NULL;
@@ -554,23 +547,22 @@ bfd_ecoff_debug_init (output_bfd, output_debug, output_swap, info)
 
 /* Free the accumulated debugging information.  */
 
-/*ARGSUSED*/
 void
 bfd_ecoff_debug_free (handle, output_bfd, output_debug, output_swap, info)
      PTR handle;
-     bfd *output_bfd;
-     struct ecoff_debug_info *output_debug;
-     const struct ecoff_debug_swap *output_swap;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
+     struct ecoff_debug_info *output_debug ATTRIBUTE_UNUSED;
+     const struct ecoff_debug_swap *output_swap ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   struct accumulate *ainfo = (struct accumulate *) handle;
-  
+
   bfd_hash_table_free (&ainfo->fdr_hash.table);
 
   if (! info->relocateable)
     bfd_hash_table_free (&ainfo->str_hash.table);
 
-  obstack_free (&ainfo->memory, (PTR) NULL);
+  objalloc_free (ainfo->memory);
 
   free (ainfo);
 }
@@ -583,8 +575,7 @@ bfd_ecoff_debug_free (handle, output_bfd, output_debug, output_swap, info)
    linker information structure.  HANDLE is returned by
    bfd_ecoff_debug_init.  */
 
-/*ARGSUSED*/
-boolean
+bfd_boolean
 bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
                            input_bfd, input_debug, input_swap,
                            info)
@@ -630,6 +621,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
   long newrfdbase = 0;
   long oldrfdbase = 0;
   bfd_byte *fdr_out;
+  bfd_size_type amt;
 
   /* Use section_adjust to hold the value to add to a symbol in a
      particular section.  */
@@ -670,19 +662,19 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
     }
   fdr_end = fdr_start + input_symhdr->ifdMax * fdr_add;
 
-  input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd,
-                                           (input_symhdr->ifdMax
-                                            * sizeof (RFDT)));
+  amt = input_symhdr->ifdMax;
+  amt *= sizeof (RFDT);
+  input_debug->ifdmap = (RFDT *) bfd_alloc (input_bfd, amt);
 
   sz = (input_symhdr->crfd + input_symhdr->ifdMax) * external_rfd_size;
-  rfd_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
+  rfd_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
   if (!input_debug->ifdmap || !rfd_out)
     {
       bfd_set_error (bfd_error_no_memory);
-      return false;
+      return FALSE;
     }
   if (!add_memory_shuffle (ainfo, &ainfo->rfd, &ainfo->rfd_end, rfd_out, sz))
-    return false;
+    return FALSE;
 
   copied = 0;
 
@@ -713,25 +705,23 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          struct string_hash_entry *fh;
 
          /* We look up a string formed from the file name and the
-            number of symbols.  Sometimes an include file will
-            conditionally define a typedef or something based on the
-            order of include files.  Using the number of symbols as a
-            hash reduces the chance that we will merge symbol
-            information that should not be merged.  */
+            number of symbols and aux entries.  Sometimes an include
+            file will conditionally define a typedef or something
+            based on the order of include files.  Using the number of
+            symbols and aux entries as a hash reduces the chance that
+            we will merge symbol information that should not be
+            merged.  */
          name = input_debug->ss + fdr.issBase + fdr.rss;
 
-         lookup = (char *) malloc (strlen (name) + 20);
+         lookup = (char *) bfd_malloc ((bfd_size_type) strlen (name) + 20);
          if (lookup == NULL)
-           {
-             bfd_set_error (bfd_error_no_memory);
-             return false;
-           }
-         sprintf (lookup, "%s %lx", name, fdr.csym);
+           return FALSE;
+         sprintf (lookup, "%s %lx %lx", name, fdr.csym, fdr.caux);
 
-         fh = string_hash_lookup (&ainfo->fdr_hash, lookup, true, true);
+         fh = string_hash_lookup (&ainfo->fdr_hash, lookup, TRUE, TRUE);
          free (lookup);
          if (fh == (struct string_hash_entry *) NULL)
-           return false;
+           return FALSE;
 
          if (fh->val != -1)
            {
@@ -778,14 +768,14 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
   /* Look through the FDR's and copy over all associated debugging
      information.  */
   sz = copied * external_fdr_size;
-  fdr_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
+  fdr_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
   if (!fdr_out)
     {
       bfd_set_error (bfd_error_no_memory);
-      return false;
+      return FALSE;
     }
   if (!add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end, fdr_out, sz))
-    return false;
+    return FALSE;
   for (fdr_ptr = fdr_start, i = 0;
        fdr_ptr < fdr_end;
        fdr_ptr += fdr_add, i++)
@@ -795,7 +785,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
       bfd_byte *sym_out;
       bfd_byte *lraw_src;
       bfd_byte *lraw_end;
-      boolean fgotfilename;
+      bfd_boolean fgotfilename;
 
       if (input_debug->ifdmap[i] < output_symhdr->ifdMax)
        {
@@ -831,17 +821,17 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
 
       /* Swap in the local symbols, adjust their values, and swap them
         out again.  */
-      fgotfilename = false;
+      fgotfilename = FALSE;
       sz = fdr.csym * external_sym_size;
-      sym_out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
+      sym_out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
       if (!sym_out)
        {
          bfd_set_error (bfd_error_no_memory);
-         return false;
+         return FALSE;
        }
       if (!add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end, sym_out,
                               sz))
-       return false;
+       return FALSE;
       lraw_src = ((bfd_byte *) input_debug->external_sym
                  + fdr.isymBase * input_swap->external_sym_size);
       lraw_end = lraw_src + fdr.csym * input_swap->external_sym_size;
@@ -893,13 +883,13 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
             prevent us from easily merging different FDR's.  */
          if (! info->relocateable)
            {
-             boolean ffilename;
+             bfd_boolean ffilename;
              const char *name;
 
              if (! fgotfilename && internal_sym.iss == fdr.rss)
-               ffilename = true;
+               ffilename = TRUE;
              else
-               ffilename = false;
+               ffilename = FALSE;
 
              /* Hash the name into the string table.  */
              name = input_debug->ss + fdr.issBase + internal_sym.iss;
@@ -909,9 +899,9 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
                {
                  struct string_hash_entry *sh;
 
-                 sh = string_hash_lookup (&ainfo->str_hash, name, true, true);
+                 sh = string_hash_lookup (&ainfo->str_hash, name, TRUE, TRUE);
                  if (sh == (struct string_hash_entry *) NULL)
-                   return false;
+                   return FALSE;
                  if (sh->val == -1)
                    {
                      sh->val = output_symhdr->issMax;
@@ -929,7 +919,7 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
              if (ffilename)
                {
                  fdr.rss = internal_sym.iss;
-                 fgotfilename = true;
+                 fgotfilename = TRUE;
                }
            }
 
@@ -948,11 +938,10 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
         stabs are adjusted correctly.  */
       if (fdr.cbLine > 0)
        {
+         file_ptr pos = input_symhdr->cbLineOffset + fdr.cbLineOffset;
          if (!add_file_shuffle (ainfo, &ainfo->line, &ainfo->line_end,
-                                input_bfd,
-                                input_symhdr->cbLineOffset + fdr.cbLineOffset,
-                                fdr.cbLine))
-           return false;
+                                input_bfd, pos, (unsigned long) fdr.cbLine))
+           return FALSE;
          fdr.ilineBase = output_symhdr->ilineMax;
          fdr.cbLineOffset = output_symhdr->cbLine;
          output_symhdr->ilineMax += fdr.cline;
@@ -960,12 +949,12 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
        }
       if (fdr.caux > 0)
        {
+         file_ptr pos = (input_symhdr->cbAuxOffset
+                         + fdr.iauxBase * sizeof (union aux_ext));
          if (!add_file_shuffle (ainfo, &ainfo->aux, &ainfo->aux_end,
-                                input_bfd,
-                                (input_symhdr->cbAuxOffset
-                                 + fdr.iauxBase * sizeof (union aux_ext)),
+                                input_bfd, pos,
                                 fdr.caux * sizeof (union aux_ext)))
-           return false;
+           return FALSE;
          fdr.iauxBase = output_symhdr->iauxMax;
          output_symhdr->iauxMax += fdr.caux;
        }
@@ -981,17 +970,16 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
        }
       else if (fdr.cbSs > 0)
        {
+         file_ptr pos = input_symhdr->cbSsOffset + fdr.issBase;
          if (!add_file_shuffle (ainfo, &ainfo->ss, &ainfo->ss_end,
-                                input_bfd,
-                                input_symhdr->cbSsOffset + fdr.issBase,
-                                fdr.cbSs))
-           return false;
+                                input_bfd, pos, (unsigned long) fdr.cbSs))
+           return FALSE;
          fdr.issBase = output_symhdr->issMax;
          output_symhdr->issMax += fdr.cbSs;
        }
 
-      if ((output_bfd->xvec->header_byteorder_big_p
-          == input_bfd->xvec->header_byteorder_big_p)
+      if ((output_bfd->xvec->header_byteorder
+          == input_bfd->xvec->header_byteorder)
          && input_debug->adjust == (struct ecoff_value_adjust *) NULL)
        {
          /* The two BFD's have the same endianness, and we don't have
@@ -1000,22 +988,22 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
          BFD_ASSERT (external_pdr_size == input_swap->external_pdr_size);
          if (fdr.cpd > 0)
            {
+             file_ptr pos = (input_symhdr->cbPdOffset
+                             + fdr.ipdFirst * external_pdr_size);
+             unsigned long size = fdr.cpd * external_pdr_size;
              if (!add_file_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end,
-                                    input_bfd,
-                                    (input_symhdr->cbPdOffset
-                                     + fdr.ipdFirst * external_pdr_size),
-                                    fdr.cpd * external_pdr_size))
-               return false;
+                                    input_bfd, pos, size))
+               return FALSE;
            }
          BFD_ASSERT (external_opt_size == input_swap->external_opt_size);
          if (fdr.copt > 0)
            {
+             file_ptr pos = (input_symhdr->cbOptOffset
+                             + fdr.ioptBase * external_opt_size);
+             unsigned long size = fdr.copt * external_opt_size;
              if (!add_file_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end,
-                                    input_bfd,
-                                    (input_symhdr->cbOptOffset
-                                     + fdr.ioptBase * external_opt_size),
-                                    fdr.copt * external_opt_size))
-               return false;
+                                    input_bfd, pos, size))
+               return FALSE;
            }
        }
       else
@@ -1034,15 +1022,15 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
                + fdr.ipdFirst * insz);
          end = in + fdr.cpd * insz;
          sz = fdr.cpd * outsz;
-         out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
+         out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
          if (!out)
            {
              bfd_set_error (bfd_error_no_memory);
-             return false;
+             return FALSE;
            }
          if (!add_memory_shuffle (ainfo, &ainfo->pdr, &ainfo->pdr_end, out,
                                   sz))
-           return false;
+           return FALSE;
          for (; in < end; in += insz, out += outsz)
            {
              PDR pdr;
@@ -1075,15 +1063,15 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
                + fdr.ioptBase * insz);
          end = in + fdr.copt * insz;
          sz = fdr.copt * outsz;
-         out = (bfd_byte *) obstack_alloc (&ainfo->memory, sz);
+         out = (bfd_byte *) objalloc_alloc (ainfo->memory, sz);
          if (!out)
            {
              bfd_set_error (bfd_error_no_memory);
-             return false;
+             return FALSE;
            }
          if (!add_memory_shuffle (ainfo, &ainfo->opt, &ainfo->opt_end, out,
                                   sz))
-           return false;
+           return FALSE;
          for (; in < end; in += insz, out += outsz)
            {
              OPTR opt;
@@ -1115,16 +1103,15 @@ bfd_ecoff_debug_accumulate (handle, output_bfd, output_debug, output_swap,
       ++output_symhdr->ifdMax;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Add a string to the debugging information we are accumulating.
    Return the offset from the fdr string base.  */
 
-static long ecoff_add_string PARAMS ((struct accumulate *,
-                                     struct bfd_link_info *,
-                                     struct ecoff_debug_info *,
-                                     FDR *fdr, const char *string));
+static long ecoff_add_string
+  PARAMS ((struct accumulate *, struct bfd_link_info *,
+          struct ecoff_debug_info *, FDR *fdr, const char *string));
 
 static long
 ecoff_add_string (ainfo, info, debug, fdr, string)
@@ -1153,7 +1140,7 @@ ecoff_add_string (ainfo, info, debug, fdr, string)
     {
       struct string_hash_entry *sh;
 
-      sh = string_hash_lookup (&ainfo->str_hash, string, true, true);
+      sh = string_hash_lookup (&ainfo->str_hash, string, TRUE, TRUE);
       if (sh == (struct string_hash_entry *) NULL)
        return -1;
       if (sh->val == -1)
@@ -1175,7 +1162,7 @@ ecoff_add_string (ainfo, info, debug, fdr, string)
 
 /* Add debugging information from a non-ECOFF file.  */
 
-boolean
+bfd_boolean
 bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
                                  output_swap, input_bfd, info)
      PTR handle;
@@ -1212,21 +1199,21 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
   fdr.issBase = output_symhdr->issMax;
   fdr.cbSs = 0;
   fdr.rss = ecoff_add_string (ainfo, info, output_debug, &fdr,
-                             bfd_get_filename (input_bfd));
+                             bfd_archive_filename (input_bfd));
   if (fdr.rss == -1)
-    return false;
+    return FALSE;
   fdr.isymBase = output_symhdr->isymMax;
 
   /* Get the local symbols from the input BFD.  */
   symsize = bfd_get_symtab_upper_bound (input_bfd);
   if (symsize < 0)
-    return false;
-  symbols = (asymbol **) bfd_alloc (output_bfd, symsize);
+    return FALSE;
+  symbols = (asymbol **) bfd_alloc (output_bfd, (bfd_size_type) symsize);
   if (symbols == (asymbol **) NULL)
-    return false;
+    return FALSE;
   symcount = bfd_canonicalize_symtab (input_bfd, symbols);
   if (symcount < 0)
-    return false;
+    return FALSE;
   sym_end = symbols + symcount;
 
   /* Handle the local symbols.  Any external symbols are handled
@@ -1244,7 +1231,7 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
                                           (*sym_ptr)->name);
 
       if (internal_sym.iss == -1)
-       return false;
+       return FALSE;
       if (bfd_is_com_section ((*sym_ptr)->section)
          || bfd_is_und_section ((*sym_ptr)->section))
        internal_sym.value = (*sym_ptr)->value;
@@ -1256,16 +1243,17 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
       internal_sym.sc = scUndefined;
       internal_sym.index = indexNil;
 
-      external_sym = (PTR) obstack_alloc (&ainfo->memory,
-                                         output_swap->external_sym_size);
+      external_sym = (PTR) objalloc_alloc (ainfo->memory,
+                                          output_swap->external_sym_size);
       if (!external_sym)
        {
          bfd_set_error (bfd_error_no_memory);
-         return false;
+         return FALSE;
        }
       (*swap_sym_out) (output_bfd, &internal_sym, external_sym);
       add_memory_shuffle (ainfo, &ainfo->sym, &ainfo->sym_end,
-                         external_sym, output_swap->external_sym_size);
+                         external_sym,
+                         (unsigned long) output_swap->external_sym_size);
       ++fdr.csym;
       ++output_symhdr->isymMax;
     }
@@ -1276,20 +1264,21 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
      the lang field to be langC.  The fBigendian field will
      indicate little endian format, but it doesn't matter because
      it only applies to aux fields and there are none.  */
-  external_fdr = (PTR) obstack_alloc (&ainfo->memory,
-                                     output_swap->external_fdr_size);
+  external_fdr = (PTR) objalloc_alloc (ainfo->memory,
+                                      output_swap->external_fdr_size);
   if (!external_fdr)
     {
       bfd_set_error (bfd_error_no_memory);
-      return false;
+      return FALSE;
     }
   (*output_swap->swap_fdr_out) (output_bfd, &fdr, external_fdr);
   add_memory_shuffle (ainfo, &ainfo->fdr, &ainfo->fdr_end,
-                     external_fdr, output_swap->external_fdr_size);
+                     external_fdr,
+                     (unsigned long) output_swap->external_fdr_size);
 
   ++output_symhdr->ifdMax;
 
-  return true;
+  return TRUE;
 }
 
 /* Set up ECOFF debugging information for the external symbols.
@@ -1297,14 +1286,14 @@ bfd_ecoff_debug_accumulate_other (handle, output_bfd, output_debug,
    probably be changed to use a shuffle structure.  The assembler uses
    this interface, so that must be changed to do something else.  */
 
-boolean
+bfd_boolean
 bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
                           set_index)
      bfd *abfd;
      struct ecoff_debug_info *debug;
      const struct ecoff_debug_swap *swap;
-     boolean relocateable;
-     boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
+     bfd_boolean relocateable;
+     bfd_boolean (*get_extr) PARAMS ((asymbol *, EXTR *));
      void (*set_index) PARAMS ((asymbol *, bfd_size_type));
 {
   HDRR * const symhdr = &debug->symbolic_header;
@@ -1313,7 +1302,7 @@ bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
 
   sym_ptr_ptr = bfd_get_outsymbols (abfd);
   if (sym_ptr_ptr == NULL)
-    return true;
+    return TRUE;
 
   for (c = bfd_get_symcount (abfd); c > 0; c--, sym_ptr_ptr++)
     {
@@ -1323,12 +1312,12 @@ bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
       sym_ptr = *sym_ptr_ptr;
 
       /* Get the external symbol information.  */
-      if ((*get_extr) (sym_ptr, &esym) == false)
+      if (! (*get_extr) (sym_ptr, &esym))
        continue;
 
       /* If we're producing an executable, move common symbols into
         bss.  */
-      if (relocateable == false)
+      if (! relocateable)
        {
          if (esym.asym.sc == scCommon)
            esym.asym.sc = scBss;
@@ -1358,15 +1347,15 @@ bfd_ecoff_debug_externals (abfd, debug, swap, relocateable, get_extr,
 
       if (! bfd_ecoff_debug_one_external (abfd, debug, swap,
                                          sym_ptr->name, &esym))
-       return false;
+       return FALSE;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Add a single external symbol to the debugging information.  */
 
-boolean
+bfd_boolean
 bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
      bfd *abfd;
      struct ecoff_debug_info *debug;
@@ -1385,21 +1374,19 @@ bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
   if ((size_t) (debug->ssext_end - debug->ssext)
       < symhdr->issExtMax + namelen + 1)
     {
-      if (ecoff_add_bytes ((char **) &debug->ssext,
-                          (char **) &debug->ssext_end,
-                          symhdr->issExtMax + namelen + 1)
-         == false)
-       return false;
+      if (! ecoff_add_bytes ((char **) &debug->ssext,
+                            (char **) &debug->ssext_end,
+                            symhdr->issExtMax + namelen + 1))
+       return FALSE;
     }
   if ((size_t) ((char *) debug->external_ext_end
                - (char *) debug->external_ext)
       < (symhdr->iextMax + 1) * external_ext_size)
     {
-      if (ecoff_add_bytes ((char **) &debug->external_ext,
-                          (char **) &debug->external_ext_end,
-                          (symhdr->iextMax + 1) * external_ext_size)
-         == false)
-       return false;
+      if (! ecoff_add_bytes ((char **) &debug->external_ext,
+                            (char **) &debug->external_ext_end,
+                            (symhdr->iextMax + 1) * (size_t) external_ext_size))
+       return FALSE;
     }
 
   esym->asym.iss = symhdr->issExtMax;
@@ -1413,15 +1400,14 @@ bfd_ecoff_debug_one_external (abfd, debug, swap, name, esym)
   strcpy (debug->ssext + symhdr->issExtMax, name);
   symhdr->issExtMax += namelen + 1;
 
-  return true;
+  return TRUE;
 }
 
 /* Align the ECOFF debugging information.  */
 
-/*ARGSUSED*/
 static void
 ecoff_align_debug (abfd, debug, swap)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      struct ecoff_debug_info *debug;
      const struct ecoff_debug_swap *swap;
 {
@@ -1515,7 +1501,7 @@ bfd_ecoff_debug_size (abfd, debug, swap)
    going to be placed at.  This assumes that the counts are set
    correctly.  */
 
-static boolean
+static bfd_boolean
 ecoff_write_symhdr (abfd, debug, swap, where)
      bfd *abfd;
      struct ecoff_debug_info *debug;
@@ -1529,7 +1515,7 @@ ecoff_write_symhdr (abfd, debug, swap, where)
 
   /* Go to the right location in the file.  */
   if (bfd_seek (abfd, where, SEEK_SET) != 0)
-    return false;
+    return FALSE;
 
   where += swap->external_hdr_size;
 
@@ -1558,25 +1544,22 @@ ecoff_write_symhdr (abfd, debug, swap, where)
   SET (cbExtOffset, iextMax, swap->external_ext_size);
 #undef SET
 
-  buff = (PTR) malloc ((size_t) swap->external_hdr_size);
+  buff = (PTR) bfd_malloc (swap->external_hdr_size);
   if (buff == NULL && swap->external_hdr_size != 0)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto error_return;
-    }
+    goto error_return;
 
   (*swap->swap_hdr_out) (abfd, symhdr, buff);
-  if (bfd_write (buff, 1, swap->external_hdr_size, abfd)
+  if (bfd_bwrite (buff, swap->external_hdr_size, abfd)
       != swap->external_hdr_size)
     goto error_return;
 
   if (buff != NULL)
     free (buff);
-  return true;
+  return TRUE;
  error_return:
   if (buff != NULL)
     free (buff);
-  return false;
+  return FALSE;
 }
 
 /* Write out the ECOFF debugging information.  This function assumes
@@ -1585,7 +1568,7 @@ ecoff_write_symhdr (abfd, debug, swap, where)
    information to.  This function fills in the file offsets in the
    symbolic header.  */
 
-boolean
+bfd_boolean
 bfd_ecoff_write_debug (abfd, debug, swap, where)
      bfd *abfd;
      struct ecoff_debug_info *debug;
@@ -1595,21 +1578,22 @@ bfd_ecoff_write_debug (abfd, debug, swap, where)
   HDRR * const symhdr = &debug->symbolic_header;
 
   if (! ecoff_write_symhdr (abfd, debug, swap, where))
-    return false;
+    return FALSE;
 
 #define WRITE(ptr, count, size, offset) \
   BFD_ASSERT (symhdr->offset == 0 \
              || (bfd_vma) bfd_tell (abfd) == symhdr->offset); \
-  if (bfd_write ((PTR) debug->ptr, size, symhdr->count, abfd) \
+  if (bfd_bwrite ((PTR) debug->ptr, (bfd_size_type) size * symhdr->count, abfd)\
       != size * symhdr->count) \
-    return false;
+    return FALSE;
 
   WRITE (line, cbLine, sizeof (unsigned char), cbLineOffset);
   WRITE (external_dnr, idnMax, swap->external_dnr_size, cbDnOffset);
   WRITE (external_pdr, ipdMax, swap->external_pdr_size, cbPdOffset);
   WRITE (external_sym, isymMax, swap->external_sym_size, cbSymOffset);
   WRITE (external_opt, ioptMax, swap->external_opt_size, cbOptOffset);
-  WRITE (external_aux, iauxMax, sizeof (union aux_ext), cbAuxOffset);
+  WRITE (external_aux, iauxMax, (bfd_size_type) sizeof (union aux_ext),
+        cbAuxOffset);
   WRITE (ss, issMax, sizeof (char), cbSsOffset);
   WRITE (ssext, issExtMax, sizeof (char), cbSsExtOffset);
   WRITE (external_fdr, ifdMax, swap->external_fdr_size, cbFdOffset);
@@ -1617,16 +1601,16 @@ bfd_ecoff_write_debug (abfd, debug, swap, where)
   WRITE (external_ext, iextMax, swap->external_ext_size, cbExtOffset);
 #undef WRITE
 
-  return true;
+  return TRUE;
 }
 
 /* Write out a shuffle list.  */
 
-static boolean ecoff_write_shuffle PARAMS ((bfd *,
-                                           const struct ecoff_debug_swap *,
-                                           struct shuffle *, PTR space));
+static bfd_boolean ecoff_write_shuffle
+  PARAMS ((bfd *, const struct ecoff_debug_swap *, struct shuffle *,
+          PTR space));
 
-static boolean
+static bfd_boolean
 ecoff_write_shuffle (abfd, swap, shuffle, space)
      bfd *abfd;
      const struct ecoff_debug_swap *swap;
@@ -1641,15 +1625,17 @@ ecoff_write_shuffle (abfd, swap, shuffle, space)
     {
       if (! l->filep)
        {
-         if (bfd_write (l->u.memory, 1, l->size, abfd) != l->size)
-           return false;
+         if (bfd_bwrite (l->u.memory, (bfd_size_type) l->size, abfd)
+             != l->size)
+           return FALSE;
        }
       else
        {
          if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
-             || bfd_read (space, 1, l->size, l->u.file.input_bfd) != l->size
-             || bfd_write (space, 1, l->size, abfd) != l->size)
-           return false;
+             || bfd_bread (space, (bfd_size_type) l->size,
+                          l->u.file.input_bfd) != l->size
+             || bfd_bwrite (space, (bfd_size_type) l->size, abfd) != l->size)
+           return FALSE;
        }
       total += l->size;
     }
@@ -1660,29 +1646,25 @@ ecoff_write_shuffle (abfd, swap, shuffle, space)
       bfd_byte *s;
 
       i = swap->debug_align - (total & (swap->debug_align - 1));
-      s = (bfd_byte *) malloc (i);
+      s = (bfd_byte *) bfd_zmalloc ((bfd_size_type) i);
       if (s == NULL && i != 0)
-       {
-         bfd_set_error (bfd_error_no_memory);
-         return false;
-       }
+       return FALSE;
 
-      memset ((PTR) s, 0, i);
-      if (bfd_write ((PTR) s, 1, i, abfd) != i)
+      if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
        {
          free (s);
-         return false;
+         return FALSE;
        }
       free (s);
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Write out debugging information using accumulated linker
    information.  */
 
-boolean
+bfd_boolean
 bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
      PTR handle;
      bfd *abfd;
@@ -1693,16 +1675,15 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
 {
   struct accumulate *ainfo = (struct accumulate *) handle;
   PTR space = NULL;
+  bfd_size_type amt;
 
   if (! ecoff_write_symhdr (abfd, debug, swap, where))
     goto error_return;
 
-  space = (PTR) malloc (ainfo->largest_file_shuffle);
+  amt = ainfo->largest_file_shuffle;
+  space = (PTR) bfd_malloc (amt);
   if (space == NULL && ainfo->largest_file_shuffle != 0)
-    {
-      bfd_set_error (bfd_error_no_memory);
-      goto error_return;
-    }
+    goto error_return;
 
   if (! ecoff_write_shuffle (abfd, swap, ainfo->line, space)
       || ! ecoff_write_shuffle (abfd, swap, ainfo->pdr, space)
@@ -1727,7 +1708,7 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
 
       BFD_ASSERT (ainfo->ss == (struct shuffle *) NULL);
       null = 0;
-      if (bfd_write ((PTR) &null, 1, 1, abfd) != 1)
+      if (bfd_bwrite ((PTR) &null, (bfd_size_type) 1, abfd) != 1)
        goto error_return;
       total = 1;
       BFD_ASSERT (ainfo->ss_hash == NULL || ainfo->ss_hash->val == 1);
@@ -1738,7 +1719,8 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
          size_t len;
 
          len = strlen (sh->root.string);
-         if (bfd_write ((PTR) sh->root.string, 1, len + 1, abfd) != len + 1)
+         amt = len + 1;
+         if (bfd_bwrite ((PTR) sh->root.string, amt, abfd) != amt)
            goto error_return;
          total += len + 1;
        }
@@ -1749,14 +1731,11 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
          bfd_byte *s;
 
          i = swap->debug_align - (total & (swap->debug_align - 1));
-         s = (bfd_byte *) malloc (i);
+         s = (bfd_byte *) bfd_zmalloc ((bfd_size_type) i);
          if (s == NULL && i != 0)
-           {
-             bfd_set_error (bfd_error_no_memory);
-             goto error_return;
-           }
-         memset ((PTR) s, 0, i);
-         if (bfd_write ((PTR) s, 1, i, abfd) != i)
+           goto error_return;
+
+         if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
            {
              free (s);
              goto error_return;
@@ -1767,8 +1746,8 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
 
   /* The external strings and symbol are not converted over to using
      shuffles.  FIXME: They probably should be.  */
-  if (bfd_write (debug->ssext, 1, debug->symbolic_header.issExtMax, abfd)
-      != (bfd_size_type) debug->symbolic_header.issExtMax)
+  amt = debug->symbolic_header.issExtMax;
+  if (bfd_bwrite (debug->ssext, amt, abfd) != amt)
     goto error_return;
   if ((debug->symbolic_header.issExtMax & (swap->debug_align - 1)) != 0)
     {
@@ -1777,14 +1756,11 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
 
       i = (swap->debug_align
           - (debug->symbolic_header.issExtMax & (swap->debug_align - 1)));
-      s = (bfd_byte *) malloc (i);
+      s = (bfd_byte *) bfd_zmalloc ((bfd_size_type) i);
       if (s == NULL && i != 0)
-       {
-         bfd_set_error (bfd_error_no_memory);
-         goto error_return;
-       }
-      memset ((PTR) s, 0, i);
-      if (bfd_write ((PTR) s, 1, i, abfd) != i)
+       goto error_return;
+
+      if (bfd_bwrite ((PTR) s, (bfd_size_type) i, abfd) != i)
        {
          free (s);
          goto error_return;
@@ -1800,19 +1776,18 @@ bfd_ecoff_write_accumulated_debug (handle, abfd, debug, swap, info, where)
              || (debug->symbolic_header.cbExtOffset
                  == (bfd_vma) bfd_tell (abfd)));
 
-  if (bfd_write (debug->external_ext, swap->external_ext_size,
-                debug->symbolic_header.iextMax, abfd)
-      != debug->symbolic_header.iextMax * swap->external_ext_size)
+  amt = debug->symbolic_header.iextMax * swap->external_ext_size;
+  if (bfd_bwrite (debug->external_ext, amt, abfd) != amt)
     goto error_return;
 
   if (space != NULL)
     free (space);
-  return true;
+  return TRUE;
 
  error_return:
   if (space != NULL)
     free (space);
-  return false;
+  return FALSE;
 }
 \f
 /* Handle the find_nearest_line function for both ECOFF and MIPS ELF
@@ -1843,7 +1818,7 @@ cmp_fdrtab_entry (leftp, rightp)
    table will be sorted by address so we can look it up via binary
    search.  */
 
-static boolean
+static bfd_boolean
 mk_fdrtab (abfd, debug_info, debug_swap, line_info)
      bfd *abfd;
      struct ecoff_debug_info * const debug_info;
@@ -1854,8 +1829,9 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
   FDR *fdr_ptr;
   FDR *fdr_start;
   FDR *fdr_end;
-  boolean stabs;
+  bfd_boolean stabs;
   long len;
+  bfd_size_type amt;
 
   fdr_start = debug_info->fdr;
   fdr_end = fdr_start + debug_info->symbolic_header.ifdMax;
@@ -1870,11 +1846,10 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
 
   /* Now, create and fill in the table: */
 
-  line_info->fdrtab = ((struct ecoff_fdrtab_entry*)
-                      bfd_zalloc (abfd,
-                                  len * sizeof (struct ecoff_fdrtab_entry)));
+  amt = (bfd_size_type) len * sizeof (struct ecoff_fdrtab_entry);
+  line_info->fdrtab = (struct ecoff_fdrtab_entry*) bfd_zalloc (abfd, amt);
   if (line_info->fdrtab == NULL)
-    return false;
+    return FALSE;
   line_info->fdrtab_len = len;
 
   tab = line_info->fdrtab;
@@ -1886,7 +1861,7 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
       /* Check whether this file has stabs debugging information.  In
         a file with stabs debugging information, the second local
         symbol is named @stabs.  */
-      stabs = false;
+      stabs = FALSE;
       if (fdr_ptr->csym >= 2)
        {
          char *sym_ptr;
@@ -1897,7 +1872,7 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
          (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
          if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
                      STABS_SYMBOL) == 0)
-           stabs = true;
+           stabs = TRUE;
        }
 
       if (!stabs)
@@ -1929,10 +1904,10 @@ mk_fdrtab (abfd, debug_info, debug_swap, line_info)
      The table is mostly sorted already, but there are cases (e.g.,
      static functions in include files), where this does not hold.
      Use "odump -PFv" to verify...  */
-  qsort ((PTR) line_info->fdrtab, len,
+  qsort ((PTR) line_info->fdrtab, (size_t) len,
         sizeof (struct ecoff_fdrtab_entry), cmp_fdrtab_entry);
 
-  return true;
+  return TRUE;
 }
 
 /* Return index of first FDR that covers to OFFSET.  */
@@ -1976,46 +1951,42 @@ fdrtab_lookup (line_info, offset)
   return mid;
 }
 
-/* Do the work of find_nearest_line.  */
+/* Look up a line given an address, storing the information in
+   LINE_INFO->cache.  */
 
-boolean
-_bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
-                       line_info, filename_ptr, functionname_ptr, retline_ptr)
+static bfd_boolean
+lookup_line (abfd, debug_info, debug_swap, line_info)
      bfd *abfd;
-     asection *section;
-     bfd_vma offset;
      struct ecoff_debug_info * const debug_info;
      const struct ecoff_debug_swap * const debug_swap;
      struct ecoff_find_line *line_info;
-     const char **filename_ptr;
-     const char **functionname_ptr;
-     unsigned int *retline_ptr;
 {
   struct ecoff_fdrtab_entry *tab;
-  boolean stabs;
+  bfd_vma offset;
+  bfd_boolean stabs;
   FDR *fdr_ptr;
   int i;
-  
-  offset += section->vma;
-     
+
+  offset = line_info->cache.start;
+
   /* Build FDR table (sorted by object file's base-address) if we
      don't have it already.  */
   if (line_info->fdrtab == NULL
       && !mk_fdrtab (abfd, debug_info, debug_swap, line_info))
-    return false;
+    return FALSE;
 
   tab = line_info->fdrtab;
 
   /* find first FDR for address OFFSET */
   i = fdrtab_lookup (line_info, offset);
   if (i < 0)
-    return false;              /* no FDR, no fun... */
+    return FALSE;              /* no FDR, no fun...  */
   fdr_ptr = tab[i].fdr;
 
   /* Check whether this file has stabs debugging information.  In a
      file with stabs debugging information, the second local symbol is
      named @stabs.  */
-  stabs = false;
+  stabs = FALSE;
   if (fdr_ptr->csym >= 2)
     {
       char *sym_ptr;
@@ -2026,7 +1997,7 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
       (*debug_swap->swap_sym_in) (abfd, sym_ptr, &sym);
       if (strcmp (debug_info->ss + fdr_ptr->issBase + sym.iss,
                  STABS_SYMBOL) == 0)
-       stabs = true;
+       stabs = TRUE;
     }
 
   if (!stabs)
@@ -2035,7 +2006,7 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
       char *pdr_ptr;
       char *best_pdr = NULL;
       FDR *best_fdr;
-      bfd_vma best_dist = ~0;
+      bfd_vma best_dist = ~(bfd_vma) 0;
       PDR pdr;
       unsigned char *line_ptr;
       unsigned char *line_end;
@@ -2074,9 +2045,9 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
                malloc.c.  I'm not sure why this happens, but it could
                be due to optimizations that reorder a function's
                position within an object-file.
-        
+
          Strategy:
-         
+
          On the first call to this function, we build a table of FDRs
          that is sorted by the base-address of the object-file the FDR
          is referring to.  Notice that each object-file may contain
@@ -2107,9 +2078,9 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
          bfd_vma dist, min_dist = 0;
          char *pdr_hold;
          char *pdr_end;
-         
+
          fdr_ptr = tab[i].fdr;
-         
+
          pdr_ptr = ((char *) debug_info->external_pdr
                     + fdr_ptr->ipdFirst * external_pdr_size);
          pdr_end = pdr_ptr + fdr_ptr->cpd * external_pdr_size;
@@ -2134,7 +2105,7 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
                    }
                }
            }
-         
+
          if (!best_pdr || min_dist < best_dist)
            {
              best_dist = min_dist;
@@ -2147,7 +2118,7 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
             && tab[i].base_addr == tab[i - 1].base_addr);
 
       if (!best_fdr || !best_pdr)
-       return false;                   /* shouldn't happen... */
+       return FALSE;                   /* shouldn't happen...  */
 
       /* phew, finally we got something that we can hold onto: */
       fdr_ptr = best_fdr;
@@ -2182,7 +2153,10 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
            }
          lineno += delta;
          if (offset < count * 4)
-           break;
+           {
+             line_info->cache.stop += count * 4 - offset;
+             break;
+           }
          offset -= count * 4;
        }
 
@@ -2190,9 +2164,9 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
          symbols, at least according to gdb/mipsread.c.  */
       if (fdr_ptr->rss == -1)
        {
-         *filename_ptr = NULL;
+         line_info->cache.filename = NULL;
          if (pdr.isym == -1)
-           *functionname_ptr = NULL;
+           line_info->cache.functionname = NULL;
          else
            {
              EXTR proc_ext;
@@ -2202,24 +2176,30 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
                 ((char *) debug_info->external_ext
                  + pdr.isym * debug_swap->external_ext_size),
                 &proc_ext);
-             *functionname_ptr = debug_info->ssext + proc_ext.asym.iss;
+             line_info->cache.functionname = (debug_info->ssext
+                                              + proc_ext.asym.iss);
            }
        }
       else
        {
          SYMR proc_sym;
 
-         *filename_ptr = debug_info->ss + fdr_ptr->issBase + fdr_ptr->rss;
+         line_info->cache.filename = (debug_info->ss
+                                      + fdr_ptr->issBase
+                                      + fdr_ptr->rss);
          (*debug_swap->swap_sym_in)
            (abfd,
             ((char *) debug_info->external_sym
-             + (fdr_ptr->isymBase + pdr.isym) * debug_swap->external_sym_size),
+             + ((fdr_ptr->isymBase + pdr.isym)
+                * debug_swap->external_sym_size)),
             &proc_sym);
-         *functionname_ptr = debug_info->ss + fdr_ptr->issBase + proc_sym.iss;
+         line_info->cache.functionname = (debug_info->ss
+                                          + fdr_ptr->issBase
+                                          + proc_sym.iss);
        }
       if (lineno == ilineNil)
        lineno = 0;
-      *retline_ptr = lineno;
+      line_info->cache.line_num = lineno;
     }
   else
     {
@@ -2231,8 +2211,8 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
       const char *line_file_name;
       bfd_vma low_func_vma;
       bfd_vma low_line_vma;
-      boolean past_line;
-      boolean past_fn;
+      bfd_boolean past_line;
+      bfd_boolean past_fn;
       char *sym_ptr, *sym_ptr_end;
       size_t len, funclen;
       char *buffer = NULL;
@@ -2247,9 +2227,9 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
         looking through the symbols until we find both a line number
         and a function name which are beyond the address we want.  */
 
-      *filename_ptr = NULL;
-      *functionname_ptr = NULL;
-      *retline_ptr = 0;
+      line_info->cache.filename = NULL;
+      line_info->cache.functionname = NULL;
+      line_info->cache.line_num = 0;
 
       directory_name = NULL;
       main_file_name = NULL;
@@ -2258,8 +2238,8 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
       line_file_name = NULL;
       low_func_vma = 0;
       low_line_vma = 0;
-      past_line = false;
-      past_fn = false;
+      past_line = FALSE;
+      past_fn = FALSE;
 
       external_sym_size = debug_swap->external_sym_size;
 
@@ -2309,7 +2289,7 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
 
                case N_FUN:
                  if (sym.value > offset)
-                   past_fn = true;
+                   past_fn = TRUE;
                  else if (sym.value >= low_func_vma)
                    {
                      low_func_vma = sym.value;
@@ -2322,17 +2302,17 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
          else if (sym.st == stLabel && sym.index != indexNil)
            {
              if (sym.value > offset)
-               past_line = true;
+               past_line = TRUE;
              else if (sym.value >= low_line_vma)
                {
                  low_line_vma = sym.value;
                  line_file_name = current_file_name;
-                 *retline_ptr = sym.index;
+                 line_info->cache.line_num = sym.index;
                }
            }
        }
 
-      if (*retline_ptr != 0)
+      if (line_info->cache.line_num != 0)
        main_file_name = line_file_name;
 
       /* We need to remove the stuff after the colon in the function
@@ -2352,12 +2332,9 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
        {
          if (line_info->find_buffer != NULL)
            free (line_info->find_buffer);
-         buffer = (char *) malloc (len);
+         buffer = (char *) bfd_malloc ((bfd_size_type) len);
          if (buffer == NULL)
-           {
-             bfd_set_error (bfd_error_no_memory);
-             return false;
-           }
+           return FALSE;
          line_info->find_buffer = buffer;
        }
 
@@ -2369,23 +2346,62 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
          colon = strchr (buffer, ':');
          if (colon != NULL)
            *colon = '\0';
-         *functionname_ptr = buffer;
+         line_info->cache.functionname = buffer;
        }
 
       if (main_file_name != NULL)
        {
          if (directory_name == NULL || main_file_name[0] == '/')
-           *filename_ptr = main_file_name;
+           line_info->cache.filename = main_file_name;
          else
            {
              sprintf (buffer + funclen, "%s%s", directory_name,
                       main_file_name);
-             *filename_ptr = buffer + funclen;
+             line_info->cache.filename = buffer + funclen;
            }
        }
     }
 
-  return true;
+  return TRUE;
+}
+
+/* Do the work of find_nearest_line.  */
+
+bfd_boolean
+_bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
+                       line_info, filename_ptr, functionname_ptr, retline_ptr)
+     bfd *abfd;
+     asection *section;
+     bfd_vma offset;
+     struct ecoff_debug_info * const debug_info;
+     const struct ecoff_debug_swap * const debug_swap;
+     struct ecoff_find_line *line_info;
+     const char **filename_ptr;
+     const char **functionname_ptr;
+     unsigned int *retline_ptr;
+{
+  offset += section->vma;
+
+  if (line_info->cache.sect == NULL
+      || line_info->cache.sect != section
+      || offset < line_info->cache.start
+      || offset >= line_info->cache.stop)
+    {
+      line_info->cache.sect = section;
+      line_info->cache.start = offset;
+      line_info->cache.stop = offset;
+      if (! lookup_line (abfd, debug_info, debug_swap, line_info))
+       {
+         line_info->cache.sect = NULL;
+         return FALSE;
+       }
+    }
+
+  *filename_ptr = line_info->cache.filename;
+  *functionname_ptr = line_info->cache.functionname;
+  *retline_ptr = line_info->cache.line_num;
+
+  return TRUE;
 }
 \f
 /* These routines copy symbolic information into a memory buffer.
@@ -2398,9 +2414,10 @@ _bfd_ecoff_locate_line (abfd, section, offset, debug_info, debug_swap,
 
 /* Collect a shuffle into a memory buffer.  */
 
-static boolean ecoff_collect_shuffle PARAMS ((struct shuffle *, bfd_byte *));
+static bfd_boolean ecoff_collect_shuffle
+  PARAMS ((struct shuffle *, bfd_byte *));
 
-static boolean
+static bfd_boolean
 ecoff_collect_shuffle (l, buff)
      struct shuffle *l;
      bfd_byte *buff;
@@ -2415,19 +2432,20 @@ ecoff_collect_shuffle (l, buff)
       else
        {
          if (bfd_seek (l->u.file.input_bfd, l->u.file.offset, SEEK_SET) != 0
-             || bfd_read (buff, 1, l->size, l->u.file.input_bfd) != l->size)
-           return false;
+             || (bfd_bread (buff, (bfd_size_type) l->size, l->u.file.input_bfd)
+                 != l->size))
+           return FALSE;
        }
       total += l->size;
       buff += l->size;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Copy PDR information into a memory buffer.  */
 
-boolean
+bfd_boolean
 _bfd_ecoff_get_accumulated_pdr (handle, buff)
      PTR handle;
      bfd_byte *buff;
@@ -2439,7 +2457,7 @@ _bfd_ecoff_get_accumulated_pdr (handle, buff)
 
 /* Copy symbol information into a memory buffer.  */
 
-boolean
+bfd_boolean
 _bfd_ecoff_get_accumulated_sym (handle, buff)
      PTR handle;
      bfd_byte *buff;
@@ -2451,7 +2469,7 @@ _bfd_ecoff_get_accumulated_sym (handle, buff)
 
 /* Copy the string table into a memory buffer.  */
 
-boolean
+bfd_boolean
 _bfd_ecoff_get_accumulated_ss (handle, buff)
      PTR handle;
      bfd_byte *buff;
@@ -2478,5 +2496,5 @@ _bfd_ecoff_get_accumulated_ss (handle, buff)
       buff += len + 1;
     }
 
-  return true;
+  return TRUE;
 }
This page took 0.046642 seconds and 4 git commands to generate.