i386: Align branches within a fixed boundary
[deliverable/binutils-gdb.git] / bfd / ecoff.c
index beac8942b887e7f897044b5092a309efe9a81be6..be3d42e305fd653a49a9d45c8020f851ea405033 100644 (file)
@@ -1,6 +1,5 @@
 /* Generic ECOFF (Extended-COFF) routines.
 /* Generic ECOFF (Extended-COFF) routines.
-   Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1990-2019 Free Software Foundation, Inc.
    Original version by Per Bothner.
    Full support added by Ian Lance Taylor, ian@cygnus.com.
 
    Original version by Per Bothner.
    Full support added by Ian Lance Taylor, ian@cygnus.com.
 
@@ -8,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02110-1301, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 
-#include "bfd.h"
 #include "sysdep.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
+#include "ecoff-bfd.h"
 #include "aout/ar.h"
 #include "aout/ar.h"
-#include "aout/ranlib.h"
 #include "aout/stab_gnu.h"
 
 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
 #include "aout/stab_gnu.h"
 
 /* FIXME: We need the definitions of N_SET[ADTB], but aout64.h defines
 /* This stuff is somewhat copied from coffcode.h.  */
 static asection bfd_debug_section =
 {
 /* This stuff is somewhat copied from coffcode.h.  */
 static asection bfd_debug_section =
 {
-  /* name,      id,  index, next, prev, flags, user_set_vma,       */
-     "*DEBUG*", 0,   0,     NULL, NULL, 0,     0,
-  /* linker_mark, linker_has_input, gc_mark, segment_mark,         */
-     0,           0,                0,       0,
-  /* sec_info_type, use_rela_p, has_tls_reloc, has_gp_reloc,       */
-     0,                    0,          0,             0,
-  /* need_finalize_relax, reloc_done,                              */
-     0,                          0,
-  /* vma, lma, size, rawsize,                                      */
-     0,   0,   0,    0,
-  /* output_offset, output_section, alignment_power,               */
-     0,             NULL,           0,
+  /* name,     id,  index, next, prev, flags, user_set_vma,       */
+     "*DEBUG*", 0,   0,            NULL, NULL, 0,     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,   */
   /* 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,      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,
      NULL,
-  /* symbol_ptr_ptr,                                               */
+  /* symbol_ptr_ptr,                                              */
      NULL,
      NULL,
-  /* map_head, map_tail                                            */
+  /* map_head, map_tail                                                   */
      { NULL }, { NULL }
 };
 
      { NULL }, { NULL }
 };
 
@@ -87,7 +87,7 @@ _bfd_ecoff_mkobject (bfd *abfd)
 {
   bfd_size_type amt = sizeof (ecoff_data_type);
 
 {
   bfd_size_type amt = sizeof (ecoff_data_type);
 
-  abfd->tdata.ecoff_obj_data = bfd_zalloc (abfd, amt);
+  abfd->tdata.ecoff_obj_data = (struct ecoff_tdata *) bfd_zalloc (abfd, amt);
   if (abfd->tdata.ecoff_obj_data == NULL)
     return FALSE;
 
   if (abfd->tdata.ecoff_obj_data == NULL)
     return FALSE;
 
@@ -140,8 +140,7 @@ _bfd_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr)
 /* Initialize a new section.  */
 
 bfd_boolean
 /* Initialize a new section.  */
 
 bfd_boolean
-_bfd_ecoff_new_section_hook (bfd *abfd ATTRIBUTE_UNUSED,
-                            asection *section)
+_bfd_ecoff_new_section_hook (bfd *abfd, asection *section)
 {
   unsigned int i;
   static struct
 {
   unsigned int i;
   static struct
@@ -181,7 +180,14 @@ _bfd_ecoff_new_section_hook (bfd *abfd ATTRIBUTE_UNUSED,
      uncertain about .init on some systems and I don't know how shared
      libraries work.  */
 
      uncertain about .init on some systems and I don't know how shared
      libraries work.  */
 
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, section);
+}
+
+void
+_bfd_ecoff_set_alignment_hook (bfd *abfd ATTRIBUTE_UNUSED,
+                              asection *section ATTRIBUTE_UNUSED,
+                              void *scnhdr ATTRIBUTE_UNUSED)
+{
 }
 
 /* Determine the machine architecture and type.  This is called from
 }
 
 /* Determine the machine architecture and type.  This is called from
@@ -192,7 +198,7 @@ _bfd_ecoff_new_section_hook (bfd *abfd ATTRIBUTE_UNUSED,
 bfd_boolean
 _bfd_ecoff_set_arch_mach_hook (bfd *abfd, void * filehdr)
 {
 bfd_boolean
 _bfd_ecoff_set_arch_mach_hook (bfd *abfd, void * filehdr)
 {
-  struct internal_filehdr *internal_f = filehdr;
+  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
   enum bfd_architecture arch;
   unsigned long mach;
 
   enum bfd_architecture arch;
   unsigned long mach;
 
@@ -233,6 +239,14 @@ _bfd_ecoff_set_arch_mach_hook (bfd *abfd, void * filehdr)
   return bfd_default_set_arch_mach (abfd, arch, mach);
 }
 
   return bfd_default_set_arch_mach (abfd, arch, mach);
 }
 
+bfd_boolean
+_bfd_ecoff_no_long_sections (bfd *abfd, int enable)
+{
+  (void) abfd;
+  (void) enable;
+  return FALSE;
+}
+
 /* Get the magic number to use based on the architecture and machine.
    This is the inverse of _bfd_ecoff_set_arch_mach_hook, above.  */
 
 /* Get the magic number to use based on the architecture and machine.
    This is the inverse of _bfd_ecoff_set_arch_mach_hook, above.  */
 
@@ -288,29 +302,29 @@ ecoff_sec_to_styp_flags (const char *name, flagword flags)
   }
   styp_flags [] =
   {
   }
   styp_flags [] =
   {
-    { _TEXT,    STYP_TEXT       },
-    { _DATA,    STYP_DATA       },
-    { _SDATA,   STYP_SDATA      },
-    { _RDATA,   STYP_RDATA      },
-    { _LITA,    STYP_LITA       },
-    { _LIT8,    STYP_LIT8       },
-    { _LIT4,    STYP_LIT4       },
-    { _BSS,     STYP_BSS        },
-    { _SBSS,    STYP_SBSS       },
-    { _INIT,    STYP_ECOFF_INIT },
-    { _FINI,    STYP_ECOFF_FINI },
-    { _PDATA,   STYP_PDATA      },
-    { _XDATA,   STYP_XDATA      },
-    { _LIB,     STYP_ECOFF_LIB  },
-    { _GOT,     STYP_GOT        },
-    { _HASH,    STYP_HASH       },
-    { _DYNAMIC, STYP_DYNAMIC    },
-    { _LIBLIST, STYP_LIBLIST    },
-    { _RELDYN,  STYP_RELDYN     },
-    { _CONFLIC, STYP_CONFLIC    },
-    { _DYNSTR,  STYP_DYNSTR     },
-    { _DYNSYM,  STYP_DYNSYM     },
-    { _RCONST,  STYP_RCONST     }
+    { _TEXT,   STYP_TEXT       },
+    { _DATA,   STYP_DATA       },
+    { _SDATA,  STYP_SDATA      },
+    { _RDATA,  STYP_RDATA      },
+    { _LITA,   STYP_LITA       },
+    { _LIT8,   STYP_LIT8       },
+    { _LIT4,   STYP_LIT4       },
+    { _BSS,    STYP_BSS        },
+    { _SBSS,   STYP_SBSS       },
+    { _INIT,   STYP_ECOFF_INIT },
+    { _FINI,   STYP_ECOFF_FINI },
+    { _PDATA,  STYP_PDATA      },
+    { _XDATA,  STYP_XDATA      },
+    { _LIB,    STYP_ECOFF_LIB  },
+    { _GOT,    STYP_GOT        },
+    { _HASH,   STYP_HASH       },
+    { _DYNAMIC, STYP_DYNAMIC   },
+    { _LIBLIST, STYP_LIBLIST   },
+    { _RELDYN, STYP_RELDYN     },
+    { _CONFLIC, STYP_CONFLIC   },
+    { _DYNSTR, STYP_DYNSTR     },
+    { _DYNSYM, STYP_DYNSYM     },
+    { _RCONST, STYP_RCONST     }
   };
   long styp = 0;
 
   };
   long styp = 0;
 
