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