Coverage Report

Created: 2025-06-24 06:45

/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
218
#define DST_S_C_LINE_NUM_HEADER_SIZE 4
101
102
/* These are used with DST_S_C_SOURCE */
103
104
12.7k
#define DST_S_B_PCLINE_UNSBYTE   1
105
40.7k
#define DST_S_W_PCLINE_UNSWORD   1
106
9.58k
#define DST_S_L_PCLINE_UNSLONG   1
107
108
68
#define DST_S_B_MODBEG_NAME 14
109
6
#define DST_S_L_RTNBEG_ADDRESS   5
110
24
#define DST_S_B_RTNBEG_NAME 13
111
22
#define DST_S_L_RTNEND_SIZE  5
112
113
/* These are used with DST_S_C_SOURCE.  */
114
178
#define DST_S_C_SOURCE_HEADER_SIZE 4
115
116
4.80k
#define DST_S_B_SRC_DF_LENGTH   1
117
2.39k
#define DST_S_W_SRC_DF_FILEID   3
118
4.78k
#define DST_S_B_SRC_DF_FILENAME  20
119
670
#define DST_S_B_SRC_UNSBYTE   1
120
2.02k
#define DST_S_W_SRC_UNSWORD   1
121
928
#define DST_S_L_SRC_UNSLONG   1
122
123
/* Debugger symbol definitions.  */
124
125
2.29k
#define DBG_S_L_DMT_MODBEG   0
126
2.29k
#define DBG_S_L_DST_SIZE   4
127
2.29k
#define DBG_S_W_DMT_PSECT_COUNT  8
128
4.88k
#define DBG_S_C_DMT_HEADER_SIZE 12
129
130
13.7k
#define DBG_S_L_DMT_PSECT_START  0
131
13.7k
#define DBG_S_L_DMT_PSECT_LENGTH 4
132
27.8k
#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
3.47M
#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
66.9M
  (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
342
66.9M
#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
9.63k
  ((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
22.8k
{
470
22.8k
  unsigned int imgtype, size;
471
22.8k
  bfd_vma symvva;
472
22.8k
  struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
473
474
22.8k
  vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
475
476
  /* PR 21813: Check for an undersized record.  */
477
22.8k
  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
22.8k
  size = bfd_getl32 (eihd->size);
485
22.8k
  imgtype = bfd_getl32 (eihd->imgtype);
486
487
22.8k
  if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
488
2.76k
    abfd->flags |= EXEC_P;
489
490
22.8k
  symvva = bfd_getl64 (eihd->symvva);
491
22.8k
  if (symvva != 0)
492
19.6k
    {
493
19.6k
      PRIV (symvva) = symvva;
494
19.6k
      abfd->flags |= DYNAMIC;
495
19.6k
    }
496
497
22.8k
  PRIV (ident) = bfd_getl32 (eihd->ident);
498
22.8k
  PRIV (matchctl) = eihd->matchctl;
499
500
22.8k
  *eisd_offset = bfd_getl32 (eihd->isdoff);
501
22.8k
  *eihs_offset = bfd_getl32 (eihd->symdbgoff);
502
503
22.8k
  vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
504
22.8k
         size, imgtype, (unsigned long)symvva,
505
22.8k
         *eisd_offset, *eihs_offset));
506
22.8k
  (void) size;
507
508
22.8k
  return true;
509
22.8k
}
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
22.8k
{
517
22.8k
  int section_count = 0;
518
519
22.8k
  vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
520
521
39.3k
  while (1)
522
39.3k
    {
523
39.3k
      struct vms_eisd *eisd;
524
39.3k
      unsigned int rec_size;
525
39.3k
      unsigned int size;
526
39.3k
      uint64_t vaddr;
527
39.3k
      unsigned int flags;
528
39.3k
      unsigned int vbn;
529
39.3k
      char *name = NULL;
530
39.3k
      asection *section;
531
39.3k
      flagword bfd_flags;
532
533
      /* PR 17512: file: 3d9e9fe9.  */
534
39.3k
      if (offset > PRIV (recrd.rec_size)
535
39.3k
    || (PRIV (recrd.rec_size) - offset
536
38.1k
        < offsetof (struct vms_eisd, eisdsize) + 4))
537
2.25k
  return false;
538
37.1k
      eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset);
539
37.1k
      rec_size = bfd_getl32 (eisd->eisdsize);
540
37.1k
      if (rec_size == 0)
541
15.3k
  break;
542
543
      /* Skip to next block if pad.  */
544
21.7k
      if (rec_size == 0xffffffff)
545
1.91k
  {
546
1.91k
    offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
547
1.91k
    continue;
548
1.91k
  }
549
550
      /* Make sure that there is enough data present in the record.  */
551
19.8k
      if (rec_size < offsetof (struct vms_eisd, type) + 1)
552
530
  return false;
553
      /* Make sure that the record is not too big either.  */
554
19.2k
      if (rec_size > PRIV (recrd.rec_size) - offset)
555
2.72k
  return false;
556
557
16.5k
      offset += rec_size;
558
559
16.5k
      size = bfd_getl32 (eisd->secsize);
560
16.5k
      vaddr = bfd_getl64 (eisd->virt_addr);
561
16.5k
      flags = bfd_getl32 (eisd->flags);
562
16.5k
      vbn = bfd_getl32 (eisd->vbn);
563
564
16.5k
      vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n",
565
16.5k
       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
16.5k
      bfd_flags = SEC_ALLOC;
572
16.5k
      if (vbn != 0)
573
12.4k
  bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD;
574
575
16.5k
      if (flags & EISD__M_EXE)
576
7.65k
  bfd_flags |= SEC_CODE;
577
578
16.5k
      if (flags & EISD__M_NONSHRADR)
579
6.27k
  bfd_flags |= SEC_DATA;
580
581
16.5k
      if (!(flags & EISD__M_WRT))
582
10.4k
  bfd_flags |= SEC_READONLY;
583
584
16.5k
      if (flags & EISD__M_DZRO)
585
6.35k
  bfd_flags |= SEC_DATA;
586
587
16.5k
      if (flags & EISD__M_FIXUPVEC)
588
4.68k
  bfd_flags |= SEC_DATA;
589
590
16.5k
      if (flags & EISD__M_CRF)
591
7.80k
  bfd_flags |= SEC_DATA;
592
593
16.5k
      if (flags & EISD__M_GBL)
594
4.17k
  {
595
4.17k
    if (rec_size <= offsetof (struct vms_eisd, gblnam))
596
416
      return false;
597
3.75k
    else if (rec_size < sizeof (struct vms_eisd))
598
1.86k
      name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
599
1.86k
             rec_size - offsetof (struct vms_eisd, gblnam));
600
1.89k
    else
601
1.89k
      name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
602
1.89k
             EISD__K_GBLNAMLEN);
603
3.75k
    if (name == NULL || name[0] == 0)
604
1.06k
      return false;
605
2.68k
    bfd_flags |= SEC_COFF_SHARED_LIBRARY;
606
2.68k
    bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
607
2.68k
  }
608
12.3k
      else if (flags & EISD__M_FIXUPVEC)
609
2.04k
  name = "$FIXUPVEC$";
610
10.3k
      else if (eisd->type == EISD__K_USRSTACK)
611
791
  name = "$STACK$";
612
9.55k
      else
613
9.55k
  {
614
9.55k
    const char *pfx;
615
616
9.55k
    name = (char *) bfd_alloc (abfd, 32);
617
9.55k
    if (name == NULL)
618
0
      return false;
619
9.55k
    if (flags & EISD__M_DZRO)
620
1.93k
      pfx = "BSS";
621
7.62k
    else if (flags & EISD__M_EXE)
622
2.47k
      pfx = "CODE";
623
5.14k
    else if (!(flags & EISD__M_WRT))
624
3.64k
      pfx = "RO";
625
1.49k
    else
626
1.49k
      pfx = "LOCAL";
627
9.55k
    BFD_ASSERT (section_count < 999);
628
9.55k
    sprintf (name, "$%s_%03d$", pfx, section_count++);
629
9.55k
  }
630
631
15.0k
      section = bfd_make_section (abfd, name);
632
633
15.0k
      if (!section)
634
425
  return false;
635
636
14.6k
      section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
637
14.6k
      section->size = size;
638
14.6k
      section->vma = vaddr;
639
640
14.6k
      if (!bfd_set_section_flags (section, bfd_flags))
641
0
  return false;
642
14.6k
    }
643
644
15.3k
  return true;
645
22.8k
}
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
10.3k
{
653
10.3k
  unsigned char *p = PRIV (recrd.rec) + offset;
654
10.3k
  unsigned int gstvbn;
655
10.3k
  unsigned int gstsize ATTRIBUTE_UNUSED;
656
10.3k
  unsigned int dstvbn;
657
10.3k
  unsigned int dstsize;
658
10.3k
  unsigned int dmtvbn;
659
10.3k
  unsigned int dmtbytes;
660
10.3k
  asection *section;
661
662
  /* PR 21611: Check that offset is valid.  */
663
10.3k
  if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4))
664
548
    {
665
548
      _bfd_error_handler (_("unable to read EIHS record at offset %#x"),
666
548
        offset);
667
548
      bfd_set_error (bfd_error_file_truncated);
668
548
      return false;
669
548
    }
670
671
9.82k
  gstvbn   = bfd_getl32 (p + EIHS__L_GSTVBN);
672
9.82k
  gstsize  = bfd_getl32 (p + EIHS__L_GSTSIZE);
673
9.82k
  dstvbn   = bfd_getl32 (p + EIHS__L_DSTVBN);
674
9.82k
  dstsize  = bfd_getl32 (p + EIHS__L_DSTSIZE);
675
9.82k
  dmtvbn   = bfd_getl32 (p + EIHS__L_DMTVBN);
676
9.82k
  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
9.82k
  if (dstvbn)
685
7.03k
    {
686
7.03k
      flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
687
688
7.03k
      section = bfd_make_section (abfd, "$DST$");
689
7.03k
      if (!section)
690
0
  return false;
691
692
7.03k
      section->size = dstsize;
693
7.03k
      section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
694
695
7.03k
      if (!bfd_set_section_flags (section, bfd_flags))
696
0
  return false;
697
698
7.03k
      PRIV (dst_section) = section;
699
7.03k
      abfd->flags |= (HAS_DEBUG | HAS_LINENO);
700
7.03k
    }
701
702
9.82k
  if (dmtvbn)
703
6.70k
    {
704
6.70k
      flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
705
706
6.70k
      section = bfd_make_section (abfd, "$DMT$");
707
6.70k
      if (!section)
708
2
  return false;
709
710
6.70k
      section->size = dmtbytes;
711
6.70k
      section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
712
713
6.70k
      if (!bfd_set_section_flags (section, bfd_flags))
714
0
  return false;
715
6.70k
    }
716
717
9.82k
  if (gstvbn)
718
2.27k
    {
719
2.27k
      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
2.27k
      if (!_bfd_vms_slurp_object_records (abfd))
726
1.92k
  return false;
727
728
354
      abfd->flags |= HAS_SYMS;
729
354
    }
730
731
7.90k
  return true;
732
9.82k
}
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
601k
#define VMS_OBJECT_ADJUSTMENT  2
772
773
static void
774
maybe_adjust_record_pointer_for_object (bfd *abfd)
775
3.74M
{
776
  /* Set the file format once for all on the first invocation.  */
777
3.74M
  if (PRIV (recrd.file_format) == FF_UNKNOWN)
778
3.36M
    {
779
3.36M
      if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4]
780
3.36M
    && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5])
781
186k
  PRIV (recrd.file_format) = FF_FOREIGN;
782
3.18M
      else
783
3.18M
  PRIV (recrd.file_format) = FF_NATIVE;
784
3.36M
    }
785
786
  /* The adjustment is needed only in an Unix environment.  */
787
3.74M
  if (PRIV (recrd.file_format) == FF_FOREIGN)
788
433k
    PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT;
789
3.74M
}
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
142k
{
797
142k
  unsigned int test_len = 6;
798
142k
  int type;
799
800
142k
  vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
801
802
  /* Skip alignment byte if the current position is odd.  */
803
142k
  if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1))
804
8.50k
    {
805
8.50k
      if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1)
806
343
  {
807
343
    bfd_set_error (bfd_error_file_truncated);
808
343
    return -1;
809
343
  }
810
8.50k
    }
811
812
  /* Read the record header  */
813
142k
  if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len)
814
5.17k
    {
815
5.17k
      bfd_set_error (bfd_error_file_truncated);
816
5.17k
      return -1;
817
5.17k
    }
818
819
  /* Reset the record pointer.  */
820
137k
  PRIV (recrd.rec) = PRIV (recrd.buf);
821
137k
  maybe_adjust_record_pointer_for_object (abfd);
822
823
137k
  if (vms_get_remaining_object_record (abfd, test_len) <= 0)
824
20.2k
    return -1;
825
826
116k
  type = bfd_getl16 (PRIV (recrd.rec));
827
828
116k
  vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n",
829
116k
         PRIV (recrd.rec), PRIV (recrd.rec_size), type));
830
831
116k
  return type;
832
137k
}
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
286k
{
840
286k
  unsigned int to_read;
841
842
286k
  vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
843
844
  /* Extract record size.  */
845
286k
  PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
846
847
286k
  if (PRIV (recrd.rec_size) == 0)
848
10.8k
    {
849
10.8k
      bfd_set_error (bfd_error_file_truncated);
850
10.8k
      return 0;
851
10.8k
    }
852
853
  /* That's what the linker manual says.  */
854
275k
  if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
855
9.38k
    {
856
9.38k
      bfd_set_error (bfd_error_file_truncated);
857
9.38k
      return 0;
858
9.38k
    }
859
860
  /* Take into account object adjustment.  */
861
266k
  to_read = PRIV (recrd.rec_size);
862
266k
  if (PRIV (recrd.file_format) == FF_FOREIGN)
863
167k
    to_read += VMS_OBJECT_ADJUSTMENT;
864
865
  /* Adjust the buffer.  */
866
266k
  if (to_read > PRIV (recrd.buf_size))
867
160k
    {
868
160k
      PRIV (recrd.buf)
869
160k
  = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read);
870
160k
      if (PRIV (recrd.buf) == NULL)
871
0
  return 0;
872
160k
      PRIV (recrd.buf_size) = to_read;
873
160k
    }
874
  /* PR 17512: file: 025-1974-0.004.  */
875
106k
  else if (to_read <= read_so_far)
876
2.50k
    return 0;
877
878
  /* Read the remaining record.  */
879
263k
  to_read -= read_so_far;
880
881
263k
  vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
882
883
263k
  if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
884
27.5k
    {
885
27.5k
      bfd_set_error (bfd_error_file_truncated);
886
27.5k
      return 0;
887
27.5k
    }
888
889
  /* Reset the record pointer.  */
890
236k
  PRIV (recrd.rec) = PRIV (recrd.buf);
891
236k
  maybe_adjust_record_pointer_for_object (abfd);
892
893
236k
  vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
894
236k
         PRIV (recrd.rec_size)));
895
896
236k
  return PRIV (recrd.rec_size);
897
263k
}
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
123k
{
905
123k
  unsigned char *ptr;
906
123k
  unsigned char *vms_rec;
907
123k
  unsigned char *end;
908
123k
  int subtype;
909
910
123k
  vms_rec = PRIV (recrd.rec);
911
  /* PR 17512: file: 62736583.  */
912
123k
  end = PRIV (recrd.buf) + PRIV (recrd.buf_size);
913
914
123k
  vms_debug2 ((2, "HDR/EMH\n"));
915
916
123k
  subtype = bfd_getl16 (vms_rec + 4);
917
918
123k
  vms_debug2 ((3, "subtype %d\n", subtype));
919
920
123k
  switch (subtype)
921
123k
    {
922
50.0k
    case EMH__C_MHD:
923
      /* Module header.  */
924
50.0k
      if (vms_rec + 21 >= end)
925
421
  goto fail;
926
49.6k
      PRIV (hdr_data).hdr_b_strlvl = vms_rec[6];
927
49.6k
      PRIV (hdr_data).hdr_l_arch1  = bfd_getl32 (vms_rec + 8);
928
49.6k
      PRIV (hdr_data).hdr_l_arch2  = bfd_getl32 (vms_rec + 12);
929
49.6k
      PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
930
49.6k
      if ((vms_rec + 20 + vms_rec[20] + 1) >= end)
931
1.49k
  goto fail;
932
48.1k
      PRIV (hdr_data).hdr_t_name
933
48.1k
  = _bfd_vms_save_counted_string (abfd, vms_rec + 20, vms_rec[20]);
934
48.1k
      ptr = vms_rec + 20 + vms_rec[20] + 1;
935
48.1k
      if ((ptr + *ptr + 1) >= end)
936
1.49k
  goto fail;
937
46.6k
      PRIV (hdr_data).hdr_t_version
938
46.6k
  = _bfd_vms_save_counted_string (abfd, ptr, *ptr);
939
46.6k
      ptr += *ptr + 1;
940
46.6k
      if (ptr + 17 >= end)
941
1.70k
  goto fail;
942
44.9k
      PRIV (hdr_data).hdr_t_date
943
44.9k
  = _bfd_vms_save_sized_string (abfd, ptr, 17);
944
44.9k
      break;
945
946
33.6k
    case EMH__C_LNM:
947
33.6k
      if (vms_rec + PRIV (recrd.rec_size - 6) > end)
948
2
  goto fail;
949
33.6k
      PRIV (hdr_data).hdr_c_lnm
950
33.6k
  = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
951
33.6k
      break;
952
953
8.18k
    case EMH__C_SRC:
954
8.18k
      if (vms_rec + PRIV (recrd.rec_size - 6) > end)
955
240
  goto fail;
956
7.94k
      PRIV (hdr_data).hdr_c_src
957
7.94k
  = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
958
7.94k
      break;
959
960
13.5k
    case EMH__C_TTL:
961
13.5k
      if (vms_rec + PRIV (recrd.rec_size - 6) > end)
962
715
  goto fail;
963
12.8k
      PRIV (hdr_data).hdr_c_ttl
964
12.8k
  = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6));
965
12.8k
      break;
966
967
4.75k
    case EMH__C_CPR:
968
11.2k
    case EMH__C_MTC:
969
15.6k
    case EMH__C_GTX:
970
15.6k
      break;
971
972
1.93k
    default:
973
8.00k
    fail:
974
8.00k
      bfd_set_error (bfd_error_wrong_format);
975
8.00k
      return false;
976
123k
    }
977
978
114k
  return true;
