⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bfdint.texi

📁 这个是LINUX下的GDB调度工具的源码
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@c 2000, 2001, 2002, 2003@c Free Software Foundation, Inc.@setfilename bfdint.info@settitle BFD Internals@iftex@titlepage@title{BFD Internals}@author{Ian Lance Taylor}@author{Cygnus Solutions}@page@end iftex@node Top@top BFD Internals@raisesections@cindex bfd internalsThis document describes some BFD internal information which may behelpful when working on BFD.  It is very incomplete.This document is not updated regularly, and may be out of date.The initial version of this document was written by Ian Lance Taylor@email{ian@@cygnus.com}.@menu* BFD overview::		BFD overview* BFD guidelines::		BFD programming guidelines* BFD target vector::		BFD target vector* BFD generated files::		BFD generated files* BFD multiple compilations::	Files compiled multiple times in BFD* BFD relocation handling::	BFD relocation handling* BFD ELF support::		BFD ELF support* BFD glossary::		Glossary* Index::			Index@end menu@node BFD overview@section BFD overviewBFD is a library which provides a single interface to read and writeobject files, executables, archive files, and core files in any format.@menu* BFD library interfaces::	BFD library interfaces* BFD library users::		BFD library users* BFD view::			The BFD view of a file* BFD blindness::		BFD loses information@end menu@node BFD library interfaces@subsection BFD library interfacesOne way to look at the BFD library is to divide it into four parts bytype of interface.The first interface is the set of generic functions which programs usingthe BFD library will call.  These generic function normally translatedirectly or indirectly into calls to routines which are specific to aparticular object file format.  Many of these generic functions areactually defined as macros in @file{bfd.h}.  These functions comprisethe official BFD interface.The second interface is the set of functions which appear in the targetvectors.  This is the bulk of the code in BFD.  A target vector is a setof function pointers specific to a particular object file format.  Thetarget vector is used to implement the generic BFD functions.  Thesefunctions are always called through the target vector, and are nevercalled directly.  The target vector is described in detail in @ref{BFDtarget vector}.  The set of functions which appear in a particulartarget vector is often referred to as a BFD backend.The third interface is a set of oddball functions which are typicallyspecific to a particular object file format, are not generic functions,and are called from outside of the BFD library.  These are used as hooksby the linker and the assembler when a particular object file formatrequires some action which the BFD generic interface does not provide.These functions are typically declared in @file{bfd.h}, but in manycases they are only provided when BFD is configured with support for aparticular object file format.  These functions live in a grey area, andare not really part of the official BFD interface.The fourth interface is the set of BFD support functions which arecalled by the other BFD functions.  These manage issues like memoryallocation, error handling, file access, hash tables, swapping, and thelike.  These functions are never called from outside of the BFD library.@node BFD library users@subsection BFD library usersAnother way to look at the BFD library is to divide it into three partsby the manner in which it is used.The first use is to read an object file.  The object file readers areprograms like @samp{gdb}, @samp{nm}, @samp{objdump}, and @samp{objcopy}.These programs use BFD to view an object file in a generic form.  Theofficial BFD interface is normally fully adequate for these programs.The second use is to write an object file.  The object file writers areprograms like @samp{gas} and @samp{objcopy}.  These programs use BFD tocreate an object file.  The official BFD interface is normally adequatefor these programs, but for some object file formats the assembler needssome additional hooks in order to set particular flags or otherinformation.  The official BFD interface includes functions to copyprivate information from one object file to another, and these functionsare used by @samp{objcopy} to avoid information loss.The third use is to link object files.  There is only one object filelinker, @samp{ld}.  Originally, @samp{ld} was an object file reader andan object file writer, and it did the link operation using the genericBFD structures.  However, this turned out to be too slow and too memoryintensive.The official BFD linker functions were written to permit specific BFDbackends to perform the link without translating through the genericstructures, in the normal case where all the input files and output filehave the same object file format.  Not all of the backends currentlyimplement the new interface, and there are default linking functionswithin BFD which use the generic structures and which work with allbackends.For several object file formats the linker needs additional hooks whichare not provided by the official BFD interface, particularly for dynamiclinking support.  These functions are typically called from the linkeremulation template.@node BFD view@subsection The BFD view of a fileBFD uses generic structures to manage information.  It translates datainto the generic form when reading files, and out of the generic formwhen writing files.BFD describes a file as a pointer to the @samp{bfd} type.  A @samp{bfd}is composed of the following elements.  The BFD information can bedisplayed using the @samp{objdump} program with various options.@table @asis@item general informationThe object file format, a few general flags, the start address.@item architectureThe architecture, including both a general processor type (m68k, MIPSetc.) and a specific machine number (m68000, R4000, etc.).@item sectionsA list of sections.@item symbolsA symbol table.@end tableBFD represents a section as a pointer to the @samp{asection} type.  Eachsection has a name and a size.  Most sections also have an associatedblock of data, known as the section contents.  Sections also haveassociated flags, a virtual memory address, a load memory address, arequired alignment, a list of relocations, and other miscellaneousinformation.BFD represents a relocation as a pointer to the @samp{arelent} type.  Arelocation describes an action which the linker must take to modify thesection contents.  Relocations have a symbol, an address, an addend, anda pointer to a howto structure which describes how to perform therelocation.  For more information, see @ref{BFD relocation handling}.BFD represents a symbol as a pointer to the @samp{asymbol} type.  Asymbol has a name, a pointer to a section, an offset within thatsection, and some flags.Archive files do not have any sections or symbols.  Instead, BFDrepresents an archive file as a file which contains a list of@samp{bfd}s.  BFD also provides access to the archive symbol map, as alist of symbol names.  BFD provides a function to return the @samp{bfd}within the archive which corresponds to a particular entry in thearchive symbol map.@node BFD blindness@subsection BFD loses informationMost object file formats have information which BFD can not represent inits generic form, at least as currently defined.There is often explicit information which BFD can not represent.  Forexample, the COFF version stamp, or the ELF program segments.  BFDprovides special hooks to handle this information when copying,printing, or linking an object file.  The BFD support for a particularobject file format will normally store this information in private dataand handle it using the special hooks.In some cases there is also implicit information which BFD can notrepresent.  For example, the MIPS processor distinguishes small andlarge symbols, and requires that all small symbls be within 32K of theGP register.  This means that the MIPS assembler must be able to markvariables as either small or large, and the MIPS linker must know to putsmall symbols within range of the GP register.  Since BFD can notrepresent this information, this means that the assembler and linkermust have information that is specific to a particular object fileformat which is outside of the BFD library.This loss of information indicates areas where the BFD paradigm breaksdown.  It is not actually possible to represent the myriad differencesamong object file formats using a single generic interface, at least notin the manner which BFD does it today.Nevertheless, the BFD library does greatly simplify the task of dealingwith object files, and particular problems caused by information losscan normally be solved using some sort of relatively constrained hookinto the library.@node BFD guidelines@section BFD programming guidelines@cindex bfd programming guidelines@cindex programming guidelines for bfd@cindex guidelines, bfd programmingThere is a lot of poorly written and confusing code in BFD.  New BFDcode should be written to a higher standard.  Merely because some BFDcode is written in a particular manner does not mean that you shouldemulate it.Here are some general BFD programming guidelines:@itemize @bullet@itemFollow the GNU coding standards.@itemAvoid global variables.  We ideally want BFD to be fully reentrant, sothat it can be used in multiple threads.  All uses of global or staticvariables interfere with that.  Initialized constant variables are OK,and they should be explicitly marked with const.  Instead of globalvariables, use data attached to a BFD or to a linker hash table.@itemAll externally visible functions should have names which start with@samp{bfd_}.  All such functions should be declared in some header file,typically @file{bfd.h}.  See, for example, the various declarations nearthe end of @file{bfd-in.h}, which mostly declare functions required byspecific linker emulations.@itemAll functions which need to be visible from one file to another withinBFD, but should not be visible outside of BFD, should start with@samp{_bfd_}.  Although external names beginning with @samp{_} areprohibited by the ANSI standard, in practice this usage will alwayswork, and it is required by the GNU coding standards.@itemAlways remember that people can compile using @samp{--enable-targets} tobuild several, or all, targets at once.  It must be possible to linktogether the files for all targets.@itemBFD code should compile with few or no warnings using @samp{gcc -Wall}.Some warnings are OK, like the absence of certain function declarationswhich may or may not be declared in system header files.  Warnings aboutambiguous expressions and the like should always be fixed.@end itemize@node BFD target vector@section BFD target vector@cindex bfd target vector@cindex target vector in bfdBFD supports multiple object file formats by using the @dfn{targetvector}.  This is simply a set of function pointers which implementbehaviour that is specific to a particular object file format.In this section I list all of the entries in the target vector anddescribe what they do.@menu* BFD target vector miscellaneous::	Miscellaneous constants* BFD target vector swap::		Swapping functions* BFD target vector format::		Format type dependent functions* BFD_JUMP_TABLE macros::		BFD_JUMP_TABLE macros* BFD target vector generic::		Generic functions* BFD target vector copy::		Copy functions* BFD target vector core::		Core file support functions* BFD target vector archive::		Archive functions* BFD target vector symbols::		Symbol table functions* BFD target vector relocs::		Relocation support* BFD target vector write::		Output functions* BFD target vector link::		Linker functions* BFD target vector dynamic::		Dynamic linking information functions@end menu@node BFD target vector miscellaneous@subsection Miscellaneous constantsThe target vector starts with a set of constants.@table @samp@item nameThe name of the target vector.  This is an arbitrary string.  This ishow the target vector is named in command line options for tools whichuse BFD, such as the @samp{--oformat} linker option.@item flavourA general description of the type of target.  The following flavours arecurrently defined:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -