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