979
123k
}
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.81k
{
1072
4.81k
  int i = 0;
1073
1074
49.8k
  while (section_flags[i].name != NULL)
1075
45.6k
    {
1076
45.6k
      if (strcmp (name, section_flags[i].name) == 0)
1077
551
  {
1078
551
    if (hassize)
1079
549
      return section_flags[i].flags_hassize;
1080
2
    else
1081
2
      return section_flags[i].flags_always;
1082
551
  }
1083
45.0k
      i++;
1084
45.0k
    }
1085
4.26k
  if (hassize)
1086
4.05k
    return section_flags[i].flags_hassize;
1087
210
  return section_flags[i].flags_always;
1088
4.26k
}
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
6.61k
{
1121
6.61k
  if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
1122
5.91k
    {
1123
5.91k
      if (PRIV (max_sym_count) == 0)
1124
5.91k
  {
1125
5.91k
    PRIV (max_sym_count) = 128;
1126
5.91k
    PRIV (syms) = bfd_malloc
1127
5.91k
      (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
1128
5.91k
  }
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
5.91k
      if (PRIV (syms) == NULL)
1137
0
  return false;
1138
5.91k
    }
1139
1140
6.61k
  PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
1141
6.61k
  return true;
1142
6.61k
}
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
8.05k
{
1150
8.05k
  struct vms_symbol_entry *entry;
1151
8.05k
  unsigned int len;
1152
1153
8.05k
  len = *ascic++;
1154
8.05k
  max -= 1;
1155
8.05k
  if (len > max)
1156
1.44k
    {
1157
1.44k
      _bfd_error_handler (_("record is too small for symbol name length"));
1158
1.44k
      bfd_set_error (bfd_error_bad_value);
1159
1.44k
      return NULL;
1160
1.44k
    }
1161
1162
6.61k
  entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
1163
6.61k
  if (entry == NULL)
1164
0
    return NULL;
1165
6.61k
  entry->namelen = len;
1166
6.61k
  memcpy (entry->name, ascic, len);
1167
6.61k
  entry->name[len] = 0;
1168
6.61k
  entry->owner = abfd;
1169
1170
6.61k
  if (!add_symbol_entry (abfd, entry))
1171
0
    return NULL;
1172
6.61k
  return entry;
1173
6.61k
}
1174
1175
/* Read and process EGSD.  Return FALSE on failure.  */
1176
1177
static bool
1178
_bfd_vms_slurp_egsd (bfd *abfd)
1179
22.0k
{
1180
22.0k
  int gsd_type;
1181
22.0k
  unsigned int gsd_size;
1182
22.0k
  unsigned char *vms_rec;
1183
22.0k
  bfd_vma base_addr;
1184
22.0k
  long psindx;
1185
1186
22.0k
  vms_debug2 ((2, "EGSD\n"));
1187
1188
22.0k
  if (PRIV (recrd.rec_size) < 8)
1189
683
    {
1190
683
      _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"),
1191
683
        PRIV (recrd.rec_size));
1192
683
      bfd_set_error (bfd_error_bad_value);
1193
683
      return false;
1194
683
    }
1195
1196
21.4k
  PRIV (recrd.rec) += 8;  /* Skip type, size, align pad.  */
1197
21.4k
  PRIV (recrd.rec_size) -= 8;
1198
1199
  /* Calculate base address for each section.  */
1200
21.4k
  base_addr = 0;
1201
1202
41.8k
  while (PRIV (recrd.rec_size) > 4)
1203
38.3k
    {
1204
38.3k
      vms_rec = PRIV (recrd.rec);
1205
1206
38.3k
      gsd_type = bfd_getl16 (vms_rec);
1207
38.3k
      gsd_size = bfd_getl16 (vms_rec + 2);
1208
1209
38.3k
      vms_debug2 ((3, "egsd_type %d\n", gsd_type));
1210
1211
      /* PR 21615: Check for size overflow.  */
1212
38.3k
      if (PRIV (recrd.rec_size) < gsd_size)
1213
5.34k
  {
1214
5.34k
    _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
1215
5.34k
        "is larger than remaining space (%#x)"),
1216
5.34k
            gsd_type, gsd_size, PRIV (recrd.rec_size));
1217
5.34k
    bfd_set_error (bfd_error_bad_value);
1218
5.34k
    return false;
1219
5.34k
  }
1220
1221
33.0k
      if (gsd_size < 4)
1222
2.50k
  {
1223
5.17k
  too_small:
1224
5.17k
    _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
1225
5.17k
        "is too small"),
1226
5.17k
            gsd_type, gsd_size);
1227
5.17k
    bfd_set_error (bfd_error_bad_value);
1228
5.17k
    return false;
1229
2.50k
  }
1230
1231
30.5k
      switch (gsd_type)
1232
30.5k
  {
1233
14.6k
  case EGSD__C_PSC:
1234
    /* Program section definition.  */
1235
14.6k
    {
1236
14.6k
      struct vms_egps *egps = (struct vms_egps *) vms_rec;
1237
14.6k
      flagword new_flags, vms_flags;
1238
14.6k
      asection *section;
1239
1240
14.6k
      if (offsetof (struct vms_egps, flags) + 2 > gsd_size)
1241
788
        goto too_small;
1242
13.8k
      vms_flags = bfd_getl16 (egps->flags);
1243
1244
13.8k
      if ((vms_flags & EGPS__V_REL) == 0)
1245
6.40k
        {
1246
    /* Use the global absolute section for all
1247
       absolute sections.  */
1248
6.40k
    section = bfd_abs_section_ptr;
1249
6.40k
        }
1250
7.46k
      else
1251
7.46k
        {
1252
7.46k
    char *name;
1253
7.46k
    bfd_vma align_addr;
1254
7.46k
    size_t left;
1255
1256
7.46k
    if (offsetof (struct vms_egps, namlng) >= gsd_size)
1257
453
      goto too_small;
1258
7.01k
    left = gsd_size - offsetof (struct vms_egps, namlng);
1259
7.01k
    name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left);
1260
7.01k
    if (name == NULL || name[0] == 0)
1261
1.68k
      return false;
1262
1263
5.33k
    section = bfd_make_section (abfd, name);
1264
5.33k
    if (!section)
1265
516
      return false;
1266
1267
4.81k
    section->filepos = 0;
1268
4.81k
    section->size = bfd_getl32 (egps->alloc);
1269
4.81k
    section->alignment_power = egps->align & 31;
1270
1271
4.81k
    vms_section_data (section)->flags = vms_flags;
1272
4.81k
    vms_section_data (section)->no_flags = 0;
1273
1274
4.81k
    new_flags = vms_secflag_by_name (evax_section_flags,
1275
4.81k
             section->name,
1276
4.81k
             section->size > 0);
1277
4.81k
    if (section->size > 0)
1278
4.60k
      new_flags |= SEC_LOAD;
1279
4.81k
    if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0)
1280
2.87k
      {
1281
        /* Set RELOC and HAS_CONTENTS if the section is not
1282
           demand-zero and not empty.  */
1283
2.87k
        new_flags |= SEC_HAS_CONTENTS;
1284
2.87k
        if (vms_flags & EGPS__V_REL)
1285
2.87k
          new_flags |= SEC_RELOC;
1286
2.87k
      }
1287
4.81k
    if (vms_flags & EGPS__V_EXE)
1288
2.24k
      {
1289
        /* Set CODE if section is executable.  */
1290
2.24k
        new_flags |= SEC_CODE;
1291
2.24k
        new_flags &= ~SEC_DATA;
1292
2.24k
      }
1293
4.81k
    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.81k
    align_addr = (bfd_vma) 1 << section->alignment_power;
1298
4.81k
    base_addr = (base_addr + align_addr - 1) & -align_addr;
1299
4.81k
    section->vma = base_addr;
1300
4.81k
    base_addr += section->size;
1301
4.81k
        }
1302
1303
      /* Append it to the section array.  */
1304
11.2k
      if (PRIV (section_count) >= PRIV (section_max))
1305
8.95k
        {
1306
8.95k
    if (PRIV (section_max) == 0)
1307
8.95k
      PRIV (section_max) = 16;
1308
0
    else
1309
0
      PRIV (section_max) *= 2;
1310
8.95k
    PRIV (sections) = bfd_realloc_or_free
1311
8.95k
      (PRIV (sections), PRIV (section_max) * sizeof (asection *));
1312
8.95k
    if (PRIV (sections) == NULL)
1313
0
      return false;
1314
8.95k
        }
1315
1316
11.2k
      PRIV (sections)[PRIV (section_count)] = section;
1317
11.2k
      PRIV (section_count)++;
1318
11.2k
    }
1319
0
    break;
1320
1321
4.38k
  case EGSD__C_SYM:
1322
4.38k
    {
1323
4.38k
      unsigned int nameoff;
1324
4.38k
      struct vms_symbol_entry *entry;
1325
4.38k
      struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
1326
4.38k
      flagword old_flags;
1327
1328
4.38k
      if (offsetof (struct vms_egsy, flags) + 2 > gsd_size)
1329
214
        goto too_small;
1330
4.17k
      old_flags = bfd_getl16 (egsy->flags);
1331
4.17k
      if (old_flags & EGSY__V_DEF)
1332
2.25k
        nameoff = ESDF__B_NAMLNG;
1333
1.91k
      else
1334
1.91k
        nameoff = ESRF__B_NAMLNG;
1335
1336
4.17k
      if (nameoff >= gsd_size)
1337
551
        goto too_small;
1338
3.62k
      entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff);
1339
3.62k
      if (entry == NULL)
1340
555
        return false;
1341
1342
      /* Allow only duplicate reference.  */
1343
3.06k
      if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
1344
0
        abort ();
1345
1346
3.06k
      if (entry->typ == 0)
1347
3.06k
        {
1348
3.06k
    entry->typ = gsd_type;
1349
3.06k
    entry->data_type = egsy->datyp;
1350
3.06k
    entry->flags = old_flags;
1351
3.06k
        }
1352
1353
3.06k
      if (old_flags & EGSY__V_DEF)
1354
1.70k
        {
1355
1.70k
    struct vms_esdf *esdf = (struct vms_esdf *) vms_rec;
1356
1357
1.70k
    entry->value = bfd_getl64 (esdf->value);
1358
1.70k
    if (PRIV (sections) == NULL)
1359
650
      return false;
1360
1361
1.05k
    psindx = bfd_getl32 (esdf->psindx);
1362
    /* PR 21813: Check for an out of range index.  */
1363
1.05k
    if (psindx < 0 || psindx >= (int) PRIV (section_count))
1364
410
      {
1365
636
      bad_psindx:
1366
636
        _bfd_error_handler (_("corrupt EGSD record: its psindx "
1367
636
            "field is too big (%#lx)"),
1368
636
          psindx);
1369
636
        bfd_set_error (bfd_error_bad_value);
1370
636
        return false;
1371
410
      }
1372
642
    entry->section = PRIV (sections)[psindx];
1373
1374
642
    if (old_flags & EGSY__V_NORM)
1375
424
      {
1376
424
        PRIV (norm_sym_count)++;
1377
1378
424
        entry->code_value = bfd_getl64 (esdf->code_address);
1379
424
        psindx = bfd_getl32 (esdf->ca_psindx);
1380
        /* PR 21813: Check for an out of range index.  */
1381
424
        if (psindx < 0 || psindx >= (int) PRIV (section_count))
1382
212
          goto bad_psindx;
1383
212
        entry->code_section = PRIV (sections)[psindx];
1384
212
      }
1385
642
        }
1386
3.06k
    }
1387
1.79k
    break;
1388
1389
5.08k
  case EGSD__C_SYMG:
1390
5.08k
    {
1391
5.08k
      struct vms_symbol_entry *entry;
1392
5.08k
      struct vms_egst *egst = (struct vms_egst *)vms_rec;
1393
5.08k
      flagword old_flags;
1394
5.08k
      unsigned int nameoff = offsetof (struct vms_egst, namlng);
1395
1396
5.08k
      if (nameoff >= gsd_size)
1397
656
        goto too_small;
1398
4.42k
      entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff);
1399
4.42k
      if (entry == NULL)
1400
885
        return false;
1401
1402
3.54k
      old_flags = bfd_getl16 (egst->header.flags);
1403
3.54k
      entry->typ = gsd_type;
1404
3.54k
      entry->data_type = egst->header.datyp;
1405
3.54k
      entry->flags = old_flags;
1406
1407
3.54k
      entry->symbol_vector = bfd_getl32 (egst->value);
1408
1409
3.54k
      if (old_flags & EGSY__V_REL)
1410
906
        {
1411
906
    if (PRIV (sections) == NULL)
1412
885
      return false;
1413
21
    psindx = bfd_getl32 (egst->psindx);
1414
    /* PR 21813: Check for an out of range index.  */
1415
21
    if (psindx < 0 || psindx >= (int) PRIV (section_count))
1416
14
      goto bad_psindx;
1417
7
    entry->section = PRIV (sections)[psindx];
1418
7
        }
1419
2.63k
      else
1420
2.63k
        entry->section = bfd_abs_section_ptr;
1421
1422
2.64k
      entry->value = bfd_getl64 (egst->lp_2);
1423
1424
2.64k
      if (old_flags & EGSY__V_NORM)
1425
963
        {
1426
963
    PRIV (norm_sym_count)++;
1427
1428
963
    entry->code_value = bfd_getl64 (egst->lp_1);
1429
963
    entry->code_section = bfd_abs_section_ptr;
1430
963
        }
1431
2.64k
    }
1432
0
    break;
1433
1434
582
  case EGSD__C_SPSC:
1435
4.74k
  case EGSD__C_IDC:
1436
    /* Currently ignored.  */
1437
4.74k
    break;
1438
0
  case EGSD__C_SYMM:
1439
0
  case EGSD__C_SYMV:
1440
1.67k
  default:
1441
1.67k
    _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type);
1442
1.67k
    bfd_set_error (bfd_error_bad_value);
1443
1.67k
    return false;
1444
30.5k
  }
1445
1446
20.4k
      PRIV (recrd.rec_size) -= gsd_size;
1447
20.4k
      PRIV (recrd.rec) += gsd_size;
1448
20.4k
    }
1449
1450
  /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ?  */
1451
1452
3.41k
  if (PRIV (gsd_sym_count) > 0)
1453
1.22k
    abfd->flags |= HAS_SYMS;
1454
1455
3.41k
  return true;
1456
21.4k
}
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
58.1k
{
1465
58.1k
  vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
1466
58.1k
         (unsigned long)val, reloc, PRIV (stackptr)));
1467
1468
58.1k
  PRIV (stack[PRIV (stackptr)]).value = val;
1469
58.1k
  PRIV (stack[PRIV (stackptr)]).reloc = reloc;
1470
58.1k
  PRIV (stackptr)++;
1471
58.1k
  if (PRIV (stackptr) >= STACKSIZE)
1472
1
    {
1473
1
      bfd_set_error (bfd_error_bad_value);
1474
1
      _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
1475
1
      return false;
1476
1
    }
1477
58.1k
  return true;
1478
58.1k
}
1479
1480
/* Pop value and section index.  */
1481
1482
static bool
1483
_bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
1484
49.6k
{
1485
49.6k
  if (PRIV (stackptr) == 0)
1486
17.0k
    {
1487
17.0k
      bfd_set_error (bfd_error_bad_value);
1488
17.0k
      _bfd_error_handler (_("stack underflow in _bfd_vms_pop"));
1489
17.0k
      return false;
1490
17.0k
    }
1491
32.6k
  PRIV (stackptr)--;
1492
32.6k
  *val = PRIV (stack[PRIV (stackptr)]).value;
1493
32.6k
  *rel = PRIV (stack[PRIV (stackptr)]).reloc;
1494
1495
32.6k
  vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
1496
32.6k
  return true;
1497
49.6k
}
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.64k
{
1546
2.64k
  vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
1547
1548
2.64k
  PRIV (image_offset) += offset;
1549
2.64k
}
1550
1551
/* Save current DST location counter under specified index.  */
1552
1553
static bool
1554
dst_define_location (bfd *abfd, unsigned int loc)
1555
624
{
1556
624
  vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
1557
1558
624
  if (loc > 1 << 24)
1559
240
    {
1560
      /* 16M entries ought to be plenty.  */
1561
240
      bfd_set_error (bfd_error_bad_value);
1562
240
      _bfd_error_handler (_("dst_define_location %u too large"), loc);
1563
240
      return false;
1564
240
    }
1565
1566
  /* Grow the ptr offset table if necessary.  */
1567
384
  if (loc + 1 > PRIV (dst_ptr_offsets_count))
1568
338
    {
1569
338
      PRIV (dst_ptr_offsets)
1570
338
  = bfd_realloc_or_free (PRIV (dst_ptr_offsets),
1571
338
             (loc + 1) * sizeof (unsigned int));
1572
338
      if (PRIV (dst_ptr_offsets) == NULL)
1573
0
  return false;
1574
338
      memset (PRIV (dst_ptr_offsets) + PRIV (dst_ptr_offsets_count), 0,
1575
338
        (loc - PRIV (dst_ptr_offsets_count)) * sizeof (unsigned int));
1576
338
      PRIV (dst_ptr_offsets_count) = loc + 1;
1577
338
    }
1578
1579
384
  PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
1580
384
  return true;
1581
384
}
1582
1583
/* Restore saved DST location counter from specified index.  */
1584
1585
static bool
1586
dst_restore_location (bfd *abfd, unsigned int loc)
1587
135
{
1588
135
  vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
1589
1590
135
  if (loc < PRIV (dst_ptr_offsets_count))
1591
26
    {
1592
26
      PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
1593
26
      return true;
1594
26
    }
1595
109
  return false;
1596
135
}
1597
1598
/* Retrieve saved DST location counter from specified index.  */
1599
1600
static bool
1601
dst_retrieve_location (bfd *abfd, bfd_vma *loc)
1602
348
{
1603
348
  vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc));
1604
1605
348
  if (*loc < PRIV (dst_ptr_offsets_count))
1606
7
    {
1607
7
      *loc = PRIV (dst_ptr_offsets)[*loc];
1608
7
      return true;
1609
7
    }
1610
341
  return false;
1611
348
}
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.83k
{
1618
8.83k
  asection *sec = PRIV (image_section);
1619
8.83k
  size_t off = PRIV (image_offset);
1620
1621
  /* Check bounds.  */
1622
8.83k
  if (off > sec->size
1623
8.83k
      || size > sec->size - off)
1624
8.15k
    {
1625
8.15k
      bfd_set_error (bfd_error_bad_value);
1626
8.15k
      return false;
1627
8.15k
    }
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
682
  if (PRIV (image_section)->contents != NULL)
1635
0
    memcpy (sec->contents + off, ptr, size);
1636
682
  else
1637
682
    {
1638
682
      unsigned int i;
1639
682
      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
682
    }
1646
1647
#if VMS_DEBUG
1648
  _bfd_hexdump (9, ptr, size, 0);
1649
#endif
1650
1651
682
  PRIV (image_offset) += size;
1652
682
  return true;
1653
682
}
1654
1655
/* Write byte to section image.  */
1656
1657
static bool
1658
image_write_b (bfd * abfd, unsigned int value)
1659
793
{
1660
793
  unsigned char data[1];
1661
1662
793
  vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
1663
1664
793
  *data = value;
1665
1666
793
  return image_write (abfd, data, sizeof (data));
1667
793
}
1668
1669
/* Write 2-byte word to image.  */
1670
1671
static bool
1672
image_write_w (bfd * abfd, unsigned int value)
1673
888
{
1674
888
  unsigned char data[2];
1675
1676
888
  vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
1677
1678
888
  bfd_putl16 (value, data);
1679
888
  return image_write (abfd, data, sizeof (data));
1680
888
}
1681
1682
/* Write 4-byte long to image.  */
1683
1684
static bool
1685
image_write_l (bfd * abfd, unsigned long value)
1686
1.37k
{
1687
1.37k
  unsigned char data[4];
1688
1689
1.37k
  vms_debug2 ((6, "image_write_l (%08lx)\n", value));
1690
1691
1.37k
  bfd_putl32 (value, data);
1692
1.37k
  return image_write (abfd, data, sizeof (data));
1693
1.37k
}
1694
1695
/* Write 8-byte quad to image.  */
1696
1697
static bool
1698
image_write_q (bfd * abfd, bfd_vma value)
1699
3.28k
{
1700
3.28k
  unsigned char data[8];
1701
1702
3.28k
  vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
1703
1704
3.28k
  bfd_putl64 (value, data);
1705
3.28k
  return image_write (abfd, data, sizeof (data));
1706
3.28k
}
1707

