Coverage Report

Created: 2026-07-25 10:20

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
15
#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
386
#define DBG_S_L_DMT_MODBEG   0
126
386
#define DBG_S_L_DST_SIZE   4
127
386
#define DBG_S_W_DMT_PSECT_COUNT  8
128
840
#define DBG_S_C_DMT_HEADER_SIZE 12
129
130
666
#define DBG_S_L_DMT_PSECT_START  0
131
666
#define DBG_S_L_DMT_PSECT_LENGTH 4
132
1.38k
#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
2
#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
180k
#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.80M
  (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
342
3.80M
#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
180
  ((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
835
{
470
835
  unsigned int imgtype;
471
835
  bfd_vma symvva;
472
835
  struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
473
474
835
  vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
475
476
835
  imgtype = bfd_getl32 (eihd->imgtype);
477
478
835
  if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
479
17
    abfd->flags |= EXEC_P;
480
481
835
  symvva = bfd_getl64 (eihd->symvva);
482
835
  if (symvva != 0)
483
777
    {
484
777
      PRIV (symvva) = symvva;
485
777
      abfd->flags |= DYNAMIC;
486
777
    }
487
488
835
  PRIV (ident) = bfd_getl32 (eihd->ident);
489
835
  PRIV (matchctl) = eihd->matchctl;
490
491
835
  *eisd_offset = bfd_getl32 (eihd->isdoff);
492
835
  *eihs_offset = bfd_getl32 (eihd->symdbgoff);
493
494
835
  vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
495
835
         PRIV (recrd.rec_size), imgtype, (unsigned long) symvva,
496
835
         *eisd_offset, *eihs_offset));
497
835
  return true;
498
835
}
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
835
{
506
835
  int section_count = 0;
507
508
835
  vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
509
510
1.46k
  while (1)
511
1.46k
    {
512
1.46k
      struct vms_eisd *eisd;
513
1.46k
      unsigned int rec_size;
514
1.46k
      unsigned int size;
515
1.46k
      uint64_t vaddr;
516
1.46k
      unsigned int flags;
517
1.46k
      unsigned int vbn;
518
1.46k
      char *name = NULL;
519
1.46k
      asection *section;
520
1.46k
      flagword bfd_flags;
521
522
      /* PR 17512: file: 3d9e9fe9.  */
523
1.46k
      if (offset > PRIV (recrd.rec_size)
524
1.34k
    || (PRIV (recrd.rec_size) - offset
525
1.34k
        < offsetof (struct vms_eisd, eisdsize) + 4))
526
178
  return false;
527
1.28k
      eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset);
528
1.28k
      rec_size = bfd_getl32 (eisd->eisdsize);
529
1.28k
      if (rec_size == 0)
530
414
  break;
531
532
      /* Skip to next block if pad.  */
533
875
      if (rec_size == 0xffffffff)
534
101
  {
535
101
    offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
536
101
    continue;
537
101
  }
538
539
      /* Make sure that there is enough data present in the record.  */
540
774
      if (rec_size < offsetof (struct vms_eisd, type) + 1)
541
8
  return false;
542
      /* Make sure that the record is not too big either.  */
543
766
      if (rec_size > PRIV (recrd.rec_size) - offset)
544
192
  return false;
545
546
574
      offset += rec_size;
547
548
574
      size = bfd_getl32 (eisd->secsize);
549
574
      vaddr = bfd_getl64 (eisd->virt_addr);
550
574
      flags = bfd_getl32 (eisd->flags);
551
574
      vbn = bfd_getl32 (eisd->vbn);
552
553
574
      vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n",
554
574
       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
574
      bfd_flags = SEC_ALLOC;
561
574
      if (vbn != 0)
562
458
  bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD;
563
564
574
      if (flags & EISD__M_EXE)
565
179
  bfd_flags |= SEC_CODE;
566
567
574
      if (flags & EISD__M_NONSHRADR)
568
156
  bfd_flags |= SEC_DATA;
569
570
574
      if (!(flags & EISD__M_WRT))
571
394
  bfd_flags |= SEC_READONLY;
572
573
574
      if (flags & EISD__M_DZRO)
574
150
  bfd_flags |= SEC_DATA;
575
576
574
      if (flags & EISD__M_FIXUPVEC)
577
228
  bfd_flags |= SEC_DATA;
578
579
574
      if (flags & EISD__M_CRF)
580
168
  bfd_flags |= SEC_DATA;
581
582
574
      if (flags & EISD__M_GBL)
583
125
  {
584
125
    if (rec_size <= offsetof (struct vms_eisd, gblnam))
585
3
      return false;
586
122
    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
91
    else
590
91
      name = _bfd_vms_save_counted_string (abfd, eisd->gblnam,
591
91
             EISD__K_GBLNAMLEN);
592
122
    if (name == NULL || name[0] == 0)
593
29
      return false;
594
93
    bfd_flags |= SEC_COFF_SHARED_LIBRARY;
595
93
    bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
596
93
  }
597
449
      else if (flags & EISD__M_FIXUPVEC)
598
117
  name = "$FIXUPVEC$";
599
332
      else if (eisd->type == EISD__K_USRSTACK)
600
5
  name = "$STACK$";
601
327
      else
602
327
  {
603
327
    const char *pfx;
604
605
327
    name = (char *) bfd_alloc (abfd, 32);
606
327
    if (name == NULL)
607
0
      return false;
608
327
    if (flags & EISD__M_DZRO)
609
25
      pfx = "BSS";
610
302
    else if (flags & EISD__M_EXE)
611
89
      pfx = "CODE";
612
213
    else if (!(flags & EISD__M_WRT))
613
186
      pfx = "RO";
614
27
    else
615
27
      pfx = "LOCAL";
616
327
    BFD_ASSERT (section_count < 999);
617
327
    sprintf (name, "$%s_%03d$", pfx, section_count++);
618
327
  }
619
620
542
      section = bfd_make_section (abfd, name);
621
622
542
      if (!section)
623
11
  return false;
624
625
531
      section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
626
531
      section->size = size;
627
531
      section->vma = vaddr;
628
629
531
      if (!bfd_set_section_flags (section, bfd_flags))
630
0
  return false;
631
531
    }
632
633
414
  return true;
634
835
}
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
285
{
642
285
  unsigned char *p = PRIV (recrd.rec) + offset;
643
285
  unsigned int gstvbn;
644
285
  unsigned int gstsize ATTRIBUTE_UNUSED;
645
285
  unsigned int dstvbn;
646
285
  unsigned int dstsize;
647
285
  unsigned int dmtvbn;
648
285
  unsigned int dmtbytes;
649
285
  asection *section;
650
651
  /* PR 21611: Check that offset is valid.  */
652
285
  if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4))
653
67
    {
654
67
      _bfd_error_handler (_("unable to read EIHS record at offset %#x"),
655
67
        offset);
656
67
      bfd_set_error (bfd_error_file_truncated);
657
67
      return false;
658
67
    }
659
660
218
  gstvbn   = bfd_getl32 (p + EIHS__L_GSTVBN);
661
218
  gstsize  = bfd_getl32 (p + EIHS__L_GSTSIZE);
662
218
  dstvbn   = bfd_getl32 (p + EIHS__L_DSTVBN);
663
218
  dstsize  = bfd_getl32 (p + EIHS__L_DSTSIZE);
664
218
  dmtvbn   = bfd_getl32 (p + EIHS__L_DMTVBN);
665
218
  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
218
  if (dstvbn)
674
196
    {
675
196
      flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
676
677
196
      section = bfd_make_section (abfd, "$DST$");
678
196
      if (!section)
679
0
  return false;
680
681
196
      section->size = dstsize;
682
196
      section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
683
684
196
      if (!bfd_set_section_flags (section, bfd_flags))
685
0
  return false;
686
687
196
      PRIV (dst_section) = section;
688
196
      abfd->flags |= (HAS_DEBUG | HAS_LINENO);
689
196
    }
690
691
218
  if (dmtvbn)
692
139
    {
693
139
      flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
694
695
139
      section = bfd_make_section (abfd, "$DMT$");
696
139
      if (!section)
697
0
  return false;
698
699
139
      section->size = dmtbytes;
700
139
      section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
701
702
139
      if (!bfd_set_section_flags (section, bfd_flags))
703
0
  return false;
704
139
    }
705
706
218
  if (gstvbn)
707
59
    {
708
59
      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
59
      if (!_bfd_vms_slurp_object_records (abfd))
715
58
  return false;
716
717
1
      abfd->flags |= HAS_SYMS;
718
1
    }
719
720
160
  return true;
721
218
}
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
19.0k
#define VMS_OBJECT_ADJUSTMENT  2
761
762
static void
763
maybe_adjust_record_pointer_for_object (bfd *abfd)
764
219k
{
765
  /* Set the file format once for all on the first invocation.  */
766
219k
  if (PRIV (recrd.file_format) == FF_UNKNOWN)
767
157k
    {
768
157k
      if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4]
769
11.1k
    && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5])
770
3.58k
  PRIV (recrd.file_format) = FF_FOREIGN;
771
154k
      else
772
154k
  PRIV (recrd.file_format) = FF_NATIVE;
773
157k
    }
774
775
  /* The adjustment is needed only in an Unix environment.  */
776
219k
  if (PRIV (recrd.file_format) == FF_FOREIGN)
777
13.6k
    PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT;
778
219k
}
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
30.6k
{
786
30.6k
  unsigned int test_len = 6;
787
30.6k
  int type;
788
789
30.6k
  vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
790
791
  /* Skip alignment byte if the current position is odd.  */
792
30.6k
  if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1))
793
3.22k
    {
794
3.22k
      if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1)
795
13
  {
796
13
    bfd_set_error (bfd_error_file_truncated);
797
13
    return -1;
798
13
  }
799
3.22k
    }
800
801
  /* Read the record header  */
802
30.6k
  if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len)
803
365
    {
804
365
      bfd_set_error (bfd_error_file_truncated);
805
365
      return -1;
806
365
    }
807
808
  /* Reset the record pointer.  */
809
30.3k
  PRIV (recrd.rec) = PRIV (recrd.buf);
810
30.3k
  maybe_adjust_record_pointer_for_object (abfd);
811
812
30.3k
  if (vms_get_remaining_object_record (abfd, test_len) <= 0)
813
558
    return -1;
814
815
29.7k
  type = bfd_getl16 (PRIV (recrd.rec));
816
817
29.7k
  vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n",
818
29.7k
         PRIV (recrd.rec), PRIV (recrd.rec_size), type));
819
820
29.7k
  return type;
821
30.3k
}
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
33.8k
{
829
33.8k
  unsigned int to_read;
830
831
33.8k
  vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
832
833
  /* Extract record size.  */
834
33.8k
  PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
835
836
33.8k
  if (PRIV (recrd.rec_size) == 0)
837
913
    {
838
913
      bfd_set_error (bfd_error_file_truncated);
839
913
      return 0;
840
913
    }
841
842
  /* That's what the linker manual says.  */
843
32.9k
  if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
844
112
    {
845
112
      bfd_set_error (bfd_error_file_truncated);
846
112
      return 0;
847
112
    }
848
849
  /* Take into account object adjustment.  */
850
32.8k
  to_read = PRIV (recrd.rec_size);
851
32.8k
  if (PRIV (recrd.file_format) == FF_FOREIGN)
852
5.36k
    to_read += VMS_OBJECT_ADJUSTMENT;
853
854
  /* Adjust the buffer.  */
855
32.8k
  if (to_read > PRIV (recrd.buf_size))
856
3.37k
    {
857
3.37k
      PRIV (recrd.buf)
858
3.37k
  = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read);
859
3.37k
      if (PRIV (recrd.buf) == NULL)
860
0
  return 0;
861
3.37k
      PRIV (recrd.buf_size) = to_read;
862
3.37k
    }
863
  /* PR 17512: file: 025-1974-0.004.  */
864
29.4k
  else if (to_read <= read_so_far)
865
55
    return 0;
866
867
  /* Read the remaining record.  */
868
32.7k
  to_read -= read_so_far;
869
870
32.7k
  vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
871
872
32.7k
  if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
873
1.36k
    {
874
1.36k
      bfd_set_error (bfd_error_file_truncated);
875
1.36k
      return 0;
876
1.36k
    }
877
878
  /* Reset the record pointer.  */
879
31.3k
  PRIV (recrd.rec) = PRIV (recrd.buf);
880
31.3k
  maybe_adjust_record_pointer_for_object (abfd);
881
882
31.3k
  vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
883
31.3k
         PRIV (recrd.rec_size)));
884
885
31.3k
  return PRIV (recrd.rec_size);
886
32.7k
}
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
3
    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
100
    case EMH__C_MHD:
914
      /* Module header.  */
915
100
      if (len < 15)
916
13
  goto fail;
917
87
      PRIV (hdr_data).hdr_b_strlvl = *ptr;
918
87
      PRIV (hdr_data).hdr_l_arch1  = bfd_getl32 (ptr + 2);
919
87
      PRIV (hdr_data).hdr_l_arch2  = bfd_getl32 (ptr + 6);
920
87
      PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (ptr + 10);
921
87
      ptr += 14;
922
87
      len -= 14;
923
87
      PRIV (hdr_data).hdr_t_name
924
87
  = _bfd_vms_save_counted_string (abfd, ptr, len);
925
87
      slen = *ptr + 1;
926
87
      if (len <= slen)
927
9
  goto fail;
928
78
      ptr += slen;
929
78
      len -= slen;
930
78
      PRIV (hdr_data).hdr_t_version
931
78
  = _bfd_vms_save_counted_string (abfd, ptr, len);
932
78
      slen = *ptr + 1;
933
78
      if (len < slen + 17)
934
16
  goto fail;
935
62
      ptr += slen;
936
62
      PRIV (hdr_data).hdr_t_date
937
62
  = _bfd_vms_save_sized_string (abfd, ptr, 17);
938
62
      break;
939
940
581
    case EMH__C_LNM:
941
581
      PRIV (hdr_data).hdr_c_lnm
942
581
  = _bfd_vms_save_sized_string (abfd, ptr, len);
943
581
      break;
944
945
212
    case EMH__C_SRC:
946
212
      PRIV (hdr_data).hdr_c_src
947
212
  = _bfd_vms_save_sized_string (abfd, ptr, len);
948
212
      break;
949
950
1.22k
    case EMH__C_TTL:
951
1.22k
      PRIV (hdr_data).hdr_c_ttl
952
1.22k
  = _bfd_vms_save_sized_string (abfd, ptr, len);
953
1.22k
      break;
954
955
346
    case EMH__C_CPR:
956
1.17k
    case EMH__C_MTC:
957
1.43k
    case EMH__C_GTX:
958
1.43k
      break;
959
960
25
    default:
961
66
    fail:
962
66
      bfd_set_error (bfd_error_wrong_format);
963
66
      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
86
{
1060
86
  int i = 0;
1061
1062
889
  while (section_flags[i].name != NULL)
1063
810
    {
1064
810
      if (strcmp (name, section_flags[i].name) == 0)
1065
7
  {
1066
7
    if (hassize)
1067
5
      return section_flags[i].flags_hassize;
1068
2
    else
1069
2
      return section_flags[i].flags_always;
1070
7
  }
1071
803
      i++;
1072
803
    }
1073
79
  if (hassize)
1074
74
    return section_flags[i].flags_hassize;
1075
5
  return section_flags[i].flags_always;
1076
79
}
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
1
{
1085
1
  int i = 0;
1086
1087
11
  while (section_flags[i].name != NULL)
1088
10
    {
1089
10
      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
10
      i++;
1097
10
    }
1098
1
  if (hassize)
1099
0
    return section_flags[i].vflags_hassize;
1100
1
  return section_flags[i].vflags_always;
1101
1
}
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
551
{
1109
551
  if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
1110
116
    {
1111
116
      if (PRIV (max_sym_count) == 0)
1112
116
  {
1113
116
    PRIV (max_sym_count) = 128;
1114
116
    PRIV (syms) = bfd_malloc
1115
116
      (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
1116
116
  }
1117
0
      else
1118
0
  {
1119
0
    PRIV (max_sym_count) *= 2;
1120
0
    PRIV (syms) = bfd_realloc_or_free
1121
0
      (PRIV (syms),
1122
0
       (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
1123
0
  }
1124
116
      if (PRIV (syms) == NULL)
1125
0
  return false;
1126
116
    }
1127
1128
551
  PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
1129
551
  return true;
1130
551
}
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
560
{
1138
560
  struct vms_symbol_entry *entry;
1139
560
  unsigned int len;
1140
1141
560
  len = *ascic++;
1142
560
  max -= 1;
1143
560
  if (len > max)
1144
9
    {
1145
9
      _bfd_error_handler (_("record is too small for symbol name length"));
1146
9
      bfd_set_error (bfd_error_bad_value);
1147
9
      return NULL;
1148
9
    }
1149
1150
551
  entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
1151
551
  if (entry == NULL)
1152
0
    return NULL;
1153
551
  entry->namelen = len;
1154
551
  memcpy (entry->name, ascic, len);
1155
551
  entry->name[len] = 0;
1156
551
  entry->owner = abfd;
1157
1158
551
  if (!add_symbol_entry (abfd, entry))
1159
0
    return NULL;
1160
551
  return entry;
1161
551
}
1162
1163
/* Read and process EGSD.  Return FALSE on failure.  */
1164
1165
static bool
1166
_bfd_vms_slurp_egsd (bfd *abfd)
1167
1.55k
{
1168
1.55k
  int gsd_type;
1169
1.55k
  unsigned int gsd_size;
1170
1.55k
  unsigned char *vms_rec;
1171
1.55k
  bfd_vma base_addr;
1172
1.55k
  long psindx;
1173
1174
1.55k
  vms_debug2 ((2, "EGSD\n"));
1175
1176
1.55k
  if (PRIV (recrd.rec_size) < 8)
1177
4
    {
1178
4
      _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"),
1179
4
        PRIV (recrd.rec_size));
1180
4
      bfd_set_error (bfd_error_bad_value);
1181
4
      return false;
1182
4
    }
1183
1184
1.55k
  PRIV (recrd.rec) += 8;  /* Skip type, size, align pad.  */
1185
1.55k
  PRIV (recrd.rec_size) -= 8;
1186
1187
  /* Calculate base address for each section.  */
1188
1.55k
  base_addr = 0;
1189
1190
3.09k
  while (PRIV (recrd.rec_size) > 4)
1191
1.68k
    {
1192
1.68k
      vms_rec = PRIV (recrd.rec);
1193
1194
1.68k
      gsd_type = bfd_getl16 (vms_rec);
1195
1.68k
      gsd_size = bfd_getl16 (vms_rec + 2);
1196
1197
1.68k
      vms_debug2 ((3, "egsd_type %d\n", gsd_type));
1198
1199
      /* PR 21615: Check for size overflow.  */
1200
1.68k
      if (PRIV (recrd.rec_size) < gsd_size)
1201
43
  {
1202
43
    _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
1203
43
        "is larger than remaining space (%#x)"),
1204
43
            gsd_type, gsd_size, PRIV (recrd.rec_size));
1205
43
    bfd_set_error (bfd_error_bad_value);
1206
43
    return false;
1207
43
  }
1208
1209
1.64k
      if (gsd_size < 4)
1210
21
  {
1211
38
  too_small:
1212
38
    _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) "
1213
38
        "is too small"),
1214
38
            gsd_type, gsd_size);
