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