Commit | Line | Data |
---|---|---|
95e34ef7 | 1 | /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files. |
b3adc24a | 2 | Copyright (C) 1996-2020 Free Software Foundation, Inc. |
95e34ef7 TG |
3 | |
4 | Initial version written by Klaus Kaempf (kkaempf@rmi.de) | |
5 | Major rewrite by Adacore. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
20 | MA 02110-1301, USA. */ | |
21 | ||
22 | /* TODO: | |
f9eeb9c9 | 23 | o overlayed sections |
95e34ef7 TG |
24 | o PIC |
25 | o Generation of shared image | |
95e34ef7 TG |
26 | o Relocation optimizations |
27 | o EISD for the stack | |
28 | o Vectors isect | |
29 | o 64 bits sections | |
30 | o Entry point | |
f9eeb9c9 TG |
31 | o LIB$INITIALIZE |
32 | o protected sections (for messages) | |
95e34ef7 TG |
33 | ... |
34 | */ | |
35 | ||
36 | #include "sysdep.h" | |
37 | #include "bfd.h" | |
38 | #include "bfdlink.h" | |
39 | #include "libbfd.h" | |
40 | #include "bfdver.h" | |
41 | ||
42 | #include "vms.h" | |
43 | #include "vms/eihd.h" | |
44 | #include "vms/eiha.h" | |
45 | #include "vms/eihi.h" | |
46 | #include "vms/eihs.h" | |
47 | #include "vms/eisd.h" | |
48 | #include "vms/dmt.h" | |
49 | #include "vms/dst.h" | |
50 | #include "vms/eihvn.h" | |
51 | #include "vms/eobjrec.h" | |
52 | #include "vms/egsd.h" | |
53 | #include "vms/egps.h" | |
9a1b4480 | 54 | #include "vms/esgps.h" |
95e34ef7 TG |
55 | #include "vms/eeom.h" |
56 | #include "vms/emh.h" | |
57 | #include "vms/eiaf.h" | |
58 | #include "vms/shl.h" | |
59 | #include "vms/eicp.h" | |
60 | #include "vms/etir.h" | |
61 | #include "vms/egsy.h" | |
62 | #include "vms/esdf.h" | |
63 | #include "vms/esdfm.h" | |
64 | #include "vms/esdfv.h" | |
65 | #include "vms/esrf.h" | |
66 | #include "vms/egst.h" | |
9a1b4480 | 67 | #include "vms/eidc.h" |
95e34ef7 TG |
68 | #include "vms/dsc.h" |
69 | #include "vms/prt.h" | |
70 | #include "vms/internal.h" | |
71 | \f | |
72 | ||
73 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
74 | ||
75 | /* The r_type field in a reloc is one of the following values. */ | |
76 | #define ALPHA_R_IGNORE 0 | |
77 | #define ALPHA_R_REFQUAD 1 | |
78 | #define ALPHA_R_BRADDR 2 | |
79 | #define ALPHA_R_HINT 3 | |
80 | #define ALPHA_R_SREL16 4 | |
81 | #define ALPHA_R_SREL32 5 | |
82 | #define ALPHA_R_SREL64 6 | |
83 | #define ALPHA_R_OP_PUSH 7 | |
84 | #define ALPHA_R_OP_STORE 8 | |
85 | #define ALPHA_R_OP_PSUB 9 | |
86 | #define ALPHA_R_OP_PRSHIFT 10 | |
87 | #define ALPHA_R_LINKAGE 11 | |
88 | #define ALPHA_R_REFLONG 12 | |
89 | #define ALPHA_R_CODEADDR 13 | |
90 | #define ALPHA_R_NOP 14 | |
91 | #define ALPHA_R_BSR 15 | |
92 | #define ALPHA_R_LDA 16 | |
93 | #define ALPHA_R_BOH 17 | |
44273c5b | 94 | |
95e34ef7 TG |
95 | /* These are used with DST_S_C_LINE_NUM. */ |
96 | #define DST_S_C_LINE_NUM_HEADER_SIZE 4 | |
97 | ||
98 | /* These are used with DST_S_C_SOURCE */ | |
99 | ||
100 | #define DST_S_B_PCLINE_UNSBYTE 1 | |
101 | #define DST_S_W_PCLINE_UNSWORD 1 | |
102 | #define DST_S_L_PCLINE_UNSLONG 1 | |
103 | ||
104 | #define DST_S_B_MODBEG_NAME 14 | |
105 | #define DST_S_L_RTNBEG_ADDRESS 5 | |
106 | #define DST_S_B_RTNBEG_NAME 13 | |
107 | #define DST_S_L_RTNEND_SIZE 5 | |
108 | ||
109 | /* These are used with DST_S_C_SOURCE. */ | |
110 | #define DST_S_C_SOURCE_HEADER_SIZE 4 | |
111 | ||
112 | #define DST_S_B_SRC_DF_LENGTH 1 | |
113 | #define DST_S_W_SRC_DF_FILEID 3 | |
114 | #define DST_S_B_SRC_DF_FILENAME 20 | |
115 | #define DST_S_B_SRC_UNSBYTE 1 | |
116 | #define DST_S_W_SRC_UNSWORD 1 | |
117 | #define DST_S_L_SRC_UNSLONG 1 | |
118 | ||
119 | /* Debugger symbol definitions. */ | |
120 | ||
07d6d2b8 AM |
121 | #define DBG_S_L_DMT_MODBEG 0 |
122 | #define DBG_S_L_DST_SIZE 4 | |
123 | #define DBG_S_W_DMT_PSECT_COUNT 8 | |
95e34ef7 TG |
124 | #define DBG_S_C_DMT_HEADER_SIZE 12 |
125 | ||
07d6d2b8 | 126 | #define DBG_S_L_DMT_PSECT_START 0 |
95e34ef7 | 127 | #define DBG_S_L_DMT_PSECT_LENGTH 4 |
07d6d2b8 | 128 | #define DBG_S_C_DMT_PSECT_SIZE 8 |
95e34ef7 TG |
129 | |
130 | /* VMS module header. */ | |
131 | ||
132 | struct hdr_struct | |
133 | { | |
134 | char hdr_b_strlvl; | |
135 | int hdr_l_arch1; | |
136 | int hdr_l_arch2; | |
137 | int hdr_l_recsiz; | |
138 | char *hdr_t_name; | |
139 | char *hdr_t_version; | |
140 | char *hdr_t_date; | |
141 | char *hdr_c_lnm; | |
142 | char *hdr_c_src; | |
143 | char *hdr_c_ttl; | |
144 | }; | |
145 | ||
146 | #define EMH_DATE_LENGTH 17 | |
147 | ||
148 | /* VMS End-Of-Module records (EOM/EEOM). */ | |
149 | ||
150 | struct eom_struct | |
151 | { | |
152 | unsigned int eom_l_total_lps; | |
153 | unsigned short eom_w_comcod; | |
154 | bfd_boolean eom_has_transfer; | |
155 | unsigned char eom_b_tfrflg; | |
156 | unsigned int eom_l_psindx; | |
157 | unsigned int eom_l_tfradr; | |
158 | }; | |
159 | ||
160 | struct vms_symbol_entry | |
161 | { | |
162 | bfd *owner; | |
163 | ||
164 | /* Common fields. */ | |
165 | unsigned char typ; | |
166 | unsigned char data_type; | |
167 | unsigned short flags; | |
168 | ||
169 | /* Section and offset/value of the symbol. */ | |
95e34ef7 | 170 | unsigned int value; |
a928f1d7 | 171 | asection *section; |
95e34ef7 TG |
172 | |
173 | /* Section and offset/value for the entry point (only for subprg). */ | |
a928f1d7 | 174 | asection *code_section; |
95e34ef7 TG |
175 | unsigned int code_value; |
176 | ||
177 | /* Symbol vector offset. */ | |
178 | unsigned int symbol_vector; | |
179 | ||
180 | /* Length of the name. */ | |
181 | unsigned char namelen; | |
182 | ||
183 | char name[1]; | |
184 | }; | |
185 | ||
186 | /* Stack value for push/pop commands. */ | |
187 | ||
188 | struct stack_struct | |
189 | { | |
190 | bfd_vma value; | |
191 | unsigned int reloc; | |
192 | }; | |
193 | ||
194 | #define STACKSIZE 128 | |
195 | ||
196 | /* A minimal decoding of DST compilation units. We only decode | |
197 | what's needed to get to the line number information. */ | |
198 | ||
199 | struct fileinfo | |
200 | { | |
201 | char *name; | |
202 | unsigned int srec; | |
203 | }; | |
204 | ||
205 | struct srecinfo | |
206 | { | |
207 | struct srecinfo *next; | |
208 | unsigned int line; | |
209 | unsigned int sfile; | |
210 | unsigned int srec; | |
211 | }; | |
212 | ||
213 | struct lineinfo | |
214 | { | |
215 | struct lineinfo *next; | |
216 | bfd_vma address; | |
217 | unsigned int line; | |
218 | }; | |
219 | ||
220 | struct funcinfo | |
221 | { | |
222 | struct funcinfo *next; | |
223 | char *name; | |
224 | bfd_vma low; | |
225 | bfd_vma high; | |
226 | }; | |
227 | ||
228 | struct module | |
229 | { | |
230 | /* Chain the previously read compilation unit. */ | |
231 | struct module *next; | |
232 | ||
233 | /* The module name. */ | |
234 | char *name; | |
235 | ||
236 | /* The start offset and size of debug info in the DST section. */ | |
237 | unsigned int modbeg; | |
238 | unsigned int size; | |
239 | ||
240 | /* The lowest and highest addresses contained in this compilation | |
241 | unit as specified in the compilation unit header. */ | |
242 | bfd_vma low; | |
243 | bfd_vma high; | |
244 | ||
245 | /* The listing line table. */ | |
246 | struct lineinfo *line_table; | |
247 | ||
248 | /* The source record table. */ | |
249 | struct srecinfo *srec_table; | |
250 | ||
251 | /* A list of the functions found in this module. */ | |
252 | struct funcinfo *func_table; | |
253 | ||
254 | /* Current allocation of file_table. */ | |
255 | unsigned int file_table_count; | |
256 | ||
257 | /* An array of the files making up this module. */ | |
258 | struct fileinfo *file_table; | |
259 | }; | |
260 | ||
261 | /* BFD private data for alpha-vms. */ | |
262 | ||
263 | struct vms_private_data_struct | |
264 | { | |
265 | /* If true, relocs have been read. */ | |
266 | bfd_boolean reloc_done; | |
267 | ||
268 | /* Record input buffer. */ | |
269 | struct vms_rec_rd recrd; | |
270 | struct vms_rec_wr recwr; | |
271 | ||
272 | struct hdr_struct hdr_data; /* data from HDR/EMH record */ | |
273 | struct eom_struct eom_data; /* data from EOM/EEOM record */ | |
c734eb83 | 274 | |
46d00b8a TG |
275 | /* Transfer addresses (entry points). */ |
276 | bfd_vma transfer_address[4]; | |
277 | ||
c734eb83 | 278 | /* Array of GSD sections to get the correspond BFD one. */ |
07d6d2b8 | 279 | unsigned int section_max; /* Size of the sections array. */ |
c734eb83 TG |
280 | unsigned int section_count; /* Number of GSD sections. */ |
281 | asection **sections; | |
95e34ef7 TG |
282 | |
283 | /* Array of raw symbols. */ | |
284 | struct vms_symbol_entry **syms; | |
285 | ||
286 | /* Canonicalized symbols. */ | |
287 | asymbol **csymbols; | |
288 | ||
289 | /* Number of symbols. */ | |
290 | unsigned int gsd_sym_count; | |
291 | /* Size of the syms array. */ | |
292 | unsigned int max_sym_count; | |
293 | /* Number of procedure symbols. */ | |
294 | unsigned int norm_sym_count; | |
295 | ||
296 | /* Stack used to evaluate TIR/ETIR commands. */ | |
297 | struct stack_struct *stack; | |
298 | int stackptr; | |
299 | ||
300 | /* Content reading. */ | |
301 | asection *image_section; /* section for image_ptr */ | |
302 | file_ptr image_offset; /* Offset for image_ptr. */ | |
95e34ef7 TG |
303 | |
304 | struct module *modules; /* list of all compilation units */ | |
305 | ||
8185f55c | 306 | /* The DST section. */ |
95e34ef7 TG |
307 | asection *dst_section; |
308 | ||
309 | unsigned int dst_ptr_offsets_count; /* # of offsets in following array */ | |
310 | unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */ | |
311 | ||
312 | /* Shared library support */ | |
313 | bfd_vma symvva; /* relative virtual address of symbol vector */ | |
314 | unsigned int ident; | |
315 | unsigned char matchctl; | |
316 | ||
317 | /* Shared library index. This is used for input bfd while linking. */ | |
318 | unsigned int shr_index; | |
319 | ||
320 | /* Used to place structures in the file. */ | |
321 | file_ptr file_pos; | |
322 | ||
323 | /* Simply linked list of eisd. */ | |
324 | struct vms_internal_eisd_map *eisd_head; | |
325 | struct vms_internal_eisd_map *eisd_tail; | |
326 | ||
327 | /* Simply linked list of eisd for shared libraries. */ | |
328 | struct vms_internal_eisd_map *gbl_eisd_head; | |
329 | struct vms_internal_eisd_map *gbl_eisd_tail; | |
330 | ||
331 | /* linkage index counter used by conditional store commands */ | |
25d41743 | 332 | unsigned int vms_linkage_index; |
95e34ef7 TG |
333 | }; |
334 | ||
335 | #define PRIV2(abfd, name) \ | |
336 | (((struct vms_private_data_struct *)(abfd)->tdata.any)->name) | |
337 | #define PRIV(name) PRIV2(abfd,name) | |
338 | ||
339 | ||
340 | /* Used to keep extra VMS specific information for a given section. | |
341 | ||
342 | reloc_size holds the size of the relocation stream, note this | |
343 | is very different from the number of relocations as VMS relocations | |
344 | are variable length. | |
345 | ||
346 | reloc_stream is the actual stream of relocation entries. */ | |
347 | ||
348 | struct vms_section_data_struct | |
349 | { | |
350 | /* Maximnum number of entries in sec->relocation. */ | |
351 | unsigned reloc_max; | |
352 | ||
353 | /* Corresponding eisd. Used only while generating executables. */ | |
354 | struct vms_internal_eisd_map *eisd; | |
355 | ||
356 | /* PSC flags to be clear. */ | |
357 | flagword no_flags; | |
358 | ||
359 | /* PSC flags to be set. */ | |
360 | flagword flags; | |
361 | }; | |
362 | ||
363 | #define vms_section_data(sec) \ | |
364 | ((struct vms_section_data_struct *)sec->used_by_bfd) | |
365 | ||
366 | /* To be called from the debugger. */ | |
0a9d414a | 367 | struct vms_private_data_struct *bfd_vms_get_data (bfd *); |
95e34ef7 | 368 | |
0a9d414a | 369 | static int vms_get_remaining_object_record (bfd *, unsigned int); |
95e34ef7 | 370 | static bfd_boolean _bfd_vms_slurp_object_records (bfd * abfd); |
96d3b80f AM |
371 | static bfd_boolean alpha_vms_add_fixup_lp (struct bfd_link_info *, |
372 | bfd *, bfd *); | |
373 | static bfd_boolean alpha_vms_add_fixup_ca (struct bfd_link_info *, | |
374 | bfd *, bfd *); | |
375 | static bfd_boolean alpha_vms_add_fixup_qr (struct bfd_link_info *, | |
376 | bfd *, bfd *, bfd_vma); | |
377 | static bfd_boolean alpha_vms_add_fixup_lr (struct bfd_link_info *, | |
378 | unsigned int, bfd_vma); | |
379 | static bfd_boolean alpha_vms_add_lw_reloc (struct bfd_link_info *); | |
380 | static bfd_boolean alpha_vms_add_qw_reloc (struct bfd_link_info *); | |
95e34ef7 TG |
381 | |
382 | struct vector_type | |
383 | { | |
384 | unsigned int max_el; | |
385 | unsigned int nbr_el; | |
386 | void *els; | |
387 | }; | |
388 | ||
389 | /* Number of elements in VEC. */ | |
390 | ||
391 | #define VEC_COUNT(VEC) ((VEC).nbr_el) | |
392 | ||
393 | /* Get the address of the Nth element. */ | |
394 | ||
395 | #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N]) | |
396 | ||
07d6d2b8 AM |
397 | #define VEC_INIT(VEC) \ |
398 | do { \ | |
399 | (VEC).max_el = 0; \ | |
400 | (VEC).nbr_el = 0; \ | |
401 | (VEC).els = NULL; \ | |
95e34ef7 TG |
402 | } while (0) |
403 | ||
404 | /* Be sure there is room for a new element. */ | |
405 | ||
96d3b80f | 406 | static void *vector_grow1 (struct vector_type *vec, size_t elsz); |
95e34ef7 TG |
407 | |
408 | /* Allocate room for a new element and return its address. */ | |
409 | ||
07d6d2b8 | 410 | #define VEC_APPEND(VEC, TYPE) \ |
96d3b80f | 411 | ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE))) |
95e34ef7 TG |
412 | |
413 | struct alpha_vms_vma_ref | |
414 | { | |
415 | bfd_vma vma; /* Vma in the output. */ | |
416 | bfd_vma ref; /* Reference in the input. */ | |
417 | }; | |
418 | ||
419 | struct alpha_vms_shlib_el | |
420 | { | |
421 | bfd *abfd; | |
422 | bfd_boolean has_fixups; | |
423 | ||
424 | struct vector_type lp; /* Vector of bfd_vma. */ | |
425 | struct vector_type ca; /* Vector of bfd_vma. */ | |
426 | struct vector_type qr; /* Vector of struct alpha_vms_vma_ref. */ | |
427 | }; | |
428 | ||
429 | /* Alpha VMS linker hash table. */ | |
430 | ||
431 | struct alpha_vms_link_hash_table | |
432 | { | |
433 | struct bfd_link_hash_table root; | |
434 | ||
cc643b88 | 435 | /* Vector of shared libraries. */ |
95e34ef7 TG |
436 | struct vector_type shrlibs; |
437 | ||
438 | /* Fixup section. */ | |
439 | asection *fixup; | |
440 | ||
441 | /* Base address. Used by fixups. */ | |
442 | bfd_vma base_addr; | |
443 | }; | |
444 | ||
445 | #define alpha_vms_link_hash(INFO) \ | |
446 | ((struct alpha_vms_link_hash_table *)(INFO->hash)) | |
447 | ||
448 | /* Alpha VMS linker hash table entry. */ | |
449 | ||
450 | struct alpha_vms_link_hash_entry | |
451 | { | |
452 | struct bfd_link_hash_entry root; | |
453 | ||
454 | /* Pointer to the original vms symbol. */ | |
455 | struct vms_symbol_entry *sym; | |
456 | }; | |
457 | \f | |
458 | /* Image reading. */ | |
459 | ||
460 | /* Read & process EIHD record. | |
461 | Return TRUE on success, FALSE on error. */ | |
462 | ||
463 | static bfd_boolean | |
464 | _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset, | |
07d6d2b8 | 465 | unsigned int *eihs_offset) |
95e34ef7 TG |
466 | { |
467 | unsigned int imgtype, size; | |
468 | bfd_vma symvva; | |
469 | struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec); | |
470 | ||
471 | vms_debug2 ((8, "_bfd_vms_slurp_eihd\n")); | |
472 | ||
ca4cf9b9 NC |
473 | /* PR 21813: Check for an undersized record. */ |
474 | if (PRIV (recrd.buf_size) < sizeof (* eihd)) | |
475 | { | |
38f14ab8 | 476 | _bfd_error_handler (_("corrupt EIHD record - size is too small")); |
ca4cf9b9 NC |
477 | bfd_set_error (bfd_error_bad_value); |
478 | return FALSE; | |
479 | } | |
480 | ||
95e34ef7 TG |
481 | size = bfd_getl32 (eihd->size); |
482 | imgtype = bfd_getl32 (eihd->imgtype); | |
483 | ||
484 | if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM) | |
485 | abfd->flags |= EXEC_P; | |
486 | ||
487 | symvva = bfd_getl64 (eihd->symvva); | |
488 | if (symvva != 0) | |
489 | { | |
490 | PRIV (symvva) = symvva; | |
491 | abfd->flags |= DYNAMIC; | |
492 | } | |
493 | ||
494 | PRIV (ident) = bfd_getl32 (eihd->ident); | |
495 | PRIV (matchctl) = eihd->matchctl; | |
496 | ||
497 | *eisd_offset = bfd_getl32 (eihd->isdoff); | |
498 | *eihs_offset = bfd_getl32 (eihd->symdbgoff); | |
499 | ||
500 | vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n", | |
07d6d2b8 AM |
501 | size, imgtype, (unsigned long)symvva, |
502 | *eisd_offset, *eihs_offset)); | |
8ab484c2 | 503 | (void) size; |
95e34ef7 | 504 | |
ddfb684a | 505 | return TRUE; |
95e34ef7 TG |
506 | } |
507 | ||
508 | /* Read & process EISD record. | |
509 | Return TRUE on success, FALSE on error. */ | |
510 | ||
511 | static bfd_boolean | |
512 | _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset) | |
513 | { | |
514 | int section_count = 0; | |
515 | ||
516 | vms_debug2 ((8, "_bfd_vms_slurp_eisd\n")); | |
517 | ||
518 | while (1) | |
519 | { | |
520 | struct vms_eisd *eisd; | |
521 | unsigned int rec_size; | |
522 | unsigned int size; | |
ce9116fd | 523 | bfd_uint64_t vaddr; |
95e34ef7 TG |
524 | unsigned int flags; |
525 | unsigned int vbn; | |
526 | char *name = NULL; | |
527 | asection *section; | |
528 | flagword bfd_flags; | |
529 | ||
bf31e604 AM |
530 | /* PR 17512: file: 3d9e9fe9. */ |
531 | if (offset > PRIV (recrd.rec_size) | |
532 | || (PRIV (recrd.rec_size) - offset | |
533 | < offsetof (struct vms_eisd, eisdsize) + 4)) | |
5860e3f8 | 534 | return FALSE; |
bf31e604 | 535 | eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset); |
95e34ef7 | 536 | rec_size = bfd_getl32 (eisd->eisdsize); |
95e34ef7 | 537 | if (rec_size == 0) |
07d6d2b8 | 538 | break; |
95e34ef7 TG |
539 | |
540 | /* Skip to next block if pad. */ | |
541 | if (rec_size == 0xffffffff) | |
07d6d2b8 AM |
542 | { |
543 | offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); | |
544 | continue; | |
545 | } | |
7adc0a81 NC |
546 | |
547 | /* Make sure that there is enough data present in the record. */ | |
bf31e604 | 548 | if (rec_size < offsetof (struct vms_eisd, type) + 1) |
7adc0a81 NC |
549 | return FALSE; |
550 | /* Make sure that the record is not too big either. */ | |
bf31e604 | 551 | if (rec_size > PRIV (recrd.rec_size) - offset) |
7adc0a81 NC |
552 | return FALSE; |
553 | ||
554 | offset += rec_size; | |
95e34ef7 TG |
555 | |
556 | size = bfd_getl32 (eisd->secsize); | |
557 | vaddr = bfd_getl64 (eisd->virt_addr); | |
558 | flags = bfd_getl32 (eisd->flags); | |
559 | vbn = bfd_getl32 (eisd->vbn); | |
560 | ||
561 | vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n", | |
07d6d2b8 | 562 | offset, size, (unsigned long)vaddr, flags, vbn)); |
95e34ef7 TG |
563 | |
564 | /* VMS combines psects from .obj files into isects in the .exe. This | |
565 | process doesn't preserve enough information to reliably determine | |
566 | what's in each section without examining the data. This is | |
567 | especially true of DWARF debug sections. */ | |
568 | bfd_flags = SEC_ALLOC; | |
c068d5be | 569 | if (vbn != 0) |
07d6d2b8 | 570 | bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD; |
95e34ef7 TG |
571 | |
572 | if (flags & EISD__M_EXE) | |
c068d5be | 573 | bfd_flags |= SEC_CODE; |
95e34ef7 TG |
574 | |
575 | if (flags & EISD__M_NONSHRADR) | |
c068d5be | 576 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
577 | |
578 | if (!(flags & EISD__M_WRT)) | |
579 | bfd_flags |= SEC_READONLY; | |
580 | ||
581 | if (flags & EISD__M_DZRO) | |
582 | bfd_flags |= SEC_DATA; | |
583 | ||
584 | if (flags & EISD__M_FIXUPVEC) | |
c068d5be | 585 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
586 | |
587 | if (flags & EISD__M_CRF) | |
c068d5be | 588 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
589 | |
590 | if (flags & EISD__M_GBL) | |
591 | { | |
bf31e604 | 592 | if (rec_size <= offsetof (struct vms_eisd, gblnam)) |
7adc0a81 NC |
593 | return FALSE; |
594 | else if (rec_size < sizeof (struct vms_eisd)) | |
37d2e9c7 | 595 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
7adc0a81 NC |
596 | rec_size - offsetof (struct vms_eisd, gblnam)); |
597 | else | |
37d2e9c7 AM |
598 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
599 | EISD__K_GBLNAMLEN); | |
bf31e604 | 600 | if (name == NULL || name[0] == 0) |
37d2e9c7 | 601 | return FALSE; |
95e34ef7 TG |
602 | bfd_flags |= SEC_COFF_SHARED_LIBRARY; |
603 | bfd_flags &= ~(SEC_ALLOC | SEC_LOAD); | |
604 | } | |
605 | else if (flags & EISD__M_FIXUPVEC) | |
07d6d2b8 | 606 | name = "$FIXUPVEC$"; |
95e34ef7 | 607 | else if (eisd->type == EISD__K_USRSTACK) |
07d6d2b8 | 608 | name = "$STACK$"; |
95e34ef7 TG |
609 | else |
610 | { | |
07d6d2b8 | 611 | const char *pfx; |
95e34ef7 | 612 | |
37d2e9c7 AM |
613 | name = (char *) bfd_alloc (abfd, 32); |
614 | if (name == NULL) | |
615 | return FALSE; | |
07d6d2b8 AM |
616 | if (flags & EISD__M_DZRO) |
617 | pfx = "BSS"; | |
618 | else if (flags & EISD__M_EXE) | |
619 | pfx = "CODE"; | |
620 | else if (!(flags & EISD__M_WRT)) | |
621 | pfx = "RO"; | |
622 | else | |
623 | pfx = "LOCAL"; | |
624 | BFD_ASSERT (section_count < 999); | |
95e34ef7 TG |
625 | sprintf (name, "$%s_%03d$", pfx, section_count++); |
626 | } | |
627 | ||
628 | section = bfd_make_section (abfd, name); | |
629 | ||
630 | if (!section) | |
631 | return FALSE; | |
632 | ||
633 | section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0; | |
634 | section->size = size; | |
635 | section->vma = vaddr; | |
636 | ||
fd361982 | 637 | if (!bfd_set_section_flags (section, bfd_flags)) |
95e34ef7 TG |
638 | return FALSE; |
639 | } | |
640 | ||
641 | return TRUE; | |
642 | } | |
643 | ||
644 | /* Read & process EIHS record. | |
645 | Return TRUE on success, FALSE on error. */ | |
646 | ||
647 | static bfd_boolean | |
648 | _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset) | |
649 | { | |
650 | unsigned char *p = PRIV (recrd.rec) + offset; | |
80053e46 NC |
651 | unsigned int gstvbn; |
652 | unsigned int gstsize ATTRIBUTE_UNUSED; | |
653 | unsigned int dstvbn; | |
654 | unsigned int dstsize; | |
655 | unsigned int dmtvbn; | |
656 | unsigned int dmtbytes; | |
95e34ef7 TG |
657 | asection *section; |
658 | ||
80053e46 NC |
659 | /* PR 21611: Check that offset is valid. */ |
660 | if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4)) | |
661 | { | |
38f14ab8 AM |
662 | _bfd_error_handler (_("unable to read EIHS record at offset %#x"), |
663 | offset); | |
80053e46 NC |
664 | bfd_set_error (bfd_error_file_truncated); |
665 | return FALSE; | |
666 | } | |
667 | ||
668 | gstvbn = bfd_getl32 (p + EIHS__L_GSTVBN); | |
669 | gstsize = bfd_getl32 (p + EIHS__L_GSTSIZE); | |
670 | dstvbn = bfd_getl32 (p + EIHS__L_DSTVBN); | |
671 | dstsize = bfd_getl32 (p + EIHS__L_DSTSIZE); | |
672 | dmtvbn = bfd_getl32 (p + EIHS__L_DMTVBN); | |
673 | dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES); | |
674 | ||
95e34ef7 TG |
675 | #if VMS_DEBUG |
676 | vms_debug (8, "_bfd_vms_slurp_ihs\n"); | |
677 | vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n", | |
678 | gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes); | |
679 | #endif | |
680 | ||
681 | if (dstvbn) | |
682 | { | |
683 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; | |
684 | ||
685 | section = bfd_make_section (abfd, "$DST$"); | |
686 | if (!section) | |
687 | return FALSE; | |
688 | ||
689 | section->size = dstsize; | |
690 | section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1); | |
691 | ||
fd361982 | 692 | if (!bfd_set_section_flags (section, bfd_flags)) |
95e34ef7 TG |
693 | return FALSE; |
694 | ||
695 | PRIV (dst_section) = section; | |
696 | abfd->flags |= (HAS_DEBUG | HAS_LINENO); | |
697 | } | |
698 | ||
699 | if (dmtvbn) | |
700 | { | |
701 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; | |
702 | ||
703 | section = bfd_make_section (abfd, "$DMT$"); | |
704 | if (!section) | |
705 | return FALSE; | |
706 | ||
707 | section->size = dmtbytes; | |
708 | section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1); | |
709 | ||
fd361982 | 710 | if (!bfd_set_section_flags (section, bfd_flags)) |
95e34ef7 TG |
711 | return FALSE; |
712 | } | |
713 | ||
714 | if (gstvbn) | |
715 | { | |
95e34ef7 TG |
716 | if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET)) |
717 | { | |
718 | bfd_set_error (bfd_error_file_truncated); | |
719 | return FALSE; | |
720 | } | |
721 | ||
535b785f | 722 | if (!_bfd_vms_slurp_object_records (abfd)) |
95e34ef7 TG |
723 | return FALSE; |
724 | ||
95e34ef7 TG |
725 | abfd->flags |= HAS_SYMS; |
726 | } | |
727 | ||
728 | return TRUE; | |
729 | } | |
730 | \f | |
731 | /* Object file reading. */ | |
732 | ||
733 | /* Object file input functions. */ | |
734 | ||
735 | /* Get next record from object file to vms_buf. | |
736 | Set PRIV(buf_size) and return it | |
737 | ||
738 | This is a little tricky since it should be portable. | |
739 | ||
740 | The openVMS object file has 'variable length' which means that | |
741 | read() returns data in chunks of (hopefully) correct and expected | |
742 | size. The linker (and other tools on VMS) depend on that. Unix | |
743 | doesn't know about 'formatted' files, so reading and writing such | |
744 | an object file in a Unix environment is not trivial. | |
745 | ||
746 | With the tool 'file' (available on all VMS FTP sites), one | |
747 | can view and change the attributes of a file. Changing from | |
748 | 'variable length' to 'fixed length, 512 bytes' reveals the | |
749 | record size at the first 2 bytes of every record. The same | |
750 | may happen during the transfer of object files from VMS to Unix, | |
751 | at least with UCX, the DEC implementation of TCP/IP. | |
752 | ||
753 | The VMS format repeats the size at bytes 2 & 3 of every record. | |
754 | ||
755 | On the first call (file_format == FF_UNKNOWN) we check if | |
756 | the first and the third byte pair (!) of the record match. | |
757 | If they do it's an object file in an Unix environment or with | |
758 | wrong attributes (FF_FOREIGN), else we should be in a VMS | |
759 | environment where read() returns the record size (FF_NATIVE). | |
760 | ||
761 | Reading is always done in 2 steps: | |
762 | 1. first just the record header is read and the size extracted, | |
763 | 2. then the read buffer is adjusted and the remaining bytes are | |
764 | read in. | |
765 | ||
766 | All file I/O is done on even file positions. */ | |
767 | ||
768 | #define VMS_OBJECT_ADJUSTMENT 2 | |
769 | ||
770 | static void | |
771 | maybe_adjust_record_pointer_for_object (bfd *abfd) | |
772 | { | |
773 | /* Set the file format once for all on the first invocation. */ | |
774 | if (PRIV (recrd.file_format) == FF_UNKNOWN) | |
775 | { | |
776 | if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4] | |
777 | && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5]) | |
778 | PRIV (recrd.file_format) = FF_FOREIGN; | |
779 | else | |
780 | PRIV (recrd.file_format) = FF_NATIVE; | |
781 | } | |
782 | ||
783 | /* The adjustment is needed only in an Unix environment. */ | |
784 | if (PRIV (recrd.file_format) == FF_FOREIGN) | |
785 | PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT; | |
786 | } | |
787 | ||
788 | /* Implement step #1 of the object record reading procedure. | |
789 | Return the record type or -1 on failure. */ | |
790 | ||
791 | static int | |
792 | _bfd_vms_get_object_record (bfd *abfd) | |
793 | { | |
ddfb684a | 794 | unsigned int test_len = 6; |
95e34ef7 | 795 | int type; |
95e34ef7 TG |
796 | |
797 | vms_debug2 ((8, "_bfd_vms_get_obj_record\n")); | |
798 | ||
ddfb684a | 799 | /* Skip alignment byte if the current position is odd. */ |
af47dcbf | 800 | if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1)) |
95e34ef7 TG |
801 | { |
802 | if (bfd_bread (PRIV (recrd.buf), 1, abfd) != 1) | |
07d6d2b8 AM |
803 | { |
804 | bfd_set_error (bfd_error_file_truncated); | |
805 | return -1; | |
806 | } | |
95e34ef7 TG |
807 | } |
808 | ||
809 | /* Read the record header */ | |
ddfb684a | 810 | if (bfd_bread (PRIV (recrd.buf), test_len, abfd) != test_len) |
95e34ef7 TG |
811 | { |
812 | bfd_set_error (bfd_error_file_truncated); | |
813 | return -1; | |
814 | } | |
815 | ||
816 | /* Reset the record pointer. */ | |
817 | PRIV (recrd.rec) = PRIV (recrd.buf); | |
818 | maybe_adjust_record_pointer_for_object (abfd); | |
819 | ||
820 | if (vms_get_remaining_object_record (abfd, test_len) <= 0) | |
821 | return -1; | |
822 | ||
823 | type = bfd_getl16 (PRIV (recrd.rec)); | |
824 | ||
825 | vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n", | |
07d6d2b8 | 826 | PRIV (recrd.rec), PRIV (recrd.rec_size), type)); |
95e34ef7 TG |
827 | |
828 | return type; | |
829 | } | |
830 | ||
831 | /* Implement step #2 of the object record reading procedure. | |
832 | Return the size of the record or 0 on failure. */ | |
833 | ||
834 | static int | |
0a9d414a | 835 | vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far) |
95e34ef7 TG |
836 | { |
837 | unsigned int to_read; | |
838 | ||
839 | vms_debug2 ((8, "vms_get_remaining_obj_record\n")); | |
840 | ||
841 | /* Extract record size. */ | |
842 | PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2); | |
843 | ||
083faca9 | 844 | if (PRIV (recrd.rec_size) == 0) |
95e34ef7 TG |
845 | { |
846 | bfd_set_error (bfd_error_file_truncated); | |
847 | return 0; | |
848 | } | |
849 | ||
850 | /* That's what the linker manual says. */ | |
851 | if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ) | |
852 | { | |
853 | bfd_set_error (bfd_error_file_truncated); | |
854 | return 0; | |
855 | } | |
856 | ||
857 | /* Take into account object adjustment. */ | |
858 | to_read = PRIV (recrd.rec_size); | |
859 | if (PRIV (recrd.file_format) == FF_FOREIGN) | |
860 | to_read += VMS_OBJECT_ADJUSTMENT; | |
861 | ||
862 | /* Adjust the buffer. */ | |
863 | if (to_read > PRIV (recrd.buf_size)) | |
864 | { | |
865 | PRIV (recrd.buf) | |
9cb56943 | 866 | = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read); |
95e34ef7 | 867 | if (PRIV (recrd.buf) == NULL) |
07d6d2b8 | 868 | return 0; |
95e34ef7 TG |
869 | PRIV (recrd.buf_size) = to_read; |
870 | } | |
0a9d414a NC |
871 | /* PR 17512: file: 025-1974-0.004. */ |
872 | else if (to_read <= read_so_far) | |
873 | return 0; | |
1b786873 | 874 | |
95e34ef7 TG |
875 | /* Read the remaining record. */ |
876 | to_read -= read_so_far; | |
877 | ||
878 | vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read)); | |
879 | ||
880 | if (bfd_bread (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read) | |
881 | { | |
882 | bfd_set_error (bfd_error_file_truncated); | |
883 | return 0; | |
884 | } | |
885 | ||
886 | /* Reset the record pointer. */ | |
887 | PRIV (recrd.rec) = PRIV (recrd.buf); | |
888 | maybe_adjust_record_pointer_for_object (abfd); | |
889 | ||
890 | vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n", | |
07d6d2b8 | 891 | PRIV (recrd.rec_size))); |
95e34ef7 TG |
892 | |
893 | return PRIV (recrd.rec_size); | |
894 | } | |
895 | ||
896 | /* Read and process emh record. | |
897 | Return TRUE on success, FALSE on error. */ | |
898 | ||
899 | static bfd_boolean | |
900 | _bfd_vms_slurp_ehdr (bfd *abfd) | |
901 | { | |
902 | unsigned char *ptr; | |
903 | unsigned char *vms_rec; | |
4e5cb37e | 904 | unsigned char *end; |
95e34ef7 TG |
905 | int subtype; |
906 | ||
907 | vms_rec = PRIV (recrd.rec); | |
4e5cb37e | 908 | /* PR 17512: file: 62736583. */ |
8bdf0be1 | 909 | end = PRIV (recrd.buf) + PRIV (recrd.buf_size); |
95e34ef7 TG |
910 | |
911 | vms_debug2 ((2, "HDR/EMH\n")); | |
912 | ||
913 | subtype = bfd_getl16 (vms_rec + 4); | |
914 | ||
915 | vms_debug2 ((3, "subtype %d\n", subtype)); | |
916 | ||
917 | switch (subtype) | |
918 | { | |
919 | case EMH__C_MHD: | |
920 | /* Module header. */ | |
4e5cb37e NC |
921 | if (vms_rec + 21 >= end) |
922 | goto fail; | |
95e34ef7 TG |
923 | PRIV (hdr_data).hdr_b_strlvl = vms_rec[6]; |
924 | PRIV (hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8); | |
925 | PRIV (hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12); | |
926 | PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16); | |
4e5cb37e NC |
927 | if ((vms_rec + 20 + vms_rec[20] + 1) >= end) |
928 | goto fail; | |
37d2e9c7 AM |
929 | PRIV (hdr_data).hdr_t_name |
930 | = _bfd_vms_save_counted_string (abfd, vms_rec + 20, vms_rec[20]); | |
95e34ef7 | 931 | ptr = vms_rec + 20 + vms_rec[20] + 1; |
4e5cb37e NC |
932 | if ((ptr + *ptr + 1) >= end) |
933 | goto fail; | |
37d2e9c7 AM |
934 | PRIV (hdr_data).hdr_t_version |
935 | = _bfd_vms_save_counted_string (abfd, ptr, *ptr); | |
95e34ef7 | 936 | ptr += *ptr + 1; |
4e5cb37e NC |
937 | if (ptr + 17 >= end) |
938 | goto fail; | |
37d2e9c7 AM |
939 | PRIV (hdr_data).hdr_t_date |
940 | = _bfd_vms_save_sized_string (abfd, ptr, 17); | |
95e34ef7 TG |
941 | break; |
942 | ||
943 | case EMH__C_LNM: | |
4e5cb37e NC |
944 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
945 | goto fail; | |
37d2e9c7 AM |
946 | PRIV (hdr_data).hdr_c_lnm |
947 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
948 | break; |
949 | ||
950 | case EMH__C_SRC: | |
4e5cb37e NC |
951 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
952 | goto fail; | |
37d2e9c7 AM |
953 | PRIV (hdr_data).hdr_c_src |
954 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
955 | break; |
956 | ||
957 | case EMH__C_TTL: | |
4e5cb37e NC |
958 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
959 | goto fail; | |
37d2e9c7 AM |
960 | PRIV (hdr_data).hdr_c_ttl |
961 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
962 | break; |
963 | ||
964 | case EMH__C_CPR: | |
965 | case EMH__C_MTC: | |
966 | case EMH__C_GTX: | |
967 | break; | |
968 | ||
969 | default: | |
4e5cb37e | 970 | fail: |
95e34ef7 TG |
971 | bfd_set_error (bfd_error_wrong_format); |
972 | return FALSE; | |
973 | } | |
974 | ||
975 | return TRUE; | |
976 | } | |
977 | ||
978 | /* Typical sections for evax object files. */ | |
979 | ||
980 | #define EVAX_ABS_NAME "$ABS$" | |
981 | #define EVAX_CODE_NAME "$CODE$" | |
982 | #define EVAX_LINK_NAME "$LINK$" | |
983 | #define EVAX_DATA_NAME "$DATA$" | |
984 | #define EVAX_BSS_NAME "$BSS$" | |
985 | #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$" | |
986 | #define EVAX_READONLY_NAME "$READONLY$" | |
987 | #define EVAX_LITERAL_NAME "$LITERAL$" | |
988 | #define EVAX_LITERALS_NAME "$LITERALS" | |
989 | #define EVAX_COMMON_NAME "$COMMON$" | |
990 | #define EVAX_LOCAL_NAME "$LOCAL$" | |
991 | ||
992 | struct sec_flags_struct | |
993 | { | |
994 | const char *name; /* Name of section. */ | |
995 | int vflags_always; | |
996 | flagword flags_always; /* Flags we set always. */ | |
997 | int vflags_hassize; | |
998 | flagword flags_hassize; /* Flags we set if the section has a size > 0. */ | |
999 | }; | |
1000 | ||
1001 | /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */ | |
1002 | ||
81bb31c0 | 1003 | static const struct sec_flags_struct evax_section_flags[] = |
95e34ef7 TG |
1004 | { |
1005 | { EVAX_ABS_NAME, | |
d833fa0d TG |
1006 | EGPS__V_SHR, |
1007 | 0, | |
1008 | EGPS__V_SHR, | |
1009 | 0 }, | |
95e34ef7 | 1010 | { EVAX_CODE_NAME, |
d833fa0d | 1011 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
cf6b8767 | 1012 | SEC_CODE | SEC_READONLY, |
d833fa0d | 1013 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
cf6b8767 | 1014 | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1015 | { EVAX_LITERAL_NAME, |
d833fa0d TG |
1016 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1017 | SEC_DATA | SEC_READONLY, | |
1018 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, | |
cf6b8767 | 1019 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1020 | { EVAX_LINK_NAME, |
d833fa0d TG |
1021 | EGPS__V_REL | EGPS__V_RD, |
1022 | SEC_DATA | SEC_READONLY, | |
1023 | EGPS__V_REL | EGPS__V_RD, | |
cf6b8767 | 1024 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1025 | { EVAX_DATA_NAME, |
d833fa0d TG |
1026 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1027 | SEC_DATA, | |
1028 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
1029 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, | |
95e34ef7 | 1030 | { EVAX_BSS_NAME, |
d833fa0d TG |
1031 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1032 | SEC_NO_FLAGS, | |
1033 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, | |
1034 | SEC_ALLOC }, | |
95e34ef7 | 1035 | { EVAX_READONLYADDR_NAME, |
d833fa0d TG |
1036 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, |
1037 | SEC_DATA | SEC_READONLY, | |
1038 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, | |
cf6b8767 | 1039 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1040 | { EVAX_READONLY_NAME, |
d833fa0d TG |
1041 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1042 | SEC_DATA | SEC_READONLY, | |
1043 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, | |
cf6b8767 | 1044 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1045 | { EVAX_LOCAL_NAME, |
d833fa0d TG |
1046 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1047 | SEC_DATA, | |
1048 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
1049 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, | |
95e34ef7 | 1050 | { EVAX_LITERALS_NAME, |
d833fa0d TG |
1051 | EGPS__V_PIC | EGPS__V_OVR, |
1052 | SEC_DATA | SEC_READONLY, | |
1053 | EGPS__V_PIC | EGPS__V_OVR, | |
cf6b8767 | 1054 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1055 | { NULL, |
d833fa0d TG |
1056 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1057 | SEC_DATA, | |
1058 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
8185f55c | 1059 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD } |
95e34ef7 TG |
1060 | }; |
1061 | ||
81bb31c0 | 1062 | /* Retrieve BFD section flags by name and size. */ |
95e34ef7 TG |
1063 | |
1064 | static flagword | |
81bb31c0 TG |
1065 | vms_secflag_by_name (const struct sec_flags_struct *section_flags, |
1066 | const char *name, | |
95e34ef7 TG |
1067 | int hassize) |
1068 | { | |
1069 | int i = 0; | |
1070 | ||
1071 | while (section_flags[i].name != NULL) | |
1072 | { | |
1073 | if (strcmp (name, section_flags[i].name) == 0) | |
07d6d2b8 | 1074 | { |
95e34ef7 TG |
1075 | if (hassize) |
1076 | return section_flags[i].flags_hassize; | |
1077 | else | |
1078 | return section_flags[i].flags_always; | |
1079 | } | |
1080 | i++; | |
1081 | } | |
1082 | if (hassize) | |
1083 | return section_flags[i].flags_hassize; | |
1084 | return section_flags[i].flags_always; | |
1085 | } | |
1086 | ||
81bb31c0 | 1087 | /* Retrieve VMS section flags by name and size. */ |
95e34ef7 TG |
1088 | |
1089 | static flagword | |
81bb31c0 TG |
1090 | vms_esecflag_by_name (const struct sec_flags_struct *section_flags, |
1091 | const char *name, | |
07d6d2b8 | 1092 | int hassize) |
95e34ef7 TG |
1093 | { |
1094 | int i = 0; | |
1095 | ||
1096 | while (section_flags[i].name != NULL) | |
1097 | { | |
1098 | if (strcmp (name, section_flags[i].name) == 0) | |
1099 | { | |
1100 | if (hassize) | |
1101 | return section_flags[i].vflags_hassize; | |
1102 | else | |
1103 | return section_flags[i].vflags_always; | |
1104 | } | |
1105 | i++; | |
1106 | } | |
1107 | if (hassize) | |
1108 | return section_flags[i].vflags_hassize; | |
1109 | return section_flags[i].vflags_always; | |
1110 | } | |
1111 | ||
ce76e55c TG |
1112 | /* Add SYM to the symbol table of ABFD. |
1113 | Return FALSE in case of error. */ | |
95e34ef7 | 1114 | |
ce76e55c TG |
1115 | static bfd_boolean |
1116 | add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym) | |
95e34ef7 | 1117 | { |
95e34ef7 TG |
1118 | if (PRIV (gsd_sym_count) >= PRIV (max_sym_count)) |
1119 | { | |
1120 | if (PRIV (max_sym_count) == 0) | |
07d6d2b8 AM |
1121 | { |
1122 | PRIV (max_sym_count) = 128; | |
1123 | PRIV (syms) = bfd_malloc | |
1124 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)); | |
1125 | } | |
95e34ef7 | 1126 | else |
07d6d2b8 AM |
1127 | { |
1128 | PRIV (max_sym_count) *= 2; | |
9cb56943 | 1129 | PRIV (syms) = bfd_realloc_or_free |
07d6d2b8 AM |
1130 | (PRIV (syms), |
1131 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *))); | |
1132 | } | |
95e34ef7 | 1133 | if (PRIV (syms) == NULL) |
07d6d2b8 | 1134 | return FALSE; |
95e34ef7 TG |
1135 | } |
1136 | ||
ce76e55c TG |
1137 | PRIV (syms)[PRIV (gsd_sym_count)++] = sym; |
1138 | return TRUE; | |
1139 | } | |
1140 | ||
1141 | /* Create a symbol whose name is ASCIC and add it to ABFD. | |
1142 | Return NULL in case of error. */ | |
1143 | ||
1144 | static struct vms_symbol_entry * | |
2c0e48e5 | 1145 | add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max) |
ce76e55c TG |
1146 | { |
1147 | struct vms_symbol_entry *entry; | |
2c0e48e5 | 1148 | unsigned int len; |
ce76e55c TG |
1149 | |
1150 | len = *ascic++; | |
2c0e48e5 AM |
1151 | max -= 1; |
1152 | if (len > max) | |
1153 | { | |
1154 | _bfd_error_handler (_("record is too small for symbol name length")); | |
1155 | bfd_set_error (bfd_error_bad_value); | |
1156 | return NULL; | |
1157 | } | |
1158 | ||
ce76e55c TG |
1159 | entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len); |
1160 | if (entry == NULL) | |
1161 | return NULL; | |
1162 | entry->namelen = len; | |
1163 | memcpy (entry->name, ascic, len); | |
1164 | entry->name[len] = 0; | |
1165 | entry->owner = abfd; | |
1166 | ||
1167 | if (!add_symbol_entry (abfd, entry)) | |
1168 | return NULL; | |
95e34ef7 TG |
1169 | return entry; |
1170 | } | |
1171 | ||
1172 | /* Read and process EGSD. Return FALSE on failure. */ | |
1173 | ||
1174 | static bfd_boolean | |
5fe88cfb | 1175 | _bfd_vms_slurp_egsd (bfd *abfd) |
95e34ef7 | 1176 | { |
72e84f96 NC |
1177 | int gsd_type; |
1178 | unsigned int gsd_size; | |
95e34ef7 | 1179 | unsigned char *vms_rec; |
401e101e | 1180 | bfd_vma base_addr; |
bf31e604 | 1181 | long psindx; |
95e34ef7 TG |
1182 | |
1183 | vms_debug2 ((2, "EGSD\n")); | |
1184 | ||
3de58d95 NC |
1185 | if (PRIV (recrd.rec_size) < 8) |
1186 | { | |
38f14ab8 | 1187 | _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"), |
3de58d95 NC |
1188 | PRIV (recrd.rec_size)); |
1189 | bfd_set_error (bfd_error_bad_value); | |
1190 | return FALSE; | |
1191 | } | |
07d6d2b8 | 1192 | |
95e34ef7 TG |
1193 | PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */ |
1194 | PRIV (recrd.rec_size) -= 8; | |
1195 | ||
1196 | /* Calculate base address for each section. */ | |
401e101e | 1197 | base_addr = 0; |
95e34ef7 | 1198 | |
72e84f96 | 1199 | while (PRIV (recrd.rec_size) > 4) |
95e34ef7 TG |
1200 | { |
1201 | vms_rec = PRIV (recrd.rec); | |
1202 | ||
1203 | gsd_type = bfd_getl16 (vms_rec); | |
1204 | gsd_size = bfd_getl16 (vms_rec + 2); | |
1205 | ||
1206 | vms_debug2 ((3, "egsd_type %d\n", gsd_type)); | |
1207 | ||
72e84f96 NC |
1208 | /* PR 21615: Check for size overflow. */ |
1209 | if (PRIV (recrd.rec_size) < gsd_size) | |
1210 | { | |
bf31e604 AM |
1211 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " |
1212 | "is larger than remaining space (%#x)"), | |
1213 | gsd_type, gsd_size, PRIV (recrd.rec_size)); | |
7adc0a81 NC |
1214 | bfd_set_error (bfd_error_bad_value); |
1215 | return FALSE; | |
1216 | } | |
1217 | ||
b50ef514 AM |
1218 | if (gsd_size < 4) |
1219 | { | |
1220 | too_small: | |
1221 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " | |
1222 | "is too small"), | |
1223 | gsd_type, gsd_size); | |
1224 | bfd_set_error (bfd_error_bad_value); | |
1225 | return FALSE; | |
1226 | } | |
1227 | ||
95e34ef7 TG |
1228 | switch (gsd_type) |
1229 | { | |
1230 | case EGSD__C_PSC: | |
07d6d2b8 | 1231 | /* Program section definition. */ |
95e34ef7 | 1232 | { |
bf31e604 | 1233 | struct vms_egps *egps = (struct vms_egps *) vms_rec; |
07d6d2b8 AM |
1234 | flagword new_flags, vms_flags; |
1235 | asection *section; | |
5fe88cfb | 1236 | |
bf31e604 | 1237 | if (offsetof (struct vms_egps, flags) + 2 > gsd_size) |
b50ef514 | 1238 | goto too_small; |
8185f55c | 1239 | vms_flags = bfd_getl16 (egps->flags); |
21e003e8 | 1240 | |
07d6d2b8 AM |
1241 | if ((vms_flags & EGPS__V_REL) == 0) |
1242 | { | |
1243 | /* Use the global absolute section for all | |
1244 | absolute sections. */ | |
1245 | section = bfd_abs_section_ptr; | |
1246 | } | |
1247 | else | |
1248 | { | |
1249 | char *name; | |
401e101e | 1250 | bfd_vma align_addr; |
bf31e604 | 1251 | size_t left; |
21e003e8 | 1252 | |
bf31e604 AM |
1253 | if (offsetof (struct vms_egps, namlng) >= gsd_size) |
1254 | goto too_small; | |
1255 | left = gsd_size - offsetof (struct vms_egps, namlng); | |
1256 | name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left); | |
1257 | if (name == NULL || name[0] == 0) | |
1258 | return FALSE; | |
21e003e8 | 1259 | |
07d6d2b8 AM |
1260 | section = bfd_make_section (abfd, name); |
1261 | if (!section) | |
1262 | return FALSE; | |
1263 | ||
1264 | section->filepos = 0; | |
1265 | section->size = bfd_getl32 (egps->alloc); | |
401e101e | 1266 | section->alignment_power = egps->align & 31; |
07d6d2b8 AM |
1267 | |
1268 | vms_section_data (section)->flags = vms_flags; | |
1269 | vms_section_data (section)->no_flags = 0; | |
1270 | ||
37d2e9c7 AM |
1271 | new_flags = vms_secflag_by_name (evax_section_flags, |
1272 | section->name, | |
07d6d2b8 AM |
1273 | section->size > 0); |
1274 | if (section->size > 0) | |
1275 | new_flags |= SEC_LOAD; | |
1276 | if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0) | |
1277 | { | |
1278 | /* Set RELOC and HAS_CONTENTS if the section is not | |
1279 | demand-zero and not empty. */ | |
1280 | new_flags |= SEC_HAS_CONTENTS; | |
1281 | if (vms_flags & EGPS__V_REL) | |
1282 | new_flags |= SEC_RELOC; | |
1283 | } | |
1284 | if (vms_flags & EGPS__V_EXE) | |
1285 | { | |
1286 | /* Set CODE if section is executable. */ | |
1287 | new_flags |= SEC_CODE; | |
1288 | new_flags &= ~SEC_DATA; | |
1289 | } | |
fd361982 | 1290 | if (!bfd_set_section_flags (section, new_flags)) |
07d6d2b8 AM |
1291 | return FALSE; |
1292 | ||
1293 | /* Give a non-overlapping vma to non absolute sections. */ | |
401e101e AM |
1294 | align_addr = (bfd_vma) 1 << section->alignment_power; |
1295 | base_addr = (base_addr + align_addr - 1) & -align_addr; | |
1296 | section->vma = base_addr; | |
07d6d2b8 AM |
1297 | base_addr += section->size; |
1298 | } | |
1299 | ||
1300 | /* Append it to the section array. */ | |
1301 | if (PRIV (section_count) >= PRIV (section_max)) | |
1302 | { | |
1303 | if (PRIV (section_max) == 0) | |
1304 | PRIV (section_max) = 16; | |
1305 | else | |
1306 | PRIV (section_max) *= 2; | |
1307 | PRIV (sections) = bfd_realloc_or_free | |
1308 | (PRIV (sections), PRIV (section_max) * sizeof (asection *)); | |
1309 | if (PRIV (sections) == NULL) | |
1310 | return FALSE; | |
1311 | } | |
1312 | ||
1313 | PRIV (sections)[PRIV (section_count)] = section; | |
1314 | PRIV (section_count)++; | |
95e34ef7 TG |
1315 | } |
1316 | break; | |
1317 | ||
1318 | case EGSD__C_SYM: | |
1319 | { | |
2c0e48e5 | 1320 | unsigned int nameoff; |
07d6d2b8 AM |
1321 | struct vms_symbol_entry *entry; |
1322 | struct vms_egsy *egsy = (struct vms_egsy *) vms_rec; | |
1323 | flagword old_flags; | |
95e34ef7 | 1324 | |
bf31e604 AM |
1325 | if (offsetof (struct vms_egsy, flags) + 2 > gsd_size) |
1326 | goto too_small; | |
95e34ef7 TG |
1327 | old_flags = bfd_getl16 (egsy->flags); |
1328 | if (old_flags & EGSY__V_DEF) | |
07d6d2b8 AM |
1329 | nameoff = ESDF__B_NAMLNG; |
1330 | else | |
1331 | nameoff = ESRF__B_NAMLNG; | |
95e34ef7 | 1332 | |
2c0e48e5 | 1333 | if (nameoff >= gsd_size) |
bf31e604 | 1334 | goto too_small; |
2c0e48e5 | 1335 | entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff); |
07d6d2b8 AM |
1336 | if (entry == NULL) |
1337 | return FALSE; | |
95e34ef7 | 1338 | |
07d6d2b8 AM |
1339 | /* Allow only duplicate reference. */ |
1340 | if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF)) | |
1341 | abort (); | |
95e34ef7 | 1342 | |
07d6d2b8 AM |
1343 | if (entry->typ == 0) |
1344 | { | |
1345 | entry->typ = gsd_type; | |
1346 | entry->data_type = egsy->datyp; | |
1347 | entry->flags = old_flags; | |
1348 | } | |
95e34ef7 TG |
1349 | |
1350 | if (old_flags & EGSY__V_DEF) | |
07d6d2b8 | 1351 | { |
bf31e604 | 1352 | struct vms_esdf *esdf = (struct vms_esdf *) vms_rec; |
95e34ef7 TG |
1353 | |
1354 | entry->value = bfd_getl64 (esdf->value); | |
cb06d03a NC |
1355 | if (PRIV (sections) == NULL) |
1356 | return FALSE; | |
ca4cf9b9 NC |
1357 | |
1358 | psindx = bfd_getl32 (esdf->psindx); | |
1359 | /* PR 21813: Check for an out of range index. */ | |
1360 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) | |
1361 | { | |
bf31e604 AM |
1362 | bad_psindx: |
1363 | _bfd_error_handler (_("corrupt EGSD record: its psindx " | |
1364 | "field is too big (%#lx)"), | |
ca4cf9b9 NC |
1365 | psindx); |
1366 | bfd_set_error (bfd_error_bad_value); | |
1367 | return FALSE; | |
1368 | } | |
1369 | entry->section = PRIV (sections)[psindx]; | |
95e34ef7 | 1370 | |
07d6d2b8 AM |
1371 | if (old_flags & EGSY__V_NORM) |
1372 | { | |
1373 | PRIV (norm_sym_count)++; | |
95e34ef7 | 1374 | |
07d6d2b8 | 1375 | entry->code_value = bfd_getl64 (esdf->code_address); |
ca4cf9b9 | 1376 | psindx = bfd_getl32 (esdf->ca_psindx); |
bf31e604 | 1377 | /* PR 21813: Check for an out of range index. */ |
ca4cf9b9 | 1378 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) |
bf31e604 | 1379 | goto bad_psindx; |
07d6d2b8 AM |
1380 | entry->code_section = PRIV (sections)[psindx]; |
1381 | } | |
1382 | } | |
95e34ef7 TG |
1383 | } |
1384 | break; | |
1385 | ||
1386 | case EGSD__C_SYMG: | |
1387 | { | |
07d6d2b8 AM |
1388 | struct vms_symbol_entry *entry; |
1389 | struct vms_egst *egst = (struct vms_egst *)vms_rec; | |
1390 | flagword old_flags; | |
2c0e48e5 | 1391 | unsigned int nameoff = offsetof (struct vms_egst, namlng); |
95e34ef7 TG |
1392 | |
1393 | old_flags = bfd_getl16 (egst->header.flags); | |
95e34ef7 | 1394 | |
2c0e48e5 | 1395 | if (nameoff >= gsd_size) |
bf31e604 | 1396 | goto too_small; |
2c0e48e5 | 1397 | entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff); |
07d6d2b8 AM |
1398 | if (entry == NULL) |
1399 | return FALSE; | |
95e34ef7 | 1400 | |
07d6d2b8 AM |
1401 | entry->typ = gsd_type; |
1402 | entry->data_type = egst->header.datyp; | |
1403 | entry->flags = old_flags; | |
95e34ef7 | 1404 | |
07d6d2b8 | 1405 | entry->symbol_vector = bfd_getl32 (egst->value); |
95e34ef7 | 1406 | |
07d6d2b8 | 1407 | if (old_flags & EGSY__V_REL) |
cb06d03a NC |
1408 | { |
1409 | if (PRIV (sections) == NULL) | |
1410 | return FALSE; | |
ca4cf9b9 NC |
1411 | psindx = bfd_getl32 (egst->psindx); |
1412 | /* PR 21813: Check for an out of range index. */ | |
1413 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) | |
bf31e604 | 1414 | goto bad_psindx; |
ca4cf9b9 | 1415 | entry->section = PRIV (sections)[psindx]; |
cb06d03a | 1416 | } |
07d6d2b8 AM |
1417 | else |
1418 | entry->section = bfd_abs_section_ptr; | |
a928f1d7 | 1419 | |
07d6d2b8 | 1420 | entry->value = bfd_getl64 (egst->lp_2); |
95e34ef7 | 1421 | |
07d6d2b8 AM |
1422 | if (old_flags & EGSY__V_NORM) |
1423 | { | |
1424 | PRIV (norm_sym_count)++; | |
95e34ef7 | 1425 | |
07d6d2b8 AM |
1426 | entry->code_value = bfd_getl64 (egst->lp_1); |
1427 | entry->code_section = bfd_abs_section_ptr; | |
1428 | } | |
1429 | } | |
95e34ef7 TG |
1430 | break; |
1431 | ||
07d6d2b8 AM |
1432 | case EGSD__C_SPSC: |
1433 | case EGSD__C_IDC: | |
1434 | /* Currently ignored. */ | |
1435 | break; | |
95e34ef7 TG |
1436 | case EGSD__C_SYMM: |
1437 | case EGSD__C_SYMV: | |
1438 | default: | |
38f14ab8 | 1439 | _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type); |
95e34ef7 TG |
1440 | bfd_set_error (bfd_error_bad_value); |
1441 | return FALSE; | |
1442 | } | |
1443 | ||
1444 | PRIV (recrd.rec_size) -= gsd_size; | |
1445 | PRIV (recrd.rec) += gsd_size; | |
1446 | } | |
1447 | ||
3de58d95 NC |
1448 | /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ? */ |
1449 | ||
95e34ef7 TG |
1450 | if (PRIV (gsd_sym_count) > 0) |
1451 | abfd->flags |= HAS_SYMS; | |
1452 | ||
1453 | return TRUE; | |
1454 | } | |
1455 | ||
1456 | /* Stack routines for vms ETIR commands. */ | |
1457 | ||
1458 | /* Push value and section index. */ | |
1459 | ||
ab356be7 | 1460 | static bfd_boolean |
95e34ef7 TG |
1461 | _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc) |
1462 | { | |
1463 | vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n", | |
07d6d2b8 | 1464 | (unsigned long)val, reloc, PRIV (stackptr))); |
95e34ef7 TG |
1465 | |
1466 | PRIV (stack[PRIV (stackptr)]).value = val; | |
1467 | PRIV (stack[PRIV (stackptr)]).reloc = reloc; | |
1468 | PRIV (stackptr)++; | |
1469 | if (PRIV (stackptr) >= STACKSIZE) | |
1470 | { | |
1471 | bfd_set_error (bfd_error_bad_value); | |
38f14ab8 | 1472 | _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr)); |
ab356be7 | 1473 | return FALSE; |
95e34ef7 | 1474 | } |
ab356be7 | 1475 | return TRUE; |
95e34ef7 TG |
1476 | } |
1477 | ||
1478 | /* Pop value and section index. */ | |
1479 | ||
ab356be7 | 1480 | static bfd_boolean |
95e34ef7 TG |
1481 | _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel) |
1482 | { | |
1483 | if (PRIV (stackptr) == 0) | |
1484 | { | |
1485 | bfd_set_error (bfd_error_bad_value); | |
38f14ab8 | 1486 | _bfd_error_handler (_("stack underflow in _bfd_vms_pop")); |
ab356be7 | 1487 | return FALSE; |
95e34ef7 TG |
1488 | } |
1489 | PRIV (stackptr)--; | |
1490 | *val = PRIV (stack[PRIV (stackptr)]).value; | |
1491 | *rel = PRIV (stack[PRIV (stackptr)]).reloc; | |
1492 | ||
1493 | vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel)); | |
ab356be7 | 1494 | return TRUE; |
95e34ef7 TG |
1495 | } |
1496 | ||
1497 | /* Routines to fill sections contents during tir/etir read. */ | |
1498 | ||
1499 | /* Initialize image buffer pointer to be filled. */ | |
1500 | ||
1501 | static void | |
1502 | image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info) | |
1503 | { | |
1504 | asection *sec; | |
1505 | ||
1506 | vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect)); | |
1507 | ||
cb06d03a NC |
1508 | if (PRIV (sections) == NULL) |
1509 | return; | |
ca4cf9b9 NC |
1510 | if (sect < 0 || sect >= (int) PRIV (section_count)) |
1511 | return; | |
1512 | ||
95e34ef7 TG |
1513 | sec = PRIV (sections)[sect]; |
1514 | ||
1515 | if (info) | |
1516 | { | |
1517 | /* Reading contents to an output bfd. */ | |
1518 | ||
1519 | if (sec->output_section == NULL) | |
07d6d2b8 AM |
1520 | { |
1521 | /* Section discarded. */ | |
1522 | vms_debug2 ((5, " section %s discarded\n", sec->name)); | |
1523 | ||
1524 | /* This is not used. */ | |
1525 | PRIV (image_section) = NULL; | |
1526 | PRIV (image_offset) = 0; | |
1527 | return; | |
1528 | } | |
95e34ef7 TG |
1529 | PRIV (image_offset) = sec->output_offset + vma; |
1530 | PRIV (image_section) = sec->output_section; | |
1531 | } | |
1532 | else | |
1533 | { | |
1534 | PRIV (image_offset) = vma; | |
1535 | PRIV (image_section) = sec; | |
1536 | } | |
1537 | } | |
1538 | ||
1539 | /* Increment image buffer pointer by offset. */ | |
1540 | ||
1541 | static void | |
1542 | image_inc_ptr (bfd *abfd, bfd_vma offset) | |
1543 | { | |
1544 | vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset)); | |
1545 | ||
1546 | PRIV (image_offset) += offset; | |
1547 | } | |
1548 | ||
1549 | /* Save current DST location counter under specified index. */ | |
1550 | ||
9cb56943 | 1551 | static bfd_boolean |
95e34ef7 TG |
1552 | dst_define_location (bfd *abfd, unsigned int loc) |
1553 | { | |
1554 | vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc)); | |
1555 | ||
f75fbe8a AM |
1556 | if (loc > 1 << 24) |
1557 | { | |
1558 | /* 16M entries ought to be plenty. */ | |
1559 | bfd_set_error (bfd_error_bad_value); | |
1560 | _bfd_error_handler (_("dst_define_location %u too large"), loc); | |
1561 | return FALSE; | |
1562 | } | |
1563 | ||
95e34ef7 TG |
1564 | /* Grow the ptr offset table if necessary. */ |
1565 | if (loc + 1 > PRIV (dst_ptr_offsets_count)) | |
1566 | { | |
9cb56943 AM |
1567 | PRIV (dst_ptr_offsets) |
1568 | = bfd_realloc_or_free (PRIV (dst_ptr_offsets), | |
1569 | (loc + 1) * sizeof (unsigned int)); | |
1570 | if (PRIV (dst_ptr_offsets) == NULL) | |
1571 | return FALSE; | |
95e34ef7 TG |
1572 | PRIV (dst_ptr_offsets_count) = loc + 1; |
1573 | } | |
1574 | ||
1575 | PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset); | |
9cb56943 | 1576 | return TRUE; |
95e34ef7 TG |
1577 | } |
1578 | ||
1579 | /* Restore saved DST location counter from specified index. */ | |
1580 | ||
7bac4137 | 1581 | static bfd_boolean |
95e34ef7 TG |
1582 | dst_restore_location (bfd *abfd, unsigned int loc) |
1583 | { | |
1584 | vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc)); | |
1585 | ||
7bac4137 AM |
1586 | if (loc < PRIV (dst_ptr_offsets_count)) |
1587 | { | |
1588 | PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc]; | |
1589 | return TRUE; | |
1590 | } | |
1591 | return FALSE; | |
95e34ef7 TG |
1592 | } |
1593 | ||
1594 | /* Retrieve saved DST location counter from specified index. */ | |
1595 | ||
7bac4137 AM |
1596 | static bfd_boolean |
1597 | dst_retrieve_location (bfd *abfd, bfd_vma *loc) | |
95e34ef7 | 1598 | { |
7bac4137 | 1599 | vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc)); |
95e34ef7 | 1600 | |
7bac4137 AM |
1601 | if (*loc < PRIV (dst_ptr_offsets_count)) |
1602 | { | |
1603 | *loc = PRIV (dst_ptr_offsets)[*loc]; | |
1604 | return TRUE; | |
1605 | } | |
1606 | return FALSE; | |
95e34ef7 TG |
1607 | } |
1608 | ||
95e34ef7 TG |
1609 | /* Write multiple bytes to section image. */ |
1610 | ||
1611 | static bfd_boolean | |
c53d2e6d | 1612 | image_write (bfd *abfd, unsigned char *ptr, unsigned int size) |
95e34ef7 TG |
1613 | { |
1614 | #if VMS_DEBUG | |
1615 | _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size, | |
07d6d2b8 | 1616 | (long)PRIV (image_offset)); |
95e34ef7 TG |
1617 | #endif |
1618 | ||
95e34ef7 TG |
1619 | if (PRIV (image_section)->contents != NULL) |
1620 | { | |
1621 | asection *sec = PRIV (image_section); | |
8ab484c2 | 1622 | size_t off = PRIV (image_offset); |
95e34ef7 TG |
1623 | |
1624 | /* Check bounds. */ | |
8ab484c2 AM |
1625 | if (off > sec->size |
1626 | || size > sec->size - off) | |
07d6d2b8 AM |
1627 | { |
1628 | bfd_set_error (bfd_error_bad_value); | |
1629 | return FALSE; | |
1630 | } | |
95e34ef7 TG |
1631 | |
1632 | memcpy (sec->contents + off, ptr, size); | |
1633 | } | |
8ab484c2 AM |
1634 | #if VMS_DEBUG |
1635 | _bfd_hexdump (9, ptr, size, 0); | |
1636 | #endif | |
95e34ef7 TG |
1637 | |
1638 | PRIV (image_offset) += size; | |
1639 | return TRUE; | |
1640 | } | |
1641 | ||
1642 | /* Write byte to section image. */ | |
1643 | ||
1644 | static bfd_boolean | |
1645 | image_write_b (bfd * abfd, unsigned int value) | |
1646 | { | |
1647 | unsigned char data[1]; | |
1648 | ||
1649 | vms_debug2 ((6, "image_write_b (%02x)\n", (int) value)); | |
1650 | ||
1651 | *data = value; | |
1652 | ||
1653 | return image_write (abfd, data, sizeof (data)); | |
1654 | } | |
1655 | ||
1656 | /* Write 2-byte word to image. */ | |
1657 | ||
1658 | static bfd_boolean | |
1659 | image_write_w (bfd * abfd, unsigned int value) | |
1660 | { | |
1661 | unsigned char data[2]; | |
1662 | ||
1663 | vms_debug2 ((6, "image_write_w (%04x)\n", (int) value)); | |
1664 | ||
1665 | bfd_putl16 (value, data); | |
1666 | return image_write (abfd, data, sizeof (data)); | |
1667 | } | |
1668 | ||
1669 | /* Write 4-byte long to image. */ | |
1670 | ||
1671 | static bfd_boolean | |
1672 | image_write_l (bfd * abfd, unsigned long value) | |
1673 | { | |
1674 | unsigned char data[4]; | |
1675 | ||
1676 | vms_debug2 ((6, "image_write_l (%08lx)\n", value)); | |
1677 | ||
1678 | bfd_putl32 (value, data); | |
1679 | return image_write (abfd, data, sizeof (data)); | |
1680 | } | |
1681 | ||
1682 | /* Write 8-byte quad to image. */ | |
1683 | ||
1684 | static bfd_boolean | |
1685 | image_write_q (bfd * abfd, bfd_vma value) | |
1686 | { | |
1687 | unsigned char data[8]; | |
1688 | ||
1689 | vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value)); | |
1690 | ||
1691 | bfd_putl64 (value, data); | |
1692 | return image_write (abfd, data, sizeof (data)); | |
1693 | } | |
1694 | \f | |
1695 | static const char * | |
1696 | _bfd_vms_etir_name (int cmd) | |
1697 | { | |
1698 | switch (cmd) | |
1699 | { | |
1700 | case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL"; | |
1701 | case ETIR__C_STA_LW: return "ETIR__C_STA_LW"; | |
1702 | case ETIR__C_STA_QW: return "ETIR__C_STA_QW"; | |
1703 | case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ"; | |
1704 | case ETIR__C_STA_LI: return "ETIR__C_STA_LI"; | |
1705 | case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD"; | |
1706 | case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG"; | |
1707 | case ETIR__C_STO_B: return "ETIR__C_STO_B"; | |
1708 | case ETIR__C_STO_W: return "ETIR__C_STO_W"; | |
1709 | case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL"; | |
1710 | case ETIR__C_STO_CA: return "ETIR__C_STO_CA"; | |
1711 | case ETIR__C_STO_RB: return "ETIR__C_STO_RB"; | |
1712 | case ETIR__C_STO_AB: return "ETIR__C_STO_AB"; | |
1713 | case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF"; | |
1714 | case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM"; | |
1715 | case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR"; | |
1716 | case ETIR__C_STO_LW: return "ETIR__C_STO_LW"; | |
1717 | case ETIR__C_STO_QW: return "ETIR__C_STO_QW"; | |
1718 | case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW"; | |
1719 | case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB"; | |
1720 | case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL"; | |
1721 | case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS"; | |
1722 | case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD"; | |
1723 | case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB"; | |
1724 | case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV"; | |
1725 | case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH"; | |
1726 | case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT"; | |
1727 | case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF"; | |
1728 | case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT"; | |
1729 | case ETIR__C_STC_LP: return "ETIR__C_STC_LP"; | |
1730 | case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL"; | |
1731 | case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA"; | |
1732 | case ETIR__C_STC_PS: return "ETIR__C_STC_PS"; | |
1733 | case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS"; | |
1734 | case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL"; | |
1735 | case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS"; | |
1736 | case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL"; | |
1737 | case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS"; | |
1738 | case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL"; | |
1739 | case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS"; | |
1740 | case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL"; | |
1741 | case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS"; | |
1742 | case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL"; | |
1743 | case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB"; | |
1744 | case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB"; | |
1745 | case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB"; | |
1746 | case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC"; | |
1747 | case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC"; | |
1748 | case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL"; | |
1749 | ||
1750 | default: | |
1751 | /* These names have not yet been added to this switch statement. */ | |
4eca0228 | 1752 | _bfd_error_handler (_("unknown ETIR command %d"), cmd); |
95e34ef7 TG |
1753 | } |
1754 | ||
1755 | return NULL; | |
1756 | } | |
1757 | #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L) | |
1758 | ||
1759 | static void | |
c53d2e6d NC |
1760 | _bfd_vms_get_value (bfd *abfd, |
1761 | const unsigned char *ascic, | |
1762 | const unsigned char *max_ascic, | |
07d6d2b8 AM |
1763 | struct bfd_link_info *info, |
1764 | bfd_vma *vma, | |
1765 | struct alpha_vms_link_hash_entry **hp) | |
95e34ef7 TG |
1766 | { |
1767 | char name[257]; | |
c53d2e6d NC |
1768 | unsigned int len; |
1769 | unsigned int i; | |
95e34ef7 TG |
1770 | struct alpha_vms_link_hash_entry *h; |
1771 | ||
1772 | /* Not linking. Do not try to resolve the symbol. */ | |
1773 | if (info == NULL) | |
1774 | { | |
1775 | *vma = 0; | |
1776 | *hp = NULL; | |
1777 | return; | |
1778 | } | |
1779 | ||
1780 | len = *ascic; | |
c53d2e6d NC |
1781 | if (ascic + len >= max_ascic) |
1782 | { | |
38f14ab8 | 1783 | _bfd_error_handler (_("corrupt vms value")); |
c53d2e6d NC |
1784 | *vma = 0; |
1785 | *hp = NULL; | |
1786 | return; | |
1787 | } | |
1788 | ||
95e34ef7 TG |
1789 | for (i = 0; i < len; i++) |
1790 | name[i] = ascic[i + 1]; | |
1791 | name[i] = 0; | |
1792 | ||
1793 | h = (struct alpha_vms_link_hash_entry *) | |
1794 | bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE); | |
1795 | ||
1796 | *hp = h; | |
1797 | ||
1798 | if (h != NULL | |
1799 | && (h->root.type == bfd_link_hash_defined | |
07d6d2b8 | 1800 | || h->root.type == bfd_link_hash_defweak)) |
95e34ef7 TG |
1801 | *vma = h->root.u.def.value |
1802 | + h->root.u.def.section->output_offset | |
1803 | + h->root.u.def.section->output_section->vma; | |
1804 | else if (h && h->root.type == bfd_link_hash_undefweak) | |
1805 | *vma = 0; | |
1806 | else | |
1807 | { | |
1a72702b AM |
1808 | (*info->callbacks->undefined_symbol) |
1809 | (info, name, abfd, PRIV (image_section), PRIV (image_offset), TRUE); | |
95e34ef7 TG |
1810 | *vma = 0; |
1811 | } | |
1812 | } | |
1813 | ||
1814 | #define RELC_NONE 0 | |
1815 | #define RELC_REL 1 | |
1816 | #define RELC_SHR_BASE 0x10000 | |
1817 | #define RELC_SEC_BASE 0x20000 | |
1818 | #define RELC_MASK 0x0ffff | |
1819 | ||
1820 | static unsigned int | |
1821 | alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h) | |
1822 | { | |
1823 | /* Handle undefined symbols. */ | |
1824 | if (h == NULL || h->sym == NULL) | |
1825 | return RELC_NONE; | |
1826 | ||
1827 | if (h->sym->typ == EGSD__C_SYMG) | |
1828 | { | |
1829 | if (h->sym->flags & EGSY__V_REL) | |
07d6d2b8 | 1830 | return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index); |
95e34ef7 | 1831 | else |
07d6d2b8 AM |
1832 | { |
1833 | /* Can this happen (non-relocatable symg) ? I'd like to see | |
1834 | an example. */ | |
1835 | abort (); | |
1836 | } | |
95e34ef7 TG |
1837 | } |
1838 | if (h->sym->typ == EGSD__C_SYM) | |
1839 | { | |
1840 | if (h->sym->flags & EGSY__V_REL) | |
07d6d2b8 | 1841 | return RELC_REL; |
95e34ef7 | 1842 | else |
07d6d2b8 | 1843 | return RELC_NONE; |
95e34ef7 TG |
1844 | } |
1845 | abort (); | |
1846 | } | |
1847 | ||
1848 | static bfd_vma | |
a928f1d7 | 1849 | alpha_vms_get_sym_value (asection *sect, bfd_vma addr) |
95e34ef7 | 1850 | { |
a928f1d7 | 1851 | return sect->output_section->vma + sect->output_offset + addr; |
95e34ef7 TG |
1852 | } |
1853 | ||
1854 | static bfd_vma | |
1855 | alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info, | |
07d6d2b8 | 1856 | unsigned int rel, bfd_vma vma) |
95e34ef7 | 1857 | { |
cb06d03a NC |
1858 | asection *sec; |
1859 | ||
1860 | if (PRIV (sections) == NULL) | |
1861 | return 0; | |
1862 | ||
1863 | sec = PRIV (sections)[rel & RELC_MASK]; | |
95e34ef7 TG |
1864 | |
1865 | if (info) | |
1866 | { | |
1867 | if (sec->output_section == NULL) | |
07d6d2b8 | 1868 | abort (); |
95e34ef7 TG |
1869 | return vma + sec->output_section->vma + sec->output_offset; |
1870 | } | |
1871 | else | |
1872 | return vma + sec->vma; | |
1873 | } | |
1874 | ||
44273c5b TG |
1875 | /* Read an ETIR record from ABFD. If INFO is not null, put the content into |
1876 | the output section (used during linking). | |
1877 | Return FALSE in case of error. */ | |
1878 | ||
95e34ef7 TG |
1879 | static bfd_boolean |
1880 | _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info) | |
1881 | { | |
1882 | unsigned char *ptr; | |
1883 | unsigned int length; | |
1884 | unsigned char *maxptr; | |
8ab484c2 AM |
1885 | bfd_vma op1 = 0; |
1886 | bfd_vma op2 = 0; | |
1887 | unsigned int rel1 = RELC_NONE; | |
1888 | unsigned int rel2 = RELC_NONE; | |
95e34ef7 TG |
1889 | struct alpha_vms_link_hash_entry *h; |
1890 | ||
1891 | PRIV (recrd.rec) += ETIR__C_HEADER_SIZE; | |
1892 | PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE; | |
1893 | ||
1894 | ptr = PRIV (recrd.rec); | |
1895 | length = PRIV (recrd.rec_size); | |
1896 | maxptr = ptr + length; | |
1897 | ||
1898 | vms_debug2 ((2, "ETIR: %d bytes\n", length)); | |
1899 | ||
1900 | while (ptr < maxptr) | |
1901 | { | |
2c0e48e5 | 1902 | int cmd, cmd_length; |
95e34ef7 | 1903 | |
2c0e48e5 AM |
1904 | if (ptr + 4 > maxptr) |
1905 | goto corrupt_etir; | |
1906 | ||
1907 | cmd = bfd_getl16 (ptr); | |
1908 | cmd_length = bfd_getl16 (ptr + 2); | |
95e34ef7 | 1909 | |
76800cba | 1910 | /* PR 21589 and 21579: Check for a corrupt ETIR record. */ |
2c0e48e5 | 1911 | if (cmd_length < 4 || ptr + cmd_length > maxptr) |
c53d2e6d NC |
1912 | { |
1913 | corrupt_etir: | |
38f14ab8 | 1914 | _bfd_error_handler (_("corrupt ETIR record encountered")); |
c53d2e6d NC |
1915 | bfd_set_error (bfd_error_bad_value); |
1916 | return FALSE; | |
1917 | } | |
2c0e48e5 | 1918 | ptr += 4; |
c53d2e6d | 1919 | |
76800cba NC |
1920 | #if VMS_DEBUG |
1921 | _bfd_vms_debug (4, "etir: %s(%d)\n", | |
07d6d2b8 | 1922 | _bfd_vms_etir_name (cmd), cmd); |
76800cba NC |
1923 | _bfd_hexdump (8, ptr, cmd_length - 4, 0); |
1924 | #endif | |
1925 | ||
95e34ef7 | 1926 | switch (cmd) |
07d6d2b8 AM |
1927 | { |
1928 | /* Stack global | |
1929 | arg: cs symbol name | |
95e34ef7 | 1930 | |
07d6d2b8 AM |
1931 | stack 32 bit value of symbol (high bits set to 0). */ |
1932 | case ETIR__C_STA_GBL: | |
1933 | _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h); | |
ab356be7 AM |
1934 | if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h))) |
1935 | return FALSE; | |
07d6d2b8 | 1936 | break; |
95e34ef7 | 1937 | |
07d6d2b8 AM |
1938 | /* Stack longword |
1939 | arg: lw value | |
95e34ef7 | 1940 | |
07d6d2b8 AM |
1941 | stack 32 bit value, sign extend to 64 bit. */ |
1942 | case ETIR__C_STA_LW: | |
2c0e48e5 | 1943 | if (ptr + 4 > maxptr) |
c53d2e6d | 1944 | goto corrupt_etir; |
ab356be7 AM |
1945 | if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE)) |
1946 | return FALSE; | |
07d6d2b8 | 1947 | break; |
95e34ef7 | 1948 | |
07d6d2b8 AM |
1949 | /* Stack quadword |
1950 | arg: qw value | |
95e34ef7 | 1951 | |
07d6d2b8 AM |
1952 | stack 64 bit value of symbol. */ |
1953 | case ETIR__C_STA_QW: | |
2c0e48e5 | 1954 | if (ptr + 8 > maxptr) |
c53d2e6d | 1955 | goto corrupt_etir; |
ab356be7 AM |
1956 | if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE)) |
1957 | return FALSE; | |
07d6d2b8 | 1958 | break; |
95e34ef7 | 1959 | |
07d6d2b8 AM |
1960 | /* Stack psect base plus quadword offset |
1961 | arg: lw section index | |
1962 | qw signed quadword offset (low 32 bits) | |
95e34ef7 | 1963 | |
07d6d2b8 AM |
1964 | Stack qw argument and section index |
1965 | (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */ | |
1966 | case ETIR__C_STA_PQ: | |
1967 | { | |
1968 | int psect; | |
95e34ef7 | 1969 | |
2c0e48e5 | 1970 | if (ptr + 12 > maxptr) |
c53d2e6d | 1971 | goto corrupt_etir; |
07d6d2b8 AM |
1972 | psect = bfd_getl32 (ptr); |
1973 | if ((unsigned int) psect >= PRIV (section_count)) | |
1974 | { | |
4eca0228 AM |
1975 | _bfd_error_handler (_("bad section index in %s"), |
1976 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
1977 | bfd_set_error (bfd_error_bad_value); |
1978 | return FALSE; | |
1979 | } | |
1980 | op1 = bfd_getl64 (ptr + 4); | |
ab356be7 AM |
1981 | if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE)) |
1982 | return FALSE; | |
07d6d2b8 AM |
1983 | } |
1984 | break; | |
1985 | ||
1986 | case ETIR__C_STA_LI: | |
1987 | case ETIR__C_STA_MOD: | |
1988 | case ETIR__C_STA_CKARG: | |
4eca0228 AM |
1989 | _bfd_error_handler (_("unsupported STA cmd %s"), |
1990 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
1991 | return FALSE; |
1992 | break; | |
1993 | ||
1994 | /* Store byte: pop stack, write byte | |
1995 | arg: -. */ | |
1996 | case ETIR__C_STO_B: | |
ab356be7 AM |
1997 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
1998 | return FALSE; | |
07d6d2b8 AM |
1999 | if (rel1 != RELC_NONE) |
2000 | goto bad_context; | |
2001 | image_write_b (abfd, (unsigned int) op1 & 0xff); | |
2002 | break; | |
2003 | ||
2004 | /* Store word: pop stack, write word | |
2005 | arg: -. */ | |
2006 | case ETIR__C_STO_W: | |
ab356be7 AM |
2007 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2008 | return FALSE; | |
07d6d2b8 AM |
2009 | if (rel1 != RELC_NONE) |
2010 | goto bad_context; | |
2011 | image_write_w (abfd, (unsigned int) op1 & 0xffff); | |
2012 | break; | |
2013 | ||
2014 | /* Store longword: pop stack, write longword | |
2015 | arg: -. */ | |
2016 | case ETIR__C_STO_LW: | |
ab356be7 AM |
2017 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2018 | return FALSE; | |
07d6d2b8 AM |
2019 | if (rel1 & RELC_SEC_BASE) |
2020 | { | |
2021 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2022 | rel1 = RELC_REL; | |
2023 | } | |
2024 | else if (rel1 & RELC_SHR_BASE) | |
2025 | { | |
96d3b80f AM |
2026 | if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1)) |
2027 | return FALSE; | |
07d6d2b8 AM |
2028 | rel1 = RELC_NONE; |
2029 | } | |
2030 | if (rel1 != RELC_NONE) | |
2031 | { | |
2032 | if (rel1 != RELC_REL) | |
2033 | abort (); | |
96d3b80f AM |
2034 | if (!alpha_vms_add_lw_reloc (info)) |
2035 | return FALSE; | |
07d6d2b8 AM |
2036 | } |
2037 | image_write_l (abfd, op1); | |
2038 | break; | |
2039 | ||
2040 | /* Store quadword: pop stack, write quadword | |
2041 | arg: -. */ | |
2042 | case ETIR__C_STO_QW: | |
ab356be7 AM |
2043 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2044 | return FALSE; | |
07d6d2b8 AM |
2045 | if (rel1 & RELC_SEC_BASE) |
2046 | { | |
2047 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2048 | rel1 = RELC_REL; | |
2049 | } | |
2050 | else if (rel1 & RELC_SHR_BASE) | |
2051 | abort (); | |
2052 | if (rel1 != RELC_NONE) | |
2053 | { | |
2054 | if (rel1 != RELC_REL) | |
2055 | abort (); | |
96d3b80f AM |
2056 | if (!alpha_vms_add_qw_reloc (info)) |
2057 | return FALSE; | |
07d6d2b8 AM |
2058 | } |
2059 | image_write_q (abfd, op1); | |
2060 | break; | |
2061 | ||
2062 | /* Store immediate repeated: pop stack for repeat count | |
2063 | arg: lw byte count | |
2064 | da data. */ | |
2065 | case ETIR__C_STO_IMMR: | |
2066 | { | |
2067 | int size; | |
95e34ef7 | 2068 | |
2c0e48e5 | 2069 | if (ptr + 4 > maxptr) |
c53d2e6d | 2070 | goto corrupt_etir; |
07d6d2b8 | 2071 | size = bfd_getl32 (ptr); |
ab356be7 AM |
2072 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2073 | return FALSE; | |
07d6d2b8 AM |
2074 | if (rel1 != RELC_NONE) |
2075 | goto bad_context; | |
2076 | while (op1-- > 0) | |
2077 | image_write (abfd, ptr + 4, size); | |
2078 | } | |
2079 | break; | |
2080 | ||
2081 | /* Store global: write symbol value | |
2082 | arg: cs global symbol name. */ | |
2083 | case ETIR__C_STO_GBL: | |
2084 | _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h); | |
2085 | if (h && h->sym) | |
2086 | { | |
2087 | if (h->sym->typ == EGSD__C_SYMG) | |
2088 | { | |
96d3b80f AM |
2089 | if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner, |
2090 | h->sym->symbol_vector)) | |
2091 | return FALSE; | |
07d6d2b8 AM |
2092 | op1 = 0; |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | op1 = alpha_vms_get_sym_value (h->sym->section, | |
2097 | h->sym->value); | |
96d3b80f AM |
2098 | if (!alpha_vms_add_qw_reloc (info)) |
2099 | return FALSE; | |
07d6d2b8 AM |
2100 | } |
2101 | } | |
2102 | image_write_q (abfd, op1); | |
2103 | break; | |
2104 | ||
2105 | /* Store code address: write address of entry point | |
2106 | arg: cs global symbol name (procedure). */ | |
2107 | case ETIR__C_STO_CA: | |
2108 | _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h); | |
2109 | if (h && h->sym) | |
2110 | { | |
2111 | if (h->sym->flags & EGSY__V_NORM) | |
2112 | { | |
2113 | /* That's really a procedure. */ | |
2114 | if (h->sym->typ == EGSD__C_SYMG) | |
2115 | { | |
96d3b80f AM |
2116 | if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner)) |
2117 | return FALSE; | |
07d6d2b8 AM |
2118 | op1 = h->sym->symbol_vector; |
2119 | } | |
2120 | else | |
2121 | { | |
2122 | op1 = alpha_vms_get_sym_value (h->sym->code_section, | |
2123 | h->sym->code_value); | |
96d3b80f AM |
2124 | if (!alpha_vms_add_qw_reloc (info)) |
2125 | return FALSE; | |
07d6d2b8 AM |
2126 | } |
2127 | } | |
2128 | else | |
2129 | { | |
2130 | /* Symbol is not a procedure. */ | |
2131 | abort (); | |
2132 | } | |
2133 | } | |
2134 | image_write_q (abfd, op1); | |
2135 | break; | |
2136 | ||
2137 | /* Store offset to psect: pop stack, add low 32 bits to base of psect | |
2138 | arg: none. */ | |
2139 | case ETIR__C_STO_OFF: | |
ab356be7 AM |
2140 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2141 | return FALSE; | |
07d6d2b8 AM |
2142 | |
2143 | if (!(rel1 & RELC_SEC_BASE)) | |
2144 | abort (); | |
2145 | ||
2146 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2147 | rel1 = RELC_REL; | |
2148 | image_write_q (abfd, op1); | |
2149 | break; | |
2150 | ||
2151 | /* Store immediate | |
2152 | arg: lw count of bytes | |
2153 | da data. */ | |
2154 | case ETIR__C_STO_IMM: | |
2155 | { | |
2156 | unsigned int size; | |
95e34ef7 | 2157 | |
2c0e48e5 | 2158 | if (ptr + 4 > maxptr) |
c53d2e6d | 2159 | goto corrupt_etir; |
07d6d2b8 AM |
2160 | size = bfd_getl32 (ptr); |
2161 | image_write (abfd, ptr + 4, size); | |
2162 | } | |
2163 | break; | |
2164 | ||
2165 | /* This code is 'reserved to digital' according to the openVMS | |
2166 | linker manual, however it is generated by the DEC C compiler | |
2167 | and defined in the include file. | |
2168 | FIXME, since the following is just a guess | |
2169 | store global longword: store 32bit value of symbol | |
2170 | arg: cs symbol name. */ | |
2171 | case ETIR__C_STO_GBL_LW: | |
2172 | _bfd_vms_get_value (abfd, ptr, maxptr, info, &op1, &h); | |
95e34ef7 | 2173 | #if 0 |
07d6d2b8 | 2174 | abort (); |
95e34ef7 | 2175 | #endif |
07d6d2b8 AM |
2176 | image_write_l (abfd, op1); |
2177 | break; | |
95e34ef7 | 2178 | |
07d6d2b8 AM |
2179 | case ETIR__C_STO_RB: |
2180 | case ETIR__C_STO_AB: | |
2181 | case ETIR__C_STO_LP_PSB: | |
4eca0228 AM |
2182 | _bfd_error_handler (_("%s: not supported"), |
2183 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
2184 | return FALSE; |
2185 | break; | |
2186 | case ETIR__C_STO_HINT_GBL: | |
2187 | case ETIR__C_STO_HINT_PS: | |
4eca0228 AM |
2188 | _bfd_error_handler (_("%s: not implemented"), |
2189 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
2190 | return FALSE; |
2191 | break; | |
95e34ef7 | 2192 | |
07d6d2b8 AM |
2193 | /* 200 Store-conditional Linkage Pair |
2194 | arg: none. */ | |
2195 | case ETIR__C_STC_LP: | |
95e34ef7 | 2196 | |
07d6d2b8 AM |
2197 | /* 202 Store-conditional Address at global address |
2198 | lw linkage index | |
2199 | cs global name. */ | |
95e34ef7 | 2200 | |
07d6d2b8 | 2201 | case ETIR__C_STC_GBL: |
95e34ef7 | 2202 | |
07d6d2b8 AM |
2203 | /* 203 Store-conditional Code Address at global address |
2204 | lw linkage index | |
2205 | cs procedure name. */ | |
2206 | case ETIR__C_STC_GCA: | |
95e34ef7 | 2207 | |
07d6d2b8 AM |
2208 | /* 204 Store-conditional Address at psect + offset |
2209 | lw linkage index | |
2210 | lw psect index | |
2211 | qw offset. */ | |
2212 | case ETIR__C_STC_PS: | |
4eca0228 AM |
2213 | _bfd_error_handler (_("%s: not supported"), |
2214 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
2215 | return FALSE; |
2216 | break; | |
2217 | ||
2218 | /* 201 Store-conditional Linkage Pair with Procedure Signature | |
2219 | lw linkage index | |
2220 | cs procedure name | |
2221 | by signature length | |
2222 | da signature. */ | |
2223 | ||
2224 | case ETIR__C_STC_LP_PSB: | |
2225 | _bfd_vms_get_value (abfd, ptr + 4, maxptr, info, &op1, &h); | |
2226 | if (h && h->sym) | |
2227 | { | |
2228 | if (h->sym->typ == EGSD__C_SYMG) | |
2229 | { | |
96d3b80f AM |
2230 | if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner)) |
2231 | return FALSE; | |
07d6d2b8 AM |
2232 | op1 = h->sym->symbol_vector; |
2233 | op2 = 0; | |
2234 | } | |
2235 | else | |
2236 | { | |
2237 | op1 = alpha_vms_get_sym_value (h->sym->code_section, | |
2238 | h->sym->code_value); | |
2239 | op2 = alpha_vms_get_sym_value (h->sym->section, | |
2240 | h->sym->value); | |
2241 | } | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | /* Undefined symbol. */ | |
2246 | op1 = 0; | |
2247 | op2 = 0; | |
2248 | } | |
2249 | image_write_q (abfd, op1); | |
2250 | image_write_q (abfd, op2); | |
2251 | break; | |
2252 | ||
2253 | /* 205 Store-conditional NOP at address of global | |
2254 | arg: none. */ | |
2255 | case ETIR__C_STC_NOP_GBL: | |
2256 | /* ALPHA_R_NOP */ | |
2257 | ||
2258 | /* 207 Store-conditional BSR at global address | |
2259 | arg: none. */ | |
2260 | ||
2261 | case ETIR__C_STC_BSR_GBL: | |
2262 | /* ALPHA_R_BSR */ | |
2263 | ||
2264 | /* 209 Store-conditional LDA at global address | |
2265 | arg: none. */ | |
2266 | ||
2267 | case ETIR__C_STC_LDA_GBL: | |
2268 | /* ALPHA_R_LDA */ | |
2269 | ||
2270 | /* 211 Store-conditional BSR or Hint at global address | |
2271 | arg: none. */ | |
2272 | ||
2273 | case ETIR__C_STC_BOH_GBL: | |
2274 | /* Currentl ignored. */ | |
2275 | break; | |
2276 | ||
2277 | /* 213 Store-conditional NOP,BSR or HINT at global address | |
2278 | arg: none. */ | |
2279 | ||
2280 | case ETIR__C_STC_NBH_GBL: | |
2281 | ||
2282 | /* 206 Store-conditional NOP at pect + offset | |
2283 | arg: none. */ | |
2284 | ||
2285 | case ETIR__C_STC_NOP_PS: | |
2286 | ||
2287 | /* 208 Store-conditional BSR at pect + offset | |
2288 | arg: none. */ | |
2289 | ||
2290 | case ETIR__C_STC_BSR_PS: | |
2291 | ||
2292 | /* 210 Store-conditional LDA at psect + offset | |
2293 | arg: none. */ | |
2294 | ||
2295 | case ETIR__C_STC_LDA_PS: | |
2296 | ||
2297 | /* 212 Store-conditional BSR or Hint at pect + offset | |
2298 | arg: none. */ | |
2299 | ||
2300 | case ETIR__C_STC_BOH_PS: | |
2301 | ||
2302 | /* 214 Store-conditional NOP, BSR or HINT at psect + offset | |
2303 | arg: none. */ | |
2304 | case ETIR__C_STC_NBH_PS: | |
695344c0 | 2305 | _bfd_error_handler (_("%s: not supported"), |
4eca0228 | 2306 | _bfd_vms_etir_name (cmd)); |
07d6d2b8 AM |
2307 | return FALSE; |
2308 | break; | |
2309 | ||
2310 | /* Det relocation base: pop stack, set image location counter | |
2311 | arg: none. */ | |
2312 | case ETIR__C_CTL_SETRB: | |
ab356be7 AM |
2313 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2314 | return FALSE; | |
07d6d2b8 AM |
2315 | if (!(rel1 & RELC_SEC_BASE)) |
2316 | abort (); | |
2317 | image_set_ptr (abfd, op1, rel1 & RELC_MASK, info); | |
2318 | break; | |
2319 | ||
2320 | /* Augment relocation base: increment image location counter by offset | |
2321 | arg: lw offset value. */ | |
2322 | case ETIR__C_CTL_AUGRB: | |
2c0e48e5 | 2323 | if (ptr + 4 > maxptr) |
c53d2e6d | 2324 | goto corrupt_etir; |
07d6d2b8 AM |
2325 | op1 = bfd_getl32 (ptr); |
2326 | image_inc_ptr (abfd, op1); | |
2327 | break; | |
2328 | ||
2329 | /* Define location: pop index, save location counter under index | |
2330 | arg: none. */ | |
2331 | case ETIR__C_CTL_DFLOC: | |
ab356be7 AM |
2332 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2333 | return FALSE; | |
07d6d2b8 AM |
2334 | if (rel1 != RELC_NONE) |
2335 | goto bad_context; | |
9cb56943 AM |
2336 | if (!dst_define_location (abfd, op1)) |
2337 | return FALSE; | |
07d6d2b8 AM |
2338 | break; |
2339 | ||
2340 | /* Set location: pop index, restore location counter from index | |
2341 | arg: none. */ | |
2342 | case ETIR__C_CTL_STLOC: | |
ab356be7 AM |
2343 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2344 | return FALSE; | |
07d6d2b8 AM |
2345 | if (rel1 != RELC_NONE) |
2346 | goto bad_context; | |
7bac4137 AM |
2347 | if (!dst_restore_location (abfd, op1)) |
2348 | { | |
2349 | bfd_set_error (bfd_error_bad_value); | |
2350 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC"); | |
2351 | return FALSE; | |
2352 | } | |
07d6d2b8 AM |
2353 | break; |
2354 | ||
2355 | /* Stack defined location: pop index, push location counter from index | |
2356 | arg: none. */ | |
2357 | case ETIR__C_CTL_STKDL: | |
ab356be7 AM |
2358 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2359 | return FALSE; | |
07d6d2b8 AM |
2360 | if (rel1 != RELC_NONE) |
2361 | goto bad_context; | |
7bac4137 AM |
2362 | if (!dst_retrieve_location (abfd, &op1)) |
2363 | { | |
2364 | bfd_set_error (bfd_error_bad_value); | |
2365 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL"); | |
2366 | return FALSE; | |
2367 | } | |
2368 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) | |
ab356be7 | 2369 | return FALSE; |
07d6d2b8 AM |
2370 | break; |
2371 | ||
2372 | case ETIR__C_OPR_NOP: /* No-op. */ | |
2373 | break; | |
2374 | ||
2375 | case ETIR__C_OPR_ADD: /* Add. */ | |
ab356be7 AM |
2376 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2377 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2378 | return FALSE; | |
07d6d2b8 AM |
2379 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2380 | rel1 = rel2; | |
2381 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) | |
2382 | goto bad_context; | |
ab356be7 AM |
2383 | if (!_bfd_vms_push (abfd, op1 + op2, rel1)) |
2384 | return FALSE; | |
07d6d2b8 AM |
2385 | break; |
2386 | ||
2387 | case ETIR__C_OPR_SUB: /* Subtract. */ | |
ab356be7 AM |
2388 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2389 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2390 | return FALSE; | |
07d6d2b8 AM |
2391 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2392 | rel1 = rel2; | |
2393 | else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE)) | |
2394 | { | |
2395 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2396 | op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2); | |
2397 | rel1 = RELC_NONE; | |
2398 | } | |
2399 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) | |
2400 | goto bad_context; | |
ab356be7 AM |
2401 | if (!_bfd_vms_push (abfd, op2 - op1, rel1)) |
2402 | return FALSE; | |
07d6d2b8 AM |
2403 | break; |
2404 | ||
2405 | case ETIR__C_OPR_MUL: /* Multiply. */ | |
ab356be7 AM |
2406 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2407 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2408 | return FALSE; | |
07d6d2b8 AM |
2409 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2410 | goto bad_context; | |
ab356be7 AM |
2411 | if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE)) |
2412 | return FALSE; | |
07d6d2b8 AM |
2413 | break; |
2414 | ||
2415 | case ETIR__C_OPR_DIV: /* Divide. */ | |
ab356be7 AM |
2416 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2417 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2418 | return FALSE; | |
07d6d2b8 AM |
2419 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2420 | goto bad_context; | |
2421 | if (op2 == 0) | |
ab356be7 AM |
2422 | { |
2423 | if (!_bfd_vms_push (abfd, 0, RELC_NONE)) | |
2424 | return FALSE; | |
2425 | } | |
07d6d2b8 | 2426 | else |
ab356be7 AM |
2427 | { |
2428 | if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE)) | |
2429 | return FALSE; | |
2430 | } | |
07d6d2b8 AM |
2431 | break; |
2432 | ||
2433 | case ETIR__C_OPR_AND: /* Logical AND. */ | |
ab356be7 AM |
2434 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2435 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2436 | return FALSE; | |
07d6d2b8 AM |
2437 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2438 | goto bad_context; | |
ab356be7 AM |
2439 | if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE)) |
2440 | return FALSE; | |
07d6d2b8 AM |
2441 | break; |
2442 | ||
2443 | case ETIR__C_OPR_IOR: /* Logical inclusive OR. */ | |
ab356be7 AM |
2444 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2445 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2446 | return FALSE; | |
07d6d2b8 AM |
2447 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2448 | goto bad_context; | |
ab356be7 AM |
2449 | if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE)) |
2450 | return FALSE; | |
07d6d2b8 AM |
2451 | break; |
2452 | ||
2453 | case ETIR__C_OPR_EOR: /* Logical exclusive OR. */ | |
ab356be7 AM |
2454 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2455 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2456 | return FALSE; | |
07d6d2b8 AM |
2457 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2458 | goto bad_context; | |
ab356be7 AM |
2459 | if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE)) |
2460 | return FALSE; | |
07d6d2b8 AM |
2461 | break; |
2462 | ||
2463 | case ETIR__C_OPR_NEG: /* Negate. */ | |
ab356be7 AM |
2464 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2465 | return FALSE; | |
07d6d2b8 AM |
2466 | if (rel1 != RELC_NONE) |
2467 | goto bad_context; | |
ab356be7 AM |
2468 | if (!_bfd_vms_push (abfd, -op1, RELC_NONE)) |
2469 | return FALSE; | |
07d6d2b8 AM |
2470 | break; |
2471 | ||
2472 | case ETIR__C_OPR_COM: /* Complement. */ | |
ab356be7 AM |
2473 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2474 | return FALSE; | |
07d6d2b8 AM |
2475 | if (rel1 != RELC_NONE) |
2476 | goto bad_context; | |
ab356be7 AM |
2477 | if (!_bfd_vms_push (abfd, ~op1, RELC_NONE)) |
2478 | return FALSE; | |
07d6d2b8 AM |
2479 | break; |
2480 | ||
2481 | case ETIR__C_OPR_ASH: /* Arithmetic shift. */ | |
ab356be7 AM |
2482 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2483 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2484 | return FALSE; | |
07d6d2b8 AM |
2485 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2486 | { | |
2487 | bad_context: | |
4eca0228 AM |
2488 | _bfd_error_handler (_("invalid use of %s with contexts"), |
2489 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
2490 | return FALSE; |
2491 | } | |
2492 | if ((int)op2 < 0) /* Shift right. */ | |
2493 | op1 >>= -(int)op2; | |
2494 | else /* Shift left. */ | |
2495 | op1 <<= (int)op2; | |
ab356be7 AM |
2496 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym. */ |
2497 | return FALSE; | |
07d6d2b8 AM |
2498 | break; |
2499 | ||
2500 | case ETIR__C_OPR_INSV: /* Insert field. */ | |
2501 | case ETIR__C_OPR_USH: /* Unsigned shift. */ | |
2502 | case ETIR__C_OPR_ROT: /* Rotate. */ | |
2503 | case ETIR__C_OPR_REDEF: /* Redefine symbol to current location. */ | |
2504 | case ETIR__C_OPR_DFLIT: /* Define a literal. */ | |
4eca0228 AM |
2505 | _bfd_error_handler (_("%s: not supported"), |
2506 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 AM |
2507 | return FALSE; |
2508 | break; | |
2509 | ||
2510 | case ETIR__C_OPR_SEL: /* Select. */ | |
ab356be7 AM |
2511 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
2512 | return FALSE; | |
07d6d2b8 | 2513 | if (op1 & 0x01L) |
ab356be7 AM |
2514 | { |
2515 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) | |
2516 | return FALSE; | |
2517 | } | |
07d6d2b8 AM |
2518 | else |
2519 | { | |
ab356be7 AM |
2520 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2521 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
2522 | return FALSE; | |
2523 | if (!_bfd_vms_push (abfd, op1, rel1)) | |
2524 | return FALSE; | |
07d6d2b8 AM |
2525 | } |
2526 | break; | |
2527 | ||
2528 | default: | |
4eca0228 | 2529 | _bfd_error_handler (_("reserved cmd %d"), cmd); |
07d6d2b8 AM |
2530 | return FALSE; |
2531 | break; | |
2532 | } | |
95e34ef7 TG |
2533 | |
2534 | ptr += cmd_length - 4; | |
2535 | } | |
2536 | ||
2537 | return TRUE; | |
2538 | } | |
2539 | ||
2540 | /* Process EDBG/ETBT record. | |
2541 | Return TRUE on success, FALSE on error */ | |
2542 | ||
2543 | static bfd_boolean | |
2544 | vms_slurp_debug (bfd *abfd) | |
2545 | { | |
2546 | asection *section = PRIV (dst_section); | |
2547 | ||
2548 | if (section == NULL) | |
2549 | { | |
2550 | /* We have no way to find out beforehand how much debug info there | |
2551 | is in an object file, so pick an initial amount and grow it as | |
2552 | needed later. */ | |
2553 | flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC | |
07d6d2b8 | 2554 | | SEC_IN_MEMORY; |
95e34ef7 TG |
2555 | |
2556 | section = bfd_make_section (abfd, "$DST$"); | |
2557 | if (!section) | |
2558 | return FALSE; | |
fd361982 | 2559 | if (!bfd_set_section_flags (section, flags)) |
95e34ef7 TG |
2560 | return FALSE; |
2561 | PRIV (dst_section) = section; | |
2562 | } | |
2563 | ||
2564 | PRIV (image_section) = section; | |
2565 | PRIV (image_offset) = section->size; | |
95e34ef7 TG |
2566 | |
2567 | if (!_bfd_vms_slurp_etir (abfd, NULL)) | |
2568 | return FALSE; | |
2569 | ||
44273c5b | 2570 | section->size = PRIV (image_offset); |
95e34ef7 TG |
2571 | return TRUE; |
2572 | } | |
2573 | ||
2574 | /* Process EDBG record. | |
2575 | Return TRUE on success, FALSE on error. */ | |
2576 | ||
2577 | static bfd_boolean | |
2578 | _bfd_vms_slurp_edbg (bfd *abfd) | |
2579 | { | |
2580 | vms_debug2 ((2, "EDBG\n")); | |
2581 | ||
44273c5b | 2582 | abfd->flags |= HAS_DEBUG | HAS_LINENO; |
95e34ef7 TG |
2583 | |
2584 | return vms_slurp_debug (abfd); | |
2585 | } | |
2586 | ||
2587 | /* Process ETBT record. | |
2588 | Return TRUE on success, FALSE on error. */ | |
2589 | ||
2590 | static bfd_boolean | |
2591 | _bfd_vms_slurp_etbt (bfd *abfd) | |
2592 | { | |
2593 | vms_debug2 ((2, "ETBT\n")); | |
2594 | ||
2595 | abfd->flags |= HAS_LINENO; | |
2596 | ||
2597 | return vms_slurp_debug (abfd); | |
2598 | } | |
2599 | ||
2600 | /* Process EEOM record. | |
2601 | Return TRUE on success, FALSE on error. */ | |
2602 | ||
2603 | static bfd_boolean | |
2604 | _bfd_vms_slurp_eeom (bfd *abfd) | |
2605 | { | |
2606 | struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec); | |
2607 | ||
2608 | vms_debug2 ((2, "EEOM\n")); | |
2609 | ||
ca4cf9b9 NC |
2610 | /* PR 21813: Check for an undersized record. */ |
2611 | if (PRIV (recrd.buf_size) < sizeof (* eeom)) | |
2612 | { | |
38f14ab8 | 2613 | _bfd_error_handler (_("corrupt EEOM record - size is too small")); |
ca4cf9b9 NC |
2614 | bfd_set_error (bfd_error_bad_value); |
2615 | return FALSE; | |
2616 | } | |
2617 | ||
95e34ef7 TG |
2618 | PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps); |
2619 | PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod); | |
2620 | if (PRIV (eom_data).eom_w_comcod > 1) | |
2621 | { | |
38f14ab8 | 2622 | _bfd_error_handler (_("object module not error-free !")); |
95e34ef7 TG |
2623 | bfd_set_error (bfd_error_bad_value); |
2624 | return FALSE; | |
2625 | } | |
2626 | ||
2627 | PRIV (eom_data).eom_has_transfer = FALSE; | |
2628 | if (PRIV (recrd.rec_size) > 10) | |
2629 | { | |
2630 | PRIV (eom_data).eom_has_transfer = TRUE; | |
2631 | PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg; | |
2632 | PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx); | |
2633 | PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr); | |
2634 | ||
2635 | abfd->start_address = PRIV (eom_data).eom_l_tfradr; | |
2636 | } | |
2637 | return TRUE; | |
2638 | } | |
2639 | ||
2640 | /* Slurp an ordered set of VMS object records. Return FALSE on error. */ | |
2641 | ||
2642 | static bfd_boolean | |
2643 | _bfd_vms_slurp_object_records (bfd * abfd) | |
2644 | { | |
f75fbe8a | 2645 | bfd_boolean ok; |
44273c5b | 2646 | int type; |
95e34ef7 TG |
2647 | |
2648 | do | |
2649 | { | |
2650 | vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd))); | |
2651 | ||
44273c5b TG |
2652 | type = _bfd_vms_get_object_record (abfd); |
2653 | if (type < 0) | |
95e34ef7 TG |
2654 | { |
2655 | vms_debug2 ((2, "next_record failed\n")); | |
2656 | return FALSE; | |
2657 | } | |
2658 | ||
95e34ef7 TG |
2659 | switch (type) |
2660 | { | |
07d6d2b8 | 2661 | case EOBJ__C_EMH: |
f75fbe8a | 2662 | ok = _bfd_vms_slurp_ehdr (abfd); |
07d6d2b8 AM |
2663 | break; |
2664 | case EOBJ__C_EEOM: | |
f75fbe8a | 2665 | ok = _bfd_vms_slurp_eeom (abfd); |
07d6d2b8 AM |
2666 | break; |
2667 | case EOBJ__C_EGSD: | |
f75fbe8a | 2668 | ok = _bfd_vms_slurp_egsd (abfd); |
07d6d2b8 AM |
2669 | break; |
2670 | case EOBJ__C_ETIR: | |
f75fbe8a | 2671 | ok = TRUE; /* _bfd_vms_slurp_etir (abfd); */ |
07d6d2b8 AM |
2672 | break; |
2673 | case EOBJ__C_EDBG: | |
f75fbe8a | 2674 | ok = _bfd_vms_slurp_edbg (abfd); |
07d6d2b8 AM |
2675 | break; |
2676 | case EOBJ__C_ETBT: | |
f75fbe8a | 2677 | ok = _bfd_vms_slurp_etbt (abfd); |
07d6d2b8 AM |
2678 | break; |
2679 | default: | |
f75fbe8a | 2680 | ok = FALSE; |
95e34ef7 | 2681 | } |
f75fbe8a | 2682 | if (!ok) |
95e34ef7 TG |
2683 | { |
2684 | vms_debug2 ((2, "slurp type %d failed\n", type)); | |
2685 | return FALSE; | |
2686 | } | |
2687 | } | |
2688 | while (type != EOBJ__C_EEOM); | |
2689 | ||
2690 | return TRUE; | |
2691 | } | |
2692 | ||
2693 | /* Initialize private data */ | |
2694 | static bfd_boolean | |
2695 | vms_initialize (bfd * abfd) | |
2696 | { | |
986f0783 | 2697 | size_t amt; |
95e34ef7 TG |
2698 | |
2699 | amt = sizeof (struct vms_private_data_struct); | |
2700 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2701 | if (abfd->tdata.any == NULL) | |
2702 | return FALSE; | |
2703 | ||
2704 | PRIV (recrd.file_format) = FF_UNKNOWN; | |
2705 | ||
2706 | amt = sizeof (struct stack_struct) * STACKSIZE; | |
2707 | PRIV (stack) = bfd_alloc (abfd, amt); | |
2708 | if (PRIV (stack) == NULL) | |
2709 | goto error_ret1; | |
2710 | ||
2711 | return TRUE; | |
2712 | ||
2713 | error_ret1: | |
2714 | bfd_release (abfd, abfd->tdata.any); | |
2715 | abfd->tdata.any = NULL; | |
2716 | return FALSE; | |
2717 | } | |
2718 | ||
a7ac9aa5 AM |
2719 | /* Free malloc'd memory. */ |
2720 | ||
2721 | static void | |
2722 | alpha_vms_free_private (bfd *abfd) | |
2723 | { | |
2724 | struct module *module; | |
2725 | ||
2726 | free (PRIV (recrd.buf)); | |
2727 | free (PRIV (sections)); | |
2728 | free (PRIV (syms)); | |
2729 | free (PRIV (dst_ptr_offsets)); | |
2730 | ||
2731 | for (module = PRIV (modules); module; module = module->next) | |
2732 | free (module->file_table); | |
2733 | } | |
2734 | ||
95e34ef7 TG |
2735 | /* Check the format for a file being read. |
2736 | Return a (bfd_target *) if it's an object file or zero if not. */ | |
2737 | ||
cb001c0d | 2738 | static bfd_cleanup |
95e34ef7 TG |
2739 | alpha_vms_object_p (bfd *abfd) |
2740 | { | |
8185f55c | 2741 | void *tdata_save = abfd->tdata.any; |
95e34ef7 TG |
2742 | unsigned int test_len; |
2743 | unsigned char *buf; | |
2744 | ||
2745 | vms_debug2 ((1, "vms_object_p(%p)\n", abfd)); | |
2746 | ||
2747 | /* Allocate alpha-vms specific data. */ | |
2748 | if (!vms_initialize (abfd)) | |
a7ac9aa5 AM |
2749 | { |
2750 | abfd->tdata.any = tdata_save; | |
2751 | return NULL; | |
2752 | } | |
95e34ef7 TG |
2753 | |
2754 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET)) | |
1b088c82 | 2755 | goto error_ret; |
95e34ef7 TG |
2756 | |
2757 | /* The first challenge with VMS is to discover the kind of the file. | |
2758 | ||
2759 | Image files (executable or shared images) are stored as a raw | |
2760 | stream of bytes (like on UNIX), but there is no magic number. | |
2761 | ||
2762 | Object files are written with RMS (record management service), ie | |
2763 | each records are preceeded by its length (on a word - 2 bytes), and | |
2764 | padded for word-alignment. That would be simple but when files | |
2765 | are transfered to a UNIX filesystem (using ftp), records are lost. | |
2766 | Only the raw content of the records are transfered. Fortunately, | |
2767 | the Alpha Object file format also store the length of the record | |
2768 | in the records. Is that clear ? */ | |
2769 | ||
2770 | /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id, | |
2771 | 2 bytes size repeated) and 12 bytes for images (4 bytes major id, | |
2772 | 4 bytes minor id, 4 bytes length). */ | |
2773 | test_len = 12; | |
1b088c82 | 2774 | buf = _bfd_malloc_and_read (abfd, test_len, test_len); |
95e34ef7 TG |
2775 | if (buf == NULL) |
2776 | goto error_ret; | |
2777 | PRIV (recrd.buf) = buf; | |
2778 | PRIV (recrd.buf_size) = test_len; | |
95e34ef7 TG |
2779 | PRIV (recrd.rec) = buf; |
2780 | ||
95e34ef7 TG |
2781 | /* Is it an image? */ |
2782 | if ((bfd_getl32 (buf) == EIHD__K_MAJORID) | |
2783 | && (bfd_getl32 (buf + 4) == EIHD__K_MINORID)) | |
2784 | { | |
95e34ef7 TG |
2785 | unsigned int eisd_offset, eihs_offset; |
2786 | ||
2787 | /* Extract the header size. */ | |
2788 | PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE); | |
2789 | ||
af47dcbf TG |
2790 | /* The header size is 0 for DSF files. */ |
2791 | if (PRIV (recrd.rec_size) == 0) | |
07d6d2b8 | 2792 | PRIV (recrd.rec_size) = sizeof (struct vms_eihd); |
af47dcbf | 2793 | |
8a2df5e2 | 2794 | /* PR 21813: Check for a truncated record. */ |
1b088c82 AM |
2795 | /* PR 17512: file: 7d7c57c2. */ |
2796 | if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd)) | |
2797 | goto err_wrong_format; | |
95e34ef7 | 2798 | |
1b088c82 AM |
2799 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET)) |
2800 | goto error_ret; | |
95e34ef7 | 2801 | |
1b088c82 AM |
2802 | free (PRIV (recrd.buf)); |
2803 | PRIV (recrd.buf) = NULL; | |
2804 | buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size), | |
2805 | PRIV (recrd.rec_size)); | |
2806 | if (buf == NULL) | |
2807 | goto error_ret; | |
95e34ef7 | 2808 | |
1b088c82 AM |
2809 | PRIV (recrd.buf) = buf; |
2810 | PRIV (recrd.buf_size) = PRIV (recrd.rec_size); | |
95e34ef7 TG |
2811 | PRIV (recrd.rec) = buf; |
2812 | ||
2813 | vms_debug2 ((2, "file type is image\n")); | |
2814 | ||
535b785f | 2815 | if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset)) |
07d6d2b8 | 2816 | goto err_wrong_format; |
95e34ef7 | 2817 | |
535b785f | 2818 | if (!_bfd_vms_slurp_eisd (abfd, eisd_offset)) |
07d6d2b8 | 2819 | goto err_wrong_format; |
95e34ef7 TG |
2820 | |
2821 | /* EIHS is optional. */ | |
535b785f | 2822 | if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset)) |
07d6d2b8 | 2823 | goto err_wrong_format; |
95e34ef7 TG |
2824 | } |
2825 | else | |
2826 | { | |
2827 | int type; | |
2828 | ||
2829 | /* Assume it's a module and adjust record pointer if necessary. */ | |
2830 | maybe_adjust_record_pointer_for_object (abfd); | |
2831 | ||
2832 | /* But is it really a module? */ | |
2833 | if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP | |
07d6d2b8 AM |
2834 | && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ) |
2835 | { | |
2836 | if (vms_get_remaining_object_record (abfd, test_len) <= 0) | |
2837 | goto err_wrong_format; | |
95e34ef7 | 2838 | |
07d6d2b8 | 2839 | vms_debug2 ((2, "file type is module\n")); |
95e34ef7 | 2840 | |
07d6d2b8 AM |
2841 | type = bfd_getl16 (PRIV (recrd.rec)); |
2842 | if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd)) | |
2843 | goto err_wrong_format; | |
95e34ef7 | 2844 | |
07d6d2b8 AM |
2845 | if (!_bfd_vms_slurp_object_records (abfd)) |
2846 | goto err_wrong_format; | |
2847 | } | |
95e34ef7 | 2848 | else |
07d6d2b8 | 2849 | goto err_wrong_format; |
95e34ef7 TG |
2850 | } |
2851 | ||
2852 | /* Set arch_info to alpha. */ | |
2853 | ||
2854 | if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0)) | |
2855 | goto err_wrong_format; | |
2856 | ||
cb001c0d | 2857 | return alpha_vms_free_private; |
95e34ef7 TG |
2858 | |
2859 | err_wrong_format: | |
2860 | bfd_set_error (bfd_error_wrong_format); | |
2861 | ||
2862 | error_ret: | |
a7ac9aa5 | 2863 | alpha_vms_free_private (abfd); |
95e34ef7 TG |
2864 | if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL) |
2865 | bfd_release (abfd, abfd->tdata.any); | |
2866 | abfd->tdata.any = tdata_save; | |
2867 | return NULL; | |
2868 | } | |
2869 | \f | |
2870 | /* Image write. */ | |
2871 | ||
bd7b51b4 TG |
2872 | /* Write an EMH/MHD record. */ |
2873 | ||
2874 | static void | |
2875 | _bfd_vms_write_emh (bfd *abfd) | |
2876 | { | |
2877 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
2878 | ||
2879 | _bfd_vms_output_alignment (recwr, 2); | |
2880 | ||
2881 | /* EMH. */ | |
2882 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
2883 | _bfd_vms_output_short (recwr, EMH__C_MHD); | |
2884 | _bfd_vms_output_short (recwr, EOBJ__C_STRLVL); | |
2885 | _bfd_vms_output_long (recwr, 0); | |
2886 | _bfd_vms_output_long (recwr, 0); | |
2887 | _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE); | |
2888 | ||
2889 | /* Create module name from filename. */ | |
2890 | if (bfd_get_filename (abfd) != 0) | |
2891 | { | |
2892 | char *module = vms_get_module_name (bfd_get_filename (abfd), TRUE); | |
2893 | _bfd_vms_output_counted (recwr, module); | |
2894 | free (module); | |
2895 | } | |
2896 | else | |
2897 | _bfd_vms_output_counted (recwr, "NONAME"); | |
2898 | ||
2899 | _bfd_vms_output_counted (recwr, BFD_VERSION_STRING); | |
2900 | _bfd_vms_output_dump (recwr, get_vms_time_string (), EMH_DATE_LENGTH); | |
2901 | _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH); | |
2902 | _bfd_vms_output_end (abfd, recwr); | |
2903 | } | |
2904 | ||
2905 | /* Write an EMH/LMN record. */ | |
2906 | ||
2907 | static void | |
2908 | _bfd_vms_write_lmn (bfd *abfd, const char *name) | |
2909 | { | |
2910 | char version [64]; | |
2911 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
2912 | unsigned int ver = BFD_VERSION / 10000; | |
2913 | ||
2914 | /* LMN. */ | |
2915 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
2916 | _bfd_vms_output_short (recwr, EMH__C_LNM); | |
2917 | snprintf (version, sizeof (version), "%s %d.%d.%d", name, | |
07d6d2b8 | 2918 | ver / 10000, (ver / 100) % 100, ver % 100); |
bd7b51b4 TG |
2919 | _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version)); |
2920 | _bfd_vms_output_end (abfd, recwr); | |
2921 | } | |
2922 | ||
2923 | ||
2924 | /* Write eom record for bfd abfd. Return FALSE on error. */ | |
2925 | ||
2926 | static bfd_boolean | |
2927 | _bfd_vms_write_eeom (bfd *abfd) | |
2928 | { | |
2929 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
2930 | ||
2931 | vms_debug2 ((2, "vms_write_eeom\n")); | |
2932 | ||
2933 | _bfd_vms_output_alignment (recwr, 2); | |
2934 | ||
2935 | _bfd_vms_output_begin (recwr, EOBJ__C_EEOM); | |
f1bb0388 | 2936 | _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1); |
bd7b51b4 TG |
2937 | _bfd_vms_output_byte (recwr, 0); /* Completion code. */ |
2938 | _bfd_vms_output_byte (recwr, 0); /* Fill byte. */ | |
2939 | ||
2940 | if ((abfd->flags & EXEC_P) == 0 | |
2941 | && bfd_get_start_address (abfd) != (bfd_vma)-1) | |
2942 | { | |
2943 | asection *section; | |
2944 | ||
2945 | section = bfd_get_section_by_name (abfd, ".link"); | |
2946 | if (section == 0) | |
2947 | { | |
2948 | bfd_set_error (bfd_error_nonrepresentable_section); | |
2949 | return FALSE; | |
2950 | } | |
2951 | _bfd_vms_output_short (recwr, 0); | |
1b3d1dbf | 2952 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); |
bd7b51b4 TG |
2953 | _bfd_vms_output_long (recwr, |
2954 | (unsigned long) bfd_get_start_address (abfd)); | |
2955 | _bfd_vms_output_long (recwr, 0); | |
2956 | } | |
2957 | ||
2958 | _bfd_vms_output_end (abfd, recwr); | |
2959 | return TRUE; | |
2960 | } | |
2961 | ||
96d3b80f | 2962 | static void * |
95e34ef7 TG |
2963 | vector_grow1 (struct vector_type *vec, size_t elsz) |
2964 | { | |
96d3b80f | 2965 | if (vec->nbr_el >= vec->max_el) |
95e34ef7 | 2966 | { |
96d3b80f AM |
2967 | if (vec->max_el == 0) |
2968 | { | |
2969 | vec->max_el = 16; | |
1f4361a7 | 2970 | vec->els = bfd_malloc (vec->max_el * elsz); |
96d3b80f AM |
2971 | } |
2972 | else | |
2973 | { | |
1f4361a7 | 2974 | size_t amt; |
96d3b80f AM |
2975 | if (vec->max_el > -1u / 2) |
2976 | { | |
2977 | bfd_set_error (bfd_error_file_too_big); | |
2978 | return NULL; | |
2979 | } | |
2980 | vec->max_el *= 2; | |
1f4361a7 AM |
2981 | if (_bfd_mul_overflow (vec->max_el, elsz, &amt)) |
2982 | { | |
2983 | bfd_set_error (bfd_error_file_too_big); | |
2984 | return NULL; | |
2985 | } | |
9cb56943 | 2986 | vec->els = bfd_realloc_or_free (vec->els, amt); |
96d3b80f | 2987 | } |
95e34ef7 | 2988 | } |
96d3b80f AM |
2989 | if (vec->els == NULL) |
2990 | return NULL; | |
2991 | return (char *) vec->els + elsz * vec->nbr_el++; | |
95e34ef7 TG |
2992 | } |
2993 | ||
2994 | /* Bump ABFD file position to next block. */ | |
2995 | ||
2996 | static void | |
2997 | alpha_vms_file_position_block (bfd *abfd) | |
2998 | { | |
2999 | /* Next block. */ | |
3000 | PRIV (file_pos) += VMS_BLOCK_SIZE - 1; | |
3001 | PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE); | |
3002 | } | |
3003 | ||
44273c5b TG |
3004 | /* Convert from internal structure SRC to external structure DST. */ |
3005 | ||
95e34ef7 TG |
3006 | static void |
3007 | alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src, | |
07d6d2b8 | 3008 | struct vms_eisd *dst) |
95e34ef7 TG |
3009 | { |
3010 | bfd_putl32 (src->u.eisd.majorid, dst->majorid); | |
3011 | bfd_putl32 (src->u.eisd.minorid, dst->minorid); | |
3012 | bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize); | |
3013 | if (src->u.eisd.eisdsize <= EISD__K_LENEND) | |
3014 | return; | |
3015 | bfd_putl32 (src->u.eisd.secsize, dst->secsize); | |
3016 | bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr); | |
3017 | bfd_putl32 (src->u.eisd.flags, dst->flags); | |
3018 | bfd_putl32 (src->u.eisd.vbn, dst->vbn); | |
3019 | dst->pfc = src->u.eisd.pfc; | |
3020 | dst->matchctl = src->u.eisd.matchctl; | |
3021 | dst->type = src->u.eisd.type; | |
3022 | dst->fill_1 = 0; | |
3023 | if (src->u.eisd.flags & EISD__M_GBL) | |
3024 | { | |
3025 | bfd_putl32 (src->u.gbl_eisd.ident, dst->ident); | |
3026 | memcpy (dst->gblnam, src->u.gbl_eisd.gblnam, | |
07d6d2b8 | 3027 | src->u.gbl_eisd.gblnam[0] + 1); |
95e34ef7 TG |
3028 | } |
3029 | } | |
3030 | ||
3031 | /* Append EISD to the list of extra eisd for ABFD. */ | |
3032 | ||
3033 | static void | |
3034 | alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd) | |
3035 | { | |
3036 | eisd->next = NULL; | |
3037 | if (PRIV (gbl_eisd_head) == NULL) | |
3038 | PRIV (gbl_eisd_head) = eisd; | |
3039 | else | |
3040 | PRIV (gbl_eisd_tail)->next = eisd; | |
3041 | PRIV (gbl_eisd_tail) = eisd; | |
3042 | } | |
3043 | ||
44273c5b TG |
3044 | /* Create an EISD for shared image SHRIMG. |
3045 | Return FALSE in case of error. */ | |
3046 | ||
95e34ef7 TG |
3047 | static bfd_boolean |
3048 | alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg) | |
3049 | { | |
3050 | struct vms_internal_eisd_map *eisd; | |
3051 | int namlen; | |
3052 | ||
3053 | namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name)); | |
3054 | if (namlen + 5 > EISD__K_GBLNAMLEN) | |
3055 | { | |
3056 | /* Won't fit. */ | |
3057 | return FALSE; | |
3058 | } | |
3059 | ||
3060 | eisd = bfd_alloc (abfd, sizeof (*eisd)); | |
3061 | if (eisd == NULL) | |
3062 | return FALSE; | |
3063 | ||
3064 | /* Fill the fields. */ | |
3065 | eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID; | |
3066 | eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID; | |
3067 | eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3; | |
3068 | eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */ | |
3069 | eisd->u.gbl_eisd.common.virt_addr = 0; | |
3070 | eisd->u.gbl_eisd.common.flags = EISD__M_GBL; | |
3071 | eisd->u.gbl_eisd.common.vbn = 0; | |
3072 | eisd->u.gbl_eisd.common.pfc = 0; | |
3073 | eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl); | |
3074 | eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC; | |
3075 | ||
3076 | eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident); | |
3077 | eisd->u.gbl_eisd.gblnam[0] = namlen + 4; | |
3078 | memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name), | |
07d6d2b8 | 3079 | namlen); |
95e34ef7 TG |
3080 | memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4); |
3081 | ||
3082 | /* Append it to the list. */ | |
3083 | alpha_vms_append_extra_eisd (abfd, eisd); | |
3084 | ||
3085 | return TRUE; | |
3086 | } | |
3087 | ||
44273c5b TG |
3088 | /* Create an EISD for section SEC. |
3089 | Return FALSE in case of failure. */ | |
3090 | ||
95e34ef7 TG |
3091 | static bfd_boolean |
3092 | alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec) | |
3093 | { | |
3094 | struct vms_internal_eisd_map *eisd; | |
3095 | ||
3096 | /* Only for allocating section. */ | |
3097 | if (!(sec->flags & SEC_ALLOC)) | |
3098 | return TRUE; | |
3099 | ||
3100 | BFD_ASSERT (vms_section_data (sec)->eisd == NULL); | |
3101 | eisd = bfd_alloc (abfd, sizeof (*eisd)); | |
3102 | if (eisd == NULL) | |
3103 | return FALSE; | |
3104 | vms_section_data (sec)->eisd = eisd; | |
3105 | ||
3106 | /* Fill the fields. */ | |
3107 | eisd->u.eisd.majorid = EISD__K_MAJORID; | |
3108 | eisd->u.eisd.minorid = EISD__K_MINORID; | |
3109 | eisd->u.eisd.eisdsize = EISD__K_LEN; | |
3110 | eisd->u.eisd.secsize = | |
3111 | (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); | |
3112 | eisd->u.eisd.virt_addr = sec->vma; | |
3113 | eisd->u.eisd.flags = 0; | |
3114 | eisd->u.eisd.vbn = 0; /* To be later defined. */ | |
3115 | eisd->u.eisd.pfc = 0; /* Default. */ | |
3116 | eisd->u.eisd.matchctl = EISD__K_MATALL; | |
3117 | eisd->u.eisd.type = EISD__K_NORMAL; | |
3118 | ||
3119 | if (sec->flags & SEC_CODE) | |
3120 | eisd->u.eisd.flags |= EISD__M_EXE; | |
cf6b8767 | 3121 | if (!(sec->flags & SEC_READONLY)) |
95e34ef7 TG |
3122 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; |
3123 | ||
5f101a3d TG |
3124 | /* If relocations or fixup will be applied, make this isect writeable. */ |
3125 | if (sec->flags & SEC_RELOC) | |
3126 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; | |
3127 | ||
8185f55c | 3128 | if (!(sec->flags & SEC_HAS_CONTENTS)) |
95e34ef7 TG |
3129 | { |
3130 | eisd->u.eisd.flags |= EISD__M_DZRO; | |
3131 | eisd->u.eisd.flags &= ~EISD__M_CRF; | |
3132 | } | |
3133 | if (sec->flags & SEC_LINKER_CREATED) | |
3134 | { | |
3135 | if (strcmp (sec->name, "$FIXUP$") == 0) | |
07d6d2b8 | 3136 | eisd->u.eisd.flags |= EISD__M_FIXUPVEC; |
95e34ef7 TG |
3137 | } |
3138 | ||
3139 | /* Append it to the list. */ | |
3140 | eisd->next = NULL; | |
3141 | if (PRIV (eisd_head) == NULL) | |
3142 | PRIV (eisd_head) = eisd; | |
3143 | else | |
3144 | PRIV (eisd_tail)->next = eisd; | |
3145 | PRIV (eisd_tail) = eisd; | |
3146 | ||
3147 | return TRUE; | |
3148 | } | |
3149 | ||
44273c5b TG |
3150 | /* Layout executable ABFD and write it to the disk. |
3151 | Return FALSE in case of failure. */ | |
3152 | ||
95e34ef7 TG |
3153 | static bfd_boolean |
3154 | alpha_vms_write_exec (bfd *abfd) | |
3155 | { | |
3156 | struct vms_eihd eihd; | |
3157 | struct vms_eiha *eiha; | |
3158 | struct vms_eihi *eihi; | |
3159 | struct vms_eihs *eihs = NULL; | |
3160 | asection *sec; | |
3161 | struct vms_internal_eisd_map *first_eisd; | |
3162 | struct vms_internal_eisd_map *eisd; | |
3163 | asection *dst; | |
44273c5b | 3164 | asection *dmt; |
f9eeb9c9 TG |
3165 | file_ptr gst_filepos = 0; |
3166 | unsigned int lnkflags = 0; | |
95e34ef7 | 3167 | |
44273c5b | 3168 | /* Build the EIHD. */ |
95e34ef7 TG |
3169 | PRIV (file_pos) = EIHD__C_LENGTH; |
3170 | ||
3171 | memset (&eihd, 0, sizeof (eihd)); | |
3172 | memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2)); | |
3173 | ||
3174 | bfd_putl32 (EIHD__K_MAJORID, eihd.majorid); | |
3175 | bfd_putl32 (EIHD__K_MINORID, eihd.minorid); | |
3176 | ||
3177 | bfd_putl32 (sizeof (eihd), eihd.size); | |
3178 | bfd_putl32 (0, eihd.isdoff); | |
3179 | bfd_putl32 (0, eihd.activoff); | |
3180 | bfd_putl32 (0, eihd.symdbgoff); | |
3181 | bfd_putl32 (0, eihd.imgidoff); | |
3182 | bfd_putl32 (0, eihd.patchoff); | |
3183 | bfd_putl64 (0, eihd.iafva); | |
3184 | bfd_putl32 (0, eihd.version_array_off); | |
3185 | ||
3186 | bfd_putl32 (EIHD__K_EXE, eihd.imgtype); | |
3187 | bfd_putl32 (0, eihd.subtype); | |
3188 | ||
3189 | bfd_putl32 (0, eihd.imgiocnt); | |
3190 | bfd_putl32 (-1, eihd.privreqs); | |
3191 | bfd_putl32 (-1, eihd.privreqs + 4); | |
3192 | ||
3193 | bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, | |
07d6d2b8 | 3194 | eihd.hdrblkcnt); |
95e34ef7 TG |
3195 | bfd_putl32 (0, eihd.ident); |
3196 | bfd_putl32 (0, eihd.sysver); | |
3197 | ||
3198 | eihd.matchctl = 0; | |
3199 | bfd_putl32 (0, eihd.symvect_size); | |
3200 | bfd_putl32 (16, eihd.virt_mem_block_size); | |
3201 | bfd_putl32 (0, eihd.ext_fixup_off); | |
3202 | bfd_putl32 (0, eihd.noopt_psect_off); | |
3203 | bfd_putl32 (-1, eihd.alias); | |
3204 | ||
3205 | /* Alloc EIHA. */ | |
3206 | eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos)); | |
3207 | bfd_putl32 (PRIV (file_pos), eihd.activoff); | |
3208 | PRIV (file_pos) += sizeof (struct vms_eiha); | |
3209 | ||
3210 | bfd_putl32 (sizeof (struct vms_eiha), eiha->size); | |
3211 | bfd_putl32 (0, eiha->spare); | |
46d00b8a TG |
3212 | bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1); |
3213 | bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2); | |
3214 | bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3); | |
3215 | bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4); | |
95e34ef7 TG |
3216 | bfd_putl64 (0, eiha->inishr); |
3217 | ||
3218 | /* Alloc EIHI. */ | |
3219 | eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos)); | |
3220 | bfd_putl32 (PRIV (file_pos), eihd.imgidoff); | |
3221 | PRIV (file_pos) += sizeof (struct vms_eihi); | |
3222 | ||
3223 | bfd_putl32 (EIHI__K_MAJORID, eihi->majorid); | |
3224 | bfd_putl32 (EIHI__K_MINORID, eihi->minorid); | |
3225 | { | |
3226 | char *module; | |
3227 | unsigned int len; | |
3228 | ||
9714ee48 | 3229 | /* Set module name. */ |
95e34ef7 TG |
3230 | module = vms_get_module_name (bfd_get_filename (abfd), TRUE); |
3231 | len = strlen (module); | |
3232 | if (len > sizeof (eihi->imgnam) - 1) | |
3233 | len = sizeof (eihi->imgnam) - 1; | |
3234 | eihi->imgnam[0] = len; | |
3235 | memcpy (eihi->imgnam + 1, module, len); | |
3236 | free (module); | |
3237 | } | |
9714ee48 TG |
3238 | { |
3239 | unsigned int lo; | |
3240 | unsigned int hi; | |
3241 | ||
3242 | /* Set time. */ | |
3243 | vms_get_time (&hi, &lo); | |
3244 | bfd_putl32 (lo, eihi->linktime + 0); | |
3245 | bfd_putl32 (hi, eihi->linktime + 4); | |
3246 | } | |
95e34ef7 TG |
3247 | eihi->imgid[0] = 0; |
3248 | eihi->linkid[0] = 0; | |
3249 | eihi->imgbid[0] = 0; | |
3250 | ||
3251 | /* Alloc EIHS. */ | |
44273c5b TG |
3252 | dst = PRIV (dst_section); |
3253 | dmt = bfd_get_section_by_name (abfd, "$DMT$"); | |
95e34ef7 TG |
3254 | if (dst != NULL && dst->size != 0) |
3255 | { | |
3256 | eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos)); | |
3257 | bfd_putl32 (PRIV (file_pos), eihd.symdbgoff); | |
3258 | PRIV (file_pos) += sizeof (struct vms_eihs); | |
3259 | ||
3260 | bfd_putl32 (EIHS__K_MAJORID, eihs->majorid); | |
3261 | bfd_putl32 (EIHS__K_MINORID, eihs->minorid); | |
3262 | bfd_putl32 (0, eihs->dstvbn); | |
3263 | bfd_putl32 (0, eihs->dstsize); | |
3264 | bfd_putl32 (0, eihs->gstvbn); | |
3265 | bfd_putl32 (0, eihs->gstsize); | |
3266 | bfd_putl32 (0, eihs->dmtvbn); | |
3267 | bfd_putl32 (0, eihs->dmtsize); | |
3268 | } | |
3269 | ||
44273c5b | 3270 | /* One EISD per section. */ |
95e34ef7 TG |
3271 | for (sec = abfd->sections; sec; sec = sec->next) |
3272 | { | |
3273 | if (!alpha_vms_create_eisd_for_section (abfd, sec)) | |
07d6d2b8 | 3274 | return FALSE; |
95e34ef7 TG |
3275 | } |
3276 | ||
3277 | /* Merge section EIDS which extra ones. */ | |
3278 | if (PRIV (eisd_tail)) | |
3279 | PRIV (eisd_tail)->next = PRIV (gbl_eisd_head); | |
3280 | else | |
3281 | PRIV (eisd_head) = PRIV (gbl_eisd_head); | |
3282 | if (PRIV (gbl_eisd_tail)) | |
3283 | PRIV (eisd_tail) = PRIV (gbl_eisd_tail); | |
3284 | ||
3285 | first_eisd = PRIV (eisd_head); | |
3286 | ||
3287 | /* Add end of eisd. */ | |
3288 | if (first_eisd) | |
3289 | { | |
3290 | eisd = bfd_zalloc (abfd, sizeof (*eisd)); | |
3291 | if (eisd == NULL) | |
07d6d2b8 | 3292 | return FALSE; |
95e34ef7 TG |
3293 | eisd->u.eisd.majorid = 0; |
3294 | eisd->u.eisd.minorid = 0; | |
3295 | eisd->u.eisd.eisdsize = 0; | |
3296 | alpha_vms_append_extra_eisd (abfd, eisd); | |
3297 | } | |
3298 | ||
3299 | /* Place EISD in the file. */ | |
3300 | for (eisd = first_eisd; eisd; eisd = eisd->next) | |
3301 | { | |
3302 | file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE); | |
3303 | ||
3304 | /* First block is a little bit special: there is a word at the end. */ | |
3305 | if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2) | |
07d6d2b8 | 3306 | room -= 2; |
95e34ef7 | 3307 | if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND) |
07d6d2b8 | 3308 | alpha_vms_file_position_block (abfd); |
95e34ef7 TG |
3309 | |
3310 | eisd->file_pos = PRIV (file_pos); | |
3311 | PRIV (file_pos) += eisd->u.eisd.eisdsize; | |
3312 | ||
3313 | if (eisd->u.eisd.flags & EISD__M_FIXUPVEC) | |
07d6d2b8 | 3314 | bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva); |
95e34ef7 TG |
3315 | } |
3316 | ||
3317 | if (first_eisd != NULL) | |
3318 | { | |
3319 | bfd_putl32 (first_eisd->file_pos, eihd.isdoff); | |
3320 | /* Real size of end of eisd marker. */ | |
3321 | PRIV (file_pos) += EISD__K_LENEND; | |
3322 | } | |
3323 | ||
3324 | bfd_putl32 (PRIV (file_pos), eihd.size); | |
3325 | bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, | |
07d6d2b8 | 3326 | eihd.hdrblkcnt); |
95e34ef7 TG |
3327 | |
3328 | /* Place sections. */ | |
3329 | for (sec = abfd->sections; sec; sec = sec->next) | |
3330 | { | |
3331 | if (!(sec->flags & SEC_HAS_CONTENTS)) | |
07d6d2b8 | 3332 | continue; |
95e34ef7 TG |
3333 | |
3334 | eisd = vms_section_data (sec)->eisd; | |
3335 | ||
3336 | /* Align on a block. */ | |
3337 | alpha_vms_file_position_block (abfd); | |
3338 | sec->filepos = PRIV (file_pos); | |
3339 | ||
3340 | if (eisd != NULL) | |
07d6d2b8 | 3341 | eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1; |
95e34ef7 TG |
3342 | |
3343 | PRIV (file_pos) += sec->size; | |
3344 | } | |
3345 | ||
5fe88cfb | 3346 | /* Update EIHS. */ |
95e34ef7 TG |
3347 | if (eihs != NULL && dst != NULL) |
3348 | { | |
3349 | bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn); | |
3350 | bfd_putl32 (dst->size, eihs->dstsize); | |
44273c5b TG |
3351 | |
3352 | if (dmt != NULL) | |
07d6d2b8 AM |
3353 | { |
3354 | lnkflags |= EIHD__M_DBGDMT; | |
3355 | bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn); | |
3356 | bfd_putl32 (dmt->size, eihs->dmtsize); | |
3357 | } | |
f9eeb9c9 | 3358 | if (PRIV (gsd_sym_count) != 0) |
07d6d2b8 AM |
3359 | { |
3360 | alpha_vms_file_position_block (abfd); | |
3361 | gst_filepos = PRIV (file_pos); | |
3362 | bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn); | |
3363 | bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize); | |
3364 | } | |
95e34ef7 TG |
3365 | } |
3366 | ||
3367 | /* Write EISD in hdr. */ | |
3368 | for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE; | |
3369 | eisd = eisd->next) | |
3370 | alpha_vms_swap_eisd_out | |
3371 | (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos)); | |
3372 | ||
3373 | /* Write first block. */ | |
f9eeb9c9 | 3374 | bfd_putl32 (lnkflags, eihd.lnkflags); |
95e34ef7 TG |
3375 | if (bfd_bwrite (&eihd, sizeof (eihd), abfd) != sizeof (eihd)) |
3376 | return FALSE; | |
3377 | ||
3378 | /* Write remaining eisd. */ | |
3379 | if (eisd != NULL) | |
3380 | { | |
3381 | unsigned char blk[VMS_BLOCK_SIZE]; | |
3382 | struct vms_internal_eisd_map *next_eisd; | |
3383 | ||
3384 | memset (blk, 0xff, sizeof (blk)); | |
3385 | while (eisd != NULL) | |
07d6d2b8 AM |
3386 | { |
3387 | alpha_vms_swap_eisd_out | |
3388 | (eisd, | |
3389 | (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE))); | |
3390 | ||
3391 | next_eisd = eisd->next; | |
3392 | if (next_eisd == NULL | |
3393 | || (next_eisd->file_pos / VMS_BLOCK_SIZE | |
3394 | != eisd->file_pos / VMS_BLOCK_SIZE)) | |
3395 | { | |
3396 | if (bfd_bwrite (blk, sizeof (blk), abfd) != sizeof (blk)) | |
3397 | return FALSE; | |
95e34ef7 | 3398 | |
07d6d2b8 AM |
3399 | memset (blk, 0xff, sizeof (blk)); |
3400 | } | |
3401 | eisd = next_eisd; | |
3402 | } | |
95e34ef7 TG |
3403 | } |
3404 | ||
3405 | /* Write sections. */ | |
3406 | for (sec = abfd->sections; sec; sec = sec->next) | |
3407 | { | |
3408 | unsigned char blk[VMS_BLOCK_SIZE]; | |
3409 | bfd_size_type len; | |
3410 | ||
3411 | if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS)) | |
07d6d2b8 | 3412 | continue; |
95e34ef7 | 3413 | if (bfd_bwrite (sec->contents, sec->size, abfd) != sec->size) |
07d6d2b8 | 3414 | return FALSE; |
95e34ef7 TG |
3415 | |
3416 | /* Pad. */ | |
3417 | len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE; | |
3418 | if (len != VMS_BLOCK_SIZE) | |
07d6d2b8 AM |
3419 | { |
3420 | memset (blk, 0, len); | |
3421 | if (bfd_bwrite (blk, len, abfd) != len) | |
3422 | return FALSE; | |
3423 | } | |
95e34ef7 TG |
3424 | } |
3425 | ||
f9eeb9c9 TG |
3426 | /* Write GST. */ |
3427 | if (gst_filepos != 0) | |
3428 | { | |
3429 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3430 | unsigned int i; | |
3431 | ||
3432 | _bfd_vms_write_emh (abfd); | |
3433 | _bfd_vms_write_lmn (abfd, "GNU LD"); | |
3434 | ||
3435 | /* PSC for the absolute section. */ | |
3436 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3437 | _bfd_vms_output_long (recwr, 0); | |
3438 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); | |
3439 | _bfd_vms_output_short (recwr, 0); | |
3440 | _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD); | |
3441 | _bfd_vms_output_long (recwr, 0); | |
3442 | _bfd_vms_output_counted (recwr, ".$$ABS$$."); | |
3443 | _bfd_vms_output_end_subrec (recwr); | |
3444 | _bfd_vms_output_end (abfd, recwr); | |
3445 | ||
3446 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 AM |
3447 | { |
3448 | struct vms_symbol_entry *sym = PRIV (syms)[i]; | |
3449 | bfd_vma val; | |
3450 | bfd_vma ep; | |
3451 | ||
3452 | if ((i % 5) == 0) | |
3453 | { | |
3454 | _bfd_vms_output_alignment (recwr, 8); | |
3455 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3456 | _bfd_vms_output_long (recwr, 0); | |
3457 | } | |
3458 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG); | |
3459 | _bfd_vms_output_short (recwr, 0); /* Data type, alignment. */ | |
3460 | _bfd_vms_output_short (recwr, sym->flags); | |
3461 | ||
3462 | if (sym->code_section) | |
3463 | ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value); | |
3464 | else | |
3465 | { | |
3466 | BFD_ASSERT (sym->code_value == 0); | |
3467 | ep = 0; | |
3468 | } | |
3469 | val = alpha_vms_get_sym_value (sym->section, sym->value); | |
3470 | _bfd_vms_output_quad | |
3471 | (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val); | |
3472 | _bfd_vms_output_quad (recwr, ep); | |
3473 | _bfd_vms_output_quad (recwr, val); | |
3474 | _bfd_vms_output_long (recwr, 0); | |
3475 | _bfd_vms_output_counted (recwr, sym->name); | |
3476 | _bfd_vms_output_end_subrec (recwr); | |
3477 | if ((i % 5) == 4) | |
3478 | _bfd_vms_output_end (abfd, recwr); | |
3479 | } | |
f9eeb9c9 | 3480 | if ((i % 5) != 0) |
07d6d2b8 | 3481 | _bfd_vms_output_end (abfd, recwr); |
f9eeb9c9 TG |
3482 | |
3483 | if (!_bfd_vms_write_eeom (abfd)) | |
07d6d2b8 | 3484 | return FALSE; |
f9eeb9c9 | 3485 | } |
95e34ef7 TG |
3486 | return TRUE; |
3487 | } | |
3488 | \f | |
3489 | /* Object write. */ | |
3490 | ||
95e34ef7 TG |
3491 | /* Write section and symbol directory of bfd abfd. Return FALSE on error. */ |
3492 | ||
3493 | static bfd_boolean | |
3494 | _bfd_vms_write_egsd (bfd *abfd) | |
3495 | { | |
3496 | asection *section; | |
3497 | asymbol *symbol; | |
3498 | unsigned int symnum; | |
dddb0e80 | 3499 | const char *sname; |
95e34ef7 | 3500 | flagword new_flags, old_flags; |
4ba2ab9f | 3501 | int abs_section_index = -1; |
1b3d1dbf | 3502 | unsigned int target_index = 0; |
95e34ef7 TG |
3503 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3504 | ||
1b3d1dbf | 3505 | vms_debug2 ((2, "vms_write_egsd\n")); |
95e34ef7 TG |
3506 | |
3507 | /* Egsd is quadword aligned. */ | |
3508 | _bfd_vms_output_alignment (recwr, 8); | |
3509 | ||
3510 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3511 | _bfd_vms_output_long (recwr, 0); | |
3512 | ||
1b3d1dbf TG |
3513 | /* Number sections. */ |
3514 | for (section = abfd->sections; section != NULL; section = section->next) | |
3515 | { | |
3516 | if (section->flags & SEC_DEBUGGING) | |
07d6d2b8 | 3517 | continue; |
1b3d1dbf | 3518 | if (!strcmp (section->name, ".vmsdebug")) |
07d6d2b8 AM |
3519 | { |
3520 | section->flags |= SEC_DEBUGGING; | |
3521 | continue; | |
3522 | } | |
1b3d1dbf TG |
3523 | section->target_index = target_index++; |
3524 | } | |
3525 | ||
3526 | for (section = abfd->sections; section != NULL; section = section->next) | |
95e34ef7 TG |
3527 | { |
3528 | vms_debug2 ((3, "Section #%d %s, %d bytes\n", | |
07d6d2b8 | 3529 | section->target_index, section->name, (int)section->size)); |
95e34ef7 TG |
3530 | |
3531 | /* Don't write out the VMS debug info section since it is in the | |
07d6d2b8 | 3532 | ETBT and EDBG sections in etir. */ |
1b3d1dbf | 3533 | if (section->flags & SEC_DEBUGGING) |
07d6d2b8 | 3534 | continue; |
95e34ef7 TG |
3535 | |
3536 | /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */ | |
3537 | if (_bfd_vms_output_check (recwr, 64) < 0) | |
3538 | { | |
3539 | _bfd_vms_output_end (abfd, recwr); | |
3540 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3541 | _bfd_vms_output_long (recwr, 0); | |
3542 | } | |
3543 | ||
95e34ef7 | 3544 | /* Don't know if this is necessary for the linker but for now it keeps |
5fe88cfb | 3545 | vms_slurp_gsd happy. */ |
81bb31c0 | 3546 | sname = section->name; |
95e34ef7 TG |
3547 | if (*sname == '.') |
3548 | { | |
07d6d2b8 | 3549 | /* Remove leading dot. */ |
95e34ef7 TG |
3550 | sname++; |
3551 | if ((*sname == 't') && (strcmp (sname, "text") == 0)) | |
3552 | sname = EVAX_CODE_NAME; | |
3553 | else if ((*sname == 'd') && (strcmp (sname, "data") == 0)) | |
3554 | sname = EVAX_DATA_NAME; | |
3555 | else if ((*sname == 'b') && (strcmp (sname, "bss") == 0)) | |
3556 | sname = EVAX_BSS_NAME; | |
3557 | else if ((*sname == 'l') && (strcmp (sname, "link") == 0)) | |
3558 | sname = EVAX_LINK_NAME; | |
3559 | else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0)) | |
3560 | sname = EVAX_READONLY_NAME; | |
3561 | else if ((*sname == 'l') && (strcmp (sname, "literal") == 0)) | |
3562 | sname = EVAX_LITERAL_NAME; | |
3563 | else if ((*sname == 'l') && (strcmp (sname, "literals") == 0)) | |
07d6d2b8 | 3564 | sname = EVAX_LITERALS_NAME; |
95e34ef7 TG |
3565 | else if ((*sname == 'c') && (strcmp (sname, "comm") == 0)) |
3566 | sname = EVAX_COMMON_NAME; | |
3567 | else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0)) | |
3568 | sname = EVAX_LOCAL_NAME; | |
3569 | } | |
95e34ef7 | 3570 | |
95e34ef7 TG |
3571 | if (bfd_is_com_section (section)) |
3572 | new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD | |
3573 | | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM); | |
3574 | else | |
3575 | new_flags = vms_esecflag_by_name (evax_section_flags, sname, | |
3576 | section->size > 0); | |
3577 | ||
3578 | /* Modify them as directed. */ | |
3579 | if (section->flags & SEC_READONLY) | |
3580 | new_flags &= ~EGPS__V_WRT; | |
3581 | ||
3582 | new_flags &= ~vms_section_data (section)->no_flags; | |
3583 | new_flags |= vms_section_data (section)->flags; | |
3584 | ||
3585 | vms_debug2 ((3, "sec flags %x\n", section->flags)); | |
3586 | vms_debug2 ((3, "new_flags %x, _raw_size %lu\n", | |
07d6d2b8 | 3587 | new_flags, (unsigned long)section->size)); |
95e34ef7 | 3588 | |
4ba2ab9f TG |
3589 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); |
3590 | _bfd_vms_output_short (recwr, section->alignment_power & 0xff); | |
95e34ef7 TG |
3591 | _bfd_vms_output_short (recwr, new_flags); |
3592 | _bfd_vms_output_long (recwr, (unsigned long) section->size); | |
3593 | _bfd_vms_output_counted (recwr, sname); | |
3594 | _bfd_vms_output_end_subrec (recwr); | |
4ba2ab9f TG |
3595 | |
3596 | /* If the section is an obsolute one, remind its index as it will be | |
07d6d2b8 | 3597 | used later for absolute symbols. */ |
4ba2ab9f | 3598 | if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0) |
07d6d2b8 | 3599 | abs_section_index = section->target_index; |
95e34ef7 TG |
3600 | } |
3601 | ||
3602 | /* Output symbols. */ | |
3603 | vms_debug2 ((3, "%d symbols found\n", abfd->symcount)); | |
3604 | ||
3605 | bfd_set_start_address (abfd, (bfd_vma) -1); | |
3606 | ||
3607 | for (symnum = 0; symnum < abfd->symcount; symnum++) | |
3608 | { | |
95e34ef7 | 3609 | symbol = abfd->outsymbols[symnum]; |
46d00b8a TG |
3610 | old_flags = symbol->flags; |
3611 | ||
4ba2ab9f | 3612 | /* Work-around a missing feature: consider __main as the main entry |
07d6d2b8 | 3613 | point. */ |
53452371 TG |
3614 | if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0) |
3615 | bfd_set_start_address (abfd, (bfd_vma)symbol->value); | |
95e34ef7 | 3616 | |
46d00b8a | 3617 | /* Only put in the GSD the global and the undefined symbols. */ |
95e34ef7 TG |
3618 | if (old_flags & BSF_FILE) |
3619 | continue; | |
3620 | ||
46d00b8a | 3621 | if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section)) |
07d6d2b8 AM |
3622 | { |
3623 | /* If the LIB$INITIIALIZE section is present, add a reference to | |
3624 | LIB$INITIALIZE symbol. FIXME: this should be done explicitely | |
3625 | in the assembly file. */ | |
3626 | if (!((old_flags & BSF_SECTION_SYM) != 0 | |
3627 | && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0)) | |
3628 | continue; | |
3629 | } | |
95e34ef7 | 3630 | |
4ba2ab9f | 3631 | /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. Add 16 more |
07d6d2b8 | 3632 | bytes for a possible ABS section. */ |
4ba2ab9f | 3633 | if (_bfd_vms_output_check (recwr, 80 + 16) < 0) |
95e34ef7 TG |
3634 | { |
3635 | _bfd_vms_output_end (abfd, recwr); | |
3636 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3637 | _bfd_vms_output_long (recwr, 0); | |
3638 | } | |
3639 | ||
4ba2ab9f | 3640 | if ((old_flags & BSF_GLOBAL) != 0 |
07d6d2b8 AM |
3641 | && bfd_is_abs_section (symbol->section) |
3642 | && abs_section_index <= 0) | |
3643 | { | |
3644 | /* Create an absolute section if none was defined. It is highly | |
3645 | unlikely that the name $ABS$ clashes with a user defined | |
3646 | non-absolute section name. */ | |
3647 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); | |
3648 | _bfd_vms_output_short (recwr, 4); | |
3649 | _bfd_vms_output_short (recwr, EGPS__V_SHR); | |
3650 | _bfd_vms_output_long (recwr, 0); | |
3651 | _bfd_vms_output_counted (recwr, "$ABS$"); | |
3652 | _bfd_vms_output_end_subrec (recwr); | |
3653 | ||
3654 | abs_section_index = target_index++; | |
3655 | } | |
4ba2ab9f | 3656 | |
95e34ef7 TG |
3657 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM); |
3658 | ||
3659 | /* Data type, alignment. */ | |
3660 | _bfd_vms_output_short (recwr, 0); | |
3661 | ||
3662 | new_flags = 0; | |
3663 | ||
3664 | if (old_flags & BSF_WEAK) | |
3665 | new_flags |= EGSY__V_WEAK; | |
3666 | if (bfd_is_com_section (symbol->section)) /* .comm */ | |
3667 | new_flags |= (EGSY__V_WEAK | EGSY__V_COMM); | |
3668 | ||
3669 | if (old_flags & BSF_FUNCTION) | |
3670 | { | |
3671 | new_flags |= EGSY__V_NORM; | |
3672 | new_flags |= EGSY__V_REL; | |
3673 | } | |
3674 | if (old_flags & BSF_GLOBAL) | |
3675 | { | |
3676 | new_flags |= EGSY__V_DEF; | |
3677 | if (!bfd_is_abs_section (symbol->section)) | |
3678 | new_flags |= EGSY__V_REL; | |
3679 | } | |
3680 | _bfd_vms_output_short (recwr, new_flags); | |
3681 | ||
3682 | if (old_flags & BSF_GLOBAL) | |
3683 | { | |
3684 | /* Symbol definition. */ | |
3685 | bfd_vma code_address = 0; | |
3686 | unsigned long ca_psindx = 0; | |
3687 | unsigned long psindx; | |
3688 | ||
3689 | if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL) | |
3690 | { | |
3691 | asymbol *sym; | |
3692 | ||
07d6d2b8 AM |
3693 | sym = |
3694 | ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym; | |
95e34ef7 | 3695 | code_address = sym->value; |
1b3d1dbf | 3696 | ca_psindx = sym->section->target_index; |
95e34ef7 TG |
3697 | } |
3698 | if (bfd_is_abs_section (symbol->section)) | |
3699 | psindx = abs_section_index; | |
3700 | else | |
1b3d1dbf | 3701 | psindx = symbol->section->target_index; |
95e34ef7 TG |
3702 | |
3703 | _bfd_vms_output_quad (recwr, symbol->value); | |
3704 | _bfd_vms_output_quad (recwr, code_address); | |
3705 | _bfd_vms_output_long (recwr, ca_psindx); | |
3706 | _bfd_vms_output_long (recwr, psindx); | |
3707 | } | |
53452371 | 3708 | _bfd_vms_output_counted (recwr, symbol->name); |
95e34ef7 TG |
3709 | |
3710 | _bfd_vms_output_end_subrec (recwr); | |
95e34ef7 TG |
3711 | } |
3712 | ||
3713 | _bfd_vms_output_alignment (recwr, 8); | |
3714 | _bfd_vms_output_end (abfd, recwr); | |
3715 | ||
3716 | return TRUE; | |
3717 | } | |
3718 | ||
3719 | /* Write object header for bfd abfd. Return FALSE on error. */ | |
3720 | ||
3721 | static bfd_boolean | |
3722 | _bfd_vms_write_ehdr (bfd *abfd) | |
3723 | { | |
3724 | asymbol *symbol; | |
3725 | unsigned int symnum; | |
95e34ef7 TG |
3726 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3727 | ||
3728 | vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd)); | |
3729 | ||
3730 | _bfd_vms_output_alignment (recwr, 2); | |
3731 | ||
bd7b51b4 TG |
3732 | _bfd_vms_write_emh (abfd); |
3733 | _bfd_vms_write_lmn (abfd, "GNU AS"); | |
95e34ef7 TG |
3734 | |
3735 | /* SRC. */ | |
3736 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3737 | _bfd_vms_output_short (recwr, EMH__C_SRC); | |
3738 | ||
3739 | for (symnum = 0; symnum < abfd->symcount; symnum++) | |
3740 | { | |
3741 | symbol = abfd->outsymbols[symnum]; | |
3742 | ||
3743 | if (symbol->flags & BSF_FILE) | |
3744 | { | |
95e34ef7 TG |
3745 | _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name, |
3746 | (int) strlen (symbol->name)); | |
53452371 | 3747 | break; |
95e34ef7 TG |
3748 | } |
3749 | } | |
3750 | ||
3751 | if (symnum == abfd->symcount) | |
3752 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname")); | |
3753 | ||
3754 | _bfd_vms_output_end (abfd, recwr); | |
3755 | ||
3756 | /* TTL. */ | |
3757 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3758 | _bfd_vms_output_short (recwr, EMH__C_TTL); | |
3759 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL")); | |
3760 | _bfd_vms_output_end (abfd, recwr); | |
3761 | ||
3762 | /* CPR. */ | |
3763 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3764 | _bfd_vms_output_short (recwr, EMH__C_CPR); | |
3765 | _bfd_vms_output_dump (recwr, | |
07d6d2b8 | 3766 | (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996", |
95e34ef7 TG |
3767 | 39); |
3768 | _bfd_vms_output_end (abfd, recwr); | |
3769 | ||
3770 | return TRUE; | |
3771 | } | |
3772 | ||
3773 | /* Part 4.6, relocations. */ | |
3774 | ||
3775 | \f | |
3776 | /* WRITE ETIR SECTION | |
3777 | ||
3778 | This is still under construction and therefore not documented. */ | |
3779 | ||
3780 | /* Close the etir/etbt record. */ | |
3781 | ||
3782 | static void | |
3783 | end_etir_record (bfd * abfd) | |
3784 | { | |
3785 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3786 | ||
3787 | _bfd_vms_output_end (abfd, recwr); | |
3788 | } | |
3789 | ||
3790 | static void | |
3791 | start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset) | |
3792 | { | |
3793 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3794 | ||
1b3d1dbf | 3795 | if (section->flags & SEC_DEBUGGING) |
95e34ef7 TG |
3796 | { |
3797 | _bfd_vms_output_begin (recwr, EOBJ__C_ETBT); | |
3798 | ||
3799 | if (offset == 0) | |
07d6d2b8 AM |
3800 | { |
3801 | /* Push start offset. */ | |
3802 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); | |
3803 | _bfd_vms_output_long (recwr, (unsigned long) 0); | |
3804 | _bfd_vms_output_end_subrec (recwr); | |
3805 | ||
3806 | /* Set location. */ | |
3807 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC); | |
3808 | _bfd_vms_output_end_subrec (recwr); | |
3809 | } | |
95e34ef7 TG |
3810 | } |
3811 | else | |
3812 | { | |
3813 | _bfd_vms_output_begin (recwr, EOBJ__C_ETIR); | |
3814 | ||
3815 | if (offset == 0) | |
07d6d2b8 AM |
3816 | { |
3817 | /* Push start offset. */ | |
3818 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); | |
3819 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); | |
3820 | _bfd_vms_output_quad (recwr, offset); | |
3821 | _bfd_vms_output_end_subrec (recwr); | |
3822 | ||
3823 | /* Start = pop (). */ | |
3824 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB); | |
3825 | _bfd_vms_output_end_subrec (recwr); | |
3826 | } | |
95e34ef7 TG |
3827 | } |
3828 | } | |
3829 | ||
3830 | /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual | |
3831 | address VADDR in section specified by SEC_INDEX and NAME. */ | |
3832 | ||
3833 | static void | |
3834 | sto_imm (bfd *abfd, asection *section, | |
07d6d2b8 | 3835 | bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr) |
95e34ef7 TG |
3836 | { |
3837 | bfd_size_type size; | |
3838 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3839 | ||
3840 | #if VMS_DEBUG | |
3841 | _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize); | |
3842 | _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr); | |
3843 | #endif | |
3844 | ||
3845 | while (ssize > 0) | |
3846 | { | |
3847 | /* Try all the rest. */ | |
3848 | size = ssize; | |
3849 | ||
3850 | if (_bfd_vms_output_check (recwr, size) < 0) | |
3851 | { | |
3852 | /* Doesn't fit, split ! */ | |
3853 | end_etir_record (abfd); | |
3854 | ||
07d6d2b8 | 3855 | start_etir_or_etbt_record (abfd, section, vaddr); |
95e34ef7 TG |
3856 | |
3857 | size = _bfd_vms_output_check (recwr, 0); /* get max size */ | |
3858 | if (size > ssize) /* more than what's left ? */ | |
3859 | size = ssize; | |
3860 | } | |
3861 | ||
3862 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM); | |
3863 | _bfd_vms_output_long (recwr, (unsigned long) (size)); | |
3864 | _bfd_vms_output_dump (recwr, cptr, size); | |
3865 | _bfd_vms_output_end_subrec (recwr); | |
3866 | ||
3867 | #if VMS_DEBUG | |
3868 | _bfd_vms_debug (10, "dumped %d bytes\n", (int) size); | |
3869 | _bfd_hexdump (10, cptr, (int) size, (int) vaddr); | |
3870 | #endif | |
3871 | ||
3872 | vaddr += size; | |
3873 | cptr += size; | |
3874 | ssize -= size; | |
3875 | } | |
3876 | } | |
3877 | ||
3878 | static void | |
3879 | etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen) | |
3880 | { | |
3881 | if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0) | |
3882 | { | |
3883 | /* Not enough room in this record. Close it and open a new one. */ | |
3884 | end_etir_record (abfd); | |
3885 | start_etir_or_etbt_record (abfd, section, vaddr); | |
3886 | } | |
3887 | } | |
3888 | ||
3889 | /* Return whether RELOC must be deferred till the end. */ | |
3890 | ||
3891 | static bfd_boolean | |
3892 | defer_reloc_p (arelent *reloc) | |
3893 | { | |
3894 | switch (reloc->howto->type) | |
3895 | { | |
3896 | case ALPHA_R_NOP: | |
3897 | case ALPHA_R_LDA: | |
3898 | case ALPHA_R_BSR: | |
3899 | case ALPHA_R_BOH: | |
3900 | return TRUE; | |
3901 | ||
3902 | default: | |
3903 | return FALSE; | |
3904 | } | |
3905 | } | |
3906 | ||
3907 | /* Write section contents for bfd abfd. Return FALSE on error. */ | |
3908 | ||
3909 | static bfd_boolean | |
3910 | _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) | |
3911 | { | |
3912 | asection *section; | |
3913 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3914 | ||
3915 | vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype)); | |
3916 | ||
3917 | _bfd_vms_output_alignment (recwr, 4); | |
3918 | ||
f1bb0388 | 3919 | PRIV (vms_linkage_index) = 0; |
95e34ef7 TG |
3920 | |
3921 | for (section = abfd->sections; section; section = section->next) | |
3922 | { | |
3923 | vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n", | |
07d6d2b8 | 3924 | section->target_index, section->name, (int) (section->size))); |
95e34ef7 TG |
3925 | |
3926 | if (!(section->flags & SEC_HAS_CONTENTS) | |
3927 | || bfd_is_com_section (section)) | |
3928 | continue; | |
3929 | ||
3930 | if (!section->contents) | |
3931 | { | |
3932 | bfd_set_error (bfd_error_no_contents); | |
3933 | return FALSE; | |
3934 | } | |
3935 | ||
3936 | start_etir_or_etbt_record (abfd, section, 0); | |
3937 | ||
3938 | if (section->flags & SEC_RELOC) | |
3939 | { | |
3940 | bfd_vma curr_addr = 0; | |
3941 | unsigned char *curr_data = section->contents; | |
3942 | bfd_size_type size; | |
3943 | int pass2_needed = 0; | |
3944 | int pass2_in_progress = 0; | |
3945 | unsigned int irel; | |
3946 | ||
083faca9 | 3947 | if (section->reloc_count == 0) |
4eca0228 | 3948 | _bfd_error_handler |
871b3ab2 | 3949 | (_("SEC_RELOC with no relocs in section %pA"), section); |
95e34ef7 TG |
3950 | |
3951 | #if VMS_DEBUG | |
3952 | else | |
3953 | { | |
3954 | int i = section->reloc_count; | |
3955 | arelent **rptr = section->orelocation; | |
3956 | _bfd_vms_debug (4, "%d relocations:\n", i); | |
3957 | while (i-- > 0) | |
3958 | { | |
3959 | _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, " | |
3960 | "addr %08lx, off %08lx, len %d: %s\n", | |
3961 | (*(*rptr)->sym_ptr_ptr)->name, | |
3962 | (*(*rptr)->sym_ptr_ptr)->section->name, | |
3963 | (long) (*(*rptr)->sym_ptr_ptr)->value, | |
3964 | (unsigned long)(*rptr)->address, | |
07d6d2b8 | 3965 | (unsigned long)(*rptr)->addend, |
95e34ef7 | 3966 | bfd_get_reloc_size ((*rptr)->howto), |
07d6d2b8 | 3967 | ( *rptr)->howto->name); |
95e34ef7 TG |
3968 | rptr++; |
3969 | } | |
3970 | } | |
3971 | #endif | |
3972 | ||
3973 | new_pass: | |
3974 | for (irel = 0; irel < section->reloc_count; irel++) | |
3975 | { | |
3976 | struct evax_private_udata_struct *udata; | |
3977 | arelent *rptr = section->orelocation [irel]; | |
3978 | bfd_vma addr = rptr->address; | |
3979 | asymbol *sym = *rptr->sym_ptr_ptr; | |
3980 | asection *sec = sym->section; | |
3981 | bfd_boolean defer = defer_reloc_p (rptr); | |
3982 | unsigned int slen; | |
95e34ef7 TG |
3983 | |
3984 | if (pass2_in_progress) | |
3985 | { | |
3986 | /* Non-deferred relocs have already been output. */ | |
3987 | if (!defer) | |
3988 | continue; | |
3989 | } | |
3990 | else | |
3991 | { | |
3992 | /* Deferred relocs must be output at the very end. */ | |
3993 | if (defer) | |
3994 | { | |
3995 | pass2_needed = 1; | |
3996 | continue; | |
3997 | } | |
3998 | ||
3999 | /* Regular relocs are intertwined with binary data. */ | |
07d6d2b8 | 4000 | if (curr_addr > addr) |
38f14ab8 | 4001 | _bfd_error_handler (_("size error in section %pA"), |
dae82561 | 4002 | section); |
95e34ef7 TG |
4003 | size = addr - curr_addr; |
4004 | sto_imm (abfd, section, size, curr_data, curr_addr); | |
4005 | curr_data += size; | |
4006 | curr_addr += size; | |
4007 | } | |
4008 | ||
4009 | size = bfd_get_reloc_size (rptr->howto); | |
4010 | ||
4011 | switch (rptr->howto->type) | |
07d6d2b8 | 4012 | { |
95e34ef7 TG |
4013 | case ALPHA_R_IGNORE: |
4014 | break; | |
4015 | ||
4016 | case ALPHA_R_REFLONG: | |
4017 | if (bfd_is_und_section (sym->section)) | |
4018 | { | |
4019 | bfd_vma addend = rptr->addend; | |
4020 | slen = strlen ((char *) sym->name); | |
95e34ef7 TG |
4021 | etir_output_check (abfd, section, curr_addr, slen); |
4022 | if (addend) | |
4023 | { | |
4024 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); | |
53452371 | 4025 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4026 | _bfd_vms_output_end_subrec (recwr); |
4027 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); | |
4028 | _bfd_vms_output_long (recwr, (unsigned long) addend); | |
4029 | _bfd_vms_output_end_subrec (recwr); | |
4030 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); | |
4031 | _bfd_vms_output_end_subrec (recwr); | |
4032 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4033 | _bfd_vms_output_end_subrec (recwr); | |
4034 | } | |
4035 | else | |
4036 | { | |
4037 | _bfd_vms_output_begin_subrec | |
07d6d2b8 | 4038 | (recwr, ETIR__C_STO_GBL_LW); |
53452371 | 4039 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4040 | _bfd_vms_output_end_subrec (recwr); |
4041 | } | |
4042 | } | |
4043 | else if (bfd_is_abs_section (sym->section)) | |
4044 | { | |
4045 | etir_output_check (abfd, section, curr_addr, 16); | |
4046 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); | |
4047 | _bfd_vms_output_long (recwr, (unsigned long) sym->value); | |
4048 | _bfd_vms_output_end_subrec (recwr); | |
4049 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4050 | _bfd_vms_output_end_subrec (recwr); | |
4051 | } | |
4052 | else | |
4053 | { | |
4054 | etir_output_check (abfd, section, curr_addr, 32); | |
4055 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); | |
1b3d1dbf | 4056 | _bfd_vms_output_long (recwr, |
07d6d2b8 | 4057 | (unsigned long) sec->target_index); |
95e34ef7 TG |
4058 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4059 | _bfd_vms_output_end_subrec (recwr); | |
4060 | /* ??? Table B-8 of the OpenVMS Linker Utilily Manual | |
4061 | says that we should have a ETIR__C_STO_OFF here. | |
4062 | But the relocation would not be BFD_RELOC_32 then. | |
4063 | This case is very likely unreachable. */ | |
4064 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4065 | _bfd_vms_output_end_subrec (recwr); | |
4066 | } | |
4067 | break; | |
4068 | ||
4069 | case ALPHA_R_REFQUAD: | |
4070 | if (bfd_is_und_section (sym->section)) | |
4071 | { | |
4072 | bfd_vma addend = rptr->addend; | |
4073 | slen = strlen ((char *) sym->name); | |
95e34ef7 TG |
4074 | etir_output_check (abfd, section, curr_addr, slen); |
4075 | if (addend) | |
4076 | { | |
4077 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); | |
53452371 | 4078 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4079 | _bfd_vms_output_end_subrec (recwr); |
4080 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); | |
4081 | _bfd_vms_output_quad (recwr, addend); | |
4082 | _bfd_vms_output_end_subrec (recwr); | |
4083 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); | |
4084 | _bfd_vms_output_end_subrec (recwr); | |
4085 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); | |
4086 | _bfd_vms_output_end_subrec (recwr); | |
4087 | } | |
4088 | else | |
4089 | { | |
4090 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL); | |
53452371 | 4091 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4092 | _bfd_vms_output_end_subrec (recwr); |
4093 | } | |
4094 | } | |
4095 | else if (bfd_is_abs_section (sym->section)) | |
4096 | { | |
4097 | etir_output_check (abfd, section, curr_addr, 16); | |
4098 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); | |
4099 | _bfd_vms_output_quad (recwr, sym->value); | |
4100 | _bfd_vms_output_end_subrec (recwr); | |
4101 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); | |
4102 | _bfd_vms_output_end_subrec (recwr); | |
4103 | } | |
4104 | else | |
4105 | { | |
4106 | etir_output_check (abfd, section, curr_addr, 32); | |
4107 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); | |
1b3d1dbf | 4108 | _bfd_vms_output_long (recwr, |
07d6d2b8 | 4109 | (unsigned long) sec->target_index); |
95e34ef7 TG |
4110 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4111 | _bfd_vms_output_end_subrec (recwr); | |
4112 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF); | |
4113 | _bfd_vms_output_end_subrec (recwr); | |
4114 | } | |
4115 | break; | |
4116 | ||
4117 | case ALPHA_R_HINT: | |
4118 | sto_imm (abfd, section, size, curr_data, curr_addr); | |
4119 | break; | |
4120 | ||
4121 | case ALPHA_R_LINKAGE: | |
706704c8 | 4122 | size = 16; |
95e34ef7 TG |
4123 | etir_output_check (abfd, section, curr_addr, 64); |
4124 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB); | |
4125 | _bfd_vms_output_long | |
25d41743 | 4126 | (recwr, (unsigned long) rptr->addend); |
07d6d2b8 AM |
4127 | if (rptr->addend > PRIV (vms_linkage_index)) |
4128 | PRIV (vms_linkage_index) = rptr->addend; | |
53452371 | 4129 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4130 | _bfd_vms_output_byte (recwr, 0); |
4131 | _bfd_vms_output_end_subrec (recwr); | |
4132 | break; | |
4133 | ||
4134 | case ALPHA_R_CODEADDR: | |
4135 | slen = strlen ((char *) sym->name); | |
95e34ef7 TG |
4136 | etir_output_check (abfd, section, curr_addr, slen); |
4137 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA); | |
53452371 | 4138 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4139 | _bfd_vms_output_end_subrec (recwr); |
4140 | break; | |
4141 | ||
4142 | case ALPHA_R_NOP: | |
4143 | udata | |
4144 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
4145 | etir_output_check (abfd, section, curr_addr, | |
4146 | 32 + 1 + strlen (udata->origname)); | |
4147 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL); | |
4148 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); | |
4149 | _bfd_vms_output_long | |
a8efca92 | 4150 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4151 | _bfd_vms_output_quad (recwr, rptr->address); |
4152 | _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f); | |
4153 | _bfd_vms_output_long | |
a8efca92 | 4154 | (recwr, (unsigned long) section->target_index); |
95e34ef7 | 4155 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4156 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4157 | _bfd_vms_output_end_subrec (recwr); |
4158 | break; | |
4159 | ||
4160 | case ALPHA_R_BSR: | |
38f14ab8 | 4161 | _bfd_error_handler (_("spurious ALPHA_R_BSR reloc")); |
95e34ef7 TG |
4162 | break; |
4163 | ||
4164 | case ALPHA_R_LDA: | |
4165 | udata | |
4166 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
4167 | etir_output_check (abfd, section, curr_addr, | |
4168 | 32 + 1 + strlen (udata->origname)); | |
4169 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL); | |
4170 | _bfd_vms_output_long | |
4171 | (recwr, (unsigned long) udata->lkindex + 1); | |
4172 | _bfd_vms_output_long | |
a8efca92 | 4173 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4174 | _bfd_vms_output_quad (recwr, rptr->address); |
4175 | _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000); | |
4176 | _bfd_vms_output_long | |
1b3d1dbf | 4177 | (recwr, (unsigned long) udata->bsym->section->target_index); |
95e34ef7 | 4178 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4179 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4180 | _bfd_vms_output_end_subrec (recwr); |
4181 | break; | |
4182 | ||
4183 | case ALPHA_R_BOH: | |
4184 | udata | |
4185 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
4186 | etir_output_check (abfd, section, curr_addr, | |
4187 | 32 + 1 + strlen (udata->origname)); | |
4188 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL); | |
4189 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); | |
4190 | _bfd_vms_output_long | |
a8efca92 | 4191 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4192 | _bfd_vms_output_quad (recwr, rptr->address); |
4193 | _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000); | |
4194 | _bfd_vms_output_long | |
a8efca92 | 4195 | (recwr, (unsigned long) section->target_index); |
95e34ef7 | 4196 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4197 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4198 | _bfd_vms_output_end_subrec (recwr); |
4199 | break; | |
4200 | ||
4201 | default: | |
38f14ab8 | 4202 | _bfd_error_handler (_("unhandled relocation %s"), |
4eca0228 | 4203 | rptr->howto->name); |
95e34ef7 TG |
4204 | break; |
4205 | } | |
4206 | ||
4207 | curr_data += size; | |
4208 | curr_addr += size; | |
4209 | } /* End of relocs loop. */ | |
4210 | ||
4211 | if (!pass2_in_progress) | |
4212 | { | |
4213 | /* Output rest of section. */ | |
4214 | if (curr_addr > section->size) | |
9ec2f606 AM |
4215 | { |
4216 | _bfd_error_handler (_("size error in section %pA"), section); | |
4217 | return FALSE; | |
4218 | } | |
95e34ef7 TG |
4219 | size = section->size - curr_addr; |
4220 | sto_imm (abfd, section, size, curr_data, curr_addr); | |
4221 | curr_data += size; | |
4222 | curr_addr += size; | |
4223 | ||
4224 | if (pass2_needed) | |
4225 | { | |
4226 | pass2_in_progress = 1; | |
4227 | goto new_pass; | |
4228 | } | |
4229 | } | |
4230 | } | |
4231 | ||
4232 | else /* (section->flags & SEC_RELOC) */ | |
4233 | sto_imm (abfd, section, section->size, section->contents, 0); | |
4234 | ||
4235 | end_etir_record (abfd); | |
4236 | } | |
4237 | ||
4238 | _bfd_vms_output_alignment (recwr, 2); | |
4239 | return TRUE; | |
4240 | } | |
4241 | ||
95e34ef7 TG |
4242 | /* Write cached information into a file being written, at bfd_close. */ |
4243 | ||
4244 | static bfd_boolean | |
4245 | alpha_vms_write_object_contents (bfd *abfd) | |
4246 | { | |
4247 | vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd)); | |
4248 | ||
4249 | if (abfd->flags & (EXEC_P | DYNAMIC)) | |
4250 | { | |
4251 | return alpha_vms_write_exec (abfd); | |
4252 | } | |
4253 | else | |
4254 | { | |
4255 | if (abfd->section_count > 0) /* we have sections */ | |
07d6d2b8 AM |
4256 | { |
4257 | if (!_bfd_vms_write_ehdr (abfd)) | |
4258 | return FALSE; | |
4259 | if (!_bfd_vms_write_egsd (abfd)) | |
4260 | return FALSE; | |
4261 | if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR)) | |
4262 | return FALSE; | |
4263 | if (!_bfd_vms_write_eeom (abfd)) | |
4264 | return FALSE; | |
4265 | } | |
95e34ef7 TG |
4266 | } |
4267 | return TRUE; | |
4268 | } | |
4269 | \f | |
4270 | /* Debug stuff: nearest line. */ | |
4271 | ||
4272 | #define SET_MODULE_PARSED(m) \ | |
4273 | do { if ((m)->name == NULL) (m)->name = ""; } while (0) | |
4274 | #define IS_MODULE_PARSED(m) ((m)->name != NULL) | |
4275 | ||
4276 | /* Build a new module for the specified BFD. */ | |
4277 | ||
4278 | static struct module * | |
4279 | new_module (bfd *abfd) | |
4280 | { | |
4281 | struct module *module | |
4282 | = (struct module *) bfd_zalloc (abfd, sizeof (struct module)); | |
4283 | module->file_table_count = 16; /* Arbitrary. */ | |
4284 | module->file_table | |
4285 | = bfd_malloc (module->file_table_count * sizeof (struct fileinfo)); | |
4286 | return module; | |
4287 | } | |
4288 | ||
4289 | /* Parse debug info for a module and internalize it. */ | |
4290 | ||
9cb56943 | 4291 | static bfd_boolean |
95e34ef7 TG |
4292 | parse_module (bfd *abfd, struct module *module, unsigned char *ptr, |
4293 | int length) | |
4294 | { | |
4295 | unsigned char *maxptr = ptr + length; | |
4296 | unsigned char *src_ptr, *pcl_ptr; | |
4297 | unsigned int prev_linum = 0, curr_linenum = 0; | |
4298 | bfd_vma prev_pc = 0, curr_pc = 0; | |
4299 | struct srecinfo *curr_srec, *srec; | |
4300 | struct lineinfo *curr_line, *line; | |
4301 | struct funcinfo *funcinfo; | |
4302 | ||
4303 | /* Initialize tables with zero element. */ | |
4304 | curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4305 | module->srec_table = curr_srec; | |
4306 | ||
4307 | curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
4308 | module->line_table = curr_line; | |
4309 | ||
4310 | while (length == -1 || ptr < maxptr) | |
4311 | { | |
4312 | /* The first byte is not counted in the recorded length. */ | |
4313 | int rec_length = bfd_getl16 (ptr) + 1; | |
4314 | int rec_type = bfd_getl16 (ptr + 2); | |
4315 | ||
4316 | vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type)); | |
4317 | ||
4318 | if (length == -1 && rec_type == DST__K_MODEND) | |
07d6d2b8 | 4319 | break; |
95e34ef7 TG |
4320 | |
4321 | switch (rec_type) | |
4322 | { | |
4323 | case DST__K_MODBEG: | |
4324 | module->name | |
37d2e9c7 | 4325 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME, |
7adc0a81 | 4326 | maxptr - (ptr + DST_S_B_MODBEG_NAME)); |
95e34ef7 TG |
4327 | |
4328 | curr_pc = 0; | |
4329 | prev_pc = 0; | |
4330 | curr_linenum = 0; | |
4331 | prev_linum = 0; | |
4332 | ||
07d6d2b8 | 4333 | vms_debug2 ((3, "module: %s\n", module->name)); |
95e34ef7 TG |
4334 | break; |
4335 | ||
4336 | case DST__K_MODEND: | |
4337 | break; | |
4338 | ||
4339 | case DST__K_RTNBEG: | |
4340 | funcinfo = (struct funcinfo *) | |
4341 | bfd_zalloc (abfd, sizeof (struct funcinfo)); | |
07d6d2b8 | 4342 | funcinfo->name |
37d2e9c7 | 4343 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME, |
7adc0a81 | 4344 | maxptr - (ptr + DST_S_B_RTNBEG_NAME)); |
95e34ef7 TG |
4345 | funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS); |
4346 | funcinfo->next = module->func_table; | |
4347 | module->func_table = funcinfo; | |
4348 | ||
07d6d2b8 AM |
4349 | vms_debug2 ((3, "routine: %s at 0x%lx\n", |
4350 | funcinfo->name, (unsigned long) funcinfo->low)); | |
95e34ef7 TG |
4351 | break; |
4352 | ||
4353 | case DST__K_RTNEND: | |
4354 | module->func_table->high = module->func_table->low | |
4355 | + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1; | |
4356 | ||
4357 | if (module->func_table->high > module->high) | |
4358 | module->high = module->func_table->high; | |
4359 | ||
07d6d2b8 | 4360 | vms_debug2 ((3, "end routine\n")); |
95e34ef7 TG |
4361 | break; |
4362 | ||
4363 | case DST__K_PROLOG: | |
07d6d2b8 | 4364 | vms_debug2 ((3, "prologue\n")); |
95e34ef7 TG |
4365 | break; |
4366 | ||
4367 | case DST__K_EPILOG: | |
07d6d2b8 | 4368 | vms_debug2 ((3, "epilog\n")); |
95e34ef7 TG |
4369 | break; |
4370 | ||
4371 | case DST__K_BLKBEG: | |
07d6d2b8 | 4372 | vms_debug2 ((3, "block\n")); |
95e34ef7 TG |
4373 | break; |
4374 | ||
4375 | case DST__K_BLKEND: | |
07d6d2b8 | 4376 | vms_debug2 ((3, "end block\n")); |
95e34ef7 TG |
4377 | break; |
4378 | ||
4379 | case DST__K_SOURCE: | |
4380 | src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE; | |
4381 | ||
4382 | vms_debug2 ((3, "source info\n")); | |
4383 | ||
4384 | while (src_ptr < ptr + rec_length) | |
4385 | { | |
4386 | int cmd = src_ptr[0], cmd_length, data; | |
4387 | ||
4388 | switch (cmd) | |
4389 | { | |
4390 | case DST__K_SRC_DECLFILE: | |
4391 | { | |
4392 | unsigned int fileid | |
4393 | = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID); | |
37d2e9c7 AM |
4394 | char *filename = _bfd_vms_save_counted_string |
4395 | (abfd, | |
4396 | src_ptr + DST_S_B_SRC_DF_FILENAME, | |
4397 | ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME)); | |
95e34ef7 TG |
4398 | |
4399 | while (fileid >= module->file_table_count) | |
4400 | { | |
4401 | module->file_table_count *= 2; | |
4402 | module->file_table | |
9cb56943 AM |
4403 | = bfd_realloc_or_free (module->file_table, |
4404 | module->file_table_count | |
4405 | * sizeof (struct fileinfo)); | |
4406 | if (module->file_table == NULL) | |
4407 | return FALSE; | |
95e34ef7 TG |
4408 | } |
4409 | ||
4410 | module->file_table [fileid].name = filename; | |
4411 | module->file_table [fileid].srec = 1; | |
4412 | cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2; | |
4413 | vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n", | |
07d6d2b8 | 4414 | fileid, module->file_table [fileid].name)); |
95e34ef7 TG |
4415 | } |
4416 | break; | |
4417 | ||
4418 | case DST__K_SRC_DEFLINES_B: | |
4419 | /* Perform the association and set the next higher index | |
4420 | to the limit. */ | |
4421 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; | |
4422 | srec = (struct srecinfo *) | |
4423 | bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4424 | srec->line = curr_srec->line + data; | |
4425 | srec->srec = curr_srec->srec + data; | |
4426 | srec->sfile = curr_srec->sfile; | |
4427 | curr_srec->next = srec; | |
4428 | curr_srec = srec; | |
4429 | cmd_length = 2; | |
4430 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data)); | |
4431 | break; | |
4432 | ||
4433 | case DST__K_SRC_DEFLINES_W: | |
4434 | /* Perform the association and set the next higher index | |
4435 | to the limit. */ | |
4436 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4437 | srec = (struct srecinfo *) | |
4438 | bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4439 | srec->line = curr_srec->line + data; | |
4440 | srec->srec = curr_srec->srec + data, | |
4441 | srec->sfile = curr_srec->sfile; | |
4442 | curr_srec->next = srec; | |
4443 | curr_srec = srec; | |
4444 | cmd_length = 3; | |
4445 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data)); | |
4446 | break; | |
4447 | ||
4448 | case DST__K_SRC_INCRLNUM_B: | |
4449 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; | |
4450 | curr_srec->line += data; | |
4451 | cmd_length = 2; | |
4452 | vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data)); | |
4453 | break; | |
4454 | ||
4455 | case DST__K_SRC_SETFILE: | |
4456 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4457 | curr_srec->sfile = data; | |
4458 | curr_srec->srec = module->file_table[data].srec; | |
4459 | cmd_length = 3; | |
4460 | vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data)); | |
4461 | break; | |
4462 | ||
4463 | case DST__K_SRC_SETLNUM_L: | |
4464 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); | |
4465 | curr_srec->line = data; | |
4466 | cmd_length = 5; | |
4467 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data)); | |
4468 | break; | |
4469 | ||
4470 | case DST__K_SRC_SETLNUM_W: | |
4471 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4472 | curr_srec->line = data; | |
4473 | cmd_length = 3; | |
4474 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data)); | |
4475 | break; | |
4476 | ||
4477 | case DST__K_SRC_SETREC_L: | |
4478 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); | |
4479 | curr_srec->srec = data; | |
4480 | module->file_table[curr_srec->sfile].srec = data; | |
4481 | cmd_length = 5; | |
4482 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data)); | |
4483 | break; | |
4484 | ||
4485 | case DST__K_SRC_SETREC_W: | |
4486 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4487 | curr_srec->srec = data; | |
4488 | module->file_table[curr_srec->sfile].srec = data; | |
4489 | cmd_length = 3; | |
4490 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data)); | |
4491 | break; | |
4492 | ||
4493 | case DST__K_SRC_FORMFEED: | |
4494 | cmd_length = 1; | |
4495 | vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n")); | |
4496 | break; | |
4497 | ||
4498 | default: | |
4eca0228 AM |
4499 | _bfd_error_handler (_("unknown source command %d"), |
4500 | cmd); | |
95e34ef7 TG |
4501 | cmd_length = 2; |
4502 | break; | |
4503 | } | |
4504 | ||
4505 | src_ptr += cmd_length; | |
4506 | } | |
4507 | break; | |
4508 | ||
4509 | case DST__K_LINE_NUM: | |
4510 | pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE; | |
4511 | ||
4512 | vms_debug2 ((3, "line info\n")); | |
4513 | ||
4514 | while (pcl_ptr < ptr + rec_length) | |
4515 | { | |
4516 | /* The command byte is signed so we must sign-extend it. */ | |
4517 | int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data; | |
4518 | ||
4519 | switch (cmd) | |
4520 | { | |
4521 | case DST__K_DELTA_PC_W: | |
4522 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4523 | curr_pc += data; | |
4524 | curr_linenum += 1; | |
4525 | cmd_length = 3; | |
4526 | vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data)); | |
4527 | break; | |
4528 | ||
4529 | case DST__K_DELTA_PC_L: | |
4530 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4531 | curr_pc += data; | |
4532 | curr_linenum += 1; | |
4533 | cmd_length = 5; | |
4534 | vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data)); | |
4535 | break; | |
4536 | ||
4537 | case DST__K_INCR_LINUM: | |
4538 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4539 | curr_linenum += data; | |
4540 | cmd_length = 2; | |
4541 | vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data)); | |
4542 | break; | |
4543 | ||
4544 | case DST__K_INCR_LINUM_W: | |
4545 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4546 | curr_linenum += data; | |
4547 | cmd_length = 3; | |
4548 | vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data)); | |
4549 | break; | |
4550 | ||
4551 | case DST__K_INCR_LINUM_L: | |
4552 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4553 | curr_linenum += data; | |
4554 | cmd_length = 5; | |
4555 | vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data)); | |
4556 | break; | |
4557 | ||
4558 | case DST__K_SET_LINUM_INCR: | |
4eca0228 | 4559 | _bfd_error_handler |
38f14ab8 | 4560 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR"); |
95e34ef7 TG |
4561 | cmd_length = 2; |
4562 | break; | |
4563 | ||
4564 | case DST__K_SET_LINUM_INCR_W: | |
4eca0228 | 4565 | _bfd_error_handler |
38f14ab8 | 4566 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W"); |
95e34ef7 TG |
4567 | cmd_length = 3; |
4568 | break; | |
4569 | ||
4570 | case DST__K_RESET_LINUM_INCR: | |
4eca0228 | 4571 | _bfd_error_handler |
38f14ab8 | 4572 | (_("%s not implemented"), "DST__K_RESET_LINUM_INCR"); |
95e34ef7 TG |
4573 | cmd_length = 1; |
4574 | break; | |
4575 | ||
4576 | case DST__K_BEG_STMT_MODE: | |
4eca0228 | 4577 | _bfd_error_handler |
38f14ab8 | 4578 | (_("%s not implemented"), "DST__K_BEG_STMT_MODE"); |
95e34ef7 TG |
4579 | cmd_length = 1; |
4580 | break; | |
4581 | ||
4582 | case DST__K_END_STMT_MODE: | |
4eca0228 | 4583 | _bfd_error_handler |
38f14ab8 | 4584 | (_("%s not implemented"), "DST__K_END_STMT_MODE"); |
95e34ef7 TG |
4585 | cmd_length = 1; |
4586 | break; | |
4587 | ||
4588 | case DST__K_SET_LINUM_B: | |
4589 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4590 | curr_linenum = data; | |
4591 | cmd_length = 2; | |
4592 | vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data)); | |
4593 | break; | |
4594 | ||
4595 | case DST__K_SET_LINUM: | |
4596 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4597 | curr_linenum = data; | |
4598 | cmd_length = 3; | |
4599 | vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data)); | |
4600 | break; | |
4601 | ||
4602 | case DST__K_SET_LINUM_L: | |
4603 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4604 | curr_linenum = data; | |
4605 | cmd_length = 5; | |
4606 | vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data)); | |
4607 | break; | |
4608 | ||
4609 | case DST__K_SET_PC: | |
4eca0228 | 4610 | _bfd_error_handler |
38f14ab8 | 4611 | (_("%s not implemented"), "DST__K_SET_PC"); |
95e34ef7 TG |
4612 | cmd_length = 2; |
4613 | break; | |
4614 | ||
4615 | case DST__K_SET_PC_W: | |
4eca0228 | 4616 | _bfd_error_handler |
38f14ab8 | 4617 | (_("%s not implemented"), "DST__K_SET_PC_W"); |
95e34ef7 TG |
4618 | cmd_length = 3; |
4619 | break; | |
4620 | ||
4621 | case DST__K_SET_PC_L: | |
4eca0228 | 4622 | _bfd_error_handler |
38f14ab8 | 4623 | (_("%s not implemented"), "DST__K_SET_PC_L"); |
95e34ef7 TG |
4624 | cmd_length = 5; |
4625 | break; | |
4626 | ||
4627 | case DST__K_SET_STMTNUM: | |
4eca0228 | 4628 | _bfd_error_handler |
38f14ab8 | 4629 | (_("%s not implemented"), "DST__K_SET_STMTNUM"); |
95e34ef7 TG |
4630 | cmd_length = 2; |
4631 | break; | |
4632 | ||
4633 | case DST__K_TERM: | |
4634 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4635 | curr_pc += data; | |
4636 | cmd_length = 2; | |
4637 | vms_debug2 ((4, "DST__K_TERM: %d\n", data)); | |
4638 | break; | |
4639 | ||
4640 | case DST__K_TERM_W: | |
4641 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4642 | curr_pc += data; | |
4643 | cmd_length = 3; | |
4644 | vms_debug2 ((4, "DST__K_TERM_W: %d\n", data)); | |
4645 | break; | |
4646 | ||
4647 | case DST__K_TERM_L: | |
4648 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4649 | curr_pc += data; | |
4650 | cmd_length = 5; | |
4651 | vms_debug2 ((4, "DST__K_TERM_L: %d\n", data)); | |
4652 | break; | |
4653 | ||
4654 | case DST__K_SET_ABS_PC: | |
4655 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4656 | curr_pc = data; | |
4657 | cmd_length = 5; | |
4658 | vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data)); | |
4659 | break; | |
4660 | ||
4661 | default: | |
4662 | if (cmd <= 0) | |
4663 | { | |
4664 | curr_pc -= cmd; | |
4665 | curr_linenum += 1; | |
4666 | cmd_length = 1; | |
4667 | vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n", | |
07d6d2b8 | 4668 | (unsigned long)curr_pc, curr_linenum)); |
95e34ef7 TG |
4669 | } |
4670 | else | |
4671 | { | |
4eca0228 | 4672 | _bfd_error_handler (_("unknown line command %d"), cmd); |
95e34ef7 TG |
4673 | cmd_length = 2; |
4674 | } | |
4675 | break; | |
4676 | } | |
4677 | ||
4678 | if ((curr_linenum != prev_linum && curr_pc != prev_pc) | |
4679 | || cmd <= 0 | |
4680 | || cmd == DST__K_DELTA_PC_L | |
4681 | || cmd == DST__K_DELTA_PC_W) | |
4682 | { | |
4683 | line = (struct lineinfo *) | |
4684 | bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
4685 | line->address = curr_pc; | |
4686 | line->line = curr_linenum; | |
4687 | ||
4688 | curr_line->next = line; | |
4689 | curr_line = line; | |
4690 | ||
4691 | prev_linum = curr_linenum; | |
4692 | prev_pc = curr_pc; | |
4693 | vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n", | |
07d6d2b8 | 4694 | (unsigned long)curr_pc, curr_linenum)); |
95e34ef7 TG |
4695 | } |
4696 | ||
4697 | pcl_ptr += cmd_length; | |
4698 | } | |
4699 | break; | |
4700 | ||
4701 | case 0x17: /* Undocumented type used by DEC C to declare equates. */ | |
4702 | vms_debug2 ((3, "undocumented type 0x17\n")); | |
4703 | break; | |
4704 | ||
4705 | default: | |
4706 | vms_debug2 ((3, "ignoring record\n")); | |
4707 | break; | |
4708 | ||
4709 | } | |
4710 | ||
4711 | ptr += rec_length; | |
4712 | } | |
4713 | ||
4714 | /* Finalize tables with EOL marker. */ | |
4715 | srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4716 | srec->line = (unsigned int) -1; | |
4717 | srec->srec = (unsigned int) -1; | |
4718 | curr_srec->next = srec; | |
4719 | ||
4720 | line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
4721 | line->line = (unsigned int) -1; | |
4722 | line->address = (bfd_vma) -1; | |
4723 | curr_line->next = line; | |
4724 | ||
4725 | /* Advertise that this module has been parsed. This is needed | |
4726 | because parsing can be either performed at module creation | |
4727 | or deferred until debug info is consumed. */ | |
4728 | SET_MODULE_PARSED (module); | |
9cb56943 | 4729 | return TRUE; |
95e34ef7 TG |
4730 | } |
4731 | ||
4732 | /* Build the list of modules for the specified BFD. */ | |
4733 | ||
4734 | static struct module * | |
4735 | build_module_list (bfd *abfd) | |
4736 | { | |
4737 | struct module *module, *list = NULL; | |
4738 | asection *dmt; | |
4739 | ||
4740 | if ((dmt = bfd_get_section_by_name (abfd, "$DMT$"))) | |
4741 | { | |
4742 | /* We have a DMT section so this must be an image. Parse the | |
4743 | section and build the list of modules. This is sufficient | |
4744 | since we can compute the start address and the end address | |
4745 | of every module from the section contents. */ | |
fd361982 | 4746 | bfd_size_type size = bfd_section_size (dmt); |
95e34ef7 TG |
4747 | unsigned char *ptr, *end; |
4748 | ||
4749 | ptr = (unsigned char *) bfd_alloc (abfd, size); | |
4750 | if (! ptr) | |
4751 | return NULL; | |
4752 | ||
4753 | if (! bfd_get_section_contents (abfd, dmt, ptr, 0, size)) | |
4754 | return NULL; | |
4755 | ||
4756 | vms_debug2 ((2, "DMT\n")); | |
4757 | ||
4758 | end = ptr + size; | |
4759 | ||
4760 | while (ptr < end) | |
4761 | { | |
4762 | /* Each header declares a module with its start offset and size | |
4763 | of debug info in the DST section, as well as the count of | |
4764 | program sections (i.e. address spans) it contains. */ | |
4765 | int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG); | |
4766 | int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE); | |
4767 | int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT); | |
4768 | ptr += DBG_S_C_DMT_HEADER_SIZE; | |
4769 | ||
4770 | vms_debug2 ((3, "module: modbeg = %d, size = %d, count = %d\n", | |
07d6d2b8 | 4771 | modbeg, msize, count)); |
95e34ef7 TG |
4772 | |
4773 | /* We create a 'module' structure for each program section since | |
4774 | we only support contiguous addresses in a 'module' structure. | |
4775 | As a consequence, the actual debug info in the DST section is | |
4776 | shared and can be parsed multiple times; that doesn't seem to | |
4777 | cause problems in practice. */ | |
4778 | while (count-- > 0) | |
4779 | { | |
4780 | int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START); | |
4781 | int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH); | |
4782 | module = new_module (abfd); | |
4783 | module->modbeg = modbeg; | |
4784 | module->size = msize; | |
4785 | module->low = start; | |
4786 | module->high = start + length; | |
4787 | module->next = list; | |
4788 | list = module; | |
4789 | ptr += DBG_S_C_DMT_PSECT_SIZE; | |
4790 | ||
4791 | vms_debug2 ((4, "section: start = 0x%x, length = %d\n", | |
07d6d2b8 | 4792 | start, length)); |
95e34ef7 TG |
4793 | } |
4794 | } | |
4795 | } | |
4796 | else | |
4797 | { | |
4798 | /* We don't have a DMT section so this must be an object. Parse | |
4799 | the module right now in order to compute its start address and | |
4800 | end address. */ | |
8185f55c TG |
4801 | void *dst = PRIV (dst_section)->contents; |
4802 | ||
4803 | if (dst == NULL) | |
07d6d2b8 | 4804 | return NULL; |
8185f55c | 4805 | |
95e34ef7 | 4806 | module = new_module (abfd); |
9cb56943 AM |
4807 | if (!parse_module (abfd, module, PRIV (dst_section)->contents, -1)) |
4808 | return NULL; | |
95e34ef7 TG |
4809 | list = module; |
4810 | } | |
4811 | ||
4812 | return list; | |
4813 | } | |
4814 | ||
4815 | /* Calculate and return the name of the source file and the line nearest | |
4816 | to the wanted location in the specified module. */ | |
4817 | ||
4818 | static bfd_boolean | |
4819 | module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr, | |
4820 | const char **file, const char **func, | |
4821 | unsigned int *line) | |
4822 | { | |
4823 | struct funcinfo *funcinfo; | |
4824 | struct lineinfo *lineinfo; | |
4825 | struct srecinfo *srecinfo; | |
4826 | bfd_boolean ret = FALSE; | |
4827 | ||
4828 | /* Parse this module if that was not done at module creation. */ | |
4829 | if (! IS_MODULE_PARSED (module)) | |
4830 | { | |
4831 | unsigned int size = module->size; | |
4832 | unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg; | |
2bb3687b | 4833 | unsigned char *buffer; |
95e34ef7 TG |
4834 | |
4835 | if (bfd_seek (abfd, modbeg, SEEK_SET) != 0 | |
2bb3687b | 4836 | || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL) |
95e34ef7 TG |
4837 | { |
4838 | bfd_set_error (bfd_error_no_debug_section); | |
4839 | return FALSE; | |
4840 | } | |
4841 | ||
9cb56943 | 4842 | ret = parse_module (abfd, module, buffer, size); |
95e34ef7 | 4843 | free (buffer); |
9cb56943 AM |
4844 | if (!ret) |
4845 | return ret; | |
95e34ef7 TG |
4846 | } |
4847 | ||
4848 | /* Find out the function (if any) that contains the address. */ | |
4849 | for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next) | |
4850 | if (addr >= funcinfo->low && addr <= funcinfo->high) | |
4851 | { | |
07d6d2b8 | 4852 | *func = funcinfo->name; |
95e34ef7 TG |
4853 | ret = TRUE; |
4854 | break; | |
4855 | } | |
4856 | ||
4857 | /* Find out the source file and the line nearest to the address. */ | |
4858 | for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next) | |
4859 | if (lineinfo->next && addr < lineinfo->next->address) | |
4860 | { | |
4861 | for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next) | |
4862 | if (srecinfo->next && lineinfo->line < srecinfo->next->line) | |
4863 | { | |
4864 | if (srecinfo->sfile > 0) | |
4865 | { | |
4866 | *file = module->file_table[srecinfo->sfile].name; | |
4867 | *line = srecinfo->srec + lineinfo->line - srecinfo->line; | |
4868 | } | |
4869 | else | |
4870 | { | |
4871 | *file = module->name; | |
4872 | *line = lineinfo->line; | |
4873 | } | |
4874 | return TRUE; | |
4875 | } | |
4876 | ||
4877 | break; | |
4878 | } | |
4879 | ||
4880 | return ret; | |
4881 | } | |
4882 | ||
4883 | /* Provided a BFD, a section and an offset into the section, calculate and | |
4884 | return the name of the source file and the line nearest to the wanted | |
4885 | location. */ | |
4886 | ||
4887 | static bfd_boolean | |
fb167eb2 AM |
4888 | _bfd_vms_find_nearest_line (bfd *abfd, |
4889 | asymbol **symbols ATTRIBUTE_UNUSED, | |
4890 | asection *section, | |
4891 | bfd_vma offset, | |
4892 | const char **file, | |
4893 | const char **func, | |
4894 | unsigned int *line, | |
4895 | unsigned int *discriminator) | |
95e34ef7 TG |
4896 | { |
4897 | struct module *module; | |
4898 | ||
4899 | /* What address are we looking for? */ | |
4900 | bfd_vma addr = section->vma + offset; | |
4901 | ||
4902 | *file = NULL; | |
4903 | *func = NULL; | |
4904 | *line = 0; | |
fb167eb2 AM |
4905 | if (discriminator) |
4906 | *discriminator = 0; | |
95e34ef7 | 4907 | |
8185f55c | 4908 | /* We can't do anything if there is no DST (debug symbol table). */ |
a283ff93 | 4909 | if (PRIV (dst_section) == NULL) |
95e34ef7 TG |
4910 | return FALSE; |
4911 | ||
8185f55c | 4912 | /* Create the module list - if not already done. */ |
95e34ef7 TG |
4913 | if (PRIV (modules) == NULL) |
4914 | { | |
4915 | PRIV (modules) = build_module_list (abfd); | |
4916 | if (PRIV (modules) == NULL) | |
07d6d2b8 | 4917 | return FALSE; |
95e34ef7 TG |
4918 | } |
4919 | ||
4920 | for (module = PRIV (modules); module; module = module->next) | |
4921 | if (addr >= module->low && addr <= module->high) | |
4922 | return module_find_nearest_line (abfd, module, addr, file, func, line); | |
4923 | ||
4924 | return FALSE; | |
4925 | } | |
4926 | \f | |
4927 | /* Canonicalizations. */ | |
4928 | /* Set name, value, section and flags of SYM from E. */ | |
4929 | ||
4930 | static bfd_boolean | |
4931 | alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym) | |
4932 | { | |
4933 | flagword flags; | |
4934 | symvalue value; | |
4935 | asection *sec; | |
4936 | const char *name; | |
4937 | ||
4938 | name = e->name; | |
4939 | value = 0; | |
4940 | flags = BSF_NO_FLAGS; | |
4941 | sec = NULL; | |
4942 | ||
4943 | switch (e->typ) | |
4944 | { | |
4945 | case EGSD__C_SYM: | |
4946 | if (e->flags & EGSY__V_WEAK) | |
07d6d2b8 | 4947 | flags |= BSF_WEAK; |
95e34ef7 TG |
4948 | |
4949 | if (e->flags & EGSY__V_DEF) | |
07d6d2b8 AM |
4950 | { |
4951 | /* Symbol definition. */ | |
4952 | flags |= BSF_GLOBAL; | |
4953 | if (e->flags & EGSY__V_NORM) | |
4954 | flags |= BSF_FUNCTION; | |
4955 | value = e->value; | |
4956 | sec = e->section; | |
4957 | } | |
95e34ef7 | 4958 | else |
07d6d2b8 AM |
4959 | { |
4960 | /* Symbol reference. */ | |
4961 | sec = bfd_und_section_ptr; | |
4962 | } | |
95e34ef7 TG |
4963 | break; |
4964 | ||
4965 | case EGSD__C_SYMG: | |
4966 | /* A universal symbol is by definition global... */ | |
4967 | flags |= BSF_GLOBAL; | |
4968 | ||
4969 | /* ...and dynamic in shared libraries. */ | |
4970 | if (abfd->flags & DYNAMIC) | |
07d6d2b8 | 4971 | flags |= BSF_DYNAMIC; |
95e34ef7 TG |
4972 | |
4973 | if (e->flags & EGSY__V_WEAK) | |
07d6d2b8 | 4974 | flags |= BSF_WEAK; |
95e34ef7 TG |
4975 | |
4976 | if (!(e->flags & EGSY__V_DEF)) | |
07d6d2b8 | 4977 | abort (); |
95e34ef7 TG |
4978 | |
4979 | if (e->flags & EGSY__V_NORM) | |
07d6d2b8 | 4980 | flags |= BSF_FUNCTION; |
95e34ef7 | 4981 | |
a928f1d7 TG |
4982 | value = e->value; |
4983 | /* sec = e->section; */ | |
95e34ef7 | 4984 | sec = bfd_abs_section_ptr; |
95e34ef7 TG |
4985 | break; |
4986 | ||
4987 | default: | |
4988 | return FALSE; | |
4989 | } | |
4990 | ||
4991 | sym->name = name; | |
4992 | sym->section = sec; | |
4993 | sym->flags = flags; | |
4994 | sym->value = value; | |
4995 | return TRUE; | |
4996 | } | |
4997 | ||
4998 | ||
4999 | /* Return the number of bytes required to store a vector of pointers | |
5000 | to asymbols for all the symbols in the BFD abfd, including a | |
5001 | terminal NULL pointer. If there are no symbols in the BFD, | |
5002 | then return 0. If an error occurs, return -1. */ | |
5003 | ||
5004 | static long | |
5005 | alpha_vms_get_symtab_upper_bound (bfd *abfd) | |
5006 | { | |
5007 | vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n", | |
07d6d2b8 | 5008 | abfd, PRIV (gsd_sym_count))); |
95e34ef7 TG |
5009 | |
5010 | return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *); | |
5011 | } | |
5012 | ||
5013 | /* Read the symbols from the BFD abfd, and fills in the vector | |
5014 | location with pointers to the symbols and a trailing NULL. | |
5015 | ||
5016 | Return number of symbols read. */ | |
5017 | ||
5018 | static long | |
5019 | alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols) | |
5020 | { | |
5021 | unsigned int i; | |
5022 | ||
5023 | vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd)); | |
5024 | ||
5025 | if (PRIV (csymbols) == NULL) | |
5026 | { | |
5027 | PRIV (csymbols) = (asymbol **) bfd_alloc | |
07d6d2b8 | 5028 | (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *)); |
95e34ef7 TG |
5029 | |
5030 | /* Traverse table and fill symbols vector. */ | |
5031 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 AM |
5032 | { |
5033 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
5034 | asymbol *sym; | |
95e34ef7 | 5035 | |
07d6d2b8 AM |
5036 | sym = bfd_make_empty_symbol (abfd); |
5037 | if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym)) | |
5038 | { | |
5039 | bfd_release (abfd, PRIV (csymbols)); | |
5040 | PRIV (csymbols) = NULL; | |
5041 | return -1; | |
5042 | } | |
95e34ef7 | 5043 | |
07d6d2b8 AM |
5044 | PRIV (csymbols)[i] = sym; |
5045 | } | |
95e34ef7 TG |
5046 | } |
5047 | ||
5048 | if (symbols != NULL) | |
5049 | { | |
5050 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 | 5051 | symbols[i] = PRIV (csymbols)[i]; |
95e34ef7 TG |
5052 | symbols[i] = NULL; |
5053 | } | |
5054 | ||
5055 | return PRIV (gsd_sym_count); | |
5056 | } | |
5057 | ||
5058 | /* Read and convert relocations from ETIR. We do it once for all sections. */ | |
5059 | ||
5060 | static bfd_boolean | |
5061 | alpha_vms_slurp_relocs (bfd *abfd) | |
5062 | { | |
5063 | int cur_psect = -1; | |
5064 | ||
5065 | vms_debug2 ((3, "alpha_vms_slurp_relocs\n")); | |
5066 | ||
5067 | /* We slurp relocs only once, for all sections. */ | |
5068 | if (PRIV (reloc_done)) | |
5069 | return TRUE; | |
5070 | PRIV (reloc_done) = TRUE; | |
5071 | ||
5072 | if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0) | |
5073 | return FALSE; | |
5074 | ||
5075 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) | |
5076 | return FALSE; | |
5077 | ||
5078 | while (1) | |
5079 | { | |
5080 | unsigned char *begin; | |
5081 | unsigned char *end; | |
5082 | unsigned char *ptr; | |
5083 | bfd_reloc_code_real_type reloc_code; | |
5084 | int type; | |
5085 | bfd_vma vaddr = 0; | |
5086 | ||
5087 | int length; | |
5088 | ||
5089 | bfd_vma cur_address; | |
5090 | int cur_psidx = -1; | |
5091 | unsigned char *cur_sym = NULL; | |
5092 | int prev_cmd = -1; | |
5093 | bfd_vma cur_addend = 0; | |
5094 | ||
5095 | /* Skip non-ETIR records. */ | |
5096 | type = _bfd_vms_get_object_record (abfd); | |
5097 | if (type == EOBJ__C_EEOM) | |
07d6d2b8 | 5098 | break; |
95e34ef7 | 5099 | if (type != EOBJ__C_ETIR) |
07d6d2b8 | 5100 | continue; |
95e34ef7 TG |
5101 | |
5102 | begin = PRIV (recrd.rec) + 4; | |
5103 | end = PRIV (recrd.rec) + PRIV (recrd.rec_size); | |
5104 | ||
5105 | for (ptr = begin; ptr < end; ptr += length) | |
07d6d2b8 AM |
5106 | { |
5107 | int cmd; | |
5108 | ||
5109 | cmd = bfd_getl16 (ptr); | |
5110 | length = bfd_getl16 (ptr + 2); | |
5111 | ||
5112 | cur_address = vaddr; | |
5113 | ||
5114 | vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n", | |
5115 | _bfd_vms_etir_name (cmd))); | |
5116 | ||
5117 | switch (cmd) | |
5118 | { | |
5119 | case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */ | |
5120 | /* ALPHA_R_REFQUAD und_section, step 1 */ | |
5121 | cur_sym = ptr + 4; | |
5122 | prev_cmd = cmd; | |
5123 | continue; | |
5124 | ||
5125 | case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */ | |
5126 | cur_psidx = bfd_getl32 (ptr + 4); | |
5127 | cur_addend = bfd_getl64 (ptr + 8); | |
5128 | prev_cmd = cmd; | |
5129 | continue; | |
5130 | ||
5131 | case ETIR__C_CTL_SETRB: | |
5132 | if (prev_cmd != ETIR__C_STA_PQ) | |
5133 | { | |
4eca0228 | 5134 | _bfd_error_handler |
695344c0 | 5135 | /* xgettext:c-format */ |
38f14ab8 | 5136 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), |
07d6d2b8 AM |
5137 | _bfd_vms_etir_name (cmd)); |
5138 | return FALSE; | |
5139 | } | |
5140 | cur_psect = cur_psidx; | |
5141 | vaddr = cur_addend; | |
5142 | cur_psidx = -1; | |
5143 | cur_addend = 0; | |
5144 | continue; | |
5145 | ||
5146 | case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */ | |
5147 | /* ALPHA_R_REFLONG und_section, step 2 */ | |
5148 | if (prev_cmd != -1) | |
5149 | { | |
5150 | if (prev_cmd != ETIR__C_STA_GBL) | |
5151 | { | |
4eca0228 | 5152 | _bfd_error_handler |
695344c0 | 5153 | /* xgettext:c-format */ |
38f14ab8 | 5154 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
07d6d2b8 AM |
5155 | _bfd_vms_etir_name (ETIR__C_STA_LW)); |
5156 | return FALSE; | |
5157 | } | |
5158 | } | |
5159 | cur_addend = bfd_getl32 (ptr + 4); | |
5160 | prev_cmd = cmd; | |
5161 | continue; | |
5162 | ||
5163 | case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */ | |
5164 | /* ALPHA_R_REFQUAD und_section, step 2 */ | |
5165 | if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL) | |
5166 | { | |
4eca0228 | 5167 | _bfd_error_handler |
695344c0 | 5168 | /* xgettext:c-format */ |
38f14ab8 | 5169 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
07d6d2b8 AM |
5170 | _bfd_vms_etir_name (ETIR__C_STA_QW)); |
5171 | return FALSE; | |
5172 | } | |
5173 | cur_addend = bfd_getl64 (ptr + 4); | |
5174 | prev_cmd = cmd; | |
5175 | continue; | |
5176 | ||
5177 | case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */ | |
5178 | /* ALPHA_R_REFLONG abs_section, step 2 */ | |
5179 | /* ALPHA_R_REFLONG others, step 2 */ | |
5180 | if (prev_cmd != ETIR__C_OPR_ADD | |
5181 | && prev_cmd != ETIR__C_STA_LW | |
5182 | && prev_cmd != ETIR__C_STA_PQ) | |
5183 | { | |
695344c0 | 5184 | /* xgettext:c-format */ |
38f14ab8 | 5185 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5186 | _bfd_vms_etir_name (prev_cmd), |
5187 | _bfd_vms_etir_name (ETIR__C_STO_LW)); | |
07d6d2b8 AM |
5188 | return FALSE; |
5189 | } | |
5190 | reloc_code = BFD_RELOC_32; | |
5191 | break; | |
5192 | ||
5193 | case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */ | |
5194 | /* ALPHA_R_REFQUAD abs_section, step 2 */ | |
5195 | if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW) | |
5196 | { | |
695344c0 | 5197 | /* xgettext:c-format */ |
38f14ab8 | 5198 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5199 | _bfd_vms_etir_name (prev_cmd), |
5200 | _bfd_vms_etir_name (ETIR__C_STO_QW)); | |
07d6d2b8 AM |
5201 | return FALSE; |
5202 | } | |
5203 | reloc_code = BFD_RELOC_64; | |
5204 | break; | |
5205 | ||
5206 | case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */ | |
5207 | if (prev_cmd != ETIR__C_STA_PQ) | |
5208 | { | |
695344c0 | 5209 | /* xgettext:c-format */ |
38f14ab8 | 5210 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5211 | _bfd_vms_etir_name (prev_cmd), |
5212 | _bfd_vms_etir_name (ETIR__C_STO_OFF)); | |
07d6d2b8 AM |
5213 | return FALSE; |
5214 | } | |
5215 | reloc_code = BFD_RELOC_64; | |
5216 | break; | |
5217 | ||
5218 | case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */ | |
5219 | /* ALPHA_R_REFQUAD und_section, step 3 */ | |
5220 | if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW) | |
5221 | { | |
695344c0 | 5222 | /* xgettext:c-format */ |
38f14ab8 | 5223 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5224 | _bfd_vms_etir_name (prev_cmd), |
5225 | _bfd_vms_etir_name (ETIR__C_OPR_ADD)); | |
07d6d2b8 AM |
5226 | return FALSE; |
5227 | } | |
5228 | prev_cmd = ETIR__C_OPR_ADD; | |
5229 | continue; | |
5230 | ||
5231 | case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */ | |
5232 | reloc_code = BFD_RELOC_ALPHA_CODEADDR; | |
5233 | cur_sym = ptr + 4; | |
5234 | break; | |
5235 | ||
5236 | case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */ | |
5237 | reloc_code = BFD_RELOC_64; | |
5238 | cur_sym = ptr + 4; | |
5239 | break; | |
5240 | ||
5241 | case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */ | |
5242 | reloc_code = BFD_RELOC_32; | |
5243 | cur_sym = ptr + 4; | |
5244 | break; | |
5245 | ||
5246 | case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */ | |
5247 | reloc_code = BFD_RELOC_ALPHA_LINKAGE; | |
5248 | cur_sym = ptr + 8; | |
5249 | break; | |
5250 | ||
5251 | case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */ | |
5252 | reloc_code = BFD_RELOC_ALPHA_NOP; | |
5253 | goto call_reloc; | |
5254 | ||
5255 | case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */ | |
5256 | reloc_code = BFD_RELOC_ALPHA_BSR; | |
5257 | goto call_reloc; | |
5258 | ||
5259 | case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */ | |
5260 | reloc_code = BFD_RELOC_ALPHA_LDA; | |
5261 | goto call_reloc; | |
5262 | ||
5263 | case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */ | |
5264 | reloc_code = BFD_RELOC_ALPHA_BOH; | |
5265 | goto call_reloc; | |
5266 | ||
5267 | call_reloc: | |
5268 | cur_sym = ptr + 4 + 32; | |
5269 | cur_address = bfd_getl64 (ptr + 4 + 8); | |
5270 | cur_addend = bfd_getl64 (ptr + 4 + 24); | |
5271 | break; | |
5272 | ||
5273 | case ETIR__C_STO_IMM: | |
5274 | vaddr += bfd_getl32 (ptr + 4); | |
5275 | continue; | |
5276 | ||
5277 | default: | |
38f14ab8 | 5278 | _bfd_error_handler (_("unknown reloc %s"), |
4eca0228 | 5279 | _bfd_vms_etir_name (cmd)); |
07d6d2b8 AM |
5280 | return FALSE; |
5281 | } | |
95e34ef7 | 5282 | |
07d6d2b8 AM |
5283 | { |
5284 | asection *sec; | |
5285 | struct vms_section_data_struct *vms_sec; | |
5286 | arelent *reloc; | |
706704c8 | 5287 | bfd_size_type size; |
95e34ef7 | 5288 | |
07d6d2b8 AM |
5289 | /* Get section to which the relocation applies. */ |
5290 | if (cur_psect < 0 || cur_psect > (int)PRIV (section_count)) | |
5291 | { | |
38f14ab8 | 5292 | _bfd_error_handler (_("invalid section index in ETIR")); |
07d6d2b8 AM |
5293 | return FALSE; |
5294 | } | |
d120eec2 | 5295 | |
cb06d03a NC |
5296 | if (PRIV (sections) == NULL) |
5297 | return FALSE; | |
07d6d2b8 AM |
5298 | sec = PRIV (sections)[cur_psect]; |
5299 | if (sec == bfd_abs_section_ptr) | |
5300 | { | |
38f14ab8 | 5301 | _bfd_error_handler (_("relocation for non-REL psect")); |
07d6d2b8 AM |
5302 | return FALSE; |
5303 | } | |
5304 | ||
5305 | vms_sec = vms_section_data (sec); | |
5306 | ||
5307 | /* Allocate a reloc entry. */ | |
5308 | if (sec->reloc_count >= vms_sec->reloc_max) | |
5309 | { | |
5310 | if (vms_sec->reloc_max == 0) | |
5311 | { | |
5312 | vms_sec->reloc_max = 64; | |
5313 | sec->relocation = bfd_zmalloc | |
5314 | (vms_sec->reloc_max * sizeof (arelent)); | |
5315 | } | |
5316 | else | |
5317 | { | |
5318 | vms_sec->reloc_max *= 2; | |
9cb56943 | 5319 | sec->relocation = bfd_realloc_or_free |
07d6d2b8 | 5320 | (sec->relocation, vms_sec->reloc_max * sizeof (arelent)); |
9cb56943 AM |
5321 | if (sec->relocation == NULL) |
5322 | return FALSE; | |
07d6d2b8 AM |
5323 | } |
5324 | } | |
5325 | reloc = &sec->relocation[sec->reloc_count]; | |
5326 | sec->reloc_count++; | |
5327 | ||
5328 | reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code); | |
5329 | ||
5330 | if (cur_sym != NULL) | |
5331 | { | |
5332 | unsigned int j; | |
5333 | unsigned int symlen = *cur_sym; | |
5334 | asymbol **sym; | |
5335 | ||
5336 | /* Linear search. */ | |
5337 | symlen = *cur_sym; | |
5338 | cur_sym++; | |
5339 | sym = NULL; | |
5340 | ||
5341 | for (j = 0; j < PRIV (gsd_sym_count); j++) | |
5342 | if (PRIV (syms)[j]->namelen == symlen | |
5343 | && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0) | |
5344 | { | |
5345 | sym = &PRIV (csymbols)[j]; | |
5346 | break; | |
5347 | } | |
5348 | if (sym == NULL) | |
5349 | { | |
38f14ab8 | 5350 | _bfd_error_handler (_("unknown symbol in command %s"), |
4eca0228 | 5351 | _bfd_vms_etir_name (cmd)); |
07d6d2b8 AM |
5352 | reloc->sym_ptr_ptr = NULL; |
5353 | } | |
5354 | else | |
5355 | reloc->sym_ptr_ptr = sym; | |
5356 | } | |
5357 | else if (cur_psidx >= 0) | |
cb06d03a | 5358 | { |
ca4cf9b9 | 5359 | if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count)) |
cb06d03a NC |
5360 | return FALSE; |
5361 | reloc->sym_ptr_ptr = | |
5362 | PRIV (sections)[cur_psidx]->symbol_ptr_ptr; | |
5363 | } | |
07d6d2b8 AM |
5364 | else |
5365 | reloc->sym_ptr_ptr = NULL; | |
95e34ef7 | 5366 | |
07d6d2b8 AM |
5367 | reloc->address = cur_address; |
5368 | reloc->addend = cur_addend; | |
95e34ef7 | 5369 | |
706704c8 AM |
5370 | if (reloc_code == ALPHA_R_LINKAGE) |
5371 | size = 16; | |
5372 | else | |
5373 | size = bfd_get_reloc_size (reloc->howto); | |
5374 | vaddr += size; | |
07d6d2b8 | 5375 | } |
95e34ef7 | 5376 | |
07d6d2b8 AM |
5377 | cur_addend = 0; |
5378 | prev_cmd = -1; | |
5379 | cur_sym = NULL; | |
5380 | cur_psidx = -1; | |
5381 | } | |
95e34ef7 TG |
5382 | } |
5383 | vms_debug2 ((3, "alpha_vms_slurp_relocs: result = TRUE\n")); | |
5384 | ||
5385 | return TRUE; | |
5386 | } | |
5387 | ||
5388 | /* Return the number of bytes required to store the relocation | |
5389 | information associated with the given section. */ | |
5390 | ||
5391 | static long | |
5392 | alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section) | |
5393 | { | |
5394 | alpha_vms_slurp_relocs (abfd); | |
5395 | ||
5396 | return (section->reloc_count + 1) * sizeof (arelent *); | |
5397 | } | |
5398 | ||
5399 | /* Convert relocations from VMS (external) form into BFD internal | |
5400 | form. Return the number of relocations. */ | |
5401 | ||
5402 | static long | |
5403 | alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr, | |
07d6d2b8 | 5404 | asymbol **symbols ATTRIBUTE_UNUSED) |
95e34ef7 TG |
5405 | { |
5406 | arelent *tblptr; | |
5407 | int count; | |
5408 | ||
5409 | if (!alpha_vms_slurp_relocs (abfd)) | |
5410 | return -1; | |
5411 | ||
5412 | count = section->reloc_count; | |
5413 | tblptr = section->relocation; | |
5414 | ||
5415 | while (count--) | |
5416 | *relptr++ = tblptr++; | |
5417 | ||
5418 | *relptr = (arelent *) NULL; | |
5419 | return section->reloc_count; | |
5420 | } | |
23186865 JM |
5421 | |
5422 | /* Install a new set of internal relocs. */ | |
5423 | ||
5424 | #define alpha_vms_set_reloc _bfd_generic_set_reloc | |
5425 | ||
95e34ef7 TG |
5426 | \f |
5427 | /* This is just copied from ecoff-alpha, needs to be fixed probably. */ | |
5428 | ||
5429 | /* How to process the various reloc types. */ | |
5430 | ||
5431 | static bfd_reloc_status_type | |
5432 | reloc_nil (bfd * abfd ATTRIBUTE_UNUSED, | |
5433 | arelent *reloc ATTRIBUTE_UNUSED, | |
5434 | asymbol *sym ATTRIBUTE_UNUSED, | |
5435 | void * data ATTRIBUTE_UNUSED, | |
5436 | asection *sec ATTRIBUTE_UNUSED, | |
5437 | bfd *output_bfd ATTRIBUTE_UNUSED, | |
5438 | char **error_message ATTRIBUTE_UNUSED) | |
5439 | { | |
5440 | #if VMS_DEBUG | |
5441 | vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd); | |
5442 | vms_debug (2, "In section %s, symbol %s\n", | |
5443 | sec->name, sym->name); | |
5444 | vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n", | |
5445 | reloc->sym_ptr_ptr[0]->name, | |
5446 | (unsigned long)reloc->address, | |
5447 | (unsigned long)reloc->addend, reloc->howto->name); | |
5448 | vms_debug (2, "data at %p\n", data); | |
5449 | /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */ | |
5450 | #endif | |
5451 | ||
5452 | return bfd_reloc_ok; | |
5453 | } | |
5454 | ||
5455 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
5456 | from smaller values. Start with zero, widen, *then* decrement. */ | |
5457 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
5458 | ||
5459 | static reloc_howto_type alpha_howto_table[] = | |
5460 | { | |
5461 | HOWTO (ALPHA_R_IGNORE, /* Type. */ | |
5462 | 0, /* Rightshift. */ | |
5463 | 0, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5464 | 8, /* Bitsize. */ | |
5465 | TRUE, /* PC relative. */ | |
5466 | 0, /* Bitpos. */ | |
5467 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5468 | reloc_nil, /* Special_function. */ | |
5469 | "IGNORE", /* Name. */ | |
5470 | TRUE, /* Partial_inplace. */ | |
5471 | 0, /* Source mask */ | |
5472 | 0, /* Dest mask. */ | |
5473 | TRUE), /* PC rel offset. */ | |
5474 | ||
5475 | /* A 64 bit reference to a symbol. */ | |
5476 | HOWTO (ALPHA_R_REFQUAD, /* Type. */ | |
5477 | 0, /* Rightshift. */ | |
5478 | 4, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5479 | 64, /* Bitsize. */ | |
5480 | FALSE, /* PC relative. */ | |
5481 | 0, /* Bitpos. */ | |
5482 | complain_overflow_bitfield, /* Complain_on_overflow. */ | |
5483 | reloc_nil, /* Special_function. */ | |
5484 | "REFQUAD", /* Name. */ | |
5485 | TRUE, /* Partial_inplace. */ | |
5486 | MINUS_ONE, /* Source mask. */ | |
5487 | MINUS_ONE, /* Dest mask. */ | |
5488 | FALSE), /* PC rel offset. */ | |
5489 | ||
5490 | /* A 21 bit branch. The native assembler generates these for | |
5491 | branches within the text segment, and also fills in the PC | |
5492 | relative offset in the instruction. */ | |
5493 | HOWTO (ALPHA_R_BRADDR, /* Type. */ | |
5494 | 2, /* Rightshift. */ | |
5495 | 2, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5496 | 21, /* Bitsize. */ | |
5497 | TRUE, /* PC relative. */ | |
5498 | 0, /* Bitpos. */ | |
5499 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5500 | reloc_nil, /* Special_function. */ | |
5501 | "BRADDR", /* Name. */ | |
5502 | TRUE, /* Partial_inplace. */ | |
5503 | 0x1fffff, /* Source mask. */ | |
5504 | 0x1fffff, /* Dest mask. */ | |
5505 | FALSE), /* PC rel offset. */ | |
5506 | ||
5507 | /* A hint for a jump to a register. */ | |
5508 | HOWTO (ALPHA_R_HINT, /* Type. */ | |
5509 | 2, /* Rightshift. */ | |
5510 | 1, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5511 | 14, /* Bitsize. */ | |
5512 | TRUE, /* PC relative. */ | |
5513 | 0, /* Bitpos. */ | |
5514 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5515 | reloc_nil, /* Special_function. */ | |
5516 | "HINT", /* Name. */ | |
5517 | TRUE, /* Partial_inplace. */ | |
5518 | 0x3fff, /* Source mask. */ | |
5519 | 0x3fff, /* Dest mask. */ | |
5520 | FALSE), /* PC rel offset. */ | |
5521 | ||
5522 | /* 16 bit PC relative offset. */ | |
5523 | HOWTO (ALPHA_R_SREL16, /* Type. */ | |
5524 | 0, /* Rightshift. */ | |
5525 | 1, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5526 | 16, /* Bitsize. */ | |
5527 | TRUE, /* PC relative. */ | |
5528 | 0, /* Bitpos. */ | |
5529 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5530 | reloc_nil, /* Special_function. */ | |
5531 | "SREL16", /* Name. */ | |
5532 | TRUE, /* Partial_inplace. */ | |
5533 | 0xffff, /* Source mask. */ | |
5534 | 0xffff, /* Dest mask. */ | |
5535 | FALSE), /* PC rel offset. */ | |
5536 | ||
5537 | /* 32 bit PC relative offset. */ | |
5538 | HOWTO (ALPHA_R_SREL32, /* Type. */ | |
5539 | 0, /* Rightshift. */ | |
5540 | 2, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5541 | 32, /* Bitsize. */ | |
5542 | TRUE, /* PC relative. */ | |
5543 | 0, /* Bitpos. */ | |
5544 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5545 | reloc_nil, /* Special_function. */ | |
5546 | "SREL32", /* Name. */ | |
5547 | TRUE, /* Partial_inplace. */ | |
5548 | 0xffffffff, /* Source mask. */ | |
5549 | 0xffffffff, /* Dest mask. */ | |
5550 | FALSE), /* PC rel offset. */ | |
5551 | ||
5552 | /* A 64 bit PC relative offset. */ | |
5553 | HOWTO (ALPHA_R_SREL64, /* Type. */ | |
5554 | 0, /* Rightshift. */ | |
5555 | 4, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5556 | 64, /* Bitsize. */ | |
5557 | TRUE, /* PC relative. */ | |
5558 | 0, /* Bitpos. */ | |
5559 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5560 | reloc_nil, /* Special_function. */ | |
5561 | "SREL64", /* Name. */ | |
5562 | TRUE, /* Partial_inplace. */ | |
5563 | MINUS_ONE, /* Source mask. */ | |
5564 | MINUS_ONE, /* Dest mask. */ | |
5565 | FALSE), /* PC rel offset. */ | |
5566 | ||
5567 | /* Push a value on the reloc evaluation stack. */ | |
5568 | HOWTO (ALPHA_R_OP_PUSH, /* Type. */ | |
5569 | 0, /* Rightshift. */ | |
5570 | 0, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5571 | 0, /* Bitsize. */ | |
5572 | FALSE, /* PC relative. */ | |
5573 | 0, /* Bitpos. */ | |
5574 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5575 | reloc_nil, /* Special_function. */ | |
5576 | "OP_PUSH", /* Name. */ | |
5577 | FALSE, /* Partial_inplace. */ | |
5578 | 0, /* Source mask. */ | |
5579 | 0, /* Dest mask. */ | |
5580 | FALSE), /* PC rel offset. */ | |
5581 | ||
5582 | /* Store the value from the stack at the given address. Store it in | |
5583 | a bitfield of size r_size starting at bit position r_offset. */ | |
5584 | HOWTO (ALPHA_R_OP_STORE, /* Type. */ | |
5585 | 0, /* Rightshift. */ | |
5586 | 4, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5587 | 64, /* Bitsize. */ | |
5588 | FALSE, /* PC relative. */ | |
5589 | 0, /* Bitpos. */ | |
5590 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5591 | reloc_nil, /* Special_function. */ | |
5592 | "OP_STORE", /* Name. */ | |
5593 | FALSE, /* Partial_inplace. */ | |
5594 | 0, /* Source mask. */ | |
5595 | MINUS_ONE, /* Dest mask. */ | |
5596 | FALSE), /* PC rel offset. */ | |
5597 | ||
5598 | /* Subtract the reloc address from the value on the top of the | |
5599 | relocation stack. */ | |
5600 | HOWTO (ALPHA_R_OP_PSUB, /* Type. */ | |
5601 | 0, /* Rightshift. */ | |
5602 | 0, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5603 | 0, /* Bitsize. */ | |
5604 | FALSE, /* PC relative. */ | |
5605 | 0, /* Bitpos. */ | |
5606 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5607 | reloc_nil, /* Special_function. */ | |
5608 | "OP_PSUB", /* Name. */ | |
5609 | FALSE, /* Partial_inplace. */ | |
5610 | 0, /* Source mask. */ | |
5611 | 0, /* Dest mask. */ | |
5612 | FALSE), /* PC rel offset. */ | |
5613 | ||
5614 | /* Shift the value on the top of the relocation stack right by the | |
5615 | given value. */ | |
5616 | HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */ | |
5617 | 0, /* Rightshift. */ | |
5618 | 0, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5619 | 0, /* Bitsize. */ | |
5620 | FALSE, /* PC relative. */ | |
5621 | 0, /* Bitpos. */ | |
5622 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5623 | reloc_nil, /* Special_function. */ | |
5624 | "OP_PRSHIFT", /* Name. */ | |
5625 | FALSE, /* Partial_inplace. */ | |
5626 | 0, /* Source mask. */ | |
5627 | 0, /* Dest mask. */ | |
5628 | FALSE), /* PC rel offset. */ | |
5629 | ||
5630 | /* Hack. Linkage is done by linker. */ | |
5631 | HOWTO (ALPHA_R_LINKAGE, /* Type. */ | |
5632 | 0, /* Rightshift. */ | |
706704c8 AM |
5633 | 0, /* Size (0 = byte, 1 = short, 2 = long). */ |
5634 | 0, /* Bitsize. */ | |
95e34ef7 TG |
5635 | FALSE, /* PC relative. */ |
5636 | 0, /* Bitpos. */ | |
5637 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5638 | reloc_nil, /* Special_function. */ | |
5639 | "LINKAGE", /* Name. */ | |
5640 | FALSE, /* Partial_inplace. */ | |
5641 | 0, /* Source mask. */ | |
5642 | 0, /* Dest mask. */ | |
5643 | FALSE), /* PC rel offset. */ | |
5644 | ||
5645 | /* A 32 bit reference to a symbol. */ | |
5646 | HOWTO (ALPHA_R_REFLONG, /* Type. */ | |
5647 | 0, /* Rightshift. */ | |
5648 | 2, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5649 | 32, /* Bitsize. */ | |
5650 | FALSE, /* PC relative. */ | |
5651 | 0, /* Bitpos. */ | |
5652 | complain_overflow_bitfield, /* Complain_on_overflow. */ | |
5653 | reloc_nil, /* Special_function. */ | |
5654 | "REFLONG", /* Name. */ | |
5655 | TRUE, /* Partial_inplace. */ | |
5656 | 0xffffffff, /* Source mask. */ | |
5657 | 0xffffffff, /* Dest mask. */ | |
5658 | FALSE), /* PC rel offset. */ | |
5659 | ||
5660 | /* A 64 bit reference to a procedure, written as 32 bit value. */ | |
5661 | HOWTO (ALPHA_R_CODEADDR, /* Type. */ | |
5662 | 0, /* Rightshift. */ | |
5663 | 4, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5664 | 64, /* Bitsize. */ | |
5665 | FALSE, /* PC relative. */ | |
5666 | 0, /* Bitpos. */ | |
5667 | complain_overflow_signed,/* Complain_on_overflow. */ | |
5668 | reloc_nil, /* Special_function. */ | |
5669 | "CODEADDR", /* Name. */ | |
5670 | FALSE, /* Partial_inplace. */ | |
5671 | 0xffffffff, /* Source mask. */ | |
5672 | 0xffffffff, /* Dest mask. */ | |
5673 | FALSE), /* PC rel offset. */ | |
5674 | ||
5675 | HOWTO (ALPHA_R_NOP, /* Type. */ | |
5676 | 0, /* Rightshift. */ | |
5677 | 3, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5678 | 0, /* Bitsize. */ | |
5679 | /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH | |
5680 | because the calculations for the 3 relocations are the same. | |
5681 | See B.4.5.2 of the OpenVMS Linker Utility Manual. */ | |
5682 | TRUE, /* PC relative. */ | |
5683 | 0, /* Bitpos. */ | |
5684 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5685 | reloc_nil, /* Special_function. */ | |
5686 | "NOP", /* Name. */ | |
5687 | FALSE, /* Partial_inplace. */ | |
5688 | 0xffffffff, /* Source mask. */ | |
5689 | 0xffffffff, /* Dest mask. */ | |
5690 | FALSE), /* PC rel offset. */ | |
5691 | ||
5692 | HOWTO (ALPHA_R_BSR, /* Type. */ | |
5693 | 0, /* Rightshift. */ | |
5694 | 3, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5695 | 0, /* Bitsize. */ | |
5696 | TRUE, /* PC relative. */ | |
5697 | 0, /* Bitpos. */ | |
5698 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5699 | reloc_nil, /* Special_function. */ | |
5700 | "BSR", /* Name. */ | |
5701 | FALSE, /* Partial_inplace. */ | |
5702 | 0xffffffff, /* Source mask. */ | |
5703 | 0xffffffff, /* Dest mask. */ | |
5704 | FALSE), /* PC rel offset. */ | |
5705 | ||
5706 | HOWTO (ALPHA_R_LDA, /* Type. */ | |
5707 | 0, /* Rightshift. */ | |
5708 | 3, /* Size (0 = byte, 1 = short, 2 = long). */ | |
5709 | 0, /* Bitsize. */ | |
5710 | FALSE, /* PC relative. */ | |
5711 | 0, /* Bitpos. */ | |
5712 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5713 | reloc_nil, /* Special_function. */ | |
5714 | "LDA", /* Name. */ | |
5715 | FALSE, /* Partial_inplace. */ | |
5716 | 0xffffffff, /* Source mask. */ | |
5717 | 0xffffffff, /* Dest mask. */ | |
5718 | FALSE), /* PC rel offset. */ | |
5719 | ||
5720 | HOWTO (ALPHA_R_BOH, /* Type. */ | |
5721 | 0, /* Rightshift. */ | |
5722 | 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */ | |
5723 | 0, /* Bitsize. */ | |
5724 | TRUE, /* PC relative. */ | |
5725 | 0, /* Bitpos. */ | |
5726 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5727 | reloc_nil, /* Special_function. */ | |
5728 | "BOH", /* Name. */ | |
5729 | FALSE, /* Partial_inplace. */ | |
5730 | 0xffffffff, /* Source mask. */ | |
5731 | 0xffffffff, /* Dest mask. */ | |
5732 | FALSE), /* PC rel offset. */ | |
5733 | }; | |
5734 | ||
5735 | /* Return a pointer to a howto structure which, when invoked, will perform | |
5736 | the relocation code on data from the architecture noted. */ | |
5737 | ||
487096bf | 5738 | static reloc_howto_type * |
95e34ef7 | 5739 | alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
07d6d2b8 | 5740 | bfd_reloc_code_real_type code) |
95e34ef7 TG |
5741 | { |
5742 | int alpha_type; | |
5743 | ||
5744 | vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code)); | |
5745 | ||
5746 | switch (code) | |
5747 | { | |
5748 | case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break; | |
5749 | case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break; | |
5750 | case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break; | |
5751 | case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break; | |
5752 | case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break; | |
5753 | case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break; | |
5754 | case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break; | |
5755 | case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break; | |
5756 | case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break; | |
5757 | case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break; | |
5758 | case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break; | |
5759 | case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break; | |
5760 | case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break; | |
5761 | case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break; | |
5762 | case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break; | |
5763 | default: | |
695344c0 | 5764 | _bfd_error_handler (_("reloc (%d) is *UNKNOWN*"), code); |
95e34ef7 TG |
5765 | return NULL; |
5766 | } | |
5767 | vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name)); | |
5768 | return & alpha_howto_table[alpha_type]; | |
5769 | } | |
5770 | ||
5771 | static reloc_howto_type * | |
5772 | alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
07d6d2b8 | 5773 | const char *r_name) |
95e34ef7 TG |
5774 | { |
5775 | unsigned int i; | |
5776 | ||
5777 | for (i = 0; | |
5778 | i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]); | |
5779 | i++) | |
5780 | if (alpha_howto_table[i].name != NULL | |
5781 | && strcasecmp (alpha_howto_table[i].name, r_name) == 0) | |
5782 | return &alpha_howto_table[i]; | |
5783 | ||
5784 | return NULL; | |
5785 | } | |
5786 | \f | |
5787 | static long | |
5788 | alpha_vms_get_synthetic_symtab (bfd *abfd, | |
07d6d2b8 AM |
5789 | long symcount ATTRIBUTE_UNUSED, |
5790 | asymbol **usyms ATTRIBUTE_UNUSED, | |
5791 | long dynsymcount ATTRIBUTE_UNUSED, | |
5792 | asymbol **dynsyms ATTRIBUTE_UNUSED, | |
5793 | asymbol **ret) | |
95e34ef7 TG |
5794 | { |
5795 | asymbol *syms; | |
5796 | unsigned int i; | |
5797 | unsigned int n = 0; | |
5798 | ||
5799 | syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol)); | |
5800 | *ret = syms; | |
5801 | if (syms == NULL) | |
5802 | return -1; | |
5803 | ||
5804 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
5805 | { | |
5806 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
5807 | asymbol *sym; | |
5808 | flagword flags; | |
5809 | symvalue value; | |
5810 | asection *sec; | |
5811 | const char *name; | |
5812 | char *sname; | |
5813 | int l; | |
5814 | ||
5815 | name = e->name; | |
5816 | value = 0; | |
5817 | flags = BSF_LOCAL | BSF_SYNTHETIC; | |
5818 | sec = NULL; | |
5819 | ||
5820 | switch (e->typ) | |
07d6d2b8 AM |
5821 | { |
5822 | case EGSD__C_SYM: | |
5823 | case EGSD__C_SYMG: | |
5824 | if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM)) | |
5825 | { | |
5826 | value = e->code_value; | |
5827 | sec = e->code_section; | |
5828 | } | |
5829 | else | |
5830 | continue; | |
5831 | break; | |
5832 | ||
5833 | default: | |
5834 | continue; | |
5835 | } | |
95e34ef7 TG |
5836 | |
5837 | l = strlen (name); | |
5838 | sname = bfd_alloc (abfd, l + 5); | |
5839 | if (sname == NULL) | |
07d6d2b8 | 5840 | return FALSE; |
95e34ef7 TG |
5841 | memcpy (sname, name, l); |
5842 | memcpy (sname + l, "..en", 5); | |
5843 | ||
5844 | sym = &syms[n++]; | |
5845 | sym->name = sname; | |
5846 | sym->section = sec; | |
5847 | sym->flags = flags; | |
5848 | sym->value = value; | |
5849 | sym->udata.p = NULL; | |
5850 | } | |
5851 | ||
5852 | return n; | |
5853 | } | |
5854 | \f | |
5855 | /* Private dump. */ | |
5856 | ||
5857 | static const char * | |
5858 | vms_time_to_str (unsigned char *buf) | |
5859 | { | |
5860 | time_t t = vms_rawtime_to_time_t (buf); | |
5861 | char *res = ctime (&t); | |
5862 | ||
5863 | if (!res) | |
5864 | res = "*invalid time*"; | |
5865 | else | |
5866 | res[24] = 0; | |
5867 | return res; | |
5868 | } | |
5869 | ||
5870 | static void | |
5871 | evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len) | |
5872 | { | |
5873 | struct vms_emh_common *emh = (struct vms_emh_common *)rec; | |
5874 | unsigned int subtype; | |
8bdf0be1 | 5875 | int extra; |
95e34ef7 | 5876 | |
8bdf0be1 | 5877 | subtype = (unsigned) bfd_getl16 (emh->subtyp); |
95e34ef7 | 5878 | |
695344c0 | 5879 | /* xgettext:c-format */ |
95e34ef7 TG |
5880 | fprintf (file, _(" EMH %u (len=%u): "), subtype, rec_len); |
5881 | ||
bc21b167 NC |
5882 | /* PR 21618: Check for invalid lengths. */ |
5883 | if (rec_len < sizeof (* emh)) | |
5884 | { | |
5885 | fprintf (file, _(" Error: The length is less than the length of an EMH record\n")); | |
5886 | return; | |
5887 | } | |
8bdf0be1 NC |
5888 | extra = rec_len - sizeof (struct vms_emh_common); |
5889 | ||
95e34ef7 TG |
5890 | switch (subtype) |
5891 | { | |
5892 | case EMH__C_MHD: | |
5893 | { | |
07d6d2b8 AM |
5894 | struct vms_emh_mhd *mhd = (struct vms_emh_mhd *) rec; |
5895 | const char * name; | |
8bdf0be1 NC |
5896 | const char * nextname; |
5897 | const char * maxname; | |
95e34ef7 | 5898 | |
8bdf0be1 NC |
5899 | /* PR 21840: Check for invalid lengths. */ |
5900 | if (rec_len < sizeof (* mhd)) | |
5901 | { | |
5902 | fprintf (file, _(" Error: The record length is less than the size of an EMH_MHD record\n")); | |
5903 | return; | |
5904 | } | |
07d6d2b8 AM |
5905 | fprintf (file, _("Module header\n")); |
5906 | fprintf (file, _(" structure level: %u\n"), mhd->strlvl); | |
5907 | fprintf (file, _(" max record size: %u\n"), | |
5908 | (unsigned) bfd_getl32 (mhd->recsiz)); | |
5909 | name = (char *)(mhd + 1); | |
8bdf0be1 NC |
5910 | maxname = (char *) rec + rec_len; |
5911 | if (name > maxname - 2) | |
5912 | { | |
5913 | fprintf (file, _(" Error: The module name is missing\n")); | |
5914 | return; | |
5915 | } | |
5916 | nextname = name + name[0] + 1; | |
5917 | if (nextname >= maxname) | |
5918 | { | |
5919 | fprintf (file, _(" Error: The module name is too long\n")); | |
5920 | return; | |
5921 | } | |
07d6d2b8 AM |
5922 | fprintf (file, _(" module name : %.*s\n"), name[0], name + 1); |
5923 | name = nextname; | |
8bdf0be1 NC |
5924 | if (name > maxname - 2) |
5925 | { | |
5926 | fprintf (file, _(" Error: The module version is missing\n")); | |
5927 | return; | |
5928 | } | |
5929 | nextname = name + name[0] + 1; | |
5930 | if (nextname >= maxname) | |
5931 | { | |
5932 | fprintf (file, _(" Error: The module version is too long\n")); | |
5933 | return; | |
5934 | } | |
07d6d2b8 AM |
5935 | fprintf (file, _(" module version : %.*s\n"), name[0], name + 1); |
5936 | name = nextname; | |
8bdf0be1 NC |
5937 | if ((maxname - name) < 17 && maxname[-1] != 0) |
5938 | fprintf (file, _(" Error: The compile date is truncated\n")); | |
5939 | else | |
5940 | fprintf (file, _(" compile date : %.17s\n"), name); | |
95e34ef7 TG |
5941 | } |
5942 | break; | |
8bdf0be1 | 5943 | |
95e34ef7 | 5944 | case EMH__C_LNM: |
8bdf0be1 NC |
5945 | fprintf (file, _("Language Processor Name\n")); |
5946 | fprintf (file, _(" language name: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 5947 | break; |
8bdf0be1 | 5948 | |
95e34ef7 | 5949 | case EMH__C_SRC: |
8bdf0be1 NC |
5950 | fprintf (file, _("Source Files Header\n")); |
5951 | fprintf (file, _(" file: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 5952 | break; |
8bdf0be1 | 5953 | |
95e34ef7 | 5954 | case EMH__C_TTL: |
8bdf0be1 NC |
5955 | fprintf (file, _("Title Text Header\n")); |
5956 | fprintf (file, _(" title: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 5957 | break; |
8bdf0be1 | 5958 | |
95e34ef7 | 5959 | case EMH__C_CPR: |
8bdf0be1 NC |
5960 | fprintf (file, _("Copyright Header\n")); |
5961 | fprintf (file, _(" copyright: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 5962 | break; |
8bdf0be1 | 5963 | |
95e34ef7 TG |
5964 | default: |
5965 | fprintf (file, _("unhandled emh subtype %u\n"), subtype); | |
5966 | break; | |
5967 | } | |
5968 | } | |
5969 | ||
5970 | static void | |
5971 | evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len) | |
5972 | { | |
5973 | struct vms_eeom *eeom = (struct vms_eeom *)rec; | |
5974 | ||
5975 | fprintf (file, _(" EEOM (len=%u):\n"), rec_len); | |
bc21b167 NC |
5976 | |
5977 | /* PR 21618: Check for invalid lengths. */ | |
5978 | if (rec_len < sizeof (* eeom)) | |
5979 | { | |
5980 | fprintf (file, _(" Error: The length is less than the length of an EEOM record\n")); | |
5981 | return; | |
5982 | } | |
07d6d2b8 | 5983 | |
95e34ef7 | 5984 | fprintf (file, _(" number of cond linkage pairs: %u\n"), |
07d6d2b8 | 5985 | (unsigned)bfd_getl32 (eeom->total_lps)); |
95e34ef7 | 5986 | fprintf (file, _(" completion code: %u\n"), |
07d6d2b8 | 5987 | (unsigned)bfd_getl16 (eeom->comcod)); |
95e34ef7 TG |
5988 | if (rec_len > 10) |
5989 | { | |
5990 | fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg); | |
5991 | fprintf (file, _(" transfer addr psect: %u\n"), | |
07d6d2b8 | 5992 | (unsigned)bfd_getl32 (eeom->psindx)); |
95e34ef7 | 5993 | fprintf (file, _(" transfer address : 0x%08x\n"), |
07d6d2b8 | 5994 | (unsigned)bfd_getl32 (eeom->tfradr)); |
95e34ef7 TG |
5995 | } |
5996 | } | |
5997 | ||
5998 | static void | |
5999 | exav_bfd_print_egsy_flags (unsigned int flags, FILE *file) | |
6000 | { | |
6001 | if (flags & EGSY__V_WEAK) | |
6002 | fputs (_(" WEAK"), file); | |
6003 | if (flags & EGSY__V_DEF) | |
6004 | fputs (_(" DEF"), file); | |
6005 | if (flags & EGSY__V_UNI) | |
6006 | fputs (_(" UNI"), file); | |
6007 | if (flags & EGSY__V_REL) | |
6008 | fputs (_(" REL"), file); | |
6009 | if (flags & EGSY__V_COMM) | |
6010 | fputs (_(" COMM"), file); | |
6011 | if (flags & EGSY__V_VECEP) | |
6012 | fputs (_(" VECEP"), file); | |
6013 | if (flags & EGSY__V_NORM) | |
6014 | fputs (_(" NORM"), file); | |
6015 | if (flags & EGSY__V_QUAD_VAL) | |
6016 | fputs (_(" QVAL"), file); | |
6017 | } | |
6018 | ||
9a1b4480 TG |
6019 | static void |
6020 | evax_bfd_print_egsd_flags (FILE *file, unsigned int flags) | |
6021 | { | |
6022 | if (flags & EGPS__V_PIC) | |
6023 | fputs (_(" PIC"), file); | |
6024 | if (flags & EGPS__V_LIB) | |
6025 | fputs (_(" LIB"), file); | |
6026 | if (flags & EGPS__V_OVR) | |
6027 | fputs (_(" OVR"), file); | |
6028 | if (flags & EGPS__V_REL) | |
6029 | fputs (_(" REL"), file); | |
6030 | if (flags & EGPS__V_GBL) | |
6031 | fputs (_(" GBL"), file); | |
6032 | if (flags & EGPS__V_SHR) | |
6033 | fputs (_(" SHR"), file); | |
6034 | if (flags & EGPS__V_EXE) | |
6035 | fputs (_(" EXE"), file); | |
6036 | if (flags & EGPS__V_RD) | |
6037 | fputs (_(" RD"), file); | |
6038 | if (flags & EGPS__V_WRT) | |
6039 | fputs (_(" WRT"), file); | |
6040 | if (flags & EGPS__V_VEC) | |
6041 | fputs (_(" VEC"), file); | |
6042 | if (flags & EGPS__V_NOMOD) | |
6043 | fputs (_(" NOMOD"), file); | |
6044 | if (flags & EGPS__V_COM) | |
6045 | fputs (_(" COM"), file); | |
6046 | if (flags & EGPS__V_ALLOC_64BIT) | |
6047 | fputs (_(" 64B"), file); | |
6048 | } | |
6049 | ||
95e34ef7 TG |
6050 | static void |
6051 | evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len) | |
6052 | { | |
6053 | unsigned int off = sizeof (struct vms_egsd); | |
6054 | unsigned int n; | |
6055 | ||
6056 | fprintf (file, _(" EGSD (len=%u):\n"), rec_len); | |
6057 | ||
6058 | n = 0; | |
6059 | for (off = sizeof (struct vms_egsd); off < rec_len; ) | |
6060 | { | |
6061 | struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off); | |
6062 | unsigned int type; | |
6063 | unsigned int len; | |
6064 | ||
6065 | type = (unsigned)bfd_getl16 (e->gsdtyp); | |
6066 | len = (unsigned)bfd_getl16 (e->gsdsiz); | |
6067 | ||
695344c0 | 6068 | /* xgettext:c-format */ |
95e34ef7 | 6069 | fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "), |
07d6d2b8 | 6070 | n, type, len); |
95e34ef7 TG |
6071 | n++; |
6072 | ||
bc21b167 NC |
6073 | if (off + len > rec_len || off + len < off) |
6074 | { | |
6075 | fprintf (file, _(" Error: length larger than remaining space in record\n")); | |
6076 | return; | |
6077 | } | |
6078 | ||
95e34ef7 | 6079 | switch (type) |
07d6d2b8 AM |
6080 | { |
6081 | case EGSD__C_PSC: | |
6082 | { | |
6083 | struct vms_egps *egps = (struct vms_egps *)e; | |
6084 | unsigned int flags = bfd_getl16 (egps->flags); | |
6085 | unsigned int l; | |
6086 | ||
6087 | fprintf (file, _("PSC - Program section definition\n")); | |
6088 | fprintf (file, _(" alignment : 2**%u\n"), egps->align); | |
6089 | fprintf (file, _(" flags : 0x%04x"), flags); | |
6090 | evax_bfd_print_egsd_flags (file, flags); | |
6091 | fputc ('\n', file); | |
6092 | l = bfd_getl32 (egps->alloc); | |
6093 | fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l); | |
6094 | fprintf (file, _(" name : %.*s\n"), | |
6095 | egps->namlng, egps->name); | |
6096 | } | |
6097 | break; | |
6098 | case EGSD__C_SPSC: | |
6099 | { | |
6100 | struct vms_esgps *esgps = (struct vms_esgps *)e; | |
6101 | unsigned int flags = bfd_getl16 (esgps->flags); | |
6102 | unsigned int l; | |
6103 | ||
6104 | fprintf (file, _("SPSC - Shared Image Program section def\n")); | |
6105 | fprintf (file, _(" alignment : 2**%u\n"), esgps->align); | |
6106 | fprintf (file, _(" flags : 0x%04x"), flags); | |
6107 | evax_bfd_print_egsd_flags (file, flags); | |
6108 | fputc ('\n', file); | |
6109 | l = bfd_getl32 (esgps->alloc); | |
6110 | fprintf (file, _(" alloc (len) : %u (0x%08x)\n"), l, l); | |
6111 | fprintf (file, _(" image offset : 0x%08x\n"), | |
6112 | (unsigned int)bfd_getl32 (esgps->base)); | |
6113 | fprintf (file, _(" symvec offset : 0x%08x\n"), | |
6114 | (unsigned int)bfd_getl32 (esgps->value)); | |
6115 | fprintf (file, _(" name : %.*s\n"), | |
6116 | esgps->namlng, esgps->name); | |
6117 | } | |
6118 | break; | |
6119 | case EGSD__C_SYM: | |
6120 | { | |
6121 | struct vms_egsy *egsy = (struct vms_egsy *)e; | |
6122 | unsigned int flags = bfd_getl16 (egsy->flags); | |
6123 | ||
6124 | if (flags & EGSY__V_DEF) | |
6125 | { | |
6126 | struct vms_esdf *esdf = (struct vms_esdf *)e; | |
6127 | ||
6128 | fprintf (file, _("SYM - Global symbol definition\n")); | |
6129 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6130 | exav_bfd_print_egsy_flags (flags, file); | |
6131 | fputc ('\n', file); | |
6132 | fprintf (file, _(" psect offset: 0x%08x\n"), | |
6133 | (unsigned)bfd_getl32 (esdf->value)); | |
6134 | if (flags & EGSY__V_NORM) | |
6135 | { | |
6136 | fprintf (file, _(" code address: 0x%08x\n"), | |
6137 | (unsigned)bfd_getl32 (esdf->code_address)); | |
6138 | fprintf (file, _(" psect index for entry point : %u\n"), | |
6139 | (unsigned)bfd_getl32 (esdf->ca_psindx)); | |
6140 | } | |
6141 | fprintf (file, _(" psect index : %u\n"), | |
6142 | (unsigned)bfd_getl32 (esdf->psindx)); | |
6143 | fprintf (file, _(" name : %.*s\n"), | |
6144 | esdf->namlng, esdf->name); | |
6145 | } | |
6146 | else | |
6147 | { | |
6148 | struct vms_esrf *esrf = (struct vms_esrf *)e; | |
6149 | ||
6150 | fprintf (file, _("SYM - Global symbol reference\n")); | |
6151 | fprintf (file, _(" name : %.*s\n"), | |
6152 | esrf->namlng, esrf->name); | |
6153 | } | |
6154 | } | |
6155 | break; | |
6156 | case EGSD__C_IDC: | |
6157 | { | |
6158 | struct vms_eidc *eidc = (struct vms_eidc *)e; | |
6159 | unsigned int flags = bfd_getl32 (eidc->flags); | |
6160 | unsigned char *p; | |
6161 | ||
6162 | fprintf (file, _("IDC - Ident Consistency check\n")); | |
6163 | fprintf (file, _(" flags : 0x%08x"), flags); | |
6164 | if (flags & EIDC__V_BINIDENT) | |
6165 | fputs (" BINDENT", file); | |
6166 | fputc ('\n', file); | |
6167 | fprintf (file, _(" id match : %x\n"), | |
6168 | (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK); | |
6169 | fprintf (file, _(" error severity: %x\n"), | |
6170 | (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK); | |
6171 | p = eidc->name; | |
6172 | fprintf (file, _(" entity name : %.*s\n"), p[0], p + 1); | |
6173 | p += 1 + p[0]; | |
6174 | fprintf (file, _(" object name : %.*s\n"), p[0], p + 1); | |
6175 | p += 1 + p[0]; | |
6176 | if (flags & EIDC__V_BINIDENT) | |
6177 | fprintf (file, _(" binary ident : 0x%08x\n"), | |
6178 | (unsigned)bfd_getl32 (p + 1)); | |
6179 | else | |
6180 | fprintf (file, _(" ascii ident : %.*s\n"), p[0], p + 1); | |
6181 | } | |
6182 | break; | |
6183 | case EGSD__C_SYMG: | |
6184 | { | |
6185 | struct vms_egst *egst = (struct vms_egst *)e; | |
6186 | unsigned int flags = bfd_getl16 (egst->header.flags); | |
6187 | ||
6188 | fprintf (file, _("SYMG - Universal symbol definition\n")); | |
6189 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6190 | exav_bfd_print_egsy_flags (flags, file); | |
6191 | fputc ('\n', file); | |
6192 | fprintf (file, _(" symbol vector offset: 0x%08x\n"), | |
6193 | (unsigned)bfd_getl32 (egst->value)); | |
6194 | fprintf (file, _(" entry point: 0x%08x\n"), | |
6195 | (unsigned)bfd_getl32 (egst->lp_1)); | |
6196 | fprintf (file, _(" proc descr : 0x%08x\n"), | |
6197 | (unsigned)bfd_getl32 (egst->lp_2)); | |
6198 | fprintf (file, _(" psect index: %u\n"), | |
6199 | (unsigned)bfd_getl32 (egst->psindx)); | |
6200 | fprintf (file, _(" name : %.*s\n"), | |
6201 | egst->namlng, egst->name); | |
6202 | } | |
6203 | break; | |
6204 | case EGSD__C_SYMV: | |
6205 | { | |
6206 | struct vms_esdfv *esdfv = (struct vms_esdfv *)e; | |
6207 | unsigned int flags = bfd_getl16 (esdfv->flags); | |
6208 | ||
6209 | fprintf (file, _("SYMV - Vectored symbol definition\n")); | |
6210 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6211 | exav_bfd_print_egsy_flags (flags, file); | |
6212 | fputc ('\n', file); | |
6213 | fprintf (file, _(" vector : 0x%08x\n"), | |
6214 | (unsigned)bfd_getl32 (esdfv->vector)); | |
6215 | fprintf (file, _(" psect offset: %u\n"), | |
6216 | (unsigned)bfd_getl32 (esdfv->value)); | |
6217 | fprintf (file, _(" psect index : %u\n"), | |
6218 | (unsigned)bfd_getl32 (esdfv->psindx)); | |
6219 | fprintf (file, _(" name : %.*s\n"), | |
6220 | esdfv->namlng, esdfv->name); | |
6221 | } | |
6222 | break; | |
6223 | case EGSD__C_SYMM: | |
6224 | { | |
6225 | struct vms_esdfm *esdfm = (struct vms_esdfm *)e; | |
6226 | unsigned int flags = bfd_getl16 (esdfm->flags); | |
6227 | ||
6228 | fprintf (file, _("SYMM - Global symbol definition with version\n")); | |
6229 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6230 | exav_bfd_print_egsy_flags (flags, file); | |
6231 | fputc ('\n', file); | |
6232 | fprintf (file, _(" version mask: 0x%08x\n"), | |
6233 | (unsigned)bfd_getl32 (esdfm->version_mask)); | |
6234 | fprintf (file, _(" psect offset: %u\n"), | |
6235 | (unsigned)bfd_getl32 (esdfm->value)); | |
6236 | fprintf (file, _(" psect index : %u\n"), | |
6237 | (unsigned)bfd_getl32 (esdfm->psindx)); | |
6238 | fprintf (file, _(" name : %.*s\n"), | |
6239 | esdfm->namlng, esdfm->name); | |
6240 | } | |
6241 | break; | |
6242 | default: | |
6243 | fprintf (file, _("unhandled egsd entry type %u\n"), type); | |
6244 | break; | |
6245 | } | |
95e34ef7 TG |
6246 | off += len; |
6247 | } | |
6248 | } | |
6249 | ||
6250 | static void | |
6251 | evax_bfd_print_hex (FILE *file, const char *pfx, | |
07d6d2b8 | 6252 | const unsigned char *buf, unsigned int len) |
95e34ef7 TG |
6253 | { |
6254 | unsigned int i; | |
6255 | unsigned int n; | |
6256 | ||
6257 | n = 0; | |
6258 | for (i = 0; i < len; i++) | |
6259 | { | |
6260 | if (n == 0) | |
07d6d2b8 | 6261 | fputs (pfx, file); |
95e34ef7 TG |
6262 | fprintf (file, " %02x", buf[i]); |
6263 | n++; | |
6264 | if (n == 16) | |
07d6d2b8 AM |
6265 | { |
6266 | n = 0; | |
6267 | fputc ('\n', file); | |
6268 | } | |
95e34ef7 TG |
6269 | } |
6270 | if (n != 0) | |
6271 | fputc ('\n', file); | |
6272 | } | |
6273 | ||
6274 | static void | |
6275 | evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf, int is_ps) | |
6276 | { | |
695344c0 | 6277 | /* xgettext:c-format */ |
95e34ef7 | 6278 | fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"), |
07d6d2b8 AM |
6279 | (unsigned)bfd_getl32 (buf), |
6280 | (unsigned)bfd_getl32 (buf + 16)); | |
695344c0 | 6281 | /* xgettext:c-format */ |
95e34ef7 | 6282 | fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"), |
07d6d2b8 AM |
6283 | (unsigned)bfd_getl32 (buf + 4), |
6284 | (unsigned)bfd_getl32 (buf + 12), | |
6285 | (unsigned)bfd_getl32 (buf + 8)); | |
695344c0 | 6286 | /* xgettext:c-format */ |
95e34ef7 | 6287 | fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"), |
07d6d2b8 AM |
6288 | (unsigned)bfd_getl32 (buf + 20), |
6289 | (unsigned)bfd_getl32 (buf + 28), | |
6290 | (unsigned)bfd_getl32 (buf + 24)); | |
95e34ef7 | 6291 | if (is_ps) |
695344c0 | 6292 | /* xgettext:c-format */ |
95e34ef7 | 6293 | fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"), |
07d6d2b8 AM |
6294 | (unsigned)bfd_getl32 (buf + 32), |
6295 | (unsigned)bfd_getl32 (buf + 40), | |
6296 | (unsigned)bfd_getl32 (buf + 36)); | |
95e34ef7 TG |
6297 | else |
6298 | fprintf (file, _(" global name: %.*s\n"), buf[32], buf + 33); | |
6299 | } | |
6300 | ||
6301 | static void | |
6302 | evax_bfd_print_etir (FILE *file, const char *name, | |
07d6d2b8 | 6303 | unsigned char *rec, unsigned int rec_len) |
95e34ef7 TG |
6304 | { |
6305 | unsigned int off = sizeof (struct vms_egsd); | |
544008aa | 6306 | unsigned int sec_len = 0; |
95e34ef7 | 6307 | |
695344c0 | 6308 | /* xgettext:c-format */ |
95e34ef7 | 6309 | fprintf (file, _(" %s (len=%u+%u):\n"), name, |
07d6d2b8 AM |
6310 | (unsigned)(rec_len - sizeof (struct vms_eobjrec)), |
6311 | (unsigned)sizeof (struct vms_eobjrec)); | |
95e34ef7 TG |
6312 | |
6313 | for (off = sizeof (struct vms_eobjrec); off < rec_len; ) | |
6314 | { | |
6315 | struct vms_etir *etir = (struct vms_etir *)(rec + off); | |
6316 | unsigned char *buf; | |
6317 | unsigned int type; | |
6318 | unsigned int size; | |
6319 | ||
6320 | type = bfd_getl16 (etir->rectyp); | |
6321 | size = bfd_getl16 (etir->size); | |
6322 | buf = rec + off + sizeof (struct vms_etir); | |
6323 | ||
bc21b167 NC |
6324 | if (off + size > rec_len || off + size < off) |
6325 | { | |
6326 | fprintf (file, _(" Error: length larger than remaining space in record\n")); | |
6327 | return; | |
6328 | } | |
6329 | ||
695344c0 | 6330 | /* xgettext:c-format */ |
95e34ef7 TG |
6331 | fprintf (file, _(" (type: %3u, size: 4+%3u): "), type, size - 4); |
6332 | switch (type) | |
07d6d2b8 AM |
6333 | { |
6334 | case ETIR__C_STA_GBL: | |
6335 | fprintf (file, _("STA_GBL (stack global) %.*s\n"), | |
6336 | buf[0], buf + 1); | |
6337 | break; | |
6338 | case ETIR__C_STA_LW: | |
6339 | fprintf (file, _("STA_LW (stack longword) 0x%08x\n"), | |
6340 | (unsigned)bfd_getl32 (buf)); | |
6341 | break; | |
6342 | case ETIR__C_STA_QW: | |
6343 | fprintf (file, _("STA_QW (stack quadword) 0x%08x %08x\n"), | |
6344 | (unsigned)bfd_getl32 (buf + 4), | |
6345 | (unsigned)bfd_getl32 (buf + 0)); | |
6346 | break; | |
6347 | case ETIR__C_STA_PQ: | |
6348 | fprintf (file, _("STA_PQ (stack psect base + offset)\n")); | |
695344c0 | 6349 | /* xgettext:c-format */ |
07d6d2b8 AM |
6350 | fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"), |
6351 | (unsigned)bfd_getl32 (buf + 0), | |
6352 | (unsigned)bfd_getl32 (buf + 8), | |
6353 | (unsigned)bfd_getl32 (buf + 4)); | |
6354 | break; | |
6355 | case ETIR__C_STA_LI: | |
6356 | fprintf (file, _("STA_LI (stack literal)\n")); | |
6357 | break; | |
6358 | case ETIR__C_STA_MOD: | |
6359 | fprintf (file, _("STA_MOD (stack module)\n")); | |
6360 | break; | |
6361 | case ETIR__C_STA_CKARG: | |
6362 | fprintf (file, _("STA_CKARG (compare procedure argument)\n")); | |
6363 | break; | |
6364 | ||
6365 | case ETIR__C_STO_B: | |
6366 | fprintf (file, _("STO_B (store byte)\n")); | |
6367 | break; | |
6368 | case ETIR__C_STO_W: | |
6369 | fprintf (file, _("STO_W (store word)\n")); | |
6370 | break; | |
6371 | case ETIR__C_STO_LW: | |
6372 | fprintf (file, _("STO_LW (store longword)\n")); | |
6373 | break; | |
6374 | case ETIR__C_STO_QW: | |
6375 | fprintf (file, _("STO_QW (store quadword)\n")); | |
6376 | break; | |
6377 | case ETIR__C_STO_IMMR: | |
6378 | { | |
6379 | unsigned int len = bfd_getl32 (buf); | |
6380 | fprintf (file, | |
6381 | _("STO_IMMR (store immediate repeat) %u bytes\n"), | |
6382 | len); | |
6383 | evax_bfd_print_hex (file, " ", buf + 4, len); | |
6384 | sec_len += len; | |
6385 | } | |
6386 | break; | |
6387 | case ETIR__C_STO_GBL: | |
6388 | fprintf (file, _("STO_GBL (store global) %.*s\n"), | |
6389 | buf[0], buf + 1); | |
6390 | break; | |
6391 | case ETIR__C_STO_CA: | |
6392 | fprintf (file, _("STO_CA (store code address) %.*s\n"), | |
6393 | buf[0], buf + 1); | |
6394 | break; | |
6395 | case ETIR__C_STO_RB: | |
6396 | fprintf (file, _("STO_RB (store relative branch)\n")); | |
6397 | break; | |
6398 | case ETIR__C_STO_AB: | |
6399 | fprintf (file, _("STO_AB (store absolute branch)\n")); | |
6400 | break; | |
6401 | case ETIR__C_STO_OFF: | |
6402 | fprintf (file, _("STO_OFF (store offset to psect)\n")); | |
6403 | break; | |
6404 | case ETIR__C_STO_IMM: | |
6405 | { | |
6406 | unsigned int len = bfd_getl32 (buf); | |
6407 | fprintf (file, | |
6408 | _("STO_IMM (store immediate) %u bytes\n"), | |
6409 | len); | |
6410 | evax_bfd_print_hex (file, " ", buf + 4, len); | |
6411 | sec_len += len; | |
6412 | } | |
6413 | break; | |
6414 | case ETIR__C_STO_GBL_LW: | |
6415 | fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"), | |
6416 | buf[0], buf + 1); | |
6417 | break; | |
6418 | case ETIR__C_STO_LP_PSB: | |
6419 | fprintf (file, _("STO_OFF (store LP with procedure signature)\n")); | |
6420 | break; | |
6421 | case ETIR__C_STO_HINT_GBL: | |
6422 | fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n")); | |
6423 | break; | |
6424 | case ETIR__C_STO_HINT_PS: | |
6425 | fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n")); | |
6426 | break; | |
6427 | ||
6428 | case ETIR__C_OPR_NOP: | |
6429 | fprintf (file, _("OPR_NOP (no-operation)\n")); | |
6430 | break; | |
6431 | case ETIR__C_OPR_ADD: | |
6432 | fprintf (file, _("OPR_ADD (add)\n")); | |
6433 | break; | |
6434 | case ETIR__C_OPR_SUB: | |
6435 | fprintf (file, _("OPR_SUB (subtract)\n")); | |
6436 | break; | |
6437 | case ETIR__C_OPR_MUL: | |
6438 | fprintf (file, _("OPR_MUL (multiply)\n")); | |
6439 | break; | |
6440 | case ETIR__C_OPR_DIV: | |
6441 | fprintf (file, _("OPR_DIV (divide)\n")); | |
6442 | break; | |
6443 | case ETIR__C_OPR_AND: | |
6444 | fprintf (file, _("OPR_AND (logical and)\n")); | |
6445 | break; | |
6446 | case ETIR__C_OPR_IOR: | |
6447 | fprintf (file, _("OPR_IOR (logical inclusive or)\n")); | |
6448 | break; | |
6449 | case ETIR__C_OPR_EOR: | |
6450 | fprintf (file, _("OPR_EOR (logical exclusive or)\n")); | |
6451 | break; | |
6452 | case ETIR__C_OPR_NEG: | |
6453 | fprintf (file, _("OPR_NEG (negate)\n")); | |
6454 | break; | |
6455 | case ETIR__C_OPR_COM: | |
6456 | fprintf (file, _("OPR_COM (complement)\n")); | |
6457 | break; | |
6458 | case ETIR__C_OPR_INSV: | |
6459 | fprintf (file, _("OPR_INSV (insert field)\n")); | |
6460 | break; | |
6461 | case ETIR__C_OPR_ASH: | |
6462 | fprintf (file, _("OPR_ASH (arithmetic shift)\n")); | |
6463 | break; | |
6464 | case ETIR__C_OPR_USH: | |
6465 | fprintf (file, _("OPR_USH (unsigned shift)\n")); | |
6466 | break; | |
6467 | case ETIR__C_OPR_ROT: | |
6468 | fprintf (file, _("OPR_ROT (rotate)\n")); | |
6469 | break; | |
6470 | case ETIR__C_OPR_SEL: | |
6471 | fprintf (file, _("OPR_SEL (select)\n")); | |
6472 | break; | |
6473 | case ETIR__C_OPR_REDEF: | |
6474 | fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n")); | |
6475 | break; | |
6476 | case ETIR__C_OPR_DFLIT: | |
6477 | fprintf (file, _("OPR_REDEF (define a literal)\n")); | |
6478 | break; | |
6479 | ||
6480 | case ETIR__C_STC_LP: | |
6481 | fprintf (file, _("STC_LP (store cond linkage pair)\n")); | |
6482 | break; | |
6483 | case ETIR__C_STC_LP_PSB: | |
6484 | fprintf (file, | |
6485 | _("STC_LP_PSB (store cond linkage pair + signature)\n")); | |
695344c0 | 6486 | /* xgettext:c-format */ |
07d6d2b8 AM |
6487 | fprintf (file, _(" linkage index: %u, procedure: %.*s\n"), |
6488 | (unsigned)bfd_getl32 (buf), buf[4], buf + 5); | |
6489 | buf += 4 + 1 + buf[4]; | |
6490 | fprintf (file, _(" signature: %.*s\n"), buf[0], buf + 1); | |
6491 | break; | |
6492 | case ETIR__C_STC_GBL: | |
6493 | fprintf (file, _("STC_GBL (store cond global)\n")); | |
695344c0 | 6494 | /* xgettext:c-format */ |
07d6d2b8 AM |
6495 | fprintf (file, _(" linkage index: %u, global: %.*s\n"), |
6496 | (unsigned)bfd_getl32 (buf), buf[4], buf + 5); | |
6497 | break; | |
6498 | case ETIR__C_STC_GCA: | |
6499 | fprintf (file, _("STC_GCA (store cond code address)\n")); | |
695344c0 | 6500 | /* xgettext:c-format */ |
07d6d2b8 AM |
6501 | fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"), |
6502 | (unsigned)bfd_getl32 (buf), buf[4], buf + 5); | |
6503 | break; | |
6504 | case ETIR__C_STC_PS: | |
6505 | fprintf (file, _("STC_PS (store cond psect + offset)\n")); | |
6506 | fprintf (file, | |
695344c0 | 6507 | /* xgettext:c-format */ |
07d6d2b8 AM |
6508 | _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"), |
6509 | (unsigned)bfd_getl32 (buf), | |
6510 | (unsigned)bfd_getl32 (buf + 4), | |
6511 | (unsigned)bfd_getl32 (buf + 12), | |
6512 | (unsigned)bfd_getl32 (buf + 8)); | |
6513 | break; | |
6514 | case ETIR__C_STC_NOP_GBL: | |
6515 | fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n")); | |
6516 | evax_bfd_print_etir_stc_ir (file, buf, 0); | |
6517 | break; | |
6518 | case ETIR__C_STC_NOP_PS: | |
6519 | fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n")); | |
6520 | evax_bfd_print_etir_stc_ir (file, buf, 1); | |
6521 | break; | |
6522 | case ETIR__C_STC_BSR_GBL: | |
6523 | fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n")); | |
6524 | evax_bfd_print_etir_stc_ir (file, buf, 0); | |
6525 | break; | |
6526 | case ETIR__C_STC_BSR_PS: | |
6527 | fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n")); | |
6528 | evax_bfd_print_etir_stc_ir (file, buf, 1); | |
6529 | break; | |
6530 | case ETIR__C_STC_LDA_GBL: | |
6531 | fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n")); | |
6532 | evax_bfd_print_etir_stc_ir (file, buf, 0); | |
6533 | break; | |
6534 | case ETIR__C_STC_LDA_PS: | |
6535 | fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n")); | |
6536 | evax_bfd_print_etir_stc_ir (file, buf, 1); | |
6537 | break; | |
6538 | case ETIR__C_STC_BOH_GBL: | |
6539 | fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n")); | |
6540 | evax_bfd_print_etir_stc_ir (file, buf, 0); | |
6541 | break; | |
6542 | case ETIR__C_STC_BOH_PS: | |
6543 | fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n")); | |
6544 | evax_bfd_print_etir_stc_ir (file, buf, 1); | |
6545 | break; | |
6546 | case ETIR__C_STC_NBH_GBL: | |
6547 | fprintf (file, | |
6548 | _("STC_NBH_GBL (store cond or hint at global addr)\n")); | |
6549 | break; | |
6550 | case ETIR__C_STC_NBH_PS: | |
6551 | fprintf (file, | |
6552 | _("STC_NBH_PS (store cond or hint at psect + offset)\n")); | |
6553 | break; | |
6554 | ||
6555 | case ETIR__C_CTL_SETRB: | |
6556 | fprintf (file, _("CTL_SETRB (set relocation base)\n")); | |
6557 | sec_len += 4; | |
6558 | break; | |
6559 | case ETIR__C_CTL_AUGRB: | |
6560 | { | |
6561 | unsigned int val = bfd_getl32 (buf); | |
6562 | fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"), val); | |
6563 | } | |
6564 | break; | |
6565 | case ETIR__C_CTL_DFLOC: | |
6566 | fprintf (file, _("CTL_DFLOC (define location)\n")); | |
6567 | break; | |
6568 | case ETIR__C_CTL_STLOC: | |
6569 | fprintf (file, _("CTL_STLOC (set location)\n")); | |
6570 | break; | |
6571 | case ETIR__C_CTL_STKDL: | |
6572 | fprintf (file, _("CTL_STKDL (stack defined location)\n")); | |
6573 | break; | |
6574 | default: | |
6575 | fprintf (file, _("*unhandled*\n")); | |
6576 | break; | |
6577 | } | |
95e34ef7 TG |
6578 | off += size; |
6579 | } | |
6580 | } | |
6581 | ||
6582 | static void | |
6583 | evax_bfd_print_eobj (struct bfd *abfd, FILE *file) | |
6584 | { | |
6585 | bfd_boolean is_first = TRUE; | |
6586 | bfd_boolean has_records = FALSE; | |
6587 | ||
6588 | while (1) | |
6589 | { | |
6590 | unsigned int rec_len; | |
6591 | unsigned int pad_len; | |
6592 | unsigned char *rec; | |
6593 | unsigned int hdr_size; | |
6594 | unsigned int type; | |
6595 | ||
6596 | if (is_first) | |
07d6d2b8 AM |
6597 | { |
6598 | unsigned char buf[6]; | |
6599 | ||
6600 | is_first = FALSE; | |
6601 | ||
6602 | /* Read 6 bytes. */ | |
6603 | if (bfd_bread (buf, sizeof (buf), abfd) != sizeof (buf)) | |
6604 | { | |
6605 | fprintf (file, _("cannot read GST record length\n")); | |
6606 | return; | |
6607 | } | |
6608 | rec_len = bfd_getl16 (buf + 0); | |
6609 | if (rec_len == bfd_getl16 (buf + 4) | |
6610 | && bfd_getl16 (buf + 2) == EOBJ__C_EMH) | |
6611 | { | |
6612 | /* The format is raw: record-size, type, record-size. */ | |
6613 | has_records = TRUE; | |
6614 | pad_len = (rec_len + 1) & ~1U; | |
6615 | hdr_size = 4; | |
6616 | } | |
6617 | else if (rec_len == EOBJ__C_EMH) | |
6618 | { | |
6619 | has_records = FALSE; | |
6620 | pad_len = bfd_getl16 (buf + 2); | |
6621 | hdr_size = 6; | |
6622 | } | |
6623 | else | |
6624 | { | |
6625 | /* Ill-formed. */ | |
6626 | fprintf (file, _("cannot find EMH in first GST record\n")); | |
6627 | return; | |
6628 | } | |
6629 | rec = bfd_malloc (pad_len); | |
6630 | memcpy (rec, buf + sizeof (buf) - hdr_size, hdr_size); | |
6631 | } | |
6632 | else | |
6633 | { | |
6634 | unsigned int rec_len2 = 0; | |
6635 | unsigned char hdr[4]; | |
6636 | ||
6637 | if (has_records) | |
6638 | { | |
6639 | unsigned char buf_len[2]; | |
6640 | ||
6641 | if (bfd_bread (buf_len, sizeof (buf_len), abfd) | |
6642 | != sizeof (buf_len)) | |
6643 | { | |
6644 | fprintf (file, _("cannot read GST record length\n")); | |
6645 | return; | |
6646 | } | |
6647 | rec_len2 = (unsigned)bfd_getl16 (buf_len); | |
6648 | } | |
6649 | ||
6650 | if (bfd_bread (hdr, sizeof (hdr), abfd) != sizeof (hdr)) | |
6651 | { | |
6652 | fprintf (file, _("cannot read GST record header\n")); | |
6653 | return; | |
6654 | } | |
6655 | rec_len = (unsigned)bfd_getl16 (hdr + 2); | |
6656 | if (has_records) | |
6657 | pad_len = (rec_len + 1) & ~1U; | |
6658 | else | |
6659 | pad_len = rec_len; | |
6660 | rec = bfd_malloc (pad_len); | |
6661 | memcpy (rec, hdr, sizeof (hdr)); | |
6662 | hdr_size = sizeof (hdr); | |
6663 | if (has_records && rec_len2 != rec_len) | |
6664 | { | |
6665 | fprintf (file, _(" corrupted GST\n")); | |
6666 | break; | |
6667 | } | |
6668 | } | |
95e34ef7 TG |
6669 | |
6670 | if (bfd_bread (rec + hdr_size, pad_len - hdr_size, abfd) | |
07d6d2b8 AM |
6671 | != pad_len - hdr_size) |
6672 | { | |
6673 | fprintf (file, _("cannot read GST record\n")); | |
6674 | return; | |
6675 | } | |
95e34ef7 TG |
6676 | |
6677 | type = (unsigned)bfd_getl16 (rec); | |
6678 | ||
6679 | switch (type) | |
07d6d2b8 AM |
6680 | { |
6681 | case EOBJ__C_EMH: | |
6682 | evax_bfd_print_emh (file, rec, rec_len); | |
6683 | break; | |
6684 | case EOBJ__C_EGSD: | |
6685 | evax_bfd_print_egsd (file, rec, rec_len); | |
6686 | break; | |
6687 | case EOBJ__C_EEOM: | |
6688 | evax_bfd_print_eeom (file, rec, rec_len); | |
6689 | free (rec); | |
6690 | return; | |
6691 | break; | |
6692 | case EOBJ__C_ETIR: | |
6693 | evax_bfd_print_etir (file, "ETIR", rec, rec_len); | |
6694 | break; | |
6695 | case EOBJ__C_EDBG: | |
6696 | evax_bfd_print_etir (file, "EDBG", rec, rec_len); | |
6697 | break; | |
6698 | case EOBJ__C_ETBT: | |
6699 | evax_bfd_print_etir (file, "ETBT", rec, rec_len); | |
6700 | break; | |
6701 | default: | |
6702 | fprintf (file, _(" unhandled EOBJ record type %u\n"), type); | |
6703 | break; | |
6704 | } | |
95e34ef7 TG |
6705 | free (rec); |
6706 | } | |
6707 | } | |
6708 | ||
6709 | static void | |
6710 | evax_bfd_print_relocation_records (FILE *file, const unsigned char *rel, | |
07d6d2b8 | 6711 | unsigned int stride) |
95e34ef7 TG |
6712 | { |
6713 | while (1) | |
6714 | { | |
6715 | unsigned int base; | |
6716 | unsigned int count; | |
6717 | unsigned int j; | |
6718 | ||
6719 | count = bfd_getl32 (rel + 0); | |
6720 | ||
6721 | if (count == 0) | |
07d6d2b8 | 6722 | break; |
95e34ef7 TG |
6723 | base = bfd_getl32 (rel + 4); |
6724 | ||
695344c0 | 6725 | /* xgettext:c-format */ |
95e34ef7 | 6726 | fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"), |
07d6d2b8 | 6727 | count, base); |
95e34ef7 TG |
6728 | |
6729 | rel += 8; | |
6730 | for (j = 0; count > 0; j += 4, count -= 32) | |
07d6d2b8 AM |
6731 | { |
6732 | unsigned int k; | |
6733 | unsigned int n = 0; | |
6734 | unsigned int val; | |
95e34ef7 | 6735 | |
07d6d2b8 AM |
6736 | val = bfd_getl32 (rel); |
6737 | rel += 4; | |
95e34ef7 | 6738 | |
695344c0 | 6739 | /* xgettext:c-format */ |
07d6d2b8 AM |
6740 | fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count); |
6741 | ||
6742 | for (k = 0; k < 32; k++) | |
401e101e | 6743 | if (val & (1u << k)) |
07d6d2b8 AM |
6744 | { |
6745 | if (n == 0) | |
6746 | fputs (" ", file); | |
6747 | fprintf (file, _(" %08x"), base + (j * 8 + k) * stride); | |
6748 | n++; | |
6749 | if (n == 8) | |
6750 | { | |
6751 | fputs ("\n", file); | |
6752 | n = 0; | |
6753 | } | |
6754 | } | |
6755 | if (n) | |
6756 | fputs ("\n", file); | |
6757 | } | |
95e34ef7 TG |
6758 | } |
6759 | } | |
6760 | ||
6761 | static void | |
6762 | evax_bfd_print_address_fixups (FILE *file, const unsigned char *rel) | |
6763 | { | |
6764 | while (1) | |
6765 | { | |
6766 | unsigned int j; | |
6767 | unsigned int count; | |
6768 | ||
6769 | count = bfd_getl32 (rel + 0); | |
6770 | if (count == 0) | |
07d6d2b8 | 6771 | return; |
695344c0 | 6772 | /* xgettext:c-format */ |
95e34ef7 | 6773 | fprintf (file, _(" image %u (%u entries)\n"), |
07d6d2b8 | 6774 | (unsigned)bfd_getl32 (rel + 4), count); |
95e34ef7 TG |
6775 | rel += 8; |
6776 | for (j = 0; j < count; j++) | |
07d6d2b8 | 6777 | { |
695344c0 | 6778 | /* xgettext:c-format */ |
07d6d2b8 AM |
6779 | fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"), |
6780 | (unsigned)bfd_getl32 (rel + 0), | |
6781 | (unsigned)bfd_getl32 (rel + 4)); | |
6782 | rel += 8; | |
6783 | } | |
95e34ef7 TG |
6784 | } |
6785 | } | |
6786 | ||
6787 | static void | |
6788 | evax_bfd_print_reference_fixups (FILE *file, const unsigned char *rel) | |
6789 | { | |
6790 | unsigned int count; | |
6791 | ||
6792 | while (1) | |
6793 | { | |
6794 | unsigned int j; | |
6795 | unsigned int n = 0; | |
6796 | ||
6797 | count = bfd_getl32 (rel + 0); | |
6798 | if (count == 0) | |
07d6d2b8 | 6799 | break; |
695344c0 | 6800 | /* xgettext:c-format */ |
95e34ef7 | 6801 | fprintf (file, _(" image %u (%u entries), offsets:\n"), |
07d6d2b8 | 6802 | (unsigned)bfd_getl32 (rel + 4), count); |
95e34ef7 TG |
6803 | rel += 8; |
6804 | for (j = 0; j < count; j++) | |
07d6d2b8 AM |
6805 | { |
6806 | if (n == 0) | |
6807 | fputs (" ", file); | |
6808 | fprintf (file, _(" 0x%08x"), (unsigned)bfd_getl32 (rel)); | |
6809 | n++; | |
6810 | if (n == 7) | |
6811 | { | |
6812 | fputs ("\n", file); | |
6813 | n = 0; | |
6814 | } | |
6815 | rel += 4; | |
6816 | } | |
95e34ef7 | 6817 | if (n) |
07d6d2b8 | 6818 | fputs ("\n", file); |
95e34ef7 TG |
6819 | } |
6820 | } | |
6821 | ||
6822 | static void | |
6823 | evax_bfd_print_indent (int indent, FILE *file) | |
6824 | { | |
6825 | for (; indent; indent--) | |
6826 | fputc (' ', file); | |
6827 | } | |
6828 | ||
6829 | static const char * | |
6830 | evax_bfd_get_dsc_name (unsigned int v) | |
6831 | { | |
6832 | switch (v) | |
6833 | { | |
6834 | case DSC__K_DTYPE_Z: | |
6835 | return "Z (Unspecified)"; | |
6836 | case DSC__K_DTYPE_V: | |
6837 | return "V (Bit)"; | |
6838 | case DSC__K_DTYPE_BU: | |
6839 | return "BU (Byte logical)"; | |
6840 | case DSC__K_DTYPE_WU: | |
6841 | return "WU (Word logical)"; | |
6842 | case DSC__K_DTYPE_LU: | |
6843 | return "LU (Longword logical)"; | |
6844 | case DSC__K_DTYPE_QU: | |
6845 | return "QU (Quadword logical)"; | |
6846 | case DSC__K_DTYPE_B: | |
6847 | return "B (Byte integer)"; | |
6848 | case DSC__K_DTYPE_W: | |
6849 | return "W (Word integer)"; | |
6850 | case DSC__K_DTYPE_L: | |
6851 | return "L (Longword integer)"; | |
6852 | case DSC__K_DTYPE_Q: | |
6853 | return "Q (Quadword integer)"; | |
6854 | case DSC__K_DTYPE_F: | |
6855 | return "F (Single-precision floating)"; | |
6856 | case DSC__K_DTYPE_D: | |
6857 | return "D (Double-precision floating)"; | |
6858 | case DSC__K_DTYPE_FC: | |
6859 | return "FC (Complex)"; | |
6860 | case DSC__K_DTYPE_DC: | |
6861 | return "DC (Double-precision Complex)"; | |
6862 | case DSC__K_DTYPE_T: | |
6863 | return "T (ASCII text string)"; | |
6864 | case DSC__K_DTYPE_NU: | |
6865 | return "NU (Numeric string, unsigned)"; | |
6866 | case DSC__K_DTYPE_NL: | |
6867 | return "NL (Numeric string, left separate sign)"; | |
6868 | case DSC__K_DTYPE_NLO: | |
6869 | return "NLO (Numeric string, left overpunched sign)"; | |
6870 | case DSC__K_DTYPE_NR: | |
6871 | return "NR (Numeric string, right separate sign)"; | |
6872 | case DSC__K_DTYPE_NRO: | |
6873 | return "NRO (Numeric string, right overpunched sig)"; | |
6874 | case DSC__K_DTYPE_NZ: | |
6875 | return "NZ (Numeric string, zoned sign)"; | |
6876 | case DSC__K_DTYPE_P: | |
6877 | return "P (Packed decimal string)"; | |
6878 | case DSC__K_DTYPE_ZI: | |
6879 | return "ZI (Sequence of instructions)"; | |
6880 | case DSC__K_DTYPE_ZEM: | |
6881 | return "ZEM (Procedure entry mask)"; | |
6882 | case DSC__K_DTYPE_DSC: | |
6883 | return "DSC (Descriptor, used for arrays of dyn strings)"; | |
6884 | case DSC__K_DTYPE_OU: | |
6885 | return "OU (Octaword logical)"; | |
6886 | case DSC__K_DTYPE_O: | |
6887 | return "O (Octaword integer)"; | |
6888 | case DSC__K_DTYPE_G: | |
6889 | return "G (Double precision G floating, 64 bit)"; | |
6890 | case DSC__K_DTYPE_H: | |
6891 | return "H (Quadruple precision floating, 128 bit)"; | |
6892 | case DSC__K_DTYPE_GC: | |
6893 | return "GC (Double precision complex, G floating)"; | |
6894 | case DSC__K_DTYPE_HC: | |
6895 | return "HC (Quadruple precision complex, H floating)"; | |
6896 | case DSC__K_DTYPE_CIT: | |
6897 | return "CIT (COBOL intermediate temporary)"; | |
6898 | case DSC__K_DTYPE_BPV: | |
6899 | return "BPV (Bound Procedure Value)"; | |
6900 | case DSC__K_DTYPE_BLV: | |
6901 | return "BLV (Bound Label Value)"; | |
6902 | case DSC__K_DTYPE_VU: | |
6903 | return "VU (Bit Unaligned)"; | |
6904 | case DSC__K_DTYPE_ADT: | |
6905 | return "ADT (Absolute Date-Time)"; | |
6906 | case DSC__K_DTYPE_VT: | |
6907 | return "VT (Varying Text)"; | |
6908 | case DSC__K_DTYPE_T2: | |
6909 | return "T2 (16-bit char)"; | |
6910 | case DSC__K_DTYPE_VT2: | |
6911 | return "VT2 (16-bit varying char)"; | |
6912 | default: | |
6913 | return "?? (unknown)"; | |
6914 | } | |
6915 | } | |
6916 | ||
6917 | static void | |
6918 | evax_bfd_print_desc (const unsigned char *buf, int indent, FILE *file) | |
6919 | { | |
6920 | unsigned char bclass = buf[3]; | |
6921 | unsigned char dtype = buf[2]; | |
6922 | unsigned int len = (unsigned)bfd_getl16 (buf); | |
6923 | unsigned int pointer = (unsigned)bfd_getl32 (buf + 4); | |
6924 | ||
6925 | evax_bfd_print_indent (indent, file); | |
6926 | ||
6927 | if (len == 1 && pointer == 0xffffffffUL) | |
6928 | { | |
6929 | /* 64 bits. */ | |
6930 | fprintf (file, _("64 bits *unhandled*\n")); | |
6931 | } | |
6932 | else | |
6933 | { | |
695344c0 | 6934 | /* xgettext:c-format */ |
95e34ef7 | 6935 | fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"), |
07d6d2b8 | 6936 | bclass, dtype, len, pointer); |
95e34ef7 | 6937 | switch (bclass) |
07d6d2b8 AM |
6938 | { |
6939 | case DSC__K_CLASS_NCA: | |
6940 | { | |
6941 | const struct vms_dsc_nca *dsc = (const void *)buf; | |
6942 | unsigned int i; | |
6943 | const unsigned char *b; | |
6944 | ||
6945 | evax_bfd_print_indent (indent, file); | |
6946 | fprintf (file, _("non-contiguous array of %s\n"), | |
6947 | evax_bfd_get_dsc_name (dsc->dtype)); | |
6948 | evax_bfd_print_indent (indent + 1, file); | |
6949 | fprintf (file, | |
695344c0 | 6950 | /* xgettext:c-format */ |
07d6d2b8 AM |
6951 | _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"), |
6952 | dsc->dimct, dsc->aflags, dsc->digits, dsc->scale); | |
6953 | evax_bfd_print_indent (indent + 1, file); | |
6954 | fprintf (file, | |
695344c0 | 6955 | /* xgettext:c-format */ |
07d6d2b8 AM |
6956 | _("arsize: %u, a0: 0x%08x\n"), |
6957 | (unsigned)bfd_getl32 (dsc->arsize), | |
6958 | (unsigned)bfd_getl32 (dsc->a0)); | |
6959 | evax_bfd_print_indent (indent + 1, file); | |
6960 | fprintf (file, _("Strides:\n")); | |
6961 | b = buf + sizeof (*dsc); | |
6962 | for (i = 0; i < dsc->dimct; i++) | |
6963 | { | |
6964 | evax_bfd_print_indent (indent + 2, file); | |
6965 | fprintf (file, "[%u]: %u\n", i + 1, | |
6966 | (unsigned)bfd_getl32 (b)); | |
6967 | b += 4; | |
6968 | } | |
6969 | evax_bfd_print_indent (indent + 1, file); | |
6970 | fprintf (file, _("Bounds:\n")); | |
6971 | b = buf + sizeof (*dsc); | |
6972 | for (i = 0; i < dsc->dimct; i++) | |
6973 | { | |
6974 | evax_bfd_print_indent (indent + 2, file); | |
695344c0 | 6975 | /* xgettext:c-format */ |
07d6d2b8 AM |
6976 | fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1, |
6977 | (unsigned)bfd_getl32 (b + 0), | |
6978 | (unsigned)bfd_getl32 (b + 4)); | |
6979 | b += 8; | |
6980 | } | |
6981 | } | |
6982 | break; | |
6983 | case DSC__K_CLASS_UBS: | |
6984 | { | |
6985 | const struct vms_dsc_ubs *ubs = (const void *)buf; | |
6986 | ||
6987 | evax_bfd_print_indent (indent, file); | |
6988 | fprintf (file, _("unaligned bit-string of %s\n"), | |
6989 | evax_bfd_get_dsc_name (ubs->dtype)); | |
6990 | evax_bfd_print_indent (indent + 1, file); | |
6991 | fprintf (file, | |
695344c0 | 6992 | /* xgettext:c-format */ |
07d6d2b8 AM |
6993 | _("base: %u, pos: %u\n"), |
6994 | (unsigned)bfd_getl32 (ubs->base), | |
6995 | (unsigned)bfd_getl32 (ubs->pos)); | |
6996 | } | |
6997 | break; | |
6998 | default: | |
6999 | fprintf (file, _("*unhandled*\n")); | |
7000 | break; | |
7001 | } | |
95e34ef7 TG |
7002 | } |
7003 | } | |
7004 | ||
7005 | static unsigned int | |
7006 | evax_bfd_print_valspec (const unsigned char *buf, int indent, FILE *file) | |
7007 | { | |
7008 | unsigned int vflags = buf[0]; | |
7009 | unsigned int value = (unsigned)bfd_getl32 (buf + 1); | |
7010 | unsigned int len = 5; | |
7011 | ||
7012 | evax_bfd_print_indent (indent, file); | |
695344c0 | 7013 | /* xgettext:c-format */ |
95e34ef7 TG |
7014 | fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value); |
7015 | buf += 5; | |
7016 | ||
7017 | switch (vflags) | |
7018 | { | |
7019 | case DST__K_VFLAGS_NOVAL: | |
7020 | fprintf (file, _("(no value)\n")); | |
7021 | break; | |
7022 | case DST__K_VFLAGS_NOTACTIVE: | |
7023 | fprintf (file, _("(not active)\n")); | |
7024 | break; | |
7025 | case DST__K_VFLAGS_UNALLOC: | |
7026 | fprintf (file, _("(not allocated)\n")); | |
7027 | break; | |
7028 | case DST__K_VFLAGS_DSC: | |
7029 | fprintf (file, _("(descriptor)\n")); | |
7030 | evax_bfd_print_desc (buf + value, indent + 1, file); | |
7031 | break; | |
7032 | case DST__K_VFLAGS_TVS: | |
7033 | fprintf (file, _("(trailing value)\n")); | |
7034 | break; | |
7035 | case DST__K_VS_FOLLOWS: | |
7036 | fprintf (file, _("(value spec follows)\n")); | |
7037 | break; | |
7038 | case DST__K_VFLAGS_BITOFFS: | |
7039 | fprintf (file, _("(at bit offset %u)\n"), value); | |
7040 | break; | |
7041 | default: | |
695344c0 | 7042 | /* xgettext:c-format */ |
95e34ef7 | 7043 | fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "), |
07d6d2b8 AM |
7044 | (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT, |
7045 | vflags & DST__K_DISP ? 1 : 0, | |
7046 | vflags & DST__K_INDIR ? 1 : 0); | |
95e34ef7 | 7047 | switch (vflags & DST__K_VALKIND_MASK) |
07d6d2b8 AM |
7048 | { |
7049 | case DST__K_VALKIND_LITERAL: | |
7050 | fputs (_("literal"), file); | |
7051 | break; | |
7052 | case DST__K_VALKIND_ADDR: | |
7053 | fputs (_("address"), file); | |
7054 | break; | |
7055 | case DST__K_VALKIND_DESC: | |
7056 | fputs (_("desc"), file); | |
7057 | break; | |
7058 | case DST__K_VALKIND_REG: | |
7059 | fputs (_("reg"), file); | |
7060 | break; | |
7061 | } | |
95e34ef7 TG |
7062 | fputs (")\n", file); |
7063 | break; | |
7064 | } | |
7065 | return len; | |
7066 | } | |
7067 | ||
7068 | static void | |
7069 | evax_bfd_print_typspec (const unsigned char *buf, int indent, FILE *file) | |
7070 | { | |
7071 | unsigned char kind = buf[2]; | |
7072 | unsigned int len = (unsigned)bfd_getl16 (buf); | |
7073 | ||
7074 | evax_bfd_print_indent (indent, file); | |
695344c0 NC |
7075 | /* xgettext:c-format */ |
7076 | fprintf (file, _("len: %2u, kind: %2u "), len, kind); | |
95e34ef7 TG |
7077 | buf += 3; |
7078 | switch (kind) | |
7079 | { | |
7080 | case DST__K_TS_ATOM: | |
695344c0 NC |
7081 | /* xgettext:c-format */ |
7082 | fprintf (file, _("atomic, type=0x%02x %s\n"), | |
07d6d2b8 | 7083 | buf[0], evax_bfd_get_dsc_name (buf[0])); |
95e34ef7 TG |
7084 | break; |
7085 | case DST__K_TS_IND: | |
695344c0 | 7086 | fprintf (file, _("indirect, defined at 0x%08x\n"), |
07d6d2b8 | 7087 | (unsigned)bfd_getl32 (buf)); |
95e34ef7 TG |
7088 | break; |
7089 | case DST__K_TS_TPTR: | |
695344c0 | 7090 | fprintf (file, _("typed pointer\n")); |
95e34ef7 TG |
7091 | evax_bfd_print_typspec (buf, indent + 1, file); |
7092 | break; | |
7093 | case DST__K_TS_PTR: | |
695344c0 | 7094 | fprintf (file, _("pointer\n")); |
95e34ef7 TG |
7095 | break; |
7096 | case DST__K_TS_ARRAY: | |
7097 | { | |
07d6d2b8 AM |
7098 | const unsigned char *vs; |
7099 | unsigned int vec_len; | |
7100 | unsigned int i; | |
7101 | ||
7102 | fprintf (file, _("array, dim: %u, bitmap: "), buf[0]); | |
7103 | vec_len = (buf[0] + 1 + 7) / 8; | |
7104 | for (i = 0; i < vec_len; i++) | |
7105 | fprintf (file, " %02x", buf[i + 1]); | |
7106 | fputc ('\n', file); | |
7107 | vs = buf + 1 + vec_len; | |
7108 | evax_bfd_print_indent (indent, file); | |
7109 | fprintf (file, _("array descriptor:\n")); | |
7110 | vs += evax_bfd_print_valspec (vs, indent + 1, file); | |
7111 | for (i = 0; i < buf[0] + 1U; i++) | |
7112 | if (buf[1 + i / 8] & (1 << (i % 8))) | |
7113 | { | |
7114 | evax_bfd_print_indent (indent, file); | |
7115 | if (i == 0) | |
7116 | fprintf (file, _("type spec for element:\n")); | |
7117 | else | |
7118 | fprintf (file, _("type spec for subscript %u:\n"), i); | |
7119 | evax_bfd_print_typspec (vs, indent + 1, file); | |
7120 | vs += bfd_getl16 (vs); | |
7121 | } | |
95e34ef7 TG |
7122 | } |
7123 | break; | |
7124 | default: | |
695344c0 | 7125 | fprintf (file, _("*unhandled*\n")); |
95e34ef7 TG |
7126 | } |
7127 | } | |
7128 | ||
7129 | static void | |
7130 | evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file) | |
7131 | { | |
7132 | unsigned int off = 0; | |
7133 | unsigned int pc = 0; | |
7134 | unsigned int line = 0; | |
7135 | ||
7136 | fprintf (file, _("Debug symbol table:\n")); | |
7137 | ||
7138 | while (dst_size > 0) | |
7139 | { | |
7140 | struct vms_dst_header dsth; | |
7141 | unsigned int len; | |
7142 | unsigned int type; | |
7143 | unsigned char *buf; | |
7144 | ||
7145 | if (bfd_bread (&dsth, sizeof (dsth), abfd) != sizeof (dsth)) | |
07d6d2b8 AM |
7146 | { |
7147 | fprintf (file, _("cannot read DST header\n")); | |
7148 | return; | |
7149 | } | |
95e34ef7 TG |
7150 | len = bfd_getl16 (dsth.length); |
7151 | type = bfd_getl16 (dsth.type); | |
695344c0 | 7152 | /* xgettext:c-format */ |
95e34ef7 | 7153 | fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "), |
07d6d2b8 | 7154 | type, len, off); |
95e34ef7 | 7155 | if (len == 0) |
07d6d2b8 AM |
7156 | { |
7157 | fputc ('\n', file); | |
7158 | break; | |
7159 | } | |
95e34ef7 TG |
7160 | len++; |
7161 | dst_size -= len; | |
7162 | off += len; | |
7163 | len -= sizeof (dsth); | |
2bb3687b AM |
7164 | buf = _bfd_malloc_and_read (abfd, len, len); |
7165 | if (buf == NULL) | |
07d6d2b8 AM |
7166 | { |
7167 | fprintf (file, _("cannot read DST symbol\n")); | |
7168 | return; | |
7169 | } | |
95e34ef7 | 7170 | switch (type) |
07d6d2b8 AM |
7171 | { |
7172 | case DSC__K_DTYPE_V: | |
7173 | case DSC__K_DTYPE_BU: | |
7174 | case DSC__K_DTYPE_WU: | |
7175 | case DSC__K_DTYPE_LU: | |
7176 | case DSC__K_DTYPE_QU: | |
7177 | case DSC__K_DTYPE_B: | |
7178 | case DSC__K_DTYPE_W: | |
7179 | case DSC__K_DTYPE_L: | |
7180 | case DSC__K_DTYPE_Q: | |
7181 | case DSC__K_DTYPE_F: | |
7182 | case DSC__K_DTYPE_D: | |
7183 | case DSC__K_DTYPE_FC: | |
7184 | case DSC__K_DTYPE_DC: | |
7185 | case DSC__K_DTYPE_T: | |
7186 | case DSC__K_DTYPE_NU: | |
7187 | case DSC__K_DTYPE_NL: | |
7188 | case DSC__K_DTYPE_NLO: | |
7189 | case DSC__K_DTYPE_NR: | |
7190 | case DSC__K_DTYPE_NRO: | |
7191 | case DSC__K_DTYPE_NZ: | |
7192 | case DSC__K_DTYPE_P: | |
7193 | case DSC__K_DTYPE_ZI: | |
7194 | case DSC__K_DTYPE_ZEM: | |
7195 | case DSC__K_DTYPE_DSC: | |
7196 | case DSC__K_DTYPE_OU: | |
7197 | case DSC__K_DTYPE_O: | |
7198 | case DSC__K_DTYPE_G: | |
7199 | case DSC__K_DTYPE_H: | |
7200 | case DSC__K_DTYPE_GC: | |
7201 | case DSC__K_DTYPE_HC: | |
7202 | case DSC__K_DTYPE_CIT: | |
7203 | case DSC__K_DTYPE_BPV: | |
7204 | case DSC__K_DTYPE_BLV: | |
7205 | case DSC__K_DTYPE_VU: | |
7206 | case DSC__K_DTYPE_ADT: | |
7207 | case DSC__K_DTYPE_VT: | |
7208 | case DSC__K_DTYPE_T2: | |
7209 | case DSC__K_DTYPE_VT2: | |
7210 | fprintf (file, _("standard data: %s\n"), | |
7211 | evax_bfd_get_dsc_name (type)); | |
7212 | evax_bfd_print_valspec (buf, 4, file); | |
7213 | fprintf (file, _(" name: %.*s\n"), buf[5], buf + 6); | |
7214 | break; | |
7215 | case DST__K_MODBEG: | |
7216 | { | |
7217 | struct vms_dst_modbeg *dst = (void *)buf; | |
7218 | const char *name = (const char *)buf + sizeof (*dst); | |
7219 | ||
7220 | fprintf (file, _("modbeg\n")); | |
695344c0 | 7221 | /* xgettext:c-format */ |
07d6d2b8 AM |
7222 | fprintf (file, _(" flags: %d, language: %u, " |
7223 | "major: %u, minor: %u\n"), | |
7224 | dst->flags, | |
7225 | (unsigned)bfd_getl32 (dst->language), | |
7226 | (unsigned)bfd_getl16 (dst->major), | |
7227 | (unsigned)bfd_getl16 (dst->minor)); | |
7228 | fprintf (file, _(" module name: %.*s\n"), | |
7229 | name[0], name + 1); | |
7230 | name += name[0] + 1; | |
7231 | fprintf (file, _(" compiler : %.*s\n"), | |
7232 | name[0], name + 1); | |
7233 | } | |
7234 | break; | |
7235 | case DST__K_MODEND: | |
7236 | fprintf (file, _("modend\n")); | |
7237 | break; | |
7238 | case DST__K_RTNBEG: | |
7239 | { | |
7240 | struct vms_dst_rtnbeg *dst = (void *)buf; | |
7241 | const char *name = (const char *)buf + sizeof (*dst); | |
7242 | ||
7243 | fputs (_("rtnbeg\n"), file); | |
695344c0 | 7244 | /* xgettext:c-format */ |
07d6d2b8 AM |
7245 | fprintf (file, _(" flags: %u, address: 0x%08x, " |
7246 | "pd-address: 0x%08x\n"), | |
7247 | dst->flags, | |
7248 | (unsigned)bfd_getl32 (dst->address), | |
7249 | (unsigned)bfd_getl32 (dst->pd_address)); | |
7250 | fprintf (file, _(" routine name: %.*s\n"), | |
7251 | name[0], name + 1); | |
7252 | } | |
7253 | break; | |
7254 | case DST__K_RTNEND: | |
7255 | { | |
7256 | struct vms_dst_rtnend *dst = (void *)buf; | |
7257 | ||
7258 | fprintf (file, _("rtnend: size 0x%08x\n"), | |
7259 | (unsigned)bfd_getl32 (dst->size)); | |
7260 | } | |
7261 | break; | |
7262 | case DST__K_PROLOG: | |
7263 | { | |
7264 | struct vms_dst_prolog *dst = (void *)buf; | |
7265 | ||
7266 | fprintf (file, _("prolog: bkpt address 0x%08x\n"), | |
7267 | (unsigned)bfd_getl32 (dst->bkpt_addr)); | |
7268 | } | |
7269 | break; | |
7270 | case DST__K_EPILOG: | |
7271 | { | |
7272 | struct vms_dst_epilog *dst = (void *)buf; | |
95e34ef7 | 7273 | |
695344c0 | 7274 | /* xgettext:c-format */ |
07d6d2b8 AM |
7275 | fprintf (file, _("epilog: flags: %u, count: %u\n"), |
7276 | dst->flags, (unsigned)bfd_getl32 (dst->count)); | |
7277 | } | |
7278 | break; | |
7279 | case DST__K_BLKBEG: | |
7280 | { | |
7281 | struct vms_dst_blkbeg *dst = (void *)buf; | |
7282 | const char *name = (const char *)buf + sizeof (*dst); | |
95e34ef7 | 7283 | |
695344c0 | 7284 | /* xgettext:c-format */ |
07d6d2b8 AM |
7285 | fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"), |
7286 | (unsigned)bfd_getl32 (dst->address), | |
7287 | name[0], name + 1); | |
7288 | } | |
7289 | break; | |
7290 | case DST__K_BLKEND: | |
7291 | { | |
7292 | struct vms_dst_blkend *dst = (void *)buf; | |
7293 | ||
7294 | fprintf (file, _("blkend: size: 0x%08x\n"), | |
7295 | (unsigned)bfd_getl32 (dst->size)); | |
7296 | } | |
7297 | break; | |
7298 | case DST__K_TYPSPEC: | |
7299 | { | |
7300 | fprintf (file, _("typspec (len: %u)\n"), len); | |
7301 | fprintf (file, _(" name: %.*s\n"), buf[0], buf + 1); | |
7302 | evax_bfd_print_typspec (buf + 1 + buf[0], 5, file); | |
7303 | } | |
7304 | break; | |
7305 | case DST__K_SEPTYP: | |
7306 | { | |
7307 | fprintf (file, _("septyp, name: %.*s\n"), buf[5], buf + 6); | |
7308 | evax_bfd_print_valspec (buf, 4, file); | |
7309 | } | |
7310 | break; | |
7311 | case DST__K_RECBEG: | |
7312 | { | |
7313 | struct vms_dst_recbeg *recbeg = (void *)buf; | |
7314 | const char *name = (const char *)buf + sizeof (*recbeg); | |
7315 | ||
7316 | fprintf (file, _("recbeg: name: %.*s\n"), name[0], name + 1); | |
7317 | evax_bfd_print_valspec (buf, 4, file); | |
7318 | fprintf (file, _(" len: %u bits\n"), | |
7319 | (unsigned)bfd_getl32 (name + 1 + name[0])); | |
7320 | } | |
7321 | break; | |
7322 | case DST__K_RECEND: | |
7323 | fprintf (file, _("recend\n")); | |
7324 | break; | |
7325 | case DST__K_ENUMBEG: | |
695344c0 | 7326 | /* xgettext:c-format */ |
07d6d2b8 AM |
7327 | fprintf (file, _("enumbeg, len: %u, name: %.*s\n"), |
7328 | buf[0], buf[1], buf + 2); | |
7329 | break; | |
7330 | case DST__K_ENUMELT: | |
7331 | fprintf (file, _("enumelt, name: %.*s\n"), buf[5], buf + 6); | |
7332 | evax_bfd_print_valspec (buf, 4, file); | |
7333 | break; | |
7334 | case DST__K_ENUMEND: | |
7335 | fprintf (file, _("enumend\n")); | |
7336 | break; | |
7337 | case DST__K_LABEL: | |
7338 | { | |
7339 | struct vms_dst_label *lab = (void *)buf; | |
7340 | fprintf (file, _("label, name: %.*s\n"), | |
7341 | lab->name[0], lab->name + 1); | |
7342 | fprintf (file, _(" address: 0x%08x\n"), | |
7343 | (unsigned)bfd_getl32 (lab->value)); | |
7344 | } | |
7345 | break; | |
7346 | case DST__K_DIS_RANGE: | |
7347 | { | |
7348 | unsigned int cnt = bfd_getl32 (buf); | |
7349 | unsigned char *rng = buf + 4; | |
7350 | unsigned int i; | |
7351 | ||
7352 | fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt); | |
7353 | for (i = 0; i < cnt; i++, rng += 8) | |
695344c0 | 7354 | /* xgettext:c-format */ |
07d6d2b8 AM |
7355 | fprintf (file, _(" address: 0x%08x, size: %u\n"), |
7356 | (unsigned)bfd_getl32 (rng), | |
7357 | (unsigned)bfd_getl32 (rng + 4)); | |
7358 | ||
7359 | } | |
7360 | break; | |
7361 | case DST__K_LINE_NUM: | |
7362 | { | |
7363 | unsigned char *buf_orig = buf; | |
7364 | ||
7365 | fprintf (file, _("line num (len: %u)\n"), len); | |
7366 | ||
7367 | while (len > 0) | |
7368 | { | |
7369 | signed char cmd; | |
7370 | unsigned char cmdlen; | |
7371 | unsigned int val; | |
7372 | ||
7373 | cmd = buf[0]; | |
7374 | cmdlen = 0; | |
7375 | ||
7376 | fputs (" ", file); | |
7377 | ||
7378 | switch (cmd) | |
7379 | { | |
7380 | case DST__K_DELTA_PC_W: | |
7381 | val = bfd_getl16 (buf + 1); | |
7382 | fprintf (file, _("delta_pc_w %u\n"), val); | |
7383 | pc += val; | |
7384 | line++; | |
7385 | cmdlen = 3; | |
7386 | break; | |
7387 | case DST__K_INCR_LINUM: | |
7388 | val = buf[1]; | |
7389 | fprintf (file, _("incr_linum(b): +%u\n"), val); | |
7390 | line += val; | |
7391 | cmdlen = 2; | |
7392 | break; | |
7393 | case DST__K_INCR_LINUM_W: | |
7394 | val = bfd_getl16 (buf + 1); | |
7395 | fprintf (file, _("incr_linum_w: +%u\n"), val); | |
7396 | line += val; | |
7397 | cmdlen = 3; | |
7398 | break; | |
7399 | case DST__K_INCR_LINUM_L: | |
7400 | val = bfd_getl32 (buf + 1); | |
7401 | fprintf (file, _("incr_linum_l: +%u\n"), val); | |
7402 | line += val; | |
7403 | cmdlen = 5; | |
7404 | break; | |
7405 | case DST__K_SET_LINUM: | |
7406 | line = bfd_getl16 (buf + 1); | |
7407 | fprintf (file, _("set_line_num(w) %u\n"), line); | |
7408 | cmdlen = 3; | |
7409 | break; | |
7410 | case DST__K_SET_LINUM_B: | |
7411 | line = buf[1]; | |
7412 | fprintf (file, _("set_line_num_b %u\n"), line); | |
7413 | cmdlen = 2; | |
7414 | break; | |
7415 | case DST__K_SET_LINUM_L: | |
7416 | line = bfd_getl32 (buf + 1); | |
7417 | fprintf (file, _("set_line_num_l %u\n"), line); | |
7418 | cmdlen = 5; | |
7419 | break; | |
7420 | case DST__K_SET_ABS_PC: | |
7421 | pc = bfd_getl32 (buf + 1); | |
7422 | fprintf (file, _("set_abs_pc: 0x%08x\n"), pc); | |
7423 | cmdlen = 5; | |
7424 | break; | |
7425 | case DST__K_DELTA_PC_L: | |
7426 | fprintf (file, _("delta_pc_l: +0x%08x\n"), | |
7427 | (unsigned)bfd_getl32 (buf + 1)); | |
7428 | cmdlen = 5; | |
7429 | break; | |
7430 | case DST__K_TERM: | |
7431 | fprintf (file, _("term(b): 0x%02x"), buf[1]); | |
7432 | pc += buf[1]; | |
7433 | fprintf (file, _(" pc: 0x%08x\n"), pc); | |
7434 | cmdlen = 2; | |
7435 | break; | |
7436 | case DST__K_TERM_W: | |
7437 | val = bfd_getl16 (buf + 1); | |
7438 | fprintf (file, _("term_w: 0x%04x"), val); | |
7439 | pc += val; | |
7440 | fprintf (file, _(" pc: 0x%08x\n"), pc); | |
7441 | cmdlen = 3; | |
7442 | break; | |
7443 | default: | |
7444 | if (cmd <= 0) | |
7445 | { | |
7446 | fprintf (file, _("delta pc +%-4d"), -cmd); | |
7447 | line++; /* FIXME: curr increment. */ | |
7448 | pc += -cmd; | |
695344c0 | 7449 | /* xgettext:c-format */ |
07d6d2b8 AM |
7450 | fprintf (file, _(" pc: 0x%08x line: %5u\n"), |
7451 | pc, line); | |
7452 | cmdlen = 1; | |
7453 | } | |
7454 | else | |
7455 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); | |
7456 | break; | |
7457 | } | |
7458 | if (cmdlen == 0) | |
7459 | break; | |
7460 | len -= cmdlen; | |
7461 | buf += cmdlen; | |
7462 | } | |
7463 | buf = buf_orig; | |
7464 | } | |
7465 | break; | |
7466 | case DST__K_SOURCE: | |
7467 | { | |
7468 | unsigned char *buf_orig = buf; | |
7469 | ||
7470 | fprintf (file, _("source (len: %u)\n"), len); | |
7471 | ||
7472 | while (len > 0) | |
7473 | { | |
7474 | signed char cmd = buf[0]; | |
7475 | unsigned char cmdlen = 0; | |
7476 | ||
7477 | switch (cmd) | |
7478 | { | |
7479 | case DST__K_SRC_DECLFILE: | |
7480 | { | |
7481 | struct vms_dst_src_decl_src *src = (void *)(buf + 1); | |
7482 | const char *name; | |
95e34ef7 | 7483 | |
695344c0 | 7484 | /* xgettext:c-format */ |
07d6d2b8 AM |
7485 | fprintf (file, _(" declfile: len: %u, flags: %u, " |
7486 | "fileid: %u\n"), | |
7487 | src->length, src->flags, | |
7488 | (unsigned)bfd_getl16 (src->fileid)); | |
695344c0 | 7489 | /* xgettext:c-format */ |
07d6d2b8 AM |
7490 | fprintf (file, _(" rms: cdt: 0x%08x %08x, " |
7491 | "ebk: 0x%08x, ffb: 0x%04x, " | |
7492 | "rfo: %u\n"), | |
7493 | (unsigned)bfd_getl32 (src->rms_cdt + 4), | |
7494 | (unsigned)bfd_getl32 (src->rms_cdt + 0), | |
7495 | (unsigned)bfd_getl32 (src->rms_ebk), | |
7496 | (unsigned)bfd_getl16 (src->rms_ffb), | |
7497 | src->rms_rfo); | |
7498 | name = (const char *)buf + 1 + sizeof (*src); | |
7499 | fprintf (file, _(" filename : %.*s\n"), | |
7500 | name[0], name + 1); | |
7501 | name += name[0] + 1; | |
7502 | fprintf (file, _(" module name: %.*s\n"), | |
7503 | name[0], name + 1); | |
7504 | cmdlen = 2 + src->length; | |
7505 | } | |
7506 | break; | |
7507 | case DST__K_SRC_SETFILE: | |
7508 | fprintf (file, _(" setfile %u\n"), | |
7509 | (unsigned)bfd_getl16 (buf + 1)); | |
7510 | cmdlen = 3; | |
7511 | break; | |
7512 | case DST__K_SRC_SETREC_W: | |
7513 | fprintf (file, _(" setrec %u\n"), | |
7514 | (unsigned)bfd_getl16 (buf + 1)); | |
7515 | cmdlen = 3; | |
7516 | break; | |
7517 | case DST__K_SRC_SETREC_L: | |
7518 | fprintf (file, _(" setrec %u\n"), | |
7519 | (unsigned)bfd_getl32 (buf + 1)); | |
7520 | cmdlen = 5; | |
7521 | break; | |
7522 | case DST__K_SRC_SETLNUM_W: | |
7523 | fprintf (file, _(" setlnum %u\n"), | |
7524 | (unsigned)bfd_getl16 (buf + 1)); | |
7525 | cmdlen = 3; | |
7526 | break; | |
7527 | case DST__K_SRC_SETLNUM_L: | |
7528 | fprintf (file, _(" setlnum %u\n"), | |
7529 | (unsigned)bfd_getl32 (buf + 1)); | |
7530 | cmdlen = 5; | |
7531 | break; | |
7532 | case DST__K_SRC_DEFLINES_W: | |
7533 | fprintf (file, _(" deflines %u\n"), | |
7534 | (unsigned)bfd_getl16 (buf + 1)); | |
7535 | cmdlen = 3; | |
7536 | break; | |
7537 | case DST__K_SRC_DEFLINES_B: | |
7538 | fprintf (file, _(" deflines %u\n"), buf[1]); | |
7539 | cmdlen = 2; | |
7540 | break; | |
7541 | case DST__K_SRC_FORMFEED: | |
7542 | fprintf (file, _(" formfeed\n")); | |
7543 | cmdlen = 1; | |
7544 | break; | |
7545 | default: | |
7546 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); | |
7547 | break; | |
7548 | } | |
7549 | if (cmdlen == 0) | |
7550 | break; | |
7551 | len -= cmdlen; | |
7552 | buf += cmdlen; | |
7553 | } | |
7554 | buf = buf_orig; | |
7555 | } | |
7556 | break; | |
7557 | default: | |
7558 | fprintf (file, _("*unhandled* dst type %u\n"), type); | |
7559 | break; | |
7560 | } | |
95e34ef7 TG |
7561 | free (buf); |
7562 | } | |
7563 | } | |
7564 | ||
7565 | static void | |
7566 | evax_bfd_print_image (bfd *abfd, FILE *file) | |
7567 | { | |
7568 | struct vms_eihd eihd; | |
7569 | const char *name; | |
7570 | unsigned int val; | |
7571 | unsigned int eiha_off; | |
7572 | unsigned int eihi_off; | |
7573 | unsigned int eihs_off; | |
7574 | unsigned int eisd_off; | |
7575 | unsigned int eihef_off = 0; | |
7576 | unsigned int eihnp_off = 0; | |
7577 | unsigned int dmt_vbn = 0; | |
7578 | unsigned int dmt_size = 0; | |
7579 | unsigned int dst_vbn = 0; | |
7580 | unsigned int dst_size = 0; | |
7581 | unsigned int gst_vbn = 0; | |
7582 | unsigned int gst_size = 0; | |
7583 | unsigned int eiaf_vbn = 0; | |
7584 | unsigned int eiaf_size = 0; | |
7585 | unsigned int eihvn_off; | |
7586 | ||
7587 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) | |
7588 | || bfd_bread (&eihd, sizeof (eihd), abfd) != sizeof (eihd)) | |
7589 | { | |
7590 | fprintf (file, _("cannot read EIHD\n")); | |
7591 | return; | |
7592 | } | |
695344c0 | 7593 | /* xgettext:c-format */ |
95e34ef7 | 7594 | fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"), |
07d6d2b8 AM |
7595 | (unsigned)bfd_getl32 (eihd.size), |
7596 | (unsigned)bfd_getl32 (eihd.hdrblkcnt)); | |
695344c0 | 7597 | /* xgettext:c-format */ |
95e34ef7 | 7598 | fprintf (file, _(" majorid: %u, minorid: %u\n"), |
07d6d2b8 AM |
7599 | (unsigned)bfd_getl32 (eihd.majorid), |
7600 | (unsigned)bfd_getl32 (eihd.minorid)); | |
95e34ef7 TG |
7601 | |
7602 | val = (unsigned)bfd_getl32 (eihd.imgtype); | |
7603 | switch (val) | |
7604 | { | |
7605 | case EIHD__K_EXE: | |
7606 | name = _("executable"); | |
7607 | break; | |
7608 | case EIHD__K_LIM: | |
7609 | name = _("linkable image"); | |
7610 | break; | |
7611 | default: | |
7612 | name = _("unknown"); | |
7613 | break; | |
7614 | } | |
695344c0 | 7615 | /* xgettext:c-format */ |
95e34ef7 TG |
7616 | fprintf (file, _(" image type: %u (%s)"), val, name); |
7617 | ||
7618 | val = (unsigned)bfd_getl32 (eihd.subtype); | |
7619 | switch (val) | |
7620 | { | |
7621 | case EIHD__C_NATIVE: | |
7622 | name = _("native"); | |
7623 | break; | |
7624 | case EIHD__C_CLI: | |
7625 | name = _("CLI"); | |
7626 | break; | |
7627 | default: | |
7628 | name = _("unknown"); | |
7629 | break; | |
7630 | } | |
695344c0 | 7631 | /* xgettext:c-format */ |
95e34ef7 TG |
7632 | fprintf (file, _(", subtype: %u (%s)\n"), val, name); |
7633 | ||
7634 | eisd_off = bfd_getl32 (eihd.isdoff); | |
7635 | eiha_off = bfd_getl32 (eihd.activoff); | |
7636 | eihi_off = bfd_getl32 (eihd.imgidoff); | |
7637 | eihs_off = bfd_getl32 (eihd.symdbgoff); | |
695344c0 | 7638 | /* xgettext:c-format */ |
95e34ef7 | 7639 | fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, " |
07d6d2b8 AM |
7640 | "imgid: %u, patch: %u\n"), |
7641 | eisd_off, eiha_off, eihs_off, eihi_off, | |
7642 | (unsigned)bfd_getl32 (eihd.patchoff)); | |
95e34ef7 TG |
7643 | fprintf (file, _(" fixup info rva: ")); |
7644 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva)); | |
7645 | fprintf (file, _(", symbol vector rva: ")); | |
7646 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva)); | |
7647 | eihvn_off = bfd_getl32 (eihd.version_array_off); | |
7648 | fprintf (file, _("\n" | |
07d6d2b8 AM |
7649 | " version array off: %u\n"), |
7650 | eihvn_off); | |
95e34ef7 | 7651 | fprintf (file, |
695344c0 | 7652 | /* xgettext:c-format */ |
07d6d2b8 AM |
7653 | _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"), |
7654 | (unsigned)bfd_getl32 (eihd.imgiocnt), | |
7655 | (unsigned)bfd_getl32 (eihd.iochancnt), | |
7656 | (unsigned)bfd_getl32 (eihd.privreqs + 4), | |
7657 | (unsigned)bfd_getl32 (eihd.privreqs + 0)); | |
95e34ef7 TG |
7658 | val = (unsigned)bfd_getl32 (eihd.lnkflags); |
7659 | fprintf (file, _(" linker flags: %08x:"), val); | |
7660 | if (val & EIHD__M_LNKDEBUG) | |
7661 | fprintf (file, " LNKDEBUG"); | |
7662 | if (val & EIHD__M_LNKNOTFR) | |
7663 | fprintf (file, " LNKNOTFR"); | |
7664 | if (val & EIHD__M_NOP0BUFS) | |
7665 | fprintf (file, " NOP0BUFS"); | |
7666 | if (val & EIHD__M_PICIMG) | |
7667 | fprintf (file, " PICIMG"); | |
7668 | if (val & EIHD__M_P0IMAGE) | |
7669 | fprintf (file, " P0IMAGE"); | |
7670 | if (val & EIHD__M_DBGDMT) | |
7671 | fprintf (file, " DBGDMT"); | |
7672 | if (val & EIHD__M_INISHR) | |
7673 | fprintf (file, " INISHR"); | |
7674 | if (val & EIHD__M_XLATED) | |
7675 | fprintf (file, " XLATED"); | |
7676 | if (val & EIHD__M_BIND_CODE_SEC) | |
7677 | fprintf (file, " BIND_CODE_SEC"); | |
7678 | if (val & EIHD__M_BIND_DATA_SEC) | |
7679 | fprintf (file, " BIND_DATA_SEC"); | |
7680 | if (val & EIHD__M_MKTHREADS) | |
7681 | fprintf (file, " MKTHREADS"); | |
7682 | if (val & EIHD__M_UPCALLS) | |
7683 | fprintf (file, " UPCALLS"); | |
7684 | if (val & EIHD__M_OMV_READY) | |
7685 | fprintf (file, " OMV_READY"); | |
7686 | if (val & EIHD__M_EXT_BIND_SECT) | |
7687 | fprintf (file, " EXT_BIND_SECT"); | |
7688 | fprintf (file, "\n"); | |
695344c0 | 7689 | /* xgettext:c-format */ |
95e34ef7 | 7690 | fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, " |
07d6d2b8 AM |
7691 | "match ctrl: %u, symvect_size: %u\n"), |
7692 | (unsigned)bfd_getl32 (eihd.ident), | |
7693 | (unsigned)bfd_getl32 (eihd.sysver), | |
7694 | eihd.matchctl, | |
7695 | (unsigned)bfd_getl32 (eihd.symvect_size)); | |
95e34ef7 | 7696 | fprintf (file, _(" BPAGE: %u"), |
07d6d2b8 | 7697 | (unsigned)bfd_getl32 (eihd.virt_mem_block_size)); |
95e34ef7 TG |
7698 | if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT)) |
7699 | { | |
7700 | eihef_off = bfd_getl32 (eihd.ext_fixup_off); | |
7701 | eihnp_off = bfd_getl32 (eihd.noopt_psect_off); | |
695344c0 | 7702 | /* xgettext:c-format */ |
95e34ef7 | 7703 | fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"), |
07d6d2b8 | 7704 | eihef_off, eihnp_off); |
95e34ef7 TG |
7705 | } |
7706 | fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias)); | |
7707 | ||
7708 | if (eihvn_off != 0) | |
7709 | { | |
7710 | struct vms_eihvn eihvn; | |
7711 | unsigned int mask; | |
7712 | unsigned int j; | |
7713 | ||
7714 | fprintf (file, _("system version array information:\n")); | |
7715 | if (bfd_seek (abfd, (file_ptr) eihvn_off, SEEK_SET) | |
07d6d2b8 AM |
7716 | || bfd_bread (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn)) |
7717 | { | |
7718 | fprintf (file, _("cannot read EIHVN header\n")); | |
7719 | return; | |
7720 | } | |
95e34ef7 TG |
7721 | mask = bfd_getl32 (eihvn.subsystem_mask); |
7722 | for (j = 0; j < 32; j++) | |
07d6d2b8 AM |
7723 | if (mask & (1 << j)) |
7724 | { | |
7725 | struct vms_eihvn_subversion ver; | |
7726 | if (bfd_bread (&ver, sizeof (ver), abfd) != sizeof (ver)) | |
7727 | { | |
7728 | fprintf (file, _("cannot read EIHVN version\n")); | |
7729 | return; | |
7730 | } | |
7731 | fprintf (file, _(" %02u "), j); | |
7732 | switch (j) | |
7733 | { | |
7734 | case EIHVN__BASE_IMAGE_BIT: | |
95e34ef7 | 7735 | fputs (_("BASE_IMAGE "), file); |
07d6d2b8 AM |
7736 | break; |
7737 | case EIHVN__MEMORY_MANAGEMENT_BIT: | |
7738 | fputs (_("MEMORY_MANAGEMENT"), file); | |
7739 | break; | |
7740 | case EIHVN__IO_BIT: | |
7741 | fputs (_("IO "), file); | |
7742 | break; | |
7743 | case EIHVN__FILES_VOLUMES_BIT: | |
7744 | fputs (_("FILES_VOLUMES "), file); | |
7745 | break; | |
7746 | case EIHVN__PROCESS_SCHED_BIT: | |
7747 | fputs (_("PROCESS_SCHED "), file); | |
7748 | break; | |
7749 | case EIHVN__SYSGEN_BIT: | |
95e34ef7 | 7750 | fputs (_("SYSGEN "), file); |
07d6d2b8 AM |
7751 | break; |
7752 | case EIHVN__CLUSTERS_LOCKMGR_BIT: | |
7753 | fputs (_("CLUSTERS_LOCKMGR "), file); | |
7754 | break; | |
7755 | case EIHVN__LOGICAL_NAMES_BIT: | |
7756 | fputs (_("LOGICAL_NAMES "), file); | |
7757 | break; | |
7758 | case EIHVN__SECURITY_BIT: | |
95e34ef7 | 7759 | fputs (_("SECURITY "), file); |
07d6d2b8 AM |
7760 | break; |
7761 | case EIHVN__IMAGE_ACTIVATOR_BIT: | |
7762 | fputs (_("IMAGE_ACTIVATOR "), file); | |
7763 | break; | |
7764 | case EIHVN__NETWORKS_BIT: | |
95e34ef7 | 7765 | fputs (_("NETWORKS "), file); |
07d6d2b8 AM |
7766 | break; |
7767 | case EIHVN__COUNTERS_BIT: | |
95e34ef7 | 7768 | fputs (_("COUNTERS "), file); |
07d6d2b8 AM |
7769 | break; |
7770 | case EIHVN__STABLE_BIT: | |
95e34ef7 | 7771 | fputs (_("STABLE "), file); |
07d6d2b8 AM |
7772 | break; |
7773 | case EIHVN__MISC_BIT: | |
7774 | fputs (_("MISC "), file); | |
7775 | break; | |
7776 | case EIHVN__CPU_BIT: | |
7777 | fputs (_("CPU "), file); | |
7778 | break; | |
7779 | case EIHVN__VOLATILE_BIT: | |
95e34ef7 | 7780 | fputs (_("VOLATILE "), file); |
07d6d2b8 AM |
7781 | break; |
7782 | case EIHVN__SHELL_BIT: | |
95e34ef7 | 7783 | fputs (_("SHELL "), file); |
07d6d2b8 AM |
7784 | break; |
7785 | case EIHVN__POSIX_BIT: | |
95e34ef7 | 7786 | fputs (_("POSIX "), file); |
07d6d2b8 AM |
7787 | break; |
7788 | case EIHVN__MULTI_PROCESSING_BIT: | |
7789 | fputs (_("MULTI_PROCESSING "), file); | |
7790 | break; | |
7791 | case EIHVN__GALAXY_BIT: | |
95e34ef7 | 7792 | fputs (_("GALAXY "), file); |
07d6d2b8 AM |
7793 | break; |
7794 | default: | |
7795 | fputs (_("*unknown* "), file); | |
7796 | break; | |
7797 | } | |
7798 | fprintf (file, ": %u.%u\n", | |
7799 | (unsigned)bfd_getl16 (ver.major), | |
7800 | (unsigned)bfd_getl16 (ver.minor)); | |
7801 | } | |
95e34ef7 TG |
7802 | } |
7803 | ||
7804 | if (eiha_off != 0) | |
7805 | { | |
7806 | struct vms_eiha eiha; | |
7807 | ||
7808 | if (bfd_seek (abfd, (file_ptr) eiha_off, SEEK_SET) | |
07d6d2b8 AM |
7809 | || bfd_bread (&eiha, sizeof (eiha), abfd) != sizeof (eiha)) |
7810 | { | |
7811 | fprintf (file, _("cannot read EIHA\n")); | |
7812 | return; | |
7813 | } | |
95e34ef7 | 7814 | fprintf (file, _("Image activation: (size=%u)\n"), |
07d6d2b8 | 7815 | (unsigned)bfd_getl32 (eiha.size)); |
695344c0 | 7816 | /* xgettext:c-format */ |
95e34ef7 | 7817 | fprintf (file, _(" First address : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
7818 | (unsigned)bfd_getl32 (eiha.tfradr1_h), |
7819 | (unsigned)bfd_getl32 (eiha.tfradr1)); | |
695344c0 | 7820 | /* xgettext:c-format */ |
95e34ef7 | 7821 | fprintf (file, _(" Second address: 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
7822 | (unsigned)bfd_getl32 (eiha.tfradr2_h), |
7823 | (unsigned)bfd_getl32 (eiha.tfradr2)); | |
695344c0 | 7824 | /* xgettext:c-format */ |
95e34ef7 | 7825 | fprintf (file, _(" Third address : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
7826 | (unsigned)bfd_getl32 (eiha.tfradr3_h), |
7827 | (unsigned)bfd_getl32 (eiha.tfradr3)); | |
695344c0 | 7828 | /* xgettext:c-format */ |
95e34ef7 | 7829 | fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
7830 | (unsigned)bfd_getl32 (eiha.tfradr4_h), |
7831 | (unsigned)bfd_getl32 (eiha.tfradr4)); | |
695344c0 | 7832 | /* xgettext:c-format */ |
95e34ef7 | 7833 | fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
7834 | (unsigned)bfd_getl32 (eiha.inishr_h), |
7835 | (unsigned)bfd_getl32 (eiha.inishr)); | |
95e34ef7 TG |
7836 | } |
7837 | if (eihi_off != 0) | |
7838 | { | |
7839 | struct vms_eihi eihi; | |
7840 | ||
7841 | if (bfd_seek (abfd, (file_ptr) eihi_off, SEEK_SET) | |
07d6d2b8 AM |
7842 | || bfd_bread (&eihi, sizeof (eihi), abfd) != sizeof (eihi)) |
7843 | { | |
7844 | fprintf (file, _("cannot read EIHI\n")); | |
7845 | return; | |
7846 | } | |
695344c0 | 7847 | /* xgettext:c-format */ |
95e34ef7 | 7848 | fprintf (file, _("Image identification: (major: %u, minor: %u)\n"), |
07d6d2b8 AM |
7849 | (unsigned)bfd_getl32 (eihi.majorid), |
7850 | (unsigned)bfd_getl32 (eihi.minorid)); | |
95e34ef7 | 7851 | fprintf (file, _(" image name : %.*s\n"), |
07d6d2b8 | 7852 | eihi.imgnam[0], eihi.imgnam + 1); |
95e34ef7 | 7853 | fprintf (file, _(" link time : %s\n"), |
07d6d2b8 | 7854 | vms_time_to_str (eihi.linktime)); |
95e34ef7 | 7855 | fprintf (file, _(" image ident : %.*s\n"), |
07d6d2b8 | 7856 | eihi.imgid[0], eihi.imgid + 1); |
95e34ef7 | 7857 | fprintf (file, _(" linker ident : %.*s\n"), |
07d6d2b8 | 7858 | eihi.linkid[0], eihi.linkid + 1); |
95e34ef7 | 7859 | fprintf (file, _(" image build ident: %.*s\n"), |
07d6d2b8 | 7860 | eihi.imgbid[0], eihi.imgbid + 1); |
95e34ef7 TG |
7861 | } |
7862 | if (eihs_off != 0) | |
7863 | { | |
7864 | struct vms_eihs eihs; | |
7865 | ||
7866 | if (bfd_seek (abfd, (file_ptr) eihs_off, SEEK_SET) | |
07d6d2b8 AM |
7867 | || bfd_bread (&eihs, sizeof (eihs), abfd) != sizeof (eihs)) |
7868 | { | |
7869 | fprintf (file, _("cannot read EIHS\n")); | |
7870 | return; | |
7871 | } | |
695344c0 | 7872 | /* xgettext:c-format */ |
95e34ef7 | 7873 | fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"), |
07d6d2b8 AM |
7874 | (unsigned)bfd_getl32 (eihs.majorid), |
7875 | (unsigned)bfd_getl32 (eihs.minorid)); | |
95e34ef7 TG |
7876 | dst_vbn = bfd_getl32 (eihs.dstvbn); |
7877 | dst_size = bfd_getl32 (eihs.dstsize); | |
695344c0 | 7878 | /* xgettext:c-format */ |
44273c5b | 7879 | fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"), |
07d6d2b8 | 7880 | dst_vbn, dst_size, dst_size); |
95e34ef7 TG |
7881 | gst_vbn = bfd_getl32 (eihs.gstvbn); |
7882 | gst_size = bfd_getl32 (eihs.gstsize); | |
695344c0 | 7883 | /* xgettext:c-format */ |
95e34ef7 | 7884 | fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"), |
07d6d2b8 | 7885 | gst_vbn, gst_size); |
95e34ef7 TG |
7886 | dmt_vbn = bfd_getl32 (eihs.dmtvbn); |
7887 | dmt_size = bfd_getl32 (eihs.dmtsize); | |
695344c0 | 7888 | /* xgettext:c-format */ |
95e34ef7 | 7889 | fprintf (file, _(" debug module table : vbn: %u, size: %u\n"), |
07d6d2b8 | 7890 | dmt_vbn, dmt_size); |
95e34ef7 TG |
7891 | } |
7892 | while (eisd_off != 0) | |
7893 | { | |
7894 | struct vms_eisd eisd; | |
7895 | unsigned int len; | |
7896 | ||
7897 | while (1) | |
07d6d2b8 AM |
7898 | { |
7899 | if (bfd_seek (abfd, (file_ptr) eisd_off, SEEK_SET) | |
7900 | || bfd_bread (&eisd, sizeof (eisd), abfd) != sizeof (eisd)) | |
7901 | { | |
7902 | fprintf (file, _("cannot read EISD\n")); | |
7903 | return; | |
7904 | } | |
7905 | len = (unsigned)bfd_getl32 (eisd.eisdsize); | |
7906 | if (len != (unsigned)-1) | |
7907 | break; | |
7908 | ||
7909 | /* Next block. */ | |
7910 | eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); | |
7911 | } | |
695344c0 | 7912 | /* xgettext:c-format */ |
95e34ef7 | 7913 | fprintf (file, _("Image section descriptor: (major: %u, minor: %u, " |
07d6d2b8 AM |
7914 | "size: %u, offset: %u)\n"), |
7915 | (unsigned)bfd_getl32 (eisd.majorid), | |
7916 | (unsigned)bfd_getl32 (eisd.minorid), | |
7917 | len, eisd_off); | |
95e34ef7 | 7918 | if (len == 0) |
07d6d2b8 | 7919 | break; |
695344c0 | 7920 | /* xgettext:c-format */ |
95e34ef7 | 7921 | fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"), |
07d6d2b8 AM |
7922 | (unsigned)bfd_getl32 (eisd.virt_addr + 4), |
7923 | (unsigned)bfd_getl32 (eisd.virt_addr + 0), | |
7924 | (unsigned)bfd_getl32 (eisd.secsize)); | |
95e34ef7 TG |
7925 | val = (unsigned)bfd_getl32 (eisd.flags); |
7926 | fprintf (file, _(" flags: 0x%04x"), val); | |
7927 | if (val & EISD__M_GBL) | |
07d6d2b8 | 7928 | fprintf (file, " GBL"); |
95e34ef7 | 7929 | if (val & EISD__M_CRF) |
07d6d2b8 | 7930 | fprintf (file, " CRF"); |
95e34ef7 | 7931 | if (val & EISD__M_DZRO) |
07d6d2b8 | 7932 | fprintf (file, " DZRO"); |
95e34ef7 | 7933 | if (val & EISD__M_WRT) |
07d6d2b8 | 7934 | fprintf (file, " WRT"); |
95e34ef7 TG |
7935 | if (val & EISD__M_INITALCODE) |
7936 | fprintf (file, " INITALCODE"); | |
7937 | if (val & EISD__M_BASED) | |
07d6d2b8 | 7938 | fprintf (file, " BASED"); |
95e34ef7 TG |
7939 | if (val & EISD__M_FIXUPVEC) |
7940 | fprintf (file, " FIXUPVEC"); | |
7941 | if (val & EISD__M_RESIDENT) | |
7942 | fprintf (file, " RESIDENT"); | |
7943 | if (val & EISD__M_VECTOR) | |
07d6d2b8 | 7944 | fprintf (file, " VECTOR"); |
95e34ef7 TG |
7945 | if (val & EISD__M_PROTECT) |
7946 | fprintf (file, " PROTECT"); | |
7947 | if (val & EISD__M_LASTCLU) | |
7948 | fprintf (file, " LASTCLU"); | |
7949 | if (val & EISD__M_EXE) | |
07d6d2b8 | 7950 | fprintf (file, " EXE"); |
95e34ef7 TG |
7951 | if (val & EISD__M_NONSHRADR) |
7952 | fprintf (file, " NONSHRADR"); | |
7953 | if (val & EISD__M_QUAD_LENGTH) | |
7954 | fprintf (file, " QUAD_LENGTH"); | |
7955 | if (val & EISD__M_ALLOC_64BIT) | |
7956 | fprintf (file, " ALLOC_64BIT"); | |
7957 | fprintf (file, "\n"); | |
7958 | if (val & EISD__M_FIXUPVEC) | |
07d6d2b8 AM |
7959 | { |
7960 | eiaf_vbn = bfd_getl32 (eisd.vbn); | |
7961 | eiaf_size = bfd_getl32 (eisd.secsize); | |
7962 | } | |
695344c0 | 7963 | /* xgettext:c-format */ |
95e34ef7 | 7964 | fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("), |
07d6d2b8 AM |
7965 | (unsigned)bfd_getl32 (eisd.vbn), |
7966 | eisd.pfc, eisd.matchctl, eisd.type); | |
95e34ef7 | 7967 | switch (eisd.type) |
07d6d2b8 AM |
7968 | { |
7969 | case EISD__K_NORMAL: | |
7970 | fputs (_("NORMAL"), file); | |
7971 | break; | |
7972 | case EISD__K_SHRFXD: | |
7973 | fputs (_("SHRFXD"), file); | |
7974 | break; | |
7975 | case EISD__K_PRVFXD: | |
7976 | fputs (_("PRVFXD"), file); | |
7977 | break; | |
7978 | case EISD__K_SHRPIC: | |
7979 | fputs (_("SHRPIC"), file); | |
7980 | break; | |
7981 | case EISD__K_PRVPIC: | |
7982 | fputs (_("PRVPIC"), file); | |
7983 | break; | |
7984 | case EISD__K_USRSTACK: | |
7985 | fputs (_("USRSTACK"), file); | |
7986 | break; | |
7987 | default: | |
7988 | fputs (_("*unknown*"), file); | |
7989 | break; | |
7990 | } | |
95e34ef7 TG |
7991 | fputs (_(")\n"), file); |
7992 | if (val & EISD__M_GBL) | |
695344c0 | 7993 | /* xgettext:c-format */ |
07d6d2b8 AM |
7994 | fprintf (file, _(" ident: 0x%08x, name: %.*s\n"), |
7995 | (unsigned)bfd_getl32 (eisd.ident), | |
7996 | eisd.gblnam[0], eisd.gblnam + 1); | |
95e34ef7 TG |
7997 | eisd_off += len; |
7998 | } | |
7999 | ||
8000 | if (dmt_vbn != 0) | |
8001 | { | |
8002 | if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8003 | { |
8004 | fprintf (file, _("cannot read DMT\n")); | |
8005 | return; | |
8006 | } | |
95e34ef7 TG |
8007 | |
8008 | fprintf (file, _("Debug module table:\n")); | |
8009 | ||
8010 | while (dmt_size > 0) | |
07d6d2b8 AM |
8011 | { |
8012 | struct vms_dmt_header dmth; | |
8013 | unsigned int count; | |
8014 | ||
8015 | if (bfd_bread (&dmth, sizeof (dmth), abfd) != sizeof (dmth)) | |
8016 | { | |
8017 | fprintf (file, _("cannot read DMT header\n")); | |
8018 | return; | |
8019 | } | |
8020 | count = bfd_getl16 (dmth.psect_count); | |
8021 | fprintf (file, | |
695344c0 | 8022 | /* xgettext:c-format */ |
07d6d2b8 AM |
8023 | _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"), |
8024 | (unsigned)bfd_getl32 (dmth.modbeg), | |
8025 | (unsigned)bfd_getl32 (dmth.size), count); | |
8026 | dmt_size -= sizeof (dmth); | |
8027 | while (count > 0) | |
8028 | { | |
8029 | struct vms_dmt_psect dmtp; | |
8030 | ||
8031 | if (bfd_bread (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp)) | |
8032 | { | |
8033 | fprintf (file, _("cannot read DMT psect\n")); | |
8034 | return; | |
8035 | } | |
695344c0 | 8036 | /* xgettext:c-format */ |
07d6d2b8 AM |
8037 | fprintf (file, _(" psect start: 0x%08x, length: %u\n"), |
8038 | (unsigned)bfd_getl32 (dmtp.start), | |
8039 | (unsigned)bfd_getl32 (dmtp.length)); | |
8040 | count--; | |
8041 | dmt_size -= sizeof (dmtp); | |
8042 | } | |
8043 | } | |
95e34ef7 TG |
8044 | } |
8045 | ||
8046 | if (dst_vbn != 0) | |
8047 | { | |
8048 | if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8049 | { |
8050 | fprintf (file, _("cannot read DST\n")); | |
8051 | return; | |
8052 | } | |
95e34ef7 TG |
8053 | |
8054 | evax_bfd_print_dst (abfd, dst_size, file); | |
8055 | } | |
8056 | if (gst_vbn != 0) | |
8057 | { | |
8058 | if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8059 | { |
8060 | fprintf (file, _("cannot read GST\n")); | |
8061 | return; | |
8062 | } | |
95e34ef7 TG |
8063 | |
8064 | fprintf (file, _("Global symbol table:\n")); | |
8065 | evax_bfd_print_eobj (abfd, file); | |
8066 | } | |
8067 | if (eiaf_vbn != 0) | |
8068 | { | |
8069 | unsigned char *buf; | |
8070 | struct vms_eiaf *eiaf; | |
8071 | unsigned int qrelfixoff; | |
8072 | unsigned int lrelfixoff; | |
8073 | unsigned int qdotadroff; | |
8074 | unsigned int ldotadroff; | |
8075 | unsigned int shrimgcnt; | |
8076 | unsigned int shlstoff; | |
8077 | unsigned int codeadroff; | |
8078 | unsigned int lpfixoff; | |
8079 | unsigned int chgprtoff; | |
2bb3687b | 8080 | file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE; |
95e34ef7 | 8081 | |
2bb3687b AM |
8082 | if (bfd_seek (abfd, f_off, SEEK_SET) != 0 |
8083 | || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL) | |
07d6d2b8 AM |
8084 | { |
8085 | fprintf (file, _("cannot read EIHA\n")); | |
07d6d2b8 AM |
8086 | return; |
8087 | } | |
95e34ef7 TG |
8088 | eiaf = (struct vms_eiaf *)buf; |
8089 | fprintf (file, | |
695344c0 | 8090 | /* xgettext:c-format */ |
07d6d2b8 AM |
8091 | _("Image activator fixup: (major: %u, minor: %u)\n"), |
8092 | (unsigned)bfd_getl32 (eiaf->majorid), | |
8093 | (unsigned)bfd_getl32 (eiaf->minorid)); | |
695344c0 | 8094 | /* xgettext:c-format */ |
95e34ef7 | 8095 | fprintf (file, _(" iaflink : 0x%08x %08x\n"), |
07d6d2b8 AM |
8096 | (unsigned)bfd_getl32 (eiaf->iaflink + 0), |
8097 | (unsigned)bfd_getl32 (eiaf->iaflink + 4)); | |
695344c0 | 8098 | /* xgettext:c-format */ |
95e34ef7 | 8099 | fprintf (file, _(" fixuplnk: 0x%08x %08x\n"), |
07d6d2b8 AM |
8100 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 0), |
8101 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 4)); | |
95e34ef7 | 8102 | fprintf (file, _(" size : %u\n"), |
07d6d2b8 | 8103 | (unsigned)bfd_getl32 (eiaf->size)); |
95e34ef7 | 8104 | fprintf (file, _(" flags: 0x%08x\n"), |
07d6d2b8 | 8105 | (unsigned)bfd_getl32 (eiaf->flags)); |
95e34ef7 TG |
8106 | qrelfixoff = bfd_getl32 (eiaf->qrelfixoff); |
8107 | lrelfixoff = bfd_getl32 (eiaf->lrelfixoff); | |
695344c0 | 8108 | /* xgettext:c-format */ |
95e34ef7 | 8109 | fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"), |
07d6d2b8 | 8110 | qrelfixoff, lrelfixoff); |
95e34ef7 TG |
8111 | qdotadroff = bfd_getl32 (eiaf->qdotadroff); |
8112 | ldotadroff = bfd_getl32 (eiaf->ldotadroff); | |
695344c0 | 8113 | /* xgettext:c-format */ |
95e34ef7 | 8114 | fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"), |
07d6d2b8 | 8115 | qdotadroff, ldotadroff); |
95e34ef7 TG |
8116 | codeadroff = bfd_getl32 (eiaf->codeadroff); |
8117 | lpfixoff = bfd_getl32 (eiaf->lpfixoff); | |
695344c0 | 8118 | /* xgettext:c-format */ |
95e34ef7 | 8119 | fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"), |
07d6d2b8 | 8120 | codeadroff, lpfixoff); |
95e34ef7 TG |
8121 | chgprtoff = bfd_getl32 (eiaf->chgprtoff); |
8122 | fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff); | |
8123 | shrimgcnt = bfd_getl32 (eiaf->shrimgcnt); | |
8124 | shlstoff = bfd_getl32 (eiaf->shlstoff); | |
695344c0 | 8125 | /* xgettext:c-format */ |
95e34ef7 | 8126 | fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"), |
07d6d2b8 | 8127 | shlstoff, shrimgcnt); |
695344c0 | 8128 | /* xgettext:c-format */ |
95e34ef7 | 8129 | fprintf (file, _(" shlextra : %5u, permctx : %5u\n"), |
07d6d2b8 AM |
8130 | (unsigned)bfd_getl32 (eiaf->shlextra), |
8131 | (unsigned)bfd_getl32 (eiaf->permctx)); | |
95e34ef7 | 8132 | fprintf (file, _(" base_va : 0x%08x\n"), |
07d6d2b8 | 8133 | (unsigned)bfd_getl32 (eiaf->base_va)); |
95e34ef7 | 8134 | fprintf (file, _(" lppsbfixoff: %5u\n"), |
07d6d2b8 | 8135 | (unsigned)bfd_getl32 (eiaf->lppsbfixoff)); |
95e34ef7 TG |
8136 | |
8137 | if (shlstoff) | |
07d6d2b8 AM |
8138 | { |
8139 | struct vms_shl *shl = (struct vms_shl *)(buf + shlstoff); | |
8140 | unsigned int j; | |
8141 | ||
8142 | fprintf (file, _(" Shareable images:\n")); | |
8143 | for (j = 0; j < shrimgcnt; j++, shl++) | |
8144 | { | |
8145 | fprintf (file, | |
695344c0 | 8146 | /* xgettext:c-format */ |
07d6d2b8 AM |
8147 | _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"), |
8148 | j, shl->size, shl->flags, | |
8149 | shl->imgnam[0], shl->imgnam + 1); | |
8150 | } | |
8151 | } | |
95e34ef7 | 8152 | if (qrelfixoff != 0) |
07d6d2b8 AM |
8153 | { |
8154 | fprintf (file, _(" quad-word relocation fixups:\n")); | |
8155 | evax_bfd_print_relocation_records (file, buf + qrelfixoff, 8); | |
8156 | } | |
95e34ef7 | 8157 | if (lrelfixoff != 0) |
07d6d2b8 AM |
8158 | { |
8159 | fprintf (file, _(" long-word relocation fixups:\n")); | |
8160 | evax_bfd_print_relocation_records (file, buf + lrelfixoff, 4); | |
8161 | } | |
95e34ef7 | 8162 | if (qdotadroff != 0) |
07d6d2b8 AM |
8163 | { |
8164 | fprintf (file, _(" quad-word .address reference fixups:\n")); | |
8165 | evax_bfd_print_address_fixups (file, buf + qdotadroff); | |
8166 | } | |
95e34ef7 | 8167 | if (ldotadroff != 0) |
07d6d2b8 AM |
8168 | { |
8169 | fprintf (file, _(" long-word .address reference fixups:\n")); | |
8170 | evax_bfd_print_address_fixups (file, buf + ldotadroff); | |
8171 | } | |
95e34ef7 | 8172 | if (codeadroff != 0) |
07d6d2b8 AM |
8173 | { |
8174 | fprintf (file, _(" Code Address Reference Fixups:\n")); | |
8175 | evax_bfd_print_reference_fixups (file, buf + codeadroff); | |
8176 | } | |
95e34ef7 | 8177 | if (lpfixoff != 0) |
07d6d2b8 AM |
8178 | { |
8179 | fprintf (file, _(" Linkage Pairs Reference Fixups:\n")); | |
8180 | evax_bfd_print_reference_fixups (file, buf + lpfixoff); | |
8181 | } | |
95e34ef7 | 8182 | if (chgprtoff) |
07d6d2b8 AM |
8183 | { |
8184 | unsigned int count = (unsigned)bfd_getl32 (buf + chgprtoff); | |
8185 | struct vms_eicp *eicp = (struct vms_eicp *)(buf + chgprtoff + 4); | |
8186 | unsigned int j; | |
8187 | ||
8188 | fprintf (file, _(" Change Protection (%u entries):\n"), count); | |
8189 | for (j = 0; j < count; j++, eicp++) | |
8190 | { | |
8191 | unsigned int prot = bfd_getl32 (eicp->newprt); | |
8192 | fprintf (file, | |
695344c0 | 8193 | /* xgettext:c-format */ |
07d6d2b8 AM |
8194 | _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "), |
8195 | (unsigned)bfd_getl32 (eicp->baseva + 4), | |
8196 | (unsigned)bfd_getl32 (eicp->baseva + 0), | |
8197 | (unsigned)bfd_getl32 (eicp->size), | |
8198 | (unsigned)bfd_getl32 (eicp->newprt)); | |
8199 | switch (prot) | |
8200 | { | |
8201 | case PRT__C_NA: | |
8202 | fprintf (file, "NA"); | |
8203 | break; | |
8204 | case PRT__C_RESERVED: | |
8205 | fprintf (file, "RES"); | |
8206 | break; | |
8207 | case PRT__C_KW: | |
8208 | fprintf (file, "KW"); | |
8209 | break; | |
8210 | case PRT__C_KR: | |
8211 | fprintf (file, "KR"); | |
8212 | break; | |
8213 | case PRT__C_UW: | |
8214 | fprintf (file, "UW"); | |
8215 | break; | |
8216 | case PRT__C_EW: | |
8217 | fprintf (file, "EW"); | |
8218 | break; | |
8219 | case PRT__C_ERKW: | |
8220 | fprintf (file, "ERKW"); | |
8221 | break; | |
8222 | case PRT__C_ER: | |
8223 | fprintf (file, "ER"); | |
8224 | break; | |
8225 | case PRT__C_SW: | |
8226 | fprintf (file, "SW"); | |
8227 | break; | |
8228 | case PRT__C_SREW: | |
8229 | fprintf (file, "SREW"); | |
8230 | break; | |
8231 | case PRT__C_SRKW: | |
8232 | fprintf (file, "SRKW"); | |
8233 | break; | |
8234 | case PRT__C_SR: | |
8235 | fprintf (file, "SR"); | |
8236 | break; | |
8237 | case PRT__C_URSW: | |
8238 | fprintf (file, "URSW"); | |
8239 | break; | |
8240 | case PRT__C_UREW: | |
8241 | fprintf (file, "UREW"); | |
8242 | break; | |
8243 | case PRT__C_URKW: | |
8244 | fprintf (file, "URKW"); | |
8245 | break; | |
8246 | case PRT__C_UR: | |
8247 | fprintf (file, "UR"); | |
8248 | break; | |
8249 | default: | |
8250 | fputs ("??", file); | |
8251 | break; | |
8252 | } | |
8253 | fputc ('\n', file); | |
8254 | } | |
8255 | } | |
95e34ef7 TG |
8256 | free (buf); |
8257 | } | |
8258 | } | |
8259 | ||
8260 | static bfd_boolean | |
8261 | vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr) | |
8262 | { | |
8263 | FILE *file = (FILE *)ptr; | |
8264 | ||
8265 | if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) | |
8266 | evax_bfd_print_image (abfd, file); | |
8267 | else | |
8268 | { | |
8269 | if (bfd_seek (abfd, 0, SEEK_SET)) | |
07d6d2b8 | 8270 | return FALSE; |
95e34ef7 TG |
8271 | evax_bfd_print_eobj (abfd, file); |
8272 | } | |
8273 | return TRUE; | |
8274 | } | |
8275 | \f | |
8276 | /* Linking. */ | |
8277 | ||
44273c5b | 8278 | /* Slurp ETIR/EDBG/ETBT VMS object records. */ |
95e34ef7 TG |
8279 | |
8280 | static bfd_boolean | |
8281 | alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info) | |
8282 | { | |
8283 | asection *cur_section; | |
8284 | file_ptr cur_offset; | |
8285 | asection *dst_section; | |
8286 | file_ptr dst_offset; | |
8287 | ||
8288 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) | |
8289 | return FALSE; | |
8290 | ||
95e34ef7 TG |
8291 | cur_section = NULL; |
8292 | cur_offset = 0; | |
8293 | ||
8294 | dst_section = PRIV (dst_section); | |
8295 | dst_offset = 0; | |
8296 | if (info) | |
8297 | { | |
8298 | if (info->strip == strip_all || info->strip == strip_debugger) | |
07d6d2b8 AM |
8299 | { |
8300 | /* Discard the DST section. */ | |
8301 | dst_offset = 0; | |
8302 | dst_section = NULL; | |
8303 | } | |
95e34ef7 | 8304 | else if (dst_section) |
07d6d2b8 AM |
8305 | { |
8306 | dst_offset = dst_section->output_offset; | |
8307 | dst_section = dst_section->output_section; | |
8308 | } | |
95e34ef7 TG |
8309 | } |
8310 | ||
8311 | while (1) | |
8312 | { | |
8313 | int type; | |
8314 | bfd_boolean res; | |
8315 | ||
8316 | type = _bfd_vms_get_object_record (abfd); | |
8317 | if (type < 0) | |
8318 | { | |
8319 | vms_debug2 ((2, "next_record failed\n")); | |
8320 | return FALSE; | |
8321 | } | |
8322 | switch (type) | |
07d6d2b8 AM |
8323 | { |
8324 | case EOBJ__C_ETIR: | |
8325 | PRIV (image_section) = cur_section; | |
8326 | PRIV (image_offset) = cur_offset; | |
8327 | res = _bfd_vms_slurp_etir (abfd, info); | |
8328 | cur_section = PRIV (image_section); | |
8329 | cur_offset = PRIV (image_offset); | |
8330 | break; | |
8331 | case EOBJ__C_EDBG: | |
8332 | case EOBJ__C_ETBT: | |
8333 | if (dst_section == NULL) | |
8334 | continue; | |
8335 | PRIV (image_section) = dst_section; | |
8336 | PRIV (image_offset) = dst_offset; | |
8337 | res = _bfd_vms_slurp_etir (abfd, info); | |
8338 | dst_offset = PRIV (image_offset); | |
8339 | break; | |
8340 | case EOBJ__C_EEOM: | |
8341 | return TRUE; | |
8342 | default: | |
8343 | continue; | |
8344 | } | |
95e34ef7 | 8345 | if (!res) |
07d6d2b8 AM |
8346 | { |
8347 | vms_debug2 ((2, "slurp eobj type %d failed\n", type)); | |
8348 | return FALSE; | |
8349 | } | |
95e34ef7 TG |
8350 | } |
8351 | } | |
8352 | ||
8353 | static int | |
8354 | alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED, | |
07d6d2b8 | 8355 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
95e34ef7 TG |
8356 | { |
8357 | return 0; | |
8358 | } | |
8359 | ||
8360 | /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */ | |
8361 | ||
96d3b80f | 8362 | static bfd_boolean |
95e34ef7 TG |
8363 | alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8364 | { | |
8365 | struct alpha_vms_shlib_el *sl; | |
8366 | asection *sect = PRIV2 (src, image_section); | |
8367 | file_ptr offset = PRIV2 (src, image_offset); | |
96d3b80f | 8368 | bfd_vma *p; |
95e34ef7 TG |
8369 | |
8370 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8371 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
95e34ef7 | 8372 | sl->has_fixups = TRUE; |
96d3b80f AM |
8373 | p = VEC_APPEND (sl->lp, bfd_vma); |
8374 | if (p == NULL) | |
8375 | return FALSE; | |
8376 | *p = sect->output_section->vma + sect->output_offset + offset; | |
5f101a3d | 8377 | sect->output_section->flags |= SEC_RELOC; |
96d3b80f | 8378 | return TRUE; |
95e34ef7 TG |
8379 | } |
8380 | ||
5f101a3d TG |
8381 | /* Add a code address fixup at address SECT + OFFSET to SHLIB. */ |
8382 | ||
96d3b80f | 8383 | static bfd_boolean |
95e34ef7 TG |
8384 | alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8385 | { | |
8386 | struct alpha_vms_shlib_el *sl; | |
8387 | asection *sect = PRIV2 (src, image_section); | |
8388 | file_ptr offset = PRIV2 (src, image_offset); | |
96d3b80f | 8389 | bfd_vma *p; |
95e34ef7 TG |
8390 | |
8391 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8392 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
95e34ef7 | 8393 | sl->has_fixups = TRUE; |
96d3b80f AM |
8394 | p = VEC_APPEND (sl->ca, bfd_vma); |
8395 | if (p == NULL) | |
8396 | return FALSE; | |
8397 | *p = sect->output_section->vma + sect->output_offset + offset; | |
5f101a3d | 8398 | sect->output_section->flags |= SEC_RELOC; |
96d3b80f | 8399 | return TRUE; |
95e34ef7 TG |
8400 | } |
8401 | ||
5f101a3d TG |
8402 | /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */ |
8403 | ||
96d3b80f | 8404 | static bfd_boolean |
95e34ef7 | 8405 | alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src, |
07d6d2b8 | 8406 | bfd *shlib, bfd_vma vec) |
95e34ef7 TG |
8407 | { |
8408 | struct alpha_vms_shlib_el *sl; | |
8409 | struct alpha_vms_vma_ref *r; | |
8410 | asection *sect = PRIV2 (src, image_section); | |
8411 | file_ptr offset = PRIV2 (src, image_offset); | |
8412 | ||
8413 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8414 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
95e34ef7 TG |
8415 | sl->has_fixups = TRUE; |
8416 | r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref); | |
96d3b80f AM |
8417 | if (r == NULL) |
8418 | return FALSE; | |
95e34ef7 TG |
8419 | r->vma = sect->output_section->vma + sect->output_offset + offset; |
8420 | r->ref = vec; | |
5f101a3d | 8421 | sect->output_section->flags |= SEC_RELOC; |
96d3b80f | 8422 | return TRUE; |
95e34ef7 TG |
8423 | } |
8424 | ||
96d3b80f | 8425 | static bfd_boolean |
5369db0a | 8426 | alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED, |
07d6d2b8 AM |
8427 | unsigned int shr ATTRIBUTE_UNUSED, |
8428 | bfd_vma vec ATTRIBUTE_UNUSED) | |
95e34ef7 | 8429 | { |
5f101a3d | 8430 | /* Not yet supported. */ |
96d3b80f | 8431 | return FALSE; |
95e34ef7 TG |
8432 | } |
8433 | ||
5369db0a | 8434 | /* Add relocation. FIXME: Not yet emitted. */ |
95e34ef7 | 8435 | |
96d3b80f | 8436 | static bfd_boolean |
95e34ef7 TG |
8437 | alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8438 | { | |
96d3b80f | 8439 | return FALSE; |
95e34ef7 TG |
8440 | } |
8441 | ||
96d3b80f | 8442 | static bfd_boolean |
95e34ef7 TG |
8443 | alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8444 | { | |
96d3b80f | 8445 | return FALSE; |
95e34ef7 TG |
8446 | } |
8447 | ||
8448 | static struct bfd_hash_entry * | |
8449 | alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry, | |
07d6d2b8 AM |
8450 | struct bfd_hash_table *table, |
8451 | const char *string) | |
95e34ef7 TG |
8452 | { |
8453 | struct alpha_vms_link_hash_entry *ret = | |
8454 | (struct alpha_vms_link_hash_entry *) entry; | |
8455 | ||
8456 | /* Allocate the structure if it has not already been allocated by a | |
8457 | subclass. */ | |
8458 | if (ret == NULL) | |
8459 | ret = ((struct alpha_vms_link_hash_entry *) | |
8460 | bfd_hash_allocate (table, | |
07d6d2b8 | 8461 | sizeof (struct alpha_vms_link_hash_entry))); |
95e34ef7 TG |
8462 | if (ret == NULL) |
8463 | return NULL; | |
8464 | ||
8465 | /* Call the allocation method of the superclass. */ | |
8466 | ret = ((struct alpha_vms_link_hash_entry *) | |
8467 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
8468 | table, string)); | |
8469 | ||
8470 | ret->sym = NULL; | |
8471 | ||
8472 | return (struct bfd_hash_entry *) ret; | |
8473 | } | |
8474 | ||
37d2e9c7 AM |
8475 | static void |
8476 | alpha_vms_bfd_link_hash_table_free (bfd *abfd) | |
8477 | { | |
8478 | struct alpha_vms_link_hash_table *t; | |
8479 | unsigned i; | |
8480 | ||
8481 | t = (struct alpha_vms_link_hash_table *) abfd->link.hash; | |
8482 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
8483 | { | |
8484 | struct alpha_vms_shlib_el *shlib; | |
8485 | ||
8486 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
8487 | free (&VEC_EL (shlib->ca, bfd_vma, 0)); | |
8488 | free (&VEC_EL (shlib->lp, bfd_vma, 0)); | |
8489 | free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0)); | |
8490 | } | |
8491 | free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0)); | |
8492 | ||
8493 | _bfd_generic_link_hash_table_free (abfd); | |
8494 | } | |
8495 | ||
95e34ef7 TG |
8496 | /* Create an Alpha/VMS link hash table. */ |
8497 | ||
8498 | static struct bfd_link_hash_table * | |
8499 | alpha_vms_bfd_link_hash_table_create (bfd *abfd) | |
8500 | { | |
8501 | struct alpha_vms_link_hash_table *ret; | |
986f0783 | 8502 | size_t amt = sizeof (struct alpha_vms_link_hash_table); |
95e34ef7 TG |
8503 | |
8504 | ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt); | |
8505 | if (ret == NULL) | |
8506 | return NULL; | |
8507 | if (!_bfd_link_hash_table_init (&ret->root, abfd, | |
8508 | alpha_vms_link_hash_newfunc, | |
8509 | sizeof (struct alpha_vms_link_hash_entry))) | |
8510 | { | |
8511 | free (ret); | |
8512 | return NULL; | |
8513 | } | |
8514 | ||
8515 | VEC_INIT (ret->shrlibs); | |
8516 | ret->fixup = NULL; | |
37d2e9c7 | 8517 | ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free; |
95e34ef7 TG |
8518 | |
8519 | return &ret->root; | |
8520 | } | |
8521 | ||
8522 | static bfd_boolean | |
8523 | alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) | |
8524 | { | |
8525 | unsigned int i; | |
8526 | ||
8527 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
8528 | { | |
8529 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
8530 | struct alpha_vms_link_hash_entry *h; | |
11afaeda | 8531 | struct bfd_link_hash_entry *h_root; |
95e34ef7 TG |
8532 | asymbol sym; |
8533 | ||
8534 | if (!alpha_vms_convert_symbol (abfd, e, &sym)) | |
07d6d2b8 | 8535 | return FALSE; |
95e34ef7 TG |
8536 | |
8537 | if ((e->flags & EGSY__V_DEF) && abfd->selective_search) | |
07d6d2b8 AM |
8538 | { |
8539 | /* In selective_search mode, only add definition that are | |
8540 | required. */ | |
8541 | h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup | |
8542 | (info->hash, sym.name, FALSE, FALSE, FALSE); | |
8543 | if (h == NULL || h->root.type != bfd_link_hash_undefined) | |
8544 | continue; | |
8545 | } | |
95e34ef7 | 8546 | else |
07d6d2b8 | 8547 | h = NULL; |
95e34ef7 | 8548 | |
11afaeda | 8549 | h_root = (struct bfd_link_hash_entry *) h; |
535b785f AM |
8550 | if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags, |
8551 | sym.section, sym.value, NULL, | |
8552 | FALSE, FALSE, &h_root)) | |
07d6d2b8 | 8553 | return FALSE; |
11afaeda | 8554 | h = (struct alpha_vms_link_hash_entry *) h_root; |
95e34ef7 TG |
8555 | |
8556 | if ((e->flags & EGSY__V_DEF) | |
07d6d2b8 AM |
8557 | && h->sym == NULL |
8558 | && abfd->xvec == info->output_bfd->xvec) | |
8559 | h->sym = e; | |
95e34ef7 TG |
8560 | } |
8561 | ||
8562 | if (abfd->flags & DYNAMIC) | |
8563 | { | |
8564 | struct alpha_vms_shlib_el *shlib; | |
8565 | ||
8566 | /* We do not want to include any of the sections in a dynamic | |
07d6d2b8 | 8567 | object in the output file. See comment in elflink.c. */ |
95e34ef7 TG |
8568 | bfd_section_list_clear (abfd); |
8569 | ||
8570 | shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8571 | struct alpha_vms_shlib_el); |
96d3b80f AM |
8572 | if (shlib == NULL) |
8573 | return FALSE; | |
95e34ef7 TG |
8574 | shlib->abfd = abfd; |
8575 | VEC_INIT (shlib->ca); | |
8576 | VEC_INIT (shlib->lp); | |
8577 | VEC_INIT (shlib->qr); | |
8578 | PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1; | |
8579 | } | |
8580 | ||
8581 | return TRUE; | |
8582 | } | |
8583 | ||
8584 | static bfd_boolean | |
8585 | alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) | |
8586 | { | |
8587 | int pass; | |
8588 | struct bfd_link_hash_entry **pundef; | |
8589 | struct bfd_link_hash_entry **next_pundef; | |
8590 | ||
8591 | /* We only accept VMS libraries. */ | |
8592 | if (info->output_bfd->xvec != abfd->xvec) | |
8593 | { | |
8594 | bfd_set_error (bfd_error_wrong_format); | |
8595 | return FALSE; | |
8596 | } | |
8597 | ||
8598 | /* The archive_pass field in the archive itself is used to | |
8599 | initialize PASS, since we may search the same archive multiple | |
8600 | times. */ | |
8601 | pass = ++abfd->archive_pass; | |
8602 | ||
8603 | /* Look through the list of undefined symbols. */ | |
8604 | for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef) | |
8605 | { | |
8606 | struct bfd_link_hash_entry *h; | |
8e57e1d1 | 8607 | symindex symidx; |
95e34ef7 TG |
8608 | bfd *element; |
8609 | bfd *orig_element; | |
8610 | ||
8611 | h = *pundef; | |
8612 | next_pundef = &(*pundef)->u.undef.next; | |
8613 | ||
8614 | /* When a symbol is defined, it is not necessarily removed from | |
8615 | the list. */ | |
8616 | if (h->type != bfd_link_hash_undefined | |
8617 | && h->type != bfd_link_hash_common) | |
8618 | { | |
8619 | /* Remove this entry from the list, for general cleanliness | |
8620 | and because we are going to look through the list again | |
8621 | if we search any more libraries. We can't remove the | |
8622 | entry if it is the tail, because that would lose any | |
8623 | entries we add to the list later on. */ | |
8624 | if (*pundef != info->hash->undefs_tail) | |
07d6d2b8 AM |
8625 | { |
8626 | *pundef = *next_pundef; | |
8627 | next_pundef = pundef; | |
8628 | } | |
95e34ef7 TG |
8629 | continue; |
8630 | } | |
8631 | ||
8632 | /* Look for this symbol in the archive hash table. */ | |
8e57e1d1 TG |
8633 | symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string); |
8634 | if (symidx == BFD_NO_MORE_SYMBOLS) | |
95e34ef7 TG |
8635 | { |
8636 | /* Nothing in this slot. */ | |
8637 | continue; | |
8638 | } | |
8639 | ||
8e57e1d1 | 8640 | element = bfd_get_elt_at_index (abfd, symidx); |
95e34ef7 TG |
8641 | if (element == NULL) |
8642 | return FALSE; | |
8643 | ||
8644 | if (element->archive_pass == -1 || element->archive_pass == pass) | |
07d6d2b8 AM |
8645 | { |
8646 | /* Next symbol if this archive is wrong or already handled. */ | |
8647 | continue; | |
8648 | } | |
95e34ef7 TG |
8649 | |
8650 | if (! bfd_check_format (element, bfd_object)) | |
07d6d2b8 AM |
8651 | { |
8652 | element->archive_pass = -1; | |
8653 | return FALSE; | |
8654 | } | |
95e34ef7 TG |
8655 | |
8656 | orig_element = element; | |
8657 | if (bfd_is_thin_archive (abfd)) | |
07d6d2b8 AM |
8658 | { |
8659 | element = _bfd_vms_lib_get_imagelib_file (element); | |
8660 | if (element == NULL || !bfd_check_format (element, bfd_object)) | |
8661 | { | |
8662 | orig_element->archive_pass = -1; | |
8663 | return FALSE; | |
8664 | } | |
8665 | } | |
95e34ef7 TG |
8666 | |
8667 | /* Unlike the generic linker, we know that this element provides | |
8668 | a definition for an undefined symbol and we know that we want | |
8669 | to include it. We don't need to check anything. */ | |
0e144ba7 AM |
8670 | if (!(*info->callbacks |
8671 | ->add_archive_element) (info, element, h->root.string, &element)) | |
b95a0a31 | 8672 | continue; |
0e144ba7 | 8673 | if (!alpha_vms_link_add_object_symbols (element, info)) |
95e34ef7 TG |
8674 | return FALSE; |
8675 | ||
8676 | orig_element->archive_pass = pass; | |
8677 | } | |
8678 | ||
8679 | return TRUE; | |
8680 | } | |
8681 | ||
8682 | static bfd_boolean | |
8683 | alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info) | |
8684 | { | |
8685 | switch (bfd_get_format (abfd)) | |
8686 | { | |
8687 | case bfd_object: | |
8688 | vms_debug2 ((2, "vms_link_add_symbols for object %s\n", | |
07d6d2b8 | 8689 | abfd->filename)); |
95e34ef7 TG |
8690 | return alpha_vms_link_add_object_symbols (abfd, info); |
8691 | break; | |
8692 | case bfd_archive: | |
8693 | vms_debug2 ((2, "vms_link_add_symbols for archive %s\n", | |
07d6d2b8 | 8694 | abfd->filename)); |
95e34ef7 TG |
8695 | return alpha_vms_link_add_archive_symbols (abfd, info); |
8696 | break; | |
8697 | default: | |
8698 | bfd_set_error (bfd_error_wrong_format); | |
8699 | return FALSE; | |
8700 | } | |
8701 | } | |
8702 | ||
8703 | static bfd_boolean | |
8704 | alpha_vms_build_fixups (struct bfd_link_info *info) | |
8705 | { | |
8706 | struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info); | |
8707 | unsigned char *content; | |
8708 | unsigned int i; | |
8709 | unsigned int sz = 0; | |
8710 | unsigned int lp_sz = 0; | |
8711 | unsigned int ca_sz = 0; | |
8712 | unsigned int qr_sz = 0; | |
8713 | unsigned int shrimg_cnt = 0; | |
79326a5a TG |
8714 | unsigned int chgprt_num = 0; |
8715 | unsigned int chgprt_sz = 0; | |
95e34ef7 TG |
8716 | struct vms_eiaf *eiaf; |
8717 | unsigned int off; | |
8718 | asection *sec; | |
8719 | ||
8720 | /* Shared libraries. */ | |
8721 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
8722 | { | |
8723 | struct alpha_vms_shlib_el *shlib; | |
8724 | ||
8725 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
8726 | ||
8727 | if (!shlib->has_fixups) | |
07d6d2b8 | 8728 | continue; |
95e34ef7 TG |
8729 | |
8730 | shrimg_cnt++; | |
8731 | ||
8732 | if (VEC_COUNT (shlib->ca) > 0) | |
07d6d2b8 AM |
8733 | { |
8734 | /* Header + entries. */ | |
8735 | ca_sz += 8; | |
8736 | ca_sz += VEC_COUNT (shlib->ca) * 4; | |
8737 | } | |
95e34ef7 | 8738 | if (VEC_COUNT (shlib->lp) > 0) |
07d6d2b8 AM |
8739 | { |
8740 | /* Header + entries. */ | |
8741 | lp_sz += 8; | |
8742 | lp_sz += VEC_COUNT (shlib->lp) * 4; | |
8743 | } | |
95e34ef7 | 8744 | if (VEC_COUNT (shlib->qr) > 0) |
07d6d2b8 AM |
8745 | { |
8746 | /* Header + entries. */ | |
8747 | qr_sz += 8; | |
8748 | qr_sz += VEC_COUNT (shlib->qr) * 8; | |
8749 | } | |
95e34ef7 TG |
8750 | } |
8751 | /* Add markers. */ | |
8752 | if (ca_sz > 0) | |
8753 | ca_sz += 8; | |
8754 | if (lp_sz > 0) | |
8755 | lp_sz += 8; | |
8756 | if (qr_sz > 0) | |
8757 | qr_sz += 8; | |
8758 | ||
8759 | /* Finish now if there is no content. */ | |
8760 | if (ca_sz + lp_sz + qr_sz == 0) | |
8761 | return TRUE; | |
8762 | ||
79326a5a TG |
8763 | /* Add an eicp entry for the fixup itself. */ |
8764 | chgprt_num = 1; | |
8765 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) | |
8766 | { | |
8767 | /* This isect could be made RO or EXE after relocations are applied. */ | |
8768 | if ((sec->flags & SEC_RELOC) != 0 | |
07d6d2b8 AM |
8769 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
8770 | chgprt_num++; | |
79326a5a TG |
8771 | } |
8772 | chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp); | |
8773 | ||
95e34ef7 TG |
8774 | /* Allocate section content (round-up size) */ |
8775 | sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl) | |
79326a5a | 8776 | + ca_sz + lp_sz + qr_sz + chgprt_sz; |
95e34ef7 TG |
8777 | sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); |
8778 | content = bfd_zalloc (info->output_bfd, sz); | |
8779 | if (content == NULL) | |
8780 | return FALSE; | |
8781 | ||
8782 | sec = alpha_vms_link_hash (info)->fixup; | |
8783 | sec->contents = content; | |
8784 | sec->size = sz; | |
8785 | ||
8786 | eiaf = (struct vms_eiaf *)content; | |
8787 | off = sizeof (struct vms_eiaf); | |
8788 | bfd_putl32 (0, eiaf->majorid); | |
8789 | bfd_putl32 (0, eiaf->minorid); | |
8790 | bfd_putl32 (0, eiaf->iaflink); | |
8791 | bfd_putl32 (0, eiaf->fixuplnk); | |
8792 | bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size); | |
8793 | bfd_putl32 (0, eiaf->flags); | |
8794 | bfd_putl32 (0, eiaf->qrelfixoff); | |
8795 | bfd_putl32 (0, eiaf->lrelfixoff); | |
8796 | bfd_putl32 (0, eiaf->qdotadroff); | |
8797 | bfd_putl32 (0, eiaf->ldotadroff); | |
8798 | bfd_putl32 (0, eiaf->codeadroff); | |
8799 | bfd_putl32 (0, eiaf->lpfixoff); | |
8800 | bfd_putl32 (0, eiaf->chgprtoff); | |
8801 | bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff); | |
8802 | bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt); | |
8803 | bfd_putl32 (0, eiaf->shlextra); | |
8804 | bfd_putl32 (0, eiaf->permctx); | |
8805 | bfd_putl32 (0, eiaf->base_va); | |
8806 | bfd_putl32 (0, eiaf->lppsbfixoff); | |
8807 | ||
8808 | if (shrimg_cnt) | |
8809 | { | |
8810 | shrimg_cnt = 0; | |
8811 | ||
8812 | /* Write shl. */ | |
8813 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
07d6d2b8 AM |
8814 | { |
8815 | struct alpha_vms_shlib_el *shlib; | |
8816 | struct vms_shl *shl; | |
8817 | ||
8818 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
8819 | ||
8820 | if (!shlib->has_fixups) | |
8821 | continue; | |
8822 | ||
8823 | /* Renumber shared images. */ | |
8824 | PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++; | |
8825 | ||
8826 | shl = (struct vms_shl *)(content + off); | |
8827 | bfd_putl32 (0, shl->baseva); | |
8828 | bfd_putl32 (0, shl->shlptr); | |
8829 | bfd_putl32 (0, shl->ident); | |
8830 | bfd_putl32 (0, shl->permctx); | |
8831 | shl->size = sizeof (struct vms_shl); | |
8832 | bfd_putl16 (0, shl->fill_1); | |
8833 | shl->flags = 0; | |
8834 | bfd_putl32 (0, shl->icb); | |
8835 | shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name)); | |
8836 | memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name), | |
8837 | shl->imgnam[0]); | |
8838 | ||
8839 | off += sizeof (struct vms_shl); | |
8840 | } | |
95e34ef7 TG |
8841 | |
8842 | /* CA fixups. */ | |
8843 | if (ca_sz != 0) | |
07d6d2b8 AM |
8844 | { |
8845 | bfd_putl32 (off, eiaf->codeadroff); | |
95e34ef7 | 8846 | |
07d6d2b8 AM |
8847 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
8848 | { | |
8849 | struct alpha_vms_shlib_el *shlib; | |
8850 | unsigned int j; | |
95e34ef7 | 8851 | |
07d6d2b8 | 8852 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 8853 | |
07d6d2b8 AM |
8854 | if (VEC_COUNT (shlib->ca) == 0) |
8855 | continue; | |
95e34ef7 | 8856 | |
07d6d2b8 AM |
8857 | bfd_putl32 (VEC_COUNT (shlib->ca), content + off); |
8858 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
8859 | off += 8; | |
95e34ef7 | 8860 | |
07d6d2b8 AM |
8861 | for (j = 0; j < VEC_COUNT (shlib->ca); j++) |
8862 | { | |
8863 | bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr, | |
8864 | content + off); | |
8865 | off += 4; | |
8866 | } | |
8867 | } | |
95e34ef7 | 8868 | |
07d6d2b8 AM |
8869 | bfd_putl32 (0, content + off); |
8870 | bfd_putl32 (0, content + off + 4); | |
8871 | off += 8; | |
8872 | } | |
95e34ef7 TG |
8873 | |
8874 | /* LP fixups. */ | |
8875 | if (lp_sz != 0) | |
07d6d2b8 AM |
8876 | { |
8877 | bfd_putl32 (off, eiaf->lpfixoff); | |
95e34ef7 | 8878 | |
07d6d2b8 AM |
8879 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
8880 | { | |
8881 | struct alpha_vms_shlib_el *shlib; | |
8882 | unsigned int j; | |
95e34ef7 | 8883 | |
07d6d2b8 | 8884 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 8885 | |
07d6d2b8 AM |
8886 | if (VEC_COUNT (shlib->lp) == 0) |
8887 | continue; | |
95e34ef7 | 8888 | |
07d6d2b8 AM |
8889 | bfd_putl32 (VEC_COUNT (shlib->lp), content + off); |
8890 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
8891 | off += 8; | |
95e34ef7 | 8892 | |
07d6d2b8 AM |
8893 | for (j = 0; j < VEC_COUNT (shlib->lp); j++) |
8894 | { | |
8895 | bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr, | |
8896 | content + off); | |
8897 | off += 4; | |
8898 | } | |
8899 | } | |
95e34ef7 | 8900 | |
07d6d2b8 AM |
8901 | bfd_putl32 (0, content + off); |
8902 | bfd_putl32 (0, content + off + 4); | |
8903 | off += 8; | |
8904 | } | |
95e34ef7 TG |
8905 | |
8906 | /* QR fixups. */ | |
8907 | if (qr_sz != 0) | |
07d6d2b8 AM |
8908 | { |
8909 | bfd_putl32 (off, eiaf->qdotadroff); | |
95e34ef7 | 8910 | |
07d6d2b8 AM |
8911 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
8912 | { | |
8913 | struct alpha_vms_shlib_el *shlib; | |
8914 | unsigned int j; | |
95e34ef7 | 8915 | |
07d6d2b8 | 8916 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 8917 | |
07d6d2b8 AM |
8918 | if (VEC_COUNT (shlib->qr) == 0) |
8919 | continue; | |
95e34ef7 | 8920 | |
07d6d2b8 AM |
8921 | bfd_putl32 (VEC_COUNT (shlib->qr), content + off); |
8922 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
8923 | off += 8; | |
95e34ef7 | 8924 | |
07d6d2b8 AM |
8925 | for (j = 0; j < VEC_COUNT (shlib->qr); j++) |
8926 | { | |
8927 | struct alpha_vms_vma_ref *r; | |
8928 | r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j); | |
8929 | bfd_putl32 (r->vma - t->base_addr, content + off); | |
8930 | bfd_putl32 (r->ref, content + off + 4); | |
8931 | off += 8; | |
8932 | } | |
8933 | } | |
95e34ef7 | 8934 | |
07d6d2b8 AM |
8935 | bfd_putl32 (0, content + off); |
8936 | bfd_putl32 (0, content + off + 4); | |
8937 | off += 8; | |
8938 | } | |
95e34ef7 TG |
8939 | } |
8940 | ||
79326a5a TG |
8941 | /* Write the change protection table. */ |
8942 | bfd_putl32 (off, eiaf->chgprtoff); | |
8943 | bfd_putl32 (chgprt_num, content + off); | |
8944 | off += 4; | |
8945 | ||
8946 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) | |
8947 | { | |
8948 | struct vms_eicp *eicp; | |
8949 | unsigned int prot; | |
8950 | ||
8951 | if ((sec->flags & SEC_LINKER_CREATED) != 0 && | |
07d6d2b8 AM |
8952 | strcmp (sec->name, "$FIXUP$") == 0) |
8953 | prot = PRT__C_UREW; | |
79326a5a | 8954 | else if ((sec->flags & SEC_RELOC) != 0 |
07d6d2b8 AM |
8955 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
8956 | prot = PRT__C_UR; | |
79326a5a | 8957 | else |
07d6d2b8 | 8958 | continue; |
79326a5a TG |
8959 | |
8960 | eicp = (struct vms_eicp *)(content + off); | |
8961 | bfd_putl64 (sec->vma - t->base_addr, eicp->baseva); | |
8962 | bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1), | |
07d6d2b8 | 8963 | eicp->size); |
79326a5a TG |
8964 | bfd_putl32 (prot, eicp->newprt); |
8965 | off += sizeof (struct vms_eicp); | |
8966 | } | |
8967 | ||
95e34ef7 TG |
8968 | return TRUE; |
8969 | } | |
8970 | ||
7686d77d | 8971 | /* Called by bfd_hash_traverse to fill the symbol table. |
f9eeb9c9 TG |
8972 | Return FALSE in case of failure. */ |
8973 | ||
8974 | static bfd_boolean | |
7686d77d | 8975 | alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov) |
f9eeb9c9 | 8976 | { |
7686d77d | 8977 | struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh; |
f9eeb9c9 | 8978 | struct bfd_link_info *info = (struct bfd_link_info *)infov; |
7686d77d | 8979 | struct alpha_vms_link_hash_entry *h; |
f9eeb9c9 TG |
8980 | struct vms_symbol_entry *sym; |
8981 | ||
7686d77d AM |
8982 | if (hc->type == bfd_link_hash_warning) |
8983 | { | |
8984 | hc = hc->u.i.link; | |
8985 | if (hc->type == bfd_link_hash_new) | |
8986 | return TRUE; | |
8987 | } | |
8988 | h = (struct alpha_vms_link_hash_entry *) hc; | |
8989 | ||
f9eeb9c9 TG |
8990 | switch (h->root.type) |
8991 | { | |
f9eeb9c9 | 8992 | case bfd_link_hash_undefined: |
8185f55c TG |
8993 | return TRUE; |
8994 | case bfd_link_hash_new: | |
7686d77d | 8995 | case bfd_link_hash_warning: |
f9eeb9c9 TG |
8996 | abort (); |
8997 | case bfd_link_hash_undefweak: | |
8998 | return TRUE; | |
8999 | case bfd_link_hash_defined: | |
9000 | case bfd_link_hash_defweak: | |
9001 | { | |
07d6d2b8 | 9002 | asection *sec = h->root.u.def.section; |
f9eeb9c9 | 9003 | |
07d6d2b8 AM |
9004 | /* FIXME: this is certainly a symbol from a dynamic library. */ |
9005 | if (bfd_is_abs_section (sec)) | |
9006 | return TRUE; | |
f9eeb9c9 | 9007 | |
07d6d2b8 AM |
9008 | if (sec->owner->flags & DYNAMIC) |
9009 | return TRUE; | |
f9eeb9c9 TG |
9010 | } |
9011 | break; | |
9012 | case bfd_link_hash_common: | |
9013 | break; | |
9014 | case bfd_link_hash_indirect: | |
f9eeb9c9 TG |
9015 | return TRUE; |
9016 | } | |
9017 | ||
9018 | /* Do not write not kept symbols. */ | |
9019 | if (info->strip == strip_some | |
9020 | && bfd_hash_lookup (info->keep_hash, h->root.root.string, | |
07d6d2b8 | 9021 | FALSE, FALSE) != NULL) |
f9eeb9c9 TG |
9022 | return TRUE; |
9023 | ||
9024 | if (h->sym == NULL) | |
9025 | { | |
9026 | /* This symbol doesn't come from a VMS object. So we suppose it is | |
07d6d2b8 | 9027 | a data. */ |
f9eeb9c9 TG |
9028 | int len = strlen (h->root.root.string); |
9029 | ||
9030 | sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd, | |
07d6d2b8 | 9031 | sizeof (*sym) + len); |
f9eeb9c9 | 9032 | if (sym == NULL) |
07d6d2b8 | 9033 | abort (); |
f9eeb9c9 TG |
9034 | sym->namelen = len; |
9035 | memcpy (sym->name, h->root.root.string, len); | |
9036 | sym->name[len] = 0; | |
9037 | sym->owner = info->output_bfd; | |
9038 | ||
9039 | sym->typ = EGSD__C_SYMG; | |
9040 | sym->data_type = 0; | |
9041 | sym->flags = EGSY__V_DEF | EGSY__V_REL; | |
9042 | sym->symbol_vector = h->root.u.def.value; | |
9043 | sym->section = h->root.u.def.section; | |
9044 | sym->value = h->root.u.def.value; | |
9045 | } | |
9046 | else | |
9047 | sym = h->sym; | |
9048 | ||
9049 | if (!add_symbol_entry (info->output_bfd, sym)) | |
9050 | return FALSE; | |
9051 | ||
9052 | return TRUE; | |
9053 | } | |
9054 | ||
95e34ef7 TG |
9055 | static bfd_boolean |
9056 | alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info) | |
9057 | { | |
9058 | asection *o; | |
9059 | struct bfd_link_order *p; | |
9060 | bfd *sub; | |
9061 | asection *fixupsec; | |
9062 | bfd_vma base_addr; | |
9063 | bfd_vma last_addr; | |
44273c5b | 9064 | asection *dst; |
fa23f0f4 | 9065 | asection *dmt; |
95e34ef7 | 9066 | |
0e1862bb | 9067 | if (bfd_link_relocatable (info)) |
79326a5a TG |
9068 | { |
9069 | /* FIXME: we do not yet support relocatable link. It is not obvious | |
07d6d2b8 | 9070 | how to do it for debug infos. */ |
79326a5a TG |
9071 | (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n")); |
9072 | return FALSE; | |
9073 | } | |
9074 | ||
ed48ec2e AM |
9075 | abfd->outsymbols = NULL; |
9076 | abfd->symcount = 0; | |
95e34ef7 TG |
9077 | |
9078 | /* Mark all sections which will be included in the output file. */ | |
9079 | for (o = abfd->sections; o != NULL; o = o->next) | |
9080 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9081 | if (p->type == bfd_indirect_link_order) | |
9082 | p->u.indirect.section->linker_mark = TRUE; | |
9083 | ||
9084 | #if 0 | |
9085 | /* Handle all the link order information for the sections. */ | |
9086 | for (o = abfd->sections; o != NULL; o = o->next) | |
9087 | { | |
9088 | printf ("For section %s (at 0x%08x, flags=0x%08x):\n", | |
07d6d2b8 | 9089 | o->name, (unsigned)o->vma, (unsigned)o->flags); |
95e34ef7 TG |
9090 | |
9091 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9092 | { | |
07d6d2b8 AM |
9093 | printf (" at 0x%08x - 0x%08x: ", |
9094 | (unsigned)p->offset, (unsigned)(p->offset + p->size - 1)); | |
95e34ef7 TG |
9095 | switch (p->type) |
9096 | { | |
9097 | case bfd_section_reloc_link_order: | |
9098 | case bfd_symbol_reloc_link_order: | |
07d6d2b8 | 9099 | printf (" section/symbol reloc\n"); |
95e34ef7 TG |
9100 | break; |
9101 | case bfd_indirect_link_order: | |
07d6d2b8 AM |
9102 | printf (" section %s of %s\n", |
9103 | p->u.indirect.section->name, | |
9104 | p->u.indirect.section->owner->filename); | |
9105 | break; | |
9106 | case bfd_data_link_order: | |
9107 | printf (" explicit data\n"); | |
95e34ef7 | 9108 | break; |
95e34ef7 | 9109 | default: |
07d6d2b8 | 9110 | printf (" *unknown* type %u\n", p->type); |
95e34ef7 TG |
9111 | break; |
9112 | } | |
9113 | } | |
9114 | } | |
9115 | #endif | |
9116 | ||
f9eeb9c9 TG |
9117 | /* Generate the symbol table. */ |
9118 | BFD_ASSERT (PRIV (syms) == NULL); | |
9119 | if (info->strip != strip_all) | |
7686d77d | 9120 | bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info); |
f9eeb9c9 | 9121 | |
44273c5b | 9122 | /* Find the entry point. */ |
95e34ef7 TG |
9123 | if (bfd_get_start_address (abfd) == 0) |
9124 | { | |
9125 | bfd *startbfd = NULL; | |
9126 | ||
c72f2fb2 | 9127 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
07d6d2b8 AM |
9128 | { |
9129 | /* Consider only VMS object files. */ | |
9130 | if (sub->xvec != abfd->xvec) | |
9131 | continue; | |
9132 | ||
9133 | if (!PRIV2 (sub, eom_data).eom_has_transfer) | |
9134 | continue; | |
9135 | if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd) | |
9136 | continue; | |
9137 | if (startbfd != NULL | |
9138 | && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR)) | |
9139 | { | |
9140 | (*info->callbacks->einfo) | |
695344c0 | 9141 | /* xgettext:c-format */ |
871b3ab2 | 9142 | (_("%P: multiple entry points: in modules %pB and %pB\n"), |
07d6d2b8 AM |
9143 | startbfd, sub); |
9144 | continue; | |
9145 | } | |
9146 | startbfd = sub; | |
9147 | } | |
95e34ef7 TG |
9148 | |
9149 | if (startbfd) | |
07d6d2b8 AM |
9150 | { |
9151 | unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx; | |
9152 | bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr; | |
9153 | asection *sec; | |
95e34ef7 | 9154 | |
07d6d2b8 | 9155 | sec = PRIV2 (startbfd, sections)[ps_idx]; |
95e34ef7 | 9156 | |
07d6d2b8 AM |
9157 | bfd_set_start_address |
9158 | (abfd, sec->output_section->vma + sec->output_offset + tfradr); | |
9159 | } | |
95e34ef7 TG |
9160 | } |
9161 | ||
46d00b8a TG |
9162 | /* Set transfer addresses. */ |
9163 | { | |
9164 | int i; | |
9165 | struct bfd_link_hash_entry *h; | |
9166 | ||
9167 | i = 0; | |
d0ef7741 | 9168 | PRIV (transfer_address[i++]) = 0xffffffff00000340ULL; /* SYS$IMGACT */ |
46d00b8a TG |
9169 | h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", FALSE, FALSE, TRUE); |
9170 | if (h != NULL && h->type == bfd_link_hash_defined) | |
9171 | PRIV (transfer_address[i++]) = | |
07d6d2b8 | 9172 | alpha_vms_get_sym_value (h->u.def.section, h->u.def.value); |
46d00b8a TG |
9173 | PRIV (transfer_address[i++]) = bfd_get_start_address (abfd); |
9174 | while (i < 4) | |
9175 | PRIV (transfer_address[i++]) = 0; | |
9176 | } | |
9177 | ||
79326a5a TG |
9178 | /* Allocate contents. |
9179 | Also compute the virtual base address. */ | |
95e34ef7 TG |
9180 | base_addr = (bfd_vma)-1; |
9181 | last_addr = 0; | |
9182 | for (o = abfd->sections; o != NULL; o = o->next) | |
9183 | { | |
9184 | if (o->flags & SEC_HAS_CONTENTS) | |
07d6d2b8 AM |
9185 | { |
9186 | o->contents = bfd_alloc (abfd, o->size); | |
9187 | if (o->contents == NULL) | |
9188 | return FALSE; | |
9189 | } | |
95e34ef7 | 9190 | if (o->flags & SEC_LOAD) |
07d6d2b8 AM |
9191 | { |
9192 | if (o->vma < base_addr) | |
9193 | base_addr = o->vma; | |
9194 | if (o->vma + o->size > last_addr) | |
9195 | last_addr = o->vma + o->size; | |
9196 | } | |
79326a5a | 9197 | /* Clear the RELOC flags. Currently we don't support incremental |
07d6d2b8 | 9198 | linking. We use the RELOC flag for computing the eicp entries. */ |
79326a5a | 9199 | o->flags &= ~SEC_RELOC; |
95e34ef7 TG |
9200 | } |
9201 | ||
44273c5b | 9202 | /* Create the fixup section. */ |
95e34ef7 TG |
9203 | fixupsec = bfd_make_section_anyway_with_flags |
9204 | (info->output_bfd, "$FIXUP$", | |
9205 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); | |
9206 | if (fixupsec == NULL) | |
9207 | return FALSE; | |
9208 | last_addr = (last_addr + 0xffff) & ~0xffff; | |
9209 | fixupsec->vma = last_addr; | |
9210 | ||
9211 | alpha_vms_link_hash (info)->fixup = fixupsec; | |
9212 | alpha_vms_link_hash (info)->base_addr = base_addr; | |
9213 | ||
fa23f0f4 | 9214 | /* Create the DMT section, if necessary. */ |
f9eeb9c9 TG |
9215 | BFD_ASSERT (PRIV (dst_section) == NULL); |
9216 | dst = bfd_get_section_by_name (abfd, "$DST$"); | |
fa23f0f4 TG |
9217 | if (dst != NULL && dst->size == 0) |
9218 | dst = NULL; | |
9219 | if (dst != NULL) | |
9220 | { | |
f9eeb9c9 | 9221 | PRIV (dst_section) = dst; |
fa23f0f4 | 9222 | dmt = bfd_make_section_anyway_with_flags |
07d6d2b8 AM |
9223 | (info->output_bfd, "$DMT$", |
9224 | SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); | |
fa23f0f4 | 9225 | if (dmt == NULL) |
07d6d2b8 | 9226 | return FALSE; |
fa23f0f4 TG |
9227 | } |
9228 | else | |
9229 | dmt = NULL; | |
9230 | ||
95e34ef7 | 9231 | /* Read all sections from the inputs. */ |
c72f2fb2 | 9232 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
95e34ef7 TG |
9233 | { |
9234 | if (sub->flags & DYNAMIC) | |
07d6d2b8 AM |
9235 | { |
9236 | alpha_vms_create_eisd_for_shared (abfd, sub); | |
9237 | continue; | |
9238 | } | |
95e34ef7 TG |
9239 | |
9240 | if (!alpha_vms_read_sections_content (sub, info)) | |
07d6d2b8 | 9241 | return FALSE; |
95e34ef7 TG |
9242 | } |
9243 | ||
fa23f0f4 TG |
9244 | /* Handle all the link order information for the sections. |
9245 | Note: past this point, it is not possible to create new sections. */ | |
95e34ef7 TG |
9246 | for (o = abfd->sections; o != NULL; o = o->next) |
9247 | { | |
9248 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9249 | { | |
9250 | switch (p->type) | |
9251 | { | |
9252 | case bfd_section_reloc_link_order: | |
9253 | case bfd_symbol_reloc_link_order: | |
07d6d2b8 AM |
9254 | abort (); |
9255 | return FALSE; | |
95e34ef7 | 9256 | case bfd_indirect_link_order: |
07d6d2b8 | 9257 | /* Already done. */ |
95e34ef7 TG |
9258 | break; |
9259 | default: | |
9260 | if (! _bfd_default_link_order (abfd, info, o, p)) | |
9261 | return FALSE; | |
9262 | break; | |
9263 | } | |
9264 | } | |
9265 | } | |
9266 | ||
9267 | /* Compute fixups. */ | |
9268 | if (!alpha_vms_build_fixups (info)) | |
9269 | return FALSE; | |
9270 | ||
44273c5b | 9271 | /* Compute the DMT. */ |
fa23f0f4 | 9272 | if (dmt != NULL) |
44273c5b | 9273 | { |
44273c5b TG |
9274 | int pass; |
9275 | unsigned char *contents = NULL; | |
9276 | ||
44273c5b TG |
9277 | /* In pass 1, compute the size. In pass 2, write the DMT contents. */ |
9278 | for (pass = 0; pass < 2; pass++) | |
07d6d2b8 AM |
9279 | { |
9280 | unsigned int off = 0; | |
9281 | ||
9282 | /* For each object file (ie for each module). */ | |
9283 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) | |
9284 | { | |
9285 | asection *sub_dst; | |
9286 | struct vms_dmt_header *dmth = NULL; | |
9287 | unsigned int psect_count; | |
9288 | ||
9289 | /* Skip this module if it has no DST. */ | |
9290 | sub_dst = PRIV2 (sub, dst_section); | |
9291 | if (sub_dst == NULL || sub_dst->size == 0) | |
9292 | continue; | |
9293 | ||
9294 | if (pass == 1) | |
9295 | { | |
9296 | /* Write the header. */ | |
9297 | dmth = (struct vms_dmt_header *)(contents + off); | |
9298 | bfd_putl32 (sub_dst->output_offset, dmth->modbeg); | |
9299 | bfd_putl32 (sub_dst->size, dmth->size); | |
9300 | } | |
9301 | ||
9302 | off += sizeof (struct vms_dmt_header); | |
9303 | psect_count = 0; | |
9304 | ||
9305 | /* For each section (ie for each psect). */ | |
9306 | for (o = sub->sections; o != NULL; o = o->next) | |
9307 | { | |
9308 | /* Only consider interesting sections. */ | |
9309 | if (!(o->flags & SEC_ALLOC)) | |
9310 | continue; | |
9311 | if (o->flags & SEC_LINKER_CREATED) | |
9312 | continue; | |
9313 | ||
9314 | if (pass == 1) | |
9315 | { | |
9316 | /* Write an entry. */ | |
9317 | struct vms_dmt_psect *dmtp; | |
9318 | ||
9319 | dmtp = (struct vms_dmt_psect *)(contents + off); | |
9320 | bfd_putl32 (o->output_offset + o->output_section->vma, | |
9321 | dmtp->start); | |
9322 | bfd_putl32 (o->size, dmtp->length); | |
9323 | psect_count++; | |
9324 | } | |
9325 | off += sizeof (struct vms_dmt_psect); | |
9326 | } | |
9327 | if (pass == 1) | |
9328 | bfd_putl32 (psect_count, dmth->psect_count); | |
9329 | } | |
9330 | ||
9331 | if (pass == 0) | |
9332 | { | |
9333 | contents = bfd_zalloc (info->output_bfd, off); | |
9334 | if (contents == NULL) | |
9335 | return FALSE; | |
9336 | dmt->contents = contents; | |
9337 | dmt->size = off; | |
9338 | } | |
9339 | else | |
9340 | { | |
9341 | BFD_ASSERT (off == dmt->size); | |
9342 | } | |
9343 | } | |
44273c5b TG |
9344 | } |
9345 | ||
95e34ef7 TG |
9346 | return TRUE; |
9347 | } | |
9348 | ||
9349 | /* Read the contents of a section. | |
9350 | buf points to a buffer of buf_size bytes to be filled with | |
9351 | section data (starting at offset into section) */ | |
9352 | ||
9353 | static bfd_boolean | |
9354 | alpha_vms_get_section_contents (bfd *abfd, asection *section, | |
07d6d2b8 AM |
9355 | void *buf, file_ptr offset, |
9356 | bfd_size_type count) | |
95e34ef7 TG |
9357 | { |
9358 | asection *sec; | |
9359 | ||
9360 | /* Image are easy. */ | |
9361 | if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) | |
9362 | return _bfd_generic_get_section_contents (abfd, section, | |
07d6d2b8 | 9363 | buf, offset, count); |
95e34ef7 TG |
9364 | |
9365 | /* Safety check. */ | |
9366 | if (offset + count < count | |
9367 | || offset + count > section->size) | |
9368 | { | |
9369 | bfd_set_error (bfd_error_invalid_operation); | |
9370 | return FALSE; | |
9371 | } | |
9372 | ||
8185f55c TG |
9373 | /* If the section is already in memory, just copy it. */ |
9374 | if (section->flags & SEC_IN_MEMORY) | |
9375 | { | |
9376 | BFD_ASSERT (section->contents != NULL); | |
9377 | memcpy (buf, section->contents + offset, count); | |
9378 | return TRUE; | |
9379 | } | |
9380 | if (section->size == 0) | |
9381 | return TRUE; | |
95e34ef7 | 9382 | |
8185f55c | 9383 | /* Alloc in memory and read ETIRs. */ |
95e34ef7 TG |
9384 | for (sec = abfd->sections; sec; sec = sec->next) |
9385 | { | |
9386 | BFD_ASSERT (sec->contents == NULL); | |
9387 | ||
9388 | if (sec->size != 0 && (sec->flags & SEC_HAS_CONTENTS)) | |
07d6d2b8 AM |
9389 | { |
9390 | sec->contents = bfd_alloc (abfd, sec->size); | |
9391 | if (sec->contents == NULL) | |
9392 | return FALSE; | |
9393 | } | |
95e34ef7 TG |
9394 | } |
9395 | if (!alpha_vms_read_sections_content (abfd, NULL)) | |
9396 | return FALSE; | |
9397 | for (sec = abfd->sections; sec; sec = sec->next) | |
8185f55c TG |
9398 | if (sec->contents) |
9399 | sec->flags |= SEC_IN_MEMORY; | |
95e34ef7 TG |
9400 | memcpy (buf, section->contents + offset, count); |
9401 | return TRUE; | |
9402 | } | |
9403 | ||
9404 | ||
9405 | /* Set the format of a file being written. */ | |
9406 | ||
9407 | static bfd_boolean | |
9408 | alpha_vms_mkobject (bfd * abfd) | |
9409 | { | |
9410 | const bfd_arch_info_type *arch; | |
9411 | ||
9412 | vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd)); | |
9413 | ||
9414 | if (!vms_initialize (abfd)) | |
9415 | return FALSE; | |
9416 | ||
9417 | PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE); | |
9418 | if (PRIV (recwr.buf) == NULL) | |
9419 | return FALSE; | |
9420 | ||
9421 | arch = bfd_scan_arch ("alpha"); | |
9422 | ||
9423 | if (arch == 0) | |
9424 | { | |
9425 | bfd_set_error (bfd_error_wrong_format); | |
9426 | return FALSE; | |
9427 | } | |
9428 | ||
9429 | abfd->arch_info = arch; | |
9430 | return TRUE; | |
9431 | } | |
9432 | ||
9433 | ||
9434 | /* 4.1, generic. */ | |
9435 | ||
9436 | /* Called when the BFD is being closed to do any necessary cleanup. */ | |
9437 | ||
9438 | static bfd_boolean | |
9439 | vms_close_and_cleanup (bfd * abfd) | |
9440 | { | |
9441 | vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd)); | |
9442 | ||
9443 | if (abfd == NULL || abfd->tdata.any == NULL) | |
9444 | return TRUE; | |
9445 | ||
37d2e9c7 | 9446 | if (abfd->format == bfd_object) |
95e34ef7 | 9447 | { |
a7ac9aa5 | 9448 | alpha_vms_free_private (abfd); |
95e34ef7 TG |
9449 | |
9450 | #ifdef VMS | |
37d2e9c7 AM |
9451 | if (abfd->direction == write_direction) |
9452 | { | |
9453 | /* Last step on VMS is to convert the file to variable record length | |
9454 | format. */ | |
9455 | if (!bfd_cache_close (abfd)) | |
9456 | return FALSE; | |
9457 | if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename)) | |
9458 | return FALSE; | |
9459 | } | |
95e34ef7 | 9460 | #endif |
37d2e9c7 | 9461 | } |
95e34ef7 | 9462 | |
37d2e9c7 | 9463 | return _bfd_generic_close_and_cleanup (abfd); |
95e34ef7 TG |
9464 | } |
9465 | ||
9466 | /* Called when a new section is created. */ | |
9467 | ||
9468 | static bfd_boolean | |
9469 | vms_new_section_hook (bfd * abfd, asection *section) | |
9470 | { | |
986f0783 | 9471 | size_t amt; |
95e34ef7 | 9472 | |
d3435ae8 | 9473 | vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n", |
07d6d2b8 | 9474 | abfd, section->index, section->name)); |
95e34ef7 | 9475 | |
fd361982 | 9476 | if (!bfd_set_section_alignment (section, 0)) |
a253d456 | 9477 | return FALSE; |
95e34ef7 | 9478 | |
d3435ae8 | 9479 | vms_debug2 ((7, "%u: %s\n", section->index, section->name)); |
95e34ef7 TG |
9480 | |
9481 | amt = sizeof (struct vms_section_data_struct); | |
8185f55c | 9482 | section->used_by_bfd = bfd_zalloc (abfd, amt); |
95e34ef7 TG |
9483 | if (section->used_by_bfd == NULL) |
9484 | return FALSE; | |
9485 | ||
95e34ef7 TG |
9486 | /* Create the section symbol. */ |
9487 | return _bfd_generic_new_section_hook (abfd, section); | |
9488 | } | |
9489 | ||
9490 | /* Part 4.5, symbols. */ | |
9491 | ||
9492 | /* Print symbol to file according to how. how is one of | |
9493 | bfd_print_symbol_name just print the name | |
9494 | bfd_print_symbol_more print more (???) | |
9495 | bfd_print_symbol_all print all we know, which is not much right now :-). */ | |
9496 | ||
9497 | static void | |
9498 | vms_print_symbol (bfd * abfd, | |
9499 | void * file, | |
9500 | asymbol *symbol, | |
9501 | bfd_print_symbol_type how) | |
9502 | { | |
9503 | vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n", | |
07d6d2b8 | 9504 | abfd, file, symbol, how)); |
95e34ef7 TG |
9505 | |
9506 | switch (how) | |
9507 | { | |
9508 | case bfd_print_symbol_name: | |
9509 | case bfd_print_symbol_more: | |
9510 | fprintf ((FILE *)file," %s", symbol->name); | |
9511 | break; | |
9512 | ||
9513 | case bfd_print_symbol_all: | |
9514 | { | |
9515 | const char *section_name = symbol->section->name; | |
9516 | ||
9517 | bfd_print_symbol_vandf (abfd, file, symbol); | |
9518 | ||
9519 | fprintf ((FILE *) file," %-8s %s", section_name, symbol->name); | |
07d6d2b8 | 9520 | } |
95e34ef7 TG |
9521 | break; |
9522 | } | |
9523 | } | |
9524 | ||
9525 | /* Return information about symbol in ret. | |
9526 | ||
9527 | fill type, value and name | |
9528 | type: | |
9529 | A absolute | |
9530 | B bss segment symbol | |
9531 | C common symbol | |
9532 | D data segment symbol | |
9533 | f filename | |
9534 | t a static function symbol | |
9535 | T text segment symbol | |
9536 | U undefined | |
9537 | - debug. */ | |
9538 | ||
9539 | static void | |
9540 | vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED, | |
9541 | asymbol *symbol, | |
9542 | symbol_info *ret) | |
9543 | { | |
9544 | asection *sec; | |
9545 | ||
9546 | vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret)); | |
9547 | ||
9548 | sec = symbol->section; | |
9549 | ||
9550 | if (ret == NULL) | |
9551 | return; | |
9552 | ||
a928f1d7 | 9553 | if (sec == NULL) |
95e34ef7 TG |
9554 | ret->type = 'U'; |
9555 | else if (bfd_is_com_section (sec)) | |
9556 | ret->type = 'C'; | |
9557 | else if (bfd_is_abs_section (sec)) | |
9558 | ret->type = 'A'; | |
9559 | else if (bfd_is_und_section (sec)) | |
9560 | ret->type = 'U'; | |
9561 | else if (bfd_is_ind_section (sec)) | |
9562 | ret->type = 'I'; | |
c068d5be | 9563 | else if ((symbol->flags & BSF_FUNCTION) |
fd361982 | 9564 | || (bfd_section_flags (sec) & SEC_CODE)) |
95e34ef7 | 9565 | ret->type = 'T'; |
fd361982 | 9566 | else if (bfd_section_flags (sec) & SEC_DATA) |
95e34ef7 | 9567 | ret->type = 'D'; |
fd361982 | 9568 | else if (bfd_section_flags (sec) & SEC_ALLOC) |
95e34ef7 TG |
9569 | ret->type = 'B'; |
9570 | else | |
5369db0a | 9571 | ret->type = '?'; |
95e34ef7 TG |
9572 | |
9573 | if (ret->type != 'U') | |
9574 | ret->value = symbol->value + symbol->section->vma; | |
9575 | else | |
9576 | ret->value = 0; | |
9577 | ret->name = symbol->name; | |
9578 | } | |
9579 | ||
9580 | /* Return TRUE if the given symbol sym in the BFD abfd is | |
9581 | a compiler generated local label, else return FALSE. */ | |
9582 | ||
9583 | static bfd_boolean | |
9584 | vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED, | |
9585 | const char *name) | |
9586 | { | |
95e34ef7 TG |
9587 | return name[0] == '$'; |
9588 | } | |
9589 | \f | |
9590 | /* Part 4.7, writing an object file. */ | |
9591 | ||
9592 | /* Sets the contents of the section section in BFD abfd to the data starting | |
9593 | in memory at LOCATION. The data is written to the output section starting | |
9594 | at offset offset for count bytes. | |
9595 | ||
9596 | Normally TRUE is returned, else FALSE. Possible error returns are: | |
9597 | o bfd_error_no_contents - The output section does not have the | |
9598 | SEC_HAS_CONTENTS attribute, so nothing can be written to it. | |
9599 | o and some more too */ | |
9600 | ||
9601 | static bfd_boolean | |
9602 | _bfd_vms_set_section_contents (bfd * abfd, | |
07d6d2b8 AM |
9603 | asection *section, |
9604 | const void * location, | |
9605 | file_ptr offset, | |
9606 | bfd_size_type count) | |
95e34ef7 TG |
9607 | { |
9608 | if (section->contents == NULL) | |
9609 | { | |
9610 | section->contents = bfd_alloc (abfd, section->size); | |
9611 | if (section->contents == NULL) | |
07d6d2b8 | 9612 | return FALSE; |
95e34ef7 TG |
9613 | |
9614 | memcpy (section->contents + offset, location, (size_t) count); | |
9615 | } | |
9616 | ||
9617 | return TRUE; | |
9618 | } | |
9619 | ||
9620 | /* Set the architecture and machine type in BFD abfd to arch and mach. | |
9621 | Find the correct pointer to a structure and insert it into the arch_info | |
9622 | pointer. */ | |
9623 | ||
9624 | static bfd_boolean | |
9625 | alpha_vms_set_arch_mach (bfd *abfd, | |
07d6d2b8 | 9626 | enum bfd_architecture arch, unsigned long mach) |
95e34ef7 TG |
9627 | { |
9628 | if (arch != bfd_arch_alpha | |
9629 | && arch != bfd_arch_unknown) | |
9630 | return FALSE; | |
9631 | ||
9632 | return bfd_default_set_arch_mach (abfd, arch, mach); | |
9633 | } | |
9634 | ||
9635 | /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */ | |
9636 | ||
9637 | void | |
9638 | bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED, | |
9639 | asection *sec, flagword no_flags, flagword flags) | |
9640 | { | |
9641 | vms_section_data (sec)->no_flags = no_flags; | |
9642 | vms_section_data (sec)->flags = flags; | |
9643 | } | |
9644 | ||
9645 | struct vms_private_data_struct * | |
9646 | bfd_vms_get_data (bfd *abfd) | |
9647 | { | |
9648 | return (struct vms_private_data_struct *)abfd->tdata.any; | |
9649 | } | |
9650 | ||
d00dd7dc | 9651 | #define vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
07d6d2b8 | 9652 | #define vms_bfd_link_just_syms _bfd_generic_link_just_syms |
95e34ef7 TG |
9653 | #define vms_bfd_copy_link_hash_symbol_type \ |
9654 | _bfd_generic_copy_link_hash_symbol_type | |
07d6d2b8 | 9655 | #define vms_bfd_is_group_section bfd_generic_is_group_section |
cb7f4b29 | 9656 | #define vms_bfd_group_name bfd_generic_group_name |
07d6d2b8 AM |
9657 | #define vms_bfd_discard_group bfd_generic_discard_group |
9658 | #define vms_section_already_linked _bfd_generic_section_already_linked | |
9659 | #define vms_bfd_define_common_symbol bfd_generic_define_common_symbol | |
34a87bb0 | 9660 | #define vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol |
68d20676 | 9661 | #define vms_bfd_define_start_stop bfd_generic_define_start_stop |
95e34ef7 TG |
9662 | #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data |
9663 | ||
9664 | #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data | |
9665 | #define vms_bfd_free_cached_info _bfd_generic_bfd_free_cached_info | |
9666 | #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data | |
9667 | #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data | |
07d6d2b8 AM |
9668 | #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags |
9669 | #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data | |
95e34ef7 TG |
9670 | |
9671 | /* Symbols table. */ | |
07d6d2b8 | 9672 | #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol |
d00dd7dc | 9673 | #define alpha_vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
07d6d2b8 AM |
9674 | #define alpha_vms_print_symbol vms_print_symbol |
9675 | #define alpha_vms_get_symbol_info vms_get_symbol_info | |
60bb06bc L |
9676 | #define alpha_vms_get_symbol_version_string \ |
9677 | _bfd_nosymbols_get_symbol_version_string | |
9678 | ||
07d6d2b8 AM |
9679 | #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols |
9680 | #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
9681 | #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno | |
9682 | #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info | |
9683 | #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol | |
9684 | #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_line | |
9685 | #define alpha_vms_find_line _bfd_nosymbols_find_line | |
95e34ef7 TG |
9686 | #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name |
9687 | ||
9688 | /* Generic table. */ | |
9689 | #define alpha_vms_close_and_cleanup vms_close_and_cleanup | |
9690 | #define alpha_vms_bfd_free_cached_info vms_bfd_free_cached_info | |
9691 | #define alpha_vms_new_section_hook vms_new_section_hook | |
9692 | #define alpha_vms_set_section_contents _bfd_vms_set_section_contents | |
9693 | #define alpha_vms_get_section_contents_in_window _bfd_generic_get_section_contents_in_window | |
9694 | ||
9695 | #define alpha_vms_bfd_get_relocated_section_contents \ | |
9696 | bfd_generic_get_relocated_section_contents | |
9697 | ||
9698 | #define alpha_vms_bfd_relax_section bfd_generic_relax_section | |
9699 | #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections | |
ae17ab41 | 9700 | #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags |
95e34ef7 TG |
9701 | #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections |
9702 | #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section | |
cb7f4b29 | 9703 | #define alpha_vms_bfd_group_name bfd_generic_group_name |
95e34ef7 TG |
9704 | #define alpha_vms_bfd_discard_group bfd_generic_discard_group |
9705 | #define alpha_vms_section_already_linked \ | |
9706 | _bfd_generic_section_already_linked | |
9707 | ||
9708 | #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol | |
34a87bb0 | 9709 | #define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol |
7dba9362 | 9710 | #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop |
95e34ef7 TG |
9711 | #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms |
9712 | #define alpha_vms_bfd_copy_link_hash_symbol_type \ | |
9713 | _bfd_generic_copy_link_hash_symbol_type | |
9714 | ||
9715 | #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section | |
9716 | ||
9717 | #define alpha_vms_get_dynamic_symtab_upper_bound \ | |
9718 | _bfd_nodynamic_get_dynamic_symtab_upper_bound | |
9719 | #define alpha_vms_canonicalize_dynamic_symtab \ | |
9720 | _bfd_nodynamic_canonicalize_dynamic_symtab | |
9721 | #define alpha_vms_get_dynamic_reloc_upper_bound \ | |
9722 | _bfd_nodynamic_get_dynamic_reloc_upper_bound | |
9723 | #define alpha_vms_canonicalize_dynamic_reloc \ | |
9724 | _bfd_nodynamic_canonicalize_dynamic_reloc | |
07d6d2b8 | 9725 | #define alpha_vms_bfd_link_check_relocs _bfd_generic_link_check_relocs |
95e34ef7 | 9726 | |
6d00b590 | 9727 | const bfd_target alpha_vms_vec = |
95e34ef7 TG |
9728 | { |
9729 | "vms-alpha", /* Name. */ | |
9730 | bfd_target_evax_flavour, | |
9731 | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ | |
9732 | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ | |
9733 | ||
9734 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | |
9735 | | WP_TEXT | D_PAGED), /* Object flags. */ | |
9736 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
9737 | | SEC_READONLY | SEC_CODE | SEC_DATA | |
9738 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */ | |
9739 | 0, /* symbol_leading_char. */ | |
9740 | ' ', /* ar_pad_char. */ | |
9741 | 15, /* ar_max_namelen. */ | |
0aabe54e | 9742 | 0, /* match priority. */ |
95e34ef7 TG |
9743 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
9744 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
9745 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
9746 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
9747 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
9748 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
9749 | ||
d00dd7dc AM |
9750 | { /* bfd_check_format. */ |
9751 | _bfd_dummy_target, | |
9752 | alpha_vms_object_p, | |
9753 | _bfd_vms_lib_alpha_archive_p, | |
9754 | _bfd_dummy_target | |
9755 | }, | |
9756 | { /* bfd_set_format. */ | |
9757 | _bfd_bool_bfd_false_error, | |
9758 | alpha_vms_mkobject, | |
9759 | _bfd_vms_lib_alpha_mkarchive, | |
9760 | _bfd_bool_bfd_false_error | |
9761 | }, | |
9762 | { /* bfd_write_contents. */ | |
9763 | _bfd_bool_bfd_false_error, | |
9764 | alpha_vms_write_object_contents, | |
9765 | _bfd_vms_lib_write_archive_contents, | |
9766 | _bfd_bool_bfd_false_error | |
9767 | }, | |
95e34ef7 TG |
9768 | |
9769 | BFD_JUMP_TABLE_GENERIC (alpha_vms), | |
9770 | BFD_JUMP_TABLE_COPY (vms), | |
9771 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
9772 | BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib), | |
9773 | BFD_JUMP_TABLE_SYMBOLS (alpha_vms), | |
9774 | BFD_JUMP_TABLE_RELOCS (alpha_vms), | |
9775 | BFD_JUMP_TABLE_WRITE (alpha_vms), | |
9776 | BFD_JUMP_TABLE_LINK (alpha_vms), | |
9777 | BFD_JUMP_TABLE_DYNAMIC (alpha_vms), | |
9778 | ||
9779 | NULL, | |
9780 | ||
8185f55c | 9781 | NULL |
95e34ef7 | 9782 | }; |