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. */
28 #define RME$C_SETRFM 0x00000001
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
,
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
,
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
,
99 static bfd_boolean
vms_slurp_reloc_table (bfd
*abfd
, asection
*section
,
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
,
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
);
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_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
148 #define vms_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
152 /* Cause debug info to be emitted for the structure. */
153 struct vms_private_data_struct _vms_private_data_struct_dummy
;
154 struct vms_section_data_struct _vms_section_data_struct_dummy
;
157 extern const bfd_target vms_vax_vec
;
158 extern const bfd_target vms_alpha_vec
;
160 /* Initialize private data */
162 vms_initialize (bfd
* abfd
)
166 bfd_set_start_address (abfd
, (bfd_vma
) -1);
168 amt
= sizeof (struct vms_private_data_struct
);
169 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
170 if (abfd
->tdata
.any
== NULL
)
173 if (bfd_get_flavour (abfd
) == bfd_target_ovax_flavour
)
174 PRIV (is_vax
) = TRUE
;
176 PRIV (file_format
) = FF_UNKNOWN
;
178 amt
= sizeof (struct stack_struct
) * STACKSIZE
;
179 PRIV (stack
) = bfd_alloc (abfd
, amt
);
180 if (PRIV (stack
) == NULL
)
183 amt
= sizeof (struct bfd_hash_table
);
184 PRIV (vms_symbol_table
) = bfd_alloc (abfd
, amt
);
185 if (PRIV (vms_symbol_table
) == NULL
)
188 if (!bfd_hash_table_init (PRIV (vms_symbol_table
), _bfd_vms_hash_newfunc
,
189 sizeof (vms_symbol_entry
)))
192 amt
= MAX_OUTREC_SIZE
;
193 PRIV (output_buf
) = bfd_alloc (abfd
, amt
);
194 if (PRIV (output_buf
) == NULL
)
197 PRIV (length_pos
) = 2;
202 bfd_hash_table_free (PRIV (vms_symbol_table
));
204 bfd_release (abfd
, abfd
->tdata
.any
);
205 abfd
->tdata
.any
= NULL
;
211 unsigned int section_count
;
215 /* Fill symbol->section with section pointer.
217 symbol->section is filled with the section index for defined symbols
218 during reading the GSD/EGSD section. But we need the pointer to the
221 It has the correct value for referenced (undefined section) symbols.
223 Called from bfd_hash_traverse in vms_fixup_sections. */
226 fill_section_ptr (struct bfd_hash_entry
*entry
, void *sections
)
228 asymbol
*sym
= ((vms_symbol_entry
*)entry
)->symbol
;
229 struct pair
*data
= (struct pair
*)sections
;
230 unsigned long sec
= (unsigned long)sym
->section
;
233 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym
, sec
);
236 if (sec
< data
->section_count
)
238 sym
->section
= data
->sections
[sec
];
240 if (strcmp (sym
->name
, sym
->section
->name
) == 0)
241 sym
->flags
|= BSF_SECTION_SYM
;
243 else if (sec
== (unsigned long)-1)
244 sym
->section
= &bfd_und_section
;
249 /* Fixup section pointers in symbols. */
251 vms_fixup_sections (bfd
* abfd
)
255 if (PRIV (fixup_done
))
258 data
.section_count
= PRIV (section_count
);
259 data
.sections
= PRIV (sections
);
260 bfd_hash_traverse (PRIV (vms_symbol_table
), fill_section_ptr
, &data
);
262 PRIV (fixup_done
) = TRUE
;
266 /* Slurp an ordered set of VMS object records. */
268 _bfd_vms_slurp_object_records (bfd
* abfd
)
270 int err
, new_type
, type
= -1;
275 vms_debug (7, "reading at %08lx\n", bfd_tell (abfd
));
277 new_type
= _bfd_vms_get_object_record (abfd
);
281 vms_debug (2, "next_record failed\n");
286 if (type
== EOBJ_S_C_EGSD
&& new_type
!= EOBJ_S_C_EGSD
)
288 if (! vms_fixup_sections (abfd
))
291 vms_debug (2, "vms_fixup_sections failed\n");
303 err
= _bfd_vms_slurp_hdr (abfd
, type
);
308 err
= _bfd_vms_slurp_eom (abfd
, type
);
312 err
= _bfd_vms_slurp_gsd (abfd
, type
);
316 err
= _bfd_vms_slurp_tir (abfd
, type
);
320 err
= _bfd_vms_slurp_dbg (abfd
, type
);
321 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
325 err
= _bfd_vms_slurp_tbt (abfd
, type
);
326 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
329 err
= _bfd_vms_slurp_lnk (abfd
, type
);
337 vms_debug (2, "slurp type %d failed with %d\n", type
, err
);
342 while (type
!= EOBJ_S_C_EEOM
&& type
!= OBJ_S_C_EOM
&& type
!= OBJ_S_C_EOMW
);
347 /* Slurp a VMS module and return an error status. */
350 vms_slurp_module (bfd
*abfd
)
355 type
= PRIV (vms_rec
)[0];
357 type
= bfd_getl16 (PRIV (vms_rec
));
359 err
= _bfd_vms_slurp_hdr (abfd
, type
);
362 bfd_set_error (bfd_error_wrong_format
);
366 return _bfd_vms_slurp_object_records (abfd
);
369 /* Slurp a VMS image and return an error status. */
372 vms_slurp_image (bfd
*abfd
)
374 unsigned int isd_offset
, ihs_offset
;
377 err
= _bfd_vms_slurp_ihd (abfd
, &isd_offset
, &ihs_offset
);
380 bfd_set_error (bfd_error_wrong_format
);
384 err
= _bfd_vms_slurp_isd (abfd
, isd_offset
);
387 bfd_set_error (bfd_error_wrong_format
);
391 return _bfd_vms_slurp_ihs (abfd
, ihs_offset
);
394 /* Check the format for a file being read.
395 Return a (bfd_target *) if it's an object file or zero if not. */
397 static const struct bfd_target
*
398 vms_object_p (bfd
*abfd
)
400 const struct bfd_target
*target_vector
;
401 const bfd_arch_info_type
*arch
;
402 PTR tdata_save
= abfd
->tdata
.any
;
403 bfd_vma saddr_save
= bfd_get_start_address (abfd
);
407 vms_debug (1, "vms_object_p(%p)\n", abfd
);
410 if (!vms_initialize (abfd
))
413 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
))
414 goto err_wrong_format
;
416 switch (_bfd_vms_get_first_record (abfd
))
424 err
= vms_slurp_module (abfd
);
428 err
= vms_slurp_image (abfd
);
433 goto err_wrong_format
;
437 if (! vms_fixup_sections (abfd
))
440 vms_debug (2, "vms_fixup_sections failed\n");
442 goto err_wrong_format
;
445 target_vector
= &vms_vax_vec
;
446 arch
= bfd_scan_arch ("vax");
449 vms_debug (2, "arch is vax\n");
454 /* Set arch_info to alpha. */
455 target_vector
= &vms_alpha_vec
;
456 arch
= bfd_scan_arch ("alpha");
458 vms_debug (2, "arch is alpha\n");
462 abfd
->arch_info
= arch
;
463 return target_vector
;
466 bfd_set_error (bfd_error_wrong_format
);
469 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
470 bfd_release (abfd
, abfd
->tdata
.any
);
471 abfd
->tdata
.any
= tdata_save
;
472 bfd_set_start_address (abfd
, saddr_save
);
476 /* Check the format for a file being read.
477 Return a (bfd_target *) if it's an archive file or zero. */
479 static const struct bfd_target
*
480 vms_archive_p (bfd
* abfd ATTRIBUTE_UNUSED
)
483 vms_debug (1, "vms_archive_p (%p)\n", abfd
);
489 /* Set the format of a file being written. */
492 vms_mkobject (bfd
* abfd
)
494 const bfd_arch_info_type
*arch
;
497 vms_debug (1, "vms_mkobject (%p)\n", abfd
);
500 if (!vms_initialize (abfd
))
504 arch
= bfd_scan_arch ("vax");
506 arch
= bfd_scan_arch ("alpha");
510 bfd_set_error(bfd_error_wrong_format
);
514 abfd
->arch_info
= arch
;
518 /* Write cached information into a file being written, at bfd_close. */
521 vms_write_object_contents (bfd
* abfd
)
524 vms_debug (1, "vms_write_object_contents (%p)\n", abfd
);
527 if (abfd
->section_count
> 0) /* we have sections */
531 if (_bfd_vms_write_hdr (abfd
, OBJ_S_C_HDR
) != 0)
533 if (_bfd_vms_write_gsd (abfd
, OBJ_S_C_GSD
) != 0)
535 if (_bfd_vms_write_tir (abfd
, OBJ_S_C_TIR
) != 0)
537 if (_bfd_vms_write_tbt (abfd
, OBJ_S_C_TBT
) != 0)
539 if (_bfd_vms_write_dbg (abfd
, OBJ_S_C_DBG
) != 0)
541 if (abfd
->section_count
> 255)
543 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOMW
) != 0)
548 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOM
) != 0)
554 if (_bfd_vms_write_hdr (abfd
, EOBJ_S_C_EMH
) != 0)
556 if (_bfd_vms_write_gsd (abfd
, EOBJ_S_C_EGSD
) != 0)
558 if (_bfd_vms_write_tir (abfd
, EOBJ_S_C_ETIR
) != 0)
560 if (_bfd_vms_write_tbt (abfd
, EOBJ_S_C_ETBT
) != 0)
562 if (_bfd_vms_write_dbg (abfd
, EOBJ_S_C_EDBG
) != 0)
564 if (_bfd_vms_write_eom (abfd
, EOBJ_S_C_EEOM
) != 0)
573 /* Free the reloc buffer for the specified section. */
576 free_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
577 void *data ATTRIBUTE_UNUSED
)
579 if (vms_section_data (section
)->reloc_stream
)
580 free (vms_section_data (section
)->reloc_stream
);
584 /* Convert the file to variable record length format. This is done
585 using undocumented system call sys$modify().
589 vms_convert_to_var (char *vms_filename
)
591 struct FAB fab
= cc$rms_fab
;
593 fab
.fab$l_fna
= vms_filename
;
594 fab
.fab$b_fns
= strlen (vms_filename
);
595 fab
.fab$b_fac
= FAB$M_PUT
;
596 fab
.fab$l_fop
= FAB$M_ESC
;
597 fab
.fab$l_ctx
= RME$C_SETRFM
;
601 fab
.fab$b_rfm
= FAB$C_VAR
;
608 vms_convert_to_var_1 (char *filename
, int type
)
610 if (type
!= DECC$K_FILE
)
612 vms_convert_to_var (filename
);
616 /* Convert the file to variable record length format. This is done
617 using undocumented system call sys$modify().
618 Unix filename version. */
621 vms_convert_to_var_unix_filename (const char *unix_filename
)
623 if (decc$
to_vms (unix_filename
, &vms_convert_to_var_1
, 0, 1) != 1)
629 /* Called when the BFD is being closed to do any necessary cleanup. */
632 vms_close_and_cleanup (bfd
* abfd
)
635 vms_debug (1, "vms_close_and_cleanup (%p)\n", abfd
);
637 if (abfd
== NULL
|| abfd
->tdata
.any
== NULL
)
640 if (PRIV (vms_buf
) != NULL
)
641 free (PRIV (vms_buf
));
643 if (PRIV (sections
) != NULL
)
644 free (PRIV (sections
));
646 if (PRIV (vms_symbol_table
))
647 bfd_hash_table_free (PRIV (vms_symbol_table
));
649 bfd_map_over_sections (abfd
, free_reloc_stream
, NULL
);
651 bfd_release (abfd
, abfd
->tdata
.any
);
652 abfd
->tdata
.any
= NULL
;
655 if (abfd
->direction
== write_direction
)
657 /* Last step on VMS is to convert the file to variable record length
659 if (bfd_cache_close (abfd
) != TRUE
)
661 if (vms_convert_to_var_unix_filename (abfd
->filename
) != TRUE
)
669 /* Ask the BFD to free all cached information. */
672 vms_bfd_free_cached_info (bfd
* abfd ATTRIBUTE_UNUSED
)
675 vms_debug (1, "vms_bfd_free_cached_info (%p)\n", abfd
);
680 /* Called when a new section is created. */
683 vms_new_section_hook (bfd
* abfd
, asection
*section
)
687 /* Count hasn't been incremented yet. */
688 unsigned int section_count
= abfd
->section_count
+ 1;
691 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
692 abfd
, section
->index
, section
->name
, section_count
);
695 bfd_set_section_alignment (abfd
, section
, 0);
697 if (section_count
> PRIV (section_count
))
699 bfd_size_type amt
= section_count
;
700 amt
*= sizeof (asection
*);
701 PRIV (sections
) = bfd_realloc_or_free (PRIV (sections
), amt
);
702 if (PRIV (sections
) == NULL
)
704 PRIV (section_count
) = section_count
;
708 vms_debug (6, "section_count: %d\n", PRIV (section_count
));
711 PRIV (sections
)[section
->index
] = section
;
714 vms_debug (7, "%d: %s\n", section
->index
, section
->name
);
717 amt
= sizeof (struct vms_section_data_struct
);
718 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
719 if (section
->used_by_bfd
== NULL
)
722 return _bfd_generic_new_section_hook (abfd
, section
);
725 /* Read the contents of a section.
726 buf points to a buffer of buf_size bytes to be filled with
727 section data (starting at offset into section) */
730 vms_get_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
731 asection
*section ATTRIBUTE_UNUSED
,
732 void * buf ATTRIBUTE_UNUSED
,
733 file_ptr offset ATTRIBUTE_UNUSED
,
734 bfd_size_type buf_size ATTRIBUTE_UNUSED
)
736 bfd_size_type size
= section
->size
;
739 vms_debug (1, "vms_get_section_contents (%p, %s, %p, off %ld, size %d)\n",
740 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
743 if (section
->contents
)
746 section
->contents
= (unsigned char *) bfd_malloc (size
);
748 if (section
->contents
== NULL
)
750 bfd_set_error (bfd_error_no_memory
);
754 if (bfd_seek (abfd
, section
->filepos
, SEEK_SET
))
756 bfd_set_error (bfd_error_file_truncated
);
760 if (bfd_bread (section
->contents
, size
, abfd
) != size
)
762 bfd_set_error (bfd_error_file_truncated
);
766 section
->flags
|= SEC_IN_MEMORY
;
769 memcpy (buf
, section
->contents
+ offset
, (size_t) buf_size
);
774 /* Read the contents of a section.
775 buf points to a buffer of buf_size bytes to be filled with
776 section data (starting at offset into section). */
779 vms_get_section_contents_in_window (bfd
* abfd ATTRIBUTE_UNUSED
,
780 asection
*section ATTRIBUTE_UNUSED
,
781 bfd_window
*w ATTRIBUTE_UNUSED
,
782 file_ptr offset ATTRIBUTE_UNUSED
,
783 bfd_size_type count ATTRIBUTE_UNUSED
)
786 vms_debug (1, "vms_get_section_contents_in_window (%p, %s, %p, off %ld, count %d)\n",
787 abfd
, section
->name
, w
, offset
, (int)count
);
790 /* Shouldn't be called, since all sections are IN_MEMORY. */
794 /* Part 4.2, copy private data. */
796 /* Called to copy BFD general private data from one object file
800 vms_bfd_copy_private_bfd_data (bfd
*src ATTRIBUTE_UNUSED
,
801 bfd
*dest ATTRIBUTE_UNUSED
)
804 vms_debug (1, "vms_bfd_copy_private_bfd_data (%p, %p)\n", src
, dest
);
809 /* Merge private BFD information from the BFD @var{ibfd} to the
810 the output file BFD @var{obfd} when linking. Return <<TRUE>>
811 on success, <<FALSE>> on error. Possible error returns are:
813 o <<bfd_error_no_memory>> -
814 Not enough memory exists to create private data for @var{obfd}. */
817 vms_bfd_merge_private_bfd_data (bfd
* ibfd ATTRIBUTE_UNUSED
,
818 bfd
* obfd ATTRIBUTE_UNUSED
)
821 vms_debug (1,"vms_bfd_merge_private_bfd_data (%p, %p)\n", ibfd
, obfd
);
826 /* Set private BFD flag information in the BFD @var{abfd}.
827 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
830 o <<bfd_error_no_memory>> -
831 Not enough memory exists to create private data for @var{obfd}. */
834 vms_bfd_set_private_flags (bfd
* abfd ATTRIBUTE_UNUSED
,
835 flagword flags ATTRIBUTE_UNUSED
)
838 vms_debug (1,"vms_bfd_set_private_flags (%p, %lx)\n", abfd
, (long)flags
);
843 /* Called to copy BFD private section data from one object file
847 vms_bfd_copy_private_section_data (bfd
*srcbfd ATTRIBUTE_UNUSED
,
848 asection
*srcsec ATTRIBUTE_UNUSED
,
849 bfd
*dstbfd ATTRIBUTE_UNUSED
,
850 asection
*dstsec ATTRIBUTE_UNUSED
)
853 vms_debug (1, "vms_bfd_copy_private_section_data (%p, %s, %p, %s)\n",
854 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
859 /* Called to copy BFD private symbol data from one object file
863 vms_bfd_copy_private_symbol_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
864 asymbol
*isym ATTRIBUTE_UNUSED
,
865 bfd
*obfd ATTRIBUTE_UNUSED
,
866 asymbol
*osym ATTRIBUTE_UNUSED
)
869 vms_debug (1, "vms_bfd_copy_private_symbol_data (%p, %s, %p, %s)\n",
870 ibfd
, isym
->name
, obfd
, osym
->name
);
875 /* Part 4.3, core file. */
877 /* Return a read-only string explaining which program was running
878 when it failed and produced the core file abfd. */
881 vms_core_file_failing_command (bfd
* abfd ATTRIBUTE_UNUSED
)
884 vms_debug (1, "vms_core_file_failing_command (%p)\n", abfd
);
889 /* Returns the signal number which caused the core dump which
890 generated the file the BFD abfd is attached to. */
893 vms_core_file_failing_signal (bfd
* abfd ATTRIBUTE_UNUSED
)
896 vms_debug (1, "vms_core_file_failing_signal (%p)\n", abfd
);
901 /* Return TRUE if the core file attached to core_bfd was generated
902 by a run of the executable file attached to exec_bfd, FALSE otherwise. */
905 vms_core_file_matches_executable_p (bfd
* abfd ATTRIBUTE_UNUSED
,
906 bfd
*bbfd ATTRIBUTE_UNUSED
)
909 vms_debug (1, "vms_core_file_matches_executable_p (%p, %p)\n", abfd
, bbfd
);
914 /* Part 4.4, archive. */
916 /* ??? do something with an archive map.
917 Return FALSE on error, TRUE otherwise. */
920 vms_slurp_armap (bfd
* abfd ATTRIBUTE_UNUSED
)
923 vms_debug (1, "vms_slurp_armap (%p)\n", abfd
);
928 /* ??? do something with an extended name table.
929 Return FALSE on error, TRUE otherwise. */
932 vms_slurp_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
)
935 vms_debug (1, "vms_slurp_extended_name_table (%p)\n", abfd
);
940 /* ??? do something with an extended name table.
941 Return FALSE on error, TRUE otherwise. */
944 vms_construct_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
,
945 char **tabloc ATTRIBUTE_UNUSED
,
946 bfd_size_type
*tablen ATTRIBUTE_UNUSED
,
947 const char **name ATTRIBUTE_UNUSED
)
950 vms_debug (1, "vms_construct_extended_name_table (%p)\n", abfd
);
955 /* Truncate the name of an archive to match system-dependent restrictions. */
958 vms_truncate_arname (bfd
* abfd ATTRIBUTE_UNUSED
,
959 const char *pathname ATTRIBUTE_UNUSED
,
960 char *arhdr ATTRIBUTE_UNUSED
)
963 vms_debug (1, "vms_truncate_arname (%p, %s, %s)\n", abfd
, pathname
, arhdr
);
967 /* ??? write archive map. */
970 vms_write_armap (bfd
*arch ATTRIBUTE_UNUSED
,
971 unsigned int elength ATTRIBUTE_UNUSED
,
972 struct orl
*map ATTRIBUTE_UNUSED
,
973 unsigned int orl_count ATTRIBUTE_UNUSED
,
974 int stridx ATTRIBUTE_UNUSED
)
977 vms_debug (1, "vms_write_armap (%p, %d, %p, %d %d)\n",
978 arch
, elength
, map
, orl_count
, stridx
);
983 /* Read archive header ??? */
986 vms_read_ar_hdr (bfd
* abfd ATTRIBUTE_UNUSED
)
989 vms_debug (1, "vms_read_ar_hdr (%p)\n", abfd
);
994 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
995 an input BFD on the first contained element and returns that.
996 Subsequent calls should pass the archive and the previous return value
997 to return a created BFD to the next contained element.
998 NULL is returned when there are no more. */
1001 vms_openr_next_archived_file (bfd
*arch ATTRIBUTE_UNUSED
,
1002 bfd
*prev ATTRIBUTE_UNUSED
)
1005 vms_debug (1, "vms_openr_next_archived_file (%p, %p)\n", arch
, prev
);
1010 /* Return the BFD which is referenced by the symbol in ABFD indexed by
1011 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
1014 vms_get_elt_at_index (bfd
* abfd
, symindex index
)
1017 vms_debug (1, "vms_get_elt_at_index (%p, %p)\n", abfd
, index
);
1019 return _bfd_generic_get_elt_at_index (abfd
, index
);
1023 -> bfd_generic_stat_arch_elt. */
1026 vms_generic_stat_arch_elt (bfd
* abfd
, struct stat
*st
)
1029 vms_debug (1, "vms_generic_stat_arch_elt (%p, %p)\n", abfd
, st
);
1031 return bfd_generic_stat_arch_elt (abfd
, st
);
1034 /* This is a new function in bfd 2.5. */
1037 vms_update_armap_timestamp (bfd
* abfd ATTRIBUTE_UNUSED
)
1040 vms_debug (1, "vms_update_armap_timestamp (%p)\n", abfd
);
1045 /* Part 4.5, symbols. */
1047 /* Return the number of bytes required to store a vector of pointers
1048 to asymbols for all the symbols in the BFD abfd, including a
1049 terminal NULL pointer. If there are no symbols in the BFD,
1050 then return 0. If an error occurs, return -1. */
1053 vms_get_symtab_upper_bound (bfd
* abfd
)
1056 vms_debug (1, "vms_get_symtab_upper_bound (%p), %d symbols\n", abfd
, PRIV (gsd_sym_count
));
1058 return (PRIV (gsd_sym_count
) + 1) * sizeof (asymbol
*);
1061 /* Copy symbols from hash table to symbol vector
1063 called from bfd_hash_traverse in vms_canonicalize_symtab
1064 init counter to 0 if entry == 0. */
1067 copy_symbols (struct bfd_hash_entry
*entry
, void * arg
)
1069 bfd
* abfd
= (bfd
*) arg
;
1071 if (entry
== NULL
) /* Init counter. */
1073 else /* Fill vector, inc counter. */
1074 PRIV (symcache
)[PRIV (symnum
)++] = ((vms_symbol_entry
*)entry
)->symbol
;
1079 /* Read the symbols from the BFD abfd, and fills in the vector
1080 location with pointers to the symbols and a trailing NULL.
1082 Return number of symbols read. */
1085 vms_canonicalize_symtab (bfd
* abfd
, asymbol
**symbols
)
1088 vms_debug (1, "vms_canonicalize_symtab (%p, <ret>)\n", abfd
);
1092 copy_symbols (NULL
, abfd
);
1094 /* Traverse table and fill symbols vector. */
1095 PRIV (symcache
) = symbols
;
1096 bfd_hash_traverse (PRIV (vms_symbol_table
), copy_symbols
, abfd
);
1098 symbols
[PRIV (gsd_sym_count
)] = NULL
;
1100 return PRIV (gsd_sym_count
);
1103 /* Print symbol to file according to how. how is one of
1104 bfd_print_symbol_name just print the name
1105 bfd_print_symbol_more print more (???)
1106 bfd_print_symbol_all print all we know, which is not much right now :-). */
1109 vms_print_symbol (bfd
* abfd
,
1112 bfd_print_symbol_type how
)
1115 vms_debug (1, "vms_print_symbol (%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1120 case bfd_print_symbol_name
:
1121 case bfd_print_symbol_more
:
1122 fprintf ((FILE *)file
," %s", symbol
->name
);
1125 case bfd_print_symbol_all
:
1127 const char *section_name
= symbol
->section
->name
;
1129 bfd_print_symbol_vandf (abfd
, file
, symbol
);
1131 fprintf ((FILE *) file
," %-8s %s", section_name
, symbol
->name
);
1137 /* Return information about symbol in ret.
1139 fill type, value and name
1142 B bss segment symbol
1144 D data segment symbol
1146 t a static function symbol
1147 T text segment symbol
1152 vms_get_symbol_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1159 vms_debug (1, "vms_get_symbol_info (%p, %p, %p)\n", abfd
, symbol
, ret
);
1162 sec
= symbol
->section
;
1169 else if (bfd_is_com_section (sec
))
1171 else if (bfd_is_abs_section (sec
))
1173 else if (bfd_is_und_section (sec
))
1175 else if (bfd_is_ind_section (sec
))
1177 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1179 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1181 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1186 if (ret
->type
!= 'U')
1187 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1190 ret
->name
= symbol
->name
;
1193 /* Return TRUE if the given symbol sym in the BFD abfd is
1194 a compiler generated local label, else return FALSE. */
1197 vms_bfd_is_local_label_name (bfd
* abfd ATTRIBUTE_UNUSED
,
1201 vms_debug (1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd
, name
);
1203 return name
[0] == '$';
1206 /* Get source line number for symbol. */
1209 vms_get_lineno (bfd
* abfd ATTRIBUTE_UNUSED
,
1210 asymbol
*symbol ATTRIBUTE_UNUSED
)
1213 vms_debug (1, "vms_get_lineno (%p, %p)\n", abfd
, symbol
);
1218 /* Provided a BFD, a section and an offset into the section, calculate and
1219 return the name of the source file and the line nearest to the wanted
1223 vms_find_nearest_line (bfd
* abfd ATTRIBUTE_UNUSED
,
1224 asection
*section ATTRIBUTE_UNUSED
,
1225 asymbol
**symbols ATTRIBUTE_UNUSED
,
1226 bfd_vma offset ATTRIBUTE_UNUSED
,
1227 const char **file ATTRIBUTE_UNUSED
,
1228 const char **func ATTRIBUTE_UNUSED
,
1229 unsigned int *line ATTRIBUTE_UNUSED
)
1232 vms_debug (1, "vms_find_nearest_line (%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1233 abfd
, section
->name
, symbols
, (long int)offset
);
1235 return _bfd_vms_find_nearest_dst_line (abfd
, section
, symbols
, offset
, file
, func
, line
);
1239 vms_find_inliner_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1240 const char **file ATTRIBUTE_UNUSED
,
1241 const char **func ATTRIBUTE_UNUSED
,
1242 unsigned int *line ATTRIBUTE_UNUSED
)
1245 vms_debug (1, "vms_find_inliner_info (%p, <ret>, <ret>, <ret>)\n",
1251 /* Back-door to allow format-aware applications to create debug symbols
1252 while using BFD for everything else. Currently used by the assembler
1253 when creating COFF files. */
1256 vms_bfd_make_debug_symbol (bfd
* abfd ATTRIBUTE_UNUSED
,
1257 void *ptr ATTRIBUTE_UNUSED
,
1258 unsigned long size ATTRIBUTE_UNUSED
)
1261 vms_debug (1, "vms_bfd_make_debug_symbol (%p, %p, %ld)\n", abfd
, ptr
, size
);
1266 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1267 symbols. The minisymbol_to_symbol function translates these into
1268 BFD asymbol structures. */
1271 vms_read_minisymbols (bfd
* abfd
,
1272 bfd_boolean dynamic
,
1274 unsigned int *sizep
)
1277 vms_debug (1, "vms_read_minisymbols (%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1279 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1282 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1283 unmodified a.out symbol. The SYM argument is a structure returned
1284 by bfd_make_empty_symbol, which we fill in here. */
1287 vms_minisymbol_to_symbol (bfd
* abfd
,
1288 bfd_boolean dynamic
,
1289 const void * minisym
,
1293 vms_debug (1, "vms_minisymbol_to_symbol (%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1295 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1298 /* Part 4.6, relocations. */
1300 /* Allocate the reloc buffer for the specified section. */
1303 alloc_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
1308 /* If there were no relocations, there is nothing to do. */
1309 if (section
->reloc_count
== 0)
1312 ptr
= bfd_malloc (vms_section_data (section
)->reloc_size
);
1315 *(bfd_boolean
*)alloc_error
= TRUE
;
1319 vms_section_data (section
)->reloc_stream
= ptr
;
1322 /* Read in the relocs for the specified section and internalize them.
1324 The implementation is loosely based on the SOM code and made up
1325 of 3 distinct phases:
1327 1. When the VMS object is opened and parsed, the number and the size
1328 of the relocations are computed for all sections. This makes it
1329 possible to know upfront both which sections have no relocs and
1330 the size of the reloc buffers for the other sections, at virtually
1331 no cost for consumers that don't care about relocs at all.
1333 2. When vms_slurp_reloc_table is invoked for the first time on a section
1334 with relocs, the object is traversed and all the reloc information
1335 is saved in per-section reloc buffers. It would be very inefficient
1336 to scan the whole file on each invocation, so we slurp for all the
1339 3. On subsequent invocations of vms_slurp_reloc_table, the relocs for the
1340 specified section are fetched from the buffer, decoded and internalized.
1341 The buffer is then freed since the internalized relocs are attached to
1342 the section, turning additional invocations of vms_slurp_reloc_table
1343 on the same section into no-ops.
1345 Since VMS objects have very few sections, it could be profitable to merge
1346 phase #2 and phase #3, i.e. to decode and internalize the relocs for all
1347 the sections at once. The current implementation is more elegant. */
1350 vms_slurp_reloc_table (bfd
*abfd
, asection
*section
, asymbol
**symbols
)
1352 arelent
*internal_relocs
;
1356 /* If there were no relocations, there is nothing to do. */
1357 if (section
->reloc_count
== 0)
1360 /* Return saved information about the relocations if it is available. */
1361 if (section
->relocation
!= NULL
)
1364 /* If the relocation stream has not been slurped, do it now. */
1365 if (vms_section_data (section
)->reloc_stream
== NULL
)
1367 bfd_boolean alloc_error
= FALSE
;
1370 /* Size the reloc buffer for each section. */
1371 bfd_map_over_sections (abfd
, alloc_reloc_stream
, &alloc_error
);
1375 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
1378 /* Reset section pointer. */
1379 PRIV (image_section
) = NULL
;
1383 type
= _bfd_vms_get_object_record (abfd
);
1384 if (type
!= EOBJ_S_C_ETIR
1385 && type
!= EOBJ_S_C_EDBG
1386 && type
!= EOBJ_S_C_ETBT
)
1388 err
= _bfd_vms_slurp_relocs (abfd
);
1392 vms_debug (2, "slurp relocs failed with %d\n", err
);
1397 while (type
!= EOBJ_S_C_EEOM
);
1400 amt
= section
->reloc_count
* sizeof (arelent
);
1401 internal_relocs
= (arelent
*) bfd_zalloc (abfd
, amt
);
1402 if (internal_relocs
== NULL
)
1405 /* Decode and internalize the relocations. */
1406 err
= _bfd_vms_decode_relocs (abfd
, internal_relocs
, section
, symbols
);
1410 vms_debug (2, "decode relocs failed with %d\n", err
);
1415 /* We're done with the external relocations. Free them. */
1416 free (vms_section_data (section
)->reloc_stream
);
1417 vms_section_data (section
)->reloc_stream
= NULL
;
1419 /* Save our results and return success. */
1420 section
->relocation
= internal_relocs
;
1424 /* Return the number of bytes required to store the relocation
1425 information associated with the given section. */
1428 vms_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
1430 return (section
->reloc_count
+ 1) * sizeof (arelent
*);
1433 /* Convert relocations from VMS (external) form into BFD internal
1434 form. Return the number of relocations. */
1437 vms_canonicalize_reloc (bfd
*abfd
, asection
*section
, arelent
**relptr
,
1443 if (! vms_slurp_reloc_table (abfd
, section
, symbols
))
1446 count
= section
->reloc_count
;
1447 tblptr
= section
->relocation
;
1450 *relptr
++ = tblptr
++;
1452 *relptr
= (arelent
*) NULL
;
1453 return section
->reloc_count
;
1456 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
1458 /* How to process the various reloc types. */
1460 static bfd_reloc_status_type
1461 reloc_nil (bfd
* abfd ATTRIBUTE_UNUSED
,
1462 arelent
*reloc ATTRIBUTE_UNUSED
,
1463 asymbol
*sym ATTRIBUTE_UNUSED
,
1464 void * data ATTRIBUTE_UNUSED
,
1465 asection
*sec ATTRIBUTE_UNUSED
,
1466 bfd
*output_bfd ATTRIBUTE_UNUSED
,
1467 char **error_message ATTRIBUTE_UNUSED
)
1470 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1471 vms_debug (2, "In section %s, symbol %s\n",
1472 sec
->name
, sym
->name
);
1473 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1474 reloc
->sym_ptr_ptr
[0]->name
,
1475 (unsigned long)reloc
->address
,
1476 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1477 vms_debug (2, "data at %p\n", data
);
1478 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
1481 return bfd_reloc_ok
;
1484 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1485 from smaller values. Start with zero, widen, *then* decrement. */
1486 #define MINUS_ONE (((bfd_vma)0) - 1)
1488 static reloc_howto_type alpha_howto_table
[] =
1490 HOWTO (ALPHA_R_IGNORE
, /* Type. */
1491 0, /* Rightshift. */
1492 0, /* Size (0 = byte, 1 = short, 2 = long). */
1494 TRUE
, /* PC relative. */
1496 complain_overflow_dont
,/* Complain_on_overflow. */
1497 reloc_nil
, /* Special_function. */
1498 "IGNORE", /* Name. */
1499 TRUE
, /* Partial_inplace. */
1500 0, /* Source mask */
1502 TRUE
), /* PC rel offset. */
1504 /* A 64 bit reference to a symbol. */
1505 HOWTO (ALPHA_R_REFQUAD
, /* Type. */
1506 0, /* Rightshift. */
1507 4, /* Size (0 = byte, 1 = short, 2 = long). */
1509 FALSE
, /* PC relative. */
1511 complain_overflow_bitfield
, /* Complain_on_overflow. */
1512 reloc_nil
, /* Special_function. */
1513 "REFQUAD", /* Name. */
1514 TRUE
, /* Partial_inplace. */
1515 MINUS_ONE
, /* Source mask. */
1516 MINUS_ONE
, /* Dest mask. */
1517 FALSE
), /* PC rel offset. */
1519 /* A 21 bit branch. The native assembler generates these for
1520 branches within the text segment, and also fills in the PC
1521 relative offset in the instruction. */
1522 HOWTO (ALPHA_R_BRADDR
, /* Type. */
1523 2, /* Rightshift. */
1524 2, /* Size (0 = byte, 1 = short, 2 = long). */
1526 TRUE
, /* PC relative. */
1528 complain_overflow_signed
, /* Complain_on_overflow. */
1529 reloc_nil
, /* Special_function. */
1530 "BRADDR", /* Name. */
1531 TRUE
, /* Partial_inplace. */
1532 0x1fffff, /* Source mask. */
1533 0x1fffff, /* Dest mask. */
1534 FALSE
), /* PC rel offset. */
1536 /* A hint for a jump to a register. */
1537 HOWTO (ALPHA_R_HINT
, /* Type. */
1538 2, /* Rightshift. */
1539 1, /* Size (0 = byte, 1 = short, 2 = long). */
1541 TRUE
, /* PC relative. */
1543 complain_overflow_dont
,/* Complain_on_overflow. */
1544 reloc_nil
, /* Special_function. */
1546 TRUE
, /* Partial_inplace. */
1547 0x3fff, /* Source mask. */
1548 0x3fff, /* Dest mask. */
1549 FALSE
), /* PC rel offset. */
1551 /* 16 bit PC relative offset. */
1552 HOWTO (ALPHA_R_SREL16
, /* Type. */
1553 0, /* Rightshift. */
1554 1, /* Size (0 = byte, 1 = short, 2 = long). */
1556 TRUE
, /* PC relative. */
1558 complain_overflow_signed
, /* Complain_on_overflow. */
1559 reloc_nil
, /* Special_function. */
1560 "SREL16", /* Name. */
1561 TRUE
, /* Partial_inplace. */
1562 0xffff, /* Source mask. */
1563 0xffff, /* Dest mask. */
1564 FALSE
), /* PC rel offset. */
1566 /* 32 bit PC relative offset. */
1567 HOWTO (ALPHA_R_SREL32
, /* Type. */
1568 0, /* Rightshift. */
1569 2, /* Size (0 = byte, 1 = short, 2 = long). */
1571 TRUE
, /* PC relative. */
1573 complain_overflow_signed
, /* Complain_on_overflow. */
1574 reloc_nil
, /* Special_function. */
1575 "SREL32", /* Name. */
1576 TRUE
, /* Partial_inplace. */
1577 0xffffffff, /* Source mask. */
1578 0xffffffff, /* Dest mask. */
1579 FALSE
), /* PC rel offset. */
1581 /* A 64 bit PC relative offset. */
1582 HOWTO (ALPHA_R_SREL64
, /* Type. */
1583 0, /* Rightshift. */
1584 4, /* Size (0 = byte, 1 = short, 2 = long). */
1586 TRUE
, /* PC relative. */
1588 complain_overflow_signed
, /* Complain_on_overflow. */
1589 reloc_nil
, /* Special_function. */
1590 "SREL64", /* Name. */
1591 TRUE
, /* Partial_inplace. */
1592 MINUS_ONE
, /* Source mask. */
1593 MINUS_ONE
, /* Dest mask. */
1594 FALSE
), /* PC rel offset. */
1596 /* Push a value on the reloc evaluation stack. */
1597 HOWTO (ALPHA_R_OP_PUSH
, /* Type. */
1598 0, /* Rightshift. */
1599 0, /* Size (0 = byte, 1 = short, 2 = long). */
1601 FALSE
, /* PC relative. */
1603 complain_overflow_dont
,/* Complain_on_overflow. */
1604 reloc_nil
, /* Special_function. */
1605 "OP_PUSH", /* Name. */
1606 FALSE
, /* Partial_inplace. */
1607 0, /* Source mask. */
1609 FALSE
), /* PC rel offset. */
1611 /* Store the value from the stack at the given address. Store it in
1612 a bitfield of size r_size starting at bit position r_offset. */
1613 HOWTO (ALPHA_R_OP_STORE
, /* Type. */
1614 0, /* Rightshift. */
1615 4, /* Size (0 = byte, 1 = short, 2 = long). */
1617 FALSE
, /* PC relative. */
1619 complain_overflow_dont
,/* Complain_on_overflow. */
1620 reloc_nil
, /* Special_function. */
1621 "OP_STORE", /* Name. */
1622 FALSE
, /* Partial_inplace. */
1623 0, /* Source mask. */
1624 MINUS_ONE
, /* Dest mask. */
1625 FALSE
), /* PC rel offset. */
1627 /* Subtract the reloc address from the value on the top of the
1628 relocation stack. */
1629 HOWTO (ALPHA_R_OP_PSUB
, /* Type. */
1630 0, /* Rightshift. */
1631 0, /* Size (0 = byte, 1 = short, 2 = long). */
1633 FALSE
, /* PC relative. */
1635 complain_overflow_dont
,/* Complain_on_overflow. */
1636 reloc_nil
, /* Special_function. */
1637 "OP_PSUB", /* Name. */
1638 FALSE
, /* Partial_inplace. */
1639 0, /* Source mask. */
1641 FALSE
), /* PC rel offset. */
1643 /* Shift the value on the top of the relocation stack right by the
1645 HOWTO (ALPHA_R_OP_PRSHIFT
, /* Type. */
1646 0, /* Rightshift. */
1647 0, /* Size (0 = byte, 1 = short, 2 = long). */
1649 FALSE
, /* PC relative. */
1651 complain_overflow_dont
,/* Complain_on_overflow. */
1652 reloc_nil
, /* Special_function. */
1653 "OP_PRSHIFT", /* Name. */
1654 FALSE
, /* Partial_inplace. */
1655 0, /* Source mask. */
1657 FALSE
), /* PC rel offset. */
1659 /* Hack. Linkage is done by linker. */
1660 HOWTO (ALPHA_R_LINKAGE
, /* Type. */
1661 0, /* Rightshift. */
1662 8, /* Size (0 = byte, 1 = short, 2 = long). */
1664 FALSE
, /* PC relative. */
1666 complain_overflow_dont
,/* Complain_on_overflow. */
1667 reloc_nil
, /* Special_function. */
1668 "LINKAGE", /* Name. */
1669 FALSE
, /* Partial_inplace. */
1670 0, /* Source mask. */
1672 FALSE
), /* PC rel offset. */
1674 /* A 32 bit reference to a symbol. */
1675 HOWTO (ALPHA_R_REFLONG
, /* Type. */
1676 0, /* Rightshift. */
1677 2, /* Size (0 = byte, 1 = short, 2 = long). */
1679 FALSE
, /* PC relative. */
1681 complain_overflow_bitfield
, /* Complain_on_overflow. */
1682 reloc_nil
, /* Special_function. */
1683 "REFLONG", /* Name. */
1684 TRUE
, /* Partial_inplace. */
1685 0xffffffff, /* Source mask. */
1686 0xffffffff, /* Dest mask. */
1687 FALSE
), /* PC rel offset. */
1689 /* A 64 bit reference to a procedure, written as 32 bit value. */
1690 HOWTO (ALPHA_R_CODEADDR
, /* Type. */
1691 0, /* Rightshift. */
1692 4, /* Size (0 = byte, 1 = short, 2 = long). */
1694 FALSE
, /* PC relative. */
1696 complain_overflow_signed
,/* Complain_on_overflow. */
1697 reloc_nil
, /* Special_function. */
1698 "CODEADDR", /* Name. */
1699 FALSE
, /* Partial_inplace. */
1700 0xffffffff, /* Source mask. */
1701 0xffffffff, /* Dest mask. */
1702 FALSE
), /* PC rel offset. */
1704 HOWTO (ALPHA_R_NOP
, /* Type. */
1705 0, /* Rightshift. */
1706 3, /* Size (0 = byte, 1 = short, 2 = long). */
1708 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
1709 because the calculations for the 3 relocations are the same.
1710 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
1711 TRUE
, /* PC relative. */
1713 complain_overflow_dont
,/* Complain_on_overflow. */
1714 reloc_nil
, /* Special_function. */
1716 FALSE
, /* Partial_inplace. */
1717 0xffffffff, /* Source mask. */
1718 0xffffffff, /* Dest mask. */
1719 FALSE
), /* PC rel offset. */
1721 HOWTO (ALPHA_R_BSR
, /* Type. */
1722 0, /* Rightshift. */
1723 3, /* Size (0 = byte, 1 = short, 2 = long). */
1725 TRUE
, /* PC relative. */
1727 complain_overflow_dont
,/* Complain_on_overflow. */
1728 reloc_nil
, /* Special_function. */
1730 FALSE
, /* Partial_inplace. */
1731 0xffffffff, /* Source mask. */
1732 0xffffffff, /* Dest mask. */
1733 FALSE
), /* PC rel offset. */
1735 HOWTO (ALPHA_R_LDA
, /* Type. */
1736 0, /* Rightshift. */
1737 3, /* Size (0 = byte, 1 = short, 2 = long). */
1739 FALSE
, /* PC relative. */
1741 complain_overflow_dont
,/* Complain_on_overflow. */
1742 reloc_nil
, /* Special_function. */
1744 FALSE
, /* Partial_inplace. */
1745 0xffffffff, /* Source mask. */
1746 0xffffffff, /* Dest mask. */
1747 FALSE
), /* PC rel offset. */
1749 HOWTO (ALPHA_R_BOH
, /* Type. */
1750 0, /* Rightshift. */
1751 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
1753 TRUE
, /* PC relative. */
1755 complain_overflow_dont
,/* Complain_on_overflow. */
1756 reloc_nil
, /* Special_function. */
1758 FALSE
, /* Partial_inplace. */
1759 0xffffffff, /* Source mask. */
1760 0xffffffff, /* Dest mask. */
1761 FALSE
), /* PC rel offset. */
1764 /* Return a pointer to a howto structure which, when invoked, will perform
1765 the relocation code on data from the architecture noted. */
1767 static const struct reloc_howto_struct
*
1768 vms_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1769 bfd_reloc_code_real_type code
)
1774 vms_debug (1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd
, code
);
1779 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1780 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1781 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1782 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1783 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1784 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1785 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1786 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1787 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1788 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1789 case BFD_RELOC_ALPHA_CODEADDR
: alpha_type
= ALPHA_R_CODEADDR
; break;
1790 case BFD_RELOC_ALPHA_NOP
: alpha_type
= ALPHA_R_NOP
; break;
1791 case BFD_RELOC_ALPHA_BSR
: alpha_type
= ALPHA_R_BSR
; break;
1792 case BFD_RELOC_ALPHA_LDA
: alpha_type
= ALPHA_R_LDA
; break;
1793 case BFD_RELOC_ALPHA_BOH
: alpha_type
= ALPHA_R_BOH
; break;
1795 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1799 vms_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1801 return & alpha_howto_table
[alpha_type
];
1804 static reloc_howto_type
*
1805 vms_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1811 i
< sizeof (alpha_howto_table
) / sizeof (alpha_howto_table
[0]);
1813 if (alpha_howto_table
[i
].name
!= NULL
1814 && strcasecmp (alpha_howto_table
[i
].name
, r_name
) == 0)
1815 return &alpha_howto_table
[i
];
1820 /* Part 4.7, writing an object file. */
1822 /* Set the architecture and machine type in BFD abfd to arch and mach.
1823 Find the correct pointer to a structure and insert it into the arch_info
1827 vms_set_arch_mach (bfd
* abfd
,
1828 enum bfd_architecture arch ATTRIBUTE_UNUSED
,
1829 unsigned long mach ATTRIBUTE_UNUSED
)
1832 vms_debug (1, "vms_set_arch_mach (%p, %d, %ld)\n", abfd
, arch
, mach
);
1835 if (arch
!= bfd_arch_alpha
1836 && arch
!= bfd_arch_vax
1837 && arch
!= bfd_arch_unknown
)
1840 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
1843 /* Sets the contents of the section section in BFD abfd to the data starting
1844 in memory at LOCATION. The data is written to the output section starting
1845 at offset offset for count bytes.
1847 Normally TRUE is returned, else FALSE. Possible error returns are:
1848 o bfd_error_no_contents - The output section does not have the
1849 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1850 o and some more too */
1853 vms_set_section_contents (bfd
* abfd
,
1855 const void * location
,
1857 bfd_size_type count
)
1860 vms_debug (1, "vms_set_section_contents (%p, sec %s, loc %p, off %ld, count %d)\n",
1861 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1862 vms_debug (2, "size %d\n", (int) section
->size
);
1864 if (count
== (bfd_size_type
)0)
1867 if (section
->contents
== NULL
)
1868 section
->contents
= bfd_alloc (abfd
, section
->size
);
1869 if (section
->contents
== NULL
)
1872 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
1876 /* Part 4.8, linker. */
1878 /* Get the size of the section headers. */
1881 vms_sizeof_headers (bfd
* abfd ATTRIBUTE_UNUSED
,
1882 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1885 vms_debug (1, "vms_sizeof_headers (%p, %s)\n", abfd
, (reloc
)?"True":"False");
1890 /* Provides default handling of relocation effort for back ends
1891 which can't be bothered to do it efficiently. */
1894 vms_bfd_get_relocated_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
1895 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1896 struct bfd_link_order
*link_order ATTRIBUTE_UNUSED
,
1897 bfd_byte
*data ATTRIBUTE_UNUSED
,
1898 bfd_boolean relocatable ATTRIBUTE_UNUSED
,
1899 asymbol
**symbols ATTRIBUTE_UNUSED
)
1902 vms_debug (1, "vms_bfd_get_relocated_section_contents (%p, %p, %p, %p, %s, %p)\n",
1903 abfd
, link_info
, link_order
, data
, (relocatable
)?"True":"False", symbols
);
1911 vms_bfd_relax_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1912 asection
*section ATTRIBUTE_UNUSED
,
1913 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1914 bfd_boolean
*again ATTRIBUTE_UNUSED
)
1917 vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, <ret>)\n",
1918 abfd
, section
->name
, link_info
);
1924 vms_bfd_gc_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1925 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1928 vms_debug (1, "vms_bfd_gc_sections (%p, %p)\n", abfd
, link_info
);
1934 vms_bfd_merge_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1935 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1938 vms_debug (1, "vms_bfd_merge_sections (%p, %p)\n", abfd
, link_info
);
1943 /* Create a hash table for the linker. Different backends store
1944 different information in this table. */
1946 static struct bfd_link_hash_table
*
1947 vms_bfd_link_hash_table_create (bfd
* abfd ATTRIBUTE_UNUSED
)
1950 vms_debug (1, "vms_bfd_link_hash_table_create (%p)\n", abfd
);
1955 /* Free a linker hash table. */
1958 vms_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash ATTRIBUTE_UNUSED
)
1961 vms_debug (1, "vms_bfd_link_hash_table_free (%p)\n", abfd
);
1965 /* Add symbols from this object file into the hash table. */
1968 vms_bfd_link_add_symbols (bfd
* abfd ATTRIBUTE_UNUSED
,
1969 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1972 vms_debug (1, "vms_bfd_link_add_symbols (%p, %p)\n", abfd
, link_info
);
1977 /* Do a link based on the link_order structures attached to each
1978 section of the BFD. */
1981 vms_bfd_final_link (bfd
* abfd ATTRIBUTE_UNUSED
,
1982 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1985 vms_debug (1, "vms_bfd_final_link (%p, %p)\n", abfd
, link_info
);
1990 /* Should this section be split up into smaller pieces during linking. */
1993 vms_bfd_link_split_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1994 asection
*section ATTRIBUTE_UNUSED
)
1997 vms_debug (1, "vms_bfd_link_split_section (%p, %s)\n", abfd
, section
->name
);
2002 /* Part 4.9, dynamic symbols and relocations. */
2004 /* Get the amount of memory required to hold the dynamic symbols. */
2007 vms_get_dynamic_symtab_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2010 vms_debug (1, "vms_get_dynamic_symtab_upper_bound (%p)\n", abfd
);
2016 vms_bfd_print_private_bfd_data (bfd
* abfd ATTRIBUTE_UNUSED
,
2017 void *file ATTRIBUTE_UNUSED
)
2020 vms_debug (1, "vms_bfd_print_private_bfd_data (%p)\n", abfd
);
2025 /* Read in the dynamic symbols. */
2028 vms_canonicalize_dynamic_symtab (bfd
* abfd ATTRIBUTE_UNUSED
,
2029 asymbol
**symbols ATTRIBUTE_UNUSED
)
2032 vms_debug (1, "vms_canonicalize_dynamic_symtab (%p, <ret>)\n", abfd
);
2037 /* Get the amount of memory required to hold the dynamic relocs. */
2040 vms_get_dynamic_reloc_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2043 vms_debug (1, "vms_get_dynamic_reloc_upper_bound (%p)\n", abfd
);
2048 /* Read in the dynamic relocs. */
2051 vms_canonicalize_dynamic_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
2052 arelent
**arel ATTRIBUTE_UNUSED
,
2053 asymbol
**symbols ATTRIBUTE_UNUSED
)
2056 vms_debug (1, "vms_canonicalize_dynamic_reloc (%p)\n", abfd
);
2061 const bfd_target vms_alpha_vec
=
2063 "vms-alpha", /* Name. */
2064 bfd_target_evax_flavour
,
2065 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2066 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2068 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
2069 | WP_TEXT
| D_PAGED
), /* Object flags. */
2070 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2071 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2072 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2073 0, /* symbol_leading_char. */
2074 ' ', /* ar_pad_char. */
2075 15, /* ar_max_namelen. */
2076 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2077 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2078 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2079 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2080 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2081 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2083 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2084 vms_archive_p
, _bfd_dummy_target
},
2085 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2086 _bfd_generic_mkarchive
, bfd_false
},
2087 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2088 _bfd_write_archive_contents
, bfd_false
},
2090 BFD_JUMP_TABLE_GENERIC (vms
),
2091 BFD_JUMP_TABLE_COPY (vms
),
2092 BFD_JUMP_TABLE_CORE (vms
),
2093 BFD_JUMP_TABLE_ARCHIVE (vms
),
2094 BFD_JUMP_TABLE_SYMBOLS (vms
),
2095 BFD_JUMP_TABLE_RELOCS (vms
),
2096 BFD_JUMP_TABLE_WRITE (vms
),
2097 BFD_JUMP_TABLE_LINK (vms
),
2098 BFD_JUMP_TABLE_DYNAMIC (vms
),
2105 const bfd_target vms_vax_vec
=
2107 "vms-vax", /* Name. */
2108 bfd_target_ovax_flavour
,
2109 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2110 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2112 (HAS_RELOC
| HAS_SYMS
/* Object flags. */
2114 | HAS_LINENO
| HAS_DEBUG
| HAS_LOCALS
),
2116 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2117 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2118 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2119 0, /* symbol_leading_char */
2120 ' ', /* ar_pad_char */
2121 15, /* ar_max_namelen */
2122 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2123 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2124 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
2125 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2126 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2127 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
2129 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2130 vms_archive_p
, _bfd_dummy_target
},
2131 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2132 _bfd_generic_mkarchive
, bfd_false
},
2133 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2134 _bfd_write_archive_contents
, bfd_false
},
2136 BFD_JUMP_TABLE_GENERIC (vms
),
2137 BFD_JUMP_TABLE_COPY (vms
),
2138 BFD_JUMP_TABLE_CORE (vms
),
2139 BFD_JUMP_TABLE_ARCHIVE (vms
),
2140 BFD_JUMP_TABLE_SYMBOLS (vms
),
2141 BFD_JUMP_TABLE_RELOCS (vms
),
2142 BFD_JUMP_TABLE_WRITE (vms
),
2143 BFD_JUMP_TABLE_LINK (vms
),
2144 BFD_JUMP_TABLE_DYNAMIC (vms
),