1708
static const char *
1709
_bfd_vms_etir_name (int cmd)
1710
16.1k
{
1711
16.1k
  switch (cmd)
1712
16.1k
    {
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
878
    case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ";
1717
684
    case ETIR__C_STA_LI: return "ETIR__C_STA_LI";
1718
1.15k
    case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD";
1719
784
    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
918
    case ETIR__C_STO_RB: return "ETIR__C_STO_RB";
1725
679
    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
781
    case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB";
1733
1.12k
    case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL";
1734
882
    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
444
    case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV";
1738
917
    case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH";
1739
442
    case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT";
1740
444
    case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF";
1741
546
    case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT";
1742
341
    case ETIR__C_STC_LP: return "ETIR__C_STC_LP";
1743
679
    case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL";
1744
441
    case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA";
1745
442
    case ETIR__C_STC_PS: return "ETIR__C_STC_PS";
1746
916
    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
342
    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
678
    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
686
    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
588
    case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS";
1755
347
    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
16.1k
    }
1767
1768
0
  return NULL;
1769
16.1k
}
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
23.7k
{
1780
23.7k
  char name[257];
1781
23.7k
  unsigned int len;
1782
23.7k
  unsigned int i;
1783
23.7k
  struct alpha_vms_link_hash_entry *h;
1784
1785
  /* Not linking.  Do not try to resolve the symbol.  */
1786
23.7k
  if (info == NULL)
1787
23.7k
    {
1788
23.7k
      *vma = 0;
1789
23.7k
      *hp = NULL;
1790
23.7k
      return;
1791
23.7k
    }
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
250k
#define RELC_NONE 0
1828
0
#define RELC_REL  1
1829
1.57k
#define RELC_SHR_BASE 0x10000
1830
3.72k
#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
20.6k
{
1836
  /* Handle undefined symbols.  */
1837
20.6k
  if (h == NULL || h->sym == NULL)
1838
20.6k
    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
78.2k
{
1895
78.2k
  unsigned char *ptr;
1896
78.2k
  unsigned int length;
1897
78.2k
  unsigned char *maxptr;
1898
78.2k
  bfd_vma op1 = 0;
1899
78.2k
  bfd_vma op2 = 0;
1900
78.2k
  unsigned int rel1 = RELC_NONE;
1901
78.2k
  unsigned int rel2 = RELC_NONE;
1902
78.2k
  struct alpha_vms_link_hash_entry *h;
1903
1904
78.2k
  PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
1905
78.2k
  PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
1906
1907
78.2k
  ptr = PRIV (recrd.rec);
1908
78.2k
  length = PRIV (recrd.rec_size);
1909
78.2k
  maxptr = ptr + length;
1910
1911
78.2k
  vms_debug2 ((2, "ETIR: %d bytes\n", length));
1912
1913
151k
  while (ptr < maxptr)
1914
132k
    {
1915
132k
      int cmd, cmd_length;
1916
1917
132k
      if (ptr + 4 > maxptr)
1918
1.94k
  goto corrupt_etir;
1919
1920
130k
      cmd = bfd_getl16 (ptr);
1921
130k
      cmd_length = bfd_getl16 (ptr + 2);
1922
1923
      /* PR 21589 and 21579: Check for a corrupt ETIR record.  */
1924
130k
      if (cmd_length < 4 || ptr + cmd_length > maxptr)
1925
8.22k
  {
1926
14.8k
  corrupt_etir:
1927
14.8k
    _bfd_error_handler (_("corrupt ETIR record encountered"));
1928
14.8k
    bfd_set_error (bfd_error_bad_value);
1929
14.8k
    return false;
1930
8.22k
  }
1931
122k
      ptr += 4;
1932
122k
      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
122k
      switch (cmd)
1941
122k
  {
1942
    /* Stack global
1943
       arg: cs  symbol name
1944
1945
       stack 32 bit value of symbol (high bits set to 0).  */
1946
20.6k
  case ETIR__C_STA_GBL:
1947
20.6k
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
1948
20.6k
    if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h)))
1949
0
      return false;
1950
20.6k
    break;
1951
1952
    /* Stack longword
1953
       arg: lw  value
1954
1955
       stack 32 bit value, sign extend to 64 bit.  */
1956
20.6k
  case ETIR__C_STA_LW:
1957
20.5k
    if (cmd_length < 4)
1958
681
      goto corrupt_etir;
1959
19.9k
    if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE))
1960
1
      return false;
1961
19.9k
    break;
1962
1963
    /* Stack quadword
1964
       arg: qw  value
1965
1966
       stack 64 bit value of symbol.  */
1967
19.9k
  case ETIR__C_STA_QW:
1968
7.83k
    if (cmd_length < 8)
1969
785
      goto corrupt_etir;
1970
7.05k
    if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE))
1971
0
      return false;
1972
7.05k
    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
7.05k
  case ETIR__C_STA_PQ:
1981
1.55k
    {
1982
1.55k
      int psect;
1983
1984
1.55k
      if (cmd_length < 12)
1985
679
        goto corrupt_etir;
1986
878
      psect = bfd_getl32 (ptr);
1987
878
      if ((unsigned int) psect >= PRIV (section_count))
1988
878
        {
1989
878
    _bfd_error_handler (_("bad section index in %s"),
1990
878
            _bfd_vms_etir_name (cmd));
1991
878
    bfd_set_error (bfd_error_bad_value);
1992
878
    return false;
1993
878
        }
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
684
  case ETIR__C_STA_LI:
2001
1.83k
  case ETIR__C_STA_MOD:
2002
2.61k
  case ETIR__C_STA_CKARG:
2003
2.61k
    _bfd_error_handler (_("unsupported STA cmd %s"),
2004
2.61k
            _bfd_vms_etir_name (cmd));
2005
2.61k
    return false;
2006
0
    break;
2007
2008
    /* Store byte: pop stack, write byte
2009
       arg: -.  */
2010
1.71k
  case ETIR__C_STO_B:
2011
1.71k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2012
918
      return false;
2013
793
    if (rel1 != RELC_NONE)
2014
0
      goto bad_context;
2015
793
    if (!image_write_b (abfd, (unsigned int) op1 & 0xff))
2016
793
      return false;
2017
0
    break;
2018
2019
    /* Store word: pop stack, write word
2020
       arg: -.  */
2021
2.00k
  case ETIR__C_STO_W:
2022
2.00k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2023
1.11k
      return false;
2024
888
    if (rel1 != RELC_NONE)
2025
0
      goto bad_context;
2026
888
    if (!image_write_w (abfd, (unsigned int) op1 & 0xffff))
2027
888
      return false;
2028
0
    break;
2029
2030
    /* Store longword: pop stack, write longword
2031
       arg: -.  */
2032
1.80k
  case ETIR__C_STO_LW:
2033
1.80k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2034
1.01k
      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.94k
  case ETIR__C_STO_QW:
2060
1.94k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2061
1.15k
      return false;
2062
787
    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
787
    else if (rel1 & RELC_SHR_BASE)
2068
0
      abort ();
2069
787
    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
787
    if (!image_write_q (abfd, op1))
2077
787
      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.73k
  case ETIR__C_STO_IMMR:
2084
5.73k
    {
2085
5.73k
      int size;
2086
2087
5.73k
      if (cmd_length < 4)
2088
914
        goto corrupt_etir;
2089
4.81k
      size = bfd_getl32 (ptr);
2090
4.81k
      if (size > cmd_length - 4)
2091
920
        goto corrupt_etir;
2092
3.89k
      if (!_bfd_vms_pop (abfd, &op1, &rel1))
2093
1.15k
        return false;
2094
2.74k
      if (rel1 != RELC_NONE)
2095
0
        goto bad_context;
2096
2.74k
      if (size == 0)
2097
989
        break;
2098
1.75k
      op1 &= 0xffffffff;
2099
1.75k
      while (op1-- > 0)
2100
896
        if (!image_write (abfd, ptr + 4, size))
2101
896
    return false;
2102
1.75k
    }
2103
857
    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
442
  case ETIR__C_STO_OFF:
2166
442
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2167
442
      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.70k
  case ETIR__C_STO_IMM:
2182
1.70k
    {
2183
1.70k
      unsigned int size;
2184
2185
1.70k
      if (cmd_length < 4)
2186
105
        goto corrupt_etir;
2187
1.60k
      size = bfd_getl32 (ptr);
2188
1.60k
      if (!image_write (abfd, ptr + 4, size))
2189
919
        return false;
2190
1.60k
    }
2191
682
    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
682
  case ETIR__C_STO_GBL_LW:
2200
587
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
2201
#if 0
2202
    abort ();
2203
#endif
2204
587
    if (!image_write_l (abfd, op1))
2205
587
      return false;
2206
0
    break;
2207
2208
918
  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
1.12k
  case ETIR__C_STO_HINT_GBL:
2216
2.00k
  case ETIR__C_STO_HINT_PS:
2217
2.00k
    _bfd_error_handler (_("%s: not implemented"),
2218
2.00k
            _bfd_vms_etir_name (cmd));
2219
2.00k
    return false;
2220
0
    break;
2221
2222
    /* 200 Store-conditional Linkage Pair
2223
       arg: none.  */
2224
341
  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.02k
  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.46k
  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.90k
  case ETIR__C_STC_PS:
2242
1.90k
    _bfd_error_handler (_("%s: not supported"),
2243
1.90k
            _bfd_vms_etir_name (cmd));
2244
1.90k
    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
550
  case ETIR__C_STC_LP_PSB:
2254
550
    if (cmd_length < 4)
2255
108
      goto corrupt_etir;
2256
442
    _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h);
2257
442
    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
442
    else
2275
442
      {
2276
        /* Undefined symbol.  */
2277
442
        op1 = 0;
2278
442
        op2 = 0;
2279
442
      }
2280
442
    if (!image_write_q (abfd, op1)
2281
442
        || !image_write_q (abfd, op2))
2282
442
      return false;
2283
0
    break;
2284
2285
    /* 205 Store-conditional NOP at address of global
2286
       arg: none.  */
2287
683
  case ETIR__C_STC_NOP_GBL:
2288
    /* ALPHA_R_NOP */
2289
2290
    /* 207 Store-conditional BSR at global address
2291
       arg: none.  */
2292
2293
2.36k
  case ETIR__C_STC_BSR_GBL:
2294
    /* ALPHA_R_BSR */
2295
2296
    /* 209 Store-conditional LDA at global address
2297
       arg: none.  */
2298
2299
4.20k
  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
6.14k
  case ETIR__C_STC_BOH_GBL:
2306
    /* Currentl ignored.  */
2307
6.14k
    break;
2308
2309
    /* 213 Store-conditional NOP,BSR or HINT at global address
2310
       arg: none.  */
2311
2312
347
  case ETIR__C_STC_NBH_GBL:
2313
2314
    /* 206 Store-conditional NOP at pect + offset
2315
       arg: none.  */
2316
2317
689
  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.05k
  case ETIR__C_STC_LDA_PS:
2328
2329
    /* 212 Store-conditional BSR or Hint at pect + offset
2330
       arg: none.  */
2331
2332
2.64k
  case ETIR__C_STC_BOH_PS:
2333
2334
    /* 214 Store-conditional NOP, BSR or HINT at psect + offset
2335
       arg: none.  */
2336
3.55k
  case ETIR__C_STC_NBH_PS:
2337
3.55k
    _bfd_error_handler (_("%s: not supported"),
2338
3.55k
            _bfd_vms_etir_name (cmd));
2339
3.55k
    return false;
2340
0
    break;
2341
2342
    /* Det relocation base: pop stack, set image location counter
2343
       arg: none.  */
2344
539
  case ETIR__C_CTL_SETRB:
2345
539
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2346
539
      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.08k
  case ETIR__C_CTL_AUGRB:
2355
3.08k
    if (cmd_length < 4)
2356
441
      goto corrupt_etir;
2357
2.64k
    op1 = bfd_getl32 (ptr);
2358
2.64k
    image_inc_ptr (abfd, op1);
2359
2.64k
    break;
2360
2361
    /* Define location: pop index, save location counter under index
2362
       arg: none.  */
2363
1.16k
  case ETIR__C_CTL_DFLOC:
2364
1.16k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2365
542
      return false;
2366
624
    if (rel1 != RELC_NONE)
2367
0
      goto bad_context;
2368
624
    if (!dst_define_location (abfd, op1))
2369
240
      return false;
2370
384
    break;
2371
2372
    /* Set location: pop index, restore location counter from index
2373
       arg: none.  */
2374
475
  case ETIR__C_CTL_STLOC:
2375
475
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2376
340
      return false;
2377
135
    if (rel1 != RELC_NONE)
2378
0
      goto bad_context;
2379
135
    if (!dst_restore_location (abfd, op1))
2380
109
      {
2381
109
        bfd_set_error (bfd_error_bad_value);
2382
109
        _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC");
2383
109
        return false;
2384
109
      }
2385
26
    break;
2386
2387
    /* Stack defined location: pop index, push location counter from index
2388
       arg: none.  */
2389
689
  case ETIR__C_CTL_STKDL:
2390
689
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2391
341
      return false;
2392
348
    if (rel1 != RELC_NONE)
2393
0
      goto bad_context;
2394
348
    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
7
    if (!_bfd_vms_push (abfd, op1, RELC_NONE))
2401
0
      return false;
2402
7
    break;
2403
2404
2.64k
  case ETIR__C_OPR_NOP:      /* No-op.  */
2405
2.64k
    break;
2406
2407
1.27k
  case ETIR__C_OPR_ADD:      /* Add.  */
2408
1.27k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2409
1.27k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2410
783
      return false;
2411
488
    if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2412
0
      rel1 = rel2;
2413
488
    else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2414
0
      goto bad_context;
2415
488
    if (!_bfd_vms_push (abfd, op1 + op2, rel1))
2416
0
      return false;
2417
488
    break;
2418
2419
3.27k
  case ETIR__C_OPR_SUB:      /* Subtract.  */
2420
3.27k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2421
3.27k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2422
1.12k
      return false;
2423
2.15k
    if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2424
0
      rel1 = rel2;
2425
2.15k
    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
2.15k
    else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2432
0
      goto bad_context;
2433
2.15k
    if (!_bfd_vms_push (abfd, op2 - op1, rel1))
2434
0
      return false;
2435
2.15k
    break;
2436
2437
2.15k
  case ETIR__C_OPR_MUL:      /* Multiply.  */
2438
1.44k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2439
1.44k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2440
885
      return false;
2441
559
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2442
0
      goto bad_context;
2443
559
    if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE))
2444
0
      return false;
2445
559
    break;
2446
2447
2.94k
  case ETIR__C_OPR_DIV:      /* Divide.  */
2448
2.94k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2449
2.94k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2450
688
      return false;
2451
2.25k
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2452
0
      goto bad_context;
2453
2.25k
    if (op1 == 0)
2454
1.11k
      {
2455
        /* Divide by zero is supposed to give a result of zero,
2456
     and a non-fatal warning message.  */
2457
1.11k
        _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV");
2458
1.11k
        if (!_bfd_vms_push (abfd, 0, RELC_NONE))
2459
0
    return false;
2460
1.11k
      }
2461
1.14k
    else
2462
1.14k
      {
2463
1.14k
        if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE))
2464
0
    return false;
2465
1.14k
      }
2466
2.25k
    break;
2467
2468
2.25k
  case ETIR__C_OPR_AND:      /* Logical AND.  */
2469
982
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2470
982
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2471
586
      return false;
2472
396
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2473
0
      goto bad_context;
2474
396
    if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE))
2475
0
      return false;
2476
396
    break;
2477
2478
1.59k
  case ETIR__C_OPR_IOR:      /* Logical inclusive OR.  */
2479
1.59k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2480
1.59k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2481
1.35k
      return false;
2482
249
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2483
0
      goto bad_context;
2484
249
    if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE))
2485
0
      return false;
2486
249
    break;
2487
2488
1.08k
  case ETIR__C_OPR_EOR:      /* Logical exclusive OR.  */
2489
1.08k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2490
1.08k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2491
548
      return false;
2492
541
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2493
0
      goto bad_context;
2494
541
    if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE))
2495
0
      return false;
2496
541
    break;
2497
2498
1.17k
  case ETIR__C_OPR_NEG:      /* Negate.  */
2499
1.17k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2500
345
      return false;
2501
833
    if (rel1 != RELC_NONE)
2502
0
      goto bad_context;
2503
833
    if (!_bfd_vms_push (abfd, -op1, RELC_NONE))
2504
0
      return false;
2505
833
    break;
2506
2507
1.86k
  case ETIR__C_OPR_COM:      /* Complement.  */
2508
1.86k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2509
583
      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.24k
  case ETIR__C_OPR_ASH:      /* Arithmetic shift.  */
2517
2.24k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2518
2.24k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2519
783
      return false;
2520
1.46k
    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.46k
    if ((bfd_signed_vma) op2 < 0)
2528
220
      {
2529
        /* Shift right.  */
2530
220
        bfd_vma sign;
2531
220
        op2 = -op2;
2532
220
        if (op2 >= CHAR_BIT * sizeof (op1))
2533
217
    op2 = CHAR_BIT * sizeof (op1) - 1;
2534
        /* op1 = (bfd_signed_vma) op1 >> op2; */
2535
220
        sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1));
2536
220
        op1 >>= op2;
2537
220
        sign >>= op2;
2538
220
        op1 = (op1 ^ sign) - sign;
2539
220
      }
2540
1.24k
    else
2541
1.24k
      {
2542
        /* Shift left.  */
2543
1.24k
        if (op2 >= CHAR_BIT * sizeof (op1))
2544
413
    op1 = 0;
2545
833
        else
2546
833
    op1 <<= op2;
2547
1.24k
      }
2548
1.46k
    if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym.  */
2549
0
      return false;
2550
1.46k
    break;
2551
2552
1.46k
  case ETIR__C_OPR_INSV:      /* Insert field.   */
2553
1.36k
  case ETIR__C_OPR_USH:       /* Unsigned shift.   */
2554
1.80k
  case ETIR__C_OPR_ROT:       /* Rotate.  */
2555
2.24k
  case ETIR__C_OPR_REDEF:     /* Redefine symbol to current location.  */
2556
2.79k
  case ETIR__C_OPR_DFLIT:     /* Define a literal.  */
2557
2.79k
    _bfd_error_handler (_("%s: not supported"),
2558
2.79k
            _bfd_vms_etir_name (cmd));
2559
2.79k
    return false;
2560
0
    break;
2561
2562
3.06k
  case ETIR__C_OPR_SEL:      /* Select.  */
2563
3.06k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2564
679
      return false;
2565
2.38k
    if (op1 & 0x01L)
2566
1.55k
      {
2567
1.55k
        if (!_bfd_vms_pop (abfd, &op1, &rel1))
2568
580
    return false;
2569
1.55k
      }
2570
826
    else
2571
826
      {
2572
826
        if (!_bfd_vms_pop (abfd, &op1, &rel1)
2573
826
      || !_bfd_vms_pop (abfd, &op2, &rel2))
2574
553
    return false;
2575
273
        if (!_bfd_vms_push (abfd, op1, rel1))
2576
0
    return false;
2577
273
      }
2578
1.25k
    break;
2579
2580
1.99k
  default:
2581
1.99k
    _bfd_error_handler (_("reserved cmd %d"), cmd);
2582
1.99k
    return false;
2583
0
    break;
2584
122k
  }
2585
2586
73.4k
      ptr += cmd_length;
2587
73.4k
    }
2588
2589
19.3k
  return true;
