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 306 /* Selector for the union above. */ 307 bfd_boolean is_sym; 308@} combined_entry_type; 309 310 311/* Each canonical asymbol really looks like this: */ 312 313typedef struct coff_symbol_struct 314@{ 315 /* The actual symbol which the rest of BFD works with */ 316 asymbol symbol; 317 318 /* A pointer to the hidden information for this symbol */ 319 combined_entry_type *native; 320 321 /* A pointer to the linenumber information for this symbol */ 322 struct lineno_cache_entry *lineno; 323 324 /* Have the line numbers been relocated yet ? */ 325 bfd_boolean done_lineno; 326@} coff_symbol_type; 327@end example 328@findex bfd_coff_backend_data 329@subsubsection @code{bfd_coff_backend_data} 330 331@example 332/* COFF symbol classifications. */ 333 334enum coff_symbol_classification 335@{ 336 /* Global symbol. */ 337 COFF_SYMBOL_GLOBAL, 338 /* Common symbol. */ 339 COFF_SYMBOL_COMMON, 340 /* Undefined symbol. */ 341 COFF_SYMBOL_UNDEFINED, 342 /* Local symbol. */ 343 COFF_SYMBOL_LOCAL, 344 /* PE section symbol. */ 345 COFF_SYMBOL_PE_SECTION 346@}; 347 348typedef asection * (*coff_gc_mark_hook_fn) 349 (asection *, struct bfd_link_info *, struct internal_reloc *, 350 struct coff_link_hash_entry *, struct internal_syment *); 351 352@end example 353Special entry points for gdb to swap in coff symbol table parts: 354@example 355typedef struct 356@{ 357 void (*_bfd_coff_swap_aux_in) 358 (bfd *, void *, int, int, int, int, void *); 359 360 void (*_bfd_coff_swap_sym_in) 361 (bfd *, void *, void *); 362 363 void (*_bfd_coff_swap_lineno_in) 364 (bfd *, void *, void *); 365 366 unsigned int (*_bfd_coff_swap_aux_out) 367 (bfd *, void *, int, int, int, int, void *); 368 369 unsigned int (*_bfd_coff_swap_sym_out) 370 (bfd *, void *, void *); 371 372 unsigned int (*_bfd_coff_swap_lineno_out) 373 (bfd *, void *, void *); 374 375 unsigned int (*_bfd_coff_swap_reloc_out) 376 (bfd *, void *, void *); 377 378 unsigned int (*_bfd_coff_swap_filehdr_out) 379 (bfd *, void *, void *); 380 381 unsigned int (*_bfd_coff_swap_aouthdr_out) 382 (bfd *, void *, void *); 383 384 unsigned int (*_bfd_coff_swap_scnhdr_out) 385 (bfd *, void *, void *); 386 387 unsigned int _bfd_filhsz; 388 unsigned int _bfd_aoutsz; 389 unsigned int _bfd_scnhsz; 390 unsigned int _bfd_symesz; 391 unsigned int _bfd_auxesz; 392 unsigned int _bfd_relsz; 393 unsigned int _bfd_linesz; 394 unsigned int _bfd_filnmlen; 395 bfd_boolean _bfd_coff_long_filenames; 396 397 bfd_boolean _bfd_coff_long_section_names; 398 bfd_boolean (*_bfd_coff_set_long_section_names) 399 (bfd *, int); 400 401 unsigned int _bfd_coff_default_section_alignment_power; 402 bfd_boolean _bfd_coff_force_symnames_in_strings; 403 unsigned int _bfd_coff_debug_string_prefix_length; 404 unsigned int _bfd_coff_max_nscns; 405 406 void (*_bfd_coff_swap_filehdr_in) 407 (bfd *, void *, void *); 408 409 void (*_bfd_coff_swap_aouthdr_in) 410 (bfd *, void *, void *); 411 412 void (*_bfd_coff_swap_scnhdr_in) 413 (bfd *, void *, void *); 414 415 void (*_bfd_coff_swap_reloc_in) 416 (bfd *abfd, void *, void *); 417 418 bfd_boolean (*_bfd_coff_bad_format_hook) 419 (bfd *, void *); 420 421 bfd_boolean (*_bfd_coff_set_arch_mach_hook) 422 (bfd *, void *); 423 424 void * (*_bfd_coff_mkobject_hook) 425 (bfd *, void *, void *); 426 427 bfd_boolean (*_bfd_styp_to_sec_flags_hook) 428 (bfd *, void *, const char *, asection *, flagword *); 429 430 void (*_bfd_set_alignment_hook) 431 (bfd *, asection *, void *); 432 433 bfd_boolean (*_bfd_coff_slurp_symbol_table) 434 (bfd *); 435 436 bfd_boolean (*_bfd_coff_symname_in_debug) 437 (bfd *, struct internal_syment *); 438 439 bfd_boolean (*_bfd_coff_pointerize_aux_hook) 440 (bfd *, combined_entry_type *, combined_entry_type *, 441 unsigned int, combined_entry_type *); 442 443 bfd_boolean (*_bfd_coff_print_aux) 444 (bfd *, FILE *, combined_entry_type *, combined_entry_type *, 445 combined_entry_type *, unsigned int); 446 447 void (*_bfd_coff_reloc16_extra_cases) 448 (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, 449 bfd_byte *, unsigned int *, unsigned int *); 450 451 int (*_bfd_coff_reloc16_estimate) 452 (bfd *, asection *, arelent *, unsigned int, 453 struct bfd_link_info *); 454 455 enum coff_symbol_classification (*_bfd_coff_classify_symbol) 456 (bfd *, struct internal_syment *); 457 458 bfd_boolean (*_bfd_coff_compute_section_file_positions) 459 (bfd *); 460 461 bfd_boolean (*_bfd_coff_start_final_link) 462 (bfd *, struct bfd_link_info *); 463 464 bfd_boolean (*_bfd_coff_relocate_section) 465 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 466 struct internal_reloc *, struct internal_syment *, asection **); 467 468 reloc_howto_type *(*_bfd_coff_rtype_to_howto) 469 (bfd *, asection *, struct internal_reloc *, 470 struct coff_link_hash_entry *, struct internal_syment *, 471 bfd_vma *); 472 473 bfd_boolean (*_bfd_coff_adjust_symndx) 474 (bfd *, struct bfd_link_info *, bfd *, asection *, 475 struct internal_reloc *, bfd_boolean *); 476 477 bfd_boolean (*_bfd_coff_link_add_one_symbol) 478 (struct bfd_link_info *, bfd *, const char *, flagword, 479 asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, 480 struct bfd_link_hash_entry **); 481 482 bfd_boolean (*_bfd_coff_link_output_has_begun) 483 (bfd *, struct coff_final_link_info *); 484 485 bfd_boolean (*_bfd_coff_final_link_postscript) 486 (bfd *, struct coff_final_link_info *); 487 488 bfd_boolean (*_bfd_coff_print_pdata) 489 (bfd *, void *); 490 491@} bfd_coff_backend_data; 492 493#define coff_backend_info(abfd) \ 494 ((bfd_coff_backend_data *) (abfd)->xvec->backend_data) 495 496#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ 497 ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) 498 499#define bfd_coff_swap_sym_in(a,e,i) \ 500 ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i)) 501 502#define bfd_coff_swap_lineno_in(a,e,i) \ 503 ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i)) 504 505#define bfd_coff_swap_reloc_out(abfd, i, o) \ 506 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o)) 507 508#define bfd_coff_swap_lineno_out(abfd, i, o) \ 509 ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o)) 510 511#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \ 512 ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o)) 513 514#define bfd_coff_swap_sym_out(abfd, i,o) \ 515 ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o)) 516 517#define bfd_coff_swap_scnhdr_out(abfd, i,o) \ 518 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o)) 519 520#define bfd_coff_swap_filehdr_out(abfd, i,o) \ 521 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o)) 522 523#define bfd_coff_swap_aouthdr_out(abfd, i,o) \ 524 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o)) 525 526#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz) 527#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz) 528#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz) 529#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz) 530#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz) 531#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz) 532#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz) 533#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen) 534#define bfd_coff_long_filenames(abfd) \ 535 (coff_backend_info (abfd)->_bfd_coff_long_filenames) 536#define bfd_coff_long_section_names(abfd) \ 537 (coff_backend_info (abfd)->_bfd_coff_long_section_names) 538#define bfd_coff_set_long_section_names(abfd, enable) \ 539 ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable)) 540#define bfd_coff_default_section_alignment_power(abfd) \ 541 (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power) 542#define bfd_coff_max_nscns(abfd) \ 543 (coff_backend_info (abfd)->_bfd_coff_max_nscns) 544 545#define bfd_coff_swap_filehdr_in(abfd, i,o) \ 546 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o)) 547 548#define bfd_coff_swap_aouthdr_in(abfd, i,o) \ 549 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o)) 550 551#define bfd_coff_swap_scnhdr_in(abfd, i,o) \ 552 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o)) 553 554#define bfd_coff_swap_reloc_in(abfd, i, o) \ 555 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o)) 556 557#define bfd_coff_bad_format_hook(abfd, filehdr) \ 558 ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr)) 559 560#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\ 561 ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr)) 562#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\ 563 ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\ 564 (abfd, filehdr, aouthdr)) 565 566#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\ 567 ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\ 568 (abfd, scnhdr, name, section, flags_ptr)) 569 570#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\ 571 ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr)) 572 573#define bfd_coff_slurp_symbol_table(abfd)\ 574 ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd)) 575 576#define bfd_coff_symname_in_debug(abfd, sym)\ 577 ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym)) 578 579#define bfd_coff_force_symnames_in_strings(abfd)\ 580 (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings) 581 582#define bfd_coff_debug_string_prefix_length(abfd)\ 583 (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length) 584 585#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\ 586 ((coff_backend_info (abfd)->_bfd_coff_print_aux)\ 587 (abfd, file, base, symbol, aux, indaux)) 588 589#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\ 590 reloc, data, src_ptr, dst_ptr)\ 591 ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\ 592 (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)) 593 594#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\ 595 ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\ 596 (abfd, section, reloc, shrink, link_info)) 597 598#define bfd_coff_classify_symbol(abfd, sym)\ 599 ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\ 600 (abfd, sym)) 601 602#define bfd_coff_compute_section_file_positions(abfd)\ 603 ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\ 604 (abfd)) 605 606#define bfd_coff_start_final_link(obfd, info)\ 607 ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\ 608 (obfd, info)) 609#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\ 610 ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\ 611 (obfd, info, ibfd, o, con, rel, isyms, secs)) 612#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\ 613 ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\ 614 (abfd, sec, rel, h, sym, addendp)) 615#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\ 616 ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\ 617 (obfd, info, ibfd, sec, rel, adjustedp)) 618#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\ 619 value, string, cp, coll, hashp)\ 620 ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\ 621 (info, abfd, name, flags, section, value, string, cp, coll, hashp)) 622 623#define bfd_coff_link_output_has_begun(a,p) \ 624 ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p)) 625#define bfd_coff_final_link_postscript(a,p) \ 626 ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p)) 627 628#define bfd_coff_have_print_pdata(a) \ 629 (coff_backend_info (a)->_bfd_coff_print_pdata) 630#define bfd_coff_print_pdata(a,p) \ 631 ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p)) 632 633/* Macro: Returns true if the bfd is a PE executable as opposed to a 634 PE object file. */ 635#define bfd_pei_p(abfd) \ 636 (CONST_STRNEQ ((abfd)->xvec->name, "pei-")) 637@end example 638@subsubsection Writing relocations 639To write relocations, the back end steps though the 640canonical relocation table and create an 641@code{internal_reloc}. The symbol index to use is removed from 642the @code{offset} field in the symbol table supplied. The 643address comes directly from the sum of the section base 644address and the relocation offset; the type is dug directly 645from the howto field. Then the @code{internal_reloc} is 646swapped into the shape of an @code{external_reloc} and written 647out to disk. 648 649@subsubsection Reading linenumbers 650Creating the linenumber table is done by reading in the entire 651coff linenumber table, and creating another table for internal use. 652 653A coff linenumber table is structured so that each function 654is marked as having a line number of 0. Each line within the 655function is an offset from the first line in the function. The 656base of the line number information for the table is stored in 657the symbol associated with the function. 658 659Note: The PE format uses line number 0 for a flag indicating a 660new source file. 661 662The information is copied from the external to the internal 663table, and each symbol which marks a function is marked by 664pointing its... 665 666How does this work ? 667 668@subsubsection Reading relocations 669Coff relocations are easily transformed into the internal BFD form 670(@code{arelent}). 671 672Reading a coff relocation table is done in the following stages: 673 674@itemize @bullet 675 676@item 677Read the entire coff relocation table into memory. 678 679@item 680Process each relocation in turn; first swap it from the 681external to the internal form. 682 683@item 684Turn the symbol referenced in the relocation's symbol index 685into a pointer into the canonical symbol table. 686This table is the same as the one returned by a call to 687@code{bfd_canonicalize_symtab}. The back end will call that 688routine and save the result if a canonicalization hasn't been done. 689 690@item 691The reloc index is turned into a pointer to a howto 692structure, in a back end specific way. For instance, the 386 693and 960 use the @code{r_type} to directly produce an index 694into a howto table vector; the 88k subtracts a number from the 695@code{r_type} field and creates an addend field. 696@end itemize 697 698