@@ -355,7 +369,7 @@ _bfd_ecoff_styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
                              asection *section ATTRIBUTE_UNUSED,
                              flagword * flags_ptr)
 {
                              asection *section ATTRIBUTE_UNUSED,
                              flagword * flags_ptr)
 {
-  struct internal_scnhdr *internal_s = hdr;
+  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
   long styp_flags = internal_s->s_flags;
   flagword sec_flags = 0;
 
   long styp_flags = internal_s->s_flags;
   flagword sec_flags = 0;
 
@@ -433,7 +447,7 @@ ecoff_slurp_symbolic_header (bfd *abfd)
   /* See whether there is a symbolic header.  */
   if (ecoff_data (abfd)->sym_filepos == 0)
     {
   /* See whether there is a symbolic header.  */
   if (ecoff_data (abfd)->sym_filepos == 0)
     {
-      bfd_get_symcount (abfd) = 0;
+      abfd->symcount = 0;
       return TRUE;
     }
 
       return TRUE;
     }
 
@@ -466,8 +480,7 @@ ecoff_slurp_symbolic_header (bfd *abfd)
     }
 
   /* Now we can get the correct number of symbols.  */
     }
 
   /* Now we can get the correct number of symbols.  */
-  bfd_get_symcount (abfd) = (internal_symhdr->isymMax
-                            + internal_symhdr->iextMax);
+  abfd->symcount = internal_symhdr->isymMax + internal_symhdr->iextMax;
 
   if (raw != NULL)
     free (raw);
 
   if (raw != NULL)
     free (raw);
@@ -498,7 +511,6 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
   struct fdr *fdr_ptr;
   bfd_size_type raw_end;
   bfd_size_type cb_end;
   struct fdr *fdr_ptr;
   bfd_size_type raw_end;
   bfd_size_type cb_end;
-  bfd_size_type amt;
   file_ptr pos;
 
   BFD_ASSERT (debug == &ecoff_data (abfd)->debug_info);
   file_ptr pos;
 
   BFD_ASSERT (debug == &ecoff_data (abfd)->debug_info);
@@ -509,7 +521,7 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
     return TRUE;
   if (ecoff_data (abfd)->sym_filepos == 0)
     {
     return TRUE;
   if (ecoff_data (abfd)->sym_filepos == 0)
     {
-      bfd_get_symcount (abfd) = 0;
+      abfd->symcount = 0;
       return TRUE;
     }
 
       return TRUE;
     }
 
@@ -601,14 +613,16 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
 
      We need to look at the fdr to deal with a lot of information in
      the symbols, so we swap them here.  */
 
      We need to look at the fdr to deal with a lot of information in
      the symbols, so we swap them here.  */
-  amt = internal_symhdr->ifdMax;
-  amt *= sizeof (struct fdr);
-  debug->fdr = bfd_alloc (abfd, amt);
+  debug->fdr = (FDR *) bfd_alloc2 (abfd, internal_symhdr->ifdMax,
+                                  sizeof (struct fdr));
   if (debug->fdr == NULL)
     return FALSE;
   external_fdr_size = backend->debug_swap.external_fdr_size;
   fdr_ptr = debug->fdr;
   fraw_src = (char *) debug->external_fdr;
   if (debug->fdr == NULL)
     return FALSE;
   external_fdr_size = backend->debug_swap.external_fdr_size;
   fdr_ptr = debug->fdr;
   fraw_src = (char *) debug->external_fdr;
+  /* PR 17512: file: 3372-1243-0.004.  */
+  if (fraw_src == NULL && internal_symhdr->ifdMax > 0)
+    return FALSE;
   fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
   for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
     (*backend->debug_swap.swap_fdr_in) (abfd, (void *) fraw_src, fdr_ptr);
   fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
   for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
     (*backend->debug_swap.swap_fdr_in) (abfd, (void *) fraw_src, fdr_ptr);
@@ -633,18 +647,18 @@ static asymbol *ecoff_scom_symbol_ptr;
 asymbol *
 _bfd_ecoff_make_empty_symbol (bfd *abfd)
 {
 asymbol *
 _bfd_ecoff_make_empty_symbol (bfd *abfd)
 {
-  ecoff_symbol_type *new;
+  ecoff_symbol_type *new_symbol;
   bfd_size_type amt = sizeof (ecoff_symbol_type);
 
   bfd_size_type amt = sizeof (ecoff_symbol_type);
 
-  new = bfd_zalloc (abfd, amt);
-  if (new == NULL)
+  new_symbol = (ecoff_symbol_type *) bfd_zalloc (abfd, amt);
+  if (new_symbol == NULL)
     return NULL;
     return NULL;
-  new->symbol.section = NULL;
-  new->fdr = NULL;
-  new->local = FALSE;
-  new->native = NULL;
-  new->symbol.the_bfd = abfd;
-  return &new->symbol;
+  new_symbol->symbol.section = NULL;
+  new_symbol->fdr = NULL;
+  new_symbol->local = FALSE;
+  new_symbol->native = NULL;
+  new_symbol->symbol.the_bfd = abfd;
+  return &new_symbol->symbol;
 }
 
 /* Set the BFD flags and section for an ECOFF symbol.  */
 }
 
 /* Set the BFD flags and section for an ECOFF symbol.  */
@@ -690,11 +704,11 @@ ecoff_set_symbol_info (bfd *abfd,
     {
       asym->flags = BSF_LOCAL;
       /* Normally, a local stProc symbol will have a corresponding
     {
       asym->flags = BSF_LOCAL;
       /* Normally, a local stProc symbol will have a corresponding
-         external symbol.  We mark the local symbol as a debugging
-         symbol, in order to prevent nm from printing both out.
-         Similarly, we mark stLabel and stabs symbols as debugging
-         symbols.  In both cases, we do want to set the value
-         correctly based on the symbol class.  */
+        external symbol.  We mark the local symbol as a debugging
+        symbol, in order to prevent nm from printing both out.
+        Similarly, we mark stLabel and stabs symbols as debugging
+        symbols.  In both cases, we do want to set the value
+        correctly based on the symbol class.  */
       if (ecoff_sym->st == stProc
          || ecoff_sym->st == stLabel
          || ECOFF_IS_STAB (ecoff_sym))
       if (ecoff_sym->st == stProc
          || ecoff_sym->st == stLabel
          || ECOFF_IS_STAB (ecoff_sym))
@@ -850,7 +864,6 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
     = backend->debug_swap.swap_ext_in;
   void (* const swap_sym_in) (bfd *, void *, SYMR *)
     = backend->debug_swap.swap_sym_in;
     = backend->debug_swap.swap_ext_in;
   void (* const swap_sym_in) (bfd *, void *, SYMR *)
     = backend->debug_swap.swap_sym_in;
-  bfd_size_type internal_size;
   ecoff_symbol_type *internal;
   ecoff_symbol_type *internal_ptr;
   char *eraw_src;
   ecoff_symbol_type *internal;
   ecoff_symbol_type *internal_ptr;
   char *eraw_src;
@@ -869,9 +882,8 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
   if (bfd_get_symcount (abfd) == 0)
     return TRUE;
 
   if (bfd_get_symcount (abfd) == 0)
     return TRUE;
 
-  internal_size = bfd_get_symcount (abfd);
-  internal_size *= sizeof (ecoff_symbol_type);
-  internal = bfd_alloc (abfd, internal_size);
+  internal = (ecoff_symbol_type *) bfd_alloc2 (abfd, bfd_get_symcount (abfd),
+                                              sizeof (ecoff_symbol_type));
   if (internal == NULL)
     return FALSE;
 
   if (internal == NULL)
     return FALSE;
 
@@ -885,16 +897,30 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
       EXTR internal_esym;
 
       (*swap_ext_in) (abfd, (void *) eraw_src, &internal_esym);
       EXTR internal_esym;
 
       (*swap_ext_in) (abfd, (void *) eraw_src, &internal_esym);
+
+      /* PR 17512: file: 3372-1000-0.004.  */
+      if (internal_esym.asym.iss >= ecoff_data (abfd)->debug_info.symbolic_header.issExtMax
+         || internal_esym.asym.iss < 0)
+       return FALSE;
+
       internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
                                   + internal_esym.asym.iss);
       internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
                                   + internal_esym.asym.iss);