2590
78.2k
}
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
78.2k
{
2598
78.2k
  asection *section = PRIV (dst_section);
2599
2600
78.2k
  if (section == NULL)
2601
61.9k
    {
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
61.9k
      flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC
2606
61.9k
  | SEC_IN_MEMORY;
2607
2608
61.9k
      section = bfd_make_section (abfd, "$DST$");
2609
61.9k
      if (!section)
2610
0
  return false;
2611
61.9k
      if (!bfd_set_section_flags (section, flags))
2612
0
  return false;
2613
61.9k
      PRIV (dst_section) = section;
2614
61.9k
    }
2615
2616
78.2k
  PRIV (image_section) = section;
2617
78.2k
  PRIV (image_offset) = section->size;
2618
2619
78.2k
  if (!_bfd_vms_slurp_etir (abfd, NULL))
2620
58.8k
    return false;
2621
2622
19.3k
  section->size = PRIV (image_offset);
2623
19.3k
  return true;
2624
78.2k
}
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
28.1k
{
2632
28.1k
  vms_debug2 ((2, "EDBG\n"));
2633
2634
28.1k
  abfd->flags |= HAS_DEBUG | HAS_LINENO;
2635
2636
28.1k
  return vms_slurp_debug (abfd);
2637
28.1k
}
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
50.0k
{
2645
50.0k
  vms_debug2 ((2, "ETBT\n"));
2646
2647
50.0k
  abfd->flags |= HAS_LINENO;
2648
2649
50.0k
  return vms_slurp_debug (abfd);
2650
50.0k
}
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
4.27k
{
2658
4.27k
  struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
2659
2660
4.27k
  vms_debug2 ((2, "EEOM\n"));
2661
2662
  /* PR 21813: Check for an undersized record.  */
2663
4.27k
  if (PRIV (recrd.buf_size) < sizeof (* eeom))
2664
110
    {
2665
110
      _bfd_error_handler (_("corrupt EEOM record - size is too small"));
2666
110
      bfd_set_error (bfd_error_bad_value);
2667
110
      return false;
2668
110
    }
2669
2670
4.16k
  PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
2671
4.16k
  PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
2672
4.16k
  if (PRIV (eom_data).eom_w_comcod > 1)
2673
1.02k
    {
2674
1.02k
      _bfd_error_handler (_("object module not error-free !"));
2675
1.02k
      bfd_set_error (bfd_error_bad_value);
2676
1.02k
      return false;
2677
1.02k
    }
2678
2679
3.13k
  PRIV (eom_data).eom_has_transfer = false;
2680
3.13k
  if (PRIV (recrd.rec_size) > 10)
2681
1.92k
    {
2682
1.92k
      PRIV (eom_data).eom_has_transfer = true;
2683
1.92k
      PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
2684
1.92k
      PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
2685
1.92k
      PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
2686
2687
1.92k
      abfd->start_address = PRIV (eom_data).eom_l_tfradr;
2688
1.92k
    }
2689
3.13k
  return true;
2690
4.16k
}
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
112k
{
2697
112k
  bool ok;
2698
112k
  int type;
2699
2700
112k
  do
2701
142k
    {
2702
142k
      vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
2703
2704
142k
      type = _bfd_vms_get_object_record (abfd);
2705
142k
      if (type < 0)
2706
25.7k
  {
2707
25.7k
    vms_debug2 ((2, "next_record failed\n"));
2708
25.7k
    return false;
2709
25.7k
  }
2710
2711
116k
      switch (type)
2712
116k
  {
2713
6.38k
  case EOBJ__C_EMH:
2714
6.38k
    ok = _bfd_vms_slurp_ehdr (abfd);
2715
6.38k
    break;
2716
4.27k
  case EOBJ__C_EEOM:
2717
4.27k
    ok = _bfd_vms_slurp_eeom (abfd);
2718
4.27k
    break;
2719
22.0k
  case EOBJ__C_EGSD:
2720
22.0k
    ok = _bfd_vms_slurp_egsd (abfd);
2721
22.0k
    break;
2722
2.51k
  case EOBJ__C_ETIR:
2723
2.51k
    ok = true; /* _bfd_vms_slurp_etir (abfd); */
2724
2.51k
    break;
2725
28.1k
  case EOBJ__C_EDBG:
2726
28.1k
    ok = _bfd_vms_slurp_edbg (abfd);
2727
28.1k
    break;
2728
50.0k
  case EOBJ__C_ETBT:
2729
50.0k
    ok = _bfd_vms_slurp_etbt (abfd);
2730
50.0k
    break;
2731
3.39k
  default:
2732
3.39k
    ok = false;
2733
116k
  }
2734
116k
      if (!ok)
2735
83.2k
  {
2736
83.2k
    vms_debug2 ((2, "slurp type %d failed\n", type));
2737
83.2k
    return false;
2738
83.2k
  }
2739
116k
    }
2740
112k
  while (type != EOBJ__C_EEOM);
2741
2742
3.13k
  return true;
2743
112k
}
2744
2745
/* Initialize private data  */
2746
static bool
2747
vms_initialize (bfd * abfd)
2748
3.41M
{
2749
3.41M
  size_t amt;
2750
2751
3.41M
  amt = sizeof (struct vms_private_data_struct);
2752
3.41M
  abfd->tdata.any = bfd_zalloc (abfd, amt);
2753
3.41M
  if (abfd->tdata.any == NULL)
2754
0
    return false;
2755
2756
3.41M
  PRIV (recrd.file_format) = FF_UNKNOWN;
2757
2758
3.41M
  amt = sizeof (struct stack_struct) * STACKSIZE;
2759
3.41M
  PRIV (stack) = bfd_alloc (abfd, amt);
2760
3.41M
  if (PRIV (stack) == NULL)
2761
0
    goto error_ret1;
2762
2763
3.41M
  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
3.41M
}
2770
2771
/* Free malloc'd memory.  */
2772
2773
static void
2774
alpha_vms_free_private (bfd *abfd)
2775
3.41M
{
2776
3.41M
  struct module *module;
2777
2778
3.41M
  free (PRIV (recrd.buf));
2779
3.41M
  free (PRIV (sections));
2780
3.41M
  free (PRIV (syms));
2781
3.41M
  free (PRIV (dst_ptr_offsets));
2782
2783
3.42M
  for (module = PRIV (modules); module; module = module->next)
2784
13.7k
    free (module->file_table);
2785
3.41M
}
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
3.41M
{
2793
3.41M
  unsigned int test_len;
2794
3.41M
  unsigned char *buf;
2795
2796
3.41M
  vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
2797
2798
  /* Allocate alpha-vms specific data.  */
2799
3.41M
  if (!vms_initialize (abfd))
2800
0
    return NULL;
2801
2802
3.41M
  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
3.41M
  test_len = 12;
2822
3.41M
  buf = _bfd_malloc_and_read (abfd, test_len, test_len);
2823
3.41M
  if (buf == NULL)
2824
21.5k
    goto error_ret;
2825
3.39M
  PRIV (recrd.buf) = buf;
2826
3.39M
  PRIV (recrd.buf_size) = test_len;
2827
3.39M
  PRIV (recrd.rec) = buf;
2828
2829
  /* Is it an image?  */
2830
3.39M
  if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
2831
3.39M
      && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
2832
24.5k
    {
2833
24.5k
      unsigned int eisd_offset, eihs_offset;
2834
2835
      /* Extract the header size.  */
2836
24.5k
      PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
2837
2838
      /* The header size is 0 for DSF files.  */
2839
24.5k
      if (PRIV (recrd.rec_size) == 0)
2840
22.1k
  PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
2841
2842
      /* PR 21813: Check for a truncated record.  */
2843
      /* PR 17512: file: 7d7c57c2.  */
2844
24.5k
      if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd))
2845
422
  goto err_wrong_format;
2846
2847
24.1k
      if (bfd_seek (abfd, 0, SEEK_SET))
2848
0
  goto error_ret;
2849
2850
24.1k
      free (PRIV (recrd.buf));
2851
24.1k
      PRIV (recrd.buf) = NULL;
2852
24.1k
      buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size),
2853
24.1k
          PRIV (recrd.rec_size));
2854
24.1k
      if (buf == NULL)
2855
1.30k
  goto error_ret;
2856
2857
22.8k
      PRIV (recrd.buf) = buf;
2858
22.8k
      PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
2859
22.8k
      PRIV (recrd.rec) = buf;
2860
2861
22.8k
      vms_debug2 ((2, "file type is image\n"));
2862
2863
22.8k
      if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset))
2864
0
  goto err_wrong_format;
2865
2866
22.8k
      if (!_bfd_vms_slurp_eisd (abfd, eisd_offset))
2867
7.41k
  goto err_wrong_format;
2868
2869
      /* EIHS is optional.  */
2870
15.3k
      if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset))
2871
2.47k
  goto err_wrong_format;
2872
15.3k
    }
2873
3.36M
  else
2874
3.36M
    {
2875
3.36M
      int type;
2876
2877
      /* Assume it's a module and adjust record pointer if necessary.  */
2878
3.36M
      maybe_adjust_record_pointer_for_object (abfd);
2879
2880
      /* But is it really a module?  */
2881
3.36M
      if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
2882
3.36M
    && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
2883
149k
  {
2884
149k
    if (vms_get_remaining_object_record (abfd, test_len) <= 0)
2885
30.0k
      goto err_wrong_format;
2886
2887
119k
    vms_debug2 ((2, "file type is module\n"));
2888
2889
119k
    type = bfd_getl16 (PRIV (recrd.rec));
2890
119k
    if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd))
2891
9.66k
      goto err_wrong_format;
2892
2893
109k
    if (!_bfd_vms_slurp_object_records (abfd))
2894
107k
      goto err_wrong_format;
2895
109k
  }
2896
3.21M
      else
2897
3.21M
  goto err_wrong_format;
2898
3.36M
    }
2899
2900
  /* Set arch_info to alpha.   */
2901
2902
15.6k
  if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
2903
0
    goto err_wrong_format;
2904
2905
15.6k
  return alpha_vms_free_private;
2906
2907
3.37M
 err_wrong_format:
2908
3.37M
  bfd_set_error (bfd_error_wrong_format);
2909
2910
3.39M
 error_ret:
2911
3.39M
  alpha_vms_free_private (abfd);
2912
3.39M
  bfd_release (abfd, abfd->tdata.any);
2913
3.39M
  return NULL;
2914
3.37M
}
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
438
  do { if ((m)->name == NULL) (m)->name = ""; } while (0)
4347
673
#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
13.7k
{
4354
13.7k
  struct module *module
4355
13.7k
    = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
4356
13.7k
  module->file_table_count = 16; /* Arbitrary.  */
4357
13.7k
  module->file_table
4358
13.7k
    = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo));
4359
13.7k
  return module;
4360
13.7k
}
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
452
{
4368
452
  unsigned char *maxptr = ptr + length;
4369
452
  unsigned char *src_ptr, *pcl_ptr;
4370
452
  unsigned int prev_linum = 0, curr_linenum = 0;
4371
452
  bfd_vma prev_pc = 0, curr_pc = 0;
4372
452
  struct srecinfo *curr_srec, *srec;
4373
452
  struct lineinfo *curr_line, *line;
4374
452
  struct funcinfo *funcinfo;
4375
4376
  /* Initialize tables with zero element.  */
4377
452
  curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4378
452
  if (!curr_srec)
4379
0
    return false;
4380
452
  module->srec_table = curr_srec;
4381
4382
452
  curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4383
452
  if (!curr_line)
4384
0
    return false;
4385
452
  module->line_table = curr_line;
4386
4387
201k
  while (ptr + 3 < maxptr)
4388
200k
    {
4389
      /* The first byte is not counted in the recorded length.  */
4390
200k
      int rec_length = bfd_getl16 (ptr) + 1;
4391
200k
      int rec_type = bfd_getl16 (ptr + 2);
4392
4393
200k
      vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
4394
4395
200k
      if (rec_length > maxptr - ptr)
4396
412
  break;
4397
200k
      if (rec_type == DST__K_MODEND)
4398
6
  break;
4399
4400
200k
      switch (rec_type)
4401
200k
  {
4402
30
  case DST__K_MODBEG:
4403
30
    if (rec_length <= DST_S_B_MODBEG_NAME)
4404
11
      break;
4405
19
    module->name
4406
19
      = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME,
4407
19
              rec_length - DST_S_B_MODBEG_NAME);
4408
4409
19
    curr_pc = 0;
4410
19
    prev_pc = 0;
4411
19
    curr_linenum = 0;
4412
19
    prev_linum = 0;
4413
4414
19
    vms_debug2 ((3, "module: %s\n", module->name));
4415
19
    break;
4416
4417
0
  case DST__K_MODEND:
4418
0
    break;
4419
4420
12
  case DST__K_RTNBEG:
4421
12
    if (rec_length <= DST_S_B_RTNBEG_NAME)
4422
6
      break;
4423
6
    funcinfo = (struct funcinfo *)
4424
6
      bfd_zalloc (abfd, sizeof (struct funcinfo));
4425
6
    if (!funcinfo)
4426
0
      return false;
4427
6
    funcinfo->name
4428
6
      = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME,
4429
6
              rec_length - DST_S_B_RTNBEG_NAME);
4430
6
    funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
4431
6
    funcinfo->next = module->func_table;
4432
6
    module->func_table = funcinfo;
4433
4434
6
    vms_debug2 ((3, "routine: %s at 0x%lx\n",
4435
6
           funcinfo->name, (unsigned long) funcinfo->low));
4436
6
    break;
4437
4438
22
  case DST__K_RTNEND:
4439
22
    if (rec_length < DST_S_L_RTNEND_SIZE + 4)
4440
8
      break;
4441
14
    if (!module->func_table)
4442
14
      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
3
  case DST__K_BLKBEG:
4461
3
    vms_debug2 ((3, "block\n"));
4462
3
    break;
4463
4464
0
  case DST__K_BLKEND:
4465
0
    vms_debug2 ((3, "end block\n"));
4466
0
    break;
4467
4468
178
  case DST__K_SOURCE:
4469
178
    src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE;
4470
4471
178
    vms_debug2 ((3, "source info\n"));
4472
4473
97.7k
    while (src_ptr - ptr < rec_length)
4474
97.6k
      {
4475
97.6k
        int cmd = src_ptr[0], cmd_length, data;
4476
4477
97.6k
        switch (cmd)
4478
97.6k
    {
4479
2.40k
    case DST__K_SRC_DECLFILE:
4480
2.40k
      if (src_ptr - ptr + DST_S_B_SRC_DF_LENGTH >= rec_length)
4481
6
        cmd_length = 0x10000;
4482
2.40k
      else
4483
2.40k
        cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2;
4484
2.40k
      break;
4485
4486
444
    case DST__K_SRC_DEFLINES_B:
4487
444
      cmd_length = 2;
4488
444
      break;
4489
4490
470
    case DST__K_SRC_DEFLINES_W:
4491
470
      cmd_length = 3;
4492
470
      break;
4493
4494
226
    case DST__K_SRC_INCRLNUM_B:
4495
226
      cmd_length = 2;
4496
226
      break;
4497
4498
645
    case DST__K_SRC_SETFILE:
4499
645
      cmd_length = 3;
4500
645
      break;
4501
4502
301
    case DST__K_SRC_SETLNUM_L:
4503
301
      cmd_length = 5;
4504
301
      break;
4505
4506
279
    case DST__K_SRC_SETLNUM_W:
4507
279
      cmd_length = 3;
4508
279
      break;
4509
4510
629
    case DST__K_SRC_SETREC_L:
4511
629
      cmd_length = 5;
4512
629
      break;
4513
4514
634
    case DST__K_SRC_SETREC_W:
4515
634
      cmd_length = 3;
4516
634
      break;
4517
4518
700
    case DST__K_SRC_FORMFEED:
4519
700
      cmd_length = 1;
4520
700
      break;
4521
4522
90.8k
    default:
4523
90.8k
      cmd_length = 2;
4524
90.8k
      break;
4525
97.6k
    }
4526
4527
97.6k
        if (src_ptr - ptr + cmd_length > rec_length)
4528
87
    break;
4529
4530
97.5k
        switch (cmd)
4531
97.5k
    {
4532
2.39k
    case DST__K_SRC_DECLFILE:
4533
2.39k
      {
4534
2.39k
        unsigned int fileid
4535
2.39k
          = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
4536
2.39k
        char *filename = _bfd_vms_save_counted_string
4537
2.39k
          (abfd,
4538
2.39k
           src_ptr + DST_S_B_SRC_DF_FILENAME,
4539
2.39k
           ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME));
4540
4541
2.39k
        if (fileid >= module->file_table_count)
4542
226
          {
4543
226
      unsigned int old_count = module->file_table_count;
4544
226
      module->file_table_count += fileid;
4545
226
      module->file_table
4546
226
        = bfd_realloc_or_free (module->file_table,
4547
226
             module->file_table_count
4548
226
             * sizeof (struct fileinfo));
4549
226
      if (module->file_table == NULL)
4550
0
        return false;
4551
226
      memset (module->file_table + old_count, 0,
4552
226
        fileid * sizeof (struct fileinfo));
4553
226
          }
4554
4555
2.39k
        module->file_table [fileid].name = filename;
4556
2.39k
        module->file_table [fileid].srec = 1;
4557
2.39k
        vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
4558
2.39k
         fileid, module->file_table [fileid].name));
4559
2.39k
      }
4560
0
      break;
4561
4562
444
    case DST__K_SRC_DEFLINES_B:
4563
      /* Perform the association and set the next higher index
4564
         to the limit.  */
4565
444
      data = src_ptr[DST_S_B_SRC_UNSBYTE];
4566
444
      srec = (struct srecinfo *)
4567
444
        bfd_zalloc (abfd, sizeof (struct srecinfo));
4568
444
      srec->line = curr_srec->line + data;
4569
444
      srec->srec = curr_srec->srec + data;
4570
444
      srec->sfile = curr_srec->sfile;
4571
444
      curr_srec->next = srec;
4572
444
      curr_srec = srec;
4573
444
      vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data));
4574
444
      break;
4575
4576
470
    case DST__K_SRC_DEFLINES_W:
4577
      /* Perform the association and set the next higher index
4578
         to the limit.  */
4579
470
      data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4580
470
      srec = (struct srecinfo *)
4581
470
        bfd_zalloc (abfd, sizeof (struct srecinfo));
4582
470
      srec->line = curr_srec->line + data;
4583
470
      srec->srec = curr_srec->srec + data,
4584
470
      srec->sfile = curr_srec->sfile;
4585
470
      curr_srec->next = srec;
4586
470
      curr_srec = srec;
4587
470
      vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data));
4588
470
      break;
4589
4590
226
    case DST__K_SRC_INCRLNUM_B:
4591
226
      data = src_ptr[DST_S_B_SRC_UNSBYTE];
4592
226
      curr_srec->line += data;
4593
226
      vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data));
4594
226
      break;
4595
4596
641
    case DST__K_SRC_SETFILE:
4597
641
      data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4598
641
      if ((unsigned int) data < module->file_table_count)
4599
596
        {
4600
596
          curr_srec->sfile = data;
4601
596
          curr_srec->srec = module->file_table[data].srec;
4602
596
        }
4603
641
      vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data));
4604
641
      break;
4605
4606
299
    case DST__K_SRC_SETLNUM_L:
4607
299
      data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4608
299
      curr_srec->line = data;
4609
299
      vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data));
4610
299
      break;
4611
4612
279
    case DST__K_SRC_SETLNUM_W:
4613
279
      data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4614
279
      curr_srec->line = data;
4615
279
      vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data));
4616
279
      break;
4617
4618
629
    case DST__K_SRC_SETREC_L:
4619
629
      data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4620
629
      curr_srec->srec = data;
4621
629
      module->file_table[curr_srec->sfile].srec = data;
4622
629
      vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data));
4623
629
      break;
4624
4625
634
    case DST__K_SRC_SETREC_W:
4626
634
      data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4627
634
      curr_srec->srec = data;
4628
634
      module->file_table[curr_srec->sfile].srec = data;
4629
634
      vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data));
4630
634
      break;
4631
4632
700
    case DST__K_SRC_FORMFEED:
4633
700
      vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n"));
4634
700
      break;
4635
4636
90.8k
    default:
4637
90.8k
      _bfd_error_handler (_("unknown source command %d"),
4638
90.8k
              cmd);
4639
90.8k
      break;
4640
97.5k
    }
4641
4642
97.5k
        src_ptr += cmd_length;
4643
97.5k
      }
4644
178
    break;
4645
4646
218
  case DST__K_LINE_NUM:
4647
218
    pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE;
4648
4649
218
    vms_debug2 ((3, "line info\n"));
4650
4651
1.10M
    while (pcl_ptr - ptr < rec_length)
