Coverage Report

Created: 2026-04-04 08:16

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