Automatic date update in version.in
[deliverable/binutils-gdb.git] / bfd / vms-alpha.c
index 6d2eb45cbc78d1ced9f4e5ba8fb7bf169081b4ad..41cc94440b348be818b5c59f47b8e82eb50319bc 100644 (file)
@@ -1,5 +1,5 @@
 /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files.
-   Copyright (C) 1996-2018 Free Software Foundation, Inc.
+   Copyright (C) 1996-2021 Free Software Foundation, Inc.
 
    Initial version written by Klaus Kaempf (kkaempf@rmi.de)
    Major rewrite by Adacore.
@@ -34,6 +34,7 @@
 */
 
 #include "sysdep.h"
+#include <limits.h>
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
@@ -71,6 +72,9 @@
 \f
 
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
+#ifndef CHAR_BIT
+#define CHAR_BIT 8
+#endif
 
 /* The r_type field in a reloc is one of the following values.  */
 #define ALPHA_R_IGNORE         0
@@ -151,7 +155,7 @@ struct eom_struct
 {
   unsigned int eom_l_total_lps;
   unsigned short eom_w_comcod;
-  bfd_boolean eom_has_transfer;
+  bool eom_has_transfer;
   unsigned char eom_b_tfrflg;
   unsigned int eom_l_psindx;
   unsigned int eom_l_tfradr;
@@ -263,7 +267,7 @@ struct module
 struct vms_private_data_struct
 {
   /* If true, relocs have been read.  */
-  bfd_boolean reloc_done;
+  bool reloc_done;
 
   /* Record input buffer.  */
   struct vms_rec_rd recrd;
@@ -367,15 +371,15 @@ struct vms_section_data_struct
 struct vms_private_data_struct *bfd_vms_get_data (bfd *);
 
 static int vms_get_remaining_object_record (bfd *, unsigned int);
-static bfd_boolean _bfd_vms_slurp_object_records (bfd * abfd);
-static void alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *);
-static void alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *);
-static void alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *,
+static bool _bfd_vms_slurp_object_records (bfd * abfd);
+static bool alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *);
+static bool alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *);
+static bool alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *,
                                    bfd_vma);
-static void alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int,
+static bool alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int,
                                    bfd_vma);
-static void alpha_vms_add_lw_reloc (struct bfd_link_info *);
-static void alpha_vms_add_qw_reloc (struct bfd_link_info *);
+static bool alpha_vms_add_lw_reloc (struct bfd_link_info *);
+static bool alpha_vms_add_qw_reloc (struct bfd_link_info *);
 
 struct vector_type
 {
@@ -401,17 +405,12 @@ struct vector_type
 
 /* Be sure there is room for a new element.  */
 
-static void vector_grow1 (struct vector_type *vec, size_t elsz);
+static void *vector_grow1 (struct vector_type *vec, size_t elsz);
 
 /* Allocate room for a new element and return its address.  */
 
 #define VEC_APPEND(VEC, TYPE)                                  \
-  (vector_grow1 (&VEC, sizeof (TYPE)), &VEC_EL(VEC, TYPE, (VEC).nbr_el++))
-
-/* Append an element.  */
-
-#define VEC_APPEND_EL(VEC, TYPE, EL)           \
-  (*(VEC_APPEND (VEC, TYPE)) = EL)
+  ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE)))
 
 struct alpha_vms_vma_ref
 {
@@ -422,7 +421,7 @@ struct alpha_vms_vma_ref
 struct alpha_vms_shlib_el
 {
   bfd *abfd;
-  bfd_boolean has_fixups;
+  bool has_fixups;
 
   struct vector_type lp;       /* Vector of bfd_vma.  */
   struct vector_type ca;       /* Vector of bfd_vma.  */
@@ -463,7 +462,7 @@ struct alpha_vms_link_hash_entry
 /* Read & process EIHD record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
                     unsigned int *eihs_offset)
 {
@@ -476,9 +475,9 @@ _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
   /* PR 21813: Check for an undersized record.  */
   if (PRIV (recrd.buf_size) < sizeof (* eihd))
     {
-      _bfd_error_handler (_("Corrupt EIHD record - size is too small"));
+      _bfd_error_handler (_("corrupt EIHD record - size is too small"));
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
   size = bfd_getl32 (eihd->size);
@@ -503,14 +502,15 @@ _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
   vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
               size, imgtype, (unsigned long)symvva,
               *eisd_offset, *eihs_offset));
+  (void) size;
 
-  return TRUE;
+  return true;
 }
 
 /* Read & process EISD record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
 {
   int section_count = 0;
@@ -529,12 +529,12 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
       asection *section;
       flagword bfd_flags;
 
-      /* PR 17512: file: 3d9e9fe9.
-        12 is the offset of the eisdsize field from the start of the record (8)
-        plus the size of the eisdsize field (4).  */
-      if (offset >= PRIV (recrd.rec_size) - 12)
-       return FALSE;
-      eisd = (struct vms_eisd *)(PRIV (recrd.rec) + offset);
+      /* PR 17512: file: 3d9e9fe9.  */
+      if (offset > PRIV (recrd.rec_size)
+         || (PRIV (recrd.rec_size) - offset
+             < offsetof (struct vms_eisd, eisdsize) + 4))
+       return false;
+      eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset);
       rec_size = bfd_getl32 (eisd->eisdsize);
       if (rec_size == 0)
        break;
@@ -547,12 +547,11 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
        }
 
       /* Make sure that there is enough data present in the record.  */
-      /* FIXME: Should we use sizeof (struct vms_eisd) rather than just 32 here ?  */
-      if (rec_size < 32)
-       return FALSE;
+      if (rec_size < offsetof (struct vms_eisd, type) + 1)
+       return false;
       /* Make sure that the record is not too big either.  */
-      if (offset + rec_size >= PRIV (recrd.rec_size))
-       return FALSE;
+      if (rec_size > PRIV (recrd.rec_size) - offset)
+       return false;
 
       offset += rec_size;
 
@@ -592,13 +591,16 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
 
       if (flags & EISD__M_GBL)
        {
-         if (rec_size < offsetof (struct vms_eisd, gblnam))
-           return FALSE;
+         if (rec_size <= offsetof (struct vms_eisd, gblnam))
+           return false;
          else if (rec_size < sizeof (struct vms_eisd))
-           name = _bfd_vms_save_counted_string (eisd->gblnam,
+           name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
                                                 rec_size - offsetof (struct vms_eisd, gblnam));
          else
-           name = _bfd_vms_save_counted_string (eisd->gblnam, EISD__K_GBLNAMLEN);
+           name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
+                                                EISD__K_GBLNAMLEN);
+         if (name == NULL || name[0] == 0)
+           return false;
          bfd_flags |= SEC_COFF_SHARED_LIBRARY;
          bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
        }
@@ -610,7 +612,9 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
        {
          const char *pfx;
 
-         name = (char*) bfd_alloc (abfd, 32);
+         name = (char *) bfd_alloc (abfd, 32);
+         if (name == NULL)
+           return false;
          if (flags & EISD__M_DZRO)
            pfx = "BSS";
          else if (flags & EISD__M_EXE)
@@ -626,23 +630,23 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
       section = bfd_make_section (abfd, name);
 
       if (!section)
-       return FALSE;
+       return false;
 
       section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
       section->size = size;
       section->vma = vaddr;
 
-      if (!bfd_set_section_flags (abfd, section, bfd_flags))
-       return FALSE;
+      if (!bfd_set_section_flags (section, bfd_flags))
+       return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Read & process EIHS record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
 {
   unsigned char *p = PRIV (recrd.rec) + offset;
@@ -657,9 +661,10 @@ _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
   /* PR 21611: Check that offset is valid.  */
   if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4))
     {
-      _bfd_error_handler (_("Unable to read EIHS record at offset %#x"), offset);
+      _bfd_error_handler (_("unable to read EIHS record at offset %#x"),
+                         offset);
       bfd_set_error (bfd_error_file_truncated);
-      return FALSE;
+      return false;
     }
 
   gstvbn   = bfd_getl32 (p + EIHS__L_GSTVBN);
@@ -681,13 +686,13 @@ _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
 
       section = bfd_make_section (abfd, "$DST$");
       if (!section)
-       return FALSE;
+       return false;
 
       section->size = dstsize;
       section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
 
-      if (!bfd_set_section_flags (abfd, section, bfd_flags))
-       return FALSE;
+      if (!bfd_set_section_flags (section, bfd_flags))
+       return false;
 
       PRIV (dst_section) = section;
       abfd->flags |= (HAS_DEBUG | HAS_LINENO);
@@ -699,13 +704,13 @@ _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
 
       section = bfd_make_section (abfd, "$DMT$");
       if (!section)
-       return FALSE;
+       return false;
 
       section->size = dmtbytes;
       section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
 
-      if (!bfd_set_section_flags (abfd, section, bfd_flags))
-       return FALSE;
+      if (!bfd_set_section_flags (section, bfd_flags))
+       return false;
     }
 
   if (gstvbn)
@@ -713,16 +718,16 @@ _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
       if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET))
        {
          bfd_set_error (bfd_error_file_truncated);
-         return FALSE;
+         return false;
        }
 
       if (!_bfd_vms_slurp_object_records (abfd))
-       return FALSE;
+       return false;
 
       abfd->flags |= HAS_SYMS;
     }
 
-  return TRUE;
+  return true;
 }
 \f
 /* Object file reading.  */
@@ -860,7 +865,7 @@ vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far)
   if (to_read > PRIV (recrd.buf_size))
     {
       PRIV (recrd.buf)
-       = (unsigned char *) bfd_realloc (PRIV (recrd.buf), to_read);
+       = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read);
       if (PRIV (recrd.buf) == NULL)
        return 0;
       PRIV (recrd.buf_size) = to_read;
@@ -893,7 +898,7 @@ vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far)
 /* Read and process emh record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_ehdr (bfd *abfd)
 {
   unsigned char *ptr;
@@ -923,36 +928,39 @@ _bfd_vms_slurp_ehdr (bfd *abfd)
       PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
       if ((vms_rec + 20 + vms_rec[20] + 1) >= end)
        goto fail;
-      PRIV (hdr_data).hdr_t_name   = _bfd_vms_save_counted_string (vms_rec + 20, vms_rec[20]);
+      PRIV (hdr_data).hdr_t_name
+       = _bfd_vms_save_counted_string (abfd, vms_rec + 20, vms_rec[20]);
       ptr = vms_rec + 20 + vms_rec[20] + 1;
       if ((ptr + *ptr + 1) >= end)
        goto fail;
-      PRIV (hdr_data).hdr_t_version =_bfd_vms_save_counted_string (ptr, *ptr);
+      PRIV (hdr_data).hdr_t_version
+       = _bfd_vms_save_counted_string (abfd, ptr, *ptr);
       ptr += *ptr + 1;
       if (ptr + 17 >= end)
        goto fail;
-      PRIV (hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
+      PRIV (hdr_data).hdr_t_date
+       = _bfd_vms_save_sized_string (abfd, ptr, 17);
       break;
 
     case EMH__C_LNM:
       if (vms_rec + PRIV (recrd.rec_size - 6) > end)
        goto fail;
-      PRIV (hdr_data).hdr_c_lnm =
-       _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
+      PRIV (hdr_data).hdr_c_lnm
+       = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
       break;
 
     case EMH__C_SRC:
       if (vms_rec + PRIV (recrd.rec_size - 6) > end)
        goto fail;
-      PRIV (hdr_data).hdr_c_src =
-       _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
+      PRIV (hdr_data).hdr_c_src
+       = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
       break;
 
     case EMH__C_TTL:
       if (vms_rec + PRIV (recrd.rec_size - 6) > end)
        goto fail;
-      PRIV (hdr_data).hdr_c_ttl =
-       _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
+      PRIV (hdr_data).hdr_c_ttl
+       = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
       break;
 
     case EMH__C_CPR:
@@ -963,10 +971,10 @@ _bfd_vms_slurp_ehdr (bfd *abfd)
     default:
     fail:
       bfd_set_error (bfd_error_wrong_format);
-      return FALSE;
+      return false;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Typical sections for evax object files.  */
@@ -1106,7 +1114,7 @@ vms_esecflag_by_name (const struct sec_flags_struct *section_flags,
 /* Add SYM to the symbol table of ABFD.
    Return FALSE in case of error.  */
 
-static bfd_boolean
+static bool
 add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym)
 {
   if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
@@ -1120,28 +1128,36 @@ add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym)
       else
        {
          PRIV (max_sym_count) *= 2;
-         PRIV (syms) = bfd_realloc
+         PRIV (syms) = bfd_realloc_or_free
            (PRIV (syms),
             (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
        }
       if (PRIV (syms) == NULL)
-       return FALSE;
+       return false;
     }
 
   PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
-  return TRUE;
+  return true;
 }
 
 /* Create a symbol whose name is ASCIC and add it to ABFD.
    Return NULL in case of error.  */
 
 static struct vms_symbol_entry *
-add_symbol (bfd *abfd, const unsigned char *ascic)
+add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max)
 {
   struct vms_symbol_entry *entry;
-  int len;
+  unsigned int len;
 
   len = *ascic++;
+  max -= 1;
+  if (len > max)
+    {
+      _bfd_error_handler (_("record is too small for symbol name length"));
+      bfd_set_error (bfd_error_bad_value);
+      return NULL;
+    }
+
   entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
   if (entry == NULL)
     return NULL;
@@ -1157,29 +1173,30 @@ add_symbol (bfd *abfd, const unsigned char *ascic)
 
 /* Read and process EGSD.  Return FALSE on failure.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_egsd (bfd *abfd)
 {
   int gsd_type;
   unsigned int gsd_size;
   unsigned char *vms_rec;
-  unsigned long base_addr;
+  bfd_vma base_addr;
+  long psindx;
 
   vms_debug2 ((2, "EGSD\n"));
 
   if (PRIV (recrd.rec_size) < 8)
     {
-      _bfd_error_handler (_("Corrupt EGSD record: its size (%#x) is too small"),
+      _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"),
                          PRIV (recrd.rec_size));
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
   PRIV (recrd.rec) += 8;       /* Skip type, size, align pad.  */
   PRIV (recrd.rec_size) -= 8;
 
   /* Calculate base address for each section.  */
-  base_addr = 0L;
+  base_addr = 0;
 
   while (PRIV (recrd.rec_size) > 4)
     {
@@ -1193,18 +1210,21 @@ _bfd_vms_slurp_egsd (bfd *abfd)
       /* PR 21615: Check for size overflow.  */
       if (PRIV (recrd.rec_size) < gsd_size)
        {
-         _bfd_error_handler (_("Corrupt EGSD record: size (%#x) is larger than remaining space (%#x)"),
-                             gsd_size, PRIV (recrd.rec_size));
+         _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
+                               "is larger than remaining space (%#x)"),
+                             gsd_type, gsd_size, PRIV (recrd.rec_size));
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
 
       if (gsd_size < 4)
        {
-         _bfd_error_handler (_("Corrupt EGSD record: size (%#x) is too small"),
-                             gsd_size);
+       too_small:
+         _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
+                               "is too small"),
+                             gsd_type, gsd_size);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
 
       switch (gsd_type)
