PR ld/11843
[binutils.git] / bfd / vms-alpha.c
blob5d38d1df2c953ae849efa38ac81d2aa16d4126fd
1 /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files.
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 Initial version written by Klaus Kaempf (kkaempf@rmi.de)
6 Major rewrite by Adacore.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 /* TODO:
24 o overlayed sections
25 o PIC
26 o Generation of shared image
27 o Relocation optimizations
28 o EISD for the stack
29 o Vectors isect
30 o 64 bits sections
31 o Entry point
32 o LIB$INITIALIZE
33 o protected sections (for messages)
34 ...
37 #include "sysdep.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))
76 /* The r_type field in a reloc is one of the following values. */
77 #define ALPHA_R_IGNORE 0
78 #define ALPHA_R_REFQUAD 1
79 #define ALPHA_R_BRADDR 2
80 #define ALPHA_R_HINT 3
81 #define ALPHA_R_SREL16 4
82 #define ALPHA_R_SREL32 5
83 #define ALPHA_R_SREL64 6
84 #define ALPHA_R_OP_PUSH 7
85 #define ALPHA_R_OP_STORE 8
86 #define ALPHA_R_OP_PSUB 9
87 #define ALPHA_R_OP_PRSHIFT 10
88 #define ALPHA_R_LINKAGE 11
89 #define ALPHA_R_REFLONG 12
90 #define ALPHA_R_CODEADDR 13
91 #define ALPHA_R_NOP 14
92 #define ALPHA_R_BSR 15
93 #define ALPHA_R_LDA 16
94 #define ALPHA_R_BOH 17
96 /* These are used with DST_S_C_LINE_NUM. */
97 #define DST_S_C_LINE_NUM_HEADER_SIZE 4
99 /* These are used with DST_S_C_SOURCE */
101 #define DST_S_B_PCLINE_UNSBYTE 1
102 #define DST_S_W_PCLINE_UNSWORD 1
103 #define DST_S_L_PCLINE_UNSLONG 1
105 #define DST_S_B_MODBEG_NAME 14
106 #define DST_S_L_RTNBEG_ADDRESS 5
107 #define DST_S_B_RTNBEG_NAME 13
108 #define DST_S_L_RTNEND_SIZE 5
110 /* These are used with DST_S_C_SOURCE. */
111 #define DST_S_C_SOURCE_HEADER_SIZE 4
113 #define DST_S_B_SRC_DF_LENGTH 1
114 #define DST_S_W_SRC_DF_FILEID 3
115 #define DST_S_B_SRC_DF_FILENAME 20
116 #define DST_S_B_SRC_UNSBYTE 1
117 #define DST_S_W_SRC_UNSWORD 1
118 #define DST_S_L_SRC_UNSLONG 1
120 /* Debugger symbol definitions. */
122 #define DBG_S_L_DMT_MODBEG 0
123 #define DBG_S_L_DST_SIZE 4
124 #define DBG_S_W_DMT_PSECT_COUNT 8
125 #define DBG_S_C_DMT_HEADER_SIZE 12
127 #define DBG_S_L_DMT_PSECT_START 0
128 #define DBG_S_L_DMT_PSECT_LENGTH 4
129 #define DBG_S_C_DMT_PSECT_SIZE 8
131 /* VMS module header. */
133 struct hdr_struct
135 char hdr_b_strlvl;
136 int hdr_l_arch1;
137 int hdr_l_arch2;
138 int hdr_l_recsiz;
139 char *hdr_t_name;
140 char *hdr_t_version;
141 char *hdr_t_date;
142 char *hdr_c_lnm;
143 char *hdr_c_src;
144 char *hdr_c_ttl;
147 #define EMH_DATE_LENGTH 17
149 /* VMS End-Of-Module records (EOM/EEOM). */
151 struct eom_struct
153 unsigned int eom_l_total_lps;
154 unsigned short eom_w_comcod;
155 bfd_boolean eom_has_transfer;
156 unsigned char eom_b_tfrflg;
157 unsigned int eom_l_psindx;
158 unsigned int eom_l_tfradr;
161 struct vms_symbol_entry
163 bfd *owner;
165 /* Common fields. */
166 unsigned char typ;
167 unsigned char data_type;
168 unsigned short flags;
170 /* Section and offset/value of the symbol. */
171 unsigned int value;
172 asection *section;
174 /* Section and offset/value for the entry point (only for subprg). */
175 asection *code_section;
176 unsigned int code_value;
178 /* Symbol vector offset. */
179 unsigned int symbol_vector;
181 /* Length of the name. */
182 unsigned char namelen;
184 char name[1];
187 /* Stack value for push/pop commands. */
189 struct stack_struct
191 bfd_vma value;
192 unsigned int reloc;
195 #define STACKSIZE 128
197 /* A minimal decoding of DST compilation units. We only decode
198 what's needed to get to the line number information. */
200 struct fileinfo
202 char *name;
203 unsigned int srec;
206 struct srecinfo
208 struct srecinfo *next;
209 unsigned int line;
210 unsigned int sfile;
211 unsigned int srec;
214 struct lineinfo
216 struct lineinfo *next;
217 bfd_vma address;
218 unsigned int line;
221 struct funcinfo
223 struct funcinfo *next;
224 char *name;
225 bfd_vma low;
226 bfd_vma high;
229 struct module
231 /* Chain the previously read compilation unit. */
232 struct module *next;
234 /* The module name. */
235 char *name;
237 /* The start offset and size of debug info in the DST section. */
238 unsigned int modbeg;
239 unsigned int size;
241 /* The lowest and highest addresses contained in this compilation
242 unit as specified in the compilation unit header. */
243 bfd_vma low;
244 bfd_vma high;
246 /* The listing line table. */
247 struct lineinfo *line_table;
249 /* The source record table. */
250 struct srecinfo *srec_table;
252 /* A list of the functions found in this module. */
253 struct funcinfo *func_table;
255 /* Current allocation of file_table. */
256 unsigned int file_table_count;
258 /* An array of the files making up this module. */
259 struct fileinfo *file_table;
262 /* BFD private data for alpha-vms. */
264 struct vms_private_data_struct
266 /* If true, relocs have been read. */
267 bfd_boolean reloc_done;
269 /* Record input buffer. */
270 struct vms_rec_rd recrd;
271 struct vms_rec_wr recwr;
273 struct hdr_struct hdr_data; /* data from HDR/EMH record */
274 struct eom_struct eom_data; /* data from EOM/EEOM record */
276 /* Transfer addresses (entry points). */
277 bfd_vma transfer_address[4];
279 /* Array of GSD sections to get the correspond BFD one. */
280 unsigned int section_max; /* Size of the sections array. */
281 unsigned int section_count; /* Number of GSD sections. */
282 asection **sections;
284 /* Array of raw symbols. */
285 struct vms_symbol_entry **syms;
287 /* Canonicalized symbols. */
288 asymbol **csymbols;
290 /* Number of symbols. */
291 unsigned int gsd_sym_count;
292 /* Size of the syms array. */
293 unsigned int max_sym_count;
294 /* Number of procedure symbols. */
295 unsigned int norm_sym_count;
297 /* Stack used to evaluate TIR/ETIR commands. */
298 struct stack_struct *stack;
299 int stackptr;
301 /* Content reading. */
302 asection *image_section; /* section for image_ptr */
303 file_ptr image_offset; /* Offset for image_ptr. */
305 struct module *modules; /* list of all compilation units */
307 asection *dst_section;
309 unsigned int dst_ptr_offsets_count; /* # of offsets in following array */
310 unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */
312 /* Shared library support */
313 bfd_vma symvva; /* relative virtual address of symbol vector */
314 unsigned int ident;
315 unsigned char matchctl;
317 /* Shared library index. This is used for input bfd while linking. */
318 unsigned int shr_index;
320 /* Used to place structures in the file. */
321 file_ptr file_pos;
323 /* Simply linked list of eisd. */
324 struct vms_internal_eisd_map *eisd_head;
325 struct vms_internal_eisd_map *eisd_tail;
327 /* Simply linked list of eisd for shared libraries. */
328 struct vms_internal_eisd_map *gbl_eisd_head;
329 struct vms_internal_eisd_map *gbl_eisd_tail;
331 /* linkage index counter used by conditional store commands */
332 int vms_linkage_index;
334 /* see tc-alpha.c of gas for a description. */
335 int flag_hash_long_names; /* -+, hash instead of truncate */
336 int flag_show_after_trunc; /* -H, show hashing/truncation */
339 #define PRIV2(abfd, name) \
340 (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
341 #define PRIV(name) PRIV2(abfd,name)
344 /* Used to keep extra VMS specific information for a given section.
346 reloc_size holds the size of the relocation stream, note this
347 is very different from the number of relocations as VMS relocations
348 are variable length.
350 reloc_stream is the actual stream of relocation entries. */
352 struct vms_section_data_struct
354 /* Maximnum number of entries in sec->relocation. */
355 unsigned reloc_max;
357 /* Corresponding eisd. Used only while generating executables. */
358 struct vms_internal_eisd_map *eisd;
360 /* PSC flags to be clear. */
361 flagword no_flags;
363 /* PSC flags to be set. */
364 flagword flags;
367 #define vms_section_data(sec) \
368 ((struct vms_section_data_struct *)sec->used_by_bfd)
370 /* To be called from the debugger. */
371 struct vms_private_data_struct *bfd_vms_get_data (bfd *abfd);
373 static int vms_get_remaining_object_record (bfd *abfd, int read_so_far);
374 static bfd_boolean _bfd_vms_slurp_object_records (bfd * abfd);
375 static void alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *);
376 static void alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *);
377 static void alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *,
378 bfd_vma);
379 static void alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int,
380 bfd_vma);
381 static void alpha_vms_add_lw_reloc (struct bfd_link_info *info);
382 static void alpha_vms_add_qw_reloc (struct bfd_link_info *info);
384 struct vector_type
386 unsigned int max_el;
387 unsigned int nbr_el;
388 void *els;
391 /* Number of elements in VEC. */
393 #define VEC_COUNT(VEC) ((VEC).nbr_el)
395 /* Get the address of the Nth element. */
397 #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N])
399 #define VEC_INIT(VEC) \
400 do { \
401 (VEC).max_el = 0; \
402 (VEC).nbr_el = 0; \
403 (VEC).els = NULL; \
404 } while (0)
406 /* Be sure there is room for a new element. */
408 static void vector_grow1 (struct vector_type *vec, size_t elsz);
410 /* Allocate room for a new element and return its address. */
412 #define VEC_APPEND(VEC, TYPE) \
413 (vector_grow1 (&VEC, sizeof (TYPE)), &VEC_EL(VEC, TYPE, (VEC).nbr_el++))
415 /* Append an element. */
417 #define VEC_APPEND_EL(VEC, TYPE, EL) \
418 (*(VEC_APPEND (VEC, TYPE)) = EL)
420 struct alpha_vms_vma_ref
422 bfd_vma vma; /* Vma in the output. */
423 bfd_vma ref; /* Reference in the input. */
426 struct alpha_vms_shlib_el
428 bfd *abfd;
429 bfd_boolean has_fixups;
431 struct vector_type lp; /* Vector of bfd_vma. */
432 struct vector_type ca; /* Vector of bfd_vma. */
433 struct vector_type qr; /* Vector of struct alpha_vms_vma_ref. */
436 /* Alpha VMS linker hash table. */
438 struct alpha_vms_link_hash_table
440 struct bfd_link_hash_table root;
442 /* Vector of shared libaries. */
443 struct vector_type shrlibs;
445 /* Fixup section. */
446 asection *fixup;
448 /* Base address. Used by fixups. */
449 bfd_vma base_addr;
452 #define alpha_vms_link_hash(INFO) \
453 ((struct alpha_vms_link_hash_table *)(INFO->hash))
455 /* Alpha VMS linker hash table entry. */
457 struct alpha_vms_link_hash_entry
459 struct bfd_link_hash_entry root;
461 /* Pointer to the original vms symbol. */
462 struct vms_symbol_entry *sym;
465 /* Image reading. */
467 /* Read & process EIHD record.
468 Return TRUE on success, FALSE on error. */
470 static bfd_boolean
471 _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
472 unsigned int *eihs_offset)
474 unsigned int imgtype, size;
475 bfd_vma symvva;
476 struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
478 vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
480 size = bfd_getl32 (eihd->size);
481 imgtype = bfd_getl32 (eihd->imgtype);
483 if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
484 abfd->flags |= EXEC_P;
486 symvva = bfd_getl64 (eihd->symvva);
487 if (symvva != 0)
489 PRIV (symvva) = symvva;
490 abfd->flags |= DYNAMIC;
493 PRIV (ident) = bfd_getl32 (eihd->ident);
494 PRIV (matchctl) = eihd->matchctl;
496 *eisd_offset = bfd_getl32 (eihd->isdoff);
497 *eihs_offset = bfd_getl32 (eihd->symdbgoff);
499 vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
500 size, imgtype, (unsigned long)symvva,
501 *eisd_offset, *eihs_offset));
503 return TRUE;
506 /* Read & process EISD record.
507 Return TRUE on success, FALSE on error. */
509 static bfd_boolean
510 _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
512 int section_count = 0;
514 vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
516 while (1)
518 struct vms_eisd *eisd;
519 unsigned int rec_size;
520 unsigned int size;
521 unsigned long long vaddr;
522 unsigned int flags;
523 unsigned int vbn;
524 char *name = NULL;
525 asection *section;
526 flagword bfd_flags;
528 eisd = (struct vms_eisd *)(PRIV (recrd.rec) + offset);
529 rec_size = bfd_getl32 (eisd->eisdsize);
531 if (rec_size == 0)
532 break;
534 /* Skip to next block if pad. */
535 if (rec_size == 0xffffffff)
537 offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
538 continue;
540 else
541 offset += rec_size;
543 size = bfd_getl32 (eisd->secsize);
544 vaddr = bfd_getl64 (eisd->virt_addr);
545 flags = bfd_getl32 (eisd->flags);
546 vbn = bfd_getl32 (eisd->vbn);
548 vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n",
549 offset, size, (unsigned long)vaddr, flags, vbn));
551 /* VMS combines psects from .obj files into isects in the .exe. This
552 process doesn't preserve enough information to reliably determine
553 what's in each section without examining the data. This is
554 especially true of DWARF debug sections. */
555 bfd_flags = SEC_ALLOC;
556 if (vbn != 0)
557 bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD;
559 if (flags & EISD__M_EXE)
560 bfd_flags |= SEC_CODE;
562 if (flags & EISD__M_NONSHRADR)
563 bfd_flags |= SEC_DATA;
565 if (!(flags & EISD__M_WRT))
566 bfd_flags |= SEC_READONLY;
568 if (flags & EISD__M_DZRO)
569 bfd_flags |= SEC_DATA;
571 if (flags & EISD__M_FIXUPVEC)
572 bfd_flags |= SEC_DATA;
574 if (flags & EISD__M_CRF)
575 bfd_flags |= SEC_DATA;
577 if (flags & EISD__M_GBL)
579 name = _bfd_vms_save_counted_string (eisd->gblnam);
580 bfd_flags |= SEC_COFF_SHARED_LIBRARY;
581 bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
583 else if (flags & EISD__M_FIXUPVEC)
584 name = "$FIXUPVEC$";
585 else if (eisd->type == EISD__K_USRSTACK)
586 name = "$STACK$";
587 else
589 const char *pfx;
591 name = (char*) bfd_alloc (abfd, 32);
592 if (flags & EISD__M_DZRO)
593 pfx = "BSS";
594 else if (flags & EISD__M_EXE)
595 pfx = "CODE";
596 else if (!(flags & EISD__M_WRT))
597 pfx = "RO";
598 else
599 pfx = "LOCAL";
600 BFD_ASSERT (section_count < 999);
601 sprintf (name, "$%s_%03d$", pfx, section_count++);
604 section = bfd_make_section (abfd, name);
606 if (!section)
607 return FALSE;
609 section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
610 section->size = size;
611 section->vma = vaddr;
613 if (!bfd_set_section_flags (abfd, section, bfd_flags))
614 return FALSE;
617 return TRUE;
620 /* Read & process EIHS record.
621 Return TRUE on success, FALSE on error. */
623 static bfd_boolean
624 _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
626 unsigned char *p = PRIV (recrd.rec) + offset;
627 unsigned int gstvbn = bfd_getl32 (p + EIHS__L_GSTVBN);
628 unsigned int gstsize ATTRIBUTE_UNUSED = bfd_getl32 (p + EIHS__L_GSTSIZE);
629 unsigned int dstvbn = bfd_getl32 (p + EIHS__L_DSTVBN);
630 unsigned int dstsize = bfd_getl32 (p + EIHS__L_DSTSIZE);
631 unsigned int dmtvbn = bfd_getl32 (p + EIHS__L_DMTVBN);
632 unsigned int dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES);
633 asection *section;
635 #if VMS_DEBUG
636 vms_debug (8, "_bfd_vms_slurp_ihs\n");
637 vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
638 gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes);
639 #endif
641 if (dstvbn)
643 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
645 section = bfd_make_section (abfd, "$DST$");
646 if (!section)
647 return FALSE;
649 section->size = dstsize;
650 section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
652 if (!bfd_set_section_flags (abfd, section, bfd_flags))
653 return FALSE;
655 PRIV (dst_section) = section;
656 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
659 if (dmtvbn)
661 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
663 section = bfd_make_section (abfd, "$DMT$");
664 if (!section)
665 return FALSE;
667 section->size = dmtbytes;
668 section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
670 if (!bfd_set_section_flags (abfd, section, bfd_flags))
671 return FALSE;
674 if (gstvbn)
676 if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET))
678 bfd_set_error (bfd_error_file_truncated);
679 return FALSE;
682 if (_bfd_vms_slurp_object_records (abfd) != TRUE)
683 return FALSE;
685 abfd->flags |= HAS_SYMS;
688 return TRUE;
691 /* Object file reading. */
693 /* Object file input functions. */
695 /* Get next record from object file to vms_buf.
696 Set PRIV(buf_size) and return it
698 This is a little tricky since it should be portable.
700 The openVMS object file has 'variable length' which means that
701 read() returns data in chunks of (hopefully) correct and expected
702 size. The linker (and other tools on VMS) depend on that. Unix
703 doesn't know about 'formatted' files, so reading and writing such
704 an object file in a Unix environment is not trivial.
706 With the tool 'file' (available on all VMS FTP sites), one
707 can view and change the attributes of a file. Changing from
708 'variable length' to 'fixed length, 512 bytes' reveals the
709 record size at the first 2 bytes of every record. The same
710 may happen during the transfer of object files from VMS to Unix,
711 at least with UCX, the DEC implementation of TCP/IP.
713 The VMS format repeats the size at bytes 2 & 3 of every record.
715 On the first call (file_format == FF_UNKNOWN) we check if
716 the first and the third byte pair (!) of the record match.
717 If they do it's an object file in an Unix environment or with
718 wrong attributes (FF_FOREIGN), else we should be in a VMS
719 environment where read() returns the record size (FF_NATIVE).
721 Reading is always done in 2 steps:
722 1. first just the record header is read and the size extracted,
723 2. then the read buffer is adjusted and the remaining bytes are
724 read in.
726 All file I/O is done on even file positions. */
728 #define VMS_OBJECT_ADJUSTMENT 2
730 static void
731 maybe_adjust_record_pointer_for_object (bfd *abfd)
733 /* Set the file format once for all on the first invocation. */
734 if (PRIV (recrd.file_format) == FF_UNKNOWN)
736 if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4]
737 && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5])
738 PRIV (recrd.file_format) = FF_FOREIGN;
739 else
740 PRIV (recrd.file_format) = FF_NATIVE;
743 /* The adjustment is needed only in an Unix environment. */
744 if (PRIV (recrd.file_format) == FF_FOREIGN)
745 PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT;
748 /* Implement step #1 of the object record reading procedure.
749 Return the record type or -1 on failure. */
751 static int
752 _bfd_vms_get_object_record (bfd *abfd)
754 unsigned int test_len = 6;
755 int type;
757 vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
759 /* Skip alignment byte if the current position is odd. */
760 if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1))
762 if (bfd_bread (PRIV (recrd.buf), 1, abfd) != 1)
764 bfd_set_error (bfd_error_file_truncated);
765 return -1;
769 /* Read the record header */
770 if (bfd_bread (PRIV (recrd.buf), test_len, abfd) != test_len)
772 bfd_set_error (bfd_error_file_truncated);
773 return -1;
776 /* Reset the record pointer. */
777 PRIV (recrd.rec) = PRIV (recrd.buf);
778 maybe_adjust_record_pointer_for_object (abfd);
780 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
781 return -1;
783 type = bfd_getl16 (PRIV (recrd.rec));
785 vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n",
786 PRIV (recrd.rec), PRIV (recrd.rec_size), type));
788 return type;
791 /* Implement step #2 of the object record reading procedure.
792 Return the size of the record or 0 on failure. */
794 static int
795 vms_get_remaining_object_record (bfd *abfd, int read_so_far)
797 unsigned int to_read;
799 vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
801 /* Extract record size. */
802 PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
804 if (PRIV (recrd.rec_size) <= 0)
806 bfd_set_error (bfd_error_file_truncated);
807 return 0;
810 /* That's what the linker manual says. */
811 if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
813 bfd_set_error (bfd_error_file_truncated);
814 return 0;
817 /* Take into account object adjustment. */
818 to_read = PRIV (recrd.rec_size);
819 if (PRIV (recrd.file_format) == FF_FOREIGN)
820 to_read += VMS_OBJECT_ADJUSTMENT;
822 /* Adjust the buffer. */
823 if (to_read > PRIV (recrd.buf_size))
825 PRIV (recrd.buf)
826 = (unsigned char *) bfd_realloc (PRIV (recrd.buf), to_read);
827 if (PRIV (recrd.buf) == NULL)
828 return 0;
829 PRIV (recrd.buf_size) = to_read;
832 /* Read the remaining record. */
833 to_read -= read_so_far;
835 vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
837 if (bfd_bread (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
839 bfd_set_error (bfd_error_file_truncated);
840 return 0;
843 /* Reset the record pointer. */
844 PRIV (recrd.rec) = PRIV (recrd.buf);
845 maybe_adjust_record_pointer_for_object (abfd);
847 vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
848 PRIV (recrd.rec_size)));
850 return PRIV (recrd.rec_size);
853 /* Read and process emh record.
854 Return TRUE on success, FALSE on error. */
856 static bfd_boolean
857 _bfd_vms_slurp_ehdr (bfd *abfd)
859 unsigned char *ptr;
860 unsigned char *vms_rec;
861 int subtype;
863 vms_rec = PRIV (recrd.rec);
865 vms_debug2 ((2, "HDR/EMH\n"));
867 subtype = bfd_getl16 (vms_rec + 4);
869 vms_debug2 ((3, "subtype %d\n", subtype));
871 switch (subtype)
873 case EMH__C_MHD:
874 /* Module header. */
875 PRIV (hdr_data).hdr_b_strlvl = vms_rec[6];
876 PRIV (hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8);
877 PRIV (hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12);
878 PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
879 PRIV (hdr_data).hdr_t_name = _bfd_vms_save_counted_string (vms_rec + 20);
880 ptr = vms_rec + 20 + vms_rec[20] + 1;
881 PRIV (hdr_data).hdr_t_version =_bfd_vms_save_counted_string (ptr);
882 ptr += *ptr + 1;
883 PRIV (hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
884 break;
886 case EMH__C_LNM:
887 PRIV (hdr_data).hdr_c_lnm =
888 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
889 break;
891 case EMH__C_SRC:
892 PRIV (hdr_data).hdr_c_src =
893 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
894 break;
896 case EMH__C_TTL:
897 PRIV (hdr_data).hdr_c_ttl =
898 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
899 break;
901 case EMH__C_CPR:
902 case EMH__C_MTC:
903 case EMH__C_GTX:
904 break;
906 default:
907 bfd_set_error (bfd_error_wrong_format);
908 return FALSE;
911 return TRUE;
914 /* Typical sections for evax object files. */
916 #define EVAX_ABS_NAME "$ABS$"
917 #define EVAX_CODE_NAME "$CODE$"
918 #define EVAX_LINK_NAME "$LINK$"
919 #define EVAX_DATA_NAME "$DATA$"
920 #define EVAX_BSS_NAME "$BSS$"
921 #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$"
922 #define EVAX_READONLY_NAME "$READONLY$"
923 #define EVAX_LITERAL_NAME "$LITERAL$"
924 #define EVAX_LITERALS_NAME "$LITERALS"
925 #define EVAX_COMMON_NAME "$COMMON$"
926 #define EVAX_LOCAL_NAME "$LOCAL$"
928 struct sec_flags_struct
930 const char *name; /* Name of section. */
931 int vflags_always;
932 flagword flags_always; /* Flags we set always. */
933 int vflags_hassize;
934 flagword flags_hassize; /* Flags we set if the section has a size > 0. */
937 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */
939 static const struct sec_flags_struct evax_section_flags[] =
941 { EVAX_ABS_NAME,
942 EGPS__V_SHR,
944 EGPS__V_SHR,
945 0 },
946 { EVAX_CODE_NAME,
947 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE,
948 SEC_CODE,
949 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE,
950 SEC_CODE | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
951 { EVAX_LITERAL_NAME,
952 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD,
953 SEC_DATA | SEC_READONLY,
954 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD,
955 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD },
956 { EVAX_LINK_NAME,
957 EGPS__V_REL | EGPS__V_RD,
958 SEC_DATA | SEC_READONLY,
959 EGPS__V_REL | EGPS__V_RD,
960 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD },
961 { EVAX_DATA_NAME,
962 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
963 SEC_DATA,
964 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
965 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
966 { EVAX_BSS_NAME,
967 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
968 SEC_NO_FLAGS,
969 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD,
970 SEC_ALLOC },
971 { EVAX_READONLYADDR_NAME,
972 EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD,
973 SEC_DATA | SEC_READONLY,
974 EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD,
975 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD },
976 { EVAX_READONLY_NAME,
977 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD,
978 SEC_DATA | SEC_READONLY,
979 EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD,
980 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD },
981 { EVAX_LOCAL_NAME,
982 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
983 SEC_DATA,
984 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
985 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD },
986 { EVAX_LITERALS_NAME,
987 EGPS__V_PIC | EGPS__V_OVR,
988 SEC_DATA | SEC_READONLY,
989 EGPS__V_PIC | EGPS__V_OVR,
990 SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD },
991 { NULL,
992 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
993 SEC_DATA,
994 EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT,
995 SEC_IN_MEMORY | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }
998 /* Retrieve BFD section flags by name and size. */
1000 static flagword
1001 vms_secflag_by_name (const struct sec_flags_struct *section_flags,
1002 const char *name,
1003 int hassize)
1005 int i = 0;
1007 while (section_flags[i].name != NULL)
1009 if (strcmp (name, section_flags[i].name) == 0)
1011 if (hassize)
1012 return section_flags[i].flags_hassize;
1013 else
1014 return section_flags[i].flags_always;
1016 i++;
1018 if (hassize)
1019 return section_flags[i].flags_hassize;
1020 return section_flags[i].flags_always;
1023 /* Retrieve VMS section flags by name and size. */
1025 static flagword
1026 vms_esecflag_by_name (const struct sec_flags_struct *section_flags,
1027 const char *name,
1028 int hassize)
1030 int i = 0;
1032 while (section_flags[i].name != NULL)
1034 if (strcmp (name, section_flags[i].name) == 0)
1036 if (hassize)
1037 return section_flags[i].vflags_hassize;
1038 else
1039 return section_flags[i].vflags_always;
1041 i++;
1043 if (hassize)
1044 return section_flags[i].vflags_hassize;
1045 return section_flags[i].vflags_always;
1048 /* Add SYM to the symbol table of ABFD.
1049 Return FALSE in case of error. */
1051 static bfd_boolean
1052 add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym)
1054 if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
1056 if (PRIV (max_sym_count) == 0)
1058 PRIV (max_sym_count) = 128;
1059 PRIV (syms) = bfd_malloc
1060 (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
1062 else
1064 PRIV (max_sym_count) *= 2;
1065 PRIV (syms) = bfd_realloc
1066 (PRIV (syms),
1067 (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
1069 if (PRIV (syms) == NULL)
1070 return FALSE;
1073 PRIV (syms)[PRIV (gsd_sym_count)++] = sym;
1074 return TRUE;
1077 /* Create a symbol whose name is ASCIC and add it to ABFD.
1078 Return NULL in case of error. */
1080 static struct vms_symbol_entry *
1081 add_symbol (bfd *abfd, const unsigned char *ascic)
1083 struct vms_symbol_entry *entry;
1084 int len;
1086 len = *ascic++;
1087 entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
1088 if (entry == NULL)
1089 return NULL;
1090 entry->namelen = len;
1091 memcpy (entry->name, ascic, len);
1092 entry->name[len] = 0;
1093 entry->owner = abfd;
1095 if (!add_symbol_entry (abfd, entry))
1096 return NULL;
1097 return entry;
1100 /* Read and process EGSD. Return FALSE on failure. */
1102 static bfd_boolean
1103 _bfd_vms_slurp_egsd (bfd *abfd)
1105 int gsd_type, gsd_size;
1106 unsigned char *vms_rec;
1107 unsigned long base_addr;
1109 vms_debug2 ((2, "EGSD\n"));
1111 PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */
1112 PRIV (recrd.rec_size) -= 8;
1114 /* Calculate base address for each section. */
1115 base_addr = 0L;
1117 while (PRIV (recrd.rec_size) > 0)
1119 vms_rec = PRIV (recrd.rec);
1121 gsd_type = bfd_getl16 (vms_rec);
1122 gsd_size = bfd_getl16 (vms_rec + 2);
1124 vms_debug2 ((3, "egsd_type %d\n", gsd_type));
1126 switch (gsd_type)
1128 case EGSD__C_PSC:
1129 /* Program section definition. */
1131 struct vms_egps *egps = (struct vms_egps *)vms_rec;
1132 flagword new_flags, old_flags;
1133 asection *section;
1135 old_flags = bfd_getl16 (egps->flags);
1137 if ((old_flags & EGPS__V_REL) == 0)
1139 /* Use the global absolute section for all absolute sections. */
1140 section = bfd_abs_section_ptr;
1142 else
1144 char *name;
1145 unsigned long align_addr;
1147 name = _bfd_vms_save_counted_string (&egps->namlng);
1149 section = bfd_make_section (abfd, name);
1150 if (!section)
1151 return FALSE;
1153 section->filepos = 0;
1154 section->size = bfd_getl32 (egps->alloc);
1155 section->alignment_power = egps->align;
1157 vms_section_data (section)->flags = old_flags;
1158 vms_section_data (section)->no_flags = 0;
1160 new_flags = vms_secflag_by_name (evax_section_flags, name,
1161 section->size > 0);
1162 if (!(old_flags & EGPS__V_NOMOD) && section->size > 0)
1164 new_flags |= SEC_HAS_CONTENTS;
1165 if (old_flags & EGPS__V_REL)
1166 new_flags |= SEC_RELOC;
1168 if (!bfd_set_section_flags (abfd, section, new_flags))
1169 return FALSE;
1171 /* Give a non-overlapping vma to non absolute sections. */
1172 align_addr = (1 << section->alignment_power);
1173 if ((base_addr % align_addr) != 0)
1174 base_addr += (align_addr - (base_addr % align_addr));
1175 section->vma = (bfd_vma)base_addr;
1176 base_addr += section->size;
1179 /* Append it to the section array. */
1180 if (PRIV (section_count) >= PRIV (section_max))
1182 if (PRIV (section_max) == 0)
1183 PRIV (section_max) = 16;
1184 else
1185 PRIV (section_max) *= 2;
1186 PRIV (sections) = bfd_realloc_or_free
1187 (PRIV (sections), PRIV (section_max) * sizeof (asection *));
1188 if (PRIV (sections) == NULL)
1189 return FALSE;
1192 PRIV (sections)[PRIV (section_count)] = section;
1193 PRIV (section_count)++;
1195 break;
1197 case EGSD__C_SYM:
1199 int nameoff;
1200 struct vms_symbol_entry *entry;
1201 struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
1202 flagword old_flags;
1204 old_flags = bfd_getl16 (egsy->flags);
1205 if (old_flags & EGSY__V_DEF)
1206 nameoff = ESDF__B_NAMLNG;
1207 else
1208 nameoff = ESRF__B_NAMLNG;
1210 entry = add_symbol (abfd, vms_rec + nameoff);
1211 if (entry == NULL)
1212 return FALSE;
1214 /* Allow only duplicate reference. */
1215 if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
1216 abort ();
1218 if (entry->typ == 0)
1220 entry->typ = gsd_type;
1221 entry->data_type = egsy->datyp;
1222 entry->flags = old_flags;
1225 if (old_flags & EGSY__V_DEF)
1227 struct vms_esdf *esdf = (struct vms_esdf *)vms_rec;
1229 entry->value = bfd_getl64 (esdf->value);
1230 entry->section = PRIV (sections)[bfd_getl32 (esdf->psindx)];
1232 if (old_flags & EGSY__V_NORM)
1234 PRIV (norm_sym_count)++;
1236 entry->code_value = bfd_getl64 (esdf->code_address);
1237 entry->code_section =
1238 PRIV (sections)[bfd_getl32 (esdf->ca_psindx)];
1242 break;
1244 case EGSD__C_SYMG:
1246 struct vms_symbol_entry *entry;
1247 struct vms_egst *egst = (struct vms_egst *)vms_rec;
1248 flagword old_flags;
1250 old_flags = bfd_getl16 (egst->header.flags);
1252 entry = add_symbol (abfd, &egst->namlng);
1254 if (entry == NULL)
1255 return FALSE;
1257 entry->typ = gsd_type;
1258 entry->data_type = egst->header.datyp;
1259 entry->flags = old_flags;
1261 entry->symbol_vector = bfd_getl32 (egst->value);
1263 if (old_flags & EGSY__V_REL)
1264 entry->section = PRIV (sections)[bfd_getl32 (egst->psindx)];
1265 else
1266 entry->section = bfd_abs_section_ptr;
1268 entry->value = bfd_getl64 (egst->lp_2);
1270 if (old_flags & EGSY__V_NORM)
1272 PRIV (norm_sym_count)++;
1274 entry->code_value = bfd_getl64 (egst->lp_1);
1275 entry->code_section = bfd_abs_section_ptr;
1278 break;
1280 case EGSD__C_SPSC:
1281 case EGSD__C_IDC:
1282 /* Currently ignored. */
1283 break;
1284 case EGSD__C_SYMM:
1285 case EGSD__C_SYMV:
1286 default:
1287 (*_bfd_error_handler) (_("Unknown EGSD subtype %d"), gsd_type);
1288 bfd_set_error (bfd_error_bad_value);
1289 return FALSE;
1292 PRIV (recrd.rec_size) -= gsd_size;
1293 PRIV (recrd.rec) += gsd_size;
1296 if (PRIV (gsd_sym_count) > 0)
1297 abfd->flags |= HAS_SYMS;
1299 return TRUE;
1302 /* Stack routines for vms ETIR commands. */
1304 /* Push value and section index. */
1306 static void
1307 _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
1309 vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
1310 (unsigned long)val, reloc, PRIV (stackptr)));
1312 PRIV (stack[PRIV (stackptr)]).value = val;
1313 PRIV (stack[PRIV (stackptr)]).reloc = reloc;
1314 PRIV (stackptr)++;
1315 if (PRIV (stackptr) >= STACKSIZE)
1317 bfd_set_error (bfd_error_bad_value);
1318 (*_bfd_error_handler) (_("Stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
1319 exit (1);
1323 /* Pop value and section index. */
1325 static void
1326 _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
1328 if (PRIV (stackptr) == 0)
1330 bfd_set_error (bfd_error_bad_value);
1331 (*_bfd_error_handler) (_("Stack underflow in _bfd_vms_pop"));
1332 exit (1);
1334 PRIV (stackptr)--;
1335 *val = PRIV (stack[PRIV (stackptr)]).value;
1336 *rel = PRIV (stack[PRIV (stackptr)]).reloc;
1338 vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
1341 /* Routines to fill sections contents during tir/etir read. */
1343 /* Initialize image buffer pointer to be filled. */
1345 static void
1346 image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info)
1348 asection *sec;
1350 vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect));
1352 sec = PRIV (sections)[sect];
1354 if (info)
1356 /* Reading contents to an output bfd. */
1358 if (sec->output_section == NULL)
1360 /* Section discarded. */
1361 vms_debug2 ((5, " section %s discarded\n", sec->name));
1363 /* This is not used. */
1364 PRIV (image_section) = NULL;
1365 PRIV (image_offset) = 0;
1366 return;
1368 PRIV (image_offset) = sec->output_offset + vma;
1369 PRIV (image_section) = sec->output_section;
1371 else
1373 PRIV (image_offset) = vma;
1374 PRIV (image_section) = sec;
1378 /* Increment image buffer pointer by offset. */
1380 static void
1381 image_inc_ptr (bfd *abfd, bfd_vma offset)
1383 vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
1385 PRIV (image_offset) += offset;
1388 /* Save current DST location counter under specified index. */
1390 static void
1391 dst_define_location (bfd *abfd, unsigned int loc)
1393 vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
1395 /* Grow the ptr offset table if necessary. */
1396 if (loc + 1 > PRIV (dst_ptr_offsets_count))
1398 PRIV (dst_ptr_offsets) = bfd_realloc (PRIV (dst_ptr_offsets),
1399 (loc + 1) * sizeof (unsigned int));
1400 PRIV (dst_ptr_offsets_count) = loc + 1;
1403 PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
1406 /* Restore saved DST location counter from specified index. */
1408 static void
1409 dst_restore_location (bfd *abfd, unsigned int loc)
1411 vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
1413 PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
1416 /* Retrieve saved DST location counter from specified index. */
1418 static unsigned int
1419 dst_retrieve_location (bfd *abfd, unsigned int loc)
1421 vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int)loc));
1423 return PRIV (dst_ptr_offsets)[loc];
1426 /* Write multiple bytes to section image. */
1428 static bfd_boolean
1429 image_write (bfd *abfd, unsigned char *ptr, int size)
1431 #if VMS_DEBUG
1432 _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size,
1433 (long)PRIV (image_offset));
1434 _bfd_hexdump (9, ptr, size, 0);
1435 #endif
1437 if (PRIV (image_section)->contents != NULL)
1439 asection *sec = PRIV (image_section);
1440 file_ptr off = PRIV (image_offset);
1442 /* Check bounds. */
1443 if (off > (file_ptr)sec->size
1444 || size > (file_ptr)sec->size
1445 || off + size > (file_ptr)sec->size)
1447 bfd_set_error (bfd_error_bad_value);
1448 return FALSE;
1451 memcpy (sec->contents + off, ptr, size);
1454 PRIV (image_offset) += size;
1455 return TRUE;
1458 /* Write byte to section image. */
1460 static bfd_boolean
1461 image_write_b (bfd * abfd, unsigned int value)
1463 unsigned char data[1];
1465 vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
1467 *data = value;
1469 return image_write (abfd, data, sizeof (data));
1472 /* Write 2-byte word to image. */
1474 static bfd_boolean
1475 image_write_w (bfd * abfd, unsigned int value)
1477 unsigned char data[2];
1479 vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
1481 bfd_putl16 (value, data);
1482 return image_write (abfd, data, sizeof (data));
1485 /* Write 4-byte long to image. */
1487 static bfd_boolean
1488 image_write_l (bfd * abfd, unsigned long value)
1490 unsigned char data[4];
1492 vms_debug2 ((6, "image_write_l (%08lx)\n", value));
1494 bfd_putl32 (value, data);
1495 return image_write (abfd, data, sizeof (data));
1498 /* Write 8-byte quad to image. */
1500 static bfd_boolean
1501 image_write_q (bfd * abfd, bfd_vma value)
1503 unsigned char data[8];
1505 vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
1507 bfd_putl64 (value, data);
1508 return image_write (abfd, data, sizeof (data));
1511 static const char *
1512 _bfd_vms_etir_name (int cmd)
1514 switch (cmd)
1516 case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL";
1517 case ETIR__C_STA_LW: return "ETIR__C_STA_LW";
1518 case ETIR__C_STA_QW: return "ETIR__C_STA_QW";
1519 case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ";
1520 case ETIR__C_STA_LI: return "ETIR__C_STA_LI";
1521 case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD";
1522 case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG";
1523 case ETIR__C_STO_B: return "ETIR__C_STO_B";
1524 case ETIR__C_STO_W: return "ETIR__C_STO_W";
1525 case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL";
1526 case ETIR__C_STO_CA: return "ETIR__C_STO_CA";
1527 case ETIR__C_STO_RB: return "ETIR__C_STO_RB";
1528 case ETIR__C_STO_AB: return "ETIR__C_STO_AB";
1529 case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF";
1530 case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM";
1531 case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR";
1532 case ETIR__C_STO_LW: return "ETIR__C_STO_LW";
1533 case ETIR__C_STO_QW: return "ETIR__C_STO_QW";
1534 case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW";
1535 case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB";
1536 case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL";
1537 case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS";
1538 case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD";
1539 case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB";
1540 case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV";
1541 case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH";
1542 case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT";
1543 case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF";
1544 case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT";
1545 case ETIR__C_STC_LP: return "ETIR__C_STC_LP";
1546 case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL";
1547 case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA";
1548 case ETIR__C_STC_PS: return "ETIR__C_STC_PS";
1549 case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS";
1550 case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL";
1551 case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS";
1552 case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL";
1553 case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS";
1554 case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL";
1555 case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS";
1556 case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL";
1557 case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS";
1558 case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL";
1559 case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB";
1560 case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB";
1561 case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB";
1562 case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC";
1563 case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC";
1564 case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL";
1566 default:
1567 /* These names have not yet been added to this switch statement. */
1568 (*_bfd_error_handler) (_("unknown ETIR command %d"), cmd);
1571 return NULL;
1573 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
1575 static void
1576 _bfd_vms_get_value (bfd *abfd, const unsigned char *ascic,
1577 struct bfd_link_info *info,
1578 bfd_vma *vma,
1579 struct alpha_vms_link_hash_entry **hp)
1581 char name[257];
1582 int len;
1583 int i;
1584 struct alpha_vms_link_hash_entry *h;
1586 /* Not linking. Do not try to resolve the symbol. */
1587 if (info == NULL)
1589 *vma = 0;
1590 *hp = NULL;
1591 return;
1594 len = *ascic;
1595 for (i = 0; i < len; i++)
1596 name[i] = ascic[i + 1];
1597 name[i] = 0;
1599 h = (struct alpha_vms_link_hash_entry *)
1600 bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
1602 *hp = h;
1604 if (h != NULL
1605 && (h->root.type == bfd_link_hash_defined
1606 || h->root.type == bfd_link_hash_defweak))
1607 *vma = h->root.u.def.value
1608 + h->root.u.def.section->output_offset
1609 + h->root.u.def.section->output_section->vma;
1610 else if (h && h->root.type == bfd_link_hash_undefweak)
1611 *vma = 0;
1612 else
1614 if (!(*info->callbacks->undefined_symbol)
1615 (info, name, abfd, PRIV (image_section), PRIV (image_offset), TRUE))
1616 abort ();
1617 *vma = 0;
1621 #define RELC_NONE 0
1622 #define RELC_REL 1
1623 #define RELC_SHR_BASE 0x10000
1624 #define RELC_SEC_BASE 0x20000
1625 #define RELC_MASK 0x0ffff
1627 static unsigned int
1628 alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h)
1630 /* Handle undefined symbols. */
1631 if (h == NULL || h->sym == NULL)
1632 return RELC_NONE;
1634 if (h->sym->typ == EGSD__C_SYMG)
1636 if (h->sym->flags & EGSY__V_REL)
1637 return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index);
1638 else
1640 /* Can this happen (non-relocatable symg) ? I'd like to see
1641 an example. */
1642 abort ();
1645 if (h->sym->typ == EGSD__C_SYM)
1647 if (h->sym->flags & EGSY__V_REL)
1648 return RELC_REL;
1649 else
1650 return RELC_NONE;
1652 abort ();
1655 static bfd_vma
1656 alpha_vms_get_sym_value (asection *sect, bfd_vma addr)
1658 return sect->output_section->vma + sect->output_offset + addr;
1661 static bfd_vma
1662 alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info,
1663 unsigned int rel, bfd_vma vma)
1665 asection *sec = PRIV (sections)[rel & RELC_MASK];
1667 if (info)
1669 if (sec->output_section == NULL)
1670 abort ();
1671 return vma + sec->output_section->vma + sec->output_offset;
1673 else
1674 return vma + sec->vma;
1677 /* Read an ETIR record from ABFD. If INFO is not null, put the content into
1678 the output section (used during linking).
1679 Return FALSE in case of error. */
1681 static bfd_boolean
1682 _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
1684 unsigned char *ptr;
1685 unsigned int length;
1686 unsigned char *maxptr;
1687 bfd_vma op1;
1688 bfd_vma op2;
1689 unsigned int rel1;
1690 unsigned int rel2;
1691 struct alpha_vms_link_hash_entry *h;
1693 PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
1694 PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
1696 ptr = PRIV (recrd.rec);
1697 length = PRIV (recrd.rec_size);
1698 maxptr = ptr + length;
1700 vms_debug2 ((2, "ETIR: %d bytes\n", length));
1702 while (ptr < maxptr)
1704 int cmd = bfd_getl16 (ptr);
1705 int cmd_length = bfd_getl16 (ptr + 2);
1707 ptr += 4;
1709 #if VMS_DEBUG
1710 _bfd_vms_debug (4, "etir: %s(%d)\n",
1711 _bfd_vms_etir_name (cmd), cmd);
1712 _bfd_hexdump (8, ptr, cmd_length - 4, (long) ptr);
1713 #endif
1715 switch (cmd)
1717 /* Stack global
1718 arg: cs symbol name
1720 stack 32 bit value of symbol (high bits set to 0). */
1721 case ETIR__C_STA_GBL:
1722 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1723 _bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h));
1724 break;
1726 /* Stack longword
1727 arg: lw value
1729 stack 32 bit value, sign extend to 64 bit. */
1730 case ETIR__C_STA_LW:
1731 _bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE);
1732 break;
1734 /* Stack quadword
1735 arg: qw value
1737 stack 64 bit value of symbol. */
1738 case ETIR__C_STA_QW:
1739 _bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE);
1740 break;
1742 /* Stack psect base plus quadword offset
1743 arg: lw section index
1744 qw signed quadword offset (low 32 bits)
1746 Stack qw argument and section index
1747 (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */
1748 case ETIR__C_STA_PQ:
1750 int psect;
1752 psect = bfd_getl32 (ptr);
1753 if ((unsigned int) psect >= PRIV (section_count))
1755 (*_bfd_error_handler) (_("bad section index in %s"),
1756 _bfd_vms_etir_name (cmd));
1757 bfd_set_error (bfd_error_bad_value);
1758 return FALSE;
1760 op1 = bfd_getl64 (ptr + 4);
1761 _bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE);
1763 break;
1765 case ETIR__C_STA_LI:
1766 case ETIR__C_STA_MOD:
1767 case ETIR__C_STA_CKARG:
1768 (*_bfd_error_handler) (_("unsupported STA cmd %s"),
1769 _bfd_vms_etir_name (cmd));
1770 return FALSE;
1771 break;
1773 /* Store byte: pop stack, write byte
1774 arg: -. */
1775 case ETIR__C_STO_B:
1776 _bfd_vms_pop (abfd, &op1, &rel1);
1777 if (rel1 != RELC_NONE)
1778 goto bad_context;
1779 image_write_b (abfd, (unsigned int) op1 & 0xff);
1780 break;
1782 /* Store word: pop stack, write word
1783 arg: -. */
1784 case ETIR__C_STO_W:
1785 _bfd_vms_pop (abfd, &op1, &rel1);
1786 if (rel1 != RELC_NONE)
1787 goto bad_context;
1788 image_write_w (abfd, (unsigned int) op1 & 0xffff);
1789 break;
1791 /* Store longword: pop stack, write longword
1792 arg: -. */
1793 case ETIR__C_STO_LW:
1794 _bfd_vms_pop (abfd, &op1, &rel1);
1795 if (rel1 & RELC_SEC_BASE)
1797 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1798 rel1 = RELC_REL;
1800 else if (rel1 & RELC_SHR_BASE)
1802 alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1);
1803 rel1 = RELC_NONE;
1805 if (rel1 != RELC_NONE)
1807 if (rel1 != RELC_REL)
1808 abort ();
1809 alpha_vms_add_lw_reloc (info);
1811 image_write_l (abfd, op1);
1812 break;
1814 /* Store quadword: pop stack, write quadword
1815 arg: -. */
1816 case ETIR__C_STO_QW:
1817 _bfd_vms_pop (abfd, &op1, &rel1);
1818 if (rel1 & RELC_SEC_BASE)
1820 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1821 rel1 = RELC_REL;
1823 else if (rel1 & RELC_SHR_BASE)
1824 abort ();
1825 if (rel1 != RELC_NONE)
1827 if (rel1 != RELC_REL)
1828 abort ();
1829 alpha_vms_add_qw_reloc (info);
1831 image_write_q (abfd, op1);
1832 break;
1834 /* Store immediate repeated: pop stack for repeat count
1835 arg: lw byte count
1836 da data. */
1837 case ETIR__C_STO_IMMR:
1839 int size;
1841 size = bfd_getl32 (ptr);
1842 _bfd_vms_pop (abfd, &op1, &rel1);
1843 if (rel1 != RELC_NONE)
1844 goto bad_context;
1845 while (op1-- > 0)
1846 image_write (abfd, ptr + 4, size);
1848 break;
1850 /* Store global: write symbol value
1851 arg: cs global symbol name. */
1852 case ETIR__C_STO_GBL:
1853 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1854 if (h && h->sym)
1856 if (h->sym->typ == EGSD__C_SYMG)
1858 alpha_vms_add_fixup_qr
1859 (info, abfd, h->sym->owner, h->sym->symbol_vector);
1860 op1 = 0;
1862 else
1864 op1 = alpha_vms_get_sym_value (h->sym->section,
1865 h->sym->value);
1866 alpha_vms_add_qw_reloc (info);
1869 image_write_q (abfd, op1);
1870 break;
1872 /* Store code address: write address of entry point
1873 arg: cs global symbol name (procedure). */
1874 case ETIR__C_STO_CA:
1875 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1876 if (h && h->sym)
1878 if (h->sym->flags & EGSY__V_NORM)
1880 /* That's really a procedure. */
1881 if (h->sym->typ == EGSD__C_SYMG)
1883 alpha_vms_add_fixup_ca (info, abfd, h->sym->owner);
1884 op1 = h->sym->symbol_vector;
1886 else
1888 op1 = alpha_vms_get_sym_value (h->sym->code_section,
1889 h->sym->code_value);
1890 alpha_vms_add_qw_reloc (info);
1893 else
1895 /* Symbol is not a procedure. */
1896 abort ();
1899 image_write_q (abfd, op1);
1900 break;
1902 /* Store offset to psect: pop stack, add low 32 bits to base of psect
1903 arg: none. */
1904 case ETIR__C_STO_OFF:
1905 _bfd_vms_pop (abfd, &op1, &rel1);
1907 if (!(rel1 & RELC_SEC_BASE))
1908 abort ();
1910 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1911 rel1 = RELC_REL;
1912 image_write_q (abfd, op1);
1913 break;
1915 /* Store immediate
1916 arg: lw count of bytes
1917 da data. */
1918 case ETIR__C_STO_IMM:
1920 int size;
1922 size = bfd_getl32 (ptr);
1923 image_write (abfd, ptr + 4, size);
1925 break;
1927 /* This code is 'reserved to digital' according to the openVMS
1928 linker manual, however it is generated by the DEC C compiler
1929 and defined in the include file.
1930 FIXME, since the following is just a guess
1931 store global longword: store 32bit value of symbol
1932 arg: cs symbol name. */
1933 case ETIR__C_STO_GBL_LW:
1934 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1935 #if 0
1936 abort ();
1937 #endif
1938 image_write_l (abfd, op1);
1939 break;
1941 case ETIR__C_STO_RB:
1942 case ETIR__C_STO_AB:
1943 case ETIR__C_STO_LP_PSB:
1944 (*_bfd_error_handler) (_("%s: not supported"),
1945 _bfd_vms_etir_name (cmd));
1946 return FALSE;
1947 break;
1948 case ETIR__C_STO_HINT_GBL:
1949 case ETIR__C_STO_HINT_PS:
1950 (*_bfd_error_handler) (_("%s: not implemented"),
1951 _bfd_vms_etir_name (cmd));
1952 return FALSE;
1953 break;
1955 /* 200 Store-conditional Linkage Pair
1956 arg: none. */
1957 case ETIR__C_STC_LP:
1959 /* 202 Store-conditional Address at global address
1960 lw linkage index
1961 cs global name. */
1963 case ETIR__C_STC_GBL:
1965 /* 203 Store-conditional Code Address at global address
1966 lw linkage index
1967 cs procedure name. */
1968 case ETIR__C_STC_GCA:
1970 /* 204 Store-conditional Address at psect + offset
1971 lw linkage index
1972 lw psect index
1973 qw offset. */
1974 case ETIR__C_STC_PS:
1975 (*_bfd_error_handler) (_("%s: not supported"),
1976 _bfd_vms_etir_name (cmd));
1977 return FALSE;
1978 break;
1980 /* 201 Store-conditional Linkage Pair with Procedure Signature
1981 lw linkage index
1982 cs procedure name
1983 by signature length
1984 da signature. */
1986 case ETIR__C_STC_LP_PSB:
1987 _bfd_vms_get_value (abfd, ptr + 4, info, &op1, &h);
1988 if (h && h->sym)
1990 if (h->sym->typ == EGSD__C_SYMG)
1992 alpha_vms_add_fixup_lp (info, abfd, h->sym->owner);
1993 op1 = h->sym->symbol_vector;
1994 op2 = 0;
1996 else
1998 op1 = alpha_vms_get_sym_value (h->sym->code_section,
1999 h->sym->code_value);
2000 op2 = alpha_vms_get_sym_value (h->sym->section,
2001 h->sym->value);
2004 else
2006 /* Undefined symbol. */
2007 op1 = 0;
2008 op2 = 0;
2010 image_write_q (abfd, op1);
2011 image_write_q (abfd, op2);
2012 break;
2014 /* 205 Store-conditional NOP at address of global
2015 arg: none. */
2016 case ETIR__C_STC_NOP_GBL:
2017 /* ALPHA_R_NOP */
2019 /* 207 Store-conditional BSR at global address
2020 arg: none. */
2022 case ETIR__C_STC_BSR_GBL:
2023 /* ALPHA_R_BSR */
2025 /* 209 Store-conditional LDA at global address
2026 arg: none. */
2028 case ETIR__C_STC_LDA_GBL:
2029 /* ALPHA_R_LDA */
2031 /* 211 Store-conditional BSR or Hint at global address
2032 arg: none. */
2034 case ETIR__C_STC_BOH_GBL:
2035 /* Currentl ignored. */
2036 break;
2038 /* 213 Store-conditional NOP,BSR or HINT at global address
2039 arg: none. */
2041 case ETIR__C_STC_NBH_GBL:
2043 /* 206 Store-conditional NOP at pect + offset
2044 arg: none. */
2046 case ETIR__C_STC_NOP_PS:
2048 /* 208 Store-conditional BSR at pect + offset
2049 arg: none. */
2051 case ETIR__C_STC_BSR_PS:
2053 /* 210 Store-conditional LDA at psect + offset
2054 arg: none. */
2056 case ETIR__C_STC_LDA_PS:
2058 /* 212 Store-conditional BSR or Hint at pect + offset
2059 arg: none. */
2061 case ETIR__C_STC_BOH_PS:
2063 /* 214 Store-conditional NOP, BSR or HINT at psect + offset
2064 arg: none. */
2065 case ETIR__C_STC_NBH_PS:
2066 (*_bfd_error_handler) ("%s: not supported",
2067 _bfd_vms_etir_name (cmd));
2068 return FALSE;
2069 break;
2071 /* Det relocation base: pop stack, set image location counter
2072 arg: none. */
2073 case ETIR__C_CTL_SETRB:
2074 _bfd_vms_pop (abfd, &op1, &rel1);
2075 if (!(rel1 & RELC_SEC_BASE))
2076 abort ();
2077 image_set_ptr (abfd, op1, rel1 & RELC_MASK, info);
2078 break;
2080 /* Augment relocation base: increment image location counter by offset
2081 arg: lw offset value. */
2082 case ETIR__C_CTL_AUGRB:
2083 op1 = bfd_getl32 (ptr);
2084 image_inc_ptr (abfd, op1);
2085 break;
2087 /* Define location: pop index, save location counter under index
2088 arg: none. */
2089 case ETIR__C_CTL_DFLOC:
2090 _bfd_vms_pop (abfd, &op1, &rel1);
2091 if (rel1 != RELC_NONE)
2092 goto bad_context;
2093 dst_define_location (abfd, op1);
2094 break;
2096 /* Set location: pop index, restore location counter from index
2097 arg: none. */
2098 case ETIR__C_CTL_STLOC:
2099 _bfd_vms_pop (abfd, &op1, &rel1);
2100 if (rel1 != RELC_NONE)
2101 goto bad_context;
2102 dst_restore_location (abfd, op1);
2103 break;
2105 /* Stack defined location: pop index, push location counter from index
2106 arg: none. */
2107 case ETIR__C_CTL_STKDL:
2108 _bfd_vms_pop (abfd, &op1, &rel1);
2109 if (rel1 != RELC_NONE)
2110 goto bad_context;
2111 _bfd_vms_push (abfd, dst_retrieve_location (abfd, op1), RELC_NONE);
2112 break;
2114 case ETIR__C_OPR_NOP: /* No-op. */
2115 break;
2117 case ETIR__C_OPR_ADD: /* Add. */
2118 _bfd_vms_pop (abfd, &op1, &rel1);
2119 _bfd_vms_pop (abfd, &op2, &rel2);
2120 if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2121 rel1 = rel2;
2122 else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2123 goto bad_context;
2124 _bfd_vms_push (abfd, op1 + op2, rel1);
2125 break;
2127 case ETIR__C_OPR_SUB: /* Subtract. */
2128 _bfd_vms_pop (abfd, &op1, &rel1);
2129 _bfd_vms_pop (abfd, &op2, &rel2);
2130 if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2131 rel1 = rel2;
2132 else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE))
2134 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
2135 op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2);
2136 rel1 = RELC_NONE;
2138 else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2139 goto bad_context;
2140 _bfd_vms_push (abfd, op2 - op1, rel1);
2141 break;
2143 case ETIR__C_OPR_MUL: /* Multiply. */
2144 _bfd_vms_pop (abfd, &op1, &rel1);
2145 _bfd_vms_pop (abfd, &op2, &rel2);
2146 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2147 goto bad_context;
2148 _bfd_vms_push (abfd, op1 * op2, RELC_NONE);
2149 break;
2151 case ETIR__C_OPR_DIV: /* Divide. */
2152 _bfd_vms_pop (abfd, &op1, &rel1);
2153 _bfd_vms_pop (abfd, &op2, &rel2);
2154 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2155 goto bad_context;
2156 if (op2 == 0)
2157 _bfd_vms_push (abfd, 0, RELC_NONE);
2158 else
2159 _bfd_vms_push (abfd, op2 / op1, RELC_NONE);
2160 break;
2162 case ETIR__C_OPR_AND: /* Logical AND. */
2163 _bfd_vms_pop (abfd, &op1, &rel1);
2164 _bfd_vms_pop (abfd, &op2, &rel2);
2165 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2166 goto bad_context;
2167 _bfd_vms_push (abfd, op1 & op2, RELC_NONE);
2168 break;
2170 case ETIR__C_OPR_IOR: /* Logical inclusive OR. */
2171 _bfd_vms_pop (abfd, &op1, &rel1);
2172 _bfd_vms_pop (abfd, &op2, &rel2);
2173 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2174 goto bad_context;
2175 _bfd_vms_push (abfd, op1 | op2, RELC_NONE);
2176 break;
2178 case ETIR__C_OPR_EOR: /* Logical exclusive OR. */
2179 _bfd_vms_pop (abfd, &op1, &rel1);
2180 _bfd_vms_pop (abfd, &op2, &rel2);
2181 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2182 goto bad_context;
2183 _bfd_vms_push (abfd, op1 ^ op2, RELC_NONE);
2184 break;
2186 case ETIR__C_OPR_NEG: /* Negate. */
2187 _bfd_vms_pop (abfd, &op1, &rel1);
2188 if (rel1 != RELC_NONE)
2189 goto bad_context;
2190 _bfd_vms_push (abfd, -op1, RELC_NONE);
2191 break;
2193 case ETIR__C_OPR_COM: /* Complement. */
2194 _bfd_vms_pop (abfd, &op1, &rel1);
2195 if (rel1 != RELC_NONE)
2196 goto bad_context;
2197 _bfd_vms_push (abfd, ~op1, RELC_NONE);
2198 break;
2200 case ETIR__C_OPR_ASH: /* Arithmetic shift. */
2201 _bfd_vms_pop (abfd, &op1, &rel1);
2202 _bfd_vms_pop (abfd, &op2, &rel2);
2203 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2205 bad_context:
2206 (*_bfd_error_handler) (_("invalid use of %s with contexts"),
2207 _bfd_vms_etir_name (cmd));
2208 return FALSE;
2210 if ((int)op2 < 0) /* Shift right. */
2211 op1 >>= -(int)op2;
2212 else /* Shift left. */
2213 op1 <<= (int)op2;
2214 _bfd_vms_push (abfd, op1, RELC_NONE); /* FIXME: sym. */
2215 break;
2217 case ETIR__C_OPR_INSV: /* Insert field. */
2218 case ETIR__C_OPR_USH: /* Unsigned shift. */
2219 case ETIR__C_OPR_ROT: /* Rotate. */
2220 case ETIR__C_OPR_REDEF: /* Redefine symbol to current location. */
2221 case ETIR__C_OPR_DFLIT: /* Define a literal. */
2222 (*_bfd_error_handler) (_("%s: not supported"),
2223 _bfd_vms_etir_name (cmd));
2224 return FALSE;
2225 break;
2227 case ETIR__C_OPR_SEL: /* Select. */
2228 _bfd_vms_pop (abfd, &op1, &rel1);
2229 if (op1 & 0x01L)
2230 _bfd_vms_pop (abfd, &op1, &rel1);
2231 else
2233 _bfd_vms_pop (abfd, &op1, &rel1);
2234 _bfd_vms_pop (abfd, &op2, &rel2);
2235 _bfd_vms_push (abfd, op1, rel1);
2237 break;
2239 default:
2240 (*_bfd_error_handler) (_("reserved cmd %d"), cmd);
2241 return FALSE;
2242 break;
2245 ptr += cmd_length - 4;
2248 return TRUE;
2251 /* Process EDBG/ETBT record.
2252 Return TRUE on success, FALSE on error */
2254 static bfd_boolean
2255 vms_slurp_debug (bfd *abfd)
2257 asection *section = PRIV (dst_section);
2259 if (section == NULL)
2261 /* We have no way to find out beforehand how much debug info there
2262 is in an object file, so pick an initial amount and grow it as
2263 needed later. */
2264 flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC
2265 | SEC_IN_MEMORY;
2267 section = bfd_make_section (abfd, "$DST$");
2268 if (!section)
2269 return FALSE;
2270 if (!bfd_set_section_flags (abfd, section, flags))
2271 return FALSE;
2272 PRIV (dst_section) = section;
2275 PRIV (image_section) = section;
2276 PRIV (image_offset) = section->size;
2278 if (!_bfd_vms_slurp_etir (abfd, NULL))
2279 return FALSE;
2281 section->size = PRIV (image_offset);
2282 return TRUE;
2285 /* Process EDBG record.
2286 Return TRUE on success, FALSE on error. */
2288 static bfd_boolean
2289 _bfd_vms_slurp_edbg (bfd *abfd)
2291 vms_debug2 ((2, "EDBG\n"));
2293 abfd->flags |= HAS_DEBUG | HAS_LINENO;
2295 return vms_slurp_debug (abfd);
2298 /* Process ETBT record.
2299 Return TRUE on success, FALSE on error. */
2301 static bfd_boolean
2302 _bfd_vms_slurp_etbt (bfd *abfd)
2304 vms_debug2 ((2, "ETBT\n"));
2306 abfd->flags |= HAS_LINENO;
2308 return vms_slurp_debug (abfd);
2311 /* Process EEOM record.
2312 Return TRUE on success, FALSE on error. */
2314 static bfd_boolean
2315 _bfd_vms_slurp_eeom (bfd *abfd)
2317 struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
2319 vms_debug2 ((2, "EEOM\n"));
2321 PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
2322 PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
2323 if (PRIV (eom_data).eom_w_comcod > 1)
2325 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
2326 bfd_set_error (bfd_error_bad_value);
2327 return FALSE;
2330 PRIV (eom_data).eom_has_transfer = FALSE;
2331 if (PRIV (recrd.rec_size) > 10)
2333 PRIV (eom_data).eom_has_transfer = TRUE;
2334 PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
2335 PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
2336 PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
2338 abfd->start_address = PRIV (eom_data).eom_l_tfradr;
2340 return TRUE;
2343 /* Slurp an ordered set of VMS object records. Return FALSE on error. */
2345 static bfd_boolean
2346 _bfd_vms_slurp_object_records (bfd * abfd)
2348 bfd_boolean err;
2349 int type;
2353 vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
2355 type = _bfd_vms_get_object_record (abfd);
2356 if (type < 0)
2358 vms_debug2 ((2, "next_record failed\n"));
2359 return FALSE;
2362 switch (type)
2364 case EOBJ__C_EMH:
2365 err = _bfd_vms_slurp_ehdr (abfd);
2366 break;
2367 case EOBJ__C_EEOM:
2368 err = _bfd_vms_slurp_eeom (abfd);
2369 break;
2370 case EOBJ__C_EGSD:
2371 err = _bfd_vms_slurp_egsd (abfd);
2372 break;
2373 case EOBJ__C_ETIR:
2374 err = TRUE; /* _bfd_vms_slurp_etir (abfd); */
2375 break;
2376 case EOBJ__C_EDBG:
2377 err = _bfd_vms_slurp_edbg (abfd);
2378 break;
2379 case EOBJ__C_ETBT:
2380 err = _bfd_vms_slurp_etbt (abfd);
2381 break;
2382 default:
2383 err = FALSE;
2385 if (err != TRUE)
2387 vms_debug2 ((2, "slurp type %d failed\n", type));
2388 return FALSE;
2391 while (type != EOBJ__C_EEOM);
2393 return TRUE;
2396 /* Initialize private data */
2397 static bfd_boolean
2398 vms_initialize (bfd * abfd)
2400 bfd_size_type amt;
2402 amt = sizeof (struct vms_private_data_struct);
2403 abfd->tdata.any = bfd_zalloc (abfd, amt);
2404 if (abfd->tdata.any == NULL)
2405 return FALSE;
2407 PRIV (recrd.file_format) = FF_UNKNOWN;
2409 amt = sizeof (struct stack_struct) * STACKSIZE;
2410 PRIV (stack) = bfd_alloc (abfd, amt);
2411 if (PRIV (stack) == NULL)
2412 goto error_ret1;
2414 return TRUE;
2416 error_ret1:
2417 bfd_release (abfd, abfd->tdata.any);
2418 abfd->tdata.any = NULL;
2419 return FALSE;
2422 /* Check the format for a file being read.
2423 Return a (bfd_target *) if it's an object file or zero if not. */
2425 static const struct bfd_target *
2426 alpha_vms_object_p (bfd *abfd)
2428 PTR tdata_save = abfd->tdata.any;
2429 unsigned int test_len;
2430 unsigned char *buf;
2432 vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
2434 /* Allocate alpha-vms specific data. */
2435 if (!vms_initialize (abfd))
2436 goto error_ret;
2438 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
2439 goto err_wrong_format;
2441 /* The first challenge with VMS is to discover the kind of the file.
2443 Image files (executable or shared images) are stored as a raw
2444 stream of bytes (like on UNIX), but there is no magic number.
2446 Object files are written with RMS (record management service), ie
2447 each records are preceeded by its length (on a word - 2 bytes), and
2448 padded for word-alignment. That would be simple but when files
2449 are transfered to a UNIX filesystem (using ftp), records are lost.
2450 Only the raw content of the records are transfered. Fortunately,
2451 the Alpha Object file format also store the length of the record
2452 in the records. Is that clear ? */
2454 /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id,
2455 2 bytes size repeated) and 12 bytes for images (4 bytes major id,
2456 4 bytes minor id, 4 bytes length). */
2457 test_len = 12;
2459 /* Size the main buffer. */
2460 buf = (unsigned char *) bfd_malloc (test_len);
2461 if (buf == NULL)
2462 goto error_ret;
2463 PRIV (recrd.buf) = buf;
2464 PRIV (recrd.buf_size) = test_len;
2466 /* Initialize the record pointer. */
2467 PRIV (recrd.rec) = buf;
2469 if (bfd_bread (buf, test_len, abfd) != test_len)
2471 bfd_set_error (bfd_error_file_truncated);
2472 goto error_ret;
2475 /* Is it an image? */
2476 if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
2477 && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
2479 unsigned int to_read;
2480 unsigned int read_so_far;
2481 unsigned int remaining;
2482 unsigned int eisd_offset, eihs_offset;
2484 /* Extract the header size. */
2485 PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
2487 /* The header size is 0 for DSF files. */
2488 if (PRIV (recrd.rec_size) == 0)
2489 PRIV (recrd.rec_size) = sizeof (struct vms_eihd);
2491 if (PRIV (recrd.rec_size) > PRIV (recrd.buf_size))
2493 buf = bfd_realloc_or_free (buf, PRIV (recrd.rec_size));
2495 if (buf == NULL)
2497 PRIV (recrd.buf) = NULL;
2498 bfd_set_error (bfd_error_no_memory);
2499 goto error_ret;
2501 PRIV (recrd.buf) = buf;
2502 PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
2505 /* Read the remaining record. */
2506 remaining = PRIV (recrd.rec_size) - test_len;
2507 to_read = MIN (VMS_BLOCK_SIZE - test_len, remaining);
2508 read_so_far = test_len;
2510 while (remaining > 0)
2512 if (bfd_bread (buf + read_so_far, to_read, abfd) != to_read)
2514 bfd_set_error (bfd_error_file_truncated);
2515 goto err_wrong_format;
2518 read_so_far += to_read;
2519 remaining -= to_read;
2521 to_read = MIN (VMS_BLOCK_SIZE, remaining);
2524 /* Reset the record pointer. */
2525 PRIV (recrd.rec) = buf;
2527 vms_debug2 ((2, "file type is image\n"));
2529 if (_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset) != TRUE)
2530 goto err_wrong_format;
2532 if (_bfd_vms_slurp_eisd (abfd, eisd_offset) != TRUE)
2533 goto err_wrong_format;
2535 /* EIHS is optional. */
2536 if (eihs_offset != 0 && _bfd_vms_slurp_eihs (abfd, eihs_offset) != TRUE)
2537 goto err_wrong_format;
2539 else
2541 int type;
2543 /* Assume it's a module and adjust record pointer if necessary. */
2544 maybe_adjust_record_pointer_for_object (abfd);
2546 /* But is it really a module? */
2547 if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
2548 && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
2550 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
2551 goto err_wrong_format;
2553 vms_debug2 ((2, "file type is module\n"));
2555 type = bfd_getl16 (PRIV (recrd.rec));
2556 if (type != EOBJ__C_EMH || _bfd_vms_slurp_ehdr (abfd) != TRUE)
2557 goto err_wrong_format;
2559 if (_bfd_vms_slurp_object_records (abfd) != TRUE)
2560 goto err_wrong_format;
2562 else
2563 goto err_wrong_format;
2566 /* Set arch_info to alpha. */
2568 if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
2569 goto err_wrong_format;
2571 return abfd->xvec;
2573 err_wrong_format:
2574 bfd_set_error (bfd_error_wrong_format);
2576 error_ret:
2577 if (PRIV (recrd.buf))
2578 free (PRIV (recrd.buf));
2579 if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
2580 bfd_release (abfd, abfd->tdata.any);
2581 abfd->tdata.any = tdata_save;
2582 return NULL;
2585 /* Image write. */
2587 /* Write an EMH/MHD record. */
2589 static void
2590 _bfd_vms_write_emh (bfd *abfd)
2592 struct vms_rec_wr *recwr = &PRIV (recwr);
2594 _bfd_vms_output_alignment (recwr, 2);
2596 /* EMH. */
2597 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2598 _bfd_vms_output_short (recwr, EMH__C_MHD);
2599 _bfd_vms_output_short (recwr, EOBJ__C_STRLVL);
2600 _bfd_vms_output_long (recwr, 0);
2601 _bfd_vms_output_long (recwr, 0);
2602 _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE);
2604 /* Create module name from filename. */
2605 if (bfd_get_filename (abfd) != 0)
2607 char *module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
2608 _bfd_vms_output_counted (recwr, module);
2609 free (module);
2611 else
2612 _bfd_vms_output_counted (recwr, "NONAME");
2614 _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
2615 _bfd_vms_output_dump (recwr, get_vms_time_string (), EMH_DATE_LENGTH);
2616 _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
2617 _bfd_vms_output_end (abfd, recwr);
2620 /* Write an EMH/LMN record. */
2622 static void
2623 _bfd_vms_write_lmn (bfd *abfd, const char *name)
2625 char version [64];
2626 struct vms_rec_wr *recwr = &PRIV (recwr);
2627 unsigned int ver = BFD_VERSION / 10000;
2629 /* LMN. */
2630 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
2631 _bfd_vms_output_short (recwr, EMH__C_LNM);
2632 snprintf (version, sizeof (version), "%s %d.%d.%d", name,
2633 ver / 10000, (ver / 100) % 100, ver % 100);
2634 _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
2635 _bfd_vms_output_end (abfd, recwr);
2639 /* Write eom record for bfd abfd. Return FALSE on error. */
2641 static bfd_boolean
2642 _bfd_vms_write_eeom (bfd *abfd)
2644 struct vms_rec_wr *recwr = &PRIV (recwr);
2646 vms_debug2 ((2, "vms_write_eeom\n"));
2648 _bfd_vms_output_alignment (recwr, 2);
2650 _bfd_vms_output_begin (recwr, EOBJ__C_EEOM);
2651 _bfd_vms_output_long (recwr, (unsigned long) (PRIV (vms_linkage_index) >> 1));
2652 _bfd_vms_output_byte (recwr, 0); /* Completion code. */
2653 _bfd_vms_output_byte (recwr, 0); /* Fill byte. */
2655 if ((abfd->flags & EXEC_P) == 0
2656 && bfd_get_start_address (abfd) != (bfd_vma)-1)
2658 asection *section;
2660 section = bfd_get_section_by_name (abfd, ".link");
2661 if (section == 0)
2663 bfd_set_error (bfd_error_nonrepresentable_section);
2664 return FALSE;
2666 _bfd_vms_output_short (recwr, 0);
2667 _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
2668 _bfd_vms_output_long (recwr,
2669 (unsigned long) bfd_get_start_address (abfd));
2670 _bfd_vms_output_long (recwr, 0);
2673 _bfd_vms_output_end (abfd, recwr);
2674 return TRUE;
2677 /* This hash routine borrowed from GNU-EMACS, and strengthened
2678 slightly. ERY. */
2680 static int
2681 hash_string (const char *ptr)
2683 const unsigned char *p = (unsigned char *) ptr;
2684 const unsigned char *end = p + strlen (ptr);
2685 unsigned char c;
2686 int hash = 0;
2688 while (p != end)
2690 c = *p++;
2691 hash = ((hash << 3) + (hash << 15) + (hash >> 28) + c);
2693 return hash;
2696 /* Generate a length-hashed VMS symbol name (limited to maxlen chars). */
2698 static char *
2699 _bfd_vms_length_hash_symbol (bfd *abfd, const char *in, int maxlen)
2701 unsigned long result;
2702 int in_len;
2703 char *new_name;
2704 const char *old_name;
2705 int i;
2706 static char outbuf[EOBJ__C_SYMSIZ + 1];
2707 char *out = outbuf;
2709 #if VMS_DEBUG
2710 vms_debug (4, "_bfd_vms_length_hash_symbol \"%s\"\n", in);
2711 #endif
2713 if (maxlen > EOBJ__C_SYMSIZ)
2714 maxlen = EOBJ__C_SYMSIZ;
2716 /* Save this for later. */
2717 new_name = out;
2719 /* We may need to truncate the symbol, save the hash for later. */
2720 in_len = strlen (in);
2722 result = (in_len > maxlen) ? hash_string (in) : 0;
2724 old_name = in;
2726 /* Do the length checking. */
2727 if (in_len <= maxlen)
2728 i = in_len;
2729 else
2731 if (PRIV (flag_hash_long_names))
2732 i = maxlen - 9;
2733 else
2734 i = maxlen;
2737 strncpy (out, in, (size_t) i);
2738 in += i;
2739 out += i;
2741 if ((in_len > maxlen)
2742 && PRIV (flag_hash_long_names))
2743 sprintf (out, "_%08lx", result);
2744 else
2745 *out = 0;
2747 #if VMS_DEBUG
2748 vms_debug (4, "--> [%d]\"%s\"\n", (int)strlen (outbuf), outbuf);
2749 #endif
2751 if (in_len > maxlen
2752 && PRIV (flag_hash_long_names)
2753 && PRIV (flag_show_after_trunc))
2754 printf (_("Symbol %s replaced by %s\n"), old_name, new_name);
2756 return outbuf;
2759 static void
2760 vector_grow1 (struct vector_type *vec, size_t elsz)
2762 if (vec->nbr_el + 1 < vec->max_el)
2763 return;
2765 if (vec->max_el == 0)
2767 vec->max_el = 16;
2768 vec->els = bfd_malloc2 (vec->max_el, elsz);
2770 else
2772 vec->max_el *= 2;
2773 vec->els = bfd_realloc2 (vec->els, vec->max_el, elsz);
2777 /* Bump ABFD file position to next block. */
2779 static void
2780 alpha_vms_file_position_block (bfd *abfd)
2782 /* Next block. */
2783 PRIV (file_pos) += VMS_BLOCK_SIZE - 1;
2784 PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE);
2787 /* Convert from internal structure SRC to external structure DST. */
2789 static void
2790 alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src,
2791 struct vms_eisd *dst)
2793 bfd_putl32 (src->u.eisd.majorid, dst->majorid);
2794 bfd_putl32 (src->u.eisd.minorid, dst->minorid);
2795 bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize);
2796 if (src->u.eisd.eisdsize <= EISD__K_LENEND)
2797 return;
2798 bfd_putl32 (src->u.eisd.secsize, dst->secsize);
2799 bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr);
2800 bfd_putl32 (src->u.eisd.flags, dst->flags);
2801 bfd_putl32 (src->u.eisd.vbn, dst->vbn);
2802 dst->pfc = src->u.eisd.pfc;
2803 dst->matchctl = src->u.eisd.matchctl;
2804 dst->type = src->u.eisd.type;
2805 dst->fill_1 = 0;
2806 if (src->u.eisd.flags & EISD__M_GBL)
2808 bfd_putl32 (src->u.gbl_eisd.ident, dst->ident);
2809 memcpy (dst->gblnam, src->u.gbl_eisd.gblnam,
2810 src->u.gbl_eisd.gblnam[0] + 1);
2814 /* Append EISD to the list of extra eisd for ABFD. */
2816 static void
2817 alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd)
2819 eisd->next = NULL;
2820 if (PRIV (gbl_eisd_head) == NULL)
2821 PRIV (gbl_eisd_head) = eisd;
2822 else
2823 PRIV (gbl_eisd_tail)->next = eisd;
2824 PRIV (gbl_eisd_tail) = eisd;
2827 /* Create an EISD for shared image SHRIMG.
2828 Return FALSE in case of error. */
2830 static bfd_boolean
2831 alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
2833 struct vms_internal_eisd_map *eisd;
2834 int namlen;
2836 namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name));
2837 if (namlen + 5 > EISD__K_GBLNAMLEN)
2839 /* Won't fit. */
2840 return FALSE;
2843 eisd = bfd_alloc (abfd, sizeof (*eisd));
2844 if (eisd == NULL)
2845 return FALSE;
2847 /* Fill the fields. */
2848 eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID;
2849 eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID;
2850 eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3;
2851 eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */
2852 eisd->u.gbl_eisd.common.virt_addr = 0;
2853 eisd->u.gbl_eisd.common.flags = EISD__M_GBL;
2854 eisd->u.gbl_eisd.common.vbn = 0;
2855 eisd->u.gbl_eisd.common.pfc = 0;
2856 eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl);
2857 eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC;
2859 eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident);
2860 eisd->u.gbl_eisd.gblnam[0] = namlen + 4;
2861 memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name),
2862 namlen);
2863 memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4);
2865 /* Append it to the list. */
2866 alpha_vms_append_extra_eisd (abfd, eisd);
2868 return TRUE;
2871 /* Create an EISD for section SEC.
2872 Return FALSE in case of failure. */
2874 static bfd_boolean
2875 alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
2877 struct vms_internal_eisd_map *eisd;
2879 /* Only for allocating section. */
2880 if (!(sec->flags & SEC_ALLOC))
2881 return TRUE;
2883 BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
2884 eisd = bfd_alloc (abfd, sizeof (*eisd));
2885 if (eisd == NULL)
2886 return FALSE;
2887 vms_section_data (sec)->eisd = eisd;
2889 /* Fill the fields. */
2890 eisd->u.eisd.majorid = EISD__K_MAJORID;
2891 eisd->u.eisd.minorid = EISD__K_MINORID;
2892 eisd->u.eisd.eisdsize = EISD__K_LEN;
2893 eisd->u.eisd.secsize =
2894 (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
2895 eisd->u.eisd.virt_addr = sec->vma;
2896 eisd->u.eisd.flags = 0;
2897 eisd->u.eisd.vbn = 0; /* To be later defined. */
2898 eisd->u.eisd.pfc = 0; /* Default. */
2899 eisd->u.eisd.matchctl = EISD__K_MATALL;
2900 eisd->u.eisd.type = EISD__K_NORMAL;
2902 if (sec->flags & SEC_CODE)
2903 eisd->u.eisd.flags |= EISD__M_EXE;
2904 else if (!(sec->flags & SEC_READONLY))
2905 eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
2907 /* If relocations or fixup will be applied, make this isect writeable. */
2908 if (sec->flags & SEC_RELOC)
2909 eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
2911 if (!(sec->flags & SEC_LOAD))
2913 eisd->u.eisd.flags |= EISD__M_DZRO;
2914 eisd->u.eisd.flags &= ~EISD__M_CRF;
2916 if (sec->flags & SEC_LINKER_CREATED)
2918 if (strcmp (sec->name, "$FIXUP$") == 0)
2919 eisd->u.eisd.flags |= EISD__M_FIXUPVEC;
2922 /* Append it to the list. */
2923 eisd->next = NULL;
2924 if (PRIV (eisd_head) == NULL)
2925 PRIV (eisd_head) = eisd;
2926 else
2927 PRIV (eisd_tail)->next = eisd;
2928 PRIV (eisd_tail) = eisd;
2930 return TRUE;
2933 /* Layout executable ABFD and write it to the disk.
2934 Return FALSE in case of failure. */
2936 static bfd_boolean
2937 alpha_vms_write_exec (bfd *abfd)
2939 struct vms_eihd eihd;
2940 struct vms_eiha *eiha;
2941 struct vms_eihi *eihi;
2942 struct vms_eihs *eihs = NULL;
2943 asection *sec;
2944 struct vms_internal_eisd_map *first_eisd;
2945 struct vms_internal_eisd_map *eisd;
2946 asection *dst;
2947 asection *dmt;
2948 file_ptr gst_filepos = 0;
2949 unsigned int lnkflags = 0;
2951 /* Build the EIHD. */
2952 PRIV (file_pos) = EIHD__C_LENGTH;
2954 memset (&eihd, 0, sizeof (eihd));
2955 memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2));
2957 bfd_putl32 (EIHD__K_MAJORID, eihd.majorid);
2958 bfd_putl32 (EIHD__K_MINORID, eihd.minorid);
2960 bfd_putl32 (sizeof (eihd), eihd.size);
2961 bfd_putl32 (0, eihd.isdoff);
2962 bfd_putl32 (0, eihd.activoff);
2963 bfd_putl32 (0, eihd.symdbgoff);
2964 bfd_putl32 (0, eihd.imgidoff);
2965 bfd_putl32 (0, eihd.patchoff);
2966 bfd_putl64 (0, eihd.iafva);
2967 bfd_putl32 (0, eihd.version_array_off);
2969 bfd_putl32 (EIHD__K_EXE, eihd.imgtype);
2970 bfd_putl32 (0, eihd.subtype);
2972 bfd_putl32 (0, eihd.imgiocnt);
2973 bfd_putl32 (-1, eihd.privreqs);
2974 bfd_putl32 (-1, eihd.privreqs + 4);
2976 bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
2977 eihd.hdrblkcnt);
2978 bfd_putl32 (0, eihd.ident);
2979 bfd_putl32 (0, eihd.sysver);
2981 eihd.matchctl = 0;
2982 bfd_putl32 (0, eihd.symvect_size);
2983 bfd_putl32 (16, eihd.virt_mem_block_size);
2984 bfd_putl32 (0, eihd.ext_fixup_off);
2985 bfd_putl32 (0, eihd.noopt_psect_off);
2986 bfd_putl32 (-1, eihd.alias);
2988 /* Alloc EIHA. */
2989 eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
2990 bfd_putl32 (PRIV (file_pos), eihd.activoff);
2991 PRIV (file_pos) += sizeof (struct vms_eiha);
2993 bfd_putl32 (sizeof (struct vms_eiha), eiha->size);
2994 bfd_putl32 (0, eiha->spare);
2995 bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1);
2996 bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2);
2997 bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3);
2998 bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4);
2999 bfd_putl64 (0, eiha->inishr);
3001 /* Alloc EIHI. */
3002 eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos));
3003 bfd_putl32 (PRIV (file_pos), eihd.imgidoff);
3004 PRIV (file_pos) += sizeof (struct vms_eihi);
3006 bfd_putl32 (EIHI__K_MAJORID, eihi->majorid);
3007 bfd_putl32 (EIHI__K_MINORID, eihi->minorid);
3009 char *module;
3010 unsigned int len;
3012 /* Set module name. */
3013 module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
3014 len = strlen (module);
3015 if (len > sizeof (eihi->imgnam) - 1)
3016 len = sizeof (eihi->imgnam) - 1;
3017 eihi->imgnam[0] = len;
3018 memcpy (eihi->imgnam + 1, module, len);
3019 free (module);
3022 unsigned int lo;
3023 unsigned int hi;
3025 /* Set time. */
3026 vms_get_time (&hi, &lo);
3027 bfd_putl32 (lo, eihi->linktime + 0);
3028 bfd_putl32 (hi, eihi->linktime + 4);
3030 eihi->imgid[0] = 0;
3031 eihi->linkid[0] = 0;
3032 eihi->imgbid[0] = 0;
3034 /* Alloc EIHS. */
3035 dst = PRIV (dst_section);
3036 dmt = bfd_get_section_by_name (abfd, "$DMT$");
3037 if (dst != NULL && dst->size != 0)
3039 eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos));
3040 bfd_putl32 (PRIV (file_pos), eihd.symdbgoff);
3041 PRIV (file_pos) += sizeof (struct vms_eihs);
3043 bfd_putl32 (EIHS__K_MAJORID, eihs->majorid);
3044 bfd_putl32 (EIHS__K_MINORID, eihs->minorid);
3045 bfd_putl32 (0, eihs->dstvbn);
3046 bfd_putl32 (0, eihs->dstsize);
3047 bfd_putl32 (0, eihs->gstvbn);
3048 bfd_putl32 (0, eihs->gstsize);
3049 bfd_putl32 (0, eihs->dmtvbn);
3050 bfd_putl32 (0, eihs->dmtsize);
3053 /* One EISD per section. */
3054 for (sec = abfd->sections; sec; sec = sec->next)
3056 if (!alpha_vms_create_eisd_for_section (abfd, sec))
3057 return FALSE;
3060 /* Merge section EIDS which extra ones. */
3061 if (PRIV (eisd_tail))
3062 PRIV (eisd_tail)->next = PRIV (gbl_eisd_head);
3063 else
3064 PRIV (eisd_head) = PRIV (gbl_eisd_head);
3065 if (PRIV (gbl_eisd_tail))
3066 PRIV (eisd_tail) = PRIV (gbl_eisd_tail);
3068 first_eisd = PRIV (eisd_head);
3070 /* Add end of eisd. */
3071 if (first_eisd)
3073 eisd = bfd_zalloc (abfd, sizeof (*eisd));
3074 if (eisd == NULL)
3075 return FALSE;
3076 eisd->u.eisd.majorid = 0;
3077 eisd->u.eisd.minorid = 0;
3078 eisd->u.eisd.eisdsize = 0;
3079 alpha_vms_append_extra_eisd (abfd, eisd);
3082 /* Place EISD in the file. */
3083 for (eisd = first_eisd; eisd; eisd = eisd->next)
3085 file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE);
3087 /* First block is a little bit special: there is a word at the end. */
3088 if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2)
3089 room -= 2;
3090 if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND)
3091 alpha_vms_file_position_block (abfd);
3093 eisd->file_pos = PRIV (file_pos);
3094 PRIV (file_pos) += eisd->u.eisd.eisdsize;
3096 if (eisd->u.eisd.flags & EISD__M_FIXUPVEC)
3097 bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva);
3100 if (first_eisd != NULL)
3102 bfd_putl32 (first_eisd->file_pos, eihd.isdoff);
3103 /* Real size of end of eisd marker. */
3104 PRIV (file_pos) += EISD__K_LENEND;
3107 bfd_putl32 (PRIV (file_pos), eihd.size);
3108 bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
3109 eihd.hdrblkcnt);
3111 /* Place sections. */
3112 for (sec = abfd->sections; sec; sec = sec->next)
3114 if (!(sec->flags & SEC_HAS_CONTENTS))
3115 continue;
3117 eisd = vms_section_data (sec)->eisd;
3119 /* Align on a block. */
3120 alpha_vms_file_position_block (abfd);
3121 sec->filepos = PRIV (file_pos);
3123 if (eisd != NULL)
3124 eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1;
3126 PRIV (file_pos) += sec->size;
3129 /* Update EIHS. */
3130 if (eihs != NULL && dst != NULL)
3132 bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn);
3133 bfd_putl32 (dst->size, eihs->dstsize);
3135 if (dmt != NULL)
3137 lnkflags |= EIHD__M_DBGDMT;
3138 bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn);
3139 bfd_putl32 (dmt->size, eihs->dmtsize);
3141 if (PRIV (gsd_sym_count) != 0)
3143 alpha_vms_file_position_block (abfd);
3144 gst_filepos = PRIV (file_pos);
3145 bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn);
3146 bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize);
3150 /* Write EISD in hdr. */
3151 for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE;
3152 eisd = eisd->next)
3153 alpha_vms_swap_eisd_out
3154 (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos));
3156 /* Write first block. */
3157 bfd_putl32 (lnkflags, eihd.lnkflags);
3158 if (bfd_bwrite (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
3159 return FALSE;
3161 /* Write remaining eisd. */
3162 if (eisd != NULL)
3164 unsigned char blk[VMS_BLOCK_SIZE];
3165 struct vms_internal_eisd_map *next_eisd;
3167 memset (blk, 0xff, sizeof (blk));
3168 while (eisd != NULL)
3170 alpha_vms_swap_eisd_out
3171 (eisd,
3172 (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE)));
3174 next_eisd = eisd->next;
3175 if (next_eisd == NULL
3176 || (next_eisd->file_pos / VMS_BLOCK_SIZE
3177 != eisd->file_pos / VMS_BLOCK_SIZE))
3179 if (bfd_bwrite (blk, sizeof (blk), abfd) != sizeof (blk))
3180 return FALSE;
3182 memset (blk, 0xff, sizeof (blk));
3184 eisd = next_eisd;
3188 /* Write sections. */
3189 for (sec = abfd->sections; sec; sec = sec->next)
3191 unsigned char blk[VMS_BLOCK_SIZE];
3192 bfd_size_type len;
3194 if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS))
3195 continue;
3196 if (bfd_bwrite (sec->contents, sec->size, abfd) != sec->size)
3197 return FALSE;
3199 /* Pad. */
3200 len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE;
3201 if (len != VMS_BLOCK_SIZE)
3203 memset (blk, 0, len);
3204 if (bfd_bwrite (blk, len, abfd) != len)
3205 return FALSE;
3209 /* Write GST. */
3210 if (gst_filepos != 0)
3212 struct vms_rec_wr *recwr = &PRIV (recwr);
3213 unsigned int i;
3215 _bfd_vms_write_emh (abfd);
3216 _bfd_vms_write_lmn (abfd, "GNU LD");
3218 /* PSC for the absolute section. */
3219 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3220 _bfd_vms_output_long (recwr, 0);
3221 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3222 _bfd_vms_output_short (recwr, 0);
3223 _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD);
3224 _bfd_vms_output_long (recwr, 0);
3225 _bfd_vms_output_counted (recwr, ".$$ABS$$.");
3226 _bfd_vms_output_end_subrec (recwr);
3227 _bfd_vms_output_end (abfd, recwr);
3229 for (i = 0; i < PRIV (gsd_sym_count); i++)
3231 struct vms_symbol_entry *sym = PRIV (syms)[i];
3232 char *hash;
3233 bfd_vma val;
3234 bfd_vma ep;
3236 if ((i % 5) == 0)
3238 _bfd_vms_output_alignment (recwr, 8);
3239 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3240 _bfd_vms_output_long (recwr, 0);
3242 _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG);
3243 _bfd_vms_output_short (recwr, 0); /* Data type, alignment. */
3244 _bfd_vms_output_short (recwr, sym->flags);
3246 if (sym->code_section)
3247 ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value);
3248 else
3250 BFD_ASSERT (sym->code_value == 0);
3251 ep = 0;
3253 val = alpha_vms_get_sym_value (sym->section, sym->value);
3254 _bfd_vms_output_quad
3255 (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val);
3256 _bfd_vms_output_quad (recwr, ep);
3257 _bfd_vms_output_quad (recwr, val);
3258 _bfd_vms_output_long (recwr, 0);
3259 hash = _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ__C_SYMSIZ);
3260 _bfd_vms_output_counted (recwr, hash);
3261 _bfd_vms_output_end_subrec (recwr);
3262 if ((i % 5) == 4)
3263 _bfd_vms_output_end (abfd, recwr);
3265 if ((i % 5) != 0)
3266 _bfd_vms_output_end (abfd, recwr);
3268 if (!_bfd_vms_write_eeom (abfd))
3269 return FALSE;
3271 return TRUE;
3274 /* Object write. */
3276 /* Write section and symbol directory of bfd abfd. Return FALSE on error. */
3278 static bfd_boolean
3279 _bfd_vms_write_egsd (bfd *abfd)
3281 asection *section;
3282 asymbol *symbol;
3283 unsigned int symnum;
3284 const char *sname;
3285 flagword new_flags, old_flags;
3286 int abs_section_index = -1;
3287 unsigned int target_index = 0;
3288 struct vms_rec_wr *recwr = &PRIV (recwr);
3290 vms_debug2 ((2, "vms_write_egsd\n"));
3292 /* Egsd is quadword aligned. */
3293 _bfd_vms_output_alignment (recwr, 8);
3295 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3296 _bfd_vms_output_long (recwr, 0);
3298 /* Number sections. */
3299 for (section = abfd->sections; section != NULL; section = section->next)
3301 if (section->flags & SEC_DEBUGGING)
3302 continue;
3303 if (!strcmp (section->name, ".vmsdebug"))
3305 section->flags |= SEC_DEBUGGING;
3306 continue;
3308 section->target_index = target_index++;
3311 for (section = abfd->sections; section != NULL; section = section->next)
3313 vms_debug2 ((3, "Section #%d %s, %d bytes\n",
3314 section->target_index, section->name, (int)section->size));
3316 /* Don't write out the VMS debug info section since it is in the
3317 ETBT and EDBG sections in etir. */
3318 if (section->flags & SEC_DEBUGGING)
3319 continue;
3321 /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
3322 if (_bfd_vms_output_check (recwr, 64) < 0)
3324 _bfd_vms_output_end (abfd, recwr);
3325 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3326 _bfd_vms_output_long (recwr, 0);
3329 /* Don't know if this is necessary for the linker but for now it keeps
3330 vms_slurp_gsd happy. */
3331 sname = section->name;
3332 if (*sname == '.')
3334 /* Remove leading dot. */
3335 sname++;
3336 if ((*sname == 't') && (strcmp (sname, "text") == 0))
3337 sname = EVAX_CODE_NAME;
3338 else if ((*sname == 'd') && (strcmp (sname, "data") == 0))
3339 sname = EVAX_DATA_NAME;
3340 else if ((*sname == 'b') && (strcmp (sname, "bss") == 0))
3341 sname = EVAX_BSS_NAME;
3342 else if ((*sname == 'l') && (strcmp (sname, "link") == 0))
3343 sname = EVAX_LINK_NAME;
3344 else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0))
3345 sname = EVAX_READONLY_NAME;
3346 else if ((*sname == 'l') && (strcmp (sname, "literal") == 0))
3347 sname = EVAX_LITERAL_NAME;
3348 else if ((*sname == 'l') && (strcmp (sname, "literals") == 0))
3349 sname = EVAX_LITERALS_NAME;
3350 else if ((*sname == 'c') && (strcmp (sname, "comm") == 0))
3351 sname = EVAX_COMMON_NAME;
3352 else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
3353 sname = EVAX_LOCAL_NAME;
3355 else
3356 sname = _bfd_vms_length_hash_symbol (abfd, sname, EOBJ__C_SECSIZ);
3358 if (bfd_is_com_section (section))
3359 new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD
3360 | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM);
3361 else
3362 new_flags = vms_esecflag_by_name (evax_section_flags, sname,
3363 section->size > 0);
3365 /* Modify them as directed. */
3366 if (section->flags & SEC_READONLY)
3367 new_flags &= ~EGPS__V_WRT;
3369 new_flags &= ~vms_section_data (section)->no_flags;
3370 new_flags |= vms_section_data (section)->flags;
3372 vms_debug2 ((3, "sec flags %x\n", section->flags));
3373 vms_debug2 ((3, "new_flags %x, _raw_size %lu\n",
3374 new_flags, (unsigned long)section->size));
3376 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3377 _bfd_vms_output_short (recwr, section->alignment_power & 0xff);
3378 _bfd_vms_output_short (recwr, new_flags);
3379 _bfd_vms_output_long (recwr, (unsigned long) section->size);
3380 _bfd_vms_output_counted (recwr, sname);
3381 _bfd_vms_output_end_subrec (recwr);
3383 /* If the section is an obsolute one, remind its index as it will be
3384 used later for absolute symbols. */
3385 if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0)
3386 abs_section_index = section->target_index;
3389 /* Output symbols. */
3390 vms_debug2 ((3, "%d symbols found\n", abfd->symcount));
3392 bfd_set_start_address (abfd, (bfd_vma) -1);
3394 for (symnum = 0; symnum < abfd->symcount; symnum++)
3396 char *hash;
3398 symbol = abfd->outsymbols[symnum];
3399 old_flags = symbol->flags;
3401 /* Work-around a missing feature: consider __main as the main entry
3402 point. */
3403 if (*(symbol->name) == '_')
3405 if (strcmp (symbol->name, "__main") == 0)
3406 bfd_set_start_address (abfd, (bfd_vma)symbol->value);
3409 /* Only put in the GSD the global and the undefined symbols. */
3410 if (old_flags & BSF_FILE)
3411 continue;
3413 if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section))
3415 /* If the LIB$INITIIALIZE section is present, add a reference to
3416 LIB$INITIALIZE symbol. FIXME: this should be done explicitely
3417 in the assembly file. */
3418 if (!((old_flags & BSF_SECTION_SYM) != 0
3419 && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0))
3420 continue;
3423 /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. Add 16 more
3424 bytes for a possible ABS section. */
3425 if (_bfd_vms_output_check (recwr, 80 + 16) < 0)
3427 _bfd_vms_output_end (abfd, recwr);
3428 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3429 _bfd_vms_output_long (recwr, 0);
3432 if ((old_flags & BSF_GLOBAL) != 0
3433 && bfd_is_abs_section (symbol->section)
3434 && abs_section_index <= 0)
3436 /* Create an absolute section if none was defined. It is highly
3437 unlikely that the name $ABS$ clashes with a user defined
3438 non-absolute section name. */
3439 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3440 _bfd_vms_output_short (recwr, 4);
3441 _bfd_vms_output_short (recwr, EGPS__V_SHR);
3442 _bfd_vms_output_long (recwr, 0);
3443 _bfd_vms_output_counted (recwr, "$ABS$");
3444 _bfd_vms_output_end_subrec (recwr);
3446 abs_section_index = target_index++;
3449 _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM);
3451 /* Data type, alignment. */
3452 _bfd_vms_output_short (recwr, 0);
3454 new_flags = 0;
3456 if (old_flags & BSF_WEAK)
3457 new_flags |= EGSY__V_WEAK;
3458 if (bfd_is_com_section (symbol->section)) /* .comm */
3459 new_flags |= (EGSY__V_WEAK | EGSY__V_COMM);
3461 if (old_flags & BSF_FUNCTION)
3463 new_flags |= EGSY__V_NORM;
3464 new_flags |= EGSY__V_REL;
3466 if (old_flags & BSF_GLOBAL)
3468 new_flags |= EGSY__V_DEF;
3469 if (!bfd_is_abs_section (symbol->section))
3470 new_flags |= EGSY__V_REL;
3472 _bfd_vms_output_short (recwr, new_flags);
3474 if (old_flags & BSF_GLOBAL)
3476 /* Symbol definition. */
3477 bfd_vma code_address = 0;
3478 unsigned long ca_psindx = 0;
3479 unsigned long psindx;
3481 if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL)
3483 asymbol *sym;
3485 sym =
3486 ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym;
3487 code_address = sym->value;
3488 ca_psindx = sym->section->target_index;
3490 if (bfd_is_abs_section (symbol->section))
3491 psindx = abs_section_index;
3492 else
3493 psindx = symbol->section->target_index;
3495 _bfd_vms_output_quad (recwr, symbol->value);
3496 _bfd_vms_output_quad (recwr, code_address);
3497 _bfd_vms_output_long (recwr, ca_psindx);
3498 _bfd_vms_output_long (recwr, psindx);
3500 hash = _bfd_vms_length_hash_symbol (abfd, symbol->name, EOBJ__C_SYMSIZ);
3501 _bfd_vms_output_counted (recwr, hash);
3503 _bfd_vms_output_end_subrec (recwr);
3506 _bfd_vms_output_alignment (recwr, 8);
3507 _bfd_vms_output_end (abfd, recwr);
3509 return TRUE;
3512 /* Write object header for bfd abfd. Return FALSE on error. */
3514 static bfd_boolean
3515 _bfd_vms_write_ehdr (bfd *abfd)
3517 asymbol *symbol;
3518 unsigned int symnum;
3519 int had_case = 0;
3520 int had_file = 0;
3521 struct vms_rec_wr *recwr = &PRIV (recwr);
3523 vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
3525 _bfd_vms_output_alignment (recwr, 2);
3527 _bfd_vms_write_emh (abfd);
3528 _bfd_vms_write_lmn (abfd, "GNU AS");
3530 /* SRC. */
3531 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3532 _bfd_vms_output_short (recwr, EMH__C_SRC);
3534 for (symnum = 0; symnum < abfd->symcount; symnum++)
3536 symbol = abfd->outsymbols[symnum];
3538 if (symbol->flags & BSF_FILE)
3540 if (CONST_STRNEQ ((char *)symbol->name, "<CASE:"))
3542 PRIV (flag_hash_long_names) = symbol->name[6] - '0';
3543 PRIV (flag_show_after_trunc) = symbol->name[7] - '0';
3545 if (had_file)
3546 break;
3547 had_case = 1;
3548 continue;
3551 _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name,
3552 (int) strlen (symbol->name));
3553 if (had_case)
3554 break;
3555 had_file = 1;
3559 if (symnum == abfd->symcount)
3560 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
3562 _bfd_vms_output_end (abfd, recwr);
3564 /* TTL. */
3565 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3566 _bfd_vms_output_short (recwr, EMH__C_TTL);
3567 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
3568 _bfd_vms_output_end (abfd, recwr);
3570 /* CPR. */
3571 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3572 _bfd_vms_output_short (recwr, EMH__C_CPR);
3573 _bfd_vms_output_dump (recwr,
3574 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
3575 39);
3576 _bfd_vms_output_end (abfd, recwr);
3578 return TRUE;
3581 /* Part 4.6, relocations. */
3584 /* WRITE ETIR SECTION
3586 This is still under construction and therefore not documented. */
3588 /* Close the etir/etbt record. */
3590 static void
3591 end_etir_record (bfd * abfd)
3593 struct vms_rec_wr *recwr = &PRIV (recwr);
3595 _bfd_vms_output_end (abfd, recwr);
3598 static void
3599 start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset)
3601 struct vms_rec_wr *recwr = &PRIV (recwr);
3603 if (section->flags & SEC_DEBUGGING)
3605 _bfd_vms_output_begin (recwr, EOBJ__C_ETBT);
3607 if (offset == 0)
3609 /* Push start offset. */
3610 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3611 _bfd_vms_output_long (recwr, (unsigned long) 0);
3612 _bfd_vms_output_end_subrec (recwr);
3614 /* Set location. */
3615 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC);
3616 _bfd_vms_output_end_subrec (recwr);
3619 else
3621 _bfd_vms_output_begin (recwr, EOBJ__C_ETIR);
3623 if (offset == 0)
3625 /* Push start offset. */
3626 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3627 _bfd_vms_output_long (recwr, (unsigned long) section->target_index);
3628 _bfd_vms_output_quad (recwr, offset);
3629 _bfd_vms_output_end_subrec (recwr);
3631 /* Start = pop (). */
3632 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB);
3633 _bfd_vms_output_end_subrec (recwr);
3638 /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual
3639 address VADDR in section specified by SEC_INDEX and NAME. */
3641 static void
3642 sto_imm (bfd *abfd, asection *section,
3643 bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr)
3645 bfd_size_type size;
3646 struct vms_rec_wr *recwr = &PRIV (recwr);
3648 #if VMS_DEBUG
3649 _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize);
3650 _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr);
3651 #endif
3653 while (ssize > 0)
3655 /* Try all the rest. */
3656 size = ssize;
3658 if (_bfd_vms_output_check (recwr, size) < 0)
3660 /* Doesn't fit, split ! */
3661 end_etir_record (abfd);
3663 start_etir_or_etbt_record (abfd, section, vaddr);
3665 size = _bfd_vms_output_check (recwr, 0); /* get max size */
3666 if (size > ssize) /* more than what's left ? */
3667 size = ssize;
3670 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM);
3671 _bfd_vms_output_long (recwr, (unsigned long) (size));
3672 _bfd_vms_output_dump (recwr, cptr, size);
3673 _bfd_vms_output_end_subrec (recwr);
3675 #if VMS_DEBUG
3676 _bfd_vms_debug (10, "dumped %d bytes\n", (int) size);
3677 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
3678 #endif
3680 vaddr += size;
3681 cptr += size;
3682 ssize -= size;
3686 static void
3687 etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
3689 if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0)
3691 /* Not enough room in this record. Close it and open a new one. */
3692 end_etir_record (abfd);
3693 start_etir_or_etbt_record (abfd, section, vaddr);
3697 /* Return whether RELOC must be deferred till the end. */
3699 static bfd_boolean
3700 defer_reloc_p (arelent *reloc)
3702 switch (reloc->howto->type)
3704 case ALPHA_R_NOP:
3705 case ALPHA_R_LDA:
3706 case ALPHA_R_BSR:
3707 case ALPHA_R_BOH:
3708 return TRUE;
3710 default:
3711 return FALSE;
3715 /* Write section contents for bfd abfd. Return FALSE on error. */
3717 static bfd_boolean
3718 _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
3720 asection *section;
3721 struct vms_rec_wr *recwr = &PRIV (recwr);
3723 vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype));
3725 _bfd_vms_output_alignment (recwr, 4);
3727 PRIV (vms_linkage_index) = 1;
3729 for (section = abfd->sections; section; section = section->next)
3731 vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n",
3732 section->target_index, section->name, (int) (section->size)));
3734 if (!(section->flags & SEC_HAS_CONTENTS)
3735 || bfd_is_com_section (section))
3736 continue;
3738 if (!section->contents)
3740 bfd_set_error (bfd_error_no_contents);
3741 return FALSE;
3744 start_etir_or_etbt_record (abfd, section, 0);
3746 if (section->flags & SEC_RELOC)
3748 bfd_vma curr_addr = 0;
3749 unsigned char *curr_data = section->contents;
3750 bfd_size_type size;
3751 int pass2_needed = 0;
3752 int pass2_in_progress = 0;
3753 unsigned int irel;
3755 if (section->reloc_count <= 0)
3756 (*_bfd_error_handler)
3757 (_("SEC_RELOC with no relocs in section %s"), section->name);
3759 #if VMS_DEBUG
3760 else
3762 int i = section->reloc_count;
3763 arelent **rptr = section->orelocation;
3764 _bfd_vms_debug (4, "%d relocations:\n", i);
3765 while (i-- > 0)
3767 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, "
3768 "addr %08lx, off %08lx, len %d: %s\n",
3769 (*(*rptr)->sym_ptr_ptr)->name,
3770 (*(*rptr)->sym_ptr_ptr)->section->name,
3771 (long) (*(*rptr)->sym_ptr_ptr)->value,
3772 (unsigned long)(*rptr)->address,
3773 (unsigned long)(*rptr)->addend,
3774 bfd_get_reloc_size ((*rptr)->howto),
3775 ( *rptr)->howto->name);
3776 rptr++;
3779 #endif
3781 new_pass:
3782 for (irel = 0; irel < section->reloc_count; irel++)
3784 struct evax_private_udata_struct *udata;
3785 arelent *rptr = section->orelocation [irel];
3786 bfd_vma addr = rptr->address;
3787 asymbol *sym = *rptr->sym_ptr_ptr;
3788 asection *sec = sym->section;
3789 bfd_boolean defer = defer_reloc_p (rptr);
3790 unsigned int slen;
3791 char *hash;
3793 if (pass2_in_progress)
3795 /* Non-deferred relocs have already been output. */
3796 if (!defer)
3797 continue;
3799 else
3801 /* Deferred relocs must be output at the very end. */
3802 if (defer)
3804 pass2_needed = 1;
3805 continue;
3808 /* Regular relocs are intertwined with binary data. */
3809 if (curr_addr > addr)
3810 (*_bfd_error_handler) (_("Size error in section %s"),
3811 section->name);
3812 size = addr - curr_addr;
3813 sto_imm (abfd, section, size, curr_data, curr_addr);
3814 curr_data += size;
3815 curr_addr += size;
3818 size = bfd_get_reloc_size (rptr->howto);
3820 switch (rptr->howto->type)
3822 case ALPHA_R_IGNORE:
3823 break;
3825 case ALPHA_R_REFLONG:
3826 if (bfd_is_und_section (sym->section))
3828 bfd_vma addend = rptr->addend;
3829 slen = strlen ((char *) sym->name);
3830 hash = _bfd_vms_length_hash_symbol
3831 (abfd, sym->name, EOBJ__C_SYMSIZ);
3832 etir_output_check (abfd, section, curr_addr, slen);
3833 if (addend)
3835 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
3836 _bfd_vms_output_counted (recwr, hash);
3837 _bfd_vms_output_end_subrec (recwr);
3838 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3839 _bfd_vms_output_long (recwr, (unsigned long) addend);
3840 _bfd_vms_output_end_subrec (recwr);
3841 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
3842 _bfd_vms_output_end_subrec (recwr);
3843 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3844 _bfd_vms_output_end_subrec (recwr);
3846 else
3848 _bfd_vms_output_begin_subrec
3849 (recwr, ETIR__C_STO_GBL_LW);
3850 _bfd_vms_output_counted (recwr, hash);
3851 _bfd_vms_output_end_subrec (recwr);
3854 else if (bfd_is_abs_section (sym->section))
3856 etir_output_check (abfd, section, curr_addr, 16);
3857 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3858 _bfd_vms_output_long (recwr, (unsigned long) sym->value);
3859 _bfd_vms_output_end_subrec (recwr);
3860 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3861 _bfd_vms_output_end_subrec (recwr);
3863 else
3865 etir_output_check (abfd, section, curr_addr, 32);
3866 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3867 _bfd_vms_output_long (recwr,
3868 (unsigned long) sec->target_index);
3869 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
3870 _bfd_vms_output_end_subrec (recwr);
3871 /* ??? Table B-8 of the OpenVMS Linker Utilily Manual
3872 says that we should have a ETIR__C_STO_OFF here.
3873 But the relocation would not be BFD_RELOC_32 then.
3874 This case is very likely unreachable. */
3875 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3876 _bfd_vms_output_end_subrec (recwr);
3878 break;
3880 case ALPHA_R_REFQUAD:
3881 if (bfd_is_und_section (sym->section))
3883 bfd_vma addend = rptr->addend;
3884 slen = strlen ((char *) sym->name);
3885 hash = _bfd_vms_length_hash_symbol
3886 (abfd, sym->name, EOBJ__C_SYMSIZ);
3887 etir_output_check (abfd, section, curr_addr, slen);
3888 if (addend)
3890 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
3891 _bfd_vms_output_counted (recwr, hash);
3892 _bfd_vms_output_end_subrec (recwr);
3893 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
3894 _bfd_vms_output_quad (recwr, addend);
3895 _bfd_vms_output_end_subrec (recwr);
3896 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
3897 _bfd_vms_output_end_subrec (recwr);
3898 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
3899 _bfd_vms_output_end_subrec (recwr);
3901 else
3903 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL);
3904 _bfd_vms_output_counted (recwr, hash);
3905 _bfd_vms_output_end_subrec (recwr);
3908 else if (bfd_is_abs_section (sym->section))
3910 etir_output_check (abfd, section, curr_addr, 16);
3911 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
3912 _bfd_vms_output_quad (recwr, sym->value);
3913 _bfd_vms_output_end_subrec (recwr);
3914 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
3915 _bfd_vms_output_end_subrec (recwr);
3917 else
3919 etir_output_check (abfd, section, curr_addr, 32);
3920 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3921 _bfd_vms_output_long (recwr,
3922 (unsigned long) sec->target_index);
3923 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
3924 _bfd_vms_output_end_subrec (recwr);
3925 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF);
3926 _bfd_vms_output_end_subrec (recwr);
3928 break;
3930 case ALPHA_R_HINT:
3931 sto_imm (abfd, section, size, curr_data, curr_addr);
3932 break;
3934 case ALPHA_R_LINKAGE:
3935 etir_output_check (abfd, section, curr_addr, 64);
3936 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
3937 _bfd_vms_output_long
3938 (recwr, (unsigned long) PRIV (vms_linkage_index));
3939 PRIV (vms_linkage_index) += 2;
3940 hash = _bfd_vms_length_hash_symbol
3941 (abfd, sym->name, EOBJ__C_SYMSIZ);
3942 _bfd_vms_output_counted (recwr, hash);
3943 _bfd_vms_output_byte (recwr, 0);
3944 _bfd_vms_output_end_subrec (recwr);
3945 break;
3947 case ALPHA_R_CODEADDR:
3948 slen = strlen ((char *) sym->name);
3949 hash = _bfd_vms_length_hash_symbol
3950 (abfd, sym->name, EOBJ__C_SYMSIZ);
3951 etir_output_check (abfd, section, curr_addr, slen);
3952 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
3953 _bfd_vms_output_counted (recwr, hash);
3954 _bfd_vms_output_end_subrec (recwr);
3955 break;
3957 case ALPHA_R_NOP:
3958 udata
3959 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
3960 etir_output_check (abfd, section, curr_addr,
3961 32 + 1 + strlen (udata->origname));
3962 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
3963 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
3964 _bfd_vms_output_long
3965 (recwr,
3966 (unsigned long) udata->enbsym->section->target_index);
3967 _bfd_vms_output_quad (recwr, rptr->address);
3968 _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f);
3969 _bfd_vms_output_long
3970 (recwr,
3971 (unsigned long) udata->enbsym->section->target_index);
3972 _bfd_vms_output_quad (recwr, rptr->addend);
3973 _bfd_vms_output_counted
3974 (recwr, _bfd_vms_length_hash_symbol
3975 (abfd, udata->origname, EOBJ__C_SYMSIZ));
3976 _bfd_vms_output_end_subrec (recwr);
3977 break;
3979 case ALPHA_R_BSR:
3980 (*_bfd_error_handler) (_("Spurious ALPHA_R_BSR reloc"));
3981 break;
3983 case ALPHA_R_LDA:
3984 udata
3985 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
3986 etir_output_check (abfd, section, curr_addr,
3987 32 + 1 + strlen (udata->origname));
3988 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL);
3989 _bfd_vms_output_long
3990 (recwr, (unsigned long) udata->lkindex + 1);
3991 _bfd_vms_output_long
3992 (recwr,
3993 (unsigned long) udata->enbsym->section->target_index);
3994 _bfd_vms_output_quad (recwr, rptr->address);
3995 _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000);
3996 _bfd_vms_output_long
3997 (recwr, (unsigned long) udata->bsym->section->target_index);
3998 _bfd_vms_output_quad (recwr, rptr->addend);
3999 _bfd_vms_output_counted
4000 (recwr, _bfd_vms_length_hash_symbol
4001 (abfd, udata->origname, EOBJ__C_SYMSIZ));
4002 _bfd_vms_output_end_subrec (recwr);
4003 break;
4005 case ALPHA_R_BOH:
4006 udata
4007 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
4008 etir_output_check (abfd, section, curr_addr,
4009 32 + 1 + strlen (udata->origname));
4010 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
4011 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
4012 _bfd_vms_output_long
4013 (recwr,
4014 (unsigned long) udata->enbsym->section->target_index);
4015 _bfd_vms_output_quad (recwr, rptr->address);
4016 _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000);
4017 _bfd_vms_output_long
4018 (recwr,
4019 (unsigned long) udata->enbsym->section->target_index);
4020 _bfd_vms_output_quad (recwr, rptr->addend);
4021 _bfd_vms_output_counted
4022 (recwr, _bfd_vms_length_hash_symbol
4023 (abfd, udata->origname, EOBJ__C_SYMSIZ));
4024 _bfd_vms_output_end_subrec (recwr);
4025 break;
4027 default:
4028 (*_bfd_error_handler) (_("Unhandled relocation %s"),
4029 rptr->howto->name);
4030 break;
4033 curr_data += size;
4034 curr_addr += size;
4035 } /* End of relocs loop. */
4037 if (!pass2_in_progress)
4039 /* Output rest of section. */
4040 if (curr_addr > section->size)
4041 (*_bfd_error_handler) (_("Size error in section %s"),
4042 section->name);
4043 size = section->size - curr_addr;
4044 sto_imm (abfd, section, size, curr_data, curr_addr);
4045 curr_data += size;
4046 curr_addr += size;
4048 if (pass2_needed)
4050 pass2_in_progress = 1;
4051 goto new_pass;
4056 else /* (section->flags & SEC_RELOC) */
4057 sto_imm (abfd, section, section->size, section->contents, 0);
4059 end_etir_record (abfd);
4062 _bfd_vms_output_alignment (recwr, 2);
4063 return TRUE;
4066 /* Write cached information into a file being written, at bfd_close. */
4068 static bfd_boolean
4069 alpha_vms_write_object_contents (bfd *abfd)
4071 vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
4073 if (abfd->flags & (EXEC_P | DYNAMIC))
4075 return alpha_vms_write_exec (abfd);
4077 else
4079 if (abfd->section_count > 0) /* we have sections */
4081 if (_bfd_vms_write_ehdr (abfd) != TRUE)
4082 return FALSE;
4083 if (_bfd_vms_write_egsd (abfd) != TRUE)
4084 return FALSE;
4085 if (_bfd_vms_write_etir (abfd, EOBJ__C_ETIR) != TRUE)
4086 return FALSE;
4087 if (_bfd_vms_write_eeom (abfd) != TRUE)
4088 return FALSE;
4091 return TRUE;
4094 /* Debug stuff: nearest line. */
4096 #define SET_MODULE_PARSED(m) \
4097 do { if ((m)->name == NULL) (m)->name = ""; } while (0)
4098 #define IS_MODULE_PARSED(m) ((m)->name != NULL)
4100 /* Build a new module for the specified BFD. */
4102 static struct module *
4103 new_module (bfd *abfd)
4105 struct module *module
4106 = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
4107 module->file_table_count = 16; /* Arbitrary. */
4108 module->file_table
4109 = bfd_malloc (module->file_table_count * sizeof (struct fileinfo));
4110 return module;
4113 /* Parse debug info for a module and internalize it. */
4115 static void
4116 parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
4117 int length)
4119 unsigned char *maxptr = ptr + length;
4120 unsigned char *src_ptr, *pcl_ptr;
4121 unsigned int prev_linum = 0, curr_linenum = 0;
4122 bfd_vma prev_pc = 0, curr_pc = 0;
4123 struct srecinfo *curr_srec, *srec;
4124 struct lineinfo *curr_line, *line;
4125 struct funcinfo *funcinfo;
4127 /* Initialize tables with zero element. */
4128 curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4129 module->srec_table = curr_srec;
4131 curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4132 module->line_table = curr_line;
4134 while (length == -1 || ptr < maxptr)
4136 /* The first byte is not counted in the recorded length. */
4137 int rec_length = bfd_getl16 (ptr) + 1;
4138 int rec_type = bfd_getl16 (ptr + 2);
4140 vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
4142 if (length == -1 && rec_type == DST__K_MODEND)
4143 break;
4145 switch (rec_type)
4147 case DST__K_MODBEG:
4148 module->name
4149 = _bfd_vms_save_counted_string (ptr + DST_S_B_MODBEG_NAME);
4151 curr_pc = 0;
4152 prev_pc = 0;
4153 curr_linenum = 0;
4154 prev_linum = 0;
4156 vms_debug2 ((3, "module: %s\n", module->name));
4157 break;
4159 case DST__K_MODEND:
4160 break;
4162 case DST__K_RTNBEG:
4163 funcinfo = (struct funcinfo *)
4164 bfd_zalloc (abfd, sizeof (struct funcinfo));
4165 funcinfo->name
4166 = _bfd_vms_save_counted_string (ptr + DST_S_B_RTNBEG_NAME);
4167 funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
4168 funcinfo->next = module->func_table;
4169 module->func_table = funcinfo;
4171 vms_debug2 ((3, "routine: %s at 0x%lx\n",
4172 funcinfo->name, (unsigned long) funcinfo->low));
4173 break;
4175 case DST__K_RTNEND:
4176 module->func_table->high = module->func_table->low
4177 + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1;
4179 if (module->func_table->high > module->high)
4180 module->high = module->func_table->high;
4182 vms_debug2 ((3, "end routine\n"));
4183 break;
4185 case DST__K_PROLOG:
4186 vms_debug2 ((3, "prologue\n"));
4187 break;
4189 case DST__K_EPILOG:
4190 vms_debug2 ((3, "epilog\n"));
4191 break;
4193 case DST__K_BLKBEG:
4194 vms_debug2 ((3, "block\n"));
4195 break;
4197 case DST__K_BLKEND:
4198 vms_debug2 ((3, "end block\n"));
4199 break;
4201 case DST__K_SOURCE:
4202 src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE;
4204 vms_debug2 ((3, "source info\n"));
4206 while (src_ptr < ptr + rec_length)
4208 int cmd = src_ptr[0], cmd_length, data;
4210 switch (cmd)
4212 case DST__K_SRC_DECLFILE:
4214 unsigned int fileid
4215 = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
4216 char *filename
4217 = _bfd_vms_save_counted_string (src_ptr
4218 + DST_S_B_SRC_DF_FILENAME);
4220 while (fileid >= module->file_table_count)
4222 module->file_table_count *= 2;
4223 module->file_table
4224 = bfd_realloc (module->file_table,
4225 module->file_table_count
4226 * sizeof (struct fileinfo));
4229 module->file_table [fileid].name = filename;
4230 module->file_table [fileid].srec = 1;
4231 cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2;
4232 vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
4233 fileid, module->file_table [fileid].name));
4235 break;
4237 case DST__K_SRC_DEFLINES_B:
4238 /* Perform the association and set the next higher index
4239 to the limit. */
4240 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4241 srec = (struct srecinfo *)
4242 bfd_zalloc (abfd, sizeof (struct srecinfo));
4243 srec->line = curr_srec->line + data;
4244 srec->srec = curr_srec->srec + data;
4245 srec->sfile = curr_srec->sfile;
4246 curr_srec->next = srec;
4247 curr_srec = srec;
4248 cmd_length = 2;
4249 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data));
4250 break;
4252 case DST__K_SRC_DEFLINES_W:
4253 /* Perform the association and set the next higher index
4254 to the limit. */
4255 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4256 srec = (struct srecinfo *)
4257 bfd_zalloc (abfd, sizeof (struct srecinfo));
4258 srec->line = curr_srec->line + data;
4259 srec->srec = curr_srec->srec + data,
4260 srec->sfile = curr_srec->sfile;
4261 curr_srec->next = srec;
4262 curr_srec = srec;
4263 cmd_length = 3;
4264 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data));
4265 break;
4267 case DST__K_SRC_INCRLNUM_B:
4268 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4269 curr_srec->line += data;
4270 cmd_length = 2;
4271 vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data));
4272 break;
4274 case DST__K_SRC_SETFILE:
4275 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4276 curr_srec->sfile = data;
4277 curr_srec->srec = module->file_table[data].srec;
4278 cmd_length = 3;
4279 vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data));
4280 break;
4282 case DST__K_SRC_SETLNUM_L:
4283 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4284 curr_srec->line = data;
4285 cmd_length = 5;
4286 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data));
4287 break;
4289 case DST__K_SRC_SETLNUM_W:
4290 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4291 curr_srec->line = data;
4292 cmd_length = 3;
4293 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data));
4294 break;
4296 case DST__K_SRC_SETREC_L:
4297 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4298 curr_srec->srec = data;
4299 module->file_table[curr_srec->sfile].srec = data;
4300 cmd_length = 5;
4301 vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data));
4302 break;
4304 case DST__K_SRC_SETREC_W:
4305 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4306 curr_srec->srec = data;
4307 module->file_table[curr_srec->sfile].srec = data;
4308 cmd_length = 3;
4309 vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data));
4310 break;
4312 case DST__K_SRC_FORMFEED:
4313 cmd_length = 1;
4314 vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n"));
4315 break;
4317 default:
4318 (*_bfd_error_handler) (_("unknown source command %d"),
4319 cmd);
4320 cmd_length = 2;
4321 break;
4324 src_ptr += cmd_length;
4326 break;
4328 case DST__K_LINE_NUM:
4329 pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE;
4331 vms_debug2 ((3, "line info\n"));
4333 while (pcl_ptr < ptr + rec_length)
4335 /* The command byte is signed so we must sign-extend it. */
4336 int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data;
4338 switch (cmd)
4340 case DST__K_DELTA_PC_W:
4341 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4342 curr_pc += data;
4343 curr_linenum += 1;
4344 cmd_length = 3;
4345 vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data));
4346 break;
4348 case DST__K_DELTA_PC_L:
4349 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4350 curr_pc += data;
4351 curr_linenum += 1;
4352 cmd_length = 5;
4353 vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data));
4354 break;
4356 case DST__K_INCR_LINUM:
4357 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4358 curr_linenum += data;
4359 cmd_length = 2;
4360 vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data));
4361 break;
4363 case DST__K_INCR_LINUM_W:
4364 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4365 curr_linenum += data;
4366 cmd_length = 3;
4367 vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data));
4368 break;
4370 case DST__K_INCR_LINUM_L:
4371 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4372 curr_linenum += data;
4373 cmd_length = 5;
4374 vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data));
4375 break;
4377 case DST__K_SET_LINUM_INCR:
4378 (*_bfd_error_handler)
4379 (_("DST__K_SET_LINUM_INCR not implemented"));
4380 cmd_length = 2;
4381 break;
4383 case DST__K_SET_LINUM_INCR_W:
4384 (*_bfd_error_handler)
4385 (_("DST__K_SET_LINUM_INCR_W not implemented"));
4386 cmd_length = 3;
4387 break;
4389 case DST__K_RESET_LINUM_INCR:
4390 (*_bfd_error_handler)
4391 (_("DST__K_RESET_LINUM_INCR not implemented"));
4392 cmd_length = 1;
4393 break;
4395 case DST__K_BEG_STMT_MODE:
4396 (*_bfd_error_handler)
4397 (_("DST__K_BEG_STMT_MODE not implemented"));
4398 cmd_length = 1;
4399 break;
4401 case DST__K_END_STMT_MODE:
4402 (*_bfd_error_handler)
4403 (_("DST__K_END_STMT_MODE not implemented"));
4404 cmd_length = 1;
4405 break;
4407 case DST__K_SET_LINUM_B:
4408 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4409 curr_linenum = data;
4410 cmd_length = 2;
4411 vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data));
4412 break;
4414 case DST__K_SET_LINUM:
4415 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4416 curr_linenum = data;
4417 cmd_length = 3;
4418 vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data));
4419 break;
4421 case DST__K_SET_LINUM_L:
4422 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4423 curr_linenum = data;
4424 cmd_length = 5;
4425 vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data));
4426 break;
4428 case DST__K_SET_PC:
4429 (*_bfd_error_handler)
4430 (_("DST__K_SET_PC not implemented"));
4431 cmd_length = 2;
4432 break;
4434 case DST__K_SET_PC_W:
4435 (*_bfd_error_handler)
4436 (_("DST__K_SET_PC_W not implemented"));
4437 cmd_length = 3;
4438 break;
4440 case DST__K_SET_PC_L:
4441 (*_bfd_error_handler)
4442 (_("DST__K_SET_PC_L not implemented"));
4443 cmd_length = 5;
4444 break;
4446 case DST__K_SET_STMTNUM:
4447 (*_bfd_error_handler)
4448 (_("DST__K_SET_STMTNUM not implemented"));
4449 cmd_length = 2;
4450 break;
4452 case DST__K_TERM:
4453 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4454 curr_pc += data;
4455 cmd_length = 2;
4456 vms_debug2 ((4, "DST__K_TERM: %d\n", data));
4457 break;
4459 case DST__K_TERM_W:
4460 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4461 curr_pc += data;
4462 cmd_length = 3;
4463 vms_debug2 ((4, "DST__K_TERM_W: %d\n", data));
4464 break;
4466 case DST__K_TERM_L:
4467 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4468 curr_pc += data;
4469 cmd_length = 5;
4470 vms_debug2 ((4, "DST__K_TERM_L: %d\n", data));
4471 break;
4473 case DST__K_SET_ABS_PC:
4474 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4475 curr_pc = data;
4476 cmd_length = 5;
4477 vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data));
4478 break;
4480 default:
4481 if (cmd <= 0)
4483 curr_pc -= cmd;
4484 curr_linenum += 1;
4485 cmd_length = 1;
4486 vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n",
4487 (unsigned long)curr_pc, curr_linenum));
4489 else
4491 (*_bfd_error_handler) (_("unknown line command %d"),
4492 cmd);
4493 cmd_length = 2;
4495 break;
4498 if ((curr_linenum != prev_linum && curr_pc != prev_pc)
4499 || cmd <= 0
4500 || cmd == DST__K_DELTA_PC_L
4501 || cmd == DST__K_DELTA_PC_W)
4503 line = (struct lineinfo *)
4504 bfd_zalloc (abfd, sizeof (struct lineinfo));
4505 line->address = curr_pc;
4506 line->line = curr_linenum;
4508 curr_line->next = line;
4509 curr_line = line;
4511 prev_linum = curr_linenum;
4512 prev_pc = curr_pc;
4513 vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n",
4514 (unsigned long)curr_pc, curr_linenum));
4517 pcl_ptr += cmd_length;
4519 break;
4521 case 0x17: /* Undocumented type used by DEC C to declare equates. */
4522 vms_debug2 ((3, "undocumented type 0x17\n"));
4523 break;
4525 default:
4526 vms_debug2 ((3, "ignoring record\n"));
4527 break;
4531 ptr += rec_length;
4534 /* Finalize tables with EOL marker. */
4535 srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4536 srec->line = (unsigned int) -1;
4537 srec->srec = (unsigned int) -1;
4538 curr_srec->next = srec;
4540 line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4541 line->line = (unsigned int) -1;
4542 line->address = (bfd_vma) -1;
4543 curr_line->next = line;
4545 /* Advertise that this module has been parsed. This is needed
4546 because parsing can be either performed at module creation
4547 or deferred until debug info is consumed. */
4548 SET_MODULE_PARSED (module);
4551 /* Build the list of modules for the specified BFD. */
4553 static struct module *
4554 build_module_list (bfd *abfd)
4556 struct module *module, *list = NULL;
4557 asection *dmt;
4559 if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
4561 /* We have a DMT section so this must be an image. Parse the
4562 section and build the list of modules. This is sufficient
4563 since we can compute the start address and the end address
4564 of every module from the section contents. */
4565 bfd_size_type size = bfd_get_section_size (dmt);
4566 unsigned char *ptr, *end;
4568 ptr = (unsigned char *) bfd_alloc (abfd, size);
4569 if (! ptr)
4570 return NULL;
4572 if (! bfd_get_section_contents (abfd, dmt, ptr, 0, size))
4573 return NULL;
4575 vms_debug2 ((2, "DMT\n"));
4577 end = ptr + size;
4579 while (ptr < end)
4581 /* Each header declares a module with its start offset and size
4582 of debug info in the DST section, as well as the count of
4583 program sections (i.e. address spans) it contains. */
4584 int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
4585 int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
4586 int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
4587 ptr += DBG_S_C_DMT_HEADER_SIZE;
4589 vms_debug2 ((3, "module: modbeg = %d, size = %d, count = %d\n",
4590 modbeg, msize, count));
4592 /* We create a 'module' structure for each program section since
4593 we only support contiguous addresses in a 'module' structure.
4594 As a consequence, the actual debug info in the DST section is
4595 shared and can be parsed multiple times; that doesn't seem to
4596 cause problems in practice. */
4597 while (count-- > 0)
4599 int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
4600 int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
4601 module = new_module (abfd);
4602 module->modbeg = modbeg;
4603 module->size = msize;
4604 module->low = start;
4605 module->high = start + length;
4606 module->next = list;
4607 list = module;
4608 ptr += DBG_S_C_DMT_PSECT_SIZE;
4610 vms_debug2 ((4, "section: start = 0x%x, length = %d\n",
4611 start, length));
4615 else
4617 /* We don't have a DMT section so this must be an object. Parse
4618 the module right now in order to compute its start address and
4619 end address. */
4620 module = new_module (abfd);
4621 parse_module (abfd, module, PRIV (dst_section)->contents, -1);
4622 list = module;
4625 return list;
4628 /* Calculate and return the name of the source file and the line nearest
4629 to the wanted location in the specified module. */
4631 static bfd_boolean
4632 module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
4633 const char **file, const char **func,
4634 unsigned int *line)
4636 struct funcinfo *funcinfo;
4637 struct lineinfo *lineinfo;
4638 struct srecinfo *srecinfo;
4639 bfd_boolean ret = FALSE;
4641 /* Parse this module if that was not done at module creation. */
4642 if (! IS_MODULE_PARSED (module))
4644 unsigned int size = module->size;
4645 unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
4646 unsigned char *buffer = (unsigned char *) bfd_malloc (module->size);
4648 if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
4649 || bfd_bread (buffer, size, abfd) != size)
4651 bfd_set_error (bfd_error_no_debug_section);
4652 return FALSE;
4655 parse_module (abfd, module, buffer, size);
4656 free (buffer);
4659 /* Find out the function (if any) that contains the address. */
4660 for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next)
4661 if (addr >= funcinfo->low && addr <= funcinfo->high)
4663 *func = funcinfo->name;
4664 ret = TRUE;
4665 break;
4668 /* Find out the source file and the line nearest to the address. */
4669 for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
4670 if (lineinfo->next && addr < lineinfo->next->address)
4672 for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
4673 if (srecinfo->next && lineinfo->line < srecinfo->next->line)
4675 if (srecinfo->sfile > 0)
4677 *file = module->file_table[srecinfo->sfile].name;
4678 *line = srecinfo->srec + lineinfo->line - srecinfo->line;
4680 else
4682 *file = module->name;
4683 *line = lineinfo->line;
4685 return TRUE;
4688 break;
4691 return ret;
4694 /* Provided a BFD, a section and an offset into the section, calculate and
4695 return the name of the source file and the line nearest to the wanted
4696 location. */
4698 static bfd_boolean
4699 _bfd_vms_find_nearest_dst_line (bfd *abfd, asection *section,
4700 asymbol **symbols ATTRIBUTE_UNUSED,
4701 bfd_vma offset, const char **file,
4702 const char **func, unsigned int *line)
4704 struct module *module;
4706 /* What address are we looking for? */
4707 bfd_vma addr = section->vma + offset;
4709 *file = NULL;
4710 *func = NULL;
4711 *line = 0;
4713 if (PRIV (dst_section) == NULL || !(abfd->flags & (EXEC_P | DYNAMIC)))
4714 return FALSE;
4716 if (PRIV (modules) == NULL)
4718 PRIV (modules) = build_module_list (abfd);
4719 if (PRIV (modules) == NULL)
4720 return FALSE;
4723 for (module = PRIV (modules); module; module = module->next)
4724 if (addr >= module->low && addr <= module->high)
4725 return module_find_nearest_line (abfd, module, addr, file, func, line);
4727 return FALSE;
4730 /* Canonicalizations. */
4731 /* Set name, value, section and flags of SYM from E. */
4733 static bfd_boolean
4734 alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
4736 flagword flags;
4737 symvalue value;
4738 asection *sec;
4739 const char *name;
4741 name = e->name;
4742 value = 0;
4743 flags = BSF_NO_FLAGS;
4744 sec = NULL;
4746 switch (e->typ)
4748 case EGSD__C_SYM:
4749 if (e->flags & EGSY__V_WEAK)
4750 flags |= BSF_WEAK;
4752 if (e->flags & EGSY__V_DEF)
4754 /* Symbol definition. */
4755 flags |= BSF_GLOBAL;
4756 if (e->flags & EGSY__V_NORM)
4757 flags |= BSF_FUNCTION;
4758 value = e->value;
4759 sec = e->section;
4761 else
4763 /* Symbol reference. */
4764 sec = bfd_und_section_ptr;
4766 break;
4768 case EGSD__C_SYMG:
4769 /* A universal symbol is by definition global... */
4770 flags |= BSF_GLOBAL;
4772 /* ...and dynamic in shared libraries. */
4773 if (abfd->flags & DYNAMIC)
4774 flags |= BSF_DYNAMIC;
4776 if (e->flags & EGSY__V_WEAK)
4777 flags |= BSF_WEAK;
4779 if (!(e->flags & EGSY__V_DEF))
4780 abort ();
4782 if (e->flags & EGSY__V_NORM)
4783 flags |= BSF_FUNCTION;
4785 value = e->value;
4786 /* sec = e->section; */
4787 sec = bfd_abs_section_ptr;
4788 break;
4790 default:
4791 return FALSE;
4794 sym->name = name;
4795 sym->section = sec;
4796 sym->flags = flags;
4797 sym->value = value;
4798 return TRUE;
4802 /* Return the number of bytes required to store a vector of pointers
4803 to asymbols for all the symbols in the BFD abfd, including a
4804 terminal NULL pointer. If there are no symbols in the BFD,
4805 then return 0. If an error occurs, return -1. */
4807 static long
4808 alpha_vms_get_symtab_upper_bound (bfd *abfd)
4810 vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
4811 abfd, PRIV (gsd_sym_count)));
4813 return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
4816 /* Read the symbols from the BFD abfd, and fills in the vector
4817 location with pointers to the symbols and a trailing NULL.
4819 Return number of symbols read. */
4821 static long
4822 alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols)
4824 unsigned int i;
4826 vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
4828 if (PRIV (csymbols) == NULL)
4830 PRIV (csymbols) = (asymbol **) bfd_alloc
4831 (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
4833 /* Traverse table and fill symbols vector. */
4834 for (i = 0; i < PRIV (gsd_sym_count); i++)
4836 struct vms_symbol_entry *e = PRIV (syms)[i];
4837 asymbol *sym;
4839 sym = bfd_make_empty_symbol (abfd);
4840 if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym))
4842 bfd_release (abfd, PRIV (csymbols));
4843 PRIV (csymbols) = NULL;
4844 return -1;
4847 PRIV (csymbols)[i] = sym;
4851 if (symbols != NULL)
4853 for (i = 0; i < PRIV (gsd_sym_count); i++)
4854 symbols[i] = PRIV (csymbols)[i];
4855 symbols[i] = NULL;
4858 return PRIV (gsd_sym_count);
4861 /* Read and convert relocations from ETIR. We do it once for all sections. */
4863 static bfd_boolean
4864 alpha_vms_slurp_relocs (bfd *abfd)
4866 int cur_psect = -1;
4868 vms_debug2 ((3, "alpha_vms_slurp_relocs\n"));
4870 /* We slurp relocs only once, for all sections. */
4871 if (PRIV (reloc_done))
4872 return TRUE;
4873 PRIV (reloc_done) = TRUE;
4875 if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
4876 return FALSE;
4878 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4879 return FALSE;
4881 while (1)
4883 unsigned char *begin;
4884 unsigned char *end;
4885 unsigned char *ptr;
4886 bfd_reloc_code_real_type reloc_code;
4887 int type;
4888 bfd_vma vaddr = 0;
4890 int length;
4892 bfd_vma cur_address;
4893 int cur_psidx = -1;
4894 unsigned char *cur_sym = NULL;
4895 int prev_cmd = -1;
4896 bfd_vma cur_addend = 0;
4898 /* Skip non-ETIR records. */
4899 type = _bfd_vms_get_object_record (abfd);
4900 if (type == EOBJ__C_EEOM)
4901 break;
4902 if (type != EOBJ__C_ETIR)
4903 continue;
4905 begin = PRIV (recrd.rec) + 4;
4906 end = PRIV (recrd.rec) + PRIV (recrd.rec_size);
4908 for (ptr = begin; ptr < end; ptr += length)
4910 int cmd;
4912 cmd = bfd_getl16 (ptr);
4913 length = bfd_getl16 (ptr + 2);
4915 cur_address = vaddr;
4917 vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n",
4918 _bfd_vms_etir_name (cmd)));
4920 switch (cmd)
4922 case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */
4923 /* ALPHA_R_REFQUAD und_section, step 1 */
4924 cur_sym = ptr + 4;
4925 prev_cmd = cmd;
4926 continue;
4928 case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */
4929 cur_psidx = bfd_getl32 (ptr + 4);
4930 cur_addend = bfd_getl64 (ptr + 8);
4931 prev_cmd = cmd;
4932 continue;
4934 case ETIR__C_CTL_SETRB:
4935 if (prev_cmd != ETIR__C_STA_PQ)
4937 (*_bfd_error_handler)
4938 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
4939 _bfd_vms_etir_name (cmd));
4940 return FALSE;
4942 cur_psect = cur_psidx;
4943 vaddr = cur_addend;
4944 cur_psidx = -1;
4945 cur_addend = 0;
4946 continue;
4948 case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */
4949 /* ALPHA_R_REFLONG und_section, step 2 */
4950 if (prev_cmd != -1)
4952 if (prev_cmd != ETIR__C_STA_GBL)
4954 (*_bfd_error_handler)
4955 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
4956 _bfd_vms_etir_name (ETIR__C_STA_LW));
4957 return FALSE;
4960 cur_addend = bfd_getl32 (ptr + 4);
4961 prev_cmd = cmd;
4962 continue;
4964 case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */
4965 /* ALPHA_R_REFQUAD und_section, step 2 */
4966 if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL)
4968 (*_bfd_error_handler)
4969 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
4970 _bfd_vms_etir_name (ETIR__C_STA_QW));
4971 return FALSE;
4973 cur_addend = bfd_getl64 (ptr + 4);
4974 prev_cmd = cmd;
4975 continue;
4977 case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */
4978 /* ALPHA_R_REFLONG abs_section, step 2 */
4979 /* ALPHA_R_REFLONG others, step 2 */
4980 if (prev_cmd != ETIR__C_OPR_ADD
4981 && prev_cmd != ETIR__C_STA_LW
4982 && prev_cmd != ETIR__C_STA_PQ)
4984 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4985 _bfd_vms_etir_name (prev_cmd),
4986 _bfd_vms_etir_name (ETIR__C_STO_LW));
4987 return FALSE;
4989 reloc_code = BFD_RELOC_32;
4990 break;
4992 case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */
4993 /* ALPHA_R_REFQUAD abs_section, step 2 */
4994 if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW)
4996 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4997 _bfd_vms_etir_name (prev_cmd),
4998 _bfd_vms_etir_name (ETIR__C_STO_QW));
4999 return FALSE;
5001 reloc_code = BFD_RELOC_64;
5002 break;
5004 case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */
5005 if (prev_cmd != ETIR__C_STA_PQ)
5007 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
5008 _bfd_vms_etir_name (prev_cmd),
5009 _bfd_vms_etir_name (ETIR__C_STO_OFF));
5010 return FALSE;
5012 reloc_code = BFD_RELOC_64;
5013 break;
5015 case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */
5016 /* ALPHA_R_REFQUAD und_section, step 3 */
5017 if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW)
5019 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
5020 _bfd_vms_etir_name (prev_cmd),
5021 _bfd_vms_etir_name (ETIR__C_OPR_ADD));
5022 return FALSE;
5024 prev_cmd = ETIR__C_OPR_ADD;
5025 continue;
5027 case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */
5028 reloc_code = BFD_RELOC_ALPHA_CODEADDR;
5029 cur_sym = ptr + 4;
5030 break;
5032 case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */
5033 reloc_code = BFD_RELOC_64;
5034 cur_sym = ptr + 4;
5035 break;
5037 case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */
5038 reloc_code = BFD_RELOC_32;
5039 cur_sym = ptr + 4;
5040 break;
5042 case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */
5043 reloc_code = BFD_RELOC_ALPHA_LINKAGE;
5044 cur_sym = ptr + 8;
5045 break;
5047 case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */
5048 reloc_code = BFD_RELOC_ALPHA_NOP;
5049 goto call_reloc;
5051 case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */
5052 reloc_code = BFD_RELOC_ALPHA_BSR;
5053 goto call_reloc;
5055 case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */
5056 reloc_code = BFD_RELOC_ALPHA_LDA;
5057 goto call_reloc;
5059 case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */
5060 reloc_code = BFD_RELOC_ALPHA_BOH;
5061 goto call_reloc;
5063 call_reloc:
5064 cur_sym = ptr + 4 + 32;
5065 cur_address = bfd_getl64 (ptr + 4 + 8);
5066 cur_addend = bfd_getl64 (ptr + 4 + 24);
5067 break;
5069 case ETIR__C_STO_IMM:
5070 vaddr += bfd_getl32 (ptr + 4);
5071 continue;
5073 default:
5074 (*_bfd_error_handler) (_("Unknown reloc %s"),
5075 _bfd_vms_etir_name (cmd));
5076 return FALSE;
5080 asection *sec;
5081 struct vms_section_data_struct *vms_sec;
5082 arelent *reloc;
5084 /* Get section to which the relocation applies. */
5085 if (cur_psect < 0 || cur_psect > (int)PRIV (section_count))
5087 (*_bfd_error_handler) (_("Invalid section index in ETIR"));
5088 return FALSE;
5090 sec = PRIV (sections)[cur_psect];
5091 vms_sec = vms_section_data (sec);
5093 /* Allocate a reloc entry. */
5094 if (sec->reloc_count >= vms_sec->reloc_max)
5096 if (vms_sec->reloc_max == 0)
5098 vms_sec->reloc_max = 64;
5099 sec->relocation = bfd_zmalloc
5100 (vms_sec->reloc_max * sizeof (arelent));
5102 else
5104 vms_sec->reloc_max *= 2;
5105 sec->relocation = bfd_realloc
5106 (sec->relocation, vms_sec->reloc_max * sizeof (arelent));
5109 reloc = &sec->relocation[sec->reloc_count];
5110 sec->reloc_count++;
5112 reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code);
5114 if (cur_sym != NULL)
5116 unsigned int j;
5117 unsigned int symlen = *cur_sym;
5118 asymbol **sym;
5120 /* Linear search. */
5121 symlen = *cur_sym;
5122 cur_sym++;
5123 sym = NULL;
5125 for (j = 0; j < PRIV (gsd_sym_count); j++)
5126 if (PRIV (syms)[j]->namelen == symlen
5127 && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0)
5129 sym = &PRIV (csymbols)[j];
5130 break;
5132 if (sym == NULL)
5134 (*_bfd_error_handler) (_("Unknown symbol in command %s"),
5135 _bfd_vms_etir_name (cmd));
5136 reloc->sym_ptr_ptr = NULL;
5138 else
5139 reloc->sym_ptr_ptr = sym;
5141 else if (cur_psidx >= 0)
5142 reloc->sym_ptr_ptr =
5143 PRIV (sections)[cur_psidx]->symbol_ptr_ptr;
5144 else
5145 reloc->sym_ptr_ptr = NULL;
5147 reloc->address = cur_address;
5148 reloc->addend = cur_addend;
5150 vaddr += bfd_get_reloc_size (reloc->howto);
5153 cur_addend = 0;
5154 prev_cmd = -1;
5155 cur_sym = NULL;
5156 cur_psidx = -1;
5159 vms_debug2 ((3, "alpha_vms_slurp_relocs: result = TRUE\n"));
5161 return TRUE;
5164 /* Return the number of bytes required to store the relocation
5165 information associated with the given section. */
5167 static long
5168 alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section)
5170 alpha_vms_slurp_relocs (abfd);
5172 return (section->reloc_count + 1) * sizeof (arelent *);
5175 /* Convert relocations from VMS (external) form into BFD internal
5176 form. Return the number of relocations. */
5178 static long
5179 alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr,
5180 asymbol **symbols ATTRIBUTE_UNUSED)
5182 arelent *tblptr;
5183 int count;
5185 if (!alpha_vms_slurp_relocs (abfd))
5186 return -1;
5188 count = section->reloc_count;
5189 tblptr = section->relocation;
5191 while (count--)
5192 *relptr++ = tblptr++;
5194 *relptr = (arelent *) NULL;
5195 return section->reloc_count;
5198 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
5200 /* How to process the various reloc types. */
5202 static bfd_reloc_status_type
5203 reloc_nil (bfd * abfd ATTRIBUTE_UNUSED,
5204 arelent *reloc ATTRIBUTE_UNUSED,
5205 asymbol *sym ATTRIBUTE_UNUSED,
5206 void * data ATTRIBUTE_UNUSED,
5207 asection *sec ATTRIBUTE_UNUSED,
5208 bfd *output_bfd ATTRIBUTE_UNUSED,
5209 char **error_message ATTRIBUTE_UNUSED)
5211 #if VMS_DEBUG
5212 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd);
5213 vms_debug (2, "In section %s, symbol %s\n",
5214 sec->name, sym->name);
5215 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
5216 reloc->sym_ptr_ptr[0]->name,
5217 (unsigned long)reloc->address,
5218 (unsigned long)reloc->addend, reloc->howto->name);
5219 vms_debug (2, "data at %p\n", data);
5220 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
5221 #endif
5223 return bfd_reloc_ok;
5226 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
5227 from smaller values. Start with zero, widen, *then* decrement. */
5228 #define MINUS_ONE (((bfd_vma)0) - 1)
5230 static reloc_howto_type alpha_howto_table[] =
5232 HOWTO (ALPHA_R_IGNORE, /* Type. */
5233 0, /* Rightshift. */
5234 0, /* Size (0 = byte, 1 = short, 2 = long). */
5235 8, /* Bitsize. */
5236 TRUE, /* PC relative. */
5237 0, /* Bitpos. */
5238 complain_overflow_dont,/* Complain_on_overflow. */
5239 reloc_nil, /* Special_function. */
5240 "IGNORE", /* Name. */
5241 TRUE, /* Partial_inplace. */
5242 0, /* Source mask */
5243 0, /* Dest mask. */
5244 TRUE), /* PC rel offset. */
5246 /* A 64 bit reference to a symbol. */
5247 HOWTO (ALPHA_R_REFQUAD, /* Type. */
5248 0, /* Rightshift. */
5249 4, /* Size (0 = byte, 1 = short, 2 = long). */
5250 64, /* Bitsize. */
5251 FALSE, /* PC relative. */
5252 0, /* Bitpos. */
5253 complain_overflow_bitfield, /* Complain_on_overflow. */
5254 reloc_nil, /* Special_function. */
5255 "REFQUAD", /* Name. */
5256 TRUE, /* Partial_inplace. */
5257 MINUS_ONE, /* Source mask. */
5258 MINUS_ONE, /* Dest mask. */
5259 FALSE), /* PC rel offset. */
5261 /* A 21 bit branch. The native assembler generates these for
5262 branches within the text segment, and also fills in the PC
5263 relative offset in the instruction. */
5264 HOWTO (ALPHA_R_BRADDR, /* Type. */
5265 2, /* Rightshift. */
5266 2, /* Size (0 = byte, 1 = short, 2 = long). */
5267 21, /* Bitsize. */
5268 TRUE, /* PC relative. */
5269 0, /* Bitpos. */
5270 complain_overflow_signed, /* Complain_on_overflow. */
5271 reloc_nil, /* Special_function. */
5272 "BRADDR", /* Name. */
5273 TRUE, /* Partial_inplace. */
5274 0x1fffff, /* Source mask. */
5275 0x1fffff, /* Dest mask. */
5276 FALSE), /* PC rel offset. */
5278 /* A hint for a jump to a register. */
5279 HOWTO (ALPHA_R_HINT, /* Type. */
5280 2, /* Rightshift. */
5281 1, /* Size (0 = byte, 1 = short, 2 = long). */
5282 14, /* Bitsize. */
5283 TRUE, /* PC relative. */
5284 0, /* Bitpos. */
5285 complain_overflow_dont,/* Complain_on_overflow. */
5286 reloc_nil, /* Special_function. */
5287 "HINT", /* Name. */
5288 TRUE, /* Partial_inplace. */
5289 0x3fff, /* Source mask. */
5290 0x3fff, /* Dest mask. */
5291 FALSE), /* PC rel offset. */
5293 /* 16 bit PC relative offset. */
5294 HOWTO (ALPHA_R_SREL16, /* Type. */
5295 0, /* Rightshift. */
5296 1, /* Size (0 = byte, 1 = short, 2 = long). */
5297 16, /* Bitsize. */
5298 TRUE, /* PC relative. */
5299 0, /* Bitpos. */
5300 complain_overflow_signed, /* Complain_on_overflow. */
5301 reloc_nil, /* Special_function. */
5302 "SREL16", /* Name. */
5303 TRUE, /* Partial_inplace. */
5304 0xffff, /* Source mask. */
5305 0xffff, /* Dest mask. */
5306 FALSE), /* PC rel offset. */
5308 /* 32 bit PC relative offset. */
5309 HOWTO (ALPHA_R_SREL32, /* Type. */
5310 0, /* Rightshift. */
5311 2, /* Size (0 = byte, 1 = short, 2 = long). */
5312 32, /* Bitsize. */
5313 TRUE, /* PC relative. */
5314 0, /* Bitpos. */
5315 complain_overflow_signed, /* Complain_on_overflow. */
5316 reloc_nil, /* Special_function. */
5317 "SREL32", /* Name. */
5318 TRUE, /* Partial_inplace. */
5319 0xffffffff, /* Source mask. */
5320 0xffffffff, /* Dest mask. */
5321 FALSE), /* PC rel offset. */
5323 /* A 64 bit PC relative offset. */
5324 HOWTO (ALPHA_R_SREL64, /* Type. */
5325 0, /* Rightshift. */
5326 4, /* Size (0 = byte, 1 = short, 2 = long). */
5327 64, /* Bitsize. */
5328 TRUE, /* PC relative. */
5329 0, /* Bitpos. */
5330 complain_overflow_signed, /* Complain_on_overflow. */
5331 reloc_nil, /* Special_function. */
5332 "SREL64", /* Name. */
5333 TRUE, /* Partial_inplace. */
5334 MINUS_ONE, /* Source mask. */
5335 MINUS_ONE, /* Dest mask. */
5336 FALSE), /* PC rel offset. */
5338 /* Push a value on the reloc evaluation stack. */
5339 HOWTO (ALPHA_R_OP_PUSH, /* Type. */
5340 0, /* Rightshift. */
5341 0, /* Size (0 = byte, 1 = short, 2 = long). */
5342 0, /* Bitsize. */
5343 FALSE, /* PC relative. */
5344 0, /* Bitpos. */
5345 complain_overflow_dont,/* Complain_on_overflow. */
5346 reloc_nil, /* Special_function. */
5347 "OP_PUSH", /* Name. */
5348 FALSE, /* Partial_inplace. */
5349 0, /* Source mask. */
5350 0, /* Dest mask. */
5351 FALSE), /* PC rel offset. */
5353 /* Store the value from the stack at the given address. Store it in
5354 a bitfield of size r_size starting at bit position r_offset. */
5355 HOWTO (ALPHA_R_OP_STORE, /* Type. */
5356 0, /* Rightshift. */
5357 4, /* Size (0 = byte, 1 = short, 2 = long). */
5358 64, /* Bitsize. */
5359 FALSE, /* PC relative. */
5360 0, /* Bitpos. */
5361 complain_overflow_dont,/* Complain_on_overflow. */
5362 reloc_nil, /* Special_function. */
5363 "OP_STORE", /* Name. */
5364 FALSE, /* Partial_inplace. */
5365 0, /* Source mask. */
5366 MINUS_ONE, /* Dest mask. */
5367 FALSE), /* PC rel offset. */
5369 /* Subtract the reloc address from the value on the top of the
5370 relocation stack. */
5371 HOWTO (ALPHA_R_OP_PSUB, /* Type. */
5372 0, /* Rightshift. */
5373 0, /* Size (0 = byte, 1 = short, 2 = long). */
5374 0, /* Bitsize. */
5375 FALSE, /* PC relative. */
5376 0, /* Bitpos. */
5377 complain_overflow_dont,/* Complain_on_overflow. */
5378 reloc_nil, /* Special_function. */
5379 "OP_PSUB", /* Name. */
5380 FALSE, /* Partial_inplace. */
5381 0, /* Source mask. */
5382 0, /* Dest mask. */
5383 FALSE), /* PC rel offset. */
5385 /* Shift the value on the top of the relocation stack right by the
5386 given value. */
5387 HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */
5388 0, /* Rightshift. */
5389 0, /* Size (0 = byte, 1 = short, 2 = long). */
5390 0, /* Bitsize. */
5391 FALSE, /* PC relative. */
5392 0, /* Bitpos. */
5393 complain_overflow_dont,/* Complain_on_overflow. */
5394 reloc_nil, /* Special_function. */
5395 "OP_PRSHIFT", /* Name. */
5396 FALSE, /* Partial_inplace. */
5397 0, /* Source mask. */
5398 0, /* Dest mask. */
5399 FALSE), /* PC rel offset. */
5401 /* Hack. Linkage is done by linker. */
5402 HOWTO (ALPHA_R_LINKAGE, /* Type. */
5403 0, /* Rightshift. */
5404 8, /* Size (0 = byte, 1 = short, 2 = long). */
5405 256, /* Bitsize. */
5406 FALSE, /* PC relative. */
5407 0, /* Bitpos. */
5408 complain_overflow_dont,/* Complain_on_overflow. */
5409 reloc_nil, /* Special_function. */
5410 "LINKAGE", /* Name. */
5411 FALSE, /* Partial_inplace. */
5412 0, /* Source mask. */
5413 0, /* Dest mask. */
5414 FALSE), /* PC rel offset. */
5416 /* A 32 bit reference to a symbol. */
5417 HOWTO (ALPHA_R_REFLONG, /* Type. */
5418 0, /* Rightshift. */
5419 2, /* Size (0 = byte, 1 = short, 2 = long). */
5420 32, /* Bitsize. */
5421 FALSE, /* PC relative. */
5422 0, /* Bitpos. */
5423 complain_overflow_bitfield, /* Complain_on_overflow. */
5424 reloc_nil, /* Special_function. */
5425 "REFLONG", /* Name. */
5426 TRUE, /* Partial_inplace. */
5427 0xffffffff, /* Source mask. */
5428 0xffffffff, /* Dest mask. */
5429 FALSE), /* PC rel offset. */
5431 /* A 64 bit reference to a procedure, written as 32 bit value. */
5432 HOWTO (ALPHA_R_CODEADDR, /* Type. */
5433 0, /* Rightshift. */
5434 4, /* Size (0 = byte, 1 = short, 2 = long). */
5435 64, /* Bitsize. */
5436 FALSE, /* PC relative. */
5437 0, /* Bitpos. */
5438 complain_overflow_signed,/* Complain_on_overflow. */
5439 reloc_nil, /* Special_function. */
5440 "CODEADDR", /* Name. */
5441 FALSE, /* Partial_inplace. */
5442 0xffffffff, /* Source mask. */
5443 0xffffffff, /* Dest mask. */
5444 FALSE), /* PC rel offset. */
5446 HOWTO (ALPHA_R_NOP, /* Type. */
5447 0, /* Rightshift. */
5448 3, /* Size (0 = byte, 1 = short, 2 = long). */
5449 0, /* Bitsize. */
5450 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
5451 because the calculations for the 3 relocations are the same.
5452 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
5453 TRUE, /* PC relative. */
5454 0, /* Bitpos. */
5455 complain_overflow_dont,/* Complain_on_overflow. */
5456 reloc_nil, /* Special_function. */
5457 "NOP", /* Name. */
5458 FALSE, /* Partial_inplace. */
5459 0xffffffff, /* Source mask. */
5460 0xffffffff, /* Dest mask. */
5461 FALSE), /* PC rel offset. */
5463 HOWTO (ALPHA_R_BSR, /* Type. */
5464 0, /* Rightshift. */
5465 3, /* Size (0 = byte, 1 = short, 2 = long). */
5466 0, /* Bitsize. */
5467 TRUE, /* PC relative. */
5468 0, /* Bitpos. */
5469 complain_overflow_dont,/* Complain_on_overflow. */
5470 reloc_nil, /* Special_function. */
5471 "BSR", /* Name. */
5472 FALSE, /* Partial_inplace. */
5473 0xffffffff, /* Source mask. */
5474 0xffffffff, /* Dest mask. */
5475 FALSE), /* PC rel offset. */
5477 HOWTO (ALPHA_R_LDA, /* Type. */
5478 0, /* Rightshift. */
5479 3, /* Size (0 = byte, 1 = short, 2 = long). */
5480 0, /* Bitsize. */
5481 FALSE, /* PC relative. */
5482 0, /* Bitpos. */
5483 complain_overflow_dont,/* Complain_on_overflow. */
5484 reloc_nil, /* Special_function. */
5485 "LDA", /* Name. */
5486 FALSE, /* Partial_inplace. */
5487 0xffffffff, /* Source mask. */
5488 0xffffffff, /* Dest mask. */
5489 FALSE), /* PC rel offset. */
5491 HOWTO (ALPHA_R_BOH, /* Type. */
5492 0, /* Rightshift. */
5493 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
5494 0, /* Bitsize. */
5495 TRUE, /* PC relative. */
5496 0, /* Bitpos. */
5497 complain_overflow_dont,/* Complain_on_overflow. */
5498 reloc_nil, /* Special_function. */
5499 "BOH", /* Name. */
5500 FALSE, /* Partial_inplace. */
5501 0xffffffff, /* Source mask. */
5502 0xffffffff, /* Dest mask. */
5503 FALSE), /* PC rel offset. */
5506 /* Return a pointer to a howto structure which, when invoked, will perform
5507 the relocation code on data from the architecture noted. */
5509 static const struct reloc_howto_struct *
5510 alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
5511 bfd_reloc_code_real_type code)
5513 int alpha_type;
5515 vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code));
5517 switch (code)
5519 case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break;
5520 case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break;
5521 case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break;
5522 case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break;
5523 case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break;
5524 case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break;
5525 case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break;
5526 case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break;
5527 case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break;
5528 case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break;
5529 case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break;
5530 case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break;
5531 case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break;
5532 case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break;
5533 case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break;
5534 default:
5535 (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code);
5536 return NULL;
5538 vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name));
5539 return & alpha_howto_table[alpha_type];
5542 static reloc_howto_type *
5543 alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
5544 const char *r_name)
5546 unsigned int i;
5548 for (i = 0;
5549 i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
5550 i++)
5551 if (alpha_howto_table[i].name != NULL
5552 && strcasecmp (alpha_howto_table[i].name, r_name) == 0)
5553 return &alpha_howto_table[i];
5555 return NULL;
5558 static long
5559 alpha_vms_get_synthetic_symtab (bfd *abfd,
5560 long symcount ATTRIBUTE_UNUSED,
5561 asymbol **usyms ATTRIBUTE_UNUSED,
5562 long dynsymcount ATTRIBUTE_UNUSED,
5563 asymbol **dynsyms ATTRIBUTE_UNUSED,
5564 asymbol **ret)
5566 asymbol *syms;
5567 unsigned int i;
5568 unsigned int n = 0;
5570 syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
5571 *ret = syms;
5572 if (syms == NULL)
5573 return -1;
5575 for (i = 0; i < PRIV (gsd_sym_count); i++)
5577 struct vms_symbol_entry *e = PRIV (syms)[i];
5578 asymbol *sym;
5579 flagword flags;
5580 symvalue value;
5581 asection *sec;
5582 const char *name;
5583 char *sname;
5584 int l;
5586 name = e->name;
5587 value = 0;
5588 flags = BSF_LOCAL | BSF_SYNTHETIC;
5589 sec = NULL;
5591 switch (e->typ)
5593 case EGSD__C_SYM:
5594 case EGSD__C_SYMG:
5595 if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM))
5597 value = e->code_value;
5598 sec = e->code_section;
5600 else
5601 continue;
5602 break;
5604 default:
5605 continue;
5608 l = strlen (name);
5609 sname = bfd_alloc (abfd, l + 5);
5610 if (sname == NULL)
5611 return FALSE;
5612 memcpy (sname, name, l);
5613 memcpy (sname + l, "..en", 5);
5615 sym = &syms[n++];
5616 sym->name = sname;
5617 sym->section = sec;
5618 sym->flags = flags;
5619 sym->value = value;
5620 sym->udata.p = NULL;
5623 return n;
5626 /* Private dump. */
5628 static const char *
5629 vms_time_to_str (unsigned char *buf)
5631 time_t t = vms_rawtime_to_time_t (buf);
5632 char *res = ctime (&t);
5634 if (!res)
5635 res = "*invalid time*";
5636 else
5637 res[24] = 0;
5638 return res;
5641 static void
5642 evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len)
5644 struct vms_emh_common *emh = (struct vms_emh_common *)rec;
5645 unsigned int subtype;
5647 subtype = (unsigned)bfd_getl16 (emh->subtyp);
5649 fprintf (file, _(" EMH %u (len=%u): "), subtype, rec_len);
5651 switch (subtype)
5653 case EMH__C_MHD:
5655 struct vms_emh_mhd *mhd = (struct vms_emh_mhd *)rec;
5656 const char *name;
5658 fprintf (file, _("Module header\n"));
5659 fprintf (file, _(" structure level: %u\n"), mhd->strlvl);
5660 fprintf (file, _(" max record size: %u\n"),
5661 (unsigned)bfd_getl32 (mhd->recsiz));
5662 name = (char *)(mhd + 1);
5663 fprintf (file, _(" module name : %.*s\n"), name[0], name + 1);
5664 name += name[0] + 1;
5665 fprintf (file, _(" module version : %.*s\n"), name[0], name + 1);
5666 name += name[0] + 1;
5667 fprintf (file, _(" compile date : %.17s\n"), name);
5669 break;
5670 case EMH__C_LNM:
5672 fprintf (file, _("Language Processor Name\n"));
5673 fprintf (file, _(" language name: %.*s\n"),
5674 (int)(rec_len - sizeof (struct vms_emh_common)),
5675 (char *)rec + sizeof (struct vms_emh_common));
5677 break;
5678 case EMH__C_SRC:
5680 fprintf (file, _("Source Files Header\n"));
5681 fprintf (file, _(" file: %.*s\n"),
5682 (int)(rec_len - sizeof (struct vms_emh_common)),
5683 (char *)rec + sizeof (struct vms_emh_common));
5685 break;
5686 case EMH__C_TTL:
5688 fprintf (file, _("Title Text Header\n"));
5689 fprintf (file, _(" title: %.*s\n"),
5690 (int)(rec_len - sizeof (struct vms_emh_common)),
5691 (char *)rec + sizeof (struct vms_emh_common));
5693 break;
5694 case EMH__C_CPR:
5696 fprintf (file, _("Copyright Header\n"));
5697 fprintf (file, _(" copyright: %.*s\n"),
5698 (int)(rec_len - sizeof (struct vms_emh_common)),
5699 (char *)rec + sizeof (struct vms_emh_common));
5701 break;
5702 default:
5703 fprintf (file, _("unhandled emh subtype %u\n"), subtype);
5704 break;
5708 static void
5709 evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len)
5711 struct vms_eeom *eeom = (struct vms_eeom *)rec;
5713 fprintf (file, _(" EEOM (len=%u):\n"), rec_len);
5714 fprintf (file, _(" number of cond linkage pairs: %u\n"),
5715 (unsigned)bfd_getl32 (eeom->total_lps));
5716 fprintf (file, _(" completion code: %u\n"),
5717 (unsigned)bfd_getl16 (eeom->comcod));
5718 if (rec_len > 10)
5720 fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg);
5721 fprintf (file, _(" transfer addr psect: %u\n"),
5722 (unsigned)bfd_getl32 (eeom->psindx));
5723 fprintf (file, _(" transfer address : 0x%08x\n"),
5724 (unsigned)bfd_getl32 (eeom->tfradr));
5728 static void
5729 exav_bfd_print_egsy_flags (unsigned int flags, FILE *file)
5731 if (flags & EGSY__V_WEAK)
5732 fputs (_(" WEAK"), file);
5733 if (flags & EGSY__V_DEF)
5734 fputs (_(" DEF"), file);
5735 if (flags & EGSY__V_UNI)
5736 fputs (_(" UNI"), file);
5737 if (flags & EGSY__V_REL)
5738 fputs (_(" REL"), file);
5739 if (flags & EGSY__V_COMM)
5740 fputs (_(" COMM"), file);
5741 if (flags & EGSY__V_VECEP)
5742 fputs (_(" VECEP"), file);
5743 if (flags & EGSY__V_NORM)
5744 fputs (_(" NORM"), file);
5745 if (flags & EGSY__V_QUAD_VAL)
5746 fputs (_(" QVAL"), file);
5749 static void
5750 evax_bfd_print_egsd_flags (FILE *file, unsigned int flags)
5752 if (flags & EGPS__V_PIC)
5753 fputs (_(" PIC"), file);
5754 if (flags & EGPS__V_LIB)
5755 fputs (_(" LIB"), file);
5756 if (flags & EGPS__V_OVR)
5757 fputs (_(" OVR"), file);
5758 if (flags & EGPS__V_REL)
5759 fputs (_(" REL"), file);
5760 if (flags & EGPS__V_GBL)
5761 fputs (_(" GBL"), file);
5762 if (flags & EGPS__V_SHR)
5763 fputs (_(" SHR"), file);
5764 if (flags & EGPS__V_EXE)
5765 fputs (_(" EXE"), file);
5766 if (flags & EGPS__V_RD)
5767 fputs (_(" RD"), file);
5768 if (flags & EGPS__V_WRT)
5769 fputs (_(" WRT"), file);
5770 if (flags & EGPS__V_VEC)
5771 fputs (_(" VEC"), file);
5772 if (flags & EGPS__V_NOMOD)
5773 fputs (_(" NOMOD"), file);
5774 if (flags & EGPS__V_COM)
5775 fputs (_(" COM"), file);
5776 if (flags & EGPS__V_ALLOC_64BIT)
5777 fputs (_(" 64B"), file);
5780 static void
5781 evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len)
5783 unsigned int off = sizeof (struct vms_egsd);
5784 unsigned int n;
5786 fprintf (file, _(" EGSD (len=%u):\n"), rec_len);
5788 n = 0;
5789 for (off = sizeof (struct vms_egsd); off < rec_len; )
5791 struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off);
5792 unsigned int type;
5793 unsigned int len;
5795 type = (unsigned)bfd_getl16 (e->gsdtyp);
5796 len = (unsigned)bfd_getl16 (e->gsdsiz);
5798 fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "),
5799 n, type, len);
5800 n++;
5802 switch (type)
5804 case EGSD__C_PSC:
5806 struct vms_egps *egps = (struct vms_egps *)e;
5807 unsigned int flags = bfd_getl16 (egps->flags);
5808 unsigned int l;
5810 fprintf (file, _("PSC - Program section definition\n"));
5811 fprintf (file, _(" alignment : 2**%u\n"), egps->align);
5812 fprintf (file, _(" flags : 0x%04x"), flags);
5813 evax_bfd_print_egsd_flags (file, flags);
5814 fputc ('\n', file);
5815 l = bfd_getl32 (egps->alloc);
5816 fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l);
5817 fprintf (file, _(" name : %.*s\n"),
5818 egps->namlng, egps->name);
5820 break;
5821 case EGSD__C_SPSC:
5823 struct vms_esgps *esgps = (struct vms_esgps *)e;
5824 unsigned int flags = bfd_getl16 (esgps->flags);
5825 unsigned int l;
5827 fprintf (file, _("SPSC - Shared Image Program section def\n"));
5828 fprintf (file, _(" alignment : 2**%u\n"), esgps->align);
5829 fprintf (file, _(" flags : 0x%04x"), flags);
5830 evax_bfd_print_egsd_flags (file, flags);
5831 fputc ('\n', file);
5832 l = bfd_getl32 (esgps->alloc);
5833 fprintf (file, _(" alloc (len) : %u (0x%08x)\n"), l, l);
5834 fprintf (file, _(" image offset : 0x%08x\n"),
5835 (unsigned int)bfd_getl32 (esgps->base));
5836 fprintf (file, _(" symvec offset : 0x%08x\n"),
5837 (unsigned int)bfd_getl32 (esgps->value));
5838 fprintf (file, _(" name : %.*s\n"),
5839 esgps->namlng, esgps->name);
5841 break;
5842 case EGSD__C_SYM:
5844 struct vms_egsy *egsy = (struct vms_egsy *)e;
5845 unsigned int flags = bfd_getl16 (egsy->flags);
5847 if (flags & EGSY__V_DEF)
5849 struct vms_esdf *esdf = (struct vms_esdf *)e;
5851 fprintf (file, _("SYM - Global symbol definition\n"));
5852 fprintf (file, _(" flags: 0x%04x"), flags);
5853 exav_bfd_print_egsy_flags (flags, file);
5854 fputc ('\n', file);
5855 fprintf (file, _(" psect offset: 0x%08x\n"),
5856 (unsigned)bfd_getl32 (esdf->value));
5857 if (flags & EGSY__V_NORM)
5859 fprintf (file, _(" code address: 0x%08x\n"),
5860 (unsigned)bfd_getl32 (esdf->code_address));
5861 fprintf (file, _(" psect index for entry point : %u\n"),
5862 (unsigned)bfd_getl32 (esdf->ca_psindx));
5864 fprintf (file, _(" psect index : %u\n"),
5865 (unsigned)bfd_getl32 (esdf->psindx));
5866 fprintf (file, _(" name : %.*s\n"),
5867 esdf->namlng, esdf->name);
5869 else
5871 struct vms_esrf *esrf = (struct vms_esrf *)e;
5873 fprintf (file, _("SYM - Global symbol reference\n"));
5874 fprintf (file, _(" name : %.*s\n"),
5875 esrf->namlng, esrf->name);
5878 break;
5879 case EGSD__C_IDC:
5881 struct vms_eidc *eidc = (struct vms_eidc *)e;
5882 unsigned int flags = bfd_getl32 (eidc->flags);
5883 unsigned char *p;
5885 fprintf (file, _("IDC - Ident Consistency check\n"));
5886 fprintf (file, _(" flags : 0x%08x"), flags);
5887 if (flags & EIDC__V_BINIDENT)
5888 fputs (" BINDENT", file);
5889 fputc ('\n', file);
5890 fprintf (file, _(" id match : %x\n"),
5891 (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK);
5892 fprintf (file, _(" error severity: %x\n"),
5893 (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK);
5894 p = eidc->name;
5895 fprintf (file, _(" entity name : %.*s\n"), p[0], p + 1);
5896 p += 1 + p[0];
5897 fprintf (file, _(" object name : %.*s\n"), p[0], p + 1);
5898 p += 1 + p[0];
5899 if (flags & EIDC__V_BINIDENT)
5900 fprintf (file, _(" binary ident : 0x%08x\n"),
5901 (unsigned)bfd_getl32 (p + 1));
5902 else
5903 fprintf (file, _(" ascii ident : %.*s\n"), p[0], p + 1);
5905 break;
5906 case EGSD__C_SYMG:
5908 struct vms_egst *egst = (struct vms_egst *)e;
5909 unsigned int flags = bfd_getl16 (egst->header.flags);
5911 fprintf (file, _("SYMG - Universal symbol definition\n"));
5912 fprintf (file, _(" flags: 0x%04x"), flags);
5913 exav_bfd_print_egsy_flags (flags, file);
5914 fputc ('\n', file);
5915 fprintf (file, _(" symbol vector offset: 0x%08x\n"),
5916 (unsigned)bfd_getl32 (egst->value));
5917 fprintf (file, _(" entry point: 0x%08x\n"),
5918 (unsigned)bfd_getl32 (egst->lp_1));
5919 fprintf (file, _(" proc descr : 0x%08x\n"),
5920 (unsigned)bfd_getl32 (egst->lp_2));
5921 fprintf (file, _(" psect index: %u\n"),
5922 (unsigned)bfd_getl32 (egst->psindx));
5923 fprintf (file, _(" name : %.*s\n"),
5924 egst->namlng, egst->name);
5926 break;
5927 case EGSD__C_SYMV:
5929 struct vms_esdfv *esdfv = (struct vms_esdfv *)e;
5930 unsigned int flags = bfd_getl16 (esdfv->flags);
5932 fprintf (file, _("SYMV - Vectored symbol definition\n"));
5933 fprintf (file, _(" flags: 0x%04x"), flags);
5934 exav_bfd_print_egsy_flags (flags, file);
5935 fputc ('\n', file);
5936 fprintf (file, _(" vector : 0x%08x\n"),
5937 (unsigned)bfd_getl32 (esdfv->vector));
5938 fprintf (file, _(" psect offset: %u\n"),
5939 (unsigned)bfd_getl32 (esdfv->value));
5940 fprintf (file, _(" psect index : %u\n"),
5941 (unsigned)bfd_getl32 (esdfv->psindx));
5942 fprintf (file, _(" name : %.*s\n"),
5943 esdfv->namlng, esdfv->name);
5945 break;
5946 case EGSD__C_SYMM:
5948 struct vms_esdfm *esdfm = (struct vms_esdfm *)e;
5949 unsigned int flags = bfd_getl16 (esdfm->flags);
5951 fprintf (file, _("SYMM - Global symbol definition with version\n"));
5952 fprintf (file, _(" flags: 0x%04x"), flags);
5953 exav_bfd_print_egsy_flags (flags, file);
5954 fputc ('\n', file);
5955 fprintf (file, _(" version mask: 0x%08x\n"),
5956 (unsigned)bfd_getl32 (esdfm->version_mask));
5957 fprintf (file, _(" psect offset: %u\n"),
5958 (unsigned)bfd_getl32 (esdfm->value));
5959 fprintf (file, _(" psect index : %u\n"),
5960 (unsigned)bfd_getl32 (esdfm->psindx));
5961 fprintf (file, _(" name : %.*s\n"),
5962 esdfm->namlng, esdfm->name);
5964 break;
5965 default:
5966 fprintf (file, _("unhandled egsd entry type %u\n"), type);
5967 break;
5969 off += len;
5973 static void
5974 evax_bfd_print_hex (FILE *file, const char *pfx,
5975 const unsigned char *buf, unsigned int len)
5977 unsigned int i;
5978 unsigned int n;
5980 n = 0;
5981 for (i = 0; i < len; i++)
5983 if (n == 0)
5984 fputs (pfx, file);
5985 fprintf (file, " %02x", buf[i]);
5986 n++;
5987 if (n == 16)
5989 n = 0;
5990 fputc ('\n', file);
5993 if (n != 0)
5994 fputc ('\n', file);
5997 static void
5998 evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf, int is_ps)
6000 fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"),
6001 (unsigned)bfd_getl32 (buf),
6002 (unsigned)bfd_getl32 (buf + 16));
6003 fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"),
6004 (unsigned)bfd_getl32 (buf + 4),
6005 (unsigned)bfd_getl32 (buf + 12),
6006 (unsigned)bfd_getl32 (buf + 8));
6007 fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"),
6008 (unsigned)bfd_getl32 (buf + 20),
6009 (unsigned)bfd_getl32 (buf + 28),
6010 (unsigned)bfd_getl32 (buf + 24));
6011 if (is_ps)
6012 fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"),
6013 (unsigned)bfd_getl32 (buf + 32),
6014 (unsigned)bfd_getl32 (buf + 40),
6015 (unsigned)bfd_getl32 (buf + 36));
6016 else
6017 fprintf (file, _(" global name: %.*s\n"), buf[32], buf + 33);
6020 static void
6021 evax_bfd_print_etir (FILE *file, const char *name,
6022 unsigned char *rec, unsigned int rec_len)
6024 unsigned int off = sizeof (struct vms_egsd);
6025 unsigned int sec_len;
6027 fprintf (file, _(" %s (len=%u+%u):\n"), name,
6028 (unsigned)(rec_len - sizeof (struct vms_eobjrec)),
6029 (unsigned)sizeof (struct vms_eobjrec));
6031 for (off = sizeof (struct vms_eobjrec); off < rec_len; )
6033 struct vms_etir *etir = (struct vms_etir *)(rec + off);
6034 unsigned char *buf;
6035 unsigned int type;
6036 unsigned int size;
6038 type = bfd_getl16 (etir->rectyp);
6039 size = bfd_getl16 (etir->size);
6040 buf = rec + off + sizeof (struct vms_etir);
6042 fprintf (file, _(" (type: %3u, size: 4+%3u): "), type, size - 4);
6043 switch (type)
6045 case ETIR__C_STA_GBL:
6046 fprintf (file, _("STA_GBL (stack global) %.*s\n"),
6047 buf[0], buf + 1);
6048 break;
6049 case ETIR__C_STA_LW:
6050 fprintf (file, _("STA_LW (stack longword) 0x%08x\n"),
6051 (unsigned)bfd_getl32 (buf));
6052 break;
6053 case ETIR__C_STA_QW:
6054 fprintf (file, _("STA_QW (stack quadword) 0x%08x %08x\n"),
6055 (unsigned)bfd_getl32 (buf + 4),
6056 (unsigned)bfd_getl32 (buf + 0));
6057 break;
6058 case ETIR__C_STA_PQ:
6059 fprintf (file, _("STA_PQ (stack psect base + offset)\n"));
6060 fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"),
6061 (unsigned)bfd_getl32 (buf + 0),
6062 (unsigned)bfd_getl32 (buf + 8),
6063 (unsigned)bfd_getl32 (buf + 4));
6064 break;
6065 case ETIR__C_STA_LI:
6066 fprintf (file, _("STA_LI (stack literal)\n"));
6067 break;
6068 case ETIR__C_STA_MOD:
6069 fprintf (file, _("STA_MOD (stack module)\n"));
6070 break;
6071 case ETIR__C_STA_CKARG:
6072 fprintf (file, _("STA_CKARG (compare procedure argument)\n"));
6073 break;
6075 case ETIR__C_STO_B:
6076 fprintf (file, _("STO_B (store byte)\n"));
6077 break;
6078 case ETIR__C_STO_W:
6079 fprintf (file, _("STO_W (store word)\n"));
6080 break;
6081 case ETIR__C_STO_LW:
6082 fprintf (file, _("STO_LW (store longword)\n"));
6083 break;
6084 case ETIR__C_STO_QW:
6085 fprintf (file, _("STO_QW (store quadword)\n"));
6086 break;
6087 case ETIR__C_STO_IMMR:
6089 unsigned int len = bfd_getl32 (buf);
6090 fprintf (file,
6091 _("STO_IMMR (store immediate repeat) %u bytes\n"),
6092 len);
6093 evax_bfd_print_hex (file, " ", buf + 4, len);
6094 sec_len += len;
6096 break;
6097 case ETIR__C_STO_GBL:
6098 fprintf (file, _("STO_GBL (store global) %.*s\n"),
6099 buf[0], buf + 1);
6100 break;
6101 case ETIR__C_STO_CA:
6102 fprintf (file, _("STO_CA (store code address) %.*s\n"),
6103 buf[0], buf + 1);
6104 break;
6105 case ETIR__C_STO_RB:
6106 fprintf (file, _("STO_RB (store relative branch)\n"));
6107 break;
6108 case ETIR__C_STO_AB:
6109 fprintf (file, _("STO_AB (store absolute branch)\n"));
6110 break;
6111 case ETIR__C_STO_OFF:
6112 fprintf (file, _("STO_OFF (store offset to psect)\n"));
6113 break;
6114 case ETIR__C_STO_IMM:
6116 unsigned int len = bfd_getl32 (buf);
6117 fprintf (file,
6118 _("STO_IMM (store immediate) %u bytes\n"),
6119 len);
6120 evax_bfd_print_hex (file, " ", buf + 4, len);
6121 sec_len += len;
6123 break;
6124 case ETIR__C_STO_GBL_LW:
6125 fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"),
6126 buf[0], buf + 1);
6127 break;
6128 case ETIR__C_STO_LP_PSB:
6129 fprintf (file, _("STO_OFF (store LP with procedure signature)\n"));
6130 break;
6131 case ETIR__C_STO_HINT_GBL:
6132 fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n"));
6133 break;
6134 case ETIR__C_STO_HINT_PS:
6135 fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n"));
6136 break;
6138 case ETIR__C_OPR_NOP:
6139 fprintf (file, _("OPR_NOP (no-operation)\n"));
6140 break;
6141 case ETIR__C_OPR_ADD:
6142 fprintf (file, _("OPR_ADD (add)\n"));
6143 break;
6144 case ETIR__C_OPR_SUB:
6145 fprintf (file, _("OPR_SUB (substract)\n"));
6146 break;
6147 case ETIR__C_OPR_MUL:
6148 fprintf (file, _("OPR_MUL (multiply)\n"));
6149 break;
6150 case ETIR__C_OPR_DIV:
6151 fprintf (file, _("OPR_DIV (divide)\n"));
6152 break;
6153 case ETIR__C_OPR_AND:
6154 fprintf (file, _("OPR_AND (logical and)\n"));
6155 break;
6156 case ETIR__C_OPR_IOR:
6157 fprintf (file, _("OPR_IOR (logical inclusive or)\n"));
6158 break;
6159 case ETIR__C_OPR_EOR:
6160 fprintf (file, _("OPR_EOR (logical exclusive or)\n"));
6161 break;
6162 case ETIR__C_OPR_NEG:
6163 fprintf (file, _("OPR_NEG (negate)\n"));
6164 break;
6165 case ETIR__C_OPR_COM:
6166 fprintf (file, _("OPR_COM (complement)\n"));
6167 break;
6168 case ETIR__C_OPR_INSV:
6169 fprintf (file, _("OPR_INSV (insert field)\n"));
6170 break;
6171 case ETIR__C_OPR_ASH:
6172 fprintf (file, _("OPR_ASH (arithmetic shift)\n"));
6173 break;
6174 case ETIR__C_OPR_USH:
6175 fprintf (file, _("OPR_USH (unsigned shift)\n"));
6176 break;
6177 case ETIR__C_OPR_ROT:
6178 fprintf (file, _("OPR_ROT (rotate)\n"));
6179 break;
6180 case ETIR__C_OPR_SEL:
6181 fprintf (file, _("OPR_SEL (select)\n"));
6182 break;
6183 case ETIR__C_OPR_REDEF:
6184 fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n"));
6185 break;
6186 case ETIR__C_OPR_DFLIT:
6187 fprintf (file, _("OPR_REDEF (define a literal)\n"));
6188 break;
6190 case ETIR__C_STC_LP:
6191 fprintf (file, _("STC_LP (store cond linkage pair)\n"));
6192 break;
6193 case ETIR__C_STC_LP_PSB:
6194 fprintf (file,
6195 _("STC_LP_PSB (store cond linkage pair + signature)\n"));
6196 fprintf (file, _(" linkage index: %u, procedure: %.*s\n"),
6197 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6198 buf += 4 + 1 + buf[4];
6199 fprintf (file, _(" signature: %.*s\n"), buf[0], buf + 1);
6200 break;
6201 case ETIR__C_STC_GBL:
6202 fprintf (file, _("STC_GBL (store cond global)\n"));
6203 fprintf (file, _(" linkage index: %u, global: %.*s\n"),
6204 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6205 break;
6206 case ETIR__C_STC_GCA:
6207 fprintf (file, _("STC_GCA (store cond code address)\n"));
6208 fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"),
6209 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6210 break;
6211 case ETIR__C_STC_PS:
6212 fprintf (file, _("STC_PS (store cond psect + offset)\n"));
6213 fprintf (file,
6214 _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"),
6215 (unsigned)bfd_getl32 (buf),
6216 (unsigned)bfd_getl32 (buf + 4),
6217 (unsigned)bfd_getl32 (buf + 12),
6218 (unsigned)bfd_getl32 (buf + 8));
6219 break;
6220 case ETIR__C_STC_NOP_GBL:
6221 fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n"));
6222 evax_bfd_print_etir_stc_ir (file, buf, 0);
6223 break;
6224 case ETIR__C_STC_NOP_PS:
6225 fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n"));
6226 evax_bfd_print_etir_stc_ir (file, buf, 1);
6227 break;
6228 case ETIR__C_STC_BSR_GBL:
6229 fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n"));
6230 evax_bfd_print_etir_stc_ir (file, buf, 0);
6231 break;
6232 case ETIR__C_STC_BSR_PS:
6233 fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n"));
6234 evax_bfd_print_etir_stc_ir (file, buf, 1);
6235 break;
6236 case ETIR__C_STC_LDA_GBL:
6237 fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n"));
6238 evax_bfd_print_etir_stc_ir (file, buf, 0);
6239 break;
6240 case ETIR__C_STC_LDA_PS:
6241 fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n"));
6242 evax_bfd_print_etir_stc_ir (file, buf, 1);
6243 break;
6244 case ETIR__C_STC_BOH_GBL:
6245 fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n"));
6246 evax_bfd_print_etir_stc_ir (file, buf, 0);
6247 break;
6248 case ETIR__C_STC_BOH_PS:
6249 fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n"));
6250 evax_bfd_print_etir_stc_ir (file, buf, 1);
6251 break;
6252 case ETIR__C_STC_NBH_GBL:
6253 fprintf (file,
6254 _("STC_NBH_GBL (store cond or hint at global addr)\n"));
6255 break;
6256 case ETIR__C_STC_NBH_PS:
6257 fprintf (file,
6258 _("STC_NBH_PS (store cond or hint at psect + offset)\n"));
6259 break;
6261 case ETIR__C_CTL_SETRB:
6262 fprintf (file, _("CTL_SETRB (set relocation base)\n"));
6263 sec_len += 4;
6264 break;
6265 case ETIR__C_CTL_AUGRB:
6267 unsigned int val = bfd_getl32 (buf);
6268 fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"), val);
6270 break;
6271 case ETIR__C_CTL_DFLOC:
6272 fprintf (file, _("CTL_DFLOC (define location)\n"));
6273 break;
6274 case ETIR__C_CTL_STLOC:
6275 fprintf (file, _("CTL_STLOC (set location)\n"));
6276 break;
6277 case ETIR__C_CTL_STKDL:
6278 fprintf (file, _("CTL_STKDL (stack defined location)\n"));
6279 break;
6280 default:
6281 fprintf (file, _("*unhandled*\n"));
6282 break;
6284 off += size;
6288 static void
6289 evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
6291 bfd_boolean is_first = TRUE;
6292 bfd_boolean has_records = FALSE;
6294 while (1)
6296 unsigned int rec_len;
6297 unsigned int pad_len;
6298 unsigned char *rec;
6299 unsigned int hdr_size;
6300 unsigned int type;
6302 if (is_first)
6304 unsigned char buf[6];
6306 is_first = FALSE;
6308 /* Read 6 bytes. */
6309 if (bfd_bread (buf, sizeof (buf), abfd) != sizeof (buf))
6311 fprintf (file, _("cannot read GST record length\n"));
6312 return;
6314 rec_len = bfd_getl16 (buf + 0);
6315 if (rec_len == bfd_getl16 (buf + 4)
6316 && bfd_getl16 (buf + 2) == EOBJ__C_EMH)
6318 /* The format is raw: record-size, type, record-size. */
6319 has_records = TRUE;
6320 pad_len = (rec_len + 1) & ~1U;
6321 hdr_size = 4;
6323 else if (rec_len == EOBJ__C_EMH)
6325 has_records = FALSE;
6326 pad_len = bfd_getl16 (buf + 2);
6327 hdr_size = 6;
6329 else
6331 /* Ill-formed. */
6332 fprintf (file, _("cannot find EMH in first GST record\n"));
6333 return;
6335 rec = bfd_malloc (pad_len);
6336 memcpy (rec, buf + sizeof (buf) - hdr_size, hdr_size);
6338 else
6340 unsigned int rec_len2 = 0;
6341 unsigned char hdr[4];
6343 if (has_records)
6345 unsigned char buf_len[2];
6347 if (bfd_bread (buf_len, sizeof (buf_len), abfd)
6348 != sizeof (buf_len))
6350 fprintf (file, _("cannot read GST record length\n"));
6351 return;
6353 rec_len2 = (unsigned)bfd_getl16 (buf_len);
6356 if (bfd_bread (hdr, sizeof (hdr), abfd) != sizeof (hdr))
6358 fprintf (file, _("cannot read GST record header\n"));
6359 return;
6361 rec_len = (unsigned)bfd_getl16 (hdr + 2);
6362 if (has_records)
6363 pad_len = (rec_len + 1) & ~1U;
6364 else
6365 pad_len = rec_len;
6366 rec = bfd_malloc (pad_len);
6367 memcpy (rec, hdr, sizeof (hdr));
6368 hdr_size = sizeof (hdr);
6369 if (has_records && rec_len2 != rec_len)
6371 fprintf (file, _(" corrupted GST\n"));
6372 break;
6376 if (bfd_bread (rec + hdr_size, pad_len - hdr_size, abfd)
6377 != pad_len - hdr_size)
6379 fprintf (file, _("cannot read GST record\n"));
6380 return;
6383 type = (unsigned)bfd_getl16 (rec);
6385 switch (type)
6387 case EOBJ__C_EMH:
6388 evax_bfd_print_emh (file, rec, rec_len);
6389 break;
6390 case EOBJ__C_EGSD:
6391 evax_bfd_print_egsd (file, rec, rec_len);
6392 break;
6393 case EOBJ__C_EEOM:
6394 evax_bfd_print_eeom (file, rec, rec_len);
6395 free (rec);
6396 return;
6397 break;
6398 case EOBJ__C_ETIR:
6399 evax_bfd_print_etir (file, "ETIR", rec, rec_len);
6400 break;
6401 case EOBJ__C_EDBG:
6402 evax_bfd_print_etir (file, "EDBG", rec, rec_len);
6403 break;
6404 case EOBJ__C_ETBT:
6405 evax_bfd_print_etir (file, "ETBT", rec, rec_len);
6406 break;
6407 default:
6408 fprintf (file, _(" unhandled EOBJ record type %u\n"), type);
6409 break;
6411 free (rec);
6415 static void
6416 evax_bfd_print_relocation_records (FILE *file, const unsigned char *rel,
6417 unsigned int stride)
6419 while (1)
6421 unsigned int base;
6422 unsigned int count;
6423 unsigned int j;
6425 count = bfd_getl32 (rel + 0);
6427 if (count == 0)
6428 break;
6429 base = bfd_getl32 (rel + 4);
6431 fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"),
6432 count, base);
6434 rel += 8;
6435 for (j = 0; count > 0; j += 4, count -= 32)
6437 unsigned int k;
6438 unsigned int n = 0;
6439 unsigned int val;
6441 val = bfd_getl32 (rel);
6442 rel += 4;
6444 fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count);
6446 for (k = 0; k < 32; k++)
6447 if (val & (1 << k))
6449 if (n == 0)
6450 fputs (" ", file);
6451 fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
6452 n++;
6453 if (n == 8)
6455 fputs ("\n", file);
6456 n = 0;
6459 if (n)
6460 fputs ("\n", file);
6465 static void
6466 evax_bfd_print_address_fixups (FILE *file, const unsigned char *rel)
6468 while (1)
6470 unsigned int j;
6471 unsigned int count;
6473 count = bfd_getl32 (rel + 0);
6474 if (count == 0)
6475 return;
6476 fprintf (file, _(" image %u (%u entries)\n"),
6477 (unsigned)bfd_getl32 (rel + 4), count);
6478 rel += 8;
6479 for (j = 0; j < count; j++)
6481 fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"),
6482 (unsigned)bfd_getl32 (rel + 0),
6483 (unsigned)bfd_getl32 (rel + 4));
6484 rel += 8;
6489 static void
6490 evax_bfd_print_reference_fixups (FILE *file, const unsigned char *rel)
6492 unsigned int count;
6494 while (1)
6496 unsigned int j;
6497 unsigned int n = 0;
6499 count = bfd_getl32 (rel + 0);
6500 if (count == 0)
6501 break;
6502 fprintf (file, _(" image %u (%u entries), offsets:\n"),
6503 (unsigned)bfd_getl32 (rel + 4), count);
6504 rel += 8;
6505 for (j = 0; j < count; j++)
6507 if (n == 0)
6508 fputs (" ", file);
6509 fprintf (file, _(" 0x%08x"), (unsigned)bfd_getl32 (rel));
6510 n++;
6511 if (n == 7)
6513 fputs ("\n", file);
6514 n = 0;
6516 rel += 4;
6518 if (n)
6519 fputs ("\n", file);
6523 static void
6524 evax_bfd_print_indent (int indent, FILE *file)
6526 for (; indent; indent--)
6527 fputc (' ', file);
6530 static const char *
6531 evax_bfd_get_dsc_name (unsigned int v)
6533 switch (v)
6535 case DSC__K_DTYPE_Z:
6536 return "Z (Unspecified)";
6537 case DSC__K_DTYPE_V:
6538 return "V (Bit)";
6539 case DSC__K_DTYPE_BU:
6540 return "BU (Byte logical)";
6541 case DSC__K_DTYPE_WU:
6542 return "WU (Word logical)";
6543 case DSC__K_DTYPE_LU:
6544 return "LU (Longword logical)";
6545 case DSC__K_DTYPE_QU:
6546 return "QU (Quadword logical)";
6547 case DSC__K_DTYPE_B:
6548 return "B (Byte integer)";
6549 case DSC__K_DTYPE_W:
6550 return "W (Word integer)";
6551 case DSC__K_DTYPE_L:
6552 return "L (Longword integer)";
6553 case DSC__K_DTYPE_Q:
6554 return "Q (Quadword integer)";
6555 case DSC__K_DTYPE_F:
6556 return "F (Single-precision floating)";
6557 case DSC__K_DTYPE_D:
6558 return "D (Double-precision floating)";
6559 case DSC__K_DTYPE_FC:
6560 return "FC (Complex)";
6561 case DSC__K_DTYPE_DC:
6562 return "DC (Double-precision Complex)";
6563 case DSC__K_DTYPE_T:
6564 return "T (ASCII text string)";
6565 case DSC__K_DTYPE_NU:
6566 return "NU (Numeric string, unsigned)";
6567 case DSC__K_DTYPE_NL:
6568 return "NL (Numeric string, left separate sign)";
6569 case DSC__K_DTYPE_NLO:
6570 return "NLO (Numeric string, left overpunched sign)";
6571 case DSC__K_DTYPE_NR:
6572 return "NR (Numeric string, right separate sign)";
6573 case DSC__K_DTYPE_NRO:
6574 return "NRO (Numeric string, right overpunched sig)";
6575 case DSC__K_DTYPE_NZ:
6576 return "NZ (Numeric string, zoned sign)";
6577 case DSC__K_DTYPE_P:
6578 return "P (Packed decimal string)";
6579 case DSC__K_DTYPE_ZI:
6580 return "ZI (Sequence of instructions)";
6581 case DSC__K_DTYPE_ZEM:
6582 return "ZEM (Procedure entry mask)";
6583 case DSC__K_DTYPE_DSC:
6584 return "DSC (Descriptor, used for arrays of dyn strings)";
6585 case DSC__K_DTYPE_OU:
6586 return "OU (Octaword logical)";
6587 case DSC__K_DTYPE_O:
6588 return "O (Octaword integer)";
6589 case DSC__K_DTYPE_G:
6590 return "G (Double precision G floating, 64 bit)";
6591 case DSC__K_DTYPE_H:
6592 return "H (Quadruple precision floating, 128 bit)";
6593 case DSC__K_DTYPE_GC:
6594 return "GC (Double precision complex, G floating)";
6595 case DSC__K_DTYPE_HC:
6596 return "HC (Quadruple precision complex, H floating)";
6597 case DSC__K_DTYPE_CIT:
6598 return "CIT (COBOL intermediate temporary)";
6599 case DSC__K_DTYPE_BPV:
6600 return "BPV (Bound Procedure Value)";
6601 case DSC__K_DTYPE_BLV:
6602 return "BLV (Bound Label Value)";
6603 case DSC__K_DTYPE_VU:
6604 return "VU (Bit Unaligned)";
6605 case DSC__K_DTYPE_ADT:
6606 return "ADT (Absolute Date-Time)";
6607 case DSC__K_DTYPE_VT:
6608 return "VT (Varying Text)";
6609 case DSC__K_DTYPE_T2:
6610 return "T2 (16-bit char)";
6611 case DSC__K_DTYPE_VT2:
6612 return "VT2 (16-bit varying char)";
6613 default:
6614 return "?? (unknown)";
6618 static void
6619 evax_bfd_print_desc (const unsigned char *buf, int indent, FILE *file)
6621 unsigned char bclass = buf[3];
6622 unsigned char dtype = buf[2];
6623 unsigned int len = (unsigned)bfd_getl16 (buf);
6624 unsigned int pointer = (unsigned)bfd_getl32 (buf + 4);
6626 evax_bfd_print_indent (indent, file);
6628 if (len == 1 && pointer == 0xffffffffUL)
6630 /* 64 bits. */
6631 fprintf (file, _("64 bits *unhandled*\n"));
6633 else
6635 fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"),
6636 bclass, dtype, len, pointer);
6637 switch (bclass)
6639 case DSC__K_CLASS_NCA:
6641 const struct vms_dsc_nca *dsc = (const void *)buf;
6642 unsigned int i;
6643 const unsigned char *b;
6645 evax_bfd_print_indent (indent, file);
6646 fprintf (file, _("non-contiguous array of %s\n"),
6647 evax_bfd_get_dsc_name (dsc->dtype));
6648 evax_bfd_print_indent (indent + 1, file);
6649 fprintf (file,
6650 _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"),
6651 dsc->dimct, dsc->aflags, dsc->digits, dsc->scale);
6652 evax_bfd_print_indent (indent + 1, file);
6653 fprintf (file,
6654 _("arsize: %u, a0: 0x%08x\n"),
6655 (unsigned)bfd_getl32 (dsc->arsize),
6656 (unsigned)bfd_getl32 (dsc->a0));
6657 evax_bfd_print_indent (indent + 1, file);
6658 fprintf (file, _("Strides:\n"));
6659 b = buf + sizeof (*dsc);
6660 for (i = 0; i < dsc->dimct; i++)
6662 evax_bfd_print_indent (indent + 2, file);
6663 fprintf (file, _("[%u]: %u\n"), i + 1,
6664 (unsigned)bfd_getl32 (b));
6665 b += 4;
6667 evax_bfd_print_indent (indent + 1, file);
6668 fprintf (file, _("Bounds:\n"));
6669 b = buf + sizeof (*dsc);
6670 for (i = 0; i < dsc->dimct; i++)
6672 evax_bfd_print_indent (indent + 2, file);
6673 fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1,
6674 (unsigned)bfd_getl32 (b + 0),
6675 (unsigned)bfd_getl32 (b + 4));
6676 b += 8;
6679 break;
6680 case DSC__K_CLASS_UBS:
6682 const struct vms_dsc_ubs *ubs = (const void *)buf;
6684 evax_bfd_print_indent (indent, file);
6685 fprintf (file, _("unaligned bit-string of %s\n"),
6686 evax_bfd_get_dsc_name (ubs->dtype));
6687 evax_bfd_print_indent (indent + 1, file);
6688 fprintf (file,
6689 _("base: %u, pos: %u\n"),
6690 (unsigned)bfd_getl32 (ubs->base),
6691 (unsigned)bfd_getl32 (ubs->pos));
6693 break;
6694 default:
6695 fprintf (file, _("*unhandled*\n"));
6696 break;
6701 static unsigned int
6702 evax_bfd_print_valspec (const unsigned char *buf, int indent, FILE *file)
6704 unsigned int vflags = buf[0];
6705 unsigned int value = (unsigned)bfd_getl32 (buf + 1);
6706 unsigned int len = 5;
6708 evax_bfd_print_indent (indent, file);
6709 fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
6710 buf += 5;
6712 switch (vflags)
6714 case DST__K_VFLAGS_NOVAL:
6715 fprintf (file, _("(no value)\n"));
6716 break;
6717 case DST__K_VFLAGS_NOTACTIVE:
6718 fprintf (file, _("(not active)\n"));
6719 break;
6720 case DST__K_VFLAGS_UNALLOC:
6721 fprintf (file, _("(not allocated)\n"));
6722 break;
6723 case DST__K_VFLAGS_DSC:
6724 fprintf (file, _("(descriptor)\n"));
6725 evax_bfd_print_desc (buf + value, indent + 1, file);
6726 break;
6727 case DST__K_VFLAGS_TVS:
6728 fprintf (file, _("(trailing value)\n"));
6729 break;
6730 case DST__K_VS_FOLLOWS:
6731 fprintf (file, _("(value spec follows)\n"));
6732 break;
6733 case DST__K_VFLAGS_BITOFFS:
6734 fprintf (file, _("(at bit offset %u)\n"), value);
6735 break;
6736 default:
6737 fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
6738 (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
6739 vflags & DST__K_DISP ? 1 : 0,
6740 vflags & DST__K_INDIR ? 1 : 0);
6741 switch (vflags & DST__K_VALKIND_MASK)
6743 case DST__K_VALKIND_LITERAL:
6744 fputs (_("literal"), file);
6745 break;
6746 case DST__K_VALKIND_ADDR:
6747 fputs (_("address"), file);
6748 break;
6749 case DST__K_VALKIND_DESC:
6750 fputs (_("desc"), file);
6751 break;
6752 case DST__K_VALKIND_REG:
6753 fputs (_("reg"), file);
6754 break;
6756 fputs (")\n", file);
6757 break;
6759 return len;
6762 static void
6763 evax_bfd_print_typspec (const unsigned char *buf, int indent, FILE *file)
6765 unsigned char kind = buf[2];
6766 unsigned int len = (unsigned)bfd_getl16 (buf);
6768 evax_bfd_print_indent (indent, file);
6769 fprintf (file, ("len: %2u, kind: %2u "), len, kind);
6770 buf += 3;
6771 switch (kind)
6773 case DST__K_TS_ATOM:
6774 fprintf (file, ("atomic, type=0x%02x %s\n"),
6775 buf[0], evax_bfd_get_dsc_name (buf[0]));
6776 break;
6777 case DST__K_TS_IND:
6778 fprintf (file, ("indirect, defined at 0x%08x\n"),
6779 (unsigned)bfd_getl32 (buf));
6780 break;
6781 case DST__K_TS_TPTR:
6782 fprintf (file, ("typed pointer\n"));
6783 evax_bfd_print_typspec (buf, indent + 1, file);
6784 break;
6785 case DST__K_TS_PTR:
6786 fprintf (file, ("pointer\n"));
6787 break;
6788 case DST__K_TS_ARRAY:
6790 const unsigned char *vs;
6791 unsigned int vec_len;
6792 unsigned int i;
6794 fprintf (file, ("array, dim: %u, bitmap: "), buf[0]);
6795 vec_len = (buf[0] + 1 + 7) / 8;
6796 for (i = 0; i < vec_len; i++)
6797 fprintf (file, " %02x", buf[i + 1]);
6798 fputc ('\n', file);
6799 vs = buf + 1 + vec_len;
6800 evax_bfd_print_indent (indent, file);
6801 fprintf (file, ("array descriptor:\n"));
6802 vs += evax_bfd_print_valspec (vs, indent + 1, file);
6803 for (i = 0; i < buf[0] + 1U; i++)
6804 if (buf[1 + i / 8] & (1 << (i % 8)))
6806 evax_bfd_print_indent (indent, file);
6807 if (i == 0)
6808 fprintf (file, ("type spec for element:\n"));
6809 else
6810 fprintf (file, ("type spec for subscript %u:\n"), i);
6811 evax_bfd_print_typspec (vs, indent + 1, file);
6812 vs += bfd_getl16 (vs);
6815 break;
6816 default:
6817 fprintf (file, ("*unhandled*\n"));
6821 static void
6822 evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
6824 unsigned int off = 0;
6825 unsigned int pc = 0;
6826 unsigned int line = 0;
6828 fprintf (file, _("Debug symbol table:\n"));
6830 while (dst_size > 0)
6832 struct vms_dst_header dsth;
6833 unsigned int len;
6834 unsigned int type;
6835 unsigned char *buf;
6837 if (bfd_bread (&dsth, sizeof (dsth), abfd) != sizeof (dsth))
6839 fprintf (file, _("cannot read DST header\n"));
6840 return;
6842 len = bfd_getl16 (dsth.length);
6843 type = bfd_getl16 (dsth.type);
6844 fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
6845 type, len, off);
6846 if (len == 0)
6848 fputc ('\n', file);
6849 break;
6851 len++;
6852 dst_size -= len;
6853 off += len;
6854 len -= sizeof (dsth);
6855 buf = bfd_malloc (len);
6856 if (bfd_bread (buf, len, abfd) != len)
6858 fprintf (file, _("cannot read DST symbol\n"));
6859 return;
6861 switch (type)
6863 case DSC__K_DTYPE_V:
6864 case DSC__K_DTYPE_BU:
6865 case DSC__K_DTYPE_WU:
6866 case DSC__K_DTYPE_LU:
6867 case DSC__K_DTYPE_QU:
6868 case DSC__K_DTYPE_B:
6869 case DSC__K_DTYPE_W:
6870 case DSC__K_DTYPE_L:
6871 case DSC__K_DTYPE_Q:
6872 case DSC__K_DTYPE_F:
6873 case DSC__K_DTYPE_D:
6874 case DSC__K_DTYPE_FC:
6875 case DSC__K_DTYPE_DC:
6876 case DSC__K_DTYPE_T:
6877 case DSC__K_DTYPE_NU:
6878 case DSC__K_DTYPE_NL:
6879 case DSC__K_DTYPE_NLO:
6880 case DSC__K_DTYPE_NR:
6881 case DSC__K_DTYPE_NRO:
6882 case DSC__K_DTYPE_NZ:
6883 case DSC__K_DTYPE_P:
6884 case DSC__K_DTYPE_ZI:
6885 case DSC__K_DTYPE_ZEM:
6886 case DSC__K_DTYPE_DSC:
6887 case DSC__K_DTYPE_OU:
6888 case DSC__K_DTYPE_O:
6889 case DSC__K_DTYPE_G:
6890 case DSC__K_DTYPE_H:
6891 case DSC__K_DTYPE_GC:
6892 case DSC__K_DTYPE_HC:
6893 case DSC__K_DTYPE_CIT:
6894 case DSC__K_DTYPE_BPV:
6895 case DSC__K_DTYPE_BLV:
6896 case DSC__K_DTYPE_VU:
6897 case DSC__K_DTYPE_ADT:
6898 case DSC__K_DTYPE_VT:
6899 case DSC__K_DTYPE_T2:
6900 case DSC__K_DTYPE_VT2:
6901 fprintf (file, _("standard data: %s\n"),
6902 evax_bfd_get_dsc_name (type));
6903 evax_bfd_print_valspec (buf, 4, file);
6904 fprintf (file, _(" name: %.*s\n"), buf[5], buf + 6);
6905 break;
6906 case DST__K_MODBEG:
6908 struct vms_dst_modbeg *dst = (void *)buf;
6909 const char *name = (const char *)buf + sizeof (*dst);
6911 fprintf (file, _("modbeg\n"));
6912 fprintf (file, _(" flags: %d, language: %u, "
6913 "major: %u, minor: %u\n"),
6914 dst->flags,
6915 (unsigned)bfd_getl32 (dst->language),
6916 (unsigned)bfd_getl16 (dst->major),
6917 (unsigned)bfd_getl16 (dst->minor));
6918 fprintf (file, _(" module name: %.*s\n"),
6919 name[0], name + 1);
6920 name += name[0] + 1;
6921 fprintf (file, _(" compiler : %.*s\n"),
6922 name[0], name + 1);
6924 break;
6925 case DST__K_MODEND:
6926 fprintf (file, _("modend\n"));
6927 break;
6928 case DST__K_RTNBEG:
6930 struct vms_dst_rtnbeg *dst = (void *)buf;
6931 const char *name = (const char *)buf + sizeof (*dst);
6933 fputs (_("rtnbeg\n"), file);
6934 fprintf (file, _(" flags: %u, address: 0x%08x, "
6935 "pd-address: 0x%08x\n"),
6936 dst->flags,
6937 (unsigned)bfd_getl32 (dst->address),
6938 (unsigned)bfd_getl32 (dst->pd_address));
6939 fprintf (file, _(" routine name: %.*s\n"),
6940 name[0], name + 1);
6942 break;
6943 case DST__K_RTNEND:
6945 struct vms_dst_rtnend *dst = (void *)buf;
6947 fprintf (file, _("rtnend: size 0x%08x\n"),
6948 (unsigned)bfd_getl32 (dst->size));
6950 break;
6951 case DST__K_PROLOG:
6953 struct vms_dst_prolog *dst = (void *)buf;
6955 fprintf (file, _("prolog: bkpt address 0x%08x\n"),
6956 (unsigned)bfd_getl32 (dst->bkpt_addr));
6958 break;
6959 case DST__K_EPILOG:
6961 struct vms_dst_epilog *dst = (void *)buf;
6963 fprintf (file, _("epilog: flags: %u, count: %u\n"),
6964 dst->flags, (unsigned)bfd_getl32 (dst->count));
6966 break;
6967 case DST__K_BLKBEG:
6969 struct vms_dst_blkbeg *dst = (void *)buf;
6970 const char *name = (const char *)buf + sizeof (*dst);
6972 fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"),
6973 (unsigned)bfd_getl32 (dst->address),
6974 name[0], name + 1);
6976 break;
6977 case DST__K_BLKEND:
6979 struct vms_dst_blkend *dst = (void *)buf;
6981 fprintf (file, _("blkend: size: 0x%08x\n"),
6982 (unsigned)bfd_getl32 (dst->size));
6984 break;
6985 case DST__K_TYPSPEC:
6987 fprintf (file, _("typspec (len: %u)\n"), len);
6988 fprintf (file, _(" name: %.*s\n"), buf[0], buf + 1);
6989 evax_bfd_print_typspec (buf + 1 + buf[0], 5, file);
6991 break;
6992 case DST__K_SEPTYP:
6994 fprintf (file, _("septyp, name: %.*s\n"), buf[5], buf + 6);
6995 evax_bfd_print_valspec (buf, 4, file);
6997 break;
6998 case DST__K_RECBEG:
7000 struct vms_dst_recbeg *recbeg = (void *)buf;
7001 const char *name = (const char *)buf + sizeof (*recbeg);
7003 fprintf (file, _("recbeg: name: %.*s\n"), name[0], name + 1);
7004 evax_bfd_print_valspec (buf, 4, file);
7005 fprintf (file, (" len: %u bits\n"),
7006 (unsigned)bfd_getl32 (name + 1 + name[0]));
7008 break;
7009 case DST__K_RECEND:
7010 fprintf (file, _("recend\n"));
7011 break;
7012 case DST__K_ENUMBEG:
7013 fprintf (file, _("enumbeg, len: %u, name: %.*s\n"),
7014 buf[0], buf[1], buf + 2);
7015 break;
7016 case DST__K_ENUMELT:
7017 fprintf (file, _("enumelt, name: %.*s\n"), buf[5], buf + 6);
7018 evax_bfd_print_valspec (buf, 4, file);
7019 break;
7020 case DST__K_ENUMEND:
7021 fprintf (file, _("enumend\n"));
7022 break;
7023 case DST__K_LABEL:
7025 struct vms_dst_label *lab = (void *)buf;
7026 fprintf (file, ("label, name: %.*s\n"),
7027 lab->name[0], lab->name + 1);
7028 fprintf (file, (" address: 0x%08x\n"),
7029 (unsigned)bfd_getl32 (lab->value));
7031 break;
7032 case DST__K_DIS_RANGE:
7034 unsigned int cnt = bfd_getl32 (buf);
7035 unsigned char *rng = buf + 4;
7036 unsigned int i;
7038 fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt);
7039 for (i = 0; i < cnt; i++, rng += 8)
7040 fprintf (file, _(" address: 0x%08x, size: %u\n"),
7041 (unsigned)bfd_getl32 (rng),
7042 (unsigned)bfd_getl32 (rng + 4));
7045 break;
7046 case DST__K_LINE_NUM:
7048 unsigned char *buf_orig = buf;
7050 fprintf (file, _("line num (len: %u)\n"), len);
7052 while (len > 0)
7054 signed char cmd;
7055 unsigned char cmdlen;
7056 unsigned int val;
7058 cmd = buf[0];
7059 cmdlen = 0;
7061 fputs (" ", file);
7063 switch (cmd)
7065 case DST__K_DELTA_PC_W:
7066 val = bfd_getl16 (buf + 1);
7067 fprintf (file, _("delta_pc_w %u\n"), val);
7068 pc += val;
7069 line++;
7070 cmdlen = 3;
7071 break;
7072 case DST__K_INCR_LINUM:
7073 val = buf[1];
7074 fprintf (file, _("incr_linum(b): +%u\n"), val);
7075 line += val;
7076 cmdlen = 2;
7077 break;
7078 case DST__K_INCR_LINUM_W:
7079 val = bfd_getl16 (buf + 1);
7080 fprintf (file, _("incr_linum_w: +%u\n"), val);
7081 line += val;
7082 cmdlen = 3;
7083 break;
7084 case DST__K_INCR_LINUM_L:
7085 val = bfd_getl32 (buf + 1);
7086 fprintf (file, _("incr_linum_l: +%u\n"), val);
7087 line += val;
7088 cmdlen = 5;
7089 break;
7090 case DST__K_SET_LINUM:
7091 line = bfd_getl16 (buf + 1);
7092 fprintf (file, _("set_line_num(w) %u\n"), line);
7093 cmdlen = 3;
7094 break;
7095 case DST__K_SET_LINUM_B:
7096 line = buf[1];
7097 fprintf (file, _("set_line_num_b %u\n"), line);
7098 cmdlen = 2;
7099 break;
7100 case DST__K_SET_LINUM_L:
7101 line = bfd_getl32 (buf + 1);
7102 fprintf (file, _("set_line_num_l %u\n"), line);
7103 cmdlen = 5;
7104 break;
7105 case DST__K_SET_ABS_PC:
7106 pc = bfd_getl32 (buf + 1);
7107 fprintf (file, _("set_abs_pc: 0x%08x\n"), pc);
7108 cmdlen = 5;
7109 break;
7110 case DST__K_DELTA_PC_L:
7111 fprintf (file, _("delta_pc_l: +0x%08x\n"),
7112 (unsigned)bfd_getl32 (buf + 1));
7113 cmdlen = 5;
7114 break;
7115 case DST__K_TERM:
7116 fprintf (file, _("term(b): 0x%02x"), buf[1]);
7117 pc += buf[1];
7118 fprintf (file, _(" pc: 0x%08x\n"), pc);
7119 cmdlen = 2;
7120 break;
7121 case DST__K_TERM_W:
7122 val = bfd_getl16 (buf + 1);
7123 fprintf (file, _("term_w: 0x%04x"), val);
7124 pc += val;
7125 fprintf (file, _(" pc: 0x%08x\n"), pc);
7126 cmdlen = 3;
7127 break;
7128 default:
7129 if (cmd <= 0)
7131 fprintf (file, _("delta pc +%-4d"), -cmd);
7132 line++; /* FIXME: curr increment. */
7133 pc += -cmd;
7134 fprintf (file, _(" pc: 0x%08x line: %5u\n"),
7135 pc, line);
7136 cmdlen = 1;
7138 else
7139 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
7140 break;
7142 if (cmdlen == 0)
7143 break;
7144 len -= cmdlen;
7145 buf += cmdlen;
7147 buf = buf_orig;
7149 break;
7150 case DST__K_SOURCE:
7152 unsigned char *buf_orig = buf;
7154 fprintf (file, _("source (len: %u)\n"), len);
7156 while (len > 0)
7158 signed char cmd = buf[0];
7159 unsigned char cmdlen = 0;
7161 switch (cmd)
7163 case DST__K_SRC_DECLFILE:
7165 struct vms_dst_src_decl_src *src = (void *)(buf + 1);
7166 const char *name;
7168 fprintf (file, _(" declfile: len: %u, flags: %u, "
7169 "fileid: %u\n"),
7170 src->length, src->flags,
7171 (unsigned)bfd_getl16 (src->fileid));
7172 fprintf (file, _(" rms: cdt: 0x%08x %08x, "
7173 "ebk: 0x%08x, ffb: 0x%04x, "
7174 "rfo: %u\n"),
7175 (unsigned)bfd_getl32 (src->rms_cdt + 4),
7176 (unsigned)bfd_getl32 (src->rms_cdt + 0),
7177 (unsigned)bfd_getl32 (src->rms_ebk),
7178 (unsigned)bfd_getl16 (src->rms_ffb),
7179 src->rms_rfo);
7180 name = (const char *)buf + 1 + sizeof (*src);
7181 fprintf (file, _(" filename : %.*s\n"),
7182 name[0], name + 1);
7183 name += name[0] + 1;
7184 fprintf (file, _(" module name: %.*s\n"),
7185 name[0], name + 1);
7186 cmdlen = 2 + src->length;
7188 break;
7189 case DST__K_SRC_SETFILE:
7190 fprintf (file, _(" setfile %u\n"),
7191 (unsigned)bfd_getl16 (buf + 1));
7192 cmdlen = 3;
7193 break;
7194 case DST__K_SRC_SETREC_W:
7195 fprintf (file, _(" setrec %u\n"),
7196 (unsigned)bfd_getl16 (buf + 1));
7197 cmdlen = 3;
7198 break;
7199 case DST__K_SRC_SETREC_L:
7200 fprintf (file, _(" setrec %u\n"),
7201 (unsigned)bfd_getl32 (buf + 1));
7202 cmdlen = 5;
7203 break;
7204 case DST__K_SRC_SETLNUM_W:
7205 fprintf (file, _(" setlnum %u\n"),
7206 (unsigned)bfd_getl16 (buf + 1));
7207 cmdlen = 3;
7208 break;
7209 case DST__K_SRC_SETLNUM_L:
7210 fprintf (file, _(" setlnum %u\n"),
7211 (unsigned)bfd_getl32 (buf + 1));
7212 cmdlen = 5;
7213 break;
7214 case DST__K_SRC_DEFLINES_W:
7215 fprintf (file, _(" deflines %u\n"),
7216 (unsigned)bfd_getl16 (buf + 1));
7217 cmdlen = 3;
7218 break;
7219 case DST__K_SRC_DEFLINES_B:
7220 fprintf (file, _(" deflines %u\n"), buf[1]);
7221 cmdlen = 2;
7222 break;
7223 case DST__K_SRC_FORMFEED:
7224 fprintf (file, _(" formfeed\n"));
7225 cmdlen = 1;
7226 break;
7227 default:
7228 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
7229 break;
7231 if (cmdlen == 0)
7232 break;
7233 len -= cmdlen;
7234 buf += cmdlen;
7236 buf = buf_orig;
7238 break;
7239 default:
7240 fprintf (file, _("*unhandled* dst type %u\n"), type);
7241 break;
7243 free (buf);
7247 static void
7248 evax_bfd_print_image (bfd *abfd, FILE *file)
7250 struct vms_eihd eihd;
7251 const char *name;
7252 unsigned int val;
7253 unsigned int eiha_off;
7254 unsigned int eihi_off;
7255 unsigned int eihs_off;
7256 unsigned int eisd_off;
7257 unsigned int eihef_off = 0;
7258 unsigned int eihnp_off = 0;
7259 unsigned int dmt_vbn = 0;
7260 unsigned int dmt_size = 0;
7261 unsigned int dst_vbn = 0;
7262 unsigned int dst_size = 0;
7263 unsigned int gst_vbn = 0;
7264 unsigned int gst_size = 0;
7265 unsigned int eiaf_vbn = 0;
7266 unsigned int eiaf_size = 0;
7267 unsigned int eihvn_off;
7269 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET)
7270 || bfd_bread (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
7272 fprintf (file, _("cannot read EIHD\n"));
7273 return;
7275 fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
7276 (unsigned)bfd_getl32 (eihd.size),
7277 (unsigned)bfd_getl32 (eihd.hdrblkcnt));
7278 fprintf (file, _(" majorid: %u, minorid: %u\n"),
7279 (unsigned)bfd_getl32 (eihd.majorid),
7280 (unsigned)bfd_getl32 (eihd.minorid));
7282 val = (unsigned)bfd_getl32 (eihd.imgtype);
7283 switch (val)
7285 case EIHD__K_EXE:
7286 name = _("executable");
7287 break;
7288 case EIHD__K_LIM:
7289 name = _("linkable image");
7290 break;
7291 default:
7292 name = _("unknown");
7293 break;
7295 fprintf (file, _(" image type: %u (%s)"), val, name);
7297 val = (unsigned)bfd_getl32 (eihd.subtype);
7298 switch (val)
7300 case EIHD__C_NATIVE:
7301 name = _("native");
7302 break;
7303 case EIHD__C_CLI:
7304 name = _("CLI");
7305 break;
7306 default:
7307 name = _("unknown");
7308 break;
7310 fprintf (file, _(", subtype: %u (%s)\n"), val, name);
7312 eisd_off = bfd_getl32 (eihd.isdoff);
7313 eiha_off = bfd_getl32 (eihd.activoff);
7314 eihi_off = bfd_getl32 (eihd.imgidoff);
7315 eihs_off = bfd_getl32 (eihd.symdbgoff);
7316 fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
7317 "imgid: %u, patch: %u\n"),
7318 eisd_off, eiha_off, eihs_off, eihi_off,
7319 (unsigned)bfd_getl32 (eihd.patchoff));
7320 fprintf (file, _(" fixup info rva: "));
7321 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
7322 fprintf (file, _(", symbol vector rva: "));
7323 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
7324 eihvn_off = bfd_getl32 (eihd.version_array_off);
7325 fprintf (file, _("\n"
7326 " version array off: %u\n"),
7327 eihvn_off);
7328 fprintf (file,
7329 _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
7330 (unsigned)bfd_getl32 (eihd.imgiocnt),
7331 (unsigned)bfd_getl32 (eihd.iochancnt),
7332 (unsigned)bfd_getl32 (eihd.privreqs + 4),
7333 (unsigned)bfd_getl32 (eihd.privreqs + 0));
7334 val = (unsigned)bfd_getl32 (eihd.lnkflags);
7335 fprintf (file, _(" linker flags: %08x:"), val);
7336 if (val & EIHD__M_LNKDEBUG)
7337 fprintf (file, " LNKDEBUG");
7338 if (val & EIHD__M_LNKNOTFR)
7339 fprintf (file, " LNKNOTFR");
7340 if (val & EIHD__M_NOP0BUFS)
7341 fprintf (file, " NOP0BUFS");
7342 if (val & EIHD__M_PICIMG)
7343 fprintf (file, " PICIMG");
7344 if (val & EIHD__M_P0IMAGE)
7345 fprintf (file, " P0IMAGE");
7346 if (val & EIHD__M_DBGDMT)
7347 fprintf (file, " DBGDMT");
7348 if (val & EIHD__M_INISHR)
7349 fprintf (file, " INISHR");
7350 if (val & EIHD__M_XLATED)
7351 fprintf (file, " XLATED");
7352 if (val & EIHD__M_BIND_CODE_SEC)
7353 fprintf (file, " BIND_CODE_SEC");
7354 if (val & EIHD__M_BIND_DATA_SEC)
7355 fprintf (file, " BIND_DATA_SEC");
7356 if (val & EIHD__M_MKTHREADS)
7357 fprintf (file, " MKTHREADS");
7358 if (val & EIHD__M_UPCALLS)
7359 fprintf (file, " UPCALLS");
7360 if (val & EIHD__M_OMV_READY)
7361 fprintf (file, " OMV_READY");
7362 if (val & EIHD__M_EXT_BIND_SECT)
7363 fprintf (file, " EXT_BIND_SECT");
7364 fprintf (file, "\n");
7365 fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
7366 "match ctrl: %u, symvect_size: %u\n"),
7367 (unsigned)bfd_getl32 (eihd.ident),
7368 (unsigned)bfd_getl32 (eihd.sysver),
7369 eihd.matchctl,
7370 (unsigned)bfd_getl32 (eihd.symvect_size));
7371 fprintf (file, _(" BPAGE: %u"),
7372 (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
7373 if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT))
7375 eihef_off = bfd_getl32 (eihd.ext_fixup_off);
7376 eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
7377 fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
7378 eihef_off, eihnp_off);
7380 fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias));
7382 if (eihvn_off != 0)
7384 struct vms_eihvn eihvn;
7385 unsigned int mask;
7386 unsigned int j;
7388 fprintf (file, _("system version array information:\n"));
7389 if (bfd_seek (abfd, (file_ptr) eihvn_off, SEEK_SET)
7390 || bfd_bread (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
7392 fprintf (file, _("cannot read EIHVN header\n"));
7393 return;
7395 mask = bfd_getl32 (eihvn.subsystem_mask);
7396 for (j = 0; j < 32; j++)
7397 if (mask & (1 << j))
7399 struct vms_eihvn_subversion ver;
7400 if (bfd_bread (&ver, sizeof (ver), abfd) != sizeof (ver))
7402 fprintf (file, _("cannot read EIHVN version\n"));
7403 return;
7405 fprintf (file, _(" %02u "), j);
7406 switch (j)
7408 case EIHVN__BASE_IMAGE_BIT:
7409 fputs (_("BASE_IMAGE "), file);
7410 break;
7411 case EIHVN__MEMORY_MANAGEMENT_BIT:
7412 fputs (_("MEMORY_MANAGEMENT"), file);
7413 break;
7414 case EIHVN__IO_BIT:
7415 fputs (_("IO "), file);
7416 break;
7417 case EIHVN__FILES_VOLUMES_BIT:
7418 fputs (_("FILES_VOLUMES "), file);
7419 break;
7420 case EIHVN__PROCESS_SCHED_BIT:
7421 fputs (_("PROCESS_SCHED "), file);
7422 break;
7423 case EIHVN__SYSGEN_BIT:
7424 fputs (_("SYSGEN "), file);
7425 break;
7426 case EIHVN__CLUSTERS_LOCKMGR_BIT:
7427 fputs (_("CLUSTERS_LOCKMGR "), file);
7428 break;
7429 case EIHVN__LOGICAL_NAMES_BIT:
7430 fputs (_("LOGICAL_NAMES "), file);
7431 break;
7432 case EIHVN__SECURITY_BIT:
7433 fputs (_("SECURITY "), file);
7434 break;
7435 case EIHVN__IMAGE_ACTIVATOR_BIT:
7436 fputs (_("IMAGE_ACTIVATOR "), file);
7437 break;
7438 case EIHVN__NETWORKS_BIT:
7439 fputs (_("NETWORKS "), file);
7440 break;
7441 case EIHVN__COUNTERS_BIT:
7442 fputs (_("COUNTERS "), file);
7443 break;
7444 case EIHVN__STABLE_BIT:
7445 fputs (_("STABLE "), file);
7446 break;
7447 case EIHVN__MISC_BIT:
7448 fputs (_("MISC "), file);
7449 break;
7450 case EIHVN__CPU_BIT:
7451 fputs (_("CPU "), file);
7452 break;
7453 case EIHVN__VOLATILE_BIT:
7454 fputs (_("VOLATILE "), file);
7455 break;
7456 case EIHVN__SHELL_BIT:
7457 fputs (_("SHELL "), file);
7458 break;
7459 case EIHVN__POSIX_BIT:
7460 fputs (_("POSIX "), file);
7461 break;
7462 case EIHVN__MULTI_PROCESSING_BIT:
7463 fputs (_("MULTI_PROCESSING "), file);
7464 break;
7465 case EIHVN__GALAXY_BIT:
7466 fputs (_("GALAXY "), file);
7467 break;
7468 default:
7469 fputs (_("*unknown* "), file);
7470 break;
7472 fprintf (file, _(": %u.%u\n"),
7473 (unsigned)bfd_getl16 (ver.major),
7474 (unsigned)bfd_getl16 (ver.minor));
7478 if (eiha_off != 0)
7480 struct vms_eiha eiha;
7482 if (bfd_seek (abfd, (file_ptr) eiha_off, SEEK_SET)
7483 || bfd_bread (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
7485 fprintf (file, _("cannot read EIHA\n"));
7486 return;
7488 fprintf (file, _("Image activation: (size=%u)\n"),
7489 (unsigned)bfd_getl32 (eiha.size));
7490 fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
7491 (unsigned)bfd_getl32 (eiha.tfradr1_h),
7492 (unsigned)bfd_getl32 (eiha.tfradr1));
7493 fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
7494 (unsigned)bfd_getl32 (eiha.tfradr2_h),
7495 (unsigned)bfd_getl32 (eiha.tfradr2));
7496 fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
7497 (unsigned)bfd_getl32 (eiha.tfradr3_h),
7498 (unsigned)bfd_getl32 (eiha.tfradr3));
7499 fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
7500 (unsigned)bfd_getl32 (eiha.tfradr4_h),
7501 (unsigned)bfd_getl32 (eiha.tfradr4));
7502 fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"),
7503 (unsigned)bfd_getl32 (eiha.inishr_h),
7504 (unsigned)bfd_getl32 (eiha.inishr));
7506 if (eihi_off != 0)
7508 struct vms_eihi eihi;
7510 if (bfd_seek (abfd, (file_ptr) eihi_off, SEEK_SET)
7511 || bfd_bread (&eihi, sizeof (eihi), abfd) != sizeof (eihi))
7513 fprintf (file, _("cannot read EIHI\n"));
7514 return;
7516 fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
7517 (unsigned)bfd_getl32 (eihi.majorid),
7518 (unsigned)bfd_getl32 (eihi.minorid));
7519 fprintf (file, _(" image name : %.*s\n"),
7520 eihi.imgnam[0], eihi.imgnam + 1);
7521 fprintf (file, _(" link time : %s\n"),
7522 vms_time_to_str (eihi.linktime));
7523 fprintf (file, _(" image ident : %.*s\n"),
7524 eihi.imgid[0], eihi.imgid + 1);
7525 fprintf (file, _(" linker ident : %.*s\n"),
7526 eihi.linkid[0], eihi.linkid + 1);
7527 fprintf (file, _(" image build ident: %.*s\n"),
7528 eihi.imgbid[0], eihi.imgbid + 1);
7530 if (eihs_off != 0)
7532 struct vms_eihs eihs;
7534 if (bfd_seek (abfd, (file_ptr) eihs_off, SEEK_SET)
7535 || bfd_bread (&eihs, sizeof (eihs), abfd) != sizeof (eihs))
7537 fprintf (file, _("cannot read EIHS\n"));
7538 return;
7540 fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
7541 (unsigned)bfd_getl32 (eihs.majorid),
7542 (unsigned)bfd_getl32 (eihs.minorid));
7543 dst_vbn = bfd_getl32 (eihs.dstvbn);
7544 dst_size = bfd_getl32 (eihs.dstsize);
7545 fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"),
7546 dst_vbn, dst_size, dst_size);
7547 gst_vbn = bfd_getl32 (eihs.gstvbn);
7548 gst_size = bfd_getl32 (eihs.gstsize);
7549 fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
7550 gst_vbn, gst_size);
7551 dmt_vbn = bfd_getl32 (eihs.dmtvbn);
7552 dmt_size = bfd_getl32 (eihs.dmtsize);
7553 fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
7554 dmt_vbn, dmt_size);
7556 while (eisd_off != 0)
7558 struct vms_eisd eisd;
7559 unsigned int len;
7561 while (1)
7563 if (bfd_seek (abfd, (file_ptr) eisd_off, SEEK_SET)
7564 || bfd_bread (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
7566 fprintf (file, _("cannot read EISD\n"));
7567 return;
7569 len = (unsigned)bfd_getl32 (eisd.eisdsize);
7570 if (len != (unsigned)-1)
7571 break;
7573 /* Next block. */
7574 eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
7576 fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
7577 "size: %u, offset: %u)\n"),
7578 (unsigned)bfd_getl32 (eisd.majorid),
7579 (unsigned)bfd_getl32 (eisd.minorid),
7580 len, eisd_off);
7581 if (len == 0)
7582 break;
7583 fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
7584 (unsigned)bfd_getl32 (eisd.virt_addr + 4),
7585 (unsigned)bfd_getl32 (eisd.virt_addr + 0),
7586 (unsigned)bfd_getl32 (eisd.secsize));
7587 val = (unsigned)bfd_getl32 (eisd.flags);
7588 fprintf (file, _(" flags: 0x%04x"), val);
7589 if (val & EISD__M_GBL)
7590 fprintf (file, " GBL");
7591 if (val & EISD__M_CRF)
7592 fprintf (file, " CRF");
7593 if (val & EISD__M_DZRO)
7594 fprintf (file, " DZRO");
7595 if (val & EISD__M_WRT)
7596 fprintf (file, " WRT");
7597 if (val & EISD__M_INITALCODE)
7598 fprintf (file, " INITALCODE");
7599 if (val & EISD__M_BASED)
7600 fprintf (file, " BASED");
7601 if (val & EISD__M_FIXUPVEC)
7602 fprintf (file, " FIXUPVEC");
7603 if (val & EISD__M_RESIDENT)
7604 fprintf (file, " RESIDENT");
7605 if (val & EISD__M_VECTOR)
7606 fprintf (file, " VECTOR");
7607 if (val & EISD__M_PROTECT)
7608 fprintf (file, " PROTECT");
7609 if (val & EISD__M_LASTCLU)
7610 fprintf (file, " LASTCLU");
7611 if (val & EISD__M_EXE)
7612 fprintf (file, " EXE");
7613 if (val & EISD__M_NONSHRADR)
7614 fprintf (file, " NONSHRADR");
7615 if (val & EISD__M_QUAD_LENGTH)
7616 fprintf (file, " QUAD_LENGTH");
7617 if (val & EISD__M_ALLOC_64BIT)
7618 fprintf (file, " ALLOC_64BIT");
7619 fprintf (file, "\n");
7620 if (val & EISD__M_FIXUPVEC)
7622 eiaf_vbn = bfd_getl32 (eisd.vbn);
7623 eiaf_size = bfd_getl32 (eisd.secsize);
7625 fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
7626 (unsigned)bfd_getl32 (eisd.vbn),
7627 eisd.pfc, eisd.matchctl, eisd.type);
7628 switch (eisd.type)
7630 case EISD__K_NORMAL:
7631 fputs (_("NORMAL"), file);
7632 break;
7633 case EISD__K_SHRFXD:
7634 fputs (_("SHRFXD"), file);
7635 break;
7636 case EISD__K_PRVFXD:
7637 fputs (_("PRVFXD"), file);
7638 break;
7639 case EISD__K_SHRPIC:
7640 fputs (_("SHRPIC"), file);
7641 break;
7642 case EISD__K_PRVPIC:
7643 fputs (_("PRVPIC"), file);
7644 break;
7645 case EISD__K_USRSTACK:
7646 fputs (_("USRSTACK"), file);
7647 break;
7648 default:
7649 fputs (_("*unknown*"), file);
7650 break;
7652 fputs (_(")\n"), file);
7653 if (val & EISD__M_GBL)
7654 fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
7655 (unsigned)bfd_getl32 (eisd.ident),
7656 eisd.gblnam[0], eisd.gblnam + 1);
7657 eisd_off += len;
7660 if (dmt_vbn != 0)
7662 if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7664 fprintf (file, _("cannot read DMT\n"));
7665 return;
7668 fprintf (file, _("Debug module table:\n"));
7670 while (dmt_size > 0)
7672 struct vms_dmt_header dmth;
7673 unsigned int count;
7675 if (bfd_bread (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
7677 fprintf (file, _("cannot read DMT header\n"));
7678 return;
7680 count = bfd_getl16 (dmth.psect_count);
7681 fprintf (file,
7682 _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"),
7683 (unsigned)bfd_getl32 (dmth.modbeg),
7684 (unsigned)bfd_getl32 (dmth.size), count);
7685 dmt_size -= sizeof (dmth);
7686 while (count > 0)
7688 struct vms_dmt_psect dmtp;
7690 if (bfd_bread (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
7692 fprintf (file, _("cannot read DMT psect\n"));
7693 return;
7695 fprintf (file, _(" psect start: 0x%08x, length: %u\n"),
7696 (unsigned)bfd_getl32 (dmtp.start),
7697 (unsigned)bfd_getl32 (dmtp.length));
7698 count--;
7699 dmt_size -= sizeof (dmtp);
7704 if (dst_vbn != 0)
7706 if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7708 fprintf (file, _("cannot read DST\n"));
7709 return;
7712 evax_bfd_print_dst (abfd, dst_size, file);
7714 if (gst_vbn != 0)
7716 if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7718 fprintf (file, _("cannot read GST\n"));
7719 return;
7722 fprintf (file, _("Global symbol table:\n"));
7723 evax_bfd_print_eobj (abfd, file);
7725 if (eiaf_vbn != 0)
7727 unsigned char *buf;
7728 struct vms_eiaf *eiaf;
7729 unsigned int qrelfixoff;
7730 unsigned int lrelfixoff;
7731 unsigned int qdotadroff;
7732 unsigned int ldotadroff;
7733 unsigned int shrimgcnt;
7734 unsigned int shlstoff;
7735 unsigned int codeadroff;
7736 unsigned int lpfixoff;
7737 unsigned int chgprtoff;
7739 buf = bfd_malloc (eiaf_size);
7741 if (bfd_seek (abfd, (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)
7742 || bfd_bread (buf, eiaf_size, abfd) != eiaf_size)
7744 fprintf (file, _("cannot read EIHA\n"));
7745 free (buf);
7746 return;
7748 eiaf = (struct vms_eiaf *)buf;
7749 fprintf (file,
7750 _("Image activator fixup: (major: %u, minor: %u)\n"),
7751 (unsigned)bfd_getl32 (eiaf->majorid),
7752 (unsigned)bfd_getl32 (eiaf->minorid));
7753 fprintf (file, _(" iaflink : 0x%08x %08x\n"),
7754 (unsigned)bfd_getl32 (eiaf->iaflink + 0),
7755 (unsigned)bfd_getl32 (eiaf->iaflink + 4));
7756 fprintf (file, _(" fixuplnk: 0x%08x %08x\n"),
7757 (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
7758 (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
7759 fprintf (file, _(" size : %u\n"),
7760 (unsigned)bfd_getl32 (eiaf->size));
7761 fprintf (file, _(" flags: 0x%08x\n"),
7762 (unsigned)bfd_getl32 (eiaf->flags));
7763 qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
7764 lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
7765 fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"),
7766 qrelfixoff, lrelfixoff);
7767 qdotadroff = bfd_getl32 (eiaf->qdotadroff);
7768 ldotadroff = bfd_getl32 (eiaf->ldotadroff);
7769 fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"),
7770 qdotadroff, ldotadroff);
7771 codeadroff = bfd_getl32 (eiaf->codeadroff);
7772 lpfixoff = bfd_getl32 (eiaf->lpfixoff);
7773 fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"),
7774 codeadroff, lpfixoff);
7775 chgprtoff = bfd_getl32 (eiaf->chgprtoff);
7776 fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff);
7777 shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
7778 shlstoff = bfd_getl32 (eiaf->shlstoff);
7779 fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"),
7780 shlstoff, shrimgcnt);
7781 fprintf (file, _(" shlextra : %5u, permctx : %5u\n"),
7782 (unsigned)bfd_getl32 (eiaf->shlextra),
7783 (unsigned)bfd_getl32 (eiaf->permctx));
7784 fprintf (file, _(" base_va : 0x%08x\n"),
7785 (unsigned)bfd_getl32 (eiaf->base_va));
7786 fprintf (file, _(" lppsbfixoff: %5u\n"),
7787 (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
7789 if (shlstoff)
7791 struct vms_shl *shl = (struct vms_shl *)(buf + shlstoff);
7792 unsigned int j;
7794 fprintf (file, _(" Shareable images:\n"));
7795 for (j = 0; j < shrimgcnt; j++, shl++)
7797 fprintf (file,
7798 _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"),
7799 j, shl->size, shl->flags,
7800 shl->imgnam[0], shl->imgnam + 1);
7803 if (qrelfixoff != 0)
7805 fprintf (file, _(" quad-word relocation fixups:\n"));
7806 evax_bfd_print_relocation_records (file, buf + qrelfixoff, 8);
7808 if (lrelfixoff != 0)
7810 fprintf (file, _(" long-word relocation fixups:\n"));
7811 evax_bfd_print_relocation_records (file, buf + lrelfixoff, 4);
7813 if (qdotadroff != 0)
7815 fprintf (file, _(" quad-word .address reference fixups:\n"));
7816 evax_bfd_print_address_fixups (file, buf + qdotadroff);
7818 if (ldotadroff != 0)
7820 fprintf (file, _(" long-word .address reference fixups:\n"));
7821 evax_bfd_print_address_fixups (file, buf + ldotadroff);
7823 if (codeadroff != 0)
7825 fprintf (file, _(" Code Address Reference Fixups:\n"));
7826 evax_bfd_print_reference_fixups (file, buf + codeadroff);
7828 if (lpfixoff != 0)
7830 fprintf (file, _(" Linkage Pairs Referece Fixups:\n"));
7831 evax_bfd_print_reference_fixups (file, buf + lpfixoff);
7833 if (chgprtoff)
7835 unsigned int count = (unsigned)bfd_getl32 (buf + chgprtoff);
7836 struct vms_eicp *eicp = (struct vms_eicp *)(buf + chgprtoff + 4);
7837 unsigned int j;
7839 fprintf (file, _(" Change Protection (%u entries):\n"), count);
7840 for (j = 0; j < count; j++, eicp++)
7842 unsigned int prot = bfd_getl32 (eicp->newprt);
7843 fprintf (file,
7844 _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
7845 (unsigned)bfd_getl32 (eicp->baseva + 4),
7846 (unsigned)bfd_getl32 (eicp->baseva + 0),
7847 (unsigned)bfd_getl32 (eicp->size),
7848 (unsigned)bfd_getl32 (eicp->newprt));
7849 switch (prot)
7851 case PRT__C_NA:
7852 fprintf (file, "NA");
7853 break;
7854 case PRT__C_RESERVED:
7855 fprintf (file, "RES");
7856 break;
7857 case PRT__C_KW:
7858 fprintf (file, "KW");
7859 break;
7860 case PRT__C_KR:
7861 fprintf (file, "KR");
7862 break;
7863 case PRT__C_UW:
7864 fprintf (file, "UW");
7865 break;
7866 case PRT__C_EW:
7867 fprintf (file, "EW");
7868 break;
7869 case PRT__C_ERKW:
7870 fprintf (file, "ERKW");
7871 break;
7872 case PRT__C_ER:
7873 fprintf (file, "ER");
7874 break;
7875 case PRT__C_SW:
7876 fprintf (file, "SW");
7877 break;
7878 case PRT__C_SREW:
7879 fprintf (file, "SREW");
7880 break;
7881 case PRT__C_SRKW:
7882 fprintf (file, "SRKW");
7883 break;
7884 case PRT__C_SR:
7885 fprintf (file, "SR");
7886 break;
7887 case PRT__C_URSW:
7888 fprintf (file, "URSW");
7889 break;
7890 case PRT__C_UREW:
7891 fprintf (file, "UREW");
7892 break;
7893 case PRT__C_URKW:
7894 fprintf (file, "URKW");
7895 break;
7896 case PRT__C_UR:
7897 fprintf (file, "UR");
7898 break;
7899 default:
7900 fputs ("??", file);
7901 break;
7903 fputc ('\n', file);
7906 free (buf);
7910 static bfd_boolean
7911 vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
7913 FILE *file = (FILE *)ptr;
7915 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
7916 evax_bfd_print_image (abfd, file);
7917 else
7919 if (bfd_seek (abfd, 0, SEEK_SET))
7920 return FALSE;
7921 evax_bfd_print_eobj (abfd, file);
7923 return TRUE;
7926 /* Linking. */
7928 /* Slurp ETIR/EDBG/ETBT VMS object records. */
7930 static bfd_boolean
7931 alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
7933 asection *cur_section;
7934 file_ptr cur_offset;
7935 asection *dst_section;
7936 file_ptr dst_offset;
7938 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
7939 return FALSE;
7941 cur_section = NULL;
7942 cur_offset = 0;
7944 dst_section = PRIV (dst_section);
7945 dst_offset = 0;
7946 if (info)
7948 if (info->strip == strip_all || info->strip == strip_debugger)
7950 /* Discard the DST section. */
7951 dst_offset = 0;
7952 dst_section = NULL;
7954 else if (dst_section)
7956 dst_offset = dst_section->output_offset;
7957 dst_section = dst_section->output_section;
7961 while (1)
7963 int type;
7964 bfd_boolean res;
7966 type = _bfd_vms_get_object_record (abfd);
7967 if (type < 0)
7969 vms_debug2 ((2, "next_record failed\n"));
7970 return FALSE;
7972 switch (type)
7974 case EOBJ__C_ETIR:
7975 PRIV (image_section) = cur_section;
7976 PRIV (image_offset) = cur_offset;
7977 res = _bfd_vms_slurp_etir (abfd, info);
7978 cur_section = PRIV (image_section);
7979 cur_offset = PRIV (image_offset);
7980 break;
7981 case EOBJ__C_EDBG:
7982 case EOBJ__C_ETBT:
7983 if (dst_section == NULL)
7984 continue;
7985 PRIV (image_section) = dst_section;
7986 PRIV (image_offset) = dst_offset;
7987 res = _bfd_vms_slurp_etir (abfd, info);
7988 dst_offset = PRIV (image_offset);
7989 break;
7990 case EOBJ__C_EEOM:
7991 return TRUE;
7992 default:
7993 continue;
7995 if (!res)
7997 vms_debug2 ((2, "slurp eobj type %d failed\n", type));
7998 return FALSE;
8003 static int
8004 alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
8005 struct bfd_link_info *info ATTRIBUTE_UNUSED)
8007 return 0;
8010 /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */
8012 static void
8013 alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib)
8015 struct alpha_vms_shlib_el *sl;
8016 asection *sect = PRIV2 (src, image_section);
8017 file_ptr offset = PRIV2 (src, image_offset);
8019 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8020 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8021 sl->has_fixups = TRUE;
8022 VEC_APPEND_EL (sl->lp, bfd_vma,
8023 sect->output_section->vma + sect->output_offset + offset);
8024 sect->output_section->flags |= SEC_RELOC;
8027 /* Add a code address fixup at address SECT + OFFSET to SHLIB. */
8029 static void
8030 alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib)
8032 struct alpha_vms_shlib_el *sl;
8033 asection *sect = PRIV2 (src, image_section);
8034 file_ptr offset = PRIV2 (src, image_offset);
8036 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8037 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8038 sl->has_fixups = TRUE;
8039 VEC_APPEND_EL (sl->ca, bfd_vma,
8040 sect->output_section->vma + sect->output_offset + offset);
8041 sect->output_section->flags |= SEC_RELOC;
8044 /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */
8046 static void
8047 alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
8048 bfd *shlib, bfd_vma vec)
8050 struct alpha_vms_shlib_el *sl;
8051 struct alpha_vms_vma_ref *r;
8052 asection *sect = PRIV2 (src, image_section);
8053 file_ptr offset = PRIV2 (src, image_offset);
8055 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
8056 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
8057 sl->has_fixups = TRUE;
8058 r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref);
8059 r->vma = sect->output_section->vma + sect->output_offset + offset;
8060 r->ref = vec;
8061 sect->output_section->flags |= SEC_RELOC;
8064 static void
8065 alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED,
8066 unsigned int shr ATTRIBUTE_UNUSED,
8067 bfd_vma vec ATTRIBUTE_UNUSED)
8069 /* Not yet supported. */
8070 abort ();
8073 /* Add relocation. FIXME: Not yet emitted. */
8075 static void
8076 alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
8080 static void
8081 alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
8085 static struct bfd_hash_entry *
8086 alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry,
8087 struct bfd_hash_table *table,
8088 const char *string)
8090 struct alpha_vms_link_hash_entry *ret =
8091 (struct alpha_vms_link_hash_entry *) entry;
8093 /* Allocate the structure if it has not already been allocated by a
8094 subclass. */
8095 if (ret == NULL)
8096 ret = ((struct alpha_vms_link_hash_entry *)
8097 bfd_hash_allocate (table,
8098 sizeof (struct alpha_vms_link_hash_entry)));
8099 if (ret == NULL)
8100 return NULL;
8102 /* Call the allocation method of the superclass. */
8103 ret = ((struct alpha_vms_link_hash_entry *)
8104 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
8105 table, string));
8107 ret->sym = NULL;
8109 return (struct bfd_hash_entry *) ret;
8112 /* Create an Alpha/VMS link hash table. */
8114 static struct bfd_link_hash_table *
8115 alpha_vms_bfd_link_hash_table_create (bfd *abfd)
8117 struct alpha_vms_link_hash_table *ret;
8118 bfd_size_type amt = sizeof (struct alpha_vms_link_hash_table);
8120 ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt);
8121 if (ret == NULL)
8122 return NULL;
8123 if (!_bfd_link_hash_table_init (&ret->root, abfd,
8124 alpha_vms_link_hash_newfunc,
8125 sizeof (struct alpha_vms_link_hash_entry)))
8127 free (ret);
8128 return NULL;
8131 VEC_INIT (ret->shrlibs);
8132 ret->fixup = NULL;
8134 return &ret->root;
8137 static bfd_boolean
8138 alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
8140 unsigned int i;
8142 for (i = 0; i < PRIV (gsd_sym_count); i++)
8144 struct vms_symbol_entry *e = PRIV (syms)[i];
8145 struct alpha_vms_link_hash_entry *h;
8146 struct bfd_link_hash_entry *h_root;
8147 asymbol sym;
8149 if (!alpha_vms_convert_symbol (abfd, e, &sym))
8150 return FALSE;
8152 if ((e->flags & EGSY__V_DEF) && abfd->selective_search)
8154 /* In selective_search mode, only add definition that are
8155 required. */
8156 h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup
8157 (info->hash, sym.name, FALSE, FALSE, FALSE);
8158 if (h == NULL || h->root.type != bfd_link_hash_undefined)
8159 continue;
8161 else
8162 h = NULL;
8164 h_root = (struct bfd_link_hash_entry *) h;
8165 if (_bfd_generic_link_add_one_symbol
8166 (info, abfd, sym.name, sym.flags, sym.section, sym.value,
8167 NULL, FALSE, FALSE, &h_root) == FALSE)
8168 return FALSE;
8169 h = (struct alpha_vms_link_hash_entry *) h_root;
8171 if ((e->flags & EGSY__V_DEF)
8172 && h->sym == NULL
8173 && abfd->xvec == info->output_bfd->xvec)
8174 h->sym = e;
8177 if (abfd->flags & DYNAMIC)
8179 struct alpha_vms_shlib_el *shlib;
8181 /* We do not want to include any of the sections in a dynamic
8182 object in the output file. See comment in elflink.c. */
8183 bfd_section_list_clear (abfd);
8185 shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs,
8186 struct alpha_vms_shlib_el);
8187 shlib->abfd = abfd;
8188 VEC_INIT (shlib->ca);
8189 VEC_INIT (shlib->lp);
8190 VEC_INIT (shlib->qr);
8191 PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1;
8194 return TRUE;
8197 static bfd_boolean
8198 alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
8200 int pass;
8201 struct bfd_link_hash_entry **pundef;
8202 struct bfd_link_hash_entry **next_pundef;
8204 /* We only accept VMS libraries. */
8205 if (info->output_bfd->xvec != abfd->xvec)
8207 bfd_set_error (bfd_error_wrong_format);
8208 return FALSE;
8211 /* The archive_pass field in the archive itself is used to
8212 initialize PASS, since we may search the same archive multiple
8213 times. */
8214 pass = ++abfd->archive_pass;
8216 /* Look through the list of undefined symbols. */
8217 for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
8219 struct bfd_link_hash_entry *h;
8220 symindex symidx;
8221 bfd *element;
8222 bfd *orig_element;
8224 h = *pundef;
8225 next_pundef = &(*pundef)->u.undef.next;
8227 /* When a symbol is defined, it is not necessarily removed from
8228 the list. */
8229 if (h->type != bfd_link_hash_undefined
8230 && h->type != bfd_link_hash_common)
8232 /* Remove this entry from the list, for general cleanliness
8233 and because we are going to look through the list again
8234 if we search any more libraries. We can't remove the
8235 entry if it is the tail, because that would lose any
8236 entries we add to the list later on. */
8237 if (*pundef != info->hash->undefs_tail)
8239 *pundef = *next_pundef;
8240 next_pundef = pundef;
8242 continue;
8245 /* Look for this symbol in the archive hash table. */
8246 symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string);
8247 if (symidx == BFD_NO_MORE_SYMBOLS)
8249 /* Nothing in this slot. */
8250 continue;
8253 element = bfd_get_elt_at_index (abfd, symidx);
8254 if (element == NULL)
8255 return FALSE;
8257 if (element->archive_pass == -1 || element->archive_pass == pass)
8258 continue;
8260 if (! bfd_check_format (element, bfd_object))
8262 element->archive_pass = -1;
8263 return FALSE;
8266 orig_element = element;
8267 if (bfd_is_thin_archive (abfd))
8269 element = _bfd_vms_lib_get_imagelib_file (element);
8270 if (element == NULL || !bfd_check_format (element, bfd_object))
8272 orig_element->archive_pass = -1;
8273 return FALSE;
8277 /* Unlike the generic linker, we know that this element provides
8278 a definition for an undefined symbol and we know that we want
8279 to include it. We don't need to check anything. */
8280 if (! (*info->callbacks->add_archive_element) (info, element,
8281 h->root.string))
8282 return FALSE;
8283 if (! alpha_vms_link_add_object_symbols (element, info))
8284 return FALSE;
8286 orig_element->archive_pass = pass;
8289 return TRUE;
8292 static bfd_boolean
8293 alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
8295 switch (bfd_get_format (abfd))
8297 case bfd_object:
8298 vms_debug2 ((2, "vms_link_add_symbols for object %s\n",
8299 abfd->filename));
8300 return alpha_vms_link_add_object_symbols (abfd, info);
8301 break;
8302 case bfd_archive:
8303 vms_debug2 ((2, "vms_link_add_symbols for archive %s\n",
8304 abfd->filename));
8305 return alpha_vms_link_add_archive_symbols (abfd, info);
8306 break;
8307 default:
8308 bfd_set_error (bfd_error_wrong_format);
8309 return FALSE;
8313 static bfd_boolean
8314 alpha_vms_build_fixups (struct bfd_link_info *info)
8316 struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info);
8317 unsigned char *content;
8318 unsigned int i;
8319 unsigned int sz = 0;
8320 unsigned int lp_sz = 0;
8321 unsigned int ca_sz = 0;
8322 unsigned int qr_sz = 0;
8323 unsigned int shrimg_cnt = 0;
8324 unsigned int chgprt_num = 0;
8325 unsigned int chgprt_sz = 0;
8326 struct vms_eiaf *eiaf;
8327 unsigned int off;
8328 asection *sec;
8330 /* Shared libraries. */
8331 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8333 struct alpha_vms_shlib_el *shlib;
8335 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8337 if (!shlib->has_fixups)
8338 continue;
8340 shrimg_cnt++;
8342 if (VEC_COUNT (shlib->ca) > 0)
8344 /* Header + entries. */
8345 ca_sz += 8;
8346 ca_sz += VEC_COUNT (shlib->ca) * 4;
8348 if (VEC_COUNT (shlib->lp) > 0)
8350 /* Header + entries. */
8351 lp_sz += 8;
8352 lp_sz += VEC_COUNT (shlib->lp) * 4;
8354 if (VEC_COUNT (shlib->qr) > 0)
8356 /* Header + entries. */
8357 qr_sz += 8;
8358 qr_sz += VEC_COUNT (shlib->qr) * 8;
8361 /* Add markers. */
8362 if (ca_sz > 0)
8363 ca_sz += 8;
8364 if (lp_sz > 0)
8365 lp_sz += 8;
8366 if (qr_sz > 0)
8367 qr_sz += 8;
8369 /* Finish now if there is no content. */
8370 if (ca_sz + lp_sz + qr_sz == 0)
8371 return TRUE;
8373 /* Add an eicp entry for the fixup itself. */
8374 chgprt_num = 1;
8375 for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
8377 /* This isect could be made RO or EXE after relocations are applied. */
8378 if ((sec->flags & SEC_RELOC) != 0
8379 && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
8380 chgprt_num++;
8382 chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp);
8384 /* Allocate section content (round-up size) */
8385 sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl)
8386 + ca_sz + lp_sz + qr_sz + chgprt_sz;
8387 sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
8388 content = bfd_zalloc (info->output_bfd, sz);
8389 if (content == NULL)
8390 return FALSE;
8392 sec = alpha_vms_link_hash (info)->fixup;
8393 sec->contents = content;
8394 sec->size = sz;
8396 eiaf = (struct vms_eiaf *)content;
8397 off = sizeof (struct vms_eiaf);
8398 bfd_putl32 (0, eiaf->majorid);
8399 bfd_putl32 (0, eiaf->minorid);
8400 bfd_putl32 (0, eiaf->iaflink);
8401 bfd_putl32 (0, eiaf->fixuplnk);
8402 bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size);
8403 bfd_putl32 (0, eiaf->flags);
8404 bfd_putl32 (0, eiaf->qrelfixoff);
8405 bfd_putl32 (0, eiaf->lrelfixoff);
8406 bfd_putl32 (0, eiaf->qdotadroff);
8407 bfd_putl32 (0, eiaf->ldotadroff);
8408 bfd_putl32 (0, eiaf->codeadroff);
8409 bfd_putl32 (0, eiaf->lpfixoff);
8410 bfd_putl32 (0, eiaf->chgprtoff);
8411 bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff);
8412 bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt);
8413 bfd_putl32 (0, eiaf->shlextra);
8414 bfd_putl32 (0, eiaf->permctx);
8415 bfd_putl32 (0, eiaf->base_va);
8416 bfd_putl32 (0, eiaf->lppsbfixoff);
8418 if (shrimg_cnt)
8420 shrimg_cnt = 0;
8422 /* Write shl. */
8423 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8425 struct alpha_vms_shlib_el *shlib;
8426 struct vms_shl *shl;
8428 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8430 if (!shlib->has_fixups)
8431 continue;
8433 /* Renumber shared images. */
8434 PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++;
8436 shl = (struct vms_shl *)(content + off);
8437 bfd_putl32 (0, shl->baseva);
8438 bfd_putl32 (0, shl->shlptr);
8439 bfd_putl32 (0, shl->ident);
8440 bfd_putl32 (0, shl->permctx);
8441 shl->size = sizeof (struct vms_shl);
8442 bfd_putl16 (0, shl->fill_1);
8443 shl->flags = 0;
8444 bfd_putl32 (0, shl->icb);
8445 shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name));
8446 memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name),
8447 shl->imgnam[0]);
8449 off += sizeof (struct vms_shl);
8452 /* CA fixups. */
8453 if (ca_sz != 0)
8455 bfd_putl32 (off, eiaf->codeadroff);
8457 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8459 struct alpha_vms_shlib_el *shlib;
8460 unsigned int j;
8462 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8464 if (VEC_COUNT (shlib->ca) == 0)
8465 continue;
8467 bfd_putl32 (VEC_COUNT (shlib->ca), content + off);
8468 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8469 off += 8;
8471 for (j = 0; j < VEC_COUNT (shlib->ca); j++)
8473 bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr,
8474 content + off);
8475 off += 4;
8479 bfd_putl32 (0, content + off);
8480 bfd_putl32 (0, content + off + 4);
8481 off += 8;
8484 /* LP fixups. */
8485 if (lp_sz != 0)
8487 bfd_putl32 (off, eiaf->lpfixoff);
8489 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8491 struct alpha_vms_shlib_el *shlib;
8492 unsigned int j;
8494 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8496 if (VEC_COUNT (shlib->lp) == 0)
8497 continue;
8499 bfd_putl32 (VEC_COUNT (shlib->lp), content + off);
8500 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8501 off += 8;
8503 for (j = 0; j < VEC_COUNT (shlib->lp); j++)
8505 bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr,
8506 content + off);
8507 off += 4;
8511 bfd_putl32 (0, content + off);
8512 bfd_putl32 (0, content + off + 4);
8513 off += 8;
8516 /* QR fixups. */
8517 if (qr_sz != 0)
8519 bfd_putl32 (off, eiaf->qdotadroff);
8521 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8523 struct alpha_vms_shlib_el *shlib;
8524 unsigned int j;
8526 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8528 if (VEC_COUNT (shlib->qr) == 0)
8529 continue;
8531 bfd_putl32 (VEC_COUNT (shlib->qr), content + off);
8532 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8533 off += 8;
8535 for (j = 0; j < VEC_COUNT (shlib->qr); j++)
8537 struct alpha_vms_vma_ref *r;
8538 r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j);
8539 bfd_putl32 (r->vma - t->base_addr, content + off);
8540 bfd_putl32 (r->ref, content + off + 4);
8541 off += 8;
8545 bfd_putl32 (0, content + off);
8546 bfd_putl32 (0, content + off + 4);
8547 off += 8;
8551 /* Write the change protection table. */
8552 bfd_putl32 (off, eiaf->chgprtoff);
8553 bfd_putl32 (chgprt_num, content + off);
8554 off += 4;
8556 for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
8558 struct vms_eicp *eicp;
8559 unsigned int prot;
8561 if ((sec->flags & SEC_LINKER_CREATED) != 0 &&
8562 strcmp (sec->name, "$FIXUP$") == 0)
8563 prot = PRT__C_UREW;
8564 else if ((sec->flags & SEC_RELOC) != 0
8565 && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
8566 prot = PRT__C_UR;
8567 else
8568 continue;
8570 eicp = (struct vms_eicp *)(content + off);
8571 bfd_putl64 (sec->vma - t->base_addr, eicp->baseva);
8572 bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1),
8573 eicp->size);
8574 bfd_putl32 (prot, eicp->newprt);
8575 off += sizeof (struct vms_eicp);
8578 return TRUE;
8581 /* Called by bfd_link_hash_traverse to fill the symbol table.
8582 Return FALSE in case of failure. */
8584 static bfd_boolean
8585 alpha_vms_link_output_symbol (struct bfd_link_hash_entry *hc, void *infov)
8587 struct bfd_link_info *info = (struct bfd_link_info *)infov;
8588 struct alpha_vms_link_hash_entry *h = (struct alpha_vms_link_hash_entry *)hc;
8589 struct vms_symbol_entry *sym;
8591 switch (h->root.type)
8593 case bfd_link_hash_new:
8594 case bfd_link_hash_undefined:
8595 abort ();
8596 case bfd_link_hash_undefweak:
8597 return TRUE;
8598 case bfd_link_hash_defined:
8599 case bfd_link_hash_defweak:
8601 asection *sec = h->root.u.def.section;
8603 /* FIXME: this is certainly a symbol from a dynamic library. */
8604 if (bfd_is_abs_section (sec))
8605 return TRUE;
8607 if (sec->owner->flags & DYNAMIC)
8608 return TRUE;
8610 break;
8611 case bfd_link_hash_common:
8612 break;
8613 case bfd_link_hash_indirect:
8614 case bfd_link_hash_warning:
8615 return TRUE;
8618 /* Do not write not kept symbols. */
8619 if (info->strip == strip_some
8620 && bfd_hash_lookup (info->keep_hash, h->root.root.string,
8621 FALSE, FALSE) != NULL)
8622 return TRUE;
8624 if (h->sym == NULL)
8626 /* This symbol doesn't come from a VMS object. So we suppose it is
8627 a data. */
8628 int len = strlen (h->root.root.string);
8630 sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd,
8631 sizeof (*sym) + len);
8632 if (sym == NULL)
8633 abort ();
8634 sym->namelen = len;
8635 memcpy (sym->name, h->root.root.string, len);
8636 sym->name[len] = 0;
8637 sym->owner = info->output_bfd;
8639 sym->typ = EGSD__C_SYMG;
8640 sym->data_type = 0;
8641 sym->flags = EGSY__V_DEF | EGSY__V_REL;
8642 sym->symbol_vector = h->root.u.def.value;
8643 sym->section = h->root.u.def.section;
8644 sym->value = h->root.u.def.value;
8646 else
8647 sym = h->sym;
8649 if (!add_symbol_entry (info->output_bfd, sym))
8650 return FALSE;
8652 return TRUE;
8655 static bfd_boolean
8656 alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
8658 asection *o;
8659 struct bfd_link_order *p;
8660 bfd *sub;
8661 asection *fixupsec;
8662 bfd_vma base_addr;
8663 bfd_vma last_addr;
8664 asection *dst;
8665 asection *dmt;
8667 if (info->relocatable)
8669 /* FIXME: we do not yet support relocatable link. It is not obvious
8670 how to do it for debug infos. */
8671 (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n"));
8672 return FALSE;
8675 bfd_get_outsymbols (abfd) = NULL;
8676 bfd_get_symcount (abfd) = 0;
8678 /* Mark all sections which will be included in the output file. */
8679 for (o = abfd->sections; o != NULL; o = o->next)
8680 for (p = o->map_head.link_order; p != NULL; p = p->next)
8681 if (p->type == bfd_indirect_link_order)
8682 p->u.indirect.section->linker_mark = TRUE;
8684 #if 0
8685 /* Handle all the link order information for the sections. */
8686 for (o = abfd->sections; o != NULL; o = o->next)
8688 printf ("For section %s (at 0x%08x, flags=0x%08x):\n",
8689 o->name, (unsigned)o->vma, (unsigned)o->flags);
8691 for (p = o->map_head.link_order; p != NULL; p = p->next)
8693 printf (" at 0x%08x - 0x%08x: ",
8694 (unsigned)p->offset, (unsigned)(p->offset + p->size - 1));
8695 switch (p->type)
8697 case bfd_section_reloc_link_order:
8698 case bfd_symbol_reloc_link_order:
8699 printf (" section/symbol reloc\n");
8700 break;
8701 case bfd_indirect_link_order:
8702 printf (" section %s of %s\n",
8703 p->u.indirect.section->name,
8704 p->u.indirect.section->owner->filename);
8705 break;
8706 case bfd_data_link_order:
8707 printf (" explicit data\n");
8708 break;
8709 default:
8710 printf (" *unknown* type %u\n", p->type);
8711 break;
8715 #endif
8717 /* Generate the symbol table. */
8718 BFD_ASSERT (PRIV (syms) == NULL);
8719 if (info->strip != strip_all)
8720 bfd_link_hash_traverse (info->hash, alpha_vms_link_output_symbol, info);
8722 /* Find the entry point. */
8723 if (bfd_get_start_address (abfd) == 0)
8725 bfd *startbfd = NULL;
8727 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8729 /* Consider only VMS object files. */
8730 if (sub->xvec != abfd->xvec)
8731 continue;
8733 if (!PRIV2 (sub, eom_data).eom_has_transfer)
8734 continue;
8735 if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd)
8736 continue;
8737 if (startbfd != NULL
8738 && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR))
8740 (*info->callbacks->einfo)
8741 (_("%P: multiple entry points: in modules %B and %B\n"),
8742 startbfd, sub);
8743 continue;
8745 startbfd = sub;
8748 if (startbfd)
8750 unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx;
8751 bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr;
8752 asection *sec;
8754 sec = PRIV2 (startbfd, sections)[ps_idx];
8756 bfd_set_start_address
8757 (abfd, sec->output_section->vma + sec->output_offset + tfradr);
8761 /* Set transfer addresses. */
8763 int i;
8764 struct bfd_link_hash_entry *h;
8766 i = 0;
8767 PRIV (transfer_address[i++]) = 0xffffffff00000340ULL; /* SYS$IMGACT */
8768 h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", FALSE, FALSE, TRUE);
8769 if (h != NULL && h->type == bfd_link_hash_defined)
8770 PRIV (transfer_address[i++]) =
8771 alpha_vms_get_sym_value (h->u.def.section, h->u.def.value);
8772 PRIV (transfer_address[i++]) = bfd_get_start_address (abfd);
8773 while (i < 4)
8774 PRIV (transfer_address[i++]) = 0;
8777 /* Allocate contents.
8778 Also compute the virtual base address. */
8779 base_addr = (bfd_vma)-1;
8780 last_addr = 0;
8781 for (o = abfd->sections; o != NULL; o = o->next)
8783 if (o->flags & SEC_HAS_CONTENTS)
8785 o->contents = bfd_alloc (abfd, o->size);
8786 if (o->contents == NULL)
8787 return FALSE;
8789 if (o->flags & SEC_LOAD)
8791 if (o->vma < base_addr)
8792 base_addr = o->vma;
8793 if (o->vma + o->size > last_addr)
8794 last_addr = o->vma + o->size;
8796 /* Clear the RELOC flags. Currently we don't support incremental
8797 linking. We use the RELOC flag for computing the eicp entries. */
8798 o->flags &= ~SEC_RELOC;
8801 /* Create the fixup section. */
8802 fixupsec = bfd_make_section_anyway_with_flags
8803 (info->output_bfd, "$FIXUP$",
8804 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
8805 if (fixupsec == NULL)
8806 return FALSE;
8807 last_addr = (last_addr + 0xffff) & ~0xffff;
8808 fixupsec->vma = last_addr;
8810 alpha_vms_link_hash (info)->fixup = fixupsec;
8811 alpha_vms_link_hash (info)->base_addr = base_addr;
8813 /* Create the DMT section, if necessary. */
8814 BFD_ASSERT (PRIV (dst_section) == NULL);
8815 dst = bfd_get_section_by_name (abfd, "$DST$");
8816 if (dst != NULL && dst->size == 0)
8817 dst = NULL;
8818 if (dst != NULL)
8820 PRIV (dst_section) = dst;
8821 dmt = bfd_make_section_anyway_with_flags
8822 (info->output_bfd, "$DMT$",
8823 SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
8824 if (dmt == NULL)
8825 return FALSE;
8827 else
8828 dmt = NULL;
8830 /* Read all sections from the inputs. */
8831 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8833 if (sub->flags & DYNAMIC)
8835 alpha_vms_create_eisd_for_shared (abfd, sub);
8836 continue;
8839 if (!alpha_vms_read_sections_content (sub, info))
8840 return FALSE;
8843 /* Handle all the link order information for the sections.
8844 Note: past this point, it is not possible to create new sections. */
8845 for (o = abfd->sections; o != NULL; o = o->next)
8847 for (p = o->map_head.link_order; p != NULL; p = p->next)
8849 switch (p->type)
8851 case bfd_section_reloc_link_order:
8852 case bfd_symbol_reloc_link_order:
8853 abort ();
8854 return FALSE;
8855 case bfd_indirect_link_order:
8856 /* Already done. */
8857 break;
8858 default:
8859 if (! _bfd_default_link_order (abfd, info, o, p))
8860 return FALSE;
8861 break;
8866 /* Compute fixups. */
8867 if (!alpha_vms_build_fixups (info))
8868 return FALSE;
8870 /* Compute the DMT. */
8871 if (dmt != NULL)
8873 int pass;
8874 unsigned char *contents = NULL;
8876 /* In pass 1, compute the size. In pass 2, write the DMT contents. */
8877 for (pass = 0; pass < 2; pass++)
8879 unsigned int off = 0;
8881 /* For each object file (ie for each module). */
8882 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8884 asection *sub_dst;
8885 struct vms_dmt_header *dmth = NULL;
8886 unsigned int psect_count;
8888 /* Skip this module if it has no DST. */
8889 sub_dst = PRIV2 (sub, dst_section);
8890 if (sub_dst == NULL || sub_dst->size == 0)
8891 continue;
8893 if (pass == 1)
8895 /* Write the header. */
8896 dmth = (struct vms_dmt_header *)(contents + off);
8897 bfd_putl32 (sub_dst->output_offset, dmth->modbeg);
8898 bfd_putl32 (sub_dst->size, dmth->size);
8901 off += sizeof (struct vms_dmt_header);
8902 psect_count = 0;
8904 /* For each section (ie for each psect). */
8905 for (o = sub->sections; o != NULL; o = o->next)
8907 /* Only consider interesting sections. */
8908 if (!(o->flags & SEC_ALLOC))
8909 continue;
8910 if (o->flags & SEC_LINKER_CREATED)
8911 continue;
8913 if (pass == 1)
8915 /* Write an entry. */
8916 struct vms_dmt_psect *dmtp;
8918 dmtp = (struct vms_dmt_psect *)(contents + off);
8919 bfd_putl32 (o->output_offset + o->output_section->vma,
8920 dmtp->start);
8921 bfd_putl32 (o->size, dmtp->length);
8922 psect_count++;
8924 off += sizeof (struct vms_dmt_psect);
8926 if (pass == 1)
8927 bfd_putl32 (psect_count, dmth->psect_count);
8930 if (pass == 0)
8932 contents = bfd_zalloc (info->output_bfd, off);
8933 if (contents == NULL)
8934 return FALSE;
8935 dmt->contents = contents;
8936 dmt->size = off;
8938 else
8940 BFD_ASSERT (off == dmt->size);
8945 return TRUE;
8948 /* Read the contents of a section.
8949 buf points to a buffer of buf_size bytes to be filled with
8950 section data (starting at offset into section) */
8952 static bfd_boolean
8953 alpha_vms_get_section_contents (bfd *abfd, asection *section,
8954 void *buf, file_ptr offset,
8955 bfd_size_type count)
8957 asection *sec;
8959 /* Image are easy. */
8960 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
8961 return _bfd_generic_get_section_contents (abfd, section,
8962 buf, offset, count);
8964 /* Safety check. */
8965 if (offset + count < count
8966 || offset + count > section->size)
8968 bfd_set_error (bfd_error_invalid_operation);
8969 return FALSE;
8972 /* Alloc in memory and read ETIRs. */
8973 BFD_ASSERT (section->contents == NULL);
8975 for (sec = abfd->sections; sec; sec = sec->next)
8977 BFD_ASSERT (sec->contents == NULL);
8979 if (sec->size != 0 && (sec->flags & SEC_HAS_CONTENTS))
8981 sec->contents = bfd_alloc (abfd, sec->size);
8982 if (sec->contents == NULL)
8983 return FALSE;
8986 if (!alpha_vms_read_sections_content (abfd, NULL))
8987 return FALSE;
8988 for (sec = abfd->sections; sec; sec = sec->next)
8989 if (section->contents)
8990 section->flags |= SEC_IN_MEMORY;
8991 memcpy (buf, section->contents + offset, count);
8992 return TRUE;
8996 /* Set the format of a file being written. */
8998 static bfd_boolean
8999 alpha_vms_mkobject (bfd * abfd)
9001 const bfd_arch_info_type *arch;
9003 vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd));
9005 if (!vms_initialize (abfd))
9006 return FALSE;
9008 PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE);
9009 if (PRIV (recwr.buf) == NULL)
9010 return FALSE;
9012 arch = bfd_scan_arch ("alpha");
9014 if (arch == 0)
9016 bfd_set_error (bfd_error_wrong_format);
9017 return FALSE;
9020 abfd->arch_info = arch;
9021 return TRUE;
9025 /* 4.1, generic. */
9027 /* Called when the BFD is being closed to do any necessary cleanup. */
9029 static bfd_boolean
9030 vms_close_and_cleanup (bfd * abfd)
9032 vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
9034 if (abfd == NULL || abfd->tdata.any == NULL)
9035 return TRUE;
9037 if (abfd->format == bfd_archive)
9039 bfd_release (abfd, abfd->tdata.any);
9040 abfd->tdata.any = NULL;
9041 return TRUE;
9044 if (PRIV (recrd.buf) != NULL)
9045 free (PRIV (recrd.buf));
9047 if (PRIV (sections) != NULL)
9048 free (PRIV (sections));
9050 bfd_release (abfd, abfd->tdata.any);
9051 abfd->tdata.any = NULL;
9053 #ifdef VMS
9054 if (abfd->direction == write_direction)
9056 /* Last step on VMS is to convert the file to variable record length
9057 format. */
9058 if (bfd_cache_close (abfd) != TRUE)
9059 return FALSE;
9060 if (_bfd_vms_convert_to_var_unix_filename (abfd->filename) != TRUE)
9061 return FALSE;
9063 #endif
9065 return TRUE;
9068 /* Called when a new section is created. */
9070 static bfd_boolean
9071 vms_new_section_hook (bfd * abfd, asection *section)
9073 bfd_size_type amt;
9075 vms_debug2 ((1, "vms_new_section_hook (%p, [%d]%s)\n",
9076 abfd, section->index, section->name));
9078 bfd_set_section_alignment (abfd, section, 0);
9080 vms_debug2 ((7, "%d: %s\n", section->index, section->name));
9082 amt = sizeof (struct vms_section_data_struct);
9083 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
9084 if (section->used_by_bfd == NULL)
9085 return FALSE;
9087 /* Create the section symbol. */
9088 return _bfd_generic_new_section_hook (abfd, section);
9091 /* Part 4.5, symbols. */
9093 /* Print symbol to file according to how. how is one of
9094 bfd_print_symbol_name just print the name
9095 bfd_print_symbol_more print more (???)
9096 bfd_print_symbol_all print all we know, which is not much right now :-). */
9098 static void
9099 vms_print_symbol (bfd * abfd,
9100 void * file,
9101 asymbol *symbol,
9102 bfd_print_symbol_type how)
9104 vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n",
9105 abfd, file, symbol, how));
9107 switch (how)
9109 case bfd_print_symbol_name:
9110 case bfd_print_symbol_more:
9111 fprintf ((FILE *)file," %s", symbol->name);
9112 break;
9114 case bfd_print_symbol_all:
9116 const char *section_name = symbol->section->name;
9118 bfd_print_symbol_vandf (abfd, file, symbol);
9120 fprintf ((FILE *) file," %-8s %s", section_name, symbol->name);
9122 break;
9126 /* Return information about symbol in ret.
9128 fill type, value and name
9129 type:
9130 A absolute
9131 B bss segment symbol
9132 C common symbol
9133 D data segment symbol
9134 f filename
9135 t a static function symbol
9136 T text segment symbol
9137 U undefined
9138 - debug. */
9140 static void
9141 vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
9142 asymbol *symbol,
9143 symbol_info *ret)
9145 asection *sec;
9147 vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret));
9149 sec = symbol->section;
9151 if (ret == NULL)
9152 return;
9154 if (sec == NULL)
9155 ret->type = 'U';
9156 else if (bfd_is_com_section (sec))
9157 ret->type = 'C';
9158 else if (bfd_is_abs_section (sec))
9159 ret->type = 'A';
9160 else if (bfd_is_und_section (sec))
9161 ret->type = 'U';
9162 else if (bfd_is_ind_section (sec))
9163 ret->type = 'I';
9164 else if ((symbol->flags & BSF_FUNCTION)
9165 || (bfd_get_section_flags (abfd, sec) & SEC_CODE))
9166 ret->type = 'T';
9167 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
9168 ret->type = 'D';
9169 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
9170 ret->type = 'B';
9171 else
9172 ret->type = '?';
9174 if (ret->type != 'U')
9175 ret->value = symbol->value + symbol->section->vma;
9176 else
9177 ret->value = 0;
9178 ret->name = symbol->name;
9181 /* Return TRUE if the given symbol sym in the BFD abfd is
9182 a compiler generated local label, else return FALSE. */
9184 static bfd_boolean
9185 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
9186 const char *name)
9188 vms_debug2 ((1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd, name));
9189 return name[0] == '$';
9192 /* Part 4.7, writing an object file. */
9194 /* Sets the contents of the section section in BFD abfd to the data starting
9195 in memory at LOCATION. The data is written to the output section starting
9196 at offset offset for count bytes.
9198 Normally TRUE is returned, else FALSE. Possible error returns are:
9199 o bfd_error_no_contents - The output section does not have the
9200 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
9201 o and some more too */
9203 static bfd_boolean
9204 _bfd_vms_set_section_contents (bfd * abfd,
9205 asection *section,
9206 const void * location,
9207 file_ptr offset,
9208 bfd_size_type count)
9210 if (section->contents == NULL)
9212 section->contents = bfd_alloc (abfd, section->size);
9213 if (section->contents == NULL)
9214 return FALSE;
9216 memcpy (section->contents + offset, location, (size_t) count);
9219 return TRUE;
9222 /* Set the architecture and machine type in BFD abfd to arch and mach.
9223 Find the correct pointer to a structure and insert it into the arch_info
9224 pointer. */
9226 static bfd_boolean
9227 alpha_vms_set_arch_mach (bfd *abfd,
9228 enum bfd_architecture arch, unsigned long mach)
9230 if (arch != bfd_arch_alpha
9231 && arch != bfd_arch_unknown)
9232 return FALSE;
9234 return bfd_default_set_arch_mach (abfd, arch, mach);
9237 /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */
9239 void
9240 bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
9241 asection *sec, flagword no_flags, flagword flags)
9243 vms_section_data (sec)->no_flags = no_flags;
9244 vms_section_data (sec)->flags = flags;
9247 struct vms_private_data_struct *
9248 bfd_vms_get_data (bfd *abfd)
9250 return (struct vms_private_data_struct *)abfd->tdata.any;
9253 #define vms_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
9254 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
9255 #define vms_bfd_copy_link_hash_symbol_type \
9256 _bfd_generic_copy_link_hash_symbol_type
9257 #define vms_bfd_is_group_section bfd_generic_is_group_section
9258 #define vms_bfd_discard_group bfd_generic_discard_group
9259 #define vms_section_already_linked _bfd_generic_section_already_linked
9260 #define vms_bfd_define_common_symbol bfd_generic_define_common_symbol
9261 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
9263 #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
9264 #define vms_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
9265 #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
9266 #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
9267 #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
9268 #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
9270 /* Symbols table. */
9271 #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol
9272 #define alpha_vms_bfd_is_target_special_symbol \
9273 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
9274 #define alpha_vms_print_symbol vms_print_symbol
9275 #define alpha_vms_get_symbol_info vms_get_symbol_info
9276 #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols
9277 #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
9278 #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno
9279 #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info
9280 #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
9281 #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_dst_line
9282 #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name
9284 /* Generic table. */
9285 #define alpha_vms_close_and_cleanup vms_close_and_cleanup
9286 #define alpha_vms_bfd_free_cached_info vms_bfd_free_cached_info
9287 #define alpha_vms_new_section_hook vms_new_section_hook
9288 #define alpha_vms_set_section_contents _bfd_vms_set_section_contents
9289 #define alpha_vms_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
9291 #define alpha_vms_bfd_get_relocated_section_contents \
9292 bfd_generic_get_relocated_section_contents
9294 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
9295 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
9296 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
9297 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
9298 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
9299 #define alpha_vms_section_already_linked \
9300 _bfd_generic_section_already_linked
9302 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
9303 #define alpha_vms_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
9304 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
9305 #define alpha_vms_bfd_copy_link_hash_symbol_type \
9306 _bfd_generic_copy_link_hash_symbol_type
9308 #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section
9310 #define alpha_vms_get_dynamic_symtab_upper_bound \
9311 _bfd_nodynamic_get_dynamic_symtab_upper_bound
9312 #define alpha_vms_canonicalize_dynamic_symtab \
9313 _bfd_nodynamic_canonicalize_dynamic_symtab
9314 #define alpha_vms_get_dynamic_reloc_upper_bound \
9315 _bfd_nodynamic_get_dynamic_reloc_upper_bound
9316 #define alpha_vms_canonicalize_dynamic_reloc \
9317 _bfd_nodynamic_canonicalize_dynamic_reloc
9319 const bfd_target vms_alpha_vec =
9321 "vms-alpha", /* Name. */
9322 bfd_target_evax_flavour,
9323 BFD_ENDIAN_LITTLE, /* Data byte order is little. */
9324 BFD_ENDIAN_LITTLE, /* Header byte order is little. */
9326 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS
9327 | WP_TEXT | D_PAGED), /* Object flags. */
9328 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
9329 | SEC_READONLY | SEC_CODE | SEC_DATA
9330 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */
9331 0, /* symbol_leading_char. */
9332 ' ', /* ar_pad_char. */
9333 15, /* ar_max_namelen. */
9334 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
9335 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
9336 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
9337 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
9338 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
9339 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
9341 {_bfd_dummy_target, alpha_vms_object_p, /* bfd_check_format. */
9342 _bfd_vms_lib_alpha_archive_p, _bfd_dummy_target},
9343 {bfd_false, alpha_vms_mkobject, /* bfd_set_format. */
9344 _bfd_vms_lib_alpha_mkarchive, bfd_false},
9345 {bfd_false, alpha_vms_write_object_contents, /* bfd_write_contents. */
9346 _bfd_vms_lib_write_archive_contents, bfd_false},
9348 BFD_JUMP_TABLE_GENERIC (alpha_vms),
9349 BFD_JUMP_TABLE_COPY (vms),
9350 BFD_JUMP_TABLE_CORE (_bfd_nocore),
9351 BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib),
9352 BFD_JUMP_TABLE_SYMBOLS (alpha_vms),
9353 BFD_JUMP_TABLE_RELOCS (alpha_vms),
9354 BFD_JUMP_TABLE_WRITE (alpha_vms),
9355 BFD_JUMP_TABLE_LINK (alpha_vms),
9356 BFD_JUMP_TABLE_DYNAMIC (alpha_vms),
9358 NULL,
9360 (PTR) 0