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