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