Coverage Report

Created: 2023-08-28 06:31

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