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