4652
1.10M
      {
4653
        /* The command byte is signed so we must sign-extend it.  */
4654
1.10M
        int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data;
4655
4656
1.10M
        switch (cmd)
4657
1.10M
    {
4658
29.4k
    case DST__K_DELTA_PC_W:
4659
29.4k
      cmd_length = 3;
4660
29.4k
      break;
4661
4662
2.70k
    case DST__K_DELTA_PC_L:
4663
2.70k
      cmd_length = 5;
4664
2.70k
      break;
4665
4666
10.3k
    case DST__K_INCR_LINUM:
4667
10.3k
      cmd_length = 2;
4668
10.3k
      break;
4669
4670
6.37k
    case DST__K_INCR_LINUM_W:
4671
6.37k
      cmd_length = 3;
4672
6.37k
      break;
4673
4674
1.38k
    case DST__K_INCR_LINUM_L:
4675
1.38k
      cmd_length = 5;
4676
1.38k
      break;
4677
4678
4.50k
    case DST__K_SET_LINUM_INCR:
4679
4.50k
      cmd_length = 2;
4680
4.50k
      break;
4681
4682
3.91k
    case DST__K_SET_LINUM_INCR_W:
4683
3.91k
      cmd_length = 3;
4684
3.91k
      break;
4685
4686
3.02k
    case DST__K_RESET_LINUM_INCR:
4687
3.02k
      cmd_length = 1;
4688
3.02k
      break;
4689
4690
2.11k
    case DST__K_BEG_STMT_MODE:
4691
2.11k
      cmd_length = 1;
4692
2.11k
      break;
4693
4694
5.95k
    case DST__K_END_STMT_MODE:
4695
5.95k
      cmd_length = 1;
4696
5.95k
      break;
4697
4698
938
    case DST__K_SET_LINUM_B:
4699
938
      cmd_length = 2;
4700
938
      break;
4701
4702
2.34k
    case DST__K_SET_LINUM:
4703
2.34k
      cmd_length = 3;
4704
2.34k
      break;
4705
4706
1.67k
    case DST__K_SET_LINUM_L:
4707
1.67k
      cmd_length = 5;
4708
1.67k
      break;
4709
4710
3.64k
    case DST__K_SET_PC:
4711
3.64k
      cmd_length = 2;
4712
3.64k
      break;
4713
4714
2.11k
    case DST__K_SET_PC_W:
4715
2.11k
      cmd_length = 3;
4716
2.11k
      break;
4717
4718
13.5k
    case DST__K_SET_PC_L:
4719
13.5k
      cmd_length = 5;
4720
13.5k
      break;
4721
4722
1.17k
    case DST__K_SET_STMTNUM:
4723
1.17k
      cmd_length = 2;
4724
1.17k
      break;
4725
4726
1.48k
    case DST__K_TERM:
4727
1.48k
      cmd_length = 2;
4728
1.48k
      break;
4729
4730
2.50k
    case DST__K_TERM_W:
4731
2.50k
      cmd_length = 3;
4732
2.50k
      break;
4733
4734
674
    case DST__K_TERM_L:
4735
674
      cmd_length = 5;
4736
674
      break;
4737
4738
3.14k
    case DST__K_SET_ABS_PC:
4739
3.14k
      cmd_length = 5;
4740
3.14k
      break;
4741
4742
1.00M
    default:
4743
1.00M
      if (cmd <= 0)
4744
858k
        cmd_length = 1;
4745
146k
      else
4746
146k
        cmd_length = 2;
4747
1.00M
      break;
4748
1.10M
    }
4749
4750
1.10M
        if (pcl_ptr - ptr + cmd_length > rec_length)
4751
30
    break;
4752
4753
1.10M
        switch (cmd)
4754
1.10M
    {
4755
29.4k
    case DST__K_DELTA_PC_W:
4756
29.4k
      data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4757
29.4k
      curr_pc += data;
4758
29.4k
      curr_linenum += 1;
4759
29.4k
      vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data));
4760
29.4k
      break;
4761
4762
2.70k
    case DST__K_DELTA_PC_L:
4763
2.70k
      data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4764
2.70k
      curr_pc += data;
4765
2.70k
      curr_linenum += 1;
4766
2.70k
      vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data));
4767
2.70k
      break;
4768
4769
10.3k
    case DST__K_INCR_LINUM:
4770
10.3k
      data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4771
10.3k
      curr_linenum += data;
4772
10.3k
      vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data));
4773
10.3k
      break;
4774
4775
6.37k
    case DST__K_INCR_LINUM_W:
4776
6.37k
      data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4777
6.37k
      curr_linenum += data;
4778
6.37k
      vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data));
4779
6.37k
      break;
4780
4781
1.38k
    case DST__K_INCR_LINUM_L:
4782
1.38k
      data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4783
1.38k
      curr_linenum += data;
4784
1.38k
      vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data));
4785
1.38k
      break;
4786
4787
4.50k
    case DST__K_SET_LINUM_INCR:
4788
4.50k
      _bfd_error_handler
4789
4.50k
        (_("%s not implemented"), "DST__K_SET_LINUM_INCR");
4790
4.50k
      break;
4791
4792
3.91k
    case DST__K_SET_LINUM_INCR_W:
4793
3.91k
      _bfd_error_handler
4794
3.91k
        (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W");
4795
3.91k
      break;
4796
4797
3.02k
    case DST__K_RESET_LINUM_INCR:
4798
3.02k
      _bfd_error_handler
4799
3.02k
        (_("%s not implemented"), "DST__K_RESET_LINUM_INCR");
4800
3.02k
      break;
4801
4802
2.11k
    case DST__K_BEG_STMT_MODE:
4803
2.11k
      _bfd_error_handler
4804
2.11k
        (_("%s not implemented"), "DST__K_BEG_STMT_MODE");
4805
2.11k
      break;
4806
4807
5.95k
    case DST__K_END_STMT_MODE:
4808
5.95k
      _bfd_error_handler
4809
5.95k
        (_("%s not implemented"), "DST__K_END_STMT_MODE");
4810
5.95k
      break;
4811
4812
938
    case DST__K_SET_LINUM_B:
4813
938
      data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4814
938
      curr_linenum = data;
4815
938
      vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data));
4816
938
      break;
4817
4818
2.34k
    case DST__K_SET_LINUM:
4819
2.34k
      data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4820
2.34k
      curr_linenum = data;
4821
2.34k
      vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data));
4822
2.34k
      break;
4823
4824
1.67k
    case DST__K_SET_LINUM_L:
4825
1.67k
      data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4826
1.67k
      curr_linenum = data;
4827
1.67k
      vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data));
4828
1.67k
      break;
4829
4830
3.64k
    case DST__K_SET_PC:
4831
3.64k
      _bfd_error_handler
4832
3.64k
        (_("%s not implemented"), "DST__K_SET_PC");
4833
3.64k
      break;
4834
4835
2.11k
    case DST__K_SET_PC_W:
4836
2.11k
      _bfd_error_handler
4837
2.11k
        (_("%s not implemented"), "DST__K_SET_PC_W");
4838
2.11k
      break;
4839
4840
13.5k
    case DST__K_SET_PC_L:
4841
13.5k
      _bfd_error_handler
4842
13.5k
        (_("%s not implemented"), "DST__K_SET_PC_L");
4843
13.5k
      break;
4844
4845
1.17k
    case DST__K_SET_STMTNUM:
4846
1.17k
      _bfd_error_handler
4847
1.17k
        (_("%s not implemented"), "DST__K_SET_STMTNUM");
4848
1.17k
      break;
4849
4850
1.48k
    case DST__K_TERM:
4851
1.48k
      data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4852
1.48k
      curr_pc += data;
4853
1.48k
      vms_debug2 ((4, "DST__K_TERM: %d\n", data));
4854
1.48k
      break;
4855
4856
2.50k
    case DST__K_TERM_W:
4857
2.50k
      data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4858
2.50k
      curr_pc += data;
4859
2.50k
      vms_debug2 ((4, "DST__K_TERM_W: %d\n", data));
4860
2.50k
      break;
4861
4862
674
    case DST__K_TERM_L:
4863
674
      data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4864
674
      curr_pc += data;
4865
674
      vms_debug2 ((4, "DST__K_TERM_L: %d\n", data));
4866
674
      break;
4867
4868
3.14k
    case DST__K_SET_ABS_PC:
4869
3.14k
      data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4870
3.14k
      curr_pc = data;
4871
3.14k
      vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data));
4872
3.14k
      break;
4873
4874
1.00M
    default:
4875
1.00M
      if (cmd <= 0)
4876
858k
        {
4877
858k
          curr_pc -= cmd;
4878
858k
          curr_linenum += 1;
4879
858k
          vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n",
4880
858k
           (unsigned long)curr_pc, curr_linenum));
4881
858k
        }
4882
146k
      else
4883
146k
        _bfd_error_handler (_("unknown line command %d"), cmd);
4884
1.00M
      break;
4885
1.10M
    }
4886
4887
1.10M
        if ((curr_linenum != prev_linum && curr_pc != prev_pc)
4888
1.10M
      || cmd <= 0
4889
1.10M
      || cmd == DST__K_DELTA_PC_L
4890
1.10M
      || cmd == DST__K_DELTA_PC_W)
4891
891k
    {
4892
891k
      line = (struct lineinfo *)
4893
891k
        bfd_zalloc (abfd, sizeof (struct lineinfo));
4894
891k
      line->address = curr_pc;
4895
891k
      line->line = curr_linenum;
4896
4897
891k
      curr_line->next = line;
4898
891k
      curr_line = line;
4899
4900
891k
      prev_linum = curr_linenum;
4901
891k
      prev_pc = curr_pc;
4902
891k
      vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n",
4903
891k
             (unsigned long)curr_pc, curr_linenum));
4904
891k
    }
4905
4906
1.10M
        pcl_ptr += cmd_length;
4907
1.10M
      }
4908
218
    break;
4909
4910
218
  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
200k
  default:
4915
200k
    vms_debug2 ((3, "ignoring record\n"));
4916
200k
    break;
4917
4918
200k
  }
4919
4920
200k
      ptr += rec_length;
4921
200k
    }
4922
4923
  /* Finalize tables with EOL marker.  */
4924
438
  srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4925
438
  srec->line = (unsigned int) -1;
4926
438
  srec->srec = (unsigned int) -1;
4927
438
  curr_srec->next = srec;
4928
4929
438
  line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4930
438
  line->line = (unsigned int) -1;
4931
438
  line->address = (bfd_vma) -1;
4932
438
  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
438
  SET_MODULE_PARSED (module);
4938
438
  return true;
4939
452
}
4940
4941
/* Build the list of modules for the specified BFD.  */
4942
4943
static struct module *
4944
build_module_list (bfd *abfd)
4945
351
{
4946
351
  struct module *module, *list = NULL;
4947
351
  asection *dmt;
4948
4949
351
  if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
4950
330
    {
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
330
      bfd_size_type size = bfd_section_size (dmt);
4956
330
      unsigned char *buf, *ptr, *end;
4957
4958
330
      if (! bfd_malloc_and_get_section (abfd, dmt, &buf))
4959
36
  return NULL;
4960
4961
294
      vms_debug2 ((2, "DMT\n"));
4962
4963
294
      ptr = buf;
4964
294
      end = ptr + size;
4965
2.59k
      while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE)
4966
2.29k
  {
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
2.29k
    unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
4971
2.29k
    unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
4972
2.29k
    int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
4973
2.29k
    ptr += DBG_S_C_DMT_HEADER_SIZE;
4974
4975
2.29k
    vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n",
4976
2.29k
           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
16.0k
    while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE)
4984
13.7k
      {
4985
13.7k
        unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
4986
13.7k
        unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
4987
13.7k
        module = new_module (abfd);
4988
13.7k
        module->modbeg = modbeg;
4989
13.7k
        module->size = msize;
4990
13.7k
        module->low = start;
4991
13.7k
        module->high = start + length;
4992
13.7k
        module->next = list;
4993
13.7k
        list = module;
4994
13.7k
        ptr += DBG_S_C_DMT_PSECT_SIZE;
4995
4996
13.7k
        vms_debug2 ((4, "section: start = 0x%x, length = %u\n",
4997
13.7k
         start, length));
4998
13.7k
      }
4999
2.29k
  }
5000
294
      free (buf);
5001
294
    }
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
294
  return list;
5020
351
}
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
673
{
5030
673
  struct funcinfo *funcinfo;
5031
673
  struct lineinfo *lineinfo;
5032
673
  struct srecinfo *srecinfo;
5033
673
  bool ret = false;
5034
5035
  /* Parse this module if that was not done at module creation.  */
5036
673
  if (! IS_MODULE_PARSED (module))
5037
516
    {
5038
516
      unsigned int size = module->size;
5039
516
      unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
5040
516
      unsigned char *buffer;
5041
5042
516
      if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
5043
516
    || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL)
5044
64
  {
5045
64
    bfd_set_error (bfd_error_no_debug_section);
5046
64
    return false;
5047
64
  }
5048
5049
452
      ret = parse_module (abfd, module, buffer, size);
5050
452
      free (buffer);
5051
452
      if (!ret)
5052
14
  return ret;
5053
452
    }
5054
5055
  /* Find out the function (if any) that contains the address.  */
5056
602
  for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next)
5057
7
    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
284k
  for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
5066
284k
    if (lineinfo->next && addr < lineinfo->next->address)
5067
585
      {
5068
725
  for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
5069
722
    if (srecinfo->next && lineinfo->line < srecinfo->next->line)
5070
582
      {
5071
582
        if (srecinfo->sfile > 0)
5072
20
    {
5073
20
      *file = module->file_table[srecinfo->sfile].name;
5074
20
      *line = srecinfo->srec + lineinfo->line - srecinfo->line;
5075
20
    }
5076
562
        else
5077
562
    {
5078
562
      *file = module->name;
5079
562
      *line = lineinfo->line;
5080
562
    }
5081
582
        return true;
5082
582
      }
5083
5084
3
  break;
5085
585
      }
5086
5087
13
  return ret;
5088
595
}
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
943
{
5104
943
  struct module *module;
5105
5106
  /* What address are we looking for?  */
5107
943
  bfd_vma addr = section->vma + offset;
5108
5109
943
  *file = NULL;
5110
943
  *func = NULL;
5111
943
  *line = 0;
5112
943
  if (discriminator)
5113
943
    *discriminator = 0;
5114
5115
  /* We can't do anything if there is no DST (debug symbol table).  */
5116
943
  if (PRIV (dst_section) == NULL)
5117
22
    return false;
5118
5119
  /* Create the module list - if not already done.  */
5120
921
  if (PRIV (modules) == NULL)
5121
351
    {
5122
351
      PRIV (modules) = build_module_list (abfd);
5123
351
      if (PRIV (modules) == NULL)
5124
119
  return false;
5125
351
    }
5126
5127
11.1k
  for (module = PRIV (modules); module; module = module->next)
5128
11.0k
    if (addr >= module->low && addr <= module->high)
5129
673
      return module_find_nearest_line (abfd, module, addr, file, func, line);
5130
5131
129
  return false;
5132
802
}
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
20
{
5214
20
  vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
5215
20
         abfd, PRIV (gsd_sym_count)));
5216
5217
20
  return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