@@ -1212,10 +1232,12 @@ _bfd_vms_slurp_egsd (bfd *abfd)
        case EGSD__C_PSC:
          /* Program section definition.  */
          {
-           struct vms_egps *egps = (struct vms_egps *)vms_rec;
+           struct vms_egps *egps = (struct vms_egps *) vms_rec;
            flagword new_flags, vms_flags;
            asection *section;
 
+           if (offsetof (struct vms_egps, flags) + 2 > gsd_size)
+             goto too_small;
            vms_flags = bfd_getl16 (egps->flags);
 
            if ((vms_flags & EGPS__V_REL) == 0)
@@ -1227,22 +1249,29 @@ _bfd_vms_slurp_egsd (bfd *abfd)
            else
              {
                char *name;
-               unsigned long align_addr;
+               bfd_vma align_addr;
+               size_t left;
 
-               name = _bfd_vms_save_counted_string (&egps->namlng, gsd_size - 4);
+               if (offsetof (struct vms_egps, namlng) >= gsd_size)
+                 goto too_small;
+               left = gsd_size - offsetof (struct vms_egps, namlng);
+               name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left);
+               if (name == NULL || name[0] == 0)
+                 return false;
 
                section = bfd_make_section (abfd, name);
                if (!section)
-                 return FALSE;
+                 return false;
 
                section->filepos = 0;
                section->size = bfd_getl32 (egps->alloc);
-               section->alignment_power = egps->align;
+               section->alignment_power = egps->align & 31;
 
                vms_section_data (section)->flags = vms_flags;
                vms_section_data (section)->no_flags = 0;
 
-               new_flags = vms_secflag_by_name (evax_section_flags, name,
+               new_flags = vms_secflag_by_name (evax_section_flags,
+                                                section->name,
                                                 section->size > 0);
                if (section->size > 0)
                  new_flags |= SEC_LOAD;
@@ -1260,14 +1289,13 @@ _bfd_vms_slurp_egsd (bfd *abfd)
                    new_flags |= SEC_CODE;
                    new_flags &= ~SEC_DATA;
                  }
-               if (!bfd_set_section_flags (abfd, section, new_flags))
-                 return FALSE;
+               if (!bfd_set_section_flags (section, new_flags))
+                 return false;
 
                /* Give a non-overlapping vma to non absolute sections.  */
-               align_addr = (1 << section->alignment_power);
-               if ((base_addr % align_addr) != 0)
-                 base_addr += (align_addr - (base_addr % align_addr));
-               section->vma = (bfd_vma)base_addr;
+               align_addr = (bfd_vma) 1 << section->alignment_power;
+               base_addr = (base_addr + align_addr - 1) & -align_addr;
+               section->vma = base_addr;
                base_addr += section->size;
              }
 
@@ -1281,7 +1309,7 @@ _bfd_vms_slurp_egsd (bfd *abfd)
                PRIV (sections) = bfd_realloc_or_free
                  (PRIV (sections), PRIV (section_max) * sizeof (asection *));
                if (PRIV (sections) == NULL)
-                 return FALSE;
+                 return false;
              }
 
            PRIV (sections)[PRIV (section_count)] = section;
@@ -1291,20 +1319,24 @@ _bfd_vms_slurp_egsd (bfd *abfd)
 
        case EGSD__C_SYM:
          {
-           int nameoff;
+           unsigned int nameoff;
            struct vms_symbol_entry *entry;
            struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
            flagword old_flags;
 
+           if (offsetof (struct vms_egsy, flags) + 2 > gsd_size)
+             goto too_small;
            old_flags = bfd_getl16 (egsy->flags);
            if (old_flags & EGSY__V_DEF)
              nameoff = ESDF__B_NAMLNG;
            else
              nameoff = ESRF__B_NAMLNG;
 
-           entry = add_symbol (abfd, vms_rec + nameoff);
+           if (nameoff >= gsd_size)
+             goto too_small;
+           entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff);
            if (entry == NULL)
-             return FALSE;
+             return false;
 
            /* Allow only duplicate reference.  */
            if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
@@ -1319,21 +1351,22 @@ _bfd_vms_slurp_egsd (bfd *abfd)
 
            if (old_flags & EGSY__V_DEF)
              {
-               struct vms_esdf *esdf = (struct vms_esdf *)vms_rec;
-               long psindx;
+               struct vms_esdf *esdf = (struct vms_esdf *) vms_rec;
 
                entry->value = bfd_getl64 (esdf->value);
                if (PRIV (sections) == NULL)
-                 return FALSE;
+                 return false;
 
                psindx = bfd_getl32 (esdf->psindx);
                /* PR 21813: Check for an out of range index.  */
                if (psindx < 0 || psindx >= (int) PRIV (section_count))
                  {
-                   _bfd_error_handler (_("Corrupt EGSD record: its psindx field is too big (%#lx)"),
+                 bad_psindx:
+                   _bfd_error_handler (_("corrupt EGSD record: its psindx "
+                                         "field is too big (%#lx)"),
                                        psindx);
                    bfd_set_error (bfd_error_bad_value);
-                   return FALSE;
+                   return false;
                  }
                entry->section = PRIV (sections)[psindx];
 
@@ -1343,14 +1376,9 @@ _bfd_vms_slurp_egsd (bfd *abfd)
 
                    entry->code_value = bfd_getl64 (esdf->code_address);
                    psindx = bfd_getl32 (esdf->ca_psindx);
-               /* PR 21813: Check for an out of range index.  */
+                   /* PR 21813: Check for an out of range index.  */
                    if (psindx < 0 || psindx >= (int) PRIV (section_count))
-                     {
-                       _bfd_error_handler (_("Corrupt EGSD record: its psindx field is too big (%#lx)"),
-                                           psindx);
-                       bfd_set_error (bfd_error_bad_value);
-                       return FALSE;
-                     }
+                     goto bad_psindx;
                    entry->code_section = PRIV (sections)[psindx];
                  }
              }
@@ -1362,14 +1390,15 @@ _bfd_vms_slurp_egsd (bfd *abfd)
            struct vms_symbol_entry *entry;
            struct vms_egst *egst = (struct vms_egst *)vms_rec;
            flagword old_flags;
+           unsigned int nameoff = offsetof (struct vms_egst, namlng);
 
-           old_flags = bfd_getl16 (egst->header.flags);
-
-           entry = add_symbol (abfd, &egst->namlng);
-
+           if (nameoff >= gsd_size)
+             goto too_small;
+           entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff);
            if (entry == NULL)
-             return FALSE;
+             return false;
 
+           old_flags = bfd_getl16 (egst->header.flags);
            entry->typ = gsd_type;
            entry->data_type = egst->header.datyp;
            entry->flags = old_flags;
@@ -1378,19 +1407,12 @@ _bfd_vms_slurp_egsd (bfd *abfd)
 
            if (old_flags & EGSY__V_REL)
              {
-               long psindx;
-
                if (PRIV (sections) == NULL)
-                 return FALSE;
+                 return false;
                psindx = bfd_getl32 (egst->psindx);
                /* PR 21813: Check for an out of range index.  */
                if (psindx < 0 || psindx >= (int) PRIV (section_count))
-                 {
-                   _bfd_error_handler (_("Corrupt EGSD record: its psindx field is too big (%#lx)"),
-                                       psindx);
-                   bfd_set_error (bfd_error_bad_value);
-                   return FALSE;
-                 }
+                 goto bad_psindx;
                entry->section = PRIV (sections)[psindx];
              }
            else
@@ -1415,9 +1437,9 @@ _bfd_vms_slurp_egsd (bfd *abfd)
        case EGSD__C_SYMM:
        case EGSD__C_SYMV:
        default:
-         _bfd_error_handler (_("Unknown EGSD subtype %d"), gsd_type);
+         _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
 
       PRIV (recrd.rec_size) -= gsd_size;
@@ -1429,14 +1451,14 @@ _bfd_vms_slurp_egsd (bfd *abfd)
   if (PRIV (gsd_sym_count) > 0)
     abfd->flags |= HAS_SYMS;
 
-  return TRUE;
+  return true;
 }
 
 /* Stack routines for vms ETIR commands.  */
 
 /* Push value and section index.  */
 
-static void
+static bool
 _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
 {
   vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
@@ -1448,27 +1470,29 @@ _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
   if (PRIV (stackptr) >= STACKSIZE)
     {
       bfd_set_error (bfd_error_bad_value);
-      _bfd_error_handler (_("Stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
-      exit (1);
+      _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
+      return false;
     }
+  return true;
 }
 
 /* Pop value and section index.  */
 
-static void
+static bool
 _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
 {
   if (PRIV (stackptr) == 0)
     {
       bfd_set_error (bfd_error_bad_value);
-      _bfd_error_handler (_("Stack underflow in _bfd_vms_pop"));
-      exit (1);
+      _bfd_error_handler (_("stack underflow in _bfd_vms_pop"));
+      return false;
     }
   PRIV (stackptr)--;
   *val = PRIV (stack[PRIV (stackptr)]).value;
   *rel = PRIV (stack[PRIV (stackptr)]).reloc;
 
   vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
+  return true;
 }
 
 /* Routines to fill sections contents during tir/etir read.  */
@@ -1525,77 +1549,109 @@ image_inc_ptr (bfd *abfd, bfd_vma offset)
 
 /* Save current DST location counter under specified index.  */
 
-static void
+static bool
 dst_define_location (bfd *abfd, unsigned int loc)
 {
   vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
 
+  if (loc > 1 << 24)
+    {
+      /* 16M entries ought to be plenty.  */
+      bfd_set_error (bfd_error_bad_value);
+      _bfd_error_handler (_("dst_define_location %u too large"), loc);
+      return false;
+    }
+
   /* Grow the ptr offset table if necessary.  */
   if (loc + 1 > PRIV (dst_ptr_offsets_count))
     {
-      PRIV (dst_ptr_offsets) = bfd_realloc (PRIV (dst_ptr_offsets),
-                                          (loc + 1) * sizeof (unsigned int));
+      PRIV (dst_ptr_offsets)
+       = bfd_realloc_or_free (PRIV (dst_ptr_offsets),
+                              (loc + 1) * sizeof (unsigned int));
+      if (PRIV (dst_ptr_offsets) == NULL)
+       return false;
       PRIV (dst_ptr_offsets_count) = loc + 1;
     }
 
   PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
+  return true;
 }
 
 /* Restore saved DST location counter from specified index.  */
 
-static void
+static bool
 dst_restore_location (bfd *abfd, unsigned int loc)
 {
   vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
 
-  PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
+  if (loc < PRIV (dst_ptr_offsets_count))
+    {
+      PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
+      return true;
+    }
+  return false;
 }
 
 /* Retrieve saved DST location counter from specified index.  */
 
-static unsigned int
-dst_retrieve_location (bfd *abfd, unsigned int loc)
+static bool
+dst_retrieve_location (bfd *abfd, bfd_vma *loc)
 {
-  vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int)loc));
+  vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc));
 
-  return PRIV (dst_ptr_offsets)[loc];
+  if (*loc < PRIV (dst_ptr_offsets_count))
+    {
+      *loc = PRIV (dst_ptr_offsets)[*loc];
+      return true;
+    }
+  return false;
 }
 
 /* Write multiple bytes to section image.  */
 
-static bfd_boolean
+static bool
 image_write (bfd *abfd, unsigned char *ptr, unsigned int size)
 {
+  asection *sec = PRIV (image_section);
+  size_t off = PRIV (image_offset);
+
+  /* Check bounds.  */
+  if (off > sec->size
+      || size > sec->size - off)
+    {
+      bfd_set_error (bfd_error_bad_value);
+      return false;
+    }
+
 #if VMS_DEBUG
   _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size,
-                 (long)PRIV (image_offset));
-  _bfd_hexdump (9, ptr, size, 0);
+                 (long) off));
 #endif
 
   if (PRIV (image_section)->contents != NULL)
+    memcpy (sec->contents + off, ptr, size);
+  else
     {
-      asection *sec = PRIV (image_section);
-      file_ptr off = PRIV (image_offset);
-
-      /* Check bounds.  */
-      if (off > (file_ptr)sec->size
-         || size > (file_ptr)sec->size
-         || off + size > (file_ptr)sec->size)
-       {
-         bfd_set_error (bfd_error_bad_value);
-         return FALSE;
-       }
-
-      memcpy (sec->contents + off, ptr, size);
+      unsigned int i;
+      for (i = 0; i < size; i++)
+       if (ptr[i] != 0)
+         {
+           bfd_set_error (bfd_error_bad_value);
+           return false;
+         }
     }
 
+#if VMS_DEBUG
+  _bfd_hexdump (9, ptr, size, 0);
+#endif
+
   PRIV (image_offset) += size;
-  return TRUE;
+  return true;
 }
 
 /* Write byte to section image.  */
 