1215
38
    bfd_set_error (bfd_error_bad_value);
1216
38
    return false;
1217
21
  }
1218
1219
1.62k
      switch (gsd_type)
1220
1.62k
  {
1221
908
  case EGSD__C_PSC:
1222
    /* Program section definition.  */
1223
908
    {
1224
908
      struct vms_egps *egps = (struct vms_egps *) vms_rec;
1225
908
      flagword new_flags, vms_flags;
1226
908
      asection *section;
1227
1228
908
      if (offsetof (struct vms_egps, flags) + 2 > gsd_size)
1229
4
        goto too_small;
1230
904
      vms_flags = bfd_getl16 (egps->flags);
1231
1232
904
      if ((vms_flags & EGPS__V_REL) == 0)
1233
799
        {
1234
    /* Use the global absolute section for all
1235
       absolute sections.  */
1236
799
    section = bfd_abs_section_ptr;
1237
799
        }
1238
105
      else
1239
105
        {
1240
105
    char *name;
1241
105
    bfd_vma align_addr;
1242
105
    size_t left;
1243
1244
105
    if (offsetof (struct vms_egps, namlng) >= gsd_size)
1245
3
      goto too_small;
1246
102
    left = gsd_size - offsetof (struct vms_egps, namlng);
1247
102
    name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left);
1248
102
    if (name == NULL || name[0] == 0)
1249
7
      return false;
1250
1251
95
    section = bfd_make_section (abfd, name);
1252
95
    if (!section)
1253
9
      return false;
1254
1255
86
    section->filepos = 0;
1256
86
    section->size = bfd_getl32 (egps->alloc);
1257
86
    section->alignment_power = egps->align & 31;
1258
1259
86
    vms_section_data (section)->flags = vms_flags;
1260
86
    vms_section_data (section)->no_flags = 0;
1261
1262
86
    new_flags = vms_secflag_by_name (evax_section_flags,
1263
86
             section->name,
1264
86
             section->size > 0);
1265
86
    if (section->size > 0)
1266
79
      new_flags |= SEC_LOAD;
1267
86
    if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0)
1268
40
      {
1269
        /* Set RELOC and HAS_CONTENTS if the section is not
1270
           demand-zero and not empty.  */
1271
40
        new_flags |= SEC_HAS_CONTENTS;
1272
40
        if (vms_flags & EGPS__V_REL)
1273
40
          new_flags |= SEC_RELOC;
1274
40
      }
1275
86
    if (vms_flags & EGPS__V_EXE)
1276
19
      {
1277
        /* Set CODE if section is executable.  */
1278
19
        new_flags |= SEC_CODE;
1279
19
        new_flags &= ~SEC_DATA;
1280
19
      }
1281
86
    if (!bfd_set_section_flags (section, new_flags))
1282
0
      return false;
1283
1284
    /* Give a non-overlapping vma to non absolute sections.  */
1285
86
    align_addr = (bfd_vma) 1 << section->alignment_power;
1286
86
    base_addr = (base_addr + align_addr - 1) & -align_addr;
1287
86
    section->vma = base_addr;
1288
86
    base_addr += section->size;
1289
86
        }
1290
1291
      /* Append it to the section array.  */
1292
885
      if (PRIV (section_count) >= PRIV (section_max))
1293
163
        {
1294
163
    if (PRIV (section_max) == 0)
1295
139
      PRIV (section_max) = 16;
1296
24
    else
1297
24
      PRIV (section_max) *= 2;
1298
163
    PRIV (sections) = bfd_realloc_or_free
1299
163
      (PRIV (sections), PRIV (section_max) * sizeof (asection *));
1300
163
    if (PRIV (sections) == NULL)
1301
0
      return false;
1302
163
        }
1303
1304
885
      PRIV (sections)[PRIV (section_count)] = section;
1305
885
      PRIV (section_count)++;
1306
885
    }
1307
0
    break;
1308
1309
471
  case EGSD__C_SYM:
1310
471
    {
1311
471
      unsigned int nameoff;
1312
471
      struct vms_symbol_entry *entry;
1313
471
      struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
1314
471
      flagword old_flags;
1315
1316
471
      if (offsetof (struct vms_egsy, flags) + 2 > gsd_size)
1317
3
        goto too_small;
1318
468
      old_flags = bfd_getl16 (egsy->flags);
1319
468
      if (old_flags & EGSY__V_DEF)
1320
39
        nameoff = ESDF__B_NAMLNG;
1321
429
      else
1322
429
        nameoff = ESRF__B_NAMLNG;
1323
1324
468
      if (nameoff >= gsd_size)
1325
3
        goto too_small;
1326
465
      entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff);
1327
465
      if (entry == NULL)
1328
5
        return false;
1329
1330
      /* Allow only duplicate reference.  */
1331
460
      if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
1332
0
        abort ();
1333
1334
460
      if (entry->typ == 0)
1335
460
        {
1336
460
    entry->typ = gsd_type;
1337
460
    entry->data_type = egsy->datyp;
1338
460
    entry->flags = old_flags;
1339
460
        }
1340
1341
460
      if (old_flags & EGSY__V_DEF)
1342
36
        {
1343
36
    struct vms_esdf *esdf = (struct vms_esdf *) vms_rec;
1344
1345
36
    entry->value = bfd_getl64 (esdf->value);
1346
36
    if (PRIV (sections) == NULL)
1347
3
      return false;
1348
1349
33
    psindx = bfd_getl32 (esdf->psindx);
1350
    /* PR 21813: Check for an out of range index.  */
1351
33
    if (psindx < 0 || psindx >= (int) PRIV (section_count))
1352
11
      {
1353
21
      bad_psindx:
1354
21
        _bfd_error_handler (_("corrupt EGSD record: its psindx "
1355
21
            "field is too big (%#lx)"),
1356
21
          psindx);
1357
21
        bfd_set_error (bfd_error_bad_value);
1358
21
        return false;
1359
11
      }
1360
22
    entry->section = PRIV (sections)[psindx];
1361
1362
22
    if (old_flags & EGSY__V_NORM)
1363
13
      {
1364
13
        PRIV (norm_sym_count)++;
1365
1366
13
        entry->code_value = bfd_getl64 (esdf->code_address);
1367
13
        psindx = bfd_getl32 (esdf->ca_psindx);
1368
        /* PR 21813: Check for an out of range index.  */
1369
13
        if (psindx < 0 || psindx >= (int) PRIV (section_count))
1370
6
          goto bad_psindx;
1371
7
        entry->code_section = PRIV (sections)[psindx];
1372
7
      }
1373
22
        }
1374
460
    }
1375
440
    break;
1376
1377
440
  case EGSD__C_SYMG:
1378
99
    {
1379
99
      struct vms_symbol_entry *entry;
1380
99
      struct vms_egst *egst = (struct vms_egst *)vms_rec;
1381
99
      flagword old_flags;
1382
99
      unsigned int nameoff = offsetof (struct vms_egst, namlng);
1383
1384
99
      if (nameoff >= gsd_size)
1385
4
        goto too_small;
1386
95
      entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff);
1387
95
      if (entry == NULL)
1388
4
        return false;
1389
1390
91
      old_flags = bfd_getl16 (egst->header.flags);
1391
91
      entry->typ = gsd_type;
1392
91
      entry->data_type = egst->header.datyp;
1393
91
      entry->flags = old_flags;
1394
1395
91
      entry->symbol_vector = bfd_getl32 (egst->value);
1396
1397
91
      if (old_flags & EGSY__V_REL)
1398
23
        {
1399
23
    if (PRIV (sections) == NULL)
1400
3
      return false;
1401
20
    psindx = bfd_getl32 (egst->psindx);
1402
    /* PR 21813: Check for an out of range index.  */
1403
20
    if (psindx < 0 || psindx >= (int) PRIV (section_count))
1404
4
      goto bad_psindx;
1405
16
    entry->section = PRIV (sections)[psindx];
1406
16
        }
1407
68
      else
1408
68
        entry->section = bfd_abs_section_ptr;
1409
1410
84
      entry->value = bfd_getl64 (egst->lp_2);
1411
1412
84
      if (old_flags & EGSY__V_NORM)
1413
56
        {
1414
56
    PRIV (norm_sym_count)++;
1415
1416
56
    entry->code_value = bfd_getl64 (egst->lp_1);
1417
56
    entry->code_section = bfd_abs_section_ptr;
1418
56
        }
1419
84
    }
1420
0
    break;
1421
1422
68
  case EGSD__C_SPSC:
1423
133
  case EGSD__C_IDC:
1424
    /* Currently ignored.  */
1425
133
    break;
1426
0
  case EGSD__C_SYMM:
1427
0
  case EGSD__C_SYMV:
1428
9
  default:
1429
9
    _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type);
1430
9
    bfd_set_error (bfd_error_bad_value);
1431
9
    return false;
1432
1.62k
  }
1433
1434
1.54k
      PRIV (recrd.rec_size) -= gsd_size;
1435
1.54k
      PRIV (recrd.rec) += gsd_size;
1436
1.54k
    }
1437
1438
  /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ?  */
1439
1440
1.40k
  if (PRIV (gsd_sym_count) > 0)
1441
463
    abfd->flags |= HAS_SYMS;
1442
1443
1.40k
  return true;
1444
1.55k
}
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
19.7k
{
1453
19.7k
  vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
1454
19.7k
         (unsigned long)val, reloc, PRIV (stackptr)));
1455
1456
19.7k
  PRIV (stack[PRIV (stackptr)]).value = val;
1457
19.7k
  PRIV (stack[PRIV (stackptr)]).reloc = reloc;
1458
19.7k
  PRIV (stackptr)++;
1459
19.7k
  if (PRIV (stackptr) >= STACKSIZE)
1460
4
    {
1461
4
      bfd_set_error (bfd_error_bad_value);
1462
4
      _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
1463
4
      return false;
1464
4
    }
1465
19.7k
  return true;
1466
19.7k
}
1467
1468
/* Pop value and section index.  */
1469
1470
static bool
1471
_bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
1472
15.3k
{
1473
15.3k
  if (PRIV (stackptr) == 0)
1474
113
    {
1475
113
      bfd_set_error (bfd_error_bad_value);
1476
113
      _bfd_error_handler (_("stack underflow in _bfd_vms_pop"));
1477
113
      return false;
1478
113
    }
1479
15.2k
  PRIV (stackptr)--;
1480
15.2k
  *val = PRIV (stack[PRIV (stackptr)]).value;
1481
15.2k
  *rel = PRIV (stack[PRIV (stackptr)]).reloc;
1482
1483
15.2k
  vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
1484
15.2k
  return true;
1485
15.3k
}
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
106
{
1534
106
  vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
1535
1536
106
  PRIV (image_offset) += offset;
1537
106
}
1538
1539
/* Save current DST location counter under specified index.  */
1540
1541
static bool
1542
dst_define_location (bfd *abfd, unsigned int loc)
1543
888
{
1544
888
  vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
1545
1546
888
  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
885
  if (loc + 1 > PRIV (dst_ptr_offsets_count))
1556
86
    {
1557
86
      PRIV (dst_ptr_offsets)
1558
86
  = bfd_realloc_or_free (PRIV (dst_ptr_offsets),
1559
86
             (loc + 1) * sizeof (unsigned int));
1560
86
      if (PRIV (dst_ptr_offsets) == NULL)
1561
0
  return false;
1562
86
      memset (PRIV (dst_ptr_offsets) + PRIV (dst_ptr_offsets_count), 0,
1563
86
        (loc - PRIV (dst_ptr_offsets_count)) * sizeof (unsigned int));
1564
86
      PRIV (dst_ptr_offsets_count) = loc + 1;
1565
86
    }
1566
1567
885
  PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
1568
885
  return true;
1569
885
}
1570
1571
/* Restore saved DST location counter from specified index.  */
1572
1573
static bool
1574
dst_restore_location (bfd *abfd, unsigned int loc)
1575
261
{
1576
261
  vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
1577
1578
261
  if (loc < PRIV (dst_ptr_offsets_count))
1579
258
    {
1580
258
      PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
1581
258
      return true;
1582
258
    }
1583
3
  return false;
1584
261
}
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.68k
{
1604
1.68k
  asection *sec = PRIV (image_section);
1605
1606
1.68k
  if (sec == NULL
1607
1.68k
      || ((sec->flags & SEC_IN_MEMORY) != 0 && sec->contents == NULL))
1608
1.68k
    return NULL;
1609
0
  return sec;
1610
1.68k
}
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.55k
{
1617
1.55k
  asection *sec = image_write_section (abfd);
1618
1619
1.55k
  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.55k
  PRIV (image_offset) += size;
1653
1.55k
  return true;
1654
1.55k
}
1655
1656
/* Write byte to section image.  */
1657
1658
static bool
1659
image_write_b (bfd * abfd, unsigned int value)
1660
89
{
1661
89
  unsigned char data[1];
1662
1663
89
  vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
1664
1665
89
  *data = value;
1666
1667
89
  return image_write (abfd, data, sizeof (data));
1668
89
}
1669
1670
/* Write 2-byte word to image.  */
1671
1672
static bool
1673
image_write_w (bfd * abfd, unsigned int value)
1674
111
{
1675
111
  unsigned char data[2];
1676
1677
111
  vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
1678
1679
111
  bfd_putl16 (value, data);
1680
111
  return image_write (abfd, data, sizeof (data));
1681
111
}
1682
1683
/* Write 4-byte long to image.  */
1684
1685
static bool
1686
image_write_l (bfd * abfd, unsigned long value)
1687
245
{
1688
245
  unsigned char data[4];
1689
1690
245
  vms_debug2 ((6, "image_write_l (%08lx)\n", value));
1691
1692
245
  bfd_putl32 (value, data);
1693
245
  return image_write (abfd, data, sizeof (data));
1694
245
}
1695
1696
/* Write 8-byte quad to image.  */
1697
1698
static bool
1699
image_write_q (bfd * abfd, bfd_vma value)
1700
739
{
1701
739
  unsigned char data[8];
1702
1703
739
  vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
1704
1705
739
  bfd_putl64 (value, data);
1706
739
  return image_write (abfd, data, sizeof (data));
1707
739
}
1708

1709
static const char *
1710
_bfd_vms_etir_name (int cmd)
1711
83
{
1712
83
  switch (cmd)
1713
83
    {
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
8
    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
4
    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
2
    default:
1765
      /* These names have not yet been added to this switch statement.  */
1766
2
      _bfd_error_handler (_("unknown ETIR command %d"), cmd);
1767
83
    }
1768
1769
2
  return NULL;
1770
83
}
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
5.47k
{
1781
5.47k
  char name[257];
1782
5.47k
  unsigned int len;
1783
5.47k
  unsigned int i;
1784
5.47k
  struct alpha_vms_link_hash_entry *h;
1785
1786
  /* Not linking.  Do not try to resolve the symbol.  */
1787
5.47k
  if (info == NULL)
1788
5.47k
    {
1789
5.47k
      *vma = 0;
1790
5.47k
      *hp = NULL;
1791
5.47k
      return;
1792
5.47k
    }
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
82.3k
#define RELC_NONE 0
1829
0
#define RELC_REL  1
1830
297
#define RELC_SHR_BASE 0x10000
1831
453
#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.81k
{
1837
  /* Handle undefined symbols.  */
1838
4.81k
  if (h == NULL || h->sym == NULL)
1839
4.81k
    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
24.6k
{
1901
24.6k
  unsigned char *ptr;
1902
24.6k
  unsigned int length;
1903
24.6k
  unsigned char *maxptr;
1904
24.6k
  bfd_vma op1 = 0;
1905
24.6k
  bfd_vma op2 = 0;
1906
24.6k
  unsigned int rel1 = RELC_NONE;
1907
24.6k
  unsigned int rel2 = RELC_NONE;
1908
24.6k
  struct alpha_vms_link_hash_entry *h;
1909
1910
24.6k
  PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
1911
24.6k
  PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
1912
1913
24.6k
  ptr = PRIV (recrd.rec);
1914
24.6k
  length = PRIV (recrd.rec_size);
1915
24.6k
  maxptr = ptr + length;
1916
1917
24.6k
  vms_debug2 ((2, "ETIR: %d bytes\n", length));
1918
1919
51.2k
  while (ptr < maxptr)
1920
27.0k
    {
1921
27.0k
      unsigned int cmd, cmd_length;
1922
1923
27.0k
      if (ptr + 4 > maxptr)
1924
44
  goto corrupt_etir;
1925
1926
27.0k
      cmd = bfd_getl16 (ptr);
1927
27.0k
      cmd_length = bfd_getl16 (ptr + 2);
1928
1929
      /* PR 21589 and 21579: Check for a corrupt ETIR record.  */
1930
27.0k
      if (cmd_length < 4 || cmd_length > (size_t) (maxptr - ptr))
1931
155
  {
1932
248
  corrupt_etir:
1933
248
    _bfd_error_handler (_("corrupt ETIR record encountered"));
1934
248
    bfd_set_error (bfd_error_bad_value);
1935
248
    return false;
1936
155
  }
1937
26.8k
      ptr += 4;
1938
26.8k
      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
26.8k
      switch (cmd)
1947
26.8k
  {
1948
    /* Stack global
1949
       arg: cs  symbol name
1950
1951
       stack 32 bit value of symbol (high bits set to 0).  */
1952
4.81k
  case ETIR__C_STA_GBL:
1953
4.81k
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
1954
4.81k
    if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h)))
1955
1
      return false;
1956
4.81k
    break;
1957
1958
    /* Stack longword
1959
       arg: lw  value
1960
1961
       stack 32 bit value, sign extend to 64 bit.  */
1962
6.95k
  case ETIR__C_STA_LW:
1963
6.95k
    if (cmd_length < 4)
1964
3
      goto corrupt_etir;
1965
6.94k
    if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE))
1966
2
      return false;
1967
6.94k
    break;
