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