| 1 |
@section coff backends |
| 2 |
BFD supports a number of different flavours of coff format. |
| 3 |
The major differences between formats are the sizes and |
| 4 |
alignments of fields in structures on disk, and the occasional |
| 5 |
extra field. |
| 6 |
|
| 7 |
Coff in all its varieties is implemented with a few common |
| 8 |
files and a number of implementation specific files. For |
| 9 |
example, the i386 coff format is implemented in the file |
| 10 |
@file{coff-i386.c}. This file @code{#include}s |
| 11 |
@file{coff/i386.h} which defines the external structure of the |
| 12 |
coff format for the i386, and @file{coff/internal.h} which |
| 13 |
defines the internal structure. @file{coff-i386.c} also |
| 14 |
defines the relocations used by the i386 coff format |
| 15 |
@xref{Relocations}. |
| 16 |
|
| 17 |
@subsection Porting to a new version of coff |
| 18 |
The recommended method is to select from the existing |
| 19 |
implementations the version of coff which is most like the one |
| 20 |
you want to use. For example, we'll say that i386 coff is |
| 21 |
the one you select, and that your coff flavour is called foo. |
| 22 |
Copy @file{i386coff.c} to @file{foocoff.c}, copy |
| 23 |
@file{../include/coff/i386.h} to @file{../include/coff/foo.h}, |
| 24 |
and add the lines to @file{targets.c} and @file{Makefile.in} |
| 25 |
so that your new back end is used. Alter the shapes of the |
| 26 |
structures in @file{../include/coff/foo.h} so that they match |
| 27 |
what you need. You will probably also have to add |
| 28 |
@code{#ifdef}s to the code in @file{coff/internal.h} and |
| 29 |
@file{coffcode.h} if your version of coff is too wild. |
| 30 |
|
| 31 |
You can verify that your new BFD backend works quite simply by |
| 32 |
building @file{objdump} from the @file{binutils} directory, |
| 33 |
and making sure that its version of what's going on and your |
| 34 |
host system's idea (assuming it has the pretty standard coff |
| 35 |
dump utility, usually called @code{att-dump} or just |
| 36 |
@code{dump}) are the same. Then clean up your code, and send |
| 37 |
what you've done to Cygnus. Then your stuff will be in the |
| 38 |
next release, and you won't have to keep integrating it. |
| 39 |
|
| 40 |
@subsection How the coff backend works |
| 41 |
|
| 42 |
|
| 43 |
@subsubsection File layout |
| 44 |
The Coff backend is split into generic routines that are |
| 45 |
applicable to any Coff target and routines that are specific |
| 46 |
to a particular target. The target-specific routines are |
| 47 |
further split into ones which are basically the same for all |
| 48 |
Coff targets except that they use the external symbol format |
| 49 |
or use different values for certain constants. |
| 50 |
|
| 51 |
The generic routines are in @file{coffgen.c}. These routines |
| 52 |
work for any Coff target. They use some hooks into the target |
| 53 |
specific code; the hooks are in a @code{bfd_coff_backend_data} |
| 54 |
structure, one of which exists for each target. |
| 55 |
|
| 56 |
The essentially similar target-specific routines are in |
| 57 |
@file{coffcode.h}. This header file includes executable C code. |
| 58 |
The various Coff targets first include the appropriate Coff |
| 59 |
header file, make any special defines that are needed, and |
| 60 |
then include @file{coffcode.h}. |
| 61 |
|
| 62 |
Some of the Coff targets then also have additional routines in |
| 63 |
the target source file itself. |
| 64 |
|
| 65 |
@subsubsection Coff long section names |
| 66 |
In the standard Coff object format, section names are limited to |
| 67 |
the eight bytes available in the @code{s_name} field of the |
| 68 |
@code{SCNHDR} section header structure. The format requires the |
| 69 |
field to be NUL-padded, but not necessarily NUL-terminated, so |
| 70 |
the longest section names permitted are a full eight characters. |
| 71 |
|
| 72 |
The Microsoft PE variants of the Coff object file format add |
| 73 |
an extension to support the use of long section names. This |
| 74 |
extension is defined in section 4 of the Microsoft PE/COFF |
| 75 |
specification (rev 8.1). If a section name is too long to fit |
| 76 |
into the section header's @code{s_name} field, it is instead |
| 77 |
placed into the string table, and the @code{s_name} field is |
| 78 |
filled with a slash ("/") followed by the ASCII decimal |
| 79 |
representation of the offset of the full name relative to the |
| 80 |
string table base. |
| 81 |
|
| 82 |
Note that this implies that the extension can only be used in object |
| 83 |
files, as executables do not contain a string table. The standard |
| 84 |
specifies that long section names from objects emitted into executable |
| 85 |
images are to be truncated. |
| 86 |
|
| 87 |
However, as a GNU extension, BFD can generate executable images |
| 88 |
that contain a string table and long section names. This |
| 89 |
would appear to be technically valid, as the standard only says |
| 90 |
that Coff debugging information is deprecated, not forbidden, |
| 91 |
and in practice it works, although some tools that parse PE files |
| 92 |
expecting the MS standard format may become confused; @file{PEview} is |
| 93 |
one known example. |
| 94 |
|
| 95 |
The functionality is supported in BFD by code implemented under |
| 96 |
the control of the macro @code{COFF_LONG_SECTION_NAMES}. If not |
| 97 |
defined, the format does not support long section names in any way. |
| 98 |
If defined, it is used to initialise a flag, |
| 99 |
@code{_bfd_coff_long_section_names}, and a hook function pointer, |
| 100 |
@code{_bfd_coff_set_long_section_names}, in the Coff backend data |
| 101 |
structure. The flag controls the generation of long section names |
| 102 |
in output BFDs at runtime; if it is false, as it will be by default |
| 103 |
when generating an executable image, long section names are truncated; |
| 104 |
if true, the long section names extension is employed. The hook |
| 105 |
points to a function that allows the value of the flag to be altered |
| 106 |
at runtime, on formats that support long section names at all; on |
| 107 |
other formats it points to a stub that returns an error indication. |
| 108 |
|
| 109 |
With input BFDs, the flag is set according to whether any long section |
| 110 |
names are detected while reading the section headers. For a completely |
| 111 |
new BFD, the flag is set to the default for the target format. This |
| 112 |
information can be used by a client of the BFD library when deciding |
| 113 |
what output format to generate, and means that a BFD that is opened |
| 114 |
for read and subsequently converted to a writeable BFD and modified |
| 115 |
in-place will retain whatever format it had on input. |
| 116 |
|
| 117 |
If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is |
| 118 |
defined to the value "1", then long section names are enabled by |
| 119 |
default; if it is defined to the value zero, they are disabled by |
| 120 |
default (but still accepted in input BFDs). The header @file{coffcode.h} |
| 121 |
defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is |
| 122 |
used in the backends to initialise the backend data structure fields |
| 123 |
appropriately; see the comments for further detail. |
| 124 |
|
| 125 |
@subsubsection Bit twiddling |
| 126 |
Each flavour of coff supported in BFD has its own header file |
| 127 |
describing the external layout of the structures. There is also |
| 128 |
an internal description of the coff layout, in |
| 129 |
@file{coff/internal.h}. A major function of the |
| 130 |
coff backend is swapping the bytes and twiddling the bits to |
| 131 |
translate the external form of the structures into the normal |
| 132 |
internal form. This is all performed in the |
| 133 |
@code{bfd_swap}_@i{thing}_@i{direction} routines. Some |
| 134 |
elements are different sizes between different versions of |
| 135 |
coff; it is the duty of the coff version specific include file |
| 136 |
to override the definitions of various packing routines in |
| 137 |
@file{coffcode.h}. E.g., the size of line number entry in coff is |
| 138 |
sometimes 16 bits, and sometimes 32 bits. @code{#define}ing |
| 139 |
@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the |
| 140 |
correct one. No doubt, some day someone will find a version of |
| 141 |
coff which has a varying field size not catered to at the |
| 142 |
moment. To port BFD, that person will have to add more @code{#defines}. |
| 143 |
Three of the bit twiddling routines are exported to |
| 144 |
@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in} |
| 145 |
and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol |
| 146 |
table on its own, but uses BFD to fix things up. More of the |
| 147 |
bit twiddlers are exported for @code{gas}; |
| 148 |
@code{coff_swap_aux_out}, @code{coff_swap_sym_out}, |
| 149 |
@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out}, |
| 150 |
@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out}, |
| 151 |
@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track |
| 152 |
of all the symbol table and reloc drudgery itself, thereby |
| 153 |
saving the internal BFD overhead, but uses BFD to swap things |
| 154 |
on the way out, making cross ports much safer. Doing so also |
| 155 |
allows BFD (and thus the linker) to use the same header files |
| 156 |
as @code{gas}, which makes one avenue to disaster disappear. |
| 157 |
|
| 158 |
@subsubsection Symbol reading |
| 159 |
The simple canonical form for symbols used by BFD is not rich |
| 160 |
enough to keep all the information available in a coff symbol |
| 161 |
table. The back end gets around this problem by keeping the original |
| 162 |
symbol table around, "behind the scenes". |
| 163 |
|
| 164 |
When a symbol table is requested (through a call to |
| 165 |
@code{bfd_canonicalize_symtab}), a request gets through to |
| 166 |
@code{coff_get_normalized_symtab}. This reads the symbol table from |
| 167 |
the coff file and swaps all the structures inside into the |
| 168 |
internal form. It also fixes up all the pointers in the table |
| 169 |
(represented in the file by offsets from the first symbol in |
| 170 |
the table) into physical pointers to elements in the new |
| 171 |
internal table. This involves some work since the meanings of |
| 172 |
fields change depending upon context: a field that is a |
| 173 |
pointer to another structure in the symbol table at one moment |
| 174 |
may be the size in bytes of a structure at the next. Another |
| 175 |
pass is made over the table. All symbols which mark file names |
| 176 |
(@code{C_FILE} symbols) are modified so that the internal |
| 177 |
string points to the value in the auxent (the real filename) |
| 178 |
rather than the normal text associated with the symbol |
| 179 |
(@code{".file"}). |
| 180 |
|
| 181 |
At this time the symbol names are moved around. Coff stores |
| 182 |
all symbols less than nine characters long physically |
| 183 |
within the symbol table; longer strings are kept at the end of |
| 184 |
the file in the string table. This pass moves all strings |
| 185 |
into memory and replaces them with pointers to the strings. |
| 186 |
|
| 187 |
The symbol table is massaged once again, this time to create |
| 188 |
the canonical table used by the BFD application. Each symbol |
| 189 |
is inspected in turn, and a decision made (using the |
| 190 |
@code{sclass} field) about the various flags to set in the |
| 191 |
@code{asymbol}. @xref{Symbols}. The generated canonical table |
| 192 |
shares strings with the hidden internal symbol table. |
| 193 |
|
| 194 |
Any linenumbers are read from the coff file too, and attached |
| 195 |
to the symbols which own the functions the linenumbers belong to. |
| 196 |
|
| 197 |
@subsubsection Symbol writing |
| 198 |
Writing a symbol to a coff file which didn't come from a coff |
| 199 |
file will lose any debugging information. The @code{asymbol} |
| 200 |
structure remembers the BFD from which the symbol was taken, and on |
| 201 |
output the back end makes sure that the same destination target as |
| 202 |
source target is present. |
| 203 |
|
| 204 |
When the symbols have come from a coff file then all the |
| 205 |
debugging information is preserved. |
| 206 |
|
| 207 |
Symbol tables are provided for writing to the back end in a |
| 208 |
vector of pointers to pointers. This allows applications like |
| 209 |
the linker to accumulate and output large symbol tables |
| 210 |
without having to do too much byte copying. |
| 211 |
|
| 212 |
This function runs through the provided symbol table and |
| 213 |
patches each symbol marked as a file place holder |
| 214 |
(@code{C_FILE}) to point to the next file place holder in the |
| 215 |
list. It also marks each @code{offset} field in the list with |
| 216 |
the offset from the first symbol of the current symbol. |
| 217 |
|
| 218 |
Another function of this procedure is to turn the canonical |
| 219 |
value form of BFD into the form used by coff. Internally, BFD |
| 220 |
expects symbol values to be offsets from a section base; so a |
| 221 |
symbol physically at 0x120, but in a section starting at |
| 222 |
0x100, would have the value 0x20. Coff expects symbols to |
| 223 |
contain their final value, so symbols have their values |
| 224 |
changed at this point to reflect their sum with their owning |
| 225 |
section. This transformation uses the |
| 226 |
@code{output_section} field of the @code{asymbol}'s |
| 227 |
@code{asection} @xref{Sections}. |
| 228 |
|
| 229 |
@itemize @bullet |
| 230 |
|
| 231 |
@item |
| 232 |
@code{coff_mangle_symbols} |
| 233 |
@end itemize |
| 234 |
This routine runs though the provided symbol table and uses |
| 235 |
the offsets generated by the previous pass and the pointers |
| 236 |
generated when the symbol table was read in to create the |
| 237 |
structured hierarchy required by coff. It changes each pointer |
| 238 |
to a symbol into the index into the symbol table of the asymbol. |
| 239 |
|
| 240 |
@itemize @bullet |
| 241 |
|
| 242 |
@item |
| 243 |
@code{coff_write_symbols} |
| 244 |
@end itemize |
| 245 |
This routine runs through the symbol table and patches up the |
| 246 |
symbols from their internal form into the coff way, calls the |
| 247 |
bit twiddlers, and writes out the table to the file. |
| 248 |
|
| 249 |
@findex coff_symbol_type |
| 250 |
@subsubsection @code{coff_symbol_type} |
| 251 |
@strong{Description}@* |
| 252 |
The hidden information for an @code{asymbol} is described in a |
| 253 |
@code{combined_entry_type}: |
| 254 |
|
| 255 |
|
| 256 |
@example |
| 257 |
|
| 258 |
typedef struct coff_ptr_struct |
| 259 |
@{ |
| 260 |
/* Remembers the offset from the first symbol in the file for |
| 261 |
this symbol. Generated by coff_renumber_symbols. */ |
| 262 |
unsigned int offset; |
| 263 |
|
| 264 |
/* Should the value of this symbol be renumbered. Used for |
| 265 |
XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */ |
| 266 |
unsigned int fix_value : 1; |
| 267 |
|
| 268 |
/* Should the tag field of this symbol be renumbered. |
| 269 |
Created by coff_pointerize_aux. */ |
| 270 |
unsigned int fix_tag : 1; |
| 271 |
|
| 272 |
/* Should the endidx field of this symbol be renumbered. |
| 273 |
Created by coff_pointerize_aux. */ |
| 274 |
unsigned int fix_end : 1; |
| 275 |
|
| 276 |
/* Should the x_csect.x_scnlen field be renumbered. |
| 277 |
Created by coff_pointerize_aux. */ |
| 278 |
unsigned int fix_scnlen : 1; |
| 279 |
|
| 280 |
/* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the |
| 281 |
index into the line number entries. Set by coff_slurp_symbol_table. */ |
| 282 |
unsigned int fix_line : 1; |
| 283 |
|
| 284 |
/* The container for the symbol structure as read and translated |
| 285 |
from the file. */ |
| 286 |
union |
| 287 |
@{ |
| 288 |
union internal_auxent auxent; |
| 289 |
struct internal_syment syment; |
| 290 |
@} u; |
| 291 |
|
| 292 |
/* Selector for the union above. */ |
| 293 |
bfd_boolean is_sym; |
| 294 |
@} combined_entry_type; |
| 295 |
|
| 296 |
|
| 297 |
/* Each canonical asymbol really looks like this: */ |
| 298 |
|
| 299 |
typedef struct coff_symbol_struct |
| 300 |
@{ |
| 301 |
/* The actual symbol which the rest of BFD works with */ |
| 302 |
asymbol symbol; |
| 303 |
|
| 304 |
/* A pointer to the hidden information for this symbol */ |
| 305 |
combined_entry_type *native; |
| 306 |
|
| 307 |
/* A pointer to the linenumber information for this symbol */ |
| 308 |
struct lineno_cache_entry *lineno; |
| 309 |
|
| 310 |
/* Have the line numbers been relocated yet ? */ |
| 311 |
bfd_boolean done_lineno; |
| 312 |
@} coff_symbol_type; |
| 313 |
@end example |
| 314 |
@findex bfd_coff_backend_data |
| 315 |
@subsubsection @code{bfd_coff_backend_data} |
| 316 |
|
| 317 |
@example |
| 318 |
/* COFF symbol classifications. */ |
| 319 |
|
| 320 |
enum coff_symbol_classification |
| 321 |
@{ |
| 322 |
/* Global symbol. */ |
| 323 |
COFF_SYMBOL_GLOBAL, |
| 324 |
/* Common symbol. */ |
| 325 |
COFF_SYMBOL_COMMON, |
| 326 |
/* Undefined symbol. */ |
| 327 |
COFF_SYMBOL_UNDEFINED, |
| 328 |
/* Local symbol. */ |
| 329 |
COFF_SYMBOL_LOCAL, |
| 330 |
/* PE section symbol. */ |
| 331 |
COFF_SYMBOL_PE_SECTION |
| 332 |
@}; |
| 333 |
|
| 334 |
typedef asection * (*coff_gc_mark_hook_fn) |
| 335 |
(asection *, struct bfd_link_info *, struct internal_reloc *, |
| 336 |
struct coff_link_hash_entry *, struct internal_syment *); |
| 337 |
|
| 338 |
@end example |
| 339 |
Special entry points for gdb to swap in coff symbol table parts: |
| 340 |
@example |
| 341 |
typedef struct |
| 342 |
@{ |
| 343 |
void (*_bfd_coff_swap_aux_in) |
| 344 |
(bfd *, void *, int, int, int, int, void *); |
| 345 |
|
| 346 |
void (*_bfd_coff_swap_sym_in) |
| 347 |
(bfd *, void *, void *); |
| 348 |
|
| 349 |
void (*_bfd_coff_swap_lineno_in) |
| 350 |
(bfd *, void *, void *); |
| 351 |
|
| 352 |
unsigned int (*_bfd_coff_swap_aux_out) |
| 353 |
(bfd *, void *, int, int, int, int, void *); |
| 354 |
|
| 355 |
unsigned int (*_bfd_coff_swap_sym_out) |
| 356 |
(bfd *, void *, void *); |
| 357 |
|
| 358 |
unsigned int (*_bfd_coff_swap_lineno_out) |
| 359 |
(bfd *, void *, void *); |
| 360 |
|
| 361 |
unsigned int (*_bfd_coff_swap_reloc_out) |
| 362 |
(bfd *, void *, void *); |
| 363 |
|
| 364 |
unsigned int (*_bfd_coff_swap_filehdr_out) |
| 365 |
(bfd *, void *, void *); |
| 366 |
|
| 367 |
unsigned int (*_bfd_coff_swap_aouthdr_out) |
| 368 |
(bfd *, void *, void *); |
| 369 |
|
| 370 |
unsigned int (*_bfd_coff_swap_scnhdr_out) |
| 371 |
(bfd *, void *, void *); |
| 372 |
|
| 373 |
unsigned int _bfd_filhsz; |
| 374 |
unsigned int _bfd_aoutsz; |
| 375 |
unsigned int _bfd_scnhsz; |
| 376 |
unsigned int _bfd_symesz; |
| 377 |
unsigned int _bfd_auxesz; |
| 378 |
unsigned int _bfd_relsz; |
| 379 |
unsigned int _bfd_linesz; |
| 380 |
unsigned int _bfd_filnmlen; |
| 381 |
bfd_boolean _bfd_coff_long_filenames; |
| 382 |
|
| 383 |
bfd_boolean _bfd_coff_long_section_names; |
| 384 |
bfd_boolean (*_bfd_coff_set_long_section_names) |
| 385 |
(bfd *, int); |
| 386 |
|
| 387 |
unsigned int _bfd_coff_default_section_alignment_power; |
| 388 |
bfd_boolean _bfd_coff_force_symnames_in_strings; |
| 389 |
unsigned int _bfd_coff_debug_string_prefix_length; |
| 390 |
unsigned int _bfd_coff_max_nscns; |
| 391 |
|
| 392 |
void (*_bfd_coff_swap_filehdr_in) |
| 393 |
(bfd *, void *, void *); |
| 394 |
|
| 395 |
void (*_bfd_coff_swap_aouthdr_in) |
| 396 |
(bfd *, void *, void *); |
| 397 |
|
| 398 |
void (*_bfd_coff_swap_scnhdr_in) |
| 399 |
(bfd *, void *, void *); |
| 400 |
|
| 401 |
void (*_bfd_coff_swap_reloc_in) |
| 402 |
(bfd *abfd, void *, void *); |
| 403 |
|
| 404 |
bfd_boolean (*_bfd_coff_bad_format_hook) |
| 405 |
(bfd *, void *); |
| 406 |
|
| 407 |
bfd_boolean (*_bfd_coff_set_arch_mach_hook) |
| 408 |
(bfd *, void *); |
| 409 |
|
| 410 |
void * (*_bfd_coff_mkobject_hook) |
| 411 |
(bfd *, void *, void *); |
| 412 |
|
| 413 |
bfd_boolean (*_bfd_styp_to_sec_flags_hook) |
| 414 |
(bfd *, void *, const char *, asection *, flagword *); |
| 415 |
|
| 416 |
void (*_bfd_set_alignment_hook) |
| 417 |
(bfd *, asection *, void *); |
| 418 |
|
| 419 |
bfd_boolean (*_bfd_coff_slurp_symbol_table) |
| 420 |
(bfd *); |
| 421 |
|
| 422 |
bfd_boolean (*_bfd_coff_symname_in_debug) |
| 423 |
(bfd *, struct internal_syment *); |
| 424 |
|
| 425 |
bfd_boolean (*_bfd_coff_pointerize_aux_hook) |
| 426 |
(bfd *, combined_entry_type *, combined_entry_type *, |
| 427 |
unsigned int, combined_entry_type *); |
| 428 |
|
| 429 |
bfd_boolean (*_bfd_coff_print_aux) |
| 430 |
(bfd *, FILE *, combined_entry_type *, combined_entry_type *, |
| 431 |
combined_entry_type *, unsigned int); |
| 432 |
|
| 433 |
void (*_bfd_coff_reloc16_extra_cases) |
| 434 |
(bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, |
| 435 |
bfd_byte *, unsigned int *, unsigned int *); |
| 436 |
|
| 437 |
int (*_bfd_coff_reloc16_estimate) |
| 438 |
(bfd *, asection *, arelent *, unsigned int, |
| 439 |
struct bfd_link_info *); |
| 440 |
|
| 441 |
enum coff_symbol_classification (*_bfd_coff_classify_symbol) |
| 442 |
(bfd *, struct internal_syment *); |
| 443 |
|
| 444 |
bfd_boolean (*_bfd_coff_compute_section_file_positions) |
| 445 |
(bfd *); |
| 446 |
|
| 447 |
bfd_boolean (*_bfd_coff_start_final_link) |
| 448 |
(bfd *, struct bfd_link_info *); |
| 449 |
|
| 450 |
bfd_boolean (*_bfd_coff_relocate_section) |
| 451 |
(bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
| 452 |
struct internal_reloc *, struct internal_syment *, asection **); |
| 453 |
|
| 454 |
reloc_howto_type *(*_bfd_coff_rtype_to_howto) |
| 455 |
(bfd *, asection *, struct internal_reloc *, |
| 456 |
struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *); |
| 457 |
|
| 458 |
bfd_boolean (*_bfd_coff_adjust_symndx) |
| 459 |
(bfd *, struct bfd_link_info *, bfd *, asection *, |
| 460 |
struct internal_reloc *, bfd_boolean *); |
| 461 |
|
| 462 |
bfd_boolean (*_bfd_coff_link_add_one_symbol) |
| 463 |
(struct bfd_link_info *, bfd *, const char *, flagword, |
| 464 |
asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, |
| 465 |
struct bfd_link_hash_entry **); |
| 466 |
|
| 467 |
bfd_boolean (*_bfd_coff_link_output_has_begun) |
| 468 |
(bfd *, struct coff_final_link_info *); |
| 469 |
|
| 470 |
bfd_boolean (*_bfd_coff_final_link_postscript) |
| 471 |
(bfd *, struct coff_final_link_info *); |
| 472 |
|
| 473 |
bfd_boolean (*_bfd_coff_print_pdata) |
| 474 |
(bfd *, void *); |
| 475 |
|
| 476 |
@} bfd_coff_backend_data; |
| 477 |
|
| 478 |
#define coff_backend_info(abfd) \ |
| 479 |
((bfd_coff_backend_data *) (abfd)->xvec->backend_data) |
| 480 |
|
| 481 |
#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ |
| 482 |
((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) |
| 483 |
|
| 484 |
#define bfd_coff_swap_sym_in(a,e,i) \ |
| 485 |
((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i)) |
| 486 |
|
| 487 |
#define bfd_coff_swap_lineno_in(a,e,i) \ |
| 488 |
((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i)) |
| 489 |
|
| 490 |
#define bfd_coff_swap_reloc_out(abfd, i, o) \ |
| 491 |
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o)) |
| 492 |
|
| 493 |
#define bfd_coff_swap_lineno_out(abfd, i, o) \ |
| 494 |
((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o)) |
| 495 |
|
| 496 |
#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \ |
| 497 |
((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o)) |
| 498 |
|
| 499 |
#define bfd_coff_swap_sym_out(abfd, i,o) \ |
| 500 |
((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o)) |
| 501 |
|
| 502 |
#define bfd_coff_swap_scnhdr_out(abfd, i,o) \ |
| 503 |
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o)) |
| 504 |
|
| 505 |
#define bfd_coff_swap_filehdr_out(abfd, i,o) \ |
| 506 |
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o)) |
| 507 |
|
| 508 |
#define bfd_coff_swap_aouthdr_out(abfd, i,o) \ |
| 509 |
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o)) |
| 510 |
|
| 511 |
#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz) |
| 512 |
#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz) |
| 513 |
#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz) |
| 514 |
#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz) |
| 515 |
#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz) |
| 516 |
#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz) |
| 517 |
#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz) |
| 518 |
#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen) |
| 519 |
#define bfd_coff_long_filenames(abfd) \ |
| 520 |
(coff_backend_info (abfd)->_bfd_coff_long_filenames) |
| 521 |
#define bfd_coff_long_section_names(abfd) \ |
| 522 |
(coff_backend_info (abfd)->_bfd_coff_long_section_names) |
| 523 |
#define bfd_coff_set_long_section_names(abfd, enable) \ |
| 524 |
((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable)) |
| 525 |
#define bfd_coff_default_section_alignment_power(abfd) \ |
| 526 |
(coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power) |
| 527 |
#define bfd_coff_max_nscns(abfd) \ |
| 528 |
(coff_backend_info (abfd)->_bfd_coff_max_nscns) |
| 529 |
|
| 530 |
#define bfd_coff_swap_filehdr_in(abfd, i,o) \ |
| 531 |
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o)) |
| 532 |
|
| 533 |
#define bfd_coff_swap_aouthdr_in(abfd, i,o) \ |
| 534 |
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o)) |
| 535 |
|
| 536 |
#define bfd_coff_swap_scnhdr_in(abfd, i,o) \ |
| 537 |
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o)) |
| 538 |
|
| 539 |
#define bfd_coff_swap_reloc_in(abfd, i, o) \ |
| 540 |
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o)) |
| 541 |
|
| 542 |
#define bfd_coff_bad_format_hook(abfd, filehdr) \ |
| 543 |
((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr)) |
| 544 |
|
| 545 |
#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\ |
| 546 |
((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr)) |
| 547 |
#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\ |
| 548 |
((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\ |
| 549 |
(abfd, filehdr, aouthdr)) |
| 550 |
|
| 551 |
#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\ |
| 552 |
((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\ |
| 553 |
(abfd, scnhdr, name, section, flags_ptr)) |
| 554 |
|
| 555 |
#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\ |
| 556 |
((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr)) |
| 557 |
|
| 558 |
#define bfd_coff_slurp_symbol_table(abfd)\ |
| 559 |
((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd)) |
| 560 |
|
| 561 |
#define bfd_coff_symname_in_debug(abfd, sym)\ |
| 562 |
((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym)) |
| 563 |
|
| 564 |
#define bfd_coff_force_symnames_in_strings(abfd)\ |
| 565 |
(coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings) |
| 566 |
|
| 567 |
#define bfd_coff_debug_string_prefix_length(abfd)\ |
| 568 |
(coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length) |
| 569 |
|
| 570 |
#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\ |
| 571 |
((coff_backend_info (abfd)->_bfd_coff_print_aux)\ |
| 572 |
(abfd, file, base, symbol, aux, indaux)) |
| 573 |
|
| 574 |
#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\ |
| 575 |
reloc, data, src_ptr, dst_ptr)\ |
| 576 |
((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\ |
| 577 |
(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)) |
| 578 |
|
| 579 |
#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\ |
| 580 |
((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\ |
| 581 |
(abfd, section, reloc, shrink, link_info)) |
| 582 |
|
| 583 |
#define bfd_coff_classify_symbol(abfd, sym)\ |
| 584 |
((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\ |
| 585 |
(abfd, sym)) |
| 586 |
|
| 587 |
#define bfd_coff_compute_section_file_positions(abfd)\ |
| 588 |
((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\ |
| 589 |
(abfd)) |
| 590 |
|
| 591 |
#define bfd_coff_start_final_link(obfd, info)\ |
| 592 |
((coff_backend_info (obfd)->_bfd_coff_start_final_link)\ |
| 593 |
(obfd, info)) |
| 594 |
#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\ |
| 595 |
((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\ |
| 596 |
(obfd, info, ibfd, o, con, rel, isyms, secs)) |
| 597 |
#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\ |
| 598 |
((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\ |
| 599 |
(abfd, sec, rel, h, sym, addendp)) |
| 600 |
#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\ |
| 601 |
((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\ |
| 602 |
(obfd, info, ibfd, sec, rel, adjustedp)) |
| 603 |
#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\ |
| 604 |
value, string, cp, coll, hashp)\ |
| 605 |
((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\ |
| 606 |
(info, abfd, name, flags, section, value, string, cp, coll, hashp)) |
| 607 |
|
| 608 |
#define bfd_coff_link_output_has_begun(a,p) \ |
| 609 |
((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p)) |
| 610 |
#define bfd_coff_final_link_postscript(a,p) \ |
| 611 |
((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p)) |
| 612 |
|
| 613 |
#define bfd_coff_have_print_pdata(a) \ |
| 614 |
(coff_backend_info (a)->_bfd_coff_print_pdata) |
| 615 |
#define bfd_coff_print_pdata(a,p) \ |
| 616 |
((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p)) |
| 617 |
|
| 618 |
/* Macro: Returns true if the bfd is a PE executable as opposed to a |
| 619 |
PE object file. */ |
| 620 |
#define bfd_pei_p(abfd) \ |
| 621 |
(CONST_STRNEQ ((abfd)->xvec->name, "pei-")) |
| 622 |
@end example |
| 623 |
@subsubsection Writing relocations |
| 624 |
To write relocations, the back end steps though the |
| 625 |
canonical relocation table and create an |
| 626 |
@code{internal_reloc}. The symbol index to use is removed from |
| 627 |
the @code{offset} field in the symbol table supplied. The |
| 628 |
address comes directly from the sum of the section base |
| 629 |
address and the relocation offset; the type is dug directly |
| 630 |
from the howto field. Then the @code{internal_reloc} is |
| 631 |
swapped into the shape of an @code{external_reloc} and written |
| 632 |
out to disk. |
| 633 |
|
| 634 |
@subsubsection Reading linenumbers |
| 635 |
Creating the linenumber table is done by reading in the entire |
| 636 |
coff linenumber table, and creating another table for internal use. |
| 637 |
|
| 638 |
A coff linenumber table is structured so that each function |
| 639 |
is marked as having a line number of 0. Each line within the |
| 640 |
function is an offset from the first line in the function. The |
| 641 |
base of the line number information for the table is stored in |
| 642 |
the symbol associated with the function. |
| 643 |
|
| 644 |
Note: The PE format uses line number 0 for a flag indicating a |
| 645 |
new source file. |
| 646 |
|
| 647 |
The information is copied from the external to the internal |
| 648 |
table, and each symbol which marks a function is marked by |
| 649 |
pointing its... |
| 650 |
|
| 651 |
How does this work ? |
| 652 |
|
| 653 |
@subsubsection Reading relocations |
| 654 |
Coff relocations are easily transformed into the internal BFD form |
| 655 |
(@code{arelent}). |
| 656 |
|
| 657 |
Reading a coff relocation table is done in the following stages: |
| 658 |
|
| 659 |
@itemize @bullet |
| 660 |
|
| 661 |
@item |
| 662 |
Read the entire coff relocation table into memory. |
| 663 |
|
| 664 |
@item |
| 665 |
Process each relocation in turn; first swap it from the |
| 666 |
external to the internal form. |
| 667 |
|
| 668 |
@item |
| 669 |
Turn the symbol referenced in the relocation's symbol index |
| 670 |
into a pointer into the canonical symbol table. |
| 671 |
This table is the same as the one returned by a call to |
| 672 |
@code{bfd_canonicalize_symtab}. The back end will call that |
| 673 |
routine and save the result if a canonicalization hasn't been done. |
| 674 |
|
| 675 |
@item |
| 676 |
The reloc index is turned into a pointer to a howto |
| 677 |
structure, in a back end specific way. For instance, the 386 |
| 678 |
uses the @code{r_type} to directly produce an index |
| 679 |
into a howto table vector. |
| 680 |
@end itemize |
| 681 |
|