1968
1969
    /* Stack quadword
1970
       arg: qw  value
1971
1972
       stack 64 bit value of symbol.  */
1973
6.94k
  case ETIR__C_STA_QW:
1974
2.82k
    if (cmd_length < 8)
1975
5
      goto corrupt_etir;
1976
2.81k
    if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE))
1977
1
      return false;
1978
2.81k
    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.81k
  case ETIR__C_STA_PQ:
1987
11
    {
1988
11
      int psect;
1989
1990
11
      if (cmd_length < 12)
1991
3
        goto corrupt_etir;
1992
8
      psect = bfd_getl32 (ptr);
1993
8
      if ((unsigned int) psect >= PRIV (section_count))
1994
8
        {
1995
8
    _bfd_error_handler (_("bad section index in %s"),
1996
8
            _bfd_vms_etir_name (cmd));
1997
8
    bfd_set_error (bfd_error_bad_value);
1998
8
    return false;
1999
8
        }
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
94
  case ETIR__C_STO_B:
2017
94
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2018
5
      return false;
2019
89
    if (rel1 != RELC_NONE)
2020
0
      goto bad_context;
2021
89
    if (!image_write_b (abfd, (unsigned int) op1 & 0xff))
2022
0
      return false;
2023
89
    break;
2024
2025
    /* Store word: pop stack, write word
2026
       arg: -.  */
2027
116
  case ETIR__C_STO_W:
2028
116
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2029
5
      return false;
2030
111
    if (rel1 != RELC_NONE)
2031
0
      goto bad_context;
2032
111
    if (!image_write_w (abfd, (unsigned int) op1 & 0xffff))
2033
0
      return false;
2034
111
    break;
2035
2036
    /* Store longword: pop stack, write longword
2037
       arg: -.  */
2038
155
  case ETIR__C_STO_LW:
2039
155
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2040
5
      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
152
  case ETIR__C_STO_QW:
2066
152
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2067
5
      return false;
2068
147
    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
147
    else if (rel1 & RELC_SHR_BASE)
2074
0
      abort ();
2075
147
    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
147
    if (!image_write_q (abfd, op1))
2083
0
      return false;
2084
147
    break;
2085
2086
    /* Store immediate repeated: pop stack for repeat count
2087
       arg: lw  byte count
2088
       da data.  */
2089
448
  case ETIR__C_STO_IMMR:
2090
448
    {
2091
448
      size_t size;
2092
2093
448
      if (cmd_length < 4)
2094
4
        goto corrupt_etir;
2095
444
      size = bfd_getl32 (ptr);
2096
444
      if (size > cmd_length - 4)
2097
19
        goto corrupt_etir;
2098
425
      if (!_bfd_vms_pop (abfd, &op1, &rel1))
2099
3
        return false;
2100
422
      if (rel1 != RELC_NONE)
2101
0
        goto bad_context;
2102
422
      if (size == 0)
2103
288
        break;
2104
134
      op1 &= 0xffffffff;
2105
134
      if (!image_write_section (abfd))
2106
134
        {
2107
    /* We are just sizing.  Optimise a little.  */
2108
134
    size *= op1;
2109
134
    op1 = 1;
2110
134
        }
2111
268
      while (op1-- > 0)
2112
134
        if (!image_write (abfd, ptr + 4, size))
2113
0
    return false;
2114
134
    }
2115
134
    break;
2116
2117
    /* Store global: write symbol value
2118
       arg: cs  global symbol name.  */
2119
313
  case ETIR__C_STO_GBL:
2120
313
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
2121
313
    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
313
    if (!image_write_q (abfd, op1))
2139
0
      return false;
2140
313
    break;
2141
2142
    /* Store code address: write address of entry point
2143
       arg: cs  global symbol name (procedure).  */
2144
313
  case ETIR__C_STO_CA:
2145
237
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
2146
237
    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
237
    if (!image_write_q (abfd, op1))
2172
0
      return false;
2173
237
    break;
2174
2175
    /* Store offset to psect: pop stack, add low 32 bits to base of psect
2176
       arg: none.  */
2177
237
  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
243
  case ETIR__C_STO_IMM:
2194
243
    {
2195
243
      unsigned int size;
2196
2197
243
      if (cmd_length < 4)
2198
3
        goto corrupt_etir;
2199
240
      size = bfd_getl32 (ptr);
2200
240
      if (size > cmd_length - 4)
2201
6
        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
95
    _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h);
2215
#if 0
2216
    abort ();
2217
#endif
2218
95
    if (!image_write_l (abfd, op1))
2219
0
      return false;
2220
95
    break;
2221
2222
95
  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
24
  case ETIR__C_STC_LP_PSB:
2268
24
    if (cmd_length < 4)
2269
3
      goto corrupt_etir;
2270
21
    _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h);
2271
21
    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
21
    else
2289
21
      {
2290
        /* Undefined symbol.  */
2291
21
        op1 = 0;
2292
21
        op2 = 0;
2293
21
      }
2294
21
    if (!image_write_q (abfd, op1)
2295
21
        || !image_write_q (abfd, op2))
2296
0
      return false;
2297
21
    break;
2298
2299
    /* 205 Store-conditional NOP at address of global
2300
       arg: none.  */
2301
101
  case ETIR__C_STC_NOP_GBL:
2302
    /* ALPHA_R_NOP */
2303
2304
    /* 207 Store-conditional BSR at global address
2305
       arg: none.  */
2306
2307
827
  case ETIR__C_STC_BSR_GBL:
2308
    /* ALPHA_R_BSR */
2309
2310
    /* 209 Store-conditional LDA at global address
2311
       arg: none.  */
2312
2313
887
  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
2.05k
  case ETIR__C_STC_BOH_GBL:
2320
    /* Currentl ignored.  */
2321
2.05k
    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
109
  case ETIR__C_CTL_AUGRB:
2369
109
    if (cmd_length < 4)
2370
3
      goto corrupt_etir;
2371
106
    op1 = bfd_getl32 (ptr);
2372
106
    image_inc_ptr (abfd, op1);
2373
106
    break;
2374
2375
    /* Define location: pop index, save location counter under index
2376
       arg: none.  */
2377
892
  case ETIR__C_CTL_DFLOC:
2378
892
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2379
4
      return false;
2380
888
    if (rel1 != RELC_NONE)
2381
0
      goto bad_context;
2382
888
    if (!dst_define_location (abfd, op1))
2383
3
      return false;
2384
885
    break;
2385
2386
    /* Set location: pop index, restore location counter from index
2387
       arg: none.  */
2388
885
  case ETIR__C_CTL_STLOC:
2389
264
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2390
3
      return false;
2391
261
    if (rel1 != RELC_NONE)
2392
0
      goto bad_context;
2393
261
    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
258
    break;
2400
2401
    /* Stack defined location: pop index, push location counter from index
2402
       arg: none.  */
2403
258
  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
827
  case ETIR__C_OPR_NOP:      /* No-op.  */
2419
827
    break;
2420
2421
220
  case ETIR__C_OPR_ADD:      /* Add.  */
2422
220
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2423
217
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2424
6
      return false;
2425
214
    if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2426
0
      rel1 = rel2;
2427
214
    else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2428
0
      goto bad_context;
2429
214
    if (!_bfd_vms_push (abfd, op1 + op2, rel1))
2430
0
      return false;
2431
214
    break;
2432
2433
214
  case ETIR__C_OPR_SUB:      /* Subtract.  */
2434
164
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2435
161
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2436
8
      return false;
2437
156
    if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2438
0
      rel1 = rel2;
2439
156
    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
156
    else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2446
0
      goto bad_context;
2447
156
    if (!_bfd_vms_push (abfd, op2 - op1, rel1))
2448
0
      return false;
2449
156
    break;
2450
2451
156
  case ETIR__C_OPR_MUL:      /* Multiply.  */
2452
34
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2453
31
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2454
7
      return false;
2455
27
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2456
0
      goto bad_context;
2457
27
    if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE))
2458
0
      return false;
2459
27
    break;
2460
2461
3.28k
  case ETIR__C_OPR_DIV:      /* Divide.  */
2462
3.28k
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2463
3.28k
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2464
9
      return false;
2465
3.27k
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2466
0
      goto bad_context;
2467
3.27k
    if (op1 == 0)
2468
1.06k
      {
2469
        /* Divide by zero is supposed to give a result of zero,
2470
     and a non-fatal warning message.  */
2471
1.06k
        _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV");
2472
1.06k
        if (!_bfd_vms_push (abfd, 0, RELC_NONE))
2473
0
    return false;
2474
1.06k
      }
2475
2.20k
    else
2476
2.20k
      {
2477
2.20k
        if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE))
2478
0
    return false;
2479
2.20k
      }
2480
3.27k
    break;
2481
2482
3.27k
  case ETIR__C_OPR_AND:      /* Logical AND.  */
2483
64
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2484
61
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2485
6
      return false;
2486
58
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2487
0
      goto bad_context;
2488
58
    if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE))
2489
0
      return false;
2490
58
    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
56
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2504
53
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2505
7
      return false;
2506
49
    if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2507
0
      goto bad_context;
2508
49
    if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE))
2509
0
      return false;
2510
49
    break;
2511
2512
49
  case ETIR__C_OPR_NEG:      /* Negate.  */
2513
29
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2514
3
      return false;
2515
26
    if (rel1 != RELC_NONE)
2516
0
      goto bad_context;
2517
26
    if (!_bfd_vms_push (abfd, -op1, RELC_NONE))
2518
0
      return false;
2519
26
    break;
2520
2521
92
  case ETIR__C_OPR_COM:      /* Complement.  */
2522
92
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2523
3
      return false;
2524
89
    if (rel1 != RELC_NONE)
2525
0
      goto bad_context;
2526
89
    if (!_bfd_vms_push (abfd, ~op1, RELC_NONE))
2527
0
      return false;
2528
89
    break;
2529
2530
89
  case ETIR__C_OPR_ASH:      /* Arithmetic shift.  */
2531
67
    if (!_bfd_vms_pop (abfd, &op1, &rel1)
2532
64
        || !_bfd_vms_pop (abfd, &op2, &rel2))
2533
7
      return false;
2534
60
    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
60
    if ((bfd_signed_vma) op2 < 0)
2542
19
      {
2543
        /* Shift right.  */
2544
19
        bfd_vma sign;
2545
19
        op2 = -op2;
2546
19
        if (op2 >= CHAR_BIT * sizeof (op1))
2547
19
    op2 = CHAR_BIT * sizeof (op1) - 1;
2548
        /* op1 = (bfd_signed_vma) op1 >> op2; */
2549
19
        sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1));
2550
19
        op1 >>= op2;
2551
19
        sign >>= op2;
2552
19
        op1 = (op1 ^ sign) - sign;
2553
19
      }
2554
41
    else
2555
41
      {
2556
        /* Shift left.  */
2557
41
        if (op2 >= CHAR_BIT * sizeof (op1))
2558
21
    op1 = 0;
2559
20
        else
2560
20
    op1 <<= op2;
2561
41
      }
2562
60
    if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym.  */
2563
0
      return false;
2564
60
    break;
2565
2566
60
  case ETIR__C_OPR_INSV:      /* Insert field.   */
2567
7
  case ETIR__C_OPR_USH:       /* Unsigned shift.   */
2568
10
  case ETIR__C_OPR_ROT:       /* Rotate.  */
2569
13
  case ETIR__C_OPR_REDEF:     /* Redefine symbol to current location.  */
2570
17
  case ETIR__C_OPR_DFLIT:     /* Define a literal.  */
2571
17
    _bfd_error_handler (_("%s: not supported"),
2572
17
            _bfd_vms_etir_name (cmd));
2573
17
    return false;
2574
0
    break;
2575
2576
2.02k
  case ETIR__C_OPR_SEL:      /* Select.  */
2577
2.02k
    if (!_bfd_vms_pop (abfd, &op1, &rel1))
2578
3
      return false;
2579
2.02k
    if (op1 & 0x01L)
2580
869
      {
2581
869
        if (!_bfd_vms_pop (abfd, &op1, &rel1))
2582
4
    return false;
2583
869
      }
2584
1.15k
    else
2585
1.15k
      {
2586
1.15k
        if (!_bfd_vms_pop (abfd, &op1, &rel1)
2587
1.14k
      || !_bfd_vms_pop (abfd, &op2, &rel2))
2588
6
    return false;
2589
1.14k
        if (!_bfd_vms_push (abfd, op1, rel1))
2590
0
    return false;
2591
1.14k
      }
2592
2.01k
    break;
2593
2594
2.01k
  default:
2595
17
    _bfd_error_handler (_("reserved cmd %d"), cmd);
2596
17
    return false;
2597
0
    break;
2598
26.8k
  }
2599
2600
26.6k
      ptr += cmd_length;
2601
26.6k
    }
2602
2603
24.1k
  return true;
2604
24.6k
}
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
24.6k
{
2612
24.6k
  asection *section = PRIV (dst_section);
2613
2614
24.6k
  if (section == NULL)
2615
925
    {
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
925
      flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC
2620
925
  | SEC_IN_MEMORY;
2621
2622
925
      section = bfd_make_section (abfd, "$DST$");
2623
925
      if (!section)
2624
0
  return false;
2625
925
      if (!bfd_set_section_flags (section, flags))
2626
0
  return false;
2627
925
      PRIV (dst_section) = section;
2628
925
    }
2629
2630
24.6k
  PRIV (image_section) = section;
2631
24.6k
  PRIV (image_offset) = section->size;
2632
2633
24.6k
  if (!_bfd_vms_slurp_etir (abfd, NULL))
2634
472
    return false;
2635
2636
24.1k
  section->size = PRIV (image_offset);
2637
24.1k
  return true;
2638
24.6k
}
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
16.1k
{
2646
16.1k
  vms_debug2 ((2, "EDBG\n"));
2647
2648
16.1k
  abfd->flags |= HAS_DEBUG | HAS_LINENO;
2649
2650
16.1k
  return vms_slurp_debug (abfd);
2651
16.1k
}
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
8.50k
{
2659
8.50k
  vms_debug2 ((2, "ETBT\n"));
2660
2661
8.50k
  abfd->flags |= HAS_LINENO;
2662
2663
8.50k
  return vms_slurp_debug (abfd);
2664
8.50k
}
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
35
{
2672
35
  struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
2673
2674
35
  vms_debug2 ((2, "EEOM\n"));
2675
2676
  /* PR 21813: Check for an undersized record.  */
2677
35
  if (PRIV (recrd.rec_size) < 10)
2678
4
    {
2679
4
      _bfd_error_handler (_("corrupt EEOM record - size is too small"));
2680
4
      bfd_set_error (bfd_error_bad_value);
2681
4
      return false;
2682
4
    }
2683
2684
31
  PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
2685
31
  PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
2686
31
  if (PRIV (eom_data).eom_w_comcod > 1)
2687
8
    {
2688
8
      _bfd_error_handler (_("object module not error-free !"));
2689
8
      bfd_set_error (bfd_error_bad_value);
2690
8
      return false;
2691
8
    }
2692
2693
23
  PRIV (eom_data).eom_has_transfer = false;
2694
23
  if (PRIV (recrd.rec_size) >= sizeof (*eeom))
2695
19
    {
2696
19
      PRIV (eom_data).eom_has_transfer = true;
2697
19
      PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
2698
19
      PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
2699
19
      PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
2700
2701
19
      abfd->start_address = PRIV (eom_data).eom_l_tfradr;
2702
19
    }
2703
23
  return true;
2704
31
}
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.53k
{
2711
1.53k
  bool ok;
2712
1.53k
  int type;
2713
2714
1.53k
  do
2715
30.5k
    {
2716
30.5k
      vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
2717
2718
30.5k
      type = _bfd_vms_get_object_record (abfd);
2719
30.5k
      if (type < 0)
2720
809
  {
2721
809
    vms_debug2 ((2, "next_record failed\n"));
2722
809
    return false;
2723
809
  }
2724
2725
29.7k
      switch (type)
2726
29.7k
  {
2727
2.06k
  case EOBJ__C_EMH:
2728
2.06k
    ok = _bfd_vms_slurp_ehdr (abfd);
2729
2.06k
    break;
2730
35
  case EOBJ__C_EEOM:
2731
35
    ok = _bfd_vms_slurp_eeom (abfd);
2732
35
    break;
2733
1.55k
  case EOBJ__C_EGSD:
2734
1.55k
    ok = _bfd_vms_slurp_egsd (abfd);
2735
1.55k
    break;
2736
1.36k
  case EOBJ__C_ETIR:
2737
1.36k
    ok = true; /* _bfd_vms_slurp_etir (abfd); */
2738
1.36k
    break;
2739
16.1k
  case EOBJ__C_EDBG:
2740
16.1k
    ok = _bfd_vms_slurp_edbg (abfd);
2741
16.1k
    break;
2742
8.50k
  case EOBJ__C_ETBT:
2743
8.50k
    ok = _bfd_vms_slurp_etbt (abfd);
2744
8.50k
    break;
2745
51
  default:
2746
51
    ok = false;
2747
29.7k
  }
2748
29.7k
      if (!ok)
2749
705
  {
2750
705
    vms_debug2 ((2, "slurp type %d failed\n", type));
2751
705
    return false;
2752
705
  }
2753
29.7k
    }
2754
29.0k
  while (type != EOBJ__C_EEOM);
2755
2756
23
  return true;
2757
1.53k
}
2758
2759
/* Initialize private data  */
2760
static bool
2761
vms_initialize (bfd * abfd)
2762
161k
{
2763
161k
  size_t amt;
2764
2765
161k
  amt = sizeof (struct vms_private_data_struct);
2766
161k
  abfd->tdata.any = bfd_zalloc (abfd, amt);
2767
161k
  if (abfd->tdata.any == NULL)
2768
0
    return false;
2769
2770
161k
  PRIV (recrd.file_format) = FF_UNKNOWN;
2771
2772
161k
  amt = sizeof (struct stack_struct) * STACKSIZE;
2773
161k
  PRIV (stack) = bfd_alloc (abfd, amt);
2774
161k
  if (PRIV (stack) == NULL)
2775
0
    goto error_ret1;
2776
2777
161k
  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
161k
}
2784
2785
/* Free malloc'd memory.  */
2786
2787
static void
2788
alpha_vms_free_private (bfd *abfd)
2789
161k
{
2790
161k
  struct module *module;
2791
2792
161k
  free (PRIV (recrd.buf));
2793
161k
  free (PRIV (sections));
2794
161k
  free (PRIV (syms));
2795
161k
  free (PRIV (dst_ptr_offsets));
2796
2797
161k
  for (module = PRIV (modules); module; module = module->next)
2798
666
    free (module->file_table);
2799
161k
}
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
161k
{
2807
161k
  unsigned int test_len;
2808
161k
  unsigned char *buf;
2809
2810
161k
  vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
2811
2812
  /* Allocate alpha-vms specific data.  */
2813
161k
  if (!vms_initialize (abfd))
2814
0
    return NULL;
2815
2816
161k
  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
161k
  test_len = 12;
2836
161k
  buf = _bfd_malloc_and_read (abfd, test_len, test_len);
2837
161k
  if (buf == NULL)
2838
2.59k
    goto error_ret;
2839
158k
  PRIV (recrd.buf) = buf;
2840
158k
  PRIV (recrd.buf_size) = test_len;
2841
158k
  PRIV (recrd.rec) = buf;
2842
2843
  /* Is it an image?  */
2844
158k
  if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
2845
1.15k
      && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
2846
1.06k
    {
2847
1.06k
      unsigned int eisd_offset, eihs_offset;
2848
2849
      /* Extract the header size.  */
2850
1.06k
      PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
2851
2852
      /* The header size is 0 for DSF files.  */
2853
1.06k
      if (PRIV (recrd.rec_size) == 0)
2854
279
  PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
2855
2856
      /* PR 21813: Check for a truncated record.  */
2857
      /* PR 17512: file: 7d7c57c2.  */
2858
1.06k
      if (PRIV (recrd.rec_size) < EIHD__C_LENGTH)
2859
11
  goto err_wrong_format;
2860
2861
1.05k
      if (bfd_seek (abfd, 0, SEEK_SET))
2862
0
  goto error_ret;
2863
2864
1.05k
      free (PRIV (recrd.buf));
2865
1.05k
      PRIV (recrd.buf) = NULL;
2866
1.05k
      buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size),
2867
1.05k
          PRIV (recrd.rec_size));