-static bfd_boolean
+static bool
 image_write_b (bfd * abfd, unsigned int value)
 {
   unsigned char data[1];
@@ -1609,7 +1665,7 @@ image_write_b (bfd * abfd, unsigned int value)
 
 /* Write 2-byte word to image.  */
 
-static bfd_boolean
+static bool
 image_write_w (bfd * abfd, unsigned int value)
 {
   unsigned char data[2];
@@ -1622,7 +1678,7 @@ image_write_w (bfd * abfd, unsigned int value)
 
 /* Write 4-byte long to image.  */
 
-static bfd_boolean
+static bool
 image_write_l (bfd * abfd, unsigned long value)
 {
   unsigned char data[4];
@@ -1635,7 +1691,7 @@ image_write_l (bfd * abfd, unsigned long value)
 
 /* Write 8-byte quad to image.  */
 
-static bfd_boolean
+static bool
 image_write_q (bfd * abfd, bfd_vma value)
 {
   unsigned char data[8];
@@ -1734,7 +1790,7 @@ _bfd_vms_get_value (bfd *abfd,
   len = *ascic;
   if (ascic + len >= max_ascic)
     {
-      _bfd_error_handler (_("Corrupt vms value"));
+      _bfd_error_handler (_("corrupt vms value"));
       *vma = 0;
       *hp = NULL;
       return;
@@ -1745,7 +1801,7 @@ _bfd_vms_get_value (bfd *abfd,
   name[i] = 0;
 
   h = (struct alpha_vms_link_hash_entry *)
-    bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
+    bfd_link_hash_lookup (info->hash, name, false, false, true);
 
   *hp = h;
 
@@ -1760,7 +1816,7 @@ _bfd_vms_get_value (bfd *abfd,
   else
     {
       (*info->callbacks->undefined_symbol)
-       (info, name, abfd, PRIV (image_section), PRIV (image_offset), TRUE);
+       (info, name, abfd, PRIV (image_section), PRIV (image_offset), true);
       *vma = 0;
     }
 }
@@ -1830,16 +1886,16 @@ alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info,
    the output section (used during linking).
    Return FALSE in case of error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
 {
   unsigned char *ptr;
   unsigned int length;
   unsigned char *maxptr;
-  bfd_vma op1;
-  bfd_vma op2;
-  unsigned int rel1;
-  unsigned int rel2;
+  bfd_vma op1 = 0;
+  bfd_vma op2 = 0;
+  unsigned int rel1 = RELC_NONE;
+  unsigned int rel2 = RELC_NONE;
   struct alpha_vms_link_hash_entry *h;
 
   PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
@@ -1853,24 +1909,29 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
 
   while (ptr < maxptr)
     {
-      int cmd = bfd_getl16 (ptr);
-      int cmd_length = bfd_getl16 (ptr + 2);
+      int cmd, cmd_length;
 
-      ptr += 4;
+      if (ptr + 4 > maxptr)
+       goto corrupt_etir;
+
+      cmd = bfd_getl16 (ptr);
+      cmd_length = bfd_getl16 (ptr + 2);
 
       /* PR 21589 and 21579: Check for a corrupt ETIR record.  */
-      if (cmd_length < 4 || (ptr + cmd_length > maxptr + 4))
+      if (cmd_length < 4 || ptr + cmd_length > maxptr)
        {
        corrupt_etir:
-         _bfd_error_handler (_("Corrupt ETIR record encountered"));
+         _bfd_error_handler (_("corrupt ETIR record encountered"));
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return false;
        }
+      ptr += 4;
+      cmd_length -= 4;
 
 #if VMS_DEBUG
       _bfd_vms_debug (4, "etir: %s(%d)\n",
                      _bfd_vms_etir_name (cmd), cmd);
-      _bfd_hexdump (8, ptr, cmd_length - 4, 0);
+      _bfd_hexdump (8, ptr, cmd_length, 0);
 #endif
 
       switch (cmd)
@@ -1880,8 +1941,9 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
 
             stack 32 bit value of symbol (high bits set to 0).  */
        case ETIR__C_STA_GBL:
-         _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h);
-         _bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h));
+         _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
+         if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h)))
+           return false;
          break;
 
          /* Stack longword
@@ -1889,9 +1951,10 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
 
             stack 32 bit value, sign extend to 64 bit.  */
        case ETIR__C_STA_LW:
-         if (ptr + 4 >= maxptr)
+         if (cmd_length < 4)
            goto corrupt_etir;
-         _bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE);
+         if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE))
+           return false;
          break;
 
          /* Stack quadword
@@ -1899,9 +1962,10 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
 
             stack 64 bit value of symbol.  */
        case ETIR__C_STA_QW:
-         if (ptr + 8 >= maxptr)
+         if (cmd_length < 8)
            goto corrupt_etir;
-         _bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE);
+         if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE))
+           return false;
          break;
 
          /* Stack psect base plus quadword offset
@@ -1914,7 +1978,7 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
          {
            int psect;
 
-           if (ptr + 12 >= maxptr)
+           if (cmd_length < 12)
              goto corrupt_etir;
            psect = bfd_getl32 (ptr);
            if ((unsigned int) psect >= PRIV (section_count))
@@ -1922,10 +1986,11 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
                _bfd_error_handler (_("bad section index in %s"),
                                    _bfd_vms_etir_name (cmd));
                bfd_set_error (bfd_error_bad_value);
-               return FALSE;
+               return false;
              }
            op1 = bfd_getl64 (ptr + 4);
-           _bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE);
+           if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE))
+             return false;
          }
          break;
 
@@ -1934,31 +1999,36 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
        case ETIR__C_STA_CKARG:
          _bfd_error_handler (_("unsupported STA cmd %s"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
 
          /* Store byte: pop stack, write byte
             arg: -.  */
        case ETIR__C_STO_B:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         image_write_b (abfd, (unsigned int) op1 & 0xff);
+         if (!image_write_b (abfd, (unsigned int) op1 & 0xff))
+           return false;
          break;
 
          /* Store word: pop stack, write word
             arg: -.  */
        case ETIR__C_STO_W:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         image_write_w (abfd, (unsigned int) op1 & 0xffff);
+         if (!image_write_w (abfd, (unsigned int) op1 & 0xffff))
+           return false;
          break;
 
          /* Store longword: pop stack, write longword
             arg: -.  */
        case ETIR__C_STO_LW:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 & RELC_SEC_BASE)
            {
              op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
@@ -1966,22 +2036,26 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
            }
          else if (rel1 & RELC_SHR_BASE)
            {
-             alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1);
+             if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1))
+               return false;
              rel1 = RELC_NONE;
            }
          if (rel1 != RELC_NONE)
            {
              if (rel1 != RELC_REL)
                abort ();
-             alpha_vms_add_lw_reloc (info);
+             if (!alpha_vms_add_lw_reloc (info))
+               return false;
            }
-         image_write_l (abfd, op1);
+         if (!image_write_l (abfd, op1))
+           return false;
          break;
 
          /* Store quadword: pop stack, write quadword
             arg: -.  */
        case ETIR__C_STO_QW:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 & RELC_SEC_BASE)
            {
              op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
@@ -1993,9 +2067,11 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
            {
              if (rel1 != RELC_REL)
                abort ();
-             alpha_vms_add_qw_reloc (info);
+             if (!alpha_vms_add_qw_reloc (info))
+               return false;
            }
-         image_write_q (abfd, op1);
+         if (!image_write_q (abfd, op1))
+           return false;
          break;
 
          /* Store immediate repeated: pop stack for repeat count
@@ -2005,43 +2081,53 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
          {
            int size;
 
-           if (ptr + 4 >= maxptr)
+           if (cmd_length < 4)
              goto corrupt_etir;
            size = bfd_getl32 (ptr);
-           _bfd_vms_pop (abfd, &op1, &rel1);
+           if (size > cmd_length - 4)
+             goto corrupt_etir;
+           if (!_bfd_vms_pop (abfd, &op1, &rel1))
+             return false;
            if (rel1 != RELC_NONE)
              goto bad_context;
+           if (size == 0)
+             break;
+           op1 &= 0xffffffff;
            while (op1-- > 0)
-             image_write (abfd, ptr + 4, size);
+             if (!image_write (abfd, ptr + 4, size))
+               return false;
          }
          break;
 
          /* Store global: write symbol value
             arg: cs    global symbol name.  */
        case ETIR__C_STO_GBL:
-         _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h);
+         _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
          if (h && h->sym)
            {
              if (h->sym->typ == EGSD__C_SYMG)
                {
-                 alpha_vms_add_fixup_qr
-                   (info, abfd, h->sym->owner, h->sym->symbol_vector);
+                 if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner,
+                                              h->sym->symbol_vector))
+                   return false;
                  op1 = 0;
                }
              else
                {
                  op1 = alpha_vms_get_sym_value (h->sym->section,
                                                 h->sym->value);
-                 alpha_vms_add_qw_reloc (info);
+                 if (!alpha_vms_add_qw_reloc (info))
+                   return false;
                }
            }
-         image_write_q (abfd, op1);
+         if (!image_write_q (abfd, op1))
+           return false;
          break;
 
          /* Store code address: write address of entry point
             arg: cs    global symbol name (procedure).  */
        case ETIR__C_STO_CA:
-         _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h);
+         _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
          if (h && h->sym)
            {
              if (h->sym->flags & EGSY__V_NORM)
@@ -2049,14 +2135,16 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
                  /* That's really a procedure.  */
                  if (h->sym->typ == EGSD__C_SYMG)
                    {
-                     alpha_vms_add_fixup_ca (info, abfd, h->sym->owner);
+                     if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner))
+                       return false;
                      op1 = h->sym->symbol_vector;
                    }
                  else
                    {
                      op1 = alpha_vms_get_sym_value (h->sym->code_section,
                                                     h->sym->code_value);
-                     alpha_vms_add_qw_reloc (info);
+                     if (!alpha_vms_add_qw_reloc (info))
+                       return false;
                    }
                }
              else
@@ -2065,20 +2153,23 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
                  abort ();
                }
            }
-         image_write_q (abfd, op1);
+         if (!image_write_q (abfd, op1))
+           return false;
          break;
 
          /* Store offset to psect: pop stack, add low 32 bits to base of psect
             arg: none.  */
        case ETIR__C_STO_OFF:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
 
          if (!(rel1 & RELC_SEC_BASE))
            abort ();
 
          op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
          rel1 = RELC_REL;
-         image_write_q (abfd, op1);
+         if (!image_write_q (abfd, op1))
+           return false;
          break;
 
          /* Store immediate
@@ -2088,10 +2179,11 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
          {
            unsigned int size;
 
-           if (ptr + 4 >= maxptr)
+           if (cmd_length < 4)
              goto corrupt_etir;
            size = bfd_getl32 (ptr);
-           image_write (abfd, ptr + 4, size);
+           if (!image_write (abfd, ptr + 4, size))
+             return false;
          }
          break;
 
@@ -2102,11 +2194,12 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
             store global longword: store 32bit value of symbol
             arg: cs    symbol name.  */
        case ETIR__C_STO_GBL_LW:
-         _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h);
+         _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
 #if 0
          abort ();
 #endif
-         image_write_l (abfd, op1);
+         if (!image_write_l (abfd, op1))
+           return false;
          break;
 
        case ETIR__C_STO_RB:
@@ -2114,13 +2207,13 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
        case ETIR__C_STO_LP_PSB:
          _bfd_error_handler (_("%s: not supported"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
        case ETIR__C_STO_HINT_GBL:
        case ETIR__C_STO_HINT_PS:
          _bfd_error_handler (_("%s: not implemented"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
 
          /* 200 Store-conditional Linkage Pair
@@ -2145,7 +2238,7 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
        case ETIR__C_STC_PS:
          _bfd_error_handler (_("%s: not supported"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
 
          /* 201 Store-conditional Linkage Pair with Procedure Signature
@@ -2155,12 +2248,15 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
             da signature.  */
 
        case ETIR__C_STC_LP_PSB:
-         _bfd_vms_get_value (abfd, ptr + 4, maxptr, info, &op1, &h);
+         if (cmd_length < 4)
+           goto corrupt_etir;
+         _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h);
          if (h && h->sym)
            {
              if (h->sym->typ == EGSD__C_SYMG)
                {
-                 alpha_vms_add_fixup_lp (info, abfd, h->sym->owner);
+                 if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner))
+                   return false;
                  op1 = h->sym->symbol_vector;
                  op2 = 0;
                }
@@ -2178,8 +2274,9 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
              op1 = 0;
              op2 = 0;
            }
-         image_write_q (abfd, op1);
-         image_write_q (abfd, op2);
+         if (!image_write_q (abfd, op1)
+             || !image_write_q (abfd, op2))
+           return false;
          break;
 
          /* 205 Store-conditional NOP at address of global
@@ -2236,13 +2333,14 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
        case ETIR__C_STC_NBH_PS:
          _bfd_error_handler (_("%s: not supported"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
 
          /* Det relocation base: pop stack, set image location counter
             arg: none.  */
        case ETIR__C_CTL_SETRB:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (!(rel1 & RELC_SEC_BASE))
            abort ();
          image_set_ptr (abfd, op1, rel1 & RELC_MASK, info);
@@ -2251,7 +2349,7 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
          /* Augment relocation base: increment image location counter by offset
             arg: lw    offset value.  */
        case ETIR__C_CTL_AUGRB:
-         if (ptr + 4 >= maxptr)
+         if (cmd_length < 4)
            goto corrupt_etir;
          op1 = bfd_getl32 (ptr);
          image_inc_ptr (abfd, op1);
@@ -2260,46 +2358,65 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
          /* Define location: pop index, save location counter under index
             arg: none.  */
        case ETIR__C_CTL_DFLOC:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         dst_define_location (abfd, op1);
+         if (!dst_define_location (abfd, op1))
+           return false;
          break;
 
          /* Set location: pop index, restore location counter from index
             arg: none.  */
        case ETIR__C_CTL_STLOC:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         dst_restore_location (abfd, op1);
+         if (!dst_restore_location (abfd, op1))
+           {
+             bfd_set_error (bfd_error_bad_value);
+             _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC");
+             return false;
+           }
          break;
 
          /* Stack defined location: pop index, push location counter from index
             arg: none.  */
        case ETIR__C_CTL_STKDL:
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, dst_retrieve_location (abfd, op1), RELC_NONE);
+         if (!dst_retrieve_location (abfd, &op1))
+           {
+             bfd_set_error (bfd_error_bad_value);
+             _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL");
+             return false;
+           }
+         if (!_bfd_vms_push (abfd, op1, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_NOP:      /* No-op.  */
          break;
 
        case ETIR__C_OPR_ADD:      /* Add.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 == RELC_NONE && rel2 != RELC_NONE)
            rel1 = rel2;
          else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op1 + op2, rel1);
+         if (!_bfd_vms_push (abfd, op1 + op2, rel1))
+           return false;
          break;
 
        case ETIR__C_OPR_SUB:      /* Subtract.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 == RELC_NONE && rel2 != RELC_NONE)
            rel1 = rel2;
          else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE))
@@ -2310,81 +2427,123 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
            }
          else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op2 - op1, rel1);
+         if (!_bfd_vms_push (abfd, op2 - op1, rel1))
+           return false;
          break;
 
        case ETIR__C_OPR_MUL:      /* Multiply.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op1 * op2, RELC_NONE);
+         if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_DIV:      /* Divide.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            goto bad_context;
-         if (op2 == 0)
-           _bfd_vms_push (abfd, 0, RELC_NONE);
+         if (op1 == 0)
+           {
+             /* Divide by zero is supposed to give a result of zero,
+                and a non-fatal warning message.  */
+             _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV");
+             if (!_bfd_vms_push (abfd, 0, RELC_NONE))
+               return false;
+           }
          else
-           _bfd_vms_push (abfd, op2 / op1, RELC_NONE);
+           {
+             if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE))
+               return false;
+           }
          break;
 
        case ETIR__C_OPR_AND:      /* Logical AND.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op1 & op2, RELC_NONE);
+         if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_IOR:      /* Logical inclusive OR.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op1 | op2, RELC_NONE);
+         if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_EOR:      /* Logical exclusive OR.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, op1 ^ op2, RELC_NONE);
+         if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_NEG:      /* Negate.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, -op1, RELC_NONE);
+         if (!_bfd_vms_push (abfd, -op1, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_COM:      /* Complement.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (rel1 != RELC_NONE)
            goto bad_context;
-         _bfd_vms_push (abfd, ~op1, RELC_NONE);
+         if (!_bfd_vms_push (abfd, ~op1, RELC_NONE))
+           return false;
          break;
 
        case ETIR__C_OPR_ASH:      /* Arithmetic shift.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
-         _bfd_vms_pop (abfd, &op2, &rel2);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1)
+             || !_bfd_vms_pop (abfd, &op2, &rel2))
+           return false;
          if (rel1 != RELC_NONE || rel2 != RELC_NONE)
            {
            bad_context:
              _bfd_error_handler (_("invalid use of %s with contexts"),
                                  _bfd_vms_etir_name (cmd));
-             return FALSE;
+             return false;
+           }
+         if ((bfd_signed_vma) op2 < 0)
+           {
+             /* Shift right.  */
+             bfd_vma sign;
+             op2 = -op2;
+             if (op2 >= CHAR_BIT * sizeof (op1))
+               op2 = CHAR_BIT * sizeof (op1) - 1;
+             /* op1 = (bfd_signed_vma) op1 >> op2; */
+             sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1));
+             op1 >>= op2;
+             sign >>= op2;
+             op1 = (op1 ^ sign) - sign;
            }
