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.
8 Written by Klaus K"ampf (kkaempf@rmi.de)
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.
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.
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. */
29 #define RME$C_SETRFM 0x00000001
40 static bfd_boolean
vms_initialize (bfd
*);
41 static bfd_boolean
fill_section_ptr (struct bfd_hash_entry
*, PTR
);
42 static bfd_boolean
vms_fixup_sections (bfd
*);
43 static bfd_boolean
copy_symbols (struct bfd_hash_entry
*, PTR
);
44 static bfd_reloc_status_type
reloc_nil (bfd
*, arelent
*, asymbol
*, PTR
,
45 asection
*, bfd
*, char **);
46 static int vms_slurp_module (bfd
*abfd
);
47 static int vms_slurp_image (bfd
*abfd
);
48 static const struct bfd_target
*vms_object_p (bfd
*abfd
);
49 static const struct bfd_target
*vms_archive_p (bfd
*abfd
);
50 static bfd_boolean
vms_mkobject (bfd
*abfd
);
51 static bfd_boolean
vms_write_object_contents (bfd
*abfd
);
52 static void free_reloc_stream (bfd
*abfd
, asection
*section
, void *data
);
53 static bfd_boolean
vms_close_and_cleanup (bfd
*abfd
);
54 static bfd_boolean
vms_bfd_free_cached_info (bfd
*abfd
);
55 static bfd_boolean
vms_new_section_hook (bfd
*abfd
, asection
*section
);
56 static bfd_boolean vms_get_section_contents
57 (bfd
*abfd
, asection
*section
, PTR x1
, file_ptr x2
, bfd_size_type x3
);
58 static bfd_boolean vms_get_section_contents_in_window
59 (bfd
*abfd
, asection
*section
, bfd_window
*w
, file_ptr offset
,
61 static bfd_boolean
vms_bfd_copy_private_bfd_data (bfd
*src
, bfd
*dest
);
62 static bfd_boolean vms_bfd_copy_private_section_data
63 (bfd
*srcbfd
, asection
*srcsec
, bfd
*dstbfd
, asection
*dstsec
);
64 static bfd_boolean vms_bfd_copy_private_symbol_data
65 (bfd
*ibfd
, asymbol
*isym
, bfd
*obfd
, asymbol
*osym
);
66 static bfd_boolean
vms_bfd_print_private_bfd_data (bfd
*abfd
, void *file
);
67 static char *vms_core_file_failing_command (bfd
*abfd
);
68 static int vms_core_file_failing_signal (bfd
*abfd
);
69 static bfd_boolean
vms_core_file_matches_executable_p (bfd
*abfd
, bfd
*bbfd
);
70 static bfd_boolean
vms_slurp_armap (bfd
*abfd
);
71 static bfd_boolean
vms_slurp_extended_name_table (bfd
*abfd
);
72 static bfd_boolean vms_construct_extended_name_table
73 (bfd
*abfd
, char **tabloc
, bfd_size_type
*tablen
, const char **name
);
74 static void vms_truncate_arname (bfd
*abfd
, const char *pathname
, char *arhdr
);
75 static bfd_boolean vms_write_armap
76 (bfd
*arch
, unsigned int elen
, struct orl
*map
, unsigned int cnt
, int idx
);
77 static PTR
vms_read_ar_hdr (bfd
*abfd
);
78 static bfd
*vms_get_elt_at_index (bfd
*abfd
, symindex index
);
79 static bfd
*vms_openr_next_archived_file (bfd
*arch
, bfd
*prev
);
80 static bfd_boolean
vms_update_armap_timestamp (bfd
*abfd
);
81 static int vms_generic_stat_arch_elt (bfd
*, struct stat
*);
82 static long vms_get_symtab_upper_bound (bfd
*abfd
);
83 static long vms_canonicalize_symtab (bfd
*abfd
, asymbol
**symbols
);
84 static void vms_print_symbol (bfd
*abfd
, PTR file
, asymbol
*symbol
,
85 bfd_print_symbol_type how
);
86 static void vms_get_symbol_info (bfd
*abfd
, asymbol
*symbol
, symbol_info
*ret
);
87 static bfd_boolean
vms_bfd_is_local_label_name (bfd
*abfd
, const char *);
88 static alent
*vms_get_lineno (bfd
*abfd
, asymbol
*symbol
);
89 static bfd_boolean vms_find_nearest_line
90 (bfd
*abfd
, asection
*section
, asymbol
**symbols
, bfd_vma offset
,
91 const char **file
, const char **func
, unsigned int *line
);
92 static asymbol
*vms_bfd_make_debug_symbol (bfd
*abfd
, void *ptr
,
94 static long vms_read_minisymbols (bfd
*abfd
, bfd_boolean dynamic
,
95 PTR
*minisymsp
, unsigned int *sizep
);
96 static asymbol
*vms_minisymbol_to_symbol
97 (bfd
*abfd
, bfd_boolean dynamic
, const PTR minisym
, asymbol
*sym
);
98 static void alloc_reloc_stream (bfd
*abfd
, asection
*section
,
100 static bfd_boolean
vms_slurp_reloc_table (bfd
*abfd
, asection
*section
,
102 static long vms_get_reloc_upper_bound (bfd
*abfd
, asection
*sect
);
103 static long vms_canonicalize_reloc (bfd
*abfd
, asection
*srcsec
,
104 arelent
**location
, asymbol
**symbols
);
105 static const struct reloc_howto_struct
*vms_bfd_reloc_type_lookup
106 (bfd
*abfd
, bfd_reloc_code_real_type code
);
107 static bfd_boolean vms_set_arch_mach
108 (bfd
*abfd
, enum bfd_architecture arch
, unsigned long mach
);
109 static bfd_boolean vms_set_section_contents
110 (bfd
*abfd
, asection
*section
, const PTR location
, file_ptr offset
,
111 bfd_size_type count
);
112 static int vms_sizeof_headers (bfd
*abfd
,
113 struct bfd_link_info
*info ATTRIBUTE_UNUSED
);
114 static bfd_byte
*vms_bfd_get_relocated_section_contents
115 (bfd
*abfd
, struct bfd_link_info
*link_info
,
116 struct bfd_link_order
*link_order
, bfd_byte
*data
,
117 bfd_boolean relocatable
, asymbol
**symbols
);
118 static bfd_boolean vms_bfd_relax_section
119 (bfd
*abfd
, asection
*section
, struct bfd_link_info
*link_info
,
121 static bfd_boolean vms_bfd_gc_sections
122 (bfd
*abfd
, struct bfd_link_info
*link_info
);
123 static bfd_boolean vms_bfd_merge_sections
124 (bfd
*abfd
, struct bfd_link_info
*link_info
);
125 static struct bfd_link_hash_table
*vms_bfd_link_hash_table_create (bfd
*abfd
);
126 static void vms_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash
);
127 static bfd_boolean vms_bfd_link_add_symbols
128 (bfd
*abfd
, struct bfd_link_info
*link_info
);
129 static bfd_boolean
vms_bfd_final_link (bfd
*abfd
,
130 struct bfd_link_info
*link_info
);
131 static bfd_boolean
vms_bfd_link_split_section (bfd
*abfd
, asection
*section
);
132 static long vms_get_dynamic_symtab_upper_bound (bfd
*abfd
);
133 static long vms_canonicalize_dynamic_symtab (bfd
*abfd
, asymbol
**symbols
);
134 static long vms_get_dynamic_reloc_upper_bound (bfd
*abfd
);
135 static long vms_canonicalize_dynamic_reloc
136 (bfd
*abfd
, arelent
**arel
, asymbol
**symbols
);
137 static bfd_boolean
vms_bfd_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
);
138 static bfd_boolean
vms_bfd_set_private_flags (bfd
*abfd
, flagword flags
);
140 #define vms_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
141 #define vms_make_empty_symbol _bfd_generic_make_empty_symbol
142 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
143 #define vms_bfd_copy_link_hash_symbol_type \
144 _bfd_generic_copy_link_hash_symbol_type
145 #define vms_bfd_is_group_section bfd_generic_is_group_section
146 #define vms_bfd_discard_group bfd_generic_discard_group
147 #define vms_section_already_linked _bfd_generic_section_already_linked
148 #define vms_bfd_define_common_symbol bfd_generic_define_common_symbol
149 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
150 #define vms_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
154 /* Cause debug info to be emitted for the structure. */
155 struct vms_private_data_struct _vms_private_data_struct_dummy
;
156 struct vms_section_data_struct _vms_section_data_struct_dummy
;
159 extern const bfd_target vms_vax_vec
;
160 extern const bfd_target vms_alpha_vec
;
162 /* Initialize private data */
164 vms_initialize (bfd
* abfd
)
168 bfd_set_start_address (abfd
, (bfd_vma
) -1);
170 amt
= sizeof (struct vms_private_data_struct
);
171 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
172 if (abfd
->tdata
.any
== NULL
)
175 if (bfd_get_flavour (abfd
) == bfd_target_ovax_flavour
)
176 PRIV (is_vax
) = TRUE
;
178 PRIV (file_format
) = FF_UNKNOWN
;
180 amt
= sizeof (struct stack_struct
) * STACKSIZE
;
181 PRIV (stack
) = bfd_alloc (abfd
, amt
);
182 if (PRIV (stack
) == NULL
)
185 amt
= sizeof (struct bfd_hash_table
);
186 PRIV (vms_symbol_table
) = bfd_alloc (abfd
, amt
);
187 if (PRIV (vms_symbol_table
) == NULL
)
190 if (!bfd_hash_table_init (PRIV (vms_symbol_table
), _bfd_vms_hash_newfunc
,
191 sizeof (vms_symbol_entry
)))
194 amt
= MAX_OUTREC_SIZE
;
195 PRIV (output_buf
) = bfd_alloc (abfd
, amt
);
196 if (PRIV (output_buf
) == NULL
)
199 PRIV (length_pos
) = 2;
204 bfd_hash_table_free (PRIV (vms_symbol_table
));
206 bfd_release (abfd
, abfd
->tdata
.any
);
207 abfd
->tdata
.any
= NULL
;
213 unsigned int section_count
;
217 /* Fill symbol->section with section pointer.
219 symbol->section is filled with the section index for defined symbols
220 during reading the GSD/EGSD section. But we need the pointer to the
223 It has the correct value for referenced (undefined section) symbols.
225 Called from bfd_hash_traverse in vms_fixup_sections. */
228 fill_section_ptr (struct bfd_hash_entry
*entry
, void *sections
)
230 asymbol
*sym
= ((vms_symbol_entry
*)entry
)->symbol
;
231 struct pair
*data
= (struct pair
*)sections
;
232 unsigned long sec
= (unsigned long)sym
->section
;
235 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym
, sec
);
238 if (sec
< data
->section_count
)
240 sym
->section
= data
->sections
[sec
];
242 if (strcmp (sym
->name
, sym
->section
->name
) == 0)
243 sym
->flags
|= BSF_SECTION_SYM
;
245 else if (sec
== (unsigned long)-1)
246 sym
->section
= &bfd_und_section
;
251 /* Fixup section pointers in symbols. */
253 vms_fixup_sections (bfd
* abfd
)
257 if (PRIV (fixup_done
))
260 data
.section_count
= PRIV (section_count
);
261 data
.sections
= PRIV (sections
);
262 bfd_hash_traverse (PRIV (vms_symbol_table
), fill_section_ptr
, &data
);
264 PRIV (fixup_done
) = TRUE
;
268 /* Slurp an ordered set of VMS object records. */
270 _bfd_vms_slurp_object_records (bfd
* abfd
)
272 int err
, new_type
, type
= -1;
277 vms_debug (7, "reading at %08lx\n", bfd_tell (abfd
));
279 new_type
= _bfd_vms_get_object_record (abfd
);
283 vms_debug (2, "next_record failed\n");
288 if (type
== EOBJ_S_C_EGSD
&& new_type
!= EOBJ_S_C_EGSD
)
290 if (! vms_fixup_sections (abfd
))
293 vms_debug (2, "vms_fixup_sections failed\n");
305 err
= _bfd_vms_slurp_hdr (abfd
, type
);
310 err
= _bfd_vms_slurp_eom (abfd
, type
);
314 err
= _bfd_vms_slurp_gsd (abfd
, type
);
318 err
= _bfd_vms_slurp_tir (abfd
, type
);
322 err
= _bfd_vms_slurp_dbg (abfd
, type
);
323 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
327 err
= _bfd_vms_slurp_tbt (abfd
, type
);
328 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
331 err
= _bfd_vms_slurp_lnk (abfd
, type
);
339 vms_debug (2, "slurp type %d failed with %d\n", type
, err
);
344 while (type
!= EOBJ_S_C_EEOM
&& type
!= OBJ_S_C_EOM
&& type
!= OBJ_S_C_EOMW
);
349 /* Slurp a VMS module and return an error status. */
352 vms_slurp_module (bfd
*abfd
)
357 type
= PRIV (vms_rec
)[0];
359 type
= bfd_getl16 (PRIV (vms_rec
));
361 err
= _bfd_vms_slurp_hdr (abfd
, type
);
364 bfd_set_error (bfd_error_wrong_format
);
368 return _bfd_vms_slurp_object_records (abfd
);
371 /* Slurp a VMS image and return an error status. */
374 vms_slurp_image (bfd
*abfd
)
376 unsigned int isd_offset
, ihs_offset
;
379 err
= _bfd_vms_slurp_ihd (abfd
, &isd_offset
, &ihs_offset
);
382 bfd_set_error (bfd_error_wrong_format
);
386 err
= _bfd_vms_slurp_isd (abfd
, isd_offset
);
389 bfd_set_error (bfd_error_wrong_format
);
393 return _bfd_vms_slurp_ihs (abfd
, ihs_offset
);
396 /* Check the format for a file being read.
397 Return a (bfd_target *) if it's an object file or zero if not. */
399 static const struct bfd_target
*
400 vms_object_p (bfd
*abfd
)
402 const struct bfd_target
*target_vector
;
403 const bfd_arch_info_type
*arch
;
404 PTR tdata_save
= abfd
->tdata
.any
;
405 bfd_vma saddr_save
= bfd_get_start_address (abfd
);
409 vms_debug (1, "vms_object_p(%p)\n", abfd
);
412 if (!vms_initialize (abfd
))
415 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
))
416 goto err_wrong_format
;
418 switch (_bfd_vms_get_first_record (abfd
))
426 err
= vms_slurp_module (abfd
);
430 err
= vms_slurp_image (abfd
);
435 goto err_wrong_format
;
439 if (! vms_fixup_sections (abfd
))
442 vms_debug (2, "vms_fixup_sections failed\n");
444 goto err_wrong_format
;
447 target_vector
= &vms_vax_vec
;
448 arch
= bfd_scan_arch ("vax");
451 vms_debug (2, "arch is vax\n");
456 /* Set arch_info to alpha. */
457 target_vector
= &vms_alpha_vec
;
458 arch
= bfd_scan_arch ("alpha");
460 vms_debug (2, "arch is alpha\n");
464 abfd
->arch_info
= arch
;
465 return target_vector
;
468 bfd_set_error (bfd_error_wrong_format
);
471 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
472 bfd_release (abfd
, abfd
->tdata
.any
);
473 abfd
->tdata
.any
= tdata_save
;
474 bfd_set_start_address (abfd
, saddr_save
);
478 /* Check the format for a file being read.
479 Return a (bfd_target *) if it's an archive file or zero. */
481 static const struct bfd_target
*
482 vms_archive_p (bfd
* abfd ATTRIBUTE_UNUSED
)
485 vms_debug (1, "vms_archive_p (%p)\n", abfd
);
491 /* Set the format of a file being written. */
494 vms_mkobject (bfd
* abfd
)
496 const bfd_arch_info_type
*arch
;
499 vms_debug (1, "vms_mkobject (%p)\n", abfd
);
502 if (!vms_initialize (abfd
))
506 arch
= bfd_scan_arch ("vax");
508 arch
= bfd_scan_arch ("alpha");
512 bfd_set_error(bfd_error_wrong_format
);
516 abfd
->arch_info
= arch
;
520 /* Write cached information into a file being written, at bfd_close. */
523 vms_write_object_contents (bfd
* abfd
)
526 vms_debug (1, "vms_write_object_contents (%p)\n", abfd
);
529 if (abfd
->section_count
> 0) /* we have sections */
533 if (_bfd_vms_write_hdr (abfd
, OBJ_S_C_HDR
) != 0)
535 if (_bfd_vms_write_gsd (abfd
, OBJ_S_C_GSD
) != 0)
537 if (_bfd_vms_write_tir (abfd
, OBJ_S_C_TIR
) != 0)
539 if (_bfd_vms_write_tbt (abfd
, OBJ_S_C_TBT
) != 0)
541 if (_bfd_vms_write_dbg (abfd
, OBJ_S_C_DBG
) != 0)
543 if (abfd
->section_count
> 255)
545 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOMW
) != 0)
550 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOM
) != 0)
556 if (_bfd_vms_write_hdr (abfd
, EOBJ_S_C_EMH
) != 0)
558 if (_bfd_vms_write_gsd (abfd
, EOBJ_S_C_EGSD
) != 0)
560 if (_bfd_vms_write_tir (abfd
, EOBJ_S_C_ETIR
) != 0)
562 if (_bfd_vms_write_tbt (abfd
, EOBJ_S_C_ETBT
) != 0)
564 if (_bfd_vms_write_dbg (abfd
, EOBJ_S_C_EDBG
) != 0)
566 if (_bfd_vms_write_eom (abfd
, EOBJ_S_C_EEOM
) != 0)
575 /* Free the reloc buffer for the specified section. */
578 free_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
579 void *data ATTRIBUTE_UNUSED
)
581 if (vms_section_data (section
)->reloc_stream
)
582 free (vms_section_data (section
)->reloc_stream
);
586 /* Convert the file to variable record length format. This is done
587 using undocumented system call sys$modify().
591 vms_convert_to_var (char *vms_filename
)
593 struct FAB fab
= cc$rms_fab
;
595 fab
.fab$l_fna
= vms_filename
;
596 fab
.fab$b_fns
= strlen (vms_filename
);
597 fab
.fab$b_fac
= FAB$M_PUT
;
598 fab
.fab$l_fop
= FAB$M_ESC
;
599 fab
.fab$l_ctx
= RME$C_SETRFM
;
603 fab
.fab$b_rfm
= FAB$C_VAR
;
610 vms_convert_to_var_1 (char *filename
, int type
)
612 if (type
!= DECC$K_FILE
)
614 vms_convert_to_var (filename
);
618 /* Convert the file to variable record length format. This is done
619 using undocumented system call sys$modify().
620 Unix filename version. */
623 vms_convert_to_var_unix_filename (const char *unix_filename
)
625 if (decc$
to_vms (unix_filename
, &vms_convert_to_var_1
, 0, 1) != 1)
631 /* Called when the BFD is being closed to do any necessary cleanup. */
634 vms_close_and_cleanup (bfd
* abfd
)
637 vms_debug (1, "vms_close_and_cleanup (%p)\n", abfd
);
639 if (abfd
== NULL
|| abfd
->tdata
.any
== NULL
)
642 if (PRIV (vms_buf
) != NULL
)
643 free (PRIV (vms_buf
));
645 if (PRIV (sections
) != NULL
)
646 free (PRIV (sections
));
648 if (PRIV (vms_symbol_table
))
649 bfd_hash_table_free (PRIV (vms_symbol_table
));
651 bfd_map_over_sections (abfd
, free_reloc_stream
, NULL
);
653 bfd_release (abfd
, abfd
->tdata
.any
);
654 abfd
->tdata
.any
= NULL
;
657 if (abfd
->direction
== write_direction
)
659 /* Last step on VMS is to convert the file to variable record length
661 if (bfd_cache_close (abfd
) != TRUE
)
663 if (vms_convert_to_var_unix_filename (abfd
->filename
) != TRUE
)
671 /* Ask the BFD to free all cached information. */
674 vms_bfd_free_cached_info (bfd
* abfd ATTRIBUTE_UNUSED
)
677 vms_debug (1, "vms_bfd_free_cached_info (%p)\n", abfd
);
682 /* Called when a new section is created. */
685 vms_new_section_hook (bfd
* abfd
, asection
*section
)
689 /* Count hasn't been incremented yet. */
690 unsigned int section_count
= abfd
->section_count
+ 1;
693 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
694 abfd
, section
->index
, section
->name
, section_count
);
697 bfd_set_section_alignment (abfd
, section
, 0);
699 if (section_count
> PRIV (section_count
))
701 bfd_size_type amt
= section_count
;
702 amt
*= sizeof (asection
*);
703 PRIV (sections
) = bfd_realloc_or_free (PRIV (sections
), amt
);
704 if (PRIV (sections
) == NULL
)
706 PRIV (section_count
) = section_count
;
710 vms_debug (6, "section_count: %d\n", PRIV (section_count
));
713 PRIV (sections
)[section
->index
] = section
;
716 vms_debug (7, "%d: %s\n", section
->index
, section
->name
);
719 amt
= sizeof (struct vms_section_data_struct
);
720 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
721 if (section
->used_by_bfd
== NULL
)
724 return _bfd_generic_new_section_hook (abfd
, section
);
727 /* Read the contents of a section.
728 buf points to a buffer of buf_size bytes to be filled with
729 section data (starting at offset into section) */
732 vms_get_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
733 asection
*section ATTRIBUTE_UNUSED
,
734 void * buf ATTRIBUTE_UNUSED
,
735 file_ptr offset ATTRIBUTE_UNUSED
,
736 bfd_size_type buf_size ATTRIBUTE_UNUSED
)
738 bfd_size_type size
= section
->size
;
741 vms_debug (1, "vms_get_section_contents (%p, %s, %p, off %ld, size %d)\n",
742 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
745 if (section
->contents
)
748 section
->contents
= (unsigned char *) bfd_malloc (size
);
750 if (section
->contents
== NULL
)
752 bfd_set_error (bfd_error_no_memory
);
756 if (bfd_seek (abfd
, section
->filepos
, SEEK_SET
))
758 bfd_set_error (bfd_error_file_truncated
);
762 if (bfd_bread (section
->contents
, size
, abfd
) != size
)
764 bfd_set_error (bfd_error_file_truncated
);
768 section
->flags
|= SEC_IN_MEMORY
;
771 memcpy (buf
, section
->contents
+ offset
, (size_t) buf_size
);
776 /* Read the contents of a section.
777 buf points to a buffer of buf_size bytes to be filled with
778 section data (starting at offset into section). */
781 vms_get_section_contents_in_window (bfd
* abfd ATTRIBUTE_UNUSED
,
782 asection
*section ATTRIBUTE_UNUSED
,
783 bfd_window
*w ATTRIBUTE_UNUSED
,
784 file_ptr offset ATTRIBUTE_UNUSED
,
785 bfd_size_type count ATTRIBUTE_UNUSED
)
788 vms_debug (1, "vms_get_section_contents_in_window (%p, %s, %p, off %ld, count %d)\n",
789 abfd
, section
->name
, w
, offset
, (int)count
);
792 /* Shouldn't be called, since all sections are IN_MEMORY. */
796 /* Part 4.2, copy private data. */
798 /* Called to copy BFD general private data from one object file
802 vms_bfd_copy_private_bfd_data (bfd
*src ATTRIBUTE_UNUSED
,
803 bfd
*dest ATTRIBUTE_UNUSED
)
806 vms_debug (1, "vms_bfd_copy_private_bfd_data (%p, %p)\n", src
, dest
);
811 /* Merge private BFD information from the BFD @var{ibfd} to the
812 the output file BFD @var{obfd} when linking. Return <<TRUE>>
813 on success, <<FALSE>> on error. Possible error returns are:
815 o <<bfd_error_no_memory>> -
816 Not enough memory exists to create private data for @var{obfd}. */
819 vms_bfd_merge_private_bfd_data (bfd
* ibfd ATTRIBUTE_UNUSED
,
820 bfd
* obfd ATTRIBUTE_UNUSED
)
823 vms_debug (1,"vms_bfd_merge_private_bfd_data (%p, %p)\n", ibfd
, obfd
);
828 /* Set private BFD flag information in the BFD @var{abfd}.
829 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
832 o <<bfd_error_no_memory>> -
833 Not enough memory exists to create private data for @var{obfd}. */
836 vms_bfd_set_private_flags (bfd
* abfd ATTRIBUTE_UNUSED
,
837 flagword flags ATTRIBUTE_UNUSED
)
840 vms_debug (1,"vms_bfd_set_private_flags (%p, %lx)\n", abfd
, (long)flags
);
845 /* Called to copy BFD private section data from one object file
849 vms_bfd_copy_private_section_data (bfd
*srcbfd ATTRIBUTE_UNUSED
,
850 asection
*srcsec ATTRIBUTE_UNUSED
,
851 bfd
*dstbfd ATTRIBUTE_UNUSED
,
852 asection
*dstsec ATTRIBUTE_UNUSED
)
855 vms_debug (1, "vms_bfd_copy_private_section_data (%p, %s, %p, %s)\n",
856 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
861 /* Called to copy BFD private symbol data from one object file
865 vms_bfd_copy_private_symbol_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
866 asymbol
*isym ATTRIBUTE_UNUSED
,
867 bfd
*obfd ATTRIBUTE_UNUSED
,
868 asymbol
*osym ATTRIBUTE_UNUSED
)
871 vms_debug (1, "vms_bfd_copy_private_symbol_data (%p, %s, %p, %s)\n",
872 ibfd
, isym
->name
, obfd
, osym
->name
);
877 /* Part 4.3, core file. */
879 /* Return a read-only string explaining which program was running
880 when it failed and produced the core file abfd. */
883 vms_core_file_failing_command (bfd
* abfd ATTRIBUTE_UNUSED
)
886 vms_debug (1, "vms_core_file_failing_command (%p)\n", abfd
);
891 /* Returns the signal number which caused the core dump which
892 generated the file the BFD abfd is attached to. */
895 vms_core_file_failing_signal (bfd
* abfd ATTRIBUTE_UNUSED
)
898 vms_debug (1, "vms_core_file_failing_signal (%p)\n", abfd
);
903 /* Return TRUE if the core file attached to core_bfd was generated
904 by a run of the executable file attached to exec_bfd, FALSE otherwise. */
907 vms_core_file_matches_executable_p (bfd
* abfd ATTRIBUTE_UNUSED
,
908 bfd
*bbfd ATTRIBUTE_UNUSED
)
911 vms_debug (1, "vms_core_file_matches_executable_p (%p, %p)\n", abfd
, bbfd
);
916 /* Part 4.4, archive. */
918 /* ??? do something with an archive map.
919 Return FALSE on error, TRUE otherwise. */
922 vms_slurp_armap (bfd
* abfd ATTRIBUTE_UNUSED
)
925 vms_debug (1, "vms_slurp_armap (%p)\n", abfd
);
930 /* ??? do something with an extended name table.
931 Return FALSE on error, TRUE otherwise. */
934 vms_slurp_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
)
937 vms_debug (1, "vms_slurp_extended_name_table (%p)\n", abfd
);
942 /* ??? do something with an extended name table.
943 Return FALSE on error, TRUE otherwise. */
946 vms_construct_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
,
947 char **tabloc ATTRIBUTE_UNUSED
,
948 bfd_size_type
*tablen ATTRIBUTE_UNUSED
,
949 const char **name ATTRIBUTE_UNUSED
)
952 vms_debug (1, "vms_construct_extended_name_table (%p)\n", abfd
);
957 /* Truncate the name of an archive to match system-dependent restrictions. */
960 vms_truncate_arname (bfd
* abfd ATTRIBUTE_UNUSED
,
961 const char *pathname ATTRIBUTE_UNUSED
,
962 char *arhdr ATTRIBUTE_UNUSED
)
965 vms_debug (1, "vms_truncate_arname (%p, %s, %s)\n", abfd
, pathname
, arhdr
);
969 /* ??? write archive map. */
972 vms_write_armap (bfd
*arch ATTRIBUTE_UNUSED
,
973 unsigned int elength ATTRIBUTE_UNUSED
,
974 struct orl
*map ATTRIBUTE_UNUSED
,
975 unsigned int orl_count ATTRIBUTE_UNUSED
,
976 int stridx ATTRIBUTE_UNUSED
)
979 vms_debug (1, "vms_write_armap (%p, %d, %p, %d %d)\n",
980 arch
, elength
, map
, orl_count
, stridx
);
985 /* Read archive header ??? */
988 vms_read_ar_hdr (bfd
* abfd ATTRIBUTE_UNUSED
)
991 vms_debug (1, "vms_read_ar_hdr (%p)\n", abfd
);
996 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
997 an input BFD on the first contained element and returns that.
998 Subsequent calls should pass the archive and the previous return value
999 to return a created BFD to the next contained element.
1000 NULL is returned when there are no more. */
1003 vms_openr_next_archived_file (bfd
*arch ATTRIBUTE_UNUSED
,
1004 bfd
*prev ATTRIBUTE_UNUSED
)
1007 vms_debug (1, "vms_openr_next_archived_file (%p, %p)\n", arch
, prev
);
1012 /* Return the BFD which is referenced by the symbol in ABFD indexed by
1013 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
1016 vms_get_elt_at_index (bfd
* abfd
, symindex index
)
1019 vms_debug (1, "vms_get_elt_at_index (%p, %p)\n", abfd
, index
);
1021 return _bfd_generic_get_elt_at_index (abfd
, index
);
1025 -> bfd_generic_stat_arch_elt. */
1028 vms_generic_stat_arch_elt (bfd
* abfd
, struct stat
*st
)
1031 vms_debug (1, "vms_generic_stat_arch_elt (%p, %p)\n", abfd
, st
);
1033 return bfd_generic_stat_arch_elt (abfd
, st
);
1036 /* This is a new function in bfd 2.5. */
1039 vms_update_armap_timestamp (bfd
* abfd ATTRIBUTE_UNUSED
)
1042 vms_debug (1, "vms_update_armap_timestamp (%p)\n", abfd
);
1047 /* Part 4.5, symbols. */
1049 /* Return the number of bytes required to store a vector of pointers
1050 to asymbols for all the symbols in the BFD abfd, including a
1051 terminal NULL pointer. If there are no symbols in the BFD,
1052 then return 0. If an error occurs, return -1. */
1055 vms_get_symtab_upper_bound (bfd
* abfd
)
1058 vms_debug (1, "vms_get_symtab_upper_bound (%p), %d symbols\n", abfd
, PRIV (gsd_sym_count
));
1060 return (PRIV (gsd_sym_count
) + 1) * sizeof (asymbol
*);
1063 /* Copy symbols from hash table to symbol vector
1065 called from bfd_hash_traverse in vms_canonicalize_symtab
1066 init counter to 0 if entry == 0. */
1069 copy_symbols (struct bfd_hash_entry
*entry
, void * arg
)
1071 bfd
* abfd
= (bfd
*) arg
;
1073 if (entry
== NULL
) /* Init counter. */
1075 else /* Fill vector, inc counter. */
1076 PRIV (symcache
)[PRIV (symnum
)++] = ((vms_symbol_entry
*)entry
)->symbol
;
1081 /* Read the symbols from the BFD abfd, and fills in the vector
1082 location with pointers to the symbols and a trailing NULL.
1084 Return number of symbols read. */
1087 vms_canonicalize_symtab (bfd
* abfd
, asymbol
**symbols
)
1090 vms_debug (1, "vms_canonicalize_symtab (%p, <ret>)\n", abfd
);
1094 copy_symbols (NULL
, abfd
);
1096 /* Traverse table and fill symbols vector. */
1097 PRIV (symcache
) = symbols
;
1098 bfd_hash_traverse (PRIV (vms_symbol_table
), copy_symbols
, abfd
);
1100 symbols
[PRIV (gsd_sym_count
)] = NULL
;
1102 return PRIV (gsd_sym_count
);
1105 /* Print symbol to file according to how. how is one of
1106 bfd_print_symbol_name just print the name
1107 bfd_print_symbol_more print more (???)
1108 bfd_print_symbol_all print all we know, which is not much right now :-). */
1111 vms_print_symbol (bfd
* abfd
,
1114 bfd_print_symbol_type how
)
1117 vms_debug (1, "vms_print_symbol (%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1122 case bfd_print_symbol_name
:
1123 case bfd_print_symbol_more
:
1124 fprintf ((FILE *)file
," %s", symbol
->name
);
1127 case bfd_print_symbol_all
:
1129 const char *section_name
= symbol
->section
->name
;
1131 bfd_print_symbol_vandf (abfd
, file
, symbol
);
1133 fprintf ((FILE *) file
," %-8s %s", section_name
, symbol
->name
);
1139 /* Return information about symbol in ret.
1141 fill type, value and name
1144 B bss segment symbol
1146 D data segment symbol
1148 t a static function symbol
1149 T text segment symbol
1154 vms_get_symbol_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1161 vms_debug (1, "vms_get_symbol_info (%p, %p, %p)\n", abfd
, symbol
, ret
);
1164 sec
= symbol
->section
;
1171 else if (bfd_is_com_section (sec
))
1173 else if (bfd_is_abs_section (sec
))
1175 else if (bfd_is_und_section (sec
))
1177 else if (bfd_is_ind_section (sec
))
1179 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1181 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1183 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1188 if (ret
->type
!= 'U')
1189 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1192 ret
->name
= symbol
->name
;
1195 /* Return TRUE if the given symbol sym in the BFD abfd is
1196 a compiler generated local label, else return FALSE. */
1199 vms_bfd_is_local_label_name (bfd
* abfd ATTRIBUTE_UNUSED
,
1203 vms_debug (1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd
, name
);
1205 return name
[0] == '$';
1208 /* Get source line number for symbol. */
1211 vms_get_lineno (bfd
* abfd ATTRIBUTE_UNUSED
,
1212 asymbol
*symbol ATTRIBUTE_UNUSED
)
1215 vms_debug (1, "vms_get_lineno (%p, %p)\n", abfd
, symbol
);
1220 /* Provided a BFD, a section and an offset into the section, calculate and
1221 return the name of the source file and the line nearest to the wanted
1225 vms_find_nearest_line (bfd
* abfd ATTRIBUTE_UNUSED
,
1226 asection
*section ATTRIBUTE_UNUSED
,
1227 asymbol
**symbols ATTRIBUTE_UNUSED
,
1228 bfd_vma offset ATTRIBUTE_UNUSED
,
1229 const char **file ATTRIBUTE_UNUSED
,
1230 const char **func ATTRIBUTE_UNUSED
,
1231 unsigned int *line ATTRIBUTE_UNUSED
)
1234 vms_debug (1, "vms_find_nearest_line (%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1235 abfd
, section
->name
, symbols
, (long int)offset
);
1237 return _bfd_vms_find_nearest_dst_line (abfd
, section
, symbols
, offset
, file
, func
, line
);
1241 vms_find_inliner_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1242 const char **file ATTRIBUTE_UNUSED
,
1243 const char **func ATTRIBUTE_UNUSED
,
1244 unsigned int *line ATTRIBUTE_UNUSED
)
1247 vms_debug (1, "vms_find_inliner_info (%p, <ret>, <ret>, <ret>)\n",
1253 /* Back-door to allow format-aware applications to create debug symbols
1254 while using BFD for everything else. Currently used by the assembler
1255 when creating COFF files. */
1258 vms_bfd_make_debug_symbol (bfd
* abfd ATTRIBUTE_UNUSED
,
1259 void *ptr ATTRIBUTE_UNUSED
,
1260 unsigned long size ATTRIBUTE_UNUSED
)
1263 vms_debug (1, "vms_bfd_make_debug_symbol (%p, %p, %ld)\n", abfd
, ptr
, size
);
1268 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1269 symbols. The minisymbol_to_symbol function translates these into
1270 BFD asymbol structures. */
1273 vms_read_minisymbols (bfd
* abfd
,
1274 bfd_boolean dynamic
,
1276 unsigned int *sizep
)
1279 vms_debug (1, "vms_read_minisymbols (%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1281 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1284 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1285 unmodified a.out symbol. The SYM argument is a structure returned
1286 by bfd_make_empty_symbol, which we fill in here. */
1289 vms_minisymbol_to_symbol (bfd
* abfd
,
1290 bfd_boolean dynamic
,
1291 const void * minisym
,
1295 vms_debug (1, "vms_minisymbol_to_symbol (%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1297 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1300 /* Part 4.6, relocations. */
1302 /* Allocate the reloc buffer for the specified section. */
1305 alloc_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
1310 /* If there were no relocations, there is nothing to do. */
1311 if (section
->reloc_count
== 0)
1314 ptr
= bfd_malloc (vms_section_data (section
)->reloc_size
);
1317 *(bfd_boolean
*)alloc_error
= TRUE
;
1321 vms_section_data (section
)->reloc_stream
= ptr
;
1324 /* Read in the relocs for the specified section and internalize them.
1326 The implementation is loosely based on the SOM code and made up
1327 of 3 distinct phases:
1329 1. When the VMS object is opened and parsed, the number and the size
1330 of the relocations are computed for all sections. This makes it
1331 possible to know upfront both which sections have no relocs and
1332 the size of the reloc buffers for the other sections, at virtually
1333 no cost for consumers that don't care about relocs at all.
1335 2. When vms_slurp_reloc_table is invoked for the first time on a section
1336 with relocs, the object is traversed and all the reloc information
1337 is saved in per-section reloc buffers. It would be very inefficient
1338 to scan the whole file on each invocation, so we slurp for all the
1341 3. On subsequent invocations of vms_slurp_reloc_table, the relocs for the
1342 specified section are fetched from the buffer, decoded and internalized.
1343 The buffer is then freed since the internalized relocs are attached to
1344 the section, turning additional invocations of vms_slurp_reloc_table
1345 on the same section into no-ops.
1347 Since VMS objects have very few sections, it could be profitable to merge
1348 phase #2 and phase #3, i.e. to decode and internalize the relocs for all
1349 the sections at once. The current implementation is more elegant. */
1352 vms_slurp_reloc_table (bfd
*abfd
, asection
*section
, asymbol
**symbols
)
1354 arelent
*internal_relocs
;
1358 /* If there were no relocations, there is nothing to do. */
1359 if (section
->reloc_count
== 0)
1362 /* Return saved information about the relocations if it is available. */
1363 if (section
->relocation
!= NULL
)
1366 /* If the relocation stream has not been slurped, do it now. */
1367 if (vms_section_data (section
)->reloc_stream
== NULL
)
1369 bfd_boolean alloc_error
= FALSE
;
1372 /* Size the reloc buffer for each section. */
1373 bfd_map_over_sections (abfd
, alloc_reloc_stream
, &alloc_error
);
1377 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
1380 /* Reset section pointer. */
1381 PRIV (image_section
) = NULL
;
1385 type
= _bfd_vms_get_object_record (abfd
);
1386 if (type
!= EOBJ_S_C_ETIR
1387 && type
!= EOBJ_S_C_EDBG
1388 && type
!= EOBJ_S_C_ETBT
)
1390 err
= _bfd_vms_slurp_relocs (abfd
);
1394 vms_debug (2, "slurp relocs failed with %d\n", err
);
1399 while (type
!= EOBJ_S_C_EEOM
);
1402 amt
= section
->reloc_count
* sizeof (arelent
);
1403 internal_relocs
= (arelent
*) bfd_zalloc (abfd
, amt
);
1404 if (internal_relocs
== NULL
)
1407 /* Decode and internalize the relocations. */
1408 err
= _bfd_vms_decode_relocs (abfd
, internal_relocs
, section
, symbols
);
1412 vms_debug (2, "decode relocs failed with %d\n", err
);
1417 /* We're done with the external relocations. Free them. */
1418 free (vms_section_data (section
)->reloc_stream
);
1419 vms_section_data (section
)->reloc_stream
= NULL
;
1421 /* Save our results and return success. */
1422 section
->relocation
= internal_relocs
;
1426 /* Return the number of bytes required to store the relocation
1427 information associated with the given section. */
1430 vms_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
1432 return (section
->reloc_count
+ 1) * sizeof (arelent
*);
1435 /* Convert relocations from VMS (external) form into BFD internal
1436 form. Return the number of relocations. */
1439 vms_canonicalize_reloc (bfd
*abfd
, asection
*section
, arelent
**relptr
,
1445 if (! vms_slurp_reloc_table (abfd
, section
, symbols
))
1448 count
= section
->reloc_count
;
1449 tblptr
= section
->relocation
;
1452 *relptr
++ = tblptr
++;
1454 *relptr
= (arelent
*) NULL
;
1455 return section
->reloc_count
;
1458 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
1460 /* How to process the various reloc types. */
1462 static bfd_reloc_status_type
1463 reloc_nil (bfd
* abfd ATTRIBUTE_UNUSED
,
1464 arelent
*reloc ATTRIBUTE_UNUSED
,
1465 asymbol
*sym ATTRIBUTE_UNUSED
,
1466 void * data ATTRIBUTE_UNUSED
,
1467 asection
*sec ATTRIBUTE_UNUSED
,
1468 bfd
*output_bfd ATTRIBUTE_UNUSED
,
1469 char **error_message ATTRIBUTE_UNUSED
)
1472 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1473 vms_debug (2, "In section %s, symbol %s\n",
1474 sec
->name
, sym
->name
);
1475 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1476 reloc
->sym_ptr_ptr
[0]->name
,
1477 (unsigned long)reloc
->address
,
1478 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1479 vms_debug (2, "data at %p\n", data
);
1480 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
1483 return bfd_reloc_ok
;
1486 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1487 from smaller values. Start with zero, widen, *then* decrement. */
1488 #define MINUS_ONE (((bfd_vma)0) - 1)
1490 static reloc_howto_type alpha_howto_table
[] =
1492 HOWTO (ALPHA_R_IGNORE
, /* Type. */
1493 0, /* Rightshift. */
1494 0, /* Size (0 = byte, 1 = short, 2 = long). */
1496 TRUE
, /* PC relative. */
1498 complain_overflow_dont
,/* Complain_on_overflow. */
1499 reloc_nil
, /* Special_function. */
1500 "IGNORE", /* Name. */
1501 TRUE
, /* Partial_inplace. */
1502 0, /* Source mask */
1504 TRUE
), /* PC rel offset. */
1506 /* A 64 bit reference to a symbol. */
1507 HOWTO (ALPHA_R_REFQUAD
, /* Type. */
1508 0, /* Rightshift. */
1509 4, /* Size (0 = byte, 1 = short, 2 = long). */
1511 FALSE
, /* PC relative. */
1513 complain_overflow_bitfield
, /* Complain_on_overflow. */
1514 reloc_nil
, /* Special_function. */
1515 "REFQUAD", /* Name. */
1516 TRUE
, /* Partial_inplace. */
1517 MINUS_ONE
, /* Source mask. */
1518 MINUS_ONE
, /* Dest mask. */
1519 FALSE
), /* PC rel offset. */
1521 /* A 21 bit branch. The native assembler generates these for
1522 branches within the text segment, and also fills in the PC
1523 relative offset in the instruction. */
1524 HOWTO (ALPHA_R_BRADDR
, /* Type. */
1525 2, /* Rightshift. */
1526 2, /* Size (0 = byte, 1 = short, 2 = long). */
1528 TRUE
, /* PC relative. */
1530 complain_overflow_signed
, /* Complain_on_overflow. */
1531 reloc_nil
, /* Special_function. */
1532 "BRADDR", /* Name. */
1533 TRUE
, /* Partial_inplace. */
1534 0x1fffff, /* Source mask. */
1535 0x1fffff, /* Dest mask. */
1536 FALSE
), /* PC rel offset. */
1538 /* A hint for a jump to a register. */
1539 HOWTO (ALPHA_R_HINT
, /* Type. */
1540 2, /* Rightshift. */
1541 1, /* Size (0 = byte, 1 = short, 2 = long). */
1543 TRUE
, /* PC relative. */
1545 complain_overflow_dont
,/* Complain_on_overflow. */
1546 reloc_nil
, /* Special_function. */
1548 TRUE
, /* Partial_inplace. */
1549 0x3fff, /* Source mask. */
1550 0x3fff, /* Dest mask. */
1551 FALSE
), /* PC rel offset. */
1553 /* 16 bit PC relative offset. */
1554 HOWTO (ALPHA_R_SREL16
, /* Type. */
1555 0, /* Rightshift. */
1556 1, /* Size (0 = byte, 1 = short, 2 = long). */
1558 TRUE
, /* PC relative. */
1560 complain_overflow_signed
, /* Complain_on_overflow. */
1561 reloc_nil
, /* Special_function. */
1562 "SREL16", /* Name. */
1563 TRUE
, /* Partial_inplace. */
1564 0xffff, /* Source mask. */
1565 0xffff, /* Dest mask. */
1566 FALSE
), /* PC rel offset. */
1568 /* 32 bit PC relative offset. */
1569 HOWTO (ALPHA_R_SREL32
, /* Type. */
1570 0, /* Rightshift. */
1571 2, /* Size (0 = byte, 1 = short, 2 = long). */
1573 TRUE
, /* PC relative. */
1575 complain_overflow_signed
, /* Complain_on_overflow. */
1576 reloc_nil
, /* Special_function. */
1577 "SREL32", /* Name. */
1578 TRUE
, /* Partial_inplace. */
1579 0xffffffff, /* Source mask. */
1580 0xffffffff, /* Dest mask. */
1581 FALSE
), /* PC rel offset. */
1583 /* A 64 bit PC relative offset. */
1584 HOWTO (ALPHA_R_SREL64
, /* Type. */
1585 0, /* Rightshift. */
1586 4, /* Size (0 = byte, 1 = short, 2 = long). */
1588 TRUE
, /* PC relative. */
1590 complain_overflow_signed
, /* Complain_on_overflow. */
1591 reloc_nil
, /* Special_function. */
1592 "SREL64", /* Name. */
1593 TRUE
, /* Partial_inplace. */
1594 MINUS_ONE
, /* Source mask. */
1595 MINUS_ONE
, /* Dest mask. */
1596 FALSE
), /* PC rel offset. */
1598 /* Push a value on the reloc evaluation stack. */
1599 HOWTO (ALPHA_R_OP_PUSH
, /* Type. */
1600 0, /* Rightshift. */
1601 0, /* Size (0 = byte, 1 = short, 2 = long). */
1603 FALSE
, /* PC relative. */
1605 complain_overflow_dont
,/* Complain_on_overflow. */
1606 reloc_nil
, /* Special_function. */
1607 "OP_PUSH", /* Name. */
1608 FALSE
, /* Partial_inplace. */
1609 0, /* Source mask. */
1611 FALSE
), /* PC rel offset. */
1613 /* Store the value from the stack at the given address. Store it in
1614 a bitfield of size r_size starting at bit position r_offset. */
1615 HOWTO (ALPHA_R_OP_STORE
, /* Type. */
1616 0, /* Rightshift. */
1617 4, /* Size (0 = byte, 1 = short, 2 = long). */
1619 FALSE
, /* PC relative. */
1621 complain_overflow_dont
,/* Complain_on_overflow. */
1622 reloc_nil
, /* Special_function. */
1623 "OP_STORE", /* Name. */
1624 FALSE
, /* Partial_inplace. */
1625 0, /* Source mask. */
1626 MINUS_ONE
, /* Dest mask. */
1627 FALSE
), /* PC rel offset. */
1629 /* Subtract the reloc address from the value on the top of the
1630 relocation stack. */
1631 HOWTO (ALPHA_R_OP_PSUB
, /* Type. */
1632 0, /* Rightshift. */
1633 0, /* Size (0 = byte, 1 = short, 2 = long). */
1635 FALSE
, /* PC relative. */
1637 complain_overflow_dont
,/* Complain_on_overflow. */
1638 reloc_nil
, /* Special_function. */
1639 "OP_PSUB", /* Name. */
1640 FALSE
, /* Partial_inplace. */
1641 0, /* Source mask. */
1643 FALSE
), /* PC rel offset. */
1645 /* Shift the value on the top of the relocation stack right by the
1647 HOWTO (ALPHA_R_OP_PRSHIFT
, /* Type. */
1648 0, /* Rightshift. */
1649 0, /* Size (0 = byte, 1 = short, 2 = long). */
1651 FALSE
, /* PC relative. */
1653 complain_overflow_dont
,/* Complain_on_overflow. */
1654 reloc_nil
, /* Special_function. */
1655 "OP_PRSHIFT", /* Name. */
1656 FALSE
, /* Partial_inplace. */
1657 0, /* Source mask. */
1659 FALSE
), /* PC rel offset. */
1661 /* Hack. Linkage is done by linker. */
1662 HOWTO (ALPHA_R_LINKAGE
, /* Type. */
1663 0, /* Rightshift. */
1664 8, /* Size (0 = byte, 1 = short, 2 = long). */
1666 FALSE
, /* PC relative. */
1668 complain_overflow_dont
,/* Complain_on_overflow. */
1669 reloc_nil
, /* Special_function. */
1670 "LINKAGE", /* Name. */
1671 FALSE
, /* Partial_inplace. */
1672 0, /* Source mask. */
1674 FALSE
), /* PC rel offset. */
1676 /* A 32 bit reference to a symbol. */
1677 HOWTO (ALPHA_R_REFLONG
, /* Type. */
1678 0, /* Rightshift. */
1679 2, /* Size (0 = byte, 1 = short, 2 = long). */
1681 FALSE
, /* PC relative. */
1683 complain_overflow_bitfield
, /* Complain_on_overflow. */
1684 reloc_nil
, /* Special_function. */
1685 "REFLONG", /* Name. */
1686 TRUE
, /* Partial_inplace. */
1687 0xffffffff, /* Source mask. */
1688 0xffffffff, /* Dest mask. */
1689 FALSE
), /* PC rel offset. */
1691 /* A 64 bit reference to a procedure, written as 32 bit value. */
1692 HOWTO (ALPHA_R_CODEADDR
, /* Type. */
1693 0, /* Rightshift. */
1694 4, /* Size (0 = byte, 1 = short, 2 = long). */
1696 FALSE
, /* PC relative. */
1698 complain_overflow_signed
,/* Complain_on_overflow. */
1699 reloc_nil
, /* Special_function. */
1700 "CODEADDR", /* Name. */
1701 FALSE
, /* Partial_inplace. */
1702 0xffffffff, /* Source mask. */
1703 0xffffffff, /* Dest mask. */
1704 FALSE
), /* PC rel offset. */
1706 HOWTO (ALPHA_R_NOP
, /* Type. */
1707 0, /* Rightshift. */
1708 3, /* Size (0 = byte, 1 = short, 2 = long). */
1710 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
1711 because the calculations for the 3 relocations are the same.
1712 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
1713 TRUE
, /* PC relative. */
1715 complain_overflow_dont
,/* Complain_on_overflow. */
1716 reloc_nil
, /* Special_function. */
1718 FALSE
, /* Partial_inplace. */
1719 0xffffffff, /* Source mask. */
1720 0xffffffff, /* Dest mask. */
1721 FALSE
), /* PC rel offset. */
1723 HOWTO (ALPHA_R_BSR
, /* Type. */
1724 0, /* Rightshift. */
1725 3, /* Size (0 = byte, 1 = short, 2 = long). */
1727 TRUE
, /* PC relative. */
1729 complain_overflow_dont
,/* Complain_on_overflow. */
1730 reloc_nil
, /* Special_function. */
1732 FALSE
, /* Partial_inplace. */
1733 0xffffffff, /* Source mask. */
1734 0xffffffff, /* Dest mask. */
1735 FALSE
), /* PC rel offset. */
1737 HOWTO (ALPHA_R_LDA
, /* Type. */
1738 0, /* Rightshift. */
1739 3, /* Size (0 = byte, 1 = short, 2 = long). */
1741 FALSE
, /* PC relative. */
1743 complain_overflow_dont
,/* Complain_on_overflow. */
1744 reloc_nil
, /* Special_function. */
1746 FALSE
, /* Partial_inplace. */
1747 0xffffffff, /* Source mask. */
1748 0xffffffff, /* Dest mask. */
1749 FALSE
), /* PC rel offset. */
1751 HOWTO (ALPHA_R_BOH
, /* Type. */
1752 0, /* Rightshift. */
1753 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
1755 TRUE
, /* PC relative. */
1757 complain_overflow_dont
,/* Complain_on_overflow. */
1758 reloc_nil
, /* Special_function. */
1760 FALSE
, /* Partial_inplace. */
1761 0xffffffff, /* Source mask. */
1762 0xffffffff, /* Dest mask. */
1763 FALSE
), /* PC rel offset. */
1766 /* Return a pointer to a howto structure which, when invoked, will perform
1767 the relocation code on data from the architecture noted. */
1769 static const struct reloc_howto_struct
*
1770 vms_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1771 bfd_reloc_code_real_type code
)
1776 vms_debug (1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd
, code
);
1781 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1782 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1783 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1784 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1785 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1786 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1787 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1788 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1789 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1790 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1791 case BFD_RELOC_ALPHA_CODEADDR
: alpha_type
= ALPHA_R_CODEADDR
; break;
1792 case BFD_RELOC_ALPHA_NOP
: alpha_type
= ALPHA_R_NOP
; break;
1793 case BFD_RELOC_ALPHA_BSR
: alpha_type
= ALPHA_R_BSR
; break;
1794 case BFD_RELOC_ALPHA_LDA
: alpha_type
= ALPHA_R_LDA
; break;
1795 case BFD_RELOC_ALPHA_BOH
: alpha_type
= ALPHA_R_BOH
; break;
1797 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1801 vms_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1803 return & alpha_howto_table
[alpha_type
];
1806 static reloc_howto_type
*
1807 vms_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1813 i
< sizeof (alpha_howto_table
) / sizeof (alpha_howto_table
[0]);
1815 if (alpha_howto_table
[i
].name
!= NULL
1816 && strcasecmp (alpha_howto_table
[i
].name
, r_name
) == 0)
1817 return &alpha_howto_table
[i
];
1822 /* Part 4.7, writing an object file. */
1824 /* Set the architecture and machine type in BFD abfd to arch and mach.
1825 Find the correct pointer to a structure and insert it into the arch_info
1829 vms_set_arch_mach (bfd
* abfd
,
1830 enum bfd_architecture arch ATTRIBUTE_UNUSED
,
1831 unsigned long mach ATTRIBUTE_UNUSED
)
1834 vms_debug (1, "vms_set_arch_mach (%p, %d, %ld)\n", abfd
, arch
, mach
);
1837 if (arch
!= bfd_arch_alpha
1838 && arch
!= bfd_arch_vax
1839 && arch
!= bfd_arch_unknown
)
1842 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
1845 /* Sets the contents of the section section in BFD abfd to the data starting
1846 in memory at LOCATION. The data is written to the output section starting
1847 at offset offset for count bytes.
1849 Normally TRUE is returned, else FALSE. Possible error returns are:
1850 o bfd_error_no_contents - The output section does not have the
1851 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1852 o and some more too */
1855 vms_set_section_contents (bfd
* abfd
,
1857 const void * location
,
1859 bfd_size_type count
)
1862 vms_debug (1, "vms_set_section_contents (%p, sec %s, loc %p, off %ld, count %d)\n",
1863 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1864 vms_debug (2, "size %d\n", (int) section
->size
);
1866 if (count
== (bfd_size_type
)0)
1869 if (section
->contents
== NULL
)
1870 section
->contents
= bfd_alloc (abfd
, section
->size
);
1871 if (section
->contents
== NULL
)
1874 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
1878 /* Part 4.8, linker. */
1880 /* Get the size of the section headers. */
1883 vms_sizeof_headers (bfd
* abfd ATTRIBUTE_UNUSED
,
1884 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1887 vms_debug (1, "vms_sizeof_headers (%p, %s)\n", abfd
, (reloc
)?"True":"False");
1892 /* Provides default handling of relocation effort for back ends
1893 which can't be bothered to do it efficiently. */
1896 vms_bfd_get_relocated_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
1897 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1898 struct bfd_link_order
*link_order ATTRIBUTE_UNUSED
,
1899 bfd_byte
*data ATTRIBUTE_UNUSED
,
1900 bfd_boolean relocatable ATTRIBUTE_UNUSED
,
1901 asymbol
**symbols ATTRIBUTE_UNUSED
)
1904 vms_debug (1, "vms_bfd_get_relocated_section_contents (%p, %p, %p, %p, %s, %p)\n",
1905 abfd
, link_info
, link_order
, data
, (relocatable
)?"True":"False", symbols
);
1913 vms_bfd_relax_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1914 asection
*section ATTRIBUTE_UNUSED
,
1915 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1916 bfd_boolean
*again ATTRIBUTE_UNUSED
)
1918 if (link_info
->relocatable
)
1919 (*link_info
->callbacks
->einfo
)
1920 (_("%P%F: --relax and -r may not be used together\n"));
1923 vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, <ret>)\n",
1924 abfd
, section
->name
, link_info
);
1930 vms_bfd_gc_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1931 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1934 vms_debug (1, "vms_bfd_gc_sections (%p, %p)\n", abfd
, link_info
);
1940 vms_bfd_merge_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1941 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1944 vms_debug (1, "vms_bfd_merge_sections (%p, %p)\n", abfd
, link_info
);
1949 /* Create a hash table for the linker. Different backends store
1950 different information in this table. */
1952 static struct bfd_link_hash_table
*
1953 vms_bfd_link_hash_table_create (bfd
* abfd ATTRIBUTE_UNUSED
)
1956 vms_debug (1, "vms_bfd_link_hash_table_create (%p)\n", abfd
);
1961 /* Free a linker hash table. */
1964 vms_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash ATTRIBUTE_UNUSED
)
1967 vms_debug (1, "vms_bfd_link_hash_table_free (%p)\n", abfd
);
1971 /* Add symbols from this object file into the hash table. */
1974 vms_bfd_link_add_symbols (bfd
* abfd ATTRIBUTE_UNUSED
,
1975 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1978 vms_debug (1, "vms_bfd_link_add_symbols (%p, %p)\n", abfd
, link_info
);
1983 /* Do a link based on the link_order structures attached to each
1984 section of the BFD. */
1987 vms_bfd_final_link (bfd
* abfd ATTRIBUTE_UNUSED
,
1988 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1991 vms_debug (1, "vms_bfd_final_link (%p, %p)\n", abfd
, link_info
);
1996 /* Should this section be split up into smaller pieces during linking. */
1999 vms_bfd_link_split_section (bfd
* abfd ATTRIBUTE_UNUSED
,
2000 asection
*section ATTRIBUTE_UNUSED
)
2003 vms_debug (1, "vms_bfd_link_split_section (%p, %s)\n", abfd
, section
->name
);
2008 /* Part 4.9, dynamic symbols and relocations. */
2010 /* Get the amount of memory required to hold the dynamic symbols. */
2013 vms_get_dynamic_symtab_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2016 vms_debug (1, "vms_get_dynamic_symtab_upper_bound (%p)\n", abfd
);
2022 vms_bfd_print_private_bfd_data (bfd
* abfd ATTRIBUTE_UNUSED
,
2023 void *file ATTRIBUTE_UNUSED
)
2026 vms_debug (1, "vms_bfd_print_private_bfd_data (%p)\n", abfd
);
2031 /* Read in the dynamic symbols. */
2034 vms_canonicalize_dynamic_symtab (bfd
* abfd ATTRIBUTE_UNUSED
,
2035 asymbol
**symbols ATTRIBUTE_UNUSED
)
2038 vms_debug (1, "vms_canonicalize_dynamic_symtab (%p, <ret>)\n", abfd
);
2043 /* Get the amount of memory required to hold the dynamic relocs. */
2046 vms_get_dynamic_reloc_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2049 vms_debug (1, "vms_get_dynamic_reloc_upper_bound (%p)\n", abfd
);
2054 /* Read in the dynamic relocs. */
2057 vms_canonicalize_dynamic_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
2058 arelent
**arel ATTRIBUTE_UNUSED
,
2059 asymbol
**symbols ATTRIBUTE_UNUSED
)
2062 vms_debug (1, "vms_canonicalize_dynamic_reloc (%p)\n", abfd
);
2067 const bfd_target vms_alpha_vec
=
2069 "vms-alpha", /* Name. */
2070 bfd_target_evax_flavour
,
2071 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2072 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2074 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
2075 | WP_TEXT
| D_PAGED
), /* Object flags. */
2076 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2077 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2078 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2079 0, /* symbol_leading_char. */
2080 ' ', /* ar_pad_char. */
2081 15, /* ar_max_namelen. */
2082 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2083 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2084 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2085 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2086 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2087 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2089 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2090 vms_archive_p
, _bfd_dummy_target
},
2091 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2092 _bfd_generic_mkarchive
, bfd_false
},
2093 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2094 _bfd_write_archive_contents
, bfd_false
},
2096 BFD_JUMP_TABLE_GENERIC (vms
),
2097 BFD_JUMP_TABLE_COPY (vms
),
2098 BFD_JUMP_TABLE_CORE (vms
),
2099 BFD_JUMP_TABLE_ARCHIVE (vms
),
2100 BFD_JUMP_TABLE_SYMBOLS (vms
),
2101 BFD_JUMP_TABLE_RELOCS (vms
),
2102 BFD_JUMP_TABLE_WRITE (vms
),
2103 BFD_JUMP_TABLE_LINK (vms
),
2104 BFD_JUMP_TABLE_DYNAMIC (vms
),
2111 const bfd_target vms_vax_vec
=
2113 "vms-vax", /* Name. */
2114 bfd_target_ovax_flavour
,
2115 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2116 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2118 (HAS_RELOC
| HAS_SYMS
/* Object flags. */
2120 | HAS_LINENO
| HAS_DEBUG
| HAS_LOCALS
),
2122 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2123 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2124 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2125 0, /* symbol_leading_char */
2126 ' ', /* ar_pad_char */
2127 15, /* ar_max_namelen */
2128 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2129 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2130 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
2131 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2132 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2133 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
2135 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2136 vms_archive_p
, _bfd_dummy_target
},
2137 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2138 _bfd_generic_mkarchive
, bfd_false
},
2139 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2140 _bfd_write_archive_contents
, bfd_false
},
2142 BFD_JUMP_TABLE_GENERIC (vms
),
2143 BFD_JUMP_TABLE_COPY (vms
),
2144 BFD_JUMP_TABLE_CORE (vms
),
2145 BFD_JUMP_TABLE_ARCHIVE (vms
),
2146 BFD_JUMP_TABLE_SYMBOLS (vms
),
2147 BFD_JUMP_TABLE_RELOCS (vms
),
2148 BFD_JUMP_TABLE_WRITE (vms
),
2149 BFD_JUMP_TABLE_LINK (vms
),
2150 BFD_JUMP_TABLE_DYNAMIC (vms
),