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