]>
Commit | Line | Data |
---|---|---|
95e34ef7 | 1 | /* vms.c -- BFD back-end for EVAX (openVMS/Alpha) files. |
fd67aa11 | 2 | Copyright (C) 1996-2024 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" | |
f8b1e5f6 | 37 | #include <limits.h> |
95e34ef7 TG |
38 | #include "bfd.h" |
39 | #include "bfdlink.h" | |
40 | #include "libbfd.h" | |
41 | #include "bfdver.h" | |
42 | ||
43 | #include "vms.h" | |
44 | #include "vms/eihd.h" | |
45 | #include "vms/eiha.h" | |
46 | #include "vms/eihi.h" | |
47 | #include "vms/eihs.h" | |
48 | #include "vms/eisd.h" | |
49 | #include "vms/dmt.h" | |
50 | #include "vms/dst.h" | |
51 | #include "vms/eihvn.h" | |
52 | #include "vms/eobjrec.h" | |
53 | #include "vms/egsd.h" | |
54 | #include "vms/egps.h" | |
9a1b4480 | 55 | #include "vms/esgps.h" |
95e34ef7 TG |
56 | #include "vms/eeom.h" |
57 | #include "vms/emh.h" | |
58 | #include "vms/eiaf.h" | |
59 | #include "vms/shl.h" | |
60 | #include "vms/eicp.h" | |
61 | #include "vms/etir.h" | |
62 | #include "vms/egsy.h" | |
63 | #include "vms/esdf.h" | |
64 | #include "vms/esdfm.h" | |
65 | #include "vms/esdfv.h" | |
66 | #include "vms/esrf.h" | |
67 | #include "vms/egst.h" | |
9a1b4480 | 68 | #include "vms/eidc.h" |
95e34ef7 TG |
69 | #include "vms/dsc.h" |
70 | #include "vms/prt.h" | |
71 | #include "vms/internal.h" | |
72 | \f | |
73 | ||
74 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
f8b1e5f6 AM |
75 | #ifndef CHAR_BIT |
76 | #define CHAR_BIT 8 | |
77 | #endif | |
95e34ef7 TG |
78 | |
79 | /* The r_type field in a reloc is one of the following values. */ | |
80 | #define ALPHA_R_IGNORE 0 | |
81 | #define ALPHA_R_REFQUAD 1 | |
82 | #define ALPHA_R_BRADDR 2 | |
83 | #define ALPHA_R_HINT 3 | |
84 | #define ALPHA_R_SREL16 4 | |
85 | #define ALPHA_R_SREL32 5 | |
86 | #define ALPHA_R_SREL64 6 | |
87 | #define ALPHA_R_OP_PUSH 7 | |
88 | #define ALPHA_R_OP_STORE 8 | |
89 | #define ALPHA_R_OP_PSUB 9 | |
90 | #define ALPHA_R_OP_PRSHIFT 10 | |
91 | #define ALPHA_R_LINKAGE 11 | |
92 | #define ALPHA_R_REFLONG 12 | |
93 | #define ALPHA_R_CODEADDR 13 | |
94 | #define ALPHA_R_NOP 14 | |
95 | #define ALPHA_R_BSR 15 | |
96 | #define ALPHA_R_LDA 16 | |
97 | #define ALPHA_R_BOH 17 | |
44273c5b | 98 | |
95e34ef7 TG |
99 | /* These are used with DST_S_C_LINE_NUM. */ |
100 | #define DST_S_C_LINE_NUM_HEADER_SIZE 4 | |
101 | ||
102 | /* These are used with DST_S_C_SOURCE */ | |
103 | ||
104 | #define DST_S_B_PCLINE_UNSBYTE 1 | |
105 | #define DST_S_W_PCLINE_UNSWORD 1 | |
106 | #define DST_S_L_PCLINE_UNSLONG 1 | |
107 | ||
108 | #define DST_S_B_MODBEG_NAME 14 | |
109 | #define DST_S_L_RTNBEG_ADDRESS 5 | |
110 | #define DST_S_B_RTNBEG_NAME 13 | |
111 | #define DST_S_L_RTNEND_SIZE 5 | |
112 | ||
113 | /* These are used with DST_S_C_SOURCE. */ | |
114 | #define DST_S_C_SOURCE_HEADER_SIZE 4 | |
115 | ||
116 | #define DST_S_B_SRC_DF_LENGTH 1 | |
117 | #define DST_S_W_SRC_DF_FILEID 3 | |
118 | #define DST_S_B_SRC_DF_FILENAME 20 | |
119 | #define DST_S_B_SRC_UNSBYTE 1 | |
120 | #define DST_S_W_SRC_UNSWORD 1 | |
121 | #define DST_S_L_SRC_UNSLONG 1 | |
122 | ||
123 | /* Debugger symbol definitions. */ | |
124 | ||
07d6d2b8 AM |
125 | #define DBG_S_L_DMT_MODBEG 0 |
126 | #define DBG_S_L_DST_SIZE 4 | |
127 | #define DBG_S_W_DMT_PSECT_COUNT 8 | |
95e34ef7 TG |
128 | #define DBG_S_C_DMT_HEADER_SIZE 12 |
129 | ||
07d6d2b8 | 130 | #define DBG_S_L_DMT_PSECT_START 0 |
95e34ef7 | 131 | #define DBG_S_L_DMT_PSECT_LENGTH 4 |
07d6d2b8 | 132 | #define DBG_S_C_DMT_PSECT_SIZE 8 |
95e34ef7 TG |
133 | |
134 | /* VMS module header. */ | |
135 | ||
136 | struct hdr_struct | |
137 | { | |
138 | char hdr_b_strlvl; | |
139 | int hdr_l_arch1; | |
140 | int hdr_l_arch2; | |
141 | int hdr_l_recsiz; | |
142 | char *hdr_t_name; | |
143 | char *hdr_t_version; | |
144 | char *hdr_t_date; | |
145 | char *hdr_c_lnm; | |
146 | char *hdr_c_src; | |
147 | char *hdr_c_ttl; | |
148 | }; | |
149 | ||
150 | #define EMH_DATE_LENGTH 17 | |
151 | ||
152 | /* VMS End-Of-Module records (EOM/EEOM). */ | |
153 | ||
154 | struct eom_struct | |
155 | { | |
156 | unsigned int eom_l_total_lps; | |
157 | unsigned short eom_w_comcod; | |
0a1b45a2 | 158 | bool eom_has_transfer; |
95e34ef7 TG |
159 | unsigned char eom_b_tfrflg; |
160 | unsigned int eom_l_psindx; | |
161 | unsigned int eom_l_tfradr; | |
162 | }; | |
163 | ||
164 | struct vms_symbol_entry | |
165 | { | |
166 | bfd *owner; | |
167 | ||
168 | /* Common fields. */ | |
169 | unsigned char typ; | |
170 | unsigned char data_type; | |
171 | unsigned short flags; | |
172 | ||
173 | /* Section and offset/value of the symbol. */ | |
95e34ef7 | 174 | unsigned int value; |
a928f1d7 | 175 | asection *section; |
95e34ef7 TG |
176 | |
177 | /* Section and offset/value for the entry point (only for subprg). */ | |
a928f1d7 | 178 | asection *code_section; |
95e34ef7 TG |
179 | unsigned int code_value; |
180 | ||
181 | /* Symbol vector offset. */ | |
182 | unsigned int symbol_vector; | |
183 | ||
184 | /* Length of the name. */ | |
185 | unsigned char namelen; | |
186 | ||
187 | char name[1]; | |
188 | }; | |
189 | ||
190 | /* Stack value for push/pop commands. */ | |
191 | ||
192 | struct stack_struct | |
193 | { | |
194 | bfd_vma value; | |
195 | unsigned int reloc; | |
196 | }; | |
197 | ||
198 | #define STACKSIZE 128 | |
199 | ||
200 | /* A minimal decoding of DST compilation units. We only decode | |
201 | what's needed to get to the line number information. */ | |
202 | ||
203 | struct fileinfo | |
204 | { | |
205 | char *name; | |
206 | unsigned int srec; | |
207 | }; | |
208 | ||
209 | struct srecinfo | |
210 | { | |
211 | struct srecinfo *next; | |
212 | unsigned int line; | |
213 | unsigned int sfile; | |
214 | unsigned int srec; | |
215 | }; | |
216 | ||
217 | struct lineinfo | |
218 | { | |
219 | struct lineinfo *next; | |
220 | bfd_vma address; | |
221 | unsigned int line; | |
222 | }; | |
223 | ||
224 | struct funcinfo | |
225 | { | |
226 | struct funcinfo *next; | |
227 | char *name; | |
228 | bfd_vma low; | |
229 | bfd_vma high; | |
230 | }; | |
231 | ||
232 | struct module | |
233 | { | |
234 | /* Chain the previously read compilation unit. */ | |
235 | struct module *next; | |
236 | ||
237 | /* The module name. */ | |
238 | char *name; | |
239 | ||
240 | /* The start offset and size of debug info in the DST section. */ | |
241 | unsigned int modbeg; | |
242 | unsigned int size; | |
243 | ||
244 | /* The lowest and highest addresses contained in this compilation | |
245 | unit as specified in the compilation unit header. */ | |
246 | bfd_vma low; | |
247 | bfd_vma high; | |
248 | ||
249 | /* The listing line table. */ | |
250 | struct lineinfo *line_table; | |
251 | ||
252 | /* The source record table. */ | |
253 | struct srecinfo *srec_table; | |
254 | ||
255 | /* A list of the functions found in this module. */ | |
256 | struct funcinfo *func_table; | |
257 | ||
258 | /* Current allocation of file_table. */ | |
259 | unsigned int file_table_count; | |
260 | ||
261 | /* An array of the files making up this module. */ | |
262 | struct fileinfo *file_table; | |
263 | }; | |
264 | ||
265 | /* BFD private data for alpha-vms. */ | |
266 | ||
267 | struct vms_private_data_struct | |
268 | { | |
8c8fa33c AM |
269 | /* If 1, relocs have been read successfully, if 0 they have yet to be |
270 | read, if -1 reading relocs failed. */ | |
271 | int reloc_done; | |
95e34ef7 TG |
272 | |
273 | /* Record input buffer. */ | |
274 | struct vms_rec_rd recrd; | |
275 | struct vms_rec_wr recwr; | |
276 | ||
277 | struct hdr_struct hdr_data; /* data from HDR/EMH record */ | |
278 | struct eom_struct eom_data; /* data from EOM/EEOM record */ | |
c734eb83 | 279 | |
46d00b8a TG |
280 | /* Transfer addresses (entry points). */ |
281 | bfd_vma transfer_address[4]; | |
282 | ||
c734eb83 | 283 | /* Array of GSD sections to get the correspond BFD one. */ |
07d6d2b8 | 284 | unsigned int section_max; /* Size of the sections array. */ |
c734eb83 TG |
285 | unsigned int section_count; /* Number of GSD sections. */ |
286 | asection **sections; | |
95e34ef7 TG |
287 | |
288 | /* Array of raw symbols. */ | |
289 | struct vms_symbol_entry **syms; | |
290 | ||
291 | /* Canonicalized symbols. */ | |
292 | asymbol **csymbols; | |
293 | ||
294 | /* Number of symbols. */ | |
295 | unsigned int gsd_sym_count; | |
296 | /* Size of the syms array. */ | |
297 | unsigned int max_sym_count; | |
298 | /* Number of procedure symbols. */ | |
299 | unsigned int norm_sym_count; | |
300 | ||
301 | /* Stack used to evaluate TIR/ETIR commands. */ | |
302 | struct stack_struct *stack; | |
303 | int stackptr; | |
304 | ||
305 | /* Content reading. */ | |
306 | asection *image_section; /* section for image_ptr */ | |
307 | file_ptr image_offset; /* Offset for image_ptr. */ | |
95e34ef7 TG |
308 | |
309 | struct module *modules; /* list of all compilation units */ | |
310 | ||
8185f55c | 311 | /* The DST section. */ |
95e34ef7 TG |
312 | asection *dst_section; |
313 | ||
314 | unsigned int dst_ptr_offsets_count; /* # of offsets in following array */ | |
315 | unsigned int *dst_ptr_offsets; /* array of saved image_ptr offsets */ | |
316 | ||
317 | /* Shared library support */ | |
318 | bfd_vma symvva; /* relative virtual address of symbol vector */ | |
319 | unsigned int ident; | |
320 | unsigned char matchctl; | |
321 | ||
322 | /* Shared library index. This is used for input bfd while linking. */ | |
323 | unsigned int shr_index; | |
324 | ||
325 | /* Used to place structures in the file. */ | |
326 | file_ptr file_pos; | |
327 | ||
328 | /* Simply linked list of eisd. */ | |
329 | struct vms_internal_eisd_map *eisd_head; | |
330 | struct vms_internal_eisd_map *eisd_tail; | |
331 | ||
332 | /* Simply linked list of eisd for shared libraries. */ | |
333 | struct vms_internal_eisd_map *gbl_eisd_head; | |
334 | struct vms_internal_eisd_map *gbl_eisd_tail; | |
335 | ||
336 | /* linkage index counter used by conditional store commands */ | |
25d41743 | 337 | unsigned int vms_linkage_index; |
95e34ef7 TG |
338 | }; |
339 | ||
340 | #define PRIV2(abfd, name) \ | |
341 | (((struct vms_private_data_struct *)(abfd)->tdata.any)->name) | |
342 | #define PRIV(name) PRIV2(abfd,name) | |
343 | ||
344 | ||
345 | /* Used to keep extra VMS specific information for a given section. | |
346 | ||
347 | reloc_size holds the size of the relocation stream, note this | |
348 | is very different from the number of relocations as VMS relocations | |
349 | are variable length. | |
350 | ||
351 | reloc_stream is the actual stream of relocation entries. */ | |
352 | ||
353 | struct vms_section_data_struct | |
354 | { | |
355 | /* Maximnum number of entries in sec->relocation. */ | |
356 | unsigned reloc_max; | |
357 | ||
358 | /* Corresponding eisd. Used only while generating executables. */ | |
359 | struct vms_internal_eisd_map *eisd; | |
360 | ||
361 | /* PSC flags to be clear. */ | |
362 | flagword no_flags; | |
363 | ||
364 | /* PSC flags to be set. */ | |
365 | flagword flags; | |
366 | }; | |
367 | ||
368 | #define vms_section_data(sec) \ | |
369 | ((struct vms_section_data_struct *)sec->used_by_bfd) | |
370 | ||
371 | /* To be called from the debugger. */ | |
0a9d414a | 372 | struct vms_private_data_struct *bfd_vms_get_data (bfd *); |
95e34ef7 | 373 | |
0a9d414a | 374 | static int vms_get_remaining_object_record (bfd *, unsigned int); |
0a1b45a2 AM |
375 | static bool _bfd_vms_slurp_object_records (bfd * abfd); |
376 | static bool alpha_vms_add_fixup_lp (struct bfd_link_info *, bfd *, bfd *); | |
377 | static bool alpha_vms_add_fixup_ca (struct bfd_link_info *, bfd *, bfd *); | |
378 | static bool alpha_vms_add_fixup_qr (struct bfd_link_info *, bfd *, bfd *, | |
379 | bfd_vma); | |
380 | static bool alpha_vms_add_fixup_lr (struct bfd_link_info *, unsigned int, | |
381 | bfd_vma); | |
382 | static bool alpha_vms_add_lw_reloc (struct bfd_link_info *); | |
383 | static bool alpha_vms_add_qw_reloc (struct bfd_link_info *); | |
95e34ef7 TG |
384 | |
385 | struct vector_type | |
386 | { | |
387 | unsigned int max_el; | |
388 | unsigned int nbr_el; | |
389 | void *els; | |
390 | }; | |
391 | ||
392 | /* Number of elements in VEC. */ | |
393 | ||
394 | #define VEC_COUNT(VEC) ((VEC).nbr_el) | |
395 | ||
396 | /* Get the address of the Nth element. */ | |
397 | ||
398 | #define VEC_EL(VEC, TYPE, N) (((TYPE *)((VEC).els))[N]) | |
399 | ||
07d6d2b8 AM |
400 | #define VEC_INIT(VEC) \ |
401 | do { \ | |
402 | (VEC).max_el = 0; \ | |
403 | (VEC).nbr_el = 0; \ | |
404 | (VEC).els = NULL; \ | |
95e34ef7 TG |
405 | } while (0) |
406 | ||
407 | /* Be sure there is room for a new element. */ | |
408 | ||
96d3b80f | 409 | static void *vector_grow1 (struct vector_type *vec, size_t elsz); |
95e34ef7 TG |
410 | |
411 | /* Allocate room for a new element and return its address. */ | |
412 | ||
07d6d2b8 | 413 | #define VEC_APPEND(VEC, TYPE) \ |
96d3b80f | 414 | ((TYPE *) vector_grow1 (&VEC, sizeof (TYPE))) |
95e34ef7 TG |
415 | |
416 | struct alpha_vms_vma_ref | |
417 | { | |
418 | bfd_vma vma; /* Vma in the output. */ | |
419 | bfd_vma ref; /* Reference in the input. */ | |
420 | }; | |
421 | ||
422 | struct alpha_vms_shlib_el | |
423 | { | |
424 | bfd *abfd; | |
0a1b45a2 | 425 | bool has_fixups; |
95e34ef7 TG |
426 | |
427 | struct vector_type lp; /* Vector of bfd_vma. */ | |
428 | struct vector_type ca; /* Vector of bfd_vma. */ | |
429 | struct vector_type qr; /* Vector of struct alpha_vms_vma_ref. */ | |
430 | }; | |
431 | ||
432 | /* Alpha VMS linker hash table. */ | |
433 | ||
434 | struct alpha_vms_link_hash_table | |
435 | { | |
436 | struct bfd_link_hash_table root; | |
437 | ||
cc643b88 | 438 | /* Vector of shared libraries. */ |
95e34ef7 TG |
439 | struct vector_type shrlibs; |
440 | ||
441 | /* Fixup section. */ | |
442 | asection *fixup; | |
443 | ||
444 | /* Base address. Used by fixups. */ | |
445 | bfd_vma base_addr; | |
446 | }; | |
447 | ||
448 | #define alpha_vms_link_hash(INFO) \ | |
449 | ((struct alpha_vms_link_hash_table *)(INFO->hash)) | |
450 | ||
451 | /* Alpha VMS linker hash table entry. */ | |
452 | ||
453 | struct alpha_vms_link_hash_entry | |
454 | { | |
455 | struct bfd_link_hash_entry root; | |
456 | ||
457 | /* Pointer to the original vms symbol. */ | |
458 | struct vms_symbol_entry *sym; | |
459 | }; | |
460 | \f | |
461 | /* Image reading. */ | |
462 | ||
463 | /* Read & process EIHD record. | |
464 | Return TRUE on success, FALSE on error. */ | |
465 | ||
0a1b45a2 | 466 | static bool |
95e34ef7 | 467 | _bfd_vms_slurp_eihd (bfd *abfd, unsigned int *eisd_offset, |
07d6d2b8 | 468 | unsigned int *eihs_offset) |
95e34ef7 TG |
469 | { |
470 | unsigned int imgtype, size; | |
471 | bfd_vma symvva; | |
472 | struct vms_eihd *eihd = (struct vms_eihd *)PRIV (recrd.rec); | |
473 | ||
474 | vms_debug2 ((8, "_bfd_vms_slurp_eihd\n")); | |
475 | ||
ca4cf9b9 NC |
476 | /* PR 21813: Check for an undersized record. */ |
477 | if (PRIV (recrd.buf_size) < sizeof (* eihd)) | |
478 | { | |
38f14ab8 | 479 | _bfd_error_handler (_("corrupt EIHD record - size is too small")); |
ca4cf9b9 | 480 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 481 | return false; |
ca4cf9b9 NC |
482 | } |
483 | ||
95e34ef7 TG |
484 | size = bfd_getl32 (eihd->size); |
485 | imgtype = bfd_getl32 (eihd->imgtype); | |
486 | ||
487 | if (imgtype == EIHD__K_EXE || imgtype == EIHD__K_LIM) | |
488 | abfd->flags |= EXEC_P; | |
489 | ||
490 | symvva = bfd_getl64 (eihd->symvva); | |
491 | if (symvva != 0) | |
492 | { | |
493 | PRIV (symvva) = symvva; | |
494 | abfd->flags |= DYNAMIC; | |
495 | } | |
496 | ||
497 | PRIV (ident) = bfd_getl32 (eihd->ident); | |
498 | PRIV (matchctl) = eihd->matchctl; | |
499 | ||
500 | *eisd_offset = bfd_getl32 (eihd->isdoff); | |
501 | *eihs_offset = bfd_getl32 (eihd->symdbgoff); | |
502 | ||
503 | vms_debug2 ((4, "EIHD size %d imgtype %d symvva 0x%lx eisd %d eihs %d\n", | |
07d6d2b8 AM |
504 | size, imgtype, (unsigned long)symvva, |
505 | *eisd_offset, *eihs_offset)); | |
8ab484c2 | 506 | (void) size; |
95e34ef7 | 507 | |
0a1b45a2 | 508 | return true; |
95e34ef7 TG |
509 | } |
510 | ||
511 | /* Read & process EISD record. | |
512 | Return TRUE on success, FALSE on error. */ | |
513 | ||
0a1b45a2 | 514 | static bool |
95e34ef7 TG |
515 | _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset) |
516 | { | |
517 | int section_count = 0; | |
518 | ||
519 | vms_debug2 ((8, "_bfd_vms_slurp_eisd\n")); | |
520 | ||
521 | while (1) | |
522 | { | |
523 | struct vms_eisd *eisd; | |
524 | unsigned int rec_size; | |
525 | unsigned int size; | |
0e3c1eeb | 526 | uint64_t vaddr; |
95e34ef7 TG |
527 | unsigned int flags; |
528 | unsigned int vbn; | |
529 | char *name = NULL; | |
530 | asection *section; | |
531 | flagword bfd_flags; | |
532 | ||
bf31e604 AM |
533 | /* PR 17512: file: 3d9e9fe9. */ |
534 | if (offset > PRIV (recrd.rec_size) | |
535 | || (PRIV (recrd.rec_size) - offset | |
536 | < offsetof (struct vms_eisd, eisdsize) + 4)) | |
0a1b45a2 | 537 | return false; |
bf31e604 | 538 | eisd = (struct vms_eisd *) (PRIV (recrd.rec) + offset); |
95e34ef7 | 539 | rec_size = bfd_getl32 (eisd->eisdsize); |
95e34ef7 | 540 | if (rec_size == 0) |
07d6d2b8 | 541 | break; |
95e34ef7 TG |
542 | |
543 | /* Skip to next block if pad. */ | |
544 | if (rec_size == 0xffffffff) | |
07d6d2b8 AM |
545 | { |
546 | offset = (offset + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); | |
547 | continue; | |
548 | } | |
7adc0a81 NC |
549 | |
550 | /* Make sure that there is enough data present in the record. */ | |
bf31e604 | 551 | if (rec_size < offsetof (struct vms_eisd, type) + 1) |
0a1b45a2 | 552 | return false; |
7adc0a81 | 553 | /* Make sure that the record is not too big either. */ |
bf31e604 | 554 | if (rec_size > PRIV (recrd.rec_size) - offset) |
0a1b45a2 | 555 | return false; |
7adc0a81 NC |
556 | |
557 | offset += rec_size; | |
95e34ef7 TG |
558 | |
559 | size = bfd_getl32 (eisd->secsize); | |
560 | vaddr = bfd_getl64 (eisd->virt_addr); | |
561 | flags = bfd_getl32 (eisd->flags); | |
562 | vbn = bfd_getl32 (eisd->vbn); | |
563 | ||
564 | vms_debug2 ((4, "EISD at 0x%x size 0x%x addr 0x%lx flags 0x%x blk %d\n", | |
07d6d2b8 | 565 | offset, size, (unsigned long)vaddr, flags, vbn)); |
95e34ef7 TG |
566 | |
567 | /* VMS combines psects from .obj files into isects in the .exe. This | |
568 | process doesn't preserve enough information to reliably determine | |
569 | what's in each section without examining the data. This is | |
570 | especially true of DWARF debug sections. */ | |
571 | bfd_flags = SEC_ALLOC; | |
c068d5be | 572 | if (vbn != 0) |
07d6d2b8 | 573 | bfd_flags |= SEC_HAS_CONTENTS | SEC_LOAD; |
95e34ef7 TG |
574 | |
575 | if (flags & EISD__M_EXE) | |
c068d5be | 576 | bfd_flags |= SEC_CODE; |
95e34ef7 TG |
577 | |
578 | if (flags & EISD__M_NONSHRADR) | |
c068d5be | 579 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
580 | |
581 | if (!(flags & EISD__M_WRT)) | |
582 | bfd_flags |= SEC_READONLY; | |
583 | ||
584 | if (flags & EISD__M_DZRO) | |
585 | bfd_flags |= SEC_DATA; | |
586 | ||
587 | if (flags & EISD__M_FIXUPVEC) | |
c068d5be | 588 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
589 | |
590 | if (flags & EISD__M_CRF) | |
c068d5be | 591 | bfd_flags |= SEC_DATA; |
95e34ef7 TG |
592 | |
593 | if (flags & EISD__M_GBL) | |
594 | { | |
bf31e604 | 595 | if (rec_size <= offsetof (struct vms_eisd, gblnam)) |
0a1b45a2 | 596 | return false; |
7adc0a81 | 597 | else if (rec_size < sizeof (struct vms_eisd)) |
37d2e9c7 | 598 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
7adc0a81 NC |
599 | rec_size - offsetof (struct vms_eisd, gblnam)); |
600 | else | |
37d2e9c7 AM |
601 | name = _bfd_vms_save_counted_string (abfd, eisd->gblnam, |
602 | EISD__K_GBLNAMLEN); | |
bf31e604 | 603 | if (name == NULL || name[0] == 0) |
0a1b45a2 | 604 | return false; |
95e34ef7 TG |
605 | bfd_flags |= SEC_COFF_SHARED_LIBRARY; |
606 | bfd_flags &= ~(SEC_ALLOC | SEC_LOAD); | |
607 | } | |
608 | else if (flags & EISD__M_FIXUPVEC) | |
07d6d2b8 | 609 | name = "$FIXUPVEC$"; |
95e34ef7 | 610 | else if (eisd->type == EISD__K_USRSTACK) |
07d6d2b8 | 611 | name = "$STACK$"; |
95e34ef7 TG |
612 | else |
613 | { | |
07d6d2b8 | 614 | const char *pfx; |
95e34ef7 | 615 | |
37d2e9c7 AM |
616 | name = (char *) bfd_alloc (abfd, 32); |
617 | if (name == NULL) | |
0a1b45a2 | 618 | return false; |
07d6d2b8 AM |
619 | if (flags & EISD__M_DZRO) |
620 | pfx = "BSS"; | |
621 | else if (flags & EISD__M_EXE) | |
622 | pfx = "CODE"; | |
623 | else if (!(flags & EISD__M_WRT)) | |
624 | pfx = "RO"; | |
625 | else | |
626 | pfx = "LOCAL"; | |
627 | BFD_ASSERT (section_count < 999); | |
95e34ef7 TG |
628 | sprintf (name, "$%s_%03d$", pfx, section_count++); |
629 | } | |
630 | ||
631 | section = bfd_make_section (abfd, name); | |
632 | ||
633 | if (!section) | |
0a1b45a2 | 634 | return false; |
95e34ef7 TG |
635 | |
636 | section->filepos = vbn ? VMS_BLOCK_SIZE * (vbn - 1) : 0; | |
637 | section->size = size; | |
638 | section->vma = vaddr; | |
639 | ||
fd361982 | 640 | if (!bfd_set_section_flags (section, bfd_flags)) |
0a1b45a2 | 641 | return false; |
95e34ef7 TG |
642 | } |
643 | ||
0a1b45a2 | 644 | return true; |
95e34ef7 TG |
645 | } |
646 | ||
647 | /* Read & process EIHS record. | |
648 | Return TRUE on success, FALSE on error. */ | |
649 | ||
0a1b45a2 | 650 | static bool |
95e34ef7 TG |
651 | _bfd_vms_slurp_eihs (bfd *abfd, unsigned int offset) |
652 | { | |
653 | unsigned char *p = PRIV (recrd.rec) + offset; | |
80053e46 NC |
654 | unsigned int gstvbn; |
655 | unsigned int gstsize ATTRIBUTE_UNUSED; | |
656 | unsigned int dstvbn; | |
657 | unsigned int dstsize; | |
658 | unsigned int dmtvbn; | |
659 | unsigned int dmtbytes; | |
95e34ef7 TG |
660 | asection *section; |
661 | ||
80053e46 NC |
662 | /* PR 21611: Check that offset is valid. */ |
663 | if (offset > PRIV (recrd.rec_size) - (EIHS__L_DMTBYTES + 4)) | |
664 | { | |
38f14ab8 AM |
665 | _bfd_error_handler (_("unable to read EIHS record at offset %#x"), |
666 | offset); | |
80053e46 | 667 | bfd_set_error (bfd_error_file_truncated); |
0a1b45a2 | 668 | return false; |
80053e46 NC |
669 | } |
670 | ||
671 | gstvbn = bfd_getl32 (p + EIHS__L_GSTVBN); | |
672 | gstsize = bfd_getl32 (p + EIHS__L_GSTSIZE); | |
673 | dstvbn = bfd_getl32 (p + EIHS__L_DSTVBN); | |
674 | dstsize = bfd_getl32 (p + EIHS__L_DSTSIZE); | |
675 | dmtvbn = bfd_getl32 (p + EIHS__L_DMTVBN); | |
676 | dmtbytes = bfd_getl32 (p + EIHS__L_DMTBYTES); | |
677 | ||
95e34ef7 TG |
678 | #if VMS_DEBUG |
679 | vms_debug (8, "_bfd_vms_slurp_ihs\n"); | |
680 | vms_debug (4, "EIHS record gstvbn %d gstsize %d dstvbn %d dstsize %d dmtvbn %d dmtbytes %d\n", | |
681 | gstvbn, gstsize, dstvbn, dstsize, dmtvbn, dmtbytes); | |
682 | #endif | |
683 | ||
684 | if (dstvbn) | |
685 | { | |
686 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; | |
687 | ||
688 | section = bfd_make_section (abfd, "$DST$"); | |
689 | if (!section) | |
0a1b45a2 | 690 | return false; |
95e34ef7 TG |
691 | |
692 | section->size = dstsize; | |
693 | section->filepos = VMS_BLOCK_SIZE * (dstvbn - 1); | |
694 | ||
fd361982 | 695 | if (!bfd_set_section_flags (section, bfd_flags)) |
0a1b45a2 | 696 | return false; |
95e34ef7 TG |
697 | |
698 | PRIV (dst_section) = section; | |
699 | abfd->flags |= (HAS_DEBUG | HAS_LINENO); | |
700 | } | |
701 | ||
702 | if (dmtvbn) | |
703 | { | |
704 | flagword bfd_flags = SEC_HAS_CONTENTS | SEC_DEBUGGING; | |
705 | ||
706 | section = bfd_make_section (abfd, "$DMT$"); | |
707 | if (!section) | |
0a1b45a2 | 708 | return false; |
95e34ef7 TG |
709 | |
710 | section->size = dmtbytes; | |
711 | section->filepos = VMS_BLOCK_SIZE * (dmtvbn - 1); | |
712 | ||
fd361982 | 713 | if (!bfd_set_section_flags (section, bfd_flags)) |
0a1b45a2 | 714 | return false; |
95e34ef7 TG |
715 | } |
716 | ||
717 | if (gstvbn) | |
718 | { | |
95e34ef7 TG |
719 | if (bfd_seek (abfd, VMS_BLOCK_SIZE * (gstvbn - 1), SEEK_SET)) |
720 | { | |
721 | bfd_set_error (bfd_error_file_truncated); | |
0a1b45a2 | 722 | return false; |
95e34ef7 TG |
723 | } |
724 | ||
535b785f | 725 | if (!_bfd_vms_slurp_object_records (abfd)) |
0a1b45a2 | 726 | return false; |
95e34ef7 | 727 | |
95e34ef7 TG |
728 | abfd->flags |= HAS_SYMS; |
729 | } | |
730 | ||
0a1b45a2 | 731 | return true; |
95e34ef7 TG |
732 | } |
733 | \f | |
734 | /* Object file reading. */ | |
735 | ||
736 | /* Object file input functions. */ | |
737 | ||
738 | /* Get next record from object file to vms_buf. | |
739 | Set PRIV(buf_size) and return it | |
740 | ||
741 | This is a little tricky since it should be portable. | |
742 | ||
743 | The openVMS object file has 'variable length' which means that | |
744 | read() returns data in chunks of (hopefully) correct and expected | |
745 | size. The linker (and other tools on VMS) depend on that. Unix | |
746 | doesn't know about 'formatted' files, so reading and writing such | |
747 | an object file in a Unix environment is not trivial. | |
748 | ||
749 | With the tool 'file' (available on all VMS FTP sites), one | |
750 | can view and change the attributes of a file. Changing from | |
751 | 'variable length' to 'fixed length, 512 bytes' reveals the | |
752 | record size at the first 2 bytes of every record. The same | |
753 | may happen during the transfer of object files from VMS to Unix, | |
754 | at least with UCX, the DEC implementation of TCP/IP. | |
755 | ||
756 | The VMS format repeats the size at bytes 2 & 3 of every record. | |
757 | ||
758 | On the first call (file_format == FF_UNKNOWN) we check if | |
759 | the first and the third byte pair (!) of the record match. | |
760 | If they do it's an object file in an Unix environment or with | |
761 | wrong attributes (FF_FOREIGN), else we should be in a VMS | |
762 | environment where read() returns the record size (FF_NATIVE). | |
763 | ||
764 | Reading is always done in 2 steps: | |
765 | 1. first just the record header is read and the size extracted, | |
766 | 2. then the read buffer is adjusted and the remaining bytes are | |
767 | read in. | |
768 | ||
769 | All file I/O is done on even file positions. */ | |
770 | ||
771 | #define VMS_OBJECT_ADJUSTMENT 2 | |
772 | ||
773 | static void | |
774 | maybe_adjust_record_pointer_for_object (bfd *abfd) | |
775 | { | |
776 | /* Set the file format once for all on the first invocation. */ | |
777 | if (PRIV (recrd.file_format) == FF_UNKNOWN) | |
778 | { | |
779 | if (PRIV (recrd.rec)[0] == PRIV (recrd.rec)[4] | |
780 | && PRIV (recrd.rec)[1] == PRIV (recrd.rec)[5]) | |
781 | PRIV (recrd.file_format) = FF_FOREIGN; | |
782 | else | |
783 | PRIV (recrd.file_format) = FF_NATIVE; | |
784 | } | |
785 | ||
786 | /* The adjustment is needed only in an Unix environment. */ | |
787 | if (PRIV (recrd.file_format) == FF_FOREIGN) | |
788 | PRIV (recrd.rec) += VMS_OBJECT_ADJUSTMENT; | |
789 | } | |
790 | ||
791 | /* Implement step #1 of the object record reading procedure. | |
792 | Return the record type or -1 on failure. */ | |
793 | ||
794 | static int | |
795 | _bfd_vms_get_object_record (bfd *abfd) | |
796 | { | |
ddfb684a | 797 | unsigned int test_len = 6; |
95e34ef7 | 798 | int type; |
95e34ef7 TG |
799 | |
800 | vms_debug2 ((8, "_bfd_vms_get_obj_record\n")); | |
801 | ||
ddfb684a | 802 | /* Skip alignment byte if the current position is odd. */ |
af47dcbf | 803 | if (PRIV (recrd.file_format) == FF_FOREIGN && (bfd_tell (abfd) & 1)) |
95e34ef7 | 804 | { |
226f9f4f | 805 | if (bfd_read (PRIV (recrd.buf), 1, abfd) != 1) |
07d6d2b8 AM |
806 | { |
807 | bfd_set_error (bfd_error_file_truncated); | |
808 | return -1; | |
809 | } | |
95e34ef7 TG |
810 | } |
811 | ||
812 | /* Read the record header */ | |
226f9f4f | 813 | if (bfd_read (PRIV (recrd.buf), test_len, abfd) != test_len) |
95e34ef7 TG |
814 | { |
815 | bfd_set_error (bfd_error_file_truncated); | |
816 | return -1; | |
817 | } | |
818 | ||
819 | /* Reset the record pointer. */ | |
820 | PRIV (recrd.rec) = PRIV (recrd.buf); | |
821 | maybe_adjust_record_pointer_for_object (abfd); | |
822 | ||
823 | if (vms_get_remaining_object_record (abfd, test_len) <= 0) | |
824 | return -1; | |
825 | ||
826 | type = bfd_getl16 (PRIV (recrd.rec)); | |
827 | ||
828 | vms_debug2 ((8, "_bfd_vms_get_obj_record: rec %p, size %d, type %d\n", | |
07d6d2b8 | 829 | PRIV (recrd.rec), PRIV (recrd.rec_size), type)); |
95e34ef7 TG |
830 | |
831 | return type; | |
832 | } | |
833 | ||
834 | /* Implement step #2 of the object record reading procedure. | |
835 | Return the size of the record or 0 on failure. */ | |
836 | ||
837 | static int | |
0a9d414a | 838 | vms_get_remaining_object_record (bfd *abfd, unsigned int read_so_far) |
95e34ef7 TG |
839 | { |
840 | unsigned int to_read; | |
841 | ||
842 | vms_debug2 ((8, "vms_get_remaining_obj_record\n")); | |
843 | ||
844 | /* Extract record size. */ | |
845 | PRIV (recrd.rec_size) = bfd_getl16 (PRIV (recrd.rec) + 2); | |
846 | ||
083faca9 | 847 | if (PRIV (recrd.rec_size) == 0) |
95e34ef7 TG |
848 | { |
849 | bfd_set_error (bfd_error_file_truncated); | |
850 | return 0; | |
851 | } | |
852 | ||
853 | /* That's what the linker manual says. */ | |
854 | if (PRIV (recrd.rec_size) > EOBJ__C_MAXRECSIZ) | |
855 | { | |
856 | bfd_set_error (bfd_error_file_truncated); | |
857 | return 0; | |
858 | } | |
859 | ||
860 | /* Take into account object adjustment. */ | |
861 | to_read = PRIV (recrd.rec_size); | |
862 | if (PRIV (recrd.file_format) == FF_FOREIGN) | |
863 | to_read += VMS_OBJECT_ADJUSTMENT; | |
864 | ||
865 | /* Adjust the buffer. */ | |
866 | if (to_read > PRIV (recrd.buf_size)) | |
867 | { | |
868 | PRIV (recrd.buf) | |
9cb56943 | 869 | = (unsigned char *) bfd_realloc_or_free (PRIV (recrd.buf), to_read); |
95e34ef7 | 870 | if (PRIV (recrd.buf) == NULL) |
07d6d2b8 | 871 | return 0; |
95e34ef7 TG |
872 | PRIV (recrd.buf_size) = to_read; |
873 | } | |
0a9d414a NC |
874 | /* PR 17512: file: 025-1974-0.004. */ |
875 | else if (to_read <= read_so_far) | |
876 | return 0; | |
1b786873 | 877 | |
95e34ef7 TG |
878 | /* Read the remaining record. */ |
879 | to_read -= read_so_far; | |
880 | ||
881 | vms_debug2 ((8, "vms_get_remaining_obj_record: to_read %d\n", to_read)); | |
882 | ||
226f9f4f | 883 | if (bfd_read (PRIV (recrd.buf) + read_so_far, to_read, abfd) != to_read) |
95e34ef7 TG |
884 | { |
885 | bfd_set_error (bfd_error_file_truncated); | |
886 | return 0; | |
887 | } | |
888 | ||
889 | /* Reset the record pointer. */ | |
890 | PRIV (recrd.rec) = PRIV (recrd.buf); | |
891 | maybe_adjust_record_pointer_for_object (abfd); | |
892 | ||
893 | vms_debug2 ((8, "vms_get_remaining_obj_record: size %d\n", | |
07d6d2b8 | 894 | PRIV (recrd.rec_size))); |
95e34ef7 TG |
895 | |
896 | return PRIV (recrd.rec_size); | |
897 | } | |
898 | ||
899 | /* Read and process emh record. | |
900 | Return TRUE on success, FALSE on error. */ | |
901 | ||
0a1b45a2 | 902 | static bool |
95e34ef7 TG |
903 | _bfd_vms_slurp_ehdr (bfd *abfd) |
904 | { | |
905 | unsigned char *ptr; | |
906 | unsigned char *vms_rec; | |
4e5cb37e | 907 | unsigned char *end; |
95e34ef7 TG |
908 | int subtype; |
909 | ||
910 | vms_rec = PRIV (recrd.rec); | |
4e5cb37e | 911 | /* PR 17512: file: 62736583. */ |
8bdf0be1 | 912 | end = PRIV (recrd.buf) + PRIV (recrd.buf_size); |
95e34ef7 TG |
913 | |
914 | vms_debug2 ((2, "HDR/EMH\n")); | |
915 | ||
916 | subtype = bfd_getl16 (vms_rec + 4); | |
917 | ||
918 | vms_debug2 ((3, "subtype %d\n", subtype)); | |
919 | ||
920 | switch (subtype) | |
921 | { | |
922 | case EMH__C_MHD: | |
923 | /* Module header. */ | |
4e5cb37e NC |
924 | if (vms_rec + 21 >= end) |
925 | goto fail; | |
95e34ef7 TG |
926 | PRIV (hdr_data).hdr_b_strlvl = vms_rec[6]; |
927 | PRIV (hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8); | |
928 | PRIV (hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12); | |
929 | PRIV (hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16); | |
4e5cb37e NC |
930 | if ((vms_rec + 20 + vms_rec[20] + 1) >= end) |
931 | goto fail; | |
37d2e9c7 AM |
932 | PRIV (hdr_data).hdr_t_name |
933 | = _bfd_vms_save_counted_string (abfd, vms_rec + 20, vms_rec[20]); | |
95e34ef7 | 934 | ptr = vms_rec + 20 + vms_rec[20] + 1; |
4e5cb37e NC |
935 | if ((ptr + *ptr + 1) >= end) |
936 | goto fail; | |
37d2e9c7 AM |
937 | PRIV (hdr_data).hdr_t_version |
938 | = _bfd_vms_save_counted_string (abfd, ptr, *ptr); | |
95e34ef7 | 939 | ptr += *ptr + 1; |
4e5cb37e NC |
940 | if (ptr + 17 >= end) |
941 | goto fail; | |
37d2e9c7 AM |
942 | PRIV (hdr_data).hdr_t_date |
943 | = _bfd_vms_save_sized_string (abfd, ptr, 17); | |
95e34ef7 TG |
944 | break; |
945 | ||
946 | case EMH__C_LNM: | |
4e5cb37e NC |
947 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
948 | goto fail; | |
37d2e9c7 AM |
949 | PRIV (hdr_data).hdr_c_lnm |
950 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
951 | break; |
952 | ||
953 | case EMH__C_SRC: | |
4e5cb37e NC |
954 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
955 | goto fail; | |
37d2e9c7 AM |
956 | PRIV (hdr_data).hdr_c_src |
957 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
958 | break; |
959 | ||
960 | case EMH__C_TTL: | |
4e5cb37e NC |
961 | if (vms_rec + PRIV (recrd.rec_size - 6) > end) |
962 | goto fail; | |
37d2e9c7 AM |
963 | PRIV (hdr_data).hdr_c_ttl |
964 | = _bfd_vms_save_sized_string (abfd, vms_rec, PRIV (recrd.rec_size - 6)); | |
95e34ef7 TG |
965 | break; |
966 | ||
967 | case EMH__C_CPR: | |
968 | case EMH__C_MTC: | |
969 | case EMH__C_GTX: | |
970 | break; | |
971 | ||
972 | default: | |
4e5cb37e | 973 | fail: |
95e34ef7 | 974 | bfd_set_error (bfd_error_wrong_format); |
0a1b45a2 | 975 | return false; |
95e34ef7 TG |
976 | } |
977 | ||
0a1b45a2 | 978 | return true; |
95e34ef7 TG |
979 | } |
980 | ||
981 | /* Typical sections for evax object files. */ | |
982 | ||
983 | #define EVAX_ABS_NAME "$ABS$" | |
984 | #define EVAX_CODE_NAME "$CODE$" | |
985 | #define EVAX_LINK_NAME "$LINK$" | |
986 | #define EVAX_DATA_NAME "$DATA$" | |
987 | #define EVAX_BSS_NAME "$BSS$" | |
988 | #define EVAX_READONLYADDR_NAME "$READONLY_ADDR$" | |
989 | #define EVAX_READONLY_NAME "$READONLY$" | |
990 | #define EVAX_LITERAL_NAME "$LITERAL$" | |
991 | #define EVAX_LITERALS_NAME "$LITERALS" | |
992 | #define EVAX_COMMON_NAME "$COMMON$" | |
993 | #define EVAX_LOCAL_NAME "$LOCAL$" | |
994 | ||
995 | struct sec_flags_struct | |
996 | { | |
997 | const char *name; /* Name of section. */ | |
998 | int vflags_always; | |
999 | flagword flags_always; /* Flags we set always. */ | |
1000 | int vflags_hassize; | |
1001 | flagword flags_hassize; /* Flags we set if the section has a size > 0. */ | |
1002 | }; | |
1003 | ||
1004 | /* These flags are deccrtl/vaxcrtl (openVMS 6.2 Alpha) compatible. */ | |
1005 | ||
81bb31c0 | 1006 | static const struct sec_flags_struct evax_section_flags[] = |
95e34ef7 TG |
1007 | { |
1008 | { EVAX_ABS_NAME, | |
d833fa0d TG |
1009 | EGPS__V_SHR, |
1010 | 0, | |
1011 | EGPS__V_SHR, | |
1012 | 0 }, | |
95e34ef7 | 1013 | { EVAX_CODE_NAME, |
d833fa0d | 1014 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
cf6b8767 | 1015 | SEC_CODE | SEC_READONLY, |
d833fa0d | 1016 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_EXE, |
cf6b8767 | 1017 | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1018 | { EVAX_LITERAL_NAME, |
d833fa0d TG |
1019 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1020 | SEC_DATA | SEC_READONLY, | |
1021 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, | |
cf6b8767 | 1022 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1023 | { EVAX_LINK_NAME, |
d833fa0d TG |
1024 | EGPS__V_REL | EGPS__V_RD, |
1025 | SEC_DATA | SEC_READONLY, | |
1026 | EGPS__V_REL | EGPS__V_RD, | |
cf6b8767 | 1027 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1028 | { EVAX_DATA_NAME, |
d833fa0d TG |
1029 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1030 | SEC_DATA, | |
1031 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
1032 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, | |
95e34ef7 | 1033 | { EVAX_BSS_NAME, |
d833fa0d TG |
1034 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, |
1035 | SEC_NO_FLAGS, | |
1036 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT | EGPS__V_NOMOD, | |
1037 | SEC_ALLOC }, | |
95e34ef7 | 1038 | { EVAX_READONLYADDR_NAME, |
d833fa0d TG |
1039 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, |
1040 | SEC_DATA | SEC_READONLY, | |
1041 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_RD, | |
cf6b8767 | 1042 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1043 | { EVAX_READONLY_NAME, |
d833fa0d TG |
1044 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD | EGPS__V_NOMOD, |
1045 | SEC_DATA | SEC_READONLY, | |
1046 | EGPS__V_PIC | EGPS__V_REL | EGPS__V_SHR | EGPS__V_RD, | |
cf6b8767 | 1047 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1048 | { EVAX_LOCAL_NAME, |
d833fa0d TG |
1049 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1050 | SEC_DATA, | |
1051 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
1052 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, | |
95e34ef7 | 1053 | { EVAX_LITERALS_NAME, |
d833fa0d TG |
1054 | EGPS__V_PIC | EGPS__V_OVR, |
1055 | SEC_DATA | SEC_READONLY, | |
1056 | EGPS__V_PIC | EGPS__V_OVR, | |
cf6b8767 | 1057 | SEC_DATA | SEC_READONLY | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD }, |
95e34ef7 | 1058 | { NULL, |
d833fa0d TG |
1059 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, |
1060 | SEC_DATA, | |
1061 | EGPS__V_REL | EGPS__V_RD | EGPS__V_WRT, | |
8185f55c | 1062 | SEC_DATA | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD } |
95e34ef7 TG |
1063 | }; |
1064 | ||
81bb31c0 | 1065 | /* Retrieve BFD section flags by name and size. */ |
95e34ef7 TG |
1066 | |
1067 | static flagword | |
81bb31c0 TG |
1068 | vms_secflag_by_name (const struct sec_flags_struct *section_flags, |
1069 | const char *name, | |
95e34ef7 TG |
1070 | int hassize) |
1071 | { | |
1072 | int i = 0; | |
1073 | ||
1074 | while (section_flags[i].name != NULL) | |
1075 | { | |
1076 | if (strcmp (name, section_flags[i].name) == 0) | |
07d6d2b8 | 1077 | { |
95e34ef7 TG |
1078 | if (hassize) |
1079 | return section_flags[i].flags_hassize; | |
1080 | else | |
1081 | return section_flags[i].flags_always; | |
1082 | } | |
1083 | i++; | |
1084 | } | |
1085 | if (hassize) | |
1086 | return section_flags[i].flags_hassize; | |
1087 | return section_flags[i].flags_always; | |
1088 | } | |
1089 | ||
81bb31c0 | 1090 | /* Retrieve VMS section flags by name and size. */ |
95e34ef7 TG |
1091 | |
1092 | static flagword | |
81bb31c0 TG |
1093 | vms_esecflag_by_name (const struct sec_flags_struct *section_flags, |
1094 | const char *name, | |
07d6d2b8 | 1095 | int hassize) |
95e34ef7 TG |
1096 | { |
1097 | int i = 0; | |
1098 | ||
1099 | while (section_flags[i].name != NULL) | |
1100 | { | |
1101 | if (strcmp (name, section_flags[i].name) == 0) | |
1102 | { | |
1103 | if (hassize) | |
1104 | return section_flags[i].vflags_hassize; | |
1105 | else | |
1106 | return section_flags[i].vflags_always; | |
1107 | } | |
1108 | i++; | |
1109 | } | |
1110 | if (hassize) | |
1111 | return section_flags[i].vflags_hassize; | |
1112 | return section_flags[i].vflags_always; | |
1113 | } | |
1114 | ||
ce76e55c TG |
1115 | /* Add SYM to the symbol table of ABFD. |
1116 | Return FALSE in case of error. */ | |
95e34ef7 | 1117 | |
0a1b45a2 | 1118 | static bool |
ce76e55c | 1119 | add_symbol_entry (bfd *abfd, struct vms_symbol_entry *sym) |
95e34ef7 | 1120 | { |
95e34ef7 TG |
1121 | if (PRIV (gsd_sym_count) >= PRIV (max_sym_count)) |
1122 | { | |
1123 | if (PRIV (max_sym_count) == 0) | |
07d6d2b8 AM |
1124 | { |
1125 | PRIV (max_sym_count) = 128; | |
1126 | PRIV (syms) = bfd_malloc | |
1127 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *)); | |
1128 | } | |
95e34ef7 | 1129 | else |
07d6d2b8 AM |
1130 | { |
1131 | PRIV (max_sym_count) *= 2; | |
9cb56943 | 1132 | PRIV (syms) = bfd_realloc_or_free |
07d6d2b8 AM |
1133 | (PRIV (syms), |
1134 | (PRIV (max_sym_count) * sizeof (struct vms_symbol_entry *))); | |
1135 | } | |
95e34ef7 | 1136 | if (PRIV (syms) == NULL) |
0a1b45a2 | 1137 | return false; |
95e34ef7 TG |
1138 | } |
1139 | ||
ce76e55c | 1140 | PRIV (syms)[PRIV (gsd_sym_count)++] = sym; |
0a1b45a2 | 1141 | return true; |
ce76e55c TG |
1142 | } |
1143 | ||
1144 | /* Create a symbol whose name is ASCIC and add it to ABFD. | |
1145 | Return NULL in case of error. */ | |
1146 | ||
1147 | static struct vms_symbol_entry * | |
2c0e48e5 | 1148 | add_symbol (bfd *abfd, const unsigned char *ascic, unsigned int max) |
ce76e55c TG |
1149 | { |
1150 | struct vms_symbol_entry *entry; | |
2c0e48e5 | 1151 | unsigned int len; |
ce76e55c TG |
1152 | |
1153 | len = *ascic++; | |
2c0e48e5 AM |
1154 | max -= 1; |
1155 | if (len > max) | |
1156 | { | |
1157 | _bfd_error_handler (_("record is too small for symbol name length")); | |
1158 | bfd_set_error (bfd_error_bad_value); | |
1159 | return NULL; | |
1160 | } | |
1161 | ||
ce76e55c TG |
1162 | entry = (struct vms_symbol_entry *)bfd_zalloc (abfd, sizeof (*entry) + len); |
1163 | if (entry == NULL) | |
1164 | return NULL; | |
1165 | entry->namelen = len; | |
1166 | memcpy (entry->name, ascic, len); | |
1167 | entry->name[len] = 0; | |
1168 | entry->owner = abfd; | |
1169 | ||
1170 | if (!add_symbol_entry (abfd, entry)) | |
1171 | return NULL; | |
95e34ef7 TG |
1172 | return entry; |
1173 | } | |
1174 | ||
1175 | /* Read and process EGSD. Return FALSE on failure. */ | |
1176 | ||
0a1b45a2 | 1177 | static bool |
5fe88cfb | 1178 | _bfd_vms_slurp_egsd (bfd *abfd) |
95e34ef7 | 1179 | { |
72e84f96 NC |
1180 | int gsd_type; |
1181 | unsigned int gsd_size; | |
95e34ef7 | 1182 | unsigned char *vms_rec; |
401e101e | 1183 | bfd_vma base_addr; |
bf31e604 | 1184 | long psindx; |
95e34ef7 TG |
1185 | |
1186 | vms_debug2 ((2, "EGSD\n")); | |
1187 | ||
3de58d95 NC |
1188 | if (PRIV (recrd.rec_size) < 8) |
1189 | { | |
38f14ab8 | 1190 | _bfd_error_handler (_("corrupt EGSD record: its size (%#x) is too small"), |
3de58d95 NC |
1191 | PRIV (recrd.rec_size)); |
1192 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 1193 | return false; |
3de58d95 | 1194 | } |
07d6d2b8 | 1195 | |
95e34ef7 TG |
1196 | PRIV (recrd.rec) += 8; /* Skip type, size, align pad. */ |
1197 | PRIV (recrd.rec_size) -= 8; | |
1198 | ||
1199 | /* Calculate base address for each section. */ | |
401e101e | 1200 | base_addr = 0; |
95e34ef7 | 1201 | |
72e84f96 | 1202 | while (PRIV (recrd.rec_size) > 4) |
95e34ef7 TG |
1203 | { |
1204 | vms_rec = PRIV (recrd.rec); | |
1205 | ||
1206 | gsd_type = bfd_getl16 (vms_rec); | |
1207 | gsd_size = bfd_getl16 (vms_rec + 2); | |
1208 | ||
1209 | vms_debug2 ((3, "egsd_type %d\n", gsd_type)); | |
1210 | ||
72e84f96 NC |
1211 | /* PR 21615: Check for size overflow. */ |
1212 | if (PRIV (recrd.rec_size) < gsd_size) | |
1213 | { | |
bf31e604 AM |
1214 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " |
1215 | "is larger than remaining space (%#x)"), | |
1216 | gsd_type, gsd_size, PRIV (recrd.rec_size)); | |
7adc0a81 | 1217 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 1218 | return false; |
7adc0a81 NC |
1219 | } |
1220 | ||
b50ef514 AM |
1221 | if (gsd_size < 4) |
1222 | { | |
1223 | too_small: | |
1224 | _bfd_error_handler (_("corrupt EGSD record type %d: size (%#x) " | |
1225 | "is too small"), | |
1226 | gsd_type, gsd_size); | |
1227 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 1228 | return false; |
b50ef514 AM |
1229 | } |
1230 | ||
95e34ef7 TG |
1231 | switch (gsd_type) |
1232 | { | |
1233 | case EGSD__C_PSC: | |
07d6d2b8 | 1234 | /* Program section definition. */ |
95e34ef7 | 1235 | { |
bf31e604 | 1236 | struct vms_egps *egps = (struct vms_egps *) vms_rec; |
07d6d2b8 AM |
1237 | flagword new_flags, vms_flags; |
1238 | asection *section; | |
5fe88cfb | 1239 | |
bf31e604 | 1240 | if (offsetof (struct vms_egps, flags) + 2 > gsd_size) |
b50ef514 | 1241 | goto too_small; |
8185f55c | 1242 | vms_flags = bfd_getl16 (egps->flags); |
21e003e8 | 1243 | |
07d6d2b8 AM |
1244 | if ((vms_flags & EGPS__V_REL) == 0) |
1245 | { | |
1246 | /* Use the global absolute section for all | |
1247 | absolute sections. */ | |
1248 | section = bfd_abs_section_ptr; | |
1249 | } | |
1250 | else | |
1251 | { | |
1252 | char *name; | |
401e101e | 1253 | bfd_vma align_addr; |
bf31e604 | 1254 | size_t left; |
21e003e8 | 1255 | |
bf31e604 AM |
1256 | if (offsetof (struct vms_egps, namlng) >= gsd_size) |
1257 | goto too_small; | |
1258 | left = gsd_size - offsetof (struct vms_egps, namlng); | |
1259 | name = _bfd_vms_save_counted_string (abfd, &egps->namlng, left); | |
1260 | if (name == NULL || name[0] == 0) | |
0a1b45a2 | 1261 | return false; |
21e003e8 | 1262 | |
07d6d2b8 AM |
1263 | section = bfd_make_section (abfd, name); |
1264 | if (!section) | |
0a1b45a2 | 1265 | return false; |
07d6d2b8 AM |
1266 | |
1267 | section->filepos = 0; | |
1268 | section->size = bfd_getl32 (egps->alloc); | |
401e101e | 1269 | section->alignment_power = egps->align & 31; |
07d6d2b8 AM |
1270 | |
1271 | vms_section_data (section)->flags = vms_flags; | |
1272 | vms_section_data (section)->no_flags = 0; | |
1273 | ||
37d2e9c7 AM |
1274 | new_flags = vms_secflag_by_name (evax_section_flags, |
1275 | section->name, | |
07d6d2b8 AM |
1276 | section->size > 0); |
1277 | if (section->size > 0) | |
1278 | new_flags |= SEC_LOAD; | |
1279 | if (!(vms_flags & EGPS__V_NOMOD) && section->size > 0) | |
1280 | { | |
1281 | /* Set RELOC and HAS_CONTENTS if the section is not | |
1282 | demand-zero and not empty. */ | |
1283 | new_flags |= SEC_HAS_CONTENTS; | |
1284 | if (vms_flags & EGPS__V_REL) | |
1285 | new_flags |= SEC_RELOC; | |
1286 | } | |
1287 | if (vms_flags & EGPS__V_EXE) | |
1288 | { | |
1289 | /* Set CODE if section is executable. */ | |
1290 | new_flags |= SEC_CODE; | |
1291 | new_flags &= ~SEC_DATA; | |
1292 | } | |
fd361982 | 1293 | if (!bfd_set_section_flags (section, new_flags)) |
0a1b45a2 | 1294 | return false; |
07d6d2b8 AM |
1295 | |
1296 | /* Give a non-overlapping vma to non absolute sections. */ | |
401e101e AM |
1297 | align_addr = (bfd_vma) 1 << section->alignment_power; |
1298 | base_addr = (base_addr + align_addr - 1) & -align_addr; | |
1299 | section->vma = base_addr; | |
07d6d2b8 AM |
1300 | base_addr += section->size; |
1301 | } | |
1302 | ||
1303 | /* Append it to the section array. */ | |
1304 | if (PRIV (section_count) >= PRIV (section_max)) | |
1305 | { | |
1306 | if (PRIV (section_max) == 0) | |
1307 | PRIV (section_max) = 16; | |
1308 | else | |
1309 | PRIV (section_max) *= 2; | |
1310 | PRIV (sections) = bfd_realloc_or_free | |
1311 | (PRIV (sections), PRIV (section_max) * sizeof (asection *)); | |
1312 | if (PRIV (sections) == NULL) | |
0a1b45a2 | 1313 | return false; |
07d6d2b8 AM |
1314 | } |
1315 | ||
1316 | PRIV (sections)[PRIV (section_count)] = section; | |
1317 | PRIV (section_count)++; | |
95e34ef7 TG |
1318 | } |
1319 | break; | |
1320 | ||
1321 | case EGSD__C_SYM: | |
1322 | { | |
2c0e48e5 | 1323 | unsigned int nameoff; |
07d6d2b8 AM |
1324 | struct vms_symbol_entry *entry; |
1325 | struct vms_egsy *egsy = (struct vms_egsy *) vms_rec; | |
1326 | flagword old_flags; | |
95e34ef7 | 1327 | |
bf31e604 AM |
1328 | if (offsetof (struct vms_egsy, flags) + 2 > gsd_size) |
1329 | goto too_small; | |
95e34ef7 TG |
1330 | old_flags = bfd_getl16 (egsy->flags); |
1331 | if (old_flags & EGSY__V_DEF) | |
07d6d2b8 AM |
1332 | nameoff = ESDF__B_NAMLNG; |
1333 | else | |
1334 | nameoff = ESRF__B_NAMLNG; | |
95e34ef7 | 1335 | |
2c0e48e5 | 1336 | if (nameoff >= gsd_size) |
bf31e604 | 1337 | goto too_small; |
2c0e48e5 | 1338 | entry = add_symbol (abfd, vms_rec + nameoff, gsd_size - nameoff); |
07d6d2b8 | 1339 | if (entry == NULL) |
0a1b45a2 | 1340 | return false; |
95e34ef7 | 1341 | |
07d6d2b8 AM |
1342 | /* Allow only duplicate reference. */ |
1343 | if ((entry->flags & EGSY__V_DEF) && (old_flags & EGSY__V_DEF)) | |
1344 | abort (); | |
95e34ef7 | 1345 | |
07d6d2b8 AM |
1346 | if (entry->typ == 0) |
1347 | { | |
1348 | entry->typ = gsd_type; | |
1349 | entry->data_type = egsy->datyp; | |
1350 | entry->flags = old_flags; | |
1351 | } | |
95e34ef7 TG |
1352 | |
1353 | if (old_flags & EGSY__V_DEF) | |
07d6d2b8 | 1354 | { |
bf31e604 | 1355 | struct vms_esdf *esdf = (struct vms_esdf *) vms_rec; |
95e34ef7 TG |
1356 | |
1357 | entry->value = bfd_getl64 (esdf->value); | |
cb06d03a | 1358 | if (PRIV (sections) == NULL) |
0a1b45a2 | 1359 | return false; |
ca4cf9b9 NC |
1360 | |
1361 | psindx = bfd_getl32 (esdf->psindx); | |
1362 | /* PR 21813: Check for an out of range index. */ | |
1363 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) | |
1364 | { | |
bf31e604 AM |
1365 | bad_psindx: |
1366 | _bfd_error_handler (_("corrupt EGSD record: its psindx " | |
1367 | "field is too big (%#lx)"), | |
ca4cf9b9 NC |
1368 | psindx); |
1369 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 1370 | return false; |
ca4cf9b9 NC |
1371 | } |
1372 | entry->section = PRIV (sections)[psindx]; | |
95e34ef7 | 1373 | |
07d6d2b8 AM |
1374 | if (old_flags & EGSY__V_NORM) |
1375 | { | |
1376 | PRIV (norm_sym_count)++; | |
95e34ef7 | 1377 | |
07d6d2b8 | 1378 | entry->code_value = bfd_getl64 (esdf->code_address); |
ca4cf9b9 | 1379 | psindx = bfd_getl32 (esdf->ca_psindx); |
bf31e604 | 1380 | /* PR 21813: Check for an out of range index. */ |
ca4cf9b9 | 1381 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) |
bf31e604 | 1382 | goto bad_psindx; |
07d6d2b8 AM |
1383 | entry->code_section = PRIV (sections)[psindx]; |
1384 | } | |
1385 | } | |
95e34ef7 TG |
1386 | } |
1387 | break; | |
1388 | ||
1389 | case EGSD__C_SYMG: | |
1390 | { | |
07d6d2b8 AM |
1391 | struct vms_symbol_entry *entry; |
1392 | struct vms_egst *egst = (struct vms_egst *)vms_rec; | |
1393 | flagword old_flags; | |
2c0e48e5 | 1394 | unsigned int nameoff = offsetof (struct vms_egst, namlng); |
95e34ef7 | 1395 | |
2c0e48e5 | 1396 | if (nameoff >= gsd_size) |
bf31e604 | 1397 | goto too_small; |
2c0e48e5 | 1398 | entry = add_symbol (abfd, &egst->namlng, gsd_size - nameoff); |
07d6d2b8 | 1399 | if (entry == NULL) |
0a1b45a2 | 1400 | return false; |
95e34ef7 | 1401 | |
de6a7ee4 | 1402 | old_flags = bfd_getl16 (egst->header.flags); |
07d6d2b8 AM |
1403 | entry->typ = gsd_type; |
1404 | entry->data_type = egst->header.datyp; | |
1405 | entry->flags = old_flags; | |
95e34ef7 | 1406 | |
07d6d2b8 | 1407 | entry->symbol_vector = bfd_getl32 (egst->value); |
95e34ef7 | 1408 | |
07d6d2b8 | 1409 | if (old_flags & EGSY__V_REL) |
cb06d03a NC |
1410 | { |
1411 | if (PRIV (sections) == NULL) | |
0a1b45a2 | 1412 | return false; |
ca4cf9b9 NC |
1413 | psindx = bfd_getl32 (egst->psindx); |
1414 | /* PR 21813: Check for an out of range index. */ | |
1415 | if (psindx < 0 || psindx >= (int) PRIV (section_count)) | |
bf31e604 | 1416 | goto bad_psindx; |
ca4cf9b9 | 1417 | entry->section = PRIV (sections)[psindx]; |
cb06d03a | 1418 | } |
07d6d2b8 AM |
1419 | else |
1420 | entry->section = bfd_abs_section_ptr; | |
a928f1d7 | 1421 | |
07d6d2b8 | 1422 | entry->value = bfd_getl64 (egst->lp_2); |
95e34ef7 | 1423 | |
07d6d2b8 AM |
1424 | if (old_flags & EGSY__V_NORM) |
1425 | { | |
1426 | PRIV (norm_sym_count)++; | |
95e34ef7 | 1427 | |
07d6d2b8 AM |
1428 | entry->code_value = bfd_getl64 (egst->lp_1); |
1429 | entry->code_section = bfd_abs_section_ptr; | |
1430 | } | |
1431 | } | |
95e34ef7 TG |
1432 | break; |
1433 | ||
07d6d2b8 AM |
1434 | case EGSD__C_SPSC: |
1435 | case EGSD__C_IDC: | |
1436 | /* Currently ignored. */ | |
1437 | break; | |
95e34ef7 TG |
1438 | case EGSD__C_SYMM: |
1439 | case EGSD__C_SYMV: | |
1440 | default: | |
38f14ab8 | 1441 | _bfd_error_handler (_("unknown EGSD subtype %d"), gsd_type); |
95e34ef7 | 1442 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 1443 | return false; |
95e34ef7 TG |
1444 | } |
1445 | ||
1446 | PRIV (recrd.rec_size) -= gsd_size; | |
1447 | PRIV (recrd.rec) += gsd_size; | |
1448 | } | |
1449 | ||
3de58d95 NC |
1450 | /* FIXME: Should we complain if PRIV (recrd.rec_size) is not zero ? */ |
1451 | ||
95e34ef7 TG |
1452 | if (PRIV (gsd_sym_count) > 0) |
1453 | abfd->flags |= HAS_SYMS; | |
1454 | ||
0a1b45a2 | 1455 | return true; |
95e34ef7 TG |
1456 | } |
1457 | ||
1458 | /* Stack routines for vms ETIR commands. */ | |
1459 | ||
1460 | /* Push value and section index. */ | |
1461 | ||
0a1b45a2 | 1462 | static bool |
95e34ef7 TG |
1463 | _bfd_vms_push (bfd *abfd, bfd_vma val, unsigned int reloc) |
1464 | { | |
1465 | vms_debug2 ((4, "<push %08lx (0x%08x) at %d>\n", | |
07d6d2b8 | 1466 | (unsigned long)val, reloc, PRIV (stackptr))); |
95e34ef7 TG |
1467 | |
1468 | PRIV (stack[PRIV (stackptr)]).value = val; | |
1469 | PRIV (stack[PRIV (stackptr)]).reloc = reloc; | |
1470 | PRIV (stackptr)++; | |
1471 | if (PRIV (stackptr) >= STACKSIZE) | |
1472 | { | |
1473 | bfd_set_error (bfd_error_bad_value); | |
38f14ab8 | 1474 | _bfd_error_handler (_("stack overflow (%d) in _bfd_vms_push"), PRIV (stackptr)); |
0a1b45a2 | 1475 | return false; |
95e34ef7 | 1476 | } |
0a1b45a2 | 1477 | return true; |
95e34ef7 TG |
1478 | } |
1479 | ||
1480 | /* Pop value and section index. */ | |
1481 | ||
0a1b45a2 | 1482 | static bool |
95e34ef7 TG |
1483 | _bfd_vms_pop (bfd *abfd, bfd_vma *val, unsigned int *rel) |
1484 | { | |
1485 | if (PRIV (stackptr) == 0) | |
1486 | { | |
1487 | bfd_set_error (bfd_error_bad_value); | |
38f14ab8 | 1488 | _bfd_error_handler (_("stack underflow in _bfd_vms_pop")); |
0a1b45a2 | 1489 | return false; |
95e34ef7 TG |
1490 | } |
1491 | PRIV (stackptr)--; | |
1492 | *val = PRIV (stack[PRIV (stackptr)]).value; | |
1493 | *rel = PRIV (stack[PRIV (stackptr)]).reloc; | |
1494 | ||
1495 | vms_debug2 ((4, "<pop %08lx (0x%08x)>\n", (unsigned long)*val, *rel)); | |
0a1b45a2 | 1496 | return true; |
95e34ef7 TG |
1497 | } |
1498 | ||
1499 | /* Routines to fill sections contents during tir/etir read. */ | |
1500 | ||
1501 | /* Initialize image buffer pointer to be filled. */ | |
1502 | ||
1503 | static void | |
1504 | image_set_ptr (bfd *abfd, bfd_vma vma, int sect, struct bfd_link_info *info) | |
1505 | { | |
1506 | asection *sec; | |
1507 | ||
1508 | vms_debug2 ((4, "image_set_ptr (0x%08x, sect=%d)\n", (unsigned)vma, sect)); | |
1509 | ||
cb06d03a NC |
1510 | if (PRIV (sections) == NULL) |
1511 | return; | |
ca4cf9b9 NC |
1512 | if (sect < 0 || sect >= (int) PRIV (section_count)) |
1513 | return; | |
1514 | ||
95e34ef7 TG |
1515 | sec = PRIV (sections)[sect]; |
1516 | ||
1517 | if (info) | |
1518 | { | |
1519 | /* Reading contents to an output bfd. */ | |
1520 | ||
1521 | if (sec->output_section == NULL) | |
07d6d2b8 AM |
1522 | { |
1523 | /* Section discarded. */ | |
1524 | vms_debug2 ((5, " section %s discarded\n", sec->name)); | |
1525 | ||
1526 | /* This is not used. */ | |
1527 | PRIV (image_section) = NULL; | |
1528 | PRIV (image_offset) = 0; | |
1529 | return; | |
1530 | } | |
95e34ef7 TG |
1531 | PRIV (image_offset) = sec->output_offset + vma; |
1532 | PRIV (image_section) = sec->output_section; | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | PRIV (image_offset) = vma; | |
1537 | PRIV (image_section) = sec; | |
1538 | } | |
1539 | } | |
1540 | ||
1541 | /* Increment image buffer pointer by offset. */ | |
1542 | ||
1543 | static void | |
1544 | image_inc_ptr (bfd *abfd, bfd_vma offset) | |
1545 | { | |
1546 | vms_debug2 ((4, "image_inc_ptr (%u)\n", (unsigned)offset)); | |
1547 | ||
1548 | PRIV (image_offset) += offset; | |
1549 | } | |
1550 | ||
1551 | /* Save current DST location counter under specified index. */ | |
1552 | ||
0a1b45a2 | 1553 | static bool |
95e34ef7 TG |
1554 | dst_define_location (bfd *abfd, unsigned int loc) |
1555 | { | |
1556 | vms_debug2 ((4, "dst_define_location (%d)\n", (int)loc)); | |
1557 | ||
f75fbe8a AM |
1558 | if (loc > 1 << 24) |
1559 | { | |
1560 | /* 16M entries ought to be plenty. */ | |
1561 | bfd_set_error (bfd_error_bad_value); | |
1562 | _bfd_error_handler (_("dst_define_location %u too large"), loc); | |
0a1b45a2 | 1563 | return false; |
f75fbe8a AM |
1564 | } |
1565 | ||
95e34ef7 TG |
1566 | /* Grow the ptr offset table if necessary. */ |
1567 | if (loc + 1 > PRIV (dst_ptr_offsets_count)) | |
1568 | { | |
9cb56943 AM |
1569 | PRIV (dst_ptr_offsets) |
1570 | = bfd_realloc_or_free (PRIV (dst_ptr_offsets), | |
1571 | (loc + 1) * sizeof (unsigned int)); | |
1572 | if (PRIV (dst_ptr_offsets) == NULL) | |
0a1b45a2 | 1573 | return false; |
3cb5e955 AM |
1574 | memset (PRIV (dst_ptr_offsets) + PRIV (dst_ptr_offsets_count), 0, |
1575 | (loc - PRIV (dst_ptr_offsets_count)) * sizeof (unsigned int)); | |
95e34ef7 TG |
1576 | PRIV (dst_ptr_offsets_count) = loc + 1; |
1577 | } | |
1578 | ||
1579 | PRIV (dst_ptr_offsets)[loc] = PRIV (image_offset); | |
0a1b45a2 | 1580 | return true; |
95e34ef7 TG |
1581 | } |
1582 | ||
1583 | /* Restore saved DST location counter from specified index. */ | |
1584 | ||
0a1b45a2 | 1585 | static bool |
95e34ef7 TG |
1586 | dst_restore_location (bfd *abfd, unsigned int loc) |
1587 | { | |
1588 | vms_debug2 ((4, "dst_restore_location (%d)\n", (int)loc)); | |
1589 | ||
7bac4137 AM |
1590 | if (loc < PRIV (dst_ptr_offsets_count)) |
1591 | { | |
1592 | PRIV (image_offset) = PRIV (dst_ptr_offsets)[loc]; | |
0a1b45a2 | 1593 | return true; |
7bac4137 | 1594 | } |
0a1b45a2 | 1595 | return false; |
95e34ef7 TG |
1596 | } |
1597 | ||
1598 | /* Retrieve saved DST location counter from specified index. */ | |
1599 | ||
0a1b45a2 | 1600 | static bool |
7bac4137 | 1601 | dst_retrieve_location (bfd *abfd, bfd_vma *loc) |
95e34ef7 | 1602 | { |
7bac4137 | 1603 | vms_debug2 ((4, "dst_retrieve_location (%d)\n", (int) *loc)); |
95e34ef7 | 1604 | |
7bac4137 AM |
1605 | if (*loc < PRIV (dst_ptr_offsets_count)) |
1606 | { | |
1607 | *loc = PRIV (dst_ptr_offsets)[*loc]; | |
0a1b45a2 | 1608 | return true; |
7bac4137 | 1609 | } |
0a1b45a2 | 1610 | return false; |
95e34ef7 TG |
1611 | } |
1612 | ||
95e34ef7 TG |
1613 | /* Write multiple bytes to section image. */ |
1614 | ||
0a1b45a2 | 1615 | static bool |
c53d2e6d | 1616 | image_write (bfd *abfd, unsigned char *ptr, unsigned int size) |
95e34ef7 | 1617 | { |
81699544 AM |
1618 | asection *sec = PRIV (image_section); |
1619 | size_t off = PRIV (image_offset); | |
1620 | ||
1621 | /* Check bounds. */ | |
1622 | if (off > sec->size | |
1623 | || size > sec->size - off) | |
1624 | { | |
1625 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 1626 | return false; |
81699544 AM |
1627 | } |
1628 | ||
95e34ef7 TG |
1629 | #if VMS_DEBUG |
1630 | _bfd_vms_debug (8, "image_write from (%p, %d) to (%ld)\n", ptr, size, | |
fbf4b3c9 | 1631 | (long) off); |
95e34ef7 TG |
1632 | #endif |
1633 | ||
95e34ef7 | 1634 | if (PRIV (image_section)->contents != NULL) |
81699544 AM |
1635 | memcpy (sec->contents + off, ptr, size); |
1636 | else | |
95e34ef7 | 1637 | { |
81699544 AM |
1638 | unsigned int i; |
1639 | for (i = 0; i < size; i++) | |
1640 | if (ptr[i] != 0) | |
1641 | { | |
1642 | bfd_set_error (bfd_error_bad_value); | |
0a1b45a2 | 1643 | return false; |
81699544 | 1644 | } |
95e34ef7 | 1645 | } |
81699544 | 1646 | |
8ab484c2 AM |
1647 | #if VMS_DEBUG |
1648 | _bfd_hexdump (9, ptr, size, 0); | |
1649 | #endif | |
95e34ef7 TG |
1650 | |
1651 | PRIV (image_offset) += size; | |
0a1b45a2 | 1652 | return true; |
95e34ef7 TG |
1653 | } |
1654 | ||
1655 | /* Write byte to section image. */ | |
1656 | ||
0a1b45a2 | 1657 | static bool |
95e34ef7 TG |
1658 | image_write_b (bfd * abfd, unsigned int value) |
1659 | { | |
1660 | unsigned char data[1]; | |
1661 | ||
1662 | vms_debug2 ((6, "image_write_b (%02x)\n", (int) value)); | |
1663 | ||
1664 | *data = value; | |
1665 | ||
1666 | return image_write (abfd, data, sizeof (data)); | |
1667 | } | |
1668 | ||
1669 | /* Write 2-byte word to image. */ | |
1670 | ||
0a1b45a2 | 1671 | static bool |
95e34ef7 TG |
1672 | image_write_w (bfd * abfd, unsigned int value) |
1673 | { | |
1674 | unsigned char data[2]; | |
1675 | ||
1676 | vms_debug2 ((6, "image_write_w (%04x)\n", (int) value)); | |
1677 | ||
1678 | bfd_putl16 (value, data); | |
1679 | return image_write (abfd, data, sizeof (data)); | |
1680 | } | |
1681 | ||
1682 | /* Write 4-byte long to image. */ | |
1683 | ||
0a1b45a2 | 1684 | static bool |
95e34ef7 TG |
1685 | image_write_l (bfd * abfd, unsigned long value) |
1686 | { | |
1687 | unsigned char data[4]; | |
1688 | ||
1689 | vms_debug2 ((6, "image_write_l (%08lx)\n", value)); | |
1690 | ||
1691 | bfd_putl32 (value, data); | |
1692 | return image_write (abfd, data, sizeof (data)); | |
1693 | } | |
1694 | ||
1695 | /* Write 8-byte quad to image. */ | |
1696 | ||
0a1b45a2 | 1697 | static bool |
95e34ef7 TG |
1698 | image_write_q (bfd * abfd, bfd_vma value) |
1699 | { | |
1700 | unsigned char data[8]; | |
1701 | ||
1702 | vms_debug2 ((6, "image_write_q (%08lx)\n", (unsigned long)value)); | |
1703 | ||
1704 | bfd_putl64 (value, data); | |
1705 | return image_write (abfd, data, sizeof (data)); | |
1706 | } | |
1707 | \f | |
1708 | static const char * | |
1709 | _bfd_vms_etir_name (int cmd) | |
1710 | { | |
1711 | switch (cmd) | |
1712 | { | |
1713 | case ETIR__C_STA_GBL: return "ETIR__C_STA_GBL"; | |
1714 | case ETIR__C_STA_LW: return "ETIR__C_STA_LW"; | |
1715 | case ETIR__C_STA_QW: return "ETIR__C_STA_QW"; | |
1716 | case ETIR__C_STA_PQ: return "ETIR__C_STA_PQ"; | |
1717 | case ETIR__C_STA_LI: return "ETIR__C_STA_LI"; | |
1718 | case ETIR__C_STA_MOD: return "ETIR__C_STA_MOD"; | |
1719 | case ETIR__C_STA_CKARG: return "ETIR__C_STA_CKARG"; | |
1720 | case ETIR__C_STO_B: return "ETIR__C_STO_B"; | |
1721 | case ETIR__C_STO_W: return "ETIR__C_STO_W"; | |
1722 | case ETIR__C_STO_GBL: return "ETIR__C_STO_GBL"; | |
1723 | case ETIR__C_STO_CA: return "ETIR__C_STO_CA"; | |
1724 | case ETIR__C_STO_RB: return "ETIR__C_STO_RB"; | |
1725 | case ETIR__C_STO_AB: return "ETIR__C_STO_AB"; | |
1726 | case ETIR__C_STO_OFF: return "ETIR__C_STO_OFF"; | |
1727 | case ETIR__C_STO_IMM: return "ETIR__C_STO_IMM"; | |
1728 | case ETIR__C_STO_IMMR: return "ETIR__C_STO_IMMR"; | |
1729 | case ETIR__C_STO_LW: return "ETIR__C_STO_LW"; | |
1730 | case ETIR__C_STO_QW: return "ETIR__C_STO_QW"; | |
1731 | case ETIR__C_STO_GBL_LW: return "ETIR__C_STO_GBL_LW"; | |
1732 | case ETIR__C_STO_LP_PSB: return "ETIR__C_STO_LP_PSB"; | |
1733 | case ETIR__C_STO_HINT_GBL: return "ETIR__C_STO_HINT_GBL"; | |
1734 | case ETIR__C_STO_HINT_PS: return "ETIR__C_STO_HINT_PS"; | |
1735 | case ETIR__C_OPR_ADD: return "ETIR__C_OPR_ADD"; | |
1736 | case ETIR__C_OPR_SUB: return "ETIR__C_OPR_SUB"; | |
1737 | case ETIR__C_OPR_INSV: return "ETIR__C_OPR_INSV"; | |
1738 | case ETIR__C_OPR_USH: return "ETIR__C_OPR_USH"; | |
1739 | case ETIR__C_OPR_ROT: return "ETIR__C_OPR_ROT"; | |
1740 | case ETIR__C_OPR_REDEF: return "ETIR__C_OPR_REDEF"; | |
1741 | case ETIR__C_OPR_DFLIT: return "ETIR__C_OPR_DFLIT"; | |
1742 | case ETIR__C_STC_LP: return "ETIR__C_STC_LP"; | |
1743 | case ETIR__C_STC_GBL: return "ETIR__C_STC_GBL"; | |
1744 | case ETIR__C_STC_GCA: return "ETIR__C_STC_GCA"; | |
1745 | case ETIR__C_STC_PS: return "ETIR__C_STC_PS"; | |
1746 | case ETIR__C_STC_NBH_PS: return "ETIR__C_STC_NBH_PS"; | |
1747 | case ETIR__C_STC_NOP_GBL: return "ETIR__C_STC_NOP_GBL"; | |
1748 | case ETIR__C_STC_NOP_PS: return "ETIR__C_STC_NOP_PS"; | |
1749 | case ETIR__C_STC_BSR_GBL: return "ETIR__C_STC_BSR_GBL"; | |
1750 | case ETIR__C_STC_BSR_PS: return "ETIR__C_STC_BSR_PS"; | |
1751 | case ETIR__C_STC_LDA_GBL: return "ETIR__C_STC_LDA_GBL"; | |
1752 | case ETIR__C_STC_LDA_PS: return "ETIR__C_STC_LDA_PS"; | |
1753 | case ETIR__C_STC_BOH_GBL: return "ETIR__C_STC_BOH_GBL"; | |
1754 | case ETIR__C_STC_BOH_PS: return "ETIR__C_STC_BOH_PS"; | |
1755 | case ETIR__C_STC_NBH_GBL: return "ETIR__C_STC_NBH_GBL"; | |
1756 | case ETIR__C_STC_LP_PSB: return "ETIR__C_STC_LP_PSB"; | |
1757 | case ETIR__C_CTL_SETRB: return "ETIR__C_CTL_SETRB"; | |
1758 | case ETIR__C_CTL_AUGRB: return "ETIR__C_CTL_AUGRB"; | |
1759 | case ETIR__C_CTL_DFLOC: return "ETIR__C_CTL_DFLOC"; | |
1760 | case ETIR__C_CTL_STLOC: return "ETIR__C_CTL_STLOC"; | |
1761 | case ETIR__C_CTL_STKDL: return "ETIR__C_CTL_STKDL"; | |
1762 | ||
1763 | default: | |
1764 | /* These names have not yet been added to this switch statement. */ | |
4eca0228 | 1765 | _bfd_error_handler (_("unknown ETIR command %d"), cmd); |
95e34ef7 TG |
1766 | } |
1767 | ||
1768 | return NULL; | |
1769 | } | |
1770 | #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L) | |
1771 | ||
1772 | static void | |
c53d2e6d NC |
1773 | _bfd_vms_get_value (bfd *abfd, |
1774 | const unsigned char *ascic, | |
1775 | const unsigned char *max_ascic, | |
07d6d2b8 AM |
1776 | struct bfd_link_info *info, |
1777 | bfd_vma *vma, | |
1778 | struct alpha_vms_link_hash_entry **hp) | |
95e34ef7 TG |
1779 | { |
1780 | char name[257]; | |
c53d2e6d NC |
1781 | unsigned int len; |
1782 | unsigned int i; | |
95e34ef7 TG |
1783 | struct alpha_vms_link_hash_entry *h; |
1784 | ||
1785 | /* Not linking. Do not try to resolve the symbol. */ | |
1786 | if (info == NULL) | |
1787 | { | |
1788 | *vma = 0; | |
1789 | *hp = NULL; | |
1790 | return; | |
1791 | } | |
1792 | ||
1793 | len = *ascic; | |
c53d2e6d NC |
1794 | if (ascic + len >= max_ascic) |
1795 | { | |
38f14ab8 | 1796 | _bfd_error_handler (_("corrupt vms value")); |
c53d2e6d NC |
1797 | *vma = 0; |
1798 | *hp = NULL; | |
1799 | return; | |
1800 | } | |
1801 | ||
95e34ef7 TG |
1802 | for (i = 0; i < len; i++) |
1803 | name[i] = ascic[i + 1]; | |
1804 | name[i] = 0; | |
1805 | ||
1806 | h = (struct alpha_vms_link_hash_entry *) | |
0a1b45a2 | 1807 | bfd_link_hash_lookup (info->hash, name, false, false, true); |
95e34ef7 TG |
1808 | |
1809 | *hp = h; | |
1810 | ||
1811 | if (h != NULL | |
1812 | && (h->root.type == bfd_link_hash_defined | |
07d6d2b8 | 1813 | || h->root.type == bfd_link_hash_defweak)) |
95e34ef7 TG |
1814 | *vma = h->root.u.def.value |
1815 | + h->root.u.def.section->output_offset | |
1816 | + h->root.u.def.section->output_section->vma; | |
1817 | else if (h && h->root.type == bfd_link_hash_undefweak) | |
1818 | *vma = 0; | |
1819 | else | |
1820 | { | |
1a72702b | 1821 | (*info->callbacks->undefined_symbol) |
0a1b45a2 | 1822 | (info, name, abfd, PRIV (image_section), PRIV (image_offset), true); |
95e34ef7 TG |
1823 | *vma = 0; |
1824 | } | |
1825 | } | |
1826 | ||
1827 | #define RELC_NONE 0 | |
1828 | #define RELC_REL 1 | |
1829 | #define RELC_SHR_BASE 0x10000 | |
1830 | #define RELC_SEC_BASE 0x20000 | |
1831 | #define RELC_MASK 0x0ffff | |
1832 | ||
1833 | static unsigned int | |
1834 | alpha_vms_sym_to_ctxt (struct alpha_vms_link_hash_entry *h) | |
1835 | { | |
1836 | /* Handle undefined symbols. */ | |
1837 | if (h == NULL || h->sym == NULL) | |
1838 | return RELC_NONE; | |
1839 | ||
1840 | if (h->sym->typ == EGSD__C_SYMG) | |
1841 | { | |
1842 | if (h->sym->flags & EGSY__V_REL) | |
07d6d2b8 | 1843 | return RELC_SHR_BASE + PRIV2 (h->sym->owner, shr_index); |
95e34ef7 | 1844 | else |
07d6d2b8 AM |
1845 | { |
1846 | /* Can this happen (non-relocatable symg) ? I'd like to see | |
1847 | an example. */ | |
1848 | abort (); | |
1849 | } | |
95e34ef7 TG |
1850 | } |
1851 | if (h->sym->typ == EGSD__C_SYM) | |
1852 | { | |
1853 | if (h->sym->flags & EGSY__V_REL) | |
07d6d2b8 | 1854 | return RELC_REL; |
95e34ef7 | 1855 | else |
07d6d2b8 | 1856 | return RELC_NONE; |
95e34ef7 TG |
1857 | } |
1858 | abort (); | |
1859 | } | |
1860 | ||
1861 | static bfd_vma | |
a928f1d7 | 1862 | alpha_vms_get_sym_value (asection *sect, bfd_vma addr) |
95e34ef7 | 1863 | { |
a928f1d7 | 1864 | return sect->output_section->vma + sect->output_offset + addr; |
95e34ef7 TG |
1865 | } |
1866 | ||
1867 | static bfd_vma | |
1868 | alpha_vms_fix_sec_rel (bfd *abfd, struct bfd_link_info *info, | |
07d6d2b8 | 1869 | unsigned int rel, bfd_vma vma) |
95e34ef7 | 1870 | { |
cb06d03a NC |
1871 | asection *sec; |
1872 | ||
1873 | if (PRIV (sections) == NULL) | |
1874 | return 0; | |
1875 | ||
1876 | sec = PRIV (sections)[rel & RELC_MASK]; | |
95e34ef7 TG |
1877 | |
1878 | if (info) | |
1879 | { | |
1880 | if (sec->output_section == NULL) | |
07d6d2b8 | 1881 | abort (); |
95e34ef7 TG |
1882 | return vma + sec->output_section->vma + sec->output_offset; |
1883 | } | |
1884 | else | |
1885 | return vma + sec->vma; | |
1886 | } | |
1887 | ||
44273c5b TG |
1888 | /* Read an ETIR record from ABFD. If INFO is not null, put the content into |
1889 | the output section (used during linking). | |
1890 | Return FALSE in case of error. */ | |
1891 | ||
0a1b45a2 | 1892 | static bool |
95e34ef7 TG |
1893 | _bfd_vms_slurp_etir (bfd *abfd, struct bfd_link_info *info) |
1894 | { | |
1895 | unsigned char *ptr; | |
1896 | unsigned int length; | |
1897 | unsigned char *maxptr; | |
8ab484c2 AM |
1898 | bfd_vma op1 = 0; |
1899 | bfd_vma op2 = 0; | |
1900 | unsigned int rel1 = RELC_NONE; | |
1901 | unsigned int rel2 = RELC_NONE; | |
95e34ef7 TG |
1902 | struct alpha_vms_link_hash_entry *h; |
1903 | ||
1904 | PRIV (recrd.rec) += ETIR__C_HEADER_SIZE; | |
1905 | PRIV (recrd.rec_size) -= ETIR__C_HEADER_SIZE; | |
1906 | ||
1907 | ptr = PRIV (recrd.rec); | |
1908 | length = PRIV (recrd.rec_size); | |
1909 | maxptr = ptr + length; | |
1910 | ||
1911 | vms_debug2 ((2, "ETIR: %d bytes\n", length)); | |
1912 | ||
1913 | while (ptr < maxptr) | |
1914 | { | |
2c0e48e5 | 1915 | int cmd, cmd_length; |
95e34ef7 | 1916 | |
2c0e48e5 AM |
1917 | if (ptr + 4 > maxptr) |
1918 | goto corrupt_etir; | |
1919 | ||
1920 | cmd = bfd_getl16 (ptr); | |
1921 | cmd_length = bfd_getl16 (ptr + 2); | |
95e34ef7 | 1922 | |
76800cba | 1923 | /* PR 21589 and 21579: Check for a corrupt ETIR record. */ |
2c0e48e5 | 1924 | if (cmd_length < 4 || ptr + cmd_length > maxptr) |
c53d2e6d NC |
1925 | { |
1926 | corrupt_etir: | |
38f14ab8 | 1927 | _bfd_error_handler (_("corrupt ETIR record encountered")); |
c53d2e6d | 1928 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 1929 | return false; |
c53d2e6d | 1930 | } |
2c0e48e5 | 1931 | ptr += 4; |
2fdb65f2 | 1932 | cmd_length -= 4; |
c53d2e6d | 1933 | |
76800cba NC |
1934 | #if VMS_DEBUG |
1935 | _bfd_vms_debug (4, "etir: %s(%d)\n", | |
07d6d2b8 | 1936 | _bfd_vms_etir_name (cmd), cmd); |
2fdb65f2 | 1937 | _bfd_hexdump (8, ptr, cmd_length, 0); |
76800cba NC |
1938 | #endif |
1939 | ||
95e34ef7 | 1940 | switch (cmd) |
07d6d2b8 AM |
1941 | { |
1942 | /* Stack global | |
1943 | arg: cs symbol name | |
95e34ef7 | 1944 | |
07d6d2b8 AM |
1945 | stack 32 bit value of symbol (high bits set to 0). */ |
1946 | case ETIR__C_STA_GBL: | |
2fdb65f2 | 1947 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
ab356be7 | 1948 | if (!_bfd_vms_push (abfd, op1, alpha_vms_sym_to_ctxt (h))) |
0a1b45a2 | 1949 | return false; |
07d6d2b8 | 1950 | break; |
95e34ef7 | 1951 | |
07d6d2b8 AM |
1952 | /* Stack longword |
1953 | arg: lw value | |
95e34ef7 | 1954 | |
07d6d2b8 AM |
1955 | stack 32 bit value, sign extend to 64 bit. */ |
1956 | case ETIR__C_STA_LW: | |
2fdb65f2 | 1957 | if (cmd_length < 4) |
c53d2e6d | 1958 | goto corrupt_etir; |
ab356be7 | 1959 | if (!_bfd_vms_push (abfd, bfd_getl32 (ptr), RELC_NONE)) |
0a1b45a2 | 1960 | return false; |
07d6d2b8 | 1961 | break; |
95e34ef7 | 1962 | |
07d6d2b8 AM |
1963 | /* Stack quadword |
1964 | arg: qw value | |
95e34ef7 | 1965 | |
07d6d2b8 AM |
1966 | stack 64 bit value of symbol. */ |
1967 | case ETIR__C_STA_QW: | |
2fdb65f2 | 1968 | if (cmd_length < 8) |
c53d2e6d | 1969 | goto corrupt_etir; |
ab356be7 | 1970 | if (!_bfd_vms_push (abfd, bfd_getl64 (ptr), RELC_NONE)) |
0a1b45a2 | 1971 | return false; |
07d6d2b8 | 1972 | break; |
95e34ef7 | 1973 | |
07d6d2b8 AM |
1974 | /* Stack psect base plus quadword offset |
1975 | arg: lw section index | |
1976 | qw signed quadword offset (low 32 bits) | |
95e34ef7 | 1977 | |
07d6d2b8 AM |
1978 | Stack qw argument and section index |
1979 | (see ETIR__C_STO_OFF, ETIR__C_CTL_SETRB). */ | |
1980 | case ETIR__C_STA_PQ: | |
1981 | { | |
1982 | int psect; | |
95e34ef7 | 1983 | |
2fdb65f2 | 1984 | if (cmd_length < 12) |
c53d2e6d | 1985 | goto corrupt_etir; |
07d6d2b8 AM |
1986 | psect = bfd_getl32 (ptr); |
1987 | if ((unsigned int) psect >= PRIV (section_count)) | |
1988 | { | |
4eca0228 AM |
1989 | _bfd_error_handler (_("bad section index in %s"), |
1990 | _bfd_vms_etir_name (cmd)); | |
07d6d2b8 | 1991 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 1992 | return false; |
07d6d2b8 AM |
1993 | } |
1994 | op1 = bfd_getl64 (ptr + 4); | |
ab356be7 | 1995 | if (!_bfd_vms_push (abfd, op1, psect | RELC_SEC_BASE)) |
0a1b45a2 | 1996 | return false; |
07d6d2b8 AM |
1997 | } |
1998 | break; | |
1999 | ||
2000 | case ETIR__C_STA_LI: | |
2001 | case ETIR__C_STA_MOD: | |
2002 | case ETIR__C_STA_CKARG: | |
4eca0228 AM |
2003 | _bfd_error_handler (_("unsupported STA cmd %s"), |
2004 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2005 | return false; |
07d6d2b8 AM |
2006 | break; |
2007 | ||
2008 | /* Store byte: pop stack, write byte | |
2009 | arg: -. */ | |
2010 | case ETIR__C_STO_B: | |
ab356be7 | 2011 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2012 | return false; |
07d6d2b8 AM |
2013 | if (rel1 != RELC_NONE) |
2014 | goto bad_context; | |
81699544 | 2015 | if (!image_write_b (abfd, (unsigned int) op1 & 0xff)) |
0a1b45a2 | 2016 | return false; |
07d6d2b8 AM |
2017 | break; |
2018 | ||
2019 | /* Store word: pop stack, write word | |
2020 | arg: -. */ | |
2021 | case ETIR__C_STO_W: | |
ab356be7 | 2022 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2023 | return false; |
07d6d2b8 AM |
2024 | if (rel1 != RELC_NONE) |
2025 | goto bad_context; | |
81699544 | 2026 | if (!image_write_w (abfd, (unsigned int) op1 & 0xffff)) |
0a1b45a2 | 2027 | return false; |
07d6d2b8 AM |
2028 | break; |
2029 | ||
2030 | /* Store longword: pop stack, write longword | |
2031 | arg: -. */ | |
2032 | case ETIR__C_STO_LW: | |
ab356be7 | 2033 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2034 | return false; |
07d6d2b8 AM |
2035 | if (rel1 & RELC_SEC_BASE) |
2036 | { | |
2037 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2038 | rel1 = RELC_REL; | |
2039 | } | |
2040 | else if (rel1 & RELC_SHR_BASE) | |
2041 | { | |
96d3b80f | 2042 | if (!alpha_vms_add_fixup_lr (info, rel1 & RELC_MASK, op1)) |
0a1b45a2 | 2043 | return false; |
07d6d2b8 AM |
2044 | rel1 = RELC_NONE; |
2045 | } | |
2046 | if (rel1 != RELC_NONE) | |
2047 | { | |
2048 | if (rel1 != RELC_REL) | |
2049 | abort (); | |
96d3b80f | 2050 | if (!alpha_vms_add_lw_reloc (info)) |
0a1b45a2 | 2051 | return false; |
07d6d2b8 | 2052 | } |
81699544 | 2053 | if (!image_write_l (abfd, op1)) |
0a1b45a2 | 2054 | return false; |
07d6d2b8 AM |
2055 | break; |
2056 | ||
2057 | /* Store quadword: pop stack, write quadword | |
2058 | arg: -. */ | |
2059 | case ETIR__C_STO_QW: | |
ab356be7 | 2060 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2061 | return false; |
07d6d2b8 AM |
2062 | if (rel1 & RELC_SEC_BASE) |
2063 | { | |
2064 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2065 | rel1 = RELC_REL; | |
2066 | } | |
2067 | else if (rel1 & RELC_SHR_BASE) | |
2068 | abort (); | |
2069 | if (rel1 != RELC_NONE) | |
2070 | { | |
2071 | if (rel1 != RELC_REL) | |
2072 | abort (); | |
96d3b80f | 2073 | if (!alpha_vms_add_qw_reloc (info)) |
0a1b45a2 | 2074 | return false; |
07d6d2b8 | 2075 | } |
81699544 | 2076 | if (!image_write_q (abfd, op1)) |
0a1b45a2 | 2077 | return false; |
07d6d2b8 AM |
2078 | break; |
2079 | ||
2080 | /* Store immediate repeated: pop stack for repeat count | |
2081 | arg: lw byte count | |
2082 | da data. */ | |
2083 | case ETIR__C_STO_IMMR: | |
2084 | { | |
2085 | int size; | |
95e34ef7 | 2086 | |
2fdb65f2 | 2087 | if (cmd_length < 4) |
c53d2e6d | 2088 | goto corrupt_etir; |
07d6d2b8 | 2089 | size = bfd_getl32 (ptr); |
2fdb65f2 AM |
2090 | if (size > cmd_length - 4) |
2091 | goto corrupt_etir; | |
ab356be7 | 2092 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2093 | return false; |
07d6d2b8 AM |
2094 | if (rel1 != RELC_NONE) |
2095 | goto bad_context; | |
2fdb65f2 AM |
2096 | if (size == 0) |
2097 | break; | |
2098 | op1 &= 0xffffffff; | |
07d6d2b8 | 2099 | while (op1-- > 0) |
81699544 | 2100 | if (!image_write (abfd, ptr + 4, size)) |
0a1b45a2 | 2101 | return false; |
07d6d2b8 AM |
2102 | } |
2103 | break; | |
2104 | ||
2105 | /* Store global: write symbol value | |
2106 | arg: cs global symbol name. */ | |
2107 | case ETIR__C_STO_GBL: | |
2fdb65f2 | 2108 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
07d6d2b8 AM |
2109 | if (h && h->sym) |
2110 | { | |
2111 | if (h->sym->typ == EGSD__C_SYMG) | |
2112 | { | |
96d3b80f AM |
2113 | if (!alpha_vms_add_fixup_qr (info, abfd, h->sym->owner, |
2114 | h->sym->symbol_vector)) | |
0a1b45a2 | 2115 | return false; |
07d6d2b8 AM |
2116 | op1 = 0; |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | op1 = alpha_vms_get_sym_value (h->sym->section, | |
2121 | h->sym->value); | |
96d3b80f | 2122 | if (!alpha_vms_add_qw_reloc (info)) |
0a1b45a2 | 2123 | return false; |
07d6d2b8 AM |
2124 | } |
2125 | } | |
81699544 | 2126 | if (!image_write_q (abfd, op1)) |
0a1b45a2 | 2127 | return false; |
07d6d2b8 AM |
2128 | break; |
2129 | ||
2130 | /* Store code address: write address of entry point | |
2131 | arg: cs global symbol name (procedure). */ | |
2132 | case ETIR__C_STO_CA: | |
2fdb65f2 | 2133 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
07d6d2b8 AM |
2134 | if (h && h->sym) |
2135 | { | |
2136 | if (h->sym->flags & EGSY__V_NORM) | |
2137 | { | |
2138 | /* That's really a procedure. */ | |
2139 | if (h->sym->typ == EGSD__C_SYMG) | |
2140 | { | |
96d3b80f | 2141 | if (!alpha_vms_add_fixup_ca (info, abfd, h->sym->owner)) |
0a1b45a2 | 2142 | return false; |
07d6d2b8 AM |
2143 | op1 = h->sym->symbol_vector; |
2144 | } | |
2145 | else | |
2146 | { | |
2147 | op1 = alpha_vms_get_sym_value (h->sym->code_section, | |
2148 | h->sym->code_value); | |
96d3b80f | 2149 | if (!alpha_vms_add_qw_reloc (info)) |
0a1b45a2 | 2150 | return false; |
07d6d2b8 AM |
2151 | } |
2152 | } | |
2153 | else | |
2154 | { | |
2155 | /* Symbol is not a procedure. */ | |
2156 | abort (); | |
2157 | } | |
2158 | } | |
81699544 | 2159 | if (!image_write_q (abfd, op1)) |
0a1b45a2 | 2160 | return false; |
07d6d2b8 AM |
2161 | break; |
2162 | ||
2163 | /* Store offset to psect: pop stack, add low 32 bits to base of psect | |
2164 | arg: none. */ | |
2165 | case ETIR__C_STO_OFF: | |
ab356be7 | 2166 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2167 | return false; |
07d6d2b8 AM |
2168 | |
2169 | if (!(rel1 & RELC_SEC_BASE)) | |
2170 | abort (); | |
2171 | ||
2172 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2173 | rel1 = RELC_REL; | |
81699544 | 2174 | if (!image_write_q (abfd, op1)) |
0a1b45a2 | 2175 | return false; |
07d6d2b8 AM |
2176 | break; |
2177 | ||
2178 | /* Store immediate | |
2179 | arg: lw count of bytes | |
2180 | da data. */ | |
2181 | case ETIR__C_STO_IMM: | |
2182 | { | |
2183 | unsigned int size; | |
95e34ef7 | 2184 | |
2fdb65f2 | 2185 | if (cmd_length < 4) |
c53d2e6d | 2186 | goto corrupt_etir; |
07d6d2b8 | 2187 | size = bfd_getl32 (ptr); |
81699544 | 2188 | if (!image_write (abfd, ptr + 4, size)) |
0a1b45a2 | 2189 | return false; |
07d6d2b8 AM |
2190 | } |
2191 | break; | |
2192 | ||
2193 | /* This code is 'reserved to digital' according to the openVMS | |
2194 | linker manual, however it is generated by the DEC C compiler | |
2195 | and defined in the include file. | |
2196 | FIXME, since the following is just a guess | |
2197 | store global longword: store 32bit value of symbol | |
2198 | arg: cs symbol name. */ | |
2199 | case ETIR__C_STO_GBL_LW: | |
2fdb65f2 | 2200 | _bfd_vms_get_value (abfd, ptr, ptr + cmd_length, info, &op1, &h); |
95e34ef7 | 2201 | #if 0 |
07d6d2b8 | 2202 | abort (); |
95e34ef7 | 2203 | #endif |
81699544 | 2204 | if (!image_write_l (abfd, op1)) |
0a1b45a2 | 2205 | return false; |
07d6d2b8 | 2206 | break; |
95e34ef7 | 2207 | |
07d6d2b8 AM |
2208 | case ETIR__C_STO_RB: |
2209 | case ETIR__C_STO_AB: | |
2210 | case ETIR__C_STO_LP_PSB: | |
4eca0228 AM |
2211 | _bfd_error_handler (_("%s: not supported"), |
2212 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2213 | return false; |
07d6d2b8 AM |
2214 | break; |
2215 | case ETIR__C_STO_HINT_GBL: | |
2216 | case ETIR__C_STO_HINT_PS: | |
4eca0228 AM |
2217 | _bfd_error_handler (_("%s: not implemented"), |
2218 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2219 | return false; |
07d6d2b8 | 2220 | break; |
95e34ef7 | 2221 | |
07d6d2b8 AM |
2222 | /* 200 Store-conditional Linkage Pair |
2223 | arg: none. */ | |
2224 | case ETIR__C_STC_LP: | |
95e34ef7 | 2225 | |
07d6d2b8 AM |
2226 | /* 202 Store-conditional Address at global address |
2227 | lw linkage index | |
2228 | cs global name. */ | |
95e34ef7 | 2229 | |
07d6d2b8 | 2230 | case ETIR__C_STC_GBL: |
95e34ef7 | 2231 | |
07d6d2b8 AM |
2232 | /* 203 Store-conditional Code Address at global address |
2233 | lw linkage index | |
2234 | cs procedure name. */ | |
2235 | case ETIR__C_STC_GCA: | |
95e34ef7 | 2236 | |
07d6d2b8 AM |
2237 | /* 204 Store-conditional Address at psect + offset |
2238 | lw linkage index | |
2239 | lw psect index | |
2240 | qw offset. */ | |
2241 | case ETIR__C_STC_PS: | |
4eca0228 AM |
2242 | _bfd_error_handler (_("%s: not supported"), |
2243 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2244 | return false; |
07d6d2b8 AM |
2245 | break; |
2246 | ||
2247 | /* 201 Store-conditional Linkage Pair with Procedure Signature | |
2248 | lw linkage index | |
2249 | cs procedure name | |
2250 | by signature length | |
2251 | da signature. */ | |
2252 | ||
2253 | case ETIR__C_STC_LP_PSB: | |
2fdb65f2 AM |
2254 | if (cmd_length < 4) |
2255 | goto corrupt_etir; | |
2256 | _bfd_vms_get_value (abfd, ptr + 4, ptr + cmd_length, info, &op1, &h); | |
07d6d2b8 AM |
2257 | if (h && h->sym) |
2258 | { | |
2259 | if (h->sym->typ == EGSD__C_SYMG) | |
2260 | { | |
96d3b80f | 2261 | if (!alpha_vms_add_fixup_lp (info, abfd, h->sym->owner)) |
0a1b45a2 | 2262 | return false; |
07d6d2b8 AM |
2263 | op1 = h->sym->symbol_vector; |
2264 | op2 = 0; | |
2265 | } | |
2266 | else | |
2267 | { | |
2268 | op1 = alpha_vms_get_sym_value (h->sym->code_section, | |
2269 | h->sym->code_value); | |
2270 | op2 = alpha_vms_get_sym_value (h->sym->section, | |
2271 | h->sym->value); | |
2272 | } | |
2273 | } | |
2274 | else | |
2275 | { | |
2276 | /* Undefined symbol. */ | |
2277 | op1 = 0; | |
2278 | op2 = 0; | |
2279 | } | |
81699544 AM |
2280 | if (!image_write_q (abfd, op1) |
2281 | || !image_write_q (abfd, op2)) | |
0a1b45a2 | 2282 | return false; |
07d6d2b8 AM |
2283 | break; |
2284 | ||
2285 | /* 205 Store-conditional NOP at address of global | |
2286 | arg: none. */ | |
2287 | case ETIR__C_STC_NOP_GBL: | |
2288 | /* ALPHA_R_NOP */ | |
2289 | ||
2290 | /* 207 Store-conditional BSR at global address | |
2291 | arg: none. */ | |
2292 | ||
2293 | case ETIR__C_STC_BSR_GBL: | |
2294 | /* ALPHA_R_BSR */ | |
2295 | ||
2296 | /* 209 Store-conditional LDA at global address | |
2297 | arg: none. */ | |
2298 | ||
2299 | case ETIR__C_STC_LDA_GBL: | |
2300 | /* ALPHA_R_LDA */ | |
2301 | ||
2302 | /* 211 Store-conditional BSR or Hint at global address | |
2303 | arg: none. */ | |
2304 | ||
2305 | case ETIR__C_STC_BOH_GBL: | |
2306 | /* Currentl ignored. */ | |
2307 | break; | |
2308 | ||
2309 | /* 213 Store-conditional NOP,BSR or HINT at global address | |
2310 | arg: none. */ | |
2311 | ||
2312 | case ETIR__C_STC_NBH_GBL: | |
2313 | ||
2314 | /* 206 Store-conditional NOP at pect + offset | |
2315 | arg: none. */ | |
2316 | ||
2317 | case ETIR__C_STC_NOP_PS: | |
2318 | ||
2319 | /* 208 Store-conditional BSR at pect + offset | |
2320 | arg: none. */ | |
2321 | ||
2322 | case ETIR__C_STC_BSR_PS: | |
2323 | ||
2324 | /* 210 Store-conditional LDA at psect + offset | |
2325 | arg: none. */ | |
2326 | ||
2327 | case ETIR__C_STC_LDA_PS: | |
2328 | ||
2329 | /* 212 Store-conditional BSR or Hint at pect + offset | |
2330 | arg: none. */ | |
2331 | ||
2332 | case ETIR__C_STC_BOH_PS: | |
2333 | ||
2334 | /* 214 Store-conditional NOP, BSR or HINT at psect + offset | |
2335 | arg: none. */ | |
2336 | case ETIR__C_STC_NBH_PS: | |
695344c0 | 2337 | _bfd_error_handler (_("%s: not supported"), |
4eca0228 | 2338 | _bfd_vms_etir_name (cmd)); |
0a1b45a2 | 2339 | return false; |
07d6d2b8 AM |
2340 | break; |
2341 | ||
2342 | /* Det relocation base: pop stack, set image location counter | |
2343 | arg: none. */ | |
2344 | case ETIR__C_CTL_SETRB: | |
ab356be7 | 2345 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2346 | return false; |
07d6d2b8 AM |
2347 | if (!(rel1 & RELC_SEC_BASE)) |
2348 | abort (); | |
2349 | image_set_ptr (abfd, op1, rel1 & RELC_MASK, info); | |
2350 | break; | |
2351 | ||
2352 | /* Augment relocation base: increment image location counter by offset | |
2353 | arg: lw offset value. */ | |
2354 | case ETIR__C_CTL_AUGRB: | |
2fdb65f2 | 2355 | if (cmd_length < 4) |
c53d2e6d | 2356 | goto corrupt_etir; |
07d6d2b8 AM |
2357 | op1 = bfd_getl32 (ptr); |
2358 | image_inc_ptr (abfd, op1); | |
2359 | break; | |
2360 | ||
2361 | /* Define location: pop index, save location counter under index | |
2362 | arg: none. */ | |
2363 | case ETIR__C_CTL_DFLOC: | |
ab356be7 | 2364 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2365 | return false; |
07d6d2b8 AM |
2366 | if (rel1 != RELC_NONE) |
2367 | goto bad_context; | |
9cb56943 | 2368 | if (!dst_define_location (abfd, op1)) |
0a1b45a2 | 2369 | return false; |
07d6d2b8 AM |
2370 | break; |
2371 | ||
2372 | /* Set location: pop index, restore location counter from index | |
2373 | arg: none. */ | |
2374 | case ETIR__C_CTL_STLOC: | |
ab356be7 | 2375 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2376 | return false; |
07d6d2b8 AM |
2377 | if (rel1 != RELC_NONE) |
2378 | goto bad_context; | |
7bac4137 AM |
2379 | if (!dst_restore_location (abfd, op1)) |
2380 | { | |
2381 | bfd_set_error (bfd_error_bad_value); | |
2382 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STLOC"); | |
0a1b45a2 | 2383 | return false; |
7bac4137 | 2384 | } |
07d6d2b8 AM |
2385 | break; |
2386 | ||
2387 | /* Stack defined location: pop index, push location counter from index | |
2388 | arg: none. */ | |
2389 | case ETIR__C_CTL_STKDL: | |
ab356be7 | 2390 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2391 | return false; |
07d6d2b8 AM |
2392 | if (rel1 != RELC_NONE) |
2393 | goto bad_context; | |
7bac4137 AM |
2394 | if (!dst_retrieve_location (abfd, &op1)) |
2395 | { | |
2396 | bfd_set_error (bfd_error_bad_value); | |
2397 | _bfd_error_handler (_("invalid %s"), "ETIR__C_CTL_STKDL"); | |
0a1b45a2 | 2398 | return false; |
7bac4137 AM |
2399 | } |
2400 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) | |
0a1b45a2 | 2401 | return false; |
07d6d2b8 AM |
2402 | break; |
2403 | ||
2404 | case ETIR__C_OPR_NOP: /* No-op. */ | |
2405 | break; | |
2406 | ||
2407 | case ETIR__C_OPR_ADD: /* Add. */ | |
ab356be7 AM |
2408 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2409 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2410 | return false; |
07d6d2b8 AM |
2411 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2412 | rel1 = rel2; | |
2413 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) | |
2414 | goto bad_context; | |
ab356be7 | 2415 | if (!_bfd_vms_push (abfd, op1 + op2, rel1)) |
0a1b45a2 | 2416 | return false; |
07d6d2b8 AM |
2417 | break; |
2418 | ||
2419 | case ETIR__C_OPR_SUB: /* Subtract. */ | |
ab356be7 AM |
2420 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2421 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2422 | return false; |
07d6d2b8 AM |
2423 | if (rel1 == RELC_NONE && rel2 != RELC_NONE) |
2424 | rel1 = rel2; | |
2425 | else if ((rel1 & RELC_SEC_BASE) && (rel2 & RELC_SEC_BASE)) | |
2426 | { | |
2427 | op1 = alpha_vms_fix_sec_rel (abfd, info, rel1, op1); | |
2428 | op2 = alpha_vms_fix_sec_rel (abfd, info, rel2, op2); | |
2429 | rel1 = RELC_NONE; | |
2430 | } | |
2431 | else if (rel1 != RELC_NONE && rel2 != RELC_NONE) | |
2432 | goto bad_context; | |
ab356be7 | 2433 | if (!_bfd_vms_push (abfd, op2 - op1, rel1)) |
0a1b45a2 | 2434 | return false; |
07d6d2b8 AM |
2435 | break; |
2436 | ||
2437 | case ETIR__C_OPR_MUL: /* Multiply. */ | |
ab356be7 AM |
2438 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2439 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2440 | return false; |
07d6d2b8 AM |
2441 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2442 | goto bad_context; | |
ab356be7 | 2443 | if (!_bfd_vms_push (abfd, op1 * op2, RELC_NONE)) |
0a1b45a2 | 2444 | return false; |
07d6d2b8 AM |
2445 | break; |
2446 | ||
2447 | case ETIR__C_OPR_DIV: /* Divide. */ | |
ab356be7 AM |
2448 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2449 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2450 | return false; |
07d6d2b8 AM |
2451 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2452 | goto bad_context; | |
48e5bada | 2453 | if (op1 == 0) |
ab356be7 | 2454 | { |
48e5bada AM |
2455 | /* Divide by zero is supposed to give a result of zero, |
2456 | and a non-fatal warning message. */ | |
2457 | _bfd_error_handler (_("%s divide by zero"), "ETIR__C_OPR_DIV"); | |
ab356be7 | 2458 | if (!_bfd_vms_push (abfd, 0, RELC_NONE)) |
0a1b45a2 | 2459 | return false; |
ab356be7 | 2460 | } |
07d6d2b8 | 2461 | else |
ab356be7 AM |
2462 | { |
2463 | if (!_bfd_vms_push (abfd, op2 / op1, RELC_NONE)) | |
0a1b45a2 | 2464 | return false; |
ab356be7 | 2465 | } |
07d6d2b8 AM |
2466 | break; |
2467 | ||
2468 | case ETIR__C_OPR_AND: /* Logical AND. */ | |
ab356be7 AM |
2469 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2470 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2471 | return false; |
07d6d2b8 AM |
2472 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2473 | goto bad_context; | |
ab356be7 | 2474 | if (!_bfd_vms_push (abfd, op1 & op2, RELC_NONE)) |
0a1b45a2 | 2475 | return false; |
07d6d2b8 AM |
2476 | break; |
2477 | ||
2478 | case ETIR__C_OPR_IOR: /* Logical inclusive OR. */ | |
ab356be7 AM |
2479 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2480 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2481 | return false; |
07d6d2b8 AM |
2482 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2483 | goto bad_context; | |
ab356be7 | 2484 | if (!_bfd_vms_push (abfd, op1 | op2, RELC_NONE)) |
0a1b45a2 | 2485 | return false; |
07d6d2b8 AM |
2486 | break; |
2487 | ||
2488 | case ETIR__C_OPR_EOR: /* Logical exclusive OR. */ | |
ab356be7 AM |
2489 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2490 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2491 | return false; |
07d6d2b8 AM |
2492 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2493 | goto bad_context; | |
ab356be7 | 2494 | if (!_bfd_vms_push (abfd, op1 ^ op2, RELC_NONE)) |
0a1b45a2 | 2495 | return false; |
07d6d2b8 AM |
2496 | break; |
2497 | ||
2498 | case ETIR__C_OPR_NEG: /* Negate. */ | |
ab356be7 | 2499 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2500 | return false; |
07d6d2b8 AM |
2501 | if (rel1 != RELC_NONE) |
2502 | goto bad_context; | |
ab356be7 | 2503 | if (!_bfd_vms_push (abfd, -op1, RELC_NONE)) |
0a1b45a2 | 2504 | return false; |
07d6d2b8 AM |
2505 | break; |
2506 | ||
2507 | case ETIR__C_OPR_COM: /* Complement. */ | |
ab356be7 | 2508 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2509 | return false; |
07d6d2b8 AM |
2510 | if (rel1 != RELC_NONE) |
2511 | goto bad_context; | |
ab356be7 | 2512 | if (!_bfd_vms_push (abfd, ~op1, RELC_NONE)) |
0a1b45a2 | 2513 | return false; |
07d6d2b8 AM |
2514 | break; |
2515 | ||
2516 | case ETIR__C_OPR_ASH: /* Arithmetic shift. */ | |
ab356be7 AM |
2517 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2518 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2519 | return false; |
07d6d2b8 AM |
2520 | if (rel1 != RELC_NONE || rel2 != RELC_NONE) |
2521 | { | |
2522 | bad_context: | |
4eca0228 AM |
2523 | _bfd_error_handler (_("invalid use of %s with contexts"), |
2524 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2525 | return false; |
07d6d2b8 | 2526 | } |
f8b1e5f6 AM |
2527 | if ((bfd_signed_vma) op2 < 0) |
2528 | { | |
2529 | /* Shift right. */ | |
2530 | bfd_vma sign; | |
2531 | op2 = -op2; | |
2532 | if (op2 >= CHAR_BIT * sizeof (op1)) | |
2533 | op2 = CHAR_BIT * sizeof (op1) - 1; | |
2534 | /* op1 = (bfd_signed_vma) op1 >> op2; */ | |
2535 | sign = op1 & ((bfd_vma) 1 << (CHAR_BIT * sizeof (op1) - 1)); | |
2536 | op1 >>= op2; | |
2537 | sign >>= op2; | |
2538 | op1 = (op1 ^ sign) - sign; | |
2539 | } | |
2540 | else | |
2541 | { | |
2542 | /* Shift left. */ | |
2543 | if (op2 >= CHAR_BIT * sizeof (op1)) | |
2544 | op1 = 0; | |
2545 | else | |
2546 | op1 <<= op2; | |
2547 | } | |
ab356be7 | 2548 | if (!_bfd_vms_push (abfd, op1, RELC_NONE)) /* FIXME: sym. */ |
0a1b45a2 | 2549 | return false; |
07d6d2b8 AM |
2550 | break; |
2551 | ||
2552 | case ETIR__C_OPR_INSV: /* Insert field. */ | |
2553 | case ETIR__C_OPR_USH: /* Unsigned shift. */ | |
2554 | case ETIR__C_OPR_ROT: /* Rotate. */ | |
2555 | case ETIR__C_OPR_REDEF: /* Redefine symbol to current location. */ | |
2556 | case ETIR__C_OPR_DFLIT: /* Define a literal. */ | |
4eca0228 AM |
2557 | _bfd_error_handler (_("%s: not supported"), |
2558 | _bfd_vms_etir_name (cmd)); | |
0a1b45a2 | 2559 | return false; |
07d6d2b8 AM |
2560 | break; |
2561 | ||
2562 | case ETIR__C_OPR_SEL: /* Select. */ | |
ab356be7 | 2563 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) |
0a1b45a2 | 2564 | return false; |
07d6d2b8 | 2565 | if (op1 & 0x01L) |
ab356be7 AM |
2566 | { |
2567 | if (!_bfd_vms_pop (abfd, &op1, &rel1)) | |
0a1b45a2 | 2568 | return false; |
ab356be7 | 2569 | } |
07d6d2b8 AM |
2570 | else |
2571 | { | |
ab356be7 AM |
2572 | if (!_bfd_vms_pop (abfd, &op1, &rel1) |
2573 | || !_bfd_vms_pop (abfd, &op2, &rel2)) | |
0a1b45a2 | 2574 | return false; |
ab356be7 | 2575 | if (!_bfd_vms_push (abfd, op1, rel1)) |
0a1b45a2 | 2576 | return false; |
07d6d2b8 AM |
2577 | } |
2578 | break; | |
2579 | ||
2580 | default: | |
4eca0228 | 2581 | _bfd_error_handler (_("reserved cmd %d"), cmd); |
0a1b45a2 | 2582 | return false; |
07d6d2b8 AM |
2583 | break; |
2584 | } | |
95e34ef7 | 2585 | |
2fdb65f2 | 2586 | ptr += cmd_length; |
95e34ef7 TG |
2587 | } |
2588 | ||
0a1b45a2 | 2589 | return true; |
95e34ef7 TG |
2590 | } |
2591 | ||
2592 | /* Process EDBG/ETBT record. | |
2593 | Return TRUE on success, FALSE on error */ | |
2594 | ||
0a1b45a2 | 2595 | static bool |
95e34ef7 TG |
2596 | vms_slurp_debug (bfd *abfd) |
2597 | { | |
2598 | asection *section = PRIV (dst_section); | |
2599 | ||
2600 | if (section == NULL) | |
2601 | { | |
2602 | /* We have no way to find out beforehand how much debug info there | |
2603 | is in an object file, so pick an initial amount and grow it as | |
2604 | needed later. */ | |
2605 | flagword flags = SEC_HAS_CONTENTS | SEC_DEBUGGING | SEC_RELOC | |
07d6d2b8 | 2606 | | SEC_IN_MEMORY; |
95e34ef7 TG |
2607 | |
2608 | section = bfd_make_section (abfd, "$DST$"); | |
2609 | if (!section) | |
0a1b45a2 | 2610 | return false; |
fd361982 | 2611 | if (!bfd_set_section_flags (section, flags)) |
0a1b45a2 | 2612 | return false; |
95e34ef7 TG |
2613 | PRIV (dst_section) = section; |
2614 | } | |
2615 | ||
2616 | PRIV (image_section) = section; | |
2617 | PRIV (image_offset) = section->size; | |
95e34ef7 TG |
2618 | |
2619 | if (!_bfd_vms_slurp_etir (abfd, NULL)) | |
0a1b45a2 | 2620 | return false; |
95e34ef7 | 2621 | |
44273c5b | 2622 | section->size = PRIV (image_offset); |
0a1b45a2 | 2623 | return true; |
95e34ef7 TG |
2624 | } |
2625 | ||
2626 | /* Process EDBG record. | |
2627 | Return TRUE on success, FALSE on error. */ | |
2628 | ||
0a1b45a2 | 2629 | static bool |
95e34ef7 TG |
2630 | _bfd_vms_slurp_edbg (bfd *abfd) |
2631 | { | |
2632 | vms_debug2 ((2, "EDBG\n")); | |
2633 | ||
44273c5b | 2634 | abfd->flags |= HAS_DEBUG | HAS_LINENO; |
95e34ef7 TG |
2635 | |
2636 | return vms_slurp_debug (abfd); | |
2637 | } | |
2638 | ||
2639 | /* Process ETBT record. | |
2640 | Return TRUE on success, FALSE on error. */ | |
2641 | ||
0a1b45a2 | 2642 | static bool |
95e34ef7 TG |
2643 | _bfd_vms_slurp_etbt (bfd *abfd) |
2644 | { | |
2645 | vms_debug2 ((2, "ETBT\n")); | |
2646 | ||
2647 | abfd->flags |= HAS_LINENO; | |
2648 | ||
2649 | return vms_slurp_debug (abfd); | |
2650 | } | |
2651 | ||
2652 | /* Process EEOM record. | |
2653 | Return TRUE on success, FALSE on error. */ | |
2654 | ||
0a1b45a2 | 2655 | static bool |
95e34ef7 TG |
2656 | _bfd_vms_slurp_eeom (bfd *abfd) |
2657 | { | |
2658 | struct vms_eeom *eeom = (struct vms_eeom *) PRIV (recrd.rec); | |
2659 | ||
2660 | vms_debug2 ((2, "EEOM\n")); | |
2661 | ||
ca4cf9b9 NC |
2662 | /* PR 21813: Check for an undersized record. */ |
2663 | if (PRIV (recrd.buf_size) < sizeof (* eeom)) | |
2664 | { | |
38f14ab8 | 2665 | _bfd_error_handler (_("corrupt EEOM record - size is too small")); |
ca4cf9b9 | 2666 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 2667 | return false; |
ca4cf9b9 NC |
2668 | } |
2669 | ||
95e34ef7 TG |
2670 | PRIV (eom_data).eom_l_total_lps = bfd_getl32 (eeom->total_lps); |
2671 | PRIV (eom_data).eom_w_comcod = bfd_getl16 (eeom->comcod); | |
2672 | if (PRIV (eom_data).eom_w_comcod > 1) | |
2673 | { | |
38f14ab8 | 2674 | _bfd_error_handler (_("object module not error-free !")); |
95e34ef7 | 2675 | bfd_set_error (bfd_error_bad_value); |
0a1b45a2 | 2676 | return false; |
95e34ef7 TG |
2677 | } |
2678 | ||
0a1b45a2 | 2679 | PRIV (eom_data).eom_has_transfer = false; |
95e34ef7 TG |
2680 | if (PRIV (recrd.rec_size) > 10) |
2681 | { | |
0a1b45a2 | 2682 | PRIV (eom_data).eom_has_transfer = true; |
95e34ef7 TG |
2683 | PRIV (eom_data).eom_b_tfrflg = eeom->tfrflg; |
2684 | PRIV (eom_data).eom_l_psindx = bfd_getl32 (eeom->psindx); | |
2685 | PRIV (eom_data).eom_l_tfradr = bfd_getl32 (eeom->tfradr); | |
2686 | ||
2687 | abfd->start_address = PRIV (eom_data).eom_l_tfradr; | |
2688 | } | |
0a1b45a2 | 2689 | return true; |
95e34ef7 TG |
2690 | } |
2691 | ||
2692 | /* Slurp an ordered set of VMS object records. Return FALSE on error. */ | |
2693 | ||
0a1b45a2 | 2694 | static bool |
95e34ef7 TG |
2695 | _bfd_vms_slurp_object_records (bfd * abfd) |
2696 | { | |
0a1b45a2 | 2697 | bool ok; |
44273c5b | 2698 | int type; |
95e34ef7 TG |
2699 | |
2700 | do | |
2701 | { | |
2702 | vms_debug2 ((7, "reading at %08lx\n", (unsigned long)bfd_tell (abfd))); | |
2703 | ||
44273c5b TG |
2704 | type = _bfd_vms_get_object_record (abfd); |
2705 | if (type < 0) | |
95e34ef7 TG |
2706 | { |
2707 | vms_debug2 ((2, "next_record failed\n")); | |
0a1b45a2 | 2708 | return false; |
95e34ef7 TG |
2709 | } |
2710 | ||
95e34ef7 TG |
2711 | switch (type) |
2712 | { | |
07d6d2b8 | 2713 | case EOBJ__C_EMH: |
f75fbe8a | 2714 | ok = _bfd_vms_slurp_ehdr (abfd); |
07d6d2b8 AM |
2715 | break; |
2716 | case EOBJ__C_EEOM: | |
f75fbe8a | 2717 | ok = _bfd_vms_slurp_eeom (abfd); |
07d6d2b8 AM |
2718 | break; |
2719 | case EOBJ__C_EGSD: | |
f75fbe8a | 2720 | ok = _bfd_vms_slurp_egsd (abfd); |
07d6d2b8 AM |
2721 | break; |
2722 | case EOBJ__C_ETIR: | |
0a1b45a2 | 2723 | ok = true; /* _bfd_vms_slurp_etir (abfd); */ |
07d6d2b8 AM |
2724 | break; |
2725 | case EOBJ__C_EDBG: | |
f75fbe8a | 2726 | ok = _bfd_vms_slurp_edbg (abfd); |
07d6d2b8 AM |
2727 | break; |
2728 | case EOBJ__C_ETBT: | |
f75fbe8a | 2729 | ok = _bfd_vms_slurp_etbt (abfd); |
07d6d2b8 AM |
2730 | break; |
2731 | default: | |
0a1b45a2 | 2732 | ok = false; |
95e34ef7 | 2733 | } |
f75fbe8a | 2734 | if (!ok) |
95e34ef7 TG |
2735 | { |
2736 | vms_debug2 ((2, "slurp type %d failed\n", type)); | |
0a1b45a2 | 2737 | return false; |
95e34ef7 TG |
2738 | } |
2739 | } | |
2740 | while (type != EOBJ__C_EEOM); | |
2741 | ||
0a1b45a2 | 2742 | return true; |
95e34ef7 TG |
2743 | } |
2744 | ||
2745 | /* Initialize private data */ | |
0a1b45a2 | 2746 | static bool |
95e34ef7 TG |
2747 | vms_initialize (bfd * abfd) |
2748 | { | |
986f0783 | 2749 | size_t amt; |
95e34ef7 TG |
2750 | |
2751 | amt = sizeof (struct vms_private_data_struct); | |
2752 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
2753 | if (abfd->tdata.any == NULL) | |
0a1b45a2 | 2754 | return false; |
95e34ef7 TG |
2755 | |
2756 | PRIV (recrd.file_format) = FF_UNKNOWN; | |
2757 | ||
2758 | amt = sizeof (struct stack_struct) * STACKSIZE; | |
2759 | PRIV (stack) = bfd_alloc (abfd, amt); | |
2760 | if (PRIV (stack) == NULL) | |
2761 | goto error_ret1; | |
2762 | ||
0a1b45a2 | 2763 | return true; |
95e34ef7 TG |
2764 | |
2765 | error_ret1: | |
2766 | bfd_release (abfd, abfd->tdata.any); | |
2767 | abfd->tdata.any = NULL; | |
0a1b45a2 | 2768 | return false; |
95e34ef7 TG |
2769 | } |
2770 | ||
a7ac9aa5 AM |
2771 | /* Free malloc'd memory. */ |
2772 | ||
2773 | static void | |
2774 | alpha_vms_free_private (bfd *abfd) | |
2775 | { | |
2776 | struct module *module; | |
2777 | ||
2778 | free (PRIV (recrd.buf)); | |
2779 | free (PRIV (sections)); | |
2780 | free (PRIV (syms)); | |
2781 | free (PRIV (dst_ptr_offsets)); | |
2782 | ||
2783 | for (module = PRIV (modules); module; module = module->next) | |
2784 | free (module->file_table); | |
2785 | } | |
2786 | ||
95e34ef7 TG |
2787 | /* Check the format for a file being read. |
2788 | Return a (bfd_target *) if it's an object file or zero if not. */ | |
2789 | ||
cb001c0d | 2790 | static bfd_cleanup |
95e34ef7 TG |
2791 | alpha_vms_object_p (bfd *abfd) |
2792 | { | |
8185f55c | 2793 | void *tdata_save = abfd->tdata.any; |
95e34ef7 TG |
2794 | unsigned int test_len; |
2795 | unsigned char *buf; | |
2796 | ||
2797 | vms_debug2 ((1, "vms_object_p(%p)\n", abfd)); | |
2798 | ||
2799 | /* Allocate alpha-vms specific data. */ | |
2800 | if (!vms_initialize (abfd)) | |
a7ac9aa5 AM |
2801 | { |
2802 | abfd->tdata.any = tdata_save; | |
2803 | return NULL; | |
2804 | } | |
95e34ef7 | 2805 | |
226f9f4f | 2806 | if (bfd_seek (abfd, 0, SEEK_SET)) |
1b088c82 | 2807 | goto error_ret; |
95e34ef7 TG |
2808 | |
2809 | /* The first challenge with VMS is to discover the kind of the file. | |
2810 | ||
2811 | Image files (executable or shared images) are stored as a raw | |
2812 | stream of bytes (like on UNIX), but there is no magic number. | |
2813 | ||
2814 | Object files are written with RMS (record management service), ie | |
2815 | each records are preceeded by its length (on a word - 2 bytes), and | |
2816 | padded for word-alignment. That would be simple but when files | |
2817 | are transfered to a UNIX filesystem (using ftp), records are lost. | |
2818 | Only the raw content of the records are transfered. Fortunately, | |
2819 | the Alpha Object file format also store the length of the record | |
2820 | in the records. Is that clear ? */ | |
2821 | ||
2822 | /* Minimum is 6 bytes for objects (2 bytes size, 2 bytes record id, | |
2823 | 2 bytes size repeated) and 12 bytes for images (4 bytes major id, | |
2824 | 4 bytes minor id, 4 bytes length). */ | |
2825 | test_len = 12; | |
1b088c82 | 2826 | buf = _bfd_malloc_and_read (abfd, test_len, test_len); |
95e34ef7 TG |
2827 | if (buf == NULL) |
2828 | goto error_ret; | |
2829 | PRIV (recrd.buf) = buf; | |
2830 | PRIV (recrd.buf_size) = test_len; | |
95e34ef7 TG |
2831 | PRIV (recrd.rec) = buf; |
2832 | ||
95e34ef7 TG |
2833 | /* Is it an image? */ |
2834 | if ((bfd_getl32 (buf) == EIHD__K_MAJORID) | |
2835 | && (bfd_getl32 (buf + 4) == EIHD__K_MINORID)) | |
2836 | { | |
95e34ef7 TG |
2837 | unsigned int eisd_offset, eihs_offset; |
2838 | ||
2839 | /* Extract the header size. */ | |
2840 | PRIV (recrd.rec_size) = bfd_getl32 (buf + EIHD__L_SIZE); | |
2841 | ||
af47dcbf TG |
2842 | /* The header size is 0 for DSF files. */ |
2843 | if (PRIV (recrd.rec_size) == 0) | |
07d6d2b8 | 2844 | PRIV (recrd.rec_size) = sizeof (struct vms_eihd); |
af47dcbf | 2845 | |
8a2df5e2 | 2846 | /* PR 21813: Check for a truncated record. */ |
1b088c82 AM |
2847 | /* PR 17512: file: 7d7c57c2. */ |
2848 | if (PRIV (recrd.rec_size) < sizeof (struct vms_eihd)) | |
2849 | goto err_wrong_format; | |
95e34ef7 | 2850 | |
226f9f4f | 2851 | if (bfd_seek (abfd, 0, SEEK_SET)) |
1b088c82 | 2852 | goto error_ret; |
95e34ef7 | 2853 | |
1b088c82 AM |
2854 | free (PRIV (recrd.buf)); |
2855 | PRIV (recrd.buf) = NULL; | |
2856 | buf = _bfd_malloc_and_read (abfd, PRIV (recrd.rec_size), | |
2857 | PRIV (recrd.rec_size)); | |
2858 | if (buf == NULL) | |
2859 | goto error_ret; | |
95e34ef7 | 2860 | |
1b088c82 AM |
2861 | PRIV (recrd.buf) = buf; |
2862 | PRIV (recrd.buf_size) = PRIV (recrd.rec_size); | |
95e34ef7 TG |
2863 | PRIV (recrd.rec) = buf; |
2864 | ||
2865 | vms_debug2 ((2, "file type is image\n")); | |
2866 | ||
535b785f | 2867 | if (!_bfd_vms_slurp_eihd (abfd, &eisd_offset, &eihs_offset)) |
07d6d2b8 | 2868 | goto err_wrong_format; |
95e34ef7 | 2869 | |
535b785f | 2870 | if (!_bfd_vms_slurp_eisd (abfd, eisd_offset)) |
07d6d2b8 | 2871 | goto err_wrong_format; |
95e34ef7 TG |
2872 | |
2873 | /* EIHS is optional. */ | |
535b785f | 2874 | if (eihs_offset != 0 && !_bfd_vms_slurp_eihs (abfd, eihs_offset)) |
07d6d2b8 | 2875 | goto err_wrong_format; |
95e34ef7 TG |
2876 | } |
2877 | else | |
2878 | { | |
2879 | int type; | |
2880 | ||
2881 | /* Assume it's a module and adjust record pointer if necessary. */ | |
2882 | maybe_adjust_record_pointer_for_object (abfd); | |
2883 | ||
2884 | /* But is it really a module? */ | |
2885 | if (bfd_getl16 (PRIV (recrd.rec)) <= EOBJ__C_MAXRECTYP | |
07d6d2b8 AM |
2886 | && bfd_getl16 (PRIV (recrd.rec) + 2) <= EOBJ__C_MAXRECSIZ) |
2887 | { | |
2888 | if (vms_get_remaining_object_record (abfd, test_len) <= 0) | |
2889 | goto err_wrong_format; | |
95e34ef7 | 2890 | |
07d6d2b8 | 2891 | vms_debug2 ((2, "file type is module\n")); |
95e34ef7 | 2892 | |
07d6d2b8 AM |
2893 | type = bfd_getl16 (PRIV (recrd.rec)); |
2894 | if (type != EOBJ__C_EMH || !_bfd_vms_slurp_ehdr (abfd)) | |
2895 | goto err_wrong_format; | |
95e34ef7 | 2896 | |
07d6d2b8 AM |
2897 | if (!_bfd_vms_slurp_object_records (abfd)) |
2898 | goto err_wrong_format; | |
2899 | } | |
95e34ef7 | 2900 | else |
07d6d2b8 | 2901 | goto err_wrong_format; |
95e34ef7 TG |
2902 | } |
2903 | ||
2904 | /* Set arch_info to alpha. */ | |
2905 | ||
2906 | if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0)) | |
2907 | goto err_wrong_format; | |
2908 | ||
cb001c0d | 2909 | return alpha_vms_free_private; |
95e34ef7 TG |
2910 | |
2911 | err_wrong_format: | |
2912 | bfd_set_error (bfd_error_wrong_format); | |
2913 | ||
2914 | error_ret: | |
a7ac9aa5 | 2915 | alpha_vms_free_private (abfd); |
95e34ef7 TG |
2916 | if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL) |
2917 | bfd_release (abfd, abfd->tdata.any); | |
2918 | abfd->tdata.any = tdata_save; | |
2919 | return NULL; | |
2920 | } | |
2921 | \f | |
2922 | /* Image write. */ | |
2923 | ||
bd7b51b4 TG |
2924 | /* Write an EMH/MHD record. */ |
2925 | ||
e416bd75 | 2926 | static bool |
bd7b51b4 TG |
2927 | _bfd_vms_write_emh (bfd *abfd) |
2928 | { | |
2929 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
7fbd5f4e | 2930 | unsigned char tbuf[18]; |
bd7b51b4 TG |
2931 | |
2932 | _bfd_vms_output_alignment (recwr, 2); | |
2933 | ||
2934 | /* EMH. */ | |
2935 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
2936 | _bfd_vms_output_short (recwr, EMH__C_MHD); | |
2937 | _bfd_vms_output_short (recwr, EOBJ__C_STRLVL); | |
2938 | _bfd_vms_output_long (recwr, 0); | |
2939 | _bfd_vms_output_long (recwr, 0); | |
2940 | _bfd_vms_output_long (recwr, MAX_OUTREC_SIZE); | |
2941 | ||
2942 | /* Create module name from filename. */ | |
2943 | if (bfd_get_filename (abfd) != 0) | |
2944 | { | |
0a1b45a2 | 2945 | char *module = vms_get_module_name (bfd_get_filename (abfd), true); |
bd7b51b4 TG |
2946 | _bfd_vms_output_counted (recwr, module); |
2947 | free (module); | |
2948 | } | |
2949 | else | |
2950 | _bfd_vms_output_counted (recwr, "NONAME"); | |
2951 | ||
2952 | _bfd_vms_output_counted (recwr, BFD_VERSION_STRING); | |
7fbd5f4e | 2953 | _bfd_vms_output_dump (recwr, get_vms_time_string (tbuf), EMH_DATE_LENGTH); |
bd7b51b4 | 2954 | _bfd_vms_output_fill (recwr, 0, EMH_DATE_LENGTH); |
e416bd75 | 2955 | return _bfd_vms_output_end (abfd, recwr); |
bd7b51b4 TG |
2956 | } |
2957 | ||
2958 | /* Write an EMH/LMN record. */ | |
2959 | ||
e416bd75 | 2960 | static bool |
bd7b51b4 TG |
2961 | _bfd_vms_write_lmn (bfd *abfd, const char *name) |
2962 | { | |
2963 | char version [64]; | |
2964 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
2965 | unsigned int ver = BFD_VERSION / 10000; | |
2966 | ||
2967 | /* LMN. */ | |
2968 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
2969 | _bfd_vms_output_short (recwr, EMH__C_LNM); | |
2970 | snprintf (version, sizeof (version), "%s %d.%d.%d", name, | |
07d6d2b8 | 2971 | ver / 10000, (ver / 100) % 100, ver % 100); |
bd7b51b4 | 2972 | _bfd_vms_output_dump (recwr, (unsigned char *)version, strlen (version)); |
e416bd75 | 2973 | return _bfd_vms_output_end (abfd, recwr); |
bd7b51b4 TG |
2974 | } |
2975 | ||
2976 | ||
2977 | /* Write eom record for bfd abfd. Return FALSE on error. */ | |
2978 | ||
0a1b45a2 | 2979 | static bool |
bd7b51b4 TG |
2980 | _bfd_vms_write_eeom (bfd *abfd) |
2981 | { | |
2982 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
2983 | ||
2984 | vms_debug2 ((2, "vms_write_eeom\n")); | |
2985 | ||
2986 | _bfd_vms_output_alignment (recwr, 2); | |
2987 | ||
2988 | _bfd_vms_output_begin (recwr, EOBJ__C_EEOM); | |
f1bb0388 | 2989 | _bfd_vms_output_long (recwr, PRIV (vms_linkage_index + 1) >> 1); |
bd7b51b4 TG |
2990 | _bfd_vms_output_byte (recwr, 0); /* Completion code. */ |
2991 | _bfd_vms_output_byte (recwr, 0); /* Fill byte. */ | |
2992 | ||
2993 | if ((abfd->flags & EXEC_P) == 0 | |
2994 | && bfd_get_start_address (abfd) != (bfd_vma)-1) | |
2995 | { | |
2996 | asection *section; | |
2997 | ||
2998 | section = bfd_get_section_by_name (abfd, ".link"); | |
2999 | if (section == 0) | |
3000 | { | |
3001 | bfd_set_error (bfd_error_nonrepresentable_section); | |
0a1b45a2 | 3002 | return false; |
bd7b51b4 TG |
3003 | } |
3004 | _bfd_vms_output_short (recwr, 0); | |
1b3d1dbf | 3005 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); |
bd7b51b4 TG |
3006 | _bfd_vms_output_long (recwr, |
3007 | (unsigned long) bfd_get_start_address (abfd)); | |
3008 | _bfd_vms_output_long (recwr, 0); | |
3009 | } | |
3010 | ||
e416bd75 | 3011 | return _bfd_vms_output_end (abfd, recwr); |
bd7b51b4 TG |
3012 | } |
3013 | ||
96d3b80f | 3014 | static void * |
95e34ef7 TG |
3015 | vector_grow1 (struct vector_type *vec, size_t elsz) |
3016 | { | |
96d3b80f | 3017 | if (vec->nbr_el >= vec->max_el) |
95e34ef7 | 3018 | { |
96d3b80f AM |
3019 | if (vec->max_el == 0) |
3020 | { | |
3021 | vec->max_el = 16; | |
1f4361a7 | 3022 | vec->els = bfd_malloc (vec->max_el * elsz); |
96d3b80f AM |
3023 | } |
3024 | else | |
3025 | { | |
1f4361a7 | 3026 | size_t amt; |
96d3b80f AM |
3027 | if (vec->max_el > -1u / 2) |
3028 | { | |
3029 | bfd_set_error (bfd_error_file_too_big); | |
3030 | return NULL; | |
3031 | } | |
3032 | vec->max_el *= 2; | |
1f4361a7 AM |
3033 | if (_bfd_mul_overflow (vec->max_el, elsz, &amt)) |
3034 | { | |
3035 | bfd_set_error (bfd_error_file_too_big); | |
3036 | return NULL; | |
3037 | } | |
9cb56943 | 3038 | vec->els = bfd_realloc_or_free (vec->els, amt); |
96d3b80f | 3039 | } |
95e34ef7 | 3040 | } |
96d3b80f AM |
3041 | if (vec->els == NULL) |
3042 | return NULL; | |
3043 | return (char *) vec->els + elsz * vec->nbr_el++; | |
95e34ef7 TG |
3044 | } |
3045 | ||
3046 | /* Bump ABFD file position to next block. */ | |
3047 | ||
3048 | static void | |
3049 | alpha_vms_file_position_block (bfd *abfd) | |
3050 | { | |
3051 | /* Next block. */ | |
3052 | PRIV (file_pos) += VMS_BLOCK_SIZE - 1; | |
3053 | PRIV (file_pos) -= (PRIV (file_pos) % VMS_BLOCK_SIZE); | |
3054 | } | |
3055 | ||
44273c5b TG |
3056 | /* Convert from internal structure SRC to external structure DST. */ |
3057 | ||
95e34ef7 TG |
3058 | static void |
3059 | alpha_vms_swap_eisd_out (struct vms_internal_eisd_map *src, | |
07d6d2b8 | 3060 | struct vms_eisd *dst) |
95e34ef7 TG |
3061 | { |
3062 | bfd_putl32 (src->u.eisd.majorid, dst->majorid); | |
3063 | bfd_putl32 (src->u.eisd.minorid, dst->minorid); | |
3064 | bfd_putl32 (src->u.eisd.eisdsize, dst->eisdsize); | |
3065 | if (src->u.eisd.eisdsize <= EISD__K_LENEND) | |
3066 | return; | |
3067 | bfd_putl32 (src->u.eisd.secsize, dst->secsize); | |
3068 | bfd_putl64 (src->u.eisd.virt_addr, dst->virt_addr); | |
3069 | bfd_putl32 (src->u.eisd.flags, dst->flags); | |
3070 | bfd_putl32 (src->u.eisd.vbn, dst->vbn); | |
3071 | dst->pfc = src->u.eisd.pfc; | |
3072 | dst->matchctl = src->u.eisd.matchctl; | |
3073 | dst->type = src->u.eisd.type; | |
3074 | dst->fill_1 = 0; | |
3075 | if (src->u.eisd.flags & EISD__M_GBL) | |
3076 | { | |
3077 | bfd_putl32 (src->u.gbl_eisd.ident, dst->ident); | |
3078 | memcpy (dst->gblnam, src->u.gbl_eisd.gblnam, | |
07d6d2b8 | 3079 | src->u.gbl_eisd.gblnam[0] + 1); |
95e34ef7 TG |
3080 | } |
3081 | } | |
3082 | ||
3083 | /* Append EISD to the list of extra eisd for ABFD. */ | |
3084 | ||
3085 | static void | |
3086 | alpha_vms_append_extra_eisd (bfd *abfd, struct vms_internal_eisd_map *eisd) | |
3087 | { | |
3088 | eisd->next = NULL; | |
3089 | if (PRIV (gbl_eisd_head) == NULL) | |
3090 | PRIV (gbl_eisd_head) = eisd; | |
3091 | else | |
3092 | PRIV (gbl_eisd_tail)->next = eisd; | |
3093 | PRIV (gbl_eisd_tail) = eisd; | |
3094 | } | |
3095 | ||
44273c5b TG |
3096 | /* Create an EISD for shared image SHRIMG. |
3097 | Return FALSE in case of error. */ | |
3098 | ||
0a1b45a2 | 3099 | static bool |
95e34ef7 TG |
3100 | alpha_vms_create_eisd_for_shared (bfd *abfd, bfd *shrimg) |
3101 | { | |
3102 | struct vms_internal_eisd_map *eisd; | |
3103 | int namlen; | |
3104 | ||
3105 | namlen = strlen (PRIV2 (shrimg, hdr_data.hdr_t_name)); | |
3106 | if (namlen + 5 > EISD__K_GBLNAMLEN) | |
3107 | { | |
3108 | /* Won't fit. */ | |
0a1b45a2 | 3109 | return false; |
95e34ef7 TG |
3110 | } |
3111 | ||
3112 | eisd = bfd_alloc (abfd, sizeof (*eisd)); | |
3113 | if (eisd == NULL) | |
0a1b45a2 | 3114 | return false; |
95e34ef7 TG |
3115 | |
3116 | /* Fill the fields. */ | |
3117 | eisd->u.gbl_eisd.common.majorid = EISD__K_MAJORID; | |
3118 | eisd->u.gbl_eisd.common.minorid = EISD__K_MINORID; | |
3119 | eisd->u.gbl_eisd.common.eisdsize = (EISD__K_LEN + 4 + namlen + 5 + 3) & ~3; | |
3120 | eisd->u.gbl_eisd.common.secsize = VMS_BLOCK_SIZE; /* Must not be 0. */ | |
3121 | eisd->u.gbl_eisd.common.virt_addr = 0; | |
3122 | eisd->u.gbl_eisd.common.flags = EISD__M_GBL; | |
3123 | eisd->u.gbl_eisd.common.vbn = 0; | |
3124 | eisd->u.gbl_eisd.common.pfc = 0; | |
3125 | eisd->u.gbl_eisd.common.matchctl = PRIV2 (shrimg, matchctl); | |
3126 | eisd->u.gbl_eisd.common.type = EISD__K_SHRPIC; | |
3127 | ||
3128 | eisd->u.gbl_eisd.ident = PRIV2 (shrimg, ident); | |
3129 | eisd->u.gbl_eisd.gblnam[0] = namlen + 4; | |
3130 | memcpy (eisd->u.gbl_eisd.gblnam + 1, PRIV2 (shrimg, hdr_data.hdr_t_name), | |
07d6d2b8 | 3131 | namlen); |
95e34ef7 TG |
3132 | memcpy (eisd->u.gbl_eisd.gblnam + 1 + namlen, "_001", 4); |
3133 | ||
3134 | /* Append it to the list. */ | |
3135 | alpha_vms_append_extra_eisd (abfd, eisd); | |
3136 | ||
0a1b45a2 | 3137 | return true; |
95e34ef7 TG |
3138 | } |
3139 | ||
44273c5b TG |
3140 | /* Create an EISD for section SEC. |
3141 | Return FALSE in case of failure. */ | |
3142 | ||
0a1b45a2 | 3143 | static bool |
95e34ef7 TG |
3144 | alpha_vms_create_eisd_for_section (bfd *abfd, asection *sec) |
3145 | { | |
3146 | struct vms_internal_eisd_map *eisd; | |
3147 | ||
3148 | /* Only for allocating section. */ | |
3149 | if (!(sec->flags & SEC_ALLOC)) | |
0a1b45a2 | 3150 | return true; |
95e34ef7 TG |
3151 | |
3152 | BFD_ASSERT (vms_section_data (sec)->eisd == NULL); | |
3153 | eisd = bfd_alloc (abfd, sizeof (*eisd)); | |
3154 | if (eisd == NULL) | |
0a1b45a2 | 3155 | return false; |
95e34ef7 TG |
3156 | vms_section_data (sec)->eisd = eisd; |
3157 | ||
3158 | /* Fill the fields. */ | |
3159 | eisd->u.eisd.majorid = EISD__K_MAJORID; | |
3160 | eisd->u.eisd.minorid = EISD__K_MINORID; | |
3161 | eisd->u.eisd.eisdsize = EISD__K_LEN; | |
3162 | eisd->u.eisd.secsize = | |
3163 | (sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); | |
3164 | eisd->u.eisd.virt_addr = sec->vma; | |
3165 | eisd->u.eisd.flags = 0; | |
3166 | eisd->u.eisd.vbn = 0; /* To be later defined. */ | |
3167 | eisd->u.eisd.pfc = 0; /* Default. */ | |
3168 | eisd->u.eisd.matchctl = EISD__K_MATALL; | |
3169 | eisd->u.eisd.type = EISD__K_NORMAL; | |
3170 | ||
3171 | if (sec->flags & SEC_CODE) | |
3172 | eisd->u.eisd.flags |= EISD__M_EXE; | |
cf6b8767 | 3173 | if (!(sec->flags & SEC_READONLY)) |
95e34ef7 TG |
3174 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; |
3175 | ||
5f101a3d TG |
3176 | /* If relocations or fixup will be applied, make this isect writeable. */ |
3177 | if (sec->flags & SEC_RELOC) | |
3178 | eisd->u.eisd.flags |= EISD__M_WRT | EISD__M_CRF; | |
3179 | ||
8185f55c | 3180 | if (!(sec->flags & SEC_HAS_CONTENTS)) |
95e34ef7 TG |
3181 | { |
3182 | eisd->u.eisd.flags |= EISD__M_DZRO; | |
3183 | eisd->u.eisd.flags &= ~EISD__M_CRF; | |
3184 | } | |
3185 | if (sec->flags & SEC_LINKER_CREATED) | |
3186 | { | |
3187 | if (strcmp (sec->name, "$FIXUP$") == 0) | |
07d6d2b8 | 3188 | eisd->u.eisd.flags |= EISD__M_FIXUPVEC; |
95e34ef7 TG |
3189 | } |
3190 | ||
3191 | /* Append it to the list. */ | |
3192 | eisd->next = NULL; | |
3193 | if (PRIV (eisd_head) == NULL) | |
3194 | PRIV (eisd_head) = eisd; | |
3195 | else | |
3196 | PRIV (eisd_tail)->next = eisd; | |
3197 | PRIV (eisd_tail) = eisd; | |
3198 | ||
0a1b45a2 | 3199 | return true; |
95e34ef7 TG |
3200 | } |
3201 | ||
44273c5b TG |
3202 | /* Layout executable ABFD and write it to the disk. |
3203 | Return FALSE in case of failure. */ | |
3204 | ||
0a1b45a2 | 3205 | static bool |
95e34ef7 TG |
3206 | alpha_vms_write_exec (bfd *abfd) |
3207 | { | |
3208 | struct vms_eihd eihd; | |
3209 | struct vms_eiha *eiha; | |
3210 | struct vms_eihi *eihi; | |
3211 | struct vms_eihs *eihs = NULL; | |
3212 | asection *sec; | |
3213 | struct vms_internal_eisd_map *first_eisd; | |
3214 | struct vms_internal_eisd_map *eisd; | |
3215 | asection *dst; | |
44273c5b | 3216 | asection *dmt; |
f9eeb9c9 TG |
3217 | file_ptr gst_filepos = 0; |
3218 | unsigned int lnkflags = 0; | |
95e34ef7 | 3219 | |
44273c5b | 3220 | /* Build the EIHD. */ |
95e34ef7 TG |
3221 | PRIV (file_pos) = EIHD__C_LENGTH; |
3222 | ||
3223 | memset (&eihd, 0, sizeof (eihd)); | |
3224 | memset (eihd.fill_2, 0xff, sizeof (eihd.fill_2)); | |
3225 | ||
3226 | bfd_putl32 (EIHD__K_MAJORID, eihd.majorid); | |
3227 | bfd_putl32 (EIHD__K_MINORID, eihd.minorid); | |
3228 | ||
3229 | bfd_putl32 (sizeof (eihd), eihd.size); | |
3230 | bfd_putl32 (0, eihd.isdoff); | |
3231 | bfd_putl32 (0, eihd.activoff); | |
3232 | bfd_putl32 (0, eihd.symdbgoff); | |
3233 | bfd_putl32 (0, eihd.imgidoff); | |
3234 | bfd_putl32 (0, eihd.patchoff); | |
3235 | bfd_putl64 (0, eihd.iafva); | |
3236 | bfd_putl32 (0, eihd.version_array_off); | |
3237 | ||
3238 | bfd_putl32 (EIHD__K_EXE, eihd.imgtype); | |
3239 | bfd_putl32 (0, eihd.subtype); | |
3240 | ||
3241 | bfd_putl32 (0, eihd.imgiocnt); | |
3242 | bfd_putl32 (-1, eihd.privreqs); | |
3243 | bfd_putl32 (-1, eihd.privreqs + 4); | |
3244 | ||
3245 | bfd_putl32 ((sizeof (eihd) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, | |
07d6d2b8 | 3246 | eihd.hdrblkcnt); |
95e34ef7 TG |
3247 | bfd_putl32 (0, eihd.ident); |
3248 | bfd_putl32 (0, eihd.sysver); | |
3249 | ||
3250 | eihd.matchctl = 0; | |
3251 | bfd_putl32 (0, eihd.symvect_size); | |
3252 | bfd_putl32 (16, eihd.virt_mem_block_size); | |
3253 | bfd_putl32 (0, eihd.ext_fixup_off); | |
3254 | bfd_putl32 (0, eihd.noopt_psect_off); | |
5cbc0eb0 | 3255 | bfd_putl16 (-1, eihd.alias); |
95e34ef7 TG |
3256 | |
3257 | /* Alloc EIHA. */ | |
3258 | eiha = (struct vms_eiha *)((char *) &eihd + PRIV (file_pos)); | |
3259 | bfd_putl32 (PRIV (file_pos), eihd.activoff); | |
3260 | PRIV (file_pos) += sizeof (struct vms_eiha); | |
3261 | ||
3262 | bfd_putl32 (sizeof (struct vms_eiha), eiha->size); | |
3263 | bfd_putl32 (0, eiha->spare); | |
46d00b8a TG |
3264 | bfd_putl64 (PRIV (transfer_address[0]), eiha->tfradr1); |
3265 | bfd_putl64 (PRIV (transfer_address[1]), eiha->tfradr2); | |
3266 | bfd_putl64 (PRIV (transfer_address[2]), eiha->tfradr3); | |
3267 | bfd_putl64 (PRIV (transfer_address[3]), eiha->tfradr4); | |
95e34ef7 TG |
3268 | bfd_putl64 (0, eiha->inishr); |
3269 | ||
3270 | /* Alloc EIHI. */ | |
3271 | eihi = (struct vms_eihi *)((char *) &eihd + PRIV (file_pos)); | |
3272 | bfd_putl32 (PRIV (file_pos), eihd.imgidoff); | |
3273 | PRIV (file_pos) += sizeof (struct vms_eihi); | |
3274 | ||
3275 | bfd_putl32 (EIHI__K_MAJORID, eihi->majorid); | |
3276 | bfd_putl32 (EIHI__K_MINORID, eihi->minorid); | |
3277 | { | |
3278 | char *module; | |
3279 | unsigned int len; | |
3280 | ||
9714ee48 | 3281 | /* Set module name. */ |
0a1b45a2 | 3282 | module = vms_get_module_name (bfd_get_filename (abfd), true); |
95e34ef7 TG |
3283 | len = strlen (module); |
3284 | if (len > sizeof (eihi->imgnam) - 1) | |
3285 | len = sizeof (eihi->imgnam) - 1; | |
3286 | eihi->imgnam[0] = len; | |
3287 | memcpy (eihi->imgnam + 1, module, len); | |
3288 | free (module); | |
3289 | } | |
9714ee48 TG |
3290 | { |
3291 | unsigned int lo; | |
3292 | unsigned int hi; | |
3293 | ||
3294 | /* Set time. */ | |
3295 | vms_get_time (&hi, &lo); | |
3296 | bfd_putl32 (lo, eihi->linktime + 0); | |
3297 | bfd_putl32 (hi, eihi->linktime + 4); | |
3298 | } | |
95e34ef7 TG |
3299 | eihi->imgid[0] = 0; |
3300 | eihi->linkid[0] = 0; | |
3301 | eihi->imgbid[0] = 0; | |
3302 | ||
3303 | /* Alloc EIHS. */ | |
44273c5b TG |
3304 | dst = PRIV (dst_section); |
3305 | dmt = bfd_get_section_by_name (abfd, "$DMT$"); | |
95e34ef7 TG |
3306 | if (dst != NULL && dst->size != 0) |
3307 | { | |
3308 | eihs = (struct vms_eihs *)((char *) &eihd + PRIV (file_pos)); | |
3309 | bfd_putl32 (PRIV (file_pos), eihd.symdbgoff); | |
3310 | PRIV (file_pos) += sizeof (struct vms_eihs); | |
3311 | ||
3312 | bfd_putl32 (EIHS__K_MAJORID, eihs->majorid); | |
3313 | bfd_putl32 (EIHS__K_MINORID, eihs->minorid); | |
3314 | bfd_putl32 (0, eihs->dstvbn); | |
3315 | bfd_putl32 (0, eihs->dstsize); | |
3316 | bfd_putl32 (0, eihs->gstvbn); | |
3317 | bfd_putl32 (0, eihs->gstsize); | |
3318 | bfd_putl32 (0, eihs->dmtvbn); | |
3319 | bfd_putl32 (0, eihs->dmtsize); | |
3320 | } | |
3321 | ||
44273c5b | 3322 | /* One EISD per section. */ |
95e34ef7 TG |
3323 | for (sec = abfd->sections; sec; sec = sec->next) |
3324 | { | |
3325 | if (!alpha_vms_create_eisd_for_section (abfd, sec)) | |
0a1b45a2 | 3326 | return false; |
95e34ef7 TG |
3327 | } |
3328 | ||
3329 | /* Merge section EIDS which extra ones. */ | |
3330 | if (PRIV (eisd_tail)) | |
3331 | PRIV (eisd_tail)->next = PRIV (gbl_eisd_head); | |
3332 | else | |
3333 | PRIV (eisd_head) = PRIV (gbl_eisd_head); | |
3334 | if (PRIV (gbl_eisd_tail)) | |
3335 | PRIV (eisd_tail) = PRIV (gbl_eisd_tail); | |
3336 | ||
3337 | first_eisd = PRIV (eisd_head); | |
3338 | ||
3339 | /* Add end of eisd. */ | |
3340 | if (first_eisd) | |
3341 | { | |
3342 | eisd = bfd_zalloc (abfd, sizeof (*eisd)); | |
3343 | if (eisd == NULL) | |
0a1b45a2 | 3344 | return false; |
95e34ef7 TG |
3345 | eisd->u.eisd.majorid = 0; |
3346 | eisd->u.eisd.minorid = 0; | |
3347 | eisd->u.eisd.eisdsize = 0; | |
3348 | alpha_vms_append_extra_eisd (abfd, eisd); | |
3349 | } | |
3350 | ||
3351 | /* Place EISD in the file. */ | |
3352 | for (eisd = first_eisd; eisd; eisd = eisd->next) | |
3353 | { | |
3354 | file_ptr room = VMS_BLOCK_SIZE - (PRIV (file_pos) % VMS_BLOCK_SIZE); | |
3355 | ||
3356 | /* First block is a little bit special: there is a word at the end. */ | |
3357 | if (PRIV (file_pos) < VMS_BLOCK_SIZE && room > 2) | |
07d6d2b8 | 3358 | room -= 2; |
95e34ef7 | 3359 | if (room < eisd->u.eisd.eisdsize + EISD__K_LENEND) |
07d6d2b8 | 3360 | alpha_vms_file_position_block (abfd); |
95e34ef7 TG |
3361 | |
3362 | eisd->file_pos = PRIV (file_pos); | |
3363 | PRIV (file_pos) += eisd->u.eisd.eisdsize; | |
3364 | ||
3365 | if (eisd->u.eisd.flags & EISD__M_FIXUPVEC) | |
07d6d2b8 | 3366 | bfd_putl64 (eisd->u.eisd.virt_addr, eihd.iafva); |
95e34ef7 TG |
3367 | } |
3368 | ||
3369 | if (first_eisd != NULL) | |
3370 | { | |
3371 | bfd_putl32 (first_eisd->file_pos, eihd.isdoff); | |
3372 | /* Real size of end of eisd marker. */ | |
3373 | PRIV (file_pos) += EISD__K_LENEND; | |
3374 | } | |
3375 | ||
3376 | bfd_putl32 (PRIV (file_pos), eihd.size); | |
3377 | bfd_putl32 ((PRIV (file_pos) + VMS_BLOCK_SIZE - 1) / VMS_BLOCK_SIZE, | |
07d6d2b8 | 3378 | eihd.hdrblkcnt); |
95e34ef7 TG |
3379 | |
3380 | /* Place sections. */ | |
3381 | for (sec = abfd->sections; sec; sec = sec->next) | |
3382 | { | |
8c8fa33c AM |
3383 | if (!(sec->flags & SEC_HAS_CONTENTS) |
3384 | || sec->contents == NULL) | |
07d6d2b8 | 3385 | continue; |
95e34ef7 TG |
3386 | |
3387 | eisd = vms_section_data (sec)->eisd; | |
3388 | ||
3389 | /* Align on a block. */ | |
3390 | alpha_vms_file_position_block (abfd); | |
3391 | sec->filepos = PRIV (file_pos); | |
3392 | ||
3393 | if (eisd != NULL) | |
07d6d2b8 | 3394 | eisd->u.eisd.vbn = (sec->filepos / VMS_BLOCK_SIZE) + 1; |
95e34ef7 TG |
3395 | |
3396 | PRIV (file_pos) += sec->size; | |
3397 | } | |
3398 | ||
5fe88cfb | 3399 | /* Update EIHS. */ |
95e34ef7 TG |
3400 | if (eihs != NULL && dst != NULL) |
3401 | { | |
3402 | bfd_putl32 ((dst->filepos / VMS_BLOCK_SIZE) + 1, eihs->dstvbn); | |
3403 | bfd_putl32 (dst->size, eihs->dstsize); | |
44273c5b TG |
3404 | |
3405 | if (dmt != NULL) | |
07d6d2b8 AM |
3406 | { |
3407 | lnkflags |= EIHD__M_DBGDMT; | |
3408 | bfd_putl32 ((dmt->filepos / VMS_BLOCK_SIZE) + 1, eihs->dmtvbn); | |
3409 | bfd_putl32 (dmt->size, eihs->dmtsize); | |
3410 | } | |
f9eeb9c9 | 3411 | if (PRIV (gsd_sym_count) != 0) |
07d6d2b8 AM |
3412 | { |
3413 | alpha_vms_file_position_block (abfd); | |
3414 | gst_filepos = PRIV (file_pos); | |
3415 | bfd_putl32 ((gst_filepos / VMS_BLOCK_SIZE) + 1, eihs->gstvbn); | |
3416 | bfd_putl32 ((PRIV (gsd_sym_count) + 4) / 5 + 4, eihs->gstsize); | |
3417 | } | |
95e34ef7 TG |
3418 | } |
3419 | ||
3420 | /* Write EISD in hdr. */ | |
3421 | for (eisd = first_eisd; eisd && eisd->file_pos < VMS_BLOCK_SIZE; | |
3422 | eisd = eisd->next) | |
3423 | alpha_vms_swap_eisd_out | |
3424 | (eisd, (struct vms_eisd *)((char *)&eihd + eisd->file_pos)); | |
3425 | ||
3426 | /* Write first block. */ | |
f9eeb9c9 | 3427 | bfd_putl32 (lnkflags, eihd.lnkflags); |
226f9f4f | 3428 | if (bfd_write (&eihd, sizeof (eihd), abfd) != sizeof (eihd)) |
0a1b45a2 | 3429 | return false; |
95e34ef7 TG |
3430 | |
3431 | /* Write remaining eisd. */ | |
3432 | if (eisd != NULL) | |
3433 | { | |
3434 | unsigned char blk[VMS_BLOCK_SIZE]; | |
3435 | struct vms_internal_eisd_map *next_eisd; | |
3436 | ||
3437 | memset (blk, 0xff, sizeof (blk)); | |
3438 | while (eisd != NULL) | |
07d6d2b8 AM |
3439 | { |
3440 | alpha_vms_swap_eisd_out | |
3441 | (eisd, | |
3442 | (struct vms_eisd *)(blk + (eisd->file_pos % VMS_BLOCK_SIZE))); | |
3443 | ||
3444 | next_eisd = eisd->next; | |
3445 | if (next_eisd == NULL | |
3446 | || (next_eisd->file_pos / VMS_BLOCK_SIZE | |
3447 | != eisd->file_pos / VMS_BLOCK_SIZE)) | |
3448 | { | |
226f9f4f | 3449 | if (bfd_write (blk, sizeof (blk), abfd) != sizeof (blk)) |
0a1b45a2 | 3450 | return false; |
95e34ef7 | 3451 | |
07d6d2b8 AM |
3452 | memset (blk, 0xff, sizeof (blk)); |
3453 | } | |
3454 | eisd = next_eisd; | |
3455 | } | |
95e34ef7 TG |
3456 | } |
3457 | ||
3458 | /* Write sections. */ | |
3459 | for (sec = abfd->sections; sec; sec = sec->next) | |
3460 | { | |
3461 | unsigned char blk[VMS_BLOCK_SIZE]; | |
3462 | bfd_size_type len; | |
3463 | ||
8c8fa33c AM |
3464 | if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS) |
3465 | || sec->contents == NULL) | |
07d6d2b8 | 3466 | continue; |
226f9f4f | 3467 | if (bfd_write (sec->contents, sec->size, abfd) != sec->size) |
0a1b45a2 | 3468 | return false; |
95e34ef7 TG |
3469 | |
3470 | /* Pad. */ | |
3471 | len = VMS_BLOCK_SIZE - sec->size % VMS_BLOCK_SIZE; | |
3472 | if (len != VMS_BLOCK_SIZE) | |
07d6d2b8 AM |
3473 | { |
3474 | memset (blk, 0, len); | |
226f9f4f | 3475 | if (bfd_write (blk, len, abfd) != len) |
0a1b45a2 | 3476 | return false; |
07d6d2b8 | 3477 | } |
95e34ef7 TG |
3478 | } |
3479 | ||
f9eeb9c9 TG |
3480 | /* Write GST. */ |
3481 | if (gst_filepos != 0) | |
3482 | { | |
3483 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3484 | unsigned int i; | |
3485 | ||
e416bd75 AM |
3486 | if (!_bfd_vms_write_emh (abfd) |
3487 | || !_bfd_vms_write_lmn (abfd, "GNU LD")) | |
3488 | return false; | |
f9eeb9c9 TG |
3489 | |
3490 | /* PSC for the absolute section. */ | |
3491 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3492 | _bfd_vms_output_long (recwr, 0); | |
3493 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); | |
3494 | _bfd_vms_output_short (recwr, 0); | |
3495 | _bfd_vms_output_short (recwr, EGPS__V_PIC | EGPS__V_LIB | EGPS__V_RD); | |
3496 | _bfd_vms_output_long (recwr, 0); | |
3497 | _bfd_vms_output_counted (recwr, ".$$ABS$$."); | |
3498 | _bfd_vms_output_end_subrec (recwr); | |
e416bd75 AM |
3499 | if (!_bfd_vms_output_end (abfd, recwr)) |
3500 | return false; | |
f9eeb9c9 TG |
3501 | |
3502 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 AM |
3503 | { |
3504 | struct vms_symbol_entry *sym = PRIV (syms)[i]; | |
3505 | bfd_vma val; | |
3506 | bfd_vma ep; | |
3507 | ||
3508 | if ((i % 5) == 0) | |
3509 | { | |
3510 | _bfd_vms_output_alignment (recwr, 8); | |
3511 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3512 | _bfd_vms_output_long (recwr, 0); | |
3513 | } | |
3514 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYMG); | |
3515 | _bfd_vms_output_short (recwr, 0); /* Data type, alignment. */ | |
3516 | _bfd_vms_output_short (recwr, sym->flags); | |
3517 | ||
3518 | if (sym->code_section) | |
3519 | ep = alpha_vms_get_sym_value (sym->code_section, sym->code_value); | |
3520 | else | |
3521 | { | |
3522 | BFD_ASSERT (sym->code_value == 0); | |
3523 | ep = 0; | |
3524 | } | |
3525 | val = alpha_vms_get_sym_value (sym->section, sym->value); | |
3526 | _bfd_vms_output_quad | |
3527 | (recwr, sym->typ == EGSD__C_SYMG ? sym->symbol_vector : val); | |
3528 | _bfd_vms_output_quad (recwr, ep); | |
3529 | _bfd_vms_output_quad (recwr, val); | |
3530 | _bfd_vms_output_long (recwr, 0); | |
3531 | _bfd_vms_output_counted (recwr, sym->name); | |
3532 | _bfd_vms_output_end_subrec (recwr); | |
e416bd75 AM |
3533 | if ((i % 5) == 4 |
3534 | && !_bfd_vms_output_end (abfd, recwr)) | |
3535 | return false; | |
07d6d2b8 | 3536 | } |
e416bd75 AM |
3537 | if ((i % 5) != 0 |
3538 | && !_bfd_vms_output_end (abfd, recwr)) | |
3539 | return false; | |
f9eeb9c9 TG |
3540 | |
3541 | if (!_bfd_vms_write_eeom (abfd)) | |
0a1b45a2 | 3542 | return false; |
f9eeb9c9 | 3543 | } |
0a1b45a2 | 3544 | return true; |
95e34ef7 TG |
3545 | } |
3546 | \f | |
3547 | /* Object write. */ | |
3548 | ||
95e34ef7 TG |
3549 | /* Write section and symbol directory of bfd abfd. Return FALSE on error. */ |
3550 | ||
0a1b45a2 | 3551 | static bool |
95e34ef7 TG |
3552 | _bfd_vms_write_egsd (bfd *abfd) |
3553 | { | |
3554 | asection *section; | |
3555 | asymbol *symbol; | |
3556 | unsigned int symnum; | |
dddb0e80 | 3557 | const char *sname; |
95e34ef7 | 3558 | flagword new_flags, old_flags; |
4ba2ab9f | 3559 | int abs_section_index = -1; |
1b3d1dbf | 3560 | unsigned int target_index = 0; |
95e34ef7 TG |
3561 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3562 | ||
1b3d1dbf | 3563 | vms_debug2 ((2, "vms_write_egsd\n")); |
95e34ef7 TG |
3564 | |
3565 | /* Egsd is quadword aligned. */ | |
3566 | _bfd_vms_output_alignment (recwr, 8); | |
3567 | ||
3568 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); | |
3569 | _bfd_vms_output_long (recwr, 0); | |
3570 | ||
1b3d1dbf TG |
3571 | /* Number sections. */ |
3572 | for (section = abfd->sections; section != NULL; section = section->next) | |
3573 | { | |
3574 | if (section->flags & SEC_DEBUGGING) | |
07d6d2b8 | 3575 | continue; |
1b3d1dbf | 3576 | if (!strcmp (section->name, ".vmsdebug")) |
07d6d2b8 AM |
3577 | { |
3578 | section->flags |= SEC_DEBUGGING; | |
3579 | continue; | |
3580 | } | |
1b3d1dbf TG |
3581 | section->target_index = target_index++; |
3582 | } | |
3583 | ||
3584 | for (section = abfd->sections; section != NULL; section = section->next) | |
95e34ef7 TG |
3585 | { |
3586 | vms_debug2 ((3, "Section #%d %s, %d bytes\n", | |
07d6d2b8 | 3587 | section->target_index, section->name, (int)section->size)); |
95e34ef7 TG |
3588 | |
3589 | /* Don't write out the VMS debug info section since it is in the | |
07d6d2b8 | 3590 | ETBT and EDBG sections in etir. */ |
1b3d1dbf | 3591 | if (section->flags & SEC_DEBUGGING) |
07d6d2b8 | 3592 | continue; |
95e34ef7 TG |
3593 | |
3594 | /* 13 bytes egsd, max 31 chars name -> should be 44 bytes. */ | |
3595 | if (_bfd_vms_output_check (recwr, 64) < 0) | |
3596 | { | |
e416bd75 AM |
3597 | if (!_bfd_vms_output_end (abfd, recwr)) |
3598 | return false; | |
95e34ef7 TG |
3599 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3600 | _bfd_vms_output_long (recwr, 0); | |
3601 | } | |
3602 | ||
95e34ef7 | 3603 | /* Don't know if this is necessary for the linker but for now it keeps |
5fe88cfb | 3604 | vms_slurp_gsd happy. */ |
81bb31c0 | 3605 | sname = section->name; |
95e34ef7 TG |
3606 | if (*sname == '.') |
3607 | { | |
07d6d2b8 | 3608 | /* Remove leading dot. */ |
95e34ef7 TG |
3609 | sname++; |
3610 | if ((*sname == 't') && (strcmp (sname, "text") == 0)) | |
3611 | sname = EVAX_CODE_NAME; | |
3612 | else if ((*sname == 'd') && (strcmp (sname, "data") == 0)) | |
3613 | sname = EVAX_DATA_NAME; | |
3614 | else if ((*sname == 'b') && (strcmp (sname, "bss") == 0)) | |
3615 | sname = EVAX_BSS_NAME; | |
3616 | else if ((*sname == 'l') && (strcmp (sname, "link") == 0)) | |
3617 | sname = EVAX_LINK_NAME; | |
3618 | else if ((*sname == 'r') && (strcmp (sname, "rdata") == 0)) | |
3619 | sname = EVAX_READONLY_NAME; | |
3620 | else if ((*sname == 'l') && (strcmp (sname, "literal") == 0)) | |
3621 | sname = EVAX_LITERAL_NAME; | |
3622 | else if ((*sname == 'l') && (strcmp (sname, "literals") == 0)) | |
07d6d2b8 | 3623 | sname = EVAX_LITERALS_NAME; |
95e34ef7 TG |
3624 | else if ((*sname == 'c') && (strcmp (sname, "comm") == 0)) |
3625 | sname = EVAX_COMMON_NAME; | |
3626 | else if ((*sname == 'l') && (strcmp (sname, "lcomm") == 0)) | |
3627 | sname = EVAX_LOCAL_NAME; | |
3628 | } | |
95e34ef7 | 3629 | |
95e34ef7 TG |
3630 | if (bfd_is_com_section (section)) |
3631 | new_flags = (EGPS__V_OVR | EGPS__V_REL | EGPS__V_GBL | EGPS__V_RD | |
3632 | | EGPS__V_WRT | EGPS__V_NOMOD | EGPS__V_COM); | |
3633 | else | |
3634 | new_flags = vms_esecflag_by_name (evax_section_flags, sname, | |
3635 | section->size > 0); | |
3636 | ||
3637 | /* Modify them as directed. */ | |
3638 | if (section->flags & SEC_READONLY) | |
3639 | new_flags &= ~EGPS__V_WRT; | |
3640 | ||
3641 | new_flags &= ~vms_section_data (section)->no_flags; | |
3642 | new_flags |= vms_section_data (section)->flags; | |
3643 | ||
3644 | vms_debug2 ((3, "sec flags %x\n", section->flags)); | |
3645 | vms_debug2 ((3, "new_flags %x, _raw_size %lu\n", | |
07d6d2b8 | 3646 | new_flags, (unsigned long)section->size)); |
95e34ef7 | 3647 | |
4ba2ab9f TG |
3648 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); |
3649 | _bfd_vms_output_short (recwr, section->alignment_power & 0xff); | |
95e34ef7 TG |
3650 | _bfd_vms_output_short (recwr, new_flags); |
3651 | _bfd_vms_output_long (recwr, (unsigned long) section->size); | |
3652 | _bfd_vms_output_counted (recwr, sname); | |
3653 | _bfd_vms_output_end_subrec (recwr); | |
4ba2ab9f TG |
3654 | |
3655 | /* If the section is an obsolute one, remind its index as it will be | |
07d6d2b8 | 3656 | used later for absolute symbols. */ |
4ba2ab9f | 3657 | if ((new_flags & EGPS__V_REL) == 0 && abs_section_index < 0) |
07d6d2b8 | 3658 | abs_section_index = section->target_index; |
95e34ef7 TG |
3659 | } |
3660 | ||
3661 | /* Output symbols. */ | |
3662 | vms_debug2 ((3, "%d symbols found\n", abfd->symcount)); | |
3663 | ||
3664 | bfd_set_start_address (abfd, (bfd_vma) -1); | |
3665 | ||
3666 | for (symnum = 0; symnum < abfd->symcount; symnum++) | |
3667 | { | |
95e34ef7 | 3668 | symbol = abfd->outsymbols[symnum]; |
46d00b8a TG |
3669 | old_flags = symbol->flags; |
3670 | ||
4ba2ab9f | 3671 | /* Work-around a missing feature: consider __main as the main entry |
07d6d2b8 | 3672 | point. */ |
53452371 TG |
3673 | if (symbol->name[0] == '_' && strcmp (symbol->name, "__main") == 0) |
3674 | bfd_set_start_address (abfd, (bfd_vma)symbol->value); | |
95e34ef7 | 3675 | |
46d00b8a | 3676 | /* Only put in the GSD the global and the undefined symbols. */ |
95e34ef7 TG |
3677 | if (old_flags & BSF_FILE) |
3678 | continue; | |
3679 | ||
46d00b8a | 3680 | if ((old_flags & BSF_GLOBAL) == 0 && !bfd_is_und_section (symbol->section)) |
07d6d2b8 AM |
3681 | { |
3682 | /* If the LIB$INITIIALIZE section is present, add a reference to | |
3683 | LIB$INITIALIZE symbol. FIXME: this should be done explicitely | |
3684 | in the assembly file. */ | |
3685 | if (!((old_flags & BSF_SECTION_SYM) != 0 | |
3686 | && strcmp (symbol->section->name, "LIB$INITIALIZE") == 0)) | |
3687 | continue; | |
3688 | } | |
95e34ef7 | 3689 | |
4ba2ab9f | 3690 | /* 13 bytes egsd, max 64 chars name -> should be 77 bytes. Add 16 more |
07d6d2b8 | 3691 | bytes for a possible ABS section. */ |
4ba2ab9f | 3692 | if (_bfd_vms_output_check (recwr, 80 + 16) < 0) |
95e34ef7 | 3693 | { |
e416bd75 AM |
3694 | if (!_bfd_vms_output_end (abfd, recwr)) |
3695 | return false; | |
95e34ef7 TG |
3696 | _bfd_vms_output_begin (recwr, EOBJ__C_EGSD); |
3697 | _bfd_vms_output_long (recwr, 0); | |
3698 | } | |
3699 | ||
4ba2ab9f | 3700 | if ((old_flags & BSF_GLOBAL) != 0 |
07d6d2b8 AM |
3701 | && bfd_is_abs_section (symbol->section) |
3702 | && abs_section_index <= 0) | |
3703 | { | |
3704 | /* Create an absolute section if none was defined. It is highly | |
3705 | unlikely that the name $ABS$ clashes with a user defined | |
3706 | non-absolute section name. */ | |
3707 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_PSC); | |
3708 | _bfd_vms_output_short (recwr, 4); | |
3709 | _bfd_vms_output_short (recwr, EGPS__V_SHR); | |
3710 | _bfd_vms_output_long (recwr, 0); | |
3711 | _bfd_vms_output_counted (recwr, "$ABS$"); | |
3712 | _bfd_vms_output_end_subrec (recwr); | |
3713 | ||
3714 | abs_section_index = target_index++; | |
3715 | } | |
4ba2ab9f | 3716 | |
95e34ef7 TG |
3717 | _bfd_vms_output_begin_subrec (recwr, EGSD__C_SYM); |
3718 | ||
3719 | /* Data type, alignment. */ | |
3720 | _bfd_vms_output_short (recwr, 0); | |
3721 | ||
3722 | new_flags = 0; | |
3723 | ||
3724 | if (old_flags & BSF_WEAK) | |
3725 | new_flags |= EGSY__V_WEAK; | |
3726 | if (bfd_is_com_section (symbol->section)) /* .comm */ | |
3727 | new_flags |= (EGSY__V_WEAK | EGSY__V_COMM); | |
3728 | ||
3729 | if (old_flags & BSF_FUNCTION) | |
3730 | { | |
3731 | new_flags |= EGSY__V_NORM; | |
3732 | new_flags |= EGSY__V_REL; | |
3733 | } | |
3734 | if (old_flags & BSF_GLOBAL) | |
3735 | { | |
3736 | new_flags |= EGSY__V_DEF; | |
3737 | if (!bfd_is_abs_section (symbol->section)) | |
3738 | new_flags |= EGSY__V_REL; | |
3739 | } | |
3740 | _bfd_vms_output_short (recwr, new_flags); | |
3741 | ||
3742 | if (old_flags & BSF_GLOBAL) | |
3743 | { | |
3744 | /* Symbol definition. */ | |
3745 | bfd_vma code_address = 0; | |
3746 | unsigned long ca_psindx = 0; | |
3747 | unsigned long psindx; | |
3748 | ||
3749 | if ((old_flags & BSF_FUNCTION) && symbol->udata.p != NULL) | |
3750 | { | |
3751 | asymbol *sym; | |
3752 | ||
07d6d2b8 AM |
3753 | sym = |
3754 | ((struct evax_private_udata_struct *)symbol->udata.p)->enbsym; | |
95e34ef7 | 3755 | code_address = sym->value; |
1b3d1dbf | 3756 | ca_psindx = sym->section->target_index; |
95e34ef7 TG |
3757 | } |
3758 | if (bfd_is_abs_section (symbol->section)) | |
3759 | psindx = abs_section_index; | |
3760 | else | |
1b3d1dbf | 3761 | psindx = symbol->section->target_index; |
95e34ef7 TG |
3762 | |
3763 | _bfd_vms_output_quad (recwr, symbol->value); | |
3764 | _bfd_vms_output_quad (recwr, code_address); | |
3765 | _bfd_vms_output_long (recwr, ca_psindx); | |
3766 | _bfd_vms_output_long (recwr, psindx); | |
3767 | } | |
53452371 | 3768 | _bfd_vms_output_counted (recwr, symbol->name); |
95e34ef7 TG |
3769 | |
3770 | _bfd_vms_output_end_subrec (recwr); | |
95e34ef7 TG |
3771 | } |
3772 | ||
3773 | _bfd_vms_output_alignment (recwr, 8); | |
e416bd75 | 3774 | return _bfd_vms_output_end (abfd, recwr); |
95e34ef7 TG |
3775 | } |
3776 | ||
3777 | /* Write object header for bfd abfd. Return FALSE on error. */ | |
3778 | ||
0a1b45a2 | 3779 | static bool |
95e34ef7 TG |
3780 | _bfd_vms_write_ehdr (bfd *abfd) |
3781 | { | |
3782 | asymbol *symbol; | |
3783 | unsigned int symnum; | |
95e34ef7 TG |
3784 | struct vms_rec_wr *recwr = &PRIV (recwr); |
3785 | ||
3786 | vms_debug2 ((2, "vms_write_ehdr (%p)\n", abfd)); | |
3787 | ||
3788 | _bfd_vms_output_alignment (recwr, 2); | |
3789 | ||
e416bd75 AM |
3790 | if (!_bfd_vms_write_emh (abfd) |
3791 | || !_bfd_vms_write_lmn (abfd, "GNU AS")) | |
3792 | return false; | |
95e34ef7 TG |
3793 | |
3794 | /* SRC. */ | |
3795 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3796 | _bfd_vms_output_short (recwr, EMH__C_SRC); | |
3797 | ||
3798 | for (symnum = 0; symnum < abfd->symcount; symnum++) | |
3799 | { | |
3800 | symbol = abfd->outsymbols[symnum]; | |
3801 | ||
3802 | if (symbol->flags & BSF_FILE) | |
3803 | { | |
95e34ef7 TG |
3804 | _bfd_vms_output_dump (recwr, (unsigned char *) symbol->name, |
3805 | (int) strlen (symbol->name)); | |
53452371 | 3806 | break; |
95e34ef7 TG |
3807 | } |
3808 | } | |
3809 | ||
3810 | if (symnum == abfd->symcount) | |
3811 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("noname")); | |
3812 | ||
e416bd75 AM |
3813 | if (!_bfd_vms_output_end (abfd, recwr)) |
3814 | return false; | |
95e34ef7 TG |
3815 | |
3816 | /* TTL. */ | |
3817 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3818 | _bfd_vms_output_short (recwr, EMH__C_TTL); | |
3819 | _bfd_vms_output_dump (recwr, (unsigned char *) STRING_COMMA_LEN ("TTL")); | |
e416bd75 AM |
3820 | if (!_bfd_vms_output_end (abfd, recwr)) |
3821 | return false; | |
95e34ef7 TG |
3822 | |
3823 | /* CPR. */ | |
3824 | _bfd_vms_output_begin (recwr, EOBJ__C_EMH); | |
3825 | _bfd_vms_output_short (recwr, EMH__C_CPR); | |
3826 | _bfd_vms_output_dump (recwr, | |
07d6d2b8 | 3827 | (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996", |
95e34ef7 | 3828 | 39); |
e416bd75 | 3829 | return _bfd_vms_output_end (abfd, recwr); |
95e34ef7 TG |
3830 | } |
3831 | ||
3832 | /* Part 4.6, relocations. */ | |
3833 | ||
3834 | \f | |
3835 | /* WRITE ETIR SECTION | |
3836 | ||
3837 | This is still under construction and therefore not documented. */ | |
3838 | ||
3839 | /* Close the etir/etbt record. */ | |
3840 | ||
e416bd75 | 3841 | static bool |
95e34ef7 TG |
3842 | end_etir_record (bfd * abfd) |
3843 | { | |
3844 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3845 | ||
e416bd75 | 3846 | return _bfd_vms_output_end (abfd, recwr); |
95e34ef7 TG |
3847 | } |
3848 | ||
3849 | static void | |
3850 | start_etir_or_etbt_record (bfd *abfd, asection *section, bfd_vma offset) | |
3851 | { | |
3852 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3853 | ||
1b3d1dbf | 3854 | if (section->flags & SEC_DEBUGGING) |
95e34ef7 TG |
3855 | { |
3856 | _bfd_vms_output_begin (recwr, EOBJ__C_ETBT); | |
3857 | ||
3858 | if (offset == 0) | |
07d6d2b8 AM |
3859 | { |
3860 | /* Push start offset. */ | |
3861 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); | |
3862 | _bfd_vms_output_long (recwr, (unsigned long) 0); | |
3863 | _bfd_vms_output_end_subrec (recwr); | |
3864 | ||
3865 | /* Set location. */ | |
3866 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_DFLOC); | |
3867 | _bfd_vms_output_end_subrec (recwr); | |
3868 | } | |
95e34ef7 TG |
3869 | } |
3870 | else | |
3871 | { | |
3872 | _bfd_vms_output_begin (recwr, EOBJ__C_ETIR); | |
3873 | ||
3874 | if (offset == 0) | |
07d6d2b8 AM |
3875 | { |
3876 | /* Push start offset. */ | |
3877 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); | |
3878 | _bfd_vms_output_long (recwr, (unsigned long) section->target_index); | |
3879 | _bfd_vms_output_quad (recwr, offset); | |
3880 | _bfd_vms_output_end_subrec (recwr); | |
3881 | ||
3882 | /* Start = pop (). */ | |
3883 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_CTL_SETRB); | |
3884 | _bfd_vms_output_end_subrec (recwr); | |
3885 | } | |
95e34ef7 TG |
3886 | } |
3887 | } | |
3888 | ||
3889 | /* Output a STO_IMM command for SSIZE bytes of data from CPR at virtual | |
3890 | address VADDR in section specified by SEC_INDEX and NAME. */ | |
3891 | ||
e416bd75 | 3892 | static bool |
95e34ef7 | 3893 | sto_imm (bfd *abfd, asection *section, |
07d6d2b8 | 3894 | bfd_size_type ssize, unsigned char *cptr, bfd_vma vaddr) |
95e34ef7 TG |
3895 | { |
3896 | bfd_size_type size; | |
3897 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3898 | ||
3899 | #if VMS_DEBUG | |
3900 | _bfd_vms_debug (8, "sto_imm %d bytes\n", (int) ssize); | |
3901 | _bfd_hexdump (9, cptr, (int) ssize, (int) vaddr); | |
3902 | #endif | |
3903 | ||
3904 | while (ssize > 0) | |
3905 | { | |
3906 | /* Try all the rest. */ | |
3907 | size = ssize; | |
3908 | ||
3909 | if (_bfd_vms_output_check (recwr, size) < 0) | |
3910 | { | |
3911 | /* Doesn't fit, split ! */ | |
e416bd75 AM |
3912 | if (!end_etir_record (abfd)) |
3913 | return false; | |
95e34ef7 | 3914 | |
07d6d2b8 | 3915 | start_etir_or_etbt_record (abfd, section, vaddr); |
95e34ef7 TG |
3916 | |
3917 | size = _bfd_vms_output_check (recwr, 0); /* get max size */ | |
3918 | if (size > ssize) /* more than what's left ? */ | |
3919 | size = ssize; | |
3920 | } | |
3921 | ||
3922 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_IMM); | |
3923 | _bfd_vms_output_long (recwr, (unsigned long) (size)); | |
3924 | _bfd_vms_output_dump (recwr, cptr, size); | |
3925 | _bfd_vms_output_end_subrec (recwr); | |
3926 | ||
3927 | #if VMS_DEBUG | |
3928 | _bfd_vms_debug (10, "dumped %d bytes\n", (int) size); | |
3929 | _bfd_hexdump (10, cptr, (int) size, (int) vaddr); | |
3930 | #endif | |
3931 | ||
3932 | vaddr += size; | |
3933 | cptr += size; | |
3934 | ssize -= size; | |
3935 | } | |
e416bd75 | 3936 | return true; |
95e34ef7 TG |
3937 | } |
3938 | ||
e416bd75 | 3939 | static bool |
95e34ef7 TG |
3940 | etir_output_check (bfd *abfd, asection *section, bfd_vma vaddr, int checklen) |
3941 | { | |
3942 | if (_bfd_vms_output_check (&PRIV (recwr), checklen) < 0) | |
3943 | { | |
3944 | /* Not enough room in this record. Close it and open a new one. */ | |
e416bd75 AM |
3945 | if (!end_etir_record (abfd)) |
3946 | return false; | |
95e34ef7 TG |
3947 | start_etir_or_etbt_record (abfd, section, vaddr); |
3948 | } | |
e416bd75 | 3949 | return true; |
95e34ef7 TG |
3950 | } |
3951 | ||
3952 | /* Return whether RELOC must be deferred till the end. */ | |
3953 | ||
0a1b45a2 | 3954 | static bool |
95e34ef7 TG |
3955 | defer_reloc_p (arelent *reloc) |
3956 | { | |
3957 | switch (reloc->howto->type) | |
3958 | { | |
3959 | case ALPHA_R_NOP: | |
3960 | case ALPHA_R_LDA: | |
3961 | case ALPHA_R_BSR: | |
3962 | case ALPHA_R_BOH: | |
0a1b45a2 | 3963 | return true; |
95e34ef7 TG |
3964 | |
3965 | default: | |
0a1b45a2 | 3966 | return false; |
95e34ef7 TG |
3967 | } |
3968 | } | |
3969 | ||
3970 | /* Write section contents for bfd abfd. Return FALSE on error. */ | |
3971 | ||
0a1b45a2 | 3972 | static bool |
95e34ef7 TG |
3973 | _bfd_vms_write_etir (bfd * abfd, int objtype ATTRIBUTE_UNUSED) |
3974 | { | |
3975 | asection *section; | |
3976 | struct vms_rec_wr *recwr = &PRIV (recwr); | |
3977 | ||
3978 | vms_debug2 ((2, "vms_write_tir (%p, %d)\n", abfd, objtype)); | |
3979 | ||
3980 | _bfd_vms_output_alignment (recwr, 4); | |
3981 | ||
f1bb0388 | 3982 | PRIV (vms_linkage_index) = 0; |
95e34ef7 TG |
3983 | |
3984 | for (section = abfd->sections; section; section = section->next) | |
3985 | { | |
3986 | vms_debug2 ((4, "writing %d. section '%s' (%d bytes)\n", | |
07d6d2b8 | 3987 | section->target_index, section->name, (int) (section->size))); |
95e34ef7 TG |
3988 | |
3989 | if (!(section->flags & SEC_HAS_CONTENTS) | |
3990 | || bfd_is_com_section (section)) | |
3991 | continue; | |
3992 | ||
3993 | if (!section->contents) | |
3994 | { | |
3995 | bfd_set_error (bfd_error_no_contents); | |
0a1b45a2 | 3996 | return false; |
95e34ef7 TG |
3997 | } |
3998 | ||
3999 | start_etir_or_etbt_record (abfd, section, 0); | |
4000 | ||
4001 | if (section->flags & SEC_RELOC) | |
4002 | { | |
4003 | bfd_vma curr_addr = 0; | |
4004 | unsigned char *curr_data = section->contents; | |
4005 | bfd_size_type size; | |
4006 | int pass2_needed = 0; | |
4007 | int pass2_in_progress = 0; | |
4008 | unsigned int irel; | |
4009 | ||
083faca9 | 4010 | if (section->reloc_count == 0) |
4eca0228 | 4011 | _bfd_error_handler |
871b3ab2 | 4012 | (_("SEC_RELOC with no relocs in section %pA"), section); |
95e34ef7 TG |
4013 | |
4014 | #if VMS_DEBUG | |
4015 | else | |
4016 | { | |
4017 | int i = section->reloc_count; | |
4018 | arelent **rptr = section->orelocation; | |
4019 | _bfd_vms_debug (4, "%d relocations:\n", i); | |
4020 | while (i-- > 0) | |
4021 | { | |
4022 | _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, " | |
4023 | "addr %08lx, off %08lx, len %d: %s\n", | |
4024 | (*(*rptr)->sym_ptr_ptr)->name, | |
4025 | (*(*rptr)->sym_ptr_ptr)->section->name, | |
4026 | (long) (*(*rptr)->sym_ptr_ptr)->value, | |
4027 | (unsigned long)(*rptr)->address, | |
07d6d2b8 | 4028 | (unsigned long)(*rptr)->addend, |
95e34ef7 | 4029 | bfd_get_reloc_size ((*rptr)->howto), |
07d6d2b8 | 4030 | ( *rptr)->howto->name); |
95e34ef7 TG |
4031 | rptr++; |
4032 | } | |
4033 | } | |
4034 | #endif | |
4035 | ||
4036 | new_pass: | |
4037 | for (irel = 0; irel < section->reloc_count; irel++) | |
4038 | { | |
4039 | struct evax_private_udata_struct *udata; | |
4040 | arelent *rptr = section->orelocation [irel]; | |
4041 | bfd_vma addr = rptr->address; | |
4042 | asymbol *sym = *rptr->sym_ptr_ptr; | |
4043 | asection *sec = sym->section; | |
0a1b45a2 | 4044 | bool defer = defer_reloc_p (rptr); |
95e34ef7 | 4045 | unsigned int slen; |
95e34ef7 TG |
4046 | |
4047 | if (pass2_in_progress) | |
4048 | { | |
4049 | /* Non-deferred relocs have already been output. */ | |
4050 | if (!defer) | |
4051 | continue; | |
4052 | } | |
4053 | else | |
4054 | { | |
4055 | /* Deferred relocs must be output at the very end. */ | |
4056 | if (defer) | |
4057 | { | |
4058 | pass2_needed = 1; | |
4059 | continue; | |
4060 | } | |
4061 | ||
4062 | /* Regular relocs are intertwined with binary data. */ | |
07d6d2b8 | 4063 | if (curr_addr > addr) |
38f14ab8 | 4064 | _bfd_error_handler (_("size error in section %pA"), |
dae82561 | 4065 | section); |
95e34ef7 | 4066 | size = addr - curr_addr; |
e416bd75 AM |
4067 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4068 | return false; | |
95e34ef7 TG |
4069 | curr_data += size; |
4070 | curr_addr += size; | |
4071 | } | |
4072 | ||
4073 | size = bfd_get_reloc_size (rptr->howto); | |
4074 | ||
4075 | switch (rptr->howto->type) | |
07d6d2b8 | 4076 | { |
95e34ef7 TG |
4077 | case ALPHA_R_IGNORE: |
4078 | break; | |
4079 | ||
4080 | case ALPHA_R_REFLONG: | |
4081 | if (bfd_is_und_section (sym->section)) | |
4082 | { | |
4083 | bfd_vma addend = rptr->addend; | |
4084 | slen = strlen ((char *) sym->name); | |
e416bd75 AM |
4085 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4086 | return false; | |
95e34ef7 TG |
4087 | if (addend) |
4088 | { | |
4089 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); | |
53452371 | 4090 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4091 | _bfd_vms_output_end_subrec (recwr); |
4092 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); | |
4093 | _bfd_vms_output_long (recwr, (unsigned long) addend); | |
4094 | _bfd_vms_output_end_subrec (recwr); | |
4095 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); | |
4096 | _bfd_vms_output_end_subrec (recwr); | |
4097 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4098 | _bfd_vms_output_end_subrec (recwr); | |
4099 | } | |
4100 | else | |
4101 | { | |
4102 | _bfd_vms_output_begin_subrec | |
07d6d2b8 | 4103 | (recwr, ETIR__C_STO_GBL_LW); |
53452371 | 4104 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4105 | _bfd_vms_output_end_subrec (recwr); |
4106 | } | |
4107 | } | |
4108 | else if (bfd_is_abs_section (sym->section)) | |
4109 | { | |
e416bd75 AM |
4110 | if (!etir_output_check (abfd, section, curr_addr, 16)) |
4111 | return false; | |
95e34ef7 TG |
4112 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_LW); |
4113 | _bfd_vms_output_long (recwr, (unsigned long) sym->value); | |
4114 | _bfd_vms_output_end_subrec (recwr); | |
4115 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4116 | _bfd_vms_output_end_subrec (recwr); | |
4117 | } | |
4118 | else | |
4119 | { | |
e416bd75 AM |
4120 | if (!etir_output_check (abfd, section, curr_addr, 32)) |
4121 | return false; | |
95e34ef7 | 4122 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); |
1b3d1dbf | 4123 | _bfd_vms_output_long (recwr, |
07d6d2b8 | 4124 | (unsigned long) sec->target_index); |
95e34ef7 TG |
4125 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4126 | _bfd_vms_output_end_subrec (recwr); | |
4127 | /* ??? Table B-8 of the OpenVMS Linker Utilily Manual | |
4128 | says that we should have a ETIR__C_STO_OFF here. | |
4129 | But the relocation would not be BFD_RELOC_32 then. | |
4130 | This case is very likely unreachable. */ | |
4131 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_LW); | |
4132 | _bfd_vms_output_end_subrec (recwr); | |
4133 | } | |
4134 | break; | |
4135 | ||
4136 | case ALPHA_R_REFQUAD: | |
4137 | if (bfd_is_und_section (sym->section)) | |
4138 | { | |
4139 | bfd_vma addend = rptr->addend; | |
4140 | slen = strlen ((char *) sym->name); | |
e416bd75 AM |
4141 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4142 | return false; | |
95e34ef7 TG |
4143 | if (addend) |
4144 | { | |
4145 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_GBL); | |
53452371 | 4146 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4147 | _bfd_vms_output_end_subrec (recwr); |
4148 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); | |
4149 | _bfd_vms_output_quad (recwr, addend); | |
4150 | _bfd_vms_output_end_subrec (recwr); | |
4151 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_OPR_ADD); | |
4152 | _bfd_vms_output_end_subrec (recwr); | |
4153 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); | |
4154 | _bfd_vms_output_end_subrec (recwr); | |
4155 | } | |
4156 | else | |
4157 | { | |
4158 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_GBL); | |
53452371 | 4159 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4160 | _bfd_vms_output_end_subrec (recwr); |
4161 | } | |
4162 | } | |
4163 | else if (bfd_is_abs_section (sym->section)) | |
4164 | { | |
e416bd75 AM |
4165 | if (!etir_output_check (abfd, section, curr_addr, 16)) |
4166 | return false; | |
95e34ef7 TG |
4167 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_QW); |
4168 | _bfd_vms_output_quad (recwr, sym->value); | |
4169 | _bfd_vms_output_end_subrec (recwr); | |
4170 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_QW); | |
4171 | _bfd_vms_output_end_subrec (recwr); | |
4172 | } | |
4173 | else | |
4174 | { | |
e416bd75 AM |
4175 | if (!etir_output_check (abfd, section, curr_addr, 32)) |
4176 | return false; | |
95e34ef7 | 4177 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STA_PQ); |
1b3d1dbf | 4178 | _bfd_vms_output_long (recwr, |
07d6d2b8 | 4179 | (unsigned long) sec->target_index); |
95e34ef7 TG |
4180 | _bfd_vms_output_quad (recwr, rptr->addend + sym->value); |
4181 | _bfd_vms_output_end_subrec (recwr); | |
4182 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_OFF); | |
4183 | _bfd_vms_output_end_subrec (recwr); | |
4184 | } | |
4185 | break; | |
4186 | ||
4187 | case ALPHA_R_HINT: | |
e416bd75 AM |
4188 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4189 | return false; | |
95e34ef7 TG |
4190 | break; |
4191 | ||
4192 | case ALPHA_R_LINKAGE: | |
706704c8 | 4193 | size = 16; |
e416bd75 AM |
4194 | if (!etir_output_check (abfd, section, curr_addr, 64)) |
4195 | return false; | |
95e34ef7 TG |
4196 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LP_PSB); |
4197 | _bfd_vms_output_long | |
25d41743 | 4198 | (recwr, (unsigned long) rptr->addend); |
07d6d2b8 AM |
4199 | if (rptr->addend > PRIV (vms_linkage_index)) |
4200 | PRIV (vms_linkage_index) = rptr->addend; | |
53452371 | 4201 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4202 | _bfd_vms_output_byte (recwr, 0); |
4203 | _bfd_vms_output_end_subrec (recwr); | |
4204 | break; | |
4205 | ||
4206 | case ALPHA_R_CODEADDR: | |
4207 | slen = strlen ((char *) sym->name); | |
e416bd75 AM |
4208 | if (!etir_output_check (abfd, section, curr_addr, slen)) |
4209 | return false; | |
95e34ef7 | 4210 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STO_CA); |
53452371 | 4211 | _bfd_vms_output_counted (recwr, sym->name); |
95e34ef7 TG |
4212 | _bfd_vms_output_end_subrec (recwr); |
4213 | break; | |
4214 | ||
4215 | case ALPHA_R_NOP: | |
4216 | udata | |
4217 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
e416bd75 AM |
4218 | if (!etir_output_check (abfd, section, curr_addr, |
4219 | 32 + 1 + strlen (udata->origname))) | |
4220 | return false; | |
95e34ef7 TG |
4221 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_NOP_GBL); |
4222 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); | |
4223 | _bfd_vms_output_long | |
a8efca92 | 4224 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4225 | _bfd_vms_output_quad (recwr, rptr->address); |
4226 | _bfd_vms_output_long (recwr, (unsigned long) 0x47ff041f); | |
4227 | _bfd_vms_output_long | |
a8efca92 | 4228 | (recwr, (unsigned long) section->target_index); |
95e34ef7 | 4229 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4230 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4231 | _bfd_vms_output_end_subrec (recwr); |
4232 | break; | |
4233 | ||
4234 | case ALPHA_R_BSR: | |
38f14ab8 | 4235 | _bfd_error_handler (_("spurious ALPHA_R_BSR reloc")); |
95e34ef7 TG |
4236 | break; |
4237 | ||
4238 | case ALPHA_R_LDA: | |
4239 | udata | |
4240 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
e416bd75 AM |
4241 | if (!etir_output_check (abfd, section, curr_addr, |
4242 | 32 + 1 + strlen (udata->origname))) | |
4243 | return false; | |
95e34ef7 TG |
4244 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_LDA_GBL); |
4245 | _bfd_vms_output_long | |
4246 | (recwr, (unsigned long) udata->lkindex + 1); | |
4247 | _bfd_vms_output_long | |
a8efca92 | 4248 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4249 | _bfd_vms_output_quad (recwr, rptr->address); |
4250 | _bfd_vms_output_long (recwr, (unsigned long) 0x237B0000); | |
4251 | _bfd_vms_output_long | |
1b3d1dbf | 4252 | (recwr, (unsigned long) udata->bsym->section->target_index); |
95e34ef7 | 4253 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4254 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4255 | _bfd_vms_output_end_subrec (recwr); |
4256 | break; | |
4257 | ||
4258 | case ALPHA_R_BOH: | |
4259 | udata | |
4260 | = (struct evax_private_udata_struct *) rptr->sym_ptr_ptr; | |
e416bd75 AM |
4261 | if (!etir_output_check (abfd, section, curr_addr, |
4262 | 32 + 1 + strlen (udata->origname))) | |
4263 | return false; | |
95e34ef7 TG |
4264 | _bfd_vms_output_begin_subrec (recwr, ETIR__C_STC_BOH_GBL); |
4265 | _bfd_vms_output_long (recwr, (unsigned long) udata->lkindex); | |
4266 | _bfd_vms_output_long | |
a8efca92 | 4267 | (recwr, (unsigned long) section->target_index); |
95e34ef7 TG |
4268 | _bfd_vms_output_quad (recwr, rptr->address); |
4269 | _bfd_vms_output_long (recwr, (unsigned long) 0xD3400000); | |
4270 | _bfd_vms_output_long | |
a8efca92 | 4271 | (recwr, (unsigned long) section->target_index); |
95e34ef7 | 4272 | _bfd_vms_output_quad (recwr, rptr->addend); |
53452371 | 4273 | _bfd_vms_output_counted (recwr, udata->origname); |
95e34ef7 TG |
4274 | _bfd_vms_output_end_subrec (recwr); |
4275 | break; | |
4276 | ||
4277 | default: | |
38f14ab8 | 4278 | _bfd_error_handler (_("unhandled relocation %s"), |
4eca0228 | 4279 | rptr->howto->name); |
95e34ef7 TG |
4280 | break; |
4281 | } | |
4282 | ||
4283 | curr_data += size; | |
4284 | curr_addr += size; | |
4285 | } /* End of relocs loop. */ | |
4286 | ||
4287 | if (!pass2_in_progress) | |
4288 | { | |
4289 | /* Output rest of section. */ | |
4290 | if (curr_addr > section->size) | |
9ec2f606 AM |
4291 | { |
4292 | _bfd_error_handler (_("size error in section %pA"), section); | |
0a1b45a2 | 4293 | return false; |
9ec2f606 | 4294 | } |
95e34ef7 | 4295 | size = section->size - curr_addr; |
e416bd75 AM |
4296 | if (!sto_imm (abfd, section, size, curr_data, curr_addr)) |
4297 | return false; | |
95e34ef7 TG |
4298 | curr_data += size; |
4299 | curr_addr += size; | |
4300 | ||
4301 | if (pass2_needed) | |
4302 | { | |
4303 | pass2_in_progress = 1; | |
4304 | goto new_pass; | |
4305 | } | |
4306 | } | |
4307 | } | |
4308 | ||
4309 | else /* (section->flags & SEC_RELOC) */ | |
e416bd75 AM |
4310 | if (!sto_imm (abfd, section, section->size, section->contents, 0)) |
4311 | return false; | |
95e34ef7 | 4312 | |
e416bd75 AM |
4313 | if (!end_etir_record (abfd)) |
4314 | return false; | |
95e34ef7 TG |
4315 | } |
4316 | ||
4317 | _bfd_vms_output_alignment (recwr, 2); | |
0a1b45a2 | 4318 | return true; |
95e34ef7 TG |
4319 | } |
4320 | ||
95e34ef7 TG |
4321 | /* Write cached information into a file being written, at bfd_close. */ |
4322 | ||
0a1b45a2 | 4323 | static bool |
95e34ef7 TG |
4324 | alpha_vms_write_object_contents (bfd *abfd) |
4325 | { | |
4326 | vms_debug2 ((1, "vms_write_object_contents (%p)\n", abfd)); | |
4327 | ||
4328 | if (abfd->flags & (EXEC_P | DYNAMIC)) | |
4329 | { | |
4330 | return alpha_vms_write_exec (abfd); | |
4331 | } | |
4332 | else | |
4333 | { | |
4334 | if (abfd->section_count > 0) /* we have sections */ | |
07d6d2b8 AM |
4335 | { |
4336 | if (!_bfd_vms_write_ehdr (abfd)) | |
0a1b45a2 | 4337 | return false; |
07d6d2b8 | 4338 | if (!_bfd_vms_write_egsd (abfd)) |
0a1b45a2 | 4339 | return false; |
07d6d2b8 | 4340 | if (!_bfd_vms_write_etir (abfd, EOBJ__C_ETIR)) |
0a1b45a2 | 4341 | return false; |
07d6d2b8 | 4342 | if (!_bfd_vms_write_eeom (abfd)) |
0a1b45a2 | 4343 | return false; |
07d6d2b8 | 4344 | } |
95e34ef7 | 4345 | } |
0a1b45a2 | 4346 | return true; |
95e34ef7 TG |
4347 | } |
4348 | \f | |
4349 | /* Debug stuff: nearest line. */ | |
4350 | ||
4351 | #define SET_MODULE_PARSED(m) \ | |
4352 | do { if ((m)->name == NULL) (m)->name = ""; } while (0) | |
4353 | #define IS_MODULE_PARSED(m) ((m)->name != NULL) | |
4354 | ||
4355 | /* Build a new module for the specified BFD. */ | |
4356 | ||
4357 | static struct module * | |
4358 | new_module (bfd *abfd) | |
4359 | { | |
4360 | struct module *module | |
4361 | = (struct module *) bfd_zalloc (abfd, sizeof (struct module)); | |
4362 | module->file_table_count = 16; /* Arbitrary. */ | |
4363 | module->file_table | |
65cf035b | 4364 | = bfd_zmalloc (module->file_table_count * sizeof (struct fileinfo)); |
95e34ef7 TG |
4365 | return module; |
4366 | } | |
4367 | ||
4368 | /* Parse debug info for a module and internalize it. */ | |
4369 | ||
0a1b45a2 | 4370 | static bool |
95e34ef7 | 4371 | parse_module (bfd *abfd, struct module *module, unsigned char *ptr, |
77c225bd | 4372 | bfd_size_type length) |
95e34ef7 TG |
4373 | { |
4374 | unsigned char *maxptr = ptr + length; | |
4375 | unsigned char *src_ptr, *pcl_ptr; | |
4376 | unsigned int prev_linum = 0, curr_linenum = 0; | |
4377 | bfd_vma prev_pc = 0, curr_pc = 0; | |
4378 | struct srecinfo *curr_srec, *srec; | |
4379 | struct lineinfo *curr_line, *line; | |
4380 | struct funcinfo *funcinfo; | |
4381 | ||
4382 | /* Initialize tables with zero element. */ | |
4383 | curr_srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
c9178f28 AM |
4384 | if (!curr_srec) |
4385 | return false; | |
95e34ef7 TG |
4386 | module->srec_table = curr_srec; |
4387 | ||
4388 | curr_line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
c9178f28 AM |
4389 | if (!curr_line) |
4390 | return false; | |
95e34ef7 TG |
4391 | module->line_table = curr_line; |
4392 | ||
77c225bd | 4393 | while (ptr + 3 < maxptr) |
95e34ef7 TG |
4394 | { |
4395 | /* The first byte is not counted in the recorded length. */ | |
4396 | int rec_length = bfd_getl16 (ptr) + 1; | |
4397 | int rec_type = bfd_getl16 (ptr + 2); | |
4398 | ||
4399 | vms_debug2 ((2, "DST record: leng %d, type %d\n", rec_length, rec_type)); | |
4400 | ||
77c225bd AM |
4401 | if (rec_length > maxptr - ptr) |
4402 | break; | |
4403 | if (rec_type == DST__K_MODEND) | |
07d6d2b8 | 4404 | break; |
95e34ef7 TG |
4405 | |
4406 | switch (rec_type) | |
4407 | { | |
4408 | case DST__K_MODBEG: | |
77c225bd AM |
4409 | if (rec_length <= DST_S_B_MODBEG_NAME) |
4410 | break; | |
95e34ef7 | 4411 | module->name |
37d2e9c7 | 4412 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_MODBEG_NAME, |
77c225bd | 4413 | rec_length - DST_S_B_MODBEG_NAME); |
95e34ef7 TG |
4414 | |
4415 | curr_pc = 0; | |
4416 | prev_pc = 0; | |
4417 | curr_linenum = 0; | |
4418 | prev_linum = 0; | |
4419 | ||
07d6d2b8 | 4420 | vms_debug2 ((3, "module: %s\n", module->name)); |
95e34ef7 TG |
4421 | break; |
4422 | ||
4423 | case DST__K_MODEND: | |
4424 | break; | |
4425 | ||
4426 | case DST__K_RTNBEG: | |
77c225bd AM |
4427 | if (rec_length <= DST_S_B_RTNBEG_NAME) |
4428 | break; | |
95e34ef7 TG |
4429 | funcinfo = (struct funcinfo *) |
4430 | bfd_zalloc (abfd, sizeof (struct funcinfo)); | |
c9178f28 AM |
4431 | if (!funcinfo) |
4432 | return false; | |
07d6d2b8 | 4433 | funcinfo->name |
37d2e9c7 | 4434 | = _bfd_vms_save_counted_string (abfd, ptr + DST_S_B_RTNBEG_NAME, |
77c225bd | 4435 | rec_length - DST_S_B_RTNBEG_NAME); |
95e34ef7 TG |
4436 | funcinfo->low = bfd_getl32 (ptr + DST_S_L_RTNBEG_ADDRESS); |
4437 | funcinfo->next = module->func_table; | |
4438 | module->func_table = funcinfo; | |
4439 | ||
07d6d2b8 AM |
4440 | vms_debug2 ((3, "routine: %s at 0x%lx\n", |
4441 | funcinfo->name, (unsigned long) funcinfo->low)); | |
95e34ef7 TG |
4442 | break; |
4443 | ||
4444 | case DST__K_RTNEND: | |
77c225bd AM |
4445 | if (rec_length < DST_S_L_RTNEND_SIZE + 4) |
4446 | break; | |
c9178f28 AM |
4447 | if (!module->func_table) |
4448 | return false; | |
95e34ef7 TG |
4449 | module->func_table->high = module->func_table->low |
4450 | + bfd_getl32 (ptr + DST_S_L_RTNEND_SIZE) - 1; | |
4451 | ||
4452 | if (module->func_table->high > module->high) | |
4453 | module->high = module->func_table->high; | |
4454 | ||
07d6d2b8 | 4455 | vms_debug2 ((3, "end routine\n")); |
95e34ef7 TG |
4456 | break; |
4457 | ||
4458 | case DST__K_PROLOG: | |
07d6d2b8 | 4459 | vms_debug2 ((3, "prologue\n")); |
95e34ef7 TG |
4460 | break; |
4461 | ||
4462 | case DST__K_EPILOG: | |
07d6d2b8 | 4463 | vms_debug2 ((3, "epilog\n")); |
95e34ef7 TG |
4464 | break; |
4465 | ||
4466 | case DST__K_BLKBEG: | |
07d6d2b8 | 4467 | vms_debug2 ((3, "block\n")); |
95e34ef7 TG |
4468 | break; |
4469 | ||
4470 | case DST__K_BLKEND: | |
07d6d2b8 | 4471 | vms_debug2 ((3, "end block\n")); |
95e34ef7 TG |
4472 | break; |
4473 | ||
4474 | case DST__K_SOURCE: | |
4475 | src_ptr = ptr + DST_S_C_SOURCE_HEADER_SIZE; | |
4476 | ||
4477 | vms_debug2 ((3, "source info\n")); | |
4478 | ||
77c225bd | 4479 | while (src_ptr - ptr < rec_length) |
95e34ef7 TG |
4480 | { |
4481 | int cmd = src_ptr[0], cmd_length, data; | |
4482 | ||
77c225bd AM |
4483 | switch (cmd) |
4484 | { | |
4485 | case DST__K_SRC_DECLFILE: | |
4486 | if (src_ptr - ptr + DST_S_B_SRC_DF_LENGTH >= rec_length) | |
4487 | cmd_length = 0x10000; | |
4488 | else | |
4489 | cmd_length = src_ptr[DST_S_B_SRC_DF_LENGTH] + 2; | |
4490 | break; | |
4491 | ||
4492 | case DST__K_SRC_DEFLINES_B: | |
4493 | cmd_length = 2; | |
4494 | break; | |
4495 | ||
4496 | case DST__K_SRC_DEFLINES_W: | |
4497 | cmd_length = 3; | |
4498 | break; | |
4499 | ||
4500 | case DST__K_SRC_INCRLNUM_B: | |
4501 | cmd_length = 2; | |
4502 | break; | |
4503 | ||
4504 | case DST__K_SRC_SETFILE: | |
4505 | cmd_length = 3; | |
4506 | break; | |
4507 | ||
4508 | case DST__K_SRC_SETLNUM_L: | |
4509 | cmd_length = 5; | |
4510 | break; | |
4511 | ||
4512 | case DST__K_SRC_SETLNUM_W: | |
4513 | cmd_length = 3; | |
4514 | break; | |
4515 | ||
4516 | case DST__K_SRC_SETREC_L: | |
4517 | cmd_length = 5; | |
4518 | break; | |
4519 | ||
4520 | case DST__K_SRC_SETREC_W: | |
4521 | cmd_length = 3; | |
4522 | break; | |
4523 | ||
4524 | case DST__K_SRC_FORMFEED: | |
4525 | cmd_length = 1; | |
4526 | break; | |
4527 | ||
4528 | default: | |
4529 | cmd_length = 2; | |
4530 | break; | |
4531 | } | |
4532 | ||
4533 | if (src_ptr - ptr + cmd_length > rec_length) | |
4534 | break; | |
4535 | ||
95e34ef7 TG |
4536 | switch (cmd) |
4537 | { | |
4538 | case DST__K_SRC_DECLFILE: | |
4539 | { | |
4540 | unsigned int fileid | |
4541 | = bfd_getl16 (src_ptr + DST_S_W_SRC_DF_FILEID); | |
37d2e9c7 AM |
4542 | char *filename = _bfd_vms_save_counted_string |
4543 | (abfd, | |
4544 | src_ptr + DST_S_B_SRC_DF_FILENAME, | |
4545 | ptr + rec_length - (src_ptr + DST_S_B_SRC_DF_FILENAME)); | |
95e34ef7 | 4546 | |
65cf035b | 4547 | if (fileid >= module->file_table_count) |
95e34ef7 | 4548 | { |
65cf035b AM |
4549 | unsigned int old_count = module->file_table_count; |
4550 | module->file_table_count += fileid; | |
95e34ef7 | 4551 | module->file_table |
9cb56943 AM |
4552 | = bfd_realloc_or_free (module->file_table, |
4553 | module->file_table_count | |
4554 | * sizeof (struct fileinfo)); | |
4555 | if (module->file_table == NULL) | |
0a1b45a2 | 4556 | return false; |
65cf035b AM |
4557 | memset (module->file_table + old_count, 0, |
4558 | fileid * sizeof (struct fileinfo)); | |
95e34ef7 TG |
4559 | } |
4560 | ||
4561 | module->file_table [fileid].name = filename; | |
4562 | module->file_table [fileid].srec = 1; | |
95e34ef7 | 4563 | vms_debug2 ((4, "DST_S_C_SRC_DECLFILE: %d, %s\n", |
07d6d2b8 | 4564 | fileid, module->file_table [fileid].name)); |
95e34ef7 TG |
4565 | } |
4566 | break; | |
4567 | ||
4568 | case DST__K_SRC_DEFLINES_B: | |
4569 | /* Perform the association and set the next higher index | |
4570 | to the limit. */ | |
4571 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; | |
4572 | srec = (struct srecinfo *) | |
4573 | bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4574 | srec->line = curr_srec->line + data; | |
4575 | srec->srec = curr_srec->srec + data; | |
4576 | srec->sfile = curr_srec->sfile; | |
4577 | curr_srec->next = srec; | |
4578 | curr_srec = srec; | |
95e34ef7 TG |
4579 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_B: %d\n", data)); |
4580 | break; | |
4581 | ||
4582 | case DST__K_SRC_DEFLINES_W: | |
4583 | /* Perform the association and set the next higher index | |
4584 | to the limit. */ | |
4585 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4586 | srec = (struct srecinfo *) | |
4587 | bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4588 | srec->line = curr_srec->line + data; | |
4589 | srec->srec = curr_srec->srec + data, | |
4590 | srec->sfile = curr_srec->sfile; | |
4591 | curr_srec->next = srec; | |
4592 | curr_srec = srec; | |
95e34ef7 TG |
4593 | vms_debug2 ((4, "DST_S_C_SRC_DEFLINES_W: %d\n", data)); |
4594 | break; | |
4595 | ||
4596 | case DST__K_SRC_INCRLNUM_B: | |
4597 | data = src_ptr[DST_S_B_SRC_UNSBYTE]; | |
4598 | curr_srec->line += data; | |
95e34ef7 TG |
4599 | vms_debug2 ((4, "DST_S_C_SRC_INCRLNUM_B: %d\n", data)); |
4600 | break; | |
4601 | ||
4602 | case DST__K_SRC_SETFILE: | |
4603 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
c093f5ee AM |
4604 | if ((unsigned int) data < module->file_table_count) |
4605 | { | |
4606 | curr_srec->sfile = data; | |
4607 | curr_srec->srec = module->file_table[data].srec; | |
4608 | } | |
95e34ef7 TG |
4609 | vms_debug2 ((4, "DST_S_C_SRC_SETFILE: %d\n", data)); |
4610 | break; | |
4611 | ||
4612 | case DST__K_SRC_SETLNUM_L: | |
4613 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); | |
4614 | curr_srec->line = data; | |
95e34ef7 TG |
4615 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_L: %d\n", data)); |
4616 | break; | |
4617 | ||
4618 | case DST__K_SRC_SETLNUM_W: | |
4619 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4620 | curr_srec->line = data; | |
95e34ef7 TG |
4621 | vms_debug2 ((4, "DST_S_C_SRC_SETLNUM_W: %d\n", data)); |
4622 | break; | |
4623 | ||
4624 | case DST__K_SRC_SETREC_L: | |
4625 | data = bfd_getl32 (src_ptr + DST_S_L_SRC_UNSLONG); | |
4626 | curr_srec->srec = data; | |
4627 | module->file_table[curr_srec->sfile].srec = data; | |
95e34ef7 TG |
4628 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_L: %d\n", data)); |
4629 | break; | |
4630 | ||
4631 | case DST__K_SRC_SETREC_W: | |
4632 | data = bfd_getl16 (src_ptr + DST_S_W_SRC_UNSWORD); | |
4633 | curr_srec->srec = data; | |
4634 | module->file_table[curr_srec->sfile].srec = data; | |
95e34ef7 TG |
4635 | vms_debug2 ((4, "DST_S_C_SRC_SETREC_W: %d\n", data)); |
4636 | break; | |
4637 | ||
4638 | case DST__K_SRC_FORMFEED: | |
95e34ef7 TG |
4639 | vms_debug2 ((4, "DST_S_C_SRC_FORMFEED\n")); |
4640 | break; | |
4641 | ||
4642 | default: | |
4eca0228 AM |
4643 | _bfd_error_handler (_("unknown source command %d"), |
4644 | cmd); | |
95e34ef7 TG |
4645 | break; |
4646 | } | |
4647 | ||
4648 | src_ptr += cmd_length; | |
4649 | } | |
4650 | break; | |
4651 | ||
4652 | case DST__K_LINE_NUM: | |
4653 | pcl_ptr = ptr + DST_S_C_LINE_NUM_HEADER_SIZE; | |
4654 | ||
4655 | vms_debug2 ((3, "line info\n")); | |
4656 | ||
77c225bd | 4657 | while (pcl_ptr - ptr < rec_length) |
95e34ef7 TG |
4658 | { |
4659 | /* The command byte is signed so we must sign-extend it. */ | |
4660 | int cmd = ((signed char *)pcl_ptr)[0], cmd_length, data; | |
4661 | ||
77c225bd AM |
4662 | switch (cmd) |
4663 | { | |
4664 | case DST__K_DELTA_PC_W: | |
4665 | cmd_length = 3; | |
4666 | break; | |
4667 | ||
4668 | case DST__K_DELTA_PC_L: | |
4669 | cmd_length = 5; | |
4670 | break; | |
4671 | ||
4672 | case DST__K_INCR_LINUM: | |
4673 | cmd_length = 2; | |
4674 | break; | |
4675 | ||
4676 | case DST__K_INCR_LINUM_W: | |
4677 | cmd_length = 3; | |
4678 | break; | |
4679 | ||
4680 | case DST__K_INCR_LINUM_L: | |
4681 | cmd_length = 5; | |
4682 | break; | |
4683 | ||
4684 | case DST__K_SET_LINUM_INCR: | |
4685 | cmd_length = 2; | |
4686 | break; | |
4687 | ||
4688 | case DST__K_SET_LINUM_INCR_W: | |
4689 | cmd_length = 3; | |
4690 | break; | |
4691 | ||
4692 | case DST__K_RESET_LINUM_INCR: | |
4693 | cmd_length = 1; | |
4694 | break; | |
4695 | ||
4696 | case DST__K_BEG_STMT_MODE: | |
4697 | cmd_length = 1; | |
4698 | break; | |
4699 | ||
4700 | case DST__K_END_STMT_MODE: | |
4701 | cmd_length = 1; | |
4702 | break; | |
4703 | ||
4704 | case DST__K_SET_LINUM_B: | |
4705 | cmd_length = 2; | |
4706 | break; | |
4707 | ||
4708 | case DST__K_SET_LINUM: | |
4709 | cmd_length = 3; | |
4710 | break; | |
4711 | ||
4712 | case DST__K_SET_LINUM_L: | |
4713 | cmd_length = 5; | |
4714 | break; | |
4715 | ||
4716 | case DST__K_SET_PC: | |
4717 | cmd_length = 2; | |
4718 | break; | |
4719 | ||
4720 | case DST__K_SET_PC_W: | |
4721 | cmd_length = 3; | |
4722 | break; | |
4723 | ||
4724 | case DST__K_SET_PC_L: | |
4725 | cmd_length = 5; | |
4726 | break; | |
4727 | ||
4728 | case DST__K_SET_STMTNUM: | |
4729 | cmd_length = 2; | |
4730 | break; | |
4731 | ||
4732 | case DST__K_TERM: | |
4733 | cmd_length = 2; | |
4734 | break; | |
4735 | ||
4736 | case DST__K_TERM_W: | |
4737 | cmd_length = 3; | |
4738 | break; | |
4739 | ||
4740 | case DST__K_TERM_L: | |
4741 | cmd_length = 5; | |
4742 | break; | |
4743 | ||
4744 | case DST__K_SET_ABS_PC: | |
4745 | cmd_length = 5; | |
4746 | break; | |
4747 | ||
4748 | default: | |
4749 | if (cmd <= 0) | |
4750 | cmd_length = 1; | |
4751 | else | |
4752 | cmd_length = 2; | |
4753 | break; | |
4754 | } | |
4755 | ||
4756 | if (pcl_ptr - ptr + cmd_length > rec_length) | |
4757 | break; | |
4758 | ||
95e34ef7 TG |
4759 | switch (cmd) |
4760 | { | |
4761 | case DST__K_DELTA_PC_W: | |
4762 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4763 | curr_pc += data; | |
4764 | curr_linenum += 1; | |
95e34ef7 TG |
4765 | vms_debug2 ((4, "DST__K_DELTA_PC_W: %d\n", data)); |
4766 | break; | |
4767 | ||
4768 | case DST__K_DELTA_PC_L: | |
4769 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4770 | curr_pc += data; | |
4771 | curr_linenum += 1; | |
95e34ef7 TG |
4772 | vms_debug2 ((4, "DST__K_DELTA_PC_L: %d\n", data)); |
4773 | break; | |
4774 | ||
4775 | case DST__K_INCR_LINUM: | |
4776 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4777 | curr_linenum += data; | |
95e34ef7 TG |
4778 | vms_debug2 ((4, "DST__K_INCR_LINUM: %d\n", data)); |
4779 | break; | |
4780 | ||
4781 | case DST__K_INCR_LINUM_W: | |
4782 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4783 | curr_linenum += data; | |
95e34ef7 TG |
4784 | vms_debug2 ((4, "DST__K_INCR_LINUM_W: %d\n", data)); |
4785 | break; | |
4786 | ||
4787 | case DST__K_INCR_LINUM_L: | |
4788 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4789 | curr_linenum += data; | |
95e34ef7 TG |
4790 | vms_debug2 ((4, "DST__K_INCR_LINUM_L: %d\n", data)); |
4791 | break; | |
4792 | ||
4793 | case DST__K_SET_LINUM_INCR: | |
4eca0228 | 4794 | _bfd_error_handler |
38f14ab8 | 4795 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR"); |
95e34ef7 TG |
4796 | break; |
4797 | ||
4798 | case DST__K_SET_LINUM_INCR_W: | |
4eca0228 | 4799 | _bfd_error_handler |
38f14ab8 | 4800 | (_("%s not implemented"), "DST__K_SET_LINUM_INCR_W"); |
95e34ef7 TG |
4801 | break; |
4802 | ||
4803 | case DST__K_RESET_LINUM_INCR: | |
4eca0228 | 4804 | _bfd_error_handler |
38f14ab8 | 4805 | (_("%s not implemented"), "DST__K_RESET_LINUM_INCR"); |
95e34ef7 TG |
4806 | break; |
4807 | ||
4808 | case DST__K_BEG_STMT_MODE: | |
4eca0228 | 4809 | _bfd_error_handler |
38f14ab8 | 4810 | (_("%s not implemented"), "DST__K_BEG_STMT_MODE"); |
95e34ef7 TG |
4811 | break; |
4812 | ||
4813 | case DST__K_END_STMT_MODE: | |
4eca0228 | 4814 | _bfd_error_handler |
38f14ab8 | 4815 | (_("%s not implemented"), "DST__K_END_STMT_MODE"); |
95e34ef7 TG |
4816 | break; |
4817 | ||
4818 | case DST__K_SET_LINUM_B: | |
4819 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4820 | curr_linenum = data; | |
95e34ef7 TG |
4821 | vms_debug2 ((4, "DST__K_SET_LINUM_B: %d\n", data)); |
4822 | break; | |
4823 | ||
4824 | case DST__K_SET_LINUM: | |
4825 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4826 | curr_linenum = data; | |
95e34ef7 TG |
4827 | vms_debug2 ((4, "DST__K_SET_LINE_NUM: %d\n", data)); |
4828 | break; | |
4829 | ||
4830 | case DST__K_SET_LINUM_L: | |
4831 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4832 | curr_linenum = data; | |
95e34ef7 TG |
4833 | vms_debug2 ((4, "DST__K_SET_LINUM_L: %d\n", data)); |
4834 | break; | |
4835 | ||
4836 | case DST__K_SET_PC: | |
4eca0228 | 4837 | _bfd_error_handler |
38f14ab8 | 4838 | (_("%s not implemented"), "DST__K_SET_PC"); |
95e34ef7 TG |
4839 | break; |
4840 | ||
4841 | case DST__K_SET_PC_W: | |
4eca0228 | 4842 | _bfd_error_handler |
38f14ab8 | 4843 | (_("%s not implemented"), "DST__K_SET_PC_W"); |
95e34ef7 TG |
4844 | break; |
4845 | ||
4846 | case DST__K_SET_PC_L: | |
4eca0228 | 4847 | _bfd_error_handler |
38f14ab8 | 4848 | (_("%s not implemented"), "DST__K_SET_PC_L"); |
95e34ef7 TG |
4849 | break; |
4850 | ||
4851 | case DST__K_SET_STMTNUM: | |
4eca0228 | 4852 | _bfd_error_handler |
38f14ab8 | 4853 | (_("%s not implemented"), "DST__K_SET_STMTNUM"); |
95e34ef7 TG |
4854 | break; |
4855 | ||
4856 | case DST__K_TERM: | |
4857 | data = pcl_ptr[DST_S_B_PCLINE_UNSBYTE]; | |
4858 | curr_pc += data; | |
95e34ef7 TG |
4859 | vms_debug2 ((4, "DST__K_TERM: %d\n", data)); |
4860 | break; | |
4861 | ||
4862 | case DST__K_TERM_W: | |
4863 | data = bfd_getl16 (pcl_ptr + DST_S_W_PCLINE_UNSWORD); | |
4864 | curr_pc += data; | |
95e34ef7 TG |
4865 | vms_debug2 ((4, "DST__K_TERM_W: %d\n", data)); |
4866 | break; | |
4867 | ||
4868 | case DST__K_TERM_L: | |
4869 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4870 | curr_pc += data; | |
95e34ef7 TG |
4871 | vms_debug2 ((4, "DST__K_TERM_L: %d\n", data)); |
4872 | break; | |
4873 | ||
4874 | case DST__K_SET_ABS_PC: | |
4875 | data = bfd_getl32 (pcl_ptr + DST_S_L_PCLINE_UNSLONG); | |
4876 | curr_pc = data; | |
95e34ef7 TG |
4877 | vms_debug2 ((4, "DST__K_SET_ABS_PC: 0x%x\n", data)); |
4878 | break; | |
4879 | ||
4880 | default: | |
4881 | if (cmd <= 0) | |
4882 | { | |
4883 | curr_pc -= cmd; | |
4884 | curr_linenum += 1; | |
95e34ef7 | 4885 | vms_debug2 ((4, "bump pc to 0x%lx and line to %d\n", |
07d6d2b8 | 4886 | (unsigned long)curr_pc, curr_linenum)); |
95e34ef7 TG |
4887 | } |
4888 | else | |
77c225bd | 4889 | _bfd_error_handler (_("unknown line command %d"), cmd); |
95e34ef7 TG |
4890 | break; |
4891 | } | |
4892 | ||
4893 | if ((curr_linenum != prev_linum && curr_pc != prev_pc) | |
4894 | || cmd <= 0 | |
4895 | || cmd == DST__K_DELTA_PC_L | |
4896 | || cmd == DST__K_DELTA_PC_W) | |
4897 | { | |
4898 | line = (struct lineinfo *) | |
4899 | bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
4900 | line->address = curr_pc; | |
4901 | line->line = curr_linenum; | |
4902 | ||
4903 | curr_line->next = line; | |
4904 | curr_line = line; | |
4905 | ||
4906 | prev_linum = curr_linenum; | |
4907 | prev_pc = curr_pc; | |
4908 | vms_debug2 ((4, "-> correlate pc 0x%lx with line %d\n", | |
07d6d2b8 | 4909 | (unsigned long)curr_pc, curr_linenum)); |
95e34ef7 TG |
4910 | } |
4911 | ||
4912 | pcl_ptr += cmd_length; | |
4913 | } | |
4914 | break; | |
4915 | ||
4916 | case 0x17: /* Undocumented type used by DEC C to declare equates. */ | |
4917 | vms_debug2 ((3, "undocumented type 0x17\n")); | |
4918 | break; | |
4919 | ||
4920 | default: | |
4921 | vms_debug2 ((3, "ignoring record\n")); | |
4922 | break; | |
4923 | ||
4924 | } | |
4925 | ||
4926 | ptr += rec_length; | |
4927 | } | |
4928 | ||
4929 | /* Finalize tables with EOL marker. */ | |
4930 | srec = (struct srecinfo *) bfd_zalloc (abfd, sizeof (struct srecinfo)); | |
4931 | srec->line = (unsigned int) -1; | |
4932 | srec->srec = (unsigned int) -1; | |
4933 | curr_srec->next = srec; | |
4934 | ||
4935 | line = (struct lineinfo *) bfd_zalloc (abfd, sizeof (struct lineinfo)); | |
4936 | line->line = (unsigned int) -1; | |
4937 | line->address = (bfd_vma) -1; | |
4938 | curr_line->next = line; | |
4939 | ||
4940 | /* Advertise that this module has been parsed. This is needed | |
4941 | because parsing can be either performed at module creation | |
4942 | or deferred until debug info is consumed. */ | |
4943 | SET_MODULE_PARSED (module); | |
0a1b45a2 | 4944 | return true; |
95e34ef7 TG |
4945 | } |
4946 | ||
4947 | /* Build the list of modules for the specified BFD. */ | |
4948 | ||
4949 | static struct module * | |
4950 | build_module_list (bfd *abfd) | |
4951 | { | |
4952 | struct module *module, *list = NULL; | |
4953 | asection *dmt; | |
4954 | ||
4955 | if ((dmt = bfd_get_section_by_name (abfd, "$DMT$"))) | |
4956 | { | |
4957 | /* We have a DMT section so this must be an image. Parse the | |
4958 | section and build the list of modules. This is sufficient | |
4959 | since we can compute the start address and the end address | |
4960 | of every module from the section contents. */ | |
fd361982 | 4961 | bfd_size_type size = bfd_section_size (dmt); |
3c8ed65a | 4962 | unsigned char *buf, *ptr, *end; |
95e34ef7 | 4963 | |
3c8ed65a | 4964 | if (! bfd_malloc_and_get_section (abfd, dmt, &buf)) |
95e34ef7 TG |
4965 | return NULL; |
4966 | ||
4967 | vms_debug2 ((2, "DMT\n")); | |
4968 | ||
3c8ed65a | 4969 | ptr = buf; |
95e34ef7 | 4970 | end = ptr + size; |
ddbe6976 | 4971 | while (end - ptr >= DBG_S_C_DMT_HEADER_SIZE) |
95e34ef7 TG |
4972 | { |
4973 | /* Each header declares a module with its start offset and size | |
4974 | of debug info in the DST section, as well as the count of | |
4975 | program sections (i.e. address spans) it contains. */ | |
3c8ed65a AM |
4976 | unsigned int modbeg = bfd_getl32 (ptr + DBG_S_L_DMT_MODBEG); |
4977 | unsigned int msize = bfd_getl32 (ptr + DBG_S_L_DST_SIZE); | |
95e34ef7 TG |
4978 | int count = bfd_getl16 (ptr + DBG_S_W_DMT_PSECT_COUNT); |
4979 | ptr += DBG_S_C_DMT_HEADER_SIZE; | |
4980 | ||
3c8ed65a | 4981 | vms_debug2 ((3, "module: modbeg = %u, size = %u, count = %d\n", |
07d6d2b8 | 4982 | modbeg, msize, count)); |
95e34ef7 TG |
4983 | |
4984 | /* We create a 'module' structure for each program section since | |
4985 | we only support contiguous addresses in a 'module' structure. | |
4986 | As a consequence, the actual debug info in the DST section is | |
4987 | shared and can be parsed multiple times; that doesn't seem to | |
4988 | cause problems in practice. */ | |
ddbe6976 | 4989 | while (count-- > 0 && end - ptr >= DBG_S_C_DMT_PSECT_SIZE) |
95e34ef7 | 4990 | { |
3c8ed65a AM |
4991 | unsigned int start = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_START); |
4992 | unsigned int length = bfd_getl32 (ptr + DBG_S_L_DMT_PSECT_LENGTH); | |
95e34ef7 TG |
4993 | module = new_module (abfd); |
4994 | module->modbeg = modbeg; | |
4995 | module->size = msize; | |
4996 | module->low = start; | |
4997 | module->high = start + length; | |
4998 | module->next = list; | |
4999 | list = module; | |
5000 | ptr += DBG_S_C_DMT_PSECT_SIZE; | |
5001 | ||
3c8ed65a | 5002 | vms_debug2 ((4, "section: start = 0x%x, length = %u\n", |
07d6d2b8 | 5003 | start, length)); |
95e34ef7 TG |
5004 | } |
5005 | } | |
3c8ed65a | 5006 | free (buf); |
95e34ef7 TG |
5007 | } |
5008 | else | |
5009 | { | |
5010 | /* We don't have a DMT section so this must be an object. Parse | |
5011 | the module right now in order to compute its start address and | |
5012 | end address. */ | |
8185f55c TG |
5013 | void *dst = PRIV (dst_section)->contents; |
5014 | ||
5015 | if (dst == NULL) | |
07d6d2b8 | 5016 | return NULL; |
8185f55c | 5017 | |
95e34ef7 | 5018 | module = new_module (abfd); |
77c225bd AM |
5019 | if (!parse_module (abfd, module, PRIV (dst_section)->contents, |
5020 | PRIV (dst_section)->size)) | |
9cb56943 | 5021 | return NULL; |
95e34ef7 TG |
5022 | list = module; |
5023 | } | |
5024 | ||
5025 | return list; | |
5026 | } | |
5027 | ||
5028 | /* Calculate and return the name of the source file and the line nearest | |
5029 | to the wanted location in the specified module. */ | |
5030 | ||
0a1b45a2 | 5031 | static bool |
95e34ef7 TG |
5032 | module_find_nearest_line (bfd *abfd, struct module *module, bfd_vma addr, |
5033 | const char **file, const char **func, | |
5034 | unsigned int *line) | |
5035 | { | |
5036 | struct funcinfo *funcinfo; | |
5037 | struct lineinfo *lineinfo; | |
5038 | struct srecinfo *srecinfo; | |
0a1b45a2 | 5039 | bool ret = false; |
95e34ef7 TG |
5040 | |
5041 | /* Parse this module if that was not done at module creation. */ | |
5042 | if (! IS_MODULE_PARSED (module)) | |
5043 | { | |
5044 | unsigned int size = module->size; | |
5045 | unsigned int modbeg = PRIV (dst_section)->filepos + module->modbeg; | |
2bb3687b | 5046 | unsigned char *buffer; |
95e34ef7 TG |
5047 | |
5048 | if (bfd_seek (abfd, modbeg, SEEK_SET) != 0 | |
2bb3687b | 5049 | || (buffer = _bfd_malloc_and_read (abfd, size, size)) == NULL) |
95e34ef7 TG |
5050 | { |
5051 | bfd_set_error (bfd_error_no_debug_section); | |
0a1b45a2 | 5052 | return false; |
95e34ef7 TG |
5053 | } |
5054 | ||
9cb56943 | 5055 | ret = parse_module (abfd, module, buffer, size); |
95e34ef7 | 5056 | free (buffer); |
9cb56943 AM |
5057 | if (!ret) |
5058 | return ret; | |
95e34ef7 TG |
5059 | } |
5060 | ||
5061 | /* Find out the function (if any) that contains the address. */ | |
5062 | for (funcinfo = module->func_table; funcinfo; funcinfo = funcinfo->next) | |
5063 | if (addr >= funcinfo->low && addr <= funcinfo->high) | |
5064 | { | |
07d6d2b8 | 5065 | *func = funcinfo->name; |
0a1b45a2 | 5066 | ret = true; |
95e34ef7 TG |
5067 | break; |
5068 | } | |
5069 | ||
5070 | /* Find out the source file and the line nearest to the address. */ | |
5071 | for (lineinfo = module->line_table; lineinfo; lineinfo = lineinfo->next) | |
5072 | if (lineinfo->next && addr < lineinfo->next->address) | |
5073 | { | |
5074 | for (srecinfo = module->srec_table; srecinfo; srecinfo = srecinfo->next) | |
5075 | if (srecinfo->next && lineinfo->line < srecinfo->next->line) | |
5076 | { | |
5077 | if (srecinfo->sfile > 0) | |
5078 | { | |
5079 | *file = module->file_table[srecinfo->sfile].name; | |
5080 | *line = srecinfo->srec + lineinfo->line - srecinfo->line; | |
5081 | } | |
5082 | else | |
5083 | { | |
5084 | *file = module->name; | |
5085 | *line = lineinfo->line; | |
5086 | } | |
0a1b45a2 | 5087 | return true; |
95e34ef7 TG |
5088 | } |
5089 | ||
5090 | break; | |
5091 | } | |
5092 | ||
5093 | return ret; | |
5094 | } | |
5095 | ||
5096 | /* Provided a BFD, a section and an offset into the section, calculate and | |
5097 | return the name of the source file and the line nearest to the wanted | |
5098 | location. */ | |
5099 | ||
0a1b45a2 | 5100 | static bool |
fb167eb2 AM |
5101 | _bfd_vms_find_nearest_line (bfd *abfd, |
5102 | asymbol **symbols ATTRIBUTE_UNUSED, | |
5103 | asection *section, | |
5104 | bfd_vma offset, | |
5105 | const char **file, | |
5106 | const char **func, | |
5107 | unsigned int *line, | |
5108 | unsigned int *discriminator) | |
95e34ef7 TG |
5109 | { |
5110 | struct module *module; | |
5111 | ||
5112 | /* What address are we looking for? */ | |
5113 | bfd_vma addr = section->vma + offset; | |
5114 | ||
5115 | *file = NULL; | |
5116 | *func = NULL; | |
5117 | *line = 0; | |
fb167eb2 AM |
5118 | if (discriminator) |
5119 | *discriminator = 0; | |
95e34ef7 | 5120 | |
8185f55c | 5121 | /* We can't do anything if there is no DST (debug symbol table). */ |
a283ff93 | 5122 | if (PRIV (dst_section) == NULL) |
0a1b45a2 | 5123 | return false; |
95e34ef7 | 5124 | |
8185f55c | 5125 | /* Create the module list - if not already done. */ |
95e34ef7 TG |
5126 | if (PRIV (modules) == NULL) |
5127 | { | |
5128 | PRIV (modules) = build_module_list (abfd); | |
5129 | if (PRIV (modules) == NULL) | |
0a1b45a2 | 5130 | return false; |
95e34ef7 TG |
5131 | } |
5132 | ||
5133 | for (module = PRIV (modules); module; module = module->next) | |
5134 | if (addr >= module->low && addr <= module->high) | |
5135 | return module_find_nearest_line (abfd, module, addr, file, func, line); | |
5136 | ||
0a1b45a2 | 5137 | return false; |
95e34ef7 TG |
5138 | } |
5139 | \f | |
5140 | /* Canonicalizations. */ | |
5141 | /* Set name, value, section and flags of SYM from E. */ | |
5142 | ||
0a1b45a2 | 5143 | static bool |
95e34ef7 TG |
5144 | alpha_vms_convert_symbol (bfd *abfd, struct vms_symbol_entry *e, asymbol *sym) |
5145 | { | |
5146 | flagword flags; | |
5147 | symvalue value; | |
5148 | asection *sec; | |
5149 | const char *name; | |
5150 | ||
5151 | name = e->name; | |
5152 | value = 0; | |
5153 | flags = BSF_NO_FLAGS; | |
5154 | sec = NULL; | |
5155 | ||
5156 | switch (e->typ) | |
5157 | { | |
5158 | case EGSD__C_SYM: | |
5159 | if (e->flags & EGSY__V_WEAK) | |
07d6d2b8 | 5160 | flags |= BSF_WEAK; |
95e34ef7 TG |
5161 | |
5162 | if (e->flags & EGSY__V_DEF) | |
07d6d2b8 AM |
5163 | { |
5164 | /* Symbol definition. */ | |
5165 | flags |= BSF_GLOBAL; | |
5166 | if (e->flags & EGSY__V_NORM) | |
5167 | flags |= BSF_FUNCTION; | |
5168 | value = e->value; | |
5169 | sec = e->section; | |
5170 | } | |
95e34ef7 | 5171 | else |
07d6d2b8 AM |
5172 | { |
5173 | /* Symbol reference. */ | |
5174 | sec = bfd_und_section_ptr; | |
5175 | } | |
95e34ef7 TG |
5176 | break; |
5177 | ||
5178 | case EGSD__C_SYMG: | |
5179 | /* A universal symbol is by definition global... */ | |
5180 | flags |= BSF_GLOBAL; | |
5181 | ||
5182 | /* ...and dynamic in shared libraries. */ | |
5183 | if (abfd->flags & DYNAMIC) | |
07d6d2b8 | 5184 | flags |= BSF_DYNAMIC; |
95e34ef7 TG |
5185 | |
5186 | if (e->flags & EGSY__V_WEAK) | |
07d6d2b8 | 5187 | flags |= BSF_WEAK; |
95e34ef7 TG |
5188 | |
5189 | if (!(e->flags & EGSY__V_DEF)) | |
07d6d2b8 | 5190 | abort (); |
95e34ef7 TG |
5191 | |
5192 | if (e->flags & EGSY__V_NORM) | |
07d6d2b8 | 5193 | flags |= BSF_FUNCTION; |
95e34ef7 | 5194 | |
a928f1d7 TG |
5195 | value = e->value; |
5196 | /* sec = e->section; */ | |
95e34ef7 | 5197 | sec = bfd_abs_section_ptr; |
95e34ef7 TG |
5198 | break; |
5199 | ||
5200 | default: | |
0a1b45a2 | 5201 | return false; |
95e34ef7 TG |
5202 | } |
5203 | ||
5204 | sym->name = name; | |
5205 | sym->section = sec; | |
5206 | sym->flags = flags; | |
5207 | sym->value = value; | |
0a1b45a2 | 5208 | return true; |
95e34ef7 TG |
5209 | } |
5210 | ||
5211 | ||
5212 | /* Return the number of bytes required to store a vector of pointers | |
5213 | to asymbols for all the symbols in the BFD abfd, including a | |
5214 | terminal NULL pointer. If there are no symbols in the BFD, | |
5215 | then return 0. If an error occurs, return -1. */ | |
5216 | ||
5217 | static long | |
5218 | alpha_vms_get_symtab_upper_bound (bfd *abfd) | |
5219 | { | |
5220 | vms_debug2 ((1, "alpha_vms_get_symtab_upper_bound (%p), %d symbols\n", | |
07d6d2b8 | 5221 | abfd, PRIV (gsd_sym_count))); |
95e34ef7 TG |
5222 | |
5223 | return (PRIV (gsd_sym_count) + 1) * sizeof (asymbol *); | |
5224 | } | |
5225 | ||
5226 | /* Read the symbols from the BFD abfd, and fills in the vector | |
5227 | location with pointers to the symbols and a trailing NULL. | |
5228 | ||
5229 | Return number of symbols read. */ | |
5230 | ||
5231 | static long | |
5232 | alpha_vms_canonicalize_symtab (bfd *abfd, asymbol **symbols) | |
5233 | { | |
5234 | unsigned int i; | |
5235 | ||
5236 | vms_debug2 ((1, "alpha_vms_canonicalize_symtab (%p, <ret>)\n", abfd)); | |
5237 | ||
5238 | if (PRIV (csymbols) == NULL) | |
5239 | { | |
5240 | PRIV (csymbols) = (asymbol **) bfd_alloc | |
07d6d2b8 | 5241 | (abfd, PRIV (gsd_sym_count) * sizeof (asymbol *)); |
95e34ef7 TG |
5242 | |
5243 | /* Traverse table and fill symbols vector. */ | |
5244 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 AM |
5245 | { |
5246 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
5247 | asymbol *sym; | |
95e34ef7 | 5248 | |
07d6d2b8 AM |
5249 | sym = bfd_make_empty_symbol (abfd); |
5250 | if (sym == NULL || !alpha_vms_convert_symbol (abfd, e, sym)) | |
5251 | { | |
5252 | bfd_release (abfd, PRIV (csymbols)); | |
5253 | PRIV (csymbols) = NULL; | |
5254 | return -1; | |
5255 | } | |
95e34ef7 | 5256 | |
07d6d2b8 AM |
5257 | PRIV (csymbols)[i] = sym; |
5258 | } | |
95e34ef7 TG |
5259 | } |
5260 | ||
5261 | if (symbols != NULL) | |
5262 | { | |
5263 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
07d6d2b8 | 5264 | symbols[i] = PRIV (csymbols)[i]; |
95e34ef7 TG |
5265 | symbols[i] = NULL; |
5266 | } | |
5267 | ||
5268 | return PRIV (gsd_sym_count); | |
5269 | } | |
5270 | ||
5271 | /* Read and convert relocations from ETIR. We do it once for all sections. */ | |
5272 | ||
0a1b45a2 | 5273 | static bool |
95e34ef7 TG |
5274 | alpha_vms_slurp_relocs (bfd *abfd) |
5275 | { | |
5276 | int cur_psect = -1; | |
5277 | ||
5278 | vms_debug2 ((3, "alpha_vms_slurp_relocs\n")); | |
5279 | ||
5280 | /* We slurp relocs only once, for all sections. */ | |
8c8fa33c AM |
5281 | if (PRIV (reloc_done) != 0) |
5282 | return PRIV (reloc_done) == 1; | |
95e34ef7 TG |
5283 | |
5284 | if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0) | |
8c8fa33c | 5285 | goto fail; |
95e34ef7 TG |
5286 | |
5287 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) | |
8c8fa33c | 5288 | goto fail; |
95e34ef7 TG |
5289 | |
5290 | while (1) | |
5291 | { | |
5292 | unsigned char *begin; | |
5293 | unsigned char *end; | |
5294 | unsigned char *ptr; | |
5295 | bfd_reloc_code_real_type reloc_code; | |
5296 | int type; | |
5297 | bfd_vma vaddr = 0; | |
5298 | ||
5299 | int length; | |
5300 | ||
5301 | bfd_vma cur_address; | |
5302 | int cur_psidx = -1; | |
5303 | unsigned char *cur_sym = NULL; | |
5304 | int prev_cmd = -1; | |
5305 | bfd_vma cur_addend = 0; | |
5306 | ||
5307 | /* Skip non-ETIR records. */ | |
5308 | type = _bfd_vms_get_object_record (abfd); | |
8c8fa33c AM |
5309 | if (type < 0) |
5310 | goto fail; | |
95e34ef7 | 5311 | if (type == EOBJ__C_EEOM) |
07d6d2b8 | 5312 | break; |
95e34ef7 | 5313 | if (type != EOBJ__C_ETIR) |
07d6d2b8 | 5314 | continue; |
95e34ef7 TG |
5315 | |
5316 | begin = PRIV (recrd.rec) + 4; | |
5317 | end = PRIV (recrd.rec) + PRIV (recrd.rec_size); | |
5318 | ||
06ba6be6 | 5319 | for (ptr = begin; ptr + 4 <= end; ptr += length) |
07d6d2b8 AM |
5320 | { |
5321 | int cmd; | |
5322 | ||
5323 | cmd = bfd_getl16 (ptr); | |
5324 | length = bfd_getl16 (ptr + 2); | |
06ba6be6 AM |
5325 | if (length < 4 || length > end - ptr) |
5326 | { | |
5327 | bad_rec: | |
5328 | _bfd_error_handler (_("corrupt reloc record")); | |
5329 | goto fail; | |
5330 | } | |
07d6d2b8 AM |
5331 | |
5332 | cur_address = vaddr; | |
5333 | ||
5334 | vms_debug2 ((4, "alpha_vms_slurp_relocs: etir %s\n", | |
5335 | _bfd_vms_etir_name (cmd))); | |
5336 | ||
5337 | switch (cmd) | |
5338 | { | |
5339 | case ETIR__C_STA_GBL: /* ALPHA_R_REFLONG und_section, step 1 */ | |
5340 | /* ALPHA_R_REFQUAD und_section, step 1 */ | |
5341 | cur_sym = ptr + 4; | |
5342 | prev_cmd = cmd; | |
5343 | continue; | |
5344 | ||
5345 | case ETIR__C_STA_PQ: /* ALPHA_R_REF{LONG|QUAD}, others part 1 */ | |
06ba6be6 AM |
5346 | if (length < 16) |
5347 | goto bad_rec; | |
07d6d2b8 AM |
5348 | cur_psidx = bfd_getl32 (ptr + 4); |
5349 | cur_addend = bfd_getl64 (ptr + 8); | |
5350 | prev_cmd = cmd; | |
5351 | continue; | |
5352 | ||
5353 | case ETIR__C_CTL_SETRB: | |
5354 | if (prev_cmd != ETIR__C_STA_PQ) | |
5355 | { | |
4eca0228 | 5356 | _bfd_error_handler |
695344c0 | 5357 | /* xgettext:c-format */ |
38f14ab8 | 5358 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), |
07d6d2b8 | 5359 | _bfd_vms_etir_name (cmd)); |
8c8fa33c | 5360 | goto fail; |
07d6d2b8 AM |
5361 | } |
5362 | cur_psect = cur_psidx; | |
5363 | vaddr = cur_addend; | |
5364 | cur_psidx = -1; | |
5365 | cur_addend = 0; | |
5366 | continue; | |
5367 | ||
5368 | case ETIR__C_STA_LW: /* ALPHA_R_REFLONG abs_section, step 1 */ | |
5369 | /* ALPHA_R_REFLONG und_section, step 2 */ | |
5370 | if (prev_cmd != -1) | |
5371 | { | |
5372 | if (prev_cmd != ETIR__C_STA_GBL) | |
5373 | { | |
4eca0228 | 5374 | _bfd_error_handler |
695344c0 | 5375 | /* xgettext:c-format */ |
38f14ab8 | 5376 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
07d6d2b8 | 5377 | _bfd_vms_etir_name (ETIR__C_STA_LW)); |
8c8fa33c | 5378 | goto fail; |
07d6d2b8 AM |
5379 | } |
5380 | } | |
06ba6be6 AM |
5381 | if (length < 8) |
5382 | goto bad_rec; | |
07d6d2b8 AM |
5383 | cur_addend = bfd_getl32 (ptr + 4); |
5384 | prev_cmd = cmd; | |
5385 | continue; | |
5386 | ||
5387 | case ETIR__C_STA_QW: /* ALPHA_R_REFQUAD abs_section, step 1 */ | |
5388 | /* ALPHA_R_REFQUAD und_section, step 2 */ | |
5389 | if (prev_cmd != -1 && prev_cmd != ETIR__C_STA_GBL) | |
5390 | { | |
4eca0228 | 5391 | _bfd_error_handler |
695344c0 | 5392 | /* xgettext:c-format */ |
38f14ab8 | 5393 | (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), |
07d6d2b8 | 5394 | _bfd_vms_etir_name (ETIR__C_STA_QW)); |
8c8fa33c | 5395 | goto fail; |
07d6d2b8 | 5396 | } |
06ba6be6 AM |
5397 | if (length < 12) |
5398 | goto bad_rec; | |
07d6d2b8 AM |
5399 | cur_addend = bfd_getl64 (ptr + 4); |
5400 | prev_cmd = cmd; | |
5401 | continue; | |
5402 | ||
5403 | case ETIR__C_STO_LW: /* ALPHA_R_REFLONG und_section, step 4 */ | |
5404 | /* ALPHA_R_REFLONG abs_section, step 2 */ | |
5405 | /* ALPHA_R_REFLONG others, step 2 */ | |
5406 | if (prev_cmd != ETIR__C_OPR_ADD | |
5407 | && prev_cmd != ETIR__C_STA_LW | |
5408 | && prev_cmd != ETIR__C_STA_PQ) | |
5409 | { | |
695344c0 | 5410 | /* xgettext:c-format */ |
38f14ab8 | 5411 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5412 | _bfd_vms_etir_name (prev_cmd), |
5413 | _bfd_vms_etir_name (ETIR__C_STO_LW)); | |
8c8fa33c | 5414 | goto fail; |
07d6d2b8 AM |
5415 | } |
5416 | reloc_code = BFD_RELOC_32; | |
5417 | break; | |
5418 | ||
5419 | case ETIR__C_STO_QW: /* ALPHA_R_REFQUAD und_section, step 4 */ | |
5420 | /* ALPHA_R_REFQUAD abs_section, step 2 */ | |
5421 | if (prev_cmd != ETIR__C_OPR_ADD && prev_cmd != ETIR__C_STA_QW) | |
5422 | { | |
695344c0 | 5423 | /* xgettext:c-format */ |
38f14ab8 | 5424 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5425 | _bfd_vms_etir_name (prev_cmd), |
5426 | _bfd_vms_etir_name (ETIR__C_STO_QW)); | |
8c8fa33c | 5427 | goto fail; |
07d6d2b8 AM |
5428 | } |
5429 | reloc_code = BFD_RELOC_64; | |
5430 | break; | |
5431 | ||
5432 | case ETIR__C_STO_OFF: /* ALPHA_R_REFQUAD others, step 2 */ | |
5433 | if (prev_cmd != ETIR__C_STA_PQ) | |
5434 | { | |
695344c0 | 5435 | /* xgettext:c-format */ |
38f14ab8 | 5436 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5437 | _bfd_vms_etir_name (prev_cmd), |
5438 | _bfd_vms_etir_name (ETIR__C_STO_OFF)); | |
8c8fa33c | 5439 | goto fail; |
07d6d2b8 AM |
5440 | } |
5441 | reloc_code = BFD_RELOC_64; | |
5442 | break; | |
5443 | ||
5444 | case ETIR__C_OPR_ADD: /* ALPHA_R_REFLONG und_section, step 3 */ | |
5445 | /* ALPHA_R_REFQUAD und_section, step 3 */ | |
5446 | if (prev_cmd != ETIR__C_STA_LW && prev_cmd != ETIR__C_STA_QW) | |
5447 | { | |
695344c0 | 5448 | /* xgettext:c-format */ |
38f14ab8 | 5449 | _bfd_error_handler (_("unknown reloc %s + %s"), |
4eca0228 AM |
5450 | _bfd_vms_etir_name (prev_cmd), |
5451 | _bfd_vms_etir_name (ETIR__C_OPR_ADD)); | |
8c8fa33c | 5452 | goto fail; |
07d6d2b8 AM |
5453 | } |
5454 | prev_cmd = ETIR__C_OPR_ADD; | |
5455 | continue; | |
5456 | ||
5457 | case ETIR__C_STO_CA: /* ALPHA_R_CODEADDR */ | |
5458 | reloc_code = BFD_RELOC_ALPHA_CODEADDR; | |
5459 | cur_sym = ptr + 4; | |
5460 | break; | |
5461 | ||
5462 | case ETIR__C_STO_GBL: /* ALPHA_R_REFQUAD und_section */ | |
5463 | reloc_code = BFD_RELOC_64; | |
5464 | cur_sym = ptr + 4; | |
5465 | break; | |
5466 | ||
5467 | case ETIR__C_STO_GBL_LW: /* ALPHA_R_REFLONG und_section */ | |
5468 | reloc_code = BFD_RELOC_32; | |
5469 | cur_sym = ptr + 4; | |
5470 | break; | |
5471 | ||
5472 | case ETIR__C_STC_LP_PSB: /* ALPHA_R_LINKAGE */ | |
5473 | reloc_code = BFD_RELOC_ALPHA_LINKAGE; | |
5474 | cur_sym = ptr + 8; | |
5475 | break; | |
5476 | ||
5477 | case ETIR__C_STC_NOP_GBL: /* ALPHA_R_NOP */ | |
5478 | reloc_code = BFD_RELOC_ALPHA_NOP; | |
5479 | goto call_reloc; | |
5480 | ||
5481 | case ETIR__C_STC_BSR_GBL: /* ALPHA_R_BSR */ | |
5482 | reloc_code = BFD_RELOC_ALPHA_BSR; | |
5483 | goto call_reloc; | |
5484 | ||
5485 | case ETIR__C_STC_LDA_GBL: /* ALPHA_R_LDA */ | |
5486 | reloc_code = BFD_RELOC_ALPHA_LDA; | |
5487 | goto call_reloc; | |
5488 | ||
5489 | case ETIR__C_STC_BOH_GBL: /* ALPHA_R_BOH */ | |
5490 | reloc_code = BFD_RELOC_ALPHA_BOH; | |
5491 | goto call_reloc; | |
5492 | ||
5493 | call_reloc: | |
06ba6be6 AM |
5494 | if (length < 36) |
5495 | goto bad_rec; | |
07d6d2b8 AM |
5496 | cur_sym = ptr + 4 + 32; |
5497 | cur_address = bfd_getl64 (ptr + 4 + 8); | |
5498 | cur_addend = bfd_getl64 (ptr + 4 + 24); | |
5499 | break; | |
5500 | ||
5501 | case ETIR__C_STO_IMM: | |
06ba6be6 AM |
5502 | if (length < 8) |
5503 | goto bad_rec; | |
07d6d2b8 AM |
5504 | vaddr += bfd_getl32 (ptr + 4); |
5505 | continue; | |
5506 | ||
5507 | default: | |
38f14ab8 | 5508 | _bfd_error_handler (_("unknown reloc %s"), |
4eca0228 | 5509 | _bfd_vms_etir_name (cmd)); |
8c8fa33c | 5510 | goto fail; |
07d6d2b8 | 5511 | } |
95e34ef7 | 5512 | |
07d6d2b8 AM |
5513 | { |
5514 | asection *sec; | |
5515 | struct vms_section_data_struct *vms_sec; | |
5516 | arelent *reloc; | |
706704c8 | 5517 | bfd_size_type size; |
95e34ef7 | 5518 | |
07d6d2b8 AM |
5519 | /* Get section to which the relocation applies. */ |
5520 | if (cur_psect < 0 || cur_psect > (int)PRIV (section_count)) | |
5521 | { | |
38f14ab8 | 5522 | _bfd_error_handler (_("invalid section index in ETIR")); |
8c8fa33c | 5523 | goto fail; |
07d6d2b8 | 5524 | } |
d120eec2 | 5525 | |
cb06d03a | 5526 | if (PRIV (sections) == NULL) |
8c8fa33c | 5527 | goto fail; |
07d6d2b8 AM |
5528 | sec = PRIV (sections)[cur_psect]; |
5529 | if (sec == bfd_abs_section_ptr) | |
5530 | { | |
38f14ab8 | 5531 | _bfd_error_handler (_("relocation for non-REL psect")); |
8c8fa33c | 5532 | goto fail; |
07d6d2b8 AM |
5533 | } |
5534 | ||
5535 | vms_sec = vms_section_data (sec); | |
5536 | ||
5537 | /* Allocate a reloc entry. */ | |
5538 | if (sec->reloc_count >= vms_sec->reloc_max) | |
5539 | { | |
5540 | if (vms_sec->reloc_max == 0) | |
5541 | { | |
5542 | vms_sec->reloc_max = 64; | |
5543 | sec->relocation = bfd_zmalloc | |
5544 | (vms_sec->reloc_max * sizeof (arelent)); | |
5545 | } | |
5546 | else | |
5547 | { | |
5548 | vms_sec->reloc_max *= 2; | |
9cb56943 | 5549 | sec->relocation = bfd_realloc_or_free |
07d6d2b8 | 5550 | (sec->relocation, vms_sec->reloc_max * sizeof (arelent)); |
9cb56943 | 5551 | if (sec->relocation == NULL) |
8c8fa33c | 5552 | goto fail; |
07d6d2b8 AM |
5553 | } |
5554 | } | |
5555 | reloc = &sec->relocation[sec->reloc_count]; | |
5556 | sec->reloc_count++; | |
5557 | ||
5558 | reloc->howto = bfd_reloc_type_lookup (abfd, reloc_code); | |
5559 | ||
5560 | if (cur_sym != NULL) | |
5561 | { | |
5562 | unsigned int j; | |
06ba6be6 | 5563 | int symlen; |
07d6d2b8 AM |
5564 | asymbol **sym; |
5565 | ||
5566 | /* Linear search. */ | |
06ba6be6 AM |
5567 | if (end - cur_sym < 1) |
5568 | goto bad_rec; | |
07d6d2b8 AM |
5569 | symlen = *cur_sym; |
5570 | cur_sym++; | |
06ba6be6 AM |
5571 | if (end - cur_sym < symlen) |
5572 | goto bad_rec; | |
07d6d2b8 AM |
5573 | sym = NULL; |
5574 | ||
5575 | for (j = 0; j < PRIV (gsd_sym_count); j++) | |
5576 | if (PRIV (syms)[j]->namelen == symlen | |
5577 | && memcmp (PRIV (syms)[j]->name, cur_sym, symlen) == 0) | |
5578 | { | |
5579 | sym = &PRIV (csymbols)[j]; | |
5580 | break; | |
5581 | } | |
5582 | if (sym == NULL) | |
5583 | { | |
38f14ab8 | 5584 | _bfd_error_handler (_("unknown symbol in command %s"), |
4eca0228 | 5585 | _bfd_vms_etir_name (cmd)); |
07d6d2b8 AM |
5586 | reloc->sym_ptr_ptr = NULL; |
5587 | } | |
5588 | else | |
5589 | reloc->sym_ptr_ptr = sym; | |
5590 | } | |
5591 | else if (cur_psidx >= 0) | |
cb06d03a | 5592 | { |
ca4cf9b9 | 5593 | if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count)) |
8c8fa33c | 5594 | goto fail; |
cb06d03a NC |
5595 | reloc->sym_ptr_ptr = |
5596 | PRIV (sections)[cur_psidx]->symbol_ptr_ptr; | |
5597 | } | |
07d6d2b8 AM |
5598 | else |
5599 | reloc->sym_ptr_ptr = NULL; | |
95e34ef7 | 5600 | |
07d6d2b8 AM |
5601 | reloc->address = cur_address; |
5602 | reloc->addend = cur_addend; | |
95e34ef7 | 5603 | |
706704c8 AM |
5604 | if (reloc_code == ALPHA_R_LINKAGE) |
5605 | size = 16; | |
5606 | else | |
5607 | size = bfd_get_reloc_size (reloc->howto); | |
5608 | vaddr += size; | |
07d6d2b8 | 5609 | } |
95e34ef7 | 5610 | |
07d6d2b8 AM |
5611 | cur_addend = 0; |
5612 | prev_cmd = -1; | |
5613 | cur_sym = NULL; | |
5614 | cur_psidx = -1; | |
5615 | } | |
95e34ef7 | 5616 | } |
0a1b45a2 | 5617 | vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n")); |
8c8fa33c | 5618 | PRIV (reloc_done) = 1; |
0a1b45a2 | 5619 | return true; |
8c8fa33c AM |
5620 | |
5621 | fail: | |
5622 | PRIV (reloc_done) = -1; | |
5623 | return false; | |
95e34ef7 TG |
5624 | } |
5625 | ||
5626 | /* Return the number of bytes required to store the relocation | |
5627 | information associated with the given section. */ | |
5628 | ||
5629 | static long | |
5630 | alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section) | |
5631 | { | |
8c8fa33c AM |
5632 | if (!alpha_vms_slurp_relocs (abfd)) |
5633 | return -1; | |
95e34ef7 | 5634 | |
5cfe19e5 | 5635 | return (section->reloc_count + 1L) * sizeof (arelent *); |
95e34ef7 TG |
5636 | } |
5637 | ||
5638 | /* Convert relocations from VMS (external) form into BFD internal | |
5639 | form. Return the number of relocations. */ | |
5640 | ||
5641 | static long | |
5642 | alpha_vms_canonicalize_reloc (bfd *abfd, asection *section, arelent **relptr, | |
07d6d2b8 | 5643 | asymbol **symbols ATTRIBUTE_UNUSED) |
95e34ef7 TG |
5644 | { |
5645 | arelent *tblptr; | |
5646 | int count; | |
5647 | ||
5648 | if (!alpha_vms_slurp_relocs (abfd)) | |
5649 | return -1; | |
5650 | ||
5651 | count = section->reloc_count; | |
5652 | tblptr = section->relocation; | |
5653 | ||
5654 | while (count--) | |
5655 | *relptr++ = tblptr++; | |
5656 | ||
5657 | *relptr = (arelent *) NULL; | |
5658 | return section->reloc_count; | |
5659 | } | |
23186865 JM |
5660 | |
5661 | /* Install a new set of internal relocs. */ | |
5662 | ||
5663 | #define alpha_vms_set_reloc _bfd_generic_set_reloc | |
5664 | ||
95e34ef7 TG |
5665 | \f |
5666 | /* This is just copied from ecoff-alpha, needs to be fixed probably. */ | |
5667 | ||
5668 | /* How to process the various reloc types. */ | |
5669 | ||
5670 | static bfd_reloc_status_type | |
5671 | reloc_nil (bfd * abfd ATTRIBUTE_UNUSED, | |
5672 | arelent *reloc ATTRIBUTE_UNUSED, | |
5673 | asymbol *sym ATTRIBUTE_UNUSED, | |
5674 | void * data ATTRIBUTE_UNUSED, | |
5675 | asection *sec ATTRIBUTE_UNUSED, | |
5676 | bfd *output_bfd ATTRIBUTE_UNUSED, | |
5677 | char **error_message ATTRIBUTE_UNUSED) | |
5678 | { | |
5679 | #if VMS_DEBUG | |
5680 | vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd, output_bfd); | |
5681 | vms_debug (2, "In section %s, symbol %s\n", | |
5682 | sec->name, sym->name); | |
5683 | vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n", | |
5684 | reloc->sym_ptr_ptr[0]->name, | |
5685 | (unsigned long)reloc->address, | |
5686 | (unsigned long)reloc->addend, reloc->howto->name); | |
5687 | vms_debug (2, "data at %p\n", data); | |
5688 | /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */ | |
5689 | #endif | |
5690 | ||
5691 | return bfd_reloc_ok; | |
5692 | } | |
5693 | ||
5694 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
5695 | from smaller values. Start with zero, widen, *then* decrement. */ | |
5696 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
5697 | ||
5698 | static reloc_howto_type alpha_howto_table[] = | |
5699 | { | |
5700 | HOWTO (ALPHA_R_IGNORE, /* Type. */ | |
5701 | 0, /* Rightshift. */ | |
c94cb026 | 5702 | 1, /* Size. */ |
95e34ef7 | 5703 | 8, /* Bitsize. */ |
0a1b45a2 | 5704 | true, /* PC relative. */ |
95e34ef7 TG |
5705 | 0, /* Bitpos. */ |
5706 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5707 | reloc_nil, /* Special_function. */ | |
5708 | "IGNORE", /* Name. */ | |
0a1b45a2 | 5709 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5710 | 0, /* Source mask */ |
5711 | 0, /* Dest mask. */ | |
0a1b45a2 | 5712 | true), /* PC rel offset. */ |
95e34ef7 TG |
5713 | |
5714 | /* A 64 bit reference to a symbol. */ | |
5715 | HOWTO (ALPHA_R_REFQUAD, /* Type. */ | |
5716 | 0, /* Rightshift. */ | |
c94cb026 | 5717 | 8, /* Size. */ |
95e34ef7 | 5718 | 64, /* Bitsize. */ |
0a1b45a2 | 5719 | false, /* PC relative. */ |
95e34ef7 TG |
5720 | 0, /* Bitpos. */ |
5721 | complain_overflow_bitfield, /* Complain_on_overflow. */ | |
5722 | reloc_nil, /* Special_function. */ | |
5723 | "REFQUAD", /* Name. */ | |
0a1b45a2 | 5724 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5725 | MINUS_ONE, /* Source mask. */ |
5726 | MINUS_ONE, /* Dest mask. */ | |
0a1b45a2 | 5727 | false), /* PC rel offset. */ |
95e34ef7 TG |
5728 | |
5729 | /* A 21 bit branch. The native assembler generates these for | |
5730 | branches within the text segment, and also fills in the PC | |
5731 | relative offset in the instruction. */ | |
5732 | HOWTO (ALPHA_R_BRADDR, /* Type. */ | |
5733 | 2, /* Rightshift. */ | |
c94cb026 | 5734 | 4, /* Size. */ |
95e34ef7 | 5735 | 21, /* Bitsize. */ |
0a1b45a2 | 5736 | true, /* PC relative. */ |
95e34ef7 TG |
5737 | 0, /* Bitpos. */ |
5738 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5739 | reloc_nil, /* Special_function. */ | |
5740 | "BRADDR", /* Name. */ | |
0a1b45a2 | 5741 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5742 | 0x1fffff, /* Source mask. */ |
5743 | 0x1fffff, /* Dest mask. */ | |
0a1b45a2 | 5744 | false), /* PC rel offset. */ |
95e34ef7 TG |
5745 | |
5746 | /* A hint for a jump to a register. */ | |
5747 | HOWTO (ALPHA_R_HINT, /* Type. */ | |
5748 | 2, /* Rightshift. */ | |
c94cb026 | 5749 | 2, /* Size. */ |
95e34ef7 | 5750 | 14, /* Bitsize. */ |
0a1b45a2 | 5751 | true, /* PC relative. */ |
95e34ef7 TG |
5752 | 0, /* Bitpos. */ |
5753 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5754 | reloc_nil, /* Special_function. */ | |
5755 | "HINT", /* Name. */ | |
0a1b45a2 | 5756 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5757 | 0x3fff, /* Source mask. */ |
5758 | 0x3fff, /* Dest mask. */ | |
0a1b45a2 | 5759 | false), /* PC rel offset. */ |
95e34ef7 TG |
5760 | |
5761 | /* 16 bit PC relative offset. */ | |
5762 | HOWTO (ALPHA_R_SREL16, /* Type. */ | |
5763 | 0, /* Rightshift. */ | |
c94cb026 | 5764 | 2, /* Size. */ |
95e34ef7 | 5765 | 16, /* Bitsize. */ |
0a1b45a2 | 5766 | true, /* PC relative. */ |
95e34ef7 TG |
5767 | 0, /* Bitpos. */ |
5768 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5769 | reloc_nil, /* Special_function. */ | |
5770 | "SREL16", /* Name. */ | |
0a1b45a2 | 5771 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5772 | 0xffff, /* Source mask. */ |
5773 | 0xffff, /* Dest mask. */ | |
0a1b45a2 | 5774 | false), /* PC rel offset. */ |
95e34ef7 TG |
5775 | |
5776 | /* 32 bit PC relative offset. */ | |
5777 | HOWTO (ALPHA_R_SREL32, /* Type. */ | |
5778 | 0, /* Rightshift. */ | |
c94cb026 | 5779 | 4, /* Size. */ |
95e34ef7 | 5780 | 32, /* Bitsize. */ |
0a1b45a2 | 5781 | true, /* PC relative. */ |
95e34ef7 TG |
5782 | 0, /* Bitpos. */ |
5783 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5784 | reloc_nil, /* Special_function. */ | |
5785 | "SREL32", /* Name. */ | |
0a1b45a2 | 5786 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5787 | 0xffffffff, /* Source mask. */ |
5788 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5789 | false), /* PC rel offset. */ |
95e34ef7 TG |
5790 | |
5791 | /* A 64 bit PC relative offset. */ | |
5792 | HOWTO (ALPHA_R_SREL64, /* Type. */ | |
5793 | 0, /* Rightshift. */ | |
c94cb026 | 5794 | 8, /* Size. */ |
95e34ef7 | 5795 | 64, /* Bitsize. */ |
0a1b45a2 | 5796 | true, /* PC relative. */ |
95e34ef7 TG |
5797 | 0, /* Bitpos. */ |
5798 | complain_overflow_signed, /* Complain_on_overflow. */ | |
5799 | reloc_nil, /* Special_function. */ | |
5800 | "SREL64", /* Name. */ | |
0a1b45a2 | 5801 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5802 | MINUS_ONE, /* Source mask. */ |
5803 | MINUS_ONE, /* Dest mask. */ | |
0a1b45a2 | 5804 | false), /* PC rel offset. */ |
95e34ef7 TG |
5805 | |
5806 | /* Push a value on the reloc evaluation stack. */ | |
5807 | HOWTO (ALPHA_R_OP_PUSH, /* Type. */ | |
5808 | 0, /* Rightshift. */ | |
5d0feb98 | 5809 | 0, /* Size. */ |
95e34ef7 | 5810 | 0, /* Bitsize. */ |
0a1b45a2 | 5811 | false, /* PC relative. */ |
95e34ef7 TG |
5812 | 0, /* Bitpos. */ |
5813 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5814 | reloc_nil, /* Special_function. */ | |
5815 | "OP_PUSH", /* Name. */ | |
0a1b45a2 | 5816 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5817 | 0, /* Source mask. */ |
5818 | 0, /* Dest mask. */ | |
0a1b45a2 | 5819 | false), /* PC rel offset. */ |
95e34ef7 TG |
5820 | |
5821 | /* Store the value from the stack at the given address. Store it in | |
5822 | a bitfield of size r_size starting at bit position r_offset. */ | |
5823 | HOWTO (ALPHA_R_OP_STORE, /* Type. */ | |
5824 | 0, /* Rightshift. */ | |
c94cb026 | 5825 | 8, /* Size. */ |
95e34ef7 | 5826 | 64, /* Bitsize. */ |
0a1b45a2 | 5827 | false, /* PC relative. */ |
95e34ef7 TG |
5828 | 0, /* Bitpos. */ |
5829 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5830 | reloc_nil, /* Special_function. */ | |
5831 | "OP_STORE", /* Name. */ | |
0a1b45a2 | 5832 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5833 | 0, /* Source mask. */ |
5834 | MINUS_ONE, /* Dest mask. */ | |
0a1b45a2 | 5835 | false), /* PC rel offset. */ |
95e34ef7 TG |
5836 | |
5837 | /* Subtract the reloc address from the value on the top of the | |
5838 | relocation stack. */ | |
5839 | HOWTO (ALPHA_R_OP_PSUB, /* Type. */ | |
5840 | 0, /* Rightshift. */ | |
5d0feb98 | 5841 | 0, /* Size. */ |
95e34ef7 | 5842 | 0, /* Bitsize. */ |
0a1b45a2 | 5843 | false, /* PC relative. */ |
95e34ef7 TG |
5844 | 0, /* Bitpos. */ |
5845 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5846 | reloc_nil, /* Special_function. */ | |
5847 | "OP_PSUB", /* Name. */ | |
0a1b45a2 | 5848 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5849 | 0, /* Source mask. */ |
5850 | 0, /* Dest mask. */ | |
0a1b45a2 | 5851 | false), /* PC rel offset. */ |
95e34ef7 TG |
5852 | |
5853 | /* Shift the value on the top of the relocation stack right by the | |
5854 | given value. */ | |
5855 | HOWTO (ALPHA_R_OP_PRSHIFT, /* Type. */ | |
5856 | 0, /* Rightshift. */ | |
5d0feb98 | 5857 | 0, /* Size. */ |
95e34ef7 | 5858 | 0, /* Bitsize. */ |
0a1b45a2 | 5859 | false, /* PC relative. */ |
95e34ef7 TG |
5860 | 0, /* Bitpos. */ |
5861 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5862 | reloc_nil, /* Special_function. */ | |
5863 | "OP_PRSHIFT", /* Name. */ | |
0a1b45a2 | 5864 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5865 | 0, /* Source mask. */ |
5866 | 0, /* Dest mask. */ | |
0a1b45a2 | 5867 | false), /* PC rel offset. */ |
95e34ef7 TG |
5868 | |
5869 | /* Hack. Linkage is done by linker. */ | |
5870 | HOWTO (ALPHA_R_LINKAGE, /* Type. */ | |
5871 | 0, /* Rightshift. */ | |
5d0feb98 | 5872 | 0, /* Size. */ |
706704c8 | 5873 | 0, /* Bitsize. */ |
0a1b45a2 | 5874 | false, /* PC relative. */ |
95e34ef7 TG |
5875 | 0, /* Bitpos. */ |
5876 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5877 | reloc_nil, /* Special_function. */ | |
5878 | "LINKAGE", /* Name. */ | |
0a1b45a2 | 5879 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5880 | 0, /* Source mask. */ |
5881 | 0, /* Dest mask. */ | |
0a1b45a2 | 5882 | false), /* PC rel offset. */ |
95e34ef7 TG |
5883 | |
5884 | /* A 32 bit reference to a symbol. */ | |
5885 | HOWTO (ALPHA_R_REFLONG, /* Type. */ | |
5886 | 0, /* Rightshift. */ | |
c94cb026 | 5887 | 4, /* Size. */ |
95e34ef7 | 5888 | 32, /* Bitsize. */ |
0a1b45a2 | 5889 | false, /* PC relative. */ |
95e34ef7 TG |
5890 | 0, /* Bitpos. */ |
5891 | complain_overflow_bitfield, /* Complain_on_overflow. */ | |
5892 | reloc_nil, /* Special_function. */ | |
5893 | "REFLONG", /* Name. */ | |
0a1b45a2 | 5894 | true, /* Partial_inplace. */ |
95e34ef7 TG |
5895 | 0xffffffff, /* Source mask. */ |
5896 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5897 | false), /* PC rel offset. */ |
95e34ef7 TG |
5898 | |
5899 | /* A 64 bit reference to a procedure, written as 32 bit value. */ | |
5900 | HOWTO (ALPHA_R_CODEADDR, /* Type. */ | |
5901 | 0, /* Rightshift. */ | |
c94cb026 | 5902 | 8, /* Size. */ |
95e34ef7 | 5903 | 64, /* Bitsize. */ |
0a1b45a2 | 5904 | false, /* PC relative. */ |
95e34ef7 TG |
5905 | 0, /* Bitpos. */ |
5906 | complain_overflow_signed,/* Complain_on_overflow. */ | |
5907 | reloc_nil, /* Special_function. */ | |
5908 | "CODEADDR", /* Name. */ | |
0a1b45a2 | 5909 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5910 | 0xffffffff, /* Source mask. */ |
5911 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5912 | false), /* PC rel offset. */ |
95e34ef7 TG |
5913 | |
5914 | HOWTO (ALPHA_R_NOP, /* Type. */ | |
5915 | 0, /* Rightshift. */ | |
c94cb026 | 5916 | 0, /* Size. */ |
95e34ef7 TG |
5917 | 0, /* Bitsize. */ |
5918 | /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH | |
5919 | because the calculations for the 3 relocations are the same. | |
5920 | See B.4.5.2 of the OpenVMS Linker Utility Manual. */ | |
0a1b45a2 | 5921 | true, /* PC relative. */ |
95e34ef7 TG |
5922 | 0, /* Bitpos. */ |
5923 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5924 | reloc_nil, /* Special_function. */ | |
5925 | "NOP", /* Name. */ | |
0a1b45a2 | 5926 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5927 | 0xffffffff, /* Source mask. */ |
5928 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5929 | false), /* PC rel offset. */ |
95e34ef7 TG |
5930 | |
5931 | HOWTO (ALPHA_R_BSR, /* Type. */ | |
5932 | 0, /* Rightshift. */ | |
c94cb026 | 5933 | 0, /* Size. */ |
95e34ef7 | 5934 | 0, /* Bitsize. */ |
0a1b45a2 | 5935 | true, /* PC relative. */ |
95e34ef7 TG |
5936 | 0, /* Bitpos. */ |
5937 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5938 | reloc_nil, /* Special_function. */ | |
5939 | "BSR", /* Name. */ | |
0a1b45a2 | 5940 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5941 | 0xffffffff, /* Source mask. */ |
5942 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5943 | false), /* PC rel offset. */ |
95e34ef7 TG |
5944 | |
5945 | HOWTO (ALPHA_R_LDA, /* Type. */ | |
5946 | 0, /* Rightshift. */ | |
c94cb026 | 5947 | 0, /* Size. */ |
95e34ef7 | 5948 | 0, /* Bitsize. */ |
0a1b45a2 | 5949 | false, /* PC relative. */ |
95e34ef7 TG |
5950 | 0, /* Bitpos. */ |
5951 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5952 | reloc_nil, /* Special_function. */ | |
5953 | "LDA", /* Name. */ | |
0a1b45a2 | 5954 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5955 | 0xffffffff, /* Source mask. */ |
5956 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5957 | false), /* PC rel offset. */ |
95e34ef7 TG |
5958 | |
5959 | HOWTO (ALPHA_R_BOH, /* Type. */ | |
5960 | 0, /* Rightshift. */ | |
c94cb026 | 5961 | 0, /* Size. */ |
95e34ef7 | 5962 | 0, /* Bitsize. */ |
0a1b45a2 | 5963 | true, /* PC relative. */ |
95e34ef7 TG |
5964 | 0, /* Bitpos. */ |
5965 | complain_overflow_dont,/* Complain_on_overflow. */ | |
5966 | reloc_nil, /* Special_function. */ | |
5967 | "BOH", /* Name. */ | |
0a1b45a2 | 5968 | false, /* Partial_inplace. */ |
95e34ef7 TG |
5969 | 0xffffffff, /* Source mask. */ |
5970 | 0xffffffff, /* Dest mask. */ | |
0a1b45a2 | 5971 | false), /* PC rel offset. */ |
95e34ef7 TG |
5972 | }; |
5973 | ||
5974 | /* Return a pointer to a howto structure which, when invoked, will perform | |
5975 | the relocation code on data from the architecture noted. */ | |
5976 | ||
487096bf | 5977 | static reloc_howto_type * |
95e34ef7 | 5978 | alpha_vms_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
07d6d2b8 | 5979 | bfd_reloc_code_real_type code) |
95e34ef7 TG |
5980 | { |
5981 | int alpha_type; | |
5982 | ||
5983 | vms_debug2 ((1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd, code)); | |
5984 | ||
5985 | switch (code) | |
5986 | { | |
5987 | case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break; | |
5988 | case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break; | |
5989 | case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break; | |
5990 | case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break; | |
5991 | case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break; | |
5992 | case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break; | |
5993 | case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break; | |
5994 | case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break; | |
5995 | case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break; | |
5996 | case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break; | |
5997 | case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break; | |
5998 | case BFD_RELOC_ALPHA_NOP: alpha_type = ALPHA_R_NOP; break; | |
5999 | case BFD_RELOC_ALPHA_BSR: alpha_type = ALPHA_R_BSR; break; | |
6000 | case BFD_RELOC_ALPHA_LDA: alpha_type = ALPHA_R_LDA; break; | |
6001 | case BFD_RELOC_ALPHA_BOH: alpha_type = ALPHA_R_BOH; break; | |
6002 | default: | |
695344c0 | 6003 | _bfd_error_handler (_("reloc (%d) is *UNKNOWN*"), code); |
95e34ef7 TG |
6004 | return NULL; |
6005 | } | |
6006 | vms_debug2 ((2, "reloc is %s\n", alpha_howto_table[alpha_type].name)); | |
6007 | return & alpha_howto_table[alpha_type]; | |
6008 | } | |
6009 | ||
6010 | static reloc_howto_type * | |
6011 | alpha_vms_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
07d6d2b8 | 6012 | const char *r_name) |
95e34ef7 TG |
6013 | { |
6014 | unsigned int i; | |
6015 | ||
6016 | for (i = 0; | |
6017 | i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]); | |
6018 | i++) | |
6019 | if (alpha_howto_table[i].name != NULL | |
6020 | && strcasecmp (alpha_howto_table[i].name, r_name) == 0) | |
6021 | return &alpha_howto_table[i]; | |
6022 | ||
6023 | return NULL; | |
6024 | } | |
6025 | \f | |
6026 | static long | |
6027 | alpha_vms_get_synthetic_symtab (bfd *abfd, | |
07d6d2b8 AM |
6028 | long symcount ATTRIBUTE_UNUSED, |
6029 | asymbol **usyms ATTRIBUTE_UNUSED, | |
6030 | long dynsymcount ATTRIBUTE_UNUSED, | |
6031 | asymbol **dynsyms ATTRIBUTE_UNUSED, | |
6032 | asymbol **ret) | |
95e34ef7 TG |
6033 | { |
6034 | asymbol *syms; | |
6035 | unsigned int i; | |
6036 | unsigned int n = 0; | |
6037 | ||
6038 | syms = (asymbol *) bfd_malloc (PRIV (norm_sym_count) * sizeof (asymbol)); | |
6039 | *ret = syms; | |
6040 | if (syms == NULL) | |
6041 | return -1; | |
6042 | ||
6043 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
6044 | { | |
6045 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
6046 | asymbol *sym; | |
6047 | flagword flags; | |
6048 | symvalue value; | |
6049 | asection *sec; | |
6050 | const char *name; | |
6051 | char *sname; | |
6052 | int l; | |
6053 | ||
6054 | name = e->name; | |
6055 | value = 0; | |
6056 | flags = BSF_LOCAL | BSF_SYNTHETIC; | |
6057 | sec = NULL; | |
6058 | ||
6059 | switch (e->typ) | |
07d6d2b8 AM |
6060 | { |
6061 | case EGSD__C_SYM: | |
6062 | case EGSD__C_SYMG: | |
6063 | if ((e->flags & EGSY__V_DEF) && (e->flags & EGSY__V_NORM)) | |
6064 | { | |
6065 | value = e->code_value; | |
6066 | sec = e->code_section; | |
6067 | } | |
6068 | else | |
6069 | continue; | |
6070 | break; | |
6071 | ||
6072 | default: | |
6073 | continue; | |
6074 | } | |
95e34ef7 TG |
6075 | |
6076 | l = strlen (name); | |
6077 | sname = bfd_alloc (abfd, l + 5); | |
6078 | if (sname == NULL) | |
0a1b45a2 | 6079 | return false; |
95e34ef7 TG |
6080 | memcpy (sname, name, l); |
6081 | memcpy (sname + l, "..en", 5); | |
6082 | ||
6083 | sym = &syms[n++]; | |
6084 | sym->name = sname; | |
6085 | sym->section = sec; | |
6086 | sym->flags = flags; | |
6087 | sym->value = value; | |
6088 | sym->udata.p = NULL; | |
6089 | } | |
6090 | ||
6091 | return n; | |
6092 | } | |
6093 | \f | |
6094 | /* Private dump. */ | |
6095 | ||
6096 | static const char * | |
6097 | vms_time_to_str (unsigned char *buf) | |
6098 | { | |
6099 | time_t t = vms_rawtime_to_time_t (buf); | |
6100 | char *res = ctime (&t); | |
6101 | ||
6102 | if (!res) | |
6103 | res = "*invalid time*"; | |
6104 | else | |
6105 | res[24] = 0; | |
6106 | return res; | |
6107 | } | |
6108 | ||
6109 | static void | |
6110 | evax_bfd_print_emh (FILE *file, unsigned char *rec, unsigned int rec_len) | |
6111 | { | |
6112 | struct vms_emh_common *emh = (struct vms_emh_common *)rec; | |
ebf18671 | 6113 | int subtype = -1; |
8bdf0be1 | 6114 | int extra; |
95e34ef7 | 6115 | |
ebf18671 AM |
6116 | if (rec_len >= sizeof (*emh)) |
6117 | subtype = bfd_getl16 (emh->subtyp); | |
95e34ef7 | 6118 | |
695344c0 | 6119 | /* xgettext:c-format */ |
ebf18671 | 6120 | fprintf (file, _(" EMH %d (len=%u): "), subtype, rec_len); |
95e34ef7 | 6121 | |
bc21b167 | 6122 | /* PR 21618: Check for invalid lengths. */ |
ebf18671 | 6123 | if (rec_len < sizeof (*emh)) |
bc21b167 | 6124 | { |
ebf18671 AM |
6125 | fprintf (file, _(" Error: %s min length is %u\n"), |
6126 | "EMH", (unsigned) sizeof (*emh)); | |
bc21b167 NC |
6127 | return; |
6128 | } | |
ebf18671 | 6129 | |
8bdf0be1 NC |
6130 | extra = rec_len - sizeof (struct vms_emh_common); |
6131 | ||
95e34ef7 TG |
6132 | switch (subtype) |
6133 | { | |
6134 | case EMH__C_MHD: | |
6135 | { | |
07d6d2b8 | 6136 | struct vms_emh_mhd *mhd = (struct vms_emh_mhd *) rec; |
98c445c0 AM |
6137 | unsigned char *name; |
6138 | unsigned char *nextname; | |
6139 | unsigned char *maxname; | |
95e34ef7 | 6140 | |
8bdf0be1 NC |
6141 | /* PR 21840: Check for invalid lengths. */ |
6142 | if (rec_len < sizeof (* mhd)) | |
6143 | { | |
ebf18671 AM |
6144 | fprintf (file, _(" Error: %s min length is %u\n"), |
6145 | "EMH_MHD", (unsigned) sizeof (*mhd)); | |
8bdf0be1 NC |
6146 | return; |
6147 | } | |
07d6d2b8 AM |
6148 | fprintf (file, _("Module header\n")); |
6149 | fprintf (file, _(" structure level: %u\n"), mhd->strlvl); | |
6150 | fprintf (file, _(" max record size: %u\n"), | |
6151 | (unsigned) bfd_getl32 (mhd->recsiz)); | |
98c445c0 AM |
6152 | name = (unsigned char *) (mhd + 1); |
6153 | maxname = (unsigned char *) rec + rec_len; | |
8bdf0be1 NC |
6154 | if (name > maxname - 2) |
6155 | { | |
6156 | fprintf (file, _(" Error: The module name is missing\n")); | |
6157 | return; | |
6158 | } | |
6159 | nextname = name + name[0] + 1; | |
6160 | if (nextname >= maxname) | |
6161 | { | |
6162 | fprintf (file, _(" Error: The module name is too long\n")); | |
6163 | return; | |
6164 | } | |
07d6d2b8 AM |
6165 | fprintf (file, _(" module name : %.*s\n"), name[0], name + 1); |
6166 | name = nextname; | |
8bdf0be1 NC |
6167 | if (name > maxname - 2) |
6168 | { | |
6169 | fprintf (file, _(" Error: The module version is missing\n")); | |
6170 | return; | |
6171 | } | |
6172 | nextname = name + name[0] + 1; | |
6173 | if (nextname >= maxname) | |
6174 | { | |
6175 | fprintf (file, _(" Error: The module version is too long\n")); | |
6176 | return; | |
6177 | } | |
07d6d2b8 AM |
6178 | fprintf (file, _(" module version : %.*s\n"), name[0], name + 1); |
6179 | name = nextname; | |
8bdf0be1 NC |
6180 | if ((maxname - name) < 17 && maxname[-1] != 0) |
6181 | fprintf (file, _(" Error: The compile date is truncated\n")); | |
6182 | else | |
6183 | fprintf (file, _(" compile date : %.17s\n"), name); | |
95e34ef7 TG |
6184 | } |
6185 | break; | |
8bdf0be1 | 6186 | |
95e34ef7 | 6187 | case EMH__C_LNM: |
8bdf0be1 NC |
6188 | fprintf (file, _("Language Processor Name\n")); |
6189 | fprintf (file, _(" language name: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 6190 | break; |
8bdf0be1 | 6191 | |
95e34ef7 | 6192 | case EMH__C_SRC: |
8bdf0be1 NC |
6193 | fprintf (file, _("Source Files Header\n")); |
6194 | fprintf (file, _(" file: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 6195 | break; |
8bdf0be1 | 6196 | |
95e34ef7 | 6197 | case EMH__C_TTL: |
8bdf0be1 NC |
6198 | fprintf (file, _("Title Text Header\n")); |
6199 | fprintf (file, _(" title: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 6200 | break; |
8bdf0be1 | 6201 | |
95e34ef7 | 6202 | case EMH__C_CPR: |
8bdf0be1 NC |
6203 | fprintf (file, _("Copyright Header\n")); |
6204 | fprintf (file, _(" copyright: %.*s\n"), extra, (char *)(emh + 1)); | |
95e34ef7 | 6205 | break; |
8bdf0be1 | 6206 | |
95e34ef7 TG |
6207 | default: |
6208 | fprintf (file, _("unhandled emh subtype %u\n"), subtype); | |
6209 | break; | |
6210 | } | |
6211 | } | |
6212 | ||
6213 | static void | |
6214 | evax_bfd_print_eeom (FILE *file, unsigned char *rec, unsigned int rec_len) | |
6215 | { | |
6216 | struct vms_eeom *eeom = (struct vms_eeom *)rec; | |
6217 | ||
6218 | fprintf (file, _(" EEOM (len=%u):\n"), rec_len); | |
bc21b167 NC |
6219 | |
6220 | /* PR 21618: Check for invalid lengths. */ | |
ebf18671 | 6221 | if (rec_len < 10) |
bc21b167 | 6222 | { |
ebf18671 AM |
6223 | fprintf (file, _(" Error: %s min length is %u\n"), |
6224 | "EEOM", 10); | |
bc21b167 NC |
6225 | return; |
6226 | } | |
07d6d2b8 | 6227 | |
95e34ef7 | 6228 | fprintf (file, _(" number of cond linkage pairs: %u\n"), |
07d6d2b8 | 6229 | (unsigned)bfd_getl32 (eeom->total_lps)); |
95e34ef7 | 6230 | fprintf (file, _(" completion code: %u\n"), |
07d6d2b8 | 6231 | (unsigned)bfd_getl16 (eeom->comcod)); |
ebf18671 AM |
6232 | |
6233 | if (rec_len >= sizeof (*eeom)) | |
95e34ef7 TG |
6234 | { |
6235 | fprintf (file, _(" transfer addr flags: 0x%02x\n"), eeom->tfrflg); | |
6236 | fprintf (file, _(" transfer addr psect: %u\n"), | |
07d6d2b8 | 6237 | (unsigned)bfd_getl32 (eeom->psindx)); |
95e34ef7 | 6238 | fprintf (file, _(" transfer address : 0x%08x\n"), |
07d6d2b8 | 6239 | (unsigned)bfd_getl32 (eeom->tfradr)); |
95e34ef7 TG |
6240 | } |
6241 | } | |
6242 | ||
6243 | static void | |
6244 | exav_bfd_print_egsy_flags (unsigned int flags, FILE *file) | |
6245 | { | |
6246 | if (flags & EGSY__V_WEAK) | |
6247 | fputs (_(" WEAK"), file); | |
6248 | if (flags & EGSY__V_DEF) | |
6249 | fputs (_(" DEF"), file); | |
6250 | if (flags & EGSY__V_UNI) | |
6251 | fputs (_(" UNI"), file); | |
6252 | if (flags & EGSY__V_REL) | |
6253 | fputs (_(" REL"), file); | |
6254 | if (flags & EGSY__V_COMM) | |
6255 | fputs (_(" COMM"), file); | |
6256 | if (flags & EGSY__V_VECEP) | |
6257 | fputs (_(" VECEP"), file); | |
6258 | if (flags & EGSY__V_NORM) | |
6259 | fputs (_(" NORM"), file); | |
6260 | if (flags & EGSY__V_QUAD_VAL) | |
6261 | fputs (_(" QVAL"), file); | |
6262 | } | |
6263 | ||
9a1b4480 TG |
6264 | static void |
6265 | evax_bfd_print_egsd_flags (FILE *file, unsigned int flags) | |
6266 | { | |
6267 | if (flags & EGPS__V_PIC) | |
6268 | fputs (_(" PIC"), file); | |
6269 | if (flags & EGPS__V_LIB) | |
6270 | fputs (_(" LIB"), file); | |
6271 | if (flags & EGPS__V_OVR) | |
6272 | fputs (_(" OVR"), file); | |
6273 | if (flags & EGPS__V_REL) | |
6274 | fputs (_(" REL"), file); | |
6275 | if (flags & EGPS__V_GBL) | |
6276 | fputs (_(" GBL"), file); | |
6277 | if (flags & EGPS__V_SHR) | |
6278 | fputs (_(" SHR"), file); | |
6279 | if (flags & EGPS__V_EXE) | |
6280 | fputs (_(" EXE"), file); | |
6281 | if (flags & EGPS__V_RD) | |
6282 | fputs (_(" RD"), file); | |
6283 | if (flags & EGPS__V_WRT) | |
6284 | fputs (_(" WRT"), file); | |
6285 | if (flags & EGPS__V_VEC) | |
6286 | fputs (_(" VEC"), file); | |
6287 | if (flags & EGPS__V_NOMOD) | |
6288 | fputs (_(" NOMOD"), file); | |
6289 | if (flags & EGPS__V_COM) | |
6290 | fputs (_(" COM"), file); | |
6291 | if (flags & EGPS__V_ALLOC_64BIT) | |
6292 | fputs (_(" 64B"), file); | |
6293 | } | |
6294 | ||
95e34ef7 TG |
6295 | static void |
6296 | evax_bfd_print_egsd (FILE *file, unsigned char *rec, unsigned int rec_len) | |
6297 | { | |
6298 | unsigned int off = sizeof (struct vms_egsd); | |
94852430 | 6299 | unsigned int n = 0; |
95e34ef7 TG |
6300 | |
6301 | fprintf (file, _(" EGSD (len=%u):\n"), rec_len); | |
94852430 AM |
6302 | if (rec_len < sizeof (struct vms_egsd) + sizeof (struct vms_egsd_entry)) |
6303 | return; | |
95e34ef7 | 6304 | |
94852430 | 6305 | while (off <= rec_len - sizeof (struct vms_egsd_entry)) |
95e34ef7 TG |
6306 | { |
6307 | struct vms_egsd_entry *e = (struct vms_egsd_entry *)(rec + off); | |
6308 | unsigned int type; | |
6309 | unsigned int len; | |
94852430 | 6310 | unsigned int rest; |
95e34ef7 TG |
6311 | |
6312 | type = (unsigned)bfd_getl16 (e->gsdtyp); | |
6313 | len = (unsigned)bfd_getl16 (e->gsdsiz); | |
6314 | ||
695344c0 | 6315 | /* xgettext:c-format */ |
95e34ef7 | 6316 | fprintf (file, _(" EGSD entry %2u (type: %u, len: %u): "), |
07d6d2b8 | 6317 | n, type, len); |
95e34ef7 TG |
6318 | n++; |
6319 | ||
94852430 | 6320 | if (len < sizeof (struct vms_egsd_entry) || len > rec_len - off) |
bc21b167 | 6321 | { |
94852430 | 6322 | fprintf (file, _(" Erroneous length\n")); |
bc21b167 NC |
6323 | return; |
6324 | } | |
6325 | ||
95e34ef7 | 6326 | switch (type) |
07d6d2b8 AM |
6327 | { |
6328 | case EGSD__C_PSC: | |
94852430 AM |
6329 | if (len >= offsetof (struct vms_egps, name)) |
6330 | { | |
6331 | struct vms_egps *egps = (struct vms_egps *) e; | |
6332 | unsigned int flags = bfd_getl16 (egps->flags); | |
6333 | unsigned int l; | |
6334 | ||
6335 | fprintf (file, _("PSC - Program section definition\n")); | |
6336 | fprintf (file, _(" alignment : 2**%u\n"), egps->align); | |
6337 | fprintf (file, _(" flags : 0x%04x"), flags); | |
6338 | evax_bfd_print_egsd_flags (file, flags); | |
6339 | fputc ('\n', file); | |
6340 | l = bfd_getl32 (egps->alloc); | |
6341 | fprintf (file, _(" alloc (len): %u (0x%08x)\n"), l, l); | |
6342 | rest = len - offsetof (struct vms_egps, name); | |
6343 | fprintf (file, _(" name : %.*s\n"), | |
6344 | egps->namlng > rest ? rest : egps->namlng, | |
6345 | egps->name); | |
6346 | } | |
07d6d2b8 AM |
6347 | break; |
6348 | case EGSD__C_SPSC: | |
94852430 AM |
6349 | if (len >= offsetof (struct vms_esgps, name)) |
6350 | { | |
6351 | struct vms_esgps *esgps = (struct vms_esgps *) e; | |
6352 | unsigned int flags = bfd_getl16 (esgps->flags); | |
6353 | unsigned int l; | |
6354 | ||
6355 | fprintf (file, _("SPSC - Shared Image Program section def\n")); | |
6356 | fprintf (file, _(" alignment : 2**%u\n"), esgps->align); | |
6357 | fprintf (file, _(" flags : 0x%04x"), flags); | |
6358 | evax_bfd_print_egsd_flags (file, flags); | |
6359 | fputc ('\n', file); | |
6360 | l = bfd_getl32 (esgps->alloc); | |
6361 | fprintf (file, _(" alloc (len) : %u (0x%08x)\n"), l, l); | |
6362 | fprintf (file, _(" image offset : 0x%08x\n"), | |
6363 | (unsigned int) bfd_getl32 (esgps->base)); | |
6364 | fprintf (file, _(" symvec offset : 0x%08x\n"), | |
6365 | (unsigned int) bfd_getl32 (esgps->value)); | |
6366 | rest = len - offsetof (struct vms_esgps, name); | |
6367 | fprintf (file, _(" name : %.*s\n"), | |
6368 | esgps->namlng > rest ? rest : esgps->namlng, | |
6369 | esgps->name); | |
6370 | } | |
07d6d2b8 AM |
6371 | break; |
6372 | case EGSD__C_SYM: | |
94852430 AM |
6373 | if (len >= sizeof (struct vms_egsy)) |
6374 | { | |
6375 | struct vms_egsy *egsy = (struct vms_egsy *) e; | |
6376 | unsigned int flags = bfd_getl16 (egsy->flags); | |
07d6d2b8 | 6377 | |
94852430 AM |
6378 | if ((flags & EGSY__V_DEF) != 0 |
6379 | && len >= offsetof (struct vms_esdf, name)) | |
6380 | { | |
6381 | struct vms_esdf *esdf = (struct vms_esdf *) e; | |
6382 | ||
6383 | fprintf (file, _("SYM - Global symbol definition\n")); | |
6384 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6385 | exav_bfd_print_egsy_flags (flags, file); | |
6386 | fputc ('\n', file); | |
6387 | fprintf (file, _(" psect offset: 0x%08x\n"), | |
6388 | (unsigned) bfd_getl32 (esdf->value)); | |
6389 | if (flags & EGSY__V_NORM) | |
6390 | { | |
6391 | fprintf (file, _(" code address: 0x%08x\n"), | |
6392 | (unsigned) bfd_getl32 (esdf->code_address)); | |
6393 | fprintf (file, _(" psect index for entry point : %u\n"), | |
6394 | (unsigned) bfd_getl32 (esdf->ca_psindx)); | |
6395 | } | |
6396 | fprintf (file, _(" psect index : %u\n"), | |
6397 | (unsigned) bfd_getl32 (esdf->psindx)); | |
6398 | rest = len - offsetof (struct vms_esdf, name); | |
6399 | fprintf (file, _(" name : %.*s\n"), | |
6400 | esdf->namlng > rest ? rest : esdf->namlng, | |
6401 | esdf->name); | |
6402 | } | |
6403 | else if (len >= offsetof (struct vms_esrf, name)) | |
6404 | { | |
6405 | struct vms_esrf *esrf = (struct vms_esrf *)e; | |
07d6d2b8 | 6406 | |
94852430 AM |
6407 | fprintf (file, _("SYM - Global symbol reference\n")); |
6408 | rest = len - offsetof (struct vms_esrf, name); | |
6409 | fprintf (file, _(" name : %.*s\n"), | |
6410 | esrf->namlng > rest ? rest : esrf->namlng, | |
6411 | esrf->name); | |
6412 | } | |
6413 | } | |
07d6d2b8 AM |
6414 | break; |
6415 | case EGSD__C_IDC: | |
94852430 AM |
6416 | if (len >= sizeof (struct vms_eidc)) |
6417 | { | |
6418 | struct vms_eidc *eidc = (struct vms_eidc *) e; | |
6419 | unsigned int flags = bfd_getl32 (eidc->flags); | |
6420 | unsigned char *p; | |
6421 | ||
6422 | fprintf (file, _("IDC - Ident Consistency check\n")); | |
6423 | fprintf (file, _(" flags : 0x%08x"), flags); | |
6424 | if (flags & EIDC__V_BINIDENT) | |
6425 | fputs (" BINDENT", file); | |
6426 | fputc ('\n', file); | |
6427 | fprintf (file, _(" id match : %x\n"), | |
6428 | (flags >> EIDC__V_IDMATCH_SH) & EIDC__V_IDMATCH_MASK); | |
6429 | fprintf (file, _(" error severity: %x\n"), | |
6430 | (flags >> EIDC__V_ERRSEV_SH) & EIDC__V_ERRSEV_MASK); | |
6431 | p = eidc->name; | |
6432 | rest = len - (p - (unsigned char *) e); | |
6433 | fprintf (file, _(" entity name : %.*s\n"), | |
6434 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); | |
6435 | if (rest > 1u + p[0]) | |
6436 | { | |
6437 | rest -= 1 + p[0]; | |
6438 | p += 1 + p[0]; | |
6439 | fprintf (file, _(" object name : %.*s\n"), | |
6440 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); | |
6441 | if (rest > 1u + p[0]) | |
6442 | { | |
6443 | rest -= 1 + p[0]; | |
6444 | p += 1 + p[0]; | |
6445 | if (flags & EIDC__V_BINIDENT) | |
6446 | { | |
6447 | if (rest >= 4) | |
6448 | fprintf (file, _(" binary ident : 0x%08x\n"), | |
6449 | (unsigned) bfd_getl32 (p)); | |
6450 | } | |
6451 | else | |
6452 | fprintf (file, _(" ascii ident : %.*s\n"), | |
6453 | p[0] > rest - 1 ? rest - 1 : p[0], p + 1); | |
6454 | } | |
6455 | } | |
6456 | } | |
07d6d2b8 AM |
6457 | break; |
6458 | case EGSD__C_SYMG: | |
94852430 AM |
6459 | if (len >= offsetof (struct vms_egst, name)) |
6460 | { | |
6461 | struct vms_egst *egst = (struct vms_egst *) e; | |
6462 | unsigned int flags = bfd_getl16 (egst->header.flags); | |
6463 | ||
6464 | fprintf (file, _("SYMG - Universal symbol definition\n")); | |
6465 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6466 | exav_bfd_print_egsy_flags (flags, file); | |
6467 | fputc ('\n', file); | |
6468 | fprintf (file, _(" symbol vector offset: 0x%08x\n"), | |
6469 | (unsigned) bfd_getl32 (egst->value)); | |
6470 | fprintf (file, _(" entry point: 0x%08x\n"), | |
6471 | (unsigned) bfd_getl32 (egst->lp_1)); | |
6472 | fprintf (file, _(" proc descr : 0x%08x\n"), | |
6473 | (unsigned) bfd_getl32 (egst->lp_2)); | |
6474 | fprintf (file, _(" psect index: %u\n"), | |
6475 | (unsigned) bfd_getl32 (egst->psindx)); | |
6476 | rest = len - offsetof (struct vms_egst, name); | |
6477 | fprintf (file, _(" name : %.*s\n"), | |
6478 | egst->namlng > rest ? rest : egst->namlng, | |
6479 | egst->name); | |
6480 | } | |
07d6d2b8 AM |
6481 | break; |
6482 | case EGSD__C_SYMV: | |
94852430 AM |
6483 | if (len >= offsetof (struct vms_esdfv, name)) |
6484 | { | |
6485 | struct vms_esdfv *esdfv = (struct vms_esdfv *) e; | |
6486 | unsigned int flags = bfd_getl16 (esdfv->flags); | |
6487 | ||
6488 | fprintf (file, _("SYMV - Vectored symbol definition\n")); | |
6489 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6490 | exav_bfd_print_egsy_flags (flags, file); | |
6491 | fputc ('\n', file); | |
6492 | fprintf (file, _(" vector : 0x%08x\n"), | |
6493 | (unsigned) bfd_getl32 (esdfv->vector)); | |
6494 | fprintf (file, _(" psect offset: %u\n"), | |
6495 | (unsigned) bfd_getl32 (esdfv->value)); | |
6496 | fprintf (file, _(" psect index : %u\n"), | |
6497 | (unsigned) bfd_getl32 (esdfv->psindx)); | |
6498 | rest = len - offsetof (struct vms_esdfv, name); | |
6499 | fprintf (file, _(" name : %.*s\n"), | |
6500 | esdfv->namlng > rest ? rest : esdfv->namlng, | |
6501 | esdfv->name); | |
6502 | } | |
07d6d2b8 AM |
6503 | break; |
6504 | case EGSD__C_SYMM: | |
94852430 AM |
6505 | if (len >= offsetof (struct vms_esdfm, name)) |
6506 | { | |
6507 | struct vms_esdfm *esdfm = (struct vms_esdfm *) e; | |
6508 | unsigned int flags = bfd_getl16 (esdfm->flags); | |
6509 | ||
6510 | fprintf (file, | |
6511 | _("SYMM - Global symbol definition with version\n")); | |
6512 | fprintf (file, _(" flags: 0x%04x"), flags); | |
6513 | exav_bfd_print_egsy_flags (flags, file); | |
6514 | fputc ('\n', file); | |
6515 | fprintf (file, _(" version mask: 0x%08x\n"), | |
6516 | (unsigned)bfd_getl32 (esdfm->version_mask)); | |
6517 | fprintf (file, _(" psect offset: %u\n"), | |
6518 | (unsigned)bfd_getl32 (esdfm->value)); | |
6519 | fprintf (file, _(" psect index : %u\n"), | |
6520 | (unsigned)bfd_getl32 (esdfm->psindx)); | |
6521 | rest = len - offsetof (struct vms_esdfm, name); | |
6522 | fprintf (file, _(" name : %.*s\n"), | |
6523 | esdfm->namlng > rest ? rest : esdfm->namlng, | |
6524 | esdfm->name); | |
6525 | } | |
07d6d2b8 AM |
6526 | break; |
6527 | default: | |
6528 | fprintf (file, _("unhandled egsd entry type %u\n"), type); | |
6529 | break; | |
6530 | } | |
95e34ef7 TG |
6531 | off += len; |
6532 | } | |
6533 | } | |
6534 | ||
6535 | static void | |
6536 | evax_bfd_print_hex (FILE *file, const char *pfx, | |
07d6d2b8 | 6537 | const unsigned char *buf, unsigned int len) |
95e34ef7 TG |
6538 | { |
6539 | unsigned int i; | |
6540 | unsigned int n; | |
6541 | ||
6542 | n = 0; | |
6543 | for (i = 0; i < len; i++) | |
6544 | { | |
6545 | if (n == 0) | |
07d6d2b8 | 6546 | fputs (pfx, file); |
95e34ef7 TG |
6547 | fprintf (file, " %02x", buf[i]); |
6548 | n++; | |
6549 | if (n == 16) | |
07d6d2b8 AM |
6550 | { |
6551 | n = 0; | |
6552 | fputc ('\n', file); | |
6553 | } | |
95e34ef7 TG |
6554 | } |
6555 | if (n != 0) | |
6556 | fputc ('\n', file); | |
6557 | } | |
6558 | ||
6559 | static void | |
94852430 AM |
6560 | evax_bfd_print_etir_stc_ir (FILE *file, const unsigned char *buf, |
6561 | unsigned int len, int is_ps) | |
95e34ef7 | 6562 | { |
94852430 AM |
6563 | if (is_ps ? len < 44 : len < 33) |
6564 | return; | |
6565 | ||
695344c0 | 6566 | /* xgettext:c-format */ |
95e34ef7 | 6567 | fprintf (file, _(" linkage index: %u, replacement insn: 0x%08x\n"), |
07d6d2b8 AM |
6568 | (unsigned)bfd_getl32 (buf), |
6569 | (unsigned)bfd_getl32 (buf + 16)); | |
695344c0 | 6570 | /* xgettext:c-format */ |
95e34ef7 | 6571 | fprintf (file, _(" psect idx 1: %u, offset 1: 0x%08x %08x\n"), |
07d6d2b8 AM |
6572 | (unsigned)bfd_getl32 (buf + 4), |
6573 | (unsigned)bfd_getl32 (buf + 12), | |
6574 | (unsigned)bfd_getl32 (buf + 8)); | |
695344c0 | 6575 | /* xgettext:c-format */ |
95e34ef7 | 6576 | fprintf (file, _(" psect idx 2: %u, offset 2: 0x%08x %08x\n"), |
07d6d2b8 AM |
6577 | (unsigned)bfd_getl32 (buf + 20), |
6578 | (unsigned)bfd_getl32 (buf + 28), | |
6579 | (unsigned)bfd_getl32 (buf + 24)); | |
95e34ef7 | 6580 | if (is_ps) |
695344c0 | 6581 | /* xgettext:c-format */ |
95e34ef7 | 6582 | fprintf (file, _(" psect idx 3: %u, offset 3: 0x%08x %08x\n"), |
07d6d2b8 AM |
6583 | (unsigned)bfd_getl32 (buf + 32), |
6584 | (unsigned)bfd_getl32 (buf + 40), | |
6585 | (unsigned)bfd_getl32 (buf + 36)); | |
95e34ef7 | 6586 | else |
94852430 AM |
6587 | fprintf (file, _(" global name: %.*s\n"), |
6588 | buf[32] > len - 33 ? len - 33 : buf[32], | |
6589 | buf + 33); | |
95e34ef7 TG |
6590 | } |
6591 | ||
6592 | static void | |
6593 | evax_bfd_print_etir (FILE *file, const char *name, | |
07d6d2b8 | 6594 | unsigned char *rec, unsigned int rec_len) |
95e34ef7 | 6595 | { |
94852430 | 6596 | unsigned int off = sizeof (struct vms_eobjrec); |
95e34ef7 | 6597 | |
695344c0 | 6598 | /* xgettext:c-format */ |
94852430 AM |
6599 | fprintf (file, _(" %s (len=%u):\n"), name, (unsigned) rec_len); |
6600 | if (rec_len < sizeof (struct vms_eobjrec) + sizeof (struct vms_etir)) | |
6601 | return; | |
95e34ef7 | 6602 | |
94852430 | 6603 | while (off <= rec_len - sizeof (struct vms_etir)) |
95e34ef7 TG |
6604 | { |
6605 | struct vms_etir *etir = (struct vms_etir *)(rec + off); | |
6606 | unsigned char *buf; | |
6607 | unsigned int type; | |
6608 | unsigned int size; | |
94852430 | 6609 | unsigned int rest; |
95e34ef7 TG |
6610 | |
6611 | type = bfd_getl16 (etir->rectyp); | |
6612 | size = bfd_getl16 (etir->size); | |
6613 | buf = rec + off + sizeof (struct vms_etir); | |
6614 | ||
94852430 | 6615 | if (size < sizeof (struct vms_etir) || size > rec_len - off) |
bc21b167 | 6616 | { |
94852430 | 6617 | fprintf (file, _(" Erroneous length\n")); |
bc21b167 NC |
6618 | return; |
6619 | } | |
6620 | ||
695344c0 | 6621 | /* xgettext:c-format */ |
94852430 AM |
6622 | fprintf (file, _(" (type: %3u, size: %3u): "), type, size); |
6623 | rest = size - sizeof (struct vms_etir); | |
95e34ef7 | 6624 | switch (type) |
07d6d2b8 AM |
6625 | { |
6626 | case ETIR__C_STA_GBL: | |
94852430 AM |
6627 | if (rest >= 1) |
6628 | fprintf (file, _("STA_GBL (stack global) %.*s\n"), | |
6629 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); | |
07d6d2b8 AM |
6630 | break; |
6631 | case ETIR__C_STA_LW: | |
94852430 AM |
6632 | fprintf (file, _("STA_LW (stack longword)")); |
6633 | if (rest >= 4) | |
6634 | fprintf (file, " 0x%08x\n", | |
6635 | (unsigned) bfd_getl32 (buf)); | |
07d6d2b8 AM |
6636 | break; |
6637 | case ETIR__C_STA_QW: | |
94852430 AM |
6638 | fprintf (file, _("STA_QW (stack quadword)")); |
6639 | if (rest >= 8) | |
6640 | fprintf (file, " 0x%08x %08x\n", | |
6641 | (unsigned) bfd_getl32 (buf + 4), | |
6642 | (unsigned) bfd_getl32 (buf + 0)); | |
07d6d2b8 AM |
6643 | break; |
6644 | case ETIR__C_STA_PQ: | |
6645 | fprintf (file, _("STA_PQ (stack psect base + offset)\n")); | |
94852430 AM |
6646 | if (rest >= 12) |
6647 | /* xgettext:c-format */ | |
6648 | fprintf (file, _(" psect: %u, offset: 0x%08x %08x\n"), | |
6649 | (unsigned) bfd_getl32 (buf + 0), | |
6650 | (unsigned) bfd_getl32 (buf + 8), | |
6651 | (unsigned) bfd_getl32 (buf + 4)); | |
07d6d2b8 AM |
6652 | break; |
6653 | case ETIR__C_STA_LI: | |
6654 | fprintf (file, _("STA_LI (stack literal)\n")); | |
6655 | break; | |
6656 | case ETIR__C_STA_MOD: | |
6657 | fprintf (file, _("STA_MOD (stack module)\n")); | |
6658 | break; | |
6659 | case ETIR__C_STA_CKARG: | |
6660 | fprintf (file, _("STA_CKARG (compare procedure argument)\n")); | |
6661 | break; | |
6662 | ||
6663 | case ETIR__C_STO_B: | |
6664 | fprintf (file, _("STO_B (store byte)\n")); | |
6665 | break; | |
6666 | case ETIR__C_STO_W: | |
6667 | fprintf (file, _("STO_W (store word)\n")); | |
6668 | break; | |
6669 | case ETIR__C_STO_LW: | |
6670 | fprintf (file, _("STO_LW (store longword)\n")); | |
6671 | break; | |
6672 | case ETIR__C_STO_QW: | |
6673 | fprintf (file, _("STO_QW (store quadword)\n")); | |
6674 | break; | |
6675 | case ETIR__C_STO_IMMR: | |
94852430 AM |
6676 | if (rest >= 4) |
6677 | { | |
6678 | unsigned int rpt = bfd_getl32 (buf); | |
6679 | fprintf (file, | |
6680 | _("STO_IMMR (store immediate repeat) %u bytes\n"), | |
6681 | rpt); | |
6682 | if (rpt > rest - 4) | |
6683 | rpt = rest - 4; | |
6684 | evax_bfd_print_hex (file, " ", buf + 4, rpt); | |
6685 | } | |
07d6d2b8 AM |
6686 | break; |
6687 | case ETIR__C_STO_GBL: | |
94852430 AM |
6688 | if (rest >= 1) |
6689 | fprintf (file, _("STO_GBL (store global) %.*s\n"), | |
6690 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); | |
07d6d2b8 AM |
6691 | break; |
6692 | case ETIR__C_STO_CA: | |
94852430 AM |
6693 | if (rest >= 1) |
6694 | fprintf (file, _("STO_CA (store code address) %.*s\n"), | |
6695 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); | |
07d6d2b8 AM |
6696 | break; |
6697 | case ETIR__C_STO_RB: | |
6698 | fprintf (file, _("STO_RB (store relative branch)\n")); | |
6699 | break; | |
6700 | case ETIR__C_STO_AB: | |
6701 | fprintf (file, _("STO_AB (store absolute branch)\n")); | |
6702 | break; | |
6703 | case ETIR__C_STO_OFF: | |
6704 | fprintf (file, _("STO_OFF (store offset to psect)\n")); | |
6705 | break; | |
6706 | case ETIR__C_STO_IMM: | |
94852430 AM |
6707 | if (rest >= 4) |
6708 | { | |
6709 | unsigned int rpt = bfd_getl32 (buf); | |
6710 | fprintf (file, | |
6711 | _("STO_IMM (store immediate) %u bytes\n"), | |
6712 | rpt); | |
6713 | if (rpt > rest - 4) | |
6714 | rpt = rest - 4; | |
6715 | evax_bfd_print_hex (file, " ", buf + 4, rpt); | |
6716 | } | |
07d6d2b8 AM |
6717 | break; |
6718 | case ETIR__C_STO_GBL_LW: | |
94852430 AM |
6719 | if (rest >= 1) |
6720 | fprintf (file, _("STO_GBL_LW (store global longword) %.*s\n"), | |
6721 | buf[0] > rest - 1 ? rest - 1 : buf[0], buf + 1); | |
07d6d2b8 AM |
6722 | break; |
6723 | case ETIR__C_STO_LP_PSB: | |
6724 | fprintf (file, _("STO_OFF (store LP with procedure signature)\n")); | |
6725 | break; | |
6726 | case ETIR__C_STO_HINT_GBL: | |
6727 | fprintf (file, _("STO_BR_GBL (store branch global) *todo*\n")); | |
6728 | break; | |
6729 | case ETIR__C_STO_HINT_PS: | |
6730 | fprintf (file, _("STO_BR_PS (store branch psect + offset) *todo*\n")); | |
6731 | break; | |
6732 | ||
6733 | case ETIR__C_OPR_NOP: | |
6734 | fprintf (file, _("OPR_NOP (no-operation)\n")); | |
6735 | break; | |
6736 | case ETIR__C_OPR_ADD: | |
6737 | fprintf (file, _("OPR_ADD (add)\n")); | |
6738 | break; | |
6739 | case ETIR__C_OPR_SUB: | |
6740 | fprintf (file, _("OPR_SUB (subtract)\n")); | |
6741 | break; | |
6742 | case ETIR__C_OPR_MUL: | |
6743 | fprintf (file, _("OPR_MUL (multiply)\n")); | |
6744 | break; | |
6745 | case ETIR__C_OPR_DIV: | |
6746 | fprintf (file, _("OPR_DIV (divide)\n")); | |
6747 | break; | |
6748 | case ETIR__C_OPR_AND: | |
6749 | fprintf (file, _("OPR_AND (logical and)\n")); | |
6750 | break; | |
6751 | case ETIR__C_OPR_IOR: | |
6752 | fprintf (file, _("OPR_IOR (logical inclusive or)\n")); | |
6753 | break; | |
6754 | case ETIR__C_OPR_EOR: | |
6755 | fprintf (file, _("OPR_EOR (logical exclusive or)\n")); | |
6756 | break; | |
6757 | case ETIR__C_OPR_NEG: | |
6758 | fprintf (file, _("OPR_NEG (negate)\n")); | |
6759 | break; | |
6760 | case ETIR__C_OPR_COM: | |
6761 | fprintf (file, _("OPR_COM (complement)\n")); | |
6762 | break; | |
6763 | case ETIR__C_OPR_INSV: | |
6764 | fprintf (file, _("OPR_INSV (insert field)\n")); | |
6765 | break; | |
6766 | case ETIR__C_OPR_ASH: | |
6767 | fprintf (file, _("OPR_ASH (arithmetic shift)\n")); | |
6768 | break; | |
6769 | case ETIR__C_OPR_USH: | |
6770 | fprintf (file, _("OPR_USH (unsigned shift)\n")); | |
6771 | break; | |
6772 | case ETIR__C_OPR_ROT: | |
6773 | fprintf (file, _("OPR_ROT (rotate)\n")); | |
6774 | break; | |
6775 | case ETIR__C_OPR_SEL: | |
6776 | fprintf (file, _("OPR_SEL (select)\n")); | |
6777 | break; | |
6778 | case ETIR__C_OPR_REDEF: | |
6779 | fprintf (file, _("OPR_REDEF (redefine symbol to curr location)\n")); | |
6780 | break; | |
6781 | case ETIR__C_OPR_DFLIT: | |
6782 | fprintf (file, _("OPR_REDEF (define a literal)\n")); | |
6783 | break; | |
6784 | ||
6785 | case ETIR__C_STC_LP: | |
6786 | fprintf (file, _("STC_LP (store cond linkage pair)\n")); | |
6787 | break; | |
6788 | case ETIR__C_STC_LP_PSB: | |
6789 | fprintf (file, | |
6790 | _("STC_LP_PSB (store cond linkage pair + signature)\n")); | |
94852430 AM |
6791 | if (rest >= 5) |
6792 | { | |
6793 | /* xgettext:c-format */ | |
6794 | fprintf (file, _(" linkage index: %u, procedure: %.*s\n"), | |
6795 | (unsigned) bfd_getl32 (buf), | |
6796 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); | |
6797 | if (rest > 4 + 1u + buf[4]) | |
6798 | { | |
6799 | rest -= 4 + 1 + buf[4]; | |
6800 | buf += 4 + 1 + buf[4]; | |
6801 | fprintf (file, _(" signature: %.*s\n"), | |
6802 | buf[0] > rest - 1 ? rest - 1: buf[0], buf + 1); | |
6803 | } | |
6804 | } | |
07d6d2b8 AM |
6805 | break; |
6806 | case ETIR__C_STC_GBL: | |
6807 | fprintf (file, _("STC_GBL (store cond global)\n")); | |
94852430 AM |
6808 | if (rest >= 5) |
6809 | /* xgettext:c-format */ | |
6810 | fprintf (file, _(" linkage index: %u, global: %.*s\n"), | |
6811 | (unsigned) bfd_getl32 (buf), | |
6812 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); | |
07d6d2b8 AM |
6813 | break; |
6814 | case ETIR__C_STC_GCA: | |
6815 | fprintf (file, _("STC_GCA (store cond code address)\n")); | |
94852430 AM |
6816 | if (rest >= 5) |
6817 | /* xgettext:c-format */ | |
6818 | fprintf (file, _(" linkage index: %u, procedure name: %.*s\n"), | |
6819 | (unsigned) bfd_getl32 (buf), | |
6820 | buf[4] > rest - 5 ? rest - 5 : buf[4], buf + 5); | |
07d6d2b8 AM |
6821 | break; |
6822 | case ETIR__C_STC_PS: | |
6823 | fprintf (file, _("STC_PS (store cond psect + offset)\n")); | |
94852430 AM |
6824 | if (rest >= 16) |
6825 | fprintf (file, | |
6826 | /* xgettext:c-format */ | |
6827 | _(" linkage index: %u, psect: %u, offset: 0x%08x %08x\n"), | |
6828 | (unsigned)bfd_getl32 (buf), | |
6829 | (unsigned)bfd_getl32 (buf + 4), | |
6830 | (unsigned)bfd_getl32 (buf + 12), | |
6831 | (unsigned)bfd_getl32 (buf + 8)); | |
07d6d2b8 AM |
6832 | break; |
6833 | case ETIR__C_STC_NOP_GBL: | |
6834 | fprintf (file, _("STC_NOP_GBL (store cond NOP at global addr)\n")); | |
94852430 | 6835 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
07d6d2b8 AM |
6836 | break; |
6837 | case ETIR__C_STC_NOP_PS: | |
6838 | fprintf (file, _("STC_NOP_PS (store cond NOP at psect + offset)\n")); | |
94852430 | 6839 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
07d6d2b8 AM |
6840 | break; |
6841 | case ETIR__C_STC_BSR_GBL: | |
6842 | fprintf (file, _("STC_BSR_GBL (store cond BSR at global addr)\n")); | |
94852430 | 6843 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
07d6d2b8 AM |
6844 | break; |
6845 | case ETIR__C_STC_BSR_PS: | |
6846 | fprintf (file, _("STC_BSR_PS (store cond BSR at psect + offset)\n")); | |
94852430 | 6847 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
07d6d2b8 AM |
6848 | break; |
6849 | case ETIR__C_STC_LDA_GBL: | |
6850 | fprintf (file, _("STC_LDA_GBL (store cond LDA at global addr)\n")); | |
94852430 | 6851 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
07d6d2b8 AM |
6852 | break; |
6853 | case ETIR__C_STC_LDA_PS: | |
6854 | fprintf (file, _("STC_LDA_PS (store cond LDA at psect + offset)\n")); | |
94852430 | 6855 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
07d6d2b8 AM |
6856 | break; |
6857 | case ETIR__C_STC_BOH_GBL: | |
6858 | fprintf (file, _("STC_BOH_GBL (store cond BOH at global addr)\n")); | |
94852430 | 6859 | evax_bfd_print_etir_stc_ir (file, buf, rest, 0); |
07d6d2b8 AM |
6860 | break; |
6861 | case ETIR__C_STC_BOH_PS: | |
6862 | fprintf (file, _("STC_BOH_PS (store cond BOH at psect + offset)\n")); | |
94852430 | 6863 | evax_bfd_print_etir_stc_ir (file, buf, rest, 1); |
07d6d2b8 AM |
6864 | break; |
6865 | case ETIR__C_STC_NBH_GBL: | |
6866 | fprintf (file, | |
6867 | _("STC_NBH_GBL (store cond or hint at global addr)\n")); | |
6868 | break; | |
6869 | case ETIR__C_STC_NBH_PS: | |
6870 | fprintf (file, | |
6871 | _("STC_NBH_PS (store cond or hint at psect + offset)\n")); | |
6872 | break; | |
6873 | ||
6874 | case ETIR__C_CTL_SETRB: | |
6875 | fprintf (file, _("CTL_SETRB (set relocation base)\n")); | |
07d6d2b8 AM |
6876 | break; |
6877 | case ETIR__C_CTL_AUGRB: | |
94852430 AM |
6878 | if (rest >= 4) |
6879 | { | |
6880 | unsigned int val = bfd_getl32 (buf); | |
6881 | fprintf (file, _("CTL_AUGRB (augment relocation base) %u\n"), | |
6882 | val); | |
6883 | } | |
07d6d2b8 AM |
6884 | break; |
6885 | case ETIR__C_CTL_DFLOC: | |
6886 | fprintf (file, _("CTL_DFLOC (define location)\n")); | |
6887 | break; | |
6888 | case ETIR__C_CTL_STLOC: | |
6889 | fprintf (file, _("CTL_STLOC (set location)\n")); | |
6890 | break; | |
6891 | case ETIR__C_CTL_STKDL: | |
6892 | fprintf (file, _("CTL_STKDL (stack defined location)\n")); | |
6893 | break; | |
6894 | default: | |
6895 | fprintf (file, _("*unhandled*\n")); | |
6896 | break; | |
6897 | } | |
95e34ef7 TG |
6898 | off += size; |
6899 | } | |
6900 | } | |
6901 | ||
6902 | static void | |
6903 | evax_bfd_print_eobj (struct bfd *abfd, FILE *file) | |
6904 | { | |
0a1b45a2 | 6905 | bool is_first = true; |
0ea8d78b | 6906 | bool has_records = true; |
95e34ef7 TG |
6907 | |
6908 | while (1) | |
6909 | { | |
6910 | unsigned int rec_len; | |
6911 | unsigned int pad_len; | |
6912 | unsigned char *rec; | |
6913 | unsigned int hdr_size; | |
6914 | unsigned int type; | |
0ea8d78b | 6915 | unsigned char buf[6]; |
95e34ef7 | 6916 | |
0ea8d78b | 6917 | hdr_size = has_records ? 6 : 4; |
226f9f4f | 6918 | if (bfd_read (buf, hdr_size, abfd) != hdr_size) |
07d6d2b8 | 6919 | { |
0ea8d78b AM |
6920 | fprintf (file, _("cannot read GST record header\n")); |
6921 | return; | |
07d6d2b8 | 6922 | } |
0ea8d78b AM |
6923 | |
6924 | type = bfd_getl16 (buf); | |
6925 | rec_len = bfd_getl16 (buf + 2); | |
6926 | pad_len = rec_len; | |
6927 | if (has_records) | |
07d6d2b8 | 6928 | { |
0ea8d78b | 6929 | unsigned int rec_len2 = bfd_getl16 (buf + 4); |
07d6d2b8 | 6930 | |
0ea8d78b | 6931 | if (is_first) |
07d6d2b8 | 6932 | { |
0ea8d78b AM |
6933 | is_first = false; |
6934 | if (type == rec_len2 && rec_len == EOBJ__C_EMH) | |
6935 | /* Matched a VMS record EMH. */ | |
6936 | ; | |
6937 | else | |
07d6d2b8 | 6938 | { |
0ea8d78b AM |
6939 | has_records = false; |
6940 | if (type != EOBJ__C_EMH) | |
6941 | { | |
6942 | /* Ill-formed. */ | |
6943 | fprintf (file, _("cannot find EMH in first GST record\n")); | |
6944 | return; | |
6945 | } | |
07d6d2b8 | 6946 | } |
07d6d2b8 AM |
6947 | } |
6948 | ||
07d6d2b8 | 6949 | if (has_records) |
07d6d2b8 | 6950 | { |
0ea8d78b AM |
6951 | /* VMS record format is: record-size, type, record-size. |
6952 | See maybe_adjust_record_pointer_for_object comment. */ | |
6953 | if (type == rec_len2) | |
6954 | { | |
6955 | type = rec_len; | |
6956 | rec_len = rec_len2; | |
6957 | } | |
6958 | else | |
6959 | rec_len = 0; | |
6960 | pad_len = (rec_len + 1) & ~1U; | |
6961 | hdr_size = 4; | |
07d6d2b8 AM |
6962 | } |
6963 | } | |
95e34ef7 | 6964 | |
0ea8d78b AM |
6965 | if (rec_len < hdr_size) |
6966 | { | |
6967 | fprintf (file, _("corrupted GST\n")); | |
6968 | return; | |
6969 | } | |
6970 | ||
6971 | rec = bfd_malloc (pad_len); | |
6972 | if (rec == NULL) | |
6973 | return; | |
6974 | ||
6975 | memcpy (rec, buf + (has_records ? 2 : 0), hdr_size); | |
6976 | ||
226f9f4f | 6977 | if (bfd_read (rec + hdr_size, pad_len - hdr_size, abfd) |
07d6d2b8 AM |
6978 | != pad_len - hdr_size) |
6979 | { | |
6980 | fprintf (file, _("cannot read GST record\n")); | |
ad4ee59e | 6981 | free (rec); |
07d6d2b8 AM |
6982 | return; |
6983 | } | |
95e34ef7 | 6984 | |
95e34ef7 | 6985 | switch (type) |
07d6d2b8 AM |
6986 | { |
6987 | case EOBJ__C_EMH: | |
6988 | evax_bfd_print_emh (file, rec, rec_len); | |
6989 | break; | |
6990 | case EOBJ__C_EGSD: | |
6991 | evax_bfd_print_egsd (file, rec, rec_len); | |
6992 | break; | |
6993 | case EOBJ__C_EEOM: | |
6994 | evax_bfd_print_eeom (file, rec, rec_len); | |
6995 | free (rec); | |
6996 | return; | |
07d6d2b8 AM |
6997 | case EOBJ__C_ETIR: |
6998 | evax_bfd_print_etir (file, "ETIR", rec, rec_len); | |
6999 | break; | |
7000 | case EOBJ__C_EDBG: | |
7001 | evax_bfd_print_etir (file, "EDBG", rec, rec_len); | |
7002 | break; | |
7003 | case EOBJ__C_ETBT: | |
7004 | evax_bfd_print_etir (file, "ETBT", rec, rec_len); | |
7005 | break; | |
7006 | default: | |
7007 | fprintf (file, _(" unhandled EOBJ record type %u\n"), type); | |
7008 | break; | |
7009 | } | |
95e34ef7 TG |
7010 | free (rec); |
7011 | } | |
7012 | } | |
7013 | ||
7014 | static void | |
b920bc37 AM |
7015 | evax_bfd_print_relocation_records (FILE *file, const unsigned char *buf, |
7016 | size_t buf_size, size_t off, | |
07d6d2b8 | 7017 | unsigned int stride) |
95e34ef7 | 7018 | { |
b920bc37 | 7019 | while (off <= buf_size - 8) |
95e34ef7 TG |
7020 | { |
7021 | unsigned int base; | |
7022 | unsigned int count; | |
7023 | unsigned int j; | |
7024 | ||
b920bc37 | 7025 | count = bfd_getl32 (buf + off + 0); |
95e34ef7 TG |
7026 | |
7027 | if (count == 0) | |
07d6d2b8 | 7028 | break; |
b920bc37 | 7029 | base = bfd_getl32 (buf + off + 4); |
95e34ef7 | 7030 | |
695344c0 | 7031 | /* xgettext:c-format */ |
95e34ef7 | 7032 | fprintf (file, _(" bitcount: %u, base addr: 0x%08x\n"), |
07d6d2b8 | 7033 | count, base); |
95e34ef7 | 7034 | |
b920bc37 AM |
7035 | off += 8; |
7036 | for (j = 0; count > 0 && off <= buf_size - 4; j += 4, count -= 32) | |
07d6d2b8 AM |
7037 | { |
7038 | unsigned int k; | |
7039 | unsigned int n = 0; | |
7040 | unsigned int val; | |
95e34ef7 | 7041 | |
b920bc37 AM |
7042 | val = bfd_getl32 (buf + off); |
7043 | off += 4; | |
95e34ef7 | 7044 | |
695344c0 | 7045 | /* xgettext:c-format */ |
07d6d2b8 AM |
7046 | fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count); |
7047 | ||
7048 | for (k = 0; k < 32; k++) | |
401e101e | 7049 | if (val & (1u << k)) |
07d6d2b8 AM |
7050 | { |
7051 | if (n == 0) | |
7052 | fputs (" ", file); | |
7053 | fprintf (file, _(" %08x"), base + (j * 8 + k) * stride); | |
7054 | n++; | |
7055 | if (n == 8) | |
7056 | { | |
7057 | fputs ("\n", file); | |
7058 | n = 0; | |
7059 | } | |
7060 | } | |
7061 | if (n) | |
7062 | fputs ("\n", file); | |
7063 | } | |
95e34ef7 TG |
7064 | } |
7065 | } | |
7066 | ||
7067 | static void | |
b920bc37 AM |
7068 | evax_bfd_print_address_fixups (FILE *file, const unsigned char *buf, |
7069 | size_t buf_size, size_t off) | |
95e34ef7 | 7070 | { |
b920bc37 | 7071 | while (off <= buf_size - 8) |
95e34ef7 TG |
7072 | { |
7073 | unsigned int j; | |
7074 | unsigned int count; | |
7075 | ||
b920bc37 | 7076 | count = bfd_getl32 (buf + off + 0); |
95e34ef7 | 7077 | if (count == 0) |
07d6d2b8 | 7078 | return; |
695344c0 | 7079 | /* xgettext:c-format */ |
95e34ef7 | 7080 | fprintf (file, _(" image %u (%u entries)\n"), |
b920bc37 AM |
7081 | (unsigned) bfd_getl32 (buf + off + 4), count); |
7082 | off += 8; | |
7083 | for (j = 0; j < count && off <= buf_size - 8; j++) | |
07d6d2b8 | 7084 | { |
695344c0 | 7085 | /* xgettext:c-format */ |
07d6d2b8 | 7086 | fprintf (file, _(" offset: 0x%08x, val: 0x%08x\n"), |
b920bc37 AM |
7087 | (unsigned) bfd_getl32 (buf + off + 0), |
7088 | (unsigned) bfd_getl32 (buf + off + 4)); | |
7089 | off += 8; | |
07d6d2b8 | 7090 | } |
95e34ef7 TG |
7091 | } |
7092 | } | |
7093 | ||
7094 | static void | |
b920bc37 AM |
7095 | evax_bfd_print_reference_fixups (FILE *file, const unsigned char *buf, |
7096 | size_t buf_size, size_t off) | |
95e34ef7 TG |
7097 | { |
7098 | unsigned int count; | |
7099 | ||
b920bc37 | 7100 | while (off <= buf_size - 8) |
95e34ef7 TG |
7101 | { |
7102 | unsigned int j; | |
7103 | unsigned int n = 0; | |
7104 | ||
b920bc37 | 7105 | count = bfd_getl32 (buf + off + 0); |
95e34ef7 | 7106 | if (count == 0) |
07d6d2b8 | 7107 | break; |
695344c0 | 7108 | /* xgettext:c-format */ |
95e34ef7 | 7109 | fprintf (file, _(" image %u (%u entries), offsets:\n"), |
b920bc37 AM |
7110 | (unsigned) bfd_getl32 (buf + off + 4), count); |
7111 | off += 8; | |
7112 | for (j = 0; j < count && off <= buf_size - 4; j++) | |
07d6d2b8 AM |
7113 | { |
7114 | if (n == 0) | |
7115 | fputs (" ", file); | |
b920bc37 | 7116 | fprintf (file, _(" 0x%08x"), (unsigned) bfd_getl32 (buf + off)); |
07d6d2b8 AM |
7117 | n++; |
7118 | if (n == 7) | |
7119 | { | |
7120 | fputs ("\n", file); | |
7121 | n = 0; | |
7122 | } | |
b920bc37 | 7123 | off += 4; |
07d6d2b8 | 7124 | } |
95e34ef7 | 7125 | if (n) |
07d6d2b8 | 7126 | fputs ("\n", file); |
95e34ef7 TG |
7127 | } |
7128 | } | |
7129 | ||
7130 | static void | |
7131 | evax_bfd_print_indent (int indent, FILE *file) | |
7132 | { | |
7133 | for (; indent; indent--) | |
7134 | fputc (' ', file); | |
7135 | } | |
7136 | ||
7137 | static const char * | |
7138 | evax_bfd_get_dsc_name (unsigned int v) | |
7139 | { | |
7140 | switch (v) | |
7141 | { | |
7142 | case DSC__K_DTYPE_Z: | |
7143 | return "Z (Unspecified)"; | |
7144 | case DSC__K_DTYPE_V: | |
7145 | return "V (Bit)"; | |
7146 | case DSC__K_DTYPE_BU: | |
7147 | return "BU (Byte logical)"; | |
7148 | case DSC__K_DTYPE_WU: | |
7149 | return "WU (Word logical)"; | |
7150 | case DSC__K_DTYPE_LU: | |
7151 | return "LU (Longword logical)"; | |
7152 | case DSC__K_DTYPE_QU: | |
7153 | return "QU (Quadword logical)"; | |
7154 | case DSC__K_DTYPE_B: | |
7155 | return "B (Byte integer)"; | |
7156 | case DSC__K_DTYPE_W: | |
7157 | return "W (Word integer)"; | |
7158 | case DSC__K_DTYPE_L: | |
7159 | return "L (Longword integer)"; | |
7160 | case DSC__K_DTYPE_Q: | |
7161 | return "Q (Quadword integer)"; | |
7162 | case DSC__K_DTYPE_F: | |
7163 | return "F (Single-precision floating)"; | |
7164 | case DSC__K_DTYPE_D: | |
7165 | return "D (Double-precision floating)"; | |
7166 | case DSC__K_DTYPE_FC: | |
7167 | return "FC (Complex)"; | |
7168 | case DSC__K_DTYPE_DC: | |
7169 | return "DC (Double-precision Complex)"; | |
7170 | case DSC__K_DTYPE_T: | |
7171 | return "T (ASCII text string)"; | |
7172 | case DSC__K_DTYPE_NU: | |
7173 | return "NU (Numeric string, unsigned)"; | |
7174 | case DSC__K_DTYPE_NL: | |
7175 | return "NL (Numeric string, left separate sign)"; | |
7176 | case DSC__K_DTYPE_NLO: | |
7177 | return "NLO (Numeric string, left overpunched sign)"; | |
7178 | case DSC__K_DTYPE_NR: | |
7179 | return "NR (Numeric string, right separate sign)"; | |
7180 | case DSC__K_DTYPE_NRO: | |
7181 | return "NRO (Numeric string, right overpunched sig)"; | |
7182 | case DSC__K_DTYPE_NZ: | |
7183 | return "NZ (Numeric string, zoned sign)"; | |
7184 | case DSC__K_DTYPE_P: | |
7185 | return "P (Packed decimal string)"; | |
7186 | case DSC__K_DTYPE_ZI: | |
7187 | return "ZI (Sequence of instructions)"; | |
7188 | case DSC__K_DTYPE_ZEM: | |
7189 | return "ZEM (Procedure entry mask)"; | |
7190 | case DSC__K_DTYPE_DSC: | |
7191 | return "DSC (Descriptor, used for arrays of dyn strings)"; | |
7192 | case DSC__K_DTYPE_OU: | |
7193 | return "OU (Octaword logical)"; | |
7194 | case DSC__K_DTYPE_O: | |
7195 | return "O (Octaword integer)"; | |
7196 | case DSC__K_DTYPE_G: | |
7197 | return "G (Double precision G floating, 64 bit)"; | |
7198 | case DSC__K_DTYPE_H: | |
7199 | return "H (Quadruple precision floating, 128 bit)"; | |
7200 | case DSC__K_DTYPE_GC: | |
7201 | return "GC (Double precision complex, G floating)"; | |
7202 | case DSC__K_DTYPE_HC: | |
7203 | return "HC (Quadruple precision complex, H floating)"; | |
7204 | case DSC__K_DTYPE_CIT: | |
7205 | return "CIT (COBOL intermediate temporary)"; | |
7206 | case DSC__K_DTYPE_BPV: | |
7207 | return "BPV (Bound Procedure Value)"; | |
7208 | case DSC__K_DTYPE_BLV: | |
7209 | return "BLV (Bound Label Value)"; | |
7210 | case DSC__K_DTYPE_VU: | |
7211 | return "VU (Bit Unaligned)"; | |
7212 | case DSC__K_DTYPE_ADT: | |
7213 | return "ADT (Absolute Date-Time)"; | |
7214 | case DSC__K_DTYPE_VT: | |
7215 | return "VT (Varying Text)"; | |
7216 | case DSC__K_DTYPE_T2: | |
7217 | return "T2 (16-bit char)"; | |
7218 | case DSC__K_DTYPE_VT2: | |
7219 | return "VT2 (16-bit varying char)"; | |
7220 | default: | |
7221 | return "?? (unknown)"; | |
7222 | } | |
7223 | } | |
7224 | ||
7225 | static void | |
a3c0896d AM |
7226 | evax_bfd_print_desc (const unsigned char *buf, unsigned int bufsize, |
7227 | int indent, FILE *file) | |
95e34ef7 | 7228 | { |
a3c0896d AM |
7229 | if (bufsize < 8) |
7230 | return; | |
7231 | ||
95e34ef7 TG |
7232 | unsigned char bclass = buf[3]; |
7233 | unsigned char dtype = buf[2]; | |
7234 | unsigned int len = (unsigned)bfd_getl16 (buf); | |
7235 | unsigned int pointer = (unsigned)bfd_getl32 (buf + 4); | |
7236 | ||
7237 | evax_bfd_print_indent (indent, file); | |
7238 | ||
7239 | if (len == 1 && pointer == 0xffffffffUL) | |
7240 | { | |
7241 | /* 64 bits. */ | |
7242 | fprintf (file, _("64 bits *unhandled*\n")); | |
7243 | } | |
7244 | else | |
7245 | { | |
695344c0 | 7246 | /* xgettext:c-format */ |
95e34ef7 | 7247 | fprintf (file, _("class: %u, dtype: %u, length: %u, pointer: 0x%08x\n"), |
07d6d2b8 | 7248 | bclass, dtype, len, pointer); |
95e34ef7 | 7249 | switch (bclass) |
07d6d2b8 AM |
7250 | { |
7251 | case DSC__K_CLASS_NCA: | |
7252 | { | |
7253 | const struct vms_dsc_nca *dsc = (const void *)buf; | |
7254 | unsigned int i; | |
7255 | const unsigned char *b; | |
7256 | ||
7257 | evax_bfd_print_indent (indent, file); | |
7258 | fprintf (file, _("non-contiguous array of %s\n"), | |
7259 | evax_bfd_get_dsc_name (dsc->dtype)); | |
a3c0896d | 7260 | if (bufsize >= sizeof (*dsc)) |
07d6d2b8 | 7261 | { |
a3c0896d AM |
7262 | evax_bfd_print_indent (indent + 1, file); |
7263 | fprintf (file, | |
7264 | /* xgettext:c-format */ | |
7265 | _("dimct: %u, aflags: 0x%02x, digits: %u, scale: %u\n"), | |
7266 | dsc->dimct, dsc->aflags, dsc->digits, dsc->scale); | |
7267 | evax_bfd_print_indent (indent + 1, file); | |
7268 | fprintf (file, | |
7269 | /* xgettext:c-format */ | |
7270 | _("arsize: %u, a0: 0x%08x\n"), | |
7271 | (unsigned) bfd_getl32 (dsc->arsize), | |
7272 | (unsigned) bfd_getl32 (dsc->a0)); | |
7273 | evax_bfd_print_indent (indent + 1, file); | |
7274 | fprintf (file, _("Strides:\n")); | |
7275 | b = buf + sizeof (*dsc); | |
7276 | bufsize -= sizeof (*dsc); | |
7277 | for (i = 0; i < dsc->dimct; i++) | |
7278 | { | |
7279 | if (bufsize < 4) | |
7280 | break; | |
7281 | evax_bfd_print_indent (indent + 2, file); | |
7282 | fprintf (file, "[%u]: %u\n", i + 1, | |
7283 | (unsigned) bfd_getl32 (b)); | |
7284 | b += 4; | |
7285 | bufsize -= 4; | |
7286 | } | |
7287 | evax_bfd_print_indent (indent + 1, file); | |
7288 | fprintf (file, _("Bounds:\n")); | |
7289 | for (i = 0; i < dsc->dimct; i++) | |
7290 | { | |
7291 | if (bufsize < 8) | |
7292 | break; | |
7293 | evax_bfd_print_indent (indent + 2, file); | |
7294 | /* xgettext:c-format */ | |
7295 | fprintf (file, _("[%u]: Lower: %u, upper: %u\n"), i + 1, | |
7296 | (unsigned) bfd_getl32 (b + 0), | |
7297 | (unsigned) bfd_getl32 (b + 4)); | |
7298 | b += 8; | |
7299 | bufsize -= 8; | |
7300 | } | |
07d6d2b8 AM |
7301 | } |
7302 | } | |
7303 | break; | |
7304 | case DSC__K_CLASS_UBS: | |
7305 | { | |
7306 | const struct vms_dsc_ubs *ubs = (const void *)buf; | |
7307 | ||
7308 | evax_bfd_print_indent (indent, file); | |
7309 | fprintf (file, _("unaligned bit-string of %s\n"), | |
7310 | evax_bfd_get_dsc_name (ubs->dtype)); | |
a3c0896d AM |
7311 | if (bufsize >= sizeof (*ubs)) |
7312 | { | |
7313 | evax_bfd_print_indent (indent + 1, file); | |
7314 | fprintf (file, | |
7315 | /* xgettext:c-format */ | |
7316 | _("base: %u, pos: %u\n"), | |
7317 | (unsigned) bfd_getl32 (ubs->base), | |
7318 | (unsigned) bfd_getl32 (ubs->pos)); | |
7319 | } | |
07d6d2b8 AM |
7320 | } |
7321 | break; | |
7322 | default: | |
7323 | fprintf (file, _("*unhandled*\n")); | |
7324 | break; | |
7325 | } | |
95e34ef7 TG |
7326 | } |
7327 | } | |
7328 | ||
7329 | static unsigned int | |
a3c0896d AM |
7330 | evax_bfd_print_valspec (const unsigned char *buf, unsigned int bufsize, |
7331 | int indent, FILE *file) | |
95e34ef7 | 7332 | { |
a3c0896d AM |
7333 | if (bufsize < 5) |
7334 | return bufsize; | |
7335 | ||
95e34ef7 | 7336 | unsigned int vflags = buf[0]; |
a3c0896d | 7337 | unsigned int value = (unsigned) bfd_getl32 (buf + 1); |
95e34ef7 TG |
7338 | unsigned int len = 5; |
7339 | ||
7340 | evax_bfd_print_indent (indent, file); | |
695344c0 | 7341 | /* xgettext:c-format */ |
95e34ef7 TG |
7342 | fprintf (file, _("vflags: 0x%02x, value: 0x%08x "), vflags, value); |
7343 | buf += 5; | |
a3c0896d | 7344 | bufsize -= 5; |
95e34ef7 TG |
7345 | |
7346 | switch (vflags) | |
7347 | { | |
7348 | case DST__K_VFLAGS_NOVAL: | |
7349 | fprintf (file, _("(no value)\n")); | |
7350 | break; | |
7351 | case DST__K_VFLAGS_NOTACTIVE: | |
7352 | fprintf (file, _("(not active)\n")); | |
7353 | break; | |
7354 | case DST__K_VFLAGS_UNALLOC: | |
7355 | fprintf (file, _("(not allocated)\n")); | |
7356 | break; | |
7357 | case DST__K_VFLAGS_DSC: | |
7358 | fprintf (file, _("(descriptor)\n")); | |
a3c0896d AM |
7359 | if (value <= bufsize) |
7360 | evax_bfd_print_desc (buf + value, bufsize - value, indent + 1, file); | |
95e34ef7 TG |
7361 | break; |
7362 | case DST__K_VFLAGS_TVS: | |
7363 | fprintf (file, _("(trailing value)\n")); | |
7364 | break; | |
7365 | case DST__K_VS_FOLLOWS: | |
7366 | fprintf (file, _("(value spec follows)\n")); | |
7367 | break; | |
7368 | case DST__K_VFLAGS_BITOFFS: | |
7369 | fprintf (file, _("(at bit offset %u)\n"), value); | |
7370 | break; | |
7371 | default: | |
695344c0 | 7372 | /* xgettext:c-format */ |
95e34ef7 | 7373 | fprintf (file, _("(reg: %u, disp: %u, indir: %u, kind: "), |
07d6d2b8 AM |
7374 | (vflags & DST__K_REGNUM_MASK) >> DST__K_REGNUM_SHIFT, |
7375 | vflags & DST__K_DISP ? 1 : 0, | |
7376 | vflags & DST__K_INDIR ? 1 : 0); | |
95e34ef7 | 7377 | switch (vflags & DST__K_VALKIND_MASK) |
07d6d2b8 AM |
7378 | { |
7379 | case DST__K_VALKIND_LITERAL: | |
7380 | fputs (_("literal"), file); | |
7381 | break; | |
7382 | case DST__K_VALKIND_ADDR: | |
7383 | fputs (_("address"), file); | |
7384 | break; | |
7385 | case DST__K_VALKIND_DESC: | |
7386 | fputs (_("desc"), file); | |
7387 | break; | |
7388 | case DST__K_VALKIND_REG: | |
7389 | fputs (_("reg"), file); | |
7390 | break; | |
7391 | } | |
95e34ef7 TG |
7392 | fputs (")\n", file); |
7393 | break; | |
7394 | } | |
7395 | return len; | |
7396 | } | |
7397 | ||
7398 | static void | |
a3c0896d AM |
7399 | evax_bfd_print_typspec (const unsigned char *buf, unsigned int bufsize, |
7400 | int indent, FILE *file) | |
95e34ef7 | 7401 | { |
a3c0896d AM |
7402 | if (bufsize < 3) |
7403 | return; | |
7404 | ||
95e34ef7 | 7405 | unsigned char kind = buf[2]; |
a3c0896d | 7406 | unsigned int len = (unsigned) bfd_getl16 (buf); |
95e34ef7 TG |
7407 | |
7408 | evax_bfd_print_indent (indent, file); | |
695344c0 NC |
7409 | /* xgettext:c-format */ |
7410 | fprintf (file, _("len: %2u, kind: %2u "), len, kind); | |
95e34ef7 | 7411 | buf += 3; |
a3c0896d | 7412 | bufsize -= 3; |
95e34ef7 TG |
7413 | switch (kind) |
7414 | { | |
7415 | case DST__K_TS_ATOM: | |
695344c0 | 7416 | /* xgettext:c-format */ |
a3c0896d AM |
7417 | if (bufsize >= 1) |
7418 | fprintf (file, _("atomic, type=0x%02x %s\n"), | |
7419 | buf[0], evax_bfd_get_dsc_name (buf[0])); | |
95e34ef7 TG |
7420 | break; |
7421 | case DST__K_TS_IND: | |
a3c0896d AM |
7422 | if (bufsize >= 4) |
7423 | fprintf (file, _("indirect, defined at 0x%08x\n"), | |
7424 | (unsigned) bfd_getl32 (buf)); | |
95e34ef7 TG |
7425 | break; |
7426 | case DST__K_TS_TPTR: | |
695344c0 | 7427 | fprintf (file, _("typed pointer\n")); |
a3c0896d | 7428 | evax_bfd_print_typspec (buf, bufsize, indent + 1, file); |
95e34ef7 TG |
7429 | break; |
7430 | case DST__K_TS_PTR: | |
695344c0 | 7431 | fprintf (file, _("pointer\n")); |
95e34ef7 TG |
7432 | break; |
7433 | case DST__K_TS_ARRAY: | |
7434 | { | |
07d6d2b8 | 7435 | const unsigned char *vs; |
a3c0896d | 7436 | unsigned int vs_len; |
07d6d2b8 AM |
7437 | unsigned int vec_len; |
7438 | unsigned int i; | |
7439 | ||
a3c0896d AM |
7440 | if (bufsize == 0) |
7441 | return; | |
07d6d2b8 | 7442 | fprintf (file, _("array, dim: %u, bitmap: "), buf[0]); |
a3c0896d | 7443 | --bufsize; |
07d6d2b8 AM |
7444 | vec_len = (buf[0] + 1 + 7) / 8; |
7445 | for (i = 0; i < vec_len; i++) | |
a3c0896d AM |
7446 | { |
7447 | if (bufsize == 0) | |
7448 | break; | |
7449 | fprintf (file, " %02x", buf[i + 1]); | |
7450 | --bufsize; | |
7451 | } | |
07d6d2b8 | 7452 | fputc ('\n', file); |
a3c0896d AM |
7453 | if (bufsize == 0) |
7454 | return; | |
07d6d2b8 AM |
7455 | vs = buf + 1 + vec_len; |
7456 | evax_bfd_print_indent (indent, file); | |
7457 | fprintf (file, _("array descriptor:\n")); | |
a3c0896d AM |
7458 | vs_len = evax_bfd_print_valspec (vs, bufsize, indent + 1, file); |
7459 | vs += vs_len; | |
7460 | if (bufsize > vs_len) | |
7461 | { | |
7462 | bufsize -= vs_len; | |
7463 | for (i = 0; i < buf[0] + 1U; i++) | |
7464 | if (buf[1 + i / 8] & (1 << (i % 8))) | |
7465 | { | |
7466 | evax_bfd_print_indent (indent, file); | |
7467 | if (i == 0) | |
7468 | fprintf (file, _("type spec for element:\n")); | |
7469 | else | |
7470 | fprintf (file, _("type spec for subscript %u:\n"), i); | |
7471 | evax_bfd_print_typspec (vs, bufsize, indent + 1, file); | |
7472 | if (bufsize < 2) | |
7473 | break; | |
7474 | vs_len = bfd_getl16 (vs); | |
7475 | if (bufsize <= vs_len) | |
7476 | break; | |
7477 | vs += vs_len; | |
7478 | bufsize -= vs_len; | |
7479 | } | |
7480 | } | |
95e34ef7 TG |
7481 | } |
7482 | break; | |
7483 | default: | |
695344c0 | 7484 | fprintf (file, _("*unhandled*\n")); |
95e34ef7 TG |
7485 | } |
7486 | } | |
7487 | ||
7488 | static void | |
7489 | evax_bfd_print_dst (struct bfd *abfd, unsigned int dst_size, FILE *file) | |
7490 | { | |
7491 | unsigned int off = 0; | |
7492 | unsigned int pc = 0; | |
7493 | unsigned int line = 0; | |
7494 | ||
7495 | fprintf (file, _("Debug symbol table:\n")); | |
7496 | ||
7497 | while (dst_size > 0) | |
7498 | { | |
7499 | struct vms_dst_header dsth; | |
7500 | unsigned int len; | |
7501 | unsigned int type; | |
7502 | unsigned char *buf; | |
7503 | ||
226f9f4f | 7504 | if (bfd_read (&dsth, sizeof (dsth), abfd) != sizeof (dsth)) |
07d6d2b8 AM |
7505 | { |
7506 | fprintf (file, _("cannot read DST header\n")); | |
7507 | return; | |
7508 | } | |
95e34ef7 TG |
7509 | len = bfd_getl16 (dsth.length); |
7510 | type = bfd_getl16 (dsth.type); | |
695344c0 | 7511 | /* xgettext:c-format */ |
95e34ef7 | 7512 | fprintf (file, _(" type: %3u, len: %3u (at 0x%08x): "), |
07d6d2b8 | 7513 | type, len, off); |
a3c0896d | 7514 | if (len < sizeof (dsth)) |
07d6d2b8 AM |
7515 | { |
7516 | fputc ('\n', file); | |
7517 | break; | |
7518 | } | |
95e34ef7 TG |
7519 | dst_size -= len; |
7520 | off += len; | |
7521 | len -= sizeof (dsth); | |
a3c0896d AM |
7522 | if (len == 0) |
7523 | buf = NULL; | |
7524 | else | |
07d6d2b8 | 7525 | { |
a3c0896d AM |
7526 | buf = _bfd_malloc_and_read (abfd, len, len); |
7527 | if (buf == NULL) | |
7528 | { | |
7529 | fprintf (file, _("cannot read DST symbol\n")); | |
7530 | return; | |
7531 | } | |
07d6d2b8 | 7532 | } |
95e34ef7 | 7533 | switch (type) |
07d6d2b8 AM |
7534 | { |
7535 | case DSC__K_DTYPE_V: | |
7536 | case DSC__K_DTYPE_BU: | |
7537 | case DSC__K_DTYPE_WU: | |
7538 | case DSC__K_DTYPE_LU: | |
7539 | case DSC__K_DTYPE_QU: | |
7540 | case DSC__K_DTYPE_B: | |
7541 | case DSC__K_DTYPE_W: | |
7542 | case DSC__K_DTYPE_L: | |
7543 | case DSC__K_DTYPE_Q: | |
7544 | case DSC__K_DTYPE_F: | |
7545 | case DSC__K_DTYPE_D: | |
7546 | case DSC__K_DTYPE_FC: | |
7547 | case DSC__K_DTYPE_DC: | |
7548 | case DSC__K_DTYPE_T: | |
7549 | case DSC__K_DTYPE_NU: | |
7550 | case DSC__K_DTYPE_NL: | |
7551 | case DSC__K_DTYPE_NLO: | |
7552 | case DSC__K_DTYPE_NR: | |
7553 | case DSC__K_DTYPE_NRO: | |
7554 | case DSC__K_DTYPE_NZ: | |
7555 | case DSC__K_DTYPE_P: | |
7556 | case DSC__K_DTYPE_ZI: | |
7557 | case DSC__K_DTYPE_ZEM: | |
7558 | case DSC__K_DTYPE_DSC: | |
7559 | case DSC__K_DTYPE_OU: | |
7560 | case DSC__K_DTYPE_O: | |
7561 | case DSC__K_DTYPE_G: | |
7562 | case DSC__K_DTYPE_H: | |
7563 | case DSC__K_DTYPE_GC: | |
7564 | case DSC__K_DTYPE_HC: | |
7565 | case DSC__K_DTYPE_CIT: | |
7566 | case DSC__K_DTYPE_BPV: | |
7567 | case DSC__K_DTYPE_BLV: | |
7568 | case DSC__K_DTYPE_VU: | |
7569 | case DSC__K_DTYPE_ADT: | |
7570 | case DSC__K_DTYPE_VT: | |
7571 | case DSC__K_DTYPE_T2: | |
7572 | case DSC__K_DTYPE_VT2: | |
7573 | fprintf (file, _("standard data: %s\n"), | |
7574 | evax_bfd_get_dsc_name (type)); | |
a3c0896d | 7575 | evax_bfd_print_valspec (buf, len, 4, file); |
6e731729 AM |
7576 | if (len > 6) |
7577 | fprintf (file, _(" name: %.*s\n"), | |
7578 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); | |
07d6d2b8 AM |
7579 | break; |
7580 | case DST__K_MODBEG: | |
7581 | { | |
7582 | struct vms_dst_modbeg *dst = (void *)buf; | |
98c445c0 | 7583 | unsigned char *name = buf + sizeof (*dst); |
07d6d2b8 AM |
7584 | |
7585 | fprintf (file, _("modbeg\n")); | |
a3c0896d AM |
7586 | if (len < sizeof (*dst)) |
7587 | break; | |
695344c0 | 7588 | /* xgettext:c-format */ |
07d6d2b8 AM |
7589 | fprintf (file, _(" flags: %d, language: %u, " |
7590 | "major: %u, minor: %u\n"), | |
7591 | dst->flags, | |
7592 | (unsigned)bfd_getl32 (dst->language), | |
7593 | (unsigned)bfd_getl16 (dst->major), | |
7594 | (unsigned)bfd_getl16 (dst->minor)); | |
a3c0896d AM |
7595 | len -= sizeof (*dst); |
7596 | if (len > 0) | |
7597 | { | |
7598 | int nlen = len - 1; | |
7599 | fprintf (file, _(" module name: %.*s\n"), | |
7600 | name[0] > nlen ? nlen : name[0], name + 1); | |
7601 | if (name[0] < nlen) | |
7602 | { | |
7603 | len -= name[0] + 1; | |
7604 | name += name[0] + 1; | |
7605 | nlen = len - 1; | |
7606 | fprintf (file, _(" compiler : %.*s\n"), | |
98c445c0 | 7607 | name[0] > nlen ? nlen : name[0], name + 1); |
a3c0896d AM |
7608 | } |
7609 | } | |
07d6d2b8 AM |
7610 | } |
7611 | break; | |
7612 | case DST__K_MODEND: | |
7613 | fprintf (file, _("modend\n")); | |
7614 | break; | |
7615 | case DST__K_RTNBEG: | |
7616 | { | |
7617 | struct vms_dst_rtnbeg *dst = (void *)buf; | |
98c445c0 | 7618 | unsigned char *name = buf + sizeof (*dst); |
07d6d2b8 AM |
7619 | |
7620 | fputs (_("rtnbeg\n"), file); | |
a3c0896d AM |
7621 | if (len >= sizeof (*dst)) |
7622 | { | |
7623 | /* xgettext:c-format */ | |
7624 | fprintf (file, _(" flags: %u, address: 0x%08x, " | |
7625 | "pd-address: 0x%08x\n"), | |
7626 | dst->flags, | |
7627 | (unsigned) bfd_getl32 (dst->address), | |
7628 | (unsigned) bfd_getl32 (dst->pd_address)); | |
7629 | len -= sizeof (*dst); | |
7630 | if (len > 0) | |
7631 | { | |
7632 | int nlen = len - 1; | |
7633 | fprintf (file, _(" routine name: %.*s\n"), | |
7634 | name[0] > nlen ? nlen : name[0], name + 1); | |
7635 | } | |
7636 | } | |
07d6d2b8 AM |
7637 | } |
7638 | break; | |
7639 | case DST__K_RTNEND: | |
7640 | { | |
7641 | struct vms_dst_rtnend *dst = (void *)buf; | |
7642 | ||
a3c0896d AM |
7643 | if (len >= sizeof (*dst)) |
7644 | fprintf (file, _("rtnend: size 0x%08x\n"), | |
7645 | (unsigned) bfd_getl32 (dst->size)); | |
07d6d2b8 AM |
7646 | } |
7647 | break; | |
7648 | case DST__K_PROLOG: | |
7649 | { | |
7650 | struct vms_dst_prolog *dst = (void *)buf; | |
7651 | ||
a3c0896d AM |
7652 | if (len >= sizeof (*dst)) |
7653 | /* xgettext:c-format */ | |
7654 | fprintf (file, _("prolog: bkpt address 0x%08x\n"), | |
7655 | (unsigned) bfd_getl32 (dst->bkpt_addr)); | |
07d6d2b8 AM |
7656 | } |
7657 | break; | |
7658 | case DST__K_EPILOG: | |
7659 | { | |
7660 | struct vms_dst_epilog *dst = (void *)buf; | |
95e34ef7 | 7661 | |
a3c0896d AM |
7662 | if (len >= sizeof (*dst)) |
7663 | /* xgettext:c-format */ | |
7664 | fprintf (file, _("epilog: flags: %u, count: %u\n"), | |
7665 | dst->flags, (unsigned) bfd_getl32 (dst->count)); | |
07d6d2b8 AM |
7666 | } |
7667 | break; | |
7668 | case DST__K_BLKBEG: | |
7669 | { | |
7670 | struct vms_dst_blkbeg *dst = (void *)buf; | |
98c445c0 | 7671 | unsigned char *name = buf + sizeof (*dst); |
95e34ef7 | 7672 | |
a3c0896d AM |
7673 | if (len > sizeof (*dst)) |
7674 | { | |
7675 | int nlen; | |
7676 | len -= sizeof (*dst); | |
7677 | nlen = len - 1; | |
7678 | /* xgettext:c-format */ | |
7679 | fprintf (file, _("blkbeg: address: 0x%08x, name: %.*s\n"), | |
7680 | (unsigned) bfd_getl32 (dst->address), | |
7681 | name[0] > nlen ? nlen : name[0], name + 1); | |
7682 | } | |
07d6d2b8 AM |
7683 | } |
7684 | break; | |
7685 | case DST__K_BLKEND: | |
7686 | { | |
7687 | struct vms_dst_blkend *dst = (void *)buf; | |
7688 | ||
a3c0896d AM |
7689 | if (len >= sizeof (*dst)) |
7690 | /* xgettext:c-format */ | |
7691 | fprintf (file, _("blkend: size: 0x%08x\n"), | |
7692 | (unsigned) bfd_getl32 (dst->size)); | |
07d6d2b8 AM |
7693 | } |
7694 | break; | |
7695 | case DST__K_TYPSPEC: | |
7696 | { | |
7697 | fprintf (file, _("typspec (len: %u)\n"), len); | |
a3c0896d AM |
7698 | if (len >= 1) |
7699 | { | |
7700 | int nlen = len - 1; | |
7701 | fprintf (file, _(" name: %.*s\n"), | |
7702 | buf[0] > nlen ? nlen : buf[0], buf + 1); | |
7703 | if (nlen > buf[0]) | |
7704 | evax_bfd_print_typspec (buf + 1 + buf[0], len - (1 + buf[0]), | |
7705 | 5, file); | |
7706 | } | |
07d6d2b8 AM |
7707 | } |
7708 | break; | |
7709 | case DST__K_SEPTYP: | |
7710 | { | |
a3c0896d AM |
7711 | if (len >= 6) |
7712 | { | |
7713 | fprintf (file, _("septyp, name: %.*s\n"), | |
7714 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); | |
7715 | evax_bfd_print_valspec (buf, len, 4, file); | |
7716 | } | |
07d6d2b8 AM |
7717 | } |
7718 | break; | |
7719 | case DST__K_RECBEG: | |
7720 | { | |
7721 | struct vms_dst_recbeg *recbeg = (void *)buf; | |
98c445c0 | 7722 | unsigned char *name = buf + sizeof (*recbeg); |
07d6d2b8 | 7723 | |
a3c0896d AM |
7724 | if (len > sizeof (*recbeg)) |
7725 | { | |
7726 | int nlen = len - sizeof (*recbeg) - 1; | |
7727 | if (name[0] < nlen) | |
7728 | nlen = name[0]; | |
7729 | fprintf (file, _("recbeg: name: %.*s\n"), nlen, name + 1); | |
7730 | evax_bfd_print_valspec (buf, len, 4, file); | |
7731 | len -= 1 + nlen; | |
7732 | if (len >= 4) | |
7733 | fprintf (file, _(" len: %u bits\n"), | |
7734 | (unsigned) bfd_getl32 (name + 1 + nlen)); | |
7735 | } | |
07d6d2b8 AM |
7736 | } |
7737 | break; | |
7738 | case DST__K_RECEND: | |
7739 | fprintf (file, _("recend\n")); | |
7740 | break; | |
7741 | case DST__K_ENUMBEG: | |
a3c0896d AM |
7742 | if (len >= 2) |
7743 | /* xgettext:c-format */ | |
7744 | fprintf (file, _("enumbeg, len: %u, name: %.*s\n"), | |
7745 | buf[0], buf[1] > len - 2 ? len - 2 : buf[1], buf + 2); | |
07d6d2b8 AM |
7746 | break; |
7747 | case DST__K_ENUMELT: | |
a3c0896d AM |
7748 | if (len >= 6) |
7749 | { | |
7750 | fprintf (file, _("enumelt, name: %.*s\n"), | |
7751 | buf[5] > len - 6 ? len - 6 : buf[5], buf + 6); | |
7752 | evax_bfd_print_valspec (buf, len, 4, file); | |
7753 | } | |
07d6d2b8 AM |
7754 | break; |
7755 | case DST__K_ENUMEND: | |
7756 | fprintf (file, _("enumend\n")); | |
7757 | break; | |
7758 | case DST__K_LABEL: | |
7759 | { | |
7760 | struct vms_dst_label *lab = (void *)buf; | |
a3c0896d AM |
7761 | if (len >= sizeof (*lab)) |
7762 | { | |
7763 | fprintf (file, _("label, name: %.*s\n"), | |
7764 | lab->name[0] > len - 1 ? len - 1 : lab->name[0], | |
7765 | lab->name + 1); | |
7766 | fprintf (file, _(" address: 0x%08x\n"), | |
7767 | (unsigned) bfd_getl32 (lab->value)); | |
7768 | } | |
07d6d2b8 AM |
7769 | } |
7770 | break; | |
7771 | case DST__K_DIS_RANGE: | |
a3c0896d AM |
7772 | if (len >= 4) |
7773 | { | |
7774 | unsigned int cnt = bfd_getl32 (buf); | |
7775 | unsigned char *rng = buf + 4; | |
7776 | unsigned int i; | |
07d6d2b8 | 7777 | |
a3c0896d AM |
7778 | fprintf (file, _("discontiguous range (nbr: %u)\n"), cnt); |
7779 | len -= 4; | |
7780 | for (i = 0; i < cnt; i++, rng += 8) | |
7781 | { | |
7782 | if (len < 8) | |
7783 | break; | |
7784 | /* xgettext:c-format */ | |
7785 | fprintf (file, _(" address: 0x%08x, size: %u\n"), | |
7786 | (unsigned) bfd_getl32 (rng), | |
7787 | (unsigned) bfd_getl32 (rng + 4)); | |
7788 | len -= 8; | |
7789 | } | |
7790 | } | |
07d6d2b8 AM |
7791 | break; |
7792 | case DST__K_LINE_NUM: | |
7793 | { | |
7794 | unsigned char *buf_orig = buf; | |
7795 | ||
7796 | fprintf (file, _("line num (len: %u)\n"), len); | |
7797 | ||
7798 | while (len > 0) | |
7799 | { | |
a3c0896d | 7800 | int cmd; |
07d6d2b8 | 7801 | unsigned int val; |
a3c0896d | 7802 | int cmdlen = -1; |
07d6d2b8 | 7803 | |
a3c0896d AM |
7804 | cmd = *buf++; |
7805 | len--; | |
07d6d2b8 AM |
7806 | |
7807 | fputs (" ", file); | |
7808 | ||
7809 | switch (cmd) | |
7810 | { | |
7811 | case DST__K_DELTA_PC_W: | |
a3c0896d AM |
7812 | if (len < 2) |
7813 | break; | |
7814 | val = bfd_getl16 (buf); | |
07d6d2b8 AM |
7815 | fprintf (file, _("delta_pc_w %u\n"), val); |
7816 | pc += val; | |
7817 | line++; | |
a3c0896d | 7818 | cmdlen = 2; |
07d6d2b8 AM |
7819 | break; |
7820 | case DST__K_INCR_LINUM: | |
a3c0896d AM |
7821 | if (len < 1) |
7822 | break; | |
7823 | val = *buf; | |
07d6d2b8 AM |
7824 | fprintf (file, _("incr_linum(b): +%u\n"), val); |
7825 | line += val; | |
a3c0896d | 7826 | cmdlen = 1; |
07d6d2b8 AM |
7827 | break; |
7828 | case DST__K_INCR_LINUM_W: | |
a3c0896d AM |
7829 | if (len < 2) |
7830 | break; | |
7831 | val = bfd_getl16 (buf); | |
07d6d2b8 AM |
7832 | fprintf (file, _("incr_linum_w: +%u\n"), val); |
7833 | line += val; | |
a3c0896d | 7834 | cmdlen = 2; |
07d6d2b8 AM |
7835 | break; |
7836 | case DST__K_INCR_LINUM_L: | |
a3c0896d AM |
7837 | if (len < 4) |
7838 | break; | |
7839 | val = bfd_getl32 (buf); | |
07d6d2b8 AM |
7840 | fprintf (file, _("incr_linum_l: +%u\n"), val); |
7841 | line += val; | |
a3c0896d | 7842 | cmdlen = 4; |
07d6d2b8 AM |
7843 | break; |
7844 | case DST__K_SET_LINUM: | |
a3c0896d AM |
7845 | if (len < 2) |
7846 | break; | |
7847 | line = bfd_getl16 (buf); | |
07d6d2b8 | 7848 | fprintf (file, _("set_line_num(w) %u\n"), line); |
a3c0896d | 7849 | cmdlen = 2; |
07d6d2b8 AM |
7850 | break; |
7851 | case DST__K_SET_LINUM_B: | |
a3c0896d AM |
7852 | if (len < 1) |
7853 | break; | |
7854 | line = *buf; | |
07d6d2b8 | 7855 | fprintf (file, _("set_line_num_b %u\n"), line); |
a3c0896d | 7856 | cmdlen = 1; |
07d6d2b8 AM |
7857 | break; |
7858 | case DST__K_SET_LINUM_L: | |
a3c0896d AM |
7859 | if (len < 4) |
7860 | break; | |
7861 | line = bfd_getl32 (buf); | |
07d6d2b8 | 7862 | fprintf (file, _("set_line_num_l %u\n"), line); |
a3c0896d | 7863 | cmdlen = 4; |
07d6d2b8 AM |
7864 | break; |
7865 | case DST__K_SET_ABS_PC: | |
a3c0896d AM |
7866 | if (len < 4) |
7867 | break; | |
7868 | pc = bfd_getl32 (buf); | |
07d6d2b8 | 7869 | fprintf (file, _("set_abs_pc: 0x%08x\n"), pc); |
a3c0896d | 7870 | cmdlen = 4; |
07d6d2b8 AM |
7871 | break; |
7872 | case DST__K_DELTA_PC_L: | |
a3c0896d AM |
7873 | if (len < 4) |
7874 | break; | |
07d6d2b8 | 7875 | fprintf (file, _("delta_pc_l: +0x%08x\n"), |
a3c0896d AM |
7876 | (unsigned) bfd_getl32 (buf)); |
7877 | cmdlen = 4; | |
07d6d2b8 AM |
7878 | break; |
7879 | case DST__K_TERM: | |
a3c0896d AM |
7880 | if (len < 1) |
7881 | break; | |
7882 | fprintf (file, _("term(b): 0x%02x"), *buf); | |
7883 | pc += *buf; | |
07d6d2b8 | 7884 | fprintf (file, _(" pc: 0x%08x\n"), pc); |
a3c0896d | 7885 | cmdlen = 1; |
07d6d2b8 AM |
7886 | break; |
7887 | case DST__K_TERM_W: | |
a3c0896d AM |
7888 | if (len < 2) |
7889 | break; | |
7890 | val = bfd_getl16 (buf); | |
07d6d2b8 AM |
7891 | fprintf (file, _("term_w: 0x%04x"), val); |
7892 | pc += val; | |
7893 | fprintf (file, _(" pc: 0x%08x\n"), pc); | |
a3c0896d | 7894 | cmdlen = 2; |
07d6d2b8 AM |
7895 | break; |
7896 | default: | |
7897 | if (cmd <= 0) | |
7898 | { | |
7899 | fprintf (file, _("delta pc +%-4d"), -cmd); | |
7900 | line++; /* FIXME: curr increment. */ | |
7901 | pc += -cmd; | |
695344c0 | 7902 | /* xgettext:c-format */ |
07d6d2b8 AM |
7903 | fprintf (file, _(" pc: 0x%08x line: %5u\n"), |
7904 | pc, line); | |
a3c0896d | 7905 | cmdlen = 0; |
07d6d2b8 AM |
7906 | } |
7907 | else | |
7908 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); | |
7909 | break; | |
7910 | } | |
a3c0896d | 7911 | if (cmdlen < 0) |
07d6d2b8 AM |
7912 | break; |
7913 | len -= cmdlen; | |
7914 | buf += cmdlen; | |
7915 | } | |
7916 | buf = buf_orig; | |
7917 | } | |
7918 | break; | |
7919 | case DST__K_SOURCE: | |
7920 | { | |
7921 | unsigned char *buf_orig = buf; | |
7922 | ||
7923 | fprintf (file, _("source (len: %u)\n"), len); | |
7924 | ||
7925 | while (len > 0) | |
7926 | { | |
a3c0896d AM |
7927 | int cmd = *buf++; |
7928 | int cmdlen = -1; | |
07d6d2b8 | 7929 | |
a3c0896d | 7930 | len--; |
07d6d2b8 AM |
7931 | switch (cmd) |
7932 | { | |
7933 | case DST__K_SRC_DECLFILE: | |
7934 | { | |
a3c0896d | 7935 | struct vms_dst_src_decl_src *src = (void *) buf; |
98c445c0 | 7936 | unsigned char *name; |
a3c0896d | 7937 | int nlen; |
95e34ef7 | 7938 | |
a3c0896d AM |
7939 | if (len < sizeof (*src)) |
7940 | break; | |
695344c0 | 7941 | /* xgettext:c-format */ |
07d6d2b8 AM |
7942 | fprintf (file, _(" declfile: len: %u, flags: %u, " |
7943 | "fileid: %u\n"), | |
7944 | src->length, src->flags, | |
7945 | (unsigned)bfd_getl16 (src->fileid)); | |
695344c0 | 7946 | /* xgettext:c-format */ |
07d6d2b8 AM |
7947 | fprintf (file, _(" rms: cdt: 0x%08x %08x, " |
7948 | "ebk: 0x%08x, ffb: 0x%04x, " | |
7949 | "rfo: %u\n"), | |
7950 | (unsigned)bfd_getl32 (src->rms_cdt + 4), | |
7951 | (unsigned)bfd_getl32 (src->rms_cdt + 0), | |
7952 | (unsigned)bfd_getl32 (src->rms_ebk), | |
7953 | (unsigned)bfd_getl16 (src->rms_ffb), | |
7954 | src->rms_rfo); | |
a3c0896d AM |
7955 | if (src->length > len || src->length <= sizeof (*src)) |
7956 | break; | |
7957 | nlen = src->length - sizeof (*src) - 1; | |
98c445c0 | 7958 | name = buf + sizeof (*src); |
07d6d2b8 | 7959 | fprintf (file, _(" filename : %.*s\n"), |
a3c0896d AM |
7960 | name[0] > nlen ? nlen : name[0], name + 1); |
7961 | if (name[0] >= nlen) | |
7962 | break; | |
7963 | nlen -= name[0] + 1; | |
07d6d2b8 AM |
7964 | name += name[0] + 1; |
7965 | fprintf (file, _(" module name: %.*s\n"), | |
a3c0896d AM |
7966 | name[0] > nlen ? nlen : name[0], name + 1); |
7967 | if (name[0] > nlen) | |
7968 | break; | |
7969 | cmdlen = src->length; | |
07d6d2b8 AM |
7970 | } |
7971 | break; | |
7972 | case DST__K_SRC_SETFILE: | |
a3c0896d AM |
7973 | if (len < 2) |
7974 | break; | |
07d6d2b8 | 7975 | fprintf (file, _(" setfile %u\n"), |
a3c0896d AM |
7976 | (unsigned) bfd_getl16 (buf)); |
7977 | cmdlen = 2; | |
07d6d2b8 AM |
7978 | break; |
7979 | case DST__K_SRC_SETREC_W: | |
a3c0896d AM |
7980 | if (len < 2) |
7981 | break; | |
07d6d2b8 | 7982 | fprintf (file, _(" setrec %u\n"), |
a3c0896d AM |
7983 | (unsigned) bfd_getl16 (buf)); |
7984 | cmdlen = 2; | |
07d6d2b8 AM |
7985 | break; |
7986 | case DST__K_SRC_SETREC_L: | |
a3c0896d AM |
7987 | if (len < 4) |
7988 | break; | |
07d6d2b8 | 7989 | fprintf (file, _(" setrec %u\n"), |
a3c0896d AM |
7990 | (unsigned) bfd_getl32 (buf)); |
7991 | cmdlen = 4; | |
07d6d2b8 AM |
7992 | break; |
7993 | case DST__K_SRC_SETLNUM_W: | |
a3c0896d AM |
7994 | if (len < 2) |
7995 | break; | |
07d6d2b8 | 7996 | fprintf (file, _(" setlnum %u\n"), |
a3c0896d AM |
7997 | (unsigned) bfd_getl16 (buf)); |
7998 | cmdlen = 2; | |
07d6d2b8 AM |
7999 | break; |
8000 | case DST__K_SRC_SETLNUM_L: | |
a3c0896d AM |
8001 | if (len < 4) |
8002 | break; | |
07d6d2b8 | 8003 | fprintf (file, _(" setlnum %u\n"), |
a3c0896d AM |
8004 | (unsigned) bfd_getl32 (buf)); |
8005 | cmdlen = 4; | |
07d6d2b8 AM |
8006 | break; |
8007 | case DST__K_SRC_DEFLINES_W: | |
a3c0896d AM |
8008 | if (len < 2) |
8009 | break; | |
07d6d2b8 | 8010 | fprintf (file, _(" deflines %u\n"), |
a3c0896d AM |
8011 | (unsigned) bfd_getl16 (buf)); |
8012 | cmdlen = 2; | |
07d6d2b8 AM |
8013 | break; |
8014 | case DST__K_SRC_DEFLINES_B: | |
a3c0896d AM |
8015 | if (len < 1) |
8016 | break; | |
8017 | fprintf (file, _(" deflines %u\n"), *buf); | |
8018 | cmdlen = 1; | |
07d6d2b8 AM |
8019 | break; |
8020 | case DST__K_SRC_FORMFEED: | |
8021 | fprintf (file, _(" formfeed\n")); | |
a3c0896d | 8022 | cmdlen = 0; |
07d6d2b8 AM |
8023 | break; |
8024 | default: | |
8025 | fprintf (file, _(" *unhandled* cmd %u\n"), cmd); | |
8026 | break; | |
8027 | } | |
a3c0896d | 8028 | if (cmdlen < 0) |
07d6d2b8 AM |
8029 | break; |
8030 | len -= cmdlen; | |
8031 | buf += cmdlen; | |
8032 | } | |
8033 | buf = buf_orig; | |
8034 | } | |
8035 | break; | |
8036 | default: | |
8037 | fprintf (file, _("*unhandled* dst type %u\n"), type); | |
8038 | break; | |
8039 | } | |
95e34ef7 TG |
8040 | free (buf); |
8041 | } | |
8042 | } | |
8043 | ||
8044 | static void | |
8045 | evax_bfd_print_image (bfd *abfd, FILE *file) | |
8046 | { | |
8047 | struct vms_eihd eihd; | |
8048 | const char *name; | |
8049 | unsigned int val; | |
8050 | unsigned int eiha_off; | |
8051 | unsigned int eihi_off; | |
8052 | unsigned int eihs_off; | |
8053 | unsigned int eisd_off; | |
8054 | unsigned int eihef_off = 0; | |
8055 | unsigned int eihnp_off = 0; | |
8056 | unsigned int dmt_vbn = 0; | |
8057 | unsigned int dmt_size = 0; | |
8058 | unsigned int dst_vbn = 0; | |
8059 | unsigned int dst_size = 0; | |
8060 | unsigned int gst_vbn = 0; | |
8061 | unsigned int gst_size = 0; | |
8062 | unsigned int eiaf_vbn = 0; | |
8063 | unsigned int eiaf_size = 0; | |
8064 | unsigned int eihvn_off; | |
8065 | ||
226f9f4f AM |
8066 | if (bfd_seek (abfd, 0, SEEK_SET) |
8067 | || bfd_read (&eihd, sizeof (eihd), abfd) != sizeof (eihd)) | |
95e34ef7 TG |
8068 | { |
8069 | fprintf (file, _("cannot read EIHD\n")); | |
8070 | return; | |
8071 | } | |
695344c0 | 8072 | /* xgettext:c-format */ |
95e34ef7 | 8073 | fprintf (file, _("EIHD: (size: %u, nbr blocks: %u)\n"), |
07d6d2b8 AM |
8074 | (unsigned)bfd_getl32 (eihd.size), |
8075 | (unsigned)bfd_getl32 (eihd.hdrblkcnt)); | |
695344c0 | 8076 | /* xgettext:c-format */ |
95e34ef7 | 8077 | fprintf (file, _(" majorid: %u, minorid: %u\n"), |
07d6d2b8 AM |
8078 | (unsigned)bfd_getl32 (eihd.majorid), |
8079 | (unsigned)bfd_getl32 (eihd.minorid)); | |
95e34ef7 TG |
8080 | |
8081 | val = (unsigned)bfd_getl32 (eihd.imgtype); | |
8082 | switch (val) | |
8083 | { | |
8084 | case EIHD__K_EXE: | |
8085 | name = _("executable"); | |
8086 | break; | |
8087 | case EIHD__K_LIM: | |
8088 | name = _("linkable image"); | |
8089 | break; | |
8090 | default: | |
8091 | name = _("unknown"); | |
8092 | break; | |
8093 | } | |
695344c0 | 8094 | /* xgettext:c-format */ |
95e34ef7 TG |
8095 | fprintf (file, _(" image type: %u (%s)"), val, name); |
8096 | ||
8097 | val = (unsigned)bfd_getl32 (eihd.subtype); | |
8098 | switch (val) | |
8099 | { | |
8100 | case EIHD__C_NATIVE: | |
8101 | name = _("native"); | |
8102 | break; | |
8103 | case EIHD__C_CLI: | |
8104 | name = _("CLI"); | |
8105 | break; | |
8106 | default: | |
8107 | name = _("unknown"); | |
8108 | break; | |
8109 | } | |
695344c0 | 8110 | /* xgettext:c-format */ |
95e34ef7 TG |
8111 | fprintf (file, _(", subtype: %u (%s)\n"), val, name); |
8112 | ||
8113 | eisd_off = bfd_getl32 (eihd.isdoff); | |
8114 | eiha_off = bfd_getl32 (eihd.activoff); | |
8115 | eihi_off = bfd_getl32 (eihd.imgidoff); | |
8116 | eihs_off = bfd_getl32 (eihd.symdbgoff); | |
695344c0 | 8117 | /* xgettext:c-format */ |
95e34ef7 | 8118 | fprintf (file, _(" offsets: isd: %u, activ: %u, symdbg: %u, " |
07d6d2b8 AM |
8119 | "imgid: %u, patch: %u\n"), |
8120 | eisd_off, eiha_off, eihs_off, eihi_off, | |
8121 | (unsigned)bfd_getl32 (eihd.patchoff)); | |
95e34ef7 TG |
8122 | fprintf (file, _(" fixup info rva: ")); |
8123 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.iafva)); | |
8124 | fprintf (file, _(", symbol vector rva: ")); | |
8125 | bfd_fprintf_vma (abfd, file, bfd_getl64 (eihd.symvva)); | |
8126 | eihvn_off = bfd_getl32 (eihd.version_array_off); | |
8127 | fprintf (file, _("\n" | |
07d6d2b8 AM |
8128 | " version array off: %u\n"), |
8129 | eihvn_off); | |
95e34ef7 | 8130 | fprintf (file, |
695344c0 | 8131 | /* xgettext:c-format */ |
07d6d2b8 AM |
8132 | _(" img I/O count: %u, nbr channels: %u, req pri: %08x%08x\n"), |
8133 | (unsigned)bfd_getl32 (eihd.imgiocnt), | |
8134 | (unsigned)bfd_getl32 (eihd.iochancnt), | |
8135 | (unsigned)bfd_getl32 (eihd.privreqs + 4), | |
8136 | (unsigned)bfd_getl32 (eihd.privreqs + 0)); | |
95e34ef7 TG |
8137 | val = (unsigned)bfd_getl32 (eihd.lnkflags); |
8138 | fprintf (file, _(" linker flags: %08x:"), val); | |
8139 | if (val & EIHD__M_LNKDEBUG) | |
8140 | fprintf (file, " LNKDEBUG"); | |
8141 | if (val & EIHD__M_LNKNOTFR) | |
8142 | fprintf (file, " LNKNOTFR"); | |
8143 | if (val & EIHD__M_NOP0BUFS) | |
8144 | fprintf (file, " NOP0BUFS"); | |
8145 | if (val & EIHD__M_PICIMG) | |
8146 | fprintf (file, " PICIMG"); | |
8147 | if (val & EIHD__M_P0IMAGE) | |
8148 | fprintf (file, " P0IMAGE"); | |
8149 | if (val & EIHD__M_DBGDMT) | |
8150 | fprintf (file, " DBGDMT"); | |
8151 | if (val & EIHD__M_INISHR) | |
8152 | fprintf (file, " INISHR"); | |
8153 | if (val & EIHD__M_XLATED) | |
8154 | fprintf (file, " XLATED"); | |
8155 | if (val & EIHD__M_BIND_CODE_SEC) | |
8156 | fprintf (file, " BIND_CODE_SEC"); | |
8157 | if (val & EIHD__M_BIND_DATA_SEC) | |
8158 | fprintf (file, " BIND_DATA_SEC"); | |
8159 | if (val & EIHD__M_MKTHREADS) | |
8160 | fprintf (file, " MKTHREADS"); | |
8161 | if (val & EIHD__M_UPCALLS) | |
8162 | fprintf (file, " UPCALLS"); | |
8163 | if (val & EIHD__M_OMV_READY) | |
8164 | fprintf (file, " OMV_READY"); | |
8165 | if (val & EIHD__M_EXT_BIND_SECT) | |
8166 | fprintf (file, " EXT_BIND_SECT"); | |
8167 | fprintf (file, "\n"); | |
695344c0 | 8168 | /* xgettext:c-format */ |
95e34ef7 | 8169 | fprintf (file, _(" ident: 0x%08x, sysver: 0x%08x, " |
07d6d2b8 AM |
8170 | "match ctrl: %u, symvect_size: %u\n"), |
8171 | (unsigned)bfd_getl32 (eihd.ident), | |
8172 | (unsigned)bfd_getl32 (eihd.sysver), | |
8173 | eihd.matchctl, | |
8174 | (unsigned)bfd_getl32 (eihd.symvect_size)); | |
95e34ef7 | 8175 | fprintf (file, _(" BPAGE: %u"), |
07d6d2b8 | 8176 | (unsigned)bfd_getl32 (eihd.virt_mem_block_size)); |
95e34ef7 TG |
8177 | if (val & (EIHD__M_OMV_READY | EIHD__M_EXT_BIND_SECT)) |
8178 | { | |
8179 | eihef_off = bfd_getl32 (eihd.ext_fixup_off); | |
8180 | eihnp_off = bfd_getl32 (eihd.noopt_psect_off); | |
695344c0 | 8181 | /* xgettext:c-format */ |
95e34ef7 | 8182 | fprintf (file, _(", ext fixup offset: %u, no_opt psect off: %u"), |
07d6d2b8 | 8183 | eihef_off, eihnp_off); |
95e34ef7 TG |
8184 | } |
8185 | fprintf (file, _(", alias: %u\n"), (unsigned)bfd_getl16 (eihd.alias)); | |
8186 | ||
8187 | if (eihvn_off != 0) | |
8188 | { | |
8189 | struct vms_eihvn eihvn; | |
8190 | unsigned int mask; | |
8191 | unsigned int j; | |
8192 | ||
8193 | fprintf (file, _("system version array information:\n")); | |
226f9f4f AM |
8194 | if (bfd_seek (abfd, eihvn_off, SEEK_SET) |
8195 | || bfd_read (&eihvn, sizeof (eihvn), abfd) != sizeof (eihvn)) | |
07d6d2b8 AM |
8196 | { |
8197 | fprintf (file, _("cannot read EIHVN header\n")); | |
8198 | return; | |
8199 | } | |
95e34ef7 TG |
8200 | mask = bfd_getl32 (eihvn.subsystem_mask); |
8201 | for (j = 0; j < 32; j++) | |
9216910e | 8202 | if (mask & (1u << j)) |
07d6d2b8 AM |
8203 | { |
8204 | struct vms_eihvn_subversion ver; | |
226f9f4f | 8205 | if (bfd_read (&ver, sizeof (ver), abfd) != sizeof (ver)) |
07d6d2b8 AM |
8206 | { |
8207 | fprintf (file, _("cannot read EIHVN version\n")); | |
8208 | return; | |
8209 | } | |
8210 | fprintf (file, _(" %02u "), j); | |
8211 | switch (j) | |
8212 | { | |
8213 | case EIHVN__BASE_IMAGE_BIT: | |
95e34ef7 | 8214 | fputs (_("BASE_IMAGE "), file); |
07d6d2b8 AM |
8215 | break; |
8216 | case EIHVN__MEMORY_MANAGEMENT_BIT: | |
8217 | fputs (_("MEMORY_MANAGEMENT"), file); | |
8218 | break; | |
8219 | case EIHVN__IO_BIT: | |
8220 | fputs (_("IO "), file); | |
8221 | break; | |
8222 | case EIHVN__FILES_VOLUMES_BIT: | |
8223 | fputs (_("FILES_VOLUMES "), file); | |
8224 | break; | |
8225 | case EIHVN__PROCESS_SCHED_BIT: | |
8226 | fputs (_("PROCESS_SCHED "), file); | |
8227 | break; | |
8228 | case EIHVN__SYSGEN_BIT: | |
95e34ef7 | 8229 | fputs (_("SYSGEN "), file); |
07d6d2b8 AM |
8230 | break; |
8231 | case EIHVN__CLUSTERS_LOCKMGR_BIT: | |
8232 | fputs (_("CLUSTERS_LOCKMGR "), file); | |
8233 | break; | |
8234 | case EIHVN__LOGICAL_NAMES_BIT: | |
8235 | fputs (_("LOGICAL_NAMES "), file); | |
8236 | break; | |
8237 | case EIHVN__SECURITY_BIT: | |
95e34ef7 | 8238 | fputs (_("SECURITY "), file); |
07d6d2b8 AM |
8239 | break; |
8240 | case EIHVN__IMAGE_ACTIVATOR_BIT: | |
8241 | fputs (_("IMAGE_ACTIVATOR "), file); | |
8242 | break; | |
8243 | case EIHVN__NETWORKS_BIT: | |
95e34ef7 | 8244 | fputs (_("NETWORKS "), file); |
07d6d2b8 AM |
8245 | break; |
8246 | case EIHVN__COUNTERS_BIT: | |
95e34ef7 | 8247 | fputs (_("COUNTERS "), file); |
07d6d2b8 AM |
8248 | break; |
8249 | case EIHVN__STABLE_BIT: | |
95e34ef7 | 8250 | fputs (_("STABLE "), file); |
07d6d2b8 AM |
8251 | break; |
8252 | case EIHVN__MISC_BIT: | |
8253 | fputs (_("MISC "), file); | |
8254 | break; | |
8255 | case EIHVN__CPU_BIT: | |
8256 | fputs (_("CPU "), file); | |
8257 | break; | |
8258 | case EIHVN__VOLATILE_BIT: | |
95e34ef7 | 8259 | fputs (_("VOLATILE "), file); |
07d6d2b8 AM |
8260 | break; |
8261 | case EIHVN__SHELL_BIT: | |
95e34ef7 | 8262 | fputs (_("SHELL "), file); |
07d6d2b8 AM |
8263 | break; |
8264 | case EIHVN__POSIX_BIT: | |
95e34ef7 | 8265 | fputs (_("POSIX "), file); |
07d6d2b8 AM |
8266 | break; |
8267 | case EIHVN__MULTI_PROCESSING_BIT: | |
8268 | fputs (_("MULTI_PROCESSING "), file); | |
8269 | break; | |
8270 | case EIHVN__GALAXY_BIT: | |
95e34ef7 | 8271 | fputs (_("GALAXY "), file); |
07d6d2b8 AM |
8272 | break; |
8273 | default: | |
8274 | fputs (_("*unknown* "), file); | |
8275 | break; | |
8276 | } | |
8277 | fprintf (file, ": %u.%u\n", | |
8278 | (unsigned)bfd_getl16 (ver.major), | |
8279 | (unsigned)bfd_getl16 (ver.minor)); | |
8280 | } | |
95e34ef7 TG |
8281 | } |
8282 | ||
8283 | if (eiha_off != 0) | |
8284 | { | |
8285 | struct vms_eiha eiha; | |
8286 | ||
226f9f4f AM |
8287 | if (bfd_seek (abfd, eiha_off, SEEK_SET) |
8288 | || bfd_read (&eiha, sizeof (eiha), abfd) != sizeof (eiha)) | |
07d6d2b8 AM |
8289 | { |
8290 | fprintf (file, _("cannot read EIHA\n")); | |
8291 | return; | |
8292 | } | |
95e34ef7 | 8293 | fprintf (file, _("Image activation: (size=%u)\n"), |
07d6d2b8 | 8294 | (unsigned)bfd_getl32 (eiha.size)); |
695344c0 | 8295 | /* xgettext:c-format */ |
95e34ef7 | 8296 | fprintf (file, _(" First address : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
8297 | (unsigned)bfd_getl32 (eiha.tfradr1_h), |
8298 | (unsigned)bfd_getl32 (eiha.tfradr1)); | |
695344c0 | 8299 | /* xgettext:c-format */ |
95e34ef7 | 8300 | fprintf (file, _(" Second address: 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
8301 | (unsigned)bfd_getl32 (eiha.tfradr2_h), |
8302 | (unsigned)bfd_getl32 (eiha.tfradr2)); | |
695344c0 | 8303 | /* xgettext:c-format */ |
95e34ef7 | 8304 | fprintf (file, _(" Third address : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
8305 | (unsigned)bfd_getl32 (eiha.tfradr3_h), |
8306 | (unsigned)bfd_getl32 (eiha.tfradr3)); | |
695344c0 | 8307 | /* xgettext:c-format */ |
95e34ef7 | 8308 | fprintf (file, _(" Fourth address: 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
8309 | (unsigned)bfd_getl32 (eiha.tfradr4_h), |
8310 | (unsigned)bfd_getl32 (eiha.tfradr4)); | |
695344c0 | 8311 | /* xgettext:c-format */ |
95e34ef7 | 8312 | fprintf (file, _(" Shared image : 0x%08x 0x%08x\n"), |
07d6d2b8 AM |
8313 | (unsigned)bfd_getl32 (eiha.inishr_h), |
8314 | (unsigned)bfd_getl32 (eiha.inishr)); | |
95e34ef7 TG |
8315 | } |
8316 | if (eihi_off != 0) | |
8317 | { | |
8318 | struct vms_eihi eihi; | |
8319 | ||
226f9f4f AM |
8320 | if (bfd_seek (abfd, eihi_off, SEEK_SET) |
8321 | || bfd_read (&eihi, sizeof (eihi), abfd) != sizeof (eihi)) | |
07d6d2b8 AM |
8322 | { |
8323 | fprintf (file, _("cannot read EIHI\n")); | |
8324 | return; | |
8325 | } | |
695344c0 | 8326 | /* xgettext:c-format */ |
95e34ef7 | 8327 | fprintf (file, _("Image identification: (major: %u, minor: %u)\n"), |
07d6d2b8 AM |
8328 | (unsigned)bfd_getl32 (eihi.majorid), |
8329 | (unsigned)bfd_getl32 (eihi.minorid)); | |
95e34ef7 | 8330 | fprintf (file, _(" image name : %.*s\n"), |
07d6d2b8 | 8331 | eihi.imgnam[0], eihi.imgnam + 1); |
95e34ef7 | 8332 | fprintf (file, _(" link time : %s\n"), |
07d6d2b8 | 8333 | vms_time_to_str (eihi.linktime)); |
95e34ef7 | 8334 | fprintf (file, _(" image ident : %.*s\n"), |
07d6d2b8 | 8335 | eihi.imgid[0], eihi.imgid + 1); |
95e34ef7 | 8336 | fprintf (file, _(" linker ident : %.*s\n"), |
07d6d2b8 | 8337 | eihi.linkid[0], eihi.linkid + 1); |
95e34ef7 | 8338 | fprintf (file, _(" image build ident: %.*s\n"), |
07d6d2b8 | 8339 | eihi.imgbid[0], eihi.imgbid + 1); |
95e34ef7 TG |
8340 | } |
8341 | if (eihs_off != 0) | |
8342 | { | |
8343 | struct vms_eihs eihs; | |
8344 | ||
226f9f4f AM |
8345 | if (bfd_seek (abfd, eihs_off, SEEK_SET) |
8346 | || bfd_read (&eihs, sizeof (eihs), abfd) != sizeof (eihs)) | |
07d6d2b8 AM |
8347 | { |
8348 | fprintf (file, _("cannot read EIHS\n")); | |
8349 | return; | |
8350 | } | |
695344c0 | 8351 | /* xgettext:c-format */ |
95e34ef7 | 8352 | fprintf (file, _("Image symbol & debug table: (major: %u, minor: %u)\n"), |
07d6d2b8 AM |
8353 | (unsigned)bfd_getl32 (eihs.majorid), |
8354 | (unsigned)bfd_getl32 (eihs.minorid)); | |
95e34ef7 TG |
8355 | dst_vbn = bfd_getl32 (eihs.dstvbn); |
8356 | dst_size = bfd_getl32 (eihs.dstsize); | |
695344c0 | 8357 | /* xgettext:c-format */ |
44273c5b | 8358 | fprintf (file, _(" debug symbol table : vbn: %u, size: %u (0x%x)\n"), |
07d6d2b8 | 8359 | dst_vbn, dst_size, dst_size); |
95e34ef7 TG |
8360 | gst_vbn = bfd_getl32 (eihs.gstvbn); |
8361 | gst_size = bfd_getl32 (eihs.gstsize); | |
695344c0 | 8362 | /* xgettext:c-format */ |
95e34ef7 | 8363 | fprintf (file, _(" global symbol table: vbn: %u, records: %u\n"), |
07d6d2b8 | 8364 | gst_vbn, gst_size); |
95e34ef7 TG |
8365 | dmt_vbn = bfd_getl32 (eihs.dmtvbn); |
8366 | dmt_size = bfd_getl32 (eihs.dmtsize); | |
695344c0 | 8367 | /* xgettext:c-format */ |
95e34ef7 | 8368 | fprintf (file, _(" debug module table : vbn: %u, size: %u\n"), |
07d6d2b8 | 8369 | dmt_vbn, dmt_size); |
95e34ef7 TG |
8370 | } |
8371 | while (eisd_off != 0) | |
8372 | { | |
8373 | struct vms_eisd eisd; | |
8374 | unsigned int len; | |
8375 | ||
8376 | while (1) | |
07d6d2b8 | 8377 | { |
226f9f4f AM |
8378 | if (bfd_seek (abfd, eisd_off, SEEK_SET) |
8379 | || bfd_read (&eisd, sizeof (eisd), abfd) != sizeof (eisd)) | |
07d6d2b8 AM |
8380 | { |
8381 | fprintf (file, _("cannot read EISD\n")); | |
8382 | return; | |
8383 | } | |
8384 | len = (unsigned)bfd_getl32 (eisd.eisdsize); | |
8385 | if (len != (unsigned)-1) | |
8386 | break; | |
8387 | ||
8388 | /* Next block. */ | |
8389 | eisd_off = (eisd_off + VMS_BLOCK_SIZE) & ~(VMS_BLOCK_SIZE - 1); | |
8390 | } | |
695344c0 | 8391 | /* xgettext:c-format */ |
95e34ef7 | 8392 | fprintf (file, _("Image section descriptor: (major: %u, minor: %u, " |
07d6d2b8 AM |
8393 | "size: %u, offset: %u)\n"), |
8394 | (unsigned)bfd_getl32 (eisd.majorid), | |
8395 | (unsigned)bfd_getl32 (eisd.minorid), | |
8396 | len, eisd_off); | |
95e34ef7 | 8397 | if (len == 0) |
07d6d2b8 | 8398 | break; |
695344c0 | 8399 | /* xgettext:c-format */ |
95e34ef7 | 8400 | fprintf (file, _(" section: base: 0x%08x%08x size: 0x%08x\n"), |
07d6d2b8 AM |
8401 | (unsigned)bfd_getl32 (eisd.virt_addr + 4), |
8402 | (unsigned)bfd_getl32 (eisd.virt_addr + 0), | |
8403 | (unsigned)bfd_getl32 (eisd.secsize)); | |
95e34ef7 TG |
8404 | val = (unsigned)bfd_getl32 (eisd.flags); |
8405 | fprintf (file, _(" flags: 0x%04x"), val); | |
8406 | if (val & EISD__M_GBL) | |
07d6d2b8 | 8407 | fprintf (file, " GBL"); |
95e34ef7 | 8408 | if (val & EISD__M_CRF) |
07d6d2b8 | 8409 | fprintf (file, " CRF"); |
95e34ef7 | 8410 | if (val & EISD__M_DZRO) |
07d6d2b8 | 8411 | fprintf (file, " DZRO"); |
95e34ef7 | 8412 | if (val & EISD__M_WRT) |
07d6d2b8 | 8413 | fprintf (file, " WRT"); |
95e34ef7 TG |
8414 | if (val & EISD__M_INITALCODE) |
8415 | fprintf (file, " INITALCODE"); | |
8416 | if (val & EISD__M_BASED) | |
07d6d2b8 | 8417 | fprintf (file, " BASED"); |
95e34ef7 TG |
8418 | if (val & EISD__M_FIXUPVEC) |
8419 | fprintf (file, " FIXUPVEC"); | |
8420 | if (val & EISD__M_RESIDENT) | |
8421 | fprintf (file, " RESIDENT"); | |
8422 | if (val & EISD__M_VECTOR) | |
07d6d2b8 | 8423 | fprintf (file, " VECTOR"); |
95e34ef7 TG |
8424 | if (val & EISD__M_PROTECT) |
8425 | fprintf (file, " PROTECT"); | |
8426 | if (val & EISD__M_LASTCLU) | |
8427 | fprintf (file, " LASTCLU"); | |
8428 | if (val & EISD__M_EXE) | |
07d6d2b8 | 8429 | fprintf (file, " EXE"); |
95e34ef7 TG |
8430 | if (val & EISD__M_NONSHRADR) |
8431 | fprintf (file, " NONSHRADR"); | |
8432 | if (val & EISD__M_QUAD_LENGTH) | |
8433 | fprintf (file, " QUAD_LENGTH"); | |
8434 | if (val & EISD__M_ALLOC_64BIT) | |
8435 | fprintf (file, " ALLOC_64BIT"); | |
8436 | fprintf (file, "\n"); | |
8437 | if (val & EISD__M_FIXUPVEC) | |
07d6d2b8 AM |
8438 | { |
8439 | eiaf_vbn = bfd_getl32 (eisd.vbn); | |
8440 | eiaf_size = bfd_getl32 (eisd.secsize); | |
8441 | } | |
695344c0 | 8442 | /* xgettext:c-format */ |
95e34ef7 | 8443 | fprintf (file, _(" vbn: %u, pfc: %u, matchctl: %u type: %u ("), |
07d6d2b8 AM |
8444 | (unsigned)bfd_getl32 (eisd.vbn), |
8445 | eisd.pfc, eisd.matchctl, eisd.type); | |
95e34ef7 | 8446 | switch (eisd.type) |
07d6d2b8 AM |
8447 | { |
8448 | case EISD__K_NORMAL: | |
8449 | fputs (_("NORMAL"), file); | |
8450 | break; | |
8451 | case EISD__K_SHRFXD: | |
8452 | fputs (_("SHRFXD"), file); | |
8453 | break; | |
8454 | case EISD__K_PRVFXD: | |
8455 | fputs (_("PRVFXD"), file); | |
8456 | break; | |
8457 | case EISD__K_SHRPIC: | |
8458 | fputs (_("SHRPIC"), file); | |
8459 | break; | |
8460 | case EISD__K_PRVPIC: | |
8461 | fputs (_("PRVPIC"), file); | |
8462 | break; | |
8463 | case EISD__K_USRSTACK: | |
8464 | fputs (_("USRSTACK"), file); | |
8465 | break; | |
8466 | default: | |
8467 | fputs (_("*unknown*"), file); | |
8468 | break; | |
8469 | } | |
95e34ef7 TG |
8470 | fputs (_(")\n"), file); |
8471 | if (val & EISD__M_GBL) | |
695344c0 | 8472 | /* xgettext:c-format */ |
07d6d2b8 AM |
8473 | fprintf (file, _(" ident: 0x%08x, name: %.*s\n"), |
8474 | (unsigned)bfd_getl32 (eisd.ident), | |
8475 | eisd.gblnam[0], eisd.gblnam + 1); | |
95e34ef7 TG |
8476 | eisd_off += len; |
8477 | } | |
8478 | ||
8479 | if (dmt_vbn != 0) | |
8480 | { | |
8481 | if (bfd_seek (abfd, (file_ptr) (dmt_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8482 | { |
8483 | fprintf (file, _("cannot read DMT\n")); | |
8484 | return; | |
8485 | } | |
95e34ef7 TG |
8486 | |
8487 | fprintf (file, _("Debug module table:\n")); | |
8488 | ||
8489 | while (dmt_size > 0) | |
07d6d2b8 AM |
8490 | { |
8491 | struct vms_dmt_header dmth; | |
8492 | unsigned int count; | |
8493 | ||
226f9f4f | 8494 | if (bfd_read (&dmth, sizeof (dmth), abfd) != sizeof (dmth)) |
07d6d2b8 AM |
8495 | { |
8496 | fprintf (file, _("cannot read DMT header\n")); | |
8497 | return; | |
8498 | } | |
8499 | count = bfd_getl16 (dmth.psect_count); | |
8500 | fprintf (file, | |
695344c0 | 8501 | /* xgettext:c-format */ |
07d6d2b8 AM |
8502 | _(" module offset: 0x%08x, size: 0x%08x, (%u psects)\n"), |
8503 | (unsigned)bfd_getl32 (dmth.modbeg), | |
8504 | (unsigned)bfd_getl32 (dmth.size), count); | |
8505 | dmt_size -= sizeof (dmth); | |
8506 | while (count > 0) | |
8507 | { | |
8508 | struct vms_dmt_psect dmtp; | |
8509 | ||
226f9f4f | 8510 | if (bfd_read (&dmtp, sizeof (dmtp), abfd) != sizeof (dmtp)) |
07d6d2b8 AM |
8511 | { |
8512 | fprintf (file, _("cannot read DMT psect\n")); | |
8513 | return; | |
8514 | } | |
695344c0 | 8515 | /* xgettext:c-format */ |
07d6d2b8 AM |
8516 | fprintf (file, _(" psect start: 0x%08x, length: %u\n"), |
8517 | (unsigned)bfd_getl32 (dmtp.start), | |
8518 | (unsigned)bfd_getl32 (dmtp.length)); | |
8519 | count--; | |
8520 | dmt_size -= sizeof (dmtp); | |
8521 | } | |
8522 | } | |
95e34ef7 TG |
8523 | } |
8524 | ||
8525 | if (dst_vbn != 0) | |
8526 | { | |
8527 | if (bfd_seek (abfd, (file_ptr) (dst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8528 | { |
8529 | fprintf (file, _("cannot read DST\n")); | |
8530 | return; | |
8531 | } | |
95e34ef7 TG |
8532 | |
8533 | evax_bfd_print_dst (abfd, dst_size, file); | |
8534 | } | |
8535 | if (gst_vbn != 0) | |
8536 | { | |
8537 | if (bfd_seek (abfd, (file_ptr) (gst_vbn - 1) * VMS_BLOCK_SIZE, SEEK_SET)) | |
07d6d2b8 AM |
8538 | { |
8539 | fprintf (file, _("cannot read GST\n")); | |
8540 | return; | |
8541 | } | |
95e34ef7 TG |
8542 | |
8543 | fprintf (file, _("Global symbol table:\n")); | |
8544 | evax_bfd_print_eobj (abfd, file); | |
8545 | } | |
b920bc37 | 8546 | if (eiaf_vbn != 0 && eiaf_size >= sizeof (struct vms_eiaf)) |
95e34ef7 TG |
8547 | { |
8548 | unsigned char *buf; | |
8549 | struct vms_eiaf *eiaf; | |
8550 | unsigned int qrelfixoff; | |
8551 | unsigned int lrelfixoff; | |
8552 | unsigned int qdotadroff; | |
8553 | unsigned int ldotadroff; | |
8554 | unsigned int shrimgcnt; | |
8555 | unsigned int shlstoff; | |
8556 | unsigned int codeadroff; | |
8557 | unsigned int lpfixoff; | |
8558 | unsigned int chgprtoff; | |
2bb3687b | 8559 | file_ptr f_off = (file_ptr) (eiaf_vbn - 1) * VMS_BLOCK_SIZE; |
95e34ef7 | 8560 | |
2bb3687b AM |
8561 | if (bfd_seek (abfd, f_off, SEEK_SET) != 0 |
8562 | || (buf = _bfd_malloc_and_read (abfd, eiaf_size, eiaf_size)) == NULL) | |
07d6d2b8 AM |
8563 | { |
8564 | fprintf (file, _("cannot read EIHA\n")); | |
07d6d2b8 AM |
8565 | return; |
8566 | } | |
95e34ef7 TG |
8567 | eiaf = (struct vms_eiaf *)buf; |
8568 | fprintf (file, | |
695344c0 | 8569 | /* xgettext:c-format */ |
07d6d2b8 AM |
8570 | _("Image activator fixup: (major: %u, minor: %u)\n"), |
8571 | (unsigned)bfd_getl32 (eiaf->majorid), | |
8572 | (unsigned)bfd_getl32 (eiaf->minorid)); | |
695344c0 | 8573 | /* xgettext:c-format */ |
95e34ef7 | 8574 | fprintf (file, _(" iaflink : 0x%08x %08x\n"), |
07d6d2b8 AM |
8575 | (unsigned)bfd_getl32 (eiaf->iaflink + 0), |
8576 | (unsigned)bfd_getl32 (eiaf->iaflink + 4)); | |
695344c0 | 8577 | /* xgettext:c-format */ |
95e34ef7 | 8578 | fprintf (file, _(" fixuplnk: 0x%08x %08x\n"), |
07d6d2b8 AM |
8579 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 0), |
8580 | (unsigned)bfd_getl32 (eiaf->fixuplnk + 4)); | |
95e34ef7 | 8581 | fprintf (file, _(" size : %u\n"), |
07d6d2b8 | 8582 | (unsigned)bfd_getl32 (eiaf->size)); |
95e34ef7 | 8583 | fprintf (file, _(" flags: 0x%08x\n"), |
07d6d2b8 | 8584 | (unsigned)bfd_getl32 (eiaf->flags)); |
95e34ef7 TG |
8585 | qrelfixoff = bfd_getl32 (eiaf->qrelfixoff); |
8586 | lrelfixoff = bfd_getl32 (eiaf->lrelfixoff); | |
695344c0 | 8587 | /* xgettext:c-format */ |
95e34ef7 | 8588 | fprintf (file, _(" qrelfixoff: %5u, lrelfixoff: %5u\n"), |
07d6d2b8 | 8589 | qrelfixoff, lrelfixoff); |
95e34ef7 TG |
8590 | qdotadroff = bfd_getl32 (eiaf->qdotadroff); |
8591 | ldotadroff = bfd_getl32 (eiaf->ldotadroff); | |
695344c0 | 8592 | /* xgettext:c-format */ |
95e34ef7 | 8593 | fprintf (file, _(" qdotadroff: %5u, ldotadroff: %5u\n"), |
07d6d2b8 | 8594 | qdotadroff, ldotadroff); |
95e34ef7 TG |
8595 | codeadroff = bfd_getl32 (eiaf->codeadroff); |
8596 | lpfixoff = bfd_getl32 (eiaf->lpfixoff); | |
695344c0 | 8597 | /* xgettext:c-format */ |
95e34ef7 | 8598 | fprintf (file, _(" codeadroff: %5u, lpfixoff : %5u\n"), |
07d6d2b8 | 8599 | codeadroff, lpfixoff); |
95e34ef7 TG |
8600 | chgprtoff = bfd_getl32 (eiaf->chgprtoff); |
8601 | fprintf (file, _(" chgprtoff : %5u\n"), chgprtoff); | |
8602 | shrimgcnt = bfd_getl32 (eiaf->shrimgcnt); | |
8603 | shlstoff = bfd_getl32 (eiaf->shlstoff); | |
695344c0 | 8604 | /* xgettext:c-format */ |
95e34ef7 | 8605 | fprintf (file, _(" shlstoff : %5u, shrimgcnt : %5u\n"), |
07d6d2b8 | 8606 | shlstoff, shrimgcnt); |
695344c0 | 8607 | /* xgettext:c-format */ |
95e34ef7 | 8608 | fprintf (file, _(" shlextra : %5u, permctx : %5u\n"), |
07d6d2b8 AM |
8609 | (unsigned)bfd_getl32 (eiaf->shlextra), |
8610 | (unsigned)bfd_getl32 (eiaf->permctx)); | |
95e34ef7 | 8611 | fprintf (file, _(" base_va : 0x%08x\n"), |
07d6d2b8 | 8612 | (unsigned)bfd_getl32 (eiaf->base_va)); |
95e34ef7 | 8613 | fprintf (file, _(" lppsbfixoff: %5u\n"), |
07d6d2b8 | 8614 | (unsigned)bfd_getl32 (eiaf->lppsbfixoff)); |
95e34ef7 TG |
8615 | |
8616 | if (shlstoff) | |
07d6d2b8 | 8617 | { |
07d6d2b8 AM |
8618 | unsigned int j; |
8619 | ||
8620 | fprintf (file, _(" Shareable images:\n")); | |
b920bc37 AM |
8621 | for (j = 0; |
8622 | j < shrimgcnt && shlstoff <= eiaf_size - sizeof (struct vms_shl); | |
8623 | j++, shlstoff += sizeof (struct vms_shl)) | |
07d6d2b8 | 8624 | { |
b920bc37 | 8625 | struct vms_shl *shl = (struct vms_shl *) (buf + shlstoff); |
07d6d2b8 | 8626 | fprintf (file, |
695344c0 | 8627 | /* xgettext:c-format */ |
07d6d2b8 AM |
8628 | _(" %u: size: %u, flags: 0x%02x, name: %.*s\n"), |
8629 | j, shl->size, shl->flags, | |
8630 | shl->imgnam[0], shl->imgnam + 1); | |
8631 | } | |
8632 | } | |
95e34ef7 | 8633 | if (qrelfixoff != 0) |
07d6d2b8 AM |
8634 | { |
8635 | fprintf (file, _(" quad-word relocation fixups:\n")); | |
b920bc37 AM |
8636 | evax_bfd_print_relocation_records (file, buf, eiaf_size, |
8637 | qrelfixoff, 8); | |
07d6d2b8 | 8638 | } |
95e34ef7 | 8639 | if (lrelfixoff != 0) |
07d6d2b8 AM |
8640 | { |
8641 | fprintf (file, _(" long-word relocation fixups:\n")); | |
b920bc37 AM |
8642 | evax_bfd_print_relocation_records (file, buf, eiaf_size, |
8643 | lrelfixoff, 4); | |
07d6d2b8 | 8644 | } |
95e34ef7 | 8645 | if (qdotadroff != 0) |
07d6d2b8 AM |
8646 | { |
8647 | fprintf (file, _(" quad-word .address reference fixups:\n")); | |
b920bc37 | 8648 | evax_bfd_print_address_fixups (file, buf, eiaf_size, qdotadroff); |
07d6d2b8 | 8649 | } |
95e34ef7 | 8650 | if (ldotadroff != 0) |
07d6d2b8 AM |
8651 | { |
8652 | fprintf (file, _(" long-word .address reference fixups:\n")); | |
b920bc37 | 8653 | evax_bfd_print_address_fixups (file, buf, eiaf_size, ldotadroff); |
07d6d2b8 | 8654 | } |
95e34ef7 | 8655 | if (codeadroff != 0) |
07d6d2b8 AM |
8656 | { |
8657 | fprintf (file, _(" Code Address Reference Fixups:\n")); | |
b920bc37 | 8658 | evax_bfd_print_reference_fixups (file, buf, eiaf_size, codeadroff); |
07d6d2b8 | 8659 | } |
95e34ef7 | 8660 | if (lpfixoff != 0) |
07d6d2b8 AM |
8661 | { |
8662 | fprintf (file, _(" Linkage Pairs Reference Fixups:\n")); | |
b920bc37 | 8663 | evax_bfd_print_reference_fixups (file, buf, eiaf_size, lpfixoff); |
07d6d2b8 | 8664 | } |
b920bc37 | 8665 | if (chgprtoff && chgprtoff <= eiaf_size - 4) |
07d6d2b8 | 8666 | { |
b920bc37 | 8667 | unsigned int count = (unsigned) bfd_getl32 (buf + chgprtoff); |
07d6d2b8 AM |
8668 | unsigned int j; |
8669 | ||
8670 | fprintf (file, _(" Change Protection (%u entries):\n"), count); | |
b920bc37 AM |
8671 | for (j = 0, chgprtoff += 4; |
8672 | j < count && chgprtoff <= eiaf_size - sizeof (struct vms_eicp); | |
8673 | j++, chgprtoff += sizeof (struct vms_eicp)) | |
07d6d2b8 | 8674 | { |
b920bc37 | 8675 | struct vms_eicp *eicp = (struct vms_eicp *) (buf + chgprtoff); |
07d6d2b8 AM |
8676 | unsigned int prot = bfd_getl32 (eicp->newprt); |
8677 | fprintf (file, | |
695344c0 | 8678 | /* xgettext:c-format */ |
07d6d2b8 | 8679 | _(" base: 0x%08x %08x, size: 0x%08x, prot: 0x%08x "), |
b920bc37 AM |
8680 | (unsigned) bfd_getl32 (eicp->baseva + 4), |
8681 | (unsigned) bfd_getl32 (eicp->baseva + 0), | |
8682 | (unsigned) bfd_getl32 (eicp->size), | |
8683 | (unsigned) bfd_getl32 (eicp->newprt)); | |
07d6d2b8 AM |
8684 | switch (prot) |
8685 | { | |
8686 | case PRT__C_NA: | |
8687 | fprintf (file, "NA"); | |
8688 | break; | |
8689 | case PRT__C_RESERVED: | |
8690 | fprintf (file, "RES"); | |
8691 | break; | |
8692 | case PRT__C_KW: | |
8693 | fprintf (file, "KW"); | |
8694 | break; | |
8695 | case PRT__C_KR: | |
8696 | fprintf (file, "KR"); | |
8697 | break; | |
8698 | case PRT__C_UW: | |
8699 | fprintf (file, "UW"); | |
8700 | break; | |
8701 | case PRT__C_EW: | |
8702 | fprintf (file, "EW"); | |
8703 | break; | |
8704 | case PRT__C_ERKW: | |
8705 | fprintf (file, "ERKW"); | |
8706 | break; | |
8707 | case PRT__C_ER: | |
8708 | fprintf (file, "ER"); | |
8709 | break; | |
8710 | case PRT__C_SW: | |
8711 | fprintf (file, "SW"); | |
8712 | break; | |
8713 | case PRT__C_SREW: | |
8714 | fprintf (file, "SREW"); | |
8715 | break; | |
8716 | case PRT__C_SRKW: | |
8717 | fprintf (file, "SRKW"); | |
8718 | break; | |
8719 | case PRT__C_SR: | |
8720 | fprintf (file, "SR"); | |
8721 | break; | |
8722 | case PRT__C_URSW: | |
8723 | fprintf (file, "URSW"); | |
8724 | break; | |
8725 | case PRT__C_UREW: | |
8726 | fprintf (file, "UREW"); | |
8727 | break; | |
8728 | case PRT__C_URKW: | |
8729 | fprintf (file, "URKW"); | |
8730 | break; | |
8731 | case PRT__C_UR: | |
8732 | fprintf (file, "UR"); | |
8733 | break; | |
8734 | default: | |
8735 | fputs ("??", file); | |
8736 | break; | |
8737 | } | |
8738 | fputc ('\n', file); | |
8739 | } | |
8740 | } | |
95e34ef7 TG |
8741 | free (buf); |
8742 | } | |
8743 | } | |
8744 | ||
0a1b45a2 | 8745 | static bool |
95e34ef7 TG |
8746 | vms_bfd_print_private_bfd_data (bfd *abfd, void *ptr) |
8747 | { | |
8748 | FILE *file = (FILE *)ptr; | |
8749 | ||
8750 | if (bfd_get_file_flags (abfd) & (EXEC_P | DYNAMIC)) | |
8751 | evax_bfd_print_image (abfd, file); | |
8752 | else | |
8753 | { | |
8754 | if (bfd_seek (abfd, 0, SEEK_SET)) | |
0a1b45a2 | 8755 | return false; |
95e34ef7 TG |
8756 | evax_bfd_print_eobj (abfd, file); |
8757 | } | |
0a1b45a2 | 8758 | return true; |
95e34ef7 TG |
8759 | } |
8760 | \f | |
8761 | /* Linking. */ | |
8762 | ||
44273c5b | 8763 | /* Slurp ETIR/EDBG/ETBT VMS object records. */ |
95e34ef7 | 8764 | |
0a1b45a2 | 8765 | static bool |
95e34ef7 TG |
8766 | alpha_vms_read_sections_content (bfd *abfd, struct bfd_link_info *info) |
8767 | { | |
8768 | asection *cur_section; | |
8769 | file_ptr cur_offset; | |
8770 | asection *dst_section; | |
8771 | file_ptr dst_offset; | |
8772 | ||
8773 | if (bfd_seek (abfd, 0, SEEK_SET) != 0) | |
0a1b45a2 | 8774 | return false; |
95e34ef7 | 8775 | |
95e34ef7 TG |
8776 | cur_section = NULL; |
8777 | cur_offset = 0; | |
8778 | ||
8779 | dst_section = PRIV (dst_section); | |
8780 | dst_offset = 0; | |
8781 | if (info) | |
8782 | { | |
8783 | if (info->strip == strip_all || info->strip == strip_debugger) | |
07d6d2b8 AM |
8784 | { |
8785 | /* Discard the DST section. */ | |
8786 | dst_offset = 0; | |
8787 | dst_section = NULL; | |
8788 | } | |
95e34ef7 | 8789 | else if (dst_section) |
07d6d2b8 AM |
8790 | { |
8791 | dst_offset = dst_section->output_offset; | |
8792 | dst_section = dst_section->output_section; | |
8793 | } | |
95e34ef7 TG |
8794 | } |
8795 | ||
8796 | while (1) | |
8797 | { | |
8798 | int type; | |
0a1b45a2 | 8799 | bool res; |
95e34ef7 TG |
8800 | |
8801 | type = _bfd_vms_get_object_record (abfd); | |
8802 | if (type < 0) | |
8803 | { | |
8804 | vms_debug2 ((2, "next_record failed\n")); | |
0a1b45a2 | 8805 | return false; |
95e34ef7 TG |
8806 | } |
8807 | switch (type) | |
07d6d2b8 AM |
8808 | { |
8809 | case EOBJ__C_ETIR: | |
8810 | PRIV (image_section) = cur_section; | |
8811 | PRIV (image_offset) = cur_offset; | |
8812 | res = _bfd_vms_slurp_etir (abfd, info); | |
8813 | cur_section = PRIV (image_section); | |
8814 | cur_offset = PRIV (image_offset); | |
8815 | break; | |
8816 | case EOBJ__C_EDBG: | |
8817 | case EOBJ__C_ETBT: | |
8818 | if (dst_section == NULL) | |
8819 | continue; | |
8820 | PRIV (image_section) = dst_section; | |
8821 | PRIV (image_offset) = dst_offset; | |
8822 | res = _bfd_vms_slurp_etir (abfd, info); | |
8823 | dst_offset = PRIV (image_offset); | |
8824 | break; | |
8825 | case EOBJ__C_EEOM: | |
0a1b45a2 | 8826 | return true; |
07d6d2b8 AM |
8827 | default: |
8828 | continue; | |
8829 | } | |
95e34ef7 | 8830 | if (!res) |
07d6d2b8 AM |
8831 | { |
8832 | vms_debug2 ((2, "slurp eobj type %d failed\n", type)); | |
0a1b45a2 | 8833 | return false; |
07d6d2b8 | 8834 | } |
95e34ef7 TG |
8835 | } |
8836 | } | |
8837 | ||
8838 | static int | |
8839 | alpha_vms_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED, | |
07d6d2b8 | 8840 | struct bfd_link_info *info ATTRIBUTE_UNUSED) |
95e34ef7 TG |
8841 | { |
8842 | return 0; | |
8843 | } | |
8844 | ||
8845 | /* Add a linkage pair fixup at address SECT + OFFSET to SHLIB. */ | |
8846 | ||
0a1b45a2 | 8847 | static bool |
95e34ef7 TG |
8848 | alpha_vms_add_fixup_lp (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8849 | { | |
8850 | struct alpha_vms_shlib_el *sl; | |
8851 | asection *sect = PRIV2 (src, image_section); | |
8852 | file_ptr offset = PRIV2 (src, image_offset); | |
96d3b80f | 8853 | bfd_vma *p; |
95e34ef7 TG |
8854 | |
8855 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8856 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
0a1b45a2 | 8857 | sl->has_fixups = true; |
96d3b80f AM |
8858 | p = VEC_APPEND (sl->lp, bfd_vma); |
8859 | if (p == NULL) | |
0a1b45a2 | 8860 | return false; |
96d3b80f | 8861 | *p = sect->output_section->vma + sect->output_offset + offset; |
5f101a3d | 8862 | sect->output_section->flags |= SEC_RELOC; |
0a1b45a2 | 8863 | return true; |
95e34ef7 TG |
8864 | } |
8865 | ||
5f101a3d TG |
8866 | /* Add a code address fixup at address SECT + OFFSET to SHLIB. */ |
8867 | ||
0a1b45a2 | 8868 | static bool |
95e34ef7 TG |
8869 | alpha_vms_add_fixup_ca (struct bfd_link_info *info, bfd *src, bfd *shlib) |
8870 | { | |
8871 | struct alpha_vms_shlib_el *sl; | |
8872 | asection *sect = PRIV2 (src, image_section); | |
8873 | file_ptr offset = PRIV2 (src, image_offset); | |
96d3b80f | 8874 | bfd_vma *p; |
95e34ef7 TG |
8875 | |
8876 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8877 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
0a1b45a2 | 8878 | sl->has_fixups = true; |
96d3b80f AM |
8879 | p = VEC_APPEND (sl->ca, bfd_vma); |
8880 | if (p == NULL) | |
0a1b45a2 | 8881 | return false; |
96d3b80f | 8882 | *p = sect->output_section->vma + sect->output_offset + offset; |
5f101a3d | 8883 | sect->output_section->flags |= SEC_RELOC; |
0a1b45a2 | 8884 | return true; |
95e34ef7 TG |
8885 | } |
8886 | ||
5f101a3d TG |
8887 | /* Add a quad word relocation fixup at address SECT + OFFSET to SHLIB. */ |
8888 | ||
0a1b45a2 | 8889 | static bool |
95e34ef7 | 8890 | alpha_vms_add_fixup_qr (struct bfd_link_info *info, bfd *src, |
07d6d2b8 | 8891 | bfd *shlib, bfd_vma vec) |
95e34ef7 TG |
8892 | { |
8893 | struct alpha_vms_shlib_el *sl; | |
8894 | struct alpha_vms_vma_ref *r; | |
8895 | asection *sect = PRIV2 (src, image_section); | |
8896 | file_ptr offset = PRIV2 (src, image_offset); | |
8897 | ||
8898 | sl = &VEC_EL (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 8899 | struct alpha_vms_shlib_el, PRIV2 (shlib, shr_index)); |
0a1b45a2 | 8900 | sl->has_fixups = true; |
95e34ef7 | 8901 | r = VEC_APPEND (sl->qr, struct alpha_vms_vma_ref); |
96d3b80f | 8902 | if (r == NULL) |
0a1b45a2 | 8903 | return false; |
95e34ef7 TG |
8904 | r->vma = sect->output_section->vma + sect->output_offset + offset; |
8905 | r->ref = vec; | |
5f101a3d | 8906 | sect->output_section->flags |= SEC_RELOC; |
0a1b45a2 | 8907 | return true; |
95e34ef7 TG |
8908 | } |
8909 | ||
0a1b45a2 | 8910 | static bool |
5369db0a | 8911 | alpha_vms_add_fixup_lr (struct bfd_link_info *info ATTRIBUTE_UNUSED, |
07d6d2b8 AM |
8912 | unsigned int shr ATTRIBUTE_UNUSED, |
8913 | bfd_vma vec ATTRIBUTE_UNUSED) | |
95e34ef7 | 8914 | { |
5f101a3d | 8915 | /* Not yet supported. */ |
0a1b45a2 | 8916 | return false; |
95e34ef7 TG |
8917 | } |
8918 | ||
5369db0a | 8919 | /* Add relocation. FIXME: Not yet emitted. */ |
95e34ef7 | 8920 | |
0a1b45a2 | 8921 | static bool |
95e34ef7 TG |
8922 | alpha_vms_add_lw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8923 | { | |
0a1b45a2 | 8924 | return false; |
95e34ef7 TG |
8925 | } |
8926 | ||
0a1b45a2 | 8927 | static bool |
95e34ef7 TG |
8928 | alpha_vms_add_qw_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED) |
8929 | { | |
0a1b45a2 | 8930 | return false; |
95e34ef7 TG |
8931 | } |
8932 | ||
8933 | static struct bfd_hash_entry * | |
8934 | alpha_vms_link_hash_newfunc (struct bfd_hash_entry *entry, | |
07d6d2b8 AM |
8935 | struct bfd_hash_table *table, |
8936 | const char *string) | |
95e34ef7 TG |
8937 | { |
8938 | struct alpha_vms_link_hash_entry *ret = | |
8939 | (struct alpha_vms_link_hash_entry *) entry; | |
8940 | ||
8941 | /* Allocate the structure if it has not already been allocated by a | |
8942 | subclass. */ | |
8943 | if (ret == NULL) | |
8944 | ret = ((struct alpha_vms_link_hash_entry *) | |
8945 | bfd_hash_allocate (table, | |
07d6d2b8 | 8946 | sizeof (struct alpha_vms_link_hash_entry))); |
95e34ef7 TG |
8947 | if (ret == NULL) |
8948 | return NULL; | |
8949 | ||
8950 | /* Call the allocation method of the superclass. */ | |
8951 | ret = ((struct alpha_vms_link_hash_entry *) | |
8952 | _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
8953 | table, string)); | |
8954 | ||
8955 | ret->sym = NULL; | |
8956 | ||
8957 | return (struct bfd_hash_entry *) ret; | |
8958 | } | |
8959 | ||
37d2e9c7 AM |
8960 | static void |
8961 | alpha_vms_bfd_link_hash_table_free (bfd *abfd) | |
8962 | { | |
8963 | struct alpha_vms_link_hash_table *t; | |
8964 | unsigned i; | |
8965 | ||
8966 | t = (struct alpha_vms_link_hash_table *) abfd->link.hash; | |
8967 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
8968 | { | |
8969 | struct alpha_vms_shlib_el *shlib; | |
8970 | ||
8971 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
8972 | free (&VEC_EL (shlib->ca, bfd_vma, 0)); | |
8973 | free (&VEC_EL (shlib->lp, bfd_vma, 0)); | |
8974 | free (&VEC_EL (shlib->qr, struct alpha_vms_vma_ref, 0)); | |
8975 | } | |
8976 | free (&VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, 0)); | |
8977 | ||
8978 | _bfd_generic_link_hash_table_free (abfd); | |
8979 | } | |
8980 | ||
95e34ef7 TG |
8981 | /* Create an Alpha/VMS link hash table. */ |
8982 | ||
8983 | static struct bfd_link_hash_table * | |
8984 | alpha_vms_bfd_link_hash_table_create (bfd *abfd) | |
8985 | { | |
8986 | struct alpha_vms_link_hash_table *ret; | |
986f0783 | 8987 | size_t amt = sizeof (struct alpha_vms_link_hash_table); |
95e34ef7 TG |
8988 | |
8989 | ret = (struct alpha_vms_link_hash_table *) bfd_malloc (amt); | |
8990 | if (ret == NULL) | |
8991 | return NULL; | |
8992 | if (!_bfd_link_hash_table_init (&ret->root, abfd, | |
8993 | alpha_vms_link_hash_newfunc, | |
8994 | sizeof (struct alpha_vms_link_hash_entry))) | |
8995 | { | |
8996 | free (ret); | |
8997 | return NULL; | |
8998 | } | |
8999 | ||
9000 | VEC_INIT (ret->shrlibs); | |
9001 | ret->fixup = NULL; | |
37d2e9c7 | 9002 | ret->root.hash_table_free = alpha_vms_bfd_link_hash_table_free; |
95e34ef7 TG |
9003 | |
9004 | return &ret->root; | |
9005 | } | |
9006 | ||
0a1b45a2 | 9007 | static bool |
95e34ef7 TG |
9008 | alpha_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) |
9009 | { | |
9010 | unsigned int i; | |
9011 | ||
9012 | for (i = 0; i < PRIV (gsd_sym_count); i++) | |
9013 | { | |
9014 | struct vms_symbol_entry *e = PRIV (syms)[i]; | |
9015 | struct alpha_vms_link_hash_entry *h; | |
11afaeda | 9016 | struct bfd_link_hash_entry *h_root; |
95e34ef7 TG |
9017 | asymbol sym; |
9018 | ||
9019 | if (!alpha_vms_convert_symbol (abfd, e, &sym)) | |
0a1b45a2 | 9020 | return false; |
95e34ef7 TG |
9021 | |
9022 | if ((e->flags & EGSY__V_DEF) && abfd->selective_search) | |
07d6d2b8 AM |
9023 | { |
9024 | /* In selective_search mode, only add definition that are | |
9025 | required. */ | |
9026 | h = (struct alpha_vms_link_hash_entry *)bfd_link_hash_lookup | |
0a1b45a2 | 9027 | (info->hash, sym.name, false, false, false); |
07d6d2b8 AM |
9028 | if (h == NULL || h->root.type != bfd_link_hash_undefined) |
9029 | continue; | |
9030 | } | |
95e34ef7 | 9031 | else |
07d6d2b8 | 9032 | h = NULL; |
95e34ef7 | 9033 | |
11afaeda | 9034 | h_root = (struct bfd_link_hash_entry *) h; |
535b785f AM |
9035 | if (!_bfd_generic_link_add_one_symbol (info, abfd, sym.name, sym.flags, |
9036 | sym.section, sym.value, NULL, | |
0a1b45a2 AM |
9037 | false, false, &h_root)) |
9038 | return false; | |
11afaeda | 9039 | h = (struct alpha_vms_link_hash_entry *) h_root; |
95e34ef7 TG |
9040 | |
9041 | if ((e->flags & EGSY__V_DEF) | |
07d6d2b8 AM |
9042 | && h->sym == NULL |
9043 | && abfd->xvec == info->output_bfd->xvec) | |
9044 | h->sym = e; | |
95e34ef7 TG |
9045 | } |
9046 | ||
9047 | if (abfd->flags & DYNAMIC) | |
9048 | { | |
9049 | struct alpha_vms_shlib_el *shlib; | |
9050 | ||
9051 | /* We do not want to include any of the sections in a dynamic | |
07d6d2b8 | 9052 | object in the output file. See comment in elflink.c. */ |
95e34ef7 TG |
9053 | bfd_section_list_clear (abfd); |
9054 | ||
9055 | shlib = VEC_APPEND (alpha_vms_link_hash (info)->shrlibs, | |
07d6d2b8 | 9056 | struct alpha_vms_shlib_el); |
96d3b80f | 9057 | if (shlib == NULL) |
0a1b45a2 | 9058 | return false; |
95e34ef7 TG |
9059 | shlib->abfd = abfd; |
9060 | VEC_INIT (shlib->ca); | |
9061 | VEC_INIT (shlib->lp); | |
9062 | VEC_INIT (shlib->qr); | |
9063 | PRIV (shr_index) = VEC_COUNT (alpha_vms_link_hash (info)->shrlibs) - 1; | |
9064 | } | |
9065 | ||
0a1b45a2 | 9066 | return true; |
95e34ef7 TG |
9067 | } |
9068 | ||
0a1b45a2 | 9069 | static bool |
95e34ef7 TG |
9070 | alpha_vms_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info) |
9071 | { | |
9072 | int pass; | |
9073 | struct bfd_link_hash_entry **pundef; | |
9074 | struct bfd_link_hash_entry **next_pundef; | |
9075 | ||
9076 | /* We only accept VMS libraries. */ | |
9077 | if (info->output_bfd->xvec != abfd->xvec) | |
9078 | { | |
9079 | bfd_set_error (bfd_error_wrong_format); | |
0a1b45a2 | 9080 | return false; |
95e34ef7 TG |
9081 | } |
9082 | ||
9083 | /* The archive_pass field in the archive itself is used to | |
9084 | initialize PASS, since we may search the same archive multiple | |
9085 | times. */ | |
9086 | pass = ++abfd->archive_pass; | |
9087 | ||
9088 | /* Look through the list of undefined symbols. */ | |
9089 | for (pundef = &info->hash->undefs; *pundef != NULL; pundef = next_pundef) | |
9090 | { | |
9091 | struct bfd_link_hash_entry *h; | |
8e57e1d1 | 9092 | symindex symidx; |
95e34ef7 TG |
9093 | bfd *element; |
9094 | bfd *orig_element; | |
9095 | ||
9096 | h = *pundef; | |
9097 | next_pundef = &(*pundef)->u.undef.next; | |
9098 | ||
9099 | /* When a symbol is defined, it is not necessarily removed from | |
9100 | the list. */ | |
9101 | if (h->type != bfd_link_hash_undefined | |
9102 | && h->type != bfd_link_hash_common) | |
9103 | { | |
9104 | /* Remove this entry from the list, for general cleanliness | |
9105 | and because we are going to look through the list again | |
9106 | if we search any more libraries. We can't remove the | |
9107 | entry if it is the tail, because that would lose any | |
9108 | entries we add to the list later on. */ | |
9109 | if (*pundef != info->hash->undefs_tail) | |
07d6d2b8 AM |
9110 | { |
9111 | *pundef = *next_pundef; | |
9112 | next_pundef = pundef; | |
9113 | } | |
95e34ef7 TG |
9114 | continue; |
9115 | } | |
9116 | ||
9117 | /* Look for this symbol in the archive hash table. */ | |
8e57e1d1 TG |
9118 | symidx = _bfd_vms_lib_find_symbol (abfd, h->root.string); |
9119 | if (symidx == BFD_NO_MORE_SYMBOLS) | |
95e34ef7 TG |
9120 | { |
9121 | /* Nothing in this slot. */ | |
9122 | continue; | |
9123 | } | |
9124 | ||
8e57e1d1 | 9125 | element = bfd_get_elt_at_index (abfd, symidx); |
95e34ef7 | 9126 | if (element == NULL) |
0a1b45a2 | 9127 | return false; |
95e34ef7 TG |
9128 | |
9129 | if (element->archive_pass == -1 || element->archive_pass == pass) | |
07d6d2b8 AM |
9130 | { |
9131 | /* Next symbol if this archive is wrong or already handled. */ | |
9132 | continue; | |
9133 | } | |
95e34ef7 TG |
9134 | |
9135 | if (! bfd_check_format (element, bfd_object)) | |
07d6d2b8 AM |
9136 | { |
9137 | element->archive_pass = -1; | |
0a1b45a2 | 9138 | return false; |
07d6d2b8 | 9139 | } |
95e34ef7 TG |
9140 | |
9141 | orig_element = element; | |
9142 | if (bfd_is_thin_archive (abfd)) | |
07d6d2b8 AM |
9143 | { |
9144 | element = _bfd_vms_lib_get_imagelib_file (element); | |
9145 | if (element == NULL || !bfd_check_format (element, bfd_object)) | |
9146 | { | |
9147 | orig_element->archive_pass = -1; | |
0a1b45a2 | 9148 | return false; |
07d6d2b8 AM |
9149 | } |
9150 | } | |
95e34ef7 TG |
9151 | |
9152 | /* Unlike the generic linker, we know that this element provides | |
9153 | a definition for an undefined symbol and we know that we want | |
9154 | to include it. We don't need to check anything. */ | |
0e144ba7 AM |
9155 | if (!(*info->callbacks |
9156 | ->add_archive_element) (info, element, h->root.string, &element)) | |
b95a0a31 | 9157 | continue; |
0e144ba7 | 9158 | if (!alpha_vms_link_add_object_symbols (element, info)) |
0a1b45a2 | 9159 | return false; |
95e34ef7 TG |
9160 | |
9161 | orig_element->archive_pass = pass; | |
9162 | } | |
9163 | ||
0a1b45a2 | 9164 | return true; |
95e34ef7 TG |
9165 | } |
9166 | ||
0a1b45a2 | 9167 | static bool |
95e34ef7 TG |
9168 | alpha_vms_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info) |
9169 | { | |
9170 | switch (bfd_get_format (abfd)) | |
9171 | { | |
9172 | case bfd_object: | |
9173 | vms_debug2 ((2, "vms_link_add_symbols for object %s\n", | |
07d6d2b8 | 9174 | abfd->filename)); |
95e34ef7 TG |
9175 | return alpha_vms_link_add_object_symbols (abfd, info); |
9176 | break; | |
9177 | case bfd_archive: | |
9178 | vms_debug2 ((2, "vms_link_add_symbols for archive %s\n", | |
07d6d2b8 | 9179 | abfd->filename)); |
95e34ef7 TG |
9180 | return alpha_vms_link_add_archive_symbols (abfd, info); |
9181 | break; | |
9182 | default: | |
9183 | bfd_set_error (bfd_error_wrong_format); | |
0a1b45a2 | 9184 | return false; |
95e34ef7 TG |
9185 | } |
9186 | } | |
9187 | ||
0a1b45a2 | 9188 | static bool |
95e34ef7 TG |
9189 | alpha_vms_build_fixups (struct bfd_link_info *info) |
9190 | { | |
9191 | struct alpha_vms_link_hash_table *t = alpha_vms_link_hash (info); | |
9192 | unsigned char *content; | |
9193 | unsigned int i; | |
9194 | unsigned int sz = 0; | |
9195 | unsigned int lp_sz = 0; | |
9196 | unsigned int ca_sz = 0; | |
9197 | unsigned int qr_sz = 0; | |
9198 | unsigned int shrimg_cnt = 0; | |
79326a5a TG |
9199 | unsigned int chgprt_num = 0; |
9200 | unsigned int chgprt_sz = 0; | |
95e34ef7 TG |
9201 | struct vms_eiaf *eiaf; |
9202 | unsigned int off; | |
9203 | asection *sec; | |
9204 | ||
9205 | /* Shared libraries. */ | |
9206 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
9207 | { | |
9208 | struct alpha_vms_shlib_el *shlib; | |
9209 | ||
9210 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
9211 | ||
9212 | if (!shlib->has_fixups) | |
07d6d2b8 | 9213 | continue; |
95e34ef7 TG |
9214 | |
9215 | shrimg_cnt++; | |
9216 | ||
9217 | if (VEC_COUNT (shlib->ca) > 0) | |
07d6d2b8 AM |
9218 | { |
9219 | /* Header + entries. */ | |
9220 | ca_sz += 8; | |
9221 | ca_sz += VEC_COUNT (shlib->ca) * 4; | |
9222 | } | |
95e34ef7 | 9223 | if (VEC_COUNT (shlib->lp) > 0) |
07d6d2b8 AM |
9224 | { |
9225 | /* Header + entries. */ | |
9226 | lp_sz += 8; | |
9227 | lp_sz += VEC_COUNT (shlib->lp) * 4; | |
9228 | } | |
95e34ef7 | 9229 | if (VEC_COUNT (shlib->qr) > 0) |
07d6d2b8 AM |
9230 | { |
9231 | /* Header + entries. */ | |
9232 | qr_sz += 8; | |
9233 | qr_sz += VEC_COUNT (shlib->qr) * 8; | |
9234 | } | |
95e34ef7 TG |
9235 | } |
9236 | /* Add markers. */ | |
9237 | if (ca_sz > 0) | |
9238 | ca_sz += 8; | |
9239 | if (lp_sz > 0) | |
9240 | lp_sz += 8; | |
9241 | if (qr_sz > 0) | |
9242 | qr_sz += 8; | |
9243 | ||
9244 | /* Finish now if there is no content. */ | |
9245 | if (ca_sz + lp_sz + qr_sz == 0) | |
0a1b45a2 | 9246 | return true; |
95e34ef7 | 9247 | |
79326a5a TG |
9248 | /* Add an eicp entry for the fixup itself. */ |
9249 | chgprt_num = 1; | |
9250 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) | |
9251 | { | |
9252 | /* This isect could be made RO or EXE after relocations are applied. */ | |
9253 | if ((sec->flags & SEC_RELOC) != 0 | |
07d6d2b8 AM |
9254 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
9255 | chgprt_num++; | |
79326a5a TG |
9256 | } |
9257 | chgprt_sz = 4 + chgprt_num * sizeof (struct vms_eicp); | |
9258 | ||
95e34ef7 TG |
9259 | /* Allocate section content (round-up size) */ |
9260 | sz = sizeof (struct vms_eiaf) + shrimg_cnt * sizeof (struct vms_shl) | |
79326a5a | 9261 | + ca_sz + lp_sz + qr_sz + chgprt_sz; |
95e34ef7 TG |
9262 | sz = (sz + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1); |
9263 | content = bfd_zalloc (info->output_bfd, sz); | |
9264 | if (content == NULL) | |
0a1b45a2 | 9265 | return false; |
95e34ef7 TG |
9266 | |
9267 | sec = alpha_vms_link_hash (info)->fixup; | |
9268 | sec->contents = content; | |
9269 | sec->size = sz; | |
9270 | ||
9271 | eiaf = (struct vms_eiaf *)content; | |
9272 | off = sizeof (struct vms_eiaf); | |
9273 | bfd_putl32 (0, eiaf->majorid); | |
9274 | bfd_putl32 (0, eiaf->minorid); | |
9275 | bfd_putl32 (0, eiaf->iaflink); | |
9276 | bfd_putl32 (0, eiaf->fixuplnk); | |
9277 | bfd_putl32 (sizeof (struct vms_eiaf), eiaf->size); | |
9278 | bfd_putl32 (0, eiaf->flags); | |
9279 | bfd_putl32 (0, eiaf->qrelfixoff); | |
9280 | bfd_putl32 (0, eiaf->lrelfixoff); | |
9281 | bfd_putl32 (0, eiaf->qdotadroff); | |
9282 | bfd_putl32 (0, eiaf->ldotadroff); | |
9283 | bfd_putl32 (0, eiaf->codeadroff); | |
9284 | bfd_putl32 (0, eiaf->lpfixoff); | |
9285 | bfd_putl32 (0, eiaf->chgprtoff); | |
9286 | bfd_putl32 (shrimg_cnt ? off : 0, eiaf->shlstoff); | |
9287 | bfd_putl32 (shrimg_cnt, eiaf->shrimgcnt); | |
9288 | bfd_putl32 (0, eiaf->shlextra); | |
9289 | bfd_putl32 (0, eiaf->permctx); | |
9290 | bfd_putl32 (0, eiaf->base_va); | |
9291 | bfd_putl32 (0, eiaf->lppsbfixoff); | |
9292 | ||
9293 | if (shrimg_cnt) | |
9294 | { | |
9295 | shrimg_cnt = 0; | |
9296 | ||
9297 | /* Write shl. */ | |
9298 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) | |
07d6d2b8 AM |
9299 | { |
9300 | struct alpha_vms_shlib_el *shlib; | |
9301 | struct vms_shl *shl; | |
9302 | ||
9303 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); | |
9304 | ||
9305 | if (!shlib->has_fixups) | |
9306 | continue; | |
9307 | ||
9308 | /* Renumber shared images. */ | |
9309 | PRIV2 (shlib->abfd, shr_index) = shrimg_cnt++; | |
9310 | ||
9311 | shl = (struct vms_shl *)(content + off); | |
9312 | bfd_putl32 (0, shl->baseva); | |
9313 | bfd_putl32 (0, shl->shlptr); | |
9314 | bfd_putl32 (0, shl->ident); | |
9315 | bfd_putl32 (0, shl->permctx); | |
9316 | shl->size = sizeof (struct vms_shl); | |
9317 | bfd_putl16 (0, shl->fill_1); | |
9318 | shl->flags = 0; | |
9319 | bfd_putl32 (0, shl->icb); | |
9320 | shl->imgnam[0] = strlen (PRIV2 (shlib->abfd, hdr_data.hdr_t_name)); | |
9321 | memcpy (shl->imgnam + 1, PRIV2 (shlib->abfd, hdr_data.hdr_t_name), | |
9322 | shl->imgnam[0]); | |
9323 | ||
9324 | off += sizeof (struct vms_shl); | |
9325 | } | |
95e34ef7 TG |
9326 | |
9327 | /* CA fixups. */ | |
9328 | if (ca_sz != 0) | |
07d6d2b8 AM |
9329 | { |
9330 | bfd_putl32 (off, eiaf->codeadroff); | |
95e34ef7 | 9331 | |
07d6d2b8 AM |
9332 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9333 | { | |
9334 | struct alpha_vms_shlib_el *shlib; | |
9335 | unsigned int j; | |
95e34ef7 | 9336 | |
07d6d2b8 | 9337 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 9338 | |
07d6d2b8 AM |
9339 | if (VEC_COUNT (shlib->ca) == 0) |
9340 | continue; | |
95e34ef7 | 9341 | |
07d6d2b8 AM |
9342 | bfd_putl32 (VEC_COUNT (shlib->ca), content + off); |
9343 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
9344 | off += 8; | |
95e34ef7 | 9345 | |
07d6d2b8 AM |
9346 | for (j = 0; j < VEC_COUNT (shlib->ca); j++) |
9347 | { | |
9348 | bfd_putl32 (VEC_EL (shlib->ca, bfd_vma, j) - t->base_addr, | |
9349 | content + off); | |
9350 | off += 4; | |
9351 | } | |
9352 | } | |
95e34ef7 | 9353 | |
07d6d2b8 AM |
9354 | bfd_putl32 (0, content + off); |
9355 | bfd_putl32 (0, content + off + 4); | |
9356 | off += 8; | |
9357 | } | |
95e34ef7 TG |
9358 | |
9359 | /* LP fixups. */ | |
9360 | if (lp_sz != 0) | |
07d6d2b8 AM |
9361 | { |
9362 | bfd_putl32 (off, eiaf->lpfixoff); | |
95e34ef7 | 9363 | |
07d6d2b8 AM |
9364 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9365 | { | |
9366 | struct alpha_vms_shlib_el *shlib; | |
9367 | unsigned int j; | |
95e34ef7 | 9368 | |
07d6d2b8 | 9369 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 9370 | |
07d6d2b8 AM |
9371 | if (VEC_COUNT (shlib->lp) == 0) |
9372 | continue; | |
95e34ef7 | 9373 | |
07d6d2b8 AM |
9374 | bfd_putl32 (VEC_COUNT (shlib->lp), content + off); |
9375 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
9376 | off += 8; | |
95e34ef7 | 9377 | |
07d6d2b8 AM |
9378 | for (j = 0; j < VEC_COUNT (shlib->lp); j++) |
9379 | { | |
9380 | bfd_putl32 (VEC_EL (shlib->lp, bfd_vma, j) - t->base_addr, | |
9381 | content + off); | |
9382 | off += 4; | |
9383 | } | |
9384 | } | |
95e34ef7 | 9385 | |
07d6d2b8 AM |
9386 | bfd_putl32 (0, content + off); |
9387 | bfd_putl32 (0, content + off + 4); | |
9388 | off += 8; | |
9389 | } | |
95e34ef7 TG |
9390 | |
9391 | /* QR fixups. */ | |
9392 | if (qr_sz != 0) | |
07d6d2b8 AM |
9393 | { |
9394 | bfd_putl32 (off, eiaf->qdotadroff); | |
95e34ef7 | 9395 | |
07d6d2b8 AM |
9396 | for (i = 0; i < VEC_COUNT (t->shrlibs); i++) |
9397 | { | |
9398 | struct alpha_vms_shlib_el *shlib; | |
9399 | unsigned int j; | |
95e34ef7 | 9400 | |
07d6d2b8 | 9401 | shlib = &VEC_EL (t->shrlibs, struct alpha_vms_shlib_el, i); |
95e34ef7 | 9402 | |
07d6d2b8 AM |
9403 | if (VEC_COUNT (shlib->qr) == 0) |
9404 | continue; | |
95e34ef7 | 9405 | |
07d6d2b8 AM |
9406 | bfd_putl32 (VEC_COUNT (shlib->qr), content + off); |
9407 | bfd_putl32 (PRIV2 (shlib->abfd, shr_index), content + off + 4); | |
9408 | off += 8; | |
95e34ef7 | 9409 | |
07d6d2b8 AM |
9410 | for (j = 0; j < VEC_COUNT (shlib->qr); j++) |
9411 | { | |
9412 | struct alpha_vms_vma_ref *r; | |
9413 | r = &VEC_EL (shlib->qr, struct alpha_vms_vma_ref, j); | |
9414 | bfd_putl32 (r->vma - t->base_addr, content + off); | |
9415 | bfd_putl32 (r->ref, content + off + 4); | |
9416 | off += 8; | |
9417 | } | |
9418 | } | |
95e34ef7 | 9419 | |
07d6d2b8 AM |
9420 | bfd_putl32 (0, content + off); |
9421 | bfd_putl32 (0, content + off + 4); | |
9422 | off += 8; | |
9423 | } | |
95e34ef7 TG |
9424 | } |
9425 | ||
79326a5a TG |
9426 | /* Write the change protection table. */ |
9427 | bfd_putl32 (off, eiaf->chgprtoff); | |
9428 | bfd_putl32 (chgprt_num, content + off); | |
9429 | off += 4; | |
9430 | ||
9431 | for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next) | |
9432 | { | |
9433 | struct vms_eicp *eicp; | |
9434 | unsigned int prot; | |
9435 | ||
9436 | if ((sec->flags & SEC_LINKER_CREATED) != 0 && | |
07d6d2b8 AM |
9437 | strcmp (sec->name, "$FIXUP$") == 0) |
9438 | prot = PRT__C_UREW; | |
79326a5a | 9439 | else if ((sec->flags & SEC_RELOC) != 0 |
07d6d2b8 AM |
9440 | && (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) |
9441 | prot = PRT__C_UR; | |
79326a5a | 9442 | else |
07d6d2b8 | 9443 | continue; |
79326a5a TG |
9444 | |
9445 | eicp = (struct vms_eicp *)(content + off); | |
9446 | bfd_putl64 (sec->vma - t->base_addr, eicp->baseva); | |
9447 | bfd_putl32 ((sec->size + VMS_BLOCK_SIZE - 1) & ~(VMS_BLOCK_SIZE - 1), | |
07d6d2b8 | 9448 | eicp->size); |
79326a5a TG |
9449 | bfd_putl32 (prot, eicp->newprt); |
9450 | off += sizeof (struct vms_eicp); | |
9451 | } | |
9452 | ||
0a1b45a2 | 9453 | return true; |
95e34ef7 TG |
9454 | } |
9455 | ||
7686d77d | 9456 | /* Called by bfd_hash_traverse to fill the symbol table. |
f9eeb9c9 TG |
9457 | Return FALSE in case of failure. */ |
9458 | ||
0a1b45a2 | 9459 | static bool |
7686d77d | 9460 | alpha_vms_link_output_symbol (struct bfd_hash_entry *bh, void *infov) |
f9eeb9c9 | 9461 | { |
7686d77d | 9462 | struct bfd_link_hash_entry *hc = (struct bfd_link_hash_entry *) bh; |
f9eeb9c9 | 9463 | struct bfd_link_info *info = (struct bfd_link_info *)infov; |
7686d77d | 9464 | struct alpha_vms_link_hash_entry *h; |
f9eeb9c9 TG |
9465 | struct vms_symbol_entry *sym; |
9466 | ||
7686d77d AM |
9467 | if (hc->type == bfd_link_hash_warning) |
9468 | { | |
9469 | hc = hc->u.i.link; | |
9470 | if (hc->type == bfd_link_hash_new) | |
0a1b45a2 | 9471 | return true; |
7686d77d AM |
9472 | } |
9473 | h = (struct alpha_vms_link_hash_entry *) hc; | |
9474 | ||
f9eeb9c9 TG |
9475 | switch (h->root.type) |
9476 | { | |
f9eeb9c9 | 9477 | case bfd_link_hash_undefined: |
0a1b45a2 | 9478 | return true; |
8185f55c | 9479 | case bfd_link_hash_new: |
7686d77d | 9480 | case bfd_link_hash_warning: |
f9eeb9c9 TG |
9481 | abort (); |
9482 | case bfd_link_hash_undefweak: | |
0a1b45a2 | 9483 | return true; |
f9eeb9c9 TG |
9484 | case bfd_link_hash_defined: |
9485 | case bfd_link_hash_defweak: | |
9486 | { | |
07d6d2b8 | 9487 | asection *sec = h->root.u.def.section; |
f9eeb9c9 | 9488 | |
07d6d2b8 AM |
9489 | /* FIXME: this is certainly a symbol from a dynamic library. */ |
9490 | if (bfd_is_abs_section (sec)) | |
0a1b45a2 | 9491 | return true; |
f9eeb9c9 | 9492 | |
07d6d2b8 | 9493 | if (sec->owner->flags & DYNAMIC) |
0a1b45a2 | 9494 | return true; |
f9eeb9c9 TG |
9495 | } |
9496 | break; | |
9497 | case bfd_link_hash_common: | |
9498 | break; | |
9499 | case bfd_link_hash_indirect: | |
0a1b45a2 | 9500 | return true; |
f9eeb9c9 TG |
9501 | } |
9502 | ||
9503 | /* Do not write not kept symbols. */ | |
9504 | if (info->strip == strip_some | |
9505 | && bfd_hash_lookup (info->keep_hash, h->root.root.string, | |
0a1b45a2 AM |
9506 | false, false) != NULL) |
9507 | return true; | |
f9eeb9c9 TG |
9508 | |
9509 | if (h->sym == NULL) | |
9510 | { | |
9511 | /* This symbol doesn't come from a VMS object. So we suppose it is | |
07d6d2b8 | 9512 | a data. */ |
f9eeb9c9 TG |
9513 | int len = strlen (h->root.root.string); |
9514 | ||
9515 | sym = (struct vms_symbol_entry *)bfd_zalloc (info->output_bfd, | |
07d6d2b8 | 9516 | sizeof (*sym) + len); |
f9eeb9c9 | 9517 | if (sym == NULL) |
07d6d2b8 | 9518 | abort (); |
f9eeb9c9 TG |
9519 | sym->namelen = len; |
9520 | memcpy (sym->name, h->root.root.string, len); | |
9521 | sym->name[len] = 0; | |
9522 | sym->owner = info->output_bfd; | |
9523 | ||
9524 | sym->typ = EGSD__C_SYMG; | |
9525 | sym->data_type = 0; | |
9526 | sym->flags = EGSY__V_DEF | EGSY__V_REL; | |
9527 | sym->symbol_vector = h->root.u.def.value; | |
9528 | sym->section = h->root.u.def.section; | |
9529 | sym->value = h->root.u.def.value; | |
9530 | } | |
9531 | else | |
9532 | sym = h->sym; | |
9533 | ||
9534 | if (!add_symbol_entry (info->output_bfd, sym)) | |
0a1b45a2 | 9535 | return false; |
f9eeb9c9 | 9536 | |
0a1b45a2 | 9537 | return true; |
f9eeb9c9 TG |
9538 | } |
9539 | ||
0a1b45a2 | 9540 | static bool |
95e34ef7 TG |
9541 | alpha_vms_bfd_final_link (bfd *abfd, struct bfd_link_info *info) |
9542 | { | |
9543 | asection *o; | |
9544 | struct bfd_link_order *p; | |
9545 | bfd *sub; | |
9546 | asection *fixupsec; | |
9547 | bfd_vma base_addr; | |
9548 | bfd_vma last_addr; | |
44273c5b | 9549 | asection *dst; |
fa23f0f4 | 9550 | asection *dmt; |
95e34ef7 | 9551 | |
0e1862bb | 9552 | if (bfd_link_relocatable (info)) |
79326a5a TG |
9553 | { |
9554 | /* FIXME: we do not yet support relocatable link. It is not obvious | |
07d6d2b8 | 9555 | how to do it for debug infos. */ |
79326a5a | 9556 | (*info->callbacks->einfo)(_("%P: relocatable link is not supported\n")); |
0a1b45a2 | 9557 | return false; |
79326a5a TG |
9558 | } |
9559 | ||
ed48ec2e AM |
9560 | abfd->outsymbols = NULL; |
9561 | abfd->symcount = 0; | |
95e34ef7 TG |
9562 | |
9563 | /* Mark all sections which will be included in the output file. */ | |
9564 | for (o = abfd->sections; o != NULL; o = o->next) | |
9565 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9566 | if (p->type == bfd_indirect_link_order) | |
0a1b45a2 | 9567 | p->u.indirect.section->linker_mark = true; |
95e34ef7 TG |
9568 | |
9569 | #if 0 | |
9570 | /* Handle all the link order information for the sections. */ | |
9571 | for (o = abfd->sections; o != NULL; o = o->next) | |
9572 | { | |
9573 | printf ("For section %s (at 0x%08x, flags=0x%08x):\n", | |
07d6d2b8 | 9574 | o->name, (unsigned)o->vma, (unsigned)o->flags); |
95e34ef7 TG |
9575 | |
9576 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9577 | { | |
07d6d2b8 AM |
9578 | printf (" at 0x%08x - 0x%08x: ", |
9579 | (unsigned)p->offset, (unsigned)(p->offset + p->size - 1)); | |
95e34ef7 TG |
9580 | switch (p->type) |
9581 | { | |
9582 | case bfd_section_reloc_link_order: | |
9583 | case bfd_symbol_reloc_link_order: | |
07d6d2b8 | 9584 | printf (" section/symbol reloc\n"); |
95e34ef7 TG |
9585 | break; |
9586 | case bfd_indirect_link_order: | |
07d6d2b8 AM |
9587 | printf (" section %s of %s\n", |
9588 | p->u.indirect.section->name, | |
9589 | p->u.indirect.section->owner->filename); | |
9590 | break; | |
9591 | case bfd_data_link_order: | |
9592 | printf (" explicit data\n"); | |
95e34ef7 | 9593 | break; |
95e34ef7 | 9594 | default: |
07d6d2b8 | 9595 | printf (" *unknown* type %u\n", p->type); |
95e34ef7 TG |
9596 | break; |
9597 | } | |
9598 | } | |
9599 | } | |
9600 | #endif | |
9601 | ||
f9eeb9c9 TG |
9602 | /* Generate the symbol table. */ |
9603 | BFD_ASSERT (PRIV (syms) == NULL); | |
9604 | if (info->strip != strip_all) | |
7686d77d | 9605 | bfd_hash_traverse (&info->hash->table, alpha_vms_link_output_symbol, info); |
f9eeb9c9 | 9606 | |
44273c5b | 9607 | /* Find the entry point. */ |
95e34ef7 TG |
9608 | if (bfd_get_start_address (abfd) == 0) |
9609 | { | |
9610 | bfd *startbfd = NULL; | |
9611 | ||
c72f2fb2 | 9612 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
07d6d2b8 AM |
9613 | { |
9614 | /* Consider only VMS object files. */ | |
9615 | if (sub->xvec != abfd->xvec) | |
9616 | continue; | |
9617 | ||
9618 | if (!PRIV2 (sub, eom_data).eom_has_transfer) | |
9619 | continue; | |
9620 | if ((PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR) && startbfd) | |
9621 | continue; | |
9622 | if (startbfd != NULL | |
9623 | && !(PRIV2 (sub, eom_data).eom_b_tfrflg & EEOM__M_WKTFR)) | |
9624 | { | |
9625 | (*info->callbacks->einfo) | |
695344c0 | 9626 | /* xgettext:c-format */ |
871b3ab2 | 9627 | (_("%P: multiple entry points: in modules %pB and %pB\n"), |
07d6d2b8 AM |
9628 | startbfd, sub); |
9629 | continue; | |
9630 | } | |
9631 | startbfd = sub; | |
9632 | } | |
95e34ef7 TG |
9633 | |
9634 | if (startbfd) | |
07d6d2b8 AM |
9635 | { |
9636 | unsigned int ps_idx = PRIV2 (startbfd, eom_data).eom_l_psindx; | |
9637 | bfd_vma tfradr = PRIV2 (startbfd, eom_data).eom_l_tfradr; | |
9638 | asection *sec; | |
95e34ef7 | 9639 | |
07d6d2b8 | 9640 | sec = PRIV2 (startbfd, sections)[ps_idx]; |
95e34ef7 | 9641 | |
07d6d2b8 AM |
9642 | bfd_set_start_address |
9643 | (abfd, sec->output_section->vma + sec->output_offset + tfradr); | |
9644 | } | |
95e34ef7 TG |
9645 | } |
9646 | ||
46d00b8a TG |
9647 | /* Set transfer addresses. */ |
9648 | { | |
9649 | int i; | |
9650 | struct bfd_link_hash_entry *h; | |
9651 | ||
9652 | i = 0; | |
d0ef7741 | 9653 | PRIV (transfer_address[i++]) = 0xffffffff00000340ULL; /* SYS$IMGACT */ |
0a1b45a2 | 9654 | h = bfd_link_hash_lookup (info->hash, "LIB$INITIALIZE", false, false, true); |
46d00b8a TG |
9655 | if (h != NULL && h->type == bfd_link_hash_defined) |
9656 | PRIV (transfer_address[i++]) = | |
07d6d2b8 | 9657 | alpha_vms_get_sym_value (h->u.def.section, h->u.def.value); |
46d00b8a TG |
9658 | PRIV (transfer_address[i++]) = bfd_get_start_address (abfd); |
9659 | while (i < 4) | |
9660 | PRIV (transfer_address[i++]) = 0; | |
9661 | } | |
9662 | ||
79326a5a TG |
9663 | /* Allocate contents. |
9664 | Also compute the virtual base address. */ | |
95e34ef7 TG |
9665 | base_addr = (bfd_vma)-1; |
9666 | last_addr = 0; | |
9667 | for (o = abfd->sections; o != NULL; o = o->next) | |
9668 | { | |
9669 | if (o->flags & SEC_HAS_CONTENTS) | |
07d6d2b8 AM |
9670 | { |
9671 | o->contents = bfd_alloc (abfd, o->size); | |
9672 | if (o->contents == NULL) | |
0a1b45a2 | 9673 | return false; |
07d6d2b8 | 9674 | } |
95e34ef7 | 9675 | if (o->flags & SEC_LOAD) |
07d6d2b8 AM |
9676 | { |
9677 | if (o->vma < base_addr) | |
9678 | base_addr = o->vma; | |
9679 | if (o->vma + o->size > last_addr) | |
9680 | last_addr = o->vma + o->size; | |
9681 | } | |
79326a5a | 9682 | /* Clear the RELOC flags. Currently we don't support incremental |
07d6d2b8 | 9683 | linking. We use the RELOC flag for computing the eicp entries. */ |
79326a5a | 9684 | o->flags &= ~SEC_RELOC; |
95e34ef7 TG |
9685 | } |
9686 | ||
44273c5b | 9687 | /* Create the fixup section. */ |
95e34ef7 TG |
9688 | fixupsec = bfd_make_section_anyway_with_flags |
9689 | (info->output_bfd, "$FIXUP$", | |
9690 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); | |
9691 | if (fixupsec == NULL) | |
0a1b45a2 | 9692 | return false; |
95e34ef7 TG |
9693 | last_addr = (last_addr + 0xffff) & ~0xffff; |
9694 | fixupsec->vma = last_addr; | |
9695 | ||
9696 | alpha_vms_link_hash (info)->fixup = fixupsec; | |
9697 | alpha_vms_link_hash (info)->base_addr = base_addr; | |
9698 | ||
fa23f0f4 | 9699 | /* Create the DMT section, if necessary. */ |
f9eeb9c9 TG |
9700 | BFD_ASSERT (PRIV (dst_section) == NULL); |
9701 | dst = bfd_get_section_by_name (abfd, "$DST$"); | |
fa23f0f4 TG |
9702 | if (dst != NULL && dst->size == 0) |
9703 | dst = NULL; | |
9704 | if (dst != NULL) | |
9705 | { | |
f9eeb9c9 | 9706 | PRIV (dst_section) = dst; |
fa23f0f4 | 9707 | dmt = bfd_make_section_anyway_with_flags |
07d6d2b8 AM |
9708 | (info->output_bfd, "$DMT$", |
9709 | SEC_DEBUGGING | SEC_HAS_CONTENTS | SEC_LINKER_CREATED); | |
fa23f0f4 | 9710 | if (dmt == NULL) |
0a1b45a2 | 9711 | return false; |
fa23f0f4 TG |
9712 | } |
9713 | else | |
9714 | dmt = NULL; | |
9715 | ||
95e34ef7 | 9716 | /* Read all sections from the inputs. */ |
c72f2fb2 | 9717 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
95e34ef7 TG |
9718 | { |
9719 | if (sub->flags & DYNAMIC) | |
07d6d2b8 AM |
9720 | { |
9721 | alpha_vms_create_eisd_for_shared (abfd, sub); | |
9722 | continue; | |
9723 | } | |
95e34ef7 TG |
9724 | |
9725 | if (!alpha_vms_read_sections_content (sub, info)) | |
0a1b45a2 | 9726 | return false; |
95e34ef7 TG |
9727 | } |
9728 | ||
fa23f0f4 TG |
9729 | /* Handle all the link order information for the sections. |
9730 | Note: past this point, it is not possible to create new sections. */ | |
95e34ef7 TG |
9731 | for (o = abfd->sections; o != NULL; o = o->next) |
9732 | { | |
9733 | for (p = o->map_head.link_order; p != NULL; p = p->next) | |
9734 | { | |
9735 | switch (p->type) | |
9736 | { | |
9737 | case bfd_section_reloc_link_order: | |
9738 | case bfd_symbol_reloc_link_order: | |
07d6d2b8 | 9739 | abort (); |
0a1b45a2 | 9740 | return false; |
95e34ef7 | 9741 | case bfd_indirect_link_order: |
07d6d2b8 | 9742 | /* Already done. */ |
95e34ef7 TG |
9743 | break; |
9744 | default: | |
9745 | if (! _bfd_default_link_order (abfd, info, o, p)) | |
0a1b45a2 | 9746 | return false; |
95e34ef7 TG |
9747 | break; |
9748 | } | |
9749 | } | |
9750 | } | |
9751 | ||
9752 | /* Compute fixups. */ | |
9753 | if (!alpha_vms_build_fixups (info)) | |
0a1b45a2 | 9754 | return false; |
95e34ef7 | 9755 | |
44273c5b | 9756 | /* Compute the DMT. */ |
fa23f0f4 | 9757 | if (dmt != NULL) |
44273c5b | 9758 | { |
44273c5b TG |
9759 | int pass; |
9760 | unsigned char *contents = NULL; | |
9761 | ||
44273c5b TG |
9762 | /* In pass 1, compute the size. In pass 2, write the DMT contents. */ |
9763 | for (pass = 0; pass < 2; pass++) | |
07d6d2b8 AM |
9764 | { |
9765 | unsigned int off = 0; | |
9766 | ||
9767 | /* For each object file (ie for each module). */ | |
9768 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) | |
9769 | { | |
9770 | asection *sub_dst; | |
9771 | struct vms_dmt_header *dmth = NULL; | |
9772 | unsigned int psect_count; | |
9773 | ||
9774 | /* Skip this module if it has no DST. */ | |
9775 | sub_dst = PRIV2 (sub, dst_section); | |
9776 | if (sub_dst == NULL || sub_dst->size == 0) | |
9777 | continue; | |
9778 | ||
9779 | if (pass == 1) | |
9780 | { | |
9781 | /* Write the header. */ | |
9782 | dmth = (struct vms_dmt_header *)(contents + off); | |
9783 | bfd_putl32 (sub_dst->output_offset, dmth->modbeg); | |
9784 | bfd_putl32 (sub_dst->size, dmth->size); | |
9785 | } | |
9786 | ||
9787 | off += sizeof (struct vms_dmt_header); | |
9788 | psect_count = 0; | |
9789 | ||
9790 | /* For each section (ie for each psect). */ | |
9791 | for (o = sub->sections; o != NULL; o = o->next) | |
9792 | { | |
9793 | /* Only consider interesting sections. */ | |
9794 | if (!(o->flags & SEC_ALLOC)) | |
9795 | continue; | |
9796 | if (o->flags & SEC_LINKER_CREATED) | |
9797 | continue; | |
9798 | ||
9799 | if (pass == 1) | |
9800 | { | |
9801 | /* Write an entry. */ | |
9802 | struct vms_dmt_psect *dmtp; | |
9803 | ||
9804 | dmtp = (struct vms_dmt_psect *)(contents + off); | |
9805 | bfd_putl32 (o->output_offset + o->output_section->vma, | |
9806 | dmtp->start); | |
9807 | bfd_putl32 (o->size, dmtp->length); | |
9808 | psect_count++; | |
9809 | } | |
9810 | off += sizeof (struct vms_dmt_psect); | |
9811 | } | |
9812 | if (pass == 1) | |
9813 | bfd_putl32 (psect_count, dmth->psect_count); | |
9814 | } | |
9815 | ||
9816 | if (pass == 0) | |
9817 | { | |
9818 | contents = bfd_zalloc (info->output_bfd, off); | |
9819 | if (contents == NULL) | |
0a1b45a2 | 9820 | return false; |
07d6d2b8 AM |
9821 | dmt->contents = contents; |
9822 | dmt->size = off; | |
9823 | } | |
9824 | else | |
9825 | { | |
9826 | BFD_ASSERT (off == dmt->size); | |
9827 | } | |
9828 | } | |
44273c5b TG |
9829 | } |
9830 | ||
0a1b45a2 | 9831 | return true; |
95e34ef7 TG |
9832 | } |
9833 | ||
9834 | /* Read the contents of a section. | |
9835 | buf points to a buffer of buf_size bytes to be filled with | |
9836 | section data (starting at offset into section) */ | |
9837 | ||
0a1b45a2 | 9838 | static bool |
95e34ef7 | 9839 | alpha_vms_get_section_contents (bfd *abfd, asection *section, |
07d6d2b8 AM |
9840 | void *buf, file_ptr offset, |
9841 | bfd_size_type count) | |
95e34ef7 | 9842 | { |
ee19a472 AM |
9843 | /* Handle image sections. */ |
9844 | if (section->filepos != 0 | |
9845 | || (section->flags & SEC_HAS_CONTENTS) == 0) | |
95e34ef7 | 9846 | return _bfd_generic_get_section_contents (abfd, section, |
07d6d2b8 | 9847 | buf, offset, count); |
95e34ef7 | 9848 | |
ee19a472 AM |
9849 | /* A section with a zero filepos implies the section has no direct |
9850 | file backing. Its contents must be calculated by processing ETIR | |
9851 | records. */ | |
9852 | ||
95e34ef7 TG |
9853 | /* Safety check. */ |
9854 | if (offset + count < count | |
9855 | || offset + count > section->size) | |
9856 | { | |
9857 | bfd_set_error (bfd_error_invalid_operation); | |
0a1b45a2 | 9858 | return false; |
95e34ef7 TG |
9859 | } |
9860 | ||
8185f55c | 9861 | if (section->size == 0) |
0a1b45a2 | 9862 | return true; |
95e34ef7 | 9863 | |
ee19a472 AM |
9864 | /* If we haven't yet read ETIR/EDBG/ETBT records, do so. */ |
9865 | if ((section->flags & SEC_IN_MEMORY) == 0) | |
95e34ef7 | 9866 | { |
ee19a472 AM |
9867 | /* Alloc memory and read ETIRs. */ |
9868 | for (asection *sec = abfd->sections; sec; sec = sec->next) | |
07d6d2b8 | 9869 | { |
ee19a472 AM |
9870 | if (sec->size != 0 |
9871 | && sec->filepos == 0 | |
9872 | && (sec->flags & SEC_HAS_CONTENTS) != 0) | |
9873 | { | |
9874 | BFD_ASSERT (sec->contents == NULL); | |
9875 | ||
9876 | sec->contents = bfd_zalloc (abfd, sec->size); | |
9877 | sec->flags |= SEC_IN_MEMORY; | |
9878 | if (sec->contents == NULL) | |
9879 | return false; | |
9880 | } | |
07d6d2b8 | 9881 | } |
ee19a472 AM |
9882 | if (!alpha_vms_read_sections_content (abfd, NULL)) |
9883 | return false; | |
95e34ef7 | 9884 | } |
ee19a472 AM |
9885 | |
9886 | BFD_ASSERT (section->contents != NULL); | |
95e34ef7 | 9887 | memcpy (buf, section->contents + offset, count); |
0a1b45a2 | 9888 | return true; |
95e34ef7 TG |
9889 | } |
9890 | ||
9891 | ||
9892 | /* Set the format of a file being written. */ | |
9893 | ||
0a1b45a2 | 9894 | static bool |
95e34ef7 TG |
9895 | alpha_vms_mkobject (bfd * abfd) |
9896 | { | |
9897 | const bfd_arch_info_type *arch; | |
9898 | ||
9899 | vms_debug2 ((1, "alpha_vms_mkobject (%p)\n", abfd)); | |
9900 | ||
9901 | if (!vms_initialize (abfd)) | |
0a1b45a2 | 9902 | return false; |
95e34ef7 TG |
9903 | |
9904 | PRIV (recwr.buf) = bfd_alloc (abfd, MAX_OUTREC_SIZE); | |
9905 | if (PRIV (recwr.buf) == NULL) | |
0a1b45a2 | 9906 | return false; |
95e34ef7 TG |
9907 | |
9908 | arch = bfd_scan_arch ("alpha"); | |
9909 | ||
9910 | if (arch == 0) | |
9911 | { | |
9912 | bfd_set_error (bfd_error_wrong_format); | |
0a1b45a2 | 9913 | return false; |
95e34ef7 TG |
9914 | } |
9915 | ||
9916 | abfd->arch_info = arch; | |
0a1b45a2 | 9917 | return true; |
95e34ef7 TG |
9918 | } |
9919 | ||
9920 | ||
9921 | /* 4.1, generic. */ | |
9922 | ||
9923 | /* Called when the BFD is being closed to do any necessary cleanup. */ | |
9924 | ||
0a1b45a2 | 9925 | static bool |
95e34ef7 TG |
9926 | vms_close_and_cleanup (bfd * abfd) |
9927 | { | |
9928 | vms_debug2 ((1, "vms_close_and_cleanup (%p)\n", abfd)); | |
9929 | ||
9930 | if (abfd == NULL || abfd->tdata.any == NULL) | |
0a1b45a2 | 9931 | return true; |
95e34ef7 | 9932 | |
37d2e9c7 | 9933 | if (abfd->format == bfd_object) |
95e34ef7 | 9934 | { |
a7ac9aa5 | 9935 | alpha_vms_free_private (abfd); |
95e34ef7 TG |
9936 | |
9937 | #ifdef VMS | |
37d2e9c7 AM |
9938 | if (abfd->direction == write_direction) |
9939 | { | |
9940 | /* Last step on VMS is to convert the file to variable record length | |
9941 | format. */ | |
9942 | if (!bfd_cache_close (abfd)) | |
0a1b45a2 | 9943 | return false; |
37d2e9c7 | 9944 | if (!_bfd_vms_convert_to_var_unix_filename (abfd->filename)) |
0a1b45a2 | 9945 | return false; |
37d2e9c7 | 9946 | } |
95e34ef7 | 9947 | #endif |
37d2e9c7 | 9948 | } |
95e34ef7 | 9949 | |
37d2e9c7 | 9950 | return _bfd_generic_close_and_cleanup (abfd); |
95e34ef7 TG |
9951 | } |
9952 | ||
9953 | /* Called when a new section is created. */ | |
9954 | ||
0a1b45a2 | 9955 | static bool |
95e34ef7 TG |
9956 | vms_new_section_hook (bfd * abfd, asection *section) |
9957 | { | |
986f0783 | 9958 | size_t amt; |
95e34ef7 | 9959 | |
d3435ae8 | 9960 | vms_debug2 ((1, "vms_new_section_hook (%p, [%u]%s)\n", |
07d6d2b8 | 9961 | abfd, section->index, section->name)); |
95e34ef7 | 9962 | |
fd361982 | 9963 | if (!bfd_set_section_alignment (section, 0)) |
0a1b45a2 | 9964 | return false; |
95e34ef7 | 9965 | |
d3435ae8 | 9966 | vms_debug2 ((7, "%u: %s\n", section->index, section->name)); |
95e34ef7 TG |
9967 | |
9968 | amt = sizeof (struct vms_section_data_struct); | |
8185f55c | 9969 | section->used_by_bfd = bfd_zalloc (abfd, amt); |
95e34ef7 | 9970 | if (section->used_by_bfd == NULL) |
0a1b45a2 | 9971 | return false; |
95e34ef7 | 9972 | |
95e34ef7 TG |
9973 | /* Create the section symbol. */ |
9974 | return _bfd_generic_new_section_hook (abfd, section); | |
9975 | } | |
9976 | ||
9977 | /* Part 4.5, symbols. */ | |
9978 | ||
9979 | /* Print symbol to file according to how. how is one of | |
9980 | bfd_print_symbol_name just print the name | |
9981 | bfd_print_symbol_more print more (???) | |
9982 | bfd_print_symbol_all print all we know, which is not much right now :-). */ | |
9983 | ||
9984 | static void | |
9985 | vms_print_symbol (bfd * abfd, | |
9986 | void * file, | |
9987 | asymbol *symbol, | |
9988 | bfd_print_symbol_type how) | |
9989 | { | |
9990 | vms_debug2 ((1, "vms_print_symbol (%p, %p, %p, %d)\n", | |
07d6d2b8 | 9991 | abfd, file, symbol, how)); |
95e34ef7 TG |
9992 | |
9993 | switch (how) | |
9994 | { | |
9995 | case bfd_print_symbol_name: | |
9996 | case bfd_print_symbol_more: | |
9997 | fprintf ((FILE *)file," %s", symbol->name); | |
9998 | break; | |
9999 | ||
10000 | case bfd_print_symbol_all: | |
10001 | { | |
10002 | const char *section_name = symbol->section->name; | |
10003 | ||
10004 | bfd_print_symbol_vandf (abfd, file, symbol); | |
10005 | ||
10006 | fprintf ((FILE *) file," %-8s %s", section_name, symbol->name); | |
07d6d2b8 | 10007 | } |
95e34ef7 TG |
10008 | break; |
10009 | } | |
10010 | } | |
10011 | ||
10012 | /* Return information about symbol in ret. | |
10013 | ||
10014 | fill type, value and name | |
10015 | type: | |
10016 | A absolute | |
10017 | B bss segment symbol | |
10018 | C common symbol | |
10019 | D data segment symbol | |
10020 | f filename | |
10021 | t a static function symbol | |
10022 | T text segment symbol | |
10023 | U undefined | |
10024 | - debug. */ | |
10025 | ||
10026 | static void | |
10027 | vms_get_symbol_info (bfd * abfd ATTRIBUTE_UNUSED, | |
10028 | asymbol *symbol, | |
10029 | symbol_info *ret) | |
10030 | { | |
10031 | asection *sec; | |
10032 | ||
10033 | vms_debug2 ((1, "vms_get_symbol_info (%p, %p, %p)\n", abfd, symbol, ret)); | |
10034 | ||
10035 | sec = symbol->section; | |
10036 | ||
10037 | if (ret == NULL) | |
10038 | return; | |
10039 | ||
a928f1d7 | 10040 | if (sec == NULL) |
95e34ef7 TG |
10041 | ret->type = 'U'; |
10042 | else if (bfd_is_com_section (sec)) | |
10043 | ret->type = 'C'; | |
10044 | else if (bfd_is_abs_section (sec)) | |
10045 | ret->type = 'A'; | |
10046 | else if (bfd_is_und_section (sec)) | |
10047 | ret->type = 'U'; | |
10048 | else if (bfd_is_ind_section (sec)) | |
10049 | ret->type = 'I'; | |
c068d5be | 10050 | else if ((symbol->flags & BSF_FUNCTION) |
fd361982 | 10051 | || (bfd_section_flags (sec) & SEC_CODE)) |
95e34ef7 | 10052 | ret->type = 'T'; |
fd361982 | 10053 | else if (bfd_section_flags (sec) & SEC_DATA) |
95e34ef7 | 10054 | ret->type = 'D'; |
fd361982 | 10055 | else if (bfd_section_flags (sec) & SEC_ALLOC) |
95e34ef7 TG |
10056 | ret->type = 'B'; |
10057 | else | |
5369db0a | 10058 | ret->type = '?'; |
95e34ef7 TG |
10059 | |
10060 | if (ret->type != 'U') | |
10061 | ret->value = symbol->value + symbol->section->vma; | |
10062 | else | |
10063 | ret->value = 0; | |
10064 | ret->name = symbol->name; | |
10065 | } | |
10066 | ||
10067 | /* Return TRUE if the given symbol sym in the BFD abfd is | |
10068 | a compiler generated local label, else return FALSE. */ | |
10069 | ||
0a1b45a2 | 10070 | static bool |
95e34ef7 TG |
10071 | vms_bfd_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED, |
10072 | const char *name) | |
10073 | { | |
95e34ef7 TG |
10074 | return name[0] == '$'; |
10075 | } | |
10076 | \f | |
10077 | /* Part 4.7, writing an object file. */ | |
10078 | ||
10079 | /* Sets the contents of the section section in BFD abfd to the data starting | |
10080 | in memory at LOCATION. The data is written to the output section starting | |
10081 | at offset offset for count bytes. | |
10082 | ||
10083 | Normally TRUE is returned, else FALSE. Possible error returns are: | |
10084 | o bfd_error_no_contents - The output section does not have the | |
10085 | SEC_HAS_CONTENTS attribute, so nothing can be written to it. | |
10086 | o and some more too */ | |
10087 | ||
0a1b45a2 | 10088 | static bool |
95e34ef7 | 10089 | _bfd_vms_set_section_contents (bfd * abfd, |
07d6d2b8 AM |
10090 | asection *section, |
10091 | const void * location, | |
10092 | file_ptr offset, | |
10093 | bfd_size_type count) | |
95e34ef7 TG |
10094 | { |
10095 | if (section->contents == NULL) | |
10096 | { | |
10097 | section->contents = bfd_alloc (abfd, section->size); | |
10098 | if (section->contents == NULL) | |
0a1b45a2 | 10099 | return false; |
95e34ef7 TG |
10100 | |
10101 | memcpy (section->contents + offset, location, (size_t) count); | |
10102 | } | |
10103 | ||
0a1b45a2 | 10104 | return true; |
95e34ef7 TG |
10105 | } |
10106 | ||
10107 | /* Set the architecture and machine type in BFD abfd to arch and mach. | |
10108 | Find the correct pointer to a structure and insert it into the arch_info | |
10109 | pointer. */ | |
10110 | ||
0a1b45a2 | 10111 | static bool |
95e34ef7 | 10112 | alpha_vms_set_arch_mach (bfd *abfd, |
07d6d2b8 | 10113 | enum bfd_architecture arch, unsigned long mach) |
95e34ef7 TG |
10114 | { |
10115 | if (arch != bfd_arch_alpha | |
10116 | && arch != bfd_arch_unknown) | |
0a1b45a2 | 10117 | return false; |
95e34ef7 TG |
10118 | |
10119 | return bfd_default_set_arch_mach (abfd, arch, mach); | |
10120 | } | |
10121 | ||
10122 | /* Set section VMS flags. Clear NO_FLAGS and set FLAGS. */ | |
10123 | ||
10124 | void | |
10125 | bfd_vms_set_section_flags (bfd *abfd ATTRIBUTE_UNUSED, | |
10126 | asection *sec, flagword no_flags, flagword flags) | |
10127 | { | |
10128 | vms_section_data (sec)->no_flags = no_flags; | |
10129 | vms_section_data (sec)->flags = flags; | |
10130 | } | |
10131 | ||
10132 | struct vms_private_data_struct * | |
10133 | bfd_vms_get_data (bfd *abfd) | |
10134 | { | |
10135 | return (struct vms_private_data_struct *)abfd->tdata.any; | |
10136 | } | |
10137 | ||
95e34ef7 | 10138 | #define vms_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data |
ba75d1c5 | 10139 | #define vms_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data |
433b4f8a | 10140 | #define vms_init_private_section_data _bfd_generic_init_private_section_data |
95e34ef7 TG |
10141 | #define vms_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data |
10142 | #define vms_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data | |
ba75d1c5 | 10143 | #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data |
07d6d2b8 | 10144 | #define vms_bfd_set_private_flags _bfd_generic_bfd_set_private_flags |
95e34ef7 TG |
10145 | |
10146 | /* Symbols table. */ | |
07d6d2b8 | 10147 | #define alpha_vms_make_empty_symbol _bfd_generic_make_empty_symbol |
d00dd7dc | 10148 | #define alpha_vms_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false |
07d6d2b8 AM |
10149 | #define alpha_vms_print_symbol vms_print_symbol |
10150 | #define alpha_vms_get_symbol_info vms_get_symbol_info | |
60bb06bc L |
10151 | #define alpha_vms_get_symbol_version_string \ |
10152 | _bfd_nosymbols_get_symbol_version_string | |
10153 | ||
07d6d2b8 AM |
10154 | #define alpha_vms_read_minisymbols _bfd_generic_read_minisymbols |
10155 | #define alpha_vms_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
10156 | #define alpha_vms_get_lineno _bfd_nosymbols_get_lineno | |
10157 | #define alpha_vms_find_inliner_info _bfd_nosymbols_find_inliner_info | |
10158 | #define alpha_vms_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol | |
10159 | #define alpha_vms_find_nearest_line _bfd_vms_find_nearest_line | |
6e7a29c7 AM |
10160 | #define alpha_vms_find_nearest_line_with_alt \ |
10161 | _bfd_nosymbols_find_nearest_line_with_alt | |
07d6d2b8 | 10162 | #define alpha_vms_find_line _bfd_nosymbols_find_line |
95e34ef7 TG |
10163 | #define alpha_vms_bfd_is_local_label_name vms_bfd_is_local_label_name |
10164 | ||
10165 | /* Generic table. */ | |
10166 | #define alpha_vms_close_and_cleanup vms_close_and_cleanup | |
ba75d1c5 | 10167 | #define alpha_vms_bfd_free_cached_info _bfd_bool_bfd_true |
95e34ef7 TG |
10168 | #define alpha_vms_new_section_hook vms_new_section_hook |
10169 | #define alpha_vms_set_section_contents _bfd_vms_set_section_contents | |
95e34ef7 TG |
10170 | |
10171 | #define alpha_vms_bfd_get_relocated_section_contents \ | |
10172 | bfd_generic_get_relocated_section_contents | |
10173 | ||
10174 | #define alpha_vms_bfd_relax_section bfd_generic_relax_section | |
10175 | #define alpha_vms_bfd_gc_sections bfd_generic_gc_sections | |
ae17ab41 | 10176 | #define alpha_vms_bfd_lookup_section_flags bfd_generic_lookup_section_flags |
95e34ef7 TG |
10177 | #define alpha_vms_bfd_merge_sections bfd_generic_merge_sections |
10178 | #define alpha_vms_bfd_is_group_section bfd_generic_is_group_section | |
cb7f4b29 | 10179 | #define alpha_vms_bfd_group_name bfd_generic_group_name |
95e34ef7 TG |
10180 | #define alpha_vms_bfd_discard_group bfd_generic_discard_group |
10181 | #define alpha_vms_section_already_linked \ | |
10182 | _bfd_generic_section_already_linked | |
10183 | ||
10184 | #define alpha_vms_bfd_define_common_symbol bfd_generic_define_common_symbol | |
34a87bb0 | 10185 | #define alpha_vms_bfd_link_hide_symbol _bfd_generic_link_hide_symbol |
7dba9362 | 10186 | #define alpha_vms_bfd_define_start_stop bfd_generic_define_start_stop |
95e34ef7 TG |
10187 | #define alpha_vms_bfd_link_just_syms _bfd_generic_link_just_syms |
10188 | #define alpha_vms_bfd_copy_link_hash_symbol_type \ | |
10189 | _bfd_generic_copy_link_hash_symbol_type | |
10190 | ||
10191 | #define alpha_vms_bfd_link_split_section _bfd_generic_link_split_section | |
10192 | ||
10193 | #define alpha_vms_get_dynamic_symtab_upper_bound \ | |
10194 | _bfd_nodynamic_get_dynamic_symtab_upper_bound | |
10195 | #define alpha_vms_canonicalize_dynamic_symtab \ | |
10196 | _bfd_nodynamic_canonicalize_dynamic_symtab | |
10197 | #define alpha_vms_get_dynamic_reloc_upper_bound \ | |
10198 | _bfd_nodynamic_get_dynamic_reloc_upper_bound | |
10199 | #define alpha_vms_canonicalize_dynamic_reloc \ | |
10200 | _bfd_nodynamic_canonicalize_dynamic_reloc | |
07d6d2b8 | 10201 | #define alpha_vms_bfd_link_check_relocs _bfd_generic_link_check_relocs |
95e34ef7 | 10202 | |
6d00b590 | 10203 | const bfd_target alpha_vms_vec = |
95e34ef7 TG |
10204 | { |
10205 | "vms-alpha", /* Name. */ | |
10206 | bfd_target_evax_flavour, | |
10207 | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ | |
10208 | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ | |
10209 | ||
10210 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS | |
10211 | | WP_TEXT | D_PAGED), /* Object flags. */ | |
10212 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
10213 | | SEC_READONLY | SEC_CODE | SEC_DATA | |
10214 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* Sect flags. */ | |
10215 | 0, /* symbol_leading_char. */ | |
10216 | ' ', /* ar_pad_char. */ | |
10217 | 15, /* ar_max_namelen. */ | |
0aabe54e | 10218 | 0, /* match priority. */ |
d1bcae83 | 10219 | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
95e34ef7 TG |
10220 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
10221 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
10222 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
10223 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
10224 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
10225 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
10226 | ||
d00dd7dc AM |
10227 | { /* bfd_check_format. */ |
10228 | _bfd_dummy_target, | |
10229 | alpha_vms_object_p, | |
10230 | _bfd_vms_lib_alpha_archive_p, | |
10231 | _bfd_dummy_target | |
10232 | }, | |
10233 | { /* bfd_set_format. */ | |
10234 | _bfd_bool_bfd_false_error, | |
10235 | alpha_vms_mkobject, | |
10236 | _bfd_vms_lib_alpha_mkarchive, | |
10237 | _bfd_bool_bfd_false_error | |
10238 | }, | |
10239 | { /* bfd_write_contents. */ | |
10240 | _bfd_bool_bfd_false_error, | |
10241 | alpha_vms_write_object_contents, | |
10242 | _bfd_vms_lib_write_archive_contents, | |
10243 | _bfd_bool_bfd_false_error | |
10244 | }, | |
95e34ef7 TG |
10245 | |
10246 | BFD_JUMP_TABLE_GENERIC (alpha_vms), | |
10247 | BFD_JUMP_TABLE_COPY (vms), | |
10248 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
10249 | BFD_JUMP_TABLE_ARCHIVE (_bfd_vms_lib), | |
10250 | BFD_JUMP_TABLE_SYMBOLS (alpha_vms), | |
10251 | BFD_JUMP_TABLE_RELOCS (alpha_vms), | |
10252 | BFD_JUMP_TABLE_WRITE (alpha_vms), | |
10253 | BFD_JUMP_TABLE_LINK (alpha_vms), | |
10254 | BFD_JUMP_TABLE_DYNAMIC (alpha_vms), | |
10255 | ||
10256 | NULL, | |
10257 | ||
8185f55c | 10258 | NULL |
95e34ef7 | 10259 | }; |