Add translations for various sub-directories
[binutils-gdb.git] / bfd / vms-alpha.c
blob548a97901003069457f90d21ec310c877fe6cf91
1 /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files.
2 Copyright (C) 1996-2025 Free Software Foundation, Inc.
4 Initial version written by Klaus Kaempf (kkaempf@rmi.de)
5 Major rewrite by Adacore.
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.
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.
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. */
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 ...
36 #include "sysdep.h"
37 #include <limits.h>
38 #include "bfd.h"
39 #include "bfdlink.h"
40 #include "libbfd.h"
41 #include "bfdver.h"
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"
74 #define MIN(a,b) ((a) < (b) ? (a) : (b))
75 #ifndef CHAR_BIT
76 #define CHAR_BIT 8
77 #endif
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
99 /* These are used with DST_S_C_LINE_NUM. */
100 #define DST_S_C_LINE_NUM_HEADER_SIZE 4
102 /* These are used with DST_S_C_SOURCE */
104 #define DST_S_B_PCLINE_UNSBYTE 1
105 #define DST_S_W_PCLINE_UNSWORD 1
106 #define DST_S_L_PCLINE_UNSLONG 1
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
113 /* These are used with DST_S_C_SOURCE. */
114 #define DST_S_C_SOURCE_HEADER_SIZE 4
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
123 /* Debugger symbol definitions. */
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
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
134 /* VMS module header. */
136 struct hdr_struct
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;
150 #define EMH_DATE_LENGTH 17
152 /* VMS End-Of-Module records (EOM/EEOM). */
154 struct eom_struct
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;
164 struct vms_symbol_entry
166 bfd *owner;
168 /* Common fields. */
169 unsigned char typ;
170 unsigned char data_type;
171 unsigned short flags;
173 /* Section and offset/value of the symbol. */
174 unsigned int value;
175 asection *section;
177 /* Section and offset/value for the entry point (only for subprg). */
178 asection *code_section;
179 unsigned int code_value;
181 /* Symbol vector offset. */
182 unsigned int symbol_vector;
184 /* Length of the name. */
185 unsigned char namelen;
187 char name[1];
190 /* Stack value for push/pop commands. */
192 struct stack_struct
194 bfd_vma value;
195 unsigned int reloc;
198 #define STACKSIZE 128
200 /* A minimal decoding of DST compilation units. We only decode
201 what's needed to get to the line number information. */
203 struct fileinfo
205 char *name;
206 unsigned int srec;
209 struct srecinfo
211 struct srecinfo *next;
212 unsigned int line;
213 unsigned int sfile;
214 unsigned int srec;
217 struct lineinfo
219 struct lineinfo *next;
220 bfd_vma address;
221 unsigned int line;
224 struct funcinfo
226 struct funcinfo *next;
227 char *name;
228 bfd_vma low;
229 bfd_vma high;
232 struct module
234 /* Chain the previously read compilation unit. */
235 struct module *next;
237 /* The module name. */
238 char *name;
240 /* The start offset and size of debug info in the DST section. */
241 unsigned int modbeg;
242 unsigned int size;
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;
249 /* The listing line table. */
250 struct lineinfo *line_table;
252 /* The source record table. */
253 struct srecinfo *srec_table;
255 /* A list of the functions found in this module. */
256 struct funcinfo *func_table;
258 /* Current allocation of file_table. */
259 unsigned int file_table_count;
261 /* An array of the files making up this module. */
262 struct fileinfo *file_table;
265 /* BFD private data for alpha-vms. */
267 struct vms_private_data_struct
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;
273 /* Record input buffer. */
274 struct vms_rec_rd recrd;
275 struct vms_rec_wr recwr;
277 struct hdr_struct hdr_data; /* data from HDR/EMH record */
278 struct eom_struct eom_data; /* data from EOM/EEOM record */
280 /* Transfer addresses (entry points). */
281 bfd_vma transfer_address[4];
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;
288 /* Array of raw symbols. */
289 struct vms_symbol_entry **syms;
291 /* Canonicalized symbols. */
292 asymbol **csymbols;
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;
301 /* Stack used to evaluate TIR/ETIR commands. */
302 struct stack_struct *stack;
303 int stackptr;
305 /* Content reading. */
306 asection *image_section; /* section for image_ptr */
307 file_ptr image_offset; /* Offset for image_ptr. */
309 struct module *modules; /* list of all compilation units */
311 /* The DST section. */
312 asection *dst_section;
314 unsigned int dst_ptr_offsets_count; /* # of offsets in following array */
315 unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */
317 /* Shared library support */
318 bfd_vma symvva; /* relative virtual address of symbol vector */
319 unsigned int ident;
320 unsigned char matchctl;
322 /* Shared library index. This is used for input bfd while linking. */
323 unsigned int shr_index;
325 /* Used to place structures in the file. */
326 file_ptr file_pos;
328 /* Simply linked list of eisd. */
329 struct vms_internal_eisd_map *eisd_head;
330 struct vms_internal_eisd_map *eisd_tail;
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;
336 /* linkage index counter used by conditional store commands */
337 unsigned int vms_linkage_index;
340 #define PRIV2(abfd, name) \
341 (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
342 #define PRIV(name) PRIV2(abfd,name)
345 /* Used to keep extra VMS specific information for a given section.
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.
351 reloc_stream is the actual stream of relocation entries. */
353 struct vms_section_data_struct
355 /* Maximnum number of entries in sec->relocation. */
356 unsigned reloc_max;
358 /* Corresponding eisd. Used only while generating executables. */
359 struct vms_internal_eisd_map *eisd;
361 /* PSC flags to be clear. */
362 flagword no_flags;
364 /* PSC flags to be set. */
365 flagword flags;
368 #define vms_section_data(sec) \
369 ((struct vms_section_data_struct *)sec->used_by_bfd)
371 /* To be called from the debugger. */
372 struct vms_private_data_struct *bfd_vms_get_data (bfd *);
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 *);
385 struct vector_type
387 unsigned int max_el;
388 unsigned int nbr_el;
389 void *els;
392 /* Number of elements in VEC. */
394 #define VEC_COUNT(VEC) ((VEC).nbr_el)
396 /* Get the address of the Nth element. */
398 #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N])
400 #define VEC_INIT(VEC) \
401 do { \
402 (VEC).max_el = 0; \
403 (VEC).nbr_el = 0; \
404 (VEC).els = NULL; \
405 } while (0)
407 /* Be sure there is room for a new element. */
409 static void *vector_grow1 (struct vector_type *vec, size_t elsz);
411 /* Allocate room for a new element and return its address. */
413 #define VEC_APPEND(VEC, TYPE) \
414 ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE)))
416 struct alpha_vms_vma_ref
418 bfd_vma vma; /* Vma in the output. */
419 bfd_vma ref; /* Reference in the input. */
422 struct alpha_vms_shlib_el
424 bfd *abfd;
425 bool has_fixups;
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. */
432 /* Alpha VMS linker hash table. */
434 struct alpha_vms_link_hash_table
436 struct bfd_link_hash_table root;
438 /* Vector of shared libraries. */
439 struct vector_type shrlibs;
441 /* Fixup section. */
442 asection *fixup;
444 /* Base address. Used by fixups. */
445 bfd_vma base_addr;
448 #define alpha_vms_link_hash(INFO) \
449 ((struct alpha_vms_link_hash_table *)(INFO->hash))
451 /* Alpha VMS linker hash table entry. */
453 struct alpha_vms_link_hash_entry
455 struct bfd_link_hash_entry root;
457 /* Pointer to the original vms symbol. */
458 struct vms_symbol_entry *sym;
461 /* Image reading. */
463 /* Read & process EIHD record.
464 Return TRUE on success, FALSE on error. */
466 static bool
467 _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
468 unsigned int *eihs_offset)
470 unsigned int imgtype, size;
471 bfd_vma symvva;
472 struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
474 vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
476 /* PR 21813: Check for an undersized record. */
477 if (PRIV (recrd.buf_size) < sizeof (* eihd))
479 _bfd_error_handler (_("corrupt EIHD record - size is too small"));
480 bfd_set_error (bfd_error_bad_value);
481 return false;
484 size = bfd_getl32 (eihd->size);
485 imgtype = bfd_getl32 (eihd->imgtype);
487 if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
488 abfd->flags |= EXEC_P;
490 symvva = bfd_getl64 (eihd->symvva);
491 if (symvva != 0)
493 PRIV (symvva) = symvva;
494 abfd->flags |= DYNAMIC;
497 PRIV (ident) = bfd_getl32 (eihd->ident);
498 PRIV (matchctl) = eihd->matchctl;
500 *eisd_offset = bfd_getl32 (eihd->isdoff);
501 *eihs_offset = bfd_getl32 (eihd->symdbgoff);
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;
508 return true;
511 /* Read & process EISD record.
512 Return TRUE on success, FALSE on error. */
514 static bool
515 _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
517 int section_count = 0;
519 vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
521 while (1)
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;
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;
543 /* Skip to next block if pad. */
544 if (rec_size == 0xffffffff)
546 offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
547 continue;
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;
557 offset += rec_size;
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);
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));
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;
575 if (flags & EISD__M_EXE)
576 bfd_flags |= SEC_CODE;
578 if (flags & EISD__M_NONSHRADR)
579 bfd_flags |= SEC_DATA;
581 if (!(flags & EISD__M_WRT))
582 bfd_flags |= SEC_READONLY;
584 if (flags & EISD__M_DZRO)
585 bfd_flags |= SEC_DATA;
587 if (flags & EISD__M_FIXUPVEC)
588 bfd_flags |= SEC_DATA;
590 if (flags & EISD__M_CRF)
591 bfd_flags |= SEC_DATA;
593 if (flags & EISD__M_GBL)
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);
608 else if (flags & EISD__M_FIXUPVEC)
609 name = "$FIXUPVEC$";
610 else if (eisd->type == EISD__K_USRSTACK)
611 name = "$STACK$";
612 else
614 const char *pfx;
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++);
631 section = bfd_make_section (abfd, name);
633 if (!section)
634 return false;
636 section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
637 section->size = size;
638 section->vma = vaddr;
640 if (!bfd_set_section_flags (section, bfd_flags))
641 return false;
644 return true;
647 /* Read & process EIHS record.
648 Return TRUE on success, FALSE on error. */
650 static bool
651 _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
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;
662 /* PR 21611: Check that offset is valid. */
663 if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4))
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;
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);
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
684 if (dstvbn)
686 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
688 section = bfd_make_section (abfd, "$DST$");
689 if (!section)
690 return false;
692 section->size = dstsize;
693 section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
695 if (!bfd_set_section_flags (section, bfd_flags))
696 return false;
698 PRIV (dst_section) = section;
699 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
702 if (dmtvbn)
704 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
706 section = bfd_make_section (abfd, "$DMT$");
707 if (!section)
708 return false;
710 section->size = dmtbytes;
711 section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
713 if (!bfd_set_section_flags (section, bfd_flags))
714 return false;
717 if (gstvbn)
719 if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET))
721 bfd_set_error (bfd_error_file_truncated);
722 return false;
725 if (!_bfd_vms_slurp_object_records (abfd))
726 return false;
728 abfd->flags |= HAS_SYMS;
731 return true;
734 /* Object file reading. */
736 /* Object file input functions. */
738 /* Get next record from object file to vms_buf.
739 Set PRIV(buf_size) and return it
741 This is a little tricky since it should be portable.
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.
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.
756 The VMS format repeats the size at bytes 2 & 3 of every record.
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).
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.
769 All file I/O is done on even file positions. */
771 #define VMS_OBJECT_ADJUSTMENT 2
773 static void
774 maybe_adjust_record_pointer_for_object (bfd *abfd)
776 /* Set the file format once for all on the first invocation. */
777 if (PRIV (recrd.file_format) == FF_UNKNOWN)
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;
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;
791 /* Implement step #1 of the object record reading procedure.
792 Return the record type or -1 on failure. */
794 static int
795 _bfd_vms_get_object_record (bfd *abfd)
797 unsigned int test_len = 6;
798 int type;
800 vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
802 /* Skip alignment byte if the current position is odd. */
803 if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1))
805 if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1)
807 bfd_set_error (bfd_error_file_truncated);
808 return -1;
812 /* Read the record header */
813 if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len)
815 bfd_set_error (bfd_error_file_truncated);
816 return -1;
819 /* Reset the record pointer. */
820 PRIV (recrd.rec) = PRIV (recrd.buf);
821 maybe_adjust_record_pointer_for_object (abfd);
823 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
824 return -1;
826 type = bfd_getl16 (PRIV (recrd.rec));
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));
831 return type;
834 /* Implement step #2 of the object record reading procedure.
835 Return the size of the record or 0 on failure. */
837 static int
838 vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far)
840 unsigned int to_read;
842 vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
844 /* Extract record size. */
845 PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
847 if (PRIV (recrd.rec_size) == 0)
849 bfd_set_error (bfd_error_file_truncated);
850 return 0;
853 /* That's what the linker manual says. */
854 if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
856 bfd_set_error (bfd_error_file_truncated);
857 return 0;
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;
865 /* Adjust the buffer. */
866 if (to_read > PRIV (recrd.buf_size))
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;
874 /* PR 17512: file: 025-1974-0.004. */
875 else if (to_read <= read_so_far)
876 return 0;
878 /* Read the remaining record. */
879 to_read -= read_so_far;
881 vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
883 if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
885 bfd_set_error (bfd_error_file_truncated);
886 return 0;
889 /* Reset the record pointer. */
890 PRIV (recrd.rec) = PRIV (recrd.buf);
891 maybe_adjust_record_pointer_for_object (abfd);
893 vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
894 PRIV (recrd.rec_size)));
896 return PRIV (recrd.rec_size);
899 /* Read and process emh record.
900 Return TRUE on success, FALSE on error. */
902 static bool
903 _bfd_vms_slurp_ehdr (bfd *abfd)
905 unsigned char *ptr;
906 unsigned char *vms_rec;
907 unsigned char *end;
908 int subtype;
910 vms_rec = PRIV (recrd.rec);
911 /* PR 17512: file: 62736583. */
912 end = PRIV (recrd.buf) + PRIV (recrd.buf_size);
914 vms_debug2 ((2, "HDR/EMH\n"));
916 subtype = bfd_getl16 (vms_rec + 4);
918 vms_debug2 ((3, "subtype %d\n", subtype));
920 switch (subtype)
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;
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;
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;
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;
967 case EMH__C_CPR:
968 case EMH__C_MTC:
969 case EMH__C_GTX:
970 break;
972 default:
973 fail:
974 bfd_set_error (bfd_error_wrong_format);
975 return false;
978 return true;
981 /* Typical sections for evax object files. */
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$"
995 struct sec_flags_struct
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. */
1004 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */
1006 static const struct sec_flags_struct evax_section_flags[] =
1008 { EVAX_ABS_NAME,
1009 EGPS__V_SHR,
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 }
1065 /* Retrieve BFD section flags by name and size. */
1067 static flagword
1068 vms_secflag_by_name (const struct sec_flags_struct *section_flags,
1069 const char *name,
1070 int hassize)
1072 int i = 0;
1074 while (section_flags[i].name != NULL)
1076 if (strcmp (name, section_flags[i].name) == 0)
1078 if (hassize)
1079 return section_flags[i].flags_hassize;
1080 else
1081 return section_flags[i].flags_always;
1083 i++;
1085 if (hassize)
1086 return section_flags[i].flags_hassize;
1087 return section_flags[i].flags_always;
1090 /* Retrieve VMS section flags by name and size. */
1092 static flagword
1093 vms_esecflag_by_name (const struct sec_flags_struct *section_flags,
1094 const char *name,
1095 int hassize)
1097 int i = 0;
1099 while (section_flags[i].name != NULL)
1101 if (strcmp (name, section_flags[i].name) == 0)
1103 if (hassize)
1104 return section_flags[i].vflags_hassize;
1105 else
1106 return section_flags[i].vflags_always;
1108 i++;
1110 if (hassize)
1111 return section_flags[i].vflags_hassize;
1112 return section_flags[i].vflags_always;
1115 /* Add SYM to the symbol table of ABFD.
1116 Return FALSE in case of error. */
1118 static bool
1119 add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym)
1121 if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
1123 if (PRIV (max_sym_count) == 0)
1125 PRIV (max_sym_count) = 128;
1126 PRIV (syms) = bfd_malloc
1127 (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
1129 else
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 *)));
1136 if (PRIV (syms) == NULL)
1137 return false;
1140 PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
1141 return true;
1144 /* Create a symbol whose name is ASCIC and add it to ABFD.
1145 Return NULL in case of error. */
1147 static struct vms_symbol_entry *
1148 add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max)
1150 struct vms_symbol_entry *entry;
1151 unsigned int len;
1153 len = *ascic++;
1154 max -= 1;
1155 if (len > max)
1157 _bfd_error_handler (_("record is too small for symbol name length"));
1158 bfd_set_error (bfd_error_bad_value);
1159 return NULL;
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;
1170 if (!add_symbol_entry (abfd, entry))
1171 return NULL;
1172 return entry;
1175 /* Read and process EGSD. Return FALSE on failure. */
1177 static bool
1178 _bfd_vms_slurp_egsd (bfd *abfd)
1180 int gsd_type;
1181 unsigned int gsd_size;
1182 unsigned char *vms_rec;
1183 bfd_vma base_addr;
1184 long psindx;
1186 vms_debug2 ((2, "EGSD\n"));
1188 if (PRIV (recrd.rec_size) < 8)
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;
1196 PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */
1197 PRIV (recrd.rec_size) -= 8;
1199 /* Calculate base address for each section. */
1200 base_addr = 0;
1202 while (PRIV (recrd.rec_size) > 4)
1204 vms_rec = PRIV (recrd.rec);
1206 gsd_type = bfd_getl16 (vms_rec);
1207 gsd_size = bfd_getl16 (vms_rec + 2);
1209 vms_debug2 ((3, "egsd_type %d\n", gsd_type));
1211 /* PR 21615: Check for size overflow. */
1212 if (PRIV (recrd.rec_size) < gsd_size)
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;
1221 if (gsd_size < 4)
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;
1231 switch (gsd_type)
1233 case EGSD__C_PSC:
1234 /* Program section definition. */
1236 struct vms_egps *egps = (struct vms_egps *) vms_rec;
1237 flagword new_flags, vms_flags;
1238 asection *section;
1240 if (offsetof (struct vms_egps, flags) + 2 > gsd_size)
1241 goto too_small;
1242 vms_flags = bfd_getl16 (egps->flags);
1244 if ((vms_flags & EGPS__V_REL) == 0)
1246 /* Use the global absolute section for all
1247 absolute sections. */
1248 section = bfd_abs_section_ptr;
1250 else
1252 char *name;
1253 bfd_vma align_addr;
1254 size_t left;
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;
1263 section = bfd_make_section (abfd, name);
1264 if (!section)
1265 return false;
1267 section->filepos = 0;
1268 section->size = bfd_getl32 (egps->alloc);
1269 section->alignment_power = egps->align & 31;
1271 vms_section_data (section)->flags = vms_flags;
1272 vms_section_data (section)->no_flags = 0;
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)
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;
1287 if (vms_flags & EGPS__V_EXE)
1289 /* Set CODE if section is executable. */
1290 new_flags |= SEC_CODE;
1291 new_flags &= ~SEC_DATA;
1293 if (!bfd_set_section_flags (section, new_flags))
1294 return false;
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;
1303 /* Append it to the section array. */
1304 if (PRIV (section_count) >= PRIV (section_max))
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;
1316 PRIV (sections)[PRIV (section_count)] = section;
1317 PRIV (section_count)++;
1319 break;
1321 case EGSD__C_SYM:
1323 unsigned int nameoff;
1324 struct vms_symbol_entry *entry;
1325 struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
1326 flagword old_flags;
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;
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;
1342 /* Allow only duplicate reference. */
1343 if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
1344 abort ();
1346 if (entry->typ == 0)
1348 entry->typ = gsd_type;
1349 entry->data_type = egsy->datyp;
1350 entry->flags = old_flags;
1353 if (old_flags & EGSY__V_DEF)
1355 struct vms_esdf *esdf = (struct vms_esdf *) vms_rec;
1357 entry->value = bfd_getl64 (esdf->value);
1358 if (PRIV (sections) == NULL)
1359 return false;
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))
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;
1372 entry->section = PRIV (sections)[psindx];
1374 if (old_flags & EGSY__V_NORM)
1376 PRIV (norm_sym_count)++;
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];
1387 break;
1389 case EGSD__C_SYMG:
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);
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;
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;
1407 entry->symbol_vector = bfd_getl32 (egst->value);
1409 if (old_flags & EGSY__V_REL)
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];
1419 else
1420 entry->section = bfd_abs_section_ptr;
1422 entry->value = bfd_getl64 (egst->lp_2);
1424 if (old_flags & EGSY__V_NORM)
1426 PRIV (norm_sym_count)++;
1428 entry->code_value = bfd_getl64 (egst->lp_1);
1429 entry->code_section = bfd_abs_section_ptr;
1432 break;
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;
1446 PRIV (recrd.rec_size) -= gsd_size;
1447 PRIV (recrd.rec) += gsd_size;
1450 /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ? */
1452 if (PRIV (gsd_sym_count) > 0)
1453 abfd->flags |= HAS_SYMS;
1455 return true;
1458 /* Stack routines for vms ETIR commands. */
1460 /* Push value and section index. */
1462 static bool
1463 _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
1465 vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
1466 (unsigned long)val, reloc, PRIV (stackptr)));
1468 PRIV (stack[PRIV (stackptr)]).value = val;
1469 PRIV (stack[PRIV (stackptr)]).reloc = reloc;
1470 PRIV (stackptr)++;
1471 if (PRIV (stackptr) >= STACKSIZE)
1473 bfd_set_error (bfd_error_bad_value);
1474 _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
1475 return false;
1477 return true;
1480 /* Pop value and section index. */
1482 static bool
1483 _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
1485 if (PRIV (stackptr) == 0)
1487 bfd_set_error (bfd_error_bad_value);
1488 _bfd_error_handler (_("stack underflow in _bfd_vms_pop"));
1489 return false;
1491 PRIV (stackptr)--;
1492 *val = PRIV (stack[PRIV (stackptr)]).value;
1493 *rel = PRIV (stack[PRIV (stackptr)]).reloc;
1495 vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
1496 return true;
1499 /* Routines to fill sections contents during tir/etir read. */
1501 /* Initialize image buffer pointer to be filled. */
1503 static void
1504 image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info)
1506 asection *sec;
1508 vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect));
1510 if (PRIV (sections) == NULL)
1511 return;
1512 if (sect < 0 || sect >= (int) PRIV (section_count))
1513 return;
1515 sec = PRIV (sections)[sect];
1517 if (info)
1519 /* Reading contents to an output bfd. */
1521 if (sec->output_section == NULL)
1523 /* Section discarded. */
1524 vms_debug2 ((5, " section %s discarded\n", sec->name));
1526 /* This is not used. */
1527 PRIV (image_section) = NULL;
1528 PRIV (image_offset) = 0;
1529 return;
1531 PRIV (image_offset) = sec->output_offset + vma;
1532 PRIV (image_section) = sec->output_section;
1534 else
1536 PRIV (image_offset) = vma;
1537 PRIV (image_section) = sec;
1541 /* Increment image buffer pointer by offset. */
1543 static void
1544 image_inc_ptr (bfd *abfd, bfd_vma offset)
1546 vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
1548 PRIV (image_offset) += offset;
1551 /* Save current DST location counter under specified index. */
1553 static bool
1554 dst_define_location (bfd *abfd, unsigned int loc)
1556 vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
1558 if (loc > 1 << 24)
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;
1566 /* Grow the ptr offset table if necessary. */
1567 if (loc + 1 > PRIV (dst_ptr_offsets_count))
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;
1579 PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
1580 return true;
1583 /* Restore saved DST location counter from specified index. */
1585 static bool
1586 dst_restore_location (bfd *abfd, unsigned int loc)
1588 vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
1590 if (loc < PRIV (dst_ptr_offsets_count))
1592 PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
1593 return true;
1595 return false;
1598 /* Retrieve saved DST location counter from specified index. */
1600 static bool
1601 dst_retrieve_location (bfd *abfd, bfd_vma *loc)
1603 vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc));
1605 if (*loc < PRIV (dst_ptr_offsets_count))
1607 *loc = PRIV (dst_ptr_offsets)[*loc];
1608 return true;
1610 return false;
1613 /* Write multiple bytes to section image. */
1615 static bool
1616 image_write (bfd *abfd, unsigned char *ptr, unsigned int size)
1618 asection *sec = PRIV (image_section);
1619 size_t off = PRIV (image_offset);
1621 /* Check bounds. */
1622 if (off > sec->size
1623 || size > sec->size - off)
1625 bfd_set_error (bfd_error_bad_value);
1626 return false;
1629 #if VMS_DEBUG
1630 _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size,
1631 (long) off);
1632 #endif
1634 if (PRIV (image_section)->contents != NULL)
1635 memcpy (sec->contents + off, ptr, size);
1636 else
1638 unsigned int i;
1639 for (i = 0; i < size; i++)
1640 if (ptr[i] != 0)
1642 bfd_set_error (bfd_error_bad_value);
1643 return false;
1647 #if VMS_DEBUG
1648 _bfd_hexdump (9, ptr, size, 0);
1649 #endif
1651 PRIV (image_offset) += size;
1652 return true;
1655 /* Write byte to section image. */
1657 static bool
1658 image_write_b (bfd * abfd, unsigned int value)
1660 unsigned char data[1];
1662 vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
1664 *data = value;
1666 return image_write (abfd, data, sizeof (data));
1669 /* Write 2-byte word to image. */
1671 static bool
1672 image_write_w (bfd * abfd, unsigned int value)
1674 unsigned char data[2];
1676 vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
1678 bfd_putl16 (value, data);
1679 return image_write (abfd, data, sizeof (data));
1682 /* Write 4-byte long to image. */
1684 static bool
1685 image_write_l (bfd * abfd, unsigned long value)
1687 unsigned char data[4];
1689 vms_debug2 ((6, "image_write_l (%08lx)\n", value));
1691 bfd_putl32 (value, data);
1692 return image_write (abfd, data, sizeof (data));
1695 /* Write 8-byte quad to image. */
1697 static bool
1698 image_write_q (bfd * abfd, bfd_vma value)
1700 unsigned char data[8];
1702 vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
1704 bfd_putl64 (value, data);
1705 return image_write (abfd, data, sizeof (data));
1708 static const char *
1709 _bfd_vms_etir_name (int cmd)
1711 switch (cmd)
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";
1763 default:
1764 /* These names have not yet been added to this switch statement. */
1765 _bfd_error_handler (_("unknown ETIR command %d"), cmd);
1768 return NULL;
1770 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
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)
1780 char name[257];
1781 unsigned int len;
1782 unsigned int i;
1783 struct alpha_vms_link_hash_entry *h;
1785 /* Not linking. Do not try to resolve the symbol. */
1786 if (info == NULL)
1788 *vma = 0;
1789 *hp = NULL;
1790 return;
1793 len = *ascic;
1794 if (ascic + len >= max_ascic)
1796 _bfd_error_handler (_("corrupt vms value"));
1797 *vma = 0;
1798 *hp = NULL;
1799 return;
1802 for (i = 0; i < len; i++)
1803 name[i] = ascic[i + 1];
1804 name[i] = 0;
1806 h = (struct alpha_vms_link_hash_entry *)
1807 bfd_link_hash_lookup (info->hash, name, false, false, true);
1809 *hp = h;
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
1821 (*info->callbacks->undefined_symbol)
1822 (info, name, abfd, PRIV (image_section), PRIV (image_offset), true);
1823 *vma = 0;
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
1833 static unsigned int
1834 alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h)
1836 /* Handle undefined symbols. */
1837 if (h == NULL || h->sym == NULL)
1838 return RELC_NONE;
1840 if (h->sym->typ == EGSD__C_SYMG)
1842 if (h->sym->flags & EGSY__V_REL)
1843 return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index);
1844 else
1846 /* Can this happen (non-relocatable symg) ? I'd like to see
1847 an example. */
1848 abort ();
1851 if (h->sym->typ == EGSD__C_SYM)
1853 if (h->sym->flags & EGSY__V_REL)
1854 return RELC_REL;
1855 else
1856 return RELC_NONE;
1858 abort ();
1861 static bfd_vma
1862 alpha_vms_get_sym_value (asection *sect, bfd_vma addr)
1864 return sect->output_section->vma + sect->output_offset + addr;
1867 static bfd_vma
1868 alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info,
1869 unsigned int rel, bfd_vma vma)
1871 asection *sec;
1873 if (PRIV (sections) == NULL)
1874 return 0;
1876 sec = PRIV (sections)[rel & RELC_MASK];
1878 if (info)
1880 if (sec->output_section == NULL)
1881 abort ();
1882 return vma + sec->output_section->vma + sec->output_offset;
1884 else
1885 return vma + sec->vma;
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. */
1892 static bool
1893 _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
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;
1904 PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
1905 PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
1907 ptr = PRIV (recrd.rec);
1908 length = PRIV (recrd.rec_size);
1909 maxptr = ptr + length;
1911 vms_debug2 ((2, "ETIR: %d bytes\n", length));
1913 while (ptr < maxptr)
1915 int cmd, cmd_length;
1917 if (ptr + 4 > maxptr)
1918 goto corrupt_etir;
1920 cmd = bfd_getl16 (ptr);
1921 cmd_length = bfd_getl16 (ptr + 2);
1923 /* PR 21589 and 21579: Check for a corrupt ETIR record. */
1924 if (cmd_length < 4 || ptr + cmd_length > maxptr)
1926 corrupt_etir:
1927 _bfd_error_handler (_("corrupt ETIR record encountered"));
1928 bfd_set_error (bfd_error_bad_value);
1929 return false;
1931 ptr += 4;
1932 cmd_length -= 4;
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
1940 switch (cmd)
1942 /* Stack global
1943 arg: cs symbol name
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;
1952 /* Stack longword
1953 arg: lw value
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;
1963 /* Stack quadword
1964 arg: qw value
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;
1974 /* Stack psect base plus quadword offset
1975 arg: lw section index
1976 qw signed quadword offset (low 32 bits)
1978 Stack qw argument and section index
1979 (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */
1980 case ETIR__C_STA_PQ:
1982 int psect;
1984 if (cmd_length < 12)
1985 goto corrupt_etir;
1986 psect = bfd_getl32 (ptr);
1987 if ((unsigned int) psect >= PRIV (section_count))
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;
1994 op1 = bfd_getl64 (ptr + 4);
1995 if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE))
1996 return false;
1998 break;
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;
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;
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;
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)
2037 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
2038 rel1 = RELC_REL;
2040 else if (rel1 & RELC_SHR_BASE)
2042 if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1))
2043 return false;
2044 rel1 = RELC_NONE;
2046 if (rel1 != RELC_NONE)
2048 if (rel1 != RELC_REL)
2049 abort ();
2050 if (!alpha_vms_add_lw_reloc (info))
2051 return false;
2053 if (!image_write_l (abfd, op1))
2054 return false;
2055 break;
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)
2064 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
2065 rel1 = RELC_REL;
2067 else if (rel1 & RELC_SHR_BASE)
2068 abort ();
2069 if (rel1 != RELC_NONE)
2071 if (rel1 != RELC_REL)
2072 abort ();
2073 if (!alpha_vms_add_qw_reloc (info))
2074 return false;
2076 if (!image_write_q (abfd, op1))
2077 return false;
2078 break;
2080 /* Store immediate repeated: pop stack for repeat count
2081 arg: lw byte count
2082 da data. */
2083 case ETIR__C_STO_IMMR:
2085 int size;
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;
2103 break;
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)
2111 if (h->sym->typ == EGSD__C_SYMG)
2113 if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner,
2114 h->sym->symbol_vector))
2115 return false;
2116 op1 = 0;
2118 else
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;
2126 if (!image_write_q (abfd, op1))
2127 return false;
2128 break;
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)
2136 if (h->sym->flags & EGSY__V_NORM)
2138 /* That's really a procedure. */
2139 if (h->sym->typ == EGSD__C_SYMG)
2141 if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner))
2142 return false;
2143 op1 = h->sym->symbol_vector;
2145 else
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;
2153 else
2155 /* Symbol is not a procedure. */
2156 abort ();
2159 if (!image_write_q (abfd, op1))
2160 return false;
2161 break;
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;
2169 if (!(rel1 & RELC_SEC_BASE))
2170 abort ();
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;
2178 /* Store immediate
2179 arg: lw count of bytes
2180 da data. */
2181 case ETIR__C_STO_IMM:
2183 unsigned int size;
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;
2191 break;
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;
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;
2222 /* 200 Store-conditional Linkage Pair
2223 arg: none. */
2224 case ETIR__C_STC_LP:
2226 /* 202 Store-conditional Address at global address
2227 lw linkage index
2228 cs global name. */
2230 case ETIR__C_STC_GBL:
2232 /* 203 Store-conditional Code Address at global address
2233 lw linkage index
2234 cs procedure name. */
2235 case ETIR__C_STC_GCA:
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;
2247 /* 201 Store-conditional Linkage Pair with Procedure Signature
2248 lw linkage index
2249 cs procedure name
2250 by signature length
2251 da signature. */
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)
2259 if (h->sym->typ == EGSD__C_SYMG)
2261 if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner))
2262 return false;
2263 op1 = h->sym->symbol_vector;
2264 op2 = 0;
2266 else
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);
2274 else
2276 /* Undefined symbol. */
2277 op1 = 0;
2278 op2 = 0;
2280 if (!image_write_q (abfd, op1)
2281 || !image_write_q (abfd, op2))
2282 return false;
2283 break;
2285 /* 205 Store-conditional NOP at address of global
2286 arg: none. */
2287 case ETIR__C_STC_NOP_GBL:
2288 /* ALPHA_R_NOP */
2290 /* 207 Store-conditional BSR at global address
2291 arg: none. */
2293 case ETIR__C_STC_BSR_GBL:
2294 /* ALPHA_R_BSR */
2296 /* 209 Store-conditional LDA at global address
2297 arg: none. */
2299 case ETIR__C_STC_LDA_GBL:
2300 /* ALPHA_R_LDA */
2302 /* 211 Store-conditional BSR or Hint at global address
2303 arg: none. */
2305 case ETIR__C_STC_BOH_GBL:
2306 /* Currentl ignored. */
2307 break;
2309 /* 213 Store-conditional NOP,BSR or HINT at global address
2310 arg: none. */
2312 case ETIR__C_STC_NBH_GBL:
2314 /* 206 Store-conditional NOP at pect + offset
2315 arg: none. */
2317 case ETIR__C_STC_NOP_PS:
2319 /* 208 Store-conditional BSR at pect + offset
2320 arg: none. */
2322 case ETIR__C_STC_BSR_PS:
2324 /* 210 Store-conditional LDA at psect + offset
2325 arg: none. */
2327 case ETIR__C_STC_LDA_PS:
2329 /* 212 Store-conditional BSR or Hint at pect + offset
2330 arg: none. */
2332 case ETIR__C_STC_BOH_PS:
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;
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;
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;
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;
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))
2381 bfd_set_error (bfd_error_bad_value);
2382 _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC");
2383 return false;
2385 break;
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))
2396 bfd_set_error (bfd_error_bad_value);
2397 _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL");
2398 return false;
2400 if (!_bfd_vms_push (abfd, op1, RELC_NONE))
2401 return false;
2402 break;
2404 case ETIR__C_OPR_NOP: /* No-op. */
2405 break;
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;
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))
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;
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;
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;
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)
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;
2461 else
2463 if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE))
2464 return false;
2466 break;
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;
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;
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;
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;
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;
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)
2522 bad_context:
2523 _bfd_error_handler (_("invalid use of %s with contexts"),
2524 _bfd_vms_etir_name (cmd));
2525 return false;
2527 if ((bfd_signed_vma) op2 < 0)
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;
2540 else
2542 /* Shift left. */
2543 if (op2 >= CHAR_BIT * sizeof (op1))
2544 op1 = 0;
2545 else
2546 op1 <<= op2;
2548 if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym. */
2549 return false;
2550 break;
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;
2562 case ETIR__C_OPR_SEL: /* Select. */
2563 if (!_bfd_vms_pop (abfd, &op1, &rel1))
2564 return false;
2565 if (op1 & 0x01L)
2567 if (!_bfd_vms_pop (abfd, &op1, &rel1))
2568 return false;
2570 else
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;
2578 break;
2580 default:
2581 _bfd_error_handler (_("reserved cmd %d"), cmd);
2582 return false;
2583 break;
2586 ptr += cmd_length;
2589 return true;
2592 /* Process EDBG/ETBT record.
2593 Return TRUE on success, FALSE on error */
2595 static bool
2596 vms_slurp_debug (bfd *abfd)
2598 asection *section = PRIV (dst_section);
2600 if (section == NULL)
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;
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;
2616 PRIV (image_section) = section;
2617 PRIV (image_offset) = section->size;
2619 if (!_bfd_vms_slurp_etir (abfd, NULL))
2620 return false;
2622 section->size = PRIV (image_offset);
2623 return true;
2626 /* Process EDBG record.
2627 Return TRUE on success, FALSE on error. */
2629 static bool
2630 _bfd_vms_slurp_edbg (bfd *abfd)
2632 vms_debug2 ((2, "EDBG\n"));
2634 abfd->flags |= HAS_DEBUG | HAS_LINENO;
2636 return vms_slurp_debug (abfd);
2639 /* Process ETBT record.
2640 Return TRUE on success, FALSE on error. */
2642 static bool
2643 _bfd_vms_slurp_etbt (bfd *abfd)
2645 vms_debug2 ((2, "ETBT\n"));
2647 abfd->flags |= HAS_LINENO;
2649 return vms_slurp_debug (abfd);
2652 /* Process EEOM record.
2653 Return TRUE on success, FALSE on error. */
2655 static bool
2656 _bfd_vms_slurp_eeom (bfd *abfd)
2658 struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
2660 vms_debug2 ((2, "EEOM\n"));
2662 /* PR 21813: Check for an undersized record. */
2663 if (PRIV (recrd.buf_size) < sizeof (* eeom))
2665 _bfd_error_handler (_("corrupt EEOM record - size is too small"));
2666 bfd_set_error (bfd_error_bad_value);
2667 return false;
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)
2674 _bfd_error_handler (_("object module not error-free !"));
2675 bfd_set_error (bfd_error_bad_value);
2676 return false;
2679 PRIV (eom_data).eom_has_transfer = false;
2680 if (PRIV (recrd.rec_size) > 10)
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);
2687 abfd->start_address = PRIV (eom_data).eom_l_tfradr;
2689 return true;
2692 /* Slurp an ordered set of VMS object records. Return FALSE on error. */
2694 static bool
2695 _bfd_vms_slurp_object_records (bfd * abfd)
2697 bool ok;
2698 int type;
2702 vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
2704 type = _bfd_vms_get_object_record (abfd);
2705 if (type < 0)
2707 vms_debug2 ((2, "next_record failed\n"));
2708 return false;
2711 switch (type)
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;
2734 if (!ok)
2736 vms_debug2 ((2, "slurp type %d failed\n", type));
2737 return false;
2740 while (type != EOBJ__C_EEOM);
2742 return true;
2745 /* Initialize private data */
2746 static bool
2747 vms_initialize (bfd * abfd)
2749 size_t amt;
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;
2756 PRIV (recrd.file_format) = FF_UNKNOWN;
2758 amt = sizeof (struct stack_struct) * STACKSIZE;
2759 PRIV (stack) = bfd_alloc (abfd, amt);
2760 if (PRIV (stack) == NULL)
2761 goto error_ret1;
2763 return true;
2765 error_ret1:
2766 bfd_release (abfd, abfd->tdata.any);
2767 abfd->tdata.any = NULL;
2768 return false;
2771 /* Free malloc'd memory. */
2773 static void
2774 alpha_vms_free_private (bfd *abfd)
2776 struct module *module;
2778 free (PRIV (recrd.buf));
2779 free (PRIV (sections));
2780 free (PRIV (syms));
2781 free (PRIV (dst_ptr_offsets));
2783 for (module = PRIV (modules); module; module = module->next)
2784 free (module->file_table);
2787 /* Check the format for a file being read.
2788 Return a (bfd_target *) if it's an object file or zero if not. */
2790 static bfd_cleanup
2791 alpha_vms_object_p (bfd *abfd)
2793 unsigned int test_len;
2794 unsigned char *buf;
2796 vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
2798 /* Allocate alpha-vms specific data. */
2799 if (!vms_initialize (abfd))
2800 return NULL;
2802 if (bfd_seek (abfd, 0, SEEK_SET))
2803 goto error_ret;
2805 /* The first challenge with VMS is to discover the kind of the file.
2807 Image files (executable or shared images) are stored as a raw
2808 stream of bytes (like on UNIX), but there is no magic number.
2810 Object files are written with RMS (record management service), ie
2811 each records are preceeded by its length (on a word - 2 bytes), and
2812 padded for word-alignment. That would be simple but when files
2813 are transfered to a UNIX filesystem (using ftp), records are lost.
2814 Only the raw content of the records are transfered. Fortunately,
2815 the Alpha Object file format also store the length of the record
2816 in the records. Is that clear ? */
2818 /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id,
2819 2 bytes size repeated) and 12 bytes for images (4 bytes major id,
2820 4 bytes minor id, 4 bytes length). */
2821 test_len = 12;
2822 buf = _bfd_malloc_and_read (abfd, test_len, test_len);
2823 if (buf == NULL)
2824 goto error_ret;
2825 PRIV (recrd.buf) = buf;
2826 PRIV (recrd.buf_size) = test_len;
2827 PRIV (recrd.rec) = buf;
2829 /* Is it an image? */
2830 if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
2831 && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
2833 unsigned int eisd_offset, eihs_offset;
2835 /* Extract the header size. */
2836 PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
2838 /* The header size is 0 for DSF files. */
2839 if (PRIV (recrd.rec_size) == 0)
2840 PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
2842 /* PR 21813: Check for a truncated record. */
2843 /* PR 17512: file: 7d7c57c2. */
2844 if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd))
2845 goto err_wrong_format;
2847 if (bfd_seek (abfd, 0, SEEK_SET))
2848 goto error_ret;
2850 free (PRIV (recrd.buf));
2851 PRIV (recrd.buf) = NULL;
2852 buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size),
2853 PRIV (recrd.rec_size));
2854 if (buf == NULL)
2855 goto error_ret;
2857 PRIV (recrd.buf) = buf;
2858 PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
2859 PRIV (recrd.rec) = buf;
2861 vms_debug2 ((2, "file type is image\n"));
2863 if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset))
2864 goto err_wrong_format;
2866 if (!_bfd_vms_slurp_eisd (abfd, eisd_offset))
2867 goto err_wrong_format;
2869 /* EIHS is optional. */
2870 if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset))
2871 goto err_wrong_format;
2873 else
2875 int type;
2877 /* Assume it's a module and adjust record pointer if necessary. */
2878 maybe_adjust_record_pointer_for_object (abfd);
2880 /* But is it really a module? */
2881 if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
2882 && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
2884 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
2885 goto err_wrong_format;
2887 vms_debug2 ((2, "file type is module\n"));
2889 type = bfd_getl16 (PRIV (recrd.rec));
2890 if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd))
2891 goto err_wrong_format;
2893 if (!_bfd_vms_slurp_object_records (abfd))
2894 goto err_wrong_format;
2896 else
2897 goto err_wrong_format;
2900 /* Set arch_info to alpha. */
2902 if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
2903 goto err_wrong_format;
2905 return alpha_vms_free_private;
2907 err_wrong_format:
2908 bfd_set_error (bfd_error_wrong_format);
2910 error_ret:
2911 alpha_vms_free_private (abfd);
2912 bfd_release (abfd, abfd->tdata.any);
2913 return NULL;
2916 /* Image write. */
2918 /* Write an EMH/MHD record. */
2920 static bool
2921 _bfd_vms_write_emh (bfd *abfd)
2923 struct vms_rec_wr *recwr = &PRIV (recwr);
2924 unsigned char tbuf[18];
2926 _bfd_vms_output_alignment (recwr, 2);
2928 /* EMH. */
2929 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2930 _bfd_vms_output_short (recwr, EMH__C_MHD);
2931 _bfd_vms_output_short (recwr, EOBJ__C_STRLVL);
2932 _bfd_vms_output_long (recwr, 0);
2933 _bfd_vms_output_long (recwr, 0);
2934 _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE);
2936 /* Create module name from filename. */
2937 if (bfd_get_filename (abfd) != 0)
2939 char *module = vms_get_module_name (bfd_get_filename (abfd), true);
2940 _bfd_vms_output_counted (recwr, module);
2941 free (module);
2943 else
2944 _bfd_vms_output_counted (recwr, "NONAME");
2946 _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
2947 _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH);
2948 _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
2949 return _bfd_vms_output_end (abfd, recwr);
2952 /* Write an EMH/LMN record. */
2954 static bool
2955 _bfd_vms_write_lmn (bfd *abfd, const char *name)
2957 char version [64];
2958 struct vms_rec_wr *recwr = &PRIV (recwr);
2959 unsigned int ver = BFD_VERSION / 10000;
2961 /* LMN. */
2962 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2963 _bfd_vms_output_short (recwr, EMH__C_LNM);
2964 snprintf (version, sizeof (version), "%s %d.%d.%d", name,
2965 ver / 10000, (ver / 100) % 100, ver % 100);
2966 _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
2967 return _bfd_vms_output_end (abfd, recwr);
2971 /* Write eom record for bfd abfd. Return FALSE on error. */
2973 static bool
2974 _bfd_vms_write_eeom (bfd *abfd)
2976 struct vms_rec_wr *recwr = &PRIV (recwr);
2978 vms_debug2 ((2, "vms_write_eeom\n"));
2980 _bfd_vms_output_alignment (recwr, 2);
2982 _bfd_vms_output_begin (recwr, EOBJ__C_EEOM);
2983 _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1);
2984 _bfd_vms_output_byte (recwr, 0); /* Completion code. */
2985 _bfd_vms_output_byte (recwr, 0); /* Fill byte. */
2987 if ((abfd->flags & EXEC_P) == 0
2988 && bfd_get_start_address (abfd) != (bfd_vma)-1)
2990 asection *section;
2992 section = bfd_get_section_by_name (abfd, ".link");
2993 if (section == 0)
2995 bfd_set_error (bfd_error_nonrepresentable_section);
2996 return false;
2998 _bfd_vms_output_short (recwr, 0);
2999 _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
3000 _bfd_vms_output_long (recwr,
3001 (unsigned long) bfd_get_start_address (abfd));
3002 _bfd_vms_output_long (recwr, 0);
3005 return _bfd_vms_output_end (abfd, recwr);
3008 static void *
3009 vector_grow1 (struct vector_type *vec, size_t elsz)
3011 if (vec->nbr_el >= vec->max_el)
3013 if (vec->max_el == 0)
3015 vec->max_el = 16;
3016 vec->els = bfd_malloc (vec->max_el * elsz);
3018 else
3020 size_t amt;
3021 if (vec->max_el > -1u / 2)
3023 bfd_set_error (bfd_error_file_too_big);
3024 return NULL;
3026 vec->max_el *= 2;
3027 if (_bfd_mul_overflow (vec->max_el, elsz, &amt))
3029 bfd_set_error (bfd_error_file_too_big);
3030 return NULL;
3032 vec->els = bfd_realloc_or_free (vec->els, amt);
3035 if (vec->els == NULL)
3036 return NULL;
3037 return (char *) vec->els + elsz * vec->nbr_el++;
3040 /* Bump ABFD file position to next block. */
3042 static void
3043 alpha_vms_file_position_block (bfd *abfd)
3045 /* Next block. */
3046 PRIV (file_pos) += VMS_BLOCK_SIZE - 1;
3047 PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE);
3050 /* Convert from internal structure SRC to external structure DST. */
3052 static void
3053 alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src,
3054 struct vms_eisd *dst)
3056 bfd_putl32 (src->u.eisd.majorid, dst->majorid);
3057 bfd_putl32 (src->u.eisd.minorid, dst->minorid);
3058 bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize);
3059 if (src->u.eisd.eisdsize <= EISD__K_LENEND)
3060 return;
3061 bfd_putl32 (src->u.eisd.secsize, dst->secsize);
3062 bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr);
3063 bfd_putl32 (src->u.eisd.flags, dst->flags);
3064 bfd_putl32 (src->u.eisd.vbn, dst->vbn);
3065 dst->pfc = src->u.eisd.pfc;
3066 dst->matchctl = src->u.eisd.matchctl;
3067 dst->type = src->u.eisd.type;
3068 dst->fill_1 = 0;
3069 if (src->u.eisd.flags & EISD__M_GBL)
3071 bfd_putl32 (src->u.gbl_eisd.ident, dst->ident);
3072 memcpy (dst->gblnam, src->u.gbl_eisd.gblnam,
3073 src->u.gbl_eisd.gblnam[0] + 1);
3077 /* Append EISD to the list of extra eisd for ABFD. */
3079 static void
3080 alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd)
3082 eisd->next = NULL;
3083 if (PRIV (gbl_eisd_head) == NULL)
3084 PRIV (gbl_eisd_head) = eisd;
3085 else
3086 PRIV (gbl_eisd_tail)->next = eisd;
3087 PRIV (gbl_eisd_tail) = eisd;
3090 /* Create an EISD for shared image SHRIMG.
3091 Return FALSE in case of error. */
3093 static bool
3094 alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
3096 struct vms_internal_eisd_map *eisd;
3097 int namlen;
3099 namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name));
3100 if (namlen + 5 > EISD__K_GBLNAMLEN)
3102 /* Won't fit. */
3103 return false;
3106 eisd = bfd_alloc (abfd, sizeof (*eisd));
3107 if (eisd == NULL)
3108 return false;
3110 /* Fill the fields. */
3111 eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID;
3112 eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID;
3113 eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3;
3114 eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */
3115 eisd->u.gbl_eisd.common.virt_addr = 0;
3116 eisd->u.gbl_eisd.common.flags = EISD__M_GBL;
3117 eisd->u.gbl_eisd.common.vbn = 0;
3118 eisd->u.gbl_eisd.common.pfc = 0;
3119 eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl);
3120 eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC;
3122 eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident);
3123 eisd->u.gbl_eisd.gblnam[0] = namlen + 4;
3124 memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name),
3125 namlen);
3126 memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4);
3128 /* Append it to the list. */
3129 alpha_vms_append_extra_eisd (abfd, eisd);
3131 return true;
3134 /* Create an EISD for section SEC.
3135 Return FALSE in case of failure. */
3137 static bool
3138 alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
3140 struct vms_internal_eisd_map *eisd;
3142 /* Only for allocating section. */
3143 if (!(sec->flags & SEC_ALLOC))
3144 return true;
3146 BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
3147 eisd = bfd_alloc (abfd, sizeof (*eisd));
3148 if (eisd == NULL)
3149 return false;
3150 vms_section_data (sec)->eisd = eisd;
3152 /* Fill the fields. */
3153 eisd->u.eisd.majorid = EISD__K_MAJORID;
3154 eisd->u.eisd.minorid = EISD__K_MINORID;
3155 eisd->u.eisd.eisdsize = EISD__K_LEN;
3156 eisd->u.eisd.secsize =
3157 (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
3158 eisd->u.eisd.virt_addr = sec->vma;
3159 eisd->u.eisd.flags = 0;
3160 eisd->u.eisd.vbn = 0; /* To be later defined. */
3161 eisd->u.eisd.pfc = 0; /* Default. */
3162 eisd->u.eisd.matchctl = EISD__K_MATALL;
3163 eisd->u.eisd.type = EISD__K_NORMAL;
3165 if (sec->flags & SEC_CODE)
3166 eisd->u.eisd.flags |= EISD__M_EXE;
3167 if (!(sec->flags & SEC_READONLY))
3168 eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
3170 /* If relocations or fixup will be applied, make this isect writeable. */
3171 if (sec->flags & SEC_RELOC)
3172 eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
3174 if (!(sec->flags & SEC_HAS_CONTENTS))
3176 eisd->u.eisd.flags |= EISD__M_DZRO;
3177 eisd->u.eisd.flags &= ~EISD__M_CRF;
3179 if (sec->flags & SEC_LINKER_CREATED)
3181 if (strcmp (sec->name, "$FIXUP$") == 0)
3182 eisd->u.eisd.flags |= EISD__M_FIXUPVEC;
3185 /* Append it to the list. */
3186 eisd->next = NULL;
3187 if (PRIV (eisd_head) == NULL)
3188 PRIV (eisd_head) = eisd;
3189 else
3190 PRIV (eisd_tail)->next = eisd;
3191 PRIV (eisd_tail) = eisd;
3193 return true;
3196 /* Layout executable ABFD and write it to the disk.
3197 Return FALSE in case of failure. */
3199 static bool
3200 alpha_vms_write_exec (bfd *abfd)
3202 struct vms_eihd eihd;
3203 struct vms_eiha *eiha;
3204 struct vms_eihi *eihi;
3205 struct vms_eihs *eihs = NULL;
3206 asection *sec;
3207 struct vms_internal_eisd_map *first_eisd;
3208 struct vms_internal_eisd_map *eisd;
3209 asection *dst;
3210 asection *dmt;
3211 file_ptr gst_filepos = 0;
3212 unsigned int lnkflags = 0;
3214 /* Build the EIHD. */
3215 PRIV (file_pos) = EIHD__C_LENGTH;
3217 memset (&eihd, 0, sizeof (eihd));
3218 memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2));
3220 bfd_putl32 (EIHD__K_MAJORID, eihd.majorid);
3221 bfd_putl32 (EIHD__K_MINORID, eihd.minorid);
3223 bfd_putl32 (sizeof (eihd), eihd.size);
3224 bfd_putl32 (0, eihd.isdoff);
3225 bfd_putl32 (0, eihd.activoff);
3226 bfd_putl32 (0, eihd.symdbgoff);
3227 bfd_putl32 (0, eihd.imgidoff);
3228 bfd_putl32 (0, eihd.patchoff);
3229 bfd_putl64 (0, eihd.iafva);
3230 bfd_putl32 (0, eihd.version_array_off);
3232 bfd_putl32 (EIHD__K_EXE, eihd.imgtype);
3233 bfd_putl32 (0, eihd.subtype);
3235 bfd_putl32 (0, eihd.imgiocnt);
3236 bfd_putl32 (-1, eihd.privreqs);
3237 bfd_putl32 (-1, eihd.privreqs + 4);
3239 bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
3240 eihd.hdrblkcnt);
3241 bfd_putl32 (0, eihd.ident);
3242 bfd_putl32 (0, eihd.sysver);
3244 eihd.matchctl = 0;
3245 bfd_putl32 (0, eihd.symvect_size);
3246 bfd_putl32 (16, eihd.virt_mem_block_size);
3247 bfd_putl32 (0, eihd.ext_fixup_off);
3248 bfd_putl32 (0, eihd.noopt_psect_off);
3249 bfd_putl16 (-1, eihd.alias);
3251 /* Alloc EIHA. */
3252 eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
3253 bfd_putl32 (PRIV (file_pos), eihd.activoff);
3254 PRIV (file_pos) += sizeof (struct vms_eiha);
3256 bfd_putl32 (sizeof (struct vms_eiha), eiha->size);
3257 bfd_putl32 (0, eiha->spare);
3258 bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1);
3259 bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2);
3260 bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3);
3261 bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4);
3262 bfd_putl64 (0, eiha->inishr);
3264 /* Alloc EIHI. */
3265 eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos));
3266 bfd_putl32 (PRIV (file_pos), eihd.imgidoff);
3267 PRIV (file_pos) += sizeof (struct vms_eihi);
3269 bfd_putl32 (EIHI__K_MAJORID, eihi->majorid);
3270 bfd_putl32 (EIHI__K_MINORID, eihi->minorid);
3272 char *module;
3273 unsigned int len;
3275 /* Set module name. */
3276 module = vms_get_module_name (bfd_get_filename (abfd), true);
3277 len = strlen (module);
3278 if (len > sizeof (eihi->imgnam) - 1)
3279 len = sizeof (eihi->imgnam) - 1;
3280 eihi->imgnam[0] = len;
3281 memcpy (eihi->imgnam + 1, module, len);
3282 free (module);
3285 unsigned int lo;
3286 unsigned int hi;
3288 /* Set time. */
3289 vms_get_time (&hi, &lo);
3290 bfd_putl32 (lo, eihi->linktime + 0);
3291 bfd_putl32 (hi, eihi->linktime + 4);
3293 eihi->imgid[0] = 0;
3294 eihi->linkid[0] = 0;
3295 eihi->imgbid[0] = 0;
3297 /* Alloc EIHS. */
3298 dst = PRIV (dst_section);
3299 dmt = bfd_get_section_by_name (abfd, "$DMT$");
3300 if (dst != NULL && dst->size != 0)
3302 eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos));
3303 bfd_putl32 (PRIV (file_pos), eihd.symdbgoff);
3304 PRIV (file_pos) += sizeof (struct vms_eihs);
3306 bfd_putl32 (EIHS__K_MAJORID, eihs->majorid);
3307 bfd_putl32 (EIHS__K_MINORID, eihs->minorid);
3308 bfd_putl32 (0, eihs->dstvbn);
3309 bfd_putl32 (0, eihs->dstsize);
3310 bfd_putl32 (0, eihs->gstvbn);
3311 bfd_putl32 (0, eihs->gstsize);
3312 bfd_putl32 (0, eihs->dmtvbn);
3313 bfd_putl32 (0, eihs->dmtsize);
3316 /* One EISD per section. */
3317 for (sec = abfd->sections; sec; sec = sec->next)
3319 if (!alpha_vms_create_eisd_for_section (abfd, sec))
3320 return false;
3323 /* Merge section EIDS which extra ones. */
3324 if (PRIV (eisd_tail))
3325 PRIV (eisd_tail)->next = PRIV (gbl_eisd_head);
3326 else
3327 PRIV (eisd_head) = PRIV (gbl_eisd_head);
3328 if (PRIV (gbl_eisd_tail))
3329 PRIV (eisd_tail) = PRIV (gbl_eisd_tail);
3331 first_eisd = PRIV (eisd_head);
3333 /* Add end of eisd. */
3334 if (first_eisd)
3336 eisd = bfd_zalloc (abfd, sizeof (*eisd));
3337 if (eisd == NULL)
3338 return false;
3339 eisd->u.eisd.majorid = 0;
3340 eisd->u.eisd.minorid = 0;
3341 eisd->u.eisd.eisdsize = 0;
3342 alpha_vms_append_extra_eisd (abfd, eisd);
3345 /* Place EISD in the file. */
3346 for (eisd = first_eisd; eisd; eisd = eisd->next)
3348 file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE);
3350 /* First block is a little bit special: there is a word at the end. */
3351 if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2)
3352 room -= 2;
3353 if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND)
3354 alpha_vms_file_position_block (abfd);
3356 eisd->file_pos = PRIV (file_pos);
3357 PRIV (file_pos) += eisd->u.eisd.eisdsize;
3359 if (eisd->u.eisd.flags & EISD__M_FIXUPVEC)
3360 bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva);
3363 if (first_eisd != NULL)
3365 bfd_putl32 (first_eisd->file_pos, eihd.isdoff);
3366 /* Real size of end of eisd marker. */
3367 PRIV (file_pos) += EISD__K_LENEND;
3370 bfd_putl32 (PRIV (file_pos), eihd.size);
3371 bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
3372 eihd.hdrblkcnt);
3374 /* Place sections. */
3375 for (sec = abfd->sections; sec; sec = sec->next)
3377 if (!(sec->flags & SEC_HAS_CONTENTS)
3378 || sec->contents == NULL)
3379 continue;
3381 eisd = vms_section_data (sec)->eisd;
3383 /* Align on a block. */
3384 alpha_vms_file_position_block (abfd);
3385 sec->filepos = PRIV (file_pos);
3387 if (eisd != NULL)
3388 eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1;
3390 PRIV (file_pos) += sec->size;
3393 /* Update EIHS. */
3394 if (eihs != NULL && dst != NULL)
3396 bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn);
3397 bfd_putl32 (dst->size, eihs->dstsize);
3399 if (dmt != NULL)
3401 lnkflags |= EIHD__M_DBGDMT;
3402 bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn);
3403 bfd_putl32 (dmt->size, eihs->dmtsize);
3405 if (PRIV (gsd_sym_count) != 0)
3407 alpha_vms_file_position_block (abfd);
3408 gst_filepos = PRIV (file_pos);
3409 bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn);
3410 bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize);
3414 /* Write EISD in hdr. */
3415 for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE;
3416 eisd = eisd->next)
3417 alpha_vms_swap_eisd_out
3418 (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos));
3420 /* Write first block. */
3421 bfd_putl32 (lnkflags, eihd.lnkflags);
3422 if (bfd_write (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
3423 return false;
3425 /* Write remaining eisd. */
3426 if (eisd != NULL)
3428 unsigned char blk[VMS_BLOCK_SIZE];
3429 struct vms_internal_eisd_map *next_eisd;
3431 memset (blk, 0xff, sizeof (blk));
3432 while (eisd != NULL)
3434 alpha_vms_swap_eisd_out
3435 (eisd,
3436 (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE)));
3438 next_eisd = eisd->next;
3439 if (next_eisd == NULL
3440 || (next_eisd->file_pos / VMS_BLOCK_SIZE
3441 != eisd->file_pos / VMS_BLOCK_SIZE))
3443 if (bfd_write (blk, sizeof (blk), abfd) != sizeof (blk))
3444 return false;
3446 memset (blk, 0xff, sizeof (blk));
3448 eisd = next_eisd;
3452 /* Write sections. */
3453 for (sec = abfd->sections; sec; sec = sec->next)
3455 unsigned char blk[VMS_BLOCK_SIZE];
3456 bfd_size_type len;
3458 if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS)
3459 || sec->contents == NULL)
3460 continue;
3461 if (bfd_write (sec->contents, sec->size, abfd) != sec->size)
3462 return false;
3464 /* Pad. */
3465 len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE;
3466 if (len != VMS_BLOCK_SIZE)
3468 memset (blk, 0, len);
3469 if (bfd_write (blk, len, abfd) != len)
3470 return false;
3474 /* Write GST. */
3475 if (gst_filepos != 0)
3477 struct vms_rec_wr *recwr = &PRIV (recwr);
3478 unsigned int i;
3480 if (!_bfd_vms_write_emh (abfd)
3481 || !_bfd_vms_write_lmn (abfd, "GNU LD"))
3482 return false;
3484 /* PSC for the absolute section. */
3485 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3486 _bfd_vms_output_long (recwr, 0);
3487 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3488 _bfd_vms_output_short (recwr, 0);
3489 _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD);
3490 _bfd_vms_output_long (recwr, 0);
3491 _bfd_vms_output_counted (recwr, ".$$ABS$$.");
3492 _bfd_vms_output_end_subrec (recwr);
3493 if (!_bfd_vms_output_end (abfd, recwr))
3494 return false;
3496 for (i = 0; i < PRIV (gsd_sym_count); i++)
3498 struct vms_symbol_entry *sym = PRIV (syms)[i];
3499 bfd_vma val;
3500 bfd_vma ep;
3502 if ((i % 5) == 0)
3504 _bfd_vms_output_alignment (recwr, 8);
3505 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3506 _bfd_vms_output_long (recwr, 0);
3508 _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG);
3509 _bfd_vms_output_short (recwr, 0); /* Data type, alignment. */
3510 _bfd_vms_output_short (recwr, sym->flags);
3512 if (sym->code_section)
3513 ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value);
3514 else
3516 BFD_ASSERT (sym->code_value == 0);
3517 ep = 0;
3519 val = alpha_vms_get_sym_value (sym->section, sym->value);
3520 _bfd_vms_output_quad
3521 (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val);
3522 _bfd_vms_output_quad (recwr, ep);
3523 _bfd_vms_output_quad (recwr, val);
3524 _bfd_vms_output_long (recwr, 0);
3525 _bfd_vms_output_counted (recwr, sym->name);
3526 _bfd_vms_output_end_subrec (recwr);
3527 if ((i % 5) == 4
3528 && !_bfd_vms_output_end (abfd, recwr))
3529 return false;
3531 if ((i % 5) != 0
3532 && !_bfd_vms_output_end (abfd, recwr))
3533 return false;
3535 if (!_bfd_vms_write_eeom (abfd))
3536 return false;
3538 return true;
3541 /* Object write. */
3543 /* Write section and symbol directory of bfd abfd. Return FALSE on error. */
3545 static bool
3546 _bfd_vms_write_egsd (bfd *abfd)
3548 asection *section;
3549 asymbol *symbol;
3550 unsigned int symnum;
3551 const char *sname;
3552 flagword new_flags, old_flags;
3553 int abs_section_index = -1;
3554 unsigned int target_index = 0;
3555 struct vms_rec_wr *recwr = &PRIV (recwr);
3557 vms_debug2 ((2, "vms_write_egsd\n"));
3559 /* Egsd is quadword aligned. */
3560 _bfd_vms_output_alignment (recwr, 8);
3562 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3563 _bfd_vms_output_long (recwr, 0);
3565 /* Number sections. */
3566 for (section = abfd->sections; section != NULL; section = section->next)
3568 if (section->flags & SEC_DEBUGGING)
3569 continue;
3570 if (!strcmp (section->name, ".vmsdebug"))
3572 section->flags |= SEC_DEBUGGING;
3573 continue;
3575 section->target_index = target_index++;
3578 for (section = abfd->sections; section != NULL; section = section->next)
3580 vms_debug2 ((3, "Section #%d %s, %d bytes\n",
3581 section->target_index, section->name, (int)section->size));
3583 /* Don't write out the VMS debug info section since it is in the
3584 ETBT and EDBG sections in etir. */
3585 if (section->flags & SEC_DEBUGGING)
3586 continue;
3588 /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
3589 if (_bfd_vms_output_check (recwr, 64) < 0)
3591 if (!_bfd_vms_output_end (abfd, recwr))
3592 return false;
3593 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3594 _bfd_vms_output_long (recwr, 0);
3597 /* Don't know if this is necessary for the linker but for now it keeps
3598 vms_slurp_gsd happy. */
3599 sname = section->name;
3600 if (*sname == '.')
3602 /* Remove leading dot. */
3603 sname++;
3604 if ((*sname == 't') && (strcmp (sname, "text") == 0))
3605 sname = EVAX_CODE_NAME;
3606 else if ((*sname == 'd') && (strcmp (sname, "data") == 0))
3607 sname = EVAX_DATA_NAME;
3608 else if ((*sname == 'b') && (strcmp (sname, "bss") == 0))
3609 sname = EVAX_BSS_NAME;
3610 else if ((*sname == 'l') && (strcmp (sname, "link") == 0))
3611 sname = EVAX_LINK_NAME;
3612 else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0))
3613 sname = EVAX_READONLY_NAME;
3614 else if ((*sname == 'l') && (strcmp (sname, "literal") == 0))
3615 sname = EVAX_LITERAL_NAME;
3616 else if ((*sname == 'l') && (strcmp (sname, "literals") == 0))
3617 sname = EVAX_LITERALS_NAME;
3618 else if ((*sname == 'c') && (strcmp (sname, "comm") == 0))
3619 sname = EVAX_COMMON_NAME;
3620 else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
3621 sname = EVAX_LOCAL_NAME;
3624 if (bfd_is_com_section (section))
3625 new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD
3626 | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM);
3627 else
3628 new_flags = vms_esecflag_by_name (evax_section_flags, sname,
3629 section->size > 0);
3631 /* Modify them as directed. */
3632 if (section->flags & SEC_READONLY)
3633 new_flags &= ~EGPS__V_WRT;
3635 new_flags &= ~vms_section_data (section)->no_flags;
3636 new_flags |= vms_section_data (section)->flags;
3638 vms_debug2 ((3, "sec flags %x\n", section->flags));
3639 vms_debug2 ((3, "new_flags %x, _raw_size %lu\n",
3640 new_flags, (unsigned long)section->size));
3642 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3643 _bfd_vms_output_short (recwr, section->alignment_power & 0xff);
3644 _bfd_vms_output_short (recwr, new_flags);
3645 _bfd_vms_output_long (recwr, (unsigned long) section->size);
3646 _bfd_vms_output_counted (recwr, sname);
3647 _bfd_vms_output_end_subrec (recwr);
3649 /* If the section is an obsolute one, remind its index as it will be
3650 used later for absolute symbols. */
3651 if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0)
3652 abs_section_index = section->target_index;
3655 /* Output symbols. */
3656 vms_debug2 ((3, "%d symbols found\n", abfd->symcount));
3658 bfd_set_start_address (abfd, (bfd_vma) -1);
3660 for (symnum = 0; symnum < abfd->symcount; symnum++)
3662 symbol = abfd->outsymbols[symnum];
3663 old_flags = symbol->flags;
3665 /* Work-around a missing feature: consider __main as the main entry
3666 point. */
3667 if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0)
3668 bfd_set_start_address (abfd, (bfd_vma)symbol->value);
3670 /* Only put in the GSD the global and the undefined symbols. */
3671 if (old_flags & BSF_FILE)
3672 continue;
3674 if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section))
3676 /* If the LIB$INITIIALIZE section is present, add a reference to
3677 LIB$INITIALIZE symbol. FIXME: this should be done explicitely
3678 in the assembly file. */
3679 if (!((old_flags & BSF_SECTION_SYM) != 0
3680 && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0))
3681 continue;
3684 /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. Add 16 more
3685 bytes for a possible ABS section. */
3686 if (_bfd_vms_output_check (recwr, 80 + 16) < 0)
3688 if (!_bfd_vms_output_end (abfd, recwr))
3689 return false;
3690 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3691 _bfd_vms_output_long (recwr, 0);
3694 if ((old_flags & BSF_GLOBAL) != 0
3695 && bfd_is_abs_section (symbol->section)
3696 && abs_section_index <= 0)
3698 /* Create an absolute section if none was defined. It is highly
3699 unlikely that the name $ABS$ clashes with a user defined
3700 non-absolute section name. */
3701 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3702 _bfd_vms_output_short (recwr, 4);
3703 _bfd_vms_output_short (recwr, EGPS__V_SHR);
3704 _bfd_vms_output_long (recwr, 0);
3705 _bfd_vms_output_counted (recwr, "$ABS$");
3706 _bfd_vms_output_end_subrec (recwr);
3708 abs_section_index = target_index++;
3711 _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM);
3713 /* Data type, alignment. */
3714 _bfd_vms_output_short (recwr, 0);
3716 new_flags = 0;
3718 if (old_flags & BSF_WEAK)
3719 new_flags |= EGSY__V_WEAK;
3720 if (bfd_is_com_section (symbol->section)) /* .comm */
3721 new_flags |= (EGSY__V_WEAK | EGSY__V_COMM);
3723 if (old_flags & BSF_FUNCTION)
3725 new_flags |= EGSY__V_NORM;
3726 new_flags |= EGSY__V_REL;
3728 if (old_flags & BSF_GLOBAL)
3730 new_flags |= EGSY__V_DEF;
3731 if (!bfd_is_abs_section (symbol->section))
3732 new_flags |= EGSY__V_REL;
3734 _bfd_vms_output_short (recwr, new_flags);
3736 if (old_flags & BSF_GLOBAL)
3738 /* Symbol definition. */
3739 bfd_vma code_address = 0;
3740 unsigned long ca_psindx = 0;
3741 unsigned long psindx;
3743 if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL)
3745 asymbol *sym;
3747 sym =
3748 ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym;
3749 code_address = sym->value;
3750 ca_psindx = sym->section->target_index;
3752 if (bfd_is_abs_section (symbol->section))
3753 psindx = abs_section_index;
3754 else
3755 psindx = symbol->section->target_index;
3757 _bfd_vms_output_quad (recwr, symbol->value);
3758 _bfd_vms_output_quad (recwr, code_address);
3759 _bfd_vms_output_long (recwr, ca_psindx);
3760 _bfd_vms_output_long (recwr, psindx);
3762 _bfd_vms_output_counted (recwr, symbol->name);
3764 _bfd_vms_output_end_subrec (recwr);
3767 _bfd_vms_output_alignment (recwr, 8);
3768 return _bfd_vms_output_end (abfd, recwr);
3771 /* Write object header for bfd abfd. Return FALSE on error. */
3773 static bool
3774 _bfd_vms_write_ehdr (bfd *abfd)
3776 asymbol *symbol;
3777 unsigned int symnum;
3778 struct vms_rec_wr *recwr = &PRIV (recwr);
3780 vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
3782 _bfd_vms_output_alignment (recwr, 2);
3784 if (!_bfd_vms_write_emh (abfd)
3785 || !_bfd_vms_write_lmn (abfd, "GNU AS"))
3786 return false;
3788 /* SRC. */
3789 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3790 _bfd_vms_output_short (recwr, EMH__C_SRC);
3792 for (symnum = 0; symnum < abfd->symcount; symnum++)
3794 symbol = abfd->outsymbols[symnum];
3796 if (symbol->flags & BSF_FILE)
3798 _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name,
3799 (int) strlen (symbol->name));
3800 break;
3804 if (symnum == abfd->symcount)
3805 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
3807 if (!_bfd_vms_output_end (abfd, recwr))
3808 return false;
3810 /* TTL. */
3811 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3812 _bfd_vms_output_short (recwr, EMH__C_TTL);
3813 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
3814 if (!_bfd_vms_output_end (abfd, recwr))
3815 return false;
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 return _bfd_vms_output_end (abfd, recwr);
3826 /* Part 4.6, relocations. */
3829 /* WRITE ETIR SECTION
3831 This is still under construction and therefore not documented. */
3833 /* Close the etir/etbt record. */
3835 static bool
3836 end_etir_record (bfd * abfd)
3838 struct vms_rec_wr *recwr = &PRIV (recwr);
3840 return _bfd_vms_output_end (abfd, recwr);
3843 static void
3844 start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset)
3846 struct vms_rec_wr *recwr = &PRIV (recwr);
3848 if (section->flags & SEC_DEBUGGING)
3850 _bfd_vms_output_begin (recwr, EOBJ__C_ETBT);
3852 if (offset == 0)
3854 /* Push start offset. */
3855 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3856 _bfd_vms_output_long (recwr, (unsigned long) 0);
3857 _bfd_vms_output_end_subrec (recwr);
3859 /* Set location. */
3860 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC);
3861 _bfd_vms_output_end_subrec (recwr);
3864 else
3866 _bfd_vms_output_begin (recwr, EOBJ__C_ETIR);
3868 if (offset == 0)
3870 /* Push start offset. */
3871 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3872 _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
3873 _bfd_vms_output_quad (recwr, offset);
3874 _bfd_vms_output_end_subrec (recwr);
3876 /* Start = pop (). */
3877 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB);
3878 _bfd_vms_output_end_subrec (recwr);
3883 /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual
3884 address VADDR in section specified by SEC_INDEX and NAME. */
3886 static bool
3887 sto_imm (bfd *abfd, asection *section,
3888 bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr)
3890 bfd_size_type size;
3891 struct vms_rec_wr *recwr = &PRIV (recwr);
3893 #if VMS_DEBUG
3894 _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize);
3895 _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr);
3896 #endif
3898 while (ssize > 0)
3900 /* Try all the rest. */
3901 size = ssize;
3903 if (_bfd_vms_output_check (recwr, size) < 0)
3905 /* Doesn't fit, split ! */
3906 if (!end_etir_record (abfd))
3907 return false;
3909 start_etir_or_etbt_record (abfd, section, vaddr);
3911 size = _bfd_vms_output_check (recwr, 0); /* get max size */
3912 if (size > ssize) /* more than what's left ? */
3913 size = ssize;
3916 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM);
3917 _bfd_vms_output_long (recwr, (unsigned long) (size));
3918 _bfd_vms_output_dump (recwr, cptr, size);
3919 _bfd_vms_output_end_subrec (recwr);
3921 #if VMS_DEBUG
3922 _bfd_vms_debug (10, "dumped %d bytes\n", (int) size);
3923 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
3924 #endif
3926 vaddr += size;
3927 cptr += size;
3928 ssize -= size;
3930 return true;
3933 static bool
3934 etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
3936 if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0)
3938 /* Not enough room in this record. Close it and open a new one. */
3939 if (!end_etir_record (abfd))
3940 return false;
3941 start_etir_or_etbt_record (abfd, section, vaddr);
3943 return true;
3946 /* Return whether RELOC must be deferred till the end. */
3948 static bool
3949 defer_reloc_p (arelent *reloc)
3951 switch (reloc->howto->type)
3953 case ALPHA_R_NOP:
3954 case ALPHA_R_LDA:
3955 case ALPHA_R_BSR:
3956 case ALPHA_R_BOH:
3957 return true;
3959 default:
3960 return false;
3964 /* Write section contents for bfd abfd. Return FALSE on error. */
3966 static bool
3967 _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
3969 asection *section;
3970 struct vms_rec_wr *recwr = &PRIV (recwr);
3972 vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype));
3974 _bfd_vms_output_alignment (recwr, 4);
3976 PRIV (vms_linkage_index) = 0;
3978 for (section = abfd->sections; section; section = section->next)
3980 vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n",
3981 section->target_index, section->name, (int) (section->size)));
3983 if (!(section->flags & SEC_HAS_CONTENTS)
3984 || bfd_is_com_section (section))
3985 continue;
3987 if (!section->contents)
3989 bfd_set_error (bfd_error_no_contents);
3990 return false;
3993 start_etir_or_etbt_record (abfd, section, 0);
3995 if (section->flags & SEC_RELOC)
3997 bfd_vma curr_addr = 0;
3998 unsigned char *curr_data = section->contents;
3999 bfd_size_type size;
4000 int pass2_needed = 0;
4001 int pass2_in_progress = 0;
4002 unsigned int irel;
4004 if (section->reloc_count == 0)
4005 _bfd_error_handler
4006 (_("SEC_RELOC with no relocs in section %pA"), section);
4008 #if VMS_DEBUG
4009 else
4011 int i = section->reloc_count;
4012 arelent **rptr = section->orelocation;
4013 _bfd_vms_debug (4, "%d relocations:\n", i);
4014 while (i-- > 0)
4016 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, "
4017 "addr %08lx, off %08lx, len %d: %s\n",
4018 (*(*rptr)->sym_ptr_ptr)->name,
4019 (*(*rptr)->sym_ptr_ptr)->section->name,
4020 (long) (*(*rptr)->sym_ptr_ptr)->value,
4021 (unsigned long)(*rptr)->address,
4022 (unsigned long)(*rptr)->addend,
4023 bfd_get_reloc_size ((*rptr)->howto),
4024 ( *rptr)->howto->name);
4025 rptr++;
4028 #endif
4030 new_pass:
4031 for (irel = 0; irel < section->reloc_count; irel++)
4033 struct evax_private_udata_struct *udata;
4034 arelent *rptr = section->orelocation [irel];
4035 bfd_vma addr = rptr->address;
4036 asymbol *sym = *rptr->sym_ptr_ptr;
4037 asection *sec = sym->section;
4038 bool defer = defer_reloc_p (rptr);
4039 unsigned int slen;
4041 if (pass2_in_progress)
4043 /* Non-deferred relocs have already been output. */
4044 if (!defer)
4045 continue;
4047 else
4049 /* Deferred relocs must be output at the very end. */
4050 if (defer)
4052 pass2_needed = 1;
4053 continue;
4056 /* Regular relocs are intertwined with binary data. */
4057 if (curr_addr > addr)
4058 _bfd_error_handler (_("size error in section %pA"),
4059 section);
4060 size = addr - curr_addr;
4061 if (!sto_imm (abfd, section, size, curr_data, curr_addr))
4062 return false;
4063 curr_data += size;
4064 curr_addr += size;
4067 size = bfd_get_reloc_size (rptr->howto);
4069 switch (rptr->howto->type)
4071 case ALPHA_R_IGNORE:
4072 break;
4074 case ALPHA_R_REFLONG:
4075 if (bfd_is_und_section (sym->section))
4077 bfd_vma addend = rptr->addend;
4078 slen = strlen ((char *) sym->name);
4079 if (!etir_output_check (abfd, section, curr_addr, slen))
4080 return false;
4081 if (addend)
4083 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
4084 _bfd_vms_output_counted (recwr, sym->name);
4085 _bfd_vms_output_end_subrec (recwr);
4086 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
4087 _bfd_vms_output_long (recwr, (unsigned long) addend);
4088 _bfd_vms_output_end_subrec (recwr);
4089 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
4090 _bfd_vms_output_end_subrec (recwr);
4091 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
4092 _bfd_vms_output_end_subrec (recwr);
4094 else
4096 _bfd_vms_output_begin_subrec
4097 (recwr, ETIR__C_STO_GBL_LW);
4098 _bfd_vms_output_counted (recwr, sym->name);
4099 _bfd_vms_output_end_subrec (recwr);
4102 else if (bfd_is_abs_section (sym->section))
4104 if (!etir_output_check (abfd, section, curr_addr, 16))
4105 return false;
4106 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
4107 _bfd_vms_output_long (recwr, (unsigned long) sym->value);
4108 _bfd_vms_output_end_subrec (recwr);
4109 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
4110 _bfd_vms_output_end_subrec (recwr);
4112 else
4114 if (!etir_output_check (abfd, section, curr_addr, 32))
4115 return false;
4116 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
4117 _bfd_vms_output_long (recwr,
4118 (unsigned long) sec->target_index);
4119 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
4120 _bfd_vms_output_end_subrec (recwr);
4121 /* ??? Table B-8 of the OpenVMS Linker Utilily Manual
4122 says that we should have a ETIR__C_STO_OFF here.
4123 But the relocation would not be BFD_RELOC_32 then.
4124 This case is very likely unreachable. */
4125 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
4126 _bfd_vms_output_end_subrec (recwr);
4128 break;
4130 case ALPHA_R_REFQUAD:
4131 if (bfd_is_und_section (sym->section))
4133 bfd_vma addend = rptr->addend;
4134 slen = strlen ((char *) sym->name);
4135 if (!etir_output_check (abfd, section, curr_addr, slen))
4136 return false;
4137 if (addend)
4139 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
4140 _bfd_vms_output_counted (recwr, sym->name);
4141 _bfd_vms_output_end_subrec (recwr);
4142 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
4143 _bfd_vms_output_quad (recwr, addend);
4144 _bfd_vms_output_end_subrec (recwr);
4145 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
4146 _bfd_vms_output_end_subrec (recwr);
4147 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
4148 _bfd_vms_output_end_subrec (recwr);
4150 else
4152 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL);
4153 _bfd_vms_output_counted (recwr, sym->name);
4154 _bfd_vms_output_end_subrec (recwr);
4157 else if (bfd_is_abs_section (sym->section))
4159 if (!etir_output_check (abfd, section, curr_addr, 16))
4160 return false;
4161 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
4162 _bfd_vms_output_quad (recwr, sym->value);
4163 _bfd_vms_output_end_subrec (recwr);
4164 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
4165 _bfd_vms_output_end_subrec (recwr);
4167 else
4169 if (!etir_output_check (abfd, section, curr_addr, 32))
4170 return false;
4171 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
4172 _bfd_vms_output_long (recwr,
4173 (unsigned long) sec->target_index);
4174 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
4175 _bfd_vms_output_end_subrec (recwr);
4176 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF);
4177 _bfd_vms_output_end_subrec (recwr);
4179 break;
4181 case ALPHA_R_HINT:
4182 if (!sto_imm (abfd, section, size, curr_data, curr_addr))
4183 return false;
4184 break;
4186 case ALPHA_R_LINKAGE:
4187 size = 16;
4188 if (!etir_output_check (abfd, section, curr_addr, 64))
4189 return false;
4190 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
4191 _bfd_vms_output_long
4192 (recwr, (unsigned long) rptr->addend);
4193 if (rptr->addend > PRIV (vms_linkage_index))
4194 PRIV (vms_linkage_index) = rptr->addend;
4195 _bfd_vms_output_counted (recwr, sym->name);
4196 _bfd_vms_output_byte (recwr, 0);
4197 _bfd_vms_output_end_subrec (recwr);
4198 break;
4200 case ALPHA_R_CODEADDR:
4201 slen = strlen ((char *) sym->name);
4202 if (!etir_output_check (abfd, section, curr_addr, slen))
4203 return false;
4204 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
4205 _bfd_vms_output_counted (recwr, sym->name);
4206 _bfd_vms_output_end_subrec (recwr);
4207 break;
4209 case ALPHA_R_NOP:
4210 udata
4211 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
4212 if (!etir_output_check (abfd, section, curr_addr,
4213 32 + 1 + strlen (udata->origname)))
4214 return false;
4215 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
4216 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
4217 _bfd_vms_output_long
4218 (recwr, (unsigned long) section->target_index);
4219 _bfd_vms_output_quad (recwr, rptr->address);
4220 _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f);
4221 _bfd_vms_output_long
4222 (recwr, (unsigned long) section->target_index);
4223 _bfd_vms_output_quad (recwr, rptr->addend);
4224 _bfd_vms_output_counted (recwr, udata->origname);
4225 _bfd_vms_output_end_subrec (recwr);
4226 break;
4228 case ALPHA_R_BSR:
4229 _bfd_error_handler (_("spurious ALPHA_R_BSR reloc"));
4230 break;
4232 case ALPHA_R_LDA:
4233 udata
4234 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
4235 if (!etir_output_check (abfd, section, curr_addr,
4236 32 + 1 + strlen (udata->origname)))
4237 return false;
4238 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL);
4239 _bfd_vms_output_long
4240 (recwr, (unsigned long) udata->lkindex + 1);
4241 _bfd_vms_output_long
4242 (recwr, (unsigned long) section->target_index);
4243 _bfd_vms_output_quad (recwr, rptr->address);
4244 _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000);
4245 _bfd_vms_output_long
4246 (recwr, (unsigned long) udata->bsym->section->target_index);
4247 _bfd_vms_output_quad (recwr, rptr->addend);
4248 _bfd_vms_output_counted (recwr, udata->origname);
4249 _bfd_vms_output_end_subrec (recwr);
4250 break;
4252 case ALPHA_R_BOH:
4253 udata
4254 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
4255 if (!etir_output_check (abfd, section, curr_addr,
4256 32 + 1 + strlen (udata->origname)))
4257 return false;
4258 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
4259 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
4260 _bfd_vms_output_long
4261 (recwr, (unsigned long) section->target_index);
4262 _bfd_vms_output_quad (recwr, rptr->address);
4263 _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000);
4264 _bfd_vms_output_long
4265 (recwr, (unsigned long) section->target_index);
4266 _bfd_vms_output_quad (recwr, rptr->addend);
4267 _bfd_vms_output_counted (recwr, udata->origname);
4268 _bfd_vms_output_end_subrec (recwr);
4269 break;
4271 default:
4272 _bfd_error_handler (_("unhandled relocation %s"),
4273 rptr->howto->name);
4274 break;
4277 curr_data += size;
4278 curr_addr += size;
4279 } /* End of relocs loop. */
4281 if (!pass2_in_progress)
4283 /* Output rest of section. */
4284 if (curr_addr > section->size)
4286 _bfd_error_handler (_("size error in section %pA"), section);
4287 return false;
4289 size = section->size - curr_addr;
4290 if (!sto_imm (abfd, section, size, curr_data, curr_addr))
4291 return false;
4292 curr_data += size;
4293 curr_addr += size;
4295 if (pass2_needed)
4297 pass2_in_progress = 1;
4298 goto new_pass;
4303 else /* (section->flags & SEC_RELOC) */
4304 if (!sto_imm (abfd, section, section->size, section->contents, 0))
4305 return false;
4307 if (!end_etir_record (abfd))
4308 return false;
4311 _bfd_vms_output_alignment (recwr, 2);
4312 return true;
4315 /* Write cached information into a file being written, at bfd_close. */
4317 static bool
4318 alpha_vms_write_object_contents (bfd *abfd)
4320 vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
4322 if (abfd->flags & (EXEC_P | DYNAMIC))
4324 return alpha_vms_write_exec (abfd);
4326 else
4328 if (abfd->section_count > 0) /* we have sections */
4330 if (!_bfd_vms_write_ehdr (abfd))
4331 return false;
4332 if (!_bfd_vms_write_egsd (abfd))
4333 return false;
4334 if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR))
4335 return false;
4336 if (!_bfd_vms_write_eeom (abfd))
4337 return false;
4340 return true;
4343 /* Debug stuff: nearest line. */
4345 #define SET_MODULE_PARSED(m) \
4346 do { if ((m)->name == NULL) (m)->name = ""; } while (0)
4347 #define IS_MODULE_PARSED(m) ((m)->name != NULL)
4349 /* Build a new module for the specified BFD. */
4351 static struct module *
4352 new_module (bfd *abfd)
4354 struct module *module
4355 = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
4356 module->file_table_count = 16; /* Arbitrary. */
4357 module->file_table
4358 = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo));
4359 return module;
4362 /* Parse debug info for a module and internalize it. */
4364 static bool
4365 parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
4366 bfd_size_type length)
4368 unsigned char *maxptr = ptr + length;
4369 unsigned char *src_ptr, *pcl_ptr;
4370 unsigned int prev_linum = 0, curr_linenum = 0;
4371 bfd_vma prev_pc = 0, curr_pc = 0;
4372 struct srecinfo *curr_srec, *srec;
4373 struct lineinfo *curr_line, *line;
4374 struct funcinfo *funcinfo;
4376 /* Initialize tables with zero element. */
4377 curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4378 if (!curr_srec)
4379 return false;
4380 module->srec_table = curr_srec;
4382 curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4383 if (!curr_line)
4384 return false;
4385 module->line_table = curr_line;
4387 while (ptr + 3 < maxptr)
4389 /* The first byte is not counted in the recorded length. */
4390 int rec_length = bfd_getl16 (ptr) + 1;
4391 int rec_type = bfd_getl16 (ptr + 2);
4393 vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
4395 if (rec_length > maxptr - ptr)
4396 break;
4397 if (rec_type == DST__K_MODEND)
4398 break;
4400 switch (rec_type)
4402 case DST__K_MODBEG:
4403 if (rec_length <= DST_S_B_MODBEG_NAME)
4404 break;
4405 module->name
4406 = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME,
4407 rec_length - DST_S_B_MODBEG_NAME);
4409 curr_pc = 0;
4410 prev_pc = 0;
4411 curr_linenum = 0;
4412 prev_linum = 0;
4414 vms_debug2 ((3, "module: %s\n", module->name));
4415 break;
4417 case DST__K_MODEND:
4418 break;
4420 case DST__K_RTNBEG:
4421 if (rec_length <= DST_S_B_RTNBEG_NAME)
4422 break;
4423 funcinfo = (struct funcinfo *)
4424 bfd_zalloc (abfd, sizeof (struct funcinfo));
4425 if (!funcinfo)
4426 return false;
4427 funcinfo->name
4428 = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME,
4429 rec_length - DST_S_B_RTNBEG_NAME);
4430 funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
4431 funcinfo->next = module->func_table;
4432 module->func_table = funcinfo;
4434 vms_debug2 ((3, "routine: %s at 0x%lx\n",
4435 funcinfo->name, (unsigned long) funcinfo->low));
4436 break;
4438 case DST__K_RTNEND:
4439 if (rec_length < DST_S_L_RTNEND_SIZE + 4)
4440 break;
4441 if (!module->func_table)
4442 return false;
4443 module->func_table->high = module->func_table->low
4444 + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1;
4446 if (module->func_table->high > module->high)
4447 module->high = module->func_table->high;
4449 vms_debug2 ((3, "end routine\n"));
4450 break;
4452 case DST__K_PROLOG:
4453 vms_debug2 ((3, "prologue\n"));
4454 break;
4456 case DST__K_EPILOG:
4457 vms_debug2 ((3, "epilog\n"));
4458 break;
4460 case DST__K_BLKBEG:
4461 vms_debug2 ((3, "block\n"));
4462 break;
4464 case DST__K_BLKEND:
4465 vms_debug2 ((3, "end block\n"));
4466 break;
4468 case DST__K_SOURCE:
4469 src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE;
4471 vms_debug2 ((3, "source info\n"));
4473 while (src_ptr - ptr < rec_length)
4475 int cmd = src_ptr[0], cmd_length, data;
4477 switch (cmd)
4479 case DST__K_SRC_DECLFILE:
4480 if (src_ptr - ptr + DST_S_B_SRC_DF_LENGTH >= rec_length)
4481 cmd_length = 0x10000;
4482 else
4483 cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2;
4484 break;
4486 case DST__K_SRC_DEFLINES_B:
4487 cmd_length = 2;
4488 break;
4490 case DST__K_SRC_DEFLINES_W:
4491 cmd_length = 3;
4492 break;
4494 case DST__K_SRC_INCRLNUM_B:
4495 cmd_length = 2;
4496 break;
4498 case DST__K_SRC_SETFILE:
4499 cmd_length = 3;
4500 break;
4502 case DST__K_SRC_SETLNUM_L:
4503 cmd_length = 5;
4504 break;
4506 case DST__K_SRC_SETLNUM_W:
4507 cmd_length = 3;
4508 break;
4510 case DST__K_SRC_SETREC_L:
4511 cmd_length = 5;
4512 break;
4514 case DST__K_SRC_SETREC_W:
4515 cmd_length = 3;
4516 break;
4518 case DST__K_SRC_FORMFEED:
4519 cmd_length = 1;
4520 break;
4522 default:
4523 cmd_length = 2;
4524 break;
4527 if (src_ptr - ptr + cmd_length > rec_length)
4528 break;
4530 switch (cmd)
4532 case DST__K_SRC_DECLFILE:
4534 unsigned int fileid
4535 = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
4536 char *filename = _bfd_vms_save_counted_string
4537 (abfd,
4538 src_ptr + DST_S_B_SRC_DF_FILENAME,
4539 ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME));
4541 if (fileid >= module->file_table_count)
4543 unsigned int old_count = module->file_table_count;
4544 module->file_table_count += fileid;
4545 module->file_table
4546 = bfd_realloc_or_free (module->file_table,
4547 module->file_table_count
4548 * sizeof (struct fileinfo));
4549 if (module->file_table == NULL)
4550 return false;
4551 memset (module->file_table + old_count, 0,
4552 fileid * sizeof (struct fileinfo));
4555 module->file_table [fileid].name = filename;
4556 module->file_table [fileid].srec = 1;
4557 vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
4558 fileid, module->file_table [fileid].name));
4560 break;
4562 case DST__K_SRC_DEFLINES_B:
4563 /* Perform the association and set the next higher index
4564 to the limit. */
4565 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4566 srec = (struct srecinfo *)
4567 bfd_zalloc (abfd, sizeof (struct srecinfo));
4568 srec->line = curr_srec->line + data;
4569 srec->srec = curr_srec->srec + data;
4570 srec->sfile = curr_srec->sfile;
4571 curr_srec->next = srec;
4572 curr_srec = srec;
4573 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data));
4574 break;
4576 case DST__K_SRC_DEFLINES_W:
4577 /* Perform the association and set the next higher index
4578 to the limit. */
4579 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4580 srec = (struct srecinfo *)
4581 bfd_zalloc (abfd, sizeof (struct srecinfo));
4582 srec->line = curr_srec->line + data;
4583 srec->srec = curr_srec->srec + data,
4584 srec->sfile = curr_srec->sfile;
4585 curr_srec->next = srec;
4586 curr_srec = srec;
4587 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data));
4588 break;
4590 case DST__K_SRC_INCRLNUM_B:
4591 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4592 curr_srec->line += data;
4593 vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data));
4594 break;
4596 case DST__K_SRC_SETFILE:
4597 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4598 if ((unsigned int) data < module->file_table_count)
4600 curr_srec->sfile = data;
4601 curr_srec->srec = module->file_table[data].srec;
4603 vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data));
4604 break;
4606 case DST__K_SRC_SETLNUM_L:
4607 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4608 curr_srec->line = data;
4609 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data));
4610 break;
4612 case DST__K_SRC_SETLNUM_W:
4613 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4614 curr_srec->line = data;
4615 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data));
4616 break;
4618 case DST__K_SRC_SETREC_L:
4619 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4620 curr_srec->srec = data;
4621 module->file_table[curr_srec->sfile].srec = data;
4622 vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data));
4623 break;
4625 case DST__K_SRC_SETREC_W:
4626 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4627 curr_srec->srec = data;
4628 module->file_table[curr_srec->sfile].srec = data;
4629 vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data));
4630 break;
4632 case DST__K_SRC_FORMFEED:
4633 vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n"));
4634 break;
4636 default:
4637 _bfd_error_handler (_("unknown source command %d"),
4638 cmd);
4639 break;
4642 src_ptr += cmd_length;
4644 break;
4646 case DST__K_LINE_NUM:
4647 pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE;
4649 vms_debug2 ((3, "line info\n"));
4651 while (pcl_ptr - ptr < rec_length)
4653 /* The command byte is signed so we must sign-extend it. */
4654 int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data;
4656 switch (cmd)
4658 case DST__K_DELTA_PC_W:
4659 cmd_length = 3;
4660 break;
4662 case DST__K_DELTA_PC_L:
4663 cmd_length = 5;
4664 break;
4666 case DST__K_INCR_LINUM:
4667 cmd_length = 2;
4668 break;
4670 case DST__K_INCR_LINUM_W:
4671 cmd_length = 3;
4672 break;
4674 case DST__K_INCR_LINUM_L:
4675 cmd_length = 5;
4676 break;
4678 case DST__K_SET_LINUM_INCR:
4679 cmd_length = 2;
4680 break;
4682 case DST__K_SET_LINUM_INCR_W:
4683 cmd_length = 3;
4684 break;
4686 case DST__K_RESET_LINUM_INCR:
4687 cmd_length = 1;
4688 break;
4690 case DST__K_BEG_STMT_MODE:
4691 cmd_length = 1;
4692 break;
4694 case DST__K_END_STMT_MODE:
4695 cmd_length = 1;
4696 break;
4698 case DST__K_SET_LINUM_B:
4699 cmd_length = 2;
4700 break;
4702 case DST__K_SET_LINUM:
4703 cmd_length = 3;
4704 break;
4706 case DST__K_SET_LINUM_L:
4707 cmd_length = 5;
4708 break;
4710 case DST__K_SET_PC:
4711 cmd_length = 2;
4712 break;
4714 case DST__K_SET_PC_W:
4715 cmd_length = 3;
4716 break;
4718 case DST__K_SET_PC_L:
4719 cmd_length = 5;
4720 break;
4722 case DST__K_SET_STMTNUM:
4723 cmd_length = 2;
4724 break;
4726 case DST__K_TERM:
4727 cmd_length = 2;
4728 break;
4730 case DST__K_TERM_W:
4731 cmd_length = 3;
4732 break;
4734 case DST__K_TERM_L:
4735 cmd_length = 5;
4736 break;
4738 case DST__K_SET_ABS_PC:
4739 cmd_length = 5;
4740 break;
4742 default:
4743 if (cmd <= 0)
4744 cmd_length = 1;
4745 else
4746 cmd_length = 2;
4747 break;
4750 if (pcl_ptr - ptr + cmd_length > rec_length)
4751 break;
4753 switch (cmd)
4755 case DST__K_DELTA_PC_W:
4756 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4757 curr_pc += data;
4758 curr_linenum += 1;
4759 vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data));
4760 break;
4762 case DST__K_DELTA_PC_L:
4763 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4764 curr_pc += data;
4765 curr_linenum += 1;
4766 vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data));
4767 break;
4769 case DST__K_INCR_LINUM:
4770 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4771 curr_linenum += data;
4772 vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data));
4773 break;
4775 case DST__K_INCR_LINUM_W:
4776 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4777 curr_linenum += data;
4778 vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data));
4779 break;
4781 case DST__K_INCR_LINUM_L:
4782 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4783 curr_linenum += data;
4784 vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data));
4785 break;
4787 case DST__K_SET_LINUM_INCR:
4788 _bfd_error_handler
4789 (_("%s not implemented"), "DST__K_SET_LINUM_INCR");
4790 break;
4792 case DST__K_SET_LINUM_INCR_W:
4793 _bfd_error_handler
4794 (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W");
4795 break;
4797 case DST__K_RESET_LINUM_INCR:
4798 _bfd_error_handler
4799 (_("%s not implemented"), "DST__K_RESET_LINUM_INCR");
4800 break;
4802 case DST__K_BEG_STMT_MODE:
4803 _bfd_error_handler
4804 (_("%s not implemented"), "DST__K_BEG_STMT_MODE");
4805 break;
4807 case DST__K_END_STMT_MODE:
4808 _bfd_error_handler
4809 (_("%s not implemented"), "DST__K_END_STMT_MODE");
4810 break;
4812 case DST__K_SET_LINUM_B:
4813 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4814 curr_linenum = data;
4815 vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data));
4816 break;
4818 case DST__K_SET_LINUM:
4819 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4820 curr_linenum = data;
4821 vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data));
4822 break;
4824 case DST__K_SET_LINUM_L:
4825 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4826 curr_linenum = data;
4827 vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data));
4828 break;
4830 case DST__K_SET_PC:
4831 _bfd_error_handler
4832 (_("%s not implemented"), "DST__K_SET_PC");
4833 break;
4835 case DST__K_SET_PC_W:
4836 _bfd_error_handler
4837 (_("%s not implemented"), "DST__K_SET_PC_W");
4838 break;
4840 case DST__K_SET_PC_L:
4841 _bfd_error_handler
4842 (_("%s not implemented"), "DST__K_SET_PC_L");
4843 break;
4845 case DST__K_SET_STMTNUM:
4846 _bfd_error_handler
4847 (_("%s not implemented"), "DST__K_SET_STMTNUM");
4848 break;
4850 case DST__K_TERM:
4851 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4852 curr_pc += data;
4853 vms_debug2 ((4, "DST__K_TERM: %d\n", data));
4854 break;
4856 case DST__K_TERM_W:
4857 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4858 curr_pc += data;
4859 vms_debug2 ((4, "DST__K_TERM_W: %d\n", data));
4860 break;
4862 case DST__K_TERM_L:
4863 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4864 curr_pc += data;
4865 vms_debug2 ((4, "DST__K_TERM_L: %d\n", data));
4866 break;
4868 case DST__K_SET_ABS_PC:
4869 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4870 curr_pc = data;
4871 vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data));
4872 break;
4874 default:
4875 if (cmd <= 0)
4877 curr_pc -= cmd;
4878 curr_linenum += 1;
4879 vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n",
4880 (unsigned long)curr_pc, curr_linenum));
4882 else
4883 _bfd_error_handler (_("unknown line command %d"), cmd);
4884 break;
4887 if ((curr_linenum != prev_linum && curr_pc != prev_pc)
4888 || cmd <= 0
4889 || cmd == DST__K_DELTA_PC_L
4890 || cmd == DST__K_DELTA_PC_W)
4892 line = (struct lineinfo *)
4893 bfd_zalloc (abfd, sizeof (struct lineinfo));
4894 line->address = curr_pc;
4895 line->line = curr_linenum;
4897 curr_line->next = line;
4898 curr_line = line;
4900 prev_linum = curr_linenum;
4901 prev_pc = curr_pc;
4902 vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n",
4903 (unsigned long)curr_pc, curr_linenum));
4906 pcl_ptr += cmd_length;
4908 break;
4910 case 0x17: /* Undocumented type used by DEC C to declare equates. */
4911 vms_debug2 ((3, "undocumented type 0x17\n"));
4912 break;
4914 default:
4915 vms_debug2 ((3, "ignoring record\n"));
4916 break;
4920 ptr += rec_length;
4923 /* Finalize tables with EOL marker. */
4924 srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4925 srec->line = (unsigned int) -1;
4926 srec->srec = (unsigned int) -1;
4927 curr_srec->next = srec;
4929 line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4930 line->line = (unsigned int) -1;
4931 line->address = (bfd_vma) -1;
4932 curr_line->next = line;
4934 /* Advertise that this module has been parsed. This is needed
4935 because parsing can be either performed at module creation
4936 or deferred until debug info is consumed. */
4937 SET_MODULE_PARSED (module);
4938 return true;
4941 /* Build the list of modules for the specified BFD. */
4943 static struct module *
4944 build_module_list (bfd *abfd)
4946 struct module *module, *list = NULL;
4947 asection *dmt;
4949 if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
4951 /* We have a DMT section so this must be an image. Parse the
4952 section and build the list of modules. This is sufficient
4953 since we can compute the start address and the end address
4954 of every module from the section contents. */
4955 bfd_size_type size = bfd_section_size (dmt);
4956 unsigned char *buf, *ptr, *end;
4958 if (! bfd_malloc_and_get_section (abfd, dmt, &buf))
4959 return NULL;
4961 vms_debug2 ((2, "DMT\n"));
4963 ptr = buf;
4964 end = ptr + size;
4965 while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE)
4967 /* Each header declares a module with its start offset and size
4968 of debug info in the DST section, as well as the count of
4969 program sections (i.e. address spans) it contains. */
4970 unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
4971 unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
4972 int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
4973 ptr += DBG_S_C_DMT_HEADER_SIZE;
4975 vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n",
4976 modbeg, msize, count));
4978 /* We create a 'module' structure for each program section since
4979 we only support contiguous addresses in a 'module' structure.
4980 As a consequence, the actual debug info in the DST section is
4981 shared and can be parsed multiple times; that doesn't seem to
4982 cause problems in practice. */
4983 while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE)
4985 unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
4986 unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
4987 module = new_module (abfd);
4988 module->modbeg = modbeg;
4989 module->size = msize;
4990 module->low = start;
4991 module->high = start + length;
4992 module->next = list;
4993 list = module;
4994 ptr += DBG_S_C_DMT_PSECT_SIZE;
4996 vms_debug2 ((4, "section: start = 0x%x, length = %u\n",
4997 start, length));
5000 free (buf);
5002 else
5004 /* We don't have a DMT section so this must be an object. Parse
5005 the module right now in order to compute its start address and
5006 end address. */
5007 void *dst = PRIV (dst_section)->contents;
5009 if (dst == NULL)
5010 return NULL;
5012 module = new_module (abfd);
5013 if (!parse_module (abfd, module, PRIV (dst_section)->contents,
5014 PRIV (dst_section)->size))
5015 return NULL;
5016 list = module;
5019 return list;
5022 /* Calculate and return the name of the source file and the line nearest
5023 to the wanted location in the specified module. */
5025 static bool
5026 module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
5027 const char **file, const char **func,
5028 unsigned int *line)
5030 struct funcinfo *funcinfo;
5031 struct lineinfo *lineinfo;
5032 struct srecinfo *srecinfo;
5033 bool ret = false;
5035 /* Parse this module if that was not done at module creation. */
5036 if (! IS_MODULE_PARSED (module))
5038 unsigned int size = module->size;
5039 unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
5040 unsigned char *buffer;
5042 if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
5043 || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL)
5045 bfd_set_error (bfd_error_no_debug_section);
5046 return false;
5049 ret = parse_module (abfd, module, buffer, size);
5050 free (buffer);
5051 if (!ret)
5052 return ret;
5055 /* Find out the function (if any) that contains the address. */
5056 for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next)
5057 if (addr >= funcinfo->low && addr <= funcinfo->high)
5059 *func = funcinfo->name;
5060 ret = true;
5061 break;
5064 /* Find out the source file and the line nearest to the address. */
5065 for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
5066 if (lineinfo->next && addr < lineinfo->next->address)
5068 for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
5069 if (srecinfo->next && lineinfo->line < srecinfo->next->line)
5071 if (srecinfo->sfile > 0)
5073 *file = module->file_table[srecinfo->sfile].name;
5074 *line = srecinfo->srec + lineinfo->line - srecinfo->line;
5076 else
5078 *file = module->name;
5079 *line = lineinfo->line;
5081 return true;
5084 break;
5087 return ret;
5090 /* Provided a BFD, a section and an offset into the section, calculate and
5091 return the name of the source file and the line nearest to the wanted
5092 location. */
5094 static bool
5095 _bfd_vms_find_nearest_line (bfd *abfd,
5096 asymbol **symbols ATTRIBUTE_UNUSED,
5097 asection *section,
5098 bfd_vma offset,
5099 const char **file,
5100 const char **func,
5101 unsigned int *line,
5102 unsigned int *discriminator)
5104 struct module *module;
5106 /* What address are we looking for? */
5107 bfd_vma addr = section->vma + offset;
5109 *file = NULL;
5110 *func = NULL;
5111 *line = 0;
5112 if (discriminator)
5113 *discriminator = 0;
5115 /* We can't do anything if there is no DST (debug symbol table). */
5116 if (PRIV (dst_section) == NULL)
5117 return false;
5119 /* Create the module list - if not already done. */
5120 if (PRIV (modules) == NULL)
5122 PRIV (modules) = build_module_list (abfd);
5123 if (PRIV (modules) == NULL)
5124 return false;
5127 for (module = PRIV (modules); module; module = module->next)
5128 if (addr >= module->low && addr <= module->high)
5129 return module_find_nearest_line (abfd, module, addr, file, func, line);
5131 return false;
5134 /* Canonicalizations. */
5135 /* Set name, value, section and flags of SYM from E. */
5137 static bool
5138 alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
5140 flagword flags;
5141 symvalue value;
5142 asection *sec;
5143 const char *name;
5145 name = e->name;
5146 value = 0;
5147 flags = BSF_NO_FLAGS;
5148 sec = NULL;
5150 switch (e->typ)
5152 case EGSD__C_SYM:
5153 if (e->flags & EGSY__V_WEAK)
5154 flags |= BSF_WEAK;
5156 if (e->flags & EGSY__V_DEF)
5158 /* Symbol definition. */
5159 flags |= BSF_GLOBAL;
5160 if (e->flags & EGSY__V_NORM)
5161 flags |= BSF_FUNCTION;
5162 value = e->value;
5163 sec = e->section;
5165 else
5167 /* Symbol reference. */
5168 sec = bfd_und_section_ptr;
5170 break;
5172 case EGSD__C_SYMG:
5173 /* A universal symbol is by definition global... */
5174 flags |= BSF_GLOBAL;
5176 /* ...and dynamic in shared libraries. */
5177 if (abfd->flags & DYNAMIC)
5178 flags |= BSF_DYNAMIC;
5180 if (e->flags & EGSY__V_WEAK)
5181 flags |= BSF_WEAK;
5183 if (!(e->flags & EGSY__V_DEF))
5184 abort ();
5186 if (e->flags & EGSY__V_NORM)
5187 flags |= BSF_FUNCTION;
5189 value = e->value;
5190 /* sec = e->section; */
5191 sec = bfd_abs_section_ptr;
5192 break;
5194 default:
5195 return false;
5198 sym->name = name;
5199 sym->section = sec;
5200 sym->flags = flags;
5201 sym->value = value;
5202 return true;
5206 /* Return the number of bytes required to store a vector of pointers
5207 to asymbols for all the symbols in the BFD abfd, including a
5208 terminal NULL pointer. If there are no symbols in the BFD,
5209 then return 0. If an error occurs, return -1. */
5211 static long
5212 alpha_vms_get_symtab_upper_bound (bfd *abfd)
5214 vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
5215 abfd, PRIV (gsd_sym_count)));
5217 return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
5220 /* Read the symbols from the BFD abfd, and fills in the vector
5221 location with pointers to the symbols and a trailing NULL.
5223 Return number of symbols read. */
5225 static long
5226 alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols)
5228 unsigned int i;
5230 vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
5232 if (PRIV (csymbols) == NULL)
5234 PRIV (csymbols) = (asymbol **) bfd_alloc
5235 (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
5237 /* Traverse table and fill symbols vector. */
5238 for (i = 0; i < PRIV (gsd_sym_count); i++)
5240 struct vms_symbol_entry *e = PRIV (syms)[i];
5241 asymbol *sym;
5243 sym = bfd_make_empty_symbol (abfd);
5244 if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym))
5246 bfd_release (abfd, PRIV (csymbols));
5247 PRIV (csymbols) = NULL;
5248 return -1;
5251 PRIV (csymbols)[i] = sym;
5255 if (symbols != NULL)
5257 for (i = 0; i < PRIV (gsd_sym_count); i++)
5258 symbols[i] = PRIV (csymbols)[i];
5259 symbols[i] = NULL;
5262 return PRIV (gsd_sym_count);
5265 /* Read and convert relocations from ETIR. We do it once for all sections. */
5267 static bool
5268 alpha_vms_slurp_relocs (bfd *abfd)
5270 int cur_psect = -1;
5272 vms_debug2 ((3, "alpha_vms_slurp_relocs\n"));
5274 /* We slurp relocs only once, for all sections. */
5275 if (PRIV (reloc_done) != 0)
5276 return PRIV (reloc_done) == 1;
5278 if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
5279 goto fail;
5281 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
5282 goto fail;
5284 while (1)
5286 unsigned char *begin;
5287 unsigned char *end;
5288 unsigned char *ptr;
5289 bfd_reloc_code_real_type reloc_code;
5290 int type;
5291 bfd_vma vaddr = 0;
5293 int length;
5295 bfd_vma cur_address;
5296 int cur_psidx = -1;
5297 unsigned char *cur_sym = NULL;
5298 int prev_cmd = -1;
5299 bfd_vma cur_addend = 0;
5301 /* Skip non-ETIR records. */
5302 type = _bfd_vms_get_object_record (abfd);
5303 if (type < 0)
5304 goto fail;
5305 if (type == EOBJ__C_EEOM)
5306 break;
5307 if (type != EOBJ__C_ETIR)
5308 continue;
5310 begin = PRIV (recrd.rec) + 4;
5311 end = PRIV (recrd.rec) + PRIV (recrd.rec_size);
5313 for (ptr = begin; ptr + 4 <= end; ptr += length)
5315 int cmd;
5317 cmd = bfd_getl16 (ptr);
5318 length = bfd_getl16 (ptr + 2);
5319 if (length < 4 || length > end - ptr)
5321 bad_rec:
5322 _bfd_error_handler (_("corrupt reloc record"));
5323 goto fail;
5326 cur_address = vaddr;
5328 vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n",
5329 _bfd_vms_etir_name (cmd)));
5331 switch (cmd)
5333 case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */
5334 /* ALPHA_R_REFQUAD und_section, step 1 */
5335 cur_sym = ptr + 4;
5336 prev_cmd = cmd;
5337 continue;
5339 case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */
5340 if (length < 16)
5341 goto bad_rec;
5342 cur_psidx = bfd_getl32 (ptr + 4);
5343 cur_addend = bfd_getl64 (ptr + 8);
5344 prev_cmd = cmd;
5345 continue;
5347 case ETIR__C_CTL_SETRB:
5348 if (prev_cmd != ETIR__C_STA_PQ)
5350 _bfd_error_handler
5351 /* xgettext:c-format */
5352 (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
5353 _bfd_vms_etir_name (cmd));
5354 goto fail;
5356 cur_psect = cur_psidx;
5357 vaddr = cur_addend;
5358 cur_psidx = -1;
5359 cur_addend = 0;
5360 continue;
5362 case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */
5363 /* ALPHA_R_REFLONG und_section, step 2 */
5364 if (prev_cmd != -1)
5366 if (prev_cmd != ETIR__C_STA_GBL)
5368 _bfd_error_handler
5369 /* xgettext:c-format */
5370 (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
5371 _bfd_vms_etir_name (ETIR__C_STA_LW));
5372 goto fail;
5375 if (length < 8)
5376 goto bad_rec;
5377 cur_addend = bfd_getl32 (ptr + 4);
5378 prev_cmd = cmd;
5379 continue;
5381 case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */
5382 /* ALPHA_R_REFQUAD und_section, step 2 */
5383 if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL)
5385 _bfd_error_handler
5386 /* xgettext:c-format */
5387 (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
5388 _bfd_vms_etir_name (ETIR__C_STA_QW));
5389 goto fail;
5391 if (length < 12)
5392 goto bad_rec;
5393 cur_addend = bfd_getl64 (ptr + 4);
5394 prev_cmd = cmd;
5395 continue;
5397 case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */
5398 /* ALPHA_R_REFLONG abs_section, step 2 */
5399 /* ALPHA_R_REFLONG others, step 2 */
5400 if (prev_cmd != ETIR__C_OPR_ADD
5401 && prev_cmd != ETIR__C_STA_LW
5402 && prev_cmd != ETIR__C_STA_PQ)
5404 /* xgettext:c-format */
5405 _bfd_error_handler (_("unknown reloc %s + %s"),
5406 _bfd_vms_etir_name (prev_cmd),
5407 _bfd_vms_etir_name (ETIR__C_STO_LW));
5408 goto fail;
5410 reloc_code = BFD_RELOC_32;
5411 break;
5413 case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */
5414 /* ALPHA_R_REFQUAD abs_section, step 2 */
5415 if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW)
5417 /* xgettext:c-format */
5418 _bfd_error_handler (_("unknown reloc %s + %s"),
5419 _bfd_vms_etir_name (prev_cmd),
5420 _bfd_vms_etir_name (ETIR__C_STO_QW));
5421 goto fail;
5423 reloc_code = BFD_RELOC_64;
5424 break;
5426 case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */
5427 if (prev_cmd != ETIR__C_STA_PQ)
5429 /* xgettext:c-format */
5430 _bfd_error_handler (_("unknown reloc %s + %s"),
5431 _bfd_vms_etir_name (prev_cmd),
5432 _bfd_vms_etir_name (ETIR__C_STO_OFF));
5433 goto fail;
5435 reloc_code = BFD_RELOC_64;
5436 break;
5438 case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */
5439 /* ALPHA_R_REFQUAD und_section, step 3 */
5440 if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW)
5442 /* xgettext:c-format */
5443 _bfd_error_handler (_("unknown reloc %s + %s"),
5444 _bfd_vms_etir_name (prev_cmd),
5445 _bfd_vms_etir_name (ETIR__C_OPR_ADD));
5446 goto fail;
5448 prev_cmd = ETIR__C_OPR_ADD;
5449 continue;
5451 case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */
5452 reloc_code = BFD_RELOC_ALPHA_CODEADDR;
5453 cur_sym = ptr + 4;
5454 break;
5456 case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */
5457 reloc_code = BFD_RELOC_64;
5458 cur_sym = ptr + 4;
5459 break;
5461 case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */
5462 reloc_code = BFD_RELOC_32;
5463 cur_sym = ptr + 4;
5464 break;
5466 case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */
5467 reloc_code = BFD_RELOC_ALPHA_LINKAGE;
5468 cur_sym = ptr + 8;
5469 break;
5471 case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */
5472 reloc_code = BFD_RELOC_ALPHA_NOP;
5473 goto call_reloc;
5475 case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */
5476 reloc_code = BFD_RELOC_ALPHA_BSR;
5477 goto call_reloc;
5479 case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */
5480 reloc_code = BFD_RELOC_ALPHA_LDA;
5481 goto call_reloc;
5483 case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */
5484 reloc_code = BFD_RELOC_ALPHA_BOH;
5485 goto call_reloc;
5487 call_reloc:
5488 if (length < 36)
5489 goto bad_rec;
5490 cur_sym = ptr + 4 + 32;
5491 cur_address = bfd_getl64 (ptr + 4 + 8);
5492 cur_addend = bfd_getl64 (ptr + 4 + 24);
5493 break;
5495 case ETIR__C_STO_IMM:
5496 if (length < 8)
5497 goto bad_rec;
5498 vaddr += bfd_getl32 (ptr + 4);
5499 continue;
5501 default:
5502 _bfd_error_handler (_("unknown reloc %s"),
5503 _bfd_vms_etir_name (cmd));
5504 goto fail;
5508 asection *sec;
5509 struct vms_section_data_struct *vms_sec;
5510 arelent *reloc;
5511 bfd_size_type size;
5513 /* Get section to which the relocation applies. */
5514 if (cur_psect < 0 || cur_psect > (int)PRIV (section_count))
5516 _bfd_error_handler (_("invalid section index in ETIR"));
5517 goto fail;
5520 if (PRIV (sections) == NULL)
5521 goto fail;
5522 sec = PRIV (sections)[cur_psect];
5523 if (sec == bfd_abs_section_ptr)
5525 _bfd_error_handler (_("relocation for non-REL psect"));
5526 goto fail;
5529 vms_sec = vms_section_data (sec);
5531 /* Allocate a reloc entry. */
5532 if (sec->reloc_count >= vms_sec->reloc_max)
5534 if (vms_sec->reloc_max == 0)
5536 vms_sec->reloc_max = 64;
5537 sec->relocation = bfd_zmalloc
5538 (vms_sec->reloc_max * sizeof (arelent));
5540 else
5542 vms_sec->reloc_max *= 2;
5543 sec->relocation = bfd_realloc_or_free
5544 (sec->relocation, vms_sec->reloc_max * sizeof (arelent));
5545 if (sec->relocation == NULL)
5546 goto fail;
5549 reloc = &sec->relocation[sec->reloc_count];
5550 sec->reloc_count++;
5552 reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code);
5554 if (cur_sym != NULL)
5556 unsigned int j;
5557 int symlen;
5558 asymbol **sym;
5560 /* Linear search. */
5561 if (end - cur_sym < 1)
5562 goto bad_rec;
5563 symlen = *cur_sym;
5564 cur_sym++;
5565 if (end - cur_sym < symlen)
5566 goto bad_rec;
5567 sym = NULL;
5569 for (j = 0; j < PRIV (gsd_sym_count); j++)
5570 if (PRIV (syms)[j]->namelen == symlen
5571 && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0)
5573 sym = &PRIV (csymbols)[j];
5574 break;
5576 if (sym == NULL)
5578 _bfd_error_handler (_("unknown symbol in command %s"),
5579 _bfd_vms_etir_name (cmd));
5580 reloc->sym_ptr_ptr = NULL;
5582 else
5583 reloc->sym_ptr_ptr = sym;
5585 else if (cur_psidx >= 0)
5587 if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count))
5588 goto fail;
5589 reloc->sym_ptr_ptr = &PRIV (sections)[cur_psidx]->symbol;
5591 else
5592 reloc->sym_ptr_ptr = NULL;
5594 reloc->address = cur_address;
5595 reloc->addend = cur_addend;
5597 if (reloc_code == ALPHA_R_LINKAGE)
5598 size = 16;
5599 else
5600 size = bfd_get_reloc_size (reloc->howto);
5601 vaddr += size;
5604 cur_addend = 0;
5605 prev_cmd = -1;
5606 cur_sym = NULL;
5607 cur_psidx = -1;
5610 vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n"));
5611 PRIV (reloc_done) = 1;
5612 return true;
5614 fail:
5615 PRIV (reloc_done) = -1;
5616 return false;
5619 /* Return the number of bytes required to store the relocation
5620 information associated with the given section. */
5622 static long
5623 alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section)
5625 if (!alpha_vms_slurp_relocs (abfd))
5626 return -1;
5628 return (section->reloc_count + 1L) * sizeof (arelent *);
5631 /* Convert relocations from VMS (external) form into BFD internal
5632 form. Return the number of relocations. */
5634 static long
5635 alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr,
5636 asymbol **symbols ATTRIBUTE_UNUSED)
5638 arelent *tblptr;
5639 int count;
5641 if (!alpha_vms_slurp_relocs (abfd))
5642 return -1;
5644 count = section->reloc_count;
5645 tblptr = section->relocation;
5647 while (count--)
5648 *relptr++ = tblptr++;
5650 *relptr = (arelent *) NULL;
5651 return section->reloc_count;
5654 /* Install a new set of internal relocs. */
5656 #define alpha_vms_set_reloc _bfd_generic_set_reloc
5659 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
5661 /* How to process the various reloc types. */
5663 static bfd_reloc_status_type
5664 reloc_nil (bfd * abfd ATTRIBUTE_UNUSED,
5665 arelent *reloc ATTRIBUTE_UNUSED,
5666 asymbol *sym ATTRIBUTE_UNUSED,
5667 void * data ATTRIBUTE_UNUSED,
5668 asection *sec ATTRIBUTE_UNUSED,
5669 bfd *output_bfd ATTRIBUTE_UNUSED,
5670 char **error_message ATTRIBUTE_UNUSED)
5672 #if VMS_DEBUG
5673 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd);
5674 vms_debug (2, "In section %s, symbol %s\n",
5675 sec->name, sym->name);
5676 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
5677 reloc->sym_ptr_ptr[0]->name,
5678 (unsigned long)reloc->address,
5679 (unsigned long)reloc->addend, reloc->howto->name);
5680 vms_debug (2, "data at %p\n", data);
5681 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
5682 #endif
5684 return bfd_reloc_ok;
5687 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
5688 from smaller values. Start with zero, widen, *then* decrement. */
5689 #define MINUS_ONE (((bfd_vma)0) - 1)
5691 static reloc_howto_type alpha_howto_table[] =
5693 HOWTO (ALPHA_R_IGNORE, /* Type. */
5694 0, /* Rightshift. */
5695 1, /* Size. */
5696 8, /* Bitsize. */
5697 true, /* PC relative. */
5698 0, /* Bitpos. */
5699 complain_overflow_dont,/* Complain_on_overflow. */
5700 reloc_nil, /* Special_function. */
5701 "IGNORE", /* Name. */
5702 true, /* Partial_inplace. */
5703 0, /* Source mask */
5704 0, /* Dest mask. */
5705 true), /* PC rel offset. */
5707 /* A 64 bit reference to a symbol. */
5708 HOWTO (ALPHA_R_REFQUAD, /* Type. */
5709 0, /* Rightshift. */
5710 8, /* Size. */
5711 64, /* Bitsize. */
5712 false, /* PC relative. */
5713 0, /* Bitpos. */
5714 complain_overflow_bitfield, /* Complain_on_overflow. */
5715 reloc_nil, /* Special_function. */
5716 "REFQUAD", /* Name. */
5717 true, /* Partial_inplace. */
5718 MINUS_ONE, /* Source mask. */
5719 MINUS_ONE, /* Dest mask. */
5720 false), /* PC rel offset. */
5722 /* A 21 bit branch. The native assembler generates these for
5723 branches within the text segment, and also fills in the PC
5724 relative offset in the instruction. */
5725 HOWTO (ALPHA_R_BRADDR, /* Type. */
5726 2, /* Rightshift. */
5727 4, /* Size. */
5728 21, /* Bitsize. */
5729 true, /* PC relative. */
5730 0, /* Bitpos. */
5731 complain_overflow_signed, /* Complain_on_overflow. */
5732 reloc_nil, /* Special_function. */
5733 "BRADDR", /* Name. */
5734 true, /* Partial_inplace. */
5735 0x1fffff, /* Source mask. */
5736 0x1fffff, /* Dest mask. */
5737 false), /* PC rel offset. */
5739 /* A hint for a jump to a register. */
5740 HOWTO (ALPHA_R_HINT, /* Type. */
5741 2, /* Rightshift. */
5742 2, /* Size. */
5743 14, /* Bitsize. */
5744 true, /* PC relative. */
5745 0, /* Bitpos. */
5746 complain_overflow_dont,/* Complain_on_overflow. */
5747 reloc_nil, /* Special_function. */
5748 "HINT", /* Name. */
5749 true, /* Partial_inplace. */
5750 0x3fff, /* Source mask. */
5751 0x3fff, /* Dest mask. */
5752 false), /* PC rel offset. */
5754 /* 16 bit PC relative offset. */
5755 HOWTO (ALPHA_R_SREL16, /* Type. */
5756 0, /* Rightshift. */
5757 2, /* Size. */
5758 16, /* Bitsize. */
5759 true, /* PC relative. */
5760 0, /* Bitpos. */
5761 complain_overflow_signed, /* Complain_on_overflow. */
5762 reloc_nil, /* Special_function. */
5763 "SREL16", /* Name. */
5764 true, /* Partial_inplace. */
5765 0xffff, /* Source mask. */
5766 0xffff, /* Dest mask. */
5767 false), /* PC rel offset. */
5769 /* 32 bit PC relative offset. */
5770 HOWTO (ALPHA_R_SREL32, /* Type. */
5771 0, /* Rightshift. */
5772 4, /* Size. */
5773 32, /* Bitsize. */
5774 true, /* PC relative. */
5775 0, /* Bitpos. */
5776 complain_overflow_signed, /* Complain_on_overflow. */
5777 reloc_nil, /* Special_function. */
5778 "SREL32", /* Name. */
5779 true, /* Partial_inplace. */
5780 0xffffffff, /* Source mask. */
5781 0xffffffff, /* Dest mask. */
5782 false), /* PC rel offset. */
5784 /* A 64 bit PC relative offset. */
5785 HOWTO (ALPHA_R_SREL64, /* Type. */
5786 0, /* Rightshift. */
5787 8, /* Size. */
5788 64, /* Bitsize. */
5789 true, /* PC relative. */
5790 0, /* Bitpos. */
5791 complain_overflow_signed, /* Complain_on_overflow. */
5792 reloc_nil, /* Special_function. */
5793 "SREL64", /* Name. */
5794 true, /* Partial_inplace. */
5795 MINUS_ONE, /* Source mask. */
5796 MINUS_ONE, /* Dest mask. */
5797 false), /* PC rel offset. */
5799 /* Push a value on the reloc evaluation stack. */
5800 HOWTO (ALPHA_R_OP_PUSH, /* Type. */
5801 0, /* Rightshift. */
5802 0, /* Size. */
5803 0, /* Bitsize. */
5804 false, /* PC relative. */
5805 0, /* Bitpos. */
5806 complain_overflow_dont,/* Complain_on_overflow. */
5807 reloc_nil, /* Special_function. */
5808 "OP_PUSH", /* Name. */
5809 false, /* Partial_inplace. */
5810 0, /* Source mask. */
5811 0, /* Dest mask. */
5812 false), /* PC rel offset. */
5814 /* Store the value from the stack at the given address. Store it in
5815 a bitfield of size r_size starting at bit position r_offset. */
5816 HOWTO (ALPHA_R_OP_STORE, /* Type. */
5817 0, /* Rightshift. */
5818 8, /* Size. */
5819 64, /* Bitsize. */
5820 false, /* PC relative. */
5821 0, /* Bitpos. */
5822 complain_overflow_dont,/* Complain_on_overflow. */
5823 reloc_nil, /* Special_function. */
5824 "OP_STORE", /* Name. */
5825 false, /* Partial_inplace. */
5826 0, /* Source mask. */
5827 MINUS_ONE, /* Dest mask. */
5828 false), /* PC rel offset. */
5830 /* Subtract the reloc address from the value on the top of the
5831 relocation stack. */
5832 HOWTO (ALPHA_R_OP_PSUB, /* Type. */
5833 0, /* Rightshift. */
5834 0, /* Size. */
5835 0, /* Bitsize. */
5836 false, /* PC relative. */
5837 0, /* Bitpos. */
5838 complain_overflow_dont,/* Complain_on_overflow. */
5839 reloc_nil, /* Special_function. */
5840 "OP_PSUB", /* Name. */
5841 false, /* Partial_inplace. */
5842 0, /* Source mask. */
5843 0, /* Dest mask. */
5844 false), /* PC rel offset. */
5846 /* Shift the value on the top of the relocation stack right by the
5847 given value. */
5848 HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */
5849 0, /* Rightshift. */
5850 0, /* Size. */
5851 0, /* Bitsize. */
5852 false, /* PC relative. */
5853 0, /* Bitpos. */
5854 complain_overflow_dont,/* Complain_on_overflow. */
5855 reloc_nil, /* Special_function. */
5856 "OP_PRSHIFT", /* Name. */
5857 false, /* Partial_inplace. */
5858 0, /* Source mask. */
5859 0, /* Dest mask. */
5860 false), /* PC rel offset. */
5862 /* Hack. Linkage is done by linker. */
5863 HOWTO (ALPHA_R_LINKAGE, /* Type. */
5864 0, /* Rightshift. */
5865 0, /* Size. */
5866 0, /* Bitsize. */
5867 false, /* PC relative. */
5868 0, /* Bitpos. */
5869 complain_overflow_dont,/* Complain_on_overflow. */
5870 reloc_nil, /* Special_function. */
5871 "LINKAGE", /* Name. */
5872 false, /* Partial_inplace. */
5873 0, /* Source mask. */
5874 0, /* Dest mask. */
5875 false), /* PC rel offset. */
5877 /* A 32 bit reference to a symbol. */
5878 HOWTO (ALPHA_R_REFLONG, /* Type. */
5879 0, /* Rightshift. */
5880 4, /* Size. */
5881 32, /* Bitsize. */
5882 false, /* PC relative. */
5883 0, /* Bitpos. */
5884 complain_overflow_bitfield, /* Complain_on_overflow. */
5885 reloc_nil, /* Special_function. */
5886 "REFLONG", /* Name. */
5887 true, /* Partial_inplace. */
5888 0xffffffff, /* Source mask. */
5889 0xffffffff, /* Dest mask. */
5890 false), /* PC rel offset. */
5892 /* A 64 bit reference to a procedure, written as 32 bit value. */
5893 HOWTO (ALPHA_R_CODEADDR, /* Type. */
5894 0, /* Rightshift. */
5895 8, /* Size. */
5896 64, /* Bitsize. */
5897 false, /* PC relative. */
5898 0, /* Bitpos. */
5899 complain_overflow_signed,/* Complain_on_overflow. */
5900 reloc_nil, /* Special_function. */
5901 "CODEADDR", /* Name. */
5902 false, /* Partial_inplace. */
5903 0xffffffff, /* Source mask. */
5904 0xffffffff, /* Dest mask. */
5905 false), /* PC rel offset. */
5907 HOWTO (ALPHA_R_NOP, /* Type. */
5908 0, /* Rightshift. */
5909 0, /* Size. */
5910 0, /* Bitsize. */
5911 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
5912 because the calculations for the 3 relocations are the same.
5913 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
5914 true, /* PC relative. */
5915 0, /* Bitpos. */
5916 complain_overflow_dont,/* Complain_on_overflow. */
5917 reloc_nil, /* Special_function. */
5918 "NOP", /* Name. */
5919 false, /* Partial_inplace. */
5920 0xffffffff, /* Source mask. */
5921 0xffffffff, /* Dest mask. */
5922 false), /* PC rel offset. */
5924 HOWTO (ALPHA_R_BSR, /* Type. */
5925 0, /* Rightshift. */
5926 0, /* Size. */
5927 0, /* Bitsize. */
5928 true, /* PC relative. */
5929 0, /* Bitpos. */
5930 complain_overflow_dont,/* Complain_on_overflow. */
5931 reloc_nil, /* Special_function. */
5932 "BSR", /* Name. */
5933 false, /* Partial_inplace. */
5934 0xffffffff, /* Source mask. */
5935 0xffffffff, /* Dest mask. */
5936 false), /* PC rel offset. */
5938 HOWTO (ALPHA_R_LDA, /* Type. */
5939 0, /* Rightshift. */
5940 0, /* Size. */
5941 0, /* Bitsize. */
5942 false, /* PC relative. */
5943 0, /* Bitpos. */
5944 complain_overflow_dont,/* Complain_on_overflow. */
5945 reloc_nil, /* Special_function. */
5946 "LDA", /* Name. */
5947 false, /* Partial_inplace. */
5948 0xffffffff, /* Source mask. */
5949 0xffffffff, /* Dest mask. */
5950 false), /* PC rel offset. */
5952 HOWTO (ALPHA_R_BOH, /* Type. */
5953 0, /* Rightshift. */
5954 0, /* Size. */
5955 0, /* Bitsize. */
5956 true, /* PC relative. */
5957 0, /* Bitpos. */
5958 complain_overflow_dont,/* Complain_on_overflow. */
5959 reloc_nil, /* Special_function. */
5960 "BOH", /* Name. */
5961 false, /* Partial_inplace. */
5962 0xffffffff, /* Source mask. */
5963 0xffffffff, /* Dest mask. */
5964 false), /* PC rel offset. */
5967 /* Return a pointer to a howto structure which, when invoked, will perform
5968 the relocation code on data from the architecture noted. */
5970 static reloc_howto_type *
5971 alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
5972 bfd_reloc_code_real_type code)
5974 int alpha_type;
5976 vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code));
5978 switch (code)
5980 case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break;
5981 case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break;
5982 case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break;
5983 case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break;
5984 case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break;
5985 case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break;
5986 case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break;
5987 case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break;
5988 case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break;
5989 case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break;
5990 case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break;
5991 case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break;
5992 case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break;
5993 case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break;
5994 case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break;
5995 default:
5996 _bfd_error_handler (_("reloc (%d) is *UNKNOWN*"), code);
5997 return NULL;
5999 vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name));
6000 return & alpha_howto_table[alpha_type];
6003 static reloc_howto_type *
6004 alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
6005 const char *r_name)
6007 unsigned int i;
6009 for (i = 0;
6010 i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
6011 i++)
6012 if (alpha_howto_table[i].name != NULL
6013 && strcasecmp (alpha_howto_table[i].name, r_name) == 0)
6014 return &alpha_howto_table[i];
6016 return NULL;
6019 static long
6020 alpha_vms_get_synthetic_symtab (bfd *abfd,
6021 long symcount ATTRIBUTE_UNUSED,
6022 asymbol **usyms ATTRIBUTE_UNUSED,
6023 long dynsymcount ATTRIBUTE_UNUSED,
6024 asymbol **dynsyms ATTRIBUTE_UNUSED,
6025 asymbol **ret)
6027 asymbol *syms;
6028 unsigned int i;
6029 unsigned int n = 0;
6031 syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
6032 *ret = syms;
6033 if (syms == NULL)
6034 return -1;
6036 for (i = 0; i < PRIV (gsd_sym_count); i++)
6038 struct vms_symbol_entry *e = PRIV (syms)[i];
6039 asymbol *sym;
6040 flagword flags;
6041 symvalue value;
6042 asection *sec;
6043 const char *name;
6044 char *sname;
6045 int l;
6047 name = e->name;
6048 value = 0;
6049 flags = BSF_LOCAL | BSF_SYNTHETIC;
6050 sec = NULL;
6052 switch (e->typ)
6054 case EGSD__C_SYM:
6055 case EGSD__C_SYMG:
6056 if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM))
6058 value = e->code_value;
6059 sec = e->code_section;
6061 else
6062 continue;
6063 break;
6065 default:
6066 continue;
6069 l = strlen (name);
6070 sname = bfd_alloc (abfd, l + 5);
6071 if (sname == NULL)
6072 return false;
6073 memcpy (sname, name, l);
6074 memcpy (sname + l, "..en", 5);
6076 sym = &syms[n++];
6077 sym->name = sname;
6078 sym->section = sec;
6079 sym->flags = flags;
6080 sym->value = value;
6081 sym->udata.p = NULL;
6084 return n;
6087 /* Private dump. */
6089 static const char *
6090 vms_time_to_str (unsigned char *buf)
6092 time_t t = vms_rawtime_to_time_t (buf);
6093 char *res = ctime (&t);
6095 if (!res)
6096 res = "*invalid time*";
6097 else
6098 res[24] = 0;
6099 return res;
6102 static void
6103 evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len)
6105 struct vms_emh_common *emh = (struct vms_emh_common *)rec;
6106 int subtype = -1;
6107 int extra;
6109 if (rec_len >= sizeof (*emh))
6110 subtype = bfd_getl16 (emh->subtyp);
6112 /* xgettext:c-format */
6113 fprintf (file, _(" EMH %d (len=%u): "), subtype, rec_len);
6115 /* PR 21618: Check for invalid lengths. */
6116 if (rec_len < sizeof (*emh))
6118 fprintf (file, _(" Error: %s min length is %u\n"),
6119 "EMH", (unsigned) sizeof (*emh));
6120 return;
6123 extra = rec_len - sizeof (struct vms_emh_common);
6125 switch (subtype)
6127 case EMH__C_MHD:
6129 struct vms_emh_mhd *mhd = (struct vms_emh_mhd *) rec;
6130 unsigned char *name;
6131 unsigned char *nextname;
6132 unsigned char *maxname;
6134 /* PR 21840: Check for invalid lengths. */
6135 if (rec_len < sizeof (* mhd))
6137 fprintf (file, _(" Error: %s min length is %u\n"),
6138 "EMH_MHD", (unsigned) sizeof (*mhd));
6139 return;
6141 fprintf (file, _("Module header\n"));
6142 fprintf (file, _(" structure level: %u\n"), mhd->strlvl);
6143 fprintf (file, _(" max record size: %u\n"),
6144 (unsigned) bfd_getl32 (mhd->recsiz));
6145 name = (unsigned char *) (mhd + 1);
6146 maxname = (unsigned char *) rec + rec_len;
6147 if (name > maxname - 2)
6149 fprintf (file, _(" Error: The module name is missing\n"));
6150 return;
6152 nextname = name + name[0] + 1;
6153 if (nextname >= maxname)
6155 fprintf (file, _(" Error: The module name is too long\n"));
6156 return;
6158 fprintf (file, _(" module name : %.*s\n"), name[0], name + 1);
6159 name = nextname;
6160 if (name > maxname - 2)
6162 fprintf (file, _(" Error: The module version is missing\n"));
6163 return;
6165 nextname = name + name[0] + 1;
6166 if (nextname >= maxname)
6168 fprintf (file, _(" Error: The module version is too long\n"));
6169 return;
6171 fprintf (file, _(" module version : %.*s\n"), name[0], name + 1);
6172 name = nextname;
6173 if ((maxname - name) < 17 && maxname[-1] != 0)
6174 fprintf (file, _(" Error: The compile date is truncated\n"));
6175 else
6176 fprintf (file, _(" compile date : %.17s\n"), name);
6178 break;
6180 case EMH__C_LNM:
6181 fprintf (file, _("Language Processor Name\n"));
6182 fprintf (file, _(" language name: %.*s\n"), extra, (char *)(emh + 1));
6183 break;
6185 case EMH__C_SRC:
6186 fprintf (file, _("Source Files Header\n"));
6187 fprintf (file, _(" file: %.*s\n"), extra, (char *)(emh + 1));
6188 break;
6190 case EMH__C_TTL:
6191 fprintf (file, _("Title Text Header\n"));
6192 fprintf (file, _(" title: %.*s\n"), extra, (char *)(emh + 1));
6193 break;
6195 case EMH__C_CPR:
6196 fprintf (file, _("Copyright Header\n"));
6197 fprintf (file, _(" copyright: %.*s\n"), extra, (char *)(emh + 1));
6198 break;
6200 default:
6201 fprintf (file, _("unhandled emh subtype %u\n"), subtype);
6202 break;
6206 static void
6207 evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len)
6209 struct vms_eeom *eeom = (struct vms_eeom *)rec;
6211 fprintf (file, _(" EEOM (len=%u):\n"), rec_len);
6213 /* PR 21618: Check for invalid lengths. */
6214 if (rec_len < 10)
6216 fprintf (file, _(" Error: %s min length is %u\n"),
6217 "EEOM", 10);
6218 return;
6221 fprintf (file, _(" number of cond linkage pairs: %u\n"),
6222 (unsigned)bfd_getl32 (eeom->total_lps));
6223 fprintf (file, _(" completion code: %u\n"),
6224 (unsigned)bfd_getl16 (eeom->comcod));
6226 if (rec_len >= sizeof (*eeom))
6228 fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg);
6229 fprintf (file, _(" transfer addr psect: %u\n"),
6230 (unsigned)bfd_getl32 (eeom->psindx));
6231 fprintf (file, _(" transfer address : 0x%08x\n"),
6232 (unsigned)bfd_getl32 (eeom->tfradr));
6236 static void
6237 exav_bfd_print_egsy_flags (unsigned int flags, FILE *file)
6239 if (flags & EGSY__V_WEAK)
6240 fputs (_(" WEAK"), file);
6241 if (flags & EGSY__V_DEF)
6242 fputs (_(" DEF"), file);
6243 if (flags & EGSY__V_UNI)
6244 fputs (_(" UNI"), file);
6245 if (flags & EGSY__V_REL)
6246 fputs (_(" REL"), file);
6247 if (flags & EGSY__V_COMM)
6248 fputs (_(" COMM"), file);
6249 if (flags & EGSY__V_VECEP)
6250 fputs (_(" VECEP"), file);
6251 if (flags & EGSY__V_NORM)
6252 fputs (_(" NORM"), file);
6253 if (flags & EGSY__V_QUAD_VAL)
6254 fputs (_(" QVAL"), file);
6257 static void
6258 evax_bfd_print_egsd_flags (FILE *file, unsigned int flags)
6260 if (flags & EGPS__V_PIC)
6261 fputs (_(" PIC"), file);
6262 if (flags & EGPS__V_LIB)
6263 fputs (_(" LIB"), file);
6264 if (flags & EGPS__V_OVR)
6265 fputs (_(" OVR"), file);
6266 if (flags & EGPS__V_REL)
6267 fputs (_(" REL"), file);
6268 if (flags & EGPS__V_GBL)
6269 fputs (_(" GBL"), file);
6270 if (flags & EGPS__V_SHR)
6271 fputs (_(" SHR"), file);
6272 if (flags & EGPS__V_EXE)
6273 fputs (_(" EXE"), file);
6274 if (flags & EGPS__V_RD)
6275 fputs (_(" RD"), file);
6276 if (flags & EGPS__V_WRT)
6277 fputs (_(" WRT"), file);
6278 if (flags & EGPS__V_VEC)
6279 fputs (_(" VEC"), file);
6280 if (flags & EGPS__V_NOMOD)
6281 fputs (_(" NOMOD"), file);
6282 if (flags & EGPS__V_COM)
6283 fputs (_(" COM"), file);
6284 if (flags & EGPS__V_ALLOC_64BIT)
6285 fputs (_(" 64B"), file);
6288 static void
6289 evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len)
6291 unsigned int off = sizeof (struct vms_egsd);
6292 unsigned int n = 0;
6294 fprintf (file, _(" EGSD (len=%u):\n"), rec_len);
6295 if (rec_len < sizeof (struct vms_egsd) + sizeof (struct vms_egsd_entry))
6296 return;
6298 while (off <= rec_len - sizeof (struct vms_egsd_entry))
6300 struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off);
6301 unsigned int type;
6302 unsigned int len;
6303 unsigned int rest;
6305 type = (unsigned)bfd_getl16 (e->gsdtyp);
6306 len = (unsigned)bfd_getl16 (e->gsdsiz);
6308 /* xgettext:c-format */
6309 fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "),
6310 n, type, len);
6311 n++;
6313 if (len < sizeof (struct vms_egsd_entry) || len > rec_len - off)
6315 fprintf (file, _(" Erroneous length\n"));
6316 return;
6319 switch (type)
6321 case EGSD__C_PSC:
6322 if (len >= offsetof (struct vms_egps, name))
6324 struct vms_egps *egps = (struct vms_egps *) e;
6325 unsigned int flags = bfd_getl16 (egps->flags);
6326 unsigned int l;
6328 fprintf (file, _("PSC - Program section definition\n"));
6329 fprintf (file, _(" alignment : 2**%u\n"), egps->align);
6330 fprintf (file, _(" flags : 0x%04x"), flags);
6331 evax_bfd_print_egsd_flags (file, flags);
6332 fputc ('\n', file);
6333 l = bfd_getl32 (egps->alloc);
6334 fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l);
6335 rest = len - offsetof (struct vms_egps, name);
6336 fprintf (file, _(" name : %.*s\n"),
6337 egps->namlng > rest ? rest : egps->namlng,
6338 egps->name);
6340 break;
6341 case EGSD__C_SPSC:
6342 if (len >= offsetof (struct vms_esgps, name))
6344 struct vms_esgps *esgps = (struct vms_esgps *) e;
6345 unsigned int flags = bfd_getl16 (esgps->flags);
6346 unsigned int l;
6348 fprintf (file, _("SPSC - Shared Image Program section def\n"));
6349 fprintf (file, _(" alignment : 2**%u\n"), esgps->align);
6350 fprintf (file, _(" flags : 0x%04x"), flags);
6351 evax_bfd_print_egsd_flags (file, flags);
6352 fputc ('\n', file);
6353 l = bfd_getl32 (esgps->alloc);
6354 fprintf (file, _(" alloc (len) : %u (0x%08x)\n"), l, l);
6355 fprintf (file, _(" image offset : 0x%08x\n"),
6356 (unsigned int) bfd_getl32 (esgps->base));
6357 fprintf (file, _(" symvec offset : 0x%08x\n"),
6358 (unsigned int) bfd_getl32 (esgps->value));
6359 rest = len - offsetof (struct vms_esgps, name);
6360 fprintf (file, _(" name : %.*s\n"),
6361 esgps->namlng > rest ? rest : esgps->namlng,
6362 esgps->name);
6364 break;
6365 case EGSD__C_SYM:
6366 if (len >= sizeof (struct vms_egsy))
6368 struct vms_egsy *egsy = (struct vms_egsy *) e;
6369 unsigned int flags = bfd_getl16 (egsy->flags);
6371 if ((flags & EGSY__V_DEF) != 0
6372 && len >= offsetof (struct vms_esdf, name))
6374 struct vms_esdf *esdf = (struct vms_esdf *) e;
6376 fprintf (file, _("SYM - Global symbol definition\n"));
6377 fprintf (file, _(" flags: 0x%04x"), flags);
6378 exav_bfd_print_egsy_flags (flags, file);
6379 fputc ('\n', file);
6380 fprintf (file, _(" psect offset: 0x%08x\n"),
6381 (unsigned) bfd_getl32 (esdf->value));
6382 if (flags & EGSY__V_NORM)
6384 fprintf (file, _(" code address: 0x%08x\n"),
6385 (unsigned) bfd_getl32 (esdf->code_address));
6386 fprintf (file, _(" psect index for entry point : %u\n"),
6387 (unsigned) bfd_getl32 (esdf->ca_psindx));
6389 fprintf (file, _(" psect index : %u\n"),
6390 (unsigned) bfd_getl32 (esdf->psindx));
6391 rest = len - offsetof (struct vms_esdf, name);
6392 fprintf (file, _(" name : %.*s\n"),
6393 esdf->namlng > rest ? rest : esdf->namlng,
6394 esdf->name);
6396 else if (len >= offsetof (struct vms_esrf, name))
6398 struct vms_esrf *esrf = (struct vms_esrf *)e;
6400 fprintf (file, _("SYM - Global symbol reference\n"));
6401 rest = len - offsetof (struct vms_esrf, name);
6402 fprintf (file, _(" name : %.*s\n"),
6403 esrf->namlng > rest ? rest : esrf->namlng,
6404 esrf->name);
6407 break;
6408 case EGSD__C_IDC:
6409 if (len >= sizeof (struct vms_eidc))
6411 struct vms_eidc *eidc = (struct vms_eidc *) e;
6412 unsigned int flags = bfd_getl32 (eidc->flags);
6413 unsigned char *p;
6415 fprintf (file, _("IDC - Ident Consistency check\n"));
6416 fprintf (file, _(" flags : 0x%08x"), flags);
6417 if (flags & EIDC__V_BINIDENT)
6418 fputs (" BINDENT", file);
6419 fputc ('\n', file);
6420 fprintf (file, _(" id match : %x\n"),
6421 (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK);
6422 fprintf (file, _(" error severity: %x\n"),
6423 (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK);
6424 p = eidc->name;
6425 rest = len - (p - (unsigned char *) e);
6426 fprintf (file, _(" entity name : %.*s\n"),
6427 p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
6428 if (rest > 1u + p[0])
6430 rest -= 1 + p[0];
6431 p += 1 + p[0];
6432 fprintf (file, _(" object name : %.*s\n"),
6433 p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
6434 if (rest > 1u + p[0])
6436 rest -= 1 + p[0];
6437 p += 1 + p[0];
6438 if (flags & EIDC__V_BINIDENT)
6440 if (rest >= 4)
6441 fprintf (file, _(" binary ident : 0x%08x\n"),
6442 (unsigned) bfd_getl32 (p));
6444 else
6445 fprintf (file, _(" ascii ident : %.*s\n"),
6446 p[0] > rest - 1 ? rest - 1 : p[0], p + 1);
6450 break;
6451 case EGSD__C_SYMG:
6452 if (len >= offsetof (struct vms_egst, name))
6454 struct vms_egst *egst = (struct vms_egst *) e;
6455 unsigned int flags = bfd_getl16 (egst->header.flags);
6457 fprintf (file, _("SYMG - Universal symbol definition\n"));
6458 fprintf (file, _(" flags: 0x%04x"), flags);
6459 exav_bfd_print_egsy_flags (flags, file);
6460 fputc ('\n', file);
6461 fprintf (file, _(" symbol vector offset: 0x%08x\n"),
6462 (unsigned) bfd_getl32 (egst->value));
6463 fprintf (file, _(" entry point: 0x%08x\n"),
6464 (unsigned) bfd_getl32 (egst->lp_1));
6465 fprintf (file, _(" proc descr : 0x%08x\n"),
6466 (unsigned) bfd_getl32 (egst->lp_2));
6467 fprintf (file, _(" psect index: %u\n"),
6468 (unsigned) bfd_getl32 (egst->psindx));
6469 rest = len - offsetof (struct vms_egst, name);
6470 fprintf (file, _(" name : %.*s\n"),
6471 egst->namlng > rest ? rest : egst->namlng,
6472 egst->name);
6474 break;
6475 case EGSD__C_SYMV:
6476 if (len >= offsetof (struct vms_esdfv, name))
6478 struct vms_esdfv *esdfv = (struct vms_esdfv *) e;
6479 unsigned int flags = bfd_getl16 (esdfv->flags);
6481 fprintf (file, _("SYMV - Vectored symbol definition\n"));
6482 fprintf (file, _(" flags: 0x%04x"), flags);
6483 exav_bfd_print_egsy_flags (flags, file);
6484 fputc ('\n', file);
6485 fprintf (file, _(" vector : 0x%08x\n"),
6486 (unsigned) bfd_getl32 (esdfv->vector));
6487 fprintf (file, _(" psect offset: %u\n"),
6488 (unsigned) bfd_getl32 (esdfv->value));
6489 fprintf (file, _(" psect index : %u\n"),
6490 (unsigned) bfd_getl32 (esdfv->psindx));
6491 rest = len - offsetof (struct vms_esdfv, name);
6492 fprintf (file, _(" name : %.*s\n"),
6493 esdfv->namlng > rest ? rest : esdfv->namlng,
6494 esdfv->name);
6496 break;
6497 case EGSD__C_SYMM:
6498 if (len >= offsetof (struct vms_esdfm, name))
6500 struct vms_esdfm *esdfm = (struct vms_esdfm *) e;
6501 unsigned int flags = bfd_getl16 (esdfm->flags);
6503 fprintf (file,
6504 _("SYMM - Global symbol definition with version\n"));
6505 fprintf (file, _(" flags: 0x%04x"), flags);
6506 exav_bfd_print_egsy_flags (flags, file);
6507 fputc ('\n', file);
6508 fprintf (file, _(" version mask: 0x%08x\n"),
6509 (unsigned)bfd_getl32 (esdfm->version_mask));
6510 fprintf (file, _(" psect offset: %u\n"),
6511 (unsigned)bfd_getl32 (esdfm->value));
6512 fprintf (file, _(" psect index : %u\n"),
6513 (unsigned)bfd_getl32 (esdfm->psindx));
6514 rest = len - offsetof (struct vms_esdfm, name);
6515 fprintf (file, _(" name : %.*s\n"),
6516 esdfm->namlng > rest ? rest : esdfm->namlng,
6517 esdfm->name);
6519 break;
6520 default:
6521 fprintf (file, _("unhandled egsd entry type %u\n"), type);
6522 break;
6524 off += len;
6528 static void
6529 evax_bfd_print_hex (FILE *file, const char *pfx,
6530 const unsigned char *buf, unsigned int len)
6532 unsigned int i;
6533 unsigned int n;
6535 n = 0;
6536 for (i = 0; i < len; i++)
6538 if (n == 0)
6539 fputs (pfx, file);
6540 fprintf (file, " %02x", buf[i]);
6541 n++;
6542 if (n == 16)
6544 n = 0;
6545 fputc ('\n', file);
6548 if (n != 0)
6549 fputc ('\n', file);
6552 static void
6553 evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf,
6554 unsigned int len, int is_ps)
6556 if (is_ps ? len < 44 : len < 33)
6557 return;
6559 /* xgettext:c-format */
6560 fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"),
6561 (unsigned)bfd_getl32 (buf),
6562 (unsigned)bfd_getl32 (buf + 16));
6563 /* xgettext:c-format */
6564 fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"),
6565 (unsigned)bfd_getl32 (buf + 4),
6566 (unsigned)bfd_getl32 (buf + 12),
6567 (unsigned)bfd_getl32 (buf + 8));
6568 /* xgettext:c-format */
6569 fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"),
6570 (unsigned)bfd_getl32 (buf + 20),
6571 (unsigned)bfd_getl32 (buf + 28),
6572 (unsigned)bfd_getl32 (buf + 24));
6573 if (is_ps)
6574 /* xgettext:c-format */
6575 fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"),
6576 (unsigned)bfd_getl32 (buf + 32),
6577 (unsigned)bfd_getl32 (buf + 40),
6578 (unsigned)bfd_getl32 (buf + 36));
6579 else
6580 fprintf (file, _(" global name: %.*s\n"),
6581 buf[32] > len - 33 ? len - 33 : buf[32],
6582 buf + 33);
6585 static void
6586 evax_bfd_print_etir (FILE *file, const char *name,
6587 unsigned char *rec, unsigned int rec_len)
6589 unsigned int off = sizeof (struct vms_eobjrec);
6591 /* xgettext:c-format */
6592 fprintf (file, _(" %s (len=%u):\n"), name, (unsigned) rec_len);
6593 if (rec_len < sizeof (struct vms_eobjrec) + sizeof (struct vms_etir))
6594 return;
6596 while (off <= rec_len - sizeof (struct vms_etir))
6598 struct vms_etir *etir = (struct vms_etir *)(rec + off);
6599 unsigned char *buf;
6600 unsigned int type;
6601 unsigned int size;
6602 unsigned int rest;
6604 type = bfd_getl16 (etir->rectyp);
6605 size = bfd_getl16 (etir->size);
6606 buf = rec + off + sizeof (struct vms_etir);
6608 if (size < sizeof (struct vms_etir) || size > rec_len - off)
6610 fprintf (file, _(" Erroneous length\n"));
6611 return;
6614 /* xgettext:c-format */
6615 fprintf (file, _(" (type: %3u, size: %3u): "), type, size);
6616 rest = size - sizeof (struct vms_etir);
6617 switch (type)
6619 case ETIR__C_STA_GBL:
6620 if (rest >= 1)
6621 fprintf (file, _("STA_GBL (stack global) %.*s\n"),
6622 buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
6623 break;
6624 case ETIR__C_STA_LW:
6625 fprintf (file, _("STA_LW (stack longword)"));
6626 if (rest >= 4)
6627 fprintf (file, " 0x%08x\n",
6628 (unsigned) bfd_getl32 (buf));
6629 break;
6630 case ETIR__C_STA_QW:
6631 fprintf (file, _("STA_QW (stack quadword)"));
6632 if (rest >= 8)
6633 fprintf (file, " 0x%08x %08x\n",
6634 (unsigned) bfd_getl32 (buf + 4),
6635 (unsigned) bfd_getl32 (buf + 0));
6636 break;
6637 case ETIR__C_STA_PQ:
6638 fprintf (file, _("STA_PQ (stack psect base + offset)\n"));
6639 if (rest >= 12)
6640 /* xgettext:c-format */
6641 fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"),
6642 (unsigned) bfd_getl32 (buf + 0),
6643 (unsigned) bfd_getl32 (buf + 8),
6644 (unsigned) bfd_getl32 (buf + 4));
6645 break;
6646 case ETIR__C_STA_LI:
6647 fprintf (file, _("STA_LI (stack literal)\n"));
6648 break;
6649 case ETIR__C_STA_MOD:
6650 fprintf (file, _("STA_MOD (stack module)\n"));
6651 break;
6652 case ETIR__C_STA_CKARG:
6653 fprintf (file, _("STA_CKARG (compare procedure argument)\n"));
6654 break;
6656 case ETIR__C_STO_B:
6657 fprintf (file, _("STO_B (store byte)\n"));
6658 break;
6659 case ETIR__C_STO_W:
6660 fprintf (file, _("STO_W (store word)\n"));
6661 break;
6662 case ETIR__C_STO_LW:
6663 fprintf (file, _("STO_LW (store longword)\n"));
6664 break;
6665 case ETIR__C_STO_QW:
6666 fprintf (file, _("STO_QW (store quadword)\n"));
6667 break;
6668 case ETIR__C_STO_IMMR:
6669 if (rest >= 4)
6671 unsigned int rpt = bfd_getl32 (buf);
6672 fprintf (file,
6673 _("STO_IMMR (store immediate repeat) %u bytes\n"),
6674 rpt);
6675 if (rpt > rest - 4)
6676 rpt = rest - 4;
6677 evax_bfd_print_hex (file, " ", buf + 4, rpt);
6679 break;
6680 case ETIR__C_STO_GBL:
6681 if (rest >= 1)
6682 fprintf (file, _("STO_GBL (store global) %.*s\n"),
6683 buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
6684 break;
6685 case ETIR__C_STO_CA:
6686 if (rest >= 1)
6687 fprintf (file, _("STO_CA (store code address) %.*s\n"),
6688 buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
6689 break;
6690 case ETIR__C_STO_RB:
6691 fprintf (file, _("STO_RB (store relative branch)\n"));
6692 break;
6693 case ETIR__C_STO_AB:
6694 fprintf (file, _("STO_AB (store absolute branch)\n"));
6695 break;
6696 case ETIR__C_STO_OFF:
6697 fprintf (file, _("STO_OFF (store offset to psect)\n"));
6698 break;
6699 case ETIR__C_STO_IMM:
6700 if (rest >= 4)
6702 unsigned int rpt = bfd_getl32 (buf);
6703 fprintf (file,
6704 _("STO_IMM (store immediate) %u bytes\n"),
6705 rpt);
6706 if (rpt > rest - 4)
6707 rpt = rest - 4;
6708 evax_bfd_print_hex (file, " ", buf + 4, rpt);
6710 break;
6711 case ETIR__C_STO_GBL_LW:
6712 if (rest >= 1)
6713 fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"),
6714 buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1);
6715 break;
6716 case ETIR__C_STO_LP_PSB:
6717 fprintf (file, _("STO_OFF (store LP with procedure signature)\n"));
6718 break;
6719 case ETIR__C_STO_HINT_GBL:
6720 fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n"));
6721 break;
6722 case ETIR__C_STO_HINT_PS:
6723 fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n"));
6724 break;
6726 case ETIR__C_OPR_NOP:
6727 fprintf (file, _("OPR_NOP (no-operation)\n"));
6728 break;
6729 case ETIR__C_OPR_ADD:
6730 fprintf (file, _("OPR_ADD (add)\n"));
6731 break;
6732 case ETIR__C_OPR_SUB:
6733 fprintf (file, _("OPR_SUB (subtract)\n"));
6734 break;
6735 case ETIR__C_OPR_MUL:
6736 fprintf (file, _("OPR_MUL (multiply)\n"));
6737 break;
6738 case ETIR__C_OPR_DIV:
6739 fprintf (file, _("OPR_DIV (divide)\n"));
6740 break;
6741 case ETIR__C_OPR_AND:
6742 fprintf (file, _("OPR_AND (logical and)\n"));
6743 break;
6744 case ETIR__C_OPR_IOR:
6745 fprintf (file, _("OPR_IOR (logical inclusive or)\n"));
6746 break;
6747 case ETIR__C_OPR_EOR:
6748 fprintf (file, _("OPR_EOR (logical exclusive or)\n"));
6749 break;
6750 case ETIR__C_OPR_NEG:
6751 fprintf (file, _("OPR_NEG (negate)\n"));
6752 break;
6753 case ETIR__C_OPR_COM:
6754 fprintf (file, _("OPR_COM (complement)\n"));
6755 break;
6756 case ETIR__C_OPR_INSV:
6757 fprintf (file, _("OPR_INSV (insert field)\n"));
6758 break;
6759 case ETIR__C_OPR_ASH:
6760 fprintf (file, _("OPR_ASH (arithmetic shift)\n"));
6761 break;
6762 case ETIR__C_OPR_USH:
6763 fprintf (file, _("OPR_USH (unsigned shift)\n"));
6764 break;
6765 case ETIR__C_OPR_ROT:
6766 fprintf (file, _("OPR_ROT (rotate)\n"));
6767 break;
6768 case ETIR__C_OPR_SEL:
6769 fprintf (file, _("OPR_SEL (select)\n"));
6770 break;
6771 case ETIR__C_OPR_REDEF:
6772 fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n"));
6773 break;
6774 case ETIR__C_OPR_DFLIT:
6775 fprintf (file, _("OPR_REDEF (define a literal)\n"));
6776 break;
6778 case ETIR__C_STC_LP:
6779 fprintf (file, _("STC_LP (store cond linkage pair)\n"));
6780 break;
6781 case ETIR__C_STC_LP_PSB:
6782 fprintf (file,
6783 _("STC_LP_PSB (store cond linkage pair + signature)\n"));
6784 if (rest >= 5)
6786 /* xgettext:c-format */
6787 fprintf (file, _(" linkage index: %u, procedure: %.*s\n"),
6788 (unsigned) bfd_getl32 (buf),
6789 buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
6790 if (rest > 4 + 1u + buf[4])
6792 rest -= 4 + 1 + buf[4];
6793 buf += 4 + 1 + buf[4];
6794 fprintf (file, _(" signature: %.*s\n"),
6795 buf[0] > rest - 1 ? rest - 1: buf[0], buf + 1);
6798 break;
6799 case ETIR__C_STC_GBL:
6800 fprintf (file, _("STC_GBL (store cond global)\n"));
6801 if (rest >= 5)
6802 /* xgettext:c-format */
6803 fprintf (file, _(" linkage index: %u, global: %.*s\n"),
6804 (unsigned) bfd_getl32 (buf),
6805 buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
6806 break;
6807 case ETIR__C_STC_GCA:
6808 fprintf (file, _("STC_GCA (store cond code address)\n"));
6809 if (rest >= 5)
6810 /* xgettext:c-format */
6811 fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"),
6812 (unsigned) bfd_getl32 (buf),
6813 buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5);
6814 break;
6815 case ETIR__C_STC_PS:
6816 fprintf (file, _("STC_PS (store cond psect + offset)\n"));
6817 if (rest >= 16)
6818 fprintf (file,
6819 /* xgettext:c-format */
6820 _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"),
6821 (unsigned)bfd_getl32 (buf),
6822 (unsigned)bfd_getl32 (buf + 4),
6823 (unsigned)bfd_getl32 (buf + 12),
6824 (unsigned)bfd_getl32 (buf + 8));
6825 break;
6826 case ETIR__C_STC_NOP_GBL:
6827 fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n"));
6828 evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
6829 break;
6830 case ETIR__C_STC_NOP_PS:
6831 fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n"));
6832 evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
6833 break;
6834 case ETIR__C_STC_BSR_GBL:
6835 fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n"));
6836 evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
6837 break;
6838 case ETIR__C_STC_BSR_PS:
6839 fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n"));
6840 evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
6841 break;
6842 case ETIR__C_STC_LDA_GBL:
6843 fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n"));
6844 evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
6845 break;
6846 case ETIR__C_STC_LDA_PS:
6847 fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n"));
6848 evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
6849 break;
6850 case ETIR__C_STC_BOH_GBL:
6851 fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n"));
6852 evax_bfd_print_etir_stc_ir (file, buf, rest, 0);
6853 break;
6854 case ETIR__C_STC_BOH_PS:
6855 fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n"));
6856 evax_bfd_print_etir_stc_ir (file, buf, rest, 1);
6857 break;
6858 case ETIR__C_STC_NBH_GBL:
6859 fprintf (file,
6860 _("STC_NBH_GBL (store cond or hint at global addr)\n"));
6861 break;
6862 case ETIR__C_STC_NBH_PS:
6863 fprintf (file,
6864 _("STC_NBH_PS (store cond or hint at psect + offset)\n"));
6865 break;
6867 case ETIR__C_CTL_SETRB:
6868 fprintf (file, _("CTL_SETRB (set relocation base)\n"));
6869 break;
6870 case ETIR__C_CTL_AUGRB:
6871 if (rest >= 4)
6873 unsigned int val = bfd_getl32 (buf);
6874 fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"),
6875 val);
6877 break;
6878 case ETIR__C_CTL_DFLOC:
6879 fprintf (file, _("CTL_DFLOC (define location)\n"));
6880 break;
6881 case ETIR__C_CTL_STLOC:
6882 fprintf (file, _("CTL_STLOC (set location)\n"));
6883 break;
6884 case ETIR__C_CTL_STKDL:
6885 fprintf (file, _("CTL_STKDL (stack defined location)\n"));
6886 break;
6887 default:
6888 fprintf (file, _("*unhandled*\n"));
6889 break;
6891 off += size;
6895 static void
6896 evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
6898 bool is_first = true;
6899 bool has_records = true;
6901 while (1)
6903 unsigned int rec_len;
6904 unsigned int pad_len;
6905 unsigned char *rec;
6906 unsigned int hdr_size;
6907 unsigned int type;
6908 unsigned char buf[6];
6910 hdr_size = has_records ? 6 : 4;
6911 if (bfd_read (buf, hdr_size, abfd) != hdr_size)
6913 fprintf (file, _("cannot read GST record header\n"));
6914 return;
6917 type = bfd_getl16 (buf);
6918 rec_len = bfd_getl16 (buf + 2);
6919 pad_len = rec_len;
6920 if (has_records)
6922 unsigned int rec_len2 = bfd_getl16 (buf + 4);
6924 if (is_first)
6926 is_first = false;
6927 if (type == rec_len2 && rec_len == EOBJ__C_EMH)
6928 /* Matched a VMS record EMH. */
6930 else
6932 has_records = false;
6933 if (type != EOBJ__C_EMH)
6935 /* Ill-formed. */
6936 fprintf (file, _("cannot find EMH in first GST record\n"));
6937 return;
6942 if (has_records)
6944 /* VMS record format is: record-size, type, record-size.
6945 See maybe_adjust_record_pointer_for_object comment. */
6946 if (type == rec_len2)
6948 type = rec_len;
6949 rec_len = rec_len2;
6951 else
6952 rec_len = 0;
6953 pad_len = (rec_len + 1) & ~1U;
6954 hdr_size = 4;
6958 if (rec_len < hdr_size)
6960 fprintf (file, _("corrupted GST\n"));
6961 return;
6964 rec = bfd_malloc (pad_len);
6965 if (rec == NULL)
6966 return;
6968 memcpy (rec, buf + (has_records ? 2 : 0), hdr_size);
6970 if (bfd_read (rec + hdr_size, pad_len - hdr_size, abfd)
6971 != pad_len - hdr_size)
6973 fprintf (file, _("cannot read GST record\n"));
6974 free (rec);
6975 return;
6978 switch (type)
6980 case EOBJ__C_EMH:
6981 evax_bfd_print_emh (file, rec, rec_len);
6982 break;
6983 case EOBJ__C_EGSD:
6984 evax_bfd_print_egsd (file, rec, rec_len);
6985 break;
6986 case EOBJ__C_EEOM:
6987 evax_bfd_print_eeom (file, rec, rec_len);
6988 free (rec);
6989 return;
6990 case EOBJ__C_ETIR:
6991 evax_bfd_print_etir (file, "ETIR", rec, rec_len);
6992 break;
6993 case EOBJ__C_EDBG:
6994 evax_bfd_print_etir (file, "EDBG", rec, rec_len);
6995 break;
6996 case EOBJ__C_ETBT:
6997 evax_bfd_print_etir (file, "ETBT", rec, rec_len);
6998 break;
6999 default:
7000 fprintf (file, _(" unhandled EOBJ record type %u\n"), type);
7001 break;
7003 free (rec);
7007 static void
7008 evax_bfd_print_relocation_records (FILE *file, const unsigned char *buf,
7009 size_t buf_size, size_t off,
7010 unsigned int stride)
7012 while (off <= buf_size - 8)
7014 unsigned int base;
7015 unsigned int count;
7016 unsigned int j;
7018 count = bfd_getl32 (buf + off + 0);
7020 if (count == 0)
7021 break;
7022 base = bfd_getl32 (buf + off + 4);
7024 /* xgettext:c-format */
7025 fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"),
7026 count, base);
7028 off += 8;
7029 for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32)
7031 unsigned int k;
7032 unsigned int n = 0;
7033 unsigned int val;
7035 val = bfd_getl32 (buf + off);
7036 off += 4;
7038 /* xgettext:c-format */
7039 fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count);
7041 for (k = 0; k < 32; k++)
7042 if (val & (1u << k))
7044 if (n == 0)
7045 fputs (" ", file);
7046 fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
7047 n++;
7048 if (n == 8)
7050 fputs ("\n", file);
7051 n = 0;
7054 if (n)
7055 fputs ("\n", file);
7060 static void
7061 evax_bfd_print_address_fixups (FILE *file, const unsigned char *buf,
7062 size_t buf_size, size_t off)
7064 while (off <= buf_size - 8)
7066 unsigned int j;
7067 unsigned int count;
7069 count = bfd_getl32 (buf + off + 0);
7070 if (count == 0)
7071 return;
7072 /* xgettext:c-format */
7073 fprintf (file, _(" image %u (%u entries)\n"),
7074 (unsigned) bfd_getl32 (buf + off + 4), count);
7075 off += 8;
7076 for (j = 0; j < count && off <= buf_size - 8; j++)
7078 /* xgettext:c-format */
7079 fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"),
7080 (unsigned) bfd_getl32 (buf + off + 0),
7081 (unsigned) bfd_getl32 (buf + off + 4));
7082 off += 8;
7087 static void
7088 evax_bfd_print_reference_fixups (FILE *file, const unsigned char *buf,
7089 size_t buf_size, size_t off)
7091 unsigned int count;
7093 while (off <= buf_size - 8)
7095 unsigned int j;
7096 unsigned int n = 0;
7098 count = bfd_getl32 (buf + off + 0);
7099 if (count == 0)
7100 break;
7101 /* xgettext:c-format */
7102 fprintf (file, _(" image %u (%u entries), offsets:\n"),
7103 (unsigned) bfd_getl32 (buf + off + 4), count);
7104 off += 8;
7105 for (j = 0; j < count && off <= buf_size - 4; j++)
7107 if (n == 0)
7108 fputs (" ", file);
7109 fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off));
7110 n++;
7111 if (n == 7)
7113 fputs ("\n", file);
7114 n = 0;
7116 off += 4;
7118 if (n)
7119 fputs ("\n", file);
7123 static void
7124 evax_bfd_print_indent (int indent, FILE *file)
7126 for (; indent; indent--)
7127 fputc (' ', file);
7130 static const char *
7131 evax_bfd_get_dsc_name (unsigned int v)
7133 switch (v)
7135 case DSC__K_DTYPE_Z:
7136 return "Z (Unspecified)";
7137 case DSC__K_DTYPE_V:
7138 return "V (Bit)";
7139 case DSC__K_DTYPE_BU:
7140 return "BU (Byte logical)";
7141 case DSC__K_DTYPE_WU:
7142 return "WU (Word logical)";
7143 case DSC__K_DTYPE_LU:
7144 return "LU (Longword logical)";
7145 case DSC__K_DTYPE_QU:
7146 return "QU (Quadword logical)";
7147 case DSC__K_DTYPE_B:
7148 return "B (Byte integer)";
7149 case DSC__K_DTYPE_W:
7150 return "W (Word integer)";
7151 case DSC__K_DTYPE_L:
7152 return "L (Longword integer)";
7153 case DSC__K_DTYPE_Q:
7154 return "Q (Quadword integer)";
7155 case DSC__K_DTYPE_F:
7156 return "F (Single-precision floating)";
7157 case DSC__K_DTYPE_D:
7158 return "D (Double-precision floating)";
7159 case DSC__K_DTYPE_FC:
7160 return "FC (Complex)";
7161 case DSC__K_DTYPE_DC:
7162 return "DC (Double-precision Complex)";
7163 case DSC__K_DTYPE_T:
7164 return "T (ASCII text string)";
7165 case DSC__K_DTYPE_NU:
7166 return "NU (Numeric string, unsigned)";
7167 case DSC__K_DTYPE_NL:
7168 return "NL (Numeric string, left separate sign)";
7169 case DSC__K_DTYPE_NLO:
7170 return "NLO (Numeric string, left overpunched sign)";
7171 case DSC__K_DTYPE_NR:
7172 return "NR (Numeric string, right separate sign)";
7173 case DSC__K_DTYPE_NRO:
7174 return "NRO (Numeric string, right overpunched sig)";
7175 case DSC__K_DTYPE_NZ:
7176 return "NZ (Numeric string, zoned sign)";
7177 case DSC__K_DTYPE_P:
7178 return "P (Packed decimal string)";
7179 case DSC__K_DTYPE_ZI:
7180 return "ZI (Sequence of instructions)";
7181 case DSC__K_DTYPE_ZEM:
7182 return "ZEM (Procedure entry mask)";
7183 case DSC__K_DTYPE_DSC:
7184 return "DSC (Descriptor, used for arrays of dyn strings)";
7185 case DSC__K_DTYPE_OU:
7186 return "OU (Octaword logical)";
7187 case DSC__K_DTYPE_O:
7188 return "O (Octaword integer)";
7189 case DSC__K_DTYPE_G:
7190 return "G (Double precision G floating, 64 bit)";
7191 case DSC__K_DTYPE_H:
7192 return "H (Quadruple precision floating, 128 bit)";
7193 case DSC__K_DTYPE_GC:
7194 return "GC (Double precision complex, G floating)";
7195 case DSC__K_DTYPE_HC:
7196 return "HC (Quadruple precision complex, H floating)";
7197 case DSC__K_DTYPE_CIT:
7198 return "CIT (COBOL intermediate temporary)";
7199 case DSC__K_DTYPE_BPV:
7200 return "BPV (Bound Procedure Value)";
7201 case DSC__K_DTYPE_BLV:
7202 return "BLV (Bound Label Value)";
7203 case DSC__K_DTYPE_VU:
7204 return "VU (Bit Unaligned)";
7205 case DSC__K_DTYPE_ADT:
7206 return "ADT (Absolute Date-Time)";
7207 case DSC__K_DTYPE_VT:
7208 return "VT (Varying Text)";
7209 case DSC__K_DTYPE_T2:
7210 return "T2 (16-bit char)";
7211 case DSC__K_DTYPE_VT2:
7212 return "VT2 (16-bit varying char)";
7213 default:
7214 return "?? (unknown)";
7218 static void
7219 evax_bfd_print_desc (const unsigned char *buf, unsigned int bufsize,
7220 int indent, FILE *file)
7222 if (bufsize < 8)
7223 return;
7225 unsigned char bclass = buf[3];
7226 unsigned char dtype = buf[2];
7227 unsigned int len = (unsigned)bfd_getl16 (buf);
7228 unsigned int pointer = (unsigned)bfd_getl32 (buf + 4);
7230 evax_bfd_print_indent (indent, file);
7232 if (len == 1 && pointer == 0xffffffffUL)
7234 /* 64 bits. */
7235 fprintf (file, _("64 bits *unhandled*\n"));
7237 else
7239 /* xgettext:c-format */
7240 fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"),
7241 bclass, dtype, len, pointer);
7242 switch (bclass)
7244 case DSC__K_CLASS_NCA:
7246 const struct vms_dsc_nca *dsc = (const void *)buf;
7247 unsigned int i;
7248 const unsigned char *b;
7250 evax_bfd_print_indent (indent, file);
7251 fprintf (file, _("non-contiguous array of %s\n"),
7252 evax_bfd_get_dsc_name (dsc->dtype));
7253 if (bufsize >= sizeof (*dsc))
7255 evax_bfd_print_indent (indent + 1, file);
7256 fprintf (file,
7257 /* xgettext:c-format */
7258 _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"),
7259 dsc->dimct, dsc->aflags, dsc->digits, dsc->scale);
7260 evax_bfd_print_indent (indent + 1, file);
7261 fprintf (file,
7262 /* xgettext:c-format */
7263 _("arsize: %u, a0: 0x%08x\n"),
7264 (unsigned) bfd_getl32 (dsc->arsize),
7265 (unsigned) bfd_getl32 (dsc->a0));
7266 evax_bfd_print_indent (indent + 1, file);
7267 fprintf (file, _("Strides:\n"));
7268 b = buf + sizeof (*dsc);
7269 bufsize -= sizeof (*dsc);
7270 for (i = 0; i < dsc->dimct; i++)
7272 if (bufsize < 4)
7273 break;
7274 evax_bfd_print_indent (indent + 2, file);
7275 fprintf (file, "[%u]: %u\n", i + 1,
7276 (unsigned) bfd_getl32 (b));
7277 b += 4;
7278 bufsize -= 4;
7280 evax_bfd_print_indent (indent + 1, file);
7281 fprintf (file, _("Bounds:\n"));
7282 for (i = 0; i < dsc->dimct; i++)
7284 if (bufsize < 8)
7285 break;
7286 evax_bfd_print_indent (indent + 2, file);
7287 /* xgettext:c-format */
7288 fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1,
7289 (unsigned) bfd_getl32 (b + 0),
7290 (unsigned) bfd_getl32 (b + 4));
7291 b += 8;
7292 bufsize -= 8;
7296 break;
7297 case DSC__K_CLASS_UBS:
7299 const struct vms_dsc_ubs *ubs = (const void *)buf;
7301 evax_bfd_print_indent (indent, file);
7302 fprintf (file, _("unaligned bit-string of %s\n"),
7303 evax_bfd_get_dsc_name (ubs->dtype));
7304 if (bufsize >= sizeof (*ubs))
7306 evax_bfd_print_indent (indent + 1, file);
7307 fprintf (file,
7308 /* xgettext:c-format */
7309 _("base: %u, pos: %u\n"),
7310 (unsigned) bfd_getl32 (ubs->base),
7311 (unsigned) bfd_getl32 (ubs->pos));
7314 break;
7315 default:
7316 fprintf (file, _("*unhandled*\n"));
7317 break;
7322 static unsigned int
7323 evax_bfd_print_valspec (const unsigned char *buf, unsigned int bufsize,
7324 int indent, FILE *file)
7326 if (bufsize < 5)
7327 return bufsize;
7329 unsigned int vflags = buf[0];
7330 unsigned int value = (unsigned) bfd_getl32 (buf + 1);
7331 unsigned int len = 5;
7333 evax_bfd_print_indent (indent, file);
7334 /* xgettext:c-format */
7335 fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
7336 buf += 5;
7337 bufsize -= 5;
7339 switch (vflags)
7341 case DST__K_VFLAGS_NOVAL:
7342 fprintf (file, _("(no value)\n"));
7343 break;
7344 case DST__K_VFLAGS_NOTACTIVE:
7345 fprintf (file, _("(not active)\n"));
7346 break;
7347 case DST__K_VFLAGS_UNALLOC:
7348 fprintf (file, _("(not allocated)\n"));
7349 break;
7350 case DST__K_VFLAGS_DSC:
7351 fprintf (file, _("(descriptor)\n"));
7352 if (value <= bufsize)
7353 evax_bfd_print_desc (buf + value, bufsize - value, indent + 1, file);
7354 break;
7355 case DST__K_VFLAGS_TVS:
7356 fprintf (file, _("(trailing value)\n"));
7357 break;
7358 case DST__K_VS_FOLLOWS:
7359 fprintf (file, _("(value spec follows)\n"));
7360 break;
7361 case DST__K_VFLAGS_BITOFFS:
7362 fprintf (file, _("(at bit offset %u)\n"), value);
7363 break;
7364 default:
7365 /* xgettext:c-format */
7366 fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
7367 (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
7368 vflags & DST__K_DISP ? 1 : 0,
7369 vflags & DST__K_INDIR ? 1 : 0);
7370 switch (vflags & DST__K_VALKIND_MASK)
7372 case DST__K_VALKIND_LITERAL:
7373 fputs (_("literal"), file);
7374 break;
7375 case DST__K_VALKIND_ADDR:
7376 fputs (_("address"), file);
7377 break;
7378 case DST__K_VALKIND_DESC:
7379 fputs (_("desc"), file);
7380 break;
7381 case DST__K_VALKIND_REG:
7382 fputs (_("reg"), file);
7383 break;
7385 fputs (")\n", file);
7386 break;
7388 return len;
7391 static void
7392 evax_bfd_print_typspec (const unsigned char *buf, unsigned int bufsize,
7393 int indent, FILE *file)
7395 if (bufsize < 3)
7396 return;
7398 unsigned char kind = buf[2];
7399 unsigned int len = (unsigned) bfd_getl16 (buf);
7401 evax_bfd_print_indent (indent, file);
7402 /* xgettext:c-format */
7403 fprintf (file, _("len: %2u, kind: %2u "), len, kind);
7404 buf += 3;
7405 bufsize -= 3;
7406 switch (kind)
7408 case DST__K_TS_ATOM:
7409 /* xgettext:c-format */
7410 if (bufsize >= 1)
7411 fprintf (file, _("atomic, type=0x%02x %s\n"),
7412 buf[0], evax_bfd_get_dsc_name (buf[0]));
7413 break;
7414 case DST__K_TS_IND:
7415 if (bufsize >= 4)
7416 fprintf (file, _("indirect, defined at 0x%08x\n"),
7417 (unsigned) bfd_getl32 (buf));
7418 break;
7419 case DST__K_TS_TPTR:
7420 fprintf (file, _("typed pointer\n"));
7421 evax_bfd_print_typspec (buf, bufsize, indent + 1, file);
7422 break;
7423 case DST__K_TS_PTR:
7424 fprintf (file, _("pointer\n"));
7425 break;
7426 case DST__K_TS_ARRAY:
7428 const unsigned char *vs;
7429 unsigned int vs_len;
7430 unsigned int vec_len;
7431 unsigned int i;
7433 if (bufsize == 0)
7434 return;
7435 fprintf (file, _("array, dim: %u, bitmap: "), buf[0]);
7436 --bufsize;
7437 vec_len = (buf[0] + 1 + 7) / 8;
7438 for (i = 0; i < vec_len; i++)
7440 if (bufsize == 0)
7441 break;
7442 fprintf (file, " %02x", buf[i + 1]);
7443 --bufsize;
7445 fputc ('\n', file);
7446 if (bufsize == 0)
7447 return;
7448 vs = buf + 1 + vec_len;
7449 evax_bfd_print_indent (indent, file);
7450 fprintf (file, _("array descriptor:\n"));
7451 vs_len = evax_bfd_print_valspec (vs, bufsize, indent + 1, file);
7452 vs += vs_len;
7453 if (bufsize > vs_len)
7455 bufsize -= vs_len;
7456 for (i = 0; i < buf[0] + 1U; i++)
7457 if (buf[1 + i / 8] & (1 << (i % 8)))
7459 evax_bfd_print_indent (indent, file);
7460 if (i == 0)
7461 fprintf (file, _("type spec for element:\n"));
7462 else
7463 fprintf (file, _("type spec for subscript %u:\n"), i);
7464 evax_bfd_print_typspec (vs, bufsize, indent + 1, file);
7465 if (bufsize < 2)
7466 break;
7467 vs_len = bfd_getl16 (vs);
7468 if (bufsize <= vs_len)
7469 break;
7470 vs += vs_len;
7471 bufsize -= vs_len;
7475 break;
7476 default:
7477 fprintf (file, _("*unhandled*\n"));
7481 static void
7482 evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
7484 unsigned int off = 0;
7485 unsigned int pc = 0;
7486 unsigned int line = 0;
7488 fprintf (file, _("Debug symbol table:\n"));
7490 while (dst_size > 0)
7492 struct vms_dst_header dsth;
7493 unsigned int len;
7494 unsigned int type;
7495 unsigned char *buf;
7497 if (bfd_read (&dsth, sizeof (dsth), abfd) != sizeof (dsth))
7499 fprintf (file, _("cannot read DST header\n"));
7500 return;
7502 len = bfd_getl16 (dsth.length);
7503 type = bfd_getl16 (dsth.type);
7504 /* xgettext:c-format */
7505 fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
7506 type, len, off);
7507 if (len > dst_size)
7508 len = dst_size;
7509 if (len < sizeof (dsth))
7511 fputc ('\n', file);
7512 break;
7514 dst_size -= len;
7515 off += len;
7516 len -= sizeof (dsth);
7517 if (len == 0)
7518 buf = NULL;
7519 else
7521 buf = _bfd_malloc_and_read (abfd, len, len);
7522 if (buf == NULL)
7524 fprintf (file, _("cannot read DST symbol\n"));
7525 return;
7528 switch (type)
7530 case DSC__K_DTYPE_V:
7531 case DSC__K_DTYPE_BU:
7532 case DSC__K_DTYPE_WU:
7533 case DSC__K_DTYPE_LU:
7534 case DSC__K_DTYPE_QU:
7535 case DSC__K_DTYPE_B:
7536 case DSC__K_DTYPE_W:
7537 case DSC__K_DTYPE_L:
7538 case DSC__K_DTYPE_Q:
7539 case DSC__K_DTYPE_F:
7540 case DSC__K_DTYPE_D:
7541 case DSC__K_DTYPE_FC:
7542 case DSC__K_DTYPE_DC:
7543 case DSC__K_DTYPE_T:
7544 case DSC__K_DTYPE_NU:
7545 case DSC__K_DTYPE_NL:
7546 case DSC__K_DTYPE_NLO:
7547 case DSC__K_DTYPE_NR:
7548 case DSC__K_DTYPE_NRO:
7549 case DSC__K_DTYPE_NZ:
7550 case DSC__K_DTYPE_P:
7551 case DSC__K_DTYPE_ZI:
7552 case DSC__K_DTYPE_ZEM:
7553 case DSC__K_DTYPE_DSC:
7554 case DSC__K_DTYPE_OU:
7555 case DSC__K_DTYPE_O:
7556 case DSC__K_DTYPE_G:
7557 case DSC__K_DTYPE_H:
7558 case DSC__K_DTYPE_GC:
7559 case DSC__K_DTYPE_HC:
7560 case DSC__K_DTYPE_CIT:
7561 case DSC__K_DTYPE_BPV:
7562 case DSC__K_DTYPE_BLV:
7563 case DSC__K_DTYPE_VU:
7564 case DSC__K_DTYPE_ADT:
7565 case DSC__K_DTYPE_VT:
7566 case DSC__K_DTYPE_T2:
7567 case DSC__K_DTYPE_VT2:
7568 fprintf (file, _("standard data: %s\n"),
7569 evax_bfd_get_dsc_name (type));
7570 evax_bfd_print_valspec (buf, len, 4, file);
7571 if (len > 6)
7572 fprintf (file, _(" name: %.*s\n"),
7573 buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7574 break;
7575 case DST__K_MODBEG:
7577 struct vms_dst_modbeg *dst = (void *)buf;
7578 unsigned char *name = buf + sizeof (*dst);
7580 fprintf (file, _("modbeg\n"));
7581 if (len < sizeof (*dst))
7582 break;
7583 /* xgettext:c-format */
7584 fprintf (file, _(" flags: %d, language: %u, "
7585 "major: %u, minor: %u\n"),
7586 dst->flags,
7587 (unsigned)bfd_getl32 (dst->language),
7588 (unsigned)bfd_getl16 (dst->major),
7589 (unsigned)bfd_getl16 (dst->minor));
7590 len -= sizeof (*dst);
7591 if (len > 0)
7593 int nlen = len - 1;
7594 fprintf (file, _(" module name: %.*s\n"),
7595 name[0] > nlen ? nlen : name[0], name + 1);
7596 if (name[0] < nlen)
7598 len -= name[0] + 1;
7599 name += name[0] + 1;
7600 nlen = len - 1;
7601 fprintf (file, _(" compiler : %.*s\n"),
7602 name[0] > nlen ? nlen : name[0], name + 1);
7606 break;
7607 case DST__K_MODEND:
7608 fprintf (file, _("modend\n"));
7609 break;
7610 case DST__K_RTNBEG:
7612 struct vms_dst_rtnbeg *dst = (void *)buf;
7613 unsigned char *name = buf + sizeof (*dst);
7615 fputs (_("rtnbeg\n"), file);
7616 if (len >= sizeof (*dst))
7618 /* xgettext:c-format */
7619 fprintf (file, _(" flags: %u, address: 0x%08x, "
7620 "pd-address: 0x%08x\n"),
7621 dst->flags,
7622 (unsigned) bfd_getl32 (dst->address),
7623 (unsigned) bfd_getl32 (dst->pd_address));
7624 len -= sizeof (*dst);
7625 if (len > 0)
7627 int nlen = len - 1;
7628 fprintf (file, _(" routine name: %.*s\n"),
7629 name[0] > nlen ? nlen : name[0], name + 1);
7633 break;
7634 case DST__K_RTNEND:
7636 struct vms_dst_rtnend *dst = (void *)buf;
7638 if (len >= sizeof (*dst))
7639 fprintf (file, _("rtnend: size 0x%08x\n"),
7640 (unsigned) bfd_getl32 (dst->size));
7642 break;
7643 case DST__K_PROLOG:
7645 struct vms_dst_prolog *dst = (void *)buf;
7647 if (len >= sizeof (*dst))
7648 /* xgettext:c-format */
7649 fprintf (file, _("prolog: bkpt address 0x%08x\n"),
7650 (unsigned) bfd_getl32 (dst->bkpt_addr));
7652 break;
7653 case DST__K_EPILOG:
7655 struct vms_dst_epilog *dst = (void *)buf;
7657 if (len >= sizeof (*dst))
7658 /* xgettext:c-format */
7659 fprintf (file, _("epilog: flags: %u, count: %u\n"),
7660 dst->flags, (unsigned) bfd_getl32 (dst->count));
7662 break;
7663 case DST__K_BLKBEG:
7665 struct vms_dst_blkbeg *dst = (void *)buf;
7666 unsigned char *name = buf + sizeof (*dst);
7668 if (len > sizeof (*dst))
7670 int nlen;
7671 len -= sizeof (*dst);
7672 nlen = len - 1;
7673 /* xgettext:c-format */
7674 fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"),
7675 (unsigned) bfd_getl32 (dst->address),
7676 name[0] > nlen ? nlen : name[0], name + 1);
7679 break;
7680 case DST__K_BLKEND:
7682 struct vms_dst_blkend *dst = (void *)buf;
7684 if (len >= sizeof (*dst))
7685 /* xgettext:c-format */
7686 fprintf (file, _("blkend: size: 0x%08x\n"),
7687 (unsigned) bfd_getl32 (dst->size));
7689 break;
7690 case DST__K_TYPSPEC:
7692 fprintf (file, _("typspec (len: %u)\n"), len);
7693 if (len >= 1)
7695 int nlen = len - 1;
7696 fprintf (file, _(" name: %.*s\n"),
7697 buf[0] > nlen ? nlen : buf[0], buf + 1);
7698 if (nlen > buf[0])
7699 evax_bfd_print_typspec (buf + 1 + buf[0], len - (1 + buf[0]),
7700 5, file);
7703 break;
7704 case DST__K_SEPTYP:
7706 if (len >= 6)
7708 fprintf (file, _("septyp, name: %.*s\n"),
7709 buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7710 evax_bfd_print_valspec (buf, len, 4, file);
7713 break;
7714 case DST__K_RECBEG:
7716 struct vms_dst_recbeg *recbeg = (void *)buf;
7718 if (len > sizeof (*recbeg))
7720 unsigned char *name = buf + sizeof (*recbeg);
7721 int nlen = len - sizeof (*recbeg) - 1;
7723 if (name[0] < nlen)
7724 nlen = name[0];
7725 fprintf (file, _("recbeg: name: %.*s\n"), nlen, name + 1);
7727 evax_bfd_print_valspec (buf, len, 4, file);
7729 len -= sizeof (*recbeg) + 1 + nlen;
7730 if (len >= 4)
7731 fprintf (file, _(" len: %u bits\n"),
7732 (unsigned) bfd_getl32 (name + 1 + nlen));
7735 break;
7736 case DST__K_RECEND:
7737 fprintf (file, _("recend\n"));
7738 break;
7739 case DST__K_ENUMBEG:
7740 if (len >= 2)
7741 /* xgettext:c-format */
7742 fprintf (file, _("enumbeg, len: %u, name: %.*s\n"),
7743 buf[0], buf[1] > len - 2 ? len - 2 : buf[1], buf + 2);
7744 break;
7745 case DST__K_ENUMELT:
7746 if (len >= 6)
7748 fprintf (file, _("enumelt, name: %.*s\n"),
7749 buf[5] > len - 6 ? len - 6 : buf[5], buf + 6);
7750 evax_bfd_print_valspec (buf, len, 4, file);
7752 break;
7753 case DST__K_ENUMEND:
7754 fprintf (file, _("enumend\n"));
7755 break;
7756 case DST__K_LABEL:
7758 struct vms_dst_label *lab = (void *)buf;
7759 if (len >= sizeof (*lab))
7761 fprintf (file, _("label, name: %.*s\n"),
7762 lab->name[0] > len - 1 ? len - 1 : lab->name[0],
7763 lab->name + 1);
7764 fprintf (file, _(" address: 0x%08x\n"),
7765 (unsigned) bfd_getl32 (lab->value));
7768 break;
7769 case DST__K_DIS_RANGE:
7770 if (len >= 4)
7772 unsigned int cnt = bfd_getl32 (buf);
7773 unsigned char *rng = buf + 4;
7774 unsigned int i;
7776 fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt);
7777 len -= 4;
7778 for (i = 0; i < cnt; i++, rng += 8)
7780 if (len < 8)
7781 break;
7782 /* xgettext:c-format */
7783 fprintf (file, _(" address: 0x%08x, size: %u\n"),
7784 (unsigned) bfd_getl32 (rng),
7785 (unsigned) bfd_getl32 (rng + 4));
7786 len -= 8;
7789 break;
7790 case DST__K_LINE_NUM:
7792 unsigned char *buf_orig = buf;
7794 fprintf (file, _("line num (len: %u)\n"), len);
7796 while (len > 0)
7798 int cmd;
7799 unsigned int val;
7800 int cmdlen = -1;
7802 cmd = *buf++;
7803 len--;
7805 fputs (" ", file);
7807 switch (cmd)
7809 case DST__K_DELTA_PC_W:
7810 if (len < 2)
7811 break;
7812 val = bfd_getl16 (buf);
7813 fprintf (file, _("delta_pc_w %u\n"), val);
7814 pc += val;
7815 line++;
7816 cmdlen = 2;
7817 break;
7818 case DST__K_INCR_LINUM:
7819 if (len < 1)
7820 break;
7821 val = *buf;
7822 fprintf (file, _("incr_linum(b): +%u\n"), val);
7823 line += val;
7824 cmdlen = 1;
7825 break;
7826 case DST__K_INCR_LINUM_W:
7827 if (len < 2)
7828 break;
7829 val = bfd_getl16 (buf);
7830 fprintf (file, _("incr_linum_w: +%u\n"), val);
7831 line += val;
7832 cmdlen = 2;
7833 break;
7834 case DST__K_INCR_LINUM_L:
7835 if (len < 4)
7836 break;
7837 val = bfd_getl32 (buf);
7838 fprintf (file, _("incr_linum_l: +%u\n"), val);
7839 line += val;
7840 cmdlen = 4;
7841 break;
7842 case DST__K_SET_LINUM:
7843 if (len < 2)
7844 break;
7845 line = bfd_getl16 (buf);
7846 fprintf (file, _("set_line_num(w) %u\n"), line);
7847 cmdlen = 2;
7848 break;
7849 case DST__K_SET_LINUM_B:
7850 if (len < 1)
7851 break;
7852 line = *buf;
7853 fprintf (file, _("set_line_num_b %u\n"), line);
7854 cmdlen = 1;
7855 break;
7856 case DST__K_SET_LINUM_L:
7857 if (len < 4)
7858 break;
7859 line = bfd_getl32 (buf);
7860 fprintf (file, _("set_line_num_l %u\n"), line);
7861 cmdlen = 4;
7862 break;
7863 case DST__K_SET_ABS_PC:
7864 if (len < 4)
7865 break;
7866 pc = bfd_getl32 (buf);
7867 fprintf (file, _("set_abs_pc: 0x%08x\n"), pc);
7868 cmdlen = 4;
7869 break;
7870 case DST__K_DELTA_PC_L:
7871 if (len < 4)
7872 break;
7873 fprintf (file, _("delta_pc_l: +0x%08x\n"),
7874 (unsigned) bfd_getl32 (buf));
7875 cmdlen = 4;
7876 break;
7877 case DST__K_TERM:
7878 if (len < 1)
7879 break;
7880 fprintf (file, _("term(b): 0x%02x"), *buf);
7881 pc += *buf;
7882 fprintf (file, _(" pc: 0x%08x\n"), pc);
7883 cmdlen = 1;
7884 break;
7885 case DST__K_TERM_W:
7886 if (len < 2)
7887 break;
7888 val = bfd_getl16 (buf);
7889 fprintf (file, _("term_w: 0x%04x"), val);
7890 pc += val;
7891 fprintf (file, _(" pc: 0x%08x\n"), pc);
7892 cmdlen = 2;
7893 break;
7894 default:
7895 if (cmd <= 0)
7897 fprintf (file, _("delta pc +%-4d"), -cmd);
7898 line++; /* FIXME: curr increment. */
7899 pc += -cmd;
7900 /* xgettext:c-format */
7901 fprintf (file, _(" pc: 0x%08x line: %5u\n"),
7902 pc, line);
7903 cmdlen = 0;
7905 else
7906 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
7907 break;
7909 if (cmdlen < 0)
7910 break;
7911 len -= cmdlen;
7912 buf += cmdlen;
7914 buf = buf_orig;
7916 break;
7917 case DST__K_SOURCE:
7919 unsigned char *buf_orig = buf;
7921 fprintf (file, _("source (len: %u)\n"), len);
7923 while (len > 0)
7925 int cmd = *buf++;
7926 int cmdlen = -1;
7928 len--;
7929 switch (cmd)
7931 case DST__K_SRC_DECLFILE:
7933 struct vms_dst_src_decl_src *src = (void *) buf;
7934 unsigned char *name;
7935 int nlen;
7937 if (len < sizeof (*src))
7938 break;
7939 /* xgettext:c-format */
7940 fprintf (file, _(" declfile: len: %u, flags: %u, "
7941 "fileid: %u\n"),
7942 src->length, src->flags,
7943 (unsigned)bfd_getl16 (src->fileid));
7944 /* xgettext:c-format */
7945 fprintf (file, _(" rms: cdt: 0x%08x %08x, "
7946 "ebk: 0x%08x, ffb: 0x%04x, "
7947 "rfo: %u\n"),
7948 (unsigned)bfd_getl32 (src->rms_cdt + 4),
7949 (unsigned)bfd_getl32 (src->rms_cdt + 0),
7950 (unsigned)bfd_getl32 (src->rms_ebk),
7951 (unsigned)bfd_getl16 (src->rms_ffb),
7952 src->rms_rfo);
7953 if (src->length > len || src->length <= sizeof (*src))
7954 break;
7955 nlen = src->length - sizeof (*src) - 1;
7956 name = buf + sizeof (*src);
7957 fprintf (file, _(" filename : %.*s\n"),
7958 name[0] > nlen ? nlen : name[0], name + 1);
7959 if (name[0] >= nlen)
7960 break;
7961 nlen -= name[0] + 1;
7962 name += name[0] + 1;
7963 fprintf (file, _(" module name: %.*s\n"),
7964 name[0] > nlen ? nlen : name[0], name + 1);
7965 if (name[0] > nlen)
7966 break;
7967 cmdlen = src->length;
7969 break;
7970 case DST__K_SRC_SETFILE:
7971 if (len < 2)
7972 break;
7973 fprintf (file, _(" setfile %u\n"),
7974 (unsigned) bfd_getl16 (buf));
7975 cmdlen = 2;
7976 break;
7977 case DST__K_SRC_SETREC_W:
7978 if (len < 2)
7979 break;
7980 fprintf (file, _(" setrec %u\n"),
7981 (unsigned) bfd_getl16 (buf));
7982 cmdlen = 2;
7983 break;
7984 case DST__K_SRC_SETREC_L:
7985 if (len < 4)
7986 break;
7987 fprintf (file, _(" setrec %u\n"),
7988 (unsigned) bfd_getl32 (buf));
7989 cmdlen = 4;
7990 break;
7991 case DST__K_SRC_SETLNUM_W:
7992 if (len < 2)
7993 break;
7994 fprintf (file, _(" setlnum %u\n"),
7995 (unsigned) bfd_getl16 (buf));
7996 cmdlen = 2;
7997 break;
7998 case DST__K_SRC_SETLNUM_L:
7999 if (len < 4)
8000 break;
8001 fprintf (file, _(" setlnum %u\n"),
8002 (unsigned) bfd_getl32 (buf));
8003 cmdlen = 4;
8004 break;
8005 case DST__K_SRC_DEFLINES_W:
8006 if (len < 2)
8007 break;
8008 fprintf (file, _(" deflines %u\n"),
8009 (unsigned) bfd_getl16 (buf));
8010 cmdlen = 2;
8011 break;
8012 case DST__K_SRC_DEFLINES_B:
8013 if (len < 1)
8014 break;
8015 fprintf (file, _(" deflines %u\n"), *buf);
8016 cmdlen = 1;
8017 break;
8018 case DST__K_SRC_FORMFEED:
8019 fprintf (file, _(" formfeed\n"));
8020 cmdlen = 0;
8021 break;
8022 default:
8023 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
8024 break;
8026 if (cmdlen < 0)
8027 break;
8028 len -= cmdlen;
8029 buf += cmdlen;
8031 buf = buf_orig;
8033 break;
8034 default:
8035 fprintf (file, _("*unhandled* dst type %u\n"), type);
8036 break;
8038 free (buf);
8042 static void
8043 evax_bfd_print_image (bfd *abfd, FILE *file)
8045 struct vms_eihd eihd;
8046 const char *name;
8047 unsigned int val;
8048 unsigned int eiha_off;
8049 unsigned int eihi_off;
8050 unsigned int eihs_off;
8051 unsigned int eisd_off;
8052 unsigned int eihef_off = 0;
8053 unsigned int eihnp_off = 0;
8054 unsigned int dmt_vbn = 0;
8055 unsigned int dmt_size = 0;
8056 unsigned int dst_vbn = 0;
8057 unsigned int dst_size = 0;
8058 unsigned int gst_vbn = 0;
8059 unsigned int gst_size = 0;
8060 unsigned int eiaf_vbn = 0;
8061 unsigned int eiaf_size = 0;
8062 unsigned int eihvn_off;
8064 if (bfd_seek (abfd, 0, SEEK_SET)
8065 || bfd_read (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
8067 fprintf (file, _("cannot read EIHD\n"));
8068 return;
8070 /* xgettext:c-format */
8071 fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
8072 (unsigned)bfd_getl32 (eihd.size),
8073 (unsigned)bfd_getl32 (eihd.hdrblkcnt));
8074 /* xgettext:c-format */
8075 fprintf (file, _(" majorid: %u, minorid: %u\n"),
8076 (unsigned)bfd_getl32 (eihd.majorid),
8077 (unsigned)bfd_getl32 (eihd.minorid));
8079 val = (unsigned)bfd_getl32 (eihd.imgtype);
8080 switch (val)
8082 case EIHD__K_EXE:
8083 name = _("executable");
8084 break;
8085 case EIHD__K_LIM:
8086 name = _("linkable image");
8087 break;
8088 default:
8089 name = _("unknown");
8090 break;
8092 /* xgettext:c-format */
8093 fprintf (file, _(" image type: %u (%s)"), val, name);
8095 val = (unsigned)bfd_getl32 (eihd.subtype);
8096 switch (val)
8098 case EIHD__C_NATIVE:
8099 name = _("native");
8100 break;
8101 case EIHD__C_CLI:
8102 name = _("CLI");
8103 break;
8104 default:
8105 name = _("unknown");
8106 break;
8108 /* xgettext:c-format */
8109 fprintf (file, _(", subtype: %u (%s)\n"), val, name);
8111 eisd_off = bfd_getl32 (eihd.isdoff);
8112 eiha_off = bfd_getl32 (eihd.activoff);
8113 eihi_off = bfd_getl32 (eihd.imgidoff);
8114 eihs_off = bfd_getl32 (eihd.symdbgoff);
8115 /* xgettext:c-format */
8116 fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
8117 "imgid: %u, patch: %u\n"),
8118 eisd_off, eiha_off, eihs_off, eihi_off,
8119 (unsigned)bfd_getl32 (eihd.patchoff));
8120 fprintf (file, _(" fixup info rva: "));
8121 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
8122 fprintf (file, _(", symbol vector rva: "));
8123 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
8124 eihvn_off = bfd_getl32 (eihd.version_array_off);
8125 fprintf (file, _("\n"
8126 " version array off: %u\n"),
8127 eihvn_off);
8128 fprintf (file,
8129 /* xgettext:c-format */
8130 _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
8131 (unsigned)bfd_getl32 (eihd.imgiocnt),
8132 (unsigned)bfd_getl32 (eihd.iochancnt),
8133 (unsigned)bfd_getl32 (eihd.privreqs + 4),
8134 (unsigned)bfd_getl32 (eihd.privreqs + 0));
8135 val = (unsigned)bfd_getl32 (eihd.lnkflags);
8136 fprintf (file, _(" linker flags: %08x:"), val);
8137 if (val & EIHD__M_LNKDEBUG)
8138 fprintf (file, " LNKDEBUG");
8139 if (val & EIHD__M_LNKNOTFR)
8140 fprintf (file, " LNKNOTFR");
8141 if (val & EIHD__M_NOP0BUFS)
8142 fprintf (file, " NOP0BUFS");
8143 if (val & EIHD__M_PICIMG)
8144 fprintf (file, " PICIMG");
8145 if (val & EIHD__M_P0IMAGE)
8146 fprintf (file, " P0IMAGE");
8147 if (val & EIHD__M_DBGDMT)
8148 fprintf (file, " DBGDMT");
8149 if (val & EIHD__M_INISHR)
8150 fprintf (file, " INISHR");
8151 if (val & EIHD__M_XLATED)
8152 fprintf (file, " XLATED");
8153 if (val & EIHD__M_BIND_CODE_SEC)
8154 fprintf (file, " BIND_CODE_SEC");
8155 if (val & EIHD__M_BIND_DATA_SEC)
8156 fprintf (file, " BIND_DATA_SEC");
8157 if (val & EIHD__M_MKTHREADS)
8158 fprintf (file, " MKTHREADS");
8159 if (val & EIHD__M_UPCALLS)
8160 fprintf (file, " UPCALLS");
8161 if (val & EIHD__M_OMV_READY)
8162 fprintf (file, " OMV_READY");
8163 if (val & EIHD__M_EXT_BIND_SECT)
8164 fprintf (file, " EXT_BIND_SECT");
8165 fprintf (file, "\n");
8166 /* xgettext:c-format */
8167 fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
8168 "match ctrl: %u, symvect_size: %u\n"),
8169 (unsigned)bfd_getl32 (eihd.ident),
8170 (unsigned)bfd_getl32 (eihd.sysver),
8171 eihd.matchctl,
8172 (unsigned)bfd_getl32 (eihd.symvect_size));
8173 fprintf (file, _(" BPAGE: %u"),
8174 (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
8175 if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT))
8177 eihef_off = bfd_getl32 (eihd.ext_fixup_off);
8178 eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
8179 /* xgettext:c-format */
8180 fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
8181 eihef_off, eihnp_off);
8183 fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias));
8185 if (eihvn_off != 0)
8187 struct vms_eihvn eihvn;
8188 unsigned int mask;
8189 unsigned int j;
8191 fprintf (file, _("system version array information:\n"));
8192 if (bfd_seek (abfd, eihvn_off, SEEK_SET)
8193 || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
8195 fprintf (file, _("cannot read EIHVN header\n"));
8196 return;
8198 mask = bfd_getl32 (eihvn.subsystem_mask);
8199 for (j = 0; j < 32; j++)
8200 if (mask & (1u << j))
8202 struct vms_eihvn_subversion ver;
8203 if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver))
8205 fprintf (file, _("cannot read EIHVN version\n"));
8206 return;
8208 fprintf (file, _(" %02u "), j);
8209 switch (j)
8211 case EIHVN__BASE_IMAGE_BIT:
8212 fputs (_("BASE_IMAGE "), file);
8213 break;
8214 case EIHVN__MEMORY_MANAGEMENT_BIT:
8215 fputs (_("MEMORY_MANAGEMENT"), file);
8216 break;
8217 case EIHVN__IO_BIT:
8218 fputs (_("IO "), file);
8219 break;
8220 case EIHVN__FILES_VOLUMES_BIT:
8221 fputs (_("FILES_VOLUMES "), file);
8222 break;
8223 case EIHVN__PROCESS_SCHED_BIT:
8224 fputs (_("PROCESS_SCHED "), file);
8225 break;
8226 case EIHVN__SYSGEN_BIT:
8227 fputs (_("SYSGEN "), file);
8228 break;
8229 case EIHVN__CLUSTERS_LOCKMGR_BIT:
8230 fputs (_("CLUSTERS_LOCKMGR "), file);
8231 break;
8232 case EIHVN__LOGICAL_NAMES_BIT:
8233 fputs (_("LOGICAL_NAMES "), file);
8234 break;
8235 case EIHVN__SECURITY_BIT:
8236 fputs (_("SECURITY "), file);
8237 break;
8238 case EIHVN__IMAGE_ACTIVATOR_BIT:
8239 fputs (_("IMAGE_ACTIVATOR "), file);
8240 break;
8241 case EIHVN__NETWORKS_BIT:
8242 fputs (_("NETWORKS "), file);
8243 break;
8244 case EIHVN__COUNTERS_BIT:
8245 fputs (_("COUNTERS "), file);
8246 break;
8247 case EIHVN__STABLE_BIT:
8248 fputs (_("STABLE "), file);
8249 break;
8250 case EIHVN__MISC_BIT:
8251 fputs (_("MISC "), file);
8252 break;
8253 case EIHVN__CPU_BIT:
8254 fputs (_("CPU "), file);
8255 break;
8256 case EIHVN__VOLATILE_BIT:
8257 fputs (_("VOLATILE "), file);
8258 break;
8259 case EIHVN__SHELL_BIT:
8260 fputs (_("SHELL "), file);
8261 break;
8262 case EIHVN__POSIX_BIT:
8263 fputs (_("POSIX "), file);
8264 break;
8265 case EIHVN__MULTI_PROCESSING_BIT:
8266 fputs (_("MULTI_PROCESSING "), file);
8267 break;
8268 case EIHVN__GALAXY_BIT:
8269 fputs (_("GALAXY "), file);
8270 break;
8271 default:
8272 fputs (_("*unknown* "), file);
8273 break;
8275 fprintf (file, ": %u.%u\n",
8276 (unsigned)bfd_getl16 (ver.major),
8277 (unsigned)bfd_getl16 (ver.minor));
8281 if (eiha_off != 0)
8283 struct vms_eiha eiha;
8285 if (bfd_seek (abfd, eiha_off, SEEK_SET)
8286 || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
8288 fprintf (file, _("cannot read EIHA\n"));
8289 return;
8291 fprintf (file, _("Image activation: (size=%u)\n"),
8292 (unsigned)bfd_getl32 (eiha.size));
8293 /* xgettext:c-format */
8294 fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
8295 (unsigned)bfd_getl32 (eiha.tfradr1_h),
8296 (unsigned)bfd_getl32 (eiha.tfradr1));
8297 /* xgettext:c-format */
8298 fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
8299 (unsigned)bfd_getl32 (eiha.tfradr2_h),
8300 (unsigned)bfd_getl32 (eiha.tfradr2));
8301 /* xgettext:c-format */
8302 fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
8303 (unsigned)bfd_getl32 (eiha.tfradr3_h),
8304 (unsigned)bfd_getl32 (eiha.tfradr3));
8305 /* xgettext:c-format */
8306 fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
8307 (unsigned)bfd_getl32 (eiha.tfradr4_h),
8308 (unsigned)bfd_getl32 (eiha.tfradr4));
8309 /* xgettext:c-format */
8310 fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"),
8311 (unsigned)bfd_getl32 (eiha.inishr_h),
8312 (unsigned)bfd_getl32 (eiha.inishr));
8314 if (eihi_off != 0)
8316 struct vms_eihi eihi;
8318 if (bfd_seek (abfd, eihi_off, SEEK_SET)
8319 || bfd_read (&eihi, sizeof (eihi), abfd) != sizeof (eihi))
8321 fprintf (file, _("cannot read EIHI\n"));
8322 return;
8324 /* xgettext:c-format */
8325 fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
8326 (unsigned) bfd_getl32 (eihi.majorid),
8327 (unsigned) bfd_getl32 (eihi.minorid));
8328 unsigned int nlen = eihi.imgnam[0];
8329 if (nlen > sizeof (eihi.imgnam) - 1)
8330 nlen = sizeof (eihi.imgnam) - 1;
8331 fprintf (file, _(" image name : %.*s\n"), nlen, eihi.imgnam + 1);
8332 fprintf (file, _(" link time : %s\n"),
8333 vms_time_to_str (eihi.linktime));
8334 nlen = eihi.imgid[0];
8335 if (nlen > sizeof (eihi.imgid) - 1)
8336 nlen = sizeof (eihi.imgid) - 1;
8337 fprintf (file, _(" image ident : %.*s\n"), nlen, eihi.imgid + 1);
8338 nlen = eihi.linkid[0];
8339 if (nlen > sizeof (eihi.linkid) - 1)
8340 nlen = sizeof (eihi.linkid) - 1;
8341 fprintf (file, _(" linker ident : %.*s\n"), nlen, eihi.linkid + 1);
8342 nlen = eihi.imgbid[0];
8343 if (nlen > sizeof (eihi.imgbid) -1 )
8344 nlen = sizeof (eihi.imgbid) - 1;
8345 fprintf (file, _(" image build ident: %.*s\n"), nlen, eihi.imgbid + 1);
8347 if (eihs_off != 0)
8349 struct vms_eihs eihs;
8351 if (bfd_seek (abfd, eihs_off, SEEK_SET)
8352 || bfd_read (&eihs, sizeof (eihs), abfd) != sizeof (eihs))
8354 fprintf (file, _("cannot read EIHS\n"));
8355 return;
8357 /* xgettext:c-format */
8358 fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
8359 (unsigned)bfd_getl32 (eihs.majorid),
8360 (unsigned)bfd_getl32 (eihs.minorid));
8361 dst_vbn = bfd_getl32 (eihs.dstvbn);
8362 dst_size = bfd_getl32 (eihs.dstsize);
8363 /* xgettext:c-format */
8364 fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"),
8365 dst_vbn, dst_size, dst_size);
8366 gst_vbn = bfd_getl32 (eihs.gstvbn);
8367 gst_size = bfd_getl32 (eihs.gstsize);
8368 /* xgettext:c-format */
8369 fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
8370 gst_vbn, gst_size);
8371 dmt_vbn = bfd_getl32 (eihs.dmtvbn);
8372 dmt_size = bfd_getl32 (eihs.dmtsize);
8373 /* xgettext:c-format */
8374 fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
8375 dmt_vbn, dmt_size);
8377 while (eisd_off != 0)
8379 struct vms_eisd eisd;
8380 unsigned int len;
8382 while (1)
8384 if (bfd_seek (abfd, eisd_off, SEEK_SET)
8385 || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
8387 fprintf (file, _("cannot read EISD\n"));
8388 return;
8390 len = (unsigned)bfd_getl32 (eisd.eisdsize);
8391 if (len != (unsigned)-1)
8392 break;
8394 /* Next block. */
8395 eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
8397 /* xgettext:c-format */
8398 fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
8399 "size: %u, offset: %u)\n"),
8400 (unsigned)bfd_getl32 (eisd.majorid),
8401 (unsigned)bfd_getl32 (eisd.minorid),
8402 len, eisd_off);
8403 if (len == 0)
8404 break;
8405 /* xgettext:c-format */
8406 fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
8407 (unsigned)bfd_getl32 (eisd.virt_addr + 4),
8408 (unsigned)bfd_getl32 (eisd.virt_addr + 0),
8409 (unsigned)bfd_getl32 (eisd.secsize));
8410 val = (unsigned)bfd_getl32 (eisd.flags);
8411 fprintf (file, _(" flags: 0x%04x"), val);
8412 if (val & EISD__M_GBL)
8413 fprintf (file, " GBL");
8414 if (val & EISD__M_CRF)
8415 fprintf (file, " CRF");
8416 if (val & EISD__M_DZRO)
8417 fprintf (file, " DZRO");
8418 if (val & EISD__M_WRT)
8419 fprintf (file, " WRT");
8420 if (val & EISD__M_INITALCODE)
8421 fprintf (file, " INITALCODE");
8422 if (val & EISD__M_BASED)
8423 fprintf (file, " BASED");
8424 if (val & EISD__M_FIXUPVEC)
8425 fprintf (file, " FIXUPVEC");
8426 if (val & EISD__M_RESIDENT)
8427 fprintf (file, " RESIDENT");
8428 if (val & EISD__M_VECTOR)
8429 fprintf (file, " VECTOR");
8430 if (val & EISD__M_PROTECT)
8431 fprintf (file, " PROTECT");
8432 if (val & EISD__M_LASTCLU)
8433 fprintf (file, " LASTCLU");
8434 if (val & EISD__M_EXE)
8435 fprintf (file, " EXE");
8436 if (val & EISD__M_NONSHRADR)
8437 fprintf (file, " NONSHRADR");
8438 if (val & EISD__M_QUAD_LENGTH)
8439 fprintf (file, " QUAD_LENGTH");
8440 if (val & EISD__M_ALLOC_64BIT)
8441 fprintf (file, " ALLOC_64BIT");
8442 fprintf (file, "\n");
8443 if (val & EISD__M_FIXUPVEC)
8445 eiaf_vbn = bfd_getl32 (eisd.vbn);
8446 eiaf_size = bfd_getl32 (eisd.secsize);
8448 /* xgettext:c-format */
8449 fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
8450 (unsigned)bfd_getl32 (eisd.vbn),
8451 eisd.pfc, eisd.matchctl, eisd.type);
8452 switch (eisd.type)
8454 case EISD__K_NORMAL:
8455 fputs (_("NORMAL"), file);
8456 break;
8457 case EISD__K_SHRFXD:
8458 fputs (_("SHRFXD"), file);
8459 break;
8460 case EISD__K_PRVFXD:
8461 fputs (_("PRVFXD"), file);
8462 break;
8463 case EISD__K_SHRPIC:
8464 fputs (_("SHRPIC"), file);
8465 break;
8466 case EISD__K_PRVPIC:
8467 fputs (_("PRVPIC"), file);
8468 break;
8469 case EISD__K_USRSTACK:
8470 fputs (_("USRSTACK"), file);
8471 break;
8472 default:
8473 fputs (_("*unknown*"), file);
8474 break;
8476 fputs (_(")\n"), file);
8477 if (val & EISD__M_GBL)
8479 unsigned int nlen = eisd.gblnam[0];
8480 if (nlen > sizeof (eisd.gblnam) - 1)
8481 nlen = sizeof (eisd.gblnam) - 1;
8482 /* xgettext:c-format */
8483 fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
8484 (unsigned) bfd_getl32 (eisd.ident),
8485 nlen, eisd.gblnam + 1);
8487 eisd_off += len;
8490 if (dmt_vbn != 0)
8492 if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
8494 fprintf (file, _("cannot read DMT\n"));
8495 return;
8498 fprintf (file, _("Debug module table:\n"));
8500 while (dmt_size > 0)
8502 struct vms_dmt_header dmth;
8503 unsigned int count;
8505 if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
8507 fprintf (file, _("cannot read DMT header\n"));
8508 return;
8510 count = bfd_getl16 (dmth.psect_count);
8511 fprintf (file,
8512 /* xgettext:c-format */
8513 _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"),
8514 (unsigned)bfd_getl32 (dmth.modbeg),
8515 (unsigned)bfd_getl32 (dmth.size), count);
8516 dmt_size -= sizeof (dmth);
8517 while (count > 0)
8519 struct vms_dmt_psect dmtp;
8521 if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
8523 fprintf (file, _("cannot read DMT psect\n"));
8524 return;
8526 /* xgettext:c-format */
8527 fprintf (file, _(" psect start: 0x%08x, length: %u\n"),
8528 (unsigned)bfd_getl32 (dmtp.start),
8529 (unsigned)bfd_getl32 (dmtp.length));
8530 count--;
8531 dmt_size -= sizeof (dmtp);
8536 if (dst_vbn != 0)
8538 if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
8540 fprintf (file, _("cannot read DST\n"));
8541 return;
8544 evax_bfd_print_dst (abfd, dst_size, file);
8546 if (gst_vbn != 0)
8548 if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
8550 fprintf (file, _("cannot read GST\n"));
8551 return;
8554 fprintf (file, _("Global symbol table:\n"));
8555 evax_bfd_print_eobj (abfd, file);
8557 if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf))
8559 unsigned char *buf;
8560 struct vms_eiaf *eiaf;
8561 unsigned int qrelfixoff;
8562 unsigned int lrelfixoff;
8563 unsigned int qdotadroff;
8564 unsigned int ldotadroff;
8565 unsigned int shrimgcnt;
8566 unsigned int shlstoff;
8567 unsigned int codeadroff;
8568 unsigned int lpfixoff;
8569 unsigned int chgprtoff;
8570 file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE;
8572 if (bfd_seek (abfd, f_off, SEEK_SET) != 0
8573 || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL)
8575 fprintf (file, _("cannot read EIHA\n"));
8576 return;
8578 eiaf = (struct vms_eiaf *)buf;
8579 fprintf (file,
8580 /* xgettext:c-format */
8581 _("Image activator fixup: (major: %u, minor: %u)\n"),
8582 (unsigned)bfd_getl32 (eiaf->majorid),
8583 (unsigned)bfd_getl32 (eiaf->minorid));
8584 /* xgettext:c-format */
8585 fprintf (file, _(" iaflink : 0x%08x %08x\n"),
8586 (unsigned)bfd_getl32 (eiaf->iaflink + 0),
8587 (unsigned)bfd_getl32 (eiaf->iaflink + 4));
8588 /* xgettext:c-format */
8589 fprintf (file, _(" fixuplnk: 0x%08x %08x\n"),
8590 (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
8591 (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
8592 fprintf (file, _(" size : %u\n"),
8593 (unsigned)bfd_getl32 (eiaf->size));
8594 fprintf (file, _(" flags: 0x%08x\n"),
8595 (unsigned)bfd_getl32 (eiaf->flags));
8596 qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
8597 lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
8598 /* xgettext:c-format */
8599 fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"),
8600 qrelfixoff, lrelfixoff);
8601 qdotadroff = bfd_getl32 (eiaf->qdotadroff);
8602 ldotadroff = bfd_getl32 (eiaf->ldotadroff);
8603 /* xgettext:c-format */
8604 fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"),
8605 qdotadroff, ldotadroff);
8606 codeadroff = bfd_getl32 (eiaf->codeadroff);
8607 lpfixoff = bfd_getl32 (eiaf->lpfixoff);
8608 /* xgettext:c-format */
8609 fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"),
8610 codeadroff, lpfixoff);
8611 chgprtoff = bfd_getl32 (eiaf->chgprtoff);
8612 fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff);
8613 shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
8614 shlstoff = bfd_getl32 (eiaf->shlstoff);
8615 /* xgettext:c-format */
8616 fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"),
8617 shlstoff, shrimgcnt);
8618 /* xgettext:c-format */
8619 fprintf (file, _(" shlextra : %5u, permctx : %5u\n"),
8620 (unsigned)bfd_getl32 (eiaf->shlextra),
8621 (unsigned)bfd_getl32 (eiaf->permctx));
8622 fprintf (file, _(" base_va : 0x%08x\n"),
8623 (unsigned)bfd_getl32 (eiaf->base_va));
8624 fprintf (file, _(" lppsbfixoff: %5u\n"),
8625 (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
8627 if (shlstoff)
8629 unsigned int j;
8631 fprintf (file, _(" Shareable images:\n"));
8632 for (j = 0;
8633 j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl);
8634 j++, shlstoff += sizeof (struct vms_shl))
8636 struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff);
8637 unsigned int nlen = shl->imgnam[0];
8638 if (nlen > sizeof (shl->imgnam) - 1)
8639 nlen = sizeof (shl->imgnam) - 1;
8640 fprintf (file,
8641 /* xgettext:c-format */
8642 _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"),
8643 j, shl->size, shl->flags,
8644 nlen, shl->imgnam + 1);
8647 if (qrelfixoff != 0)
8649 fprintf (file, _(" quad-word relocation fixups:\n"));
8650 evax_bfd_print_relocation_records (file, buf, eiaf_size,
8651 qrelfixoff, 8);
8653 if (lrelfixoff != 0)
8655 fprintf (file, _(" long-word relocation fixups:\n"));
8656 evax_bfd_print_relocation_records (file, buf, eiaf_size,
8657 lrelfixoff, 4);
8659 if (qdotadroff != 0)
8661 fprintf (file, _(" quad-word .address reference fixups:\n"));
8662 evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff);
8664 if (ldotadroff != 0)
8666 fprintf (file, _(" long-word .address reference fixups:\n"));
8667 evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff);
8669 if (codeadroff != 0)
8671 fprintf (file, _(" Code Address Reference Fixups:\n"));
8672 evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff);
8674 if (lpfixoff != 0)
8676 fprintf (file, _(" Linkage Pairs Reference Fixups:\n"));
8677 evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff);
8679 if (chgprtoff && chgprtoff <= eiaf_size - 4)
8681 unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff);
8682 unsigned int j;
8684 fprintf (file, _(" Change Protection (%u entries):\n"), count);
8685 for (j = 0, chgprtoff += 4;
8686 j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp);
8687 j++, chgprtoff += sizeof (struct vms_eicp))
8689 struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff);
8690 unsigned int prot = bfd_getl32 (eicp->newprt);
8691 fprintf (file,
8692 /* xgettext:c-format */
8693 _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
8694 (unsigned) bfd_getl32 (eicp->baseva + 4),
8695 (unsigned) bfd_getl32 (eicp->baseva + 0),
8696 (unsigned) bfd_getl32 (eicp->size),
8697 (unsigned) bfd_getl32 (eicp->newprt));
8698 switch (prot)
8700 case PRT__C_NA:
8701 fprintf (file, "NA");
8702 break;
8703 case PRT__C_RESERVED:
8704 fprintf (file, "RES");
8705 break;
8706 case PRT__C_KW:
8707 fprintf (file, "KW");
8708 break;
8709 case PRT__C_KR:
8710 fprintf (file, "KR");
8711 break;
8712 case PRT__C_UW:
8713 fprintf (file, "UW");
8714 break;
8715 case PRT__C_EW:
8716 fprintf (file, "EW");
8717 break;
8718 case PRT__C_ERKW:
8719 fprintf (file, "ERKW");
8720 break;
8721 case PRT__C_ER:
8722 fprintf (file, "ER");
8723 break;
8724 case PRT__C_SW:
8725 fprintf (file, "SW");
8726 break;
8727 case PRT__C_SREW:
8728 fprintf (file, "SREW");
8729 break;
8730 case PRT__C_SRKW:
8731 fprintf (file, "SRKW");
8732 break;
8733 case PRT__C_SR:
8734 fprintf (file, "SR");
8735 break;
8736 case PRT__C_URSW:
8737 fprintf (file, "URSW");
8738 break;
8739 case PRT__C_UREW:
8740 fprintf (file, "UREW");
8741 break;
8742 case PRT__C_URKW:
8743 fprintf (file, "URKW");
8744 break;
8745 case PRT__C_UR:
8746 fprintf (file, "UR");
8747 break;
8748 default:
8749 fputs ("??", file);
8750 break;
8752 fputc ('\n', file);
8755 free (buf);
8759 static bool
8760 vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
8762 FILE *file = (FILE *)ptr;
8764 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
8765 evax_bfd_print_image (abfd, file);
8766 else
8768 if (bfd_seek (abfd, 0, SEEK_SET))
8769 return false;
8770 evax_bfd_print_eobj (abfd, file);
8772 return true;
8775 /* Linking. */
8777 /* Slurp ETIR/EDBG/ETBT VMS object records. */
8779 static bool
8780 alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
8782 asection *cur_section;
8783 file_ptr cur_offset;
8784 asection *dst_section;
8785 file_ptr dst_offset;
8787 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
8788 return false;
8790 cur_section = NULL;
8791 cur_offset = 0;
8793 dst_section = PRIV (dst_section);
8794 dst_offset = 0;
8795 if (info)
8797 if (info->strip == strip_all || info->strip == strip_debugger)
8799 /* Discard the DST section. */
8800 dst_offset = 0;
8801 dst_section = NULL;
8803 else if (dst_section)
8805 dst_offset = dst_section->output_offset;
8806 dst_section = dst_section->output_section;
8810 while (1)
8812 int type;
8813 bool res;
8815 type = _bfd_vms_get_object_record (abfd);
8816 if (type < 0)
8818 vms_debug2 ((2, "next_record failed\n"));
8819 return false;
8821 switch (type)
8823 case EOBJ__C_ETIR:
8824 PRIV (image_section) = cur_section;
8825 PRIV (image_offset) = cur_offset;
8826 res = _bfd_vms_slurp_etir (abfd, info);
8827 cur_section = PRIV (image_section);
8828 cur_offset = PRIV (image_offset);
8829 break;
8830 case EOBJ__C_EDBG:
8831 case EOBJ__C_ETBT:
8832 if (dst_section == NULL)
8833 continue;
8834 PRIV (image_section) = dst_section;
8835 PRIV (image_offset) = dst_offset;
8836 res = _bfd_vms_slurp_etir (abfd, info);
8837 dst_offset = PRIV (image_offset);
8838 break;
8839 case EOBJ__C_EEOM:
8840 return true;
8841 default:
8842 continue;
8844 if (!res)
8846 vms_debug2 ((2, "slurp eobj type %d failed\n", type));
8847 return false;
8852 static int
8853 alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
8854 struct bfd_link_info *info ATTRIBUTE_UNUSED)
8856 return 0;
8859 /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */
8861 static bool
8862 alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib)
8864 struct alpha_vms_shlib_el *sl;
8865 asection *sect = PRIV2 (src, image_section);
8866 file_ptr offset = PRIV2 (src, image_offset);
8867 bfd_vma *p;
8869 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8870 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8871 sl->has_fixups = true;
8872 p = VEC_APPEND (sl->lp, bfd_vma);
8873 if (p == NULL)
8874 return false;
8875 *p = sect->output_section->vma + sect->output_offset + offset;
8876 sect->output_section->flags |= SEC_RELOC;
8877 return true;
8880 /* Add a code address fixup at address SECT + OFFSET to SHLIB. */
8882 static bool
8883 alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib)
8885 struct alpha_vms_shlib_el *sl;
8886 asection *sect = PRIV2 (src, image_section);
8887 file_ptr offset = PRIV2 (src, image_offset);
8888 bfd_vma *p;
8890 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8891 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8892 sl->has_fixups = true;
8893 p = VEC_APPEND (sl->ca, bfd_vma);
8894 if (p == NULL)
8895 return false;
8896 *p = sect->output_section->vma + sect->output_offset + offset;
8897 sect->output_section->flags |= SEC_RELOC;
8898 return true;
8901 /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */
8903 static bool
8904 alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
8905 bfd *shlib, bfd_vma vec)
8907 struct alpha_vms_shlib_el *sl;
8908 struct alpha_vms_vma_ref *r;
8909 asection *sect = PRIV2 (src, image_section);
8910 file_ptr offset = PRIV2 (src, image_offset);
8912 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8913 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8914 sl->has_fixups = true;
8915 r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref);
8916 if (r == NULL)
8917 return false;
8918 r->vma = sect->output_section->vma + sect->output_offset + offset;
8919 r->ref = vec;
8920 sect->output_section->flags |= SEC_RELOC;
8921 return true;
8924 static bool
8925 alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED,
8926 unsigned int shr ATTRIBUTE_UNUSED,
8927 bfd_vma vec ATTRIBUTE_UNUSED)
8929 /* Not yet supported. */
8930 return false;
8933 /* Add relocation. FIXME: Not yet emitted. */
8935 static bool
8936 alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
8938 return false;
8941 static bool
8942 alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
8944 return false;
8947 static struct bfd_hash_entry *
8948 alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry,
8949 struct bfd_hash_table *table,
8950 const char *string)
8952 struct alpha_vms_link_hash_entry *ret =
8953 (struct alpha_vms_link_hash_entry *) entry;
8955 /* Allocate the structure if it has not already been allocated by a
8956 subclass. */
8957 if (ret == NULL)
8958 ret = ((struct alpha_vms_link_hash_entry *)
8959 bfd_hash_allocate (table,
8960 sizeof (struct alpha_vms_link_hash_entry)));
8961 if (ret == NULL)
8962 return NULL;
8964 /* Call the allocation method of the superclass. */
8965 ret = ((struct alpha_vms_link_hash_entry *)
8966 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
8967 table, string));
8969 ret->sym = NULL;
8971 return (struct bfd_hash_entry *) ret;
8974 static void
8975 alpha_vms_bfd_link_hash_table_free (bfd *abfd)
8977 struct alpha_vms_link_hash_table *t;
8978 unsigned i;
8980 t = (struct alpha_vms_link_hash_table *) abfd->link.hash;
8981 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8983 struct alpha_vms_shlib_el *shlib;
8985 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8986 free (&VEC_EL (shlib->ca, bfd_vma, 0));
8987 free (&VEC_EL (shlib->lp, bfd_vma, 0));
8988 free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0));
8990 free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0));
8992 _bfd_generic_link_hash_table_free (abfd);
8995 /* Create an Alpha/VMS link hash table. */
8997 static struct bfd_link_hash_table *
8998 alpha_vms_bfd_link_hash_table_create (bfd *abfd)
9000 struct alpha_vms_link_hash_table *ret;
9001 size_t amt = sizeof (struct alpha_vms_link_hash_table);
9003 ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt);
9004 if (ret == NULL)
9005 return NULL;
9006 if (!_bfd_link_hash_table_init (&ret->root, abfd,
9007 alpha_vms_link_hash_newfunc,
9008 sizeof (struct alpha_vms_link_hash_entry)))
9010 free (ret);
9011 return NULL;
9014 VEC_INIT (ret->shrlibs);
9015 ret->fixup = NULL;
9016 ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free;
9018 return &ret->root;
9021 static bool
9022 alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
9024 unsigned int i;
9026 for (i = 0; i < PRIV (gsd_sym_count); i++)
9028 struct vms_symbol_entry *e = PRIV (syms)[i];
9029 struct alpha_vms_link_hash_entry *h;
9030 struct bfd_link_hash_entry *h_root;
9031 asymbol sym;
9033 if (!alpha_vms_convert_symbol (abfd, e, &sym))
9034 return false;
9036 if ((e->flags & EGSY__V_DEF) && abfd->selective_search)
9038 /* In selective_search mode, only add definition that are
9039 required. */
9040 h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup
9041 (info->hash, sym.name, false, false, false);
9042 if (h == NULL || h->root.type != bfd_link_hash_undefined)
9043 continue;
9045 else
9046 h = NULL;
9048 h_root = (struct bfd_link_hash_entry *) h;
9049 if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags,
9050 sym.section, sym.value, NULL,
9051 false, false, &h_root))
9052 return false;
9053 h = (struct alpha_vms_link_hash_entry *) h_root;
9055 if ((e->flags & EGSY__V_DEF)
9056 && h->sym == NULL
9057 && abfd->xvec == info->output_bfd->xvec)
9058 h->sym = e;
9061 if (abfd->flags & DYNAMIC)
9063 struct alpha_vms_shlib_el *shlib;
9065 /* We do not want to include any of the sections in a dynamic
9066 object in the output file. See comment in elflink.c. */
9067 bfd_section_list_clear (abfd);
9069 shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs,
9070 struct alpha_vms_shlib_el);
9071 if (shlib == NULL)
9072 return false;
9073 shlib->abfd = abfd;
9074 VEC_INIT (shlib->ca);
9075 VEC_INIT (shlib->lp);
9076 VEC_INIT (shlib->qr);
9077 PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1;
9080 return true;
9083 static bool
9084 alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
9086 int pass;
9087 struct bfd_link_hash_entry **pundef;
9088 struct bfd_link_hash_entry **next_pundef;
9090 /* We only accept VMS libraries. */
9091 if (info->output_bfd->xvec != abfd->xvec)
9093 bfd_set_error (bfd_error_wrong_format);
9094 return false;
9097 /* The archive_pass field in the archive itself is used to
9098 initialize PASS, since we may search the same archive multiple
9099 times. */
9100 pass = ++abfd->archive_pass;
9102 /* Look through the list of undefined symbols. */
9103 for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
9105 struct bfd_link_hash_entry *h;
9106 symindex symidx;
9107 bfd *element;
9108 bfd *orig_element;
9110 h = *pundef;
9111 next_pundef = &(*pundef)->u.undef.next;
9113 /* When a symbol is defined, it is not necessarily removed from
9114 the list. */
9115 if (h->type != bfd_link_hash_undefined
9116 && h->type != bfd_link_hash_common)
9118 /* Remove this entry from the list, for general cleanliness
9119 and because we are going to look through the list again
9120 if we search any more libraries. We can't remove the
9121 entry if it is the tail, because that would lose any
9122 entries we add to the list later on. */
9123 if (*pundef != info->hash->undefs_tail)
9125 *pundef = *next_pundef;
9126 next_pundef = pundef;
9128 continue;
9131 /* Look for this symbol in the archive hash table. */
9132 symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string);
9133 if (symidx == BFD_NO_MORE_SYMBOLS)
9135 /* Nothing in this slot. */
9136 continue;
9139 element = bfd_get_elt_at_index (abfd, symidx);
9140 if (element == NULL)
9141 return false;
9143 if (element->archive_pass == -1 || element->archive_pass == pass)
9145 /* Next symbol if this archive is wrong or already handled. */
9146 continue;
9149 if (! bfd_check_format (element, bfd_object))
9151 element->archive_pass = -1;
9152 return false;
9155 orig_element = element;
9156 if (bfd_is_thin_archive (abfd))
9158 element = _bfd_vms_lib_get_imagelib_file (element);
9159 if (element == NULL || !bfd_check_format (element, bfd_object))
9161 orig_element->archive_pass = -1;
9162 return false;
9166 /* Unlike the generic linker, we know that this element provides
9167 a definition for an undefined symbol and we know that we want
9168 to include it. We don't need to check anything. */
9169 if (!(*info->callbacks
9170 ->add_archive_element) (info, element, h->root.string, &element))
9171 continue;
9172 if (!alpha_vms_link_add_object_symbols (element, info))
9173 return false;
9175 orig_element->archive_pass = pass;
9178 return true;
9181 static bool
9182 alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
9184 switch (bfd_get_format (abfd))
9186 case bfd_object:
9187 vms_debug2 ((2, "vms_link_add_symbols for object %s\n",
9188 abfd->filename));
9189 return alpha_vms_link_add_object_symbols (abfd, info);
9190 break;
9191 case bfd_archive:
9192 vms_debug2 ((2, "vms_link_add_symbols for archive %s\n",
9193 abfd->filename));
9194 return alpha_vms_link_add_archive_symbols (abfd, info);
9195 break;
9196 default:
9197 bfd_set_error (bfd_error_wrong_format);
9198 return false;
9202 static bool
9203 alpha_vms_build_fixups (struct bfd_link_info *info)
9205 struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info);
9206 unsigned char *content;
9207 unsigned int i;
9208 unsigned int sz = 0;
9209 unsigned int lp_sz = 0;
9210 unsigned int ca_sz = 0;
9211 unsigned int qr_sz = 0;
9212 unsigned int shrimg_cnt = 0;
9213 unsigned int chgprt_num = 0;
9214 unsigned int chgprt_sz = 0;
9215 struct vms_eiaf *eiaf;
9216 unsigned int off;
9217 asection *sec;
9219 /* Shared libraries. */
9220 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
9222 struct alpha_vms_shlib_el *shlib;
9224 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
9226 if (!shlib->has_fixups)
9227 continue;
9229 shrimg_cnt++;
9231 if (VEC_COUNT (shlib->ca) > 0)
9233 /* Header + entries. */
9234 ca_sz += 8;
9235 ca_sz += VEC_COUNT (shlib->ca) * 4;
9237 if (VEC_COUNT (shlib->lp) > 0)
9239 /* Header + entries. */
9240 lp_sz += 8;
9241 lp_sz += VEC_COUNT (shlib->lp) * 4;
9243 if (VEC_COUNT (shlib->qr) > 0)
9245 /* Header + entries. */
9246 qr_sz += 8;
9247 qr_sz += VEC_COUNT (shlib->qr) * 8;
9250 /* Add markers. */
9251 if (ca_sz > 0)
9252 ca_sz += 8;
9253 if (lp_sz > 0)
9254 lp_sz += 8;
9255 if (qr_sz > 0)
9256 qr_sz += 8;
9258 /* Finish now if there is no content. */
9259 if (ca_sz + lp_sz + qr_sz == 0)
9260 return true;
9262 /* Add an eicp entry for the fixup itself. */
9263 chgprt_num = 1;
9264 for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
9266 /* This isect could be made RO or EXE after relocations are applied. */
9267 if ((sec->flags & SEC_RELOC) != 0
9268 && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
9269 chgprt_num++;
9271 chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp);
9273 /* Allocate section content (round-up size) */
9274 sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl)
9275 + ca_sz + lp_sz + qr_sz + chgprt_sz;
9276 sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
9277 content = bfd_zalloc (info->output_bfd, sz);
9278 if (content == NULL)
9279 return false;
9281 sec = alpha_vms_link_hash (info)->fixup;
9282 sec->contents = content;
9283 sec->alloced = 1;
9284 sec->size = sz;
9286 eiaf = (struct vms_eiaf *)content;
9287 off = sizeof (struct vms_eiaf);
9288 bfd_putl32 (0, eiaf->majorid);
9289 bfd_putl32 (0, eiaf->minorid);
9290 bfd_putl32 (0, eiaf->iaflink);
9291 bfd_putl32 (0, eiaf->fixuplnk);
9292 bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size);
9293 bfd_putl32 (0, eiaf->flags);
9294 bfd_putl32 (0, eiaf->qrelfixoff);
9295 bfd_putl32 (0, eiaf->lrelfixoff);
9296 bfd_putl32 (0, eiaf->qdotadroff);
9297 bfd_putl32 (0, eiaf->ldotadroff);
9298 bfd_putl32 (0, eiaf->codeadroff);
9299 bfd_putl32 (0, eiaf->lpfixoff);
9300 bfd_putl32 (0, eiaf->chgprtoff);
9301 bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff);
9302 bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt);
9303 bfd_putl32 (0, eiaf->shlextra);
9304 bfd_putl32 (0, eiaf->permctx);
9305 bfd_putl32 (0, eiaf->base_va);
9306 bfd_putl32 (0, eiaf->lppsbfixoff);
9308 if (shrimg_cnt)
9310 shrimg_cnt = 0;
9312 /* Write shl. */
9313 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
9315 struct alpha_vms_shlib_el *shlib;
9316 struct vms_shl *shl;
9318 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
9320 if (!shlib->has_fixups)
9321 continue;
9323 /* Renumber shared images. */
9324 PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++;
9326 shl = (struct vms_shl *)(content + off);
9327 bfd_putl32 (0, shl->baseva);
9328 bfd_putl32 (0, shl->shlptr);
9329 bfd_putl32 (0, shl->ident);
9330 bfd_putl32 (0, shl->permctx);
9331 shl->size = sizeof (struct vms_shl);
9332 bfd_putl16 (0, shl->fill_1);
9333 shl->flags = 0;
9334 bfd_putl32 (0, shl->icb);
9335 shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name));
9336 memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name),
9337 shl->imgnam[0]);
9339 off += sizeof (struct vms_shl);
9342 /* CA fixups. */
9343 if (ca_sz != 0)
9345 bfd_putl32 (off, eiaf->codeadroff);
9347 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
9349 struct alpha_vms_shlib_el *shlib;
9350 unsigned int j;
9352 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
9354 if (VEC_COUNT (shlib->ca) == 0)
9355 continue;
9357 bfd_putl32 (VEC_COUNT (shlib->ca), content + off);
9358 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
9359 off += 8;
9361 for (j = 0; j < VEC_COUNT (shlib->ca); j++)
9363 bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr,
9364 content + off);
9365 off += 4;
9369 bfd_putl32 (0, content + off);
9370 bfd_putl32 (0, content + off + 4);
9371 off += 8;
9374 /* LP fixups. */
9375 if (lp_sz != 0)
9377 bfd_putl32 (off, eiaf->lpfixoff);
9379 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
9381 struct alpha_vms_shlib_el *shlib;
9382 unsigned int j;
9384 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
9386 if (VEC_COUNT (shlib->lp) == 0)
9387 continue;
9389 bfd_putl32 (VEC_COUNT (shlib->lp), content + off);
9390 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
9391 off += 8;
9393 for (j = 0; j < VEC_COUNT (shlib->lp); j++)
9395 bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr,
9396 content + off);
9397 off += 4;
9401 bfd_putl32 (0, content + off);
9402 bfd_putl32 (0, content + off + 4);
9403 off += 8;
9406 /* QR fixups. */
9407 if (qr_sz != 0)
9409 bfd_putl32 (off, eiaf->qdotadroff);
9411 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
9413 struct alpha_vms_shlib_el *shlib;
9414 unsigned int j;
9416 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
9418 if (VEC_COUNT (shlib->qr) == 0)
9419 continue;
9421 bfd_putl32 (VEC_COUNT (shlib->qr), content + off);
9422 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
9423 off += 8;
9425 for (j = 0; j < VEC_COUNT (shlib->qr); j++)
9427 struct alpha_vms_vma_ref *r;
9428 r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j);
9429 bfd_putl32 (r->vma - t->base_addr, content + off);
9430 bfd_putl32 (r->ref, content + off + 4);
9431 off += 8;
9435 bfd_putl32 (0, content + off);
9436 bfd_putl32 (0, content + off + 4);
9437 off += 8;
9441 /* Write the change protection table. */
9442 bfd_putl32 (off, eiaf->chgprtoff);
9443 bfd_putl32 (chgprt_num, content + off);
9444 off += 4;
9446 for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
9448 struct vms_eicp *eicp;
9449 unsigned int prot;
9451 if ((sec->flags & SEC_LINKER_CREATED) != 0 &&
9452 strcmp (sec->name, "$FIXUP$") == 0)
9453 prot = PRT__C_UREW;
9454 else if ((sec->flags & SEC_RELOC) != 0
9455 && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
9456 prot = PRT__C_UR;
9457 else
9458 continue;
9460 eicp = (struct vms_eicp *)(content + off);
9461 bfd_putl64 (sec->vma - t->base_addr, eicp->baseva);
9462 bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1),
9463 eicp->size);
9464 bfd_putl32 (prot, eicp->newprt);
9465 off += sizeof (struct vms_eicp);
9468 return true;
9471 /* Called by bfd_hash_traverse to fill the symbol table.
9472 Return FALSE in case of failure. */
9474 static bool
9475 alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov)
9477 struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh;
9478 struct bfd_link_info *info = (struct bfd_link_info *)infov;
9479 struct alpha_vms_link_hash_entry *h;
9480 struct vms_symbol_entry *sym;
9482 if (hc->type == bfd_link_hash_warning)
9484 hc = hc->u.i.link;
9485 if (hc->type == bfd_link_hash_new)
9486 return true;
9488 h = (struct alpha_vms_link_hash_entry *) hc;
9490 switch (h->root.type)
9492 case bfd_link_hash_undefined:
9493 return true;
9494 case bfd_link_hash_new:
9495 case bfd_link_hash_warning:
9496 abort ();
9497 case bfd_link_hash_undefweak:
9498 return true;
9499 case bfd_link_hash_defined:
9500 case bfd_link_hash_defweak:
9502 asection *sec = h->root.u.def.section;
9504 /* FIXME: this is certainly a symbol from a dynamic library. */
9505 if (bfd_is_abs_section (sec))
9506 return true;
9508 if (sec->owner->flags & DYNAMIC)
9509 return true;
9511 break;
9512 case bfd_link_hash_common:
9513 break;
9514 case bfd_link_hash_indirect:
9515 return true;
9518 /* Do not write not kept symbols. */
9519 if (info->strip == strip_some
9520 && bfd_hash_lookup (info->keep_hash, h->root.root.string,
9521 false, false) != NULL)
9522 return true;
9524 if (h->sym == NULL)
9526 /* This symbol doesn't come from a VMS object. So we suppose it is
9527 a data. */
9528 int len = strlen (h->root.root.string);
9530 sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd,
9531 sizeof (*sym) + len);
9532 if (sym == NULL)
9533 abort ();
9534 sym->namelen = len;
9535 memcpy (sym->name, h->root.root.string, len);
9536 sym->name[len] = 0;
9537 sym->owner = info->output_bfd;
9539 sym->typ = EGSD__C_SYMG;
9540 sym->data_type = 0;
9541 sym->flags = EGSY__V_DEF | EGSY__V_REL;
9542 sym->symbol_vector = h->root.u.def.value;
9543 sym->section = h->root.u.def.section;
9544 sym->value = h->root.u.def.value;
9546 else
9547 sym = h->sym;
9549 if (!add_symbol_entry (info->output_bfd, sym))
9550 return false;
9552 return true;
9555 static bool
9556 alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
9558 asection *o;
9559 struct bfd_link_order *p;
9560 bfd *sub;
9561 asection *fixupsec;
9562 bfd_vma base_addr;
9563 bfd_vma last_addr;
9564 asection *dst;
9565 asection *dmt;
9567 if (bfd_link_relocatable (info))
9569 /* FIXME: we do not yet support relocatable link. It is not obvious
9570 how to do it for debug infos. */
9571 (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n"));
9572 return false;
9575 abfd->outsymbols = NULL;
9576 abfd->symcount = 0;
9578 /* Mark all sections which will be included in the output file. */
9579 for (o = abfd->sections; o != NULL; o = o->next)
9580 for (p = o->map_head.link_order; p != NULL; p = p->next)
9581 if (p->type == bfd_indirect_link_order)
9582 p->u.indirect.section->linker_mark = true;
9584 #if 0
9585 /* Handle all the link order information for the sections. */
9586 for (o = abfd->sections; o != NULL; o = o->next)
9588 printf ("For section %s (at 0x%08x, flags=0x%08x):\n",
9589 o->name, (unsigned)o->vma, (unsigned)o->flags);
9591 for (p = o->map_head.link_order; p != NULL; p = p->next)
9593 printf (" at 0x%08x - 0x%08x: ",
9594 (unsigned)p->offset, (unsigned)(p->offset + p->size - 1));
9595 switch (p->type)
9597 case bfd_section_reloc_link_order:
9598 case bfd_symbol_reloc_link_order:
9599 printf (" section/symbol reloc\n");
9600 break;
9601 case bfd_indirect_link_order:
9602 printf (" section %s of %s\n",
9603 p->u.indirect.section->name,
9604 p->u.indirect.section->owner->filename);
9605 break;
9606 case bfd_data_link_order:
9607 printf (" explicit data\n");
9608 break;
9609 default:
9610 printf (" *unknown* type %u\n", p->type);
9611 break;
9615 #endif
9617 /* Generate the symbol table. */
9618 BFD_ASSERT (PRIV (syms) == NULL);
9619 if (info->strip != strip_all)
9620 bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info);
9622 /* Find the entry point. */
9623 if (bfd_get_start_address (abfd) == 0)
9625 bfd *startbfd = NULL;
9627 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
9629 /* Consider only VMS object files. */
9630 if (sub->xvec != abfd->xvec)
9631 continue;
9633 if (!PRIV2 (sub, eom_data).eom_has_transfer)
9634 continue;
9635 if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd)
9636 continue;
9637 if (startbfd != NULL
9638 && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR))
9640 (*info->callbacks->einfo)
9641 /* xgettext:c-format */
9642 (_("%P: multiple entry points: in modules %pB and %pB\n"),
9643 startbfd, sub);
9644 continue;
9646 startbfd = sub;
9649 if (startbfd)
9651 unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx;
9652 bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr;
9653 asection *sec;
9655 sec = PRIV2 (startbfd, sections)[ps_idx];
9657 bfd_set_start_address
9658 (abfd, sec->output_section->vma + sec->output_offset + tfradr);
9662 /* Set transfer addresses. */
9664 int i;
9665 struct bfd_link_hash_entry *h;
9667 i = 0;
9668 PRIV (transfer_address[i++]) = 0xffffffff00000340ULL; /* SYS$IMGACT */
9669 h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", false, false, true);
9670 if (h != NULL && h->type == bfd_link_hash_defined)
9671 PRIV (transfer_address[i++]) =
9672 alpha_vms_get_sym_value (h->u.def.section, h->u.def.value);
9673 PRIV (transfer_address[i++]) = bfd_get_start_address (abfd);
9674 while (i < 4)
9675 PRIV (transfer_address[i++]) = 0;
9678 /* Allocate contents.
9679 Also compute the virtual base address. */
9680 base_addr = (bfd_vma)-1;
9681 last_addr = 0;
9682 for (o = abfd->sections; o != NULL; o = o->next)
9684 if (o->flags & SEC_HAS_CONTENTS)
9686 o->contents = bfd_alloc (abfd, o->size);
9687 if (o->contents == NULL)
9688 return false;
9689 o->alloced = 1;
9691 if (o->flags & SEC_LOAD)
9693 if (o->vma < base_addr)
9694 base_addr = o->vma;
9695 if (o->vma + o->size > last_addr)
9696 last_addr = o->vma + o->size;
9698 /* Clear the RELOC flags. Currently we don't support incremental
9699 linking. We use the RELOC flag for computing the eicp entries. */
9700 o->flags &= ~SEC_RELOC;
9703 /* Create the fixup section. */
9704 fixupsec = bfd_make_section_anyway_with_flags
9705 (info->output_bfd, "$FIXUP$",
9706 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
9707 if (fixupsec == NULL)
9708 return false;
9709 last_addr = (last_addr + 0xffff) & ~0xffff;
9710 fixupsec->vma = last_addr;
9712 alpha_vms_link_hash (info)->fixup = fixupsec;
9713 alpha_vms_link_hash (info)->base_addr = base_addr;
9715 /* Create the DMT section, if necessary. */
9716 BFD_ASSERT (PRIV (dst_section) == NULL);
9717 dst = bfd_get_section_by_name (abfd, "$DST$");
9718 if (dst != NULL && dst->size == 0)
9719 dst = NULL;
9720 if (dst != NULL)
9722 PRIV (dst_section) = dst;
9723 dmt = bfd_make_section_anyway_with_flags
9724 (info->output_bfd, "$DMT$",
9725 SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
9726 if (dmt == NULL)
9727 return false;
9729 else
9730 dmt = NULL;
9732 /* Read all sections from the inputs. */
9733 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
9735 if (sub->flags & DYNAMIC)
9737 alpha_vms_create_eisd_for_shared (abfd, sub);
9738 continue;
9741 if (!alpha_vms_read_sections_content (sub, info))
9742 return false;
9745 /* Handle all the link order information for the sections.
9746 Note: past this point, it is not possible to create new sections. */
9747 for (o = abfd->sections; o != NULL; o = o->next)
9749 for (p = o->map_head.link_order; p != NULL; p = p->next)
9751 switch (p->type)
9753 case bfd_section_reloc_link_order:
9754 case bfd_symbol_reloc_link_order:
9755 abort ();
9756 return false;
9757 case bfd_indirect_link_order:
9758 /* Already done. */
9759 break;
9760 default:
9761 if (! _bfd_default_link_order (abfd, info, o, p))
9762 return false;
9763 break;
9768 /* Compute fixups. */
9769 if (!alpha_vms_build_fixups (info))
9770 return false;
9772 /* Compute the DMT. */
9773 if (dmt != NULL)
9775 int pass;
9776 unsigned char *contents = NULL;
9778 /* In pass 1, compute the size. In pass 2, write the DMT contents. */
9779 for (pass = 0; pass < 2; pass++)
9781 unsigned int off = 0;
9783 /* For each object file (ie for each module). */
9784 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
9786 asection *sub_dst;
9787 struct vms_dmt_header *dmth = NULL;
9788 unsigned int psect_count;
9790 /* Skip this module if it has no DST. */
9791 sub_dst = PRIV2 (sub, dst_section);
9792 if (sub_dst == NULL || sub_dst->size == 0)
9793 continue;
9795 if (pass == 1)
9797 /* Write the header. */
9798 dmth = (struct vms_dmt_header *)(contents + off);
9799 bfd_putl32 (sub_dst->output_offset, dmth->modbeg);
9800 bfd_putl32 (sub_dst->size, dmth->size);
9803 off += sizeof (struct vms_dmt_header);
9804 psect_count = 0;
9806 /* For each section (ie for each psect). */
9807 for (o = sub->sections; o != NULL; o = o->next)
9809 /* Only consider interesting sections. */
9810 if (!(o->flags & SEC_ALLOC))
9811 continue;
9812 if (o->flags & SEC_LINKER_CREATED)
9813 continue;
9815 if (pass == 1)
9817 /* Write an entry. */
9818 struct vms_dmt_psect *dmtp;
9820 dmtp = (struct vms_dmt_psect *)(contents + off);
9821 bfd_putl32 (o->output_offset + o->output_section->vma,
9822 dmtp->start);
9823 bfd_putl32 (o->size, dmtp->length);
9824 psect_count++;
9826 off += sizeof (struct vms_dmt_psect);
9828 if (pass == 1)
9829 bfd_putl32 (psect_count, dmth->psect_count);
9832 if (pass == 0)
9834 contents = bfd_zalloc (info->output_bfd, off);
9835 if (contents == NULL)
9836 return false;
9837 dmt->contents = contents;
9838 dmt->alloced = 1;
9839 dmt->size = off;
9841 else
9843 BFD_ASSERT (off == dmt->size);
9848 return true;
9851 /* Read the contents of a section.
9852 buf points to a buffer of buf_size bytes to be filled with
9853 section data (starting at offset into section) */
9855 static bool
9856 alpha_vms_get_section_contents (bfd *abfd, asection *section,
9857 void *buf, file_ptr offset,
9858 bfd_size_type count)
9860 /* Handle image sections. */
9861 if (section->filepos != 0
9862 || (section->flags & SEC_HAS_CONTENTS) == 0)
9863 return _bfd_generic_get_section_contents (abfd, section,
9864 buf, offset, count);
9866 /* A section with a zero filepos implies the section has no direct
9867 file backing. Its contents must be calculated by processing ETIR
9868 records. */
9870 /* Safety check. */
9871 if (offset + count < count
9872 || offset + count > section->size)
9874 bfd_set_error (bfd_error_invalid_operation);
9875 return false;
9878 if (section->size == 0)
9879 return true;
9881 /* If we haven't yet read ETIR/EDBG/ETBT records, do so. */
9882 if ((section->flags & SEC_IN_MEMORY) == 0)
9884 /* Alloc memory and read ETIRs. */
9885 for (asection *sec = abfd->sections; sec; sec = sec->next)
9887 if (sec->size != 0
9888 && sec->filepos == 0
9889 && (sec->flags & SEC_HAS_CONTENTS) != 0)
9891 BFD_ASSERT (sec->contents == NULL);
9893 sec->contents = bfd_zalloc (abfd, sec->size);
9894 sec->flags |= SEC_IN_MEMORY;
9895 if (sec->contents == NULL)
9896 return false;
9897 sec->alloced = 1;
9900 if (!alpha_vms_read_sections_content (abfd, NULL))
9901 return false;
9904 BFD_ASSERT (section->contents != NULL);
9905 memcpy (buf, section->contents + offset, count);
9906 return true;
9910 /* Set the format of a file being written. */
9912 static bool
9913 alpha_vms_mkobject (bfd * abfd)
9915 const bfd_arch_info_type *arch;
9917 vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd));
9919 if (!vms_initialize (abfd))
9920 return false;
9922 PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE);
9923 if (PRIV (recwr.buf) == NULL)
9924 return false;
9926 arch = bfd_scan_arch ("alpha");
9928 if (arch == 0)
9930 bfd_set_error (bfd_error_wrong_format);
9931 return false;
9934 abfd->arch_info = arch;
9935 return true;
9939 /* 4.1, generic. */
9941 /* Called when the BFD is being closed to do any necessary cleanup. */
9943 static bool
9944 vms_close_and_cleanup (bfd * abfd)
9946 vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
9948 if (abfd == NULL || abfd->tdata.any == NULL)
9949 return true;
9951 if (abfd->format == bfd_object)
9953 alpha_vms_free_private (abfd);
9955 #ifdef VMS
9956 if (abfd->direction == write_direction)
9958 /* Last step on VMS is to convert the file to variable record length
9959 format. */
9960 if (!bfd_cache_close (abfd))
9961 return false;
9962 if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename))
9963 return false;
9965 #endif
9968 return _bfd_generic_close_and_cleanup (abfd);
9971 /* Called when a new section is created. */
9973 static bool
9974 vms_new_section_hook (bfd * abfd, asection *section)
9976 size_t amt;
9978 vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n",
9979 abfd, section->index, section->name));
9981 if (!bfd_set_section_alignment (section, 0))
9982 return false;
9984 vms_debug2 ((7, "%u: %s\n", section->index, section->name));
9986 amt = sizeof (struct vms_section_data_struct);
9987 section->used_by_bfd = bfd_zalloc (abfd, amt);
9988 if (section->used_by_bfd == NULL)
9989 return false;
9991 /* Create the section symbol. */
9992 return _bfd_generic_new_section_hook (abfd, section);
9995 /* Part 4.5, symbols. */
9997 /* Print symbol to file according to how. how is one of
9998 bfd_print_symbol_name just print the name
9999 bfd_print_symbol_more print more (???)
10000 bfd_print_symbol_all print all we know, which is not much right now :-). */
10002 static void
10003 vms_print_symbol (bfd * abfd,
10004 void * file,
10005 asymbol *symbol,
10006 bfd_print_symbol_type how)
10008 vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n",
10009 abfd, file, symbol, how));
10011 switch (how)
10013 case bfd_print_symbol_name:
10014 case bfd_print_symbol_more:
10015 fprintf ((FILE *)file," %s", symbol->name);
10016 break;
10018 case bfd_print_symbol_all:
10020 const char *section_name = symbol->section->name;
10022 bfd_print_symbol_vandf (abfd, file, symbol);
10024 fprintf ((FILE *) file," %-8s %s", section_name, symbol->name);
10026 break;
10030 /* Return information about symbol in ret.
10032 fill type, value and name
10033 type:
10034 A absolute
10035 B bss segment symbol
10036 C common symbol
10037 D data segment symbol
10038 f filename
10039 t a static function symbol
10040 T text segment symbol
10041 U undefined
10042 - debug. */
10044 static void
10045 vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
10046 asymbol *symbol,
10047 symbol_info *ret)
10049 asection *sec;
10051 vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret));
10053 sec = symbol->section;
10055 if (ret == NULL)
10056 return;
10058 if (sec == NULL)
10059 ret->type = 'U';
10060 else if (bfd_is_com_section (sec))
10061 ret->type = 'C';
10062 else if (bfd_is_abs_section (sec))
10063 ret->type = 'A';
10064 else if (bfd_is_und_section (sec))
10065 ret->type = 'U';
10066 else if (bfd_is_ind_section (sec))
10067 ret->type = 'I';
10068 else if ((symbol->flags & BSF_FUNCTION)
10069 || (bfd_section_flags (sec) & SEC_CODE))
10070 ret->type = 'T';
10071 else if (bfd_section_flags (sec) & SEC_DATA)
10072 ret->type = 'D';
10073 else if (bfd_section_flags (sec) & SEC_ALLOC)
10074 ret->type = 'B';
10075 else
10076 ret->type = '?';
10078 if (ret->type != 'U')
10079 ret->value = symbol->value + symbol->section->vma;
10080 else
10081 ret->value = 0;
10082 ret->name = symbol->name;
10085 /* Return TRUE if the given symbol sym in the BFD abfd is
10086 a compiler generated local label, else return FALSE. */
10088 static bool
10089 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
10090 const char *name)
10092 return name[0] == '$';
10095 /* Part 4.7, writing an object file. */
10097 /* Sets the contents of the section section in BFD abfd to the data starting
10098 in memory at LOCATION. The data is written to the output section starting
10099 at offset offset for count bytes.
10101 Normally TRUE is returned, else FALSE. Possible error returns are:
10102 o bfd_error_no_contents - The output section does not have the
10103 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
10104 o and some more too */
10106 static bool
10107 _bfd_vms_set_section_contents (bfd * abfd,
10108 asection *section,
10109 const void * location,
10110 file_ptr offset,
10111 bfd_size_type count)
10113 if (section->contents == NULL)
10115 section->contents = bfd_alloc (abfd, section->size);
10116 if (section->contents == NULL)
10117 return false;
10118 section->alloced = 1;
10120 memcpy (section->contents + offset, location, (size_t) count);
10123 return true;
10126 /* Set the architecture and machine type in BFD abfd to arch and mach.
10127 Find the correct pointer to a structure and insert it into the arch_info
10128 pointer. */
10130 static bool
10131 alpha_vms_set_arch_mach (bfd *abfd,
10132 enum bfd_architecture arch, unsigned long mach)
10134 if (arch != bfd_arch_alpha
10135 && arch != bfd_arch_unknown)
10136 return false;
10138 return bfd_default_set_arch_mach (abfd, arch, mach);
10141 /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */
10143 void
10144 bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
10145 asection *sec, flagword no_flags, flagword flags)
10147 vms_section_data (sec)->no_flags = no_flags;
10148 vms_section_data (sec)->flags = flags;
10151 struct vms_private_data_struct *
10152 bfd_vms_get_data (bfd *abfd)
10154 return (struct vms_private_data_struct *)abfd->tdata.any;
10157 #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
10158 #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
10159 #define vms_init_private_section_data _bfd_generic_init_private_section_data
10160 #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
10161 #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
10162 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
10163 #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
10165 /* Symbols table. */
10166 #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol
10167 #define alpha_vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
10168 #define alpha_vms_print_symbol vms_print_symbol
10169 #define alpha_vms_get_symbol_info vms_get_symbol_info
10170 #define alpha_vms_get_symbol_version_string \
10171 _bfd_nosymbols_get_symbol_version_string
10173 #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols
10174 #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
10175 #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno
10176 #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info
10177 #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
10178 #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_line
10179 #define alpha_vms_find_nearest_line_with_alt \
10180 _bfd_nosymbols_find_nearest_line_with_alt
10181 #define alpha_vms_find_line _bfd_nosymbols_find_line
10182 #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name
10184 /* Generic table. */
10185 #define alpha_vms_close_and_cleanup vms_close_and_cleanup
10186 #define alpha_vms_bfd_free_cached_info _bfd_bool_bfd_true
10187 #define alpha_vms_new_section_hook vms_new_section_hook
10188 #define alpha_vms_set_section_contents _bfd_vms_set_section_contents
10190 #define alpha_vms_bfd_get_relocated_section_contents \
10191 bfd_generic_get_relocated_section_contents
10193 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
10194 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
10195 #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags
10196 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
10197 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
10198 #define alpha_vms_bfd_group_name bfd_generic_group_name
10199 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
10200 #define alpha_vms_section_already_linked \
10201 _bfd_generic_section_already_linked
10203 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
10204 #define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
10205 #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop
10206 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
10207 #define alpha_vms_bfd_copy_link_hash_symbol_type \
10208 _bfd_generic_copy_link_hash_symbol_type
10210 #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section
10212 #define alpha_vms_get_dynamic_symtab_upper_bound \
10213 _bfd_nodynamic_get_dynamic_symtab_upper_bound
10214 #define alpha_vms_canonicalize_dynamic_symtab \
10215 _bfd_nodynamic_canonicalize_dynamic_symtab
10216 #define alpha_vms_get_dynamic_reloc_upper_bound \
10217 _bfd_nodynamic_get_dynamic_reloc_upper_bound
10218 #define alpha_vms_canonicalize_dynamic_reloc \
10219 _bfd_nodynamic_canonicalize_dynamic_reloc
10220 #define alpha_vms_bfd_link_check_relocs _bfd_generic_link_check_relocs
10222 const bfd_target alpha_vms_vec =
10224 "vms-alpha", /* Name. */
10225 bfd_target_evax_flavour,
10226 BFD_ENDIAN_LITTLE, /* Data byte order is little. */
10227 BFD_ENDIAN_LITTLE, /* Header byte order is little. */
10229 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS
10230 | WP_TEXT | D_PAGED), /* Object flags. */
10231 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
10232 | SEC_READONLY | SEC_CODE | SEC_DATA
10233 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */
10234 0, /* symbol_leading_char. */
10235 ' ', /* ar_pad_char. */
10236 15, /* ar_max_namelen. */
10237 0, /* match priority. */
10238 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
10239 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
10240 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
10241 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
10242 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
10243 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
10244 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
10246 { /* bfd_check_format. */
10247 _bfd_dummy_target,
10248 alpha_vms_object_p,
10249 _bfd_vms_lib_alpha_archive_p,
10250 _bfd_dummy_target
10252 { /* bfd_set_format. */
10253 _bfd_bool_bfd_false_error,
10254 alpha_vms_mkobject,
10255 _bfd_vms_lib_alpha_mkarchive,
10256 _bfd_bool_bfd_false_error
10258 { /* bfd_write_contents. */
10259 _bfd_bool_bfd_false_error,
10260 alpha_vms_write_object_contents,
10261 _bfd_vms_lib_write_archive_contents,
10262 _bfd_bool_bfd_false_error
10265 BFD_JUMP_TABLE_GENERIC (alpha_vms),
10266 BFD_JUMP_TABLE_COPY (vms),
10267 BFD_JUMP_TABLE_CORE (_bfd_nocore),
10268 BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib),
10269 BFD_JUMP_TABLE_SYMBOLS (alpha_vms),
10270 BFD_JUMP_TABLE_RELOCS (alpha_vms),
10271 BFD_JUMP_TABLE_WRITE (alpha_vms),
10272 BFD_JUMP_TABLE_LINK (alpha_vms),
10273 BFD_JUMP_TABLE_DYNAMIC (alpha_vms),
10275 NULL,
10277 NULL