5218
20
}
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
20
{
5228
20
  unsigned int i;
5229
5230
20
  vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
5231
5232
20
  if (PRIV (csymbols) == NULL)
5233
20
    {
5234
20
      PRIV (csymbols) = (asymbol **) bfd_alloc
5235
20
  (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
5236
5237
      /* Traverse table and fill symbols vector.  */
5238
20
      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
20
    }
5254
5255
20
  if (symbols != NULL)
5256
20
    {
5257
20
      for (i = 0; i < PRIV (gsd_sym_count); i++)
5258
0
  symbols[i] = PRIV (csymbols)[i];
5259
20
      symbols[i] = NULL;
5260
20
    }
5261
5262
20
  return PRIV (gsd_sym_count);
5263
20
}
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
16
{
6027
16
  asymbol *syms;
6028
16
  unsigned int i;
6029
16
  unsigned int n = 0;
6030
6031
16
  syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
6032
16
  *ret = syms;
6033
16
  if (syms == NULL)
6034
0
    return -1;
6035
6036
16
  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
16
  return n;
6085
16
}
6086

6087
/* Private dump.  */
6088
6089
static const char *
6090
vms_time_to_str (unsigned char *buf)
6091
149
{
6092
149
  time_t t = vms_rawtime_to_time_t (buf);
6093
149
  char *res = ctime (&t);
6094
6095
149
  if (!res)
6096
0
    res = "*invalid time*";
6097
149
  else
6098
149
    res[24] = 0;
6099
149
  return res;
6100
149
}
6101
6102
static void
6103
evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len)
6104
25
{
6105
25
  struct vms_emh_common *emh = (struct vms_emh_common *)rec;
6106
25
  int subtype = -1;
6107
25
  int extra;
6108
6109
25
  if (rec_len >= sizeof (*emh))
6110
25
    subtype = bfd_getl16 (emh->subtyp);
6111
6112
  /* xgettext:c-format */
6113
25
  fprintf (file, _("  EMH %d (len=%u): "), subtype, rec_len);
6114
6115
  /* PR 21618: Check for invalid lengths.  */
6116
25
  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
25
  extra = rec_len - sizeof (struct vms_emh_common);
6124
6125
25
  switch (subtype)
6126
25
    {
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
2
    case EMH__C_SRC:
6186
2
      fprintf (file, _("Source Files Header\n"));
6187
2
      fprintf (file, _("   file: %.*s\n"), extra, (char *)(emh + 1));
6188
2
      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
19
    default:
6201
19
      fprintf (file, _("unhandled emh subtype %u\n"), subtype);
6202
19
      break;
6203
25
    }
6204
25
}
6205
6206
static void
6207
evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len)
6208
7
{
6209
7
  struct vms_eeom *eeom = (struct vms_eeom *)rec;
6210
6211
7
  fprintf (file, _("  EEOM (len=%u):\n"), rec_len);
6212
6213
  /* PR 21618: Check for invalid lengths.  */
6214
7
  if (rec_len < 10)
6215
1
    {
6216
1
      fprintf (file, _("   Error: %s min length is %u\n"),
6217
1
         "EEOM", 10);
6218
1
      return;
6219
1
    }
6220
6221
6
  fprintf (file, _("   number of cond linkage pairs: %u\n"),
6222
6
     (unsigned)bfd_getl32 (eeom->total_lps));
6223
6
  fprintf (file, _("   completion code: %u\n"),
6224
6
     (unsigned)bfd_getl16 (eeom->comcod));
6225
6226
6
  if (rec_len >= sizeof (*eeom))
6227
5
    {
6228
5
      fprintf (file, _("   transfer addr flags: 0x%02x\n"), eeom->tfrflg);
6229
5
      fprintf (file, _("   transfer addr psect: %u\n"),
6230
5
         (unsigned)bfd_getl32 (eeom->psindx));
6231
5
      fprintf (file, _("   transfer address   : 0x%08x\n"),
6232
5
         (unsigned)bfd_getl32 (eeom->tfradr));
6233
5
    }
6234
6
}
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
8
{
6589
8
  unsigned int off = sizeof (struct vms_eobjrec);
6590
6591
  /* xgettext:c-format */
6592
8
  fprintf (file, _("  %s (len=%u):\n"), name, (unsigned) rec_len);
6593
8
  if (rec_len < sizeof (struct vms_eobjrec) + sizeof (struct vms_etir))
6594
0
    return;
6595
6596
30
  while (off <= rec_len - sizeof (struct vms_etir))
6597
30
    {
6598
30
      struct vms_etir *etir = (struct vms_etir *)(rec + off);
6599
30
      unsigned char *buf;
6600
30
      unsigned int type;
6601
30
      unsigned int size;
6602
30
      unsigned int rest;
6603
6604
30
      type = bfd_getl16 (etir->rectyp);
6605
30
      size = bfd_getl16 (etir->size);
6606
30
      buf = rec + off + sizeof (struct vms_etir);
6607
6608
30
      if (size < sizeof (struct vms_etir) || size > rec_len - off)
6609
8
  {
6610
8
    fprintf (file, _("   Erroneous length\n"));
6611
8
    return;
6612
8
  }
6613
6614
      /* xgettext:c-format */
6615
22
      fprintf (file, _("   (type: %3u, size: %3u): "), type, size);
6616
22
      rest = size - sizeof (struct vms_etir);
6617
22
      switch (type)
6618
22
  {
6619
3
  case ETIR__C_STA_GBL:
6620
3
    if (rest >= 1)
6621
3
      fprintf (file, _("STA_GBL (stack global) %.*s\n"),
6622
3
         buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
6623
3
    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
1
  case ETIR__C_STA_PQ:
6638
1
    fprintf (file, _("STA_PQ (stack psect base + offset)\n"));
6639
1
    if (rest >= 12)
6640
      /* xgettext:c-format */
6641
1
      fprintf (file, _("    psect: %u, offset: 0x%08x %08x\n"),
6642
1
         (unsigned) bfd_getl32 (buf + 0),
6643
1
         (unsigned) bfd_getl32 (buf + 8),
6644
1
         (unsigned) bfd_getl32 (buf + 4));
6645
1
    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
6
  case ETIR__C_OPR_AND:
6742
6
    fprintf (file, _("OPR_AND (logical and)\n"));
6743
6
    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
12
  default:
6888
12
    fprintf (file, _("*unhandled*\n"));
6889
12
    break;
6890
22
  }
6891
22
      off += size;
6892
22
    }
6893
8
}
6894
6895
static void
6896
evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
6897
27
{
6898
27
  bool is_first = true;
6899
27
  bool has_records = true;
6900
6901
110
  while (1)
6902
110
    {
6903
110
      unsigned int rec_len;
6904
110
      unsigned int pad_len;
6905
110
      unsigned char *rec;
6906
110
      unsigned int hdr_size;
6907
110
      unsigned int type;
6908
110
      unsigned char buf[6];
6909
6910
110
      hdr_size = has_records ? 6 : 4;
6911
110
      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
109
      type = bfd_getl16 (buf);
6918
109
      rec_len = bfd_getl16 (buf + 2);
6919
109
      pad_len = rec_len;
6920
109
      if (has_records)
6921
27
  {
6922
27
    unsigned int rec_len2 = bfd_getl16 (buf + 4);
6923
6924
27
    if (is_first)
6925
27
      {
6926
27
        is_first = false;
6927
27
        if (type == rec_len2 && rec_len == EOBJ__C_EMH)
6928
    /* Matched a VMS record EMH.  */
6929
0
    ;
6930
27
        else
6931
27
    {
6932
27
      has_records = false;
6933
27
      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
27
    }
6940
27
      }
6941
6942
25
    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
25
  }
6957
6958
107
      if (rec_len < hdr_size)
6959
4
  {
6960
4
    fprintf (file, _("corrupted GST\n"));
6961
4
    return;
6962
4
  }
6963
6964
103
      rec = bfd_malloc (pad_len);
6965
103
      if (rec == NULL)
6966
0
  return;
6967
6968
103
      memcpy (rec, buf + (has_records ? 2 : 0), hdr_size);
6969
6970
103
      if (bfd_read (rec + hdr_size, pad_len - hdr_size, abfd)
6971
103
    != pad_len - hdr_size)
6972
13
  {
6973
13
    fprintf (file, _("cannot read GST record\n"));
6974
13
    free (rec);
6975
13
    return;
6976
13
  }
6977
6978
90
      switch (type)
6979
90
  {
6980
25
  case EOBJ__C_EMH:
6981
25
    evax_bfd_print_emh (file, rec, rec_len);
6982
25
    break;
6983
2
  case EOBJ__C_EGSD:
6984
2
    evax_bfd_print_egsd (file, rec, rec_len);
6985
2
    break;
6986
7
  case EOBJ__C_EEOM:
6987
7
    evax_bfd_print_eeom (file, rec, rec_len);
6988
7
    free (rec);
6989
7
    return;
6990
0
  case EOBJ__C_ETIR:
6991
0
    evax_bfd_print_etir (file, "ETIR", rec, rec_len);
6992
0
    break;
6993
8
  case EOBJ__C_EDBG:
6994
8
    evax_bfd_print_etir (file, "EDBG", rec, rec_len);
6995
8
    break;
6996
0
  case EOBJ__C_ETBT:
6997
0
    evax_bfd_print_etir (file, "ETBT", rec, rec_len);
6998
0
    break;
6999
48
  default:
7000
48
    fprintf (file, _(" unhandled EOBJ record type %u\n"), type);
7001
48
    break;
7002
90
  }
7003
83
      free (rec);
7004
83
    }
7005
27
}
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
246
{
7012
338
  while (off <= buf_size - 8)
7013
108
    {
7014
108
      unsigned int base;
7015
108
      unsigned int count;
7016
108
      unsigned int j;
7017
7018
108
      count = bfd_getl32 (buf + off + 0);
7019
7020
108
      if (count == 0)
7021
16
  break;
7022
92
      base = bfd_getl32 (buf + off + 4);
7023
7024
      /* xgettext:c-format */
7025
92
      fprintf (file, _("  bitcount: %u, base addr: 0x%08x\n"),
7026
92
         count, base);
7027
7028
92
      off += 8;
7029
15.1k
      for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32)
7030
15.0k
  {
7031
15.0k
    unsigned int k;
7032
15.0k
    unsigned int n = 0;
7033
15.0k
    unsigned int val;
7034
7035
15.0k
    val = bfd_getl32 (buf + off);
7036
15.0k
    off += 4;
7037
7038
    /* xgettext:c-format */
7039
15.0k
    fprintf (file, _("   bitmap: 0x%08x (count: %u):\n"), val, count);
7040
7041
496k
    for (k = 0; k < 32; k++)
7042
481k
      if (val & (1u << k))
7043
115k
        {
7044
115k
    if (n == 0)
7045
19.1k
      fputs ("   ", file);
7046
115k
    fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
7047
115k
    n++;
7048
115k
    if (n == 8)
7049
10.8k
      {
7050
10.8k
        fputs ("\n", file);
7051
10.8k
        n = 0;
7052
10.8k
      }
7053
115k
        }
7054
15.0k
    if (n)
7055
8.31k
      fputs ("\n", file);
7056
15.0k
  }
7057
92
    }
7058
246
}
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
260
{
7064
330
  while (off <= buf_size - 8)
7065
84
    {
7066
84
      unsigned int j;
7067
84
      unsigned int count;
7068
7069
84
      count = bfd_getl32 (buf + off + 0);
7070
84
      if (count == 0)
7071
14
  return;
7072
      /* xgettext:c-format */
7073
70
      fprintf (file, _("  image %u (%u entries)\n"),
7074
70
         (unsigned) bfd_getl32 (buf + off + 4), count);
7075
70
      off += 8;
7076
3.05k
      for (j = 0; j < count && off <= buf_size - 8; j++)
7077
2.98k
  {
7078
    /* xgettext:c-format */
7079
2.98k
    fprintf (file, _("   offset: 0x%08x, val: 0x%08x\n"),
7080
2.98k
       (unsigned) bfd_getl32 (buf + off + 0),
7081
2.98k
       (unsigned) bfd_getl32 (buf + off + 4));
7082
2.98k
    off += 8;
7083
2.98k
  }
7084
70
    }
7085
260
}
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
238
{
7091
238
  unsigned int count;
7092
7093
319
  while (off <= buf_size - 8)
7094
100
    {
7095
100
      unsigned int j;
7096
100
      unsigned int n = 0;
7097
7098
100
      count = bfd_getl32 (buf + off + 0);
7099
100
      if (count == 0)
7100
19
  break;
7101
      /* xgettext:c-format */
7102
81
      fprintf (file, _("  image %u (%u entries), offsets:\n"),
7103
81
         (unsigned) bfd_getl32 (buf + off + 4), count);
7104
81
      off += 8;
7105
14.6k
      for (j = 0; j < count && off <= buf_size - 4; j++)
7106
14.5k
  {
7107
14.5k
    if (n == 0)
7108
2.11k
      fputs ("   ", file);
7109
14.5k
    fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off));
7110
14.5k
    n++;
7111
14.5k
    if (n == 7)
7112
2.05k
      {
7113
2.05k
        fputs ("\n", file);
7114
2.05k
        n = 0;
7115
2.05k
      }
7116
14.5k
    off += 4;
7117
14.5k
  }
7118
81
      if (n)
7119
64
  fputs ("\n", file);
7120
81
    }
7121
238
}
7122
7123
static void
7124
evax_bfd_print_indent (int indent, FILE *file)
7125
110
{
7126
551
  for (; indent; indent--)
7127
441
    fputc (' ', file);
7128
110
}
7129
7130
static const char *
7131
evax_bfd_get_dsc_name (unsigned int v)
7132
112
{
7133
112
  switch (v)
7134
112
    {
7135
0
    case DSC__K_DTYPE_Z:
7136
0
      return "Z (Unspecified)";
7137
6
    case DSC__K_DTYPE_V:
7138
6
      return "V (Bit)";
7139
22
    case DSC__K_DTYPE_BU:
7140
22
      return "BU (Byte logical)";
7141
6
    case DSC__K_DTYPE_WU:
7142
6
      return "WU (Word logical)";
7143
6
    case DSC__K_DTYPE_LU:
7144
6
      return "LU (Longword logical)";
7145
3
    case DSC__K_DTYPE_QU:
7146
3
      return "QU (Quadword logical)";
7147
1
    case DSC__K_DTYPE_B:
7148
1
      return "B (Byte integer)";
7149
4
    case DSC__K_DTYPE_W:
7150
4
      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
1
    case DSC__K_DTYPE_F:
7156
1
      return "F (Single-precision floating)";
7157
2
    case DSC__K_DTYPE_D:
7158
2
      return "D (Double-precision floating)";
7159
2
    case DSC__K_DTYPE_FC:
7160
2
      return "FC (Complex)";
7161
2
    case DSC__K_DTYPE_DC:
7162
2
      return "DC (Double-precision Complex)";
7163
4
    case DSC__K_DTYPE_T:
7164
4
      return "T (ASCII text string)";
7165
5
    case DSC__K_DTYPE_NU:
7166
5
      return "NU (Numeric string, unsigned)";
7167
2
    case DSC__K_DTYPE_NL:
7168
2
      return "NL (Numeric string, left separate sign)";
7169
1
    case DSC__K_DTYPE_NLO:
7170
1
      return "NLO (Numeric string, left overpunched sign)";
7171
3
    case DSC__K_DTYPE_NR:
7172
3
      return "NR (Numeric string, right separate sign)";
7173
2
    case DSC__K_DTYPE_NRO:
7174
2
      return "NRO (Numeric string, right overpunched sig)";
7175
1
    case DSC__K_DTYPE_NZ:
7176
1
      return "NZ (Numeric string, zoned sign)";
7177
4
    case DSC__K_DTYPE_P:
7178
4
      return "P (Packed decimal string)";
7179
13
    case DSC__K_DTYPE_ZI:
7180
13
      return "ZI (Sequence of instructions)";
7181
2
    case DSC__K_DTYPE_ZEM:
7182
2
      return "ZEM (Procedure entry mask)";
7183
4
    case DSC__K_DTYPE_DSC:
7184
4
      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
1
    case DSC__K_DTYPE_H:
7192
1
      return "H (Quadruple precision floating, 128 bit)";
7193
1
    case DSC__K_DTYPE_GC:
7194
1
      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
1
    case DSC__K_DTYPE_BPV:
7200
1
      return "BPV (Bound Procedure Value)";
7201
1
    case DSC__K_DTYPE_BLV:
7202
1
      return "BLV (Bound Label Value)";
7203
1
    case DSC__K_DTYPE_VU:
7204
1
      return "VU (Bit Unaligned)";
7205
2
    case DSC__K_DTYPE_ADT:
7206
2
      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
1
    case DSC__K_DTYPE_VT2:
7212
1
      return "VT2 (16-bit varying char)";
7213
0
    default:
7214
0
      return "?? (unknown)";
7215
112
    }
7216
112
}
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
114
{
7326
114
  if (bufsize < 5)
7327
5
    return bufsize;
7328
7329
109
  unsigned int vflags = buf[0];
7330
109
  unsigned int value = (unsigned) bfd_getl32 (buf + 1);
7331
109
  unsigned int len = 5;
7332
7333
109
  evax_bfd_print_indent (indent, file);
7334
  /* xgettext:c-format */
7335
109
  fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
7336
109
  buf += 5;
7337
109
  bufsize -= 5;
7338
7339
109
  switch (vflags)
7340
109
    {
7341
2
    case DST__K_VFLAGS_NOVAL:
7342
2
      fprintf (file, _("(no value)\n"));
7343
2
      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
106
    default:
7365
      /* xgettext:c-format */
7366
106
      fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
7367
106
         (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
7368
106
         vflags & DST__K_DISP ? 1 : 0,
7369
106
         vflags & DST__K_INDIR ? 1 : 0);
7370
106
      switch (vflags & DST__K_VALKIND_MASK)
7371
106
  {
7372
57
  case DST__K_VALKIND_LITERAL:
7373
57
    fputs (_("literal"), file);
7374
57
    break;
7375
33
  case DST__K_VALKIND_ADDR:
7376
33
    fputs (_("address"), file);
7377
33
    break;
7378
14
  case DST__K_VALKIND_DESC:
7379
14
    fputs (_("desc"), file);
7380
14
    break;
7381
2
  case DST__K_VALKIND_REG:
7382
2
    fputs (_("reg"), file);
7383
2
    break;
7384
106
  }
7385
106
      fputs (")\n", file);
7386
106
      break;
7387
109
    }
7388
109
  return len;
7389
109
}
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
161
{
7484
161
  unsigned int off = 0;
7485
161
  unsigned int pc = 0;
7486
161
  unsigned int line = 0;
7487
7488
161
  fprintf (file, _("Debug symbol table:\n"));
7489
7490
908
  while (dst_size > 0)
7491
823
    {
7492
823
      struct vms_dst_header dsth;
7493
823
      unsigned int len;
7494
823
      unsigned int type;
7495
823
      unsigned char *buf;
7496
7497
823
      if (bfd_read (&dsth, sizeof (dsth), abfd) != sizeof (dsth))
7498
15
  {
7499
15
    fprintf (file, _("cannot read DST header\n"));
7500
15
    return;
7501
15
  }
7502
808
      len = bfd_getl16 (dsth.length);
7503
808
      type = bfd_getl16 (dsth.type);
7504
      /* xgettext:c-format */
7505
808
      fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
7506
808
         type, len, off);
7507
808
      if (len > dst_size)
7508
44
  len = dst_size;
7509
808
      if (len < sizeof (dsth))
7510
34
  {
7511
34
    fputc ('\n', file);
7512
34
    break;
7513
34
  }
7514
774
      dst_size -= len;
7515
774
      off += len;
7516
774
      len -= sizeof (dsth);
7517
774
      if (len == 0)
7518
2
  buf = NULL;
7519
772
      else
7520
772
  {
7521
772
    buf = _bfd_malloc_and_read (abfd, len, len);
7522
772
    if (buf == NULL)
7523
27
      {
7524
27
        fprintf (file, _("cannot read DST symbol\n"));
7525
27
        return;
7526
27
      }
7527
772
  }
7528
747
      switch (type)
7529
747
  {
7530
6
  case DSC__K_DTYPE_V:
7531
28
  case DSC__K_DTYPE_BU:
7532
34
  case DSC__K_DTYPE_WU:
7533
40
  case DSC__K_DTYPE_LU:
7534
43
  case DSC__K_DTYPE_QU:
7535
44
  case DSC__K_DTYPE_B:
7536
48
  case DSC__K_DTYPE_W:
7537
49
  case DSC__K_DTYPE_L:
7538
50
  case DSC__K_DTYPE_Q:
7539
51
  case DSC__K_DTYPE_F:
7540
53
  case DSC__K_DTYPE_D:
7541
55
  case DSC__K_DTYPE_FC:
7542
57
  case DSC__K_DTYPE_DC:
7543
61
  case DSC__K_DTYPE_T:
7544
66
  case DSC__K_DTYPE_NU:
7545
68
  case DSC__K_DTYPE_NL:
7546
69
  case DSC__K_DTYPE_NLO:
7547
72
  case DSC__K_DTYPE_NR:
7548
74
  case DSC__K_DTYPE_NRO:
7549
75
  case DSC__K_DTYPE_NZ:
7550
79
  case DSC__K_DTYPE_P:
7551
92
  case DSC__K_DTYPE_ZI:
7552
94
  case DSC__K_DTYPE_ZEM:
7553
98
  case DSC__K_DTYPE_DSC:
7554
99
  case DSC__K_DTYPE_OU:
7555
100
  case DSC__K_DTYPE_O:
7556
100
  case DSC__K_DTYPE_G:
7557
101
  case DSC__K_DTYPE_H:
7558
102
  case DSC__K_DTYPE_GC:
7559
103
  case DSC__K_DTYPE_HC:
7560
103
  case DSC__K_DTYPE_CIT:
7561
104
  case DSC__K_DTYPE_BPV:
7562
105
  case DSC__K_DTYPE_BLV:
7563
106
  case DSC__K_DTYPE_VU:
7564
108
  case DSC__K_DTYPE_ADT:
7565
110
  case DSC__K_DTYPE_VT:
7566
111
  case DSC__K_DTYPE_T2:
7567
112
  case DSC__K_DTYPE_VT2:
7568
112
    fprintf (file, _("standard data: %s\n"),
7569
112
       evax_bfd_get_dsc_name (type));
7570
112
    evax_bfd_print_valspec (buf, len, 4, file);
7571
112
    if (len > 6)
7572
106
      fprintf (file, _("    name: %.*s\n"),
7573
106
         buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7574
112
    break;
7575
1
  case DST__K_MODBEG:
7576
1
    {
7577
1
      struct vms_dst_modbeg *dst = (void *)buf;
7578
1
      unsigned char *name = buf + sizeof (*dst);
7579
7580
1
      fprintf (file, _("modbeg\n"));
7581
1
      if (len < sizeof (*dst))
7582
0
        break;
7583
      /* xgettext:c-format */
7584
1
      fprintf (file, _("   flags: %d, language: %u, "
7585
1
           "major: %u, minor: %u\n"),
7586
1
         dst->flags,
7587
1
         (unsigned)bfd_getl32 (dst->language),
7588
1
         (unsigned)bfd_getl16 (dst->major),
7589
1
         (unsigned)bfd_getl16 (dst->minor));
7590
1
      len -= sizeof (*dst);
7591
1
      if (len > 0)
7592
1
        {
7593
1
    int nlen = len - 1;
7594
1
    fprintf (file, _("   module name: %.*s\n"),
7595
1
       name[0] > nlen ? nlen : name[0], name + 1);
7596
1
    if (name[0] < nlen)
7597
1
      {
7598
1
        len -= name[0] + 1;
7599
1
        name += name[0] + 1;
7600
1
        nlen = len - 1;
7601
1
        fprintf (file, _("   compiler   : %.*s\n"),
7602
1
           name[0] > nlen ? nlen : name[0], name + 1);
7603
1
      }
7604
1
        }
7605
1
    }
7606
0
    break;
7607
1
  case DST__K_MODEND:
7608
1
    fprintf (file, _("modend\n"));
7609
1
    break;
7610
3
  case DST__K_RTNBEG:
7611
3
    {
7612
3
      struct vms_dst_rtnbeg *dst = (void *)buf;
7613
3
      unsigned char *name = buf + sizeof (*dst);
7614
7615
3
      fputs (_("rtnbeg\n"), file);
7616
3
      if (len >= sizeof (*dst))
7617
3
        {
7618
    /* xgettext:c-format */
7619
3
    fprintf (file, _("    flags: %u, address: 0x%08x, "
7620
3
         "pd-address: 0x%08x\n"),
7621
3
       dst->flags,
7622
3
       (unsigned) bfd_getl32 (dst->address),
7623
3
       (unsigned) bfd_getl32 (dst->pd_address));
7624
3
    len -= sizeof (*dst);
7625
3
    if (len > 0)
7626
3
      {
7627
3
        int nlen = len - 1;
7628
3
        fprintf (file, _("    routine name: %.*s\n"),
7629
3
           name[0] > nlen ? nlen : name[0], name + 1);
7630
3
      }
7631
3
        }
7632
3
    }
7633
3
    break;
7634
1
  case DST__K_RTNEND:
7635
1
    {
7636
1
      struct vms_dst_rtnend *dst = (void *)buf;
7637
7638
1
      if (len >= sizeof (*dst))
7639
1
        fprintf (file, _("rtnend: size 0x%08x\n"),
7640
1
           (unsigned) bfd_getl32 (dst->size));
7641
1
    }
7642
1
    break;
7643
1
  case DST__K_PROLOG:
7644
1
    {
7645
1
      struct vms_dst_prolog *dst = (void *)buf;
7646
7647
1
      if (len >= sizeof (*dst))
7648
        /* xgettext:c-format */
7649
1
        fprintf (file, _("prolog: bkpt address 0x%08x\n"),
7650
1
           (unsigned) bfd_getl32 (dst->bkpt_addr));
7651
1
    }
7652
1
    break;
7653
1
  case DST__K_EPILOG:
7654
1
    {
7655
1
      struct vms_dst_epilog *dst = (void *)buf;
7656
7657
1
      if (len >= sizeof (*dst))
7658
        /* xgettext:c-format */
7659
1
        fprintf (file, _("epilog: flags: %u, count: %u\n"),
7660
1
           dst->flags, (unsigned) bfd_getl32 (dst->count));
7661
1
    }
7662
1
    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
1
  case DST__K_ENUMELT:
7746
1
    if (len >= 6)
7747
1
      {
7748
1
        fprintf (file, _("enumelt, name: %.*s\n"),
7749
1
           buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7750
1
        evax_bfd_print_valspec (buf, len, 4, file);
7751
1
      }
7752
1
    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
3
  case DST__K_DIS_RANGE:
7770
3
    if (len >= 4)
7771
3
      {
7772
3
        unsigned int cnt = bfd_getl32 (buf);
7773
3
        unsigned char *rng = buf + 4;
7774
3
        unsigned int i;
7775
7776
3
        fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt);
7777
3
        len -= 4;
7778
3.82k
        for (i = 0; i < cnt; i++, rng += 8)
7779
3.82k
    {
7780
3.82k
      if (len < 8)
7781
3
        break;
7782
      /* xgettext:c-format */
7783
3.82k
      fprintf (file, _("    address: 0x%08x, size: %u\n"),
7784
3.82k
         (unsigned) bfd_getl32 (rng),
7785
3.82k
         (unsigned) bfd_getl32 (rng + 4));
7786
3.82k
      len -= 8;
7787
3.82k
    }
7788
3
      }
7789
3
    break;
7790
1
  case DST__K_LINE_NUM:
7791
1
    {
7792
1
      unsigned char *buf_orig = buf;
7793
7794
1
      fprintf (file, _("line num  (len: %u)\n"), len);
7795
7796
1
      while (len > 0)
7797
1
        {
7798
1
    int cmd;
7799
1
    unsigned int val;
7800
1
    int cmdlen = -1;
7801
7802
1
    cmd = *buf++;
7803
1
    len--;
7804
7805
1
    fputs ("    ", file);
7806
7807
1
    switch (cmd)
7808
1
      {
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
1
      default:
7895
1
        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
1
        else
7906
1
          fprintf (file, _("    *unhandled* cmd %u\n"), cmd);
7907
1
        break;
7908
1
      }
7909
1
    if (cmdlen < 0)
7910
1
      break;
7911
0
    len -= cmdlen;
7912
0
    buf += cmdlen;
7913
0
        }
7914
1
      buf = buf_orig;
7915
1
    }
7916
0
    break;
7917
2
  case DST__K_SOURCE:
7918
2
    {
7919
2
      unsigned char *buf_orig = buf;
7920
7921
2
      fprintf (file, _("source (len: %u)\n"), len);
7922
7923
3
      while (len > 0)
7924
3
        {
7925
3
    int cmd = *buf++;
7926
3
    int cmdlen = -1;
7927
7928
3
    len--;
7929
3
    switch (cmd)
7930
3
      {
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
1
      case DST__K_SRC_SETFILE:
7971
1
        if (len < 2)
7972
0
          break;
7973
1
        fprintf (file, _("   setfile %u\n"),
7974
1
           (unsigned) bfd_getl16 (buf));
7975
1
        cmdlen = 2;
7976
1
        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
2
      default:
8023
2
        fprintf (file, _("   *unhandled* cmd %u\n"), cmd);
8024
2
        break;
8025
3
      }
8026
3
    if (cmdlen < 0)
8027
2
      break;
8028
1
    len -= cmdlen;
8029
1
    buf += cmdlen;
8030
1
        }
8031
2
      buf = buf_orig;
8032
2
    }
8033
0
    break;
8034
614
  default:
8035
614
    fprintf (file, _("*unhandled* dst type %u\n"), type);
8036
614
    break;
8037
747
  }
8038
747
      free (buf);
8039
747
    }
8040
161
}
8041
8042
static void
8043
evax_bfd_print_image (bfd *abfd, FILE *file)
8044
323
{
8045
323
  struct vms_eihd eihd;
8046
323
  const char *name;
8047
323
  unsigned int val;
8048
323
  unsigned int eiha_off;
8049
323
  unsigned int eihi_off;
8050
323
  unsigned int eihs_off;
8051
323
  unsigned int eisd_off;
8052
323
  unsigned int eihef_off = 0;
8053
323
  unsigned int eihnp_off = 0;
8054
323
  unsigned int dmt_vbn = 0;
8055
323
  unsigned int dmt_size = 0;
8056
323
  unsigned int dst_vbn = 0;
8057
323
  unsigned int dst_size = 0;
8058
323
  unsigned int gst_vbn = 0;
8059
323
  unsigned int gst_size = 0;
8060
323
  unsigned int eiaf_vbn = 0;
8061
323
  unsigned int eiaf_size = 0;
8062
323
  unsigned int eihvn_off;
8063
8064
323
  if (bfd_seek (abfd, 0, SEEK_SET)
8065
323
      || 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
323
  fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
8072
323
     (unsigned)bfd_getl32 (eihd.size),
8073
323
     (unsigned)bfd_getl32 (eihd.hdrblkcnt));
8074
  /* xgettext:c-format */
8075
323
  fprintf (file, _(" majorid: %u, minorid: %u\n"),
8076
323
     (unsigned)bfd_getl32 (eihd.majorid),
8077
323
     (unsigned)bfd_getl32 (eihd.minorid));
8078
8079
323
  val = (unsigned)bfd_getl32 (eihd.imgtype);
8080
323
  switch (val)
8081
323
    {
8082
1
    case EIHD__K_EXE:
8083
1
      name = _("executable");
8084
1
      break;
8085
1
    case EIHD__K_LIM:
8086
1
      name = _("linkable image");
8087
1
      break;
8088
321
    default:
8089
321
      name = _("unknown");
8090
321
      break;
8091
323
    }
8092
  /* xgettext:c-format */
8093
323
  fprintf (file, _(" image type: %u (%s)"), val, name);
8094
8095
323
  val = (unsigned)bfd_getl32 (eihd.subtype);
8096
323
  switch (val)
8097
323
    {
8098
37
    case EIHD__C_NATIVE:
8099
37
      name = _("native");
8100
37
      break;
8101
31
    case EIHD__C_CLI:
8102
31
      name = _("CLI");
8103
31
      break;
8104
255
    default:
8105
255
      name = _("unknown");
8106
255
      break;
8107
323
    }
8108
  /* xgettext:c-format */
8109
323
  fprintf (file, _(", subtype: %u (%s)\n"), val, name);
8110
8111
323
  eisd_off = bfd_getl32 (eihd.isdoff);
8112
323
  eiha_off = bfd_getl32 (eihd.activoff);
8113
323
  eihi_off = bfd_getl32 (eihd.imgidoff);
8114
323
  eihs_off = bfd_getl32 (eihd.symdbgoff);
8115
  /* xgettext:c-format */
8116
323
  fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
8117
323
       "imgid: %u, patch: %u\n"),
