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