Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD ECOFF object file private structure. |
7920ce38 NC |
2 | Copyright 1993, 1994, 1995, 1996, 1999, 2001, 2002, 2003, 2004, |
3 | 2005 Free Software Foundation, Inc. | |
252b5132 RH |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
7920ce38 | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
7920ce38 NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
252b5132 | 12 | |
7920ce38 NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
252b5132 | 17 | |
7920ce38 NC |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
3e110533 | 20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
21 | |
22 | #include "bfdlink.h" | |
23 | ||
24 | #ifndef ECOFF_H | |
25 | #include "coff/ecoff.h" | |
26 | #endif | |
27 | ||
28 | /* This is the backend information kept for ECOFF files. This | |
29 | structure is constant for a particular backend. The first element | |
30 | is the COFF backend data structure, so that ECOFF targets can use | |
31 | the generic COFF code. */ | |
32 | ||
33 | #define ecoff_backend(abfd) \ | |
34 | ((struct ecoff_backend_data *) (abfd)->xvec->backend_data) | |
35 | ||
36 | struct ecoff_backend_data | |
37 | { | |
38 | /* COFF backend information. This must be the first field. */ | |
39 | bfd_coff_backend_data coff; | |
40 | /* Supported architecture. */ | |
41 | enum bfd_architecture arch; | |
42 | /* Initial portion of armap string. */ | |
43 | const char *armap_start; | |
44 | /* The page boundary used to align sections in a demand-paged | |
45 | executable file. E.g., 0x1000. */ | |
46 | bfd_vma round; | |
b34976b6 AM |
47 | /* TRUE if the .rdata section is part of the text segment, as on the |
48 | Alpha. FALSE if .rdata is part of the data segment, as on the | |
252b5132 | 49 | MIPS. */ |
b34976b6 | 50 | bfd_boolean rdata_in_text; |
252b5132 RH |
51 | /* Bitsize of constructor entries. */ |
52 | unsigned int constructor_bitsize; | |
53 | /* Reloc to use for constructor entries. */ | |
54 | reloc_howto_type *constructor_reloc; | |
55 | /* How to swap debugging information. */ | |
56 | struct ecoff_debug_swap debug_swap; | |
57 | /* External reloc size. */ | |
58 | bfd_size_type external_reloc_size; | |
59 | /* Reloc swapping functions. */ | |
7920ce38 NC |
60 | void (*swap_reloc_in) (bfd *, void *, struct internal_reloc *); |
61 | void (*swap_reloc_out) (bfd *, const struct internal_reloc *, void *); | |
252b5132 | 62 | /* Backend reloc tweaking. */ |
b34976b6 | 63 | void (*adjust_reloc_in) |
7920ce38 | 64 | (bfd *, const struct internal_reloc *, arelent *); |
b34976b6 | 65 | void (*adjust_reloc_out) |
7920ce38 | 66 | (bfd *, const arelent *, struct internal_reloc *); |
252b5132 | 67 | /* Relocate section contents while linking. */ |
b34976b6 | 68 | bfd_boolean (*relocate_section) |
7920ce38 | 69 | (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, void *); |
252b5132 | 70 | /* Do final adjustments to filehdr and aouthdr. */ |
b34976b6 | 71 | bfd_boolean (*adjust_headers) |
7920ce38 | 72 | (bfd *, struct internal_filehdr *, struct internal_aouthdr *); |
252b5132 RH |
73 | /* Read an element from an archive at a given file position. This |
74 | is needed because OSF/1 3.2 uses a weird archive format. */ | |
7920ce38 | 75 | bfd *(*get_elt_at_filepos) (bfd *, file_ptr); |
252b5132 RH |
76 | }; |
77 | ||
78 | /* This is the target specific information kept for ECOFF files. */ | |
79 | ||
80 | #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data) | |
81 | ||
82 | typedef struct ecoff_tdata | |
83 | { | |
84 | /* The reloc file position, set by | |
85 | ecoff_compute_section_file_positions. */ | |
86 | file_ptr reloc_filepos; | |
87 | ||
88 | /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */ | |
89 | file_ptr sym_filepos; | |
90 | ||
91 | /* The start and end of the text segment. Only valid for an | |
92 | existing file, not for one we are creating. */ | |
93 | unsigned long text_start; | |
94 | unsigned long text_end; | |
95 | ||
96 | /* The cached gp value. This is used when relocating. */ | |
97 | bfd_vma gp; | |
98 | ||
99 | /* The maximum size of objects to optimize using gp. This is | |
100 | typically set by the -G option to the compiler, assembler or | |
101 | linker. */ | |
102 | unsigned int gp_size; | |
103 | ||
104 | /* The register masks. When linking, all the masks found in the | |
105 | input files are combined into the masks of the output file. | |
106 | These are not all used for all targets, but that's OK, because | |
107 | the relevant ones are the only ones swapped in and out. */ | |
108 | unsigned long gprmask; | |
109 | unsigned long fprmask; | |
110 | unsigned long cprmask[4]; | |
111 | ||
112 | /* The ECOFF symbolic debugging information. */ | |
113 | struct ecoff_debug_info debug_info; | |
114 | ||
115 | /* The unswapped ECOFF symbolic information. */ | |
7920ce38 | 116 | void * raw_syments; |
252b5132 RH |
117 | |
118 | /* The canonical BFD symbols. */ | |
119 | struct ecoff_symbol_struct *canonical_symbols; | |
120 | ||
121 | /* A mapping from external symbol numbers to entries in the linker | |
122 | hash table, used when linking. */ | |
123 | struct ecoff_link_hash_entry **sym_hashes; | |
124 | ||
125 | /* A mapping from reloc symbol indices to sections, used when | |
126 | linking. */ | |
127 | asection **symndx_to_section; | |
128 | ||
b34976b6 AM |
129 | /* TRUE if this BFD was written by the backend linker. */ |
130 | bfd_boolean linker; | |
252b5132 | 131 | |
b34976b6 | 132 | /* TRUE if a warning that multiple global pointer values are |
252b5132 | 133 | needed in the output binary was issued already. */ |
b34976b6 | 134 | bfd_boolean issued_multiple_gp_warning; |
252b5132 RH |
135 | |
136 | /* Used by find_nearest_line entry point. The structure could be | |
137 | included directly in this one, but there's no point to wasting | |
138 | the memory just for the infrequently called find_nearest_line. */ | |
139 | struct ecoff_find_line *find_line_info; | |
140 | ||
141 | /* Whether the .rdata section is in the text segment for this | |
142 | particular ECOFF file. This is not valid until | |
143 | ecoff_compute_section_file_positions is called. */ | |
b34976b6 | 144 | bfd_boolean rdata_in_text; |
252b5132 RH |
145 | |
146 | } ecoff_data_type; | |
147 | ||
148 | /* Each canonical asymbol really looks like this. */ | |
149 | ||
150 | typedef struct ecoff_symbol_struct | |
151 | { | |
152 | /* The actual symbol which the rest of BFD works with */ | |
153 | asymbol symbol; | |
154 | ||
155 | /* The fdr for this symbol. */ | |
156 | FDR *fdr; | |
157 | ||
b34976b6 AM |
158 | /* TRUE if this is a local symbol rather than an external one. */ |
159 | bfd_boolean local; | |
252b5132 RH |
160 | |
161 | /* A pointer to the unswapped hidden information for this symbol. | |
162 | This is either a struct sym_ext or a struct ext_ext, depending on | |
163 | the value of the local field above. */ | |
7920ce38 | 164 | void * native; |
252b5132 RH |
165 | } ecoff_symbol_type; |
166 | ||
08da05b0 | 167 | /* We take the address of the first element of an asymbol to ensure that the |
252b5132 RH |
168 | macro is only ever applied to an asymbol. */ |
169 | #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd))) | |
170 | ||
171 | /* We need to save the index of an external symbol when we write it | |
172 | out so that can set the symbol index correctly when we write out | |
173 | the relocs. */ | |
174 | #define ecoff_get_sym_index(symbol) ((symbol)->udata.i) | |
175 | #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx)) | |
176 | ||
3e27568f CD |
177 | /* A pointer to this structure is put in the used_by_bfd pointer of |
178 | a section to keep track of any per-section data. | |
179 | The user_by_bfd pointer will be NULL if the information was not | |
180 | needed. */ | |
252b5132 RH |
181 | |
182 | struct ecoff_section_tdata | |
183 | { | |
252b5132 RH |
184 | /* When producing an executable (i.e., final, non-relocatable link) |
185 | on the Alpha, we may need to use multiple global pointer values | |
186 | to span the entire .lita section. In essence, we allow each | |
187 | input .lita section to have its own gp value. To support this, | |
188 | we need to keep track of the gp values that we picked for each | |
189 | input .lita section . */ | |
190 | bfd_vma gp; | |
191 | }; | |
192 | ||
193 | /* An accessor macro for the ecoff_section_tdata structure. */ | |
194 | #define ecoff_section_data(abfd, sec) \ | |
195 | ((struct ecoff_section_tdata *) (sec)->used_by_bfd) | |
196 | ||
197 | /* ECOFF linker hash table entries. */ | |
198 | ||
199 | struct ecoff_link_hash_entry | |
200 | { | |
201 | struct bfd_link_hash_entry root; | |
202 | /* Symbol index in output file. */ | |
203 | long indx; | |
204 | /* BFD that ext field value came from. */ | |
205 | bfd *abfd; | |
206 | /* ECOFF external symbol information. */ | |
207 | EXTR esym; | |
208 | /* Nonzero if this symbol has been written out. */ | |
209 | char written; | |
210 | /* Nonzero if this symbol was referred to as small undefined. */ | |
211 | char small; | |
212 | }; | |
213 | ||
214 | /* ECOFF linker hash table. */ | |
215 | ||
216 | struct ecoff_link_hash_table | |
217 | { | |
218 | struct bfd_link_hash_table root; | |
219 | }; | |
220 | ||
221 | /* Make an ECOFF object. */ | |
7920ce38 | 222 | extern bfd_boolean _bfd_ecoff_mkobject (bfd *); |
252b5132 RH |
223 | |
224 | /* Read in the ECOFF symbolic debugging information. */ | |
b34976b6 | 225 | extern bfd_boolean _bfd_ecoff_slurp_symbolic_info |
7920ce38 | 226 | (bfd *, asection *, struct ecoff_debug_info *); |
252b5132 RH |
227 | |
228 | /* Generic ECOFF BFD backend vectors. */ | |
229 | ||
7920ce38 NC |
230 | extern bfd_boolean _bfd_ecoff_write_object_contents (bfd *); |
231 | extern const bfd_target *_bfd_ecoff_archive_p (bfd *); | |
252b5132 RH |
232 | |
233 | #define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup | |
234 | #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info | |
b34976b6 | 235 | extern bfd_boolean _bfd_ecoff_new_section_hook |
7920ce38 | 236 | (bfd *, asection *); |
b34976b6 | 237 | extern bfd_boolean _bfd_ecoff_get_section_contents |
7920ce38 | 238 | (bfd *, asection *, void * location, file_ptr, bfd_size_type); |
252b5132 RH |
239 | |
240 | #define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section | |
241 | ||
b34976b6 | 242 | extern bfd_boolean _bfd_ecoff_bfd_copy_private_bfd_data |
7920ce38 | 243 | (bfd *, bfd *); |
252b5132 RH |
244 | #define _bfd_ecoff_bfd_copy_private_section_data \ |
245 | _bfd_generic_bfd_copy_private_section_data | |
246 | ||
247 | #define _bfd_ecoff_bfd_copy_private_symbol_data \ | |
248 | _bfd_generic_bfd_copy_private_symbol_data | |
249 | ||
80fccad2 BW |
250 | #define _bfd_ecoff_bfd_copy_private_header_data \ |
251 | _bfd_generic_bfd_copy_private_header_data | |
252 | ||
252b5132 RH |
253 | #define _bfd_ecoff_bfd_print_private_bfd_data \ |
254 | _bfd_generic_bfd_print_private_bfd_data | |
255 | ||
256 | #define _bfd_ecoff_bfd_merge_private_bfd_data \ | |
257 | _bfd_generic_bfd_merge_private_bfd_data | |
258 | ||
259 | #define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags | |
7920ce38 | 260 | extern bfd_boolean _bfd_ecoff_slurp_armap (bfd *); |
252b5132 RH |
261 | #define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table |
262 | #define _bfd_ecoff_construct_extended_name_table \ | |
263 | _bfd_archive_bsd_construct_extended_name_table | |
264 | #define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname | |
b34976b6 | 265 | extern bfd_boolean _bfd_ecoff_write_armap |
7920ce38 | 266 | (bfd *, unsigned int, struct orl *, unsigned int, int); |
252b5132 RH |
267 | #define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr |
268 | #define _bfd_ecoff_openr_next_archived_file \ | |
269 | bfd_generic_openr_next_archived_file | |
270 | #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index | |
271 | #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
272 | #define _bfd_ecoff_update_armap_timestamp bfd_true | |
3c9458e9 NC |
273 | #define _bfd_ecoff_bfd_is_target_special_symbol \ |
274 | ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) | |
252b5132 | 275 | |
7920ce38 NC |
276 | extern long _bfd_ecoff_get_symtab_upper_bound (bfd *); |
277 | extern long _bfd_ecoff_canonicalize_symtab (bfd *, asymbol **); | |
278 | extern asymbol *_bfd_ecoff_make_empty_symbol (bfd *); | |
252b5132 | 279 | extern void _bfd_ecoff_print_symbol |
7920ce38 | 280 | (bfd *, void *, asymbol *, bfd_print_symbol_type); |
252b5132 | 281 | extern void _bfd_ecoff_get_symbol_info |
7920ce38 | 282 | (bfd *, asymbol *, symbol_info *); |
b34976b6 | 283 | extern bfd_boolean _bfd_ecoff_bfd_is_local_label_name |
7920ce38 | 284 | (bfd *, const char *); |
252b5132 | 285 | #define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno |
b34976b6 | 286 | extern bfd_boolean _bfd_ecoff_find_nearest_line |
7920ce38 NC |
287 | (bfd *, asection *, asymbol **, bfd_vma, const char **, const char **, |
288 | unsigned int *); | |
252b5132 RH |
289 | #define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol |
290 | #define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols | |
291 | #define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
4ab527b0 | 292 | #define _bfd_ecoff_find_inliner_info _bfd_nosymbols_find_inliner_info |
252b5132 RH |
293 | |
294 | #define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound | |
295 | extern long _bfd_ecoff_canonicalize_reloc | |
7920ce38 | 296 | (bfd *, asection *, arelent **, asymbol **symbols); |
252b5132 RH |
297 | /* ecoff_bfd_reloc_type_lookup defined by backend. */ |
298 | ||
b34976b6 | 299 | extern bfd_boolean _bfd_ecoff_set_arch_mach |
7920ce38 | 300 | (bfd *, enum bfd_architecture, unsigned long); |
b34976b6 | 301 | extern bfd_boolean _bfd_ecoff_set_section_contents |
7920ce38 | 302 | (bfd *, asection *, const void * location, file_ptr, bfd_size_type); |
252b5132 | 303 | |
7920ce38 | 304 | extern int _bfd_ecoff_sizeof_headers (bfd *, bfd_boolean); |
252b5132 RH |
305 | /* ecoff_bfd_get_relocated_section_contents defined by backend. */ |
306 | /* ecoff_bfd_relax_section defined by backend. */ | |
307 | extern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create | |
7920ce38 | 308 | (bfd *); |
e2d34d7d | 309 | #define _bfd_ecoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free |
b34976b6 | 310 | extern bfd_boolean _bfd_ecoff_bfd_link_add_symbols |
7920ce38 | 311 | (bfd *, struct bfd_link_info *); |
2d653fc7 | 312 | #define _bfd_ecoff_bfd_link_just_syms _bfd_generic_link_just_syms |
b34976b6 | 313 | extern bfd_boolean _bfd_ecoff_bfd_final_link |
7920ce38 | 314 | (bfd *, struct bfd_link_info *); |
252b5132 RH |
315 | |
316 | /* Hook functions for the generic COFF section reading code. */ | |
317 | ||
7920ce38 | 318 | extern void * _bfd_ecoff_mkobject_hook (bfd *, void *, void *); |
252b5132 | 319 | #define _bfd_ecoff_set_alignment_hook \ |
7920ce38 | 320 | ((void (*) (bfd *, asection *, void *)) bfd_void) |
b34976b6 | 321 | extern bfd_boolean _bfd_ecoff_set_arch_mach_hook |
7920ce38 | 322 | (bfd *, void *); |
b34976b6 | 323 | extern bfd_boolean _bfd_ecoff_styp_to_sec_flags |
7920ce38 NC |
324 | (bfd *, void *, const char *, asection *, flagword *); |
325 | extern bfd_boolean _bfd_ecoff_slurp_symbol_table (bfd *); | |
252b5132 RH |
326 | |
327 | /* ECOFF auxiliary information swapping routines. These are the same | |
328 | for all ECOFF targets, so they are defined in ecofflink.c. */ | |
329 | ||
330 | extern void _bfd_ecoff_swap_tir_in | |
7920ce38 | 331 | (int, const struct tir_ext *, TIR *); |
252b5132 | 332 | extern void _bfd_ecoff_swap_tir_out |
7920ce38 | 333 | (int, const TIR *, struct tir_ext *); |
252b5132 | 334 | extern void _bfd_ecoff_swap_rndx_in |
7920ce38 | 335 | (int, const struct rndx_ext *, RNDXR *); |
252b5132 | 336 | extern void _bfd_ecoff_swap_rndx_out |
7920ce38 | 337 | (int, const RNDXR *, struct rndx_ext *); |