2868
1.05k
      if (buf == NULL)
2869
216
  goto error_ret;
2870
2871
835
      PRIV (recrd.buf) = buf;
2872
835
      PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
2873
835
      PRIV (recrd.rec) = buf;
2874
2875
835
      vms_debug2 ((2, "file type is image\n"));
2876
2877
835
      if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset))
2878
0
  goto err_wrong_format;
2879
2880
835
      if (!_bfd_vms_slurp_eisd (abfd, eisd_offset))
2881
421
  goto err_wrong_format;
2882
2883
      /* EIHS is optional.  */
2884
414
      if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset))
2885
125
  goto err_wrong_format;
2886
414
    }
2887
157k
  else
2888
157k
    {
2889
157k
      int type;
2890
2891
      /* Assume it's a module and adjust record pointer if necessary.  */
2892
157k
      maybe_adjust_record_pointer_for_object (abfd);
2893
2894
      /* But is it really a module?  */
2895
157k
      if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
2896
4.40k
    && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
2897
3.52k
  {
2898
3.52k
    if (vms_get_remaining_object_record (abfd, test_len) <= 0)
2899
1.89k
      goto err_wrong_format;
2900
2901
1.63k
    vms_debug2 ((2, "file type is module\n"));
2902
2903
1.63k
    type = bfd_getl16 (PRIV (recrd.rec));
2904
1.63k
    if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd))
2905
158
      goto err_wrong_format;
2906
2907
1.47k
    if (!_bfd_vms_slurp_object_records (abfd))
2908
1.45k
      goto err_wrong_format;
2909
1.47k
  }
2910
153k
      else
2911
153k
  goto err_wrong_format;
2912
157k
    }
2913
2914
  /* Set arch_info to alpha.   */
2915
2916
311
  if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
2917
0
    goto err_wrong_format;
2918
2919
311
  return alpha_vms_free_private;
2920
2921
158k
 err_wrong_format:
2922
158k
  bfd_set_error (bfd_error_wrong_format);
2923
2924
160k
 error_ret:
2925
160k
  alpha_vms_free_private (abfd);
2926
160k
  bfd_release (abfd, abfd->tdata.any);
2927
160k
  return NULL;
2928
158k
}
2929

2930
/* Image write.  */
2931
2932
/* Write an EMH/MHD record.  */
2933
2934
static bool
2935
_bfd_vms_write_emh (bfd *abfd)
2936
1
{
2937
1
  struct vms_rec_wr *recwr = &PRIV (recwr);
2938
1
  unsigned char tbuf[18];
2939
2940
1
  _bfd_vms_output_alignment (recwr, 2);
2941
2942
  /* EMH.  */
2943
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2944
1
  _bfd_vms_output_short (recwr, EMH__C_MHD);
2945
1
  _bfd_vms_output_short (recwr, EOBJ__C_STRLVL);
2946
1
  _bfd_vms_output_long (recwr, 0);
2947
1
  _bfd_vms_output_long (recwr, 0);
2948
1
  _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE);
2949
2950
  /* Create module name from filename.  */
2951
1
  if (bfd_get_filename (abfd) != 0)
2952
1
    {
2953
1
      char *module = vms_get_module_name (bfd_get_filename (abfd), true);
2954
1
      _bfd_vms_output_counted (recwr, module);
2955
1
      free (module);
2956
1
    }
2957
0
  else
2958
0
    _bfd_vms_output_counted (recwr, "NONAME");
2959
2960
1
  _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
2961
1
  _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH);
2962
1
  _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
2963
1
  return _bfd_vms_output_end (abfd, recwr);
2964
1
}
2965
2966
/* Write an EMH/LMN record.  */
2967
2968
static bool
2969
_bfd_vms_write_lmn (bfd *abfd, const char *name)
2970
1
{
2971
1
  char version [64];
2972
1
  struct vms_rec_wr *recwr = &PRIV (recwr);
2973
1
  unsigned int ver = BFD_VERSION / 10000;
2974
2975
  /* LMN.  */
2976
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2977
1
  _bfd_vms_output_short (recwr, EMH__C_LNM);
2978
1
  snprintf (version, sizeof (version), "%s %d.%d.%d", name,
2979
1
      ver / 10000, (ver / 100) % 100, ver % 100);
2980
1
  _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
2981
1
  return _bfd_vms_output_end (abfd, recwr);
2982
1
}
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
6
{
3070
6
  bfd_putl32 (src->u.eisd.majorid, dst->majorid);
3071
6
  bfd_putl32 (src->u.eisd.minorid, dst->minorid);
3072
6
  bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize);
3073
6
  if (src->u.eisd.eisdsize <= EISD__K_LENEND)
3074
0
    return;
3075
6
  bfd_putl32 (src->u.eisd.secsize, dst->secsize);
3076
6
  bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr);
3077
6
  bfd_putl32 (src->u.eisd.flags, dst->flags);
3078
6
  bfd_putl32 (src->u.eisd.vbn, dst->vbn);
3079
6
  dst->pfc = src->u.eisd.pfc;
3080
6
  dst->matchctl = src->u.eisd.matchctl;
3081
6
  dst->type = src->u.eisd.type;
3082
6
  dst->fill_1 = 0;
3083
6
  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
6
}
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
8
{
3154
8
  struct vms_internal_eisd_map *eisd;
3155
3156
  /* Only for allocating section.  */
3157
8
  if (!(sec->flags & SEC_ALLOC))
3158
2
    return true;
3159
3160
6
  BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
3161
6
  eisd = bfd_alloc (abfd, sizeof (*eisd));
3162
6
  if (eisd == NULL)
3163
0
    return false;
3164
6
  vms_section_data (sec)->eisd = eisd;
3165
3166
  /* Fill the fields.  */
3167
6
  eisd->u.eisd.majorid = EISD__K_MAJORID;
3168
6
  eisd->u.eisd.minorid = EISD__K_MINORID;
3169
6
  eisd->u.eisd.eisdsize = EISD__K_LEN;
3170
6
  eisd->u.eisd.secsize =
3171
6
    (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
3172
6
  eisd->u.eisd.virt_addr = sec->vma;
3173
6
  eisd->u.eisd.flags = 0;
3174
6
  eisd->u.eisd.vbn = 0; /* To be later defined.  */
3175
6
  eisd->u.eisd.pfc = 0; /* Default.  */
3176
6
  eisd->u.eisd.matchctl = EISD__K_MATALL;
3177
6
  eisd->u.eisd.type = EISD__K_NORMAL;
3178
3179
6
  if (sec->flags & SEC_CODE)
3180
3
    eisd->u.eisd.flags |= EISD__M_EXE;
3181
6
  if (!(sec->flags & SEC_READONLY))
3182
0
    eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
3183
3184
  /* If relocations or fixup will be applied, make this isect writeable.  */
3185
6
  if (sec->flags & SEC_RELOC)
3186
0
    eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
3187
3188
6
  if (!(sec->flags & SEC_HAS_CONTENTS))
3189
1
    {
3190
1
      eisd->u.eisd.flags |= EISD__M_DZRO;
3191
1
      eisd->u.eisd.flags &= ~EISD__M_CRF;
3192
1
    }
3193
6
  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
6
  eisd->next = NULL;
3201
6
  if (PRIV (eisd_head) == NULL)
3202
2
    PRIV (eisd_head) = eisd;
3203
4
  else
3204
4
    PRIV (eisd_tail)->next = eisd;
3205
6
  PRIV (eisd_tail) = eisd;
3206
3207
6
  return true;
3208
6
}
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
3
{
3216
3
  struct vms_eihd eihd;
3217
3
  struct vms_eiha *eiha;
3218
3
  struct vms_eihi *eihi;
3219
3
  struct vms_eihs *eihs = NULL;
3220
3
  asection *sec;
3221
3
  struct vms_internal_eisd_map *first_eisd;
3222
3
  struct vms_internal_eisd_map *eisd;
3223
3
  asection *dst;
3224
3
  asection *dmt;
3225
3
  file_ptr gst_filepos = 0;
3226
3
  unsigned int lnkflags = 0;
3227
3228
  /* Build the EIHD.  */
3229
3
  PRIV (file_pos) = EIHD__C_LENGTH;
3230
3231
3
  memset (&eihd, 0, sizeof (eihd));
3232
3
  memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2));
3233
3234
3
  bfd_putl32 (EIHD__K_MAJORID, eihd.majorid);
3235
3
  bfd_putl32 (EIHD__K_MINORID, eihd.minorid);
3236
3237
3
  bfd_putl32 (sizeof (eihd), eihd.size);
3238
3
  bfd_putl32 (0, eihd.isdoff);
3239
3
  bfd_putl32 (0, eihd.activoff);
3240
3
  bfd_putl32 (0, eihd.symdbgoff);
3241
3
  bfd_putl32 (0, eihd.imgidoff);
3242
3
  bfd_putl32 (0, eihd.patchoff);
3243
3
  bfd_putl64 (0, eihd.iafva);
3244
3
  bfd_putl32 (0, eihd.version_array_off);
3245
3246
3
  bfd_putl32 (EIHD__K_EXE, eihd.imgtype);
3247
3
  bfd_putl32 (0, eihd.subtype);
3248
3249
3
  bfd_putl32 (0, eihd.imgiocnt);
3250
3
  bfd_putl32 (-1, eihd.privreqs);
3251
3
  bfd_putl32 (-1, eihd.privreqs + 4);
3252
3253
3
  bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
3254
3
        eihd.hdrblkcnt);
3255
3
  bfd_putl32 (0, eihd.ident);
3256
3
  bfd_putl32 (0, eihd.sysver);
3257
3258
3
  eihd.matchctl = 0;
3259
3
  bfd_putl32 (0, eihd.symvect_size);
3260
3
  bfd_putl32 (16, eihd.virt_mem_block_size);
3261
3
  bfd_putl32 (0, eihd.ext_fixup_off);
3262
3
  bfd_putl32 (0, eihd.noopt_psect_off);
3263
3
  bfd_putl16 (-1, eihd.alias);
3264
3265
  /* Alloc EIHA.  */
3266
3
  eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
3267
3
  bfd_putl32 (PRIV (file_pos), eihd.activoff);
3268
3
  PRIV (file_pos) += sizeof (struct vms_eiha);
3269
3270
3
  bfd_putl32 (sizeof (struct vms_eiha), eiha->size);
3271
3
  bfd_putl32 (0, eiha->spare);
3272
3
  bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1);
3273
3
  bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2);
3274
3
  bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3);
3275
3
  bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4);
3276
3
  bfd_putl64 (0, eiha->inishr);
3277
3278
  /* Alloc EIHI.  */
3279
3
  eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos));
3280
3
  bfd_putl32 (PRIV (file_pos), eihd.imgidoff);
3281
3
  PRIV (file_pos) += sizeof (struct vms_eihi);
3282
3283
3
  bfd_putl32 (EIHI__K_MAJORID, eihi->majorid);
3284
3
  bfd_putl32 (EIHI__K_MINORID, eihi->minorid);
3285
3
  {
3286
3
    char *module;
3287
3
    unsigned int len;
3288
3289
    /* Set module name.  */
3290
3
    module = vms_get_module_name (bfd_get_filename (abfd), true);
3291
3
    len = strlen (module);
3292
3
    if (len > sizeof (eihi->imgnam) - 1)
3293
0
      len = sizeof (eihi->imgnam) - 1;
3294
3
    eihi->imgnam[0] = len;
3295
3
    memcpy (eihi->imgnam + 1, module, len);
3296
3
    free (module);
3297
3
  }
3298
3
  {
3299
3
    unsigned int lo;
3300
3
    unsigned int hi;
3301
3302
    /* Set time.  */
3303
3
    vms_get_time (&hi, &lo);
3304
3
    bfd_putl32 (lo, eihi->linktime + 0);
3305
3
    bfd_putl32 (hi, eihi->linktime + 4);
3306
3
  }
3307
3
  eihi->imgid[0] = 0;
3308
3
  eihi->linkid[0] = 0;
3309
3
  eihi->imgbid[0] = 0;
3310
3311
  /* Alloc EIHS.  */
3312
3
  dst = PRIV (dst_section);
3313
3
  dmt = bfd_get_section_by_name (abfd, "$DMT$");
3314
3
  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
11
  for (sec = abfd->sections; sec; sec = sec->next)
3332
8
    {
3333
8
      if (!alpha_vms_create_eisd_for_section (abfd, sec))
3334
0
  return false;
3335
8
    }
3336
3337
  /* Merge section EIDS which extra ones.  */
3338
3
  if (PRIV (eisd_tail))
3339
2
    PRIV (eisd_tail)->next = PRIV (gbl_eisd_head);
3340
1
  else
3341
1
    PRIV (eisd_head) = PRIV (gbl_eisd_head);
3342
3
  if (PRIV (gbl_eisd_tail))
3343
0
    PRIV (eisd_tail) = PRIV (gbl_eisd_tail);
3344
3345
3
  first_eisd = PRIV (eisd_head);
3346
3347
  /* Add end of eisd.  */
3348
3
  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
9
  for (eisd = first_eisd; eisd; eisd = eisd->next)
3361
6
    {
3362
6
      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
6
      if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2)
3366
6
  room -= 2;
3367
6
      if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND)
3368
0
  alpha_vms_file_position_block (abfd);
3369
3370
6
      eisd->file_pos = PRIV (file_pos);
3371
6
      PRIV (file_pos) += eisd->u.eisd.eisdsize;
3372
3373
6
      if (eisd->u.eisd.flags & EISD__M_FIXUPVEC)
3374
0
  bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva);
3375
6
    }
3376
3377
3
  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
3
  bfd_putl32 (PRIV (file_pos), eihd.size);
3385
3
  bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
3386
3
        eihd.hdrblkcnt);
3387
3388
  /* Place sections.  */
3389
11
  for (sec = abfd->sections; sec; sec = sec->next)
3390
8
    {
3391
8
      if (!(sec->flags & SEC_HAS_CONTENTS)
3392
7
    || sec->contents == NULL)
3393
8
  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
3
  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
9
  for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE;
3430
6
       eisd = eisd->next)
3431
6
    alpha_vms_swap_eisd_out
3432
6
      (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos));
3433
3434
  /* Write first block.  */
3435
3
  bfd_putl32 (lnkflags, eihd.lnkflags);
3436
3
  if (bfd_write (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
3437
0
    return false;
3438
3439
  /* Write remaining eisd.  */
3440
3
  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
11
  for (sec = abfd->sections; sec; sec = sec->next)
3468
8
    {
3469
8
      unsigned char blk[VMS_BLOCK_SIZE];
3470
8
      bfd_size_type len;
3471
3472
8
      if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS)
3473
0
    || sec->contents == NULL)
3474
8
  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
3
  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
3
  return true;
3553
3
}
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
1
{
3562
1
  asection *section;
3563
1
  asymbol *symbol;
3564
1
  unsigned int symnum;
3565
1
  const char *sname;
3566
1
  flagword new_flags, old_flags;
3567
1
  int abs_section_index = -1;
3568
1
  unsigned int target_index = 0;
3569
1
  struct vms_rec_wr *recwr = &PRIV (recwr);
3570
3571
1
  vms_debug2 ((2, "vms_write_egsd\n"));
3572
3573
  /* Egsd is quadword aligned.  */
3574
1
  _bfd_vms_output_alignment (recwr, 8);
3575
3576
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3577
1
  _bfd_vms_output_long (recwr, 0);
3578
3579
  /* Number sections.  */
3580
3
  for (section = abfd->sections; section != NULL; section = section->next)
3581
2
    {
3582
2
      if (section->flags & SEC_DEBUGGING)
3583
1
  continue;
3584
1
      if (!strcmp (section->name, ".vmsdebug"))
3585
0
  {
3586
0
    section->flags |= SEC_DEBUGGING;
3587
0
    continue;
3588
0
  }
3589
1
      section->target_index = target_index++;
3590
1
    }
3591
3592
3
  for (section = abfd->sections; section != NULL; section = section->next)
3593
2
    {
3594
2
      vms_debug2 ((3, "Section #%d %s, %d bytes\n",
3595
2
       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
2
      if (section->flags & SEC_DEBUGGING)
3600
1
  continue;
3601
3602
      /* 13 bytes egsd, max 31 chars name -> should be 44 bytes.  */
3603
1
      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
1
      sname = section->name;
3614
1
      if (*sname == '.')
3615
1
  {
3616
    /* Remove leading dot.  */
3617
1
    sname++;
3618
1
    if ((*sname == 't') && (strcmp (sname, "text") == 0))
3619
0
      sname = EVAX_CODE_NAME;
3620
1
    else if ((*sname == 'd') && (strcmp (sname, "data") == 0))
3621
0
      sname = EVAX_DATA_NAME;
3622
1
    else if ((*sname == 'b') && (strcmp (sname, "bss") == 0))
3623
0
      sname = EVAX_BSS_NAME;
3624
1
    else if ((*sname == 'l') && (strcmp (sname, "link") == 0))
3625
0
      sname = EVAX_LINK_NAME;
3626
1
    else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0))
3627
0
      sname = EVAX_READONLY_NAME;
3628
1
    else if ((*sname == 'l') && (strcmp (sname, "literal") == 0))
3629
0
      sname = EVAX_LITERAL_NAME;
3630
1
    else if ((*sname == 'l') && (strcmp (sname, "literals") == 0))
3631
0
      sname = EVAX_LITERALS_NAME;
3632
1
    else if ((*sname == 'c') && (strcmp (sname, "comm") == 0))
3633
0
      sname = EVAX_COMMON_NAME;
3634
1
    else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
3635
0
      sname = EVAX_LOCAL_NAME;
3636
1
  }
3637
3638
1
      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
1
      else
3642
1
  new_flags = vms_esecflag_by_name (evax_section_flags, sname,
3643
1
            section->size > 0);
3644
3645
      /* Modify them as directed.  */
3646
1
      if (section->flags & SEC_READONLY)
3647
0
  new_flags &= ~EGPS__V_WRT;
3648
3649
1
      new_flags &= ~vms_section_data (section)->no_flags;
3650
1
      new_flags |= vms_section_data (section)->flags;
3651
3652
1
      vms_debug2 ((3, "sec flags %x\n", section->flags));
3653
1
      vms_debug2 ((3, "new_flags %x, _raw_size %lu\n",
3654
1
       new_flags, (unsigned long)section->size));
3655
3656
1
      _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3657
1
      _bfd_vms_output_short (recwr, section->alignment_power & 0xff);
3658
1
      _bfd_vms_output_short (recwr, new_flags);
3659
1
      _bfd_vms_output_long (recwr, (unsigned long) section->size);
3660
1
      _bfd_vms_output_counted (recwr, sname);
3661
1
      _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
1
      if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0)
3666
0
  abs_section_index = section->target_index;
3667
1
    }
3668
3669
  /* Output symbols.  */
3670
1
  vms_debug2 ((3, "%d symbols found\n", abfd->symcount));
3671
3672
1
  bfd_set_start_address (abfd, (bfd_vma) -1);
3673
3674
1
  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
1
  _bfd_vms_output_alignment (recwr, 8);
3782
1
  return _bfd_vms_output_end (abfd, recwr);
3783
1
}
3784
3785
/* Write object header for bfd abfd.  Return FALSE on error.  */
3786
3787
static bool
3788
_bfd_vms_write_ehdr (bfd *abfd)
3789
1
{
3790
1
  asymbol *symbol;
3791
1
  unsigned int symnum;
3792
1
  struct vms_rec_wr *recwr = &PRIV (recwr);
3793
3794
1
  vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
3795
3796
1
  _bfd_vms_output_alignment (recwr, 2);
3797
3798
1
  if (!_bfd_vms_write_emh (abfd)
3799
1
      || !_bfd_vms_write_lmn (abfd, "GNU AS"))
3800
0
    return false;
3801
3802
  /* SRC.  */
3803
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3804
1
  _bfd_vms_output_short (recwr, EMH__C_SRC);
3805
3806
1
  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
1
  if (symnum == abfd->symcount)
3819
1
    _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
3820
3821
1
  if (!_bfd_vms_output_end (abfd, recwr))
3822
0
    return false;
3823
3824
  /* TTL.  */
3825
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3826
1
  _bfd_vms_output_short (recwr, EMH__C_TTL);
3827
1
  _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
3828
1
  if (!_bfd_vms_output_end (abfd, recwr))
3829
0
    return false;
3830
3831
  /* CPR.  */
3832
1
  _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3833
1
  _bfd_vms_output_short (recwr, EMH__C_CPR);
3834
1
  _bfd_vms_output_dump (recwr,
3835
1
      (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
3836
1
       39);
3837
1
  return _bfd_vms_output_end (abfd, recwr);
3838
1
}
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
1
{
3983
1
  asection *section;
3984
1
  struct vms_rec_wr *recwr = &PRIV (recwr);
3985
3986
1
  vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype));
3987
3988
1
  _bfd_vms_output_alignment (recwr, 4);
3989
3990
1
  PRIV (vms_linkage_index) = 0;
3991
3992
2
  for (section = abfd->sections; section; section = section->next)
3993
2
    {
3994
2
      vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n",
3995
2
       section->target_index, section->name, (int) (section->size)));
3996
3997
2
      if (!(section->flags & SEC_HAS_CONTENTS)
3998
1
    || bfd_is_com_section (section))
3999
1
  continue;
4000
4001
1
      if (!section->contents)
4002
1
  {
4003
1
    bfd_set_error (bfd_error_no_contents);
4004
1
    return false;
4005
1
  }
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
1
}
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
11
{
4334
11
  vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
4335
4336
11
  if (abfd->flags & (EXEC_P | DYNAMIC))
4337
3
    {
4338
3
      return alpha_vms_write_exec (abfd);
4339
3
    }
4340
8
  else
4341
8
    {
4342
8
      if (abfd->section_count > 0)      /* we have sections */
4343
1
  {
4344
1
    if (!_bfd_vms_write_ehdr (abfd))
4345
0
      return false;
4346
1
    if (!_bfd_vms_write_egsd (abfd))
4347
0
      return false;
4348
1
    if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR))
4349
1
      return false;
4350
0
    if (!_bfd_vms_write_eeom (abfd))
4351
0
      return false;
4352
0
  }
4353
8
    }
4354
7
  return true;
4355
11
}
4356

4357
/* Debug stuff: nearest line.  */
4358
4359
#define SET_MODULE_PARSED(m) \
4360
45
  do { if ((m)->name == NULL) (m)->name = ""; } while (0)
4361
162
#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
666
{
4368
666
  struct module *module
4369
666
    = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
4370
666
  module->file_table_count = 16; /* Arbitrary.  */
4371
666
  module->file_table
4372
666
    = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo));
4373
666
  return module;
4374
666
}
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
45
{
4382
45
  unsigned char *maxptr = ptr + length;
4383
45
  unsigned char *src_ptr, *pcl_ptr;
4384
45
  unsigned int prev_linum = 0, curr_linenum = 0;
4385
45
  bfd_vma prev_pc = 0, curr_pc = 0;
4386
45
  struct srecinfo *curr_srec, *srec;
4387
45
  struct lineinfo *curr_line, *line;
4388
45
  struct funcinfo *funcinfo;
4389
4390
  /* Initialize tables with zero element.  */
4391
45
  curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4392
45
  if (!curr_srec)
4393
0
    return false;
4394
45
  module->srec_table = curr_srec;
4395
4396
45
  curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4397
45
  if (!curr_line)
4398
0
    return false;
4399
45
  module->line_table = curr_line;
4400
4401
325
  while (ptr + 3 < maxptr)
4402
299
    {
4403
      /* The first byte is not counted in the recorded length.  */
4404
299
      int rec_length = bfd_getl16 (ptr) + 1;
4405
299
      int rec_type = bfd_getl16 (ptr + 2);
4406
4407
299
      vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
4408
4409
299
      if (rec_length > maxptr - ptr)
4410
19
  break;
4411
280
      if (rec_type == DST__K_MODEND)
4412
0
  break;
4413
4414
280
      switch (rec_type)
4415
280
  {
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
15
  case DST__K_RTNEND:
4453
15
    if (rec_length < DST_S_L_RTNEND_SIZE + 4)
4454
15
      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
265
  default:
4929
265
    vms_debug2 ((3, "ignoring record\n"));
4930
265
    break;
4931
4932
280
  }
4933
4934
280
      ptr += rec_length;
4935
280
    }
4936
4937
  /* Finalize tables with EOL marker.  */
4938
45
  srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4939
45
  srec->line = (unsigned int) -1;
4940
45
  srec->srec = (unsigned int) -1;
4941
45
  curr_srec->next = srec;
4942
4943
45
  line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4944
45
  line->line = (unsigned int) -1;
4945
45
  line->address = (bfd_vma) -1;
4946
45
  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
45
  SET_MODULE_PARSED (module);
4952
45
  return true;
4953
45
}
4954
4955
/* Build the list of modules for the specified BFD.  */
4956
4957
static struct module *
4958
build_module_list (bfd *abfd)
4959
69
{
4960
69
  struct module *module, *list = NULL;
4961
69
  asection *dmt;
4962
4963
69
  if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
4964
69
    {
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
69
      bfd_size_type size = bfd_section_size (dmt);
4970
69
      unsigned char *buf, *ptr, *end;
4971
4972
69
      if (! bfd_malloc_and_get_section (abfd, dmt, &buf))
4973
1
  return NULL;
4974
4975
68
      vms_debug2 ((2, "DMT\n"));
4976
4977
68
      ptr = buf;
4978
68
      end = ptr + size;
4979
454
      while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE)
4980
386
  {
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
386
    unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
4985
386
    unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
4986
386
    int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
4987
386
    ptr += DBG_S_C_DMT_HEADER_SIZE;
4988
4989
386
    vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n",
4990
386
           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
1.05k
    while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE)
4998
666
      {
4999
666
        unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
5000
666
        unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
5001
666
        module = new_module (abfd);
5002
666
        module->modbeg = modbeg;
5003
666
        module->size = msize;
5004
666
        module->low = start;
5005
666
        module->high = start + length;
5006
666
        module->next = list;
5007
666
        list = module;
5008
666
        ptr += DBG_S_C_DMT_PSECT_SIZE;
5009
5010
666
        vms_debug2 ((4, "section: start = 0x%x, length = %u\n",
5011
666
         start, length));
5012
666
      }
5013
386
  }
5014
68
      free (buf);
5015
68
    }
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
68
  return list;
5034
69
}
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
162
{
5044
162
  struct funcinfo *funcinfo;
5045
162
  struct lineinfo *lineinfo;
5046
162
  struct srecinfo *srecinfo;
5047
162
  bool ret = false;
5048
5049
  /* Parse this module if that was not done at module creation.  */
5050
162
  if (! IS_MODULE_PARSED (module))
5051
131
    {
5052
131
      unsigned int size = module->size;
5053
131
      unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
5054
131
      unsigned char *buffer;
5055
5056
131
      if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
5057
131
    || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL)
5058
86
  {
5059
86
    bfd_set_error (bfd_error_no_debug_section);
5060
86
    return false;
5061
86
  }
5062
5063
45
      ret = parse_module (abfd, module, buffer, size);
5064
45
      free (buffer);
5065
45
      if (!ret)
5066
0
  return ret;
5067
45
    }
5068
5069
  /* Find out the function (if any) that contains the address.  */
5070
76
  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
76
  for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
5080
76
    if (lineinfo->next && addr < lineinfo->next->address)
5081
76
      {
5082
76
  for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
5083
76
    if (srecinfo->next && lineinfo->line < srecinfo->next->line)
5084
76
      {
5085
76
        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
76
        else
5091
76
    {
5092
76
      *file = module->name;
5093
76
      *line = lineinfo->line;
5094
76
    }
5095
76
        return true;
5096
76
      }
5097
5098
0
  break;
5099
76
      }
5100
5101
0
  return ret;
5102
76
}
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
247
{
5118
247
  struct module *module;
5119
5120
  /* What address are we looking for?  */
5121
247
  bfd_vma addr = section->vma + offset;
5122
5123
247
  *file = NULL;
5124
247
  *func = NULL;
5125
247
  *line = 0;
5126
247
  if (discriminator)
5127
247
    *discriminator = 0;
5128
5129
  /* We can't do anything if there is no DST (debug symbol table).  */
5130
247
  if (PRIV (dst_section) == NULL)
5131
0
    return false;
5132
5133
  /* Create the module list - if not already done.  */
5134
247
  if (PRIV (modules) == NULL)
5135
69
    {
5136
69
      PRIV (modules) = build_module_list (abfd);
5137
69
      if (PRIV (modules) == NULL)
5138
21
  return false;
5139
69
    }
5140
5141
2.51k
  for (module = PRIV (modules); module; module = module->next)
5142
2.45k
    if (addr >= module->low && addr <= module->high)
5143
162
      return module_find_nearest_line (abfd, module, addr, file, func, line);
5144
5145
64
  return false;
5146
226
}
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
85
{
5154
85
  flagword flags;
5155
85
  symvalue value;
5156
85
  asection *sec;
5157
85
  const char *name;
5158
5159
85
  name = e->name;
5160
85
  value = 0;
5161
85
  flags = BSF_NO_FLAGS;
5162
85
  sec = NULL;
5163
5164
85
  switch (e->typ)
5165
85
    {
5166
85
    case EGSD__C_SYM:
5167
85
      if (e->flags & EGSY__V_WEAK)
5168
17
  flags |= BSF_WEAK;
5169
5170
85
      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
85
      else
5180
85
  {
5181
    /* Symbol reference.  */
5182
85
    sec = bfd_und_section_ptr;
5183
85
  }
5184
85
      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
85
    }
5211
5212
85
  sym->name = name;
5213
85
  sym->section = sec;
5214
85
  sym->flags = flags;
5215
85
  sym->value = value;
5216
85
  return true;
5217
85
}
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
37
{
5228
37
  vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
5229
37
         abfd, PRIV (gsd_sym_count)));
5230
5231
37
  return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
5232
37
}
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
47
{
5242
47
  unsigned int i;
5243
5244
47
  vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
5245
5246
47
  if (PRIV (csymbols) == NULL)
5247
28
    {
5248
28
      PRIV (csymbols) = (asymbol **) bfd_alloc
5249
28
  (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
5250
5251
      /* Traverse table and fill symbols vector.  */
5252
113
      for (i = 0; i < PRIV (gsd_sym_count); i++)
5253
85
  {
5254
85
    struct vms_symbol_entry *e = PRIV (syms)[i];
5255
85
    asymbol *sym;
5256
5257
85
    sym = bfd_make_empty_symbol (abfd);
5258
85
    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
85
    PRIV (csymbols)[i] = sym;
5266
85
  }
5267
28
    }
5268
5269
47
  if (symbols != NULL)
5270
37
    {
5271
178
      for (i = 0; i < PRIV (gsd_sym_count); i++)
5272
141
  symbols[i] = PRIV (csymbols)[i];
5273
37
      symbols[i] = NULL;
5274
37
    }
5275
5276
47
  return PRIV (gsd_sym_count);
5277
47
}
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
12
{
5284
12
  unsigned int cur_psect = -1u;
5285
5286
12
  vms_debug2 ((3, "alpha_vms_slurp_relocs\n"));
5287
5288
  /* We slurp relocs only once, for all sections.  */
5289
12
  if (PRIV (reloc_done) != 0)
5290
2
    return PRIV (reloc_done) == 1;
5291
5292
10
  if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
5293
0
    goto fail;
5294
5295
10
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
5296
0
    goto fail;
5297
5298
37
  while (1)
5299
37
    {
5300
37
      unsigned char *begin;
5301
37
      unsigned char *end;
5302
37
      unsigned char *ptr;
5303
37
      bfd_reloc_code_real_type reloc_code;
5304
37
      int type;
5305
37
      bfd_vma vaddr = 0;
5306
5307
37
      int length;
5308
5309
37
      bfd_vma cur_address;
5310
37
      int cur_psidx = -1;
5311
37
      unsigned char *cur_sym = NULL;
5312
37
      int prev_cmd = -1;
5313
37
      bfd_vma cur_addend = 0;
5314
5315
      /* Skip non-ETIR records.  */
5316
37
      type = _bfd_vms_get_object_record (abfd);
5317
37
      if (type < 0)
5318
2
  goto fail;
5319
35
      if (type == EOBJ__C_EEOM)
5320
2
  break;
5321
33
      if (type != EOBJ__C_ETIR)
5322
27
  continue;
5323
5324
6
      begin = PRIV (recrd.rec) + 4;
5325
6
      end = PRIV (recrd.rec) + PRIV (recrd.rec_size);
5326
5327
12
      for (ptr = begin; ptr + 4 <= end; ptr += length)
5328
12
  {
5329
12
    int cmd;
5330
5331
12
    cmd = bfd_getl16 (ptr);
5332
12
    length = bfd_getl16 (ptr + 2);
5333
12
    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
10
    cur_address = vaddr;
5341
5342
10
    vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n",
5343
10
           _bfd_vms_etir_name (cmd)));
5344
5345
10
    switch (cmd)
5346
10
      {
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
2
      case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */
5377
         /* ALPHA_R_REFLONG und_section, step 2 */
5378
2
        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
2
        if (length < 8)
5390
1
    goto bad_rec;
5391
1
        cur_addend = bfd_getl32 (ptr + 4);
5392
1
        prev_cmd = cmd;
5393
1
        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
2
      default:
5516
2
        _bfd_error_handler (_("unknown reloc %s"),
5517
2
          _bfd_vms_etir_name (cmd));
5518
2
        goto fail;
5519
10
      }
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 >= 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
6
    }
5624
2
  vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n"));
5625
2
  PRIV (reloc_done) = 1;
5626
2
  return true;
5627
5628
8
fail:
5629
8
  PRIV (reloc_done) = -1;
5630
8
  return false;
5631
10
}
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
10
{
5639
10
  if (!alpha_vms_slurp_relocs (abfd))
5640
8
    return -1;
5641
5642
2
  return (section->reloc_count + 1L) * sizeof (arelent *);
5643
10
}
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
180
{
6041
180
  asymbol *syms;
6042
180
  unsigned int i;
6043
180
  unsigned int n = 0;
6044
6045
180
  syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
6046
180
  *ret = syms;
6047
180
  if (syms == NULL)
6048
0
    return -1;
6049
6050
180
  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
180
  return n;
6099
180
}
6100