-         if ((int)op2 < 0)             /* Shift right.  */
-           op1 >>= -(int)op2;
-         else                  /* Shift left.  */
-           op1 <<= (int)op2;
-         _bfd_vms_push (abfd, op1, RELC_NONE); /* FIXME: sym.  */
+         else
+           {
+             /* Shift left.  */
+             if (op2 >= CHAR_BIT * sizeof (op1))
+               op1 = 0;
+             else
+               op1 <<= op2;
+           }
+         if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym.  */
+           return false;
          break;
 
        case ETIR__C_OPR_INSV:      /* Insert field.   */
@@ -2394,37 +2553,43 @@ _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
        case ETIR__C_OPR_DFLIT:     /* Define a literal.  */
          _bfd_error_handler (_("%s: not supported"),
                              _bfd_vms_etir_name (cmd));
-         return FALSE;
+         return false;
          break;
 
        case ETIR__C_OPR_SEL:      /* Select.  */
-         _bfd_vms_pop (abfd, &op1, &rel1);
+         if (!_bfd_vms_pop (abfd, &op1, &rel1))
+           return false;
          if (op1 & 0x01L)
-           _bfd_vms_pop (abfd, &op1, &rel1);
+           {
+             if (!_bfd_vms_pop (abfd, &op1, &rel1))
+               return false;
+           }
          else
            {
-             _bfd_vms_pop (abfd, &op1, &rel1);
-             _bfd_vms_pop (abfd, &op2, &rel2);
-             _bfd_vms_push (abfd, op1, rel1);
+             if (!_bfd_vms_pop (abfd, &op1, &rel1)
+                 || !_bfd_vms_pop (abfd, &op2, &rel2))
+               return false;
+             if (!_bfd_vms_push (abfd, op1, rel1))
+               return false;
            }
          break;
 
        default:
          _bfd_error_handler (_("reserved cmd %d"), cmd);
-         return FALSE;
+         return false;
          break;
        }
 
-      ptr += cmd_length - 4;
+      ptr += cmd_length;
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Process EDBG/ETBT record.
    Return TRUE on success, FALSE on error  */
 
-static bfd_boolean
+static bool
 vms_slurp_debug (bfd *abfd)
 {
   asection *section = PRIV (dst_section);
@@ -2439,9 +2604,9 @@ vms_slurp_debug (bfd *abfd)
 
       section = bfd_make_section (abfd, "$DST$");
       if (!section)
-       return FALSE;
-      if (!bfd_set_section_flags (abfd, section, flags))
-       return FALSE;
+       return false;
+      if (!bfd_set_section_flags (section, flags))
+       return false;
       PRIV (dst_section) = section;
     }
 
@@ -2449,16 +2614,16 @@ vms_slurp_debug (bfd *abfd)
   PRIV (image_offset) = section->size;
 
   if (!_bfd_vms_slurp_etir (abfd, NULL))
-    return FALSE;
+    return false;
 
   section->size = PRIV (image_offset);
-  return TRUE;
+  return true;
 }
 
 /* Process EDBG record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_edbg (bfd *abfd)
 {
   vms_debug2 ((2, "EDBG\n"));
@@ -2471,7 +2636,7 @@ _bfd_vms_slurp_edbg (bfd *abfd)
 /* Process ETBT record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_etbt (bfd *abfd)
 {
   vms_debug2 ((2, "ETBT\n"));
@@ -2484,7 +2649,7 @@ _bfd_vms_slurp_etbt (bfd *abfd)
 /* Process EEOM record.
    Return TRUE on success, FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_eeom (bfd *abfd)
 {
   struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
@@ -2494,39 +2659,39 @@ _bfd_vms_slurp_eeom (bfd *abfd)
   /* PR 21813: Check for an undersized record.  */
   if (PRIV (recrd.buf_size) < sizeof (* eeom))
     {
-      _bfd_error_handler (_("Corrupt EEOM record - size is too small"));
+      _bfd_error_handler (_("corrupt EEOM record - size is too small"));
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
   PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
   PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
   if (PRIV (eom_data).eom_w_comcod > 1)
     {
-      _bfd_error_handler (_("Object module NOT error-free !\n"));
+      _bfd_error_handler (_("object module not error-free !"));
       bfd_set_error (bfd_error_bad_value);
-      return FALSE;
+      return false;
     }
 
-  PRIV (eom_data).eom_has_transfer = FALSE;
+  PRIV (eom_data).eom_has_transfer = false;
   if (PRIV (recrd.rec_size) > 10)
     {
-      PRIV (eom_data).eom_has_transfer = TRUE;
+      PRIV (eom_data).eom_has_transfer = true;
       PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
       PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
       PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
 
       abfd->start_address = PRIV (eom_data).eom_l_tfradr;
     }
-  return TRUE;
+  return true;
 }
 
 /* Slurp an ordered set of VMS object records.  Return FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_slurp_object_records (bfd * abfd)
 {
-  bfd_boolean err;
+  bool ok;
   int type;
 
   do
@@ -2537,53 +2702,53 @@ _bfd_vms_slurp_object_records (bfd * abfd)
       if (type < 0)
        {
          vms_debug2 ((2, "next_record failed\n"));
-         return FALSE;
+         return false;
        }
 
       switch (type)
        {
        case EOBJ__C_EMH:
-         err = _bfd_vms_slurp_ehdr (abfd);
+         ok = _bfd_vms_slurp_ehdr (abfd);
          break;
        case EOBJ__C_EEOM:
-         err = _bfd_vms_slurp_eeom (abfd);
+         ok = _bfd_vms_slurp_eeom (abfd);
          break;
        case EOBJ__C_EGSD:
-         err = _bfd_vms_slurp_egsd (abfd);
+         ok = _bfd_vms_slurp_egsd (abfd);
          break;
        case EOBJ__C_ETIR:
-         err = TRUE; /* _bfd_vms_slurp_etir (abfd); */
+         ok = true; /* _bfd_vms_slurp_etir (abfd); */
          break;
        case EOBJ__C_EDBG:
-         err = _bfd_vms_slurp_edbg (abfd);
+         ok = _bfd_vms_slurp_edbg (abfd);
          break;
        case EOBJ__C_ETBT:
-         err = _bfd_vms_slurp_etbt (abfd);
+         ok = _bfd_vms_slurp_etbt (abfd);
          break;
        default:
-         err = FALSE;
+         ok = false;
        }
-      if (!err)
+      if (!ok)
        {
          vms_debug2 ((2, "slurp type %d failed\n", type));
-         return FALSE;
+         return false;
        }
     }
   while (type != EOBJ__C_EEOM);
 
-  return TRUE;
+  return true;
 }
 
 /* Initialize private data  */
-static bfd_boolean
+static bool
 vms_initialize (bfd * abfd)
 {
-  bfd_size_type amt;
+  size_t amt;
 
   amt = sizeof (struct vms_private_data_struct);
   abfd->tdata.any = bfd_zalloc (abfd, amt);
   if (abfd->tdata.any == NULL)
-    return FALSE;
+    return false;
 
   PRIV (recrd.file_format) = FF_UNKNOWN;
 
@@ -2592,18 +2757,34 @@ vms_initialize (bfd * abfd)
   if (PRIV (stack) == NULL)
     goto error_ret1;
 
-  return TRUE;
+  return true;
 
  error_ret1:
   bfd_release (abfd, abfd->tdata.any);
   abfd->tdata.any = NULL;
-  return FALSE;
+  return false;
+}
+
+/* Free malloc'd memory.  */
+
+static void
+alpha_vms_free_private (bfd *abfd)
+{
+  struct module *module;
+
+  free (PRIV (recrd.buf));
+  free (PRIV (sections));
+  free (PRIV (syms));
+  free (PRIV (dst_ptr_offsets));
+
+  for (module = PRIV (modules); module; module = module->next)
+    free (module->file_table);
 }
 
 /* Check the format for a file being read.
    Return a (bfd_target *) if it's an object file or zero if not.  */
 
-static const struct bfd_target *
+static bfd_cleanup
 alpha_vms_object_p (bfd *abfd)
 {
   void *tdata_save = abfd->tdata.any;
@@ -2614,10 +2795,13 @@ alpha_vms_object_p (bfd *abfd)
 
   /* Allocate alpha-vms specific data.  */
   if (!vms_initialize (abfd))
-    goto error_ret;
+    {
+      abfd->tdata.any = tdata_save;
+      return NULL;
+    }
 
   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
-    goto err_wrong_format;
+    goto error_ret;
 
   /* The first challenge with VMS is to discover the kind of the file.
 
@@ -2636,27 +2820,17 @@ alpha_vms_object_p (bfd *abfd)
      2 bytes size repeated) and 12 bytes for images (4 bytes major id,
      4 bytes minor id, 4 bytes length).  */
   test_len = 12;
-
-  /* Size the main buffer.  */
-  buf = (unsigned char *) bfd_malloc (test_len);
+  buf = _bfd_malloc_and_read (abfd, test_len, test_len);
   if (buf == NULL)
     goto error_ret;
   PRIV (recrd.buf) = buf;
   PRIV (recrd.buf_size) = test_len;
-
-  /* Initialize the record pointer.  */
   PRIV (recrd.rec) = buf;
 
-  if (bfd_bread (buf, test_len, abfd) != test_len)
-    goto err_wrong_format;
-
   /* Is it an image?  */
   if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
       && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
     {
-      unsigned int to_read;
-      unsigned int read_so_far;
-      unsigned int remaining;
       unsigned int eisd_offset, eihs_offset;
 
       /* Extract the header size.  */
@@ -2666,44 +2840,25 @@ alpha_vms_object_p (bfd *abfd)
       if (PRIV (recrd.rec_size) == 0)
        PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
 
-      if (PRIV (recrd.rec_size) > PRIV (recrd.buf_size))
-       {
-         buf = bfd_realloc_or_free (buf, PRIV (recrd.rec_size));
-
-         if (buf == NULL)
-           {
-             PRIV (recrd.buf) = NULL;
-             goto error_ret;
-           }
-         PRIV (recrd.buf) = buf;
-         PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
-       }
-
       /* PR 21813: Check for a truncated record.  */
-      if (PRIV (recrd.rec_size < test_len))
-       goto error_ret;
-      /* Read the remaining record.  */
-      remaining = PRIV (recrd.rec_size) - test_len;
-      to_read = MIN (VMS_BLOCK_SIZE - test_len, remaining);
-      read_so_far = test_len;
-
-      while (remaining > 0)
-       {
-         if (bfd_bread (buf + read_so_far, to_read, abfd) != to_read)
-           goto err_wrong_format;
+      /* PR 17512: file: 7d7c57c2.  */
+      if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd))
+       goto err_wrong_format;
 
-         read_so_far += to_read;
-         remaining -= to_read;
+      if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
+       goto error_ret;
 
-         to_read = MIN (VMS_BLOCK_SIZE, remaining);
-       }
+      free (PRIV (recrd.buf));
+      PRIV (recrd.buf) = NULL;
+      buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size),
+                                 PRIV (recrd.rec_size));
+      if (buf == NULL)
+       goto error_ret;
 
-      /* Reset the record pointer.  */
+      PRIV (recrd.buf) = buf;
+      PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
       PRIV (recrd.rec) = buf;
 
-      /* PR 17512: file: 7d7c57c2.  */
-      if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd))
-       goto error_ret;
       vms_debug2 ((2, "file type is image\n"));
 
       if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset))
@@ -2748,14 +2903,13 @@ alpha_vms_object_p (bfd *abfd)
   if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
     goto err_wrong_format;
 
-  return abfd->xvec;
+  return alpha_vms_free_private;
 
  err_wrong_format:
   bfd_set_error (bfd_error_wrong_format);
 
  error_ret:
-  if (PRIV (recrd.buf))
-    free (PRIV (recrd.buf));
+  alpha_vms_free_private (abfd);
   if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
     bfd_release (abfd, abfd->tdata.any);
   abfd->tdata.any = tdata_save;
@@ -2770,6 +2924,7 @@ static void
 _bfd_vms_write_emh (bfd *abfd)
 {
   struct vms_rec_wr *recwr = &PRIV (recwr);
+  unsigned char tbuf[18];
 
   _bfd_vms_output_alignment (recwr, 2);
 
@@ -2784,7 +2939,7 @@ _bfd_vms_write_emh (bfd *abfd)
   /* Create module name from filename.  */
   if (bfd_get_filename (abfd) != 0)
     {
-      char *module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
+      char *module = vms_get_module_name (bfd_get_filename (abfd), true);
       _bfd_vms_output_counted (recwr, module);
       free (module);
     }
@@ -2792,7 +2947,7 @@ _bfd_vms_write_emh (bfd *abfd)
     _bfd_vms_output_counted (recwr, "NONAME");
 
   _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
-  _bfd_vms_output_dump (recwr, get_vms_time_string (), EMH_DATE_LENGTH);
+  _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH);
   _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
   _bfd_vms_output_end (abfd, recwr);
 }
