1*3d8817e4Smiod@c This summary of BFD is shared by the BFD and LD docs. 2*3d8817e4SmiodWhen an object file is opened, BFD subroutines automatically determine 3*3d8817e4Smiodthe format of the input object file. They then build a descriptor in 4*3d8817e4Smiodmemory with pointers to routines that will be used to access elements of 5*3d8817e4Smiodthe object file's data structures. 6*3d8817e4Smiod 7*3d8817e4SmiodAs different information from the object files is required, 8*3d8817e4SmiodBFD reads from different sections of the file and processes them. 9*3d8817e4SmiodFor example, a very common operation for the linker is processing symbol 10*3d8817e4Smiodtables. Each BFD back end provides a routine for converting 11*3d8817e4Smiodbetween the object file's representation of symbols and an internal 12*3d8817e4Smiodcanonical format. When the linker asks for the symbol table of an object 13*3d8817e4Smiodfile, it calls through a memory pointer to the routine from the 14*3d8817e4Smiodrelevant BFD back end which reads and converts the table into a canonical 15*3d8817e4Smiodform. The linker then operates upon the canonical form. When the link is 16*3d8817e4Smiodfinished and the linker writes the output file's symbol table, 17*3d8817e4Smiodanother BFD back end routine is called to take the newly 18*3d8817e4Smiodcreated symbol table and convert it into the chosen output format. 19*3d8817e4Smiod 20*3d8817e4Smiod@menu 21*3d8817e4Smiod* BFD information loss:: Information Loss 22*3d8817e4Smiod* Canonical format:: The BFD canonical object-file format 23*3d8817e4Smiod@end menu 24*3d8817e4Smiod 25*3d8817e4Smiod@node BFD information loss 26*3d8817e4Smiod@subsection Information Loss 27*3d8817e4Smiod 28*3d8817e4Smiod@emph{Information can be lost during output.} The output formats 29*3d8817e4Smiodsupported by BFD do not provide identical facilities, and 30*3d8817e4Smiodinformation which can be described in one form has nowhere to go in 31*3d8817e4Smiodanother format. One example of this is alignment information in 32*3d8817e4Smiod@code{b.out}. There is nowhere in an @code{a.out} format file to store 33*3d8817e4Smiodalignment information on the contained data, so when a file is linked 34*3d8817e4Smiodfrom @code{b.out} and an @code{a.out} image is produced, alignment 35*3d8817e4Smiodinformation will not propagate to the output file. (The linker will 36*3d8817e4Smiodstill use the alignment information internally, so the link is performed 37*3d8817e4Smiodcorrectly). 38*3d8817e4Smiod 39*3d8817e4SmiodAnother example is COFF section names. COFF files may contain an 40*3d8817e4Smiodunlimited number of sections, each one with a textual section name. If 41*3d8817e4Smiodthe target of the link is a format which does not have many sections (e.g., 42*3d8817e4Smiod@code{a.out}) or has sections without names (e.g., the Oasys format), the 43*3d8817e4Smiodlink cannot be done simply. You can circumvent this problem by 44*3d8817e4Smioddescribing the desired input-to-output section mapping with the linker command 45*3d8817e4Smiodlanguage. 46*3d8817e4Smiod 47*3d8817e4Smiod@emph{Information can be lost during canonicalization.} The BFD 48*3d8817e4Smiodinternal canonical form of the external formats is not exhaustive; there 49*3d8817e4Smiodare structures in input formats for which there is no direct 50*3d8817e4Smiodrepresentation internally. This means that the BFD back ends 51*3d8817e4Smiodcannot maintain all possible data richness through the transformation 52*3d8817e4Smiodbetween external to internal and back to external formats. 53*3d8817e4Smiod 54*3d8817e4SmiodThis limitation is only a problem when an application reads one 55*3d8817e4Smiodformat and writes another. Each BFD back end is responsible for 56*3d8817e4Smiodmaintaining as much data as possible, and the internal BFD 57*3d8817e4Smiodcanonical form has structures which are opaque to the BFD core, 58*3d8817e4Smiodand exported only to the back ends. When a file is read in one format, 59*3d8817e4Smiodthe canonical form is generated for BFD and the application. At the 60*3d8817e4Smiodsame time, the back end saves away any information which may otherwise 61*3d8817e4Smiodbe lost. If the data is then written back in the same format, the back 62*3d8817e4Smiodend routine will be able to use the canonical form provided by the 63*3d8817e4SmiodBFD core as well as the information it prepared earlier. Since 64*3d8817e4Smiodthere is a great deal of commonality between back ends, 65*3d8817e4Smiodthere is no information lost when 66*3d8817e4Smiodlinking or copying big endian COFF to little endian COFF, or @code{a.out} to 67*3d8817e4Smiod@code{b.out}. When a mixture of formats is linked, the information is 68*3d8817e4Smiodonly lost from the files whose format differs from the destination. 69*3d8817e4Smiod 70*3d8817e4Smiod@node Canonical format 71*3d8817e4Smiod@subsection The BFD canonical object-file format 72*3d8817e4Smiod 73*3d8817e4SmiodThe greatest potential for loss of information occurs when there is the least 74*3d8817e4Smiodoverlap between the information provided by the source format, that 75*3d8817e4Smiodstored by the canonical format, and that needed by the 76*3d8817e4Smioddestination format. A brief description of the canonical form may help 77*3d8817e4Smiodyou understand which kinds of data you can count on preserving across 78*3d8817e4Smiodconversions. 79*3d8817e4Smiod@cindex BFD canonical format 80*3d8817e4Smiod@cindex internal object-file format 81*3d8817e4Smiod 82*3d8817e4Smiod@table @emph 83*3d8817e4Smiod@item files 84*3d8817e4SmiodInformation stored on a per-file basis includes target machine 85*3d8817e4Smiodarchitecture, particular implementation format type, a demand pageable 86*3d8817e4Smiodbit, and a write protected bit. Information like Unix magic numbers is 87*3d8817e4Smiodnot stored here---only the magic numbers' meaning, so a @code{ZMAGIC} 88*3d8817e4Smiodfile would have both the demand pageable bit and the write protected 89*3d8817e4Smiodtext bit set. The byte order of the target is stored on a per-file 90*3d8817e4Smiodbasis, so that big- and little-endian object files may be used with one 91*3d8817e4Smiodanother. 92*3d8817e4Smiod 93*3d8817e4Smiod@item sections 94*3d8817e4SmiodEach section in the input file contains the name of the section, the 95*3d8817e4Smiodsection's original address in the object file, size and alignment 96*3d8817e4Smiodinformation, various flags, and pointers into other BFD data 97*3d8817e4Smiodstructures. 98*3d8817e4Smiod 99*3d8817e4Smiod@item symbols 100*3d8817e4SmiodEach symbol contains a pointer to the information for the object file 101*3d8817e4Smiodwhich originally defined it, its name, its value, and various flag 102*3d8817e4Smiodbits. When a BFD back end reads in a symbol table, it relocates all 103*3d8817e4Smiodsymbols to make them relative to the base of the section where they were 104*3d8817e4Smioddefined. Doing this ensures that each symbol points to its containing 105*3d8817e4Smiodsection. Each symbol also has a varying amount of hidden private data 106*3d8817e4Smiodfor the BFD back end. Since the symbol points to the original file, the 107*3d8817e4Smiodprivate data format for that symbol is accessible. @code{ld} can 108*3d8817e4Smiodoperate on a collection of symbols of wildly different formats without 109*3d8817e4Smiodproblems. 110*3d8817e4Smiod 111*3d8817e4SmiodNormal global and simple local symbols are maintained on output, so an 112*3d8817e4Smiodoutput file (no matter its format) will retain symbols pointing to 113*3d8817e4Smiodfunctions and to global, static, and common variables. Some symbol 114*3d8817e4Smiodinformation is not worth retaining; in @code{a.out}, type information is 115*3d8817e4Smiodstored in the symbol table as long symbol names. This information would 116*3d8817e4Smiodbe useless to most COFF debuggers; the linker has command line switches 117*3d8817e4Smiodto allow users to throw it away. 118*3d8817e4Smiod 119*3d8817e4SmiodThere is one word of type information within the symbol, so if the 120*3d8817e4Smiodformat supports symbol type information within symbols (for example, COFF, 121*3d8817e4SmiodIEEE, Oasys) and the type is simple enough to fit within one word 122*3d8817e4Smiod(nearly everything but aggregates), the information will be preserved. 123*3d8817e4Smiod 124*3d8817e4Smiod@item relocation level 125*3d8817e4SmiodEach canonical BFD relocation record contains a pointer to the symbol to 126*3d8817e4Smiodrelocate to, the offset of the data to relocate, the section the data 127*3d8817e4Smiodis in, and a pointer to a relocation type descriptor. Relocation is 128*3d8817e4Smiodperformed by passing messages through the relocation type 129*3d8817e4Smioddescriptor and the symbol pointer. Therefore, relocations can be performed 130*3d8817e4Smiodon output data using a relocation method that is only available in one of the 131*3d8817e4Smiodinput formats. For instance, Oasys provides a byte relocation format. 132*3d8817e4SmiodA relocation record requesting this relocation type would point 133*3d8817e4Smiodindirectly to a routine to perform this, so the relocation may be 134*3d8817e4Smiodperformed on a byte being written to a 68k COFF file, even though 68k COFF 135*3d8817e4Smiodhas no such relocation type. 136*3d8817e4Smiod 137*3d8817e4Smiod@item line numbers 138*3d8817e4SmiodObject formats can contain, for debugging purposes, some form of mapping 139*3d8817e4Smiodbetween symbols, source line numbers, and addresses in the output file. 140*3d8817e4SmiodThese addresses have to be relocated along with the symbol information. 141*3d8817e4SmiodEach symbol with an associated list of line number records points to the 142*3d8817e4Smiodfirst record of the list. The head of a line number list consists of a 143*3d8817e4Smiodpointer to the symbol, which allows finding out the address of the 144*3d8817e4Smiodfunction whose line number is being described. The rest of the list is 145*3d8817e4Smiodmade up of pairs: offsets into the section and line numbers. Any format 146*3d8817e4Smiodwhich can simply derive this information can pass it successfully 147*3d8817e4Smiodbetween formats (COFF, IEEE and Oasys). 148*3d8817e4Smiod@end table 149