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