📄 bfdint.texi
字号:
describes them. Some files are created at configure time, when youconfigure BFD. Some files are created at make time, when you buildBFD. Some files are automatically rebuilt at make time, but only ifyou configure with the @samp{--enable-maintainer-mode} option. Somefiles live in the object directory---the directory from which you runconfigure---and some live in the source directory. All files that livein the source directory are checked into the CVS repository.@table @file@item bfd.h@cindex @file{bfd.h}@cindex @file{bfd-in3.h}Lives in the object directory. Created at make time from@file{bfd-in2.h} via @file{bfd-in3.h}. @file{bfd-in3.h} is created atconfigure time from @file{bfd-in2.h}. There are automatic dependenciesto rebuild @file{bfd-in3.h} and hence @file{bfd.h} if @file{bfd-in2.h}changes, so you can normally ignore @file{bfd-in3.h}, and just thinkabout @file{bfd-in2.h} and @file{bfd.h}.@file{bfd.h} is built by replacing a few strings in @file{bfd-in2.h}.To see them, search for @samp{@@} in @file{bfd-in2.h}. They mainlycontrol whether BFD is built for a 32 bit target or a 64 bit target.@item bfd-in2.h@cindex @file{bfd-in2.h}Lives in the source directory. Created from @file{bfd-in.h} and severalother BFD source files. If you configure with the@samp{--enable-maintainer-mode} option, @file{bfd-in2.h} is rebuiltautomatically when a source file changes.@item elf32-target.h@itemx elf64-target.h@cindex @file{elf32-target.h}@cindex @file{elf64-target.h}Live in the object directory. Created from @file{elfxx-target.h}.These files are versions of @file{elfxx-target.h} customized for eithera 32 bit ELF target or a 64 bit ELF target.@item libbfd.h@cindex @file{libbfd.h}Lives in the source directory. Created from @file{libbfd-in.h} andseveral other BFD source files. If you configure with the@samp{--enable-maintainer-mode} option, @file{libbfd.h} is rebuiltautomatically when a source file changes.@item libcoff.h@cindex @file{libcoff.h}Lives in the source directory. Created from @file{libcoff-in.h} and@file{coffcode.h}. If you configure with the@samp{--enable-maintainer-mode} option, @file{libcoff.h} is rebuiltautomatically when a source file changes.@item targmatch.h@cindex @file{targmatch.h}Lives in the object directory. Created at make time from@file{config.bfd}. This file is used to map configuration triplets intoBFD target vector variable names at run time.@end table@node BFD multiple compilations@section Files compiled multiple times in BFDSeveral files in BFD are compiled multiple times. By this I mean thatthere are header files which contain function definitions. These headerfiles are included by other files, and thus the functions are compiledonce per file which includes them.Preprocessor macros are used to control the compilation, so that eachtime the files are compiled the resulting functions are slightlydifferent. Naturally, if they weren't different, there would be noreason to compile them multiple times.This is a not a particularly good programming technique, and future BFDwork should avoid it.@itemize @bullet@itemSince this technique is rarely used, even experienced C programmers findit confusing.@itemIt is difficult to debug programs which use BFD, since there is no wayto describe which version of a particular function you are looking at.@itemPrograms which use BFD wind up incorporating two or more slightlydifferent versions of the same function, which wastes space in theexecutable.@itemThis technique is never required nor is it especially efficient. It isalways possible to use statically initialized structures holdingfunction pointers and magic constants instead.@end itemizeThe following is a list of the files which are compiled multiple times.@table @file@item aout-target.h@cindex @file{aout-target.h}Describes a few functions and the target vector for a.out targets. Thisis used by individual a.out targets with different definitions of@samp{N_TXTADDR} and similar a.out macros.@item aoutf1.h@cindex @file{aoutf1.h}Implements standard SunOS a.out files. In principle it supports 64 bita.out targets based on the preprocessor macro @samp{ARCH_SIZE}, butsince all known a.out targets are 32 bits, this code may or may notwork. This file is only included by a few other files, and it isdifficult to justify its existence.@item aoutx.h@cindex @file{aoutx.h}Implements basic a.out support routines. This file can be compiled foreither 32 or 64 bit support. Since all known a.out targets are 32 bits,the 64 bit support may or may not work. I believe the originalintention was that this file would only be included by @samp{aout32.c}and @samp{aout64.c}, and that other a.out targets would simply refer tothe functions it defined. Unfortunately, some other a.out targetsstarted including it directly, leading to a somewhat confused state ofaffairs.@item coffcode.h@cindex @file{coffcode.h}Implements basic COFF support routines. This file is included by everyCOFF target. It implements code which handles COFF magic numbers aswell as various hook functions called by the generic COFF functions in@file{coffgen.c}. This file is controlled by a number of differentmacros, and more are added regularly.@item coffswap.h@cindex @file{coffswap.h}Implements COFF swapping routines. This file is included by@file{coffcode.h}, and thus by every COFF target. It implements theroutines which swap COFF structures between internal and externalformat. The main control for this file is the external structuredefinitions in the files in the @file{include/coff} directory. A COFFtarget file will include one of those files before including@file{coffcode.h} and thus @file{coffswap.h}. There are a few othermacros which affect @file{coffswap.h} as well, mostly describing whethercertain fields are present in the external structures.@item ecoffswap.h@cindex @file{ecoffswap.h}Implements ECOFF swapping routines. This is like @file{coffswap.h}, butfor ECOFF. It is included by the ECOFF target files (of which there areonly two). The control is the preprocessor macro @samp{ECOFF_32} or@samp{ECOFF_64}.@item elfcode.h@cindex @file{elfcode.h}Implements ELF functions that use external structure definitions. Thisfile is included by two other files: @file{elf32.c} and @file{elf64.c}.It is controlled by the @samp{ARCH_SIZE} macro which is defined to be@samp{32} or @samp{64} before including it. The @samp{NAME} macro isused internally to give the functions different names for the two targetsizes.@item elfcore.h@cindex @file{elfcore.h}Like @file{elfcode.h}, but for functions that are specific to ELF corefiles. This is included only by @file{elfcode.h}.@item elfxx-target.h@cindex @file{elfxx-target.h}This file is the source for the generated files @file{elf32-target.h}and @file{elf64-target.h}, one of which is included by every ELF target.It defines the ELF target vector.@item freebsd.h@cindex @file{freebsd.h}Presumably intended to be included by all FreeBSD targets, but in factthere is only one such target, @samp{i386-freebsd}. This defines afunction used to set the right magic number for FreeBSD, as well asvarious macros, and includes @file{aout-target.h}.@item netbsd.h@cindex @file{netbsd.h}Like @file{freebsd.h}, except that there are several files which includeit.@item nlm-target.h@cindex @file{nlm-target.h}Defines the target vector for a standard NLM target.@item nlmcode.h@cindex @file{nlmcode.h}Like @file{elfcode.h}, but for NLM targets. This is only included by@file{nlm32.c} and @file{nlm64.c}, both of which define the macro@samp{ARCH_SIZE} to an appropriate value. There are no 64 bit NLMtargets anyhow, so this is sort of useless.@item nlmswap.h@cindex @file{nlmswap.h}Like @file{coffswap.h}, but for NLM targets. This is included by eachNLM target, but I think it winds up compiling to the exact same code forevery target, and as such is fairly useless.@item peicode.h@cindex @file{peicode.h}Provides swapping routines and other hooks for PE targets.@file{coffcode.h} will include this rather than @file{coffswap.h} for aPE target. This defines PE specific versions of the COFF swappingroutines, and also defines some macros which control @file{coffcode.h}itself.@end table@node BFD relocation handling@section BFD relocation handling@cindex bfd relocation handling@cindex relocations in bfdThe handling of relocations is one of the more confusing aspects of BFD.Relocation handling has been implemented in various different ways, allsomewhat incompatible, none perfect.@menu* BFD relocation concepts:: BFD relocation concepts* BFD relocation functions:: BFD relocation functions* BFD relocation codes:: BFD relocation codes* BFD relocation future:: BFD relocation future@end menu@node BFD relocation concepts@subsection BFD relocation conceptsA relocation is an action which the linker must take when linking. Itdescribes a change to the contents of a section. The change is normallybased on the final value of one or more symbols. Relocations arecreated by the assembler when it creates an object file.Most relocations are simple. A typical simple relocation is to set 32bits at a given offset in a section to the value of a symbol. This typeof relocation would be generated for code like @code{int *p = &i;} where@samp{p} and @samp{i} are global variables. A relocation for the symbol@samp{i} would be generated such that the linker would initialize thearea of memory which holds the value of @samp{p} to the value of thesymbol @samp{i}.Slightly more complex relocations may include an addend, which is aconstant to add to the symbol value before using it. In some cases arelocation will require adding the symbol value to the existing contentsof the section in the object file. In others the relocation will simplyreplace the contents of the section with the symbol value. Somerelocations are PC relative, so that the value to be stored in thesection is the difference between the value of a symbol and the finaladdress of the section contents.In general, relocations can be arbitrarily complex. For example,relocations used in dynamic linking systems often require the linker toallocate space in a different section and use the offset within thatsection as the value to store. In the IEEE object file format,relocations may involve arbitrary expressions.When doing a relocatable link, the linker may or may not have to doanything with a relocation, depending upon the definition of therelocation. Simple relocations generally do not require any specialaction.@node BFD relocation functions@subsection BFD relocation functionsIn BFD, each section has an array of @samp{arelent} structures. Eachstructure has a pointer to a symbol, an address within the section, anaddend, and a pointer to a @samp{reloc_howto_struct} structure. Thehowto structure has a bunch of fields describing the reloc, including atype field. The type field is specific to the object file formatbackend; none of the generic code in BFD examines it.Originally, the function @samp{bfd_perform_relocation} was supposed tohandle all relocations. In theory, many relocations would be simpleenough to be described by the fields in the howto structure. For thosethat weren't, the howto structure included a @samp{special_function}field to use as an escape.While this seems plausible, a look at @samp{bfd_perform_relocation}shows that it failed. The function has odd special cases. Some of thefields in the howto structure, such as @samp{pcrel_offset}, were notadequately documented.The linker uses @samp{bfd_perform_relocation} to do all relocations whenthe input and output file have different formats (e.g., when generatingS-records). The generic linker code, which is used by all targets whichdo not define their own special purpose linker, uses@samp{bfd_get_relocated_section_contents}, which for most targets turnsinto a call to @samp{bfd_generic_get_relocated_section_contents}, whichcalls @samp{bfd_perform_relocation}. So @samp{bfd_perform_relocation}is still widely used, which makes it difficult to change, since it isdifficult to test all possible cases.The assembler used @samp{bfd_perform_relocation} for a while. Thisturned out to be the wrong thing to do, since@samp{bfd_perform_relocation} was written to handle relocations on anexisting object file, while the assembler needed to create relocationsin a new object file. The assembler was changed to use the new function@samp{bfd_install_relocation} instead, and @samp{bfd_install_relocation}was created as a copy of @samp{bfd_perform_relocation}.Unfortunately, the work did not progress any farther, so@samp{bfd_install_relocation} remains a simple copy of@samp{bfd_perform_relocation}, with all the odd special cases andconfusing code. This again is difficult to change, because again anychange can affect any assembler target, and so is difficult to test.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -