Coverage Report

Created: 2023-06-29 07:06

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