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