xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/doc/coffcode.texi (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos@section coff backends
275fd0b74SchristosBFD supports a number of different flavours of coff format.
375fd0b74SchristosThe major differences between formats are the sizes and
475fd0b74Schristosalignments of fields in structures on disk, and the occasional
575fd0b74Schristosextra field.
675fd0b74Schristos
775fd0b74SchristosCoff in all its varieties is implemented with a few common
875fd0b74Schristosfiles and a number of implementation specific files. For
9ede78133Schristosexample, the i386 coff format is implemented in the file
10ede78133Schristos@file{coff-i386.c}.  This file @code{#include}s
11ede78133Schristos@file{coff/i386.h} which defines the external structure of the
12ede78133Schristoscoff format for the i386, and @file{coff/internal.h} which
13ede78133Schristosdefines the internal structure. @file{coff-i386.c} also
14ede78133Schristosdefines the relocations used by the i386 coff format
1575fd0b74Schristos@xref{Relocations}.
1675fd0b74Schristos
1775fd0b74Schristos@subsection Porting to a new version of coff
1875fd0b74SchristosThe recommended method is to select from the existing
1975fd0b74Schristosimplementations the version of coff which is most like the one
2075fd0b74Schristosyou want to use.  For example, we'll say that i386 coff is
2175fd0b74Schristosthe one you select, and that your coff flavour is called foo.
2275fd0b74SchristosCopy @file{i386coff.c} to @file{foocoff.c}, copy
2375fd0b74Schristos@file{../include/coff/i386.h} to @file{../include/coff/foo.h},
2475fd0b74Schristosand add the lines to @file{targets.c} and @file{Makefile.in}
2575fd0b74Schristosso that your new back end is used. Alter the shapes of the
2675fd0b74Schristosstructures in @file{../include/coff/foo.h} so that they match
2775fd0b74Schristoswhat you need. You will probably also have to add
2875fd0b74Schristos@code{#ifdef}s to the code in @file{coff/internal.h} and
2975fd0b74Schristos@file{coffcode.h} if your version of coff is too wild.
3075fd0b74Schristos
3175fd0b74SchristosYou can verify that your new BFD backend works quite simply by
3275fd0b74Schristosbuilding @file{objdump} from the @file{binutils} directory,
3375fd0b74Schristosand making sure that its version of what's going on and your
3475fd0b74Schristoshost system's idea (assuming it has the pretty standard coff
3575fd0b74Schristosdump utility, usually called @code{att-dump} or just
3675fd0b74Schristos@code{dump}) are the same.  Then clean up your code, and send
3775fd0b74Schristoswhat you've done to Cygnus. Then your stuff will be in the
3875fd0b74Schristosnext release, and you won't have to keep integrating it.
3975fd0b74Schristos
4075fd0b74Schristos@subsection How the coff backend works
4175fd0b74Schristos
4275fd0b74Schristos
4375fd0b74Schristos@subsubsection File layout
4475fd0b74SchristosThe Coff backend is split into generic routines that are
4575fd0b74Schristosapplicable to any Coff target and routines that are specific
4675fd0b74Schristosto a particular target.  The target-specific routines are
4775fd0b74Schristosfurther split into ones which are basically the same for all
4875fd0b74SchristosCoff targets except that they use the external symbol format
4975fd0b74Schristosor use different values for certain constants.
5075fd0b74Schristos
5175fd0b74SchristosThe generic routines are in @file{coffgen.c}.  These routines
5275fd0b74Schristoswork for any Coff target.  They use some hooks into the target
5375fd0b74Schristosspecific code; the hooks are in a @code{bfd_coff_backend_data}
5475fd0b74Schristosstructure, one of which exists for each target.
5575fd0b74Schristos
5675fd0b74SchristosThe essentially similar target-specific routines are in
5775fd0b74Schristos@file{coffcode.h}.  This header file includes executable C code.
5875fd0b74SchristosThe various Coff targets first include the appropriate Coff
5975fd0b74Schristosheader file, make any special defines that are needed, and
6075fd0b74Schristosthen include @file{coffcode.h}.
6175fd0b74Schristos
6275fd0b74SchristosSome of the Coff targets then also have additional routines in
6375fd0b74Schristosthe target source file itself.
6475fd0b74Schristos
6575fd0b74Schristos@subsubsection Coff long section names
6675fd0b74SchristosIn the standard Coff object format, section names are limited to
6775fd0b74Schristosthe eight bytes available in the @code{s_name} field of the
6875fd0b74Schristos@code{SCNHDR} section header structure.  The format requires the
6975fd0b74Schristosfield to be NUL-padded, but not necessarily NUL-terminated, so
7075fd0b74Schristosthe longest section names permitted are a full eight characters.
7175fd0b74Schristos
7275fd0b74SchristosThe Microsoft PE variants of the Coff object file format add
7375fd0b74Schristosan extension to support the use of long section names.  This
7475fd0b74Schristosextension is defined in section 4 of the Microsoft PE/COFF
7575fd0b74Schristosspecification (rev 8.1).  If a section name is too long to fit
7675fd0b74Schristosinto the section header's @code{s_name} field, it is instead
7775fd0b74Schristosplaced into the string table, and the @code{s_name} field is
7875fd0b74Schristosfilled with a slash ("/") followed by the ASCII decimal
7975fd0b74Schristosrepresentation of the offset of the full name relative to the
8075fd0b74Schristosstring table base.
8175fd0b74Schristos
8275fd0b74SchristosNote that this implies that the extension can only be used in object
8375fd0b74Schristosfiles, as executables do not contain a string table.  The standard
8475fd0b74Schristosspecifies that long section names from objects emitted into executable
8575fd0b74Schristosimages are to be truncated.
8675fd0b74Schristos
8775fd0b74SchristosHowever, as a GNU extension, BFD can generate executable images
8875fd0b74Schristosthat contain a string table and long section names.  This
8975fd0b74Schristoswould appear to be technically valid, as the standard only says
9075fd0b74Schristosthat Coff debugging information is deprecated, not forbidden,
9175fd0b74Schristosand in practice it works, although some tools that parse PE files
9275fd0b74Schristosexpecting the MS standard format may become confused; @file{PEview} is
9375fd0b74Schristosone known example.
9475fd0b74Schristos
9575fd0b74SchristosThe functionality is supported in BFD by code implemented under
9675fd0b74Schristosthe control of the macro @code{COFF_LONG_SECTION_NAMES}.  If not
9775fd0b74Schristosdefined, the format does not support long section names in any way.
9875fd0b74SchristosIf defined, it is used to initialise a flag,
9975fd0b74Schristos@code{_bfd_coff_long_section_names}, and a hook function pointer,
10075fd0b74Schristos@code{_bfd_coff_set_long_section_names}, in the Coff backend data
10175fd0b74Schristosstructure.  The flag controls the generation of long section names
10275fd0b74Schristosin output BFDs at runtime; if it is false, as it will be by default
10375fd0b74Schristoswhen generating an executable image, long section names are truncated;
10475fd0b74Schristosif true, the long section names extension is employed.  The hook
10575fd0b74Schristospoints to a function that allows the value of the flag to be altered
10675fd0b74Schristosat runtime, on formats that support long section names at all; on
10775fd0b74Schristosother formats it points to a stub that returns an error indication.
10875fd0b74Schristos
10975fd0b74SchristosWith input BFDs, the flag is set according to whether any long section
11075fd0b74Schristosnames are detected while reading the section headers.  For a completely
11175fd0b74Schristosnew BFD, the flag is set to the default for the target format.  This
11275fd0b74Schristosinformation can be used by a client of the BFD library when deciding
11375fd0b74Schristoswhat output format to generate, and means that a BFD that is opened
11475fd0b74Schristosfor read and subsequently converted to a writeable BFD and modified
11575fd0b74Schristosin-place will retain whatever format it had on input.
11675fd0b74Schristos
11775fd0b74SchristosIf @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
11875fd0b74Schristosdefined to the value "1", then long section names are enabled by
11975fd0b74Schristosdefault; if it is defined to the value zero, they are disabled by
12075fd0b74Schristosdefault (but still accepted in input BFDs).  The header @file{coffcode.h}
12175fd0b74Schristosdefines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
12275fd0b74Schristosused in the backends to initialise the backend data structure fields
12375fd0b74Schristosappropriately; see the comments for further detail.
12475fd0b74Schristos
12575fd0b74Schristos@subsubsection Bit twiddling
12675fd0b74SchristosEach flavour of coff supported in BFD has its own header file
12775fd0b74Schristosdescribing the external layout of the structures. There is also
12875fd0b74Schristosan internal description of the coff layout, in
12975fd0b74Schristos@file{coff/internal.h}. A major function of the
13075fd0b74Schristoscoff backend is swapping the bytes and twiddling the bits to
13175fd0b74Schristostranslate the external form of the structures into the normal
13275fd0b74Schristosinternal form. This is all performed in the
13375fd0b74Schristos@code{bfd_swap}_@i{thing}_@i{direction} routines. Some
13475fd0b74Schristoselements are different sizes between different versions of
13575fd0b74Schristoscoff; it is the duty of the coff version specific include file
13675fd0b74Schristosto override the definitions of various packing routines in
13775fd0b74Schristos@file{coffcode.h}. E.g., the size of line number entry in coff is
13875fd0b74Schristossometimes 16 bits, and sometimes 32 bits. @code{#define}ing
13975fd0b74Schristos@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
14075fd0b74Schristoscorrect one. No doubt, some day someone will find a version of
14175fd0b74Schristoscoff which has a varying field size not catered to at the
14275fd0b74Schristosmoment. To port BFD, that person will have to add more @code{#defines}.
14375fd0b74SchristosThree of the bit twiddling routines are exported to
14475fd0b74Schristos@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
14575fd0b74Schristosand @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
14675fd0b74Schristostable on its own, but uses BFD to fix things up.  More of the
14775fd0b74Schristosbit twiddlers are exported for @code{gas};
14875fd0b74Schristos@code{coff_swap_aux_out}, @code{coff_swap_sym_out},
14975fd0b74Schristos@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
15075fd0b74Schristos@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
15175fd0b74Schristos@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
15275fd0b74Schristosof all the symbol table and reloc drudgery itself, thereby
15375fd0b74Schristossaving the internal BFD overhead, but uses BFD to swap things
15475fd0b74Schristoson the way out, making cross ports much safer.  Doing so also
15575fd0b74Schristosallows BFD (and thus the linker) to use the same header files
15675fd0b74Schristosas @code{gas}, which makes one avenue to disaster disappear.
15775fd0b74Schristos
15875fd0b74Schristos@subsubsection Symbol reading
15975fd0b74SchristosThe simple canonical form for symbols used by BFD is not rich
16075fd0b74Schristosenough to keep all the information available in a coff symbol
16175fd0b74Schristostable. The back end gets around this problem by keeping the original
16275fd0b74Schristossymbol table around, "behind the scenes".
16375fd0b74Schristos
16475fd0b74SchristosWhen a symbol table is requested (through a call to
16575fd0b74Schristos@code{bfd_canonicalize_symtab}), a request gets through to
16675fd0b74Schristos@code{coff_get_normalized_symtab}. This reads the symbol table from
16775fd0b74Schristosthe coff file and swaps all the structures inside into the
16875fd0b74Schristosinternal form. It also fixes up all the pointers in the table
16975fd0b74Schristos(represented in the file by offsets from the first symbol in
17075fd0b74Schristosthe table) into physical pointers to elements in the new
17175fd0b74Schristosinternal table. This involves some work since the meanings of
17275fd0b74Schristosfields change depending upon context: a field that is a
17375fd0b74Schristospointer to another structure in the symbol table at one moment
17475fd0b74Schristosmay be the size in bytes of a structure at the next.  Another
17575fd0b74Schristospass is made over the table. All symbols which mark file names
17675fd0b74Schristos(@code{C_FILE} symbols) are modified so that the internal
17775fd0b74Schristosstring points to the value in the auxent (the real filename)
17875fd0b74Schristosrather than the normal text associated with the symbol
17975fd0b74Schristos(@code{".file"}).
18075fd0b74Schristos
18175fd0b74SchristosAt this time the symbol names are moved around. Coff stores
18275fd0b74Schristosall symbols less than nine characters long physically
18375fd0b74Schristoswithin the symbol table; longer strings are kept at the end of
18475fd0b74Schristosthe file in the string table. This pass moves all strings
18575fd0b74Schristosinto memory and replaces them with pointers to the strings.
18675fd0b74Schristos
18775fd0b74SchristosThe symbol table is massaged once again, this time to create
18875fd0b74Schristosthe canonical table used by the BFD application. Each symbol
18975fd0b74Schristosis inspected in turn, and a decision made (using the
19075fd0b74Schristos@code{sclass} field) about the various flags to set in the
19175fd0b74Schristos@code{asymbol}.  @xref{Symbols}. The generated canonical table
19275fd0b74Schristosshares strings with the hidden internal symbol table.
19375fd0b74Schristos
19475fd0b74SchristosAny linenumbers are read from the coff file too, and attached
19575fd0b74Schristosto the symbols which own the functions the linenumbers belong to.
19675fd0b74Schristos
19775fd0b74Schristos@subsubsection Symbol writing
19875fd0b74SchristosWriting a symbol to a coff file which didn't come from a coff
19975fd0b74Schristosfile will lose any debugging information. The @code{asymbol}
20075fd0b74Schristosstructure remembers the BFD from which the symbol was taken, and on
20175fd0b74Schristosoutput the back end makes sure that the same destination target as
20275fd0b74Schristossource target is present.
20375fd0b74Schristos
20475fd0b74SchristosWhen the symbols have come from a coff file then all the
20575fd0b74Schristosdebugging information is preserved.
20675fd0b74Schristos
20775fd0b74SchristosSymbol tables are provided for writing to the back end in a
20875fd0b74Schristosvector of pointers to pointers. This allows applications like
20975fd0b74Schristosthe linker to accumulate and output large symbol tables
21075fd0b74Schristoswithout having to do too much byte copying.
21175fd0b74Schristos
21275fd0b74SchristosThis function runs through the provided symbol table and
21375fd0b74Schristospatches each symbol marked as a file place holder
21475fd0b74Schristos(@code{C_FILE}) to point to the next file place holder in the
21575fd0b74Schristoslist. It also marks each @code{offset} field in the list with
21675fd0b74Schristosthe offset from the first symbol of the current symbol.
21775fd0b74Schristos
21875fd0b74SchristosAnother function of this procedure is to turn the canonical
21975fd0b74Schristosvalue form of BFD into the form used by coff. Internally, BFD
22075fd0b74Schristosexpects symbol values to be offsets from a section base; so a
22175fd0b74Schristossymbol physically at 0x120, but in a section starting at
22275fd0b74Schristos0x100, would have the value 0x20. Coff expects symbols to
22375fd0b74Schristoscontain their final value, so symbols have their values
22475fd0b74Schristoschanged at this point to reflect their sum with their owning
22575fd0b74Schristossection.  This transformation uses the
22675fd0b74Schristos@code{output_section} field of the @code{asymbol}'s
22775fd0b74Schristos@code{asection} @xref{Sections}.
22875fd0b74Schristos
22975fd0b74Schristos@itemize @bullet
23075fd0b74Schristos
23175fd0b74Schristos@item
23275fd0b74Schristos@code{coff_mangle_symbols}
23375fd0b74Schristos@end itemize
23475fd0b74SchristosThis routine runs though the provided symbol table and uses
23575fd0b74Schristosthe offsets generated by the previous pass and the pointers
23675fd0b74Schristosgenerated when the symbol table was read in to create the
23775fd0b74Schristosstructured hierarchy required by coff. It changes each pointer
23875fd0b74Schristosto a symbol into the index into the symbol table of the asymbol.
23975fd0b74Schristos
24075fd0b74Schristos@itemize @bullet
24175fd0b74Schristos
24275fd0b74Schristos@item
24375fd0b74Schristos@code{coff_write_symbols}
24475fd0b74Schristos@end itemize
24575fd0b74SchristosThis routine runs through the symbol table and patches up the
24675fd0b74Schristossymbols from their internal form into the coff way, calls the
24775fd0b74Schristosbit twiddlers, and writes out the table to the file.
24875fd0b74Schristos
24975fd0b74Schristos@findex coff_symbol_type
25075fd0b74Schristos@subsubsection @code{coff_symbol_type}
25175fd0b74Schristos@strong{Description}@*
25275fd0b74SchristosThe hidden information for an @code{asymbol} is described in a
25375fd0b74Schristos@code{combined_entry_type}:
25475fd0b74Schristos
25575fd0b74Schristos
25675fd0b74Schristos@example
25775fd0b74Schristos
25875fd0b74Schristostypedef struct coff_ptr_struct
25975fd0b74Schristos@{
26075fd0b74Schristos  /* Remembers the offset from the first symbol in the file for
26175fd0b74Schristos     this symbol. Generated by coff_renumber_symbols.  */
26275fd0b74Schristos  unsigned int offset;
26375fd0b74Schristos
26475fd0b74Schristos  /* Should the value of this symbol be renumbered.  Used for
26575fd0b74Schristos     XCOFF C_BSTAT symbols.  Set by coff_slurp_symbol_table.  */
26675fd0b74Schristos  unsigned int fix_value : 1;
26775fd0b74Schristos
26875fd0b74Schristos  /* Should the tag field of this symbol be renumbered.
26975fd0b74Schristos     Created by coff_pointerize_aux.  */
27075fd0b74Schristos  unsigned int fix_tag : 1;
27175fd0b74Schristos
27275fd0b74Schristos  /* Should the endidx field of this symbol be renumbered.
27375fd0b74Schristos     Created by coff_pointerize_aux.  */
27475fd0b74Schristos  unsigned int fix_end : 1;
27575fd0b74Schristos
27675fd0b74Schristos  /* Should the x_csect.x_scnlen field be renumbered.
27775fd0b74Schristos     Created by coff_pointerize_aux.  */
27875fd0b74Schristos  unsigned int fix_scnlen : 1;
27975fd0b74Schristos
28075fd0b74Schristos  /* Fix up an XCOFF C_BINCL/C_EINCL symbol.  The value is the
28175fd0b74Schristos     index into the line number entries.  Set by coff_slurp_symbol_table.  */
28275fd0b74Schristos  unsigned int fix_line : 1;
28375fd0b74Schristos
28475fd0b74Schristos  /* The container for the symbol structure as read and translated
28575fd0b74Schristos     from the file.  */
28675fd0b74Schristos  union
28775fd0b74Schristos  @{
28875fd0b74Schristos    union internal_auxent auxent;
28975fd0b74Schristos    struct internal_syment syment;
29075fd0b74Schristos  @} u;
29175fd0b74Schristos
29275fd0b74Schristos /* Selector for the union above.  */
293*e992f068Schristos bool is_sym;
294*e992f068Schristos
295*e992f068Schristos /* An extra pointer which can used by format based on COFF (like XCOFF)
296*e992f068Schristos    to provide extra information to their backend.  */
297*e992f068Schristos void *extrap;
29875fd0b74Schristos@} combined_entry_type;
29975fd0b74Schristos
30075fd0b74Schristos
30175fd0b74Schristos/* Each canonical asymbol really looks like this: */
30275fd0b74Schristos
30375fd0b74Schristostypedef struct coff_symbol_struct
30475fd0b74Schristos@{
30575fd0b74Schristos  /* The actual symbol which the rest of BFD works with */
30675fd0b74Schristos  asymbol symbol;
30775fd0b74Schristos
30875fd0b74Schristos  /* A pointer to the hidden information for this symbol */
30975fd0b74Schristos  combined_entry_type *native;
31075fd0b74Schristos
31175fd0b74Schristos  /* A pointer to the linenumber information for this symbol */
31275fd0b74Schristos  struct lineno_cache_entry *lineno;
31375fd0b74Schristos
31475fd0b74Schristos  /* Have the line numbers been relocated yet ? */
315*e992f068Schristos  bool done_lineno;
31675fd0b74Schristos@} coff_symbol_type;
31775fd0b74Schristos@end example
31875fd0b74Schristos@findex bfd_coff_backend_data
31975fd0b74Schristos@subsubsection @code{bfd_coff_backend_data}
32075fd0b74Schristos
32175fd0b74Schristos@example
32275fd0b74Schristos/* COFF symbol classifications.  */
32375fd0b74Schristos
32475fd0b74Schristosenum coff_symbol_classification
32575fd0b74Schristos@{
32675fd0b74Schristos  /* Global symbol.  */
32775fd0b74Schristos  COFF_SYMBOL_GLOBAL,
32875fd0b74Schristos  /* Common symbol.  */
32975fd0b74Schristos  COFF_SYMBOL_COMMON,
33075fd0b74Schristos  /* Undefined symbol.  */
33175fd0b74Schristos  COFF_SYMBOL_UNDEFINED,
33275fd0b74Schristos  /* Local symbol.  */
33375fd0b74Schristos  COFF_SYMBOL_LOCAL,
33475fd0b74Schristos  /* PE section symbol.  */
33575fd0b74Schristos  COFF_SYMBOL_PE_SECTION
33675fd0b74Schristos@};
33775fd0b74Schristos
33875fd0b74Schristostypedef asection * (*coff_gc_mark_hook_fn)
33975fd0b74Schristos  (asection *, struct bfd_link_info *, struct internal_reloc *,
34075fd0b74Schristos   struct coff_link_hash_entry *, struct internal_syment *);
34175fd0b74Schristos
34275fd0b74Schristos@end example
34375fd0b74SchristosSpecial entry points for gdb to swap in coff symbol table parts:
34475fd0b74Schristos@example
34575fd0b74Schristostypedef struct
34675fd0b74Schristos@{
34775fd0b74Schristos  void (*_bfd_coff_swap_aux_in)
34875fd0b74Schristos    (bfd *, void *, int, int, int, int, void *);
34975fd0b74Schristos
35075fd0b74Schristos  void (*_bfd_coff_swap_sym_in)
35175fd0b74Schristos    (bfd *, void *, void *);
35275fd0b74Schristos
35375fd0b74Schristos  void (*_bfd_coff_swap_lineno_in)
35475fd0b74Schristos    (bfd *, void *, void *);
35575fd0b74Schristos
35675fd0b74Schristos  unsigned int (*_bfd_coff_swap_aux_out)
35775fd0b74Schristos    (bfd *, void *, int, int, int, int, void *);
35875fd0b74Schristos
35975fd0b74Schristos  unsigned int (*_bfd_coff_swap_sym_out)
36075fd0b74Schristos    (bfd *, void *, void *);
36175fd0b74Schristos
36275fd0b74Schristos  unsigned int (*_bfd_coff_swap_lineno_out)
36375fd0b74Schristos    (bfd *, void *, void *);
36475fd0b74Schristos
36575fd0b74Schristos  unsigned int (*_bfd_coff_swap_reloc_out)
36675fd0b74Schristos    (bfd *, void *, void *);
36775fd0b74Schristos
36875fd0b74Schristos  unsigned int (*_bfd_coff_swap_filehdr_out)
36975fd0b74Schristos    (bfd *, void *, void *);
37075fd0b74Schristos
37175fd0b74Schristos  unsigned int (*_bfd_coff_swap_aouthdr_out)
37275fd0b74Schristos    (bfd *, void *, void *);
37375fd0b74Schristos
37475fd0b74Schristos  unsigned int (*_bfd_coff_swap_scnhdr_out)
37575fd0b74Schristos    (bfd *, void *, void *);
37675fd0b74Schristos
37775fd0b74Schristos  unsigned int _bfd_filhsz;
37875fd0b74Schristos  unsigned int _bfd_aoutsz;
37975fd0b74Schristos  unsigned int _bfd_scnhsz;
38075fd0b74Schristos  unsigned int _bfd_symesz;
38175fd0b74Schristos  unsigned int _bfd_auxesz;
38275fd0b74Schristos  unsigned int _bfd_relsz;
38375fd0b74Schristos  unsigned int _bfd_linesz;
38475fd0b74Schristos  unsigned int _bfd_filnmlen;
385*e992f068Schristos  bool _bfd_coff_long_filenames;
38675fd0b74Schristos
387*e992f068Schristos  bool _bfd_coff_long_section_names;
388*e992f068Schristos  bool (*_bfd_coff_set_long_section_names)
38975fd0b74Schristos    (bfd *, int);
39075fd0b74Schristos
39175fd0b74Schristos  unsigned int _bfd_coff_default_section_alignment_power;
392*e992f068Schristos  bool _bfd_coff_force_symnames_in_strings;
39375fd0b74Schristos  unsigned int _bfd_coff_debug_string_prefix_length;
39475fd0b74Schristos  unsigned int _bfd_coff_max_nscns;
39575fd0b74Schristos
39675fd0b74Schristos  void (*_bfd_coff_swap_filehdr_in)
39775fd0b74Schristos    (bfd *, void *, void *);
39875fd0b74Schristos
39975fd0b74Schristos  void (*_bfd_coff_swap_aouthdr_in)
40075fd0b74Schristos    (bfd *, void *, void *);
40175fd0b74Schristos
40275fd0b74Schristos  void (*_bfd_coff_swap_scnhdr_in)
40375fd0b74Schristos    (bfd *, void *, void *);
40475fd0b74Schristos
40575fd0b74Schristos  void (*_bfd_coff_swap_reloc_in)
40675fd0b74Schristos    (bfd *abfd, void *, void *);
40775fd0b74Schristos
408*e992f068Schristos  bool (*_bfd_coff_bad_format_hook)
40975fd0b74Schristos    (bfd *, void *);
41075fd0b74Schristos
411*e992f068Schristos  bool (*_bfd_coff_set_arch_mach_hook)
41275fd0b74Schristos    (bfd *, void *);
41375fd0b74Schristos
41475fd0b74Schristos  void * (*_bfd_coff_mkobject_hook)
41575fd0b74Schristos    (bfd *, void *, void *);
41675fd0b74Schristos
417*e992f068Schristos  bool (*_bfd_styp_to_sec_flags_hook)
41875fd0b74Schristos    (bfd *, void *, const char *, asection *, flagword *);
41975fd0b74Schristos
42075fd0b74Schristos  void (*_bfd_set_alignment_hook)
42175fd0b74Schristos    (bfd *, asection *, void *);
42275fd0b74Schristos
423*e992f068Schristos  bool (*_bfd_coff_slurp_symbol_table)
42475fd0b74Schristos    (bfd *);
42575fd0b74Schristos
426*e992f068Schristos  bool (*_bfd_coff_symname_in_debug)
42775fd0b74Schristos    (bfd *, struct internal_syment *);
42875fd0b74Schristos
429*e992f068Schristos  bool (*_bfd_coff_pointerize_aux_hook)
43075fd0b74Schristos    (bfd *, combined_entry_type *, combined_entry_type *,
43175fd0b74Schristos     unsigned int, combined_entry_type *);
43275fd0b74Schristos
433*e992f068Schristos  bool (*_bfd_coff_print_aux)
43475fd0b74Schristos    (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
43575fd0b74Schristos     combined_entry_type *, unsigned int);
43675fd0b74Schristos
43775fd0b74Schristos  void (*_bfd_coff_reloc16_extra_cases)
43875fd0b74Schristos    (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
43975fd0b74Schristos     bfd_byte *, unsigned int *, unsigned int *);
44075fd0b74Schristos
44175fd0b74Schristos  int (*_bfd_coff_reloc16_estimate)
44275fd0b74Schristos    (bfd *, asection *, arelent *, unsigned int,
44375fd0b74Schristos     struct bfd_link_info *);
44475fd0b74Schristos
44575fd0b74Schristos  enum coff_symbol_classification (*_bfd_coff_classify_symbol)
44675fd0b74Schristos    (bfd *, struct internal_syment *);
44775fd0b74Schristos
448*e992f068Schristos  bool (*_bfd_coff_compute_section_file_positions)
44975fd0b74Schristos    (bfd *);
45075fd0b74Schristos
451*e992f068Schristos  bool (*_bfd_coff_start_final_link)
45275fd0b74Schristos    (bfd *, struct bfd_link_info *);
45375fd0b74Schristos
454*e992f068Schristos  bool (*_bfd_coff_relocate_section)
45575fd0b74Schristos    (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
45675fd0b74Schristos     struct internal_reloc *, struct internal_syment *, asection **);
45775fd0b74Schristos
45875fd0b74Schristos  reloc_howto_type *(*_bfd_coff_rtype_to_howto)
45975fd0b74Schristos    (bfd *, asection *, struct internal_reloc *,
460ede78133Schristos     struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *);
46175fd0b74Schristos
462*e992f068Schristos  bool (*_bfd_coff_adjust_symndx)
46375fd0b74Schristos    (bfd *, struct bfd_link_info *, bfd *, asection *,
464*e992f068Schristos     struct internal_reloc *, bool *);
46575fd0b74Schristos
466*e992f068Schristos  bool (*_bfd_coff_link_add_one_symbol)
46775fd0b74Schristos    (struct bfd_link_info *, bfd *, const char *, flagword,
468*e992f068Schristos     asection *, bfd_vma, const char *, bool, bool,
46975fd0b74Schristos     struct bfd_link_hash_entry **);
47075fd0b74Schristos
471*e992f068Schristos  bool (*_bfd_coff_link_output_has_begun)
47275fd0b74Schristos    (bfd *, struct coff_final_link_info *);
47375fd0b74Schristos
474*e992f068Schristos  bool (*_bfd_coff_final_link_postscript)
47575fd0b74Schristos    (bfd *, struct coff_final_link_info *);
47675fd0b74Schristos
477*e992f068Schristos  bool (*_bfd_coff_print_pdata)
47875fd0b74Schristos    (bfd *, void *);
47975fd0b74Schristos
48075fd0b74Schristos@} bfd_coff_backend_data;
48175fd0b74Schristos
48275fd0b74Schristos#define coff_backend_info(abfd) \
48375fd0b74Schristos  ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
48475fd0b74Schristos
48575fd0b74Schristos#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
48675fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
48775fd0b74Schristos
48875fd0b74Schristos#define bfd_coff_swap_sym_in(a,e,i) \
48975fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
49075fd0b74Schristos
49175fd0b74Schristos#define bfd_coff_swap_lineno_in(a,e,i) \
49275fd0b74Schristos  ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
49375fd0b74Schristos
49475fd0b74Schristos#define bfd_coff_swap_reloc_out(abfd, i, o) \
49575fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
49675fd0b74Schristos
49775fd0b74Schristos#define bfd_coff_swap_lineno_out(abfd, i, o) \
49875fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
49975fd0b74Schristos
50075fd0b74Schristos#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
50175fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
50275fd0b74Schristos
50375fd0b74Schristos#define bfd_coff_swap_sym_out(abfd, i,o) \
50475fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
50575fd0b74Schristos
50675fd0b74Schristos#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
50775fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
50875fd0b74Schristos
50975fd0b74Schristos#define bfd_coff_swap_filehdr_out(abfd, i,o) \
51075fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
51175fd0b74Schristos
51275fd0b74Schristos#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
51375fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
51475fd0b74Schristos
51575fd0b74Schristos#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
51675fd0b74Schristos#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
51775fd0b74Schristos#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
51875fd0b74Schristos#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
51975fd0b74Schristos#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
52075fd0b74Schristos#define bfd_coff_relsz(abfd)  (coff_backend_info (abfd)->_bfd_relsz)
52175fd0b74Schristos#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
52275fd0b74Schristos#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
52375fd0b74Schristos#define bfd_coff_long_filenames(abfd) \
52475fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_long_filenames)
52575fd0b74Schristos#define bfd_coff_long_section_names(abfd) \
52675fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_long_section_names)
52775fd0b74Schristos#define bfd_coff_set_long_section_names(abfd, enable) \
52875fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
52975fd0b74Schristos#define bfd_coff_default_section_alignment_power(abfd) \
53075fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
53175fd0b74Schristos#define bfd_coff_max_nscns(abfd) \
53275fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_max_nscns)
53375fd0b74Schristos
53475fd0b74Schristos#define bfd_coff_swap_filehdr_in(abfd, i,o) \
53575fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
53675fd0b74Schristos
53775fd0b74Schristos#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
53875fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
53975fd0b74Schristos
54075fd0b74Schristos#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
54175fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
54275fd0b74Schristos
54375fd0b74Schristos#define bfd_coff_swap_reloc_in(abfd, i, o) \
54475fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
54575fd0b74Schristos
54675fd0b74Schristos#define bfd_coff_bad_format_hook(abfd, filehdr) \
54775fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
54875fd0b74Schristos
54975fd0b74Schristos#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
55075fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
55175fd0b74Schristos#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
55275fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
55375fd0b74Schristos   (abfd, filehdr, aouthdr))
55475fd0b74Schristos
55575fd0b74Schristos#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
55675fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
55775fd0b74Schristos   (abfd, scnhdr, name, section, flags_ptr))
55875fd0b74Schristos
55975fd0b74Schristos#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
56075fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
56175fd0b74Schristos
56275fd0b74Schristos#define bfd_coff_slurp_symbol_table(abfd)\
56375fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
56475fd0b74Schristos
56575fd0b74Schristos#define bfd_coff_symname_in_debug(abfd, sym)\
56675fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
56775fd0b74Schristos
56875fd0b74Schristos#define bfd_coff_force_symnames_in_strings(abfd)\
56975fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
57075fd0b74Schristos
57175fd0b74Schristos#define bfd_coff_debug_string_prefix_length(abfd)\
57275fd0b74Schristos  (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
57375fd0b74Schristos
57475fd0b74Schristos#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
57575fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
57675fd0b74Schristos   (abfd, file, base, symbol, aux, indaux))
57775fd0b74Schristos
57875fd0b74Schristos#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
57975fd0b74Schristos                                     reloc, data, src_ptr, dst_ptr)\
58075fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
58175fd0b74Schristos   (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
58275fd0b74Schristos
58375fd0b74Schristos#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
58475fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
58575fd0b74Schristos   (abfd, section, reloc, shrink, link_info))
58675fd0b74Schristos
58775fd0b74Schristos#define bfd_coff_classify_symbol(abfd, sym)\
58875fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
58975fd0b74Schristos   (abfd, sym))
59075fd0b74Schristos
59175fd0b74Schristos#define bfd_coff_compute_section_file_positions(abfd)\
59275fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
59375fd0b74Schristos   (abfd))
59475fd0b74Schristos
59575fd0b74Schristos#define bfd_coff_start_final_link(obfd, info)\
59675fd0b74Schristos  ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
59775fd0b74Schristos   (obfd, info))
59875fd0b74Schristos#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
59975fd0b74Schristos  ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
60075fd0b74Schristos   (obfd, info, ibfd, o, con, rel, isyms, secs))
60175fd0b74Schristos#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
60275fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
60375fd0b74Schristos   (abfd, sec, rel, h, sym, addendp))
60475fd0b74Schristos#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
60575fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
60675fd0b74Schristos   (obfd, info, ibfd, sec, rel, adjustedp))
60775fd0b74Schristos#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
60875fd0b74Schristos                                     value, string, cp, coll, hashp)\
60975fd0b74Schristos  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
61075fd0b74Schristos   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
61175fd0b74Schristos
61275fd0b74Schristos#define bfd_coff_link_output_has_begun(a,p) \
61375fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
61475fd0b74Schristos#define bfd_coff_final_link_postscript(a,p) \
61575fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
61675fd0b74Schristos
61775fd0b74Schristos#define bfd_coff_have_print_pdata(a) \
61875fd0b74Schristos  (coff_backend_info (a)->_bfd_coff_print_pdata)
61975fd0b74Schristos#define bfd_coff_print_pdata(a,p) \
62075fd0b74Schristos  ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
62175fd0b74Schristos
62275fd0b74Schristos/* Macro: Returns true if the bfd is a PE executable as opposed to a
62375fd0b74Schristos   PE object file.  */
62475fd0b74Schristos#define bfd_pei_p(abfd) \
625*e992f068Schristos  (startswith ((abfd)->xvec->name, "pei-"))
62675fd0b74Schristos@end example
62775fd0b74Schristos@subsubsection Writing relocations
62875fd0b74SchristosTo write relocations, the back end steps though the
62975fd0b74Schristoscanonical relocation table and create an
63075fd0b74Schristos@code{internal_reloc}. The symbol index to use is removed from
63175fd0b74Schristosthe @code{offset} field in the symbol table supplied.  The
63275fd0b74Schristosaddress comes directly from the sum of the section base
63375fd0b74Schristosaddress and the relocation offset; the type is dug directly
63475fd0b74Schristosfrom the howto field.  Then the @code{internal_reloc} is
63575fd0b74Schristosswapped into the shape of an @code{external_reloc} and written
63675fd0b74Schristosout to disk.
63775fd0b74Schristos
63875fd0b74Schristos@subsubsection Reading linenumbers
63975fd0b74SchristosCreating the linenumber table is done by reading in the entire
64075fd0b74Schristoscoff linenumber table, and creating another table for internal use.
64175fd0b74Schristos
64275fd0b74SchristosA coff linenumber table is structured so that each function
64375fd0b74Schristosis marked as having a line number of 0. Each line within the
64475fd0b74Schristosfunction is an offset from the first line in the function. The
64575fd0b74Schristosbase of the line number information for the table is stored in
64675fd0b74Schristosthe symbol associated with the function.
64775fd0b74Schristos
64875fd0b74SchristosNote: The PE format uses line number 0 for a flag indicating a
64975fd0b74Schristosnew source file.
65075fd0b74Schristos
65175fd0b74SchristosThe information is copied from the external to the internal
65275fd0b74Schristostable, and each symbol which marks a function is marked by
65375fd0b74Schristospointing its...
65475fd0b74Schristos
65575fd0b74SchristosHow does this work ?
65675fd0b74Schristos
65775fd0b74Schristos@subsubsection Reading relocations
65875fd0b74SchristosCoff relocations are easily transformed into the internal BFD form
65975fd0b74Schristos(@code{arelent}).
66075fd0b74Schristos
66175fd0b74SchristosReading a coff relocation table is done in the following stages:
66275fd0b74Schristos
66375fd0b74Schristos@itemize @bullet
66475fd0b74Schristos
66575fd0b74Schristos@item
66675fd0b74SchristosRead the entire coff relocation table into memory.
66775fd0b74Schristos
66875fd0b74Schristos@item
66975fd0b74SchristosProcess each relocation in turn; first swap it from the
67075fd0b74Schristosexternal to the internal form.
67175fd0b74Schristos
67275fd0b74Schristos@item
67375fd0b74SchristosTurn the symbol referenced in the relocation's symbol index
67475fd0b74Schristosinto a pointer into the canonical symbol table.
67575fd0b74SchristosThis table is the same as the one returned by a call to
67675fd0b74Schristos@code{bfd_canonicalize_symtab}. The back end will call that
67775fd0b74Schristosroutine and save the result if a canonicalization hasn't been done.
67875fd0b74Schristos
67975fd0b74Schristos@item
68075fd0b74SchristosThe reloc index is turned into a pointer to a howto
68175fd0b74Schristosstructure, in a back end specific way. For instance, the 386
682ede78133Schristosuses the @code{r_type} to directly produce an index
683ede78133Schristosinto a howto table vector.
68475fd0b74Schristos@end itemize
68575fd0b74Schristos
686