gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / aoutx.h
index f08171c9b3a277bef996808cbd44102920c17141..8fe2a62d21c76a60e2e219473156a8977cf68d2e 100644 (file)
@@ -1,14 +1,12 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005
-   Free Software Foundation, Inc.
+   Copyright (C) 1990-2020 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    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,
@@ -18,7 +16,8 @@
 
    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 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 /*
 SECTION
@@ -34,14 +33,13 @@ DESCRIPTION
        The support is split into a basic support file @file{aoutx.h}
        and other files which derive functions from the base. One
        derivation file is @file{aoutf1.h} (for a.out flavour 1), and
-       adds to the basic a.out functions support for sun3, sun4, 386
-       and 29k a.out files, to create a target jump vector for a
-       specific target.
+       adds to the basic a.out functions support for sun3, sun4, and
+       386 a.out files, to create a target jump vector for a specific
+       target.
 
        This information is further split out into more specific files
        for each machine, including @file{sunos.c} for sun3 and sun4,
-       @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
-       demonstration of a 64 bit a.out format.
+       and @file{demo64.c} for a demonstration of a 64 bit a.out format.
 
        The base file @file{aoutx.h} defines general mechanisms for
        reading and writing records to and from disk and various
@@ -67,12 +65,12 @@ DESCRIPTION
        from @file{sunos.c}:
 
 |      #define TARGET_NAME "a.out-sunos-big"
-|      #define VECNAME    sunos_big_vec
+|      #define VECNAME    sparc_aout_sunos_be_vec
 |      #include "aoutf1.h"
 
        requires all the names from @file{aout32.c}, and produces the jump vector
 
-|      sunos_big_vec
+|      sparc_aout_sunos_be_vec
 
        The file @file{host-aout.c} is a special case.  It is for a large set
        of hosts that use ``more or less standard'' a.out files, and
@@ -102,7 +100,7 @@ DESCRIPTION
 |      TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
 |      TDEPFILES= host-aout.o trad-core.o
 
-       in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
+       in the @file{config/@var{XXX}.mt} file, and modify @file{configure.ac}
        to use the
        @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your
        configuration is selected.  */
@@ -118,8 +116,9 @@ DESCRIPTION
 
 #define KEEPIT udata.i
 
-#include "bfd.h"
 #include "sysdep.h"
+#include <limits.h>
+#include "bfd.h"
 #include "safe-ctype.h"
 #include "bfdlink.h"
 
@@ -129,7 +128,17 @@ DESCRIPTION
 #include "aout/stab_gnu.h"
 #include "aout/ar.h"
 
-reloc_howto_type * NAME (aout, reloc_type_lookup)  (bfd *, bfd_reloc_code_real_type);
+#ifdef BMAGIC
+#define N_IS_BMAGIC(x) (N_MAGIC (x) == BMAGIC)
+#else
+#define N_IS_BMAGIC(x) (0)
+#endif
+
+#ifdef QMAGIC
+#define N_SET_QMAGIC(x) N_SET_MAGIC (x, QMAGIC)
+#else
+#define N_SET_QMAGIC(x) do { /**/ } while (0)
+#endif
 
 /*
 SUBSECTION
@@ -139,10 +148,9 @@ DESCRIPTION
        The file @file{aoutx.h} provides for both the @emph{standard}
        and @emph{extended} forms of a.out relocation records.
 
-       The standard records contain only an
-       address, a symbol index, and a type field. The extended records
-       (used on 29ks and sparcs) also have a full integer for an
-       addend.  */
+       The standard records contain only an address, a symbol index,
+       and a type field.  The extended records also have a full
+       integer for an addend.  */
 
 #ifndef CTOR_TABLE_RELOC_HOWTO
 #define CTOR_TABLE_RELOC_IDX 2
@@ -181,59 +189,59 @@ DESCRIPTION
 
 reloc_howto_type howto_table_ext[] =
 {
-  /*     Type         rs   size bsz  pcrel bitpos ovrf                  sf name          part_inpl readmask setmask pcdone.  */
-  HOWTO (RELOC_8,       0,  0,  8,  FALSE, 0, complain_overflow_bitfield, 0, "8",           FALSE, 0, 0x000000ff, FALSE),
-  HOWTO (RELOC_16,      0,  1,         16, FALSE, 0, complain_overflow_bitfield, 0, "16",          FALSE, 0, 0x0000ffff, FALSE),
-  HOWTO (RELOC_32,      0,  2,         32, FALSE, 0, complain_overflow_bitfield, 0, "32",          FALSE, 0, 0xffffffff, FALSE),
-  HOWTO (RELOC_DISP8,   0,  0,         8,  TRUE,  0, complain_overflow_signed,   0, "DISP8",       FALSE, 0, 0x000000ff, FALSE),
-  HOWTO (RELOC_DISP16,  0,  1,         16, TRUE,  0, complain_overflow_signed,   0, "DISP16",      FALSE, 0, 0x0000ffff, FALSE),
-  HOWTO (RELOC_DISP32,  0,  2,         32, TRUE,  0, complain_overflow_signed,   0, "DISP32",      FALSE, 0, 0xffffffff, FALSE),
-  HOWTO (RELOC_WDISP30, 2,  2,         30, TRUE,  0, complain_overflow_signed,   0, "WDISP30",     FALSE, 0, 0x3fffffff, FALSE),
-  HOWTO (RELOC_WDISP22, 2,  2,         22, TRUE,  0, complain_overflow_signed,   0, "WDISP22",     FALSE, 0, 0x003fffff, FALSE),
-  HOWTO (RELOC_HI22,   10,  2,         22, FALSE, 0, complain_overflow_bitfield, 0, "HI22",        FALSE, 0, 0x003fffff, FALSE),
-  HOWTO (RELOC_22,      0,  2,         22, FALSE, 0, complain_overflow_bitfield, 0, "22",          FALSE, 0, 0x003fffff, FALSE),
-  HOWTO (RELOC_13,      0,  2,         13, FALSE, 0, complain_overflow_bitfield, 0, "13",          FALSE, 0, 0x00001fff, FALSE),
-  HOWTO (RELOC_LO10,    0,  2,         10, FALSE, 0, complain_overflow_dont,     0, "LO10",        FALSE, 0, 0x000003ff, FALSE),
-  HOWTO (RELOC_SFA_BASE,0,  2,         32, FALSE, 0, complain_overflow_bitfield, 0, "SFA_BASE",    FALSE, 0, 0xffffffff, FALSE),
-  HOWTO (RELOC_SFA_OFF13,0, 2,         32, FALSE, 0, complain_overflow_bitfield, 0, "SFA_OFF13",   FALSE, 0, 0xffffffff, FALSE),
-  HOWTO (RELOC_BASE10,  0,  2,         10, FALSE, 0, complain_overflow_dont,     0, "BASE10",      FALSE, 0, 0x000003ff, FALSE),
-  HOWTO (RELOC_BASE13,  0,  2, 13, FALSE, 0, complain_overflow_signed,   0, "BASE13",      FALSE, 0, 0x00001fff, FALSE),
-  HOWTO (RELOC_BASE22, 10,  2, 22, FALSE, 0, complain_overflow_bitfield, 0, "BASE22",      FALSE, 0, 0x003fffff, FALSE),
-  HOWTO (RELOC_PC10,    0,  2, 10, TRUE,  0, complain_overflow_dont,     0, "PC10",        FALSE, 0, 0x000003ff, TRUE),
-  HOWTO (RELOC_PC22,   10,  2, 22, TRUE,  0, complain_overflow_signed,   0, "PC22",        FALSE, 0, 0x003fffff, TRUE),
-  HOWTO (RELOC_JMP_TBL, 2,  2,         30, TRUE,  0, complain_overflow_signed,   0, "JMP_TBL",     FALSE, 0, 0x3fffffff, FALSE),
+  /*    Type         rs   size bsz  pcrel bitpos ovrf                  sf name          part_inpl readmask setmask pcdone.  */
+  HOWTO (RELOC_8,      0,  0,  8,  FALSE, 0, complain_overflow_bitfield, 0, "8",           FALSE, 0, 0x000000ff, FALSE),
+  HOWTO (RELOC_16,     0,  1,  16, FALSE, 0, complain_overflow_bitfield, 0, "16",          FALSE, 0, 0x0000ffff, FALSE),
+  HOWTO (RELOC_32,     0,  2,  32, FALSE, 0, complain_overflow_bitfield, 0, "32",          FALSE, 0, 0xffffffff, FALSE),
+  HOWTO (RELOC_DISP8,  0,  0,  8,  TRUE,  0, complain_overflow_signed,   0, "DISP8",       FALSE, 0, 0x000000ff, FALSE),
+  HOWTO (RELOC_DISP16, 0,  1,  16, TRUE,  0, complain_overflow_signed,   0, "DISP16",      FALSE, 0, 0x0000ffff, FALSE),
+  HOWTO (RELOC_DISP32, 0,  2,  32, TRUE,  0, complain_overflow_signed,   0, "DISP32",      FALSE, 0, 0xffffffff, FALSE),
+  HOWTO (RELOC_WDISP30, 2,  2, 30, TRUE,  0, complain_overflow_signed,   0, "WDISP30",     FALSE, 0, 0x3fffffff, FALSE),
+  HOWTO (RELOC_WDISP22, 2,  2, 22, TRUE,  0, complain_overflow_signed,   0, "WDISP22",     FALSE, 0, 0x003fffff, FALSE),
+  HOWTO (RELOC_HI22,   10,  2, 22, FALSE, 0, complain_overflow_bitfield, 0, "HI22",        FALSE, 0, 0x003fffff, FALSE),
+  HOWTO (RELOC_22,     0,  2,  22, FALSE, 0, complain_overflow_bitfield, 0, "22",          FALSE, 0, 0x003fffff, FALSE),
+  HOWTO (RELOC_13,     0,  2,  13, FALSE, 0, complain_overflow_bitfield, 0, "13",          FALSE, 0, 0x00001fff, FALSE),
+  HOWTO (RELOC_LO10,   0,  2,  10, FALSE, 0, complain_overflow_dont,     0, "LO10",        FALSE, 0, 0x000003ff, FALSE),
+  HOWTO (RELOC_SFA_BASE,0,  2, 32, FALSE, 0, complain_overflow_bitfield, 0, "SFA_BASE",    FALSE, 0, 0xffffffff, FALSE),
+  HOWTO (RELOC_SFA_OFF13,0, 2, 32, FALSE, 0, complain_overflow_bitfield, 0, "SFA_OFF13",   FALSE, 0, 0xffffffff, FALSE),
+  HOWTO (RELOC_BASE10, 0,  2,  10, FALSE, 0, complain_overflow_dont,     0, "BASE10",      FALSE, 0, 0x000003ff, FALSE),
+  HOWTO (RELOC_BASE13, 0,  2,  13, FALSE, 0, complain_overflow_signed,   0, "BASE13",      FALSE, 0, 0x00001fff, FALSE),
+  HOWTO (RELOC_BASE22, 10,  2, 22, FALSE, 0, complain_overflow_bitfield, 0, "BASE22",      FALSE, 0, 0x003fffff, FALSE),
+  HOWTO (RELOC_PC10,   0,  2,  10, TRUE,  0, complain_overflow_dont,     0, "PC10",        FALSE, 0, 0x000003ff, TRUE),
+  HOWTO (RELOC_PC22,   10,  2, 22, TRUE,  0, complain_overflow_signed,   0, "PC22",        FALSE, 0, 0x003fffff, TRUE),
+  HOWTO (RELOC_JMP_TBL, 2,  2, 30, TRUE,  0, complain_overflow_signed,   0, "JMP_TBL",     FALSE, 0, 0x3fffffff, FALSE),
   HOWTO (RELOC_SEGOFF16,0,  2, 0,  FALSE, 0, complain_overflow_bitfield, 0, "SEGOFF16",    FALSE, 0, 0x00000000, FALSE),
   HOWTO (RELOC_GLOB_DAT,0,  2, 0,  FALSE, 0, complain_overflow_bitfield, 0, "GLOB_DAT",    FALSE, 0, 0x00000000, FALSE),
   HOWTO (RELOC_JMP_SLOT,0,  2, 0,  FALSE, 0, complain_overflow_bitfield, 0, "JMP_SLOT",    FALSE, 0, 0x00000000, FALSE),
   HOWTO (RELOC_RELATIVE,0,  2, 0,  FALSE, 0, complain_overflow_bitfield, 0, "RELATIVE",    FALSE, 0, 0x00000000, FALSE),
-  HOWTO (0,             0,  0,  0,  FALSE, 0, complain_overflow_dont,     0, "R_SPARC_NONE",FALSE, 0, 0x00000000, TRUE),
-  HOWTO (0,             0,  0,  0,  FALSE, 0, complain_overflow_dont,     0, "R_SPARC_NONE",FALSE, 0, 0x00000000, TRUE),
+  HOWTO (0,            0,  3,  0,  FALSE, 0, complain_overflow_dont,     0, "R_SPARC_NONE",FALSE, 0, 0x00000000, TRUE),
+  HOWTO (0,            0,  3,  0,  FALSE, 0, complain_overflow_dont,     0, "R_SPARC_NONE",FALSE, 0, 0x00000000, TRUE),
 #define RELOC_SPARC_REV32 RELOC_WDISP19
-  HOWTO (RELOC_SPARC_REV32, 0, 2, 32, FALSE, 0, complain_overflow_dont,   0,"R_SPARC_REV32",FALSE, 0, 0xffffffff, FALSE),
+  HOWTO (RELOC_SPARC_REV32, 0, 2, 32, FALSE, 0, complain_overflow_dont,          0,"R_SPARC_REV32",FALSE, 0, 0xffffffff, FALSE),
 };
 
 /* Convert standard reloc records to "arelent" format (incl byte swap).  */
 
 reloc_howto_type howto_table_std[] =
 {
-  /* type              rs size bsz  pcrel bitpos ovrf                     sf name     part_inpl readmask  setmask    pcdone.  */
-HOWTO ( 0,            0,  0,   8,  FALSE, 0, complain_overflow_bitfield,0,"8",         TRUE, 0x000000ff,0x000000ff, FALSE),
-HOWTO ( 1,            0,  1,   16, FALSE, 0, complain_overflow_bitfield,0,"16",        TRUE, 0x0000ffff,0x0000ffff, FALSE),
-HOWTO ( 2,            0,  2,   32, FALSE, 0, complain_overflow_bitfield,0,"32",        TRUE, 0xffffffff,0xffffffff, FALSE),
-HOWTO ( 3,            0,  4,   64, FALSE, 0, complain_overflow_bitfield,0,"64",        TRUE, 0xdeaddead,0xdeaddead, FALSE),
-HOWTO ( 4,            0,  0,   8,  TRUE,  0, complain_overflow_signed,  0,"DISP8",     TRUE, 0x000000ff,0x000000ff, FALSE),
-HOWTO ( 5,            0,  1,   16, TRUE,  0, complain_overflow_signed,  0,"DISP16",    TRUE, 0x0000ffff,0x0000ffff, FALSE),
-HOWTO ( 6,            0,  2,   32, TRUE,  0, complain_overflow_signed,  0,"DISP32",    TRUE, 0xffffffff,0xffffffff, FALSE),
-HOWTO ( 7,            0,  4,   64, TRUE,  0, complain_overflow_signed,  0,"DISP64",    TRUE, 0xfeedface,0xfeedface, FALSE),
-HOWTO ( 8,            0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"GOT_REL",   FALSE,         0,0x00000000, FALSE),
-HOWTO ( 9,            0,  1,   16, FALSE, 0, complain_overflow_bitfield,0,"BASE16",    FALSE,0xffffffff,0xffffffff, FALSE),
-HOWTO (10,            0,  2,   32, FALSE, 0, complain_overflow_bitfield,0,"BASE32",    FALSE,0xffffffff,0xffffffff, FALSE),
+  /* type             rs size bsz  pcrel bitpos ovrf                     sf name     part_inpl readmask  setmask    pcdone.  */
+HOWTO ( 0,            0,  0,   8,  FALSE, 0, complain_overflow_bitfield,0,"8",         TRUE, 0x000000ff,0x000000ff, FALSE),
+HOWTO ( 1,            0,  1,   16, FALSE, 0, complain_overflow_bitfield,0,"16",        TRUE, 0x0000ffff,0x0000ffff, FALSE),
+HOWTO ( 2,            0,  2,   32, FALSE, 0, complain_overflow_bitfield,0,"32",        TRUE, 0xffffffff,0xffffffff, FALSE),
+HOWTO ( 3,            0,  4,   64, FALSE, 0, complain_overflow_bitfield,0,"64",        TRUE, 0xdeaddead,0xdeaddead, FALSE),
+HOWTO ( 4,            0,  0,   8,  TRUE,  0, complain_overflow_signed,  0,"DISP8",     TRUE, 0x000000ff,0x000000ff, FALSE),
+HOWTO ( 5,            0,  1,   16, TRUE,  0, complain_overflow_signed,  0,"DISP16",    TRUE, 0x0000ffff,0x0000ffff, FALSE),
+HOWTO ( 6,            0,  2,   32, TRUE,  0, complain_overflow_signed,  0,"DISP32",    TRUE, 0xffffffff,0xffffffff, FALSE),
+HOWTO ( 7,            0,  4,   64, TRUE,  0, complain_overflow_signed,  0,"DISP64",    TRUE, 0xfeedface,0xfeedface, FALSE),
+HOWTO ( 8,            0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"GOT_REL",   FALSE,         0,0x00000000, FALSE),
+HOWTO ( 9,            0,  1,   16, FALSE, 0, complain_overflow_bitfield,0,"BASE16",    FALSE,0xffffffff,0xffffffff, FALSE),
+HOWTO (10,            0,  2,   32, FALSE, 0, complain_overflow_bitfield,0,"BASE32",    FALSE,0xffffffff,0xffffffff, FALSE),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
-  HOWTO (16,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"JMP_TABLE", FALSE,         0,0x00000000, FALSE),
+  HOWTO (16,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"JMP_TABLE", FALSE,         0,0x00000000, FALSE),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
@@ -249,7 +257,7 @@ EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
-  HOWTO (32,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE",  FALSE,         0,0x00000000, FALSE),
+  HOWTO (32,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"RELATIVE",  FALSE,         0,0x00000000, FALSE),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
@@ -257,7 +265,7 @@ EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
 EMPTY_HOWTO (-1),
-  HOWTO (40,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL",   FALSE,         0,0x00000000, FALSE),
+  HOWTO (40,          0,  2,    0, FALSE, 0, complain_overflow_bitfield,0,"BASEREL",   FALSE,         0,0x00000000, FALSE),
 };
 
 #define TABLE_SIZE(TABLE)      (sizeof (TABLE) / sizeof (TABLE[0]))
@@ -270,7 +278,7 @@ NAME (aout, reloc_type_lookup) (bfd *abfd, bfd_reloc_code_real_type code)
   int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE;
 
   if (code == BFD_RELOC_CTOR)
-    switch (bfd_get_arch_info (abfd)->bits_per_address)
+    switch (bfd_arch_bits_per_address (abfd))
       {
       case 32:
        code = BFD_RELOC_32;
@@ -319,6 +327,31 @@ NAME (aout, reloc_type_lookup) (bfd *abfd, bfd_reloc_code_real_type code)
       }
 }
 
+reloc_howto_type *
+NAME (aout, reloc_name_lookup) (bfd *abfd, const char *r_name)
+{
+  unsigned int i, size;
+  reloc_howto_type *howto_table;
+
+  if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
+    {
+      howto_table = howto_table_ext;
+      size = sizeof (howto_table_ext) / sizeof (howto_table_ext[0]);
+    }
+  else
+    {
+      howto_table = howto_table_std;
+      size = sizeof (howto_table_std) / sizeof (howto_table_std[0]);
+    }
+
+  for (i = 0; i < size; i++)
+    if (howto_table[i].name != NULL
+       && strcasecmp (howto_table[i].name, r_name) == 0)
+      return &howto_table[i];
+
+  return NULL;
+}
+
 /*
 SUBSECTION
        Internal entry points
@@ -335,9 +368,9 @@ FUNCTION
 
 SYNOPSIS
        void aout_@var{size}_swap_exec_header_in,
-           (bfd *abfd,
-            struct external_exec *bytes,
-            struct internal_exec *execp);
+          (bfd *abfd,
+           struct external_exec *bytes,
+           struct internal_exec *execp);
 
 DESCRIPTION
        Swap the information in an executable header @var{raw_bytes} taken
@@ -420,7 +453,7 @@ FUNCTION
 SYNOPSIS
        const bfd_target *aout_@var{size}_some_aout_object_p
         (bfd *abfd,
-          struct internal_exec *execp,
+         struct internal_exec *execp,
          const bfd_target *(*callback_to_real_object_p) (bfd *));
 
 DESCRIPTION
@@ -431,26 +464,23 @@ DESCRIPTION
        handle any last-minute setup.
 */
 
-const bfd_target *
+bfd_cleanup
 NAME (aout, some_aout_object_p) (bfd *abfd,
                                 struct internal_exec *execp,
-                                const bfd_target *(*callback_to_real_object_p) (bfd *))
+                                bfd_cleanup (*callback_to_real_object_p) (bfd *))
 {
   struct aout_data_struct *rawptr, *oldrawptr;
-  const bfd_target *result;
-  bfd_size_type amt = sizeof (* rawptr);
+  bfd_cleanup result;
+  size_t amt = sizeof (* rawptr);
 
-  rawptr = bfd_zalloc (abfd, amt);
+  rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
   if (rawptr == NULL)
     return NULL;
 
   oldrawptr = abfd->tdata.aout_data;
   abfd->tdata.aout_data = rawptr;
 
-  /* Copy the contents of the old tdata struct.
-     In particular, we want the subformat, since for hpux it was set in
-     hp300hpux.c:swap_exec_header_in and will be used in
-     hp300hpux.c:callback.  */
+  /* Copy the contents of the old tdata struct.  */
   if (oldrawptr != NULL)
     *abfd->tdata.aout_data = *oldrawptr;
 
@@ -466,37 +496,36 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   /* Setting of EXEC_P has been deferred to the bottom of this function.  */
   if (execp->a_syms)
     abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
-  if (N_DYNAMIC (*execp))
+  if (N_DYNAMIC (execp))
     abfd->flags |= DYNAMIC;
 
-  if (N_MAGIC (*execp) == ZMAGIC)
+  if (N_MAGIC (execp) == ZMAGIC)
     {
       abfd->flags |= D_PAGED | WP_TEXT;
       adata (abfd).magic = z_magic;
     }
-  else if (N_MAGIC (*execp) == QMAGIC)
+  else if (N_IS_QMAGIC (execp))
     {
       abfd->flags |= D_PAGED | WP_TEXT;
       adata (abfd).magic = z_magic;
       adata (abfd).subformat = q_magic_format;
     }
-  else if (N_MAGIC (*execp) == NMAGIC)
+  else if (N_MAGIC (execp) == NMAGIC)
     {
       abfd->flags |= WP_TEXT;
       adata (abfd).magic = n_magic;
     }
-  else if (N_MAGIC (*execp) == OMAGIC
-          || N_MAGIC (*execp) == BMAGIC)
+  else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp))
     adata (abfd).magic = o_magic;
   else
     /* Should have been checked with N_BADMAG before this routine
        was called.  */
     abort ();
 