6101
/* Private dump.  */
6102
6103
static const char *
6104
vms_time_to_str (unsigned char *buf)
6105
119
{
6106
119
  time_t t = vms_rawtime_to_time_t (buf);
6107
119
  char *res = ctime (&t);
6108
6109
119
  if (!res)
6110
0
    res = "*invalid time*";
6111
119
  else
6112
119
    res[24] = 0;
6113
119
  return res;
6114
119
}
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
231
{
7026
301
  while (off <= buf_size - 8)
7027
83
    {
7028
83
      unsigned int base;
7029
83
      unsigned int count;
7030
83
      unsigned int j;
7031
7032
83
      count = bfd_getl32 (buf + off + 0);
7033
7034
83
      if (count == 0)
7035
13
  break;
7036
70
      base = bfd_getl32 (buf + off + 4);
7037
7038
      /* xgettext:c-format */
7039
70
      fprintf (file, _("  bitcount: %u, base addr: 0x%08x\n"),
7040
70
         count, base);
7041
7042
70
      off += 8;
7043
31.7k
      for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32)
7044
31.6k
  {
7045
31.6k
    unsigned int k;
7046
31.6k
    unsigned int n = 0;
7047
31.6k
    unsigned int val;
7048
7049
31.6k
    val = bfd_getl32 (buf + off);
7050
31.6k
    off += 4;
7051
7052
    /* xgettext:c-format */
7053
31.6k
    fprintf (file, _("   bitmap: 0x%08x (count: %u):\n"), val, count);
7054
7055
1.04M
    for (k = 0; k < 32; k++)
7056
1.01M
      if (val & (1u << k))
7057
171k
        {
7058
171k
    if (n == 0)
7059
30.5k
      fputs ("   ", file);
7060
171k
    fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
7061
171k
    n++;
7062
171k
    if (n == 8)
7063
14.2k
      {
7064
14.2k
        fputs ("\n", file);
7065
14.2k
        n = 0;
7066
14.2k
      }
7067
171k
        }
7068
31.6k
    if (n)
7069
16.2k
      fputs ("\n", file);
7070
31.6k
  }
7071
70
    }
7072
231
}
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
238
{
7078
326
  while (off <= buf_size - 8)
7079
125
    {
7080
125
      unsigned int j;
7081
125
      unsigned int count;
7082
7083
125
      count = bfd_getl32 (buf + off + 0);
7084
125
      if (count == 0)
7085
37
  return;
7086
      /* xgettext:c-format */
7087
88
      fprintf (file, _("  image %u (%u entries)\n"),
7088
88
         (unsigned) bfd_getl32 (buf + off + 4), count);
7089
88
      off += 8;
7090
15.7k
      for (j = 0; j < count && off <= buf_size - 8; j++)
7091
15.6k
  {
7092
    /* xgettext:c-format */
7093
15.6k
    fprintf (file, _("   offset: 0x%08x, val: 0x%08x\n"),
7094
15.6k
       (unsigned) bfd_getl32 (buf + off + 0),
7095
15.6k
       (unsigned) bfd_getl32 (buf + off + 4));
7096
15.6k
    off += 8;
7097
15.6k
  }
7098
88
    }
7099
238
}
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
229
{
7105
229
  unsigned int count;
7106
7107
376
  while (off <= buf_size - 8)
7108
209
    {
7109
209
      unsigned int j;
7110
209
      unsigned int n = 0;
7111
7112
209
      count = bfd_getl32 (buf + off + 0);
7113
209
      if (count == 0)
7114
62
  break;
7115
      /* xgettext:c-format */
7116
147
      fprintf (file, _("  image %u (%u entries), offsets:\n"),
7117
147
         (unsigned) bfd_getl32 (buf + off + 4), count);
7118
147
      off += 8;
7119
49.0k
      for (j = 0; j < count && off <= buf_size - 4; j++)
7120
48.8k
  {
7121
48.8k
    if (n == 0)
7122
7.05k
      fputs ("   ", file);
7123
48.8k
    fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off));
7124
48.8k
    n++;
7125
48.8k
    if (n == 7)
7126
6.92k
      {
7127
6.92k
        fputs ("\n", file);
7128
6.92k
        n = 0;
7129
6.92k
      }
7130
48.8k
    off += 4;
7131
48.8k
  }
7132
147
      if (n)
7133
131
  fputs ("\n", file);
7134
147
    }
7135
229
}
7136
7137
static void
7138
evax_bfd_print_indent (int indent, FILE *file)
7139
114
{
7140
572
  for (; indent; indent--)
7141
458
    fputc (' ', file);
7142
114
}
7143
7144
static const char *
7145
evax_bfd_get_dsc_name (unsigned int v)
7146
132
{
7147
132
  switch (v)
7148
132
    {
7149
0
    case DSC__K_DTYPE_Z:
7150
0
      return "Z (Unspecified)";
7151
6
    case DSC__K_DTYPE_V:
7152
6
      return "V (Bit)";
7153
1
    case DSC__K_DTYPE_BU:
7154
1
      return "BU (Byte logical)";
7155
1
    case DSC__K_DTYPE_WU:
7156
1
      return "WU (Word logical)";
7157
1
    case DSC__K_DTYPE_LU:
7158
1
      return "LU (Longword logical)";
7159
12
    case DSC__K_DTYPE_QU:
7160
12
      return "QU (Quadword logical)";
7161
1
    case DSC__K_DTYPE_B:
7162
1
      return "B (Byte integer)";
7163
4
    case DSC__K_DTYPE_W:
7164
4
      return "W (Word integer)";
7165
3
    case DSC__K_DTYPE_L:
7166
3
      return "L (Longword integer)";
7167
71
    case DSC__K_DTYPE_Q:
7168
71
      return "Q (Quadword integer)";
7169
3
    case DSC__K_DTYPE_F:
7170
3
      return "F (Single-precision floating)";
7171
2
    case DSC__K_DTYPE_D:
7172
2
      return "D (Double-precision floating)";
7173
0
    case DSC__K_DTYPE_FC:
7174
0
      return "FC (Complex)";
7175
2
    case DSC__K_DTYPE_DC:
7176
2
      return "DC (Double-precision Complex)";
7177
3
    case DSC__K_DTYPE_T:
7178
3
      return "T (ASCII text string)";
7179
0
    case DSC__K_DTYPE_NU:
7180
0
      return "NU (Numeric string, unsigned)";
7181
1
    case DSC__K_DTYPE_NL:
7182
1
      return "NL (Numeric string, left separate sign)";
7183
1
    case DSC__K_DTYPE_NLO:
7184
1
      return "NLO (Numeric string, left overpunched sign)";
7185
1
    case DSC__K_DTYPE_NR:
7186
1
      return "NR (Numeric string, right separate sign)";
7187
1
    case DSC__K_DTYPE_NRO:
7188
1
      return "NRO (Numeric string, right overpunched sig)";
7189
1
    case DSC__K_DTYPE_NZ:
7190
1
      return "NZ (Numeric string, zoned sign)";
7191
2
    case DSC__K_DTYPE_P:
7192
2
      return "P (Packed decimal string)";
7193
0
    case DSC__K_DTYPE_ZI:
7194
0
      return "ZI (Sequence of instructions)";
7195
4
    case DSC__K_DTYPE_ZEM:
7196
4
      return "ZEM (Procedure entry mask)";
7197
1
    case DSC__K_DTYPE_DSC:
7198
1
      return "DSC (Descriptor, used for arrays of dyn strings)";
7199
4
    case DSC__K_DTYPE_OU:
7200
4
      return "OU (Octaword logical)";
7201
1
    case DSC__K_DTYPE_O:
7202
1
      return "O (Octaword integer)";
7203
1
    case DSC__K_DTYPE_G:
7204
1
      return "G (Double precision G floating, 64 bit)";
7205
1
    case DSC__K_DTYPE_H:
7206
1
      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
1
    case DSC__K_DTYPE_CIT:
7212
1
      return "CIT (COBOL intermediate temporary)";
7213
1
    case DSC__K_DTYPE_BPV:
7214
1
      return "BPV (Bound Procedure Value)";
7215
0
    case DSC__K_DTYPE_BLV:
7216
0
      return "BLV (Bound Label Value)";
7217
1
    case DSC__K_DTYPE_VU:
7218
1
      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
132
    }
7230
132
}
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
134
{
7340
134
  if (bufsize < 5)
7341
22
    return bufsize;
7342
7343
112
  unsigned int vflags = buf[0];
7344
112
  unsigned int value = (unsigned) bfd_getl32 (buf + 1);
7345
112
  unsigned int len = 5;
7346
7347
112
  evax_bfd_print_indent (indent, file);
7348
  /* xgettext:c-format */
7349
112
  fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
7350
112
  buf += 5;
7351
112
  bufsize -= 5;
7352
7353
112
  switch (vflags)
7354
112
    {
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
1
    case DST__K_VFLAGS_TVS:
7370
1
      fprintf (file, _("(trailing value)\n"));
7371
1
      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
109
    default:
7379
      /* xgettext:c-format */
7380
109
      fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
7381
109
         (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
7382
109
         vflags & DST__K_DISP ? 1 : 0,
7383
109
         vflags & DST__K_INDIR ? 1 : 0);
7384
109
      switch (vflags & DST__K_VALKIND_MASK)
7385
109
  {
7386
11
  case DST__K_VALKIND_LITERAL:
7387
11
    fputs (_("literal"), file);
7388
11
    break;
7389
17
  case DST__K_VALKIND_ADDR:
7390
17
    fputs (_("address"), file);
7391
17
    break;
7392
0
  case DST__K_VALKIND_DESC:
7393
0
    fputs (_("desc"), file);
7394
0
    break;
7395
81
  case DST__K_VALKIND_REG:
7396
81
    fputs (_("reg"), file);
7397
81
    break;
7398
109
  }
7399
109
      fputs (")\n", file);
7400
109
      break;
7401
112
    }
7402
112
  return len;
7403
112
}
7404
7405
static void
7406
evax_bfd_print_typspec (const unsigned char *buf, unsigned int bufsize,
7407
      int indent, FILE *file)
7408
2
{
7409
2
  if (bufsize < 3)
7410
0
    return;
7411
7412
2
  unsigned char kind = buf[2];
7413
2
  unsigned int len = (unsigned) bfd_getl16 (buf);
7414
7415
2
  evax_bfd_print_indent (indent, file);
7416
  /* xgettext:c-format */
7417
2
  fprintf (file, _("len: %2u, kind: %2u "), len, kind);
7418
2
  buf += 3;
7419
2
  bufsize -= 3;
7420
2
  switch (kind)
7421
2
    {
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
2
    default:
7491
2
      fprintf (file, _("*unhandled*\n"));
7492
2
    }
7493
2
}
7494
7495
static void
7496
evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
7497
50
{
7498
50
  unsigned int off = 0;
7499
50
  unsigned int pc = 0;
7500
50
  unsigned int line = 0;
7501
7502
50
  fprintf (file, _("Debug symbol table:\n"));
7503
7504
346
  while (dst_size > 0)
7505
338
    {
7506
338
      struct vms_dst_header dsth;
7507
338
      unsigned int len;
7508
338
      unsigned int type;
7509
338
      unsigned char *buf;
7510
7511
338
      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
335
      len = bfd_getl16 (dsth.length);
7517
335
      type = bfd_getl16 (dsth.type);
7518
      /* xgettext:c-format */
7519
335
      fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
7520
335
         type, len, off);
7521
      /* !!! The length is short by one!  */
7522
335
      len++;
7523
335
      if (len > dst_size)
7524
5
  len = dst_size;
7525
335
      if (len < sizeof (dsth))
7526
12
  {
7527
12
    fputc ('\n', file);
7528
12
    break;
7529
12
  }
7530
323
      dst_size -= len;
7531
323
      off += len;
7532
323
      len -= sizeof (dsth);
7533
323
      if (len == 0)
7534
3
  buf = NULL;
7535
320
      else
7536
320
  {
7537
320
    buf = _bfd_malloc_and_read (abfd, len, len);
7538
320
    if (buf == NULL)
7539
27
      {
7540
27
        fprintf (file, _("cannot read DST symbol\n"));
7541
27
        return;
7542
27
      }
7543
320
  }
7544
296
      switch (type)
7545
296
  {
7546
6
  case DSC__K_DTYPE_V:
7547
7
  case DSC__K_DTYPE_BU:
7548
8
  case DSC__K_DTYPE_WU:
7549
9
  case DSC__K_DTYPE_LU:
7550
21
  case DSC__K_DTYPE_QU:
7551
22
  case DSC__K_DTYPE_B:
7552
26
  case DSC__K_DTYPE_W:
7553
29
  case DSC__K_DTYPE_L:
7554
100
  case DSC__K_DTYPE_Q:
7555
103
  case DSC__K_DTYPE_F:
7556
105
  case DSC__K_DTYPE_D:
7557
105
  case DSC__K_DTYPE_FC:
7558
107
  case DSC__K_DTYPE_DC:
7559
110
  case DSC__K_DTYPE_T:
7560
110
  case DSC__K_DTYPE_NU:
7561
111
  case DSC__K_DTYPE_NL:
7562
112
  case DSC__K_DTYPE_NLO:
7563
113
  case DSC__K_DTYPE_NR:
7564
114
  case DSC__K_DTYPE_NRO:
7565
115
  case DSC__K_DTYPE_NZ:
7566
117
  case DSC__K_DTYPE_P:
7567
117
  case DSC__K_DTYPE_ZI:
7568
121
  case DSC__K_DTYPE_ZEM:
7569
122
  case DSC__K_DTYPE_DSC:
7570
126
  case DSC__K_DTYPE_OU:
7571
127
  case DSC__K_DTYPE_O:
7572
128
  case DSC__K_DTYPE_G:
7573
129
  case DSC__K_DTYPE_H:
7574
129
  case DSC__K_DTYPE_GC:
7575
129
  case DSC__K_DTYPE_HC:
7576
130
  case DSC__K_DTYPE_CIT:
7577
131
  case DSC__K_DTYPE_BPV:
7578
131
  case DSC__K_DTYPE_BLV:
7579
132
  case DSC__K_DTYPE_VU:
7580
132
  case DSC__K_DTYPE_ADT:
7581
132
  case DSC__K_DTYPE_VT:
7582
132
  case DSC__K_DTYPE_T2:
7583
132
  case DSC__K_DTYPE_VT2:
7584
132
    fprintf (file, _("standard data: %s\n"),
7585
132
       evax_bfd_get_dsc_name (type));
7586
132
    evax_bfd_print_valspec (buf, len, 4, file);
7587
132
    if (len > 6)
7588
98
      fprintf (file, _("    name: %.*s\n"),
7589
98
         buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7590
132
    break;
7591
0
  case DST__K_MODBEG:
7592
0
    {
7593
0
      struct vms_dst_modbeg *dst = (void *)buf;
7594
0
      unsigned char *name = buf + sizeof (*dst);
7595
7596
0
      fprintf (file, _("modbeg\n"));
7597
0
      if (len < sizeof (*dst))
7598
0
        break;
7599
      /* xgettext:c-format */
7600
0
      fprintf (file, _("   flags: %d, language: %u, "
7601
0
           "major: %u, minor: %u\n"),
7602
0
         dst->flags,
7603
0
         (unsigned)bfd_getl32 (dst->language),
7604
0
         (unsigned)bfd_getl16 (dst->major),
7605
0
         (unsigned)bfd_getl16 (dst->minor));
7606
0
      len -= sizeof (*dst);
7607
0
      if (len > 0)
7608
0
        {
7609
0
    int nlen = len - 1;
7610
0
    fprintf (file, _("   module name: %.*s\n"),
7611
0
       name[0] > nlen ? nlen : name[0], name + 1);
7612
0
    if (name[0] < nlen)
7613
0
      {
7614
0
        len -= name[0] + 1;
7615
0
        name += name[0] + 1;
7616
0
        nlen = len - 1;
7617
0
        fprintf (file, _("   compiler   : %.*s\n"),
7618
0
           name[0] > nlen ? nlen : name[0], name + 1);
7619
0
      }
7620
0
        }
7621
0
    }
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
1
  case DST__K_RTNEND:
7651
1
    {
7652
1
      struct vms_dst_rtnend *dst = (void *)buf;
7653
7654
1
      if (len >= sizeof (*dst))
7655
1
        fprintf (file, _("rtnend: size 0x%08x\n"),
7656
1
           (unsigned) bfd_getl32 (dst->size));
7657
1
    }
7658
1
    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
2
  case DST__K_TYPSPEC:
7707
2
    {
7708
2
      fprintf (file, _("typspec (len: %u)\n"), len);
7709
2
      if (len >= 1)
7710
2
        {
7711
2
    int nlen = len - 1;
7712
2
    fprintf (file, _("    name: %.*s\n"),
7713
2
       buf[0] > nlen ? nlen : buf[0], buf + 1);
7714
2
    if (nlen > buf[0])
7715
2
      evax_bfd_print_typspec (buf + 1 + buf[0], len - (1 + buf[0]),
7716
2
            5, file);
7717
2
        }
7718
2
    }
7719
2
    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
2
  case DST__K_RECBEG:
7731
2
    {
7732
2
      struct vms_dst_recbeg *recbeg = (void *)buf;
7733
7734
2
      if (len > sizeof (*recbeg))
7735
2
        {
7736
2
    unsigned char *name = buf + sizeof (*recbeg);
7737
2
    int nlen = len - sizeof (*recbeg) - 1;
7738
7739
2
    if (name[0] < nlen)
7740
0
      nlen = name[0];
7741
2
    fprintf (file, _("recbeg: name: %.*s\n"), nlen, name + 1);
7742
7743
2
    evax_bfd_print_valspec (buf, len, 4, file);
7744
7745
2
    len -= sizeof (*recbeg) + 1 + nlen;
7746
2
    if (len >= 4)
7747
0
      fprintf (file, _("    len: %u bits\n"),
7748
0
         (unsigned) bfd_getl32 (name + 1 + nlen));
7749
2
        }
7750
2
    }
7751
2
    break;
7752
1
  case DST__K_RECEND:
7753
1
    fprintf (file, _("recend\n"));
7754
1
    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
2
  case DST__K_LABEL:
7773
2
    {
7774
2
      struct vms_dst_label *lab = (void *)buf;
7775
2
      if (len >= sizeof (*lab))
7776
2
        {
7777
2
    fprintf (file, _("label, name: %.*s\n"),
7778
2
       lab->name[0] > len - 1 ? len - 1 : lab->name[0],
7779
2
       lab->name + 1);
7780
2
    fprintf (file, _("    address: 0x%08x\n"),
7781
2
       (unsigned) bfd_getl32 (lab->value));
7782
2
        }
7783
2
    }
7784
2
    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
1
  case DST__K_SOURCE:
7934
1
    {
7935
1
      unsigned char *buf_orig = buf;
7936
7937
1
      fprintf (file, _("source (len: %u)\n"), len);
7938
7939
1
      while (len > 0)
7940
1
        {
7941
1
    int cmd = *buf++;
7942
1
    int cmdlen = -1;
7943
7944
1
    len--;
7945
1
    switch (cmd)
7946
1
      {
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
1
      default:
8039
1
        fprintf (file, _("   *unhandled* cmd %u\n"), cmd);
8040
1
        break;
8041
1
      }
8042
1
    if (cmdlen < 0)
8043
1
      break;
8044
0
    len -= cmdlen;
8045
0
    buf += cmdlen;
8046
0
        }
8047
1
      buf = buf_orig;
8048
1
    }
8049
0
    break;
8050
155
  default:
8051
155
    fprintf (file, _("*unhandled* dst type %u\n"), type);
8052
155
    break;
8053
296
  }
8054
296
      free (buf);
8055
296
    }
8056
50
}
8057
8058
static void
8059
evax_bfd_print_image (bfd *abfd, FILE *file)
8060
198
{
8061
198
  struct vms_eihd eihd;
8062
198
  unsigned int rec_size, size;
8063
198
  const char *name;
8064
198
  unsigned int val;
8065
198
  unsigned int eiha_off;
8066
198
  unsigned int eihi_off;
8067
198
  unsigned int eihs_off;
8068
198
  unsigned int eisd_off;
8069
198
  unsigned int eihef_off = 0;
8070
198
  unsigned int eihnp_off = 0;
8071
198
  unsigned int dmt_vbn = 0;
8072
198
  unsigned int dmt_size = 0;
8073
198
  unsigned int dst_vbn = 0;
8074
198
  unsigned int dst_size = 0;
8075
198
  unsigned int gst_vbn = 0;
8076
198
  unsigned int gst_size = 0;
8077
198
  unsigned int eiaf_vbn = 0;
8078
198
  unsigned int eiaf_size = 0;
8079
198
  unsigned int eihvn_off;
8080
8081
198
  if (bfd_seek (abfd, 0, SEEK_SET)
8082
198
      || (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
198
  size = bfd_getl32 (eihd.size);
8088
  /* xgettext:c-format */
8089
198
  fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
8090
198
     size, (unsigned) bfd_getl32 (eihd.hdrblkcnt));
8091
198
  if (size > rec_size)
8092
16
    size = rec_size;
8093
  /* xgettext:c-format */
8094
198
  fprintf (file, _(" majorid: %u, minorid: %u\n"),
8095
198
     (unsigned)bfd_getl32 (eihd.majorid),
8096
198
     (unsigned)bfd_getl32 (eihd.minorid));
8097
8098
198
  val = (unsigned)bfd_getl32 (eihd.imgtype);
8099
198
  switch (val)
8100
198
    {
8101
1
    case EIHD__K_EXE:
8102
1
      name = _("executable");
8103
1
      break;
8104
0
    case EIHD__K_LIM:
8105
0
      name = _("linkable image");
8106
0
      break;
8107
197
    default:
8108
197
      name = _("unknown");
8109
197
      break;
8110
198
    }
8111
  /* xgettext:c-format */
8112
198
  fprintf (file, _(" image type: %u (%s)"), val, name);
8113
8114
198
  val = (unsigned)bfd_getl32 (eihd.subtype);
8115
198
  switch (val)
8116
198
    {
8117
8
    case EIHD__C_NATIVE:
8118
8
      name = _("native");
8119
8
      break;
8120
0
    case EIHD__C_CLI:
8121
0
      name = _("CLI");
8122
0
      break;
8123
190
    default:
8124
190
      name = _("unknown");
8125
190
      break;
8126
198
    }
8127
  /* xgettext:c-format */
8128
198
  fprintf (file, _(", subtype: %u (%s)\n"), val, name);
8129
8130
198
  eisd_off = bfd_getl32 (eihd.isdoff);
8131
198
  eiha_off = bfd_getl32 (eihd.activoff);
8132
198
  eihi_off = bfd_getl32 (eihd.imgidoff);
8133
198
  eihs_off = bfd_getl32 (eihd.symdbgoff);
8134
  /* xgettext:c-format */
8135
198
  fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
8136
198
       "imgid: %u, patch: %u\n"),
8137
198
     eisd_off, eiha_off, eihs_off, eihi_off,
8138
198
     (unsigned)bfd_getl32 (eihd.patchoff));
