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