-  bfd_get_start_address (abfd) = execp->a_entry;
+  abfd->start_address = execp->a_entry;
 
   obj_aout_symbols (abfd) = NULL;
-  bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
+  abfd->symcount = execp->a_syms / sizeof (struct external_nlist);
 
   /* The default relocation entry size is that of traditional V7 Unix.  */
   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
@@ -541,28 +570,28 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
 
   struct exec *execp = exec_hdr (abfd);
 
-  obj_textsec (abfd)->size = N_TXTSIZE (*execp);
+  obj_textsec (abfd)->size = N_TXTSIZE (execp);
   /* Data and bss are already filled in since they're so standard.  */
 
   /* The virtual memory addresses of the sections.  */
-  obj_textsec (abfd)->vma = N_TXTADDR (*execp);
-  obj_datasec (abfd)->vma = N_DATADDR (*execp);
-  obj_bsssec  (abfd)->vma = N_BSSADDR (*execp);
+  obj_textsec (abfd)->vma = N_TXTADDR (execp);
+  obj_datasec (abfd)->vma = N_DATADDR (execp);
+  obj_bsssec  (abfd)->vma = N_BSSADDR (execp);
 
   /* The file offsets of the sections.  */
-  obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
-  obj_datasec (abfd)->filepos = N_DATOFF (*execp);
+  obj_textsec (abfd)->filepos = N_TXTOFF (execp);
+  obj_datasec (abfd)->filepos = N_DATOFF (execp);
 
   /* The file offsets of the relocation info.  */
-  obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
-  obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
+  obj_textsec (abfd)->rel_filepos = N_TRELOFF (execp);
+  obj_datasec (abfd)->rel_filepos = N_DRELOFF (execp);
 
   /* The file offsets of the string table and symbol table.  */
-  obj_str_filepos (abfd) = N_STROFF (*execp);
-  obj_sym_filepos (abfd) = N_SYMOFF (*execp);
+  obj_str_filepos (abfd) = N_STROFF (execp);
+  obj_sym_filepos (abfd) = N_SYMOFF (execp);
 
   /* Determine the architecture and machine type of the object file.  */
-  switch (N_MACHTYPE (*exec_hdr (abfd)))
+  switch (N_MACHTYPE (exec_hdr (abfd)))
     {
     default:
       abfd->obj_arch = bfd_arch_obscure;
@@ -573,7 +602,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   adata (abfd)->segment_size = SEGMENT_SIZE;
   adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup
 
   /* The architecture is encoded in various ways in various a.out variants,
      or is not encoded at all in some of them.  The relocation size depends
@@ -605,7 +634,9 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   if (execp->a_entry != 0
       || (execp->a_entry >= obj_textsec (abfd)->vma
          && execp->a_entry < (obj_textsec (abfd)->vma
-                              + obj_textsec (abfd)->size)))
+                              + obj_textsec (abfd)->size)
+         && execp->a_trsize == 0
+         && execp->a_drsize == 0))
     abfd->flags |= EXEC_P;
 #ifdef STAT_FOR_EXEC
   else
@@ -613,12 +644,12 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
       struct stat stat_buf;
 
       /* The original heuristic doesn't work in some important cases.
-        The a.out file has no information about the text start
-        address.  For files (like kernels) linked to non-standard
-        addresses (ld -Ttext nnn) the entry point may not be between
-        the default text start (obj_textsec(abfd)->vma) and
-        (obj_textsec(abfd)->vma) + text size.  This is not just a mach
-        issue.  Many kernels are loaded at non standard addresses.  */
+       The a.out file has no information about the text start
+       address.  For files (like kernels) linked to non-standard
+       addresses (ld -Ttext nnn) the entry point may not be between
+       the default text start (obj_textsec(abfd)->vma) and
+       (obj_textsec(abfd)->vma) + text size.  This is not just a mach
+       issue.  Many kernels are loaded at non standard addresses.  */
       if (abfd->iostream != NULL
          && (abfd->flags & BFD_IN_MEMORY) == 0
          && (fstat (fileno ((FILE *) (abfd->iostream)), &stat_buf) == 0)
@@ -651,11 +682,11 @@ bfd_boolean
 NAME (aout, mkobject) (bfd *abfd)
 {
   struct aout_data_struct *rawptr;
-  bfd_size_type amt = sizeof (* rawptr);
+  size_t amt = sizeof (* rawptr);
 
   bfd_set_error (bfd_error_system_call);
 
-  rawptr = bfd_zalloc (abfd, amt);
+  rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
   if (rawptr == NULL)
     return FALSE;
 
@@ -677,7 +708,7 @@ SYNOPSIS
        enum machine_type  aout_@var{size}_machine_type
         (enum bfd_architecture arch,
          unsigned long machine,
-          bfd_boolean *unknown);
+         bfd_boolean *unknown);
 
 DESCRIPTION
        Keep track of machine architecture and machine type for
@@ -706,23 +737,29 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
          || machine == bfd_mach_sparc
          || machine == bfd_mach_sparc_sparclite
          || machine == bfd_mach_sparc_sparclite_le
-         || machine == bfd_mach_sparc_v9)
+         || machine == bfd_mach_sparc_v8plus
+         || machine == bfd_mach_sparc_v8plusa
+         || machine == bfd_mach_sparc_v8plusb
+         || machine == bfd_mach_sparc_v8plusc
+         || machine == bfd_mach_sparc_v8plusd
+         || machine == bfd_mach_sparc_v8pluse
+         || machine == bfd_mach_sparc_v8plusv
+         || machine == bfd_mach_sparc_v8plusm
+         || machine == bfd_mach_sparc_v8plusm8
+         || machine == bfd_mach_sparc_v9
+         || machine == bfd_mach_sparc_v9a
+         || machine == bfd_mach_sparc_v9b
+         || machine == bfd_mach_sparc_v9c
+         || machine == bfd_mach_sparc_v9d
+         || machine == bfd_mach_sparc_v9e
+         || machine == bfd_mach_sparc_v9v
+         || machine == bfd_mach_sparc_v9m
+         || machine == bfd_mach_sparc_v9m8)
        arch_flags = M_SPARC;
       else if (machine == bfd_mach_sparc_sparclet)
        arch_flags = M_SPARCLET;
       break;
 