+
       if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
                                  &internal_ptr->symbol, 1,
                                  internal_esym.weakext))
        return FALSE;
       if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
                                  &internal_ptr->symbol, 1,
                                  internal_esym.weakext))
        return FALSE;
+
       /* The alpha uses a negative ifd field for section symbols.  */
       if (internal_esym.ifd >= 0)
       /* The alpha uses a negative ifd field for section symbols.  */
       if (internal_esym.ifd >= 0)
-       internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
-                            + internal_esym.ifd);
+       {
+         /* PR 17512: file: 3372-1983-0.004.  */
+         if (internal_esym.ifd >= ecoff_data (abfd)->debug_info.symbolic_header.ifdMax)
+           internal_ptr->fdr = NULL;
+         else
+           internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
+                                + internal_esym.ifd);
+       }
       else
        internal_ptr->fdr = NULL;
       internal_ptr->local = FALSE;
       else
        internal_ptr->fdr = NULL;
       internal_ptr->local = FALSE;
@@ -932,6 +958,21 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
        }
     }
 
        }
     }
 
+  /* PR 17512: file: 3372-3080-0.004.
+     A discrepancy between ecoff_data (abfd)->debug_info.symbolic_header.isymMax
+     and ecoff_data (abfd)->debug_info.symbolic_header.ifdMax can mean that
+     we have fewer symbols than we were expecting.  Allow for this by updating
+     the symbol count and warning the user.  */
+  if (internal_ptr - internal < (ptrdiff_t) bfd_get_symcount (abfd))
+    {
+      abfd->symcount = internal_ptr - internal;
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%pB: warning: isymMax (%ld) is greater than ifdMax (%ld)"),
+        abfd, ecoff_data (abfd)->debug_info.symbolic_header.isymMax,
+        ecoff_data (abfd)->debug_info.symbolic_header.ifdMax);
+    }
+
   ecoff_data (abfd)->canonical_symbols = internal;
 
   return TRUE;
   ecoff_data (abfd)->canonical_symbols = internal;
 
   return TRUE;
@@ -1038,7 +1079,7 @@ ecoff_emit_aggregate (bfd *abfd,
   sprintf (string,
           "%s %s { ifd = %u, index = %lu }",
           which, name, ifd,
   sprintf (string,
           "%s %s { ifd = %u, index = %lu }",
           which, name, ifd,
-          ((long) indx
+          ((unsigned long) indx
            + debug_info->symbolic_header.iextMax));
 }
 
            + debug_info->symbolic_header.iextMax));
 }
 
@@ -1224,7 +1265,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
       break;
 
     default:
       break;
 
     default:
-      sprintf (p1, _("Unknown basic type %d"), (int) basic_type);
+      sprintf (p1, _("unknown basic type %d"), (int) basic_type);
       break;
     }
 
       break;
     }
 
