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