@@ -2818,7 +2973,7 @@ _bfd_vms_write_lmn (bfd *abfd, const char *name)
 
 /* Write eom record for bfd abfd.  Return FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_write_eeom (bfd *abfd)
 {
   struct vms_rec_wr *recwr = &PRIV (recwr);
@@ -2841,7 +2996,7 @@ _bfd_vms_write_eeom (bfd *abfd)
       if (section == 0)
        {
          bfd_set_error (bfd_error_nonrepresentable_section);
-         return FALSE;
+         return false;
        }
       _bfd_vms_output_short (recwr, 0);
       _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
@@ -2851,25 +3006,39 @@ _bfd_vms_write_eeom (bfd *abfd)
     }
 
   _bfd_vms_output_end (abfd, recwr);
-  return TRUE;
+  return true;
 }
 
-static void
+static void *
 vector_grow1 (struct vector_type *vec, size_t elsz)
 {
-  if (vec->nbr_el + 1 < vec->max_el)
-    return;
-
-  if (vec->max_el == 0)
+  if (vec->nbr_el >= vec->max_el)
     {
-      vec->max_el = 16;
-      vec->els = bfd_malloc2 (vec->max_el, elsz);
-    }
-  else
-    {
-      vec->max_el *= 2;
-      vec->els = bfd_realloc2 (vec->els, vec->max_el, elsz);
+      if (vec->max_el == 0)
+       {
+         vec->max_el = 16;
+         vec->els = bfd_malloc (vec->max_el * elsz);
+       }
+      else
+       {
+         size_t amt;
+         if (vec->max_el > -1u / 2)
+           {
+             bfd_set_error (bfd_error_file_too_big);
+             return NULL;
+           }
+         vec->max_el *= 2;
+         if (_bfd_mul_overflow (vec->max_el, elsz, &amt))
+           {
+             bfd_set_error (bfd_error_file_too_big);
+             return NULL;
+           }
+         vec->els = bfd_realloc_or_free (vec->els, amt);
+       }
     }
+  if (vec->els == NULL)
+    return NULL;
+  return (char *) vec->els + elsz * vec->nbr_el++;
 }
 
 /* Bump ABFD file position to next block.  */
@@ -2925,7 +3094,7 @@ alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd)
 /* Create an EISD for shared image SHRIMG.
    Return FALSE in case of error.  */
 
-static bfd_boolean
+static bool
 alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
 {
   struct vms_internal_eisd_map *eisd;
@@ -2935,12 +3104,12 @@ alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
   if (namlen + 5 > EISD__K_GBLNAMLEN)
     {
       /* Won't fit.  */
-      return FALSE;
+      return false;
     }
 
   eisd = bfd_alloc (abfd, sizeof (*eisd));
   if (eisd == NULL)
-    return FALSE;
+    return false;
 
   /* Fill the fields.  */
   eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID;
@@ -2963,25 +3132,25 @@ alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
   /* Append it to the list.  */
   alpha_vms_append_extra_eisd (abfd, eisd);
 
-  return TRUE;
+  return true;
 }
 
 /* Create an EISD for section SEC.
    Return FALSE in case of failure.  */
 
-static bfd_boolean
+static bool
 alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
 {
   struct vms_internal_eisd_map *eisd;
 
   /* Only for allocating section.  */
   if (!(sec->flags & SEC_ALLOC))
-    return TRUE;
+    return true;
 
   BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
   eisd = bfd_alloc (abfd, sizeof (*eisd));
   if (eisd == NULL)
-    return FALSE;
+    return false;
   vms_section_data (sec)->eisd = eisd;
 
   /* Fill the fields.  */
@@ -3025,13 +3194,13 @@ alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
     PRIV (eisd_tail)->next = eisd;
   PRIV (eisd_tail) = eisd;
 
-  return TRUE;
+  return true;
 }
 
 /* Layout executable ABFD and write it to the disk.
    Return FALSE in case of failure.  */
 
-static bfd_boolean
+static bool
 alpha_vms_write_exec (bfd *abfd)
 {
   struct vms_eihd eihd;
@@ -3081,7 +3250,7 @@ alpha_vms_write_exec (bfd *abfd)
   bfd_putl32 (16, eihd.virt_mem_block_size);
   bfd_putl32 (0, eihd.ext_fixup_off);
   bfd_putl32 (0, eihd.noopt_psect_off);
-  bfd_putl32 (-1, eihd.alias);
+  bfd_putl16 (-1, eihd.alias);
 
   /* Alloc EIHA.  */
   eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
@@ -3108,7 +3277,7 @@ alpha_vms_write_exec (bfd *abfd)
     unsigned int len;
 
     /* Set module name.  */
-    module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
+    module = vms_get_module_name (bfd_get_filename (abfd), true);
     len = strlen (module);
     if (len > sizeof (eihi->imgnam) - 1)
       len = sizeof (eihi->imgnam) - 1;
@@ -3152,7 +3321,7 @@ alpha_vms_write_exec (bfd *abfd)
   for (sec = abfd->sections; sec; sec = sec->next)
     {
       if (!alpha_vms_create_eisd_for_section (abfd, sec))
-       return FALSE;
+       return false;
     }
 
   /* Merge section EIDS which extra ones.  */
@@ -3170,7 +3339,7 @@ alpha_vms_write_exec (bfd *abfd)
     {
       eisd = bfd_zalloc (abfd, sizeof (*eisd));
       if (eisd == NULL)
-       return FALSE;
+       return false;
       eisd->u.eisd.majorid = 0;
       eisd->u.eisd.minorid = 0;
       eisd->u.eisd.eisdsize = 0;
@@ -3254,7 +3423,7 @@ alpha_vms_write_exec (bfd *abfd)
   /* Write first block.  */
   bfd_putl32 (lnkflags, eihd.lnkflags);
   if (bfd_bwrite (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
-    return FALSE;
+    return false;
 
   /* Write remaining eisd.  */
   if (eisd != NULL)
@@ -3275,7 +3444,7 @@ alpha_vms_write_exec (bfd *abfd)
                  != eisd->file_pos / VMS_BLOCK_SIZE))
            {
              if (bfd_bwrite (blk, sizeof (blk), abfd) != sizeof (blk))
-               return FALSE;
+               return false;
 
              memset (blk, 0xff, sizeof (blk));
            }
@@ -3292,7 +3461,7 @@ alpha_vms_write_exec (bfd *abfd)
       if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS))
        continue;
       if (bfd_bwrite (sec->contents, sec->size, abfd) != sec->size)
-       return FALSE;
+       return false;
 
       /* Pad.  */
       len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE;
@@ -3300,7 +3469,7 @@ alpha_vms_write_exec (bfd *abfd)
        {
          memset (blk, 0, len);
          if (bfd_bwrite (blk, len, abfd) != len)
-           return FALSE;
+           return false;
        }
     }
 
@@ -3362,16 +3531,16 @@ alpha_vms_write_exec (bfd *abfd)
        _bfd_vms_output_end (abfd, recwr);
 
       if (!_bfd_vms_write_eeom (abfd))
-       return FALSE;
+       return false;
     }
-  return TRUE;
+  return true;
 }
 \f
 /* Object write.  */
 
 /* Write section and symbol directory of bfd abfd.  Return FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_write_egsd (bfd *abfd)
 {
   asection *section;
@@ -3594,12 +3763,12 @@ _bfd_vms_write_egsd (bfd *abfd)
   _bfd_vms_output_alignment (recwr, 8);
   _bfd_vms_output_end (abfd, recwr);
 
-  return TRUE;
+  return true;
 }
 
 /* Write object header for bfd abfd.  Return FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_write_ehdr (bfd *abfd)
 {
   asymbol *symbol;
@@ -3648,7 +3817,7 @@ _bfd_vms_write_ehdr (bfd *abfd)
                         39);
   _bfd_vms_output_end (abfd, recwr);
 
-  return TRUE;
+  return true;
 }
 
 /* Part 4.6, relocations.  */
@@ -3769,7 +3938,7 @@ etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
 
 /* Return whether RELOC must be deferred till the end.  */
 
-static bfd_boolean
+static bool
 defer_reloc_p (arelent *reloc)
 {
   switch (reloc->howto->type)
@@ -3778,16 +3947,16 @@ defer_reloc_p (arelent *reloc)
     case ALPHA_R_LDA:
     case ALPHA_R_BSR:
     case ALPHA_R_BOH:
-      return TRUE;
+      return true;
 
     default:
-      return FALSE;
+      return false;
     }
 }
 
 /* Write section contents for bfd abfd.  Return FALSE on error.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
 {
   asection *section;
@@ -3811,7 +3980,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
       if (!section->contents)
        {
          bfd_set_error (bfd_error_no_contents);
-         return FALSE;
+         return false;
        }
 
       start_etir_or_etbt_record (abfd, section, 0);
@@ -3859,7 +4028,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
              bfd_vma addr = rptr->address;
              asymbol *sym = *rptr->sym_ptr_ptr;
              asection *sec = sym->section;
-             bfd_boolean defer = defer_reloc_p (rptr);
+             bool defer = defer_reloc_p (rptr);
              unsigned int slen;
 
              if (pass2_in_progress)
@@ -3879,7 +4048,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
 
                  /* Regular relocs are intertwined with binary data.  */
                  if (curr_addr > addr)
-                   _bfd_error_handler (_("Size error in section %pA"),
+                   _bfd_error_handler (_("size error in section %pA"),
                                        section);
                  size = addr - curr_addr;
                  sto_imm (abfd, section, size, curr_data, curr_addr);
@@ -4000,6 +4169,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  break;
 
                case ALPHA_R_LINKAGE:
+                 size = 16;
                  etir_output_check (abfd, section, curr_addr, 64);
                  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
                  _bfd_vms_output_long
@@ -4038,7 +4208,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  break;
 
                case ALPHA_R_BSR:
-                 _bfd_error_handler (_("Spurious ALPHA_R_BSR reloc"));
+                 _bfd_error_handler (_("spurious ALPHA_R_BSR reloc"));
                  break;
 
                case ALPHA_R_LDA:
@@ -4079,7 +4249,7 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
                  break;
 
                default:
-                 _bfd_error_handler (_("Unhandled relocation %s"),
+                 _bfd_error_handler (_("unhandled relocation %s"),
                                      rptr->howto->name);
                  break;
                }
@@ -4092,7 +4262,10 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
            {
              /* Output rest of section.  */
              if (curr_addr > section->size)
-               _bfd_error_handler (_("Size error in section %pA"), section);
+               {
+                 _bfd_error_handler (_("size error in section %pA"), section);
+                 return false;
+               }
              size = section->size - curr_addr;
              sto_imm (abfd, section, size, curr_data, curr_addr);
              curr_data += size;
@@ -4113,12 +4286,12 @@ _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
     }
 
   _bfd_vms_output_alignment (recwr, 2);
-  return TRUE;
+  return true;
 }
 
 /* Write cached information into a file being written, at bfd_close.  */
 
-static bfd_boolean
+static bool
 alpha_vms_write_object_contents (bfd *abfd)
 {
   vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
@@ -4132,16 +4305,16 @@ alpha_vms_write_object_contents (bfd *abfd)
       if (abfd->section_count > 0)                     /* we have sections */
        {
          if (!_bfd_vms_write_ehdr (abfd))
-           return FALSE;
+           return false;
          if (!_bfd_vms_write_egsd (abfd))
-           return FALSE;
+           return false;
          if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR))
-           return FALSE;
+           return false;
          if (!_bfd_vms_write_eeom (abfd))
-           return FALSE;
+           return false;
        }
     }
-  return TRUE;
+  return true;
 }
 \f
 /* Debug stuff: nearest line.  */
@@ -4165,7 +4338,7 @@ new_module (bfd *abfd)
 
 /* Parse debug info for a module and internalize it.  */
 
