* gas/mn10300/am33_5.s: Check that negative SP offsets are encoded
[binutils.git] / bfd / vms.c
blobf0ea63ff92d30630de0792c4035075cd642cd259
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 =
135 "vms-alpha", /* name */
136 bfd_target_evax_flavour,
137 BFD_ENDIAN_LITTLE, /* data byte order is little */
138 BFD_ENDIAN_LITTLE, /* header byte order is little */
140 (HAS_RELOC | HAS_SYMS
141 | WP_TEXT | D_PAGED), /* object flags */
142 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
143 | SEC_READONLY | SEC_CODE | SEC_DATA
144 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* sect flags */
145 0, /* symbol_leading_char */
146 ' ', /* ar_pad_char */
147 15, /* ar_max_namelen */
148 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
149 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
150 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
151 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
152 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
153 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
155 {_bfd_dummy_target, vms_object_p, /* bfd_check_format */
156 vms_archive_p, _bfd_dummy_target},
157 {bfd_false, vms_mkobject, /* bfd_set_format */
158 _bfd_generic_mkarchive, bfd_false},
159 {bfd_false, vms_write_object_contents, /* bfd_write_contents */
160 _bfd_write_archive_contents, bfd_false},
162 BFD_JUMP_TABLE_GENERIC (vms),
163 BFD_JUMP_TABLE_COPY (vms),
164 BFD_JUMP_TABLE_CORE (vms),
165 BFD_JUMP_TABLE_ARCHIVE (vms),
166 BFD_JUMP_TABLE_SYMBOLS (vms),
167 BFD_JUMP_TABLE_RELOCS (vms),
168 BFD_JUMP_TABLE_WRITE (vms),
169 BFD_JUMP_TABLE_LINK (vms),
170 BFD_JUMP_TABLE_DYNAMIC (vms),
172 NULL,
174 (PTR) 0
177 const bfd_target vms_vax_vec =
179 "vms-vax", /* name */
180 bfd_target_ovax_flavour,
181 BFD_ENDIAN_LITTLE, /* data byte order is little */
182 BFD_ENDIAN_LITTLE, /* 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 NULL,
220 (PTR) 0
223 /*===========================================================================*/
225 /* Initialize private data */
227 static boolean
228 vms_initialize (abfd)
229 bfd *abfd;
231 int i;
233 if (abfd->tdata.any != 0)
234 return true;
236 bfd_set_start_address (abfd, (bfd_vma)-1);
238 abfd->tdata.any = ((struct vms_private_data_struct*)
239 bfd_malloc (sizeof (struct vms_private_data_struct)));
240 if (abfd->tdata.any == 0)
241 return false;
243 #ifdef __ALPHA
244 PRIV(is_vax) = 0;
245 #else
246 PRIV(is_vax) = 1;
247 #endif
248 PRIV(vms_buf) = 0;
249 PRIV(buf_size) = 0;
250 PRIV(rec_length) = 0;
251 PRIV(file_format) = FF_UNKNOWN;
252 PRIV(fixup_done) = false;
253 PRIV(sections) = NULL;
255 PRIV(stack) = ((struct stack_struct *)
256 bfd_malloc (sizeof (struct stack_struct) * STACKSIZE));
257 if (PRIV(stack) == 0)
259 vms_init_no_mem1:
260 free (abfd->tdata.any);
261 abfd->tdata.any = 0;
262 return false;
264 PRIV(stackptr) = 0;
266 PRIV(vms_symbol_table) = ((struct bfd_hash_table *)
267 bfd_malloc (sizeof (struct bfd_hash_table)));
268 if (PRIV(vms_symbol_table) == 0)
270 vms_init_no_mem2:
271 free (PRIV(stack));
272 PRIV(stack) = 0;
273 goto vms_init_no_mem1;
276 if (!bfd_hash_table_init (PRIV(vms_symbol_table), _bfd_vms_hash_newfunc))
277 return false;
279 PRIV(location_stack) = ((struct location_struct *)
280 bfd_malloc (sizeof (struct location_struct)
281 * LOCATION_SAVE_SIZE));
282 if (PRIV(location_stack) == 0)
284 vms_init_no_mem3:
285 free (PRIV(vms_symbol_table));
286 PRIV(vms_symbol_table) = 0;
287 goto vms_init_no_mem2;
290 for (i = 0; i < VMS_SECTION_COUNT; i++)
291 PRIV(vms_section_table)[i] = NULL;
293 PRIV(output_buf) = (unsigned char *) malloc (MAX_OUTREC_SIZE);
294 if (PRIV(output_buf) == 0)
296 free (PRIV(location_stack));
297 PRIV(location_stack) = 0;
298 goto vms_init_no_mem3;
300 PRIV(push_level) = 0;
301 PRIV(pushed_size) = 0;
302 PRIV(length_pos) = 2;
303 PRIV(output_size) = 0;
304 PRIV(output_alignment) = 1;
306 return true;
310 /* Fill symbol->section with section ptr
311 symbol->section is filled with the section index for defined symbols
312 during reading the GSD/EGSD section. But we need the pointer to the
313 bfd section later.
315 It has the correct value for referenced (undefined section) symbols
317 called from bfd_hash_traverse in vms_fixup_sections */
319 static boolean
320 fill_section_ptr (entry, sections)
321 struct bfd_hash_entry *entry;
322 PTR sections;
324 asection *sec;
325 asymbol *sym;
327 sym = ((vms_symbol_entry *)entry)->symbol;
328 sec = sym->section;
330 #if VMS_DEBUG
331 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym, sec);
332 #endif
334 /* fill forward references (these contain section number, not section ptr). */
336 if ((unsigned int) sec < priv_section_count)
338 sec = ((vms_symbol_entry *)entry)->symbol->section =
339 ((asection **)sections)[(int)sec];
342 if (strcmp (sym->name, sec->name) == 0)
343 sym->flags |= BSF_SECTION_SYM;
345 return true;
349 /* Fixup sections
350 set up all pointers and arrays, counters and sizes are fixed now
352 we build a private sections vector for easy access since sections
353 are always referenced by an index number.
355 alloc PRIV(sections) according to abfd->section_count
356 copy abfd->sections to PRIV(sections) */
358 static boolean
359 vms_fixup_sections (abfd)
360 bfd *abfd;
362 if (PRIV(fixup_done))
363 return true;
366 * traverse symbol table and fill in all section pointers
369 /* can't provide section count as argument to fill_section_ptr(). */
370 priv_section_count = PRIV(section_count);
371 bfd_hash_traverse (PRIV(vms_symbol_table), fill_section_ptr,
372 (PTR)(PRIV(sections)));
374 PRIV(fixup_done) = true;
376 return true;
379 /*===========================================================================*/
381 /* Check the format for a file being read.
382 Return a (bfd_target *) if it's an object file or zero if not. */
384 static const struct bfd_target *
385 vms_object_p (abfd)
386 bfd *abfd;
388 int err = 0;
389 int prev_type;
390 const struct bfd_target *target_vector = 0;
391 const bfd_arch_info_type *arch = 0;
393 #if VMS_DEBUG
394 vms_debug (1, "vms_object_p(%p)\n", abfd);
395 #endif
397 if (!vms_initialize (abfd))
399 fprintf (stderr, "vms_initialize () failed !!\n");
400 return 0;
403 if (bfd_seek (abfd, 0L, SEEK_SET))
405 bfd_set_error (bfd_error_file_truncated);
406 return 0;
409 prev_type = -1;
413 #if VMS_DEBUG
414 vms_debug (7, "reading at %08lx\n", bfd_tell(abfd));
415 #endif
416 if (_bfd_vms_next_record (abfd) < 0)
418 #if VMS_DEBUG
419 vms_debug (2, "next_record failed\n");
420 #endif
421 bfd_set_error (bfd_error_wrong_format);
422 return 0;
425 if ((prev_type == EOBJ_S_C_EGSD)
426 && (PRIV(rec_type) != EOBJ_S_C_EGSD))
428 if (vms_fixup_sections (abfd) == false)
430 #if VMS_DEBUG
431 vms_debug (2, "vms_fixup_sections failed\n");
432 #endif
433 bfd_set_error (bfd_error_wrong_format);
434 return 0;
438 prev_type = PRIV(rec_type);
440 if (target_vector == 0)
442 if (prev_type <= OBJ_S_C_MAXRECTYP)
443 target_vector = &vms_vax_vec;
444 else
445 target_vector = &vms_alpha_vec;
448 switch (prev_type)
450 case OBJ_S_C_HDR:
451 case EOBJ_S_C_EMH:
452 err = _bfd_vms_slurp_hdr (abfd, prev_type);
453 break;
454 case OBJ_S_C_EOM:
455 case OBJ_S_C_EOMW:
456 case EOBJ_S_C_EEOM:
457 err = _bfd_vms_slurp_eom (abfd, prev_type);
458 break;
459 case OBJ_S_C_GSD:
460 case EOBJ_S_C_EGSD:
461 err = _bfd_vms_slurp_gsd (abfd, prev_type);
462 break;
463 case OBJ_S_C_TIR:
464 case EOBJ_S_C_ETIR:
465 err = _bfd_vms_slurp_tir (abfd, prev_type);
466 break;
467 case OBJ_S_C_DBG:
468 case EOBJ_S_C_EDBG:
469 err = _bfd_vms_slurp_dbg (abfd, prev_type);
470 break;
471 case OBJ_S_C_TBT:
472 case EOBJ_S_C_ETBT:
473 err = _bfd_vms_slurp_tbt (abfd, prev_type);
474 break;
475 case OBJ_S_C_LNK:
476 err = _bfd_vms_slurp_lnk (abfd, prev_type);
477 break;
478 default:
479 err = -1;
481 if (err != 0)
483 #if VMS_DEBUG
484 vms_debug (2, "slurp type %d failed with %d\n", prev_type, err);
485 #endif
486 bfd_set_error (bfd_error_wrong_format);
487 return 0;
490 while ((prev_type != EOBJ_S_C_EEOM) && (prev_type != OBJ_S_C_EOM) && (prev_type != OBJ_S_C_EOMW));
492 if (target_vector == &vms_vax_vec)
494 if (vms_fixup_sections (abfd) == false)
496 #if VMS_DEBUG
497 vms_debug (2, "vms_fixup_sections failed\n");
498 #endif
499 bfd_set_error (bfd_error_wrong_format);
500 return 0;
503 /* set arch_info to vax */
505 arch = bfd_scan_arch ("vax");
506 PRIV (is_vax) = 1;
507 #if VMS_DEBUG
508 vms_debug (2, "arch is vax\n");
509 #endif
511 else if (target_vector == &vms_alpha_vec)
513 /* set arch_info to alpha */
515 arch = bfd_scan_arch ("alpha");
516 PRIV (is_vax) = 0;
517 #if VMS_DEBUG
518 vms_debug (2, "arch is alpha\n");
519 #endif
522 if (arch == 0)
524 #if VMS_DEBUG
525 vms_debug (2, "arch not found\n");
526 #endif
527 bfd_set_error (bfd_error_wrong_format);
528 return 0;
530 abfd->arch_info = arch;
532 return target_vector;
536 /* Check the format for a file being read.
537 Return a (bfd_target *) if it's an archive file or zero. */
539 static const struct bfd_target *
540 vms_archive_p (abfd)
541 bfd *abfd ATTRIBUTE_UNUSED;
543 #if VMS_DEBUG
544 vms_debug (1, "vms_archive_p(%p)\n", abfd);
545 #endif
547 return 0;
551 /* Set the format of a file being written. */
553 static boolean
554 vms_mkobject (abfd)
555 bfd *abfd;
557 #if VMS_DEBUG
558 vms_debug (1, "vms_mkobject(%p)\n", abfd);
559 #endif
561 if (!vms_initialize (abfd))
563 fprintf (stderr, "vms_initialize () failed !!\n");
564 return 0;
568 #ifdef __VAX
569 const bfd_arch_info_type *arch = bfd_scan_arch ("vax");
570 #else
571 const bfd_arch_info_type *arch = bfd_scan_arch ("alpha");
572 #endif
573 if (arch == 0)
575 bfd_set_error(bfd_error_wrong_format);
576 return 0;
578 abfd->arch_info = arch;
581 return true;
585 /* Write cached information into a file being written, at bfd_close. */
587 static boolean
588 vms_write_object_contents (abfd)
589 bfd *abfd;
591 #if VMS_DEBUG
592 vms_debug (1, "vms_write_object_contents(%p)\n", abfd);
593 #endif
595 if (abfd->section_count > 0) /* we have sections */
597 if (PRIV(is_vax))
599 if (_bfd_vms_write_hdr (abfd, OBJ_S_C_HDR) != 0)
600 return false;
601 if (_bfd_vms_write_gsd (abfd, OBJ_S_C_GSD) != 0)
602 return false;
603 if (_bfd_vms_write_tir (abfd, OBJ_S_C_TIR) != 0)
604 return false;
605 if (_bfd_vms_write_tbt (abfd, OBJ_S_C_TBT) != 0)
606 return false;
607 if (_bfd_vms_write_dbg (abfd, OBJ_S_C_DBG) != 0)
608 return false;
609 if (abfd->section_count > 255)
611 if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOMW) != 0)
612 return false;
614 else
616 if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOM) != 0)
617 return false;
620 else
622 if (_bfd_vms_write_hdr (abfd, EOBJ_S_C_EMH) != 0)
623 return false;
624 if (_bfd_vms_write_gsd (abfd, EOBJ_S_C_EGSD) != 0)
625 return false;
626 if (_bfd_vms_write_tir (abfd, EOBJ_S_C_ETIR) != 0)
627 return false;
628 if (_bfd_vms_write_tbt (abfd, EOBJ_S_C_ETBT) != 0)
629 return false;
630 if (_bfd_vms_write_dbg (abfd, EOBJ_S_C_EDBG) != 0)
631 return false;
632 if (_bfd_vms_write_eom (abfd, EOBJ_S_C_EEOM) != 0)
633 return false;
636 return true;
639 /*-- 4.1, generic -----------------------------------------------------------*/
641 /* Called when the BFD is being closed to do any necessary cleanup. */
643 static boolean
644 vms_close_and_cleanup (abfd)
645 bfd *abfd;
647 asection *sec;
648 vms_section *es, *es1;
649 int i;
651 #if VMS_DEBUG
652 vms_debug (1, "vms_close_and_cleanup(%p)\n", abfd);
653 #endif
654 if (abfd == 0)
655 return true;
657 if (PRIV(vms_buf) != NULL)
659 free (PRIV(vms_buf));
660 PRIV(vms_buf) = NULL;
662 PRIV(buf_size) = 0;
664 if (PRIV(output_buf) != 0)
666 free (PRIV(output_buf));
667 PRIV(output_buf) = 0;
670 sec = abfd->sections;
671 while (sec != NULL)
673 if (sec->contents)
674 free (sec->contents);
675 sec = sec->next;
678 if (PRIV(sections) != NULL)
680 free (PRIV(sections));
681 PRIV(sections) = NULL;
684 if (PRIV(vms_symbol_table))
686 bfd_hash_table_free (PRIV(vms_symbol_table));
687 PRIV(vms_symbol_table) = 0;
690 if (PRIV(stack))
692 free (PRIV(stack));
693 PRIV(stack) = 0;
696 if (PRIV(location_stack))
698 free (PRIV(location_stack));
699 PRIV(location_stack) = 0;
702 for (i = 0; i < VMS_SECTION_COUNT; i++)
704 es = PRIV(vms_section_table)[i];
705 while (es != NULL)
707 es1 = es->next;
708 free (es);
709 es = es1;
711 PRIV(vms_section_table)[i] = NULL;
714 free (abfd->tdata.any);
715 abfd->tdata.any = NULL;
717 return true;
721 /* Ask the BFD to free all cached information. */
722 static boolean
723 vms_bfd_free_cached_info (abfd)
724 bfd *abfd ATTRIBUTE_UNUSED;
726 #if VMS_DEBUG
727 vms_debug (1, "vms_bfd_free_cached_info(%p)\n", abfd);
728 #endif
729 return true;
733 /* Called when a new section is created. */
735 static boolean
736 vms_new_section_hook (abfd, section)
737 bfd *abfd;
738 asection *section;
740 #if VMS_DEBUG
741 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n", abfd, section->index, section->name, abfd->section_count);
742 #endif
743 bfd_set_section_alignment(abfd, section, 4);
745 if (abfd->section_count > PRIV(section_count))
747 PRIV(sections) = ((asection **)
748 bfd_realloc (PRIV(sections), abfd->section_count * sizeof (asection *)));
749 if (PRIV(sections) == 0)
750 return false;
751 PRIV(section_count) = abfd->section_count;
753 #if VMS_DEBUG
754 vms_debug (6, "section_count: %d\n", PRIV(section_count));
755 #endif
756 PRIV(sections)[section->index] = section;
757 #if VMS_DEBUG
758 vms_debug (7, "%d: %s\n", section->index, section->name);
759 #endif
761 return true;
765 /* Read the contents of a section.
766 buf points to a buffer of buf_size bytes to be filled with
767 section data (starting at offset into section) */
769 static boolean
770 vms_get_section_contents (abfd, section, buf, offset, buf_size)
771 bfd *abfd ATTRIBUTE_UNUSED;
772 asection *section ATTRIBUTE_UNUSED;
773 PTR buf ATTRIBUTE_UNUSED;
774 file_ptr offset ATTRIBUTE_UNUSED;
775 bfd_size_type buf_size ATTRIBUTE_UNUSED;
777 #if VMS_DEBUG
778 vms_debug (1, "vms_get_section_contents(%p, %s, %p, off %ld, size %d)\n",
779 abfd, section->name, buf, offset, (int)buf_size);
780 #endif
782 /* shouldn't be called, since all sections are IN_MEMORY */
784 return false;
787 /* Read the contents of a section.
788 buf points to a buffer of buf_size bytes to be filled with
789 section data (starting at offset into section) */
791 static boolean
792 vms_get_section_contents_in_window (abfd, section, w, offset, count)
793 bfd *abfd ATTRIBUTE_UNUSED;
794 asection *section ATTRIBUTE_UNUSED;
795 bfd_window *w ATTRIBUTE_UNUSED;
796 file_ptr offset ATTRIBUTE_UNUSED;
797 bfd_size_type count ATTRIBUTE_UNUSED;
799 #if VMS_DEBUG
800 vms_debug (1, "vms_get_section_contents_in_window(%p, %s, %p, off %ld, count %d)\n",
801 abfd, section->name, w, offset, (int)count);
802 #endif
804 /* shouldn't be called, since all sections are IN_MEMORY */
806 return false;
809 /*-- Part 4.2, copy private data --------------------------------------------*/
811 /* Called to copy BFD general private data from one object file
812 to another. */
814 static boolean
815 vms_bfd_copy_private_bfd_data (src, dest)
816 bfd *src ATTRIBUTE_UNUSED;
817 bfd *dest ATTRIBUTE_UNUSED;
819 #if VMS_DEBUG
820 vms_debug (1, "vms_bfd_copy_private_bfd_data(%p, %p)\n", src, dest);
821 #endif
822 return true;
826 /* Merge private BFD information from the BFD @var{ibfd} to the
827 the output file BFD @var{obfd} when linking. Return <<true>>
828 on success, <<false>> on error. Possible error returns are:
830 o <<bfd_error_no_memory>> -
831 Not enough memory exists to create private data for @var{obfd}. */
833 static boolean
834 vms_bfd_merge_private_bfd_data (ibfd, obfd)
835 bfd *ibfd ATTRIBUTE_UNUSED;
836 bfd *obfd ATTRIBUTE_UNUSED;
838 #if VMS_DEBUG
839 vms_debug (1,"vms_bfd_merge_private_bfd_data(%p, %p)\n", ibfd, obfd);
840 #endif
841 return true;
845 /* Set private BFD flag information in the BFD @var{abfd}.
846 Return <<true>> on success, <<false>> on error. Possible error
847 returns are:
849 o <<bfd_error_no_memory>> -
850 Not enough memory exists to create private data for @var{obfd}. */
852 static boolean
853 vms_bfd_set_private_flags (abfd, flags)
854 bfd *abfd ATTRIBUTE_UNUSED;
855 flagword flags ATTRIBUTE_UNUSED;
857 #if VMS_DEBUG
858 vms_debug (1,"vms_bfd_set_private_flags(%p, %lx)\n", abfd, (long)flags);
859 #endif
860 return true;
864 /* Called to copy BFD private section data from one object file
865 to another. */
867 static boolean
868 vms_bfd_copy_private_section_data (srcbfd, srcsec, dstbfd, dstsec)
869 bfd *srcbfd ATTRIBUTE_UNUSED;
870 asection *srcsec ATTRIBUTE_UNUSED;
871 bfd *dstbfd ATTRIBUTE_UNUSED;
872 asection *dstsec ATTRIBUTE_UNUSED;
874 #if VMS_DEBUG
875 vms_debug (1, "vms_bfd_copy_private_section_data(%p, %s, %p, %s)\n",
876 srcbfd, srcsec->name, dstbfd, dstsec->name);
877 #endif
878 return true;
881 /* Called to copy BFD private symbol data from one object file
882 to another. */
884 static boolean
885 vms_bfd_copy_private_symbol_data (ibfd, isym, obfd, osym)
886 bfd *ibfd ATTRIBUTE_UNUSED;
887 asymbol *isym ATTRIBUTE_UNUSED;
888 bfd *obfd ATTRIBUTE_UNUSED;
889 asymbol *osym ATTRIBUTE_UNUSED;
891 #if VMS_DEBUG
892 vms_debug (1, "vms_bfd_copy_private_symbol_data(%p, %s, %p, %s)\n",
893 ibfd, isym->name, obfd, osym->name);
894 #endif
895 return true;
898 /*-- Part 4.3, core file ----------------------------------------------------*/
900 /* Return a read-only string explaining which program was running
901 when it failed and produced the core file abfd. */
903 static char *
904 vms_core_file_failing_command (abfd)
905 bfd *abfd ATTRIBUTE_UNUSED;
907 #if VMS_DEBUG
908 vms_debug (1, "vms_core_file_failing_command(%p)\n", abfd);
909 #endif
910 return 0;
914 /* Returns the signal number which caused the core dump which
915 generated the file the BFD abfd is attached to. */
917 static int
918 vms_core_file_failing_signal (abfd)
919 bfd *abfd ATTRIBUTE_UNUSED;
921 #if VMS_DEBUG
922 vms_debug (1, "vms_core_file_failing_signal(%p)\n", abfd);
923 #endif
924 return 0;
928 /* Return true if the core file attached to core_bfd was generated
929 by a run of the executable file attached to exec_bfd, false otherwise. */
931 static boolean
932 vms_core_file_matches_executable_p (abfd, bbfd)
933 bfd *abfd ATTRIBUTE_UNUSED;
934 bfd *bbfd ATTRIBUTE_UNUSED;
936 #if VMS_DEBUG
937 vms_debug (1, "vms_core_file_matches_executable_p(%p, %p)\n", abfd, bbfd);
938 #endif
939 return false;
942 /*-- Part 4.4, archive ------------------------------------------------------*/
944 /* ??? do something with an archive map.
945 Return false on error, true otherwise. */
947 static boolean
948 vms_slurp_armap (abfd)
949 bfd *abfd ATTRIBUTE_UNUSED;
951 #if VMS_DEBUG
952 vms_debug (1, "vms_slurp_armap(%p)\n", abfd);
953 #endif
954 return false;
958 /* ??? do something with an extended name table.
959 Return false on error, true otherwise. */
961 static boolean
962 vms_slurp_extended_name_table (abfd)
963 bfd *abfd ATTRIBUTE_UNUSED;
965 #if VMS_DEBUG
966 vms_debug (1, "vms_slurp_extended_name_table(%p)\n", abfd);
967 #endif
968 return false;
972 /* ??? do something with an extended name table.
973 Return false on error, true otherwise. */
975 static boolean
976 vms_construct_extended_name_table (abfd, tabloc, tablen, name)
977 bfd *abfd ATTRIBUTE_UNUSED;
978 char **tabloc ATTRIBUTE_UNUSED;
979 bfd_size_type *tablen ATTRIBUTE_UNUSED;
980 const char **name ATTRIBUTE_UNUSED;
982 #if VMS_DEBUG
983 vms_debug (1, "vms_construct_extended_name_table(%p)\n", abfd);
984 #endif
985 return false;
989 /* Truncate the name of an archive to match system-dependent restrictions */
991 static void
992 vms_truncate_arname (abfd, pathname, arhdr)
993 bfd *abfd ATTRIBUTE_UNUSED;
994 CONST char *pathname ATTRIBUTE_UNUSED;
995 char *arhdr ATTRIBUTE_UNUSED;
997 #if VMS_DEBUG
998 vms_debug (1, "vms_truncate_arname(%p, %s, %s)\n", abfd, pathname, arhdr);
999 #endif
1000 return;
1004 /* ??? write archive map */
1006 static boolean
1007 vms_write_armap (arch, elength, map, orl_count, stridx)
1008 bfd *arch ATTRIBUTE_UNUSED;
1009 unsigned int elength ATTRIBUTE_UNUSED;
1010 struct orl *map ATTRIBUTE_UNUSED;
1011 unsigned int orl_count ATTRIBUTE_UNUSED;
1012 int stridx ATTRIBUTE_UNUSED;
1014 #if VMS_DEBUG
1015 vms_debug (1, "vms_write_armap(%p, %d, %p, %d %d)\n",
1016 arch, elength, map, orl_count, stridx);
1017 #endif
1018 return true;
1021 /* Read archive header ??? */
1023 static PTR
1024 vms_read_ar_hdr (abfd)
1025 bfd * abfd ATTRIBUTE_UNUSED;
1027 #if VMS_DEBUG
1028 vms_debug (1, "vms_read_ar_hdr(%p)\n", abfd);
1029 #endif
1030 return (PTR)0;
1034 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
1035 an input BFD on the first contained element and returns that.
1036 Subsequent calls should pass the archive and the previous return value
1037 to return a created BFD to the next contained element.
1038 NULL is returned when there are no more. */
1040 static bfd *
1041 vms_openr_next_archived_file (arch, prev)
1042 bfd *arch ATTRIBUTE_UNUSED;
1043 bfd *prev ATTRIBUTE_UNUSED;
1045 #if VMS_DEBUG
1046 vms_debug (1, "vms_openr_next_archived_file(%p, %p)\n", arch, prev);
1047 #endif
1048 return false;
1052 /* Return the BFD which is referenced by the symbol in ABFD indexed by
1053 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
1055 static bfd *
1056 vms_get_elt_at_index (abfd, index)
1057 bfd *abfd;
1058 symindex index;
1060 #if VMS_DEBUG
1061 vms_debug (1, "vms_get_elt_at_index(%p, %p)\n", abfd, index);
1062 #endif
1063 return _bfd_generic_get_elt_at_index(abfd, index);
1067 /* ???
1068 -> bfd_generic_stat_arch_elt */
1070 static int
1071 vms_generic_stat_arch_elt (abfd, stat)
1072 bfd *abfd;
1073 struct stat *stat;
1075 #if VMS_DEBUG
1076 vms_debug (1, "vms_generic_stat_arch_elt(%p, %p)\n", abfd, stat);
1077 #endif
1078 return bfd_generic_stat_arch_elt(abfd, stat);
1082 /* This is a new function in bfd 2.5 */
1084 static boolean
1085 vms_update_armap_timestamp (abfd)
1086 bfd *abfd ATTRIBUTE_UNUSED;
1088 #if VMS_DEBUG
1089 vms_debug (1, "vms_update_armap_timestamp(%p)\n", abfd);
1090 #endif
1091 return true;
1094 /*-- Part 4.5, symbols --------------------------------------------------------*/
1096 /* Return the number of bytes required to store a vector of pointers
1097 to asymbols for all the symbols in the BFD abfd, including a
1098 terminal NULL pointer. If there are no symbols in the BFD,
1099 then return 0. If an error occurs, return -1. */
1101 static long
1102 vms_get_symtab_upper_bound (abfd)
1103 bfd *abfd;
1105 #if VMS_DEBUG
1106 vms_debug (1, "vms_get_symtab_upper_bound(%p), %d symbols\n", abfd, PRIV(gsd_sym_count));
1107 #endif
1108 return (PRIV(gsd_sym_count)+1) * sizeof(asymbol *);
1112 /* Copy symbols from hash table to symbol vector
1114 called from bfd_hash_traverse in vms_get_symtab
1115 init counter to 0 if entry == 0 */
1117 static boolean
1118 copy_symbols (entry, arg)
1119 struct bfd_hash_entry *entry;
1120 PTR arg;
1122 bfd *abfd = (bfd *) arg;
1124 if (entry == NULL) /* init counter */
1125 PRIV(symnum) = 0;
1126 else /* fill vector, inc counter */
1127 PRIV(symcache)[PRIV(symnum)++] = ((vms_symbol_entry *)entry)->symbol;
1129 return true;
1133 /* Read the symbols from the BFD abfd, and fills in the vector
1134 location with pointers to the symbols and a trailing NULL.
1136 return # of symbols read */
1138 static long
1139 vms_get_symtab (abfd, symbols)
1140 bfd *abfd;
1141 asymbol **symbols;
1143 #if VMS_DEBUG
1144 vms_debug (1, "vms_get_symtab(%p, <ret>)\n", abfd);
1145 #endif
1147 /* init counter */
1148 (void)copy_symbols((struct bfd_hash_entry *)0, abfd);
1150 /* traverse table and fill symbols vector */
1152 PRIV(symcache) = symbols;
1153 bfd_hash_traverse(PRIV(vms_symbol_table), copy_symbols, (PTR)abfd);
1155 symbols[PRIV(gsd_sym_count)] = NULL;
1157 return PRIV(gsd_sym_count);
1161 /* Create a new asymbol structure for the BFD abfd and return a pointer
1162 to it.
1163 This routine is necessary because each back end has private information
1164 surrounding the asymbol. Building your own asymbol and pointing to it
1165 will not create the private information, and will cause problems later on. */
1167 asymbol *
1168 _bfd_vms_make_empty_symbol (abfd)
1169 bfd *abfd;
1171 asymbol *symbol = (asymbol *)bfd_zalloc(abfd, sizeof(asymbol));
1173 #if VMS_DEBUG
1174 vms_debug (1, "_bfd_vms_make_empty_symbol(%p)\n", abfd);
1175 #endif
1177 if (symbol == 0)
1179 bfd_set_error (bfd_error_no_memory);
1180 return 0;
1182 symbol->the_bfd = abfd;
1184 return symbol;
1188 /* Print symbol to file according to how. how is one of
1189 bfd_print_symbol_name just print the name
1190 bfd_print_symbol_more print more (???)
1191 bfd_print_symbol_all print all we know, which is not much right now :-) */
1193 static void
1194 vms_print_symbol (abfd, file, symbol, how)
1195 bfd *abfd ATTRIBUTE_UNUSED;
1196 PTR file;
1197 asymbol *symbol;
1198 bfd_print_symbol_type how;
1200 #if VMS_DEBUG
1201 vms_debug (1, "vms_print_symbol(%p, %p, %p, %d)\n", abfd, file, symbol, how);
1202 #endif
1204 switch (how)
1206 case bfd_print_symbol_name:
1207 case bfd_print_symbol_more:
1208 fprintf((FILE *)file," %s", symbol->name);
1209 break;
1211 break;
1213 case bfd_print_symbol_all:
1215 CONST char *section_name = symbol->section->name;
1217 bfd_print_symbol_vandf((PTR)file,symbol);
1219 fprintf((FILE *)file," %-8s %s", section_name, symbol->name);
1221 break;
1223 return;
1227 /* Return information about symbol in ret.
1229 fill type, value and name
1230 type:
1231 A absolute
1232 B bss segment symbol
1233 C common symbol
1234 D data segment symbol
1235 f filename
1236 t a static function symbol
1237 T text segment symbol
1238 U undefined
1239 - debug */
1241 static void
1242 vms_get_symbol_info (abfd, symbol, ret)
1243 bfd *abfd ATTRIBUTE_UNUSED;
1244 asymbol *symbol;
1245 symbol_info *ret;
1247 asection *sec;
1249 #if VMS_DEBUG
1250 vms_debug (1, "vms_get_symbol_info(%p, %p, %p)\n", abfd, symbol, ret);
1251 #endif
1253 sec = symbol->section;
1255 if (ret == 0)
1256 return;
1258 if (bfd_is_com_section (sec))
1259 ret->type = 'C';
1260 else if (bfd_is_abs_section (sec))
1261 ret->type = 'A';
1262 else if (bfd_is_und_section (sec))
1263 ret->type = 'U';
1264 else if (bfd_is_ind_section (sec))
1265 ret->type = 'I';
1266 else if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
1267 ret->type = 'T';
1268 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
1269 ret->type = 'D';
1270 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
1271 ret->type = 'B';
1272 else
1273 ret->type = '-';
1275 if (ret->type != 'U')
1276 ret->value = symbol->value + symbol->section->vma;
1277 else
1278 ret->value = 0;
1279 ret->name = symbol->name;
1281 return;
1285 /* Return true if the given symbol sym in the BFD abfd is
1286 a compiler generated local label, else return false. */
1288 static boolean
1289 vms_bfd_is_local_label_name (abfd, name)
1290 bfd *abfd ATTRIBUTE_UNUSED;
1291 const char *name;
1293 #if VMS_DEBUG
1294 vms_debug (1, "vms_bfd_is_local_label_name(%p, %s)\n", abfd, name);
1295 #endif
1296 return name[0] == '$';
1300 /* Get source line number for symbol */
1302 static alent *
1303 vms_get_lineno (abfd, symbol)
1304 bfd *abfd ATTRIBUTE_UNUSED;
1305 asymbol *symbol ATTRIBUTE_UNUSED;
1307 #if VMS_DEBUG
1308 vms_debug (1, "vms_get_lineno(%p, %p)\n", abfd, symbol);
1309 #endif
1310 return 0;
1314 /* Provided a BFD, a section and an offset into the section, calculate and
1315 return the name of the source file and the line nearest to the wanted
1316 location. */
1318 static boolean
1319 vms_find_nearest_line (abfd, section, symbols, offset, file, func, line)
1320 bfd *abfd ATTRIBUTE_UNUSED;
1321 asection *section ATTRIBUTE_UNUSED;
1322 asymbol **symbols ATTRIBUTE_UNUSED;
1323 bfd_vma offset ATTRIBUTE_UNUSED;
1324 CONST char **file ATTRIBUTE_UNUSED;
1325 CONST char **func ATTRIBUTE_UNUSED;
1326 unsigned int *line ATTRIBUTE_UNUSED;
1328 #if VMS_DEBUG
1329 vms_debug (1, "vms_find_nearest_line(%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1330 abfd, section->name, symbols, (long int)offset);
1331 #endif
1332 return false;
1336 /* Back-door to allow format-aware applications to create debug symbols
1337 while using BFD for everything else. Currently used by the assembler
1338 when creating COFF files. */
1340 static asymbol *
1341 vms_bfd_make_debug_symbol (abfd, ptr, size)
1342 bfd *abfd ATTRIBUTE_UNUSED;
1343 void *ptr ATTRIBUTE_UNUSED;
1344 unsigned long size ATTRIBUTE_UNUSED;
1346 #if VMS_DEBUG
1347 vms_debug (1, "vms_bfd_make_debug_symbol(%p, %p, %ld)\n", abfd, ptr, size);
1348 #endif
1349 return 0;
1353 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1354 symbols. The minisymbol_to_symbol function translates these into
1355 BFD asymbol structures. */
1357 static long
1358 vms_read_minisymbols (abfd, dynamic, minisymsp, sizep)
1359 bfd *abfd;
1360 boolean dynamic;
1361 PTR *minisymsp;
1362 unsigned int *sizep;
1364 #if VMS_DEBUG
1365 vms_debug (1, "vms_read_minisymbols(%p, %d, %p, %d)\n", abfd, dynamic, minisymsp, *sizep);
1366 #endif
1367 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
1370 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1371 unmodified a.out symbol. The SYM argument is a structure returned
1372 by bfd_make_empty_symbol, which we fill in here. */
1374 static asymbol *
1375 vms_minisymbol_to_symbol (abfd, dynamic, minisym, sym)
1376 bfd *abfd;
1377 boolean dynamic;
1378 const PTR minisym;
1379 asymbol *sym;
1381 #if VMS_DEBUG
1382 vms_debug (1, "vms_minisymbol_to_symbol(%p, %d, %p, %p)\n", abfd, dynamic, minisym, sym);
1383 #endif
1384 return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
1387 /*-- Part 4.6, relocations --------------------------------------------------*/
1389 /* Return the number of bytes required to store the relocation information
1390 associated with section sect attached to bfd abfd.
1391 If an error occurs, return -1. */
1393 static long
1394 vms_get_reloc_upper_bound (abfd, section)
1395 bfd *abfd ATTRIBUTE_UNUSED;
1396 asection *section ATTRIBUTE_UNUSED;
1398 #if VMS_DEBUG
1399 vms_debug (1, "vms_get_reloc_upper_bound(%p, %s)\n", abfd, section->name);
1400 #endif
1401 return -1L;
1405 /* Call the back end associated with the open BFD abfd and translate the
1406 external form of the relocation information attached to sec into the
1407 internal canonical form. Place the table into memory at loc, which has
1408 been preallocated, usually by a call to bfd_get_reloc_upper_bound.
1409 Returns the number of relocs, or -1 on error. */
1411 static long
1412 vms_canonicalize_reloc (abfd, section, location, symbols)
1413 bfd *abfd ATTRIBUTE_UNUSED;
1414 asection *section ATTRIBUTE_UNUSED;
1415 arelent **location ATTRIBUTE_UNUSED;
1416 asymbol **symbols ATTRIBUTE_UNUSED;
1418 #if VMS_DEBUG
1419 vms_debug (1, "vms_canonicalize_reloc(%p, %s, <ret>, <ret>)\n", abfd, section->name);
1420 #endif
1421 return false;
1424 /*---------------------------------------------------------------------------*/
1425 /* this is just copied from ecoff-alpha, needs to be fixed probably */
1427 /* How to process the various reloc types. */
1429 static bfd_reloc_status_type
1430 reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
1431 bfd *abfd ATTRIBUTE_UNUSED;
1432 arelent *reloc ATTRIBUTE_UNUSED;
1433 asymbol *sym ATTRIBUTE_UNUSED;
1434 PTR data ATTRIBUTE_UNUSED;
1435 asection *sec ATTRIBUTE_UNUSED;
1436 bfd *output_bfd ATTRIBUTE_UNUSED;
1437 char **error_message ATTRIBUTE_UNUSED;
1439 #if VMS_DEBUG
1440 vms_debug (1, "reloc_nil(abfd %p, output_bfd %p)\n", abfd, output_bfd);
1441 vms_debug (2, "In section %s, symbol %s\n",
1442 sec->name, sym->name);
1443 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1444 reloc->sym_ptr_ptr[0]->name,
1445 (unsigned long)reloc->address,
1446 (unsigned long)reloc->addend, reloc->howto->name);
1447 vms_debug (2, "data at %p\n", data);
1448 /* _bfd_hexdump (2, data, bfd_get_reloc_size(reloc->howto),0); */
1449 #endif
1451 return bfd_reloc_ok;
1454 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1455 from smaller values. Start with zero, widen, *then* decrement. */
1456 #define MINUS_ONE (((bfd_vma)0) - 1)
1458 static reloc_howto_type alpha_howto_table[] =
1460 HOWTO (ALPHA_R_IGNORE, /* type */
1461 0, /* rightshift */
1462 0, /* size (0 = byte, 1 = short, 2 = long) */
1463 8, /* bitsize */
1464 true, /* pc_relative */
1465 0, /* bitpos */
1466 complain_overflow_dont, /* complain_on_overflow */
1467 reloc_nil, /* special_function */
1468 "IGNORE", /* name */
1469 true, /* partial_inplace */
1470 0, /* src_mask */
1471 0, /* dst_mask */
1472 true), /* pcrel_offset */
1474 /* A 64 bit reference to a symbol. */
1475 HOWTO (ALPHA_R_REFQUAD, /* type */
1476 0, /* rightshift */
1477 4, /* size (0 = byte, 1 = short, 2 = long) */
1478 64, /* bitsize */
1479 false, /* pc_relative */
1480 0, /* bitpos */
1481 complain_overflow_bitfield, /* complain_on_overflow */
1482 reloc_nil, /* special_function */
1483 "REFQUAD", /* name */
1484 true, /* partial_inplace */
1485 MINUS_ONE, /* src_mask */
1486 MINUS_ONE, /* dst_mask */
1487 false), /* pcrel_offset */
1489 /* A 21 bit branch. The native assembler generates these for
1490 branches within the text segment, and also fills in the PC
1491 relative offset in the instruction. */
1492 HOWTO (ALPHA_R_BRADDR, /* type */
1493 2, /* rightshift */
1494 2, /* size (0 = byte, 1 = short, 2 = long) */
1495 21, /* bitsize */
1496 true, /* pc_relative */
1497 0, /* bitpos */
1498 complain_overflow_signed, /* complain_on_overflow */
1499 reloc_nil, /* special_function */
1500 "BRADDR", /* name */
1501 true, /* partial_inplace */
1502 0x1fffff, /* src_mask */
1503 0x1fffff, /* dst_mask */
1504 false), /* pcrel_offset */
1506 /* A hint for a jump to a register. */
1507 HOWTO (ALPHA_R_HINT, /* type */
1508 2, /* rightshift */
1509 1, /* size (0 = byte, 1 = short, 2 = long) */
1510 14, /* bitsize */
1511 true, /* pc_relative */
1512 0, /* bitpos */
1513 complain_overflow_dont, /* complain_on_overflow */
1514 reloc_nil, /* special_function */
1515 "HINT", /* name */
1516 true, /* partial_inplace */
1517 0x3fff, /* src_mask */
1518 0x3fff, /* dst_mask */
1519 false), /* pcrel_offset */
1521 /* 16 bit PC relative offset. */
1522 HOWTO (ALPHA_R_SREL16, /* type */
1523 0, /* rightshift */
1524 1, /* size (0 = byte, 1 = short, 2 = long) */
1525 16, /* bitsize */
1526 true, /* pc_relative */
1527 0, /* bitpos */
1528 complain_overflow_signed, /* complain_on_overflow */
1529 reloc_nil, /* special_function */
1530 "SREL16", /* name */
1531 true, /* partial_inplace */
1532 0xffff, /* src_mask */
1533 0xffff, /* dst_mask */
1534 false), /* pcrel_offset */
1536 /* 32 bit PC relative offset. */
1537 HOWTO (ALPHA_R_SREL32, /* type */
1538 0, /* rightshift */
1539 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 32, /* bitsize */
1541 true, /* pc_relative */
1542 0, /* bitpos */
1543 complain_overflow_signed, /* complain_on_overflow */
1544 reloc_nil, /* special_function */
1545 "SREL32", /* name */
1546 true, /* partial_inplace */
1547 0xffffffff, /* src_mask */
1548 0xffffffff, /* dst_mask */
1549 false), /* pcrel_offset */
1551 /* A 64 bit PC relative offset. */
1552 HOWTO (ALPHA_R_SREL64, /* type */
1553 0, /* rightshift */
1554 4, /* size (0 = byte, 1 = short, 2 = long) */
1555 64, /* bitsize */
1556 true, /* pc_relative */
1557 0, /* bitpos */
1558 complain_overflow_signed, /* complain_on_overflow */
1559 reloc_nil, /* special_function */
1560 "SREL64", /* name */
1561 true, /* partial_inplace */
1562 MINUS_ONE, /* src_mask */
1563 MINUS_ONE, /* dst_mask */
1564 false), /* pcrel_offset */
1566 /* Push a value on the reloc evaluation stack. */
1567 HOWTO (ALPHA_R_OP_PUSH, /* type */
1568 0, /* rightshift */
1569 0, /* size (0 = byte, 1 = short, 2 = long) */
1570 0, /* bitsize */
1571 false, /* pc_relative */
1572 0, /* bitpos */
1573 complain_overflow_dont, /* complain_on_overflow */
1574 reloc_nil, /* special_function */
1575 "OP_PUSH", /* name */
1576 false, /* partial_inplace */
1577 0, /* src_mask */
1578 0, /* dst_mask */
1579 false), /* pcrel_offset */
1581 /* Store the value from the stack at the given address. Store it in
1582 a bitfield of size r_size starting at bit position r_offset. */
1583 HOWTO (ALPHA_R_OP_STORE, /* type */
1584 0, /* rightshift */
1585 4, /* size (0 = byte, 1 = short, 2 = long) */
1586 64, /* bitsize */
1587 false, /* pc_relative */
1588 0, /* bitpos */
1589 complain_overflow_dont, /* complain_on_overflow */
1590 reloc_nil, /* special_function */
1591 "OP_STORE", /* name */
1592 false, /* partial_inplace */
1593 0, /* src_mask */
1594 MINUS_ONE, /* dst_mask */
1595 false), /* pcrel_offset */
1597 /* Subtract the reloc address from the value on the top of the
1598 relocation stack. */
1599 HOWTO (ALPHA_R_OP_PSUB, /* type */
1600 0, /* rightshift */
1601 0, /* size (0 = byte, 1 = short, 2 = long) */
1602 0, /* bitsize */
1603 false, /* pc_relative */
1604 0, /* bitpos */
1605 complain_overflow_dont, /* complain_on_overflow */
1606 reloc_nil, /* special_function */
1607 "OP_PSUB", /* name */
1608 false, /* partial_inplace */
1609 0, /* src_mask */
1610 0, /* dst_mask */
1611 false), /* pcrel_offset */
1613 /* Shift the value on the top of the relocation stack right by the
1614 given value. */
1615 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
1616 0, /* rightshift */
1617 0, /* size (0 = byte, 1 = short, 2 = long) */
1618 0, /* bitsize */
1619 false, /* pc_relative */
1620 0, /* bitpos */
1621 complain_overflow_dont, /* complain_on_overflow */
1622 reloc_nil, /* special_function */
1623 "OP_PRSHIFT", /* name */
1624 false, /* partial_inplace */
1625 0, /* src_mask */
1626 0, /* dst_mask */
1627 false), /* pcrel_offset */
1629 /* Hack. Linkage is done by linker. */
1630 HOWTO (ALPHA_R_LINKAGE, /* type */
1631 0, /* rightshift */
1632 8, /* size (0 = byte, 1 = short, 2 = long) */
1633 256, /* bitsize */
1634 false, /* pc_relative */
1635 0, /* bitpos */
1636 complain_overflow_dont, /* complain_on_overflow */
1637 reloc_nil, /* special_function */
1638 "LINKAGE", /* name */
1639 false, /* partial_inplace */
1640 0, /* src_mask */
1641 0, /* dst_mask */
1642 false), /* pcrel_offset */
1644 /* A 32 bit reference to a symbol. */
1645 HOWTO (ALPHA_R_REFLONG, /* type */
1646 0, /* rightshift */
1647 2, /* size (0 = byte, 1 = short, 2 = long) */
1648 32, /* bitsize */
1649 false, /* pc_relative */
1650 0, /* bitpos */
1651 complain_overflow_bitfield, /* complain_on_overflow */
1652 reloc_nil, /* special_function */
1653 "REFLONG", /* name */
1654 true, /* partial_inplace */
1655 0xffffffff, /* src_mask */
1656 0xffffffff, /* dst_mask */
1657 false), /* pcrel_offset */
1659 /* A 64 bit reference to a procedure, written as 32 bit value. */
1660 HOWTO (ALPHA_R_CODEADDR, /* type */
1661 0, /* rightshift */
1662 4, /* size (0 = byte, 1 = short, 2 = long) */
1663 64, /* bitsize */
1664 false, /* pc_relative */
1665 0, /* bitpos */
1666 complain_overflow_signed,/* complain_on_overflow */
1667 reloc_nil, /* special_function */
1668 "CODEADDR", /* name */
1669 false, /* partial_inplace */
1670 0xffffffff, /* src_mask */
1671 0xffffffff, /* dst_mask */
1672 false), /* pcrel_offset */
1676 /* Return a pointer to a howto structure which, when invoked, will perform
1677 the relocation code on data from the architecture noted. */
1679 static const struct reloc_howto_struct *
1680 vms_bfd_reloc_type_lookup (abfd, code)
1681 bfd *abfd ATTRIBUTE_UNUSED;
1682 bfd_reloc_code_real_type code;
1684 int alpha_type;
1686 #if VMS_DEBUG
1687 vms_debug (1, "vms_bfd_reloc_type_lookup(%p, %d)\t", abfd, code);
1688 #endif
1690 switch (code)
1692 case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break;
1693 case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break;
1694 case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break;
1695 case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break;
1696 case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break;
1697 case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break;
1698 case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break;
1699 case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break;
1700 case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break;
1701 case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break;
1702 case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break;
1703 default:
1704 (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code);
1705 return (const struct reloc_howto_struct *) NULL;
1707 #if VMS_DEBUG
1708 vms_debug (2, "reloc is %s\n", alpha_howto_table[alpha_type].name);
1709 #endif
1710 return &alpha_howto_table[alpha_type];
1714 /*-- Part 4.7, writing an object file ---------------------------------------*/
1716 /* Set the architecture and machine type in BFD abfd to arch and mach.
1717 Find the correct pointer to a structure and insert it into the arch_info
1718 pointer. */
1720 static boolean
1721 vms_set_arch_mach (abfd, arch, mach)
1722 bfd *abfd;
1723 enum bfd_architecture arch ATTRIBUTE_UNUSED;
1724 unsigned long mach ATTRIBUTE_UNUSED;
1726 #if VMS_DEBUG
1727 vms_debug (1, "vms_set_arch_mach(%p, %d, %ld)\n", abfd, arch, mach);
1728 #endif
1729 abfd->arch_info = bfd_scan_arch("alpha");
1731 return true;
1735 /* Sets the contents of the section section in BFD abfd to the data starting
1736 in memory at data. The data is written to the output section starting at
1737 offset offset for count bytes.
1739 Normally true is returned, else false. Possible error returns are:
1740 o bfd_error_no_contents - The output section does not have the
1741 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1742 o and some more too */
1744 static boolean
1745 vms_set_section_contents (abfd, section, location, offset, count)
1746 bfd *abfd;
1747 asection *section;
1748 PTR location;
1749 file_ptr offset;
1750 bfd_size_type count;
1752 #if VMS_DEBUG
1753 vms_debug (1, "vms_set_section_contents(%p, sec %s, loc %p, off %ld, count %d)\n",
1754 abfd, section->name, location, (long int)offset, (int)count);
1755 vms_debug (2, "secraw %d, seccooked %d\n", (int)section->_raw_size, (int)section->_cooked_size);
1756 #endif
1757 return _bfd_save_vms_section(abfd, section, location, offset, count);
1761 /*-- Part 4.8, linker -------------------------------------------------------*/
1763 /* Get the size of the section headers. */
1765 static int
1766 vms_sizeof_headers (abfd, reloc)
1767 bfd *abfd ATTRIBUTE_UNUSED;
1768 boolean reloc ATTRIBUTE_UNUSED;
1770 #if VMS_DEBUG
1771 vms_debug (1, "vms_sizeof_headers(%p, %s)\n", abfd, (reloc)?"True":"False");
1772 #endif
1773 return 0;
1777 /* Provides default handling of relocation effort for back ends
1778 which can't be bothered to do it efficiently. */
1780 static bfd_byte *
1781 vms_bfd_get_relocated_section_contents (abfd, link_info, link_order, data,
1782 relocateable, symbols)
1783 bfd *abfd ATTRIBUTE_UNUSED;
1784 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1785 struct bfd_link_order *link_order ATTRIBUTE_UNUSED;
1786 bfd_byte *data ATTRIBUTE_UNUSED;
1787 boolean relocateable ATTRIBUTE_UNUSED;
1788 asymbol **symbols ATTRIBUTE_UNUSED;
1790 #if VMS_DEBUG
1791 vms_debug (1, "vms_bfd_get_relocated_section_contents(%p, %p, %p, %p, %s, %p)\n",
1792 abfd, link_info, link_order, data, (relocateable)?"True":"False", symbols);
1793 #endif
1794 return 0;
1798 /* ??? */
1800 static boolean
1801 vms_bfd_relax_section (abfd, section, link_info, again)
1802 bfd *abfd ATTRIBUTE_UNUSED;
1803 asection *section ATTRIBUTE_UNUSED;
1804 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1805 boolean *again ATTRIBUTE_UNUSED;
1807 #if VMS_DEBUG
1808 vms_debug (1, "vms_bfd_relax_section(%p, %s, %p, <ret>)\n",
1809 abfd, section->name, link_info);
1810 #endif
1811 return true;
1814 static boolean
1815 vms_bfd_gc_sections (abfd, link_info)
1816 bfd *abfd ATTRIBUTE_UNUSED;
1817 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1819 #if VMS_DEBUG
1820 vms_debug (1, "vms_bfd_gc_sections(%p, %p)\n", abfd, link_info);
1821 #endif
1822 return true;
1826 /* Create a hash table for the linker. Different backends store
1827 different information in this table. */
1829 static struct bfd_link_hash_table *
1830 vms_bfd_link_hash_table_create (abfd)
1831 bfd *abfd ATTRIBUTE_UNUSED;
1833 #if VMS_DEBUG
1834 vms_debug (1, "vms_bfd_link_hash_table_create(%p)\n", abfd);
1835 #endif
1836 return 0;
1840 /* Add symbols from this object file into the hash table. */
1842 static boolean
1843 vms_bfd_link_add_symbols (abfd, link_info)
1844 bfd *abfd ATTRIBUTE_UNUSED;
1845 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1847 #if VMS_DEBUG
1848 vms_debug (1, "vms_bfd_link_add_symbols(%p, %p)\n", abfd, link_info);
1849 #endif
1850 return false;
1854 /* Do a link based on the link_order structures attached to each
1855 section of the BFD. */
1857 static boolean
1858 vms_bfd_final_link (abfd, link_info)
1859 bfd *abfd ATTRIBUTE_UNUSED;
1860 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1862 #if VMS_DEBUG
1863 vms_debug (1, "vms_bfd_final_link(%p, %p)\n", abfd, link_info);
1864 #endif
1865 return true;
1868 /* Should this section be split up into smaller pieces during linking. */
1870 static boolean
1871 vms_bfd_link_split_section (abfd, section)
1872 bfd *abfd ATTRIBUTE_UNUSED;
1873 asection *section ATTRIBUTE_UNUSED;
1875 #if VMS_DEBUG
1876 vms_debug (1, "vms_bfd_link_split_section(%p, %s)\n", abfd, section->name);
1877 #endif
1878 return false;
1881 /*-- Part 4.9, dynamic symbols and relocations ------------------------------*/
1883 /* Get the amount of memory required to hold the dynamic symbols. */
1885 static long
1886 vms_get_dynamic_symtab_upper_bound (abfd)
1887 bfd *abfd ATTRIBUTE_UNUSED;
1889 #if VMS_DEBUG
1890 vms_debug (1, "vms_get_dynamic_symtab_upper_bound(%p)\n", abfd);
1891 #endif
1892 return 0;
1895 static boolean
1896 vms_bfd_print_private_bfd_data (abfd, file)
1897 bfd *abfd ATTRIBUTE_UNUSED;
1898 void *file ATTRIBUTE_UNUSED;
1900 #if VMS_DEBUG
1901 vms_debug (1, "vms_bfd_print_private_bfd_data(%p)\n", abfd);
1902 #endif
1903 return 0;
1907 /* Read in the dynamic symbols. */
1909 static long
1910 vms_canonicalize_dynamic_symtab (abfd, symbols)
1911 bfd *abfd ATTRIBUTE_UNUSED;
1912 asymbol **symbols ATTRIBUTE_UNUSED;
1914 #if VMS_DEBUG
1915 vms_debug (1, "vms_canonicalize_dynamic_symtab(%p, <ret>)\n", abfd);
1916 #endif
1917 return 0L;
1921 /* Get the amount of memory required to hold the dynamic relocs. */
1923 static long
1924 vms_get_dynamic_reloc_upper_bound (abfd)
1925 bfd *abfd ATTRIBUTE_UNUSED;
1927 #if VMS_DEBUG
1928 vms_debug (1, "vms_get_dynamic_reloc_upper_bound(%p)\n", abfd);
1929 #endif
1930 return 0L;
1934 /* Read in the dynamic relocs. */
1936 static long
1937 vms_canonicalize_dynamic_reloc (abfd, arel, symbols)
1938 bfd *abfd ATTRIBUTE_UNUSED;
1939 arelent **arel ATTRIBUTE_UNUSED;
1940 asymbol **symbols ATTRIBUTE_UNUSED;
1942 #if VMS_DEBUG
1943 vms_debug (1, "vms_canonicalize_dynamic_reloc(%p)\n", abfd);
1944 #endif
1945 return 0L;