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