8118
323
     eisd_off, eiha_off, eihs_off, eihi_off,
8119
323
     (unsigned)bfd_getl32 (eihd.patchoff));
8120
323
  fprintf (file, _(" fixup info rva: "));
8121
323
  bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
8122
323
  fprintf (file, _(", symbol vector rva: "));
8123
323
  bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
8124
323
  eihvn_off = bfd_getl32 (eihd.version_array_off);
8125
323
  fprintf (file, _("\n"
8126
323
       " version array off: %u\n"),
8127
323
     eihvn_off);
8128
323
  fprintf (file,
8129
     /* xgettext:c-format */
8130
323
     _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
8131
323
     (unsigned)bfd_getl32 (eihd.imgiocnt),
8132
323
     (unsigned)bfd_getl32 (eihd.iochancnt),
8133
323
     (unsigned)bfd_getl32 (eihd.privreqs + 4),
8134
323
     (unsigned)bfd_getl32 (eihd.privreqs + 0));
8135
323
  val = (unsigned)bfd_getl32 (eihd.lnkflags);
8136
323
  fprintf (file, _(" linker flags: %08x:"), val);
8137
323
  if (val & EIHD__M_LNKDEBUG)
8138
109
    fprintf (file, " LNKDEBUG");
8139
323
  if (val & EIHD__M_LNKNOTFR)
8140
53
    fprintf (file, " LNKNOTFR");
8141
323
  if (val & EIHD__M_NOP0BUFS)
8142
88
    fprintf (file, " NOP0BUFS");
8143
323
  if (val & EIHD__M_PICIMG)
8144
147
    fprintf (file, " PICIMG");
8145
323
  if (val & EIHD__M_P0IMAGE)
8146
51
    fprintf (file, " P0IMAGE");
8147
323
  if (val & EIHD__M_DBGDMT)
8148
30
    fprintf (file, " DBGDMT");
8149
323
  if (val & EIHD__M_INISHR)
8150
25
    fprintf (file, " INISHR");
8151
323
  if (val & EIHD__M_XLATED)
8152
24
    fprintf (file, " XLATED");
8153
323
  if (val & EIHD__M_BIND_CODE_SEC)
8154
90
    fprintf (file, " BIND_CODE_SEC");
8155
323
  if (val & EIHD__M_BIND_DATA_SEC)
8156
77
    fprintf (file, " BIND_DATA_SEC");
8157
323
  if (val & EIHD__M_MKTHREADS)
8158
120
    fprintf (file, " MKTHREADS");
8159
323
  if (val & EIHD__M_UPCALLS)
8160
118
    fprintf (file, " UPCALLS");
8161
323
  if (val & EIHD__M_OMV_READY)
8162
118
    fprintf (file, " OMV_READY");
8163
323
  if (val & EIHD__M_EXT_BIND_SECT)
8164
179
    fprintf (file, " EXT_BIND_SECT");
8165
323
  fprintf (file, "\n");
8166
  /* xgettext:c-format */
8167
323
  fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
8168
323
       "match ctrl: %u, symvect_size: %u\n"),
8169
323
     (unsigned)bfd_getl32 (eihd.ident),
8170
323
     (unsigned)bfd_getl32 (eihd.sysver),
8171
323
     eihd.matchctl,
8172
323
     (unsigned)bfd_getl32 (eihd.symvect_size));
8173
323
  fprintf (file, _(" BPAGE: %u"),
8174
323
     (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
8175
323
  if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT))
8176
215
    {
8177
215
      eihef_off = bfd_getl32 (eihd.ext_fixup_off);
8178
215
      eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
8179
      /* xgettext:c-format */
8180
215
      fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
8181
215
         eihef_off, eihnp_off);
8182
215
    }
8183
323
  fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias));
8184
8185
323
  if (eihvn_off != 0)
8186
238
    {
8187
238
      struct vms_eihvn eihvn;
8188
238
      unsigned int mask;
8189
238
      unsigned int j;
8190
8191
238
      fprintf (file, _("system version array information:\n"));
8192
238
      if (bfd_seek (abfd, eihvn_off, SEEK_SET)
8193
238
    || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
8194
13
  {
8195
13
    fprintf (file, _("cannot read EIHVN header\n"));
8196
13
    return;
8197
13
  }
8198
225
      mask = bfd_getl32 (eihvn.subsystem_mask);
8199
7.29k
      for (j = 0; j < 32; j++)
8200
7.07k
  if (mask & (1u << j))
8201
1.50k
    {
8202
1.50k
      struct vms_eihvn_subversion ver;
8203
1.50k
      if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver))
8204
5
        {
8205
5
    fprintf (file, _("cannot read EIHVN version\n"));
8206
5
    return;
8207
5
        }
8208
1.49k
      fprintf (file, _("   %02u "), j);
8209
1.49k
      switch (j)
8210
1.49k
        {
8211
52
        case EIHVN__BASE_IMAGE_BIT:
8212
52
    fputs (_("BASE_IMAGE       "), file);
8213
52
    break;
8214
50
        case EIHVN__MEMORY_MANAGEMENT_BIT:
8215
50
    fputs (_("MEMORY_MANAGEMENT"), file);
8216
50
    break;
8217
62
        case EIHVN__IO_BIT:
8218
62
    fputs (_("IO               "), file);
8219
62
    break;
8220
57
        case EIHVN__FILES_VOLUMES_BIT:
8221
57
    fputs (_("FILES_VOLUMES    "), file);
8222
57
    break;
8223
40
        case EIHVN__PROCESS_SCHED_BIT:
8224
40
    fputs (_("PROCESS_SCHED    "), file);
8225
40
    break;
8226
59
        case EIHVN__SYSGEN_BIT:
8227
59
    fputs (_("SYSGEN           "), file);
8228
59
    break;
8229
50
        case EIHVN__CLUSTERS_LOCKMGR_BIT:
8230
50
    fputs (_("CLUSTERS_LOCKMGR "), file);
8231
50
    break;
8232
33
        case EIHVN__LOGICAL_NAMES_BIT:
8233
33
    fputs (_("LOGICAL_NAMES    "), file);
8234
33
    break;
8235
51
        case EIHVN__SECURITY_BIT:
8236
51
    fputs (_("SECURITY         "), file);
8237
51
    break;
8238
43
        case EIHVN__IMAGE_ACTIVATOR_BIT:
8239
43
    fputs (_("IMAGE_ACTIVATOR  "), file);
8240
43
    break;
8241
34
        case EIHVN__NETWORKS_BIT:
8242
34
    fputs (_("NETWORKS         "), file);
8243
34
    break;
8244
47
        case EIHVN__COUNTERS_BIT:
8245
47
    fputs (_("COUNTERS         "), file);
8246
47
    break;
8247
32
        case EIHVN__STABLE_BIT:
8248
32
    fputs (_("STABLE           "), file);
8249
32
    break;
8250
59
        case EIHVN__MISC_BIT:
8251
59
    fputs (_("MISC             "), file);
8252
59
    break;
8253
57
        case EIHVN__CPU_BIT:
8254
57
    fputs (_("CPU              "), file);
8255
57
    break;
8256
22
        case EIHVN__VOLATILE_BIT:
8257
22
    fputs (_("VOLATILE         "), file);
8258
22
    break;
8259
24
        case EIHVN__SHELL_BIT:
8260
24
    fputs (_("SHELL            "), file);
8261
24
    break;
8262
36
        case EIHVN__POSIX_BIT:
8263
36
    fputs (_("POSIX            "), file);
8264
36
    break;
8265
44
        case EIHVN__MULTI_PROCESSING_BIT:
8266
44
    fputs (_("MULTI_PROCESSING "), file);
8267
44
    break;
8268
23
        case EIHVN__GALAXY_BIT:
8269
23
    fputs (_("GALAXY           "), file);
8270
23
    break;
8271
621
        default:
8272
621
    fputs (_("*unknown*        "), file);
8273
621
    break;
8274
1.49k
        }
8275
1.49k
      fprintf (file, ": %u.%u\n",
8276
1.49k
         (unsigned)bfd_getl16 (ver.major),
8277
1.49k
         (unsigned)bfd_getl16 (ver.minor));
8278
1.49k
    }
8279
225
    }
8280
8281
305
  if (eiha_off != 0)
8282
215
    {
8283
215
      struct vms_eiha eiha;
8284
8285
215
      if (bfd_seek (abfd, eiha_off, SEEK_SET)
8286
215
    || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
8287
5
  {
8288
5
    fprintf (file, _("cannot read EIHA\n"));
8289
5
    return;
8290
5
  }
8291
210
      fprintf (file, _("Image activation:  (size=%u)\n"),
8292
210
         (unsigned)bfd_getl32 (eiha.size));
8293
      /* xgettext:c-format */
8294
210
      fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
8295
210
         (unsigned)bfd_getl32 (eiha.tfradr1_h),
8296
210
         (unsigned)bfd_getl32 (eiha.tfradr1));
8297
      /* xgettext:c-format */
8298
210
      fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
8299
210
         (unsigned)bfd_getl32 (eiha.tfradr2_h),
8300
210
         (unsigned)bfd_getl32 (eiha.tfradr2));
8301
      /* xgettext:c-format */
8302
210
      fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
8303
210
         (unsigned)bfd_getl32 (eiha.tfradr3_h),
8304
210
         (unsigned)bfd_getl32 (eiha.tfradr3));
8305
      /* xgettext:c-format */
8306
210
      fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
8307
210
         (unsigned)bfd_getl32 (eiha.tfradr4_h),
8308
210
         (unsigned)bfd_getl32 (eiha.tfradr4));
8309
      /* xgettext:c-format */
8310
210
      fprintf (file, _(" Shared image  : 0x%08x 0x%08x\n"),
8311
210
         (unsigned)bfd_getl32 (eiha.inishr_h),
8312
210
         (unsigned)bfd_getl32 (eiha.inishr));
8313
210
    }
8314
300
  if (eihi_off != 0)
8315
150
    {
8316
150
      struct vms_eihi eihi;
8317
8318
150
      if (bfd_seek (abfd, eihi_off, SEEK_SET)
8319
150
    || 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
149
      fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
8326
149
         (unsigned) bfd_getl32 (eihi.majorid),
8327
149
         (unsigned) bfd_getl32 (eihi.minorid));
8328
149
      unsigned int nlen = eihi.imgnam[0];
8329
149
      if (nlen > sizeof (eihi.imgnam) - 1)
8330
77
  nlen = sizeof (eihi.imgnam) - 1;
8331
149
      fprintf (file, _(" image name       : %.*s\n"), nlen, eihi.imgnam + 1);
8332
149
      fprintf (file, _(" link time        : %s\n"),
8333
149
         vms_time_to_str (eihi.linktime));
8334
149
      nlen = eihi.imgid[0];
8335
149
      if (nlen > sizeof (eihi.imgid) - 1)
8336
68
  nlen = sizeof (eihi.imgid) - 1;
8337
149
      fprintf (file, _(" image ident      : %.*s\n"), nlen, eihi.imgid + 1);
8338
149
      nlen = eihi.linkid[0];
8339
149
      if (nlen > sizeof (eihi.linkid) - 1)
8340
28
  nlen = sizeof (eihi.linkid) - 1;
8341
149
      fprintf (file, _(" linker ident     : %.*s\n"), nlen, eihi.linkid + 1);
8342
149
      nlen = eihi.imgbid[0];
8343
149
      if (nlen > sizeof (eihi.imgbid) -1 )
8344
126
  nlen = sizeof (eihi.imgbid) - 1;
8345
149
      fprintf (file, _(" image build ident: %.*s\n"), nlen, eihi.imgbid + 1);
8346
149
    }
8347
299
  if (eihs_off != 0)
8348
229
    {
8349
229
      struct vms_eihs eihs;
8350
8351
229
      if (bfd_seek (abfd, eihs_off, SEEK_SET)
8352
229
    || 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
229
      fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
8359
229
         (unsigned)bfd_getl32 (eihs.majorid),
8360
229
         (unsigned)bfd_getl32 (eihs.minorid));
8361
229
      dst_vbn = bfd_getl32 (eihs.dstvbn);
8362
229
      dst_size = bfd_getl32 (eihs.dstsize);
8363
      /* xgettext:c-format */
8364
229
      fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"),
8365
229
         dst_vbn, dst_size, dst_size);
8366
229
      gst_vbn = bfd_getl32 (eihs.gstvbn);
8367
229
      gst_size = bfd_getl32 (eihs.gstsize);
8368
      /* xgettext:c-format */
8369
229
      fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
8370
229
         gst_vbn, gst_size);
8371
229
      dmt_vbn = bfd_getl32 (eihs.dmtvbn);
8372
229
      dmt_size = bfd_getl32 (eihs.dmtsize);
8373
      /* xgettext:c-format */
8374
229
      fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
8375
229
         dmt_vbn, dmt_size);
8376
229
    }
8377
534
  while (eisd_off != 0)
