OSDN Git Service

daily update
[pf3gnuchains/pf3gnuchains4x.git] / bfd / pdp11.c
index 3b60b03..265c159 100644 (file)
@@ -1,21 +1,21 @@
 /* BFD back-end for PDP-11 a.out binaries.
    Copyright 2001 Free Software Foundation, Inc.
 
-This file is part of BFD, the Binary File Descriptor library.
+   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
-(at your option) any later version.
+   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
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-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. */
+   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. */
 
 /* BFD backend for PDP-11, running 2.11BSD in particular.
 
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
    * support for overlay object files (see 2.11 a.out(5))
    * support for old and very old archives
    (see 2.11 ar(5), historical section)
-   
+
    Search for TODO to find other areas needing more work.  */
 
 #define        BYTES_IN_WORD   2
@@ -41,7 +41,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 #define        DEFAULT_ARCH    bfd_arch_pdp11
 #define        DEFAULT_MID     M_PDP11
 
-#define MY(OP) CAT(pdp11_aout_,OP)
+/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
+   remove whitespace added here, and thus will fail to concatenate
+   the tokens.  */
+#define MY(OP) CONCAT2 (pdp11_aout_,OP)
+
 /* This needs to start with a.out so GDB knows it is an a.out variant.  */
 #define TARGETNAME "a.out-pdp11"
 
@@ -176,7 +180,7 @@ const bfd_target MY(vec) =
 
   /* Alternative_target */
   NULL,
-  
+
   (PTR) MY_backend_data,
 };
 
@@ -304,9 +308,9 @@ DESCRIPTION
 #define KEEPIT udata.i
 
 #include <string.h>            /* For strchr and friends */
-#include <ctype.h>
 #include "bfd.h"
 #include "sysdep.h"
+#include "safe-ctype.h"
 #include "bfdlink.h"
 
 #include "libaout.h"
@@ -363,6 +367,12 @@ static void adjust_o_magic PARAMS ((bfd *, struct internal_exec *));
 static void adjust_z_magic PARAMS ((bfd *, struct internal_exec *));
 static void adjust_n_magic PARAMS ((bfd *, struct internal_exec *));
 
+static int pdp11_aout_write_headers PARAMS ((bfd *, struct internal_exec *));
+void pdp11_aout_swap_reloc_out PARAMS  ((bfd *, arelent *, struct pdp11_aout_reloc_external *));
+void pdp11_aout_swap_reloc_in
+PARAMS ((bfd *, struct pdp11_aout_reloc_external *, arelent *,
+        bfd_size_type, asymbol **, bfd_size_type));
+
 /*
 SUBSECTION
        Relocations
@@ -443,7 +453,7 @@ pdp11_aout_write_headers (abfd, execp)
   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
     return false;
 
-  if (bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
+  if (bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, abfd)
       != EXEC_BYTES_SIZE)
     return false;
 
@@ -452,28 +462,29 @@ pdp11_aout_write_headers (abfd, execp)
   if (bfd_get_outsymbols (abfd) != (asymbol **) NULL
       && bfd_get_symcount (abfd) != 0)
     {
-      if (bfd_seek (abfd, (file_ptr)(N_SYMOFF(*execp)), SEEK_SET) != 0)
+      if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0)
        return false;
 
-      if (! NAME(aout,write_syms)(abfd)) return false;
+      if (! NAME(aout,write_syms) (abfd))
+       return false;
     }
 
   if (obj_textsec (abfd)->reloc_count > 0 ||
       obj_datasec (abfd)->reloc_count > 0)
     {
-      if (bfd_seek (abfd, (file_ptr)(N_TRELOFF(*execp)), SEEK_SET) != 0)
+      if (bfd_seek (abfd, (file_ptr) (N_TRELOFF(*execp)), SEEK_SET) != 0)
        return false;
       if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd)))
        return false;
 
-      if (bfd_seek (abfd, (file_ptr)(N_DRELOFF(*execp)), SEEK_SET) != 0)
+      if (bfd_seek (abfd, (file_ptr) (N_DRELOFF(*execp)), SEEK_SET) != 0)
        return false;
-      if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd)))
+      if (!NAME(aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))
        return false;
     }
 
   return true;
-}                                                                            
+}
 
 /* Write an object file.
    Section contents have already been written.  We write the
@@ -652,8 +663,9 @@ NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
 {
   struct aout_data_struct *rawptr, *oldrawptr;
   const bfd_target *result;
+  bfd_size_type amt = sizeof (struct aout_data_struct);
 
-  rawptr = (struct aout_data_struct  *) bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
+  rawptr = (struct aout_data_struct  *) bfd_zalloc (abfd, amt);
   if (rawptr == NULL)
     return 0;
 
@@ -868,11 +880,12 @@ NAME(aout,mkobject) (abfd)
      bfd *abfd;
 {
   struct aout_data_struct  *rawptr;
+  bfd_size_type amt = sizeof (struct aout_data_struct);
 
   bfd_set_error (bfd_error_system_call);
 
   /* Use an intermediate variable for clarity */
