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 Bit twiddling 80Each flavour of coff supported in BFD has its own header file 81describing the external layout of the structures. There is also 82an internal description of the coff layout, in 83@file{coff/internal.h}. A major function of the 84coff backend is swapping the bytes and twiddling the bits to 85translate the external form of the structures into the normal 86internal form. This is all performed in the 87@code{bfd_swap}_@i{thing}_@i{direction} routines. Some 88elements are different sizes between different versions of 89coff; it is the duty of the coff version specific include file 90to override the definitions of various packing routines in 91@file{coffcode.h}. E.g., the size of line number entry in coff is 92sometimes 16 bits, and sometimes 32 bits. @code{#define}ing 93@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the 94correct one. No doubt, some day someone will find a version of 95coff which has a varying field size not catered to at the 96moment. To port BFD, that person will have to add more @code{#defines}. 97Three of the bit twiddling routines are exported to 98@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in} 99and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol 100table on its own, but uses BFD to fix things up. More of the 101bit twiddlers are exported for @code{gas}; 102@code{coff_swap_aux_out}, @code{coff_swap_sym_out}, 103@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out}, 104@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out}, 105@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track 106of all the symbol table and reloc drudgery itself, thereby 107saving the internal BFD overhead, but uses BFD to swap things 108on the way out, making cross ports much safer. Doing so also 109allows BFD (and thus the linker) to use the same header files 110as @code{gas}, which makes one avenue to disaster disappear. 111 112@subsubsection Symbol reading 113The simple canonical form for symbols used by BFD is not rich 114enough to keep all the information available in a coff symbol 115table. The back end gets around this problem by keeping the original 116symbol table around, "behind the scenes". 117 118When a symbol table is requested (through a call to 119@code{bfd_canonicalize_symtab}), a request gets through to 120@code{coff_get_normalized_symtab}. This reads the symbol table from 121the coff file and swaps all the structures inside into the 122internal form. It also fixes up all the pointers in the table 123(represented in the file by offsets from the first symbol in 124the table) into physical pointers to elements in the new 125internal table. This involves some work since the meanings of 126fields change depending upon context: a field that is a 127pointer to another structure in the symbol table at one moment 128may be the size in bytes of a structure at the next. Another 129pass is made over the table. All symbols which mark file names 130(@code{C_FILE} symbols) are modified so that the internal 131string points to the value in the auxent (the real filename) 132rather than the normal text associated with the symbol 133(@code{".file"}). 134 135At this time the symbol names are moved around. Coff stores 136all symbols less than nine characters long physically 137within the symbol table; longer strings are kept at the end of 138the file in the string table. This pass moves all strings 139into memory and replaces them with pointers to the strings. 140 141The symbol table is massaged once again, this time to create 142the canonical table used by the BFD application. Each symbol 143is inspected in turn, and a decision made (using the 144@code{sclass} field) about the various flags to set in the 145@code{asymbol}. @xref{Symbols}. The generated canonical table 146shares strings with the hidden internal symbol table. 147 148Any linenumbers are read from the coff file too, and attached 149to the symbols which own the functions the linenumbers belong to. 150 151@subsubsection Symbol writing 152Writing a symbol to a coff file which didn't come from a coff 153file will lose any debugging information. The @code{asymbol} 154structure remembers the BFD from which the symbol was taken, and on 155output the back end makes sure that the same destination target as 156source target is present. 157 158When the symbols have come from a coff file then all the 159debugging information is preserved. 160 161Symbol tables are provided for writing to the back end in a 162vector of pointers to pointers. This allows applications like 163the linker to accumulate and output large symbol tables 164without having to do too much byte copying. 165 166This function runs through the provided symbol table and 167patches each symbol marked as a file place holder 168(@code{C_FILE}) to point to the next file place holder in the 169list. It also marks each @code{offset} field in the list with 170the offset from the first symbol of the current symbol. 171 172Another function of this procedure is to turn the canonical 173value form of BFD into the form used by coff. Internally, BFD 174expects symbol values to be offsets from a section base; so a 175symbol physically at 0x120, but in a section starting at 1760x100, would have the value 0x20. Coff expects symbols to 177contain their final value, so symbols have their values 178changed at this point to reflect their sum with their owning 179section. This transformation uses the 180@code{output_section} field of the @code{asymbol}'s 181@code{asection} @xref{Sections}. 182 183@itemize @bullet 184 185@item 186@code{coff_mangle_symbols} 187@end itemize 188This routine runs though the provided symbol table and uses 189the offsets generated by the previous pass and the pointers 190generated when the symbol table was read in to create the 191structured hierachy required by coff. It changes each pointer 192to a symbol into the index into the symbol table of the asymbol. 193 194@itemize @bullet 195 196@item 197@code{coff_write_symbols} 198@end itemize 199This routine runs through the symbol table and patches up the 200symbols from their internal form into the coff way, calls the 201bit twiddlers, and writes out the table to the file. 202 203@findex coff_symbol_type 204@subsubsection @code{coff_symbol_type} 205@strong{Description}@* 206The hidden information for an @code{asymbol} is described in a 207@code{combined_entry_type}: 208 209 210@example 211 212typedef struct coff_ptr_struct 213@{ 214 215 /* Remembers the offset from the first symbol in the file for 216 this symbol. Generated by coff_renumber_symbols. */ 217unsigned int offset; 218 219 /* Should the value of this symbol be renumbered. Used for 220 XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */ 221unsigned int fix_value : 1; 222 223 /* Should the tag field of this symbol be renumbered. 224 Created by coff_pointerize_aux. */ 225unsigned int fix_tag : 1; 226 227 /* Should the endidx field of this symbol be renumbered. 228 Created by coff_pointerize_aux. */ 229unsigned int fix_end : 1; 230 231 /* Should the x_csect.x_scnlen field be renumbered. 232 Created by coff_pointerize_aux. */ 233unsigned int fix_scnlen : 1; 234 235 /* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the 236 index into the line number entries. Set by 237 coff_slurp_symbol_table. */ 238unsigned int fix_line : 1; 239 240 /* The container for the symbol structure as read and translated 241 from the file. */ 242 243union @{ 244 union internal_auxent auxent; 245 struct internal_syment syment; 246 @} u; 247@} combined_entry_type; 248 249 250/* Each canonical asymbol really looks like this: */ 251 252typedef struct coff_symbol_struct 253@{ 254 /* The actual symbol which the rest of BFD works with */ 255asymbol symbol; 256 257 /* A pointer to the hidden information for this symbol */ 258combined_entry_type *native; 259 260 /* A pointer to the linenumber information for this symbol */ 261struct lineno_cache_entry *lineno; 262 263 /* Have the line numbers been relocated yet ? */ 264boolean done_lineno; 265@} coff_symbol_type; 266@end example 267@findex bfd_coff_backend_data 268@subsubsection @code{bfd_coff_backend_data} 269 270@example 271/* COFF symbol classifications. */ 272 273enum coff_symbol_classification 274@{ 275 /* Global symbol. */ 276 COFF_SYMBOL_GLOBAL, 277 /* Common symbol. */ 278 COFF_SYMBOL_COMMON, 279 /* Undefined symbol. */ 280 COFF_SYMBOL_UNDEFINED, 281 /* Local symbol. */ 282 COFF_SYMBOL_LOCAL, 283 /* PE section symbol. */ 284 COFF_SYMBOL_PE_SECTION 285@}; 286 287@end example 288Special entry points for gdb to swap in coff symbol table parts: 289@example 290typedef struct 291@{ 292 void (*_bfd_coff_swap_aux_in) PARAMS (( 293 bfd *abfd, 294 PTR ext, 295 int type, 296 int class, 297 int indaux, 298 int numaux, 299 PTR in)); 300 301 void (*_bfd_coff_swap_sym_in) PARAMS (( 302 bfd *abfd , 303 PTR ext, 304 PTR in)); 305 306 void (*_bfd_coff_swap_lineno_in) PARAMS (( 307 bfd *abfd, 308 PTR ext, 309 PTR in)); 310 311@end example 312Special entry points for gas to swap out coff parts: 313@example 314 unsigned int (*_bfd_coff_swap_aux_out) PARAMS (( 315 bfd *abfd, 316 PTR in, 317 int type, 318 int class, 319 int indaux, 320 int numaux, 321 PTR ext)); 322 323 unsigned int (*_bfd_coff_swap_sym_out) PARAMS (( 324 bfd *abfd, 325 PTR in, 326 PTR ext)); 327 328 unsigned int (*_bfd_coff_swap_lineno_out) PARAMS (( 329 bfd *abfd, 330 PTR in, 331 PTR ext)); 332 333 unsigned int (*_bfd_coff_swap_reloc_out) PARAMS (( 334 bfd *abfd, 335 PTR src, 336 PTR dst)); 337 338 unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS (( 339 bfd *abfd, 340 PTR in, 341 PTR out)); 342 343 unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS (( 344 bfd *abfd, 345 PTR in, 346 PTR out)); 347 348 unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS (( 349 bfd *abfd, 350 PTR in, 351 PTR out)); 352 353@end example 354Special entry points for generic COFF routines to call target 355dependent COFF routines: 356@example 357 unsigned int _bfd_filhsz; 358 unsigned int _bfd_aoutsz; 359 unsigned int _bfd_scnhsz; 360 unsigned int _bfd_symesz; 361 unsigned int _bfd_auxesz; 362 unsigned int _bfd_relsz; 363 unsigned int _bfd_linesz; 364 unsigned int _bfd_filnmlen; 365 boolean _bfd_coff_long_filenames; 366 boolean _bfd_coff_long_section_names; 367 unsigned int _bfd_coff_default_section_alignment_power; 368 void (*_bfd_coff_swap_filehdr_in) PARAMS (( 369 bfd *abfd, 370 PTR ext, 371 PTR in)); 372 void (*_bfd_coff_swap_aouthdr_in) PARAMS (( 373 bfd *abfd, 374 PTR ext, 375 PTR in)); 376 void (*_bfd_coff_swap_scnhdr_in) PARAMS (( 377 bfd *abfd, 378 PTR ext, 379 PTR in)); 380 void (*_bfd_coff_swap_reloc_in) PARAMS (( 381 bfd *abfd, 382 PTR ext, 383 PTR in)); 384 boolean (*_bfd_coff_bad_format_hook) PARAMS (( 385 bfd *abfd, 386 PTR internal_filehdr)); 387 boolean (*_bfd_coff_set_arch_mach_hook) PARAMS (( 388 bfd *abfd, 389 PTR internal_filehdr)); 390 PTR (*_bfd_coff_mkobject_hook) PARAMS (( 391 bfd *abfd, 392 PTR internal_filehdr, 393 PTR internal_aouthdr)); 394 flagword (*_bfd_styp_to_sec_flags_hook) PARAMS (( 395 bfd *abfd, 396 PTR internal_scnhdr, 397 const char *name, 398 asection *section)); 399 void (*_bfd_set_alignment_hook) PARAMS (( 400 bfd *abfd, 401 asection *sec, 402 PTR internal_scnhdr)); 403 boolean (*_bfd_coff_slurp_symbol_table) PARAMS (( 404 bfd *abfd)); 405 boolean (*_bfd_coff_symname_in_debug) PARAMS (( 406 bfd *abfd, 407 struct internal_syment *sym)); 408 boolean (*_bfd_coff_pointerize_aux_hook) PARAMS (( 409 bfd *abfd, 410 combined_entry_type *table_base, 411 combined_entry_type *symbol, 412 unsigned int indaux, 413 combined_entry_type *aux)); 414 boolean (*_bfd_coff_print_aux) PARAMS (( 415 bfd *abfd, 416 FILE *file, 417 combined_entry_type *table_base, 418 combined_entry_type *symbol, 419 combined_entry_type *aux, 420 unsigned int indaux)); 421 void (*_bfd_coff_reloc16_extra_cases) PARAMS (( 422 bfd *abfd, 423 struct bfd_link_info *link_info, 424 struct bfd_link_order *link_order, 425 arelent *reloc, 426 bfd_byte *data, 427 unsigned int *src_ptr, 428 unsigned int *dst_ptr)); 429 int (*_bfd_coff_reloc16_estimate) PARAMS (( 430 bfd *abfd, 431 asection *input_section, 432 arelent *r, 433 unsigned int shrink, 434 struct bfd_link_info *link_info)); 435 enum coff_symbol_classification (*_bfd_coff_classify_symbol) PARAMS (( 436 bfd *abfd, 437 struct internal_syment *)); 438 boolean (*_bfd_coff_compute_section_file_positions) PARAMS (( 439 bfd *abfd)); 440 boolean (*_bfd_coff_start_final_link) PARAMS (( 441 bfd *output_bfd, 442 struct bfd_link_info *info)); 443 boolean (*_bfd_coff_relocate_section) PARAMS (( 444 bfd *output_bfd, 445 struct bfd_link_info *info, 446 bfd *input_bfd, 447 asection *input_section, 448 bfd_byte *contents, 449 struct internal_reloc *relocs, 450 struct internal_syment *syms, 451 asection **sections)); 452 reloc_howto_type *(*_bfd_coff_rtype_to_howto) PARAMS (( 453 bfd *abfd, 454 asection *sec, 455 struct internal_reloc *rel, 456 struct coff_link_hash_entry *h, 457 struct internal_syment *sym, 458 bfd_vma *addendp)); 459 boolean (*_bfd_coff_adjust_symndx) PARAMS (( 460 bfd *obfd, 461 struct bfd_link_info *info, 462 bfd *ibfd, 463 asection *sec, 464 struct internal_reloc *reloc, 465 boolean *adjustedp)); 466 boolean (*_bfd_coff_link_add_one_symbol) PARAMS (( 467 struct bfd_link_info *info, 468 bfd *abfd, 469 const char *name, 470 flagword flags, 471 asection *section, 472 bfd_vma value, 473 const char *string, 474 boolean copy, 475 boolean collect, 476 struct bfd_link_hash_entry **hashp)); 477 478 boolean (*_bfd_coff_link_output_has_begun) PARAMS (( 479 bfd * abfd, 480 struct coff_final_link_info * pfinfo)); 481 boolean (*_bfd_coff_final_link_postscript) PARAMS (( 482 bfd * abfd, 483 struct coff_final_link_info * pfinfo)); 484 485@} bfd_coff_backend_data; 486 487#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data) 488 489#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ 490 ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) 491 492#define bfd_coff_swap_sym_in(a,e,i) \ 493 ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i)) 494 495#define bfd_coff_swap_lineno_in(a,e,i) \ 496 ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i)) 497 498#define bfd_coff_swap_reloc_out(abfd, i, o) \ 499 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o)) 500 501#define bfd_coff_swap_lineno_out(abfd, i, o) \ 502 ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o)) 503 504#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \ 505 ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o)) 506 507#define bfd_coff_swap_sym_out(abfd, i,o) \ 508 ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o)) 509 510#define bfd_coff_swap_scnhdr_out(abfd, i,o) \ 511 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o)) 512 513#define bfd_coff_swap_filehdr_out(abfd, i,o) \ 514 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o)) 515 516#define bfd_coff_swap_aouthdr_out(abfd, i,o) \ 517 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o)) 518 519#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz) 520#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz) 521#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz) 522#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz) 523#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz) 524#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz) 525#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz) 526#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen) 527#define bfd_coff_long_filenames(abfd) (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_default_section_alignment_power(abfd) \ 531 (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power) 532#define bfd_coff_swap_filehdr_in(abfd, i,o) \ 533 ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o)) 534 535#define bfd_coff_swap_aouthdr_in(abfd, i,o) \ 536 ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o)) 537 538#define bfd_coff_swap_scnhdr_in(abfd, i,o) \ 539 ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o)) 540 541#define bfd_coff_swap_reloc_in(abfd, i, o) \ 542 ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o)) 543 544#define bfd_coff_bad_format_hook(abfd, filehdr) \ 545 ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr)) 546 547#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\ 548 ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr)) 549#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\ 550 ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr)) 551 552#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section)\ 553 ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\ 554 (abfd, scnhdr, name, section)) 555 556#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\ 557 ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr)) 558 559#define bfd_coff_slurp_symbol_table(abfd)\ 560 ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd)) 561 562#define bfd_coff_symname_in_debug(abfd, sym)\ 563 ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym)) 564 565#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\ 566 ((coff_backend_info (abfd)->_bfd_coff_print_aux)\ 567 (abfd, file, base, symbol, aux, indaux)) 568 569#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\ 570 ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\ 571 (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)) 572 573#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\ 574 ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\ 575 (abfd, section, reloc, shrink, link_info)) 576 577#define bfd_coff_classify_symbol(abfd, sym)\ 578 ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\ 579 (abfd, sym)) 580 581#define bfd_coff_compute_section_file_positions(abfd)\ 582 ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\ 583 (abfd)) 584 585#define bfd_coff_start_final_link(obfd, info)\ 586 ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\ 587 (obfd, info)) 588#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\ 589 ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\ 590 (obfd, info, ibfd, o, con, rel, isyms, secs)) 591#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\ 592 ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\ 593 (abfd, sec, rel, h, sym, addendp)) 594#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\ 595 ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\ 596 (obfd, info, ibfd, sec, rel, adjustedp)) 597#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\ 598 ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\ 599 (info, abfd, name, flags, section, value, string, cp, coll, hashp)) 600 601#define bfd_coff_link_output_has_begun(a,p) \ 602 ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p)) 603#define bfd_coff_final_link_postscript(a,p) \ 604 ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p)) 605 606@end example 607@subsubsection Writing relocations 608To write relocations, the back end steps though the 609canonical relocation table and create an 610@code{internal_reloc}. The symbol index to use is removed from 611the @code{offset} field in the symbol table supplied. The 612address comes directly from the sum of the section base 613address and the relocation offset; the type is dug directly 614from the howto field. Then the @code{internal_reloc} is 615swapped into the shape of an @code{external_reloc} and written 616out to disk. 617 618@subsubsection Reading linenumbers 619Creating the linenumber table is done by reading in the entire 620coff linenumber table, and creating another table for internal use. 621 622A coff linenumber table is structured so that each function 623is marked as having a line number of 0. Each line within the 624function is an offset from the first line in the function. The 625base of the line number information for the table is stored in 626the symbol associated with the function. 627 628Note: The PE format uses line number 0 for a flag indicating a 629new source file. 630 631The information is copied from the external to the internal 632table, and each symbol which marks a function is marked by 633pointing its... 634 635How does this work ? 636 637@subsubsection Reading relocations 638Coff relocations are easily transformed into the internal BFD form 639(@code{arelent}). 640 641Reading a coff relocation table is done in the following stages: 642 643@itemize @bullet 644 645@item 646Read the entire coff relocation table into memory. 647 648@item 649Process each relocation in turn; first swap it from the 650external to the internal form. 651 652@item 653Turn the symbol referenced in the relocation's symbol index 654into a pointer into the canonical symbol table. 655This table is the same as the one returned by a call to 656@code{bfd_canonicalize_symtab}. The back end will call that 657routine and save the result if a canonicalization hasn't been done. 658 659@item 660The reloc index is turned into a pointer to a howto 661structure, in a back end specific way. For instance, the 386 662and 960 use the @code{r_type} to directly produce an index 663into a howto table vector; the 88k subtracts a number from the 664@code{r_type} field and creates an addend field. 665@end itemize 666 667