-    case bfd_arch_m68k:
-      switch (machine)
-       {
-       case 0:               arch_flags = M_68010; break;
-       case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = FALSE; break;
-       case bfd_mach_m68010: arch_flags = M_68010; break;
-       case bfd_mach_m68020: arch_flags = M_68020; break;
-       default:              arch_flags = M_UNKNOWN; break;
-       }
-      break;
-
     case bfd_arch_i386:
       if (machine == 0
          || machine == bfd_mach_i386_i386
@@ -730,11 +767,6 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        arch_flags = M_386;
       break;
 
-    case bfd_arch_a29k:
-      if (machine == 0)
-       arch_flags = M_29K;
-      break;
-
     case bfd_arch_arm:
       if (machine == 0)
        arch_flags = M_ARM;
@@ -762,13 +794,22 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        case bfd_mach_mips9000:
        case bfd_mach_mips10000:
        case bfd_mach_mips12000:
+       case bfd_mach_mips14000:
+       case bfd_mach_mips16000:
        case bfd_mach_mips16:
        case bfd_mach_mipsisa32:
        case bfd_mach_mipsisa32r2:
+       case bfd_mach_mipsisa32r3:
+       case bfd_mach_mipsisa32r5:
+       case bfd_mach_mipsisa32r6:
        case bfd_mach_mips5:
        case bfd_mach_mipsisa64:
        case bfd_mach_mipsisa64r2:
+       case bfd_mach_mipsisa64r3:
+       case bfd_mach_mipsisa64r5:
+       case bfd_mach_mipsisa64r6:
        case bfd_mach_mips_sb1:
+       case bfd_mach_mips_xlr:
          /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc.  */
          arch_flags = M_MIPS2;
          break;
@@ -781,7 +822,7 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
     case bfd_arch_ns32k:
       switch (machine)
        {
-       case 0:         arch_flags = M_NS32532; break;
+       case 0:         arch_flags = M_NS32532; break;
        case 32032:     arch_flags = M_NS32032; break;
        case 32532:     arch_flags = M_NS32532; break;
        default:        arch_flags = M_UNKNOWN; break;
@@ -797,10 +838,6 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        arch_flags = M_CRIS;
       break;
 
-    case bfd_arch_m88k:
-      *unknown = FALSE;
-      break;
-
     default:
       arch_flags = M_UNKNOWN;
     }
@@ -848,7 +885,6 @@ NAME (aout, set_arch_mach) (bfd *abfd,
   switch (arch)
     {
     case bfd_arch_sparc:
-    case bfd_arch_a29k:
     case bfd_arch_mips:
       obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
       break;
@@ -866,58 +902,57 @@ adjust_o_magic (bfd *abfd, struct internal_exec *execp)
   file_ptr pos = adata (abfd).exec_bytes_size;
   bfd_vma vma = 0;
   int pad = 0;
+  asection *text = obj_textsec (abfd);
+  asection *data = obj_datasec (abfd);
+  asection *bss = obj_bsssec (abfd);
 
   /* Text.  */
-  obj_textsec (abfd)->filepos = pos;
-  if (!obj_textsec (abfd)->user_set_vma)
-    obj_textsec (abfd)->vma = vma;
+  text->filepos = pos;
+  if (!text->user_set_vma)
+    text->vma = vma;
   else
-    vma = obj_textsec (abfd)->vma;
+    vma = text->vma;
 
-  pos += obj_textsec (abfd)->size;
-  vma += obj_textsec (abfd)->size;
+  pos += execp->a_text;
+  vma += execp->a_text;
 
   /* Data.  */
-  if (!obj_datasec (abfd)->user_set_vma)
+  if (!data->user_set_vma)
     {
-      obj_textsec (abfd)->size += pad;
       pos += pad;
       vma += pad;
-      obj_datasec (abfd)->vma = vma;
+      data->vma = vma;
     }
   else
-    vma = obj_datasec (abfd)->vma;
-  obj_datasec (abfd)->filepos = pos;
-  pos += obj_datasec (abfd)->size;
-  vma += obj_datasec (abfd)->size;
+    vma = data->vma;
+  execp->a_text += pad;
+
+  data->filepos = pos;
+  pos += data->size;
+  vma += data->size;
 
   /* BSS.  */
-  if (!obj_bsssec (abfd)->user_set_vma)
+  if (!bss->user_set_vma)
     {
-      obj_datasec (abfd)->size += pad;
       pos += pad;
       vma += pad;
-      obj_bsssec (abfd)->vma = vma;
+      bss->vma = vma;
     }
   else
     {
       /* The VMA of the .bss section is set by the VMA of the
-         .data section plus the size of the .data section.  We may
-         need to add padding bytes to make this true.  */
-      pad = obj_bsssec (abfd)->vma - vma;
-      if (pad > 0)
-       {
-         obj_datasec (abfd)->size += pad;
-         pos += pad;
-       }
+        .data section plus the size of the .data section.  We may
+        need to add padding bytes to make this true.  */
+      pad = bss->vma - vma;
+      if (pad < 0)
+       pad = 0;
+      pos += pad;
     }
-  obj_bsssec (abfd)->filepos = pos;
+  execp->a_data = data->size + pad;
+  bss->filepos = pos;
+  execp->a_bss = bss->size;
 
-  /* Fix up the exec header.  */
-  execp->a_text = obj_textsec (abfd)->size;
-  execp->a_data = obj_datasec (abfd)->size;
-  execp->a_bss = obj_bsssec (abfd)->size;
-  N_SET_MAGIC (*execp, OMAGIC);
+  N_SET_MAGIC (execp, OMAGIC);
 }
 
 static void
@@ -928,6 +963,9 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp)
   const struct aout_backend_data *abdp;
   /* TRUE if text includes exec header.  */
   bfd_boolean ztih;
+  asection *text = obj_textsec (abfd);
+  asection *data = obj_datasec (abfd);
+  asection *bss = obj_bsssec (abfd);
 
   abdp = aout_backend_info (abfd);
 
@@ -935,37 +973,36 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp)
   ztih = (abdp != NULL
          && (abdp->text_includes_header
              || obj_aout_subformat (abfd) == q_magic_format));
-  obj_textsec (abfd)->filepos = (ztih
-                                ? adata (abfd).exec_bytes_size
-                                : adata (abfd).zmagic_disk_block_size);
-  if (! obj_textsec (abfd)->user_set_vma)
+  text->filepos = (ztih
+                  ? adata (abfd).exec_bytes_size
+                  : adata (abfd).zmagic_disk_block_size);
+  if (!text->user_set_vma)
     {
       /* ?? Do we really need to check for relocs here?  */
-      obj_textsec (abfd)->vma = ((abfd->flags & HAS_RELOC)
-                                ? 0
-                                : (ztih
-                                   ? (abdp->default_text_vma
-                                      + adata (abfd).exec_bytes_size)
-                                   : abdp->default_text_vma));
+      text->vma = ((abfd->flags & HAS_RELOC)
+                  ? 0
+                  : (ztih
+                     ? abdp->default_text_vma + adata (abfd).exec_bytes_size
+                     : abdp->default_text_vma));
       text_pad = 0;
     }
   else
     {
       /* The .text section is being loaded at an unusual address.  We
-         may need to pad it such that the .data section starts at a page
-         boundary.  */
+        may need to pad it such that the .data section starts at a page
+        boundary.  */
       if (ztih)
-       text_pad = ((obj_textsec (abfd)->filepos - obj_textsec (abfd)->vma)
+       text_pad = ((text->filepos - text->vma)
                    & (adata (abfd).page_size - 1));
       else
-       text_pad = ((- obj_textsec (abfd)->vma)
+       text_pad = (-text->vma
                    & (adata (abfd).page_size - 1));
     }
 
   /* Find start of data.  */
   if (ztih)
     {
-      text_end = obj_textsec (abfd)->filepos + obj_textsec (abfd)->size;
+      text_end = text->filepos + execp->a_text;
       text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
     }
   else
@@ -973,55 +1010,45 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp)
       /* Note that if page_size == zmagic_disk_block_size, then
         filepos == page_size, and this case is the same as the ztih
         case.  */
-      text_end = obj_textsec (abfd)->size;
+      text_end = execp->a_text;
       text_pad += BFD_ALIGN (text_end, adata (abfd).page_size) - text_end;
-      text_end += obj_textsec (abfd)->filepos;
+      text_end += text->filepos;
     }
-  obj_textsec (abfd)->size += text_pad;
-  text_end += text_pad;
+  execp->a_text += text_pad;
 
   /* Data.  */
-  if (!obj_datasec (abfd)->user_set_vma)
+  if (!data->user_set_vma)
     {
       bfd_vma vma;
-      vma = obj_textsec (abfd)->vma + obj_textsec (abfd)->size;
-      obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
+      vma = text->vma + execp->a_text;
+      data->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
     }
   if (abdp && abdp->zmagic_mapped_contiguous)
     {
-      asection * text = obj_textsec (abfd);
-      asection * data = obj_datasec (abfd);
-
-      text_pad = data->vma - (text->vma + text->size);
+      text_pad = data->vma - (text->vma + execp->a_text);
       /* Only pad the text section if the data
         section is going to be placed after it.  */
       if (text_pad > 0)
-       text->size += text_pad;
+       execp->a_text += text_pad;
     }
-  obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
-                                + obj_textsec (abfd)->size);
+  data->filepos = text->filepos + execp->a_text;
 
   /* Fix up exec header while we're at it.  */
-  execp->a_text = obj_textsec (abfd)->size;
   if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
     execp->a_text += adata (abfd).exec_bytes_size;
   if (obj_aout_subformat (abfd) == q_magic_format)
-    N_SET_MAGIC (*execp, QMAGIC);
+    N_SET_QMAGIC (execp);
   else
-    N_SET_MAGIC (*execp, ZMAGIC);
+    N_SET_MAGIC (execp, ZMAGIC);
 
   /* Spec says data section should be rounded up to page boundary.  */
-  obj_datasec (abfd)->size
-    = align_power (obj_datasec (abfd)->size,
-                  obj_bsssec (abfd)->alignment_power);
-  execp->a_data = BFD_ALIGN (obj_datasec (abfd)->size,
-                            adata (abfd).page_size);
-  data_pad = execp->a_data - obj_datasec (abfd)->size;
+  execp->a_data = align_power (data->size, bss->alignment_power);
+  execp->a_data = BFD_ALIGN (execp->a_data, adata (abfd).page_size);
+  data_pad = execp->a_data - data->size;
 
   /* BSS.  */
-  if (!obj_bsssec (abfd)->user_set_vma)
-    obj_bsssec (abfd)->vma = (obj_datasec (abfd)->vma
-                             + obj_datasec (abfd)->size);
+  if (!bss->user_set_vma)
+    bss->vma = data->vma + execp->a_data;
   /* If the BSS immediately follows the data section and extra space
      in the page is left after the data section, fudge data
      in the header so that the bss section looks smaller by that
@@ -1029,12 +1056,10 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp)
      (Note that a linker script, as well as the above assignment,
      could have explicitly set the BSS vma to immediately follow
      the data section.)  */
-  if (align_power (obj_bsssec (abfd)->vma, obj_bsssec (abfd)->alignment_power)
-      == obj_datasec (abfd)->vma + obj_datasec (abfd)->size)
-    execp->a_bss = (data_pad > obj_bsssec (abfd)->size
-                   ? 0 : obj_bsssec (abfd)->size - data_pad);
+  if (align_power (bss->vma, bss->alignment_power) == data->vma + execp->a_data)
+    execp->a_bss = data_pad > bss->size ? 0 : bss->size - data_pad;
   else
-    execp->a_bss = obj_bsssec (abfd)->size;
+    execp->a_bss = bss->size;
 }
 
 static void
@@ -1043,45 +1068,44 @@ adjust_n_magic (bfd *abfd, struct internal_exec *execp)
   file_ptr pos = adata (abfd).exec_bytes_size;
   bfd_vma vma = 0;
   int pad;
+  asection *text = obj_textsec (abfd);
+  asection *data = obj_datasec (abfd);
+  asection *bss = obj_bsssec (abfd);
 
   /* Text.  */
-  obj_textsec (abfd)->filepos = pos;
-  if (!obj_textsec (abfd)->user_set_vma)
-    obj_textsec (abfd)->vma = vma;
+  text->filepos = pos;
+  if (!text->user_set_vma)
+    text->vma = vma;
   else
-    vma = obj_textsec (abfd)->vma;
-  pos += obj_textsec (abfd)->size;
-  vma += obj_textsec (abfd)->size;
+    vma = text->vma;
+  pos += execp->a_text;
+  vma += execp->a_text;
 
   /* Data.  */
-  obj_datasec (abfd)->filepos = pos;
-  if (!obj_datasec (abfd)->user_set_vma)
-    obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
-  vma = obj_datasec (abfd)->vma;
+  data->filepos = pos;
+  if (!data->user_set_vma)
+    data->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
+  vma = data->vma;
 
   /* Since BSS follows data immediately, see if it needs alignment.  */
-  vma += obj_datasec (abfd)->size;
-  pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
-  obj_datasec (abfd)->size += pad;
-  pos += obj_datasec (abfd)->size;
+  vma += data->size;
+  pad = align_power (vma, bss->alignment_power) - vma;
+  execp->a_data = data->size + pad;
+  pos += execp->a_data;
 
   /* BSS.  */
-  if (!obj_bsssec (abfd)->user_set_vma)
-    obj_bsssec (abfd)->vma = vma;
+  if (!bss->user_set_vma)
+    bss->vma = vma;
   else
-    vma = obj_bsssec (abfd)->vma;
+    vma = bss->vma;
 
   /* Fix up exec header.  */
-  execp->a_text = obj_textsec (abfd)->size;
-  execp->a_data = obj_datasec (abfd)->size;
-  execp->a_bss = obj_bsssec (abfd)->size;
-  N_SET_MAGIC (*execp, NMAGIC);
+  execp->a_bss = bss->size;
+  N_SET_MAGIC (execp, NMAGIC);
 }
 
 bfd_boolean
-NAME (aout, adjust_sizes_and_vmas) (bfd *abfd,
-                                   bfd_size_type *text_size,
-                                   file_ptr *text_end ATTRIBUTE_UNUSED)
+NAME (aout, adjust_sizes_and_vmas) (bfd *abfd)
 {
   struct internal_exec *execp = exec_hdr (abfd);
 
@@ -1091,11 +1115,9 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd,
   if (adata (abfd).magic != undecided_magic)
     return TRUE;
 
-  obj_textsec (abfd)->size =
-    align_power (obj_textsec (abfd)->size,
-                obj_textsec (abfd)->alignment_power);
+  execp->a_text = align_power (obj_textsec (abfd)->size,
+                              obj_textsec (abfd)->alignment_power);
 
-  *text_size = obj_textsec (abfd)->size;
   /* Rule (heuristic) for when to pad to a new page.  Note that there
      are (at least) two ways demand-paged (ZMAGIC) files have been
      handled.  Most Berkeley-based systems start the text segment at
@@ -1134,11 +1156,11 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd,
              str;
            }),
           obj_textsec (abfd)->vma, obj_textsec (abfd)->size,
-               obj_textsec (abfd)->alignment_power,
+               obj_textsec (abfd)->alignment_power,
           obj_datasec (abfd)->vma, obj_datasec (abfd)->size,
-               obj_datasec (abfd)->alignment_power,
+               obj_datasec (abfd)->alignment_power,
           obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size,
-               obj_bsssec (abfd)->alignment_power);
+               obj_bsssec (abfd)->alignment_power);
 #endif
 #endif
 
@@ -1159,11 +1181,11 @@ NAME (aout, adjust_sizes_and_vmas) (bfd *abfd,
 
 #ifdef BFD_AOUT_DEBUG
   fprintf (stderr, "       text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",
-          obj_textsec (abfd)->vma, obj_textsec (abfd)->size,
-               obj_textsec (abfd)->filepos,
-          obj_datasec (abfd)->vma, obj_datasec (abfd)->size,
-               obj_datasec (abfd)->filepos,
-          obj_bsssec (abfd)->vma, obj_bsssec (abfd)->size);
+          obj_textsec (abfd)->vma, execp->a_text,
+               obj_textsec (abfd)->filepos,
+          obj_datasec (abfd)->vma, execp->a_data,
+               obj_datasec (abfd)->filepos,
+          obj_bsssec (abfd)->vma, execp->a_bss);
 #endif
 
   return TRUE;
@@ -1174,7 +1196,7 @@ FUNCTION
        aout_@var{size}_new_section_hook
 
 SYNOPSIS
-        bfd_boolean aout_@var{size}_new_section_hook,
+       bfd_boolean aout_@var{size}_new_section_hook,
           (bfd *abfd,
            asection *newsect);
 
@@ -1194,26 +1216,21 @@ NAME (aout, new_section_hook) (bfd *abfd, asection *newsect)
        {
          obj_textsec (abfd)= newsect;
          newsect->target_index = N_TEXT;
-         return TRUE;
        }
-
-      if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
+      else if (obj_datasec (abfd) == NULL && !strcmp (newsect->name, ".data"))
        {
          obj_datasec (abfd) = newsect;
          newsect->target_index = N_DATA;
-         return TRUE;
        }
-
-      if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
+      else if (obj_bsssec (abfd) == NULL && !strcmp (newsect->name, ".bss"))
        {
          obj_bsssec (abfd) = newsect;
          newsect->target_index = N_BSS;
-         return TRUE;
        }
     }
 
   /* We allow more than three sections internally.  */
-  return TRUE;
+  return _bfd_generic_new_section_hook (abfd, newsect);
 }
 
 bfd_boolean
