xref: /openbsd-src/gnu/usr.bin/binutils/bfd/doc/coffcode.texi (revision d2201f2f89f0be1a0be6f7568000ed297414a06d)
1fddef416Sniklas@section coff backends
2fddef416SniklasBFD supports a number of different flavours of coff format.
3fddef416SniklasThe major differences between formats are the sizes and
4fddef416Sniklasalignments of fields in structures on disk, and the occasional
5fddef416Sniklasextra field.
6fddef416Sniklas
7fddef416SniklasCoff in all its varieties is implemented with a few common
8fddef416Sniklasfiles and a number of implementation specific files. For
9fddef416Sniklasexample, The 88k bcs coff format is implemented in the file
10fddef416Sniklas@file{coff-m88k.c}. This file @code{#include}s
11fddef416Sniklas@file{coff/m88k.h} which defines the external structure of the
12fddef416Sniklascoff format for the 88k, and @file{coff/internal.h} which
13fddef416Sniklasdefines the internal structure. @file{coff-m88k.c} also
14fddef416Sniklasdefines the relocations used by the 88k format
15fddef416Sniklas@xref{Relocations}.
16fddef416Sniklas
17fddef416SniklasThe Intel i960 processor version of coff is implemented in
18fddef416Sniklas@file{coff-i960.c}. This file has the same structure as
19fddef416Sniklas@file{coff-m88k.c}, except that it includes @file{coff/i960.h}
20fddef416Sniklasrather than @file{coff-m88k.h}.
21f7cc78ecSespie
22fddef416Sniklas@subsection Porting to a new version of coff
23fddef416SniklasThe recommended method is to select from the existing
24fddef416Sniklasimplementations the version of coff which is most like the one
25fddef416Sniklasyou want to use.  For example, we'll say that i386 coff is
26fddef416Sniklasthe one you select, and that your coff flavour is called foo.
27fddef416SniklasCopy @file{i386coff.c} to @file{foocoff.c}, copy
28fddef416Sniklas@file{../include/coff/i386.h} to @file{../include/coff/foo.h},
29fddef416Sniklasand add the lines to @file{targets.c} and @file{Makefile.in}
30fddef416Sniklasso that your new back end is used. Alter the shapes of the
31fddef416Sniklasstructures in @file{../include/coff/foo.h} so that they match
32fddef416Sniklaswhat you need. You will probably also have to add
33fddef416Sniklas@code{#ifdef}s to the code in @file{coff/internal.h} and
34fddef416Sniklas@file{coffcode.h} if your version of coff is too wild.
35fddef416Sniklas
36fddef416SniklasYou can verify that your new BFD backend works quite simply by
37fddef416Sniklasbuilding @file{objdump} from the @file{binutils} directory,
38fddef416Sniklasand making sure that its version of what's going on and your
39fddef416Sniklashost system's idea (assuming it has the pretty standard coff
40fddef416Sniklasdump utility, usually called @code{att-dump} or just
41fddef416Sniklas@code{dump}) are the same.  Then clean up your code, and send
42fddef416Sniklaswhat you've done to Cygnus. Then your stuff will be in the
43fddef416Sniklasnext release, and you won't have to keep integrating it.
44f7cc78ecSespie
45fddef416Sniklas@subsection How the coff backend works
46fddef416Sniklas
47f7cc78ecSespie
48fddef416Sniklas@subsubsection File layout
49fddef416SniklasThe Coff backend is split into generic routines that are
50fddef416Sniklasapplicable to any Coff target and routines that are specific
51fddef416Sniklasto a particular target.  The target-specific routines are
52fddef416Sniklasfurther split into ones which are basically the same for all
53fddef416SniklasCoff targets except that they use the external symbol format
54fddef416Sniklasor use different values for certain constants.
55fddef416Sniklas
56fddef416SniklasThe generic routines are in @file{coffgen.c}.  These routines
57fddef416Sniklaswork for any Coff target.  They use some hooks into the target
58fddef416Sniklasspecific code; the hooks are in a @code{bfd_coff_backend_data}
59fddef416Sniklasstructure, one of which exists for each target.
60fddef416Sniklas
61fddef416SniklasThe essentially similar target-specific routines are in
62fddef416Sniklas@file{coffcode.h}.  This header file includes executable C code.
63fddef416SniklasThe various Coff targets first include the appropriate Coff
64fddef416Sniklasheader file, make any special defines that are needed, and
65fddef416Sniklasthen include @file{coffcode.h}.
66fddef416Sniklas
67fddef416SniklasSome of the Coff targets then also have additional routines in
68fddef416Sniklasthe target source file itself.
69fddef416Sniklas
70fddef416SniklasFor example, @file{coff-i960.c} includes
71fddef416Sniklas@file{coff/internal.h} and @file{coff/i960.h}.  It then
72fddef416Sniklasdefines a few constants, such as @code{I960}, and includes
73fddef416Sniklas@file{coffcode.h}.  Since the i960 has complex relocation
74fddef416Sniklastypes, @file{coff-i960.c} also includes some code to
75fddef416Sniklasmanipulate the i960 relocs.  This code is not in
76fddef416Sniklas@file{coffcode.h} because it would not be used by any other
77fddef416Sniklastarget.
78f7cc78ecSespie
79fddef416Sniklas@subsubsection Bit twiddling
80fddef416SniklasEach flavour of coff supported in BFD has its own header file
81fddef416Sniklasdescribing the external layout of the structures. There is also
82fddef416Sniklasan internal description of the coff layout, in
83fddef416Sniklas@file{coff/internal.h}. A major function of the
84fddef416Sniklascoff backend is swapping the bytes and twiddling the bits to
85fddef416Sniklastranslate the external form of the structures into the normal
86fddef416Sniklasinternal form. This is all performed in the
87fddef416Sniklas@code{bfd_swap}_@i{thing}_@i{direction} routines. Some
88fddef416Sniklaselements are different sizes between different versions of
89fddef416Sniklascoff; it is the duty of the coff version specific include file
90fddef416Sniklasto override the definitions of various packing routines in
91fddef416Sniklas@file{coffcode.h}. E.g., the size of line number entry in coff is
92fddef416Sniklassometimes 16 bits, and sometimes 32 bits. @code{#define}ing
93fddef416Sniklas@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
94fddef416Sniklascorrect one. No doubt, some day someone will find a version of
95fddef416Sniklascoff which has a varying field size not catered to at the
96fddef416Sniklasmoment. To port BFD, that person will have to add more @code{#defines}.
97fddef416SniklasThree of the bit twiddling routines are exported to
98fddef416Sniklas@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
99f7cc78ecSespieand @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
100fddef416Sniklastable on its own, but uses BFD to fix things up.  More of the
101fddef416Sniklasbit twiddlers are exported for @code{gas};
102fddef416Sniklas@code{coff_swap_aux_out}, @code{coff_swap_sym_out},
103fddef416Sniklas@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
104fddef416Sniklas@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
105fddef416Sniklas@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
106fddef416Sniklasof all the symbol table and reloc drudgery itself, thereby
107fddef416Sniklassaving the internal BFD overhead, but uses BFD to swap things
108fddef416Sniklason the way out, making cross ports much safer.  Doing so also
109fddef416Sniklasallows BFD (and thus the linker) to use the same header files
110fddef416Sniklasas @code{gas}, which makes one avenue to disaster disappear.
111f7cc78ecSespie
112fddef416Sniklas@subsubsection Symbol reading
113fddef416SniklasThe simple canonical form for symbols used by BFD is not rich
114fddef416Sniklasenough to keep all the information available in a coff symbol
115fddef416Sniklastable. The back end gets around this problem by keeping the original
116fddef416Sniklassymbol table around, "behind the scenes".
117fddef416Sniklas
118fddef416SniklasWhen a symbol table is requested (through a call to
119fddef416Sniklas@code{bfd_canonicalize_symtab}), a request gets through to
120fddef416Sniklas@code{coff_get_normalized_symtab}. This reads the symbol table from
121fddef416Sniklasthe coff file and swaps all the structures inside into the
122fddef416Sniklasinternal form. It also fixes up all the pointers in the table
123fddef416Sniklas(represented in the file by offsets from the first symbol in
124fddef416Sniklasthe table) into physical pointers to elements in the new
125fddef416Sniklasinternal table. This involves some work since the meanings of
126fddef416Sniklasfields change depending upon context: a field that is a
127fddef416Sniklaspointer to another structure in the symbol table at one moment
128fddef416Sniklasmay be the size in bytes of a structure at the next.  Another
129fddef416Sniklaspass is made over the table. All symbols which mark file names
130fddef416Sniklas(@code{C_FILE} symbols) are modified so that the internal
131fddef416Sniklasstring points to the value in the auxent (the real filename)
132fddef416Sniklasrather than the normal text associated with the symbol
133fddef416Sniklas(@code{".file"}).
134fddef416Sniklas
135fddef416SniklasAt this time the symbol names are moved around. Coff stores
136fddef416Sniklasall symbols less than nine characters long physically
137fddef416Sniklaswithin the symbol table; longer strings are kept at the end of
138fddef416Sniklasthe file in the string  table. This pass moves all strings
139fddef416Sniklasinto memory and replaces them with pointers to the strings.
140fddef416Sniklas
141fddef416SniklasThe symbol table is massaged once again, this time to create
142fddef416Sniklasthe canonical table used by the BFD application. Each symbol
143fddef416Sniklasis inspected in turn, and a decision made (using the
144fddef416Sniklas@code{sclass} field) about the various flags to set in the
145fddef416Sniklas@code{asymbol}.  @xref{Symbols}. The generated canonical table
146fddef416Sniklasshares strings with the hidden internal symbol table.
147fddef416Sniklas
148fddef416SniklasAny linenumbers are read from the coff file too, and attached
149fddef416Sniklasto the symbols which own the functions the linenumbers belong to.
150f7cc78ecSespie
151fddef416Sniklas@subsubsection Symbol writing
152fddef416SniklasWriting a symbol to a coff file which didn't come from a coff
153fddef416Sniklasfile will lose any debugging information. The @code{asymbol}
154fddef416Sniklasstructure remembers the BFD from which the symbol was taken, and on
155fddef416Sniklasoutput the back end makes sure that the same destination target as
156fddef416Sniklassource target is present.
157fddef416Sniklas
158fddef416SniklasWhen the symbols have come from a coff file then all the
159fddef416Sniklasdebugging information is preserved.
160fddef416Sniklas
161fddef416SniklasSymbol tables are provided for writing to the back end in a
162fddef416Sniklasvector of pointers to pointers. This allows applications like
163fddef416Sniklasthe linker to accumulate and output large symbol tables
164fddef416Sniklaswithout having to do too much byte copying.
165fddef416Sniklas
166fddef416SniklasThis function runs through the provided symbol table and
167fddef416Sniklaspatches each symbol marked as a file place holder
168fddef416Sniklas(@code{C_FILE}) to point to the next file place holder in the
169fddef416Sniklaslist. It also marks each @code{offset} field in the list with
170fddef416Sniklasthe offset from the first symbol of the current symbol.
171fddef416Sniklas
172fddef416SniklasAnother function of this procedure is to turn the canonical
173fddef416Sniklasvalue form of BFD into the form used by coff. Internally, BFD
174fddef416Sniklasexpects symbol values to be offsets from a section base; so a
175fddef416Sniklassymbol physically at 0x120, but in a section starting at
176fddef416Sniklas0x100, would have the value 0x20. Coff expects symbols to
177fddef416Sniklascontain their final value, so symbols have their values
178fddef416Sniklaschanged at this point to reflect their sum with their owning
179fddef416Sniklassection.  This transformation uses the
180fddef416Sniklas@code{output_section} field of the @code{asymbol}'s
181fddef416Sniklas@code{asection} @xref{Sections}.
182fddef416Sniklas
183fddef416Sniklas@itemize @bullet
184fddef416Sniklas
185fddef416Sniklas@item
186fddef416Sniklas@code{coff_mangle_symbols}
187fddef416Sniklas@end itemize
188fddef416SniklasThis routine runs though the provided symbol table and uses
189fddef416Sniklasthe offsets generated by the previous pass and the pointers
190fddef416Sniklasgenerated when the symbol table was read in to create the
191*d2201f2fSdrahnstructured hierarchy required by coff. It changes each pointer
192fddef416Sniklasto a symbol into the index into the symbol table of the asymbol.
193fddef416Sniklas
194fddef416Sniklas@itemize @bullet
195fddef416Sniklas
196fddef416Sniklas@item
197fddef416Sniklas@code{coff_write_symbols}
198fddef416Sniklas@end itemize
199fddef416SniklasThis routine runs through the symbol table and patches up the
200fddef416Sniklassymbols from their internal form into the coff way, calls the
201fddef416Sniklasbit twiddlers, and writes out the table to the file.
202f7cc78ecSespie
203fddef416Sniklas@findex coff_symbol_type
204fddef416Sniklas@subsubsection @code{coff_symbol_type}
205fddef416Sniklas@strong{Description}@*
206fddef416SniklasThe hidden information for an @code{asymbol} is described in a
207fddef416Sniklas@code{combined_entry_type}:
208f7cc78ecSespie
209f7cc78ecSespie
210fddef416Sniklas@example
211f7cc78ecSespie
212fddef416Sniklastypedef struct coff_ptr_struct
213fddef416Sniklas@{
214fddef416Sniklas  /* Remembers the offset from the first symbol in the file for
215fddef416Sniklas     this symbol. Generated by coff_renumber_symbols. */
216fddef416Sniklas  unsigned int offset;
217fddef416Sniklas
218fddef416Sniklas  /* Should the value of this symbol be renumbered.  Used for
219fddef416Sniklas     XCOFF C_BSTAT symbols.  Set by coff_slurp_symbol_table.  */
220fddef416Sniklas  unsigned int fix_value : 1;
221fddef416Sniklas
222fddef416Sniklas  /* Should the tag field of this symbol be renumbered.
223fddef416Sniklas     Created by coff_pointerize_aux. */
224fddef416Sniklas  unsigned int fix_tag : 1;
225fddef416Sniklas
226fddef416Sniklas  /* Should the endidx field of this symbol be renumbered.
227fddef416Sniklas     Created by coff_pointerize_aux. */
228fddef416Sniklas  unsigned int fix_end : 1;
229fddef416Sniklas
230fddef416Sniklas  /* Should the x_csect.x_scnlen field be renumbered.
231fddef416Sniklas     Created by coff_pointerize_aux. */
232fddef416Sniklas  unsigned int fix_scnlen : 1;
233fddef416Sniklas
234fddef416Sniklas  /* Fix up an XCOFF C_BINCL/C_EINCL symbol.  The value is the
235*d2201f2fSdrahn     index into the line number entries.  Set by coff_slurp_symbol_table.  */
236fddef416Sniklas  unsigned int fix_line : 1;
237fddef416Sniklas
238fddef416Sniklas  /* The container for the symbol structure as read and translated
239fddef416Sniklas     from the file. */
240*d2201f2fSdrahn  union
241*d2201f2fSdrahn  @{
242fddef416Sniklas    union internal_auxent auxent;
243fddef416Sniklas    struct internal_syment syment;
244fddef416Sniklas  @} u;
245fddef416Sniklas@} combined_entry_type;
246fddef416Sniklas
247fddef416Sniklas
248fddef416Sniklas/* Each canonical asymbol really looks like this: */
249fddef416Sniklas
250fddef416Sniklastypedef struct coff_symbol_struct
251fddef416Sniklas@{
252fddef416Sniklas  /* The actual symbol which the rest of BFD works with */
253fddef416Sniklas  asymbol symbol;
254fddef416Sniklas
255fddef416Sniklas  /* A pointer to the hidden information for this symbol */
256fddef416Sniklas  combined_entry_type *native;
257fddef416Sniklas
258fddef416Sniklas  /* A pointer to the linenumber information for this symbol */
259fddef416Sniklas  struct lineno_cache_entry *lineno;
260fddef416Sniklas
261fddef416Sniklas  /* Have the line numbers been relocated yet ? */
262*d2201f2fSdrahn  bfd_boolean done_lineno;
263fddef416Sniklas@} coff_symbol_type;
264fddef416Sniklas@end example
265fddef416Sniklas@findex bfd_coff_backend_data
266fddef416Sniklas@subsubsection @code{bfd_coff_backend_data}
267f7cc78ecSespie
268f7cc78ecSespie@example
269f7cc78ecSespie/* COFF symbol classifications.  */
270f7cc78ecSespie
271f7cc78ecSespieenum coff_symbol_classification
272f7cc78ecSespie@{
273f7cc78ecSespie  /* Global symbol.  */
274f7cc78ecSespie  COFF_SYMBOL_GLOBAL,
275f7cc78ecSespie  /* Common symbol.  */
276f7cc78ecSespie  COFF_SYMBOL_COMMON,
277f7cc78ecSespie  /* Undefined symbol.  */
278f7cc78ecSespie  COFF_SYMBOL_UNDEFINED,
279f7cc78ecSespie  /* Local symbol.  */
280f7cc78ecSespie  COFF_SYMBOL_LOCAL,
281f7cc78ecSespie  /* PE section symbol.  */
282f7cc78ecSespie  COFF_SYMBOL_PE_SECTION
283f7cc78ecSespie@};
284f7cc78ecSespie
285f7cc78ecSespie@end example
286fddef416SniklasSpecial entry points for gdb to swap in coff symbol table parts:
287fddef416Sniklas@example
288fddef416Sniklastypedef struct
289fddef416Sniklas@{
290*d2201f2fSdrahn  void (*_bfd_coff_swap_aux_in)
291*d2201f2fSdrahn    PARAMS ((bfd *, PTR, int, int, int, int, PTR));
292fddef416Sniklas
293*d2201f2fSdrahn  void (*_bfd_coff_swap_sym_in)
294*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
295fddef416Sniklas
296*d2201f2fSdrahn  void (*_bfd_coff_swap_lineno_in)
297*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
298fddef416Sniklas
299*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_aux_out)
300*d2201f2fSdrahn    PARAMS ((bfd *, PTR, int, int, int, int, PTR));
301fddef416Sniklas
302*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_sym_out)
303*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
304fddef416Sniklas
305*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_lineno_out)
306*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
307fddef416Sniklas
308*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_reloc_out)
309*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
310fddef416Sniklas
311*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_filehdr_out)
312*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
313fddef416Sniklas
314*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_aouthdr_out)
315*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
316fddef416Sniklas
317*d2201f2fSdrahn  unsigned int (*_bfd_coff_swap_scnhdr_out)
318*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
319fddef416Sniklas
320fddef416Sniklas  unsigned int _bfd_filhsz;
321fddef416Sniklas  unsigned int _bfd_aoutsz;
322fddef416Sniklas  unsigned int _bfd_scnhsz;
323fddef416Sniklas  unsigned int _bfd_symesz;
324fddef416Sniklas  unsigned int _bfd_auxesz;
325fddef416Sniklas  unsigned int _bfd_relsz;
326fddef416Sniklas  unsigned int _bfd_linesz;
327f7cc78ecSespie  unsigned int _bfd_filnmlen;
328*d2201f2fSdrahn  bfd_boolean _bfd_coff_long_filenames;
329*d2201f2fSdrahn  bfd_boolean _bfd_coff_long_section_names;
330fddef416Sniklas  unsigned int _bfd_coff_default_section_alignment_power;
331*d2201f2fSdrahn  bfd_boolean _bfd_coff_force_symnames_in_strings;
3325f210c2aSfgsch  unsigned int _bfd_coff_debug_string_prefix_length;
333fddef416Sniklas
334*d2201f2fSdrahn  void (*_bfd_coff_swap_filehdr_in)
335*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
336*d2201f2fSdrahn
337*d2201f2fSdrahn  void (*_bfd_coff_swap_aouthdr_in)
338*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
339*d2201f2fSdrahn
340*d2201f2fSdrahn  void (*_bfd_coff_swap_scnhdr_in)
341*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
342*d2201f2fSdrahn
343*d2201f2fSdrahn  void (*_bfd_coff_swap_reloc_in)
344*d2201f2fSdrahn    PARAMS ((bfd *abfd, PTR, PTR));
345*d2201f2fSdrahn
346*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_bad_format_hook)
347*d2201f2fSdrahn    PARAMS ((bfd *, PTR));
348*d2201f2fSdrahn
349*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_set_arch_mach_hook)
350*d2201f2fSdrahn    PARAMS ((bfd *, PTR));
351*d2201f2fSdrahn
352*d2201f2fSdrahn  PTR (*_bfd_coff_mkobject_hook)
353*d2201f2fSdrahn    PARAMS ((bfd *, PTR, PTR));
354*d2201f2fSdrahn
355*d2201f2fSdrahn  bfd_boolean (*_bfd_styp_to_sec_flags_hook)
356*d2201f2fSdrahn    PARAMS ((bfd *, PTR, const char *, asection *, flagword *));
357*d2201f2fSdrahn
358*d2201f2fSdrahn  void (*_bfd_set_alignment_hook)
359*d2201f2fSdrahn    PARAMS ((bfd *, asection *, PTR));
360*d2201f2fSdrahn
361*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_slurp_symbol_table)
362*d2201f2fSdrahn    PARAMS ((bfd *));
363*d2201f2fSdrahn
364*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_symname_in_debug)
365*d2201f2fSdrahn    PARAMS ((bfd *, struct internal_syment *));
366*d2201f2fSdrahn
367*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_pointerize_aux_hook)
368*d2201f2fSdrahn    PARAMS ((bfd *, combined_entry_type *, combined_entry_type *,
369*d2201f2fSdrahn            unsigned int, combined_entry_type *));
370*d2201f2fSdrahn
371*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_print_aux)
372*d2201f2fSdrahn    PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *,
373*d2201f2fSdrahn            combined_entry_type *, unsigned int));
374*d2201f2fSdrahn
375*d2201f2fSdrahn  void (*_bfd_coff_reloc16_extra_cases)
376*d2201f2fSdrahn    PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
377*d2201f2fSdrahn           bfd_byte *, unsigned int *, unsigned int *));
378*d2201f2fSdrahn
379*d2201f2fSdrahn  int (*_bfd_coff_reloc16_estimate)
380*d2201f2fSdrahn    PARAMS ((bfd *, asection *, arelent *, unsigned int,
381*d2201f2fSdrahn            struct bfd_link_info *));
382*d2201f2fSdrahn
383*d2201f2fSdrahn  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
384*d2201f2fSdrahn    PARAMS ((bfd *, struct internal_syment *));
385*d2201f2fSdrahn
386*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_compute_section_file_positions)
387*d2201f2fSdrahn    PARAMS ((bfd *));
388*d2201f2fSdrahn
389*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_start_final_link)
390*d2201f2fSdrahn    PARAMS ((bfd *, struct bfd_link_info *));
391*d2201f2fSdrahn
392*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_relocate_section)
393*d2201f2fSdrahn    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
394*d2201f2fSdrahn            struct internal_reloc *, struct internal_syment *, asection **));
395*d2201f2fSdrahn
396*d2201f2fSdrahn  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
397*d2201f2fSdrahn    PARAMS ((bfd *, asection *, struct internal_reloc *,
398*d2201f2fSdrahn            struct coff_link_hash_entry *, struct internal_syment *,
399*d2201f2fSdrahn            bfd_vma *));
400*d2201f2fSdrahn
401*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_adjust_symndx)
402*d2201f2fSdrahn    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
403*d2201f2fSdrahn            struct internal_reloc *, bfd_boolean *));
404*d2201f2fSdrahn
405*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_link_add_one_symbol)
406*d2201f2fSdrahn    PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
407*d2201f2fSdrahn            asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
408*d2201f2fSdrahn            struct bfd_link_hash_entry **));
409*d2201f2fSdrahn
410*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_link_output_has_begun)
411*d2201f2fSdrahn    PARAMS ((bfd *, struct coff_final_link_info *));
412*d2201f2fSdrahn
413*d2201f2fSdrahn  bfd_boolean (*_bfd_coff_final_link_postscript)
414*d2201f2fSdrahn    PARAMS ((bfd *, struct coff_final_link_info *));
415f7cc78ecSespie
416fddef416Sniklas@} bfd_coff_backend_data;
417fddef416Sniklas
418*d2201f2fSdrahn#define coff_backend_info(abfd) \
419*d2201f2fSdrahn  ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
420fddef416Sniklas
421fddef416Sniklas#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
422fddef416Sniklas  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
423fddef416Sniklas
424fddef416Sniklas#define bfd_coff_swap_sym_in(a,e,i) \
425fddef416Sniklas  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
426fddef416Sniklas
427fddef416Sniklas#define bfd_coff_swap_lineno_in(a,e,i) \
428fddef416Sniklas  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
429fddef416Sniklas
430fddef416Sniklas#define bfd_coff_swap_reloc_out(abfd, i, o) \
431fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
432fddef416Sniklas
433fddef416Sniklas#define bfd_coff_swap_lineno_out(abfd, i, o) \
434fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
435fddef416Sniklas
436fddef416Sniklas#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
437fddef416Sniklas  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
438fddef416Sniklas
439fddef416Sniklas#define bfd_coff_swap_sym_out(abfd, i,o) \
440fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
441fddef416Sniklas
442fddef416Sniklas#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
443fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
444fddef416Sniklas
445fddef416Sniklas#define bfd_coff_swap_filehdr_out(abfd, i,o) \
446fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
447fddef416Sniklas
448fddef416Sniklas#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
449fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
450fddef416Sniklas
451fddef416Sniklas#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
452fddef416Sniklas#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
453fddef416Sniklas#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
454fddef416Sniklas#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
455fddef416Sniklas#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
456fddef416Sniklas#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
457fddef416Sniklas#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
458f7cc78ecSespie#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
459*d2201f2fSdrahn#define bfd_coff_long_filenames(abfd) \
460*d2201f2fSdrahn  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
461fddef416Sniklas#define bfd_coff_long_section_names(abfd) \
462fddef416Sniklas  (coff_backend_info (abfd)->_bfd_coff_long_section_names)
463fddef416Sniklas#define bfd_coff_default_section_alignment_power(abfd) \
464fddef416Sniklas  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
465fddef416Sniklas#define bfd_coff_swap_filehdr_in(abfd, i,o) \
466fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
467fddef416Sniklas
468fddef416Sniklas#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
469fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
470fddef416Sniklas
471fddef416Sniklas#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
472fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
473fddef416Sniklas
474fddef416Sniklas#define bfd_coff_swap_reloc_in(abfd, i, o) \
475fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
476fddef416Sniklas
477fddef416Sniklas#define bfd_coff_bad_format_hook(abfd, filehdr) \
478fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
479fddef416Sniklas
480fddef416Sniklas#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
481fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
482fddef416Sniklas#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
483*d2201f2fSdrahn  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
484*d2201f2fSdrahn   (abfd, filehdr, aouthdr))
485fddef416Sniklas
486*d2201f2fSdrahn#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
487f7cc78ecSespie  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
488*d2201f2fSdrahn   (abfd, scnhdr, name, section, flags_ptr))
489fddef416Sniklas
490fddef416Sniklas#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
491fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
492fddef416Sniklas
493fddef416Sniklas#define bfd_coff_slurp_symbol_table(abfd)\
494fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
495fddef416Sniklas
496fddef416Sniklas#define bfd_coff_symname_in_debug(abfd, sym)\
497fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
498fddef416Sniklas
4995f210c2aSfgsch#define bfd_coff_force_symnames_in_strings(abfd)\
5005f210c2aSfgsch  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
5015f210c2aSfgsch
5025f210c2aSfgsch#define bfd_coff_debug_string_prefix_length(abfd)\
5035f210c2aSfgsch  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
5045f210c2aSfgsch
505fddef416Sniklas#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
506fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
507fddef416Sniklas   (abfd, file, base, symbol, aux, indaux))
508fddef416Sniklas
509*d2201f2fSdrahn#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
510*d2201f2fSdrahn                                     reloc, data, src_ptr, dst_ptr)\
511fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
512fddef416Sniklas   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
513fddef416Sniklas
514fddef416Sniklas#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
515fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
516fddef416Sniklas   (abfd, section, reloc, shrink, link_info))
517fddef416Sniklas
518f7cc78ecSespie#define bfd_coff_classify_symbol(abfd, sym)\
519f7cc78ecSespie  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
520fddef416Sniklas   (abfd, sym))
521fddef416Sniklas
522fddef416Sniklas#define bfd_coff_compute_section_file_positions(abfd)\
523fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
524fddef416Sniklas   (abfd))
525fddef416Sniklas
526fddef416Sniklas#define bfd_coff_start_final_link(obfd, info)\
527fddef416Sniklas  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
528fddef416Sniklas   (obfd, info))
529fddef416Sniklas#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
530fddef416Sniklas  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
531fddef416Sniklas   (obfd, info, ibfd, o, con, rel, isyms, secs))
532fddef416Sniklas#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
533fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
534fddef416Sniklas   (abfd, sec, rel, h, sym, addendp))
535fddef416Sniklas#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
536fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
537fddef416Sniklas   (obfd, info, ibfd, sec, rel, adjustedp))
538*d2201f2fSdrahn#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
539*d2201f2fSdrahn                                     value, string, cp, coll, hashp)\
540fddef416Sniklas  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
541fddef416Sniklas   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
542fddef416Sniklas
543f7cc78ecSespie#define bfd_coff_link_output_has_begun(a,p) \
544f7cc78ecSespie  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p))
545f7cc78ecSespie#define bfd_coff_final_link_postscript(a,p) \
546f7cc78ecSespie  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p))
547f7cc78ecSespie
548fddef416Sniklas@end example
549fddef416Sniklas@subsubsection Writing relocations
550fddef416SniklasTo write relocations, the back end steps though the
551fddef416Sniklascanonical relocation table and create an
552fddef416Sniklas@code{internal_reloc}. The symbol index to use is removed from
553fddef416Sniklasthe @code{offset} field in the symbol table supplied.  The
554fddef416Sniklasaddress comes directly from the sum of the section base
555fddef416Sniklasaddress and the relocation offset; the type is dug directly
556fddef416Sniklasfrom the howto field.  Then the @code{internal_reloc} is
557fddef416Sniklasswapped into the shape of an @code{external_reloc} and written
558fddef416Sniklasout to disk.
559f7cc78ecSespie
560fddef416Sniklas@subsubsection Reading linenumbers
561fddef416SniklasCreating the linenumber table is done by reading in the entire
562fddef416Sniklascoff linenumber table, and creating another table for internal use.
563fddef416Sniklas
564fddef416SniklasA coff linenumber table is structured so that each function
565fddef416Sniklasis marked as having a line number of 0. Each line within the
566fddef416Sniklasfunction is an offset from the first line in the function. The
567fddef416Sniklasbase of the line number information for the table is stored in
568fddef416Sniklasthe symbol associated with the function.
569fddef416Sniklas
570f7cc78ecSespieNote: The PE format uses line number 0 for a flag indicating a
571f7cc78ecSespienew source file.
572f7cc78ecSespie
573fddef416SniklasThe information is copied from the external to the internal
574fddef416Sniklastable, and each symbol which marks a function is marked by
575fddef416Sniklaspointing its...
576fddef416Sniklas
577fddef416SniklasHow does this work ?
578f7cc78ecSespie
579fddef416Sniklas@subsubsection Reading relocations
580fddef416SniklasCoff relocations are easily transformed into the internal BFD form
581fddef416Sniklas(@code{arelent}).
582fddef416Sniklas
583fddef416SniklasReading a coff relocation table is done in the following stages:
584fddef416Sniklas
585fddef416Sniklas@itemize @bullet
586fddef416Sniklas
587fddef416Sniklas@item
588fddef416SniklasRead the entire coff relocation table into memory.
589fddef416Sniklas
590fddef416Sniklas@item
591fddef416SniklasProcess each relocation in turn; first swap it from the
592fddef416Sniklasexternal to the internal form.
593fddef416Sniklas
594fddef416Sniklas@item
595fddef416SniklasTurn the symbol referenced in the relocation's symbol index
596fddef416Sniklasinto a pointer into the canonical symbol table.
597fddef416SniklasThis table is the same as the one returned by a call to
598fddef416Sniklas@code{bfd_canonicalize_symtab}. The back end will call that
599fddef416Sniklasroutine and save the result if a canonicalization hasn't been done.
600fddef416Sniklas
601fddef416Sniklas@item
602fddef416SniklasThe reloc index is turned into a pointer to a howto
603fddef416Sniklasstructure, in a back end specific way. For instance, the 386
604fddef416Sniklasand 960 use the @code{r_type} to directly produce an index
605fddef416Sniklasinto a howto table vector; the 88k subtracts a number from the
606fddef416Sniklas@code{r_type} field and creates an addend field.
607fddef416Sniklas@end itemize
608f7cc78ecSespie
609