1 /* BFD ECOFF object file private structure.
2 Copyright (C) 1993, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "coff/ecoff.h"
27 /* This is the backend information kept for ECOFF files. This
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. */
32 #define ecoff_backend(abfd) \
33 ((struct ecoff_backend_data *) (abfd)->xvec->backend_data)
35 struct ecoff_backend_data
37 /* COFF backend information. This must be the first field. */
38 bfd_coff_backend_data coff;
39 /* Supported architecture. */
40 enum bfd_architecture arch;
41 /* Initial portion of armap string. */
42 const char *armap_start;
43 /* The page boundary used to align sections in a demand-paged
44 executable file. E.g., 0x1000. */
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
49 boolean rdata_in_text;
50 /* Bitsize of constructor entries. */
51 unsigned int constructor_bitsize;
52 /* Reloc to use for constructor entries. */
53 reloc_howto_type *constructor_reloc;
54 /* How to swap debugging information. */
55 struct ecoff_debug_swap debug_swap;
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));
61 /* Backend reloc tweaking. */
62 void (*adjust_reloc_in) PARAMS ((bfd *, const struct internal_reloc *,
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,
70 PTR external_relocs));
71 /* Do final adjustments to filehdr and aouthdr. */
72 boolean (*adjust_headers) PARAMS ((bfd *, struct internal_filehdr *,
73 struct internal_aouthdr *));
74 /* Read an element from an archive at a given file position. This
75 is needed because OSF/1 3.2 uses a weird archive format. */
76 bfd *(*get_elt_at_filepos) PARAMS ((bfd *, file_ptr));
79 /* This is the target specific information kept for ECOFF files. */
81 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
83 typedef struct ecoff_tdata
85 /* The reloc file position, set by
86 ecoff_compute_section_file_positions. */
87 file_ptr reloc_filepos;
89 /* The symbol table file position, set by _bfd_ecoff_mkobject_hook. */
92 /* The start and end of the text segment. Only valid for an
93 existing file, not for one we are creating. */
94 unsigned long text_start;
95 unsigned long text_end;
97 /* The cached gp value. This is used when relocating. */
100 /* The maximum size of objects to optimize using gp. This is
101 typically set by the -G option to the compiler, assembler or
103 unsigned int gp_size;
105 /* The register masks. When linking, all the masks found in the
106 input files are combined into the masks of the output file.
107 These are not all used for all targets, but that's OK, because
108 the relevant ones are the only ones swapped in and out. */
109 unsigned long gprmask;
110 unsigned long fprmask;
111 unsigned long cprmask[4];
113 /* The ECOFF symbolic debugging information. */
114 struct ecoff_debug_info debug_info;
116 /* The unswapped ECOFF symbolic information. */
119 /* The canonical BFD symbols. */
120 struct ecoff_symbol_struct *canonical_symbols;
122 /* A mapping from external symbol numbers to entries in the linker
123 hash table, used when linking. */
124 struct ecoff_link_hash_entry **sym_hashes;
126 /* A mapping from reloc symbol indices to sections, used when
128 asection **symndx_to_section;
130 /* True if this BFD was written by the backend linker. */
133 /* True if a warning that multiple global pointer values are
134 needed in the output binary was issued already. */
135 boolean issued_multiple_gp_warning;
137 /* Used by find_nearest_line entry point. The structure could be
138 included directly in this one, but there's no point to wasting
139 the memory just for the infrequently called find_nearest_line. */
140 struct ecoff_find_line *find_line_info;
142 /* Whether the .rdata section is in the text segment for this
143 particular ECOFF file. This is not valid until
144 ecoff_compute_section_file_positions is called. */
145 boolean rdata_in_text;
149 /* Each canonical asymbol really looks like this. */
151 typedef struct ecoff_symbol_struct
153 /* The actual symbol which the rest of BFD works with */
156 /* The fdr for this symbol. */
159 /* true if this is a local symbol rather than an external one. */
162 /* A pointer to the unswapped hidden information for this symbol.
163 This is either a struct sym_ext or a struct ext_ext, depending on
164 the value of the local field above. */
168 /* We take the address of the first element of a asymbol to ensure that the
169 macro is only ever applied to an asymbol. */
170 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
172 /* We need to save the index of an external symbol when we write it
173 out so that can set the symbol index correctly when we write out
175 #define ecoff_get_sym_index(symbol) ((symbol)->udata.i)
176 #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata.i = (idx))
178 /* When generating MIPS embedded PIC code, the linker relaxes the code
179 to turn PC relative branches into longer code sequences when the PC
180 relative branch is out of range. This involves reading the relocs
181 in bfd_relax_section as well as in bfd_final_link, and requires the
182 code to keep track of which relocs have been expanded. A pointer
183 to this structure is put in the used_by_bfd pointer of a section to
184 keep track of this information. The user_by_bfd pointer will be
185 NULL if the information was not needed. */
187 struct ecoff_section_tdata
189 /* The unswapped relocs for this section. These are stored in
190 memory so the input file does not have to be read twice. */
193 /* The contents of the section. These bytes may or may not be saved
194 in memory, but if it is this is a pointer to them. */
197 /* Offset adjustments for PC relative branches. A number other than
198 1 is an addend for a PC relative branch, or a switch table entry
199 which is the difference of two .text locations; this addend
200 arises because the branch or difference crosses one or more
201 branches which were expanded into a larger code sequence. A 1
202 means that this branch was itself expanded into a larger code
203 sequence. 1 is not a possible offset, since all offsets must be
204 multiples of the instruction size, which is 4; also, the only
205 relocs with non-zero offsets will be PC relative branches or
206 switch table entries within the same object file. If this field
207 is NULL, no branches were expanded and no offsets are required.
208 Otherwise there are as many entries as there are relocs in the
209 section, and the entry for any reloc that is not PC relative is
213 /* When producing an executable (i.e., final, non-relocatable link)
214 on the Alpha, we may need to use multiple global pointer values
215 to span the entire .lita section. In essence, we allow each
216 input .lita section to have its own gp value. To support this,
217 we need to keep track of the gp values that we picked for each
218 input .lita section . */
222 /* An accessor macro for the ecoff_section_tdata structure. */
223 #define ecoff_section_data(abfd, sec) \
224 ((struct ecoff_section_tdata *) (sec)->used_by_bfd)
226 /* ECOFF linker hash table entries. */
228 struct ecoff_link_hash_entry
230 struct bfd_link_hash_entry root;
231 /* Symbol index in output file. */
233 /* BFD that ext field value came from. */
235 /* ECOFF external symbol information. */
237 /* Nonzero if this symbol has been written out. */
239 /* Nonzero if this symbol was referred to as small undefined. */
243 /* ECOFF linker hash table. */
245 struct ecoff_link_hash_table
247 struct bfd_link_hash_table root;
250 /* Make an ECOFF object. */
251 extern boolean _bfd_ecoff_mkobject PARAMS ((bfd *));
253 /* Read in the ECOFF symbolic debugging information. */
254 extern boolean _bfd_ecoff_slurp_symbolic_info
255 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
257 /* Generic ECOFF BFD backend vectors. */
259 extern boolean _bfd_ecoff_write_object_contents PARAMS ((bfd *abfd));
260 extern const bfd_target *_bfd_ecoff_archive_p PARAMS ((bfd *abfd));
262 #define _bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup
263 #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
264 extern boolean _bfd_ecoff_new_section_hook
265 PARAMS ((bfd *, asection *));
266 extern boolean _bfd_ecoff_get_section_contents
267 PARAMS ((bfd *, asection *, PTR location, file_ptr, bfd_size_type));
269 #define _bfd_ecoff_bfd_link_split_section _bfd_generic_link_split_section
271 extern boolean _bfd_ecoff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
272 #define _bfd_ecoff_bfd_copy_private_section_data \
273 _bfd_generic_bfd_copy_private_section_data
275 #define _bfd_ecoff_bfd_copy_private_symbol_data \
276 _bfd_generic_bfd_copy_private_symbol_data
278 #define _bfd_ecoff_bfd_print_private_bfd_data \
279 _bfd_generic_bfd_print_private_bfd_data
281 #define _bfd_ecoff_bfd_merge_private_bfd_data \
282 _bfd_generic_bfd_merge_private_bfd_data
284 #define _bfd_ecoff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
285 extern boolean _bfd_ecoff_slurp_armap PARAMS ((bfd *abfd));
286 #define _bfd_ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
287 #define _bfd_ecoff_construct_extended_name_table \
288 _bfd_archive_bsd_construct_extended_name_table
289 #define _bfd_ecoff_truncate_arname bfd_dont_truncate_arname
290 extern boolean _bfd_ecoff_write_armap
291 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
292 #define _bfd_ecoff_read_ar_hdr _bfd_generic_read_ar_hdr
293 #define _bfd_ecoff_openr_next_archived_file \
294 bfd_generic_openr_next_archived_file
295 #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index
296 #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
297 #define _bfd_ecoff_update_armap_timestamp bfd_true
299 extern long _bfd_ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
300 extern long _bfd_ecoff_get_symtab PARAMS ((bfd *abfd, asymbol **alocation));
301 extern asymbol *_bfd_ecoff_make_empty_symbol PARAMS ((bfd *abfd));
302 extern void _bfd_ecoff_print_symbol
303 PARAMS ((bfd *, PTR filep, asymbol *, bfd_print_symbol_type));
304 extern void _bfd_ecoff_get_symbol_info
305 PARAMS ((bfd *, asymbol *, symbol_info *));
306 extern boolean _bfd_ecoff_bfd_is_local_label_name
307 PARAMS ((bfd *, const char *));
308 #define _bfd_ecoff_get_lineno _bfd_nosymbols_get_lineno
309 extern boolean _bfd_ecoff_find_nearest_line
310 PARAMS ((bfd *, asection *, asymbol **, bfd_vma offset,
311 const char **filename_ptr, const char **fnname_ptr,
312 unsigned int *retline_ptr));
313 #define _bfd_ecoff_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
314 #define _bfd_ecoff_read_minisymbols _bfd_generic_read_minisymbols
315 #define _bfd_ecoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
317 #define _bfd_ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
318 extern long _bfd_ecoff_canonicalize_reloc
319 PARAMS ((bfd *, asection *, arelent **, asymbol **symbols));
320 /* ecoff_bfd_reloc_type_lookup defined by backend. */
322 extern boolean _bfd_ecoff_set_arch_mach
323 PARAMS ((bfd *, enum bfd_architecture, unsigned long machine));
324 extern boolean _bfd_ecoff_set_section_contents
325 PARAMS ((bfd *, asection *, PTR location, file_ptr, bfd_size_type));
327 extern int _bfd_ecoff_sizeof_headers PARAMS ((bfd *abfd, boolean reloc));
328 /* ecoff_bfd_get_relocated_section_contents defined by backend. */
329 /* ecoff_bfd_relax_section defined by backend. */
330 extern struct bfd_link_hash_table *_bfd_ecoff_bfd_link_hash_table_create
332 extern boolean _bfd_ecoff_bfd_link_add_symbols
333 PARAMS ((bfd *, struct bfd_link_info *));
334 extern boolean _bfd_ecoff_bfd_final_link
335 PARAMS ((bfd *, struct bfd_link_info *));
337 /* Hook functions for the generic COFF section reading code. */
339 extern PTR _bfd_ecoff_mkobject_hook PARAMS ((bfd *, PTR filehdr, PTR aouthdr));
340 #define _bfd_ecoff_set_alignment_hook \
341 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
342 extern boolean _bfd_ecoff_set_arch_mach_hook PARAMS ((bfd *abfd, PTR filehdr));
343 extern flagword _bfd_ecoff_styp_to_sec_flags
344 PARAMS ((bfd *abfd, PTR hdr, const char *name, asection *section));
345 extern boolean _bfd_ecoff_slurp_symbol_table PARAMS ((bfd *abfd));
347 /* ECOFF auxiliary information swapping routines. These are the same
348 for all ECOFF targets, so they are defined in ecofflink.c. */
350 extern void _bfd_ecoff_swap_tir_in
351 PARAMS ((int, const struct tir_ext *, TIR *));
352 extern void _bfd_ecoff_swap_tir_out
353 PARAMS ((int, const TIR *, struct tir_ext *));
354 extern void _bfd_ecoff_swap_rndx_in
355 PARAMS ((int, const struct rndx_ext *, RNDXR *));
356 extern void _bfd_ecoff_swap_rndx_out
357 PARAMS ((int, const RNDXR *, struct rndx_ext *));