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