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_define_common_symbol bfd_generic_define_common_symbol
148 #define vms_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
149 #define vms_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
153 /* Cause debug info to be emitted for the structure. */
154 struct vms_private_data_struct _vms_private_data_struct_dummy
;
155 struct vms_section_data_struct _vms_section_data_struct_dummy
;
158 extern const bfd_target vms_vax_vec
;
159 extern const bfd_target vms_alpha_vec
;
161 /* Initialize private data */
163 vms_initialize (bfd
* abfd
)
167 bfd_set_start_address (abfd
, (bfd_vma
) -1);
169 amt
= sizeof (struct vms_private_data_struct
);
170 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
171 if (abfd
->tdata
.any
== NULL
)
174 if (bfd_get_flavour (abfd
) == bfd_target_ovax_flavour
)
175 PRIV (is_vax
) = TRUE
;
177 PRIV (file_format
) = FF_UNKNOWN
;
179 amt
= sizeof (struct stack_struct
) * STACKSIZE
;
180 PRIV (stack
) = bfd_alloc (abfd
, amt
);
181 if (PRIV (stack
) == NULL
)
184 amt
= sizeof (struct bfd_hash_table
);
185 PRIV (vms_symbol_table
) = bfd_alloc (abfd
, amt
);
186 if (PRIV (vms_symbol_table
) == NULL
)
189 if (!bfd_hash_table_init (PRIV (vms_symbol_table
), _bfd_vms_hash_newfunc
,
190 sizeof (vms_symbol_entry
)))
193 amt
= MAX_OUTREC_SIZE
;
194 PRIV (output_buf
) = bfd_alloc (abfd
, amt
);
195 if (PRIV (output_buf
) == NULL
)
198 PRIV (length_pos
) = 2;
203 bfd_hash_table_free (PRIV (vms_symbol_table
));
205 bfd_release (abfd
, abfd
->tdata
.any
);
206 abfd
->tdata
.any
= NULL
;
212 unsigned int section_count
;
216 /* Fill symbol->section with section pointer.
218 symbol->section is filled with the section index for defined symbols
219 during reading the GSD/EGSD section. But we need the pointer to the
222 It has the correct value for referenced (undefined section) symbols.
224 Called from bfd_hash_traverse in vms_fixup_sections. */
227 fill_section_ptr (struct bfd_hash_entry
*entry
, void *sections
)
229 asymbol
*sym
= ((vms_symbol_entry
*)entry
)->symbol
;
230 struct pair
*data
= (struct pair
*)sections
;
231 unsigned long sec
= (unsigned long)sym
->section
;
234 vms_debug (6, "fill_section_ptr: sym %p, sec %p\n", sym
, sec
);
237 if (sec
< data
->section_count
)
239 sym
->section
= data
->sections
[sec
];
241 if (strcmp (sym
->name
, sym
->section
->name
) == 0)
242 sym
->flags
|= BSF_SECTION_SYM
;
244 else if (sec
== (unsigned long)-1)
245 sym
->section
= &bfd_und_section
;
250 /* Fixup section pointers in symbols. */
252 vms_fixup_sections (bfd
* abfd
)
256 if (PRIV (fixup_done
))
259 data
.section_count
= PRIV (section_count
);
260 data
.sections
= PRIV (sections
);
261 bfd_hash_traverse (PRIV (vms_symbol_table
), fill_section_ptr
, &data
);
263 PRIV (fixup_done
) = TRUE
;
267 /* Slurp an ordered set of VMS object records. */
269 _bfd_vms_slurp_object_records (bfd
* abfd
)
271 int err
, new_type
, type
= -1;
276 vms_debug (7, "reading at %08lx\n", bfd_tell (abfd
));
278 new_type
= _bfd_vms_get_object_record (abfd
);
282 vms_debug (2, "next_record failed\n");
287 if (type
== EOBJ_S_C_EGSD
&& new_type
!= EOBJ_S_C_EGSD
)
289 if (! vms_fixup_sections (abfd
))
292 vms_debug (2, "vms_fixup_sections failed\n");
304 err
= _bfd_vms_slurp_hdr (abfd
, type
);
309 err
= _bfd_vms_slurp_eom (abfd
, type
);
313 err
= _bfd_vms_slurp_gsd (abfd
, type
);
317 err
= _bfd_vms_slurp_tir (abfd
, type
);
321 err
= _bfd_vms_slurp_dbg (abfd
, type
);
322 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
326 err
= _bfd_vms_slurp_tbt (abfd
, type
);
327 PRIV (dst_ptr_end
) = PRIV (image_ptr
);
330 err
= _bfd_vms_slurp_lnk (abfd
, type
);
338 vms_debug (2, "slurp type %d failed with %d\n", type
, err
);
343 while (type
!= EOBJ_S_C_EEOM
&& type
!= OBJ_S_C_EOM
&& type
!= OBJ_S_C_EOMW
);
348 /* Slurp a VMS module and return an error status. */
351 vms_slurp_module (bfd
*abfd
)
356 type
= PRIV (vms_rec
)[0];
358 type
= bfd_getl16 (PRIV (vms_rec
));
360 err
= _bfd_vms_slurp_hdr (abfd
, type
);
363 bfd_set_error (bfd_error_wrong_format
);
367 return _bfd_vms_slurp_object_records (abfd
);
370 /* Slurp a VMS image and return an error status. */
373 vms_slurp_image (bfd
*abfd
)
375 unsigned int isd_offset
, ihs_offset
;
378 err
= _bfd_vms_slurp_ihd (abfd
, &isd_offset
, &ihs_offset
);
381 bfd_set_error (bfd_error_wrong_format
);
385 err
= _bfd_vms_slurp_isd (abfd
, isd_offset
);
388 bfd_set_error (bfd_error_wrong_format
);
392 return _bfd_vms_slurp_ihs (abfd
, ihs_offset
);
395 /* Check the format for a file being read.
396 Return a (bfd_target *) if it's an object file or zero if not. */
398 static const struct bfd_target
*
399 vms_object_p (bfd
*abfd
)
401 const struct bfd_target
*target_vector
;
402 const bfd_arch_info_type
*arch
;
403 PTR tdata_save
= abfd
->tdata
.any
;
404 bfd_vma saddr_save
= bfd_get_start_address (abfd
);
408 vms_debug (1, "vms_object_p(%p)\n", abfd
);
411 if (!vms_initialize (abfd
))
414 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
))
415 goto err_wrong_format
;
417 switch (_bfd_vms_get_first_record (abfd
))
425 err
= vms_slurp_module (abfd
);
429 err
= vms_slurp_image (abfd
);
434 goto err_wrong_format
;
438 if (! vms_fixup_sections (abfd
))
441 vms_debug (2, "vms_fixup_sections failed\n");
443 goto err_wrong_format
;
446 target_vector
= &vms_vax_vec
;
447 arch
= bfd_scan_arch ("vax");
450 vms_debug (2, "arch is vax\n");
455 /* Set arch_info to alpha. */
456 target_vector
= &vms_alpha_vec
;
457 arch
= bfd_scan_arch ("alpha");
459 vms_debug (2, "arch is alpha\n");
463 abfd
->arch_info
= arch
;
464 return target_vector
;
467 bfd_set_error (bfd_error_wrong_format
);
470 if (abfd
->tdata
.any
!= tdata_save
&& abfd
->tdata
.any
!= NULL
)
471 bfd_release (abfd
, abfd
->tdata
.any
);
472 abfd
->tdata
.any
= tdata_save
;
473 bfd_set_start_address (abfd
, saddr_save
);
477 /* Check the format for a file being read.
478 Return a (bfd_target *) if it's an archive file or zero. */
480 static const struct bfd_target
*
481 vms_archive_p (bfd
* abfd ATTRIBUTE_UNUSED
)
484 vms_debug (1, "vms_archive_p (%p)\n", abfd
);
490 /* Set the format of a file being written. */
493 vms_mkobject (bfd
* abfd
)
495 const bfd_arch_info_type
*arch
;
498 vms_debug (1, "vms_mkobject (%p)\n", abfd
);
501 if (!vms_initialize (abfd
))
505 arch
= bfd_scan_arch ("vax");
507 arch
= bfd_scan_arch ("alpha");
511 bfd_set_error(bfd_error_wrong_format
);
515 abfd
->arch_info
= arch
;
519 /* Write cached information into a file being written, at bfd_close. */
522 vms_write_object_contents (bfd
* abfd
)
525 vms_debug (1, "vms_write_object_contents (%p)\n", abfd
);
528 if (abfd
->section_count
> 0) /* we have sections */
532 if (_bfd_vms_write_hdr (abfd
, OBJ_S_C_HDR
) != 0)
534 if (_bfd_vms_write_gsd (abfd
, OBJ_S_C_GSD
) != 0)
536 if (_bfd_vms_write_tir (abfd
, OBJ_S_C_TIR
) != 0)
538 if (_bfd_vms_write_tbt (abfd
, OBJ_S_C_TBT
) != 0)
540 if (_bfd_vms_write_dbg (abfd
, OBJ_S_C_DBG
) != 0)
542 if (abfd
->section_count
> 255)
544 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOMW
) != 0)
549 if (_bfd_vms_write_eom (abfd
, OBJ_S_C_EOM
) != 0)
555 if (_bfd_vms_write_hdr (abfd
, EOBJ_S_C_EMH
) != 0)
557 if (_bfd_vms_write_gsd (abfd
, EOBJ_S_C_EGSD
) != 0)
559 if (_bfd_vms_write_tir (abfd
, EOBJ_S_C_ETIR
) != 0)
561 if (_bfd_vms_write_tbt (abfd
, EOBJ_S_C_ETBT
) != 0)
563 if (_bfd_vms_write_dbg (abfd
, EOBJ_S_C_EDBG
) != 0)
565 if (_bfd_vms_write_eom (abfd
, EOBJ_S_C_EEOM
) != 0)
574 /* Free the reloc buffer for the specified section. */
577 free_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
578 void *data ATTRIBUTE_UNUSED
)
580 if (vms_section_data (section
)->reloc_stream
)
581 free (vms_section_data (section
)->reloc_stream
);
585 /* Convert the file to variable record length format. This is done
586 using undocumented system call sys$modify().
590 vms_convert_to_var (char *vms_filename
)
592 struct FAB fab
= cc$rms_fab
;
594 fab
.fab$l_fna
= vms_filename
;
595 fab
.fab$b_fns
= strlen (vms_filename
);
596 fab
.fab$b_fac
= FAB$M_PUT
;
597 fab
.fab$l_fop
= FAB$M_ESC
;
598 fab
.fab$l_ctx
= RME$C_SETRFM
;
602 fab
.fab$b_rfm
= FAB$C_VAR
;
609 vms_convert_to_var_1 (char *filename
, int type
)
611 if (type
!= DECC$K_FILE
)
613 vms_convert_to_var (filename
);
617 /* Convert the file to variable record length format. This is done
618 using undocumented system call sys$modify().
619 Unix filename version. */
622 vms_convert_to_var_unix_filename (const char *unix_filename
)
624 if (decc$
to_vms (unix_filename
, &vms_convert_to_var_1
, 0, 1) != 1)
630 /* Called when the BFD is being closed to do any necessary cleanup. */
633 vms_close_and_cleanup (bfd
* abfd
)
636 vms_debug (1, "vms_close_and_cleanup (%p)\n", abfd
);
638 if (abfd
== NULL
|| abfd
->tdata
.any
== NULL
)
641 if (PRIV (vms_buf
) != NULL
)
642 free (PRIV (vms_buf
));
644 if (PRIV (sections
) != NULL
)
645 free (PRIV (sections
));
647 if (PRIV (vms_symbol_table
))
648 bfd_hash_table_free (PRIV (vms_symbol_table
));
650 bfd_map_over_sections (abfd
, free_reloc_stream
, NULL
);
652 bfd_release (abfd
, abfd
->tdata
.any
);
653 abfd
->tdata
.any
= NULL
;
656 if (abfd
->direction
== write_direction
)
658 /* Last step on VMS is to convert the file to variable record length
660 if (bfd_cache_close (abfd
) != TRUE
)
662 if (vms_convert_to_var_unix_filename (abfd
->filename
) != TRUE
)
670 /* Ask the BFD to free all cached information. */
673 vms_bfd_free_cached_info (bfd
* abfd ATTRIBUTE_UNUSED
)
676 vms_debug (1, "vms_bfd_free_cached_info (%p)\n", abfd
);
681 /* Called when a new section is created. */
684 vms_new_section_hook (bfd
* abfd
, asection
*section
)
688 /* Count hasn't been incremented yet. */
689 unsigned int section_count
= abfd
->section_count
+ 1;
692 vms_debug (1, "vms_new_section_hook (%p, [%d]%s), count %d\n",
693 abfd
, section
->index
, section
->name
, section_count
);
696 bfd_set_section_alignment (abfd
, section
, 0);
698 if (section_count
> PRIV (section_count
))
700 bfd_size_type amt
= section_count
;
701 amt
*= sizeof (asection
*);
702 PRIV (sections
) = bfd_realloc_or_free (PRIV (sections
), amt
);
703 if (PRIV (sections
) == NULL
)
705 PRIV (section_count
) = section_count
;
709 vms_debug (6, "section_count: %d\n", PRIV (section_count
));
712 PRIV (sections
)[section
->index
] = section
;
715 vms_debug (7, "%d: %s\n", section
->index
, section
->name
);
718 amt
= sizeof (struct vms_section_data_struct
);
719 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
720 if (section
->used_by_bfd
== NULL
)
723 return _bfd_generic_new_section_hook (abfd
, section
);
726 /* Read the contents of a section.
727 buf points to a buffer of buf_size bytes to be filled with
728 section data (starting at offset into section) */
731 vms_get_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
732 asection
*section ATTRIBUTE_UNUSED
,
733 void * buf ATTRIBUTE_UNUSED
,
734 file_ptr offset ATTRIBUTE_UNUSED
,
735 bfd_size_type buf_size ATTRIBUTE_UNUSED
)
737 bfd_size_type size
= section
->size
;
740 vms_debug (1, "vms_get_section_contents (%p, %s, %p, off %ld, size %d)\n",
741 abfd
, section
->name
, buf
, offset
, (int)buf_size
);
744 if (section
->contents
)
747 section
->contents
= (unsigned char *) bfd_malloc (size
);
749 if (section
->contents
== NULL
)
751 bfd_set_error (bfd_error_no_memory
);
755 if (bfd_seek (abfd
, section
->filepos
, SEEK_SET
))
757 bfd_set_error (bfd_error_file_truncated
);
761 if (bfd_bread (section
->contents
, size
, abfd
) != size
)
763 bfd_set_error (bfd_error_file_truncated
);
767 section
->flags
|= SEC_IN_MEMORY
;
770 memcpy (buf
, section
->contents
+ offset
, (size_t) buf_size
);
775 /* Read the contents of a section.
776 buf points to a buffer of buf_size bytes to be filled with
777 section data (starting at offset into section). */
780 vms_get_section_contents_in_window (bfd
* abfd ATTRIBUTE_UNUSED
,
781 asection
*section ATTRIBUTE_UNUSED
,
782 bfd_window
*w ATTRIBUTE_UNUSED
,
783 file_ptr offset ATTRIBUTE_UNUSED
,
784 bfd_size_type count ATTRIBUTE_UNUSED
)
787 vms_debug (1, "vms_get_section_contents_in_window (%p, %s, %p, off %ld, count %d)\n",
788 abfd
, section
->name
, w
, offset
, (int)count
);
791 /* Shouldn't be called, since all sections are IN_MEMORY. */
795 /* Part 4.2, copy private data. */
797 /* Called to copy BFD general private data from one object file
801 vms_bfd_copy_private_bfd_data (bfd
*src ATTRIBUTE_UNUSED
,
802 bfd
*dest ATTRIBUTE_UNUSED
)
805 vms_debug (1, "vms_bfd_copy_private_bfd_data (%p, %p)\n", src
, dest
);
810 /* Merge private BFD information from the BFD @var{ibfd} to the
811 the output file BFD @var{obfd} when linking. Return <<TRUE>>
812 on success, <<FALSE>> on error. Possible error returns are:
814 o <<bfd_error_no_memory>> -
815 Not enough memory exists to create private data for @var{obfd}. */
818 vms_bfd_merge_private_bfd_data (bfd
* ibfd ATTRIBUTE_UNUSED
,
819 bfd
* obfd ATTRIBUTE_UNUSED
)
822 vms_debug (1,"vms_bfd_merge_private_bfd_data (%p, %p)\n", ibfd
, obfd
);
827 /* Set private BFD flag information in the BFD @var{abfd}.
828 Return <<TRUE>> on success, <<FALSE>> on error. Possible error
831 o <<bfd_error_no_memory>> -
832 Not enough memory exists to create private data for @var{obfd}. */
835 vms_bfd_set_private_flags (bfd
* abfd ATTRIBUTE_UNUSED
,
836 flagword flags ATTRIBUTE_UNUSED
)
839 vms_debug (1,"vms_bfd_set_private_flags (%p, %lx)\n", abfd
, (long)flags
);
844 /* Called to copy BFD private section data from one object file
848 vms_bfd_copy_private_section_data (bfd
*srcbfd ATTRIBUTE_UNUSED
,
849 asection
*srcsec ATTRIBUTE_UNUSED
,
850 bfd
*dstbfd ATTRIBUTE_UNUSED
,
851 asection
*dstsec ATTRIBUTE_UNUSED
)
854 vms_debug (1, "vms_bfd_copy_private_section_data (%p, %s, %p, %s)\n",
855 srcbfd
, srcsec
->name
, dstbfd
, dstsec
->name
);
860 /* Called to copy BFD private symbol data from one object file
864 vms_bfd_copy_private_symbol_data (bfd
*ibfd ATTRIBUTE_UNUSED
,
865 asymbol
*isym ATTRIBUTE_UNUSED
,
866 bfd
*obfd ATTRIBUTE_UNUSED
,
867 asymbol
*osym ATTRIBUTE_UNUSED
)
870 vms_debug (1, "vms_bfd_copy_private_symbol_data (%p, %s, %p, %s)\n",
871 ibfd
, isym
->name
, obfd
, osym
->name
);
876 /* Part 4.3, core file. */
878 /* Return a read-only string explaining which program was running
879 when it failed and produced the core file abfd. */
882 vms_core_file_failing_command (bfd
* abfd ATTRIBUTE_UNUSED
)
885 vms_debug (1, "vms_core_file_failing_command (%p)\n", abfd
);
890 /* Returns the signal number which caused the core dump which
891 generated the file the BFD abfd is attached to. */
894 vms_core_file_failing_signal (bfd
* abfd ATTRIBUTE_UNUSED
)
897 vms_debug (1, "vms_core_file_failing_signal (%p)\n", abfd
);
902 /* Return TRUE if the core file attached to core_bfd was generated
903 by a run of the executable file attached to exec_bfd, FALSE otherwise. */
906 vms_core_file_matches_executable_p (bfd
* abfd ATTRIBUTE_UNUSED
,
907 bfd
*bbfd ATTRIBUTE_UNUSED
)
910 vms_debug (1, "vms_core_file_matches_executable_p (%p, %p)\n", abfd
, bbfd
);
915 /* Part 4.4, archive. */
917 /* ??? do something with an archive map.
918 Return FALSE on error, TRUE otherwise. */
921 vms_slurp_armap (bfd
* abfd ATTRIBUTE_UNUSED
)
924 vms_debug (1, "vms_slurp_armap (%p)\n", abfd
);
929 /* ??? do something with an extended name table.
930 Return FALSE on error, TRUE otherwise. */
933 vms_slurp_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
)
936 vms_debug (1, "vms_slurp_extended_name_table (%p)\n", abfd
);
941 /* ??? do something with an extended name table.
942 Return FALSE on error, TRUE otherwise. */
945 vms_construct_extended_name_table (bfd
* abfd ATTRIBUTE_UNUSED
,
946 char **tabloc ATTRIBUTE_UNUSED
,
947 bfd_size_type
*tablen ATTRIBUTE_UNUSED
,
948 const char **name ATTRIBUTE_UNUSED
)
951 vms_debug (1, "vms_construct_extended_name_table (%p)\n", abfd
);
956 /* Truncate the name of an archive to match system-dependent restrictions. */
959 vms_truncate_arname (bfd
* abfd ATTRIBUTE_UNUSED
,
960 const char *pathname ATTRIBUTE_UNUSED
,
961 char *arhdr ATTRIBUTE_UNUSED
)
964 vms_debug (1, "vms_truncate_arname (%p, %s, %s)\n", abfd
, pathname
, arhdr
);
968 /* ??? write archive map. */
971 vms_write_armap (bfd
*arch ATTRIBUTE_UNUSED
,
972 unsigned int elength ATTRIBUTE_UNUSED
,
973 struct orl
*map ATTRIBUTE_UNUSED
,
974 unsigned int orl_count ATTRIBUTE_UNUSED
,
975 int stridx ATTRIBUTE_UNUSED
)
978 vms_debug (1, "vms_write_armap (%p, %d, %p, %d %d)\n",
979 arch
, elength
, map
, orl_count
, stridx
);
984 /* Read archive header ??? */
987 vms_read_ar_hdr (bfd
* abfd ATTRIBUTE_UNUSED
)
990 vms_debug (1, "vms_read_ar_hdr (%p)\n", abfd
);
995 /* Provided a BFD, @var{archive}, containing an archive and NULL, open
996 an input BFD on the first contained element and returns that.
997 Subsequent calls should pass the archive and the previous return value
998 to return a created BFD to the next contained element.
999 NULL is returned when there are no more. */
1002 vms_openr_next_archived_file (bfd
*arch ATTRIBUTE_UNUSED
,
1003 bfd
*prev ATTRIBUTE_UNUSED
)
1006 vms_debug (1, "vms_openr_next_archived_file (%p, %p)\n", arch
, prev
);
1011 /* Return the BFD which is referenced by the symbol in ABFD indexed by
1012 INDEX. INDEX should have been returned by bfd_get_next_mapent. */
1015 vms_get_elt_at_index (bfd
* abfd
, symindex index
)
1018 vms_debug (1, "vms_get_elt_at_index (%p, %p)\n", abfd
, index
);
1020 return _bfd_generic_get_elt_at_index (abfd
, index
);
1024 -> bfd_generic_stat_arch_elt. */
1027 vms_generic_stat_arch_elt (bfd
* abfd
, struct stat
*st
)
1030 vms_debug (1, "vms_generic_stat_arch_elt (%p, %p)\n", abfd
, st
);
1032 return bfd_generic_stat_arch_elt (abfd
, st
);
1035 /* This is a new function in bfd 2.5. */
1038 vms_update_armap_timestamp (bfd
* abfd ATTRIBUTE_UNUSED
)
1041 vms_debug (1, "vms_update_armap_timestamp (%p)\n", abfd
);
1046 /* Part 4.5, symbols. */
1048 /* Return the number of bytes required to store a vector of pointers
1049 to asymbols for all the symbols in the BFD abfd, including a
1050 terminal NULL pointer. If there are no symbols in the BFD,
1051 then return 0. If an error occurs, return -1. */
1054 vms_get_symtab_upper_bound (bfd
* abfd
)
1057 vms_debug (1, "vms_get_symtab_upper_bound (%p), %d symbols\n", abfd
, PRIV (gsd_sym_count
));
1059 return (PRIV (gsd_sym_count
) + 1) * sizeof (asymbol
*);
1062 /* Copy symbols from hash table to symbol vector
1064 called from bfd_hash_traverse in vms_canonicalize_symtab
1065 init counter to 0 if entry == 0. */
1068 copy_symbols (struct bfd_hash_entry
*entry
, void * arg
)
1070 bfd
* abfd
= (bfd
*) arg
;
1072 if (entry
== NULL
) /* Init counter. */
1074 else /* Fill vector, inc counter. */
1075 PRIV (symcache
)[PRIV (symnum
)++] = ((vms_symbol_entry
*)entry
)->symbol
;
1080 /* Read the symbols from the BFD abfd, and fills in the vector
1081 location with pointers to the symbols and a trailing NULL.
1083 Return number of symbols read. */
1086 vms_canonicalize_symtab (bfd
* abfd
, asymbol
**symbols
)
1089 vms_debug (1, "vms_canonicalize_symtab (%p, <ret>)\n", abfd
);
1093 copy_symbols (NULL
, abfd
);
1095 /* Traverse table and fill symbols vector. */
1096 PRIV (symcache
) = symbols
;
1097 bfd_hash_traverse (PRIV (vms_symbol_table
), copy_symbols
, abfd
);
1099 symbols
[PRIV (gsd_sym_count
)] = NULL
;
1101 return PRIV (gsd_sym_count
);
1104 /* Print symbol to file according to how. how is one of
1105 bfd_print_symbol_name just print the name
1106 bfd_print_symbol_more print more (???)
1107 bfd_print_symbol_all print all we know, which is not much right now :-). */
1110 vms_print_symbol (bfd
* abfd
,
1113 bfd_print_symbol_type how
)
1116 vms_debug (1, "vms_print_symbol (%p, %p, %p, %d)\n", abfd
, file
, symbol
, how
);
1121 case bfd_print_symbol_name
:
1122 case bfd_print_symbol_more
:
1123 fprintf ((FILE *)file
," %s", symbol
->name
);
1126 case bfd_print_symbol_all
:
1128 const char *section_name
= symbol
->section
->name
;
1130 bfd_print_symbol_vandf (abfd
, file
, symbol
);
1132 fprintf ((FILE *) file
," %-8s %s", section_name
, symbol
->name
);
1138 /* Return information about symbol in ret.
1140 fill type, value and name
1143 B bss segment symbol
1145 D data segment symbol
1147 t a static function symbol
1148 T text segment symbol
1153 vms_get_symbol_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1160 vms_debug (1, "vms_get_symbol_info (%p, %p, %p)\n", abfd
, symbol
, ret
);
1163 sec
= symbol
->section
;
1170 else if (bfd_is_com_section (sec
))
1172 else if (bfd_is_abs_section (sec
))
1174 else if (bfd_is_und_section (sec
))
1176 else if (bfd_is_ind_section (sec
))
1178 else if (bfd_get_section_flags (abfd
, sec
) & SEC_CODE
)
1180 else if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
1182 else if (bfd_get_section_flags (abfd
, sec
) & SEC_ALLOC
)
1187 if (ret
->type
!= 'U')
1188 ret
->value
= symbol
->value
+ symbol
->section
->vma
;
1191 ret
->name
= symbol
->name
;
1194 /* Return TRUE if the given symbol sym in the BFD abfd is
1195 a compiler generated local label, else return FALSE. */
1198 vms_bfd_is_local_label_name (bfd
* abfd ATTRIBUTE_UNUSED
,
1202 vms_debug (1, "vms_bfd_is_local_label_name (%p, %s)\n", abfd
, name
);
1204 return name
[0] == '$';
1207 /* Get source line number for symbol. */
1210 vms_get_lineno (bfd
* abfd ATTRIBUTE_UNUSED
,
1211 asymbol
*symbol ATTRIBUTE_UNUSED
)
1214 vms_debug (1, "vms_get_lineno (%p, %p)\n", abfd
, symbol
);
1219 /* Provided a BFD, a section and an offset into the section, calculate and
1220 return the name of the source file and the line nearest to the wanted
1224 vms_find_nearest_line (bfd
* abfd ATTRIBUTE_UNUSED
,
1225 asection
*section ATTRIBUTE_UNUSED
,
1226 asymbol
**symbols ATTRIBUTE_UNUSED
,
1227 bfd_vma offset ATTRIBUTE_UNUSED
,
1228 const char **file ATTRIBUTE_UNUSED
,
1229 const char **func ATTRIBUTE_UNUSED
,
1230 unsigned int *line ATTRIBUTE_UNUSED
)
1233 vms_debug (1, "vms_find_nearest_line (%p, %s, %p, %ld, <ret>, <ret>, <ret>)\n",
1234 abfd
, section
->name
, symbols
, (long int)offset
);
1236 return _bfd_vms_find_nearest_dst_line (abfd
, section
, symbols
, offset
, file
, func
, line
);
1240 vms_find_inliner_info (bfd
* abfd ATTRIBUTE_UNUSED
,
1241 const char **file ATTRIBUTE_UNUSED
,
1242 const char **func ATTRIBUTE_UNUSED
,
1243 unsigned int *line ATTRIBUTE_UNUSED
)
1246 vms_debug (1, "vms_find_inliner_info (%p, <ret>, <ret>, <ret>)\n",
1252 /* Back-door to allow format-aware applications to create debug symbols
1253 while using BFD for everything else. Currently used by the assembler
1254 when creating COFF files. */
1257 vms_bfd_make_debug_symbol (bfd
* abfd ATTRIBUTE_UNUSED
,
1258 void *ptr ATTRIBUTE_UNUSED
,
1259 unsigned long size ATTRIBUTE_UNUSED
)
1262 vms_debug (1, "vms_bfd_make_debug_symbol (%p, %p, %ld)\n", abfd
, ptr
, size
);
1267 /* Read minisymbols. For minisymbols, we use the unmodified a.out
1268 symbols. The minisymbol_to_symbol function translates these into
1269 BFD asymbol structures. */
1272 vms_read_minisymbols (bfd
* abfd
,
1273 bfd_boolean dynamic
,
1275 unsigned int *sizep
)
1278 vms_debug (1, "vms_read_minisymbols (%p, %d, %p, %d)\n", abfd
, dynamic
, minisymsp
, *sizep
);
1280 return _bfd_generic_read_minisymbols (abfd
, dynamic
, minisymsp
, sizep
);
1283 /* Convert a minisymbol to a BFD asymbol. A minisymbol is just an
1284 unmodified a.out symbol. The SYM argument is a structure returned
1285 by bfd_make_empty_symbol, which we fill in here. */
1288 vms_minisymbol_to_symbol (bfd
* abfd
,
1289 bfd_boolean dynamic
,
1290 const void * minisym
,
1294 vms_debug (1, "vms_minisymbol_to_symbol (%p, %d, %p, %p)\n", abfd
, dynamic
, minisym
, sym
);
1296 return _bfd_generic_minisymbol_to_symbol (abfd
, dynamic
, minisym
, sym
);
1299 /* Part 4.6, relocations. */
1301 /* Allocate the reloc buffer for the specified section. */
1304 alloc_reloc_stream (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
,
1309 /* If there were no relocations, there is nothing to do. */
1310 if (section
->reloc_count
== 0)
1313 ptr
= bfd_malloc (vms_section_data (section
)->reloc_size
);
1316 *(bfd_boolean
*)alloc_error
= TRUE
;
1320 vms_section_data (section
)->reloc_stream
= ptr
;
1323 /* Read in the relocs for the specified section and internalize them.
1325 The implementation is loosely based on the SOM code and made up
1326 of 3 distinct phases:
1328 1. When the VMS object is opened and parsed, the number and the size
1329 of the relocations are computed for all sections. This makes it
1330 possible to know upfront both which sections have no relocs and
1331 the size of the reloc buffers for the other sections, at virtually
1332 no cost for consumers that don't care about relocs at all.
1334 2. When vms_slurp_reloc_table is invoked for the first time on a section
1335 with relocs, the object is traversed and all the reloc information
1336 is saved in per-section reloc buffers. It would be very inefficient
1337 to scan the whole file on each invocation, so we slurp for all the
1340 3. On subsequent invocations of vms_slurp_reloc_table, the relocs for the
1341 specified section are fetched from the buffer, decoded and internalized.
1342 The buffer is then freed since the internalized relocs are attached to
1343 the section, turning additional invocations of vms_slurp_reloc_table
1344 on the same section into no-ops.
1346 Since VMS objects have very few sections, it could be profitable to merge
1347 phase #2 and phase #3, i.e. to decode and internalize the relocs for all
1348 the sections at once. The current implementation is more elegant. */
1351 vms_slurp_reloc_table (bfd
*abfd
, asection
*section
, asymbol
**symbols
)
1353 arelent
*internal_relocs
;
1357 /* If there were no relocations, there is nothing to do. */
1358 if (section
->reloc_count
== 0)
1361 /* Return saved information about the relocations if it is available. */
1362 if (section
->relocation
!= NULL
)
1365 /* If the relocation stream has not been slurped, do it now. */
1366 if (vms_section_data (section
)->reloc_stream
== NULL
)
1368 bfd_boolean alloc_error
= FALSE
;
1371 /* Size the reloc buffer for each section. */
1372 bfd_map_over_sections (abfd
, alloc_reloc_stream
, &alloc_error
);
1376 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
1379 /* Reset section pointer. */
1380 PRIV (image_section
) = NULL
;
1384 type
= _bfd_vms_get_object_record (abfd
);
1385 if (type
!= EOBJ_S_C_ETIR
1386 && type
!= EOBJ_S_C_EDBG
1387 && type
!= EOBJ_S_C_ETBT
)
1389 err
= _bfd_vms_slurp_relocs (abfd
);
1393 vms_debug (2, "slurp relocs failed with %d\n", err
);
1398 while (type
!= EOBJ_S_C_EEOM
);
1401 amt
= section
->reloc_count
* sizeof (arelent
);
1402 internal_relocs
= (arelent
*) bfd_zalloc (abfd
, amt
);
1403 if (internal_relocs
== NULL
)
1406 /* Decode and internalize the relocations. */
1407 err
= _bfd_vms_decode_relocs (abfd
, internal_relocs
, section
, symbols
);
1411 vms_debug (2, "decode relocs failed with %d\n", err
);
1416 /* We're done with the external relocations. Free them. */
1417 free (vms_section_data (section
)->reloc_stream
);
1418 vms_section_data (section
)->reloc_stream
= NULL
;
1420 /* Save our results and return success. */
1421 section
->relocation
= internal_relocs
;
1425 /* Return the number of bytes required to store the relocation
1426 information associated with the given section. */
1429 vms_get_reloc_upper_bound (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
)
1431 return (section
->reloc_count
+ 1) * sizeof (arelent
*);
1434 /* Convert relocations from VMS (external) form into BFD internal
1435 form. Return the number of relocations. */
1438 vms_canonicalize_reloc (bfd
*abfd
, asection
*section
, arelent
**relptr
,
1444 if (! vms_slurp_reloc_table (abfd
, section
, symbols
))
1447 count
= section
->reloc_count
;
1448 tblptr
= section
->relocation
;
1451 *relptr
++ = tblptr
++;
1453 *relptr
= (arelent
*) NULL
;
1454 return section
->reloc_count
;
1457 /* This is just copied from ecoff-alpha, needs to be fixed probably. */
1459 /* How to process the various reloc types. */
1461 static bfd_reloc_status_type
1462 reloc_nil (bfd
* abfd ATTRIBUTE_UNUSED
,
1463 arelent
*reloc ATTRIBUTE_UNUSED
,
1464 asymbol
*sym ATTRIBUTE_UNUSED
,
1465 void * data ATTRIBUTE_UNUSED
,
1466 asection
*sec ATTRIBUTE_UNUSED
,
1467 bfd
*output_bfd ATTRIBUTE_UNUSED
,
1468 char **error_message ATTRIBUTE_UNUSED
)
1471 vms_debug (1, "reloc_nil (abfd %p, output_bfd %p)\n", abfd
, output_bfd
);
1472 vms_debug (2, "In section %s, symbol %s\n",
1473 sec
->name
, sym
->name
);
1474 vms_debug (2, "reloc sym %s, addr %08lx, addend %08lx, reloc is a %s\n",
1475 reloc
->sym_ptr_ptr
[0]->name
,
1476 (unsigned long)reloc
->address
,
1477 (unsigned long)reloc
->addend
, reloc
->howto
->name
);
1478 vms_debug (2, "data at %p\n", data
);
1479 /* _bfd_hexdump (2, data, bfd_get_reloc_size (reloc->howto), 0); */
1482 return bfd_reloc_ok
;
1485 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
1486 from smaller values. Start with zero, widen, *then* decrement. */
1487 #define MINUS_ONE (((bfd_vma)0) - 1)
1489 static reloc_howto_type alpha_howto_table
[] =
1491 HOWTO (ALPHA_R_IGNORE
, /* Type. */
1492 0, /* Rightshift. */
1493 0, /* Size (0 = byte, 1 = short, 2 = long). */
1495 TRUE
, /* PC relative. */
1497 complain_overflow_dont
,/* Complain_on_overflow. */
1498 reloc_nil
, /* Special_function. */
1499 "IGNORE", /* Name. */
1500 TRUE
, /* Partial_inplace. */
1501 0, /* Source mask */
1503 TRUE
), /* PC rel offset. */
1505 /* A 64 bit reference to a symbol. */
1506 HOWTO (ALPHA_R_REFQUAD
, /* Type. */
1507 0, /* Rightshift. */
1508 4, /* Size (0 = byte, 1 = short, 2 = long). */
1510 FALSE
, /* PC relative. */
1512 complain_overflow_bitfield
, /* Complain_on_overflow. */
1513 reloc_nil
, /* Special_function. */
1514 "REFQUAD", /* Name. */
1515 TRUE
, /* Partial_inplace. */
1516 MINUS_ONE
, /* Source mask. */
1517 MINUS_ONE
, /* Dest mask. */
1518 FALSE
), /* PC rel offset. */
1520 /* A 21 bit branch. The native assembler generates these for
1521 branches within the text segment, and also fills in the PC
1522 relative offset in the instruction. */
1523 HOWTO (ALPHA_R_BRADDR
, /* Type. */
1524 2, /* Rightshift. */
1525 2, /* Size (0 = byte, 1 = short, 2 = long). */
1527 TRUE
, /* PC relative. */
1529 complain_overflow_signed
, /* Complain_on_overflow. */
1530 reloc_nil
, /* Special_function. */
1531 "BRADDR", /* Name. */
1532 TRUE
, /* Partial_inplace. */
1533 0x1fffff, /* Source mask. */
1534 0x1fffff, /* Dest mask. */
1535 FALSE
), /* PC rel offset. */
1537 /* A hint for a jump to a register. */
1538 HOWTO (ALPHA_R_HINT
, /* Type. */
1539 2, /* Rightshift. */
1540 1, /* Size (0 = byte, 1 = short, 2 = long). */
1542 TRUE
, /* PC relative. */
1544 complain_overflow_dont
,/* Complain_on_overflow. */
1545 reloc_nil
, /* Special_function. */
1547 TRUE
, /* Partial_inplace. */
1548 0x3fff, /* Source mask. */
1549 0x3fff, /* Dest mask. */
1550 FALSE
), /* PC rel offset. */
1552 /* 16 bit PC relative offset. */
1553 HOWTO (ALPHA_R_SREL16
, /* Type. */
1554 0, /* Rightshift. */
1555 1, /* Size (0 = byte, 1 = short, 2 = long). */
1557 TRUE
, /* PC relative. */
1559 complain_overflow_signed
, /* Complain_on_overflow. */
1560 reloc_nil
, /* Special_function. */
1561 "SREL16", /* Name. */
1562 TRUE
, /* Partial_inplace. */
1563 0xffff, /* Source mask. */
1564 0xffff, /* Dest mask. */
1565 FALSE
), /* PC rel offset. */
1567 /* 32 bit PC relative offset. */
1568 HOWTO (ALPHA_R_SREL32
, /* Type. */
1569 0, /* Rightshift. */
1570 2, /* Size (0 = byte, 1 = short, 2 = long). */
1572 TRUE
, /* PC relative. */
1574 complain_overflow_signed
, /* Complain_on_overflow. */
1575 reloc_nil
, /* Special_function. */
1576 "SREL32", /* Name. */
1577 TRUE
, /* Partial_inplace. */
1578 0xffffffff, /* Source mask. */
1579 0xffffffff, /* Dest mask. */
1580 FALSE
), /* PC rel offset. */
1582 /* A 64 bit PC relative offset. */
1583 HOWTO (ALPHA_R_SREL64
, /* Type. */
1584 0, /* Rightshift. */
1585 4, /* Size (0 = byte, 1 = short, 2 = long). */
1587 TRUE
, /* PC relative. */
1589 complain_overflow_signed
, /* Complain_on_overflow. */
1590 reloc_nil
, /* Special_function. */
1591 "SREL64", /* Name. */
1592 TRUE
, /* Partial_inplace. */
1593 MINUS_ONE
, /* Source mask. */
1594 MINUS_ONE
, /* Dest mask. */
1595 FALSE
), /* PC rel offset. */
1597 /* Push a value on the reloc evaluation stack. */
1598 HOWTO (ALPHA_R_OP_PUSH
, /* Type. */
1599 0, /* Rightshift. */
1600 0, /* Size (0 = byte, 1 = short, 2 = long). */
1602 FALSE
, /* PC relative. */
1604 complain_overflow_dont
,/* Complain_on_overflow. */
1605 reloc_nil
, /* Special_function. */
1606 "OP_PUSH", /* Name. */
1607 FALSE
, /* Partial_inplace. */
1608 0, /* Source mask. */
1610 FALSE
), /* PC rel offset. */
1612 /* Store the value from the stack at the given address. Store it in
1613 a bitfield of size r_size starting at bit position r_offset. */
1614 HOWTO (ALPHA_R_OP_STORE
, /* Type. */
1615 0, /* Rightshift. */
1616 4, /* Size (0 = byte, 1 = short, 2 = long). */
1618 FALSE
, /* PC relative. */
1620 complain_overflow_dont
,/* Complain_on_overflow. */
1621 reloc_nil
, /* Special_function. */
1622 "OP_STORE", /* Name. */
1623 FALSE
, /* Partial_inplace. */
1624 0, /* Source mask. */
1625 MINUS_ONE
, /* Dest mask. */
1626 FALSE
), /* PC rel offset. */
1628 /* Subtract the reloc address from the value on the top of the
1629 relocation stack. */
1630 HOWTO (ALPHA_R_OP_PSUB
, /* Type. */
1631 0, /* Rightshift. */
1632 0, /* Size (0 = byte, 1 = short, 2 = long). */
1634 FALSE
, /* PC relative. */
1636 complain_overflow_dont
,/* Complain_on_overflow. */
1637 reloc_nil
, /* Special_function. */
1638 "OP_PSUB", /* Name. */
1639 FALSE
, /* Partial_inplace. */
1640 0, /* Source mask. */
1642 FALSE
), /* PC rel offset. */
1644 /* Shift the value on the top of the relocation stack right by the
1646 HOWTO (ALPHA_R_OP_PRSHIFT
, /* Type. */
1647 0, /* Rightshift. */
1648 0, /* Size (0 = byte, 1 = short, 2 = long). */
1650 FALSE
, /* PC relative. */
1652 complain_overflow_dont
,/* Complain_on_overflow. */
1653 reloc_nil
, /* Special_function. */
1654 "OP_PRSHIFT", /* Name. */
1655 FALSE
, /* Partial_inplace. */
1656 0, /* Source mask. */
1658 FALSE
), /* PC rel offset. */
1660 /* Hack. Linkage is done by linker. */
1661 HOWTO (ALPHA_R_LINKAGE
, /* Type. */
1662 0, /* Rightshift. */
1663 8, /* Size (0 = byte, 1 = short, 2 = long). */
1665 FALSE
, /* PC relative. */
1667 complain_overflow_dont
,/* Complain_on_overflow. */
1668 reloc_nil
, /* Special_function. */
1669 "LINKAGE", /* Name. */
1670 FALSE
, /* Partial_inplace. */
1671 0, /* Source mask. */
1673 FALSE
), /* PC rel offset. */
1675 /* A 32 bit reference to a symbol. */
1676 HOWTO (ALPHA_R_REFLONG
, /* Type. */
1677 0, /* Rightshift. */
1678 2, /* Size (0 = byte, 1 = short, 2 = long). */
1680 FALSE
, /* PC relative. */
1682 complain_overflow_bitfield
, /* Complain_on_overflow. */
1683 reloc_nil
, /* Special_function. */
1684 "REFLONG", /* Name. */
1685 TRUE
, /* Partial_inplace. */
1686 0xffffffff, /* Source mask. */
1687 0xffffffff, /* Dest mask. */
1688 FALSE
), /* PC rel offset. */
1690 /* A 64 bit reference to a procedure, written as 32 bit value. */
1691 HOWTO (ALPHA_R_CODEADDR
, /* Type. */
1692 0, /* Rightshift. */
1693 4, /* Size (0 = byte, 1 = short, 2 = long). */
1695 FALSE
, /* PC relative. */
1697 complain_overflow_signed
,/* Complain_on_overflow. */
1698 reloc_nil
, /* Special_function. */
1699 "CODEADDR", /* Name. */
1700 FALSE
, /* Partial_inplace. */
1701 0xffffffff, /* Source mask. */
1702 0xffffffff, /* Dest mask. */
1703 FALSE
), /* PC rel offset. */
1705 HOWTO (ALPHA_R_NOP
, /* Type. */
1706 0, /* Rightshift. */
1707 3, /* Size (0 = byte, 1 = short, 2 = long). */
1709 /* The following value must match that of ALPHA_R_BSR/ALPHA_R_BOH
1710 because the calculations for the 3 relocations are the same.
1711 See B.4.5.2 of the OpenVMS Linker Utility Manual. */
1712 TRUE
, /* PC relative. */
1714 complain_overflow_dont
,/* Complain_on_overflow. */
1715 reloc_nil
, /* Special_function. */
1717 FALSE
, /* Partial_inplace. */
1718 0xffffffff, /* Source mask. */
1719 0xffffffff, /* Dest mask. */
1720 FALSE
), /* PC rel offset. */
1722 HOWTO (ALPHA_R_BSR
, /* Type. */
1723 0, /* Rightshift. */
1724 3, /* Size (0 = byte, 1 = short, 2 = long). */
1726 TRUE
, /* PC relative. */
1728 complain_overflow_dont
,/* Complain_on_overflow. */
1729 reloc_nil
, /* Special_function. */
1731 FALSE
, /* Partial_inplace. */
1732 0xffffffff, /* Source mask. */
1733 0xffffffff, /* Dest mask. */
1734 FALSE
), /* PC rel offset. */
1736 HOWTO (ALPHA_R_LDA
, /* Type. */
1737 0, /* Rightshift. */
1738 3, /* Size (0 = byte, 1 = short, 2 = long). */
1740 FALSE
, /* PC relative. */
1742 complain_overflow_dont
,/* Complain_on_overflow. */
1743 reloc_nil
, /* Special_function. */
1745 FALSE
, /* Partial_inplace. */
1746 0xffffffff, /* Source mask. */
1747 0xffffffff, /* Dest mask. */
1748 FALSE
), /* PC rel offset. */
1750 HOWTO (ALPHA_R_BOH
, /* Type. */
1751 0, /* Rightshift. */
1752 3, /* Size (0 = byte, 1 = short, 2 = long, 3 = nil). */
1754 TRUE
, /* PC relative. */
1756 complain_overflow_dont
,/* Complain_on_overflow. */
1757 reloc_nil
, /* Special_function. */
1759 FALSE
, /* Partial_inplace. */
1760 0xffffffff, /* Source mask. */
1761 0xffffffff, /* Dest mask. */
1762 FALSE
), /* PC rel offset. */
1765 /* Return a pointer to a howto structure which, when invoked, will perform
1766 the relocation code on data from the architecture noted. */
1768 static const struct reloc_howto_struct
*
1769 vms_bfd_reloc_type_lookup (bfd
* abfd ATTRIBUTE_UNUSED
,
1770 bfd_reloc_code_real_type code
)
1775 vms_debug (1, "vms_bfd_reloc_type_lookup (%p, %d)\t", abfd
, code
);
1780 case BFD_RELOC_16
: alpha_type
= ALPHA_R_SREL16
; break;
1781 case BFD_RELOC_32
: alpha_type
= ALPHA_R_REFLONG
; break;
1782 case BFD_RELOC_64
: alpha_type
= ALPHA_R_REFQUAD
; break;
1783 case BFD_RELOC_CTOR
: alpha_type
= ALPHA_R_REFQUAD
; break;
1784 case BFD_RELOC_23_PCREL_S2
: alpha_type
= ALPHA_R_BRADDR
; break;
1785 case BFD_RELOC_ALPHA_HINT
: alpha_type
= ALPHA_R_HINT
; break;
1786 case BFD_RELOC_16_PCREL
: alpha_type
= ALPHA_R_SREL16
; break;
1787 case BFD_RELOC_32_PCREL
: alpha_type
= ALPHA_R_SREL32
; break;
1788 case BFD_RELOC_64_PCREL
: alpha_type
= ALPHA_R_SREL64
; break;
1789 case BFD_RELOC_ALPHA_LINKAGE
: alpha_type
= ALPHA_R_LINKAGE
; break;
1790 case BFD_RELOC_ALPHA_CODEADDR
: alpha_type
= ALPHA_R_CODEADDR
; break;
1791 case BFD_RELOC_ALPHA_NOP
: alpha_type
= ALPHA_R_NOP
; break;
1792 case BFD_RELOC_ALPHA_BSR
: alpha_type
= ALPHA_R_BSR
; break;
1793 case BFD_RELOC_ALPHA_LDA
: alpha_type
= ALPHA_R_LDA
; break;
1794 case BFD_RELOC_ALPHA_BOH
: alpha_type
= ALPHA_R_BOH
; break;
1796 (*_bfd_error_handler
) ("reloc (%d) is *UNKNOWN*", code
);
1800 vms_debug (2, "reloc is %s\n", alpha_howto_table
[alpha_type
].name
);
1802 return & alpha_howto_table
[alpha_type
];
1805 static reloc_howto_type
*
1806 vms_bfd_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1812 i
< sizeof (alpha_howto_table
) / sizeof (alpha_howto_table
[0]);
1814 if (alpha_howto_table
[i
].name
!= NULL
1815 && strcasecmp (alpha_howto_table
[i
].name
, r_name
) == 0)
1816 return &alpha_howto_table
[i
];
1821 /* Part 4.7, writing an object file. */
1823 /* Set the architecture and machine type in BFD abfd to arch and mach.
1824 Find the correct pointer to a structure and insert it into the arch_info
1828 vms_set_arch_mach (bfd
* abfd
,
1829 enum bfd_architecture arch ATTRIBUTE_UNUSED
,
1830 unsigned long mach ATTRIBUTE_UNUSED
)
1833 vms_debug (1, "vms_set_arch_mach (%p, %d, %ld)\n", abfd
, arch
, mach
);
1836 if (arch
!= bfd_arch_alpha
1837 && arch
!= bfd_arch_vax
1838 && arch
!= bfd_arch_unknown
)
1841 return bfd_default_set_arch_mach (abfd
, arch
, mach
);
1844 /* Sets the contents of the section section in BFD abfd to the data starting
1845 in memory at LOCATION. The data is written to the output section starting
1846 at offset offset for count bytes.
1848 Normally TRUE is returned, else FALSE. Possible error returns are:
1849 o bfd_error_no_contents - The output section does not have the
1850 SEC_HAS_CONTENTS attribute, so nothing can be written to it.
1851 o and some more too */
1854 vms_set_section_contents (bfd
* abfd
,
1856 const void * location
,
1858 bfd_size_type count
)
1861 vms_debug (1, "vms_set_section_contents (%p, sec %s, loc %p, off %ld, count %d)\n",
1862 abfd
, section
->name
, location
, (long int)offset
, (int)count
);
1863 vms_debug (2, "size %d\n", (int) section
->size
);
1865 if (count
== (bfd_size_type
)0)
1868 if (section
->contents
== NULL
)
1869 section
->contents
= bfd_alloc (abfd
, section
->size
);
1870 if (section
->contents
== NULL
)
1873 memcpy (section
->contents
+ offset
, location
, (size_t) count
);
1877 /* Part 4.8, linker. */
1879 /* Get the size of the section headers. */
1882 vms_sizeof_headers (bfd
* abfd ATTRIBUTE_UNUSED
,
1883 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1886 vms_debug (1, "vms_sizeof_headers (%p, %s)\n", abfd
, (reloc
)?"True":"False");
1891 /* Provides default handling of relocation effort for back ends
1892 which can't be bothered to do it efficiently. */
1895 vms_bfd_get_relocated_section_contents (bfd
* abfd ATTRIBUTE_UNUSED
,
1896 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1897 struct bfd_link_order
*link_order ATTRIBUTE_UNUSED
,
1898 bfd_byte
*data ATTRIBUTE_UNUSED
,
1899 bfd_boolean relocatable ATTRIBUTE_UNUSED
,
1900 asymbol
**symbols ATTRIBUTE_UNUSED
)
1903 vms_debug (1, "vms_bfd_get_relocated_section_contents (%p, %p, %p, %p, %s, %p)\n",
1904 abfd
, link_info
, link_order
, data
, (relocatable
)?"True":"False", symbols
);
1912 vms_bfd_relax_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1913 asection
*section ATTRIBUTE_UNUSED
,
1914 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1915 bfd_boolean
*again ATTRIBUTE_UNUSED
)
1917 if (link_info
->relocatable
)
1918 (*link_info
->callbacks
->einfo
)
1919 (_("%P%F: --relax and -r may not be used together\n"));
1922 vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, <ret>)\n",
1923 abfd
, section
->name
, link_info
);
1929 vms_bfd_gc_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1930 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1933 vms_debug (1, "vms_bfd_gc_sections (%p, %p)\n", abfd
, link_info
);
1939 vms_bfd_merge_sections (bfd
* abfd ATTRIBUTE_UNUSED
,
1940 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1943 vms_debug (1, "vms_bfd_merge_sections (%p, %p)\n", abfd
, link_info
);
1948 /* Create a hash table for the linker. Different backends store
1949 different information in this table. */
1951 static struct bfd_link_hash_table
*
1952 vms_bfd_link_hash_table_create (bfd
* abfd ATTRIBUTE_UNUSED
)
1955 vms_debug (1, "vms_bfd_link_hash_table_create (%p)\n", abfd
);
1960 /* Free a linker hash table. */
1963 vms_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash ATTRIBUTE_UNUSED
)
1966 vms_debug (1, "vms_bfd_link_hash_table_free (%p)\n", abfd
);
1970 /* Add symbols from this object file into the hash table. */
1973 vms_bfd_link_add_symbols (bfd
* abfd ATTRIBUTE_UNUSED
,
1974 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1977 vms_debug (1, "vms_bfd_link_add_symbols (%p, %p)\n", abfd
, link_info
);
1982 /* Do a link based on the link_order structures attached to each
1983 section of the BFD. */
1986 vms_bfd_final_link (bfd
* abfd ATTRIBUTE_UNUSED
,
1987 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
)
1990 vms_debug (1, "vms_bfd_final_link (%p, %p)\n", abfd
, link_info
);
1995 /* Should this section be split up into smaller pieces during linking. */
1998 vms_bfd_link_split_section (bfd
* abfd ATTRIBUTE_UNUSED
,
1999 asection
*section ATTRIBUTE_UNUSED
)
2002 vms_debug (1, "vms_bfd_link_split_section (%p, %s)\n", abfd
, section
->name
);
2007 /* Part 4.9, dynamic symbols and relocations. */
2009 /* Get the amount of memory required to hold the dynamic symbols. */
2012 vms_get_dynamic_symtab_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2015 vms_debug (1, "vms_get_dynamic_symtab_upper_bound (%p)\n", abfd
);
2021 vms_bfd_print_private_bfd_data (bfd
* abfd ATTRIBUTE_UNUSED
,
2022 void *file ATTRIBUTE_UNUSED
)
2025 vms_debug (1, "vms_bfd_print_private_bfd_data (%p)\n", abfd
);
2030 /* Read in the dynamic symbols. */
2033 vms_canonicalize_dynamic_symtab (bfd
* abfd ATTRIBUTE_UNUSED
,
2034 asymbol
**symbols ATTRIBUTE_UNUSED
)
2037 vms_debug (1, "vms_canonicalize_dynamic_symtab (%p, <ret>)\n", abfd
);
2042 /* Get the amount of memory required to hold the dynamic relocs. */
2045 vms_get_dynamic_reloc_upper_bound (bfd
* abfd ATTRIBUTE_UNUSED
)
2048 vms_debug (1, "vms_get_dynamic_reloc_upper_bound (%p)\n", abfd
);
2053 /* Read in the dynamic relocs. */
2056 vms_canonicalize_dynamic_reloc (bfd
* abfd ATTRIBUTE_UNUSED
,
2057 arelent
**arel ATTRIBUTE_UNUSED
,
2058 asymbol
**symbols ATTRIBUTE_UNUSED
)
2061 vms_debug (1, "vms_canonicalize_dynamic_reloc (%p)\n", abfd
);
2066 const bfd_target vms_alpha_vec
=
2068 "vms-alpha", /* Name. */
2069 bfd_target_evax_flavour
,
2070 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2071 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2073 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| HAS_SYMS
| HAS_LOCALS
2074 | WP_TEXT
| D_PAGED
), /* Object flags. */
2075 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2076 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2077 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2078 0, /* symbol_leading_char. */
2079 ' ', /* ar_pad_char. */
2080 15, /* ar_max_namelen. */
2081 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2082 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2083 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2084 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2085 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2086 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
,
2088 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2089 vms_archive_p
, _bfd_dummy_target
},
2090 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2091 _bfd_generic_mkarchive
, bfd_false
},
2092 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2093 _bfd_write_archive_contents
, bfd_false
},
2095 BFD_JUMP_TABLE_GENERIC (vms
),
2096 BFD_JUMP_TABLE_COPY (vms
),
2097 BFD_JUMP_TABLE_CORE (vms
),
2098 BFD_JUMP_TABLE_ARCHIVE (vms
),
2099 BFD_JUMP_TABLE_SYMBOLS (vms
),
2100 BFD_JUMP_TABLE_RELOCS (vms
),
2101 BFD_JUMP_TABLE_WRITE (vms
),
2102 BFD_JUMP_TABLE_LINK (vms
),
2103 BFD_JUMP_TABLE_DYNAMIC (vms
),
2110 const bfd_target vms_vax_vec
=
2112 "vms-vax", /* Name. */
2113 bfd_target_ovax_flavour
,
2114 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
2115 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
2117 (HAS_RELOC
| HAS_SYMS
/* Object flags. */
2119 | HAS_LINENO
| HAS_DEBUG
| HAS_LOCALS
),
2121 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
2122 | SEC_READONLY
| SEC_CODE
| SEC_DATA
2123 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
), /* Sect flags. */
2124 0, /* symbol_leading_char */
2125 ' ', /* ar_pad_char */
2126 15, /* ar_max_namelen */
2127 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2128 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2129 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
2130 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2131 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2132 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
2134 {_bfd_dummy_target
, vms_object_p
, /* bfd_check_format. */
2135 vms_archive_p
, _bfd_dummy_target
},
2136 {bfd_false
, vms_mkobject
, /* bfd_set_format. */
2137 _bfd_generic_mkarchive
, bfd_false
},
2138 {bfd_false
, vms_write_object_contents
, /* bfd_write_contents. */
2139 _bfd_write_archive_contents
, bfd_false
},
2141 BFD_JUMP_TABLE_GENERIC (vms
),
2142 BFD_JUMP_TABLE_COPY (vms
),
2143 BFD_JUMP_TABLE_CORE (vms
),
2144 BFD_JUMP_TABLE_ARCHIVE (vms
),
2145 BFD_JUMP_TABLE_SYMBOLS (vms
),
2146 BFD_JUMP_TABLE_RELOCS (vms
),
2147 BFD_JUMP_TABLE_WRITE (vms
),
2148 BFD_JUMP_TABLE_LINK (vms
),
2149 BFD_JUMP_TABLE_DYNAMIC (vms
),