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