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