8139
198
  fprintf (file, _(" fixup info rva: "));
8140
198
  bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
8141
198
  fprintf (file, _(", symbol vector rva: "));
8142
198
  bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
8143
198
  eihvn_off = bfd_getl32 (eihd.version_array_off);
8144
198
  fprintf (file, _("\n"
8145
198
       " version array off: %u\n"),
8146
198
     eihvn_off);
8147
198
  fprintf (file,
8148
     /* xgettext:c-format */
8149
198
     _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
8150
198
     (unsigned)bfd_getl32 (eihd.imgiocnt),
8151
198
     (unsigned)bfd_getl32 (eihd.iochancnt),
8152
198
     (unsigned)bfd_getl32 (eihd.privreqs + 4),
8153
198
     (unsigned)bfd_getl32 (eihd.privreqs + 0));
8154
198
  val = (unsigned)bfd_getl32 (eihd.lnkflags);
8155
198
  fprintf (file, _(" linker flags: %08x:"), val);
8156
198
  if (val & EIHD__M_LNKDEBUG)
8157
55
    fprintf (file, " LNKDEBUG");
8158
198
  if (val & EIHD__M_LNKNOTFR)
8159
91
    fprintf (file, " LNKNOTFR");
8160
198
  if (val & EIHD__M_NOP0BUFS)
8161
64
    fprintf (file, " NOP0BUFS");
8162
198
  if (val & EIHD__M_PICIMG)
8163
69
    fprintf (file, " PICIMG");
8164
198
  if (val & EIHD__M_P0IMAGE)
8165
99
    fprintf (file, " P0IMAGE");
8166
198
  if (val & EIHD__M_DBGDMT)
8167
102
    fprintf (file, " DBGDMT");
8168
198
  if (val & EIHD__M_INISHR)
8169
57
    fprintf (file, " INISHR");
8170
198
  if (val & EIHD__M_XLATED)
8171
89
    fprintf (file, " XLATED");
8172
198
  if (val & EIHD__M_BIND_CODE_SEC)
8173
38
    fprintf (file, " BIND_CODE_SEC");
8174
198
  if (val & EIHD__M_BIND_DATA_SEC)
8175
30
    fprintf (file, " BIND_DATA_SEC");
8176
198
  if (val & EIHD__M_MKTHREADS)
8177
12
    fprintf (file, " MKTHREADS");
8178
198
  if (val & EIHD__M_UPCALLS)
8179
39
    fprintf (file, " UPCALLS");
8180
198
  if (val & EIHD__M_OMV_READY)
8181
39
    fprintf (file, " OMV_READY");
8182
198
  if (val & EIHD__M_EXT_BIND_SECT)
8183
24
    fprintf (file, " EXT_BIND_SECT");
8184
198
  fprintf (file, "\n");
8185
  /* xgettext:c-format */
8186
198
  fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
8187
198
       "match ctrl: %u, symvect_size: %u\n"),
8188
198
     (unsigned)bfd_getl32 (eihd.ident),
8189
198
     (unsigned)bfd_getl32 (eihd.sysver),
8190
198
     eihd.matchctl,
8191
198
     (unsigned)bfd_getl32 (eihd.symvect_size));
8192
198
  fprintf (file, _(" BPAGE: %u"),
8193
198
     (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
8194
198
  if (size >= (offsetof (struct vms_eihd, noopt_psect_off)
8195
198
         + sizeof (eihd.noopt_psect_off))
8196
114
      && (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT)))
8197
37
    {
8198
37
      eihef_off = bfd_getl32 (eihd.ext_fixup_off);
8199
37
      eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
8200
      /* xgettext:c-format */
8201
37
      fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
8202
37
         eihef_off, eihnp_off);
8203
37
    }
8204
198
  if (size >= offsetof (struct vms_eihd, alias) + sizeof (eihd.alias))
8205
114
    fprintf (file, _(", alias: %u"), (unsigned) bfd_getl16 (eihd.alias));
8206
198
  fprintf (file, "\n");
8207
8208
198
  if (eihvn_off != 0)
8209
133
    {
8210
133
      struct vms_eihvn eihvn;
8211
133
      unsigned int mask;
8212
133
      unsigned int j;
8213
8214
133
      fprintf (file, _("system version array information:\n"));
8215
133
      if (bfd_seek (abfd, eihvn_off, SEEK_SET)
8216
133
    || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
8217
4
  {
8218
4
    fprintf (file, _("cannot read EIHVN header\n"));
8219
4
    return;
8220
4
  }
8221
129
      mask = bfd_getl32 (eihvn.subsystem_mask);
8222
4.23k
      for (j = 0; j < 32; j++)
8223
4.11k
  if (mask & (1u << j))
8224
1.12k
    {
8225
1.12k
      struct vms_eihvn_subversion ver;
8226
1.12k
      if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver))
8227
2
        {
8228
2
    fprintf (file, _("cannot read EIHVN version\n"));
8229
2
    return;
8230
2
        }
8231
1.11k
      fprintf (file, _("   %02u "), j);
8232
1.11k
      switch (j)
8233
1.11k
        {
8234
37
        case EIHVN__BASE_IMAGE_BIT:
8235
37
    fputs (_("BASE_IMAGE       "), file);
8236
37
    break;
8237
38
        case EIHVN__MEMORY_MANAGEMENT_BIT:
8238
38
    fputs (_("MEMORY_MANAGEMENT"), file);
8239
38
    break;
8240
34
        case EIHVN__IO_BIT:
8241
34
    fputs (_("IO               "), file);
8242
34
    break;
8243
37
        case EIHVN__FILES_VOLUMES_BIT:
8244
37
    fputs (_("FILES_VOLUMES    "), file);
8245
37
    break;
8246
37
        case EIHVN__PROCESS_SCHED_BIT:
8247
37
    fputs (_("PROCESS_SCHED    "), file);
8248
37
    break;
8249
39
        case EIHVN__SYSGEN_BIT:
8250
39
    fputs (_("SYSGEN           "), file);
8251
39
    break;
8252
38
        case EIHVN__CLUSTERS_LOCKMGR_BIT:
8253
38
    fputs (_("CLUSTERS_LOCKMGR "), file);
8254
38
    break;
8255
31
        case EIHVN__LOGICAL_NAMES_BIT:
8256
31
    fputs (_("LOGICAL_NAMES    "), file);
8257
31
    break;
8258
39
        case EIHVN__SECURITY_BIT:
8259
39
    fputs (_("SECURITY         "), file);
8260
39
    break;
8261
34
        case EIHVN__IMAGE_ACTIVATOR_BIT:
8262
34
    fputs (_("IMAGE_ACTIVATOR  "), file);
8263
34
    break;
8264
34
        case EIHVN__NETWORKS_BIT:
8265
34
    fputs (_("NETWORKS         "), file);
8266
34
    break;
8267
34
        case EIHVN__COUNTERS_BIT:
8268
34
    fputs (_("COUNTERS         "), file);
8269
34
    break;
8270
31
        case EIHVN__STABLE_BIT:
8271
31
    fputs (_("STABLE           "), file);
8272
31
    break;
8273
31
        case EIHVN__MISC_BIT:
8274
31
    fputs (_("MISC             "), file);
8275
31
    break;
8276
31
        case EIHVN__CPU_BIT:
8277
31
    fputs (_("CPU              "), file);
8278
31
    break;
8279
31
        case EIHVN__VOLATILE_BIT:
8280
31
    fputs (_("VOLATILE         "), file);
8281
31
    break;
8282
33
        case EIHVN__SHELL_BIT:
8283
33
    fputs (_("SHELL            "), file);
8284
33
    break;
8285
40
        case EIHVN__POSIX_BIT:
8286
40
    fputs (_("POSIX            "), file);
8287
40
    break;
8288
35
        case EIHVN__MULTI_PROCESSING_BIT:
8289
35
    fputs (_("MULTI_PROCESSING "), file);
8290
35
    break;
8291
39
        case EIHVN__GALAXY_BIT:
8292
39
    fputs (_("GALAXY           "), file);
8293
39
    break;
8294
416
        default:
8295
416
    fputs (_("*unknown*        "), file);
8296
416
    break;
8297
1.11k
        }
8298
1.11k
      fprintf (file, ": %u.%u\n",
8299
1.11k
         (unsigned)bfd_getl16 (ver.major),
8300
1.11k
         (unsigned)bfd_getl16 (ver.minor));
8301
1.11k
    }
8302
129
    }
8303
8304
192
  if (eiha_off != 0)
8305
181
    {
8306
181
      struct vms_eiha eiha;
8307
8308
181
      if (bfd_seek (abfd, eiha_off, SEEK_SET)
8309
181
    || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
8310
11
  {
8311
11
    fprintf (file, _("cannot read EIHA\n"));
8312
11
    return;
8313
11
  }
8314
170
      fprintf (file, _("Image activation:  (size=%u)\n"),
8315
170
         (unsigned)bfd_getl32 (eiha.size));
8316
      /* xgettext:c-format */
8317
170
      fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
8318
170
         (unsigned)bfd_getl32 (eiha.tfradr1_h),
8319
170
         (unsigned)bfd_getl32 (eiha.tfradr1));
8320
      /* xgettext:c-format */
8321
170
      fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
8322
170
         (unsigned)bfd_getl32 (eiha.tfradr2_h),
8323
170
         (unsigned)bfd_getl32 (eiha.tfradr2));
8324
      /* xgettext:c-format */
8325
170
      fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
8326
170
         (unsigned)bfd_getl32 (eiha.tfradr3_h),
8327
170
         (unsigned)bfd_getl32 (eiha.tfradr3));
8328
      /* xgettext:c-format */
8329
170
      fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
8330
170
         (unsigned)bfd_getl32 (eiha.tfradr4_h),
8331
170
         (unsigned)bfd_getl32 (eiha.tfradr4));
8332
      /* xgettext:c-format */
8333
170
      fprintf (file, _(" Shared image  : 0x%08x 0x%08x\n"),
8334
170
         (unsigned)bfd_getl32 (eiha.inishr_h),
8335
170
         (unsigned)bfd_getl32 (eiha.inishr));
8336
170
    }
8337
181
  if (eihi_off != 0)
8338
119
    {
8339
119
      struct vms_eihi eihi;
8340
8341
119
      if (bfd_seek (abfd, eihi_off, SEEK_SET)
8342
119
    || 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
119
      fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
8349
119
         (unsigned) bfd_getl32 (eihi.majorid),
8350
119
         (unsigned) bfd_getl32 (eihi.minorid));
8351
119
      unsigned int nlen = eihi.imgnam[0];
8352
119
      if (nlen > sizeof (eihi.imgnam) - 1)
8353
28
  nlen = sizeof (eihi.imgnam) - 1;
8354
119
      fprintf (file, _(" image name       : %.*s\n"), nlen, eihi.imgnam + 1);
8355
119
      fprintf (file, _(" link time        : %s\n"),
8356
119
         vms_time_to_str (eihi.linktime));
8357
119
      nlen = eihi.imgid[0];
8358
119
      if (nlen > sizeof (eihi.imgid) - 1)
8359
20
  nlen = sizeof (eihi.imgid) - 1;
8360
119
      fprintf (file, _(" image ident      : %.*s\n"), nlen, eihi.imgid + 1);
8361
119
      nlen = eihi.linkid[0];
8362
119
      if (nlen > sizeof (eihi.linkid) - 1)
8363
38
  nlen = sizeof (eihi.linkid) - 1;
8364
119
      fprintf (file, _(" linker ident     : %.*s\n"), nlen, eihi.linkid + 1);
8365
119
      nlen = eihi.imgbid[0];
8366
119
      if (nlen > sizeof (eihi.imgbid) -1 )
8367
28
  nlen = sizeof (eihi.imgbid) - 1;
8368
119
      fprintf (file, _(" image build ident: %.*s\n"), nlen, eihi.imgbid + 1);
8369
119
    }
8370
181
  if (eihs_off != 0)
8371
65
    {
8372
65
      struct vms_eihs eihs;
8373
8374
65
      if (bfd_seek (abfd, eihs_off, SEEK_SET)
8375
65
    || 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
65
      fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
8382
65
         (unsigned)bfd_getl32 (eihs.majorid),
8383
65
         (unsigned)bfd_getl32 (eihs.minorid));
8384
65
      dst_vbn = bfd_getl32 (eihs.dstvbn);
8385
65
      dst_size = bfd_getl32 (eihs.dstsize);
8386
      /* xgettext:c-format */
8387
65
      fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"),
8388
65
         dst_vbn, dst_size, dst_size);
8389
65
      gst_vbn = bfd_getl32 (eihs.gstvbn);
8390
65
      gst_size = bfd_getl32 (eihs.gstsize);
8391
      /* xgettext:c-format */
8392
65
      fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
8393
65
         gst_vbn, gst_size);
8394
65
      dmt_vbn = bfd_getl32 (eihs.dmtvbn);
8395
65
      dmt_size = bfd_getl32 (eihs.dmtsize);
8396
      /* xgettext:c-format */
8397
65
      fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
8398
65
         dmt_vbn, dmt_size);
8399
65
    }
8400
363
  while (eisd_off != 0)
8401
363
    {
8402
363
      struct vms_eisd eisd;
8403
363
      unsigned int len;
8404
8405
363
      while (1)
8406
363
  {
8407
363
    if (bfd_seek (abfd, eisd_off, SEEK_SET)
8408
363
        || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
8409
0
      {
8410
0
        fprintf (file, _("cannot read EISD\n"));
8411
0
        return;
8412
0
      }
8413
363
    len = (unsigned)bfd_getl32 (eisd.eisdsize);
8414
363
    if (len != (unsigned)-1)
8415
363
      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
363
      fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
8422
363
           "size: %u, offset: %u)\n"),
8423
363
         (unsigned)bfd_getl32 (eisd.majorid),
8424
363
         (unsigned)bfd_getl32 (eisd.minorid),
8425
363
         len, eisd_off);
8426
363
      if (len == 0)
8427
181
  break;
8428
      /* xgettext:c-format */
8429
182
      fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
8430
182
         (unsigned)bfd_getl32 (eisd.virt_addr + 4),
8431
182
         (unsigned)bfd_getl32 (eisd.virt_addr + 0),
8432
182
         (unsigned)bfd_getl32 (eisd.secsize));
8433
182
      val = (unsigned)bfd_getl32 (eisd.flags);
8434
182
      fprintf (file, _(" flags: 0x%04x"), val);
8435
182
      if (val & EISD__M_GBL)
8436
46
  fprintf (file, " GBL");
8437
182
      if (val & EISD__M_CRF)
8438
44
  fprintf (file, " CRF");
8439
182
      if (val & EISD__M_DZRO)
8440
53
  fprintf (file, " DZRO");
8441
182
      if (val & EISD__M_WRT)
8442
51
  fprintf (file, " WRT");
8443
182
      if (val & EISD__M_INITALCODE)
8444
48
  fprintf (file, " INITALCODE");
8445
182
      if (val & EISD__M_BASED)
8446
49
  fprintf (file, " BASED");
8447
182
      if (val & EISD__M_FIXUPVEC)
8448
125
  fprintf (file, " FIXUPVEC");
