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