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 (bfd
*abfd
, asymbol
**symbols
);
133 static long vms_get_dynamic_reloc_upper_bound (bfd
*abfd
);
134 static long vms_canonicalize_dynamic_reloc
135 (bfd
*abfd
, arelent
**arel
, asymbol
**symbols
);
136 static bfd_boolean
vms_bfd_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
);
137 static bfd_boolean
vms_bfd_set_private_flags (bfd
*abfd
, flagword flags
);
139 #define vms_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
140 #define vms_make_empty_symbol _bfd_generic_make_empty_symbol
141 #define vms_bfd_link_just_syms _bfd_generic_link_just_syms
142 #define vms_bfd_is_group_section bfd_generic_is_group_section
143 #define vms_bfd_discard_group bfd_generic_discard_group
144 #define vms_section_already_linked _bfd_generic_section_already_linked
145 #define vms_bfd_define_common_symbol bfd_generic_define_common_symbol
146 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
147 #define vms_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
151 /* Cause debug info to be emitted for the structure. */
152 struct vms_private_data_struct _vms_private_data_struct_dummy
;
153 struct vms_section_data_struct _vms_section_data_struct_dummy
;
156 extern const bfd_target vms_vax_vec
;
157 extern const bfd_target vms_alpha_vec
;
159 /* Initialize private data */
161 vms_initialize (bfd
* abfd
)
165 bfd_set_start_address (abfd
, (bfd_vma
) -1);
167 amt
= sizeof (struct vms_private_data_struct
);
168 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
169 if (abfd
->tdata
.any
== NULL
)
172 if (bfd_get_flavour (abfd
) == bfd_target_ovax_flavour
)
173 PRIV (is_vax
) = TRUE
;
175 PRIV (file_format
) = FF_UNKNOWN
;
177 amt
= sizeof (struct stack_struct
) * STACKSIZE
;
178 PRIV (stack
) = bfd_alloc (abfd
, amt
);
179 if (PRIV (stack
) == NULL
)
182 amt
= sizeof (struct bfd_hash_table
);
183 PRIV (vms_symbol_table
) = bfd_alloc (abfd
, amt
);
184 if (PRIV (vms_symbol_table
) == NULL
)
187 if (!bfd_hash_table_init (PRIV (vms_symbol_table
), _bfd_vms_hash_newfunc
,
188 sizeof (vms_symbol_entry
)))
191 amt
= MAX_OUTREC_SIZE
;
192 PRIV (output_buf
) = bfd_alloc (abfd
, amt
);
193 if (PRIV (output_buf
) == NULL
)
196 PRIV (length_pos
) = 2;
201 bfd_hash_table_free (PRIV (vms_symbol_table
));
203 bfd_release (abfd
, abfd
->tdata
.any
);
204 abfd
->tdata
.any
= NULL
;
210 unsigned int section_count
;
214 /* Fill symbol->section with section pointer.
216 symbol->section is filled with the section index for defined symbols
217 during reading the GSD/EGSD section. But we need the pointer to the
220 It has the correct value for referenced (undefined section) symbols.
222 Called from bfd_hash_traverse in vms_fixup_sections. */
225 fill_section_ptr (struct bfd_hash_entry
*entry
, void *sections
)
227 asymbol
*sym
= ((vms_symbol_entry
*)entry
)->symbol
;
228 struct pair
*data
= (struct pair
*)sections
;
229 unsigned long sec
= (unsigned long)sym
->section
;
232 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym
, sec
);
235 if (sec
< data
->section_count
)
237 sym
->section
= data
->sections
[sec
];
239 if (strcmp (sym
->name
, sym
->section
->name
) == 0)
240 sym
->flags
|= BSF_SECTION_SYM
;
242 else if (sec
== (unsigned long)-1)
243 sym
->section
= &bfd_und_section
;
248 /* Fixup section pointers in symbols. */
250 vms_fixup_sections (bfd
* abfd
)
254 if (PRIV (fixup_done
))
257 data
.section_count
= PRIV (section_count
);
258 data
.sections
= PRIV (sections
);
259 bfd_hash_traverse (PRIV (vms_symbol_table
), fill_section_ptr
, &data
);
261 PRIV (fixup_done
) = TRUE
;
265 /* Slurp an ordered set of VMS object records. */
267 _bfd_vms_slurp_object_records (bfd
* abfd
)
269 int err
, new_type
, type
= -1;
274 vms_debug (7, "reading at %08lx\n", bfd_tell (abfd
));
276 new_type
= _bfd_vms_get_object_record (abfd
);
280 vms_debug (2, "next_record failed\n");
285 if (type
== EOBJ_S_C_EGSD
&& new_type
!= EOBJ_S_C_EGSD
)
287 if (! vms_fixup_sections (abfd
))
290 vms_debug (2, "vms_fixup_sections failed\n");
302 err
= _bfd_vms_slurp_hdr (abfd
, type
);
307 err
= _bfd_vms_slurp_eom (abfd
, type
);
311 err
= _bfd_vms_slurp_gsd (abfd
, type
);
315 err
= _bfd_vms_slurp_tir (abfd
, type
);
319 err
= _bfd_vms_slurp_dbg (abfd
, type
);
320 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
324 err
= _bfd_vms_slurp_tbt (abfd
, type
);
325 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
328 err
= _bfd_vms_slurp_lnk (abfd
, type
);
336 vms_debug (2, "slurp type %d failed with %d\n", type
, err
);
341 while (type
!= EOBJ_S_C_EEOM
&& type
!= OBJ_S_C_EOM
&& type
!= OBJ_S_C_EOMW
);
346 /* Slurp a VMS module and return an error status. */
349 vms_slurp_module (bfd
*abfd
)
354 type
= PRIV (vms_rec
)[0];
356 type
= bfd_getl16 (PRIV (vms_rec
));
358 err
= _bfd_vms_slurp_hdr (abfd
, type
);
361 bfd_set_error (bfd_error_wrong_format
);
365 return _bfd_vms_slurp_object_records (abfd
);
368 /* Slurp a VMS image and return an error status. */
371 vms_slurp_image (bfd
*abfd
)
373 unsigned int isd_offset
, ihs_offset
;
376 err
= _bfd_vms_slurp_ihd (abfd
, &isd_offset
, &ihs_offset
);
379 bfd_set_error (bfd_error_wrong_format
);
383 err
= _bfd_vms_slurp_isd (abfd
, isd_offset
);
386 bfd_set_error (bfd_error_wrong_format
);
390 return _bfd_vms_slurp_ihs (abfd
, ihs_offset
);
393 /* Check the format for a file being read.
394 Return a (bfd_target *) if it's an object file or zero if not. */
396 static const struct bfd_target
*
397 vms_object_p (bfd
*abfd
)
399 const struct bfd_target
*target_vector
;
400 const bfd_arch_info_type
*arch
;
401 PTR tdata_save
= abfd
->tdata
.any
;
402 bfd_vma saddr_save
= bfd_get_start_address (abfd
);
406 vms_debug (1, "vms_object_p(%p)\n", abfd
);
409 if (!vms_initialize (abfd
))
412 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
))
413 goto err_wrong_format
;
415 switch (_bfd_vms_get_first_record (abfd
))
423 err
= vms_slurp_module (abfd
);
427 err
= vms_slurp_image (abfd
);
432 goto err_wrong_format
;
436 if (! vms_fixup_sections (abfd
))
439 vms_debug (2, "vms_fixup_sections failed\n");
441 goto err_wrong_format
;
444 target_vector
= &vms_vax_vec
;
445 arch
= bfd_scan_arch ("vax");
448 vms_debug (2, "arch is vax\n");
453 /* Set arch_info to alpha. */
454 target_vector
= &vms_alpha_vec
;
455 arch
= bfd_scan_arch ("alpha");
457 vms_debug (2, "arch is alpha\n");
461 abfd
->arch_info
= arch
;
462 return target_vector
;
465 bfd_set_error (bfd_error_wrong_format
);
468 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
469 bfd_release (abfd
, abfd
->tdata
.any
);
470 abfd
->tdata
.any
= tdata_save
;
471 bfd_set_start_address (abfd
, saddr_save
);
475 /* Check the format for a file being read.
476 Return a (bfd_target *) if it's an archive file or zero. */
478 static const struct bfd_target
*
479 vms_archive_p (bfd
* abfd ATTRIBUTE_UNUSED
)
482 vms_debug (1, "vms_archive_p (%p)\n", abfd
);
488 /* Set the format of a file being written. */
491 vms_mkobject (bfd
* abfd
)
493 const bfd_arch_info_type
*arch
;
496 vms_debug (1, "vms_mkobject (%p)\n", abfd
);
499 if (!vms_initialize (abfd
))
503 arch
= bfd_scan_arch ("vax");
505 arch
= bfd_scan_arch ("alpha");
509 bfd_set_error(bfd_error_wrong_format
);
513 abfd
->arch_info
= arch
;
517 /* Write cached information into a file being written, at bfd_close. */
520 vms_write_object_contents (bfd
* abfd
)
523 vms_debug (1, "vms_write_object_contents (%p)\n", abfd
);
526 if (abfd
->section_count
> 0) /* we have sections */
530 if (_bfd_vms_write_hdr (abfd
, OBJ_S_C_HDR
) != 0)
532 if (_bfd_vms_write_gsd (abfd
, OBJ_S_C_GSD
) != 0)
534 if (_bfd_vms_write_tir (abfd
, OBJ_S_C_TIR
) != 0)
536 if (_bfd_vms_write_tbt (abfd
, OBJ_S_C_TBT
) != 0)
538 if (_bfd_vms_write_dbg (abfd
, OBJ_S_C_DBG
) != 0)
540 if (abfd
->section_count
> 255)
542 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOMW
) != 0)
547 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOM
) != 0)
553 if (_bfd_vms_write_hdr (abfd
, EOBJ_S_C_EMH
) != 0)
555 if (_bfd_vms_write_gsd (abfd
, EOBJ_S_C_EGSD
) != 0)
557 if (_bfd_vms_write_tir (abfd
, EOBJ_S_C_ETIR
) != 0)
559 if (_bfd_vms_write_tbt (abfd
, EOBJ_S_C_ETBT
) != 0)
561 if (_bfd_vms_write_dbg (abfd
, EOBJ_S_C_EDBG
) != 0)
563 if (_bfd_vms_write_eom (abfd
, EOBJ_S_C_EEOM
) != 0)
572 /* Free the reloc buffer for the specified section. */
575 free_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
576 void *data ATTRIBUTE_UNUSED
)
578 if (vms_section_data (section
)->reloc_stream
)
579 free (vms_section_data (section
)->reloc_stream
);
583 /* Convert the file to variable record length format. This is done
584 using undocumented system call sys$modify().
588 vms_convert_to_var (char *vms_filename
)
590 struct FAB fab
= cc$rms_fab
;
592 fab
.fab$l_fna
= vms_filename
;
593 fab
.fab$b_fns
= strlen (vms_filename
);
594 fab
.fab$b_fac
= FAB$M_PUT
;
595 fab
.fab$l_fop
= FAB$M_ESC
;
596 fab
.fab$l_ctx
= RME$C_SETRFM
;
600 fab
.fab$b_rfm
= FAB$C_VAR
;
607 vms_convert_to_var_1 (char *filename
, int type
)
609 if (type
!= DECC$K_FILE
)
611 vms_convert_to_var (filename
);
615 /* Convert the file to variable record length format. This is done
616 using undocumented system call sys$modify().
617 Unix filename version. */
620 vms_convert_to_var_unix_filename (const char *unix_filename
)
622 if (decc$
to_vms (unix_filename
, &vms_convert_to_var_1
, 0, 1) != 1)
628 /* Called when the BFD is being closed to do any necessary cleanup. */
631 vms_close_and_cleanup (bfd
* abfd
)
634 vms_debug (1, "vms_close_and_cleanup (%p)\n", abfd
);
636 if (abfd
== NULL
|| abfd
->tdata
.any
== NULL
)
639 if (PRIV (vms_buf
) != NULL
)
640 free (PRIV (vms_buf
));
642 if (PRIV (sections
) != NULL
)
643 free (PRIV (sections
));
645 if (PRIV (vms_symbol_table
))
646 bfd_hash_table_free (PRIV (vms_symbol_table
));
648 bfd_map_over_sections (abfd
, free_reloc_stream
, NULL
);
650 bfd_release (abfd
, abfd
->tdata
.any
);
651 abfd
->tdata
.any
= NULL
;
654 if (abfd
->direction
== write_direction
)
656 /* Last step on VMS is to convert the file to variable record length
658 if (bfd_cache_close (abfd
) != TRUE
)
660 if (vms_convert_to_var_unix_filename (abfd
->filename
) != TRUE
)
668 /* Ask the BFD to free all cached information. */
671 vms_bfd_free_cached_info (bfd
* abfd ATTRIBUTE_UNUSED
)
674 vms_debug (1, "vms_bfd_free_cached_info (%p)\n", abfd
);
679 /* Called when a new section is created. */
682 vms_new_section_hook (bfd
* abfd
, asection
*section
)
686 /* Count hasn't been incremented yet. */
687 unsigned int section_count
= abfd
->section_count
+ 1;
690 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
691 abfd
, section
->index
, section
->name
, section_count
);
694 bfd_set_section_alignment (abfd
, section
, 0);
696 if (section_count
> PRIV (section_count
))
698 bfd_size_type amt
= section_count
;
699 amt
*= sizeof (asection
*);
700 PRIV (sections
) = bfd_realloc_or_free (PRIV (sections
), amt
);
701 if (PRIV (sections
) == NULL
)
703 PRIV (section_count
) = section_count
;
707 vms_debug (6, "section_count: %d\n", PRIV (section_count
));
710 PRIV (sections
)[section
->index
] = section
;
713 vms_debug (7, "%d: %s\n", section
->index
, section
->name
);
716 amt
= sizeof (struct vms_section_data_struct
);
717 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
718 if (section
->used_by_bfd
== NULL
)
721 return _bfd_generic_new_section_hook (abfd
, section
);
724 /* Read the contents of a section.
725 buf points to a buffer of buf_size bytes to be filled with
726 section data (starting at offset into section) */
729 vms_get_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
730 asection
*section ATTRIBUTE_UNUSED
,
731 void * buf ATTRIBUTE_UNUSED
,
732 file_ptr offset ATTRIBUTE_UNUSED
,
733 bfd_size_type buf_size ATTRIBUTE_UNUSED
)
735 bfd_size_type size
= section
->size
;
738 vms_debug (1, "vms_get_section_contents (%p, %s, %p, off %ld, size %d)\n",
739 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
742 if (section
->contents
)
745 section
->contents
= (unsigned char *) bfd_malloc (size
);
747 if (section
->contents
== NULL
)
749 bfd_set_error (bfd_error_no_memory
);
753 if (bfd_seek (abfd
, section
->filepos
, SEEK_SET
))
755 bfd_set_error (bfd_error_file_truncated
);
759 if (bfd_bread (section
->contents
, size
, abfd
) != size
)
761 bfd_set_error (bfd_error_file_truncated
);
765 section
->flags
|= SEC_IN_MEMORY
;
768 memcpy (buf
, section
->contents
+ offset
, (size_t) buf_size
);
773 /* Read the contents of a section.
774 buf points to a buffer of buf_size bytes to be filled with
775 section data (starting at offset into section). */
778 vms_get_section_contents_in_window (bfd
* abfd ATTRIBUTE_UNUSED
,
779 asection
*section ATTRIBUTE_UNUSED
,
780 bfd_window
*w ATTRIBUTE_UNUSED
,
781 file_ptr offset ATTRIBUTE_UNUSED
,
782 bfd_size_type count ATTRIBUTE_UNUSED
)
785 vms_debug (1, "vms_get_section_contents_in_window (%p, %s, %p, off %ld, count %d)\n",
786 abfd
, section
->name
, w
, offset
, (int)count
);
789 /* Shouldn't be called, since all sections are IN_MEMORY. */
793 /* Part 4.2, copy private data. */
795 /* Called to copy BFD general private data from one object file
799 vms_bfd_copy_private_bfd_data (bfd
*src ATTRIBUTE_UNUSED
,
800 bfd
*dest ATTRIBUTE_UNUSED
)
803 vms_debug (1, "vms_bfd_copy_private_bfd_data (%p, %p)\n", src
, dest
);
808 /* Merge private BFD information from the BFD @var{ibfd} to the
809 the output file BFD @var{obfd} when linking. Return <<TRUE>>
810 on success, <<FALSE>> on error. Possible error returns are:
812 o <<bfd_error_no_memory>> -
813 Not enough memory exists to create private data for @var{obfd}. */
816 vms_bfd_merge_private_bfd_data (bfd
* ibfd ATTRIBUTE_UNUSED
,
817 bfd
* obfd ATTRIBUTE_UNUSED
)
820 vms_debug (1,"vms_bfd_merge_private_bfd_data (%p, %p)\n", ibfd
, obfd
);
825 /* Set private BFD flag information in the BFD @var{abfd}.
826 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
829 o <<bfd_error_no_memory>> -
830 Not enough memory exists to create private data for @var{obfd}. */
833 vms_bfd_set_private_flags (bfd
* abfd ATTRIBUTE_UNUSED
,
834 flagword flags ATTRIBUTE_UNUSED
)
837 vms_debug (1,"vms_bfd_set_private_flags (%p, %lx)\n", abfd
, (long)flags
);
842 /* Called to copy BFD private section data from one object file
846 vms_bfd_copy_private_section_data (bfd
*srcbfd ATTRIBUTE_UNUSED
,
847 asection
*srcsec ATTRIBUTE_UNUSED
,
848 bfd
*dstbfd ATTRIBUTE_UNUSED
,
849 asection
*dstsec ATTRIBUTE_UNUSED
)
852 vms_debug (1, "vms_bfd_copy_private_section_data (%p, %s, %p, %s)\n",
853 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
858 /* Called to copy BFD private symbol data from one object file
862 vms_bfd_copy_private_symbol_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
863 asymbol
*isym ATTRIBUTE_UNUSED
,
864 bfd
*obfd ATTRIBUTE_UNUSED
,
865 asymbol
*osym ATTRIBUTE_UNUSED
)
868 vms_debug (1, "vms_bfd_copy_private_symbol_data (%p, %s, %p, %s)\n",
869 ibfd
, isym
->name
, obfd
, osym
->name
);
874 /* Part 4.3, core file. */
876 /* Return a read-only string explaining which program was running
877 when it failed and produced the core file abfd. */
880 vms_core_file_failing_command (bfd
* abfd ATTRIBUTE_UNUSED
)
883 vms_debug (1, "vms_core_file_failing_command (%p)\n", abfd
);
888 /* Returns the signal number which caused the core dump which
889 generated the file the BFD abfd is attached to. */
892 vms_core_file_failing_signal (bfd
* abfd ATTRIBUTE_UNUSED
)
895 vms_debug (1, "vms_core_file_failing_signal (%p)\n", abfd
);
900 /* Return TRUE if the core file attached to core_bfd was generated
901 by a run of the executable file attached to exec_bfd, FALSE otherwise. */
904 vms_core_file_matches_executable_p (bfd
* abfd ATTRIBUTE_UNUSED
,
905 bfd
*bbfd ATTRIBUTE_UNUSED
)
908 vms_debug (1, "vms_core_file_matches_executable_p (%p, %p)\n", abfd
, bbfd
);
913 /* Part 4.4, archive. */
915 /* ??? do something with an archive map.
916 Return FALSE on error, TRUE otherwise. */
919 vms_slurp_armap (bfd
* abfd ATTRIBUTE_UNUSED
)
922 vms_debug (1, "vms_slurp_armap (%p)\n", abfd
);
927 /* ??? do something with an extended name table.
928 Return FALSE on error, TRUE otherwise. */
931 vms_slurp_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
)
934 vms_debug (1, "vms_slurp_extended_name_table (%p)\n", abfd
);
939 /* ??? do something with an extended name table.
940 Return FALSE on error, TRUE otherwise. */
943 vms_construct_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
,
944 char **tabloc ATTRIBUTE_UNUSED
,
945 bfd_size_type
*tablen ATTRIBUTE_UNUSED
,
946 const char **name ATTRIBUTE_UNUSED
)
949 vms_debug (1, "vms_construct_extended_name_table (%p)\n", abfd
);
954 /* Truncate the name of an archive to match system-dependent restrictions. */
957 vms_truncate_arname (bfd
* abfd ATTRIBUTE_UNUSED
,
958 const char *pathname ATTRIBUTE_UNUSED
,
959 char *arhdr ATTRIBUTE_UNUSED
)
962 vms_debug (1, "vms_truncate_arname (%p, %s, %s)\n", abfd
, pathname
, arhdr
);
966 /* ??? write archive map. */
969 vms_write_armap (bfd
*arch ATTRIBUTE_UNUSED
,
970 unsigned int elength ATTRIBUTE_UNUSED
,
971 struct orl
*map ATTRIBUTE_UNUSED
,
972 unsigned int orl_count ATTRIBUTE_UNUSED
,
973 int stridx ATTRIBUTE_UNUSED
)
976 vms_debug (1, "vms_write_armap (%p, %d, %p, %d %d)\n",
977 arch
, elength
, map
, orl_count
, stridx
);
982 /* Read archive header ??? */
985 vms_read_ar_hdr (bfd
* abfd ATTRIBUTE_UNUSED
)
988 vms_debug (1, "vms_read_ar_hdr (%p)\n", abfd
);
993 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
994 an input BFD on the first contained element and returns that.
995 Subsequent calls should pass the archive and the previous return value
996 to return a created BFD to the next contained element.
997 NULL is returned when there are no more. */
1000 vms_openr_next_archived_file (bfd
*arch ATTRIBUTE_UNUSED
,
1001 bfd
*prev ATTRIBUTE_UNUSED
)
1004 vms_debug (1, "vms_openr_next_archived_file (%p, %p)\n", arch
, prev
);
1009 /* Return the BFD which is referenced by the symbol in ABFD indexed by
1010 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
1013 vms_get_elt_at_index (bfd
* abfd
, symindex index
)
1016 vms_debug (1, "vms_get_elt_at_index (%p, %p)\n", abfd
, index
);
1018 return _bfd_generic_get_elt_at_index (abfd
, index
);
1022 -> bfd_generic_stat_arch_elt. */
1025 vms_generic_stat_arch_elt (bfd
* abfd
, struct stat
*st
)
1028 vms_debug (1, "vms_generic_stat_arch_elt (%p, %p)\n", abfd
, st
);
1030 return bfd_generic_stat_arch_elt (abfd
, st
);
1033 /* This is a new function in bfd 2.5. */
1036 vms_update_armap_timestamp (bfd
* abfd ATTRIBUTE_UNUSED
)
1039 vms_debug (1, "vms_update_armap_timestamp (%p)\n", abfd
);
1044 /* Part 4.5, symbols. */
1046 /* Return the number of bytes required to store a vector of pointers
1047 to asymbols for all the symbols in the BFD abfd, including a
1048 terminal NULL pointer. If there are no symbols in the BFD,
1049 then return 0. If an error occurs, return -1. */
1052 vms_get_symtab_upper_bound (bfd
* abfd
)
1055 vms_debug (1, "vms_get_symtab_upper_bound (%p), %d symbols\n", abfd
, PRIV (gsd_sym_count
));
1057 return (PRIV (gsd_sym_count
) + 1) * sizeof (asymbol
*);
1060 /* Copy symbols from hash table to symbol vector
1062 called from bfd_hash_traverse in vms_canonicalize_symtab
1063 init counter to 0 if entry == 0. */
1066 copy_symbols (struct bfd_hash_entry
*entry
, void * arg
)
1068 bfd
* abfd
= (bfd
*) arg
;
1070 if (entry
== NULL
) /* Init counter. */
1072 else /* Fill vector, inc counter. */
1073 PRIV (symcache
)[PRIV (symnum
)++] = ((vms_symbol_entry
*)entry
)->symbol
;
1078 /* Read the symbols from the BFD abfd, and fills in the vector
1079 location with pointers to the symbols and a trailing NULL.
1081 Return number of symbols read. */
1084 vms_canonicalize_symtab (bfd
* abfd
, asymbol
**symbols
)
1087 vms_debug (1, "vms_canonicalize_symtab (%p, <ret>)\n", abfd
);
1091 copy_symbols (NULL
, abfd
);
1093 /* Traverse table and fill symbols vector. */
1094 PRIV (symcache
) = symbols
;
1095 bfd_hash_traverse (PRIV (vms_symbol_table
), copy_symbols
, abfd
);
1097 symbols
[PRIV (gsd_sym_count
)] = NULL
;
1099 return PRIV (gsd_sym_count
);
1102 /* Print symbol to file according to how. how is one of
1103 bfd_print_symbol_name just print the name
1104 bfd_print_symbol_more print more (???)
1105 bfd_print_symbol_all print all we know, which is not much right now :-). */
1108 vms_print_symbol (bfd
* abfd
,
1111 bfd_print_symbol_type how
)
1114 vms_debug (1, "vms_print_symbol (%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1119 case bfd_print_symbol_name
:
1120 case bfd_print_symbol_more
:
1121 fprintf ((FILE *)file
," %s", symbol
->name
);
1124 case bfd_print_symbol_all
:
1126 const char *section_name
= symbol
->section
->name
;
1128 bfd_print_symbol_vandf (abfd
, file
, symbol
);
1130 fprintf ((FILE *) file
," %-8s %s", section_name
, symbol
->name
);
1136 /* Return information about symbol in ret.
1138 fill type, value and name
1141 B bss segment symbol
1143 D data segment symbol
1145 t a static function symbol
1146 T text segment symbol
1151 vms_get_symbol_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1158 vms_debug (1, "vms_get_symbol_info (%p, %p, %p)\n", abfd
, symbol
, ret
);
1161 sec
= symbol
->section
;
1168 else if (bfd_is_com_section (sec
))
1170 else if (bfd_is_abs_section (sec
))
1172 else if (bfd_is_und_section (sec
))
1174 else if (bfd_is_ind_section (sec
))
1176 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1178 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1180 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1185 if (ret
->type
!= 'U')
1186 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1189 ret
->name
= symbol
->name
;
1192 /* Return TRUE if the given symbol sym in the BFD abfd is
1193 a compiler generated local label, else return FALSE. */
1196 vms_bfd_is_local_label_name (bfd
* abfd ATTRIBUTE_UNUSED
,
1200 vms_debug (1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd
, name
);
1202 return name
[0] == '$';
1205 /* Get source line number for symbol. */
1208 vms_get_lineno (bfd
* abfd ATTRIBUTE_UNUSED
,
1209 asymbol
*symbol ATTRIBUTE_UNUSED
)
1212 vms_debug (1, "vms_get_lineno (%p, %p)\n", abfd
, symbol
);
1217 /* Provided a BFD, a section and an offset into the section, calculate and
1218 return the name of the source file and the line nearest to the wanted
1222 vms_find_nearest_line (bfd
* abfd ATTRIBUTE_UNUSED
,
1223 asection
*section ATTRIBUTE_UNUSED
,
1224 asymbol
**symbols ATTRIBUTE_UNUSED
,
1225 bfd_vma offset ATTRIBUTE_UNUSED
,
1226 const char **file ATTRIBUTE_UNUSED
,
1227 const char **func ATTRIBUTE_UNUSED
,
1228 unsigned int *line ATTRIBUTE_UNUSED
)
1231 vms_debug (1, "vms_find_nearest_line (%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1232 abfd
, section
->name
, symbols
, (long int)offset
);
1234 return _bfd_vms_find_nearest_dst_line (abfd
, section
, symbols
, offset
, file
, func
, line
);
1238 vms_find_inliner_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1239 const char **file ATTRIBUTE_UNUSED
,
1240 const char **func ATTRIBUTE_UNUSED
,
1241 unsigned int *line ATTRIBUTE_UNUSED
)
1244 vms_debug (1, "vms_find_inliner_info (%p, <ret>, <ret>, <ret>)\n",
1250 /* Back-door to allow format-aware applications to create debug symbols
1251 while using BFD for everything else. Currently used by the assembler
1252 when creating COFF files. */
1255 vms_bfd_make_debug_symbol (bfd
* abfd ATTRIBUTE_UNUSED
,
1256 void *ptr ATTRIBUTE_UNUSED
,
1257 unsigned long size ATTRIBUTE_UNUSED
)
1260 vms_debug (1, "vms_bfd_make_debug_symbol (%p, %p, %ld)\n", abfd
, ptr
, size
);
1265 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1266 symbols. The minisymbol_to_symbol function translates these into
1267 BFD asymbol structures. */
1270 vms_read_minisymbols (bfd
* abfd
,
1271 bfd_boolean dynamic
,
1273 unsigned int *sizep
)
1276 vms_debug (1, "vms_read_minisymbols (%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1278 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1281 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1282 unmodified a.out symbol. The SYM argument is a structure returned
1283 by bfd_make_empty_symbol, which we fill in here. */
1286 vms_minisymbol_to_symbol (bfd
* abfd
,
1287 bfd_boolean dynamic
,
1288 const void * minisym
,
1292 vms_debug (1, "vms_minisymbol_to_symbol (%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1294 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1297 /* Part 4.6, relocations. */
1299 /* Allocate the reloc buffer for the specified section. */
1302 alloc_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
1307 /* If there were no relocations, there is nothing to do. */
1308 if (section
->reloc_count
== 0)
1311 ptr
= bfd_malloc (vms_section_data (section
)->reloc_size
);
1314 *(bfd_boolean
*)alloc_error
= TRUE
;
1318 vms_section_data (section
)->reloc_stream
= ptr
;
1321 /* Read in the relocs for the specified section and internalize them.
1323 The implementation is loosely based on the SOM code and made up
1324 of 3 distinct phases:
1326 1. When the VMS object is opened and parsed, the number and the size
1327 of the relocations are computed for all sections. This makes it
1328 possible to know upfront both which sections have no relocs and
1329 the size of the reloc buffers for the other sections, at virtually
1330 no cost for consumers that don't care about relocs at all.
1332 2. When vms_slurp_reloc_table is invoked for the first time on a section
1333 with relocs, the object is traversed and all the reloc information
1334 is saved in per-section reloc buffers. It would be very inefficient
1335 to scan the whole file on each invocation, so we slurp for all the
1338 3. On subsequent invocations of vms_slurp_reloc_table, the relocs for the
1339 specified section are fetched from the buffer, decoded and internalized.
1340 The buffer is then freed since the internalized relocs are attached to
1341 the section, turning additional invocations of vms_slurp_reloc_table
1342 on the same section into no-ops.
1344 Since VMS objects have very few sections, it could be profitable to merge
1345 phase #2 and phase #3, i.e. to decode and internalize the relocs for all
1346 the sections at once. The current implementation is more elegant. */
1349 vms_slurp_reloc_table (bfd
*abfd
, asection
*section
, asymbol
**symbols
)
1351 arelent
*internal_relocs
;
1355 /* If there were no relocations, there is nothing to do. */
1356 if (section
->reloc_count
== 0)
1359 /* Return saved information about the relocations if it is available. */
1360 if (section
->relocation
!= NULL
)
1363 /* If the relocation stream has not been slurped, do it now. */
1364 if (vms_section_data (section
)->reloc_stream
== NULL
)
1366 bfd_boolean alloc_error
= FALSE
;
1369 /* Size the reloc buffer for each section. */
1370 bfd_map_over_sections (abfd
, alloc_reloc_stream
, &alloc_error
);
1374 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
1377 /* Reset section pointer. */
1378 PRIV (image_section
) = NULL
;
1382 type
= _bfd_vms_get_object_record (abfd
);
1383 if (type
!= EOBJ_S_C_ETIR
1384 && type
!= EOBJ_S_C_EDBG
1385 && type
!= EOBJ_S_C_ETBT
)
1387 err
= _bfd_vms_slurp_relocs (abfd
);
1391 vms_debug (2, "slurp relocs failed with %d\n", err
);
1396 while (type
!= EOBJ_S_C_EEOM
);
1399 amt
= section
->reloc_count
* sizeof (arelent
);
1400 internal_relocs
= (arelent
*) bfd_zalloc (abfd
, amt
);
1401 if (internal_relocs
== NULL
)
1404 /* Decode and internalize the relocations. */
1405 err
= _bfd_vms_decode_relocs (abfd
, internal_relocs
, section
, symbols
);
1409 vms_debug (2, "decode relocs failed with %d\n", err
);
1414 /* We're done with the external relocations. Free them. */
1415 free (vms_section_data (section
)->reloc_stream
);
1416 vms_section_data (section
)->reloc_stream
= NULL
;
1418 /* Save our results and return success. */
1419 section
->relocation
= internal_relocs
;
1423 /* Return the number of bytes required to store the relocation
1424 information associated with the given section. */
1427 vms_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
1429 return (section
->reloc_count
+ 1) * sizeof (arelent
*);
1432 /* Convert relocations from VMS (external) form into BFD internal
1433 form. Return the number of relocations. */
1436 vms_canonicalize_reloc (bfd
*abfd
, asection
*section
, arelent
**relptr
,
1442 if (! vms_slurp_reloc_table (abfd
, section
, symbols
))
1445 count
= section
->reloc_count
;
1446 tblptr
= section
->relocation
;
1449 *relptr
++ = tblptr
++;
1451 *relptr
= (arelent
*) NULL
;
1452 return section
->reloc_count
;
1455 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
1457 /* How to process the various reloc types. */
1459 static bfd_reloc_status_type
1460 reloc_nil (bfd
* abfd ATTRIBUTE_UNUSED
,
1461 arelent
*reloc ATTRIBUTE_UNUSED
,
1462 asymbol
*sym ATTRIBUTE_UNUSED
,
1463 void * data ATTRIBUTE_UNUSED
,
1464 asection
*sec ATTRIBUTE_UNUSED
,
1465 bfd
*output_bfd ATTRIBUTE_UNUSED
,
1466 char **error_message ATTRIBUTE_UNUSED
)
1469 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1470 vms_debug (2, "In section %s, symbol %s\n",
1471 sec
->name
, sym
->name
);
1472 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1473 reloc
->sym_ptr_ptr
[0]->name
,
1474 (unsigned long)reloc
->address
,
1475 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1476 vms_debug (2, "data at %p\n", data
);
1477 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
1480 return bfd_reloc_ok
;
1483 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1484 from smaller values. Start with zero, widen, *then* decrement. */
1485 #define MINUS_ONE (((bfd_vma)0) - 1)
1487 static reloc_howto_type alpha_howto_table
[] =
1489 HOWTO (ALPHA_R_IGNORE
, /* Type. */
1490 0, /* Rightshift. */
1491 0, /* Size (0 = byte, 1 = short, 2 = long). */
1493 TRUE
, /* PC relative. */
1495 complain_overflow_dont
,/* Complain_on_overflow. */
1496 reloc_nil
, /* Special_function. */
1497 "IGNORE", /* Name. */
1498 TRUE
, /* Partial_inplace. */
1499 0, /* Source mask */
1501 TRUE
), /* PC rel offset. */
1503 /* A 64 bit reference to a symbol. */
1504 HOWTO (ALPHA_R_REFQUAD
, /* Type. */
1505 0, /* Rightshift. */
1506 4, /* Size (0 = byte, 1 = short, 2 = long). */
1508 FALSE
, /* PC relative. */
1510 complain_overflow_bitfield
, /* Complain_on_overflow. */
1511 reloc_nil
, /* Special_function. */
1512 "REFQUAD", /* Name. */
1513 TRUE
, /* Partial_inplace. */
1514 MINUS_ONE
, /* Source mask. */
1515 MINUS_ONE
, /* Dest mask. */
1516 FALSE
), /* PC rel offset. */
1518 /* A 21 bit branch. The native assembler generates these for
1519 branches within the text segment, and also fills in the PC
1520 relative offset in the instruction. */
1521 HOWTO (ALPHA_R_BRADDR
, /* Type. */
1522 2, /* Rightshift. */
1523 2, /* Size (0 = byte, 1 = short, 2 = long). */
1525 TRUE
, /* PC relative. */
1527 complain_overflow_signed
, /* Complain_on_overflow. */
1528 reloc_nil
, /* Special_function. */
1529 "BRADDR", /* Name. */
1530 TRUE
, /* Partial_inplace. */
1531 0x1fffff, /* Source mask. */
1532 0x1fffff, /* Dest mask. */
1533 FALSE
), /* PC rel offset. */
1535 /* A hint for a jump to a register. */
1536 HOWTO (ALPHA_R_HINT
, /* Type. */
1537 2, /* Rightshift. */
1538 1, /* Size (0 = byte, 1 = short, 2 = long). */
1540 TRUE
, /* PC relative. */
1542 complain_overflow_dont
,/* Complain_on_overflow. */
1543 reloc_nil
, /* Special_function. */
1545 TRUE
, /* Partial_inplace. */
1546 0x3fff, /* Source mask. */
1547 0x3fff, /* Dest mask. */
1548 FALSE
), /* PC rel offset. */
1550 /* 16 bit PC relative offset. */
1551 HOWTO (ALPHA_R_SREL16
, /* Type. */
1552 0, /* Rightshift. */
1553 1, /* Size (0 = byte, 1 = short, 2 = long). */
1555 TRUE
, /* PC relative. */
1557 complain_overflow_signed
, /* Complain_on_overflow. */
1558 reloc_nil
, /* Special_function. */
1559 "SREL16", /* Name. */
1560 TRUE
, /* Partial_inplace. */
1561 0xffff, /* Source mask. */
1562 0xffff, /* Dest mask. */
1563 FALSE
), /* PC rel offset. */
1565 /* 32 bit PC relative offset. */
1566 HOWTO (ALPHA_R_SREL32
, /* Type. */
1567 0, /* Rightshift. */
1568 2, /* Size (0 = byte, 1 = short, 2 = long). */
1570 TRUE
, /* PC relative. */
1572 complain_overflow_signed
, /* Complain_on_overflow. */
1573 reloc_nil
, /* Special_function. */
1574 "SREL32", /* Name. */
1575 TRUE
, /* Partial_inplace. */
1576 0xffffffff, /* Source mask. */
1577 0xffffffff, /* Dest mask. */
1578 FALSE
), /* PC rel offset. */
1580 /* A 64 bit PC relative offset. */
1581 HOWTO (ALPHA_R_SREL64
, /* Type. */
1582 0, /* Rightshift. */
1583 4, /* Size (0 = byte, 1 = short, 2 = long). */
1585 TRUE
, /* PC relative. */
1587 complain_overflow_signed
, /* Complain_on_overflow. */
1588 reloc_nil
, /* Special_function. */
1589 "SREL64", /* Name. */
1590 TRUE
, /* Partial_inplace. */
1591 MINUS_ONE
, /* Source mask. */
1592 MINUS_ONE
, /* Dest mask. */
1593 FALSE
), /* PC rel offset. */
1595 /* Push a value on the reloc evaluation stack. */
1596 HOWTO (ALPHA_R_OP_PUSH
, /* Type. */
1597 0, /* Rightshift. */
1598 0, /* Size (0 = byte, 1 = short, 2 = long). */
1600 FALSE
, /* PC relative. */
1602 complain_overflow_dont
,/* Complain_on_overflow. */
1603 reloc_nil
, /* Special_function. */
1604 "OP_PUSH", /* Name. */
1605 FALSE
, /* Partial_inplace. */
1606 0, /* Source mask. */
1608 FALSE
), /* PC rel offset. */
1610 /* Store the value from the stack at the given address. Store it in
1611 a bitfield of size r_size starting at bit position r_offset. */
1612 HOWTO (ALPHA_R_OP_STORE
, /* Type. */
1613 0, /* Rightshift. */
1614 4, /* Size (0 = byte, 1 = short, 2 = long). */
1616 FALSE
, /* PC relative. */
1618 complain_overflow_dont
,/* Complain_on_overflow. */
1619 reloc_nil
, /* Special_function. */
1620 "OP_STORE", /* Name. */
1621 FALSE
, /* Partial_inplace. */
1622 0, /* Source mask. */
1623 MINUS_ONE
, /* Dest mask. */
1624 FALSE
), /* PC rel offset. */
1626 /* Subtract the reloc address from the value on the top of the
1627 relocation stack. */
1628 HOWTO (ALPHA_R_OP_PSUB
, /* Type. */
1629 0, /* Rightshift. */
1630 0, /* Size (0 = byte, 1 = short, 2 = long). */
1632 FALSE
, /* PC relative. */
1634 complain_overflow_dont
,/* Complain_on_overflow. */
1635 reloc_nil
, /* Special_function. */
1636 "OP_PSUB", /* Name. */
1637 FALSE
, /* Partial_inplace. */
1638 0, /* Source mask. */
1640 FALSE
), /* PC rel offset. */
1642 /* Shift the value on the top of the relocation stack right by the
1644 HOWTO (ALPHA_R_OP_PRSHIFT
, /* Type. */
1645 0, /* Rightshift. */
1646 0, /* Size (0 = byte, 1 = short, 2 = long). */
1648 FALSE
, /* PC relative. */
1650 complain_overflow_dont
,/* Complain_on_overflow. */
1651 reloc_nil
, /* Special_function. */
1652 "OP_PRSHIFT", /* Name. */
1653 FALSE
, /* Partial_inplace. */
1654 0, /* Source mask. */
1656 FALSE
), /* PC rel offset. */
1658 /* Hack. Linkage is done by linker. */
1659 HOWTO (ALPHA_R_LINKAGE
, /* Type. */
1660 0, /* Rightshift. */
1661 8, /* Size (0 = byte, 1 = short, 2 = long). */
1663 FALSE
, /* PC relative. */
1665 complain_overflow_dont
,/* Complain_on_overflow. */
1666 reloc_nil
, /* Special_function. */
1667 "LINKAGE", /* Name. */
1668 FALSE
, /* Partial_inplace. */
1669 0, /* Source mask. */
1671 FALSE
), /* PC rel offset. */
1673 /* A 32 bit reference to a symbol. */
1674 HOWTO (ALPHA_R_REFLONG
, /* Type. */
1675 0, /* Rightshift. */
1676 2, /* Size (0 = byte, 1 = short, 2 = long). */
1678 FALSE
, /* PC relative. */
1680 complain_overflow_bitfield
, /* Complain_on_overflow. */
1681 reloc_nil
, /* Special_function. */
1682 "REFLONG", /* Name. */
1683 TRUE
, /* Partial_inplace. */
1684 0xffffffff, /* Source mask. */
1685 0xffffffff, /* Dest mask. */
1686 FALSE
), /* PC rel offset. */
1688 /* A 64 bit reference to a procedure, written as 32 bit value. */
1689 HOWTO (ALPHA_R_CODEADDR
, /* Type. */
1690 0, /* Rightshift. */
1691 4, /* Size (0 = byte, 1 = short, 2 = long). */
1693 FALSE
, /* PC relative. */
1695 complain_overflow_signed
,/* Complain_on_overflow. */
1696 reloc_nil
, /* Special_function. */
1697 "CODEADDR", /* Name. */
1698 FALSE
, /* Partial_inplace. */
1699 0xffffffff, /* Source mask. */
1700 0xffffffff, /* Dest mask. */
1701 FALSE
), /* PC rel offset. */
1703 HOWTO (ALPHA_R_NOP
, /* Type. */
1704 0, /* Rightshift. */
1705 3, /* Size (0 = byte, 1 = short, 2 = long). */
1707 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
1708 because the calculations for the 3 relocations are the same.
1709 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
1710 TRUE
, /* PC relative. */
1712 complain_overflow_dont
,/* Complain_on_overflow. */
1713 reloc_nil
, /* Special_function. */
1715 FALSE
, /* Partial_inplace. */
1716 0xffffffff, /* Source mask. */
1717 0xffffffff, /* Dest mask. */
1718 FALSE
), /* PC rel offset. */
1720 HOWTO (ALPHA_R_BSR
, /* Type. */
1721 0, /* Rightshift. */
1722 3, /* Size (0 = byte, 1 = short, 2 = long). */
1724 TRUE
, /* PC relative. */
1726 complain_overflow_dont
,/* Complain_on_overflow. */
1727 reloc_nil
, /* Special_function. */
1729 FALSE
, /* Partial_inplace. */
1730 0xffffffff, /* Source mask. */
1731 0xffffffff, /* Dest mask. */
1732 FALSE
), /* PC rel offset. */
1734 HOWTO (ALPHA_R_LDA
, /* Type. */
1735 0, /* Rightshift. */
1736 3, /* Size (0 = byte, 1 = short, 2 = long). */
1738 FALSE
, /* PC relative. */
1740 complain_overflow_dont
,/* Complain_on_overflow. */
1741 reloc_nil
, /* Special_function. */
1743 FALSE
, /* Partial_inplace. */
1744 0xffffffff, /* Source mask. */
1745 0xffffffff, /* Dest mask. */
1746 FALSE
), /* PC rel offset. */
1748 HOWTO (ALPHA_R_BOH
, /* Type. */
1749 0, /* Rightshift. */
1750 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
1752 TRUE
, /* PC relative. */
1754 complain_overflow_dont
,/* Complain_on_overflow. */
1755 reloc_nil
, /* Special_function. */
1757 FALSE
, /* Partial_inplace. */
1758 0xffffffff, /* Source mask. */
1759 0xffffffff, /* Dest mask. */
1760 FALSE
), /* PC rel offset. */
1763 /* Return a pointer to a howto structure which, when invoked, will perform
1764 the relocation code on data from the architecture noted. */
1766 static const struct reloc_howto_struct
*
1767 vms_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1768 bfd_reloc_code_real_type code
)
1773 vms_debug (1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd
, code
);
1778 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1779 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1780 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1781 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1782 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1783 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1784 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1785 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1786 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1787 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1788 case BFD_RELOC_ALPHA_CODEADDR
: alpha_type
= ALPHA_R_CODEADDR
; break;
1789 case BFD_RELOC_ALPHA_NOP
: alpha_type
= ALPHA_R_NOP
; break;
1790 case BFD_RELOC_ALPHA_BSR
: alpha_type
= ALPHA_R_BSR
; break;
1791 case BFD_RELOC_ALPHA_LDA
: alpha_type
= ALPHA_R_LDA
; break;
1792 case BFD_RELOC_ALPHA_BOH
: alpha_type
= ALPHA_R_BOH
; break;
1794 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1798 vms_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1800 return & alpha_howto_table
[alpha_type
];
1803 static reloc_howto_type
*
1804 vms_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1810 i
< sizeof (alpha_howto_table
) / sizeof (alpha_howto_table
[0]);
1812 if (alpha_howto_table
[i
].name
!= NULL
1813 && strcasecmp (alpha_howto_table
[i
].name
, r_name
) == 0)
1814 return &alpha_howto_table
[i
];
1819 /* Part 4.7, writing an object file. */
1821 /* Set the architecture and machine type in BFD abfd to arch and mach.
1822 Find the correct pointer to a structure and insert it into the arch_info
1826 vms_set_arch_mach (bfd
* abfd
,
1827 enum bfd_architecture arch ATTRIBUTE_UNUSED
,
1828 unsigned long mach ATTRIBUTE_UNUSED
)
1831 vms_debug (1, "vms_set_arch_mach (%p, %d, %ld)\n", abfd
, arch
, mach
);
1834 if (arch
!= bfd_arch_alpha
1835 && arch
!= bfd_arch_vax
1836 && arch
!= bfd_arch_unknown
)
1839 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
1842 /* Sets the contents of the section section in BFD abfd to the data starting
1843 in memory at LOCATION. The data is written to the output section starting
1844 at offset offset for count bytes.
1846 Normally TRUE is returned, else FALSE. Possible error returns are:
1847 o bfd_error_no_contents - The output section does not have the
1848 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1849 o and some more too */
1852 vms_set_section_contents (bfd
* abfd
,
1854 const void * location
,
1856 bfd_size_type count
)
1859 vms_debug (1, "vms_set_section_contents (%p, sec %s, loc %p, off %ld, count %d)\n",
1860 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1861 vms_debug (2, "size %d\n", (int) section
->size
);
1863 if (count
== (bfd_size_type
)0)
1866 if (section
->contents
== NULL
)
1867 section
->contents
= bfd_alloc (abfd
, section
->size
);
1868 if (section
->contents
== NULL
)
1871 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
1875 /* Part 4.8, linker. */
1877 /* Get the size of the section headers. */
1880 vms_sizeof_headers (bfd
* abfd ATTRIBUTE_UNUSED
,
1881 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1884 vms_debug (1, "vms_sizeof_headers (%p, %s)\n", abfd
, (reloc
)?"True":"False");
1889 /* Provides default handling of relocation effort for back ends
1890 which can't be bothered to do it efficiently. */
1893 vms_bfd_get_relocated_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
1894 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1895 struct bfd_link_order
*link_order ATTRIBUTE_UNUSED
,
1896 bfd_byte
*data ATTRIBUTE_UNUSED
,
1897 bfd_boolean relocatable ATTRIBUTE_UNUSED
,
1898 asymbol
**symbols ATTRIBUTE_UNUSED
)
1901 vms_debug (1, "vms_bfd_get_relocated_section_contents (%p, %p, %p, %p, %s, %p)\n",
1902 abfd
, link_info
, link_order
, data
, (relocatable
)?"True":"False", symbols
);
1910 vms_bfd_relax_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1911 asection
*section ATTRIBUTE_UNUSED
,
1912 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1913 bfd_boolean
*again ATTRIBUTE_UNUSED
)
1915 if (link_info
->relocatable
)
1916 (*link_info
->callbacks
->einfo
)
1917 (_("%P%F: --relax and -r may not be used together\n"));
1920 vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, <ret>)\n",
1921 abfd
, section
->name
, link_info
);
1927 vms_bfd_gc_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1928 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1931 vms_debug (1, "vms_bfd_gc_sections (%p, %p)\n", abfd
, link_info
);
1937 vms_bfd_merge_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1938 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1941 vms_debug (1, "vms_bfd_merge_sections (%p, %p)\n", abfd
, link_info
);
1946 /* Create a hash table for the linker. Different backends store
1947 different information in this table. */
1949 static struct bfd_link_hash_table
*
1950 vms_bfd_link_hash_table_create (bfd
* abfd ATTRIBUTE_UNUSED
)
1953 vms_debug (1, "vms_bfd_link_hash_table_create (%p)\n", abfd
);
1958 /* Free a linker hash table. */
1961 vms_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash ATTRIBUTE_UNUSED
)
1964 vms_debug (1, "vms_bfd_link_hash_table_free (%p)\n", abfd
);
1968 /* Add symbols from this object file into the hash table. */
1971 vms_bfd_link_add_symbols (bfd
* abfd ATTRIBUTE_UNUSED
,
1972 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1975 vms_debug (1, "vms_bfd_link_add_symbols (%p, %p)\n", abfd
, link_info
);
1980 /* Do a link based on the link_order structures attached to each
1981 section of the BFD. */
1984 vms_bfd_final_link (bfd
* abfd ATTRIBUTE_UNUSED
,
1985 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1988 vms_debug (1, "vms_bfd_final_link (%p, %p)\n", abfd
, link_info
);
1993 /* Should this section be split up into smaller pieces during linking. */
1996 vms_bfd_link_split_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1997 asection
*section ATTRIBUTE_UNUSED
)
2000 vms_debug (1, "vms_bfd_link_split_section (%p, %s)\n", abfd
, section
->name
);
2005 /* Part 4.9, dynamic symbols and relocations. */
2007 /* Get the amount of memory required to hold the dynamic symbols. */
2010 vms_get_dynamic_symtab_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2013 vms_debug (1, "vms_get_dynamic_symtab_upper_bound (%p)\n", abfd
);
2019 vms_bfd_print_private_bfd_data (bfd
* abfd ATTRIBUTE_UNUSED
,
2020 void *file ATTRIBUTE_UNUSED
)
2023 vms_debug (1, "vms_bfd_print_private_bfd_data (%p)\n", abfd
);
2028 /* Read in the dynamic symbols. */
2031 vms_canonicalize_dynamic_symtab (bfd
* abfd ATTRIBUTE_UNUSED
,
2032 asymbol
**symbols ATTRIBUTE_UNUSED
)
2035 vms_debug (1, "vms_canonicalize_dynamic_symtab (%p, <ret>)\n", abfd
);
2040 /* Get the amount of memory required to hold the dynamic relocs. */
2043 vms_get_dynamic_reloc_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2046 vms_debug (1, "vms_get_dynamic_reloc_upper_bound (%p)\n", abfd
);
2051 /* Read in the dynamic relocs. */
2054 vms_canonicalize_dynamic_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
2055 arelent
**arel ATTRIBUTE_UNUSED
,
2056 asymbol
**symbols ATTRIBUTE_UNUSED
)
2059 vms_debug (1, "vms_canonicalize_dynamic_reloc (%p)\n", abfd
);
2064 const bfd_target vms_alpha_vec
=
2066 "vms-alpha", /* Name. */
2067 bfd_target_evax_flavour
,
2068 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2069 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2071 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
2072 | WP_TEXT
| D_PAGED
), /* Object flags. */
2073 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2074 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2075 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2076 0, /* symbol_leading_char. */
2077 ' ', /* ar_pad_char. */
2078 15, /* ar_max_namelen. */
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
,
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
,
2086 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2087 vms_archive_p
, _bfd_dummy_target
},
2088 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2089 _bfd_generic_mkarchive
, bfd_false
},
2090 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2091 _bfd_write_archive_contents
, bfd_false
},
2093 BFD_JUMP_TABLE_GENERIC (vms
),
2094 BFD_JUMP_TABLE_COPY (vms
),
2095 BFD_JUMP_TABLE_CORE (vms
),
2096 BFD_JUMP_TABLE_ARCHIVE (vms
),
2097 BFD_JUMP_TABLE_SYMBOLS (vms
),
2098 BFD_JUMP_TABLE_RELOCS (vms
),
2099 BFD_JUMP_TABLE_WRITE (vms
),
2100 BFD_JUMP_TABLE_LINK (vms
),
2101 BFD_JUMP_TABLE_DYNAMIC (vms
),
2108 const bfd_target vms_vax_vec
=
2110 "vms-vax", /* Name. */
2111 bfd_target_ovax_flavour
,
2112 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2113 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2115 (HAS_RELOC
| HAS_SYMS
/* Object flags. */
2117 | HAS_LINENO
| HAS_DEBUG
| HAS_LOCALS
),
2119 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2120 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2121 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2122 0, /* symbol_leading_char */
2123 ' ', /* ar_pad_char */
2124 15, /* ar_max_namelen */
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
, /* Data. */
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
, /* Hdrs. */
2132 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2133 vms_archive_p
, _bfd_dummy_target
},
2134 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2135 _bfd_generic_mkarchive
, bfd_false
},
2136 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2137 _bfd_write_archive_contents
, bfd_false
},
2139 BFD_JUMP_TABLE_GENERIC (vms
),
2140 BFD_JUMP_TABLE_COPY (vms
),
2141 BFD_JUMP_TABLE_CORE (vms
),
2142 BFD_JUMP_TABLE_ARCHIVE (vms
),
2143 BFD_JUMP_TABLE_SYMBOLS (vms
),
2144 BFD_JUMP_TABLE_RELOCS (vms
),
2145 BFD_JUMP_TABLE_WRITE (vms
),
2146 BFD_JUMP_TABLE_LINK (vms
),
2147 BFD_JUMP_TABLE_DYNAMIC (vms
),