-  rawptr = (struct aout_data_struct *)bfd_zalloc (abfd, sizeof (struct aout_data_struct ));
+  rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
 
   if (rawptr == NULL)
     return false;
@@ -991,7 +1004,7 @@ NAME(aout,machine_type) (arch, machine, unknown)
     case bfd_arch_vax:
       *unknown = false;
       break;
+
     default:
       arch_flags = M_UNKNOWN;
     }
@@ -1091,7 +1104,7 @@ adjust_o_magic (abfd, execp)
     }
   else
     {
-      /* The VMA of the .bss section is set by the the VMA of the
+      /* 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;
@@ -1117,9 +1130,9 @@ adjust_z_magic (abfd, execp)
 {
   bfd_size_type data_pad, text_pad;
   file_ptr text_end;
-  CONST struct aout_backend_data *abdp;
+  const struct aout_backend_data *abdp;
   int ztih;                    /* Nonzero if text includes exec header.  */
-  
+
   abdp = aout_backend_info (abfd);
 
   /* Text.  */
@@ -1188,7 +1201,7 @@ adjust_z_magic (abfd, execp)
     }
   obj_datasec (abfd)->filepos = (obj_textsec (abfd)->filepos
                                + obj_textsec (abfd)->_raw_size);
-  
+
   /* Fix up exec header while we're at it.  */
   execp->a_text = obj_textsec(abfd)->_raw_size;
   if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
@@ -1233,7 +1246,7 @@ adjust_n_magic (abfd, execp)
   file_ptr pos = adata(abfd).exec_bytes_size;
   bfd_vma vma = 0;
   int pad;
-  
+
   /* Text.  */
   obj_textsec(abfd)->filepos = pos;
   if (!obj_textsec(abfd)->user_set_vma)
@@ -1248,7 +1261,7 @@ adjust_n_magic (abfd, execp)
   if (!obj_datasec(abfd)->user_set_vma)
     obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
   vma = obj_datasec(abfd)->vma;
-  
+
   /* Since BSS follows data immediately, see if it needs alignment.  */
   vma += obj_datasec(abfd)->_raw_size;
   pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
@@ -1445,7 +1458,7 @@ NAME(aout,set_section_contents) (abfd, section, location, offset, count)
   if (count != 0)
     {
       if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
-         || bfd_write (location, 1, count, abfd) != count)
+         || bfd_bwrite (location, count, abfd) != count)
        return false;
     }
 
