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