* archures.c (bfd_mach_i386_i386, bfd_mach_i386_i8086,
[binutils.git] / bfd / vms.c
blobfc6bcc3e161b5450d32bbed9f143c14a2576552e
1 /* vms.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 Written by Klaus K"ampf (kkaempf@rmi.de)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "bfdlink.h"
25 #include "libbfd.h"
27 #include "vms.h"
29 static boolean vms_initialize PARAMS ((bfd *));
30 static unsigned int priv_section_count;
31 static boolean fill_section_ptr PARAMS ((struct bfd_hash_entry *, PTR));
32 static boolean vms_fixup_sections PARAMS ((bfd *));
33 static boolean copy_symbols PARAMS ((struct bfd_hash_entry *, PTR));
34 static bfd_reloc_status_type reloc_nil
35 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
36 static const struct bfd_target *vms_object_p PARAMS ((bfd *abfd));
37 static const struct bfd_target *vms_archive_p PARAMS ((bfd *abfd));
38 static boolean vms_mkobject PARAMS ((bfd *abfd));
39 static boolean vms_write_object_contents PARAMS ((bfd *abfd));
40 static boolean vms_close_and_cleanup PARAMS ((bfd *abfd));
41 static boolean vms_bfd_free_cached_info PARAMS ((bfd *abfd));
42 static boolean vms_new_section_hook PARAMS ((bfd *abfd, asection *section));
43 static boolean vms_get_section_contents
44 PARAMS ((bfd *abfd, asection *section, PTR x1, file_ptr x2,
45 bfd_size_type x3));
46 static boolean vms_get_section_contents_in_window
47 PARAMS ((bfd *abfd, asection *section, bfd_window *w, file_ptr offset,
48 bfd_size_type count));
49 static boolean vms_bfd_copy_private_bfd_data PARAMS ((bfd *src, bfd *dest));
50 static boolean vms_bfd_copy_private_section_data
51 PARAMS ((bfd *srcbfd, asection *srcsec, bfd *dstbfd, asection *dstsec));
52 static boolean vms_bfd_copy_private_symbol_data
53 PARAMS ((bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym));
54 static boolean vms_bfd_print_private_bfd_data
55 PARAMS ((bfd *abfd, void *file));
56 static char *vms_core_file_failing_command PARAMS ((bfd *abfd));
57 static int vms_core_file_failing_signal PARAMS ((bfd *abfd));
58 static boolean vms_core_file_matches_executable_p
59 PARAMS ((bfd *abfd, bfd *bbfd));
60 static boolean vms_slurp_armap PARAMS ((bfd *abfd));
61 static boolean vms_slurp_extended_name_table PARAMS ((bfd *abfd));
62 static boolean vms_construct_extended_name_table
63 PARAMS ((bfd *abfd, char **tabloc, bfd_size_type *tablen,
64 const char **name));
65 static void vms_truncate_arname
66 PARAMS ((bfd *abfd, const char *pathname, char *arhdr));
67 static boolean vms_write_armap
68 PARAMS ((bfd *arch, unsigned int elength, struct orl *map,
69 unsigned int orl_count, int stridx));
70 static PTR vms_read_ar_hdr PARAMS ((bfd *abfd));
71 static bfd *vms_get_elt_at_index PARAMS ((bfd *abfd, symindex index));
72 static bfd *vms_openr_next_archived_file PARAMS ((bfd *arch, bfd *prev));
73 static boolean vms_update_armap_timestamp PARAMS ((bfd *abfd));
74 static int vms_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
75 static long vms_get_symtab_upper_bound PARAMS ((bfd *abfd));
76 static long vms_get_symtab PARAMS ((bfd *abfd, asymbol **symbols));
77 static void vms_print_symbol
78 PARAMS ((bfd *abfd, PTR file, asymbol *symbol, bfd_print_symbol_type how));
79 static void vms_get_symbol_info
80 PARAMS ((bfd *abfd, asymbol *symbol, symbol_info *ret));
81 static boolean vms_bfd_is_local_label_name PARAMS ((bfd *abfd, const char *));
82 static alent *vms_get_lineno PARAMS ((bfd *abfd, asymbol *symbol));
83 static boolean vms_find_nearest_line
84 PARAMS ((bfd *abfd, asection *section, asymbol **symbols, bfd_vma offset,
85 const char **file, const char **func, unsigned int *line));
86 static asymbol *vms_bfd_make_debug_symbol
87 PARAMS ((bfd *abfd, void *ptr, unsigned long size));
88 static long vms_read_minisymbols
89 PARAMS ((bfd *abfd, boolean dynamic, PTR *minisymsp, unsigned int *sizep));
90 static asymbol *vms_minisymbol_to_symbol
91 PARAMS ((bfd *abfd, boolean dynamic, const PTR minisym, asymbol *sym));
92 static long vms_get_reloc_upper_bound PARAMS ((bfd *abfd, asection *sect));
93 static long vms_canonicalize_reloc
94 PARAMS ((bfd *abfd, asection *srcsec, arelent **location,
95 asymbol **symbols));
96 static const struct reloc_howto_struct *vms_bfd_reloc_type_lookup
97 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
98 static boolean vms_set_arch_mach
99 PARAMS ((bfd *abfd, enum bfd_architecture arch, unsigned long mach));
100 static boolean vms_set_section_contents
101 PARAMS ((bfd *abfd, asection *section, PTR location, file_ptr offset,
102 bfd_size_type count));
103 static int vms_sizeof_headers PARAMS ((bfd *abfd, boolean reloc));
104 static bfd_byte *vms_bfd_get_relocated_section_contents
105 PARAMS ((bfd *abfd, struct bfd_link_info *link_info,
106 struct bfd_link_order *link_order, bfd_byte *data,
107 boolean relocateable, asymbol **symbols));
108 static boolean vms_bfd_relax_section
109 PARAMS ((bfd *abfd, asection *section, struct bfd_link_info *link_info,
110 boolean *again));
111 static boolean vms_bfd_gc_sections
112 PARAMS ((bfd *abfd, struct bfd_link_info *link_info));
113 static boolean vms_bfd_merge_sections
114 PARAMS ((bfd *abfd, struct bfd_link_info *link_info));
115 static struct bfd_link_hash_table *vms_bfd_link_hash_table_create
116 PARAMS ((bfd *abfd));
117 static void vms_bfd_link_hash_table_free
118 PARAMS ((struct bfd_link_hash_table *hash));
119 static boolean vms_bfd_link_add_symbols
120 PARAMS ((bfd *abfd, struct bfd_link_info *link_info));
121 static boolean vms_bfd_final_link
122 PARAMS ((bfd *abfd, struct bfd_link_info *link_info));
123 static boolean vms_bfd_link_split_section
124 PARAMS ((bfd *abfd, asection *section));
125 static long vms_get_dynamic_symtab_upper_bound PARAMS ((bfd *abfd));
126 static long vms_canonicalize_dynamic_symtab
127 PARAMS ((bfd *abfd, asymbol **symbols));
128 static long vms_get_dynamic_reloc_upper_bound PARAMS ((bfd *abfd));
129 static long vms_canonicalize_dynamic_reloc
130 PARAMS ((bfd *abfd, arelent **arel, asymbol **symbols));
131 static boolean vms_bfd_merge_private_bfd_data PARAMS ((bfd *ibfd, bfd *obfd));
132 static boolean vms_bfd_set_private_flags PARAMS ((bfd *abfd, flagword flags));
134 #define vms_make_empty_symbol _bfd_generic_make_empty_symbol
135 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
136 #define vms_bfd_discard_group bfd_generic_discard_group
138 /*===========================================================================*/
140 const bfd_target vms_alpha_vec =
142 "vms-alpha", /* name */
143 bfd_target_evax_flavour,
144 BFD_ENDIAN_LITTLE, /* data byte order is little */
145 BFD_ENDIAN_LITTLE, /* header byte order is little */
147 (HAS_RELOC | HAS_SYMS
148 | WP_TEXT | D_PAGED), /* object flags */
149 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
150 | SEC_READONLY | SEC_CODE | SEC_DATA
151 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* sect flags */
152 0, /* symbol_leading_char */
153 ' ', /* ar_pad_char */
154 15, /* ar_max_namelen */
155 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
156 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
157 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
158 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
159 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
160 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
162 {_bfd_dummy_target, vms_object_p, /* bfd_check_format */
163 vms_archive_p, _bfd_dummy_target},
164 {bfd_false, vms_mkobject, /* bfd_set_format */
165 _bfd_generic_mkarchive, bfd_false},
166 {bfd_false, vms_write_object_contents, /* bfd_write_contents */
167 _bfd_write_archive_contents, bfd_false},
169 BFD_JUMP_TABLE_GENERIC (vms),
170 BFD_JUMP_TABLE_COPY (vms),
171 BFD_JUMP_TABLE_CORE (vms),
172 BFD_JUMP_TABLE_ARCHIVE (vms),
173 BFD_JUMP_TABLE_SYMBOLS (vms),
174 BFD_JUMP_TABLE_RELOCS (vms),
175 BFD_JUMP_TABLE_WRITE (vms),
176 BFD_JUMP_TABLE_LINK (vms),
177 BFD_JUMP_TABLE_DYNAMIC (vms),
179 NULL,
181 (PTR) 0
184 const bfd_target vms_vax_vec =
186 "vms-vax", /* name */
187 bfd_target_ovax_flavour,
188 BFD_ENDIAN_LITTLE, /* data byte order is little */
189 BFD_ENDIAN_LITTLE, /* header byte order is little */
191 (HAS_RELOC | HAS_SYMS /* object flags */
192 | WP_TEXT | D_PAGED
193 | HAS_LINENO | HAS_DEBUG | HAS_LOCALS),
195 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
196 | SEC_READONLY | SEC_CODE | SEC_DATA
197 | SEC_HAS_CONTENTS | SEC_IN_MEMORY), /* sect flags */
198 0, /* symbol_leading_char */
199 ' ', /* ar_pad_char */
200 15, /* ar_max_namelen */
201 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
202 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
203 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
204 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
205 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
206 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
208 {_bfd_dummy_target, vms_object_p, /* bfd_check_format */
209 vms_archive_p, _bfd_dummy_target},
210 {bfd_false, vms_mkobject, /* bfd_set_format */
211 _bfd_generic_mkarchive, bfd_false},
212 {bfd_false, vms_write_object_contents, /* bfd_write_contents */
213 _bfd_write_archive_contents, bfd_false},
215 BFD_JUMP_TABLE_GENERIC (vms),
216 BFD_JUMP_TABLE_COPY (vms),
217 BFD_JUMP_TABLE_CORE (vms),
218 BFD_JUMP_TABLE_ARCHIVE (vms),
219 BFD_JUMP_TABLE_SYMBOLS (vms),
220 BFD_JUMP_TABLE_RELOCS (vms),
221 BFD_JUMP_TABLE_WRITE (vms),
222 BFD_JUMP_TABLE_LINK (vms),
223 BFD_JUMP_TABLE_DYNAMIC (vms),
225 NULL,
227 (PTR) 0
230 /*===========================================================================*/
232 /* Initialize private data */
234 static boolean
235 vms_initialize (abfd)
236 bfd *abfd;
238 int i;
239 bfd_size_type amt;
241 bfd_set_start_address (abfd, (bfd_vma) -1);
243 amt = sizeof (struct vms_private_data_struct);
244 abfd->tdata.any = (struct vms_private_data_struct*) bfd_alloc (abfd, amt);
245 if (abfd->tdata.any == 0)
246 return false;
248 #ifdef __ALPHA
249 PRIV (is_vax) = 0;
250 #else
251 PRIV (is_vax) = 1;
252 #endif
253 PRIV (vms_buf) = 0;
254 PRIV (buf_size) = 0;
255 PRIV (rec_length) = 0;
256 PRIV (file_format) = FF_UNKNOWN;
257 PRIV (fixup_done) = false;
258 PRIV (sections) = NULL;
260 amt = sizeof (struct stack_struct) * STACKSIZE;
261 PRIV (stack) = (struct stack_struct *) bfd_alloc (abfd, amt);
262 if (PRIV (stack) == 0)
263 goto error_ret1;
264 PRIV (stackptr) = 0;
266 amt = sizeof (struct bfd_hash_table);
267 PRIV (vms_symbol_table) = (struct bfd_hash_table *) bfd_alloc (abfd, amt);
268 if (PRIV (vms_symbol_table) == 0)
269 goto error_ret1;
271 if (!bfd_hash_table_init (PRIV (vms_symbol_table), _bfd_vms_hash_newfunc))
272 goto error_ret1;
274 amt = sizeof (struct location_struct) * LOCATION_SAVE_SIZE;
275 PRIV (location_stack) = (struct location_struct *) bfd_alloc (abfd, amt);
276 if (PRIV (location_stack) == 0)
277 goto error_ret2;
279 for (i = 0; i < VMS_SECTION_COUNT; i++)
280 PRIV (vms_section_table)[i] = NULL;
282 amt = MAX_OUTREC_SIZE;
283 PRIV (output_buf) = (unsigned char *) bfd_alloc (abfd, amt);
284 if (PRIV (output_buf) == 0)
285 goto error_ret2;
287 PRIV (push_level) = 0;
288 PRIV (pushed_size) = 0;
289 PRIV (length_pos) = 2;
290 PRIV (output_size) = 0;
291 PRIV (output_alignment) = 1;
293 return true;
295 error_ret2:
296 bfd_hash_table_free (PRIV (vms_symbol_table));
297 error_ret1:
298 bfd_release (abfd, abfd->tdata.any);
299 abfd->tdata.any = 0;
300 return false;
303 /* Fill symbol->section with section ptr
304 symbol->section is filled with the section index for defined symbols
305 during reading the GSD/EGSD section. But we need the pointer to the
306 bfd section later.
308 It has the correct value for referenced (undefined section) symbols
310 called from bfd_hash_traverse in vms_fixup_sections */
312 static boolean
313 fill_section_ptr (entry, sections)
314 struct bfd_hash_entry *entry;
315 PTR sections;
317 asection *sec;
318 asymbol *sym;
320 sym = ((vms_symbol_entry *)entry)->symbol;
321 sec = sym->section;
323 #if VMS_DEBUG
324 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym, sec);
325 #endif
327 /* fill forward references (these contain section number, not section ptr). */
329 if ((unsigned int) sec < priv_section_count)
331 sec = ((vms_symbol_entry *)entry)->symbol->section =
332 ((asection **)sections)[(int)sec];
335 if (strcmp (sym->name, sec->name) == 0)
336 sym->flags |= BSF_SECTION_SYM;
338 return true;
341 /* Fixup sections
342 set up all pointers and arrays, counters and sizes are fixed now
344 we build a private sections vector for easy access since sections
345 are always referenced by an index number.
347 alloc PRIV(sections) according to abfd->section_count
348 copy abfd->sections to PRIV(sections) */
350 static boolean
351 vms_fixup_sections (abfd)
352 bfd *abfd;
354 if (PRIV (fixup_done))
355 return true;
358 * traverse symbol table and fill in all section pointers
361 /* can't provide section count as argument to fill_section_ptr(). */
362 priv_section_count = PRIV (section_count);
363 bfd_hash_traverse (PRIV (vms_symbol_table), fill_section_ptr,
364 (PTR) (PRIV (sections)));
366 PRIV (fixup_done) = true;
368 return true;
371 /*===========================================================================*/
373 /* Check the format for a file being read.
374 Return a (bfd_target *) if it's an object file or zero if not. */
376 static const struct bfd_target *
377 vms_object_p (abfd)
378 bfd *abfd;
380 int err = 0;
381 int prev_type;
382 const struct bfd_target *target_vector = 0;
383 const bfd_arch_info_type *arch = 0;
384 PTR tdata_save = abfd->tdata.any;
386 #if VMS_DEBUG
387 vms_debug (1, "vms_object_p(%p)\n", abfd);
388 #endif
390 if (!vms_initialize (abfd))
391 goto error_ret;
393 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
394 goto err_wrong_format;
396 prev_type = -1;
400 #if VMS_DEBUG
401 vms_debug (7, "reading at %08lx\n", bfd_tell(abfd));
402 #endif
403 if (_bfd_vms_next_record (abfd) < 0)
405 #if VMS_DEBUG
406 vms_debug (2, "next_record failed\n");
407 #endif
408 goto err_wrong_format;
411 if ((prev_type == EOBJ_S_C_EGSD)
412 && (PRIV (rec_type) != EOBJ_S_C_EGSD))
414 if (! vms_fixup_sections (abfd))
416 #if VMS_DEBUG
417 vms_debug (2, "vms_fixup_sections failed\n");
418 #endif
419 goto err_wrong_format;
423 prev_type = PRIV (rec_type);
425 if (target_vector == 0)
427 if (prev_type <= OBJ_S_C_MAXRECTYP)
428 target_vector = &vms_vax_vec;
429 else
430 target_vector = &vms_alpha_vec;
433 switch (prev_type)
435 case OBJ_S_C_HDR:
436 case EOBJ_S_C_EMH:
437 err = _bfd_vms_slurp_hdr (abfd, prev_type);
438 break;
439 case OBJ_S_C_EOM:
440 case OBJ_S_C_EOMW:
441 case EOBJ_S_C_EEOM:
442 err = _bfd_vms_slurp_eom (abfd, prev_type);
443 break;
444 case OBJ_S_C_GSD:
445 case EOBJ_S_C_EGSD:
446 err = _bfd_vms_slurp_gsd (abfd, prev_type);
447 break;
448 case OBJ_S_C_TIR:
449 case EOBJ_S_C_ETIR:
450 err = _bfd_vms_slurp_tir (abfd, prev_type);
451 break;
452 case OBJ_S_C_DBG:
453 case EOBJ_S_C_EDBG:
454 err = _bfd_vms_slurp_dbg (abfd, prev_type);
455 break;
456 case OBJ_S_C_TBT:
457 case EOBJ_S_C_ETBT:
458 err = _bfd_vms_slurp_tbt (abfd, prev_type);
459 break;
460 case OBJ_S_C_LNK:
461 err = _bfd_vms_slurp_lnk (abfd, prev_type);
462 break;
463 default:
464 err = -1;
466 if (err != 0)
468 #if VMS_DEBUG
469 vms_debug (2, "slurp type %d failed with %d\n", prev_type, err);
470 #endif
471 goto err_wrong_format;
474 while ((prev_type != EOBJ_S_C_EEOM) && (prev_type != OBJ_S_C_EOM) && (prev_type != OBJ_S_C_EOMW));
476 if (target_vector == &vms_vax_vec)
478 if (! vms_fixup_sections (abfd))
480 #if VMS_DEBUG
481 vms_debug (2, "vms_fixup_sections failed\n");
482 #endif
483 goto err_wrong_format;
486 /* set arch_info to vax */
488 arch = bfd_scan_arch ("vax");
489 PRIV (is_vax) = 1;
490 #if VMS_DEBUG
491 vms_debug (2, "arch is vax\n");
492 #endif
494 else if (target_vector == &vms_alpha_vec)
496 /* set arch_info to alpha */
498 arch = bfd_scan_arch ("alpha");
499 PRIV (is_vax) = 0;
500 #if VMS_DEBUG
501 vms_debug (2, "arch is alpha\n");
502 #endif
505 if (arch == 0)
507 #if VMS_DEBUG
508 vms_debug (2, "arch not found\n");
509 #endif
510 goto err_wrong_format;
512 abfd->arch_info = arch;
514 return target_vector;
516 err_wrong_format:
517 bfd_set_error (bfd_error_wrong_format);
518 error_ret:
519 if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
520 bfd_release (abfd, abfd->tdata.any);
521 abfd->tdata.any = tdata_save;
522 return NULL;
525 /* Check the format for a file being read.
526 Return a (bfd_target *) if it's an archive file or zero. */
528 static const struct bfd_target *
529 vms_archive_p (abfd)
530 bfd *abfd ATTRIBUTE_UNUSED;
532 #if VMS_DEBUG
533 vms_debug (1, "vms_archive_p(%p)\n", abfd);
534 #endif
536 return 0;
539 /* Set the format of a file being written. */
541 static boolean
542 vms_mkobject (abfd)
543 bfd *abfd;
545 #if VMS_DEBUG
546 vms_debug (1, "vms_mkobject(%p)\n", abfd);
547 #endif
549 if (!vms_initialize (abfd))
550 return 0;
553 #ifdef __VAX
554 const bfd_arch_info_type *arch = bfd_scan_arch ("vax");
555 #else
556 const bfd_arch_info_type *arch = bfd_scan_arch ("alpha");
557 #endif
558 if (arch == 0)
560 bfd_set_error(bfd_error_wrong_format);
561 return 0;
563 abfd->arch_info = arch;
566 return true;
569 /* Write cached information into a file being written, at bfd_close. */
571 static boolean
572 vms_write_object_contents (abfd)
573 bfd *abfd;
575 #if VMS_DEBUG
576 vms_debug (1, "vms_write_object_contents(%p)\n", abfd);
577 #endif
579 if (abfd->section_count > 0) /* we have sections */
581 if (PRIV (is_vax))
583 if (_bfd_vms_write_hdr (abfd, OBJ_S_C_HDR) != 0)
584 return false;
585 if (_bfd_vms_write_gsd (abfd, OBJ_S_C_GSD) != 0)
586 return false;
587 if (_bfd_vms_write_tir (abfd, OBJ_S_C_TIR) != 0)
588 return false;
589 if (_bfd_vms_write_tbt (abfd, OBJ_S_C_TBT) != 0)
590 return false;
591 if (_bfd_vms_write_dbg (abfd, OBJ_S_C_DBG) != 0)
592 return false;
593 if (abfd->section_count > 255)
595 if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOMW) != 0)
596 return false;
598 else
600 if (_bfd_vms_write_eom (abfd, OBJ_S_C_EOM) != 0)
601 return false;
604 else
606 if (_bfd_vms_write_hdr (abfd, EOBJ_S_C_EMH) != 0)
607 return false;
608 if (_bfd_vms_write_gsd (abfd, EOBJ_S_C_EGSD) != 0)
609 return false;
610 if (_bfd_vms_write_tir (abfd, EOBJ_S_C_ETIR) != 0)
611 return false;
612 if (_bfd_vms_write_tbt (abfd, EOBJ_S_C_ETBT) != 0)
613 return false;
614 if (_bfd_vms_write_dbg (abfd, EOBJ_S_C_EDBG) != 0)
615 return false;
616 if (_bfd_vms_write_eom (abfd, EOBJ_S_C_EEOM) != 0)
617 return false;
620 return true;
623 /*-- 4.1, generic -----------------------------------------------------------*/
625 /* Called when the BFD is being closed to do any necessary cleanup. */
627 static boolean
628 vms_close_and_cleanup (abfd)
629 bfd *abfd;
631 #if VMS_DEBUG
632 vms_debug (1, "vms_close_and_cleanup(%p)\n", abfd);
633 #endif
634 if (abfd == 0)
635 return true;
637 if (PRIV (vms_buf) != NULL)
638 free (PRIV (vms_buf));
640 if (PRIV (sections) != NULL)
641 free (PRIV (sections));
643 if (PRIV (vms_symbol_table))
644 bfd_hash_table_free (PRIV (vms_symbol_table));
646 bfd_release (abfd, abfd->tdata.any);
647 abfd->tdata.any = NULL;
649 return true;
652 /* Ask the BFD to free all cached information. */
653 static boolean
654 vms_bfd_free_cached_info (abfd)
655 bfd *abfd ATTRIBUTE_UNUSED;
657 #if VMS_DEBUG
658 vms_debug (1, "vms_bfd_free_cached_info(%p)\n", abfd);
659 #endif
660 return true;
663 /* Called when a new section is created. */
665 static boolean
666 vms_new_section_hook (abfd, section)
667 bfd *abfd;
668 asection *section;
670 /* Count hasn't been incremented yet. */
671 unsigned int section_count = abfd->section_count + 1;
673 #if VMS_DEBUG
674 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
675 abfd, section->index, section->name, section_count);
676 #endif
677 bfd_set_section_alignment (abfd, section, 4);
679 if (section_count > PRIV (section_count))
681 bfd_size_type amt = section_count;
682 amt *= sizeof (asection *);
683 PRIV (sections) = (asection **) bfd_realloc (PRIV (sections), amt);
684 if (PRIV (sections) == 0)
685 return false;
686 PRIV (section_count) = section_count;
688 #if VMS_DEBUG
689 vms_debug (6, "section_count: %d\n", PRIV (section_count));
690 #endif
691 PRIV (sections)[section->index] = section;
692 #if VMS_DEBUG
693 vms_debug (7, "%d: %s\n", section->index, section->name);
694 #endif
696 return true;
699 /* Read the contents of a section.
700 buf points to a buffer of buf_size bytes to be filled with
701 section data (starting at offset into section) */
703 static boolean
704 vms_get_section_contents (abfd, section, buf, offset, buf_size)
705 bfd *abfd ATTRIBUTE_UNUSED;
706 asection *section ATTRIBUTE_UNUSED;
707 PTR buf ATTRIBUTE_UNUSED;
708 file_ptr offset ATTRIBUTE_UNUSED;
709 bfd_size_type buf_size ATTRIBUTE_UNUSED;
711 #if VMS_DEBUG
712 vms_debug (1, "vms_get_section_contents(%p, %s, %p, off %ld, size %d)\n",
713 abfd, section->name, buf, offset, (int)buf_size);
714 #endif
716 /* shouldn't be called, since all sections are IN_MEMORY */
718 return false;
721 /* Read the contents of a section.
722 buf points to a buffer of buf_size bytes to be filled with
723 section data (starting at offset into section) */
725 static boolean
726 vms_get_section_contents_in_window (abfd, section, w, offset, count)
727 bfd *abfd ATTRIBUTE_UNUSED;
728 asection *section ATTRIBUTE_UNUSED;
729 bfd_window *w ATTRIBUTE_UNUSED;
730 file_ptr offset ATTRIBUTE_UNUSED;
731 bfd_size_type count ATTRIBUTE_UNUSED;
733 #if VMS_DEBUG
734 vms_debug (1, "vms_get_section_contents_in_window(%p, %s, %p, off %ld, count %d)\n",
735 abfd, section->name, w, offset, (int)count);
736 #endif
738 /* shouldn't be called, since all sections are IN_MEMORY */
740 return false;
743 /*-- Part 4.2, copy private data --------------------------------------------*/
745 /* Called to copy BFD general private data from one object file
746 to another. */
748 static boolean
749 vms_bfd_copy_private_bfd_data (src, dest)
750 bfd *src ATTRIBUTE_UNUSED;
751 bfd *dest ATTRIBUTE_UNUSED;
753 #if VMS_DEBUG
754 vms_debug (1, "vms_bfd_copy_private_bfd_data(%p, %p)\n", src, dest);
755 #endif
756 return true;
759 /* Merge private BFD information from the BFD @var{ibfd} to the
760 the output file BFD @var{obfd} when linking. Return <<true>>
761 on success, <<false>> on error. Possible error returns are:
763 o <<bfd_error_no_memory>> -
764 Not enough memory exists to create private data for @var{obfd}. */
766 static boolean
767 vms_bfd_merge_private_bfd_data (ibfd, obfd)
768 bfd *ibfd ATTRIBUTE_UNUSED;
769 bfd *obfd ATTRIBUTE_UNUSED;
771 #if VMS_DEBUG
772 vms_debug (1,"vms_bfd_merge_private_bfd_data(%p, %p)\n", ibfd, obfd);
773 #endif
774 return true;
777 /* Set private BFD flag information in the BFD @var{abfd}.
778 Return <<true>> on success, <<false>> on error. Possible error
779 returns are:
781 o <<bfd_error_no_memory>> -
782 Not enough memory exists to create private data for @var{obfd}. */
784 static boolean
785 vms_bfd_set_private_flags (abfd, flags)
786 bfd *abfd ATTRIBUTE_UNUSED;
787 flagword flags ATTRIBUTE_UNUSED;
789 #if VMS_DEBUG
790 vms_debug (1,"vms_bfd_set_private_flags(%p, %lx)\n", abfd, (long)flags);
791 #endif
792 return true;
795 /* Called to copy BFD private section data from one object file
796 to another. */
798 static boolean
799 vms_bfd_copy_private_section_data (srcbfd, srcsec, dstbfd, dstsec)
800 bfd *srcbfd ATTRIBUTE_UNUSED;
801 asection *srcsec ATTRIBUTE_UNUSED;
802 bfd *dstbfd ATTRIBUTE_UNUSED;
803 asection *dstsec ATTRIBUTE_UNUSED;
805 #if VMS_DEBUG
806 vms_debug (1, "vms_bfd_copy_private_section_data(%p, %s, %p, %s)\n",
807 srcbfd, srcsec->name, dstbfd, dstsec->name);
808 #endif
809 return true;
812 /* Called to copy BFD private symbol data from one object file
813 to another. */
815 static boolean
816 vms_bfd_copy_private_symbol_data (ibfd, isym, obfd, osym)
817 bfd *ibfd ATTRIBUTE_UNUSED;
818 asymbol *isym ATTRIBUTE_UNUSED;
819 bfd *obfd ATTRIBUTE_UNUSED;
820 asymbol *osym ATTRIBUTE_UNUSED;
822 #if VMS_DEBUG
823 vms_debug (1, "vms_bfd_copy_private_symbol_data(%p, %s, %p, %s)\n",
824 ibfd, isym->name, obfd, osym->name);
825 #endif
826 return true;
829 /*-- Part 4.3, core file ----------------------------------------------------*/
831 /* Return a read-only string explaining which program was running
832 when it failed and produced the core file abfd. */
834 static char *
835 vms_core_file_failing_command (abfd)
836 bfd *abfd ATTRIBUTE_UNUSED;
838 #if VMS_DEBUG
839 vms_debug (1, "vms_core_file_failing_command(%p)\n", abfd);
840 #endif
841 return 0;
844 /* Returns the signal number which caused the core dump which
845 generated the file the BFD abfd is attached to. */
847 static int
848 vms_core_file_failing_signal (abfd)
849 bfd *abfd ATTRIBUTE_UNUSED;
851 #if VMS_DEBUG
852 vms_debug (1, "vms_core_file_failing_signal(%p)\n", abfd);
853 #endif
854 return 0;
857 /* Return true if the core file attached to core_bfd was generated
858 by a run of the executable file attached to exec_bfd, false otherwise. */
860 static boolean
861 vms_core_file_matches_executable_p (abfd, bbfd)
862 bfd *abfd ATTRIBUTE_UNUSED;
863 bfd *bbfd ATTRIBUTE_UNUSED;
865 #if VMS_DEBUG
866 vms_debug (1, "vms_core_file_matches_executable_p(%p, %p)\n", abfd, bbfd);
867 #endif
868 return false;
871 /*-- Part 4.4, archive ------------------------------------------------------*/
873 /* ??? do something with an archive map.
874 Return false on error, true otherwise. */
876 static boolean
877 vms_slurp_armap (abfd)
878 bfd *abfd ATTRIBUTE_UNUSED;
880 #if VMS_DEBUG
881 vms_debug (1, "vms_slurp_armap(%p)\n", abfd);
882 #endif
883 return false;
886 /* ??? do something with an extended name table.
887 Return false on error, true otherwise. */
889 static boolean
890 vms_slurp_extended_name_table (abfd)
891 bfd *abfd ATTRIBUTE_UNUSED;
893 #if VMS_DEBUG
894 vms_debug (1, "vms_slurp_extended_name_table(%p)\n", abfd);
895 #endif
896 return false;
899 /* ??? do something with an extended name table.
900 Return false on error, true otherwise. */
902 static boolean
903 vms_construct_extended_name_table (abfd, tabloc, tablen, name)
904 bfd *abfd ATTRIBUTE_UNUSED;
905 char **tabloc ATTRIBUTE_UNUSED;
906 bfd_size_type *tablen ATTRIBUTE_UNUSED;
907 const char **name ATTRIBUTE_UNUSED;
909 #if VMS_DEBUG
910 vms_debug (1, "vms_construct_extended_name_table(%p)\n", abfd);
911 #endif
912 return false;
915 /* Truncate the name of an archive to match system-dependent restrictions */
917 static void
918 vms_truncate_arname (abfd, pathname, arhdr)
919 bfd *abfd ATTRIBUTE_UNUSED;
920 const char *pathname ATTRIBUTE_UNUSED;
921 char *arhdr ATTRIBUTE_UNUSED;
923 #if VMS_DEBUG
924 vms_debug (1, "vms_truncate_arname(%p, %s, %s)\n", abfd, pathname, arhdr);
925 #endif
926 return;
929 /* ??? write archive map */
931 static boolean
932 vms_write_armap (arch, elength, map, orl_count, stridx)
933 bfd *arch ATTRIBUTE_UNUSED;
934 unsigned int elength ATTRIBUTE_UNUSED;
935 struct orl *map ATTRIBUTE_UNUSED;
936 unsigned int orl_count ATTRIBUTE_UNUSED;
937 int stridx ATTRIBUTE_UNUSED;
939 #if VMS_DEBUG
940 vms_debug (1, "vms_write_armap(%p, %d, %p, %d %d)\n",
941 arch, elength, map, orl_count, stridx);
942 #endif
943 return true;
946 /* Read archive header ??? */
948 static PTR
949 vms_read_ar_hdr (abfd)
950 bfd * abfd ATTRIBUTE_UNUSED;
952 #if VMS_DEBUG
953 vms_debug (1, "vms_read_ar_hdr(%p)\n", abfd);
954 #endif
955 return (PTR)0;
958 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
959 an input BFD on the first contained element and returns that.
960 Subsequent calls should pass the archive and the previous return value
961 to return a created BFD to the next contained element.
962 NULL is returned when there are no more. */
964 static bfd *
965 vms_openr_next_archived_file (arch, prev)
966 bfd *arch ATTRIBUTE_UNUSED;
967 bfd *prev ATTRIBUTE_UNUSED;
969 #if VMS_DEBUG
970 vms_debug (1, "vms_openr_next_archived_file(%p, %p)\n", arch, prev);
971 #endif
972 return NULL;
975 /* Return the BFD which is referenced by the symbol in ABFD indexed by
976 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
978 static bfd *
979 vms_get_elt_at_index (abfd, index)
980 bfd *abfd;
981 symindex index;
983 #if VMS_DEBUG
984 vms_debug (1, "vms_get_elt_at_index(%p, %p)\n", abfd, index);
985 #endif
986 return _bfd_generic_get_elt_at_index(abfd, index);
989 /* ???
990 -> bfd_generic_stat_arch_elt */
992 static int
993 vms_generic_stat_arch_elt (abfd, st)
994 bfd *abfd;
995 struct stat *st;
997 #if VMS_DEBUG
998 vms_debug (1, "vms_generic_stat_arch_elt(%p, %p)\n", abfd, st);
999 #endif
1000 return bfd_generic_stat_arch_elt (abfd, st);
1003 /* This is a new function in bfd 2.5 */
1005 static boolean
1006 vms_update_armap_timestamp (abfd)
1007 bfd *abfd ATTRIBUTE_UNUSED;
1009 #if VMS_DEBUG
1010 vms_debug (1, "vms_update_armap_timestamp(%p)\n", abfd);
1011 #endif
1012 return true;
1015 /*-- Part 4.5, symbols --------------------------------------------------------*/
1017 /* Return the number of bytes required to store a vector of pointers
1018 to asymbols for all the symbols in the BFD abfd, including a
1019 terminal NULL pointer. If there are no symbols in the BFD,
1020 then return 0. If an error occurs, return -1. */
1022 static long
1023 vms_get_symtab_upper_bound (abfd)
1024 bfd *abfd;
1026 #if VMS_DEBUG
1027 vms_debug (1, "vms_get_symtab_upper_bound(%p), %d symbols\n", abfd, PRIV (gsd_sym_count));
1028 #endif
1029 return (PRIV (gsd_sym_count)+1) * sizeof (asymbol *);
1032 /* Copy symbols from hash table to symbol vector
1034 called from bfd_hash_traverse in vms_get_symtab
1035 init counter to 0 if entry == 0 */
1037 static boolean
1038 copy_symbols (entry, arg)
1039 struct bfd_hash_entry *entry;
1040 PTR arg;
1042 bfd *abfd = (bfd *) arg;
1044 if (entry == NULL) /* init counter */
1045 PRIV (symnum) = 0;
1046 else /* fill vector, inc counter */
1047 PRIV (symcache)[PRIV (symnum)++] = ((vms_symbol_entry *)entry)->symbol;
1049 return true;
1052 /* Read the symbols from the BFD abfd, and fills in the vector
1053 location with pointers to the symbols and a trailing NULL.
1055 return # of symbols read */
1057 static long
1058 vms_get_symtab (abfd, symbols)
1059 bfd *abfd;
1060 asymbol **symbols;
1062 #if VMS_DEBUG
1063 vms_debug (1, "vms_get_symtab(%p, <ret>)\n", abfd);
1064 #endif
1066 /* init counter */
1067 (void)copy_symbols((struct bfd_hash_entry *)0, abfd);
1069 /* traverse table and fill symbols vector */
1071 PRIV (symcache) = symbols;
1072 bfd_hash_traverse(PRIV (vms_symbol_table), copy_symbols, (PTR)abfd);
1074 symbols[PRIV (gsd_sym_count)] = NULL;
1076 return PRIV (gsd_sym_count);
1079 /* Print symbol to file according to how. how is one of
1080 bfd_print_symbol_name just print the name
1081 bfd_print_symbol_more print more (???)
1082 bfd_print_symbol_all print all we know, which is not much right now :-) */
1084 static void
1085 vms_print_symbol (abfd, file, symbol, how)
1086 bfd *abfd;
1087 PTR file;
1088 asymbol *symbol;
1089 bfd_print_symbol_type how;
1091 #if VMS_DEBUG
1092 vms_debug (1, "vms_print_symbol(%p, %p, %p, %d)\n", abfd, file, symbol, how);
1093 #endif
1095 switch (how)
1097 case bfd_print_symbol_name:
1098 case bfd_print_symbol_more:
1099 fprintf ((FILE *)file," %s", symbol->name);
1100 break;
1102 case bfd_print_symbol_all:
1104 const char *section_name = symbol->section->name;
1106 bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
1108 fprintf ((FILE *)file," %-8s %s", section_name, symbol->name);
1110 break;
1112 return;
1115 /* Return information about symbol in ret.
1117 fill type, value and name
1118 type:
1119 A absolute
1120 B bss segment symbol
1121 C common symbol
1122 D data segment symbol
1123 f filename
1124 t a static function symbol
1125 T text segment symbol
1126 U undefined
1127 - debug */
1129 static void
1130 vms_get_symbol_info (abfd, symbol, ret)
1131 bfd *abfd ATTRIBUTE_UNUSED;
1132 asymbol *symbol;
1133 symbol_info *ret;
1135 asection *sec;
1137 #if VMS_DEBUG
1138 vms_debug (1, "vms_get_symbol_info(%p, %p, %p)\n", abfd, symbol, ret);
1139 #endif
1141 sec = symbol->section;
1143 if (ret == 0)
1144 return;
1146 if (bfd_is_com_section (sec))
1147 ret->type = 'C';
1148 else if (bfd_is_abs_section (sec))
1149 ret->type = 'A';
1150 else if (bfd_is_und_section (sec))
1151 ret->type = 'U';
1152 else if (bfd_is_ind_section (sec))
1153 ret->type = 'I';
1154 else if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
1155 ret->type = 'T';
1156 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
1157 ret->type = 'D';
1158 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
1159 ret->type = 'B';
1160 else
1161 ret->type = '-';
1163 if (ret->type != 'U')
1164 ret->value = symbol->value + symbol->section->vma;
1165 else
1166 ret->value = 0;
1167 ret->name = symbol->name;
1169 return;
1172 /* Return true if the given symbol sym in the BFD abfd is
1173 a compiler generated local label, else return false. */
1175 static boolean
1176 vms_bfd_is_local_label_name (abfd, name)
1177 bfd *abfd ATTRIBUTE_UNUSED;
1178 const char *name;
1180 #if VMS_DEBUG
1181 vms_debug (1, "vms_bfd_is_local_label_name(%p, %s)\n", abfd, name);
1182 #endif
1183 return name[0] == '$';
1186 /* Get source line number for symbol */
1188 static alent *
1189 vms_get_lineno (abfd, symbol)
1190 bfd *abfd ATTRIBUTE_UNUSED;
1191 asymbol *symbol ATTRIBUTE_UNUSED;
1193 #if VMS_DEBUG
1194 vms_debug (1, "vms_get_lineno(%p, %p)\n", abfd, symbol);
1195 #endif
1196 return 0;
1199 /* Provided a BFD, a section and an offset into the section, calculate and
1200 return the name of the source file and the line nearest to the wanted
1201 location. */
1203 static boolean
1204 vms_find_nearest_line (abfd, section, symbols, offset, file, func, line)
1205 bfd *abfd ATTRIBUTE_UNUSED;
1206 asection *section ATTRIBUTE_UNUSED;
1207 asymbol **symbols ATTRIBUTE_UNUSED;
1208 bfd_vma offset ATTRIBUTE_UNUSED;
1209 const char **file ATTRIBUTE_UNUSED;
1210 const char **func ATTRIBUTE_UNUSED;
1211 unsigned int *line ATTRIBUTE_UNUSED;
1213 #if VMS_DEBUG
1214 vms_debug (1, "vms_find_nearest_line(%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1215 abfd, section->name, symbols, (long int)offset);
1216 #endif
1217 return false;
1220 /* Back-door to allow format-aware applications to create debug symbols
1221 while using BFD for everything else. Currently used by the assembler
1222 when creating COFF files. */
1224 static asymbol *
1225 vms_bfd_make_debug_symbol (abfd, ptr, size)
1226 bfd *abfd ATTRIBUTE_UNUSED;
1227 void *ptr ATTRIBUTE_UNUSED;
1228 unsigned long size ATTRIBUTE_UNUSED;
1230 #if VMS_DEBUG
1231 vms_debug (1, "vms_bfd_make_debug_symbol(%p, %p, %ld)\n", abfd, ptr, size);
1232 #endif
1233 return 0;
1236 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1237 symbols. The minisymbol_to_symbol function translates these into
1238 BFD asymbol structures. */
1240 static long
1241 vms_read_minisymbols (abfd, dynamic, minisymsp, sizep)
1242 bfd *abfd;
1243 boolean dynamic;
1244 PTR *minisymsp;
1245 unsigned int *sizep;
1247 #if VMS_DEBUG
1248 vms_debug (1, "vms_read_minisymbols(%p, %d, %p, %d)\n", abfd, dynamic, minisymsp, *sizep);
1249 #endif
1250 return _bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep);
1253 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1254 unmodified a.out symbol. The SYM argument is a structure returned
1255 by bfd_make_empty_symbol, which we fill in here. */
1257 static asymbol *
1258 vms_minisymbol_to_symbol (abfd, dynamic, minisym, sym)
1259 bfd *abfd;
1260 boolean dynamic;
1261 const PTR minisym;
1262 asymbol *sym;
1264 #if VMS_DEBUG
1265 vms_debug (1, "vms_minisymbol_to_symbol(%p, %d, %p, %p)\n", abfd, dynamic, minisym, sym);
1266 #endif
1267 return _bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym);
1270 /*-- Part 4.6, relocations --------------------------------------------------*/
1272 /* Return the number of bytes required to store the relocation information
1273 associated with section sect attached to bfd abfd.
1274 If an error occurs, return -1. */
1276 static long
1277 vms_get_reloc_upper_bound (abfd, section)
1278 bfd *abfd ATTRIBUTE_UNUSED;
1279 asection *section ATTRIBUTE_UNUSED;
1281 #if VMS_DEBUG
1282 vms_debug (1, "vms_get_reloc_upper_bound(%p, %s)\n", abfd, section->name);
1283 #endif
1284 return -1L;
1287 /* Call the back end associated with the open BFD abfd and translate the
1288 external form of the relocation information attached to sec into the
1289 internal canonical form. Place the table into memory at loc, which has
1290 been preallocated, usually by a call to bfd_get_reloc_upper_bound.
1291 Returns the number of relocs, or -1 on error. */
1293 static long
1294 vms_canonicalize_reloc (abfd, section, location, symbols)
1295 bfd *abfd ATTRIBUTE_UNUSED;
1296 asection *section ATTRIBUTE_UNUSED;
1297 arelent **location ATTRIBUTE_UNUSED;
1298 asymbol **symbols ATTRIBUTE_UNUSED;
1300 #if VMS_DEBUG
1301 vms_debug (1, "vms_canonicalize_reloc(%p, %s, <ret>, <ret>)\n", abfd, section->name);
1302 #endif
1303 return false;
1306 /*---------------------------------------------------------------------------*/
1307 /* this is just copied from ecoff-alpha, needs to be fixed probably */
1309 /* How to process the various reloc types. */
1311 static bfd_reloc_status_type
1312 reloc_nil (abfd, reloc, sym, data, sec, output_bfd, error_message)
1313 bfd *abfd ATTRIBUTE_UNUSED;
1314 arelent *reloc ATTRIBUTE_UNUSED;
1315 asymbol *sym ATTRIBUTE_UNUSED;
1316 PTR data ATTRIBUTE_UNUSED;
1317 asection *sec ATTRIBUTE_UNUSED;
1318 bfd *output_bfd ATTRIBUTE_UNUSED;
1319 char **error_message ATTRIBUTE_UNUSED;
1321 #if VMS_DEBUG
1322 vms_debug (1, "reloc_nil(abfd %p, output_bfd %p)\n", abfd, output_bfd);
1323 vms_debug (2, "In section %s, symbol %s\n",
1324 sec->name, sym->name);
1325 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1326 reloc->sym_ptr_ptr[0]->name,
1327 (unsigned long)reloc->address,
1328 (unsigned long)reloc->addend, reloc->howto->name);
1329 vms_debug (2, "data at %p\n", data);
1330 /* _bfd_hexdump (2, data, bfd_get_reloc_size(reloc->howto),0); */
1331 #endif
1333 return bfd_reloc_ok;
1336 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1337 from smaller values. Start with zero, widen, *then* decrement. */
1338 #define MINUS_ONE (((bfd_vma)0) - 1)
1340 static reloc_howto_type alpha_howto_table[] =
1342 HOWTO (ALPHA_R_IGNORE, /* type */
1343 0, /* rightshift */
1344 0, /* size (0 = byte, 1 = short, 2 = long) */
1345 8, /* bitsize */
1346 true, /* pc_relative */
1347 0, /* bitpos */
1348 complain_overflow_dont, /* complain_on_overflow */
1349 reloc_nil, /* special_function */
1350 "IGNORE", /* name */
1351 true, /* partial_inplace */
1352 0, /* src_mask */
1353 0, /* dst_mask */
1354 true), /* pcrel_offset */
1356 /* A 64 bit reference to a symbol. */
1357 HOWTO (ALPHA_R_REFQUAD, /* type */
1358 0, /* rightshift */
1359 4, /* size (0 = byte, 1 = short, 2 = long) */
1360 64, /* bitsize */
1361 false, /* pc_relative */
1362 0, /* bitpos */
1363 complain_overflow_bitfield, /* complain_on_overflow */
1364 reloc_nil, /* special_function */
1365 "REFQUAD", /* name */
1366 true, /* partial_inplace */
1367 MINUS_ONE, /* src_mask */
1368 MINUS_ONE, /* dst_mask */
1369 false), /* pcrel_offset */
1371 /* A 21 bit branch. The native assembler generates these for
1372 branches within the text segment, and also fills in the PC
1373 relative offset in the instruction. */
1374 HOWTO (ALPHA_R_BRADDR, /* type */
1375 2, /* rightshift */
1376 2, /* size (0 = byte, 1 = short, 2 = long) */
1377 21, /* bitsize */
1378 true, /* pc_relative */
1379 0, /* bitpos */
1380 complain_overflow_signed, /* complain_on_overflow */
1381 reloc_nil, /* special_function */
1382 "BRADDR", /* name */
1383 true, /* partial_inplace */
1384 0x1fffff, /* src_mask */
1385 0x1fffff, /* dst_mask */
1386 false), /* pcrel_offset */
1388 /* A hint for a jump to a register. */
1389 HOWTO (ALPHA_R_HINT, /* type */
1390 2, /* rightshift */
1391 1, /* size (0 = byte, 1 = short, 2 = long) */
1392 14, /* bitsize */
1393 true, /* pc_relative */
1394 0, /* bitpos */
1395 complain_overflow_dont, /* complain_on_overflow */
1396 reloc_nil, /* special_function */
1397 "HINT", /* name */
1398 true, /* partial_inplace */
1399 0x3fff, /* src_mask */
1400 0x3fff, /* dst_mask */
1401 false), /* pcrel_offset */
1403 /* 16 bit PC relative offset. */
1404 HOWTO (ALPHA_R_SREL16, /* type */
1405 0, /* rightshift */
1406 1, /* size (0 = byte, 1 = short, 2 = long) */
1407 16, /* bitsize */
1408 true, /* pc_relative */
1409 0, /* bitpos */
1410 complain_overflow_signed, /* complain_on_overflow */
1411 reloc_nil, /* special_function */
1412 "SREL16", /* name */
1413 true, /* partial_inplace */
1414 0xffff, /* src_mask */
1415 0xffff, /* dst_mask */
1416 false), /* pcrel_offset */
1418 /* 32 bit PC relative offset. */
1419 HOWTO (ALPHA_R_SREL32, /* type */
1420 0, /* rightshift */
1421 2, /* size (0 = byte, 1 = short, 2 = long) */
1422 32, /* bitsize */
1423 true, /* pc_relative */
1424 0, /* bitpos */
1425 complain_overflow_signed, /* complain_on_overflow */
1426 reloc_nil, /* special_function */
1427 "SREL32", /* name */
1428 true, /* partial_inplace */
1429 0xffffffff, /* src_mask */
1430 0xffffffff, /* dst_mask */
1431 false), /* pcrel_offset */
1433 /* A 64 bit PC relative offset. */
1434 HOWTO (ALPHA_R_SREL64, /* type */
1435 0, /* rightshift */
1436 4, /* size (0 = byte, 1 = short, 2 = long) */
1437 64, /* bitsize */
1438 true, /* pc_relative */
1439 0, /* bitpos */
1440 complain_overflow_signed, /* complain_on_overflow */
1441 reloc_nil, /* special_function */
1442 "SREL64", /* name */
1443 true, /* partial_inplace */
1444 MINUS_ONE, /* src_mask */
1445 MINUS_ONE, /* dst_mask */
1446 false), /* pcrel_offset */
1448 /* Push a value on the reloc evaluation stack. */
1449 HOWTO (ALPHA_R_OP_PUSH, /* type */
1450 0, /* rightshift */
1451 0, /* size (0 = byte, 1 = short, 2 = long) */
1452 0, /* bitsize */
1453 false, /* pc_relative */
1454 0, /* bitpos */
1455 complain_overflow_dont, /* complain_on_overflow */
1456 reloc_nil, /* special_function */
1457 "OP_PUSH", /* name */
1458 false, /* partial_inplace */
1459 0, /* src_mask */
1460 0, /* dst_mask */
1461 false), /* pcrel_offset */
1463 /* Store the value from the stack at the given address. Store it in
1464 a bitfield of size r_size starting at bit position r_offset. */
1465 HOWTO (ALPHA_R_OP_STORE, /* type */
1466 0, /* rightshift */
1467 4, /* size (0 = byte, 1 = short, 2 = long) */
1468 64, /* bitsize */
1469 false, /* pc_relative */
1470 0, /* bitpos */
1471 complain_overflow_dont, /* complain_on_overflow */
1472 reloc_nil, /* special_function */
1473 "OP_STORE", /* name */
1474 false, /* partial_inplace */
1475 0, /* src_mask */
1476 MINUS_ONE, /* dst_mask */
1477 false), /* pcrel_offset */
1479 /* Subtract the reloc address from the value on the top of the
1480 relocation stack. */
1481 HOWTO (ALPHA_R_OP_PSUB, /* type */
1482 0, /* rightshift */
1483 0, /* size (0 = byte, 1 = short, 2 = long) */
1484 0, /* bitsize */
1485 false, /* pc_relative */
1486 0, /* bitpos */
1487 complain_overflow_dont, /* complain_on_overflow */
1488 reloc_nil, /* special_function */
1489 "OP_PSUB", /* name */
1490 false, /* partial_inplace */
1491 0, /* src_mask */
1492 0, /* dst_mask */
1493 false), /* pcrel_offset */
1495 /* Shift the value on the top of the relocation stack right by the
1496 given value. */
1497 HOWTO (ALPHA_R_OP_PRSHIFT, /* type */
1498 0, /* rightshift */
1499 0, /* size (0 = byte, 1 = short, 2 = long) */
1500 0, /* bitsize */
1501 false, /* pc_relative */
1502 0, /* bitpos */
1503 complain_overflow_dont, /* complain_on_overflow */
1504 reloc_nil, /* special_function */
1505 "OP_PRSHIFT", /* name */
1506 false, /* partial_inplace */
1507 0, /* src_mask */
1508 0, /* dst_mask */
1509 false), /* pcrel_offset */
1511 /* Hack. Linkage is done by linker. */
1512 HOWTO (ALPHA_R_LINKAGE, /* type */
1513 0, /* rightshift */
1514 8, /* size (0 = byte, 1 = short, 2 = long) */
1515 256, /* bitsize */
1516 false, /* pc_relative */
1517 0, /* bitpos */
1518 complain_overflow_dont, /* complain_on_overflow */
1519 reloc_nil, /* special_function */
1520 "LINKAGE", /* name */
1521 false, /* partial_inplace */
1522 0, /* src_mask */
1523 0, /* dst_mask */
1524 false), /* pcrel_offset */
1526 /* A 32 bit reference to a symbol. */
1527 HOWTO (ALPHA_R_REFLONG, /* type */
1528 0, /* rightshift */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1530 32, /* bitsize */
1531 false, /* pc_relative */
1532 0, /* bitpos */
1533 complain_overflow_bitfield, /* complain_on_overflow */
1534 reloc_nil, /* special_function */
1535 "REFLONG", /* name */
1536 true, /* partial_inplace */
1537 0xffffffff, /* src_mask */
1538 0xffffffff, /* dst_mask */
1539 false), /* pcrel_offset */
1541 /* A 64 bit reference to a procedure, written as 32 bit value. */
1542 HOWTO (ALPHA_R_CODEADDR, /* type */
1543 0, /* rightshift */
1544 4, /* size (0 = byte, 1 = short, 2 = long) */
1545 64, /* bitsize */
1546 false, /* pc_relative */
1547 0, /* bitpos */
1548 complain_overflow_signed,/* complain_on_overflow */
1549 reloc_nil, /* special_function */
1550 "CODEADDR", /* name */
1551 false, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 false), /* pcrel_offset */
1558 /* Return a pointer to a howto structure which, when invoked, will perform
1559 the relocation code on data from the architecture noted. */
1561 static const struct reloc_howto_struct *
1562 vms_bfd_reloc_type_lookup (abfd, code)
1563 bfd *abfd ATTRIBUTE_UNUSED;
1564 bfd_reloc_code_real_type code;
1566 int alpha_type;
1568 #if VMS_DEBUG
1569 vms_debug (1, "vms_bfd_reloc_type_lookup(%p, %d)\t", abfd, code);
1570 #endif
1572 switch (code)
1574 case BFD_RELOC_16: alpha_type = ALPHA_R_SREL16; break;
1575 case BFD_RELOC_32: alpha_type = ALPHA_R_REFLONG; break;
1576 case BFD_RELOC_64: alpha_type = ALPHA_R_REFQUAD; break;
1577 case BFD_RELOC_CTOR: alpha_type = ALPHA_R_REFQUAD; break;
1578 case BFD_RELOC_23_PCREL_S2: alpha_type = ALPHA_R_BRADDR; break;
1579 case BFD_RELOC_ALPHA_HINT: alpha_type = ALPHA_R_HINT; break;
1580 case BFD_RELOC_16_PCREL: alpha_type = ALPHA_R_SREL16; break;
1581 case BFD_RELOC_32_PCREL: alpha_type = ALPHA_R_SREL32; break;
1582 case BFD_RELOC_64_PCREL: alpha_type = ALPHA_R_SREL64; break;
1583 case BFD_RELOC_ALPHA_LINKAGE: alpha_type = ALPHA_R_LINKAGE; break;
1584 case BFD_RELOC_ALPHA_CODEADDR: alpha_type = ALPHA_R_CODEADDR; break;
1585 default:
1586 (*_bfd_error_handler) ("reloc (%d) is *UNKNOWN*", code);
1587 return (const struct reloc_howto_struct *) NULL;
1589 #if VMS_DEBUG
1590 vms_debug (2, "reloc is %s\n", alpha_howto_table[alpha_type].name);
1591 #endif
1592 return &alpha_howto_table[alpha_type];
1595 /*-- Part 4.7, writing an object file ---------------------------------------*/
1597 /* Set the architecture and machine type in BFD abfd to arch and mach.
1598 Find the correct pointer to a structure and insert it into the arch_info
1599 pointer. */
1601 static boolean
1602 vms_set_arch_mach (abfd, arch, mach)
1603 bfd *abfd;
1604 enum bfd_architecture arch ATTRIBUTE_UNUSED;
1605 unsigned long mach ATTRIBUTE_UNUSED;
1607 #if VMS_DEBUG
1608 vms_debug (1, "vms_set_arch_mach(%p, %d, %ld)\n", abfd, arch, mach);
1609 #endif
1610 abfd->arch_info = bfd_scan_arch("alpha");
1612 return true;
1615 /* Sets the contents of the section section in BFD abfd to the data starting
1616 in memory at data. The data is written to the output section starting at
1617 offset offset for count bytes.
1619 Normally true is returned, else false. Possible error returns are:
1620 o bfd_error_no_contents - The output section does not have the
1621 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1622 o and some more too */
1624 static boolean
1625 vms_set_section_contents (abfd, section, location, offset, count)
1626 bfd *abfd;
1627 asection *section;
1628 PTR location;
1629 file_ptr offset;
1630 bfd_size_type count;
1632 #if VMS_DEBUG
1633 vms_debug (1, "vms_set_section_contents(%p, sec %s, loc %p, off %ld, count %d)\n",
1634 abfd, section->name, location, (long int)offset, (int)count);
1635 vms_debug (2, "secraw %d, seccooked %d\n", (int)section->_raw_size, (int)section->_cooked_size);
1636 #endif
1637 return _bfd_save_vms_section(abfd, section, location, offset, count);
1640 /*-- Part 4.8, linker -------------------------------------------------------*/
1642 /* Get the size of the section headers. */
1644 static int
1645 vms_sizeof_headers (abfd, reloc)
1646 bfd *abfd ATTRIBUTE_UNUSED;
1647 boolean reloc ATTRIBUTE_UNUSED;
1649 #if VMS_DEBUG
1650 vms_debug (1, "vms_sizeof_headers(%p, %s)\n", abfd, (reloc)?"True":"False");
1651 #endif
1652 return 0;
1655 /* Provides default handling of relocation effort for back ends
1656 which can't be bothered to do it efficiently. */
1658 static bfd_byte *
1659 vms_bfd_get_relocated_section_contents (abfd, link_info, link_order, data,
1660 relocateable, symbols)
1661 bfd *abfd ATTRIBUTE_UNUSED;
1662 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1663 struct bfd_link_order *link_order ATTRIBUTE_UNUSED;
1664 bfd_byte *data ATTRIBUTE_UNUSED;
1665 boolean relocateable ATTRIBUTE_UNUSED;
1666 asymbol **symbols ATTRIBUTE_UNUSED;
1668 #if VMS_DEBUG
1669 vms_debug (1, "vms_bfd_get_relocated_section_contents(%p, %p, %p, %p, %s, %p)\n",
1670 abfd, link_info, link_order, data, (relocateable)?"True":"False", symbols);
1671 #endif
1672 return 0;
1675 /* ??? */
1677 static boolean
1678 vms_bfd_relax_section (abfd, section, link_info, again)
1679 bfd *abfd ATTRIBUTE_UNUSED;
1680 asection *section ATTRIBUTE_UNUSED;
1681 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1682 boolean *again ATTRIBUTE_UNUSED;
1684 #if VMS_DEBUG
1685 vms_debug (1, "vms_bfd_relax_section(%p, %s, %p, <ret>)\n",
1686 abfd, section->name, link_info);
1687 #endif
1688 return true;
1691 static boolean
1692 vms_bfd_gc_sections (abfd, link_info)
1693 bfd *abfd ATTRIBUTE_UNUSED;
1694 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1696 #if VMS_DEBUG
1697 vms_debug (1, "vms_bfd_gc_sections(%p, %p)\n", abfd, link_info);
1698 #endif
1699 return true;
1702 static boolean
1703 vms_bfd_merge_sections (abfd, link_info)
1704 bfd *abfd ATTRIBUTE_UNUSED;
1705 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1707 #if VMS_DEBUG
1708 vms_debug (1, "vms_bfd_merge_sections(%p, %p)\n", abfd, link_info);
1709 #endif
1710 return true;
1713 /* Create a hash table for the linker. Different backends store
1714 different information in this table. */
1716 static struct bfd_link_hash_table *
1717 vms_bfd_link_hash_table_create (abfd)
1718 bfd *abfd ATTRIBUTE_UNUSED;
1720 #if VMS_DEBUG
1721 vms_debug (1, "vms_bfd_link_hash_table_create(%p)\n", abfd);
1722 #endif
1723 return 0;
1726 /* Free a linker hash table. */
1728 static void
1729 vms_bfd_link_hash_table_free (hash)
1730 struct bfd_link_hash_table *hash ATTRIBUTE_UNUSED;
1732 #if VMS_DEBUG
1733 vms_debug (1, "vms_bfd_link_hash_table_free(%p)\n", abfd);
1734 #endif
1737 /* Add symbols from this object file into the hash table. */
1739 static boolean
1740 vms_bfd_link_add_symbols (abfd, link_info)
1741 bfd *abfd ATTRIBUTE_UNUSED;
1742 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1744 #if VMS_DEBUG
1745 vms_debug (1, "vms_bfd_link_add_symbols(%p, %p)\n", abfd, link_info);
1746 #endif
1747 return false;
1750 /* Do a link based on the link_order structures attached to each
1751 section of the BFD. */
1753 static boolean
1754 vms_bfd_final_link (abfd, link_info)
1755 bfd *abfd ATTRIBUTE_UNUSED;
1756 struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
1758 #if VMS_DEBUG
1759 vms_debug (1, "vms_bfd_final_link(%p, %p)\n", abfd, link_info);
1760 #endif
1761 return true;
1764 /* Should this section be split up into smaller pieces during linking. */
1766 static boolean
1767 vms_bfd_link_split_section (abfd, section)
1768 bfd *abfd ATTRIBUTE_UNUSED;
1769 asection *section ATTRIBUTE_UNUSED;
1771 #if VMS_DEBUG
1772 vms_debug (1, "vms_bfd_link_split_section(%p, %s)\n", abfd, section->name);
1773 #endif
1774 return false;
1777 /*-- Part 4.9, dynamic symbols and relocations ------------------------------*/
1779 /* Get the amount of memory required to hold the dynamic symbols. */
1781 static long
1782 vms_get_dynamic_symtab_upper_bound (abfd)
1783 bfd *abfd ATTRIBUTE_UNUSED;
1785 #if VMS_DEBUG
1786 vms_debug (1, "vms_get_dynamic_symtab_upper_bound(%p)\n", abfd);
1787 #endif
1788 return 0;
1791 static boolean
1792 vms_bfd_print_private_bfd_data (abfd, file)
1793 bfd *abfd ATTRIBUTE_UNUSED;
1794 void *file ATTRIBUTE_UNUSED;
1796 #if VMS_DEBUG
1797 vms_debug (1, "vms_bfd_print_private_bfd_data(%p)\n", abfd);
1798 #endif
1799 return 0;
1802 /* Read in the dynamic symbols. */
1804 static long
1805 vms_canonicalize_dynamic_symtab (abfd, symbols)
1806 bfd *abfd ATTRIBUTE_UNUSED;
1807 asymbol **symbols ATTRIBUTE_UNUSED;
1809 #if VMS_DEBUG
1810 vms_debug (1, "vms_canonicalize_dynamic_symtab(%p, <ret>)\n", abfd);
1811 #endif
1812 return 0L;
1815 /* Get the amount of memory required to hold the dynamic relocs. */
1817 static long
1818 vms_get_dynamic_reloc_upper_bound (abfd)
1819 bfd *abfd ATTRIBUTE_UNUSED;
1821 #if VMS_DEBUG
1822 vms_debug (1, "vms_get_dynamic_reloc_upper_bound(%p)\n", abfd);
1823 #endif
1824 return 0L;
1827 /* Read in the dynamic relocs. */
1829 static long
1830 vms_canonicalize_dynamic_reloc (abfd, arel, symbols)
1831 bfd *abfd ATTRIBUTE_UNUSED;
1832 arelent **arel ATTRIBUTE_UNUSED;
1833 asymbol **symbols ATTRIBUTE_UNUSED;
1835 #if VMS_DEBUG
1836 vms_debug (1, "vms_canonicalize_dynamic_reloc(%p)\n", abfd);
1837 #endif
1838 return 0L;