8378
512
    {
8379
512
      struct vms_eisd eisd;
8380
512
      unsigned int len;
8381
8382
512
      while (1)
8383
512
  {
8384
512
    if (bfd_seek (abfd, eisd_off, SEEK_SET)
8385
512
        || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
8386
8
      {
8387
8
        fprintf (file, _("cannot read EISD\n"));
8388
8
        return;
8389
8
      }
8390
504
    len = (unsigned)bfd_getl32 (eisd.eisdsize);
8391
504
    if (len != (unsigned)-1)
8392
504
      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
504
      fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
8399
504
           "size: %u, offset: %u)\n"),
8400
504
         (unsigned)bfd_getl32 (eisd.majorid),
8401
504
         (unsigned)bfd_getl32 (eisd.minorid),
8402
504
         len, eisd_off);
8403
504
      if (len == 0)
8404
269
  break;
8405
      /* xgettext:c-format */
8406
235
      fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
8407
235
         (unsigned)bfd_getl32 (eisd.virt_addr + 4),
8408
235
         (unsigned)bfd_getl32 (eisd.virt_addr + 0),
8409
235
         (unsigned)bfd_getl32 (eisd.secsize));
8410
235
      val = (unsigned)bfd_getl32 (eisd.flags);
8411
235
      fprintf (file, _(" flags: 0x%04x"), val);
8412
235
      if (val & EISD__M_GBL)
8413
177
  fprintf (file, " GBL");
8414
235
      if (val & EISD__M_CRF)
8415
115
  fprintf (file, " CRF");
8416
235
      if (val & EISD__M_DZRO)
8417
182
  fprintf (file, " DZRO");
8418
235
      if (val & EISD__M_WRT)
8419
183
  fprintf (file, " WRT");
8420
235
      if (val & EISD__M_INITALCODE)
8421
111
  fprintf (file, " INITALCODE");
8422
235
      if (val & EISD__M_BASED)
8423
115
  fprintf (file, " BASED");
8424
235
      if (val & EISD__M_FIXUPVEC)
8425
197
  fprintf (file, " FIXUPVEC");
8426
235
      if (val & EISD__M_RESIDENT)
8427
114
  fprintf (file, " RESIDENT");
8428
235
      if (val & EISD__M_VECTOR)
8429
113
  fprintf (file, " VECTOR");
8430
235
      if (val & EISD__M_PROTECT)
8431
178
  fprintf (file, " PROTECT");
8432
235
      if (val & EISD__M_LASTCLU)
8433
118
  fprintf (file, " LASTCLU");
8434
235
      if (val & EISD__M_EXE)
8435
123
  fprintf (file, " EXE");
8436
235
      if (val & EISD__M_NONSHRADR)
8437
113
  fprintf (file, " NONSHRADR");
8438
235
      if (val & EISD__M_QUAD_LENGTH)
8439
117
  fprintf (file, " QUAD_LENGTH");
8440
235
      if (val & EISD__M_ALLOC_64BIT)
8441
185
  fprintf (file, " ALLOC_64BIT");
8442
235
      fprintf (file, "\n");
8443
235
      if (val & EISD__M_FIXUPVEC)
8444
197
  {
8445
197
    eiaf_vbn = bfd_getl32 (eisd.vbn);
8446
197
    eiaf_size = bfd_getl32 (eisd.secsize);
8447
197
  }
8448
      /* xgettext:c-format */
8449
235
      fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
8450
235
         (unsigned)bfd_getl32 (eisd.vbn),
8451
235
         eisd.pfc, eisd.matchctl, eisd.type);
8452
235
      switch (eisd.type)
8453
235
  {
8454
94
  case EISD__K_NORMAL:
8455
94
    fputs (_("NORMAL"), file);
8456
94
    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
1
  case EISD__K_SHRPIC:
8464
1
    fputs (_("SHRPIC"), file);
8465
1
    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
139
  default:
8473
139
    fputs (_("*unknown*"), file);
8474
139
    break;
8475
235
  }
8476
235
      fputs (_(")\n"), file);
8477
235
      if (val & EISD__M_GBL)
8478
177
  {
8479
177
    unsigned int nlen = eisd.gblnam[0];
8480
177
    if (nlen > sizeof (eisd.gblnam) - 1)
8481
0
      nlen = sizeof (eisd.gblnam) - 1;
8482
    /* xgettext:c-format */
8483
177
    fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
8484
177
       (unsigned) bfd_getl32 (eisd.ident),
8485
177
       nlen, eisd.gblnam + 1);
8486
177
  }
8487
235
      eisd_off += len;
8488
235
    }
8489
8490
291
  if (dmt_vbn != 0)
8491
102
    {
8492
102
      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
102
      fprintf (file, _("Debug module table:\n"));
8499
8500
1.44k
      while (dmt_size > 0)
8501
1.37k
  {
8502
1.37k
    struct vms_dmt_header dmth;
8503
1.37k
    unsigned int count;
8504
8505
1.37k
    if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
8506
12
      {
8507
12
        fprintf (file, _("cannot read DMT header\n"));
8508
12
        return;
8509
12
      }
8510
1.35k
    count = bfd_getl16 (dmth.psect_count);
8511
1.35k
    fprintf (file,
8512
       /* xgettext:c-format */
8513
1.35k
       _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"),
8514
1.35k
       (unsigned)bfd_getl32 (dmth.modbeg),
8515
1.35k
       (unsigned)bfd_getl32 (dmth.size), count);
8516
1.35k
    dmt_size -= sizeof (dmth);
8517
6.30k
    while (count > 0)
8518
4.96k
      {
8519
4.96k
        struct vms_dmt_psect dmtp;
8520
8521
4.96k
        if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
8522
19
    {
8523
19
      fprintf (file, _("cannot read DMT psect\n"));
8524
19
      return;
8525
19
    }
8526
        /* xgettext:c-format */
8527
4.94k
        fprintf (file, _("  psect start: 0x%08x, length: %u\n"),
8528
4.94k
           (unsigned)bfd_getl32 (dmtp.start),
8529
4.94k
           (unsigned)bfd_getl32 (dmtp.length));
8530
4.94k
        count--;
8531
4.94k
        dmt_size -= sizeof (dmtp);
8532
4.94k
      }
8533
1.35k
  }
8534
102
    }
8535
8536
260
  if (dst_vbn != 0)
8537
161
    {
8538
161
      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
161
      evax_bfd_print_dst (abfd, dst_size, file);
8545
161
    }
8546
260
  if (gst_vbn != 0)
8547
19
    {
8548
19
      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
19
      fprintf (file, _("Global symbol table:\n"));
8555
19
      evax_bfd_print_eobj (abfd, file);
8556
19
    }
8557
260
  if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf))
8558
182
    {
8559
182
      unsigned char *buf;
8560
182
      struct vms_eiaf *eiaf;
8561
182
      unsigned int qrelfixoff;
8562
182
      unsigned int lrelfixoff;
8563
182
      unsigned int qdotadroff;
8564
182
      unsigned int ldotadroff;
8565
182
      unsigned int shrimgcnt;
8566
182
      unsigned int shlstoff;
8567
182
      unsigned int codeadroff;
8568
182
      unsigned int lpfixoff;
8569
182
      unsigned int chgprtoff;
8570
182
      file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE;
8571
8572
182
      if (bfd_seek (abfd, f_off, SEEK_SET) != 0
8573
182
    || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL)
8574
35
  {
8575
35
    fprintf (file, _("cannot read EIHA\n"));
8576
35
    return;
8577
35
  }
8578
147
      eiaf = (struct vms_eiaf *)buf;
8579
147
      fprintf (file,
8580
         /* xgettext:c-format */
8581
147
         _("Image activator fixup: (major: %u, minor: %u)\n"),
8582
147
         (unsigned)bfd_getl32 (eiaf->majorid),
8583
147
         (unsigned)bfd_getl32 (eiaf->minorid));
8584
      /* xgettext:c-format */
8585
147
      fprintf (file, _("  iaflink : 0x%08x %08x\n"),
8586
147
         (unsigned)bfd_getl32 (eiaf->iaflink + 0),
8587
147
         (unsigned)bfd_getl32 (eiaf->iaflink + 4));
8588
      /* xgettext:c-format */
8589
147
      fprintf (file, _("  fixuplnk: 0x%08x %08x\n"),
8590
147
         (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
8591
147
         (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
8592
147
      fprintf (file, _("  size : %u\n"),
8593
147
         (unsigned)bfd_getl32 (eiaf->size));
8594
147
      fprintf (file, _("  flags: 0x%08x\n"),
8595
147
         (unsigned)bfd_getl32 (eiaf->flags));
8596
147
      qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
8597
147
      lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
8598
      /* xgettext:c-format */
8599
147
      fprintf (file, _("  qrelfixoff: %5u, lrelfixoff: %5u\n"),
8600
147
         qrelfixoff, lrelfixoff);
8601
147
      qdotadroff = bfd_getl32 (eiaf->qdotadroff);
8602
147
      ldotadroff = bfd_getl32 (eiaf->ldotadroff);
8603
      /* xgettext:c-format */
8604
147
      fprintf (file, _("  qdotadroff: %5u, ldotadroff: %5u\n"),
8605
147
         qdotadroff, ldotadroff);
8606
147
      codeadroff = bfd_getl32 (eiaf->codeadroff);
8607
147
      lpfixoff = bfd_getl32 (eiaf->lpfixoff);
8608
      /* xgettext:c-format */
8609
147
      fprintf (file, _("  codeadroff: %5u, lpfixoff  : %5u\n"),
8610
147
         codeadroff, lpfixoff);
8611
147
      chgprtoff = bfd_getl32 (eiaf->chgprtoff);
8612
147
      fprintf (file, _("  chgprtoff : %5u\n"), chgprtoff);
8613
147
      shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
8614
147
      shlstoff = bfd_getl32 (eiaf->shlstoff);
8615
      /* xgettext:c-format */
8616
147
      fprintf (file, _("  shlstoff  : %5u, shrimgcnt : %5u\n"),
8617
147
         shlstoff, shrimgcnt);
8618
      /* xgettext:c-format */
8619
147
      fprintf (file, _("  shlextra  : %5u, permctx   : %5u\n"),
8620
147
         (unsigned)bfd_getl32 (eiaf->shlextra),
8621
147
         (unsigned)bfd_getl32 (eiaf->permctx));
8622
147
      fprintf (file, _("  base_va : 0x%08x\n"),
8623
147
         (unsigned)bfd_getl32 (eiaf->base_va));
8624
147
      fprintf (file, _("  lppsbfixoff: %5u\n"),
8625
147
         (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
8626
8627
147
      if (shlstoff)
8628
115
  {
8629
115
    unsigned int j;
8630
8631
115
    fprintf (file, _(" Shareable images:\n"));
8632
115
    for (j = 0;
8633
327
         j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl);
8634
212
         j++, shlstoff += sizeof (struct vms_shl))
8635
212
      {
8636
212
        struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff);
8637
212
        unsigned int nlen = shl->imgnam[0];
8638
212
        if (nlen > sizeof (shl->imgnam) - 1)
8639
79
    nlen = sizeof (shl->imgnam) - 1;
8640
212
        fprintf (file,
8641
           /* xgettext:c-format */
8642
212
           _("  %u: size: %u, flags: 0x%02x, name: %.*s\n"),
8643
212
           j, shl->size, shl->flags,
8644
212
           nlen, shl->imgnam + 1);
8645
212
      }
8646
115
  }
8647
147
      if (qrelfixoff != 0)
8648
126
  {
8649
126
    fprintf (file, _(" quad-word relocation fixups:\n"));
8650
126
    evax_bfd_print_relocation_records (file, buf, eiaf_size,
8651
126
               qrelfixoff, 8);
8652
126
  }
8653
147
      if (lrelfixoff != 0)
8654
120
  {
8655
120
    fprintf (file, _(" long-word relocation fixups:\n"));
8656
120
    evax_bfd_print_relocation_records (file, buf, eiaf_size,
8657
120
               lrelfixoff, 4);
8658
120
  }
8659
147
      if (qdotadroff != 0)
8660
128
  {
8661
128
    fprintf (file, _(" quad-word .address reference fixups:\n"));
8662
128
    evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff);
8663
128
  }
8664
147
      if (ldotadroff != 0)
8665
132
  {
8666
132
    fprintf (file, _(" long-word .address reference fixups:\n"));
8667
132
    evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff);
8668
132
  }
8669
147
      if (codeadroff != 0)
8670
121
  {
8671
121
    fprintf (file, _(" Code Address Reference Fixups:\n"));
8672
121
    evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff);
8673
121
  }
8674
147
      if (lpfixoff != 0)
8675
117
  {
8676
117
    fprintf (file, _(" Linkage Pairs Reference Fixups:\n"));
8677
117
    evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff);
8678
117
  }
8679
147
      if (chgprtoff && chgprtoff <= eiaf_size - 4)
8680
95
  {
8681
95
    unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff);
8682
95
    unsigned int j;
8683
8684
95
    fprintf (file, _(" Change Protection (%u entries):\n"), count);
8685
95
    for (j = 0, chgprtoff += 4;
8686
4.95k
         j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp);
8687
4.85k
         j++, chgprtoff += sizeof (struct vms_eicp))
8688
4.85k
      {
8689
4.85k
        struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff);
8690
4.85k
        unsigned int prot = bfd_getl32 (eicp->newprt);
8691
4.85k
        fprintf (file,
8692
           /* xgettext:c-format */
8693
4.85k
           _("  base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
8694
4.85k
           (unsigned) bfd_getl32 (eicp->baseva + 4),
8695
4.85k
           (unsigned) bfd_getl32 (eicp->baseva + 0),
8696
4.85k
           (unsigned) bfd_getl32 (eicp->size),
8697
4.85k
           (unsigned) bfd_getl32 (eicp->newprt));
8698
4.85k
        switch (prot)
8699
4.85k
    {
8700
1.42k
    case PRT__C_NA:
8701
1.42k
      fprintf (file, "NA");
8702
1.42k
      break;
8703
76
    case PRT__C_RESERVED:
8704
76
      fprintf (file, "RES");
8705
76
      break;
8706
42
    case PRT__C_KW:
8707
42
      fprintf (file, "KW");
8708
42
      break;
8709
15
    case PRT__C_KR:
8710
15
      fprintf (file, "KR");
8711
15
      break;
8712
49
    case PRT__C_UW:
8713
49
      fprintf (file, "UW");
8714
49
      break;
8715
14
    case PRT__C_EW:
8716
14
      fprintf (file, "EW");
8717
14
      break;
8718
4
    case PRT__C_ERKW:
8719
4
      fprintf (file, "ERKW");
8720
4
      break;
8721
10
    case PRT__C_ER:
8722
10
      fprintf (file, "ER");
8723
10
      break;
8724
20
    case PRT__C_SW:
8725
20
      fprintf (file, "SW");
8726
20
      break;
8727
8
    case PRT__C_SREW:
8728
8
      fprintf (file, "SREW");
8729
8
      break;
8730
31
    case PRT__C_SRKW:
8731
31
      fprintf (file, "SRKW");
8732
31
      break;
8733
34
    case PRT__C_SR:
8734
34
      fprintf (file, "SR");
8735
34
      break;
8736
7
    case PRT__C_URSW:
8737
7
      fprintf (file, "URSW");
8738
7
      break;
8739
36
    case PRT__C_UREW:
8740
36
      fprintf (file, "UREW");
8741
36
      break;
8742
7
    case PRT__C_URKW:
8743
7
      fprintf (file, "URKW");
8744
7
      break;
8745
24
    case PRT__C_UR:
8746
24
      fprintf (file, "UR");
8747
24
      break;
8748
3.05k
    default:
8749
3.05k
      fputs ("??", file);
8750
3.05k
      break;
8751
4.85k
    }
8752
4.85k
        fputc ('\n', file);
8753
4.85k
      }
8754
95
  }
8755
147
      free (buf);
8756
147
    }
8757
260
}
8758
8759
static bool
8760
vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
8761
331
{
8762
331
  FILE *file = (FILE *)ptr;
8763
8764
331
  if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
8765
323
    evax_bfd_print_image (abfd, file);
8766
8
  else
8767
8
    {
8768
8
      if (bfd_seek (abfd, 0, SEEK_SET))
8769
0
  return false;
8770
8
      evax_bfd_print_eobj (abfd, file);
8771
8
    }
8772
331
  return true;
8773
331
}
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
79
{
8782
79
  asection *cur_section;
8783
79
  file_ptr cur_offset;
8784
79
  asection *dst_section;
8785
79
  file_ptr dst_offset;
8786
8787
79
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
8788
0
    return false;
8789
8790
79
  cur_section = NULL;
8791
79
  cur_offset = 0;
8792
8793
79
  dst_section = PRIV (dst_section);
8794
79
  dst_offset = 0;
8795
79
  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
81
  while (1)
8811
81
    {
8812
81
      int type;
8813
81
      bool res;
8814
8815
81
      type = _bfd_vms_get_object_record (abfd);
8816
81
      if (type < 0)
8817
78
  {
8818
78
    vms_debug2 ((2, "next_record failed\n"));
8819
78
    return false;
8820
78
  }
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
79
}
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
1.08k
{
9860
  /* Handle image sections.  */
9861
1.08k
  if (section->filepos != 0
9862
1.08k
      || (section->flags & SEC_HAS_CONTENTS) == 0)
9863
1.00k
    return _bfd_generic_get_section_contents (abfd, section,
9864
1.00k
                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
79
  if (offset + count < count
9872
79
      || offset + count > section->size)
9873
0
    {
9874
0
      bfd_set_error (bfd_error_invalid_operation);
9875
0
      return false;
9876
0
    }
9877
9878
79
  if (section->size == 0)
9879
0
    return true;
9880
9881
  /* If we haven't yet read ETIR/EDBG/ETBT records, do so.  */
9882
79
  if ((section->flags & SEC_IN_MEMORY) == 0)
9883
79
    {
9884
      /* Alloc memory and read ETIRs.  */
9885
212
      for (asection *sec = abfd->sections; sec; sec = sec->next)
9886
133
  {
9887
133
    if (sec->size != 0
9888
133
        && sec->filepos == 0
9889
133
        && (sec->flags & SEC_HAS_CONTENTS) != 0)
9890
80
      {
9891
80
        BFD_ASSERT (sec->contents == NULL);
9892
9893
80
        sec->contents = bfd_zalloc (abfd, sec->size);
9894
80
        sec->flags |= SEC_IN_MEMORY;
9895
80
        if (sec->contents == NULL)
9896
0
    return false;
9897
80
        sec->alloced = 1;
9898
80
      }
9899
133
  }
9900
79
      if (!alpha_vms_read_sections_content (abfd, NULL))
9901
78
  return false;
9902
79
    }
9903
9904
1
  BFD_ASSERT (section->contents != NULL);
9905
1
  memcpy (buf, section->contents + offset, count);
9906
1
  return true;
9907
79
}
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
15.5k
{
9946
15.5k
  vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
9947
9948
15.5k
  if (abfd == NULL || abfd->tdata.any == NULL)
9949
0
    return true;
9950
9951
15.5k
  if (abfd->format == bfd_object)
9952
15.5k
    {
9953
15.5k
      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
15.5k
    }
9967
9968
15.5k
  return _bfd_generic_close_and_cleanup (abfd);
9969
15.5k
}
9970
9971
/* Called when a new section is created.  */
9972
9973
static bool
9974
vms_new_section_hook (bfd * abfd, asection *section)
9975
95.2k
{
9976
95.2k
  size_t amt;
9977
9978
95.2k
  vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n",
9979
95.2k
         abfd, section->index, section->name));
9980
9981
95.2k
  if (!bfd_set_section_alignment (section, 0))
9982
0
    return false;
9983
9984
95.2k
  vms_debug2 ((7, "%u: %s\n", section->index, section->name));
9985
9986
95.2k
  amt = sizeof (struct vms_section_data_struct);
9987
95.2k
  section->used_by_bfd = bfd_zalloc (abfd, amt);
9988
95.2k
  if (section->used_by_bfd == NULL)
9989
0
    return false;
9990
9991
  /* Create the section symbol.  */
9992
95.2k
  return _bfd_generic_new_section_hook (abfd, section);
9993
95.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
};