Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* vms.c -- BFD back-end for VAX (openVMS/VAX) and |
2 | EVAX (openVMS/Alpha) files. | |
7898deda NC |
3 | Copyright 1996, 1997, 1998, 1999, 2000, 2001 |
4 | Free Software Foundation, Inc. | |
252b5132 RH |
5 | |
6 | Written by Klaus K"ampf (kkaempf@rmi.de) | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "bfdlink.h" | |
25 | #include "libbfd.h" | |
26 | ||
27 | #include "vms.h" | |
28 | ||
29 | static boolean vms_initialize PARAMS ((bfd *)); | |
5f771d47 | 30 | static unsigned int priv_section_count; |
252b5132 RH |
31 | static boolean fill_section_ptr PARAMS ((struct bfd_hash_entry *, PTR)); |
32 | static boolean vms_fixup_sections PARAMS ((bfd *)); | |
33 | static boolean copy_symbols PARAMS ((struct bfd_hash_entry *, PTR)); | |
34 | static bfd_reloc_status_type reloc_nil | |
35 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
36 | static const struct bfd_target *vms_object_p PARAMS ((bfd *abfd)); | |
37 | static const struct bfd_target *vms_archive_p PARAMS ((bfd *abfd)); | |
38 | static boolean vms_mkobject PARAMS ((bfd *abfd)); | |
39 | static boolean vms_write_object_contents PARAMS ((bfd *abfd)); | |
40 | static boolean vms_close_and_cleanup PARAMS ((bfd *abfd)); | |
41 | static boolean vms_bfd_free_cached_info PARAMS ((bfd *abfd)); | |
42 | static boolean vms_new_section_hook PARAMS ((bfd *abfd, asection *section)); | |
43 | static boolean vms_get_section_contents | |
44 | PARAMS ((bfd *abfd, asection *section, PTR x1, file_ptr x2, | |
45 | bfd_size_type x3)); | |
46 | static boolean vms_get_section_contents_in_window | |
47 | PARAMS ((bfd *abfd, asection *section, bfd_window *w, file_ptr offset, | |
48 | bfd_size_type count)); | |
49 | static boolean vms_bfd_copy_private_bfd_data PARAMS ((bfd *src, bfd *dest)); | |
50 | static boolean vms_bfd_copy_private_section_data | |
51 | PARAMS ((bfd *srcbfd, asection *srcsec, bfd *dstbfd, asection *dstsec)); | |
52 | static boolean vms_bfd_copy_private_symbol_data | |
53 | PARAMS ((bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym)); | |
54 | static boolean vms_bfd_print_private_bfd_data | |
55 | PARAMS ((bfd *abfd, void *file)); | |
56 | static char *vms_core_file_failing_command PARAMS ((bfd *abfd)); | |
57 | static int vms_core_file_failing_signal PARAMS ((bfd *abfd)); | |
58 | static boolean vms_core_file_matches_executable_p | |
59 | PARAMS ((bfd *abfd, bfd *bbfd)); | |
60 | static boolean vms_slurp_armap PARAMS ((bfd *abfd)); | |
61 | static boolean vms_slurp_extended_name_table PARAMS ((bfd *abfd)); | |
62 | static boolean vms_construct_extended_name_table | |
63 | PARAMS ((bfd *abfd, char **tabloc, bfd_size_type *tablen, | |
64 | const char **name)); | |
65 | static void vms_truncate_arname | |
66 | PARAMS ((bfd *abfd, CONST char *pathname, char *arhdr)); | |
67 | static boolean vms_write_armap | |
68 | PARAMS ((bfd *arch, unsigned int elength, struct orl *map, | |
69 | unsigned int orl_count, int stridx)); | |
70 | static PTR vms_read_ar_hdr PARAMS ((bfd *abfd)); | |
71 | static bfd *vms_get_elt_at_index PARAMS ((bfd *abfd, symindex index)); | |
72 | static bfd *vms_openr_next_archived_file PARAMS ((bfd *arch, bfd *prev)); | |
73 | static boolean vms_update_armap_timestamp PARAMS ((bfd *abfd)); | |
74 | static int vms_generic_stat_arch_elt PARAMS ((bfd *abfd, struct stat *stat)); | |
75 | static long vms_get_symtab_upper_bound PARAMS ((bfd *abfd)); | |
76 | static long vms_get_symtab PARAMS ((bfd *abfd, asymbol **symbols)); | |
77 | static void vms_print_symbol | |
78 | PARAMS ((bfd *abfd, PTR file, asymbol *symbol, bfd_print_symbol_type how)); | |
79 | static void vms_get_symbol_info | |
80 | PARAMS ((bfd *abfd, asymbol *symbol, symbol_info *ret)); | |
81 | static boolean vms_bfd_is_local_label_name PARAMS ((bfd *abfd, const char *)); | |
82 | static alent *vms_get_lineno PARAMS ((bfd *abfd, asymbol *symbol)); | |
83 | static boolean vms_find_nearest_line | |
84 | PARAMS ((bfd *abfd, asection *section, asymbol **symbols, bfd_vma offset, | |
85 | const char **file, const char **func, unsigned int *line)); | |
86 | static asymbol *vms_bfd_make_debug_symbol | |
87 | PARAMS ((bfd *abfd, void *ptr, unsigned long size)); | |
88 | static long vms_read_minisymbols | |
89 | PARAMS ((bfd *abfd, boolean dynamic, PTR *minisymsp, unsigned int *sizep)); | |
90 | static asymbol *vms_minisymbol_to_symbol | |
91 | PARAMS ((bfd *abfd, boolean dynamic, const PTR minisym, asymbol *sym)); | |
92 | static long vms_get_reloc_upper_bound PARAMS ((bfd *abfd, asection *sect)); | |
93 | static long vms_canonicalize_reloc | |
94 | PARAMS ((bfd *abfd, asection *srcsec, arelent **location, | |
95 | asymbol **symbols)); | |
96 | static const struct reloc_howto_struct *vms_bfd_reloc_type_lookup | |
97 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
98 | static boolean vms_set_arch_mach | |
99 | PARAMS ((bfd *abfd, enum bfd_architecture arch, unsigned long mach)); | |
100 | static boolean vms_set_section_contents | |
101 | PARAMS ((bfd *abfd, asection *section, PTR location, file_ptr offset, | |
102 | bfd_size_type count)); | |
103 | static int vms_sizeof_headers PARAMS ((bfd *abfd, boolean reloc)); | |
104 | static bfd_byte *vms_bfd_get_relocated_section_contents | |
105 | PARAMS ((bfd *abfd, struct bfd_link_info *link_info, | |
106 | struct bfd_link_order *link_order, bfd_byte *data, | |
107 | boolean relocateable, asymbol **symbols)); | |
108 | static boolean vms_bfd_relax_section | |
109 | PARAMS ((bfd *abfd, asection *section, struct bfd_link_info *link_info, | |
110 | boolean *again)); | |
111 | static boolean vms_bfd_gc_sections | |
112 | PARAMS ((bfd *abfd, struct bfd_link_info *link_info)); | |
113 | static struct bfd_link_hash_table *vms_bfd_link_hash_table_create | |
114 | PARAMS ((bfd *abfd)); | |
115 | static boolean vms_bfd_link_add_symbols | |
116 | PARAMS ((bfd *abfd, struct bfd_link_info *link_info)); | |
117 | static boolean vms_bfd_final_link | |
118 | PARAMS ((bfd *abfd, struct bfd_link_info *link_info)); | |
119 | static boolean vms_bfd_link_split_section | |
120 | PARAMS ((bfd *abfd, asection *section)); | |
121 | static long vms_get_dynamic_symtab_upper_bound PARAMS ((bfd *abfd)); | |
122 | static long vms_canonicalize_dynamic_symtab | |
123 | PARAMS ((bfd *abfd, asymbol **symbols)); | |
124 | static long vms_get_dynamic_reloc_upper_bound PARAMS ((bfd *abfd)); | |
125 | static long vms_canonicalize_dynamic_reloc | |
126 | PARAMS ((bfd *abfd, arelent **arel, asymbol **symbols)); | |
127 | static boolean vms_bfd_merge_private_bfd_data PARAMS ((bfd *ibfd, bfd *obfd)); | |
128 | static boolean vms_bfd_set_private_flags PARAMS ((bfd *abfd, flagword flags)); | |
129 | ||
130 | #define vms_make_empty_symbol _bfd_vms_make_empty_symbol | |
131 | \f | |
132 | /*===========================================================================*/ | |
133 | ||
134 | const bfd_target vms_alpha_vec = | |
135 | { | |
252b5132 RH |
136 | "vms-alpha", /* name */ |
137 | bfd_target_evax_flavour, | |
c3c89269 NC |
138 | BFD_ENDIAN_LITTLE, /* data byte order is little */ |
139 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
252b5132 RH |
140 | |
141 | (HAS_RELOC | HAS_SYMS | |
142 | | WP_TEXT | D_PAGED), /* object flags */ | |
143 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
144 | | SEC_READONLY | SEC_CODE | SEC_DATA | |
145 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* sect flags */ | |
146 | 0, /* symbol_leading_char */ | |
147 | ' ', /* ar_pad_char */ | |
148 | 15, /* ar_max_namelen */ | |
149 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
150 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
151 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
152 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
153 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
154 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, | |
155 | ||
156 | {_bfd_dummy_target, vms_object_p, /* bfd_check_format */ | |
157 | vms_archive_p, _bfd_dummy_target}, | |
158 | {bfd_false, vms_mkobject, /* bfd_set_format */ | |
159 | _bfd_generic_mkarchive, bfd_false}, | |
160 | {bfd_false, vms_write_object_contents, /* bfd_write_contents */ | |
161 | _bfd_write_archive_contents, bfd_false}, | |
162 | ||
163 | BFD_JUMP_TABLE_GENERIC (vms), | |
164 | BFD_JUMP_TABLE_COPY (vms), | |
165 | BFD_JUMP_TABLE_CORE (vms), | |
166 | BFD_JUMP_TABLE_ARCHIVE (vms), | |
167 | BFD_JUMP_TABLE_SYMBOLS (vms), | |
168 | BFD_JUMP_TABLE_RELOCS (vms), | |
169 | BFD_JUMP_TABLE_WRITE (vms), | |
170 | BFD_JUMP_TABLE_LINK (vms), | |
171 | BFD_JUMP_TABLE_DYNAMIC (vms), | |
172 | ||
c3c89269 | 173 | NULL, |
55f2d5ed | 174 | |
252b5132 RH |
175 | (PTR) 0 |
176 | }; | |
177 | ||
178 | const bfd_target vms_vax_vec = | |
179 | { | |
252b5132 RH |
180 | "vms-vax", /* name */ |
181 | bfd_target_ovax_flavour, | |
c3c89269 NC |
182 | BFD_ENDIAN_LITTLE, /* data byte order is little */ |
183 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
252b5132 RH |
184 | |
185 | (HAS_RELOC | HAS_SYMS /* object flags */ | |
186 | | WP_TEXT | D_PAGED | |
187 | | HAS_LINENO | HAS_DEBUG | HAS_LOCALS), | |
188 | ||
189 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
190 | | SEC_READONLY | SEC_CODE | SEC_DATA | |
191 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* sect flags */ | |
192 | 0, /* symbol_leading_char */ | |
193 | ' ', /* ar_pad_char */ | |
194 | 15, /* ar_max_namelen */ | |
195 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
196 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
197 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
198 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
199 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
200 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
201 | ||
202 | {_bfd_dummy_target, vms_object_p, /* bfd_check_format */ | |
203 | vms_archive_p, _bfd_dummy_target}, | |
204 | {bfd_false, vms_mkobject, /* bfd_set_format */ | |
205 | _bfd_generic_mkarchive, bfd_false}, | |
206 | {bfd_false, vms_write_object_contents, /* bfd_write_contents */ | |
207 | _bfd_write_archive_contents, bfd_false}, | |
208 | ||
209 | BFD_JUMP_TABLE_GENERIC (vms), | |
210 | BFD_JUMP_TABLE_COPY (vms), | |
211 | BFD_JUMP_TABLE_CORE (vms), | |
212 | BFD_JUMP_TABLE_ARCHIVE (vms), | |
213 | BFD_JUMP_TABLE_SYMBOLS (vms), | |
214 | BFD_JUMP_TABLE_RELOCS (vms), | |
215 | BFD_JUMP_TABLE_WRITE (vms), | |
216 | BFD_JUMP_TABLE_LINK (vms), | |
217 | BFD_JUMP_TABLE_DYNAMIC (vms), | |
218 | ||
c3c89269 | 219 | NULL, |
55f2d5ed | 220 | |
252b5132 RH |
221 | (PTR) 0 |
222 | }; | |
223 | \f | |
224 | /*===========================================================================*/ | |
225 | ||
226 | /* Initialize private data */ | |
227 | ||
228 | static boolean | |
229 | vms_initialize (abfd) | |
230 | bfd *abfd; | |
231 | { | |
232 | int i; | |
233 | ||
234 | if (abfd->tdata.any != 0) | |
235 | return true; | |
236 | ||
237 | bfd_set_start_address (abfd, (bfd_vma)-1); | |
238 | ||
239 | abfd->tdata.any = ((struct vms_private_data_struct*) | |
240 | bfd_malloc (sizeof (struct vms_private_data_struct))); | |
241 | if (abfd->tdata.any == 0) | |
242 | return false; | |
243 | ||
244 | #ifdef __ALPHA | |
8a0c27cd | 245 | PRIV (is_vax) = 0; |
252b5132 | 246 | #else |
8a0c27cd | 247 | PRIV (is_vax) = 1; |
252b5132 | 248 | #endif |
8a0c27cd KH |
249 | PRIV (vms_buf) = 0; |
250 | PRIV (buf_size) = 0; | |
251 | PRIV (rec_length) = 0; | |
252 | PRIV (file_format) = FF_UNKNOWN; | |
253 | PRIV (fixup_done) = false; | |
254 | PRIV (sections) = NULL; | |
255 | ||
256 | PRIV (stack) = ((struct stack_struct *) | |
252b5132 | 257 | bfd_malloc (sizeof (struct stack_struct) * STACKSIZE)); |
8a0c27cd | 258 | if (PRIV (stack) == 0) |
252b5132 RH |
259 | { |
260 | vms_init_no_mem1: | |
261 | free (abfd->tdata.any); | |
262 | abfd->tdata.any = 0; | |
263 | return false; | |
264 | } | |
8a0c27cd | 265 | PRIV (stackptr) = 0; |
252b5132 | 266 | |
8a0c27cd | 267 | PRIV (vms_symbol_table) = ((struct bfd_hash_table *) |
252b5132 | 268 | bfd_malloc (sizeof (struct bfd_hash_table))); |
8a0c27cd | 269 | if (PRIV (vms_symbol_table) == 0) |
252b5132 RH |
270 | { |
271 | vms_init_no_mem2: | |
8a0c27cd KH |
272 | free (PRIV (stack)); |
273 | PRIV (stack) = 0; | |
252b5132 RH |
274 | goto vms_init_no_mem1; |
275 | } | |
276 | ||
8a0c27cd | 277 | if (!bfd_hash_table_init (PRIV (vms_symbol_table), _bfd_vms_hash_newfunc)) |
252b5132 RH |
278 | return false; |
279 | ||
8a0c27cd | 280 | PRIV (location_stack) = ((struct location_struct *) |
252b5132 RH |
281 | bfd_malloc (sizeof (struct location_struct) |
282 | * LOCATION_SAVE_SIZE)); | |
8a0c27cd | 283 | if (PRIV (location_stack) == 0) |
252b5132 RH |
284 | { |
285 | vms_init_no_mem3: | |
8a0c27cd KH |
286 | free (PRIV (vms_symbol_table)); |
287 | PRIV (vms_symbol_table) = 0; | |
252b5132 RH |
288 | goto vms_init_no_mem2; |
289 | } | |
290 | ||
291 | for (i = 0; i < VMS_SECTION_COUNT; i++) | |
8a0c27cd | 292 | PRIV (vms_section_table)[i] = NULL; |
252b5132 | 293 | |
8a0c27cd KH |
294 | PRIV (output_buf) = (unsigned char *) malloc (MAX_OUTREC_SIZE); |
295 | if (PRIV (output_buf) == 0) | |
252b5132 | 296 | { |
8a0c27cd KH |
297 | free (PRIV (location_stack)); |
298 | PRIV (location_stack) = 0; | |
252b5132 RH |
299 | goto vms_init_no_mem3; |
300 | } | |
8a0c27cd KH |
301 | PRIV (push_level) = 0; |
302 | PRIV (pushed_size) = 0; | |
303 | PRIV (length_pos) = 2; | |
304 | PRIV (output_size) = 0; | |
305 | PRIV (output_alignment) = 1; | |
252b5132 RH |
306 | |
307 | return true; | |
308 | } | |
309 | ||
252b5132 RH |
310 | /* Fill symbol->section with section ptr |
311 | symbol->section is filled with the section index for defined symbols | |
312 | during reading the GSD/EGSD section. But we need the pointer to the | |
313 | bfd section later. | |
314 | ||
315 | It has the correct value for referenced (undefined section) symbols | |
316 | ||
317 | called from bfd_hash_traverse in vms_fixup_sections */ | |
318 | ||
319 | static boolean | |
320 | fill_section_ptr (entry, sections) | |
321 | struct bfd_hash_entry *entry; | |
322 | PTR sections; | |
323 | { | |
324 | asection *sec; | |
325 | asymbol *sym; | |
326 | ||
327 | sym = ((vms_symbol_entry *)entry)->symbol; | |
328 | sec = sym->section; | |
329 | ||
330 | #if VMS_DEBUG | |
331 | vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym, sec); | |
332 | #endif | |
333 | ||
334 | /* fill forward references (these contain section number, not section ptr). */ | |
335 | ||
5f771d47 | 336 | if ((unsigned int) sec < priv_section_count) |
252b5132 RH |
337 | { |
338 | sec = ((vms_symbol_entry *)entry)->symbol->section = | |
339 | ((asection **)sections)[(int)sec]; | |
340 | } | |
341 | ||
342 | if (strcmp (sym->name, sec->name) == 0) | |
343 | sym->flags |= BSF_SECTION_SYM; | |
344 | ||
345 | return true; | |
346 | } | |
347 | ||
252b5132 RH |
348 | /* Fixup sections |
349 | set up all pointers and arrays, counters and sizes are fixed now | |
350 | ||
351 | we build a private sections vector for easy access since sections | |
352 | are always referenced by an index number. | |
353 | ||
354 | alloc PRIV(sections) according to abfd->section_count | |
355 | copy abfd->sections to PRIV(sections) */ | |
356 | ||
357 | static boolean | |
358 | vms_fixup_sections (abfd) | |
359 | bfd *abfd; | |
360 | { | |
8a0c27cd | 361 | if (PRIV (fixup_done)) |
252b5132 RH |
362 | return true; |
363 | ||
364 | /* | |
365 | * traverse symbol table and fill in all section pointers | |
366 | */ | |
367 | ||
368 | /* can't provide section count as argument to fill_section_ptr(). */ | |
8a0c27cd KH |
369 | priv_section_count = PRIV (section_count); |
370 | bfd_hash_traverse (PRIV (vms_symbol_table), fill_section_ptr, | |
371 | (PTR) (PRIV (sections))); | |
252b5132 | 372 | |
8a0c27cd | 373 | PRIV (fixup_done) = true; |
252b5132 RH |
374 | |
375 | return true; | |
376 | } | |
377 | ||
378 | /*===========================================================================*/ | |
379 | ||
380 | /* Check the format for a file being read. | |
381 | Return a (bfd_target *) if it's an object file or zero if not. */ | |
382 | ||
383 | static const struct bfd_target * | |
384 | vms_object_p (abfd) | |
385 | bfd *abfd; | |
386 | { | |
387 | int err = 0; | |
388 | int prev_type; | |
389 | const struct bfd_target *target_vector = 0; | |
390 | const bfd_arch_info_type *arch = 0; | |
391 | ||
392 | #if VMS_DEBUG | |
393 | vms_debug (1, "vms_object_p(%p)\n", abfd); | |
394 | #endif | |
395 | ||
396 | if (!vms_initialize (abfd)) | |
397 | { | |
398 | fprintf (stderr, "vms_initialize () failed !!\n"); | |
399 | return 0; | |
400 | } | |
401 | ||
402 | if (bfd_seek (abfd, 0L, SEEK_SET)) | |
403 | { | |
404 | bfd_set_error (bfd_error_file_truncated); | |
405 | return 0; | |
406 | } | |
407 | ||
408 | prev_type = -1; | |
409 | ||
410 | do | |
411 | { | |
412 | #if VMS_DEBUG | |
413 | vms_debug (7, "reading at %08lx\n", bfd_tell(abfd)); | |
414 | #endif | |
415 | if (_bfd_vms_next_record (abfd) < 0) | |
416 | { | |
417 | #if VMS_DEBUG | |
55f2d5ed | 418 | vms_debug (2, "next_record failed\n"); |
252b5132 RH |
419 | #endif |
420 | bfd_set_error (bfd_error_wrong_format); | |
421 | return 0; | |
422 | } | |
423 | ||
424 | if ((prev_type == EOBJ_S_C_EGSD) | |
8a0c27cd | 425 | && (PRIV (rec_type) != EOBJ_S_C_EGSD)) |
252b5132 RH |
426 | { |
427 | if (vms_fixup_sections (abfd) == false) | |
428 | { | |
429 | #if VMS_DEBUG | |
430 | vms_debug (2, "vms_fixup_sections failed\n"); | |
431 | #endif | |
432 | bfd_set_error (bfd_error_wrong_format); | |
433 | return 0; | |
434 | } | |
435 | } | |
436 | ||
8a0c27cd | 437 | prev_type = PRIV (rec_type); |
252b5132 RH |
438 | |
439 | if (target_vector == 0) | |
440 | { | |
441 | if (prev_type <= OBJ_S_C_MAXRECTYP) | |
442 | target_vector = &vms_vax_vec; | |
443 | else | |
444 | target_vector = &vms_alpha_vec; | |
445 | } | |
446 | ||
447 | switch (prev_type) | |
448 | { | |
449 | case OBJ_S_C_HDR: | |
450 | case EOBJ_S_C_EMH: | |
451 | err = _bfd_vms_slurp_hdr (abfd, prev_type); | |
452 | break; | |
453 | case OBJ_S_C_EOM: | |
454 | case OBJ_S_C_EOMW: | |
455 | case EOBJ_S_C_EEOM: | |
456 | err = _bfd_vms_slurp_eom (abfd, prev_type); | |
457 | break; | |
458 | case OBJ_S_C_GSD: | |
459 | case EOBJ_S_C_EGSD: | |
460 | err = _bfd_vms_slurp_gsd (abfd, prev_type); | |
461 | break; | |
462 | case OBJ_S_C_TIR: | |
463 | case EOBJ_S_C_ETIR: | |
464 | err = _bfd_vms_slurp_tir (abfd, prev_type); | |
465 | break; | |
466 | case OBJ_S_C_DBG: | |
467 | case EOBJ_S_C_EDBG: | |
468 | err = _bfd_vms_slurp_dbg (abfd, prev_type); | |
469 | break; | |
470 | case OBJ_S_C_TBT: | |
471 | case EOBJ_S_C_ETBT: | |
472 | err = _bfd_vms_slurp_tbt (abfd, prev_type); | |
473 | break; | |
474 | case OBJ_S_C_LNK: | |
475 | err = _bfd_vms_slurp_lnk (abfd, prev_type); | |
476 | break; | |
477 | default: | |
478 | err = -1; | |
479 | } | |
480 | if (err != 0) | |
481 | { | |
482 | #if VMS_DEBUG | |
483 | vms_debug (2, "slurp type %d failed with %d\n", prev_type, err); | |
484 | #endif | |
485 | bfd_set_error (bfd_error_wrong_format); | |
486 | return 0; | |
487 | } | |
488 | } | |
489 | while ((prev_type != EOBJ_S_C_EEOM) && (prev_type != OBJ_S_C_EOM) && (prev_type != OBJ_S_C_EOMW)); | |
490 | ||
491 | if (target_vector == &vms_vax_vec) | |
492 | { | |
493 | if (vms_fixup_sections (abfd) == false) | |
494 | { | |
495 | #if VMS_DEBUG | |
496 | vms_debug (2, "vms_fixup_sections failed\n"); | |
497 | #endif | |
498 | bfd_set_error (bfd_error_wrong_format); | |
499 | return 0; | |
500 | } | |
501 | ||
502 | /* set arch_info to vax */ | |
55f2d5ed | 503 | |
252b5132 RH |
504 | arch = bfd_scan_arch ("vax"); |
505 | PRIV (is_vax) = 1; | |
506 | #if VMS_DEBUG | |
507 | vms_debug (2, "arch is vax\n"); | |
508 | #endif | |
509 | } | |
510 | else if (target_vector == &vms_alpha_vec) | |
511 | { | |
512 | /* set arch_info to alpha */ | |
55f2d5ed | 513 | |
252b5132 RH |
514 | arch = bfd_scan_arch ("alpha"); |
515 | PRIV (is_vax) = 0; | |
516 | #if VMS_DEBUG | |
517 | vms_debug (2, "arch is alpha\n"); | |
518 | #endif | |
519 | } | |
520 | ||
521 | if (arch == 0) | |
522 | { | |
523 | #if VMS_DEBUG | |
524 | vms_debug (2, "arch not found\n"); | |
525 | #endif | |
526 | bfd_set_error (bfd_error_wrong_format); | |
527 | return 0; | |
528 | } | |
529 | abfd->arch_info = arch; | |
530 | ||
531 | return target_vector; | |
532 | } | |
533 | ||
252b5132 RH |
534 | /* Check the format for a file being read. |
535 | Return a (bfd_target *) if it's an archive file or zero. */ | |
536 | ||
537 | static const struct bfd_target * | |
538 | vms_archive_p (abfd) | |
5f771d47 | 539 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
540 | { |
541 | #if VMS_DEBUG | |
542 | vms_debug (1, "vms_archive_p(%p)\n", abfd); | |
543 | #endif | |
544 | ||
545 | return 0; | |
546 | } | |
547 | ||
252b5132 RH |
548 | /* Set the format of a file being written. */ |
549 | ||
550 | static boolean | |
551 | vms_mkobject (abfd) | |
552 | bfd *abfd; | |
553 | { | |
554 | #if VMS_DEBUG | |
555 | vms_debug (1, "vms_mkobject(%p)\n", abfd); | |
556 | #endif | |
557 | ||
558 | if (!vms_initialize (abfd)) | |
559 | { | |
560 | fprintf (stderr, "vms_initialize () failed !!\n"); | |
561 | return 0; | |
562 | } | |
563 | ||
564 | { | |
565 | #ifdef __VAX | |
566 | const bfd_arch_info_type *arch = bfd_scan_arch ("vax"); | |
567 | #else | |
568 | const bfd_arch_info_type *arch = bfd_scan_arch ("alpha"); | |
569 | #endif | |
570 | if (arch == 0) | |
571 | { | |
572 | bfd_set_error(bfd_error_wrong_format); | |
573 | return 0; | |
574 | } | |
575 | abfd->arch_info = arch; | |
576 | } | |
577 | ||
578 | return true; | |
579 | } | |
580 | ||
252b5132 RH |
581 | /* Write cached information into a file being written, at bfd_close. */ |
582 | ||
583 | static boolean | |
584 | vms_write_object_contents (abfd) | |
585 | bfd *abfd; | |
586 | { | |
587 | #if VMS_DEBUG | |
588 | vms_debug (1, "vms_write_object_contents(%p)\n", abfd); | |
589 | #endif | |
590 | ||
591 | if (abfd->section_count > 0) /* we have sections */ | |
592 | { | |
8a0c27cd | 593 | if (PRIV (is_vax)) |
252b5132 RH |
594 | { |
595 | if (_bfd_vms_write_hdr (abfd, OBJ_S_C_HDR) != 0) | |
596 | return false; | |
597 | if (_bfd_vms_write_gsd (abfd, OBJ_S_C_GSD) != 0) | |
598 | return false; | |
599 | if (_bfd_vms_write_tir (abfd, OBJ_S_C_TIR) != 0) | |
600 | return false; | |
601 | if (_bfd_vms_write_tbt (abfd, OBJ_S_C_TBT) != 0) | |
602 | return false; | |
603 | if (_bfd_vms_write_dbg (abfd, OBJ_S_C_DBG) != 0) | |
604 | return false; | |
605 | if (abfd->section_count > 255) | |
606 | { | |
607 | if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOMW) != 0) | |
608 | return false; | |
609 | } | |
610 | else | |
611 | { | |
612 | if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOM) != 0) | |
613 | return false; | |
614 | } | |
615 | } | |
616 | else | |
617 | { | |
618 | if (_bfd_vms_write_hdr (abfd, EOBJ_S_C_EMH) != 0) | |
619 | return false; | |
620 | if (_bfd_vms_write_gsd (abfd, EOBJ_S_C_EGSD) != 0) | |
621 | return false; | |
622 | if (_bfd_vms_write_tir (abfd, EOBJ_S_C_ETIR) != 0) | |
623 | return false; | |
624 | if (_bfd_vms_write_tbt (abfd, EOBJ_S_C_ETBT) != 0) | |
625 | return false; | |
626 | if (_bfd_vms_write_dbg (abfd, EOBJ_S_C_EDBG) != 0) | |
627 | return false; | |
628 | if (_bfd_vms_write_eom (abfd, EOBJ_S_C_EEOM) != 0) | |
629 | return false; | |
630 | } | |
631 | } | |
632 | return true; | |
633 | } | |
634 | ||
635 | /*-- 4.1, generic -----------------------------------------------------------*/ | |
636 | ||
637 | /* Called when the BFD is being closed to do any necessary cleanup. */ | |
638 | ||
639 | static boolean | |
640 | vms_close_and_cleanup (abfd) | |
641 | bfd *abfd; | |
642 | { | |
643 | asection *sec; | |
644 | vms_section *es, *es1; | |
252b5132 RH |
645 | int i; |
646 | ||
647 | #if VMS_DEBUG | |
648 | vms_debug (1, "vms_close_and_cleanup(%p)\n", abfd); | |
649 | #endif | |
650 | if (abfd == 0) | |
651 | return true; | |
652 | ||
8a0c27cd | 653 | if (PRIV (vms_buf) != NULL) |
252b5132 | 654 | { |
8a0c27cd KH |
655 | free (PRIV (vms_buf)); |
656 | PRIV (vms_buf) = NULL; | |
252b5132 | 657 | } |
8a0c27cd | 658 | PRIV (buf_size) = 0; |
252b5132 | 659 | |
8a0c27cd | 660 | if (PRIV (output_buf) != 0) |
252b5132 | 661 | { |
8a0c27cd KH |
662 | free (PRIV (output_buf)); |
663 | PRIV (output_buf) = 0; | |
252b5132 RH |
664 | } |
665 | ||
666 | sec = abfd->sections; | |
667 | while (sec != NULL) | |
668 | { | |
669 | if (sec->contents) | |
670 | free (sec->contents); | |
671 | sec = sec->next; | |
672 | } | |
673 | ||
8a0c27cd | 674 | if (PRIV (sections) != NULL) |
252b5132 | 675 | { |
8a0c27cd KH |
676 | free (PRIV (sections)); |
677 | PRIV (sections) = NULL; | |
252b5132 RH |
678 | } |
679 | ||
8a0c27cd | 680 | if (PRIV (vms_symbol_table)) |
252b5132 | 681 | { |
8a0c27cd KH |
682 | bfd_hash_table_free (PRIV (vms_symbol_table)); |
683 | PRIV (vms_symbol_table) = 0; | |
252b5132 RH |
684 | } |
685 | ||
8a0c27cd | 686 | if (PRIV (stack)) |
252b5132 | 687 | { |
8a0c27cd KH |
688 | free (PRIV (stack)); |
689 | PRIV (stack) = 0; | |
252b5132 RH |
690 | } |
691 | ||
8a0c27cd | 692 | if (PRIV (location_stack)) |
252b5132 | 693 | { |
8a0c27cd KH |
694 | free (PRIV (location_stack)); |
695 | PRIV (location_stack) = 0; | |
252b5132 RH |
696 | } |
697 | ||
698 | for (i = 0; i < VMS_SECTION_COUNT; i++) | |
699 | { | |
8a0c27cd | 700 | es = PRIV (vms_section_table)[i]; |
252b5132 RH |
701 | while (es != NULL) |
702 | { | |
703 | es1 = es->next; | |
704 | free (es); | |
705 | es = es1; | |
706 | } | |
8a0c27cd | 707 | PRIV (vms_section_table)[i] = NULL; |
252b5132 RH |
708 | } |
709 | ||
710 | free (abfd->tdata.any); | |
711 | abfd->tdata.any = NULL; | |
712 | ||
713 | return true; | |
714 | } | |
715 | ||
252b5132 RH |
716 | /* Ask the BFD to free all cached information. */ |
717 | static boolean | |
718 | vms_bfd_free_cached_info (abfd) | |
5f771d47 | 719 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
720 | { |
721 | #if VMS_DEBUG | |
722 | vms_debug (1, "vms_bfd_free_cached_info(%p)\n", abfd); | |
723 | #endif | |
724 | return true; | |
725 | } | |
726 | ||
252b5132 RH |
727 | /* Called when a new section is created. */ |
728 | ||
729 | static boolean | |
730 | vms_new_section_hook (abfd, section) | |
731 | bfd *abfd; | |
732 | asection *section; | |
733 | { | |
734 | #if VMS_DEBUG | |
735 | vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n", abfd, section->index, section->name, abfd->section_count); | |
736 | #endif | |
737 | bfd_set_section_alignment(abfd, section, 4); | |
738 | ||
8a0c27cd | 739 | if (abfd->section_count > PRIV (section_count)) |
252b5132 | 740 | { |
8a0c27cd KH |
741 | PRIV (sections) = ((asection **) |
742 | bfd_realloc (PRIV (sections), abfd->section_count * sizeof (asection *))); | |
743 | if (PRIV (sections) == 0) | |
252b5132 | 744 | return false; |
8a0c27cd | 745 | PRIV (section_count) = abfd->section_count; |
252b5132 RH |
746 | } |
747 | #if VMS_DEBUG | |
8a0c27cd | 748 | vms_debug (6, "section_count: %d\n", PRIV (section_count)); |
252b5132 | 749 | #endif |
8a0c27cd | 750 | PRIV (sections)[section->index] = section; |
252b5132 RH |
751 | #if VMS_DEBUG |
752 | vms_debug (7, "%d: %s\n", section->index, section->name); | |
753 | #endif | |
754 | ||
755 | return true; | |
756 | } | |
757 | ||
252b5132 RH |
758 | /* Read the contents of a section. |
759 | buf points to a buffer of buf_size bytes to be filled with | |
760 | section data (starting at offset into section) */ | |
761 | ||
762 | static boolean | |
763 | vms_get_section_contents (abfd, section, buf, offset, buf_size) | |
5f771d47 ILT |
764 | bfd *abfd ATTRIBUTE_UNUSED; |
765 | asection *section ATTRIBUTE_UNUSED; | |
766 | PTR buf ATTRIBUTE_UNUSED; | |
767 | file_ptr offset ATTRIBUTE_UNUSED; | |
768 | bfd_size_type buf_size ATTRIBUTE_UNUSED; | |
252b5132 RH |
769 | { |
770 | #if VMS_DEBUG | |
771 | vms_debug (1, "vms_get_section_contents(%p, %s, %p, off %ld, size %d)\n", | |
772 | abfd, section->name, buf, offset, (int)buf_size); | |
773 | #endif | |
774 | ||
775 | /* shouldn't be called, since all sections are IN_MEMORY */ | |
776 | ||
777 | return false; | |
778 | } | |
779 | ||
780 | /* Read the contents of a section. | |
781 | buf points to a buffer of buf_size bytes to be filled with | |
782 | section data (starting at offset into section) */ | |
783 | ||
784 | static boolean | |
785 | vms_get_section_contents_in_window (abfd, section, w, offset, count) | |
5f771d47 ILT |
786 | bfd *abfd ATTRIBUTE_UNUSED; |
787 | asection *section ATTRIBUTE_UNUSED; | |
788 | bfd_window *w ATTRIBUTE_UNUSED; | |
789 | file_ptr offset ATTRIBUTE_UNUSED; | |
790 | bfd_size_type count ATTRIBUTE_UNUSED; | |
252b5132 RH |
791 | { |
792 | #if VMS_DEBUG | |
793 | vms_debug (1, "vms_get_section_contents_in_window(%p, %s, %p, off %ld, count %d)\n", | |
794 | abfd, section->name, w, offset, (int)count); | |
795 | #endif | |
796 | ||
797 | /* shouldn't be called, since all sections are IN_MEMORY */ | |
798 | ||
799 | return false; | |
800 | } | |
801 | ||
802 | /*-- Part 4.2, copy private data --------------------------------------------*/ | |
803 | ||
804 | /* Called to copy BFD general private data from one object file | |
805 | to another. */ | |
806 | ||
807 | static boolean | |
808 | vms_bfd_copy_private_bfd_data (src, dest) | |
5f771d47 ILT |
809 | bfd *src ATTRIBUTE_UNUSED; |
810 | bfd *dest ATTRIBUTE_UNUSED; | |
252b5132 RH |
811 | { |
812 | #if VMS_DEBUG | |
813 | vms_debug (1, "vms_bfd_copy_private_bfd_data(%p, %p)\n", src, dest); | |
814 | #endif | |
815 | return true; | |
816 | } | |
817 | ||
252b5132 RH |
818 | /* Merge private BFD information from the BFD @var{ibfd} to the |
819 | the output file BFD @var{obfd} when linking. Return <<true>> | |
820 | on success, <<false>> on error. Possible error returns are: | |
821 | ||
822 | o <<bfd_error_no_memory>> - | |
823 | Not enough memory exists to create private data for @var{obfd}. */ | |
824 | ||
825 | static boolean | |
826 | vms_bfd_merge_private_bfd_data (ibfd, obfd) | |
5f771d47 ILT |
827 | bfd *ibfd ATTRIBUTE_UNUSED; |
828 | bfd *obfd ATTRIBUTE_UNUSED; | |
252b5132 RH |
829 | { |
830 | #if VMS_DEBUG | |
831 | vms_debug (1,"vms_bfd_merge_private_bfd_data(%p, %p)\n", ibfd, obfd); | |
832 | #endif | |
833 | return true; | |
834 | } | |
835 | ||
252b5132 RH |
836 | /* Set private BFD flag information in the BFD @var{abfd}. |
837 | Return <<true>> on success, <<false>> on error. Possible error | |
838 | returns are: | |
839 | ||
840 | o <<bfd_error_no_memory>> - | |
841 | Not enough memory exists to create private data for @var{obfd}. */ | |
842 | ||
843 | static boolean | |
844 | vms_bfd_set_private_flags (abfd, flags) | |
5f771d47 ILT |
845 | bfd *abfd ATTRIBUTE_UNUSED; |
846 | flagword flags ATTRIBUTE_UNUSED; | |
252b5132 RH |
847 | { |
848 | #if VMS_DEBUG | |
849 | vms_debug (1,"vms_bfd_set_private_flags(%p, %lx)\n", abfd, (long)flags); | |
850 | #endif | |
851 | return true; | |
852 | } | |
853 | ||
252b5132 RH |
854 | /* Called to copy BFD private section data from one object file |
855 | to another. */ | |
856 | ||
857 | static boolean | |
858 | vms_bfd_copy_private_section_data (srcbfd, srcsec, dstbfd, dstsec) | |
5f771d47 ILT |
859 | bfd *srcbfd ATTRIBUTE_UNUSED; |
860 | asection *srcsec ATTRIBUTE_UNUSED; | |
861 | bfd *dstbfd ATTRIBUTE_UNUSED; | |
862 | asection *dstsec ATTRIBUTE_UNUSED; | |
252b5132 RH |
863 | { |
864 | #if VMS_DEBUG | |
865 | vms_debug (1, "vms_bfd_copy_private_section_data(%p, %s, %p, %s)\n", | |
866 | srcbfd, srcsec->name, dstbfd, dstsec->name); | |
867 | #endif | |
868 | return true; | |
869 | } | |
870 | ||
871 | /* Called to copy BFD private symbol data from one object file | |
872 | to another. */ | |
873 | ||
55f2d5ed | 874 | static boolean |
252b5132 | 875 | vms_bfd_copy_private_symbol_data (ibfd, isym, obfd, osym) |
5f771d47 ILT |
876 | bfd *ibfd ATTRIBUTE_UNUSED; |
877 | asymbol *isym ATTRIBUTE_UNUSED; | |
878 | bfd *obfd ATTRIBUTE_UNUSED; | |
879 | asymbol *osym ATTRIBUTE_UNUSED; | |
252b5132 RH |
880 | { |
881 | #if VMS_DEBUG | |
882 | vms_debug (1, "vms_bfd_copy_private_symbol_data(%p, %s, %p, %s)\n", | |
883 | ibfd, isym->name, obfd, osym->name); | |
884 | #endif | |
885 | return true; | |
886 | } | |
887 | ||
888 | /*-- Part 4.3, core file ----------------------------------------------------*/ | |
889 | ||
890 | /* Return a read-only string explaining which program was running | |
891 | when it failed and produced the core file abfd. */ | |
892 | ||
893 | static char * | |
894 | vms_core_file_failing_command (abfd) | |
5f771d47 | 895 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
896 | { |
897 | #if VMS_DEBUG | |
898 | vms_debug (1, "vms_core_file_failing_command(%p)\n", abfd); | |
899 | #endif | |
900 | return 0; | |
901 | } | |
902 | ||
252b5132 RH |
903 | /* Returns the signal number which caused the core dump which |
904 | generated the file the BFD abfd is attached to. */ | |
905 | ||
906 | static int | |
907 | vms_core_file_failing_signal (abfd) | |
5f771d47 | 908 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
909 | { |
910 | #if VMS_DEBUG | |
911 | vms_debug (1, "vms_core_file_failing_signal(%p)\n", abfd); | |
912 | #endif | |
913 | return 0; | |
914 | } | |
915 | ||
252b5132 RH |
916 | /* Return true if the core file attached to core_bfd was generated |
917 | by a run of the executable file attached to exec_bfd, false otherwise. */ | |
918 | ||
919 | static boolean | |
920 | vms_core_file_matches_executable_p (abfd, bbfd) | |
5f771d47 ILT |
921 | bfd *abfd ATTRIBUTE_UNUSED; |
922 | bfd *bbfd ATTRIBUTE_UNUSED; | |
252b5132 RH |
923 | { |
924 | #if VMS_DEBUG | |
925 | vms_debug (1, "vms_core_file_matches_executable_p(%p, %p)\n", abfd, bbfd); | |
926 | #endif | |
927 | return false; | |
928 | } | |
929 | ||
930 | /*-- Part 4.4, archive ------------------------------------------------------*/ | |
931 | ||
932 | /* ??? do something with an archive map. | |
933 | Return false on error, true otherwise. */ | |
934 | ||
935 | static boolean | |
936 | vms_slurp_armap (abfd) | |
5f771d47 | 937 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
938 | { |
939 | #if VMS_DEBUG | |
940 | vms_debug (1, "vms_slurp_armap(%p)\n", abfd); | |
941 | #endif | |
942 | return false; | |
943 | } | |
944 | ||
252b5132 RH |
945 | /* ??? do something with an extended name table. |
946 | Return false on error, true otherwise. */ | |
947 | ||
948 | static boolean | |
949 | vms_slurp_extended_name_table (abfd) | |
5f771d47 | 950 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
951 | { |
952 | #if VMS_DEBUG | |
953 | vms_debug (1, "vms_slurp_extended_name_table(%p)\n", abfd); | |
954 | #endif | |
955 | return false; | |
956 | } | |
957 | ||
252b5132 RH |
958 | /* ??? do something with an extended name table. |
959 | Return false on error, true otherwise. */ | |
960 | ||
961 | static boolean | |
962 | vms_construct_extended_name_table (abfd, tabloc, tablen, name) | |
5f771d47 ILT |
963 | bfd *abfd ATTRIBUTE_UNUSED; |
964 | char **tabloc ATTRIBUTE_UNUSED; | |
965 | bfd_size_type *tablen ATTRIBUTE_UNUSED; | |
966 | const char **name ATTRIBUTE_UNUSED; | |
252b5132 RH |
967 | { |
968 | #if VMS_DEBUG | |
969 | vms_debug (1, "vms_construct_extended_name_table(%p)\n", abfd); | |
970 | #endif | |
971 | return false; | |
972 | } | |
973 | ||
252b5132 RH |
974 | /* Truncate the name of an archive to match system-dependent restrictions */ |
975 | ||
976 | static void | |
977 | vms_truncate_arname (abfd, pathname, arhdr) | |
5f771d47 ILT |
978 | bfd *abfd ATTRIBUTE_UNUSED; |
979 | CONST char *pathname ATTRIBUTE_UNUSED; | |
980 | char *arhdr ATTRIBUTE_UNUSED; | |
252b5132 RH |
981 | { |
982 | #if VMS_DEBUG | |
983 | vms_debug (1, "vms_truncate_arname(%p, %s, %s)\n", abfd, pathname, arhdr); | |
984 | #endif | |
985 | return; | |
986 | } | |
987 | ||
252b5132 RH |
988 | /* ??? write archive map */ |
989 | ||
990 | static boolean | |
991 | vms_write_armap (arch, elength, map, orl_count, stridx) | |
5f771d47 ILT |
992 | bfd *arch ATTRIBUTE_UNUSED; |
993 | unsigned int elength ATTRIBUTE_UNUSED; | |
994 | struct orl *map ATTRIBUTE_UNUSED; | |
995 | unsigned int orl_count ATTRIBUTE_UNUSED; | |
996 | int stridx ATTRIBUTE_UNUSED; | |
252b5132 RH |
997 | { |
998 | #if VMS_DEBUG | |
999 | vms_debug (1, "vms_write_armap(%p, %d, %p, %d %d)\n", | |
1000 | arch, elength, map, orl_count, stridx); | |
1001 | #endif | |
1002 | return true; | |
1003 | } | |
1004 | ||
1005 | /* Read archive header ??? */ | |
1006 | ||
1007 | static PTR | |
1008 | vms_read_ar_hdr (abfd) | |
5f771d47 | 1009 | bfd * abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1010 | { |
1011 | #if VMS_DEBUG | |
1012 | vms_debug (1, "vms_read_ar_hdr(%p)\n", abfd); | |
1013 | #endif | |
1014 | return (PTR)0; | |
1015 | } | |
1016 | ||
252b5132 RH |
1017 | /* Provided a BFD, @var{archive}, containing an archive and NULL, open |
1018 | an input BFD on the first contained element and returns that. | |
1019 | Subsequent calls should pass the archive and the previous return value | |
1020 | to return a created BFD to the next contained element. | |
1021 | NULL is returned when there are no more. */ | |
1022 | ||
1023 | static bfd * | |
1024 | vms_openr_next_archived_file (arch, prev) | |
5f771d47 ILT |
1025 | bfd *arch ATTRIBUTE_UNUSED; |
1026 | bfd *prev ATTRIBUTE_UNUSED; | |
252b5132 RH |
1027 | { |
1028 | #if VMS_DEBUG | |
1029 | vms_debug (1, "vms_openr_next_archived_file(%p, %p)\n", arch, prev); | |
1030 | #endif | |
01fff6e2 | 1031 | return NULL; |
252b5132 RH |
1032 | } |
1033 | ||
252b5132 RH |
1034 | /* Return the BFD which is referenced by the symbol in ABFD indexed by |
1035 | INDEX. INDEX should have been returned by bfd_get_next_mapent. */ | |
1036 | ||
1037 | static bfd * | |
1038 | vms_get_elt_at_index (abfd, index) | |
1039 | bfd *abfd; | |
1040 | symindex index; | |
1041 | { | |
1042 | #if VMS_DEBUG | |
1043 | vms_debug (1, "vms_get_elt_at_index(%p, %p)\n", abfd, index); | |
1044 | #endif | |
1045 | return _bfd_generic_get_elt_at_index(abfd, index); | |
1046 | } | |
1047 | ||
252b5132 RH |
1048 | /* ??? |
1049 | -> bfd_generic_stat_arch_elt */ | |
1050 | ||
1051 | static int | |
1052 | vms_generic_stat_arch_elt (abfd, stat) | |
1053 | bfd *abfd; | |
1054 | struct stat *stat; | |
1055 | { | |
1056 | #if VMS_DEBUG | |
1057 | vms_debug (1, "vms_generic_stat_arch_elt(%p, %p)\n", abfd, stat); | |
1058 | #endif | |
1059 | return bfd_generic_stat_arch_elt(abfd, stat); | |
1060 | } | |
1061 | ||
252b5132 RH |
1062 | /* This is a new function in bfd 2.5 */ |
1063 | ||
1064 | static boolean | |
1065 | vms_update_armap_timestamp (abfd) | |
5f771d47 | 1066 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1067 | { |
1068 | #if VMS_DEBUG | |
1069 | vms_debug (1, "vms_update_armap_timestamp(%p)\n", abfd); | |
1070 | #endif | |
1071 | return true; | |
1072 | } | |
1073 | ||
1074 | /*-- Part 4.5, symbols --------------------------------------------------------*/ | |
1075 | ||
1076 | /* Return the number of bytes required to store a vector of pointers | |
1077 | to asymbols for all the symbols in the BFD abfd, including a | |
1078 | terminal NULL pointer. If there are no symbols in the BFD, | |
1079 | then return 0. If an error occurs, return -1. */ | |
1080 | ||
1081 | static long | |
1082 | vms_get_symtab_upper_bound (abfd) | |
1083 | bfd *abfd; | |
1084 | { | |
1085 | #if VMS_DEBUG | |
8a0c27cd | 1086 | vms_debug (1, "vms_get_symtab_upper_bound(%p), %d symbols\n", abfd, PRIV (gsd_sym_count)); |
252b5132 | 1087 | #endif |
8a0c27cd | 1088 | return (PRIV (gsd_sym_count)+1) * sizeof (asymbol *); |
252b5132 RH |
1089 | } |
1090 | ||
252b5132 RH |
1091 | /* Copy symbols from hash table to symbol vector |
1092 | ||
1093 | called from bfd_hash_traverse in vms_get_symtab | |
1094 | init counter to 0 if entry == 0 */ | |
1095 | ||
1096 | static boolean | |
1097 | copy_symbols (entry, arg) | |
1098 | struct bfd_hash_entry *entry; | |
1099 | PTR arg; | |
1100 | { | |
1101 | bfd *abfd = (bfd *) arg; | |
1102 | ||
1103 | if (entry == NULL) /* init counter */ | |
8a0c27cd | 1104 | PRIV (symnum) = 0; |
252b5132 | 1105 | else /* fill vector, inc counter */ |
8a0c27cd | 1106 | PRIV (symcache)[PRIV (symnum)++] = ((vms_symbol_entry *)entry)->symbol; |
252b5132 RH |
1107 | |
1108 | return true; | |
1109 | } | |
1110 | ||
252b5132 RH |
1111 | /* Read the symbols from the BFD abfd, and fills in the vector |
1112 | location with pointers to the symbols and a trailing NULL. | |
1113 | ||
1114 | return # of symbols read */ | |
1115 | ||
1116 | static long | |
1117 | vms_get_symtab (abfd, symbols) | |
1118 | bfd *abfd; | |
1119 | asymbol **symbols; | |
1120 | { | |
1121 | #if VMS_DEBUG | |
1122 | vms_debug (1, "vms_get_symtab(%p, <ret>)\n", abfd); | |
1123 | #endif | |
1124 | ||
1125 | /* init counter */ | |
1126 | (void)copy_symbols((struct bfd_hash_entry *)0, abfd); | |
1127 | ||
1128 | /* traverse table and fill symbols vector */ | |
1129 | ||
8a0c27cd KH |
1130 | PRIV (symcache) = symbols; |
1131 | bfd_hash_traverse(PRIV (vms_symbol_table), copy_symbols, (PTR)abfd); | |
252b5132 | 1132 | |
8a0c27cd | 1133 | symbols[PRIV (gsd_sym_count)] = NULL; |
252b5132 | 1134 | |
8a0c27cd | 1135 | return PRIV (gsd_sym_count); |
252b5132 RH |
1136 | } |
1137 | ||
252b5132 RH |
1138 | /* Create a new asymbol structure for the BFD abfd and return a pointer |
1139 | to it. | |
1140 | This routine is necessary because each back end has private information | |
1141 | surrounding the asymbol. Building your own asymbol and pointing to it | |
1142 | will not create the private information, and will cause problems later on. */ | |
1143 | ||
1144 | asymbol * | |
1145 | _bfd_vms_make_empty_symbol (abfd) | |
1146 | bfd *abfd; | |
1147 | { | |
55f2d5ed | 1148 | asymbol *symbol = (asymbol *)bfd_zalloc(abfd, sizeof (asymbol)); |
252b5132 RH |
1149 | |
1150 | #if VMS_DEBUG | |
1151 | vms_debug (1, "_bfd_vms_make_empty_symbol(%p)\n", abfd); | |
1152 | #endif | |
1153 | ||
1154 | if (symbol == 0) | |
1155 | { | |
1156 | bfd_set_error (bfd_error_no_memory); | |
1157 | return 0; | |
1158 | } | |
1159 | symbol->the_bfd = abfd; | |
1160 | ||
1161 | return symbol; | |
1162 | } | |
1163 | ||
252b5132 RH |
1164 | /* Print symbol to file according to how. how is one of |
1165 | bfd_print_symbol_name just print the name | |
1166 | bfd_print_symbol_more print more (???) | |
1167 | bfd_print_symbol_all print all we know, which is not much right now :-) */ | |
1168 | ||
1169 | static void | |
1170 | vms_print_symbol (abfd, file, symbol, how) | |
5f771d47 | 1171 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1172 | PTR file; |
1173 | asymbol *symbol; | |
1174 | bfd_print_symbol_type how; | |
1175 | { | |
1176 | #if VMS_DEBUG | |
1177 | vms_debug (1, "vms_print_symbol(%p, %p, %p, %d)\n", abfd, file, symbol, how); | |
1178 | #endif | |
1179 | ||
1180 | switch (how) | |
1181 | { | |
1182 | case bfd_print_symbol_name: | |
1183 | case bfd_print_symbol_more: | |
55f2d5ed | 1184 | fprintf ((FILE *)file," %s", symbol->name); |
252b5132 RH |
1185 | break; |
1186 | ||
252b5132 RH |
1187 | case bfd_print_symbol_all: |
1188 | { | |
1189 | CONST char *section_name = symbol->section->name; | |
1190 | ||
1191 | bfd_print_symbol_vandf((PTR)file,symbol); | |
1192 | ||
55f2d5ed | 1193 | fprintf ((FILE *)file," %-8s %s", section_name, symbol->name); |
252b5132 RH |
1194 | } |
1195 | break; | |
1196 | } | |
1197 | return; | |
1198 | } | |
1199 | ||
252b5132 RH |
1200 | /* Return information about symbol in ret. |
1201 | ||
1202 | fill type, value and name | |
1203 | type: | |
1204 | A absolute | |
1205 | B bss segment symbol | |
1206 | C common symbol | |
1207 | D data segment symbol | |
1208 | f filename | |
1209 | t a static function symbol | |
1210 | T text segment symbol | |
1211 | U undefined | |
1212 | - debug */ | |
1213 | ||
1214 | static void | |
1215 | vms_get_symbol_info (abfd, symbol, ret) | |
5f771d47 | 1216 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1217 | asymbol *symbol; |
1218 | symbol_info *ret; | |
1219 | { | |
1220 | asection *sec; | |
1221 | ||
1222 | #if VMS_DEBUG | |
1223 | vms_debug (1, "vms_get_symbol_info(%p, %p, %p)\n", abfd, symbol, ret); | |
1224 | #endif | |
1225 | ||
1226 | sec = symbol->section; | |
1227 | ||
1228 | if (ret == 0) | |
1229 | return; | |
1230 | ||
1231 | if (bfd_is_com_section (sec)) | |
1232 | ret->type = 'C'; | |
1233 | else if (bfd_is_abs_section (sec)) | |
1234 | ret->type = 'A'; | |
1235 | else if (bfd_is_und_section (sec)) | |
1236 | ret->type = 'U'; | |
1237 | else if (bfd_is_ind_section (sec)) | |
1238 | ret->type = 'I'; | |
1239 | else if (bfd_get_section_flags (abfd, sec) & SEC_CODE) | |
1240 | ret->type = 'T'; | |
1241 | else if (bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
1242 | ret->type = 'D'; | |
1243 | else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
1244 | ret->type = 'B'; | |
1245 | else | |
1246 | ret->type = '-'; | |
1247 | ||
1248 | if (ret->type != 'U') | |
1249 | ret->value = symbol->value + symbol->section->vma; | |
1250 | else | |
1251 | ret->value = 0; | |
1252 | ret->name = symbol->name; | |
1253 | ||
1254 | return; | |
1255 | } | |
1256 | ||
252b5132 RH |
1257 | /* Return true if the given symbol sym in the BFD abfd is |
1258 | a compiler generated local label, else return false. */ | |
1259 | ||
1260 | static boolean | |
1261 | vms_bfd_is_local_label_name (abfd, name) | |
5f771d47 | 1262 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1263 | const char *name; |
1264 | { | |
1265 | #if VMS_DEBUG | |
1266 | vms_debug (1, "vms_bfd_is_local_label_name(%p, %s)\n", abfd, name); | |
1267 | #endif | |
1268 | return name[0] == '$'; | |
1269 | } | |
1270 | ||
252b5132 RH |
1271 | /* Get source line number for symbol */ |
1272 | ||
1273 | static alent * | |
1274 | vms_get_lineno (abfd, symbol) | |
5f771d47 ILT |
1275 | bfd *abfd ATTRIBUTE_UNUSED; |
1276 | asymbol *symbol ATTRIBUTE_UNUSED; | |
252b5132 RH |
1277 | { |
1278 | #if VMS_DEBUG | |
1279 | vms_debug (1, "vms_get_lineno(%p, %p)\n", abfd, symbol); | |
1280 | #endif | |
1281 | return 0; | |
1282 | } | |
1283 | ||
252b5132 RH |
1284 | /* Provided a BFD, a section and an offset into the section, calculate and |
1285 | return the name of the source file and the line nearest to the wanted | |
1286 | location. */ | |
1287 | ||
1288 | static boolean | |
1289 | vms_find_nearest_line (abfd, section, symbols, offset, file, func, line) | |
5f771d47 ILT |
1290 | bfd *abfd ATTRIBUTE_UNUSED; |
1291 | asection *section ATTRIBUTE_UNUSED; | |
1292 | asymbol **symbols ATTRIBUTE_UNUSED; | |
1293 | bfd_vma offset ATTRIBUTE_UNUSED; | |
1294 | CONST char **file ATTRIBUTE_UNUSED; | |
1295 | CONST char **func ATTRIBUTE_UNUSED; | |
1296 | unsigned int *line ATTRIBUTE_UNUSED; | |
252b5132 RH |
1297 | { |
1298 | #if VMS_DEBUG | |
1299 | vms_debug (1, "vms_find_nearest_line(%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n", | |
1300 | abfd, section->name, symbols, (long int)offset); | |
1301 | #endif | |
1302 | return false; | |
1303 | } | |
1304 | ||
252b5132 RH |
1305 | /* Back-door to allow format-aware applications to create debug symbols |
1306 | while using BFD for everything else. Currently used by the assembler | |
1307 | when creating COFF files. */ | |
1308 | ||
1309 | static asymbol * | |
1310 | vms_bfd_make_debug_symbol (abfd, ptr, size) | |
5f771d47 ILT |
1311 | bfd *abfd ATTRIBUTE_UNUSED; |
1312 | void *ptr ATTRIBUTE_UNUSED; | |
1313 | unsigned long size ATTRIBUTE_UNUSED; | |
252b5132 RH |
1314 | { |
1315 | #if VMS_DEBUG | |
1316 | vms_debug (1, "vms_bfd_make_debug_symbol(%p, %p, %ld)\n", abfd, ptr, size); | |
1317 | #endif | |
1318 | return 0; | |
1319 | } | |
1320 | ||
252b5132 RH |
1321 | /* Read minisymbols. For minisymbols, we use the unmodified a.out |
1322 | symbols. The minisymbol_to_symbol function translates these into | |
1323 | BFD asymbol structures. */ | |
1324 | ||
1325 | static long | |
1326 | vms_read_minisymbols (abfd, dynamic, minisymsp, sizep) | |
1327 | bfd *abfd; | |
1328 | boolean dynamic; | |
1329 | PTR *minisymsp; | |
1330 | unsigned int *sizep; | |
1331 | { | |
1332 | #if VMS_DEBUG | |
1333 | vms_debug (1, "vms_read_minisymbols(%p, %d, %p, %d)\n", abfd, dynamic, minisymsp, *sizep); | |
1334 | #endif | |
1335 | return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep); | |
1336 | } | |
1337 | ||
1338 | /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an | |
1339 | unmodified a.out symbol. The SYM argument is a structure returned | |
1340 | by bfd_make_empty_symbol, which we fill in here. */ | |
1341 | ||
1342 | static asymbol * | |
1343 | vms_minisymbol_to_symbol (abfd, dynamic, minisym, sym) | |
1344 | bfd *abfd; | |
1345 | boolean dynamic; | |
1346 | const PTR minisym; | |
1347 | asymbol *sym; | |
1348 | { | |
1349 | #if VMS_DEBUG | |
1350 | vms_debug (1, "vms_minisymbol_to_symbol(%p, %d, %p, %p)\n", abfd, dynamic, minisym, sym); | |
1351 | #endif | |
1352 | return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym); | |
1353 | } | |
1354 | ||
1355 | /*-- Part 4.6, relocations --------------------------------------------------*/ | |
1356 | ||
1357 | /* Return the number of bytes required to store the relocation information | |
1358 | associated with section sect attached to bfd abfd. | |
1359 | If an error occurs, return -1. */ | |
1360 | ||
1361 | static long | |
1362 | vms_get_reloc_upper_bound (abfd, section) | |
5f771d47 ILT |
1363 | bfd *abfd ATTRIBUTE_UNUSED; |
1364 | asection *section ATTRIBUTE_UNUSED; | |
252b5132 RH |
1365 | { |
1366 | #if VMS_DEBUG | |
1367 | vms_debug (1, "vms_get_reloc_upper_bound(%p, %s)\n", abfd, section->name); | |
1368 | #endif | |
1369 | return -1L; | |
1370 | } | |
1371 | ||
252b5132 RH |
1372 | /* Call the back end associated with the open BFD abfd and translate the |
1373 | external form of the relocation information attached to sec into the | |
1374 | internal canonical form. Place the table into memory at loc, which has | |
1375 | been preallocated, usually by a call to bfd_get_reloc_upper_bound. | |
1376 | Returns the number of relocs, or -1 on error. */ | |
1377 | ||
1378 | static long | |
1379 | vms_canonicalize_reloc (abfd, section, location, symbols) | |
5f771d47 ILT |
1380 | bfd *abfd ATTRIBUTE_UNUSED; |
1381 | asection *section ATTRIBUTE_UNUSED; | |
1382 | arelent **location ATTRIBUTE_UNUSED; | |
1383 | asymbol **symbols ATTRIBUTE_UNUSED; | |
252b5132 RH |
1384 | { |
1385 | #if VMS_DEBUG | |
1386 | vms_debug (1, "vms_canonicalize_reloc(%p, %s, <ret>, <ret>)\n", abfd, section->name); | |
1387 | #endif | |
1388 | return false; | |
1389 | } | |
1390 | ||
1391 | /*---------------------------------------------------------------------------*/ | |
1392 | /* this is just copied from ecoff-alpha, needs to be fixed probably */ | |
1393 | ||
1394 | /* How to process the various reloc types. */ | |
1395 | ||
1396 | static bfd_reloc_status_type | |
1397 | reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message) | |
5f771d47 ILT |
1398 | bfd *abfd ATTRIBUTE_UNUSED; |
1399 | arelent *reloc ATTRIBUTE_UNUSED; | |
1400 | asymbol *sym ATTRIBUTE_UNUSED; | |
1401 | PTR data ATTRIBUTE_UNUSED; | |
1402 | asection *sec ATTRIBUTE_UNUSED; | |
1403 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
1404 | char **error_message ATTRIBUTE_UNUSED; | |
252b5132 RH |
1405 | { |
1406 | #if VMS_DEBUG | |
1407 | vms_debug (1, "reloc_nil(abfd %p, output_bfd %p)\n", abfd, output_bfd); | |
1408 | vms_debug (2, "In section %s, symbol %s\n", | |
1409 | sec->name, sym->name); | |
1410 | vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n", | |
1411 | reloc->sym_ptr_ptr[0]->name, | |
1412 | (unsigned long)reloc->address, | |
1413 | (unsigned long)reloc->addend, reloc->howto->name); | |
1414 | vms_debug (2, "data at %p\n", data); | |
1415 | /* _bfd_hexdump (2, data, bfd_get_reloc_size(reloc->howto),0); */ | |
1416 | #endif | |
1417 | ||
1418 | return bfd_reloc_ok; | |
1419 | } | |
1420 | ||
1421 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
1422 | from smaller values. Start with zero, widen, *then* decrement. */ | |
1423 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
1424 | ||
1425 | static reloc_howto_type alpha_howto_table[] = | |
1426 | { | |
1427 | HOWTO (ALPHA_R_IGNORE, /* type */ | |
1428 | 0, /* rightshift */ | |
1429 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1430 | 8, /* bitsize */ | |
1431 | true, /* pc_relative */ | |
1432 | 0, /* bitpos */ | |
1433 | complain_overflow_dont, /* complain_on_overflow */ | |
1434 | reloc_nil, /* special_function */ | |
1435 | "IGNORE", /* name */ | |
1436 | true, /* partial_inplace */ | |
1437 | 0, /* src_mask */ | |
1438 | 0, /* dst_mask */ | |
1439 | true), /* pcrel_offset */ | |
1440 | ||
1441 | /* A 64 bit reference to a symbol. */ | |
1442 | HOWTO (ALPHA_R_REFQUAD, /* type */ | |
1443 | 0, /* rightshift */ | |
1444 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1445 | 64, /* bitsize */ | |
1446 | false, /* pc_relative */ | |
1447 | 0, /* bitpos */ | |
1448 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1449 | reloc_nil, /* special_function */ | |
1450 | "REFQUAD", /* name */ | |
1451 | true, /* partial_inplace */ | |
1452 | MINUS_ONE, /* src_mask */ | |
1453 | MINUS_ONE, /* dst_mask */ | |
1454 | false), /* pcrel_offset */ | |
1455 | ||
1456 | /* A 21 bit branch. The native assembler generates these for | |
1457 | branches within the text segment, and also fills in the PC | |
1458 | relative offset in the instruction. */ | |
1459 | HOWTO (ALPHA_R_BRADDR, /* type */ | |
1460 | 2, /* rightshift */ | |
1461 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1462 | 21, /* bitsize */ | |
1463 | true, /* pc_relative */ | |
1464 | 0, /* bitpos */ | |
1465 | complain_overflow_signed, /* complain_on_overflow */ | |
1466 | reloc_nil, /* special_function */ | |
1467 | "BRADDR", /* name */ | |
1468 | true, /* partial_inplace */ | |
1469 | 0x1fffff, /* src_mask */ | |
1470 | 0x1fffff, /* dst_mask */ | |
1471 | false), /* pcrel_offset */ | |
1472 | ||
1473 | /* A hint for a jump to a register. */ | |
1474 | HOWTO (ALPHA_R_HINT, /* type */ | |
1475 | 2, /* rightshift */ | |
1476 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1477 | 14, /* bitsize */ | |
1478 | true, /* pc_relative */ | |
1479 | 0, /* bitpos */ | |
1480 | complain_overflow_dont, /* complain_on_overflow */ | |
1481 | reloc_nil, /* special_function */ | |
1482 | "HINT", /* name */ | |
1483 | true, /* partial_inplace */ | |
1484 | 0x3fff, /* src_mask */ | |
1485 | 0x3fff, /* dst_mask */ | |
1486 | false), /* pcrel_offset */ | |
1487 | ||
1488 | /* 16 bit PC relative offset. */ | |
1489 | HOWTO (ALPHA_R_SREL16, /* type */ | |
1490 | 0, /* rightshift */ | |
1491 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1492 | 16, /* bitsize */ | |
1493 | true, /* pc_relative */ | |
1494 | 0, /* bitpos */ | |
1495 | complain_overflow_signed, /* complain_on_overflow */ | |
1496 | reloc_nil, /* special_function */ | |
1497 | "SREL16", /* name */ | |
1498 | true, /* partial_inplace */ | |
1499 | 0xffff, /* src_mask */ | |
1500 | 0xffff, /* dst_mask */ | |
1501 | false), /* pcrel_offset */ | |
1502 | ||
1503 | /* 32 bit PC relative offset. */ | |
1504 | HOWTO (ALPHA_R_SREL32, /* type */ | |
1505 | 0, /* rightshift */ | |
1506 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1507 | 32, /* bitsize */ | |
1508 | true, /* pc_relative */ | |
1509 | 0, /* bitpos */ | |
1510 | complain_overflow_signed, /* complain_on_overflow */ | |
1511 | reloc_nil, /* special_function */ | |
1512 | "SREL32", /* name */ | |
1513 | true, /* partial_inplace */ | |
1514 | 0xffffffff, /* src_mask */ | |
1515 | 0xffffffff, /* dst_mask */ | |
1516 | false), /* pcrel_offset */ | |
1517 | ||
1518 | /* A 64 bit PC relative offset. */ | |
1519 | HOWTO (ALPHA_R_SREL64, /* type */ | |
1520 | 0, /* rightshift */ | |
1521 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1522 | 64, /* bitsize */ | |
1523 | true, /* pc_relative */ | |
1524 | 0, /* bitpos */ | |
1525 | complain_overflow_signed, /* complain_on_overflow */ | |
1526 | reloc_nil, /* special_function */ | |
1527 | "SREL64", /* name */ | |
1528 | true, /* partial_inplace */ | |
1529 | MINUS_ONE, /* src_mask */ | |
1530 | MINUS_ONE, /* dst_mask */ | |
1531 | false), /* pcrel_offset */ | |
1532 | ||
1533 | /* Push a value on the reloc evaluation stack. */ | |
1534 | HOWTO (ALPHA_R_OP_PUSH, /* type */ | |
1535 | 0, /* rightshift */ | |
1536 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1537 | 0, /* bitsize */ | |
1538 | false, /* pc_relative */ | |
1539 | 0, /* bitpos */ | |
1540 | complain_overflow_dont, /* complain_on_overflow */ | |
1541 | reloc_nil, /* special_function */ | |
1542 | "OP_PUSH", /* name */ | |
1543 | false, /* partial_inplace */ | |
1544 | 0, /* src_mask */ | |
1545 | 0, /* dst_mask */ | |
1546 | false), /* pcrel_offset */ | |
1547 | ||
1548 | /* Store the value from the stack at the given address. Store it in | |
1549 | a bitfield of size r_size starting at bit position r_offset. */ | |
1550 | HOWTO (ALPHA_R_OP_STORE, /* type */ | |
1551 | 0, /* rightshift */ | |
1552 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1553 | 64, /* bitsize */ | |
1554 | false, /* pc_relative */ | |
1555 | 0, /* bitpos */ | |
1556 | complain_overflow_dont, /* complain_on_overflow */ | |
1557 | reloc_nil, /* special_function */ | |
1558 | "OP_STORE", /* name */ | |
1559 | false, /* partial_inplace */ | |
1560 | 0, /* src_mask */ | |
1561 | MINUS_ONE, /* dst_mask */ | |
1562 | false), /* pcrel_offset */ | |
1563 | ||
1564 | /* Subtract the reloc address from the value on the top of the | |
1565 | relocation stack. */ | |
1566 | HOWTO (ALPHA_R_OP_PSUB, /* type */ | |
1567 | 0, /* rightshift */ | |
1568 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1569 | 0, /* bitsize */ | |
1570 | false, /* pc_relative */ | |
1571 | 0, /* bitpos */ | |
1572 | complain_overflow_dont, /* complain_on_overflow */ | |
1573 | reloc_nil, /* special_function */ | |
1574 | "OP_PSUB", /* name */ | |
1575 | false, /* partial_inplace */ | |
1576 | 0, /* src_mask */ | |
1577 | 0, /* dst_mask */ | |
1578 | false), /* pcrel_offset */ | |
1579 | ||
1580 | /* Shift the value on the top of the relocation stack right by the | |
1581 | given value. */ | |
1582 | HOWTO (ALPHA_R_OP_PRSHIFT, /* type */ | |
1583 | 0, /* rightshift */ | |
1584 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1585 | 0, /* bitsize */ | |
1586 | false, /* pc_relative */ | |
1587 | 0, /* bitpos */ | |
1588 | complain_overflow_dont, /* complain_on_overflow */ | |
1589 | reloc_nil, /* special_function */ | |
1590 | "OP_PRSHIFT", /* name */ | |
1591 | false, /* partial_inplace */ | |
1592 | 0, /* src_mask */ | |
1593 | 0, /* dst_mask */ | |
1594 | false), /* pcrel_offset */ | |
1595 | ||
1596 | /* Hack. Linkage is done by linker. */ | |
1597 | HOWTO (ALPHA_R_LINKAGE, /* type */ | |
1598 | 0, /* rightshift */ | |
1599 | 8, /* size (0 = byte, 1 = short, 2 = long) */ | |
1600 | 256, /* bitsize */ | |
1601 | false, /* pc_relative */ | |
1602 | 0, /* bitpos */ | |
1603 | complain_overflow_dont, /* complain_on_overflow */ | |
1604 | reloc_nil, /* special_function */ | |
1605 | "LINKAGE", /* name */ | |
1606 | false, /* partial_inplace */ | |
1607 | 0, /* src_mask */ | |
1608 | 0, /* dst_mask */ | |
1609 | false), /* pcrel_offset */ | |
1610 | ||
1611 | /* A 32 bit reference to a symbol. */ | |
1612 | HOWTO (ALPHA_R_REFLONG, /* type */ | |
1613 | 0, /* rightshift */ | |
1614 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1615 | 32, /* bitsize */ | |
1616 | false, /* pc_relative */ | |
1617 | 0, /* bitpos */ | |
1618 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1619 | reloc_nil, /* special_function */ | |
1620 | "REFLONG", /* name */ | |
1621 | true, /* partial_inplace */ | |
1622 | 0xffffffff, /* src_mask */ | |
1623 | 0xffffffff, /* dst_mask */ | |
1624 | false), /* pcrel_offset */ | |
1625 | ||
1626 | /* A 64 bit reference to a procedure, written as 32 bit value. */ | |
1627 | HOWTO (ALPHA_R_CODEADDR, /* type */ | |
1628 | 0, /* rightshift */ | |
1629 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
1630 | 64, /* bitsize */ | |
1631 | false, /* pc_relative */ | |
1632 | 0, /* bitpos */ | |
1633 | complain_overflow_signed,/* complain_on_overflow */ | |
1634 | reloc_nil, /* special_function */ | |
1635 | "CODEADDR", /* name */ | |
1636 | false, /* partial_inplace */ | |
1637 | 0xffffffff, /* src_mask */ | |
1638 | 0xffffffff, /* dst_mask */ | |
1639 | false), /* pcrel_offset */ | |
1640 | ||
1641 | }; | |
1642 | ||
1643 | /* Return a pointer to a howto structure which, when invoked, will perform | |
1644 | the relocation code on data from the architecture noted. */ | |
1645 | ||
1646 | static const struct reloc_howto_struct * | |
1647 | vms_bfd_reloc_type_lookup (abfd, code) | |
5f771d47 | 1648 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1649 | bfd_reloc_code_real_type code; |
1650 | { | |
1651 | int alpha_type; | |
1652 | ||
1653 | #if VMS_DEBUG | |
1654 | vms_debug (1, "vms_bfd_reloc_type_lookup(%p, %d)\t", abfd, code); | |
1655 | #endif | |
1656 | ||
1657 | switch (code) | |
1658 | { | |
1659 | case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break; | |
1660 | case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break; | |
1661 | case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break; | |
1662 | case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break; | |
1663 | case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break; | |
1664 | case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break; | |
1665 | case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break; | |
1666 | case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break; | |
1667 | case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break; | |
1668 | case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break; | |
1669 | case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break; | |
1670 | default: | |
1671 | (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code); | |
1672 | return (const struct reloc_howto_struct *) NULL; | |
1673 | } | |
1674 | #if VMS_DEBUG | |
1675 | vms_debug (2, "reloc is %s\n", alpha_howto_table[alpha_type].name); | |
1676 | #endif | |
1677 | return &alpha_howto_table[alpha_type]; | |
1678 | } | |
1679 | ||
252b5132 RH |
1680 | /*-- Part 4.7, writing an object file ---------------------------------------*/ |
1681 | ||
1682 | /* Set the architecture and machine type in BFD abfd to arch and mach. | |
1683 | Find the correct pointer to a structure and insert it into the arch_info | |
1684 | pointer. */ | |
1685 | ||
1686 | static boolean | |
1687 | vms_set_arch_mach (abfd, arch, mach) | |
1688 | bfd *abfd; | |
5f771d47 ILT |
1689 | enum bfd_architecture arch ATTRIBUTE_UNUSED; |
1690 | unsigned long mach ATTRIBUTE_UNUSED; | |
252b5132 RH |
1691 | { |
1692 | #if VMS_DEBUG | |
1693 | vms_debug (1, "vms_set_arch_mach(%p, %d, %ld)\n", abfd, arch, mach); | |
1694 | #endif | |
1695 | abfd->arch_info = bfd_scan_arch("alpha"); | |
1696 | ||
1697 | return true; | |
1698 | } | |
1699 | ||
252b5132 RH |
1700 | /* Sets the contents of the section section in BFD abfd to the data starting |
1701 | in memory at data. The data is written to the output section starting at | |
1702 | offset offset for count bytes. | |
1703 | ||
1704 | Normally true is returned, else false. Possible error returns are: | |
1705 | o bfd_error_no_contents - The output section does not have the | |
1706 | SEC_HAS_CONTENTS attribute, so nothing can be written to it. | |
1707 | o and some more too */ | |
1708 | ||
1709 | static boolean | |
1710 | vms_set_section_contents (abfd, section, location, offset, count) | |
1711 | bfd *abfd; | |
1712 | asection *section; | |
1713 | PTR location; | |
1714 | file_ptr offset; | |
1715 | bfd_size_type count; | |
1716 | { | |
1717 | #if VMS_DEBUG | |
1718 | vms_debug (1, "vms_set_section_contents(%p, sec %s, loc %p, off %ld, count %d)\n", | |
1719 | abfd, section->name, location, (long int)offset, (int)count); | |
1720 | vms_debug (2, "secraw %d, seccooked %d\n", (int)section->_raw_size, (int)section->_cooked_size); | |
1721 | #endif | |
1722 | return _bfd_save_vms_section(abfd, section, location, offset, count); | |
1723 | } | |
1724 | ||
252b5132 RH |
1725 | /*-- Part 4.8, linker -------------------------------------------------------*/ |
1726 | ||
1727 | /* Get the size of the section headers. */ | |
1728 | ||
1729 | static int | |
1730 | vms_sizeof_headers (abfd, reloc) | |
5f771d47 ILT |
1731 | bfd *abfd ATTRIBUTE_UNUSED; |
1732 | boolean reloc ATTRIBUTE_UNUSED; | |
252b5132 RH |
1733 | { |
1734 | #if VMS_DEBUG | |
1735 | vms_debug (1, "vms_sizeof_headers(%p, %s)\n", abfd, (reloc)?"True":"False"); | |
1736 | #endif | |
1737 | return 0; | |
1738 | } | |
1739 | ||
252b5132 RH |
1740 | /* Provides default handling of relocation effort for back ends |
1741 | which can't be bothered to do it efficiently. */ | |
1742 | ||
1743 | static bfd_byte * | |
1744 | vms_bfd_get_relocated_section_contents (abfd, link_info, link_order, data, | |
1745 | relocateable, symbols) | |
5f771d47 ILT |
1746 | bfd *abfd ATTRIBUTE_UNUSED; |
1747 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
1748 | struct bfd_link_order *link_order ATTRIBUTE_UNUSED; | |
1749 | bfd_byte *data ATTRIBUTE_UNUSED; | |
1750 | boolean relocateable ATTRIBUTE_UNUSED; | |
1751 | asymbol **symbols ATTRIBUTE_UNUSED; | |
252b5132 RH |
1752 | { |
1753 | #if VMS_DEBUG | |
1754 | vms_debug (1, "vms_bfd_get_relocated_section_contents(%p, %p, %p, %p, %s, %p)\n", | |
1755 | abfd, link_info, link_order, data, (relocateable)?"True":"False", symbols); | |
1756 | #endif | |
1757 | return 0; | |
1758 | } | |
1759 | ||
252b5132 RH |
1760 | /* ??? */ |
1761 | ||
1762 | static boolean | |
1763 | vms_bfd_relax_section (abfd, section, link_info, again) | |
5f771d47 ILT |
1764 | bfd *abfd ATTRIBUTE_UNUSED; |
1765 | asection *section ATTRIBUTE_UNUSED; | |
1766 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
1767 | boolean *again ATTRIBUTE_UNUSED; | |
252b5132 RH |
1768 | { |
1769 | #if VMS_DEBUG | |
1770 | vms_debug (1, "vms_bfd_relax_section(%p, %s, %p, <ret>)\n", | |
1771 | abfd, section->name, link_info); | |
1772 | #endif | |
1773 | return true; | |
1774 | } | |
1775 | ||
1776 | static boolean | |
1777 | vms_bfd_gc_sections (abfd, link_info) | |
5f771d47 ILT |
1778 | bfd *abfd ATTRIBUTE_UNUSED; |
1779 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
1780 | { |
1781 | #if VMS_DEBUG | |
1782 | vms_debug (1, "vms_bfd_gc_sections(%p, %p)\n", abfd, link_info); | |
1783 | #endif | |
1784 | return true; | |
1785 | } | |
1786 | ||
252b5132 RH |
1787 | /* Create a hash table for the linker. Different backends store |
1788 | different information in this table. */ | |
1789 | ||
1790 | static struct bfd_link_hash_table * | |
1791 | vms_bfd_link_hash_table_create (abfd) | |
5f771d47 | 1792 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1793 | { |
1794 | #if VMS_DEBUG | |
1795 | vms_debug (1, "vms_bfd_link_hash_table_create(%p)\n", abfd); | |
1796 | #endif | |
1797 | return 0; | |
1798 | } | |
1799 | ||
252b5132 RH |
1800 | /* Add symbols from this object file into the hash table. */ |
1801 | ||
1802 | static boolean | |
1803 | vms_bfd_link_add_symbols (abfd, link_info) | |
5f771d47 ILT |
1804 | bfd *abfd ATTRIBUTE_UNUSED; |
1805 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
1806 | { |
1807 | #if VMS_DEBUG | |
1808 | vms_debug (1, "vms_bfd_link_add_symbols(%p, %p)\n", abfd, link_info); | |
1809 | #endif | |
1810 | return false; | |
1811 | } | |
1812 | ||
252b5132 RH |
1813 | /* Do a link based on the link_order structures attached to each |
1814 | section of the BFD. */ | |
1815 | ||
1816 | static boolean | |
1817 | vms_bfd_final_link (abfd, link_info) | |
5f771d47 ILT |
1818 | bfd *abfd ATTRIBUTE_UNUSED; |
1819 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
1820 | { |
1821 | #if VMS_DEBUG | |
1822 | vms_debug (1, "vms_bfd_final_link(%p, %p)\n", abfd, link_info); | |
1823 | #endif | |
1824 | return true; | |
1825 | } | |
1826 | ||
1827 | /* Should this section be split up into smaller pieces during linking. */ | |
1828 | ||
1829 | static boolean | |
1830 | vms_bfd_link_split_section (abfd, section) | |
5f771d47 ILT |
1831 | bfd *abfd ATTRIBUTE_UNUSED; |
1832 | asection *section ATTRIBUTE_UNUSED; | |
252b5132 RH |
1833 | { |
1834 | #if VMS_DEBUG | |
1835 | vms_debug (1, "vms_bfd_link_split_section(%p, %s)\n", abfd, section->name); | |
1836 | #endif | |
1837 | return false; | |
1838 | } | |
1839 | ||
1840 | /*-- Part 4.9, dynamic symbols and relocations ------------------------------*/ | |
1841 | ||
1842 | /* Get the amount of memory required to hold the dynamic symbols. */ | |
1843 | ||
1844 | static long | |
1845 | vms_get_dynamic_symtab_upper_bound (abfd) | |
5f771d47 | 1846 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1847 | { |
1848 | #if VMS_DEBUG | |
1849 | vms_debug (1, "vms_get_dynamic_symtab_upper_bound(%p)\n", abfd); | |
1850 | #endif | |
1851 | return 0; | |
1852 | } | |
1853 | ||
1854 | static boolean | |
1855 | vms_bfd_print_private_bfd_data (abfd, file) | |
5f771d47 ILT |
1856 | bfd *abfd ATTRIBUTE_UNUSED; |
1857 | void *file ATTRIBUTE_UNUSED; | |
252b5132 RH |
1858 | { |
1859 | #if VMS_DEBUG | |
1860 | vms_debug (1, "vms_bfd_print_private_bfd_data(%p)\n", abfd); | |
1861 | #endif | |
1862 | return 0; | |
1863 | } | |
1864 | ||
252b5132 RH |
1865 | /* Read in the dynamic symbols. */ |
1866 | ||
1867 | static long | |
1868 | vms_canonicalize_dynamic_symtab (abfd, symbols) | |
5f771d47 ILT |
1869 | bfd *abfd ATTRIBUTE_UNUSED; |
1870 | asymbol **symbols ATTRIBUTE_UNUSED; | |
252b5132 RH |
1871 | { |
1872 | #if VMS_DEBUG | |
1873 | vms_debug (1, "vms_canonicalize_dynamic_symtab(%p, <ret>)\n", abfd); | |
1874 | #endif | |
1875 | return 0L; | |
1876 | } | |
1877 | ||
252b5132 RH |
1878 | /* Get the amount of memory required to hold the dynamic relocs. */ |
1879 | ||
1880 | static long | |
1881 | vms_get_dynamic_reloc_upper_bound (abfd) | |
5f771d47 | 1882 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1883 | { |
1884 | #if VMS_DEBUG | |
1885 | vms_debug (1, "vms_get_dynamic_reloc_upper_bound(%p)\n", abfd); | |
1886 | #endif | |
1887 | return 0L; | |
1888 | } | |
1889 | ||
252b5132 RH |
1890 | /* Read in the dynamic relocs. */ |
1891 | ||
1892 | static long | |
1893 | vms_canonicalize_dynamic_reloc (abfd, arel, symbols) | |
5f771d47 ILT |
1894 | bfd *abfd ATTRIBUTE_UNUSED; |
1895 | arelent **arel ATTRIBUTE_UNUSED; | |
1896 | asymbol **symbols ATTRIBUTE_UNUSED; | |
252b5132 RH |
1897 | { |
1898 | #if VMS_DEBUG | |
1899 | vms_debug (1, "vms_canonicalize_dynamic_reloc(%p)\n", abfd); | |
1900 | #endif | |
1901 | return 0L; | |
1902 | } |