-static void
+static bool
 parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
              int length)
 {
@@ -4199,7 +4372,7 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
        {
        case DST__K_MODBEG:
          module->name
-           = _bfd_vms_save_counted_string (ptr + DST_S_B_MODBEG_NAME,
+           = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME,
                                            maxptr - (ptr + DST_S_B_MODBEG_NAME));
 
          curr_pc = 0;
@@ -4217,7 +4390,7 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
          funcinfo = (struct funcinfo *)
            bfd_zalloc (abfd, sizeof (struct funcinfo));
          funcinfo->name
-           = _bfd_vms_save_counted_string (ptr + DST_S_B_RTNBEG_NAME,
+           = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME,
                                            maxptr - (ptr + DST_S_B_RTNBEG_NAME));
          funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
          funcinfo->next = module->func_table;
@@ -4268,19 +4441,20 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
                  {
                    unsigned int fileid
                      = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
-                   char *filename
-                     = _bfd_vms_save_counted_string (src_ptr + DST_S_B_SRC_DF_FILENAME,
-                                                     (ptr + rec_length) -
-                                                     (src_ptr + DST_S_B_SRC_DF_FILENAME)
-                                                     );
+                   char *filename = _bfd_vms_save_counted_string
+                     (abfd,
+                      src_ptr + DST_S_B_SRC_DF_FILENAME,
+                      ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME));
 
                    while (fileid >= module->file_table_count)
                      {
                        module->file_table_count *= 2;
                        module->file_table
-                         = bfd_realloc (module->file_table,
-                                        module->file_table_count
-                                          * sizeof (struct fileinfo));
+                         = bfd_realloc_or_free (module->file_table,
+                                                module->file_table_count
+                                                * sizeof (struct fileinfo));
+                       if (module->file_table == NULL)
+                         return false;
                      }
 
                    module->file_table [fileid].name = filename;
@@ -4433,31 +4607,31 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
 
                case DST__K_SET_LINUM_INCR:
                  _bfd_error_handler
-                   (_("DST__K_SET_LINUM_INCR not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_LINUM_INCR");
                  cmd_length = 2;
                  break;
 
                case DST__K_SET_LINUM_INCR_W:
                  _bfd_error_handler
-                   (_("DST__K_SET_LINUM_INCR_W not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W");
                  cmd_length = 3;
                  break;
 
                case DST__K_RESET_LINUM_INCR:
                  _bfd_error_handler
-                   (_("DST__K_RESET_LINUM_INCR not implemented"));
+                   (_("%s not implemented"), "DST__K_RESET_LINUM_INCR");
                  cmd_length = 1;
                  break;
 
                case DST__K_BEG_STMT_MODE:
                  _bfd_error_handler
-                   (_("DST__K_BEG_STMT_MODE not implemented"));
+                   (_("%s not implemented"), "DST__K_BEG_STMT_MODE");
                  cmd_length = 1;
                  break;
 
                case DST__K_END_STMT_MODE:
                  _bfd_error_handler
-                   (_("DST__K_END_STMT_MODE not implemented"));
+                   (_("%s not implemented"), "DST__K_END_STMT_MODE");
                  cmd_length = 1;
                  break;
 
@@ -4484,25 +4658,25 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
 
                case DST__K_SET_PC:
                  _bfd_error_handler
-                   (_("DST__K_SET_PC not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_PC");
                  cmd_length = 2;
                  break;
 
                case DST__K_SET_PC_W:
                  _bfd_error_handler
-                   (_("DST__K_SET_PC_W not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_PC_W");
                  cmd_length = 3;
                  break;
 
                case DST__K_SET_PC_L:
                  _bfd_error_handler
-                   (_("DST__K_SET_PC_L not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_PC_L");
                  cmd_length = 5;
                  break;
 
                case DST__K_SET_STMTNUM:
                  _bfd_error_handler
-                   (_("DST__K_SET_STMTNUM not implemented"));
+                   (_("%s not implemented"), "DST__K_SET_STMTNUM");
                  cmd_length = 2;
                  break;
 
@@ -4602,6 +4776,7 @@ parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
      because parsing can be either performed at module creation
      or deferred until debug info is consumed.  */
   SET_MODULE_PARSED (module);
+  return true;
 }
 
 /* Build the list of modules for the specified BFD.  */
@@ -4618,7 +4793,7 @@ build_module_list (bfd *abfd)
         section and build the list of modules.  This is sufficient
         since we can compute the start address and the end address
         of every module from the section contents.  */
-      bfd_size_type size = bfd_get_section_size (dmt);
+      bfd_size_type size = bfd_section_size (dmt);
       unsigned char *ptr, *end;
 
       ptr = (unsigned char *) bfd_alloc (abfd, size);
@@ -4679,7 +4854,8 @@ build_module_list (bfd *abfd)
        return NULL;
 
       module = new_module (abfd);
-      parse_module (abfd, module, PRIV (dst_section)->contents, -1);
+      if (!parse_module (abfd, module, PRIV (dst_section)->contents, -1))
+       return NULL;
       list = module;
     }
 
@@ -4689,7 +4865,7 @@ build_module_list (bfd *abfd)
 /* Calculate and return the name of the source file and the line nearest
    to the wanted location in the specified module.  */
 
-static bfd_boolean
+static bool
 module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
                          const char **file, const char **func,
                          unsigned int *line)
@@ -4697,24 +4873,26 @@ module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
   struct funcinfo *funcinfo;
   struct lineinfo *lineinfo;
   struct srecinfo *srecinfo;
-  bfd_boolean ret = FALSE;
+  bool ret = false;
 
   /* Parse this module if that was not done at module creation.  */
   if (! IS_MODULE_PARSED (module))
     {
       unsigned int size = module->size;
       unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
-      unsigned char *buffer = (unsigned char *) bfd_malloc (module->size);
+      unsigned char *buffer;
 
       if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
-         || bfd_bread (buffer, size, abfd) != size)
+         || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL)
        {
          bfd_set_error (bfd_error_no_debug_section);
-         return FALSE;
+         return false;
        }
 
-      parse_module (abfd, module, buffer, size);
+      ret = parse_module (abfd, module, buffer, size);
       free (buffer);
+      if (!ret)
+       return ret;
     }
 
   /* Find out the function (if any) that contains the address.  */
@@ -4722,7 +4900,7 @@ module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
     if (addr >= funcinfo->low && addr <= funcinfo->high)
       {
        *func = funcinfo->name;
-       ret = TRUE;
+       ret = true;
        break;
       }
 
@@ -4743,7 +4921,7 @@ module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
                  *file = module->name;
                  *line = lineinfo->line;
                }
-             return TRUE;
+             return true;
            }
 
        break;
@@ -4756,7 +4934,7 @@ module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
    return the name of the source file and the line nearest to the wanted
    location.  */
 
-static bfd_boolean
+static bool
 _bfd_vms_find_nearest_line (bfd *abfd,
                            asymbol **symbols ATTRIBUTE_UNUSED,
                            asection *section,
@@ -4779,27 +4957,27 @@ _bfd_vms_find_nearest_line (bfd *abfd,
 
   /* We can't do anything if there is no DST (debug symbol table).  */
   if (PRIV (dst_section) == NULL)
-    return FALSE;
+    return false;
 
   /* Create the module list - if not already done.  */
   if (PRIV (modules) == NULL)
     {
       PRIV (modules) = build_module_list (abfd);
       if (PRIV (modules) == NULL)
-       return FALSE;
+       return false;
     }
 
   for (module = PRIV (modules); module; module = module->next)
     if (addr >= module->low && addr <= module->high)
       return module_find_nearest_line (abfd, module, addr, file, func, line);
 
-  return FALSE;
+  return false;
 }
 \f
 /* Canonicalizations.  */
 /* Set name, value, section and flags of SYM from E.  */
 
-static bfd_boolean
+static bool
 alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
 {
   flagword flags;
@@ -4857,14 +5035,14 @@ alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
       break;
 
     default:
-      return FALSE;
+      return false;
     }
 
   sym->name = name;
   sym->section = sec;
   sym->flags = flags;
   sym->value = value;
-  return TRUE;
+  return true;
 }
 
 
@@ -4929,7 +5107,7 @@ alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols)
 
 /* Read and convert relocations from ETIR.  We do it once for all sections.  */
 
-static bfd_boolean
+static bool
 alpha_vms_slurp_relocs (bfd *abfd)
 {
   int cur_psect = -1;
@@ -4938,14 +5116,14 @@ alpha_vms_slurp_relocs (bfd *abfd)
 
   /* We slurp relocs only once, for all sections.  */
   if (PRIV (reloc_done))
-      return TRUE;
-  PRIV (reloc_done) = TRUE;
+      return true;
+  PRIV (reloc_done) = true;
 
   if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
-    return FALSE;
+    return false;
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
-    return FALSE;
+    return false;
 
   while (1)
     {
@@ -5005,9 +5183,9 @@ alpha_vms_slurp_relocs (bfd *abfd)
                {
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
+                   (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
                     _bfd_vms_etir_name (cmd));
-                 return FALSE;
+                 return false;
                }
              cur_psect = cur_psidx;
              vaddr = cur_addend;
@@ -5023,9 +5201,9 @@ alpha_vms_slurp_relocs (bfd *abfd)
                    {
                      _bfd_error_handler
                        /* xgettext:c-format */
-                       (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
+                       (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
                         _bfd_vms_etir_name (ETIR__C_STA_LW));
-                     return FALSE;
+                     return false;
                    }
                }
              cur_addend = bfd_getl32 (ptr + 4);
@@ -5038,9 +5216,9 @@ alpha_vms_slurp_relocs (bfd *abfd)
                {
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
+                   (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
                     _bfd_vms_etir_name (ETIR__C_STA_QW));
-                 return FALSE;
+                 return false;
                }
              cur_addend = bfd_getl64 (ptr + 4);
              prev_cmd = cmd;
@@ -5054,10 +5232,10 @@ alpha_vms_slurp_relocs (bfd *abfd)
                  && prev_cmd != ETIR__C_STA_PQ)
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (_("Unknown reloc %s + %s"),
+                 _bfd_error_handler (_("unknown reloc %s + %s"),
                                      _bfd_vms_etir_name (prev_cmd),
                                      _bfd_vms_etir_name (ETIR__C_STO_LW));
-                 return FALSE;
+                 return false;
                }
              reloc_code = BFD_RELOC_32;
              break;
@@ -5067,10 +5245,10 @@ alpha_vms_slurp_relocs (bfd *abfd)
              if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW)
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (_("Unknown reloc %s + %s"),
+                 _bfd_error_handler (_("unknown reloc %s + %s"),
                                      _bfd_vms_etir_name (prev_cmd),
                                      _bfd_vms_etir_name (ETIR__C_STO_QW));
-                 return FALSE;
+                 return false;
                }
              reloc_code = BFD_RELOC_64;
              break;
@@ -5079,10 +5257,10 @@ alpha_vms_slurp_relocs (bfd *abfd)
              if (prev_cmd != ETIR__C_STA_PQ)
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (_("Unknown reloc %s + %s"),
+                 _bfd_error_handler (_("unknown reloc %s + %s"),
                                      _bfd_vms_etir_name (prev_cmd),
                                      _bfd_vms_etir_name (ETIR__C_STO_OFF));
-                 return FALSE;
+                 return false;
                }
              reloc_code = BFD_RELOC_64;
              break;
@@ -5092,10 +5270,10 @@ alpha_vms_slurp_relocs (bfd *abfd)
              if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW)
                {
                  /* xgettext:c-format */
-                 _bfd_error_handler (_("Unknown reloc %s + %s"),
+                 _bfd_error_handler (_("unknown reloc %s + %s"),
                                      _bfd_vms_etir_name (prev_cmd),
                                      _bfd_vms_etir_name (ETIR__C_OPR_ADD));
-                 return FALSE;
+                 return false;
                }
              prev_cmd = ETIR__C_OPR_ADD;
              continue;
@@ -5147,30 +5325,31 @@ alpha_vms_slurp_relocs (bfd *abfd)
              continue;
 
            default:
-             _bfd_error_handler (_("Unknown reloc %s"),
+             _bfd_error_handler (_("unknown reloc %s"),
                                  _bfd_vms_etir_name (cmd));
-             return FALSE;
+             return false;
            }
 
          {
            asection *sec;
            struct vms_section_data_struct *vms_sec;
            arelent *reloc;
+           bfd_size_type size;
 
            /* Get section to which the relocation applies.  */
            if (cur_psect < 0 || cur_psect > (int)PRIV (section_count))
              {
-               _bfd_error_handler (_("Invalid section index in ETIR"));
-               return FALSE;
+               _bfd_error_handler (_("invalid section index in ETIR"));
+               return false;
              }
 
            if (PRIV (sections) == NULL)
-             return FALSE;
+             return false;
            sec = PRIV (sections)[cur_psect];
            if (sec == bfd_abs_section_ptr)
              {
-               _bfd_error_handler (_("Relocation for non-REL psect"));
-               return FALSE;
+               _bfd_error_handler (_("relocation for non-REL psect"));
+               return false;
              }
 
            vms_sec = vms_section_data (sec);
@@ -5187,8 +5366,10 @@ alpha_vms_slurp_relocs (bfd *abfd)
                else
                  {
                    vms_sec->reloc_max *= 2;
-                   sec->relocation = bfd_realloc
+                   sec->relocation = bfd_realloc_or_free
                      (sec->relocation, vms_sec->reloc_max * sizeof (arelent));
+                   if (sec->relocation == NULL)
+                     return false;
                  }
              }
            reloc = &sec->relocation[sec->reloc_count];
@@ -5216,7 +5397,7 @@ alpha_vms_slurp_relocs (bfd *abfd)
                    }
                if (sym == NULL)
                  {
-                   _bfd_error_handler (_("Unknown symbol in command %s"),
+                   _bfd_error_handler (_("unknown symbol in command %s"),
                                        _bfd_vms_etir_name (cmd));
                    reloc->sym_ptr_ptr = NULL;
                  }
@@ -5226,7 +5407,7 @@ alpha_vms_slurp_relocs (bfd *abfd)
            else if (cur_psidx >= 0)
              {
                if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count))
-                 return FALSE;
+                 return false;
                reloc->sym_ptr_ptr =
                  PRIV (sections)[cur_psidx]->symbol_ptr_ptr;
              }
@@ -5236,7 +5417,11 @@ alpha_vms_slurp_relocs (bfd *abfd)
            reloc->address = cur_address;
            reloc->addend = cur_addend;
 
-           vaddr += bfd_get_reloc_size (reloc->howto);
+           if (reloc_code == ALPHA_R_LINKAGE)
+             size = 16;
+           else
+             size = bfd_get_reloc_size (reloc->howto);
+           vaddr += size;
          }
 
          cur_addend = 0;
@@ -5245,9 +5430,9 @@ alpha_vms_slurp_relocs (bfd *abfd)
          cur_psidx = -1;
        }
     }
-  vms_debug2 ((3, "alpha_vms_slurp_relocs: result = TRUE\n"));
+  vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n"));
 
-  return TRUE;
+  return true;
 }
 
 /* Return the number of bytes required to store the relocation
@@ -5327,30 +5512,30 @@ static reloc_howto_type alpha_howto_table[] =
         0,                     /* Rightshift.  */
         0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         8,                     /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "IGNORE",              /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0,                     /* Source mask */
         0,                     /* Dest mask.  */
