Coverage Report

Created: 2026-07-12 09:22

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