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