-        TRUE),                 /* PC rel offset.  */
+        true),                 /* PC rel offset.  */
 
   /* A 64 bit reference to a symbol.  */
   HOWTO (ALPHA_R_REFQUAD,      /* Type.  */
         0,                     /* Rightshift.  */
         4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         64,                    /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_bitfield, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "REFQUAD",             /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         MINUS_ONE,             /* Source mask.  */
         MINUS_ONE,             /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* A 21 bit branch.  The native assembler generates these for
      branches within the text segment, and also fills in the PC
@@ -5359,90 +5544,90 @@ static reloc_howto_type alpha_howto_table[] =
         2,                     /* Rightshift.  */
         2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         21,                    /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_signed, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "BRADDR",              /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0x1fffff,              /* Source mask.  */
         0x1fffff,              /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* A hint for a jump to a register.  */
   HOWTO (ALPHA_R_HINT,         /* Type.  */
         2,                     /* Rightshift.  */
         1,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         14,                    /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "HINT",                /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0x3fff,                /* Source mask.  */
         0x3fff,                /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* 16 bit PC relative offset.  */
   HOWTO (ALPHA_R_SREL16,       /* Type.  */
         0,                     /* Rightshift.  */
         1,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         16,                    /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_signed, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "SREL16",              /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0xffff,                /* Source mask.  */
         0xffff,                /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* 32 bit PC relative offset.  */
   HOWTO (ALPHA_R_SREL32,       /* Type.  */
         0,                     /* Rightshift.  */
         2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         32,                    /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_signed, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "SREL32",              /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* A 64 bit PC relative offset.  */
   HOWTO (ALPHA_R_SREL64,       /* Type.  */
         0,                     /* Rightshift.  */
         4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         64,                    /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_signed, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "SREL64",              /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         MINUS_ONE,             /* Source mask.  */
         MINUS_ONE,             /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* Push a value on the reloc evaluation stack.  */
   HOWTO (ALPHA_R_OP_PUSH,      /* Type.  */
         0,                     /* Rightshift.  */
         0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "OP_PUSH",             /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0,                     /* Source mask.  */
         0,                     /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* Store the value from the stack at the given address.  Store it in
      a bitfield of size r_size starting at bit position r_offset.  */
@@ -5450,15 +5635,15 @@ static reloc_howto_type alpha_howto_table[] =
         0,                     /* Rightshift.  */
         4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         64,                    /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "OP_STORE",            /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0,                     /* Source mask.  */
         MINUS_ONE,             /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* Subtract the reloc address from the value on the top of the
      relocation stack.  */
@@ -5466,15 +5651,15 @@ static reloc_howto_type alpha_howto_table[] =
         0,                     /* Rightshift.  */
         0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "OP_PSUB",             /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0,                     /* Source mask.  */
         0,                     /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* Shift the value on the top of the relocation stack right by the
      given value.  */
@@ -5482,60 +5667,60 @@ static reloc_howto_type alpha_howto_table[] =
         0,                     /* Rightshift.  */
         0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "OP_PRSHIFT",          /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0,                     /* Source mask.  */
         0,                     /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* Hack. Linkage is done by linker.  */
   HOWTO (ALPHA_R_LINKAGE,      /* Type.  */
         0,                     /* Rightshift.  */
-        8,                     /* Size (0 = byte, 1 = short, 2 = long).  */
-        256,                   /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        0,                     /* Size (0 = byte, 1 = short, 2 = long).  */
+        0,                     /* Bitsize.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "LINKAGE",             /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0,                     /* Source mask.  */
         0,                     /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* A 32 bit reference to a symbol.  */
   HOWTO (ALPHA_R_REFLONG,      /* Type.  */
         0,                     /* Rightshift.  */
         2,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         32,                    /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_bitfield, /* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "REFLONG",             /* Name.  */
-        TRUE,                  /* Partial_inplace.  */
+        true,                  /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   /* A 64 bit reference to a procedure, written as 32 bit value.  */
   HOWTO (ALPHA_R_CODEADDR,     /* Type.  */
         0,                     /* Rightshift.  */
         4,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         64,                    /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_signed,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "CODEADDR",            /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   HOWTO (ALPHA_R_NOP,          /* Type.  */
         0,                     /* Rightshift.  */
@@ -5544,63 +5729,63 @@ static reloc_howto_type alpha_howto_table[] =
         /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
            because the calculations for the 3 relocations are the same.
            See B.4.5.2 of the OpenVMS Linker Utility Manual.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.   */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "NOP",                 /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   HOWTO (ALPHA_R_BSR,          /* Type.  */
         0,                     /* Rightshift.  */
         3,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "BSR",                 /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   HOWTO (ALPHA_R_LDA,          /* Type.  */
         0,                     /* Rightshift.  */
         3,                     /* Size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* Bitsize.  */
-        FALSE,                 /* PC relative.  */
+        false,                 /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "LDA",                 /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 
   HOWTO (ALPHA_R_BOH,          /* Type.  */
         0,                     /* Rightshift.  */
         3,                     /* Size (0 = byte, 1 = short, 2 = long, 3 = nil).  */
         0,                     /* Bitsize.  */
-        TRUE,                  /* PC relative.  */
+        true,                  /* PC relative.  */
         0,                     /* Bitpos.  */
         complain_overflow_dont,/* Complain_on_overflow.  */
         reloc_nil,             /* Special_function.  */
         "BOH",                 /* Name.  */
-        FALSE,                 /* Partial_inplace.  */
+        false,                 /* Partial_inplace.  */
         0xffffffff,            /* Source mask.  */
         0xffffffff,            /* Dest mask.  */
-        FALSE),                /* PC rel offset.  */
+        false),                /* PC rel offset.  */
 };
 
 /* Return a pointer to a howto structure which, when invoked, will perform
    the relocation code on data from the architecture noted.  */
 
-static const struct reloc_howto_struct *
+static reloc_howto_type *
 alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
                                 bfd_reloc_code_real_type code)
 {
@@ -5702,7 +5887,7 @@ alpha_vms_get_synthetic_symtab (bfd *abfd,
       l = strlen (name);
       sname = bfd_alloc (abfd, l + 5);
       if (sname == NULL)
-       return FALSE;
+       return false;
       memcpy (sname, name, l);
       memcpy (sname + l, "..en", 5);
 
@@ -6447,8 +6632,8 @@ evax_bfd_print_etir (FILE *file, const char *name,
 static void
 evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
 {
-  bfd_boolean is_first = TRUE;
-  bfd_boolean has_records = FALSE;
+  bool is_first = true;
+  bool has_records = false;
 
   while (1)
     {
@@ -6462,7 +6647,7 @@ evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
        {
          unsigned char buf[6];
 
-         is_first = FALSE;
+         is_first = false;
 
          /* Read 6 bytes.  */
          if (bfd_bread (buf, sizeof (buf), abfd) != sizeof (buf))
@@ -6475,13 +6660,13 @@ evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
              && bfd_getl16 (buf + 2) == EOBJ__C_EMH)
            {
              /* The format is raw: record-size, type, record-size.  */
-             has_records = TRUE;
+             has_records = true;
              pad_len = (rec_len + 1) & ~1U;
              hdr_size = 4;
            }
          else if (rec_len == EOBJ__C_EMH)
            {
-             has_records = FALSE;
+             has_records = false;
              pad_len = bfd_getl16 (buf + 2);
              hdr_size = 6;
            }
@@ -6605,7 +6790,7 @@ evax_bfd_print_relocation_records (FILE *file, const unsigned char *rel,
          fprintf (file, _("   bitmap: 0x%08x (count: %u):\n"), val, count);
 
          for (k = 0; k < 32; k++)
-           if (val & (1 << k))
+           if (val & (1u << k))
              {
                if (n == 0)
                  fputs ("   ", file);
@@ -7026,8 +7211,8 @@ evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
       dst_size -= len;
       off += len;
       len -= sizeof (dsth);
-      buf = bfd_malloc (len);
-      if (bfd_bread (buf, len, abfd) != len)
+      buf = _bfd_malloc_and_read (abfd, len, len);
+      if (buf == NULL)
        {
          fprintf (file, _("cannot read DST symbol\n"));
          return;
@@ -7942,14 +8127,12 @@ evax_bfd_print_image (bfd *abfd, FILE *file)
       unsigned int codeadroff;
       unsigned int lpfixoff;
       unsigned int chgprtoff;
+      file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE;
 
-      buf = bfd_malloc (eiaf_size);
-
-      if (bfd_seek (abfd, (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)
-         || bfd_bread (buf, eiaf_size, abfd) != eiaf_size)
+      if (bfd_seek (abfd, f_off, SEEK_SET) != 0
+         || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL)
        {
          fprintf (file, _("cannot read EIHA\n"));
-         free (buf);
          return;
        }
       eiaf = (struct vms_eiaf *)buf;
@@ -8124,7 +8307,7 @@ evax_bfd_print_image (bfd *abfd, FILE *file)
     }
 }
 
-static bfd_boolean
+static bool
 vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
 {
   FILE *file = (FILE *)ptr;
@@ -8134,17 +8317,17 @@ vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
   else
     {
       if (bfd_seek (abfd, 0, SEEK_SET))
-       return FALSE;
+       return false;
       evax_bfd_print_eobj (abfd, file);
     }
-  return TRUE;
+  return true;
 }
 \f
 /* Linking.  */
 
 /* Slurp ETIR/EDBG/ETBT VMS object records.  */
 
-static bfd_boolean
+static bool
 alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
 {
   asection *cur_section;
@@ -8153,7 +8336,7 @@ alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
   file_ptr dst_offset;
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
-    return FALSE;
+    return false;
 
   cur_section = NULL;
   cur_offset = 0;
@@ -8178,13 +8361,13 @@ alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
   while (1)
     {
       int type;
-      bfd_boolean res;
+      bool res;
 
       type = _bfd_vms_get_object_record (abfd);
       if (type < 0)
        {
          vms_debug2 ((2, "next_record failed\n"));
-         return FALSE;
+         return false;
        }
       switch (type)
        {
@@ -8205,14 +8388,14 @@ alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
          dst_offset = PRIV (image_offset);
          break;
        case EOBJ__C_EEOM:
-         return TRUE;
+         return true;
        default:
          continue;
        }
       if (!res)
        {
          vms_debug2 ((2, "slurp eobj type %d failed\n", type));
-         return FALSE;
+         return false;
        }
     }
 }
@@ -8226,41 +8409,49 @@ alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */
 
-static void
+static bool
 alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib)
 {
   struct alpha_vms_shlib_el *sl;
   asection *sect = PRIV2 (src, image_section);
   file_ptr offset = PRIV2 (src, image_offset);
+  bfd_vma *p;
 
   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
                struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
-  sl->has_fixups = TRUE;
-  VEC_APPEND_EL (sl->lp, bfd_vma,
-                sect->output_section->vma + sect->output_offset + offset);
+  sl->has_fixups = true;
+  p = VEC_APPEND (sl->lp, bfd_vma);
+  if (p == NULL)
+    return false;
+  *p = sect->output_section->vma + sect->output_offset + offset;
   sect->output_section->flags |= SEC_RELOC;
+  return true;
 }
 
 /* Add a code address fixup at address SECT + OFFSET to SHLIB. */
 
-static void
+static bool
 alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib)
 {
   struct alpha_vms_shlib_el *sl;
   asection *sect = PRIV2 (src, image_section);
   file_ptr offset = PRIV2 (src, image_offset);
+  bfd_vma *p;
 
   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
                struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
-  sl->has_fixups = TRUE;
-  VEC_APPEND_EL (sl->ca, bfd_vma,
-                sect->output_section->vma + sect->output_offset + offset);
+  sl->has_fixups = true;
+  p = VEC_APPEND (sl->ca, bfd_vma);
+  if (p == NULL)
+    return false;
+  *p = sect->output_section->vma + sect->output_offset + offset;
   sect->output_section->flags |= SEC_RELOC;
+  return true;
 }
 
 /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */
 
-static void
+static bool
 alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
                        bfd *shlib, bfd_vma vec)
 {
@@ -8271,32 +8462,37 @@ alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
 
   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
                struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
-  sl->has_fixups = TRUE;
+  sl->has_fixups = true;
   r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref);
+  if (r == NULL)
+    return false;
   r->vma = sect->output_section->vma + sect->output_offset + offset;
   r->ref = vec;
   sect->output_section->flags |= SEC_RELOC;
+  return true;
 }
 
-static void
+static bool
 alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                        unsigned int shr ATTRIBUTE_UNUSED,
                        bfd_vma vec ATTRIBUTE_UNUSED)
 {
   /* Not yet supported.  */
-  abort ();
+  return false;
 }
 
 /* Add relocation.  FIXME: Not yet emitted.  */
 
-static void
+static bool
 alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
+  return false;
 }
 
-static void
+static bool
 alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
+  return false;
 }
 
 static struct bfd_hash_entry *
@@ -8326,13 +8522,34 @@ alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry,
   return (struct bfd_hash_entry *) ret;
 }
 
+static void
+alpha_vms_bfd_link_hash_table_free (bfd *abfd)
+{
+  struct alpha_vms_link_hash_table *t;
+  unsigned i;
+
+  t = (struct alpha_vms_link_hash_table *) abfd->link.hash;
+  for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
+    {
+      struct alpha_vms_shlib_el *shlib;
+
+      shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
+      free (&VEC_EL (shlib->ca, bfd_vma, 0));
+      free (&VEC_EL (shlib->lp, bfd_vma, 0));
+      free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0));
+    }
+  free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0));
+
+  _bfd_generic_link_hash_table_free (abfd);
+}
+
 /* Create an Alpha/VMS link hash table.  */
 
 static struct bfd_link_hash_table *
 alpha_vms_bfd_link_hash_table_create (bfd *abfd)
 {
   struct alpha_vms_link_hash_table *ret;
-  bfd_size_type amt = sizeof (struct alpha_vms_link_hash_table);
+  size_t amt = sizeof (struct alpha_vms_link_hash_table);
 
   ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
@@ -8347,11 +8564,12 @@ alpha_vms_bfd_link_hash_table_create (bfd *abfd)
 
   VEC_INIT (ret->shrlibs);
   ret->fixup = NULL;
+  ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free;
 
   return &ret->root;
 }
 
-static bfd_boolean
+static bool
 alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 {
   unsigned int i;
@@ -8364,14 +8582,14 @@ alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       asymbol sym;
 
       if (!alpha_vms_convert_symbol (abfd, e, &sym))
-       return FALSE;
+       return false;
 
       if ((e->flags & EGSY__V_DEF) && abfd->selective_search)
        {
          /* In selective_search mode, only add definition that are
             required.  */
          h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup
-           (info->hash, sym.name, FALSE, FALSE, FALSE);
+           (info->hash, sym.name, false, false, false);
          if (h == NULL || h->root.type != bfd_link_hash_undefined)
            continue;
        }
@@ -8381,8 +8599,8 @@ alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       h_root = (struct bfd_link_hash_entry *) h;
       if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags,
                                             sym.section, sym.value, NULL,
-                                            FALSE, FALSE, &h_root))
-       return FALSE;
+                                            false, false, &h_root))
+       return false;
       h = (struct alpha_vms_link_hash_entry *) h_root;
 
       if ((e->flags & EGSY__V_DEF)
@@ -8401,6 +8619,8 @@ alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 
       shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs,
                          struct alpha_vms_shlib_el);
+      if (shlib == NULL)
+       return false;
       shlib->abfd = abfd;
       VEC_INIT (shlib->ca);
       VEC_INIT (shlib->lp);
@@ -8408,10 +8628,10 @@ alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
 {
   int pass;
@@ -8422,7 +8642,7 @@ alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
   if (info->output_bfd->xvec != abfd->xvec)
     {
       bfd_set_error (bfd_error_wrong_format);
-      return FALSE;
+      return false;
     }
 
   /* The archive_pass field in the archive itself is used to
@@ -8469,7 +8689,7 @@ alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
 
       element = bfd_get_elt_at_index (abfd, symidx);
       if (element == NULL)
-       return FALSE;
+       return false;
 
       if (element->archive_pass == -1 || element->archive_pass == pass)
        {
@@ -8480,7 +8700,7 @@ alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
       if (! bfd_check_format (element, bfd_object))
        {
          element->archive_pass = -1;
-         return FALSE;
+         return false;
        }
 
       orig_element = element;
@@ -8490,7 +8710,7 @@ alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
          if (element == NULL || !bfd_check_format (element, bfd_object))
            {
              orig_element->archive_pass = -1;
-             return FALSE;
+             return false;
            }
        }
 
@@ -8501,15 +8721,15 @@ alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
            ->add_archive_element) (info, element, h->root.string, &element))
        continue;
       if (!alpha_vms_link_add_object_symbols (element, info))
-       return FALSE;
+       return false;
 
       orig_element->archive_pass = pass;
     }
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
 {
   switch (bfd_get_format (abfd))
@@ -8526,11 +8746,11 @@ alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
       break;
     default:
       bfd_set_error (bfd_error_wrong_format);
-      return FALSE;
+      return false;
     }
 }
 
-static bfd_boolean
+static bool
 alpha_vms_build_fixups (struct bfd_link_info *info)
 {
   struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info);
@@ -8588,7 +8808,7 @@ alpha_vms_build_fixups (struct bfd_link_info *info)
 
   /* Finish now if there is no content.  */
   if (ca_sz + lp_sz + qr_sz == 0)
-    return TRUE;
+    return true;
 
   /* Add an eicp entry for the fixup itself.  */
   chgprt_num = 1;
@@ -8607,7 +8827,7 @@ alpha_vms_build_fixups (struct bfd_link_info *info)
   sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
   content = bfd_zalloc (info->output_bfd, sz);
   if (content == NULL)
-    return FALSE;
+    return false;
 
   sec = alpha_vms_link_hash (info)->fixup;
   sec->contents = content;
@@ -8795,13 +9015,13 @@ alpha_vms_build_fixups (struct bfd_link_info *info)
       off += sizeof (struct vms_eicp);
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Called by bfd_hash_traverse to fill the symbol table.
    Return FALSE in case of failure.  */
 
-static bfd_boolean
+static bool
 alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
 {
   struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh;
@@ -8813,19 +9033,19 @@ alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
     {
       hc = hc->u.i.link;
       if (hc->type == bfd_link_hash_new)
-       return TRUE;
+       return true;
     }
   h = (struct alpha_vms_link_hash_entry *) hc;
 
   switch (h->root.type)
     {
     case bfd_link_hash_undefined:
-      return TRUE;
+      return true;
     case bfd_link_hash_new:
     case bfd_link_hash_warning:
       abort ();
     case bfd_link_hash_undefweak:
-      return TRUE;
+      return true;
     case bfd_link_hash_defined:
     case bfd_link_hash_defweak:
       {
@@ -8833,23 +9053,23 @@ alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
 
        /* FIXME: this is certainly a symbol from a dynamic library.  */
        if (bfd_is_abs_section (sec))
-         return TRUE;
+         return true;
 
        if (sec->owner->flags & DYNAMIC)
-         return TRUE;
+         return true;
       }
       break;
     case bfd_link_hash_common:
       break;
     case bfd_link_hash_indirect:
-      return TRUE;
+      return true;
     }
 
   /* Do not write not kept symbols.  */
   if (info->strip == strip_some
       && bfd_hash_lookup (info->keep_hash, h->root.root.string,
-                         FALSE, FALSE) != NULL)
-    return TRUE;
+                         false, false) != NULL)
+    return true;
 
   if (h->sym == NULL)
     {
@@ -8877,12 +9097,12 @@ alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
     sym = h->sym;
 
   if (!add_symbol_entry (info->output_bfd, sym))
-    return FALSE;
+    return false;
 
-  return TRUE;
+  return true;
 }
 
-static bfd_boolean
+static bool
 alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 {
   asection *o;
@@ -8899,17 +9119,17 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
       /* FIXME: we do not yet support relocatable link.  It is not obvious
         how to do it for debug infos.  */
       (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n"));
-      return FALSE;
+      return false;
     }
 
-  bfd_get_outsymbols (abfd) = NULL;
-  bfd_get_symcount (abfd) = 0;
+  abfd->outsymbols = NULL;
+  abfd->symcount = 0;
 
   /* Mark all sections which will be included in the output file.  */
   for (o = abfd->sections; o != NULL; o = o->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;
+       p->u.indirect.section->linker_mark = true;
 
 #if 0
   /* Handle all the link order information for the sections.  */
@@ -8996,7 +9216,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 
     i = 0;
     PRIV (transfer_address[i++]) = 0xffffffff00000340ULL;      /* SYS$IMGACT */
-    h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", FALSE, FALSE, TRUE);
+    h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", false, false, true);
     if (h != NULL && h->type == bfd_link_hash_defined)
       PRIV (transfer_address[i++]) =
        alpha_vms_get_sym_value (h->u.def.section, h->u.def.value);
@@ -9015,7 +9235,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        {
          o->contents = bfd_alloc (abfd, o->size);
          if (o->contents == NULL)
-           return FALSE;
+           return false;
        }
       if (o->flags & SEC_LOAD)
        {
@@ -9034,7 +9254,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
     (info->output_bfd, "$FIXUP$",
      SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
   if (fixupsec == NULL)
-    return FALSE;
+    return false;
   last_addr = (last_addr + 0xffff) & ~0xffff;
   fixupsec->vma = last_addr;
 
@@ -9053,7 +9273,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        (info->output_bfd, "$DMT$",
         SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
       if (dmt == NULL)
-       return FALSE;
+       return false;
     }
   else
     dmt = NULL;
@@ -9068,7 +9288,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        }
 
       if (!alpha_vms_read_sections_content (sub, info))
-       return FALSE;
+       return false;
     }
 
   /* Handle all the link order information for the sections.
@@ -9082,13 +9302,13 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
            case bfd_section_reloc_link_order:
            case bfd_symbol_reloc_link_order:
              abort ();
-             return FALSE;
+             return false;
            case bfd_indirect_link_order:
              /* Already done.  */
              break;
            default:
              if (! _bfd_default_link_order (abfd, info, o, p))
-               return FALSE;
+               return false;
              break;
            }
        }
@@ -9096,7 +9316,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
 
   /* Compute fixups.  */
   if (!alpha_vms_build_fixups (info))
-    return FALSE;
+    return false;
 
   /* Compute the DMT.  */
   if (dmt != NULL)
@@ -9162,7 +9382,7 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
            {
              contents = bfd_zalloc (info->output_bfd, off);
              if (contents == NULL)
-               return FALSE;
+               return false;
              dmt->contents = contents;
              dmt->size = off;
            }
@@ -9173,14 +9393,14 @@ alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        }
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Read the contents of a section.
    buf points to a buffer of buf_size bytes to be filled with
    section data (starting at offset into section)  */
 
