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