Coverage Report

Created: 2023-06-29 07:13

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