-static bfd_boolean
+static bool
 alpha_vms_get_section_contents (bfd *abfd, asection *section,
                                void *buf, file_ptr offset,
                                bfd_size_type count)
@@ -9197,7 +9417,7 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
       || offset + count > section->size)
     {
       bfd_set_error (bfd_error_invalid_operation);
-      return FALSE;
+      return false;
     }
 
   /* If the section is already in memory, just copy it.  */
@@ -9205,10 +9425,10 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
     {
       BFD_ASSERT (section->contents != NULL);
       memcpy (buf, section->contents + offset, count);
-      return TRUE;
+      return true;
     }
   if (section->size == 0)
-    return TRUE;
+    return true;
 
   /* Alloc in memory and read ETIRs.  */
   for (sec = abfd->sections; sec; sec = sec->next)
@@ -9219,22 +9439,22 @@ alpha_vms_get_section_contents (bfd *abfd, asection *section,
        {
          sec->contents = bfd_alloc (abfd, sec->size);
          if (sec->contents == NULL)
-           return FALSE;
+           return false;
        }
     }
   if (!alpha_vms_read_sections_content (abfd, NULL))
-    return FALSE;
+    return false;
   for (sec = abfd->sections; sec; sec = sec->next)
     if (sec->contents)
       sec->flags |= SEC_IN_MEMORY;
   memcpy (buf, section->contents + offset, count);
-  return TRUE;
+  return true;
 }
 
 
 /* Set the format of a file being written.  */
 
-static bfd_boolean
+static bool
 alpha_vms_mkobject (bfd * abfd)
 {
   const bfd_arch_info_type *arch;
@@ -9242,22 +9462,22 @@ alpha_vms_mkobject (bfd * abfd)
   vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd));
 
   if (!vms_initialize (abfd))
-    return FALSE;
+    return false;
 
   PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE);
   if (PRIV (recwr.buf) == NULL)
-    return FALSE;
+    return false;
 
   arch = bfd_scan_arch ("alpha");
 
   if (arch == 0)
     {
       bfd_set_error (bfd_error_wrong_format);
-      return FALSE;
+      return false;
     }
 
   abfd->arch_info = arch;
-  return TRUE;
+  return true;
 }
 
 
@@ -9265,64 +9485,53 @@ alpha_vms_mkobject (bfd * abfd)
 
 /* Called when the BFD is being closed to do any necessary cleanup.  */
 
-static bfd_boolean
+static bool
 vms_close_and_cleanup (bfd * abfd)
 {
   vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
 
   if (abfd == NULL || abfd->tdata.any == NULL)
-    return TRUE;
+    return true;
 
-  if (abfd->format == bfd_archive)
+  if (abfd->format == bfd_object)
     {
-      bfd_release (abfd, abfd->tdata.any);
-      abfd->tdata.any = NULL;
-      return TRUE;
-    }
-
-  if (PRIV (recrd.buf) != NULL)
-    free (PRIV (recrd.buf));
-
-  if (PRIV (sections) != NULL)
-    free (PRIV (sections));
-
-  bfd_release (abfd, abfd->tdata.any);
-  abfd->tdata.any = NULL;
+      alpha_vms_free_private (abfd);
 
 #ifdef VMS
-  if (abfd->direction == write_direction)
-    {
-      /* Last step on VMS is to convert the file to variable record length
-        format.  */
-      if (!bfd_cache_close (abfd))
-       return FALSE;
-      if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename))
-       return FALSE;
-    }
+      if (abfd->direction == write_direction)
+       {
+         /* Last step on VMS is to convert the file to variable record length
+            format.  */
+         if (!bfd_cache_close (abfd))
+           return false;
+         if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename))
+           return false;
+       }
 #endif
+    }
 
-  return TRUE;
+  return _bfd_generic_close_and_cleanup (abfd);
 }
 
 /* Called when a new section is created.  */
 
-static bfd_boolean
+static bool
 vms_new_section_hook (bfd * abfd, asection *section)
 {
-  bfd_size_type amt;
+  size_t amt;
 
   vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n",
               abfd, section->index, section->name));
 
-  if (! bfd_set_section_alignment (abfd, section, 0))
-    return FALSE;
+  if (!bfd_set_section_alignment (section, 0))
+    return false;
 
   vms_debug2 ((7, "%u: %s\n", section->index, section->name));
 
   amt = sizeof (struct vms_section_data_struct);
   section->used_by_bfd = bfd_zalloc (abfd, amt);
   if (section->used_by_bfd == NULL)
-    return FALSE;
+    return false;
 
   /* Create the section symbol.  */
   return _bfd_generic_new_section_hook (abfd, section);
@@ -9402,11 +9611,11 @@ vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
   else if (bfd_is_ind_section (sec))
     ret->type = 'I';
   else if ((symbol->flags & BSF_FUNCTION)
-          || (bfd_get_section_flags (abfd, sec) & SEC_CODE))
+          || (bfd_section_flags (sec) & SEC_CODE))
     ret->type = 'T';
-  else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
+  else if (bfd_section_flags (sec) & SEC_DATA)
     ret->type = 'D';
-  else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
+  else if (bfd_section_flags (sec) & SEC_ALLOC)
     ret->type = 'B';
   else
     ret->type = '?';
@@ -9421,7 +9630,7 @@ vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
 /* Return TRUE if the given symbol sym in the BFD abfd is
    a compiler generated local label, else return FALSE.  */
 
-static bfd_boolean
+static bool
 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
                             const char *name)
 {
@@ -9439,7 +9648,7 @@ vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
        SEC_HAS_CONTENTS attribute, so nothing can be written to it.
    o and some more too  */
 
-static bfd_boolean
+static bool
 _bfd_vms_set_section_contents (bfd * abfd,
                               asection *section,
                               const void * location,
@@ -9450,25 +9659,25 @@ _bfd_vms_set_section_contents (bfd * abfd,
     {
       section->contents = bfd_alloc (abfd, section->size);
       if (section->contents == NULL)
-       return FALSE;
+       return false;
 
       memcpy (section->contents + offset, location, (size_t) count);
     }
 
-  return TRUE;
+  return true;
 }
 
 /* Set the architecture and machine type in BFD abfd to arch and mach.
    Find the correct pointer to a structure and insert it into the arch_info
    pointer.  */
 
-static bfd_boolean
+static bool
 alpha_vms_set_arch_mach (bfd *abfd,
                         enum bfd_architecture arch, unsigned long mach)
 {
   if (arch != bfd_arch_alpha
       && arch != bfd_arch_unknown)
-    return FALSE;
+    return false;
 
   return bfd_default_set_arch_mach (abfd, arch, mach);
 }
@@ -9494,9 +9703,11 @@ bfd_vms_get_data (bfd *abfd)
 #define vms_bfd_copy_link_hash_symbol_type \
   _bfd_generic_copy_link_hash_symbol_type
 #define vms_bfd_is_group_section         bfd_generic_is_group_section
+#define vms_bfd_group_name               bfd_generic_group_name
 #define vms_bfd_discard_group            bfd_generic_discard_group
 #define vms_section_already_linked       _bfd_generic_section_already_linked
 #define vms_bfd_define_common_symbol     bfd_generic_define_common_symbol
+#define vms_bfd_link_hide_symbol         _bfd_generic_link_hide_symbol
 #define vms_bfd_define_start_stop         bfd_generic_define_start_stop
 #define vms_bfd_copy_private_header_data  _bfd_generic_bfd_copy_private_header_data
 
@@ -9539,11 +9750,13 @@ bfd_vms_get_data (bfd *abfd)
 #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
+#define alpha_vms_bfd_group_name bfd_generic_group_name
 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
 #define alpha_vms_section_already_linked \
   _bfd_generic_section_already_linked
 
 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
+#define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
 #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop
 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
 #define alpha_vms_bfd_copy_link_hash_symbol_type \
@@ -9577,6 +9790,7 @@ const bfd_target alpha_vms_vec =
   ' ',                         /* ar_pad_char.  */
   15,                          /* ar_max_namelen.  */
   0,                           /* match priority.  */
+  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
This page took 0.086101 seconds and 4 git commands to generate.