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