Coverage Report

Created: 2025-07-08 11:15

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