@@ -1244,12 +1285,12 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
   if (qualifiers[0].type != tqNil)
     {
       /* Snarf up any array bounds in the correct order.  Arrays
   if (qualifiers[0].type != tqNil)
     {
       /* Snarf up any array bounds in the correct order.  Arrays
-         store 5 successive words in the aux. table:
-               word 0  RNDXR to type of the bounds (ie, int)
-               word 1  Current file descriptor index
-               word 2  low bound
-               word 3  high bound (or -1 if [])
-               word 4  stride size in bits.  */
+        store 5 successive words in the aux. table:
+               word 0  RNDXR to type of the bounds (ie, int)
+               word 1  Current file descriptor index
+               word 2  low bound
+               word 3  high bound (or -1 if [])
+               word 4  stride size in bits.  */
       for (i = 0; i < 7; i++)
        {
          if (qualifiers[i].type == tqArray)
       for (i = 0; i < 7; i++)
        {
          if (qualifiers[i].type == tqArray)
@@ -1503,6 +1544,7 @@ _bfd_ecoff_print_symbol (bfd *abfd,
                if (ECOFF_IS_STAB (&ecoff_ext.asym))
                  ;
                else if (ecoffsymbol (symbol)->local)
                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,
                  fprintf (file, _("\n      End+1 symbol: %-7ld   Type:  %s"),
                           ((long)
                            (AUX_GET_ISYM (bigendian,
@@ -1569,11 +1611,11 @@ ecoff_slurp_reloc_table (bfd *abfd,
 
   amt = section->reloc_count;
   amt *= sizeof (arelent);
 
   amt = section->reloc_count;
   amt *= sizeof (arelent);
-  internal_relocs = bfd_alloc (abfd, amt);
+  internal_relocs = (arelent *) bfd_alloc (abfd, amt);
 
   external_reloc_size = backend->external_reloc_size;
   amt = external_reloc_size * section->reloc_count;
 
   external_reloc_size = backend->external_reloc_size;
   amt = external_reloc_size * section->reloc_count;
-  external_relocs = bfd_alloc (abfd, amt);
+  external_relocs = (char *) bfd_alloc (abfd, amt);
   if (internal_relocs == NULL || external_relocs == NULL)
     return FALSE;
   if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
   if (internal_relocs == NULL || external_relocs == NULL)
     return FALSE;
   if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
@@ -1635,10 +1677,10 @@ ecoff_slurp_reloc_table (bfd *abfd,
            abort ();
          rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
 
            abort ();
          rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
 
-         rptr->addend = - bfd_get_section_vma (abfd, sec);
+         rptr->addend = - bfd_section_vma (sec);
        }
 
        }
 
-      rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
+      rptr->address = intern.r_vaddr - bfd_section_vma (section);
 
       /* Let the backend select the howto field and do any other
         required processing.  */
 
       /* Let the backend select the howto field and do any other
         required processing.  */
@@ -1698,12 +1740,13 @@ _bfd_ecoff_canonicalize_reloc (bfd *abfd,
 
 bfd_boolean
 _bfd_ecoff_find_nearest_line (bfd *abfd,
 
 bfd_boolean
 _bfd_ecoff_find_nearest_line (bfd *abfd,
+                             asymbol **symbols ATTRIBUTE_UNUSED,
                              asection *section,
                              asection *section,
-                             asymbol **ignore_symbols ATTRIBUTE_UNUSED,
                              bfd_vma offset,
                              const char **filename_ptr,
                              const char **functionname_ptr,
                              bfd_vma offset,
                              const char **filename_ptr,
                              const char **functionname_ptr,
-                             unsigned int *retline_ptr)
+                             unsigned int *retline_ptr,
+                             unsigned int *discriminator_ptr)
 {
   const struct ecoff_debug_swap * const debug_swap
     = &ecoff_backend (abfd)->debug_swap;
 {
   const struct ecoff_debug_swap * const debug_swap
     = &ecoff_backend (abfd)->debug_swap;
@@ -1719,12 +1762,15 @@ _bfd_ecoff_find_nearest_line (bfd *abfd,
     {
       bfd_size_type amt = sizeof (struct ecoff_find_line);
 
     {
       bfd_size_type amt = sizeof (struct ecoff_find_line);
 
-      ecoff_data (abfd)->find_line_info = bfd_zalloc (abfd, amt);
+      ecoff_data (abfd)->find_line_info =
+         (struct ecoff_find_line *) bfd_zalloc (abfd, amt);
       if (ecoff_data (abfd)->find_line_info == NULL)
        return FALSE;
     }
       if (ecoff_data (abfd)->find_line_info == NULL)
        return FALSE;
     }
-  line_info = ecoff_data (abfd)->find_line_info;
 
 
+  if (discriminator_ptr)
+    *discriminator_ptr = 0;
+  line_info = ecoff_data (abfd)->find_line_info;
   return _bfd_ecoff_locate_line (abfd, section, offset, debug_info,
                                 debug_swap, line_info, filename_ptr,
                                 functionname_ptr, retline_ptr);
   return _bfd_ecoff_locate_line (abfd, section, offset, debug_info,
                                 debug_swap, line_info, filename_ptr,
                                 functionname_ptr, retline_ptr);
@@ -1863,7 +1909,8 @@ _bfd_ecoff_set_arch_mach (bfd *abfd,
 /* Get the size of the section headers.  */
 
 int
 /* Get the size of the section headers.  */
 
 int
-_bfd_ecoff_sizeof_headers (bfd *abfd, bfd_boolean reloc ATTRIBUTE_UNUSED)
+_bfd_ecoff_sizeof_headers (bfd *abfd,
+                          struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   asection *current;
   int c;
 {
   asection *current;
   int c;
@@ -1878,7 +1925,7 @@ _bfd_ecoff_sizeof_headers (bfd *abfd, bfd_boolean reloc ATTRIBUTE_UNUSED)
   ret = (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);
+  return (int) BFD_ALIGN (ret, 16);
 }
 
 /* Get the contents of a section.  */
 }
 
 /* Get the contents of a section.  */
@@ -1937,13 +1984,13 @@ ecoff_compute_section_file_positions (bfd *abfd)
   const bfd_vma round = ecoff_backend (abfd)->round;
   bfd_size_type amt;
 
   const bfd_vma round = ecoff_backend (abfd)->round;
   bfd_size_type amt;
 
-  sofar = _bfd_ecoff_sizeof_headers (abfd, FALSE);
+  sofar = _bfd_ecoff_sizeof_headers (abfd, NULL);
   file_sofar = sofar;
 
   /* Sort the sections by VMA.  */
   amt = abfd->section_count;
   amt *= sizeof (asection *);
   file_sofar = sofar;
 
   /* Sort the sections by VMA.  */
   amt = abfd->section_count;
   amt *= sizeof (asection *);
-  sorted_hdrs = bfd_malloc (amt);
+  sorted_hdrs = (asection **) bfd_malloc (amt);
   if (sorted_hdrs == NULL)
     return FALSE;
   for (current = abfd->sections, i = 0;
   if (sorted_hdrs == NULL)
     return FALSE;
   for (current = abfd->sections, i = 0;
@@ -2026,8 +2073,8 @@ ecoff_compute_section_file_positions (bfd *abfd)
               && (abfd->flags & D_PAGED) != 0)
        {
          /* Skip up to the next page for an unallocated section, such
               && (abfd->flags & D_PAGED) != 0)
        {
          /* Skip up to the next page for an unallocated section, such
-             as the .comment section on the Alpha.  This leaves room
-             for the .bss section.  */
+            as the .comment section on the Alpha.  This leaves room
+            for the .bss section.  */
          first_nonalloc = FALSE;
          sofar = (sofar + round - 1) &~ (round - 1);
          file_sofar = (file_sofar + round - 1) &~ (round - 1);
          first_nonalloc = FALSE;
          sofar = (sofar + round - 1) &~ (round - 1);
          file_sofar = (file_sofar + round - 1) &~ (round - 1);
@@ -2171,22 +2218,6 @@ _bfd_ecoff_set_section_contents (bfd *abfd,
   return TRUE;
 }
 
   return TRUE;
 }
 
-/* Get the GP value for an ECOFF file.  This is a hook used by
-   nlmconv.  */
-
-bfd_vma
-bfd_ecoff_get_gp_value (bfd *abfd)
-{
-  if (bfd_get_flavour (abfd) != bfd_target_ecoff_flavour
-      || bfd_get_format (abfd) != bfd_object)
-    {
-      bfd_set_error (bfd_error_invalid_operation);
-      return 0;
-    }
-
-  return ecoff_data (abfd)->gp;
-}
-
 /* Set the GP value for an ECOFF file.  This is a hook used by the
    assembler.  */
 
 /* Set the GP value for an ECOFF file.  This is a hook used by the
    assembler.  */
 
@@ -2282,7 +2313,7 @@ ecoff_get_extr (asymbol *sym, EXTR *esym)
      symbol.  */
   if ((esym->asym.sc == scUndefined
        || esym->asym.sc == scSUndefined)
      symbol.  */
   if ((esym->asym.sc == scUndefined
        || esym->asym.sc == scSUndefined)
-      && ! bfd_is_und_section (bfd_get_section (sym)))
+      && ! bfd_is_und_section (bfd_asymbol_section (sym)))
     esym->asym.sc = scAbs;
 
   /* Adjust the FDR index for the symbol by that used for the input
     esym->asym.sc = scAbs;
 
   /* Adjust the FDR index for the symbol by that used for the input
@@ -2358,7 +2389,7 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
     }
 
   if ((abfd->flags & D_PAGED) != 0)
     }
 
   if ((abfd->flags & D_PAGED) != 0)
-    text_size = _bfd_ecoff_sizeof_headers (abfd, FALSE);
+    text_size = _bfd_ecoff_sizeof_headers (abfd, NULL);
   else
     text_size = 0;
   text_start = 0;
   else
     text_size = 0;
   text_start = 0;
@@ -2401,7 +2432,7 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
       strncpy (section.s_name, current->name, sizeof section.s_name);
 
       /* This seems to be correct for Irix 4 shared libraries.  */
       strncpy (section.s_name, current->name, sizeof section.s_name);
 
       /* This seems to be correct for Irix 4 shared libraries.  */
-      vma = bfd_get_section_vma (abfd, current);
+      vma = bfd_section_vma (current);
       if (streq (current->name, _LIB))
        section.s_vaddr = 0;
       else
       if (streq (current->name, _LIB))
        section.s_vaddr = 0;
       else
@@ -2633,6 +2664,7 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
          reloc_ptr_ptr = current->orelocation;
          reloc_end = reloc_ptr_ptr + current->reloc_count;
          out_ptr = (char *) reloc_buff;
          reloc_ptr_ptr = current->orelocation;
          reloc_end = reloc_ptr_ptr + current->reloc_count;
          out_ptr = (char *) reloc_buff;
+
          for (;
               reloc_ptr_ptr < reloc_end;
               reloc_ptr_ptr++, out_ptr += external_reloc_size)
          for (;
               reloc_ptr_ptr < reloc_end;
               reloc_ptr_ptr++, out_ptr += external_reloc_size)
@@ -2646,8 +2678,12 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
              reloc = *reloc_ptr_ptr;
              sym = *reloc->sym_ptr_ptr;
 
              reloc = *reloc_ptr_ptr;
              sym = *reloc->sym_ptr_ptr;
 
-             in.r_vaddr = (reloc->address
-                           + bfd_get_section_vma (abfd, current));
+             /* If the howto field has not been initialised then skip this reloc.
+                This assumes that an error message has been issued elsewhere.  */
+             if (reloc->howto == NULL)
+               continue;
+
+             in.r_vaddr = reloc->address + bfd_section_vma (current);
              in.r_type = reloc->howto->type;
 
              if ((sym->flags & BSF_SECTION_SYM) == 0)
              in.r_type = reloc->howto->type;
 
              if ((sym->flags & BSF_SECTION_SYM) == 0)
@@ -2658,7 +2694,7 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
              else
                {
                  const char *name;
              else
                {
                  const char *name;
-                 unsigned int i;
+                 unsigned int j;
                  static struct
                  {
                    const char * name;
                  static struct
                  {
                    const char * name;
@@ -2683,16 +2719,16 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
                    { _RCONST, RELOC_SECTION_RCONST }
                  };
 
                    { _RCONST, RELOC_SECTION_RCONST }
                  };
 
-                 name = bfd_get_section_name (abfd, bfd_get_section (sym));
+                 name = bfd_section_name (bfd_asymbol_section (sym));
 
 
-                 for (i = 0; i < ARRAY_SIZE (section_symndx); i++)
-                   if (streq (name, section_symndx[i].name))
+                 for (j = 0; j < ARRAY_SIZE (section_symndx); j++)
+                   if (streq (name, section_symndx[j].name))
                      {
                      {
-                       in.r_symndx = section_symndx[i].r_symndx;
+                       in.r_symndx = section_symndx[j].r_symndx;
                        break;
                      }
 
                        break;
                      }
 
-                 if (i == ARRAY_SIZE (section_symndx))
+                 if (j == ARRAY_SIZE (section_symndx))
                    abort ();
                  in.r_extern = 0;
                }
                    abort ();
                  in.r_extern = 0;
                }
@@ -2786,19 +2822,19 @@ _bfd_ecoff_write_object_contents (bfd *abfd)
 
    The Alpha seems to use ________64E[BL]E[BL]_.  */
 
 
    The Alpha seems to use ________64E[BL]E[BL]_.  */
 
-#define ARMAP_BIG_ENDIAN               'B'
-#define ARMAP_LITTLE_ENDIAN            'L'
-#define ARMAP_MARKER                   'E'
-#define ARMAP_START_LENGTH             10
+#define ARMAP_BIG_ENDIAN               'B'
+#define ARMAP_LITTLE_ENDIAN            'L'
+#define ARMAP_MARKER                   'E'
+#define ARMAP_START_LENGTH             10
 #define ARMAP_HEADER_MARKER_INDEX      10
 #define ARMAP_HEADER_MARKER_INDEX      10
-#define ARMAP_HEADER_ENDIAN_INDEX      11
-#define ARMAP_OBJECT_MARKER_INDEX      12
-#define ARMAP_OBJECT_ENDIAN_INDEX      13
-#define ARMAP_END_INDEX                14
-#define ARMAP_END                      "_ "
+#define ARMAP_HEADER_ENDIAN_INDEX      11
+#define ARMAP_OBJECT_MARKER_INDEX      12
+#define ARMAP_OBJECT_ENDIAN_INDEX      13
+#define ARMAP_END_INDEX                        14
+#define ARMAP_END                      "_ "
 
 /* This is a magic number used in the hashing algorithm.  */
 
 /* This is a magic number used in the hashing algorithm.  */
-#define ARMAP_HASH_MAGIC               0x9dd68ab5
+#define ARMAP_HASH_MAGIC               0x9dd68ab5
 
 /* This returns the hash value to use for a string.  It also sets
    *REHASH to the rehash adjustment if the first slot is taken.  SIZE
 
 /* This returns the hash value to use for a string.  It also sets
    *REHASH to the rehash adjustment if the first slot is taken.  SIZE
@@ -2836,7 +2872,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   struct artdata *ardata;
   unsigned int count;
   char *raw_ptr;
   struct artdata *ardata;
   unsigned int count;
   char *raw_ptr;
-  struct symdef *symdef_ptr;
+  carsym *symdef_ptr;
   char *stringbase;
   bfd_size_type amt;
 
   char *stringbase;
   bfd_size_type amt;
 
@@ -2855,7 +2891,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
      bfd_slurp_armap, but that seems inappropriate since no other
      target uses this format.  Instead, we check directly for a COFF
      armap.  */
      bfd_slurp_armap, but that seems inappropriate since no other
      target uses this format.  Instead, we check directly for a COFF
      armap.  */
-  if (strneq (nextname, "/               ", 16))
+  if (CONST_STRNEQ (nextname, "/               "))
     return bfd_slurp_armap (abfd);
 
   /* See if the first element is an armap.  */
     return bfd_slurp_armap (abfd);
 
   /* See if the first element is an armap.  */
@@ -2868,7 +2904,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
          && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
       || ! strneq (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1))
     {
          && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
       || ! strneq (nextname + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1))
     {
-      bfd_has_map (abfd) = FALSE;
+      abfd->has_armap = FALSE;
       return TRUE;
     }
 
       return TRUE;
     }
 
@@ -2888,9 +2924,9 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   if (mapdata == NULL)
     return FALSE;
   parsed_size = mapdata->parsed_size;
   if (mapdata == NULL)
     return FALSE;
   parsed_size = mapdata->parsed_size;
-  bfd_release (abfd, (void *) mapdata);
+  free (mapdata);
 
 
-  raw_armap = bfd_alloc (abfd, parsed_size);
+  raw_armap = (char *) bfd_alloc (abfd, parsed_size);
   if (raw_armap == NULL)
     return FALSE;
 
   if (raw_armap == NULL)
     return FALSE;
 
@@ -2956,12 +2992,12 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
       ++ardata->symdef_count;
 
   amt = ardata->symdef_count;
       ++ardata->symdef_count;
 
   amt = ardata->symdef_count;
-  amt *= sizeof (struct symdef);
-  symdef_ptr = bfd_alloc (abfd, amt);
+  amt *= sizeof (carsym);
+  symdef_ptr = (carsym *) bfd_alloc (abfd, amt);
   if (!symdef_ptr)
     return FALSE;
 
   if (!symdef_ptr)
     return FALSE;
 
-  ardata->symdefs = (carsym *) symdef_ptr;
+  ardata->symdefs = symdef_ptr;
 
   raw_ptr = raw_armap + 4;
   for (i = 0; i < count; i++, raw_ptr += 8)
 
   raw_ptr = raw_armap + 4;
   for (i = 0; i < count; i++, raw_ptr += 8)
@@ -2972,7 +3008,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
       if (file_offset == 0)
        continue;
       name_offset = H_GET_32 (abfd, raw_ptr);
       if (file_offset == 0)
        continue;
       name_offset = H_GET_32 (abfd, raw_ptr);
-      symdef_ptr->s.name = stringbase + name_offset;
+      symdef_ptr->name = stringbase + name_offset;
       symdef_ptr->file_offset = file_offset;
       ++symdef_ptr;
     }
       symdef_ptr->file_offset = file_offset;
       ++symdef_ptr;
     }
@@ -2981,7 +3017,7 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
   /* Pad to an even boundary.  */
   ardata->first_file_filepos += ardata->first_file_filepos % 2;
 
   /* Pad to an even boundary.  */
   ardata->first_file_filepos += ardata->first_file_filepos % 2;
 
-  bfd_has_map (abfd) = TRUE;
+  abfd->has_armap = TRUE;
 
   return TRUE;
 }
 
   return TRUE;
 }
@@ -3044,7 +3080,8 @@ _bfd_ecoff_write_armap (bfd *abfd,
      linker just checks the archive name; the GNU linker may check the
      date.  */
   stat (abfd->filename, &statbuf);
      linker just checks the archive name; the GNU linker may check the
      date.  */
   stat (abfd->filename, &statbuf);
-  sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
+  _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
+                   (long) (statbuf.st_mtime + 60));
 
   /* The DECstation uses zeroes for the uid, gid and mode of the
      armap.  */
 
   /* The DECstation uses zeroes for the uid, gid and mode of the
      armap.  */
@@ -3055,7 +3092,7 @@ _bfd_ecoff_write_armap (bfd *abfd,
   hdr.ar_mode[1] = '4';
   hdr.ar_mode[2] = '4';
 
   hdr.ar_mode[1] = '4';
   hdr.ar_mode[2] = '4';
 
-  sprintf (hdr.ar_size, "%-10d", (int) mapsize);
+  _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10ld", mapsize);
 
   hdr.ar_fmag[0] = '`';
   hdr.ar_fmag[1] = '\012';
 
   hdr.ar_fmag[0] = '`';
   hdr.ar_fmag[1] = '\012';
@@ -3073,7 +3110,7 @@ _bfd_ecoff_write_armap (bfd *abfd,
   if (bfd_bwrite ((void *) temp, (bfd_size_type) 4, abfd) != 4)
     return FALSE;
 
   if (bfd_bwrite ((void *) temp, (bfd_size_type) 4, abfd) != 4)
     return FALSE;
 
-  hashtable = bfd_zalloc (abfd, symdefsize);
+  hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
   if (!hashtable)
     return FALSE;
 
   if (!hashtable)
     return FALSE;
 
@@ -3081,7 +3118,7 @@ _bfd_ecoff_write_armap (bfd *abfd,
   last_elt = current;
   for (i = 0; i < orl_count; i++)
     {
   last_elt = current;
   for (i = 0; i < orl_count; i++)
     {
-      unsigned int hash, rehash;
+      unsigned int hash, rehash = 0;
 
       /* Advance firstreal to the file position of this archive
         element.  */
 
       /* Advance firstreal to the file position of this archive
         element.  */
@@ -3091,7 +3128,7 @@ _bfd_ecoff_write_armap (bfd *abfd,
            {
              firstreal += arelt_size (current) + sizeof (struct ar_hdr);
              firstreal += firstreal % 2;
            {
              firstreal += arelt_size (current) + sizeof (struct ar_hdr);
              firstreal += firstreal % 2;
-             current = current->next;
+             current = current->archive_next;
            }
          while (current != map[i].u.abfd);
        }
            }
          while (current != map[i].u.abfd);
        }
@@ -3147,87 +3184,6 @@ _bfd_ecoff_write_armap (bfd *abfd,
 
   return TRUE;
 }
 
   return TRUE;
 }
-
-/* See whether this BFD is an archive.  If it is, read in the armap
-   and the extended name table.  */
-
-const bfd_target *
-_bfd_ecoff_archive_p (bfd *abfd)
-{
-  struct artdata *tdata_hold;
-  char armag[SARMAG + 1];
-  bfd_size_type amt;
-
-  if (bfd_bread ((void *) armag, (bfd_size_type) SARMAG, abfd) != SARMAG)
-    {
-      if (bfd_get_error () != bfd_error_system_call)
-       bfd_set_error (bfd_error_wrong_format);
-      return NULL;
-    }
-
-  if (! strneq (armag, ARMAG, SARMAG))
-    {
-      bfd_set_error (bfd_error_wrong_format);
-      return NULL;
-    }
-
-  tdata_hold = bfd_ardata (abfd);
-
-  amt = sizeof (struct artdata);
-  bfd_ardata (abfd) = bfd_zalloc (abfd, amt);
-  if (bfd_ardata (abfd) == NULL)
-    {
-      bfd_ardata (abfd) = tdata_hold;
-      return NULL;
-    }
-
-  bfd_ardata (abfd)->first_file_filepos = SARMAG;
-  bfd_ardata (abfd)->cache = NULL;
-  bfd_ardata (abfd)->archive_head = NULL;
-  bfd_ardata (abfd)->symdefs = NULL;
-  bfd_ardata (abfd)->extended_names = NULL;
-  bfd_ardata (abfd)->tdata = NULL;
-
-  if (! _bfd_ecoff_slurp_armap (abfd)
-      || ! _bfd_ecoff_slurp_extended_name_table (abfd))
-    {
-      bfd_release (abfd, bfd_ardata (abfd));
-      bfd_ardata (abfd) = tdata_hold;
-      return NULL;
-    }
-
-  if (bfd_has_map (abfd))
-    {
-      bfd *first;
-
-      /* This archive has a map, so we may presume that the contents
-        are object files.  Make sure that if the first file in the
-        archive can be recognized as an object file, it is for this
-        target.  If not, assume that this is the wrong format.  If
-        the first file is not an object file, somebody is doing
-        something weird, and we permit it so that ar -t will work.  */
-
-      first = bfd_openr_next_archived_file (abfd, NULL);
-      if (first != NULL)
-       {
-         first->target_defaulted = FALSE;
-         if (bfd_check_format (first, bfd_object)
-             && first->xvec != abfd->xvec)
-           {
-             /* We ought to close `first' here, but we can't, because
-                we have no way to remove it from the archive cache.
-                It's almost impossible to figure out when we can
-                release bfd_ardata.  FIXME.  */
-             bfd_set_error (bfd_error_wrong_object_format);
-             bfd_ardata (abfd) = tdata_hold;
-             return NULL;
-           }
-         /* And we ought to close `first' here too.  */
-       }
-    }
-
-  return abfd->xvec;
-}
 \f
 /* ECOFF linker code.  */
 
 \f
 /* ECOFF linker code.  */
 
@@ -3274,11 +3230,12 @@ _bfd_ecoff_bfd_link_hash_table_create (bfd *abfd)
   struct ecoff_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct ecoff_link_hash_table);
 
   struct ecoff_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct ecoff_link_hash_table);
 
-  ret = bfd_malloc (amt);
+  ret = (struct ecoff_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
   if (ret == NULL)
     return NULL;
-  if (! _bfd_link_hash_table_init (&ret->root, abfd,
-                                  ecoff_link_hash_newfunc))
+  if (!_bfd_link_hash_table_init (&ret->root, abfd,
+                                 ecoff_link_hash_newfunc,
+                                 sizeof (struct ecoff_link_hash_entry)))
     {
       free (ret);
       return NULL;
     {
       free (ret);
       return NULL;
@@ -3292,14 +3249,6 @@ _bfd_ecoff_bfd_link_hash_table_create (bfd *abfd)
   ((struct ecoff_link_hash_entry *) \
    bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
 
   ((struct ecoff_link_hash_entry *) \
    bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
 
-/* Traverse an ECOFF link hash table.  */
-
-#define ecoff_link_hash_traverse(table, func, info)                    \
-  (bfd_link_hash_traverse                                              \
-   (&(table)->root,                                                    \
-    (bfd_boolean (*) (struct bfd_link_hash_entry *, void *)) (func),   \
-    (info)))
-
 /* Get the ECOFF link hash table from the info structure.  This is
    just a cast.  */
 
 /* Get the ECOFF link hash table from the info structure.  This is
    just a cast.  */
 
@@ -3331,7 +3280,7 @@ ecoff_link_add_externals (bfd *abfd,
 
   amt = ext_count;
   amt *= sizeof (struct bfd_link_hash_entry *);
 
   amt = ext_count;
   amt *= sizeof (struct bfd_link_hash_entry *);
-  sym_hash = bfd_alloc (abfd, amt);
+  sym_hash = (struct bfd_link_hash_entry **) bfd_alloc (abfd, amt);
   if (!sym_hash)
     return FALSE;
   ecoff_data (abfd)->sym_hashes = (struct ecoff_link_hash_entry **) sym_hash;
   if (!sym_hash)
     return FALSE;
   ecoff_data (abfd)->sym_hashes = (struct ecoff_link_hash_entry **) sym_hash;
@@ -3475,7 +3424,7 @@ ecoff_link_add_externals (bfd *abfd,
 
       /* If we are building an ECOFF hash table, save the external
         symbol information.  */
 
       /* If we are building an ECOFF hash table, save the external
         symbol information.  */
-      if (info->hash->creator->flavour == bfd_get_flavour (abfd))
+      if (bfd_get_flavour (info->output_bfd) == bfd_get_flavour (abfd))
        {
          if (h->abfd == NULL
              || (! bfd_is_und_section (section)
        {
          if (h->abfd == NULL
              || (! bfd_is_und_section (section)
@@ -3545,7 +3494,7 @@ ecoff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       || bfd_bread (external_ext, esize, abfd) != esize)
     goto error_return;
 
       || bfd_bread (external_ext, esize, abfd) != esize)
     goto error_return;
 
-  ssext = bfd_malloc ((bfd_size_type) symhdr->issExtMax);
+  ssext = (char *) bfd_malloc ((bfd_size_type) symhdr->issExtMax);
   if (ssext == NULL && symhdr->issExtMax != 0)
     goto error_return;
 
   if (ssext == NULL && symhdr->issExtMax != 0)
     goto error_return;
 
@@ -3576,124 +3525,23 @@ ecoff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 static bfd_boolean
 ecoff_link_check_archive_element (bfd *abfd,
                                  struct bfd_link_info *info,
 static bfd_boolean
 ecoff_link_check_archive_element (bfd *abfd,
                                  struct bfd_link_info *info,
+                                 struct bfd_link_hash_entry *h,
+                                 const char *name,
                                  bfd_boolean *pneeded)
 {
                                  bfd_boolean *pneeded)
 {
-  const struct ecoff_backend_data * const backend = ecoff_backend (abfd);
-  void (* const swap_ext_in) (bfd *, void *, EXTR *)
-    = backend->debug_swap.swap_ext_in;
-  HDRR *symhdr;
-  bfd_size_type external_ext_size;
-  void * external_ext = NULL;
-  bfd_size_type esize;
-  char *ssext = NULL;
-  char *ext_ptr;
-  char *ext_end;
-
   *pneeded = FALSE;
 
   *pneeded = FALSE;
 
-  if (! ecoff_slurp_symbolic_header (abfd))
-    goto error_return;
-
-  /* If there are no symbols, we don't want it.  */
-  if (bfd_get_symcount (abfd) == 0)
-    goto successful_return;
-
-  symhdr = &ecoff_data (abfd)->debug_info.symbolic_header;
-
-  /* Read in the external symbols and external strings.  */
-  external_ext_size = backend->debug_swap.external_ext_size;
-  esize = symhdr->iextMax * external_ext_size;
-  external_ext = bfd_malloc (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)
-    goto error_return;
-
-  ssext = bfd_malloc ((bfd_size_type) 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;
-
-  /* Look through the external symbols to see if they define some
-     symbol that is currently undefined.  */
-  ext_ptr = (char *) external_ext;
-  ext_end = ext_ptr + esize;
-  for (; ext_ptr < ext_end; ext_ptr += external_ext_size)
-    {
-      EXTR esym;
-      bfd_boolean def;
-      const char *name;
-      struct bfd_link_hash_entry *h;
-
-      (*swap_ext_in) (abfd, (void *) ext_ptr, &esym);
-
-      /* See if this symbol defines something.  */
-      if (esym.asym.st != stGlobal
-         && esym.asym.st != stLabel
-         && esym.asym.st != stProc)
-       continue;
-
-      switch (esym.asym.sc)
-       {
-       case scText:
-       case scData:
-       case scBss:
-       case scAbs:
-       case scSData:
-       case scSBss:
-       case scRData:
-       case scCommon:
-       case scSCommon:
-       case scInit:
-       case scFini:
-       case scRConst:
-         def = TRUE;
-         break;
-       default:
-         def = FALSE;
-         break;
-       }
-
-      if (! def)
-       continue;
-
-      name = ssext + esym.asym.iss;
-      h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
-
-      /* Unlike the generic linker, we do not pull in elements because
-        of common symbols.  */
-      if (h == NULL
-         || h->type != bfd_link_hash_undefined)
-       continue;
-
-      /* Include this element.  */
-      if (! (*info->callbacks->add_archive_element) (info, abfd, name))
-       goto error_return;
-      if (! ecoff_link_add_externals (abfd, info, external_ext, ssext))
-       goto error_return;
+  /* Unlike the generic linker, we do not pull in elements because
+     of common symbols.  */
+  if (h->type != bfd_link_hash_undefined)
+    return TRUE;
 
 
-      *pneeded = TRUE;
-      goto successful_return;
-    }
+  /* Include this element?  */
+  if (!(*info->callbacks->add_archive_element) (info, abfd, name, &abfd))
+    return TRUE;
+  *pneeded = TRUE;
 
 
- successful_return:
-  if (external_ext != NULL)
-    free (external_ext);
-  if (ssext != NULL)
-    free (ssext);
-  return TRUE;
- error_return:
-  if (external_ext != NULL)
-    free (external_ext);
-  if (ssext != NULL)
-    free (ssext);
-  return FALSE;
+  return ecoff_link_add_object_symbols (abfd, info);
 }
 
 /* Add the symbols from an archive file to the global hash table.
 }
 
 /* Add the symbols from an archive file to the global hash table.
@@ -3748,7 +3596,7 @@ ecoff_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
   while (*pundef != NULL)
     {
       struct bfd_link_hash_entry *h;
   while (*pundef != NULL)
     {
       struct bfd_link_hash_entry *h;
-      unsigned int hash, rehash;
+      unsigned int hash, rehash = 0;
       unsigned int file_offset;
       const char *name;
       bfd *element;
       unsigned int file_offset;
       const char *name;
       bfd *element;
@@ -3838,7 +3686,8 @@ ecoff_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
       /* Unlike the generic linker, we know that this element provides
         a definition for an undefined symbol and we know that we want
         to include it.  We don't need to check anything.  */
       /* Unlike the generic linker, we know that this element provides
         a definition for an undefined symbol and we know that we want
         to include it.  We don't need to check anything.  */
-      if (! (*info->callbacks->add_archive_element) (info, element, name))
+      if (!(*info->callbacks
+           ->add_archive_element) (info, element, name, &element))
        return FALSE;
       if (! ecoff_link_add_object_symbols (element, info))
        return FALSE;
        return FALSE;
       if (! ecoff_link_add_object_symbols (element, info))
        return FALSE;
@@ -3900,17 +3749,17 @@ ecoff_final_link_debug_accumulate (bfd *output_bfd,
   else                                                                  \
     {                                                                   \
       bfd_size_type amt = (bfd_size_type) size * symhdr->count;                 \
   else                                                                  \
     {                                                                   \
       bfd_size_type amt = (bfd_size_type) size * symhdr->count;                 \
-      debug->ptr = bfd_malloc (amt);                                    \
+      debug->ptr = (type) bfd_malloc (amt);                             \
       if (debug->ptr == NULL)                                           \
        {                                                                \
       if (debug->ptr == NULL)                                           \
        {                                                                \
-          ret = FALSE;                                                  \
-          goto return_something;                                        \
+         ret = FALSE;                                                   \
+         goto return_something;                                         \
        }                                                                \
       if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
          || bfd_bread (debug->ptr, amt, input_bfd) != amt)              \
        {                                                                \
        }                                                                \
       if (bfd_seek (input_bfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
          || bfd_bread (debug->ptr, amt, input_bfd) != amt)              \
        {                                                                \
-          ret = FALSE;                                                  \
-          goto return_something;                                        \
+         ret = FALSE;                                                   \
+         goto return_something;                                         \
        }                                                                \
     }
 
        }                                                                \
     }
 
@@ -3994,11 +3843,10 @@ ecoff_indirect_link_order (bfd *output_bfd,
 
   BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
 
 
   BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
 
-  if (link_order->size == 0)
-    return TRUE;
-
   input_section = link_order->u.indirect.section;
   input_bfd = input_section->owner;
   input_section = link_order->u.indirect.section;
   input_bfd = input_section->owner;
+  if (input_section->size == 0)
+    return TRUE;
 
   BFD_ASSERT (input_section->output_section == output_section);
   BFD_ASSERT (input_section->output_offset == link_order->offset);
 
   BFD_ASSERT (input_section->output_section == output_section);
   BFD_ASSERT (input_section->output_offset == link_order->offset);
@@ -4040,7 +3888,7 @@ ecoff_indirect_link_order (bfd *output_bfd,
      modified, and we write them out now.  We use the reloc_count
      field of output_section to keep track of the number of relocs we
      have output so far.  */
      modified, and we write them out now.  We use the reloc_count
      field of output_section to keep track of the number of relocs we
      have output so far.  */
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     {
       file_ptr pos = (output_section->rel_filepos
                      + output_section->reloc_count * external_reloc_size);
     {
       file_ptr pos = (output_section->rel_filepos
                      + output_section->reloc_count * external_reloc_size);
@@ -4111,7 +3959,7 @@ ecoff_reloc_link_order (bfd *output_bfd,
       struct bfd_link_hash_entry *h;
 
       /* Treat a reloc against a defined symbol as though it were
       struct bfd_link_hash_entry *h;
 
       /* Treat a reloc against a defined symbol as though it were
-         actually against the section.  */
+        actually against the section.  */
       h = bfd_wrapped_link_hash_lookup (output_bfd, info,
                                        link_order->u.reloc.p->u.name,
                                        FALSE, FALSE, FALSE);
       h = bfd_wrapped_link_hash_lookup (output_bfd, info,
                                        link_order->u.reloc.p->u.name,
                                        FALSE, FALSE, FALSE);
@@ -4122,8 +3970,8 @@ ecoff_reloc_link_order (bfd *output_bfd,
          type = bfd_section_reloc_link_order;
          section = h->u.def.section->output_section;
          /* It seems that we ought to add the symbol value to the
          type = bfd_section_reloc_link_order;
          section = h->u.def.section->output_section;
          /* It seems that we ought to add the symbol value to the
-             addend here, but in practice it has already been added
-             because it was passed to constructor_callback.  */
+            addend here, but in practice it has already been added
+            because it was passed to constructor_callback.  */
          addend += section->vma + h->u.def.section->output_offset;
        }
       else
          addend += section->vma + h->u.def.section->output_offset;
        }
       else
@@ -4146,8 +3994,8 @@ ecoff_reloc_link_order (bfd *output_bfd,
       bfd_byte *buf;
 
       size = bfd_get_reloc_size (rel.howto);
       bfd_byte *buf;
 
       size = bfd_get_reloc_size (rel.howto);
-      buf = bfd_zmalloc (size);
-      if (buf == NULL)
+      buf = (bfd_byte *) bfd_zmalloc (size);
+      if (buf == NULL && size != 0)
        return FALSE;
       rstat = _bfd_relocate_contents (rel.howto, output_bfd,
                                      (bfd_vma) addend, buf);
        return FALSE;
       rstat = _bfd_relocate_contents (rel.howto, output_bfd,
                                      (bfd_vma) addend, buf);
@@ -4159,17 +4007,12 @@ ecoff_reloc_link_order (bfd *output_bfd,
        case bfd_reloc_outofrange:
          abort ();
        case bfd_reloc_overflow:
        case bfd_reloc_outofrange:
          abort ();
        case bfd_reloc_overflow:
-         if (! ((*info->callbacks->reloc_overflow)
-                (info, NULL,
-                 (link_order->type == bfd_section_reloc_link_order
-                  ? bfd_section_name (output_bfd, section)
-                  : link_order->u.reloc.p->u.name),
-                 rel.howto->name, addend, NULL,
-                 NULL, (bfd_vma) 0)))
-           {
-             free (buf);
-             return FALSE;
-           }
+         (*info->callbacks->reloc_overflow)
+           (info, NULL,
+            (link_order->type == bfd_section_reloc_link_order
+             ? bfd_section_name (section)
+             : link_order->u.reloc.p->u.name),
+            rel.howto->name, addend, NULL, NULL, (bfd_vma) 0);
          break;
        }
       ok = bfd_set_section_contents (output_bfd, output_section, (void *) buf,
          break;
        }
       ok = bfd_set_section_contents (output_bfd, output_section, (void *) buf,
@@ -4182,8 +4025,7 @@ ecoff_reloc_link_order (bfd *output_bfd,
   rel.addend = 0;
 
   /* Move the information into an internal_reloc structure.  */
   rel.addend = 0;
 
   /* Move the information into an internal_reloc structure.  */
-  in.r_vaddr = (rel.address
-               + bfd_get_section_vma (output_bfd, output_section));
+  in.r_vaddr = rel.address + bfd_section_vma (output_section);
   in.r_type = rel.howto->type;
 
   if (type == bfd_symbol_reloc_link_order)
   in.r_type = rel.howto->type;
 
   if (type == bfd_symbol_reloc_link_order)
@@ -4199,10 +4041,8 @@ ecoff_reloc_link_order (bfd *output_bfd,
        in.r_symndx = h->indx;
       else
        {
        in.r_symndx = h->indx;
       else
        {
-         if (! ((*info->callbacks->unattached_reloc)
-                (info, link_order->u.reloc.p->u.name, NULL,
-                 NULL, (bfd_vma) 0)))
-           return FALSE;
+         (*info->callbacks->unattached_reloc)
+           (info, link_order->u.reloc.p->u.name, NULL, NULL, (bfd_vma) 0);
          in.r_symndx = 0;
        }
       in.r_extern = 1;
          in.r_symndx = 0;
        }
       in.r_extern = 1;
@@ -4235,7 +4075,7 @@ ecoff_reloc_link_order (bfd *output_bfd,
        { _RCONST, RELOC_SECTION_RCONST }
       };
 
        { _RCONST, RELOC_SECTION_RCONST }
       };
 
-      name = bfd_get_section_name (output_bfd, section);
+      name = bfd_section_name (section);
 
       for (i = 0; i < ARRAY_SIZE (section_symndx); i++)
        if (streq (name, section_symndx[i].name))
 
       for (i = 0; i < ARRAY_SIZE (section_symndx); i++)
        if (streq (name, section_symndx[i].name))
@@ -4255,7 +4095,7 @@ ecoff_reloc_link_order (bfd *output_bfd,
 
   /* Get some memory and swap out the reloc.  */
   external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size;
 
   /* Get some memory and swap out the reloc.  */
   external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size;
-  rbuf = bfd_malloc (external_reloc_size);
+  rbuf = (bfd_byte *) bfd_malloc (external_reloc_size);
   if (rbuf == NULL)
     return FALSE;
 
   if (rbuf == NULL)
     return FALSE;
 
@@ -4279,8 +4119,9 @@ ecoff_reloc_link_order (bfd *output_bfd,
    the hash table.  */
 
 static bfd_boolean
    the hash table.  */
 
 static bfd_boolean
-ecoff_link_write_external (struct ecoff_link_hash_entry *h, void * data)
+ecoff_link_write_external (struct bfd_hash_entry *bh, void * data)
 {
 {
+  struct ecoff_link_hash_entry *h = (struct ecoff_link_hash_entry *) bh;
   struct extsym_info *einfo = (struct extsym_info *) data;
   bfd *output_bfd = einfo->abfd;
   bfd_boolean strip;
   struct extsym_info *einfo = (struct extsym_info *) data;
   bfd *output_bfd = einfo->abfd;
   bfd_boolean strip;
@@ -4347,7 +4188,7 @@ ecoff_link_write_external (struct ecoff_link_hash_entry *h, void * data)
          };
 
          output_section = h->root.u.def.section->output_section;
          };
 
          output_section = h->root.u.def.section->output_section;
-         name = bfd_section_name (output_section->owner, output_section);
+         name = bfd_section_name (output_section);
 
          for (i = 0; i < ARRAY_SIZE (section_storage_classes); i++)
            if (streq (name, section_storage_classes[i].name))
 
          for (i = 0; i < ARRAY_SIZE (section_storage_classes); i++)
            if (streq (name, section_storage_classes[i].name))
@@ -4478,7 +4319,7 @@ _bfd_ecoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   /* Accumulate the debugging symbols from each input BFD.  */
   for (input_bfd = info->input_bfds;
        input_bfd != NULL;
   /* Accumulate the debugging symbols from each input BFD.  */
   for (input_bfd = info->input_bfds;
        input_bfd != NULL;
-       input_bfd = input_bfd->link_next)
+       input_bfd = input_bfd->link.next)
     {
       bfd_boolean ret;
 
     {
       bfd_boolean ret;
 
@@ -4511,11 +4352,9 @@ _bfd_ecoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   /* Write out the external symbols.  */
   einfo.abfd = abfd;
   einfo.info = info;
   /* Write out the external symbols.  */
   einfo.abfd = abfd;
   einfo.info = info;
-  ecoff_link_hash_traverse (ecoff_hash_table (info),
-                           ecoff_link_write_external,
-                           (void *) &einfo);
+  bfd_hash_traverse (&info->hash->table, ecoff_link_write_external, &einfo);
 
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     {
       /* We need to make a pass over the link_orders to count up the
         number of relocations we will need to output, so that we know
     {
       /* We need to make a pass over the link_orders to count up the
         number of relocations we will need to output, so that we know
@@ -4545,7 +4384,7 @@ _bfd_ecoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 
   bfd_ecoff_debug_free (handle, abfd, debug, &backend->debug_swap, info);
 
 
   bfd_ecoff_debug_free (handle, abfd, debug, &backend->debug_swap, info);
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     {
       /* Now reset the reloc_count field of the sections in the output
         BFD to 0, so that we can use them to keep track of how many
     {
       /* Now reset the reloc_count field of the sections in the output
         BFD to 0, so that we can use them to keep track of how many
@@ -4565,7 +4404,7 @@ _bfd_ecoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        ecoff_data (abfd)->gp = (h->u.def.value
                                 + h->u.def.section->output_section->vma
                                 + h->u.def.section->output_offset);
        ecoff_data (abfd)->gp = (h->u.def.value
                                 + h->u.def.section->output_section->vma
                                 + h->u.def.section->output_offset);
-      else if (info->relocatable)
+      else if (bfd_link_relocatable (info))
        {
          bfd_vma lo;
 
        {
          bfd_vma lo;
 
@@ -4618,7 +4457,7 @@ _bfd_ecoff_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        }
     }
 
        }
     }
 
-  bfd_get_symcount (abfd) = symhdr->iextMax + symhdr->isymMax;
+  abfd->symcount = symhdr->iextMax + symhdr->isymMax;
 
   ecoff_data (abfd)->linker = TRUE;
 
 
   ecoff_data (abfd)->linker = TRUE;
 
This page took 0.060574 seconds and 4 git commands to generate.