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