@@ -1475,13 +1488,12 @@ aout_get_external_symbols (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 = ((struct external_nlist *)
-             bfd_malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
+      syms = (struct external_nlist *) bfd_malloc (count * EXTERNAL_NLIST_SIZE);
       if (syms == (struct external_nlist *) NULL && count != 0)
        return false;
 
       if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
-         || (bfd_read (syms, 1, exec_hdr (abfd)->a_syms, abfd)
+         || (bfd_bread (syms, exec_hdr (abfd)->a_syms, abfd)
              != exec_hdr (abfd)->a_syms))
        {
          free (syms);
@@ -1492,7 +1504,7 @@ aout_get_external_symbols (abfd)
       obj_aout_external_syms (abfd) = syms;
       obj_aout_external_sym_count (abfd) = count;
     }
-      
+
   if (obj_aout_external_strings (abfd) == NULL
       && exec_hdr (abfd)->a_syms != 0)
     {
@@ -1502,10 +1514,10 @@ aout_get_external_symbols (abfd)
 
       /* Get the size of the strings.  */
       if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
-         || (bfd_read ((PTR) string_chars, BYTES_IN_LONG, 1, abfd) !=
-             BYTES_IN_LONG))
+         || (bfd_bread ((PTR) string_chars, (bfd_size_type) BYTES_IN_LONG,
+                       abfd) != BYTES_IN_LONG))
        return false;
-      stringsize = bfd_h_get_32 (abfd, string_chars);
+      stringsize = H_GET_32 (abfd, string_chars);
 
 #ifdef USE_MMAP
       if (bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
@@ -1513,13 +1525,13 @@ aout_get_external_symbols (abfd)
        return false;
       strings = (char *) obj_aout_string_window (abfd).data;
 #else
-      strings = (char *) bfd_malloc ((size_t) stringsize + 1);
+      strings = (char *) bfd_malloc (stringsize + 1);
       if (strings == NULL)
        return false;
 
       /* Skip space for the string count in the buffer for convenience
         when using indexes.  */
-      if (bfd_read (strings + 4, 1, stringsize - 4, abfd) != stringsize - 4)
+      if (bfd_bread (strings + 4, stringsize - 4, abfd) != stringsize - 4)
        {
          free (strings);
          return false;
@@ -1659,7 +1671,7 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
         file.  */
       (*_bfd_error_handler)
        ("%s: can not represent section for symbol `%s' in a.out object file format",
-        bfd_get_filename (abfd), 
+        bfd_archive_filename (abfd),
         cache_ptr->name != NULL ? cache_ptr->name : "*unknown*");
       bfd_set_error (bfd_error_nonrepresentable_section);
       return false;
@@ -1687,7 +1699,7 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
     {
       (*_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_archive_filename (abfd), bfd_get_section_name (abfd, sec));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return false;
     }
@@ -1746,8 +1758,8 @@ asymbol *
 NAME(aout,make_empty_symbol) (abfd)
      bfd *abfd;
 {
-  aout_symbol_type  *new =
-    (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));
+  bfd_size_type amt = sizeof (aout_symbol_type);
+  aout_symbol_type *new = (aout_symbol_type *) bfd_zalloc (abfd, amt);
   if (!new)
     return NULL;
   new->symbol.the_bfd = abfd;
@@ -1793,7 +1805,7 @@ NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
       /* TODO: is 0 a safe value here? */
       in->desc = 0;
       in->other = 0;
-      in->type = bfd_h_get_8 (abfd,  ext->e_type);
+      in->type = H_GET_8 (abfd,  ext->e_type);
       in->symbol.udata.p = NULL;
 
       if (! translate_from_native_sym_flags (abfd, in))
@@ -1816,7 +1828,7 @@ NAME(aout,slurp_symbol_table) (abfd)
 {
   struct external_nlist *old_external_syms;
   aout_symbol_type *cached;
-  size_t cached_size;
+  bfd_size_type cached_size;
 
   /* If there's no work to be done, don't do any */
   if (obj_aout_symbols (abfd) != (aout_symbol_type *) NULL)
@@ -1827,13 +1839,13 @@ NAME(aout,slurp_symbol_table) (abfd)
   if (! aout_get_external_symbols (abfd))
     return false;
 
-  cached_size = (obj_aout_external_sym_count (abfd)
-                * sizeof (aout_symbol_type));
+  cached_size = obj_aout_external_sym_count (abfd);
+  cached_size *= sizeof (aout_symbol_type);
   cached = (aout_symbol_type *) bfd_malloc (cached_size);
   if (cached == NULL && cached_size != 0)
     return false;
   if (cached_size != 0)
-    memset (cached, 0, cached_size);
+    memset (cached, 0, (size_t) cached_size);
 
   /* Convert from external symbol information to internal.  */
   if (! (NAME(aout,translate_symbol_table)
@@ -1929,8 +1941,9 @@ emit_stringtab (abfd, tab)
   bfd_byte buffer[BYTES_IN_LONG];
 
   /* The string table starts with the size.  */
-  bfd_h_put_32 (abfd, _bfd_stringtab_size (tab) + BYTES_IN_LONG, buffer);
-  if (bfd_write ((PTR) buffer, 1, BYTES_IN_LONG, abfd) != BYTES_IN_LONG)
+  H_PUT_32 (abfd, _bfd_stringtab_size (tab) + BYTES_IN_LONG, buffer);
+  if (bfd_bwrite ((PTR) buffer, (bfd_size_type) BYTES_IN_LONG, abfd)
+      != BYTES_IN_LONG)
     return false;
 
   return _bfd_stringtab_emit (abfd, tab);
@@ -1954,24 +1967,24 @@ NAME(aout,write_syms) (abfd)
       bfd_size_type indx;
       struct external_nlist nsp;
 
-      PUT_WORD (abfd, 0, (bfd_byte *)nsp.e_unused);
+      PUT_WORD (abfd, 0, nsp.e_unused);
 
       indx = add_to_stringtab (abfd, strtab, g->name, false);
       if (indx == (bfd_size_type) -1)
        goto error_return;
-      PUT_WORD (abfd, indx, (bfd_byte *) nsp.e_strx);
+      PUT_WORD (abfd, indx, nsp.e_strx);
 
       if (bfd_asymbol_flavour(g) == abfd->xvec->flavour)
-       bfd_h_put_8 (abfd, aout_symbol(g)->type,  nsp.e_type);
+       H_PUT_8 (abfd, aout_symbol(g)->type,  nsp.e_type);
       else
-       bfd_h_put_8 (abfd, 0, nsp.e_type);
+       H_PUT_8 (abfd, 0, nsp.e_type);
 
       if (! translate_to_native_sym_flags (abfd, g, &nsp))
        goto error_return;
 
-      bfd_h_put_8 (abfd, 0, nsp.e_ovly);
+      H_PUT_8 (abfd, 0, nsp.e_ovly);
 
-      if (bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd)
+      if (bfd_bwrite ((PTR)&nsp, (bfd_size_type) EXTERNAL_NLIST_SIZE, abfd)
          != EXTERNAL_NLIST_SIZE)
        goto error_return;
 
@@ -2129,7 +2142,7 @@ pdp11_aout_swap_reloc_out (abfd, g, natptr)
          cache_ptr->addend = ad;                                       \
          break;                                                        \
        }                                                               \
-    }                                                                  
+    }
 
 void
 pdp11_aout_swap_reloc_in (abfd, bytes, cache_ptr, offset,
@@ -2183,7 +2196,7 @@ NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
      asymbol **symbols;
 {
   struct pdp11_aout_reloc_external *rptr;
-  unsigned int count;
+  bfd_size_type count;
   bfd_size_type reloc_size;
   PTR relocs;
   arelent *reloc_cache;
@@ -2214,11 +2227,11 @@ NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
 
   each_size = obj_reloc_entry_size (abfd);
 
-  relocs = bfd_malloc ((size_t) reloc_size);
+  relocs = bfd_malloc (reloc_size);
   if (relocs == NULL && reloc_size != 0)
     return false;
 
-  if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size)
+  if (bfd_bread (relocs, reloc_size, abfd) != reloc_size)
     {
       free (relocs);
       return false;
@@ -2242,10 +2255,10 @@ NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
     count = real_count;
   }
 
-  reloc_cache = (arelent *) bfd_malloc ((size_t) (count * sizeof (arelent)));
+  reloc_cache = (arelent *) bfd_malloc (count * sizeof (arelent));
   if (reloc_cache == NULL && count != 0)
     return false;
-  memset (reloc_cache, 0, count * sizeof (arelent));
+  memset (reloc_cache, 0, (size_t) count * sizeof (arelent));
 
   cache_ptr = reloc_cache;
 
@@ -2258,14 +2271,15 @@ NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
        {
          rptr =
            (struct pdp11_aout_reloc_external *)
-           ((char *)rptr + RELOC_SIZE);
-         if ((char *)rptr >= (char *)relocs + reloc_size)
+           ((char *) rptr + RELOC_SIZE);
+         if ((char *) rptr >= (char *) relocs + reloc_size)
            goto done;
        }
 
       pdp11_aout_swap_reloc_in (abfd, rptr, cache_ptr,
-                               (char *)rptr - (char *)relocs,
-                                   symbols, bfd_get_symcount (abfd));
+                               (bfd_size_type) ((char *) rptr - (char *) relocs),
+                               symbols,
+                               (bfd_size_type) bfd_get_symcount (abfd));
     }
  done:
   /* Just in case, if rptr >= relocs + reloc_size should happen
@@ -2290,7 +2304,7 @@ NAME(aout,squirt_out_relocs) (abfd, section)
   arelent **generic;
   unsigned char *native;
   unsigned int count = section->reloc_count;
-  size_t natsize;
+  bfd_size_type natsize;
 
 #if 0
   /* If we're writing an .o file, we must write
@@ -2305,7 +2319,7 @@ NAME(aout,squirt_out_relocs) (abfd, section)
   if (!native)
     return false;
 
-  memset ((PTR)native, 0, natsize);
+  memset ((PTR)native, 0, (size_t) natsize);
 
   generic = section->orelocation;
   if (generic != NULL)
@@ -2322,14 +2336,13 @@ NAME(aout,squirt_out_relocs) (abfd, section)
        }
     }
 
-  if (bfd_write ((PTR) native, 1, natsize, abfd) != natsize)
+  if (bfd_bwrite ((PTR) native, natsize, abfd) != natsize)
     {
-      bfd_release(abfd, native);
+      bfd_release (abfd, native);
       return false;
     }
 
   bfd_release (abfd, native);
-
   return true;
 }
 
@@ -2387,7 +2400,7 @@ NAME(aout,get_reloc_upper_bound) (abfd, asect)
       return -1;
     }
 
-  if (asect->flags & SEC_CONSTRUCTOR) 
+  if (asect->flags & SEC_CONSTRUCTOR)
     return (sizeof (arelent *) * (asect->reloc_count+1));
 
   if (asect == obj_datasec (abfd))
@@ -2481,7 +2494,7 @@ NAME(aout,print_symbol) (abfd, afile, symbol, how)
       break;
     case bfd_print_symbol_all:
       {
-       CONST char *section_name = symbol->section->name;
+       const char *section_name = symbol->section->name;
 
        bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
 
@@ -2582,16 +2595,16 @@ NAME(aout,find_nearest_line)
      asection *section;
      asymbol **symbols;
      bfd_vma offset;
-     CONST char **filename_ptr;
-     CONST char **functionname_ptr;
+     const char **filename_ptr;
+     const char **functionname_ptr;
      unsigned int *line_ptr;
 {
   /* Run down the file looking for the filename, function and linenumber */
   asymbol **p;
-  CONST char *directory_name = NULL;
-  CONST char *main_file_name = NULL;
-  CONST char *current_file_name = NULL;
-  CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */
+  const char *directory_name = NULL;
+  const char *main_file_name = NULL;
+  const char *current_file_name = NULL;
+  const char *line_file_name = NULL; /* Value of current_file_name at line number. */
   bfd_vma low_line_vma = 0;
   bfd_vma low_func_vma = 0;
   asymbol *func = 0;
@@ -2724,7 +2737,7 @@ NAME(aout,find_nearest_line)
     adata (abfd).line_buf = buf = NULL;
   else
     {
-      buf = (char *) bfd_malloc (filelen + funclen + 3);
+      buf = (char *) bfd_malloc ((bfd_size_type) filelen + funclen + 3);
       adata (abfd).line_buf = buf;
       if (buf == NULL)
        return false;
@@ -2745,7 +2758,7 @@ NAME(aout,find_nearest_line)
   if (func)
     {
       const char *function = func->name;
-      char *p;
+      char *colon;
 
       /* The caller expects a symbol name.  We actually have a
         function name, without the leading underscore.  Put the
@@ -2759,9 +2772,9 @@ NAME(aout,find_nearest_line)
        }
 
       /* Have to remove : stuff.  */
-      p = strchr (buf, ':');
-      if (p != NULL)
-       *p = '\0';
+      colon = strchr (buf, ':');
+      if (colon != NULL)
+       *colon = '\0';
       *functionname_ptr = buf;
     }
 
@@ -2870,9 +2883,9 @@ NAME(aout,link_hash_table_create) (abfd)
      bfd *abfd;
 {
   struct aout_link_hash_table *ret;
+  bfd_size_type amt = sizeof (struct aout_link_hash_table);
 
-  ret = ((struct aout_link_hash_table *)
-        bfd_alloc (abfd, sizeof (struct aout_link_hash_table)));
+  ret = ((struct aout_link_hash_table *) bfd_alloc (abfd, amt));
   if (ret == NULL)
     return (struct bfd_link_hash_table *) NULL;
   if (! NAME(aout,link_hash_table_init) (ret, abfd,
@@ -3008,7 +3021,7 @@ aout_link_check_ar_symbols (abfd, info, pneeded)
   strings = obj_aout_external_strings (abfd);
   for (; p < pend; p++)
     {
-      int type = bfd_h_get_8 (abfd, p->e_type);
+      int type = H_GET_8 (abfd, p->e_type);
       const char *name;
       struct bfd_link_hash_entry *h;
 
@@ -3162,8 +3175,7 @@ aout_link_add_symbols (abfd, info)
      should be conditional on info->keep_memory.  */
   sym_hash = ((struct aout_link_hash_entry **)
              bfd_alloc (abfd,
-                        ((size_t) sym_count
-                         * sizeof (struct aout_link_hash_entry *))));
+                        sym_count * sizeof (struct aout_link_hash_entry *)));
   if (sym_hash == NULL && sym_count != 0)
     return false;
   obj_aout_sym_hashes (abfd) = sym_hash;
@@ -3185,7 +3197,7 @@ aout_link_add_symbols (abfd, info)
 
       *sym_hash = NULL;
 
-      type = bfd_h_get_8 (abfd, p->e_type);
+      type = H_GET_8 (abfd, p->e_type);
 
 #if 0 /* not supported in PDP-11 a.out */
       /* Ignore debugging symbols.  */
@@ -3401,9 +3413,9 @@ NAME(aout,final_link) (abfd, info, callback)
   boolean includes_hash_initialized = false;
   register bfd *sub;
   bfd_size_type trsize, drsize;
-  size_t max_contents_size;
-  size_t max_relocs_size;
-  size_t max_sym_count;
+  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;
   register struct bfd_link_order *p;
@@ -3707,11 +3719,11 @@ NAME(aout,final_link) (abfd, info, callback)
 
       b = 0;
       if (bfd_seek (abfd,
-                   (obj_datasec (abfd)->filepos
-                    + exec_hdr (abfd)->a_data
-                    - 1),
+                   (file_ptr) (obj_datasec (abfd)->filepos
+                               + exec_hdr (abfd)->a_data
+                               - 1),
                    SEEK_SET) != 0
-         || bfd_write (&b, 1, 1, abfd) != 1)
+         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
        goto error_return;
     }
 
@@ -3832,7 +3844,7 @@ aout_link_write_symbols (finfo, input_bfd)
                              false, false) != NULL)
       && discard != discard_all)
     {
-      bfd_h_put_8 (output_bfd, N_TEXT, outsym->e_type);
+      H_PUT_8 (output_bfd, N_TEXT, outsym->e_type);
       strtab_index = add_to_stringtab (output_bfd, finfo->strtab,
                                       input_bfd->filename, false);
       if (strtab_index == (bfd_size_type) -1)
@@ -3853,7 +3865,7 @@ aout_link_write_symbols (finfo, input_bfd)
   sym_end = sym + sym_count;
   sym_hash = obj_aout_sym_hashes (input_bfd);
   symbol_map = finfo->symbol_map;
-  memset (symbol_map, 0, sym_count * sizeof *symbol_map);
+  memset (symbol_map, 0, (size_t) sym_count * sizeof *symbol_map);
   for (; sym < sym_end; sym++, sym_hash++, symbol_map++)
     {
       const char *name;
@@ -3876,7 +3888,7 @@ aout_link_write_symbols (finfo, input_bfd)
          we do copy the symbol over.  */
       *symbol_map = -1;
 
-      type = bfd_h_get_8 (input_bfd, sym->e_type);
+      type = H_GET_8 (input_bfd, sym->e_type);
       name = strings + GET_WORD (input_bfd, sym->e_strx);
 
       h = NULL;
@@ -4147,7 +4159,7 @@ aout_link_write_symbols (finfo, input_bfd)
                {
                  int incl_type;
 
-                 incl_type = bfd_h_get_8 (input_bfd, incl_sym->e_type);
+                 incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
                  if (incl_type == N_EINCL)
                    {
                      if (nest == 0)
@@ -4168,7 +4180,7 @@ aout_link_write_symbols (finfo, input_bfd)
                            {
                              /* Skip the file number.  */
                              ++s;
-                             while (isdigit ((unsigned char) *s))
+                             while (ISDIGIT (*s))
                                ++s;
                              --s;
                            }
@@ -4216,7 +4228,7 @@ aout_link_write_symbols (finfo, input_bfd)
                    {
                      int incl_type;
 
-                     incl_type = bfd_h_get_8 (input_bfd, incl_sym->e_type);
+                     incl_type = H_GET_8 (input_bfd, incl_sym->e_type);
                      if (incl_type == N_EINCL)
                        {
                          if (nest == 0)
@@ -4237,7 +4249,7 @@ aout_link_write_symbols (finfo, input_bfd)
 
       /* Copy this symbol into the list of symbols we are going to
         write out.  */
-      bfd_h_put_8 (output_bfd, type, outsym->e_type);
+      H_PUT_8 (output_bfd, type, outsym->e_type);
       copy = false;
       if (! finfo->info->keep_memory)
        {
@@ -4263,17 +4275,15 @@ aout_link_write_symbols (finfo, input_bfd)
   /* Write out the output symbols we have just constructed.  */
   if (outsym > finfo->output_syms)
     {
-      bfd_size_type outsym_count;
+      bfd_size_type size;
 
       if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0)
        return false;
-      outsym_count = outsym - finfo->output_syms;
-      if (bfd_write ((PTR) finfo->output_syms,
-                    (bfd_size_type) EXTERNAL_NLIST_SIZE,
-                    (bfd_size_type) outsym_count, output_bfd)
-         != outsym_count * EXTERNAL_NLIST_SIZE)
+      size = outsym - finfo->output_syms;
+      size *= EXTERNAL_NLIST_SIZE;
+      if (bfd_bwrite ((PTR) finfo->output_syms, size, output_bfd) != size)
        return false;
-      finfo->symoff += outsym_count * EXTERNAL_NLIST_SIZE;
+      finfo->symoff += size;
     }
 
   return true;
@@ -4293,6 +4303,7 @@ aout_link_write_other_symbol (h, data)
   bfd_vma val;
   struct external_nlist outsym;
   bfd_size_type indx;
+  bfd_size_type amt;
 
   output_bfd = finfo->output_bfd;
 
@@ -4369,7 +4380,7 @@ aout_link_write_other_symbol (h, data)
       return true;
     }
 
-  bfd_h_put_8 (output_bfd, type, outsym.e_type);
+  H_PUT_8 (output_bfd, type, outsym.e_type);
   indx = add_to_stringtab (output_bfd, finfo->strtab, h->root.root.string,
                           false);
   if (indx == (bfd_size_type) -1)
@@ -4380,15 +4391,15 @@ aout_link_write_other_symbol (h, data)
   PUT_WORD (output_bfd, indx, outsym.e_strx);
   PUT_WORD (output_bfd, val, outsym.e_value);
 
+  amt = EXTERNAL_NLIST_SIZE;
   if (bfd_seek (output_bfd, finfo->symoff, SEEK_SET) != 0
-      || bfd_write ((PTR) &outsym, (bfd_size_type) EXTERNAL_NLIST_SIZE,
-                   (bfd_size_type) 1, output_bfd) != EXTERNAL_NLIST_SIZE)
+      || bfd_bwrite ((PTR) &outsym, amt, output_bfd) != amt)
     {
       /* FIXME: No way to handle errors.  */
       abort ();
     }
 
-  finfo->symoff += EXTERNAL_NLIST_SIZE;
+  finfo->symoff += amt;
   h->indx = obj_aout_external_sym_count (output_bfd);
   ++obj_aout_external_sym_count (output_bfd);
 
@@ -4426,7 +4437,7 @@ aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
       if (rel_size > 0)
        {
          if (bfd_seek (input_bfd, input_section->rel_filepos, SEEK_SET) != 0
-             || bfd_read (relocs, 1, rel_size, input_bfd) != rel_size)
+             || bfd_bread (relocs, rel_size, input_bfd) != rel_size)
            return false;
        }
     }
@@ -4441,7 +4452,7 @@ aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
   if (! bfd_set_section_contents (finfo->output_bfd,
                                  input_section->output_section,
                                  (PTR) finfo->contents,
-                                 input_section->output_offset,
+                                 (file_ptr) input_section->output_offset,
                                  input_size))
     return false;
 
@@ -4451,8 +4462,7 @@ aout_link_input_section (finfo, input_bfd, input_section, reloff_ptr,
     {
       if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0)
        return false;
-      if (bfd_write (relocs, (bfd_size_type) 1, rel_size, finfo->output_bfd)
-         != rel_size)
+      if (bfd_bwrite (relocs, rel_size, finfo->output_bfd) != rel_size)
        return false;
       *reloff_ptr += rel_size;
 
@@ -4812,6 +4822,7 @@ aout_link_reloc_link_order (finfo, o, p)
   file_ptr *reloff_ptr;
   struct reloc_std_external srel;
   PTR rel_ptr;
+  bfd_size_type rel_size;
 
   pr = p->u.reloc.p;
 
@@ -4973,14 +4984,12 @@ aout_link_reloc_link_order (finfo, o, p)
        return false;
     }
 
+  rel_size = obj_reloc_entry_size (finfo->output_bfd);
   if (bfd_seek (finfo->output_bfd, *reloff_ptr, SEEK_SET) != 0
-      || (bfd_write (rel_ptr, (bfd_size_type) 1,
-                    obj_reloc_entry_size (finfo->output_bfd),
-                    finfo->output_bfd)
-         != obj_reloc_entry_size (finfo->output_bfd)))
+      || bfd_bwrite (rel_ptr, rel_size, finfo->output_bfd) != rel_size)
     return false;
 
-  *reloff_ptr += obj_reloc_entry_size (finfo->output_bfd);
+  *reloff_ptr += rel_size;
 
   /* Assert that the relocs have not run into the symbols, and that n
      the text relocs have not run into the data relocs.  */