Home | History | Annotate | Line # | Download | only in bfd
      1 /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files.
      2    Copyright (C) 1996-2026 Free Software Foundation, Inc.
      3 
      4    Initial version written by Klaus Kaempf (kkaempf (at) rmi.de)
      5    Major rewrite by Adacore.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program; if not, write to the Free Software
     19    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20    MA 02110-1301, USA.  */
     21 
     22 /* TODO:
     23    o  overlayed sections
     24    o  PIC
     25    o  Generation of shared image
     26    o  Relocation optimizations
     27    o  EISD for the stack
     28    o  Vectors isect
     29    o  64 bits sections
     30    o  Entry point
     31    o  LIB$INITIALIZE
     32    o  protected sections (for messages)
     33    ...
     34 */
     35 
     36 #include "sysdep.h"
     37 #include <limits.h>
     38 #include "bfd.h"
     39 #include "bfdlink.h"
     40 #include "libbfd.h"
     41 #include "bfdver.h"
     42 
     43 #include "vms.h"
     44 #include "vms/eihd.h"
     45 #include "vms/eiha.h"
     46 #include "vms/eihi.h"
     47 #include "vms/eihs.h"
     48 #include "vms/eisd.h"
     49 #include "vms/dmt.h"
     50 #include "vms/dst.h"
     51 #include "vms/eihvn.h"
     52 #include "vms/eobjrec.h"
     53 #include "vms/egsd.h"
     54 #include "vms/egps.h"
     55 #include "vms/esgps.h"
     56 #include "vms/eeom.h"
     57 #include "vms/emh.h"
     58 #include "vms/eiaf.h"
     59 #include "vms/shl.h"
     60 #include "vms/eicp.h"
     61 #include "vms/etir.h"
     62 #include "vms/egsy.h"
     63 #include "vms/esdf.h"
     64 #include "vms/esdfm.h"
     65 #include "vms/esdfv.h"
     66 #include "vms/esrf.h"
     67 #include "vms/egst.h"
     68 #include "vms/eidc.h"
     69 #include "vms/dsc.h"
     70 #include "vms/prt.h"
     71 #include "vms/internal.h"
     72 
     73 
     75 #define MIN(a,b) ((a) < (b) ? (a) : (b))
     76 #ifndef CHAR_BIT
     77 #define CHAR_BIT 8
     78 #endif
     79 
     80 /* The r_type field in a reloc is one of the following values.  */
     81 #define ALPHA_R_IGNORE		0
     82 #define ALPHA_R_REFQUAD		1
     83 #define ALPHA_R_BRADDR		2
     84 #define ALPHA_R_HINT		3
     85 #define ALPHA_R_SREL16		4
     86 #define ALPHA_R_SREL32		5
     87 #define ALPHA_R_SREL64		6
     88 #define ALPHA_R_OP_PUSH		7
     89 #define ALPHA_R_OP_STORE	8
     90 #define ALPHA_R_OP_PSUB		9
     91 #define ALPHA_R_OP_PRSHIFT	10
     92 #define ALPHA_R_LINKAGE		11
     93 #define ALPHA_R_REFLONG		12
     94 #define ALPHA_R_CODEADDR	13
     95 #define ALPHA_R_NOP		14
     96 #define ALPHA_R_BSR		15
     97 #define ALPHA_R_LDA		16
     98 #define ALPHA_R_BOH		17
     99 
    100 /* These are used with DST_S_C_LINE_NUM.  */
    101 #define DST_S_C_LINE_NUM_HEADER_SIZE 4
    102 
    103 /* These are used with DST_S_C_SOURCE */
    104 
    105 #define DST_S_B_PCLINE_UNSBYTE	 1
    106 #define DST_S_W_PCLINE_UNSWORD	 1
    107 #define DST_S_L_PCLINE_UNSLONG	 1
    108 
    109 #define DST_S_B_MODBEG_NAME	14
    110 #define DST_S_L_RTNBEG_ADDRESS	 5
    111 #define DST_S_B_RTNBEG_NAME	13
    112 #define DST_S_L_RTNEND_SIZE	 5
    113 
    114 /* These are used with DST_S_C_SOURCE.  */
    115 #define DST_S_C_SOURCE_HEADER_SIZE 4
    116 
    117 #define DST_S_B_SRC_DF_LENGTH	  1
    118 #define DST_S_W_SRC_DF_FILEID	  3
    119 #define DST_S_B_SRC_DF_FILENAME	 20
    120 #define DST_S_B_SRC_UNSBYTE	  1
    121 #define DST_S_W_SRC_UNSWORD	  1
    122 #define DST_S_L_SRC_UNSLONG	  1
    123 
    124 /* Debugger symbol definitions.  */
    125 
    126 #define DBG_S_L_DMT_MODBEG	 0
    127 #define DBG_S_L_DST_SIZE	 4
    128 #define DBG_S_W_DMT_PSECT_COUNT	 8
    129 #define DBG_S_C_DMT_HEADER_SIZE 12
    130 
    131 #define DBG_S_L_DMT_PSECT_START	 0
    132 #define DBG_S_L_DMT_PSECT_LENGTH 4
    133 #define DBG_S_C_DMT_PSECT_SIZE	 8
    134 
    135 /* VMS module header.  */
    136 
    137 struct hdr_struct
    138 {
    139   char hdr_b_strlvl;
    140   int hdr_l_arch1;
    141   int hdr_l_arch2;
    142   int hdr_l_recsiz;
    143   char *hdr_t_name;
    144   char *hdr_t_version;
    145   char *hdr_t_date;
    146   char *hdr_c_lnm;
    147   char *hdr_c_src;
    148   char *hdr_c_ttl;
    149 };
    150 
    151 #define EMH_DATE_LENGTH  17
    152 
    153 /* VMS End-Of-Module records (EOM/EEOM).  */
    154 
    155 struct eom_struct
    156 {
    157   unsigned int eom_l_total_lps;
    158   unsigned short eom_w_comcod;
    159   bool eom_has_transfer;
    160   unsigned char eom_b_tfrflg;
    161   unsigned int eom_l_psindx;
    162   unsigned int eom_l_tfradr;
    163 };
    164 
    165 struct vms_symbol_entry
    166 {
    167   bfd *owner;
    168 
    169   /* Common fields.  */
    170   unsigned char typ;
    171   unsigned char data_type;
    172   unsigned short flags;
    173 
    174   /* Section and offset/value of the symbol.  */
    175   unsigned int value;
    176   asection *section;
    177 
    178   /* Section and offset/value for the entry point (only for subprg).  */
    179   asection *code_section;
    180   unsigned int code_value;
    181 
    182   /* Symbol vector offset.  */
    183   unsigned int symbol_vector;
    184 
    185   /* Length of the name.  */
    186   unsigned char namelen;
    187 
    188   char name[1];
    189 };
    190 
    191 /* Stack value for push/pop commands.  */
    192 
    193 struct stack_struct
    194 {
    195   bfd_vma value;
    196   unsigned int reloc;
    197 };
    198 
    199 #define STACKSIZE 128
    200 
    201 /* A minimal decoding of DST compilation units.  We only decode
    202    what's needed to get to the line number information.  */
    203 
    204 struct fileinfo
    205 {
    206   char *name;
    207   unsigned int srec;
    208 };
    209 
    210 struct srecinfo
    211 {
    212   struct srecinfo *next;
    213   unsigned int line;
    214   unsigned int sfile;
    215   unsigned int srec;
    216 };
    217 
    218 struct lineinfo
    219 {
    220   struct lineinfo *next;
    221   bfd_vma address;
    222   unsigned int line;
    223 };
    224 
    225 struct funcinfo
    226 {
    227   struct funcinfo *next;
    228   char *name;
    229   bfd_vma low;
    230   bfd_vma high;
    231 };
    232 
    233 struct module
    234 {
    235   /* Chain the previously read compilation unit.  */
    236   struct module *next;
    237 
    238   /* The module name.  */
    239   char *name;
    240 
    241   /* The start offset and size of debug info in the DST section.  */
    242   unsigned int modbeg;
    243   unsigned int size;
    244 
    245   /* The lowest and highest addresses contained in this compilation
    246      unit as specified in the compilation unit header.  */
    247   bfd_vma low;
    248   bfd_vma high;
    249 
    250   /* The listing line table.  */
    251   struct lineinfo *line_table;
    252 
    253   /* The source record table.  */
    254   struct srecinfo *srec_table;
    255 
    256   /* A list of the functions found in this module.  */
    257   struct funcinfo *func_table;
    258 
    259   /* Current allocation of file_table.  */
    260   unsigned int file_table_count;
    261 
    262   /* An array of the files making up this module.  */
    263   struct fileinfo *file_table;
    264 };
    265 
    266 /* BFD private data for alpha-vms.  */
    267 
    268 struct vms_private_data_struct
    269 {
    270   /* If 1, relocs have been read successfully, if 0 they have yet to be
    271      read, if -1 reading relocs failed.  */
    272   int reloc_done;
    273 
    274   /* Record input buffer.  */
    275   struct vms_rec_rd recrd;
    276   struct vms_rec_wr recwr;
    277 
    278   struct hdr_struct hdr_data;		/* data from HDR/EMH record  */
    279   struct eom_struct eom_data;		/* data from EOM/EEOM record  */
    280 
    281   /* Transfer addresses (entry points).  */
    282   bfd_vma transfer_address[4];
    283 
    284   /* Array of GSD sections to get the correspond BFD one.  */
    285   unsigned int section_max;		/* Size of the sections array.  */
    286   unsigned int section_count;		/* Number of GSD sections.  */
    287   asection **sections;
    288 
    289   /* Array of raw symbols.  */
    290   struct vms_symbol_entry **syms;
    291 
    292   /* Canonicalized symbols.  */
    293   asymbol **csymbols;
    294 
    295   /* Number of symbols.  */
    296   unsigned int gsd_sym_count;
    297   /* Size of the syms array.  */
    298   unsigned int max_sym_count;
    299   /* Number of procedure symbols.  */
    300   unsigned int norm_sym_count;
    301 
    302   /* Stack used to evaluate TIR/ETIR commands.  */
    303   struct stack_struct *stack;
    304   int stackptr;
    305 
    306   /* Content reading.  */
    307   asection *image_section;		/* section for image_ptr  */
    308   ufile_ptr image_offset;		/* Offset for image_ptr.  */
    309 
    310   struct module *modules;		/* list of all compilation units */
    311 
    312   /* The DST section.  */
    313   asection *dst_section;
    314 
    315   unsigned int dst_ptr_offsets_count;	/* # of offsets in following array  */
    316   unsigned int *dst_ptr_offsets;	/* array of saved image_ptr offsets */
    317 
    318   /* Shared library support */
    319   bfd_vma symvva; /* relative virtual address of symbol vector */
    320   unsigned int ident;
    321   unsigned char matchctl;
    322 
    323   /* Shared library index.  This is used for input bfd while linking.  */
    324   unsigned int shr_index;
    325 
    326   /* Used to place structures in the file.  */
    327   file_ptr file_pos;
    328 
    329   /* Simply linked list of eisd.  */
    330   struct vms_internal_eisd_map *eisd_head;
    331   struct vms_internal_eisd_map *eisd_tail;
    332 
    333   /* Simply linked list of eisd for shared libraries.  */
    334   struct vms_internal_eisd_map *gbl_eisd_head;
    335   struct vms_internal_eisd_map *gbl_eisd_tail;
    336 
    337   /* linkage index counter used by conditional store commands */
    338   unsigned int vms_linkage_index;
    339 };
    340 
    341 #define PRIV2(abfd, name) \
    342   (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
    343 #define PRIV(name) PRIV2(abfd,name)
    344 
    345 
    346 /* Used to keep extra VMS specific information for a given section.
    347 
    348    reloc_size holds the size of the relocation stream, note this
    349    is very different from the number of relocations as VMS relocations
    350    are variable length.
    351 
    352    reloc_stream is the actual stream of relocation entries.  */
    353 
    354 struct vms_section_data_struct
    355 {
    356   /* Maximnum number of entries in sec->relocation.  */
    357   unsigned reloc_max;
    358 
    359   /* Corresponding eisd.  Used only while generating executables.  */
    360   struct vms_internal_eisd_map *eisd;
    361 
    362   /* PSC flags to be clear.  */
    363   flagword no_flags;
    364 
    365   /* PSC flags to be set.  */
    366   flagword flags;
    367 };
    368 
    369 #define vms_section_data(sec) \
    370   ((struct vms_section_data_struct *)sec->used_by_bfd)
    371 
    372 /* To be called from the debugger.  */
    373 struct vms_private_data_struct *bfd_vms_get_data (bfd *);
    374 
    375 static int vms_get_remaining_object_record (bfd *, unsigned int);
    376 static bool _bfd_vms_slurp_object_records (bfd * abfd);
    377 static bool alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *);
    378 static bool alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *);
    379 static bool alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *,
    380 				    bfd_vma);
    381 static bool alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int,
    382 				    bfd_vma);
    383 static bool alpha_vms_add_lw_reloc (struct bfd_link_info *);
    384 static bool alpha_vms_add_qw_reloc (struct bfd_link_info *);
    385 
    386 struct vector_type
    387 {
    388   unsigned int max_el;
    389   unsigned int nbr_el;
    390   void *els;
    391 };
    392 
    393 /* Number of elements in VEC.  */
    394 
    395 #define VEC_COUNT(VEC) ((VEC).nbr_el)
    396 
    397 /* Get the address of the Nth element.  */
    398 
    399 #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N])
    400 
    401 #define VEC_INIT(VEC)				\
    402   do {						\
    403     (VEC).max_el = 0;				\
    404     (VEC).nbr_el = 0;				\
    405     (VEC).els = NULL;				\
    406   } while (0)
    407 
    408 /* Be sure there is room for a new element.  */
    409 
    410 static void *vector_grow1 (struct vector_type *vec, size_t elsz);
    411 
    412 /* Allocate room for a new element and return its address.  */
    413 
    414 #define VEC_APPEND(VEC, TYPE)					\
    415   ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE)))
    416 
    417 struct alpha_vms_vma_ref
    418 {
    419   bfd_vma vma;	/* Vma in the output.  */
    420   bfd_vma ref;	/* Reference in the input.  */
    421 };
    422 
    423 struct alpha_vms_shlib_el
    424 {
    425   bfd *abfd;
    426   bool has_fixups;
    427 
    428   struct vector_type lp;	/* Vector of bfd_vma.  */
    429   struct vector_type ca;	/* Vector of bfd_vma.  */
    430   struct vector_type qr;	/* Vector of struct alpha_vms_vma_ref.  */
    431 };
    432 
    433 /* Alpha VMS linker hash table.  */
    434 
    435 struct alpha_vms_link_hash_table
    436 {
    437   struct bfd_link_hash_table root;
    438 
    439   /* Vector of shared libraries.  */
    440   struct vector_type shrlibs;
    441 
    442   /* Fixup section.  */
    443   asection *fixup;
    444 
    445   /* Base address.  Used by fixups.  */
    446   bfd_vma base_addr;
    447 };
    448 
    449 #define alpha_vms_link_hash(INFO) \
    450   ((struct alpha_vms_link_hash_table *)(INFO->hash))
    451 
    452 /* Alpha VMS linker hash table entry.  */
    453 
    454 struct alpha_vms_link_hash_entry
    455 {
    456   struct bfd_link_hash_entry root;
    457 
    458   /* Pointer to the original vms symbol.  */
    459   struct vms_symbol_entry *sym;
    460 };
    461 
    462 /* Image reading.  */
    464 
    465 /* Read & process EIHD record.
    466    Return TRUE on success, FALSE on error.  */
    467 
    468 static bool
    469 _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
    470 		     unsigned int *eihs_offset)
    471 {
    472   unsigned int imgtype;
    473   bfd_vma symvva;
    474   struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
    475 
    476   vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
    477 
    478   imgtype = bfd_getl32 (eihd->imgtype);
    479 
    480   if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
    481     abfd->flags |= EXEC_P;
    482 
    483   symvva = bfd_getl64 (eihd->symvva);
    484   if (symvva != 0)
    485     {
    486       PRIV (symvva) = symvva;
    487       abfd->flags |= DYNAMIC;
    488     }
    489 
    490   PRIV (ident) = bfd_getl32 (eihd->ident);
    491   PRIV (matchctl) = eihd->matchctl;
    492 
    493   *eisd_offset = bfd_getl32 (eihd->isdoff);
    494   *eihs_offset = bfd_getl32 (eihd->symdbgoff);
    495 
    496   vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
    497 	       PRIV (recrd.rec_size), imgtype, (unsigned long) symvva,
    498 	       *eisd_offset, *eihs_offset));
    499   return true;
    500 }
    501 
    502 /* Read & process EISD record.
    503    Return TRUE on success, FALSE on error.  */
    504 
    505 static bool
    506 _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
    507 {
    508   int section_count = 0;
    509 
    510   vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
    511 
    512   while (1)
    513     {
    514       struct vms_eisd *eisd;
    515       unsigned int rec_size;
    516       unsigned int size;
    517       uint64_t vaddr;
    518       unsigned int flags;
    519       unsigned int vbn;
    520       char *name = NULL;
    521       asection *section;
    522       flagword bfd_flags;
    523 
    524       /* PR 17512: file: 3d9e9fe9.  */
    525       if (offset > PRIV (recrd.rec_size)
    526 	  || (PRIV (recrd.rec_size) - offset
    527 	      < offsetof (struct vms_eisd, eisdsize) + 4))
    528 	return false;
    529       eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset);
    530       rec_size = bfd_getl32 (eisd->eisdsize);
    531       if (rec_size == 0)
    532 	break;
    533 
    534       /* Skip to next block if pad.  */
    535       if (rec_size == 0xffffffff)
    536 	{
    537 	  offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
    538 	  continue;
    539 	}
    540 
    541       /* Make sure that there is enough data present in the record.  */
    542       if (rec_size < offsetof (struct vms_eisd, type) + 1)
    543 	return false;
    544       /* Make sure that the record is not too big either.  */
    545       if (rec_size > PRIV (recrd.rec_size) - offset)
    546 	return false;
    547 
    548       offset += rec_size;
    549 
    550       size = bfd_getl32 (eisd->secsize);
    551       vaddr = bfd_getl64 (eisd->virt_addr);
    552       flags = bfd_getl32 (eisd->flags);
    553       vbn = bfd_getl32 (eisd->vbn);
    554 
    555       vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n",
    556 		   offset, size, (unsigned long)vaddr, flags, vbn));
    557 
    558       /* VMS combines psects from .obj files into isects in the .exe.  This
    559 	 process doesn't preserve enough information to reliably determine
    560 	 what's in each section without examining the data.  This is
    561 	 especially true of DWARF debug sections.  */
    562       bfd_flags = SEC_ALLOC;
    563       if (vbn != 0)
    564 	bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD;
    565 
    566       if (flags & EISD__M_EXE)
    567 	bfd_flags |= SEC_CODE;
    568 
    569       if (flags & EISD__M_NONSHRADR)
    570 	bfd_flags |= SEC_DATA;
    571 
    572       if (!(flags & EISD__M_WRT))
    573 	bfd_flags |= SEC_READONLY;
    574 
    575       if (flags & EISD__M_DZRO)
    576 	bfd_flags |= SEC_DATA;
    577 
    578       if (flags & EISD__M_FIXUPVEC)
    579 	bfd_flags |= SEC_DATA;
    580 
    581       if (flags & EISD__M_CRF)
    582 	bfd_flags |= SEC_DATA;
    583 
    584       if (flags & EISD__M_GBL)
    585 	{
    586 	  if (rec_size <= offsetof (struct vms_eisd, gblnam))
    587 	    return false;
    588 	  else if (rec_size < sizeof (struct vms_eisd))
    589 	    name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
    590 						 rec_size - offsetof (struct vms_eisd, gblnam));
    591 	  else
    592 	    name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
    593 						 EISD__K_GBLNAMLEN);
    594 	  if (name == NULL || name[0] == 0)
    595 	    return false;
    596 	  bfd_flags |= SEC_COFF_SHARED_LIBRARY;
    597 	  bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
    598 	}
    599       else if (flags & EISD__M_FIXUPVEC)
    600 	name = "$FIXUPVEC$";
    601       else if (eisd->type == EISD__K_USRSTACK)
    602 	name = "$STACK$";
    603       else
    604 	{
    605 	  const char *pfx;
    606 
    607 	  name = (char *) bfd_alloc (abfd, 32);
    608 	  if (name == NULL)
    609 	    return false;
    610 	  if (flags & EISD__M_DZRO)
    611 	    pfx = "BSS";
    612 	  else if (flags & EISD__M_EXE)
    613 	    pfx = "CODE";
    614 	  else if (!(flags & EISD__M_WRT))
    615 	    pfx = "RO";
    616 	  else
    617 	    pfx = "LOCAL";
    618 	  BFD_ASSERT (section_count < 999);
    619 	  sprintf (name, "$%s_%03d$", pfx, section_count++);
    620 	}
    621 
    622       section = bfd_make_section (abfd, name);
    623 
    624       if (!section)
    625 	return false;
    626 
    627       section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
    628       section->size = size;
    629       section->vma = vaddr;
    630 
    631       if (!bfd_set_section_flags (section, bfd_flags))
    632 	return false;
    633     }
    634 
    635   return true;
    636 }
    637 
    638 /* Read & process EIHS record.
    639    Return TRUE on success, FALSE on error.  */
    640 
    641 static bool
    642 _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
    643 {
    644   unsigned char *p = PRIV (recrd.rec) + offset;
    645   unsigned int gstvbn;
    646   unsigned int gstsize ATTRIBUTE_UNUSED;
    647   unsigned int dstvbn;
    648   unsigned int dstsize;
    649   unsigned int dmtvbn;
    650   unsigned int dmtbytes;
    651   asection *section;
    652 
    653   /* PR 21611: Check that offset is valid.  */
    654   if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4))
    655     {
    656       _bfd_error_handler (_("unable to read EIHS record at offset %#x"),
    657 			  offset);
    658       bfd_set_error (bfd_error_file_truncated);
    659       return false;
    660     }
    661 
    662   gstvbn   = bfd_getl32 (p + EIHS__L_GSTVBN);
    663   gstsize  = bfd_getl32 (p + EIHS__L_GSTSIZE);
    664   dstvbn   = bfd_getl32 (p + EIHS__L_DSTVBN);
    665   dstsize  = bfd_getl32 (p + EIHS__L_DSTSIZE);
    666   dmtvbn   = bfd_getl32 (p + EIHS__L_DMTVBN);
    667   dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES);
    668 
    669 #if VMS_DEBUG
    670   vms_debug (8, "_bfd_vms_slurp_ihs\n");
    671   vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
    672 	     gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes);
    673 #endif
    674 
    675   if (dstvbn)
    676     {
    677       flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
    678 
    679       section = bfd_make_section (abfd, "$DST$");
    680       if (!section)
    681 	return false;
    682 
    683       section->size = dstsize;
    684       section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
    685 
    686       if (!bfd_set_section_flags (section, bfd_flags))
    687 	return false;
    688 
    689       PRIV (dst_section) = section;
    690       abfd->flags |= (HAS_DEBUG | HAS_LINENO);
    691     }
    692 
    693   if (dmtvbn)
    694     {
    695       flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
    696 
    697       section = bfd_make_section (abfd, "$DMT$");
    698       if (!section)
    699 	return false;
    700 
    701       section->size = dmtbytes;
    702       section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
    703 
    704       if (!bfd_set_section_flags (section, bfd_flags))
    705 	return false;
    706     }
    707 
    708   if (gstvbn)
    709     {
    710       if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET))
    711 	{
    712 	  bfd_set_error (bfd_error_file_truncated);
    713 	  return false;
    714 	}
    715 
    716       if (!_bfd_vms_slurp_object_records (abfd))
    717 	return false;
    718 
    719       abfd->flags |= HAS_SYMS;
    720     }
    721 
    722   return true;
    723 }
    724 
    725 /* Object file reading.  */
    727 
    728 /* Object file input functions.  */
    729 
    730 /* Get next record from object file to vms_buf.
    731    Set PRIV(buf_size) and return it
    732 
    733    This is a little tricky since it should be portable.
    734 
    735    The openVMS object file has 'variable length' which means that
    736    read() returns data in chunks of (hopefully) correct and expected
    737    size.  The linker (and other tools on VMS) depend on that. Unix
    738    doesn't know about 'formatted' files, so reading and writing such
    739    an object file in a Unix environment is not trivial.
    740 
    741    With the tool 'file' (available on all VMS FTP sites), one
    742    can view and change the attributes of a file.  Changing from
    743    'variable length' to 'fixed length, 512 bytes' reveals the
    744    record size at the first 2 bytes of every record.  The same
    745    may happen during the transfer of object files from VMS to Unix,
    746    at least with UCX, the DEC implementation of TCP/IP.
    747 
    748    The VMS format repeats the size at bytes 2 & 3 of every record.
    749 
    750    On the first call (file_format == FF_UNKNOWN) we check if
    751    the first and the third byte pair (!) of the record match.
    752    If they do it's an object file in an Unix environment or with
    753    wrong attributes (FF_FOREIGN), else we should be in a VMS
    754    environment where read() returns the record size (FF_NATIVE).
    755 
    756    Reading is always done in 2 steps:
    757     1. first just the record header is read and the size extracted,
    758     2. then the read buffer is adjusted and the remaining bytes are
    759        read in.
    760 
    761    All file I/O is done on even file positions.  */
    762 
    763 #define VMS_OBJECT_ADJUSTMENT  2
    764 
    765 static void
    766 maybe_adjust_record_pointer_for_object (bfd *abfd)
    767 {
    768   /* Set the file format once for all on the first invocation.  */
    769   if (PRIV (recrd.file_format) == FF_UNKNOWN)
    770     {
    771       if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4]
    772 	  && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5])
    773 	PRIV (recrd.file_format) = FF_FOREIGN;
    774       else
    775 	PRIV (recrd.file_format) = FF_NATIVE;
    776     }
    777 
    778   /* The adjustment is needed only in an Unix environment.  */
    779   if (PRIV (recrd.file_format) == FF_FOREIGN)
    780     PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT;
    781 }
    782 
    783 /* Implement step #1 of the object record reading procedure.
    784    Return the record type or -1 on failure.  */
    785 
    786 static int
    787 _bfd_vms_get_object_record (bfd *abfd)
    788 {
    789   unsigned int test_len = 6;
    790   int type;
    791 
    792   vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
    793 
    794   /* Skip alignment byte if the current position is odd.  */
    795   if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1))
    796     {
    797       if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1)
    798 	{
    799 	  bfd_set_error (bfd_error_file_truncated);
    800 	  return -1;
    801 	}
    802     }
    803 
    804   /* Read the record header  */
    805   if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len)
    806     {
    807       bfd_set_error (bfd_error_file_truncated);
    808       return -1;
    809     }
    810 
    811   /* Reset the record pointer.  */
    812   PRIV (recrd.rec) = PRIV (recrd.buf);
    813   maybe_adjust_record_pointer_for_object (abfd);
    814 
    815   if (vms_get_remaining_object_record (abfd, test_len) <= 0)
    816     return -1;
    817 
    818   type = bfd_getl16 (PRIV (recrd.rec));
    819 
    820   vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n",
    821 	       PRIV (recrd.rec), PRIV (recrd.rec_size), type));
    822 
    823   return type;
    824 }
    825 
    826 /* Implement step #2 of the object record reading procedure.
    827    Return the size of the record or 0 on failure.  */
    828 
    829 static int
    830 vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far)
    831 {
    832   unsigned int to_read;
    833 
    834   vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
    835 
    836   /* Extract record size.  */
    837   PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
    838 
    839   if (PRIV (recrd.rec_size) == 0)
    840     {
    841       bfd_set_error (bfd_error_file_truncated);
    842       return 0;
    843     }
    844 
    845   /* That's what the linker manual says.  */
    846   if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
    847     {
    848       bfd_set_error (bfd_error_file_truncated);
    849       return 0;
    850     }
    851 
    852   /* Take into account object adjustment.  */
    853   to_read = PRIV (recrd.rec_size);
    854   if (PRIV (recrd.file_format) == FF_FOREIGN)
    855     to_read += VMS_OBJECT_ADJUSTMENT;
    856 
    857   /* Adjust the buffer.  */
    858   if (to_read > PRIV (recrd.buf_size))
    859     {
    860       PRIV (recrd.buf)
    861 	= (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read);
    862       if (PRIV (recrd.buf) == NULL)
    863 	return 0;
    864       PRIV (recrd.buf_size) = to_read;
    865     }
    866   /* PR 17512: file: 025-1974-0.004.  */
    867   else if (to_read <= read_so_far)
    868     return 0;
    869 
    870   /* Read the remaining record.  */
    871   to_read -= read_so_far;
    872 
    873   vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
    874 
    875   if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
    876     {
    877       bfd_set_error (bfd_error_file_truncated);
    878       return 0;
    879     }
    880 
    881   /* Reset the record pointer.  */
    882   PRIV (recrd.rec) = PRIV (recrd.buf);
    883   maybe_adjust_record_pointer_for_object (abfd);
    884 
    885   vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
    886 	       PRIV (recrd.rec_size)));
    887 
    888   return PRIV (recrd.rec_size);
    889 }
    890 
    891 /* Read and process emh record.
    892    Return TRUE on success, FALSE on error.  */
    893 
    894 static bool
    895 _bfd_vms_slurp_ehdr (bfd *abfd)
    896 {
    897   unsigned char *ptr;
    898   unsigned int len, slen;
    899   int subtype;
    900 
    901   vms_debug2 ((2, "HDR/EMH\n"));
    902 
    903   ptr = PRIV (recrd.rec);
    904   len = PRIV (recrd.rec_size);
    905   if (len < 6)
    906     goto fail;
    907 
    908   subtype = bfd_getl16 (ptr + 4);
    909 
    910   vms_debug2 ((3, "subtype %d\n", subtype));
    911 
    912   ptr += 6;
    913   len -= 6;
    914   switch (subtype)
    915     {
    916     case EMH__C_MHD:
    917       /* Module header.  */
    918       if (len < 15)
    919 	goto fail;
    920       PRIV (hdr_data).hdr_b_strlvl = *ptr;
    921       PRIV (hdr_data).hdr_l_arch1  = bfd_getl32 (ptr + 2);
    922       PRIV (hdr_data).hdr_l_arch2  = bfd_getl32 (ptr + 6);
    923       PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (ptr + 10);
    924       ptr += 14;
    925       len -= 14;
    926       PRIV (hdr_data).hdr_t_name
    927 	= _bfd_vms_save_counted_string (abfd, ptr, len);
    928       slen = *ptr + 1;
    929       if (len <= slen)
    930 	goto fail;
    931       ptr += slen;
    932       len -= slen;
    933       PRIV (hdr_data).hdr_t_version
    934 	= _bfd_vms_save_counted_string (abfd, ptr, len);
    935       slen = *ptr + 1;
    936       if (len < slen + 17)
    937 	goto fail;
    938       ptr += slen;
    939       PRIV (hdr_data).hdr_t_date
    940 	= _bfd_vms_save_sized_string (abfd, ptr, 17);
    941       break;
    942 
    943     case EMH__C_LNM:
    944       PRIV (hdr_data).hdr_c_lnm
    945 	= _bfd_vms_save_sized_string (abfd, ptr, len);
    946       break;
    947 
    948     case EMH__C_SRC:
    949       PRIV (hdr_data).hdr_c_src
    950 	= _bfd_vms_save_sized_string (abfd, ptr, len);
    951       break;
    952 
    953     case EMH__C_TTL:
    954       PRIV (hdr_data).hdr_c_ttl
    955 	= _bfd_vms_save_sized_string (abfd, ptr, len);
    956       break;
    957 
    958     case EMH__C_CPR:
    959     case EMH__C_MTC:
    960     case EMH__C_GTX:
    961       break;
    962 
    963     default:
    964     fail:
    965       bfd_set_error (bfd_error_wrong_format);
    966       return false;
    967     }
    968 
    969   return true;
    970 }
    971 
    972 /* Typical sections for evax object files.  */
    973 
    974 #define EVAX_ABS_NAME		"$ABS$"
    975 #define EVAX_CODE_NAME		"$CODE$"
    976 #define EVAX_LINK_NAME		"$LINK$"
    977 #define EVAX_DATA_NAME		"$DATA$"
    978 #define EVAX_BSS_NAME		"$BSS$"
    979 #define EVAX_READONLYADDR_NAME	"$READONLY_ADDR$"
    980 #define EVAX_READONLY_NAME	"$READONLY$"
    981 #define EVAX_LITERAL_NAME	"$LITERAL$"
    982 #define EVAX_LITERALS_NAME	"$LITERALS"
    983 #define EVAX_COMMON_NAME	"$COMMON$"
    984 #define EVAX_LOCAL_NAME		"$LOCAL$"
    985 
    986 struct sec_flags_struct
    987 {
    988   const char *name;		/* Name of section.  */
    989   int vflags_always;
    990   flagword flags_always;	/* Flags we set always.  */
    991   int vflags_hassize;
    992   flagword flags_hassize;	/* Flags we set if the section has a size > 0.  */
    993 };
    994 
    995 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible.  */
    996 
    997 static const struct sec_flags_struct evax_section_flags[] =
    998   {
    999     { EVAX_ABS_NAME,
   1000       EGPS__V_SHR,
   1001       0,
   1002       EGPS__V_SHR,
   1003       0 },
   1004     { EVAX_CODE_NAME,
   1005       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE,
   1006       SEC_CODE | SEC_READONLY,
   1007       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE,
   1008       SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1009     { EVAX_LITERAL_NAME,
   1010       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD,
   1011       SEC_DATA | SEC_READONLY,
   1012       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD,
   1013       SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1014     { EVAX_LINK_NAME,
   1015       EGPS__V_REL | EGPS__V_RD,
   1016       SEC_DATA | SEC_READONLY,
   1017       EGPS__V_REL | EGPS__V_RD,
   1018       SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1019     { EVAX_DATA_NAME,
   1020       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
   1021       SEC_DATA,
   1022       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
   1023       SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1024     { EVAX_BSS_NAME,
   1025       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
   1026       SEC_NO_FLAGS,
   1027       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
   1028       SEC_ALLOC },
   1029     { EVAX_READONLYADDR_NAME,
   1030       EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD,
   1031       SEC_DATA | SEC_READONLY,
   1032       EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD,
   1033       SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1034     { EVAX_READONLY_NAME,
   1035       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD,
   1036       SEC_DATA | SEC_READONLY,
   1037       EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD,
   1038       SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1039     { EVAX_LOCAL_NAME,
   1040       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
   1041       SEC_DATA,
   1042       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
   1043       SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1044     { EVAX_LITERALS_NAME,
   1045       EGPS__V_PIC | EGPS__V_OVR,
   1046       SEC_DATA | SEC_READONLY,
   1047       EGPS__V_PIC | EGPS__V_OVR,
   1048       SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
   1049     { NULL,
   1050       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
   1051       SEC_DATA,
   1052       EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
   1053       SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }
   1054   };
   1055 
   1056 /* Retrieve BFD section flags by name and size.  */
   1057 
   1058 static flagword
   1059 vms_secflag_by_name (const struct sec_flags_struct *section_flags,
   1060 		     const char *name,
   1061 		     int hassize)
   1062 {
   1063   int i = 0;
   1064 
   1065   while (section_flags[i].name != NULL)
   1066     {
   1067       if (strcmp (name, section_flags[i].name) == 0)
   1068 	{
   1069 	  if (hassize)
   1070 	    return section_flags[i].flags_hassize;
   1071 	  else
   1072 	    return section_flags[i].flags_always;
   1073 	}
   1074       i++;
   1075     }
   1076   if (hassize)
   1077     return section_flags[i].flags_hassize;
   1078   return section_flags[i].flags_always;
   1079 }
   1080 
   1081 /* Retrieve VMS section flags by name and size.  */
   1082 
   1083 static flagword
   1084 vms_esecflag_by_name (const struct sec_flags_struct *section_flags,
   1085 		      const char *name,
   1086 		      int hassize)
   1087 {
   1088   int i = 0;
   1089 
   1090   while (section_flags[i].name != NULL)
   1091     {
   1092       if (strcmp (name, section_flags[i].name) == 0)
   1093 	{
   1094 	  if (hassize)
   1095 	    return section_flags[i].vflags_hassize;
   1096 	  else
   1097 	    return section_flags[i].vflags_always;
   1098 	}
   1099       i++;
   1100     }
   1101   if (hassize)
   1102     return section_flags[i].vflags_hassize;
   1103   return section_flags[i].vflags_always;
   1104 }
   1105 
   1106 /* Add SYM to the symbol table of ABFD.
   1107    Return FALSE in case of error.  */
   1108 
   1109 static bool
   1110 add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym)
   1111 {
   1112   if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
   1113     {
   1114       if (PRIV (max_sym_count) == 0)
   1115 	{
   1116 	  PRIV (max_sym_count) = 128;
   1117 	  PRIV (syms) = bfd_malloc
   1118 	    (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
   1119 	}
   1120       else
   1121 	{
   1122 	  PRIV (max_sym_count) *= 2;
   1123 	  PRIV (syms) = bfd_realloc_or_free
   1124 	    (PRIV (syms),
   1125 	     (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
   1126 	}
   1127       if (PRIV (syms) == NULL)
   1128 	return false;
   1129     }
   1130 
   1131   PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
   1132   return true;
   1133 }
   1134 
   1135 /* Create a symbol whose name is ASCIC and add it to ABFD.
   1136    Return NULL in case of error.  */
   1137 
   1138 static struct vms_symbol_entry *
   1139 add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max)
   1140 {
   1141   struct vms_symbol_entry *entry;
   1142   unsigned int len;
   1143 
   1144   len = *ascic++;
   1145   max -= 1;
   1146   if (len > max)
   1147     {
   1148       _bfd_error_handler (_("record is too small for symbol name length"));
   1149       bfd_set_error (bfd_error_bad_value);
   1150       return NULL;
   1151     }
   1152 
   1153   entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
   1154   if (entry == NULL)
   1155     return NULL;
   1156   entry->namelen = len;
   1157   memcpy (entry->name, ascic, len);
   1158   entry->name[len] = 0;
   1159   entry->owner = abfd;
   1160 
   1161   if (!add_symbol_entry (abfd, entry))
   1162     return NULL;
   1163   return entry;
   1164 }
   1165 
   1166 /* Read and process EGSD.  Return FALSE on failure.  */
   1167 
   1168 static bool
   1169 _bfd_vms_slurp_egsd (bfd *abfd)
   1170 {
   1171   int gsd_type;
   1172   unsigned int gsd_size;
   1173   unsigned char *vms_rec;
   1174   bfd_vma base_addr;
   1175   long psindx;
   1176 
   1177   vms_debug2 ((2, "EGSD\n"));
   1178 
   1179   if (PRIV (recrd.rec_size) < 8)
   1180     {
   1181       _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"),
   1182 			  PRIV (recrd.rec_size));
   1183       bfd_set_error (bfd_error_bad_value);
   1184       return false;
   1185     }
   1186 
   1187   PRIV (recrd.rec) += 8;	/* Skip type, size, align pad.  */
   1188   PRIV (recrd.rec_size) -= 8;
   1189 
   1190   /* Calculate base address for each section.  */
   1191   base_addr = 0;
   1192 
   1193   while (PRIV (recrd.rec_size) > 4)
   1194     {
   1195       vms_rec = PRIV (recrd.rec);
   1196 
   1197       gsd_type = bfd_getl16 (vms_rec);
   1198       gsd_size = bfd_getl16 (vms_rec + 2);
   1199 
   1200       vms_debug2 ((3, "egsd_type %d\n", gsd_type));
   1201 
   1202       /* PR 21615: Check for size overflow.  */
   1203       if (PRIV (recrd.rec_size) < gsd_size)
   1204 	{
   1205 	  _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
   1206 				"is larger than remaining space (%#x)"),
   1207 			      gsd_type, gsd_size, PRIV (recrd.rec_size));
   1208 	  bfd_set_error (bfd_error_bad_value);
   1209 	  return false;
   1210 	}
   1211 
   1212       if (gsd_size < 4)
   1213 	{
   1214 	too_small:
   1215 	  _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
   1216 				"is too small"),
   1217 			      gsd_type, gsd_size);
   1218 	  bfd_set_error (bfd_error_bad_value);
   1219 	  return false;
   1220 	}
   1221 
   1222       switch (gsd_type)
   1223 	{
   1224 	case EGSD__C_PSC:
   1225 	  /* Program section definition.  */
   1226 	  {
   1227 	    struct vms_egps *egps = (struct vms_egps *) vms_rec;
   1228 	    flagword new_flags, vms_flags;
   1229 	    asection *section;
   1230 
   1231 	    if (offsetof (struct vms_egps, flags) + 2 > gsd_size)
   1232 	      goto too_small;
   1233 	    vms_flags = bfd_getl16 (egps->flags);
   1234 
   1235 	    if ((vms_flags & EGPS__V_REL) == 0)
   1236 	      {
   1237 		/* Use the global absolute section for all
   1238 		   absolute sections.  */
   1239 		section = bfd_abs_section_ptr;
   1240 	      }
   1241 	    else
   1242 	      {
   1243 		char *name;
   1244 		bfd_vma align_addr;
   1245 		size_t left;
   1246 
   1247 		if (offsetof (struct vms_egps, namlng) >= gsd_size)
   1248 		  goto too_small;
   1249 		left = gsd_size - offsetof (struct vms_egps, namlng);
   1250 		name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left);
   1251 		if (name == NULL || name[0] == 0)
   1252 		  return false;
   1253 
   1254 		section = bfd_make_section (abfd, name);
   1255 		if (!section)
   1256 		  return false;
   1257 
   1258 		section->filepos = 0;
   1259 		section->size = bfd_getl32 (egps->alloc);
   1260 		section->alignment_power = egps->align & 31;
   1261 
   1262 		vms_section_data (section)->flags = vms_flags;
   1263 		vms_section_data (section)->no_flags = 0;
   1264 
   1265 		new_flags = vms_secflag_by_name (evax_section_flags,
   1266 						 section->name,
   1267 						 section->size > 0);
   1268 		if (section->size > 0)
   1269 		  new_flags |= SEC_LOAD;
   1270 		if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0)
   1271 		  {
   1272 		    /* Set RELOC and HAS_CONTENTS if the section is not
   1273 		       demand-zero and not empty.  */
   1274 		    new_flags |= SEC_HAS_CONTENTS;
   1275 		    if (vms_flags & EGPS__V_REL)
   1276 		      new_flags |= SEC_RELOC;
   1277 		  }
   1278 		if (vms_flags & EGPS__V_EXE)
   1279 		  {
   1280 		    /* Set CODE if section is executable.  */
   1281 		    new_flags |= SEC_CODE;
   1282 		    new_flags &= ~SEC_DATA;
   1283 		  }
   1284 		if (!bfd_set_section_flags (section, new_flags))
   1285 		  return false;
   1286 
   1287 		/* Give a non-overlapping vma to non absolute sections.  */
   1288 		align_addr = (bfd_vma) 1 << section->alignment_power;
   1289 		base_addr = (base_addr + align_addr - 1) & -align_addr;
   1290 		section->vma = base_addr;
   1291 		base_addr += section->size;
   1292 	      }
   1293 
   1294 	    /* Append it to the section array.  */
   1295 	    if (PRIV (section_count) >= PRIV (section_max))
   1296 	      {
   1297 		if (PRIV (section_max) == 0)
   1298 		  PRIV (section_max) = 16;
   1299 		else
   1300 		  PRIV (section_max) *= 2;
   1301 		PRIV (sections) = bfd_realloc_or_free
   1302 		  (PRIV (sections), PRIV (section_max) * sizeof (asection *));
   1303 		if (PRIV (sections) == NULL)
   1304 		  return false;
   1305 	      }
   1306 
   1307 	    PRIV (sections)[PRIV (section_count)] = section;
   1308 	    PRIV (section_count)++;
   1309 	  }
   1310 	  break;
   1311 
   1312 	case EGSD__C_SYM:
   1313 	  {
   1314 	    unsigned int nameoff;
   1315 	    struct vms_symbol_entry *entry;
   1316 	    struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
   1317 	    flagword old_flags;
   1318 
   1319 	    if (offsetof (struct vms_egsy, flags) + 2 > gsd_size)
   1320 	      goto too_small;
   1321 	    old_flags = bfd_getl16 (egsy->flags);
   1322 	    if (old_flags & EGSY__V_DEF)
   1323 	      nameoff = ESDF__B_NAMLNG;
   1324 	    else
   1325 	      nameoff = ESRF__B_NAMLNG;
   1326 
   1327 	    if (nameoff >= gsd_size)
   1328 	      goto too_small;
   1329 	    entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff);
   1330 	    if (entry == NULL)
   1331 	      return false;
   1332 
   1333 	    /* Allow only duplicate reference.  */
   1334 	    if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
   1335 	      abort ();
   1336 
   1337 	    if (entry->typ == 0)
   1338 	      {
   1339 		entry->typ = gsd_type;
   1340 		entry->data_type = egsy->datyp;
   1341 		entry->flags = old_flags;
   1342 	      }
   1343 
   1344 	    if (old_flags & EGSY__V_DEF)
   1345 	      {
   1346 		struct vms_esdf *esdf = (struct vms_esdf *) vms_rec;
   1347 
   1348 		entry->value = bfd_getl64 (esdf->value);
   1349 		if (PRIV (sections) == NULL)
   1350 		  return false;
   1351 
   1352 		psindx = bfd_getl32 (esdf->psindx);
   1353 		/* PR 21813: Check for an out of range index.  */
   1354 		if (psindx < 0 || psindx >= (int) PRIV (section_count))
   1355 		  {
   1356 		  bad_psindx:
   1357 		    _bfd_error_handler (_("corrupt EGSD record: its psindx "
   1358 					  "field is too big (%#lx)"),
   1359 					psindx);
   1360 		    bfd_set_error (bfd_error_bad_value);
   1361 		    return false;
   1362 		  }
   1363 		entry->section = PRIV (sections)[psindx];
   1364 
   1365 		if (old_flags & EGSY__V_NORM)
   1366 		  {
   1367 		    PRIV (norm_sym_count)++;
   1368 
   1369 		    entry->code_value = bfd_getl64 (esdf->code_address);
   1370 		    psindx = bfd_getl32 (esdf->ca_psindx);
   1371 		    /* PR 21813: Check for an out of range index.  */
   1372 		    if (psindx < 0 || psindx >= (int) PRIV (section_count))
   1373 		      goto bad_psindx;
   1374 		    entry->code_section = PRIV (sections)[psindx];
   1375 		  }
   1376 	      }
   1377 	  }
   1378 	  break;
   1379 
   1380 	case EGSD__C_SYMG:
   1381 	  {
   1382 	    struct vms_symbol_entry *entry;
   1383 	    struct vms_egst *egst = (struct vms_egst *)vms_rec;
   1384 	    flagword old_flags;
   1385 	    unsigned int nameoff = offsetof (struct vms_egst, namlng);
   1386 
   1387 	    if (nameoff >= gsd_size)
   1388 	      goto too_small;
   1389 	    entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff);
   1390 	    if (entry == NULL)
   1391 	      return false;
   1392 
   1393 	    old_flags = bfd_getl16 (egst->header.flags);
   1394 	    entry->typ = gsd_type;
   1395 	    entry->data_type = egst->header.datyp;
   1396 	    entry->flags = old_flags;
   1397 
   1398 	    entry->symbol_vector = bfd_getl32 (egst->value);
   1399 
   1400 	    if (old_flags & EGSY__V_REL)
   1401 	      {
   1402 		if (PRIV (sections) == NULL)
   1403 		  return false;
   1404 		psindx = bfd_getl32 (egst->psindx);
   1405 		/* PR 21813: Check for an out of range index.  */
   1406 		if (psindx < 0 || psindx >= (int) PRIV (section_count))
   1407 		  goto bad_psindx;
   1408 		entry->section = PRIV (sections)[psindx];
   1409 	      }
   1410 	    else
   1411 	      entry->section = bfd_abs_section_ptr;
   1412 
   1413 	    entry->value = bfd_getl64 (egst->lp_2);
   1414 
   1415 	    if (old_flags & EGSY__V_NORM)
   1416 	      {
   1417 		PRIV (norm_sym_count)++;
   1418 
   1419 		entry->code_value = bfd_getl64 (egst->lp_1);
   1420 		entry->code_section = bfd_abs_section_ptr;
   1421 	      }
   1422 	  }
   1423 	  break;
   1424 
   1425 	case EGSD__C_SPSC:
   1426 	case EGSD__C_IDC:
   1427 	  /* Currently ignored.  */
   1428 	  break;
   1429 	case EGSD__C_SYMM:
   1430 	case EGSD__C_SYMV:
   1431 	default:
   1432 	  _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type);
   1433 	  bfd_set_error (bfd_error_bad_value);
   1434 	  return false;
   1435 	}
   1436 
   1437       PRIV (recrd.rec_size) -= gsd_size;
   1438       PRIV (recrd.rec) += gsd_size;
   1439     }
   1440 
   1441   /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ?  */
   1442 
   1443   if (PRIV (gsd_sym_count) > 0)
   1444     abfd->flags |= HAS_SYMS;
   1445 
   1446   return true;
   1447 }
   1448 
   1449 /* Stack routines for vms ETIR commands.  */
   1450 
   1451 /* Push value and section index.  */
   1452 
   1453 static bool
   1454 _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
   1455 {
   1456   vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
   1457 	       (unsigned long)val, reloc, PRIV (stackptr)));
   1458 
   1459   PRIV (stack[PRIV (stackptr)]).value = val;
   1460   PRIV (stack[PRIV (stackptr)]).reloc = reloc;
   1461   PRIV (stackptr)++;
   1462   if (PRIV (stackptr) >= STACKSIZE)
   1463     {
   1464       bfd_set_error (bfd_error_bad_value);
   1465       _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
   1466       return false;
   1467     }
   1468   return true;
   1469 }
   1470 
   1471 /* Pop value and section index.  */
   1472 
   1473 static bool
   1474 _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
   1475 {
   1476   if (PRIV (stackptr) == 0)
   1477     {
   1478       bfd_set_error (bfd_error_bad_value);
   1479       _bfd_error_handler (_("stack underflow in _bfd_vms_pop"));
   1480       return false;
   1481     }
   1482   PRIV (stackptr)--;
   1483   *val = PRIV (stack[PRIV (stackptr)]).value;
   1484   *rel = PRIV (stack[PRIV (stackptr)]).reloc;
   1485 
   1486   vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
   1487   return true;
   1488 }
   1489 
   1490 /* Routines to fill sections contents during tir/etir read.  */
   1491 
   1492 /* Initialize image buffer pointer to be filled.  */
   1493 
   1494 static void
   1495 image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info)
   1496 {
   1497   asection *sec;
   1498 
   1499   vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect));
   1500 
   1501   if (PRIV (sections) == NULL)
   1502     return;
   1503   if (sect < 0 || sect >= (int) PRIV (section_count))
   1504     return;
   1505 
   1506   sec = PRIV (sections)[sect];
   1507 
   1508   if (info)
   1509     {
   1510       /* Reading contents to an output bfd.  */
   1511 
   1512       if (sec->output_section == NULL)
   1513 	{
   1514 	  /* Section discarded.  */
   1515 	  vms_debug2 ((5, " section %s discarded\n", sec->name));
   1516 
   1517 	  /* This is not used.  */
   1518 	  PRIV (image_section) = NULL;
   1519 	  PRIV (image_offset) = 0;
   1520 	  return;
   1521 	}
   1522       PRIV (image_offset) = sec->output_offset + vma;
   1523       PRIV (image_section) = sec->output_section;
   1524     }
   1525   else
   1526     {
   1527       PRIV (image_offset) = vma;
   1528       PRIV (image_section) = sec;
   1529     }
   1530 }
   1531 
   1532 /* Increment image buffer pointer by offset.  */
   1533 
   1534 static void
   1535 image_inc_ptr (bfd *abfd, bfd_vma offset)
   1536 {
   1537   vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
   1538 
   1539   PRIV (image_offset) += offset;
   1540 }
   1541 
   1542 /* Save current DST location counter under specified index.  */
   1543 
   1544 static bool
   1545 dst_define_location (bfd *abfd, unsigned int loc)
   1546 {
   1547   vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
   1548 
   1549   if (loc > 1 << 24)
   1550     {
   1551       /* 16M entries ought to be plenty.  */
   1552       bfd_set_error (bfd_error_bad_value);
   1553       _bfd_error_handler (_("dst_define_location %u too large"), loc);
   1554       return false;
   1555     }
   1556 
   1557   /* Grow the ptr offset table if necessary.  */
   1558   if (loc + 1 > PRIV (dst_ptr_offsets_count))
   1559     {
   1560       PRIV (dst_ptr_offsets)
   1561 	= bfd_realloc_or_free (PRIV (dst_ptr_offsets),
   1562 			       (loc + 1) * sizeof (unsigned int));
   1563       if (PRIV (dst_ptr_offsets) == NULL)
   1564 	return false;
   1565       memset (PRIV (dst_ptr_offsets) + PRIV (dst_ptr_offsets_count), 0,
   1566 	      (loc - PRIV (dst_ptr_offsets_count)) * sizeof (unsigned int));
   1567       PRIV (dst_ptr_offsets_count) = loc + 1;
   1568     }
   1569 
   1570   PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
   1571   return true;
   1572 }
   1573 
   1574 /* Restore saved DST location counter from specified index.  */
   1575 
   1576 static bool
   1577 dst_restore_location (bfd *abfd, unsigned int loc)
   1578 {
   1579   vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
   1580 
   1581   if (loc < PRIV (dst_ptr_offsets_count))
   1582     {
   1583       PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
   1584       return true;
   1585     }
   1586   return false;
   1587 }
   1588 
   1589 /* Retrieve saved DST location counter from specified index.  */
   1590 
   1591 static bool
   1592 dst_retrieve_location (bfd *abfd, bfd_vma *loc)
   1593 {
   1594   vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc));
   1595 
   1596   if (*loc < PRIV (dst_ptr_offsets_count))
   1597     {
   1598       *loc = PRIV (dst_ptr_offsets)[*loc];
   1599       return true;
   1600     }
   1601   return false;
   1602 }
   1603 
   1604 static asection *
   1605 image_write_section (bfd *abfd)
   1606 {
   1607   asection *sec = PRIV (image_section);
   1608 
   1609   if ((sec->flags & SEC_IN_MEMORY) != 0 && sec->contents == NULL)
   1610     return NULL;
   1611   return sec;
   1612 }
   1613 
   1614 /* Write multiple bytes to section image.  */
   1615 
   1616 static bool
   1617 image_write (bfd *abfd, unsigned char *ptr, size_t size)
   1618 {
   1619   asection *sec = image_write_section (abfd);
   1620 
   1621   if (sec)
   1622     {
   1623       size_t off = PRIV (image_offset);
   1624       /* Check bounds.  */
   1625       if (off > sec->size
   1626 	  || size > sec->size - off)
   1627 	{
   1628 	  bfd_set_error (bfd_error_bad_value);
   1629 	  return false;
   1630 	}
   1631 
   1632 #if VMS_DEBUG
   1633       _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size,
   1634 		      (long) off);
   1635 #endif
   1636 
   1637       if (sec->contents != NULL)
   1638 	memcpy (sec->contents + off, ptr, size);
   1639       else
   1640 	{
   1641 	  unsigned int i;
   1642 	  for (i = 0; i < size; i++)
   1643 	    if (ptr[i] != 0)
   1644 	      {
   1645 		bfd_set_error (bfd_error_bad_value);
   1646 		return false;
   1647 	      }
   1648 	}
   1649 #if VMS_DEBUG
   1650       _bfd_hexdump (9, ptr, size, 0);
   1651 #endif
   1652     }
   1653 
   1654   PRIV (image_offset) += size;
   1655   return true;
   1656 }
   1657 
   1658 /* Write byte to section image.  */
   1659 
   1660 static bool
   1661 image_write_b (bfd * abfd, unsigned int value)
   1662 {
   1663   unsigned char data[1];
   1664 
   1665   vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
   1666 
   1667   *data = value;
   1668 
   1669   return image_write (abfd, data, sizeof (data));
   1670 }
   1671 
   1672 /* Write 2-byte word to image.  */
   1673 
   1674 static bool
   1675 image_write_w (bfd * abfd, unsigned int value)
   1676 {
   1677   unsigned char data[2];
   1678 
   1679   vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
   1680 
   1681   bfd_putl16 (value, data);
   1682   return image_write (abfd, data, sizeof (data));
   1683 }
   1684 
   1685 /* Write 4-byte long to image.  */
   1686 
   1687 static bool
   1688 image_write_l (bfd * abfd, unsigned long value)
   1689 {
   1690   unsigned char data[4];
   1691 
   1692   vms_debug2 ((6, "image_write_l (%08lx)\n", value));
   1693 
   1694   bfd_putl32 (value, data);
   1695   return image_write (abfd, data, sizeof (data));
   1696 }
   1697 
   1698 /* Write 8-byte quad to image.  */
   1699 
   1700 static bool
   1701 image_write_q (bfd * abfd, bfd_vma value)
   1702 {
   1703   unsigned char data[8];
   1704 
   1705   vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
   1706 
   1707   bfd_putl64 (value, data);
   1708   return image_write (abfd, data, sizeof (data));
   1709 }
   1710 
   1711 static const char *
   1713 _bfd_vms_etir_name (int cmd)
   1714 {
   1715   switch (cmd)
   1716     {
   1717     case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL";
   1718     case ETIR__C_STA_LW: return "ETIR__C_STA_LW";
   1719     case ETIR__C_STA_QW: return "ETIR__C_STA_QW";
   1720     case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ";
   1721     case ETIR__C_STA_LI: return "ETIR__C_STA_LI";
   1722     case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD";
   1723     case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG";
   1724     case ETIR__C_STO_B: return "ETIR__C_STO_B";
   1725     case ETIR__C_STO_W: return "ETIR__C_STO_W";
   1726     case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL";
   1727     case ETIR__C_STO_CA: return "ETIR__C_STO_CA";
   1728     case ETIR__C_STO_RB: return "ETIR__C_STO_RB";
   1729     case ETIR__C_STO_AB: return "ETIR__C_STO_AB";
   1730     case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF";
   1731     case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM";
   1732     case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR";
   1733     case ETIR__C_STO_LW: return "ETIR__C_STO_LW";
   1734     case ETIR__C_STO_QW: return "ETIR__C_STO_QW";
   1735     case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW";
   1736     case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB";
   1737     case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL";
   1738     case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS";
   1739     case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD";
   1740     case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB";
   1741     case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV";
   1742     case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH";
   1743     case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT";
   1744     case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF";
   1745     case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT";
   1746     case ETIR__C_STC_LP: return "ETIR__C_STC_LP";
   1747     case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL";
   1748     case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA";
   1749     case ETIR__C_STC_PS: return "ETIR__C_STC_PS";
   1750     case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS";
   1751     case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL";
   1752     case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS";
   1753     case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL";
   1754     case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS";
   1755     case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL";
   1756     case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS";
   1757     case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL";
   1758     case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS";
   1759     case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL";
   1760     case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB";
   1761     case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB";
   1762     case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB";
   1763     case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC";
   1764     case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC";
   1765     case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL";
   1766 
   1767     default:
   1768       /* These names have not yet been added to this switch statement.  */
   1769       _bfd_error_handler (_("unknown ETIR command %d"), cmd);
   1770     }
   1771 
   1772   return NULL;
   1773 }
   1774 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
   1775 
   1776 static void
   1777 _bfd_vms_get_value (bfd *abfd,
   1778 		    const unsigned char *ascic,
   1779 		    const unsigned char *max_ascic,
   1780 		    struct bfd_link_info *info,
   1781 		    bfd_vma *vma,
   1782 		    struct alpha_vms_link_hash_entry **hp)
   1783 {
   1784   char name[257];
   1785   unsigned int len;
   1786   unsigned int i;
   1787   struct alpha_vms_link_hash_entry *h;
   1788 
   1789   /* Not linking.  Do not try to resolve the symbol.  */
   1790   if (info == NULL)
   1791     {
   1792       *vma = 0;
   1793       *hp = NULL;
   1794       return;
   1795     }
   1796 
   1797   len = *ascic;
   1798   if (ascic + len >= max_ascic)
   1799     {
   1800       _bfd_error_handler (_("corrupt vms value"));
   1801       *vma = 0;
   1802       *hp = NULL;
   1803       return;
   1804     }
   1805 
   1806   for (i = 0; i < len; i++)
   1807     name[i] = ascic[i + 1];
   1808   name[i] = 0;
   1809 
   1810   h = (struct alpha_vms_link_hash_entry *)
   1811     bfd_link_hash_lookup (info->hash, name, false, false, true);
   1812 
   1813   *hp = h;
   1814 
   1815   if (h != NULL
   1816       && (h->root.type == bfd_link_hash_defined
   1817 	  || h->root.type == bfd_link_hash_defweak))
   1818     *vma = h->root.u.def.value
   1819       + h->root.u.def.section->output_offset
   1820       + h->root.u.def.section->output_section->vma;
   1821   else if (h && h->root.type == bfd_link_hash_undefweak)
   1822     *vma = 0;
   1823   else
   1824     {
   1825       (*info->callbacks->undefined_symbol)
   1826 	(info, name, abfd, PRIV (image_section), PRIV (image_offset), true);
   1827       *vma = 0;
   1828     }
   1829 }
   1830 
   1831 #define RELC_NONE 0
   1832 #define RELC_REL  1
   1833 #define RELC_SHR_BASE 0x10000
   1834 #define RELC_SEC_BASE 0x20000
   1835 #define RELC_MASK     0x0ffff
   1836 
   1837 static unsigned int
   1838 alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h)
   1839 {
   1840   /* Handle undefined symbols.  */
   1841   if (h == NULL || h->sym == NULL)
   1842     return RELC_NONE;
   1843 
   1844   if (h->sym->typ == EGSD__C_SYMG)
   1845     {
   1846       if (h->sym->flags & EGSY__V_REL)
   1847 	return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index);
   1848       else
   1849 	{
   1850 	  /* Can this happen (non-relocatable symg) ?  I'd like to see
   1851 	     an example.  */
   1852 	  abort ();
   1853 	}
   1854     }
   1855   if (h->sym->typ == EGSD__C_SYM)
   1856     {
   1857       if (h->sym->flags & EGSY__V_REL)
   1858 	return RELC_REL;
   1859       else
   1860 	return RELC_NONE;
   1861     }
   1862   abort ();
   1863 }
   1864 
   1865 static bfd_vma
   1866 alpha_vms_get_sym_value (asection *sect, bfd_vma addr)
   1867 {
   1868   return sect->output_section->vma + sect->output_offset + addr;
   1869 }
   1870 
   1871 static bfd_vma
   1872 alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info,
   1873 		       unsigned int rel, bfd_vma vma)
   1874 {
   1875   asection *sec;
   1876   unsigned int sec_indx;
   1877 
   1878   if (PRIV (sections) == NULL)
   1879     return 0;
   1880 
   1881   sec_indx = rel & RELC_MASK;
   1882   if (sec_indx >= PRIV (section_count))
   1883     return 0;
   1884 
   1885   sec = PRIV (sections)[sec_indx];
   1886 
   1887   if (info)
   1888     {
   1889       if (sec->output_section == NULL)
   1890 	abort ();
   1891       return vma + sec->output_section->vma + sec->output_offset;
   1892     }
   1893   else
   1894     return vma + sec->vma;
   1895 }
   1896 
   1897 /* Read an ETIR record from ABFD.  If INFO is not null, put the content into
   1898    the output section (used during linking).
   1899    Return FALSE in case of error.  */
   1900 
   1901 static bool
   1902 _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
   1903 {
   1904   unsigned char *ptr;
   1905   unsigned int length;
   1906   unsigned char *maxptr;
   1907   bfd_vma op1 = 0;
   1908   bfd_vma op2 = 0;
   1909   unsigned int rel1 = RELC_NONE;
   1910   unsigned int rel2 = RELC_NONE;
   1911   struct alpha_vms_link_hash_entry *h;
   1912 
   1913   PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
   1914   PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
   1915 
   1916   ptr = PRIV (recrd.rec);
   1917   length = PRIV (recrd.rec_size);
   1918   maxptr = ptr + length;
   1919 
   1920   vms_debug2 ((2, "ETIR: %d bytes\n", length));
   1921 
   1922   while (ptr < maxptr)
   1923     {
   1924       unsigned int cmd, cmd_length;
   1925 
   1926       if (ptr + 4 > maxptr)
   1927 	goto corrupt_etir;
   1928 
   1929       cmd = bfd_getl16 (ptr);
   1930       cmd_length = bfd_getl16 (ptr + 2);
   1931 
   1932       /* PR 21589 and 21579: Check for a corrupt ETIR record.  */
   1933       if (cmd_length < 4 || cmd_length > (size_t) (maxptr - ptr))
   1934 	{
   1935 	corrupt_etir:
   1936 	  _bfd_error_handler (_("corrupt ETIR record encountered"));
   1937 	  bfd_set_error (bfd_error_bad_value);
   1938 	  return false;
   1939 	}
   1940       ptr += 4;
   1941       cmd_length -= 4;
   1942 
   1943 #if VMS_DEBUG
   1944       _bfd_vms_debug (4, "etir: %s(%d)\n",
   1945 		      _bfd_vms_etir_name (cmd), cmd);
   1946       _bfd_hexdump (8, ptr, cmd_length, 0);
   1947 #endif
   1948 
   1949       switch (cmd)
   1950 	{
   1951 	  /* Stack global
   1952 	     arg: cs	symbol name
   1953 
   1954 	     stack 32 bit value of symbol (high bits set to 0).  */
   1955 	case ETIR__C_STA_GBL:
   1956 	  _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
   1957 	  if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h)))
   1958 	    return false;
   1959 	  break;
   1960 
   1961 	  /* Stack longword
   1962 	     arg: lw	value
   1963 
   1964 	     stack 32 bit value, sign extend to 64 bit.  */
   1965 	case ETIR__C_STA_LW:
   1966 	  if (cmd_length < 4)
   1967 	    goto corrupt_etir;
   1968 	  if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE))
   1969 	    return false;
   1970 	  break;
   1971 
   1972 	  /* Stack quadword
   1973 	     arg: qw	value
   1974 
   1975 	     stack 64 bit value of symbol.  */
   1976 	case ETIR__C_STA_QW:
   1977 	  if (cmd_length < 8)
   1978 	    goto corrupt_etir;
   1979 	  if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE))
   1980 	    return false;
   1981 	  break;
   1982 
   1983 	  /* Stack psect base plus quadword offset
   1984 	     arg: lw	section index
   1985 	     qw	signed quadword offset (low 32 bits)
   1986 
   1987 	     Stack qw argument and section index
   1988 	     (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB).  */
   1989 	case ETIR__C_STA_PQ:
   1990 	  {
   1991 	    int psect;
   1992 
   1993 	    if (cmd_length < 12)
   1994 	      goto corrupt_etir;
   1995 	    psect = bfd_getl32 (ptr);
   1996 	    if ((unsigned int) psect >= PRIV (section_count))
   1997 	      {
   1998 		_bfd_error_handler (_("bad section index in %s"),
   1999 				    _bfd_vms_etir_name (cmd));
   2000 		bfd_set_error (bfd_error_bad_value);
   2001 		return false;
   2002 	      }
   2003 	    op1 = bfd_getl64 (ptr + 4);
   2004 	    if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE))
   2005 	      return false;
   2006 	  }
   2007 	  break;
   2008 
   2009 	case ETIR__C_STA_LI:
   2010 	case ETIR__C_STA_MOD:
   2011 	case ETIR__C_STA_CKARG:
   2012 	  _bfd_error_handler (_("unsupported STA cmd %s"),
   2013 			      _bfd_vms_etir_name (cmd));
   2014 	  return false;
   2015 	  break;
   2016 
   2017 	  /* Store byte: pop stack, write byte
   2018 	     arg: -.  */
   2019 	case ETIR__C_STO_B:
   2020 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2021 	    return false;
   2022 	  if (rel1 != RELC_NONE)
   2023 	    goto bad_context;
   2024 	  if (!image_write_b (abfd, (unsigned int) op1 & 0xff))
   2025 	    return false;
   2026 	  break;
   2027 
   2028 	  /* Store word: pop stack, write word
   2029 	     arg: -.  */
   2030 	case ETIR__C_STO_W:
   2031 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2032 	    return false;
   2033 	  if (rel1 != RELC_NONE)
   2034 	    goto bad_context;
   2035 	  if (!image_write_w (abfd, (unsigned int) op1 & 0xffff))
   2036 	    return false;
   2037 	  break;
   2038 
   2039 	  /* Store longword: pop stack, write longword
   2040 	     arg: -.  */
   2041 	case ETIR__C_STO_LW:
   2042 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2043 	    return false;
   2044 	  if (rel1 & RELC_SEC_BASE)
   2045 	    {
   2046 	      op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
   2047 	      rel1 = RELC_REL;
   2048 	    }
   2049 	  else if (rel1 & RELC_SHR_BASE)
   2050 	    {
   2051 	      if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1))
   2052 		return false;
   2053 	      rel1 = RELC_NONE;
   2054 	    }
   2055 	  if (rel1 != RELC_NONE)
   2056 	    {
   2057 	      if (rel1 != RELC_REL)
   2058 		abort ();
   2059 	      if (!alpha_vms_add_lw_reloc (info))
   2060 		return false;
   2061 	    }
   2062 	  if (!image_write_l (abfd, op1))
   2063 	    return false;
   2064 	  break;
   2065 
   2066 	  /* Store quadword: pop stack, write quadword
   2067 	     arg: -.  */
   2068 	case ETIR__C_STO_QW:
   2069 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2070 	    return false;
   2071 	  if (rel1 & RELC_SEC_BASE)
   2072 	    {
   2073 	      op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
   2074 	      rel1 = RELC_REL;
   2075 	    }
   2076 	  else if (rel1 & RELC_SHR_BASE)
   2077 	    abort ();
   2078 	  if (rel1 != RELC_NONE)
   2079 	    {
   2080 	      if (rel1 != RELC_REL)
   2081 		abort ();
   2082 	      if (!alpha_vms_add_qw_reloc (info))
   2083 		return false;
   2084 	    }
   2085 	  if (!image_write_q (abfd, op1))
   2086 	    return false;
   2087 	  break;
   2088 
   2089 	  /* Store immediate repeated: pop stack for repeat count
   2090 	     arg: lw	byte count
   2091 	     da	data.  */
   2092 	case ETIR__C_STO_IMMR:
   2093 	  {
   2094 	    size_t size;
   2095 
   2096 	    if (cmd_length < 4)
   2097 	      goto corrupt_etir;
   2098 	    size = bfd_getl32 (ptr);
   2099 	    if (size > cmd_length - 4)
   2100 	      goto corrupt_etir;
   2101 	    if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2102 	      return false;
   2103 	    if (rel1 != RELC_NONE)
   2104 	      goto bad_context;
   2105 	    if (size == 0)
   2106 	      break;
   2107 	    op1 &= 0xffffffff;
   2108 	    if (!image_write_section (abfd))
   2109 	      {
   2110 		/* We are just sizing.  Optimise a little.  */
   2111 		size *= op1;
   2112 		op1 = 1;
   2113 	      }
   2114 	    while (op1-- > 0)
   2115 	      if (!image_write (abfd, ptr + 4, size))
   2116 		return false;
   2117 	  }
   2118 	  break;
   2119 
   2120 	  /* Store global: write symbol value
   2121 	     arg: cs	global symbol name.  */
   2122 	case ETIR__C_STO_GBL:
   2123 	  _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
   2124 	  if (h && h->sym)
   2125 	    {
   2126 	      if (h->sym->typ == EGSD__C_SYMG)
   2127 		{
   2128 		  if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner,
   2129 					       h->sym->symbol_vector))
   2130 		    return false;
   2131 		  op1 = 0;
   2132 		}
   2133 	      else
   2134 		{
   2135 		  op1 = alpha_vms_get_sym_value (h->sym->section,
   2136 						 h->sym->value);
   2137 		  if (!alpha_vms_add_qw_reloc (info))
   2138 		    return false;
   2139 		}
   2140 	    }
   2141 	  if (!image_write_q (abfd, op1))
   2142 	    return false;
   2143 	  break;
   2144 
   2145 	  /* Store code address: write address of entry point
   2146 	     arg: cs	global symbol name (procedure).  */
   2147 	case ETIR__C_STO_CA:
   2148 	  _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
   2149 	  if (h && h->sym)
   2150 	    {
   2151 	      if (h->sym->flags & EGSY__V_NORM)
   2152 		{
   2153 		  /* That's really a procedure.  */
   2154 		  if (h->sym->typ == EGSD__C_SYMG)
   2155 		    {
   2156 		      if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner))
   2157 			return false;
   2158 		      op1 = h->sym->symbol_vector;
   2159 		    }
   2160 		  else
   2161 		    {
   2162 		      op1 = alpha_vms_get_sym_value (h->sym->code_section,
   2163 						     h->sym->code_value);
   2164 		      if (!alpha_vms_add_qw_reloc (info))
   2165 			return false;
   2166 		    }
   2167 		}
   2168 	      else
   2169 		{
   2170 		  /* Symbol is not a procedure.  */
   2171 		  abort ();
   2172 		}
   2173 	    }
   2174 	  if (!image_write_q (abfd, op1))
   2175 	    return false;
   2176 	  break;
   2177 
   2178 	  /* Store offset to psect: pop stack, add low 32 bits to base of psect
   2179 	     arg: none.  */
   2180 	case ETIR__C_STO_OFF:
   2181 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2182 	    return false;
   2183 
   2184 	  if (!(rel1 & RELC_SEC_BASE))
   2185 	    abort ();
   2186 
   2187 	  op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
   2188 	  rel1 = RELC_REL;
   2189 	  if (!image_write_q (abfd, op1))
   2190 	    return false;
   2191 	  break;
   2192 
   2193 	  /* Store immediate
   2194 	     arg: lw	count of bytes
   2195 	     da	data.  */
   2196 	case ETIR__C_STO_IMM:
   2197 	  {
   2198 	    unsigned int size;
   2199 
   2200 	    if (cmd_length < 4)
   2201 	      goto corrupt_etir;
   2202 	    size = bfd_getl32 (ptr);
   2203 	    if (size > cmd_length - 4)
   2204 	      goto corrupt_etir;
   2205 	    if (!image_write (abfd, ptr + 4, size))
   2206 	      return false;
   2207 	  }
   2208 	  break;
   2209 
   2210 	  /* This code is 'reserved to digital' according to the openVMS
   2211 	     linker manual, however it is generated by the DEC C compiler
   2212 	     and defined in the include file.
   2213 	     FIXME, since the following is just a guess
   2214 	     store global longword: store 32bit value of symbol
   2215 	     arg: cs	symbol name.  */
   2216 	case ETIR__C_STO_GBL_LW:
   2217 	  _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
   2218 #if 0
   2219 	  abort ();
   2220 #endif
   2221 	  if (!image_write_l (abfd, op1))
   2222 	    return false;
   2223 	  break;
   2224 
   2225 	case ETIR__C_STO_RB:
   2226 	case ETIR__C_STO_AB:
   2227 	case ETIR__C_STO_LP_PSB:
   2228 	  _bfd_error_handler (_("%s: not supported"),
   2229 			      _bfd_vms_etir_name (cmd));
   2230 	  return false;
   2231 	  break;
   2232 	case ETIR__C_STO_HINT_GBL:
   2233 	case ETIR__C_STO_HINT_PS:
   2234 	  _bfd_error_handler (_("%s: not implemented"),
   2235 			      _bfd_vms_etir_name (cmd));
   2236 	  return false;
   2237 	  break;
   2238 
   2239 	  /* 200 Store-conditional Linkage Pair
   2240 	     arg: none.  */
   2241 	case ETIR__C_STC_LP:
   2242 
   2243 	  /* 202 Store-conditional Address at global address
   2244 	     lw	linkage index
   2245 	     cs	global name.  */
   2246 
   2247 	case ETIR__C_STC_GBL:
   2248 
   2249 	  /* 203 Store-conditional Code Address at global address
   2250 	     lw	linkage index
   2251 	     cs	procedure name.  */
   2252 	case ETIR__C_STC_GCA:
   2253 
   2254 	  /* 204 Store-conditional Address at psect + offset
   2255 	     lw	linkage index
   2256 	     lw	psect index
   2257 	     qw	offset.  */
   2258 	case ETIR__C_STC_PS:
   2259 	  _bfd_error_handler (_("%s: not supported"),
   2260 			      _bfd_vms_etir_name (cmd));
   2261 	  return false;
   2262 	  break;
   2263 
   2264 	  /* 201 Store-conditional Linkage Pair with Procedure Signature
   2265 	     lw	linkage index
   2266 	     cs	procedure name
   2267 	     by	signature length
   2268 	     da	signature.  */
   2269 
   2270 	case ETIR__C_STC_LP_PSB:
   2271 	  if (cmd_length < 4)
   2272 	    goto corrupt_etir;
   2273 	  _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h);
   2274 	  if (h && h->sym)
   2275 	    {
   2276 	      if (h->sym->typ == EGSD__C_SYMG)
   2277 		{
   2278 		  if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner))
   2279 		    return false;
   2280 		  op1 = h->sym->symbol_vector;
   2281 		  op2 = 0;
   2282 		}
   2283 	      else
   2284 		{
   2285 		  op1 = alpha_vms_get_sym_value (h->sym->code_section,
   2286 						 h->sym->code_value);
   2287 		  op2 = alpha_vms_get_sym_value (h->sym->section,
   2288 						h->sym->value);
   2289 		}
   2290 	    }
   2291 	  else
   2292 	    {
   2293 	      /* Undefined symbol.  */
   2294 	      op1 = 0;
   2295 	      op2 = 0;
   2296 	    }
   2297 	  if (!image_write_q (abfd, op1)
   2298 	      || !image_write_q (abfd, op2))
   2299 	    return false;
   2300 	  break;
   2301 
   2302 	  /* 205 Store-conditional NOP at address of global
   2303 	     arg: none.  */
   2304 	case ETIR__C_STC_NOP_GBL:
   2305 	  /* ALPHA_R_NOP */
   2306 
   2307 	  /* 207 Store-conditional BSR at global address
   2308 	     arg: none.  */
   2309 
   2310 	case ETIR__C_STC_BSR_GBL:
   2311 	  /* ALPHA_R_BSR */
   2312 
   2313 	  /* 209 Store-conditional LDA at global address
   2314 	     arg: none.  */
   2315 
   2316 	case ETIR__C_STC_LDA_GBL:
   2317 	  /* ALPHA_R_LDA */
   2318 
   2319 	  /* 211 Store-conditional BSR or Hint at global address
   2320 	     arg: none.  */
   2321 
   2322 	case ETIR__C_STC_BOH_GBL:
   2323 	  /* Currentl ignored.  */
   2324 	  break;
   2325 
   2326 	  /* 213 Store-conditional NOP,BSR or HINT at global address
   2327 	     arg: none.  */
   2328 
   2329 	case ETIR__C_STC_NBH_GBL:
   2330 
   2331 	  /* 206 Store-conditional NOP at pect + offset
   2332 	     arg: none.  */
   2333 
   2334 	case ETIR__C_STC_NOP_PS:
   2335 
   2336 	  /* 208 Store-conditional BSR at pect + offset
   2337 	     arg: none.  */
   2338 
   2339 	case ETIR__C_STC_BSR_PS:
   2340 
   2341 	  /* 210 Store-conditional LDA at psect + offset
   2342 	     arg: none.  */
   2343 
   2344 	case ETIR__C_STC_LDA_PS:
   2345 
   2346 	  /* 212 Store-conditional BSR or Hint at pect + offset
   2347 	     arg: none.  */
   2348 
   2349 	case ETIR__C_STC_BOH_PS:
   2350 
   2351 	  /* 214 Store-conditional NOP, BSR or HINT at psect + offset
   2352 	     arg: none.  */
   2353 	case ETIR__C_STC_NBH_PS:
   2354 	  _bfd_error_handler (_("%s: not supported"),
   2355 			      _bfd_vms_etir_name (cmd));
   2356 	  return false;
   2357 	  break;
   2358 
   2359 	  /* Det relocation base: pop stack, set image location counter
   2360 	     arg: none.  */
   2361 	case ETIR__C_CTL_SETRB:
   2362 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2363 	    return false;
   2364 	  if (!(rel1 & RELC_SEC_BASE))
   2365 	    abort ();
   2366 	  image_set_ptr (abfd, op1, rel1 & RELC_MASK, info);
   2367 	  break;
   2368 
   2369 	  /* Augment relocation base: increment image location counter by offset
   2370 	     arg: lw	offset value.  */
   2371 	case ETIR__C_CTL_AUGRB:
   2372 	  if (cmd_length < 4)
   2373 	    goto corrupt_etir;
   2374 	  op1 = bfd_getl32 (ptr);
   2375 	  image_inc_ptr (abfd, op1);
   2376 	  break;
   2377 
   2378 	  /* Define location: pop index, save location counter under index
   2379 	     arg: none.  */
   2380 	case ETIR__C_CTL_DFLOC:
   2381 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2382 	    return false;
   2383 	  if (rel1 != RELC_NONE)
   2384 	    goto bad_context;
   2385 	  if (!dst_define_location (abfd, op1))
   2386 	    return false;
   2387 	  break;
   2388 
   2389 	  /* Set location: pop index, restore location counter from index
   2390 	     arg: none.  */
   2391 	case ETIR__C_CTL_STLOC:
   2392 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2393 	    return false;
   2394 	  if (rel1 != RELC_NONE)
   2395 	    goto bad_context;
   2396 	  if (!dst_restore_location (abfd, op1))
   2397 	    {
   2398 	      bfd_set_error (bfd_error_bad_value);
   2399 	      _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC");
   2400 	      return false;
   2401 	    }
   2402 	  break;
   2403 
   2404 	  /* Stack defined location: pop index, push location counter from index
   2405 	     arg: none.  */
   2406 	case ETIR__C_CTL_STKDL:
   2407 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2408 	    return false;
   2409 	  if (rel1 != RELC_NONE)
   2410 	    goto bad_context;
   2411 	  if (!dst_retrieve_location (abfd, &op1))
   2412 	    {
   2413 	      bfd_set_error (bfd_error_bad_value);
   2414 	      _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL");
   2415 	      return false;
   2416 	    }
   2417 	  if (!_bfd_vms_push (abfd, op1, RELC_NONE))
   2418 	    return false;
   2419 	  break;
   2420 
   2421 	case ETIR__C_OPR_NOP:      /* No-op.  */
   2422 	  break;
   2423 
   2424 	case ETIR__C_OPR_ADD:      /* Add.  */
   2425 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2426 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2427 	    return false;
   2428 	  if (rel1 == RELC_NONE && rel2 != RELC_NONE)
   2429 	    rel1 = rel2;
   2430 	  else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
   2431 	    goto bad_context;
   2432 	  if (!_bfd_vms_push (abfd, op1 + op2, rel1))
   2433 	    return false;
   2434 	  break;
   2435 
   2436 	case ETIR__C_OPR_SUB:      /* Subtract.  */
   2437 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2438 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2439 	    return false;
   2440 	  if (rel1 == RELC_NONE && rel2 != RELC_NONE)
   2441 	    rel1 = rel2;
   2442 	  else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE))
   2443 	    {
   2444 	      op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
   2445 	      op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2);
   2446 	      rel1 = RELC_NONE;
   2447 	    }
   2448 	  else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
   2449 	    goto bad_context;
   2450 	  if (!_bfd_vms_push (abfd, op2 - op1, rel1))
   2451 	    return false;
   2452 	  break;
   2453 
   2454 	case ETIR__C_OPR_MUL:      /* Multiply.  */
   2455 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2456 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2457 	    return false;
   2458 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2459 	    goto bad_context;
   2460 	  if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE))
   2461 	    return false;
   2462 	  break;
   2463 
   2464 	case ETIR__C_OPR_DIV:      /* Divide.  */
   2465 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2466 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2467 	    return false;
   2468 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2469 	    goto bad_context;
   2470 	  if (op1 == 0)
   2471 	    {
   2472 	      /* Divide by zero is supposed to give a result of zero,
   2473 		 and a non-fatal warning message.  */
   2474 	      _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV");
   2475 	      if (!_bfd_vms_push (abfd, 0, RELC_NONE))
   2476 		return false;
   2477 	    }
   2478 	  else
   2479 	    {
   2480 	      if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE))
   2481 		return false;
   2482 	    }
   2483 	  break;
   2484 
   2485 	case ETIR__C_OPR_AND:      /* Logical AND.  */
   2486 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2487 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2488 	    return false;
   2489 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2490 	    goto bad_context;
   2491 	  if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE))
   2492 	    return false;
   2493 	  break;
   2494 
   2495 	case ETIR__C_OPR_IOR:      /* Logical inclusive OR.  */
   2496 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2497 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2498 	    return false;
   2499 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2500 	    goto bad_context;
   2501 	  if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE))
   2502 	    return false;
   2503 	  break;
   2504 
   2505 	case ETIR__C_OPR_EOR:      /* Logical exclusive OR.  */
   2506 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2507 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2508 	    return false;
   2509 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2510 	    goto bad_context;
   2511 	  if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE))
   2512 	    return false;
   2513 	  break;
   2514 
   2515 	case ETIR__C_OPR_NEG:      /* Negate.  */
   2516 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2517 	    return false;
   2518 	  if (rel1 != RELC_NONE)
   2519 	    goto bad_context;
   2520 	  if (!_bfd_vms_push (abfd, -op1, RELC_NONE))
   2521 	    return false;
   2522 	  break;
   2523 
   2524 	case ETIR__C_OPR_COM:      /* Complement.  */
   2525 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2526 	    return false;
   2527 	  if (rel1 != RELC_NONE)
   2528 	    goto bad_context;
   2529 	  if (!_bfd_vms_push (abfd, ~op1, RELC_NONE))
   2530 	    return false;
   2531 	  break;
   2532 
   2533 	case ETIR__C_OPR_ASH:      /* Arithmetic shift.  */
   2534 	  if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2535 	      || !_bfd_vms_pop (abfd, &op2, &rel2))
   2536 	    return false;
   2537 	  if (rel1 != RELC_NONE || rel2 != RELC_NONE)
   2538 	    {
   2539 	    bad_context:
   2540 	      _bfd_error_handler (_("invalid use of %s with contexts"),
   2541 				  _bfd_vms_etir_name (cmd));
   2542 	      return false;
   2543 	    }
   2544 	  if ((bfd_signed_vma) op2 < 0)
   2545 	    {
   2546 	      /* Shift right.  */
   2547 	      bfd_vma sign;
   2548 	      op2 = -op2;
   2549 	      if (op2 >= CHAR_BIT * sizeof (op1))
   2550 		op2 = CHAR_BIT * sizeof (op1) - 1;
   2551 	      /* op1 = (bfd_signed_vma) op1 >> op2; */
   2552 	      sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1));
   2553 	      op1 >>= op2;
   2554 	      sign >>= op2;
   2555 	      op1 = (op1 ^ sign) - sign;
   2556 	    }
   2557 	  else
   2558 	    {
   2559 	      /* Shift left.  */
   2560 	      if (op2 >= CHAR_BIT * sizeof (op1))
   2561 		op1 = 0;
   2562 	      else
   2563 		op1 <<= op2;
   2564 	    }
   2565 	  if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym.  */
   2566 	    return false;
   2567 	  break;
   2568 
   2569 	case ETIR__C_OPR_INSV:      /* Insert field.   */
   2570 	case ETIR__C_OPR_USH:       /* Unsigned shift.   */
   2571 	case ETIR__C_OPR_ROT:       /* Rotate.  */
   2572 	case ETIR__C_OPR_REDEF:     /* Redefine symbol to current location.  */
   2573 	case ETIR__C_OPR_DFLIT:     /* Define a literal.  */
   2574 	  _bfd_error_handler (_("%s: not supported"),
   2575 			      _bfd_vms_etir_name (cmd));
   2576 	  return false;
   2577 	  break;
   2578 
   2579 	case ETIR__C_OPR_SEL:      /* Select.  */
   2580 	  if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2581 	    return false;
   2582 	  if (op1 & 0x01L)
   2583 	    {
   2584 	      if (!_bfd_vms_pop (abfd, &op1, &rel1))
   2585 		return false;
   2586 	    }
   2587 	  else
   2588 	    {
   2589 	      if (!_bfd_vms_pop (abfd, &op1, &rel1)
   2590 		  || !_bfd_vms_pop (abfd, &op2, &rel2))
   2591 		return false;
   2592 	      if (!_bfd_vms_push (abfd, op1, rel1))
   2593 		return false;
   2594 	    }
   2595 	  break;
   2596 
   2597 	default:
   2598 	  _bfd_error_handler (_("reserved cmd %d"), cmd);
   2599 	  return false;
   2600 	  break;
   2601 	}
   2602 
   2603       ptr += cmd_length;
   2604     }
   2605 
   2606   return true;
   2607 }
   2608 
   2609 /* Process EDBG/ETBT record.
   2610    Return TRUE on success, FALSE on error  */
   2611 
   2612 static bool
   2613 vms_slurp_debug (bfd *abfd)
   2614 {
   2615   asection *section = PRIV (dst_section);
   2616 
   2617   if (section == NULL)
   2618     {
   2619       /* We have no way to find out beforehand how much debug info there
   2620 	 is in an object file, so pick an initial amount and grow it as
   2621 	 needed later.  */
   2622       flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC
   2623 	| SEC_IN_MEMORY;
   2624 
   2625       section = bfd_make_section (abfd, "$DST$");
   2626       if (!section)
   2627 	return false;
   2628       if (!bfd_set_section_flags (section, flags))
   2629 	return false;
   2630       PRIV (dst_section) = section;
   2631     }
   2632 
   2633   PRIV (image_section) = section;
   2634   PRIV (image_offset) = section->size;
   2635 
   2636   if (!_bfd_vms_slurp_etir (abfd, NULL))
   2637     return false;
   2638 
   2639   section->size = PRIV (image_offset);
   2640   return true;
   2641 }
   2642 
   2643 /* Process EDBG record.
   2644    Return TRUE on success, FALSE on error.  */
   2645 
   2646 static bool
   2647 _bfd_vms_slurp_edbg (bfd *abfd)
   2648 {
   2649   vms_debug2 ((2, "EDBG\n"));
   2650 
   2651   abfd->flags |= HAS_DEBUG | HAS_LINENO;
   2652 
   2653   return vms_slurp_debug (abfd);
   2654 }
   2655 
   2656 /* Process ETBT record.
   2657    Return TRUE on success, FALSE on error.  */
   2658 
   2659 static bool
   2660 _bfd_vms_slurp_etbt (bfd *abfd)
   2661 {
   2662   vms_debug2 ((2, "ETBT\n"));
   2663 
   2664   abfd->flags |= HAS_LINENO;
   2665 
   2666   return vms_slurp_debug (abfd);
   2667 }
   2668 
   2669 /* Process EEOM record.
   2670    Return TRUE on success, FALSE on error.  */
   2671 
   2672 static bool
   2673 _bfd_vms_slurp_eeom (bfd *abfd)
   2674 {
   2675   struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
   2676 
   2677   vms_debug2 ((2, "EEOM\n"));
   2678 
   2679   /* PR 21813: Check for an undersized record.  */
   2680   if (PRIV (recrd.rec_size) < 10)
   2681     {
   2682       _bfd_error_handler (_("corrupt EEOM record - size is too small"));
   2683       bfd_set_error (bfd_error_bad_value);
   2684       return false;
   2685     }
   2686 
   2687   PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
   2688   PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
   2689   if (PRIV (eom_data).eom_w_comcod > 1)
   2690     {
   2691       _bfd_error_handler (_("object module not error-free !"));
   2692       bfd_set_error (bfd_error_bad_value);
   2693       return false;
   2694     }
   2695 
   2696   PRIV (eom_data).eom_has_transfer = false;
   2697   if (PRIV (recrd.rec_size) >= sizeof (*eeom))
   2698     {
   2699       PRIV (eom_data).eom_has_transfer = true;
   2700       PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
   2701       PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
   2702       PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
   2703 
   2704       abfd->start_address = PRIV (eom_data).eom_l_tfradr;
   2705     }
   2706   return true;
   2707 }
   2708 
   2709 /* Slurp an ordered set of VMS object records.  Return FALSE on error.  */
   2710 
   2711 static bool
   2712 _bfd_vms_slurp_object_records (bfd * abfd)
   2713 {
   2714   bool ok;
   2715   int type;
   2716 
   2717   do
   2718     {
   2719       vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
   2720 
   2721       type = _bfd_vms_get_object_record (abfd);
   2722       if (type < 0)
   2723 	{
   2724 	  vms_debug2 ((2, "next_record failed\n"));
   2725 	  return false;
   2726 	}
   2727 
   2728       switch (type)
   2729 	{
   2730 	case EOBJ__C_EMH:
   2731 	  ok = _bfd_vms_slurp_ehdr (abfd);
   2732 	  break;
   2733 	case EOBJ__C_EEOM:
   2734 	  ok = _bfd_vms_slurp_eeom (abfd);
   2735 	  break;
   2736 	case EOBJ__C_EGSD:
   2737 	  ok = _bfd_vms_slurp_egsd (abfd);
   2738 	  break;
   2739 	case EOBJ__C_ETIR:
   2740 	  ok = true; /* _bfd_vms_slurp_etir (abfd); */
   2741 	  break;
   2742 	case EOBJ__C_EDBG:
   2743 	  ok = _bfd_vms_slurp_edbg (abfd);
   2744 	  break;
   2745 	case EOBJ__C_ETBT:
   2746 	  ok = _bfd_vms_slurp_etbt (abfd);
   2747 	  break;
   2748 	default:
   2749 	  ok = false;
   2750 	}
   2751       if (!ok)
   2752 	{
   2753 	  vms_debug2 ((2, "slurp type %d failed\n", type));
   2754 	  return false;
   2755 	}
   2756     }
   2757   while (type != EOBJ__C_EEOM);
   2758 
   2759   return true;
   2760 }
   2761 
   2762 /* Initialize private data  */
   2763 static bool
   2764 vms_initialize (bfd * abfd)
   2765 {
   2766   size_t amt;
   2767 
   2768   amt = sizeof (struct vms_private_data_struct);
   2769   abfd->tdata.any = bfd_zalloc (abfd, amt);
   2770   if (abfd->tdata.any == NULL)
   2771     return false;
   2772 
   2773   PRIV (recrd.file_format) = FF_UNKNOWN;
   2774 
   2775   amt = sizeof (struct stack_struct) * STACKSIZE;
   2776   PRIV (stack) = bfd_alloc (abfd, amt);
   2777   if (PRIV (stack) == NULL)
   2778     goto error_ret1;
   2779 
   2780   return true;
   2781 
   2782  error_ret1:
   2783   bfd_release (abfd, abfd->tdata.any);
   2784   abfd->tdata.any = NULL;
   2785   return false;
   2786 }
   2787 
   2788 /* Free malloc'd memory.  */
   2789 
   2790 static void
   2791 alpha_vms_free_private (bfd *abfd)
   2792 {
   2793   struct module *module;
   2794 
   2795   free (PRIV (recrd.buf));
   2796   free (PRIV (sections));
   2797   free (PRIV (syms));
   2798   free (PRIV (dst_ptr_offsets));
   2799 
   2800   for (module = PRIV (modules); module; module = module->next)
   2801     free (module->file_table);
   2802 }
   2803 
   2804 /* Check the format for a file being read.
   2805    Return a (bfd_target *) if it's an object file or zero if not.  */
   2806 
   2807 static bfd_cleanup
   2808 alpha_vms_object_p (bfd *abfd)
   2809 {
   2810   unsigned int test_len;
   2811   unsigned char *buf;
   2812 
   2813   vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
   2814 
   2815   /* Allocate alpha-vms specific data.  */
   2816   if (!vms_initialize (abfd))
   2817     return NULL;
   2818 
   2819   if (bfd_seek (abfd, 0, SEEK_SET))
   2820     goto error_ret;
   2821 
   2822   /* The first challenge with VMS is to discover the kind of the file.
   2823 
   2824      Image files (executable or shared images) are stored as a raw
   2825      stream of bytes (like on UNIX), but there is no magic number.
   2826 
   2827      Object files are written with RMS (record management service), ie
   2828      each records are preceeded by its length (on a word - 2 bytes), and
   2829      padded for word-alignment.  That would be simple but when files
   2830      are transfered to a UNIX filesystem (using ftp), records are lost.
   2831      Only the raw content of the records are transfered.  Fortunately,
   2832      the Alpha Object file format also store the length of the record
   2833      in the records.  Is that clear ?  */
   2834 
   2835   /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id,
   2836      2 bytes size repeated) and 12 bytes for images (4 bytes major id,
   2837      4 bytes minor id, 4 bytes length).  */
   2838   test_len = 12;
   2839   buf = _bfd_malloc_and_read (abfd, test_len, test_len);
   2840   if (buf == NULL)
   2841     goto error_ret;
   2842   PRIV (recrd.buf) = buf;
   2843   PRIV (recrd.buf_size) = test_len;
   2844   PRIV (recrd.rec) = buf;
   2845 
   2846   /* Is it an image?  */
   2847   if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
   2848       && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
   2849     {
   2850       unsigned int eisd_offset, eihs_offset;
   2851 
   2852       /* Extract the header size.  */
   2853       PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
   2854 
   2855       /* The header size is 0 for DSF files.  */
   2856       if (PRIV (recrd.rec_size) == 0)
   2857 	PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
   2858 
   2859       /* PR 21813: Check for a truncated record.  */
   2860       /* PR 17512: file: 7d7c57c2.  */
   2861       if (PRIV (recrd.rec_size) < EIHD__C_LENGTH)
   2862 	goto err_wrong_format;
   2863 
   2864       if (bfd_seek (abfd, 0, SEEK_SET))
   2865 	goto error_ret;
   2866 
   2867       free (PRIV (recrd.buf));
   2868       PRIV (recrd.buf) = NULL;
   2869       buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size),
   2870 				  PRIV (recrd.rec_size));
   2871       if (buf == NULL)
   2872 	goto error_ret;
   2873 
   2874       PRIV (recrd.buf) = buf;
   2875       PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
   2876       PRIV (recrd.rec) = buf;
   2877 
   2878       vms_debug2 ((2, "file type is image\n"));
   2879 
   2880       if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset))
   2881 	goto err_wrong_format;
   2882 
   2883       if (!_bfd_vms_slurp_eisd (abfd, eisd_offset))
   2884 	goto err_wrong_format;
   2885 
   2886       /* EIHS is optional.  */
   2887       if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset))
   2888 	goto err_wrong_format;
   2889     }
   2890   else
   2891     {
   2892       int type;
   2893 
   2894       /* Assume it's a module and adjust record pointer if necessary.  */
   2895       maybe_adjust_record_pointer_for_object (abfd);
   2896 
   2897       /* But is it really a module?  */
   2898       if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
   2899 	  && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
   2900 	{
   2901 	  if (vms_get_remaining_object_record (abfd, test_len) <= 0)
   2902 	    goto err_wrong_format;
   2903 
   2904 	  vms_debug2 ((2, "file type is module\n"));
   2905 
   2906 	  type = bfd_getl16 (PRIV (recrd.rec));
   2907 	  if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd))
   2908 	    goto err_wrong_format;
   2909 
   2910 	  if (!_bfd_vms_slurp_object_records (abfd))
   2911 	    goto err_wrong_format;
   2912 	}
   2913       else
   2914 	goto err_wrong_format;
   2915     }
   2916 
   2917   /* Set arch_info to alpha.   */
   2918 
   2919   if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
   2920     goto err_wrong_format;
   2921 
   2922   return alpha_vms_free_private;
   2923 
   2924  err_wrong_format:
   2925   bfd_set_error (bfd_error_wrong_format);
   2926 
   2927  error_ret:
   2928   alpha_vms_free_private (abfd);
   2929   bfd_release (abfd, abfd->tdata.any);
   2930   return NULL;
   2931 }
   2932 
   2933 /* Image write.  */
   2935 
   2936 /* Write an EMH/MHD record.  */
   2937 
   2938 static bool
   2939 _bfd_vms_write_emh (bfd *abfd)
   2940 {
   2941   struct vms_rec_wr *recwr = &PRIV (recwr);
   2942   unsigned char tbuf[18];
   2943 
   2944   _bfd_vms_output_alignment (recwr, 2);
   2945 
   2946   /* EMH.  */
   2947   _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
   2948   _bfd_vms_output_short (recwr, EMH__C_MHD);
   2949   _bfd_vms_output_short (recwr, EOBJ__C_STRLVL);
   2950   _bfd_vms_output_long (recwr, 0);
   2951   _bfd_vms_output_long (recwr, 0);
   2952   _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE);
   2953 
   2954   /* Create module name from filename.  */
   2955   if (bfd_get_filename (abfd) != 0)
   2956     {
   2957       char *module = vms_get_module_name (bfd_get_filename (abfd), true);
   2958       _bfd_vms_output_counted (recwr, module);
   2959       free (module);
   2960     }
   2961   else
   2962     _bfd_vms_output_counted (recwr, "NONAME");
   2963 
   2964   _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
   2965   _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH);
   2966   _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
   2967   return _bfd_vms_output_end (abfd, recwr);
   2968 }
   2969 
   2970 /* Write an EMH/LMN record.  */
   2971 
   2972 static bool
   2973 _bfd_vms_write_lmn (bfd *abfd, const char *name)
   2974 {
   2975   char version [64];
   2976   struct vms_rec_wr *recwr = &PRIV (recwr);
   2977   unsigned int ver = BFD_VERSION / 10000;
   2978 
   2979   /* LMN.  */
   2980   _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
   2981   _bfd_vms_output_short (recwr, EMH__C_LNM);
   2982   snprintf (version, sizeof (version), "%s %d.%d.%d", name,
   2983 	    ver / 10000, (ver / 100) % 100, ver % 100);
   2984   _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
   2985   return _bfd_vms_output_end (abfd, recwr);
   2986 }
   2987 
   2988 
   2989 /* Write eom record for bfd abfd.  Return FALSE on error.  */
   2990 
   2991 static bool
   2992 _bfd_vms_write_eeom (bfd *abfd)
   2993 {
   2994   struct vms_rec_wr *recwr = &PRIV (recwr);
   2995 
   2996   vms_debug2 ((2, "vms_write_eeom\n"));
   2997 
   2998   _bfd_vms_output_alignment (recwr, 2);
   2999 
   3000   _bfd_vms_output_begin (recwr, EOBJ__C_EEOM);
   3001   _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1);
   3002   _bfd_vms_output_byte (recwr, 0);	/* Completion code.  */
   3003   _bfd_vms_output_byte (recwr, 0);	/* Fill byte.  */
   3004 
   3005   if ((abfd->flags & EXEC_P) == 0
   3006       && bfd_get_start_address (abfd) != (bfd_vma)-1)
   3007     {
   3008       asection *section;
   3009 
   3010       section = bfd_get_section_by_name (abfd, ".link");
   3011       if (section == 0)
   3012 	{
   3013 	  bfd_set_error (bfd_error_nonrepresentable_section);
   3014 	  return false;
   3015 	}
   3016       _bfd_vms_output_short (recwr, 0);
   3017       _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
   3018       _bfd_vms_output_long (recwr,
   3019 			     (unsigned long) bfd_get_start_address (abfd));
   3020       _bfd_vms_output_long (recwr, 0);
   3021     }
   3022 
   3023   return _bfd_vms_output_end (abfd, recwr);
   3024 }
   3025 
   3026 static void *
   3027 vector_grow1 (struct vector_type *vec, size_t elsz)
   3028 {
   3029   if (vec->nbr_el >= vec->max_el)
   3030     {
   3031       if (vec->max_el == 0)
   3032 	{
   3033 	  vec->max_el = 16;
   3034 	  vec->els = bfd_malloc (vec->max_el * elsz);
   3035 	}
   3036       else
   3037 	{
   3038 	  size_t amt;
   3039 	  if (vec->max_el > -1u / 2)
   3040 	    {
   3041 	      bfd_set_error (bfd_error_file_too_big);
   3042 	      return NULL;
   3043 	    }
   3044 	  vec->max_el *= 2;
   3045 	  if (_bfd_mul_overflow (vec->max_el, elsz, &amt))
   3046 	    {
   3047 	      bfd_set_error (bfd_error_file_too_big);
   3048 	      return NULL;
   3049 	    }
   3050 	  vec->els = bfd_realloc_or_free (vec->els, amt);
   3051 	}
   3052     }
   3053   if (vec->els == NULL)
   3054     return NULL;
   3055   return (char *) vec->els + elsz * vec->nbr_el++;
   3056 }
   3057 
   3058 /* Bump ABFD file position to next block.  */
   3059 
   3060 static void
   3061 alpha_vms_file_position_block (bfd *abfd)
   3062 {
   3063   /* Next block.  */
   3064   PRIV (file_pos) += VMS_BLOCK_SIZE - 1;
   3065   PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE);
   3066 }
   3067 
   3068 /* Convert from internal structure SRC to external structure DST.  */
   3069 
   3070 static void
   3071 alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src,
   3072 			 struct vms_eisd *dst)
   3073 {
   3074   bfd_putl32 (src->u.eisd.majorid, dst->majorid);
   3075   bfd_putl32 (src->u.eisd.minorid, dst->minorid);
   3076   bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize);
   3077   if (src->u.eisd.eisdsize <= EISD__K_LENEND)
   3078     return;
   3079   bfd_putl32 (src->u.eisd.secsize, dst->secsize);
   3080   bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr);
   3081   bfd_putl32 (src->u.eisd.flags, dst->flags);
   3082   bfd_putl32 (src->u.eisd.vbn, dst->vbn);
   3083   dst->pfc = src->u.eisd.pfc;
   3084   dst->matchctl = src->u.eisd.matchctl;
   3085   dst->type = src->u.eisd.type;
   3086   dst->fill_1 = 0;
   3087   if (src->u.eisd.flags & EISD__M_GBL)
   3088     {
   3089       bfd_putl32 (src->u.gbl_eisd.ident, dst->ident);
   3090       memcpy (dst->gblnam, src->u.gbl_eisd.gblnam,
   3091 	      src->u.gbl_eisd.gblnam[0] + 1);
   3092     }
   3093 }
   3094 
   3095 /* Append EISD to the list of extra eisd for ABFD.  */
   3096 
   3097 static void
   3098 alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd)
   3099 {
   3100   eisd->next = NULL;
   3101   if (PRIV (gbl_eisd_head) == NULL)
   3102     PRIV (gbl_eisd_head) = eisd;
   3103   else
   3104     PRIV (gbl_eisd_tail)->next = eisd;
   3105   PRIV (gbl_eisd_tail) = eisd;
   3106 }
   3107 
   3108 /* Create an EISD for shared image SHRIMG.
   3109    Return FALSE in case of error.  */
   3110 
   3111 static bool
   3112 alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
   3113 {
   3114   struct vms_internal_eisd_map *eisd;
   3115   int namlen;
   3116 
   3117   namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name));
   3118   if (namlen + 5 > EISD__K_GBLNAMLEN)
   3119     {
   3120       /* Won't fit.  */
   3121       return false;
   3122     }
   3123 
   3124   eisd = bfd_alloc (abfd, sizeof (*eisd));
   3125   if (eisd == NULL)
   3126     return false;
   3127 
   3128   /* Fill the fields.  */
   3129   eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID;
   3130   eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID;
   3131   eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3;
   3132   eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE;	/* Must not be 0.  */
   3133   eisd->u.gbl_eisd.common.virt_addr = 0;
   3134   eisd->u.gbl_eisd.common.flags = EISD__M_GBL;
   3135   eisd->u.gbl_eisd.common.vbn = 0;
   3136   eisd->u.gbl_eisd.common.pfc = 0;
   3137   eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl);
   3138   eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC;
   3139 
   3140   eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident);
   3141   eisd->u.gbl_eisd.gblnam[0] = namlen + 4;
   3142   memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name),
   3143 	  namlen);
   3144   memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4);
   3145 
   3146   /* Append it to the list.  */
   3147   alpha_vms_append_extra_eisd (abfd, eisd);
   3148 
   3149   return true;
   3150 }
   3151 
   3152 /* Create an EISD for section SEC.
   3153    Return FALSE in case of failure.  */
   3154 
   3155 static bool
   3156 alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
   3157 {
   3158   struct vms_internal_eisd_map *eisd;
   3159 
   3160   /* Only for allocating section.  */
   3161   if (!(sec->flags & SEC_ALLOC))
   3162     return true;
   3163 
   3164   BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
   3165   eisd = bfd_alloc (abfd, sizeof (*eisd));
   3166   if (eisd == NULL)
   3167     return false;
   3168   vms_section_data (sec)->eisd = eisd;
   3169 
   3170   /* Fill the fields.  */
   3171   eisd->u.eisd.majorid = EISD__K_MAJORID;
   3172   eisd->u.eisd.minorid = EISD__K_MINORID;
   3173   eisd->u.eisd.eisdsize = EISD__K_LEN;
   3174   eisd->u.eisd.secsize =
   3175     (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
   3176   eisd->u.eisd.virt_addr = sec->vma;
   3177   eisd->u.eisd.flags = 0;
   3178   eisd->u.eisd.vbn = 0; /* To be later defined.  */
   3179   eisd->u.eisd.pfc = 0; /* Default.  */
   3180   eisd->u.eisd.matchctl = EISD__K_MATALL;
   3181   eisd->u.eisd.type = EISD__K_NORMAL;
   3182 
   3183   if (sec->flags & SEC_CODE)
   3184     eisd->u.eisd.flags |= EISD__M_EXE;
   3185   if (!(sec->flags & SEC_READONLY))
   3186     eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
   3187 
   3188   /* If relocations or fixup will be applied, make this isect writeable.  */
   3189   if (sec->flags & SEC_RELOC)
   3190     eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
   3191 
   3192   if (!(sec->flags & SEC_HAS_CONTENTS))
   3193     {
   3194       eisd->u.eisd.flags |= EISD__M_DZRO;
   3195       eisd->u.eisd.flags &= ~EISD__M_CRF;
   3196     }
   3197   if (sec->flags & SEC_LINKER_CREATED)
   3198     {
   3199       if (strcmp (sec->name, "$FIXUP$") == 0)
   3200 	eisd->u.eisd.flags |= EISD__M_FIXUPVEC;
   3201     }
   3202 
   3203   /* Append it to the list.  */
   3204   eisd->next = NULL;
   3205   if (PRIV (eisd_head) == NULL)
   3206     PRIV (eisd_head) = eisd;
   3207   else
   3208     PRIV (eisd_tail)->next = eisd;
   3209   PRIV (eisd_tail) = eisd;
   3210 
   3211   return true;
   3212 }
   3213 
   3214 /* Layout executable ABFD and write it to the disk.
   3215    Return FALSE in case of failure.  */
   3216 
   3217 static bool
   3218 alpha_vms_write_exec (bfd *abfd)
   3219 {
   3220   struct vms_eihd eihd;
   3221   struct vms_eiha *eiha;
   3222   struct vms_eihi *eihi;
   3223   struct vms_eihs *eihs = NULL;
   3224   asection *sec;
   3225   struct vms_internal_eisd_map *first_eisd;
   3226   struct vms_internal_eisd_map *eisd;
   3227   asection *dst;
   3228   asection *dmt;
   3229   file_ptr gst_filepos = 0;
   3230   unsigned int lnkflags = 0;
   3231 
   3232   /* Build the EIHD.  */
   3233   PRIV (file_pos) = EIHD__C_LENGTH;
   3234 
   3235   memset (&eihd, 0, sizeof (eihd));
   3236   memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2));
   3237 
   3238   bfd_putl32 (EIHD__K_MAJORID, eihd.majorid);
   3239   bfd_putl32 (EIHD__K_MINORID, eihd.minorid);
   3240 
   3241   bfd_putl32 (sizeof (eihd), eihd.size);
   3242   bfd_putl32 (0, eihd.isdoff);
   3243   bfd_putl32 (0, eihd.activoff);
   3244   bfd_putl32 (0, eihd.symdbgoff);
   3245   bfd_putl32 (0, eihd.imgidoff);
   3246   bfd_putl32 (0, eihd.patchoff);
   3247   bfd_putl64 (0, eihd.iafva);
   3248   bfd_putl32 (0, eihd.version_array_off);
   3249 
   3250   bfd_putl32 (EIHD__K_EXE, eihd.imgtype);
   3251   bfd_putl32 (0, eihd.subtype);
   3252 
   3253   bfd_putl32 (0, eihd.imgiocnt);
   3254   bfd_putl32 (-1, eihd.privreqs);
   3255   bfd_putl32 (-1, eihd.privreqs + 4);
   3256 
   3257   bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
   3258 	      eihd.hdrblkcnt);
   3259   bfd_putl32 (0, eihd.ident);
   3260   bfd_putl32 (0, eihd.sysver);
   3261 
   3262   eihd.matchctl = 0;
   3263   bfd_putl32 (0, eihd.symvect_size);
   3264   bfd_putl32 (16, eihd.virt_mem_block_size);
   3265   bfd_putl32 (0, eihd.ext_fixup_off);
   3266   bfd_putl32 (0, eihd.noopt_psect_off);
   3267   bfd_putl16 (-1, eihd.alias);
   3268 
   3269   /* Alloc EIHA.  */
   3270   eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
   3271   bfd_putl32 (PRIV (file_pos), eihd.activoff);
   3272   PRIV (file_pos) += sizeof (struct vms_eiha);
   3273 
   3274   bfd_putl32 (sizeof (struct vms_eiha), eiha->size);
   3275   bfd_putl32 (0, eiha->spare);
   3276   bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1);
   3277   bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2);
   3278   bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3);
   3279   bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4);
   3280   bfd_putl64 (0, eiha->inishr);
   3281 
   3282   /* Alloc EIHI.  */
   3283   eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos));
   3284   bfd_putl32 (PRIV (file_pos), eihd.imgidoff);
   3285   PRIV (file_pos) += sizeof (struct vms_eihi);
   3286 
   3287   bfd_putl32 (EIHI__K_MAJORID, eihi->majorid);
   3288   bfd_putl32 (EIHI__K_MINORID, eihi->minorid);
   3289   {
   3290     char *module;
   3291     unsigned int len;
   3292 
   3293     /* Set module name.  */
   3294     module = vms_get_module_name (bfd_get_filename (abfd), true);
   3295     len = strlen (module);
   3296     if (len > sizeof (eihi->imgnam) - 1)
   3297       len = sizeof (eihi->imgnam) - 1;
   3298     eihi->imgnam[0] = len;
   3299     memcpy (eihi->imgnam + 1, module, len);
   3300     free (module);
   3301   }
   3302   {
   3303     unsigned int lo;
   3304     unsigned int hi;
   3305 
   3306     /* Set time.  */
   3307     vms_get_time (&hi, &lo);
   3308     bfd_putl32 (lo, eihi->linktime + 0);
   3309     bfd_putl32 (hi, eihi->linktime + 4);
   3310   }
   3311   eihi->imgid[0] = 0;
   3312   eihi->linkid[0] = 0;
   3313   eihi->imgbid[0] = 0;
   3314 
   3315   /* Alloc EIHS.  */
   3316   dst = PRIV (dst_section);
   3317   dmt = bfd_get_section_by_name (abfd, "$DMT$");
   3318   if (dst != NULL && dst->size != 0)
   3319     {
   3320       eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos));
   3321       bfd_putl32 (PRIV (file_pos), eihd.symdbgoff);
   3322       PRIV (file_pos) += sizeof (struct vms_eihs);
   3323 
   3324       bfd_putl32 (EIHS__K_MAJORID, eihs->majorid);
   3325       bfd_putl32 (EIHS__K_MINORID, eihs->minorid);
   3326       bfd_putl32 (0, eihs->dstvbn);
   3327       bfd_putl32 (0, eihs->dstsize);
   3328       bfd_putl32 (0, eihs->gstvbn);
   3329       bfd_putl32 (0, eihs->gstsize);
   3330       bfd_putl32 (0, eihs->dmtvbn);
   3331       bfd_putl32 (0, eihs->dmtsize);
   3332     }
   3333 
   3334   /* One EISD per section.  */
   3335   for (sec = abfd->sections; sec; sec = sec->next)
   3336     {
   3337       if (!alpha_vms_create_eisd_for_section (abfd, sec))
   3338 	return false;
   3339     }
   3340 
   3341   /* Merge section EIDS which extra ones.  */
   3342   if (PRIV (eisd_tail))
   3343     PRIV (eisd_tail)->next = PRIV (gbl_eisd_head);
   3344   else
   3345     PRIV (eisd_head) = PRIV (gbl_eisd_head);
   3346   if (PRIV (gbl_eisd_tail))
   3347     PRIV (eisd_tail) = PRIV (gbl_eisd_tail);
   3348 
   3349   first_eisd = PRIV (eisd_head);
   3350 
   3351   /* Add end of eisd.  */
   3352   if (first_eisd)
   3353     {
   3354       eisd = bfd_zalloc (abfd, sizeof (*eisd));
   3355       if (eisd == NULL)
   3356 	return false;
   3357       eisd->u.eisd.majorid = 0;
   3358       eisd->u.eisd.minorid = 0;
   3359       eisd->u.eisd.eisdsize = 0;
   3360       alpha_vms_append_extra_eisd (abfd, eisd);
   3361     }
   3362 
   3363   /* Place EISD in the file.  */
   3364   for (eisd = first_eisd; eisd; eisd = eisd->next)
   3365     {
   3366       file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE);
   3367 
   3368       /* First block is a little bit special: there is a word at the end.  */
   3369       if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2)
   3370 	room -= 2;
   3371       if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND)
   3372 	alpha_vms_file_position_block (abfd);
   3373 
   3374       eisd->file_pos = PRIV (file_pos);
   3375       PRIV (file_pos) += eisd->u.eisd.eisdsize;
   3376 
   3377       if (eisd->u.eisd.flags & EISD__M_FIXUPVEC)
   3378 	bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva);
   3379     }
   3380 
   3381   if (first_eisd != NULL)
   3382     {
   3383       bfd_putl32 (first_eisd->file_pos, eihd.isdoff);
   3384       /* Real size of end of eisd marker.  */
   3385       PRIV (file_pos) += EISD__K_LENEND;
   3386     }
   3387 
   3388   bfd_putl32 (PRIV (file_pos), eihd.size);
   3389   bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
   3390 	      eihd.hdrblkcnt);
   3391 
   3392   /* Place sections.  */
   3393   for (sec = abfd->sections; sec; sec = sec->next)
   3394     {
   3395       if (!(sec->flags & SEC_HAS_CONTENTS)
   3396 	  || sec->contents == NULL)
   3397 	continue;
   3398 
   3399       eisd = vms_section_data (sec)->eisd;
   3400 
   3401       /* Align on a block.  */
   3402       alpha_vms_file_position_block (abfd);
   3403       sec->filepos = PRIV (file_pos);
   3404 
   3405       if (eisd != NULL)
   3406 	eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1;
   3407 
   3408       PRIV (file_pos) += sec->size;
   3409     }
   3410 
   3411   /* Update EIHS.  */
   3412   if (eihs != NULL && dst != NULL)
   3413     {
   3414       bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn);
   3415       bfd_putl32 (dst->size, eihs->dstsize);
   3416 
   3417       if (dmt != NULL)
   3418 	{
   3419 	  lnkflags |= EIHD__M_DBGDMT;
   3420 	  bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn);
   3421 	  bfd_putl32 (dmt->size, eihs->dmtsize);
   3422 	}
   3423       if (PRIV (gsd_sym_count) != 0)
   3424 	{
   3425 	  alpha_vms_file_position_block (abfd);
   3426 	  gst_filepos = PRIV (file_pos);
   3427 	  bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn);
   3428 	  bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize);
   3429 	}
   3430     }
   3431 
   3432   /* Write EISD in hdr.  */
   3433   for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE;
   3434        eisd = eisd->next)
   3435     alpha_vms_swap_eisd_out
   3436       (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos));
   3437 
   3438   /* Write first block.  */
   3439   bfd_putl32 (lnkflags, eihd.lnkflags);
   3440   if (bfd_write (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
   3441     return false;
   3442 
   3443   /* Write remaining eisd.  */
   3444   if (eisd != NULL)
   3445     {
   3446       unsigned char blk[VMS_BLOCK_SIZE];
   3447       struct vms_internal_eisd_map *next_eisd;
   3448 
   3449       memset (blk, 0xff, sizeof (blk));
   3450       while (eisd != NULL)
   3451 	{
   3452 	  alpha_vms_swap_eisd_out
   3453 	    (eisd,
   3454 	     (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE)));
   3455 
   3456 	  next_eisd = eisd->next;
   3457 	  if (next_eisd == NULL
   3458 	      || (next_eisd->file_pos / VMS_BLOCK_SIZE
   3459 		  != eisd->file_pos / VMS_BLOCK_SIZE))
   3460 	    {
   3461 	      if (bfd_write (blk, sizeof (blk), abfd) != sizeof (blk))
   3462 		return false;
   3463 
   3464 	      memset (blk, 0xff, sizeof (blk));
   3465 	    }
   3466 	  eisd = next_eisd;
   3467 	}
   3468     }
   3469 
   3470   /* Write sections.  */
   3471   for (sec = abfd->sections; sec; sec = sec->next)
   3472     {
   3473       unsigned char blk[VMS_BLOCK_SIZE];
   3474       bfd_size_type len;
   3475 
   3476       if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS)
   3477 	  || sec->contents == NULL)
   3478 	continue;
   3479       if (bfd_write (sec->contents, sec->size, abfd) != sec->size)
   3480 	return false;
   3481 
   3482       /* Pad.  */
   3483       len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE;
   3484       if (len != VMS_BLOCK_SIZE)
   3485 	{
   3486 	  memset (blk, 0, len);
   3487 	  if (bfd_write (blk, len, abfd) != len)
   3488 	    return false;
   3489 	}
   3490     }
   3491 
   3492   /* Write GST.  */
   3493   if (gst_filepos != 0)
   3494     {
   3495       struct vms_rec_wr *recwr = &PRIV (recwr);
   3496       unsigned int i;
   3497 
   3498       if (!_bfd_vms_write_emh (abfd)
   3499 	  || !_bfd_vms_write_lmn (abfd, "GNU LD"))
   3500 	return false;
   3501 
   3502       /* PSC for the absolute section.  */
   3503       _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
   3504       _bfd_vms_output_long (recwr, 0);
   3505       _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
   3506       _bfd_vms_output_short (recwr, 0);
   3507       _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD);
   3508       _bfd_vms_output_long (recwr, 0);
   3509       _bfd_vms_output_counted (recwr, ".$$ABS$$.");
   3510       _bfd_vms_output_end_subrec (recwr);
   3511       if (!_bfd_vms_output_end (abfd, recwr))
   3512 	return false;
   3513 
   3514       for (i = 0; i < PRIV (gsd_sym_count); i++)
   3515 	{
   3516 	  struct vms_symbol_entry *sym = PRIV (syms)[i];
   3517 	  bfd_vma val;
   3518 	  bfd_vma ep;
   3519 
   3520 	  if ((i % 5) == 0)
   3521 	    {
   3522 	      _bfd_vms_output_alignment (recwr, 8);
   3523 	      _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
   3524 	      _bfd_vms_output_long (recwr, 0);
   3525 	    }
   3526 	  _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG);
   3527 	  _bfd_vms_output_short (recwr, 0); /* Data type, alignment.  */
   3528 	  _bfd_vms_output_short (recwr, sym->flags);
   3529 
   3530 	  if (sym->code_section)
   3531 	    ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value);
   3532 	  else
   3533 	    {
   3534 	      BFD_ASSERT (sym->code_value == 0);
   3535 	      ep = 0;
   3536 	    }
   3537 	  val = alpha_vms_get_sym_value (sym->section, sym->value);
   3538 	  _bfd_vms_output_quad
   3539 	    (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val);
   3540 	  _bfd_vms_output_quad (recwr, ep);
   3541 	  _bfd_vms_output_quad (recwr, val);
   3542 	  _bfd_vms_output_long (recwr, 0);
   3543 	  _bfd_vms_output_counted (recwr, sym->name);
   3544 	  _bfd_vms_output_end_subrec (recwr);
   3545 	  if ((i % 5) == 4
   3546 	      && !_bfd_vms_output_end (abfd, recwr))
   3547 	    return false;
   3548 	}
   3549       if ((i % 5) != 0
   3550 	  && !_bfd_vms_output_end (abfd, recwr))
   3551 	return false;
   3552 
   3553       if (!_bfd_vms_write_eeom (abfd))
   3554 	return false;
   3555     }
   3556   return true;
   3557 }
   3558 
   3559 /* Object write.  */
   3561 
   3562 /* Write section and symbol directory of bfd abfd.  Return FALSE on error.  */
   3563 
   3564 static bool
   3565 _bfd_vms_write_egsd (bfd *abfd)
   3566 {
   3567   asection *section;
   3568   asymbol *symbol;
   3569   unsigned int symnum;
   3570   const char *sname;
   3571   flagword new_flags, old_flags;
   3572   int abs_section_index = -1;
   3573   unsigned int target_index = 0;
   3574   struct vms_rec_wr *recwr = &PRIV (recwr);
   3575 
   3576   vms_debug2 ((2, "vms_write_egsd\n"));
   3577 
   3578   /* Egsd is quadword aligned.  */
   3579   _bfd_vms_output_alignment (recwr, 8);
   3580 
   3581   _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
   3582   _bfd_vms_output_long (recwr, 0);
   3583 
   3584   /* Number sections.  */
   3585   for (section = abfd->sections; section != NULL; section = section->next)
   3586     {
   3587       if (section->flags & SEC_DEBUGGING)
   3588 	continue;
   3589       if (!strcmp (section->name, ".vmsdebug"))
   3590 	{
   3591 	  section->flags |= SEC_DEBUGGING;
   3592 	  continue;
   3593 	}
   3594       section->target_index = target_index++;
   3595     }
   3596 
   3597   for (section = abfd->sections; section != NULL; section = section->next)
   3598     {
   3599       vms_debug2 ((3, "Section #%d %s, %d bytes\n",
   3600 		   section->target_index, section->name, (int)section->size));
   3601 
   3602       /* Don't write out the VMS debug info section since it is in the
   3603 	 ETBT and EDBG sections in etir. */
   3604       if (section->flags & SEC_DEBUGGING)
   3605 	continue;
   3606 
   3607       /* 13 bytes egsd, max 31 chars name -> should be 44 bytes.  */
   3608       if (_bfd_vms_output_check (recwr, 64) < 0)
   3609 	{
   3610 	  if (!_bfd_vms_output_end (abfd, recwr))
   3611 	    return false;
   3612 	  _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
   3613 	  _bfd_vms_output_long (recwr, 0);
   3614 	}
   3615 
   3616       /* Don't know if this is necessary for the linker but for now it keeps
   3617 	 vms_slurp_gsd happy.  */
   3618       sname = section->name;
   3619       if (*sname == '.')
   3620 	{
   3621 	  /* Remove leading dot.  */
   3622 	  sname++;
   3623 	  if ((*sname == 't') && (strcmp (sname, "text") == 0))
   3624 	    sname = EVAX_CODE_NAME;
   3625 	  else if ((*sname == 'd') && (strcmp (sname, "data") == 0))
   3626 	    sname = EVAX_DATA_NAME;
   3627 	  else if ((*sname == 'b') && (strcmp (sname, "bss") == 0))
   3628 	    sname = EVAX_BSS_NAME;
   3629 	  else if ((*sname == 'l') && (strcmp (sname, "link") == 0))
   3630 	    sname = EVAX_LINK_NAME;
   3631 	  else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0))
   3632 	    sname = EVAX_READONLY_NAME;
   3633 	  else if ((*sname == 'l') && (strcmp (sname, "literal") == 0))
   3634 	    sname = EVAX_LITERAL_NAME;
   3635 	  else if ((*sname == 'l') && (strcmp (sname, "literals") == 0))
   3636 	    sname = EVAX_LITERALS_NAME;
   3637 	  else if ((*sname == 'c') && (strcmp (sname, "comm") == 0))
   3638 	    sname = EVAX_COMMON_NAME;
   3639 	  else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
   3640 	    sname = EVAX_LOCAL_NAME;
   3641 	}
   3642 
   3643       if (bfd_is_com_section (section))
   3644 	new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD
   3645 		     | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM);
   3646       else
   3647 	new_flags = vms_esecflag_by_name (evax_section_flags, sname,
   3648 					  section->size > 0);
   3649 
   3650       /* Modify them as directed.  */
   3651       if (section->flags & SEC_READONLY)
   3652 	new_flags &= ~EGPS__V_WRT;
   3653 
   3654       new_flags &= ~vms_section_data (section)->no_flags;
   3655       new_flags |= vms_section_data (section)->flags;
   3656 
   3657       vms_debug2 ((3, "sec flags %x\n", section->flags));
   3658       vms_debug2 ((3, "new_flags %x, _raw_size %lu\n",
   3659 		   new_flags, (unsigned long)section->size));
   3660 
   3661       _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
   3662       _bfd_vms_output_short (recwr, section->alignment_power & 0xff);
   3663       _bfd_vms_output_short (recwr, new_flags);
   3664       _bfd_vms_output_long (recwr, (unsigned long) section->size);
   3665       _bfd_vms_output_counted (recwr, sname);
   3666       _bfd_vms_output_end_subrec (recwr);
   3667 
   3668       /* If the section is an obsolute one, remind its index as it will be
   3669 	 used later for absolute symbols.  */
   3670       if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0)
   3671 	abs_section_index = section->target_index;
   3672     }
   3673 
   3674   /* Output symbols.  */
   3675   vms_debug2 ((3, "%d symbols found\n", abfd->symcount));
   3676 
   3677   bfd_set_start_address (abfd, (bfd_vma) -1);
   3678 
   3679   for (symnum = 0; symnum < abfd->symcount; symnum++)
   3680     {
   3681       symbol = abfd->outsymbols[symnum];
   3682       old_flags = symbol->flags;
   3683 
   3684       /* Work-around a missing feature:  consider __main as the main entry
   3685 	 point.  */
   3686       if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0)
   3687 	bfd_set_start_address (abfd, (bfd_vma)symbol->value);
   3688 
   3689       /* Only put in the GSD the global and the undefined symbols.  */
   3690       if (old_flags & BSF_FILE)
   3691 	continue;
   3692 
   3693       if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section))
   3694 	{
   3695 	  /* If the LIB$INITIIALIZE section is present, add a reference to
   3696 	     LIB$INITIALIZE symbol.  FIXME: this should be done explicitely
   3697 	     in the assembly file.  */
   3698 	  if (!((old_flags & BSF_SECTION_SYM) != 0
   3699 		&& strcmp (symbol->section->name, "LIB$INITIALIZE") == 0))
   3700 	    continue;
   3701 	}
   3702 
   3703       /* 13 bytes egsd, max 64 chars name -> should be 77 bytes.  Add 16 more
   3704 	 bytes for a possible ABS section.  */
   3705       if (_bfd_vms_output_check (recwr, 80 + 16) < 0)
   3706 	{
   3707 	  if (!_bfd_vms_output_end (abfd, recwr))
   3708 	    return false;
   3709 	  _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
   3710 	  _bfd_vms_output_long (recwr, 0);
   3711 	}
   3712 
   3713       if ((old_flags & BSF_GLOBAL) != 0
   3714 	  && bfd_is_abs_section (symbol->section)
   3715 	  && abs_section_index <= 0)
   3716 	{
   3717 	  /* Create an absolute section if none was defined.  It is highly
   3718 	     unlikely that the name $ABS$ clashes with a user defined
   3719 	     non-absolute section name.  */
   3720 	  _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
   3721 	  _bfd_vms_output_short (recwr, 4);
   3722 	  _bfd_vms_output_short (recwr, EGPS__V_SHR);
   3723 	  _bfd_vms_output_long (recwr, 0);
   3724 	  _bfd_vms_output_counted (recwr, "$ABS$");
   3725 	  _bfd_vms_output_end_subrec (recwr);
   3726 
   3727 	  abs_section_index = target_index++;
   3728 	}
   3729 
   3730       _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM);
   3731 
   3732       /* Data type, alignment.  */
   3733       _bfd_vms_output_short (recwr, 0);
   3734 
   3735       new_flags = 0;
   3736 
   3737       if (old_flags & BSF_WEAK)
   3738 	new_flags |= EGSY__V_WEAK;
   3739       if (bfd_is_com_section (symbol->section))		/* .comm  */
   3740 	new_flags |= (EGSY__V_WEAK | EGSY__V_COMM);
   3741 
   3742       if (old_flags & BSF_FUNCTION)
   3743 	{
   3744 	  new_flags |= EGSY__V_NORM;
   3745 	  new_flags |= EGSY__V_REL;
   3746 	}
   3747       if (old_flags & BSF_GLOBAL)
   3748 	{
   3749 	  new_flags |= EGSY__V_DEF;
   3750 	  if (!bfd_is_abs_section (symbol->section))
   3751 	    new_flags |= EGSY__V_REL;
   3752 	}
   3753       _bfd_vms_output_short (recwr, new_flags);
   3754 
   3755       if (old_flags & BSF_GLOBAL)
   3756 	{
   3757 	  /* Symbol definition.  */
   3758 	  bfd_vma code_address = 0;
   3759 	  unsigned long ca_psindx = 0;
   3760 	  unsigned long psindx;
   3761 
   3762 	  if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL)
   3763 	    {
   3764 	      asymbol *sym;
   3765 
   3766 	      sym =
   3767 		((struct evax_private_udata_struct *)symbol->udata.p)->enbsym;
   3768 	      code_address = sym->value;
   3769 	      ca_psindx = sym->section->target_index;
   3770 	    }
   3771 	  if (bfd_is_abs_section (symbol->section))
   3772 	    psindx = abs_section_index;
   3773 	  else
   3774 	    psindx = symbol->section->target_index;
   3775 
   3776 	  _bfd_vms_output_quad (recwr, symbol->value);
   3777 	  _bfd_vms_output_quad (recwr, code_address);
   3778 	  _bfd_vms_output_long (recwr, ca_psindx);
   3779 	  _bfd_vms_output_long (recwr, psindx);
   3780 	}
   3781       _bfd_vms_output_counted (recwr, symbol->name);
   3782 
   3783       _bfd_vms_output_end_subrec (recwr);
   3784     }
   3785 
   3786   _bfd_vms_output_alignment (recwr, 8);
   3787   return _bfd_vms_output_end (abfd, recwr);
   3788 }
   3789 
   3790 /* Write object header for bfd abfd.  Return FALSE on error.  */
   3791 
   3792 static bool
   3793 _bfd_vms_write_ehdr (bfd *abfd)
   3794 {
   3795   asymbol *symbol;
   3796   unsigned int symnum;
   3797   struct vms_rec_wr *recwr = &PRIV (recwr);
   3798 
   3799   vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
   3800 
   3801   _bfd_vms_output_alignment (recwr, 2);
   3802 
   3803   if (!_bfd_vms_write_emh (abfd)
   3804       || !_bfd_vms_write_lmn (abfd, "GNU AS"))
   3805     return false;
   3806 
   3807   /* SRC.  */
   3808   _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
   3809   _bfd_vms_output_short (recwr, EMH__C_SRC);
   3810 
   3811   for (symnum = 0; symnum < abfd->symcount; symnum++)
   3812     {
   3813       symbol = abfd->outsymbols[symnum];
   3814 
   3815       if (symbol->flags & BSF_FILE)
   3816 	{
   3817 	  _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name,
   3818 				(int) strlen (symbol->name));
   3819 	  break;
   3820 	}
   3821     }
   3822 
   3823   if (symnum == abfd->symcount)
   3824     _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
   3825 
   3826   if (!_bfd_vms_output_end (abfd, recwr))
   3827     return false;
   3828 
   3829   /* TTL.  */
   3830   _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
   3831   _bfd_vms_output_short (recwr, EMH__C_TTL);
   3832   _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
   3833   if (!_bfd_vms_output_end (abfd, recwr))
   3834     return false;
   3835 
   3836   /* CPR.  */
   3837   _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
   3838   _bfd_vms_output_short (recwr, EMH__C_CPR);
   3839   _bfd_vms_output_dump (recwr,
   3840 			(unsigned char *)"GNU BFD ported by Klaus Kmpf 1994-1996",
   3841 			 39);
   3842   return _bfd_vms_output_end (abfd, recwr);
   3843 }
   3844 
   3845 /* Part 4.6, relocations.  */
   3846 
   3847 
   3848 /* WRITE ETIR SECTION
   3850 
   3851    This is still under construction and therefore not documented.  */
   3852 
   3853 /* Close the etir/etbt record.  */
   3854 
   3855 static bool
   3856 end_etir_record (bfd * abfd)
   3857 {
   3858   struct vms_rec_wr *recwr = &PRIV (recwr);
   3859 
   3860   return _bfd_vms_output_end (abfd, recwr);
   3861 }
   3862 
   3863 static void
   3864 start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset)
   3865 {
   3866   struct vms_rec_wr *recwr = &PRIV (recwr);
   3867 
   3868   if (section->flags & SEC_DEBUGGING)
   3869     {
   3870       _bfd_vms_output_begin (recwr, EOBJ__C_ETBT);
   3871 
   3872       if (offset == 0)
   3873 	{
   3874 	  /* Push start offset.  */
   3875 	  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
   3876 	  _bfd_vms_output_long (recwr, (unsigned long) 0);
   3877 	  _bfd_vms_output_end_subrec (recwr);
   3878 
   3879 	  /* Set location.  */
   3880 	  _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC);
   3881 	  _bfd_vms_output_end_subrec (recwr);
   3882 	}
   3883     }
   3884   else
   3885     {
   3886       _bfd_vms_output_begin (recwr, EOBJ__C_ETIR);
   3887 
   3888       if (offset == 0)
   3889 	{
   3890 	  /* Push start offset.  */
   3891 	  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
   3892 	  _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
   3893 	  _bfd_vms_output_quad (recwr, offset);
   3894 	  _bfd_vms_output_end_subrec (recwr);
   3895 
   3896 	  /* Start = pop ().  */
   3897 	  _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB);
   3898 	  _bfd_vms_output_end_subrec (recwr);
   3899 	}
   3900     }
   3901 }
   3902 
   3903 /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual
   3904    address VADDR in section specified by SEC_INDEX and NAME.  */
   3905 
   3906 static bool
   3907 sto_imm (bfd *abfd, asection *section,
   3908 	 bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr)
   3909 {
   3910   bfd_size_type size;
   3911   struct vms_rec_wr *recwr = &PRIV (recwr);
   3912 
   3913 #if VMS_DEBUG
   3914   _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize);
   3915   _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr);
   3916 #endif
   3917 
   3918   while (ssize > 0)
   3919     {
   3920       /* Try all the rest.  */
   3921       size = ssize;
   3922 
   3923       if (_bfd_vms_output_check (recwr, size) < 0)
   3924 	{
   3925 	  /* Doesn't fit, split !  */
   3926 	  if (!end_etir_record (abfd))
   3927 	    return false;
   3928 
   3929 	  start_etir_or_etbt_record (abfd, section, vaddr);
   3930 
   3931 	  size = _bfd_vms_output_check (recwr, 0);	/* get max size */
   3932 	  if (size > ssize)			/* more than what's left ? */
   3933 	    size = ssize;
   3934 	}
   3935 
   3936       _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM);
   3937       _bfd_vms_output_long (recwr, (unsigned long) (size));
   3938       _bfd_vms_output_dump (recwr, cptr, size);
   3939       _bfd_vms_output_end_subrec (recwr);
   3940 
   3941 #if VMS_DEBUG
   3942       _bfd_vms_debug (10, "dumped %d bytes\n", (int) size);
   3943       _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
   3944 #endif
   3945 
   3946       vaddr += size;
   3947       cptr += size;
   3948       ssize -= size;
   3949     }
   3950   return true;
   3951 }
   3952 
   3953 static bool
   3954 etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
   3955 {
   3956   if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0)
   3957     {
   3958       /* Not enough room in this record.  Close it and open a new one.  */
   3959       if (!end_etir_record (abfd))
   3960 	return false;
   3961       start_etir_or_etbt_record (abfd, section, vaddr);
   3962     }
   3963   return true;
   3964 }
   3965 
   3966 /* Return whether RELOC must be deferred till the end.  */
   3967 
   3968 static bool
   3969 defer_reloc_p (arelent *reloc)
   3970 {
   3971   switch (reloc->howto->type)
   3972     {
   3973     case ALPHA_R_NOP:
   3974     case ALPHA_R_LDA:
   3975     case ALPHA_R_BSR:
   3976     case ALPHA_R_BOH:
   3977       return true;
   3978 
   3979     default:
   3980       return false;
   3981     }
   3982 }
   3983 
   3984 /* Write section contents for bfd abfd.  Return FALSE on error.  */
   3985 
   3986 static bool
   3987 _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
   3988 {
   3989   asection *section;
   3990   struct vms_rec_wr *recwr = &PRIV (recwr);
   3991 
   3992   vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype));
   3993 
   3994   _bfd_vms_output_alignment (recwr, 4);
   3995 
   3996   PRIV (vms_linkage_index) = 0;
   3997 
   3998   for (section = abfd->sections; section; section = section->next)
   3999     {
   4000       vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n",
   4001 		   section->target_index, section->name, (int) (section->size)));
   4002 
   4003       if (!(section->flags & SEC_HAS_CONTENTS)
   4004 	  || bfd_is_com_section (section))
   4005 	continue;
   4006 
   4007       if (!section->contents)
   4008 	{
   4009 	  bfd_set_error (bfd_error_no_contents);
   4010 	  return false;
   4011 	}
   4012 
   4013       start_etir_or_etbt_record (abfd, section, 0);
   4014 
   4015       if (section->flags & SEC_RELOC)
   4016 	{
   4017 	  bfd_vma curr_addr = 0;
   4018 	  unsigned char *curr_data = section->contents;
   4019 	  bfd_size_type size;
   4020 	  int pass2_needed = 0;
   4021 	  int pass2_in_progress = 0;
   4022 	  unsigned int irel;
   4023 
   4024 	  if (section->reloc_count == 0)
   4025 	    _bfd_error_handler
   4026 	      (_("SEC_RELOC with no relocs in section %pA"), section);
   4027 
   4028 #if VMS_DEBUG
   4029 	  else
   4030 	    {
   4031 	      int i = section->reloc_count;
   4032 	      arelent **rptr = section->orelocation;
   4033 	      _bfd_vms_debug (4, "%d relocations:\n", i);
   4034 	      while (i-- > 0)
   4035 		{
   4036 		  _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, "
   4037 				     "addr %08lx, off %08lx, len %d: %s\n",
   4038 				  (*(*rptr)->sym_ptr_ptr)->name,
   4039 				  (*(*rptr)->sym_ptr_ptr)->section->name,
   4040 				  (long) (*(*rptr)->sym_ptr_ptr)->value,
   4041 				  (unsigned long)(*rptr)->address,
   4042 				  (unsigned long)(*rptr)->addend,
   4043 				  bfd_get_reloc_size ((*rptr)->howto),
   4044 				  ( *rptr)->howto->name);
   4045 		  rptr++;
   4046 		}
   4047 	    }
   4048 #endif
   4049 
   4050 	new_pass:
   4051 	  for (irel = 0; irel < section->reloc_count; irel++)
   4052 	    {
   4053 	      struct evax_private_udata_struct *udata;
   4054 	      arelent *rptr = section->orelocation [irel];
   4055 	      bfd_vma addr = rptr->address;
   4056 	      asymbol *sym = *rptr->sym_ptr_ptr;
   4057 	      asection *sec = sym->section;
   4058 	      bool defer = defer_reloc_p (rptr);
   4059 	      unsigned int slen;
   4060 
   4061 	      if (pass2_in_progress)
   4062 		{
   4063 		  /* Non-deferred relocs have already been output.  */
   4064 		  if (!defer)
   4065 		    continue;
   4066 		}
   4067 	      else
   4068 		{
   4069 		  /* Deferred relocs must be output at the very end.  */
   4070 		  if (defer)
   4071 		    {
   4072 		      pass2_needed = 1;
   4073 		      continue;
   4074 		    }
   4075 
   4076 		  /* Regular relocs are intertwined with binary data.  */
   4077 		  if (curr_addr > addr)
   4078 		    _bfd_error_handler (_("size error in section %pA"),
   4079 					section);
   4080 		  size = addr - curr_addr;
   4081 		  if (!sto_imm (abfd, section, size, curr_data, curr_addr))
   4082 		    return false;
   4083 		  curr_data += size;
   4084 		  curr_addr += size;
   4085 		}
   4086 
   4087 	      size = bfd_get_reloc_size (rptr->howto);
   4088 
   4089 	      switch (rptr->howto->type)
   4090 		{
   4091 		case ALPHA_R_IGNORE:
   4092 		  break;
   4093 
   4094 		case ALPHA_R_REFLONG:
   4095 		  if (bfd_is_und_section (sym->section))
   4096 		    {
   4097 		      bfd_vma addend = rptr->addend;
   4098 		      slen = strlen ((char *) sym->name);
   4099 		      if (!etir_output_check (abfd, section, curr_addr, slen))
   4100 			return false;
   4101 		      if (addend)
   4102 			{
   4103 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
   4104 			  _bfd_vms_output_counted (recwr, sym->name);
   4105 			  _bfd_vms_output_end_subrec (recwr);
   4106 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
   4107 			  _bfd_vms_output_long (recwr, (unsigned long) addend);
   4108 			  _bfd_vms_output_end_subrec (recwr);
   4109 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
   4110 			  _bfd_vms_output_end_subrec (recwr);
   4111 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
   4112 			  _bfd_vms_output_end_subrec (recwr);
   4113 			}
   4114 		      else
   4115 			{
   4116 			  _bfd_vms_output_begin_subrec
   4117 			    (recwr, ETIR__C_STO_GBL_LW);
   4118 			  _bfd_vms_output_counted (recwr, sym->name);
   4119 			  _bfd_vms_output_end_subrec (recwr);
   4120 			}
   4121 		    }
   4122 		  else if (bfd_is_abs_section (sym->section))
   4123 		    {
   4124 		      if (!etir_output_check (abfd, section, curr_addr, 16))
   4125 			return false;
   4126 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
   4127 		      _bfd_vms_output_long (recwr, (unsigned long) sym->value);
   4128 		      _bfd_vms_output_end_subrec (recwr);
   4129 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
   4130 		      _bfd_vms_output_end_subrec (recwr);
   4131 		    }
   4132 		  else
   4133 		    {
   4134 		      if (!etir_output_check (abfd, section, curr_addr, 32))
   4135 			return false;
   4136 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
   4137 		      _bfd_vms_output_long (recwr,
   4138 					    (unsigned long) sec->target_index);
   4139 		      _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
   4140 		      _bfd_vms_output_end_subrec (recwr);
   4141 		      /* ??? Table B-8 of the OpenVMS Linker Utilily Manual
   4142 			 says that we should have a ETIR__C_STO_OFF here.
   4143 			 But the relocation would not be BFD_RELOC_32 then.
   4144 			 This case is very likely unreachable.  */
   4145 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
   4146 		      _bfd_vms_output_end_subrec (recwr);
   4147 		    }
   4148 		  break;
   4149 
   4150 		case ALPHA_R_REFQUAD:
   4151 		  if (bfd_is_und_section (sym->section))
   4152 		    {
   4153 		      bfd_vma addend = rptr->addend;
   4154 		      slen = strlen ((char *) sym->name);
   4155 		      if (!etir_output_check (abfd, section, curr_addr, slen))
   4156 			return false;
   4157 		      if (addend)
   4158 			{
   4159 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
   4160 			  _bfd_vms_output_counted (recwr, sym->name);
   4161 			  _bfd_vms_output_end_subrec (recwr);
   4162 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
   4163 			  _bfd_vms_output_quad (recwr, addend);
   4164 			  _bfd_vms_output_end_subrec (recwr);
   4165 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
   4166 			  _bfd_vms_output_end_subrec (recwr);
   4167 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
   4168 			  _bfd_vms_output_end_subrec (recwr);
   4169 			}
   4170 		      else
   4171 			{
   4172 			  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL);
   4173 			  _bfd_vms_output_counted (recwr, sym->name);
   4174 			  _bfd_vms_output_end_subrec (recwr);
   4175 			}
   4176 		    }
   4177 		  else if (bfd_is_abs_section (sym->section))
   4178 		    {
   4179 		      if (!etir_output_check (abfd, section, curr_addr, 16))
   4180 			return false;
   4181 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
   4182 		      _bfd_vms_output_quad (recwr, sym->value);
   4183 		      _bfd_vms_output_end_subrec (recwr);
   4184 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
   4185 		      _bfd_vms_output_end_subrec (recwr);
   4186 		    }
   4187 		  else
   4188 		    {
   4189 		      if (!etir_output_check (abfd, section, curr_addr, 32))
   4190 			return false;
   4191 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
   4192 		      _bfd_vms_output_long (recwr,
   4193 					    (unsigned long) sec->target_index);
   4194 		      _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
   4195 		      _bfd_vms_output_end_subrec (recwr);
   4196 		      _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF);
   4197 		      _bfd_vms_output_end_subrec (recwr);
   4198 		    }
   4199 		  break;
   4200 
   4201 		case ALPHA_R_HINT:
   4202 		  if (!sto_imm (abfd, section, size, curr_data, curr_addr))
   4203 		    return false;
   4204 		  break;
   4205 
   4206 		case ALPHA_R_LINKAGE:
   4207 		  size = 16;
   4208 		  if (!etir_output_check (abfd, section, curr_addr, 64))
   4209 		    return false;
   4210 		  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
   4211 		  _bfd_vms_output_long
   4212 		    (recwr, (unsigned long) rptr->addend);
   4213 		  if (rptr->addend > PRIV (vms_linkage_index))
   4214 		    PRIV (vms_linkage_index) = rptr->addend;
   4215 		  _bfd_vms_output_counted (recwr, sym->name);
   4216 		  _bfd_vms_output_byte (recwr, 0);
   4217 		  _bfd_vms_output_end_subrec (recwr);
   4218 		  break;
   4219 
   4220 		case ALPHA_R_CODEADDR:
   4221 		  slen = strlen ((char *) sym->name);
   4222 		  if (!etir_output_check (abfd, section, curr_addr, slen))
   4223 		    return false;
   4224 		  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
   4225 		  _bfd_vms_output_counted (recwr, sym->name);
   4226 		  _bfd_vms_output_end_subrec (recwr);
   4227 		  break;
   4228 
   4229 		case ALPHA_R_NOP:
   4230 		  udata
   4231 		    = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
   4232 		  if (!etir_output_check (abfd, section, curr_addr,
   4233 					  32 + 1 + strlen (udata->origname)))
   4234 		    return false;
   4235 		  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
   4236 		  _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
   4237 		  _bfd_vms_output_long
   4238 		    (recwr, (unsigned long) section->target_index);
   4239 		  _bfd_vms_output_quad (recwr, rptr->address);
   4240 		  _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f);
   4241 		  _bfd_vms_output_long
   4242 		    (recwr, (unsigned long) section->target_index);
   4243 		  _bfd_vms_output_quad (recwr, rptr->addend);
   4244 		  _bfd_vms_output_counted (recwr, udata->origname);
   4245 		  _bfd_vms_output_end_subrec (recwr);
   4246 		  break;
   4247 
   4248 		case ALPHA_R_BSR:
   4249 		  _bfd_error_handler (_("spurious ALPHA_R_BSR reloc"));
   4250 		  break;
   4251 
   4252 		case ALPHA_R_LDA:
   4253 		  udata
   4254 		    = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
   4255 		  if (!etir_output_check (abfd, section, curr_addr,
   4256 					  32 + 1 + strlen (udata->origname)))
   4257 		    return false;
   4258 		  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL);
   4259 		  _bfd_vms_output_long
   4260 		    (recwr, (unsigned long) udata->lkindex + 1);
   4261 		  _bfd_vms_output_long
   4262 		    (recwr, (unsigned long) section->target_index);
   4263 		  _bfd_vms_output_quad (recwr, rptr->address);
   4264 		  _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000);
   4265 		  _bfd_vms_output_long
   4266 		    (recwr, (unsigned long) udata->bsym->section->target_index);
   4267 		  _bfd_vms_output_quad (recwr, rptr->addend);
   4268 		  _bfd_vms_output_counted (recwr, udata->origname);
   4269 		  _bfd_vms_output_end_subrec (recwr);
   4270 		  break;
   4271 
   4272 		case ALPHA_R_BOH:
   4273 		  udata
   4274 		    = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
   4275 		  if (!etir_output_check (abfd, section, curr_addr,
   4276 					  32 + 1 + strlen (udata->origname)))
   4277 		    return false;
   4278 		  _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
   4279 		  _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
   4280 		  _bfd_vms_output_long
   4281 		    (recwr, (unsigned long) section->target_index);
   4282 		  _bfd_vms_output_quad (recwr, rptr->address);
   4283 		  _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000);
   4284 		  _bfd_vms_output_long
   4285 		    (recwr, (unsigned long) section->target_index);
   4286 		  _bfd_vms_output_quad (recwr, rptr->addend);
   4287 		  _bfd_vms_output_counted (recwr, udata->origname);
   4288 		  _bfd_vms_output_end_subrec (recwr);
   4289 		  break;
   4290 
   4291 		default:
   4292 		  _bfd_error_handler (_("unhandled relocation %s"),
   4293 				      rptr->howto->name);
   4294 		  break;
   4295 		}
   4296 
   4297 	      curr_data += size;
   4298 	      curr_addr += size;
   4299 	    } /* End of relocs loop.  */
   4300 
   4301 	  if (!pass2_in_progress)
   4302 	    {
   4303 	      /* Output rest of section.  */
   4304 	      if (curr_addr > section->size)
   4305 		{
   4306 		  _bfd_error_handler (_("size error in section %pA"), section);
   4307 		  return false;
   4308 		}
   4309 	      size = section->size - curr_addr;
   4310 	      if (!sto_imm (abfd, section, size, curr_data, curr_addr))
   4311 		return false;
   4312 	      curr_data += size;
   4313 	      curr_addr += size;
   4314 
   4315 	      if (pass2_needed)
   4316 		{
   4317 		  pass2_in_progress = 1;
   4318 		  goto new_pass;
   4319 		}
   4320 	    }
   4321 	}
   4322 
   4323       else /* (section->flags & SEC_RELOC) */
   4324 	if (!sto_imm (abfd, section, section->size, section->contents, 0))
   4325 	  return false;
   4326 
   4327       if (!end_etir_record (abfd))
   4328 	return false;
   4329     }
   4330 
   4331   _bfd_vms_output_alignment (recwr, 2);
   4332   return true;
   4333 }
   4334 
   4335 /* Write cached information into a file being written, at bfd_close.  */
   4336 
   4337 static bool
   4338 alpha_vms_write_object_contents (bfd *abfd)
   4339 {
   4340   vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
   4341 
   4342   if (abfd->flags & (EXEC_P | DYNAMIC))
   4343     {
   4344       return alpha_vms_write_exec (abfd);
   4345     }
   4346   else
   4347     {
   4348       if (abfd->section_count > 0)			/* we have sections */
   4349 	{
   4350 	  if (!_bfd_vms_write_ehdr (abfd))
   4351 	    return false;
   4352 	  if (!_bfd_vms_write_egsd (abfd))
   4353 	    return false;
   4354 	  if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR))
   4355 	    return false;
   4356 	  if (!_bfd_vms_write_eeom (abfd))
   4357 	    return false;
   4358 	}
   4359     }
   4360   return true;
   4361 }
   4362 
   4363 /* Debug stuff: nearest line.  */
   4365 
   4366 #define SET_MODULE_PARSED(m) \
   4367   do { if ((m)->name == NULL) (m)->name = ""; } while (0)
   4368 #define IS_MODULE_PARSED(m) ((m)->name != NULL)
   4369 
   4370 /* Build a new module for the specified BFD.  */
   4371 
   4372 static struct module *
   4373 new_module (bfd *abfd)
   4374 {
   4375   struct module *module
   4376     = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
   4377   module->file_table_count = 16; /* Arbitrary.  */
   4378   module->file_table
   4379     = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo));
   4380   return module;
   4381 }
   4382 
   4383 /* Parse debug info for a module and internalize it.  */
   4384 
   4385 static bool
   4386 parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
   4387 	      bfd_size_type length)
   4388 {
   4389   unsigned char *maxptr = ptr + length;
   4390   unsigned char *src_ptr, *pcl_ptr;
   4391   unsigned int prev_linum = 0, curr_linenum = 0;
   4392   bfd_vma prev_pc = 0, curr_pc = 0;
   4393   struct srecinfo *curr_srec, *srec;
   4394   struct lineinfo *curr_line, *line;
   4395   struct funcinfo *funcinfo;
   4396 
   4397   /* Initialize tables with zero element.  */
   4398   curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
   4399   if (!curr_srec)
   4400     return false;
   4401   module->srec_table = curr_srec;
   4402 
   4403   curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
   4404   if (!curr_line)
   4405     return false;
   4406   module->line_table = curr_line;
   4407 
   4408   while (ptr + 3 < maxptr)
   4409     {
   4410       /* The first byte is not counted in the recorded length.  */
   4411       int rec_length = bfd_getl16 (ptr) + 1;
   4412       int rec_type = bfd_getl16 (ptr + 2);
   4413 
   4414       vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
   4415 
   4416       if (rec_length > maxptr - ptr)
   4417 	break;
   4418       if (rec_type == DST__K_MODEND)
   4419 	break;
   4420 
   4421       switch (rec_type)
   4422 	{
   4423 	case DST__K_MODBEG:
   4424 	  if (rec_length <= DST_S_B_MODBEG_NAME)
   4425 	    break;
   4426 	  module->name
   4427 	    = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME,
   4428 					    rec_length - DST_S_B_MODBEG_NAME);
   4429 
   4430 	  curr_pc = 0;
   4431 	  prev_pc = 0;
   4432 	  curr_linenum = 0;
   4433 	  prev_linum = 0;
   4434 
   4435 	  vms_debug2 ((3, "module: %s\n", module->name));
   4436 	  break;
   4437 
   4438 	case DST__K_MODEND:
   4439 	  break;
   4440 
   4441 	case DST__K_RTNBEG:
   4442 	  if (rec_length <= DST_S_B_RTNBEG_NAME)
   4443 	    break;
   4444 	  funcinfo = (struct funcinfo *)
   4445 	    bfd_zalloc (abfd, sizeof (struct funcinfo));
   4446 	  if (!funcinfo)
   4447 	    return false;
   4448 	  funcinfo->name
   4449 	    = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME,
   4450 					    rec_length - DST_S_B_RTNBEG_NAME);
   4451 	  funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
   4452 	  funcinfo->next = module->func_table;
   4453 	  module->func_table = funcinfo;
   4454 
   4455 	  vms_debug2 ((3, "routine: %s at 0x%lx\n",
   4456 		       funcinfo->name, (unsigned long) funcinfo->low));
   4457 	  break;
   4458 
   4459 	case DST__K_RTNEND:
   4460 	  if (rec_length < DST_S_L_RTNEND_SIZE + 4)
   4461 	    break;
   4462 	  if (!module->func_table)
   4463 	    return false;
   4464 	  module->func_table->high = module->func_table->low
   4465 	    + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1;
   4466 
   4467 	  if (module->func_table->high > module->high)
   4468 	    module->high = module->func_table->high;
   4469 
   4470 	  vms_debug2 ((3, "end routine\n"));
   4471 	  break;
   4472 
   4473 	case DST__K_PROLOG:
   4474 	  vms_debug2 ((3, "prologue\n"));
   4475 	  break;
   4476 
   4477 	case DST__K_EPILOG:
   4478 	  vms_debug2 ((3, "epilog\n"));
   4479 	  break;
   4480 
   4481 	case DST__K_BLKBEG:
   4482 	  vms_debug2 ((3, "block\n"));
   4483 	  break;
   4484 
   4485 	case DST__K_BLKEND:
   4486 	  vms_debug2 ((3, "end block\n"));
   4487 	  break;
   4488 
   4489 	case DST__K_SOURCE:
   4490 	  src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE;
   4491 
   4492 	  vms_debug2 ((3, "source info\n"));
   4493 
   4494 	  while (src_ptr - ptr < rec_length)
   4495 	    {
   4496 	      int cmd = src_ptr[0], cmd_length, data;
   4497 
   4498 	      switch (cmd)
   4499 		{
   4500 		case DST__K_SRC_DECLFILE:
   4501 		  if (src_ptr - ptr + DST_S_B_SRC_DF_LENGTH >= rec_length)
   4502 		    cmd_length = 0x10000;
   4503 		  else
   4504 		    cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2;
   4505 		  break;
   4506 
   4507 		case DST__K_SRC_DEFLINES_B:
   4508 		  cmd_length = 2;
   4509 		  break;
   4510 
   4511 		case DST__K_SRC_DEFLINES_W:
   4512 		  cmd_length = 3;
   4513 		  break;
   4514 
   4515 		case DST__K_SRC_INCRLNUM_B:
   4516 		  cmd_length = 2;
   4517 		  break;
   4518 
   4519 		case DST__K_SRC_SETFILE:
   4520 		  cmd_length = 3;
   4521 		  break;
   4522 
   4523 		case DST__K_SRC_SETLNUM_L:
   4524 		  cmd_length = 5;
   4525 		  break;
   4526 
   4527 		case DST__K_SRC_SETLNUM_W:
   4528 		  cmd_length = 3;
   4529 		  break;
   4530 
   4531 		case DST__K_SRC_SETREC_L:
   4532 		  cmd_length = 5;
   4533 		  break;
   4534 
   4535 		case DST__K_SRC_SETREC_W:
   4536 		  cmd_length = 3;
   4537 		  break;
   4538 
   4539 		case DST__K_SRC_FORMFEED:
   4540 		  cmd_length = 1;
   4541 		  break;
   4542 
   4543 		default:
   4544 		  cmd_length = 2;
   4545 		  break;
   4546 		}
   4547 
   4548 	      if (src_ptr - ptr + cmd_length > rec_length)
   4549 		break;
   4550 
   4551 	      switch (cmd)
   4552 		{
   4553 		case DST__K_SRC_DECLFILE:
   4554 		  {
   4555 		    unsigned int fileid
   4556 		      = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
   4557 		    char *filename = _bfd_vms_save_counted_string
   4558 		      (abfd,
   4559 		       src_ptr + DST_S_B_SRC_DF_FILENAME,
   4560 		       ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME));
   4561 
   4562 		    if (fileid >= module->file_table_count)
   4563 		      {
   4564 			unsigned int old_count = module->file_table_count;
   4565 			module->file_table_count += fileid;
   4566 			module->file_table
   4567 			  = bfd_realloc_or_free (module->file_table,
   4568 						 module->file_table_count
   4569 						 * sizeof (struct fileinfo));
   4570 			if (module->file_table == NULL)
   4571 			  return false;
   4572 			memset (module->file_table + old_count, 0,
   4573 				fileid * sizeof (struct fileinfo));
   4574 		      }
   4575 
   4576 		    module->file_table [fileid].name = filename;
   4577 		    module->file_table [fileid].srec = 1;
   4578 		    vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
   4579 				 fileid, module->file_table [fileid].name));
   4580 		  }
   4581 		  break;
   4582 
   4583 		case DST__K_SRC_DEFLINES_B:
   4584 		  /* Perform the association and set the next higher index
   4585 		     to the limit.  */
   4586 		  data = src_ptr[DST_S_B_SRC_UNSBYTE];
   4587 		  srec = (struct srecinfo *)
   4588 		    bfd_zalloc (abfd, sizeof (struct srecinfo));
   4589 		  srec->line = curr_srec->line + data;
   4590 		  srec->srec = curr_srec->srec + data;
   4591 		  srec->sfile = curr_srec->sfile;
   4592 		  curr_srec->next = srec;
   4593 		  curr_srec = srec;
   4594 		  vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data));
   4595 		  break;
   4596 
   4597 		case DST__K_SRC_DEFLINES_W:
   4598 		  /* Perform the association and set the next higher index
   4599 		     to the limit.  */
   4600 		  data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
   4601 		  srec = (struct srecinfo *)
   4602 		    bfd_zalloc (abfd, sizeof (struct srecinfo));
   4603 		  srec->line = curr_srec->line + data;
   4604 		  srec->srec = curr_srec->srec + data,
   4605 		  srec->sfile = curr_srec->sfile;
   4606 		  curr_srec->next = srec;
   4607 		  curr_srec = srec;
   4608 		  vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data));
   4609 		  break;
   4610 
   4611 		case DST__K_SRC_INCRLNUM_B:
   4612 		  data = src_ptr[DST_S_B_SRC_UNSBYTE];
   4613 		  curr_srec->line += data;
   4614 		  vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data));
   4615 		  break;
   4616 
   4617 		case DST__K_SRC_SETFILE:
   4618 		  data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
   4619 		  if ((unsigned int) data < module->file_table_count)
   4620 		    {
   4621 		      curr_srec->sfile = data;
   4622 		      curr_srec->srec = module->file_table[data].srec;
   4623 		    }
   4624 		  vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data));
   4625 		  break;
   4626 
   4627 		case DST__K_SRC_SETLNUM_L:
   4628 		  data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
   4629 		  curr_srec->line = data;
   4630 		  vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data));
   4631 		  break;
   4632 
   4633 		case DST__K_SRC_SETLNUM_W:
   4634 		  data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
   4635 		  curr_srec->line = data;
   4636 		  vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data));
   4637 		  break;
   4638 
   4639 		case DST__K_SRC_SETREC_L:
   4640 		  data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
   4641 		  curr_srec->srec = data;
   4642 		  module->file_table[curr_srec->sfile].srec = data;
   4643 		  vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data));
   4644 		  break;
   4645 
   4646 		case DST__K_SRC_SETREC_W:
   4647 		  data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
   4648 		  curr_srec->srec = data;
   4649 		  module->file_table[curr_srec->sfile].srec = data;
   4650 		  vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data));
   4651 		  break;
   4652 
   4653 		case DST__K_SRC_FORMFEED:
   4654 		  vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n"));
   4655 		  break;
   4656 
   4657 		default:
   4658 		  _bfd_error_handler (_("unknown source command %d"),
   4659 				      cmd);
   4660 		  break;
   4661 		}
   4662 
   4663 	      src_ptr += cmd_length;
   4664 	    }
   4665 	  break;
   4666 
   4667 	case DST__K_LINE_NUM:
   4668 	  pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE;
   4669 
   4670 	  vms_debug2 ((3, "line info\n"));
   4671 
   4672 	  while (pcl_ptr - ptr < rec_length)
   4673 	    {
   4674 	      /* The command byte is signed so we must sign-extend it.  */
   4675 	      int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data;
   4676 
   4677 	      switch (cmd)
   4678 		{
   4679 		case DST__K_DELTA_PC_W:
   4680 		  cmd_length = 3;
   4681 		  break;
   4682 
   4683 		case DST__K_DELTA_PC_L:
   4684 		  cmd_length = 5;
   4685 		  break;
   4686 
   4687 		case DST__K_INCR_LINUM:
   4688 		  cmd_length = 2;
   4689 		  break;
   4690 
   4691 		case DST__K_INCR_LINUM_W:
   4692 		  cmd_length = 3;
   4693 		  break;
   4694 
   4695 		case DST__K_INCR_LINUM_L:
   4696 		  cmd_length = 5;
   4697 		  break;
   4698 
   4699 		case DST__K_SET_LINUM_INCR:
   4700 		  cmd_length = 2;
   4701 		  break;
   4702 
   4703 		case DST__K_SET_LINUM_INCR_W:
   4704 		  cmd_length = 3;
   4705 		  break;
   4706 
   4707 		case DST__K_RESET_LINUM_INCR:
   4708 		  cmd_length = 1;
   4709 		  break;
   4710 
   4711 		case DST__K_BEG_STMT_MODE:
   4712 		  cmd_length = 1;
   4713 		  break;
   4714 
   4715 		case DST__K_END_STMT_MODE:
   4716 		  cmd_length = 1;
   4717 		  break;
   4718 
   4719 		case DST__K_SET_LINUM_B:
   4720 		  cmd_length = 2;
   4721 		  break;
   4722 
   4723 		case DST__K_SET_LINUM:
   4724 		  cmd_length = 3;
   4725 		  break;
   4726 
   4727 		case DST__K_SET_LINUM_L:
   4728 		  cmd_length = 5;
   4729 		  break;
   4730 
   4731 		case DST__K_SET_PC:
   4732 		  cmd_length = 2;
   4733 		  break;
   4734 
   4735 		case DST__K_SET_PC_W:
   4736 		  cmd_length = 3;
   4737 		  break;
   4738 
   4739 		case DST__K_SET_PC_L:
   4740 		  cmd_length = 5;
   4741 		  break;
   4742 
   4743 		case DST__K_SET_STMTNUM:
   4744 		  cmd_length = 2;
   4745 		  break;
   4746 
   4747 		case DST__K_TERM:
   4748 		  cmd_length = 2;
   4749 		  break;
   4750 
   4751 		case DST__K_TERM_W:
   4752 		  cmd_length = 3;
   4753 		  break;
   4754 
   4755 		case DST__K_TERM_L:
   4756 		  cmd_length = 5;
   4757 		  break;
   4758 
   4759 		case DST__K_SET_ABS_PC:
   4760 		  cmd_length = 5;
   4761 		  break;
   4762 
   4763 		default:
   4764 		  if (cmd <= 0)
   4765 		    cmd_length = 1;
   4766 		  else
   4767 		    cmd_length = 2;
   4768 		  break;
   4769 		}
   4770 
   4771 	      if (pcl_ptr - ptr + cmd_length > rec_length)
   4772 		break;
   4773 
   4774 	      switch (cmd)
   4775 		{
   4776 		case DST__K_DELTA_PC_W:
   4777 		  data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
   4778 		  curr_pc += data;
   4779 		  curr_linenum += 1;
   4780 		  vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data));
   4781 		  break;
   4782 
   4783 		case DST__K_DELTA_PC_L:
   4784 		  data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
   4785 		  curr_pc += data;
   4786 		  curr_linenum += 1;
   4787 		  vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data));
   4788 		  break;
   4789 
   4790 		case DST__K_INCR_LINUM:
   4791 		  data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
   4792 		  curr_linenum += data;
   4793 		  vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data));
   4794 		  break;
   4795 
   4796 		case DST__K_INCR_LINUM_W:
   4797 		  data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
   4798 		  curr_linenum += data;
   4799 		  vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data));
   4800 		  break;
   4801 
   4802 		case DST__K_INCR_LINUM_L:
   4803 		  data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
   4804 		  curr_linenum += data;
   4805 		  vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data));
   4806 		  break;
   4807 
   4808 		case DST__K_SET_LINUM_INCR:
   4809 		  _bfd_error_handler
   4810 		    (_("%s not implemented"), "DST__K_SET_LINUM_INCR");
   4811 		  break;
   4812 
   4813 		case DST__K_SET_LINUM_INCR_W:
   4814 		  _bfd_error_handler
   4815 		    (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W");
   4816 		  break;
   4817 
   4818 		case DST__K_RESET_LINUM_INCR:
   4819 		  _bfd_error_handler
   4820 		    (_("%s not implemented"), "DST__K_RESET_LINUM_INCR");
   4821 		  break;
   4822 
   4823 		case DST__K_BEG_STMT_MODE:
   4824 		  _bfd_error_handler
   4825 		    (_("%s not implemented"), "DST__K_BEG_STMT_MODE");
   4826 		  break;
   4827 
   4828 		case DST__K_END_STMT_MODE:
   4829 		  _bfd_error_handler
   4830 		    (_("%s not implemented"), "DST__K_END_STMT_MODE");
   4831 		  break;
   4832 
   4833 		case DST__K_SET_LINUM_B:
   4834 		  data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
   4835 		  curr_linenum = data;
   4836 		  vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data));
   4837 		  break;
   4838 
   4839 		case DST__K_SET_LINUM:
   4840 		  data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
   4841 		  curr_linenum = data;
   4842 		  vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data));
   4843 		  break;
   4844 
   4845 		case DST__K_SET_LINUM_L:
   4846 		  data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
   4847 		  curr_linenum = data;
   4848 		  vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data));
   4849 		  break;
   4850 
   4851 		case DST__K_SET_PC:
   4852 		  _bfd_error_handler
   4853 		    (_("%s not implemented"), "DST__K_SET_PC");
   4854 		  break;
   4855 
   4856 		case DST__K_SET_PC_W:
   4857 		  _bfd_error_handler
   4858 		    (_("%s not implemented"), "DST__K_SET_PC_W");
   4859 		  break;
   4860 
   4861 		case DST__K_SET_PC_L:
   4862 		  _bfd_error_handler
   4863 		    (_("%s not implemented"), "DST__K_SET_PC_L");
   4864 		  break;
   4865 
   4866 		case DST__K_SET_STMTNUM:
   4867 		  _bfd_error_handler
   4868 		    (_("%s not implemented"), "DST__K_SET_STMTNUM");
   4869 		  break;
   4870 
   4871 		case DST__K_TERM:
   4872 		  data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
   4873 		  curr_pc += data;
   4874 		  vms_debug2 ((4, "DST__K_TERM: %d\n", data));
   4875 		  break;
   4876 
   4877 		case DST__K_TERM_W:
   4878 		  data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
   4879 		  curr_pc += data;
   4880 		  vms_debug2 ((4, "DST__K_TERM_W: %d\n", data));
   4881 		  break;
   4882 
   4883 		case DST__K_TERM_L:
   4884 		  data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
   4885 		  curr_pc += data;
   4886 		  vms_debug2 ((4, "DST__K_TERM_L: %d\n", data));
   4887 		  break;
   4888 
   4889 		case DST__K_SET_ABS_PC:
   4890 		  data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
   4891 		  curr_pc = data;
   4892 		  vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data));
   4893 		  break;
   4894 
   4895 		default:
   4896 		  if (cmd <= 0)
   4897 		    {
   4898 		      curr_pc -= cmd;
   4899 		      curr_linenum += 1;
   4900 		      vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n",
   4901 				   (unsigned long)curr_pc, curr_linenum));
   4902 		    }
   4903 		  else
   4904 		    _bfd_error_handler (_("unknown line command %d"), cmd);
   4905 		  break;
   4906 		}
   4907 
   4908 	      if ((curr_linenum != prev_linum && curr_pc != prev_pc)
   4909 		  || cmd <= 0
   4910 		  || cmd == DST__K_DELTA_PC_L
   4911 		  || cmd == DST__K_DELTA_PC_W)
   4912 		{
   4913 		  line = (struct lineinfo *)
   4914 		    bfd_zalloc (abfd, sizeof (struct lineinfo));
   4915 		  line->address = curr_pc;
   4916 		  line->line = curr_linenum;
   4917 
   4918 		  curr_line->next = line;
   4919 		  curr_line = line;
   4920 
   4921 		  prev_linum = curr_linenum;
   4922 		  prev_pc = curr_pc;
   4923 		  vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n",
   4924 			       (unsigned long)curr_pc, curr_linenum));
   4925 		}
   4926 
   4927 	      pcl_ptr += cmd_length;
   4928 	    }
   4929 	  break;
   4930 
   4931 	case 0x17: /* Undocumented type used by DEC C to declare equates.  */
   4932 	  vms_debug2 ((3, "undocumented type 0x17\n"));
   4933 	  break;
   4934 
   4935 	default:
   4936 	  vms_debug2 ((3, "ignoring record\n"));
   4937 	  break;
   4938 
   4939 	}
   4940 
   4941       ptr += rec_length;
   4942     }
   4943 
   4944   /* Finalize tables with EOL marker.  */
   4945   srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
   4946   srec->line = (unsigned int) -1;
   4947   srec->srec = (unsigned int) -1;
   4948   curr_srec->next = srec;
   4949 
   4950   line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
   4951   line->line = (unsigned int) -1;
   4952   line->address = (bfd_vma) -1;
   4953   curr_line->next = line;
   4954 
   4955   /* Advertise that this module has been parsed.  This is needed
   4956      because parsing can be either performed at module creation
   4957      or deferred until debug info is consumed.  */
   4958   SET_MODULE_PARSED (module);
   4959   return true;
   4960 }
   4961 
   4962 /* Build the list of modules for the specified BFD.  */
   4963 
   4964 static struct module *
   4965 build_module_list (bfd *abfd)
   4966 {
   4967   struct module *module, *list = NULL;
   4968   asection *dmt;
   4969 
   4970   if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
   4971     {
   4972       /* We have a DMT section so this must be an image.  Parse the
   4973 	 section and build the list of modules.  This is sufficient
   4974 	 since we can compute the start address and the end address
   4975 	 of every module from the section contents.  */
   4976       bfd_size_type size = bfd_section_size (dmt);
   4977       unsigned char *buf, *ptr, *end;
   4978 
   4979       if (! bfd_malloc_and_get_section (abfd, dmt, &buf))
   4980 	return NULL;
   4981 
   4982       vms_debug2 ((2, "DMT\n"));
   4983 
   4984       ptr = buf;
   4985       end = ptr + size;
   4986       while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE)
   4987 	{
   4988 	  /* Each header declares a module with its start offset and size
   4989 	     of debug info in the DST section, as well as the count of
   4990 	     program sections (i.e. address spans) it contains.  */
   4991 	  unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
   4992 	  unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
   4993 	  int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
   4994 	  ptr += DBG_S_C_DMT_HEADER_SIZE;
   4995 
   4996 	  vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n",
   4997 		       modbeg, msize, count));
   4998 
   4999 	  /* We create a 'module' structure for each program section since
   5000 	     we only support contiguous addresses in a 'module' structure.
   5001 	     As a consequence, the actual debug info in the DST section is
   5002 	     shared and can be parsed multiple times; that doesn't seem to
   5003 	     cause problems in practice.  */
   5004 	  while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE)
   5005 	    {
   5006 	      unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
   5007 	      unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
   5008 	      module = new_module (abfd);
   5009 	      module->modbeg = modbeg;
   5010 	      module->size = msize;
   5011 	      module->low = start;
   5012 	      module->high = start + length;
   5013 	      module->next = list;
   5014 	      list = module;
   5015 	      ptr += DBG_S_C_DMT_PSECT_SIZE;
   5016 
   5017 	      vms_debug2 ((4, "section: start = 0x%x, length = %u\n",
   5018 			   start, length));
   5019 	    }
   5020 	}
   5021       free (buf);
   5022     }
   5023   else
   5024     {
   5025       /* We don't have a DMT section so this must be an object.  Parse
   5026 	 the module right now in order to compute its start address and
   5027 	 end address.  */
   5028       void *dst = PRIV (dst_section)->contents;
   5029 
   5030       if (dst == NULL)
   5031 	return NULL;
   5032 
   5033       module = new_module (abfd);
   5034       if (!parse_module (abfd, module, PRIV (dst_section)->contents,
   5035 			 PRIV (dst_section)->size))
   5036 	return NULL;
   5037       list = module;
   5038     }
   5039 
   5040   return list;
   5041 }
   5042 
   5043 /* Calculate and return the name of the source file and the line nearest
   5044    to the wanted location in the specified module.  */
   5045 
   5046 static bool
   5047 module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
   5048 			  const char **file, const char **func,
   5049 			  unsigned int *line)
   5050 {
   5051   struct funcinfo *funcinfo;
   5052   struct lineinfo *lineinfo;
   5053   struct srecinfo *srecinfo;
   5054   bool ret = false;
   5055 
   5056   /* Parse this module if that was not done at module creation.  */
   5057   if (! IS_MODULE_PARSED (module))
   5058     {
   5059       unsigned int size = module->size;
   5060       unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
   5061       unsigned char *buffer;
   5062 
   5063       if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
   5064 	  || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL)
   5065 	{
   5066 	  bfd_set_error (bfd_error_no_debug_section);
   5067 	  return false;
   5068 	}
   5069 
   5070       ret = parse_module (abfd, module, buffer, size);
   5071       free (buffer);
   5072       if (!ret)
   5073 	return ret;
   5074     }
   5075 
   5076   /* Find out the function (if any) that contains the address.  */
   5077   for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next)
   5078     if (addr >= funcinfo->low && addr <= funcinfo->high)
   5079       {
   5080 	*func = funcinfo->name;
   5081 	ret = true;
   5082 	break;
   5083       }
   5084 
   5085   /* Find out the source file and the line nearest to the address.  */
   5086   for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
   5087     if (lineinfo->next && addr < lineinfo->next->address)
   5088       {
   5089 	for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
   5090 	  if (srecinfo->next && lineinfo->line < srecinfo->next->line)
   5091 	    {
   5092 	      if (srecinfo->sfile > 0)
   5093 		{
   5094 		  *file = module->file_table[srecinfo->sfile].name;
   5095 		  *line = srecinfo->srec + lineinfo->line - srecinfo->line;
   5096 		}
   5097 	      else
   5098 		{
   5099 		  *file = module->name;
   5100 		  *line = lineinfo->line;
   5101 		}
   5102 	      return true;
   5103 	    }
   5104 
   5105 	break;
   5106       }
   5107 
   5108   return ret;
   5109 }
   5110 
   5111 /* Provided a BFD, a section and an offset into the section, calculate and
   5112    return the name of the source file and the line nearest to the wanted
   5113    location.  */
   5114 
   5115 static bool
   5116 _bfd_vms_find_nearest_line (bfd *abfd,
   5117 			    asymbol **symbols ATTRIBUTE_UNUSED,
   5118 			    asection *section,
   5119 			    bfd_vma offset,
   5120 			    const char **file,
   5121 			    const char **func,
   5122 			    unsigned int *line,
   5123 			    unsigned int *discriminator)
   5124 {
   5125   struct module *module;
   5126 
   5127   /* What address are we looking for?  */
   5128   bfd_vma addr = section->vma + offset;
   5129 
   5130   *file = NULL;
   5131   *func = NULL;
   5132   *line = 0;
   5133   if (discriminator)
   5134     *discriminator = 0;
   5135 
   5136   /* We can't do anything if there is no DST (debug symbol table).  */
   5137   if (PRIV (dst_section) == NULL)
   5138     return false;
   5139 
   5140   /* Create the module list - if not already done.  */
   5141   if (PRIV (modules) == NULL)
   5142     {
   5143       PRIV (modules) = build_module_list (abfd);
   5144       if (PRIV (modules) == NULL)
   5145 	return false;
   5146     }
   5147 
   5148   for (module = PRIV (modules); module; module = module->next)
   5149     if (addr >= module->low && addr <= module->high)
   5150       return module_find_nearest_line (abfd, module, addr, file, func, line);
   5151 
   5152   return false;
   5153 }
   5154 
   5155 /* Canonicalizations.  */
   5157 /* Set name, value, section and flags of SYM from E.  */
   5158 
   5159 static bool
   5160 alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
   5161 {
   5162   flagword flags;
   5163   symvalue value;
   5164   asection *sec;
   5165   const char *name;
   5166 
   5167   name = e->name;
   5168   value = 0;
   5169   flags = BSF_NO_FLAGS;
   5170   sec = NULL;
   5171 
   5172   switch (e->typ)
   5173     {
   5174     case EGSD__C_SYM:
   5175       if (e->flags & EGSY__V_WEAK)
   5176 	flags |= BSF_WEAK;
   5177 
   5178       if (e->flags & EGSY__V_DEF)
   5179 	{
   5180 	  /* Symbol definition.  */
   5181 	  flags |= BSF_GLOBAL;
   5182 	  if (e->flags & EGSY__V_NORM)
   5183 	    flags |= BSF_FUNCTION;
   5184 	  value = e->value;
   5185 	  sec = e->section;
   5186 	}
   5187       else
   5188 	{
   5189 	  /* Symbol reference.  */
   5190 	  sec = bfd_und_section_ptr;
   5191 	}
   5192       break;
   5193 
   5194     case EGSD__C_SYMG:
   5195       /* A universal symbol is by definition global...  */
   5196       flags |= BSF_GLOBAL;
   5197 
   5198       /* ...and dynamic in shared libraries.  */
   5199       if (abfd->flags & DYNAMIC)
   5200 	flags |= BSF_DYNAMIC;
   5201 
   5202       if (e->flags & EGSY__V_WEAK)
   5203 	flags |= BSF_WEAK;
   5204 
   5205       if (!(e->flags & EGSY__V_DEF))
   5206 	abort ();
   5207 
   5208       if (e->flags & EGSY__V_NORM)
   5209 	flags |= BSF_FUNCTION;
   5210 
   5211       value = e->value;
   5212       /* sec = e->section; */
   5213       sec = bfd_abs_section_ptr;
   5214       break;
   5215 
   5216     default:
   5217       return false;
   5218     }
   5219 
   5220   sym->name = name;
   5221   sym->section = sec;
   5222   sym->flags = flags;
   5223   sym->value = value;
   5224   return true;
   5225 }
   5226 
   5227 
   5228 /* Return the number of bytes required to store a vector of pointers
   5229    to asymbols for all the symbols in the BFD abfd, including a
   5230    terminal NULL pointer. If there are no symbols in the BFD,
   5231    then return 0.  If an error occurs, return -1.  */
   5232 
   5233 static long
   5234 alpha_vms_get_symtab_upper_bound (bfd *abfd)
   5235 {
   5236   vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
   5237 	       abfd, PRIV (gsd_sym_count)));
   5238 
   5239   return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
   5240 }
   5241 
   5242 /* Read the symbols from the BFD abfd, and fills in the vector
   5243    location with pointers to the symbols and a trailing NULL.
   5244 
   5245    Return number of symbols read.   */
   5246 
   5247 static long
   5248 alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols)
   5249 {
   5250   unsigned int i;
   5251 
   5252   vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
   5253 
   5254   if (PRIV (csymbols) == NULL)
   5255     {
   5256       PRIV (csymbols) = (asymbol **) bfd_alloc
   5257 	(abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
   5258 
   5259       /* Traverse table and fill symbols vector.  */
   5260       for (i = 0; i < PRIV (gsd_sym_count); i++)
   5261 	{
   5262 	  struct vms_symbol_entry *e = PRIV (syms)[i];
   5263 	  asymbol *sym;
   5264 
   5265 	  sym = bfd_make_empty_symbol (abfd);
   5266 	  if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym))
   5267 	    {
   5268 	      bfd_release (abfd, PRIV (csymbols));
   5269 	      PRIV (csymbols) = NULL;
   5270 	      return -1;
   5271 	    }
   5272 
   5273 	  PRIV (csymbols)[i] = sym;
   5274 	}
   5275     }
   5276 
   5277   if (symbols != NULL)
   5278     {
   5279       for (i = 0; i < PRIV (gsd_sym_count); i++)
   5280 	symbols[i] = PRIV (csymbols)[i];
   5281       symbols[i] = NULL;
   5282     }
   5283 
   5284   return PRIV (gsd_sym_count);
   5285 }
   5286 
   5287 /* Read and convert relocations from ETIR.  We do it once for all sections.  */
   5288 
   5289 static bool
   5290 alpha_vms_slurp_relocs (bfd *abfd)
   5291 {
   5292   int cur_psect = -1;
   5293 
   5294   vms_debug2 ((3, "alpha_vms_slurp_relocs\n"));
   5295 
   5296   /* We slurp relocs only once, for all sections.  */
   5297   if (PRIV (reloc_done) != 0)
   5298     return PRIV (reloc_done) == 1;
   5299 
   5300   if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
   5301     goto fail;
   5302 
   5303   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
   5304     goto fail;
   5305 
   5306   while (1)
   5307     {
   5308       unsigned char *begin;
   5309       unsigned char *end;
   5310       unsigned char *ptr;
   5311       bfd_reloc_code_real_type reloc_code;
   5312       int type;
   5313       bfd_vma vaddr = 0;
   5314 
   5315       int length;
   5316 
   5317       bfd_vma cur_address;
   5318       int cur_psidx = -1;
   5319       unsigned char *cur_sym = NULL;
   5320       int prev_cmd = -1;
   5321       bfd_vma cur_addend = 0;
   5322 
   5323       /* Skip non-ETIR records.  */
   5324       type = _bfd_vms_get_object_record (abfd);
   5325       if (type < 0)
   5326 	goto fail;
   5327       if (type == EOBJ__C_EEOM)
   5328 	break;
   5329       if (type != EOBJ__C_ETIR)
   5330 	continue;
   5331 
   5332       begin = PRIV (recrd.rec) + 4;
   5333       end = PRIV (recrd.rec) + PRIV (recrd.rec_size);
   5334 
   5335       for (ptr = begin; ptr + 4 <= end; ptr += length)
   5336 	{
   5337 	  int cmd;
   5338 
   5339 	  cmd = bfd_getl16 (ptr);
   5340 	  length = bfd_getl16 (ptr + 2);
   5341 	  if (length < 4 || length > end - ptr)
   5342 	    {
   5343 	    bad_rec:
   5344 	      _bfd_error_handler (_("corrupt reloc record"));
   5345 	      goto fail;
   5346 	    }
   5347 
   5348 	  cur_address = vaddr;
   5349 
   5350 	  vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n",
   5351 		       _bfd_vms_etir_name (cmd)));
   5352 
   5353 	  switch (cmd)
   5354 	    {
   5355 	    case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */
   5356 				  /* ALPHA_R_REFQUAD und_section, step 1 */
   5357 	      cur_sym = ptr + 4;
   5358 	      prev_cmd = cmd;
   5359 	      continue;
   5360 
   5361 	    case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */
   5362 	      if (length < 16)
   5363 		goto bad_rec;
   5364 	      cur_psidx = bfd_getl32 (ptr + 4);
   5365 	      cur_addend = bfd_getl64 (ptr + 8);
   5366 	      prev_cmd = cmd;
   5367 	      continue;
   5368 
   5369 	    case ETIR__C_CTL_SETRB:
   5370 	      if (prev_cmd != ETIR__C_STA_PQ)
   5371 		{
   5372 		  _bfd_error_handler
   5373 		    /* xgettext:c-format */
   5374 		    (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
   5375 		     _bfd_vms_etir_name (cmd));
   5376 		  goto fail;
   5377 		}
   5378 	      cur_psect = cur_psidx;
   5379 	      vaddr = cur_addend;
   5380 	      cur_psidx = -1;
   5381 	      cur_addend = 0;
   5382 	      continue;
   5383 
   5384 	    case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */
   5385 				 /* ALPHA_R_REFLONG und_section, step 2 */
   5386 	      if (prev_cmd != -1)
   5387 		{
   5388 		  if (prev_cmd != ETIR__C_STA_GBL)
   5389 		    {
   5390 		      _bfd_error_handler
   5391 			/* xgettext:c-format */
   5392 			(_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
   5393 			 _bfd_vms_etir_name (ETIR__C_STA_LW));
   5394 		      goto fail;
   5395 		    }
   5396 		}
   5397 	      if (length < 8)
   5398 		goto bad_rec;
   5399 	      cur_addend = bfd_getl32 (ptr + 4);
   5400 	      prev_cmd = cmd;
   5401 	      continue;
   5402 
   5403 	    case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */
   5404 				 /* ALPHA_R_REFQUAD und_section, step 2 */
   5405 	      if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL)
   5406 		{
   5407 		  _bfd_error_handler
   5408 		    /* xgettext:c-format */
   5409 		    (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
   5410 		     _bfd_vms_etir_name (ETIR__C_STA_QW));
   5411 		  goto fail;
   5412 		}
   5413 	      if (length < 12)
   5414 		goto bad_rec;
   5415 	      cur_addend = bfd_getl64 (ptr + 4);
   5416 	      prev_cmd = cmd;
   5417 	      continue;
   5418 
   5419 	    case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */
   5420 				 /* ALPHA_R_REFLONG abs_section, step 2 */
   5421 				 /* ALPHA_R_REFLONG others, step 2 */
   5422 	      if (prev_cmd != ETIR__C_OPR_ADD
   5423 		  && prev_cmd != ETIR__C_STA_LW
   5424 		  && prev_cmd != ETIR__C_STA_PQ)
   5425 		{
   5426 		  /* xgettext:c-format */
   5427 		  _bfd_error_handler (_("unknown reloc %s + %s"),
   5428 				      _bfd_vms_etir_name (prev_cmd),
   5429 				      _bfd_vms_etir_name (ETIR__C_STO_LW));
   5430 		  goto fail;
   5431 		}
   5432 	      reloc_code = BFD_RELOC_32;
   5433 	      break;
   5434 
   5435 	    case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */
   5436 				 /* ALPHA_R_REFQUAD abs_section, step 2 */
   5437 	      if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW)
   5438 		{
   5439 		  /* xgettext:c-format */
   5440 		  _bfd_error_handler (_("unknown reloc %s + %s"),
   5441 				      _bfd_vms_etir_name (prev_cmd),
   5442 				      _bfd_vms_etir_name (ETIR__C_STO_QW));
   5443 		  goto fail;
   5444 		}
   5445 	      reloc_code = BFD_RELOC_64;
   5446 	      break;
   5447 
   5448 	    case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */
   5449 	      if (prev_cmd != ETIR__C_STA_PQ)
   5450 		{
   5451 		  /* xgettext:c-format */
   5452 		  _bfd_error_handler (_("unknown reloc %s + %s"),
   5453 				      _bfd_vms_etir_name (prev_cmd),
   5454 				      _bfd_vms_etir_name (ETIR__C_STO_OFF));
   5455 		  goto fail;
   5456 		}
   5457 	      reloc_code = BFD_RELOC_64;
   5458 	      break;
   5459 
   5460 	    case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */
   5461 				  /* ALPHA_R_REFQUAD und_section, step 3 */
   5462 	      if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW)
   5463 		{
   5464 		  /* xgettext:c-format */
   5465 		  _bfd_error_handler (_("unknown reloc %s + %s"),
   5466 				      _bfd_vms_etir_name (prev_cmd),
   5467 				      _bfd_vms_etir_name (ETIR__C_OPR_ADD));
   5468 		  goto fail;
   5469 		}
   5470 	      prev_cmd = ETIR__C_OPR_ADD;
   5471 	      continue;
   5472 
   5473 	    case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */
   5474 	      reloc_code = BFD_RELOC_ALPHA_CODEADDR;
   5475 	      cur_sym = ptr + 4;
   5476 	      break;
   5477 
   5478 	    case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */
   5479 	      reloc_code = BFD_RELOC_64;
   5480 	      cur_sym = ptr + 4;
   5481 	      break;
   5482 
   5483 	    case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */
   5484 	      reloc_code = BFD_RELOC_32;
   5485 	      cur_sym = ptr + 4;
   5486 	      break;
   5487 
   5488 	    case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */
   5489 	      reloc_code = BFD_RELOC_ALPHA_LINKAGE;
   5490 	      cur_sym = ptr + 8;
   5491 	      break;
   5492 
   5493 	    case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */
   5494 	      reloc_code = BFD_RELOC_ALPHA_NOP;
   5495 	      goto call_reloc;
   5496 
   5497 	    case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */
   5498 	      reloc_code = BFD_RELOC_ALPHA_BSR;
   5499 	      goto call_reloc;
   5500 
   5501 	    case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */
   5502 	      reloc_code = BFD_RELOC_ALPHA_LDA;
   5503 	      goto call_reloc;
   5504 
   5505 	    case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */
   5506 	      reloc_code = BFD_RELOC_ALPHA_BOH;
   5507 	      goto call_reloc;
   5508 
   5509 	    call_reloc:
   5510 	      if (length < 36)
   5511 		goto bad_rec;
   5512 	      cur_sym = ptr + 4 + 32;
   5513 	      cur_address = bfd_getl64 (ptr + 4 + 8);
   5514 	      cur_addend = bfd_getl64 (ptr + 4 + 24);
   5515 	      break;
   5516 
   5517 	    case ETIR__C_STO_IMM:
   5518 	      if (length < 8)
   5519 		goto bad_rec;
   5520 	      vaddr += bfd_getl32 (ptr + 4);
   5521 	      continue;
   5522 
   5523 	    default:
   5524 	      _bfd_error_handler (_("unknown reloc %s"),
   5525 				  _bfd_vms_etir_name (cmd));
   5526 	      goto fail;
   5527 	    }
   5528 
   5529 	  {
   5530 	    asection *sec;
   5531 	    struct vms_section_data_struct *vms_sec;
   5532 	    arelent *reloc;
   5533 	    bfd_size_type size;
   5534 
   5535 	    /* Get section to which the relocation applies.  */
   5536 	    if (cur_psect < 0 || cur_psect > (int)PRIV (section_count))
   5537 	      {
   5538 		_bfd_error_handler (_("invalid section index in ETIR"));
   5539 		goto fail;
   5540 	      }
   5541 
   5542 	    if (PRIV (sections) == NULL)
   5543 	      goto fail;
   5544 	    sec = PRIV (sections)[cur_psect];
   5545 	    if (sec == bfd_abs_section_ptr)
   5546 	      {
   5547 		_bfd_error_handler (_("relocation for non-REL psect"));
   5548 		goto fail;
   5549 	      }
   5550 
   5551 	    vms_sec = vms_section_data (sec);
   5552 
   5553 	    /* Allocate a reloc entry.  */
   5554 	    if (sec->reloc_count >= vms_sec->reloc_max)
   5555 	      {
   5556 		if (vms_sec->reloc_max == 0)
   5557 		  {
   5558 		    vms_sec->reloc_max = 64;
   5559 		    sec->relocation = bfd_zmalloc
   5560 		      (vms_sec->reloc_max * sizeof (arelent));
   5561 		  }
   5562 		else
   5563 		  {
   5564 		    vms_sec->reloc_max *= 2;
   5565 		    sec->relocation = bfd_realloc_or_free
   5566 		      (sec->relocation, vms_sec->reloc_max * sizeof (arelent));
   5567 		    if (sec->relocation == NULL)
   5568 		      goto fail;
   5569 		  }
   5570 	      }
   5571 	    reloc = &sec->relocation[sec->reloc_count];
   5572 	    sec->reloc_count++;
   5573 
   5574 	    reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code);
   5575 
   5576 	    if (cur_sym != NULL)
   5577 	      {
   5578 		unsigned int j;
   5579 		int symlen;
   5580 		asymbol **sym;
   5581 
   5582 		/* Linear search.  */
   5583 		if (end - cur_sym < 1)
   5584 		  goto bad_rec;
   5585 		symlen = *cur_sym;
   5586 		cur_sym++;
   5587 		if (end - cur_sym < symlen)
   5588 		  goto bad_rec;
   5589 		sym = NULL;
   5590 
   5591 		for (j = 0; j < PRIV (gsd_sym_count); j++)
   5592 		  if (PRIV (syms)[j]->namelen == symlen
   5593 		      && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0)
   5594 		    {
   5595 		      sym = &PRIV (csymbols)[j];
   5596 		      break;
   5597 		    }
   5598 		if (sym == NULL)
   5599 		  {
   5600 		    _bfd_error_handler (_("unknown symbol in command %s"),
   5601 					_bfd_vms_etir_name (cmd));
   5602 		    reloc->sym_ptr_ptr = NULL;
   5603 		  }
   5604 		else
   5605 		  reloc->sym_ptr_ptr = sym;
   5606 	      }
   5607 	    else if (cur_psidx >= 0)
   5608 	      {
   5609 		if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count))
   5610 		  goto fail;
   5611 		reloc->sym_ptr_ptr = &PRIV (sections)[cur_psidx]->symbol;
   5612 	      }
   5613 	    else
   5614 	      reloc->sym_ptr_ptr = NULL;
   5615 
   5616 	    reloc->address = cur_address;
   5617 	    reloc->addend = cur_addend;
   5618 
   5619 	    if (reloc_code == ALPHA_R_LINKAGE)
   5620 	      size = 16;
   5621 	    else
   5622 	      size = bfd_get_reloc_size (reloc->howto);
   5623 	    vaddr += size;
   5624 	  }
   5625 
   5626 	  cur_addend = 0;
   5627 	  prev_cmd = -1;
   5628 	  cur_sym = NULL;
   5629 	  cur_psidx = -1;
   5630 	}
   5631     }
   5632   vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n"));
   5633   PRIV (reloc_done) = 1;
   5634   return true;
   5635 
   5636 fail:
   5637   PRIV (reloc_done) = -1;
   5638   return false;
   5639 }
   5640 
   5641 /* Return the number of bytes required to store the relocation
   5642    information associated with the given section.  */
   5643 
   5644 static long
   5645 alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section)
   5646 {
   5647   if (!alpha_vms_slurp_relocs (abfd))
   5648     return -1;
   5649 
   5650   return (section->reloc_count + 1L) * sizeof (arelent *);
   5651 }
   5652 
   5653 /* Convert relocations from VMS (external) form into BFD internal
   5654    form.  Return the number of relocations.  */
   5655 
   5656 static long
   5657 alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr,
   5658 			      asymbol **symbols ATTRIBUTE_UNUSED)
   5659 {
   5660   arelent *tblptr;
   5661   int count;
   5662 
   5663   if (!alpha_vms_slurp_relocs (abfd))
   5664     return -1;
   5665 
   5666   count = section->reloc_count;
   5667   tblptr = section->relocation;
   5668 
   5669   while (count--)
   5670     *relptr++ = tblptr++;
   5671 
   5672   *relptr = (arelent *) NULL;
   5673   return section->reloc_count;
   5674 }
   5675 
   5676 /* Install a new set of internal relocs.  */
   5677 
   5678 #define alpha_vms_finalize_section_relocs _bfd_generic_finalize_section_relocs
   5679 
   5680 
   5681 /* This is just copied from ecoff-alpha, needs to be fixed probably.  */
   5683 
   5684 /* How to process the various reloc types.  */
   5685 
   5686 static bfd_reloc_status_type
   5687 reloc_nil (bfd * abfd ATTRIBUTE_UNUSED,
   5688 	   arelent *reloc ATTRIBUTE_UNUSED,
   5689 	   asymbol *sym ATTRIBUTE_UNUSED,
   5690 	   void * data ATTRIBUTE_UNUSED,
   5691 	   asection *sec ATTRIBUTE_UNUSED,
   5692 	   bfd *output_bfd ATTRIBUTE_UNUSED,
   5693 	   char **error_message ATTRIBUTE_UNUSED)
   5694 {
   5695 #if VMS_DEBUG
   5696   vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd);
   5697   vms_debug (2, "In section %s, symbol %s\n",
   5698 	sec->name, sym->name);
   5699   vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
   5700 		reloc->sym_ptr_ptr[0]->name,
   5701 		(unsigned long)reloc->address,
   5702 		(unsigned long)reloc->addend, reloc->howto->name);
   5703   vms_debug (2, "data at %p\n", data);
   5704   /*  _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
   5705 #endif
   5706 
   5707   return bfd_reloc_ok;
   5708 }
   5709 
   5710 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
   5711    from smaller values.  Start with zero, widen, *then* decrement.  */
   5712 #define MINUS_ONE	(((bfd_vma)0) - 1)
   5713 
   5714 static reloc_howto_type alpha_howto_table[] =
   5715 {
   5716   HOWTO (ALPHA_R_IGNORE,	/* Type.  */
   5717 	 0,			/* Rightshift.  */
   5718 	 1,			/* Size.  */
   5719 	 8,			/* Bitsize.  */
   5720 	 true,			/* PC relative.  */
   5721 	 0,			/* Bitpos.  */
   5722 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5723 	 reloc_nil,		/* Special_function.  */
   5724 	 "IGNORE",		/* Name.  */
   5725 	 true,			/* Partial_inplace.  */
   5726 	 0,			/* Source mask */
   5727 	 0,			/* Dest mask.  */
   5728 	 true),			/* PC rel offset.  */
   5729 
   5730   /* A 64 bit reference to a symbol.  */
   5731   HOWTO (ALPHA_R_REFQUAD,	/* Type.  */
   5732 	 0,			/* Rightshift.  */
   5733 	 8,			/* Size.  */
   5734 	 64,			/* Bitsize.  */
   5735 	 false,			/* PC relative.  */
   5736 	 0,			/* Bitpos.  */
   5737 	 complain_overflow_bitfield, /* Complain_on_overflow.  */
   5738 	 reloc_nil,		/* Special_function.  */
   5739 	 "REFQUAD",		/* Name.  */
   5740 	 true,			/* Partial_inplace.  */
   5741 	 MINUS_ONE,		/* Source mask.  */
   5742 	 MINUS_ONE,		/* Dest mask.  */
   5743 	 false),		/* PC rel offset.  */
   5744 
   5745   /* A 21 bit branch.  The native assembler generates these for
   5746      branches within the text segment, and also fills in the PC
   5747      relative offset in the instruction.  */
   5748   HOWTO (ALPHA_R_BRADDR,	/* Type.  */
   5749 	 2,			/* Rightshift.  */
   5750 	 4,			/* Size.  */
   5751 	 21,			/* Bitsize.  */
   5752 	 true,			/* PC relative.  */
   5753 	 0,			/* Bitpos.  */
   5754 	 complain_overflow_signed, /* Complain_on_overflow.  */
   5755 	 reloc_nil,		/* Special_function.  */
   5756 	 "BRADDR",		/* Name.  */
   5757 	 true,			/* Partial_inplace.  */
   5758 	 0x1fffff,		/* Source mask.  */
   5759 	 0x1fffff,		/* Dest mask.  */
   5760 	 false),		/* PC rel offset.  */
   5761 
   5762   /* A hint for a jump to a register.  */
   5763   HOWTO (ALPHA_R_HINT,		/* Type.  */
   5764 	 2,			/* Rightshift.  */
   5765 	 2,			/* Size.  */
   5766 	 14,			/* Bitsize.  */
   5767 	 true,			/* PC relative.  */
   5768 	 0,			/* Bitpos.  */
   5769 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5770 	 reloc_nil,		/* Special_function.  */
   5771 	 "HINT",		/* Name.  */
   5772 	 true,			/* Partial_inplace.  */
   5773 	 0x3fff,		/* Source mask.  */
   5774 	 0x3fff,		/* Dest mask.  */
   5775 	 false),		/* PC rel offset.  */
   5776 
   5777   /* 16 bit PC relative offset.  */
   5778   HOWTO (ALPHA_R_SREL16,	/* Type.  */
   5779 	 0,			/* Rightshift.  */
   5780 	 2,			/* Size.  */
   5781 	 16,			/* Bitsize.  */
   5782 	 true,			/* PC relative.  */
   5783 	 0,			/* Bitpos.  */
   5784 	 complain_overflow_signed, /* Complain_on_overflow.  */
   5785 	 reloc_nil,		/* Special_function.  */
   5786 	 "SREL16",		/* Name.  */
   5787 	 true,			/* Partial_inplace.  */
   5788 	 0xffff,		/* Source mask.  */
   5789 	 0xffff,		/* Dest mask.  */
   5790 	 false),		/* PC rel offset.  */
   5791 
   5792   /* 32 bit PC relative offset.  */
   5793   HOWTO (ALPHA_R_SREL32,	/* Type.  */
   5794 	 0,			/* Rightshift.  */
   5795 	 4,			/* Size.  */
   5796 	 32,			/* Bitsize.  */
   5797 	 true,			/* PC relative.  */
   5798 	 0,			/* Bitpos.  */
   5799 	 complain_overflow_signed, /* Complain_on_overflow.  */
   5800 	 reloc_nil,		/* Special_function.  */
   5801 	 "SREL32",		/* Name.  */
   5802 	 true,			/* Partial_inplace.  */
   5803 	 0xffffffff,		/* Source mask.  */
   5804 	 0xffffffff,		/* Dest mask.  */
   5805 	 false),		/* PC rel offset.  */
   5806 
   5807   /* A 64 bit PC relative offset.  */
   5808   HOWTO (ALPHA_R_SREL64,	/* Type.  */
   5809 	 0,			/* Rightshift.  */
   5810 	 8,			/* Size.  */
   5811 	 64,			/* Bitsize.  */
   5812 	 true,			/* PC relative.  */
   5813 	 0,			/* Bitpos.  */
   5814 	 complain_overflow_signed, /* Complain_on_overflow.  */
   5815 	 reloc_nil,		/* Special_function.  */
   5816 	 "SREL64",		/* Name.  */
   5817 	 true,			/* Partial_inplace.  */
   5818 	 MINUS_ONE,		/* Source mask.  */
   5819 	 MINUS_ONE,		/* Dest mask.  */
   5820 	 false),		/* PC rel offset.  */
   5821 
   5822   /* Push a value on the reloc evaluation stack.  */
   5823   HOWTO (ALPHA_R_OP_PUSH,	/* Type.  */
   5824 	 0,			/* Rightshift.  */
   5825 	 0,			/* Size.  */
   5826 	 0,			/* Bitsize.  */
   5827 	 false,			/* PC relative.  */
   5828 	 0,			/* Bitpos.  */
   5829 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5830 	 reloc_nil,		/* Special_function.  */
   5831 	 "OP_PUSH",		/* Name.  */
   5832 	 false,			/* Partial_inplace.  */
   5833 	 0,			/* Source mask.  */
   5834 	 0,			/* Dest mask.  */
   5835 	 false),		/* PC rel offset.  */
   5836 
   5837   /* Store the value from the stack at the given address.  Store it in
   5838      a bitfield of size r_size starting at bit position r_offset.  */
   5839   HOWTO (ALPHA_R_OP_STORE,	/* Type.  */
   5840 	 0,			/* Rightshift.  */
   5841 	 8,			/* Size.  */
   5842 	 64,			/* Bitsize.  */
   5843 	 false,			/* PC relative.  */
   5844 	 0,			/* Bitpos.  */
   5845 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5846 	 reloc_nil,		/* Special_function.  */
   5847 	 "OP_STORE",		/* Name.  */
   5848 	 false,			/* Partial_inplace.  */
   5849 	 0,			/* Source mask.  */
   5850 	 MINUS_ONE,		/* Dest mask.  */
   5851 	 false),		/* PC rel offset.  */
   5852 
   5853   /* Subtract the reloc address from the value on the top of the
   5854      relocation stack.  */
   5855   HOWTO (ALPHA_R_OP_PSUB,	/* Type.  */
   5856 	 0,			/* Rightshift.  */
   5857 	 0,			/* Size.  */
   5858 	 0,			/* Bitsize.  */
   5859 	 false,			/* PC relative.  */
   5860 	 0,			/* Bitpos.  */
   5861 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5862 	 reloc_nil,		/* Special_function.  */
   5863 	 "OP_PSUB",		/* Name.  */
   5864 	 false,			/* Partial_inplace.  */
   5865 	 0,			/* Source mask.  */
   5866 	 0,			/* Dest mask.  */
   5867 	 false),		/* PC rel offset.  */
   5868 
   5869   /* Shift the value on the top of the relocation stack right by the
   5870      given value.  */
   5871   HOWTO (ALPHA_R_OP_PRSHIFT,	/* Type.  */
   5872 	 0,			/* Rightshift.  */
   5873 	 0,			/* Size.  */
   5874 	 0,			/* Bitsize.  */
   5875 	 false,			/* PC relative.  */
   5876 	 0,			/* Bitpos.  */
   5877 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5878 	 reloc_nil,		/* Special_function.  */
   5879 	 "OP_PRSHIFT",		/* Name.  */
   5880 	 false,			/* Partial_inplace.  */
   5881 	 0,			/* Source mask.  */
   5882 	 0,			/* Dest mask.  */
   5883 	 false),		/* PC rel offset.  */
   5884 
   5885   /* Hack. Linkage is done by linker.  */
   5886   HOWTO (ALPHA_R_LINKAGE,	/* Type.  */
   5887 	 0,			/* Rightshift.  */
   5888 	 0,			/* Size.  */
   5889 	 0,			/* Bitsize.  */
   5890 	 false,			/* PC relative.  */
   5891 	 0,			/* Bitpos.  */
   5892 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5893 	 reloc_nil,		/* Special_function.  */
   5894 	 "LINKAGE",		/* Name.  */
   5895 	 false,			/* Partial_inplace.  */
   5896 	 0,			/* Source mask.  */
   5897 	 0,			/* Dest mask.  */
   5898 	 false),		/* PC rel offset.  */
   5899 
   5900   /* A 32 bit reference to a symbol.  */
   5901   HOWTO (ALPHA_R_REFLONG,	/* Type.  */
   5902 	 0,			/* Rightshift.  */
   5903 	 4,			/* Size.  */
   5904 	 32,			/* Bitsize.  */
   5905 	 false,			/* PC relative.  */
   5906 	 0,			/* Bitpos.  */
   5907 	 complain_overflow_bitfield, /* Complain_on_overflow.  */
   5908 	 reloc_nil,		/* Special_function.  */
   5909 	 "REFLONG",		/* Name.  */
   5910 	 true,			/* Partial_inplace.  */
   5911 	 0xffffffff,		/* Source mask.  */
   5912 	 0xffffffff,		/* Dest mask.  */
   5913 	 false),		/* PC rel offset.  */
   5914 
   5915   /* A 64 bit reference to a procedure, written as 32 bit value.  */
   5916   HOWTO (ALPHA_R_CODEADDR,	/* Type.  */
   5917 	 0,			/* Rightshift.  */
   5918 	 8,			/* Size.  */
   5919 	 64,			/* Bitsize.  */
   5920 	 false,			/* PC relative.  */
   5921 	 0,			/* Bitpos.  */
   5922 	 complain_overflow_signed,/* Complain_on_overflow.  */
   5923 	 reloc_nil,		/* Special_function.  */
   5924 	 "CODEADDR",		/* Name.  */
   5925 	 false,			/* Partial_inplace.  */
   5926 	 0xffffffff,		/* Source mask.  */
   5927 	 0xffffffff,		/* Dest mask.  */
   5928 	 false),		/* PC rel offset.  */
   5929 
   5930   HOWTO (ALPHA_R_NOP,		/* Type.  */
   5931 	 0,			/* Rightshift.  */
   5932 	 0,			/* Size.  */
   5933 	 0,			/* Bitsize.  */
   5934 	 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
   5935 	    because the calculations for the 3 relocations are the same.
   5936 	    See B.4.5.2 of the OpenVMS Linker Utility Manual.  */
   5937 	 true,			/* PC relative.  */
   5938 	 0,			/* Bitpos.   */
   5939 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5940 	 reloc_nil,		/* Special_function.  */
   5941 	 "NOP",			/* Name.  */
   5942 	 false,			/* Partial_inplace.  */
   5943 	 0xffffffff,		/* Source mask.  */
   5944 	 0xffffffff,		/* Dest mask.  */
   5945 	 false),		/* PC rel offset.  */
   5946 
   5947   HOWTO (ALPHA_R_BSR,		/* Type.  */
   5948 	 0,			/* Rightshift.  */
   5949 	 0,			/* Size.  */
   5950 	 0,			/* Bitsize.  */
   5951 	 true,			/* PC relative.  */
   5952 	 0,			/* Bitpos.  */
   5953 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5954 	 reloc_nil,		/* Special_function.  */
   5955 	 "BSR",			/* Name.  */
   5956 	 false,			/* Partial_inplace.  */
   5957 	 0xffffffff,		/* Source mask.  */
   5958 	 0xffffffff,		/* Dest mask.  */
   5959 	 false),		/* PC rel offset.  */
   5960 
   5961   HOWTO (ALPHA_R_LDA,		/* Type.  */
   5962 	 0,			/* Rightshift.  */
   5963 	 0,			/* Size.  */
   5964 	 0,			/* Bitsize.  */
   5965 	 false,			/* PC relative.  */
   5966 	 0,			/* Bitpos.  */
   5967 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5968 	 reloc_nil,		/* Special_function.  */
   5969 	 "LDA",			/* Name.  */
   5970 	 false,			/* Partial_inplace.  */
   5971 	 0xffffffff,		/* Source mask.  */
   5972 	 0xffffffff,		/* Dest mask.  */
   5973 	 false),		/* PC rel offset.  */
   5974 
   5975   HOWTO (ALPHA_R_BOH,		/* Type.  */
   5976 	 0,			/* Rightshift.  */
   5977 	 0,			/* Size.  */
   5978 	 0,			/* Bitsize.  */
   5979 	 true,			/* PC relative.  */
   5980 	 0,			/* Bitpos.  */
   5981 	 complain_overflow_dont,/* Complain_on_overflow.  */
   5982 	 reloc_nil,		/* Special_function.  */
   5983 	 "BOH",			/* Name.  */
   5984 	 false,			/* Partial_inplace.  */
   5985 	 0xffffffff,		/* Source mask.  */
   5986 	 0xffffffff,		/* Dest mask.  */
   5987 	 false),		/* PC rel offset.  */
   5988 };
   5989 
   5990 /* Return a pointer to a howto structure which, when invoked, will perform
   5991    the relocation code on data from the architecture noted.  */
   5992 
   5993 static reloc_howto_type *
   5994 alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
   5995 				 bfd_reloc_code_real_type code)
   5996 {
   5997   int alpha_type;
   5998 
   5999   vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code));
   6000 
   6001   switch (code)
   6002     {
   6003       case BFD_RELOC_16:		alpha_type = ALPHA_R_SREL16;	break;
   6004       case BFD_RELOC_32:		alpha_type = ALPHA_R_REFLONG;	break;
   6005       case BFD_RELOC_64:		alpha_type = ALPHA_R_REFQUAD;	break;
   6006       case BFD_RELOC_CTOR:		alpha_type = ALPHA_R_REFQUAD;	break;
   6007       case BFD_RELOC_23_PCREL_S2:	alpha_type = ALPHA_R_BRADDR;	break;
   6008       case BFD_RELOC_ALPHA_HINT:	alpha_type = ALPHA_R_HINT;	break;
   6009       case BFD_RELOC_16_PCREL:		alpha_type = ALPHA_R_SREL16;	break;
   6010       case BFD_RELOC_32_PCREL:		alpha_type = ALPHA_R_SREL32;	break;
   6011       case BFD_RELOC_64_PCREL:		alpha_type = ALPHA_R_SREL64;	break;
   6012       case BFD_RELOC_ALPHA_LINKAGE:	alpha_type = ALPHA_R_LINKAGE;	break;
   6013       case BFD_RELOC_ALPHA_CODEADDR:	alpha_type = ALPHA_R_CODEADDR;	break;
   6014       case BFD_RELOC_ALPHA_NOP:		alpha_type = ALPHA_R_NOP;	break;
   6015       case BFD_RELOC_ALPHA_BSR:		alpha_type = ALPHA_R_BSR;	break;
   6016       case BFD_RELOC_ALPHA_LDA:		alpha_type = ALPHA_R_LDA;	break;
   6017       case BFD_RELOC_ALPHA_BOH:		alpha_type = ALPHA_R_BOH;	break;
   6018       default:
   6019 	_bfd_error_handler (_("reloc (%d) is *UNKNOWN*"), code);
   6020 	return NULL;
   6021     }
   6022   vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name));
   6023   return & alpha_howto_table[alpha_type];
   6024 }
   6025 
   6026 static reloc_howto_type *
   6027 alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   6028 				 const char *r_name)
   6029 {
   6030   unsigned int i;
   6031 
   6032   for (i = 0;
   6033        i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
   6034        i++)
   6035     if (alpha_howto_table[i].name != NULL
   6036 	&& strcasecmp (alpha_howto_table[i].name, r_name) == 0)
   6037       return &alpha_howto_table[i];
   6038 
   6039   return NULL;
   6040 }
   6041 
   6042 static long
   6044 alpha_vms_get_synthetic_symtab (bfd *abfd,
   6045 				long symcount ATTRIBUTE_UNUSED,
   6046 				asymbol **usyms ATTRIBUTE_UNUSED,
   6047 				long dynsymcount ATTRIBUTE_UNUSED,
   6048 				asymbol **dynsyms ATTRIBUTE_UNUSED,
   6049 				asymbol **ret)
   6050 {
   6051   asymbol *syms;
   6052   unsigned int i;
   6053   unsigned int n = 0;
   6054 
   6055   syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
   6056   *ret = syms;
   6057   if (syms == NULL)
   6058     return -1;
   6059 
   6060   for (i = 0; i < PRIV (gsd_sym_count); i++)
   6061     {
   6062       struct vms_symbol_entry *e = PRIV (syms)[i];
   6063       asymbol *sym;
   6064       flagword flags;
   6065       symvalue value;
   6066       asection *sec;
   6067       const char *name;
   6068       char *sname;
   6069       int l;
   6070 
   6071       name = e->name;
   6072       value = 0;
   6073       flags = BSF_LOCAL | BSF_SYNTHETIC;
   6074       sec = NULL;
   6075 
   6076       switch (e->typ)
   6077 	{
   6078 	case EGSD__C_SYM:
   6079 	case EGSD__C_SYMG:
   6080 	  if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM))
   6081 	    {
   6082 	      value = e->code_value;
   6083 	      sec = e->code_section;
   6084 	    }
   6085 	  else
   6086 	    continue;
   6087 	  break;
   6088 
   6089 	default:
   6090 	  continue;
   6091 	}
   6092 
   6093       l = strlen (name);
   6094       sname = bfd_alloc (abfd, l + 5);
   6095       if (sname == NULL)
   6096 	return false;
   6097       memcpy (sname, name, l);
   6098       memcpy (sname + l, "..en", 5);
   6099 
   6100       sym = &syms[n++];
   6101       sym->name = sname;
   6102       sym->section = sec;
   6103       sym->flags = flags;
   6104       sym->value = value;
   6105       sym->udata.p = NULL;
   6106     }
   6107 
   6108   return n;
   6109 }
   6110 
   6111 /* Private dump.  */
   6113 
   6114 static const char *
   6115 vms_time_to_str (unsigned char *buf)
   6116 {
   6117   time_t t = vms_rawtime_to_time_t (buf);
   6118   char *res = ctime (&t);
   6119 
   6120   if (!res)
   6121     res = "*invalid time*";
   6122   else
   6123     res[24] = 0;
   6124   return res;
   6125 }
   6126 
   6127 static void
   6128 evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len)
   6129 {
   6130   struct vms_emh_common *emh = (struct vms_emh_common *)rec;
   6131   int subtype = -1;
   6132   int extra;
   6133 
   6134   if (rec_len >= sizeof (*emh))
   6135     subtype = bfd_getl16 (emh->subtyp);
   6136 
   6137   /* xgettext:c-format */
   6138   fprintf (file, _("  EMH %d (len=%u): "), subtype, rec_len);
   6139 
   6140   /* PR 21618: Check for invalid lengths.  */
   6141   if (rec_len < sizeof (*emh))
   6142     {
   6143       fprintf (file, _("   Error: %s min length is %u\n"),
   6144 	       "EMH", (unsigned) sizeof (*emh));
   6145       return;
   6146     }
   6147 
   6148   extra = rec_len - sizeof (struct vms_emh_common);
   6149 
   6150   switch (subtype)
   6151     {
   6152     case EMH__C_MHD:
   6153       {
   6154 	struct vms_emh_mhd *mhd = (struct vms_emh_mhd *) rec;
   6155 	unsigned char *name;
   6156 	unsigned char *nextname;
   6157 	unsigned char *maxname;
   6158 
   6159 	/* PR 21840: Check for invalid lengths.  */
   6160 	if (rec_len < sizeof (* mhd))
   6161 	  {
   6162 	    fprintf (file, _("   Error: %s min length is %u\n"),
   6163 		     "EMH_MHD", (unsigned) sizeof (*mhd));
   6164 	    return;
   6165 	  }
   6166 	fprintf (file, _("Module header\n"));
   6167 	fprintf (file, _("   structure level: %u\n"), mhd->strlvl);
   6168 	fprintf (file, _("   max record size: %u\n"),
   6169 		 (unsigned) bfd_getl32 (mhd->recsiz));
   6170 	name = (unsigned char *) (mhd + 1);
   6171 	maxname = (unsigned char *) rec + rec_len;
   6172 	if (name > maxname - 2)
   6173 	  {
   6174 	    fprintf (file, _("   Error: The module name is missing\n"));
   6175 	    return;
   6176 	  }
   6177 	nextname = name + name[0] + 1;
   6178 	if (nextname >= maxname)
   6179 	  {
   6180 	    fprintf (file, _("   Error: The module name is too long\n"));
   6181 	    return;
   6182 	  }
   6183 	fprintf (file, _("   module name    : %.*s\n"), name[0], name + 1);
   6184 	name = nextname;
   6185 	if (name > maxname - 2)
   6186 	  {
   6187 	    fprintf (file, _("   Error: The module version is missing\n"));
   6188 	    return;
   6189 	  }
   6190 	nextname = name + name[0] + 1;
   6191 	if (nextname >= maxname)
   6192 	  {
   6193 	    fprintf (file, _("   Error: The module version is too long\n"));
   6194 	    return;
   6195 	  }
   6196 	fprintf (file, _("   module version : %.*s\n"), name[0], name + 1);
   6197 	name = nextname;
   6198 	if ((maxname - name) < 17 && maxname[-1] != 0)
   6199 	  fprintf (file, _("   Error: The compile date is truncated\n"));
   6200 	else
   6201 	  fprintf (file, _("   compile date   : %.17s\n"), name);
   6202       }
   6203       break;
   6204 
   6205     case EMH__C_LNM:
   6206       fprintf (file, _("Language Processor Name\n"));
   6207       fprintf (file, _("   language name: %.*s\n"), extra, (char *)(emh + 1));
   6208       break;
   6209 
   6210     case EMH__C_SRC:
   6211       fprintf (file, _("Source Files Header\n"));
   6212       fprintf (file, _("   file: %.*s\n"), extra, (char *)(emh + 1));
   6213       break;
   6214 
   6215     case EMH__C_TTL:
   6216       fprintf (file, _("Title Text Header\n"));
   6217       fprintf (file, _("   title: %.*s\n"), extra, (char *)(emh + 1));
   6218       break;
   6219 
   6220     case EMH__C_CPR:
   6221       fprintf (file, _("Copyright Header\n"));
   6222       fprintf (file, _("   copyright: %.*s\n"), extra, (char *)(emh + 1));
   6223       break;
   6224 
   6225     default:
   6226       fprintf (file, _("unhandled emh subtype %u\n"), subtype);
   6227       break;
   6228     }
   6229 }
   6230 
   6231 static void
   6232 evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len)
   6233 {
   6234   struct vms_eeom *eeom = (struct vms_eeom *)rec;
   6235 
   6236   fprintf (file, _("  EEOM (len=%u):\n"), rec_len);
   6237 
   6238   /* PR 21618: Check for invalid lengths.  */
   6239   if (rec_len < 10)
   6240     {
   6241       fprintf (file, _("   Error: %s min length is %u\n"),
   6242 	       "EEOM", 10);
   6243       return;
   6244     }
   6245 
   6246   fprintf (file, _("   number of cond linkage pairs: %u\n"),
   6247 	   (unsigned)bfd_getl32 (eeom->total_lps));
   6248   fprintf (file, _("   completion code: %u\n"),
   6249 	   (unsigned)bfd_getl16 (eeom->comcod));
   6250 
   6251   if (rec_len >= sizeof (*eeom))
   6252     {
   6253       fprintf (file, _("   transfer addr flags: 0x%02x\n"), eeom->tfrflg);
   6254       fprintf (file, _("   transfer addr psect: %u\n"),
   6255 	       (unsigned)bfd_getl32 (eeom->psindx));
   6256       fprintf (file, _("   transfer address   : 0x%08x\n"),
   6257 	       (unsigned)bfd_getl32 (eeom->tfradr));
   6258     }
   6259 }
   6260 
   6261 static void
   6262 exav_bfd_print_egsy_flags (unsigned int flags, FILE *file)
   6263 {
   6264   if (flags & EGSY__V_WEAK)
   6265     fputs (_(" WEAK"), file);
   6266   if (flags & EGSY__V_DEF)
   6267     fputs (_(" DEF"), file);
   6268   if (flags & EGSY__V_UNI)
   6269     fputs (_(" UNI"), file);
   6270   if (flags & EGSY__V_REL)
   6271     fputs (_(" REL"), file);
   6272   if (flags & EGSY__V_COMM)
   6273     fputs (_(" COMM"), file);
   6274   if (flags & EGSY__V_VECEP)
   6275     fputs (_(" VECEP"), file);
   6276   if (flags & EGSY__V_NORM)
   6277     fputs (_(" NORM"), file);
   6278   if (flags & EGSY__V_QUAD_VAL)
   6279     fputs (_(" QVAL"), file);
   6280 }
   6281 
   6282 static void
   6283 evax_bfd_print_egsd_flags (FILE *file, unsigned int flags)
   6284 {
   6285   if (flags & EGPS__V_PIC)
   6286     fputs (_(" PIC"), file);
   6287   if (flags & EGPS__V_LIB)
   6288     fputs (_(" LIB"), file);
   6289   if (flags & EGPS__V_OVR)
   6290     fputs (_(" OVR"), file);
   6291   if (flags & EGPS__V_REL)
   6292     fputs (_(" REL"), file);
   6293   if (flags & EGPS__V_GBL)
   6294     fputs (_(" GBL"), file);
   6295   if (flags & EGPS__V_SHR)
   6296     fputs (_(" SHR"), file);
   6297   if (flags & EGPS__V_EXE)
   6298     fputs (_(" EXE"), file);
   6299   if (flags & EGPS__V_RD)
   6300     fputs (_(" RD"), file);
   6301   if (flags & EGPS__V_WRT)
   6302     fputs (_(" WRT"), file);
   6303   if (flags & EGPS__V_VEC)
   6304     fputs (_(" VEC"), file);
   6305   if (flags & EGPS__V_NOMOD)
   6306     fputs (_(" NOMOD"), file);
   6307   if (flags & EGPS__V_COM)
   6308     fputs (_(" COM"), file);
   6309   if (flags & EGPS__V_ALLOC_64BIT)
   6310     fputs (_(" 64B"), file);
   6311 }
   6312 
   6313 static void
   6314 evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len)
   6315 {
   6316   unsigned int off = sizeof (struct vms_egsd);
   6317   unsigned int n = 0;
   6318 
   6319   fprintf (file, _("  EGSD (len=%u):\n"), rec_len);
   6320   if (rec_len < sizeof (struct vms_egsd) + sizeof (struct vms_egsd_entry))
   6321     return;
   6322 
   6323   while (off <= rec_len - sizeof (struct vms_egsd_entry))
   6324     {
   6325       struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off);
   6326       unsigned int type;
   6327       unsigned int len;
   6328       unsigned int rest;
   6329 
   6330       type = (unsigned)bfd_getl16 (e->gsdtyp);
   6331       len = (unsigned)bfd_getl16 (e->gsdsiz);
   6332 
   6333       /* xgettext:c-format */
   6334       fprintf (file, _("  EGSD entry %2u (type: %u, len: %u): "),
   6335 	       n, type, len);
   6336       n++;
   6337 
   6338       if (len < sizeof (struct vms_egsd_entry) || len > rec_len - off)
   6339 	{
   6340 	  fprintf (file, _("   Erroneous length\n"));
   6341 	  return;
   6342 	}
   6343 
   6344       switch (type)
   6345 	{
   6346 	case EGSD__C_PSC:
   6347 	  if (len >= offsetof (struct vms_egps, name))
   6348 	    {
   6349 	      struct vms_egps *egps = (struct vms_egps *) e;
   6350 	      unsigned int flags = bfd_getl16 (egps->flags);
   6351 	      unsigned int l;
   6352 
   6353 	      fprintf (file, _("PSC - Program section definition\n"));
   6354 	      fprintf (file, _("   alignment  : 2**%u\n"), egps->align);
   6355 	      fprintf (file, _("   flags      : 0x%04x"), flags);
   6356 	      evax_bfd_print_egsd_flags (file, flags);
   6357 	      fputc ('\n', file);
   6358 	      l = bfd_getl32 (egps->alloc);
   6359 	      fprintf (file, _("   alloc (len): %u (0x%08x)\n"), l, l);
   6360 	      rest = len - offsetof (struct vms_egps, name);
   6361 	      fprintf (file, _("   name       : %.*s\n"),
   6362 		       egps->namlng > rest ? rest : egps->namlng,
   6363 		       egps->name);
   6364 	    }
   6365 	  break;
   6366 	case EGSD__C_SPSC:
   6367 	  if (len >= offsetof (struct vms_esgps, name))
   6368 	    {
   6369 	      struct vms_esgps *esgps = (struct vms_esgps *) e;
   6370 	      unsigned int flags = bfd_getl16 (esgps->flags);
   6371 	      unsigned int l;
   6372 
   6373 	      fprintf (file, _("SPSC - Shared Image Program section def\n"));
   6374 	      fprintf (file, _("   alignment  : 2**%u\n"), esgps->align);
   6375 	      fprintf (file, _("   flags      : 0x%04x"), flags);
   6376 	      evax_bfd_print_egsd_flags (file, flags);
   6377 	      fputc ('\n', file);
   6378 	      l = bfd_getl32 (esgps->alloc);
   6379 	      fprintf (file, _("   alloc (len)   : %u (0x%08x)\n"), l, l);
   6380 	      fprintf (file, _("   image offset  : 0x%08x\n"),
   6381 		       (unsigned int) bfd_getl32 (esgps->base));
   6382 	      fprintf (file, _("   symvec offset : 0x%08x\n"),
   6383 		       (unsigned int) bfd_getl32 (esgps->value));
   6384 	      rest = len - offsetof (struct vms_esgps, name);
   6385 	      fprintf (file, _("   name          : %.*s\n"),
   6386 		       esgps->namlng > rest ? rest : esgps->namlng,
   6387 		       esgps->name);
   6388 	    }
   6389 	  break;
   6390 	case EGSD__C_SYM:
   6391 	  if (len >= sizeof (struct vms_egsy))
   6392 	    {
   6393 	      struct vms_egsy *egsy = (struct vms_egsy *) e;
   6394 	      unsigned int flags = bfd_getl16 (egsy->flags);
   6395 
   6396 	      if ((flags & EGSY__V_DEF) != 0
   6397 		  && len >= offsetof (struct vms_esdf, name))
   6398 		{
   6399 		  struct vms_esdf *esdf = (struct vms_esdf *) e;
   6400 
   6401 		  fprintf (file, _("SYM - Global symbol definition\n"));
   6402 		  fprintf (file, _("   flags: 0x%04x"), flags);
   6403 		  exav_bfd_print_egsy_flags (flags, file);
   6404 		  fputc ('\n', file);
   6405 		  fprintf (file, _("   psect offset: 0x%08x\n"),
   6406 			   (unsigned) bfd_getl32 (esdf->value));
   6407 		  if (flags & EGSY__V_NORM)
   6408 		    {
   6409 		      fprintf (file, _("   code address: 0x%08x\n"),
   6410 			       (unsigned) bfd_getl32 (esdf->code_address));
   6411 		      fprintf (file, _("   psect index for entry point : %u\n"),
   6412 			       (unsigned) bfd_getl32 (esdf->ca_psindx));
   6413 		    }
   6414 		  fprintf (file, _("   psect index : %u\n"),
   6415 			   (unsigned) bfd_getl32 (esdf->psindx));
   6416 		  rest = len - offsetof (struct vms_esdf, name);
   6417 		  fprintf (file, _("   name        : %.*s\n"),
   6418 			   esdf->namlng > rest ? rest : esdf->namlng,
   6419 			   esdf->name);
   6420 		}
   6421 	      else if (len >= offsetof (struct vms_esrf, name))
   6422 		{
   6423 		  struct vms_esrf *esrf = (struct vms_esrf *)e;
   6424 
   6425 		  fprintf (file, _("SYM - Global symbol reference\n"));
   6426 		  rest = len - offsetof (struct vms_esrf, name);
   6427 		  fprintf (file, _("   name       : %.*s\n"),
   6428 			   esrf->namlng > rest ? rest : esrf->namlng,
   6429 			   esrf->name);
   6430 		}
   6431 	    }
   6432 	  break;
   6433 	case EGSD__C_IDC:
   6434 	  if (len >= sizeof (struct vms_eidc))
   6435 	    {
   6436 	      struct vms_eidc *eidc = (struct vms_eidc *) e;
   6437 	      unsigned int flags = bfd_getl32 (eidc->flags);
   6438 	      unsigned char *p;
   6439 
   6440 	      fprintf (file, _("IDC - Ident Consistency check\n"));
   6441 	      fprintf (file, _("   flags         : 0x%08x"), flags);
   6442 	      if (flags & EIDC__V_BINIDENT)
   6443 		fputs (" BINDENT", file);
   6444 	      fputc ('\n', file);
   6445 	      fprintf (file, _("   id match      : %x\n"),
   6446 		       (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK);
   6447 	      fprintf (file, _("   error severity: %x\n"),
   6448 		       (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK);
   6449 	      p = eidc->name;
   6450 	      rest = len - (p - (unsigned char *) e);
   6451 	      fprintf (file, _("   entity name   : %.*s\n"),
   6452 		       p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
   6453 	      if (rest > 1u + p[0])
   6454 		{
   6455 		  rest -= 1 + p[0];
   6456 		  p += 1 + p[0];
   6457 		  fprintf (file, _("   object name   : %.*s\n"),
   6458 			   p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
   6459 		  if (rest > 1u + p[0])
   6460 		    {
   6461 		      rest -= 1 + p[0];
   6462 		      p += 1 + p[0];
   6463 		      if (flags & EIDC__V_BINIDENT)
   6464 			{
   6465 			  if (rest >= 4)
   6466 			    fprintf (file, _("   binary ident  : 0x%08x\n"),
   6467 				     (unsigned) bfd_getl32 (p));
   6468 			}
   6469 		      else
   6470 			fprintf (file, _("   ascii ident   : %.*s\n"),
   6471 				 p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
   6472 		    }
   6473 		}
   6474 	    }
   6475 	  break;
   6476 	case EGSD__C_SYMG:
   6477 	  if (len >= offsetof (struct vms_egst, name))
   6478 	    {
   6479 	      struct vms_egst *egst = (struct vms_egst *) e;
   6480 	      unsigned int flags = bfd_getl16 (egst->header.flags);
   6481 
   6482 	      fprintf (file, _("SYMG - Universal symbol definition\n"));
   6483 	      fprintf (file, _("   flags: 0x%04x"), flags);
   6484 	      exav_bfd_print_egsy_flags (flags, file);
   6485 	      fputc ('\n', file);
   6486 	      fprintf (file, _("   symbol vector offset: 0x%08x\n"),
   6487 		       (unsigned) bfd_getl32 (egst->value));
   6488 	      fprintf (file, _("   entry point: 0x%08x\n"),
   6489 		       (unsigned) bfd_getl32 (egst->lp_1));
   6490 	      fprintf (file, _("   proc descr : 0x%08x\n"),
   6491 		       (unsigned) bfd_getl32 (egst->lp_2));
   6492 	      fprintf (file, _("   psect index: %u\n"),
   6493 		       (unsigned) bfd_getl32 (egst->psindx));
   6494 	      rest = len - offsetof (struct vms_egst, name);
   6495 	      fprintf (file, _("   name       : %.*s\n"),
   6496 		       egst->namlng > rest ? rest : egst->namlng,
   6497 		       egst->name);
   6498 	    }
   6499 	  break;
   6500 	case EGSD__C_SYMV:
   6501 	  if (len >= offsetof (struct vms_esdfv, name))
   6502 	    {
   6503 	      struct vms_esdfv *esdfv = (struct vms_esdfv *) e;
   6504 	      unsigned int flags = bfd_getl16 (esdfv->flags);
   6505 
   6506 	      fprintf (file, _("SYMV - Vectored symbol definition\n"));
   6507 	      fprintf (file, _("   flags: 0x%04x"), flags);
   6508 	      exav_bfd_print_egsy_flags (flags, file);
   6509 	      fputc ('\n', file);
   6510 	      fprintf (file, _("   vector      : 0x%08x\n"),
   6511 		       (unsigned) bfd_getl32 (esdfv->vector));
   6512 	      fprintf (file, _("   psect offset: %u\n"),
   6513 		       (unsigned) bfd_getl32 (esdfv->value));
   6514 	      fprintf (file, _("   psect index : %u\n"),
   6515 		       (unsigned) bfd_getl32 (esdfv->psindx));
   6516 	      rest = len - offsetof (struct vms_esdfv, name);
   6517 	      fprintf (file, _("   name        : %.*s\n"),
   6518 		       esdfv->namlng > rest ? rest : esdfv->namlng,
   6519 		       esdfv->name);
   6520 	    }
   6521 	  break;
   6522 	case EGSD__C_SYMM:
   6523 	  if (len >= offsetof (struct vms_esdfm, name))
   6524 	    {
   6525 	      struct vms_esdfm *esdfm = (struct vms_esdfm *) e;
   6526 	      unsigned int flags = bfd_getl16 (esdfm->flags);
   6527 
   6528 	      fprintf (file,
   6529 		       _("SYMM - Global symbol definition with version\n"));
   6530 	      fprintf (file, _("   flags: 0x%04x"), flags);
   6531 	      exav_bfd_print_egsy_flags (flags, file);
   6532 	      fputc ('\n', file);
   6533 	      fprintf (file, _("   version mask: 0x%08x\n"),
   6534 		       (unsigned)bfd_getl32 (esdfm->version_mask));
   6535 	      fprintf (file, _("   psect offset: %u\n"),
   6536 		       (unsigned)bfd_getl32 (esdfm->value));
   6537 	      fprintf (file, _("   psect index : %u\n"),
   6538 		       (unsigned)bfd_getl32 (esdfm->psindx));
   6539 	      rest = len - offsetof (struct vms_esdfm, name);
   6540 	      fprintf (file, _("   name        : %.*s\n"),
   6541 		       esdfm->namlng > rest ? rest : esdfm->namlng,
   6542 		       esdfm->name);
   6543 	    }
   6544 	  break;
   6545 	default:
   6546 	  fprintf (file, _("unhandled egsd entry type %u\n"), type);
   6547 	  break;
   6548 	}
   6549       off += len;
   6550     }
   6551 }
   6552 
   6553 static void
   6554 evax_bfd_print_hex (FILE *file, const char *pfx,
   6555 		    const unsigned char *buf, unsigned int len)
   6556 {
   6557   unsigned int i;
   6558   unsigned int n;
   6559 
   6560   n = 0;
   6561   for (i = 0; i < len; i++)
   6562     {
   6563       if (n == 0)
   6564 	fputs (pfx, file);
   6565       fprintf (file, " %02x", buf[i]);
   6566       n++;
   6567       if (n == 16)
   6568 	{
   6569 	  n = 0;
   6570 	  fputc ('\n', file);
   6571 	}
   6572     }
   6573   if (n != 0)
   6574     fputc ('\n', file);
   6575 }
   6576 
   6577 static void
   6578 evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf,
   6579 			    unsigned int len, int is_ps)
   6580 {
   6581   if (is_ps ? len < 44 : len < 33)
   6582     return;
   6583 
   6584   /* xgettext:c-format */
   6585   fprintf (file, _("    linkage index: %u, replacement insn: 0x%08x\n"),
   6586 	   (unsigned)bfd_getl32 (buf),
   6587 	   (unsigned)bfd_getl32 (buf + 16));
   6588   /* xgettext:c-format */
   6589   fprintf (file, _("    psect idx 1: %u, offset 1: 0x%08x %08x\n"),
   6590 	   (unsigned)bfd_getl32 (buf + 4),
   6591 	   (unsigned)bfd_getl32 (buf + 12),
   6592 	   (unsigned)bfd_getl32 (buf + 8));
   6593   /* xgettext:c-format */
   6594   fprintf (file, _("    psect idx 2: %u, offset 2: 0x%08x %08x\n"),
   6595 	   (unsigned)bfd_getl32 (buf + 20),
   6596 	   (unsigned)bfd_getl32 (buf + 28),
   6597 	   (unsigned)bfd_getl32 (buf + 24));
   6598   if (is_ps)
   6599     /* xgettext:c-format */
   6600     fprintf (file, _("    psect idx 3: %u, offset 3: 0x%08x %08x\n"),
   6601 	     (unsigned)bfd_getl32 (buf + 32),
   6602 	     (unsigned)bfd_getl32 (buf + 40),
   6603 	     (unsigned)bfd_getl32 (buf + 36));
   6604   else
   6605     fprintf (file, _("    global name: %.*s\n"),
   6606 	     buf[32] > len - 33 ? len - 33 : buf[32],
   6607 	     buf + 33);
   6608 }
   6609 
   6610 static void
   6611 evax_bfd_print_etir (FILE *file, const char *name,
   6612 		     unsigned char *rec, unsigned int rec_len)
   6613 {
   6614   unsigned int off = sizeof (struct vms_eobjrec);
   6615 
   6616   /* xgettext:c-format */
   6617   fprintf (file, _("  %s (len=%u):\n"), name, (unsigned) rec_len);
   6618   if (rec_len < sizeof (struct vms_eobjrec) + sizeof (struct vms_etir))
   6619     return;
   6620 
   6621   while (off <= rec_len - sizeof (struct vms_etir))
   6622     {
   6623       struct vms_etir *etir = (struct vms_etir *)(rec + off);
   6624       unsigned char *buf;
   6625       unsigned int type;
   6626       unsigned int size;
   6627       unsigned int rest;
   6628 
   6629       type = bfd_getl16 (etir->rectyp);
   6630       size = bfd_getl16 (etir->size);
   6631       buf = rec + off + sizeof (struct vms_etir);
   6632 
   6633       if (size < sizeof (struct vms_etir) || size > rec_len - off)
   6634 	{
   6635 	  fprintf (file, _("   Erroneous length\n"));
   6636 	  return;
   6637 	}
   6638 
   6639       /* xgettext:c-format */
   6640       fprintf (file, _("   (type: %3u, size: %3u): "), type, size);
   6641       rest = size - sizeof (struct vms_etir);
   6642       switch (type)
   6643 	{
   6644 	case ETIR__C_STA_GBL:
   6645 	  if (rest >= 1)
   6646 	    fprintf (file, _("STA_GBL (stack global) %.*s\n"),
   6647 		     buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
   6648 	  break;
   6649 	case ETIR__C_STA_LW:
   6650 	  fprintf (file, _("STA_LW (stack longword)"));
   6651 	  if (rest >= 4)
   6652 	    fprintf (file, " 0x%08x\n",
   6653 		     (unsigned) bfd_getl32 (buf));
   6654 	  break;
   6655 	case ETIR__C_STA_QW:
   6656 	  fprintf (file, _("STA_QW (stack quadword)"));
   6657 	  if (rest >= 8)
   6658 	    fprintf (file, " 0x%08x %08x\n",
   6659 		     (unsigned) bfd_getl32 (buf + 4),
   6660 		     (unsigned) bfd_getl32 (buf + 0));
   6661 	  break;
   6662 	case ETIR__C_STA_PQ:
   6663 	  fprintf (file, _("STA_PQ (stack psect base + offset)\n"));
   6664 	  if (rest >= 12)
   6665 	    /* xgettext:c-format */
   6666 	    fprintf (file, _("    psect: %u, offset: 0x%08x %08x\n"),
   6667 		     (unsigned) bfd_getl32 (buf + 0),
   6668 		     (unsigned) bfd_getl32 (buf + 8),
   6669 		     (unsigned) bfd_getl32 (buf + 4));
   6670 	  break;
   6671 	case ETIR__C_STA_LI:
   6672 	  fprintf (file, _("STA_LI (stack literal)\n"));
   6673 	  break;
   6674 	case ETIR__C_STA_MOD:
   6675 	  fprintf (file, _("STA_MOD (stack module)\n"));
   6676 	  break;
   6677 	case ETIR__C_STA_CKARG:
   6678 	  fprintf (file, _("STA_CKARG (compare procedure argument)\n"));
   6679 	  break;
   6680 
   6681 	case ETIR__C_STO_B:
   6682 	  fprintf (file, _("STO_B (store byte)\n"));
   6683 	  break;
   6684 	case ETIR__C_STO_W:
   6685 	  fprintf (file, _("STO_W (store word)\n"));
   6686 	  break;
   6687 	case ETIR__C_STO_LW:
   6688 	  fprintf (file, _("STO_LW (store longword)\n"));
   6689 	  break;
   6690 	case ETIR__C_STO_QW:
   6691 	  fprintf (file, _("STO_QW (store quadword)\n"));
   6692 	  break;
   6693 	case ETIR__C_STO_IMMR:
   6694 	  if (rest >= 4)
   6695 	    {
   6696 	      unsigned int rpt = bfd_getl32 (buf);
   6697 	      fprintf (file,
   6698 		       _("STO_IMMR (store immediate repeat) %u bytes\n"),
   6699 		       rpt);
   6700 	      if (rpt > rest - 4)
   6701 		rpt = rest - 4;
   6702 	      evax_bfd_print_hex (file, "   ", buf + 4, rpt);
   6703 	    }
   6704 	  break;
   6705 	case ETIR__C_STO_GBL:
   6706 	  if (rest >= 1)
   6707 	    fprintf (file, _("STO_GBL (store global) %.*s\n"),
   6708 		     buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
   6709 	  break;
   6710 	case ETIR__C_STO_CA:
   6711 	  if (rest >= 1)
   6712 	    fprintf (file, _("STO_CA (store code address) %.*s\n"),
   6713 		     buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
   6714 	  break;
   6715 	case ETIR__C_STO_RB:
   6716 	  fprintf (file, _("STO_RB (store relative branch)\n"));
   6717 	  break;
   6718 	case ETIR__C_STO_AB:
   6719 	  fprintf (file, _("STO_AB (store absolute branch)\n"));
   6720 	  break;
   6721 	case ETIR__C_STO_OFF:
   6722 	  fprintf (file, _("STO_OFF (store offset to psect)\n"));
   6723 	  break;
   6724 	case ETIR__C_STO_IMM:
   6725 	  if (rest >= 4)
   6726 	    {
   6727 	      unsigned int rpt = bfd_getl32 (buf);
   6728 	      fprintf (file,
   6729 		       _("STO_IMM (store immediate) %u bytes\n"),
   6730 		       rpt);
   6731 	      if (rpt > rest - 4)
   6732 		rpt = rest - 4;
   6733 	      evax_bfd_print_hex (file, "   ", buf + 4, rpt);
   6734 	    }
   6735 	  break;
   6736 	case ETIR__C_STO_GBL_LW:
   6737 	  if (rest >= 1)
   6738 	    fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"),
   6739 		     buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
   6740 	  break;
   6741 	case ETIR__C_STO_LP_PSB:
   6742 	  fprintf (file, _("STO_OFF (store LP with procedure signature)\n"));
   6743 	  break;
   6744 	case ETIR__C_STO_HINT_GBL:
   6745 	  fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n"));
   6746 	  break;
   6747 	case ETIR__C_STO_HINT_PS:
   6748 	  fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n"));
   6749 	  break;
   6750 
   6751 	case ETIR__C_OPR_NOP:
   6752 	  fprintf (file, _("OPR_NOP (no-operation)\n"));
   6753 	  break;
   6754 	case ETIR__C_OPR_ADD:
   6755 	  fprintf (file, _("OPR_ADD (add)\n"));
   6756 	  break;
   6757 	case ETIR__C_OPR_SUB:
   6758 	  fprintf (file, _("OPR_SUB (subtract)\n"));
   6759 	  break;
   6760 	case ETIR__C_OPR_MUL:
   6761 	  fprintf (file, _("OPR_MUL (multiply)\n"));
   6762 	  break;
   6763 	case ETIR__C_OPR_DIV:
   6764 	  fprintf (file, _("OPR_DIV (divide)\n"));
   6765 	  break;
   6766 	case ETIR__C_OPR_AND:
   6767 	  fprintf (file, _("OPR_AND (logical and)\n"));
   6768 	  break;
   6769 	case ETIR__C_OPR_IOR:
   6770 	  fprintf (file, _("OPR_IOR (logical inclusive or)\n"));
   6771 	  break;
   6772 	case ETIR__C_OPR_EOR:
   6773 	  fprintf (file, _("OPR_EOR (logical exclusive or)\n"));
   6774 	  break;
   6775 	case ETIR__C_OPR_NEG:
   6776 	  fprintf (file, _("OPR_NEG (negate)\n"));
   6777 	  break;
   6778 	case ETIR__C_OPR_COM:
   6779 	  fprintf (file, _("OPR_COM (complement)\n"));
   6780 	  break;
   6781 	case ETIR__C_OPR_INSV:
   6782 	  fprintf (file, _("OPR_INSV (insert field)\n"));
   6783 	  break;
   6784 	case ETIR__C_OPR_ASH:
   6785 	  fprintf (file, _("OPR_ASH (arithmetic shift)\n"));
   6786 	  break;
   6787 	case ETIR__C_OPR_USH:
   6788 	  fprintf (file, _("OPR_USH (unsigned shift)\n"));
   6789 	  break;
   6790 	case ETIR__C_OPR_ROT:
   6791 	  fprintf (file, _("OPR_ROT (rotate)\n"));
   6792 	  break;
   6793 	case ETIR__C_OPR_SEL:
   6794 	  fprintf (file, _("OPR_SEL (select)\n"));
   6795 	  break;
   6796 	case ETIR__C_OPR_REDEF:
   6797 	  fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n"));
   6798 	  break;
   6799 	case ETIR__C_OPR_DFLIT:
   6800 	  fprintf (file, _("OPR_REDEF (define a literal)\n"));
   6801 	  break;
   6802 
   6803 	case ETIR__C_STC_LP:
   6804 	  fprintf (file, _("STC_LP (store cond linkage pair)\n"));
   6805 	  break;
   6806 	case ETIR__C_STC_LP_PSB:
   6807 	  fprintf (file,
   6808 		   _("STC_LP_PSB (store cond linkage pair + signature)\n"));
   6809 	  if (rest >= 5)
   6810 	    {
   6811 	      /* xgettext:c-format */
   6812 	      fprintf (file, _("   linkage index: %u, procedure: %.*s\n"),
   6813 		       (unsigned) bfd_getl32 (buf),
   6814 		       buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
   6815 	      if (rest > 4 + 1u + buf[4])
   6816 		{
   6817 		  rest -= 4 + 1 + buf[4];
   6818 		  buf += 4 + 1 + buf[4];
   6819 		  fprintf (file, _("   signature: %.*s\n"),
   6820 			   buf[0] > rest - 1 ? rest - 1: buf[0], buf + 1);
   6821 		}
   6822 	    }
   6823 	  break;
   6824 	case ETIR__C_STC_GBL:
   6825 	  fprintf (file, _("STC_GBL (store cond global)\n"));
   6826 	  if (rest >= 5)
   6827 	    /* xgettext:c-format */
   6828 	    fprintf (file, _("   linkage index: %u, global: %.*s\n"),
   6829 		     (unsigned) bfd_getl32 (buf),
   6830 		     buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
   6831 	  break;
   6832 	case ETIR__C_STC_GCA:
   6833 	  fprintf (file, _("STC_GCA (store cond code address)\n"));
   6834 	  if (rest >= 5)
   6835 	    /* xgettext:c-format */
   6836 	    fprintf (file, _("   linkage index: %u, procedure name: %.*s\n"),
   6837 		     (unsigned) bfd_getl32 (buf),
   6838 		     buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
   6839 	  break;
   6840 	case ETIR__C_STC_PS:
   6841 	  fprintf (file, _("STC_PS (store cond psect + offset)\n"));
   6842 	  if (rest >= 16)
   6843 	    fprintf (file,
   6844 		     /* xgettext:c-format */
   6845 		     _("   linkage index: %u, psect: %u, offset: 0x%08x %08x\n"),
   6846 		     (unsigned)bfd_getl32 (buf),
   6847 		     (unsigned)bfd_getl32 (buf + 4),
   6848 		     (unsigned)bfd_getl32 (buf + 12),
   6849 		     (unsigned)bfd_getl32 (buf + 8));
   6850 	  break;
   6851 	case ETIR__C_STC_NOP_GBL:
   6852 	  fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n"));
   6853 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
   6854 	  break;
   6855 	case ETIR__C_STC_NOP_PS:
   6856 	  fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n"));
   6857 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
   6858 	  break;
   6859 	case ETIR__C_STC_BSR_GBL:
   6860 	  fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n"));
   6861 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
   6862 	  break;
   6863 	case ETIR__C_STC_BSR_PS:
   6864 	  fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n"));
   6865 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
   6866 	  break;
   6867 	case ETIR__C_STC_LDA_GBL:
   6868 	  fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n"));
   6869 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
   6870 	  break;
   6871 	case ETIR__C_STC_LDA_PS:
   6872 	  fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n"));
   6873 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
   6874 	  break;
   6875 	case ETIR__C_STC_BOH_GBL:
   6876 	  fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n"));
   6877 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
   6878 	  break;
   6879 	case ETIR__C_STC_BOH_PS:
   6880 	  fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n"));
   6881 	  evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
   6882 	  break;
   6883 	case ETIR__C_STC_NBH_GBL:
   6884 	  fprintf (file,
   6885 		   _("STC_NBH_GBL (store cond or hint at global addr)\n"));
   6886 	  break;
   6887 	case ETIR__C_STC_NBH_PS:
   6888 	  fprintf (file,
   6889 		   _("STC_NBH_PS (store cond or hint at psect + offset)\n"));
   6890 	  break;
   6891 
   6892 	case ETIR__C_CTL_SETRB:
   6893 	  fprintf (file, _("CTL_SETRB (set relocation base)\n"));
   6894 	  break;
   6895 	case ETIR__C_CTL_AUGRB:
   6896 	  if (rest >= 4)
   6897 	    {
   6898 	      unsigned int val = bfd_getl32 (buf);
   6899 	      fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"),
   6900 		       val);
   6901 	    }
   6902 	  break;
   6903 	case ETIR__C_CTL_DFLOC:
   6904 	  fprintf (file, _("CTL_DFLOC (define location)\n"));
   6905 	  break;
   6906 	case ETIR__C_CTL_STLOC:
   6907 	  fprintf (file, _("CTL_STLOC (set location)\n"));
   6908 	  break;
   6909 	case ETIR__C_CTL_STKDL:
   6910 	  fprintf (file, _("CTL_STKDL (stack defined location)\n"));
   6911 	  break;
   6912 	default:
   6913 	  fprintf (file, _("*unhandled*\n"));
   6914 	  break;
   6915 	}
   6916       off += size;
   6917     }
   6918 }
   6919 
   6920 static void
   6921 evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
   6922 {
   6923   bool is_first = true;
   6924   bool has_records = true;
   6925 
   6926   while (1)
   6927     {
   6928       unsigned int rec_len;
   6929       unsigned int pad_len;
   6930       unsigned char *rec;
   6931       unsigned int hdr_size;
   6932       unsigned int type;
   6933       unsigned char buf[6];
   6934 
   6935       hdr_size = has_records ? 6 : 4;
   6936       if (bfd_read (buf, hdr_size, abfd) != hdr_size)
   6937 	{
   6938 	  fprintf (file, _("cannot read GST record header\n"));
   6939 	  return;
   6940 	}
   6941 
   6942       type = bfd_getl16 (buf);
   6943       rec_len = bfd_getl16 (buf + 2);
   6944       pad_len = rec_len;
   6945       if (has_records)
   6946 	{
   6947 	  unsigned int rec_len2 = bfd_getl16 (buf + 4);
   6948 
   6949 	  if (is_first)
   6950 	    {
   6951 	      is_first = false;
   6952 	      if (type == rec_len2 && rec_len == EOBJ__C_EMH)
   6953 		/* Matched a VMS record EMH.  */
   6954 		;
   6955 	      else
   6956 		{
   6957 		  has_records = false;
   6958 		  if (type != EOBJ__C_EMH)
   6959 		    {
   6960 		      /* Ill-formed.  */
   6961 		      fprintf (file, _("cannot find EMH in first GST record\n"));
   6962 		      return;
   6963 		    }
   6964 		}
   6965 	    }
   6966 
   6967 	  if (has_records)
   6968 	    {
   6969 	      /* VMS record format is: record-size, type, record-size.
   6970 		 See maybe_adjust_record_pointer_for_object comment.  */
   6971 	      if (type == rec_len2)
   6972 		{
   6973 		  type = rec_len;
   6974 		  rec_len = rec_len2;
   6975 		}
   6976 	      else
   6977 		rec_len = 0;
   6978 	      pad_len = (rec_len + 1) & ~1U;
   6979 	      hdr_size = 4;
   6980 	    }
   6981 	}
   6982 
   6983       if (rec_len < hdr_size)
   6984 	{
   6985 	  fprintf (file, _("corrupted GST\n"));
   6986 	  return;
   6987 	}
   6988 
   6989       rec = bfd_malloc (pad_len);
   6990       if (rec == NULL)
   6991 	return;
   6992 
   6993       memcpy (rec, buf + (has_records ? 2 : 0), hdr_size);
   6994 
   6995       if (bfd_read (rec + hdr_size, pad_len - hdr_size, abfd)
   6996 	  != pad_len - hdr_size)
   6997 	{
   6998 	  fprintf (file, _("cannot read GST record\n"));
   6999 	  free (rec);
   7000 	  return;
   7001 	}
   7002 
   7003       switch (type)
   7004 	{
   7005 	case EOBJ__C_EMH:
   7006 	  evax_bfd_print_emh (file, rec, rec_len);
   7007 	  break;
   7008 	case EOBJ__C_EGSD:
   7009 	  evax_bfd_print_egsd (file, rec, rec_len);
   7010 	  break;
   7011 	case EOBJ__C_EEOM:
   7012 	  evax_bfd_print_eeom (file, rec, rec_len);
   7013 	  free (rec);
   7014 	  return;
   7015 	case EOBJ__C_ETIR:
   7016 	  evax_bfd_print_etir (file, "ETIR", rec, rec_len);
   7017 	  break;
   7018 	case EOBJ__C_EDBG:
   7019 	  evax_bfd_print_etir (file, "EDBG", rec, rec_len);
   7020 	  break;
   7021 	case EOBJ__C_ETBT:
   7022 	  evax_bfd_print_etir (file, "ETBT", rec, rec_len);
   7023 	  break;
   7024 	default:
   7025 	  fprintf (file, _(" unhandled EOBJ record type %u\n"), type);
   7026 	  break;
   7027 	}
   7028       free (rec);
   7029     }
   7030 }
   7031 
   7032 static void
   7033 evax_bfd_print_relocation_records (FILE *file, const unsigned char *buf,
   7034 				   size_t buf_size, size_t off,
   7035 				   unsigned int stride)
   7036 {
   7037   while (off <= buf_size - 8)
   7038     {
   7039       unsigned int base;
   7040       unsigned int count;
   7041       unsigned int j;
   7042 
   7043       count = bfd_getl32 (buf + off + 0);
   7044 
   7045       if (count == 0)
   7046 	break;
   7047       base = bfd_getl32 (buf + off + 4);
   7048 
   7049       /* xgettext:c-format */
   7050       fprintf (file, _("  bitcount: %u, base addr: 0x%08x\n"),
   7051 	       count, base);
   7052 
   7053       off += 8;
   7054       for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32)
   7055 	{
   7056 	  unsigned int k;
   7057 	  unsigned int n = 0;
   7058 	  unsigned int val;
   7059 
   7060 	  val = bfd_getl32 (buf + off);
   7061 	  off += 4;
   7062 
   7063 	  /* xgettext:c-format */
   7064 	  fprintf (file, _("   bitmap: 0x%08x (count: %u):\n"), val, count);
   7065 
   7066 	  for (k = 0; k < 32; k++)
   7067 	    if (val & (1u << k))
   7068 	      {
   7069 		if (n == 0)
   7070 		  fputs ("   ", file);
   7071 		fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
   7072 		n++;
   7073 		if (n == 8)
   7074 		  {
   7075 		    fputs ("\n", file);
   7076 		    n = 0;
   7077 		  }
   7078 	      }
   7079 	  if (n)
   7080 	    fputs ("\n", file);
   7081 	}
   7082     }
   7083 }
   7084 
   7085 static void
   7086 evax_bfd_print_address_fixups (FILE *file, const unsigned char *buf,
   7087 			       size_t buf_size, size_t off)
   7088 {
   7089   while (off <= buf_size - 8)
   7090     {
   7091       unsigned int j;
   7092       unsigned int count;
   7093 
   7094       count = bfd_getl32 (buf + off + 0);
   7095       if (count == 0)
   7096 	return;
   7097       /* xgettext:c-format */
   7098       fprintf (file, _("  image %u (%u entries)\n"),
   7099 	       (unsigned) bfd_getl32 (buf + off + 4), count);
   7100       off += 8;
   7101       for (j = 0; j < count && off <= buf_size - 8; j++)
   7102 	{
   7103 	  /* xgettext:c-format */
   7104 	  fprintf (file, _("   offset: 0x%08x, val: 0x%08x\n"),
   7105 		   (unsigned) bfd_getl32 (buf + off + 0),
   7106 		   (unsigned) bfd_getl32 (buf + off + 4));
   7107 	  off += 8;
   7108 	}
   7109     }
   7110 }
   7111 
   7112 static void
   7113 evax_bfd_print_reference_fixups (FILE *file, const unsigned char *buf,
   7114 				 size_t buf_size, size_t off)
   7115 {
   7116   unsigned int count;
   7117 
   7118   while (off <= buf_size - 8)
   7119     {
   7120       unsigned int j;
   7121       unsigned int n = 0;
   7122 
   7123       count = bfd_getl32 (buf + off + 0);
   7124       if (count == 0)
   7125 	break;
   7126       /* xgettext:c-format */
   7127       fprintf (file, _("  image %u (%u entries), offsets:\n"),
   7128 	       (unsigned) bfd_getl32 (buf + off + 4), count);
   7129       off += 8;
   7130       for (j = 0; j < count && off <= buf_size - 4; j++)
   7131 	{
   7132 	  if (n == 0)
   7133 	    fputs ("   ", file);
   7134 	  fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off));
   7135 	  n++;
   7136 	  if (n == 7)
   7137 	    {
   7138 	      fputs ("\n", file);
   7139 	      n = 0;
   7140 	    }
   7141 	  off += 4;
   7142 	}
   7143       if (n)
   7144 	fputs ("\n", file);
   7145     }
   7146 }
   7147 
   7148 static void
   7149 evax_bfd_print_indent (int indent, FILE *file)
   7150 {
   7151   for (; indent; indent--)
   7152     fputc (' ', file);
   7153 }
   7154 
   7155 static const char *
   7156 evax_bfd_get_dsc_name (unsigned int v)
   7157 {
   7158   switch (v)
   7159     {
   7160     case DSC__K_DTYPE_Z:
   7161       return "Z (Unspecified)";
   7162     case DSC__K_DTYPE_V:
   7163       return "V (Bit)";
   7164     case DSC__K_DTYPE_BU:
   7165       return "BU (Byte logical)";
   7166     case DSC__K_DTYPE_WU:
   7167       return "WU (Word logical)";
   7168     case DSC__K_DTYPE_LU:
   7169       return "LU (Longword logical)";
   7170     case DSC__K_DTYPE_QU:
   7171       return "QU (Quadword logical)";
   7172     case DSC__K_DTYPE_B:
   7173       return "B (Byte integer)";
   7174     case DSC__K_DTYPE_W:
   7175       return "W (Word integer)";
   7176     case DSC__K_DTYPE_L:
   7177       return "L (Longword integer)";
   7178     case DSC__K_DTYPE_Q:
   7179       return "Q (Quadword integer)";
   7180     case DSC__K_DTYPE_F:
   7181       return "F (Single-precision floating)";
   7182     case DSC__K_DTYPE_D:
   7183       return "D (Double-precision floating)";
   7184     case DSC__K_DTYPE_FC:
   7185       return "FC (Complex)";
   7186     case DSC__K_DTYPE_DC:
   7187       return "DC (Double-precision Complex)";
   7188     case DSC__K_DTYPE_T:
   7189       return "T (ASCII text string)";
   7190     case DSC__K_DTYPE_NU:
   7191       return "NU (Numeric string, unsigned)";
   7192     case DSC__K_DTYPE_NL:
   7193       return "NL (Numeric string, left separate sign)";
   7194     case DSC__K_DTYPE_NLO:
   7195       return "NLO (Numeric string, left overpunched sign)";
   7196     case DSC__K_DTYPE_NR:
   7197       return "NR (Numeric string, right separate sign)";
   7198     case DSC__K_DTYPE_NRO:
   7199       return "NRO (Numeric string, right overpunched sig)";
   7200     case DSC__K_DTYPE_NZ:
   7201       return "NZ (Numeric string, zoned sign)";
   7202     case DSC__K_DTYPE_P:
   7203       return "P (Packed decimal string)";
   7204     case DSC__K_DTYPE_ZI:
   7205       return "ZI (Sequence of instructions)";
   7206     case DSC__K_DTYPE_ZEM:
   7207       return "ZEM (Procedure entry mask)";
   7208     case DSC__K_DTYPE_DSC:
   7209       return "DSC (Descriptor, used for arrays of dyn strings)";
   7210     case DSC__K_DTYPE_OU:
   7211       return "OU (Octaword logical)";
   7212     case DSC__K_DTYPE_O:
   7213       return "O (Octaword integer)";
   7214     case DSC__K_DTYPE_G:
   7215       return "G (Double precision G floating, 64 bit)";
   7216     case DSC__K_DTYPE_H:
   7217       return "H (Quadruple precision floating, 128 bit)";
   7218     case DSC__K_DTYPE_GC:
   7219       return "GC (Double precision complex, G floating)";
   7220     case DSC__K_DTYPE_HC:
   7221       return "HC (Quadruple precision complex, H floating)";
   7222     case DSC__K_DTYPE_CIT:
   7223       return "CIT (COBOL intermediate temporary)";
   7224     case DSC__K_DTYPE_BPV:
   7225       return "BPV (Bound Procedure Value)";
   7226     case DSC__K_DTYPE_BLV:
   7227       return "BLV (Bound Label Value)";
   7228     case DSC__K_DTYPE_VU:
   7229       return "VU (Bit Unaligned)";
   7230     case DSC__K_DTYPE_ADT:
   7231       return "ADT (Absolute Date-Time)";
   7232     case DSC__K_DTYPE_VT:
   7233       return "VT (Varying Text)";
   7234     case DSC__K_DTYPE_T2:
   7235       return "T2 (16-bit char)";
   7236     case DSC__K_DTYPE_VT2:
   7237       return "VT2 (16-bit varying char)";
   7238     default:
   7239       return "?? (unknown)";
   7240     }
   7241 }
   7242 
   7243 static void
   7244 evax_bfd_print_desc (const unsigned char *buf, unsigned int bufsize,
   7245 		     int indent, FILE *file)
   7246 {
   7247   if (bufsize < 8)
   7248     return;
   7249 
   7250   unsigned char bclass = buf[3];
   7251   unsigned char dtype = buf[2];
   7252   unsigned int len = (unsigned)bfd_getl16 (buf);
   7253   unsigned int pointer = (unsigned)bfd_getl32 (buf + 4);
   7254 
   7255   evax_bfd_print_indent (indent, file);
   7256 
   7257   if (len == 1 && pointer == 0xffffffffUL)
   7258     {
   7259       /* 64 bits.  */
   7260       fprintf (file, _("64 bits *unhandled*\n"));
   7261     }
   7262   else
   7263     {
   7264       /* xgettext:c-format */
   7265       fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"),
   7266 	       bclass, dtype, len, pointer);
   7267       switch (bclass)
   7268 	{
   7269 	case DSC__K_CLASS_NCA:
   7270 	  {
   7271 	    const struct vms_dsc_nca *dsc = (const void *)buf;
   7272 	    unsigned int i;
   7273 	    const unsigned char *b;
   7274 
   7275 	    evax_bfd_print_indent (indent, file);
   7276 	    fprintf (file, _("non-contiguous array of %s\n"),
   7277 		     evax_bfd_get_dsc_name (dsc->dtype));
   7278 	    if (bufsize >= sizeof (*dsc))
   7279 	      {
   7280 		evax_bfd_print_indent (indent + 1, file);
   7281 		fprintf (file,
   7282 			 /* xgettext:c-format */
   7283 			 _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"),
   7284 			 dsc->dimct, dsc->aflags, dsc->digits, dsc->scale);
   7285 		evax_bfd_print_indent (indent + 1, file);
   7286 		fprintf (file,
   7287 			 /* xgettext:c-format */
   7288 			 _("arsize: %u, a0: 0x%08x\n"),
   7289 			 (unsigned) bfd_getl32 (dsc->arsize),
   7290 			 (unsigned) bfd_getl32 (dsc->a0));
   7291 		evax_bfd_print_indent (indent + 1, file);
   7292 		fprintf (file, _("Strides:\n"));
   7293 		b = buf + sizeof (*dsc);
   7294 		bufsize -= sizeof (*dsc);
   7295 		for (i = 0; i < dsc->dimct; i++)
   7296 		  {
   7297 		    if (bufsize < 4)
   7298 		      break;
   7299 		    evax_bfd_print_indent (indent + 2, file);
   7300 		    fprintf (file, "[%u]: %u\n", i + 1,
   7301 			     (unsigned) bfd_getl32 (b));
   7302 		    b += 4;
   7303 		    bufsize -= 4;
   7304 		  }
   7305 		evax_bfd_print_indent (indent + 1, file);
   7306 		fprintf (file, _("Bounds:\n"));
   7307 		for (i = 0; i < dsc->dimct; i++)
   7308 		  {
   7309 		    if (bufsize < 8)
   7310 		      break;
   7311 		    evax_bfd_print_indent (indent + 2, file);
   7312 		    /* xgettext:c-format */
   7313 		    fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1,
   7314 			     (unsigned) bfd_getl32 (b + 0),
   7315 			     (unsigned) bfd_getl32 (b + 4));
   7316 		    b += 8;
   7317 		    bufsize -= 8;
   7318 		  }
   7319 	      }
   7320 	  }
   7321 	  break;
   7322 	case DSC__K_CLASS_UBS:
   7323 	  {
   7324 	    const struct vms_dsc_ubs *ubs = (const void *)buf;
   7325 
   7326 	    evax_bfd_print_indent (indent, file);
   7327 	    fprintf (file, _("unaligned bit-string of %s\n"),
   7328 		     evax_bfd_get_dsc_name (ubs->dtype));
   7329 	    if (bufsize >= sizeof (*ubs))
   7330 	      {
   7331 		evax_bfd_print_indent (indent + 1, file);
   7332 		fprintf (file,
   7333 			 /* xgettext:c-format */
   7334 			 _("base: %u, pos: %u\n"),
   7335 			 (unsigned) bfd_getl32 (ubs->base),
   7336 			 (unsigned) bfd_getl32 (ubs->pos));
   7337 	      }
   7338 	  }
   7339 	  break;
   7340 	default:
   7341 	  fprintf (file, _("*unhandled*\n"));
   7342 	  break;
   7343 	}
   7344     }
   7345 }
   7346 
   7347 static unsigned int
   7348 evax_bfd_print_valspec (const unsigned char *buf, unsigned int bufsize,
   7349 			int indent, FILE *file)
   7350 {
   7351   if (bufsize < 5)
   7352     return bufsize;
   7353 
   7354   unsigned int vflags = buf[0];
   7355   unsigned int value = (unsigned) bfd_getl32 (buf + 1);
   7356   unsigned int len = 5;
   7357 
   7358   evax_bfd_print_indent (indent, file);
   7359   /* xgettext:c-format */
   7360   fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
   7361   buf += 5;
   7362   bufsize -= 5;
   7363 
   7364   switch (vflags)
   7365     {
   7366     case DST__K_VFLAGS_NOVAL:
   7367       fprintf (file, _("(no value)\n"));
   7368       break;
   7369     case DST__K_VFLAGS_NOTACTIVE:
   7370       fprintf (file, _("(not active)\n"));
   7371       break;
   7372     case DST__K_VFLAGS_UNALLOC:
   7373       fprintf (file, _("(not allocated)\n"));
   7374       break;
   7375     case DST__K_VFLAGS_DSC:
   7376       fprintf (file, _("(descriptor)\n"));
   7377       if (value <= bufsize)
   7378 	evax_bfd_print_desc (buf + value, bufsize - value, indent + 1, file);
   7379       break;
   7380     case DST__K_VFLAGS_TVS:
   7381       fprintf (file, _("(trailing value)\n"));
   7382       break;
   7383     case DST__K_VS_FOLLOWS:
   7384       fprintf (file, _("(value spec follows)\n"));
   7385       break;
   7386     case DST__K_VFLAGS_BITOFFS:
   7387       fprintf (file, _("(at bit offset %u)\n"), value);
   7388       break;
   7389     default:
   7390       /* xgettext:c-format */
   7391       fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
   7392 	       (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
   7393 	       vflags & DST__K_DISP ? 1 : 0,
   7394 	       vflags & DST__K_INDIR ? 1 : 0);
   7395       switch (vflags & DST__K_VALKIND_MASK)
   7396 	{
   7397 	case DST__K_VALKIND_LITERAL:
   7398 	  fputs (_("literal"), file);
   7399 	  break;
   7400 	case DST__K_VALKIND_ADDR:
   7401 	  fputs (_("address"), file);
   7402 	  break;
   7403 	case DST__K_VALKIND_DESC:
   7404 	  fputs (_("desc"), file);
   7405 	  break;
   7406 	case DST__K_VALKIND_REG:
   7407 	  fputs (_("reg"), file);
   7408 	  break;
   7409 	}
   7410       fputs (")\n", file);
   7411       break;
   7412     }
   7413   return len;
   7414 }
   7415 
   7416 static void
   7417 evax_bfd_print_typspec (const unsigned char *buf, unsigned int bufsize,
   7418 			int indent, FILE *file)
   7419 {
   7420   if (bufsize < 3)
   7421     return;
   7422 
   7423   unsigned char kind = buf[2];
   7424   unsigned int len = (unsigned) bfd_getl16 (buf);
   7425 
   7426   evax_bfd_print_indent (indent, file);
   7427   /* xgettext:c-format */
   7428   fprintf (file, _("len: %2u, kind: %2u "), len, kind);
   7429   buf += 3;
   7430   bufsize -= 3;
   7431   switch (kind)
   7432     {
   7433     case DST__K_TS_ATOM:
   7434     /* xgettext:c-format */
   7435       if (bufsize >= 1)
   7436 	fprintf (file, _("atomic, type=0x%02x %s\n"),
   7437 		 buf[0], evax_bfd_get_dsc_name (buf[0]));
   7438       break;
   7439     case DST__K_TS_IND:
   7440       if (bufsize >= 4)
   7441 	fprintf (file, _("indirect, defined at 0x%08x\n"),
   7442 		 (unsigned) bfd_getl32 (buf));
   7443       break;
   7444     case DST__K_TS_TPTR:
   7445       fprintf (file, _("typed pointer\n"));
   7446       evax_bfd_print_typspec (buf, bufsize, indent + 1, file);
   7447       break;
   7448     case DST__K_TS_PTR:
   7449       fprintf (file, _("pointer\n"));
   7450       break;
   7451     case DST__K_TS_ARRAY:
   7452       {
   7453 	const unsigned char *vs;
   7454 	unsigned int vs_len;
   7455 	unsigned int vec_len;
   7456 	unsigned int i;
   7457 
   7458 	if (bufsize == 0)
   7459 	  return;
   7460 	fprintf (file, _("array, dim: %u, bitmap: "), buf[0]);
   7461 	--bufsize;
   7462 	vec_len = (buf[0] + 1 + 7) / 8;
   7463 	for (i = 0; i < vec_len; i++)
   7464 	  {
   7465 	    if (bufsize == 0)
   7466 	      break;
   7467 	    fprintf (file, " %02x", buf[i + 1]);
   7468 	    --bufsize;
   7469 	  }
   7470 	fputc ('\n', file);
   7471 	if (bufsize == 0)
   7472 	  return;
   7473 	vs = buf + 1 + vec_len;
   7474 	evax_bfd_print_indent (indent, file);
   7475 	fprintf (file, _("array descriptor:\n"));
   7476 	vs_len = evax_bfd_print_valspec (vs, bufsize, indent + 1, file);
   7477 	vs += vs_len;
   7478 	if (bufsize > vs_len)
   7479 	  {
   7480 	    bufsize -= vs_len;
   7481 	    for (i = 0; i < buf[0] + 1U; i++)
   7482 	      if (buf[1 + i / 8] & (1 << (i % 8)))
   7483 		{
   7484 		  evax_bfd_print_indent (indent, file);
   7485 		  if (i == 0)
   7486 		    fprintf (file, _("type spec for element:\n"));
   7487 		  else
   7488 		    fprintf (file, _("type spec for subscript %u:\n"), i);
   7489 		  evax_bfd_print_typspec (vs, bufsize, indent + 1, file);
   7490 		  if (bufsize < 2)
   7491 		    break;
   7492 		  vs_len = bfd_getl16 (vs);
   7493 		  if (bufsize <= vs_len)
   7494 		    break;
   7495 		  vs += vs_len;
   7496 		  bufsize -= vs_len;
   7497 		}
   7498 	  }
   7499       }
   7500       break;
   7501     default:
   7502       fprintf (file, _("*unhandled*\n"));
   7503     }
   7504 }
   7505 
   7506 static void
   7507 evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
   7508 {
   7509   unsigned int off = 0;
   7510   unsigned int pc = 0;
   7511   unsigned int line = 0;
   7512 
   7513   fprintf (file, _("Debug symbol table:\n"));
   7514 
   7515   while (dst_size > 0)
   7516     {
   7517       struct vms_dst_header dsth;
   7518       unsigned int len;
   7519       unsigned int type;
   7520       unsigned char *buf;
   7521 
   7522       if (bfd_read (&dsth, sizeof (dsth), abfd) != sizeof (dsth))
   7523 	{
   7524 	  fprintf (file, _("cannot read DST header\n"));
   7525 	  return;
   7526 	}
   7527       len = bfd_getl16 (dsth.length);
   7528       type = bfd_getl16 (dsth.type);
   7529       /* xgettext:c-format */
   7530       fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
   7531 	       type, len, off);
   7532       /* !!! The length is short by one!  */
   7533       len++;
   7534       if (len > dst_size)
   7535 	len = dst_size;
   7536       if (len < sizeof (dsth))
   7537 	{
   7538 	  fputc ('\n', file);
   7539 	  break;
   7540 	}
   7541       dst_size -= len;
   7542       off += len;
   7543       len -= sizeof (dsth);
   7544       if (len == 0)
   7545 	buf = NULL;
   7546       else
   7547 	{
   7548 	  buf = _bfd_malloc_and_read (abfd, len, len);
   7549 	  if (buf == NULL)
   7550 	    {
   7551 	      fprintf (file, _("cannot read DST symbol\n"));
   7552 	      return;
   7553 	    }
   7554 	}
   7555       switch (type)
   7556 	{
   7557 	case DSC__K_DTYPE_V:
   7558 	case DSC__K_DTYPE_BU:
   7559 	case DSC__K_DTYPE_WU:
   7560 	case DSC__K_DTYPE_LU:
   7561 	case DSC__K_DTYPE_QU:
   7562 	case DSC__K_DTYPE_B:
   7563 	case DSC__K_DTYPE_W:
   7564 	case DSC__K_DTYPE_L:
   7565 	case DSC__K_DTYPE_Q:
   7566 	case DSC__K_DTYPE_F:
   7567 	case DSC__K_DTYPE_D:
   7568 	case DSC__K_DTYPE_FC:
   7569 	case DSC__K_DTYPE_DC:
   7570 	case DSC__K_DTYPE_T:
   7571 	case DSC__K_DTYPE_NU:
   7572 	case DSC__K_DTYPE_NL:
   7573 	case DSC__K_DTYPE_NLO:
   7574 	case DSC__K_DTYPE_NR:
   7575 	case DSC__K_DTYPE_NRO:
   7576 	case DSC__K_DTYPE_NZ:
   7577 	case DSC__K_DTYPE_P:
   7578 	case DSC__K_DTYPE_ZI:
   7579 	case DSC__K_DTYPE_ZEM:
   7580 	case DSC__K_DTYPE_DSC:
   7581 	case DSC__K_DTYPE_OU:
   7582 	case DSC__K_DTYPE_O:
   7583 	case DSC__K_DTYPE_G:
   7584 	case DSC__K_DTYPE_H:
   7585 	case DSC__K_DTYPE_GC:
   7586 	case DSC__K_DTYPE_HC:
   7587 	case DSC__K_DTYPE_CIT:
   7588 	case DSC__K_DTYPE_BPV:
   7589 	case DSC__K_DTYPE_BLV:
   7590 	case DSC__K_DTYPE_VU:
   7591 	case DSC__K_DTYPE_ADT:
   7592 	case DSC__K_DTYPE_VT:
   7593 	case DSC__K_DTYPE_T2:
   7594 	case DSC__K_DTYPE_VT2:
   7595 	  fprintf (file, _("standard data: %s\n"),
   7596 		   evax_bfd_get_dsc_name (type));
   7597 	  evax_bfd_print_valspec (buf, len, 4, file);
   7598 	  if (len > 6)
   7599 	    fprintf (file, _("    name: %.*s\n"),
   7600 		     buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
   7601 	  break;
   7602 	case DST__K_MODBEG:
   7603 	  {
   7604 	    struct vms_dst_modbeg *dst = (void *)buf;
   7605 	    unsigned char *name = buf + sizeof (*dst);
   7606 
   7607 	    fprintf (file, _("modbeg\n"));
   7608 	    if (len < sizeof (*dst))
   7609 	      break;
   7610 	    /* xgettext:c-format */
   7611 	    fprintf (file, _("   flags: %d, language: %u, "
   7612 			     "major: %u, minor: %u\n"),
   7613 		     dst->flags,
   7614 		     (unsigned)bfd_getl32 (dst->language),
   7615 		     (unsigned)bfd_getl16 (dst->major),
   7616 		     (unsigned)bfd_getl16 (dst->minor));
   7617 	    len -= sizeof (*dst);
   7618 	    if (len > 0)
   7619 	      {
   7620 		int nlen = len - 1;
   7621 		fprintf (file, _("   module name: %.*s\n"),
   7622 			 name[0] > nlen ? nlen : name[0], name + 1);
   7623 		if (name[0] < nlen)
   7624 		  {
   7625 		    len -= name[0] + 1;
   7626 		    name += name[0] + 1;
   7627 		    nlen = len - 1;
   7628 		    fprintf (file, _("   compiler   : %.*s\n"),
   7629 			     name[0] > nlen ? nlen : name[0], name + 1);
   7630 		  }
   7631 	      }
   7632 	  }
   7633 	  break;
   7634 	case DST__K_MODEND:
   7635 	  fprintf (file, _("modend\n"));
   7636 	  break;
   7637 	case DST__K_RTNBEG:
   7638 	  {
   7639 	    struct vms_dst_rtnbeg *dst = (void *)buf;
   7640 	    unsigned char *name = buf + sizeof (*dst);
   7641 
   7642 	    fputs (_("rtnbeg\n"), file);
   7643 	    if (len >= sizeof (*dst))
   7644 	      {
   7645 		/* xgettext:c-format */
   7646 		fprintf (file, _("    flags: %u, address: 0x%08x, "
   7647 				 "pd-address: 0x%08x\n"),
   7648 			 dst->flags,
   7649 			 (unsigned) bfd_getl32 (dst->address),
   7650 			 (unsigned) bfd_getl32 (dst->pd_address));
   7651 		len -= sizeof (*dst);
   7652 		if (len > 0)
   7653 		  {
   7654 		    int nlen = len - 1;
   7655 		    fprintf (file, _("    routine name: %.*s\n"),
   7656 			     name[0] > nlen ? nlen : name[0], name + 1);
   7657 		  }
   7658 	      }
   7659 	  }
   7660 	  break;
   7661 	case DST__K_RTNEND:
   7662 	  {
   7663 	    struct vms_dst_rtnend *dst = (void *)buf;
   7664 
   7665 	    if (len >= sizeof (*dst))
   7666 	      fprintf (file, _("rtnend: size 0x%08x\n"),
   7667 		       (unsigned) bfd_getl32 (dst->size));
   7668 	  }
   7669 	  break;
   7670 	case DST__K_PROLOG:
   7671 	  {
   7672 	    struct vms_dst_prolog *dst = (void *)buf;
   7673 
   7674 	    if (len >= sizeof (*dst))
   7675 	      /* xgettext:c-format */
   7676 	      fprintf (file, _("prolog: bkpt address 0x%08x\n"),
   7677 		       (unsigned) bfd_getl32 (dst->bkpt_addr));
   7678 	  }
   7679 	  break;
   7680 	case DST__K_EPILOG:
   7681 	  {
   7682 	    struct vms_dst_epilog *dst = (void *)buf;
   7683 
   7684 	    if (len >= sizeof (*dst))
   7685 	      /* xgettext:c-format */
   7686 	      fprintf (file, _("epilog: flags: %u, count: %u\n"),
   7687 		       dst->flags, (unsigned) bfd_getl32 (dst->count));
   7688 	  }
   7689 	  break;
   7690 	case DST__K_BLKBEG:
   7691 	  {
   7692 	    struct vms_dst_blkbeg *dst = (void *)buf;
   7693 	    unsigned char *name = buf + sizeof (*dst);
   7694 
   7695 	    if (len > sizeof (*dst))
   7696 	      {
   7697 		int nlen;
   7698 		len -= sizeof (*dst);
   7699 		nlen = len - 1;
   7700 		/* xgettext:c-format */
   7701 		fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"),
   7702 			 (unsigned) bfd_getl32 (dst->address),
   7703 			 name[0] > nlen ? nlen : name[0], name + 1);
   7704 	      }
   7705 	  }
   7706 	  break;
   7707 	case DST__K_BLKEND:
   7708 	  {
   7709 	    struct vms_dst_blkend *dst = (void *)buf;
   7710 
   7711 	    if (len >= sizeof (*dst))
   7712 	      /* xgettext:c-format */
   7713 	      fprintf (file, _("blkend: size: 0x%08x\n"),
   7714 		       (unsigned) bfd_getl32 (dst->size));
   7715 	  }
   7716 	  break;
   7717 	case DST__K_TYPSPEC:
   7718 	  {
   7719 	    fprintf (file, _("typspec (len: %u)\n"), len);
   7720 	    if (len >= 1)
   7721 	      {
   7722 		int nlen = len - 1;
   7723 		fprintf (file, _("    name: %.*s\n"),
   7724 			 buf[0] > nlen ? nlen : buf[0], buf + 1);
   7725 		if (nlen > buf[0])
   7726 		  evax_bfd_print_typspec (buf + 1 + buf[0], len - (1 + buf[0]),
   7727 					  5, file);
   7728 	      }
   7729 	  }
   7730 	  break;
   7731 	case DST__K_SEPTYP:
   7732 	  {
   7733 	    if (len >= 6)
   7734 	      {
   7735 		fprintf (file, _("septyp, name: %.*s\n"),
   7736 			 buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
   7737 		evax_bfd_print_valspec (buf, len, 4, file);
   7738 	      }
   7739 	  }
   7740 	  break;
   7741 	case DST__K_RECBEG:
   7742 	  {
   7743 	    struct vms_dst_recbeg *recbeg = (void *)buf;
   7744 
   7745 	    if (len > sizeof (*recbeg))
   7746 	      {
   7747 		unsigned char *name = buf + sizeof (*recbeg);
   7748 		int nlen = len - sizeof (*recbeg) - 1;
   7749 
   7750 		if (name[0] < nlen)
   7751 		  nlen = name[0];
   7752 		fprintf (file, _("recbeg: name: %.*s\n"), nlen, name + 1);
   7753 
   7754 		evax_bfd_print_valspec (buf, len, 4, file);
   7755 
   7756 		len -= sizeof (*recbeg) + 1 + nlen;
   7757 		if (len >= 4)
   7758 		  fprintf (file, _("    len: %u bits\n"),
   7759 			   (unsigned) bfd_getl32 (name + 1 + nlen));
   7760 	      }
   7761 	  }
   7762 	  break;
   7763 	case DST__K_RECEND:
   7764 	  fprintf (file, _("recend\n"));
   7765 	  break;
   7766 	case DST__K_ENUMBEG:
   7767 	  if (len >= 2)
   7768 	    /* xgettext:c-format */
   7769 	    fprintf (file, _("enumbeg, len: %u, name: %.*s\n"),
   7770 		     buf[0], buf[1] > len - 2 ? len - 2 : buf[1], buf + 2);
   7771 	  break;
   7772 	case DST__K_ENUMELT:
   7773 	  if (len >= 6)
   7774 	    {
   7775 	      fprintf (file, _("enumelt, name: %.*s\n"),
   7776 		       buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
   7777 	      evax_bfd_print_valspec (buf, len, 4, file);
   7778 	    }
   7779 	  break;
   7780 	case DST__K_ENUMEND:
   7781 	  fprintf (file, _("enumend\n"));
   7782 	  break;
   7783 	case DST__K_LABEL:
   7784 	  {
   7785 	    struct vms_dst_label *lab = (void *)buf;
   7786 	    if (len >= sizeof (*lab))
   7787 	      {
   7788 		fprintf (file, _("label, name: %.*s\n"),
   7789 			 lab->name[0] > len - 1 ? len - 1 : lab->name[0],
   7790 			 lab->name + 1);
   7791 		fprintf (file, _("    address: 0x%08x\n"),
   7792 			 (unsigned) bfd_getl32 (lab->value));
   7793 	      }
   7794 	  }
   7795 	  break;
   7796 	case DST__K_DIS_RANGE:
   7797 	  if (len >= 4)
   7798 	    {
   7799 	      unsigned int cnt = bfd_getl32 (buf);
   7800 	      unsigned char *rng = buf + 4;
   7801 	      unsigned int i;
   7802 
   7803 	      fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt);
   7804 	      len -= 4;
   7805 	      for (i = 0; i < cnt; i++, rng += 8)
   7806 		{
   7807 		  if (len < 8)
   7808 		    break;
   7809 		  /* xgettext:c-format */
   7810 		  fprintf (file, _("    address: 0x%08x, size: %u\n"),
   7811 			   (unsigned) bfd_getl32 (rng),
   7812 			   (unsigned) bfd_getl32 (rng + 4));
   7813 		  len -= 8;
   7814 		}
   7815 	    }
   7816 	  break;
   7817 	case DST__K_LINE_NUM:
   7818 	  {
   7819 	    unsigned char *buf_orig = buf;
   7820 
   7821 	    fprintf (file, _("line num  (len: %u)\n"), len);
   7822 
   7823 	    while (len > 0)
   7824 	      {
   7825 		int cmd;
   7826 		unsigned int val;
   7827 		int cmdlen = -1;
   7828 
   7829 		cmd = *buf++;
   7830 		len--;
   7831 
   7832 		fputs ("    ", file);
   7833 
   7834 		switch (cmd)
   7835 		  {
   7836 		  case DST__K_DELTA_PC_W:
   7837 		    if (len < 2)
   7838 		      break;
   7839 		    val = bfd_getl16 (buf);
   7840 		    fprintf (file, _("delta_pc_w %u\n"), val);
   7841 		    pc += val;
   7842 		    line++;
   7843 		    cmdlen = 2;
   7844 		    break;
   7845 		  case DST__K_INCR_LINUM:
   7846 		    if (len < 1)
   7847 		      break;
   7848 		    val = *buf;
   7849 		    fprintf (file, _("incr_linum(b): +%u\n"), val);
   7850 		    line += val;
   7851 		    cmdlen = 1;
   7852 		    break;
   7853 		  case DST__K_INCR_LINUM_W:
   7854 		    if (len < 2)
   7855 		      break;
   7856 		    val = bfd_getl16 (buf);
   7857 		    fprintf (file, _("incr_linum_w: +%u\n"), val);
   7858 		    line += val;
   7859 		    cmdlen = 2;
   7860 		    break;
   7861 		  case DST__K_INCR_LINUM_L:
   7862 		    if (len < 4)
   7863 		      break;
   7864 		    val = bfd_getl32 (buf);
   7865 		    fprintf (file, _("incr_linum_l: +%u\n"), val);
   7866 		    line += val;
   7867 		    cmdlen = 4;
   7868 		    break;
   7869 		  case DST__K_SET_LINUM:
   7870 		    if (len < 2)
   7871 		      break;
   7872 		    line = bfd_getl16 (buf);
   7873 		    fprintf (file, _("set_line_num(w) %u\n"), line);
   7874 		    cmdlen = 2;
   7875 		    break;
   7876 		  case DST__K_SET_LINUM_B:
   7877 		    if (len < 1)
   7878 		      break;
   7879 		    line = *buf;
   7880 		    fprintf (file, _("set_line_num_b %u\n"), line);
   7881 		    cmdlen = 1;
   7882 		    break;
   7883 		  case DST__K_SET_LINUM_L:
   7884 		    if (len < 4)
   7885 		      break;
   7886 		    line = bfd_getl32 (buf);
   7887 		    fprintf (file, _("set_line_num_l %u\n"), line);
   7888 		    cmdlen = 4;
   7889 		    break;
   7890 		  case DST__K_SET_ABS_PC:
   7891 		    if (len < 4)
   7892 		      break;
   7893 		    pc = bfd_getl32 (buf);
   7894 		    fprintf (file, _("set_abs_pc: 0x%08x\n"), pc);
   7895 		    cmdlen = 4;
   7896 		    break;
   7897 		  case DST__K_DELTA_PC_L:
   7898 		    if (len < 4)
   7899 		      break;
   7900 		    fprintf (file, _("delta_pc_l: +0x%08x\n"),
   7901 			     (unsigned) bfd_getl32 (buf));
   7902 		    cmdlen = 4;
   7903 		    break;
   7904 		  case DST__K_TERM:
   7905 		    if (len < 1)
   7906 		      break;
   7907 		    fprintf (file, _("term(b): 0x%02x"), *buf);
   7908 		    pc += *buf;
   7909 		    fprintf (file, _("        pc: 0x%08x\n"), pc);
   7910 		    cmdlen = 1;
   7911 		    break;
   7912 		  case DST__K_TERM_W:
   7913 		    if (len < 2)
   7914 		      break;
   7915 		    val = bfd_getl16 (buf);
   7916 		    fprintf (file, _("term_w: 0x%04x"), val);
   7917 		    pc += val;
   7918 		    fprintf (file, _("    pc: 0x%08x\n"), pc);
   7919 		    cmdlen = 2;
   7920 		    break;
   7921 		  default:
   7922 		    if (cmd <= 0)
   7923 		      {
   7924 			fprintf (file, _("delta pc +%-4d"), -cmd);
   7925 			line++;  /* FIXME: curr increment.  */
   7926 			pc += -cmd;
   7927 			/* xgettext:c-format */
   7928 			fprintf (file, _("    pc: 0x%08x line: %5u\n"),
   7929 				 pc, line);
   7930 			cmdlen = 0;
   7931 		      }
   7932 		    else
   7933 		      fprintf (file, _("    *unhandled* cmd %u\n"), cmd);
   7934 		    break;
   7935 		  }
   7936 		if (cmdlen < 0)
   7937 		  break;
   7938 		len -= cmdlen;
   7939 		buf += cmdlen;
   7940 	      }
   7941 	    buf = buf_orig;
   7942 	  }
   7943 	  break;
   7944 	case DST__K_SOURCE:
   7945 	  {
   7946 	    unsigned char *buf_orig = buf;
   7947 
   7948 	    fprintf (file, _("source (len: %u)\n"), len);
   7949 
   7950 	    while (len > 0)
   7951 	      {
   7952 		int cmd = *buf++;
   7953 		int cmdlen = -1;
   7954 
   7955 		len--;
   7956 		switch (cmd)
   7957 		  {
   7958 		  case DST__K_SRC_DECLFILE:
   7959 		    {
   7960 		      struct vms_dst_src_decl_src *src = (void *) buf;
   7961 		      unsigned char *name;
   7962 		      int nlen;
   7963 
   7964 		      if (len < sizeof (*src))
   7965 			break;
   7966 		      /* xgettext:c-format */
   7967 		      fprintf (file, _("   declfile: len: %u, flags: %u, "
   7968 				       "fileid: %u\n"),
   7969 			       src->length, src->flags,
   7970 			       (unsigned)bfd_getl16 (src->fileid));
   7971 		      /* xgettext:c-format */
   7972 		      fprintf (file, _("   rms: cdt: 0x%08x %08x, "
   7973 				       "ebk: 0x%08x, ffb: 0x%04x, "
   7974 				       "rfo: %u\n"),
   7975 			       (unsigned)bfd_getl32 (src->rms_cdt + 4),
   7976 			       (unsigned)bfd_getl32 (src->rms_cdt + 0),
   7977 			       (unsigned)bfd_getl32 (src->rms_ebk),
   7978 			       (unsigned)bfd_getl16 (src->rms_ffb),
   7979 			       src->rms_rfo);
   7980 		      if (src->length > len || src->length <= sizeof (*src))
   7981 			break;
   7982 		      nlen = src->length - sizeof (*src) - 1;
   7983 		      name = buf + sizeof (*src);
   7984 		      fprintf (file, _("   filename   : %.*s\n"),
   7985 			       name[0] > nlen ? nlen : name[0], name + 1);
   7986 		      if (name[0] >= nlen)
   7987 			break;
   7988 		      nlen -= name[0] + 1;
   7989 		      name += name[0] + 1;
   7990 		      fprintf (file, _("   module name: %.*s\n"),
   7991 			       name[0] > nlen ? nlen : name[0], name + 1);
   7992 		      if (name[0] > nlen)
   7993 			break;
   7994 		      cmdlen = src->length;
   7995 		    }
   7996 		    break;
   7997 		  case DST__K_SRC_SETFILE:
   7998 		    if (len < 2)
   7999 		      break;
   8000 		    fprintf (file, _("   setfile %u\n"),
   8001 			     (unsigned) bfd_getl16 (buf));
   8002 		    cmdlen = 2;
   8003 		    break;
   8004 		  case DST__K_SRC_SETREC_W:
   8005 		    if (len < 2)
   8006 		      break;
   8007 		    fprintf (file, _("   setrec %u\n"),
   8008 			     (unsigned) bfd_getl16 (buf));
   8009 		    cmdlen = 2;
   8010 		    break;
   8011 		  case DST__K_SRC_SETREC_L:
   8012 		    if (len < 4)
   8013 		      break;
   8014 		    fprintf (file, _("   setrec %u\n"),
   8015 			     (unsigned) bfd_getl32 (buf));
   8016 		    cmdlen = 4;
   8017 		    break;
   8018 		  case DST__K_SRC_SETLNUM_W:
   8019 		    if (len < 2)
   8020 		      break;
   8021 		    fprintf (file, _("   setlnum %u\n"),
   8022 			     (unsigned) bfd_getl16 (buf));
   8023 		    cmdlen = 2;
   8024 		    break;
   8025 		  case DST__K_SRC_SETLNUM_L:
   8026 		    if (len < 4)
   8027 		      break;
   8028 		    fprintf (file, _("   setlnum %u\n"),
   8029 			     (unsigned) bfd_getl32 (buf));
   8030 		    cmdlen = 4;
   8031 		    break;
   8032 		  case DST__K_SRC_DEFLINES_W:
   8033 		    if (len < 2)
   8034 		      break;
   8035 		    fprintf (file, _("   deflines %u\n"),
   8036 			     (unsigned) bfd_getl16 (buf));
   8037 		    cmdlen = 2;
   8038 		    break;
   8039 		  case DST__K_SRC_DEFLINES_B:
   8040 		    if (len < 1)
   8041 		      break;
   8042 		    fprintf (file, _("   deflines %u\n"), *buf);
   8043 		    cmdlen = 1;
   8044 		    break;
   8045 		  case DST__K_SRC_FORMFEED:
   8046 		    fprintf (file, _("   formfeed\n"));
   8047 		    cmdlen = 0;
   8048 		    break;
   8049 		  default:
   8050 		    fprintf (file, _("   *unhandled* cmd %u\n"), cmd);
   8051 		    break;
   8052 		  }
   8053 		if (cmdlen < 0)
   8054 		  break;
   8055 		len -= cmdlen;
   8056 		buf += cmdlen;
   8057 	      }
   8058 	    buf = buf_orig;
   8059 	  }
   8060 	  break;
   8061 	default:
   8062 	  fprintf (file, _("*unhandled* dst type %u\n"), type);
   8063 	  break;
   8064 	}
   8065       free (buf);
   8066     }
   8067 }
   8068 
   8069 static void
   8070 evax_bfd_print_image (bfd *abfd, FILE *file)
   8071 {
   8072   struct vms_eihd eihd;
   8073   unsigned int rec_size, size;
   8074   const char *name;
   8075   unsigned int val;
   8076   unsigned int eiha_off;
   8077   unsigned int eihi_off;
   8078   unsigned int eihs_off;
   8079   unsigned int eisd_off;
   8080   unsigned int eihef_off = 0;
   8081   unsigned int eihnp_off = 0;
   8082   unsigned int dmt_vbn = 0;
   8083   unsigned int dmt_size = 0;
   8084   unsigned int dst_vbn = 0;
   8085   unsigned int dst_size = 0;
   8086   unsigned int gst_vbn = 0;
   8087   unsigned int gst_size = 0;
   8088   unsigned int eiaf_vbn = 0;
   8089   unsigned int eiaf_size = 0;
   8090   unsigned int eihvn_off;
   8091 
   8092   if (bfd_seek (abfd, 0, SEEK_SET)
   8093       || (rec_size = bfd_read (&eihd, sizeof (eihd), abfd)) < EIHD__C_LENGTH)
   8094     {
   8095       fprintf (file, _("cannot read EIHD\n"));
   8096       return;
   8097     }
   8098   size = bfd_getl32 (eihd.size);
   8099   /* xgettext:c-format */
   8100   fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
   8101 	   size, (unsigned) bfd_getl32 (eihd.hdrblkcnt));
   8102   if (size > rec_size)
   8103     size = rec_size;
   8104   /* xgettext:c-format */
   8105   fprintf (file, _(" majorid: %u, minorid: %u\n"),
   8106 	   (unsigned)bfd_getl32 (eihd.majorid),
   8107 	   (unsigned)bfd_getl32 (eihd.minorid));
   8108 
   8109   val = (unsigned)bfd_getl32 (eihd.imgtype);
   8110   switch (val)
   8111     {
   8112     case EIHD__K_EXE:
   8113       name = _("executable");
   8114       break;
   8115     case EIHD__K_LIM:
   8116       name = _("linkable image");
   8117       break;
   8118     default:
   8119       name = _("unknown");
   8120       break;
   8121     }
   8122   /* xgettext:c-format */
   8123   fprintf (file, _(" image type: %u (%s)"), val, name);
   8124 
   8125   val = (unsigned)bfd_getl32 (eihd.subtype);
   8126   switch (val)
   8127     {
   8128     case EIHD__C_NATIVE:
   8129       name = _("native");
   8130       break;
   8131     case EIHD__C_CLI:
   8132       name = _("CLI");
   8133       break;
   8134     default:
   8135       name = _("unknown");
   8136       break;
   8137     }
   8138   /* xgettext:c-format */
   8139   fprintf (file, _(", subtype: %u (%s)\n"), val, name);
   8140 
   8141   eisd_off = bfd_getl32 (eihd.isdoff);
   8142   eiha_off = bfd_getl32 (eihd.activoff);
   8143   eihi_off = bfd_getl32 (eihd.imgidoff);
   8144   eihs_off = bfd_getl32 (eihd.symdbgoff);
   8145   /* xgettext:c-format */
   8146   fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
   8147 		   "imgid: %u, patch: %u\n"),
   8148 	   eisd_off, eiha_off, eihs_off, eihi_off,
   8149 	   (unsigned)bfd_getl32 (eihd.patchoff));
   8150   fprintf (file, _(" fixup info rva: "));
   8151   bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
   8152   fprintf (file, _(", symbol vector rva: "));
   8153   bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
   8154   eihvn_off = bfd_getl32 (eihd.version_array_off);
   8155   fprintf (file, _("\n"
   8156 		   " version array off: %u\n"),
   8157 	   eihvn_off);
   8158   fprintf (file,
   8159 	   /* xgettext:c-format */
   8160 	   _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
   8161 	   (unsigned)bfd_getl32 (eihd.imgiocnt),
   8162 	   (unsigned)bfd_getl32 (eihd.iochancnt),
   8163 	   (unsigned)bfd_getl32 (eihd.privreqs + 4),
   8164 	   (unsigned)bfd_getl32 (eihd.privreqs + 0));
   8165   val = (unsigned)bfd_getl32 (eihd.lnkflags);
   8166   fprintf (file, _(" linker flags: %08x:"), val);
   8167   if (val & EIHD__M_LNKDEBUG)
   8168     fprintf (file, " LNKDEBUG");
   8169   if (val & EIHD__M_LNKNOTFR)
   8170     fprintf (file, " LNKNOTFR");
   8171   if (val & EIHD__M_NOP0BUFS)
   8172     fprintf (file, " NOP0BUFS");
   8173   if (val & EIHD__M_PICIMG)
   8174     fprintf (file, " PICIMG");
   8175   if (val & EIHD__M_P0IMAGE)
   8176     fprintf (file, " P0IMAGE");
   8177   if (val & EIHD__M_DBGDMT)
   8178     fprintf (file, " DBGDMT");
   8179   if (val & EIHD__M_INISHR)
   8180     fprintf (file, " INISHR");
   8181   if (val & EIHD__M_XLATED)
   8182     fprintf (file, " XLATED");
   8183   if (val & EIHD__M_BIND_CODE_SEC)
   8184     fprintf (file, " BIND_CODE_SEC");
   8185   if (val & EIHD__M_BIND_DATA_SEC)
   8186     fprintf (file, " BIND_DATA_SEC");
   8187   if (val & EIHD__M_MKTHREADS)
   8188     fprintf (file, " MKTHREADS");
   8189   if (val & EIHD__M_UPCALLS)
   8190     fprintf (file, " UPCALLS");
   8191   if (val & EIHD__M_OMV_READY)
   8192     fprintf (file, " OMV_READY");
   8193   if (val & EIHD__M_EXT_BIND_SECT)
   8194     fprintf (file, " EXT_BIND_SECT");
   8195   fprintf (file, "\n");
   8196   /* xgettext:c-format */
   8197   fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
   8198 		   "match ctrl: %u, symvect_size: %u\n"),
   8199 	   (unsigned)bfd_getl32 (eihd.ident),
   8200 	   (unsigned)bfd_getl32 (eihd.sysver),
   8201 	   eihd.matchctl,
   8202 	   (unsigned)bfd_getl32 (eihd.symvect_size));
   8203   fprintf (file, _(" BPAGE: %u"),
   8204 	   (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
   8205   if (size >= (offsetof (struct vms_eihd, noopt_psect_off)
   8206 	       + sizeof (eihd.noopt_psect_off))
   8207       && (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT)))
   8208     {
   8209       eihef_off = bfd_getl32 (eihd.ext_fixup_off);
   8210       eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
   8211       /* xgettext:c-format */
   8212       fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
   8213 	       eihef_off, eihnp_off);
   8214     }
   8215   if (size >= offsetof (struct vms_eihd, alias) + sizeof (eihd.alias))
   8216     fprintf (file, _(", alias: %u"), (unsigned) bfd_getl16 (eihd.alias));
   8217   fprintf (file, "\n");
   8218 
   8219   if (eihvn_off != 0)
   8220     {
   8221       struct vms_eihvn eihvn;
   8222       unsigned int mask;
   8223       unsigned int j;
   8224 
   8225       fprintf (file, _("system version array information:\n"));
   8226       if (bfd_seek (abfd, eihvn_off, SEEK_SET)
   8227 	  || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
   8228 	{
   8229 	  fprintf (file, _("cannot read EIHVN header\n"));
   8230 	  return;
   8231 	}
   8232       mask = bfd_getl32 (eihvn.subsystem_mask);
   8233       for (j = 0; j < 32; j++)
   8234 	if (mask & (1u << j))
   8235 	  {
   8236 	    struct vms_eihvn_subversion ver;
   8237 	    if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver))
   8238 	      {
   8239 		fprintf (file, _("cannot read EIHVN version\n"));
   8240 		return;
   8241 	      }
   8242 	    fprintf (file, _("   %02u "), j);
   8243 	    switch (j)
   8244 	      {
   8245 	      case EIHVN__BASE_IMAGE_BIT:
   8246 		fputs (_("BASE_IMAGE       "), file);
   8247 		break;
   8248 	      case EIHVN__MEMORY_MANAGEMENT_BIT:
   8249 		fputs (_("MEMORY_MANAGEMENT"), file);
   8250 		break;
   8251 	      case EIHVN__IO_BIT:
   8252 		fputs (_("IO               "), file);
   8253 		break;
   8254 	      case EIHVN__FILES_VOLUMES_BIT:
   8255 		fputs (_("FILES_VOLUMES    "), file);
   8256 		break;
   8257 	      case EIHVN__PROCESS_SCHED_BIT:
   8258 		fputs (_("PROCESS_SCHED    "), file);
   8259 		break;
   8260 	      case EIHVN__SYSGEN_BIT:
   8261 		fputs (_("SYSGEN           "), file);
   8262 		break;
   8263 	      case EIHVN__CLUSTERS_LOCKMGR_BIT:
   8264 		fputs (_("CLUSTERS_LOCKMGR "), file);
   8265 		break;
   8266 	      case EIHVN__LOGICAL_NAMES_BIT:
   8267 		fputs (_("LOGICAL_NAMES    "), file);
   8268 		break;
   8269 	      case EIHVN__SECURITY_BIT:
   8270 		fputs (_("SECURITY         "), file);
   8271 		break;
   8272 	      case EIHVN__IMAGE_ACTIVATOR_BIT:
   8273 		fputs (_("IMAGE_ACTIVATOR  "), file);
   8274 		break;
   8275 	      case EIHVN__NETWORKS_BIT:
   8276 		fputs (_("NETWORKS         "), file);
   8277 		break;
   8278 	      case EIHVN__COUNTERS_BIT:
   8279 		fputs (_("COUNTERS         "), file);
   8280 		break;
   8281 	      case EIHVN__STABLE_BIT:
   8282 		fputs (_("STABLE           "), file);
   8283 		break;
   8284 	      case EIHVN__MISC_BIT:
   8285 		fputs (_("MISC             "), file);
   8286 		break;
   8287 	      case EIHVN__CPU_BIT:
   8288 		fputs (_("CPU              "), file);
   8289 		break;
   8290 	      case EIHVN__VOLATILE_BIT:
   8291 		fputs (_("VOLATILE         "), file);
   8292 		break;
   8293 	      case EIHVN__SHELL_BIT:
   8294 		fputs (_("SHELL            "), file);
   8295 		break;
   8296 	      case EIHVN__POSIX_BIT:
   8297 		fputs (_("POSIX            "), file);
   8298 		break;
   8299 	      case EIHVN__MULTI_PROCESSING_BIT:
   8300 		fputs (_("MULTI_PROCESSING "), file);
   8301 		break;
   8302 	      case EIHVN__GALAXY_BIT:
   8303 		fputs (_("GALAXY           "), file);
   8304 		break;
   8305 	      default:
   8306 		fputs (_("*unknown*        "), file);
   8307 		break;
   8308 	      }
   8309 	    fprintf (file, ": %u.%u\n",
   8310 		     (unsigned)bfd_getl16 (ver.major),
   8311 		     (unsigned)bfd_getl16 (ver.minor));
   8312 	  }
   8313     }
   8314 
   8315   if (eiha_off != 0)
   8316     {
   8317       struct vms_eiha eiha;
   8318 
   8319       if (bfd_seek (abfd, eiha_off, SEEK_SET)
   8320 	  || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
   8321 	{
   8322 	  fprintf (file, _("cannot read EIHA\n"));
   8323 	  return;
   8324 	}
   8325       fprintf (file, _("Image activation:  (size=%u)\n"),
   8326 	       (unsigned)bfd_getl32 (eiha.size));
   8327       /* xgettext:c-format */
   8328       fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
   8329 	       (unsigned)bfd_getl32 (eiha.tfradr1_h),
   8330 	       (unsigned)bfd_getl32 (eiha.tfradr1));
   8331       /* xgettext:c-format */
   8332       fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
   8333 	       (unsigned)bfd_getl32 (eiha.tfradr2_h),
   8334 	       (unsigned)bfd_getl32 (eiha.tfradr2));
   8335       /* xgettext:c-format */
   8336       fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
   8337 	       (unsigned)bfd_getl32 (eiha.tfradr3_h),
   8338 	       (unsigned)bfd_getl32 (eiha.tfradr3));
   8339       /* xgettext:c-format */
   8340       fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
   8341 	       (unsigned)bfd_getl32 (eiha.tfradr4_h),
   8342 	       (unsigned)bfd_getl32 (eiha.tfradr4));
   8343       /* xgettext:c-format */
   8344       fprintf (file, _(" Shared image  : 0x%08x 0x%08x\n"),
   8345 	       (unsigned)bfd_getl32 (eiha.inishr_h),
   8346 	       (unsigned)bfd_getl32 (eiha.inishr));
   8347     }
   8348   if (eihi_off != 0)
   8349     {
   8350       struct vms_eihi eihi;
   8351 
   8352       if (bfd_seek (abfd, eihi_off, SEEK_SET)
   8353 	  || bfd_read (&eihi, sizeof (eihi), abfd) != sizeof (eihi))
   8354 	{
   8355 	  fprintf (file, _("cannot read EIHI\n"));
   8356 	  return;
   8357 	}
   8358       /* xgettext:c-format */
   8359       fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
   8360 	       (unsigned) bfd_getl32 (eihi.majorid),
   8361 	       (unsigned) bfd_getl32 (eihi.minorid));
   8362       unsigned int nlen = eihi.imgnam[0];
   8363       if (nlen > sizeof (eihi.imgnam) - 1)
   8364 	nlen = sizeof (eihi.imgnam) - 1;
   8365       fprintf (file, _(" image name       : %.*s\n"), nlen, eihi.imgnam + 1);
   8366       fprintf (file, _(" link time        : %s\n"),
   8367 	       vms_time_to_str (eihi.linktime));
   8368       nlen = eihi.imgid[0];
   8369       if (nlen > sizeof (eihi.imgid) - 1)
   8370 	nlen = sizeof (eihi.imgid) - 1;
   8371       fprintf (file, _(" image ident      : %.*s\n"), nlen, eihi.imgid + 1);
   8372       nlen = eihi.linkid[0];
   8373       if (nlen > sizeof (eihi.linkid) - 1)
   8374 	nlen = sizeof (eihi.linkid) - 1;
   8375       fprintf (file, _(" linker ident     : %.*s\n"), nlen, eihi.linkid + 1);
   8376       nlen = eihi.imgbid[0];
   8377       if (nlen > sizeof (eihi.imgbid) -1 )
   8378 	nlen = sizeof (eihi.imgbid) - 1;
   8379       fprintf (file, _(" image build ident: %.*s\n"), nlen, eihi.imgbid + 1);
   8380     }
   8381   if (eihs_off != 0)
   8382     {
   8383       struct vms_eihs eihs;
   8384 
   8385       if (bfd_seek (abfd, eihs_off, SEEK_SET)
   8386 	  || bfd_read (&eihs, sizeof (eihs), abfd) != sizeof (eihs))
   8387 	{
   8388 	  fprintf (file, _("cannot read EIHS\n"));
   8389 	  return;
   8390 	}
   8391       /* xgettext:c-format */
   8392       fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
   8393 	       (unsigned)bfd_getl32 (eihs.majorid),
   8394 	       (unsigned)bfd_getl32 (eihs.minorid));
   8395       dst_vbn = bfd_getl32 (eihs.dstvbn);
   8396       dst_size = bfd_getl32 (eihs.dstsize);
   8397       /* xgettext:c-format */
   8398       fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"),
   8399 	       dst_vbn, dst_size, dst_size);
   8400       gst_vbn = bfd_getl32 (eihs.gstvbn);
   8401       gst_size = bfd_getl32 (eihs.gstsize);
   8402       /* xgettext:c-format */
   8403       fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
   8404 	       gst_vbn, gst_size);
   8405       dmt_vbn = bfd_getl32 (eihs.dmtvbn);
   8406       dmt_size = bfd_getl32 (eihs.dmtsize);
   8407       /* xgettext:c-format */
   8408       fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
   8409 	       dmt_vbn, dmt_size);
   8410     }
   8411   while (eisd_off != 0)
   8412     {
   8413       struct vms_eisd eisd;
   8414       unsigned int len;
   8415 
   8416       while (1)
   8417 	{
   8418 	  if (bfd_seek (abfd, eisd_off, SEEK_SET)
   8419 	      || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
   8420 	    {
   8421 	      fprintf (file, _("cannot read EISD\n"));
   8422 	      return;
   8423 	    }
   8424 	  len = (unsigned)bfd_getl32 (eisd.eisdsize);
   8425 	  if (len != (unsigned)-1)
   8426 	    break;
   8427 
   8428 	  /* Next block.  */
   8429 	  eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
   8430 	}
   8431       /* xgettext:c-format */
   8432       fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
   8433 		       "size: %u, offset: %u)\n"),
   8434 	       (unsigned)bfd_getl32 (eisd.majorid),
   8435 	       (unsigned)bfd_getl32 (eisd.minorid),
   8436 	       len, eisd_off);
   8437       if (len == 0)
   8438 	break;
   8439       /* xgettext:c-format */
   8440       fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
   8441 	       (unsigned)bfd_getl32 (eisd.virt_addr + 4),
   8442 	       (unsigned)bfd_getl32 (eisd.virt_addr + 0),
   8443 	       (unsigned)bfd_getl32 (eisd.secsize));
   8444       val = (unsigned)bfd_getl32 (eisd.flags);
   8445       fprintf (file, _(" flags: 0x%04x"), val);
   8446       if (val & EISD__M_GBL)
   8447 	fprintf (file, " GBL");
   8448       if (val & EISD__M_CRF)
   8449 	fprintf (file, " CRF");
   8450       if (val & EISD__M_DZRO)
   8451 	fprintf (file, " DZRO");
   8452       if (val & EISD__M_WRT)
   8453 	fprintf (file, " WRT");
   8454       if (val & EISD__M_INITALCODE)
   8455 	fprintf (file, " INITALCODE");
   8456       if (val & EISD__M_BASED)
   8457 	fprintf (file, " BASED");
   8458       if (val & EISD__M_FIXUPVEC)
   8459 	fprintf (file, " FIXUPVEC");
   8460       if (val & EISD__M_RESIDENT)
   8461 	fprintf (file, " RESIDENT");
   8462       if (val & EISD__M_VECTOR)
   8463 	fprintf (file, " VECTOR");
   8464       if (val & EISD__M_PROTECT)
   8465 	fprintf (file, " PROTECT");
   8466       if (val & EISD__M_LASTCLU)
   8467 	fprintf (file, " LASTCLU");
   8468       if (val & EISD__M_EXE)
   8469 	fprintf (file, " EXE");
   8470       if (val & EISD__M_NONSHRADR)
   8471 	fprintf (file, " NONSHRADR");
   8472       if (val & EISD__M_QUAD_LENGTH)
   8473 	fprintf (file, " QUAD_LENGTH");
   8474       if (val & EISD__M_ALLOC_64BIT)
   8475 	fprintf (file, " ALLOC_64BIT");
   8476       fprintf (file, "\n");
   8477       if (val & EISD__M_FIXUPVEC)
   8478 	{
   8479 	  eiaf_vbn = bfd_getl32 (eisd.vbn);
   8480 	  eiaf_size = bfd_getl32 (eisd.secsize);
   8481 	}
   8482       /* xgettext:c-format */
   8483       fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
   8484 	       (unsigned)bfd_getl32 (eisd.vbn),
   8485 	       eisd.pfc, eisd.matchctl, eisd.type);
   8486       switch (eisd.type)
   8487 	{
   8488 	case EISD__K_NORMAL:
   8489 	  fputs (_("NORMAL"), file);
   8490 	  break;
   8491 	case EISD__K_SHRFXD:
   8492 	  fputs (_("SHRFXD"), file);
   8493 	  break;
   8494 	case EISD__K_PRVFXD:
   8495 	  fputs (_("PRVFXD"), file);
   8496 	  break;
   8497 	case EISD__K_SHRPIC:
   8498 	  fputs (_("SHRPIC"), file);
   8499 	  break;
   8500 	case EISD__K_PRVPIC:
   8501 	  fputs (_("PRVPIC"), file);
   8502 	  break;
   8503 	case EISD__K_USRSTACK:
   8504 	  fputs (_("USRSTACK"), file);
   8505 	  break;
   8506 	default:
   8507 	  fputs (_("*unknown*"), file);
   8508 	  break;
   8509 	}
   8510       fputs (_(")\n"), file);
   8511       if (val & EISD__M_GBL)
   8512 	{
   8513 	  unsigned int nlen = eisd.gblnam[0];
   8514 	  if (nlen > sizeof (eisd.gblnam) - 1)
   8515 	    nlen = sizeof (eisd.gblnam) - 1;
   8516 	  /* xgettext:c-format */
   8517 	  fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
   8518 		   (unsigned) bfd_getl32 (eisd.ident),
   8519 		   nlen, eisd.gblnam + 1);
   8520 	}
   8521       eisd_off += len;
   8522     }
   8523 
   8524   if (dmt_vbn != 0)
   8525     {
   8526       if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
   8527 	{
   8528 	  fprintf (file, _("cannot read DMT\n"));
   8529 	  return;
   8530 	}
   8531 
   8532       fprintf (file, _("Debug module table:\n"));
   8533 
   8534       while (dmt_size > 0)
   8535 	{
   8536 	  struct vms_dmt_header dmth;
   8537 	  unsigned int count;
   8538 
   8539 	  if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
   8540 	    {
   8541 	      fprintf (file, _("cannot read DMT header\n"));
   8542 	      return;
   8543 	    }
   8544 	  count = bfd_getl16 (dmth.psect_count);
   8545 	  fprintf (file,
   8546 		   /* xgettext:c-format */
   8547 		   _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"),
   8548 		   (unsigned)bfd_getl32 (dmth.modbeg),
   8549 		   (unsigned)bfd_getl32 (dmth.size), count);
   8550 	  dmt_size -= sizeof (dmth);
   8551 	  while (count > 0)
   8552 	    {
   8553 	      struct vms_dmt_psect dmtp;
   8554 
   8555 	      if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
   8556 		{
   8557 		  fprintf (file, _("cannot read DMT psect\n"));
   8558 		  return;
   8559 		}
   8560 	      /* xgettext:c-format */
   8561 	      fprintf (file, _("  psect start: 0x%08x, length: %u\n"),
   8562 		       (unsigned)bfd_getl32 (dmtp.start),
   8563 		       (unsigned)bfd_getl32 (dmtp.length));
   8564 	      count--;
   8565 	      dmt_size -= sizeof (dmtp);
   8566 	    }
   8567 	}
   8568     }
   8569 
   8570   if (dst_vbn != 0)
   8571     {
   8572       if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
   8573 	{
   8574 	  fprintf (file, _("cannot read DST\n"));
   8575 	  return;
   8576 	}
   8577 
   8578       evax_bfd_print_dst (abfd, dst_size, file);
   8579     }
   8580   if (gst_vbn != 0)
   8581     {
   8582       if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
   8583 	{
   8584 	  fprintf (file, _("cannot read GST\n"));
   8585 	  return;
   8586 	}
   8587 
   8588       fprintf (file, _("Global symbol table:\n"));
   8589       evax_bfd_print_eobj (abfd, file);
   8590     }
   8591   if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf))
   8592     {
   8593       unsigned char *buf;
   8594       struct vms_eiaf *eiaf;
   8595       unsigned int qrelfixoff;
   8596       unsigned int lrelfixoff;
   8597       unsigned int qdotadroff;
   8598       unsigned int ldotadroff;
   8599       unsigned int shrimgcnt;
   8600       unsigned int shlstoff;
   8601       unsigned int codeadroff;
   8602       unsigned int lpfixoff;
   8603       unsigned int chgprtoff;
   8604       file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE;
   8605 
   8606       if (bfd_seek (abfd, f_off, SEEK_SET) != 0
   8607 	  || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL)
   8608 	{
   8609 	  fprintf (file, _("cannot read EIHA\n"));
   8610 	  return;
   8611 	}
   8612       eiaf = (struct vms_eiaf *)buf;
   8613       fprintf (file,
   8614 	       /* xgettext:c-format */
   8615 	       _("Image activator fixup: (major: %u, minor: %u)\n"),
   8616 	       (unsigned)bfd_getl32 (eiaf->majorid),
   8617 	       (unsigned)bfd_getl32 (eiaf->minorid));
   8618       /* xgettext:c-format */
   8619       fprintf (file, _("  iaflink : 0x%08x %08x\n"),
   8620 	       (unsigned)bfd_getl32 (eiaf->iaflink + 0),
   8621 	       (unsigned)bfd_getl32 (eiaf->iaflink + 4));
   8622       /* xgettext:c-format */
   8623       fprintf (file, _("  fixuplnk: 0x%08x %08x\n"),
   8624 	       (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
   8625 	       (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
   8626       fprintf (file, _("  size : %u\n"),
   8627 	       (unsigned)bfd_getl32 (eiaf->size));
   8628       fprintf (file, _("  flags: 0x%08x\n"),
   8629 	       (unsigned)bfd_getl32 (eiaf->flags));
   8630       qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
   8631       lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
   8632       /* xgettext:c-format */
   8633       fprintf (file, _("  qrelfixoff: %5u, lrelfixoff: %5u\n"),
   8634 	       qrelfixoff, lrelfixoff);
   8635       qdotadroff = bfd_getl32 (eiaf->qdotadroff);
   8636       ldotadroff = bfd_getl32 (eiaf->ldotadroff);
   8637       /* xgettext:c-format */
   8638       fprintf (file, _("  qdotadroff: %5u, ldotadroff: %5u\n"),
   8639 	       qdotadroff, ldotadroff);
   8640       codeadroff = bfd_getl32 (eiaf->codeadroff);
   8641       lpfixoff = bfd_getl32 (eiaf->lpfixoff);
   8642       /* xgettext:c-format */
   8643       fprintf (file, _("  codeadroff: %5u, lpfixoff  : %5u\n"),
   8644 	       codeadroff, lpfixoff);
   8645       chgprtoff = bfd_getl32 (eiaf->chgprtoff);
   8646       fprintf (file, _("  chgprtoff : %5u\n"), chgprtoff);
   8647       shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
   8648       shlstoff = bfd_getl32 (eiaf->shlstoff);
   8649       /* xgettext:c-format */
   8650       fprintf (file, _("  shlstoff  : %5u, shrimgcnt : %5u\n"),
   8651 	       shlstoff, shrimgcnt);
   8652       /* xgettext:c-format */
   8653       fprintf (file, _("  shlextra  : %5u, permctx   : %5u\n"),
   8654 	       (unsigned)bfd_getl32 (eiaf->shlextra),
   8655 	       (unsigned)bfd_getl32 (eiaf->permctx));
   8656       fprintf (file, _("  base_va : 0x%08x\n"),
   8657 	       (unsigned)bfd_getl32 (eiaf->base_va));
   8658       fprintf (file, _("  lppsbfixoff: %5u\n"),
   8659 	       (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
   8660 
   8661       if (shlstoff)
   8662 	{
   8663 	  unsigned int j;
   8664 
   8665 	  fprintf (file, _(" Shareable images:\n"));
   8666 	  for (j = 0;
   8667 	       j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl);
   8668 	       j++, shlstoff += sizeof (struct vms_shl))
   8669 	    {
   8670 	      struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff);
   8671 	      unsigned int nlen = shl->imgnam[0];
   8672 	      if (nlen > sizeof (shl->imgnam) - 1)
   8673 		nlen = sizeof (shl->imgnam) - 1;
   8674 	      fprintf (file,
   8675 		       /* xgettext:c-format */
   8676 		       _("  %u: size: %u, flags: 0x%02x, name: %.*s\n"),
   8677 		       j, shl->size, shl->flags,
   8678 		       nlen, shl->imgnam + 1);
   8679 	    }
   8680 	}
   8681       if (qrelfixoff != 0)
   8682 	{
   8683 	  fprintf (file, _(" quad-word relocation fixups:\n"));
   8684 	  evax_bfd_print_relocation_records (file, buf, eiaf_size,
   8685 					     qrelfixoff, 8);
   8686 	}
   8687       if (lrelfixoff != 0)
   8688 	{
   8689 	  fprintf (file, _(" long-word relocation fixups:\n"));
   8690 	  evax_bfd_print_relocation_records (file, buf, eiaf_size,
   8691 					     lrelfixoff, 4);
   8692 	}
   8693       if (qdotadroff != 0)
   8694 	{
   8695 	  fprintf (file, _(" quad-word .address reference fixups:\n"));
   8696 	  evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff);
   8697 	}
   8698       if (ldotadroff != 0)
   8699 	{
   8700 	  fprintf (file, _(" long-word .address reference fixups:\n"));
   8701 	  evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff);
   8702 	}
   8703       if (codeadroff != 0)
   8704 	{
   8705 	  fprintf (file, _(" Code Address Reference Fixups:\n"));
   8706 	  evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff);
   8707 	}
   8708       if (lpfixoff != 0)
   8709 	{
   8710 	  fprintf (file, _(" Linkage Pairs Reference Fixups:\n"));
   8711 	  evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff);
   8712 	}
   8713       if (chgprtoff && chgprtoff <= eiaf_size - 4)
   8714 	{
   8715 	  unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff);
   8716 	  unsigned int j;
   8717 
   8718 	  fprintf (file, _(" Change Protection (%u entries):\n"), count);
   8719 	  for (j = 0, chgprtoff += 4;
   8720 	       j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp);
   8721 	       j++, chgprtoff += sizeof (struct vms_eicp))
   8722 	    {
   8723 	      struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff);
   8724 	      unsigned int prot = bfd_getl32 (eicp->newprt);
   8725 	      fprintf (file,
   8726 		       /* xgettext:c-format */
   8727 		       _("  base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
   8728 		       (unsigned) bfd_getl32 (eicp->baseva + 4),
   8729 		       (unsigned) bfd_getl32 (eicp->baseva + 0),
   8730 		       (unsigned) bfd_getl32 (eicp->size),
   8731 		       (unsigned) bfd_getl32 (eicp->newprt));
   8732 	      switch (prot)
   8733 		{
   8734 		case PRT__C_NA:
   8735 		  fprintf (file, "NA");
   8736 		  break;
   8737 		case PRT__C_RESERVED:
   8738 		  fprintf (file, "RES");
   8739 		  break;
   8740 		case PRT__C_KW:
   8741 		  fprintf (file, "KW");
   8742 		  break;
   8743 		case PRT__C_KR:
   8744 		  fprintf (file, "KR");
   8745 		  break;
   8746 		case PRT__C_UW:
   8747 		  fprintf (file, "UW");
   8748 		  break;
   8749 		case PRT__C_EW:
   8750 		  fprintf (file, "EW");
   8751 		  break;
   8752 		case PRT__C_ERKW:
   8753 		  fprintf (file, "ERKW");
   8754 		  break;
   8755 		case PRT__C_ER:
   8756 		  fprintf (file, "ER");
   8757 		  break;
   8758 		case PRT__C_SW:
   8759 		  fprintf (file, "SW");
   8760 		  break;
   8761 		case PRT__C_SREW:
   8762 		  fprintf (file, "SREW");
   8763 		  break;
   8764 		case PRT__C_SRKW:
   8765 		  fprintf (file, "SRKW");
   8766 		  break;
   8767 		case PRT__C_SR:
   8768 		  fprintf (file, "SR");
   8769 		  break;
   8770 		case PRT__C_URSW:
   8771 		  fprintf (file, "URSW");
   8772 		  break;
   8773 		case PRT__C_UREW:
   8774 		  fprintf (file, "UREW");
   8775 		  break;
   8776 		case PRT__C_URKW:
   8777 		  fprintf (file, "URKW");
   8778 		  break;
   8779 		case PRT__C_UR:
   8780 		  fprintf (file, "UR");
   8781 		  break;
   8782 		default:
   8783 		  fputs ("??", file);
   8784 		  break;
   8785 		}
   8786 	      fputc ('\n', file);
   8787 	    }
   8788 	}
   8789       free (buf);
   8790     }
   8791 }
   8792 
   8793 static bool
   8794 vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
   8795 {
   8796   FILE *file = (FILE *)ptr;
   8797 
   8798   if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
   8799     evax_bfd_print_image (abfd, file);
   8800   else
   8801     {
   8802       if (bfd_seek (abfd, 0, SEEK_SET))
   8803 	return false;
   8804       evax_bfd_print_eobj (abfd, file);
   8805     }
   8806   return true;
   8807 }
   8808 
   8809 /* Linking.  */
   8811 
   8812 /* Slurp ETIR/EDBG/ETBT VMS object records.  */
   8813 
   8814 static bool
   8815 alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
   8816 {
   8817   asection *cur_section;
   8818   file_ptr cur_offset;
   8819   asection *dst_section;
   8820   file_ptr dst_offset;
   8821 
   8822   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
   8823     return false;
   8824 
   8825   cur_section = NULL;
   8826   cur_offset = 0;
   8827 
   8828   dst_section = PRIV (dst_section);
   8829   dst_offset = 0;
   8830   if (info)
   8831     {
   8832       if (info->strip == strip_all || info->strip == strip_debugger)
   8833 	{
   8834 	  /* Discard the DST section.  */
   8835 	  dst_offset = 0;
   8836 	  dst_section = NULL;
   8837 	}
   8838       else if (dst_section)
   8839 	{
   8840 	  dst_offset = dst_section->output_offset;
   8841 	  dst_section = dst_section->output_section;
   8842 	}
   8843     }
   8844 
   8845   while (1)
   8846     {
   8847       int type;
   8848       bool res;
   8849 
   8850       type = _bfd_vms_get_object_record (abfd);
   8851       if (type < 0)
   8852 	{
   8853 	  vms_debug2 ((2, "next_record failed\n"));
   8854 	  return false;
   8855 	}
   8856       switch (type)
   8857 	{
   8858 	case EOBJ__C_ETIR:
   8859 	  PRIV (image_section) = cur_section;
   8860 	  PRIV (image_offset) = cur_offset;
   8861 	  res = _bfd_vms_slurp_etir (abfd, info);
   8862 	  cur_section = PRIV (image_section);
   8863 	  cur_offset = PRIV (image_offset);
   8864 	  break;
   8865 	case EOBJ__C_EDBG:
   8866 	case EOBJ__C_ETBT:
   8867 	  if (dst_section == NULL)
   8868 	    continue;
   8869 	  PRIV (image_section) = dst_section;
   8870 	  PRIV (image_offset) = dst_offset;
   8871 	  res = _bfd_vms_slurp_etir (abfd, info);
   8872 	  dst_offset = PRIV (image_offset);
   8873 	  break;
   8874 	case EOBJ__C_EEOM:
   8875 	  return true;
   8876 	default:
   8877 	  continue;
   8878 	}
   8879       if (!res)
   8880 	{
   8881 	  vms_debug2 ((2, "slurp eobj type %d failed\n", type));
   8882 	  return false;
   8883 	}
   8884     }
   8885 }
   8886 
   8887 static int
   8888 alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
   8889 			  struct bfd_link_info *info ATTRIBUTE_UNUSED)
   8890 {
   8891   return 0;
   8892 }
   8893 
   8894 /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */
   8895 
   8896 static bool
   8897 alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib)
   8898 {
   8899   struct alpha_vms_shlib_el *sl;
   8900   asection *sect = PRIV2 (src, image_section);
   8901   file_ptr offset = PRIV2 (src, image_offset);
   8902   bfd_vma *p;
   8903 
   8904   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
   8905 		struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
   8906   sl->has_fixups = true;
   8907   p = VEC_APPEND (sl->lp, bfd_vma);
   8908   if (p == NULL)
   8909     return false;
   8910   *p = sect->output_section->vma + sect->output_offset + offset;
   8911   sect->output_section->flags |= SEC_RELOC;
   8912   return true;
   8913 }
   8914 
   8915 /* Add a code address fixup at address SECT + OFFSET to SHLIB. */
   8916 
   8917 static bool
   8918 alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib)
   8919 {
   8920   struct alpha_vms_shlib_el *sl;
   8921   asection *sect = PRIV2 (src, image_section);
   8922   file_ptr offset = PRIV2 (src, image_offset);
   8923   bfd_vma *p;
   8924 
   8925   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
   8926 		struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
   8927   sl->has_fixups = true;
   8928   p = VEC_APPEND (sl->ca, bfd_vma);
   8929   if (p == NULL)
   8930     return false;
   8931   *p = sect->output_section->vma + sect->output_offset + offset;
   8932   sect->output_section->flags |= SEC_RELOC;
   8933   return true;
   8934 }
   8935 
   8936 /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */
   8937 
   8938 static bool
   8939 alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
   8940 			bfd *shlib, bfd_vma vec)
   8941 {
   8942   struct alpha_vms_shlib_el *sl;
   8943   struct alpha_vms_vma_ref *r;
   8944   asection *sect = PRIV2 (src, image_section);
   8945   file_ptr offset = PRIV2 (src, image_offset);
   8946 
   8947   sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
   8948 		struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
   8949   sl->has_fixups = true;
   8950   r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref);
   8951   if (r == NULL)
   8952     return false;
   8953   r->vma = sect->output_section->vma + sect->output_offset + offset;
   8954   r->ref = vec;
   8955   sect->output_section->flags |= SEC_RELOC;
   8956   return true;
   8957 }
   8958 
   8959 static bool
   8960 alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   8961 			unsigned int shr ATTRIBUTE_UNUSED,
   8962 			bfd_vma vec ATTRIBUTE_UNUSED)
   8963 {
   8964   /* Not yet supported.  */
   8965   return false;
   8966 }
   8967 
   8968 /* Add relocation.  FIXME: Not yet emitted.  */
   8969 
   8970 static bool
   8971 alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
   8972 {
   8973   return true;
   8974 }
   8975 
   8976 static bool
   8977 alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
   8978 {
   8979   return true;
   8980 }
   8981 
   8982 static struct bfd_hash_entry *
   8983 alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry,
   8984 			     struct bfd_hash_table *table,
   8985 			     const char *string)
   8986 {
   8987   struct alpha_vms_link_hash_entry *ret =
   8988     (struct alpha_vms_link_hash_entry *) entry;
   8989 
   8990   /* Allocate the structure if it has not already been allocated by a
   8991      subclass.  */
   8992   if (ret == NULL)
   8993     ret = ((struct alpha_vms_link_hash_entry *)
   8994 	   bfd_hash_allocate (table,
   8995 			      sizeof (struct alpha_vms_link_hash_entry)));
   8996   if (ret == NULL)
   8997     return NULL;
   8998 
   8999   /* Call the allocation method of the superclass.  */
   9000   ret = ((struct alpha_vms_link_hash_entry *)
   9001 	 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
   9002 				 table, string));
   9003 
   9004   ret->sym = NULL;
   9005 
   9006   return (struct bfd_hash_entry *) ret;
   9007 }
   9008 
   9009 static void
   9010 alpha_vms_bfd_link_hash_table_free (bfd *abfd)
   9011 {
   9012   struct alpha_vms_link_hash_table *t;
   9013   unsigned i;
   9014 
   9015   t = (struct alpha_vms_link_hash_table *) abfd->link.hash;
   9016   for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9017     {
   9018       struct alpha_vms_shlib_el *shlib;
   9019 
   9020       shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9021       free (&VEC_EL (shlib->ca, bfd_vma, 0));
   9022       free (&VEC_EL (shlib->lp, bfd_vma, 0));
   9023       free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0));
   9024     }
   9025   free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0));
   9026 
   9027   _bfd_generic_link_hash_table_free (abfd);
   9028 }
   9029 
   9030 /* Create an Alpha/VMS link hash table.  */
   9031 
   9032 static struct bfd_link_hash_table *
   9033 alpha_vms_bfd_link_hash_table_create (bfd *abfd)
   9034 {
   9035   struct alpha_vms_link_hash_table *ret;
   9036   size_t amt = sizeof (struct alpha_vms_link_hash_table);
   9037 
   9038   ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt);
   9039   if (ret == NULL)
   9040     return NULL;
   9041   if (!_bfd_link_hash_table_init (&ret->root, abfd,
   9042 				  alpha_vms_link_hash_newfunc,
   9043 				  sizeof (struct alpha_vms_link_hash_entry)))
   9044     {
   9045       free (ret);
   9046       return NULL;
   9047     }
   9048 
   9049   VEC_INIT (ret->shrlibs);
   9050   ret->fixup = NULL;
   9051   ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free;
   9052 
   9053   return &ret->root;
   9054 }
   9055 
   9056 static bool
   9057 alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
   9058 {
   9059   unsigned int i;
   9060 
   9061   for (i = 0; i < PRIV (gsd_sym_count); i++)
   9062     {
   9063       struct vms_symbol_entry *e = PRIV (syms)[i];
   9064       struct alpha_vms_link_hash_entry *h;
   9065       struct bfd_link_hash_entry *h_root;
   9066       asymbol sym;
   9067 
   9068       if (!alpha_vms_convert_symbol (abfd, e, &sym))
   9069 	return false;
   9070 
   9071       if ((e->flags & EGSY__V_DEF) && abfd->selective_search)
   9072 	{
   9073 	  /* In selective_search mode, only add definition that are
   9074 	     required.  */
   9075 	  h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup
   9076 	    (info->hash, sym.name, false, false, false);
   9077 	  if (h == NULL || h->root.type != bfd_link_hash_undefined)
   9078 	    continue;
   9079 	}
   9080       else
   9081 	h = NULL;
   9082 
   9083       h_root = (struct bfd_link_hash_entry *) h;
   9084       if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags,
   9085 					     sym.section, sym.value, NULL,
   9086 					     false, false, &h_root))
   9087 	return false;
   9088       h = (struct alpha_vms_link_hash_entry *) h_root;
   9089 
   9090       if ((e->flags & EGSY__V_DEF)
   9091 	  && h->sym == NULL
   9092 	  && abfd->xvec == info->output_bfd->xvec)
   9093 	h->sym = e;
   9094     }
   9095 
   9096   if (abfd->flags & DYNAMIC)
   9097     {
   9098       struct alpha_vms_shlib_el *shlib;
   9099 
   9100       /* We do not want to include any of the sections in a dynamic
   9101 	 object in the output file.  See comment in elflink.c.  */
   9102       bfd_section_list_clear (abfd);
   9103 
   9104       shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs,
   9105 			  struct alpha_vms_shlib_el);
   9106       if (shlib == NULL)
   9107 	return false;
   9108       shlib->abfd = abfd;
   9109       VEC_INIT (shlib->ca);
   9110       VEC_INIT (shlib->lp);
   9111       VEC_INIT (shlib->qr);
   9112       PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1;
   9113     }
   9114 
   9115   return true;
   9116 }
   9117 
   9118 static bool
   9119 alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
   9120 {
   9121   int pass;
   9122   struct bfd_link_hash_entry **pundef;
   9123   struct bfd_link_hash_entry **next_pundef;
   9124 
   9125   /* We only accept VMS libraries.  */
   9126   if (info->output_bfd->xvec != abfd->xvec)
   9127     {
   9128       bfd_set_error (bfd_error_wrong_format);
   9129       return false;
   9130     }
   9131 
   9132   /* The archive_pass field in the archive itself is used to
   9133      initialize PASS, since we may search the same archive multiple
   9134      times.  */
   9135   pass = ++abfd->archive_pass;
   9136 
   9137   /* Look through the list of undefined symbols.  */
   9138   for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
   9139     {
   9140       struct bfd_link_hash_entry *h;
   9141       symindex symidx;
   9142       bfd *element;
   9143       bfd *orig_element;
   9144 
   9145       h = *pundef;
   9146       next_pundef = &(*pundef)->u.undef.next;
   9147 
   9148       /* When a symbol is defined, it is not necessarily removed from
   9149 	 the list.  */
   9150       if (h->type != bfd_link_hash_undefined
   9151 	  && h->type != bfd_link_hash_common)
   9152 	{
   9153 	  /* Remove this entry from the list, for general cleanliness
   9154 	     and because we are going to look through the list again
   9155 	     if we search any more libraries.  We can't remove the
   9156 	     entry if it is the tail, because that would lose any
   9157 	     entries we add to the list later on.  */
   9158 	  if (*pundef != info->hash->undefs_tail)
   9159 	    {
   9160 	      *pundef = *next_pundef;
   9161 	      next_pundef = pundef;
   9162 	    }
   9163 	  continue;
   9164 	}
   9165 
   9166       /* Look for this symbol in the archive hash table.  */
   9167       symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string);
   9168       if (symidx == BFD_NO_MORE_SYMBOLS)
   9169 	{
   9170 	  /* Nothing in this slot.  */
   9171 	  continue;
   9172 	}
   9173 
   9174       element = bfd_get_elt_at_index (abfd, symidx);
   9175       if (element == NULL)
   9176 	return false;
   9177 
   9178       if (element->archive_pass == -1 || element->archive_pass == pass)
   9179 	{
   9180 	  /* Next symbol if this archive is wrong or already handled.  */
   9181 	  continue;
   9182 	}
   9183 
   9184       if (! bfd_check_format (element, bfd_object))
   9185 	{
   9186 	  element->archive_pass = -1;
   9187 	  return false;
   9188 	}
   9189 
   9190       orig_element = element;
   9191       if (bfd_is_thin_archive (abfd))
   9192 	{
   9193 	  element = _bfd_vms_lib_get_imagelib_file (element);
   9194 	  if (element == NULL || !bfd_check_format (element, bfd_object))
   9195 	    {
   9196 	      orig_element->archive_pass = -1;
   9197 	      return false;
   9198 	    }
   9199 	}
   9200 
   9201       /* Unlike the generic linker, we know that this element provides
   9202 	 a definition for an undefined symbol and we know that we want
   9203 	 to include it.  We don't need to check anything.  */
   9204       if (!(*info->callbacks
   9205 	    ->add_archive_element) (info, element, h->root.string, &element))
   9206 	continue;
   9207       if (!alpha_vms_link_add_object_symbols (element, info))
   9208 	return false;
   9209 
   9210       orig_element->archive_pass = pass;
   9211     }
   9212 
   9213   return true;
   9214 }
   9215 
   9216 static bool
   9217 alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
   9218 {
   9219   switch (bfd_get_format (abfd))
   9220     {
   9221     case bfd_object:
   9222       vms_debug2 ((2, "vms_link_add_symbols for object %s\n",
   9223 		   abfd->filename));
   9224       return alpha_vms_link_add_object_symbols (abfd, info);
   9225       break;
   9226     case bfd_archive:
   9227       vms_debug2 ((2, "vms_link_add_symbols for archive %s\n",
   9228 		   abfd->filename));
   9229       return alpha_vms_link_add_archive_symbols (abfd, info);
   9230       break;
   9231     default:
   9232       bfd_set_error (bfd_error_wrong_format);
   9233       return false;
   9234     }
   9235 }
   9236 
   9237 static bool
   9238 alpha_vms_build_fixups (struct bfd_link_info *info)
   9239 {
   9240   struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info);
   9241   unsigned char *content;
   9242   unsigned int i;
   9243   unsigned int sz = 0;
   9244   unsigned int lp_sz = 0;
   9245   unsigned int ca_sz = 0;
   9246   unsigned int qr_sz = 0;
   9247   unsigned int shrimg_cnt = 0;
   9248   unsigned int chgprt_num = 0;
   9249   unsigned int chgprt_sz = 0;
   9250   struct vms_eiaf *eiaf;
   9251   unsigned int off;
   9252   asection *sec;
   9253 
   9254   /* Shared libraries.  */
   9255   for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9256     {
   9257       struct alpha_vms_shlib_el *shlib;
   9258 
   9259       shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9260 
   9261       if (!shlib->has_fixups)
   9262 	continue;
   9263 
   9264       shrimg_cnt++;
   9265 
   9266       if (VEC_COUNT (shlib->ca) > 0)
   9267 	{
   9268 	  /* Header + entries.  */
   9269 	  ca_sz += 8;
   9270 	  ca_sz += VEC_COUNT (shlib->ca) * 4;
   9271 	}
   9272       if (VEC_COUNT (shlib->lp) > 0)
   9273 	{
   9274 	  /* Header + entries.  */
   9275 	  lp_sz += 8;
   9276 	  lp_sz += VEC_COUNT (shlib->lp) * 4;
   9277 	}
   9278       if (VEC_COUNT (shlib->qr) > 0)
   9279 	{
   9280 	  /* Header + entries.  */
   9281 	  qr_sz += 8;
   9282 	  qr_sz += VEC_COUNT (shlib->qr) * 8;
   9283 	}
   9284     }
   9285   /* Add markers.  */
   9286   if (ca_sz > 0)
   9287     ca_sz += 8;
   9288   if (lp_sz > 0)
   9289     lp_sz += 8;
   9290   if (qr_sz > 0)
   9291     qr_sz += 8;
   9292 
   9293   /* Finish now if there is no content.  */
   9294   if (ca_sz + lp_sz + qr_sz == 0)
   9295     return true;
   9296 
   9297   /* Add an eicp entry for the fixup itself.  */
   9298   chgprt_num = 1;
   9299   for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
   9300     {
   9301       /* This isect could be made RO or EXE after relocations are applied.  */
   9302       if ((sec->flags & SEC_RELOC) != 0
   9303 	  && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
   9304 	chgprt_num++;
   9305     }
   9306   chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp);
   9307 
   9308   /* Allocate section content (round-up size)  */
   9309   sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl)
   9310     + ca_sz + lp_sz + qr_sz + chgprt_sz;
   9311   sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
   9312   content = bfd_zalloc (info->output_bfd, sz);
   9313   if (content == NULL)
   9314     return false;
   9315 
   9316   sec = alpha_vms_link_hash (info)->fixup;
   9317   sec->contents = content;
   9318   sec->alloced = 1;
   9319   sec->size = sz;
   9320 
   9321   eiaf = (struct vms_eiaf *)content;
   9322   off = sizeof (struct vms_eiaf);
   9323   bfd_putl32 (0, eiaf->majorid);
   9324   bfd_putl32 (0, eiaf->minorid);
   9325   bfd_putl32 (0, eiaf->iaflink);
   9326   bfd_putl32 (0, eiaf->fixuplnk);
   9327   bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size);
   9328   bfd_putl32 (0, eiaf->flags);
   9329   bfd_putl32 (0, eiaf->qrelfixoff);
   9330   bfd_putl32 (0, eiaf->lrelfixoff);
   9331   bfd_putl32 (0, eiaf->qdotadroff);
   9332   bfd_putl32 (0, eiaf->ldotadroff);
   9333   bfd_putl32 (0, eiaf->codeadroff);
   9334   bfd_putl32 (0, eiaf->lpfixoff);
   9335   bfd_putl32 (0, eiaf->chgprtoff);
   9336   bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff);
   9337   bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt);
   9338   bfd_putl32 (0, eiaf->shlextra);
   9339   bfd_putl32 (0, eiaf->permctx);
   9340   bfd_putl32 (0, eiaf->base_va);
   9341   bfd_putl32 (0, eiaf->lppsbfixoff);
   9342 
   9343   if (shrimg_cnt)
   9344     {
   9345       shrimg_cnt = 0;
   9346 
   9347       /* Write shl.  */
   9348       for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9349 	{
   9350 	  struct alpha_vms_shlib_el *shlib;
   9351 	  struct vms_shl *shl;
   9352 
   9353 	  shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9354 
   9355 	  if (!shlib->has_fixups)
   9356 	    continue;
   9357 
   9358 	  /* Renumber shared images.  */
   9359 	  PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++;
   9360 
   9361 	  shl = (struct vms_shl *)(content + off);
   9362 	  bfd_putl32 (0, shl->baseva);
   9363 	  bfd_putl32 (0, shl->shlptr);
   9364 	  bfd_putl32 (0, shl->ident);
   9365 	  bfd_putl32 (0, shl->permctx);
   9366 	  shl->size = sizeof (struct vms_shl);
   9367 	  bfd_putl16 (0, shl->fill_1);
   9368 	  shl->flags = 0;
   9369 	  bfd_putl32 (0, shl->icb);
   9370 	  shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name));
   9371 	  memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name),
   9372 		  shl->imgnam[0]);
   9373 
   9374 	  off += sizeof (struct vms_shl);
   9375 	}
   9376 
   9377       /* CA fixups.  */
   9378       if (ca_sz != 0)
   9379 	{
   9380 	  bfd_putl32 (off, eiaf->codeadroff);
   9381 
   9382 	  for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9383 	    {
   9384 	      struct alpha_vms_shlib_el *shlib;
   9385 	      unsigned int j;
   9386 
   9387 	      shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9388 
   9389 	      if (VEC_COUNT (shlib->ca) == 0)
   9390 		continue;
   9391 
   9392 	      bfd_putl32 (VEC_COUNT (shlib->ca), content + off);
   9393 	      bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
   9394 	      off += 8;
   9395 
   9396 	      for (j = 0; j < VEC_COUNT (shlib->ca); j++)
   9397 		{
   9398 		  bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr,
   9399 			      content + off);
   9400 		  off += 4;
   9401 		}
   9402 	    }
   9403 
   9404 	  bfd_putl32 (0, content + off);
   9405 	  bfd_putl32 (0, content + off + 4);
   9406 	  off += 8;
   9407 	}
   9408 
   9409       /* LP fixups.  */
   9410       if (lp_sz != 0)
   9411 	{
   9412 	  bfd_putl32 (off, eiaf->lpfixoff);
   9413 
   9414 	  for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9415 	    {
   9416 	      struct alpha_vms_shlib_el *shlib;
   9417 	      unsigned int j;
   9418 
   9419 	      shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9420 
   9421 	      if (VEC_COUNT (shlib->lp) == 0)
   9422 		continue;
   9423 
   9424 	      bfd_putl32 (VEC_COUNT (shlib->lp), content + off);
   9425 	      bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
   9426 	      off += 8;
   9427 
   9428 	      for (j = 0; j < VEC_COUNT (shlib->lp); j++)
   9429 		{
   9430 		  bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr,
   9431 			      content + off);
   9432 		  off += 4;
   9433 		}
   9434 	    }
   9435 
   9436 	  bfd_putl32 (0, content + off);
   9437 	  bfd_putl32 (0, content + off + 4);
   9438 	  off += 8;
   9439 	}
   9440 
   9441       /* QR fixups.  */
   9442       if (qr_sz != 0)
   9443 	{
   9444 	  bfd_putl32 (off, eiaf->qdotadroff);
   9445 
   9446 	  for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
   9447 	    {
   9448 	      struct alpha_vms_shlib_el *shlib;
   9449 	      unsigned int j;
   9450 
   9451 	      shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
   9452 
   9453 	      if (VEC_COUNT (shlib->qr) == 0)
   9454 		continue;
   9455 
   9456 	      bfd_putl32 (VEC_COUNT (shlib->qr), content + off);
   9457 	      bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
   9458 	      off += 8;
   9459 
   9460 	      for (j = 0; j < VEC_COUNT (shlib->qr); j++)
   9461 		{
   9462 		  struct alpha_vms_vma_ref *r;
   9463 		  r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j);
   9464 		  bfd_putl32 (r->vma - t->base_addr, content + off);
   9465 		  bfd_putl32 (r->ref, content + off + 4);
   9466 		  off += 8;
   9467 		}
   9468 	    }
   9469 
   9470 	  bfd_putl32 (0, content + off);
   9471 	  bfd_putl32 (0, content + off + 4);
   9472 	  off += 8;
   9473 	}
   9474     }
   9475 
   9476   /* Write the change protection table.  */
   9477   bfd_putl32 (off, eiaf->chgprtoff);
   9478   bfd_putl32 (chgprt_num, content + off);
   9479   off += 4;
   9480 
   9481   for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
   9482     {
   9483       struct vms_eicp *eicp;
   9484       unsigned int prot;
   9485 
   9486       if ((sec->flags & SEC_LINKER_CREATED) != 0 &&
   9487 	  strcmp (sec->name, "$FIXUP$") == 0)
   9488 	prot = PRT__C_UREW;
   9489       else if ((sec->flags & SEC_RELOC) != 0
   9490 	       && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
   9491 	prot = PRT__C_UR;
   9492       else
   9493 	continue;
   9494 
   9495       eicp = (struct vms_eicp *)(content + off);
   9496       bfd_putl64 (sec->vma - t->base_addr, eicp->baseva);
   9497       bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1),
   9498 		  eicp->size);
   9499       bfd_putl32 (prot, eicp->newprt);
   9500       off += sizeof (struct vms_eicp);
   9501     }
   9502 
   9503   return true;
   9504 }
   9505 
   9506 /* Called by bfd_hash_traverse to fill the symbol table.
   9507    Return FALSE in case of failure.  */
   9508 
   9509 static bool
   9510 alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
   9511 {
   9512   struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh;
   9513   struct bfd_link_info *info = (struct bfd_link_info *)infov;
   9514   struct alpha_vms_link_hash_entry *h;
   9515   struct vms_symbol_entry *sym;
   9516 
   9517   if (hc->type == bfd_link_hash_warning)
   9518     {
   9519       hc = hc->u.i.link;
   9520       if (hc->type == bfd_link_hash_new)
   9521 	return true;
   9522     }
   9523   h = (struct alpha_vms_link_hash_entry *) hc;
   9524 
   9525   switch (h->root.type)
   9526     {
   9527     case bfd_link_hash_undefined:
   9528       return true;
   9529     case bfd_link_hash_new:
   9530     case bfd_link_hash_warning:
   9531       abort ();
   9532     case bfd_link_hash_undefweak:
   9533       return true;
   9534     case bfd_link_hash_defined:
   9535     case bfd_link_hash_defweak:
   9536       {
   9537 	asection *sec = h->root.u.def.section;
   9538 
   9539 	/* FIXME: this is certainly a symbol from a dynamic library.  */
   9540 	if (bfd_is_abs_section (sec))
   9541 	  return true;
   9542 
   9543 	if (sec->owner->flags & DYNAMIC)
   9544 	  return true;
   9545       }
   9546       break;
   9547     case bfd_link_hash_common:
   9548       break;
   9549     case bfd_link_hash_indirect:
   9550       return true;
   9551     }
   9552 
   9553   /* Do not write not kept symbols.  */
   9554   if (info->strip == strip_some
   9555       && bfd_hash_lookup (info->keep_hash, h->root.root.string,
   9556 			  false, false) != NULL)
   9557     return true;
   9558 
   9559   if (h->sym == NULL)
   9560     {
   9561       /* This symbol doesn't come from a VMS object.  So we suppose it is
   9562 	 a data.  */
   9563       int len = strlen (h->root.root.string);
   9564 
   9565       sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd,
   9566 						   sizeof (*sym) + len);
   9567       if (sym == NULL)
   9568 	abort ();
   9569       sym->namelen = len;
   9570       memcpy (sym->name, h->root.root.string, len);
   9571       sym->name[len] = 0;
   9572       sym->owner = info->output_bfd;
   9573 
   9574       sym->typ = EGSD__C_SYMG;
   9575       sym->data_type = 0;
   9576       sym->flags = EGSY__V_DEF | EGSY__V_REL;
   9577       sym->symbol_vector = h->root.u.def.value;
   9578       sym->section = h->root.u.def.section;
   9579       sym->value = h->root.u.def.value;
   9580     }
   9581   else
   9582     sym = h->sym;
   9583 
   9584   if (!add_symbol_entry (info->output_bfd, sym))
   9585     return false;
   9586 
   9587   return true;
   9588 }
   9589 
   9590 static bool
   9591 alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   9592 {
   9593   asection *o;
   9594   struct bfd_link_order *p;
   9595   bfd *sub;
   9596   asection *fixupsec;
   9597   bfd_vma base_addr;
   9598   bfd_vma last_addr;
   9599   asection *dst;
   9600   asection *dmt;
   9601 
   9602   if (bfd_link_relocatable (info))
   9603     {
   9604       /* FIXME: we do not yet support relocatable link.  It is not obvious
   9605 	 how to do it for debug infos.  */
   9606       (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n"));
   9607       return false;
   9608     }
   9609 
   9610   abfd->outsymbols = NULL;
   9611   abfd->symcount = 0;
   9612 
   9613   /* Mark all sections which will be included in the output file.  */
   9614   for (o = abfd->sections; o != NULL; o = o->next)
   9615     for (p = o->map_head.link_order; p != NULL; p = p->next)
   9616       if (p->type == bfd_indirect_link_order)
   9617 	p->u.indirect.section->linker_mark = true;
   9618 
   9619 #if 0
   9620   /* Handle all the link order information for the sections.  */
   9621   for (o = abfd->sections; o != NULL; o = o->next)
   9622     {
   9623       printf ("For section %s (at 0x%08x, flags=0x%08x):\n",
   9624 	      o->name, (unsigned)o->vma, (unsigned)o->flags);
   9625 
   9626       for (p = o->map_head.link_order; p != NULL; p = p->next)
   9627 	{
   9628 	  printf (" at 0x%08x - 0x%08x: ",
   9629 		  (unsigned)p->offset, (unsigned)(p->offset + p->size - 1));
   9630 	  switch (p->type)
   9631 	    {
   9632 	    case bfd_section_reloc_link_order:
   9633 	    case bfd_symbol_reloc_link_order:
   9634 	      printf ("  section/symbol reloc\n");
   9635 	      break;
   9636 	    case bfd_indirect_link_order:
   9637 	      printf ("  section %s of %s\n",
   9638 		      p->u.indirect.section->name,
   9639 		      p->u.indirect.section->owner->filename);
   9640 	      break;
   9641 	    case bfd_data_link_order:
   9642 	      printf ("  explicit data\n");
   9643 	      break;
   9644 	    default:
   9645 	      printf ("  *unknown* type %u\n", p->type);
   9646 	      break;
   9647 	    }
   9648 	}
   9649     }
   9650 #endif
   9651 
   9652   /* Generate the symbol table.  */
   9653   BFD_ASSERT (PRIV (syms) == NULL);
   9654   if (info->strip != strip_all)
   9655     bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info);
   9656 
   9657   /* Find the entry point.  */
   9658   if (bfd_get_start_address (abfd) == 0)
   9659     {
   9660       bfd *startbfd = NULL;
   9661 
   9662       for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
   9663 	{
   9664 	  /* Consider only VMS object files.  */
   9665 	  if (sub->xvec != abfd->xvec)
   9666 	    continue;
   9667 
   9668 	  if (!PRIV2 (sub, eom_data).eom_has_transfer)
   9669 	    continue;
   9670 	  if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd)
   9671 	    continue;
   9672 	  if (startbfd != NULL
   9673 	      && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR))
   9674 	    {
   9675 	      (*info->callbacks->einfo)
   9676 		/* xgettext:c-format */
   9677 		(_("%P: multiple entry points: in modules %pB and %pB\n"),
   9678 		 startbfd, sub);
   9679 	      continue;
   9680 	    }
   9681 	  startbfd = sub;
   9682 	}
   9683 
   9684       if (startbfd)
   9685 	{
   9686 	  unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx;
   9687 	  bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr;
   9688 	  asection *sec;
   9689 
   9690 	  BFD_ASSERT (ps_idx < PRIV2 (startbfd, section_count));
   9691 	  sec = PRIV2 (startbfd, sections)[ps_idx];
   9692 
   9693 	  bfd_set_start_address
   9694 	    (abfd, sec->output_section->vma + sec->output_offset + tfradr);
   9695 	}
   9696     }
   9697 
   9698   /* Set transfer addresses.  */
   9699   {
   9700     int i;
   9701     struct bfd_link_hash_entry *h;
   9702 
   9703     i = 0;
   9704     PRIV (transfer_address[i++]) = 0xffffffff00000340ULL;	/* SYS$IMGACT */
   9705     h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", false, false, true);
   9706     if (h != NULL && h->type == bfd_link_hash_defined)
   9707       PRIV (transfer_address[i++]) =
   9708 	alpha_vms_get_sym_value (h->u.def.section, h->u.def.value);
   9709     PRIV (transfer_address[i++]) = bfd_get_start_address (abfd);
   9710     while (i < 4)
   9711       PRIV (transfer_address[i++]) = 0;
   9712   }
   9713 
   9714   /* Allocate contents.
   9715      Also compute the virtual base address.  */
   9716   base_addr = (bfd_vma)-1;
   9717   last_addr = 0;
   9718   for (o = abfd->sections; o != NULL; o = o->next)
   9719     {
   9720       if (o->flags & SEC_HAS_CONTENTS)
   9721 	{
   9722 	  o->contents = bfd_alloc (abfd, o->size);
   9723 	  if (o->contents == NULL)
   9724 	    return false;
   9725 	  o->alloced = 1;
   9726 	}
   9727       if (o->flags & SEC_LOAD)
   9728 	{
   9729 	  if (o->vma < base_addr)
   9730 	    base_addr = o->vma;
   9731 	  if (o->vma + o->size > last_addr)
   9732 	    last_addr = o->vma + o->size;
   9733 	}
   9734       /* Clear the RELOC flags.  Currently we don't support incremental
   9735 	 linking.  We use the RELOC flag for computing the eicp entries.  */
   9736       o->flags &= ~SEC_RELOC;
   9737     }
   9738 
   9739   /* Create the fixup section.  */
   9740   fixupsec = bfd_make_section_anyway_with_flags
   9741     (info->output_bfd, "$FIXUP$",
   9742      SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
   9743   if (fixupsec == NULL)
   9744     return false;
   9745   last_addr = (last_addr + 0xffff) & ~0xffff;
   9746   fixupsec->vma = last_addr;
   9747 
   9748   alpha_vms_link_hash (info)->fixup = fixupsec;
   9749   alpha_vms_link_hash (info)->base_addr = base_addr;
   9750 
   9751   /* Create the DMT section, if necessary.  */
   9752   BFD_ASSERT (PRIV (dst_section) == NULL);
   9753   dst = bfd_get_section_by_name (abfd, "$DST$");
   9754   if (dst != NULL && dst->size == 0)
   9755     dst = NULL;
   9756   if (dst != NULL)
   9757     {
   9758       PRIV (dst_section) = dst;
   9759       dmt = bfd_make_section_anyway_with_flags
   9760 	(info->output_bfd, "$DMT$",
   9761 	 SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
   9762       if (dmt == NULL)
   9763 	return false;
   9764     }
   9765   else
   9766     dmt = NULL;
   9767 
   9768   /* Read all sections from the inputs.  */
   9769   for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
   9770     {
   9771       if (sub->flags & DYNAMIC)
   9772 	{
   9773 	  alpha_vms_create_eisd_for_shared (abfd, sub);
   9774 	  continue;
   9775 	}
   9776 
   9777       if (!alpha_vms_read_sections_content (sub, info))
   9778 	return false;
   9779     }
   9780 
   9781   /* Handle all the link order information for the sections.
   9782      Note: past this point, it is not possible to create new sections.  */
   9783   for (o = abfd->sections; o != NULL; o = o->next)
   9784     {
   9785       for (p = o->map_head.link_order; p != NULL; p = p->next)
   9786 	{
   9787 	  switch (p->type)
   9788 	    {
   9789 	    case bfd_section_reloc_link_order:
   9790 	    case bfd_symbol_reloc_link_order:
   9791 	      abort ();
   9792 	      return false;
   9793 	    case bfd_indirect_link_order:
   9794 	      /* Already done.  */
   9795 	      break;
   9796 	    default:
   9797 	      if (! _bfd_default_link_order (abfd, info, o, p))
   9798 		return false;
   9799 	      break;
   9800 	    }
   9801 	}
   9802     }
   9803 
   9804   /* Compute fixups.  */
   9805   if (!alpha_vms_build_fixups (info))
   9806     return false;
   9807 
   9808   /* Compute the DMT.  */
   9809   if (dmt != NULL)
   9810     {
   9811       int pass;
   9812       unsigned char *contents = NULL;
   9813 
   9814       /* In pass 1, compute the size.  In pass 2, write the DMT contents.  */
   9815       for (pass = 0; pass < 2; pass++)
   9816 	{
   9817 	  unsigned int off = 0;
   9818 
   9819 	  /* For each object file (ie for each module).  */
   9820 	  for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
   9821 	    {
   9822 	      asection *sub_dst;
   9823 	      struct vms_dmt_header *dmth = NULL;
   9824 	      unsigned int psect_count;
   9825 
   9826 	      /* Skip this module if it has no DST.  */
   9827 	      sub_dst = PRIV2 (sub, dst_section);
   9828 	      if (sub_dst == NULL || sub_dst->size == 0)
   9829 		continue;
   9830 
   9831 	      if (pass == 1)
   9832 		{
   9833 		  /* Write the header.  */
   9834 		  dmth = (struct vms_dmt_header *)(contents + off);
   9835 		  bfd_putl32 (sub_dst->output_offset, dmth->modbeg);
   9836 		  bfd_putl32 (sub_dst->size, dmth->size);
   9837 		}
   9838 
   9839 	      off += sizeof (struct vms_dmt_header);
   9840 	      psect_count = 0;
   9841 
   9842 	      /* For each section (ie for each psect).  */
   9843 	      for (o = sub->sections; o != NULL; o = o->next)
   9844 		{
   9845 		  /* Only consider interesting sections.  */
   9846 		  if (!(o->flags & SEC_ALLOC))
   9847 		    continue;
   9848 		  if (o->flags & SEC_LINKER_CREATED)
   9849 		    continue;
   9850 
   9851 		  if (pass == 1)
   9852 		    {
   9853 		      /* Write an entry.  */
   9854 		      struct vms_dmt_psect *dmtp;
   9855 
   9856 		      dmtp = (struct vms_dmt_psect *)(contents + off);
   9857 		      bfd_putl32 (o->output_offset + o->output_section->vma,
   9858 				  dmtp->start);
   9859 		      bfd_putl32 (o->size, dmtp->length);
   9860 		      psect_count++;
   9861 		    }
   9862 		  off += sizeof (struct vms_dmt_psect);
   9863 		}
   9864 	      if (pass == 1)
   9865 		bfd_putl32 (psect_count, dmth->psect_count);
   9866 	    }
   9867 
   9868 	  if (pass == 0)
   9869 	    {
   9870 	      contents = bfd_zalloc (info->output_bfd, off);
   9871 	      if (contents == NULL)
   9872 		return false;
   9873 	      dmt->contents = contents;
   9874 	      dmt->alloced = 1;
   9875 	      dmt->size = off;
   9876 	    }
   9877 	  else
   9878 	    {
   9879 	      BFD_ASSERT (off == dmt->size);
   9880 	    }
   9881 	}
   9882     }
   9883 
   9884   return true;
   9885 }
   9886 
   9887 /* Read the contents of a section.
   9888    buf points to a buffer of buf_size bytes to be filled with
   9889    section data (starting at offset into section)  */
   9890 
   9891 static bool
   9892 alpha_vms_get_section_contents (bfd *abfd, asection *section,
   9893 				void *buf, file_ptr offset,
   9894 				bfd_size_type count)
   9895 {
   9896   /* Handle image sections.  */
   9897   if (section->filepos != 0
   9898       || (section->flags & SEC_HAS_CONTENTS) == 0)
   9899     return _bfd_generic_get_section_contents (abfd, section,
   9900 					      buf, offset, count);
   9901 
   9902   /* A section with a zero filepos implies the section has no direct
   9903      file backing.  Its contents must be calculated by processing ETIR
   9904      records.  */
   9905 
   9906   /* Safety check.  */
   9907   if (offset + count < count
   9908       || offset + count > section->size)
   9909     {
   9910       bfd_set_error (bfd_error_invalid_operation);
   9911       return false;
   9912     }
   9913 
   9914   if (section->size == 0)
   9915     return true;
   9916 
   9917   /* If we haven't yet read ETIR/EDBG/ETBT records, do so.  */
   9918   if ((section->flags & SEC_IN_MEMORY) == 0)
   9919     {
   9920       /* Alloc memory and read ETIRs.  */
   9921       for (asection *sec = abfd->sections; sec; sec = sec->next)
   9922 	{
   9923 	  if (sec->size != 0
   9924 	      && sec->filepos == 0
   9925 	      && (sec->flags & SEC_HAS_CONTENTS) != 0)
   9926 	    {
   9927 	      BFD_ASSERT (sec->contents == NULL);
   9928 
   9929 	      sec->contents = bfd_zalloc (abfd, sec->size);
   9930 	      sec->flags |= SEC_IN_MEMORY;
   9931 	      if (sec->contents == NULL)
   9932 		return false;
   9933 	      sec->alloced = 1;
   9934 	    }
   9935 	}
   9936       if (!alpha_vms_read_sections_content (abfd, NULL))
   9937 	return false;
   9938     }
   9939 
   9940   BFD_ASSERT (section->contents != NULL);
   9941   memcpy (buf, section->contents + offset, count);
   9942   return true;
   9943 }
   9944 
   9945 
   9946 /* Set the format of a file being written.  */
   9947 
   9948 static bool
   9949 alpha_vms_mkobject (bfd * abfd)
   9950 {
   9951   const bfd_arch_info_type *arch;
   9952 
   9953   vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd));
   9954 
   9955   if (!vms_initialize (abfd))
   9956     return false;
   9957 
   9958   PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE);
   9959   if (PRIV (recwr.buf) == NULL)
   9960     return false;
   9961 
   9962   arch = bfd_scan_arch ("alpha");
   9963 
   9964   if (arch == 0)
   9965     {
   9966       bfd_set_error (bfd_error_wrong_format);
   9967       return false;
   9968     }
   9969 
   9970   abfd->arch_info = arch;
   9971   return true;
   9972 }
   9973 
   9974 
   9975 /* 4.1, generic.  */
   9976 
   9977 /* Called when the BFD is being closed to do any necessary cleanup.  */
   9978 
   9979 static bool
   9980 vms_close_and_cleanup (bfd * abfd)
   9981 {
   9982   vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
   9983 
   9984   if (abfd == NULL || abfd->tdata.any == NULL)
   9985     return true;
   9986 
   9987   if (abfd->format == bfd_object)
   9988     {
   9989       alpha_vms_free_private (abfd);
   9990 
   9991 #ifdef VMS
   9992       if (abfd->direction == write_direction)
   9993 	{
   9994 	  /* Last step on VMS is to convert the file to variable record length
   9995 	     format.  */
   9996 	  if (!bfd_cache_close (abfd))
   9997 	    return false;
   9998 	  if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename))
   9999 	    return false;
   10000 	}
   10001 #endif
   10002     }
   10003 
   10004   return _bfd_generic_close_and_cleanup (abfd);
   10005 }
   10006 
   10007 /* Called when a new section is created.  */
   10008 
   10009 static bool
   10010 vms_new_section_hook (bfd * abfd, asection *section)
   10011 {
   10012   size_t amt;
   10013 
   10014   vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n",
   10015 	       abfd, section->index, section->name));
   10016 
   10017   if (!bfd_set_section_alignment (section, 0))
   10018     return false;
   10019 
   10020   vms_debug2 ((7, "%u: %s\n", section->index, section->name));
   10021 
   10022   amt = sizeof (struct vms_section_data_struct);
   10023   section->used_by_bfd = bfd_zalloc (abfd, amt);
   10024   if (section->used_by_bfd == NULL)
   10025     return false;
   10026 
   10027   /* Create the section symbol.  */
   10028   return _bfd_generic_new_section_hook (abfd, section);
   10029 }
   10030 
   10031 /* Part 4.5, symbols.  */
   10032 
   10033 /* Print symbol to file according to how. how is one of
   10034    bfd_print_symbol_name	just print the name
   10035    bfd_print_symbol_more	print more (???)
   10036    bfd_print_symbol_all	print all we know, which is not much right now :-).  */
   10037 
   10038 static void
   10039 vms_print_symbol (bfd * abfd,
   10040 		  void * file,
   10041 		  asymbol *symbol,
   10042 		  bfd_print_symbol_type how)
   10043 {
   10044   vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n",
   10045 	       abfd, file, symbol, how));
   10046 
   10047   switch (how)
   10048     {
   10049       case bfd_print_symbol_name:
   10050       case bfd_print_symbol_more:
   10051 	fprintf ((FILE *)file," %s", symbol->name);
   10052       break;
   10053 
   10054       case bfd_print_symbol_all:
   10055 	{
   10056 	  const char *section_name = symbol->section->name;
   10057 
   10058 	  bfd_print_symbol_vandf (abfd, file, symbol);
   10059 
   10060 	  fprintf ((FILE *) file," %-8s %s", section_name, symbol->name);
   10061 	}
   10062       break;
   10063     }
   10064 }
   10065 
   10066 /* Return information about symbol in ret.
   10067 
   10068    fill type, value and name
   10069    type:
   10070 	A	absolute
   10071 	B	bss segment symbol
   10072 	C	common symbol
   10073 	D	data segment symbol
   10074 	f	filename
   10075 	t	a static function symbol
   10076 	T	text segment symbol
   10077 	U	undefined
   10078 	-	debug.  */
   10079 
   10080 static void
   10081 vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
   10082 		     asymbol *symbol,
   10083 		     symbol_info *ret)
   10084 {
   10085   asection *sec;
   10086 
   10087   vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret));
   10088 
   10089   sec = symbol->section;
   10090 
   10091   if (ret == NULL)
   10092     return;
   10093 
   10094   if (sec == NULL)
   10095     ret->type = 'U';
   10096   else if (bfd_is_com_section (sec))
   10097     ret->type = 'C';
   10098   else if (bfd_is_abs_section (sec))
   10099     ret->type = 'A';
   10100   else if (bfd_is_und_section (sec))
   10101     ret->type = 'U';
   10102   else if (bfd_is_ind_section (sec))
   10103     ret->type = 'I';
   10104   else if ((symbol->flags & BSF_FUNCTION)
   10105 	   || (bfd_section_flags (sec) & SEC_CODE))
   10106     ret->type = 'T';
   10107   else if (bfd_section_flags (sec) & SEC_DATA)
   10108     ret->type = 'D';
   10109   else if (bfd_section_flags (sec) & SEC_ALLOC)
   10110     ret->type = 'B';
   10111   else
   10112     ret->type = '?';
   10113 
   10114   if (ret->type != 'U')
   10115     ret->value = symbol->value + symbol->section->vma;
   10116   else
   10117     ret->value = 0;
   10118   ret->name = symbol->name;
   10119 }
   10120 
   10121 /* Return TRUE if the given symbol sym in the BFD abfd is
   10122    a compiler generated local label, else return FALSE.  */
   10123 
   10124 static bool
   10125 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
   10126 			     const char *name)
   10127 {
   10128   return name[0] == '$';
   10129 }
   10130 
   10131 /* Part 4.7, writing an object file.  */
   10133 
   10134 /* Sets the contents of the section section in BFD abfd to the data starting
   10135    in memory at LOCATION. The data is written to the output section starting
   10136    at offset offset for count bytes.
   10137 
   10138    Normally TRUE is returned, else FALSE. Possible error returns are:
   10139    o bfd_error_no_contents - The output section does not have the
   10140 	SEC_HAS_CONTENTS attribute, so nothing can be written to it.
   10141    o and some more too  */
   10142 
   10143 static bool
   10144 _bfd_vms_set_section_contents (bfd * abfd,
   10145 			       asection *section,
   10146 			       const void * location,
   10147 			       file_ptr offset,
   10148 			       bfd_size_type count)
   10149 {
   10150   if (section->contents == NULL)
   10151     {
   10152       section->contents = bfd_alloc (abfd, section->size);
   10153       if (section->contents == NULL)
   10154 	return false;
   10155       section->alloced = 1;
   10156 
   10157       memcpy (section->contents + offset, location, (size_t) count);
   10158     }
   10159 
   10160   return true;
   10161 }
   10162 
   10163 /* Set the architecture and machine type in BFD abfd to arch and mach.
   10164    Find the correct pointer to a structure and insert it into the arch_info
   10165    pointer.  */
   10166 
   10167 static bool
   10168 alpha_vms_set_arch_mach (bfd *abfd,
   10169 			 enum bfd_architecture arch, unsigned long mach)
   10170 {
   10171   if (arch != bfd_arch_alpha
   10172       && arch != bfd_arch_unknown)
   10173     return false;
   10174 
   10175   return bfd_default_set_arch_mach (abfd, arch, mach);
   10176 }
   10177 
   10178 /* Set section VMS flags.  Clear NO_FLAGS and set FLAGS.  */
   10179 
   10180 void
   10181 bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
   10182 			   asection *sec, flagword no_flags, flagword flags)
   10183 {
   10184   vms_section_data (sec)->no_flags = no_flags;
   10185   vms_section_data (sec)->flags = flags;
   10186 }
   10187 
   10188 struct vms_private_data_struct *
   10189 bfd_vms_get_data (bfd *abfd)
   10190 {
   10191   return (struct vms_private_data_struct *)abfd->tdata.any;
   10192 }
   10193 
   10194 #define vms_bfd_copy_private_bfd_data	  _bfd_generic_bfd_copy_private_bfd_data
   10195 #define vms_bfd_merge_private_bfd_data	  _bfd_generic_bfd_merge_private_bfd_data
   10196 #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
   10197 #define vms_bfd_copy_private_symbol_data  _bfd_generic_bfd_copy_private_symbol_data
   10198 #define vms_bfd_copy_private_header_data  _bfd_generic_bfd_copy_private_header_data
   10199 #define vms_bfd_set_private_flags	  _bfd_generic_bfd_set_private_flags
   10200 
   10201 /* Symbols table.  */
   10202 #define alpha_vms_make_empty_symbol	   _bfd_generic_make_empty_symbol
   10203 #define alpha_vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
   10204 #define alpha_vms_print_symbol		   vms_print_symbol
   10205 #define alpha_vms_get_symbol_info	   vms_get_symbol_info
   10206 #define alpha_vms_get_symbol_version_string \
   10207   _bfd_nosymbols_get_symbol_version_string
   10208 
   10209 #define alpha_vms_read_minisymbols	   _bfd_generic_read_minisymbols
   10210 #define alpha_vms_minisymbol_to_symbol	   _bfd_generic_minisymbol_to_symbol
   10211 #define alpha_vms_get_lineno		   _bfd_nosymbols_get_lineno
   10212 #define alpha_vms_find_inliner_info	   _bfd_nosymbols_find_inliner_info
   10213 #define alpha_vms_bfd_make_debug_symbol	   _bfd_nosymbols_bfd_make_debug_symbol
   10214 #define alpha_vms_find_nearest_line	   _bfd_vms_find_nearest_line
   10215 #define alpha_vms_find_nearest_line_with_alt \
   10216    _bfd_nosymbols_find_nearest_line_with_alt
   10217 #define alpha_vms_find_line		   _bfd_nosymbols_find_line
   10218 #define alpha_vms_bfd_is_local_label_name  vms_bfd_is_local_label_name
   10219 
   10220 /* Generic table.  */
   10221 #define alpha_vms_close_and_cleanup	   vms_close_and_cleanup
   10222 #define alpha_vms_bfd_free_cached_info	   _bfd_bool_bfd_true
   10223 #define alpha_vms_new_section_hook	   vms_new_section_hook
   10224 #define alpha_vms_set_section_contents	   _bfd_vms_set_section_contents
   10225 
   10226 #define alpha_vms_bfd_get_relocated_section_contents \
   10227   bfd_generic_get_relocated_section_contents
   10228 
   10229 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
   10230 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
   10231 #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
   10232 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
   10233 #define alpha_vms_bfd_group_name bfd_generic_group_name
   10234 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
   10235 #define alpha_vms_section_already_linked \
   10236   _bfd_generic_section_already_linked
   10237 
   10238 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
   10239 #define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
   10240 #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop
   10241 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
   10242 #define alpha_vms_bfd_copy_link_hash_symbol_type \
   10243   _bfd_generic_copy_link_hash_symbol_type
   10244 
   10245 #define alpha_vms_bfd_link_split_section  _bfd_generic_link_split_section
   10246 
   10247 #define alpha_vms_get_dynamic_symtab_upper_bound \
   10248   _bfd_nodynamic_get_dynamic_symtab_upper_bound
   10249 #define alpha_vms_canonicalize_dynamic_symtab \
   10250   _bfd_nodynamic_canonicalize_dynamic_symtab
   10251 #define alpha_vms_get_dynamic_reloc_upper_bound \
   10252   _bfd_nodynamic_get_dynamic_reloc_upper_bound
   10253 #define alpha_vms_canonicalize_dynamic_reloc \
   10254   _bfd_nodynamic_canonicalize_dynamic_reloc
   10255 #define alpha_vms_bfd_link_check_relocs		     _bfd_generic_link_check_relocs
   10256 
   10257 const bfd_target alpha_vms_vec =
   10258 {
   10259   "vms-alpha",			/* Name.  */
   10260   bfd_target_evax_flavour,
   10261   BFD_ENDIAN_LITTLE,		/* Data byte order is little.  */
   10262   BFD_ENDIAN_LITTLE,		/* Header byte order is little.  */
   10263 
   10264   (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS
   10265    | WP_TEXT | D_PAGED),	/* Object flags.  */
   10266   (SEC_ALLOC | SEC_LOAD | SEC_RELOC
   10267    | SEC_READONLY | SEC_CODE | SEC_DATA
   10268    | SEC_HAS_CONTENTS | SEC_IN_MEMORY),		/* Sect flags.  */
   10269   0,				/* symbol_leading_char.  */
   10270   ' ',				/* ar_pad_char.  */
   10271   15,				/* ar_max_namelen.  */
   10272   0,				/* match priority.  */
   10273   TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
   10274   TARGET_MERGE_SECTIONS,
   10275   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   10276   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   10277   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
   10278   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   10279   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   10280   bfd_getl16, bfd_getl_signed_16, bfd_putl16,
   10281 
   10282   {				/* bfd_check_format.  */
   10283     _bfd_dummy_target,
   10284     alpha_vms_object_p,
   10285     _bfd_vms_lib_alpha_archive_p,
   10286     _bfd_dummy_target
   10287   },
   10288   {				/* bfd_set_format.  */
   10289     _bfd_bool_bfd_false_error,
   10290     alpha_vms_mkobject,
   10291     _bfd_vms_lib_alpha_mkarchive,
   10292     _bfd_bool_bfd_false_error
   10293   },
   10294   {				/* bfd_write_contents.  */
   10295     _bfd_bool_bfd_false_error,
   10296     alpha_vms_write_object_contents,
   10297     _bfd_vms_lib_write_archive_contents,
   10298     _bfd_bool_bfd_false_error
   10299   },
   10300 
   10301   BFD_JUMP_TABLE_GENERIC (alpha_vms),
   10302   BFD_JUMP_TABLE_COPY (vms),
   10303   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   10304   BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib),
   10305   BFD_JUMP_TABLE_SYMBOLS (alpha_vms),
   10306   BFD_JUMP_TABLE_RELOCS (alpha_vms),
   10307   BFD_JUMP_TABLE_WRITE (alpha_vms),
   10308   BFD_JUMP_TABLE_LINK (alpha_vms),
   10309   BFD_JUMP_TABLE_DYNAMIC (alpha_vms),
   10310 
   10311   NULL,
   10312 
   10313   NULL
   10314 };
   10315