@@ -1223,12 +1240,9 @@ NAME (aout, set_section_contents) (bfd *abfd,
                                   file_ptr offset,
                                   bfd_size_type count)
 {
-  file_ptr text_end;
-  bfd_size_type text_size;
-
   if (! abfd->output_has_begun)
     {
-      if (! NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
+      if (! NAME (aout, adjust_sizes_and_vmas) (abfd))
        return FALSE;
     }
 
@@ -1246,11 +1260,12 @@ NAME (aout, set_section_contents) (bfd *abfd,
                           (section->vma - obj_textsec (abfd)->vma);
       else
        {
-          (*_bfd_error_handler)
-          (_("%s: can not represent section `%s' in a.out object file format"),
-            bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
-          bfd_set_error (bfd_error_nonrepresentable_section);
-          return FALSE;
+         _bfd_error_handler
+           /* xgettext:c-format */
+          (_("%pB: can not represent section `%pA' in a.out object file format"),
+            abfd, section);
+         bfd_set_error (bfd_error_nonrepresentable_section);
+         return FALSE;
        }
     }
 
@@ -1273,13 +1288,14 @@ aout_get_external_symbols (bfd *abfd)
     {
       bfd_size_type count;
       struct external_nlist *syms;
-      bfd_size_type amt;
+      bfd_size_type amt = exec_hdr (abfd)->a_syms;
 
-      count = exec_hdr (abfd)->a_syms / EXTERNAL_NLIST_SIZE;
+      count = amt / EXTERNAL_NLIST_SIZE;
+      if (count == 0)
+       return TRUE;            /* Nothing to do.  */
 
 #ifdef USE_MMAP
-      if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd),
-                                exec_hdr (abfd)->a_syms,
+      if (! bfd_get_file_window (abfd, obj_sym_filepos (abfd), amt,
                                 &obj_aout_sym_window (abfd), TRUE))
        return FALSE;
       syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
@@ -1287,17 +1303,11 @@ aout_get_external_symbols (bfd *abfd)
       /* We allocate using malloc to make the values easy to free
         later on.  If we put them on the objalloc it might not be
         possible to free them.  */
-      syms = bfd_malloc (count * EXTERNAL_NLIST_SIZE);
-      if (syms == NULL && count != 0)
+      if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0)
+       return FALSE;
+      syms = (struct external_nlist *) _bfd_malloc_and_read (abfd, amt, amt);
+      if (syms == NULL)
        return FALSE;
-
-      amt = exec_hdr (abfd)->a_syms;
-      if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
-         || bfd_bread (syms, amt, abfd) != amt)
-       {
-         free (syms);
-         return FALSE;
-       }
 #endif
 
       obj_aout_external_syms (abfd) = syms;
@@ -1317,31 +1327,47 @@ aout_get_external_symbols (bfd *abfd)
          || bfd_bread ((void *) string_chars, amt, abfd) != amt)
        return FALSE;
       stringsize = GET_WORD (abfd, string_chars);
+      if (stringsize == 0)
+       stringsize = 1;
+      else if (stringsize < BYTES_IN_WORD
+              || (size_t) stringsize != stringsize)
+       {
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
 #ifdef USE_MMAP
-      if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
-                                &obj_aout_string_window (abfd), TRUE))
-       return FALSE;
-      strings = (char *) obj_aout_string_window (abfd).data;
-#else
-      strings = bfd_malloc (stringsize + 1);
-      if (strings == NULL)
-       return FALSE;
-
-      /* Skip space for the string count in the buffer for convenience
-        when using indexes.  */
-      amt = stringsize - BYTES_IN_WORD;
-      if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
+      if (stringsize >= BYTES_IN_WORD)
        {
-         free (strings);
-         return FALSE;
+         if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize + 1,
+                                    &obj_aout_string_window (abfd), TRUE))
+           return FALSE;
+         strings = (char *) obj_aout_string_window (abfd).data;
        }
+      else
 #endif
+       {
+         strings = (char *) bfd_malloc (stringsize + 1);
+         if (strings == NULL)
+           return FALSE;
 
+         if (stringsize >= BYTES_IN_WORD)
+           {
+             /* Keep the string count in the buffer for convenience
+                when indexing with e_strx.  */
+             amt = stringsize - BYTES_IN_WORD;
+             if (bfd_bread (strings + BYTES_IN_WORD, amt, abfd) != amt)
+               {
+                 free (strings);
+                 return FALSE;
+               }
+           }
+       }
       /* Ensure that a zero index yields an empty string.  */
       strings[0] = '\0';
 
-      strings[stringsize - 1] = 0;
+      /* Ensure that the string buffer is NUL terminated.  */
+      strings[stringsize] = 0;
 
       obj_aout_external_strings (abfd) = strings;
       obj_aout_external_string_size (abfd) = stringsize;
