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