8449
182
      if (val & EISD__M_RESIDENT)
8450
51
  fprintf (file, " RESIDENT");
8451
182
      if (val & EISD__M_VECTOR)
8452
81
  fprintf (file, " VECTOR");
8453
182
      if (val & EISD__M_PROTECT)
8454
64
  fprintf (file, " PROTECT");
8455
182
      if (val & EISD__M_LASTCLU)
8456
61
  fprintf (file, " LASTCLU");
8457
182
      if (val & EISD__M_EXE)
8458
59
  fprintf (file, " EXE");
8459
182
      if (val & EISD__M_NONSHRADR)
8460
60
  fprintf (file, " NONSHRADR");
8461
182
      if (val & EISD__M_QUAD_LENGTH)
8462
61
  fprintf (file, " QUAD_LENGTH");
8463
182
      if (val & EISD__M_ALLOC_64BIT)
8464
62
  fprintf (file, " ALLOC_64BIT");
8465
182
      fprintf (file, "\n");
8466
182
      if (val & EISD__M_FIXUPVEC)
8467
125
  {
8468
125
    eiaf_vbn = bfd_getl32 (eisd.vbn);
8469
125
    eiaf_size = bfd_getl32 (eisd.secsize);
8470
125
  }
8471
      /* xgettext:c-format */
8472
182
      fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
8473
182
         (unsigned)bfd_getl32 (eisd.vbn),
8474
182
         eisd.pfc, eisd.matchctl, eisd.type);
8475
182
      switch (eisd.type)
8476
182
  {
8477
135
  case EISD__K_NORMAL:
8478
135
    fputs (_("NORMAL"), file);
8479
135
    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
47
  default:
8496
47
    fputs (_("*unknown*"), file);
8497
47
    break;
8498
182
  }
8499
182
      fputs (_(")\n"), file);
8500
182
      if (val & EISD__M_GBL)
8501
46
  {
8502
46
    unsigned int nlen = eisd.gblnam[0];
8503
46
    if (nlen > sizeof (eisd.gblnam) - 1)
8504
0
      nlen = sizeof (eisd.gblnam) - 1;
8505
    /* xgettext:c-format */
8506
46
    fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
8507
46
       (unsigned) bfd_getl32 (eisd.ident),
8508
46
       nlen, eisd.gblnam + 1);
8509
46
  }
8510
182
      eisd_off += len;
8511
182
    }
8512
8513
181
  if (dmt_vbn != 0)
8514
19
    {
8515
19
      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
19
      fprintf (file, _("Debug module table:\n"));
8522
8523
134
      while (dmt_size > 0)
8524
130
  {
8525
130
    struct vms_dmt_header dmth;
8526
130
    unsigned int count;
8527
8528
130
    if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
8529
1
      {
8530
1
        fprintf (file, _("cannot read DMT header\n"));
8531
1
        return;
8532
1
      }
8533
129
    count = bfd_getl16 (dmth.psect_count);
8534
129
    fprintf (file,
8535
       /* xgettext:c-format */
8536
129
       _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"),
8537
129
       (unsigned)bfd_getl32 (dmth.modbeg),
8538
129
       (unsigned)bfd_getl32 (dmth.size), count);
8539
129
    dmt_size -= sizeof (dmth);
8540
2.17k
    while (count > 0)
8541
2.05k
      {
8542
2.05k
        struct vms_dmt_psect dmtp;
8543
8544
2.05k
        if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
8545
14
    {
8546
14
      fprintf (file, _("cannot read DMT psect\n"));
8547
14
      return;
8548
14
    }
8549
        /* xgettext:c-format */
8550
2.04k
        fprintf (file, _("  psect start: 0x%08x, length: %u\n"),
8551
2.04k
           (unsigned)bfd_getl32 (dmtp.start),
8552
2.04k
           (unsigned)bfd_getl32 (dmtp.length));
8553
2.04k
        count--;
8554
2.04k
        dmt_size -= sizeof (dmtp);
8555
2.04k
      }
8556
129
  }
8557
19
    }
8558
8559
166
  if (dst_vbn != 0)
8560
50
    {
8561
50
      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
50
      evax_bfd_print_dst (abfd, dst_size, file);
8568
50
    }
8569
166
  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
166
  if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf))
8581
124
    {
8582
124
      unsigned char *buf;
8583
124
      struct vms_eiaf *eiaf;
8584
124
      unsigned int qrelfixoff;
8585
124
      unsigned int lrelfixoff;
8586
124
      unsigned int qdotadroff;
8587
124
      unsigned int ldotadroff;
8588
124
      unsigned int shrimgcnt;
8589
124
      unsigned int shlstoff;
8590
124
      unsigned int codeadroff;
8591
124
      unsigned int lpfixoff;
8592
124
      unsigned int chgprtoff;
8593
124
      file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE;
8594
8595
124
      if (bfd_seek (abfd, f_off, SEEK_SET) != 0
8596
124
    || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL)
8597
3
  {
8598
3
    fprintf (file, _("cannot read EIHA\n"));
8599
3
    return;
8600
3
  }
8601
121
      eiaf = (struct vms_eiaf *)buf;
8602
121
      fprintf (file,
8603
         /* xgettext:c-format */
8604
121
         _("Image activator fixup: (major: %u, minor: %u)\n"),
8605
121
         (unsigned)bfd_getl32 (eiaf->majorid),
8606
121
         (unsigned)bfd_getl32 (eiaf->minorid));
8607
      /* xgettext:c-format */
8608
121
      fprintf (file, _("  iaflink : 0x%08x %08x\n"),
8609
121
         (unsigned)bfd_getl32 (eiaf->iaflink + 0),
8610
121
         (unsigned)bfd_getl32 (eiaf->iaflink + 4));
8611
      /* xgettext:c-format */
8612
121
      fprintf (file, _("  fixuplnk: 0x%08x %08x\n"),
8613
121
         (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
8614
121
         (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
8615
121
      fprintf (file, _("  size : %u\n"),
8616
121
         (unsigned)bfd_getl32 (eiaf->size));
8617
121
      fprintf (file, _("  flags: 0x%08x\n"),
8618
121
         (unsigned)bfd_getl32 (eiaf->flags));
8619
121
      qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
8620
121
      lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
8621
      /* xgettext:c-format */
8622
121
      fprintf (file, _("  qrelfixoff: %5u, lrelfixoff: %5u\n"),
8623
121
         qrelfixoff, lrelfixoff);
8624
121
      qdotadroff = bfd_getl32 (eiaf->qdotadroff);
8625
121
      ldotadroff = bfd_getl32 (eiaf->ldotadroff);
8626
      /* xgettext:c-format */
8627
121
      fprintf (file, _("  qdotadroff: %5u, ldotadroff: %5u\n"),
8628
121
         qdotadroff, ldotadroff);
8629
121
      codeadroff = bfd_getl32 (eiaf->codeadroff);
8630
121
      lpfixoff = bfd_getl32 (eiaf->lpfixoff);
8631
      /* xgettext:c-format */
8632
121
      fprintf (file, _("  codeadroff: %5u, lpfixoff  : %5u\n"),
8633
121
         codeadroff, lpfixoff);
8634
121
      chgprtoff = bfd_getl32 (eiaf->chgprtoff);
8635
121
      fprintf (file, _("  chgprtoff : %5u\n"), chgprtoff);
8636
121
      shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
8637
121
      shlstoff = bfd_getl32 (eiaf->shlstoff);
8638
      /* xgettext:c-format */
8639
121
      fprintf (file, _("  shlstoff  : %5u, shrimgcnt : %5u\n"),
8640
121
         shlstoff, shrimgcnt);
8641
      /* xgettext:c-format */
8642
121
      fprintf (file, _("  shlextra  : %5u, permctx   : %5u\n"),
8643
121
         (unsigned)bfd_getl32 (eiaf->shlextra),
8644
121
         (unsigned)bfd_getl32 (eiaf->permctx));
8645
121
      fprintf (file, _("  base_va : 0x%08x\n"),
8646
121
         (unsigned)bfd_getl32 (eiaf->base_va));
8647
121
      fprintf (file, _("  lppsbfixoff: %5u\n"),
8648
121
         (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
8649
8650
121
      if (shlstoff)
8651
120
  {
8652
120
    unsigned int j;
8653
8654
120
    fprintf (file, _(" Shareable images:\n"));
8655
120
    for (j = 0;
8656
2.57k
         j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl);
8657
2.45k
         j++, shlstoff += sizeof (struct vms_shl))
8658
2.45k
      {
8659
2.45k
        struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff);
8660
2.45k
        unsigned int nlen = shl->imgnam[0];
8661
2.45k
        if (nlen > sizeof (shl->imgnam) - 1)
8662
636
    nlen = sizeof (shl->imgnam) - 1;
8663
2.45k
        fprintf (file,
8664
           /* xgettext:c-format */
8665
2.45k
           _("  %u: size: %u, flags: 0x%02x, name: %.*s\n"),
8666
2.45k
           j, shl->size, shl->flags,
8667
2.45k
           nlen, shl->imgnam + 1);
8668
2.45k
      }
8669
120
  }
8670
121
      if (qrelfixoff != 0)
8671
112
  {
8672
112
    fprintf (file, _(" quad-word relocation fixups:\n"));
8673
112
    evax_bfd_print_relocation_records (file, buf, eiaf_size,
8674
112
               qrelfixoff, 8);
8675
112
  }
8676
121
      if (lrelfixoff != 0)
8677
119
  {
8678
119
    fprintf (file, _(" long-word relocation fixups:\n"));
8679
119
    evax_bfd_print_relocation_records (file, buf, eiaf_size,
8680
119
               lrelfixoff, 4);
8681
119
  }
8682
121
      if (qdotadroff != 0)
8683
118
  {
8684
118
    fprintf (file, _(" quad-word .address reference fixups:\n"));
8685
118
    evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff);
8686
118
  }
8687
121
      if (ldotadroff != 0)
8688
120
  {
8689
120
    fprintf (file, _(" long-word .address reference fixups:\n"));
8690
120
    evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff);
8691
120
  }
8692
121
      if (codeadroff != 0)
8693
117
  {
8694
117
    fprintf (file, _(" Code Address Reference Fixups:\n"));
8695
117
    evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff);
8696
117
  }
8697
121
      if (lpfixoff != 0)
8698
112
  {
8699
112
    fprintf (file, _(" Linkage Pairs Reference Fixups:\n"));
8700
112
    evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff);
8701
112
  }
8702
121
      if (chgprtoff && chgprtoff <= eiaf_size - 4)
8703
91
  {
8704
91
    unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff);
8705
91
    unsigned int j;
8706
8707
91
    fprintf (file, _(" Change Protection (%u entries):\n"), count);
8708
91
    for (j = 0, chgprtoff += 4;
8709
8.54k
         j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp);
8710
8.44k
         j++, chgprtoff += sizeof (struct vms_eicp))
8711
8.44k
      {
8712
8.44k
        struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff);
8713
8.44k
        unsigned int prot = bfd_getl32 (eicp->newprt);
8714
8.44k
        fprintf (file,
8715
           /* xgettext:c-format */
8716
8.44k
           _("  base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
8717
8.44k
           (unsigned) bfd_getl32 (eicp->baseva + 4),
8718
8.44k
           (unsigned) bfd_getl32 (eicp->baseva + 0),
8719
8.44k
           (unsigned) bfd_getl32 (eicp->size),
8720
8.44k
           (unsigned) bfd_getl32 (eicp->newprt));
8721
8.44k
        switch (prot)
8722
8.44k
    {
8723
2.29k
    case PRT__C_NA:
8724
2.29k
      fprintf (file, "NA");
8725
2.29k
      break;
8726
143
    case PRT__C_RESERVED:
8727
143
      fprintf (file, "RES");
8728
143
      break;
8729
73
    case PRT__C_KW:
8730
73
      fprintf (file, "KW");
8731
73
      break;
8732
79
    case PRT__C_KR:
8733
79
      fprintf (file, "KR");
8734
79
      break;
8735
51
    case PRT__C_UW:
8736
51
      fprintf (file, "UW");
8737
51
      break;
8738
52
    case PRT__C_EW:
8739
52
      fprintf (file, "EW");
8740
52
      break;
8741
36
    case PRT__C_ERKW:
8742
36
      fprintf (file, "ERKW");
8743
36
      break;
8744
31
    case PRT__C_ER:
8745
31
      fprintf (file, "ER");
8746
31
      break;
8747
50
    case PRT__C_SW:
8748
50
      fprintf (file, "SW");
8749
50
      break;
8750
30
    case PRT__C_SREW:
8751
30
      fprintf (file, "SREW");
8752
30
      break;
8753
18
    case PRT__C_SRKW:
8754
18
      fprintf (file, "SRKW");
8755
18
      break;
8756
41
    case PRT__C_SR:
8757
41
      fprintf (file, "SR");
8758
41
      break;
8759
47
    case PRT__C_URSW:
8760
47
      fprintf (file, "URSW");
8761
47
      break;
8762
41
    case PRT__C_UREW:
8763
41
      fprintf (file, "UREW");
8764
41
      break;
8765
38
    case PRT__C_URKW:
8766
38
      fprintf (file, "URKW");
8767
38
      break;
8768
7
    case PRT__C_UR:
8769
7
      fprintf (file, "UR");
8770
7
      break;
8771
5.41k
    default:
8772
5.41k
      fputs ("??", file);
8773
5.41k
      break;
8774
8.44k
    }
8775
8.44k
        fputc ('\n', file);
8776
8.44k
      }
8777
91
  }
8778
121
      free (buf);
8779
121
    }
8780
166
}
8781
8782
static bool
8783
vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
8784
198
{
8785
198
  FILE *file = (FILE *)ptr;
8786
8787
198
  if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
8788
198
    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
198
  return true;
8796
198
}
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
125
{
8805
125
  asection *cur_section;
8806
125
  file_ptr cur_offset;
8807
125
  asection *dst_section;
8808
125
  file_ptr dst_offset;
8809
8810
125
  if (bfd_seek (abfd, 0, SEEK_SET) != 0)
8811
0
    return false;
8812
8813
125
  cur_section = NULL;
8814
125
  cur_offset = 0;
8815
8816
125
  dst_section = PRIV (dst_section);
8817
125
  dst_offset = 0;
8818
125
  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
125
  while (1)
8834
125
    {
8835
125
      int type;
8836
125
      bool res;
8837
8838
125
      type = _bfd_vms_get_object_record (abfd);
8839
125
      if (type < 0)
8840
125
  {
8841
125
    vms_debug2 ((2, "next_record failed\n"));
8842
125
    return false;
8843
125
  }
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
125
}
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
589
{
9897
  /* Handle image sections.  */
9898
589
  if (section->filepos != 0
9899
125
      || (section->flags & SEC_HAS_CONTENTS) == 0)
9900
464
    return _bfd_generic_get_section_contents (abfd, section,
9901
464
                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
125
  if (offset + count < count
9909
125
      || offset + count > section->size)
9910
0
    {
9911
0
      bfd_set_error (bfd_error_invalid_operation);
9912
0
      return false;
9913
0
    }
9914
9915
125
  if (section->size == 0)
9916
0
    return true;
9917
9918
  /* If we haven't yet read ETIR/EDBG/ETBT records, do so.  */
9919
125
  if ((section->flags & SEC_IN_MEMORY) == 0)
9920
125
    {
9921
      /* Alloc memory and read ETIRs.  */
9922
293
      for (asection *sec = abfd->sections; sec; sec = sec->next)
9923
168
  {
9924
168
    if (sec->size != 0
9925
148
        && sec->filepos == 0
9926
132
        && (sec->flags & SEC_HAS_CONTENTS) != 0)
9927
126
      {
9928
126
        BFD_ASSERT (sec->contents == NULL);
9929
9930
126
        sec->contents = bfd_zalloc (abfd, sec->size);
9931
126
        sec->flags |= SEC_IN_MEMORY;
9932
126
        if (sec->contents == NULL)
9933
0
    return false;
9934
126
        sec->alloced = 1;
9935
126
      }
9936
168
  }
9937
125
      if (!alpha_vms_read_sections_content (abfd, NULL))
9938
125
  return false;
9939
125
    }
9940
9941
0
  BFD_ASSERT (section->contents != NULL);
9942
0
  memcpy (buf, section->contents + offset, count);
9943
0
  return true;
9944
125
}
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
345
{
9983
345
  vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
9984
9985
345
  if (abfd == NULL || abfd->tdata.any == NULL)
9986
0
    return true;
9987
9988
345
  if (abfd->format == bfd_object)
9989
329
    {
9990
329
      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
329
    }
10004
10005
345
  return _bfd_generic_close_and_cleanup (abfd);
10006
345
}
10007
10008
/* Called when a new section is created.  */
10009
10010
static bool
10011
vms_new_section_hook (bfd * abfd, asection *section)
10012
1.89k
{
10013
1.89k
  size_t amt;
10014
10015
1.89k
  vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n",
10016
1.89k
         abfd, section->index, section->name));
10017
10018
1.89k
  if (!bfd_set_section_alignment (section, 0))
10019
0
    return false;
10020
10021
1.89k
  vms_debug2 ((7, "%u: %s\n", section->index, section->name));
10022
10023
1.89k
  amt = sizeof (struct vms_section_data_struct);
10024
1.89k
  section->used_by_bfd = bfd_zalloc (abfd, amt);
10025
1.89k
  if (section->used_by_bfd == NULL)
10026
0
    return false;
10027
10028
  /* Create the section symbol.  */
10029
1.89k
  return _bfd_generic_new_section_hook (abfd, section);
10030
1.89k
}
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
66
{
10086
66
  asection *sec;
10087
10088
66
  vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret));
10089
10090
66
  sec = symbol->section;
10091
10092
66
  if (ret == NULL)
10093
0
    return;
10094
10095
66
  if (sec == NULL)
10096
0
    ret->type = 'U';
10097
66
  else if (bfd_is_com_section (sec))
10098
0
    ret->type = 'C';
10099
66
  else if (bfd_is_abs_section (sec))
10100
0
    ret->type = 'A';
10101
66
  else if (bfd_is_und_section (sec))
10102
66
    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
66
  if (ret->type != 'U')
10116
0
    ret->value = symbol->value + symbol->section->vma;
10117
66
  else
10118
66
    ret->value = 0;
10119
66
  ret->name = symbol->name;
10120
66
}
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
14
{
10171
14
  if (arch != bfd_arch_alpha
10172
0
      && arch != bfd_arch_unknown)
10173
0
    return false;
10174
10175
14
  return bfd_default_set_arch_mach (abfd, arch, mach);
10176
14
}
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
};