@@ -1453,8 +1479,8 @@ translate_from_native_sym_flags (bfd *abfd, aout_symbol_type *cache_ptr)
     case N_SETB: case N_SETB | N_EXT:
       {
        /* This code is no longer needed.  It used to be used to make
-           the linker handle set symbols, but they are now handled in
-           the add_symbols routine instead.  */
+          the linker handle set symbols, but they are now handled in
+          the add_symbols routine instead.  */
        switch (cache_ptr->type & N_TYPE)
          {
          case N_SETA:
@@ -1539,16 +1565,18 @@ translate_to_native_sym_flags (bfd *abfd,
      to another.  */
   sym_pointer->e_type[0] &= ~N_TYPE;
 
-  sec = bfd_get_section (cache_ptr);
+  sec = bfd_asymbol_section (cache_ptr);
   off = 0;
 
   if (sec == NULL)
     {
       /* This case occurs, e.g., for the *DEBUG* section of a COFF
         file.  */
-      (*_bfd_error_handler)
-       (_("%s: can not represent section for symbol `%s' in a.out object file format"),
-        bfd_get_filename (abfd),
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%pB: can not represent section for symbol `%s' in a.out "
+          "object file format"),
+        abfd,
         cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return FALSE;
@@ -1580,11 +1608,12 @@ translate_to_native_sym_flags (bfd *abfd,
        sym_pointer->e_type[0] |= N_TEXT;
       else
        {
-          (*_bfd_error_handler)
-          (_("%s: can not represent section `%s' in a.out object file format"),
-            bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
-          bfd_set_error (bfd_error_nonrepresentable_section);
-          return FALSE;
+         _bfd_error_handler
+           /* xgettext:c-format */
+          (_("%pB: can not represent section `%pA' in a.out object file format"),
+            abfd, sec);
+         bfd_set_error (bfd_error_nonrepresentable_section);
+         return FALSE;
        }
     }
 
@@ -1641,14 +1670,14 @@ translate_to_native_sym_flags (bfd *abfd,
 asymbol *
 NAME (aout, make_empty_symbol) (bfd *abfd)
 {
-  bfd_size_type amt = sizeof (aout_symbol_type);
+  size_t amt = sizeof (aout_symbol_type);
 
-  aout_symbol_type *new = bfd_zalloc (abfd, amt);
-  if (!new)
+  aout_symbol_type *new_symbol = (aout_symbol_type *) bfd_zalloc (abfd, amt);
+  if (!new_symbol)
     return NULL;
-  new->symbol.the_bfd = abfd;
+  new_symbol->symbol.the_bfd = abfd;
 
-  return &new->symbol;
+  return &new_symbol->symbol;
 }
 
 /* Translate a set of internal symbols into external symbols.  */
@@ -1682,7 +1711,13 @@ NAME (aout, translate_symbol_table) (bfd *abfd,
       else if (x < strsize)
        in->symbol.name = str + x;
       else
-       return FALSE;
+       {
+         _bfd_error_handler
+           (_("%pB: invalid string offset %" PRIu64 " >= %" PRIu64),
+            abfd, (uint64_t) x, (uint64_t) strsize);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
       in->symbol.value = GET_SWORD (abfd,  ext->e_value);
       in->desc = H_GET_16 (abfd, ext->e_desc);
@@ -1721,9 +1756,12 @@ NAME (aout, slurp_symbol_table) (bfd *abfd)
     return FALSE;
 
   cached_size = obj_aout_external_sym_count (abfd);
+  if (cached_size == 0)
+    return TRUE;               /* Nothing to do.  */
+
   cached_size *= sizeof (aout_symbol_type);
-  cached = bfd_zmalloc (cached_size);
-  if (cached == NULL && cached_size != 0)
+  cached = (aout_symbol_type *) bfd_zmalloc (cached_size);
+  if (cached == NULL)
     return FALSE;
 
   /* Convert from external symbol information to internal.  */
@@ -1739,7 +1777,7 @@ NAME (aout, slurp_symbol_table) (bfd *abfd)
       return FALSE;
     }
 
-  bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
+  abfd->symcount = obj_aout_external_sym_count (abfd);
 
   obj_aout_symbols (abfd) = cached;
 
@@ -1780,7 +1818,7 @@ add_to_stringtab (bfd *abfd,
                  bfd_boolean copy)
 {
   bfd_boolean hash;
-  bfd_size_type index;
+  bfd_size_type str_index;
 
   /* An index of 0 always means the empty string.  */
   if (str == 0 || *str == '\0')
@@ -1792,14 +1830,14 @@ add_to_stringtab (bfd *abfd,
   if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
     hash = FALSE;
 
-  index = _bfd_stringtab_add (tab, str, hash, copy);
+  str_index = _bfd_stringtab_add (tab, str, hash, copy);
 
-  if (index != (bfd_size_type) -1)
+  if (str_index != (bfd_size_type) -1)
     /* Add BYTES_IN_WORD to the return value to account for the
        space taken up by the string table size.  */
-    index += BYTES_IN_WORD;
+    str_index += BYTES_IN_WORD;
 
-  return index;
+  return str_index;
 }
 
 /* Write out a strtab.  ABFD is already at the right location in the
@@ -1809,7 +1847,7 @@ static bfd_boolean
 emit_stringtab (bfd *abfd, struct bfd_strtab_hash *tab)
 {
   bfd_byte buffer[BYTES_IN_WORD];
-  bfd_size_type amt = BYTES_IN_WORD;
+  size_t amt = BYTES_IN_WORD;
 
   /* The string table starts with the size.  */
   PUT_WORD (abfd, _bfd_stringtab_size (tab) + BYTES_IN_WORD, buffer);
@@ -1835,7 +1873,7 @@ NAME (aout, write_syms) (bfd *abfd)
       asymbol *g = generic[count];
       bfd_size_type indx;
       struct external_nlist nsp;
-      bfd_size_type amt;
+      size_t amt;
 
       indx = add_to_stringtab (abfd, strtab, g->name, FALSE);
       if (indx == (bfd_size_type) -1)
@@ -1874,7 +1912,7 @@ NAME (aout, write_syms) (bfd *abfd)
 
   return TRUE;
 
-error_return:
+ error_return:
   _bfd_stringtab_free (strtab);
   return FALSE;
 }
@@ -1917,7 +1955,25 @@ NAME (aout, swap_std_reloc_out) (bfd *abfd,
 
   PUT_WORD (abfd, g->address, natptr->r_address);
 
-  r_length = g->howto->size ;  /* Size as a power of two.  */
+  BFD_ASSERT (g->howto != NULL);
+
+  switch (bfd_get_reloc_size (g->howto))
+    {
+    default:
+      _bfd_error_handler (_("%pB: unsupported AOUT relocation size: %d"),
+                         abfd, bfd_get_reloc_size (g->howto));
+      bfd_set_error (bfd_error_bad_value);
+      return;
+    case 1:
+    case 2:
+    case 4:
+      r_length = g->howto->size;       /* Size as a power of two.  */
+      break;
+    case 8:
+      r_length = 3;
+      break;
+    }
+
   r_pcrel  = (int) g->howto->pc_relative; /* Relative to PC?  */
   /* XXX This relies on relocs coming from a.out files.  */
   r_baserel = (g->howto->type & 8) != 0;
@@ -1935,7 +1991,10 @@ NAME (aout, swap_std_reloc_out) (bfd *abfd,
 
   if (bfd_is_com_section (output_section)
       || bfd_is_abs_section (output_section)
-      || bfd_is_und_section (output_section))
+      || bfd_is_und_section (output_section)
+      /* PR gas/3041  a.out relocs against weak symbols
+        must be treated as if they were against externs.  */
+      || (sym->flags & BSF_WEAK))
     {
       if (bfd_abs_section_ptr->symbol == sym)
        {
@@ -2017,14 +2076,14 @@ NAME (aout, swap_ext_reloc_out) (bfd *abfd,
      Absolute symbols can come in in two ways, either as an offset
      from the abs section, or as a symbol which has an abs value.
      check for that here.  */
-  if (bfd_is_abs_section (bfd_get_section (sym)))
+  if (bfd_is_abs_section (bfd_asymbol_section (sym)))
     {
       r_extern = 0;
       r_index = N_ABS;
     }
   else if ((sym->flags & BSF_SECTION_SYM) == 0)
     {
-      if (bfd_is_und_section (bfd_get_section (sym))
+      if (bfd_is_und_section (bfd_asymbol_section (sym))
          || (sym->flags & BSF_GLOBAL) != 0)
        r_extern = 1;
       else
@@ -2138,7 +2197,10 @@ NAME (aout, swap_ext_reloc_in) (bfd *abfd,
                >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
     }
 
-  cache_ptr->howto =  howto_table_ext + r_type;
+  if (r_type < TABLE_SIZE (howto_table_ext))
+    cache_ptr->howto = howto_table_ext + r_type;
+  else
+    cache_ptr->howto = NULL;
 
   /* Base relative relocs are always against the symbol table,
      regardless of the setting of r_extern.  r_extern just reflects
@@ -2151,7 +2213,7 @@ NAME (aout, swap_ext_reloc_in) (bfd *abfd,
   if (r_extern && r_index > symcount)
     {
       /* We could arrange to return an error, but it might be useful
-         to see the file even if it is bad.  */
+        to see the file even if it is bad.  */
       r_extern = 0;
       r_index = N_ABS;
     }
@@ -2206,9 +2268,14 @@ NAME (aout, swap_std_reloc_in) (bfd *abfd,
 
   howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
               + 16 * r_jmptable + 32 * r_relative);
-  BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
-  cache_ptr->howto =  howto_table_std + howto_idx;
-  BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1);
+  if (howto_idx < TABLE_SIZE (howto_table_std))
+    {
+      cache_ptr->howto = howto_table_std + howto_idx;
+      if (cache_ptr->howto->type == (unsigned int) -1)
+       cache_ptr->howto = NULL;
+    }
+  else
+    cache_ptr->howto = NULL;
 
   /* Base relative relocs are always against the symbol table,
      regardless of the setting of r_extern.  r_extern just reflects
@@ -2216,10 +2283,12 @@ NAME (aout, swap_std_reloc_in) (bfd *abfd,
   if (r_baserel)
     r_extern = 1;
 
-  if (r_extern && r_index > symcount)
+  if (r_extern && r_index >= symcount)
     {
       /* We could arrange to return an error, but it might be useful
-         to see the file even if it is bad.  */
+        to see the file even if it is bad.  FIXME: Of course this
+        means that objdump -r *doesn't* see the actual reloc, and
+        objcopy silently writes a different reloc.  */
       r_extern = 0;
       r_index = N_ABS;
     }
@@ -2259,29 +2328,22 @@ NAME (aout, slurp_reloc_table) (bfd *abfd, sec_ptr asect, asymbol **symbols)
       return FALSE;
     }
 
-  if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
-    return FALSE;
-
   each_size = obj_reloc_entry_size (abfd);
-
   count = reloc_size / each_size;
+  if (count == 0)
+    return TRUE;               /* Nothing to be done.  */
 
-  amt = count * sizeof (arelent);
-  reloc_cache = bfd_zmalloc (amt);
-  if (reloc_cache == NULL && count != 0)
+  if (bfd_seek (abfd, asect->rel_filepos, SEEK_SET) != 0)
+    return FALSE;
+  relocs = _bfd_malloc_and_read (abfd, reloc_size, reloc_size);
+  if (relocs == NULL)
     return FALSE;
 
-  relocs = bfd_malloc (reloc_size);
-  if (relocs == NULL && reloc_size != 0)
-    {
-      free (reloc_cache);
-      return FALSE;
-    }
-
-  if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
+  amt = count * sizeof (arelent);
+  reloc_cache = (arelent *) bfd_zmalloc (amt);
+  if (reloc_cache == NULL)
     {
       free (relocs);
-      free (reloc_cache);
       return FALSE;
     }
 
@@ -2328,7 +2390,7 @@ NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section)
 
   each_size = obj_reloc_entry_size (abfd);
   natsize = (bfd_size_type) each_size * count;
-  native = bfd_zalloc (abfd, natsize);
+  native = (unsigned char *) bfd_zalloc (abfd, natsize);
   if (!native)
     return FALSE;
 
@@ -2339,16 +2401,39 @@ NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section)
       for (natptr = native;
           count != 0;
           --count, natptr += each_size, ++generic)
-       MY_swap_ext_reloc_out (abfd, *generic,
-                              (struct reloc_ext_external *) natptr);
+       {
+         /* PR 20921: If the howto field has not been initialised then skip
+            this reloc.
+            PR 20929: Similarly for the symbol field.  */
+         if ((*generic)->howto == NULL
+             || (*generic)->sym_ptr_ptr == NULL)
+           {
+             bfd_set_error (bfd_error_invalid_operation);
+             _bfd_error_handler (_("%pB: attempt to write out "
+                                   "unknown reloc type"), abfd);
+             return FALSE;
+           }
+         MY_swap_ext_reloc_out (abfd, *generic,
+                                (struct reloc_ext_external *) natptr);
+       }
     }
   else
     {
       for (natptr = native;
           count != 0;
           --count, natptr += each_size, ++generic)
-       MY_swap_std_reloc_out (abfd, *generic,
-                              (struct reloc_std_external *) natptr);
+       {
+         if ((*generic)->howto == NULL
+             || (*generic)->sym_ptr_ptr == NULL)
+           {
+             bfd_set_error (bfd_error_invalid_operation);
+             _bfd_error_handler (_("%pB: attempt to write out "
+                                   "unknown reloc type"), abfd);
+             return FALSE;
+           }
+         MY_swap_std_reloc_out (abfd, *generic,
+                                (struct reloc_std_external *) natptr);
+       }
     }
 
   if (bfd_bwrite ((void *) native, natsize, abfd) != natsize)
@@ -2407,6 +2492,8 @@ NAME (aout, canonicalize_reloc) (bfd *abfd,
 long
 NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
 {
+  bfd_size_type count;
+
   if (bfd_get_format (abfd) != bfd_object)
     {
       bfd_set_error (bfd_error_invalid_operation);
@@ -2414,26 +2501,25 @@ NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
     }
 
   if (asect->flags & SEC_CONSTRUCTOR)
-    return sizeof (arelent *) * (asect->reloc_count + 1);
-
-  if (asect == obj_datasec (abfd))
-    return sizeof (arelent *)
-      * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
-        + 1);
-
-  if (asect == obj_textsec (abfd))
-    return sizeof (arelent *)
-      * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
-        + 1);
-
-  if (asect == obj_bsssec (abfd))
-    return sizeof (arelent *);
-
-  if (asect == obj_bsssec (abfd))
-    return 0;
+    count = asect->reloc_count;
+  else if (asect == obj_datasec (abfd))
+    count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
+  else if (asect == obj_textsec (abfd))
+    count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
+  else if (asect == obj_bsssec (abfd))
+    count = 0;
+  else
+    {
+      bfd_set_error (bfd_error_invalid_operation);
+      return -1;
+    }
 
-  bfd_set_error (bfd_error_invalid_operation);
-  return -1;
+  if (count >= LONG_MAX / sizeof (arelent *))
+    {
+      bfd_set_error (bfd_error_file_too_big);
+      return -1;
+    }
+  return (count + 1) * sizeof (arelent *);
 }
 \f
 long
@@ -2590,12 +2676,13 @@ NAME (aout, minisymbol_to_symbol) (bfd *abfd,
 
 bfd_boolean
 NAME (aout, find_nearest_line) (bfd *abfd,
-                               asection *section,
                                asymbol **symbols,
+                               asection *section,
                                bfd_vma offset,
                                const char **filename_ptr,
                                const char **functionname_ptr,
-                               unsigned int *line_ptr)
+                               unsigned int *line_ptr,
+                               unsigned int *disriminator_ptr)
 {
   /* Run down the file looking for the filename, function and linenumber.  */
   asymbol **p;
@@ -2610,9 +2697,11 @@ NAME (aout, find_nearest_line) (bfd *abfd,
   bfd_size_type filelen, funclen;
   char *buf;
 
-  *filename_ptr = abfd->filename;
-  *functionname_ptr = 0;
+  *filename_ptr = bfd_get_filename (abfd);
+  *functionname_ptr = NULL;
   *line_ptr = 0;
+  if (disriminator_ptr)
+    *disriminator_ptr = 0;
 
   if (symbols != NULL)
     {
@@ -2637,7 +2726,10 @@ NAME (aout, find_nearest_line) (bfd *abfd,
                  const char *symname;
 
                  symname = q->symbol.name;
-                 if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
+
+                 if (symname != NULL
+                     && strlen (symname) > 2
+                     && strcmp (symname + strlen (symname) - 2, ".o") == 0)
                    {
                      if (q->symbol.value > low_line_vma)
                        {
@@ -2702,8 +2794,8 @@ NAME (aout, find_nearest_line) (bfd *abfd,
            case N_FUN:
              {
                /* We'll keep this if it is nearer than the one we have already.  */
-               if (q->symbol.value >= low_func_vma &&
-                   q->symbol.value <= offset)
+               if (q->symbol.value >= low_func_vma
+                   && q->symbol.value <= offset)
                  {
                    low_func_vma = q->symbol.value;
                    func = (asymbol *)q;
@@ -2735,14 +2827,13 @@ NAME (aout, find_nearest_line) (bfd *abfd,
   else
     funclen = strlen (bfd_asymbol_name (func));
 
-  if (adata (abfd).line_buf != NULL)
-    free (adata (abfd).line_buf);
+  free (adata (abfd).line_buf);
 
   if (filelen + funclen == 0)
     adata (abfd).line_buf = buf = NULL;
   else
     {
-      buf = bfd_malloc (filelen + funclen + 3);
+      buf = (char *) bfd_malloc (filelen + funclen + 3);
       adata (abfd).line_buf = buf;
       if (buf == NULL)
        return FALSE;
@@ -2754,9 +2845,17 @@ NAME (aout, find_nearest_line) (bfd *abfd,
        *filename_ptr = main_file_name;
       else
        {
-         sprintf (buf, "%s%s", directory_name, main_file_name);
-         *filename_ptr = buf;
-         buf += filelen + 1;
+         if (buf == NULL)
+           /* PR binutils/20891: In a corrupt input file both
+              main_file_name and directory_name can be empty...  */
+           * filename_ptr = NULL;
+         else
+           {
+             snprintf (buf, filelen + 1, "%s%s", directory_name,
+                       main_file_name);
+             *filename_ptr = buf;
+             buf += filelen + 1;
+           }
        }
     }
 
@@ -2765,6 +2864,12 @@ NAME (aout, find_nearest_line) (bfd *abfd,
       const char *function = func->name;
       char *colon;
 
+      if (buf == NULL)
+       {
+         /* PR binutils/20892: In a corrupt input file func can be empty.  */
+         * functionname_ptr = NULL;
+         return TRUE;
+       }
       /* The caller expects a symbol name.  We actually have a
         function name, without the leading underscore.  Put the
         underscore back in, so that the caller gets a symbol name.  */
@@ -2786,7 +2891,8 @@ NAME (aout, find_nearest_line) (bfd *abfd,
 }
 
 int
-NAME (aout, sizeof_headers) (bfd *abfd, bfd_boolean execable ATTRIBUTE_UNUSED)
+NAME (aout, sizeof_headers) (bfd *abfd,
+                            struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   return adata (abfd).exec_bytes_size;
 }
@@ -2803,7 +2909,7 @@ NAME (aout, bfd_free_cached_info) (bfd *abfd)
       || abfd->tdata.aout_data == NULL)
     return TRUE;
 
-#define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
+#define BFCI_FREE(x) do { free (x); x = NULL; } while (0)
   BFCI_FREE (obj_aout_symbols (abfd));
 #ifdef USE_MMAP
   obj_aout_external_syms (abfd) = 0;
@@ -2835,7 +2941,8 @@ NAME (aout, link_hash_newfunc) (struct bfd_hash_entry *entry,
   /* Allocate the structure if it has not already been allocated by a
      subclass.  */
   if (ret == NULL)
-    ret = bfd_hash_allocate (table, sizeof (* ret));
+    ret = (struct aout_link_hash_entry *) bfd_hash_allocate (table,
+                                                            sizeof (* ret));
   if (ret == NULL)
     return NULL;
 
@@ -2860,9 +2967,10 @@ NAME (aout, link_hash_table_init) (struct aout_link_hash_table *table,
                                   bfd *abfd,
                                   struct bfd_hash_entry *(*newfunc)
                                   (struct bfd_hash_entry *, struct bfd_hash_table *,
-                                   const char *))
+                                   const char *),
+                                  unsigned int entsize)
 {
-  return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
+  return _bfd_link_hash_table_init (&table->root, abfd, newfunc, entsize);
 }
 
 /* Create an a.out link hash table.  */
@@ -2871,14 +2979,15 @@ struct bfd_link_hash_table *
 NAME (aout, link_hash_table_create) (bfd *abfd)
 {
   struct aout_link_hash_table *ret;
-  bfd_size_type amt = sizeof (* ret);
+  size_t amt = sizeof (* ret);
 
-  ret = bfd_malloc (amt);
+  ret = (struct aout_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
 
-  if (! NAME (aout, link_hash_table_init) (ret, abfd,
-                                          NAME (aout, link_hash_newfunc)))
+  if (!NAME (aout, link_hash_table_init) (ret, abfd,
+                                         NAME (aout, link_hash_newfunc),
+                                         sizeof (struct aout_link_hash_entry)))
     {
       free (ret);
       return NULL;
@@ -2919,13 +3028,16 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        return FALSE;
     }
 
+  if (sym_count == 0)
+    return TRUE;               /* Nothing to do.  */
+
   /* We keep a list of the linker hash table entries that correspond
      to particular symbols.  We could just look them up in the hash
      table, but keeping the list is more efficient.  Perhaps this
      should be conditional on info->keep_memory.  */
   amt = sym_count * sizeof (struct aout_link_hash_entry *);
-  sym_hash = bfd_alloc (abfd, amt);
-  if (sym_hash == NULL && sym_count != 0)
+  sym_hash = (struct aout_link_hash_entry **) bfd_alloc (abfd, amt);
+  if (sym_hash == NULL)
     return FALSE;
   obj_aout_sym_hashes (abfd) = sym_hash;
 
@@ -2952,6 +3064,9 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
       if ((type & N_STAB) != 0)
        continue;
 
+      /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
+      if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
+       return FALSE;
       name = strings + GET_WORD (abfd, p->e_strx);
       value = GET_WORD (abfd, p->e_value);
       flags = BSF_GLOBAL;
@@ -2992,24 +3107,29 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          break;
        case N_TEXT | N_EXT:
          section = obj_textsec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_DATA | N_EXT:
        case N_SETV | N_EXT:
          /* Treat N_SETV symbols as N_DATA symbol; see comment in
             translate_from_native_sym_flags.  */
          section = obj_datasec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_BSS | N_EXT:
          section = obj_bsssec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_INDR | N_EXT:
          /* An indirect symbol.  The next symbol is the symbol
             which this one really is.  */
-         BFD_ASSERT (p + 1 < pend);
+         /* See PR 20925 for a reproducer.  */
+         if (p + 1 >= pend)
+           return FALSE;
          ++p;
+         /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
+         if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
+           return FALSE;
          string = strings + GET_WORD (abfd, p->e_strx);
          section = bfd_ind_section_ptr;
          flags |= BSF_INDIRECT;
@@ -3024,17 +3144,17 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        case N_SETT: case N_SETT | N_EXT:
          section = obj_textsec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_SETD: case N_SETD | N_EXT:
          section = obj_datasec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_SETB: case N_SETB | N_EXT:
          section = obj_bsssec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_WARNING:
          /* A warning symbol.  The next symbol is the one to warn
@@ -3043,6 +3163,9 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
            return TRUE;
          ++p;
          string = name;
+         /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
+         if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
+           return FALSE;
          name = strings + GET_WORD (abfd, p->e_strx);
          section = bfd_und_section_ptr;
          flags |= BSF_WARNING;
@@ -3057,17 +3180,17 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          break;
        case N_WEAKT:
          section = obj_textsec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        case N_WEAKD:
          section = obj_datasec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        case N_WEAKB:
          section = obj_bsssec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        }
@@ -3157,7 +3280,8 @@ aout_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 static bfd_boolean
 aout_link_check_ar_symbols (bfd *abfd,
                            struct bfd_link_info *info,
-                           bfd_boolean *pneeded)
+                           bfd_boolean *pneeded,
+                           bfd **subsbfd)
 {
   struct external_nlist *p;
   struct external_nlist *pend;
@@ -3216,13 +3340,13 @@ aout_link_check_ar_symbols (bfd *abfd,
             in.  This is true regardless of whether the current
             definition of the symbol is undefined or common.
 
-             If the current definition is common, we have a case in
+            If the current definition is common, we have a case in
             which we have already seen an object file including:
-                int a;
+                int a;
             and this object file from the archive includes:
-                int a = 5;
+                int a = 5;
             In such a case, whether to include this object is target
-             dependant for backward compatibility.
+            dependant for backward compatibility.
 
             FIXME: The SunOS 4.1.3 linker will pull in the archive
             element if the symbol is defined in the .data section,
@@ -3233,15 +3357,16 @@ aout_link_check_ar_symbols (bfd *abfd,
            {
              int skip = 0;
 
-             switch (info->common_skip_ar_aymbols)
+             switch (info->common_skip_ar_symbols)
                {
+               case bfd_link_common_skip_none:
+                 break;
                case bfd_link_common_skip_text:
                  skip = (type == (N_TEXT | N_EXT));
                  break;
                case bfd_link_common_skip_data:
                  skip = (type == (N_DATA | N_EXT));
                  break;
-               default:
                case bfd_link_common_skip_all:
                  skip = 1;
                  break;
@@ -3251,7 +3376,8 @@ aout_link_check_ar_symbols (bfd *abfd,
                continue;
            }
 
-         if (! (*info->callbacks->add_archive_element) (info, abfd, name))
+         if (!(*info->callbacks
+               ->add_archive_element) (info, abfd, name, subsbfd))
            return FALSE;
          *pneeded = TRUE;
          return TRUE;
@@ -3278,9 +3404,8 @@ aout_link_check_ar_symbols (bfd *abfd,
                         outside BFD.  We assume that we should link
                         in the object file.  This is done for the -u
                         option in the linker.  */
-                     if (! (*info->callbacks->add_archive_element) (info,
-                                                                    abfd,
-                                                                    name))
+                     if (!(*info->callbacks
+                           ->add_archive_element) (info, abfd, name, subsbfd))
                        return FALSE;
                      *pneeded = TRUE;
                      return TRUE;
@@ -3288,8 +3413,9 @@ aout_link_check_ar_symbols (bfd *abfd,
                  /* Turn the current link symbol into a common
                     symbol.  It is already on the undefs list.  */
                  h->type = bfd_link_hash_common;
-                 h->u.c.p = bfd_hash_allocate (&info->hash->table,
-                                               sizeof (struct bfd_link_hash_common_entry));
+                 h->u.c.p = (struct bfd_link_hash_common_entry *)
+                   bfd_hash_allocate (&info->hash->table,
+                                      sizeof (struct bfd_link_hash_common_entry));
                  if (h->u.c.p == NULL)
                    return FALSE;
 
@@ -3327,7 +3453,8 @@ aout_link_check_ar_symbols (bfd *abfd,
             it if the current link symbol is common.  */
          if (h->type == bfd_link_hash_undefined)
            {
-             if (! (*info->callbacks->add_archive_element) (info, abfd, name))
+             if (!(*info->callbacks
+                   ->add_archive_element) (info, abfd, name, subsbfd))
                return FALSE;
              *pneeded = TRUE;
              return TRUE;
@@ -3346,23 +3473,40 @@ aout_link_check_ar_symbols (bfd *abfd,
 static bfd_boolean
 aout_link_check_archive_element (bfd *abfd,
                                 struct bfd_link_info *info,
+                                struct bfd_link_hash_entry *h ATTRIBUTE_UNUSED,
+                                const char *name ATTRIBUTE_UNUSED,
                                 bfd_boolean *pneeded)
 {
-  if (! aout_get_external_symbols (abfd))
+  bfd *oldbfd;
+  bfd_boolean needed;
+
+  if (!aout_get_external_symbols (abfd))
     return FALSE;
 
-  if (! aout_link_check_ar_symbols (abfd, info, pneeded))
+  oldbfd = abfd;
+  if (!aout_link_check_ar_symbols (abfd, info, pneeded, &abfd))
     return FALSE;
 
-  if (*pneeded)
+  needed = *pneeded;
+  if (needed)
     {
-      if (! aout_link_add_symbols (abfd, info))
+      /* Potentially, the add_archive_element hook may have set a
+        substitute BFD for us.  */
+      if (abfd != oldbfd)
+       {
+         if (!info->keep_memory
+             && !aout_link_free_symbols (oldbfd))
+           return FALSE;
+         if (!aout_get_external_symbols (abfd))
+           return FALSE;
+       }
+      if (!aout_link_add_symbols (abfd, info))
        return FALSE;
     }
 
-  if (! info->keep_memory || ! *pneeded)
+  if (!info->keep_memory || !needed)
     {
-      if (! aout_link_free_symbols (abfd))
+      if (!aout_link_free_symbols (abfd))
        return FALSE;
     }
 
@@ -3459,7 +3603,8 @@ aout_link_includes_newfunc (struct bfd_hash_entry *entry,
   /* Allocate the structure if it has not already been allocated by a
      subclass.  */
   if (ret == NULL)
-    ret = bfd_hash_allocate (table, sizeof (* ret));
+    ret = (struct aout_link_includes_entry *)
+       bfd_hash_allocate (table, sizeof (* ret));
   if (ret == NULL)
     return NULL;
 
@@ -3479,15 +3624,16 @@ aout_link_includes_newfunc (struct bfd_hash_entry *entry,
    object.  */
 
 static bfd_boolean
-aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
+aout_link_write_other_symbol (struct bfd_hash_entry *bh, void *data)
 {
-  struct aout_final_link_info *finfo = (struct aout_final_link_info *) data;
+  struct aout_link_hash_entry *h = (struct aout_link_hash_entry *) bh;
+  struct aout_final_link_info *flaginfo = (struct aout_final_link_info *) data;
   bfd *output_bfd;
   int type;
   bfd_vma val;
   struct external_nlist outsym;
   bfd_size_type indx;
-  bfd_size_type amt;
+  size_t amt;
 
   if (h->root.type == bfd_link_hash_warning)
     {
@@ -3496,12 +3642,12 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
        return TRUE;
     }
 
-  output_bfd = finfo->output_bfd;
+  output_bfd = flaginfo->output_bfd;
 
   if (aout_backend_info (output_bfd)->write_dynamic_symbol != NULL)
     {
       if (! ((*aout_backend_info (output_bfd)->write_dynamic_symbol)
-            (output_bfd, finfo->info, h)))
+            (output_bfd, flaginfo->info, h)))
        {
          /* FIXME: No way to handle errors.  */
          abort ();
@@ -3515,9 +3661,9 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
 
   /* An indx of -2 means the symbol must be written.  */
   if (h->indx != -2
-      && (finfo->info->strip == strip_all
-         || (finfo->info->strip == strip_some
-             && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
+      && (flaginfo->info->strip == strip_all
+         || (flaginfo->info->strip == strip_some
+             && bfd_hash_lookup (flaginfo->info->keep_hash, h->root.root.string,
                                  FALSE, FALSE) == NULL)))
     return TRUE;
 
@@ -3530,7 +3676,7 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
       return TRUE;
     case bfd_link_hash_new:
       /* This can happen for set symbols when sets are not being
-         built.  */
+        built.  */
       return TRUE;
     case bfd_link_hash_undefined:
       type = N_UNDF | N_EXT;
@@ -3565,6 +3711,7 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
     case bfd_link_hash_undefweak:
       type = N_WEAKU;
       val = 0;
+      break;
     case bfd_link_hash_indirect:
       /* We ignore these symbols, since the indirected symbol is
         already in the hash table.  */
@@ -3574,7 +3721,7 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
   H_PUT_8 (output_bfd, type, outsym.e_type);
   H_PUT_8 (output_bfd, 0, outsym.e_other);
   H_PUT_16 (output_bfd, 0, outsym.e_desc);
-  indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
+  indx = add_to_stringtab (output_bfd, flaginfo->strtab, h->root.root.string,
                           FALSE);
   if (indx == - (bfd_size_type) 1)
     /* FIXME: No way to handle errors.  */
@@ -3584,12 +3731,12 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
   PUT_WORD (output_bfd, val, outsym.e_value);
 
   amt = EXTERNAL_NLIST_SIZE;
-  if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
+  if (bfd_seek (output_bfd, flaginfo->symoff, SEEK_SET) != 0
       || bfd_bwrite ((void *) &outsym, amt, output_bfd) != amt)
     /* FIXME: No way to handle errors.  */
     abort ();
 
-  finfo->symoff += EXTERNAL_NLIST_SIZE;
+  flaginfo->symoff += EXTERNAL_NLIST_SIZE;
   h->indx = obj_aout_external_sym_count (output_bfd);
   ++obj_aout_external_sym_count (output_bfd);
 
@@ -3599,7 +3746,7 @@ aout_link_write_other_symbol (struct aout_link_hash_entry *h, void * data)
 /* Handle a link order which is supposed to generate a reloc.  */
 
 static bfd_boolean
-aout_link_reloc_link_order (struct aout_final_link_info *finfo,
+aout_link_reloc_link_order (struct aout_final_link_info *flaginfo,
                            asection *o,
                            struct bfd_link_order *p)
 {
@@ -3611,7 +3758,7 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
   struct reloc_std_external srel;
   struct reloc_ext_external erel;
   void * rel_ptr;
-  bfd_size_type amt;
+  size_t amt;
 
   pr = p->u.reloc.p;
 
@@ -3622,7 +3769,7 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
        r_index = N_ABS | N_EXT;
       else
        {
-         BFD_ASSERT (pr->u.section->owner == finfo->output_bfd);
+         BFD_ASSERT (pr->u.section->owner == flaginfo->output_bfd);
          r_index = pr->u.section->target_index;
        }
     }
@@ -3633,7 +3780,7 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
       BFD_ASSERT (p->type == bfd_symbol_reloc_link_order);
       r_extern = 1;
       h = ((struct aout_link_hash_entry *)
-          bfd_wrapped_link_hash_lookup (finfo->output_bfd, finfo->info,
+          bfd_wrapped_link_hash_lookup (flaginfo->output_bfd, flaginfo->info,
                                         pr->u.name, FALSE, FALSE, TRUE));
       if (h != NULL
          && h->indx >= 0)
@@ -3646,37 +3793,36 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
             symbol.  */
          h->indx = -2;
          h->written = FALSE;
-         if (! aout_link_write_other_symbol (h, (void *) finfo))
+         if (!aout_link_write_other_symbol (&h->root.root, flaginfo))
            return FALSE;
          r_index = h->indx;
        }
       else
        {
-         if (! ((*finfo->info->callbacks->unattached_reloc)
-                (finfo->info, pr->u.name, NULL, NULL, (bfd_vma) 0)))
-           return FALSE;
+         (*flaginfo->info->callbacks->unattached_reloc)
+           (flaginfo->info, pr->u.name, NULL, NULL, (bfd_vma) 0);
          r_index = 0;
        }
     }
 
-  howto = bfd_reloc_type_lookup (finfo->output_bfd, pr->reloc);
+  howto = bfd_reloc_type_lookup (flaginfo->output_bfd, pr->reloc);
   if (howto == 0)
     {
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
     }
 
-  if (o == obj_textsec (finfo->output_bfd))
-    reloff_ptr = &finfo->treloff;
-  else if (o == obj_datasec (finfo->output_bfd))
-    reloff_ptr = &finfo->dreloff;
+  if (o == obj_textsec (flaginfo->output_bfd))
+    reloff_ptr = &flaginfo->treloff;
+  else if (o == obj_datasec (flaginfo->output_bfd))
+    reloff_ptr = &flaginfo->dreloff;
   else
     abort ();
 
-  if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE)
+  if (obj_reloc_entry_size (flaginfo->output_bfd) == RELOC_STD_SIZE)
     {
 #ifdef MY_put_reloc
-      MY_put_reloc (finfo->output_bfd, r_extern, r_index, p->offset, howto,
+      MY_put_reloc (flaginfo->output_bfd, r_extern, r_index, p->offset, howto,
                    &srel);
 #else
       {
@@ -3684,16 +3830,19 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
        int r_baserel;
        int r_jmptable;
        int r_relative;
-       int r_length;
+       unsigned int r_length;
 
        r_pcrel = (int) howto->pc_relative;
        r_baserel = (howto->type & 8) != 0;
        r_jmptable = (howto->type & 16) != 0;
        r_relative = (howto->type & 32) != 0;
-       r_length = howto->size;
+       if (bfd_get_reloc_size (howto) != 8)
+         r_length = howto->size;       /* Size as a power of two.  */
+       else
+         r_length = 3;
 
-       PUT_WORD (finfo->output_bfd, p->offset, srel.r_address);
-       if (bfd_header_big_endian (finfo->output_bfd))
+       PUT_WORD (flaginfo->output_bfd, p->offset, srel.r_address);
+       if (bfd_header_big_endian (flaginfo->output_bfd))
          {
            srel.r_index[0] = r_index >> 16;
            srel.r_index[1] = r_index >> 8;
@@ -3736,10 +3885,10 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
          bfd_boolean ok;
 
          size = bfd_get_reloc_size (howto);
-         buf = bfd_zmalloc (size);
-         if (buf == NULL)
+         buf = (bfd_byte *) bfd_zmalloc (size);
+         if (buf == NULL && size != 0)
            return FALSE;
-         r = MY_relocate_contents (howto, finfo->output_bfd,
+         r = MY_relocate_contents (howto, flaginfo->output_bfd,
                                    (bfd_vma) pr->addend, buf);
          switch (r)
            {
@@ -3749,20 +3898,15 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
            case bfd_reloc_outofrange:
              abort ();
            case bfd_reloc_overflow:
-             if (! ((*finfo->info->callbacks->reloc_overflow)
-                    (finfo->info, NULL,
-                     (p->type == bfd_section_reloc_link_order
-                      ? bfd_section_name (finfo->output_bfd,
-                                          pr->u.section)
-                      : pr->u.name),
-                     howto->name, pr->addend, NULL, NULL, (bfd_vma) 0)))
-               {
-                 free (buf);
-                 return FALSE;
-               }
+             (*flaginfo->info->callbacks->reloc_overflow)
+               (flaginfo->info, NULL,
+                (p->type == bfd_section_reloc_link_order
+                 ? bfd_section_name (pr->u.section)
+                 : pr->u.name),
+                howto->name, pr->addend, NULL, NULL, (bfd_vma) 0);
              break;
            }
-         ok = bfd_set_section_contents (finfo->output_bfd, o, (void *) buf,
+         ok = bfd_set_section_contents (flaginfo->output_bfd, o, (void *) buf,
                                         (file_ptr) p->offset, size);
          free (buf);
          if (! ok)
@@ -3772,12 +3916,12 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
   else
     {
 #ifdef MY_put_ext_reloc
-      MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
+      MY_put_ext_reloc (flaginfo->output_bfd, r_extern, r_index, p->offset,
                        howto, &erel, pr->addend);
 #else
-      PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
+      PUT_WORD (flaginfo->output_bfd, p->offset, erel.r_address);
 
-      if (bfd_header_big_endian (finfo->output_bfd))
+      if (bfd_header_big_endian (flaginfo->output_bfd))
        {
          erel.r_index[0] = r_index >> 16;
          erel.r_index[1] = r_index >> 8;
@@ -3796,25 +3940,25 @@ aout_link_reloc_link_order (struct aout_final_link_info *finfo,
              | (howto->type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
        }
 
-      PUT_WORD (finfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
+      PUT_WORD (flaginfo->output_bfd, (bfd_vma) pr->addend, erel.r_addend);
 #endif /* MY_put_ext_reloc */
 
       rel_ptr = (void *) &erel;
     }
 
-  amt = obj_reloc_entry_size (finfo->output_bfd);
-  if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
-      || bfd_bwrite (rel_ptr, amt, finfo->output_bfd) != amt)
+  amt = obj_reloc_entry_size (flaginfo->output_bfd);
+  if (bfd_seek (flaginfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
+      || bfd_bwrite (rel_ptr, amt, flaginfo->output_bfd) != amt)
     return FALSE;
 
-  *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
+  *reloff_ptr += obj_reloc_entry_size (flaginfo->output_bfd);
 
   /* Assert that the relocs have not run into the symbols, and that n
      the text relocs have not run into the data relocs.  */
-  BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
-             && (reloff_ptr != &finfo->treloff
+  BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (flaginfo->output_bfd)
+             && (reloff_ptr != &flaginfo->treloff
                  || (*reloff_ptr
-                     <= obj_datasec (finfo->output_bfd)->rel_filepos)));
+                     <= obj_datasec (flaginfo->output_bfd)->rel_filepos)));
 
   return TRUE;
 }
@@ -3839,7 +3983,7 @@ aout_reloc_index_to_section (bfd *abfd, int indx)
 /* Relocate an a.out section using standard a.out relocs.  */
 
 static bfd_boolean
-aout_link_input_section_std (struct aout_final_link_info *finfo,
+aout_link_input_section_std (struct aout_final_link_info *flaginfo,
                             bfd *input_bfd,
                             asection *input_section,
                             struct reloc_std_external *relocs,
@@ -3860,18 +4004,18 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
   struct reloc_std_external *rel;
   struct reloc_std_external *rel_end;
 
-  output_bfd = finfo->output_bfd;
+  output_bfd = flaginfo->output_bfd;
   check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
 
   BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE);
   BFD_ASSERT (input_bfd->xvec->header_byteorder
              == output_bfd->xvec->header_byteorder);
 
-  relocatable = finfo->info->relocatable;
+  relocatable = bfd_link_relocatable (flaginfo->info);
   syms = obj_aout_external_syms (input_bfd);
   strings = obj_aout_external_strings (input_bfd);
   sym_hashes = obj_aout_sym_hashes (input_bfd);
-  symbol_map = finfo->symbol_map;
+  symbol_map = flaginfo->symbol_map;
 
   reloc_count = rel_size / RELOC_STD_SIZE;
   rel = relocs;
@@ -3931,11 +4075,21 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
 
        howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel
                     + 16 * r_jmptable + 32 * r_relative);
-       BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
-       howto = howto_table_std + howto_idx;
+       if (howto_idx < TABLE_SIZE (howto_table_std))
+         howto = howto_table_std + howto_idx;
+       else
+         howto = NULL;
       }
 #endif
 
+      if (howto == NULL)
+       {
+         _bfd_error_handler (_("%pB: unsupported relocation type"),
+                             input_bfd);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
+
       if (relocatable)
        {
          /* We are generating a relocatable output file, and must
@@ -3986,16 +4140,16 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
                      if (h != NULL)
                        {
                          /* We decided to strip this symbol, but it
-                             turns out that we can't.  Note that we
-                             lose the other and desc information here.
-                             I don't think that will ever matter for a
-                             global symbol.  */
+                            turns out that we can't.  Note that we
+                            lose the other and desc information here.
+                            I don't think that will ever matter for a
+                            global symbol.  */
                          if (h->indx < 0)
                            {
                              h->indx = -2;
                              h->written = FALSE;
-                             if (! aout_link_write_other_symbol (h,
-                                                                 (void *) finfo))
+                             if (!aout_link_write_other_symbol (&h->root.root,
+                                                                flaginfo))
                                return FALSE;
                            }
                          r_index = h->indx;
@@ -4006,10 +4160,9 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
 
                          name = strings + GET_WORD (input_bfd,
                                                     syms[r_index].e_strx);
-                         if (! ((*finfo->info->callbacks->unattached_reloc)
-                                (finfo->info, name, input_bfd, input_section,
-                                 r_addr)))
-                           return FALSE;
+                         (*flaginfo->info->callbacks->unattached_reloc)
+                           (flaginfo->info, name,
+                            input_bfd, input_section, r_addr);
                          r_index = 0;
                        }
                    }
@@ -4113,7 +4266,7 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
              bfd_boolean skip;
 
              if (! ((*check_dynamic_reloc)
-                    (finfo->info, input_bfd, input_section, h,
+                    (flaginfo->info, input_bfd, input_section, h,
                      (void *) rel, contents, &skip, &relocation)))
                return FALSE;
              if (skip)
@@ -4121,9 +4274,9 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
            }
 
          /* Now warn if a global symbol is undefined.  We could not
-             do this earlier, because check_dynamic_reloc might want
-             to skip this reloc.  */
-         if (hundef && ! finfo->info->shared && ! r_baserel)
+            do this earlier, because check_dynamic_reloc might want
+            to skip this reloc.  */
+         if (hundef && ! bfd_link_pic (flaginfo->info) && ! r_baserel)
            {
              const char *name;
 
@@ -4131,10 +4284,8 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
                name = h->root.root.string;
              else
                name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
-             if (! ((*finfo->info->callbacks->undefined_symbol)
-                    (finfo->info, name, input_bfd, input_section,
-                    r_addr, TRUE)))
-               return FALSE;
+             (*flaginfo->info->callbacks->undefined_symbol)
+               (flaginfo->info, name, input_bfd, input_section, r_addr, TRUE);
            }
 
          r = MY_final_link_relocate (howto,
@@ -4164,13 +4315,11 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
                    asection *s;
 
                    s = aout_reloc_index_to_section (input_bfd, r_index);
-                   name = bfd_section_name (input_bfd, s);
+                   name = bfd_section_name (s);
                  }
-               if (! ((*finfo->info->callbacks->reloc_overflow)
-                      (finfo->info, (h ? &h->root : NULL), name,
-                       howto->name, (bfd_vma) 0, input_bfd,
-                       input_section, r_addr)))
-                 return FALSE;
+               (*flaginfo->info->callbacks->reloc_overflow)
+                 (flaginfo->info, (h ? &h->root : NULL), name, howto->name,
+                  (bfd_vma) 0, input_bfd, input_section, r_addr);
              }
              break;
            }
@@ -4183,7 +4332,7 @@ aout_link_input_section_std (struct aout_final_link_info *finfo,
 /* Relocate an a.out section using extended a.out relocs.  */
 
 static bfd_boolean
-aout_link_input_section_ext (struct aout_final_link_info *finfo,
+aout_link_input_section_ext (struct aout_final_link_info *flaginfo,
                             bfd *input_bfd,
                             asection *input_section,
                             struct reloc_ext_external *relocs,
@@ -4204,18 +4353,18 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
   struct reloc_ext_external *rel;
   struct reloc_ext_external *rel_end;
 
-  output_bfd = finfo->output_bfd;
+  output_bfd = flaginfo->output_bfd;
   check_dynamic_reloc = aout_backend_info (output_bfd)->check_dynamic_reloc;
 
   BFD_ASSERT (obj_reloc_entry_size (input_bfd) == RELOC_EXT_SIZE);
   BFD_ASSERT (input_bfd->xvec->header_byteorder
              == output_bfd->xvec->header_byteorder);
 
-  relocatable = finfo->info->relocatable;
+  relocatable = bfd_link_relocatable (flaginfo->info);
   syms = obj_aout_external_syms (input_bfd);
   strings = obj_aout_external_strings (input_bfd);
   sym_hashes = obj_aout_sym_hashes (input_bfd);
-  symbol_map = finfo->symbol_map;
+  symbol_map = flaginfo->symbol_map;
 
   reloc_count = rel_size / RELOC_EXT_SIZE;
   rel = relocs;
@@ -4254,7 +4403,13 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
 
       r_addend = GET_SWORD (input_bfd, rel->r_addend);
 
-      BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext));
+      if (r_type >= TABLE_SIZE (howto_table_ext))
+       {
+         _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                             input_bfd, r_type);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
       if (relocatable)
        {
@@ -4322,16 +4477,16 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
                      if (h != NULL)
                        {
                          /* We decided to strip this symbol, but it
-                             turns out that we can't.  Note that we
-                             lose the other and desc information here.
-                             I don't think that will ever matter for a
-                             global symbol.  */
+                            turns out that we can't.  Note that we
+                            lose the other and desc information here.
+                            I don't think that will ever matter for a
+                            global symbol.  */
                          if (h->indx < 0)
                            {
                              h->indx = -2;
                              h->written = FALSE;
-                             if (! aout_link_write_other_symbol (h,
-                                                                 (void *) finfo))
+                             if (!aout_link_write_other_symbol (&h->root.root,
+                                                                flaginfo))
                                return FALSE;
                            }
                          r_index = h->indx;
@@ -4342,10 +4497,9 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
 
                          name = strings + GET_WORD (input_bfd,
                                                     syms[r_index].e_strx);
-                         if (! ((*finfo->info->callbacks->unattached_reloc)
-                                (finfo->info, name, input_bfd, input_section,
-                                 r_addr)))
-                           return FALSE;
+                         (*flaginfo->info->callbacks->unattached_reloc)
+                           (flaginfo->info, name,
+                            input_bfd, input_section, r_addr);
                          r_index = 0;
                        }
                    }
@@ -4446,7 +4600,7 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
              int type;
 
              /* For base relative relocs, r_index is always an index
-                 into the symbol table, even if r_extern is 0.  */
+                into the symbol table, even if r_extern is 0.  */
              sym = syms + r_index;
              type = H_GET_8 (input_bfd, sym->e_type);
              if ((type & N_TYPE) == N_TEXT
@@ -4510,7 +4664,7 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
              bfd_boolean skip;
 
              if (! ((*check_dynamic_reloc)
-                    (finfo->info, input_bfd, input_section, h,
+                    (flaginfo->info, input_bfd, input_section, h,
                      (void *) rel, contents, &skip, &relocation)))
                return FALSE;
              if (skip)
@@ -4518,10 +4672,10 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
            }
 
          /* Now warn if a global symbol is undefined.  We could not
-             do this earlier, because check_dynamic_reloc might want
-             to skip this reloc.  */
+            do this earlier, because check_dynamic_reloc might want
+            to skip this reloc.  */
          if (hundef
-             && ! finfo->info->shared
+             && ! bfd_link_pic (flaginfo->info)
              && r_type != (unsigned int) RELOC_BASE10
              && r_type != (unsigned int) RELOC_BASE13
              && r_type != (unsigned int) RELOC_BASE22)
@@ -4532,10 +4686,8 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
                name = h->root.root.string;
              else
                name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
-             if (! ((*finfo->info->callbacks->undefined_symbol)
-                    (finfo->info, name, input_bfd, input_section,
-                    r_addr, TRUE)))
-               return FALSE;
+             (*flaginfo->info->callbacks->undefined_symbol)
+               (flaginfo->info, name, input_bfd, input_section, r_addr, TRUE);
            }
 
          if (r_type != (unsigned int) RELOC_SPARC_REV32)
@@ -4577,13 +4729,12 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
                        asection *s;
 
                        s = aout_reloc_index_to_section (input_bfd, r_index);
-                       name = bfd_section_name (input_bfd, s);
+                       name = bfd_section_name (s);
                      }
-                   if (! ((*finfo->info->callbacks->reloc_overflow)
-                          (finfo->info, (h ? &h->root : NULL), name,
-                           howto_table_ext[r_type].name,
-                           r_addend, input_bfd, input_section, r_addr)))
-                     return FALSE;
+                   (*flaginfo->info->callbacks->reloc_overflow)
+                     (flaginfo->info, (h ? &h->root : NULL), name,
+                      howto_table_ext[r_type].name,
+                      r_addend, input_bfd, input_section, r_addr);
                  }
                  break;
                }
@@ -4597,7 +4748,7 @@ aout_link_input_section_ext (struct aout_final_link_info *finfo,
 /* Link an a.out section into the output file.  */
 
 static bfd_boolean
-aout_link_input_section (struct aout_final_link_info *finfo,
+aout_link_input_section (struct aout_final_link_info *flaginfo,
                         bfd *input_bfd,
                         asection *input_section,
                         file_ptr *reloff_ptr,
@@ -4609,7 +4760,7 @@ aout_link_input_section (struct aout_final_link_info *finfo,
   /* Get the section contents.  */
   input_size = input_section->size;
   if (! bfd_get_section_contents (input_bfd, input_section,
-                                 (void *) finfo->contents,
+                                 (void *) flaginfo->contents,
                                  (file_ptr) 0, input_size))
     return FALSE;
 
@@ -4619,7 +4770,7 @@ aout_link_input_section (struct aout_final_link_info *finfo,
     relocs = aout_section_data (input_section)->relocs;
   else
     {
-      relocs = finfo->relocs;
+      relocs = flaginfo->relocs;
       if (rel_size > 0)
        {
          if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
@@ -4631,44 +4782,44 @@ aout_link_input_section (struct aout_final_link_info *finfo,
   /* Relocate the section contents.  */
   if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
     {
-      if (! aout_link_input_section_std (finfo, input_bfd, input_section,
+      if (! aout_link_input_section_std (flaginfo, input_bfd, input_section,
                                         (struct reloc_std_external *) relocs,
-                                        rel_size, finfo->contents))
+                                        rel_size, flaginfo->contents))
        return FALSE;
     }
   else
     {
-      if (! aout_link_input_section_ext (finfo, input_bfd, input_section,
+      if (! aout_link_input_section_ext (flaginfo, input_bfd, input_section,
                                         (struct reloc_ext_external *) relocs,
-                                        rel_size, finfo->contents))
+                                        rel_size, flaginfo->contents))
        return FALSE;
     }
 
   /* Write out the section contents.  */
-  if (! bfd_set_section_contents (finfo->output_bfd,
+  if (! bfd_set_section_contents (flaginfo->output_bfd,
                                  input_section->output_section,
-                                 (void *) finfo->contents,
+                                 (void *) flaginfo->contents,
                                  (file_ptr) input_section->output_offset,
                                  input_size))
     return FALSE;
 
   /* If we are producing relocatable output, the relocs were
      modified, and we now write them out.  */
-  if (finfo->info->relocatable && rel_size > 0)
+  if (bfd_link_relocatable (flaginfo->info) && rel_size > 0)
     {
-      if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
+      if (bfd_seek (flaginfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
        return FALSE;
-      if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
+      if (bfd_bwrite (relocs, rel_size, flaginfo->output_bfd) != rel_size)
        return FALSE;
       *reloff_ptr += rel_size;
 
       /* Assert that the relocs have not run into the symbols, and
         that if these are the text relocs they have not run into the
         data relocs.  */
-      BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (finfo->output_bfd)
-                 && (reloff_ptr != &finfo->treloff
+      BFD_ASSERT (*reloff_ptr <= obj_sym_filepos (flaginfo->output_bfd)
+                 && (reloff_ptr != &flaginfo->treloff
                      || (*reloff_ptr
-                         <= obj_datasec (finfo->output_bfd)->rel_filepos)));
+                         <= obj_datasec (flaginfo->output_bfd)->rel_filepos)));
     }
 
   return TRUE;
@@ -4678,7 +4829,7 @@ aout_link_input_section (struct aout_final_link_info *finfo,
    symbol indices into a symbol_map.  */
 
 static bfd_boolean
-aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
+aout_link_write_symbols (struct aout_final_link_info *flaginfo, bfd *input_bfd)
 {
   bfd *output_bfd;
   bfd_size_type sym_count;
@@ -4694,32 +4845,32 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
   bfd_boolean pass;
   bfd_boolean skip_next;
 
-  output_bfd = finfo->output_bfd;
+  output_bfd = flaginfo->output_bfd;
   sym_count = obj_aout_external_sym_count (input_bfd);
   strings = obj_aout_external_strings (input_bfd);
-  strip = finfo->info->strip;
-  discard = finfo->info->discard;
-  outsym = finfo->output_syms;
+  strip = flaginfo->info->strip;
+  discard = flaginfo->info->discard;
+  outsym = flaginfo->output_syms;
 
   /* First write out a symbol for this object file, unless we are
      discarding such symbols.  */
   if (strip != strip_all
       && (strip != strip_some
-         || bfd_hash_lookup (finfo->info->keep_hash, input_bfd->filename,
+         || bfd_hash_lookup (flaginfo->info->keep_hash,
+                             bfd_get_filename (input_bfd),
                              FALSE, FALSE) != NULL)
       && discard != discard_all)
     {
       H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
       H_PUT_8 (output_bfd, 0, outsym->e_other);
       H_PUT_16 (output_bfd, 0, outsym->e_desc);
-      strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
-                                      input_bfd->filename, FALSE);
+      strtab_index = add_to_stringtab (output_bfd, flaginfo->strtab,
+                                      bfd_get_filename (input_bfd), FALSE);
       if (strtab_index == (bfd_size_type) -1)
        return FALSE;
       PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
       PUT_WORD (output_bfd,
-               (bfd_get_section_vma (output_bfd,
-                                     obj_textsec (input_bfd)->output_section)
+               (bfd_section_vma (obj_textsec (input_bfd)->output_section)
                 + obj_textsec (input_bfd)->output_offset),
                outsym->e_value);
       ++obj_aout_external_sym_count (output_bfd);
@@ -4731,7 +4882,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
   sym = obj_aout_external_syms (input_bfd);
   sym_end = sym + sym_count;
   sym_hash = obj_aout_sym_hashes (input_bfd);
-  symbol_map = finfo->symbol_map;
+  symbol_map = flaginfo->symbol_map;
   memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
   for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
     {
@@ -4744,15 +4895,15 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
       bfd_boolean copy;
 
       /* We set *symbol_map to 0 above for all symbols.  If it has
-         already been set to -1 for this symbol, it means that we are
-         discarding it because it appears in a duplicate header file.
-         See the N_BINCL code below.  */
+        already been set to -1 for this symbol, it means that we are
+        discarding it because it appears in a duplicate header file.
+        See the N_BINCL code below.  */
       if (*symbol_map == -1)
        continue;
 
       /* Initialize *symbol_map to -1, which means that the symbol was
-         not copied into the output file.  We will change it later if
-         we do copy the symbol over.  */
+        not copied into the output file.  We will change it later if
+        we do copy the symbol over.  */
       *symbol_map = -1;
 
       type = H_GET_8 (input_bfd, sym->e_type);
@@ -4786,7 +4937,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
          h = *sym_hash;
 
          /* Use the name from the hash table, in case the symbol was
-             wrapped.  */
+            wrapped.  */
          if (h != NULL
              && h->root.type != bfd_link_hash_warning)
            name = h->root.root.string;
@@ -4830,7 +4981,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
                skip = TRUE;
              break;
            case strip_some:
-             if (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
+             if (bfd_hash_lookup (flaginfo->info->keep_hash, name, FALSE, FALSE)
                  == NULL)
                skip = TRUE;
              break;
@@ -4927,7 +5078,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
                  BFD_ASSERT (bfd_is_abs_section (output_section)
                              || output_section->owner == output_bfd);
                  val = (hresolve->root.u.def.value
-                        + bfd_get_section_vma (output_bfd, output_section)
+                        + bfd_section_vma (output_section)
                         + input_section->output_offset);
 
                  /* Get the correct type based on the section.  If
@@ -5056,10 +5207,10 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
                }
 
              /* If we have already included a header file with the
-                 same value, then replace this one with an N_EXCL
-                 symbol.  */
-             copy = (bfd_boolean) (! finfo->info->keep_memory);
-             incl_entry = aout_link_includes_lookup (&finfo->includes,
+                same value, then replace this one with an N_EXCL
+                symbol.  */
+             copy = (bfd_boolean) (! flaginfo->info->keep_memory);
+             incl_entry = aout_link_includes_lookup (&flaginfo->includes,
                                                      name, TRUE, copy);
              if (incl_entry == NULL)
                return FALSE;
@@ -5069,8 +5220,9 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
              if (t == NULL)
                {
                  /* This is the first time we have seen this header
-                     file with this set of stabs strings.  */
-                 t = bfd_hash_allocate (&finfo->includes.root,
+                    file with this set of stabs strings.  */
+                 t = (struct aout_link_includes_totals *)
+                     bfd_hash_allocate (&flaginfo->includes.root,
                                         sizeof *t);
                  if (t == NULL)
                    return FALSE;
@@ -5083,8 +5235,8 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
                  int *incl_map;
 
                  /* This is a duplicate header file.  We must change
-                     it to be an N_EXCL entry, and mark all the
-                     included symbols to prevent outputting them.  */
+                    it to be an N_EXCL entry, and mark all the
+                    included symbols to prevent outputting them.  */
                  type = (int) N_EXCL;
 
                  nest = 0;
@@ -5119,7 +5271,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
       H_PUT_8 (output_bfd, H_GET_8 (input_bfd, sym->e_other), outsym->e_other);
       H_PUT_16 (output_bfd, H_GET_16 (input_bfd, sym->e_desc), outsym->e_desc);
       copy = FALSE;
-      if (! finfo->info->keep_memory)
+      if (! flaginfo->info->keep_memory)
        {
          /* name points into a string table which we are going to
             free.  If there is a hash table entry, use that string.
@@ -5129,7 +5281,7 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
          else
            copy = TRUE;
        }
-      strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
+      strtab_index = add_to_stringtab (output_bfd, flaginfo->strtab,
                                       name, copy);
       if (strtab_index == (bfd_size_type) -1)
        return FALSE;
@@ -5141,18 +5293,18 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
     }
 
   /* Write out the output symbols we have just constructed.  */
-  if (outsym > finfo->output_syms)
+  if (outsym > flaginfo->output_syms)
     {
       bfd_size_type outsym_size;
 
-      if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
+      if (bfd_seek (output_bfd, flaginfo->symoff, SEEK_SET) != 0)
        return FALSE;
-      outsym_size = outsym - finfo->output_syms;
+      outsym_size = outsym - flaginfo->output_syms;
       outsym_size *= EXTERNAL_NLIST_SIZE;
-      if (bfd_bwrite ((void *) finfo->output_syms, outsym_size, output_bfd)
+      if (bfd_bwrite ((void *) flaginfo->output_syms, outsym_size, output_bfd)
          != outsym_size)
        return FALSE;
-      finfo->symoff += outsym_size;
+      flaginfo->symoff += outsym_size;
     }
 
   return TRUE;
@@ -5161,28 +5313,24 @@ aout_link_write_symbols (struct aout_final_link_info *finfo, bfd *input_bfd)
 /* Link an a.out input BFD into the output file.  */
 
 static bfd_boolean
-aout_link_input_bfd (struct aout_final_link_info *finfo, bfd *input_bfd)
+aout_link_input_bfd (struct aout_final_link_info *flaginfo, bfd *input_bfd)
 {
-  bfd_size_type sym_count;
-
   BFD_ASSERT (bfd_get_format (input_bfd) == bfd_object);
 
   /* If this is a dynamic object, it may need special handling.  */
   if ((input_bfd->flags & DYNAMIC) != 0
       && aout_backend_info (input_bfd)->link_dynamic_object != NULL)
     return ((*aout_backend_info (input_bfd)->link_dynamic_object)
-           (finfo->info, input_bfd));
+           (flaginfo->info, input_bfd));
 
   /* Get the symbols.  We probably have them already, unless
-     finfo->info->keep_memory is FALSE.  */
+     flaginfo->info->keep_memory is FALSE.  */
   if (! aout_get_external_symbols (input_bfd))
     return FALSE;
 
-  sym_count = obj_aout_external_sym_count (input_bfd);
-
   /* Write out the symbols and get a map of the new indices.  The map
-     is placed into finfo->symbol_map.  */
-  if (! aout_link_write_symbols (finfo, input_bfd))
+     is placed into flaginfo->symbol_map.  */
+  if (! aout_link_write_symbols (flaginfo, input_bfd))
     return FALSE;
 
   /* Relocate and write out the sections.  These functions use the
@@ -5191,17 +5339,17 @@ aout_link_input_bfd (struct aout_final_link_info *finfo, bfd *input_bfd)
      link, which will normally be the case.  */
   if (obj_textsec (input_bfd)->linker_mark)
     {
-      if (! aout_link_input_section (finfo, input_bfd,
+      if (! aout_link_input_section (flaginfo, input_bfd,
                                     obj_textsec (input_bfd),
-                                    &finfo->treloff,
+                                    &flaginfo->treloff,
                                     exec_hdr (input_bfd)->a_trsize))
        return FALSE;
     }
   if (obj_datasec (input_bfd)->linker_mark)
     {
-      if (! aout_link_input_section (finfo, input_bfd,
+      if (! aout_link_input_section (flaginfo, input_bfd,
                                     obj_datasec (input_bfd),
-                                    &finfo->dreloff,
+                                    &flaginfo->dreloff,
                                     exec_hdr (input_bfd)->a_drsize))
        return FALSE;
     }
@@ -5209,7 +5357,7 @@ aout_link_input_bfd (struct aout_final_link_info *finfo, bfd *input_bfd)
   /* If we are not keeping memory, we don't need the symbols any
      longer.  We still need them if we are keeping memory, because the
      strings in the hash table point into them.  */
-  if (! finfo->info->keep_memory)
+  if (! flaginfo->info->keep_memory)
     {
       if (! aout_link_free_symbols (input_bfd))
        return FALSE;
@@ -5220,7 +5368,7 @@ aout_link_input_bfd (struct aout_final_link_info *finfo, bfd *input_bfd)
 
 /* Do the final link step.  This is called on the output BFD.  The
    INFO structure should point to a list of BFDs linked through the
-   link_next field which can be used to find each BFD which takes part
+   link.next field which can be used to find each BFD which takes part
    in the output.  Also, each section in ABFD should point to a list
    of bfd_link_order structures which list all the input sections for
    the output section.  */
@@ -5237,13 +5385,11 @@ NAME (aout, final_link) (bfd *abfd,
   bfd_size_type max_contents_size;
   bfd_size_type max_relocs_size;
   bfd_size_type max_sym_count;
-  bfd_size_type text_size;
-  file_ptr text_end;
   struct bfd_link_order *p;
   asection *o;
   bfd_boolean have_link_order_relocs;
 
-  if (info->shared)
+  if (bfd_link_pic (info))
     abfd->flags |= DYNAMIC;
 
   aout_info.info = info;
@@ -5253,9 +5399,10 @@ NAME (aout, final_link) (bfd *abfd,
   aout_info.symbol_map = NULL;
   aout_info.output_syms = NULL;
 
-  if (! bfd_hash_table_init_n (&aout_info.includes.root,
-                              aout_link_includes_newfunc,
-                              251))
+  if (!bfd_hash_table_init_n (&aout_info.includes.root,
+                             aout_link_includes_newfunc,
+                             sizeof (struct aout_link_includes_entry),
+                             251))
     goto error_return;
   includes_hash_initialized = TRUE;
 
@@ -5266,11 +5413,11 @@ NAME (aout, final_link) (bfd *abfd,
   max_contents_size = 0;
   max_relocs_size = 0;
   max_sym_count = 0;
-  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+  for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
     {
       bfd_size_type sz;
 
-      if (info->relocatable)
+      if (bfd_link_relocatable (info))
        {
          if (bfd_get_flavour (sub) == bfd_target_aout_flavour)
            {
@@ -5283,10 +5430,10 @@ NAME (aout, final_link) (bfd *abfd,
                 and call get_reloc_upper_bound and canonicalize_reloc to
                 work out the number of relocs needed, and then multiply
                 by the reloc size.  */
-             (*_bfd_error_handler)
-               (_("%s: relocatable link from %s to %s not supported"),
-                bfd_get_filename (abfd),
-                sub->xvec->name, abfd->xvec->name);
+             _bfd_error_handler
+               /* xgettext:c-format */
+               (_("%pB: relocatable link from %s to %s not supported"),
+                abfd, sub->xvec->name, abfd->xvec->name);
              bfd_set_error (bfd_error_invalid_operation);
              goto error_return;
            }
@@ -5314,15 +5461,15 @@ NAME (aout, final_link) (bfd *abfd,
        }
     }
 
-  if (info->relocatable)
+  if (bfd_link_relocatable (info))
     {
       if (obj_textsec (abfd) != NULL)
        trsize += (_bfd_count_link_order_relocs (obj_textsec (abfd)
-                                                ->link_order_head)
+                                                ->map_head.link_order)
                   * obj_reloc_entry_size (abfd));
       if (obj_datasec (abfd) != NULL)
        drsize += (_bfd_count_link_order_relocs (obj_datasec (abfd)
-                                                ->link_order_head)
+                                                ->map_head.link_order)
                   * obj_reloc_entry_size (abfd));
     }
 
@@ -5334,7 +5481,7 @@ NAME (aout, final_link) (bfd *abfd,
   /* Adjust the section sizes and vmas according to the magic number.
      This sets a_text, a_data and a_bss in the exec_hdr and sets the
      filepos for each section.  */
-  if (! NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end))
+  if (! NAME (aout, adjust_sizes_and_vmas) (abfd))
     goto error_return;
 
   /* The relocation and symbol file positions differ among a.out
@@ -5343,8 +5490,7 @@ NAME (aout, final_link) (bfd *abfd,
      FIXME: At this point we do not know how much space the symbol
      table will require.  This will not work for any (nonstandard)
      a.out target that needs to know the symbol table size before it
-     can compute the relocation file positions.  This may or may not
-     be the case for the hp300hpux target, for example.  */
+     can compute the relocation file positions.  */
   (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
               &aout_info.symoff);
   obj_textsec (abfd)->rel_filepos = aout_info.treloff;
@@ -5360,11 +5506,11 @@ NAME (aout, final_link) (bfd *abfd,
     goto error_return;
 
   /* Allocate buffers to hold section contents and relocs.  */
-  aout_info.contents = bfd_malloc (max_contents_size);
+  aout_info.contents = (bfd_byte *) bfd_malloc (max_contents_size);
   aout_info.relocs = bfd_malloc (max_relocs_size);
-  aout_info.symbol_map = bfd_malloc (max_sym_count * sizeof (int *));
-  aout_info.output_syms = bfd_malloc ((max_sym_count + 1)
-                                     * sizeof (struct external_nlist));
+  aout_info.symbol_map = (int *) bfd_malloc (max_sym_count * sizeof (int));
+  aout_info.output_syms = (struct external_nlist *)
+      bfd_malloc ((max_sym_count + 1) * sizeof (struct external_nlist));
   if ((aout_info.contents == NULL && max_contents_size != 0)
       || (aout_info.relocs == NULL && max_relocs_size != 0)
       || (aout_info.symbol_map == NULL && max_sym_count != 0)
@@ -5381,7 +5527,7 @@ NAME (aout, final_link) (bfd *abfd,
     h = aout_link_hash_lookup (aout_hash_table (info), "__DYNAMIC",
                               FALSE, FALSE, FALSE);
     if (h != NULL)
-      aout_link_write_other_symbol (h, &aout_info);
+      aout_link_write_other_symbol (&h->root.root, &aout_info);
   }
 
   /* The most time efficient way to do the link would be to read all
@@ -5405,7 +5551,7 @@ NAME (aout, final_link) (bfd *abfd,
 
      We use the output_has_begun field of the input BFDs to see
      whether we have already handled it.  */
-  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+  for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
     sub->output_has_begun = FALSE;
 
   /* Mark all sections which are to be included in the link.  This
@@ -5414,7 +5560,7 @@ NAME (aout, final_link) (bfd *abfd,
      include.  */
   for (o = abfd->sections; o != NULL; o = o->next)
     {
-      for (p = o->link_order_head; p != NULL; p = p->next)
+      for (p = o->map_head.link_order; p != NULL; p = p->next)
        if (p->type == bfd_indirect_link_order)
          p->u.indirect.section->linker_mark = TRUE;
     }
@@ -5422,7 +5568,7 @@ NAME (aout, final_link) (bfd *abfd,
   have_link_order_relocs = FALSE;
   for (o = abfd->sections; o != NULL; o = o->next)
     {
-      for (p = o->link_order_head;
+      for (p = o->map_head.link_order;
           p != NULL;
           p = p->next)
        {
@@ -5455,9 +5601,9 @@ NAME (aout, final_link) (bfd *abfd,
     }
 
   /* Write out any symbols that we have not already written out.  */
-  aout_link_hash_traverse (aout_hash_table (info),
-                          aout_link_write_other_symbol,
-                          (void *) &aout_info);
+  bfd_hash_traverse (&info->hash->table,
+                    aout_link_write_other_symbol,
+                    &aout_info);
 
   /* Now handle any relocs we were asked to create by the linker.
      These did not come from any input file.  We must do these after
@@ -5467,7 +5613,7 @@ NAME (aout, final_link) (bfd *abfd,
     {
       for (o = abfd->sections; o != NULL; o = o->next)
        {
-         for (p = o->link_order_head;
+         for (p = o->map_head.link_order;
               p != NULL;
               p = p->next)
            {
@@ -5481,26 +5627,15 @@ NAME (aout, final_link) (bfd *abfd,
        }
     }
 
-  if (aout_info.contents != NULL)
-    {
-      free (aout_info.contents);
-      aout_info.contents = NULL;
-    }
-  if (aout_info.relocs != NULL)
-    {
-      free (aout_info.relocs);
-      aout_info.relocs = NULL;
-    }
-  if (aout_info.symbol_map != NULL)
-    {
-      free (aout_info.symbol_map);
-      aout_info.symbol_map = NULL;
-    }
-  if (aout_info.output_syms != NULL)
-    {
-      free (aout_info.output_syms);
-      aout_info.output_syms = NULL;
-    }
+  free (aout_info.contents);
+  aout_info.contents = NULL;
+  free (aout_info.relocs);
+  aout_info.relocs = NULL;
+  free (aout_info.symbol_map);
+  aout_info.symbol_map = NULL;
+  free (aout_info.output_syms);
+  aout_info.output_syms = NULL;
+
   if (includes_hash_initialized)
     {
       bfd_hash_table_free (&aout_info.includes.root);
@@ -5524,36 +5659,29 @@ NAME (aout, final_link) (bfd *abfd,
     exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
 
   /* Write out the string table, unless there are no symbols.  */
+  if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0)
+    goto error_return;
   if (abfd->symcount > 0)
     {
-      if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
-         || ! emit_stringtab (abfd, aout_info.strtab))
+      if (!emit_stringtab (abfd, aout_info.strtab))
        goto error_return;
     }
-  else if (obj_textsec (abfd)->reloc_count == 0
-          && obj_datasec (abfd)->reloc_count == 0)
+  else
     {
-      bfd_byte b;
-      file_ptr pos;
+      bfd_byte b[BYTES_IN_WORD];
 
-      b = 0;
-      pos = obj_datasec (abfd)->filepos + exec_hdr (abfd)->a_data - 1;
-      if (bfd_seek (abfd, pos, SEEK_SET) != 0
-         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
+      memset (b, 0, BYTES_IN_WORD);
+      if (bfd_bwrite (b, (bfd_size_type) BYTES_IN_WORD, abfd) != BYTES_IN_WORD)
        goto error_return;
     }
 
   return TRUE;
 
  error_return:
-  if (aout_info.contents != NULL)
-    free (aout_info.contents);
-  if (aout_info.relocs != NULL)
-    free (aout_info.relocs);
-  if (aout_info.symbol_map != NULL)
-    free (aout_info.symbol_map);
-  if (aout_info.output_syms != NULL)
-    free (aout_info.output_syms);
+  free (aout_info.contents);
+  free (aout_info.relocs);
+  free (aout_info.symbol_map);
+  free (aout_info.output_syms);
   if (includes_hash_initialized)
     bfd_hash_table_free (&aout_info.includes.root);
   return FALSE;
This page took 0.070705 seconds and 4 git commands to generate.