/src/binutils-gdb/bfd/vms-alpha.c
Line | Count | Source |
1 | | /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files. |
2 | | Copyright (C) 1996-2026 Free Software Foundation, Inc. |
3 | | |
4 | | Initial version written by Klaus Kaempf (kkaempf@rmi.de) |
5 | | Major rewrite by Adacore. |
6 | | |
7 | | This program is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3 of the License, or |
10 | | (at your option) any later version. |
11 | | |
12 | | This program is distributed in the hope that it will be useful, |
13 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | GNU General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this program; if not, write to the Free Software |
19 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | | MA 02110-1301, USA. */ |
21 | | |
22 | | /* TODO: |
23 | | o overlayed sections |
24 | | o PIC |
25 | | o Generation of shared image |
26 | | o Relocation optimizations |
27 | | o EISD for the stack |
28 | | o Vectors isect |
29 | | o 64 bits sections |
30 | | o Entry point |
31 | | o LIB$INITIALIZE |
32 | | o protected sections (for messages) |
33 | | ... |
34 | | */ |
35 | | |
36 | | #include "sysdep.h" |
37 | | #include <limits.h> |
38 | | #include "bfd.h" |
39 | | #include "bfdlink.h" |
40 | | #include "libbfd.h" |
41 | | #include "bfdver.h" |
42 | | |
43 | | #include "vms.h" |
44 | | #include "vms/eihd.h" |
45 | | #include "vms/eiha.h" |
46 | | #include "vms/eihi.h" |
47 | | #include "vms/eihs.h" |
48 | | #include "vms/eisd.h" |
49 | | #include "vms/dmt.h" |
50 | | #include "vms/dst.h" |
51 | | #include "vms/eihvn.h" |
52 | | #include "vms/eobjrec.h" |
53 | | #include "vms/egsd.h" |
54 | | #include "vms/egps.h" |
55 | | #include "vms/esgps.h" |
56 | | #include "vms/eeom.h" |
57 | | #include "vms/emh.h" |
58 | | #include "vms/eiaf.h" |
59 | | #include "vms/shl.h" |
60 | | #include "vms/eicp.h" |
61 | | #include "vms/etir.h" |
62 | | #include "vms/egsy.h" |
63 | | #include "vms/esdf.h" |
64 | | #include "vms/esdfm.h" |
65 | | #include "vms/esdfv.h" |
66 | | #include "vms/esrf.h" |
67 | | #include "vms/egst.h" |
68 | | #include "vms/eidc.h" |
69 | | #include "vms/dsc.h" |
70 | | #include "vms/prt.h" |
71 | | #include "vms/internal.h" |
72 | | |
73 | | |
74 | | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
75 | | #ifndef CHAR_BIT |
76 | | #define CHAR_BIT 8 |
77 | | #endif |
78 | | |
79 | | /* The r_type field in a reloc is one of the following values. */ |
80 | 0 | #define ALPHA_R_IGNORE 0 |
81 | 0 | #define ALPHA_R_REFQUAD 1 |
82 | 0 | #define ALPHA_R_BRADDR 2 |
83 | 0 | #define ALPHA_R_HINT 3 |
84 | 0 | #define ALPHA_R_SREL16 4 |
85 | 0 | #define ALPHA_R_SREL32 5 |
86 | 0 | #define ALPHA_R_SREL64 6 |
87 | | #define ALPHA_R_OP_PUSH 7 |
88 | | #define ALPHA_R_OP_STORE 8 |
89 | | #define ALPHA_R_OP_PSUB 9 |
90 | | #define ALPHA_R_OP_PRSHIFT 10 |
91 | 0 | #define ALPHA_R_LINKAGE 11 |
92 | 0 | #define ALPHA_R_REFLONG 12 |
93 | 0 | #define ALPHA_R_CODEADDR 13 |
94 | 0 | #define ALPHA_R_NOP 14 |
95 | 0 | #define ALPHA_R_BSR 15 |
96 | 0 | #define ALPHA_R_LDA 16 |
97 | 0 | #define ALPHA_R_BOH 17 |
98 | | |
99 | | /* These are used with DST_S_C_LINE_NUM. */ |
100 | 0 | #define DST_S_C_LINE_NUM_HEADER_SIZE 4 |
101 | | |
102 | | /* These are used with DST_S_C_SOURCE */ |
103 | | |
104 | 0 | #define DST_S_B_PCLINE_UNSBYTE 1 |
105 | 0 | #define DST_S_W_PCLINE_UNSWORD 1 |
106 | 0 | #define DST_S_L_PCLINE_UNSLONG 1 |
107 | | |
108 | 0 | #define DST_S_B_MODBEG_NAME 14 |
109 | 0 | #define DST_S_L_RTNBEG_ADDRESS 5 |
110 | 0 | #define DST_S_B_RTNBEG_NAME 13 |
111 | 0 | #define DST_S_L_RTNEND_SIZE 5 |
112 | | |
113 | | /* These are used with DST_S_C_SOURCE. */ |
114 | 0 | #define DST_S_C_SOURCE_HEADER_SIZE 4 |
115 | | |
116 | 0 | #define DST_S_B_SRC_DF_LENGTH 1 |
117 | 0 | #define DST_S_W_SRC_DF_FILEID 3 |
118 | 0 | #define DST_S_B_SRC_DF_FILENAME 20 |
119 | 0 | #define DST_S_B_SRC_UNSBYTE 1 |
120 | 0 | #define DST_S_W_SRC_UNSWORD 1 |
121 | 0 | #define DST_S_L_SRC_UNSLONG 1 |
122 | | |
123 | | /* Debugger symbol definitions. */ |
124 | | |
125 | 377 | #define DBG_S_L_DMT_MODBEG 0 |
126 | 377 | #define DBG_S_L_DST_SIZE 4 |
127 | 377 | #define DBG_S_W_DMT_PSECT_COUNT 8 |
128 | 824 | #define DBG_S_C_DMT_HEADER_SIZE 12 |
129 | | |
130 | 823 | #define DBG_S_L_DMT_PSECT_START 0 |
131 | 823 | #define DBG_S_L_DMT_PSECT_LENGTH 4 |
132 | 1.70k | #define DBG_S_C_DMT_PSECT_SIZE 8 |
133 | | |
134 | | /* VMS module header. */ |
135 | | |
136 | | struct hdr_struct |
137 | | { |
138 | | char hdr_b_strlvl; |
139 | | int hdr_l_arch1; |
140 | | int hdr_l_arch2; |
141 | | int hdr_l_recsiz; |
142 | | char *hdr_t_name; |
143 | | char *hdr_t_version; |
144 | | char *hdr_t_date; |
145 | | char *hdr_c_lnm; |
146 | | char *hdr_c_src; |
147 | | char *hdr_c_ttl; |
148 | | }; |
149 | | |
150 | 2 | #define EMH_DATE_LENGTH 17 |
151 | | |
152 | | /* VMS End-Of-Module records (EOM/EEOM). */ |
153 | | |
154 | | struct eom_struct |
155 | | { |
156 | | unsigned int eom_l_total_lps; |
157 | | unsigned short eom_w_comcod; |
158 | | bool eom_has_transfer; |
159 | | unsigned char eom_b_tfrflg; |
160 | | unsigned int eom_l_psindx; |
161 | | unsigned int eom_l_tfradr; |
162 | | }; |
163 | | |
164 | | struct vms_symbol_entry |
165 | | { |
166 | | bfd *owner; |
167 | | |
168 | | /* Common fields. */ |
169 | | unsigned char typ; |
170 | | unsigned char data_type; |
171 | | unsigned short flags; |
172 | | |
173 | | /* Section and offset/value of the symbol. */ |
174 | | unsigned int value; |
175 | | asection *section; |
176 | | |
177 | | /* Section and offset/value for the entry point (only for subprg). */ |
178 | | asection *code_section; |
179 | | unsigned int code_value; |
180 | | |
181 | | /* Symbol vector offset. */ |
182 | | unsigned int symbol_vector; |
183 | | |
184 | | /* Length of the name. */ |
185 | | unsigned char namelen; |
186 | | |
187 | | char name[1]; |
188 | | }; |
189 | | |
190 | | /* Stack value for push/pop commands. */ |
191 | | |
192 | | struct stack_struct |
193 | | { |
194 | | bfd_vma value; |
195 | | unsigned int reloc; |
196 | | }; |
197 | | |
198 | 106k | #define STACKSIZE 128 |
199 | | |
200 | | /* A minimal decoding of DST compilation units. We only decode |
201 | | what's needed to get to the line number information. */ |
202 | | |
203 | | struct fileinfo |
204 | | { |
205 | | char *name; |
206 | | unsigned int srec; |
207 | | }; |
208 | | |
209 | | struct srecinfo |
210 | | { |
211 | | struct srecinfo *next; |
212 | | unsigned int line; |
213 | | unsigned int sfile; |
214 | | unsigned int srec; |
215 | | }; |
216 | | |
217 | | struct lineinfo |
218 | | { |
219 | | struct lineinfo *next; |
220 | | bfd_vma address; |
221 | | unsigned int line; |
222 | | }; |
223 | | |
224 | | struct funcinfo |
225 | | { |
226 | | struct funcinfo *next; |
227 | | char *name; |
228 | | bfd_vma low; |
229 | | bfd_vma high; |
230 | | }; |
231 | | |
232 | | struct module |
233 | | { |
234 | | /* Chain the previously read compilation unit. */ |
235 | | struct module *next; |
236 | | |
237 | | /* The module name. */ |
238 | | char *name; |
239 | | |
240 | | /* The start offset and size of debug info in the DST section. */ |
241 | | unsigned int modbeg; |
242 | | unsigned int size; |
243 | | |
244 | | /* The lowest and highest addresses contained in this compilation |
245 | | unit as specified in the compilation unit header. */ |
246 | | bfd_vma low; |
247 | | bfd_vma high; |
248 | | |
249 | | /* The listing line table. */ |
250 | | struct lineinfo *line_table; |
251 | | |
252 | | /* The source record table. */ |
253 | | struct srecinfo *srec_table; |
254 | | |
255 | | /* A list of the functions found in this module. */ |
256 | | struct funcinfo *func_table; |
257 | | |
258 | | /* Current allocation of file_table. */ |
259 | | unsigned int file_table_count; |
260 | | |
261 | | /* An array of the files making up this module. */ |
262 | | struct fileinfo *file_table; |
263 | | }; |
264 | | |
265 | | /* BFD private data for alpha-vms. */ |
266 | | |
267 | | struct vms_private_data_struct |
268 | | { |
269 | | /* If 1, relocs have been read successfully, if 0 they have yet to be |
270 | | read, if -1 reading relocs failed. */ |
271 | | int reloc_done; |
272 | | |
273 | | /* Record input buffer. */ |
274 | | struct vms_rec_rd recrd; |
275 | | struct vms_rec_wr recwr; |
276 | | |
277 | | struct hdr_struct hdr_data; /* data from HDR/EMH record */ |
278 | | struct eom_struct eom_data; /* data from EOM/EEOM record */ |
279 | | |
280 | | /* Transfer addresses (entry points). */ |
281 | | bfd_vma transfer_address[4]; |
282 | | |
283 | | /* Array of GSD sections to get the correspond BFD one. */ |
284 | | unsigned int section_max; /* Size of the sections array. */ |
285 | | unsigned int section_count; /* Number of GSD sections. */ |
286 | | asection **sections; |
287 | | |
288 | | /* Array of raw symbols. */ |
289 | | struct vms_symbol_entry **syms; |
290 | | |
291 | | /* Canonicalized symbols. */ |
292 | | asymbol **csymbols; |
293 | | |
294 | | /* Number of symbols. */ |
295 | | unsigned int gsd_sym_count; |
296 | | /* Size of the syms array. */ |
297 | | unsigned int max_sym_count; |
298 | | /* Number of procedure symbols. */ |
299 | | unsigned int norm_sym_count; |
300 | | |
301 | | /* Stack used to evaluate TIR/ETIR commands. */ |
302 | | struct stack_struct *stack; |
303 | | int stackptr; |
304 | | |
305 | | /* Content reading. */ |
306 | | asection *image_section; /* section for image_ptr */ |
307 | | ufile_ptr image_offset; /* Offset for image_ptr. */ |
308 | | |
309 | | struct module *modules; /* list of all compilation units */ |
310 | | |
311 | | /* The DST section. */ |
312 | | asection *dst_section; |
313 | | |
314 | | unsigned int dst_ptr_offsets_count; /* # of offsets in following array */ |
315 | | unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */ |
316 | | |
317 | | /* Shared library support */ |
318 | | bfd_vma symvva; /* relative virtual address of symbol vector */ |
319 | | unsigned int ident; |
320 | | unsigned char matchctl; |
321 | | |
322 | | /* Shared library index. This is used for input bfd while linking. */ |
323 | | unsigned int shr_index; |
324 | | |
325 | | /* Used to place structures in the file. */ |
326 | | file_ptr file_pos; |
327 | | |
328 | | /* Simply linked list of eisd. */ |
329 | | struct vms_internal_eisd_map *eisd_head; |
330 | | struct vms_internal_eisd_map *eisd_tail; |
331 | | |
332 | | /* Simply linked list of eisd for shared libraries. */ |
333 | | struct vms_internal_eisd_map *gbl_eisd_head; |
334 | | struct vms_internal_eisd_map *gbl_eisd_tail; |
335 | | |
336 | | /* linkage index counter used by conditional store commands */ |
337 | | unsigned int vms_linkage_index; |
338 | | }; |
339 | | |
340 | | #define PRIV2(abfd, name) \ |
341 | 2.14M | (((struct vms_private_data_struct *)(abfd)->tdata.any)->name) |
342 | 2.14M | #define PRIV(name) PRIV2(abfd,name) |
343 | | |
344 | | |
345 | | /* Used to keep extra VMS specific information for a given section. |
346 | | |
347 | | reloc_size holds the size of the relocation stream, note this |
348 | | is very different from the number of relocations as VMS relocations |
349 | | are variable length. |
350 | | |
351 | | reloc_stream is the actual stream of relocation entries. */ |
352 | | |
353 | | struct vms_section_data_struct |
354 | | { |
355 | | /* Maximnum number of entries in sec->relocation. */ |
356 | | unsigned reloc_max; |
357 | | |
358 | | /* Corresponding eisd. Used only while generating executables. */ |
359 | | struct vms_internal_eisd_map *eisd; |
360 | | |
361 | | /* PSC flags to be clear. */ |
362 | | flagword no_flags; |
363 | | |
364 | | /* PSC flags to be set. */ |
365 | | flagword flags; |
366 | | }; |
367 | | |
368 | | #define vms_section_data(sec) \ |
369 | 72 | ((struct vms_section_data_struct *)sec->used_by_bfd) |
370 | | |
371 | | /* To be called from the debugger. */ |
372 | | struct vms_private_data_struct *bfd_vms_get_data (bfd *); |
373 | | |
374 | | static int vms_get_remaining_object_record (bfd *, unsigned int); |
375 | | static bool _bfd_vms_slurp_object_records (bfd * abfd); |
376 | | static bool alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *); |
377 | | static bool alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *); |
378 | | static bool alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *, |
379 | | bfd_vma); |
380 | | static bool alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int, |
381 | | bfd_vma); |
382 | | static bool alpha_vms_add_lw_reloc (struct bfd_link_info *); |
383 | | static bool alpha_vms_add_qw_reloc (struct bfd_link_info *); |
384 | | |
385 | | struct vector_type |
386 | | { |
387 | | unsigned int max_el; |
388 | | unsigned int nbr_el; |
389 | | void *els; |
390 | | }; |
391 | | |
392 | | /* Number of elements in VEC. */ |
393 | | |
394 | 0 | #define VEC_COUNT(VEC) ((VEC).nbr_el) |
395 | | |
396 | | /* Get the address of the Nth element. */ |
397 | | |
398 | 0 | #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N]) |
399 | | |
400 | | #define VEC_INIT(VEC) \ |
401 | 0 | do { \ |
402 | 0 | (VEC).max_el = 0; \ |
403 | 0 | (VEC).nbr_el = 0; \ |
404 | 0 | (VEC).els = NULL; \ |
405 | 0 | } while (0) |
406 | | |
407 | | /* Be sure there is room for a new element. */ |
408 | | |
409 | | static void *vector_grow1 (struct vector_type *vec, size_t elsz); |
410 | | |
411 | | /* Allocate room for a new element and return its address. */ |
412 | | |
413 | | #define VEC_APPEND(VEC, TYPE) \ |
414 | 0 | ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE))) |
415 | | |
416 | | struct alpha_vms_vma_ref |
417 | | { |
418 | | bfd_vma vma; /* Vma in the output. */ |
419 | | bfd_vma ref; /* Reference in the input. */ |
420 | | }; |
421 | | |
422 | | struct alpha_vms_shlib_el |
423 | | { |
424 | | bfd *abfd; |
425 | | bool has_fixups; |
426 | | |
427 | | struct vector_type lp; /* Vector of bfd_vma. */ |
428 | | struct vector_type ca; /* Vector of bfd_vma. */ |
429 | | struct vector_type qr; /* Vector of struct alpha_vms_vma_ref. */ |
430 | | }; |
431 | | |
432 | | /* Alpha VMS linker hash table. */ |
433 | | |
434 | | struct alpha_vms_link_hash_table |
435 | | { |
436 | | struct bfd_link_hash_table root; |
437 | | |
438 | | /* Vector of shared libraries. */ |
439 | | struct vector_type shrlibs; |
440 | | |
441 | | /* Fixup section. */ |
442 | | asection *fixup; |
443 | | |
444 | | /* Base address. Used by fixups. */ |
445 | | bfd_vma base_addr; |
446 | | }; |
447 | | |
448 | | #define alpha_vms_link_hash(INFO) \ |
449 | 0 | ((struct alpha_vms_link_hash_table *)(INFO->hash)) |
450 | | |
451 | | /* Alpha VMS linker hash table entry. */ |
452 | | |
453 | | struct alpha_vms_link_hash_entry |
454 | | { |
455 | | struct bfd_link_hash_entry root; |
456 | | |
457 | | /* Pointer to the original vms symbol. */ |
458 | | struct vms_symbol_entry *sym; |
459 | | }; |
460 | | |
461 | | /* Image reading. */ |
462 | | |
463 | | /* Read & process EIHD record. |
464 | | Return TRUE on success, FALSE on error. */ |
465 | | |
466 | | static bool |
467 | | _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset, |
468 | | unsigned int *eihs_offset) |
469 | 327 | { |
470 | 327 | unsigned int imgtype; |
471 | 327 | bfd_vma symvva; |
472 | 327 | struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec); |
473 | | |
474 | 327 | vms_debug2 ((8, "_bfd_vms_slurp_eihd\n")); |
475 | | |
476 | 327 | imgtype = bfd_getl32 (eihd->imgtype); |
477 | | |
478 | 327 | if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM) |
479 | 11 | abfd->flags |= EXEC_P; |
480 | | |
481 | 327 | symvva = bfd_getl64 (eihd->symvva); |
482 | 327 | if (symvva != 0) |
483 | 297 | { |
484 | 297 | PRIV (symvva) = symvva; |
485 | 297 | abfd->flags |= DYNAMIC; |
486 | 297 | } |
487 | | |
488 | 327 | PRIV (ident) = bfd_getl32 (eihd->ident); |
489 | 327 | PRIV (matchctl) = eihd->matchctl; |
490 | | |
491 | 327 | *eisd_offset = bfd_getl32 (eihd->isdoff); |
492 | 327 | *eihs_offset = bfd_getl32 (eihd->symdbgoff); |
493 | | |
494 | 327 | vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n", |
495 | 327 | PRIV (recrd.rec_size), imgtype, (unsigned long) symvva, |
496 | 327 | *eisd_offset, *eihs_offset)); |
497 | 327 | return true; |
498 | 327 | } |
499 | | |
500 | | /* Read & process EISD record. |
501 | | Return TRUE on success, FALSE on error. */ |
502 | | |
503 | | static bool |
504 | | _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset) |
505 | 327 | { |
506 | 327 | int section_count = 0; |
507 | | |
508 | 327 | vms_debug2 ((8, "_bfd_vms_slurp_eisd\n")); |
509 | | |
510 | 711 | while (1) |
511 | 711 | { |
512 | 711 | struct vms_eisd *eisd; |
513 | 711 | unsigned int rec_size; |
514 | 711 | unsigned int size; |
515 | 711 | uint64_t vaddr; |
516 | 711 | unsigned int flags; |
517 | 711 | unsigned int vbn; |
518 | 711 | char *name = NULL; |
519 | 711 | asection *section; |
520 | 711 | flagword bfd_flags; |
521 | | |
522 | | /* PR 17512: file: 3d9e9fe9. */ |
523 | 711 | if (offset > PRIV (recrd.rec_size) |
524 | 681 | || (PRIV (recrd.rec_size) - offset |
525 | 681 | < offsetof (struct vms_eisd, eisdsize) + 4)) |
526 | 52 | return false; |
527 | 659 | eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset); |
528 | 659 | rec_size = bfd_getl32 (eisd->eisdsize); |
529 | 659 | if (rec_size == 0) |
530 | 162 | break; |
531 | | |
532 | | /* Skip to next block if pad. */ |
533 | 497 | if (rec_size == 0xffffffff) |
534 | 86 | { |
535 | 86 | offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); |
536 | 86 | continue; |
537 | 86 | } |
538 | | |
539 | | /* Make sure that there is enough data present in the record. */ |
540 | 411 | if (rec_size < offsetof (struct vms_eisd, type) + 1) |
541 | 4 | return false; |
542 | | /* Make sure that the record is not too big either. */ |
543 | 407 | if (rec_size > PRIV (recrd.rec_size) - offset) |
544 | 83 | return false; |
545 | | |
546 | 324 | offset += rec_size; |
547 | | |
548 | 324 | size = bfd_getl32 (eisd->secsize); |
549 | 324 | vaddr = bfd_getl64 (eisd->virt_addr); |
550 | 324 | flags = bfd_getl32 (eisd->flags); |
551 | 324 | vbn = bfd_getl32 (eisd->vbn); |
552 | | |
553 | 324 | vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n", |
554 | 324 | offset, size, (unsigned long)vaddr, flags, vbn)); |
555 | | |
556 | | /* VMS combines psects from .obj files into isects in the .exe. This |
557 | | process doesn't preserve enough information to reliably determine |
558 | | what's in each section without examining the data. This is |
559 | | especially true of DWARF debug sections. */ |
560 | 324 | bfd_flags = SEC_ALLOC; |
561 | 324 | if (vbn != 0) |
562 | 243 | bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD; |
563 | | |
564 | 324 | if (flags & EISD__M_EXE) |
565 | 107 | bfd_flags |= SEC_CODE; |
566 | | |
567 | 324 | if (flags & EISD__M_NONSHRADR) |
568 | 94 | bfd_flags |= SEC_DATA; |
569 | | |
570 | 324 | if (!(flags & EISD__M_WRT)) |
571 | 214 | bfd_flags |= SEC_READONLY; |
572 | | |
573 | 324 | if (flags & EISD__M_DZRO) |
574 | 87 | bfd_flags |= SEC_DATA; |
575 | | |
576 | 324 | if (flags & EISD__M_FIXUPVEC) |
577 | 80 | bfd_flags |= SEC_DATA; |
578 | | |
579 | 324 | if (flags & EISD__M_CRF) |
580 | 104 | bfd_flags |= SEC_DATA; |
581 | | |
582 | 324 | if (flags & EISD__M_GBL) |
583 | 63 | { |
584 | 63 | if (rec_size <= offsetof (struct vms_eisd, gblnam)) |
585 | 2 | return false; |
586 | 61 | else if (rec_size < sizeof (struct vms_eisd)) |
587 | 26 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
588 | 26 | rec_size - offsetof (struct vms_eisd, gblnam)); |
589 | 35 | else |
590 | 35 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
591 | 35 | EISD__K_GBLNAMLEN); |
592 | 61 | if (name == NULL || name[0] == 0) |
593 | 18 | return false; |
594 | 43 | bfd_flags |= SEC_COFF_SHARED_LIBRARY; |
595 | 43 | bfd_flags &= ~(SEC_ALLOC | SEC_LOAD); |
596 | 43 | } |
597 | 261 | else if (flags & EISD__M_FIXUPVEC) |
598 | 25 | name = "$FIXUPVEC$"; |
599 | 236 | else if (eisd->type == EISD__K_USRSTACK) |
600 | 3 | name = "$STACK$"; |
601 | 233 | else |
602 | 233 | { |
603 | 233 | const char *pfx; |
604 | | |
605 | 233 | name = (char *) bfd_alloc (abfd, 32); |
606 | 233 | if (name == NULL) |
607 | 0 | return false; |
608 | 233 | if (flags & EISD__M_DZRO) |
609 | 27 | pfx = "BSS"; |
610 | 206 | else if (flags & EISD__M_EXE) |
611 | 40 | pfx = "CODE"; |
612 | 166 | else if (!(flags & EISD__M_WRT)) |
613 | 138 | pfx = "RO"; |
614 | 28 | else |
615 | 28 | pfx = "LOCAL"; |
616 | 233 | BFD_ASSERT (section_count < 999); |
617 | 233 | sprintf (name, "$%s_%03d$", pfx, section_count++); |
618 | 233 | } |
619 | | |
620 | 304 | section = bfd_make_section (abfd, name); |
621 | | |
622 | 304 | if (!section) |
623 | 6 | return false; |
624 | | |
625 | 298 | section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0; |
626 | 298 | section->size = size; |
627 | 298 | section->vma = vaddr; |
628 | | |
629 | 298 | if (!bfd_set_section_flags (section, bfd_flags)) |
630 | 0 | return false; |
631 | 298 | } |
632 | | |
633 | 162 | return true; |
634 | 327 | } |
635 | | |
636 | | /* Read & process EIHS record. |
637 | | Return TRUE on success, FALSE on error. */ |
638 | | |
639 | | static bool |
640 | | _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset) |
641 | 141 | { |
642 | 141 | unsigned char *p = PRIV (recrd.rec) + offset; |
643 | 141 | unsigned int gstvbn; |
644 | 141 | unsigned int gstsize ATTRIBUTE_UNUSED; |
645 | 141 | unsigned int dstvbn; |
646 | 141 | unsigned int dstsize; |
647 | 141 | unsigned int dmtvbn; |
648 | 141 | unsigned int dmtbytes; |
649 | 141 | asection *section; |
650 | | |
651 | | /* PR 21611: Check that offset is valid. */ |
652 | 141 | if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4)) |
653 | 28 | { |
654 | 28 | _bfd_error_handler (_("unable to read EIHS record at offset %#x"), |
655 | 28 | offset); |
656 | 28 | bfd_set_error (bfd_error_file_truncated); |
657 | 28 | return false; |
658 | 28 | } |
659 | | |
660 | 113 | gstvbn = bfd_getl32 (p + EIHS__L_GSTVBN); |
661 | 113 | gstsize = bfd_getl32 (p + EIHS__L_GSTSIZE); |
662 | 113 | dstvbn = bfd_getl32 (p + EIHS__L_DSTVBN); |
663 | 113 | dstsize = bfd_getl32 (p + EIHS__L_DSTSIZE); |
664 | 113 | dmtvbn = bfd_getl32 (p + EIHS__L_DMTVBN); |
665 | 113 | dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES); |
666 | | |
667 | | #if VMS_DEBUG |
668 | | vms_debug (8, "_bfd_vms_slurp_ihs\n"); |
669 | | vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n", |
670 | | gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes); |
671 | | #endif |
672 | | |
673 | 113 | if (dstvbn) |
674 | 102 | { |
675 | 102 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; |
676 | | |
677 | 102 | section = bfd_make_section (abfd, "$DST$"); |
678 | 102 | if (!section) |
679 | 0 | return false; |
680 | | |
681 | 102 | section->size = dstsize; |
682 | 102 | section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1); |
683 | | |
684 | 102 | if (!bfd_set_section_flags (section, bfd_flags)) |
685 | 0 | return false; |
686 | | |
687 | 102 | PRIV (dst_section) = section; |
688 | 102 | abfd->flags |= (HAS_DEBUG | HAS_LINENO); |
689 | 102 | } |
690 | | |
691 | 113 | if (dmtvbn) |
692 | 96 | { |
693 | 96 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; |
694 | | |
695 | 96 | section = bfd_make_section (abfd, "$DMT$"); |
696 | 96 | if (!section) |
697 | 0 | return false; |
698 | | |
699 | 96 | section->size = dmtbytes; |
700 | 96 | section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1); |
701 | | |
702 | 96 | if (!bfd_set_section_flags (section, bfd_flags)) |
703 | 0 | return false; |
704 | 96 | } |
705 | | |
706 | 113 | if (gstvbn) |
707 | 21 | { |
708 | 21 | if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET)) |
709 | 0 | { |
710 | 0 | bfd_set_error (bfd_error_file_truncated); |
711 | 0 | return false; |
712 | 0 | } |
713 | | |
714 | 21 | if (!_bfd_vms_slurp_object_records (abfd)) |
715 | 20 | return false; |
716 | | |
717 | 1 | abfd->flags |= HAS_SYMS; |
718 | 1 | } |
719 | | |
720 | 93 | return true; |
721 | 113 | } |
722 | | |
723 | | /* Object file reading. */ |
724 | | |
725 | | /* Object file input functions. */ |
726 | | |
727 | | /* Get next record from object file to vms_buf. |
728 | | Set PRIV(buf_size) and return it |
729 | | |
730 | | This is a little tricky since it should be portable. |
731 | | |
732 | | The openVMS object file has 'variable length' which means that |
733 | | read() returns data in chunks of (hopefully) correct and expected |
734 | | size. The linker (and other tools on VMS) depend on that. Unix |
735 | | doesn't know about 'formatted' files, so reading and writing such |
736 | | an object file in a Unix environment is not trivial. |
737 | | |
738 | | With the tool 'file' (available on all VMS FTP sites), one |
739 | | can view and change the attributes of a file. Changing from |
740 | | 'variable length' to 'fixed length, 512 bytes' reveals the |
741 | | record size at the first 2 bytes of every record. The same |
742 | | may happen during the transfer of object files from VMS to Unix, |
743 | | at least with UCX, the DEC implementation of TCP/IP. |
744 | | |
745 | | The VMS format repeats the size at bytes 2 & 3 of every record. |
746 | | |
747 | | On the first call (file_format == FF_UNKNOWN) we check if |
748 | | the first and the third byte pair (!) of the record match. |
749 | | If they do it's an object file in an Unix environment or with |
750 | | wrong attributes (FF_FOREIGN), else we should be in a VMS |
751 | | environment where read() returns the record size (FF_NATIVE). |
752 | | |
753 | | Reading is always done in 2 steps: |
754 | | 1. first just the record header is read and the size extracted, |
755 | | 2. then the read buffer is adjusted and the remaining bytes are |
756 | | read in. |
757 | | |
758 | | All file I/O is done on even file positions. */ |
759 | | |
760 | 4.15k | #define VMS_OBJECT_ADJUSTMENT 2 |
761 | | |
762 | | static void |
763 | | maybe_adjust_record_pointer_for_object (bfd *abfd) |
764 | 123k | { |
765 | | /* Set the file format once for all on the first invocation. */ |
766 | 123k | if (PRIV (recrd.file_format) == FF_UNKNOWN) |
767 | 95.4k | { |
768 | 95.4k | if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4] |
769 | 5.55k | && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5]) |
770 | 1.29k | PRIV (recrd.file_format) = FF_FOREIGN; |
771 | 94.1k | else |
772 | 94.1k | PRIV (recrd.file_format) = FF_NATIVE; |
773 | 95.4k | } |
774 | | |
775 | | /* The adjustment is needed only in an Unix environment. */ |
776 | 123k | if (PRIV (recrd.file_format) == FF_FOREIGN) |
777 | 3.11k | PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT; |
778 | 123k | } |
779 | | |
780 | | /* Implement step #1 of the object record reading procedure. |
781 | | Return the record type or -1 on failure. */ |
782 | | |
783 | | static int |
784 | | _bfd_vms_get_object_record (bfd *abfd) |
785 | 14.0k | { |
786 | 14.0k | unsigned int test_len = 6; |
787 | 14.0k | int type; |
788 | | |
789 | 14.0k | vms_debug2 ((8, "_bfd_vms_get_obj_record\n")); |
790 | | |
791 | | /* Skip alignment byte if the current position is odd. */ |
792 | 14.0k | if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1)) |
793 | 392 | { |
794 | 392 | if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1) |
795 | 1 | { |
796 | 1 | bfd_set_error (bfd_error_file_truncated); |
797 | 1 | return -1; |
798 | 1 | } |
799 | 392 | } |
800 | | |
801 | | /* Read the record header */ |
802 | 14.0k | if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len) |
803 | 100 | { |
804 | 100 | bfd_set_error (bfd_error_file_truncated); |
805 | 100 | return -1; |
806 | 100 | } |
807 | | |
808 | | /* Reset the record pointer. */ |
809 | 13.9k | PRIV (recrd.rec) = PRIV (recrd.buf); |
810 | 13.9k | maybe_adjust_record_pointer_for_object (abfd); |
811 | | |
812 | 13.9k | if (vms_get_remaining_object_record (abfd, test_len) <= 0) |
813 | 215 | return -1; |
814 | | |
815 | 13.7k | type = bfd_getl16 (PRIV (recrd.rec)); |
816 | | |
817 | 13.7k | vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n", |
818 | 13.7k | PRIV (recrd.rec), PRIV (recrd.rec_size), type)); |
819 | | |
820 | 13.7k | return type; |
821 | 13.9k | } |
822 | | |
823 | | /* Implement step #2 of the object record reading procedure. |
824 | | Return the size of the record or 0 on failure. */ |
825 | | |
826 | | static int |
827 | | vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far) |
828 | 15.6k | { |
829 | 15.6k | unsigned int to_read; |
830 | | |
831 | 15.6k | vms_debug2 ((8, "vms_get_remaining_obj_record\n")); |
832 | | |
833 | | /* Extract record size. */ |
834 | 15.6k | PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2); |
835 | | |
836 | 15.6k | if (PRIV (recrd.rec_size) == 0) |
837 | 480 | { |
838 | 480 | bfd_set_error (bfd_error_file_truncated); |
839 | 480 | return 0; |
840 | 480 | } |
841 | | |
842 | | /* That's what the linker manual says. */ |
843 | 15.1k | if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ) |
844 | 61 | { |
845 | 61 | bfd_set_error (bfd_error_file_truncated); |
846 | 61 | return 0; |
847 | 61 | } |
848 | | |
849 | | /* Take into account object adjustment. */ |
850 | 15.0k | to_read = PRIV (recrd.rec_size); |
851 | 15.0k | if (PRIV (recrd.file_format) == FF_FOREIGN) |
852 | 1.03k | to_read += VMS_OBJECT_ADJUSTMENT; |
853 | | |
854 | | /* Adjust the buffer. */ |
855 | 15.0k | if (to_read > PRIV (recrd.buf_size)) |
856 | 1.40k | { |
857 | 1.40k | PRIV (recrd.buf) |
858 | 1.40k | = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read); |
859 | 1.40k | if (PRIV (recrd.buf) == NULL) |
860 | 0 | return 0; |
861 | 1.40k | PRIV (recrd.buf_size) = to_read; |
862 | 1.40k | } |
863 | | /* PR 17512: file: 025-1974-0.004. */ |
864 | 13.6k | else if (to_read <= read_so_far) |
865 | 22 | return 0; |
866 | | |
867 | | /* Read the remaining record. */ |
868 | 15.0k | to_read -= read_so_far; |
869 | | |
870 | 15.0k | vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read)); |
871 | | |
872 | 15.0k | if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read) |
873 | 673 | { |
874 | 673 | bfd_set_error (bfd_error_file_truncated); |
875 | 673 | return 0; |
876 | 673 | } |
877 | | |
878 | | /* Reset the record pointer. */ |
879 | 14.3k | PRIV (recrd.rec) = PRIV (recrd.buf); |
880 | 14.3k | maybe_adjust_record_pointer_for_object (abfd); |
881 | | |
882 | 14.3k | vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n", |
883 | 14.3k | PRIV (recrd.rec_size))); |
884 | | |
885 | 14.3k | return PRIV (recrd.rec_size); |
886 | 15.0k | } |
887 | | |
888 | | /* Read and process emh record. |
889 | | Return TRUE on success, FALSE on error. */ |
890 | | |
891 | | static bool |
892 | | _bfd_vms_slurp_ehdr (bfd *abfd) |
893 | 971 | { |
894 | 971 | unsigned char *ptr; |
895 | 971 | unsigned int len, slen; |
896 | 971 | int subtype; |
897 | | |
898 | 971 | vms_debug2 ((2, "HDR/EMH\n")); |
899 | | |
900 | 971 | ptr = PRIV (recrd.rec); |
901 | 971 | len = PRIV (recrd.rec_size); |
902 | 971 | if (len < 6) |
903 | 4 | goto fail; |
904 | | |
905 | 967 | subtype = bfd_getl16 (ptr + 4); |
906 | | |
907 | 967 | vms_debug2 ((3, "subtype %d\n", subtype)); |
908 | | |
909 | 967 | ptr += 6; |
910 | 967 | len -= 6; |
911 | 967 | switch (subtype) |
912 | 967 | { |
913 | 66 | case EMH__C_MHD: |
914 | | /* Module header. */ |
915 | 66 | if (len < 15) |
916 | 8 | goto fail; |
917 | 58 | PRIV (hdr_data).hdr_b_strlvl = *ptr; |
918 | 58 | PRIV (hdr_data).hdr_l_arch1 = bfd_getl32 (ptr + 2); |
919 | 58 | PRIV (hdr_data).hdr_l_arch2 = bfd_getl32 (ptr + 6); |
920 | 58 | PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (ptr + 10); |
921 | 58 | ptr += 14; |
922 | 58 | len -= 14; |
923 | 58 | PRIV (hdr_data).hdr_t_name |
924 | 58 | = _bfd_vms_save_counted_string (abfd, ptr, len); |
925 | 58 | slen = *ptr + 1; |
926 | 58 | if (len <= slen) |
927 | 3 | goto fail; |
928 | 55 | ptr += slen; |
929 | 55 | len -= slen; |
930 | 55 | PRIV (hdr_data).hdr_t_version |
931 | 55 | = _bfd_vms_save_counted_string (abfd, ptr, len); |
932 | 55 | slen = *ptr + 1; |
933 | 55 | if (len < slen + 17) |
934 | 6 | goto fail; |
935 | 49 | ptr += slen; |
936 | 49 | PRIV (hdr_data).hdr_t_date |
937 | 49 | = _bfd_vms_save_sized_string (abfd, ptr, 17); |
938 | 49 | break; |
939 | | |
940 | 206 | case EMH__C_LNM: |
941 | 206 | PRIV (hdr_data).hdr_c_lnm |
942 | 206 | = _bfd_vms_save_sized_string (abfd, ptr, len); |
943 | 206 | break; |
944 | | |
945 | 27 | case EMH__C_SRC: |
946 | 27 | PRIV (hdr_data).hdr_c_src |
947 | 27 | = _bfd_vms_save_sized_string (abfd, ptr, len); |
948 | 27 | break; |
949 | | |
950 | 396 | case EMH__C_TTL: |
951 | 396 | PRIV (hdr_data).hdr_c_ttl |
952 | 396 | = _bfd_vms_save_sized_string (abfd, ptr, len); |
953 | 396 | break; |
954 | | |
955 | 169 | case EMH__C_CPR: |
956 | 256 | case EMH__C_MTC: |
957 | 265 | case EMH__C_GTX: |
958 | 265 | break; |
959 | | |
960 | 7 | default: |
961 | 28 | fail: |
962 | 28 | bfd_set_error (bfd_error_wrong_format); |
963 | 28 | return false; |
964 | 967 | } |
965 | | |
966 | 943 | return true; |
967 | 967 | } |
968 | | |
969 | | /* Typical sections for evax object files. */ |
970 | | |
971 | | #define EVAX_ABS_NAME "$ABS$" |
972 | 0 | #define EVAX_CODE_NAME "$CODE$" |
973 | 0 | #define EVAX_LINK_NAME "$LINK$" |
974 | 0 | #define EVAX_DATA_NAME "$DATA$" |
975 | 0 | #define EVAX_BSS_NAME "$BSS$" |
976 | | #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$" |
977 | 0 | #define EVAX_READONLY_NAME "$READONLY$" |
978 | 0 | #define EVAX_LITERAL_NAME "$LITERAL$" |
979 | 0 | #define EVAX_LITERALS_NAME "$LITERALS" |
980 | 0 | #define EVAX_COMMON_NAME "$COMMON$" |
981 | 0 | #define EVAX_LOCAL_NAME "$LOCAL$" |
982 | | |
983 | | struct sec_flags_struct |
984 | | { |
985 | | const char *name; /* Name of section. */ |
986 | | int vflags_always; |
987 | | flagword flags_always; /* Flags we set always. */ |
988 | | int vflags_hassize; |
989 | | flagword flags_hassize; /* Flags we set if the section has a size > 0. */ |
990 | | }; |
991 | | |
992 | | /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */ |
993 | | |
994 | | static const struct sec_flags_struct evax_section_flags[] = |
995 | | { |
996 | | { EVAX_ABS_NAME, |
997 | | EGPS__V_SHR, |
998 | | 0, |
999 | | EGPS__V_SHR, |
1000 | | 0 }, |
1001 | | { EVAX_CODE_NAME, |
1002 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
1003 | | SEC_CODE | SEC_READONLY, |
1004 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
1005 | | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1006 | | { EVAX_LITERAL_NAME, |
1007 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1008 | | SEC_DATA | SEC_READONLY, |
1009 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, |
1010 | | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1011 | | { EVAX_LINK_NAME, |
1012 | | EGPS__V_REL | EGPS__V_RD, |
1013 | | SEC_DATA | SEC_READONLY, |
1014 | | EGPS__V_REL | EGPS__V_RD, |
1015 | | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1016 | | { EVAX_DATA_NAME, |
1017 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1018 | | SEC_DATA, |
1019 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1020 | | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1021 | | { EVAX_BSS_NAME, |
1022 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1023 | | SEC_NO_FLAGS, |
1024 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1025 | | SEC_ALLOC }, |
1026 | | { EVAX_READONLYADDR_NAME, |
1027 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, |
1028 | | SEC_DATA | SEC_READONLY, |
1029 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, |
1030 | | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1031 | | { EVAX_READONLY_NAME, |
1032 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1033 | | SEC_DATA | SEC_READONLY, |
1034 | | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, |
1035 | | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1036 | | { EVAX_LOCAL_NAME, |
1037 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1038 | | SEC_DATA, |
1039 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1040 | | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1041 | | { EVAX_LITERALS_NAME, |
1042 | | EGPS__V_PIC | EGPS__V_OVR, |
1043 | | SEC_DATA | SEC_READONLY, |
1044 | | EGPS__V_PIC | EGPS__V_OVR, |
1045 | | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
1046 | | { NULL, |
1047 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1048 | | SEC_DATA, |
1049 | | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1050 | | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD } |
1051 | | }; |
1052 | | |
1053 | | /* Retrieve BFD section flags by name and size. */ |
1054 | | |
1055 | | static flagword |
1056 | | vms_secflag_by_name (const struct sec_flags_struct *section_flags, |
1057 | | const char *name, |
1058 | | int hassize) |
1059 | 36 | { |
1060 | 36 | int i = 0; |
1061 | | |
1062 | 372 | while (section_flags[i].name != NULL) |
1063 | 339 | { |
1064 | 339 | if (strcmp (name, section_flags[i].name) == 0) |
1065 | 3 | { |
1066 | 3 | if (hassize) |
1067 | 1 | return section_flags[i].flags_hassize; |
1068 | 2 | else |
1069 | 2 | return section_flags[i].flags_always; |
1070 | 3 | } |
1071 | 336 | i++; |
1072 | 336 | } |
1073 | 33 | if (hassize) |
1074 | 32 | return section_flags[i].flags_hassize; |
1075 | 1 | return section_flags[i].flags_always; |
1076 | 33 | } |
1077 | | |
1078 | | /* Retrieve VMS section flags by name and size. */ |
1079 | | |
1080 | | static flagword |
1081 | | vms_esecflag_by_name (const struct sec_flags_struct *section_flags, |
1082 | | const char *name, |
1083 | | int hassize) |
1084 | 0 | { |
1085 | 0 | int i = 0; |
1086 | |
|
1087 | 0 | while (section_flags[i].name != NULL) |
1088 | 0 | { |
1089 | 0 | if (strcmp (name, section_flags[i].name) == 0) |
1090 | 0 | { |
1091 | 0 | if (hassize) |
1092 | 0 | return section_flags[i].vflags_hassize; |
1093 | 0 | else |
1094 | 0 | return section_flags[i].vflags_always; |
1095 | 0 | } |
1096 | 0 | i++; |
1097 | 0 | } |
1098 | 0 | if (hassize) |
1099 | 0 | return section_flags[i].vflags_hassize; |
1100 | 0 | return section_flags[i].vflags_always; |
1101 | 0 | } |
1102 | | |
1103 | | /* Add SYM to the symbol table of ABFD. |
1104 | | Return FALSE in case of error. */ |
1105 | | |
1106 | | static bool |
1107 | | add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym) |
1108 | 419 | { |
1109 | 419 | if (PRIV (gsd_sym_count) >= PRIV (max_sym_count)) |
1110 | 59 | { |
1111 | 59 | if (PRIV (max_sym_count) == 0) |
1112 | 59 | { |
1113 | 59 | PRIV (max_sym_count) = 128; |
1114 | 59 | PRIV (syms) = bfd_malloc |
1115 | 59 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)); |
1116 | 59 | } |
1117 | 0 | else |
1118 | 0 | { |
1119 | 0 | PRIV (max_sym_count) *= 2; |
1120 | 0 | PRIV (syms) = bfd_realloc_or_free |
1121 | 0 | (PRIV (syms), |
1122 | 0 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *))); |
1123 | 0 | } |
1124 | 59 | if (PRIV (syms) == NULL) |
1125 | 0 | return false; |
1126 | 59 | } |
1127 | | |
1128 | 419 | PRIV (syms)[PRIV (gsd_sym_count)++] = sym; |
1129 | 419 | return true; |
1130 | 419 | } |
1131 | | |
1132 | | /* Create a symbol whose name is ASCIC and add it to ABFD. |
1133 | | Return NULL in case of error. */ |
1134 | | |
1135 | | static struct vms_symbol_entry * |
1136 | | add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max) |
1137 | 423 | { |
1138 | 423 | struct vms_symbol_entry *entry; |
1139 | 423 | unsigned int len; |
1140 | | |
1141 | 423 | len = *ascic++; |
1142 | 423 | max -= 1; |
1143 | 423 | if (len > max) |
1144 | 4 | { |
1145 | 4 | _bfd_error_handler (_("record is too small for symbol name length")); |
1146 | 4 | bfd_set_error (bfd_error_bad_value); |
1147 | 4 | return NULL; |
1148 | 4 | } |
1149 | | |
1150 | 419 | entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len); |
1151 | 419 | if (entry == NULL) |
1152 | 0 | return NULL; |
1153 | 419 | entry->namelen = len; |
1154 | 419 | memcpy (entry->name, ascic, len); |
1155 | 419 | entry->name[len] = 0; |
1156 | 419 | entry->owner = abfd; |
1157 | | |
1158 | 419 | if (!add_symbol_entry (abfd, entry)) |
1159 | 0 | return NULL; |
1160 | 419 | return entry; |
1161 | 419 | } |
1162 | | |
1163 | | /* Read and process EGSD. Return FALSE on failure. */ |
1164 | | |
1165 | | static bool |
1166 | | _bfd_vms_slurp_egsd (bfd *abfd) |
1167 | 563 | { |
1168 | 563 | int gsd_type; |
1169 | 563 | unsigned int gsd_size; |
1170 | 563 | unsigned char *vms_rec; |
1171 | 563 | bfd_vma base_addr; |
1172 | 563 | long psindx; |
1173 | | |
1174 | 563 | vms_debug2 ((2, "EGSD\n")); |
1175 | | |
1176 | 563 | if (PRIV (recrd.rec_size) < 8) |
1177 | 1 | { |
1178 | 1 | _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"), |
1179 | 1 | PRIV (recrd.rec_size)); |
1180 | 1 | bfd_set_error (bfd_error_bad_value); |
1181 | 1 | return false; |
1182 | 1 | } |
1183 | | |
1184 | 562 | PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */ |
1185 | 562 | PRIV (recrd.rec_size) -= 8; |
1186 | | |
1187 | | /* Calculate base address for each section. */ |
1188 | 562 | base_addr = 0; |
1189 | | |
1190 | 1.09k | while (PRIV (recrd.rec_size) > 4) |
1191 | 593 | { |
1192 | 593 | vms_rec = PRIV (recrd.rec); |
1193 | | |
1194 | 593 | gsd_type = bfd_getl16 (vms_rec); |
1195 | 593 | gsd_size = bfd_getl16 (vms_rec + 2); |
1196 | | |
1197 | 593 | vms_debug2 ((3, "egsd_type %d\n", gsd_type)); |
1198 | | |
1199 | | /* PR 21615: Check for size overflow. */ |
1200 | 593 | if (PRIV (recrd.rec_size) < gsd_size) |
1201 | 16 | { |
1202 | 16 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " |
1203 | 16 | "is larger than remaining space (%#x)"), |
1204 | 16 | gsd_type, gsd_size, PRIV (recrd.rec_size)); |
1205 | 16 | bfd_set_error (bfd_error_bad_value); |
1206 | 16 | return false; |
1207 | 16 | } |
1208 | | |
1209 | 577 | if (gsd_size < 4) |
1210 | 7 | { |
1211 | 11 | too_small: |
1212 | 11 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " |
1213 | 11 | "is too small"), |
1214 | 11 | gsd_type, gsd_size); |
1215 | 11 | bfd_set_error (bfd_error_bad_value); |
1216 | 11 | return false; |
1217 | 7 | } |
1218 | | |
1219 | 570 | switch (gsd_type) |
1220 | 570 | { |
1221 | 103 | case EGSD__C_PSC: |
1222 | | /* Program section definition. */ |
1223 | 103 | { |
1224 | 103 | struct vms_egps *egps = (struct vms_egps *) vms_rec; |
1225 | 103 | flagword new_flags, vms_flags; |
1226 | 103 | asection *section; |
1227 | | |
1228 | 103 | if (offsetof (struct vms_egps, flags) + 2 > gsd_size) |
1229 | 1 | goto too_small; |
1230 | 102 | vms_flags = bfd_getl16 (egps->flags); |
1231 | | |
1232 | 102 | if ((vms_flags & EGPS__V_REL) == 0) |
1233 | 59 | { |
1234 | | /* Use the global absolute section for all |
1235 | | absolute sections. */ |
1236 | 59 | section = bfd_abs_section_ptr; |
1237 | 59 | } |
1238 | 43 | else |
1239 | 43 | { |
1240 | 43 | char *name; |
1241 | 43 | bfd_vma align_addr; |
1242 | 43 | size_t left; |
1243 | | |
1244 | 43 | if (offsetof (struct vms_egps, namlng) >= gsd_size) |
1245 | 1 | goto too_small; |
1246 | 42 | left = gsd_size - offsetof (struct vms_egps, namlng); |
1247 | 42 | name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left); |
1248 | 42 | if (name == NULL || name[0] == 0) |
1249 | 2 | return false; |
1250 | | |
1251 | 40 | section = bfd_make_section (abfd, name); |
1252 | 40 | if (!section) |
1253 | 4 | return false; |
1254 | | |
1255 | 36 | section->filepos = 0; |
1256 | 36 | section->size = bfd_getl32 (egps->alloc); |
1257 | 36 | section->alignment_power = egps->align & 31; |
1258 | | |
1259 | 36 | vms_section_data (section)->flags = vms_flags; |
1260 | 36 | vms_section_data (section)->no_flags = 0; |
1261 | | |
1262 | 36 | new_flags = vms_secflag_by_name (evax_section_flags, |
1263 | 36 | section->name, |
1264 | 36 | section->size > 0); |
1265 | 36 | if (section->size > 0) |
1266 | 33 | new_flags |= SEC_LOAD; |
1267 | 36 | if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0) |
1268 | 14 | { |
1269 | | /* Set RELOC and HAS_CONTENTS if the section is not |
1270 | | demand-zero and not empty. */ |
1271 | 14 | new_flags |= SEC_HAS_CONTENTS; |
1272 | 14 | if (vms_flags & EGPS__V_REL) |
1273 | 14 | new_flags |= SEC_RELOC; |
1274 | 14 | } |
1275 | 36 | if (vms_flags & EGPS__V_EXE) |
1276 | 9 | { |
1277 | | /* Set CODE if section is executable. */ |
1278 | 9 | new_flags |= SEC_CODE; |
1279 | 9 | new_flags &= ~SEC_DATA; |
1280 | 9 | } |
1281 | 36 | if (!bfd_set_section_flags (section, new_flags)) |
1282 | 0 | return false; |
1283 | | |
1284 | | /* Give a non-overlapping vma to non absolute sections. */ |
1285 | 36 | align_addr = (bfd_vma) 1 << section->alignment_power; |
1286 | 36 | base_addr = (base_addr + align_addr - 1) & -align_addr; |
1287 | 36 | section->vma = base_addr; |
1288 | 36 | base_addr += section->size; |
1289 | 36 | } |
1290 | | |
1291 | | /* Append it to the section array. */ |
1292 | 95 | if (PRIV (section_count) >= PRIV (section_max)) |
1293 | 53 | { |
1294 | 53 | if (PRIV (section_max) == 0) |
1295 | 53 | PRIV (section_max) = 16; |
1296 | 0 | else |
1297 | 0 | PRIV (section_max) *= 2; |
1298 | 53 | PRIV (sections) = bfd_realloc_or_free |
1299 | 53 | (PRIV (sections), PRIV (section_max) * sizeof (asection *)); |
1300 | 53 | if (PRIV (sections) == NULL) |
1301 | 0 | return false; |
1302 | 53 | } |
1303 | | |
1304 | 95 | PRIV (sections)[PRIV (section_count)] = section; |
1305 | 95 | PRIV (section_count)++; |
1306 | 95 | } |
1307 | 0 | break; |
1308 | | |
1309 | 372 | case EGSD__C_SYM: |
1310 | 372 | { |
1311 | 372 | unsigned int nameoff; |
1312 | 372 | struct vms_symbol_entry *entry; |
1313 | 372 | struct vms_egsy *egsy = (struct vms_egsy *) vms_rec; |
1314 | 372 | flagword old_flags; |
1315 | | |
1316 | 372 | if (offsetof (struct vms_egsy, flags) + 2 > gsd_size) |
1317 | 0 | goto too_small; |
1318 | 372 | old_flags = bfd_getl16 (egsy->flags); |
1319 | 372 | if (old_flags & EGSY__V_DEF) |
1320 | 26 | nameoff = ESDF__B_NAMLNG; |
1321 | 346 | else |
1322 | 346 | nameoff = ESRF__B_NAMLNG; |
1323 | | |
1324 | 372 | if (nameoff >= gsd_size) |
1325 | 1 | goto too_small; |
1326 | 371 | entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff); |
1327 | 371 | if (entry == NULL) |
1328 | 2 | return false; |
1329 | | |
1330 | | /* Allow only duplicate reference. */ |
1331 | 369 | if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF)) |
1332 | 0 | abort (); |
1333 | | |
1334 | 369 | if (entry->typ == 0) |
1335 | 369 | { |
1336 | 369 | entry->typ = gsd_type; |
1337 | 369 | entry->data_type = egsy->datyp; |
1338 | 369 | entry->flags = old_flags; |
1339 | 369 | } |
1340 | | |
1341 | 369 | if (old_flags & EGSY__V_DEF) |
1342 | 25 | { |
1343 | 25 | struct vms_esdf *esdf = (struct vms_esdf *) vms_rec; |
1344 | | |
1345 | 25 | entry->value = bfd_getl64 (esdf->value); |
1346 | 25 | if (PRIV (sections) == NULL) |
1347 | 3 | return false; |
1348 | | |
1349 | 22 | psindx = bfd_getl32 (esdf->psindx); |
1350 | | /* PR 21813: Check for an out of range index. */ |
1351 | 22 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) |
1352 | 3 | { |
1353 | 13 | bad_psindx: |
1354 | 13 | _bfd_error_handler (_("corrupt EGSD record: its psindx " |
1355 | 13 | "field is too big (%#lx)"), |
1356 | 13 | psindx); |
1357 | 13 | bfd_set_error (bfd_error_bad_value); |
1358 | 13 | return false; |
1359 | 3 | } |
1360 | 19 | entry->section = PRIV (sections)[psindx]; |
1361 | | |
1362 | 19 | if (old_flags & EGSY__V_NORM) |
1363 | 10 | { |
1364 | 10 | PRIV (norm_sym_count)++; |
1365 | | |
1366 | 10 | entry->code_value = bfd_getl64 (esdf->code_address); |
1367 | 10 | psindx = bfd_getl32 (esdf->ca_psindx); |
1368 | | /* PR 21813: Check for an out of range index. */ |
1369 | 10 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) |
1370 | 6 | goto bad_psindx; |
1371 | 4 | entry->code_section = PRIV (sections)[psindx]; |
1372 | 4 | } |
1373 | 19 | } |
1374 | 369 | } |
1375 | 357 | break; |
1376 | | |
1377 | 357 | case EGSD__C_SYMG: |
1378 | 53 | { |
1379 | 53 | struct vms_symbol_entry *entry; |
1380 | 53 | struct vms_egst *egst = (struct vms_egst *)vms_rec; |
1381 | 53 | flagword old_flags; |
1382 | 53 | unsigned int nameoff = offsetof (struct vms_egst, namlng); |
1383 | | |
1384 | 53 | if (nameoff >= gsd_size) |
1385 | 1 | goto too_small; |
1386 | 52 | entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff); |
1387 | 52 | if (entry == NULL) |
1388 | 2 | return false; |
1389 | | |
1390 | 50 | old_flags = bfd_getl16 (egst->header.flags); |
1391 | 50 | entry->typ = gsd_type; |
1392 | 50 | entry->data_type = egst->header.datyp; |
1393 | 50 | entry->flags = old_flags; |
1394 | | |
1395 | 50 | entry->symbol_vector = bfd_getl32 (egst->value); |
1396 | | |
1397 | 50 | if (old_flags & EGSY__V_REL) |
1398 | 12 | { |
1399 | 12 | if (PRIV (sections) == NULL) |
1400 | 1 | return false; |
1401 | 11 | psindx = bfd_getl32 (egst->psindx); |
1402 | | /* PR 21813: Check for an out of range index. */ |
1403 | 11 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) |
1404 | 4 | goto bad_psindx; |
1405 | 7 | entry->section = PRIV (sections)[psindx]; |
1406 | 7 | } |
1407 | 38 | else |
1408 | 38 | entry->section = bfd_abs_section_ptr; |
1409 | | |
1410 | 45 | entry->value = bfd_getl64 (egst->lp_2); |
1411 | | |
1412 | 45 | if (old_flags & EGSY__V_NORM) |
1413 | 25 | { |
1414 | 25 | PRIV (norm_sym_count)++; |
1415 | | |
1416 | 25 | entry->code_value = bfd_getl64 (egst->lp_1); |
1417 | 25 | entry->code_section = bfd_abs_section_ptr; |
1418 | 25 | } |
1419 | 45 | } |
1420 | 0 | break; |
1421 | | |
1422 | 27 | case EGSD__C_SPSC: |
1423 | 39 | case EGSD__C_IDC: |
1424 | | /* Currently ignored. */ |
1425 | 39 | break; |
1426 | 0 | case EGSD__C_SYMM: |
1427 | 0 | case EGSD__C_SYMV: |
1428 | 3 | default: |
1429 | 3 | _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type); |
1430 | 3 | bfd_set_error (bfd_error_bad_value); |
1431 | 3 | return false; |
1432 | 570 | } |
1433 | | |
1434 | 536 | PRIV (recrd.rec_size) -= gsd_size; |
1435 | 536 | PRIV (recrd.rec) += gsd_size; |
1436 | 536 | } |
1437 | | |
1438 | | /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ? */ |
1439 | | |
1440 | 505 | if (PRIV (gsd_sym_count) > 0) |
1441 | 364 | abfd->flags |= HAS_SYMS; |
1442 | | |
1443 | 505 | return true; |
1444 | 562 | } |
1445 | | |
1446 | | /* Stack routines for vms ETIR commands. */ |
1447 | | |
1448 | | /* Push value and section index. */ |
1449 | | |
1450 | | static bool |
1451 | | _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc) |
1452 | 10.1k | { |
1453 | 10.1k | vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n", |
1454 | 10.1k | (unsigned long)val, reloc, PRIV (stackptr))); |
1455 | | |
1456 | 10.1k | PRIV (stack[PRIV (stackptr)]).value = val; |
1457 | 10.1k | PRIV (stack[PRIV (stackptr)]).reloc = reloc; |
1458 | 10.1k | PRIV (stackptr)++; |
1459 | 10.1k | if (PRIV (stackptr) >= STACKSIZE) |
1460 | 0 | { |
1461 | 0 | bfd_set_error (bfd_error_bad_value); |
1462 | 0 | _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr)); |
1463 | 0 | return false; |
1464 | 0 | } |
1465 | 10.1k | return true; |
1466 | 10.1k | } |
1467 | | |
1468 | | /* Pop value and section index. */ |
1469 | | |
1470 | | static bool |
1471 | | _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel) |
1472 | 8.57k | { |
1473 | 8.57k | if (PRIV (stackptr) == 0) |
1474 | 39 | { |
1475 | 39 | bfd_set_error (bfd_error_bad_value); |
1476 | 39 | _bfd_error_handler (_("stack underflow in _bfd_vms_pop")); |
1477 | 39 | return false; |
1478 | 39 | } |
1479 | 8.53k | PRIV (stackptr)--; |
1480 | 8.53k | *val = PRIV (stack[PRIV (stackptr)]).value; |
1481 | 8.53k | *rel = PRIV (stack[PRIV (stackptr)]).reloc; |
1482 | | |
1483 | 8.53k | vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel)); |
1484 | 8.53k | return true; |
1485 | 8.57k | } |
1486 | | |
1487 | | /* Routines to fill sections contents during tir/etir read. */ |
1488 | | |
1489 | | /* Initialize image buffer pointer to be filled. */ |
1490 | | |
1491 | | static void |
1492 | | image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info) |
1493 | 0 | { |
1494 | 0 | asection *sec; |
1495 | |
|
1496 | 0 | vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect)); |
1497 | |
|
1498 | 0 | if (PRIV (sections) == NULL) |
1499 | 0 | return; |
1500 | 0 | if (sect < 0 || sect >= (int) PRIV (section_count)) |
1501 | 0 | return; |
1502 | | |
1503 | 0 | sec = PRIV (sections)[sect]; |
1504 | |
|
1505 | 0 | if (info) |
1506 | 0 | { |
1507 | | /* Reading contents to an output bfd. */ |
1508 | |
|
1509 | 0 | if (sec->output_section == NULL) |
1510 | 0 | { |
1511 | | /* Section discarded. */ |
1512 | 0 | vms_debug2 ((5, " section %s discarded\n", sec->name)); |
1513 | | |
1514 | | /* This is not used. */ |
1515 | 0 | PRIV (image_section) = NULL; |
1516 | 0 | PRIV (image_offset) = 0; |
1517 | 0 | return; |
1518 | 0 | } |
1519 | 0 | PRIV (image_offset) = sec->output_offset + vma; |
1520 | 0 | PRIV (image_section) = sec->output_section; |
1521 | 0 | } |
1522 | 0 | else |
1523 | 0 | { |
1524 | 0 | PRIV (image_offset) = vma; |
1525 | 0 | PRIV (image_section) = sec; |
1526 | 0 | } |
1527 | 0 | } |
1528 | | |
1529 | | /* Increment image buffer pointer by offset. */ |
1530 | | |
1531 | | static void |
1532 | | image_inc_ptr (bfd *abfd, bfd_vma offset) |
1533 | 17 | { |
1534 | 17 | vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset)); |
1535 | | |
1536 | 17 | PRIV (image_offset) += offset; |
1537 | 17 | } |
1538 | | |
1539 | | /* Save current DST location counter under specified index. */ |
1540 | | |
1541 | | static bool |
1542 | | dst_define_location (bfd *abfd, unsigned int loc) |
1543 | 219 | { |
1544 | 219 | vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc)); |
1545 | | |
1546 | 219 | if (loc > 1 << 24) |
1547 | 1 | { |
1548 | | /* 16M entries ought to be plenty. */ |
1549 | 1 | bfd_set_error (bfd_error_bad_value); |
1550 | 1 | _bfd_error_handler (_("dst_define_location %u too large"), loc); |
1551 | 1 | return false; |
1552 | 1 | } |
1553 | | |
1554 | | /* Grow the ptr offset table if necessary. */ |
1555 | 218 | if (loc + 1 > PRIV (dst_ptr_offsets_count)) |
1556 | 23 | { |
1557 | 23 | PRIV (dst_ptr_offsets) |
1558 | 23 | = bfd_realloc_or_free (PRIV (dst_ptr_offsets), |
1559 | 23 | (loc + 1) * sizeof (unsigned int)); |
1560 | 23 | if (PRIV (dst_ptr_offsets) == NULL) |
1561 | 0 | return false; |
1562 | 23 | memset (PRIV (dst_ptr_offsets) + PRIV (dst_ptr_offsets_count), 0, |
1563 | 23 | (loc - PRIV (dst_ptr_offsets_count)) * sizeof (unsigned int)); |
1564 | 23 | PRIV (dst_ptr_offsets_count) = loc + 1; |
1565 | 23 | } |
1566 | | |
1567 | 218 | PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset); |
1568 | 218 | return true; |
1569 | 218 | } |
1570 | | |
1571 | | /* Restore saved DST location counter from specified index. */ |
1572 | | |
1573 | | static bool |
1574 | | dst_restore_location (bfd *abfd, unsigned int loc) |
1575 | 27 | { |
1576 | 27 | vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc)); |
1577 | | |
1578 | 27 | if (loc < PRIV (dst_ptr_offsets_count)) |
1579 | 26 | { |
1580 | 26 | PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc]; |
1581 | 26 | return true; |
1582 | 26 | } |
1583 | 1 | return false; |
1584 | 27 | } |
1585 | | |
1586 | | /* Retrieve saved DST location counter from specified index. */ |
1587 | | |
1588 | | static bool |
1589 | | dst_retrieve_location (bfd *abfd, bfd_vma *loc) |
1590 | 13 | { |
1591 | 13 | vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc)); |
1592 | | |
1593 | 13 | if (*loc < PRIV (dst_ptr_offsets_count)) |
1594 | 12 | { |
1595 | 12 | *loc = PRIV (dst_ptr_offsets)[*loc]; |
1596 | 12 | return true; |
1597 | 12 | } |
1598 | 1 | return false; |
1599 | 13 | } |
1600 | | |
1601 | | static asection * |
1602 | | image_write_section (bfd *abfd) |
1603 | 222 | { |
1604 | 222 | asection *sec = PRIV (image_section); |
1605 | | |
1606 | 222 | if ((sec->flags & SEC_IN_MEMORY) != 0 && sec->contents == NULL) |
1607 | 222 | return NULL; |
1608 | 0 | return sec; |
1609 | 222 | } |
1610 | | |
1611 | | /* Write multiple bytes to section image. */ |
1612 | | |
1613 | | static bool |
1614 | | image_write (bfd *abfd, unsigned char *ptr, size_t size) |
1615 | 201 | { |
1616 | 201 | asection *sec = image_write_section (abfd); |
1617 | | |
1618 | 201 | if (sec) |
1619 | 0 | { |
1620 | 0 | size_t off = PRIV (image_offset); |
1621 | | /* Check bounds. */ |
1622 | 0 | if (off > sec->size |
1623 | 0 | || size > sec->size - off) |
1624 | 0 | { |
1625 | 0 | bfd_set_error (bfd_error_bad_value); |
1626 | 0 | return false; |
1627 | 0 | } |
1628 | | |
1629 | | #if VMS_DEBUG |
1630 | | _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size, |
1631 | | (long) off); |
1632 | | #endif |
1633 | | |
1634 | 0 | if (sec->contents != NULL) |
1635 | 0 | memcpy (sec->contents + off, ptr, size); |
1636 | 0 | else |
1637 | 0 | { |
1638 | 0 | unsigned int i; |
1639 | 0 | for (i = 0; i < size; i++) |
1640 | 0 | if (ptr[i] != 0) |
1641 | 0 | { |
1642 | 0 | bfd_set_error (bfd_error_bad_value); |
1643 | 0 | return false; |
1644 | 0 | } |
1645 | 0 | } |
1646 | | #if VMS_DEBUG |
1647 | | _bfd_hexdump (9, ptr, size, 0); |
1648 | | #endif |
1649 | 0 | } |
1650 | | |
1651 | 201 | PRIV (image_offset) += size; |
1652 | 201 | return true; |
1653 | 201 | } |
1654 | | |
1655 | | /* Write byte to section image. */ |
1656 | | |
1657 | | static bool |
1658 | | image_write_b (bfd * abfd, unsigned int value) |
1659 | 10 | { |
1660 | 10 | unsigned char data[1]; |
1661 | | |
1662 | 10 | vms_debug2 ((6, "image_write_b (%02x)\n", (int) value)); |
1663 | | |
1664 | 10 | *data = value; |
1665 | | |
1666 | 10 | return image_write (abfd, data, sizeof (data)); |
1667 | 10 | } |
1668 | | |
1669 | | /* Write 2-byte word to image. */ |
1670 | | |
1671 | | static bool |
1672 | | image_write_w (bfd * abfd, unsigned int value) |
1673 | 1 | { |
1674 | 1 | unsigned char data[2]; |
1675 | | |
1676 | 1 | vms_debug2 ((6, "image_write_w (%04x)\n", (int) value)); |
1677 | | |
1678 | 1 | bfd_putl16 (value, data); |
1679 | 1 | return image_write (abfd, data, sizeof (data)); |
1680 | 1 | } |
1681 | | |
1682 | | /* Write 4-byte long to image. */ |
1683 | | |
1684 | | static bool |
1685 | | image_write_l (bfd * abfd, unsigned long value) |
1686 | 3 | { |
1687 | 3 | unsigned char data[4]; |
1688 | | |
1689 | 3 | vms_debug2 ((6, "image_write_l (%08lx)\n", value)); |
1690 | | |
1691 | 3 | bfd_putl32 (value, data); |
1692 | 3 | return image_write (abfd, data, sizeof (data)); |
1693 | 3 | } |
1694 | | |
1695 | | /* Write 8-byte quad to image. */ |
1696 | | |
1697 | | static bool |
1698 | | image_write_q (bfd * abfd, bfd_vma value) |
1699 | 70 | { |
1700 | 70 | unsigned char data[8]; |
1701 | | |
1702 | 70 | vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value)); |
1703 | | |
1704 | 70 | bfd_putl64 (value, data); |
1705 | 70 | return image_write (abfd, data, sizeof (data)); |
1706 | 70 | } |
1707 | | |
1708 | | static const char * |
1709 | | _bfd_vms_etir_name (int cmd) |
1710 | 29 | { |
1711 | 29 | switch (cmd) |
1712 | 29 | { |
1713 | 0 | case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL"; |
1714 | 0 | case ETIR__C_STA_LW: return "ETIR__C_STA_LW"; |
1715 | 0 | case ETIR__C_STA_QW: return "ETIR__C_STA_QW"; |
1716 | 0 | case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ"; |
1717 | 1 | case ETIR__C_STA_LI: return "ETIR__C_STA_LI"; |
1718 | 1 | case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD"; |
1719 | 2 | case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG"; |
1720 | 0 | case ETIR__C_STO_B: return "ETIR__C_STO_B"; |
1721 | 0 | case ETIR__C_STO_W: return "ETIR__C_STO_W"; |
1722 | 0 | case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL"; |
1723 | 0 | case ETIR__C_STO_CA: return "ETIR__C_STO_CA"; |
1724 | 3 | case ETIR__C_STO_RB: return "ETIR__C_STO_RB"; |
1725 | 1 | case ETIR__C_STO_AB: return "ETIR__C_STO_AB"; |
1726 | 0 | case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF"; |
1727 | 0 | case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM"; |
1728 | 0 | case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR"; |
1729 | 0 | case ETIR__C_STO_LW: return "ETIR__C_STO_LW"; |
1730 | 0 | case ETIR__C_STO_QW: return "ETIR__C_STO_QW"; |
1731 | 0 | case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW"; |
1732 | 1 | case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB"; |
1733 | 1 | case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL"; |
1734 | 1 | case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS"; |
1735 | 0 | case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD"; |
1736 | 0 | case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB"; |
1737 | 2 | case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV"; |
1738 | 2 | case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH"; |
1739 | 1 | case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT"; |
1740 | 1 | case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF"; |
1741 | 1 | case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT"; |
1742 | 1 | case ETIR__C_STC_LP: return "ETIR__C_STC_LP"; |
1743 | 3 | case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL"; |
1744 | 1 | case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA"; |
1745 | 1 | case ETIR__C_STC_PS: return "ETIR__C_STC_PS"; |
1746 | 1 | case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS"; |
1747 | 0 | case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL"; |
1748 | 1 | case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS"; |
1749 | 0 | case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL"; |
1750 | 1 | case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS"; |
1751 | 0 | case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL"; |
1752 | 1 | case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS"; |
1753 | 0 | case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL"; |
1754 | 0 | case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS"; |
1755 | 1 | case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL"; |
1756 | 0 | case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB"; |
1757 | 0 | case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB"; |
1758 | 0 | case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB"; |
1759 | 0 | case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC"; |
1760 | 0 | case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC"; |
1761 | 0 | case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL"; |
1762 | | |
1763 | 0 | default: |
1764 | | /* These names have not yet been added to this switch statement. */ |
1765 | 0 | _bfd_error_handler (_("unknown ETIR command %d"), cmd); |
1766 | 29 | } |
1767 | | |
1768 | 0 | return NULL; |
1769 | 29 | } |
1770 | | #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L) |
1771 | | |
1772 | | static void |
1773 | | _bfd_vms_get_value (bfd *abfd, |
1774 | | const unsigned char *ascic, |
1775 | | const unsigned char *max_ascic, |
1776 | | struct bfd_link_info *info, |
1777 | | bfd_vma *vma, |
1778 | | struct alpha_vms_link_hash_entry **hp) |
1779 | 1.62k | { |
1780 | 1.62k | char name[257]; |
1781 | 1.62k | unsigned int len; |
1782 | 1.62k | unsigned int i; |
1783 | 1.62k | struct alpha_vms_link_hash_entry *h; |
1784 | | |
1785 | | /* Not linking. Do not try to resolve the symbol. */ |
1786 | 1.62k | if (info == NULL) |
1787 | 1.62k | { |
1788 | 1.62k | *vma = 0; |
1789 | 1.62k | *hp = NULL; |
1790 | 1.62k | return; |
1791 | 1.62k | } |
1792 | | |
1793 | 0 | len = *ascic; |
1794 | 0 | if (ascic + len >= max_ascic) |
1795 | 0 | { |
1796 | 0 | _bfd_error_handler (_("corrupt vms value")); |
1797 | 0 | *vma = 0; |
1798 | 0 | *hp = NULL; |
1799 | 0 | return; |
1800 | 0 | } |
1801 | | |
1802 | 0 | for (i = 0; i < len; i++) |
1803 | 0 | name[i] = ascic[i + 1]; |
1804 | 0 | name[i] = 0; |
1805 | |
|
1806 | 0 | h = (struct alpha_vms_link_hash_entry *) |
1807 | 0 | bfd_link_hash_lookup (info->hash, name, false, false, true); |
1808 | |
|
1809 | 0 | *hp = h; |
1810 | |
|
1811 | 0 | if (h != NULL |
1812 | 0 | && (h->root.type == bfd_link_hash_defined |
1813 | 0 | || h->root.type == bfd_link_hash_defweak)) |
1814 | 0 | *vma = h->root.u.def.value |
1815 | 0 | + h->root.u.def.section->output_offset |
1816 | 0 | + h->root.u.def.section->output_section->vma; |
1817 | 0 | else if (h && h->root.type == bfd_link_hash_undefweak) |
1818 | 0 | *vma = 0; |
1819 | 0 | else |
1820 | 0 | { |
1821 | 0 | (*info->callbacks->undefined_symbol) |
1822 | 0 | (info, name, abfd, PRIV (image_section), PRIV (image_offset), true); |
1823 | 0 | *vma = 0; |
1824 | 0 | } |
1825 | 0 | } |
1826 | | |
1827 | 42.6k | #define RELC_NONE 0 |
1828 | 0 | #define RELC_REL 1 |
1829 | 29 | #define RELC_SHR_BASE 0x10000 |
1830 | 99 | #define RELC_SEC_BASE 0x20000 |
1831 | 0 | #define RELC_MASK 0x0ffff |
1832 | | |
1833 | | static unsigned int |
1834 | | alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h) |
1835 | 1.58k | { |
1836 | | /* Handle undefined symbols. */ |
1837 | 1.58k | if (h == NULL || h->sym == NULL) |
1838 | 1.58k | return RELC_NONE; |
1839 | | |
1840 | 0 | if (h->sym->typ == EGSD__C_SYMG) |
1841 | 0 | { |
1842 | 0 | if (h->sym->flags & EGSY__V_REL) |
1843 | 0 | return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index); |
1844 | 0 | else |
1845 | 0 | { |
1846 | | /* Can this happen (non-relocatable symg) ? I'd like to see |
1847 | | an example. */ |
1848 | 0 | abort (); |
1849 | 0 | } |
1850 | 0 | } |
1851 | 0 | if (h->sym->typ == EGSD__C_SYM) |
1852 | 0 | { |
1853 | 0 | if (h->sym->flags & EGSY__V_REL) |
1854 | 0 | return RELC_REL; |
1855 | 0 | else |
1856 | 0 | return RELC_NONE; |
1857 | 0 | } |
1858 | 0 | abort (); |
1859 | 0 | } |
1860 | | |
1861 | | static bfd_vma |
1862 | | alpha_vms_get_sym_value (asection *sect, bfd_vma addr) |
1863 | 0 | { |
1864 | 0 | return sect->output_section->vma + sect->output_offset + addr; |
1865 | 0 | } |
1866 | | |
1867 | | static bfd_vma |
1868 | | alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info, |
1869 | | unsigned int rel, bfd_vma vma) |
1870 | 0 | { |
1871 | 0 | asection *sec; |
1872 | 0 | unsigned int sec_indx; |
1873 | |
|
1874 | 0 | if (PRIV (sections) == NULL) |
1875 | 0 | return 0; |
1876 | | |
1877 | 0 | sec_indx = rel & RELC_MASK; |
1878 | 0 | if (sec_indx >= PRIV (section_count)) |
1879 | 0 | return 0; |
1880 | | |
1881 | 0 | sec = PRIV (sections)[sec_indx]; |
1882 | |
|
1883 | 0 | if (info) |
1884 | 0 | { |
1885 | 0 | if (sec->output_section == NULL) |
1886 | 0 | abort (); |
1887 | 0 | return vma + sec->output_section->vma + sec->output_offset; |
1888 | 0 | } |
1889 | 0 | else |
1890 | 0 | return vma + sec->vma; |
1891 | 0 | } |
1892 | | |
1893 | | /* Read an ETIR record from ABFD. If INFO is not null, put the content into |
1894 | | the output section (used during linking). |
1895 | | Return FALSE in case of error. */ |
1896 | | |
1897 | | static bool |
1898 | | _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info) |
1899 | 12.5k | { |
1900 | 12.5k | unsigned char *ptr; |
1901 | 12.5k | unsigned int length; |
1902 | 12.5k | unsigned char *maxptr; |
1903 | 12.5k | bfd_vma op1 = 0; |
1904 | 12.5k | bfd_vma op2 = 0; |
1905 | 12.5k | unsigned int rel1 = RELC_NONE; |
1906 | 12.5k | unsigned int rel2 = RELC_NONE; |
1907 | 12.5k | struct alpha_vms_link_hash_entry *h; |
1908 | | |
1909 | 12.5k | PRIV (recrd.rec) += ETIR__C_HEADER_SIZE; |
1910 | 12.5k | PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE; |
1911 | | |
1912 | 12.5k | ptr = PRIV (recrd.rec); |
1913 | 12.5k | length = PRIV (recrd.rec_size); |
1914 | 12.5k | maxptr = ptr + length; |
1915 | | |
1916 | 12.5k | vms_debug2 ((2, "ETIR: %d bytes\n", length)); |
1917 | | |
1918 | 25.1k | while (ptr < maxptr) |
1919 | 12.8k | { |
1920 | 12.8k | unsigned int cmd, cmd_length; |
1921 | | |
1922 | 12.8k | if (ptr + 4 > maxptr) |
1923 | 21 | goto corrupt_etir; |
1924 | | |
1925 | 12.8k | cmd = bfd_getl16 (ptr); |
1926 | 12.8k | cmd_length = bfd_getl16 (ptr + 2); |
1927 | | |
1928 | | /* PR 21589 and 21579: Check for a corrupt ETIR record. */ |
1929 | 12.8k | if (cmd_length < 4 || cmd_length > (size_t) (maxptr - ptr)) |
1930 | 54 | { |
1931 | 88 | corrupt_etir: |
1932 | 88 | _bfd_error_handler (_("corrupt ETIR record encountered")); |
1933 | 88 | bfd_set_error (bfd_error_bad_value); |
1934 | 88 | return false; |
1935 | 54 | } |
1936 | 12.7k | ptr += 4; |
1937 | 12.7k | cmd_length -= 4; |
1938 | | |
1939 | | #if VMS_DEBUG |
1940 | | _bfd_vms_debug (4, "etir: %s(%d)\n", |
1941 | | _bfd_vms_etir_name (cmd), cmd); |
1942 | | _bfd_hexdump (8, ptr, cmd_length, 0); |
1943 | | #endif |
1944 | | |
1945 | 12.7k | switch (cmd) |
1946 | 12.7k | { |
1947 | | /* Stack global |
1948 | | arg: cs symbol name |
1949 | | |
1950 | | stack 32 bit value of symbol (high bits set to 0). */ |
1951 | 1.58k | case ETIR__C_STA_GBL: |
1952 | 1.58k | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
1953 | 1.58k | if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h))) |
1954 | 0 | return false; |
1955 | 1.58k | break; |
1956 | | |
1957 | | /* Stack longword |
1958 | | arg: lw value |
1959 | | |
1960 | | stack 32 bit value, sign extend to 64 bit. */ |
1961 | 3.74k | case ETIR__C_STA_LW: |
1962 | 3.74k | if (cmd_length < 4) |
1963 | 1 | goto corrupt_etir; |
1964 | 3.74k | if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE)) |
1965 | 0 | return false; |
1966 | 3.74k | break; |
1967 | | |
1968 | | /* Stack quadword |
1969 | | arg: qw value |
1970 | | |
1971 | | stack 64 bit value of symbol. */ |
1972 | 3.74k | case ETIR__C_STA_QW: |
1973 | 1.55k | if (cmd_length < 8) |
1974 | 1 | goto corrupt_etir; |
1975 | 1.55k | if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE)) |
1976 | 0 | return false; |
1977 | 1.55k | break; |
1978 | | |
1979 | | /* Stack psect base plus quadword offset |
1980 | | arg: lw section index |
1981 | | qw signed quadword offset (low 32 bits) |
1982 | | |
1983 | | Stack qw argument and section index |
1984 | | (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */ |
1985 | 1.55k | case ETIR__C_STA_PQ: |
1986 | 1 | { |
1987 | 1 | int psect; |
1988 | | |
1989 | 1 | if (cmd_length < 12) |
1990 | 1 | goto corrupt_etir; |
1991 | 0 | psect = bfd_getl32 (ptr); |
1992 | 0 | if ((unsigned int) psect >= PRIV (section_count)) |
1993 | 0 | { |
1994 | 0 | _bfd_error_handler (_("bad section index in %s"), |
1995 | 0 | _bfd_vms_etir_name (cmd)); |
1996 | 0 | bfd_set_error (bfd_error_bad_value); |
1997 | 0 | return false; |
1998 | 0 | } |
1999 | 0 | op1 = bfd_getl64 (ptr + 4); |
2000 | 0 | if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE)) |
2001 | 0 | return false; |
2002 | 0 | } |
2003 | 0 | break; |
2004 | | |
2005 | 1 | case ETIR__C_STA_LI: |
2006 | 2 | case ETIR__C_STA_MOD: |
2007 | 4 | case ETIR__C_STA_CKARG: |
2008 | 4 | _bfd_error_handler (_("unsupported STA cmd %s"), |
2009 | 4 | _bfd_vms_etir_name (cmd)); |
2010 | 4 | return false; |
2011 | 0 | break; |
2012 | | |
2013 | | /* Store byte: pop stack, write byte |
2014 | | arg: -. */ |
2015 | 13 | case ETIR__C_STO_B: |
2016 | 13 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2017 | 3 | return false; |
2018 | 10 | if (rel1 != RELC_NONE) |
2019 | 0 | goto bad_context; |
2020 | 10 | if (!image_write_b (abfd, (unsigned int) op1 & 0xff)) |
2021 | 0 | return false; |
2022 | 10 | break; |
2023 | | |
2024 | | /* Store word: pop stack, write word |
2025 | | arg: -. */ |
2026 | 10 | case ETIR__C_STO_W: |
2027 | 4 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2028 | 3 | return false; |
2029 | 1 | if (rel1 != RELC_NONE) |
2030 | 0 | goto bad_context; |
2031 | 1 | if (!image_write_w (abfd, (unsigned int) op1 & 0xffff)) |
2032 | 0 | return false; |
2033 | 1 | break; |
2034 | | |
2035 | | /* Store longword: pop stack, write longword |
2036 | | arg: -. */ |
2037 | 4 | case ETIR__C_STO_LW: |
2038 | 4 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2039 | 3 | return false; |
2040 | 1 | if (rel1 & RELC_SEC_BASE) |
2041 | 0 | { |
2042 | 0 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); |
2043 | 0 | rel1 = RELC_REL; |
2044 | 0 | } |
2045 | 1 | else if (rel1 & RELC_SHR_BASE) |
2046 | 0 | { |
2047 | 0 | if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1)) |
2048 | 0 | return false; |
2049 | 0 | rel1 = RELC_NONE; |
2050 | 0 | } |
2051 | 1 | if (rel1 != RELC_NONE) |
2052 | 0 | { |
2053 | 0 | if (rel1 != RELC_REL) |
2054 | 0 | abort (); |
2055 | 0 | if (!alpha_vms_add_lw_reloc (info)) |
2056 | 0 | return false; |
2057 | 0 | } |
2058 | 1 | if (!image_write_l (abfd, op1)) |
2059 | 0 | return false; |
2060 | 1 | break; |
2061 | | |
2062 | | /* Store quadword: pop stack, write quadword |
2063 | | arg: -. */ |
2064 | 31 | case ETIR__C_STO_QW: |
2065 | 31 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2066 | 3 | return false; |
2067 | 28 | if (rel1 & RELC_SEC_BASE) |
2068 | 0 | { |
2069 | 0 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); |
2070 | 0 | rel1 = RELC_REL; |
2071 | 0 | } |
2072 | 28 | else if (rel1 & RELC_SHR_BASE) |
2073 | 0 | abort (); |
2074 | 28 | if (rel1 != RELC_NONE) |
2075 | 0 | { |
2076 | 0 | if (rel1 != RELC_REL) |
2077 | 0 | abort (); |
2078 | 0 | if (!alpha_vms_add_qw_reloc (info)) |
2079 | 0 | return false; |
2080 | 0 | } |
2081 | 28 | if (!image_write_q (abfd, op1)) |
2082 | 0 | return false; |
2083 | 28 | break; |
2084 | | |
2085 | | /* Store immediate repeated: pop stack for repeat count |
2086 | | arg: lw byte count |
2087 | | da data. */ |
2088 | 77 | case ETIR__C_STO_IMMR: |
2089 | 77 | { |
2090 | 77 | size_t size; |
2091 | | |
2092 | 77 | if (cmd_length < 4) |
2093 | 1 | goto corrupt_etir; |
2094 | 76 | size = bfd_getl32 (ptr); |
2095 | 76 | if (size > cmd_length - 4) |
2096 | 4 | goto corrupt_etir; |
2097 | 72 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2098 | 0 | return false; |
2099 | 72 | if (rel1 != RELC_NONE) |
2100 | 0 | goto bad_context; |
2101 | 72 | if (size == 0) |
2102 | 51 | break; |
2103 | 21 | op1 &= 0xffffffff; |
2104 | 21 | if (!image_write_section (abfd)) |
2105 | 21 | { |
2106 | | /* We are just sizing. Optimise a little. */ |
2107 | 21 | size *= op1; |
2108 | 21 | op1 = 1; |
2109 | 21 | } |
2110 | 42 | while (op1-- > 0) |
2111 | 21 | if (!image_write (abfd, ptr + 4, size)) |
2112 | 0 | return false; |
2113 | 21 | } |
2114 | 21 | break; |
2115 | | |
2116 | | /* Store global: write symbol value |
2117 | | arg: cs global symbol name. */ |
2118 | 33 | case ETIR__C_STO_GBL: |
2119 | 33 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
2120 | 33 | if (h && h->sym) |
2121 | 0 | { |
2122 | 0 | if (h->sym->typ == EGSD__C_SYMG) |
2123 | 0 | { |
2124 | 0 | if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner, |
2125 | 0 | h->sym->symbol_vector)) |
2126 | 0 | return false; |
2127 | 0 | op1 = 0; |
2128 | 0 | } |
2129 | 0 | else |
2130 | 0 | { |
2131 | 0 | op1 = alpha_vms_get_sym_value (h->sym->section, |
2132 | 0 | h->sym->value); |
2133 | 0 | if (!alpha_vms_add_qw_reloc (info)) |
2134 | 0 | return false; |
2135 | 0 | } |
2136 | 0 | } |
2137 | 33 | if (!image_write_q (abfd, op1)) |
2138 | 0 | return false; |
2139 | 33 | break; |
2140 | | |
2141 | | /* Store code address: write address of entry point |
2142 | | arg: cs global symbol name (procedure). */ |
2143 | 33 | case ETIR__C_STO_CA: |
2144 | 7 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
2145 | 7 | if (h && h->sym) |
2146 | 0 | { |
2147 | 0 | if (h->sym->flags & EGSY__V_NORM) |
2148 | 0 | { |
2149 | | /* That's really a procedure. */ |
2150 | 0 | if (h->sym->typ == EGSD__C_SYMG) |
2151 | 0 | { |
2152 | 0 | if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner)) |
2153 | 0 | return false; |
2154 | 0 | op1 = h->sym->symbol_vector; |
2155 | 0 | } |
2156 | 0 | else |
2157 | 0 | { |
2158 | 0 | op1 = alpha_vms_get_sym_value (h->sym->code_section, |
2159 | 0 | h->sym->code_value); |
2160 | 0 | if (!alpha_vms_add_qw_reloc (info)) |
2161 | 0 | return false; |
2162 | 0 | } |
2163 | 0 | } |
2164 | 0 | else |
2165 | 0 | { |
2166 | | /* Symbol is not a procedure. */ |
2167 | 0 | abort (); |
2168 | 0 | } |
2169 | 0 | } |
2170 | 7 | if (!image_write_q (abfd, op1)) |
2171 | 0 | return false; |
2172 | 7 | break; |
2173 | | |
2174 | | /* Store offset to psect: pop stack, add low 32 bits to base of psect |
2175 | | arg: none. */ |
2176 | 7 | case ETIR__C_STO_OFF: |
2177 | 1 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2178 | 1 | return false; |
2179 | | |
2180 | 0 | if (!(rel1 & RELC_SEC_BASE)) |
2181 | 0 | abort (); |
2182 | | |
2183 | 0 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); |
2184 | 0 | rel1 = RELC_REL; |
2185 | 0 | if (!image_write_q (abfd, op1)) |
2186 | 0 | return false; |
2187 | 0 | break; |
2188 | | |
2189 | | /* Store immediate |
2190 | | arg: lw count of bytes |
2191 | | da data. */ |
2192 | 99 | case ETIR__C_STO_IMM: |
2193 | 99 | { |
2194 | 99 | unsigned int size; |
2195 | | |
2196 | 99 | if (cmd_length < 4) |
2197 | 1 | goto corrupt_etir; |
2198 | 98 | size = bfd_getl32 (ptr); |
2199 | 98 | if (size > cmd_length - 4) |
2200 | 2 | goto corrupt_etir; |
2201 | 96 | if (!image_write (abfd, ptr + 4, size)) |
2202 | 0 | return false; |
2203 | 96 | } |
2204 | 96 | break; |
2205 | | |
2206 | | /* This code is 'reserved to digital' according to the openVMS |
2207 | | linker manual, however it is generated by the DEC C compiler |
2208 | | and defined in the include file. |
2209 | | FIXME, since the following is just a guess |
2210 | | store global longword: store 32bit value of symbol |
2211 | | arg: cs symbol name. */ |
2212 | 96 | case ETIR__C_STO_GBL_LW: |
2213 | 2 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
2214 | | #if 0 |
2215 | | abort (); |
2216 | | #endif |
2217 | 2 | if (!image_write_l (abfd, op1)) |
2218 | 0 | return false; |
2219 | 2 | break; |
2220 | | |
2221 | 3 | case ETIR__C_STO_RB: |
2222 | 4 | case ETIR__C_STO_AB: |
2223 | 5 | case ETIR__C_STO_LP_PSB: |
2224 | 5 | _bfd_error_handler (_("%s: not supported"), |
2225 | 5 | _bfd_vms_etir_name (cmd)); |
2226 | 5 | return false; |
2227 | 0 | break; |
2228 | 1 | case ETIR__C_STO_HINT_GBL: |
2229 | 2 | case ETIR__C_STO_HINT_PS: |
2230 | 2 | _bfd_error_handler (_("%s: not implemented"), |
2231 | 2 | _bfd_vms_etir_name (cmd)); |
2232 | 2 | return false; |
2233 | 0 | break; |
2234 | | |
2235 | | /* 200 Store-conditional Linkage Pair |
2236 | | arg: none. */ |
2237 | 1 | case ETIR__C_STC_LP: |
2238 | | |
2239 | | /* 202 Store-conditional Address at global address |
2240 | | lw linkage index |
2241 | | cs global name. */ |
2242 | | |
2243 | 4 | case ETIR__C_STC_GBL: |
2244 | | |
2245 | | /* 203 Store-conditional Code Address at global address |
2246 | | lw linkage index |
2247 | | cs procedure name. */ |
2248 | 5 | case ETIR__C_STC_GCA: |
2249 | | |
2250 | | /* 204 Store-conditional Address at psect + offset |
2251 | | lw linkage index |
2252 | | lw psect index |
2253 | | qw offset. */ |
2254 | 6 | case ETIR__C_STC_PS: |
2255 | 6 | _bfd_error_handler (_("%s: not supported"), |
2256 | 6 | _bfd_vms_etir_name (cmd)); |
2257 | 6 | return false; |
2258 | 0 | break; |
2259 | | |
2260 | | /* 201 Store-conditional Linkage Pair with Procedure Signature |
2261 | | lw linkage index |
2262 | | cs procedure name |
2263 | | by signature length |
2264 | | da signature. */ |
2265 | | |
2266 | 2 | case ETIR__C_STC_LP_PSB: |
2267 | 2 | if (cmd_length < 4) |
2268 | 1 | goto corrupt_etir; |
2269 | 1 | _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h); |
2270 | 1 | if (h && h->sym) |
2271 | 0 | { |
2272 | 0 | if (h->sym->typ == EGSD__C_SYMG) |
2273 | 0 | { |
2274 | 0 | if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner)) |
2275 | 0 | return false; |
2276 | 0 | op1 = h->sym->symbol_vector; |
2277 | 0 | op2 = 0; |
2278 | 0 | } |
2279 | 0 | else |
2280 | 0 | { |
2281 | 0 | op1 = alpha_vms_get_sym_value (h->sym->code_section, |
2282 | 0 | h->sym->code_value); |
2283 | 0 | op2 = alpha_vms_get_sym_value (h->sym->section, |
2284 | 0 | h->sym->value); |
2285 | 0 | } |
2286 | 0 | } |
2287 | 1 | else |
2288 | 1 | { |
2289 | | /* Undefined symbol. */ |
2290 | 1 | op1 = 0; |
2291 | 1 | op2 = 0; |
2292 | 1 | } |
2293 | 1 | if (!image_write_q (abfd, op1) |
2294 | 1 | || !image_write_q (abfd, op2)) |
2295 | 0 | return false; |
2296 | 1 | break; |
2297 | | |
2298 | | /* 205 Store-conditional NOP at address of global |
2299 | | arg: none. */ |
2300 | 45 | case ETIR__C_STC_NOP_GBL: |
2301 | | /* ALPHA_R_NOP */ |
2302 | | |
2303 | | /* 207 Store-conditional BSR at global address |
2304 | | arg: none. */ |
2305 | | |
2306 | 610 | case ETIR__C_STC_BSR_GBL: |
2307 | | /* ALPHA_R_BSR */ |
2308 | | |
2309 | | /* 209 Store-conditional LDA at global address |
2310 | | arg: none. */ |
2311 | | |
2312 | 633 | case ETIR__C_STC_LDA_GBL: |
2313 | | /* ALPHA_R_LDA */ |
2314 | | |
2315 | | /* 211 Store-conditional BSR or Hint at global address |
2316 | | arg: none. */ |
2317 | | |
2318 | 1.49k | case ETIR__C_STC_BOH_GBL: |
2319 | | /* Currentl ignored. */ |
2320 | 1.49k | break; |
2321 | | |
2322 | | /* 213 Store-conditional NOP,BSR or HINT at global address |
2323 | | arg: none. */ |
2324 | | |
2325 | 1 | case ETIR__C_STC_NBH_GBL: |
2326 | | |
2327 | | /* 206 Store-conditional NOP at pect + offset |
2328 | | arg: none. */ |
2329 | | |
2330 | 2 | case ETIR__C_STC_NOP_PS: |
2331 | | |
2332 | | /* 208 Store-conditional BSR at pect + offset |
2333 | | arg: none. */ |
2334 | | |
2335 | 3 | case ETIR__C_STC_BSR_PS: |
2336 | | |
2337 | | /* 210 Store-conditional LDA at psect + offset |
2338 | | arg: none. */ |
2339 | | |
2340 | 4 | case ETIR__C_STC_LDA_PS: |
2341 | | |
2342 | | /* 212 Store-conditional BSR or Hint at pect + offset |
2343 | | arg: none. */ |
2344 | | |
2345 | 4 | case ETIR__C_STC_BOH_PS: |
2346 | | |
2347 | | /* 214 Store-conditional NOP, BSR or HINT at psect + offset |
2348 | | arg: none. */ |
2349 | 5 | case ETIR__C_STC_NBH_PS: |
2350 | 5 | _bfd_error_handler (_("%s: not supported"), |
2351 | 5 | _bfd_vms_etir_name (cmd)); |
2352 | 5 | return false; |
2353 | 0 | break; |
2354 | | |
2355 | | /* Det relocation base: pop stack, set image location counter |
2356 | | arg: none. */ |
2357 | 1 | case ETIR__C_CTL_SETRB: |
2358 | 1 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2359 | 1 | return false; |
2360 | 0 | if (!(rel1 & RELC_SEC_BASE)) |
2361 | 0 | abort (); |
2362 | 0 | image_set_ptr (abfd, op1, rel1 & RELC_MASK, info); |
2363 | 0 | break; |
2364 | | |
2365 | | /* Augment relocation base: increment image location counter by offset |
2366 | | arg: lw offset value. */ |
2367 | 18 | case ETIR__C_CTL_AUGRB: |
2368 | 18 | if (cmd_length < 4) |
2369 | 1 | goto corrupt_etir; |
2370 | 17 | op1 = bfd_getl32 (ptr); |
2371 | 17 | image_inc_ptr (abfd, op1); |
2372 | 17 | break; |
2373 | | |
2374 | | /* Define location: pop index, save location counter under index |
2375 | | arg: none. */ |
2376 | 220 | case ETIR__C_CTL_DFLOC: |
2377 | 220 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2378 | 1 | return false; |
2379 | 219 | if (rel1 != RELC_NONE) |
2380 | 0 | goto bad_context; |
2381 | 219 | if (!dst_define_location (abfd, op1)) |
2382 | 1 | return false; |
2383 | 218 | break; |
2384 | | |
2385 | | /* Set location: pop index, restore location counter from index |
2386 | | arg: none. */ |
2387 | 218 | case ETIR__C_CTL_STLOC: |
2388 | 28 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2389 | 1 | return false; |
2390 | 27 | if (rel1 != RELC_NONE) |
2391 | 0 | goto bad_context; |
2392 | 27 | if (!dst_restore_location (abfd, op1)) |
2393 | 1 | { |
2394 | 1 | bfd_set_error (bfd_error_bad_value); |
2395 | 1 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC"); |
2396 | 1 | return false; |
2397 | 1 | } |
2398 | 26 | break; |
2399 | | |
2400 | | /* Stack defined location: pop index, push location counter from index |
2401 | | arg: none. */ |
2402 | 26 | case ETIR__C_CTL_STKDL: |
2403 | 14 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2404 | 1 | return false; |
2405 | 13 | if (rel1 != RELC_NONE) |
2406 | 0 | goto bad_context; |
2407 | 13 | if (!dst_retrieve_location (abfd, &op1)) |
2408 | 1 | { |
2409 | 1 | bfd_set_error (bfd_error_bad_value); |
2410 | 1 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL"); |
2411 | 1 | return false; |
2412 | 1 | } |
2413 | 12 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) |
2414 | 0 | return false; |
2415 | 12 | break; |
2416 | | |
2417 | 28 | case ETIR__C_OPR_NOP: /* No-op. */ |
2418 | 28 | break; |
2419 | | |
2420 | 53 | case ETIR__C_OPR_ADD: /* Add. */ |
2421 | 53 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2422 | 52 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2423 | 2 | return false; |
2424 | 51 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2425 | 0 | rel1 = rel2; |
2426 | 51 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) |
2427 | 0 | goto bad_context; |
2428 | 51 | if (!_bfd_vms_push (abfd, op1 + op2, rel1)) |
2429 | 0 | return false; |
2430 | 51 | break; |
2431 | | |
2432 | 72 | case ETIR__C_OPR_SUB: /* Subtract. */ |
2433 | 72 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2434 | 71 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2435 | 2 | return false; |
2436 | 70 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2437 | 0 | rel1 = rel2; |
2438 | 70 | else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE)) |
2439 | 0 | { |
2440 | 0 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); |
2441 | 0 | op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2); |
2442 | 0 | rel1 = RELC_NONE; |
2443 | 0 | } |
2444 | 70 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) |
2445 | 0 | goto bad_context; |
2446 | 70 | if (!_bfd_vms_push (abfd, op2 - op1, rel1)) |
2447 | 0 | return false; |
2448 | 70 | break; |
2449 | | |
2450 | 70 | case ETIR__C_OPR_MUL: /* Multiply. */ |
2451 | 4 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2452 | 3 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2453 | 2 | return false; |
2454 | 2 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2455 | 0 | goto bad_context; |
2456 | 2 | if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE)) |
2457 | 0 | return false; |
2458 | 2 | break; |
2459 | | |
2460 | 2.33k | case ETIR__C_OPR_DIV: /* Divide. */ |
2461 | 2.33k | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2462 | 2.33k | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2463 | 0 | return false; |
2464 | 2.33k | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2465 | 0 | goto bad_context; |
2466 | 2.33k | if (op1 == 0) |
2467 | 770 | { |
2468 | | /* Divide by zero is supposed to give a result of zero, |
2469 | | and a non-fatal warning message. */ |
2470 | 770 | _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV"); |
2471 | 770 | if (!_bfd_vms_push (abfd, 0, RELC_NONE)) |
2472 | 0 | return false; |
2473 | 770 | } |
2474 | 1.56k | else |
2475 | 1.56k | { |
2476 | 1.56k | if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE)) |
2477 | 0 | return false; |
2478 | 1.56k | } |
2479 | 2.33k | break; |
2480 | | |
2481 | 2.33k | case ETIR__C_OPR_AND: /* Logical AND. */ |
2482 | 30 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2483 | 29 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2484 | 2 | return false; |
2485 | 28 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2486 | 0 | goto bad_context; |
2487 | 28 | if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE)) |
2488 | 0 | return false; |
2489 | 28 | break; |
2490 | | |
2491 | 28 | case ETIR__C_OPR_IOR: /* Logical inclusive OR. */ |
2492 | 24 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2493 | 22 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2494 | 4 | return false; |
2495 | 20 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2496 | 0 | goto bad_context; |
2497 | 20 | if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE)) |
2498 | 0 | return false; |
2499 | 20 | break; |
2500 | | |
2501 | 20 | case ETIR__C_OPR_EOR: /* Logical exclusive OR. */ |
2502 | 10 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2503 | 9 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2504 | 3 | return false; |
2505 | 7 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2506 | 0 | goto bad_context; |
2507 | 7 | if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE)) |
2508 | 0 | return false; |
2509 | 7 | break; |
2510 | | |
2511 | 7 | case ETIR__C_OPR_NEG: /* Negate. */ |
2512 | 3 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2513 | 0 | return false; |
2514 | 3 | if (rel1 != RELC_NONE) |
2515 | 0 | goto bad_context; |
2516 | 3 | if (!_bfd_vms_push (abfd, -op1, RELC_NONE)) |
2517 | 0 | return false; |
2518 | 3 | break; |
2519 | | |
2520 | 26 | case ETIR__C_OPR_COM: /* Complement. */ |
2521 | 26 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2522 | 1 | return false; |
2523 | 25 | if (rel1 != RELC_NONE) |
2524 | 0 | goto bad_context; |
2525 | 25 | if (!_bfd_vms_push (abfd, ~op1, RELC_NONE)) |
2526 | 0 | return false; |
2527 | 25 | break; |
2528 | | |
2529 | 25 | case ETIR__C_OPR_ASH: /* Arithmetic shift. */ |
2530 | 22 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2531 | 21 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2532 | 2 | return false; |
2533 | 20 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2534 | 0 | { |
2535 | 0 | bad_context: |
2536 | 0 | _bfd_error_handler (_("invalid use of %s with contexts"), |
2537 | 0 | _bfd_vms_etir_name (cmd)); |
2538 | 0 | return false; |
2539 | 0 | } |
2540 | 20 | if ((bfd_signed_vma) op2 < 0) |
2541 | 2 | { |
2542 | | /* Shift right. */ |
2543 | 2 | bfd_vma sign; |
2544 | 2 | op2 = -op2; |
2545 | 2 | if (op2 >= CHAR_BIT * sizeof (op1)) |
2546 | 1 | op2 = CHAR_BIT * sizeof (op1) - 1; |
2547 | | /* op1 = (bfd_signed_vma) op1 >> op2; */ |
2548 | 2 | sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1)); |
2549 | 2 | op1 >>= op2; |
2550 | 2 | sign >>= op2; |
2551 | 2 | op1 = (op1 ^ sign) - sign; |
2552 | 2 | } |
2553 | 18 | else |
2554 | 18 | { |
2555 | | /* Shift left. */ |
2556 | 18 | if (op2 >= CHAR_BIT * sizeof (op1)) |
2557 | 9 | op1 = 0; |
2558 | 9 | else |
2559 | 9 | op1 <<= op2; |
2560 | 18 | } |
2561 | 20 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym. */ |
2562 | 0 | return false; |
2563 | 20 | break; |
2564 | | |
2565 | 20 | case ETIR__C_OPR_INSV: /* Insert field. */ |
2566 | 4 | case ETIR__C_OPR_USH: /* Unsigned shift. */ |
2567 | 5 | case ETIR__C_OPR_ROT: /* Rotate. */ |
2568 | 6 | case ETIR__C_OPR_REDEF: /* Redefine symbol to current location. */ |
2569 | 7 | case ETIR__C_OPR_DFLIT: /* Define a literal. */ |
2570 | 7 | _bfd_error_handler (_("%s: not supported"), |
2571 | 7 | _bfd_vms_etir_name (cmd)); |
2572 | 7 | return false; |
2573 | 0 | break; |
2574 | | |
2575 | 1.18k | case ETIR__C_OPR_SEL: /* Select. */ |
2576 | 1.18k | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2577 | 1 | return false; |
2578 | 1.18k | if (op1 & 0x01L) |
2579 | 487 | { |
2580 | 487 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2581 | 1 | return false; |
2582 | 487 | } |
2583 | 695 | else |
2584 | 695 | { |
2585 | 695 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2586 | 694 | || !_bfd_vms_pop (abfd, &op2, &rel2)) |
2587 | 2 | return false; |
2588 | 693 | if (!_bfd_vms_push (abfd, op1, rel1)) |
2589 | 0 | return false; |
2590 | 693 | } |
2591 | 1.17k | break; |
2592 | | |
2593 | 1.17k | default: |
2594 | 10 | _bfd_error_handler (_("reserved cmd %d"), cmd); |
2595 | 10 | return false; |
2596 | 0 | break; |
2597 | 12.7k | } |
2598 | | |
2599 | 12.6k | ptr += cmd_length; |
2600 | 12.6k | } |
2601 | | |
2602 | 12.3k | return true; |
2603 | 12.5k | } |
2604 | | |
2605 | | /* Process EDBG/ETBT record. |
2606 | | Return TRUE on success, FALSE on error */ |
2607 | | |
2608 | | static bool |
2609 | | vms_slurp_debug (bfd *abfd) |
2610 | 12.5k | { |
2611 | 12.5k | asection *section = PRIV (dst_section); |
2612 | | |
2613 | 12.5k | if (section == NULL) |
2614 | 329 | { |
2615 | | /* We have no way to find out beforehand how much debug info there |
2616 | | is in an object file, so pick an initial amount and grow it as |
2617 | | needed later. */ |
2618 | 329 | flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC |
2619 | 329 | | SEC_IN_MEMORY; |
2620 | | |
2621 | 329 | section = bfd_make_section (abfd, "$DST$"); |
2622 | 329 | if (!section) |
2623 | 0 | return false; |
2624 | 329 | if (!bfd_set_section_flags (section, flags)) |
2625 | 0 | return false; |
2626 | 329 | PRIV (dst_section) = section; |
2627 | 329 | } |
2628 | | |
2629 | 12.5k | PRIV (image_section) = section; |
2630 | 12.5k | PRIV (image_offset) = section->size; |
2631 | | |
2632 | 12.5k | if (!_bfd_vms_slurp_etir (abfd, NULL)) |
2633 | 169 | return false; |
2634 | | |
2635 | 12.3k | section->size = PRIV (image_offset); |
2636 | 12.3k | return true; |
2637 | 12.5k | } |
2638 | | |
2639 | | /* Process EDBG record. |
2640 | | Return TRUE on success, FALSE on error. */ |
2641 | | |
2642 | | static bool |
2643 | | _bfd_vms_slurp_edbg (bfd *abfd) |
2644 | 8.97k | { |
2645 | 8.97k | vms_debug2 ((2, "EDBG\n")); |
2646 | | |
2647 | 8.97k | abfd->flags |= HAS_DEBUG | HAS_LINENO; |
2648 | | |
2649 | 8.97k | return vms_slurp_debug (abfd); |
2650 | 8.97k | } |
2651 | | |
2652 | | /* Process ETBT record. |
2653 | | Return TRUE on success, FALSE on error. */ |
2654 | | |
2655 | | static bool |
2656 | | _bfd_vms_slurp_etbt (bfd *abfd) |
2657 | 3.55k | { |
2658 | 3.55k | vms_debug2 ((2, "ETBT\n")); |
2659 | | |
2660 | 3.55k | abfd->flags |= HAS_LINENO; |
2661 | | |
2662 | 3.55k | return vms_slurp_debug (abfd); |
2663 | 3.55k | } |
2664 | | |
2665 | | /* Process EEOM record. |
2666 | | Return TRUE on success, FALSE on error. */ |
2667 | | |
2668 | | static bool |
2669 | | _bfd_vms_slurp_eeom (bfd *abfd) |
2670 | 13 | { |
2671 | 13 | struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec); |
2672 | | |
2673 | 13 | vms_debug2 ((2, "EEOM\n")); |
2674 | | |
2675 | | /* PR 21813: Check for an undersized record. */ |
2676 | 13 | if (PRIV (recrd.rec_size) < 10) |
2677 | 1 | { |
2678 | 1 | _bfd_error_handler (_("corrupt EEOM record - size is too small")); |
2679 | 1 | bfd_set_error (bfd_error_bad_value); |
2680 | 1 | return false; |
2681 | 1 | } |
2682 | | |
2683 | 12 | PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps); |
2684 | 12 | PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod); |
2685 | 12 | if (PRIV (eom_data).eom_w_comcod > 1) |
2686 | 3 | { |
2687 | 3 | _bfd_error_handler (_("object module not error-free !")); |
2688 | 3 | bfd_set_error (bfd_error_bad_value); |
2689 | 3 | return false; |
2690 | 3 | } |
2691 | | |
2692 | 9 | PRIV (eom_data).eom_has_transfer = false; |
2693 | 9 | if (PRIV (recrd.rec_size) >= sizeof (*eeom)) |
2694 | 8 | { |
2695 | 8 | PRIV (eom_data).eom_has_transfer = true; |
2696 | 8 | PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg; |
2697 | 8 | PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx); |
2698 | 8 | PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr); |
2699 | | |
2700 | 8 | abfd->start_address = PRIV (eom_data).eom_l_tfradr; |
2701 | 8 | } |
2702 | 9 | return true; |
2703 | 12 | } |
2704 | | |
2705 | | /* Slurp an ordered set of VMS object records. Return FALSE on error. */ |
2706 | | |
2707 | | static bool |
2708 | | _bfd_vms_slurp_object_records (bfd * abfd) |
2709 | 558 | { |
2710 | 558 | bool ok; |
2711 | 558 | int type; |
2712 | | |
2713 | 558 | do |
2714 | 14.0k | { |
2715 | 14.0k | vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd))); |
2716 | | |
2717 | 14.0k | type = _bfd_vms_get_object_record (abfd); |
2718 | 14.0k | if (type < 0) |
2719 | 281 | { |
2720 | 281 | vms_debug2 ((2, "next_record failed\n")); |
2721 | 281 | return false; |
2722 | 281 | } |
2723 | | |
2724 | 13.7k | switch (type) |
2725 | 13.7k | { |
2726 | 421 | case EOBJ__C_EMH: |
2727 | 421 | ok = _bfd_vms_slurp_ehdr (abfd); |
2728 | 421 | break; |
2729 | 13 | case EOBJ__C_EEOM: |
2730 | 13 | ok = _bfd_vms_slurp_eeom (abfd); |
2731 | 13 | break; |
2732 | 563 | case EOBJ__C_EGSD: |
2733 | 563 | ok = _bfd_vms_slurp_egsd (abfd); |
2734 | 563 | break; |
2735 | 200 | case EOBJ__C_ETIR: |
2736 | 200 | ok = true; /* _bfd_vms_slurp_etir (abfd); */ |
2737 | 200 | break; |
2738 | 8.97k | case EOBJ__C_EDBG: |
2739 | 8.97k | ok = _bfd_vms_slurp_edbg (abfd); |
2740 | 8.97k | break; |
2741 | 3.55k | case EOBJ__C_ETBT: |
2742 | 3.55k | ok = _bfd_vms_slurp_etbt (abfd); |
2743 | 3.55k | break; |
2744 | 22 | default: |
2745 | 22 | ok = false; |
2746 | 13.7k | } |
2747 | 13.7k | if (!ok) |
2748 | 268 | { |
2749 | 268 | vms_debug2 ((2, "slurp type %d failed\n", type)); |
2750 | 268 | return false; |
2751 | 268 | } |
2752 | 13.7k | } |
2753 | 13.4k | while (type != EOBJ__C_EEOM); |
2754 | | |
2755 | 9 | return true; |
2756 | 558 | } |
2757 | | |
2758 | | /* Initialize private data */ |
2759 | | static bool |
2760 | | vms_initialize (bfd * abfd) |
2761 | 96.8k | { |
2762 | 96.8k | size_t amt; |
2763 | | |
2764 | 96.8k | amt = sizeof (struct vms_private_data_struct); |
2765 | 96.8k | abfd->tdata.any = bfd_zalloc (abfd, amt); |
2766 | 96.8k | if (abfd->tdata.any == NULL) |
2767 | 0 | return false; |
2768 | | |
2769 | 96.8k | PRIV (recrd.file_format) = FF_UNKNOWN; |
2770 | | |
2771 | 96.8k | amt = sizeof (struct stack_struct) * STACKSIZE; |
2772 | 96.8k | PRIV (stack) = bfd_alloc (abfd, amt); |
2773 | 96.8k | if (PRIV (stack) == NULL) |
2774 | 0 | goto error_ret1; |
2775 | | |
2776 | 96.8k | return true; |
2777 | | |
2778 | 0 | error_ret1: |
2779 | 0 | bfd_release (abfd, abfd->tdata.any); |
2780 | 0 | abfd->tdata.any = NULL; |
2781 | 0 | return false; |
2782 | 96.8k | } |
2783 | | |
2784 | | /* Free malloc'd memory. */ |
2785 | | |
2786 | | static void |
2787 | | alpha_vms_free_private (bfd *abfd) |
2788 | 96.8k | { |
2789 | 96.8k | struct module *module; |
2790 | | |
2791 | 96.8k | free (PRIV (recrd.buf)); |
2792 | 96.8k | free (PRIV (sections)); |
2793 | 96.8k | free (PRIV (syms)); |
2794 | 96.8k | free (PRIV (dst_ptr_offsets)); |
2795 | | |
2796 | 97.6k | for (module = PRIV (modules); module; module = module->next) |
2797 | 823 | free (module->file_table); |
2798 | 96.8k | } |
2799 | | |
2800 | | /* Check the format for a file being read. |
2801 | | Return a (bfd_target *) if it's an object file or zero if not. */ |
2802 | | |
2803 | | static bfd_cleanup |
2804 | | alpha_vms_object_p (bfd *abfd) |
2805 | 96.8k | { |
2806 | 96.8k | unsigned int test_len; |
2807 | 96.8k | unsigned char *buf; |
2808 | | |
2809 | 96.8k | vms_debug2 ((1, "vms_object_p(%p)\n", abfd)); |
2810 | | |
2811 | | /* Allocate alpha-vms specific data. */ |
2812 | 96.8k | if (!vms_initialize (abfd)) |
2813 | 0 | return NULL; |
2814 | | |
2815 | 96.8k | if (bfd_seek (abfd, 0, SEEK_SET)) |
2816 | 0 | goto error_ret; |
2817 | | |
2818 | | /* The first challenge with VMS is to discover the kind of the file. |
2819 | | |
2820 | | Image files (executable or shared images) are stored as a raw |
2821 | | stream of bytes (like on UNIX), but there is no magic number. |
2822 | | |
2823 | | Object files are written with RMS (record management service), ie |
2824 | | each records are preceeded by its length (on a word - 2 bytes), and |
2825 | | padded for word-alignment. That would be simple but when files |
2826 | | are transfered to a UNIX filesystem (using ftp), records are lost. |
2827 | | Only the raw content of the records are transfered. Fortunately, |
2828 | | the Alpha Object file format also store the length of the record |
2829 | | in the records. Is that clear ? */ |
2830 | | |
2831 | | /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id, |
2832 | | 2 bytes size repeated) and 12 bytes for images (4 bytes major id, |
2833 | | 4 bytes minor id, 4 bytes length). */ |
2834 | 96.8k | test_len = 12; |
2835 | 96.8k | buf = _bfd_malloc_and_read (abfd, test_len, test_len); |
2836 | 96.8k | if (buf == NULL) |
2837 | 987 | goto error_ret; |
2838 | 95.8k | PRIV (recrd.buf) = buf; |
2839 | 95.8k | PRIV (recrd.buf_size) = test_len; |
2840 | 95.8k | PRIV (recrd.rec) = buf; |
2841 | | |
2842 | | /* Is it an image? */ |
2843 | 95.8k | if ((bfd_getl32 (buf) == EIHD__K_MAJORID) |
2844 | 413 | && (bfd_getl32 (buf + 4) == EIHD__K_MINORID)) |
2845 | 390 | { |
2846 | 390 | unsigned int eisd_offset, eihs_offset; |
2847 | | |
2848 | | /* Extract the header size. */ |
2849 | 390 | PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE); |
2850 | | |
2851 | | /* The header size is 0 for DSF files. */ |
2852 | 390 | if (PRIV (recrd.rec_size) == 0) |
2853 | 203 | PRIV (recrd.rec_size) = sizeof (struct vms_eihd); |
2854 | | |
2855 | | /* PR 21813: Check for a truncated record. */ |
2856 | | /* PR 17512: file: 7d7c57c2. */ |
2857 | 390 | if (PRIV (recrd.rec_size) < EIHD__C_LENGTH) |
2858 | 3 | goto err_wrong_format; |
2859 | | |
2860 | 387 | if (bfd_seek (abfd, 0, SEEK_SET)) |
2861 | 0 | goto error_ret; |
2862 | | |
2863 | 387 | free (PRIV (recrd.buf)); |
2864 | 387 | PRIV (recrd.buf) = NULL; |
2865 | 387 | buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size), |
2866 | 387 | PRIV (recrd.rec_size)); |
2867 | 387 | if (buf == NULL) |
2868 | 60 | goto error_ret; |
2869 | | |
2870 | 327 | PRIV (recrd.buf) = buf; |
2871 | 327 | PRIV (recrd.buf_size) = PRIV (recrd.rec_size); |
2872 | 327 | PRIV (recrd.rec) = buf; |
2873 | | |
2874 | 327 | vms_debug2 ((2, "file type is image\n")); |
2875 | | |
2876 | 327 | if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset)) |
2877 | 0 | goto err_wrong_format; |
2878 | | |
2879 | 327 | if (!_bfd_vms_slurp_eisd (abfd, eisd_offset)) |
2880 | 165 | goto err_wrong_format; |
2881 | | |
2882 | | /* EIHS is optional. */ |
2883 | 162 | if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset)) |
2884 | 48 | goto err_wrong_format; |
2885 | 162 | } |
2886 | 95.4k | else |
2887 | 95.4k | { |
2888 | 95.4k | int type; |
2889 | | |
2890 | | /* Assume it's a module and adjust record pointer if necessary. */ |
2891 | 95.4k | maybe_adjust_record_pointer_for_object (abfd); |
2892 | | |
2893 | | /* But is it really a module? */ |
2894 | 95.4k | if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP |
2895 | 2.03k | && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ) |
2896 | 1.65k | { |
2897 | 1.65k | if (vms_get_remaining_object_record (abfd, test_len) <= 0) |
2898 | 1.02k | goto err_wrong_format; |
2899 | | |
2900 | 637 | vms_debug2 ((2, "file type is module\n")); |
2901 | | |
2902 | 637 | type = bfd_getl16 (PRIV (recrd.rec)); |
2903 | 637 | if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd)) |
2904 | 100 | goto err_wrong_format; |
2905 | | |
2906 | 537 | if (!_bfd_vms_slurp_object_records (abfd)) |
2907 | 529 | goto err_wrong_format; |
2908 | 537 | } |
2909 | 93.7k | else |
2910 | 93.7k | goto err_wrong_format; |
2911 | 95.4k | } |
2912 | | |
2913 | | /* Set arch_info to alpha. */ |
2914 | | |
2915 | 122 | if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0)) |
2916 | 0 | goto err_wrong_format; |
2917 | | |
2918 | 122 | return alpha_vms_free_private; |
2919 | | |
2920 | 95.6k | err_wrong_format: |
2921 | 95.6k | bfd_set_error (bfd_error_wrong_format); |
2922 | | |
2923 | 96.6k | error_ret: |
2924 | 96.6k | alpha_vms_free_private (abfd); |
2925 | 96.6k | bfd_release (abfd, abfd->tdata.any); |
2926 | 96.6k | return NULL; |
2927 | 95.6k | } |
2928 | | |
2929 | | /* Image write. */ |
2930 | | |
2931 | | /* Write an EMH/MHD record. */ |
2932 | | |
2933 | | static bool |
2934 | | _bfd_vms_write_emh (bfd *abfd) |
2935 | 1 | { |
2936 | 1 | struct vms_rec_wr *recwr = &PRIV (recwr); |
2937 | 1 | unsigned char tbuf[18]; |
2938 | | |
2939 | 1 | _bfd_vms_output_alignment (recwr, 2); |
2940 | | |
2941 | | /* EMH. */ |
2942 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); |
2943 | 1 | _bfd_vms_output_short (recwr, EMH__C_MHD); |
2944 | 1 | _bfd_vms_output_short (recwr, EOBJ__C_STRLVL); |
2945 | 1 | _bfd_vms_output_long (recwr, 0); |
2946 | 1 | _bfd_vms_output_long (recwr, 0); |
2947 | 1 | _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE); |
2948 | | |
2949 | | /* Create module name from filename. */ |
2950 | 1 | if (bfd_get_filename (abfd) != 0) |
2951 | 1 | { |
2952 | 1 | char *module = vms_get_module_name (bfd_get_filename (abfd), true); |
2953 | 1 | _bfd_vms_output_counted (recwr, module); |
2954 | 1 | free (module); |
2955 | 1 | } |
2956 | 0 | else |
2957 | 0 | _bfd_vms_output_counted (recwr, "NONAME"); |
2958 | | |
2959 | 1 | _bfd_vms_output_counted (recwr, BFD_VERSION_STRING); |
2960 | 1 | _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH); |
2961 | 1 | _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH); |
2962 | 1 | return _bfd_vms_output_end (abfd, recwr); |
2963 | 1 | } |
2964 | | |
2965 | | /* Write an EMH/LMN record. */ |
2966 | | |
2967 | | static bool |
2968 | | _bfd_vms_write_lmn (bfd *abfd, const char *name) |
2969 | 1 | { |
2970 | 1 | char version [64]; |
2971 | 1 | struct vms_rec_wr *recwr = &PRIV (recwr); |
2972 | 1 | unsigned int ver = BFD_VERSION / 10000; |
2973 | | |
2974 | | /* LMN. */ |
2975 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); |
2976 | 1 | _bfd_vms_output_short (recwr, EMH__C_LNM); |
2977 | 1 | snprintf (version, sizeof (version), "%s %d.%d.%d", name, |
2978 | 1 | ver / 10000, (ver / 100) % 100, ver % 100); |
2979 | 1 | _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version)); |
2980 | 1 | return _bfd_vms_output_end (abfd, recwr); |
2981 | 1 | } |
2982 | | |
2983 | | |
2984 | | /* Write eom record for bfd abfd. Return FALSE on error. */ |
2985 | | |
2986 | | static bool |
2987 | | _bfd_vms_write_eeom (bfd *abfd) |
2988 | 0 | { |
2989 | 0 | struct vms_rec_wr *recwr = &PRIV (recwr); |
2990 | |
|
2991 | 0 | vms_debug2 ((2, "vms_write_eeom\n")); |
2992 | |
|
2993 | 0 | _bfd_vms_output_alignment (recwr, 2); |
2994 | |
|
2995 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_EEOM); |
2996 | 0 | _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1); |
2997 | 0 | _bfd_vms_output_byte (recwr, 0); /* Completion code. */ |
2998 | 0 | _bfd_vms_output_byte (recwr, 0); /* Fill byte. */ |
2999 | |
|
3000 | 0 | if ((abfd->flags & EXEC_P) == 0 |
3001 | 0 | && bfd_get_start_address (abfd) != (bfd_vma)-1) |
3002 | 0 | { |
3003 | 0 | asection *section; |
3004 | |
|
3005 | 0 | section = bfd_get_section_by_name (abfd, ".link"); |
3006 | 0 | if (section == 0) |
3007 | 0 | { |
3008 | 0 | bfd_set_error (bfd_error_nonrepresentable_section); |
3009 | 0 | return false; |
3010 | 0 | } |
3011 | 0 | _bfd_vms_output_short (recwr, 0); |
3012 | 0 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); |
3013 | 0 | _bfd_vms_output_long (recwr, |
3014 | 0 | (unsigned long) bfd_get_start_address (abfd)); |
3015 | 0 | _bfd_vms_output_long (recwr, 0); |
3016 | 0 | } |
3017 | | |
3018 | 0 | return _bfd_vms_output_end (abfd, recwr); |
3019 | 0 | } |
3020 | | |
3021 | | static void * |
3022 | | vector_grow1 (struct vector_type *vec, size_t elsz) |
3023 | 0 | { |
3024 | 0 | if (vec->nbr_el >= vec->max_el) |
3025 | 0 | { |
3026 | 0 | if (vec->max_el == 0) |
3027 | 0 | { |
3028 | 0 | vec->max_el = 16; |
3029 | 0 | vec->els = bfd_malloc (vec->max_el * elsz); |
3030 | 0 | } |
3031 | 0 | else |
3032 | 0 | { |
3033 | 0 | size_t amt; |
3034 | 0 | if (vec->max_el > -1u / 2) |
3035 | 0 | { |
3036 | 0 | bfd_set_error (bfd_error_file_too_big); |
3037 | 0 | return NULL; |
3038 | 0 | } |
3039 | 0 | vec->max_el *= 2; |
3040 | 0 | if (_bfd_mul_overflow (vec->max_el, elsz, &amt)) |
3041 | 0 | { |
3042 | 0 | bfd_set_error (bfd_error_file_too_big); |
3043 | 0 | return NULL; |
3044 | 0 | } |
3045 | 0 | vec->els = bfd_realloc_or_free (vec->els, amt); |
3046 | 0 | } |
3047 | 0 | } |
3048 | 0 | if (vec->els == NULL) |
3049 | 0 | return NULL; |
3050 | 0 | return (char *) vec->els + elsz * vec->nbr_el++; |
3051 | 0 | } |
3052 | | |
3053 | | /* Bump ABFD file position to next block. */ |
3054 | | |
3055 | | static void |
3056 | | alpha_vms_file_position_block (bfd *abfd) |
3057 | 0 | { |
3058 | | /* Next block. */ |
3059 | 0 | PRIV (file_pos) += VMS_BLOCK_SIZE - 1; |
3060 | 0 | PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE); |
3061 | 0 | } |
3062 | | |
3063 | | /* Convert from internal structure SRC to external structure DST. */ |
3064 | | |
3065 | | static void |
3066 | | alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src, |
3067 | | struct vms_eisd *dst) |
3068 | 0 | { |
3069 | 0 | bfd_putl32 (src->u.eisd.majorid, dst->majorid); |
3070 | 0 | bfd_putl32 (src->u.eisd.minorid, dst->minorid); |
3071 | 0 | bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize); |
3072 | 0 | if (src->u.eisd.eisdsize <= EISD__K_LENEND) |
3073 | 0 | return; |
3074 | 0 | bfd_putl32 (src->u.eisd.secsize, dst->secsize); |
3075 | 0 | bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr); |
3076 | 0 | bfd_putl32 (src->u.eisd.flags, dst->flags); |
3077 | 0 | bfd_putl32 (src->u.eisd.vbn, dst->vbn); |
3078 | 0 | dst->pfc = src->u.eisd.pfc; |
3079 | 0 | dst->matchctl = src->u.eisd.matchctl; |
3080 | 0 | dst->type = src->u.eisd.type; |
3081 | 0 | dst->fill_1 = 0; |
3082 | 0 | if (src->u.eisd.flags & EISD__M_GBL) |
3083 | 0 | { |
3084 | 0 | bfd_putl32 (src->u.gbl_eisd.ident, dst->ident); |
3085 | 0 | memcpy (dst->gblnam, src->u.gbl_eisd.gblnam, |
3086 | 0 | src->u.gbl_eisd.gblnam[0] + 1); |
3087 | 0 | } |
3088 | 0 | } |
3089 | | |
3090 | | /* Append EISD to the list of extra eisd for ABFD. */ |
3091 | | |
3092 | | static void |
3093 | | alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd) |
3094 | 0 | { |
3095 | 0 | eisd->next = NULL; |
3096 | 0 | if (PRIV (gbl_eisd_head) == NULL) |
3097 | 0 | PRIV (gbl_eisd_head) = eisd; |
3098 | 0 | else |
3099 | 0 | PRIV (gbl_eisd_tail)->next = eisd; |
3100 | 0 | PRIV (gbl_eisd_tail) = eisd; |
3101 | 0 | } |
3102 | | |
3103 | | /* Create an EISD for shared image SHRIMG. |
3104 | | Return FALSE in case of error. */ |
3105 | | |
3106 | | static bool |
3107 | | alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg) |
3108 | 0 | { |
3109 | 0 | struct vms_internal_eisd_map *eisd; |
3110 | 0 | int namlen; |
3111 | |
|
3112 | 0 | namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name)); |
3113 | 0 | if (namlen + 5 > EISD__K_GBLNAMLEN) |
3114 | 0 | { |
3115 | | /* Won't fit. */ |
3116 | 0 | return false; |
3117 | 0 | } |
3118 | | |
3119 | 0 | eisd = bfd_alloc (abfd, sizeof (*eisd)); |
3120 | 0 | if (eisd == NULL) |
3121 | 0 | return false; |
3122 | | |
3123 | | /* Fill the fields. */ |
3124 | 0 | eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID; |
3125 | 0 | eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID; |
3126 | 0 | eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3; |
3127 | 0 | eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */ |
3128 | 0 | eisd->u.gbl_eisd.common.virt_addr = 0; |
3129 | 0 | eisd->u.gbl_eisd.common.flags = EISD__M_GBL; |
3130 | 0 | eisd->u.gbl_eisd.common.vbn = 0; |
3131 | 0 | eisd->u.gbl_eisd.common.pfc = 0; |
3132 | 0 | eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl); |
3133 | 0 | eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC; |
3134 | |
|
3135 | 0 | eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident); |
3136 | 0 | eisd->u.gbl_eisd.gblnam[0] = namlen + 4; |
3137 | 0 | memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name), |
3138 | 0 | namlen); |
3139 | 0 | memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4); |
3140 | | |
3141 | | /* Append it to the list. */ |
3142 | 0 | alpha_vms_append_extra_eisd (abfd, eisd); |
3143 | |
|
3144 | 0 | return true; |
3145 | 0 | } |
3146 | | |
3147 | | /* Create an EISD for section SEC. |
3148 | | Return FALSE in case of failure. */ |
3149 | | |
3150 | | static bool |
3151 | | alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec) |
3152 | 0 | { |
3153 | 0 | struct vms_internal_eisd_map *eisd; |
3154 | | |
3155 | | /* Only for allocating section. */ |
3156 | 0 | if (!(sec->flags & SEC_ALLOC)) |
3157 | 0 | return true; |
3158 | | |
3159 | 0 | BFD_ASSERT (vms_section_data (sec)->eisd == NULL); |
3160 | 0 | eisd = bfd_alloc (abfd, sizeof (*eisd)); |
3161 | 0 | if (eisd == NULL) |
3162 | 0 | return false; |
3163 | 0 | vms_section_data (sec)->eisd = eisd; |
3164 | | |
3165 | | /* Fill the fields. */ |
3166 | 0 | eisd->u.eisd.majorid = EISD__K_MAJORID; |
3167 | 0 | eisd->u.eisd.minorid = EISD__K_MINORID; |
3168 | 0 | eisd->u.eisd.eisdsize = EISD__K_LEN; |
3169 | 0 | eisd->u.eisd.secsize = |
3170 | 0 | (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); |
3171 | 0 | eisd->u.eisd.virt_addr = sec->vma; |
3172 | 0 | eisd->u.eisd.flags = 0; |
3173 | 0 | eisd->u.eisd.vbn = 0; /* To be later defined. */ |
3174 | 0 | eisd->u.eisd.pfc = 0; /* Default. */ |
3175 | 0 | eisd->u.eisd.matchctl = EISD__K_MATALL; |
3176 | 0 | eisd->u.eisd.type = EISD__K_NORMAL; |
3177 | |
|
3178 | 0 | if (sec->flags & SEC_CODE) |
3179 | 0 | eisd->u.eisd.flags |= EISD__M_EXE; |
3180 | 0 | if (!(sec->flags & SEC_READONLY)) |
3181 | 0 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; |
3182 | | |
3183 | | /* If relocations or fixup will be applied, make this isect writeable. */ |
3184 | 0 | if (sec->flags & SEC_RELOC) |
3185 | 0 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; |
3186 | |
|
3187 | 0 | if (!(sec->flags & SEC_HAS_CONTENTS)) |
3188 | 0 | { |
3189 | 0 | eisd->u.eisd.flags |= EISD__M_DZRO; |
3190 | 0 | eisd->u.eisd.flags &= ~EISD__M_CRF; |
3191 | 0 | } |
3192 | 0 | if (sec->flags & SEC_LINKER_CREATED) |
3193 | 0 | { |
3194 | 0 | if (strcmp (sec->name, "$FIXUP$") == 0) |
3195 | 0 | eisd->u.eisd.flags |= EISD__M_FIXUPVEC; |
3196 | 0 | } |
3197 | | |
3198 | | /* Append it to the list. */ |
3199 | 0 | eisd->next = NULL; |
3200 | 0 | if (PRIV (eisd_head) == NULL) |
3201 | 0 | PRIV (eisd_head) = eisd; |
3202 | 0 | else |
3203 | 0 | PRIV (eisd_tail)->next = eisd; |
3204 | 0 | PRIV (eisd_tail) = eisd; |
3205 | |
|
3206 | 0 | return true; |
3207 | 0 | } |
3208 | | |
3209 | | /* Layout executable ABFD and write it to the disk. |
3210 | | Return FALSE in case of failure. */ |
3211 | | |
3212 | | static bool |
3213 | | alpha_vms_write_exec (bfd *abfd) |
3214 | 3 | { |
3215 | 3 | struct vms_eihd eihd; |
3216 | 3 | struct vms_eiha *eiha; |
3217 | 3 | struct vms_eihi *eihi; |
3218 | 3 | struct vms_eihs *eihs = NULL; |
3219 | 3 | asection *sec; |
3220 | 3 | struct vms_internal_eisd_map *first_eisd; |
3221 | 3 | struct vms_internal_eisd_map *eisd; |
3222 | 3 | asection *dst; |
3223 | 3 | asection *dmt; |
3224 | 3 | file_ptr gst_filepos = 0; |
3225 | 3 | unsigned int lnkflags = 0; |
3226 | | |
3227 | | /* Build the EIHD. */ |
3228 | 3 | PRIV (file_pos) = EIHD__C_LENGTH; |
3229 | | |
3230 | 3 | memset (&eihd, 0, sizeof (eihd)); |
3231 | 3 | memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2)); |
3232 | | |
3233 | 3 | bfd_putl32 (EIHD__K_MAJORID, eihd.majorid); |
3234 | 3 | bfd_putl32 (EIHD__K_MINORID, eihd.minorid); |
3235 | | |
3236 | 3 | bfd_putl32 (sizeof (eihd), eihd.size); |
3237 | 3 | bfd_putl32 (0, eihd.isdoff); |
3238 | 3 | bfd_putl32 (0, eihd.activoff); |
3239 | 3 | bfd_putl32 (0, eihd.symdbgoff); |
3240 | 3 | bfd_putl32 (0, eihd.imgidoff); |
3241 | 3 | bfd_putl32 (0, eihd.patchoff); |
3242 | 3 | bfd_putl64 (0, eihd.iafva); |
3243 | 3 | bfd_putl32 (0, eihd.version_array_off); |
3244 | | |
3245 | 3 | bfd_putl32 (EIHD__K_EXE, eihd.imgtype); |
3246 | 3 | bfd_putl32 (0, eihd.subtype); |
3247 | | |
3248 | 3 | bfd_putl32 (0, eihd.imgiocnt); |
3249 | 3 | bfd_putl32 (-1, eihd.privreqs); |
3250 | 3 | bfd_putl32 (-1, eihd.privreqs + 4); |
3251 | | |
3252 | 3 | bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, |
3253 | 3 | eihd.hdrblkcnt); |
3254 | 3 | bfd_putl32 (0, eihd.ident); |
3255 | 3 | bfd_putl32 (0, eihd.sysver); |
3256 | | |
3257 | 3 | eihd.matchctl = 0; |
3258 | 3 | bfd_putl32 (0, eihd.symvect_size); |
3259 | 3 | bfd_putl32 (16, eihd.virt_mem_block_size); |
3260 | 3 | bfd_putl32 (0, eihd.ext_fixup_off); |
3261 | 3 | bfd_putl32 (0, eihd.noopt_psect_off); |
3262 | 3 | bfd_putl16 (-1, eihd.alias); |
3263 | | |
3264 | | /* Alloc EIHA. */ |
3265 | 3 | eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos)); |
3266 | 3 | bfd_putl32 (PRIV (file_pos), eihd.activoff); |
3267 | 3 | PRIV (file_pos) += sizeof (struct vms_eiha); |
3268 | | |
3269 | 3 | bfd_putl32 (sizeof (struct vms_eiha), eiha->size); |
3270 | 3 | bfd_putl32 (0, eiha->spare); |
3271 | 3 | bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1); |
3272 | 3 | bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2); |
3273 | 3 | bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3); |
3274 | 3 | bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4); |
3275 | 3 | bfd_putl64 (0, eiha->inishr); |
3276 | | |
3277 | | /* Alloc EIHI. */ |
3278 | 3 | eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos)); |
3279 | 3 | bfd_putl32 (PRIV (file_pos), eihd.imgidoff); |
3280 | 3 | PRIV (file_pos) += sizeof (struct vms_eihi); |
3281 | | |
3282 | 3 | bfd_putl32 (EIHI__K_MAJORID, eihi->majorid); |
3283 | 3 | bfd_putl32 (EIHI__K_MINORID, eihi->minorid); |
3284 | 3 | { |
3285 | 3 | char *module; |
3286 | 3 | unsigned int len; |
3287 | | |
3288 | | /* Set module name. */ |
3289 | 3 | module = vms_get_module_name (bfd_get_filename (abfd), true); |
3290 | 3 | len = strlen (module); |
3291 | 3 | if (len > sizeof (eihi->imgnam) - 1) |
3292 | 0 | len = sizeof (eihi->imgnam) - 1; |
3293 | 3 | eihi->imgnam[0] = len; |
3294 | 3 | memcpy (eihi->imgnam + 1, module, len); |
3295 | 3 | free (module); |
3296 | 3 | } |
3297 | 3 | { |
3298 | 3 | unsigned int lo; |
3299 | 3 | unsigned int hi; |
3300 | | |
3301 | | /* Set time. */ |
3302 | 3 | vms_get_time (&hi, &lo); |
3303 | 3 | bfd_putl32 (lo, eihi->linktime + 0); |
3304 | 3 | bfd_putl32 (hi, eihi->linktime + 4); |
3305 | 3 | } |
3306 | 3 | eihi->imgid[0] = 0; |
3307 | 3 | eihi->linkid[0] = 0; |
3308 | 3 | eihi->imgbid[0] = 0; |
3309 | | |
3310 | | /* Alloc EIHS. */ |
3311 | 3 | dst = PRIV (dst_section); |
3312 | 3 | dmt = bfd_get_section_by_name (abfd, "$DMT$"); |
3313 | 3 | if (dst != NULL && dst->size != 0) |
3314 | 0 | { |
3315 | 0 | eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos)); |
3316 | 0 | bfd_putl32 (PRIV (file_pos), eihd.symdbgoff); |
3317 | 0 | PRIV (file_pos) += sizeof (struct vms_eihs); |
3318 | |
|
3319 | 0 | bfd_putl32 (EIHS__K_MAJORID, eihs->majorid); |
3320 | 0 | bfd_putl32 (EIHS__K_MINORID, eihs->minorid); |
3321 | 0 | bfd_putl32 (0, eihs->dstvbn); |
3322 | 0 | bfd_putl32 (0, eihs->dstsize); |
3323 | 0 | bfd_putl32 (0, eihs->gstvbn); |
3324 | 0 | bfd_putl32 (0, eihs->gstsize); |
3325 | 0 | bfd_putl32 (0, eihs->dmtvbn); |
3326 | 0 | bfd_putl32 (0, eihs->dmtsize); |
3327 | 0 | } |
3328 | | |
3329 | | /* One EISD per section. */ |
3330 | 3 | for (sec = abfd->sections; sec; sec = sec->next) |
3331 | 0 | { |
3332 | 0 | if (!alpha_vms_create_eisd_for_section (abfd, sec)) |
3333 | 0 | return false; |
3334 | 0 | } |
3335 | | |
3336 | | /* Merge section EIDS which extra ones. */ |
3337 | 3 | if (PRIV (eisd_tail)) |
3338 | 0 | PRIV (eisd_tail)->next = PRIV (gbl_eisd_head); |
3339 | 3 | else |
3340 | 3 | PRIV (eisd_head) = PRIV (gbl_eisd_head); |
3341 | 3 | if (PRIV (gbl_eisd_tail)) |
3342 | 0 | PRIV (eisd_tail) = PRIV (gbl_eisd_tail); |
3343 | | |
3344 | 3 | first_eisd = PRIV (eisd_head); |
3345 | | |
3346 | | /* Add end of eisd. */ |
3347 | 3 | if (first_eisd) |
3348 | 0 | { |
3349 | 0 | eisd = bfd_zalloc (abfd, sizeof (*eisd)); |
3350 | 0 | if (eisd == NULL) |
3351 | 0 | return false; |
3352 | 0 | eisd->u.eisd.majorid = 0; |
3353 | 0 | eisd->u.eisd.minorid = 0; |
3354 | 0 | eisd->u.eisd.eisdsize = 0; |
3355 | 0 | alpha_vms_append_extra_eisd (abfd, eisd); |
3356 | 0 | } |
3357 | | |
3358 | | /* Place EISD in the file. */ |
3359 | 3 | for (eisd = first_eisd; eisd; eisd = eisd->next) |
3360 | 0 | { |
3361 | 0 | file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE); |
3362 | | |
3363 | | /* First block is a little bit special: there is a word at the end. */ |
3364 | 0 | if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2) |
3365 | 0 | room -= 2; |
3366 | 0 | if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND) |
3367 | 0 | alpha_vms_file_position_block (abfd); |
3368 | |
|
3369 | 0 | eisd->file_pos = PRIV (file_pos); |
3370 | 0 | PRIV (file_pos) += eisd->u.eisd.eisdsize; |
3371 | |
|
3372 | 0 | if (eisd->u.eisd.flags & EISD__M_FIXUPVEC) |
3373 | 0 | bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva); |
3374 | 0 | } |
3375 | | |
3376 | 3 | if (first_eisd != NULL) |
3377 | 0 | { |
3378 | 0 | bfd_putl32 (first_eisd->file_pos, eihd.isdoff); |
3379 | | /* Real size of end of eisd marker. */ |
3380 | 0 | PRIV (file_pos) += EISD__K_LENEND; |
3381 | 0 | } |
3382 | | |
3383 | 3 | bfd_putl32 (PRIV (file_pos), eihd.size); |
3384 | 3 | bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, |
3385 | 3 | eihd.hdrblkcnt); |
3386 | | |
3387 | | /* Place sections. */ |
3388 | 3 | for (sec = abfd->sections; sec; sec = sec->next) |
3389 | 0 | { |
3390 | 0 | if (!(sec->flags & SEC_HAS_CONTENTS) |
3391 | 0 | || sec->contents == NULL) |
3392 | 0 | continue; |
3393 | | |
3394 | 0 | eisd = vms_section_data (sec)->eisd; |
3395 | | |
3396 | | /* Align on a block. */ |
3397 | 0 | alpha_vms_file_position_block (abfd); |
3398 | 0 | sec->filepos = PRIV (file_pos); |
3399 | |
|
3400 | 0 | if (eisd != NULL) |
3401 | 0 | eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1; |
3402 | |
|
3403 | 0 | PRIV (file_pos) += sec->size; |
3404 | 0 | } |
3405 | | |
3406 | | /* Update EIHS. */ |
3407 | 3 | if (eihs != NULL && dst != NULL) |
3408 | 0 | { |
3409 | 0 | bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn); |
3410 | 0 | bfd_putl32 (dst->size, eihs->dstsize); |
3411 | |
|
3412 | 0 | if (dmt != NULL) |
3413 | 0 | { |
3414 | 0 | lnkflags |= EIHD__M_DBGDMT; |
3415 | 0 | bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn); |
3416 | 0 | bfd_putl32 (dmt->size, eihs->dmtsize); |
3417 | 0 | } |
3418 | 0 | if (PRIV (gsd_sym_count) != 0) |
3419 | 0 | { |
3420 | 0 | alpha_vms_file_position_block (abfd); |
3421 | 0 | gst_filepos = PRIV (file_pos); |
3422 | 0 | bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn); |
3423 | 0 | bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize); |
3424 | 0 | } |
3425 | 0 | } |
3426 | | |
3427 | | /* Write EISD in hdr. */ |
3428 | 3 | for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE; |
3429 | 3 | eisd = eisd->next) |
3430 | 0 | alpha_vms_swap_eisd_out |
3431 | 0 | (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos)); |
3432 | | |
3433 | | /* Write first block. */ |
3434 | 3 | bfd_putl32 (lnkflags, eihd.lnkflags); |
3435 | 3 | if (bfd_write (&eihd, sizeof (eihd), abfd) != sizeof (eihd)) |
3436 | 0 | return false; |
3437 | | |
3438 | | /* Write remaining eisd. */ |
3439 | 3 | if (eisd != NULL) |
3440 | 0 | { |
3441 | 0 | unsigned char blk[VMS_BLOCK_SIZE]; |
3442 | 0 | struct vms_internal_eisd_map *next_eisd; |
3443 | |
|
3444 | 0 | memset (blk, 0xff, sizeof (blk)); |
3445 | 0 | while (eisd != NULL) |
3446 | 0 | { |
3447 | 0 | alpha_vms_swap_eisd_out |
3448 | 0 | (eisd, |
3449 | 0 | (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE))); |
3450 | |
|
3451 | 0 | next_eisd = eisd->next; |
3452 | 0 | if (next_eisd == NULL |
3453 | 0 | || (next_eisd->file_pos / VMS_BLOCK_SIZE |
3454 | 0 | != eisd->file_pos / VMS_BLOCK_SIZE)) |
3455 | 0 | { |
3456 | 0 | if (bfd_write (blk, sizeof (blk), abfd) != sizeof (blk)) |
3457 | 0 | return false; |
3458 | | |
3459 | 0 | memset (blk, 0xff, sizeof (blk)); |
3460 | 0 | } |
3461 | 0 | eisd = next_eisd; |
3462 | 0 | } |
3463 | 0 | } |
3464 | | |
3465 | | /* Write sections. */ |
3466 | 3 | for (sec = abfd->sections; sec; sec = sec->next) |
3467 | 0 | { |
3468 | 0 | unsigned char blk[VMS_BLOCK_SIZE]; |
3469 | 0 | bfd_size_type len; |
3470 | |
|
3471 | 0 | if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS) |
3472 | 0 | || sec->contents == NULL) |
3473 | 0 | continue; |
3474 | 0 | if (bfd_write (sec->contents, sec->size, abfd) != sec->size) |
3475 | 0 | return false; |
3476 | | |
3477 | | /* Pad. */ |
3478 | 0 | len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE; |
3479 | 0 | if (len != VMS_BLOCK_SIZE) |
3480 | 0 | { |
3481 | 0 | memset (blk, 0, len); |
3482 | 0 | if (bfd_write (blk, len, abfd) != len) |
3483 | 0 | return false; |
3484 | 0 | } |
3485 | 0 | } |
3486 | | |
3487 | | /* Write GST. */ |
3488 | 3 | if (gst_filepos != 0) |
3489 | 0 | { |
3490 | 0 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3491 | 0 | unsigned int i; |
3492 | |
|
3493 | 0 | if (!_bfd_vms_write_emh (abfd) |
3494 | 0 | || !_bfd_vms_write_lmn (abfd, "GNU LD")) |
3495 | 0 | return false; |
3496 | | |
3497 | | /* PSC for the absolute section. */ |
3498 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3499 | 0 | _bfd_vms_output_long (recwr, 0); |
3500 | 0 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); |
3501 | 0 | _bfd_vms_output_short (recwr, 0); |
3502 | 0 | _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD); |
3503 | 0 | _bfd_vms_output_long (recwr, 0); |
3504 | 0 | _bfd_vms_output_counted (recwr, ".$$ABS$$."); |
3505 | 0 | _bfd_vms_output_end_subrec (recwr); |
3506 | 0 | if (!_bfd_vms_output_end (abfd, recwr)) |
3507 | 0 | return false; |
3508 | | |
3509 | 0 | for (i = 0; i < PRIV (gsd_sym_count); i++) |
3510 | 0 | { |
3511 | 0 | struct vms_symbol_entry *sym = PRIV (syms)[i]; |
3512 | 0 | bfd_vma val; |
3513 | 0 | bfd_vma ep; |
3514 | |
|
3515 | 0 | if ((i % 5) == 0) |
3516 | 0 | { |
3517 | 0 | _bfd_vms_output_alignment (recwr, 8); |
3518 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3519 | 0 | _bfd_vms_output_long (recwr, 0); |
3520 | 0 | } |
3521 | 0 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG); |
3522 | 0 | _bfd_vms_output_short (recwr, 0); /* Data type, alignment. */ |
3523 | 0 | _bfd_vms_output_short (recwr, sym->flags); |
3524 | |
|
3525 | 0 | if (sym->code_section) |
3526 | 0 | ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value); |
3527 | 0 | else |
3528 | 0 | { |
3529 | 0 | BFD_ASSERT (sym->code_value == 0); |
3530 | 0 | ep = 0; |
3531 | 0 | } |
3532 | 0 | val = alpha_vms_get_sym_value (sym->section, sym->value); |
3533 | 0 | _bfd_vms_output_quad |
3534 | 0 | (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val); |
3535 | 0 | _bfd_vms_output_quad (recwr, ep); |
3536 | 0 | _bfd_vms_output_quad (recwr, val); |
3537 | 0 | _bfd_vms_output_long (recwr, 0); |
3538 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
3539 | 0 | _bfd_vms_output_end_subrec (recwr); |
3540 | 0 | if ((i % 5) == 4 |
3541 | 0 | && !_bfd_vms_output_end (abfd, recwr)) |
3542 | 0 | return false; |
3543 | 0 | } |
3544 | 0 | if ((i % 5) != 0 |
3545 | 0 | && !_bfd_vms_output_end (abfd, recwr)) |
3546 | 0 | return false; |
3547 | | |
3548 | 0 | if (!_bfd_vms_write_eeom (abfd)) |
3549 | 0 | return false; |
3550 | 0 | } |
3551 | 3 | return true; |
3552 | 3 | } |
3553 | | |
3554 | | /* Object write. */ |
3555 | | |
3556 | | /* Write section and symbol directory of bfd abfd. Return FALSE on error. */ |
3557 | | |
3558 | | static bool |
3559 | | _bfd_vms_write_egsd (bfd *abfd) |
3560 | 1 | { |
3561 | 1 | asection *section; |
3562 | 1 | asymbol *symbol; |
3563 | 1 | unsigned int symnum; |
3564 | 1 | const char *sname; |
3565 | 1 | flagword new_flags, old_flags; |
3566 | 1 | int abs_section_index = -1; |
3567 | 1 | unsigned int target_index = 0; |
3568 | 1 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3569 | | |
3570 | 1 | vms_debug2 ((2, "vms_write_egsd\n")); |
3571 | | |
3572 | | /* Egsd is quadword aligned. */ |
3573 | 1 | _bfd_vms_output_alignment (recwr, 8); |
3574 | | |
3575 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3576 | 1 | _bfd_vms_output_long (recwr, 0); |
3577 | | |
3578 | | /* Number sections. */ |
3579 | 2 | for (section = abfd->sections; section != NULL; section = section->next) |
3580 | 1 | { |
3581 | 1 | if (section->flags & SEC_DEBUGGING) |
3582 | 1 | continue; |
3583 | 0 | if (!strcmp (section->name, ".vmsdebug")) |
3584 | 0 | { |
3585 | 0 | section->flags |= SEC_DEBUGGING; |
3586 | 0 | continue; |
3587 | 0 | } |
3588 | 0 | section->target_index = target_index++; |
3589 | 0 | } |
3590 | | |
3591 | 2 | for (section = abfd->sections; section != NULL; section = section->next) |
3592 | 1 | { |
3593 | 1 | vms_debug2 ((3, "Section #%d %s, %d bytes\n", |
3594 | 1 | section->target_index, section->name, (int)section->size)); |
3595 | | |
3596 | | /* Don't write out the VMS debug info section since it is in the |
3597 | | ETBT and EDBG sections in etir. */ |
3598 | 1 | if (section->flags & SEC_DEBUGGING) |
3599 | 1 | continue; |
3600 | | |
3601 | | /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */ |
3602 | 0 | if (_bfd_vms_output_check (recwr, 64) < 0) |
3603 | 0 | { |
3604 | 0 | if (!_bfd_vms_output_end (abfd, recwr)) |
3605 | 0 | return false; |
3606 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3607 | 0 | _bfd_vms_output_long (recwr, 0); |
3608 | 0 | } |
3609 | | |
3610 | | /* Don't know if this is necessary for the linker but for now it keeps |
3611 | | vms_slurp_gsd happy. */ |
3612 | 0 | sname = section->name; |
3613 | 0 | if (*sname == '.') |
3614 | 0 | { |
3615 | | /* Remove leading dot. */ |
3616 | 0 | sname++; |
3617 | 0 | if ((*sname == 't') && (strcmp (sname, "text") == 0)) |
3618 | 0 | sname = EVAX_CODE_NAME; |
3619 | 0 | else if ((*sname == 'd') && (strcmp (sname, "data") == 0)) |
3620 | 0 | sname = EVAX_DATA_NAME; |
3621 | 0 | else if ((*sname == 'b') && (strcmp (sname, "bss") == 0)) |
3622 | 0 | sname = EVAX_BSS_NAME; |
3623 | 0 | else if ((*sname == 'l') && (strcmp (sname, "link") == 0)) |
3624 | 0 | sname = EVAX_LINK_NAME; |
3625 | 0 | else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0)) |
3626 | 0 | sname = EVAX_READONLY_NAME; |
3627 | 0 | else if ((*sname == 'l') && (strcmp (sname, "literal") == 0)) |
3628 | 0 | sname = EVAX_LITERAL_NAME; |
3629 | 0 | else if ((*sname == 'l') && (strcmp (sname, "literals") == 0)) |
3630 | 0 | sname = EVAX_LITERALS_NAME; |
3631 | 0 | else if ((*sname == 'c') && (strcmp (sname, "comm") == 0)) |
3632 | 0 | sname = EVAX_COMMON_NAME; |
3633 | 0 | else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0)) |
3634 | 0 | sname = EVAX_LOCAL_NAME; |
3635 | 0 | } |
3636 | |
|
3637 | 0 | if (bfd_is_com_section (section)) |
3638 | 0 | new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD |
3639 | 0 | | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM); |
3640 | 0 | else |
3641 | 0 | new_flags = vms_esecflag_by_name (evax_section_flags, sname, |
3642 | 0 | section->size > 0); |
3643 | | |
3644 | | /* Modify them as directed. */ |
3645 | 0 | if (section->flags & SEC_READONLY) |
3646 | 0 | new_flags &= ~EGPS__V_WRT; |
3647 | |
|
3648 | 0 | new_flags &= ~vms_section_data (section)->no_flags; |
3649 | 0 | new_flags |= vms_section_data (section)->flags; |
3650 | |
|
3651 | 0 | vms_debug2 ((3, "sec flags %x\n", section->flags)); |
3652 | 0 | vms_debug2 ((3, "new_flags %x, _raw_size %lu\n", |
3653 | 0 | new_flags, (unsigned long)section->size)); |
3654 | |
|
3655 | 0 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); |
3656 | 0 | _bfd_vms_output_short (recwr, section->alignment_power & 0xff); |
3657 | 0 | _bfd_vms_output_short (recwr, new_flags); |
3658 | 0 | _bfd_vms_output_long (recwr, (unsigned long) section->size); |
3659 | 0 | _bfd_vms_output_counted (recwr, sname); |
3660 | 0 | _bfd_vms_output_end_subrec (recwr); |
3661 | | |
3662 | | /* If the section is an obsolute one, remind its index as it will be |
3663 | | used later for absolute symbols. */ |
3664 | 0 | if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0) |
3665 | 0 | abs_section_index = section->target_index; |
3666 | 0 | } |
3667 | | |
3668 | | /* Output symbols. */ |
3669 | 1 | vms_debug2 ((3, "%d symbols found\n", abfd->symcount)); |
3670 | | |
3671 | 1 | bfd_set_start_address (abfd, (bfd_vma) -1); |
3672 | | |
3673 | 1 | for (symnum = 0; symnum < abfd->symcount; symnum++) |
3674 | 0 | { |
3675 | 0 | symbol = abfd->outsymbols[symnum]; |
3676 | 0 | old_flags = symbol->flags; |
3677 | | |
3678 | | /* Work-around a missing feature: consider __main as the main entry |
3679 | | point. */ |
3680 | 0 | if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0) |
3681 | 0 | bfd_set_start_address (abfd, (bfd_vma)symbol->value); |
3682 | | |
3683 | | /* Only put in the GSD the global and the undefined symbols. */ |
3684 | 0 | if (old_flags & BSF_FILE) |
3685 | 0 | continue; |
3686 | | |
3687 | 0 | if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section)) |
3688 | 0 | { |
3689 | | /* If the LIB$INITIIALIZE section is present, add a reference to |
3690 | | LIB$INITIALIZE symbol. FIXME: this should be done explicitely |
3691 | | in the assembly file. */ |
3692 | 0 | if (!((old_flags & BSF_SECTION_SYM) != 0 |
3693 | 0 | && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0)) |
3694 | 0 | continue; |
3695 | 0 | } |
3696 | | |
3697 | | /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. Add 16 more |
3698 | | bytes for a possible ABS section. */ |
3699 | 0 | if (_bfd_vms_output_check (recwr, 80 + 16) < 0) |
3700 | 0 | { |
3701 | 0 | if (!_bfd_vms_output_end (abfd, recwr)) |
3702 | 0 | return false; |
3703 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3704 | 0 | _bfd_vms_output_long (recwr, 0); |
3705 | 0 | } |
3706 | | |
3707 | 0 | if ((old_flags & BSF_GLOBAL) != 0 |
3708 | 0 | && bfd_is_abs_section (symbol->section) |
3709 | 0 | && abs_section_index <= 0) |
3710 | 0 | { |
3711 | | /* Create an absolute section if none was defined. It is highly |
3712 | | unlikely that the name $ABS$ clashes with a user defined |
3713 | | non-absolute section name. */ |
3714 | 0 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); |
3715 | 0 | _bfd_vms_output_short (recwr, 4); |
3716 | 0 | _bfd_vms_output_short (recwr, EGPS__V_SHR); |
3717 | 0 | _bfd_vms_output_long (recwr, 0); |
3718 | 0 | _bfd_vms_output_counted (recwr, "$ABS$"); |
3719 | 0 | _bfd_vms_output_end_subrec (recwr); |
3720 | |
|
3721 | 0 | abs_section_index = target_index++; |
3722 | 0 | } |
3723 | |
|
3724 | 0 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM); |
3725 | | |
3726 | | /* Data type, alignment. */ |
3727 | 0 | _bfd_vms_output_short (recwr, 0); |
3728 | |
|
3729 | 0 | new_flags = 0; |
3730 | |
|
3731 | 0 | if (old_flags & BSF_WEAK) |
3732 | 0 | new_flags |= EGSY__V_WEAK; |
3733 | 0 | if (bfd_is_com_section (symbol->section)) /* .comm */ |
3734 | 0 | new_flags |= (EGSY__V_WEAK | EGSY__V_COMM); |
3735 | |
|
3736 | 0 | if (old_flags & BSF_FUNCTION) |
3737 | 0 | { |
3738 | 0 | new_flags |= EGSY__V_NORM; |
3739 | 0 | new_flags |= EGSY__V_REL; |
3740 | 0 | } |
3741 | 0 | if (old_flags & BSF_GLOBAL) |
3742 | 0 | { |
3743 | 0 | new_flags |= EGSY__V_DEF; |
3744 | 0 | if (!bfd_is_abs_section (symbol->section)) |
3745 | 0 | new_flags |= EGSY__V_REL; |
3746 | 0 | } |
3747 | 0 | _bfd_vms_output_short (recwr, new_flags); |
3748 | |
|
3749 | 0 | if (old_flags & BSF_GLOBAL) |
3750 | 0 | { |
3751 | | /* Symbol definition. */ |
3752 | 0 | bfd_vma code_address = 0; |
3753 | 0 | unsigned long ca_psindx = 0; |
3754 | 0 | unsigned long psindx; |
3755 | |
|
3756 | 0 | if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL) |
3757 | 0 | { |
3758 | 0 | asymbol *sym; |
3759 | |
|
3760 | 0 | sym = |
3761 | 0 | ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym; |
3762 | 0 | code_address = sym->value; |
3763 | 0 | ca_psindx = sym->section->target_index; |
3764 | 0 | } |
3765 | 0 | if (bfd_is_abs_section (symbol->section)) |
3766 | 0 | psindx = abs_section_index; |
3767 | 0 | else |
3768 | 0 | psindx = symbol->section->target_index; |
3769 | |
|
3770 | 0 | _bfd_vms_output_quad (recwr, symbol->value); |
3771 | 0 | _bfd_vms_output_quad (recwr, code_address); |
3772 | 0 | _bfd_vms_output_long (recwr, ca_psindx); |
3773 | 0 | _bfd_vms_output_long (recwr, psindx); |
3774 | 0 | } |
3775 | 0 | _bfd_vms_output_counted (recwr, symbol->name); |
3776 | |
|
3777 | 0 | _bfd_vms_output_end_subrec (recwr); |
3778 | 0 | } |
3779 | | |
3780 | 1 | _bfd_vms_output_alignment (recwr, 8); |
3781 | 1 | return _bfd_vms_output_end (abfd, recwr); |
3782 | 1 | } |
3783 | | |
3784 | | /* Write object header for bfd abfd. Return FALSE on error. */ |
3785 | | |
3786 | | static bool |
3787 | | _bfd_vms_write_ehdr (bfd *abfd) |
3788 | 1 | { |
3789 | 1 | asymbol *symbol; |
3790 | 1 | unsigned int symnum; |
3791 | 1 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3792 | | |
3793 | 1 | vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd)); |
3794 | | |
3795 | 1 | _bfd_vms_output_alignment (recwr, 2); |
3796 | | |
3797 | 1 | if (!_bfd_vms_write_emh (abfd) |
3798 | 1 | || !_bfd_vms_write_lmn (abfd, "GNU AS")) |
3799 | 0 | return false; |
3800 | | |
3801 | | /* SRC. */ |
3802 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); |
3803 | 1 | _bfd_vms_output_short (recwr, EMH__C_SRC); |
3804 | | |
3805 | 1 | for (symnum = 0; symnum < abfd->symcount; symnum++) |
3806 | 0 | { |
3807 | 0 | symbol = abfd->outsymbols[symnum]; |
3808 | |
|
3809 | 0 | if (symbol->flags & BSF_FILE) |
3810 | 0 | { |
3811 | 0 | _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name, |
3812 | 0 | (int) strlen (symbol->name)); |
3813 | 0 | break; |
3814 | 0 | } |
3815 | 0 | } |
3816 | | |
3817 | 1 | if (symnum == abfd->symcount) |
3818 | 1 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname")); |
3819 | | |
3820 | 1 | if (!_bfd_vms_output_end (abfd, recwr)) |
3821 | 0 | return false; |
3822 | | |
3823 | | /* TTL. */ |
3824 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); |
3825 | 1 | _bfd_vms_output_short (recwr, EMH__C_TTL); |
3826 | 1 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL")); |
3827 | 1 | if (!_bfd_vms_output_end (abfd, recwr)) |
3828 | 0 | return false; |
3829 | | |
3830 | | /* CPR. */ |
3831 | 1 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); |
3832 | 1 | _bfd_vms_output_short (recwr, EMH__C_CPR); |
3833 | 1 | _bfd_vms_output_dump (recwr, |
3834 | 1 | (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996", |
3835 | 1 | 39); |
3836 | 1 | return _bfd_vms_output_end (abfd, recwr); |
3837 | 1 | } |
3838 | | |
3839 | | /* Part 4.6, relocations. */ |
3840 | | |
3841 | | |
3842 | | /* WRITE ETIR SECTION |
3843 | | |
3844 | | This is still under construction and therefore not documented. */ |
3845 | | |
3846 | | /* Close the etir/etbt record. */ |
3847 | | |
3848 | | static bool |
3849 | | end_etir_record (bfd * abfd) |
3850 | 0 | { |
3851 | 0 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3852 | |
|
3853 | 0 | return _bfd_vms_output_end (abfd, recwr); |
3854 | 0 | } |
3855 | | |
3856 | | static void |
3857 | | start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset) |
3858 | 0 | { |
3859 | 0 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3860 | |
|
3861 | 0 | if (section->flags & SEC_DEBUGGING) |
3862 | 0 | { |
3863 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_ETBT); |
3864 | |
|
3865 | 0 | if (offset == 0) |
3866 | 0 | { |
3867 | | /* Push start offset. */ |
3868 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); |
3869 | 0 | _bfd_vms_output_long (recwr, (unsigned long) 0); |
3870 | 0 | _bfd_vms_output_end_subrec (recwr); |
3871 | | |
3872 | | /* Set location. */ |
3873 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC); |
3874 | 0 | _bfd_vms_output_end_subrec (recwr); |
3875 | 0 | } |
3876 | 0 | } |
3877 | 0 | else |
3878 | 0 | { |
3879 | 0 | _bfd_vms_output_begin (recwr, EOBJ__C_ETIR); |
3880 | |
|
3881 | 0 | if (offset == 0) |
3882 | 0 | { |
3883 | | /* Push start offset. */ |
3884 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); |
3885 | 0 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); |
3886 | 0 | _bfd_vms_output_quad (recwr, offset); |
3887 | 0 | _bfd_vms_output_end_subrec (recwr); |
3888 | | |
3889 | | /* Start = pop (). */ |
3890 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB); |
3891 | 0 | _bfd_vms_output_end_subrec (recwr); |
3892 | 0 | } |
3893 | 0 | } |
3894 | 0 | } |
3895 | | |
3896 | | /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual |
3897 | | address VADDR in section specified by SEC_INDEX and NAME. */ |
3898 | | |
3899 | | static bool |
3900 | | sto_imm (bfd *abfd, asection *section, |
3901 | | bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr) |
3902 | 0 | { |
3903 | 0 | bfd_size_type size; |
3904 | 0 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3905 | |
|
3906 | | #if VMS_DEBUG |
3907 | | _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize); |
3908 | | _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr); |
3909 | | #endif |
3910 | |
|
3911 | 0 | while (ssize > 0) |
3912 | 0 | { |
3913 | | /* Try all the rest. */ |
3914 | 0 | size = ssize; |
3915 | |
|
3916 | 0 | if (_bfd_vms_output_check (recwr, size) < 0) |
3917 | 0 | { |
3918 | | /* Doesn't fit, split ! */ |
3919 | 0 | if (!end_etir_record (abfd)) |
3920 | 0 | return false; |
3921 | | |
3922 | 0 | start_etir_or_etbt_record (abfd, section, vaddr); |
3923 | |
|
3924 | 0 | size = _bfd_vms_output_check (recwr, 0); /* get max size */ |
3925 | 0 | if (size > ssize) /* more than what's left ? */ |
3926 | 0 | size = ssize; |
3927 | 0 | } |
3928 | | |
3929 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM); |
3930 | 0 | _bfd_vms_output_long (recwr, (unsigned long) (size)); |
3931 | 0 | _bfd_vms_output_dump (recwr, cptr, size); |
3932 | 0 | _bfd_vms_output_end_subrec (recwr); |
3933 | |
|
3934 | | #if VMS_DEBUG |
3935 | | _bfd_vms_debug (10, "dumped %d bytes\n", (int) size); |
3936 | | _bfd_hexdump (10, cptr, (int) size, (int) vaddr); |
3937 | | #endif |
3938 | |
|
3939 | 0 | vaddr += size; |
3940 | 0 | cptr += size; |
3941 | 0 | ssize -= size; |
3942 | 0 | } |
3943 | 0 | return true; |
3944 | 0 | } |
3945 | | |
3946 | | static bool |
3947 | | etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen) |
3948 | 0 | { |
3949 | 0 | if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0) |
3950 | 0 | { |
3951 | | /* Not enough room in this record. Close it and open a new one. */ |
3952 | 0 | if (!end_etir_record (abfd)) |
3953 | 0 | return false; |
3954 | 0 | start_etir_or_etbt_record (abfd, section, vaddr); |
3955 | 0 | } |
3956 | 0 | return true; |
3957 | 0 | } |
3958 | | |
3959 | | /* Return whether RELOC must be deferred till the end. */ |
3960 | | |
3961 | | static bool |
3962 | | defer_reloc_p (arelent *reloc) |
3963 | 0 | { |
3964 | 0 | switch (reloc->howto->type) |
3965 | 0 | { |
3966 | 0 | case ALPHA_R_NOP: |
3967 | 0 | case ALPHA_R_LDA: |
3968 | 0 | case ALPHA_R_BSR: |
3969 | 0 | case ALPHA_R_BOH: |
3970 | 0 | return true; |
3971 | | |
3972 | 0 | default: |
3973 | 0 | return false; |
3974 | 0 | } |
3975 | 0 | } |
3976 | | |
3977 | | /* Write section contents for bfd abfd. Return FALSE on error. */ |
3978 | | |
3979 | | static bool |
3980 | | _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) |
3981 | 1 | { |
3982 | 1 | asection *section; |
3983 | 1 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3984 | | |
3985 | 1 | vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype)); |
3986 | | |
3987 | 1 | _bfd_vms_output_alignment (recwr, 4); |
3988 | | |
3989 | 1 | PRIV (vms_linkage_index) = 0; |
3990 | | |
3991 | 1 | for (section = abfd->sections; section; section = section->next) |
3992 | 1 | { |
3993 | 1 | vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n", |
3994 | 1 | section->target_index, section->name, (int) (section->size))); |
3995 | | |
3996 | 1 | if (!(section->flags & SEC_HAS_CONTENTS) |
3997 | 1 | || bfd_is_com_section (section)) |
3998 | 0 | continue; |
3999 | | |
4000 | 1 | if (!section->contents) |
4001 | 1 | { |
4002 | 1 | bfd_set_error (bfd_error_no_contents); |
4003 | 1 | return false; |
4004 | 1 | } |
4005 | | |
4006 | 0 | start_etir_or_etbt_record (abfd, section, 0); |
4007 | |
|
4008 | 0 | if (section->flags & SEC_RELOC) |
4009 | 0 | { |
4010 | 0 | bfd_vma curr_addr = 0; |
4011 | 0 | unsigned char *curr_data = section->contents; |
4012 | 0 | bfd_size_type size; |
4013 | 0 | int pass2_needed = 0; |
4014 | 0 | int pass2_in_progress = 0; |
4015 | 0 | unsigned int irel; |
4016 | |
|
4017 | 0 | if (section->reloc_count == 0) |
4018 | 0 | _bfd_error_handler |
4019 | 0 | (_("SEC_RELOC with no relocs in section %pA"), section); |
4020 | |
|
4021 | | #if VMS_DEBUG |
4022 | | else |
4023 | | { |
4024 | | int i = section->reloc_count; |
4025 | | arelent **rptr = section->orelocation; |
4026 | | _bfd_vms_debug (4, "%d relocations:\n", i); |
4027 | | while (i-- > 0) |
4028 | | { |
4029 | | _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, " |
4030 | | "addr %08lx, off %08lx, len %d: %s\n", |
4031 | | (*(*rptr)->sym_ptr_ptr)->name, |
4032 | | (*(*rptr)->sym_ptr_ptr)->section->name, |
4033 | | (long) (*(*rptr)->sym_ptr_ptr)->value, |
4034 | | (unsigned long)(*rptr)->address, |
4035 | | (unsigned long)(*rptr)->addend, |
4036 | | bfd_get_reloc_size ((*rptr)->howto), |
4037 | | ( *rptr)->howto->name); |
4038 | | rptr++; |
4039 | | } |
4040 | | } |
4041 | | #endif |
4042 | |
|
4043 | 0 | new_pass: |
4044 | 0 | for (irel = 0; irel < section->reloc_count; irel++) |
4045 | 0 | { |
4046 | 0 | struct evax_private_udata_struct *udata; |
4047 | 0 | arelent *rptr = section->orelocation [irel]; |
4048 | 0 | bfd_vma addr = rptr->address; |
4049 | 0 | asymbol *sym = *rptr->sym_ptr_ptr; |
4050 | 0 | asection *sec = sym->section; |
4051 | 0 | bool defer = defer_reloc_p (rptr); |
4052 | 0 | unsigned int slen; |
4053 | |
|
4054 | 0 | if (pass2_in_progress) |
4055 | 0 | { |
4056 | | /* Non-deferred relocs have already been output. */ |
4057 | 0 | if (!defer) |
4058 | 0 | continue; |
4059 | 0 | } |
4060 | 0 | else |
4061 | 0 | { |
4062 | | /* Deferred relocs must be output at the very end. */ |
4063 | 0 | if (defer) |
4064 | 0 | { |
4065 | 0 | pass2_needed = 1; |
4066 | 0 | continue; |
4067 | 0 | } |
4068 | | |
4069 | | /* Regular relocs are intertwined with binary data. */ |
4070 | 0 | if (curr_addr > addr) |
4071 | 0 | _bfd_error_handler (_("size error in section %pA"), |
4072 | 0 | section); |
4073 | 0 | size = addr - curr_addr; |
4074 | 0 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4075 | 0 | return false; |
4076 | 0 | curr_data += size; |
4077 | 0 | curr_addr += size; |
4078 | 0 | } |
4079 | | |
4080 | 0 | size = bfd_get_reloc_size (rptr->howto); |
4081 | |
|
4082 | 0 | switch (rptr->howto->type) |
4083 | 0 | { |
4084 | 0 | case ALPHA_R_IGNORE: |
4085 | 0 | break; |
4086 | | |
4087 | 0 | case ALPHA_R_REFLONG: |
4088 | 0 | if (bfd_is_und_section (sym->section)) |
4089 | 0 | { |
4090 | 0 | bfd_vma addend = rptr->addend; |
4091 | 0 | slen = strlen ((char *) sym->name); |
4092 | 0 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4093 | 0 | return false; |
4094 | 0 | if (addend) |
4095 | 0 | { |
4096 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); |
4097 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4098 | 0 | _bfd_vms_output_end_subrec (recwr); |
4099 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); |
4100 | 0 | _bfd_vms_output_long (recwr, (unsigned long) addend); |
4101 | 0 | _bfd_vms_output_end_subrec (recwr); |
4102 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); |
4103 | 0 | _bfd_vms_output_end_subrec (recwr); |
4104 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); |
4105 | 0 | _bfd_vms_output_end_subrec (recwr); |
4106 | 0 | } |
4107 | 0 | else |
4108 | 0 | { |
4109 | 0 | _bfd_vms_output_begin_subrec |
4110 | 0 | (recwr, ETIR__C_STO_GBL_LW); |
4111 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4112 | 0 | _bfd_vms_output_end_subrec (recwr); |
4113 | 0 | } |
4114 | 0 | } |
4115 | 0 | else if (bfd_is_abs_section (sym->section)) |
4116 | 0 | { |
4117 | 0 | if (!etir_output_check (abfd, section, curr_addr, 16)) |
4118 | 0 | return false; |
4119 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); |
4120 | 0 | _bfd_vms_output_long (recwr, (unsigned long) sym->value); |
4121 | 0 | _bfd_vms_output_end_subrec (recwr); |
4122 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); |
4123 | 0 | _bfd_vms_output_end_subrec (recwr); |
4124 | 0 | } |
4125 | 0 | else |
4126 | 0 | { |
4127 | 0 | if (!etir_output_check (abfd, section, curr_addr, 32)) |
4128 | 0 | return false; |
4129 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); |
4130 | 0 | _bfd_vms_output_long (recwr, |
4131 | 0 | (unsigned long) sec->target_index); |
4132 | 0 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4133 | 0 | _bfd_vms_output_end_subrec (recwr); |
4134 | | /* ??? Table B-8 of the OpenVMS Linker Utilily Manual |
4135 | | says that we should have a ETIR__C_STO_OFF here. |
4136 | | But the relocation would not be BFD_RELOC_32 then. |
4137 | | This case is very likely unreachable. */ |
4138 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); |
4139 | 0 | _bfd_vms_output_end_subrec (recwr); |
4140 | 0 | } |
4141 | 0 | break; |
4142 | | |
4143 | 0 | case ALPHA_R_REFQUAD: |
4144 | 0 | if (bfd_is_und_section (sym->section)) |
4145 | 0 | { |
4146 | 0 | bfd_vma addend = rptr->addend; |
4147 | 0 | slen = strlen ((char *) sym->name); |
4148 | 0 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4149 | 0 | return false; |
4150 | 0 | if (addend) |
4151 | 0 | { |
4152 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); |
4153 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4154 | 0 | _bfd_vms_output_end_subrec (recwr); |
4155 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); |
4156 | 0 | _bfd_vms_output_quad (recwr, addend); |
4157 | 0 | _bfd_vms_output_end_subrec (recwr); |
4158 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); |
4159 | 0 | _bfd_vms_output_end_subrec (recwr); |
4160 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); |
4161 | 0 | _bfd_vms_output_end_subrec (recwr); |
4162 | 0 | } |
4163 | 0 | else |
4164 | 0 | { |
4165 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL); |
4166 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4167 | 0 | _bfd_vms_output_end_subrec (recwr); |
4168 | 0 | } |
4169 | 0 | } |
4170 | 0 | else if (bfd_is_abs_section (sym->section)) |
4171 | 0 | { |
4172 | 0 | if (!etir_output_check (abfd, section, curr_addr, 16)) |
4173 | 0 | return false; |
4174 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); |
4175 | 0 | _bfd_vms_output_quad (recwr, sym->value); |
4176 | 0 | _bfd_vms_output_end_subrec (recwr); |
4177 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); |
4178 | 0 | _bfd_vms_output_end_subrec (recwr); |
4179 | 0 | } |
4180 | 0 | else |
4181 | 0 | { |
4182 | 0 | if (!etir_output_check (abfd, section, curr_addr, 32)) |
4183 | 0 | return false; |
4184 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); |
4185 | 0 | _bfd_vms_output_long (recwr, |
4186 | 0 | (unsigned long) sec->target_index); |
4187 | 0 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4188 | 0 | _bfd_vms_output_end_subrec (recwr); |
4189 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF); |
4190 | 0 | _bfd_vms_output_end_subrec (recwr); |
4191 | 0 | } |
4192 | 0 | break; |
4193 | | |
4194 | 0 | case ALPHA_R_HINT: |
4195 | 0 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4196 | 0 | return false; |
4197 | 0 | break; |
4198 | | |
4199 | 0 | case ALPHA_R_LINKAGE: |
4200 | 0 | size = 16; |
4201 | 0 | if (!etir_output_check (abfd, section, curr_addr, 64)) |
4202 | 0 | return false; |
4203 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB); |
4204 | 0 | _bfd_vms_output_long |
4205 | 0 | (recwr, (unsigned long) rptr->addend); |
4206 | 0 | if (rptr->addend > PRIV (vms_linkage_index)) |
4207 | 0 | PRIV (vms_linkage_index) = rptr->addend; |
4208 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4209 | 0 | _bfd_vms_output_byte (recwr, 0); |
4210 | 0 | _bfd_vms_output_end_subrec (recwr); |
4211 | 0 | break; |
4212 | | |
4213 | 0 | case ALPHA_R_CODEADDR: |
4214 | 0 | slen = strlen ((char *) sym->name); |
4215 | 0 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4216 | 0 | return false; |
4217 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA); |
4218 | 0 | _bfd_vms_output_counted (recwr, sym->name); |
4219 | 0 | _bfd_vms_output_end_subrec (recwr); |
4220 | 0 | break; |
4221 | | |
4222 | 0 | case ALPHA_R_NOP: |
4223 | 0 | udata |
4224 | 0 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; |
4225 | 0 | if (!etir_output_check (abfd, section, curr_addr, |
4226 | 0 | 32 + 1 + strlen (udata->origname))) |
4227 | 0 | return false; |
4228 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL); |
4229 | 0 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); |
4230 | 0 | _bfd_vms_output_long |
4231 | 0 | (recwr, (unsigned long) section->target_index); |
4232 | 0 | _bfd_vms_output_quad (recwr, rptr->address); |
4233 | 0 | _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f); |
4234 | 0 | _bfd_vms_output_long |
4235 | 0 | (recwr, (unsigned long) section->target_index); |
4236 | 0 | _bfd_vms_output_quad (recwr, rptr->addend); |
4237 | 0 | _bfd_vms_output_counted (recwr, udata->origname); |
4238 | 0 | _bfd_vms_output_end_subrec (recwr); |
4239 | 0 | break; |
4240 | | |
4241 | 0 | case ALPHA_R_BSR: |
4242 | 0 | _bfd_error_handler (_("spurious ALPHA_R_BSR reloc")); |
4243 | 0 | break; |
4244 | | |
4245 | 0 | case ALPHA_R_LDA: |
4246 | 0 | udata |
4247 | 0 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; |
4248 | 0 | if (!etir_output_check (abfd, section, curr_addr, |
4249 | 0 | 32 + 1 + strlen (udata->origname))) |
4250 | 0 | return false; |
4251 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL); |
4252 | 0 | _bfd_vms_output_long |
4253 | 0 | (recwr, (unsigned long) udata->lkindex + 1); |
4254 | 0 | _bfd_vms_output_long |
4255 | 0 | (recwr, (unsigned long) section->target_index); |
4256 | 0 | _bfd_vms_output_quad (recwr, rptr->address); |
4257 | 0 | _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000); |
4258 | 0 | _bfd_vms_output_long |
4259 | 0 | (recwr, (unsigned long) udata->bsym->section->target_index); |
4260 | 0 | _bfd_vms_output_quad (recwr, rptr->addend); |
4261 | 0 | _bfd_vms_output_counted (recwr, udata->origname); |
4262 | 0 | _bfd_vms_output_end_subrec (recwr); |
4263 | 0 | break; |
4264 | | |
4265 | 0 | case ALPHA_R_BOH: |
4266 | 0 | udata |
4267 | 0 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; |
4268 | 0 | if (!etir_output_check (abfd, section, curr_addr, |
4269 | 0 | 32 + 1 + strlen (udata->origname))) |
4270 | 0 | return false; |
4271 | 0 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL); |
4272 | 0 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); |
4273 | 0 | _bfd_vms_output_long |
4274 | 0 | (recwr, (unsigned long) section->target_index); |
4275 | 0 | _bfd_vms_output_quad (recwr, rptr->address); |
4276 | 0 | _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000); |
4277 | 0 | _bfd_vms_output_long |
4278 | 0 | (recwr, (unsigned long) section->target_index); |
4279 | 0 | _bfd_vms_output_quad (recwr, rptr->addend); |
4280 | 0 | _bfd_vms_output_counted (recwr, udata->origname); |
4281 | 0 | _bfd_vms_output_end_subrec (recwr); |
4282 | 0 | break; |
4283 | | |
4284 | 0 | default: |
4285 | 0 | _bfd_error_handler (_("unhandled relocation %s"), |
4286 | 0 | rptr->howto->name); |
4287 | 0 | break; |
4288 | 0 | } |
4289 | | |
4290 | 0 | curr_data += size; |
4291 | 0 | curr_addr += size; |
4292 | 0 | } /* End of relocs loop. */ |
4293 | | |
4294 | 0 | if (!pass2_in_progress) |
4295 | 0 | { |
4296 | | /* Output rest of section. */ |
4297 | 0 | if (curr_addr > section->size) |
4298 | 0 | { |
4299 | 0 | _bfd_error_handler (_("size error in section %pA"), section); |
4300 | 0 | return false; |
4301 | 0 | } |
4302 | 0 | size = section->size - curr_addr; |
4303 | 0 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4304 | 0 | return false; |
4305 | 0 | curr_data += size; |
4306 | 0 | curr_addr += size; |
4307 | |
|
4308 | 0 | if (pass2_needed) |
4309 | 0 | { |
4310 | 0 | pass2_in_progress = 1; |
4311 | 0 | goto new_pass; |
4312 | 0 | } |
4313 | 0 | } |
4314 | 0 | } |
4315 | | |
4316 | 0 | else /* (section->flags & SEC_RELOC) */ |
4317 | 0 | if (!sto_imm (abfd, section, section->size, section->contents, 0)) |
4318 | 0 | return false; |
4319 | | |
4320 | 0 | if (!end_etir_record (abfd)) |
4321 | 0 | return false; |
4322 | 0 | } |
4323 | | |
4324 | 0 | _bfd_vms_output_alignment (recwr, 2); |
4325 | 0 | return true; |
4326 | 1 | } |
4327 | | |
4328 | | /* Write cached information into a file being written, at bfd_close. */ |
4329 | | |
4330 | | static bool |
4331 | | alpha_vms_write_object_contents (bfd *abfd) |
4332 | 6 | { |
4333 | 6 | vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd)); |
4334 | | |
4335 | 6 | if (abfd->flags & (EXEC_P | DYNAMIC)) |
4336 | 3 | { |
4337 | 3 | return alpha_vms_write_exec (abfd); |
4338 | 3 | } |
4339 | 3 | else |
4340 | 3 | { |
4341 | 3 | if (abfd->section_count > 0) /* we have sections */ |
4342 | 1 | { |
4343 | 1 | if (!_bfd_vms_write_ehdr (abfd)) |
4344 | 0 | return false; |
4345 | 1 | if (!_bfd_vms_write_egsd (abfd)) |
4346 | 0 | return false; |
4347 | 1 | if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR)) |
4348 | 1 | return false; |
4349 | 0 | if (!_bfd_vms_write_eeom (abfd)) |
4350 | 0 | return false; |
4351 | 0 | } |
4352 | 3 | } |
4353 | 2 | return true; |
4354 | 6 | } |
4355 | | |
4356 | | /* Debug stuff: nearest line. */ |
4357 | | |
4358 | | #define SET_MODULE_PARSED(m) \ |
4359 | 37 | do { if ((m)->name == NULL) (m)->name = ""; } while (0) |
4360 | 121 | #define IS_MODULE_PARSED(m) ((m)->name != NULL) |
4361 | | |
4362 | | /* Build a new module for the specified BFD. */ |
4363 | | |
4364 | | static struct module * |
4365 | | new_module (bfd *abfd) |
4366 | 823 | { |
4367 | 823 | struct module *module |
4368 | 823 | = (struct module *) bfd_zalloc (abfd, sizeof (struct module)); |
4369 | 823 | module->file_table_count = 16; /* Arbitrary. */ |
4370 | 823 | module->file_table |
4371 | 823 | = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo)); |
4372 | 823 | return module; |
4373 | 823 | } |
4374 | | |
4375 | | /* Parse debug info for a module and internalize it. */ |
4376 | | |
4377 | | static bool |
4378 | | parse_module (bfd *abfd, struct module *module, unsigned char *ptr, |
4379 | | bfd_size_type length) |
4380 | 37 | { |
4381 | 37 | unsigned char *maxptr = ptr + length; |
4382 | 37 | unsigned char *src_ptr, *pcl_ptr; |
4383 | 37 | unsigned int prev_linum = 0, curr_linenum = 0; |
4384 | 37 | bfd_vma prev_pc = 0, curr_pc = 0; |
4385 | 37 | struct srecinfo *curr_srec, *srec; |
4386 | 37 | struct lineinfo *curr_line, *line; |
4387 | 37 | struct funcinfo *funcinfo; |
4388 | | |
4389 | | /* Initialize tables with zero element. */ |
4390 | 37 | curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); |
4391 | 37 | if (!curr_srec) |
4392 | 0 | return false; |
4393 | 37 | module->srec_table = curr_srec; |
4394 | | |
4395 | 37 | curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); |
4396 | 37 | if (!curr_line) |
4397 | 0 | return false; |
4398 | 37 | module->line_table = curr_line; |
4399 | | |
4400 | 125 | while (ptr + 3 < maxptr) |
4401 | 101 | { |
4402 | | /* The first byte is not counted in the recorded length. */ |
4403 | 101 | int rec_length = bfd_getl16 (ptr) + 1; |
4404 | 101 | int rec_type = bfd_getl16 (ptr + 2); |
4405 | | |
4406 | 101 | vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type)); |
4407 | | |
4408 | 101 | if (rec_length > maxptr - ptr) |
4409 | 13 | break; |
4410 | 88 | if (rec_type == DST__K_MODEND) |
4411 | 0 | break; |
4412 | | |
4413 | 88 | switch (rec_type) |
4414 | 88 | { |
4415 | 0 | case DST__K_MODBEG: |
4416 | 0 | if (rec_length <= DST_S_B_MODBEG_NAME) |
4417 | 0 | break; |
4418 | 0 | module->name |
4419 | 0 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME, |
4420 | 0 | rec_length - DST_S_B_MODBEG_NAME); |
4421 | |
|
4422 | 0 | curr_pc = 0; |
4423 | 0 | prev_pc = 0; |
4424 | 0 | curr_linenum = 0; |
4425 | 0 | prev_linum = 0; |
4426 | |
|
4427 | 0 | vms_debug2 ((3, "module: %s\n", module->name)); |
4428 | 0 | break; |
4429 | | |
4430 | 0 | case DST__K_MODEND: |
4431 | 0 | break; |
4432 | | |
4433 | 0 | case DST__K_RTNBEG: |
4434 | 0 | if (rec_length <= DST_S_B_RTNBEG_NAME) |
4435 | 0 | break; |
4436 | 0 | funcinfo = (struct funcinfo *) |
4437 | 0 | bfd_zalloc (abfd, sizeof (struct funcinfo)); |
4438 | 0 | if (!funcinfo) |
4439 | 0 | return false; |
4440 | 0 | funcinfo->name |
4441 | 0 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME, |
4442 | 0 | rec_length - DST_S_B_RTNBEG_NAME); |
4443 | 0 | funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS); |
4444 | 0 | funcinfo->next = module->func_table; |
4445 | 0 | module->func_table = funcinfo; |
4446 | |
|
4447 | 0 | vms_debug2 ((3, "routine: %s at 0x%lx\n", |
4448 | 0 | funcinfo->name, (unsigned long) funcinfo->low)); |
4449 | 0 | break; |
4450 | | |
4451 | 0 | case DST__K_RTNEND: |
4452 | 0 | if (rec_length < DST_S_L_RTNEND_SIZE + 4) |
4453 | 0 | break; |
4454 | 0 | if (!module->func_table) |
4455 | 0 | return false; |
4456 | 0 | module->func_table->high = module->func_table->low |
4457 | 0 | + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1; |
4458 | |
|
4459 | 0 | if (module->func_table->high > module->high) |
4460 | 0 | module->high = module->func_table->high; |
4461 | |
|
4462 | 0 | vms_debug2 ((3, "end routine\n")); |
4463 | 0 | break; |
4464 | | |
4465 | 0 | case DST__K_PROLOG: |
4466 | 0 | vms_debug2 ((3, "prologue\n")); |
4467 | 0 | break; |
4468 | | |
4469 | 0 | case DST__K_EPILOG: |
4470 | 0 | vms_debug2 ((3, "epilog\n")); |
4471 | 0 | break; |
4472 | | |
4473 | 0 | case DST__K_BLKBEG: |
4474 | 0 | vms_debug2 ((3, "block\n")); |
4475 | 0 | break; |
4476 | | |
4477 | 0 | case DST__K_BLKEND: |
4478 | 0 | vms_debug2 ((3, "end block\n")); |
4479 | 0 | break; |
4480 | | |
4481 | 0 | case DST__K_SOURCE: |
4482 | 0 | src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE; |
4483 | |
|
4484 | 0 | vms_debug2 ((3, "source info\n")); |
4485 | |
|
4486 | 0 | while (src_ptr - ptr < rec_length) |
4487 | 0 | { |
4488 | 0 | int cmd = src_ptr[0], cmd_length, data; |
4489 | |
|
4490 | 0 | switch (cmd) |
4491 | 0 | { |
4492 | 0 | case DST__K_SRC_DECLFILE: |
4493 | 0 | if (src_ptr - ptr + DST_S_B_SRC_DF_LENGTH >= rec_length) |
4494 | 0 | cmd_length = 0x10000; |
4495 | 0 | else |
4496 | 0 | cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2; |
4497 | 0 | break; |
4498 | | |
4499 | 0 | case DST__K_SRC_DEFLINES_B: |
4500 | 0 | cmd_length = 2; |
4501 | 0 | break; |
4502 | | |
4503 | 0 | case DST__K_SRC_DEFLINES_W: |
4504 | 0 | cmd_length = 3; |
4505 | 0 | break; |
4506 | | |
4507 | 0 | case DST__K_SRC_INCRLNUM_B: |
4508 | 0 | cmd_length = 2; |
4509 | 0 | break; |
4510 | | |
4511 | 0 | case DST__K_SRC_SETFILE: |
4512 | 0 | cmd_length = 3; |
4513 | 0 | break; |
4514 | | |
4515 | 0 | case DST__K_SRC_SETLNUM_L: |
4516 | 0 | cmd_length = 5; |
4517 | 0 | break; |
4518 | | |
4519 | 0 | case DST__K_SRC_SETLNUM_W: |
4520 | 0 | cmd_length = 3; |
4521 | 0 | break; |
4522 | | |
4523 | 0 | case DST__K_SRC_SETREC_L: |
4524 | 0 | cmd_length = 5; |
4525 | 0 | break; |
4526 | | |
4527 | 0 | case DST__K_SRC_SETREC_W: |
4528 | 0 | cmd_length = 3; |
4529 | 0 | break; |
4530 | | |
4531 | 0 | case DST__K_SRC_FORMFEED: |
4532 | 0 | cmd_length = 1; |
4533 | 0 | break; |
4534 | | |
4535 | 0 | default: |
4536 | 0 | cmd_length = 2; |
4537 | 0 | break; |
4538 | 0 | } |
4539 | | |
4540 | 0 | if (src_ptr - ptr + cmd_length > rec_length) |
4541 | 0 | break; |
4542 | | |
4543 | 0 | switch (cmd) |
4544 | 0 | { |
4545 | 0 | case DST__K_SRC_DECLFILE: |
4546 | 0 | { |
4547 | 0 | unsigned int fileid |
4548 | 0 | = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID); |
4549 | 0 | char *filename = _bfd_vms_save_counted_string |
4550 | 0 | (abfd, |
4551 | 0 | src_ptr + DST_S_B_SRC_DF_FILENAME, |
4552 | 0 | ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME)); |
4553 | |
|
4554 | 0 | if (fileid >= module->file_table_count) |
4555 | 0 | { |
4556 | 0 | unsigned int old_count = module->file_table_count; |
4557 | 0 | module->file_table_count += fileid; |
4558 | 0 | module->file_table |
4559 | 0 | = bfd_realloc_or_free (module->file_table, |
4560 | 0 | module->file_table_count |
4561 | 0 | * sizeof (struct fileinfo)); |
4562 | 0 | if (module->file_table == NULL) |
4563 | 0 | return false; |
4564 | 0 | memset (module->file_table + old_count, 0, |
4565 | 0 | fileid * sizeof (struct fileinfo)); |
4566 | 0 | } |
4567 | | |
4568 | 0 | module->file_table [fileid].name = filename; |
4569 | 0 | module->file_table [fileid].srec = 1; |
4570 | 0 | vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n", |
4571 | 0 | fileid, module->file_table [fileid].name)); |
4572 | 0 | } |
4573 | 0 | break; |
4574 | | |
4575 | 0 | case DST__K_SRC_DEFLINES_B: |
4576 | | /* Perform the association and set the next higher index |
4577 | | to the limit. */ |
4578 | 0 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; |
4579 | 0 | srec = (struct srecinfo *) |
4580 | 0 | bfd_zalloc (abfd, sizeof (struct srecinfo)); |
4581 | 0 | srec->line = curr_srec->line + data; |
4582 | 0 | srec->srec = curr_srec->srec + data; |
4583 | 0 | srec->sfile = curr_srec->sfile; |
4584 | 0 | curr_srec->next = srec; |
4585 | 0 | curr_srec = srec; |
4586 | 0 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data)); |
4587 | 0 | break; |
4588 | | |
4589 | 0 | case DST__K_SRC_DEFLINES_W: |
4590 | | /* Perform the association and set the next higher index |
4591 | | to the limit. */ |
4592 | 0 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); |
4593 | 0 | srec = (struct srecinfo *) |
4594 | 0 | bfd_zalloc (abfd, sizeof (struct srecinfo)); |
4595 | 0 | srec->line = curr_srec->line + data; |
4596 | 0 | srec->srec = curr_srec->srec + data, |
4597 | 0 | srec->sfile = curr_srec->sfile; |
4598 | 0 | curr_srec->next = srec; |
4599 | 0 | curr_srec = srec; |
4600 | 0 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data)); |
4601 | 0 | break; |
4602 | | |
4603 | 0 | case DST__K_SRC_INCRLNUM_B: |
4604 | 0 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; |
4605 | 0 | curr_srec->line += data; |
4606 | 0 | vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data)); |
4607 | 0 | break; |
4608 | | |
4609 | 0 | case DST__K_SRC_SETFILE: |
4610 | 0 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); |
4611 | 0 | if ((unsigned int) data < module->file_table_count) |
4612 | 0 | { |
4613 | 0 | curr_srec->sfile = data; |
4614 | 0 | curr_srec->srec = module->file_table[data].srec; |
4615 | 0 | } |
4616 | 0 | vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data)); |
4617 | 0 | break; |
4618 | | |
4619 | 0 | case DST__K_SRC_SETLNUM_L: |
4620 | 0 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); |
4621 | 0 | curr_srec->line = data; |
4622 | 0 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data)); |
4623 | 0 | break; |
4624 | | |
4625 | 0 | case DST__K_SRC_SETLNUM_W: |
4626 | 0 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); |
4627 | 0 | curr_srec->line = data; |
4628 | 0 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data)); |
4629 | 0 | break; |
4630 | | |
4631 | 0 | case DST__K_SRC_SETREC_L: |
4632 | 0 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); |
4633 | 0 | curr_srec->srec = data; |
4634 | 0 | module->file_table[curr_srec->sfile].srec = data; |
4635 | 0 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data)); |
4636 | 0 | break; |
4637 | | |
4638 | 0 | case DST__K_SRC_SETREC_W: |
4639 | 0 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); |
4640 | 0 | curr_srec->srec = data; |
4641 | 0 | module->file_table[curr_srec->sfile].srec = data; |
4642 | 0 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data)); |
4643 | 0 | break; |
4644 | | |
4645 | 0 | case DST__K_SRC_FORMFEED: |
4646 | 0 | vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n")); |
4647 | 0 | break; |
4648 | | |
4649 | 0 | default: |
4650 | 0 | _bfd_error_handler (_("unknown source command %d"), |
4651 | 0 | cmd); |
4652 | 0 | break; |
4653 | 0 | } |
4654 | | |
4655 | 0 | src_ptr += cmd_length; |
4656 | 0 | } |
4657 | 0 | break; |
4658 | | |
4659 | 0 | case DST__K_LINE_NUM: |
4660 | 0 | pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE; |
4661 | |
|
4662 | 0 | vms_debug2 ((3, "line info\n")); |
4663 | |
|
4664 | 0 | while (pcl_ptr - ptr < rec_length) |
4665 | 0 | { |
4666 | | /* The command byte is signed so we must sign-extend it. */ |
4667 | 0 | int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data; |
4668 | |
|
4669 | 0 | switch (cmd) |
4670 | 0 | { |
4671 | 0 | case DST__K_DELTA_PC_W: |
4672 | 0 | cmd_length = 3; |
4673 | 0 | break; |
4674 | | |
4675 | 0 | case DST__K_DELTA_PC_L: |
4676 | 0 | cmd_length = 5; |
4677 | 0 | break; |
4678 | | |
4679 | 0 | case DST__K_INCR_LINUM: |
4680 | 0 | cmd_length = 2; |
4681 | 0 | break; |
4682 | | |
4683 | 0 | case DST__K_INCR_LINUM_W: |
4684 | 0 | cmd_length = 3; |
4685 | 0 | break; |
4686 | | |
4687 | 0 | case DST__K_INCR_LINUM_L: |
4688 | 0 | cmd_length = 5; |
4689 | 0 | break; |
4690 | | |
4691 | 0 | case DST__K_SET_LINUM_INCR: |
4692 | 0 | cmd_length = 2; |
4693 | 0 | break; |
4694 | | |
4695 | 0 | case DST__K_SET_LINUM_INCR_W: |
4696 | 0 | cmd_length = 3; |
4697 | 0 | break; |
4698 | | |
4699 | 0 | case DST__K_RESET_LINUM_INCR: |
4700 | 0 | cmd_length = 1; |
4701 | 0 | break; |
4702 | | |
4703 | 0 | case DST__K_BEG_STMT_MODE: |
4704 | 0 | cmd_length = 1; |
4705 | 0 | break; |
4706 | | |
4707 | 0 | case DST__K_END_STMT_MODE: |
4708 | 0 | cmd_length = 1; |
4709 | 0 | break; |
4710 | | |
4711 | 0 | case DST__K_SET_LINUM_B: |
4712 | 0 | cmd_length = 2; |
4713 | 0 | break; |
4714 | | |
4715 | 0 | case DST__K_SET_LINUM: |
4716 | 0 | cmd_length = 3; |
4717 | 0 | break; |
4718 | | |
4719 | 0 | case DST__K_SET_LINUM_L: |
4720 | 0 | cmd_length = 5; |
4721 | 0 | break; |
4722 | | |
4723 | 0 | case DST__K_SET_PC: |
4724 | 0 | cmd_length = 2; |
4725 | 0 | break; |
4726 | | |
4727 | 0 | case DST__K_SET_PC_W: |
4728 | 0 | cmd_length = 3; |
4729 | 0 | break; |
4730 | | |
4731 | 0 | case DST__K_SET_PC_L: |
4732 | 0 | cmd_length = 5; |
4733 | 0 | break; |
4734 | | |
4735 | 0 | case DST__K_SET_STMTNUM: |
4736 | 0 | cmd_length = 2; |
4737 | 0 | break; |
4738 | | |
4739 | 0 | case DST__K_TERM: |
4740 | 0 | cmd_length = 2; |
4741 | 0 | break; |
4742 | | |
4743 | 0 | case DST__K_TERM_W: |
4744 | 0 | cmd_length = 3; |
4745 | 0 | break; |
4746 | | |
4747 | 0 | case DST__K_TERM_L: |
4748 | 0 | cmd_length = 5; |
4749 | 0 | break; |
4750 | | |
4751 | 0 | case DST__K_SET_ABS_PC: |
4752 | 0 | cmd_length = 5; |
4753 | 0 | break; |
4754 | | |
4755 | 0 | default: |
4756 | 0 | if (cmd <= 0) |
4757 | 0 | cmd_length = 1; |
4758 | 0 | else |
4759 | 0 | cmd_length = 2; |
4760 | 0 | break; |
4761 | 0 | } |
4762 | | |
4763 | 0 | if (pcl_ptr - ptr + cmd_length > rec_length) |
4764 | 0 | break; |
4765 | | |
4766 | 0 | switch (cmd) |
4767 | 0 | { |
4768 | 0 | case DST__K_DELTA_PC_W: |
4769 | 0 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); |
4770 | 0 | curr_pc += data; |
4771 | 0 | curr_linenum += 1; |
4772 | 0 | vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data)); |
4773 | 0 | break; |
4774 | | |
4775 | 0 | case DST__K_DELTA_PC_L: |
4776 | 0 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); |
4777 | 0 | curr_pc += data; |
4778 | 0 | curr_linenum += 1; |
4779 | 0 | vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data)); |
4780 | 0 | break; |
4781 | | |
4782 | 0 | case DST__K_INCR_LINUM: |
4783 | 0 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; |
4784 | 0 | curr_linenum += data; |
4785 | 0 | vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data)); |
4786 | 0 | break; |
4787 | | |
4788 | 0 | case DST__K_INCR_LINUM_W: |
4789 | 0 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); |
4790 | 0 | curr_linenum += data; |
4791 | 0 | vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data)); |
4792 | 0 | break; |
4793 | | |
4794 | 0 | case DST__K_INCR_LINUM_L: |
4795 | 0 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); |
4796 | 0 | curr_linenum += data; |
4797 | 0 | vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data)); |
4798 | 0 | break; |
4799 | | |
4800 | 0 | case DST__K_SET_LINUM_INCR: |
4801 | 0 | _bfd_error_handler |
4802 | 0 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR"); |
4803 | 0 | break; |
4804 | | |
4805 | 0 | case DST__K_SET_LINUM_INCR_W: |
4806 | 0 | _bfd_error_handler |
4807 | 0 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W"); |
4808 | 0 | break; |
4809 | | |
4810 | 0 | case DST__K_RESET_LINUM_INCR: |
4811 | 0 | _bfd_error_handler |
4812 | 0 | (_("%s not implemented"), "DST__K_RESET_LINUM_INCR"); |
4813 | 0 | break; |
4814 | | |
4815 | 0 | case DST__K_BEG_STMT_MODE: |
4816 | 0 | _bfd_error_handler |
4817 | 0 | (_("%s not implemented"), "DST__K_BEG_STMT_MODE"); |
4818 | 0 | break; |
4819 | | |
4820 | 0 | case DST__K_END_STMT_MODE: |
4821 | 0 | _bfd_error_handler |
4822 | 0 | (_("%s not implemented"), "DST__K_END_STMT_MODE"); |
4823 | 0 | break; |
4824 | | |
4825 | 0 | case DST__K_SET_LINUM_B: |
4826 | 0 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; |
4827 | 0 | curr_linenum = data; |
4828 | 0 | vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data)); |
4829 | 0 | break; |
4830 | | |
4831 | 0 | case DST__K_SET_LINUM: |
4832 | 0 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); |
4833 | 0 | curr_linenum = data; |
4834 | 0 | vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data)); |
4835 | 0 | break; |
4836 | | |
4837 | 0 | case DST__K_SET_LINUM_L: |
4838 | 0 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); |
4839 | 0 | curr_linenum = data; |
4840 | 0 | vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data)); |
4841 | 0 | break; |
4842 | | |
4843 | 0 | case DST__K_SET_PC: |
4844 | 0 | _bfd_error_handler |
4845 | 0 | (_("%s not implemented"), "DST__K_SET_PC"); |
4846 | 0 | break; |
4847 | | |
4848 | 0 | case DST__K_SET_PC_W: |
4849 | 0 | _bfd_error_handler |
4850 | 0 | (_("%s not implemented"), "DST__K_SET_PC_W"); |
4851 | 0 | break; |
4852 | | |
4853 | 0 | case DST__K_SET_PC_L: |
4854 | 0 | _bfd_error_handler |
4855 | 0 | (_("%s not implemented"), "DST__K_SET_PC_L"); |
4856 | 0 | break; |
4857 | | |
4858 | 0 | case DST__K_SET_STMTNUM: |
4859 | 0 | _bfd_error_handler |
4860 | 0 | (_("%s not implemented"), "DST__K_SET_STMTNUM"); |
4861 | 0 | break; |
4862 | | |
4863 | 0 | case DST__K_TERM: |
4864 | 0 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; |
4865 | 0 | curr_pc += data; |
4866 | 0 | vms_debug2 ((4, "DST__K_TERM: %d\n", data)); |
4867 | 0 | break; |
4868 | | |
4869 | 0 | case DST__K_TERM_W: |
4870 | 0 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); |
4871 | 0 | curr_pc += data; |
4872 | 0 | vms_debug2 ((4, "DST__K_TERM_W: %d\n", data)); |
4873 | 0 | break; |
4874 | | |
4875 | 0 | case DST__K_TERM_L: |
4876 | 0 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); |
4877 | 0 | curr_pc += data; |
4878 | 0 | vms_debug2 ((4, "DST__K_TERM_L: %d\n", data)); |
4879 | 0 | break; |
4880 | | |
4881 | 0 | case DST__K_SET_ABS_PC: |
4882 | 0 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); |
4883 | 0 | curr_pc = data; |
4884 | 0 | vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data)); |
4885 | 0 | break; |
4886 | | |
4887 | 0 | default: |
4888 | 0 | if (cmd <= 0) |
4889 | 0 | { |
4890 | 0 | curr_pc -= cmd; |
4891 | 0 | curr_linenum += 1; |
4892 | 0 | vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n", |
4893 | 0 | (unsigned long)curr_pc, curr_linenum)); |
4894 | 0 | } |
4895 | 0 | else |
4896 | 0 | _bfd_error_handler (_("unknown line command %d"), cmd); |
4897 | 0 | break; |
4898 | 0 | } |
4899 | | |
4900 | 0 | if ((curr_linenum != prev_linum && curr_pc != prev_pc) |
4901 | 0 | || cmd <= 0 |
4902 | 0 | || cmd == DST__K_DELTA_PC_L |
4903 | 0 | || cmd == DST__K_DELTA_PC_W) |
4904 | 0 | { |
4905 | 0 | line = (struct lineinfo *) |
4906 | 0 | bfd_zalloc (abfd, sizeof (struct lineinfo)); |
4907 | 0 | line->address = curr_pc; |
4908 | 0 | line->line = curr_linenum; |
4909 | |
|
4910 | 0 | curr_line->next = line; |
4911 | 0 | curr_line = line; |
4912 | |
|
4913 | 0 | prev_linum = curr_linenum; |
4914 | 0 | prev_pc = curr_pc; |
4915 | 0 | vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n", |
4916 | 0 | (unsigned long)curr_pc, curr_linenum)); |
4917 | 0 | } |
4918 | |
|
4919 | 0 | pcl_ptr += cmd_length; |
4920 | 0 | } |
4921 | 0 | break; |
4922 | | |
4923 | 0 | case 0x17: /* Undocumented type used by DEC C to declare equates. */ |
4924 | 0 | vms_debug2 ((3, "undocumented type 0x17\n")); |
4925 | 0 | break; |
4926 | | |
4927 | 88 | default: |
4928 | 88 | vms_debug2 ((3, "ignoring record\n")); |
4929 | 88 | break; |
4930 | | |
4931 | 88 | } |
4932 | | |
4933 | 88 | ptr += rec_length; |
4934 | 88 | } |
4935 | | |
4936 | | /* Finalize tables with EOL marker. */ |
4937 | 37 | srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); |
4938 | 37 | srec->line = (unsigned int) -1; |
4939 | 37 | srec->srec = (unsigned int) -1; |
4940 | 37 | curr_srec->next = srec; |
4941 | | |
4942 | 37 | line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); |
4943 | 37 | line->line = (unsigned int) -1; |
4944 | 37 | line->address = (bfd_vma) -1; |
4945 | 37 | curr_line->next = line; |
4946 | | |
4947 | | /* Advertise that this module has been parsed. This is needed |
4948 | | because parsing can be either performed at module creation |
4949 | | or deferred until debug info is consumed. */ |
4950 | 37 | SET_MODULE_PARSED (module); |
4951 | 37 | return true; |
4952 | 37 | } |
4953 | | |
4954 | | /* Build the list of modules for the specified BFD. */ |
4955 | | |
4956 | | static struct module * |
4957 | | build_module_list (bfd *abfd) |
4958 | 105 | { |
4959 | 105 | struct module *module, *list = NULL; |
4960 | 105 | asection *dmt; |
4961 | | |
4962 | 105 | if ((dmt = bfd_get_section_by_name (abfd, "$DMT$"))) |
4963 | 96 | { |
4964 | | /* We have a DMT section so this must be an image. Parse the |
4965 | | section and build the list of modules. This is sufficient |
4966 | | since we can compute the start address and the end address |
4967 | | of every module from the section contents. */ |
4968 | 96 | bfd_size_type size = bfd_section_size (dmt); |
4969 | 96 | unsigned char *buf, *ptr, *end; |
4970 | | |
4971 | 96 | if (! bfd_malloc_and_get_section (abfd, dmt, &buf)) |
4972 | 26 | return NULL; |
4973 | | |
4974 | 70 | vms_debug2 ((2, "DMT\n")); |
4975 | | |
4976 | 70 | ptr = buf; |
4977 | 70 | end = ptr + size; |
4978 | 447 | while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE) |
4979 | 377 | { |
4980 | | /* Each header declares a module with its start offset and size |
4981 | | of debug info in the DST section, as well as the count of |
4982 | | program sections (i.e. address spans) it contains. */ |
4983 | 377 | unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG); |
4984 | 377 | unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE); |
4985 | 377 | int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT); |
4986 | 377 | ptr += DBG_S_C_DMT_HEADER_SIZE; |
4987 | | |
4988 | 377 | vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n", |
4989 | 377 | modbeg, msize, count)); |
4990 | | |
4991 | | /* We create a 'module' structure for each program section since |
4992 | | we only support contiguous addresses in a 'module' structure. |
4993 | | As a consequence, the actual debug info in the DST section is |
4994 | | shared and can be parsed multiple times; that doesn't seem to |
4995 | | cause problems in practice. */ |
4996 | 1.20k | while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE) |
4997 | 823 | { |
4998 | 823 | unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START); |
4999 | 823 | unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH); |
5000 | 823 | module = new_module (abfd); |
5001 | 823 | module->modbeg = modbeg; |
5002 | 823 | module->size = msize; |
5003 | 823 | module->low = start; |
5004 | 823 | module->high = start + length; |
5005 | 823 | module->next = list; |
5006 | 823 | list = module; |
5007 | 823 | ptr += DBG_S_C_DMT_PSECT_SIZE; |
5008 | | |
5009 | 823 | vms_debug2 ((4, "section: start = 0x%x, length = %u\n", |
5010 | 823 | start, length)); |
5011 | 823 | } |
5012 | 377 | } |
5013 | 70 | free (buf); |
5014 | 70 | } |
5015 | 9 | else |
5016 | 9 | { |
5017 | | /* We don't have a DMT section so this must be an object. Parse |
5018 | | the module right now in order to compute its start address and |
5019 | | end address. */ |
5020 | 9 | void *dst = PRIV (dst_section)->contents; |
5021 | | |
5022 | 9 | if (dst == NULL) |
5023 | 9 | return NULL; |
5024 | | |
5025 | 0 | module = new_module (abfd); |
5026 | 0 | if (!parse_module (abfd, module, PRIV (dst_section)->contents, |
5027 | 0 | PRIV (dst_section)->size)) |
5028 | 0 | return NULL; |
5029 | 0 | list = module; |
5030 | 0 | } |
5031 | | |
5032 | 70 | return list; |
5033 | 105 | } |
5034 | | |
5035 | | /* Calculate and return the name of the source file and the line nearest |
5036 | | to the wanted location in the specified module. */ |
5037 | | |
5038 | | static bool |
5039 | | module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr, |
5040 | | const char **file, const char **func, |
5041 | | unsigned int *line) |
5042 | 121 | { |
5043 | 121 | struct funcinfo *funcinfo; |
5044 | 121 | struct lineinfo *lineinfo; |
5045 | 121 | struct srecinfo *srecinfo; |
5046 | 121 | bool ret = false; |
5047 | | |
5048 | | /* Parse this module if that was not done at module creation. */ |
5049 | 121 | if (! IS_MODULE_PARSED (module)) |
5050 | 98 | { |
5051 | 98 | unsigned int size = module->size; |
5052 | 98 | unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg; |
5053 | 98 | unsigned char *buffer; |
5054 | | |
5055 | 98 | if (bfd_seek (abfd, modbeg, SEEK_SET) != 0 |
5056 | 98 | || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL) |
5057 | 61 | { |
5058 | 61 | bfd_set_error (bfd_error_no_debug_section); |
5059 | 61 | return false; |
5060 | 61 | } |
5061 | | |
5062 | 37 | ret = parse_module (abfd, module, buffer, size); |
5063 | 37 | free (buffer); |
5064 | 37 | if (!ret) |
5065 | 0 | return ret; |
5066 | 37 | } |
5067 | | |
5068 | | /* Find out the function (if any) that contains the address. */ |
5069 | 60 | for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next) |
5070 | 0 | if (addr >= funcinfo->low && addr <= funcinfo->high) |
5071 | 0 | { |
5072 | 0 | *func = funcinfo->name; |
5073 | 0 | ret = true; |
5074 | 0 | break; |
5075 | 0 | } |
5076 | | |
5077 | | /* Find out the source file and the line nearest to the address. */ |
5078 | 60 | for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next) |
5079 | 60 | if (lineinfo->next && addr < lineinfo->next->address) |
5080 | 60 | { |
5081 | 60 | for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next) |
5082 | 60 | if (srecinfo->next && lineinfo->line < srecinfo->next->line) |
5083 | 60 | { |
5084 | 60 | if (srecinfo->sfile > 0) |
5085 | 0 | { |
5086 | 0 | *file = module->file_table[srecinfo->sfile].name; |
5087 | 0 | *line = srecinfo->srec + lineinfo->line - srecinfo->line; |
5088 | 0 | } |
5089 | 60 | else |
5090 | 60 | { |
5091 | 60 | *file = module->name; |
5092 | 60 | *line = lineinfo->line; |
5093 | 60 | } |
5094 | 60 | return true; |
5095 | 60 | } |
5096 | | |
5097 | 0 | break; |
5098 | 60 | } |
5099 | | |
5100 | 0 | return ret; |
5101 | 60 | } |
5102 | | |
5103 | | /* Provided a BFD, a section and an offset into the section, calculate and |
5104 | | return the name of the source file and the line nearest to the wanted |
5105 | | location. */ |
5106 | | |
5107 | | static bool |
5108 | | _bfd_vms_find_nearest_line (bfd *abfd, |
5109 | | asymbol **symbols ATTRIBUTE_UNUSED, |
5110 | | asection *section, |
5111 | | bfd_vma offset, |
5112 | | const char **file, |
5113 | | const char **func, |
5114 | | unsigned int *line, |
5115 | | unsigned int *discriminator) |
5116 | 224 | { |
5117 | 224 | struct module *module; |
5118 | | |
5119 | | /* What address are we looking for? */ |
5120 | 224 | bfd_vma addr = section->vma + offset; |
5121 | | |
5122 | 224 | *file = NULL; |
5123 | 224 | *func = NULL; |
5124 | 224 | *line = 0; |
5125 | 224 | if (discriminator) |
5126 | 224 | *discriminator = 0; |
5127 | | |
5128 | | /* We can't do anything if there is no DST (debug symbol table). */ |
5129 | 224 | if (PRIV (dst_section) == NULL) |
5130 | 0 | return false; |
5131 | | |
5132 | | /* Create the module list - if not already done. */ |
5133 | 224 | if (PRIV (modules) == NULL) |
5134 | 105 | { |
5135 | 105 | PRIV (modules) = build_module_list (abfd); |
5136 | 105 | if (PRIV (modules) == NULL) |
5137 | 56 | return false; |
5138 | 105 | } |
5139 | | |
5140 | 1.36k | for (module = PRIV (modules); module; module = module->next) |
5141 | 1.31k | if (addr >= module->low && addr <= module->high) |
5142 | 121 | return module_find_nearest_line (abfd, module, addr, file, func, line); |
5143 | | |
5144 | 47 | return false; |
5145 | 168 | } |
5146 | | |
5147 | | /* Canonicalizations. */ |
5148 | | /* Set name, value, section and flags of SYM from E. */ |
5149 | | |
5150 | | static bool |
5151 | | alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym) |
5152 | 38 | { |
5153 | 38 | flagword flags; |
5154 | 38 | symvalue value; |
5155 | 38 | asection *sec; |
5156 | 38 | const char *name; |
5157 | | |
5158 | 38 | name = e->name; |
5159 | 38 | value = 0; |
5160 | 38 | flags = BSF_NO_FLAGS; |
5161 | 38 | sec = NULL; |
5162 | | |
5163 | 38 | switch (e->typ) |
5164 | 38 | { |
5165 | 38 | case EGSD__C_SYM: |
5166 | 38 | if (e->flags & EGSY__V_WEAK) |
5167 | 2 | flags |= BSF_WEAK; |
5168 | | |
5169 | 38 | if (e->flags & EGSY__V_DEF) |
5170 | 0 | { |
5171 | | /* Symbol definition. */ |
5172 | 0 | flags |= BSF_GLOBAL; |
5173 | 0 | if (e->flags & EGSY__V_NORM) |
5174 | 0 | flags |= BSF_FUNCTION; |
5175 | 0 | value = e->value; |
5176 | 0 | sec = e->section; |
5177 | 0 | } |
5178 | 38 | else |
5179 | 38 | { |
5180 | | /* Symbol reference. */ |
5181 | 38 | sec = bfd_und_section_ptr; |
5182 | 38 | } |
5183 | 38 | break; |
5184 | | |
5185 | 0 | case EGSD__C_SYMG: |
5186 | | /* A universal symbol is by definition global... */ |
5187 | 0 | flags |= BSF_GLOBAL; |
5188 | | |
5189 | | /* ...and dynamic in shared libraries. */ |
5190 | 0 | if (abfd->flags & DYNAMIC) |
5191 | 0 | flags |= BSF_DYNAMIC; |
5192 | |
|
5193 | 0 | if (e->flags & EGSY__V_WEAK) |
5194 | 0 | flags |= BSF_WEAK; |
5195 | |
|
5196 | 0 | if (!(e->flags & EGSY__V_DEF)) |
5197 | 0 | abort (); |
5198 | | |
5199 | 0 | if (e->flags & EGSY__V_NORM) |
5200 | 0 | flags |= BSF_FUNCTION; |
5201 | |
|
5202 | 0 | value = e->value; |
5203 | | /* sec = e->section; */ |
5204 | 0 | sec = bfd_abs_section_ptr; |
5205 | 0 | break; |
5206 | | |
5207 | 0 | default: |
5208 | 0 | return false; |
5209 | 38 | } |
5210 | | |
5211 | 38 | sym->name = name; |
5212 | 38 | sym->section = sec; |
5213 | 38 | sym->flags = flags; |
5214 | 38 | sym->value = value; |
5215 | 38 | return true; |
5216 | 38 | } |
5217 | | |
5218 | | |
5219 | | /* Return the number of bytes required to store a vector of pointers |
5220 | | to asymbols for all the symbols in the BFD abfd, including a |
5221 | | terminal NULL pointer. If there are no symbols in the BFD, |
5222 | | then return 0. If an error occurs, return -1. */ |
5223 | | |
5224 | | static long |
5225 | | alpha_vms_get_symtab_upper_bound (bfd *abfd) |
5226 | 15 | { |
5227 | 15 | vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n", |
5228 | 15 | abfd, PRIV (gsd_sym_count))); |
5229 | | |
5230 | 15 | return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *); |
5231 | 15 | } |
5232 | | |
5233 | | /* Read the symbols from the BFD abfd, and fills in the vector |
5234 | | location with pointers to the symbols and a trailing NULL. |
5235 | | |
5236 | | Return number of symbols read. */ |
5237 | | |
5238 | | static long |
5239 | | alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols) |
5240 | 21 | { |
5241 | 21 | unsigned int i; |
5242 | | |
5243 | 21 | vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd)); |
5244 | | |
5245 | 21 | if (PRIV (csymbols) == NULL) |
5246 | 14 | { |
5247 | 14 | PRIV (csymbols) = (asymbol **) bfd_alloc |
5248 | 14 | (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *)); |
5249 | | |
5250 | | /* Traverse table and fill symbols vector. */ |
5251 | 52 | for (i = 0; i < PRIV (gsd_sym_count); i++) |
5252 | 38 | { |
5253 | 38 | struct vms_symbol_entry *e = PRIV (syms)[i]; |
5254 | 38 | asymbol *sym; |
5255 | | |
5256 | 38 | sym = bfd_make_empty_symbol (abfd); |
5257 | 38 | if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym)) |
5258 | 0 | { |
5259 | 0 | bfd_release (abfd, PRIV (csymbols)); |
5260 | 0 | PRIV (csymbols) = NULL; |
5261 | 0 | return -1; |
5262 | 0 | } |
5263 | | |
5264 | 38 | PRIV (csymbols)[i] = sym; |
5265 | 38 | } |
5266 | 14 | } |
5267 | | |
5268 | 21 | if (symbols != NULL) |
5269 | 15 | { |
5270 | 63 | for (i = 0; i < PRIV (gsd_sym_count); i++) |
5271 | 48 | symbols[i] = PRIV (csymbols)[i]; |
5272 | 15 | symbols[i] = NULL; |
5273 | 15 | } |
5274 | | |
5275 | 21 | return PRIV (gsd_sym_count); |
5276 | 21 | } |
5277 | | |
5278 | | /* Read and convert relocations from ETIR. We do it once for all sections. */ |
5279 | | |
5280 | | static bool |
5281 | | alpha_vms_slurp_relocs (bfd *abfd) |
5282 | 6 | { |
5283 | 6 | int cur_psect = -1; |
5284 | | |
5285 | 6 | vms_debug2 ((3, "alpha_vms_slurp_relocs\n")); |
5286 | | |
5287 | | /* We slurp relocs only once, for all sections. */ |
5288 | 6 | if (PRIV (reloc_done) != 0) |
5289 | 0 | return PRIV (reloc_done) == 1; |
5290 | | |
5291 | 6 | if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0) |
5292 | 0 | goto fail; |
5293 | | |
5294 | 6 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) |
5295 | 0 | goto fail; |
5296 | | |
5297 | 8 | while (1) |
5298 | 8 | { |
5299 | 8 | unsigned char *begin; |
5300 | 8 | unsigned char *end; |
5301 | 8 | unsigned char *ptr; |
5302 | 8 | bfd_reloc_code_real_type reloc_code; |
5303 | 8 | int type; |
5304 | 8 | bfd_vma vaddr = 0; |
5305 | | |
5306 | 8 | int length; |
5307 | | |
5308 | 8 | bfd_vma cur_address; |
5309 | 8 | int cur_psidx = -1; |
5310 | 8 | unsigned char *cur_sym = NULL; |
5311 | 8 | int prev_cmd = -1; |
5312 | 8 | bfd_vma cur_addend = 0; |
5313 | | |
5314 | | /* Skip non-ETIR records. */ |
5315 | 8 | type = _bfd_vms_get_object_record (abfd); |
5316 | 8 | if (type < 0) |
5317 | 4 | goto fail; |
5318 | 4 | if (type == EOBJ__C_EEOM) |
5319 | 0 | break; |
5320 | 4 | if (type != EOBJ__C_ETIR) |
5321 | 2 | continue; |
5322 | | |
5323 | 2 | begin = PRIV (recrd.rec) + 4; |
5324 | 2 | end = PRIV (recrd.rec) + PRIV (recrd.rec_size); |
5325 | | |
5326 | 2 | for (ptr = begin; ptr + 4 <= end; ptr += length) |
5327 | 2 | { |
5328 | 2 | int cmd; |
5329 | | |
5330 | 2 | cmd = bfd_getl16 (ptr); |
5331 | 2 | length = bfd_getl16 (ptr + 2); |
5332 | 2 | if (length < 4 || length > end - ptr) |
5333 | 2 | { |
5334 | 2 | bad_rec: |
5335 | 2 | _bfd_error_handler (_("corrupt reloc record")); |
5336 | 2 | goto fail; |
5337 | 2 | } |
5338 | | |
5339 | 0 | cur_address = vaddr; |
5340 | |
|
5341 | 0 | vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n", |
5342 | 0 | _bfd_vms_etir_name (cmd))); |
5343 | |
|
5344 | 0 | switch (cmd) |
5345 | 0 | { |
5346 | 0 | case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */ |
5347 | | /* ALPHA_R_REFQUAD und_section, step 1 */ |
5348 | 0 | cur_sym = ptr + 4; |
5349 | 0 | prev_cmd = cmd; |
5350 | 0 | continue; |
5351 | | |
5352 | 0 | case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */ |
5353 | 0 | if (length < 16) |
5354 | 0 | goto bad_rec; |
5355 | 0 | cur_psidx = bfd_getl32 (ptr + 4); |
5356 | 0 | cur_addend = bfd_getl64 (ptr + 8); |
5357 | 0 | prev_cmd = cmd; |
5358 | 0 | continue; |
5359 | | |
5360 | 0 | case ETIR__C_CTL_SETRB: |
5361 | 0 | if (prev_cmd != ETIR__C_STA_PQ) |
5362 | 0 | { |
5363 | 0 | _bfd_error_handler |
5364 | | /* xgettext:c-format */ |
5365 | 0 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), |
5366 | 0 | _bfd_vms_etir_name (cmd)); |
5367 | 0 | goto fail; |
5368 | 0 | } |
5369 | 0 | cur_psect = cur_psidx; |
5370 | 0 | vaddr = cur_addend; |
5371 | 0 | cur_psidx = -1; |
5372 | 0 | cur_addend = 0; |
5373 | 0 | continue; |
5374 | | |
5375 | 0 | case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */ |
5376 | | /* ALPHA_R_REFLONG und_section, step 2 */ |
5377 | 0 | if (prev_cmd != -1) |
5378 | 0 | { |
5379 | 0 | if (prev_cmd != ETIR__C_STA_GBL) |
5380 | 0 | { |
5381 | 0 | _bfd_error_handler |
5382 | | /* xgettext:c-format */ |
5383 | 0 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
5384 | 0 | _bfd_vms_etir_name (ETIR__C_STA_LW)); |
5385 | 0 | goto fail; |
5386 | 0 | } |
5387 | 0 | } |
5388 | 0 | if (length < 8) |
5389 | 0 | goto bad_rec; |
5390 | 0 | cur_addend = bfd_getl32 (ptr + 4); |
5391 | 0 | prev_cmd = cmd; |
5392 | 0 | continue; |
5393 | | |
5394 | 0 | case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */ |
5395 | | /* ALPHA_R_REFQUAD und_section, step 2 */ |
5396 | 0 | if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL) |
5397 | 0 | { |
5398 | 0 | _bfd_error_handler |
5399 | | /* xgettext:c-format */ |
5400 | 0 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
5401 | 0 | _bfd_vms_etir_name (ETIR__C_STA_QW)); |
5402 | 0 | goto fail; |
5403 | 0 | } |
5404 | 0 | if (length < 12) |
5405 | 0 | goto bad_rec; |
5406 | 0 | cur_addend = bfd_getl64 (ptr + 4); |
5407 | 0 | prev_cmd = cmd; |
5408 | 0 | continue; |
5409 | | |
5410 | 0 | case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */ |
5411 | | /* ALPHA_R_REFLONG abs_section, step 2 */ |
5412 | | /* ALPHA_R_REFLONG others, step 2 */ |
5413 | 0 | if (prev_cmd != ETIR__C_OPR_ADD |
5414 | 0 | && prev_cmd != ETIR__C_STA_LW |
5415 | 0 | && prev_cmd != ETIR__C_STA_PQ) |
5416 | 0 | { |
5417 | | /* xgettext:c-format */ |
5418 | 0 | _bfd_error_handler (_("unknown reloc %s + %s"), |
5419 | 0 | _bfd_vms_etir_name (prev_cmd), |
5420 | 0 | _bfd_vms_etir_name (ETIR__C_STO_LW)); |
5421 | 0 | goto fail; |
5422 | 0 | } |
5423 | 0 | reloc_code = BFD_RELOC_32; |
5424 | 0 | break; |
5425 | | |
5426 | 0 | case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */ |
5427 | | /* ALPHA_R_REFQUAD abs_section, step 2 */ |
5428 | 0 | if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW) |
5429 | 0 | { |
5430 | | /* xgettext:c-format */ |
5431 | 0 | _bfd_error_handler (_("unknown reloc %s + %s"), |
5432 | 0 | _bfd_vms_etir_name (prev_cmd), |
5433 | 0 | _bfd_vms_etir_name (ETIR__C_STO_QW)); |
5434 | 0 | goto fail; |
5435 | 0 | } |
5436 | 0 | reloc_code = BFD_RELOC_64; |
5437 | 0 | break; |
5438 | | |
5439 | 0 | case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */ |
5440 | 0 | if (prev_cmd != ETIR__C_STA_PQ) |
5441 | 0 | { |
5442 | | /* xgettext:c-format */ |
5443 | 0 | _bfd_error_handler (_("unknown reloc %s + %s"), |
5444 | 0 | _bfd_vms_etir_name (prev_cmd), |
5445 | 0 | _bfd_vms_etir_name (ETIR__C_STO_OFF)); |
5446 | 0 | goto fail; |
5447 | 0 | } |
5448 | 0 | reloc_code = BFD_RELOC_64; |
5449 | 0 | break; |
5450 | | |
5451 | 0 | case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */ |
5452 | | /* ALPHA_R_REFQUAD und_section, step 3 */ |
5453 | 0 | if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW) |
5454 | 0 | { |
5455 | | /* xgettext:c-format */ |
5456 | 0 | _bfd_error_handler (_("unknown reloc %s + %s"), |
5457 | 0 | _bfd_vms_etir_name (prev_cmd), |
5458 | 0 | _bfd_vms_etir_name (ETIR__C_OPR_ADD)); |
5459 | 0 | goto fail; |
5460 | 0 | } |
5461 | 0 | prev_cmd = ETIR__C_OPR_ADD; |
5462 | 0 | continue; |
5463 | | |
5464 | 0 | case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */ |
5465 | 0 | reloc_code = BFD_RELOC_ALPHA_CODEADDR; |
5466 | 0 | cur_sym = ptr + 4; |
5467 | 0 | break; |
5468 | | |
5469 | 0 | case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */ |
5470 | 0 | reloc_code = BFD_RELOC_64; |
5471 | 0 | cur_sym = ptr + 4; |
5472 | 0 | break; |
5473 | | |
5474 | 0 | case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */ |
5475 | 0 | reloc_code = BFD_RELOC_32; |
5476 | 0 | cur_sym = ptr + 4; |
5477 | 0 | break; |
5478 | | |
5479 | 0 | case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */ |
5480 | 0 | reloc_code = BFD_RELOC_ALPHA_LINKAGE; |
5481 | 0 | cur_sym = ptr + 8; |
5482 | 0 | break; |
5483 | | |
5484 | 0 | case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */ |
5485 | 0 | reloc_code = BFD_RELOC_ALPHA_NOP; |
5486 | 0 | goto call_reloc; |
5487 | | |
5488 | 0 | case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */ |
5489 | 0 | reloc_code = BFD_RELOC_ALPHA_BSR; |
5490 | 0 | goto call_reloc; |
5491 | | |
5492 | 0 | case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */ |
5493 | 0 | reloc_code = BFD_RELOC_ALPHA_LDA; |
5494 | 0 | goto call_reloc; |
5495 | | |
5496 | 0 | case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */ |
5497 | 0 | reloc_code = BFD_RELOC_ALPHA_BOH; |
5498 | 0 | goto call_reloc; |
5499 | | |
5500 | 0 | call_reloc: |
5501 | 0 | if (length < 36) |
5502 | 0 | goto bad_rec; |
5503 | 0 | cur_sym = ptr + 4 + 32; |
5504 | 0 | cur_address = bfd_getl64 (ptr + 4 + 8); |
5505 | 0 | cur_addend = bfd_getl64 (ptr + 4 + 24); |
5506 | 0 | break; |
5507 | | |
5508 | 0 | case ETIR__C_STO_IMM: |
5509 | 0 | if (length < 8) |
5510 | 0 | goto bad_rec; |
5511 | 0 | vaddr += bfd_getl32 (ptr + 4); |
5512 | 0 | continue; |
5513 | | |
5514 | 0 | default: |
5515 | 0 | _bfd_error_handler (_("unknown reloc %s"), |
5516 | 0 | _bfd_vms_etir_name (cmd)); |
5517 | 0 | goto fail; |
5518 | 0 | } |
5519 | | |
5520 | 0 | { |
5521 | 0 | asection *sec; |
5522 | 0 | struct vms_section_data_struct *vms_sec; |
5523 | 0 | arelent *reloc; |
5524 | 0 | bfd_size_type size; |
5525 | | |
5526 | | /* Get section to which the relocation applies. */ |
5527 | 0 | if (cur_psect < 0 || cur_psect > (int)PRIV (section_count)) |
5528 | 0 | { |
5529 | 0 | _bfd_error_handler (_("invalid section index in ETIR")); |
5530 | 0 | goto fail; |
5531 | 0 | } |
5532 | | |
5533 | 0 | if (PRIV (sections) == NULL) |
5534 | 0 | goto fail; |
5535 | 0 | sec = PRIV (sections)[cur_psect]; |
5536 | 0 | if (sec == bfd_abs_section_ptr) |
5537 | 0 | { |
5538 | 0 | _bfd_error_handler (_("relocation for non-REL psect")); |
5539 | 0 | goto fail; |
5540 | 0 | } |
5541 | | |
5542 | 0 | vms_sec = vms_section_data (sec); |
5543 | | |
5544 | | /* Allocate a reloc entry. */ |
5545 | 0 | if (sec->reloc_count >= vms_sec->reloc_max) |
5546 | 0 | { |
5547 | 0 | if (vms_sec->reloc_max == 0) |
5548 | 0 | { |
5549 | 0 | vms_sec->reloc_max = 64; |
5550 | 0 | sec->relocation = bfd_zmalloc |
5551 | 0 | (vms_sec->reloc_max * sizeof (arelent)); |
5552 | 0 | } |
5553 | 0 | else |
5554 | 0 | { |
5555 | 0 | vms_sec->reloc_max *= 2; |
5556 | 0 | sec->relocation = bfd_realloc_or_free |
5557 | 0 | (sec->relocation, vms_sec->reloc_max * sizeof (arelent)); |
5558 | 0 | if (sec->relocation == NULL) |
5559 | 0 | goto fail; |
5560 | 0 | } |
5561 | 0 | } |
5562 | 0 | reloc = &sec->relocation[sec->reloc_count]; |
5563 | 0 | sec->reloc_count++; |
5564 | |
|
5565 | 0 | reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code); |
5566 | |
|
5567 | 0 | if (cur_sym != NULL) |
5568 | 0 | { |
5569 | 0 | unsigned int j; |
5570 | 0 | int symlen; |
5571 | 0 | asymbol **sym; |
5572 | | |
5573 | | /* Linear search. */ |
5574 | 0 | if (end - cur_sym < 1) |
5575 | 0 | goto bad_rec; |
5576 | 0 | symlen = *cur_sym; |
5577 | 0 | cur_sym++; |
5578 | 0 | if (end - cur_sym < symlen) |
5579 | 0 | goto bad_rec; |
5580 | 0 | sym = NULL; |
5581 | |
|
5582 | 0 | for (j = 0; j < PRIV (gsd_sym_count); j++) |
5583 | 0 | if (PRIV (syms)[j]->namelen == symlen |
5584 | 0 | && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0) |
5585 | 0 | { |
5586 | 0 | sym = &PRIV (csymbols)[j]; |
5587 | 0 | break; |
5588 | 0 | } |
5589 | 0 | if (sym == NULL) |
5590 | 0 | { |
5591 | 0 | _bfd_error_handler (_("unknown symbol in command %s"), |
5592 | 0 | _bfd_vms_etir_name (cmd)); |
5593 | 0 | reloc->sym_ptr_ptr = NULL; |
5594 | 0 | } |
5595 | 0 | else |
5596 | 0 | reloc->sym_ptr_ptr = sym; |
5597 | 0 | } |
5598 | 0 | else if (cur_psidx >= 0) |
5599 | 0 | { |
5600 | 0 | if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count)) |
5601 | 0 | goto fail; |
5602 | 0 | reloc->sym_ptr_ptr = &PRIV (sections)[cur_psidx]->symbol; |
5603 | 0 | } |
5604 | 0 | else |
5605 | 0 | reloc->sym_ptr_ptr = NULL; |
5606 | | |
5607 | 0 | reloc->address = cur_address; |
5608 | 0 | reloc->addend = cur_addend; |
5609 | |
|
5610 | 0 | if (reloc_code == ALPHA_R_LINKAGE) |
5611 | 0 | size = 16; |
5612 | 0 | else |
5613 | 0 | size = bfd_get_reloc_size (reloc->howto); |
5614 | 0 | vaddr += size; |
5615 | 0 | } |
5616 | | |
5617 | 0 | cur_addend = 0; |
5618 | 0 | prev_cmd = -1; |
5619 | 0 | cur_sym = NULL; |
5620 | 0 | cur_psidx = -1; |
5621 | 0 | } |
5622 | 2 | } |
5623 | 0 | vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n")); |
5624 | 0 | PRIV (reloc_done) = 1; |
5625 | 0 | return true; |
5626 | | |
5627 | 6 | fail: |
5628 | 6 | PRIV (reloc_done) = -1; |
5629 | 6 | return false; |
5630 | 6 | } |
5631 | | |
5632 | | /* Return the number of bytes required to store the relocation |
5633 | | information associated with the given section. */ |
5634 | | |
5635 | | static long |
5636 | | alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section) |
5637 | 6 | { |
5638 | 6 | if (!alpha_vms_slurp_relocs (abfd)) |
5639 | 6 | return -1; |
5640 | | |
5641 | 0 | return (section->reloc_count + 1L) * sizeof (arelent *); |
5642 | 6 | } |
5643 | | |
5644 | | /* Convert relocations from VMS (external) form into BFD internal |
5645 | | form. Return the number of relocations. */ |
5646 | | |
5647 | | static long |
5648 | | alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr, |
5649 | | asymbol **symbols ATTRIBUTE_UNUSED) |
5650 | 0 | { |
5651 | 0 | arelent *tblptr; |
5652 | 0 | int count; |
5653 | |
|
5654 | 0 | if (!alpha_vms_slurp_relocs (abfd)) |
5655 | 0 | return -1; |
5656 | | |
5657 | 0 | count = section->reloc_count; |
5658 | 0 | tblptr = section->relocation; |
5659 | |
|
5660 | 0 | while (count--) |
5661 | 0 | *relptr++ = tblptr++; |
5662 | |
|
5663 | 0 | *relptr = (arelent *) NULL; |
5664 | 0 | return section->reloc_count; |
5665 | 0 | } |
5666 | | |
5667 | | /* Install a new set of internal relocs. */ |
5668 | | |
5669 | | #define alpha_vms_finalize_section_relocs _bfd_generic_finalize_section_relocs |
5670 | | |
5671 | | |
5672 | | /* This is just copied from ecoff-alpha, needs to be fixed probably. */ |
5673 | | |
5674 | | /* How to process the various reloc types. */ |
5675 | | |
5676 | | static bfd_reloc_status_type |
5677 | | reloc_nil (bfd * abfd ATTRIBUTE_UNUSED, |
5678 | | arelent *reloc ATTRIBUTE_UNUSED, |
5679 | | asymbol *sym ATTRIBUTE_UNUSED, |
5680 | | void * data ATTRIBUTE_UNUSED, |
5681 | | asection *sec ATTRIBUTE_UNUSED, |
5682 | | bfd *output_bfd ATTRIBUTE_UNUSED, |
5683 | | char **error_message ATTRIBUTE_UNUSED) |
5684 | 0 | { |
5685 | | #if VMS_DEBUG |
5686 | | vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd); |
5687 | | vms_debug (2, "In section %s, symbol %s\n", |
5688 | | sec->name, sym->name); |
5689 | | vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n", |
5690 | | reloc->sym_ptr_ptr[0]->name, |
5691 | | (unsigned long)reloc->address, |
5692 | | (unsigned long)reloc->addend, reloc->howto->name); |
5693 | | vms_debug (2, "data at %p\n", data); |
5694 | | /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */ |
5695 | | #endif |
5696 | |
|
5697 | 0 | return bfd_reloc_ok; |
5698 | 0 | } |
5699 | | |
5700 | | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value |
5701 | | from smaller values. Start with zero, widen, *then* decrement. */ |
5702 | | #define MINUS_ONE (((bfd_vma)0) - 1) |
5703 | | |
5704 | | static reloc_howto_type alpha_howto_table[] = |
5705 | | { |
5706 | | HOWTO (ALPHA_R_IGNORE, /* Type. */ |
5707 | | 0, /* Rightshift. */ |
5708 | | 1, /* Size. */ |
5709 | | 8, /* Bitsize. */ |
5710 | | true, /* PC relative. */ |
5711 | | 0, /* Bitpos. */ |
5712 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5713 | | reloc_nil, /* Special_function. */ |
5714 | | "IGNORE", /* Name. */ |
5715 | | true, /* Partial_inplace. */ |
5716 | | 0, /* Source mask */ |
5717 | | 0, /* Dest mask. */ |
5718 | | true), /* PC rel offset. */ |
5719 | | |
5720 | | /* A 64 bit reference to a symbol. */ |
5721 | | HOWTO (ALPHA_R_REFQUAD, /* Type. */ |
5722 | | 0, /* Rightshift. */ |
5723 | | 8, /* Size. */ |
5724 | | 64, /* Bitsize. */ |
5725 | | false, /* PC relative. */ |
5726 | | 0, /* Bitpos. */ |
5727 | | complain_overflow_bitfield, /* Complain_on_overflow. */ |
5728 | | reloc_nil, /* Special_function. */ |
5729 | | "REFQUAD", /* Name. */ |
5730 | | true, /* Partial_inplace. */ |
5731 | | MINUS_ONE, /* Source mask. */ |
5732 | | MINUS_ONE, /* Dest mask. */ |
5733 | | false), /* PC rel offset. */ |
5734 | | |
5735 | | /* A 21 bit branch. The native assembler generates these for |
5736 | | branches within the text segment, and also fills in the PC |
5737 | | relative offset in the instruction. */ |
5738 | | HOWTO (ALPHA_R_BRADDR, /* Type. */ |
5739 | | 2, /* Rightshift. */ |
5740 | | 4, /* Size. */ |
5741 | | 21, /* Bitsize. */ |
5742 | | true, /* PC relative. */ |
5743 | | 0, /* Bitpos. */ |
5744 | | complain_overflow_signed, /* Complain_on_overflow. */ |
5745 | | reloc_nil, /* Special_function. */ |
5746 | | "BRADDR", /* Name. */ |
5747 | | true, /* Partial_inplace. */ |
5748 | | 0x1fffff, /* Source mask. */ |
5749 | | 0x1fffff, /* Dest mask. */ |
5750 | | false), /* PC rel offset. */ |
5751 | | |
5752 | | /* A hint for a jump to a register. */ |
5753 | | HOWTO (ALPHA_R_HINT, /* Type. */ |
5754 | | 2, /* Rightshift. */ |
5755 | | 2, /* Size. */ |
5756 | | 14, /* Bitsize. */ |
5757 | | true, /* PC relative. */ |
5758 | | 0, /* Bitpos. */ |
5759 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5760 | | reloc_nil, /* Special_function. */ |
5761 | | "HINT", /* Name. */ |
5762 | | true, /* Partial_inplace. */ |
5763 | | 0x3fff, /* Source mask. */ |
5764 | | 0x3fff, /* Dest mask. */ |
5765 | | false), /* PC rel offset. */ |
5766 | | |
5767 | | /* 16 bit PC relative offset. */ |
5768 | | HOWTO (ALPHA_R_SREL16, /* Type. */ |
5769 | | 0, /* Rightshift. */ |
5770 | | 2, /* Size. */ |
5771 | | 16, /* Bitsize. */ |
5772 | | true, /* PC relative. */ |
5773 | | 0, /* Bitpos. */ |
5774 | | complain_overflow_signed, /* Complain_on_overflow. */ |
5775 | | reloc_nil, /* Special_function. */ |
5776 | | "SREL16", /* Name. */ |
5777 | | true, /* Partial_inplace. */ |
5778 | | 0xffff, /* Source mask. */ |
5779 | | 0xffff, /* Dest mask. */ |
5780 | | false), /* PC rel offset. */ |
5781 | | |
5782 | | /* 32 bit PC relative offset. */ |
5783 | | HOWTO (ALPHA_R_SREL32, /* Type. */ |
5784 | | 0, /* Rightshift. */ |
5785 | | 4, /* Size. */ |
5786 | | 32, /* Bitsize. */ |
5787 | | true, /* PC relative. */ |
5788 | | 0, /* Bitpos. */ |
5789 | | complain_overflow_signed, /* Complain_on_overflow. */ |
5790 | | reloc_nil, /* Special_function. */ |
5791 | | "SREL32", /* Name. */ |
5792 | | true, /* Partial_inplace. */ |
5793 | | 0xffffffff, /* Source mask. */ |
5794 | | 0xffffffff, /* Dest mask. */ |
5795 | | false), /* PC rel offset. */ |
5796 | | |
5797 | | /* A 64 bit PC relative offset. */ |
5798 | | HOWTO (ALPHA_R_SREL64, /* Type. */ |
5799 | | 0, /* Rightshift. */ |
5800 | | 8, /* Size. */ |
5801 | | 64, /* Bitsize. */ |
5802 | | true, /* PC relative. */ |
5803 | | 0, /* Bitpos. */ |
5804 | | complain_overflow_signed, /* Complain_on_overflow. */ |
5805 | | reloc_nil, /* Special_function. */ |
5806 | | "SREL64", /* Name. */ |
5807 | | true, /* Partial_inplace. */ |
5808 | | MINUS_ONE, /* Source mask. */ |
5809 | | MINUS_ONE, /* Dest mask. */ |
5810 | | false), /* PC rel offset. */ |
5811 | | |
5812 | | /* Push a value on the reloc evaluation stack. */ |
5813 | | HOWTO (ALPHA_R_OP_PUSH, /* Type. */ |
5814 | | 0, /* Rightshift. */ |
5815 | | 0, /* Size. */ |
5816 | | 0, /* Bitsize. */ |
5817 | | false, /* PC relative. */ |
5818 | | 0, /* Bitpos. */ |
5819 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5820 | | reloc_nil, /* Special_function. */ |
5821 | | "OP_PUSH", /* Name. */ |
5822 | | false, /* Partial_inplace. */ |
5823 | | 0, /* Source mask. */ |
5824 | | 0, /* Dest mask. */ |
5825 | | false), /* PC rel offset. */ |
5826 | | |
5827 | | /* Store the value from the stack at the given address. Store it in |
5828 | | a bitfield of size r_size starting at bit position r_offset. */ |
5829 | | HOWTO (ALPHA_R_OP_STORE, /* Type. */ |
5830 | | 0, /* Rightshift. */ |
5831 | | 8, /* Size. */ |
5832 | | 64, /* Bitsize. */ |
5833 | | false, /* PC relative. */ |
5834 | | 0, /* Bitpos. */ |
5835 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5836 | | reloc_nil, /* Special_function. */ |
5837 | | "OP_STORE", /* Name. */ |
5838 | | false, /* Partial_inplace. */ |
5839 | | 0, /* Source mask. */ |
5840 | | MINUS_ONE, /* Dest mask. */ |
5841 | | false), /* PC rel offset. */ |
5842 | | |
5843 | | /* Subtract the reloc address from the value on the top of the |
5844 | | relocation stack. */ |
5845 | | HOWTO (ALPHA_R_OP_PSUB, /* Type. */ |
5846 | | 0, /* Rightshift. */ |
5847 | | 0, /* Size. */ |
5848 | | 0, /* Bitsize. */ |
5849 | | false, /* PC relative. */ |
5850 | | 0, /* Bitpos. */ |
5851 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5852 | | reloc_nil, /* Special_function. */ |
5853 | | "OP_PSUB", /* Name. */ |
5854 | | false, /* Partial_inplace. */ |
5855 | | 0, /* Source mask. */ |
5856 | | 0, /* Dest mask. */ |
5857 | | false), /* PC rel offset. */ |
5858 | | |
5859 | | /* Shift the value on the top of the relocation stack right by the |
5860 | | given value. */ |
5861 | | HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */ |
5862 | | 0, /* Rightshift. */ |
5863 | | 0, /* Size. */ |
5864 | | 0, /* Bitsize. */ |
5865 | | false, /* PC relative. */ |
5866 | | 0, /* Bitpos. */ |
5867 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5868 | | reloc_nil, /* Special_function. */ |
5869 | | "OP_PRSHIFT", /* Name. */ |
5870 | | false, /* Partial_inplace. */ |
5871 | | 0, /* Source mask. */ |
5872 | | 0, /* Dest mask. */ |
5873 | | false), /* PC rel offset. */ |
5874 | | |
5875 | | /* Hack. Linkage is done by linker. */ |
5876 | | HOWTO (ALPHA_R_LINKAGE, /* Type. */ |
5877 | | 0, /* Rightshift. */ |
5878 | | 0, /* Size. */ |
5879 | | 0, /* Bitsize. */ |
5880 | | false, /* PC relative. */ |
5881 | | 0, /* Bitpos. */ |
5882 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5883 | | reloc_nil, /* Special_function. */ |
5884 | | "LINKAGE", /* Name. */ |
5885 | | false, /* Partial_inplace. */ |
5886 | | 0, /* Source mask. */ |
5887 | | 0, /* Dest mask. */ |
5888 | | false), /* PC rel offset. */ |
5889 | | |
5890 | | /* A 32 bit reference to a symbol. */ |
5891 | | HOWTO (ALPHA_R_REFLONG, /* Type. */ |
5892 | | 0, /* Rightshift. */ |
5893 | | 4, /* Size. */ |
5894 | | 32, /* Bitsize. */ |
5895 | | false, /* PC relative. */ |
5896 | | 0, /* Bitpos. */ |
5897 | | complain_overflow_bitfield, /* Complain_on_overflow. */ |
5898 | | reloc_nil, /* Special_function. */ |
5899 | | "REFLONG", /* Name. */ |
5900 | | true, /* Partial_inplace. */ |
5901 | | 0xffffffff, /* Source mask. */ |
5902 | | 0xffffffff, /* Dest mask. */ |
5903 | | false), /* PC rel offset. */ |
5904 | | |
5905 | | /* A 64 bit reference to a procedure, written as 32 bit value. */ |
5906 | | HOWTO (ALPHA_R_CODEADDR, /* Type. */ |
5907 | | 0, /* Rightshift. */ |
5908 | | 8, /* Size. */ |
5909 | | 64, /* Bitsize. */ |
5910 | | false, /* PC relative. */ |
5911 | | 0, /* Bitpos. */ |
5912 | | complain_overflow_signed,/* Complain_on_overflow. */ |
5913 | | reloc_nil, /* Special_function. */ |
5914 | | "CODEADDR", /* Name. */ |
5915 | | false, /* Partial_inplace. */ |
5916 | | 0xffffffff, /* Source mask. */ |
5917 | | 0xffffffff, /* Dest mask. */ |
5918 | | false), /* PC rel offset. */ |
5919 | | |
5920 | | HOWTO (ALPHA_R_NOP, /* Type. */ |
5921 | | 0, /* Rightshift. */ |
5922 | | 0, /* Size. */ |
5923 | | 0, /* Bitsize. */ |
5924 | | /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH |
5925 | | because the calculations for the 3 relocations are the same. |
5926 | | See B.4.5.2 of the OpenVMS Linker Utility Manual. */ |
5927 | | true, /* PC relative. */ |
5928 | | 0, /* Bitpos. */ |
5929 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5930 | | reloc_nil, /* Special_function. */ |
5931 | | "NOP", /* Name. */ |
5932 | | false, /* Partial_inplace. */ |
5933 | | 0xffffffff, /* Source mask. */ |
5934 | | 0xffffffff, /* Dest mask. */ |
5935 | | false), /* PC rel offset. */ |
5936 | | |
5937 | | HOWTO (ALPHA_R_BSR, /* Type. */ |
5938 | | 0, /* Rightshift. */ |
5939 | | 0, /* Size. */ |
5940 | | 0, /* Bitsize. */ |
5941 | | true, /* PC relative. */ |
5942 | | 0, /* Bitpos. */ |
5943 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5944 | | reloc_nil, /* Special_function. */ |
5945 | | "BSR", /* Name. */ |
5946 | | false, /* Partial_inplace. */ |
5947 | | 0xffffffff, /* Source mask. */ |
5948 | | 0xffffffff, /* Dest mask. */ |
5949 | | false), /* PC rel offset. */ |
5950 | | |
5951 | | HOWTO (ALPHA_R_LDA, /* Type. */ |
5952 | | 0, /* Rightshift. */ |
5953 | | 0, /* Size. */ |
5954 | | 0, /* Bitsize. */ |
5955 | | false, /* PC relative. */ |
5956 | | 0, /* Bitpos. */ |
5957 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5958 | | reloc_nil, /* Special_function. */ |
5959 | | "LDA", /* Name. */ |
5960 | | false, /* Partial_inplace. */ |
5961 | | 0xffffffff, /* Source mask. */ |
5962 | | 0xffffffff, /* Dest mask. */ |
5963 | | false), /* PC rel offset. */ |
5964 | | |
5965 | | HOWTO (ALPHA_R_BOH, /* Type. */ |
5966 | | 0, /* Rightshift. */ |
5967 | | 0, /* Size. */ |
5968 | | 0, /* Bitsize. */ |
5969 | | true, /* PC relative. */ |
5970 | | 0, /* Bitpos. */ |
5971 | | complain_overflow_dont,/* Complain_on_overflow. */ |
5972 | | reloc_nil, /* Special_function. */ |
5973 | | "BOH", /* Name. */ |
5974 | | false, /* Partial_inplace. */ |
5975 | | 0xffffffff, /* Source mask. */ |
5976 | | 0xffffffff, /* Dest mask. */ |
5977 | | false), /* PC rel offset. */ |
5978 | | }; |
5979 | | |
5980 | | /* Return a pointer to a howto structure which, when invoked, will perform |
5981 | | the relocation code on data from the architecture noted. */ |
5982 | | |
5983 | | static reloc_howto_type * |
5984 | | alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
5985 | | bfd_reloc_code_real_type code) |
5986 | 0 | { |
5987 | 0 | int alpha_type; |
5988 | |
|
5989 | 0 | vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code)); |
5990 | |
|
5991 | 0 | switch (code) |
5992 | 0 | { |
5993 | 0 | case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break; |
5994 | 0 | case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break; |
5995 | 0 | case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break; |
5996 | 0 | case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break; |
5997 | 0 | case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break; |
5998 | 0 | case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break; |
5999 | 0 | case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break; |
6000 | 0 | case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break; |
6001 | 0 | case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break; |
6002 | 0 | case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break; |
6003 | 0 | case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break; |
6004 | 0 | case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break; |
6005 | 0 | case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break; |
6006 | 0 | case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break; |
6007 | 0 | case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break; |
6008 | 0 | default: |
6009 | 0 | _bfd_error_handler (_("reloc (%d) is *UNKNOWN*"), code); |
6010 | 0 | return NULL; |
6011 | 0 | } |
6012 | 0 | vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name)); |
6013 | 0 | return & alpha_howto_table[alpha_type]; |
6014 | 0 | } |
6015 | | |
6016 | | static reloc_howto_type * |
6017 | | alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
6018 | | const char *r_name) |
6019 | 0 | { |
6020 | 0 | unsigned int i; |
6021 | |
|
6022 | 0 | for (i = 0; |
6023 | 0 | i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]); |
6024 | 0 | i++) |
6025 | 0 | if (alpha_howto_table[i].name != NULL |
6026 | 0 | && strcasecmp (alpha_howto_table[i].name, r_name) == 0) |
6027 | 0 | return &alpha_howto_table[i]; |
6028 | | |
6029 | 0 | return NULL; |
6030 | 0 | } |
6031 | | |
6032 | | static long |
6033 | | alpha_vms_get_synthetic_symtab (bfd *abfd, |
6034 | | long symcount ATTRIBUTE_UNUSED, |
6035 | | asymbol **usyms ATTRIBUTE_UNUSED, |
6036 | | long dynsymcount ATTRIBUTE_UNUSED, |
6037 | | asymbol **dynsyms ATTRIBUTE_UNUSED, |
6038 | | asymbol **ret) |
6039 | 13 | { |
6040 | 13 | asymbol *syms; |
6041 | 13 | unsigned int i; |
6042 | 13 | unsigned int n = 0; |
6043 | | |
6044 | 13 | syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol)); |
6045 | 13 | *ret = syms; |
6046 | 13 | if (syms == NULL) |
6047 | 0 | return -1; |
6048 | | |
6049 | 13 | for (i = 0; i < PRIV (gsd_sym_count); i++) |
6050 | 0 | { |
6051 | 0 | struct vms_symbol_entry *e = PRIV (syms)[i]; |
6052 | 0 | asymbol *sym; |
6053 | 0 | flagword flags; |
6054 | 0 | symvalue value; |
6055 | 0 | asection *sec; |
6056 | 0 | const char *name; |
6057 | 0 | char *sname; |
6058 | 0 | int l; |
6059 | |
|
6060 | 0 | name = e->name; |
6061 | 0 | value = 0; |
6062 | 0 | flags = BSF_LOCAL | BSF_SYNTHETIC; |
6063 | 0 | sec = NULL; |
6064 | |
|
6065 | 0 | switch (e->typ) |
6066 | 0 | { |
6067 | 0 | case EGSD__C_SYM: |
6068 | 0 | case EGSD__C_SYMG: |
6069 | 0 | if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM)) |
6070 | 0 | { |
6071 | 0 | value = e->code_value; |
6072 | 0 | sec = e->code_section; |
6073 | 0 | } |
6074 | 0 | else |
6075 | 0 | continue; |
6076 | 0 | break; |
6077 | | |
6078 | 0 | default: |
6079 | 0 | continue; |
6080 | 0 | } |
6081 | | |
6082 | 0 | l = strlen (name); |
6083 | 0 | sname = bfd_alloc (abfd, l + 5); |
6084 | 0 | if (sname == NULL) |
6085 | 0 | return false; |
6086 | 0 | memcpy (sname, name, l); |
6087 | 0 | memcpy (sname + l, "..en", 5); |
6088 | |
|
6089 | 0 | sym = &syms[n++]; |
6090 | 0 | sym->name = sname; |
6091 | 0 | sym->section = sec; |
6092 | 0 | sym->flags = flags; |
6093 | 0 | sym->value = value; |
6094 | 0 | sym->udata.p = NULL; |
6095 | 0 | } |
6096 | | |
6097 | 13 | return n; |
6098 | 13 | } |
6099 | | |
6100 | | /* Private dump. */ |
6101 | | |
6102 | | static const char * |
6103 | | vms_time_to_str (unsigned char *buf) |
6104 | 22 | { |
6105 | 22 | time_t t = vms_rawtime_to_time_t (buf); |
6106 | 22 | char *res = ctime (&t); |
6107 | | |
6108 | 22 | if (!res) |
6109 | 0 | res = "*invalid time*"; |
6110 | 22 | else |
6111 | 22 | res[24] = 0; |
6112 | 22 | return res; |
6113 | 22 | } |
6114 | | |
6115 | | static void |
6116 | | evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len) |
6117 | 0 | { |
6118 | 0 | struct vms_emh_common *emh = (struct vms_emh_common *)rec; |
6119 | 0 | int subtype = -1; |
6120 | 0 | int extra; |
6121 | |
|
6122 | 0 | if (rec_len >= sizeof (*emh)) |
6123 | 0 | subtype = bfd_getl16 (emh->subtyp); |
6124 | | |
6125 | | /* xgettext:c-format */ |
6126 | 0 | fprintf (file, _(" EMH %d (len=%u): "), subtype, rec_len); |
6127 | | |
6128 | | /* PR 21618: Check for invalid lengths. */ |
6129 | 0 | if (rec_len < sizeof (*emh)) |
6130 | 0 | { |
6131 | 0 | fprintf (file, _(" Error: %s min length is %u\n"), |
6132 | 0 | "EMH", (unsigned) sizeof (*emh)); |
6133 | 0 | return; |
6134 | 0 | } |
6135 | | |
6136 | 0 | extra = rec_len - sizeof (struct vms_emh_common); |
6137 | |
|
6138 | 0 | switch (subtype) |
6139 | 0 | { |
6140 | 0 | case EMH__C_MHD: |
6141 | 0 | { |
6142 | 0 | struct vms_emh_mhd *mhd = (struct vms_emh_mhd *) rec; |
6143 | 0 | unsigned char *name; |
6144 | 0 | unsigned char *nextname; |
6145 | 0 | unsigned char *maxname; |
6146 | | |
6147 | | /* PR 21840: Check for invalid lengths. */ |
6148 | 0 | if (rec_len < sizeof (* mhd)) |
6149 | 0 | { |
6150 | 0 | fprintf (file, _(" Error: %s min length is %u\n"), |
6151 | 0 | "EMH_MHD", (unsigned) sizeof (*mhd)); |
6152 | 0 | return; |
6153 | 0 | } |
6154 | 0 | fprintf (file, _("Module header\n")); |
6155 | 0 | fprintf (file, _(" structure level: %u\n"), mhd->strlvl); |
6156 | 0 | fprintf (file, _(" max record size: %u\n"), |
6157 | 0 | (unsigned) bfd_getl32 (mhd->recsiz)); |
6158 | 0 | name = (unsigned char *) (mhd + 1); |
6159 | 0 | maxname = (unsigned char *) rec + rec_len; |
6160 | 0 | if (name > maxname - 2) |
6161 | 0 | { |
6162 | 0 | fprintf (file, _(" Error: The module name is missing\n")); |
6163 | 0 | return; |
6164 | 0 | } |
6165 | 0 | nextname = name + name[0] + 1; |
6166 | 0 | if (nextname >= maxname) |
6167 | 0 | { |
6168 | 0 | fprintf (file, _(" Error: The module name is too long\n")); |
6169 | 0 | return; |
6170 | 0 | } |
6171 | 0 | fprintf (file, _(" module name : %.*s\n"), name[0], name + 1); |
6172 | 0 | name = nextname; |
6173 | 0 | if (name > maxname - 2) |
6174 | 0 | { |
6175 | 0 | fprintf (file, _(" Error: The module version is missing\n")); |
6176 | 0 | return; |
6177 | 0 | } |
6178 | 0 | nextname = name + name[0] + 1; |
6179 | 0 | if (nextname >= maxname) |
6180 | 0 | { |
6181 | 0 | fprintf (file, _(" Error: The module version is too long\n")); |
6182 | 0 | return; |
6183 | 0 | } |
6184 | 0 | fprintf (file, _(" module version : %.*s\n"), name[0], name + 1); |
6185 | 0 | name = nextname; |
6186 | 0 | if ((maxname - name) < 17 && maxname[-1] != 0) |
6187 | 0 | fprintf (file, _(" Error: The compile date is truncated\n")); |
6188 | 0 | else |
6189 | 0 | fprintf (file, _(" compile date : %.17s\n"), name); |
6190 | 0 | } |
6191 | 0 | break; |
6192 | | |
6193 | 0 | case EMH__C_LNM: |
6194 | 0 | fprintf (file, _("Language Processor Name\n")); |
6195 | 0 | fprintf (file, _(" language name: %.*s\n"), extra, (char *)(emh + 1)); |
6196 | 0 | break; |
6197 | | |
6198 | 0 | case EMH__C_SRC: |
6199 | 0 | fprintf (file, _("Source Files Header\n")); |
6200 | 0 | fprintf (file, _(" file: %.*s\n"), extra, (char *)(emh + 1)); |
6201 | 0 | break; |
6202 | | |
6203 | 0 | case EMH__C_TTL: |
6204 | 0 | fprintf (file, _("Title Text Header\n")); |
6205 | 0 | fprintf (file, _(" title: %.*s\n"), extra, (char *)(emh + 1)); |
6206 | 0 | break; |
6207 | | |
6208 | 0 | case EMH__C_CPR: |
6209 | 0 | fprintf (file, _("Copyright Header\n")); |
6210 | 0 | fprintf (file, _(" copyright: %.*s\n"), extra, (char *)(emh + 1)); |
6211 | 0 | break; |
6212 | | |
6213 | 0 | default: |
6214 | 0 | fprintf (file, _("unhandled emh subtype %u\n"), subtype); |
6215 | 0 | break; |
6216 | 0 | } |
6217 | 0 | } |
6218 | | |
6219 | | static void |
6220 | | evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len) |
6221 | 0 | { |
6222 | 0 | struct vms_eeom *eeom = (struct vms_eeom *)rec; |
6223 | |
|
6224 | 0 | fprintf (file, _(" EEOM (len=%u):\n"), rec_len); |
6225 | | |
6226 | | /* PR 21618: Check for invalid lengths. */ |
6227 | 0 | if (rec_len < 10) |
6228 | 0 | { |
6229 | 0 | fprintf (file, _(" Error: %s min length is %u\n"), |
6230 | 0 | "EEOM", 10); |
6231 | 0 | return; |
6232 | 0 | } |
6233 | | |
6234 | 0 | fprintf (file, _(" number of cond linkage pairs: %u\n"), |
6235 | 0 | (unsigned)bfd_getl32 (eeom->total_lps)); |
6236 | 0 | fprintf (file, _(" completion code: %u\n"), |
6237 | 0 | (unsigned)bfd_getl16 (eeom->comcod)); |
6238 | |
|
6239 | 0 | if (rec_len >= sizeof (*eeom)) |
6240 | 0 | { |
6241 | 0 | fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg); |
6242 | 0 | fprintf (file, _(" transfer addr psect: %u\n"), |
6243 | 0 | (unsigned)bfd_getl32 (eeom->psindx)); |
6244 | 0 | fprintf (file, _(" transfer address : 0x%08x\n"), |
6245 | 0 | (unsigned)bfd_getl32 (eeom->tfradr)); |
6246 | 0 | } |
6247 | 0 | } |
6248 | | |
6249 | | static void |
6250 | | exav_bfd_print_egsy_flags (unsigned int flags, FILE *file) |
6251 | 0 | { |
6252 | 0 | if (flags & EGSY__V_WEAK) |
6253 | 0 | fputs (_(" WEAK"), file); |
6254 | 0 | if (flags & EGSY__V_DEF) |
6255 | 0 | fputs (_(" DEF"), file); |
6256 | 0 | if (flags & EGSY__V_UNI) |
6257 | 0 | fputs (_(" UNI"), file); |
6258 | 0 | if (flags & EGSY__V_REL) |
6259 | 0 | fputs (_(" REL"), file); |
6260 | 0 | if (flags & EGSY__V_COMM) |
6261 | 0 | fputs (_(" COMM"), file); |
6262 | 0 | if (flags & EGSY__V_VECEP) |
6263 | 0 | fputs (_(" VECEP"), file); |
6264 | 0 | if (flags & EGSY__V_NORM) |
6265 | 0 | fputs (_(" NORM"), file); |
6266 | 0 | if (flags & EGSY__V_QUAD_VAL) |
6267 | 0 | fputs (_(" QVAL"), file); |
6268 | 0 | } |
6269 | | |
6270 | | static void |
6271 | | evax_bfd_print_egsd_flags (FILE *file, unsigned int flags) |
6272 | 0 | { |
6273 | 0 | if (flags & EGPS__V_PIC) |
6274 | 0 | fputs (_(" PIC"), file); |
6275 | 0 | if (flags & EGPS__V_LIB) |
6276 | 0 | fputs (_(" LIB"), file); |
6277 | 0 | if (flags & EGPS__V_OVR) |
6278 | 0 | fputs (_(" OVR"), file); |
6279 | 0 | if (flags & EGPS__V_REL) |
6280 | 0 | fputs (_(" REL"), file); |
6281 | 0 | if (flags & EGPS__V_GBL) |
6282 | 0 | fputs (_(" GBL"), file); |
6283 | 0 | if (flags & EGPS__V_SHR) |
6284 | 0 | fputs (_(" SHR"), file); |
6285 | 0 | if (flags & EGPS__V_EXE) |
6286 | 0 | fputs (_(" EXE"), file); |
6287 | 0 | if (flags & EGPS__V_RD) |
6288 | 0 | fputs (_(" RD"), file); |
6289 | 0 | if (flags & EGPS__V_WRT) |
6290 | 0 | fputs (_(" WRT"), file); |
6291 | 0 | if (flags & EGPS__V_VEC) |
6292 | 0 | fputs (_(" VEC"), file); |
6293 | 0 | if (flags & EGPS__V_NOMOD) |
6294 | 0 | fputs (_(" NOMOD"), file); |
6295 | 0 | if (flags & EGPS__V_COM) |
6296 | 0 | fputs (_(" COM"), file); |
6297 | 0 | if (flags & EGPS__V_ALLOC_64BIT) |
6298 | 0 | fputs (_(" 64B"), file); |
6299 | 0 | } |
6300 | | |
6301 | | static void |
6302 | | evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len) |
6303 | 0 | { |
6304 | 0 | unsigned int off = sizeof (struct vms_egsd); |
6305 | 0 | unsigned int n = 0; |
6306 | |
|
6307 | 0 | fprintf (file, _(" EGSD (len=%u):\n"), rec_len); |
6308 | 0 | if (rec_len < sizeof (struct vms_egsd) + sizeof (struct vms_egsd_entry)) |
6309 | 0 | return; |
6310 | | |
6311 | 0 | while (off <= rec_len - sizeof (struct vms_egsd_entry)) |
6312 | 0 | { |
6313 | 0 | struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off); |
6314 | 0 | unsigned int type; |
6315 | 0 | unsigned int len; |
6316 | 0 | unsigned int rest; |
6317 | |
|
6318 | 0 | type = (unsigned)bfd_getl16 (e->gsdtyp); |
6319 | 0 | len = (unsigned)bfd_getl16 (e->gsdsiz); |
6320 | | |
6321 | | /* xgettext:c-format */ |
6322 | 0 | fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "), |
6323 | 0 | n, type, len); |
6324 | 0 | n++; |
6325 | |
|
6326 | 0 | if (len < sizeof (struct vms_egsd_entry) || len > rec_len - off) |
6327 | 0 | { |
6328 | 0 | fprintf (file, _(" Erroneous length\n")); |
6329 | 0 | return; |
6330 | 0 | } |
6331 | | |
6332 | 0 | switch (type) |
6333 | 0 | { |
6334 | 0 | case EGSD__C_PSC: |
6335 | 0 | if (len >= offsetof (struct vms_egps, name)) |
6336 | 0 | { |
6337 | 0 | struct vms_egps *egps = (struct vms_egps *) e; |
6338 | 0 | unsigned int flags = bfd_getl16 (egps->flags); |
6339 | 0 | unsigned int l; |
6340 | |
|
6341 | 0 | fprintf (file, _("PSC - Program section definition\n")); |
6342 | 0 | fprintf (file, _(" alignment : 2**%u\n"), egps->align); |
6343 | 0 | fprintf (file, _(" flags : 0x%04x"), flags); |
6344 | 0 | evax_bfd_print_egsd_flags (file, flags); |
6345 | 0 | fputc ('\n', file); |
6346 | 0 | l = bfd_getl32 (egps->alloc); |
6347 | 0 | fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l); |
6348 | 0 | rest = len - offsetof (struct vms_egps, name); |
6349 | 0 | fprintf (file, _(" name : %.*s\n"), |
6350 | 0 | egps->namlng > rest ? rest : egps->namlng, |
6351 | 0 | egps->name); |
6352 | 0 | } |
6353 | 0 | break; |
6354 | 0 | case EGSD__C_SPSC: |
6355 | 0 | if (len >= offsetof (struct vms_esgps, name)) |
6356 | 0 | { |
6357 | 0 | struct vms_esgps *esgps = (struct vms_esgps *) e; |
6358 | 0 | unsigned int flags = bfd_getl16 (esgps->flags); |
6359 | 0 | unsigned int l; |
6360 | |
|
6361 | 0 | fprintf (file, _("SPSC - Shared Image Program section def\n")); |
6362 | 0 | fprintf (file, _(" alignment : 2**%u\n"), esgps->align); |
6363 | 0 | fprintf (file, _(" flags : 0x%04x"), flags); |
6364 | 0 | evax_bfd_print_egsd_flags (file, flags); |
6365 | 0 | fputc ('\n', file); |
6366 | 0 | l = bfd_getl32 (esgps->alloc); |
6367 | 0 | fprintf (file, _(" alloc (len) : %u (0x%08x)\n"), l, l); |
6368 | 0 | fprintf (file, _(" image offset : 0x%08x\n"), |
6369 | 0 | (unsigned int) bfd_getl32 (esgps->base)); |
6370 | 0 | fprintf (file, _(" symvec offset : 0x%08x\n"), |
6371 | 0 | (unsigned int) bfd_getl32 (esgps->value)); |
6372 | 0 | rest = len - offsetof (struct vms_esgps, name); |
6373 | 0 | fprintf (file, _(" name : %.*s\n"), |
6374 | 0 | esgps->namlng > rest ? rest : esgps->namlng, |
6375 | 0 | esgps->name); |
6376 | 0 | } |
6377 | 0 | break; |
6378 | 0 | case EGSD__C_SYM: |
6379 | 0 | if (len >= sizeof (struct vms_egsy)) |
6380 | 0 | { |
6381 | 0 | struct vms_egsy *egsy = (struct vms_egsy *) e; |
6382 | 0 | unsigned int flags = bfd_getl16 (egsy->flags); |
6383 | |
|
6384 | 0 | if ((flags & EGSY__V_DEF) != 0 |
6385 | 0 | && len >= offsetof (struct vms_esdf, name)) |
6386 | 0 | { |
6387 | 0 | struct vms_esdf *esdf = (struct vms_esdf *) e; |
6388 | |
|
6389 | 0 | fprintf (file, _("SYM - Global symbol definition\n")); |
6390 | 0 | fprintf (file, _(" flags: 0x%04x"), flags); |
6391 | 0 | exav_bfd_print_egsy_flags (flags, file); |
6392 | 0 | fputc ('\n', file); |
6393 | 0 | fprintf (file, _(" psect offset: 0x%08x\n"), |
6394 | 0 | (unsigned) bfd_getl32 (esdf->value)); |
6395 | 0 | if (flags & EGSY__V_NORM) |
6396 | 0 | { |
6397 | 0 | fprintf (file, _(" code address: 0x%08x\n"), |
6398 | 0 | (unsigned) bfd_getl32 (esdf->code_address)); |
6399 | 0 | fprintf (file, _(" psect index for entry point : %u\n"), |
6400 | 0 | (unsigned) bfd_getl32 (esdf->ca_psindx)); |
6401 | 0 | } |
6402 | 0 | fprintf (file, _(" psect index : %u\n"), |
6403 | 0 | (unsigned) bfd_getl32 (esdf->psindx)); |
6404 | 0 | rest = len - offsetof (struct vms_esdf, name); |
6405 | 0 | fprintf (file, _(" name : %.*s\n"), |
6406 | 0 | esdf->namlng > rest ? rest : esdf->namlng, |
6407 | 0 | esdf->name); |
6408 | 0 | } |
6409 | 0 | else if (len >= offsetof (struct vms_esrf, name)) |
6410 | 0 | { |
6411 | 0 | struct vms_esrf *esrf = (struct vms_esrf *)e; |
6412 | |
|
6413 | 0 | fprintf (file, _("SYM - Global symbol reference\n")); |
6414 | 0 | rest = len - offsetof (struct vms_esrf, name); |
6415 | 0 | fprintf (file, _(" name : %.*s\n"), |
6416 | 0 | esrf->namlng > rest ? rest : esrf->namlng, |
6417 | 0 | esrf->name); |
6418 | 0 | } |
6419 | 0 | } |
6420 | 0 | break; |
6421 | 0 | case EGSD__C_IDC: |
6422 | 0 | if (len >= sizeof (struct vms_eidc)) |
6423 | 0 | { |
6424 | 0 | struct vms_eidc *eidc = (struct vms_eidc *) e; |
6425 | 0 | unsigned int flags = bfd_getl32 (eidc->flags); |
6426 | 0 | unsigned char *p; |
6427 | |
|
6428 | 0 | fprintf (file, _("IDC - Ident Consistency check\n")); |
6429 | 0 | fprintf (file, _(" flags : 0x%08x"), flags); |
6430 | 0 | if (flags & EIDC__V_BINIDENT) |
6431 | 0 | fputs (" BINDENT", file); |
6432 | 0 | fputc ('\n', file); |
6433 | 0 | fprintf (file, _(" id match : %x\n"), |
6434 | 0 | (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK); |
6435 | 0 | fprintf (file, _(" error severity: %x\n"), |
6436 | 0 | (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK); |
6437 | 0 | p = eidc->name; |
6438 | 0 | rest = len - (p - (unsigned char *) e); |
6439 | 0 | fprintf (file, _(" entity name : %.*s\n"), |
6440 | 0 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); |
6441 | 0 | if (rest > 1u + p[0]) |
6442 | 0 | { |
6443 | 0 | rest -= 1 + p[0]; |
6444 | 0 | p += 1 + p[0]; |
6445 | 0 | fprintf (file, _(" object name : %.*s\n"), |
6446 | 0 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); |
6447 | 0 | if (rest > 1u + p[0]) |
6448 | 0 | { |
6449 | 0 | rest -= 1 + p[0]; |
6450 | 0 | p += 1 + p[0]; |
6451 | 0 | if (flags & EIDC__V_BINIDENT) |
6452 | 0 | { |
6453 | 0 | if (rest >= 4) |
6454 | 0 | fprintf (file, _(" binary ident : 0x%08x\n"), |
6455 | 0 | (unsigned) bfd_getl32 (p)); |
6456 | 0 | } |
6457 | 0 | else |
6458 | 0 | fprintf (file, _(" ascii ident : %.*s\n"), |
6459 | 0 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); |
6460 | 0 | } |
6461 | 0 | } |
6462 | 0 | } |
6463 | 0 | break; |
6464 | 0 | case EGSD__C_SYMG: |
6465 | 0 | if (len >= offsetof (struct vms_egst, name)) |
6466 | 0 | { |
6467 | 0 | struct vms_egst *egst = (struct vms_egst *) e; |
6468 | 0 | unsigned int flags = bfd_getl16 (egst->header.flags); |
6469 | |
|
6470 | 0 | fprintf (file, _("SYMG - Universal symbol definition\n")); |
6471 | 0 | fprintf (file, _(" flags: 0x%04x"), flags); |
6472 | 0 | exav_bfd_print_egsy_flags (flags, file); |
6473 | 0 | fputc ('\n', file); |
6474 | 0 | fprintf (file, _(" symbol vector offset: 0x%08x\n"), |
6475 | 0 | (unsigned) bfd_getl32 (egst->value)); |
6476 | 0 | fprintf (file, _(" entry point: 0x%08x\n"), |
6477 | 0 | (unsigned) bfd_getl32 (egst->lp_1)); |
6478 | 0 | fprintf (file, _(" proc descr : 0x%08x\n"), |
6479 | 0 | (unsigned) bfd_getl32 (egst->lp_2)); |
6480 | 0 | fprintf (file, _(" psect index: %u\n"), |
6481 | 0 | (unsigned) bfd_getl32 (egst->psindx)); |
6482 | 0 | rest = len - offsetof (struct vms_egst, name); |
6483 | 0 | fprintf (file, _(" name : %.*s\n"), |
6484 | 0 | egst->namlng > rest ? rest : egst->namlng, |
6485 | 0 | egst->name); |
6486 | 0 | } |
6487 | 0 | break; |
6488 | 0 | case EGSD__C_SYMV: |
6489 | 0 | if (len >= offsetof (struct vms_esdfv, name)) |
6490 | 0 | { |
6491 | 0 | struct vms_esdfv *esdfv = (struct vms_esdfv *) e; |
6492 | 0 | unsigned int flags = bfd_getl16 (esdfv->flags); |
6493 | |
|
6494 | 0 | fprintf (file, _("SYMV - Vectored symbol definition\n")); |
6495 | 0 | fprintf (file, _(" flags: 0x%04x"), flags); |
6496 | 0 | exav_bfd_print_egsy_flags (flags, file); |
6497 | 0 | fputc ('\n', file); |
6498 | 0 | fprintf (file, _(" vector : 0x%08x\n"), |
6499 | 0 | (unsigned) bfd_getl32 (esdfv->vector)); |
6500 | 0 | fprintf (file, _(" psect offset: %u\n"), |
6501 | 0 | (unsigned) bfd_getl32 (esdfv->value)); |
6502 | 0 | fprintf (file, _(" psect index : %u\n"), |
6503 | 0 | (unsigned) bfd_getl32 (esdfv->psindx)); |
6504 | 0 | rest = len - offsetof (struct vms_esdfv, name); |
6505 | 0 | fprintf (file, _(" name : %.*s\n"), |
6506 | 0 | esdfv->namlng > rest ? rest : esdfv->namlng, |
6507 | 0 | esdfv->name); |
6508 | 0 | } |
6509 | 0 | break; |
6510 | 0 | case EGSD__C_SYMM: |
6511 | 0 | if (len >= offsetof (struct vms_esdfm, name)) |
6512 | 0 | { |
6513 | 0 | struct vms_esdfm *esdfm = (struct vms_esdfm *) e; |
6514 | 0 | unsigned int flags = bfd_getl16 (esdfm->flags); |
6515 | |
|
6516 | 0 | fprintf (file, |
6517 | 0 | _("SYMM - Global symbol definition with version\n")); |
6518 | 0 | fprintf (file, _(" flags: 0x%04x"), flags); |
6519 | 0 | exav_bfd_print_egsy_flags (flags, file); |
6520 | 0 | fputc ('\n', file); |
6521 | 0 | fprintf (file, _(" version mask: 0x%08x\n"), |
6522 | 0 | (unsigned)bfd_getl32 (esdfm->version_mask)); |
6523 | 0 | fprintf (file, _(" psect offset: %u\n"), |
6524 | 0 | (unsigned)bfd_getl32 (esdfm->value)); |
6525 | 0 | fprintf (file, _(" psect index : %u\n"), |
6526 | 0 | (unsigned)bfd_getl32 (esdfm->psindx)); |
6527 | 0 | rest = len - offsetof (struct vms_esdfm, name); |
6528 | 0 | fprintf (file, _(" name : %.*s\n"), |
6529 | 0 | esdfm->namlng > rest ? rest : esdfm->namlng, |
6530 | 0 | esdfm->name); |
6531 | 0 | } |
6532 | 0 | break; |
6533 | 0 | default: |
6534 | 0 | fprintf (file, _("unhandled egsd entry type %u\n"), type); |
6535 | 0 | break; |
6536 | 0 | } |
6537 | 0 | off += len; |
6538 | 0 | } |
6539 | 0 | } |
6540 | | |
6541 | | static void |
6542 | | evax_bfd_print_hex (FILE *file, const char *pfx, |
6543 | | const unsigned char *buf, unsigned int len) |
6544 | 0 | { |
6545 | 0 | unsigned int i; |
6546 | 0 | unsigned int n; |
6547 | |
|
6548 | 0 | n = 0; |
6549 | 0 | for (i = 0; i < len; i++) |
6550 | 0 | { |
6551 | 0 | if (n == 0) |
6552 | 0 | fputs (pfx, file); |
6553 | 0 | fprintf (file, " %02x", buf[i]); |
6554 | 0 | n++; |
6555 | 0 | if (n == 16) |
6556 | 0 | { |
6557 | 0 | n = 0; |
6558 | 0 | fputc ('\n', file); |
6559 | 0 | } |
6560 | 0 | } |
6561 | 0 | if (n != 0) |
6562 | 0 | fputc ('\n', file); |
6563 | 0 | } |
6564 | | |
6565 | | static void |
6566 | | evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf, |
6567 | | unsigned int len, int is_ps) |
6568 | 0 | { |
6569 | 0 | if (is_ps ? len < 44 : len < 33) |
6570 | 0 | return; |
6571 | | |
6572 | | /* xgettext:c-format */ |
6573 | 0 | fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"), |
6574 | 0 | (unsigned)bfd_getl32 (buf), |
6575 | 0 | (unsigned)bfd_getl32 (buf + 16)); |
6576 | | /* xgettext:c-format */ |
6577 | 0 | fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"), |
6578 | 0 | (unsigned)bfd_getl32 (buf + 4), |
6579 | 0 | (unsigned)bfd_getl32 (buf + 12), |
6580 | 0 | (unsigned)bfd_getl32 (buf + 8)); |
6581 | | /* xgettext:c-format */ |
6582 | 0 | fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"), |
6583 | 0 | (unsigned)bfd_getl32 (buf + 20), |
6584 | 0 | (unsigned)bfd_getl32 (buf + 28), |
6585 | 0 | (unsigned)bfd_getl32 (buf + 24)); |
6586 | 0 | if (is_ps) |
6587 | | /* xgettext:c-format */ |
6588 | 0 | fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"), |
6589 | 0 | (unsigned)bfd_getl32 (buf + 32), |
6590 | 0 | (unsigned)bfd_getl32 (buf + 40), |
6591 | 0 | (unsigned)bfd_getl32 (buf + 36)); |
6592 | 0 | else |
6593 | 0 | fprintf (file, _(" global name: %.*s\n"), |
6594 | 0 | buf[32] > len - 33 ? len - 33 : buf[32], |
6595 | 0 | buf + 33); |
6596 | 0 | } |
6597 | | |
6598 | | static void |
6599 | | evax_bfd_print_etir (FILE *file, const char *name, |
6600 | | unsigned char *rec, unsigned int rec_len) |
6601 | 0 | { |
6602 | 0 | unsigned int off = sizeof (struct vms_eobjrec); |
6603 | | |
6604 | | /* xgettext:c-format */ |
6605 | 0 | fprintf (file, _(" %s (len=%u):\n"), name, (unsigned) rec_len); |
6606 | 0 | if (rec_len < sizeof (struct vms_eobjrec) + sizeof (struct vms_etir)) |
6607 | 0 | return; |
6608 | | |
6609 | 0 | while (off <= rec_len - sizeof (struct vms_etir)) |
6610 | 0 | { |
6611 | 0 | struct vms_etir *etir = (struct vms_etir *)(rec + off); |
6612 | 0 | unsigned char *buf; |
6613 | 0 | unsigned int type; |
6614 | 0 | unsigned int size; |
6615 | 0 | unsigned int rest; |
6616 | |
|
6617 | 0 | type = bfd_getl16 (etir->rectyp); |
6618 | 0 | size = bfd_getl16 (etir->size); |
6619 | 0 | buf = rec + off + sizeof (struct vms_etir); |
6620 | |
|
6621 | 0 | if (size < sizeof (struct vms_etir) || size > rec_len - off) |
6622 | 0 | { |
6623 | 0 | fprintf (file, _(" Erroneous length\n")); |
6624 | 0 | return; |
6625 | 0 | } |
6626 | | |
6627 | | /* xgettext:c-format */ |
6628 | 0 | fprintf (file, _(" (type: %3u, size: %3u): "), type, size); |
6629 | 0 | rest = size - sizeof (struct vms_etir); |
6630 | 0 | switch (type) |
6631 | 0 | { |
6632 | 0 | case ETIR__C_STA_GBL: |
6633 | 0 | if (rest >= 1) |
6634 | 0 | fprintf (file, _("STA_GBL (stack global) %.*s\n"), |
6635 | 0 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); |
6636 | 0 | break; |
6637 | 0 | case ETIR__C_STA_LW: |
6638 | 0 | fprintf (file, _("STA_LW (stack longword)")); |
6639 | 0 | if (rest >= 4) |
6640 | 0 | fprintf (file, " 0x%08x\n", |
6641 | 0 | (unsigned) bfd_getl32 (buf)); |
6642 | 0 | break; |
6643 | 0 | case ETIR__C_STA_QW: |
6644 | 0 | fprintf (file, _("STA_QW (stack quadword)")); |
6645 | 0 | if (rest >= 8) |
6646 | 0 | fprintf (file, " 0x%08x %08x\n", |
6647 | 0 | (unsigned) bfd_getl32 (buf + 4), |
6648 | 0 | (unsigned) bfd_getl32 (buf + 0)); |
6649 | 0 | break; |
6650 | 0 | case ETIR__C_STA_PQ: |
6651 | 0 | fprintf (file, _("STA_PQ (stack psect base + offset)\n")); |
6652 | 0 | if (rest >= 12) |
6653 | | /* xgettext:c-format */ |
6654 | 0 | fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"), |
6655 | 0 | (unsigned) bfd_getl32 (buf + 0), |
6656 | 0 | (unsigned) bfd_getl32 (buf + 8), |
6657 | 0 | (unsigned) bfd_getl32 (buf + 4)); |
6658 | 0 | break; |
6659 | 0 | case ETIR__C_STA_LI: |
6660 | 0 | fprintf (file, _("STA_LI (stack literal)\n")); |
6661 | 0 | break; |
6662 | 0 | case ETIR__C_STA_MOD: |
6663 | 0 | fprintf (file, _("STA_MOD (stack module)\n")); |
6664 | 0 | break; |
6665 | 0 | case ETIR__C_STA_CKARG: |
6666 | 0 | fprintf (file, _("STA_CKARG (compare procedure argument)\n")); |
6667 | 0 | break; |
6668 | | |
6669 | 0 | case ETIR__C_STO_B: |
6670 | 0 | fprintf (file, _("STO_B (store byte)\n")); |
6671 | 0 | break; |
6672 | 0 | case ETIR__C_STO_W: |
6673 | 0 | fprintf (file, _("STO_W (store word)\n")); |
6674 | 0 | break; |
6675 | 0 | case ETIR__C_STO_LW: |
6676 | 0 | fprintf (file, _("STO_LW (store longword)\n")); |
6677 | 0 | break; |
6678 | 0 | case ETIR__C_STO_QW: |
6679 | 0 | fprintf (file, _("STO_QW (store quadword)\n")); |
6680 | 0 | break; |
6681 | 0 | case ETIR__C_STO_IMMR: |
6682 | 0 | if (rest >= 4) |
6683 | 0 | { |
6684 | 0 | unsigned int rpt = bfd_getl32 (buf); |
6685 | 0 | fprintf (file, |
6686 | 0 | _("STO_IMMR (store immediate repeat) %u bytes\n"), |
6687 | 0 | rpt); |
6688 | 0 | if (rpt > rest - 4) |
6689 | 0 | rpt = rest - 4; |
6690 | 0 | evax_bfd_print_hex (file, " ", buf + 4, rpt); |
6691 | 0 | } |
6692 | 0 | break; |
6693 | 0 | case ETIR__C_STO_GBL: |
6694 | 0 | if (rest >= 1) |
6695 | 0 | fprintf (file, _("STO_GBL (store global) %.*s\n"), |
6696 | 0 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); |
6697 | 0 | break; |
6698 | 0 | case ETIR__C_STO_CA: |
6699 | 0 | if (rest >= 1) |
6700 | 0 | fprintf (file, _("STO_CA (store code address) %.*s\n"), |
6701 | 0 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); |
6702 | 0 | break; |
6703 | 0 | case ETIR__C_STO_RB: |
6704 | 0 | fprintf (file, _("STO_RB (store relative branch)\n")); |
6705 | 0 | break; |
6706 | 0 | case ETIR__C_STO_AB: |
6707 | 0 | fprintf (file, _("STO_AB (store absolute branch)\n")); |
6708 | 0 | break; |
6709 | 0 | case ETIR__C_STO_OFF: |
6710 | 0 | fprintf (file, _("STO_OFF (store offset to psect)\n")); |
6711 | 0 | break; |
6712 | 0 | case ETIR__C_STO_IMM: |
6713 | 0 | if (rest >= 4) |
6714 | 0 | { |
6715 | 0 | unsigned int rpt = bfd_getl32 (buf); |
6716 | 0 | fprintf (file, |
6717 | 0 | _("STO_IMM (store immediate) %u bytes\n"), |
6718 | 0 | rpt); |
6719 | 0 | if (rpt > rest - 4) |
6720 | 0 | rpt = rest - 4; |
6721 | 0 | evax_bfd_print_hex (file, " ", buf + 4, rpt); |
6722 | 0 | } |
6723 | 0 | break; |
6724 | 0 | case ETIR__C_STO_GBL_LW: |
6725 | 0 | if (rest >= 1) |
6726 | 0 | fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"), |
6727 | 0 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); |
6728 | 0 | break; |
6729 | 0 | case ETIR__C_STO_LP_PSB: |
6730 | 0 | fprintf (file, _("STO_OFF (store LP with procedure signature)\n")); |
6731 | 0 | break; |
6732 | 0 | case ETIR__C_STO_HINT_GBL: |
6733 | 0 | fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n")); |
6734 | 0 | break; |
6735 | 0 | case ETIR__C_STO_HINT_PS: |
6736 | 0 | fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n")); |
6737 | 0 | break; |
6738 | | |
6739 | 0 | case ETIR__C_OPR_NOP: |
6740 | 0 | fprintf (file, _("OPR_NOP (no-operation)\n")); |
6741 | 0 | break; |
6742 | 0 | case ETIR__C_OPR_ADD: |
6743 | 0 | fprintf (file, _("OPR_ADD (add)\n")); |
6744 | 0 | break; |
6745 | 0 | case ETIR__C_OPR_SUB: |
6746 | 0 | fprintf (file, _("OPR_SUB (subtract)\n")); |
6747 | 0 | break; |
6748 | 0 | case ETIR__C_OPR_MUL: |
6749 | 0 | fprintf (file, _("OPR_MUL (multiply)\n")); |
6750 | 0 | break; |
6751 | 0 | case ETIR__C_OPR_DIV: |
6752 | 0 | fprintf (file, _("OPR_DIV (divide)\n")); |
6753 | 0 | break; |
6754 | 0 | case ETIR__C_OPR_AND: |
6755 | 0 | fprintf (file, _("OPR_AND (logical and)\n")); |
6756 | 0 | break; |
6757 | 0 | case ETIR__C_OPR_IOR: |
6758 | 0 | fprintf (file, _("OPR_IOR (logical inclusive or)\n")); |
6759 | 0 | break; |
6760 | 0 | case ETIR__C_OPR_EOR: |
6761 | 0 | fprintf (file, _("OPR_EOR (logical exclusive or)\n")); |
6762 | 0 | break; |
6763 | 0 | case ETIR__C_OPR_NEG: |
6764 | 0 | fprintf (file, _("OPR_NEG (negate)\n")); |
6765 | 0 | break; |
6766 | 0 | case ETIR__C_OPR_COM: |
6767 | 0 | fprintf (file, _("OPR_COM (complement)\n")); |
6768 | 0 | break; |
6769 | 0 | case ETIR__C_OPR_INSV: |
6770 | 0 | fprintf (file, _("OPR_INSV (insert field)\n")); |
6771 | 0 | break; |
6772 | 0 | case ETIR__C_OPR_ASH: |
6773 | 0 | fprintf (file, _("OPR_ASH (arithmetic shift)\n")); |
6774 | 0 | break; |
6775 | 0 | case ETIR__C_OPR_USH: |
6776 | 0 | fprintf (file, _("OPR_USH (unsigned shift)\n")); |
6777 | 0 | break; |
6778 | 0 | case ETIR__C_OPR_ROT: |
6779 | 0 | fprintf (file, _("OPR_ROT (rotate)\n")); |
6780 | 0 | break; |
6781 | 0 | case ETIR__C_OPR_SEL: |
6782 | 0 | fprintf (file, _("OPR_SEL (select)\n")); |
6783 | 0 | break; |
6784 | 0 | case ETIR__C_OPR_REDEF: |
6785 | 0 | fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n")); |
6786 | 0 | break; |
6787 | 0 | case ETIR__C_OPR_DFLIT: |
6788 | 0 | fprintf (file, _("OPR_REDEF (define a literal)\n")); |
6789 | 0 | break; |
6790 | | |
6791 | 0 | case ETIR__C_STC_LP: |
6792 | 0 | fprintf (file, _("STC_LP (store cond linkage pair)\n")); |
6793 | 0 | break; |
6794 | 0 | case ETIR__C_STC_LP_PSB: |
6795 | 0 | fprintf (file, |
6796 | 0 | _("STC_LP_PSB (store cond linkage pair + signature)\n")); |
6797 | 0 | if (rest >= 5) |
6798 | 0 | { |
6799 | | /* xgettext:c-format */ |
6800 | 0 | fprintf (file, _(" linkage index: %u, procedure: %.*s\n"), |
6801 | 0 | (unsigned) bfd_getl32 (buf), |
6802 | 0 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); |
6803 | 0 | if (rest > 4 + 1u + buf[4]) |
6804 | 0 | { |
6805 | 0 | rest -= 4 + 1 + buf[4]; |
6806 | 0 | buf += 4 + 1 + buf[4]; |
6807 | 0 | fprintf (file, _(" signature: %.*s\n"), |
6808 | 0 | buf[0] > rest - 1 ? rest - 1: buf[0], buf + 1); |
6809 | 0 | } |
6810 | 0 | } |
6811 | 0 | break; |
6812 | 0 | case ETIR__C_STC_GBL: |
6813 | 0 | fprintf (file, _("STC_GBL (store cond global)\n")); |
6814 | 0 | if (rest >= 5) |
6815 | | /* xgettext:c-format */ |
6816 | 0 | fprintf (file, _(" linkage index: %u, global: %.*s\n"), |
6817 | 0 | (unsigned) bfd_getl32 (buf), |
6818 | 0 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); |
6819 | 0 | break; |
6820 | 0 | case ETIR__C_STC_GCA: |
6821 | 0 | fprintf (file, _("STC_GCA (store cond code address)\n")); |
6822 | 0 | if (rest >= 5) |
6823 | | /* xgettext:c-format */ |
6824 | 0 | fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"), |
6825 | 0 | (unsigned) bfd_getl32 (buf), |
6826 | 0 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); |
6827 | 0 | break; |
6828 | 0 | case ETIR__C_STC_PS: |
6829 | 0 | fprintf (file, _("STC_PS (store cond psect + offset)\n")); |
6830 | 0 | if (rest >= 16) |
6831 | 0 | fprintf (file, |
6832 | | /* xgettext:c-format */ |
6833 | 0 | _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"), |
6834 | 0 | (unsigned)bfd_getl32 (buf), |
6835 | 0 | (unsigned)bfd_getl32 (buf + 4), |
6836 | 0 | (unsigned)bfd_getl32 (buf + 12), |
6837 | 0 | (unsigned)bfd_getl32 (buf + 8)); |
6838 | 0 | break; |
6839 | 0 | case ETIR__C_STC_NOP_GBL: |
6840 | 0 | fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n")); |
6841 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
6842 | 0 | break; |
6843 | 0 | case ETIR__C_STC_NOP_PS: |
6844 | 0 | fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n")); |
6845 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
6846 | 0 | break; |
6847 | 0 | case ETIR__C_STC_BSR_GBL: |
6848 | 0 | fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n")); |
6849 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
6850 | 0 | break; |
6851 | 0 | case ETIR__C_STC_BSR_PS: |
6852 | 0 | fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n")); |
6853 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
6854 | 0 | break; |
6855 | 0 | case ETIR__C_STC_LDA_GBL: |
6856 | 0 | fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n")); |
6857 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
6858 | 0 | break; |
6859 | 0 | case ETIR__C_STC_LDA_PS: |
6860 | 0 | fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n")); |
6861 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
6862 | 0 | break; |
6863 | 0 | case ETIR__C_STC_BOH_GBL: |
6864 | 0 | fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n")); |
6865 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
6866 | 0 | break; |
6867 | 0 | case ETIR__C_STC_BOH_PS: |
6868 | 0 | fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n")); |
6869 | 0 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
6870 | 0 | break; |
6871 | 0 | case ETIR__C_STC_NBH_GBL: |
6872 | 0 | fprintf (file, |
6873 | 0 | _("STC_NBH_GBL (store cond or hint at global addr)\n")); |
6874 | 0 | break; |
6875 | 0 | case ETIR__C_STC_NBH_PS: |
6876 | 0 | fprintf (file, |
6877 | 0 | _("STC_NBH_PS (store cond or hint at psect + offset)\n")); |
6878 | 0 | break; |
6879 | | |
6880 | 0 | case ETIR__C_CTL_SETRB: |
6881 | 0 | fprintf (file, _("CTL_SETRB (set relocation base)\n")); |
6882 | 0 | break; |
6883 | 0 | case ETIR__C_CTL_AUGRB: |
6884 | 0 | if (rest >= 4) |
6885 | 0 | { |
6886 | 0 | unsigned int val = bfd_getl32 (buf); |
6887 | 0 | fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"), |
6888 | 0 | val); |
6889 | 0 | } |
6890 | 0 | break; |
6891 | 0 | case ETIR__C_CTL_DFLOC: |
6892 | 0 | fprintf (file, _("CTL_DFLOC (define location)\n")); |
6893 | 0 | break; |
6894 | 0 | case ETIR__C_CTL_STLOC: |
6895 | 0 | fprintf (file, _("CTL_STLOC (set location)\n")); |
6896 | 0 | break; |
6897 | 0 | case ETIR__C_CTL_STKDL: |
6898 | 0 | fprintf (file, _("CTL_STKDL (stack defined location)\n")); |
6899 | 0 | break; |
6900 | 0 | default: |
6901 | 0 | fprintf (file, _("*unhandled*\n")); |
6902 | 0 | break; |
6903 | 0 | } |
6904 | 0 | off += size; |
6905 | 0 | } |
6906 | 0 | } |
6907 | | |
6908 | | static void |
6909 | | evax_bfd_print_eobj (struct bfd *abfd, FILE *file) |
6910 | 0 | { |
6911 | 0 | bool is_first = true; |
6912 | 0 | bool has_records = true; |
6913 | |
|
6914 | 0 | while (1) |
6915 | 0 | { |
6916 | 0 | unsigned int rec_len; |
6917 | 0 | unsigned int pad_len; |
6918 | 0 | unsigned char *rec; |
6919 | 0 | unsigned int hdr_size; |
6920 | 0 | unsigned int type; |
6921 | 0 | unsigned char buf[6]; |
6922 | |
|
6923 | 0 | hdr_size = has_records ? 6 : 4; |
6924 | 0 | if (bfd_read (buf, hdr_size, abfd) != hdr_size) |
6925 | 0 | { |
6926 | 0 | fprintf (file, _("cannot read GST record header\n")); |
6927 | 0 | return; |
6928 | 0 | } |
6929 | | |
6930 | 0 | type = bfd_getl16 (buf); |
6931 | 0 | rec_len = bfd_getl16 (buf + 2); |
6932 | 0 | pad_len = rec_len; |
6933 | 0 | if (has_records) |
6934 | 0 | { |
6935 | 0 | unsigned int rec_len2 = bfd_getl16 (buf + 4); |
6936 | |
|
6937 | 0 | if (is_first) |
6938 | 0 | { |
6939 | 0 | is_first = false; |
6940 | 0 | if (type == rec_len2 && rec_len == EOBJ__C_EMH) |
6941 | | /* Matched a VMS record EMH. */ |
6942 | 0 | ; |
6943 | 0 | else |
6944 | 0 | { |
6945 | 0 | has_records = false; |
6946 | 0 | if (type != EOBJ__C_EMH) |
6947 | 0 | { |
6948 | | /* Ill-formed. */ |
6949 | 0 | fprintf (file, _("cannot find EMH in first GST record\n")); |
6950 | 0 | return; |
6951 | 0 | } |
6952 | 0 | } |
6953 | 0 | } |
6954 | | |
6955 | 0 | if (has_records) |
6956 | 0 | { |
6957 | | /* VMS record format is: record-size, type, record-size. |
6958 | | See maybe_adjust_record_pointer_for_object comment. */ |
6959 | 0 | if (type == rec_len2) |
6960 | 0 | { |
6961 | 0 | type = rec_len; |
6962 | 0 | rec_len = rec_len2; |
6963 | 0 | } |
6964 | 0 | else |
6965 | 0 | rec_len = 0; |
6966 | 0 | pad_len = (rec_len + 1) & ~1U; |
6967 | 0 | hdr_size = 4; |
6968 | 0 | } |
6969 | 0 | } |
6970 | | |
6971 | 0 | if (rec_len < hdr_size) |
6972 | 0 | { |
6973 | 0 | fprintf (file, _("corrupted GST\n")); |
6974 | 0 | return; |
6975 | 0 | } |
6976 | | |
6977 | 0 | rec = bfd_malloc (pad_len); |
6978 | 0 | if (rec == NULL) |
6979 | 0 | return; |
6980 | | |
6981 | 0 | memcpy (rec, buf + (has_records ? 2 : 0), hdr_size); |
6982 | |
|
6983 | 0 | if (bfd_read (rec + hdr_size, pad_len - hdr_size, abfd) |
6984 | 0 | != pad_len - hdr_size) |
6985 | 0 | { |
6986 | 0 | fprintf (file, _("cannot read GST record\n")); |
6987 | 0 | free (rec); |
6988 | 0 | return; |
6989 | 0 | } |
6990 | | |
6991 | 0 | switch (type) |
6992 | 0 | { |
6993 | 0 | case EOBJ__C_EMH: |
6994 | 0 | evax_bfd_print_emh (file, rec, rec_len); |
6995 | 0 | break; |
6996 | 0 | case EOBJ__C_EGSD: |
6997 | 0 | evax_bfd_print_egsd (file, rec, rec_len); |
6998 | 0 | break; |
6999 | 0 | case EOBJ__C_EEOM: |
7000 | 0 | evax_bfd_print_eeom (file, rec, rec_len); |
7001 | 0 | free (rec); |
7002 | 0 | return; |
7003 | 0 | case EOBJ__C_ETIR: |
7004 | 0 | evax_bfd_print_etir (file, "ETIR", rec, rec_len); |
7005 | 0 | break; |
7006 | 0 | case EOBJ__C_EDBG: |
7007 | 0 | evax_bfd_print_etir (file, "EDBG", rec, rec_len); |
7008 | 0 | break; |
7009 | 0 | case EOBJ__C_ETBT: |
7010 | 0 | evax_bfd_print_etir (file, "ETBT", rec, rec_len); |
7011 | 0 | break; |
7012 | 0 | default: |
7013 | 0 | fprintf (file, _(" unhandled EOBJ record type %u\n"), type); |
7014 | 0 | break; |
7015 | 0 | } |
7016 | 0 | free (rec); |
7017 | 0 | } |
7018 | 0 | } |
7019 | | |
7020 | | static void |
7021 | | evax_bfd_print_relocation_records (FILE *file, const unsigned char *buf, |
7022 | | size_t buf_size, size_t off, |
7023 | | unsigned int stride) |
7024 | 47 | { |
7025 | 68 | while (off <= buf_size - 8) |
7026 | 26 | { |
7027 | 26 | unsigned int base; |
7028 | 26 | unsigned int count; |
7029 | 26 | unsigned int j; |
7030 | | |
7031 | 26 | count = bfd_getl32 (buf + off + 0); |
7032 | | |
7033 | 26 | if (count == 0) |
7034 | 5 | break; |
7035 | 21 | base = bfd_getl32 (buf + off + 4); |
7036 | | |
7037 | | /* xgettext:c-format */ |
7038 | 21 | fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"), |
7039 | 21 | count, base); |
7040 | | |
7041 | 21 | off += 8; |
7042 | 10.5k | for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32) |
7043 | 10.5k | { |
7044 | 10.5k | unsigned int k; |
7045 | 10.5k | unsigned int n = 0; |
7046 | 10.5k | unsigned int val; |
7047 | | |
7048 | 10.5k | val = bfd_getl32 (buf + off); |
7049 | 10.5k | off += 4; |
7050 | | |
7051 | | /* xgettext:c-format */ |
7052 | 10.5k | fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count); |
7053 | | |
7054 | 348k | for (k = 0; k < 32; k++) |
7055 | 337k | if (val & (1u << k)) |
7056 | 49.9k | { |
7057 | 49.9k | if (n == 0) |
7058 | 10.0k | fputs (" ", file); |
7059 | 49.9k | fprintf (file, _(" %08x"), base + (j * 8 + k) * stride); |
7060 | 49.9k | n++; |
7061 | 49.9k | if (n == 8) |
7062 | 3.74k | { |
7063 | 3.74k | fputs ("\n", file); |
7064 | 3.74k | n = 0; |
7065 | 3.74k | } |
7066 | 49.9k | } |
7067 | 10.5k | if (n) |
7068 | 6.32k | fputs ("\n", file); |
7069 | 10.5k | } |
7070 | 21 | } |
7071 | 47 | } |
7072 | | |
7073 | | static void |
7074 | | evax_bfd_print_address_fixups (FILE *file, const unsigned char *buf, |
7075 | | size_t buf_size, size_t off) |
7076 | 47 | { |
7077 | 64 | while (off <= buf_size - 8) |
7078 | 18 | { |
7079 | 18 | unsigned int j; |
7080 | 18 | unsigned int count; |
7081 | | |
7082 | 18 | count = bfd_getl32 (buf + off + 0); |
7083 | 18 | if (count == 0) |
7084 | 1 | return; |
7085 | | /* xgettext:c-format */ |
7086 | 17 | fprintf (file, _(" image %u (%u entries)\n"), |
7087 | 17 | (unsigned) bfd_getl32 (buf + off + 4), count); |
7088 | 17 | off += 8; |
7089 | 1.88k | for (j = 0; j < count && off <= buf_size - 8; j++) |
7090 | 1.86k | { |
7091 | | /* xgettext:c-format */ |
7092 | 1.86k | fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"), |
7093 | 1.86k | (unsigned) bfd_getl32 (buf + off + 0), |
7094 | 1.86k | (unsigned) bfd_getl32 (buf + off + 4)); |
7095 | 1.86k | off += 8; |
7096 | 1.86k | } |
7097 | 17 | } |
7098 | 47 | } |
7099 | | |
7100 | | static void |
7101 | | evax_bfd_print_reference_fixups (FILE *file, const unsigned char *buf, |
7102 | | size_t buf_size, size_t off) |
7103 | 48 | { |
7104 | 48 | unsigned int count; |
7105 | | |
7106 | 77 | while (off <= buf_size - 8) |
7107 | 36 | { |
7108 | 36 | unsigned int j; |
7109 | 36 | unsigned int n = 0; |
7110 | | |
7111 | 36 | count = bfd_getl32 (buf + off + 0); |
7112 | 36 | if (count == 0) |
7113 | 7 | break; |
7114 | | /* xgettext:c-format */ |
7115 | 29 | fprintf (file, _(" image %u (%u entries), offsets:\n"), |
7116 | 29 | (unsigned) bfd_getl32 (buf + off + 4), count); |
7117 | 29 | off += 8; |
7118 | 14.2k | for (j = 0; j < count && off <= buf_size - 4; j++) |
7119 | 14.2k | { |
7120 | 14.2k | if (n == 0) |
7121 | 2.05k | fputs (" ", file); |
7122 | 14.2k | fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off)); |
7123 | 14.2k | n++; |
7124 | 14.2k | if (n == 7) |
7125 | 2.02k | { |
7126 | 2.02k | fputs ("\n", file); |
7127 | 2.02k | n = 0; |
7128 | 2.02k | } |
7129 | 14.2k | off += 4; |
7130 | 14.2k | } |
7131 | 29 | if (n) |
7132 | 24 | fputs ("\n", file); |
7133 | 29 | } |
7134 | 48 | } |
7135 | | |
7136 | | static void |
7137 | | evax_bfd_print_indent (int indent, FILE *file) |
7138 | 3 | { |
7139 | 15 | for (; indent; indent--) |
7140 | 12 | fputc (' ', file); |
7141 | 3 | } |
7142 | | |
7143 | | static const char * |
7144 | | evax_bfd_get_dsc_name (unsigned int v) |
7145 | 4 | { |
7146 | 4 | switch (v) |
7147 | 4 | { |
7148 | 0 | case DSC__K_DTYPE_Z: |
7149 | 0 | return "Z (Unspecified)"; |
7150 | 0 | case DSC__K_DTYPE_V: |
7151 | 0 | return "V (Bit)"; |
7152 | 0 | case DSC__K_DTYPE_BU: |
7153 | 0 | return "BU (Byte logical)"; |
7154 | 0 | case DSC__K_DTYPE_WU: |
7155 | 0 | return "WU (Word logical)"; |
7156 | 1 | case DSC__K_DTYPE_LU: |
7157 | 1 | return "LU (Longword logical)"; |
7158 | 0 | case DSC__K_DTYPE_QU: |
7159 | 0 | return "QU (Quadword logical)"; |
7160 | 0 | case DSC__K_DTYPE_B: |
7161 | 0 | return "B (Byte integer)"; |
7162 | 0 | case DSC__K_DTYPE_W: |
7163 | 0 | return "W (Word integer)"; |
7164 | 0 | case DSC__K_DTYPE_L: |
7165 | 0 | return "L (Longword integer)"; |
7166 | 1 | case DSC__K_DTYPE_Q: |
7167 | 1 | return "Q (Quadword integer)"; |
7168 | 0 | case DSC__K_DTYPE_F: |
7169 | 0 | return "F (Single-precision floating)"; |
7170 | 0 | case DSC__K_DTYPE_D: |
7171 | 0 | return "D (Double-precision floating)"; |
7172 | 0 | case DSC__K_DTYPE_FC: |
7173 | 0 | return "FC (Complex)"; |
7174 | 0 | case DSC__K_DTYPE_DC: |
7175 | 0 | return "DC (Double-precision Complex)"; |
7176 | 0 | case DSC__K_DTYPE_T: |
7177 | 0 | return "T (ASCII text string)"; |
7178 | 0 | case DSC__K_DTYPE_NU: |
7179 | 0 | return "NU (Numeric string, unsigned)"; |
7180 | 0 | case DSC__K_DTYPE_NL: |
7181 | 0 | return "NL (Numeric string, left separate sign)"; |
7182 | 0 | case DSC__K_DTYPE_NLO: |
7183 | 0 | return "NLO (Numeric string, left overpunched sign)"; |
7184 | 0 | case DSC__K_DTYPE_NR: |
7185 | 0 | return "NR (Numeric string, right separate sign)"; |
7186 | 0 | case DSC__K_DTYPE_NRO: |
7187 | 0 | return "NRO (Numeric string, right overpunched sig)"; |
7188 | 0 | case DSC__K_DTYPE_NZ: |
7189 | 0 | return "NZ (Numeric string, zoned sign)"; |
7190 | 0 | case DSC__K_DTYPE_P: |
7191 | 0 | return "P (Packed decimal string)"; |
7192 | 0 | case DSC__K_DTYPE_ZI: |
7193 | 0 | return "ZI (Sequence of instructions)"; |
7194 | 0 | case DSC__K_DTYPE_ZEM: |
7195 | 0 | return "ZEM (Procedure entry mask)"; |
7196 | 0 | case DSC__K_DTYPE_DSC: |
7197 | 0 | return "DSC (Descriptor, used for arrays of dyn strings)"; |
7198 | 0 | case DSC__K_DTYPE_OU: |
7199 | 0 | return "OU (Octaword logical)"; |
7200 | 0 | case DSC__K_DTYPE_O: |
7201 | 0 | return "O (Octaword integer)"; |
7202 | 0 | case DSC__K_DTYPE_G: |
7203 | 0 | return "G (Double precision G floating, 64 bit)"; |
7204 | 1 | case DSC__K_DTYPE_H: |
7205 | 1 | return "H (Quadruple precision floating, 128 bit)"; |
7206 | 0 | case DSC__K_DTYPE_GC: |
7207 | 0 | return "GC (Double precision complex, G floating)"; |
7208 | 0 | case DSC__K_DTYPE_HC: |
7209 | 0 | return "HC (Quadruple precision complex, H floating)"; |
7210 | 0 | case DSC__K_DTYPE_CIT: |
7211 | 0 | return "CIT (COBOL intermediate temporary)"; |
7212 | 0 | case DSC__K_DTYPE_BPV: |
7213 | 0 | return "BPV (Bound Procedure Value)"; |
7214 | 0 | case DSC__K_DTYPE_BLV: |
7215 | 0 | return "BLV (Bound Label Value)"; |
7216 | 1 | case DSC__K_DTYPE_VU: |
7217 | 1 | return "VU (Bit Unaligned)"; |
7218 | 0 | case DSC__K_DTYPE_ADT: |
7219 | 0 | return "ADT (Absolute Date-Time)"; |
7220 | 0 | case DSC__K_DTYPE_VT: |
7221 | 0 | return "VT (Varying Text)"; |
7222 | 0 | case DSC__K_DTYPE_T2: |
7223 | 0 | return "T2 (16-bit char)"; |
7224 | 0 | case DSC__K_DTYPE_VT2: |
7225 | 0 | return "VT2 (16-bit varying char)"; |
7226 | 0 | default: |
7227 | 0 | return "?? (unknown)"; |
7228 | 4 | } |
7229 | 4 | } |
7230 | | |
7231 | | static void |
7232 | | evax_bfd_print_desc (const unsigned char *buf, unsigned int bufsize, |
7233 | | int indent, FILE *file) |
7234 | 0 | { |
7235 | 0 | if (bufsize < 8) |
7236 | 0 | return; |
7237 | | |
7238 | 0 | unsigned char bclass = buf[3]; |
7239 | 0 | unsigned char dtype = buf[2]; |
7240 | 0 | unsigned int len = (unsigned)bfd_getl16 (buf); |
7241 | 0 | unsigned int pointer = (unsigned)bfd_getl32 (buf + 4); |
7242 | |
|
7243 | 0 | evax_bfd_print_indent (indent, file); |
7244 | |
|
7245 | 0 | if (len == 1 && pointer == 0xffffffffUL) |
7246 | 0 | { |
7247 | | /* 64 bits. */ |
7248 | 0 | fprintf (file, _("64 bits *unhandled*\n")); |
7249 | 0 | } |
7250 | 0 | else |
7251 | 0 | { |
7252 | | /* xgettext:c-format */ |
7253 | 0 | fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"), |
7254 | 0 | bclass, dtype, len, pointer); |
7255 | 0 | switch (bclass) |
7256 | 0 | { |
7257 | 0 | case DSC__K_CLASS_NCA: |
7258 | 0 | { |
7259 | 0 | const struct vms_dsc_nca *dsc = (const void *)buf; |
7260 | 0 | unsigned int i; |
7261 | 0 | const unsigned char *b; |
7262 | |
|
7263 | 0 | evax_bfd_print_indent (indent, file); |
7264 | 0 | fprintf (file, _("non-contiguous array of %s\n"), |
7265 | 0 | evax_bfd_get_dsc_name (dsc->dtype)); |
7266 | 0 | if (bufsize >= sizeof (*dsc)) |
7267 | 0 | { |
7268 | 0 | evax_bfd_print_indent (indent + 1, file); |
7269 | 0 | fprintf (file, |
7270 | | /* xgettext:c-format */ |
7271 | 0 | _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"), |
7272 | 0 | dsc->dimct, dsc->aflags, dsc->digits, dsc->scale); |
7273 | 0 | evax_bfd_print_indent (indent + 1, file); |
7274 | 0 | fprintf (file, |
7275 | | /* xgettext:c-format */ |
7276 | 0 | _("arsize: %u, a0: 0x%08x\n"), |
7277 | 0 | (unsigned) bfd_getl32 (dsc->arsize), |
7278 | 0 | (unsigned) bfd_getl32 (dsc->a0)); |
7279 | 0 | evax_bfd_print_indent (indent + 1, file); |
7280 | 0 | fprintf (file, _("Strides:\n")); |
7281 | 0 | b = buf + sizeof (*dsc); |
7282 | 0 | bufsize -= sizeof (*dsc); |
7283 | 0 | for (i = 0; i < dsc->dimct; i++) |
7284 | 0 | { |
7285 | 0 | if (bufsize < 4) |
7286 | 0 | break; |
7287 | 0 | evax_bfd_print_indent (indent + 2, file); |
7288 | 0 | fprintf (file, "[%u]: %u\n", i + 1, |
7289 | 0 | (unsigned) bfd_getl32 (b)); |
7290 | 0 | b += 4; |
7291 | 0 | bufsize -= 4; |
7292 | 0 | } |
7293 | 0 | evax_bfd_print_indent (indent + 1, file); |
7294 | 0 | fprintf (file, _("Bounds:\n")); |
7295 | 0 | for (i = 0; i < dsc->dimct; i++) |
7296 | 0 | { |
7297 | 0 | if (bufsize < 8) |
7298 | 0 | break; |
7299 | 0 | evax_bfd_print_indent (indent + 2, file); |
7300 | | /* xgettext:c-format */ |
7301 | 0 | fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1, |
7302 | 0 | (unsigned) bfd_getl32 (b + 0), |
7303 | 0 | (unsigned) bfd_getl32 (b + 4)); |
7304 | 0 | b += 8; |
7305 | 0 | bufsize -= 8; |
7306 | 0 | } |
7307 | 0 | } |
7308 | 0 | } |
7309 | 0 | break; |
7310 | 0 | case DSC__K_CLASS_UBS: |
7311 | 0 | { |
7312 | 0 | const struct vms_dsc_ubs *ubs = (const void *)buf; |
7313 | |
|
7314 | 0 | evax_bfd_print_indent (indent, file); |
7315 | 0 | fprintf (file, _("unaligned bit-string of %s\n"), |
7316 | 0 | evax_bfd_get_dsc_name (ubs->dtype)); |
7317 | 0 | if (bufsize >= sizeof (*ubs)) |
7318 | 0 | { |
7319 | 0 | evax_bfd_print_indent (indent + 1, file); |
7320 | 0 | fprintf (file, |
7321 | | /* xgettext:c-format */ |
7322 | 0 | _("base: %u, pos: %u\n"), |
7323 | 0 | (unsigned) bfd_getl32 (ubs->base), |
7324 | 0 | (unsigned) bfd_getl32 (ubs->pos)); |
7325 | 0 | } |
7326 | 0 | } |
7327 | 0 | break; |
7328 | 0 | default: |
7329 | 0 | fprintf (file, _("*unhandled*\n")); |
7330 | 0 | break; |
7331 | 0 | } |
7332 | 0 | } |
7333 | 0 | } |
7334 | | |
7335 | | static unsigned int |
7336 | | evax_bfd_print_valspec (const unsigned char *buf, unsigned int bufsize, |
7337 | | int indent, FILE *file) |
7338 | 4 | { |
7339 | 4 | if (bufsize < 5) |
7340 | 1 | return bufsize; |
7341 | | |
7342 | 3 | unsigned int vflags = buf[0]; |
7343 | 3 | unsigned int value = (unsigned) bfd_getl32 (buf + 1); |
7344 | 3 | unsigned int len = 5; |
7345 | | |
7346 | 3 | evax_bfd_print_indent (indent, file); |
7347 | | /* xgettext:c-format */ |
7348 | 3 | fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value); |
7349 | 3 | buf += 5; |
7350 | 3 | bufsize -= 5; |
7351 | | |
7352 | 3 | switch (vflags) |
7353 | 3 | { |
7354 | 0 | case DST__K_VFLAGS_NOVAL: |
7355 | 0 | fprintf (file, _("(no value)\n")); |
7356 | 0 | break; |
7357 | 0 | case DST__K_VFLAGS_NOTACTIVE: |
7358 | 0 | fprintf (file, _("(not active)\n")); |
7359 | 0 | break; |
7360 | 0 | case DST__K_VFLAGS_UNALLOC: |
7361 | 0 | fprintf (file, _("(not allocated)\n")); |
7362 | 0 | break; |
7363 | 0 | case DST__K_VFLAGS_DSC: |
7364 | 0 | fprintf (file, _("(descriptor)\n")); |
7365 | 0 | if (value <= bufsize) |
7366 | 0 | evax_bfd_print_desc (buf + value, bufsize - value, indent + 1, file); |
7367 | 0 | break; |
7368 | 0 | case DST__K_VFLAGS_TVS: |
7369 | 0 | fprintf (file, _("(trailing value)\n")); |
7370 | 0 | break; |
7371 | 0 | case DST__K_VS_FOLLOWS: |
7372 | 0 | fprintf (file, _("(value spec follows)\n")); |
7373 | 0 | break; |
7374 | 0 | case DST__K_VFLAGS_BITOFFS: |
7375 | 0 | fprintf (file, _("(at bit offset %u)\n"), value); |
7376 | 0 | break; |
7377 | 3 | default: |
7378 | | /* xgettext:c-format */ |
7379 | 3 | fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "), |
7380 | 3 | (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT, |
7381 | 3 | vflags & DST__K_DISP ? 1 : 0, |
7382 | 3 | vflags & DST__K_INDIR ? 1 : 0); |
7383 | 3 | switch (vflags & DST__K_VALKIND_MASK) |
7384 | 3 | { |
7385 | 1 | case DST__K_VALKIND_LITERAL: |
7386 | 1 | fputs (_("literal"), file); |
7387 | 1 | break; |
7388 | 0 | case DST__K_VALKIND_ADDR: |
7389 | 0 | fputs (_("address"), file); |
7390 | 0 | break; |
7391 | 0 | case DST__K_VALKIND_DESC: |
7392 | 0 | fputs (_("desc"), file); |
7393 | 0 | break; |
7394 | 2 | case DST__K_VALKIND_REG: |
7395 | 2 | fputs (_("reg"), file); |
7396 | 2 | break; |
7397 | 3 | } |
7398 | 3 | fputs (")\n", file); |
7399 | 3 | break; |
7400 | 3 | } |
7401 | 3 | return len; |
7402 | 3 | } |
7403 | | |
7404 | | static void |
7405 | | evax_bfd_print_typspec (const unsigned char *buf, unsigned int bufsize, |
7406 | | int indent, FILE *file) |
7407 | 0 | { |
7408 | 0 | if (bufsize < 3) |
7409 | 0 | return; |
7410 | | |
7411 | 0 | unsigned char kind = buf[2]; |
7412 | 0 | unsigned int len = (unsigned) bfd_getl16 (buf); |
7413 | |
|
7414 | 0 | evax_bfd_print_indent (indent, file); |
7415 | | /* xgettext:c-format */ |
7416 | 0 | fprintf (file, _("len: %2u, kind: %2u "), len, kind); |
7417 | 0 | buf += 3; |
7418 | 0 | bufsize -= 3; |
7419 | 0 | switch (kind) |
7420 | 0 | { |
7421 | 0 | case DST__K_TS_ATOM: |
7422 | | /* xgettext:c-format */ |
7423 | 0 | if (bufsize >= 1) |
7424 | 0 | fprintf (file, _("atomic, type=0x%02x %s\n"), |
7425 | 0 | buf[0], evax_bfd_get_dsc_name (buf[0])); |
7426 | 0 | break; |
7427 | 0 | case DST__K_TS_IND: |
7428 | 0 | if (bufsize >= 4) |
7429 | 0 | fprintf (file, _("indirect, defined at 0x%08x\n"), |
7430 | 0 | (unsigned) bfd_getl32 (buf)); |
7431 | 0 | break; |
7432 | 0 | case DST__K_TS_TPTR: |
7433 | 0 | fprintf (file, _("typed pointer\n")); |
7434 | 0 | evax_bfd_print_typspec (buf, bufsize, indent + 1, file); |
7435 | 0 | break; |
7436 | 0 | case DST__K_TS_PTR: |
7437 | 0 | fprintf (file, _("pointer\n")); |
7438 | 0 | break; |
7439 | 0 | case DST__K_TS_ARRAY: |
7440 | 0 | { |
7441 | 0 | const unsigned char *vs; |
7442 | 0 | unsigned int vs_len; |
7443 | 0 | unsigned int vec_len; |
7444 | 0 | unsigned int i; |
7445 | |
|
7446 | 0 | if (bufsize == 0) |
7447 | 0 | return; |
7448 | 0 | fprintf (file, _("array, dim: %u, bitmap: "), buf[0]); |
7449 | 0 | --bufsize; |
7450 | 0 | vec_len = (buf[0] + 1 + 7) / 8; |
7451 | 0 | for (i = 0; i < vec_len; i++) |
7452 | 0 | { |
7453 | 0 | if (bufsize == 0) |
7454 | 0 | break; |
7455 | 0 | fprintf (file, " %02x", buf[i + 1]); |
7456 | 0 | --bufsize; |
7457 | 0 | } |
7458 | 0 | fputc ('\n', file); |
7459 | 0 | if (bufsize == 0) |
7460 | 0 | return; |
7461 | 0 | vs = buf + 1 + vec_len; |
7462 | 0 | evax_bfd_print_indent (indent, file); |
7463 | 0 | fprintf (file, _("array descriptor:\n")); |
7464 | 0 | vs_len = evax_bfd_print_valspec (vs, bufsize, indent + 1, file); |
7465 | 0 | vs += vs_len; |
7466 | 0 | if (bufsize > vs_len) |
7467 | 0 | { |
7468 | 0 | bufsize -= vs_len; |
7469 | 0 | for (i = 0; i < buf[0] + 1U; i++) |
7470 | 0 | if (buf[1 + i / 8] & (1 << (i % 8))) |
7471 | 0 | { |
7472 | 0 | evax_bfd_print_indent (indent, file); |
7473 | 0 | if (i == 0) |
7474 | 0 | fprintf (file, _("type spec for element:\n")); |
7475 | 0 | else |
7476 | 0 | fprintf (file, _("type spec for subscript %u:\n"), i); |
7477 | 0 | evax_bfd_print_typspec (vs, bufsize, indent + 1, file); |
7478 | 0 | if (bufsize < 2) |
7479 | 0 | break; |
7480 | 0 | vs_len = bfd_getl16 (vs); |
7481 | 0 | if (bufsize <= vs_len) |
7482 | 0 | break; |
7483 | 0 | vs += vs_len; |
7484 | 0 | bufsize -= vs_len; |
7485 | 0 | } |
7486 | 0 | } |
7487 | 0 | } |
7488 | 0 | break; |
7489 | 0 | default: |
7490 | 0 | fprintf (file, _("*unhandled*\n")); |
7491 | 0 | } |
7492 | 0 | } |
7493 | | |
7494 | | static void |
7495 | | evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file) |
7496 | 9 | { |
7497 | 9 | unsigned int off = 0; |
7498 | 9 | unsigned int pc = 0; |
7499 | 9 | unsigned int line = 0; |
7500 | | |
7501 | 9 | fprintf (file, _("Debug symbol table:\n")); |
7502 | | |
7503 | 29 | while (dst_size > 0) |
7504 | 28 | { |
7505 | 28 | struct vms_dst_header dsth; |
7506 | 28 | unsigned int len; |
7507 | 28 | unsigned int type; |
7508 | 28 | unsigned char *buf; |
7509 | | |
7510 | 28 | if (bfd_read (&dsth, sizeof (dsth), abfd) != sizeof (dsth)) |
7511 | 3 | { |
7512 | 3 | fprintf (file, _("cannot read DST header\n")); |
7513 | 3 | return; |
7514 | 3 | } |
7515 | 25 | len = bfd_getl16 (dsth.length); |
7516 | 25 | type = bfd_getl16 (dsth.type); |
7517 | | /* xgettext:c-format */ |
7518 | 25 | fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "), |
7519 | 25 | type, len, off); |
7520 | | /* !!! The length is short by one! */ |
7521 | 25 | len++; |
7522 | 25 | if (len > dst_size) |
7523 | 1 | len = dst_size; |
7524 | 25 | if (len < sizeof (dsth)) |
7525 | 0 | { |
7526 | 0 | fputc ('\n', file); |
7527 | 0 | break; |
7528 | 0 | } |
7529 | 25 | dst_size -= len; |
7530 | 25 | off += len; |
7531 | 25 | len -= sizeof (dsth); |
7532 | 25 | if (len == 0) |
7533 | 0 | buf = NULL; |
7534 | 25 | else |
7535 | 25 | { |
7536 | 25 | buf = _bfd_malloc_and_read (abfd, len, len); |
7537 | 25 | if (buf == NULL) |
7538 | 5 | { |
7539 | 5 | fprintf (file, _("cannot read DST symbol\n")); |
7540 | 5 | return; |
7541 | 5 | } |
7542 | 25 | } |
7543 | 20 | switch (type) |
7544 | 20 | { |
7545 | 0 | case DSC__K_DTYPE_V: |
7546 | 0 | case DSC__K_DTYPE_BU: |
7547 | 0 | case DSC__K_DTYPE_WU: |
7548 | 1 | case DSC__K_DTYPE_LU: |
7549 | 1 | case DSC__K_DTYPE_QU: |
7550 | 1 | case DSC__K_DTYPE_B: |
7551 | 1 | case DSC__K_DTYPE_W: |
7552 | 1 | case DSC__K_DTYPE_L: |
7553 | 2 | case DSC__K_DTYPE_Q: |
7554 | 2 | case DSC__K_DTYPE_F: |
7555 | 2 | case DSC__K_DTYPE_D: |
7556 | 2 | case DSC__K_DTYPE_FC: |
7557 | 2 | case DSC__K_DTYPE_DC: |
7558 | 2 | case DSC__K_DTYPE_T: |
7559 | 2 | case DSC__K_DTYPE_NU: |
7560 | 2 | case DSC__K_DTYPE_NL: |
7561 | 2 | case DSC__K_DTYPE_NLO: |
7562 | 2 | case DSC__K_DTYPE_NR: |
7563 | 2 | case DSC__K_DTYPE_NRO: |
7564 | 2 | case DSC__K_DTYPE_NZ: |
7565 | 2 | case DSC__K_DTYPE_P: |
7566 | 2 | case DSC__K_DTYPE_ZI: |
7567 | 2 | case DSC__K_DTYPE_ZEM: |
7568 | 2 | case DSC__K_DTYPE_DSC: |
7569 | 2 | case DSC__K_DTYPE_OU: |
7570 | 2 | case DSC__K_DTYPE_O: |
7571 | 2 | case DSC__K_DTYPE_G: |
7572 | 3 | case DSC__K_DTYPE_H: |
7573 | 3 | case DSC__K_DTYPE_GC: |
7574 | 3 | case DSC__K_DTYPE_HC: |
7575 | 3 | case DSC__K_DTYPE_CIT: |
7576 | 3 | case DSC__K_DTYPE_BPV: |
7577 | 3 | case DSC__K_DTYPE_BLV: |
7578 | 4 | case DSC__K_DTYPE_VU: |
7579 | 4 | case DSC__K_DTYPE_ADT: |
7580 | 4 | case DSC__K_DTYPE_VT: |
7581 | 4 | case DSC__K_DTYPE_T2: |
7582 | 4 | case DSC__K_DTYPE_VT2: |
7583 | 4 | fprintf (file, _("standard data: %s\n"), |
7584 | 4 | evax_bfd_get_dsc_name (type)); |
7585 | 4 | evax_bfd_print_valspec (buf, len, 4, file); |
7586 | 4 | if (len > 6) |
7587 | 3 | fprintf (file, _(" name: %.*s\n"), |
7588 | 3 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); |
7589 | 4 | break; |
7590 | 0 | case DST__K_MODBEG: |
7591 | 0 | { |
7592 | 0 | struct vms_dst_modbeg *dst = (void *)buf; |
7593 | 0 | unsigned char *name = buf + sizeof (*dst); |
7594 | |
|
7595 | 0 | fprintf (file, _("modbeg\n")); |
7596 | 0 | if (len < sizeof (*dst)) |
7597 | 0 | break; |
7598 | | /* xgettext:c-format */ |
7599 | 0 | fprintf (file, _(" flags: %d, language: %u, " |
7600 | 0 | "major: %u, minor: %u\n"), |
7601 | 0 | dst->flags, |
7602 | 0 | (unsigned)bfd_getl32 (dst->language), |
7603 | 0 | (unsigned)bfd_getl16 (dst->major), |
7604 | 0 | (unsigned)bfd_getl16 (dst->minor)); |
7605 | 0 | len -= sizeof (*dst); |
7606 | 0 | if (len > 0) |
7607 | 0 | { |
7608 | 0 | int nlen = len - 1; |
7609 | 0 | fprintf (file, _(" module name: %.*s\n"), |
7610 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7611 | 0 | if (name[0] < nlen) |
7612 | 0 | { |
7613 | 0 | len -= name[0] + 1; |
7614 | 0 | name += name[0] + 1; |
7615 | 0 | nlen = len - 1; |
7616 | 0 | fprintf (file, _(" compiler : %.*s\n"), |
7617 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7618 | 0 | } |
7619 | 0 | } |
7620 | 0 | } |
7621 | 0 | break; |
7622 | 0 | case DST__K_MODEND: |
7623 | 0 | fprintf (file, _("modend\n")); |
7624 | 0 | break; |
7625 | 0 | case DST__K_RTNBEG: |
7626 | 0 | { |
7627 | 0 | struct vms_dst_rtnbeg *dst = (void *)buf; |
7628 | 0 | unsigned char *name = buf + sizeof (*dst); |
7629 | |
|
7630 | 0 | fputs (_("rtnbeg\n"), file); |
7631 | 0 | if (len >= sizeof (*dst)) |
7632 | 0 | { |
7633 | | /* xgettext:c-format */ |
7634 | 0 | fprintf (file, _(" flags: %u, address: 0x%08x, " |
7635 | 0 | "pd-address: 0x%08x\n"), |
7636 | 0 | dst->flags, |
7637 | 0 | (unsigned) bfd_getl32 (dst->address), |
7638 | 0 | (unsigned) bfd_getl32 (dst->pd_address)); |
7639 | 0 | len -= sizeof (*dst); |
7640 | 0 | if (len > 0) |
7641 | 0 | { |
7642 | 0 | int nlen = len - 1; |
7643 | 0 | fprintf (file, _(" routine name: %.*s\n"), |
7644 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7645 | 0 | } |
7646 | 0 | } |
7647 | 0 | } |
7648 | 0 | break; |
7649 | 0 | case DST__K_RTNEND: |
7650 | 0 | { |
7651 | 0 | struct vms_dst_rtnend *dst = (void *)buf; |
7652 | |
|
7653 | 0 | if (len >= sizeof (*dst)) |
7654 | 0 | fprintf (file, _("rtnend: size 0x%08x\n"), |
7655 | 0 | (unsigned) bfd_getl32 (dst->size)); |
7656 | 0 | } |
7657 | 0 | break; |
7658 | 0 | case DST__K_PROLOG: |
7659 | 0 | { |
7660 | 0 | struct vms_dst_prolog *dst = (void *)buf; |
7661 | |
|
7662 | 0 | if (len >= sizeof (*dst)) |
7663 | | /* xgettext:c-format */ |
7664 | 0 | fprintf (file, _("prolog: bkpt address 0x%08x\n"), |
7665 | 0 | (unsigned) bfd_getl32 (dst->bkpt_addr)); |
7666 | 0 | } |
7667 | 0 | break; |
7668 | 0 | case DST__K_EPILOG: |
7669 | 0 | { |
7670 | 0 | struct vms_dst_epilog *dst = (void *)buf; |
7671 | |
|
7672 | 0 | if (len >= sizeof (*dst)) |
7673 | | /* xgettext:c-format */ |
7674 | 0 | fprintf (file, _("epilog: flags: %u, count: %u\n"), |
7675 | 0 | dst->flags, (unsigned) bfd_getl32 (dst->count)); |
7676 | 0 | } |
7677 | 0 | break; |
7678 | 0 | case DST__K_BLKBEG: |
7679 | 0 | { |
7680 | 0 | struct vms_dst_blkbeg *dst = (void *)buf; |
7681 | 0 | unsigned char *name = buf + sizeof (*dst); |
7682 | |
|
7683 | 0 | if (len > sizeof (*dst)) |
7684 | 0 | { |
7685 | 0 | int nlen; |
7686 | 0 | len -= sizeof (*dst); |
7687 | 0 | nlen = len - 1; |
7688 | | /* xgettext:c-format */ |
7689 | 0 | fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"), |
7690 | 0 | (unsigned) bfd_getl32 (dst->address), |
7691 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7692 | 0 | } |
7693 | 0 | } |
7694 | 0 | break; |
7695 | 0 | case DST__K_BLKEND: |
7696 | 0 | { |
7697 | 0 | struct vms_dst_blkend *dst = (void *)buf; |
7698 | |
|
7699 | 0 | if (len >= sizeof (*dst)) |
7700 | | /* xgettext:c-format */ |
7701 | 0 | fprintf (file, _("blkend: size: 0x%08x\n"), |
7702 | 0 | (unsigned) bfd_getl32 (dst->size)); |
7703 | 0 | } |
7704 | 0 | break; |
7705 | 0 | case DST__K_TYPSPEC: |
7706 | 0 | { |
7707 | 0 | fprintf (file, _("typspec (len: %u)\n"), len); |
7708 | 0 | if (len >= 1) |
7709 | 0 | { |
7710 | 0 | int nlen = len - 1; |
7711 | 0 | fprintf (file, _(" name: %.*s\n"), |
7712 | 0 | buf[0] > nlen ? nlen : buf[0], buf + 1); |
7713 | 0 | if (nlen > buf[0]) |
7714 | 0 | evax_bfd_print_typspec (buf + 1 + buf[0], len - (1 + buf[0]), |
7715 | 0 | 5, file); |
7716 | 0 | } |
7717 | 0 | } |
7718 | 0 | break; |
7719 | 0 | case DST__K_SEPTYP: |
7720 | 0 | { |
7721 | 0 | if (len >= 6) |
7722 | 0 | { |
7723 | 0 | fprintf (file, _("septyp, name: %.*s\n"), |
7724 | 0 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); |
7725 | 0 | evax_bfd_print_valspec (buf, len, 4, file); |
7726 | 0 | } |
7727 | 0 | } |
7728 | 0 | break; |
7729 | 0 | case DST__K_RECBEG: |
7730 | 0 | { |
7731 | 0 | struct vms_dst_recbeg *recbeg = (void *)buf; |
7732 | |
|
7733 | 0 | if (len > sizeof (*recbeg)) |
7734 | 0 | { |
7735 | 0 | unsigned char *name = buf + sizeof (*recbeg); |
7736 | 0 | int nlen = len - sizeof (*recbeg) - 1; |
7737 | |
|
7738 | 0 | if (name[0] < nlen) |
7739 | 0 | nlen = name[0]; |
7740 | 0 | fprintf (file, _("recbeg: name: %.*s\n"), nlen, name + 1); |
7741 | |
|
7742 | 0 | evax_bfd_print_valspec (buf, len, 4, file); |
7743 | |
|
7744 | 0 | len -= sizeof (*recbeg) + 1 + nlen; |
7745 | 0 | if (len >= 4) |
7746 | 0 | fprintf (file, _(" len: %u bits\n"), |
7747 | 0 | (unsigned) bfd_getl32 (name + 1 + nlen)); |
7748 | 0 | } |
7749 | 0 | } |
7750 | 0 | break; |
7751 | 0 | case DST__K_RECEND: |
7752 | 0 | fprintf (file, _("recend\n")); |
7753 | 0 | break; |
7754 | 0 | case DST__K_ENUMBEG: |
7755 | 0 | if (len >= 2) |
7756 | | /* xgettext:c-format */ |
7757 | 0 | fprintf (file, _("enumbeg, len: %u, name: %.*s\n"), |
7758 | 0 | buf[0], buf[1] > len - 2 ? len - 2 : buf[1], buf + 2); |
7759 | 0 | break; |
7760 | 0 | case DST__K_ENUMELT: |
7761 | 0 | if (len >= 6) |
7762 | 0 | { |
7763 | 0 | fprintf (file, _("enumelt, name: %.*s\n"), |
7764 | 0 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); |
7765 | 0 | evax_bfd_print_valspec (buf, len, 4, file); |
7766 | 0 | } |
7767 | 0 | break; |
7768 | 0 | case DST__K_ENUMEND: |
7769 | 0 | fprintf (file, _("enumend\n")); |
7770 | 0 | break; |
7771 | 0 | case DST__K_LABEL: |
7772 | 0 | { |
7773 | 0 | struct vms_dst_label *lab = (void *)buf; |
7774 | 0 | if (len >= sizeof (*lab)) |
7775 | 0 | { |
7776 | 0 | fprintf (file, _("label, name: %.*s\n"), |
7777 | 0 | lab->name[0] > len - 1 ? len - 1 : lab->name[0], |
7778 | 0 | lab->name + 1); |
7779 | 0 | fprintf (file, _(" address: 0x%08x\n"), |
7780 | 0 | (unsigned) bfd_getl32 (lab->value)); |
7781 | 0 | } |
7782 | 0 | } |
7783 | 0 | break; |
7784 | 0 | case DST__K_DIS_RANGE: |
7785 | 0 | if (len >= 4) |
7786 | 0 | { |
7787 | 0 | unsigned int cnt = bfd_getl32 (buf); |
7788 | 0 | unsigned char *rng = buf + 4; |
7789 | 0 | unsigned int i; |
7790 | |
|
7791 | 0 | fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt); |
7792 | 0 | len -= 4; |
7793 | 0 | for (i = 0; i < cnt; i++, rng += 8) |
7794 | 0 | { |
7795 | 0 | if (len < 8) |
7796 | 0 | break; |
7797 | | /* xgettext:c-format */ |
7798 | 0 | fprintf (file, _(" address: 0x%08x, size: %u\n"), |
7799 | 0 | (unsigned) bfd_getl32 (rng), |
7800 | 0 | (unsigned) bfd_getl32 (rng + 4)); |
7801 | 0 | len -= 8; |
7802 | 0 | } |
7803 | 0 | } |
7804 | 0 | break; |
7805 | 0 | case DST__K_LINE_NUM: |
7806 | 0 | { |
7807 | 0 | unsigned char *buf_orig = buf; |
7808 | |
|
7809 | 0 | fprintf (file, _("line num (len: %u)\n"), len); |
7810 | |
|
7811 | 0 | while (len > 0) |
7812 | 0 | { |
7813 | 0 | int cmd; |
7814 | 0 | unsigned int val; |
7815 | 0 | int cmdlen = -1; |
7816 | |
|
7817 | 0 | cmd = *buf++; |
7818 | 0 | len--; |
7819 | |
|
7820 | 0 | fputs (" ", file); |
7821 | |
|
7822 | 0 | switch (cmd) |
7823 | 0 | { |
7824 | 0 | case DST__K_DELTA_PC_W: |
7825 | 0 | if (len < 2) |
7826 | 0 | break; |
7827 | 0 | val = bfd_getl16 (buf); |
7828 | 0 | fprintf (file, _("delta_pc_w %u\n"), val); |
7829 | 0 | pc += val; |
7830 | 0 | line++; |
7831 | 0 | cmdlen = 2; |
7832 | 0 | break; |
7833 | 0 | case DST__K_INCR_LINUM: |
7834 | 0 | if (len < 1) |
7835 | 0 | break; |
7836 | 0 | val = *buf; |
7837 | 0 | fprintf (file, _("incr_linum(b): +%u\n"), val); |
7838 | 0 | line += val; |
7839 | 0 | cmdlen = 1; |
7840 | 0 | break; |
7841 | 0 | case DST__K_INCR_LINUM_W: |
7842 | 0 | if (len < 2) |
7843 | 0 | break; |
7844 | 0 | val = bfd_getl16 (buf); |
7845 | 0 | fprintf (file, _("incr_linum_w: +%u\n"), val); |
7846 | 0 | line += val; |
7847 | 0 | cmdlen = 2; |
7848 | 0 | break; |
7849 | 0 | case DST__K_INCR_LINUM_L: |
7850 | 0 | if (len < 4) |
7851 | 0 | break; |
7852 | 0 | val = bfd_getl32 (buf); |
7853 | 0 | fprintf (file, _("incr_linum_l: +%u\n"), val); |
7854 | 0 | line += val; |
7855 | 0 | cmdlen = 4; |
7856 | 0 | break; |
7857 | 0 | case DST__K_SET_LINUM: |
7858 | 0 | if (len < 2) |
7859 | 0 | break; |
7860 | 0 | line = bfd_getl16 (buf); |
7861 | 0 | fprintf (file, _("set_line_num(w) %u\n"), line); |
7862 | 0 | cmdlen = 2; |
7863 | 0 | break; |
7864 | 0 | case DST__K_SET_LINUM_B: |
7865 | 0 | if (len < 1) |
7866 | 0 | break; |
7867 | 0 | line = *buf; |
7868 | 0 | fprintf (file, _("set_line_num_b %u\n"), line); |
7869 | 0 | cmdlen = 1; |
7870 | 0 | break; |
7871 | 0 | case DST__K_SET_LINUM_L: |
7872 | 0 | if (len < 4) |
7873 | 0 | break; |
7874 | 0 | line = bfd_getl32 (buf); |
7875 | 0 | fprintf (file, _("set_line_num_l %u\n"), line); |
7876 | 0 | cmdlen = 4; |
7877 | 0 | break; |
7878 | 0 | case DST__K_SET_ABS_PC: |
7879 | 0 | if (len < 4) |
7880 | 0 | break; |
7881 | 0 | pc = bfd_getl32 (buf); |
7882 | 0 | fprintf (file, _("set_abs_pc: 0x%08x\n"), pc); |
7883 | 0 | cmdlen = 4; |
7884 | 0 | break; |
7885 | 0 | case DST__K_DELTA_PC_L: |
7886 | 0 | if (len < 4) |
7887 | 0 | break; |
7888 | 0 | fprintf (file, _("delta_pc_l: +0x%08x\n"), |
7889 | 0 | (unsigned) bfd_getl32 (buf)); |
7890 | 0 | cmdlen = 4; |
7891 | 0 | break; |
7892 | 0 | case DST__K_TERM: |
7893 | 0 | if (len < 1) |
7894 | 0 | break; |
7895 | 0 | fprintf (file, _("term(b): 0x%02x"), *buf); |
7896 | 0 | pc += *buf; |
7897 | 0 | fprintf (file, _(" pc: 0x%08x\n"), pc); |
7898 | 0 | cmdlen = 1; |
7899 | 0 | break; |
7900 | 0 | case DST__K_TERM_W: |
7901 | 0 | if (len < 2) |
7902 | 0 | break; |
7903 | 0 | val = bfd_getl16 (buf); |
7904 | 0 | fprintf (file, _("term_w: 0x%04x"), val); |
7905 | 0 | pc += val; |
7906 | 0 | fprintf (file, _(" pc: 0x%08x\n"), pc); |
7907 | 0 | cmdlen = 2; |
7908 | 0 | break; |
7909 | 0 | default: |
7910 | 0 | if (cmd <= 0) |
7911 | 0 | { |
7912 | 0 | fprintf (file, _("delta pc +%-4d"), -cmd); |
7913 | 0 | line++; /* FIXME: curr increment. */ |
7914 | 0 | pc += -cmd; |
7915 | | /* xgettext:c-format */ |
7916 | 0 | fprintf (file, _(" pc: 0x%08x line: %5u\n"), |
7917 | 0 | pc, line); |
7918 | 0 | cmdlen = 0; |
7919 | 0 | } |
7920 | 0 | else |
7921 | 0 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); |
7922 | 0 | break; |
7923 | 0 | } |
7924 | 0 | if (cmdlen < 0) |
7925 | 0 | break; |
7926 | 0 | len -= cmdlen; |
7927 | 0 | buf += cmdlen; |
7928 | 0 | } |
7929 | 0 | buf = buf_orig; |
7930 | 0 | } |
7931 | 0 | break; |
7932 | 0 | case DST__K_SOURCE: |
7933 | 0 | { |
7934 | 0 | unsigned char *buf_orig = buf; |
7935 | |
|
7936 | 0 | fprintf (file, _("source (len: %u)\n"), len); |
7937 | |
|
7938 | 0 | while (len > 0) |
7939 | 0 | { |
7940 | 0 | int cmd = *buf++; |
7941 | 0 | int cmdlen = -1; |
7942 | |
|
7943 | 0 | len--; |
7944 | 0 | switch (cmd) |
7945 | 0 | { |
7946 | 0 | case DST__K_SRC_DECLFILE: |
7947 | 0 | { |
7948 | 0 | struct vms_dst_src_decl_src *src = (void *) buf; |
7949 | 0 | unsigned char *name; |
7950 | 0 | int nlen; |
7951 | |
|
7952 | 0 | if (len < sizeof (*src)) |
7953 | 0 | break; |
7954 | | /* xgettext:c-format */ |
7955 | 0 | fprintf (file, _(" declfile: len: %u, flags: %u, " |
7956 | 0 | "fileid: %u\n"), |
7957 | 0 | src->length, src->flags, |
7958 | 0 | (unsigned)bfd_getl16 (src->fileid)); |
7959 | | /* xgettext:c-format */ |
7960 | 0 | fprintf (file, _(" rms: cdt: 0x%08x %08x, " |
7961 | 0 | "ebk: 0x%08x, ffb: 0x%04x, " |
7962 | 0 | "rfo: %u\n"), |
7963 | 0 | (unsigned)bfd_getl32 (src->rms_cdt + 4), |
7964 | 0 | (unsigned)bfd_getl32 (src->rms_cdt + 0), |
7965 | 0 | (unsigned)bfd_getl32 (src->rms_ebk), |
7966 | 0 | (unsigned)bfd_getl16 (src->rms_ffb), |
7967 | 0 | src->rms_rfo); |
7968 | 0 | if (src->length > len || src->length <= sizeof (*src)) |
7969 | 0 | break; |
7970 | 0 | nlen = src->length - sizeof (*src) - 1; |
7971 | 0 | name = buf + sizeof (*src); |
7972 | 0 | fprintf (file, _(" filename : %.*s\n"), |
7973 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7974 | 0 | if (name[0] >= nlen) |
7975 | 0 | break; |
7976 | 0 | nlen -= name[0] + 1; |
7977 | 0 | name += name[0] + 1; |
7978 | 0 | fprintf (file, _(" module name: %.*s\n"), |
7979 | 0 | name[0] > nlen ? nlen : name[0], name + 1); |
7980 | 0 | if (name[0] > nlen) |
7981 | 0 | break; |
7982 | 0 | cmdlen = src->length; |
7983 | 0 | } |
7984 | 0 | break; |
7985 | 0 | case DST__K_SRC_SETFILE: |
7986 | 0 | if (len < 2) |
7987 | 0 | break; |
7988 | 0 | fprintf (file, _(" setfile %u\n"), |
7989 | 0 | (unsigned) bfd_getl16 (buf)); |
7990 | 0 | cmdlen = 2; |
7991 | 0 | break; |
7992 | 0 | case DST__K_SRC_SETREC_W: |
7993 | 0 | if (len < 2) |
7994 | 0 | break; |
7995 | 0 | fprintf (file, _(" setrec %u\n"), |
7996 | 0 | (unsigned) bfd_getl16 (buf)); |
7997 | 0 | cmdlen = 2; |
7998 | 0 | break; |
7999 | 0 | case DST__K_SRC_SETREC_L: |
8000 | 0 | if (len < 4) |
8001 | 0 | break; |
8002 | 0 | fprintf (file, _(" setrec %u\n"), |
8003 | 0 | (unsigned) bfd_getl32 (buf)); |
8004 | 0 | cmdlen = 4; |
8005 | 0 | break; |
8006 | 0 | case DST__K_SRC_SETLNUM_W: |
8007 | 0 | if (len < 2) |
8008 | 0 | break; |
8009 | 0 | fprintf (file, _(" setlnum %u\n"), |
8010 | 0 | (unsigned) bfd_getl16 (buf)); |
8011 | 0 | cmdlen = 2; |
8012 | 0 | break; |
8013 | 0 | case DST__K_SRC_SETLNUM_L: |
8014 | 0 | if (len < 4) |
8015 | 0 | break; |
8016 | 0 | fprintf (file, _(" setlnum %u\n"), |
8017 | 0 | (unsigned) bfd_getl32 (buf)); |
8018 | 0 | cmdlen = 4; |
8019 | 0 | break; |
8020 | 0 | case DST__K_SRC_DEFLINES_W: |
8021 | 0 | if (len < 2) |
8022 | 0 | break; |
8023 | 0 | fprintf (file, _(" deflines %u\n"), |
8024 | 0 | (unsigned) bfd_getl16 (buf)); |
8025 | 0 | cmdlen = 2; |
8026 | 0 | break; |
8027 | 0 | case DST__K_SRC_DEFLINES_B: |
8028 | 0 | if (len < 1) |
8029 | 0 | break; |
8030 | 0 | fprintf (file, _(" deflines %u\n"), *buf); |
8031 | 0 | cmdlen = 1; |
8032 | 0 | break; |
8033 | 0 | case DST__K_SRC_FORMFEED: |
8034 | 0 | fprintf (file, _(" formfeed\n")); |
8035 | 0 | cmdlen = 0; |
8036 | 0 | break; |
8037 | 0 | default: |
8038 | 0 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); |
8039 | 0 | break; |
8040 | 0 | } |
8041 | 0 | if (cmdlen < 0) |
8042 | 0 | break; |
8043 | 0 | len -= cmdlen; |
8044 | 0 | buf += cmdlen; |
8045 | 0 | } |
8046 | 0 | buf = buf_orig; |
8047 | 0 | } |
8048 | 0 | break; |
8049 | 16 | default: |
8050 | 16 | fprintf (file, _("*unhandled* dst type %u\n"), type); |
8051 | 16 | break; |
8052 | 20 | } |
8053 | 20 | free (buf); |
8054 | 20 | } |
8055 | 9 | } |
8056 | | |
8057 | | static void |
8058 | | evax_bfd_print_image (bfd *abfd, FILE *file) |
8059 | 31 | { |
8060 | 31 | struct vms_eihd eihd; |
8061 | 31 | unsigned int rec_size, size; |
8062 | 31 | const char *name; |
8063 | 31 | unsigned int val; |
8064 | 31 | unsigned int eiha_off; |
8065 | 31 | unsigned int eihi_off; |
8066 | 31 | unsigned int eihs_off; |
8067 | 31 | unsigned int eisd_off; |
8068 | 31 | unsigned int eihef_off = 0; |
8069 | 31 | unsigned int eihnp_off = 0; |
8070 | 31 | unsigned int dmt_vbn = 0; |
8071 | 31 | unsigned int dmt_size = 0; |
8072 | 31 | unsigned int dst_vbn = 0; |
8073 | 31 | unsigned int dst_size = 0; |
8074 | 31 | unsigned int gst_vbn = 0; |
8075 | 31 | unsigned int gst_size = 0; |
8076 | 31 | unsigned int eiaf_vbn = 0; |
8077 | 31 | unsigned int eiaf_size = 0; |
8078 | 31 | unsigned int eihvn_off; |
8079 | | |
8080 | 31 | if (bfd_seek (abfd, 0, SEEK_SET) |
8081 | 31 | || (rec_size = bfd_read (&eihd, sizeof (eihd), abfd)) < EIHD__C_LENGTH) |
8082 | 0 | { |
8083 | 0 | fprintf (file, _("cannot read EIHD\n")); |
8084 | 0 | return; |
8085 | 0 | } |
8086 | 31 | size = bfd_getl32 (eihd.size); |
8087 | | /* xgettext:c-format */ |
8088 | 31 | fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"), |
8089 | 31 | size, (unsigned) bfd_getl32 (eihd.hdrblkcnt)); |
8090 | 31 | if (size > rec_size) |
8091 | 0 | size = rec_size; |
8092 | | /* xgettext:c-format */ |
8093 | 31 | fprintf (file, _(" majorid: %u, minorid: %u\n"), |
8094 | 31 | (unsigned)bfd_getl32 (eihd.majorid), |
8095 | 31 | (unsigned)bfd_getl32 (eihd.minorid)); |
8096 | | |
8097 | 31 | val = (unsigned)bfd_getl32 (eihd.imgtype); |
8098 | 31 | switch (val) |
8099 | 31 | { |
8100 | 0 | case EIHD__K_EXE: |
8101 | 0 | name = _("executable"); |
8102 | 0 | break; |
8103 | 0 | case EIHD__K_LIM: |
8104 | 0 | name = _("linkable image"); |
8105 | 0 | break; |
8106 | 31 | default: |
8107 | 31 | name = _("unknown"); |
8108 | 31 | break; |
8109 | 31 | } |
8110 | | /* xgettext:c-format */ |
8111 | 31 | fprintf (file, _(" image type: %u (%s)"), val, name); |
8112 | | |
8113 | 31 | val = (unsigned)bfd_getl32 (eihd.subtype); |
8114 | 31 | switch (val) |
8115 | 31 | { |
8116 | 0 | case EIHD__C_NATIVE: |
8117 | 0 | name = _("native"); |
8118 | 0 | break; |
8119 | 0 | case EIHD__C_CLI: |
8120 | 0 | name = _("CLI"); |
8121 | 0 | break; |
8122 | 31 | default: |
8123 | 31 | name = _("unknown"); |
8124 | 31 | break; |
8125 | 31 | } |
8126 | | /* xgettext:c-format */ |
8127 | 31 | fprintf (file, _(", subtype: %u (%s)\n"), val, name); |
8128 | | |
8129 | 31 | eisd_off = bfd_getl32 (eihd.isdoff); |
8130 | 31 | eiha_off = bfd_getl32 (eihd.activoff); |
8131 | 31 | eihi_off = bfd_getl32 (eihd.imgidoff); |
8132 | 31 | eihs_off = bfd_getl32 (eihd.symdbgoff); |
8133 | | /* xgettext:c-format */ |
8134 | 31 | fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, " |
8135 | 31 | "imgid: %u, patch: %u\n"), |
8136 | 31 | eisd_off, eiha_off, eihs_off, eihi_off, |
8137 | 31 | (unsigned)bfd_getl32 (eihd.patchoff)); |
8138 | 31 | fprintf (file, _(" fixup info rva: ")); |
8139 | 31 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva)); |
8140 | 31 | fprintf (file, _(", symbol vector rva: ")); |
8141 | 31 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva)); |
8142 | 31 | eihvn_off = bfd_getl32 (eihd.version_array_off); |
8143 | 31 | fprintf (file, _("\n" |
8144 | 31 | " version array off: %u\n"), |
8145 | 31 | eihvn_off); |
8146 | 31 | fprintf (file, |
8147 | | /* xgettext:c-format */ |
8148 | 31 | _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"), |
8149 | 31 | (unsigned)bfd_getl32 (eihd.imgiocnt), |
8150 | 31 | (unsigned)bfd_getl32 (eihd.iochancnt), |
8151 | 31 | (unsigned)bfd_getl32 (eihd.privreqs + 4), |
8152 | 31 | (unsigned)bfd_getl32 (eihd.privreqs + 0)); |
8153 | 31 | val = (unsigned)bfd_getl32 (eihd.lnkflags); |
8154 | 31 | fprintf (file, _(" linker flags: %08x:"), val); |
8155 | 31 | if (val & EIHD__M_LNKDEBUG) |
8156 | 2 | fprintf (file, " LNKDEBUG"); |
8157 | 31 | if (val & EIHD__M_LNKNOTFR) |
8158 | 8 | fprintf (file, " LNKNOTFR"); |
8159 | 31 | if (val & EIHD__M_NOP0BUFS) |
8160 | 2 | fprintf (file, " NOP0BUFS"); |
8161 | 31 | if (val & EIHD__M_PICIMG) |
8162 | 18 | fprintf (file, " PICIMG"); |
8163 | 31 | if (val & EIHD__M_P0IMAGE) |
8164 | 8 | fprintf (file, " P0IMAGE"); |
8165 | 31 | if (val & EIHD__M_DBGDMT) |
8166 | 8 | fprintf (file, " DBGDMT"); |
8167 | 31 | if (val & EIHD__M_INISHR) |
8168 | 2 | fprintf (file, " INISHR"); |
8169 | 31 | if (val & EIHD__M_XLATED) |
8170 | 8 | fprintf (file, " XLATED"); |
8171 | 31 | if (val & EIHD__M_BIND_CODE_SEC) |
8172 | 6 | fprintf (file, " BIND_CODE_SEC"); |
8173 | 31 | if (val & EIHD__M_BIND_DATA_SEC) |
8174 | 12 | fprintf (file, " BIND_DATA_SEC"); |
8175 | 31 | if (val & EIHD__M_MKTHREADS) |
8176 | 14 | fprintf (file, " MKTHREADS"); |
8177 | 31 | if (val & EIHD__M_UPCALLS) |
8178 | 2 | fprintf (file, " UPCALLS"); |
8179 | 31 | if (val & EIHD__M_OMV_READY) |
8180 | 6 | fprintf (file, " OMV_READY"); |
8181 | 31 | if (val & EIHD__M_EXT_BIND_SECT) |
8182 | 16 | fprintf (file, " EXT_BIND_SECT"); |
8183 | 31 | fprintf (file, "\n"); |
8184 | | /* xgettext:c-format */ |
8185 | 31 | fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, " |
8186 | 31 | "match ctrl: %u, symvect_size: %u\n"), |
8187 | 31 | (unsigned)bfd_getl32 (eihd.ident), |
8188 | 31 | (unsigned)bfd_getl32 (eihd.sysver), |
8189 | 31 | eihd.matchctl, |
8190 | 31 | (unsigned)bfd_getl32 (eihd.symvect_size)); |
8191 | 31 | fprintf (file, _(" BPAGE: %u"), |
8192 | 31 | (unsigned)bfd_getl32 (eihd.virt_mem_block_size)); |
8193 | 31 | if (size >= (offsetof (struct vms_eihd, noopt_psect_off) |
8194 | 31 | + sizeof (eihd.noopt_psect_off)) |
8195 | 9 | && (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT))) |
8196 | 6 | { |
8197 | 6 | eihef_off = bfd_getl32 (eihd.ext_fixup_off); |
8198 | 6 | eihnp_off = bfd_getl32 (eihd.noopt_psect_off); |
8199 | | /* xgettext:c-format */ |
8200 | 6 | fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"), |
8201 | 6 | eihef_off, eihnp_off); |
8202 | 6 | } |
8203 | 31 | if (size >= offsetof (struct vms_eihd, alias) + sizeof (eihd.alias)) |
8204 | 9 | fprintf (file, _(", alias: %u"), (unsigned) bfd_getl16 (eihd.alias)); |
8205 | 31 | fprintf (file, "\n"); |
8206 | | |
8207 | 31 | if (eihvn_off != 0) |
8208 | 25 | { |
8209 | 25 | struct vms_eihvn eihvn; |
8210 | 25 | unsigned int mask; |
8211 | 25 | unsigned int j; |
8212 | | |
8213 | 25 | fprintf (file, _("system version array information:\n")); |
8214 | 25 | if (bfd_seek (abfd, eihvn_off, SEEK_SET) |
8215 | 25 | || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn)) |
8216 | 0 | { |
8217 | 0 | fprintf (file, _("cannot read EIHVN header\n")); |
8218 | 0 | return; |
8219 | 0 | } |
8220 | 25 | mask = bfd_getl32 (eihvn.subsystem_mask); |
8221 | 825 | for (j = 0; j < 32; j++) |
8222 | 800 | if (mask & (1u << j)) |
8223 | 381 | { |
8224 | 381 | struct vms_eihvn_subversion ver; |
8225 | 381 | if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver)) |
8226 | 0 | { |
8227 | 0 | fprintf (file, _("cannot read EIHVN version\n")); |
8228 | 0 | return; |
8229 | 0 | } |
8230 | 381 | fprintf (file, _(" %02u "), j); |
8231 | 381 | switch (j) |
8232 | 381 | { |
8233 | 17 | case EIHVN__BASE_IMAGE_BIT: |
8234 | 17 | fputs (_("BASE_IMAGE "), file); |
8235 | 17 | break; |
8236 | 11 | case EIHVN__MEMORY_MANAGEMENT_BIT: |
8237 | 11 | fputs (_("MEMORY_MANAGEMENT"), file); |
8238 | 11 | break; |
8239 | 11 | case EIHVN__IO_BIT: |
8240 | 11 | fputs (_("IO "), file); |
8241 | 11 | break; |
8242 | 11 | case EIHVN__FILES_VOLUMES_BIT: |
8243 | 11 | fputs (_("FILES_VOLUMES "), file); |
8244 | 11 | break; |
8245 | 10 | case EIHVN__PROCESS_SCHED_BIT: |
8246 | 10 | fputs (_("PROCESS_SCHED "), file); |
8247 | 10 | break; |
8248 | 14 | case EIHVN__SYSGEN_BIT: |
8249 | 14 | fputs (_("SYSGEN "), file); |
8250 | 14 | break; |
8251 | 11 | case EIHVN__CLUSTERS_LOCKMGR_BIT: |
8252 | 11 | fputs (_("CLUSTERS_LOCKMGR "), file); |
8253 | 11 | break; |
8254 | 11 | case EIHVN__LOGICAL_NAMES_BIT: |
8255 | 11 | fputs (_("LOGICAL_NAMES "), file); |
8256 | 11 | break; |
8257 | 12 | case EIHVN__SECURITY_BIT: |
8258 | 12 | fputs (_("SECURITY "), file); |
8259 | 12 | break; |
8260 | 11 | case EIHVN__IMAGE_ACTIVATOR_BIT: |
8261 | 11 | fputs (_("IMAGE_ACTIVATOR "), file); |
8262 | 11 | break; |
8263 | 10 | case EIHVN__NETWORKS_BIT: |
8264 | 10 | fputs (_("NETWORKS "), file); |
8265 | 10 | break; |
8266 | 14 | case EIHVN__COUNTERS_BIT: |
8267 | 14 | fputs (_("COUNTERS "), file); |
8268 | 14 | break; |
8269 | 11 | case EIHVN__STABLE_BIT: |
8270 | 11 | fputs (_("STABLE "), file); |
8271 | 11 | break; |
8272 | 11 | case EIHVN__MISC_BIT: |
8273 | 11 | fputs (_("MISC "), file); |
8274 | 11 | break; |
8275 | 10 | case EIHVN__CPU_BIT: |
8276 | 10 | fputs (_("CPU "), file); |
8277 | 10 | break; |
8278 | 11 | case EIHVN__VOLATILE_BIT: |
8279 | 11 | fputs (_("VOLATILE "), file); |
8280 | 11 | break; |
8281 | 16 | case EIHVN__SHELL_BIT: |
8282 | 16 | fputs (_("SHELL "), file); |
8283 | 16 | break; |
8284 | 14 | case EIHVN__POSIX_BIT: |
8285 | 14 | fputs (_("POSIX "), file); |
8286 | 14 | break; |
8287 | 13 | case EIHVN__MULTI_PROCESSING_BIT: |
8288 | 13 | fputs (_("MULTI_PROCESSING "), file); |
8289 | 13 | break; |
8290 | 13 | case EIHVN__GALAXY_BIT: |
8291 | 13 | fputs (_("GALAXY "), file); |
8292 | 13 | break; |
8293 | 139 | default: |
8294 | 139 | fputs (_("*unknown* "), file); |
8295 | 139 | break; |
8296 | 381 | } |
8297 | 381 | fprintf (file, ": %u.%u\n", |
8298 | 381 | (unsigned)bfd_getl16 (ver.major), |
8299 | 381 | (unsigned)bfd_getl16 (ver.minor)); |
8300 | 381 | } |
8301 | 25 | } |
8302 | | |
8303 | 31 | if (eiha_off != 0) |
8304 | 20 | { |
8305 | 20 | struct vms_eiha eiha; |
8306 | | |
8307 | 20 | if (bfd_seek (abfd, eiha_off, SEEK_SET) |
8308 | 20 | || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha)) |
8309 | 0 | { |
8310 | 0 | fprintf (file, _("cannot read EIHA\n")); |
8311 | 0 | return; |
8312 | 0 | } |
8313 | 20 | fprintf (file, _("Image activation: (size=%u)\n"), |
8314 | 20 | (unsigned)bfd_getl32 (eiha.size)); |
8315 | | /* xgettext:c-format */ |
8316 | 20 | fprintf (file, _(" First address : 0x%08x 0x%08x\n"), |
8317 | 20 | (unsigned)bfd_getl32 (eiha.tfradr1_h), |
8318 | 20 | (unsigned)bfd_getl32 (eiha.tfradr1)); |
8319 | | /* xgettext:c-format */ |
8320 | 20 | fprintf (file, _(" Second address: 0x%08x 0x%08x\n"), |
8321 | 20 | (unsigned)bfd_getl32 (eiha.tfradr2_h), |
8322 | 20 | (unsigned)bfd_getl32 (eiha.tfradr2)); |
8323 | | /* xgettext:c-format */ |
8324 | 20 | fprintf (file, _(" Third address : 0x%08x 0x%08x\n"), |
8325 | 20 | (unsigned)bfd_getl32 (eiha.tfradr3_h), |
8326 | 20 | (unsigned)bfd_getl32 (eiha.tfradr3)); |
8327 | | /* xgettext:c-format */ |
8328 | 20 | fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"), |
8329 | 20 | (unsigned)bfd_getl32 (eiha.tfradr4_h), |
8330 | 20 | (unsigned)bfd_getl32 (eiha.tfradr4)); |
8331 | | /* xgettext:c-format */ |
8332 | 20 | fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"), |
8333 | 20 | (unsigned)bfd_getl32 (eiha.inishr_h), |
8334 | 20 | (unsigned)bfd_getl32 (eiha.inishr)); |
8335 | 20 | } |
8336 | 31 | if (eihi_off != 0) |
8337 | 22 | { |
8338 | 22 | struct vms_eihi eihi; |
8339 | | |
8340 | 22 | if (bfd_seek (abfd, eihi_off, SEEK_SET) |
8341 | 22 | || bfd_read (&eihi, sizeof (eihi), abfd) != sizeof (eihi)) |
8342 | 0 | { |
8343 | 0 | fprintf (file, _("cannot read EIHI\n")); |
8344 | 0 | return; |
8345 | 0 | } |
8346 | | /* xgettext:c-format */ |
8347 | 22 | fprintf (file, _("Image identification: (major: %u, minor: %u)\n"), |
8348 | 22 | (unsigned) bfd_getl32 (eihi.majorid), |
8349 | 22 | (unsigned) bfd_getl32 (eihi.minorid)); |
8350 | 22 | unsigned int nlen = eihi.imgnam[0]; |
8351 | 22 | if (nlen > sizeof (eihi.imgnam) - 1) |
8352 | 1 | nlen = sizeof (eihi.imgnam) - 1; |
8353 | 22 | fprintf (file, _(" image name : %.*s\n"), nlen, eihi.imgnam + 1); |
8354 | 22 | fprintf (file, _(" link time : %s\n"), |
8355 | 22 | vms_time_to_str (eihi.linktime)); |
8356 | 22 | nlen = eihi.imgid[0]; |
8357 | 22 | if (nlen > sizeof (eihi.imgid) - 1) |
8358 | 4 | nlen = sizeof (eihi.imgid) - 1; |
8359 | 22 | fprintf (file, _(" image ident : %.*s\n"), nlen, eihi.imgid + 1); |
8360 | 22 | nlen = eihi.linkid[0]; |
8361 | 22 | if (nlen > sizeof (eihi.linkid) - 1) |
8362 | 5 | nlen = sizeof (eihi.linkid) - 1; |
8363 | 22 | fprintf (file, _(" linker ident : %.*s\n"), nlen, eihi.linkid + 1); |
8364 | 22 | nlen = eihi.imgbid[0]; |
8365 | 22 | if (nlen > sizeof (eihi.imgbid) -1 ) |
8366 | 3 | nlen = sizeof (eihi.imgbid) - 1; |
8367 | 22 | fprintf (file, _(" image build ident: %.*s\n"), nlen, eihi.imgbid + 1); |
8368 | 22 | } |
8369 | 31 | if (eihs_off != 0) |
8370 | 11 | { |
8371 | 11 | struct vms_eihs eihs; |
8372 | | |
8373 | 11 | if (bfd_seek (abfd, eihs_off, SEEK_SET) |
8374 | 11 | || bfd_read (&eihs, sizeof (eihs), abfd) != sizeof (eihs)) |
8375 | 0 | { |
8376 | 0 | fprintf (file, _("cannot read EIHS\n")); |
8377 | 0 | return; |
8378 | 0 | } |
8379 | | /* xgettext:c-format */ |
8380 | 11 | fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"), |
8381 | 11 | (unsigned)bfd_getl32 (eihs.majorid), |
8382 | 11 | (unsigned)bfd_getl32 (eihs.minorid)); |
8383 | 11 | dst_vbn = bfd_getl32 (eihs.dstvbn); |
8384 | 11 | dst_size = bfd_getl32 (eihs.dstsize); |
8385 | | /* xgettext:c-format */ |
8386 | 11 | fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"), |
8387 | 11 | dst_vbn, dst_size, dst_size); |
8388 | 11 | gst_vbn = bfd_getl32 (eihs.gstvbn); |
8389 | 11 | gst_size = bfd_getl32 (eihs.gstsize); |
8390 | | /* xgettext:c-format */ |
8391 | 11 | fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"), |
8392 | 11 | gst_vbn, gst_size); |
8393 | 11 | dmt_vbn = bfd_getl32 (eihs.dmtvbn); |
8394 | 11 | dmt_size = bfd_getl32 (eihs.dmtsize); |
8395 | | /* xgettext:c-format */ |
8396 | 11 | fprintf (file, _(" debug module table : vbn: %u, size: %u\n"), |
8397 | 11 | dmt_vbn, dmt_size); |
8398 | 11 | } |
8399 | 62 | while (eisd_off != 0) |
8400 | 62 | { |
8401 | 62 | struct vms_eisd eisd; |
8402 | 62 | unsigned int len; |
8403 | | |
8404 | 62 | while (1) |
8405 | 62 | { |
8406 | 62 | if (bfd_seek (abfd, eisd_off, SEEK_SET) |
8407 | 62 | || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd)) |
8408 | 0 | { |
8409 | 0 | fprintf (file, _("cannot read EISD\n")); |
8410 | 0 | return; |
8411 | 0 | } |
8412 | 62 | len = (unsigned)bfd_getl32 (eisd.eisdsize); |
8413 | 62 | if (len != (unsigned)-1) |
8414 | 62 | break; |
8415 | | |
8416 | | /* Next block. */ |
8417 | 0 | eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); |
8418 | 0 | } |
8419 | | /* xgettext:c-format */ |
8420 | 62 | fprintf (file, _("Image section descriptor: (major: %u, minor: %u, " |
8421 | 62 | "size: %u, offset: %u)\n"), |
8422 | 62 | (unsigned)bfd_getl32 (eisd.majorid), |
8423 | 62 | (unsigned)bfd_getl32 (eisd.minorid), |
8424 | 62 | len, eisd_off); |
8425 | 62 | if (len == 0) |
8426 | 31 | break; |
8427 | | /* xgettext:c-format */ |
8428 | 31 | fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"), |
8429 | 31 | (unsigned)bfd_getl32 (eisd.virt_addr + 4), |
8430 | 31 | (unsigned)bfd_getl32 (eisd.virt_addr + 0), |
8431 | 31 | (unsigned)bfd_getl32 (eisd.secsize)); |
8432 | 31 | val = (unsigned)bfd_getl32 (eisd.flags); |
8433 | 31 | fprintf (file, _(" flags: 0x%04x"), val); |
8434 | 31 | if (val & EISD__M_GBL) |
8435 | 16 | fprintf (file, " GBL"); |
8436 | 31 | if (val & EISD__M_CRF) |
8437 | 16 | fprintf (file, " CRF"); |
8438 | 31 | if (val & EISD__M_DZRO) |
8439 | 16 | fprintf (file, " DZRO"); |
8440 | 31 | if (val & EISD__M_WRT) |
8441 | 16 | fprintf (file, " WRT"); |
8442 | 31 | if (val & EISD__M_INITALCODE) |
8443 | 16 | fprintf (file, " INITALCODE"); |
8444 | 31 | if (val & EISD__M_BASED) |
8445 | 16 | fprintf (file, " BASED"); |
8446 | 31 | if (val & EISD__M_FIXUPVEC) |
8447 | 25 | fprintf (file, " FIXUPVEC"); |
8448 | 31 | if (val & EISD__M_RESIDENT) |
8449 | 16 | fprintf (file, " RESIDENT"); |
8450 | 31 | if (val & EISD__M_VECTOR) |
8451 | 26 | fprintf (file, " VECTOR"); |
8452 | 31 | if (val & EISD__M_PROTECT) |
8453 | 20 | fprintf (file, " PROTECT"); |
8454 | 31 | if (val & EISD__M_LASTCLU) |
8455 | 20 | fprintf (file, " LASTCLU"); |
8456 | 31 | if (val & EISD__M_EXE) |
8457 | 20 | fprintf (file, " EXE"); |
8458 | 31 | if (val & EISD__M_NONSHRADR) |
8459 | 20 | fprintf (file, " NONSHRADR"); |
8460 | 31 | if (val & EISD__M_QUAD_LENGTH) |
8461 | 20 | fprintf (file, " QUAD_LENGTH"); |
8462 | 31 | if (val & EISD__M_ALLOC_64BIT) |
8463 | 20 | fprintf (file, " ALLOC_64BIT"); |
8464 | 31 | fprintf (file, "\n"); |
8465 | 31 | if (val & EISD__M_FIXUPVEC) |
8466 | 25 | { |
8467 | 25 | eiaf_vbn = bfd_getl32 (eisd.vbn); |
8468 | 25 | eiaf_size = bfd_getl32 (eisd.secsize); |
8469 | 25 | } |
8470 | | /* xgettext:c-format */ |
8471 | 31 | fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("), |
8472 | 31 | (unsigned)bfd_getl32 (eisd.vbn), |
8473 | 31 | eisd.pfc, eisd.matchctl, eisd.type); |
8474 | 31 | switch (eisd.type) |
8475 | 31 | { |
8476 | 15 | case EISD__K_NORMAL: |
8477 | 15 | fputs (_("NORMAL"), file); |
8478 | 15 | break; |
8479 | 0 | case EISD__K_SHRFXD: |
8480 | 0 | fputs (_("SHRFXD"), file); |
8481 | 0 | break; |
8482 | 0 | case EISD__K_PRVFXD: |
8483 | 0 | fputs (_("PRVFXD"), file); |
8484 | 0 | break; |
8485 | 0 | case EISD__K_SHRPIC: |
8486 | 0 | fputs (_("SHRPIC"), file); |
8487 | 0 | break; |
8488 | 0 | case EISD__K_PRVPIC: |
8489 | 0 | fputs (_("PRVPIC"), file); |
8490 | 0 | break; |
8491 | 0 | case EISD__K_USRSTACK: |
8492 | 0 | fputs (_("USRSTACK"), file); |
8493 | 0 | break; |
8494 | 16 | default: |
8495 | 16 | fputs (_("*unknown*"), file); |
8496 | 16 | break; |
8497 | 31 | } |
8498 | 31 | fputs (_(")\n"), file); |
8499 | 31 | if (val & EISD__M_GBL) |
8500 | 16 | { |
8501 | 16 | unsigned int nlen = eisd.gblnam[0]; |
8502 | 16 | if (nlen > sizeof (eisd.gblnam) - 1) |
8503 | 0 | nlen = sizeof (eisd.gblnam) - 1; |
8504 | | /* xgettext:c-format */ |
8505 | 16 | fprintf (file, _(" ident: 0x%08x, name: %.*s\n"), |
8506 | 16 | (unsigned) bfd_getl32 (eisd.ident), |
8507 | 16 | nlen, eisd.gblnam + 1); |
8508 | 16 | } |
8509 | 31 | eisd_off += len; |
8510 | 31 | } |
8511 | | |
8512 | 31 | if (dmt_vbn != 0) |
8513 | 3 | { |
8514 | 3 | if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) |
8515 | 0 | { |
8516 | 0 | fprintf (file, _("cannot read DMT\n")); |
8517 | 0 | return; |
8518 | 0 | } |
8519 | | |
8520 | 3 | fprintf (file, _("Debug module table:\n")); |
8521 | | |
8522 | 28 | while (dmt_size > 0) |
8523 | 27 | { |
8524 | 27 | struct vms_dmt_header dmth; |
8525 | 27 | unsigned int count; |
8526 | | |
8527 | 27 | if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth)) |
8528 | 0 | { |
8529 | 0 | fprintf (file, _("cannot read DMT header\n")); |
8530 | 0 | return; |
8531 | 0 | } |
8532 | 27 | count = bfd_getl16 (dmth.psect_count); |
8533 | 27 | fprintf (file, |
8534 | | /* xgettext:c-format */ |
8535 | 27 | _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"), |
8536 | 27 | (unsigned)bfd_getl32 (dmth.modbeg), |
8537 | 27 | (unsigned)bfd_getl32 (dmth.size), count); |
8538 | 27 | dmt_size -= sizeof (dmth); |
8539 | 762 | while (count > 0) |
8540 | 737 | { |
8541 | 737 | struct vms_dmt_psect dmtp; |
8542 | | |
8543 | 737 | if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp)) |
8544 | 2 | { |
8545 | 2 | fprintf (file, _("cannot read DMT psect\n")); |
8546 | 2 | return; |
8547 | 2 | } |
8548 | | /* xgettext:c-format */ |
8549 | 735 | fprintf (file, _(" psect start: 0x%08x, length: %u\n"), |
8550 | 735 | (unsigned)bfd_getl32 (dmtp.start), |
8551 | 735 | (unsigned)bfd_getl32 (dmtp.length)); |
8552 | 735 | count--; |
8553 | 735 | dmt_size -= sizeof (dmtp); |
8554 | 735 | } |
8555 | 27 | } |
8556 | 3 | } |
8557 | | |
8558 | 29 | if (dst_vbn != 0) |
8559 | 9 | { |
8560 | 9 | if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) |
8561 | 0 | { |
8562 | 0 | fprintf (file, _("cannot read DST\n")); |
8563 | 0 | return; |
8564 | 0 | } |
8565 | | |
8566 | 9 | evax_bfd_print_dst (abfd, dst_size, file); |
8567 | 9 | } |
8568 | 29 | if (gst_vbn != 0) |
8569 | 0 | { |
8570 | 0 | if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) |
8571 | 0 | { |
8572 | 0 | fprintf (file, _("cannot read GST\n")); |
8573 | 0 | return; |
8574 | 0 | } |
8575 | | |
8576 | 0 | fprintf (file, _("Global symbol table:\n")); |
8577 | 0 | evax_bfd_print_eobj (abfd, file); |
8578 | 0 | } |
8579 | 29 | if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf)) |
8580 | 25 | { |
8581 | 25 | unsigned char *buf; |
8582 | 25 | struct vms_eiaf *eiaf; |
8583 | 25 | unsigned int qrelfixoff; |
8584 | 25 | unsigned int lrelfixoff; |
8585 | 25 | unsigned int qdotadroff; |
8586 | 25 | unsigned int ldotadroff; |
8587 | 25 | unsigned int shrimgcnt; |
8588 | 25 | unsigned int shlstoff; |
8589 | 25 | unsigned int codeadroff; |
8590 | 25 | unsigned int lpfixoff; |
8591 | 25 | unsigned int chgprtoff; |
8592 | 25 | file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE; |
8593 | | |
8594 | 25 | if (bfd_seek (abfd, f_off, SEEK_SET) != 0 |
8595 | 25 | || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL) |
8596 | 0 | { |
8597 | 0 | fprintf (file, _("cannot read EIHA\n")); |
8598 | 0 | return; |
8599 | 0 | } |
8600 | 25 | eiaf = (struct vms_eiaf *)buf; |
8601 | 25 | fprintf (file, |
8602 | | /* xgettext:c-format */ |
8603 | 25 | _("Image activator fixup: (major: %u, minor: %u)\n"), |
8604 | 25 | (unsigned)bfd_getl32 (eiaf->majorid), |
8605 | 25 | (unsigned)bfd_getl32 (eiaf->minorid)); |
8606 | | /* xgettext:c-format */ |
8607 | 25 | fprintf (file, _(" iaflink : 0x%08x %08x\n"), |
8608 | 25 | (unsigned)bfd_getl32 (eiaf->iaflink + 0), |
8609 | 25 | (unsigned)bfd_getl32 (eiaf->iaflink + 4)); |
8610 | | /* xgettext:c-format */ |
8611 | 25 | fprintf (file, _(" fixuplnk: 0x%08x %08x\n"), |
8612 | 25 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 0), |
8613 | 25 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 4)); |
8614 | 25 | fprintf (file, _(" size : %u\n"), |
8615 | 25 | (unsigned)bfd_getl32 (eiaf->size)); |
8616 | 25 | fprintf (file, _(" flags: 0x%08x\n"), |
8617 | 25 | (unsigned)bfd_getl32 (eiaf->flags)); |
8618 | 25 | qrelfixoff = bfd_getl32 (eiaf->qrelfixoff); |
8619 | 25 | lrelfixoff = bfd_getl32 (eiaf->lrelfixoff); |
8620 | | /* xgettext:c-format */ |
8621 | 25 | fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"), |
8622 | 25 | qrelfixoff, lrelfixoff); |
8623 | 25 | qdotadroff = bfd_getl32 (eiaf->qdotadroff); |
8624 | 25 | ldotadroff = bfd_getl32 (eiaf->ldotadroff); |
8625 | | /* xgettext:c-format */ |
8626 | 25 | fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"), |
8627 | 25 | qdotadroff, ldotadroff); |
8628 | 25 | codeadroff = bfd_getl32 (eiaf->codeadroff); |
8629 | 25 | lpfixoff = bfd_getl32 (eiaf->lpfixoff); |
8630 | | /* xgettext:c-format */ |
8631 | 25 | fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"), |
8632 | 25 | codeadroff, lpfixoff); |
8633 | 25 | chgprtoff = bfd_getl32 (eiaf->chgprtoff); |
8634 | 25 | fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff); |
8635 | 25 | shrimgcnt = bfd_getl32 (eiaf->shrimgcnt); |
8636 | 25 | shlstoff = bfd_getl32 (eiaf->shlstoff); |
8637 | | /* xgettext:c-format */ |
8638 | 25 | fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"), |
8639 | 25 | shlstoff, shrimgcnt); |
8640 | | /* xgettext:c-format */ |
8641 | 25 | fprintf (file, _(" shlextra : %5u, permctx : %5u\n"), |
8642 | 25 | (unsigned)bfd_getl32 (eiaf->shlextra), |
8643 | 25 | (unsigned)bfd_getl32 (eiaf->permctx)); |
8644 | 25 | fprintf (file, _(" base_va : 0x%08x\n"), |
8645 | 25 | (unsigned)bfd_getl32 (eiaf->base_va)); |
8646 | 25 | fprintf (file, _(" lppsbfixoff: %5u\n"), |
8647 | 25 | (unsigned)bfd_getl32 (eiaf->lppsbfixoff)); |
8648 | | |
8649 | 25 | if (shlstoff) |
8650 | 24 | { |
8651 | 24 | unsigned int j; |
8652 | | |
8653 | 24 | fprintf (file, _(" Shareable images:\n")); |
8654 | 24 | for (j = 0; |
8655 | 206 | j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl); |
8656 | 182 | j++, shlstoff += sizeof (struct vms_shl)) |
8657 | 182 | { |
8658 | 182 | struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff); |
8659 | 182 | unsigned int nlen = shl->imgnam[0]; |
8660 | 182 | if (nlen > sizeof (shl->imgnam) - 1) |
8661 | 72 | nlen = sizeof (shl->imgnam) - 1; |
8662 | 182 | fprintf (file, |
8663 | | /* xgettext:c-format */ |
8664 | 182 | _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"), |
8665 | 182 | j, shl->size, shl->flags, |
8666 | 182 | nlen, shl->imgnam + 1); |
8667 | 182 | } |
8668 | 24 | } |
8669 | 25 | if (qrelfixoff != 0) |
8670 | 24 | { |
8671 | 24 | fprintf (file, _(" quad-word relocation fixups:\n")); |
8672 | 24 | evax_bfd_print_relocation_records (file, buf, eiaf_size, |
8673 | 24 | qrelfixoff, 8); |
8674 | 24 | } |
8675 | 25 | if (lrelfixoff != 0) |
8676 | 23 | { |
8677 | 23 | fprintf (file, _(" long-word relocation fixups:\n")); |
8678 | 23 | evax_bfd_print_relocation_records (file, buf, eiaf_size, |
8679 | 23 | lrelfixoff, 4); |
8680 | 23 | } |
8681 | 25 | if (qdotadroff != 0) |
8682 | 23 | { |
8683 | 23 | fprintf (file, _(" quad-word .address reference fixups:\n")); |
8684 | 23 | evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff); |
8685 | 23 | } |
8686 | 25 | if (ldotadroff != 0) |
8687 | 24 | { |
8688 | 24 | fprintf (file, _(" long-word .address reference fixups:\n")); |
8689 | 24 | evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff); |
8690 | 24 | } |
8691 | 25 | if (codeadroff != 0) |
8692 | 25 | { |
8693 | 25 | fprintf (file, _(" Code Address Reference Fixups:\n")); |
8694 | 25 | evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff); |
8695 | 25 | } |
8696 | 25 | if (lpfixoff != 0) |
8697 | 23 | { |
8698 | 23 | fprintf (file, _(" Linkage Pairs Reference Fixups:\n")); |
8699 | 23 | evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff); |
8700 | 23 | } |
8701 | 25 | if (chgprtoff && chgprtoff <= eiaf_size - 4) |
8702 | 17 | { |
8703 | 17 | unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff); |
8704 | 17 | unsigned int j; |
8705 | | |
8706 | 17 | fprintf (file, _(" Change Protection (%u entries):\n"), count); |
8707 | 17 | for (j = 0, chgprtoff += 4; |
8708 | 2.87k | j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp); |
8709 | 2.85k | j++, chgprtoff += sizeof (struct vms_eicp)) |
8710 | 2.85k | { |
8711 | 2.85k | struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff); |
8712 | 2.85k | unsigned int prot = bfd_getl32 (eicp->newprt); |
8713 | 2.85k | fprintf (file, |
8714 | | /* xgettext:c-format */ |
8715 | 2.85k | _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "), |
8716 | 2.85k | (unsigned) bfd_getl32 (eicp->baseva + 4), |
8717 | 2.85k | (unsigned) bfd_getl32 (eicp->baseva + 0), |
8718 | 2.85k | (unsigned) bfd_getl32 (eicp->size), |
8719 | 2.85k | (unsigned) bfd_getl32 (eicp->newprt)); |
8720 | 2.85k | switch (prot) |
8721 | 2.85k | { |
8722 | 706 | case PRT__C_NA: |
8723 | 706 | fprintf (file, "NA"); |
8724 | 706 | break; |
8725 | 75 | case PRT__C_RESERVED: |
8726 | 75 | fprintf (file, "RES"); |
8727 | 75 | break; |
8728 | 51 | case PRT__C_KW: |
8729 | 51 | fprintf (file, "KW"); |
8730 | 51 | break; |
8731 | 65 | case PRT__C_KR: |
8732 | 65 | fprintf (file, "KR"); |
8733 | 65 | break; |
8734 | 60 | case PRT__C_UW: |
8735 | 60 | fprintf (file, "UW"); |
8736 | 60 | break; |
8737 | 42 | case PRT__C_EW: |
8738 | 42 | fprintf (file, "EW"); |
8739 | 42 | break; |
8740 | 13 | case PRT__C_ERKW: |
8741 | 13 | fprintf (file, "ERKW"); |
8742 | 13 | break; |
8743 | 2 | case PRT__C_ER: |
8744 | 2 | fprintf (file, "ER"); |
8745 | 2 | break; |
8746 | 18 | case PRT__C_SW: |
8747 | 18 | fprintf (file, "SW"); |
8748 | 18 | break; |
8749 | 24 | case PRT__C_SREW: |
8750 | 24 | fprintf (file, "SREW"); |
8751 | 24 | break; |
8752 | 56 | case PRT__C_SRKW: |
8753 | 56 | fprintf (file, "SRKW"); |
8754 | 56 | break; |
8755 | 12 | case PRT__C_SR: |
8756 | 12 | fprintf (file, "SR"); |
8757 | 12 | break; |
8758 | 35 | case PRT__C_URSW: |
8759 | 35 | fprintf (file, "URSW"); |
8760 | 35 | break; |
8761 | 9 | case PRT__C_UREW: |
8762 | 9 | fprintf (file, "UREW"); |
8763 | 9 | break; |
8764 | 11 | case PRT__C_URKW: |
8765 | 11 | fprintf (file, "URKW"); |
8766 | 11 | break; |
8767 | 13 | case PRT__C_UR: |
8768 | 13 | fprintf (file, "UR"); |
8769 | 13 | break; |
8770 | 1.66k | default: |
8771 | 1.66k | fputs ("??", file); |
8772 | 1.66k | break; |
8773 | 2.85k | } |
8774 | 2.85k | fputc ('\n', file); |
8775 | 2.85k | } |
8776 | 17 | } |
8777 | 25 | free (buf); |
8778 | 25 | } |
8779 | 29 | } |
8780 | | |
8781 | | static bool |
8782 | | vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr) |
8783 | 31 | { |
8784 | 31 | FILE *file = (FILE *)ptr; |
8785 | | |
8786 | 31 | if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) |
8787 | 31 | evax_bfd_print_image (abfd, file); |
8788 | 0 | else |
8789 | 0 | { |
8790 | 0 | if (bfd_seek (abfd, 0, SEEK_SET)) |
8791 | 0 | return false; |
8792 | 0 | evax_bfd_print_eobj (abfd, file); |
8793 | 0 | } |
8794 | 31 | return true; |
8795 | 31 | } |
8796 | | |
8797 | | /* Linking. */ |
8798 | | |
8799 | | /* Slurp ETIR/EDBG/ETBT VMS object records. */ |
8800 | | |
8801 | | static bool |
8802 | | alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info) |
8803 | 31 | { |
8804 | 31 | asection *cur_section; |
8805 | 31 | file_ptr cur_offset; |
8806 | 31 | asection *dst_section; |
8807 | 31 | file_ptr dst_offset; |
8808 | | |
8809 | 31 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) |
8810 | 0 | return false; |
8811 | | |
8812 | 31 | cur_section = NULL; |
8813 | 31 | cur_offset = 0; |
8814 | | |
8815 | 31 | dst_section = PRIV (dst_section); |
8816 | 31 | dst_offset = 0; |
8817 | 31 | if (info) |
8818 | 0 | { |
8819 | 0 | if (info->strip == strip_all || info->strip == strip_debugger) |
8820 | 0 | { |
8821 | | /* Discard the DST section. */ |
8822 | 0 | dst_offset = 0; |
8823 | 0 | dst_section = NULL; |
8824 | 0 | } |
8825 | 0 | else if (dst_section) |
8826 | 0 | { |
8827 | 0 | dst_offset = dst_section->output_offset; |
8828 | 0 | dst_section = dst_section->output_section; |
8829 | 0 | } |
8830 | 0 | } |
8831 | | |
8832 | 31 | while (1) |
8833 | 31 | { |
8834 | 31 | int type; |
8835 | 31 | bool res; |
8836 | | |
8837 | 31 | type = _bfd_vms_get_object_record (abfd); |
8838 | 31 | if (type < 0) |
8839 | 31 | { |
8840 | 31 | vms_debug2 ((2, "next_record failed\n")); |
8841 | 31 | return false; |
8842 | 31 | } |
8843 | 0 | switch (type) |
8844 | 0 | { |
8845 | 0 | case EOBJ__C_ETIR: |
8846 | 0 | PRIV (image_section) = cur_section; |
8847 | 0 | PRIV (image_offset) = cur_offset; |
8848 | 0 | res = _bfd_vms_slurp_etir (abfd, info); |
8849 | 0 | cur_section = PRIV (image_section); |
8850 | 0 | cur_offset = PRIV (image_offset); |
8851 | 0 | break; |
8852 | 0 | case EOBJ__C_EDBG: |
8853 | 0 | case EOBJ__C_ETBT: |
8854 | 0 | if (dst_section == NULL) |
8855 | 0 | continue; |
8856 | 0 | PRIV (image_section) = dst_section; |
8857 | 0 | PRIV (image_offset) = dst_offset; |
8858 | 0 | res = _bfd_vms_slurp_etir (abfd, info); |
8859 | 0 | dst_offset = PRIV (image_offset); |
8860 | 0 | break; |
8861 | 0 | case EOBJ__C_EEOM: |
8862 | 0 | return true; |
8863 | 0 | default: |
8864 | 0 | continue; |
8865 | 0 | } |
8866 | 0 | if (!res) |
8867 | 0 | { |
8868 | 0 | vms_debug2 ((2, "slurp eobj type %d failed\n", type)); |
8869 | 0 | return false; |
8870 | 0 | } |
8871 | 0 | } |
8872 | 31 | } |
8873 | | |
8874 | | static int |
8875 | | alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED, |
8876 | | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8877 | 0 | { |
8878 | 0 | return 0; |
8879 | 0 | } |
8880 | | |
8881 | | /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */ |
8882 | | |
8883 | | static bool |
8884 | | alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8885 | 0 | { |
8886 | 0 | struct alpha_vms_shlib_el *sl; |
8887 | 0 | asection *sect = PRIV2 (src, image_section); |
8888 | 0 | file_ptr offset = PRIV2 (src, image_offset); |
8889 | 0 | bfd_vma *p; |
8890 | |
|
8891 | 0 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, |
8892 | 0 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
8893 | 0 | sl->has_fixups = true; |
8894 | 0 | p = VEC_APPEND (sl->lp, bfd_vma); |
8895 | 0 | if (p == NULL) |
8896 | 0 | return false; |
8897 | 0 | *p = sect->output_section->vma + sect->output_offset + offset; |
8898 | 0 | sect->output_section->flags |= SEC_RELOC; |
8899 | 0 | return true; |
8900 | 0 | } |
8901 | | |
8902 | | /* Add a code address fixup at address SECT + OFFSET to SHLIB. */ |
8903 | | |
8904 | | static bool |
8905 | | alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8906 | 0 | { |
8907 | 0 | struct alpha_vms_shlib_el *sl; |
8908 | 0 | asection *sect = PRIV2 (src, image_section); |
8909 | 0 | file_ptr offset = PRIV2 (src, image_offset); |
8910 | 0 | bfd_vma *p; |
8911 | |
|
8912 | 0 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, |
8913 | 0 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
8914 | 0 | sl->has_fixups = true; |
8915 | 0 | p = VEC_APPEND (sl->ca, bfd_vma); |
8916 | 0 | if (p == NULL) |
8917 | 0 | return false; |
8918 | 0 | *p = sect->output_section->vma + sect->output_offset + offset; |
8919 | 0 | sect->output_section->flags |= SEC_RELOC; |
8920 | 0 | return true; |
8921 | 0 | } |
8922 | | |
8923 | | /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */ |
8924 | | |
8925 | | static bool |
8926 | | alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src, |
8927 | | bfd *shlib, bfd_vma vec) |
8928 | 0 | { |
8929 | 0 | struct alpha_vms_shlib_el *sl; |
8930 | 0 | struct alpha_vms_vma_ref *r; |
8931 | 0 | asection *sect = PRIV2 (src, image_section); |
8932 | 0 | file_ptr offset = PRIV2 (src, image_offset); |
8933 | |
|
8934 | 0 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, |
8935 | 0 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
8936 | 0 | sl->has_fixups = true; |
8937 | 0 | r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref); |
8938 | 0 | if (r == NULL) |
8939 | 0 | return false; |
8940 | 0 | r->vma = sect->output_section->vma + sect->output_offset + offset; |
8941 | 0 | r->ref = vec; |
8942 | 0 | sect->output_section->flags |= SEC_RELOC; |
8943 | 0 | return true; |
8944 | 0 | } |
8945 | | |
8946 | | static bool |
8947 | | alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED, |
8948 | | unsigned int shr ATTRIBUTE_UNUSED, |
8949 | | bfd_vma vec ATTRIBUTE_UNUSED) |
8950 | 0 | { |
8951 | | /* Not yet supported. */ |
8952 | 0 | return false; |
8953 | 0 | } |
8954 | | |
8955 | | /* Add relocation. FIXME: Not yet emitted. */ |
8956 | | |
8957 | | static bool |
8958 | | alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8959 | 0 | { |
8960 | 0 | return true; |
8961 | 0 | } |
8962 | | |
8963 | | static bool |
8964 | | alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8965 | 0 | { |
8966 | 0 | return true; |
8967 | 0 | } |
8968 | | |
8969 | | static struct bfd_hash_entry * |
8970 | | alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry, |
8971 | | struct bfd_hash_table *table, |
8972 | | const char *string) |
8973 | 0 | { |
8974 | 0 | struct alpha_vms_link_hash_entry *ret = |
8975 | 0 | (struct alpha_vms_link_hash_entry *) entry; |
8976 | | |
8977 | | /* Allocate the structure if it has not already been allocated by a |
8978 | | subclass. */ |
8979 | 0 | if (ret == NULL) |
8980 | 0 | ret = ((struct alpha_vms_link_hash_entry *) |
8981 | 0 | bfd_hash_allocate (table, |
8982 | 0 | sizeof (struct alpha_vms_link_hash_entry))); |
8983 | 0 | if (ret == NULL) |
8984 | 0 | return NULL; |
8985 | | |
8986 | | /* Call the allocation method of the superclass. */ |
8987 | 0 | ret = ((struct alpha_vms_link_hash_entry *) |
8988 | 0 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
8989 | 0 | table, string)); |
8990 | |
|
8991 | 0 | ret->sym = NULL; |
8992 | |
|
8993 | 0 | return (struct bfd_hash_entry *) ret; |
8994 | 0 | } |
8995 | | |
8996 | | static void |
8997 | | alpha_vms_bfd_link_hash_table_free (bfd *abfd) |
8998 | 0 | { |
8999 | 0 | struct alpha_vms_link_hash_table *t; |
9000 | 0 | unsigned i; |
9001 | |
|
9002 | 0 | t = (struct alpha_vms_link_hash_table *) abfd->link.hash; |
9003 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9004 | 0 | { |
9005 | 0 | struct alpha_vms_shlib_el *shlib; |
9006 | |
|
9007 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9008 | 0 | free (&VEC_EL (shlib->ca, bfd_vma, 0)); |
9009 | 0 | free (&VEC_EL (shlib->lp, bfd_vma, 0)); |
9010 | 0 | free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0)); |
9011 | 0 | } |
9012 | 0 | free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0)); |
9013 | |
|
9014 | 0 | _bfd_generic_link_hash_table_free (abfd); |
9015 | 0 | } |
9016 | | |
9017 | | /* Create an Alpha/VMS link hash table. */ |
9018 | | |
9019 | | static struct bfd_link_hash_table * |
9020 | | alpha_vms_bfd_link_hash_table_create (bfd *abfd) |
9021 | 0 | { |
9022 | 0 | struct alpha_vms_link_hash_table *ret; |
9023 | 0 | size_t amt = sizeof (struct alpha_vms_link_hash_table); |
9024 | |
|
9025 | 0 | ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt); |
9026 | 0 | if (ret == NULL) |
9027 | 0 | return NULL; |
9028 | 0 | if (!_bfd_link_hash_table_init (&ret->root, abfd, |
9029 | 0 | alpha_vms_link_hash_newfunc, |
9030 | 0 | sizeof (struct alpha_vms_link_hash_entry))) |
9031 | 0 | { |
9032 | 0 | free (ret); |
9033 | 0 | return NULL; |
9034 | 0 | } |
9035 | | |
9036 | 0 | VEC_INIT (ret->shrlibs); |
9037 | 0 | ret->fixup = NULL; |
9038 | 0 | ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free; |
9039 | |
|
9040 | 0 | return &ret->root; |
9041 | 0 | } |
9042 | | |
9043 | | static bool |
9044 | | alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) |
9045 | 0 | { |
9046 | 0 | unsigned int i; |
9047 | |
|
9048 | 0 | for (i = 0; i < PRIV (gsd_sym_count); i++) |
9049 | 0 | { |
9050 | 0 | struct vms_symbol_entry *e = PRIV (syms)[i]; |
9051 | 0 | struct alpha_vms_link_hash_entry *h; |
9052 | 0 | struct bfd_link_hash_entry *h_root; |
9053 | 0 | asymbol sym; |
9054 | |
|
9055 | 0 | if (!alpha_vms_convert_symbol (abfd, e, &sym)) |
9056 | 0 | return false; |
9057 | | |
9058 | 0 | if ((e->flags & EGSY__V_DEF) && abfd->selective_search) |
9059 | 0 | { |
9060 | | /* In selective_search mode, only add definition that are |
9061 | | required. */ |
9062 | 0 | h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup |
9063 | 0 | (info->hash, sym.name, false, false, false); |
9064 | 0 | if (h == NULL || h->root.type != bfd_link_hash_undefined) |
9065 | 0 | continue; |
9066 | 0 | } |
9067 | 0 | else |
9068 | 0 | h = NULL; |
9069 | | |
9070 | 0 | h_root = (struct bfd_link_hash_entry *) h; |
9071 | 0 | if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags, |
9072 | 0 | sym.section, sym.value, NULL, |
9073 | 0 | false, false, &h_root)) |
9074 | 0 | return false; |
9075 | 0 | h = (struct alpha_vms_link_hash_entry *) h_root; |
9076 | |
|
9077 | 0 | if ((e->flags & EGSY__V_DEF) |
9078 | 0 | && h->sym == NULL |
9079 | 0 | && abfd->xvec == info->output_bfd->xvec) |
9080 | 0 | h->sym = e; |
9081 | 0 | } |
9082 | | |
9083 | 0 | if (abfd->flags & DYNAMIC) |
9084 | 0 | { |
9085 | 0 | struct alpha_vms_shlib_el *shlib; |
9086 | | |
9087 | | /* We do not want to include any of the sections in a dynamic |
9088 | | object in the output file. See comment in elflink.c. */ |
9089 | 0 | bfd_section_list_clear (abfd); |
9090 | |
|
9091 | 0 | shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs, |
9092 | 0 | struct alpha_vms_shlib_el); |
9093 | 0 | if (shlib == NULL) |
9094 | 0 | return false; |
9095 | 0 | shlib->abfd = abfd; |
9096 | 0 | VEC_INIT (shlib->ca); |
9097 | 0 | VEC_INIT (shlib->lp); |
9098 | 0 | VEC_INIT (shlib->qr); |
9099 | 0 | PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1; |
9100 | 0 | } |
9101 | | |
9102 | 0 | return true; |
9103 | 0 | } |
9104 | | |
9105 | | static bool |
9106 | | alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) |
9107 | 0 | { |
9108 | 0 | int pass; |
9109 | 0 | struct bfd_link_hash_entry **pundef; |
9110 | 0 | struct bfd_link_hash_entry **next_pundef; |
9111 | | |
9112 | | /* We only accept VMS libraries. */ |
9113 | 0 | if (info->output_bfd->xvec != abfd->xvec) |
9114 | 0 | { |
9115 | 0 | bfd_set_error (bfd_error_wrong_format); |
9116 | 0 | return false; |
9117 | 0 | } |
9118 | | |
9119 | | /* This can only ever happen for fake archives. */ |
9120 | 0 | if (!bfd_has_map (abfd)) |
9121 | 0 | { |
9122 | 0 | bfd *first_one = bfd_openr_next_archived_file (abfd, NULL); |
9123 | | |
9124 | | /* An empty archive is a special case. */ |
9125 | 0 | if (first_one == NULL) |
9126 | 0 | return true; |
9127 | | |
9128 | 0 | if (!_bfd_make_armap (abfd, first_one)) |
9129 | 0 | return false; |
9130 | 0 | } |
9131 | | |
9132 | | /* The archive_pass field in the archive itself is used to |
9133 | | initialize PASS, since we may search the same archive multiple |
9134 | | times. */ |
9135 | 0 | pass = ++abfd->archive_pass; |
9136 | | |
9137 | | /* Look through the list of undefined symbols. */ |
9138 | 0 | for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef) |
9139 | 0 | { |
9140 | 0 | struct bfd_link_hash_entry *h; |
9141 | 0 | symindex symidx; |
9142 | 0 | bfd *element; |
9143 | 0 | bfd *orig_element; |
9144 | |
|
9145 | 0 | h = *pundef; |
9146 | 0 | next_pundef = &(*pundef)->u.undef.next; |
9147 | | |
9148 | | /* When a symbol is defined, it is not necessarily removed from |
9149 | | the list. */ |
9150 | 0 | if (h->type != bfd_link_hash_undefined |
9151 | 0 | && h->type != bfd_link_hash_common) |
9152 | 0 | { |
9153 | | /* Remove this entry from the list, for general cleanliness |
9154 | | and because we are going to look through the list again |
9155 | | if we search any more libraries. We can't remove the |
9156 | | entry if it is the tail, because that would lose any |
9157 | | entries we add to the list later on. */ |
9158 | 0 | if (*pundef != info->hash->undefs_tail) |
9159 | 0 | { |
9160 | 0 | *pundef = *next_pundef; |
9161 | 0 | next_pundef = pundef; |
9162 | 0 | } |
9163 | 0 | continue; |
9164 | 0 | } |
9165 | | |
9166 | | /* Look for this symbol in the archive hash table. */ |
9167 | 0 | symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string); |
9168 | 0 | if (symidx == BFD_NO_MORE_SYMBOLS) |
9169 | 0 | { |
9170 | | /* Nothing in this slot. */ |
9171 | 0 | continue; |
9172 | 0 | } |
9173 | | |
9174 | 0 | element = bfd_get_elt_at_index (abfd, symidx); |
9175 | 0 | if (element == NULL) |
9176 | 0 | return false; |
9177 | | |
9178 | 0 | if (element->archive_pass == -1 || element->archive_pass == pass) |
9179 | 0 | { |
9180 | | /* Next symbol if this archive is wrong or already handled. */ |
9181 | 0 | continue; |
9182 | 0 | } |
9183 | | |
9184 | 0 | if (! bfd_check_format (element, bfd_object)) |
9185 | 0 | { |
9186 | 0 | element->archive_pass = -1; |
9187 | 0 | return false; |
9188 | 0 | } |
9189 | | |
9190 | 0 | orig_element = element; |
9191 | 0 | if (bfd_is_thin_archive (abfd) && !bfd_is_fake_archive (abfd)) |
9192 | 0 | { |
9193 | 0 | element = _bfd_vms_lib_get_imagelib_file (element); |
9194 | 0 | if (element == NULL || !bfd_check_format (element, bfd_object)) |
9195 | 0 | { |
9196 | 0 | orig_element->archive_pass = -1; |
9197 | 0 | return false; |
9198 | 0 | } |
9199 | 0 | } |
9200 | | |
9201 | | /* Unlike the generic linker, we know that this element provides |
9202 | | a definition for an undefined symbol and we know that we want |
9203 | | to include it. We don't need to check anything. */ |
9204 | 0 | if (!(*info->callbacks |
9205 | 0 | ->add_archive_element) (info, element, h->root.string, &element)) |
9206 | 0 | continue; |
9207 | 0 | if (!alpha_vms_link_add_object_symbols (element, info)) |
9208 | 0 | return false; |
9209 | | |
9210 | 0 | orig_element->archive_pass = pass; |
9211 | 0 | } |
9212 | | |
9213 | 0 | return true; |
9214 | 0 | } |
9215 | | |
9216 | | static bool |
9217 | | alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
9218 | 0 | { |
9219 | 0 | switch (bfd_get_format (abfd)) |
9220 | 0 | { |
9221 | 0 | case bfd_object: |
9222 | 0 | vms_debug2 ((2, "vms_link_add_symbols for object %s\n", |
9223 | 0 | abfd->filename)); |
9224 | 0 | return alpha_vms_link_add_object_symbols (abfd, info); |
9225 | 0 | break; |
9226 | 0 | case bfd_archive: |
9227 | 0 | vms_debug2 ((2, "vms_link_add_symbols for archive %s\n", |
9228 | 0 | abfd->filename)); |
9229 | 0 | return alpha_vms_link_add_archive_symbols (abfd, info); |
9230 | 0 | break; |
9231 | 0 | default: |
9232 | 0 | bfd_set_error (bfd_error_wrong_format); |
9233 | 0 | return false; |
9234 | 0 | } |
9235 | 0 | } |
9236 | | |
9237 | | static bool |
9238 | | alpha_vms_build_fixups (struct bfd_link_info *info) |
9239 | 0 | { |
9240 | 0 | struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info); |
9241 | 0 | unsigned char *content; |
9242 | 0 | unsigned int i; |
9243 | 0 | unsigned int sz = 0; |
9244 | 0 | unsigned int lp_sz = 0; |
9245 | 0 | unsigned int ca_sz = 0; |
9246 | 0 | unsigned int qr_sz = 0; |
9247 | 0 | unsigned int shrimg_cnt = 0; |
9248 | 0 | unsigned int chgprt_num = 0; |
9249 | 0 | unsigned int chgprt_sz = 0; |
9250 | 0 | struct vms_eiaf *eiaf; |
9251 | 0 | unsigned int off; |
9252 | 0 | asection *sec; |
9253 | | |
9254 | | /* Shared libraries. */ |
9255 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9256 | 0 | { |
9257 | 0 | struct alpha_vms_shlib_el *shlib; |
9258 | |
|
9259 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9260 | |
|
9261 | 0 | if (!shlib->has_fixups) |
9262 | 0 | continue; |
9263 | | |
9264 | 0 | shrimg_cnt++; |
9265 | |
|
9266 | 0 | if (VEC_COUNT (shlib->ca) > 0) |
9267 | 0 | { |
9268 | | /* Header + entries. */ |
9269 | 0 | ca_sz += 8; |
9270 | 0 | ca_sz += VEC_COUNT (shlib->ca) * 4; |
9271 | 0 | } |
9272 | 0 | if (VEC_COUNT (shlib->lp) > 0) |
9273 | 0 | { |
9274 | | /* Header + entries. */ |
9275 | 0 | lp_sz += 8; |
9276 | 0 | lp_sz += VEC_COUNT (shlib->lp) * 4; |
9277 | 0 | } |
9278 | 0 | if (VEC_COUNT (shlib->qr) > 0) |
9279 | 0 | { |
9280 | | /* Header + entries. */ |
9281 | 0 | qr_sz += 8; |
9282 | 0 | qr_sz += VEC_COUNT (shlib->qr) * 8; |
9283 | 0 | } |
9284 | 0 | } |
9285 | | /* Add markers. */ |
9286 | 0 | if (ca_sz > 0) |
9287 | 0 | ca_sz += 8; |
9288 | 0 | if (lp_sz > 0) |
9289 | 0 | lp_sz += 8; |
9290 | 0 | if (qr_sz > 0) |
9291 | 0 | qr_sz += 8; |
9292 | | |
9293 | | /* Finish now if there is no content. */ |
9294 | 0 | if (ca_sz + lp_sz + qr_sz == 0) |
9295 | 0 | return true; |
9296 | | |
9297 | | /* Add an eicp entry for the fixup itself. */ |
9298 | 0 | chgprt_num = 1; |
9299 | 0 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) |
9300 | 0 | { |
9301 | | /* This isect could be made RO or EXE after relocations are applied. */ |
9302 | 0 | if ((sec->flags & SEC_RELOC) != 0 |
9303 | 0 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
9304 | 0 | chgprt_num++; |
9305 | 0 | } |
9306 | 0 | chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp); |
9307 | | |
9308 | | /* Allocate section content (round-up size) */ |
9309 | 0 | sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl) |
9310 | 0 | + ca_sz + lp_sz + qr_sz + chgprt_sz; |
9311 | 0 | sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); |
9312 | 0 | content = bfd_zalloc (info->output_bfd, sz); |
9313 | 0 | if (content == NULL) |
9314 | 0 | return false; |
9315 | | |
9316 | 0 | sec = alpha_vms_link_hash (info)->fixup; |
9317 | 0 | sec->contents = content; |
9318 | 0 | sec->alloced = 1; |
9319 | 0 | sec->size = sz; |
9320 | |
|
9321 | 0 | eiaf = (struct vms_eiaf *)content; |
9322 | 0 | off = sizeof (struct vms_eiaf); |
9323 | 0 | bfd_putl32 (0, eiaf->majorid); |
9324 | 0 | bfd_putl32 (0, eiaf->minorid); |
9325 | 0 | bfd_putl32 (0, eiaf->iaflink); |
9326 | 0 | bfd_putl32 (0, eiaf->fixuplnk); |
9327 | 0 | bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size); |
9328 | 0 | bfd_putl32 (0, eiaf->flags); |
9329 | 0 | bfd_putl32 (0, eiaf->qrelfixoff); |
9330 | 0 | bfd_putl32 (0, eiaf->lrelfixoff); |
9331 | 0 | bfd_putl32 (0, eiaf->qdotadroff); |
9332 | 0 | bfd_putl32 (0, eiaf->ldotadroff); |
9333 | 0 | bfd_putl32 (0, eiaf->codeadroff); |
9334 | 0 | bfd_putl32 (0, eiaf->lpfixoff); |
9335 | 0 | bfd_putl32 (0, eiaf->chgprtoff); |
9336 | 0 | bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff); |
9337 | 0 | bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt); |
9338 | 0 | bfd_putl32 (0, eiaf->shlextra); |
9339 | 0 | bfd_putl32 (0, eiaf->permctx); |
9340 | 0 | bfd_putl32 (0, eiaf->base_va); |
9341 | 0 | bfd_putl32 (0, eiaf->lppsbfixoff); |
9342 | |
|
9343 | 0 | if (shrimg_cnt) |
9344 | 0 | { |
9345 | 0 | shrimg_cnt = 0; |
9346 | | |
9347 | | /* Write shl. */ |
9348 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9349 | 0 | { |
9350 | 0 | struct alpha_vms_shlib_el *shlib; |
9351 | 0 | struct vms_shl *shl; |
9352 | |
|
9353 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9354 | |
|
9355 | 0 | if (!shlib->has_fixups) |
9356 | 0 | continue; |
9357 | | |
9358 | | /* Renumber shared images. */ |
9359 | 0 | PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++; |
9360 | |
|
9361 | 0 | shl = (struct vms_shl *)(content + off); |
9362 | 0 | bfd_putl32 (0, shl->baseva); |
9363 | 0 | bfd_putl32 (0, shl->shlptr); |
9364 | 0 | bfd_putl32 (0, shl->ident); |
9365 | 0 | bfd_putl32 (0, shl->permctx); |
9366 | 0 | shl->size = sizeof (struct vms_shl); |
9367 | 0 | bfd_putl16 (0, shl->fill_1); |
9368 | 0 | shl->flags = 0; |
9369 | 0 | bfd_putl32 (0, shl->icb); |
9370 | 0 | shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name)); |
9371 | 0 | memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name), |
9372 | 0 | shl->imgnam[0]); |
9373 | |
|
9374 | 0 | off += sizeof (struct vms_shl); |
9375 | 0 | } |
9376 | | |
9377 | | /* CA fixups. */ |
9378 | 0 | if (ca_sz != 0) |
9379 | 0 | { |
9380 | 0 | bfd_putl32 (off, eiaf->codeadroff); |
9381 | |
|
9382 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9383 | 0 | { |
9384 | 0 | struct alpha_vms_shlib_el *shlib; |
9385 | 0 | unsigned int j; |
9386 | |
|
9387 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9388 | |
|
9389 | 0 | if (VEC_COUNT (shlib->ca) == 0) |
9390 | 0 | continue; |
9391 | | |
9392 | 0 | bfd_putl32 (VEC_COUNT (shlib->ca), content + off); |
9393 | 0 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); |
9394 | 0 | off += 8; |
9395 | |
|
9396 | 0 | for (j = 0; j < VEC_COUNT (shlib->ca); j++) |
9397 | 0 | { |
9398 | 0 | bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr, |
9399 | 0 | content + off); |
9400 | 0 | off += 4; |
9401 | 0 | } |
9402 | 0 | } |
9403 | |
|
9404 | 0 | bfd_putl32 (0, content + off); |
9405 | 0 | bfd_putl32 (0, content + off + 4); |
9406 | 0 | off += 8; |
9407 | 0 | } |
9408 | | |
9409 | | /* LP fixups. */ |
9410 | 0 | if (lp_sz != 0) |
9411 | 0 | { |
9412 | 0 | bfd_putl32 (off, eiaf->lpfixoff); |
9413 | |
|
9414 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9415 | 0 | { |
9416 | 0 | struct alpha_vms_shlib_el *shlib; |
9417 | 0 | unsigned int j; |
9418 | |
|
9419 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9420 | |
|
9421 | 0 | if (VEC_COUNT (shlib->lp) == 0) |
9422 | 0 | continue; |
9423 | | |
9424 | 0 | bfd_putl32 (VEC_COUNT (shlib->lp), content + off); |
9425 | 0 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); |
9426 | 0 | off += 8; |
9427 | |
|
9428 | 0 | for (j = 0; j < VEC_COUNT (shlib->lp); j++) |
9429 | 0 | { |
9430 | 0 | bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr, |
9431 | 0 | content + off); |
9432 | 0 | off += 4; |
9433 | 0 | } |
9434 | 0 | } |
9435 | |
|
9436 | 0 | bfd_putl32 (0, content + off); |
9437 | 0 | bfd_putl32 (0, content + off + 4); |
9438 | 0 | off += 8; |
9439 | 0 | } |
9440 | | |
9441 | | /* QR fixups. */ |
9442 | 0 | if (qr_sz != 0) |
9443 | 0 | { |
9444 | 0 | bfd_putl32 (off, eiaf->qdotadroff); |
9445 | |
|
9446 | 0 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9447 | 0 | { |
9448 | 0 | struct alpha_vms_shlib_el *shlib; |
9449 | 0 | unsigned int j; |
9450 | |
|
9451 | 0 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
9452 | |
|
9453 | 0 | if (VEC_COUNT (shlib->qr) == 0) |
9454 | 0 | continue; |
9455 | | |
9456 | 0 | bfd_putl32 (VEC_COUNT (shlib->qr), content + off); |
9457 | 0 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); |
9458 | 0 | off += 8; |
9459 | |
|
9460 | 0 | for (j = 0; j < VEC_COUNT (shlib->qr); j++) |
9461 | 0 | { |
9462 | 0 | struct alpha_vms_vma_ref *r; |
9463 | 0 | r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j); |
9464 | 0 | bfd_putl32 (r->vma - t->base_addr, content + off); |
9465 | 0 | bfd_putl32 (r->ref, content + off + 4); |
9466 | 0 | off += 8; |
9467 | 0 | } |
9468 | 0 | } |
9469 | |
|
9470 | 0 | bfd_putl32 (0, content + off); |
9471 | 0 | bfd_putl32 (0, content + off + 4); |
9472 | 0 | off += 8; |
9473 | 0 | } |
9474 | 0 | } |
9475 | | |
9476 | | /* Write the change protection table. */ |
9477 | 0 | bfd_putl32 (off, eiaf->chgprtoff); |
9478 | 0 | bfd_putl32 (chgprt_num, content + off); |
9479 | 0 | off += 4; |
9480 | |
|
9481 | 0 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) |
9482 | 0 | { |
9483 | 0 | struct vms_eicp *eicp; |
9484 | 0 | unsigned int prot; |
9485 | |
|
9486 | 0 | if ((sec->flags & SEC_LINKER_CREATED) != 0 && |
9487 | 0 | strcmp (sec->name, "$FIXUP$") == 0) |
9488 | 0 | prot = PRT__C_UREW; |
9489 | 0 | else if ((sec->flags & SEC_RELOC) != 0 |
9490 | 0 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
9491 | 0 | prot = PRT__C_UR; |
9492 | 0 | else |
9493 | 0 | continue; |
9494 | | |
9495 | 0 | eicp = (struct vms_eicp *)(content + off); |
9496 | 0 | bfd_putl64 (sec->vma - t->base_addr, eicp->baseva); |
9497 | 0 | bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1), |
9498 | 0 | eicp->size); |
9499 | 0 | bfd_putl32 (prot, eicp->newprt); |
9500 | 0 | off += sizeof (struct vms_eicp); |
9501 | 0 | } |
9502 | |
|
9503 | 0 | return true; |
9504 | 0 | } |
9505 | | |
9506 | | /* Called by bfd_hash_traverse to fill the symbol table. |
9507 | | Return FALSE in case of failure. */ |
9508 | | |
9509 | | static bool |
9510 | | alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov) |
9511 | 0 | { |
9512 | 0 | struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh; |
9513 | 0 | struct bfd_link_info *info = (struct bfd_link_info *)infov; |
9514 | 0 | struct alpha_vms_link_hash_entry *h; |
9515 | 0 | struct vms_symbol_entry *sym; |
9516 | |
|
9517 | 0 | if (hc->type == bfd_link_hash_warning) |
9518 | 0 | { |
9519 | 0 | hc = hc->u.i.link; |
9520 | 0 | if (hc->type == bfd_link_hash_new) |
9521 | 0 | return true; |
9522 | 0 | } |
9523 | 0 | h = (struct alpha_vms_link_hash_entry *) hc; |
9524 | |
|
9525 | 0 | switch (h->root.type) |
9526 | 0 | { |
9527 | 0 | case bfd_link_hash_undefined: |
9528 | 0 | return true; |
9529 | 0 | case bfd_link_hash_new: |
9530 | 0 | case bfd_link_hash_warning: |
9531 | 0 | abort (); |
9532 | 0 | case bfd_link_hash_undefweak: |
9533 | 0 | return true; |
9534 | 0 | case bfd_link_hash_defined: |
9535 | 0 | case bfd_link_hash_defweak: |
9536 | 0 | { |
9537 | 0 | asection *sec = h->root.u.def.section; |
9538 | | |
9539 | | /* FIXME: this is certainly a symbol from a dynamic library. */ |
9540 | 0 | if (bfd_is_abs_section (sec)) |
9541 | 0 | return true; |
9542 | | |
9543 | 0 | if (sec->owner->flags & DYNAMIC) |
9544 | 0 | return true; |
9545 | 0 | } |
9546 | 0 | break; |
9547 | 0 | case bfd_link_hash_common: |
9548 | 0 | break; |
9549 | 0 | case bfd_link_hash_indirect: |
9550 | 0 | return true; |
9551 | 0 | } |
9552 | | |
9553 | | /* Do not write not kept symbols. */ |
9554 | 0 | if (info->strip == strip_some |
9555 | 0 | && bfd_hash_lookup (info->keep_hash, h->root.root.string, |
9556 | 0 | false, false) != NULL) |
9557 | 0 | return true; |
9558 | | |
9559 | 0 | if (h->sym == NULL) |
9560 | 0 | { |
9561 | | /* This symbol doesn't come from a VMS object. So we suppose it is |
9562 | | a data. */ |
9563 | 0 | int len = strlen (h->root.root.string); |
9564 | |
|
9565 | 0 | sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd, |
9566 | 0 | sizeof (*sym) + len); |
9567 | 0 | if (sym == NULL) |
9568 | 0 | abort (); |
9569 | 0 | sym->namelen = len; |
9570 | 0 | memcpy (sym->name, h->root.root.string, len); |
9571 | 0 | sym->name[len] = 0; |
9572 | 0 | sym->owner = info->output_bfd; |
9573 | |
|
9574 | 0 | sym->typ = EGSD__C_SYMG; |
9575 | 0 | sym->data_type = 0; |
9576 | 0 | sym->flags = EGSY__V_DEF | EGSY__V_REL; |
9577 | 0 | sym->symbol_vector = h->root.u.def.value; |
9578 | 0 | sym->section = h->root.u.def.section; |
9579 | 0 | sym->value = h->root.u.def.value; |
9580 | 0 | } |
9581 | 0 | else |
9582 | 0 | sym = h->sym; |
9583 | | |
9584 | 0 | if (!add_symbol_entry (info->output_bfd, sym)) |
9585 | 0 | return false; |
9586 | | |
9587 | 0 | return true; |
9588 | 0 | } |
9589 | | |
9590 | | static bool |
9591 | | alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info) |
9592 | 0 | { |
9593 | 0 | asection *o; |
9594 | 0 | struct bfd_link_order *p; |
9595 | 0 | bfd *sub; |
9596 | 0 | asection *fixupsec; |
9597 | 0 | bfd_vma base_addr; |
9598 | 0 | bfd_vma last_addr; |
9599 | 0 | asection *dst; |
9600 | 0 | asection *dmt; |
9601 | |
|
9602 | 0 | if (bfd_link_relocatable (info)) |
9603 | 0 | { |
9604 | | /* FIXME: we do not yet support relocatable link. It is not obvious |
9605 | | how to do it for debug infos. */ |
9606 | 0 | (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n")); |
9607 | 0 | return false; |
9608 | 0 | } |
9609 | | |
9610 | 0 | abfd->outsymbols = NULL; |
9611 | 0 | abfd->symcount = 0; |
9612 | | |
9613 | | /* Mark all sections which will be included in the output file. */ |
9614 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
9615 | 0 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
9616 | 0 | if (p->type == bfd_indirect_link_order) |
9617 | 0 | p->u.indirect.section->linker_mark = true; |
9618 | |
|
9619 | | #if 0 |
9620 | | /* Handle all the link order information for the sections. */ |
9621 | | for (o = abfd->sections; o != NULL; o = o->next) |
9622 | | { |
9623 | | printf ("For section %s (at 0x%08x, flags=0x%08x):\n", |
9624 | | o->name, (unsigned)o->vma, (unsigned)o->flags); |
9625 | | |
9626 | | for (p = o->map_head.link_order; p != NULL; p = p->next) |
9627 | | { |
9628 | | printf (" at 0x%08x - 0x%08x: ", |
9629 | | (unsigned)p->offset, (unsigned)(p->offset + p->size - 1)); |
9630 | | switch (p->type) |
9631 | | { |
9632 | | case bfd_section_reloc_link_order: |
9633 | | case bfd_symbol_reloc_link_order: |
9634 | | printf (" section/symbol reloc\n"); |
9635 | | break; |
9636 | | case bfd_indirect_link_order: |
9637 | | printf (" section %s of %s\n", |
9638 | | p->u.indirect.section->name, |
9639 | | p->u.indirect.section->owner->filename); |
9640 | | break; |
9641 | | case bfd_data_link_order: |
9642 | | printf (" explicit data\n"); |
9643 | | break; |
9644 | | default: |
9645 | | printf (" *unknown* type %u\n", p->type); |
9646 | | break; |
9647 | | } |
9648 | | } |
9649 | | } |
9650 | | #endif |
9651 | | |
9652 | | /* Generate the symbol table. */ |
9653 | 0 | BFD_ASSERT (PRIV (syms) == NULL); |
9654 | 0 | if (info->strip != strip_all) |
9655 | 0 | bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info); |
9656 | | |
9657 | | /* Find the entry point. */ |
9658 | 0 | if (bfd_get_start_address (abfd) == 0) |
9659 | 0 | { |
9660 | 0 | bfd *startbfd = NULL; |
9661 | |
|
9662 | 0 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
9663 | 0 | { |
9664 | | /* Consider only VMS object files. */ |
9665 | 0 | if (sub->xvec != abfd->xvec) |
9666 | 0 | continue; |
9667 | | |
9668 | 0 | if (!PRIV2 (sub, eom_data).eom_has_transfer) |
9669 | 0 | continue; |
9670 | 0 | if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd) |
9671 | 0 | continue; |
9672 | 0 | if (startbfd != NULL |
9673 | 0 | && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR)) |
9674 | 0 | { |
9675 | 0 | (*info->callbacks->einfo) |
9676 | | /* xgettext:c-format */ |
9677 | 0 | (_("%P: multiple entry points: in modules %pB and %pB\n"), |
9678 | 0 | startbfd, sub); |
9679 | 0 | continue; |
9680 | 0 | } |
9681 | 0 | startbfd = sub; |
9682 | 0 | } |
9683 | |
|
9684 | 0 | if (startbfd) |
9685 | 0 | { |
9686 | 0 | unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx; |
9687 | 0 | bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr; |
9688 | 0 | asection *sec; |
9689 | |
|
9690 | 0 | BFD_ASSERT (ps_idx < PRIV2 (startbfd, section_count)); |
9691 | 0 | sec = PRIV2 (startbfd, sections)[ps_idx]; |
9692 | |
|
9693 | 0 | bfd_set_start_address |
9694 | 0 | (abfd, sec->output_section->vma + sec->output_offset + tfradr); |
9695 | 0 | } |
9696 | 0 | } |
9697 | | |
9698 | | /* Set transfer addresses. */ |
9699 | 0 | { |
9700 | 0 | int i; |
9701 | 0 | struct bfd_link_hash_entry *h; |
9702 | |
|
9703 | 0 | i = 0; |
9704 | 0 | PRIV (transfer_address[i++]) = 0xffffffff00000340ULL; /* SYS$IMGACT */ |
9705 | 0 | h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", false, false, true); |
9706 | 0 | if (h != NULL && h->type == bfd_link_hash_defined) |
9707 | 0 | PRIV (transfer_address[i++]) = |
9708 | 0 | alpha_vms_get_sym_value (h->u.def.section, h->u.def.value); |
9709 | 0 | PRIV (transfer_address[i++]) = bfd_get_start_address (abfd); |
9710 | 0 | while (i < 4) |
9711 | 0 | PRIV (transfer_address[i++]) = 0; |
9712 | 0 | } |
9713 | | |
9714 | | /* Allocate contents. |
9715 | | Also compute the virtual base address. */ |
9716 | 0 | base_addr = (bfd_vma)-1; |
9717 | 0 | last_addr = 0; |
9718 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
9719 | 0 | { |
9720 | 0 | if (o->flags & SEC_HAS_CONTENTS) |
9721 | 0 | { |
9722 | 0 | o->contents = bfd_alloc (abfd, o->size); |
9723 | 0 | if (o->contents == NULL) |
9724 | 0 | return false; |
9725 | 0 | o->alloced = 1; |
9726 | 0 | } |
9727 | 0 | if (o->flags & SEC_LOAD) |
9728 | 0 | { |
9729 | 0 | if (o->vma < base_addr) |
9730 | 0 | base_addr = o->vma; |
9731 | 0 | if (o->vma + o->size > last_addr) |
9732 | 0 | last_addr = o->vma + o->size; |
9733 | 0 | } |
9734 | | /* Clear the RELOC flags. Currently we don't support incremental |
9735 | | linking. We use the RELOC flag for computing the eicp entries. */ |
9736 | 0 | o->flags &= ~SEC_RELOC; |
9737 | 0 | } |
9738 | | |
9739 | | /* Create the fixup section. */ |
9740 | 0 | fixupsec = bfd_make_section_anyway_with_flags |
9741 | 0 | (info->output_bfd, "$FIXUP$", |
9742 | 0 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); |
9743 | 0 | if (fixupsec == NULL) |
9744 | 0 | return false; |
9745 | 0 | last_addr = (last_addr + 0xffff) & ~0xffff; |
9746 | 0 | fixupsec->vma = last_addr; |
9747 | |
|
9748 | 0 | alpha_vms_link_hash (info)->fixup = fixupsec; |
9749 | 0 | alpha_vms_link_hash (info)->base_addr = base_addr; |
9750 | | |
9751 | | /* Create the DMT section, if necessary. */ |
9752 | 0 | BFD_ASSERT (PRIV (dst_section) == NULL); |
9753 | 0 | dst = bfd_get_section_by_name (abfd, "$DST$"); |
9754 | 0 | if (dst != NULL && dst->size == 0) |
9755 | 0 | dst = NULL; |
9756 | 0 | if (dst != NULL) |
9757 | 0 | { |
9758 | 0 | PRIV (dst_section) = dst; |
9759 | 0 | dmt = bfd_make_section_anyway_with_flags |
9760 | 0 | (info->output_bfd, "$DMT$", |
9761 | 0 | SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); |
9762 | 0 | if (dmt == NULL) |
9763 | 0 | return false; |
9764 | 0 | } |
9765 | 0 | else |
9766 | 0 | dmt = NULL; |
9767 | | |
9768 | | /* Read all sections from the inputs. */ |
9769 | 0 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
9770 | 0 | { |
9771 | 0 | if (sub->flags & DYNAMIC) |
9772 | 0 | { |
9773 | 0 | alpha_vms_create_eisd_for_shared (abfd, sub); |
9774 | 0 | continue; |
9775 | 0 | } |
9776 | | |
9777 | 0 | if (!alpha_vms_read_sections_content (sub, info)) |
9778 | 0 | return false; |
9779 | 0 | } |
9780 | | |
9781 | | /* Handle all the link order information for the sections. |
9782 | | Note: past this point, it is not possible to create new sections. */ |
9783 | 0 | for (o = abfd->sections; o != NULL; o = o->next) |
9784 | 0 | { |
9785 | 0 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
9786 | 0 | { |
9787 | 0 | switch (p->type) |
9788 | 0 | { |
9789 | 0 | case bfd_section_reloc_link_order: |
9790 | 0 | case bfd_symbol_reloc_link_order: |
9791 | 0 | abort (); |
9792 | 0 | return false; |
9793 | 0 | case bfd_indirect_link_order: |
9794 | | /* Already done. */ |
9795 | 0 | break; |
9796 | 0 | default: |
9797 | 0 | if (! _bfd_default_link_order (abfd, info, o, p)) |
9798 | 0 | return false; |
9799 | 0 | break; |
9800 | 0 | } |
9801 | 0 | } |
9802 | 0 | } |
9803 | | |
9804 | | /* Compute fixups. */ |
9805 | 0 | if (!alpha_vms_build_fixups (info)) |
9806 | 0 | return false; |
9807 | | |
9808 | | /* Compute the DMT. */ |
9809 | 0 | if (dmt != NULL) |
9810 | 0 | { |
9811 | 0 | int pass; |
9812 | 0 | unsigned char *contents = NULL; |
9813 | | |
9814 | | /* In pass 1, compute the size. In pass 2, write the DMT contents. */ |
9815 | 0 | for (pass = 0; pass < 2; pass++) |
9816 | 0 | { |
9817 | 0 | unsigned int off = 0; |
9818 | | |
9819 | | /* For each object file (ie for each module). */ |
9820 | 0 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
9821 | 0 | { |
9822 | 0 | asection *sub_dst; |
9823 | 0 | struct vms_dmt_header *dmth = NULL; |
9824 | 0 | unsigned int psect_count; |
9825 | | |
9826 | | /* Skip this module if it has no DST. */ |
9827 | 0 | sub_dst = PRIV2 (sub, dst_section); |
9828 | 0 | if (sub_dst == NULL || sub_dst->size == 0) |
9829 | 0 | continue; |
9830 | | |
9831 | 0 | if (pass == 1) |
9832 | 0 | { |
9833 | | /* Write the header. */ |
9834 | 0 | dmth = (struct vms_dmt_header *)(contents + off); |
9835 | 0 | bfd_putl32 (sub_dst->output_offset, dmth->modbeg); |
9836 | 0 | bfd_putl32 (sub_dst->size, dmth->size); |
9837 | 0 | } |
9838 | |
|
9839 | 0 | off += sizeof (struct vms_dmt_header); |
9840 | 0 | psect_count = 0; |
9841 | | |
9842 | | /* For each section (ie for each psect). */ |
9843 | 0 | for (o = sub->sections; o != NULL; o = o->next) |
9844 | 0 | { |
9845 | | /* Only consider interesting sections. */ |
9846 | 0 | if (!(o->flags & SEC_ALLOC)) |
9847 | 0 | continue; |
9848 | 0 | if (o->flags & SEC_LINKER_CREATED) |
9849 | 0 | continue; |
9850 | | |
9851 | 0 | if (pass == 1) |
9852 | 0 | { |
9853 | | /* Write an entry. */ |
9854 | 0 | struct vms_dmt_psect *dmtp; |
9855 | |
|
9856 | 0 | dmtp = (struct vms_dmt_psect *)(contents + off); |
9857 | 0 | bfd_putl32 (o->output_offset + o->output_section->vma, |
9858 | 0 | dmtp->start); |
9859 | 0 | bfd_putl32 (o->size, dmtp->length); |
9860 | 0 | psect_count++; |
9861 | 0 | } |
9862 | 0 | off += sizeof (struct vms_dmt_psect); |
9863 | 0 | } |
9864 | 0 | if (pass == 1) |
9865 | 0 | bfd_putl32 (psect_count, dmth->psect_count); |
9866 | 0 | } |
9867 | |
|
9868 | 0 | if (pass == 0) |
9869 | 0 | { |
9870 | 0 | contents = bfd_zalloc (info->output_bfd, off); |
9871 | 0 | if (contents == NULL) |
9872 | 0 | return false; |
9873 | 0 | dmt->contents = contents; |
9874 | 0 | dmt->alloced = 1; |
9875 | 0 | dmt->size = off; |
9876 | 0 | } |
9877 | 0 | else |
9878 | 0 | { |
9879 | 0 | BFD_ASSERT (off == dmt->size); |
9880 | 0 | } |
9881 | 0 | } |
9882 | 0 | } |
9883 | | |
9884 | 0 | return true; |
9885 | 0 | } |
9886 | | |
9887 | | /* Read the contents of a section. |
9888 | | buf points to a buffer of buf_size bytes to be filled with |
9889 | | section data (starting at offset into section) */ |
9890 | | |
9891 | | static bool |
9892 | | alpha_vms_get_section_contents (bfd *abfd, asection *section, |
9893 | | void *buf, file_ptr offset, |
9894 | | bfd_size_type count) |
9895 | 153 | { |
9896 | | /* Handle image sections. */ |
9897 | 153 | if (section->filepos != 0 |
9898 | 31 | || (section->flags & SEC_HAS_CONTENTS) == 0) |
9899 | 122 | return _bfd_generic_get_section_contents (abfd, section, |
9900 | 122 | buf, offset, count); |
9901 | | |
9902 | | /* A section with a zero filepos implies the section has no direct |
9903 | | file backing. Its contents must be calculated by processing ETIR |
9904 | | records. */ |
9905 | | |
9906 | | /* Safety check. */ |
9907 | 31 | if (offset + count < count |
9908 | 31 | || offset + count > section->size) |
9909 | 0 | { |
9910 | 0 | bfd_set_error (bfd_error_invalid_operation); |
9911 | 0 | return false; |
9912 | 0 | } |
9913 | | |
9914 | 31 | if (section->size == 0) |
9915 | 0 | return true; |
9916 | | |
9917 | | /* If we haven't yet read ETIR/EDBG/ETBT records, do so. */ |
9918 | 31 | if ((section->flags & SEC_IN_MEMORY) == 0) |
9919 | 31 | { |
9920 | | /* Alloc memory and read ETIRs. */ |
9921 | 98 | for (asection *sec = abfd->sections; sec; sec = sec->next) |
9922 | 67 | { |
9923 | 67 | if (sec->size != 0 |
9924 | 55 | && sec->filepos == 0 |
9925 | 40 | && (sec->flags & SEC_HAS_CONTENTS) != 0) |
9926 | 32 | { |
9927 | 32 | BFD_ASSERT (sec->contents == NULL); |
9928 | | |
9929 | 32 | sec->contents = bfd_zalloc (abfd, sec->size); |
9930 | 32 | sec->flags |= SEC_IN_MEMORY; |
9931 | 32 | if (sec->contents == NULL) |
9932 | 0 | return false; |
9933 | 32 | sec->alloced = 1; |
9934 | 32 | } |
9935 | 67 | } |
9936 | 31 | if (!alpha_vms_read_sections_content (abfd, NULL)) |
9937 | 31 | return false; |
9938 | 31 | } |
9939 | | |
9940 | 0 | BFD_ASSERT (section->contents != NULL); |
9941 | 0 | memcpy (buf, section->contents + offset, count); |
9942 | 0 | return true; |
9943 | 31 | } |
9944 | | |
9945 | | |
9946 | | /* Set the format of a file being written. */ |
9947 | | |
9948 | | static bool |
9949 | | alpha_vms_mkobject (bfd * abfd) |
9950 | 15 | { |
9951 | 15 | const bfd_arch_info_type *arch; |
9952 | | |
9953 | 15 | vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd)); |
9954 | | |
9955 | 15 | if (!vms_initialize (abfd)) |
9956 | 0 | return false; |
9957 | | |
9958 | 15 | PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE); |
9959 | 15 | if (PRIV (recwr.buf) == NULL) |
9960 | 0 | return false; |
9961 | | |
9962 | 15 | arch = bfd_scan_arch ("alpha"); |
9963 | | |
9964 | 15 | if (arch == 0) |
9965 | 0 | { |
9966 | 0 | bfd_set_error (bfd_error_wrong_format); |
9967 | 0 | return false; |
9968 | 0 | } |
9969 | | |
9970 | 15 | abfd->arch_info = arch; |
9971 | 15 | return true; |
9972 | 15 | } |
9973 | | |
9974 | | |
9975 | | /* 4.1, generic. */ |
9976 | | |
9977 | | /* Called when the BFD is being closed to do any necessary cleanup. */ |
9978 | | |
9979 | | static bool |
9980 | | vms_close_and_cleanup (bfd * abfd) |
9981 | 147 | { |
9982 | 147 | vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd)); |
9983 | | |
9984 | 147 | if (abfd == NULL || abfd->tdata.any == NULL) |
9985 | 0 | return true; |
9986 | | |
9987 | 147 | if (abfd->format == bfd_object) |
9988 | 137 | { |
9989 | 137 | alpha_vms_free_private (abfd); |
9990 | | |
9991 | | #ifdef VMS |
9992 | | if (abfd->direction == write_direction) |
9993 | | { |
9994 | | /* Last step on VMS is to convert the file to variable record length |
9995 | | format. */ |
9996 | | if (!bfd_cache_close (abfd)) |
9997 | | return false; |
9998 | | if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename)) |
9999 | | return false; |
10000 | | } |
10001 | | #endif |
10002 | 137 | } |
10003 | | |
10004 | 147 | return _bfd_generic_close_and_cleanup (abfd); |
10005 | 147 | } |
10006 | | |
10007 | | /* Called when a new section is created. */ |
10008 | | |
10009 | | static bool |
10010 | | vms_new_section_hook (bfd * abfd, asection *section) |
10011 | 871 | { |
10012 | 871 | size_t amt; |
10013 | | |
10014 | 871 | vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n", |
10015 | 871 | abfd, section->index, section->name)); |
10016 | | |
10017 | 871 | if (!bfd_set_section_alignment (section, 0)) |
10018 | 0 | return false; |
10019 | | |
10020 | 871 | vms_debug2 ((7, "%u: %s\n", section->index, section->name)); |
10021 | | |
10022 | 871 | amt = sizeof (struct vms_section_data_struct); |
10023 | 871 | section->used_by_bfd = bfd_zalloc (abfd, amt); |
10024 | 871 | if (section->used_by_bfd == NULL) |
10025 | 0 | return false; |
10026 | | |
10027 | | /* Create the section symbol. */ |
10028 | 871 | return _bfd_generic_new_section_hook (abfd, section); |
10029 | 871 | } |
10030 | | |
10031 | | /* Part 4.5, symbols. */ |
10032 | | |
10033 | | /* Print symbol to file according to how. how is one of |
10034 | | bfd_print_symbol_name just print the name |
10035 | | bfd_print_symbol_more print more (???) |
10036 | | bfd_print_symbol_all print all we know, which is not much right now :-). */ |
10037 | | |
10038 | | static void |
10039 | | vms_print_symbol (bfd * abfd, |
10040 | | void * file, |
10041 | | asymbol *symbol, |
10042 | | bfd_print_symbol_type how) |
10043 | 0 | { |
10044 | 0 | vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n", |
10045 | 0 | abfd, file, symbol, how)); |
10046 | |
|
10047 | 0 | switch (how) |
10048 | 0 | { |
10049 | 0 | case bfd_print_symbol_name: |
10050 | 0 | case bfd_print_symbol_more: |
10051 | 0 | fprintf ((FILE *)file," %s", symbol->name); |
10052 | 0 | break; |
10053 | | |
10054 | 0 | case bfd_print_symbol_all: |
10055 | 0 | { |
10056 | 0 | const char *section_name = symbol->section->name; |
10057 | |
|
10058 | 0 | bfd_print_symbol_vandf (abfd, file, symbol); |
10059 | |
|
10060 | 0 | fprintf ((FILE *) file," %-8s %s", section_name, symbol->name); |
10061 | 0 | } |
10062 | 0 | break; |
10063 | 0 | } |
10064 | 0 | } |
10065 | | |
10066 | | /* Return information about symbol in ret. |
10067 | | |
10068 | | fill type, value and name |
10069 | | type: |
10070 | | A absolute |
10071 | | B bss segment symbol |
10072 | | C common symbol |
10073 | | D data segment symbol |
10074 | | f filename |
10075 | | t a static function symbol |
10076 | | T text segment symbol |
10077 | | U undefined |
10078 | | - debug. */ |
10079 | | |
10080 | | static void |
10081 | | vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED, |
10082 | | asymbol *symbol, |
10083 | | symbol_info *ret) |
10084 | 37 | { |
10085 | 37 | asection *sec; |
10086 | | |
10087 | 37 | vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret)); |
10088 | | |
10089 | 37 | sec = symbol->section; |
10090 | | |
10091 | 37 | if (ret == NULL) |
10092 | 0 | return; |
10093 | | |
10094 | 37 | if (sec == NULL) |
10095 | 0 | ret->type = 'U'; |
10096 | 37 | else if (bfd_is_com_section (sec)) |
10097 | 0 | ret->type = 'C'; |
10098 | 37 | else if (bfd_is_abs_section (sec)) |
10099 | 0 | ret->type = 'A'; |
10100 | 37 | else if (bfd_is_und_section (sec)) |
10101 | 37 | ret->type = 'U'; |
10102 | 0 | else if (bfd_is_ind_section (sec)) |
10103 | 0 | ret->type = 'I'; |
10104 | 0 | else if ((symbol->flags & BSF_FUNCTION) |
10105 | 0 | || (bfd_section_flags (sec) & SEC_CODE)) |
10106 | 0 | ret->type = 'T'; |
10107 | 0 | else if (bfd_section_flags (sec) & SEC_DATA) |
10108 | 0 | ret->type = 'D'; |
10109 | 0 | else if (bfd_section_flags (sec) & SEC_ALLOC) |
10110 | 0 | ret->type = 'B'; |
10111 | 0 | else |
10112 | 0 | ret->type = '?'; |
10113 | | |
10114 | 37 | if (ret->type != 'U') |
10115 | 0 | ret->value = symbol->value + symbol->section->vma; |
10116 | 37 | else |
10117 | 37 | ret->value = 0; |
10118 | 37 | ret->name = symbol->name; |
10119 | 37 | } |
10120 | | |
10121 | | /* Return TRUE if the given symbol sym in the BFD abfd is |
10122 | | a compiler generated local label, else return FALSE. */ |
10123 | | |
10124 | | static bool |
10125 | | vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED, |
10126 | | const char *name) |
10127 | 0 | { |
10128 | 0 | return name[0] == '$'; |
10129 | 0 | } |
10130 | | |
10131 | | /* Part 4.7, writing an object file. */ |
10132 | | |
10133 | | /* Sets the contents of the section section in BFD abfd to the data starting |
10134 | | in memory at LOCATION. The data is written to the output section starting |
10135 | | at offset offset for count bytes. |
10136 | | |
10137 | | Normally TRUE is returned, else FALSE. Possible error returns are: |
10138 | | o bfd_error_no_contents - The output section does not have the |
10139 | | SEC_HAS_CONTENTS attribute, so nothing can be written to it. |
10140 | | o and some more too */ |
10141 | | |
10142 | | static bool |
10143 | | _bfd_vms_set_section_contents (bfd * abfd, |
10144 | | asection *section, |
10145 | | const void * location, |
10146 | | file_ptr offset, |
10147 | | bfd_size_type count) |
10148 | 0 | { |
10149 | 0 | if (section->contents == NULL) |
10150 | 0 | { |
10151 | 0 | section->contents = bfd_alloc (abfd, section->size); |
10152 | 0 | if (section->contents == NULL) |
10153 | 0 | return false; |
10154 | 0 | section->alloced = 1; |
10155 | |
|
10156 | 0 | memcpy (section->contents + offset, location, (size_t) count); |
10157 | 0 | } |
10158 | | |
10159 | 0 | return true; |
10160 | 0 | } |
10161 | | |
10162 | | /* Set the architecture and machine type in BFD abfd to arch and mach. |
10163 | | Find the correct pointer to a structure and insert it into the arch_info |
10164 | | pointer. */ |
10165 | | |
10166 | | static bool |
10167 | | alpha_vms_set_arch_mach (bfd *abfd, |
10168 | | enum bfd_architecture arch, unsigned long mach) |
10169 | 12 | { |
10170 | 12 | if (arch != bfd_arch_alpha |
10171 | 0 | && arch != bfd_arch_unknown) |
10172 | 0 | return false; |
10173 | | |
10174 | 12 | return bfd_default_set_arch_mach (abfd, arch, mach); |
10175 | 12 | } |
10176 | | |
10177 | | /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */ |
10178 | | |
10179 | | void |
10180 | | bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED, |
10181 | | asection *sec, flagword no_flags, flagword flags) |
10182 | 0 | { |
10183 | 0 | vms_section_data (sec)->no_flags = no_flags; |
10184 | 0 | vms_section_data (sec)->flags = flags; |
10185 | 0 | } |
10186 | | |
10187 | | struct vms_private_data_struct * |
10188 | | bfd_vms_get_data (bfd *abfd) |
10189 | 0 | { |
10190 | 0 | return (struct vms_private_data_struct *)abfd->tdata.any; |
10191 | 0 | } |
10192 | | |
10193 | | #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data |
10194 | | #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data |
10195 | | #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data |
10196 | | #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data |
10197 | | #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data |
10198 | | #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags |
10199 | | |
10200 | | /* Symbols table. */ |
10201 | | #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol |
10202 | | #define alpha_vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
10203 | | #define alpha_vms_print_symbol vms_print_symbol |
10204 | | #define alpha_vms_get_symbol_info vms_get_symbol_info |
10205 | | #define alpha_vms_get_symbol_version_string \ |
10206 | | _bfd_nosymbols_get_symbol_version_string |
10207 | | |
10208 | | #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols |
10209 | | #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol |
10210 | | #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno |
10211 | | #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info |
10212 | | #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol |
10213 | | #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_line |
10214 | | #define alpha_vms_find_nearest_line_with_alt \ |
10215 | | _bfd_nosymbols_find_nearest_line_with_alt |
10216 | | #define alpha_vms_find_line _bfd_nosymbols_find_line |
10217 | | #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name |
10218 | | |
10219 | | /* Generic table. */ |
10220 | | #define alpha_vms_close_and_cleanup vms_close_and_cleanup |
10221 | | #define alpha_vms_bfd_free_cached_info _bfd_bool_bfd_true |
10222 | | #define alpha_vms_new_section_hook vms_new_section_hook |
10223 | | #define alpha_vms_set_section_contents _bfd_vms_set_section_contents |
10224 | | |
10225 | | #define alpha_vms_bfd_get_relocated_section_contents \ |
10226 | | bfd_generic_get_relocated_section_contents |
10227 | | |
10228 | | #define alpha_vms_bfd_relax_section bfd_generic_relax_section |
10229 | | #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections |
10230 | | #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags |
10231 | | #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section |
10232 | | #define alpha_vms_bfd_group_name bfd_generic_group_name |
10233 | | #define alpha_vms_bfd_discard_group bfd_generic_discard_group |
10234 | | #define alpha_vms_section_already_linked \ |
10235 | | _bfd_generic_section_already_linked |
10236 | | |
10237 | | #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol |
10238 | | #define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol |
10239 | | #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop |
10240 | | #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms |
10241 | | #define alpha_vms_bfd_copy_link_hash_symbol_type \ |
10242 | | _bfd_generic_copy_link_hash_symbol_type |
10243 | | |
10244 | | #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section |
10245 | | |
10246 | | #define alpha_vms_get_dynamic_symtab_upper_bound \ |
10247 | | _bfd_nodynamic_get_dynamic_symtab_upper_bound |
10248 | | #define alpha_vms_canonicalize_dynamic_symtab \ |
10249 | | _bfd_nodynamic_canonicalize_dynamic_symtab |
10250 | | #define alpha_vms_get_dynamic_reloc_upper_bound \ |
10251 | | _bfd_nodynamic_get_dynamic_reloc_upper_bound |
10252 | | #define alpha_vms_canonicalize_dynamic_reloc \ |
10253 | | _bfd_nodynamic_canonicalize_dynamic_reloc |
10254 | | #define alpha_vms_bfd_link_check_relocs _bfd_generic_link_check_relocs |
10255 | | |
10256 | | const bfd_target alpha_vms_vec = |
10257 | | { |
10258 | | "vms-alpha", /* Name. */ |
10259 | | bfd_target_evax_flavour, |
10260 | | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ |
10261 | | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ |
10262 | | |
10263 | | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
10264 | | | WP_TEXT | D_PAGED), /* Object flags. */ |
10265 | | (SEC_ALLOC | SEC_LOAD | SEC_RELOC |
10266 | | | SEC_READONLY | SEC_CODE | SEC_DATA |
10267 | | | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */ |
10268 | | 0, /* symbol_leading_char. */ |
10269 | | ' ', /* ar_pad_char. */ |
10270 | | 15, /* ar_max_namelen. */ |
10271 | | 0, /* match priority. */ |
10272 | | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
10273 | | TARGET_MERGE_SECTIONS, |
10274 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
10275 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
10276 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, |
10277 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
10278 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
10279 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, |
10280 | | |
10281 | | { /* bfd_check_format. */ |
10282 | | _bfd_dummy_target, |
10283 | | alpha_vms_object_p, |
10284 | | _bfd_vms_lib_alpha_archive_p, |
10285 | | _bfd_dummy_target |
10286 | | }, |
10287 | | { /* bfd_set_format. */ |
10288 | | _bfd_bool_bfd_false_error, |
10289 | | alpha_vms_mkobject, |
10290 | | _bfd_vms_lib_alpha_mkarchive, |
10291 | | _bfd_bool_bfd_false_error |
10292 | | }, |
10293 | | { /* bfd_write_contents. */ |
10294 | | _bfd_bool_bfd_false_error, |
10295 | | alpha_vms_write_object_contents, |
10296 | | _bfd_vms_lib_write_archive_contents, |
10297 | | _bfd_bool_bfd_false_error |
10298 | | }, |
10299 | | |
10300 | | BFD_JUMP_TABLE_GENERIC (alpha_vms), |
10301 | | BFD_JUMP_TABLE_COPY (vms), |
10302 | | BFD_JUMP_TABLE_CORE (_bfd_nocore), |
10303 | | BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib), |
10304 | | BFD_JUMP_TABLE_SYMBOLS (alpha_vms), |
10305 | | BFD_JUMP_TABLE_RELOCS (alpha_vms), |
10306 | | BFD_JUMP_TABLE_WRITE (alpha_vms), |
10307 | | BFD_JUMP_TABLE_LINK (alpha_vms), |
10308 | | BFD_JUMP_TABLE_DYNAMIC (alpha_vms), |
10309 | | |
10310 | | NULL, |
10311 | | |
10312 | | NULL |
10313 | | }; |