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. */
26 o Generation of shared image
27 o Generation of GST in image
28 o Relocation optimizations
50 #include "vms/eihvn.h"
51 #include "vms/eobjrec.h"
62 #include "vms/esdfm.h"
63 #include "vms/esdfv.h"
68 #include "vms/internal.h"
71 #define MIN(a,b) ((a) < (b) ? (a) : (b))
73 /* The r_type field in a reloc is one of the following values. */
74 #define ALPHA_R_IGNORE 0
75 #define ALPHA_R_REFQUAD 1
76 #define ALPHA_R_BRADDR 2
77 #define ALPHA_R_HINT 3
78 #define ALPHA_R_SREL16 4
79 #define ALPHA_R_SREL32 5
80 #define ALPHA_R_SREL64 6
81 #define ALPHA_R_OP_PUSH 7
82 #define ALPHA_R_OP_STORE 8
83 #define ALPHA_R_OP_PSUB 9
84 #define ALPHA_R_OP_PRSHIFT 10
85 #define ALPHA_R_LINKAGE 11
86 #define ALPHA_R_REFLONG 12
87 #define ALPHA_R_CODEADDR 13
88 #define ALPHA_R_NOP 14
89 #define ALPHA_R_BSR 15
90 #define ALPHA_R_LDA 16
91 #define ALPHA_R_BOH 17
92 /* These are used with DST_S_C_LINE_NUM. */
93 #define DST_S_C_LINE_NUM_HEADER_SIZE 4
95 /* These are used with DST_S_C_SOURCE */
97 #define DST_S_B_PCLINE_UNSBYTE 1
98 #define DST_S_W_PCLINE_UNSWORD 1
99 #define DST_S_L_PCLINE_UNSLONG 1
101 #define DST_S_B_MODBEG_NAME 14
102 #define DST_S_L_RTNBEG_ADDRESS 5
103 #define DST_S_B_RTNBEG_NAME 13
104 #define DST_S_L_RTNEND_SIZE 5
106 /* These are used with DST_S_C_SOURCE. */
107 #define DST_S_C_SOURCE_HEADER_SIZE 4
109 #define DST_S_B_SRC_DF_LENGTH 1
110 #define DST_S_W_SRC_DF_FILEID 3
111 #define DST_S_B_SRC_DF_FILENAME 20
112 #define DST_S_B_SRC_UNSBYTE 1
113 #define DST_S_W_SRC_UNSWORD 1
114 #define DST_S_L_SRC_UNSLONG 1
116 /* Debugger symbol definitions. */
118 #define DBG_S_L_DMT_MODBEG 0
119 #define DBG_S_L_DST_SIZE 4
120 #define DBG_S_W_DMT_PSECT_COUNT 8
121 #define DBG_S_C_DMT_HEADER_SIZE 12
123 #define DBG_S_L_DMT_PSECT_START 0
124 #define DBG_S_L_DMT_PSECT_LENGTH 4
125 #define DBG_S_C_DMT_PSECT_SIZE 8
127 /* VMS module header. */
143 #define EMH_DATE_LENGTH 17
145 /* VMS End-Of-Module records (EOM/EEOM). */
149 unsigned int eom_l_total_lps;
150 unsigned short eom_w_comcod;
151 bfd_boolean eom_has_transfer;
152 unsigned char eom_b_tfrflg;
153 unsigned int eom_l_psindx;
154 unsigned int eom_l_tfradr;
157 struct vms_symbol_entry
163 unsigned char data_type;
164 unsigned short flags;
166 /* Section and offset/value of the symbol. */
167 unsigned int section;
170 /* Section and offset/value for the entry point (only for subprg). */
171 unsigned int code_section;
172 unsigned int code_value;
174 /* Symbol vector offset. */
175 unsigned int symbol_vector;
177 /* Length of the name. */
178 unsigned char namelen;
183 /* Stack value for push/pop commands. */
191 #define STACKSIZE 128
193 /* A minimal decoding of DST compilation units. We only decode
194 what's needed to get to the line number information. */
204 struct srecinfo *next;
212 struct lineinfo *next;
219 struct funcinfo *next;
227 /* Chain the previously read compilation unit. */
230 /* The module name. */
233 /* The start offset and size of debug info in the DST section. */
237 /* The lowest and highest addresses contained in this compilation
238 unit as specified in the compilation unit header. */
242 /* The listing line table. */
243 struct lineinfo *line_table;
245 /* The source record table. */
246 struct srecinfo *srec_table;
248 /* A list of the functions found in this module. */
249 struct funcinfo *func_table;
251 /* Current allocation of file_table. */
252 unsigned int file_table_count;
254 /* An array of the files making up this module. */
255 struct fileinfo *file_table;
258 /* BFD private data for alpha-vms. */
260 struct vms_private_data_struct
262 /* If true, relocs have been read. */
263 bfd_boolean reloc_done;
265 /* Record input buffer. */
266 struct vms_rec_rd recrd;
267 struct vms_rec_wr recwr;
269 struct hdr_struct hdr_data; /* data from HDR/EMH record */
270 struct eom_struct eom_data; /* data from EOM/EEOM record */
271 unsigned int section_count; /* # of sections in following array */
272 asection **sections; /* array of GSD/EGSD sections */
274 /* Array of raw symbols. */
275 struct vms_symbol_entry **syms;
277 /* Canonicalized symbols. */
280 /* Number of symbols. */
281 unsigned int gsd_sym_count;
282 /* Size of the syms array. */
283 unsigned int max_sym_count;
284 /* Number of procedure symbols. */
285 unsigned int norm_sym_count;
287 /* Stack used to evaluate TIR/ETIR commands. */
288 struct stack_struct *stack;
291 /* Content reading. */
292 asection *image_section; /* section for image_ptr */
293 file_ptr image_offset; /* Offset for image_ptr. */
294 bfd_boolean image_autoextend; /* Resize section if necessary. */
296 struct module *modules; /* list of all compilation units */
298 struct dst_info *dst_info;
299 asection *dst_section;
301 unsigned int dst_ptr_offsets_count; /* # of offsets in following array */
302 unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */
304 /* Shared library support */
305 bfd_vma symvva; /* relative virtual address of symbol vector */
307 unsigned char matchctl;
309 /* Shared library index. This is used for input bfd while linking. */
310 unsigned int shr_index;
312 /* Used to place structures in the file. */
315 /* Simply linked list of eisd. */
316 struct vms_internal_eisd_map *eisd_head;
317 struct vms_internal_eisd_map *eisd_tail;
319 /* Simply linked list of eisd for shared libraries. */
320 struct vms_internal_eisd_map *gbl_eisd_head;
321 struct vms_internal_eisd_map *gbl_eisd_tail;
323 /* linkage index counter used by conditional store commands */
324 int vms_linkage_index;
326 /* see tc-alpha.c of gas for a description. */
327 int flag_hash_long_names; /* -+, hash instead of truncate */
328 int flag_show_after_trunc; /* -H, show hashing/truncation */
331 #define PRIV2(abfd, name) \
332 (((struct vms_private_data_struct *)(abfd)->tdata.any)->name)
333 #define PRIV(name) PRIV2(abfd,name)
336 /* Used to keep extra VMS specific information for a given section.
338 reloc_size holds the size of the relocation stream, note this
339 is very different from the number of relocations as VMS relocations
342 reloc_stream is the actual stream of relocation entries. */
344 struct vms_section_data_struct
346 /* Maximnum number of entries in sec->relocation. */
349 /* Corresponding eisd. Used only while generating executables. */
350 struct vms_internal_eisd_map *eisd;
352 /* PSC flags to be clear. */
355 /* PSC flags to be set. */
359 #define vms_section_data(sec) \
360 ((struct vms_section_data_struct *)sec->used_by_bfd)
362 /* To be called from the debugger. */
363 struct vms_private_data_struct *bfd_vms_get_data (bfd *abfd);
365 static int vms_get_remaining_object_record (bfd *abfd, int read_so_far);
366 static bfd_boolean _bfd_vms_slurp_object_records (bfd * abfd);
367 static void alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *);
368 static void alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *);
369 static void alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *,
371 static void alpha_vms_add_lw_reloc (struct bfd_link_info *info);
372 static void alpha_vms_add_qw_reloc (struct bfd_link_info *info);
373 static void alpha_vms_add_lw_fixup (struct bfd_link_info *, unsigned int,
383 /* Number of elements in VEC. */
385 #define VEC_COUNT(VEC) ((VEC).nbr_el)
387 /* Get the address of the Nth element. */
389 #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N])
391 #define VEC_INIT(VEC) \
398 /* Be sure there is room for a new element. */
400 static void vector_grow1 (struct vector_type *vec, size_t elsz);
402 /* Allocate room for a new element and return its address. */
404 #define VEC_APPEND(VEC, TYPE) \
405 (vector_grow1 (&VEC, sizeof (TYPE)), &VEC_EL(VEC, TYPE, (VEC).nbr_el++))
407 /* Append an element. */
409 #define VEC_APPEND_EL(VEC, TYPE, EL) \
410 (*(VEC_APPEND (VEC, TYPE)) = EL)
412 struct alpha_vms_vma_ref
414 bfd_vma vma; /* Vma in the output. */
415 bfd_vma ref; /* Reference in the input. */
418 struct alpha_vms_shlib_el
421 bfd_boolean has_fixups;
423 struct vector_type lp; /* Vector of bfd_vma. */
424 struct vector_type ca; /* Vector of bfd_vma. */
425 struct vector_type qr; /* Vector of struct alpha_vms_vma_ref. */
428 /* Alpha VMS linker hash table. */
430 struct alpha_vms_link_hash_table
432 struct bfd_link_hash_table root;
434 /* Vector of shared libaries. */
435 struct vector_type shrlibs;
440 /* Base address. Used by fixups. */
444 #define alpha_vms_link_hash(INFO) \
445 ((struct alpha_vms_link_hash_table *)(INFO->hash))
447 /* Alpha VMS linker hash table entry. */
449 struct alpha_vms_link_hash_entry
451 struct bfd_link_hash_entry root;
453 /* Pointer to the original vms symbol. */
454 struct vms_symbol_entry *sym;
459 /* Read & process EIHD record.
460 Return TRUE on success, FALSE on error. */
463 _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset,
464 unsigned int *eihs_offset)
466 unsigned int imgtype, size;
468 struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec);
470 vms_debug2 ((8, "_bfd_vms_slurp_eihd\n"));
472 size = bfd_getl32 (eihd->size);
473 imgtype = bfd_getl32 (eihd->imgtype);
475 if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM)
476 abfd->flags |= EXEC_P;
478 symvva = bfd_getl64 (eihd->symvva);
481 PRIV (symvva) = symvva;
482 abfd->flags |= DYNAMIC;
485 PRIV (ident) = bfd_getl32 (eihd->ident);
486 PRIV (matchctl) = eihd->matchctl;
488 *eisd_offset = bfd_getl32 (eihd->isdoff);
489 *eihs_offset = bfd_getl32 (eihd->symdbgoff);
491 vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n",
492 size, imgtype, (unsigned long)symvva,
493 *eisd_offset, *eihs_offset));
498 /* Read & process EISD record.
499 Return TRUE on success, FALSE on error. */
502 _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
504 int section_count = 0;
506 vms_debug2 ((8, "_bfd_vms_slurp_eisd\n"));
510 struct vms_eisd *eisd;
511 unsigned int rec_size;
513 unsigned long long vaddr;
520 eisd = (struct vms_eisd *)(PRIV (recrd.rec) + offset);
521 rec_size = bfd_getl32 (eisd->eisdsize);
526 /* Skip to next block if pad. */
527 if (rec_size == 0xffffffff)
529 offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
535 size = bfd_getl32 (eisd->secsize);
536 vaddr = bfd_getl64 (eisd->virt_addr);
537 flags = bfd_getl32 (eisd->flags);
538 vbn = bfd_getl32 (eisd->vbn);
540 vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n",
541 offset, size, (unsigned long)vaddr, flags, vbn));
543 /* VMS combines psects from .obj files into isects in the .exe. This
544 process doesn't preserve enough information to reliably determine
545 what's in each section without examining the data. This is
546 especially true of DWARF debug sections. */
547 bfd_flags = SEC_ALLOC;
549 if (flags & EISD__M_EXE)
550 bfd_flags |= SEC_CODE | SEC_HAS_CONTENTS | SEC_LOAD;
552 if (flags & EISD__M_NONSHRADR)
553 bfd_flags |= SEC_DATA | SEC_HAS_CONTENTS | SEC_LOAD;
555 if (!(flags & EISD__M_WRT))
556 bfd_flags |= SEC_READONLY;
558 if (flags & EISD__M_DZRO)
559 bfd_flags |= SEC_DATA;
561 if (flags & EISD__M_FIXUPVEC)
562 bfd_flags |= SEC_DATA | SEC_HAS_CONTENTS | SEC_LOAD;
564 if (flags & EISD__M_CRF)
565 bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD;
567 if (flags & EISD__M_GBL)
569 name = _bfd_vms_save_counted_string (eisd->gblnam);
570 bfd_flags |= SEC_COFF_SHARED_LIBRARY;
571 bfd_flags &= ~(SEC_ALLOC | SEC_LOAD);
573 else if (flags & EISD__M_FIXUPVEC)
575 else if (eisd->type == EISD__K_USRSTACK)
581 name = (char*) bfd_alloc (abfd, 32);
582 if (flags & EISD__M_DZRO)
584 else if (flags & EISD__M_EXE)
586 else if (!(flags & EISD__M_WRT))
590 BFD_ASSERT (section_count < 999);
591 sprintf (name, "$%s_%03d$", pfx, section_count++);
594 section = bfd_make_section (abfd, name);
599 section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0;
600 section->size = size;
601 section->vma = vaddr;
603 if (!bfd_set_section_flags (abfd, section, bfd_flags))
610 /* Read & process EIHS record.
611 Return TRUE on success, FALSE on error. */
614 _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset)
616 unsigned char *p = PRIV (recrd.rec) + offset;
617 unsigned int gstvbn = bfd_getl32 (p + EIHS__L_GSTVBN);
618 unsigned int gstsize ATTRIBUTE_UNUSED = bfd_getl32 (p + EIHS__L_GSTSIZE);
619 unsigned int dstvbn = bfd_getl32 (p + EIHS__L_DSTVBN);
620 unsigned int dstsize = bfd_getl32 (p + EIHS__L_DSTSIZE);
621 unsigned int dmtvbn = bfd_getl32 (p + EIHS__L_DMTVBN);
622 unsigned int dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES);
626 vms_debug (8, "_bfd_vms_slurp_ihs\n");
627 vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n",
628 gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes);
633 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
635 section = bfd_make_section (abfd, "$DST$");
639 section->size = dstsize;
640 section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1);
642 if (!bfd_set_section_flags (abfd, section, bfd_flags))
645 PRIV (dst_section) = section;
646 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
651 flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING;
653 section = bfd_make_section (abfd, "$DMT$");
657 section->size = dmtbytes;
658 section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1);
660 if (!bfd_set_section_flags (abfd, section, bfd_flags))
666 flagword bfd_flags = SEC_HAS_CONTENTS;
668 section = bfd_make_section (abfd, "$GST$");
672 if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET))
674 bfd_set_error (bfd_error_file_truncated);
678 if (_bfd_vms_slurp_object_records (abfd) != TRUE)
681 section->filepos = VMS_BLOCK_SIZE * (gstvbn - 1);
682 section->size = bfd_tell (abfd) - section->filepos;
684 if (!bfd_set_section_flags (abfd, section, bfd_flags))
687 abfd->flags |= HAS_SYMS;
693 /* Object file reading. */
695 /* Object file input functions. */
697 /* Get next record from object file to vms_buf.
698 Set PRIV(buf_size) and return it
700 This is a little tricky since it should be portable.
702 The openVMS object file has 'variable length' which means that
703 read() returns data in chunks of (hopefully) correct and expected
704 size. The linker (and other tools on VMS) depend on that. Unix
705 doesn't know about 'formatted' files, so reading and writing such
706 an object file in a Unix environment is not trivial.
708 With the tool 'file' (available on all VMS FTP sites), one
709 can view and change the attributes of a file. Changing from
710 'variable length' to 'fixed length, 512 bytes' reveals the
711 record size at the first 2 bytes of every record. The same
712 may happen during the transfer of object files from VMS to Unix,
713 at least with UCX, the DEC implementation of TCP/IP.
715 The VMS format repeats the size at bytes 2 & 3 of every record.
717 On the first call (file_format == FF_UNKNOWN) we check if
718 the first and the third byte pair (!) of the record match.
719 If they do it's an object file in an Unix environment or with
720 wrong attributes (FF_FOREIGN), else we should be in a VMS
721 environment where read() returns the record size (FF_NATIVE).
723 Reading is always done in 2 steps:
724 1. first just the record header is read and the size extracted,
725 2. then the read buffer is adjusted and the remaining bytes are
728 All file I/O is done on even file positions. */
730 #define VMS_OBJECT_ADJUSTMENT 2
733 maybe_adjust_record_pointer_for_object (bfd *abfd)
735 /* Set the file format once for all on the first invocation. */
736 if (PRIV (recrd.file_format) == FF_UNKNOWN)
738 if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4]
739 && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5])
740 PRIV (recrd.file_format) = FF_FOREIGN;
742 PRIV (recrd.file_format) = FF_NATIVE;
745 /* The adjustment is needed only in an Unix environment. */
746 if (PRIV (recrd.file_format) == FF_FOREIGN)
747 PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT;
750 /* Implement step #1 of the object record reading procedure.
751 Return the record type or -1 on failure. */
754 _bfd_vms_get_object_record (bfd *abfd)
756 unsigned int test_len = 6;
759 vms_debug2 ((8, "_bfd_vms_get_obj_record\n"));
761 /* Skip alignment byte if the current position is odd. */
762 if (bfd_tell (abfd) & 1)
764 if (bfd_bread (PRIV (recrd.buf), 1, abfd) != 1)
766 bfd_set_error (bfd_error_file_truncated);
771 /* Read the record header */
772 if (bfd_bread (PRIV (recrd.buf), test_len, abfd) != test_len)
774 bfd_set_error (bfd_error_file_truncated);
778 /* Reset the record pointer. */
779 PRIV (recrd.rec) = PRIV (recrd.buf);
780 maybe_adjust_record_pointer_for_object (abfd);
782 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
785 type = bfd_getl16 (PRIV (recrd.rec));
787 vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n",
788 PRIV (recrd.rec), PRIV (recrd.rec_size), type));
793 /* Implement step #2 of the object record reading procedure.
794 Return the size of the record or 0 on failure. */
797 vms_get_remaining_object_record (bfd *abfd, int read_so_far)
799 unsigned int to_read;
801 vms_debug2 ((8, "vms_get_remaining_obj_record\n"));
803 /* Extract record size. */
804 PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2);
806 if (PRIV (recrd.rec_size) <= 0)
808 bfd_set_error (bfd_error_file_truncated);
812 /* That's what the linker manual says. */
813 if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ)
815 bfd_set_error (bfd_error_file_truncated);
819 /* Take into account object adjustment. */
820 to_read = PRIV (recrd.rec_size);
821 if (PRIV (recrd.file_format) == FF_FOREIGN)
822 to_read += VMS_OBJECT_ADJUSTMENT;
824 /* Adjust the buffer. */
825 if (to_read > PRIV (recrd.buf_size))
828 = (unsigned char *) bfd_realloc (PRIV (recrd.buf), to_read);
829 if (PRIV (recrd.buf) == NULL)
831 PRIV (recrd.buf_size) = to_read;
834 /* Read the remaining record. */
835 to_read -= read_so_far;
837 vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read));
839 if (bfd_bread (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read)
841 bfd_set_error (bfd_error_file_truncated);
845 /* Reset the record pointer. */
846 PRIV (recrd.rec) = PRIV (recrd.buf);
847 maybe_adjust_record_pointer_for_object (abfd);
849 vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n",
850 PRIV (recrd.rec_size)));
852 return PRIV (recrd.rec_size);
855 /* Read and process emh record.
856 Return TRUE on success, FALSE on error. */
859 _bfd_vms_slurp_ehdr (bfd *abfd)
862 unsigned char *vms_rec;
865 vms_rec = PRIV (recrd.rec);
867 vms_debug2 ((2, "HDR/EMH\n"));
869 subtype = bfd_getl16 (vms_rec + 4);
871 vms_debug2 ((3, "subtype %d\n", subtype));
877 PRIV (hdr_data).hdr_b_strlvl = vms_rec[6];
878 PRIV (hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8);
879 PRIV (hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12);
880 PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
881 PRIV (hdr_data).hdr_t_name = _bfd_vms_save_counted_string (vms_rec + 20);
882 ptr = vms_rec + 20 + vms_rec[20] + 1;
883 PRIV (hdr_data).hdr_t_version =_bfd_vms_save_counted_string (ptr);
885 PRIV (hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
889 PRIV (hdr_data).hdr_c_lnm =
890 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
894 PRIV (hdr_data).hdr_c_src =
895 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
899 PRIV (hdr_data).hdr_c_ttl =
900 _bfd_vms_save_sized_string (vms_rec, PRIV (recrd.rec_size - 6));
909 bfd_set_error (bfd_error_wrong_format);
916 /* Typical sections for evax object files. */
918 #define EVAX_ABS_NAME "$ABS$"
919 #define EVAX_CODE_NAME "$CODE$"
920 #define EVAX_LINK_NAME "$LINK$"
921 #define EVAX_DATA_NAME "$DATA$"
922 #define EVAX_BSS_NAME "$BSS$"
923 #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$"
924 #define EVAX_READONLY_NAME "$READONLY$"
925 #define EVAX_LITERAL_NAME "$LITERAL$"
926 #define EVAX_LITERALS_NAME "$LITERALS"
927 #define EVAX_COMMON_NAME "$COMMON$"
928 #define EVAX_LOCAL_NAME "$LOCAL$"
930 struct sec_flags_struct
932 const char *name; /* Name of section. */
934 flagword flags_always; /* Flags we set always. */
936 flagword flags_hassize; /* Flags we set if the section has a size > 0. */
939 /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */
941 static struct sec_flags_struct evax_section_flags[] =
947 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD) },
949 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE),
951 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE),
952 (SEC_CODE | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD) },
954 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD),
955 (SEC_DATA | SEC_READONLY),
956 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD),
957 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD) },
959 (EGPS__V_REL | EGPS__V_RD),
960 (SEC_DATA | SEC_READONLY),
961 (EGPS__V_REL | EGPS__V_RD),
962 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD) },
964 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD),
966 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT),
967 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD) },
969 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD),
971 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD),
973 { EVAX_READONLYADDR_NAME,
974 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD),
975 (SEC_DATA | SEC_READONLY),
976 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD),
977 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD) },
978 { EVAX_READONLY_NAME,
979 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD),
980 (SEC_DATA | SEC_READONLY),
981 (EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD),
982 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD) },
984 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT),
986 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT),
987 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD) },
988 { EVAX_LITERALS_NAME,
989 (EGPS__V_PIC | EGPS__V_OVR),
990 (SEC_DATA | SEC_READONLY),
991 (EGPS__V_PIC | EGPS__V_OVR),
992 (SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_READONLY | SEC_LOAD) },
994 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT),
996 (EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT),
997 (SEC_IN_MEMORY | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD) }
1000 /* Retrieve bfd section flags by name and size. */
1003 vms_secflag_by_name (bfd *abfd ATTRIBUTE_UNUSED,
1004 struct sec_flags_struct *section_flags,
1010 while (section_flags[i].name != NULL)
1012 if (strcmp (name, section_flags[i].name) == 0)
1015 return section_flags[i].flags_hassize;
1017 return section_flags[i].flags_always;
1022 return section_flags[i].flags_hassize;
1023 return section_flags[i].flags_always;
1026 /* Retrieve vms section flags by name and size. */
1029 vms_esecflag_by_name (struct sec_flags_struct *section_flags,
1035 while (section_flags[i].name != NULL)
1037 if (strcmp (name, section_flags[i].name) == 0)
1040 return section_flags[i].vflags_hassize;
1042 return section_flags[i].vflags_always;
1047 return section_flags[i].vflags_hassize;
1048 return section_flags[i].vflags_always;
1051 /* Input routines. */
1053 static struct vms_symbol_entry *
1054 add_symbol (bfd *abfd, const unsigned char *ascic)
1056 struct vms_symbol_entry *entry;
1060 entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len);
1063 entry->namelen = len;
1064 memcpy (entry->name, ascic, len);
1065 entry->name[len] = 0;
1066 entry->owner = abfd;
1068 if (PRIV (gsd_sym_count) >= PRIV (max_sym_count))
1070 if (PRIV (max_sym_count) == 0)
1072 PRIV (max_sym_count) = 128;
1073 PRIV (syms) = bfd_malloc
1074 (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *));
1078 PRIV (max_sym_count) *= 2;
1079 PRIV (syms) = bfd_realloc
1081 (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)));
1083 if (PRIV (syms) == NULL)
1087 PRIV (syms)[PRIV (gsd_sym_count)++] = entry;
1091 /* Read and process EGSD. Return FALSE on failure. */
1094 _bfd_vms_slurp_egsd (bfd * abfd)
1096 int gsd_type, gsd_size;
1098 unsigned char *vms_rec;
1099 flagword new_flags, old_flags;
1101 unsigned long base_addr;
1102 unsigned long align_addr;
1104 vms_debug2 ((2, "EGSD\n"));
1106 PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */
1107 PRIV (recrd.rec_size) -= 8;
1109 /* Calculate base address for each section. */
1112 while (PRIV (recrd.rec_size) > 0)
1114 vms_rec = PRIV (recrd.rec);
1116 gsd_type = bfd_getl16 (vms_rec);
1117 gsd_size = bfd_getl16 (vms_rec + 2);
1119 vms_debug2 ((3, "egsd_type %d\n", gsd_type));
1125 /* Program section definition. */
1126 struct vms_egps *egps = (struct vms_egps *)vms_rec;
1127 name = _bfd_vms_save_counted_string (&egps->namlng);
1128 section = bfd_make_section (abfd, name);
1131 old_flags = bfd_getl16 (egps->flags);
1132 vms_section_data (section)->flags = old_flags;
1133 vms_section_data (section)->no_flags = 0;
1134 section->size = bfd_getl32 (egps->alloc);
1135 new_flags = vms_secflag_by_name (abfd, evax_section_flags, name,
1137 if (!(old_flags & EGPS__V_NOMOD))
1139 new_flags |= SEC_HAS_CONTENTS;
1140 if (old_flags & EGPS__V_REL)
1141 new_flags |= SEC_RELOC;
1143 if (!bfd_set_section_flags (abfd, section, new_flags))
1145 section->alignment_power = egps->align;
1146 align_addr = (1 << section->alignment_power);
1147 if ((base_addr % align_addr) != 0)
1148 base_addr += (align_addr - (base_addr % align_addr));
1149 section->vma = (bfd_vma)base_addr;
1150 base_addr += section->size;
1151 section->filepos = (unsigned int)-1;
1153 vms_debug (4, "EGSD P-section %d (%s, flags %04x) ",
1154 section->index, name, old_flags);
1155 vms_debug (4, "%lu bytes at 0x%08lx (mem %p)\n",
1156 (unsigned long)section->size,
1157 (unsigned long)section->vma, section->contents);
1165 struct vms_symbol_entry *entry;
1166 struct vms_egsy *egsy = (struct vms_egsy *) vms_rec;
1168 old_flags = bfd_getl16 (egsy->flags);
1169 if (old_flags & EGSY__V_DEF)
1170 nameoff = ESDF__B_NAMLNG;
1172 nameoff = ESRF__B_NAMLNG;
1174 entry = add_symbol (abfd, vms_rec + nameoff);
1178 /* Allow only duplicate reference. */
1179 if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF))
1182 if (entry->typ == 0)
1184 entry->typ = gsd_type;
1185 entry->data_type = egsy->datyp;
1186 entry->flags = old_flags;
1189 if (old_flags & EGSY__V_DEF)
1191 struct vms_esdf *esdf = (struct vms_esdf *)vms_rec;
1193 entry->value = bfd_getl64 (esdf->value);
1194 entry->section = bfd_getl32 (esdf->psindx);
1196 if (old_flags & EGSY__V_NORM)
1198 PRIV (norm_sym_count)++;
1200 entry->code_value = bfd_getl64 (esdf->code_address);
1201 entry->code_section = bfd_getl32 (esdf->ca_psindx);
1210 struct vms_symbol_entry *entry;
1211 struct vms_egst *egst = (struct vms_egst *)vms_rec;
1213 old_flags = bfd_getl16 (egst->header.flags);
1214 if (old_flags & EGSY__V_DEF)
1215 nameoff = ESDF__B_NAMLNG;
1217 nameoff = ESRF__B_NAMLNG;
1219 entry = add_symbol (abfd, &egst->namlng);
1224 entry->typ = gsd_type;
1225 entry->data_type = egst->header.datyp;
1226 entry->flags = old_flags;
1228 entry->symbol_vector = bfd_getl32 (egst->value);
1230 entry->section = bfd_getl32 (egst->psindx);
1231 entry->value = bfd_getl64 (egst->lp_2);
1233 if (old_flags & EGSY__V_NORM)
1235 PRIV (norm_sym_count)++;
1237 entry->code_value = bfd_getl64 (egst->lp_1);
1238 entry->code_section = 0;
1247 (*_bfd_error_handler) (_("Unknown EGSD subtype %d"), gsd_type);
1248 bfd_set_error (bfd_error_bad_value);
1252 PRIV (recrd.rec_size) -= gsd_size;
1253 PRIV (recrd.rec) += gsd_size;
1256 if (PRIV (gsd_sym_count) > 0)
1257 abfd->flags |= HAS_SYMS;
1262 /* Stack routines for vms ETIR commands. */
1264 /* Push value and section index. */
1267 _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc)
1269 vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n",
1270 (unsigned long)val, reloc, PRIV (stackptr)));
1272 PRIV (stack[PRIV (stackptr)]).value = val;
1273 PRIV (stack[PRIV (stackptr)]).reloc = reloc;
1275 if (PRIV (stackptr) >= STACKSIZE)
1277 bfd_set_error (bfd_error_bad_value);
1278 (*_bfd_error_handler) (_("Stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr));
1283 /* Pop value and section index. */
1286 _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel)
1288 if (PRIV (stackptr) == 0)
1290 bfd_set_error (bfd_error_bad_value);
1291 (*_bfd_error_handler) (_("Stack underflow in _bfd_vms_pop"));
1295 *val = PRIV (stack[PRIV (stackptr)]).value;
1296 *rel = PRIV (stack[PRIV (stackptr)]).reloc;
1298 vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel));
1301 /* Routines to fill sections contents during tir/etir read. */
1303 /* Initialize image buffer pointer to be filled. */
1306 image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info)
1310 vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect));
1312 sec = PRIV (sections)[sect];
1316 /* Reading contents to an output bfd. */
1318 if (sec->output_section == NULL)
1320 /* Section discarded. */
1321 vms_debug2 ((5, " section %s discarded\n", sec->name));
1323 /* This is not used. */
1324 PRIV (image_section) = NULL;
1325 PRIV (image_offset) = 0;
1328 PRIV (image_offset) = sec->output_offset + vma;
1329 PRIV (image_section) = sec->output_section;
1333 PRIV (image_offset) = vma;
1334 PRIV (image_section) = sec;
1338 /* Increment image buffer pointer by offset. */
1341 image_inc_ptr (bfd *abfd, bfd_vma offset)
1343 vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset));
1345 PRIV (image_offset) += offset;
1348 /* Save current DST location counter under specified index. */
1351 dst_define_location (bfd *abfd, unsigned int loc)
1353 vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc));
1355 /* Grow the ptr offset table if necessary. */
1356 if (loc + 1 > PRIV (dst_ptr_offsets_count))
1358 PRIV (dst_ptr_offsets) = bfd_realloc (PRIV (dst_ptr_offsets),
1359 (loc + 1) * sizeof (unsigned int));
1360 PRIV (dst_ptr_offsets_count) = loc + 1;
1363 PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset);
1366 /* Restore saved DST location counter from specified index. */
1369 dst_restore_location (bfd *abfd, unsigned int loc)
1371 vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc));
1373 PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc];
1376 /* Retrieve saved DST location counter from specified index. */
1379 dst_retrieve_location (bfd *abfd, unsigned int loc)
1381 vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int)loc));
1383 return PRIV (dst_ptr_offsets)[loc];
1386 /* Check that the DST section is big enough for the specified
1390 dst_check_allocation (bfd *abfd, unsigned int size)
1392 asection *section = PRIV (image_section);
1394 section->size += size;
1396 /* Grow the section as necessary */
1397 if (section->size <= section->rawsize)
1401 if (section->rawsize == 0)
1402 section->rawsize = 1024;
1404 section->rawsize *= 2;
1406 while (section->size > section->rawsize);
1407 section->contents = bfd_realloc (section->contents, section->rawsize);
1410 /* Write multiple bytes to section image. */
1413 image_write (bfd *abfd, unsigned char *ptr, int size)
1416 _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size,
1417 (long)PRIV (image_offset));
1418 _bfd_hexdump (9, ptr, size, 0);
1421 if (PRIV (image_autoextend))
1422 dst_check_allocation (abfd, size);
1424 if (PRIV (image_section)->contents != NULL)
1426 asection *sec = PRIV (image_section);
1427 file_ptr off = PRIV (image_offset);
1430 if (off > (file_ptr)sec->size
1431 || size > (file_ptr)sec->size
1432 || off + size > (file_ptr)sec->size)
1434 bfd_set_error (bfd_error_bad_value);
1438 memcpy (sec->contents + off, ptr, size);
1441 PRIV (image_offset) += size;
1445 /* Write byte to section image. */
1448 image_write_b (bfd * abfd, unsigned int value)
1450 unsigned char data[1];
1452 vms_debug2 ((6, "image_write_b (%02x)\n", (int) value));
1456 return image_write (abfd, data, sizeof (data));
1459 /* Write 2-byte word to image. */
1462 image_write_w (bfd * abfd, unsigned int value)
1464 unsigned char data[2];
1466 vms_debug2 ((6, "image_write_w (%04x)\n", (int) value));
1468 bfd_putl16 (value, data);
1469 return image_write (abfd, data, sizeof (data));
1472 /* Write 4-byte long to image. */
1475 image_write_l (bfd * abfd, unsigned long value)
1477 unsigned char data[4];
1479 vms_debug2 ((6, "image_write_l (%08lx)\n", value));
1481 bfd_putl32 (value, data);
1482 return image_write (abfd, data, sizeof (data));
1485 /* Write 8-byte quad to image. */
1488 image_write_q (bfd * abfd, bfd_vma value)
1490 unsigned char data[8];
1492 vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value));
1494 bfd_putl64 (value, data);
1495 return image_write (abfd, data, sizeof (data));
1499 _bfd_vms_etir_name (int cmd)
1503 case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL";
1504 case ETIR__C_STA_LW: return "ETIR__C_STA_LW";
1505 case ETIR__C_STA_QW: return "ETIR__C_STA_QW";
1506 case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ";
1507 case ETIR__C_STA_LI: return "ETIR__C_STA_LI";
1508 case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD";
1509 case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG";
1510 case ETIR__C_STO_B: return "ETIR__C_STO_B";
1511 case ETIR__C_STO_W: return "ETIR__C_STO_W";
1512 case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL";
1513 case ETIR__C_STO_CA: return "ETIR__C_STO_CA";
1514 case ETIR__C_STO_RB: return "ETIR__C_STO_RB";
1515 case ETIR__C_STO_AB: return "ETIR__C_STO_AB";
1516 case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF";
1517 case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM";
1518 case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR";
1519 case ETIR__C_STO_LW: return "ETIR__C_STO_LW";
1520 case ETIR__C_STO_QW: return "ETIR__C_STO_QW";
1521 case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW";
1522 case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB";
1523 case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL";
1524 case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS";
1525 case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD";
1526 case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB";
1527 case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV";
1528 case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH";
1529 case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT";
1530 case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF";
1531 case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT";
1532 case ETIR__C_STC_LP: return "ETIR__C_STC_LP";
1533 case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL";
1534 case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA";
1535 case ETIR__C_STC_PS: return "ETIR__C_STC_PS";
1536 case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS";
1537 case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL";
1538 case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS";
1539 case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL";
1540 case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS";
1541 case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL";
1542 case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS";
1543 case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL";
1544 case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS";
1545 case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL";
1546 case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB";
1547 case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB";
1548 case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB";
1549 case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC";
1550 case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC";
1551 case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL";
1554 /* These names have not yet been added to this switch statement. */
1555 (*_bfd_error_handler) (_("unknown ETIR command %d"), cmd);
1560 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
1563 _bfd_vms_get_value (bfd *abfd, const unsigned char *ascic,
1564 struct bfd_link_info *info,
1566 struct alpha_vms_link_hash_entry **hp)
1571 struct alpha_vms_link_hash_entry *h;
1573 /* Not linking. Do not try to resolve the symbol. */
1582 for (i = 0; i < len; i++)
1583 name[i] = ascic[i + 1];
1586 h = (struct alpha_vms_link_hash_entry *)
1587 bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
1592 && (h->root.type == bfd_link_hash_defined
1593 || h->root.type == bfd_link_hash_defweak))
1594 *vma = h->root.u.def.value
1595 + h->root.u.def.section->output_offset
1596 + h->root.u.def.section->output_section->vma;
1597 else if (h && h->root.type == bfd_link_hash_undefweak)
1601 if (!(*info->callbacks->undefined_symbol)
1602 (info, name, abfd, PRIV (image_section), PRIV (image_offset), TRUE))
1610 #define RELC_SHR_BASE 0x10000
1611 #define RELC_SEC_BASE 0x20000
1612 #define RELC_MASK 0x0ffff
1615 alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h)
1617 /* Handle undefined symbols. */
1618 if (h == NULL || h->sym == NULL)
1621 if (h->sym->typ == EGSD__C_SYMG)
1623 if (h->sym->flags & EGSY__V_REL)
1624 return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index);
1627 /* Can this happen ? I'd like to see an example. */
1631 if (h->sym->typ == EGSD__C_SYM)
1633 if (h->sym->flags & EGSY__V_REL)
1642 alpha_vms_get_sym_value (unsigned int sect, bfd_vma addr,
1643 struct alpha_vms_link_hash_entry *h)
1647 BFD_ASSERT (h && (h->root.type == bfd_link_hash_defined
1648 || h->root.type == bfd_link_hash_defweak));
1650 s = PRIV2 (h->root.u.def.section->owner, sections)[sect];
1651 return s->output_section->vma + s->output_offset + addr;
1655 alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info,
1656 unsigned int rel, bfd_vma vma)
1658 asection *sec = PRIV (sections)[rel & RELC_MASK];
1662 if (sec->output_section == NULL)
1664 return vma + sec->output_section->vma + sec->output_offset;
1667 return vma + sec->vma;
1671 _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info)
1674 unsigned int length;
1675 unsigned char *maxptr;
1680 struct alpha_vms_link_hash_entry *h;
1682 PRIV (recrd.rec) += ETIR__C_HEADER_SIZE;
1683 PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE;
1685 ptr = PRIV (recrd.rec);
1686 length = PRIV (recrd.rec_size);
1687 maxptr = ptr + length;
1689 vms_debug2 ((2, "ETIR: %d bytes\n", length));
1691 while (ptr < maxptr)
1693 int cmd = bfd_getl16 (ptr);
1694 int cmd_length = bfd_getl16 (ptr + 2);
1699 _bfd_vms_debug (4, "etir: %s(%d)\n",
1700 _bfd_vms_etir_name (cmd), cmd);
1701 _bfd_hexdump (8, ptr, cmd_length - 4, (long) ptr);
1709 stack 32 bit value of symbol (high bits set to 0). */
1710 case ETIR__C_STA_GBL:
1711 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1712 _bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h));
1718 stack 32 bit value, sign extend to 64 bit. */
1719 case ETIR__C_STA_LW:
1720 _bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE);
1726 stack 64 bit value of symbol. */
1727 case ETIR__C_STA_QW:
1728 _bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE);
1731 /* Stack psect base plus quadword offset
1732 arg: lw section index
1733 qw signed quadword offset (low 32 bits)
1735 Stack qw argument and section index
1736 (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */
1737 case ETIR__C_STA_PQ:
1741 psect = bfd_getl32 (ptr);
1742 if ((unsigned int) psect >= PRIV (section_count))
1744 (*_bfd_error_handler) (_("bad section index in %s"),
1745 _bfd_vms_etir_name (cmd));
1746 bfd_set_error (bfd_error_bad_value);
1749 op1 = bfd_getl64 (ptr + 4);
1750 _bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE);
1754 case ETIR__C_STA_LI:
1755 case ETIR__C_STA_MOD:
1756 case ETIR__C_STA_CKARG:
1757 (*_bfd_error_handler) (_("unsupported STA cmd %s"),
1758 _bfd_vms_etir_name (cmd));
1762 /* Store byte: pop stack, write byte
1765 _bfd_vms_pop (abfd, &op1, &rel1);
1766 if (rel1 != RELC_NONE)
1768 image_write_b (abfd, (unsigned int) op1 & 0xff);
1771 /* Store word: pop stack, write word
1774 _bfd_vms_pop (abfd, &op1, &rel1);
1775 if (rel1 != RELC_NONE)
1777 image_write_w (abfd, (unsigned int) op1 & 0xffff);
1780 /* Store longword: pop stack, write longword
1782 case ETIR__C_STO_LW:
1783 _bfd_vms_pop (abfd, &op1, &rel1);
1784 if (rel1 & RELC_SEC_BASE)
1786 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1789 else if (rel1 & RELC_SHR_BASE)
1791 alpha_vms_add_lw_fixup (info, rel1 & RELC_MASK, op1);
1794 if (rel1 != RELC_NONE)
1796 if (rel1 != RELC_REL)
1798 alpha_vms_add_lw_reloc (info);
1800 image_write_l (abfd, op1);
1803 /* Store quadword: pop stack, write quadword
1805 case ETIR__C_STO_QW:
1806 _bfd_vms_pop (abfd, &op1, &rel1);
1807 if (rel1 & RELC_SEC_BASE)
1809 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1812 else if (rel1 & RELC_SHR_BASE)
1814 if (rel1 != RELC_NONE)
1816 if (rel1 != RELC_REL)
1818 alpha_vms_add_qw_reloc (info);
1820 image_write_q (abfd, op1);
1823 /* Store immediate repeated: pop stack for repeat count
1826 case ETIR__C_STO_IMMR:
1830 size = bfd_getl32 (ptr);
1831 _bfd_vms_pop (abfd, &op1, &rel1);
1832 if (rel1 != RELC_NONE)
1835 image_write (abfd, ptr + 4, size);
1839 /* Store global: write symbol value
1840 arg: cs global symbol name. */
1841 case ETIR__C_STO_GBL:
1842 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1845 if (h->sym->typ == EGSD__C_SYMG)
1847 alpha_vms_add_fixup_qr
1848 (info, abfd, h->sym->owner, h->sym->symbol_vector);
1853 op1 = alpha_vms_get_sym_value (h->sym->section,
1855 alpha_vms_add_qw_reloc (info);
1858 image_write_q (abfd, op1);
1861 /* Store code address: write address of entry point
1862 arg: cs global symbol name (procedure). */
1863 case ETIR__C_STO_CA:
1864 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1867 if (h->sym->flags & EGSY__V_NORM)
1869 /* That's really a procedure. */
1870 if (h->sym->typ == EGSD__C_SYMG)
1872 alpha_vms_add_fixup_ca (info, abfd, h->sym->owner);
1873 op1 = h->sym->symbol_vector;
1877 op1 = alpha_vms_get_sym_value (h->sym->code_section,
1878 h->sym->code_value, h);
1879 alpha_vms_add_qw_reloc (info);
1884 /* Symbol is not a procedure. */
1888 image_write_q (abfd, op1);
1891 /* Store offset to psect: pop stack, add low 32 bits to base of psect
1893 case ETIR__C_STO_OFF:
1894 _bfd_vms_pop (abfd, &op1, &rel1);
1896 if (!(rel1 & RELC_SEC_BASE))
1899 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
1901 image_write_q (abfd, op1);
1905 arg: lw count of bytes
1907 case ETIR__C_STO_IMM:
1911 size = bfd_getl32 (ptr);
1912 image_write (abfd, ptr + 4, size);
1916 /* This code is 'reserved to digital' according to the openVMS
1917 linker manual, however it is generated by the DEC C compiler
1918 and defined in the include file.
1919 FIXME, since the following is just a guess
1920 store global longword: store 32bit value of symbol
1921 arg: cs symbol name. */
1922 case ETIR__C_STO_GBL_LW:
1923 _bfd_vms_get_value (abfd, ptr, info, &op1, &h);
1927 image_write_l (abfd, op1);
1930 case ETIR__C_STO_RB:
1931 case ETIR__C_STO_AB:
1932 case ETIR__C_STO_LP_PSB:
1933 (*_bfd_error_handler) (_("%s: not supported"),
1934 _bfd_vms_etir_name (cmd));
1937 case ETIR__C_STO_HINT_GBL:
1938 case ETIR__C_STO_HINT_PS:
1939 (*_bfd_error_handler) (_("%s: not implemented"),
1940 _bfd_vms_etir_name (cmd));
1944 /* 200 Store-conditional Linkage Pair
1946 case ETIR__C_STC_LP:
1948 /* 202 Store-conditional Address at global address
1952 case ETIR__C_STC_GBL:
1954 /* 203 Store-conditional Code Address at global address
1956 cs procedure name. */
1957 case ETIR__C_STC_GCA:
1959 /* 204 Store-conditional Address at psect + offset
1963 case ETIR__C_STC_PS:
1964 (*_bfd_error_handler) (_("%s: not supported"),
1965 _bfd_vms_etir_name (cmd));
1969 /* 201 Store-conditional Linkage Pair with Procedure Signature
1975 case ETIR__C_STC_LP_PSB:
1976 _bfd_vms_get_value (abfd, ptr + 4, info, &op1, &h);
1979 if (h->sym->typ == EGSD__C_SYMG)
1981 alpha_vms_add_fixup_lp (info, abfd, h->sym->owner);
1982 op1 = h->sym->symbol_vector;
1987 op1 = alpha_vms_get_sym_value (h->sym->code_section,
1988 h->sym->code_value, h);
1989 op2 = alpha_vms_get_sym_value (h->sym->section,
1995 /* Undefined symbol. */
1999 image_write_q (abfd, op1);
2000 image_write_q (abfd, op2);
2003 /* 205 Store-conditional NOP at address of global
2005 case ETIR__C_STC_NOP_GBL:
2008 /* 207 Store-conditional BSR at global address
2011 case ETIR__C_STC_BSR_GBL:
2014 /* 209 Store-conditional LDA at global address
2017 case ETIR__C_STC_LDA_GBL:
2020 /* 211 Store-conditional BSR or Hint at global address
2023 case ETIR__C_STC_BOH_GBL:
2024 /* Currentl ignored. */
2027 /* 213 Store-conditional NOP,BSR or HINT at global address
2030 case ETIR__C_STC_NBH_GBL:
2032 /* 206 Store-conditional NOP at pect + offset
2035 case ETIR__C_STC_NOP_PS:
2037 /* 208 Store-conditional BSR at pect + offset
2040 case ETIR__C_STC_BSR_PS:
2042 /* 210 Store-conditional LDA at psect + offset
2045 case ETIR__C_STC_LDA_PS:
2047 /* 212 Store-conditional BSR or Hint at pect + offset
2050 case ETIR__C_STC_BOH_PS:
2052 /* 214 Store-conditional NOP, BSR or HINT at psect + offset
2054 case ETIR__C_STC_NBH_PS:
2055 (*_bfd_error_handler) ("%s: not supported",
2056 _bfd_vms_etir_name (cmd));
2060 /* Det relocation base: pop stack, set image location counter
2062 case ETIR__C_CTL_SETRB:
2063 _bfd_vms_pop (abfd, &op1, &rel1);
2064 if (!(rel1 & RELC_SEC_BASE))
2066 image_set_ptr (abfd, op1, rel1 & RELC_MASK, info);
2069 /* Augment relocation base: increment image location counter by offset
2070 arg: lw offset value. */
2071 case ETIR__C_CTL_AUGRB:
2072 op1 = bfd_getl32 (ptr);
2073 image_inc_ptr (abfd, op1);
2076 /* Define location: pop index, save location counter under index
2078 case ETIR__C_CTL_DFLOC:
2079 _bfd_vms_pop (abfd, &op1, &rel1);
2080 if (rel1 != RELC_NONE)
2082 dst_define_location (abfd, op1);
2085 /* Set location: pop index, restore location counter from index
2087 case ETIR__C_CTL_STLOC:
2088 _bfd_vms_pop (abfd, &op1, &rel1);
2089 if (rel1 != RELC_NONE)
2091 dst_restore_location (abfd, op1);
2094 /* Stack defined location: pop index, push location counter from index
2096 case ETIR__C_CTL_STKDL:
2097 _bfd_vms_pop (abfd, &op1, &rel1);
2098 if (rel1 != RELC_NONE)
2100 _bfd_vms_push (abfd, dst_retrieve_location (abfd, op1), RELC_NONE);
2103 case ETIR__C_OPR_NOP: /* No-op. */
2106 case ETIR__C_OPR_ADD: /* Add. */
2107 _bfd_vms_pop (abfd, &op1, &rel1);
2108 _bfd_vms_pop (abfd, &op2, &rel2);
2109 if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2111 else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2113 _bfd_vms_push (abfd, op1 + op2, rel1);
2116 case ETIR__C_OPR_SUB: /* Subtract. */
2117 _bfd_vms_pop (abfd, &op1, &rel1);
2118 _bfd_vms_pop (abfd, &op2, &rel2);
2119 if (rel1 == RELC_NONE && rel2 != RELC_NONE)
2121 else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE))
2123 op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1);
2124 op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2);
2127 else if (rel1 != RELC_NONE && rel2 != RELC_NONE)
2129 _bfd_vms_push (abfd, op2 - op1, rel1);
2132 case ETIR__C_OPR_MUL: /* Multiply. */
2133 _bfd_vms_pop (abfd, &op1, &rel1);
2134 _bfd_vms_pop (abfd, &op2, &rel2);
2135 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2137 _bfd_vms_push (abfd, op1 * op2, RELC_NONE);
2140 case ETIR__C_OPR_DIV: /* Divide. */
2141 _bfd_vms_pop (abfd, &op1, &rel1);
2142 _bfd_vms_pop (abfd, &op2, &rel2);
2143 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2146 _bfd_vms_push (abfd, 0, RELC_NONE);
2148 _bfd_vms_push (abfd, op2 / op1, RELC_NONE);
2151 case ETIR__C_OPR_AND: /* Logical AND. */
2152 _bfd_vms_pop (abfd, &op1, &rel1);
2153 _bfd_vms_pop (abfd, &op2, &rel2);
2154 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2156 _bfd_vms_push (abfd, op1 & op2, RELC_NONE);
2159 case ETIR__C_OPR_IOR: /* Logical inclusive OR. */
2160 _bfd_vms_pop (abfd, &op1, &rel1);
2161 _bfd_vms_pop (abfd, &op2, &rel2);
2162 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2164 _bfd_vms_push (abfd, op1 | op2, RELC_NONE);
2167 case ETIR__C_OPR_EOR: /* Logical exclusive OR. */
2168 _bfd_vms_pop (abfd, &op1, &rel1);
2169 _bfd_vms_pop (abfd, &op2, &rel2);
2170 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2172 _bfd_vms_push (abfd, op1 ^ op2, RELC_NONE);
2175 case ETIR__C_OPR_NEG: /* Negate. */
2176 _bfd_vms_pop (abfd, &op1, &rel1);
2177 if (rel1 != RELC_NONE)
2179 _bfd_vms_push (abfd, -op1, RELC_NONE);
2182 case ETIR__C_OPR_COM: /* Complement. */
2183 _bfd_vms_pop (abfd, &op1, &rel1);
2184 if (rel1 != RELC_NONE)
2186 _bfd_vms_push (abfd, ~op1, RELC_NONE);
2189 case ETIR__C_OPR_ASH: /* Arithmetic shift. */
2190 _bfd_vms_pop (abfd, &op1, &rel1);
2191 _bfd_vms_pop (abfd, &op2, &rel2);
2192 if (rel1 != RELC_NONE || rel2 != RELC_NONE)
2195 (*_bfd_error_handler) (_("invalid use of %s with contexts"),
2196 _bfd_vms_etir_name (cmd));
2199 if ((int)op2 < 0) /* Shift right. */
2201 else /* Shift left. */
2203 _bfd_vms_push (abfd, op1, RELC_NONE); /* FIXME: sym. */
2206 case ETIR__C_OPR_INSV: /* Insert field. */
2207 case ETIR__C_OPR_USH: /* Unsigned shift. */
2208 case ETIR__C_OPR_ROT: /* Rotate. */
2209 case ETIR__C_OPR_REDEF: /* Redefine symbol to current location. */
2210 case ETIR__C_OPR_DFLIT: /* Define a literal. */
2211 (*_bfd_error_handler) (_("%s: not supported"),
2212 _bfd_vms_etir_name (cmd));
2216 case ETIR__C_OPR_SEL: /* Select. */
2217 _bfd_vms_pop (abfd, &op1, &rel1);
2219 _bfd_vms_pop (abfd, &op1, &rel1);
2222 _bfd_vms_pop (abfd, &op1, &rel1);
2223 _bfd_vms_pop (abfd, &op2, &rel2);
2224 _bfd_vms_push (abfd, op1, rel1);
2229 (*_bfd_error_handler) (_("reserved cmd %d"), cmd);
2234 ptr += cmd_length - 4;
2240 /* Process EDBG/ETBT record.
2241 Return TRUE on success, FALSE on error */
2244 vms_slurp_debug (bfd *abfd)
2246 asection *section = PRIV (dst_section);
2248 if (section == NULL)
2250 /* We have no way to find out beforehand how much debug info there
2251 is in an object file, so pick an initial amount and grow it as
2253 flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC
2256 section = bfd_make_section (abfd, "$DST$");
2259 if (!bfd_set_section_flags (abfd, section, flags))
2261 PRIV (dst_section) = section;
2264 PRIV (image_section) = section;
2265 PRIV (image_offset) = section->size;
2266 PRIV (image_autoextend) = FALSE;
2268 if (!_bfd_vms_slurp_etir (abfd, NULL))
2274 /* Process EDBG record.
2275 Return TRUE on success, FALSE on error. */
2278 _bfd_vms_slurp_edbg (bfd *abfd)
2280 vms_debug2 ((2, "EDBG\n"));
2282 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
2284 return vms_slurp_debug (abfd);
2287 /* Process ETBT record.
2288 Return TRUE on success, FALSE on error. */
2291 _bfd_vms_slurp_etbt (bfd *abfd)
2293 vms_debug2 ((2, "ETBT\n"));
2295 abfd->flags |= HAS_LINENO;
2297 return vms_slurp_debug (abfd);
2300 /* Process EEOM record.
2301 Return TRUE on success, FALSE on error. */
2304 _bfd_vms_slurp_eeom (bfd *abfd)
2306 struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec);
2308 vms_debug2 ((2, "EEOM\n"));
2310 PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps);
2311 PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod);
2312 if (PRIV (eom_data).eom_w_comcod > 1)
2314 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
2315 bfd_set_error (bfd_error_bad_value);
2319 PRIV (eom_data).eom_has_transfer = FALSE;
2320 if (PRIV (recrd.rec_size) > 10)
2322 PRIV (eom_data).eom_has_transfer = TRUE;
2323 PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg;
2324 PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx);
2325 PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr);
2327 abfd->start_address = PRIV (eom_data).eom_l_tfradr;
2332 /* Slurp an ordered set of VMS object records. Return FALSE on error. */
2335 _bfd_vms_slurp_object_records (bfd * abfd)
2337 int err, new_type, type = -1;
2341 vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd)));
2343 new_type = _bfd_vms_get_object_record (abfd);
2346 vms_debug2 ((2, "next_record failed\n"));
2355 err = _bfd_vms_slurp_ehdr (abfd);
2358 err = _bfd_vms_slurp_eeom (abfd);
2361 err = _bfd_vms_slurp_egsd (abfd);
2364 err = TRUE; /* _bfd_vms_slurp_etir (abfd); */
2367 err = _bfd_vms_slurp_edbg (abfd);
2370 err = _bfd_vms_slurp_etbt (abfd);
2377 vms_debug2 ((2, "slurp type %d failed\n", type));
2381 while (type != EOBJ__C_EEOM);
2386 /* Initialize private data */
2388 vms_initialize (bfd * abfd)
2392 amt = sizeof (struct vms_private_data_struct);
2393 abfd->tdata.any = bfd_zalloc (abfd, amt);
2394 if (abfd->tdata.any == NULL)
2397 PRIV (recrd.file_format) = FF_UNKNOWN;
2399 amt = sizeof (struct stack_struct) * STACKSIZE;
2400 PRIV (stack) = bfd_alloc (abfd, amt);
2401 if (PRIV (stack) == NULL)
2407 bfd_release (abfd, abfd->tdata.any);
2408 abfd->tdata.any = NULL;
2412 /* Check the format for a file being read.
2413 Return a (bfd_target *) if it's an object file or zero if not. */
2415 static const struct bfd_target *
2416 alpha_vms_object_p (bfd *abfd)
2418 PTR tdata_save = abfd->tdata.any;
2419 unsigned int test_len;
2422 vms_debug2 ((1, "vms_object_p(%p)\n", abfd));
2424 /* Allocate alpha-vms specific data. */
2425 if (!vms_initialize (abfd))
2428 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
2429 goto err_wrong_format;
2431 /* The first challenge with VMS is to discover the kind of the file.
2433 Image files (executable or shared images) are stored as a raw
2434 stream of bytes (like on UNIX), but there is no magic number.
2436 Object files are written with RMS (record management service), ie
2437 each records are preceeded by its length (on a word - 2 bytes), and
2438 padded for word-alignment. That would be simple but when files
2439 are transfered to a UNIX filesystem (using ftp), records are lost.
2440 Only the raw content of the records are transfered. Fortunately,
2441 the Alpha Object file format also store the length of the record
2442 in the records. Is that clear ? */
2444 /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id,
2445 2 bytes size repeated) and 12 bytes for images (4 bytes major id,
2446 4 bytes minor id, 4 bytes length). */
2449 /* Size the main buffer. */
2450 buf = (unsigned char *) bfd_malloc (test_len);
2453 PRIV (recrd.buf) = buf;
2454 PRIV (recrd.buf_size) = test_len;
2456 /* Initialize the record pointer. */
2457 PRIV (recrd.rec) = buf;
2459 if (bfd_bread (buf, test_len, abfd) != test_len)
2461 bfd_set_error (bfd_error_file_truncated);
2465 /* Is it an image? */
2466 if ((bfd_getl32 (buf) == EIHD__K_MAJORID)
2467 && (bfd_getl32 (buf + 4) == EIHD__K_MINORID))
2469 unsigned int to_read;
2470 unsigned int read_so_far;
2471 unsigned int remaining;
2472 unsigned int eisd_offset, eihs_offset;
2474 /* Extract the header size. */
2475 PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE);
2477 if (PRIV (recrd.rec_size) > PRIV (recrd.buf_size))
2479 buf = bfd_realloc_or_free (buf, PRIV (recrd.rec_size));
2483 PRIV (recrd.buf) = NULL;
2484 bfd_set_error (bfd_error_no_memory);
2487 PRIV (recrd.buf) = buf;
2488 PRIV (recrd.buf_size) = PRIV (recrd.rec_size);
2491 /* Read the remaining record. */
2492 remaining = PRIV (recrd.rec_size) - test_len;
2493 to_read = MIN (VMS_BLOCK_SIZE - test_len, remaining);
2494 read_so_far = test_len;
2496 while (remaining > 0)
2498 if (bfd_bread (buf + read_so_far, to_read, abfd) != to_read)
2500 bfd_set_error (bfd_error_file_truncated);
2501 goto err_wrong_format;
2504 read_so_far += to_read;
2505 remaining -= to_read;
2507 to_read = MIN (VMS_BLOCK_SIZE, remaining);
2510 /* Reset the record pointer. */
2511 PRIV (recrd.rec) = buf;
2513 vms_debug2 ((2, "file type is image\n"));
2515 if (_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset) != TRUE)
2516 goto err_wrong_format;
2518 if (_bfd_vms_slurp_eisd (abfd, eisd_offset) != TRUE)
2519 goto err_wrong_format;
2521 /* EIHS is optional. */
2522 if (eihs_offset != 0 && _bfd_vms_slurp_eihs (abfd, eihs_offset) != TRUE)
2523 goto err_wrong_format;
2529 /* Assume it's a module and adjust record pointer if necessary. */
2530 maybe_adjust_record_pointer_for_object (abfd);
2532 /* But is it really a module? */
2533 if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP
2534 && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ)
2536 if (vms_get_remaining_object_record (abfd, test_len) <= 0)
2537 goto err_wrong_format;
2539 vms_debug2 ((2, "file type is module\n"));
2541 type = bfd_getl16 (PRIV (recrd.rec));
2542 if (type != EOBJ__C_EMH || _bfd_vms_slurp_ehdr (abfd) != TRUE)
2543 goto err_wrong_format;
2545 if (_bfd_vms_slurp_object_records (abfd) != TRUE)
2546 goto err_wrong_format;
2549 goto err_wrong_format;
2552 /* Set arch_info to alpha. */
2554 if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
2555 goto err_wrong_format;
2560 bfd_set_error (bfd_error_wrong_format);
2563 if (PRIV (recrd.buf))
2564 free (PRIV (recrd.buf));
2565 if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
2566 bfd_release (abfd, abfd->tdata.any);
2567 abfd->tdata.any = tdata_save;
2574 vector_grow1 (struct vector_type *vec, size_t elsz)
2576 if (vec->nbr_el + 1 < vec->max_el)
2579 if (vec->max_el == 0)
2582 vec->els = bfd_malloc2 (vec->max_el, elsz);
2587 vec->els = bfd_realloc2 (vec->els, vec->max_el, elsz);
2591 /* Bump ABFD file position to next block. */
2594 alpha_vms_file_position_block (bfd *abfd)
2597 PRIV (file_pos) += VMS_BLOCK_SIZE - 1;
2598 PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE);
2602 alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src,
2603 struct vms_eisd *dst)
2605 bfd_putl32 (src->u.eisd.majorid, dst->majorid);
2606 bfd_putl32 (src->u.eisd.minorid, dst->minorid);
2607 bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize);
2608 if (src->u.eisd.eisdsize <= EISD__K_LENEND)
2610 bfd_putl32 (src->u.eisd.secsize, dst->secsize);
2611 bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr);
2612 bfd_putl32 (src->u.eisd.flags, dst->flags);
2613 bfd_putl32 (src->u.eisd.vbn, dst->vbn);
2614 dst->pfc = src->u.eisd.pfc;
2615 dst->matchctl = src->u.eisd.matchctl;
2616 dst->type = src->u.eisd.type;
2618 if (src->u.eisd.flags & EISD__M_GBL)
2620 bfd_putl32 (src->u.gbl_eisd.ident, dst->ident);
2621 memcpy (dst->gblnam, src->u.gbl_eisd.gblnam,
2622 src->u.gbl_eisd.gblnam[0] + 1);
2626 /* Append EISD to the list of extra eisd for ABFD. */
2629 alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd)
2632 if (PRIV (gbl_eisd_head) == NULL)
2633 PRIV (gbl_eisd_head) = eisd;
2635 PRIV (gbl_eisd_tail)->next = eisd;
2636 PRIV (gbl_eisd_tail) = eisd;
2640 alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg)
2642 struct vms_internal_eisd_map *eisd;
2645 namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name));
2646 if (namlen + 5 > EISD__K_GBLNAMLEN)
2652 eisd = bfd_alloc (abfd, sizeof (*eisd));
2656 /* Fill the fields. */
2657 eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID;
2658 eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID;
2659 eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3;
2660 eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */
2661 eisd->u.gbl_eisd.common.virt_addr = 0;
2662 eisd->u.gbl_eisd.common.flags = EISD__M_GBL;
2663 eisd->u.gbl_eisd.common.vbn = 0;
2664 eisd->u.gbl_eisd.common.pfc = 0;
2665 eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl);
2666 eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC;
2668 eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident);
2669 eisd->u.gbl_eisd.gblnam[0] = namlen + 4;
2670 memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name),
2672 memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4);
2674 /* Append it to the list. */
2675 alpha_vms_append_extra_eisd (abfd, eisd);
2681 alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec)
2683 struct vms_internal_eisd_map *eisd;
2685 /* Only for allocating section. */
2686 if (!(sec->flags & SEC_ALLOC))
2689 BFD_ASSERT (vms_section_data (sec)->eisd == NULL);
2690 eisd = bfd_alloc (abfd, sizeof (*eisd));
2693 vms_section_data (sec)->eisd = eisd;
2695 /* Fill the fields. */
2696 eisd->u.eisd.majorid = EISD__K_MAJORID;
2697 eisd->u.eisd.minorid = EISD__K_MINORID;
2698 eisd->u.eisd.eisdsize = EISD__K_LEN;
2699 eisd->u.eisd.secsize =
2700 (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
2701 eisd->u.eisd.virt_addr = sec->vma;
2702 eisd->u.eisd.flags = 0;
2703 eisd->u.eisd.vbn = 0; /* To be later defined. */
2704 eisd->u.eisd.pfc = 0; /* Default. */
2705 eisd->u.eisd.matchctl = EISD__K_MATALL;
2706 eisd->u.eisd.type = EISD__K_NORMAL;
2708 if (sec->flags & SEC_CODE)
2709 eisd->u.eisd.flags |= EISD__M_EXE;
2710 if (!(sec->flags & SEC_READONLY))
2711 eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF;
2713 if (!(sec->flags & SEC_LOAD))
2715 eisd->u.eisd.flags |= EISD__M_DZRO;
2716 eisd->u.eisd.flags &= ~EISD__M_CRF;
2718 if (sec->flags & SEC_LINKER_CREATED)
2720 if (strcmp (sec->name, "$FIXUP$") == 0)
2721 eisd->u.eisd.flags |= EISD__M_FIXUPVEC;
2724 /* Append it to the list. */
2726 if (PRIV (eisd_head) == NULL)
2727 PRIV (eisd_head) = eisd;
2729 PRIV (eisd_tail)->next = eisd;
2730 PRIV (eisd_tail) = eisd;
2736 alpha_vms_write_exec (bfd *abfd)
2738 struct vms_eihd eihd;
2739 struct vms_eiha *eiha;
2740 struct vms_eihi *eihi;
2741 struct vms_eihs *eihs = NULL;
2743 struct vms_internal_eisd_map *first_eisd;
2744 struct vms_internal_eisd_map *eisd;
2747 PRIV (file_pos) = EIHD__C_LENGTH;
2749 memset (&eihd, 0, sizeof (eihd));
2750 memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2));
2752 bfd_putl32 (EIHD__K_MAJORID, eihd.majorid);
2753 bfd_putl32 (EIHD__K_MINORID, eihd.minorid);
2755 bfd_putl32 (sizeof (eihd), eihd.size);
2756 bfd_putl32 (0, eihd.isdoff);
2757 bfd_putl32 (0, eihd.activoff);
2758 bfd_putl32 (0, eihd.symdbgoff);
2759 bfd_putl32 (0, eihd.imgidoff);
2760 bfd_putl32 (0, eihd.patchoff);
2761 bfd_putl64 (0, eihd.iafva);
2762 bfd_putl32 (0, eihd.version_array_off);
2764 bfd_putl32 (EIHD__K_EXE, eihd.imgtype);
2765 bfd_putl32 (0, eihd.subtype);
2767 bfd_putl32 (0, eihd.imgiocnt);
2768 bfd_putl32 (-1, eihd.privreqs);
2769 bfd_putl32 (-1, eihd.privreqs + 4);
2771 bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
2773 bfd_putl32 (0, eihd.lnkflags);
2774 bfd_putl32 (0, eihd.ident);
2775 bfd_putl32 (0, eihd.sysver);
2778 bfd_putl32 (0, eihd.symvect_size);
2779 bfd_putl32 (16, eihd.virt_mem_block_size);
2780 bfd_putl32 (0, eihd.ext_fixup_off);
2781 bfd_putl32 (0, eihd.noopt_psect_off);
2782 bfd_putl32 (-1, eihd.alias);
2785 eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos));
2786 bfd_putl32 (PRIV (file_pos), eihd.activoff);
2787 PRIV (file_pos) += sizeof (struct vms_eiha);
2789 bfd_putl32 (sizeof (struct vms_eiha), eiha->size);
2790 bfd_putl32 (0, eiha->spare);
2791 bfd_putl32 (0x00000340, eiha->tfradr1); /* SYS$IMGACT */
2792 bfd_putl32 (0xffffffff, eiha->tfradr1_h);
2793 bfd_putl64 (bfd_get_start_address (abfd), eiha->tfradr2);
2794 bfd_putl64 (0, eiha->tfradr3);
2795 bfd_putl64 (0, eiha->tfradr4);
2796 bfd_putl64 (0, eiha->inishr);
2799 eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos));
2800 bfd_putl32 (PRIV (file_pos), eihd.imgidoff);
2801 PRIV (file_pos) += sizeof (struct vms_eihi);
2803 bfd_putl32 (EIHI__K_MAJORID, eihi->majorid);
2804 bfd_putl32 (EIHI__K_MINORID, eihi->minorid);
2809 module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
2810 len = strlen (module);
2811 if (len > sizeof (eihi->imgnam) - 1)
2812 len = sizeof (eihi->imgnam) - 1;
2813 eihi->imgnam[0] = len;
2814 memcpy (eihi->imgnam + 1, module, len);
2817 bfd_putl32 (0, eihi->linktime + 0);
2818 bfd_putl32 (0, eihi->linktime + 4);
2820 eihi->linkid[0] = 0;
2821 eihi->imgbid[0] = 0;
2824 dst = bfd_get_section_by_name (abfd, "$DST$");
2825 if (dst == NULL || dst->size == 0)
2826 dst = bfd_get_section_by_name (abfd, "$TBT$");
2827 if (dst != NULL && dst->size != 0)
2829 eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos));
2830 bfd_putl32 (PRIV (file_pos), eihd.symdbgoff);
2831 PRIV (file_pos) += sizeof (struct vms_eihs);
2833 bfd_putl32 (EIHS__K_MAJORID, eihs->majorid);
2834 bfd_putl32 (EIHS__K_MINORID, eihs->minorid);
2835 bfd_putl32 (0, eihs->dstvbn);
2836 bfd_putl32 (0, eihs->dstsize);
2837 bfd_putl32 (0, eihs->gstvbn);
2838 bfd_putl32 (0, eihs->gstsize);
2839 bfd_putl32 (0, eihs->dmtvbn);
2840 bfd_putl32 (0, eihs->dmtsize);
2843 /* One per section. */
2844 for (sec = abfd->sections; sec; sec = sec->next)
2846 if (!alpha_vms_create_eisd_for_section (abfd, sec))
2850 /* Merge section EIDS which extra ones. */
2851 if (PRIV (eisd_tail))
2852 PRIV (eisd_tail)->next = PRIV (gbl_eisd_head);
2854 PRIV (eisd_head) = PRIV (gbl_eisd_head);
2855 if (PRIV (gbl_eisd_tail))
2856 PRIV (eisd_tail) = PRIV (gbl_eisd_tail);
2858 first_eisd = PRIV (eisd_head);
2860 /* Add end of eisd. */
2863 eisd = bfd_zalloc (abfd, sizeof (*eisd));
2866 eisd->u.eisd.majorid = 0;
2867 eisd->u.eisd.minorid = 0;
2868 eisd->u.eisd.eisdsize = 0;
2869 alpha_vms_append_extra_eisd (abfd, eisd);
2872 /* Place EISD in the file. */
2873 for (eisd = first_eisd; eisd; eisd = eisd->next)
2875 file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE);
2877 /* First block is a little bit special: there is a word at the end. */
2878 if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2)
2880 if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND)
2881 alpha_vms_file_position_block (abfd);
2883 eisd->file_pos = PRIV (file_pos);
2884 PRIV (file_pos) += eisd->u.eisd.eisdsize;
2886 if (eisd->u.eisd.flags & EISD__M_FIXUPVEC)
2887 bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva);
2890 if (first_eisd != NULL)
2892 bfd_putl32 (first_eisd->file_pos, eihd.isdoff);
2893 /* Real size of end of eisd marker. */
2894 PRIV (file_pos) += EISD__K_LENEND;
2897 bfd_putl32 (PRIV (file_pos), eihd.size);
2898 bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE,
2901 /* Place sections. */
2902 for (sec = abfd->sections; sec; sec = sec->next)
2904 if (!(sec->flags & SEC_HAS_CONTENTS))
2907 eisd = vms_section_data (sec)->eisd;
2909 /* Align on a block. */
2910 alpha_vms_file_position_block (abfd);
2911 sec->filepos = PRIV (file_pos);
2914 eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1;
2916 PRIV (file_pos) += sec->size;
2919 if (eihs != NULL && dst != NULL)
2921 bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn);
2922 bfd_putl32 (dst->size, eihs->dstsize);
2925 /* Write EISD in hdr. */
2926 for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE;
2928 alpha_vms_swap_eisd_out
2929 (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos));
2931 /* Write first block. */
2932 if (bfd_bwrite (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
2935 /* Write remaining eisd. */
2938 unsigned char blk[VMS_BLOCK_SIZE];
2939 struct vms_internal_eisd_map *next_eisd;
2941 memset (blk, 0xff, sizeof (blk));
2942 while (eisd != NULL)
2944 alpha_vms_swap_eisd_out
2946 (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE)));
2948 next_eisd = eisd->next;
2949 if (next_eisd == NULL
2950 || (next_eisd->file_pos / VMS_BLOCK_SIZE
2951 != eisd->file_pos / VMS_BLOCK_SIZE))
2953 if (bfd_bwrite (blk, sizeof (blk), abfd) != sizeof (blk))
2956 memset (blk, 0xff, sizeof (blk));
2962 /* Write sections. */
2963 for (sec = abfd->sections; sec; sec = sec->next)
2965 unsigned char blk[VMS_BLOCK_SIZE];
2968 if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS))
2970 if (bfd_bwrite (sec->contents, sec->size, abfd) != sec->size)
2974 len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE;
2975 if (len != VMS_BLOCK_SIZE)
2977 memset (blk, 0, len);
2978 if (bfd_bwrite (blk, len, abfd) != len)
2988 /* This hash routine borrowed from GNU-EMACS, and strengthened
2992 hash_string (const char *ptr)
2994 const unsigned char *p = (unsigned char *) ptr;
2995 const unsigned char *end = p + strlen (ptr);
3002 hash = ((hash << 3) + (hash << 15) + (hash >> 28) + c);
3007 /* Generate a length-hashed VMS symbol name (limited to maxlen chars). */
3010 _bfd_vms_length_hash_symbol (bfd *abfd, const char *in, int maxlen)
3012 unsigned long result;
3015 const char *old_name;
3017 static char outbuf[EOBJ__C_SYMSIZ + 1];
3021 vms_debug (4, "_bfd_vms_length_hash_symbol \"%s\"\n", in);
3024 if (maxlen > EOBJ__C_SYMSIZ)
3025 maxlen = EOBJ__C_SYMSIZ;
3027 /* Save this for later. */
3030 /* We may need to truncate the symbol, save the hash for later. */
3031 in_len = strlen (in);
3033 result = (in_len > maxlen) ? hash_string (in) : 0;
3037 /* Do the length checking. */
3038 if (in_len <= maxlen)
3042 if (PRIV (flag_hash_long_names))
3048 strncpy (out, in, (size_t) i);
3052 if ((in_len > maxlen)
3053 && PRIV (flag_hash_long_names))
3054 sprintf (out, "_%08lx", result);
3059 vms_debug (4, "--> [%d]\"%s\"\n", (int)strlen (outbuf), outbuf);
3063 && PRIV (flag_hash_long_names)
3064 && PRIV (flag_show_after_trunc))
3065 printf (_("Symbol %s replaced by %s\n"), old_name, new_name);
3070 /* Write section and symbol directory of bfd abfd. Return FALSE on error. */
3073 _bfd_vms_write_egsd (bfd *abfd)
3077 unsigned int symnum;
3078 int last_index = -1;
3079 char dummy_name[10];
3081 flagword new_flags, old_flags;
3082 int abs_section_index = 0;
3083 struct vms_rec_wr *recwr = &PRIV (recwr);
3085 vms_debug2 ((2, "vms_write_gsd\n"));
3087 /* Output sections. */
3088 section = abfd->sections;
3089 vms_debug2 ((3, "%d sections found\n", abfd->section_count));
3091 /* Egsd is quadword aligned. */
3092 _bfd_vms_output_alignment (recwr, 8);
3094 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3095 _bfd_vms_output_long (recwr, 0);
3097 while (section != 0)
3099 vms_debug2 ((3, "Section #%d %s, %d bytes\n",
3100 section->index, section->name, (int)section->size));
3102 /* Don't write out the VMS debug info section since it is in the
3103 ETBT and EDBG sections in etir. */
3104 if (!strcmp (section->name, ".vmsdebug"))
3107 /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */
3108 if (_bfd_vms_output_check (recwr, 64) < 0)
3110 _bfd_vms_output_end (abfd, recwr);
3111 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3112 _bfd_vms_output_long (recwr, 0);
3115 /* Create dummy sections to keep consecutive indices. */
3116 while (section->index - last_index > 1)
3118 vms_debug2 ((3, "index %d, last %d\n", section->index, last_index));
3119 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3120 _bfd_vms_output_short (recwr, 0);
3121 _bfd_vms_output_short (recwr, 0);
3122 _bfd_vms_output_long (recwr, 0);
3123 sprintf (dummy_name, ".DUMMY%02d", last_index);
3124 _bfd_vms_output_counted (recwr, dummy_name);
3125 _bfd_vms_output_end_subrec (recwr);
3129 /* Don't know if this is necessary for the linker but for now it keeps
3130 vms_slurp_gsd happy */
3131 sname = (char *)section->name;
3135 if ((*sname == 't') && (strcmp (sname, "text") == 0))
3136 sname = EVAX_CODE_NAME;
3137 else if ((*sname == 'd') && (strcmp (sname, "data") == 0))
3138 sname = EVAX_DATA_NAME;
3139 else if ((*sname == 'b') && (strcmp (sname, "bss") == 0))
3140 sname = EVAX_BSS_NAME;
3141 else if ((*sname == 'l') && (strcmp (sname, "link") == 0))
3142 sname = EVAX_LINK_NAME;
3143 else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0))
3144 sname = EVAX_READONLY_NAME;
3145 else if ((*sname == 'l') && (strcmp (sname, "literal") == 0))
3146 sname = EVAX_LITERAL_NAME;
3147 else if ((*sname == 'l') && (strcmp (sname, "literals") == 0))
3149 sname = EVAX_LITERALS_NAME;
3150 abs_section_index = section->index;
3152 else if ((*sname == 'c') && (strcmp (sname, "comm") == 0))
3153 sname = EVAX_COMMON_NAME;
3154 else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0))
3155 sname = EVAX_LOCAL_NAME;
3158 sname = _bfd_vms_length_hash_symbol (abfd, sname, EOBJ__C_SECSIZ);
3160 _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC);
3161 _bfd_vms_output_short (recwr, section->alignment_power & 0xff);
3163 if (bfd_is_com_section (section))
3164 new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD
3165 | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM);
3167 new_flags = vms_esecflag_by_name (evax_section_flags, sname,
3170 /* Modify them as directed. */
3171 if (section->flags & SEC_READONLY)
3172 new_flags &= ~EGPS__V_WRT;
3174 new_flags &= ~vms_section_data (section)->no_flags;
3175 new_flags |= vms_section_data (section)->flags;
3177 vms_debug2 ((3, "sec flags %x\n", section->flags));
3178 vms_debug2 ((3, "new_flags %x, _raw_size %lu\n",
3179 new_flags, (unsigned long)section->size));
3181 _bfd_vms_output_short (recwr, new_flags);
3182 _bfd_vms_output_long (recwr, (unsigned long) section->size);
3183 _bfd_vms_output_counted (recwr, sname);
3184 _bfd_vms_output_end_subrec (recwr);
3186 last_index = section->index;
3188 section = section->next;
3191 /* Output symbols. */
3192 vms_debug2 ((3, "%d symbols found\n", abfd->symcount));
3194 bfd_set_start_address (abfd, (bfd_vma) -1);
3196 for (symnum = 0; symnum < abfd->symcount; symnum++)
3200 symbol = abfd->outsymbols[symnum];
3201 if (*(symbol->name) == '_')
3203 if (strcmp (symbol->name, "__main") == 0)
3204 bfd_set_start_address (abfd, (bfd_vma)symbol->value);
3206 old_flags = symbol->flags;
3208 if (old_flags & BSF_FILE)
3211 if ((old_flags & BSF_GLOBAL) == 0 /* Not xdef... */
3212 && !bfd_is_und_section (symbol->section) /* and not xref... */
3213 && !((old_flags & BSF_SECTION_SYM) != 0 /* and not LIB$INITIALIZE. */
3214 && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0))
3217 /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. */
3218 if (_bfd_vms_output_check (recwr, 80) < 0)
3220 _bfd_vms_output_end (abfd, recwr);
3221 _bfd_vms_output_begin (recwr, EOBJ__C_EGSD);
3222 _bfd_vms_output_long (recwr, 0);
3225 _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM);
3227 /* Data type, alignment. */
3228 _bfd_vms_output_short (recwr, 0);
3232 if (old_flags & BSF_WEAK)
3233 new_flags |= EGSY__V_WEAK;
3234 if (bfd_is_com_section (symbol->section)) /* .comm */
3235 new_flags |= (EGSY__V_WEAK | EGSY__V_COMM);
3237 if (old_flags & BSF_FUNCTION)
3239 new_flags |= EGSY__V_NORM;
3240 new_flags |= EGSY__V_REL;
3242 if (old_flags & BSF_GLOBAL)
3244 new_flags |= EGSY__V_DEF;
3245 if (!bfd_is_abs_section (symbol->section))
3246 new_flags |= EGSY__V_REL;
3248 _bfd_vms_output_short (recwr, new_flags);
3250 if (old_flags & BSF_GLOBAL)
3252 /* Symbol definition. */
3253 bfd_vma code_address = 0;
3254 unsigned long ca_psindx = 0;
3255 unsigned long psindx;
3257 if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL)
3261 sym = ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym;
3262 code_address = sym->value;
3263 ca_psindx = sym->section->index;
3265 if (bfd_is_abs_section (symbol->section))
3266 psindx = abs_section_index;
3268 psindx = symbol->section->index;
3270 _bfd_vms_output_quad (recwr, symbol->value);
3271 _bfd_vms_output_quad (recwr, code_address);
3272 _bfd_vms_output_long (recwr, ca_psindx);
3273 _bfd_vms_output_long (recwr, psindx);
3275 hash = _bfd_vms_length_hash_symbol (abfd, symbol->name, EOBJ__C_SYMSIZ);
3276 _bfd_vms_output_counted (recwr, hash);
3278 _bfd_vms_output_end_subrec (recwr);
3282 _bfd_vms_output_alignment (recwr, 8);
3283 _bfd_vms_output_end (abfd, recwr);
3288 /* Write object header for bfd abfd. Return FALSE on error. */
3291 _bfd_vms_write_ehdr (bfd *abfd)
3294 unsigned int symnum;
3298 struct vms_rec_wr *recwr = &PRIV (recwr);
3300 vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd));
3302 _bfd_vms_output_alignment (recwr, 2);
3305 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3306 _bfd_vms_output_short (recwr, EMH__C_MHD);
3307 _bfd_vms_output_short (recwr, EOBJ__C_STRLVL);
3308 _bfd_vms_output_long (recwr, 0);
3309 _bfd_vms_output_long (recwr, 0);
3310 _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE);
3312 /* Create module name from filename. */
3313 if (bfd_get_filename (abfd) != 0)
3315 char *module = vms_get_module_name (bfd_get_filename (abfd), TRUE);
3316 _bfd_vms_output_counted (recwr, module);
3320 _bfd_vms_output_counted (recwr, "NONAME");
3322 _bfd_vms_output_counted (recwr, BFD_VERSION_STRING);
3323 _bfd_vms_output_dump (recwr, get_vms_time_string (), EMH_DATE_LENGTH);
3324 _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH);
3325 _bfd_vms_output_end (abfd, recwr);
3328 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3329 _bfd_vms_output_short (recwr, EMH__C_LNM);
3330 snprintf (version, sizeof (version), "GAS BFD v%s", BFD_VERSION_STRING);
3331 _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version));
3332 _bfd_vms_output_end (abfd, recwr);
3335 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3336 _bfd_vms_output_short (recwr, EMH__C_SRC);
3338 for (symnum = 0; symnum < abfd->symcount; symnum++)
3340 symbol = abfd->outsymbols[symnum];
3342 if (symbol->flags & BSF_FILE)
3344 if (CONST_STRNEQ ((char *)symbol->name, "<CASE:"))
3346 PRIV (flag_hash_long_names) = symbol->name[6] - '0';
3347 PRIV (flag_show_after_trunc) = symbol->name[7] - '0';
3355 _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name,
3356 (int) strlen (symbol->name));
3363 if (symnum == abfd->symcount)
3364 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname"));
3366 _bfd_vms_output_end (abfd, recwr);
3369 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3370 _bfd_vms_output_short (recwr, EMH__C_TTL);
3371 _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL"));
3372 _bfd_vms_output_end (abfd, recwr);
3375 _bfd_vms_output_begin (recwr, EOBJ__C_EMH);
3376 _bfd_vms_output_short (recwr, EMH__C_CPR);
3377 _bfd_vms_output_dump (recwr,
3378 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
3380 _bfd_vms_output_end (abfd, recwr);
3385 /* Part 4.6, relocations. */
3388 /* WRITE ETIR SECTION
3390 This is still under construction and therefore not documented. */
3392 /* Close the etir/etbt record. */
3395 end_etir_record (bfd * abfd)
3397 struct vms_rec_wr *recwr = &PRIV (recwr);
3399 _bfd_vms_output_end (abfd, recwr);
3403 start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset)
3405 struct vms_rec_wr *recwr = &PRIV (recwr);
3407 if (section->name[0] == '.' && section->name[1] == 'v'
3408 && !strcmp (section->name, ".vmsdebug"))
3410 _bfd_vms_output_begin (recwr, EOBJ__C_ETBT);
3414 /* Push start offset. */
3415 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3416 _bfd_vms_output_long (recwr, (unsigned long) 0);
3417 _bfd_vms_output_end_subrec (recwr);
3420 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC);
3421 _bfd_vms_output_end_subrec (recwr);
3426 _bfd_vms_output_begin (recwr, EOBJ__C_ETIR);
3430 /* Push start offset. */
3431 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3432 _bfd_vms_output_long (recwr, (unsigned long) section->index);
3433 _bfd_vms_output_quad (recwr, offset);
3434 _bfd_vms_output_end_subrec (recwr);
3436 /* Start = pop (). */
3437 _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB);
3438 _bfd_vms_output_end_subrec (recwr);
3443 /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual
3444 address VADDR in section specified by SEC_INDEX and NAME. */
3447 sto_imm (bfd *abfd, asection *section,
3448 bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr)
3451 struct vms_rec_wr *recwr = &PRIV (recwr);
3454 _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize);
3455 _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr);
3460 /* Try all the rest. */
3463 if (_bfd_vms_output_check (recwr, size) < 0)
3465 /* Doesn't fit, split ! */
3466 end_etir_record (abfd);
3468 start_etir_or_etbt_record (abfd, section, vaddr);
3470 size = _bfd_vms_output_check (recwr, 0); /* get max size */
3471 if (size > ssize) /* more than what's left ? */
3475 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM);
3476 _bfd_vms_output_long (recwr, (unsigned long) (size));
3477 _bfd_vms_output_dump (recwr, cptr, size);
3478 _bfd_vms_output_end_subrec (recwr);
3481 _bfd_vms_debug (10, "dumped %d bytes\n", (int) size);
3482 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
3492 etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen)
3494 if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0)
3496 /* Not enough room in this record. Close it and open a new one. */
3497 end_etir_record (abfd);
3498 start_etir_or_etbt_record (abfd, section, vaddr);
3502 /* Return whether RELOC must be deferred till the end. */
3505 defer_reloc_p (arelent *reloc)
3507 switch (reloc->howto->type)
3520 /* Write section contents for bfd abfd. Return FALSE on error. */
3523 _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
3526 struct vms_rec_wr *recwr = &PRIV (recwr);
3528 vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype));
3530 _bfd_vms_output_alignment (recwr, 4);
3532 PRIV (vms_linkage_index) = 1;
3534 for (section = abfd->sections; section; section = section->next)
3536 vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n",
3537 section->index, section->name, (int) (section->size)));
3539 if (!(section->flags & SEC_HAS_CONTENTS)
3540 || bfd_is_com_section (section))
3543 if (!section->contents)
3545 bfd_set_error (bfd_error_no_contents);
3549 start_etir_or_etbt_record (abfd, section, 0);
3551 if (section->flags & SEC_RELOC)
3553 bfd_vma curr_addr = 0;
3554 unsigned char *curr_data = section->contents;
3556 int pass2_needed = 0;
3557 int pass2_in_progress = 0;
3560 if (section->reloc_count <= 0)
3561 (*_bfd_error_handler)
3562 (_("SEC_RELOC with no relocs in section %s"), section->name);
3567 int i = section->reloc_count;
3568 arelent **rptr = section->orelocation;
3569 _bfd_vms_debug (4, "%d relocations:\n", i);
3572 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, "
3573 "addr %08lx, off %08lx, len %d: %s\n",
3574 (*(*rptr)->sym_ptr_ptr)->name,
3575 (*(*rptr)->sym_ptr_ptr)->section->name,
3576 (long) (*(*rptr)->sym_ptr_ptr)->value,
3577 (unsigned long)(*rptr)->address,
3578 (unsigned long)(*rptr)->addend,
3579 bfd_get_reloc_size ((*rptr)->howto),
3580 ( *rptr)->howto->name);
3587 for (irel = 0; irel < section->reloc_count; irel++)
3589 struct evax_private_udata_struct *udata;
3590 arelent *rptr = section->orelocation [irel];
3591 bfd_vma addr = rptr->address;
3592 asymbol *sym = *rptr->sym_ptr_ptr;
3593 asection *sec = sym->section;
3594 bfd_boolean defer = defer_reloc_p (rptr);
3598 if (pass2_in_progress)
3600 /* Non-deferred relocs have already been output. */
3606 /* Deferred relocs must be output at the very end. */
3613 /* Regular relocs are intertwined with binary data. */
3614 if (curr_addr > addr)
3615 (*_bfd_error_handler) (_("Size error in section %s"),
3617 size = addr - curr_addr;
3618 sto_imm (abfd, section, size, curr_data, curr_addr);
3623 size = bfd_get_reloc_size (rptr->howto);
3625 switch (rptr->howto->type)
3627 case ALPHA_R_IGNORE:
3630 case ALPHA_R_REFLONG:
3631 if (bfd_is_und_section (sym->section))
3633 bfd_vma addend = rptr->addend;
3634 slen = strlen ((char *) sym->name);
3635 hash = _bfd_vms_length_hash_symbol
3636 (abfd, sym->name, EOBJ__C_SYMSIZ);
3637 etir_output_check (abfd, section, curr_addr, slen);
3640 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
3641 _bfd_vms_output_counted (recwr, hash);
3642 _bfd_vms_output_end_subrec (recwr);
3643 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3644 _bfd_vms_output_long (recwr, (unsigned long) addend);
3645 _bfd_vms_output_end_subrec (recwr);
3646 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
3647 _bfd_vms_output_end_subrec (recwr);
3648 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3649 _bfd_vms_output_end_subrec (recwr);
3653 _bfd_vms_output_begin_subrec
3654 (recwr, ETIR__C_STO_GBL_LW);
3655 _bfd_vms_output_counted (recwr, hash);
3656 _bfd_vms_output_end_subrec (recwr);
3659 else if (bfd_is_abs_section (sym->section))
3661 etir_output_check (abfd, section, curr_addr, 16);
3662 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW);
3663 _bfd_vms_output_long (recwr, (unsigned long) sym->value);
3664 _bfd_vms_output_end_subrec (recwr);
3665 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3666 _bfd_vms_output_end_subrec (recwr);
3670 etir_output_check (abfd, section, curr_addr, 32);
3671 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3672 _bfd_vms_output_long (recwr, (unsigned long) sec->index);
3673 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
3674 _bfd_vms_output_end_subrec (recwr);
3675 /* ??? Table B-8 of the OpenVMS Linker Utilily Manual
3676 says that we should have a ETIR__C_STO_OFF here.
3677 But the relocation would not be BFD_RELOC_32 then.
3678 This case is very likely unreachable. */
3679 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW);
3680 _bfd_vms_output_end_subrec (recwr);
3684 case ALPHA_R_REFQUAD:
3685 if (bfd_is_und_section (sym->section))
3687 bfd_vma addend = rptr->addend;
3688 slen = strlen ((char *) sym->name);
3689 hash = _bfd_vms_length_hash_symbol
3690 (abfd, sym->name, EOBJ__C_SYMSIZ);
3691 etir_output_check (abfd, section, curr_addr, slen);
3694 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL);
3695 _bfd_vms_output_counted (recwr, hash);
3696 _bfd_vms_output_end_subrec (recwr);
3697 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
3698 _bfd_vms_output_quad (recwr, addend);
3699 _bfd_vms_output_end_subrec (recwr);
3700 _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD);
3701 _bfd_vms_output_end_subrec (recwr);
3702 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
3703 _bfd_vms_output_end_subrec (recwr);
3707 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL);
3708 _bfd_vms_output_counted (recwr, hash);
3709 _bfd_vms_output_end_subrec (recwr);
3712 else if (bfd_is_abs_section (sym->section))
3714 etir_output_check (abfd, section, curr_addr, 16);
3715 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW);
3716 _bfd_vms_output_quad (recwr, sym->value);
3717 _bfd_vms_output_end_subrec (recwr);
3718 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW);
3719 _bfd_vms_output_end_subrec (recwr);
3723 etir_output_check (abfd, section, curr_addr, 32);
3724 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ);
3725 _bfd_vms_output_long (recwr, (unsigned long) sec->index);
3726 _bfd_vms_output_quad (recwr, rptr->addend + sym->value);
3727 _bfd_vms_output_end_subrec (recwr);
3728 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF);
3729 _bfd_vms_output_end_subrec (recwr);
3734 sto_imm (abfd, section, size, curr_data, curr_addr);
3737 case ALPHA_R_LINKAGE:
3738 etir_output_check (abfd, section, curr_addr, 64);
3739 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB);
3740 _bfd_vms_output_long
3741 (recwr, (unsigned long) PRIV (vms_linkage_index));
3742 PRIV (vms_linkage_index) += 2;
3743 hash = _bfd_vms_length_hash_symbol
3744 (abfd, sym->name, EOBJ__C_SYMSIZ);
3745 _bfd_vms_output_counted (recwr, hash);
3746 _bfd_vms_output_byte (recwr, 0);
3747 _bfd_vms_output_end_subrec (recwr);
3750 case ALPHA_R_CODEADDR:
3751 slen = strlen ((char *) sym->name);
3752 hash = _bfd_vms_length_hash_symbol
3753 (abfd, sym->name, EOBJ__C_SYMSIZ);
3754 etir_output_check (abfd, section, curr_addr, slen);
3755 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA);
3756 _bfd_vms_output_counted (recwr, hash);
3757 _bfd_vms_output_end_subrec (recwr);
3762 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
3763 etir_output_check (abfd, section, curr_addr,
3764 32 + 1 + strlen (udata->origname));
3765 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL);
3766 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
3767 _bfd_vms_output_long
3768 (recwr, (unsigned long) udata->enbsym->section->index);
3769 _bfd_vms_output_quad (recwr, rptr->address);
3770 _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f);
3771 _bfd_vms_output_long
3772 (recwr, (unsigned long) udata->enbsym->section->index);
3773 _bfd_vms_output_quad (recwr, rptr->addend);
3774 _bfd_vms_output_counted
3775 (recwr, _bfd_vms_length_hash_symbol
3776 (abfd, udata->origname, EOBJ__C_SYMSIZ));
3777 _bfd_vms_output_end_subrec (recwr);
3781 (*_bfd_error_handler) (_("Spurious ALPHA_R_BSR reloc"));
3786 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
3787 etir_output_check (abfd, section, curr_addr,
3788 32 + 1 + strlen (udata->origname));
3789 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL);
3790 _bfd_vms_output_long
3791 (recwr, (unsigned long) udata->lkindex + 1);
3792 _bfd_vms_output_long
3793 (recwr, (unsigned long) udata->enbsym->section->index);
3794 _bfd_vms_output_quad (recwr, rptr->address);
3795 _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000);
3796 _bfd_vms_output_long
3797 (recwr, (unsigned long) udata->bsym->section->index);
3798 _bfd_vms_output_quad (recwr, rptr->addend);
3799 _bfd_vms_output_counted
3800 (recwr, _bfd_vms_length_hash_symbol
3801 (abfd, udata->origname, EOBJ__C_SYMSIZ));
3802 _bfd_vms_output_end_subrec (recwr);
3807 = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr;
3808 etir_output_check (abfd, section, curr_addr,
3809 32 + 1 + strlen (udata->origname));
3810 _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL);
3811 _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex);
3812 _bfd_vms_output_long
3813 (recwr, (unsigned long) udata->enbsym->section->index);
3814 _bfd_vms_output_quad (recwr, rptr->address);
3815 _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000);
3816 _bfd_vms_output_long
3817 (recwr, (unsigned long) udata->enbsym->section->index);
3818 _bfd_vms_output_quad (recwr, rptr->addend);
3819 _bfd_vms_output_counted
3820 (recwr, _bfd_vms_length_hash_symbol
3821 (abfd, udata->origname, EOBJ__C_SYMSIZ));
3822 _bfd_vms_output_end_subrec (recwr);
3826 (*_bfd_error_handler) (_("Unhandled relocation %s"),
3833 } /* End of relocs loop. */
3835 if (!pass2_in_progress)
3837 /* Output rest of section. */
3838 if (curr_addr > section->size)
3839 (*_bfd_error_handler) (_("Size error in section %s"),
3841 size = section->size - curr_addr;
3842 sto_imm (abfd, section, size, curr_data, curr_addr);
3848 pass2_in_progress = 1;
3854 else /* (section->flags & SEC_RELOC) */
3855 sto_imm (abfd, section, section->size, section->contents, 0);
3857 end_etir_record (abfd);
3860 _bfd_vms_output_alignment (recwr, 2);
3864 /* Write eom record for bfd abfd. Return FALSE on error. */
3867 _bfd_vms_write_eeom (bfd *abfd)
3869 struct vms_rec_wr *recwr = &PRIV (recwr);
3871 vms_debug2 ((2, "vms_write_eeom\n"));
3873 _bfd_vms_output_begin (recwr, EOBJ__C_EEOM);
3874 _bfd_vms_output_long (recwr, (unsigned long) (PRIV (vms_linkage_index) >> 1));
3875 _bfd_vms_output_byte (recwr, 0); /* Completion code. */
3876 _bfd_vms_output_byte (recwr, 0); /* Fill byte. */
3878 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
3882 section = bfd_get_section_by_name (abfd, ".link");
3885 bfd_set_error (bfd_error_nonrepresentable_section);
3888 _bfd_vms_output_short (recwr, 0);
3889 _bfd_vms_output_long (recwr, (unsigned long) (section->index));
3890 _bfd_vms_output_long (recwr,
3891 (unsigned long) bfd_get_start_address (abfd));
3892 _bfd_vms_output_long (recwr, 0);
3895 _bfd_vms_output_end (abfd, recwr);
3899 /* Write cached information into a file being written, at bfd_close. */
3902 alpha_vms_write_object_contents (bfd *abfd)
3904 vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd));
3906 if (abfd->flags & (EXEC_P | DYNAMIC))
3908 return alpha_vms_write_exec (abfd);
3912 if (abfd->section_count > 0) /* we have sections */
3914 if (_bfd_vms_write_ehdr (abfd) != TRUE)
3916 if (_bfd_vms_write_egsd (abfd) != TRUE)
3918 if (_bfd_vms_write_etir (abfd, EOBJ__C_ETIR) != TRUE)
3920 if (_bfd_vms_write_eeom (abfd) != TRUE)
3927 /* Debug stuff: nearest line. */
3929 #define SET_MODULE_PARSED(m) \
3930 do { if ((m)->name == NULL) (m)->name = ""; } while (0)
3931 #define IS_MODULE_PARSED(m) ((m)->name != NULL)
3933 /* Build a new module for the specified BFD. */
3935 static struct module *
3936 new_module (bfd *abfd)
3938 struct module *module
3939 = (struct module *) bfd_zalloc (abfd, sizeof (struct module));
3940 module->file_table_count = 16; /* Arbitrary. */
3942 = bfd_malloc (module->file_table_count * sizeof (struct fileinfo));
3946 /* Parse debug info for a module and internalize it. */
3949 parse_module (bfd *abfd, struct module *module, unsigned char *ptr,
3952 unsigned char *maxptr = ptr + length;
3953 unsigned char *src_ptr, *pcl_ptr;
3954 unsigned int prev_linum = 0, curr_linenum = 0;
3955 bfd_vma prev_pc = 0, curr_pc = 0;
3956 struct srecinfo *curr_srec, *srec;
3957 struct lineinfo *curr_line, *line;
3958 struct funcinfo *funcinfo;
3960 /* Initialize tables with zero element. */
3961 curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
3962 module->srec_table = curr_srec;
3964 curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
3965 module->line_table = curr_line;
3967 while (length == -1 || ptr < maxptr)
3969 /* The first byte is not counted in the recorded length. */
3970 int rec_length = bfd_getl16 (ptr) + 1;
3971 int rec_type = bfd_getl16 (ptr + 2);
3973 vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type));
3975 if (length == -1 && rec_type == DST__K_MODEND)
3982 = _bfd_vms_save_counted_string (ptr + DST_S_B_MODBEG_NAME);
3989 vms_debug2 ((3, "module: %s\n", module->name));
3996 funcinfo = (struct funcinfo *)
3997 bfd_zalloc (abfd, sizeof (struct funcinfo));
3999 = _bfd_vms_save_counted_string (ptr + DST_S_B_RTNBEG_NAME);
4000 funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS);
4001 funcinfo->next = module->func_table;
4002 module->func_table = funcinfo;
4004 vms_debug2 ((3, "routine: %s at 0x%lx\n",
4005 funcinfo->name, (unsigned long) funcinfo->low));
4009 module->func_table->high = module->func_table->low
4010 + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1;
4012 if (module->func_table->high > module->high)
4013 module->high = module->func_table->high;
4015 vms_debug2 ((3, "end routine\n"));
4019 vms_debug2 ((3, "prologue\n"));
4023 vms_debug2 ((3, "epilog\n"));
4027 vms_debug2 ((3, "block\n"));
4031 vms_debug2 ((3, "end block\n"));
4035 src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE;
4037 vms_debug2 ((3, "source info\n"));
4039 while (src_ptr < ptr + rec_length)
4041 int cmd = src_ptr[0], cmd_length, data;
4045 case DST__K_SRC_DECLFILE:
4048 = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID);
4050 = _bfd_vms_save_counted_string (src_ptr
4051 + DST_S_B_SRC_DF_FILENAME);
4053 while (fileid >= module->file_table_count)
4055 module->file_table_count *= 2;
4057 = bfd_realloc (module->file_table,
4058 module->file_table_count
4059 * sizeof (struct fileinfo));
4062 module->file_table [fileid].name = filename;
4063 module->file_table [fileid].srec = 1;
4064 cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2;
4065 vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n",
4066 fileid, module->file_table [fileid].name));
4070 case DST__K_SRC_DEFLINES_B:
4071 /* Perform the association and set the next higher index
4073 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4074 srec = (struct srecinfo *)
4075 bfd_zalloc (abfd, sizeof (struct srecinfo));
4076 srec->line = curr_srec->line + data;
4077 srec->srec = curr_srec->srec + data;
4078 srec->sfile = curr_srec->sfile;
4079 curr_srec->next = srec;
4082 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data));
4085 case DST__K_SRC_DEFLINES_W:
4086 /* Perform the association and set the next higher index
4088 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4089 srec = (struct srecinfo *)
4090 bfd_zalloc (abfd, sizeof (struct srecinfo));
4091 srec->line = curr_srec->line + data;
4092 srec->srec = curr_srec->srec + data,
4093 srec->sfile = curr_srec->sfile;
4094 curr_srec->next = srec;
4097 vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data));
4100 case DST__K_SRC_INCRLNUM_B:
4101 data = src_ptr[DST_S_B_SRC_UNSBYTE];
4102 curr_srec->line += data;
4104 vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data));
4107 case DST__K_SRC_SETFILE:
4108 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4109 curr_srec->sfile = data;
4110 curr_srec->srec = module->file_table[data].srec;
4112 vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data));
4115 case DST__K_SRC_SETLNUM_L:
4116 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4117 curr_srec->line = data;
4119 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data));
4122 case DST__K_SRC_SETLNUM_W:
4123 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4124 curr_srec->line = data;
4126 vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data));
4129 case DST__K_SRC_SETREC_L:
4130 data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG);
4131 curr_srec->srec = data;
4132 module->file_table[curr_srec->sfile].srec = data;
4134 vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data));
4137 case DST__K_SRC_SETREC_W:
4138 data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD);
4139 curr_srec->srec = data;
4140 module->file_table[curr_srec->sfile].srec = data;
4142 vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data));
4145 case DST__K_SRC_FORMFEED:
4147 vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n"));
4151 (*_bfd_error_handler) (_("unknown source command %d"),
4157 src_ptr += cmd_length;
4161 case DST__K_LINE_NUM:
4162 pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE;
4164 vms_debug2 ((3, "line info\n"));
4166 while (pcl_ptr < ptr + rec_length)
4168 /* The command byte is signed so we must sign-extend it. */
4169 int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data;
4173 case DST__K_DELTA_PC_W:
4174 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4178 vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data));
4181 case DST__K_DELTA_PC_L:
4182 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4186 vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data));
4189 case DST__K_INCR_LINUM:
4190 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4191 curr_linenum += data;
4193 vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data));
4196 case DST__K_INCR_LINUM_W:
4197 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4198 curr_linenum += data;
4200 vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data));
4203 case DST__K_INCR_LINUM_L:
4204 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4205 curr_linenum += data;
4207 vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data));
4210 case DST__K_SET_LINUM_INCR:
4211 (*_bfd_error_handler)
4212 (_("DST__K_SET_LINUM_INCR not implemented"));
4216 case DST__K_SET_LINUM_INCR_W:
4217 (*_bfd_error_handler)
4218 (_("DST__K_SET_LINUM_INCR_W not implemented"));
4222 case DST__K_RESET_LINUM_INCR:
4223 (*_bfd_error_handler)
4224 (_("DST__K_RESET_LINUM_INCR not implemented"));
4228 case DST__K_BEG_STMT_MODE:
4229 (*_bfd_error_handler)
4230 (_("DST__K_BEG_STMT_MODE not implemented"));
4234 case DST__K_END_STMT_MODE:
4235 (*_bfd_error_handler)
4236 (_("DST__K_END_STMT_MODE not implemented"));
4240 case DST__K_SET_LINUM_B:
4241 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4242 curr_linenum = data;
4244 vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data));
4247 case DST__K_SET_LINUM:
4248 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4249 curr_linenum = data;
4251 vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data));
4254 case DST__K_SET_LINUM_L:
4255 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4256 curr_linenum = data;
4258 vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data));
4262 (*_bfd_error_handler)
4263 (_("DST__K_SET_PC not implemented"));
4267 case DST__K_SET_PC_W:
4268 (*_bfd_error_handler)
4269 (_("DST__K_SET_PC_W not implemented"));
4273 case DST__K_SET_PC_L:
4274 (*_bfd_error_handler)
4275 (_("DST__K_SET_PC_L not implemented"));
4279 case DST__K_SET_STMTNUM:
4280 (*_bfd_error_handler)
4281 (_("DST__K_SET_STMTNUM not implemented"));
4286 data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE];
4289 vms_debug2 ((4, "DST__K_TERM: %d\n", data));
4293 data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD);
4296 vms_debug2 ((4, "DST__K_TERM_W: %d\n", data));
4300 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4303 vms_debug2 ((4, "DST__K_TERM_L: %d\n", data));
4306 case DST__K_SET_ABS_PC:
4307 data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG);
4310 vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data));
4319 vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n",
4320 (unsigned long)curr_pc, curr_linenum));
4324 (*_bfd_error_handler) (_("unknown line command %d"),
4331 if ((curr_linenum != prev_linum && curr_pc != prev_pc)
4333 || cmd == DST__K_DELTA_PC_L
4334 || cmd == DST__K_DELTA_PC_W)
4336 line = (struct lineinfo *)
4337 bfd_zalloc (abfd, sizeof (struct lineinfo));
4338 line->address = curr_pc;
4339 line->line = curr_linenum;
4341 curr_line->next = line;
4344 prev_linum = curr_linenum;
4346 vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n",
4347 (unsigned long)curr_pc, curr_linenum));
4350 pcl_ptr += cmd_length;
4354 case 0x17: /* Undocumented type used by DEC C to declare equates. */
4355 vms_debug2 ((3, "undocumented type 0x17\n"));
4359 vms_debug2 ((3, "ignoring record\n"));
4367 /* Finalize tables with EOL marker. */
4368 srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo));
4369 srec->line = (unsigned int) -1;
4370 srec->srec = (unsigned int) -1;
4371 curr_srec->next = srec;
4373 line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo));
4374 line->line = (unsigned int) -1;
4375 line->address = (bfd_vma) -1;
4376 curr_line->next = line;
4378 /* Advertise that this module has been parsed. This is needed
4379 because parsing can be either performed at module creation
4380 or deferred until debug info is consumed. */
4381 SET_MODULE_PARSED (module);
4384 /* Build the list of modules for the specified BFD. */
4386 static struct module *
4387 build_module_list (bfd *abfd)
4389 struct module *module, *list = NULL;
4392 if ((dmt = bfd_get_section_by_name (abfd, "$DMT$")))
4394 /* We have a DMT section so this must be an image. Parse the
4395 section and build the list of modules. This is sufficient
4396 since we can compute the start address and the end address
4397 of every module from the section contents. */
4398 bfd_size_type size = bfd_get_section_size (dmt);
4399 unsigned char *ptr, *end;
4401 ptr = (unsigned char *) bfd_alloc (abfd, size);
4405 if (! bfd_get_section_contents (abfd, dmt, ptr, 0, size))
4408 vms_debug2 ((2, "DMT\n"));
4414 /* Each header declares a module with its start offset and size
4415 of debug info in the DST section, as well as the count of
4416 program sections (i.e. address spans) it contains. */
4417 int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG);
4418 int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE);
4419 int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT);
4420 ptr += DBG_S_C_DMT_HEADER_SIZE;
4422 vms_debug2 ((3, "module: modbeg = %d, size = %d, count = %d\n",
4423 modbeg, msize, count));
4425 /* We create a 'module' structure for each program section since
4426 we only support contiguous addresses in a 'module' structure.
4427 As a consequence, the actual debug info in the DST section is
4428 shared and can be parsed multiple times; that doesn't seem to
4429 cause problems in practice. */
4432 int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START);
4433 int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH);
4434 module = new_module (abfd);
4435 module->modbeg = modbeg;
4436 module->size = msize;
4437 module->low = start;
4438 module->high = start + length;
4439 module->next = list;
4441 ptr += DBG_S_C_DMT_PSECT_SIZE;
4443 vms_debug2 ((4, "section: start = 0x%x, length = %d\n",
4450 /* We don't have a DMT section so this must be an object. Parse
4451 the module right now in order to compute its start address and
4453 module = new_module (abfd);
4454 parse_module (abfd, module, PRIV (dst_section)->contents, -1);
4461 /* Calculate and return the name of the source file and the line nearest
4462 to the wanted location in the specified module. */
4465 module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr,
4466 const char **file, const char **func,
4469 struct funcinfo *funcinfo;
4470 struct lineinfo *lineinfo;
4471 struct srecinfo *srecinfo;
4472 bfd_boolean ret = FALSE;
4474 /* Parse this module if that was not done at module creation. */
4475 if (! IS_MODULE_PARSED (module))
4477 unsigned int size = module->size;
4478 unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg;
4479 unsigned char *buffer = (unsigned char *) bfd_malloc (module->size);
4481 if (bfd_seek (abfd, modbeg, SEEK_SET) != 0
4482 || bfd_bread (buffer, size, abfd) != size)
4484 bfd_set_error (bfd_error_no_debug_section);
4488 parse_module (abfd, module, buffer, size);
4492 /* Find out the function (if any) that contains the address. */
4493 for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next)
4494 if (addr >= funcinfo->low && addr <= funcinfo->high)
4496 *func = funcinfo->name;
4501 /* Find out the source file and the line nearest to the address. */
4502 for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next)
4503 if (lineinfo->next && addr < lineinfo->next->address)
4505 for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next)
4506 if (srecinfo->next && lineinfo->line < srecinfo->next->line)
4508 if (srecinfo->sfile > 0)
4510 *file = module->file_table[srecinfo->sfile].name;
4511 *line = srecinfo->srec + lineinfo->line - srecinfo->line;
4515 *file = module->name;
4516 *line = lineinfo->line;
4527 /* Provided a BFD, a section and an offset into the section, calculate and
4528 return the name of the source file and the line nearest to the wanted
4532 _bfd_vms_find_nearest_dst_line (bfd *abfd, asection *section,
4533 asymbol **symbols ATTRIBUTE_UNUSED,
4534 bfd_vma offset, const char **file,
4535 const char **func, unsigned int *line)
4537 struct module *module;
4539 /* What address are we looking for? */
4540 bfd_vma addr = section->vma + offset;
4546 if (PRIV (dst_section) == NULL || !(abfd->flags & (EXEC_P | DYNAMIC)))
4549 if (PRIV (modules) == NULL)
4551 PRIV (modules) = build_module_list (abfd);
4552 if (PRIV (modules) == NULL)
4556 for (module = PRIV (modules); module; module = module->next)
4557 if (addr >= module->low && addr <= module->high)
4558 return module_find_nearest_line (abfd, module, addr, file, func, line);
4563 /* Canonicalizations. */
4564 /* Set name, value, section and flags of SYM from E. */
4567 alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym)
4576 flags = BSF_NO_FLAGS;
4582 if (e->flags & EGSY__V_WEAK)
4585 if (e->flags & EGSY__V_DEF)
4587 /* Symbol definition. */
4588 flags |= BSF_GLOBAL;
4589 if (e->flags & EGSY__V_NORM)
4590 flags |= BSF_FUNCTION;
4592 sec = PRIV (sections)[e->section];
4596 /* Symbol reference. */
4597 sec = bfd_und_section_ptr;
4602 /* A universal symbol is by definition global... */
4603 flags |= BSF_GLOBAL;
4605 /* ...and dynamic in shared libraries. */
4606 if (abfd->flags & DYNAMIC)
4607 flags |= BSF_DYNAMIC;
4609 if (e->flags & EGSY__V_WEAK)
4612 if (!(e->flags & EGSY__V_DEF))
4615 if (e->flags & EGSY__V_NORM)
4616 flags |= BSF_FUNCTION;
4618 value = e->symbol_vector;
4620 /* Adding this offset is necessary in order for GDB to
4621 read the DWARF-2 debug info from shared libraries. */
4622 if ((abfd->flags & DYNAMIC) && strstr (name, "$DWARF2.DEBUG") != 0)
4623 value += PRIV (symvva);
4625 sec = bfd_abs_section_ptr;
4627 /* Find containing section. */
4632 for (s = abfd->sections; s; s = s->next)
4636 && !(s->flags & SEC_COFF_SHARED_LIBRARY)
4637 && (s->size > 0 || !(e->flags & EGSY__V_REL)))
4661 /* Return the number of bytes required to store a vector of pointers
4662 to asymbols for all the symbols in the BFD abfd, including a
4663 terminal NULL pointer. If there are no symbols in the BFD,
4664 then return 0. If an error occurs, return -1. */
4667 alpha_vms_get_symtab_upper_bound (bfd *abfd)
4669 vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n",
4670 abfd, PRIV (gsd_sym_count)));
4672 return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *);
4675 /* Read the symbols from the BFD abfd, and fills in the vector
4676 location with pointers to the symbols and a trailing NULL.
4678 Return number of symbols read. */
4681 alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols)
4685 vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd));
4687 if (PRIV (csymbols) == NULL)
4689 PRIV (csymbols) = (asymbol **) bfd_alloc
4690 (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *));
4692 /* Traverse table and fill symbols vector. */
4693 for (i = 0; i < PRIV (gsd_sym_count); i++)
4695 struct vms_symbol_entry *e = PRIV (syms)[i];
4698 sym = bfd_make_empty_symbol (abfd);
4699 if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym))
4701 bfd_release (abfd, PRIV (csymbols));
4702 PRIV (csymbols) = NULL;
4706 PRIV (csymbols)[i] = sym;
4710 if (symbols != NULL)
4712 for (i = 0; i < PRIV (gsd_sym_count); i++)
4713 symbols[i] = PRIV (csymbols)[i];
4717 return PRIV (gsd_sym_count);
4720 /* Read and convert relocations from ETIR. We do it once for all sections. */
4723 alpha_vms_slurp_relocs (bfd *abfd)
4727 vms_debug2 ((3, "alpha_vms_slurp_relocs\n"));
4729 /* We slurp relocs only once, for all sections. */
4730 if (PRIV (reloc_done))
4732 PRIV (reloc_done) = TRUE;
4734 if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0)
4737 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
4742 unsigned char *begin;
4745 bfd_reloc_code_real_type reloc_code;
4751 bfd_vma cur_address;
4753 unsigned char *cur_sym = NULL;
4755 bfd_vma cur_addend = 0;
4757 /* Skip non-ETIR records. */
4758 type = _bfd_vms_get_object_record (abfd);
4759 if (type == EOBJ__C_EEOM)
4761 if (type != EOBJ__C_ETIR)
4764 begin = PRIV (recrd.rec) + 4;
4765 end = PRIV (recrd.rec) + PRIV (recrd.rec_size);
4767 for (ptr = begin; ptr < end; ptr += length)
4771 cmd = bfd_getl16 (ptr);
4772 length = bfd_getl16 (ptr + 2);
4774 cur_address = vaddr;
4776 vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n",
4777 _bfd_vms_etir_name (cmd)));
4781 case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */
4782 /* ALPHA_R_REFQUAD und_section, step 1 */
4787 case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */
4788 cur_psidx = bfd_getl32 (ptr + 4);
4789 cur_addend = bfd_getl64 (ptr + 8);
4793 case ETIR__C_CTL_SETRB:
4794 if (prev_cmd != ETIR__C_STA_PQ)
4796 (*_bfd_error_handler)
4797 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd),
4798 _bfd_vms_etir_name (cmd));
4801 cur_psect = cur_psidx;
4807 case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */
4808 /* ALPHA_R_REFLONG und_section, step 2 */
4811 if (prev_cmd != ETIR__C_STA_GBL)
4813 (*_bfd_error_handler)
4814 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
4815 _bfd_vms_etir_name (ETIR__C_STA_LW));
4819 cur_addend = bfd_getl32 (ptr + 4);
4823 case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */
4824 /* ALPHA_R_REFQUAD und_section, step 2 */
4825 if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL)
4827 (*_bfd_error_handler)
4828 (_("Unknown reloc %s + %s"), _bfd_vms_etir_name (cmd),
4829 _bfd_vms_etir_name (ETIR__C_STA_QW));
4832 cur_addend = bfd_getl64 (ptr + 4);
4836 case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */
4837 /* ALPHA_R_REFLONG abs_section, step 2 */
4838 /* ALPHA_R_REFLONG others, step 2 */
4839 if (prev_cmd != ETIR__C_OPR_ADD
4840 && prev_cmd != ETIR__C_STA_LW
4841 && prev_cmd != ETIR__C_STA_PQ)
4843 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4844 _bfd_vms_etir_name (prev_cmd),
4845 _bfd_vms_etir_name (ETIR__C_STO_LW));
4848 reloc_code = BFD_RELOC_32;
4851 case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */
4852 /* ALPHA_R_REFQUAD abs_section, step 2 */
4853 if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW)
4855 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4856 _bfd_vms_etir_name (prev_cmd),
4857 _bfd_vms_etir_name (ETIR__C_STO_QW));
4860 reloc_code = BFD_RELOC_64;
4863 case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */
4864 if (prev_cmd != ETIR__C_STA_PQ)
4866 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4867 _bfd_vms_etir_name (prev_cmd),
4868 _bfd_vms_etir_name (ETIR__C_STO_OFF));
4871 reloc_code = BFD_RELOC_64;
4874 case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */
4875 /* ALPHA_R_REFQUAD und_section, step 3 */
4876 if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW)
4878 (*_bfd_error_handler) (_("Unknown reloc %s + %s"),
4879 _bfd_vms_etir_name (prev_cmd),
4880 _bfd_vms_etir_name (ETIR__C_OPR_ADD));
4883 prev_cmd = ETIR__C_OPR_ADD;
4886 case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */
4887 reloc_code = BFD_RELOC_ALPHA_CODEADDR;
4891 case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */
4892 reloc_code = BFD_RELOC_64;
4896 case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */
4897 reloc_code = BFD_RELOC_32;
4901 case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */
4902 reloc_code = BFD_RELOC_ALPHA_LINKAGE;
4906 case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */
4907 reloc_code = BFD_RELOC_ALPHA_NOP;
4910 case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */
4911 reloc_code = BFD_RELOC_ALPHA_BSR;
4914 case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */
4915 reloc_code = BFD_RELOC_ALPHA_LDA;
4918 case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */
4919 reloc_code = BFD_RELOC_ALPHA_BOH;
4923 cur_sym = ptr + 4 + 32;
4924 cur_address = bfd_getl64 (ptr + 4 + 8);
4925 cur_addend = bfd_getl64 (ptr + 4 + 24);
4928 case ETIR__C_STO_IMM:
4929 vaddr += bfd_getl32 (ptr + 4);
4933 (*_bfd_error_handler) (_("Unknown reloc %s"),
4934 _bfd_vms_etir_name (cmd));
4940 struct vms_section_data_struct *vms_sec;
4943 /* Get section to which the relocation applies. */
4944 if (cur_psect < 0 || cur_psect > (int)PRIV (section_count))
4946 (*_bfd_error_handler) (_("Invalid section index in ETIR"));
4949 sec = PRIV (sections)[cur_psect];
4950 vms_sec = vms_section_data (sec);
4952 /* Allocate a reloc entry. */
4953 if (sec->reloc_count >= vms_sec->reloc_max)
4955 if (vms_sec->reloc_max == 0)
4957 vms_sec->reloc_max = 64;
4958 sec->relocation = bfd_zmalloc
4959 (vms_sec->reloc_max * sizeof (arelent));
4963 vms_sec->reloc_max *= 2;
4964 sec->relocation = bfd_realloc
4965 (sec->relocation, vms_sec->reloc_max * sizeof (arelent));
4968 reloc = &sec->relocation[sec->reloc_count];
4971 reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code);
4973 if (cur_sym != NULL)
4976 unsigned int symlen = *cur_sym;
4979 /* Linear search. */
4984 for (j = 0; j < PRIV (gsd_sym_count); j++)
4985 if (PRIV (syms)[j]->namelen == symlen
4986 && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0)
4988 sym = &PRIV (csymbols)[j];
4993 (*_bfd_error_handler) (_("Unknown symbol in command %s"),
4994 _bfd_vms_etir_name (cmd));
4995 reloc->sym_ptr_ptr = NULL;
4998 reloc->sym_ptr_ptr = sym;
5000 else if (cur_psidx >= 0)
5001 reloc->sym_ptr_ptr =
5002 PRIV (sections)[cur_psidx]->symbol_ptr_ptr;
5004 reloc->sym_ptr_ptr = NULL;
5006 reloc->address = cur_address;
5007 reloc->addend = cur_addend;
5009 vaddr += bfd_get_reloc_size (reloc->howto);
5018 vms_debug2 ((3, "alpha_vms_slurp_relocs: result = TRUE\n"));
5023 /* Return the number of bytes required to store the relocation
5024 information associated with the given section. */
5027 alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section)
5029 alpha_vms_slurp_relocs (abfd);
5031 return (section->reloc_count + 1) * sizeof (arelent *);
5034 /* Convert relocations from VMS (external) form into BFD internal
5035 form. Return the number of relocations. */
5038 alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr,
5039 asymbol **symbols ATTRIBUTE_UNUSED)
5044 if (!alpha_vms_slurp_relocs (abfd))
5047 count = section->reloc_count;
5048 tblptr = section->relocation;
5051 *relptr++ = tblptr++;
5053 *relptr = (arelent *) NULL;
5054 return section->reloc_count;
5057 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
5059 /* How to process the various reloc types. */
5061 static bfd_reloc_status_type
5062 reloc_nil (bfd * abfd ATTRIBUTE_UNUSED,
5063 arelent *reloc ATTRIBUTE_UNUSED,
5064 asymbol *sym ATTRIBUTE_UNUSED,
5065 void * data ATTRIBUTE_UNUSED,
5066 asection *sec ATTRIBUTE_UNUSED,
5067 bfd *output_bfd ATTRIBUTE_UNUSED,
5068 char **error_message ATTRIBUTE_UNUSED)
5071 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd);
5072 vms_debug (2, "In section %s, symbol %s\n",
5073 sec->name, sym->name);
5074 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
5075 reloc->sym_ptr_ptr[0]->name,
5076 (unsigned long)reloc->address,
5077 (unsigned long)reloc->addend, reloc->howto->name);
5078 vms_debug (2, "data at %p\n", data);
5079 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
5082 return bfd_reloc_ok;
5085 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
5086 from smaller values. Start with zero, widen, *then* decrement. */
5087 #define MINUS_ONE (((bfd_vma)0) - 1)
5089 static reloc_howto_type alpha_howto_table[] =
5091 HOWTO (ALPHA_R_IGNORE, /* Type. */
5092 0, /* Rightshift. */
5093 0, /* Size (0 = byte, 1 = short, 2 = long). */
5095 TRUE, /* PC relative. */
5097 complain_overflow_dont,/* Complain_on_overflow. */
5098 reloc_nil, /* Special_function. */
5099 "IGNORE", /* Name. */
5100 TRUE, /* Partial_inplace. */
5101 0, /* Source mask */
5103 TRUE), /* PC rel offset. */
5105 /* A 64 bit reference to a symbol. */
5106 HOWTO (ALPHA_R_REFQUAD, /* Type. */
5107 0, /* Rightshift. */
5108 4, /* Size (0 = byte, 1 = short, 2 = long). */
5110 FALSE, /* PC relative. */
5112 complain_overflow_bitfield, /* Complain_on_overflow. */
5113 reloc_nil, /* Special_function. */
5114 "REFQUAD", /* Name. */
5115 TRUE, /* Partial_inplace. */
5116 MINUS_ONE, /* Source mask. */
5117 MINUS_ONE, /* Dest mask. */
5118 FALSE), /* PC rel offset. */
5120 /* A 21 bit branch. The native assembler generates these for
5121 branches within the text segment, and also fills in the PC
5122 relative offset in the instruction. */
5123 HOWTO (ALPHA_R_BRADDR, /* Type. */
5124 2, /* Rightshift. */
5125 2, /* Size (0 = byte, 1 = short, 2 = long). */
5127 TRUE, /* PC relative. */
5129 complain_overflow_signed, /* Complain_on_overflow. */
5130 reloc_nil, /* Special_function. */
5131 "BRADDR", /* Name. */
5132 TRUE, /* Partial_inplace. */
5133 0x1fffff, /* Source mask. */
5134 0x1fffff, /* Dest mask. */
5135 FALSE), /* PC rel offset. */
5137 /* A hint for a jump to a register. */
5138 HOWTO (ALPHA_R_HINT, /* Type. */
5139 2, /* Rightshift. */
5140 1, /* Size (0 = byte, 1 = short, 2 = long). */
5142 TRUE, /* PC relative. */
5144 complain_overflow_dont,/* Complain_on_overflow. */
5145 reloc_nil, /* Special_function. */
5147 TRUE, /* Partial_inplace. */
5148 0x3fff, /* Source mask. */
5149 0x3fff, /* Dest mask. */
5150 FALSE), /* PC rel offset. */
5152 /* 16 bit PC relative offset. */
5153 HOWTO (ALPHA_R_SREL16, /* Type. */
5154 0, /* Rightshift. */
5155 1, /* Size (0 = byte, 1 = short, 2 = long). */
5157 TRUE, /* PC relative. */
5159 complain_overflow_signed, /* Complain_on_overflow. */
5160 reloc_nil, /* Special_function. */
5161 "SREL16", /* Name. */
5162 TRUE, /* Partial_inplace. */
5163 0xffff, /* Source mask. */
5164 0xffff, /* Dest mask. */
5165 FALSE), /* PC rel offset. */
5167 /* 32 bit PC relative offset. */
5168 HOWTO (ALPHA_R_SREL32, /* Type. */
5169 0, /* Rightshift. */
5170 2, /* Size (0 = byte, 1 = short, 2 = long). */
5172 TRUE, /* PC relative. */
5174 complain_overflow_signed, /* Complain_on_overflow. */
5175 reloc_nil, /* Special_function. */
5176 "SREL32", /* Name. */
5177 TRUE, /* Partial_inplace. */
5178 0xffffffff, /* Source mask. */
5179 0xffffffff, /* Dest mask. */
5180 FALSE), /* PC rel offset. */
5182 /* A 64 bit PC relative offset. */
5183 HOWTO (ALPHA_R_SREL64, /* Type. */
5184 0, /* Rightshift. */
5185 4, /* Size (0 = byte, 1 = short, 2 = long). */
5187 TRUE, /* PC relative. */
5189 complain_overflow_signed, /* Complain_on_overflow. */
5190 reloc_nil, /* Special_function. */
5191 "SREL64", /* Name. */
5192 TRUE, /* Partial_inplace. */
5193 MINUS_ONE, /* Source mask. */
5194 MINUS_ONE, /* Dest mask. */
5195 FALSE), /* PC rel offset. */
5197 /* Push a value on the reloc evaluation stack. */
5198 HOWTO (ALPHA_R_OP_PUSH, /* Type. */
5199 0, /* Rightshift. */
5200 0, /* Size (0 = byte, 1 = short, 2 = long). */
5202 FALSE, /* PC relative. */
5204 complain_overflow_dont,/* Complain_on_overflow. */
5205 reloc_nil, /* Special_function. */
5206 "OP_PUSH", /* Name. */
5207 FALSE, /* Partial_inplace. */
5208 0, /* Source mask. */
5210 FALSE), /* PC rel offset. */
5212 /* Store the value from the stack at the given address. Store it in
5213 a bitfield of size r_size starting at bit position r_offset. */
5214 HOWTO (ALPHA_R_OP_STORE, /* Type. */
5215 0, /* Rightshift. */
5216 4, /* Size (0 = byte, 1 = short, 2 = long). */
5218 FALSE, /* PC relative. */
5220 complain_overflow_dont,/* Complain_on_overflow. */
5221 reloc_nil, /* Special_function. */
5222 "OP_STORE", /* Name. */
5223 FALSE, /* Partial_inplace. */
5224 0, /* Source mask. */
5225 MINUS_ONE, /* Dest mask. */
5226 FALSE), /* PC rel offset. */
5228 /* Subtract the reloc address from the value on the top of the
5229 relocation stack. */
5230 HOWTO (ALPHA_R_OP_PSUB, /* Type. */
5231 0, /* Rightshift. */
5232 0, /* Size (0 = byte, 1 = short, 2 = long). */
5234 FALSE, /* PC relative. */
5236 complain_overflow_dont,/* Complain_on_overflow. */
5237 reloc_nil, /* Special_function. */
5238 "OP_PSUB", /* Name. */
5239 FALSE, /* Partial_inplace. */
5240 0, /* Source mask. */
5242 FALSE), /* PC rel offset. */
5244 /* Shift the value on the top of the relocation stack right by the
5246 HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */
5247 0, /* Rightshift. */
5248 0, /* Size (0 = byte, 1 = short, 2 = long). */
5250 FALSE, /* PC relative. */
5252 complain_overflow_dont,/* Complain_on_overflow. */
5253 reloc_nil, /* Special_function. */
5254 "OP_PRSHIFT", /* Name. */
5255 FALSE, /* Partial_inplace. */
5256 0, /* Source mask. */
5258 FALSE), /* PC rel offset. */
5260 /* Hack. Linkage is done by linker. */
5261 HOWTO (ALPHA_R_LINKAGE, /* Type. */
5262 0, /* Rightshift. */
5263 8, /* Size (0 = byte, 1 = short, 2 = long). */
5265 FALSE, /* PC relative. */
5267 complain_overflow_dont,/* Complain_on_overflow. */
5268 reloc_nil, /* Special_function. */
5269 "LINKAGE", /* Name. */
5270 FALSE, /* Partial_inplace. */
5271 0, /* Source mask. */
5273 FALSE), /* PC rel offset. */
5275 /* A 32 bit reference to a symbol. */
5276 HOWTO (ALPHA_R_REFLONG, /* Type. */
5277 0, /* Rightshift. */
5278 2, /* Size (0 = byte, 1 = short, 2 = long). */
5280 FALSE, /* PC relative. */
5282 complain_overflow_bitfield, /* Complain_on_overflow. */
5283 reloc_nil, /* Special_function. */
5284 "REFLONG", /* Name. */
5285 TRUE, /* Partial_inplace. */
5286 0xffffffff, /* Source mask. */
5287 0xffffffff, /* Dest mask. */
5288 FALSE), /* PC rel offset. */
5290 /* A 64 bit reference to a procedure, written as 32 bit value. */
5291 HOWTO (ALPHA_R_CODEADDR, /* Type. */
5292 0, /* Rightshift. */
5293 4, /* Size (0 = byte, 1 = short, 2 = long). */
5295 FALSE, /* PC relative. */
5297 complain_overflow_signed,/* Complain_on_overflow. */
5298 reloc_nil, /* Special_function. */
5299 "CODEADDR", /* Name. */
5300 FALSE, /* Partial_inplace. */
5301 0xffffffff, /* Source mask. */
5302 0xffffffff, /* Dest mask. */
5303 FALSE), /* PC rel offset. */
5305 HOWTO (ALPHA_R_NOP, /* Type. */
5306 0, /* Rightshift. */
5307 3, /* Size (0 = byte, 1 = short, 2 = long). */
5309 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
5310 because the calculations for the 3 relocations are the same.
5311 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
5312 TRUE, /* PC relative. */
5314 complain_overflow_dont,/* Complain_on_overflow. */
5315 reloc_nil, /* Special_function. */
5317 FALSE, /* Partial_inplace. */
5318 0xffffffff, /* Source mask. */
5319 0xffffffff, /* Dest mask. */
5320 FALSE), /* PC rel offset. */
5322 HOWTO (ALPHA_R_BSR, /* Type. */
5323 0, /* Rightshift. */
5324 3, /* Size (0 = byte, 1 = short, 2 = long). */
5326 TRUE, /* PC relative. */
5328 complain_overflow_dont,/* Complain_on_overflow. */
5329 reloc_nil, /* Special_function. */
5331 FALSE, /* Partial_inplace. */
5332 0xffffffff, /* Source mask. */
5333 0xffffffff, /* Dest mask. */
5334 FALSE), /* PC rel offset. */
5336 HOWTO (ALPHA_R_LDA, /* Type. */
5337 0, /* Rightshift. */
5338 3, /* Size (0 = byte, 1 = short, 2 = long). */
5340 FALSE, /* PC relative. */
5342 complain_overflow_dont,/* Complain_on_overflow. */
5343 reloc_nil, /* Special_function. */
5345 FALSE, /* Partial_inplace. */
5346 0xffffffff, /* Source mask. */
5347 0xffffffff, /* Dest mask. */
5348 FALSE), /* PC rel offset. */
5350 HOWTO (ALPHA_R_BOH, /* Type. */
5351 0, /* Rightshift. */
5352 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
5354 TRUE, /* PC relative. */
5356 complain_overflow_dont,/* Complain_on_overflow. */
5357 reloc_nil, /* Special_function. */
5359 FALSE, /* Partial_inplace. */
5360 0xffffffff, /* Source mask. */
5361 0xffffffff, /* Dest mask. */
5362 FALSE), /* PC rel offset. */
5365 /* Return a pointer to a howto structure which, when invoked, will perform
5366 the relocation code on data from the architecture noted. */
5368 static const struct reloc_howto_struct *
5369 alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
5370 bfd_reloc_code_real_type code)
5374 vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code));
5378 case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break;
5379 case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break;
5380 case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break;
5381 case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break;
5382 case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break;
5383 case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break;
5384 case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break;
5385 case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break;
5386 case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break;
5387 case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break;
5388 case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break;
5389 case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break;
5390 case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break;
5391 case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break;
5392 case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break;
5394 (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code);
5397 vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name));
5398 return & alpha_howto_table[alpha_type];
5401 static reloc_howto_type *
5402 alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
5408 i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]);
5410 if (alpha_howto_table[i].name != NULL
5411 && strcasecmp (alpha_howto_table[i].name, r_name) == 0)
5412 return &alpha_howto_table[i];
5418 alpha_vms_get_synthetic_symtab (bfd *abfd,
5419 long symcount ATTRIBUTE_UNUSED,
5420 asymbol **usyms ATTRIBUTE_UNUSED,
5421 long dynsymcount ATTRIBUTE_UNUSED,
5422 asymbol **dynsyms ATTRIBUTE_UNUSED,
5429 syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol));
5434 for (i = 0; i < PRIV (gsd_sym_count); i++)
5436 struct vms_symbol_entry *e = PRIV (syms)[i];
5447 flags = BSF_LOCAL | BSF_SYNTHETIC;
5453 if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM))
5455 value = e->code_value;
5456 sec = PRIV (sections)[e->code_section];
5463 if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM))
5468 value = e->code_value;
5470 /* Find containing section. */
5471 for (s = abfd->sections; s; s = s->next)
5475 && !(s->flags & SEC_COFF_SHARED_LIBRARY)
5476 && (s->size > 0 || !(e->flags & EGSY__V_REL)))
5493 sname = bfd_alloc (abfd, l + 5);
5496 memcpy (sname, name, l);
5497 memcpy (sname + l, "..en", 5);
5504 sym->udata.p = NULL;
5513 vms_time_to_str (unsigned char *buf)
5515 time_t t = vms_rawtime_to_time_t (buf);
5516 char *res = ctime (&t);
5519 res = "*invalid time*";
5526 evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len)
5528 struct vms_emh_common *emh = (struct vms_emh_common *)rec;
5529 unsigned int subtype;
5531 subtype = (unsigned)bfd_getl16 (emh->subtyp);
5533 fprintf (file, _(" EMH %u (len=%u): "), subtype, rec_len);
5539 struct vms_emh_mhd *mhd = (struct vms_emh_mhd *)rec;
5542 fprintf (file, _("Module header\n"));
5543 fprintf (file, _(" structure level: %u\n"), mhd->strlvl);
5544 fprintf (file, _(" max record size: %u\n"),
5545 (unsigned)bfd_getl32 (mhd->recsiz));
5546 name = (char *)(mhd + 1);
5547 fprintf (file, _(" module name : %.*s\n"), name[0], name + 1);
5548 name += name[0] + 1;
5549 fprintf (file, _(" module version : %.*s\n"), name[0], name + 1);
5550 name += name[0] + 1;
5551 fprintf (file, _(" compile date : %.17s\n"), name);
5556 fprintf (file, _("Language Processor Name\n"));
5557 fprintf (file, _(" language name: %.*s\n"),
5558 (int)(rec_len - sizeof (struct vms_emh_common)),
5559 (char *)rec + sizeof (struct vms_emh_common));
5564 fprintf (file, _("Source Files Header\n"));
5565 fprintf (file, _(" file: %.*s\n"),
5566 (int)(rec_len - sizeof (struct vms_emh_common)),
5567 (char *)rec + sizeof (struct vms_emh_common));
5572 fprintf (file, _("Title Text Header\n"));
5573 fprintf (file, _(" title: %.*s\n"),
5574 (int)(rec_len - sizeof (struct vms_emh_common)),
5575 (char *)rec + sizeof (struct vms_emh_common));
5580 fprintf (file, _("Copyright Header\n"));
5581 fprintf (file, _(" copyright: %.*s\n"),
5582 (int)(rec_len - sizeof (struct vms_emh_common)),
5583 (char *)rec + sizeof (struct vms_emh_common));
5587 fprintf (file, _("unhandled emh subtype %u\n"), subtype);
5593 evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len)
5595 struct vms_eeom *eeom = (struct vms_eeom *)rec;
5597 fprintf (file, _(" EEOM (len=%u):\n"), rec_len);
5598 fprintf (file, _(" number of cond linkage pairs: %u\n"),
5599 (unsigned)bfd_getl32 (eeom->total_lps));
5600 fprintf (file, _(" completion code: %u\n"),
5601 (unsigned)bfd_getl16 (eeom->comcod));
5604 fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg);
5605 fprintf (file, _(" transfer addr psect: %u\n"),
5606 (unsigned)bfd_getl32 (eeom->psindx));
5607 fprintf (file, _(" transfer address : 0x%08x\n"),
5608 (unsigned)bfd_getl32 (eeom->tfradr));
5613 exav_bfd_print_egsy_flags (unsigned int flags, FILE *file)
5615 if (flags & EGSY__V_WEAK)
5616 fputs (_(" WEAK"), file);
5617 if (flags & EGSY__V_DEF)
5618 fputs (_(" DEF"), file);
5619 if (flags & EGSY__V_UNI)
5620 fputs (_(" UNI"), file);
5621 if (flags & EGSY__V_REL)
5622 fputs (_(" REL"), file);
5623 if (flags & EGSY__V_COMM)
5624 fputs (_(" COMM"), file);
5625 if (flags & EGSY__V_VECEP)
5626 fputs (_(" VECEP"), file);
5627 if (flags & EGSY__V_NORM)
5628 fputs (_(" NORM"), file);
5629 if (flags & EGSY__V_QUAD_VAL)
5630 fputs (_(" QVAL"), file);
5634 evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len)
5636 unsigned int off = sizeof (struct vms_egsd);
5639 fprintf (file, _(" EGSD (len=%u):\n"), rec_len);
5642 for (off = sizeof (struct vms_egsd); off < rec_len; )
5644 struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off);
5648 type = (unsigned)bfd_getl16 (e->gsdtyp);
5649 len = (unsigned)bfd_getl16 (e->gsdsiz);
5651 fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "),
5659 struct vms_egps *egps = (struct vms_egps *)e;
5660 unsigned int flags = bfd_getl16 (egps->flags);
5663 fprintf (file, _("PSC - Program section definition\n"));
5664 fprintf (file, _(" alignment : 2**%u\n"), egps->align);
5665 fprintf (file, _(" flags : 0x%04x"), flags);
5666 if (flags & EGPS__V_PIC)
5667 fputs (_(" PIC"), file);
5668 if (flags & EGPS__V_LIB)
5669 fputs (_(" LIB"), file);
5670 if (flags & EGPS__V_OVR)
5671 fputs (_(" OVR"), file);
5672 if (flags & EGPS__V_REL)
5673 fputs (_(" REL"), file);
5674 if (flags & EGPS__V_GBL)
5675 fputs (_(" GBL"), file);
5676 if (flags & EGPS__V_SHR)
5677 fputs (_(" SHR"), file);
5678 if (flags & EGPS__V_EXE)
5679 fputs (_(" EXE"), file);
5680 if (flags & EGPS__V_RD)
5681 fputs (_(" RD"), file);
5682 if (flags & EGPS__V_WRT)
5683 fputs (_(" WRT"), file);
5684 if (flags & EGPS__V_VEC)
5685 fputs (_(" VEC"), file);
5686 if (flags & EGPS__V_NOMOD)
5687 fputs (_(" NOMOD"), file);
5688 if (flags & EGPS__V_COM)
5689 fputs (_(" COM"), file);
5690 if (flags & EGPS__V_ALLOC_64BIT)
5691 fputs (_(" 64B"), file);
5693 l = bfd_getl32 (egps->alloc);
5694 fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l);
5695 fprintf (file, _(" name : %.*s\n"),
5696 egps->namlng, egps->name);
5701 struct vms_egsy *egsy = (struct vms_egsy *)e;
5702 unsigned int flags = bfd_getl16 (egsy->flags);
5704 if (flags & EGSY__V_DEF)
5706 struct vms_esdf *esdf = (struct vms_esdf *)e;
5708 fprintf (file, _("SYM - Global symbol definition\n"));
5709 fprintf (file, _(" flags: 0x%04x"), flags);
5710 exav_bfd_print_egsy_flags (flags, file);
5712 fprintf (file, _(" psect offset: 0x%08x\n"),
5713 (unsigned)bfd_getl32 (esdf->value));
5714 if (flags & EGSY__V_NORM)
5716 fprintf (file, _(" code address: 0x%08x\n"),
5717 (unsigned)bfd_getl32 (esdf->code_address));
5718 fprintf (file, _(" psect index for entry point : %u\n"),
5719 (unsigned)bfd_getl32 (esdf->ca_psindx));
5721 fprintf (file, _(" psect index : %u\n"),
5722 (unsigned)bfd_getl32 (esdf->psindx));
5723 fprintf (file, _(" name : %.*s\n"),
5724 esdf->namlng, esdf->name);
5728 struct vms_esrf *esrf = (struct vms_esrf *)e;
5730 fprintf (file, _("SYM - Global symbol reference\n"));
5731 fprintf (file, _(" name : %.*s\n"),
5732 esrf->namlng, esrf->name);
5738 struct vms_egst *egst = (struct vms_egst *)e;
5739 unsigned int flags = bfd_getl16 (egst->header.flags);
5741 fprintf (file, _("SYMG - Universal symbol definition\n"));
5742 fprintf (file, _(" flags: 0x%04x"), flags);
5743 exav_bfd_print_egsy_flags (flags, file);
5745 fprintf (file, _(" symbol vector offset: 0x%08x\n"),
5746 (unsigned)bfd_getl32 (egst->value));
5747 fprintf (file, _(" entry point: 0x%08x\n"),
5748 (unsigned)bfd_getl32 (egst->lp_1));
5749 fprintf (file, _(" proc descr : 0x%08x\n"),
5750 (unsigned)bfd_getl32 (egst->lp_2));
5751 fprintf (file, _(" psect index: %u\n"),
5752 (unsigned)bfd_getl32 (egst->psindx));
5753 fprintf (file, _(" name : %.*s\n"),
5754 egst->namlng, egst->name);
5759 struct vms_esdfv *esdfv = (struct vms_esdfv *)e;
5760 unsigned int flags = bfd_getl16 (esdfv->flags);
5762 fprintf (file, _("SYMV - Vectored symbol definition\n"));
5763 fprintf (file, _(" flags: 0x%04x"), flags);
5764 exav_bfd_print_egsy_flags (flags, file);
5766 fprintf (file, _(" vector : 0x%08x\n"),
5767 (unsigned)bfd_getl32 (esdfv->vector));
5768 fprintf (file, _(" psect offset: %u\n"),
5769 (unsigned)bfd_getl32 (esdfv->value));
5770 fprintf (file, _(" psect index : %u\n"),
5771 (unsigned)bfd_getl32 (esdfv->psindx));
5772 fprintf (file, _(" name : %.*s\n"),
5773 esdfv->namlng, esdfv->name);
5778 struct vms_esdfm *esdfm = (struct vms_esdfm *)e;
5779 unsigned int flags = bfd_getl16 (esdfm->flags);
5781 fprintf (file, _("SYMM - Global symbol definition with version\n"));
5782 fprintf (file, _(" flags: 0x%04x"), flags);
5783 exav_bfd_print_egsy_flags (flags, file);
5785 fprintf (file, _(" version mask: 0x%08x\n"),
5786 (unsigned)bfd_getl32 (esdfm->version_mask));
5787 fprintf (file, _(" psect offset: %u\n"),
5788 (unsigned)bfd_getl32 (esdfm->value));
5789 fprintf (file, _(" psect index : %u\n"),
5790 (unsigned)bfd_getl32 (esdfm->psindx));
5791 fprintf (file, _(" name : %.*s\n"),
5792 esdfm->namlng, esdfm->name);
5796 fprintf (file, _("unhandled egsd entry type %u\n"), type);
5804 evax_bfd_print_hex (FILE *file, const char *pfx,
5805 const unsigned char *buf, unsigned int len)
5811 for (i = 0; i < len; i++)
5815 fprintf (file, " %02x", buf[i]);
5828 evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf, int is_ps)
5830 fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"),
5831 (unsigned)bfd_getl32 (buf),
5832 (unsigned)bfd_getl32 (buf + 16));
5833 fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"),
5834 (unsigned)bfd_getl32 (buf + 4),
5835 (unsigned)bfd_getl32 (buf + 12),
5836 (unsigned)bfd_getl32 (buf + 8));
5837 fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"),
5838 (unsigned)bfd_getl32 (buf + 20),
5839 (unsigned)bfd_getl32 (buf + 28),
5840 (unsigned)bfd_getl32 (buf + 24));
5842 fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"),
5843 (unsigned)bfd_getl32 (buf + 32),
5844 (unsigned)bfd_getl32 (buf + 40),
5845 (unsigned)bfd_getl32 (buf + 36));
5847 fprintf (file, _(" global name: %.*s\n"), buf[32], buf + 33);
5851 evax_bfd_print_etir (FILE *file, const char *name,
5852 unsigned char *rec, unsigned int rec_len)
5854 unsigned int off = sizeof (struct vms_egsd);
5855 unsigned int sec_len;
5857 fprintf (file, _(" %s (len=%u+%u):\n"), name,
5858 (unsigned)(rec_len - sizeof (struct vms_eobjrec)),
5859 (unsigned)sizeof (struct vms_eobjrec));
5861 for (off = sizeof (struct vms_eobjrec); off < rec_len; )
5863 struct vms_etir *etir = (struct vms_etir *)(rec + off);
5868 type = bfd_getl16 (etir->rectyp);
5869 size = bfd_getl16 (etir->size);
5870 buf = rec + off + sizeof (struct vms_etir);
5872 fprintf (file, _(" (type: %3u, size: 4+%3u): "), type, size - 4);
5875 case ETIR__C_STA_GBL:
5876 fprintf (file, _("STA_GBL (stack global) %.*s\n"),
5879 case ETIR__C_STA_LW:
5880 fprintf (file, _("STA_LW (stack longword) 0x%08x\n"),
5881 (unsigned)bfd_getl32 (buf));
5883 case ETIR__C_STA_QW:
5884 fprintf (file, _("STA_QW (stack quadword) 0x%08x %08x\n"),
5885 (unsigned)bfd_getl32 (buf + 4),
5886 (unsigned)bfd_getl32 (buf + 0));
5888 case ETIR__C_STA_PQ:
5889 fprintf (file, _("STA_PQ (stack psect base + offset)\n"));
5890 fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"),
5891 (unsigned)bfd_getl32 (buf + 0),
5892 (unsigned)bfd_getl32 (buf + 8),
5893 (unsigned)bfd_getl32 (buf + 4));
5895 case ETIR__C_STA_LI:
5896 fprintf (file, _("STA_LI (stack literal)\n"));
5898 case ETIR__C_STA_MOD:
5899 fprintf (file, _("STA_MOD (stack module)\n"));
5901 case ETIR__C_STA_CKARG:
5902 fprintf (file, _("STA_CKARG (compare procedure argument)\n"));
5906 fprintf (file, _("STO_B (store byte)\n"));
5909 fprintf (file, _("STO_W (store word)\n"));
5911 case ETIR__C_STO_LW:
5912 fprintf (file, _("STO_LW (store longword)\n"));
5914 case ETIR__C_STO_QW:
5915 fprintf (file, _("STO_QW (store quadword)\n"));
5917 case ETIR__C_STO_IMMR:
5919 unsigned int len = bfd_getl32 (buf);
5921 _("STO_IMMR (store immediate repeat) %u bytes\n"),
5923 evax_bfd_print_hex (file, " ", buf + 4, len);
5927 case ETIR__C_STO_GBL:
5928 fprintf (file, _("STO_GBL (store global) %.*s\n"),
5931 case ETIR__C_STO_CA:
5932 fprintf (file, _("STO_CA (store code address) %.*s\n"),
5935 case ETIR__C_STO_RB:
5936 fprintf (file, _("STO_RB (store relative branch)\n"));
5938 case ETIR__C_STO_AB:
5939 fprintf (file, _("STO_AB (store absolute branch)\n"));
5941 case ETIR__C_STO_OFF:
5942 fprintf (file, _("STO_OFF (store offset to psect)\n"));
5944 case ETIR__C_STO_IMM:
5946 unsigned int len = bfd_getl32 (buf);
5948 _("STO_IMM (store immediate) %u bytes\n"),
5950 evax_bfd_print_hex (file, " ", buf + 4, len);
5954 case ETIR__C_STO_LP_PSB:
5955 fprintf (file, _("STO_OFF (store LP with procedure signature)\n"));
5957 case ETIR__C_STO_HINT_GBL:
5958 fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n"));
5960 case ETIR__C_STO_HINT_PS:
5961 fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n"));
5964 case ETIR__C_OPR_NOP:
5965 fprintf (file, _("OPR_NOP (no-operation)\n"));
5967 case ETIR__C_OPR_ADD:
5968 fprintf (file, _("OPR_ADD (add)\n"));
5970 case ETIR__C_OPR_SUB:
5971 fprintf (file, _("OPR_SUB (substract)\n"));
5973 case ETIR__C_OPR_MUL:
5974 fprintf (file, _("OPR_MUL (multiply)\n"));
5976 case ETIR__C_OPR_DIV:
5977 fprintf (file, _("OPR_DIV (divide)\n"));
5979 case ETIR__C_OPR_AND:
5980 fprintf (file, _("OPR_AND (logical and)\n"));
5982 case ETIR__C_OPR_IOR:
5983 fprintf (file, _("OPR_IOR (logical inclusive or)\n"));
5985 case ETIR__C_OPR_EOR:
5986 fprintf (file, _("OPR_EOR (logical exclusive or)\n"));
5988 case ETIR__C_OPR_NEG:
5989 fprintf (file, _("OPR_NEG (negate)\n"));
5991 case ETIR__C_OPR_COM:
5992 fprintf (file, _("OPR_COM (complement)\n"));
5994 case ETIR__C_OPR_INSV:
5995 fprintf (file, _("OPR_INSV (insert field)\n"));
5997 case ETIR__C_OPR_ASH:
5998 fprintf (file, _("OPR_ASH (arithmetic shift)\n"));
6000 case ETIR__C_OPR_USH:
6001 fprintf (file, _("OPR_USH (unsigned shift)\n"));
6003 case ETIR__C_OPR_ROT:
6004 fprintf (file, _("OPR_ROT (rotate)\n"));
6006 case ETIR__C_OPR_SEL:
6007 fprintf (file, _("OPR_SEL (select)\n"));
6009 case ETIR__C_OPR_REDEF:
6010 fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n"));
6012 case ETIR__C_OPR_DFLIT:
6013 fprintf (file, _("OPR_REDEF (define a literal)\n"));
6016 case ETIR__C_STC_LP:
6017 fprintf (file, _("STC_LP (store cond linkage pair)\n"));
6019 case ETIR__C_STC_LP_PSB:
6021 _("STC_LP_PSB (store cond linkage pair + signature)\n"));
6022 fprintf (file, _(" linkage index: %u, procedure: %.*s\n"),
6023 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6024 buf += 4 + 1 + buf[4];
6025 fprintf (file, _(" signature: %.*s\n"), buf[0], buf + 1);
6027 case ETIR__C_STC_GBL:
6028 fprintf (file, _("STC_GBL (store cond global)\n"));
6029 fprintf (file, _(" linkage index: %u, global: %.*s\n"),
6030 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6032 case ETIR__C_STC_GCA:
6033 fprintf (file, _("STC_GCA (store cond code address)\n"));
6034 fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"),
6035 (unsigned)bfd_getl32 (buf), buf[4], buf + 5);
6037 case ETIR__C_STC_PS:
6038 fprintf (file, _("STC_PS (store cond psect + offset)\n"));
6040 _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"),
6041 (unsigned)bfd_getl32 (buf),
6042 (unsigned)bfd_getl32 (buf + 4),
6043 (unsigned)bfd_getl32 (buf + 12),
6044 (unsigned)bfd_getl32 (buf + 8));
6046 case ETIR__C_STC_NOP_GBL:
6047 fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n"));
6048 evax_bfd_print_etir_stc_ir (file, buf, 0);
6050 case ETIR__C_STC_NOP_PS:
6051 fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n"));
6052 evax_bfd_print_etir_stc_ir (file, buf, 1);
6054 case ETIR__C_STC_BSR_GBL:
6055 fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n"));
6056 evax_bfd_print_etir_stc_ir (file, buf, 0);
6058 case ETIR__C_STC_BSR_PS:
6059 fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n"));
6060 evax_bfd_print_etir_stc_ir (file, buf, 1);
6062 case ETIR__C_STC_LDA_GBL:
6063 fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n"));
6064 evax_bfd_print_etir_stc_ir (file, buf, 0);
6066 case ETIR__C_STC_LDA_PS:
6067 fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n"));
6068 evax_bfd_print_etir_stc_ir (file, buf, 1);
6070 case ETIR__C_STC_BOH_GBL:
6071 fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n"));
6072 evax_bfd_print_etir_stc_ir (file, buf, 0);
6074 case ETIR__C_STC_BOH_PS:
6075 fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n"));
6076 evax_bfd_print_etir_stc_ir (file, buf, 1);
6078 case ETIR__C_STC_NBH_GBL:
6080 _("STC_NBH_GBL (store cond or hint at global addr)\n"));
6082 case ETIR__C_STC_NBH_PS:
6084 _("STC_NBH_PS (store cond or hint at psect + offset)\n"));
6087 case ETIR__C_CTL_SETRB:
6088 fprintf (file, _("CTL_SETRB (set relocation base)\n"));
6091 case ETIR__C_CTL_AUGRB:
6093 unsigned int val = bfd_getl32 (buf);
6094 fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"), val);
6097 case ETIR__C_CTL_DFLOC:
6098 fprintf (file, _("CTL_DFLOC (define location)\n"));
6100 case ETIR__C_CTL_STLOC:
6101 fprintf (file, _("CTL_STLOC (set location)\n"));
6103 case ETIR__C_CTL_STKDL:
6104 fprintf (file, _("CTL_STKDL (stack defined location)\n"));
6107 fprintf (file, _("*unhandled*\n"));
6115 evax_bfd_print_eobj (struct bfd *abfd, FILE *file)
6117 bfd_boolean is_first = TRUE;
6118 bfd_boolean has_records = FALSE;
6122 unsigned int rec_len;
6123 unsigned int pad_len;
6125 unsigned int hdr_size;
6130 unsigned char buf[6];
6135 if (bfd_bread (buf, sizeof (buf), abfd) != sizeof (buf))
6137 fprintf (file, _("cannot read GST record length\n"));
6140 rec_len = bfd_getl16 (buf + 0);
6141 if (rec_len == bfd_getl16 (buf + 4)
6142 && bfd_getl16 (buf + 2) == EOBJ__C_EMH)
6144 /* The format is raw: record-size, type, record-size. */
6146 pad_len = (rec_len + 1) & ~1U;
6149 else if (rec_len == EOBJ__C_EMH)
6151 has_records = FALSE;
6152 pad_len = bfd_getl16 (buf + 2);
6158 fprintf (file, _("cannot find EMH in first GST record\n"));
6161 rec = bfd_malloc (pad_len);
6162 memcpy (rec, buf + sizeof (buf) - hdr_size, hdr_size);
6166 unsigned int rec_len2 = 0;
6167 unsigned char hdr[4];
6171 unsigned char buf_len[2];
6173 if (bfd_bread (buf_len, sizeof (buf_len), abfd)
6174 != sizeof (buf_len))
6176 fprintf (file, _("cannot read GST record length\n"));
6179 rec_len2 = (unsigned)bfd_getl16 (buf_len);
6182 if (bfd_bread (hdr, sizeof (hdr), abfd) != sizeof (hdr))
6184 fprintf (file, _("cannot read GST record header\n"));
6187 rec_len = (unsigned)bfd_getl16 (hdr + 2);
6189 pad_len = (rec_len + 1) & ~1U;
6192 rec = bfd_malloc (pad_len);
6193 memcpy (rec, hdr, sizeof (hdr));
6194 hdr_size = sizeof (hdr);
6195 if (has_records && rec_len2 != rec_len)
6197 fprintf (file, _(" corrupted GST\n"));
6202 if (bfd_bread (rec + hdr_size, pad_len - hdr_size, abfd)
6203 != pad_len - hdr_size)
6205 fprintf (file, _("cannot read GST record\n"));
6209 type = (unsigned)bfd_getl16 (rec);
6214 evax_bfd_print_emh (file, rec, rec_len);
6217 evax_bfd_print_egsd (file, rec, rec_len);
6220 evax_bfd_print_eeom (file, rec, rec_len);
6225 evax_bfd_print_etir (file, "ETIR", rec, rec_len);
6228 evax_bfd_print_etir (file, "EDBG", rec, rec_len);
6231 evax_bfd_print_etir (file, "ETBT", rec, rec_len);
6234 fprintf (file, _(" unhandled EOBJ record type %u\n"), type);
6242 evax_bfd_print_relocation_records (FILE *file, const unsigned char *rel,
6243 unsigned int stride)
6251 count = bfd_getl32 (rel + 0);
6255 base = bfd_getl32 (rel + 4);
6257 fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"),
6261 for (j = 0; count > 0; j += 4, count -= 32)
6267 val = bfd_getl32 (rel);
6270 fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count);
6272 for (k = 0; k < 32; k++)
6277 fprintf (file, _(" %08x"), base + (j * 8 + k) * stride);
6292 evax_bfd_print_address_fixups (FILE *file, const unsigned char *rel)
6299 count = bfd_getl32 (rel + 0);
6302 fprintf (file, _(" image %u (%u entries)\n"),
6303 (unsigned)bfd_getl32 (rel + 4), count);
6305 for (j = 0; j < count; j++)
6307 fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"),
6308 (unsigned)bfd_getl32 (rel + 0),
6309 (unsigned)bfd_getl32 (rel + 4));
6316 evax_bfd_print_reference_fixups (FILE *file, const unsigned char *rel)
6325 count = bfd_getl32 (rel + 0);
6328 fprintf (file, _(" image %u (%u entries), offsets:\n"),
6329 (unsigned)bfd_getl32 (rel + 4), count);
6331 for (j = 0; j < count; j++)
6335 fprintf (file, _(" 0x%08x"), (unsigned)bfd_getl32 (rel));
6350 evax_bfd_print_indent (int indent, FILE *file)
6352 for (; indent; indent--)
6357 evax_bfd_get_dsc_name (unsigned int v)
6361 case DSC__K_DTYPE_Z:
6362 return "Z (Unspecified)";
6363 case DSC__K_DTYPE_V:
6365 case DSC__K_DTYPE_BU:
6366 return "BU (Byte logical)";
6367 case DSC__K_DTYPE_WU:
6368 return "WU (Word logical)";
6369 case DSC__K_DTYPE_LU:
6370 return "LU (Longword logical)";
6371 case DSC__K_DTYPE_QU:
6372 return "QU (Quadword logical)";
6373 case DSC__K_DTYPE_B:
6374 return "B (Byte integer)";
6375 case DSC__K_DTYPE_W:
6376 return "W (Word integer)";
6377 case DSC__K_DTYPE_L:
6378 return "L (Longword integer)";
6379 case DSC__K_DTYPE_Q:
6380 return "Q (Quadword integer)";
6381 case DSC__K_DTYPE_F:
6382 return "F (Single-precision floating)";
6383 case DSC__K_DTYPE_D:
6384 return "D (Double-precision floating)";
6385 case DSC__K_DTYPE_FC:
6386 return "FC (Complex)";
6387 case DSC__K_DTYPE_DC:
6388 return "DC (Double-precision Complex)";
6389 case DSC__K_DTYPE_T:
6390 return "T (ASCII text string)";
6391 case DSC__K_DTYPE_NU:
6392 return "NU (Numeric string, unsigned)";
6393 case DSC__K_DTYPE_NL:
6394 return "NL (Numeric string, left separate sign)";
6395 case DSC__K_DTYPE_NLO:
6396 return "NLO (Numeric string, left overpunched sign)";
6397 case DSC__K_DTYPE_NR:
6398 return "NR (Numeric string, right separate sign)";
6399 case DSC__K_DTYPE_NRO:
6400 return "NRO (Numeric string, right overpunched sig)";
6401 case DSC__K_DTYPE_NZ:
6402 return "NZ (Numeric string, zoned sign)";
6403 case DSC__K_DTYPE_P:
6404 return "P (Packed decimal string)";
6405 case DSC__K_DTYPE_ZI:
6406 return "ZI (Sequence of instructions)";
6407 case DSC__K_DTYPE_ZEM:
6408 return "ZEM (Procedure entry mask)";
6409 case DSC__K_DTYPE_DSC:
6410 return "DSC (Descriptor, used for arrays of dyn strings)";
6411 case DSC__K_DTYPE_OU:
6412 return "OU (Octaword logical)";
6413 case DSC__K_DTYPE_O:
6414 return "O (Octaword integer)";
6415 case DSC__K_DTYPE_G:
6416 return "G (Double precision G floating, 64 bit)";
6417 case DSC__K_DTYPE_H:
6418 return "H (Quadruple precision floating, 128 bit)";
6419 case DSC__K_DTYPE_GC:
6420 return "GC (Double precision complex, G floating)";
6421 case DSC__K_DTYPE_HC:
6422 return "HC (Quadruple precision complex, H floating)";
6423 case DSC__K_DTYPE_CIT:
6424 return "CIT (COBOL intermediate temporary)";
6425 case DSC__K_DTYPE_BPV:
6426 return "BPV (Bound Procedure Value)";
6427 case DSC__K_DTYPE_BLV:
6428 return "BLV (Bound Label Value)";
6429 case DSC__K_DTYPE_VU:
6430 return "VU (Bit Unaligned)";
6431 case DSC__K_DTYPE_ADT:
6432 return "ADT (Absolute Date-Time)";
6433 case DSC__K_DTYPE_VT:
6434 return "VT (Varying Text)";
6435 case DSC__K_DTYPE_T2:
6436 return "T2 (16-bit char)";
6437 case DSC__K_DTYPE_VT2:
6438 return "VT2 (16-bit varying char)";
6440 return "?? (unknown)";
6445 evax_bfd_print_desc (const unsigned char *buf, int indent, FILE *file)
6447 unsigned char bclass = buf[3];
6448 unsigned char dtype = buf[2];
6449 unsigned int len = (unsigned)bfd_getl16 (buf);
6450 unsigned int pointer = (unsigned)bfd_getl32 (buf + 4);
6452 evax_bfd_print_indent (indent, file);
6454 if (len == 1 && pointer == 0xffffffffUL)
6457 fprintf (file, _("64 bits *unhandled*\n"));
6461 fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"),
6462 bclass, dtype, len, pointer);
6465 case DSC__K_CLASS_NCA:
6467 const struct vms_dsc_nca *dsc = (const void *)buf;
6469 const unsigned char *b;
6471 evax_bfd_print_indent (indent, file);
6472 fprintf (file, _("non-contiguous array of %s\n"),
6473 evax_bfd_get_dsc_name (dsc->dtype));
6474 evax_bfd_print_indent (indent + 1, file);
6476 _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"),
6477 dsc->dimct, dsc->aflags, dsc->digits, dsc->scale);
6478 evax_bfd_print_indent (indent + 1, file);
6480 _("arsize: %u, a0: 0x%08x\n"),
6481 (unsigned)bfd_getl32 (dsc->arsize),
6482 (unsigned)bfd_getl32 (dsc->a0));
6483 evax_bfd_print_indent (indent + 1, file);
6484 fprintf (file, _("Strides:\n"));
6485 b = buf + sizeof (*dsc);
6486 for (i = 0; i < dsc->dimct; i++)
6488 evax_bfd_print_indent (indent + 2, file);
6489 fprintf (file, _("[%u]: %u\n"), i + 1,
6490 (unsigned)bfd_getl32 (b));
6493 evax_bfd_print_indent (indent + 1, file);
6494 fprintf (file, _("Bounds:\n"));
6495 b = buf + sizeof (*dsc);
6496 for (i = 0; i < dsc->dimct; i++)
6498 evax_bfd_print_indent (indent + 2, file);
6499 fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1,
6500 (unsigned)bfd_getl32 (b + 0),
6501 (unsigned)bfd_getl32 (b + 4));
6506 case DSC__K_CLASS_UBS:
6508 const struct vms_dsc_ubs *ubs = (const void *)buf;
6510 evax_bfd_print_indent (indent, file);
6511 fprintf (file, _("unaligned bit-string of %s\n"),
6512 evax_bfd_get_dsc_name (ubs->dtype));
6513 evax_bfd_print_indent (indent + 1, file);
6515 _("base: %u, pos: %u\n"),
6516 (unsigned)bfd_getl32 (ubs->base),
6517 (unsigned)bfd_getl32 (ubs->pos));
6521 fprintf (file, _("*unhandled*\n"));
6528 evax_bfd_print_valspec (const unsigned char *buf, int indent, FILE *file)
6530 unsigned int vflags = buf[0];
6531 unsigned int value = (unsigned)bfd_getl32 (buf + 1);
6532 unsigned int len = 5;
6534 evax_bfd_print_indent (indent, file);
6535 fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value);
6540 case DST__K_VFLAGS_NOVAL:
6541 fprintf (file, _("(no value)\n"));
6543 case DST__K_VFLAGS_NOTACTIVE:
6544 fprintf (file, _("(not active)\n"));
6546 case DST__K_VFLAGS_UNALLOC:
6547 fprintf (file, _("(not allocated)\n"));
6549 case DST__K_VFLAGS_DSC:
6550 fprintf (file, _("(descriptor)\n"));
6551 evax_bfd_print_desc (buf + value, indent + 1, file);
6553 case DST__K_VFLAGS_TVS:
6554 fprintf (file, _("(trailing value)\n"));
6556 case DST__K_VS_FOLLOWS:
6557 fprintf (file, _("(value spec follows)\n"));
6559 case DST__K_VFLAGS_BITOFFS:
6560 fprintf (file, _("(at bit offset %u)\n"), value);
6563 fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "),
6564 (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT,
6565 vflags & DST__K_DISP ? 1 : 0,
6566 vflags & DST__K_INDIR ? 1 : 0);
6567 switch (vflags & DST__K_VALKIND_MASK)
6569 case DST__K_VALKIND_LITERAL:
6570 fputs (_("literal"), file);
6572 case DST__K_VALKIND_ADDR:
6573 fputs (_("address"), file);
6575 case DST__K_VALKIND_DESC:
6576 fputs (_("desc"), file);
6578 case DST__K_VALKIND_REG:
6579 fputs (_("reg"), file);
6582 fputs (")\n", file);
6589 evax_bfd_print_typspec (const unsigned char *buf, int indent, FILE *file)
6591 unsigned char kind = buf[2];
6592 unsigned int len = (unsigned)bfd_getl16 (buf);
6594 evax_bfd_print_indent (indent, file);
6595 fprintf (file, ("len: %2u, kind: %2u "), len, kind);
6599 case DST__K_TS_ATOM:
6600 fprintf (file, ("atomic, type=0x%02x %s\n"),
6601 buf[0], evax_bfd_get_dsc_name (buf[0]));
6604 fprintf (file, ("indirect, defined at 0x%08x\n"),
6605 (unsigned)bfd_getl32 (buf));
6607 case DST__K_TS_TPTR:
6608 fprintf (file, ("typed pointer\n"));
6609 evax_bfd_print_typspec (buf, indent + 1, file);
6612 fprintf (file, ("pointer\n"));
6614 case DST__K_TS_ARRAY:
6616 const unsigned char *vs;
6617 unsigned int vec_len;
6620 fprintf (file, ("array, dim: %u, bitmap: "), buf[0]);
6621 vec_len = (buf[0] + 1 + 7) / 8;
6622 for (i = 0; i < vec_len; i++)
6623 fprintf (file, " %02x", buf[i + 1]);
6625 vs = buf + 1 + vec_len;
6626 evax_bfd_print_indent (indent, file);
6627 fprintf (file, ("array descriptor:\n"));
6628 vs += evax_bfd_print_valspec (vs, indent + 1, file);
6629 for (i = 0; i < buf[0] + 1U; i++)
6630 if (buf[1 + i / 8] & (1 << (i % 8)))
6632 evax_bfd_print_indent (indent, file);
6634 fprintf (file, ("type spec for element:\n"));
6636 fprintf (file, ("type spec for subscript %u:\n"), i);
6637 evax_bfd_print_typspec (vs, indent + 1, file);
6638 vs += bfd_getl16 (vs);
6643 fprintf (file, ("*unhandled*\n"));
6648 evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file)
6650 unsigned int off = 0;
6651 unsigned int pc = 0;
6652 unsigned int line = 0;
6654 fprintf (file, _("Debug symbol table:\n"));
6656 while (dst_size > 0)
6658 struct vms_dst_header dsth;
6663 if (bfd_bread (&dsth, sizeof (dsth), abfd) != sizeof (dsth))
6665 fprintf (file, _("cannot read DST header\n"));
6668 len = bfd_getl16 (dsth.length);
6669 type = bfd_getl16 (dsth.type);
6670 fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "),
6680 len -= sizeof (dsth);
6681 buf = bfd_malloc (len);
6682 if (bfd_bread (buf, len, abfd) != len)
6684 fprintf (file, _("cannot read DST symbol\n"));
6689 case DSC__K_DTYPE_V:
6690 case DSC__K_DTYPE_BU:
6691 case DSC__K_DTYPE_WU:
6692 case DSC__K_DTYPE_LU:
6693 case DSC__K_DTYPE_QU:
6694 case DSC__K_DTYPE_B:
6695 case DSC__K_DTYPE_W:
6696 case DSC__K_DTYPE_L:
6697 case DSC__K_DTYPE_Q:
6698 case DSC__K_DTYPE_F:
6699 case DSC__K_DTYPE_D:
6700 case DSC__K_DTYPE_FC:
6701 case DSC__K_DTYPE_DC:
6702 case DSC__K_DTYPE_T:
6703 case DSC__K_DTYPE_NU:
6704 case DSC__K_DTYPE_NL:
6705 case DSC__K_DTYPE_NLO:
6706 case DSC__K_DTYPE_NR:
6707 case DSC__K_DTYPE_NRO:
6708 case DSC__K_DTYPE_NZ:
6709 case DSC__K_DTYPE_P:
6710 case DSC__K_DTYPE_ZI:
6711 case DSC__K_DTYPE_ZEM:
6712 case DSC__K_DTYPE_DSC:
6713 case DSC__K_DTYPE_OU:
6714 case DSC__K_DTYPE_O:
6715 case DSC__K_DTYPE_G:
6716 case DSC__K_DTYPE_H:
6717 case DSC__K_DTYPE_GC:
6718 case DSC__K_DTYPE_HC:
6719 case DSC__K_DTYPE_CIT:
6720 case DSC__K_DTYPE_BPV:
6721 case DSC__K_DTYPE_BLV:
6722 case DSC__K_DTYPE_VU:
6723 case DSC__K_DTYPE_ADT:
6724 case DSC__K_DTYPE_VT:
6725 case DSC__K_DTYPE_T2:
6726 case DSC__K_DTYPE_VT2:
6727 fprintf (file, _("standard data: %s\n"),
6728 evax_bfd_get_dsc_name (type));
6729 evax_bfd_print_valspec (buf, 4, file);
6730 fprintf (file, _(" name: %.*s\n"), buf[5], buf + 6);
6734 struct vms_dst_modbeg *dst = (void *)buf;
6735 const char *name = (const char *)buf + sizeof (*dst);
6737 fprintf (file, _("modbeg\n"));
6738 fprintf (file, _(" flags: %d, language: %u, "
6739 "major: %u, minor: %u\n"),
6741 (unsigned)bfd_getl32 (dst->language),
6742 (unsigned)bfd_getl16 (dst->major),
6743 (unsigned)bfd_getl16 (dst->minor));
6744 fprintf (file, _(" module name: %.*s\n"),
6746 name += name[0] + 1;
6747 fprintf (file, _(" compiler : %.*s\n"),
6752 fprintf (file, _("modend\n"));
6756 struct vms_dst_rtnbeg *dst = (void *)buf;
6757 const char *name = (const char *)buf + sizeof (*dst);
6759 fputs (_("rtnbeg\n"), file);
6760 fprintf (file, _(" flags: %u, address: 0x%08x, "
6761 "pd-address: 0x%08x\n"),
6763 (unsigned)bfd_getl32 (dst->address),
6764 (unsigned)bfd_getl32 (dst->pd_address));
6765 fprintf (file, _(" routine name: %.*s\n"),
6771 struct vms_dst_rtnend *dst = (void *)buf;
6773 fprintf (file, _("rtnend: size 0x%08x\n"),
6774 (unsigned)bfd_getl32 (dst->size));
6779 struct vms_dst_prolog *dst = (void *)buf;
6781 fprintf (file, _("prolog: bkpt address 0x%08x\n"),
6782 (unsigned)bfd_getl32 (dst->bkpt_addr));
6787 struct vms_dst_epilog *dst = (void *)buf;
6789 fprintf (file, _("epilog: flags: %u, count: %u\n"),
6790 dst->flags, (unsigned)bfd_getl32 (dst->count));
6795 struct vms_dst_blkbeg *dst = (void *)buf;
6796 const char *name = (const char *)buf + sizeof (*dst);
6798 fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"),
6799 (unsigned)bfd_getl32 (dst->address),
6805 struct vms_dst_blkend *dst = (void *)buf;
6807 fprintf (file, _("blkend: size: 0x%08x\n"),
6808 (unsigned)bfd_getl32 (dst->size));
6811 case DST__K_TYPSPEC:
6813 fprintf (file, _("typspec (len: %u)\n"), len);
6814 fprintf (file, _(" name: %.*s\n"), buf[0], buf + 1);
6815 evax_bfd_print_typspec (buf + 1 + buf[0], 5, file);
6820 fprintf (file, _("septyp, name: %.*s\n"), buf[5], buf + 6);
6821 evax_bfd_print_valspec (buf, 4, file);
6826 struct vms_dst_recbeg *recbeg = (void *)buf;
6827 const char *name = (const char *)buf + sizeof (*recbeg);
6829 fprintf (file, _("recbeg: name: %.*s\n"), name[0], name + 1);
6830 evax_bfd_print_valspec (buf, 4, file);
6831 fprintf (file, (" len: %u bits\n"),
6832 (unsigned)bfd_getl32 (name + 1 + name[0]));
6836 fprintf (file, _("recend\n"));
6838 case DST__K_ENUMBEG:
6839 fprintf (file, _("enumbeg, len: %u, name: %.*s\n"),
6840 buf[0], buf[1], buf + 2);
6842 case DST__K_ENUMELT:
6843 fprintf (file, _("enumelt, name: %.*s\n"), buf[5], buf + 6);
6844 evax_bfd_print_valspec (buf, 4, file);
6846 case DST__K_ENUMEND:
6847 fprintf (file, _("enumend\n"));
6851 struct vms_dst_label *lab = (void *)buf;
6852 fprintf (file, ("label, name: %.*s\n"),
6853 lab->name[0], lab->name + 1);
6854 fprintf (file, (" address: 0x%08x\n"),
6855 (unsigned)bfd_getl32 (lab->value));
6858 case DST__K_DIS_RANGE:
6860 unsigned int cnt = bfd_getl32 (buf);
6861 unsigned char *rng = buf + 4;
6864 fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt);
6865 for (i = 0; i < cnt; i++, rng += 8)
6866 fprintf (file, _(" address: 0x%08x, size: %u\n"),
6867 (unsigned)bfd_getl32 (rng),
6868 (unsigned)bfd_getl32 (rng + 4));
6872 case DST__K_LINE_NUM:
6874 unsigned char *buf_orig = buf;
6876 fprintf (file, _("line num (len: %u)\n"), len);
6881 unsigned char cmdlen;
6891 case DST__K_DELTA_PC_W:
6892 val = bfd_getl16 (buf + 1);
6893 fprintf (file, _("delta_pc_w %u\n"), val);
6898 case DST__K_INCR_LINUM:
6900 fprintf (file, _("incr_linum: +%u\n"), val);
6904 case DST__K_INCR_LINUM_W:
6905 val = bfd_getl16 (buf + 1);
6906 fprintf (file, _("incr_linum: +%u\n"), val);
6910 case DST__K_SET_LINUM:
6911 line = (unsigned)bfd_getl16 (buf + 1);
6912 fprintf (file, _("set_line_num %u\n"), line);
6915 case DST__K_SET_LINUM_B:
6917 fprintf (file, _("set_line_num_b %u\n"), line);
6920 case DST__K_SET_LINUM_L:
6921 line = (unsigned)bfd_getl32 (buf + 1);
6922 fprintf (file, _("set_line_num_l %u\n"), line);
6925 case DST__K_SET_ABS_PC:
6926 pc = (unsigned)bfd_getl32 (buf + 1);
6927 fprintf (file, _("set_abs_pc: 0x%08x\n"), pc);
6930 case DST__K_DELTA_PC_L:
6931 fprintf (file, _("delta_pc_l: +0x%08x\n"),
6932 (unsigned)bfd_getl32 (buf + 1));
6936 fprintf (file, _("term: 0x%02x"), buf[1]);
6938 fprintf (file, _(" pc: 0x%08x\n"), pc);
6942 val = bfd_getl16 (buf + 1);
6943 fprintf (file, _("term_w: 0x%04x"), val);
6945 fprintf (file, _(" pc: 0x%08x\n"), pc);
6951 fprintf (file, _("delta pc +%-4d"), -cmd);
6952 line++; /* FIXME: curr increment. */
6954 fprintf (file, _(" pc: 0x%08x line: %5u\n"),
6959 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
6972 unsigned char *buf_orig = buf;
6974 fprintf (file, _("source (len: %u)\n"), len);
6978 signed char cmd = buf[0];
6979 unsigned char cmdlen = 0;
6983 case DST__K_SRC_DECLFILE:
6985 struct vms_dst_src_decl_src *src = (void *)(buf + 1);
6988 fprintf (file, _(" declfile: len: %u, flags: %u, "
6990 src->length, src->flags,
6991 (unsigned)bfd_getl16 (src->fileid));
6992 fprintf (file, _(" rms: cdt: 0x%08x %08x, "
6993 "ebk: 0x%08x, ffb: 0x%04x, "
6995 (unsigned)bfd_getl32 (src->rms_cdt + 4),
6996 (unsigned)bfd_getl32 (src->rms_cdt + 0),
6997 (unsigned)bfd_getl32 (src->rms_ebk),
6998 (unsigned)bfd_getl16 (src->rms_ffb),
7000 name = (const char *)buf + 1 + sizeof (*src);
7001 fprintf (file, _(" filename : %.*s\n"),
7003 name += name[0] + 1;
7004 fprintf (file, _(" module name: %.*s\n"),
7006 cmdlen = 2 + src->length;
7009 case DST__K_SRC_SETFILE:
7010 fprintf (file, _(" setfile %u\n"),
7011 (unsigned)bfd_getl16 (buf + 1));
7014 case DST__K_SRC_SETREC_W:
7015 fprintf (file, _(" setrec %u\n"),
7016 (unsigned)bfd_getl16 (buf + 1));
7019 case DST__K_SRC_SETREC_L:
7020 fprintf (file, _(" setrec %u\n"),
7021 (unsigned)bfd_getl32 (buf + 1));
7024 case DST__K_SRC_SETLNUM_W:
7025 fprintf (file, _(" setlnum %u\n"),
7026 (unsigned)bfd_getl16 (buf + 1));
7029 case DST__K_SRC_SETLNUM_L:
7030 fprintf (file, _(" setlnum %u\n"),
7031 (unsigned)bfd_getl32 (buf + 1));
7034 case DST__K_SRC_DEFLINES_W:
7035 fprintf (file, _(" deflines %u\n"),
7036 (unsigned)bfd_getl16 (buf + 1));
7039 case DST__K_SRC_DEFLINES_B:
7040 fprintf (file, _(" deflines %u\n"), buf[1]);
7043 case DST__K_SRC_FORMFEED:
7044 fprintf (file, _(" formfeed\n"));
7048 fprintf (file, _(" *unhandled* cmd %u\n"), cmd);
7060 fprintf (file, _("*unhandled* dst type %u\n"), type);
7068 evax_bfd_print_image (bfd *abfd, FILE *file)
7070 struct vms_eihd eihd;
7073 unsigned int eiha_off;
7074 unsigned int eihi_off;
7075 unsigned int eihs_off;
7076 unsigned int eisd_off;
7077 unsigned int eihef_off = 0;
7078 unsigned int eihnp_off = 0;
7079 unsigned int dmt_vbn = 0;
7080 unsigned int dmt_size = 0;
7081 unsigned int dst_vbn = 0;
7082 unsigned int dst_size = 0;
7083 unsigned int gst_vbn = 0;
7084 unsigned int gst_size = 0;
7085 unsigned int eiaf_vbn = 0;
7086 unsigned int eiaf_size = 0;
7087 unsigned int eihvn_off;
7089 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET)
7090 || bfd_bread (&eihd, sizeof (eihd), abfd) != sizeof (eihd))
7092 fprintf (file, _("cannot read EIHD\n"));
7095 fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"),
7096 (unsigned)bfd_getl32 (eihd.size),
7097 (unsigned)bfd_getl32 (eihd.hdrblkcnt));
7098 fprintf (file, _(" majorid: %u, minorid: %u\n"),
7099 (unsigned)bfd_getl32 (eihd.majorid),
7100 (unsigned)bfd_getl32 (eihd.minorid));
7102 val = (unsigned)bfd_getl32 (eihd.imgtype);
7106 name = _("executable");
7109 name = _("linkable image");
7112 name = _("unknown");
7115 fprintf (file, _(" image type: %u (%s)"), val, name);
7117 val = (unsigned)bfd_getl32 (eihd.subtype);
7120 case EIHD__C_NATIVE:
7127 name = _("unknown");
7130 fprintf (file, _(", subtype: %u (%s)\n"), val, name);
7132 eisd_off = bfd_getl32 (eihd.isdoff);
7133 eiha_off = bfd_getl32 (eihd.activoff);
7134 eihi_off = bfd_getl32 (eihd.imgidoff);
7135 eihs_off = bfd_getl32 (eihd.symdbgoff);
7136 fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, "
7137 "imgid: %u, patch: %u\n"),
7138 eisd_off, eiha_off, eihs_off, eihi_off,
7139 (unsigned)bfd_getl32 (eihd.patchoff));
7140 fprintf (file, _(" fixup info rva: "));
7141 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva));
7142 fprintf (file, _(", symbol vector rva: "));
7143 bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva));
7144 eihvn_off = bfd_getl32 (eihd.version_array_off);
7145 fprintf (file, _("\n"
7146 " version array off: %u\n"),
7149 _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"),
7150 (unsigned)bfd_getl32 (eihd.imgiocnt),
7151 (unsigned)bfd_getl32 (eihd.iochancnt),
7152 (unsigned)bfd_getl32 (eihd.privreqs + 4),
7153 (unsigned)bfd_getl32 (eihd.privreqs + 0));
7154 val = (unsigned)bfd_getl32 (eihd.lnkflags);
7155 fprintf (file, _(" linker flags: %08x:"), val);
7156 if (val & EIHD__M_LNKDEBUG)
7157 fprintf (file, " LNKDEBUG");
7158 if (val & EIHD__M_LNKNOTFR)
7159 fprintf (file, " LNKNOTFR");
7160 if (val & EIHD__M_NOP0BUFS)
7161 fprintf (file, " NOP0BUFS");
7162 if (val & EIHD__M_PICIMG)
7163 fprintf (file, " PICIMG");
7164 if (val & EIHD__M_P0IMAGE)
7165 fprintf (file, " P0IMAGE");
7166 if (val & EIHD__M_DBGDMT)
7167 fprintf (file, " DBGDMT");
7168 if (val & EIHD__M_INISHR)
7169 fprintf (file, " INISHR");
7170 if (val & EIHD__M_XLATED)
7171 fprintf (file, " XLATED");
7172 if (val & EIHD__M_BIND_CODE_SEC)
7173 fprintf (file, " BIND_CODE_SEC");
7174 if (val & EIHD__M_BIND_DATA_SEC)
7175 fprintf (file, " BIND_DATA_SEC");
7176 if (val & EIHD__M_MKTHREADS)
7177 fprintf (file, " MKTHREADS");
7178 if (val & EIHD__M_UPCALLS)
7179 fprintf (file, " UPCALLS");
7180 if (val & EIHD__M_OMV_READY)
7181 fprintf (file, " OMV_READY");
7182 if (val & EIHD__M_EXT_BIND_SECT)
7183 fprintf (file, " EXT_BIND_SECT");
7184 fprintf (file, "\n");
7185 fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, "
7186 "match ctrl: %u, symvect_size: %u\n"),
7187 (unsigned)bfd_getl32 (eihd.ident),
7188 (unsigned)bfd_getl32 (eihd.sysver),
7190 (unsigned)bfd_getl32 (eihd.symvect_size));
7191 fprintf (file, _(" BPAGE: %u"),
7192 (unsigned)bfd_getl32 (eihd.virt_mem_block_size));
7193 if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT))
7195 eihef_off = bfd_getl32 (eihd.ext_fixup_off);
7196 eihnp_off = bfd_getl32 (eihd.noopt_psect_off);
7197 fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"),
7198 eihef_off, eihnp_off);
7200 fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias));
7204 struct vms_eihvn eihvn;
7208 fprintf (file, _("system version array information:\n"));
7209 if (bfd_seek (abfd, (file_ptr) eihvn_off, SEEK_SET)
7210 || bfd_bread (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn))
7212 fprintf (file, _("cannot read EIHVN header\n"));
7215 mask = bfd_getl32 (eihvn.subsystem_mask);
7216 for (j = 0; j < 32; j++)
7217 if (mask & (1 << j))
7219 struct vms_eihvn_subversion ver;
7220 if (bfd_bread (&ver, sizeof (ver), abfd) != sizeof (ver))
7222 fprintf (file, _("cannot read EIHVN version\n"));
7225 fprintf (file, _(" %02u "), j);
7228 case EIHVN__BASE_IMAGE_BIT:
7229 fputs (_("BASE_IMAGE "), file);
7231 case EIHVN__MEMORY_MANAGEMENT_BIT:
7232 fputs (_("MEMORY_MANAGEMENT"), file);
7235 fputs (_("IO "), file);
7237 case EIHVN__FILES_VOLUMES_BIT:
7238 fputs (_("FILES_VOLUMES "), file);
7240 case EIHVN__PROCESS_SCHED_BIT:
7241 fputs (_("PROCESS_SCHED "), file);
7243 case EIHVN__SYSGEN_BIT:
7244 fputs (_("SYSGEN "), file);
7246 case EIHVN__CLUSTERS_LOCKMGR_BIT:
7247 fputs (_("CLUSTERS_LOCKMGR "), file);
7249 case EIHVN__LOGICAL_NAMES_BIT:
7250 fputs (_("LOGICAL_NAMES "), file);
7252 case EIHVN__SECURITY_BIT:
7253 fputs (_("SECURITY "), file);
7255 case EIHVN__IMAGE_ACTIVATOR_BIT:
7256 fputs (_("IMAGE_ACTIVATOR "), file);
7258 case EIHVN__NETWORKS_BIT:
7259 fputs (_("NETWORKS "), file);
7261 case EIHVN__COUNTERS_BIT:
7262 fputs (_("COUNTERS "), file);
7264 case EIHVN__STABLE_BIT:
7265 fputs (_("STABLE "), file);
7267 case EIHVN__MISC_BIT:
7268 fputs (_("MISC "), file);
7270 case EIHVN__CPU_BIT:
7271 fputs (_("CPU "), file);
7273 case EIHVN__VOLATILE_BIT:
7274 fputs (_("VOLATILE "), file);
7276 case EIHVN__SHELL_BIT:
7277 fputs (_("SHELL "), file);
7279 case EIHVN__POSIX_BIT:
7280 fputs (_("POSIX "), file);
7282 case EIHVN__MULTI_PROCESSING_BIT:
7283 fputs (_("MULTI_PROCESSING "), file);
7285 case EIHVN__GALAXY_BIT:
7286 fputs (_("GALAXY "), file);
7289 fputs (_("*unknown* "), file);
7292 fprintf (file, _(": %u.%u\n"),
7293 (unsigned)bfd_getl16 (ver.major),
7294 (unsigned)bfd_getl16 (ver.minor));
7300 struct vms_eiha eiha;
7302 if (bfd_seek (abfd, (file_ptr) eiha_off, SEEK_SET)
7303 || bfd_bread (&eiha, sizeof (eiha), abfd) != sizeof (eiha))
7305 fprintf (file, _("cannot read EIHA\n"));
7308 fprintf (file, _("Image activation: (size=%u)\n"),
7309 (unsigned)bfd_getl32 (eiha.size));
7310 fprintf (file, _(" First address : 0x%08x 0x%08x\n"),
7311 (unsigned)bfd_getl32 (eiha.tfradr1_h),
7312 (unsigned)bfd_getl32 (eiha.tfradr1));
7313 fprintf (file, _(" Second address: 0x%08x 0x%08x\n"),
7314 (unsigned)bfd_getl32 (eiha.tfradr2_h),
7315 (unsigned)bfd_getl32 (eiha.tfradr2));
7316 fprintf (file, _(" Third address : 0x%08x 0x%08x\n"),
7317 (unsigned)bfd_getl32 (eiha.tfradr3_h),
7318 (unsigned)bfd_getl32 (eiha.tfradr3));
7319 fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"),
7320 (unsigned)bfd_getl32 (eiha.tfradr4_h),
7321 (unsigned)bfd_getl32 (eiha.tfradr4));
7322 fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"),
7323 (unsigned)bfd_getl32 (eiha.inishr_h),
7324 (unsigned)bfd_getl32 (eiha.inishr));
7328 struct vms_eihi eihi;
7330 if (bfd_seek (abfd, (file_ptr) eihi_off, SEEK_SET)
7331 || bfd_bread (&eihi, sizeof (eihi), abfd) != sizeof (eihi))
7333 fprintf (file, _("cannot read EIHI\n"));
7336 fprintf (file, _("Image identification: (major: %u, minor: %u)\n"),
7337 (unsigned)bfd_getl32 (eihi.majorid),
7338 (unsigned)bfd_getl32 (eihi.minorid));
7339 fprintf (file, _(" image name : %.*s\n"),
7340 eihi.imgnam[0], eihi.imgnam + 1);
7341 fprintf (file, _(" link time : %s\n"),
7342 vms_time_to_str (eihi.linktime));
7343 fprintf (file, _(" image ident : %.*s\n"),
7344 eihi.imgid[0], eihi.imgid + 1);
7345 fprintf (file, _(" linker ident : %.*s\n"),
7346 eihi.linkid[0], eihi.linkid + 1);
7347 fprintf (file, _(" image build ident: %.*s\n"),
7348 eihi.imgbid[0], eihi.imgbid + 1);
7352 struct vms_eihs eihs;
7354 if (bfd_seek (abfd, (file_ptr) eihs_off, SEEK_SET)
7355 || bfd_bread (&eihs, sizeof (eihs), abfd) != sizeof (eihs))
7357 fprintf (file, _("cannot read EIHS\n"));
7360 fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"),
7361 (unsigned)bfd_getl32 (eihs.majorid),
7362 (unsigned)bfd_getl32 (eihs.minorid));
7363 dst_vbn = bfd_getl32 (eihs.dstvbn);
7364 dst_size = bfd_getl32 (eihs.dstsize);
7365 fprintf (file, _(" debug symbol table : vbn: %u, size: %u\n"),
7367 gst_vbn = bfd_getl32 (eihs.gstvbn);
7368 gst_size = bfd_getl32 (eihs.gstsize);
7369 fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"),
7371 dmt_vbn = bfd_getl32 (eihs.dmtvbn);
7372 dmt_size = bfd_getl32 (eihs.dmtsize);
7373 fprintf (file, _(" debug module table : vbn: %u, size: %u\n"),
7376 while (eisd_off != 0)
7378 struct vms_eisd eisd;
7383 if (bfd_seek (abfd, (file_ptr) eisd_off, SEEK_SET)
7384 || bfd_bread (&eisd, sizeof (eisd), abfd) != sizeof (eisd))
7386 fprintf (file, _("cannot read EISD\n"));
7389 len = (unsigned)bfd_getl32 (eisd.eisdsize);
7390 if (len != (unsigned)-1)
7394 eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1);
7396 fprintf (file, _("Image section descriptor: (major: %u, minor: %u, "
7397 "size: %u, offset: %u)\n"),
7398 (unsigned)bfd_getl32 (eisd.majorid),
7399 (unsigned)bfd_getl32 (eisd.minorid),
7403 fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"),
7404 (unsigned)bfd_getl32 (eisd.virt_addr + 4),
7405 (unsigned)bfd_getl32 (eisd.virt_addr + 0),
7406 (unsigned)bfd_getl32 (eisd.secsize));
7407 val = (unsigned)bfd_getl32 (eisd.flags);
7408 fprintf (file, _(" flags: 0x%04x"), val);
7409 if (val & EISD__M_GBL)
7410 fprintf (file, " GBL");
7411 if (val & EISD__M_CRF)
7412 fprintf (file, " CRF");
7413 if (val & EISD__M_DZRO)
7414 fprintf (file, " DZRO");
7415 if (val & EISD__M_WRT)
7416 fprintf (file, " WRT");
7417 if (val & EISD__M_INITALCODE)
7418 fprintf (file, " INITALCODE");
7419 if (val & EISD__M_BASED)
7420 fprintf (file, " BASED");
7421 if (val & EISD__M_FIXUPVEC)
7422 fprintf (file, " FIXUPVEC");
7423 if (val & EISD__M_RESIDENT)
7424 fprintf (file, " RESIDENT");
7425 if (val & EISD__M_VECTOR)
7426 fprintf (file, " VECTOR");
7427 if (val & EISD__M_PROTECT)
7428 fprintf (file, " PROTECT");
7429 if (val & EISD__M_LASTCLU)
7430 fprintf (file, " LASTCLU");
7431 if (val & EISD__M_EXE)
7432 fprintf (file, " EXE");
7433 if (val & EISD__M_NONSHRADR)
7434 fprintf (file, " NONSHRADR");
7435 if (val & EISD__M_QUAD_LENGTH)
7436 fprintf (file, " QUAD_LENGTH");
7437 if (val & EISD__M_ALLOC_64BIT)
7438 fprintf (file, " ALLOC_64BIT");
7439 fprintf (file, "\n");
7440 if (val & EISD__M_FIXUPVEC)
7442 eiaf_vbn = bfd_getl32 (eisd.vbn);
7443 eiaf_size = bfd_getl32 (eisd.secsize);
7445 fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("),
7446 (unsigned)bfd_getl32 (eisd.vbn),
7447 eisd.pfc, eisd.matchctl, eisd.type);
7450 case EISD__K_NORMAL:
7451 fputs (_("NORMAL"), file);
7453 case EISD__K_SHRFXD:
7454 fputs (_("SHRFXD"), file);
7456 case EISD__K_PRVFXD:
7457 fputs (_("PRVFXD"), file);
7459 case EISD__K_SHRPIC:
7460 fputs (_("SHRPIC"), file);
7462 case EISD__K_PRVPIC:
7463 fputs (_("PRVPIC"), file);
7465 case EISD__K_USRSTACK:
7466 fputs (_("USRSTACK"), file);
7469 fputs (_("*unknown*"), file);
7472 fputs (_(")\n"), file);
7473 if (val & EISD__M_GBL)
7474 fprintf (file, _(" ident: 0x%08x, name: %.*s\n"),
7475 (unsigned)bfd_getl32 (eisd.ident),
7476 eisd.gblnam[0], eisd.gblnam + 1);
7482 if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7484 fprintf (file, _("cannot read DMT\n"));
7488 fprintf (file, _("Debug module table:\n"));
7490 while (dmt_size > 0)
7492 struct vms_dmt_header dmth;
7495 if (bfd_bread (&dmth, sizeof (dmth), abfd) != sizeof (dmth))
7497 fprintf (file, _("cannot read DMT header\n"));
7500 count = bfd_getl16 (dmth.psect_count);
7502 _(" module address: 0x%08x, size: 0x%08x, (%u psect)\n"),
7503 (unsigned)bfd_getl32 (dmth.modbeg),
7504 (unsigned)bfd_getl32 (dmth.size), count);
7505 dmt_size -= sizeof (dmth);
7508 struct vms_dmt_psect dmtp;
7510 if (bfd_bread (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp))
7512 fprintf (file, _("cannot read DMT psect\n"));
7515 fprintf (file, _(" psect start: 0x%08x, length: %u\n"),
7516 (unsigned)bfd_getl32 (dmtp.start),
7517 (unsigned)bfd_getl32 (dmtp.length));
7519 dmt_size -= sizeof (dmtp);
7526 if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7528 fprintf (file, _("cannot read DST\n"));
7532 evax_bfd_print_dst (abfd, dst_size, file);
7536 if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET))
7538 fprintf (file, _("cannot read GST\n"));
7542 fprintf (file, _("Global symbol table:\n"));
7543 evax_bfd_print_eobj (abfd, file);
7548 struct vms_eiaf *eiaf;
7549 unsigned int qrelfixoff;
7550 unsigned int lrelfixoff;
7551 unsigned int qdotadroff;
7552 unsigned int ldotadroff;
7553 unsigned int shrimgcnt;
7554 unsigned int shlstoff;
7555 unsigned int codeadroff;
7556 unsigned int lpfixoff;
7557 unsigned int chgprtoff;
7559 buf = bfd_malloc (eiaf_size);
7561 if (bfd_seek (abfd, (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)
7562 || bfd_bread (buf, eiaf_size, abfd) != eiaf_size)
7564 fprintf (file, _("cannot read EIHA\n"));
7568 eiaf = (struct vms_eiaf *)buf;
7570 _("Image activator fixup: (major: %u, minor: %u)\n"),
7571 (unsigned)bfd_getl32 (eiaf->majorid),
7572 (unsigned)bfd_getl32 (eiaf->minorid));
7573 fprintf (file, _(" iaflink : 0x%08x %08x\n"),
7574 (unsigned)bfd_getl32 (eiaf->iaflink + 0),
7575 (unsigned)bfd_getl32 (eiaf->iaflink + 4));
7576 fprintf (file, _(" fixuplnk: 0x%08x %08x\n"),
7577 (unsigned)bfd_getl32 (eiaf->fixuplnk + 0),
7578 (unsigned)bfd_getl32 (eiaf->fixuplnk + 4));
7579 fprintf (file, _(" size : %u\n"),
7580 (unsigned)bfd_getl32 (eiaf->size));
7581 fprintf (file, _(" flags: 0x%08x\n"),
7582 (unsigned)bfd_getl32 (eiaf->flags));
7583 qrelfixoff = bfd_getl32 (eiaf->qrelfixoff);
7584 lrelfixoff = bfd_getl32 (eiaf->lrelfixoff);
7585 fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"),
7586 qrelfixoff, lrelfixoff);
7587 qdotadroff = bfd_getl32 (eiaf->qdotadroff);
7588 ldotadroff = bfd_getl32 (eiaf->ldotadroff);
7589 fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"),
7590 qdotadroff, ldotadroff);
7591 codeadroff = bfd_getl32 (eiaf->codeadroff);
7592 lpfixoff = bfd_getl32 (eiaf->lpfixoff);
7593 fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"),
7594 codeadroff, lpfixoff);
7595 chgprtoff = bfd_getl32 (eiaf->chgprtoff);
7596 fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff);
7597 shrimgcnt = bfd_getl32 (eiaf->shrimgcnt);
7598 shlstoff = bfd_getl32 (eiaf->shlstoff);
7599 fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"),
7600 shlstoff, shrimgcnt);
7601 fprintf (file, _(" shlextra : %5u, permctx : %5u\n"),
7602 (unsigned)bfd_getl32 (eiaf->shlextra),
7603 (unsigned)bfd_getl32 (eiaf->permctx));
7604 fprintf (file, _(" base_va : 0x%08x\n"),
7605 (unsigned)bfd_getl32 (eiaf->base_va));
7606 fprintf (file, _(" lppsbfixoff: %5u\n"),
7607 (unsigned)bfd_getl32 (eiaf->lppsbfixoff));
7611 struct vms_shl *shl = (struct vms_shl *)(buf + shlstoff);
7614 fprintf (file, _(" Shareable images:\n"));
7615 for (j = 0; j < shrimgcnt; j++, shl++)
7618 _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"),
7619 j, shl->size, shl->flags,
7620 shl->imgnam[0], shl->imgnam + 1);
7623 if (qrelfixoff != 0)
7625 fprintf (file, _(" quad-word relocation fixups:\n"));
7626 evax_bfd_print_relocation_records (file, buf + qrelfixoff, 8);
7628 if (lrelfixoff != 0)
7630 fprintf (file, _(" long-word relocation fixups:\n"));
7631 evax_bfd_print_relocation_records (file, buf + lrelfixoff, 4);
7633 if (qdotadroff != 0)
7635 fprintf (file, _(" quad-word .address reference fixups:\n"));
7636 evax_bfd_print_address_fixups (file, buf + qdotadroff);
7638 if (ldotadroff != 0)
7640 fprintf (file, _(" long-word .address reference fixups:\n"));
7641 evax_bfd_print_address_fixups (file, buf + ldotadroff);
7643 if (codeadroff != 0)
7645 fprintf (file, _(" Code Address Reference Fixups:\n"));
7646 evax_bfd_print_reference_fixups (file, buf + codeadroff);
7650 fprintf (file, _(" Linkage Pairs Referece Fixups:\n"));
7651 evax_bfd_print_reference_fixups (file, buf + lpfixoff);
7655 unsigned int count = (unsigned)bfd_getl32 (buf + chgprtoff);
7656 struct vms_eicp *eicp = (struct vms_eicp *)(buf + chgprtoff + 4);
7659 fprintf (file, _(" Change Protection (%u entries):\n"), count);
7660 for (j = 0; j < count; j++, eicp++)
7662 unsigned int prot = bfd_getl32 (eicp->newprt);
7664 _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "),
7665 (unsigned)bfd_getl32 (eicp->baseva + 4),
7666 (unsigned)bfd_getl32 (eicp->baseva + 0),
7667 (unsigned)bfd_getl32 (eicp->size),
7668 (unsigned)bfd_getl32 (eicp->newprt));
7672 fprintf (file, "NA");
7674 case PRT__C_RESERVED:
7675 fprintf (file, "RES");
7678 fprintf (file, "KW");
7681 fprintf (file, "KR");
7684 fprintf (file, "UW");
7687 fprintf (file, "EW");
7690 fprintf (file, "ERKW");
7693 fprintf (file, "ER");
7696 fprintf (file, "SW");
7699 fprintf (file, "SREW");
7702 fprintf (file, "SRKW");
7705 fprintf (file, "SR");
7708 fprintf (file, "URSW");
7711 fprintf (file, "UREW");
7714 fprintf (file, "URKW");
7717 fprintf (file, "UR");
7731 vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
7733 FILE *file = (FILE *)ptr;
7735 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
7736 evax_bfd_print_image (abfd, file);
7739 if (bfd_seek (abfd, 0, SEEK_SET))
7741 evax_bfd_print_eobj (abfd, file);
7748 /* Slurp an ordered set of VMS object records. */
7751 alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info)
7753 asection *cur_section;
7754 file_ptr cur_offset;
7755 asection *dst_section;
7756 file_ptr dst_offset;
7758 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
7761 PRIV (image_autoextend) = FALSE;
7766 dst_section = PRIV (dst_section);
7770 if (info->strip == strip_all || info->strip == strip_debugger)
7775 else if (dst_section)
7777 dst_offset = dst_section->output_offset;
7778 dst_section = dst_section->output_section;
7787 type = _bfd_vms_get_object_record (abfd);
7790 vms_debug2 ((2, "next_record failed\n"));
7796 PRIV (image_section) = cur_section;
7797 PRIV (image_offset) = cur_offset;
7798 res = _bfd_vms_slurp_etir (abfd, info);
7799 cur_section = PRIV (image_section);
7800 cur_offset = PRIV (image_offset);
7804 if (dst_section == NULL)
7806 PRIV (image_section) = dst_section;
7807 PRIV (image_offset) = dst_offset;
7808 PRIV (image_autoextend) = TRUE;
7809 res = _bfd_vms_slurp_etir (abfd, info);
7810 PRIV (image_autoextend) = FALSE;
7811 dst_offset = PRIV (image_offset);
7820 vms_debug2 ((2, "slurp eobj type %d failed\n", type));
7827 alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
7828 struct bfd_link_info *info ATTRIBUTE_UNUSED)
7833 /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */
7836 alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib)
7838 struct alpha_vms_shlib_el *sl;
7839 asection *sect = PRIV2 (src, image_section);
7840 file_ptr offset = PRIV2 (src, image_offset);
7842 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
7843 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
7844 sl->has_fixups = TRUE;
7845 VEC_APPEND_EL (sl->lp, bfd_vma,
7846 sect->output_section->vma + sect->output_offset + offset);
7850 alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib)
7852 struct alpha_vms_shlib_el *sl;
7853 asection *sect = PRIV2 (src, image_section);
7854 file_ptr offset = PRIV2 (src, image_offset);
7856 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
7857 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
7858 sl->has_fixups = TRUE;
7859 VEC_APPEND_EL (sl->ca, bfd_vma,
7860 sect->output_section->vma + sect->output_offset + offset);
7864 alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src,
7865 bfd *shlib, bfd_vma vec)
7867 struct alpha_vms_shlib_el *sl;
7868 struct alpha_vms_vma_ref *r;
7869 asection *sect = PRIV2 (src, image_section);
7870 file_ptr offset = PRIV2 (src, image_offset);
7872 sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs,
7873 struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index));
7874 sl->has_fixups = TRUE;
7875 r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref);
7876 r->vma = sect->output_section->vma + sect->output_offset + offset;
7881 alpha_vms_add_lw_fixup (struct bfd_link_info *info ATTRIBUTE_UNUSED,
7882 unsigned int shr ATTRIBUTE_UNUSED,
7883 bfd_vma vec ATTRIBUTE_UNUSED)
7890 alpha_vms_add_qw_fixup (struct bfd_link_info *info ATTRIBUTE_UNUSED,
7891 unsigned int shr ATTRIBUTE_UNUSED,
7892 bfd_vma vec ATTRIBUTE_UNUSED)
7899 alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
7904 alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED)
7908 static struct bfd_hash_entry *
7909 alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry,
7910 struct bfd_hash_table *table,
7913 struct alpha_vms_link_hash_entry *ret =
7914 (struct alpha_vms_link_hash_entry *) entry;
7916 /* Allocate the structure if it has not already been allocated by a
7919 ret = ((struct alpha_vms_link_hash_entry *)
7920 bfd_hash_allocate (table,
7921 sizeof (struct alpha_vms_link_hash_entry)));
7925 /* Call the allocation method of the superclass. */
7926 ret = ((struct alpha_vms_link_hash_entry *)
7927 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
7932 return (struct bfd_hash_entry *) ret;
7935 /* Create an Alpha/VMS link hash table. */
7937 static struct bfd_link_hash_table *
7938 alpha_vms_bfd_link_hash_table_create (bfd *abfd)
7940 struct alpha_vms_link_hash_table *ret;
7941 bfd_size_type amt = sizeof (struct alpha_vms_link_hash_table);
7943 ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt);
7946 if (!_bfd_link_hash_table_init (&ret->root, abfd,
7947 alpha_vms_link_hash_newfunc,
7948 sizeof (struct alpha_vms_link_hash_entry)))
7954 VEC_INIT (ret->shrlibs);
7961 alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
7965 for (i = 0; i < PRIV (gsd_sym_count); i++)
7967 struct vms_symbol_entry *e = PRIV (syms)[i];
7968 struct alpha_vms_link_hash_entry *h;
7971 if (!alpha_vms_convert_symbol (abfd, e, &sym))
7974 if ((e->flags & EGSY__V_DEF) && abfd->selective_search)
7976 /* In selective_search mode, only add definition that are
7978 h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup
7979 (info->hash, sym.name, FALSE, FALSE, FALSE);
7980 if (h == NULL || h->root.type != bfd_link_hash_undefined)
7986 if (_bfd_generic_link_add_one_symbol
7987 (info, abfd, sym.name, sym.flags, sym.section, sym.value,
7988 NULL, FALSE, FALSE, (struct bfd_link_hash_entry **)&h) == FALSE)
7991 if ((e->flags & EGSY__V_DEF)
7993 && abfd->xvec == info->output_bfd->xvec)
7997 if (abfd->flags & DYNAMIC)
7999 struct alpha_vms_shlib_el *shlib;
8001 /* We do not want to include any of the sections in a dynamic
8002 object in the output file. See comment in elflink.c. */
8003 bfd_section_list_clear (abfd);
8005 shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs,
8006 struct alpha_vms_shlib_el);
8008 VEC_INIT (shlib->ca);
8009 VEC_INIT (shlib->lp);
8010 VEC_INIT (shlib->qr);
8011 PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1;
8018 alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
8021 struct bfd_link_hash_entry **pundef;
8022 struct bfd_link_hash_entry **next_pundef;
8024 /* We only accept VMS libraries. */
8025 if (info->output_bfd->xvec != abfd->xvec)
8027 bfd_set_error (bfd_error_wrong_format);
8031 /* The archive_pass field in the archive itself is used to
8032 initialize PASS, since we may search the same archive multiple
8034 pass = ++abfd->archive_pass;
8036 /* Look through the list of undefined symbols. */
8037 for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef)
8039 struct bfd_link_hash_entry *h;
8040 file_ptr file_offset;
8045 next_pundef = &(*pundef)->u.undef.next;
8047 /* When a symbol is defined, it is not necessarily removed from
8049 if (h->type != bfd_link_hash_undefined
8050 && h->type != bfd_link_hash_common)
8052 /* Remove this entry from the list, for general cleanliness
8053 and because we are going to look through the list again
8054 if we search any more libraries. We can't remove the
8055 entry if it is the tail, because that would lose any
8056 entries we add to the list later on. */
8057 if (*pundef != info->hash->undefs_tail)
8059 *pundef = *next_pundef;
8060 next_pundef = pundef;
8065 /* Look for this symbol in the archive hash table. */
8066 file_offset = _bfd_vms_lib_find_symbol (abfd, h->root.string);
8067 if (file_offset == 0)
8069 /* Nothing in this slot. */
8073 element = bfd_get_elt_at_index (abfd, file_offset);
8074 if (element == NULL)
8077 if (element->archive_pass == -1 || element->archive_pass == pass)
8080 if (! bfd_check_format (element, bfd_object))
8082 element->archive_pass = -1;
8086 orig_element = element;
8087 if (bfd_is_thin_archive (abfd))
8089 element = _bfd_vms_lib_get_imagelib_file (element);
8090 if (element == NULL || !bfd_check_format (element, bfd_object))
8092 orig_element->archive_pass = -1;
8097 /* Unlike the generic linker, we know that this element provides
8098 a definition for an undefined symbol and we know that we want
8099 to include it. We don't need to check anything. */
8100 if (! (*info->callbacks->add_archive_element) (info, element,
8103 if (! alpha_vms_link_add_object_symbols (element, info))
8106 orig_element->archive_pass = pass;
8113 alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
8115 switch (bfd_get_format (abfd))
8118 vms_debug2 ((2, "vms_link_add_symbols for object %s\n",
8120 return alpha_vms_link_add_object_symbols (abfd, info);
8123 vms_debug2 ((2, "vms_link_add_symbols for archive %s\n",
8125 return alpha_vms_link_add_archive_symbols (abfd, info);
8128 bfd_set_error (bfd_error_wrong_format);
8134 alpha_vms_build_fixups (struct bfd_link_info *info)
8136 struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info);
8137 unsigned char *content;
8139 unsigned int sz = 0;
8140 unsigned int lp_sz = 0;
8141 unsigned int ca_sz = 0;
8142 unsigned int qr_sz = 0;
8143 unsigned int shrimg_cnt = 0;
8144 struct vms_eiaf *eiaf;
8148 /* Shared libraries. */
8149 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8151 struct alpha_vms_shlib_el *shlib;
8153 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8155 if (!shlib->has_fixups)
8160 if (VEC_COUNT (shlib->ca) > 0)
8162 /* Header + entries. */
8164 ca_sz += VEC_COUNT (shlib->ca) * 4;
8166 if (VEC_COUNT (shlib->lp) > 0)
8168 /* Header + entries. */
8170 lp_sz += VEC_COUNT (shlib->lp) * 4;
8172 if (VEC_COUNT (shlib->qr) > 0)
8174 /* Header + entries. */
8176 qr_sz += VEC_COUNT (shlib->qr) * 8;
8187 /* Finish now if there is no content. */
8188 if (ca_sz + lp_sz + qr_sz == 0)
8191 /* Allocate section content (round-up size) */
8192 sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl)
8193 + ca_sz + lp_sz + qr_sz;
8194 sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1);
8195 content = bfd_zalloc (info->output_bfd, sz);
8196 if (content == NULL)
8199 sec = alpha_vms_link_hash (info)->fixup;
8200 sec->contents = content;
8203 eiaf = (struct vms_eiaf *)content;
8204 off = sizeof (struct vms_eiaf);
8205 bfd_putl32 (0, eiaf->majorid);
8206 bfd_putl32 (0, eiaf->minorid);
8207 bfd_putl32 (0, eiaf->iaflink);
8208 bfd_putl32 (0, eiaf->fixuplnk);
8209 bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size);
8210 bfd_putl32 (0, eiaf->flags);
8211 bfd_putl32 (0, eiaf->qrelfixoff);
8212 bfd_putl32 (0, eiaf->lrelfixoff);
8213 bfd_putl32 (0, eiaf->qdotadroff);
8214 bfd_putl32 (0, eiaf->ldotadroff);
8215 bfd_putl32 (0, eiaf->codeadroff);
8216 bfd_putl32 (0, eiaf->lpfixoff);
8217 bfd_putl32 (0, eiaf->chgprtoff);
8218 bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff);
8219 bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt);
8220 bfd_putl32 (0, eiaf->shlextra);
8221 bfd_putl32 (0, eiaf->permctx);
8222 bfd_putl32 (0, eiaf->base_va);
8223 bfd_putl32 (0, eiaf->lppsbfixoff);
8230 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8232 struct alpha_vms_shlib_el *shlib;
8233 struct vms_shl *shl;
8235 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8237 if (!shlib->has_fixups)
8240 /* Renumber shared images. */
8241 PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++;
8243 shl = (struct vms_shl *)(content + off);
8244 bfd_putl32 (0, shl->baseva);
8245 bfd_putl32 (0, shl->shlptr);
8246 bfd_putl32 (0, shl->ident);
8247 bfd_putl32 (0, shl->permctx);
8248 shl->size = sizeof (struct vms_shl);
8249 bfd_putl16 (0, shl->fill_1);
8251 bfd_putl32 (0, shl->icb);
8252 shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name));
8253 memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name),
8256 off += sizeof (struct vms_shl);
8262 bfd_putl32 (off, eiaf->codeadroff);
8264 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8266 struct alpha_vms_shlib_el *shlib;
8269 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8271 if (VEC_COUNT (shlib->ca) == 0)
8274 bfd_putl32 (VEC_COUNT (shlib->ca), content + off);
8275 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8278 for (j = 0; j < VEC_COUNT (shlib->ca); j++)
8280 bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr,
8286 bfd_putl32 (0, content + off);
8287 bfd_putl32 (0, content + off + 4);
8294 bfd_putl32 (off, eiaf->lpfixoff);
8296 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8298 struct alpha_vms_shlib_el *shlib;
8301 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8303 if (VEC_COUNT (shlib->lp) == 0)
8306 bfd_putl32 (VEC_COUNT (shlib->lp), content + off);
8307 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8310 for (j = 0; j < VEC_COUNT (shlib->lp); j++)
8312 bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr,
8318 bfd_putl32 (0, content + off);
8319 bfd_putl32 (0, content + off + 4);
8326 bfd_putl32 (off, eiaf->qdotadroff);
8328 for (i = 0; i < VEC_COUNT (t->shrlibs); i++)
8330 struct alpha_vms_shlib_el *shlib;
8333 shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i);
8335 if (VEC_COUNT (shlib->qr) == 0)
8338 bfd_putl32 (VEC_COUNT (shlib->qr), content + off);
8339 bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4);
8342 for (j = 0; j < VEC_COUNT (shlib->qr); j++)
8344 struct alpha_vms_vma_ref *r;
8345 r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j);
8346 bfd_putl32 (r->vma - t->base_addr, content + off);
8347 bfd_putl32 (r->ref, content + off + 4);
8352 bfd_putl32 (0, content + off);
8353 bfd_putl32 (0, content + off + 4);
8364 alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
8367 struct bfd_link_order *p;
8373 bfd_get_outsymbols (abfd) = NULL;
8374 bfd_get_symcount (abfd) = 0;
8376 /* Mark all sections which will be included in the output file. */
8377 for (o = abfd->sections; o != NULL; o = o->next)
8378 for (p = o->map_head.link_order; p != NULL; p = p->next)
8379 if (p->type == bfd_indirect_link_order)
8380 p->u.indirect.section->linker_mark = TRUE;
8383 /* Handle all the link order information for the sections. */
8384 for (o = abfd->sections; o != NULL; o = o->next)
8386 printf ("For section %s (at 0x%08x, flags=0x%08x):\n",
8387 o->name, (unsigned)o->vma, (unsigned)o->flags);
8389 for (p = o->map_head.link_order; p != NULL; p = p->next)
8391 printf (" at 0x%08x - 0x%08x: ",
8392 (unsigned)p->offset, (unsigned)(p->offset + p->size - 1));
8395 case bfd_section_reloc_link_order:
8396 case bfd_symbol_reloc_link_order:
8397 printf (" section/symbol reloc\n");
8399 case bfd_indirect_link_order:
8400 printf (" section %s of %s\n",
8401 p->u.indirect.section->name,
8402 p->u.indirect.section->owner->filename);
8404 case bfd_data_link_order:
8405 printf (" explicit data\n");
8408 printf (" *unknown* type %u\n", p->type);
8415 /* Find entry point. */
8416 if (bfd_get_start_address (abfd) == 0)
8418 bfd *startbfd = NULL;
8420 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8422 /* Consider only VMS object files. */
8423 if (sub->xvec != abfd->xvec)
8426 if (!PRIV2 (sub, eom_data).eom_has_transfer)
8428 if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd)
8430 if (startbfd != NULL
8431 && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR))
8433 (*info->callbacks->einfo)
8434 (_("%P: multiple entry points: in modules %B and %B\n"),
8443 unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx;
8444 bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr;
8447 sec = PRIV2 (startbfd, sections)[ps_idx];
8449 bfd_set_start_address
8450 (abfd, sec->output_section->vma + sec->output_offset + tfradr);
8454 /* Allocate content. */
8455 base_addr = (bfd_vma)-1;
8457 for (o = abfd->sections; o != NULL; o = o->next)
8459 if (o->flags & SEC_HAS_CONTENTS)
8461 o->contents = bfd_alloc (abfd, o->size);
8462 if (o->contents == NULL)
8465 if (o->flags & SEC_LOAD)
8467 if (o->vma < base_addr)
8469 if (o->vma + o->size > last_addr)
8470 last_addr = o->vma + o->size;
8474 fixupsec = bfd_make_section_anyway_with_flags
8475 (info->output_bfd, "$FIXUP$",
8476 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED);
8477 if (fixupsec == NULL)
8479 last_addr = (last_addr + 0xffff) & ~0xffff;
8480 fixupsec->vma = last_addr;
8482 alpha_vms_link_hash (info)->fixup = fixupsec;
8483 alpha_vms_link_hash (info)->base_addr = base_addr;
8485 /* Read all sections from the inputs. */
8486 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8488 if (sub->flags & DYNAMIC)
8490 alpha_vms_create_eisd_for_shared (abfd, sub);
8494 if (!alpha_vms_read_sections_content (sub, info))
8498 /* Handle all the link order information for the sections. */
8499 for (o = abfd->sections; o != NULL; o = o->next)
8501 for (p = o->map_head.link_order; p != NULL; p = p->next)
8505 case bfd_section_reloc_link_order:
8506 case bfd_symbol_reloc_link_order:
8509 case bfd_indirect_link_order:
8513 if (! _bfd_default_link_order (abfd, info, o, p))
8520 /* Compute fixups. */
8521 if (!alpha_vms_build_fixups (info))
8527 /* Read the contents of a section.
8528 buf points to a buffer of buf_size bytes to be filled with
8529 section data (starting at offset into section) */
8532 alpha_vms_get_section_contents (bfd *abfd, asection *section,
8533 void *buf, file_ptr offset,
8534 bfd_size_type count)
8538 /* Image are easy. */
8539 if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC))
8540 return _bfd_generic_get_section_contents (abfd, section,
8541 buf, offset, count);
8544 if (offset + count < count
8545 || offset + count > section->size)
8547 bfd_set_error (bfd_error_invalid_operation);
8551 /* Alloc in memory and read ETIRs. */
8552 BFD_ASSERT (section->contents == NULL);
8554 for (sec = abfd->sections; sec; sec = sec->next)
8556 BFD_ASSERT (sec->contents == NULL);
8558 if (sec->size != 0 && (sec->flags & SEC_HAS_CONTENTS))
8560 sec->contents = bfd_alloc (abfd, sec->size);
8561 if (sec->contents == NULL)
8565 if (!alpha_vms_read_sections_content (abfd, NULL))
8567 for (sec = abfd->sections; sec; sec = sec->next)
8568 if (section->contents)
8569 section->flags |= SEC_IN_MEMORY;
8570 memcpy (buf, section->contents + offset, count);
8575 /* Set the format of a file being written. */
8578 alpha_vms_mkobject (bfd * abfd)
8580 const bfd_arch_info_type *arch;
8582 vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd));
8584 if (!vms_initialize (abfd))
8587 PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE);
8588 if (PRIV (recwr.buf) == NULL)
8591 arch = bfd_scan_arch ("alpha");
8595 bfd_set_error (bfd_error_wrong_format);
8599 abfd->arch_info = arch;
8606 /* Called when the BFD is being closed to do any necessary cleanup. */
8609 vms_close_and_cleanup (bfd * abfd)
8611 vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd));
8613 if (abfd == NULL || abfd->tdata.any == NULL)
8616 if (abfd->format == bfd_archive)
8618 bfd_release (abfd, abfd->tdata.any);
8619 abfd->tdata.any = NULL;
8623 if (PRIV (recrd.buf) != NULL)
8624 free (PRIV (recrd.buf));
8626 if (PRIV (sections) != NULL)
8627 free (PRIV (sections));
8629 bfd_release (abfd, abfd->tdata.any);
8630 abfd->tdata.any = NULL;
8633 if (abfd->direction == write_direction)
8635 /* Last step on VMS is to convert the file to variable record length
8637 if (bfd_cache_close (abfd) != TRUE)
8639 if (vms_convert_to_var_unix_filename (abfd->filename) != TRUE)
8647 /* Called when a new section is created. */
8650 vms_new_section_hook (bfd * abfd, asection *section)
8654 /* Count hasn't been incremented yet. */
8655 unsigned int section_count = abfd->section_count + 1;
8657 vms_debug2 ((1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
8658 abfd, section->index, section->name, section_count));
8660 bfd_set_section_alignment (abfd, section, 0);
8662 if (section_count > PRIV (section_count))
8664 amt = section_count;
8665 amt *= sizeof (asection *);
8666 PRIV (sections) = bfd_realloc_or_free (PRIV (sections), amt);
8667 if (PRIV (sections) == NULL)
8669 PRIV (section_count) = section_count;
8672 vms_debug2 ((6, "section_count: %d\n", PRIV (section_count)));
8674 PRIV (sections)[section->index] = section;
8676 vms_debug2 ((7, "%d: %s\n", section->index, section->name));
8678 amt = sizeof (struct vms_section_data_struct);
8679 section->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
8680 if (section->used_by_bfd == NULL)
8683 if (strcmp (bfd_get_section_name (abfd, section), "$DST$") == 0)
8684 PRIV (dst_section) = section;
8686 /* Create the section symbol. */
8687 return _bfd_generic_new_section_hook (abfd, section);
8690 /* Part 4.5, symbols. */
8692 /* Print symbol to file according to how. how is one of
8693 bfd_print_symbol_name just print the name
8694 bfd_print_symbol_more print more (???)
8695 bfd_print_symbol_all print all we know, which is not much right now :-). */
8698 vms_print_symbol (bfd * abfd,
8701 bfd_print_symbol_type how)
8703 vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n",
8704 abfd, file, symbol, how));
8708 case bfd_print_symbol_name:
8709 case bfd_print_symbol_more:
8710 fprintf ((FILE *)file," %s", symbol->name);
8713 case bfd_print_symbol_all:
8715 const char *section_name = symbol->section->name;
8717 bfd_print_symbol_vandf (abfd, file, symbol);
8719 fprintf ((FILE *) file," %-8s %s", section_name, symbol->name);
8725 /* Return information about symbol in ret.
8727 fill type, value and name
8730 B bss segment symbol
8732 D data segment symbol
8734 t a static function symbol
8735 T text segment symbol
8740 vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED,
8746 vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret));
8748 sec = symbol->section;
8755 else if (bfd_is_com_section (sec))
8757 else if (bfd_is_abs_section (sec))
8759 else if (bfd_is_und_section (sec))
8761 else if (bfd_is_ind_section (sec))
8763 else if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
8765 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
8767 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
8772 if (ret->type != 'U')
8773 ret->value = symbol->value + symbol->section->vma;
8776 ret->name = symbol->name;
8779 /* Return TRUE if the given symbol sym in the BFD abfd is
8780 a compiler generated local label, else return FALSE. */
8783 vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
8786 vms_debug2 ((1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd, name));
8787 return name[0] == '$';
8790 /* Part 4.7, writing an object file. */
8792 /* Sets the contents of the section section in BFD abfd to the data starting
8793 in memory at LOCATION. The data is written to the output section starting
8794 at offset offset for count bytes.
8796 Normally TRUE is returned, else FALSE. Possible error returns are:
8797 o bfd_error_no_contents - The output section does not have the
8798 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
8799 o and some more too */
8802 _bfd_vms_set_section_contents (bfd * abfd,
8804 const void * location,
8806 bfd_size_type count)
8808 if (section->contents == NULL)
8810 section->contents = bfd_alloc (abfd, section->size);
8811 if (section->contents == NULL)
8814 memcpy (section->contents + offset, location, (size_t) count);
8820 /* Set the architecture and machine type in BFD abfd to arch and mach.
8821 Find the correct pointer to a structure and insert it into the arch_info
8825 alpha_vms_set_arch_mach (bfd *abfd,
8826 enum bfd_architecture arch, unsigned long mach)
8828 if (arch != bfd_arch_alpha
8829 && arch != bfd_arch_unknown)
8832 return bfd_default_set_arch_mach (abfd, arch, mach);
8835 /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */
8838 bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED,
8839 asection *sec, flagword no_flags, flagword flags)
8841 vms_section_data (sec)->no_flags = no_flags;
8842 vms_section_data (sec)->flags = flags;
8845 struct vms_private_data_struct *
8846 bfd_vms_get_data (bfd *abfd)
8848 return (struct vms_private_data_struct *)abfd->tdata.any;
8851 #define vms_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
8852 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
8853 #define vms_bfd_copy_link_hash_symbol_type \
8854 _bfd_generic_copy_link_hash_symbol_type
8855 #define vms_bfd_is_group_section bfd_generic_is_group_section
8856 #define vms_bfd_discard_group bfd_generic_discard_group
8857 #define vms_section_already_linked _bfd_generic_section_already_linked
8858 #define vms_bfd_define_common_symbol bfd_generic_define_common_symbol
8859 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
8861 #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
8862 #define vms_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
8863 #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
8864 #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
8865 #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
8866 #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
8868 /* Symbols table. */
8869 #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol
8870 #define alpha_vms_bfd_is_target_special_symbol \
8871 ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
8872 #define alpha_vms_print_symbol vms_print_symbol
8873 #define alpha_vms_get_symbol_info vms_get_symbol_info
8874 #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols
8875 #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
8876 #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno
8877 #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info
8878 #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
8879 #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_dst_line
8880 #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name
8882 /* Generic table. */
8883 #define alpha_vms_close_and_cleanup vms_close_and_cleanup
8884 #define alpha_vms_bfd_free_cached_info vms_bfd_free_cached_info
8885 #define alpha_vms_new_section_hook vms_new_section_hook
8886 #define alpha_vms_set_section_contents _bfd_vms_set_section_contents
8887 #define alpha_vms_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
8889 #define alpha_vms_bfd_get_relocated_section_contents \
8890 bfd_generic_get_relocated_section_contents
8892 #define alpha_vms_bfd_relax_section bfd_generic_relax_section
8893 #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections
8894 #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections
8895 #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section
8896 #define alpha_vms_bfd_discard_group bfd_generic_discard_group
8897 #define alpha_vms_section_already_linked \
8898 _bfd_generic_section_already_linked
8900 #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol
8901 #define alpha_vms_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
8902 #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms
8903 #define alpha_vms_bfd_copy_link_hash_symbol_type \
8904 _bfd_generic_copy_link_hash_symbol_type
8906 #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section
8908 #define alpha_vms_get_dynamic_symtab_upper_bound \
8909 _bfd_nodynamic_get_dynamic_symtab_upper_bound
8910 #define alpha_vms_canonicalize_dynamic_symtab \
8911 _bfd_nodynamic_canonicalize_dynamic_symtab
8912 #define alpha_vms_get_dynamic_reloc_upper_bound \
8913 _bfd_nodynamic_get_dynamic_reloc_upper_bound
8914 #define alpha_vms_canonicalize_dynamic_reloc \
8915 _bfd_nodynamic_canonicalize_dynamic_reloc
8917 const bfd_target vms_alpha_vec =
8919 "vms-alpha", /* Name. */
8920 bfd_target_evax_flavour,
8921 BFD_ENDIAN_LITTLE, /* Data byte order is little. */
8922 BFD_ENDIAN_LITTLE, /* Header byte order is little. */
8924 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS
8925 | WP_TEXT | D_PAGED), /* Object flags. */
8926 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
8927 | SEC_READONLY | SEC_CODE | SEC_DATA
8928 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */
8929 0, /* symbol_leading_char. */
8930 ' ', /* ar_pad_char. */
8931 15, /* ar_max_namelen. */
8932 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
8933 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
8934 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
8935 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
8936 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
8937 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
8939 {_bfd_dummy_target, alpha_vms_object_p, /* bfd_check_format. */
8940 _bfd_vms_lib_alpha_archive_p, _bfd_dummy_target},
8941 {bfd_false, alpha_vms_mkobject, /* bfd_set_format. */
8942 _bfd_vms_lib_mkarchive, bfd_false},
8943 {bfd_false, alpha_vms_write_object_contents, /* bfd_write_contents. */
8944 _bfd_vms_lib_write_archive_contents, bfd_false},
8946 BFD_JUMP_TABLE_GENERIC (alpha_vms),
8947 BFD_JUMP_TABLE_COPY (vms),
8948 BFD_JUMP_TABLE_CORE (_bfd_nocore),
8949 BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib),
8950 BFD_JUMP_TABLE_SYMBOLS (alpha_vms),
8951 BFD_JUMP_TABLE_RELOCS (alpha_vms),
8952 BFD_JUMP_TABLE_WRITE (alpha_vms),
8953 BFD_JUMP_TABLE_LINK (alpha_vms),
8954 BFD_JUMP_TABLE_DYNAMIC (alpha_vms),