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