]>
Commit | Line | Data |
---|---|---|
2013f9b4 SC |
1 | \input cyginfo |
2 | @c\input texinfo | |
3 | @setfilename bfdinfo | |
4 | @c $Id$ | |
5 | @synindex ky cp | |
6 | @ifinfo | |
7 | This file documents the BFD library. | |
8 | ||
9 | Copyright (C) 1991 Cygnus Support. | |
10 | ||
11 | Permission is granted to make and distribute verbatim copies of | |
12 | this manual provided the copyright notice and this permission notice | |
13 | are preserved on all copies. | |
14 | ||
15 | @ignore | |
16 | Permission is granted to process this file through Tex and print the | |
17 | results, provided the printed document carries copying permission | |
18 | notice identical to this one except for the removal of this paragraph | |
19 | (this paragraph not being relevant to the printed manual). | |
20 | ||
21 | @end ignore | |
22 | Permission is granted to copy and distribute modified versions of this | |
23 | manual under the conditions for verbatim copying, provided also that the | |
24 | section entitled ``GNU General Public License'' is included exactly as | |
25 | in the original, and provided that the entire resulting derived work is | |
26 | distributed under the terms of a permission notice identical to this | |
27 | one. | |
28 | ||
29 | Permission is granted to copy and distribute translations of this manual | |
30 | into another language, under the above conditions for modified versions, | |
31 | except that the section entitled ``GNU General Public License'' may be | |
32 | included in a translation approved by the author instead of in the | |
33 | original English. | |
34 | @end ifinfo | |
35 | @iftex | |
36 | @c this removes the gaps around @examples | |
37 | ||
38 | @c@finalout | |
39 | @c@setchapternewpage odd | |
990778ee | 40 | @settitle LIB BFD, the Binary File Descriptor Library |
2013f9b4 SC |
41 | @titlepage |
42 | @title{libbfd} | |
990778ee | 43 | @subtitle{The Binary File Descriptor Library} |
2013f9b4 SC |
44 | @sp 1 |
45 | @subtitle First Edition---@code{bfd} version < 2.0 | |
46 | @subtitle April 1991 | |
47 | @author {Steve Chamberlain} | |
48 | @author {Cygnus Support} | |
49 | @page | |
50 | ||
51 | @tex | |
52 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
53 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
54 | {\parskip=0pt | |
55 | \hfill Cygnus Support\par | |
56 | \hfill steve\@cygnus.com\par | |
57 | \hfill {\it BFD}, \manvers\par | |
58 | \hfill \TeX{}info \texinfoversion\par | |
59 | } | |
60 | \global\parindent=0pt % Steve likes it this way | |
61 | @end tex | |
62 | ||
63 | @vskip 0pt plus 1filll | |
64 | Copyright @copyright{} 1991 Cygnus Support. | |
65 | ||
66 | Permission is granted to make and distribute verbatim copies of | |
67 | this manual provided the copyright notice and this permission notice | |
68 | are preserved on all copies. | |
69 | ||
70 | Permission is granted to copy and distribute modified versions of this | |
71 | manual under the conditions for verbatim copying, provided also that | |
72 | the entire resulting derived work is distributed under the terms of a | |
73 | permission notice identical to this one. | |
74 | ||
75 | Permission is granted to copy and distribute translations of this manual | |
76 | into another language, under the above conditions for modified versions. | |
77 | @end titlepage | |
78 | @end iftex | |
79 | @c FIXME: Talk about importance of *order* of args, cmds to linker! | |
80 | ||
81 | @node Top, Overview, (dir), (dir) | |
82 | @ifinfo | |
83 | This file documents the binary file descriptor library libbfd. | |
84 | @end ifinfo | |
85 | ||
86 | @menu | |
87 | * Overview:: Overview of bfd | |
88 | * History:: History of bfd | |
89 | * Backends:: Backends | |
90 | * Porting:: Porting | |
91 | * Future:: Future | |
92 | * Index:: Index | |
93 | ||
94 | BFD body: | |
95 | * Sections:: | |
96 | * Symbols:: | |
97 | * Archives:: | |
98 | * Formats:: | |
99 | * Relocations:: | |
100 | * Core Files:: | |
101 | * Targets:: | |
102 | * Architecturs:: | |
103 | * Opening and Closing:: | |
104 | * Internal:: | |
105 | * File Caching:: | |
106 | ||
107 | Bfd backends: | |
108 | * a.out backends:: | |
109 | * coff backends:: | |
110 | @end menu | |
111 | ||
112 | @node Overview, History, Top, Top | |
113 | @chapter Introduction | |
114 | @cindex BFD | |
115 | @cindex what is it? | |
116 | Simply put, @code{bfd} is a package which allow applications to use the | |
117 | same routines to operate on object files whatever the object file | |
118 | format. A different object file format can be supported simply by | |
119 | creating a new BFD back end and adding it to the library. | |
120 | ||
121 | BFD is split into two parts; the front end and the many back ends. | |
122 | @itemize @bullet | |
123 | @item The front end of bfd provides the interface to the user. It manages | |
124 | memory, and various canonical data structures. The front end also | |
125 | decides which back end to use, and when to call back end routines. | |
126 | @item The back ends provide bfd its view of the real world. Each back | |
127 | end provides a set of calls which the bfd front end can use to maintain | |
128 | its canonical form. The back ends also may keep around information for | |
129 | their own use, for greater efficiency. | |
130 | @end itemize | |
131 | @node History, How It Works, Overview,Top | |
132 | @section History | |
133 | ||
2013f9b4 SC |
134 | One spur behind @code{bfd} was the Intel Oregon's GNU 960 team desire for |
135 | interoperability of applications on their COFF and b.out file formats. | |
136 | Cygnus was providing GNU support for the team, and Cygnus were | |
137 | contracted to provid the required functionality. | |
138 | ||
139 | The name came from a conversation Gumby Wallace was | |
140 | having with Richard Stallman about the library, RMS said that it | |
141 | would be quite hard, Gumby said BFD. (Stallman was right, but the name | |
142 | stuck). | |
143 | ||
144 | At the same time, Ready Systems wanted much the same thing, but for | |
145 | different object file formats, IEEE-695, Oasys, Srecords, a.out and 68k coff. | |
146 | ||
147 | BFD was first implemented by Steve Chamberlain (steve@@cygnus.com), | |
148 | John Gilmore (gnu@@cygnus.com), K. Richard Pixley (rich@@cygnus.com) and | |
990778ee JG |
149 | Gumby Wallace (gumby@@cygnus.com) at Cygnus Support in Palo Alto, |
150 | California. | |
2013f9b4 SC |
151 | |
152 | @node How It Works, History, Porting, Top | |
153 | @section How It Works | |
154 | @code{bfd} provides a common interface to the parts of an object file | |
155 | to a calling application. | |
156 | ||
157 | When an application sucessfully opens a | |
158 | target file (object, archive or whatever) a pointer to an internal | |
159 | structure is returned. This pointer points to structure described in | |
160 | @code{include/bfd.h}, called @code{bfd}. Conventionally this pointer is | |
161 | called a @code{bfd}, and instances of it within code are called | |
162 | @code{abfd}. All operations on the target object file are applied as | |
163 | methods to the @code{bfd}, the mapping is defined within @code{bfd.h} in | |
164 | a set of macros, all beginning @code{bfd}_something. | |
165 | ||
166 | For example, this sequence would do what you expect: | |
167 | @tex | |
168 | \globaldefs=1 | |
169 | \def\example{\begingroup\inENV %This group ends at the end of the @lisp body | |
170 | \hfuzz=12truept % Don't be fussy | |
171 | % Make spaces be word-separators rather than space tokens. | |
172 | \sepspaces % | |
173 | % Single space lines | |
174 | \singlespace % | |
175 | % The following causes blank lines not to be ignored | |
176 | % by adding a space to the end of each line. | |
177 | \let\par=\lisppar | |
178 | \def\Eexample{\endgroup}% | |
179 | \parskip=0pt | |
180 | \advance \leftskip by \lispnarrowing | |
181 | \parindent=0pt | |
182 | \let\exdent=\internalexdent | |
183 | \obeyspaces \obeylines \tt \rawbackslash | |
184 | \def\next##1{}\next} | |
185 | \globaldefs=0 | |
186 | @end tex | |
187 | ||
188 | @lisp | |
189 | @w{ | |
190 | #include "bfd.h" | |
191 | ||
192 | unsigned int number_of_sections(abfd) | |
193 | bfd *abfd; | |
194 | @{ | |
195 | return bfd_count_sections(abfd); | |
196 | @} | |
197 | } | |
198 | @end lisp | |
199 | ||
200 | The metaphor used within @code{bfd} is that an object file has a header, | |
201 | a numbber of sections containing raw data, a set of relocations and some | |
202 | symbol information. Also, @code{bfd}s opened upon archives have the | |
203 | additional attribute of an index and contained sub bfds. This approach is | |
204 | find for a.out and coff, but looses efficiency when applied to formats | |
205 | such as S-records and IEEE-695. | |
206 | ||
207 | @section What BFD Version 1 Can't Do | |
208 | As different information from the the object files is required, | |
209 | BFD reads from different sections of the file and processes them. | |
210 | For example a very common operation for the linker is processing symbol | |
211 | tables. Each BFD back end provides a routine for converting | |
212 | between the object file's representation of symbols and an internal | |
213 | canonical format. When the linker asks for the symbol table of an object | |
214 | file, it calls through the memory pointer to the relevant BFD | |
215 | back end routine which reads and converts the table into a canonical | |
216 | form. The linker then operates upon the common form. When the link is | |
217 | finished and the linker writes the symbol table of the output file, | |
218 | another BFD back end routine is called which takes the newly | |
219 | created symbol table and converts it into the chosen output format. | |
220 | ||
221 | @node BFD information loss, Mechanism, BFD outline, BFD | |
222 | @subsection Information Loss | |
223 | @emph{Some information is lost due to the nature of the file format.} The output targets | |
224 | supported by BFD do not provide identical facilities, and | |
225 | information which may be described in one form has nowhere to go in | |
226 | another format. One example of this is alignment information in | |
227 | @code{b.out}. There is nowhere in an @code{a.out} format file to store | |
228 | alignment information on the contained data, so when a file is linked | |
229 | from @code{b.out} and an @code{a.out} image is produced, alignment | |
230 | information will not propagate to the output file. (The linker will | |
231 | still use the alignment information internally, so the link is performed | |
232 | correctly). | |
233 | ||
234 | Another example is COFF section names. COFF files may contain an | |
235 | unlimited number of sections, each one with a textual section name. If | |
236 | the target of the link is a format which does not have many sections (eg | |
237 | @code{a.out}) or has sections without names (eg the Oasys format) the | |
238 | link cannot be done simply. You can circumvent this problem by | |
239 | describing the desired input-to-output section mapping with the linker command | |
240 | language. | |
241 | ||
242 | @emph{Information can be lost during canonicalization.} The BFD | |
243 | internal canonical form of the external formats is not exhaustive; there | |
244 | are structures in input formats for which there is no direct | |
245 | representation internally. This means that the BFD back ends | |
246 | cannot maintain all possible data richness through the transformation | |
247 | between external to internal and back to external formats. | |
248 | ||
249 | This limitation is only a problem when using the linker to read one | |
250 | format and write another. Each BFD back end is responsible for | |
251 | maintaining as much data as possible, and the internal BFD | |
252 | canonical form has structures which are opaque to the BFD core, | |
253 | and exported only to the back ends. When a file is read in one format, | |
254 | the canonical form is generated for BFD and the linker. At the | |
255 | same time, the back end saves away any information which may otherwise | |
256 | be lost. If the data is then written back in the same format, the back | |
257 | end routine will be able to use the canonical form provided by the | |
258 | BFD core as well as the information it prepared earlier. Since | |
259 | there is a great deal of commonality between back ends, this mechanism | |
260 | is very useful. There is no information lost for this reason when | |
261 | linking big endian COFF to little endian COFF, or from @code{a.out} to | |
262 | @code{b.out}. When a mixture of formats is linked, the information is | |
263 | only lost from the files whose format differs from the destination. | |
264 | ||
265 | @node Mechanism, , BFD information loss, BFD | |
266 | @subsection Mechanism | |
267 | The greatest potential for loss of information is when there is least | |
268 | overlap between the information provided by the source format, that | |
269 | stored by the canonical format, and the information needed by the | |
270 | destination format. A brief description of the canonical form may help | |
271 | you appreciate what kinds of data you can count on preserving across | |
272 | conversions. | |
273 | @cindex BFD canonical format | |
274 | @cindex internal object-file format | |
275 | ||
276 | @table @emph | |
277 | @item files | |
278 | Information on target machine architecture, particular implementation | |
279 | and format type are stored on a per-file basis. Other information | |
280 | includes a demand pageable bit and a write protected bit. Note that | |
281 | information like Unix magic numbers is not stored here---only the magic | |
282 | numbers' meaning, so a @code{ZMAGIC} file would have both the demand pageable | |
283 | bit and the write protected text bit set. | |
284 | ||
285 | The byte order of the target is stored on a per-file basis, so that big- | |
286 | and little-endian object files may be linked with one another. | |
287 | ||
288 | @item sections | |
289 | Each section in the input file contains the name of the section, the | |
290 | original address in the object file, various flags, size and alignment | |
291 | information and pointers into other BFD data structures. | |
292 | ||
293 | @item symbols | |
294 | Each symbol contains a pointer to the object file which originally | |
295 | defined it, its name, its value, and various flag bits. When a | |
296 | BFD back end reads in a symbol table, the back end relocates all | |
297 | symbols to make them relative to the base of the section where they were | |
298 | defined. This ensures that each symbol points to its containing | |
299 | section. Each symbol also has a varying amount of hidden data to contain | |
300 | private data for the BFD back end. Since the symbol points to the | |
301 | original file, the private data format for that symbol is accessible. | |
302 | @code{gld} can operate on a collection of symbols of wildly different | |
303 | formats without problems. | |
304 | ||
305 | Normal global and simple local symbols are maintained on output, so an | |
306 | output file (no matter its format) will retain symbols pointing to | |
307 | functions and to global, static, and common variables. Some symbol | |
308 | information is not worth retaining; in @code{a.out} type information is | |
309 | stored in the symbol table as long symbol names. This information would | |
310 | be useless to most COFF debuggers and may be thrown away with | |
311 | appropriate command line switches. (The GNU debugger @code{gdb} does | |
312 | support @code{a.out} style debugging information in COFF). | |
313 | ||
314 | There is one word of type information within the symbol, so if the | |
315 | format supports symbol type information within symbols (for example COFF, | |
316 | IEEE, Oasys) and the type is simple enough to fit within one word | |
317 | (nearly everything but aggregates) the information will be preserved. | |
318 | ||
319 | @item relocation level | |
320 | Each canonical BFD relocation record contains a pointer to the symbol to | |
321 | relocate to, the offset of the data to relocate, the section the data | |
322 | is in and a pointer to a relocation type descriptor. Relocation is | |
323 | performed effectively by message passing through the relocation type | |
324 | descriptor and symbol pointer. It allows relocations to be performed | |
325 | on output data using a relocation method only available in one of the | |
326 | input formats. For instance, Oasys provides a byte relocation format. | |
327 | A relocation record requesting this relocation type would point | |
328 | indirectly to a routine to perform this, so the relocation may be | |
329 | performed on a byte being written to a COFF file, even though 68k COFF | |
330 | has no such relocation type. | |
331 | ||
332 | @item line numbers | |
333 | Object formats can contain, for debugging purposes, some form of mapping | |
334 | between symbols, source line numbers, and addresses in the output file. | |
335 | These addresses have to be relocated along with the symbol information. | |
336 | Each symbol with an associated list of line number records points to the | |
337 | first record of the list. The head of a line number list consists of a | |
338 | pointer to the symbol, which allows divination of the address of the | |
339 | function whose line number is being described. The rest of the list is | |
340 | made up of pairs: offsets into the section and line numbers. Any format | |
341 | which can simply derive this information can pass it successfully | |
342 | between formats (COFF, IEEE and Oasys). | |
343 | @end table | |
344 | ||
345 | ||
346 | What is a backend | |
347 | @node BFD front end, BFD back end, Mechanism, Top | |
348 | @page | |
349 | @chapter BFD front end | |
350 | @include doc/bfd.doc | |
351 | @page | |
352 | @node Sections, Symbols , bfd, Top | |
353 | @include doc/section.doc | |
354 | @page | |
355 | @node Symbols, Archives ,Sections, To | |
356 | @include doc/syms.doc | |
357 | @page | |
358 | @node Archives, Formats, Symbols, Top | |
359 | @include doc/archive.doc | |
360 | @page | |
361 | @node Formats, Relocations, Archives, Top | |
362 | @include doc/format.doc | |
363 | @page | |
364 | @node Relocations, Core Files,Formats, Top | |
365 | @include doc/reloc.doc | |
366 | @page | |
367 | @node Core Files, Targets, Relocations, Top | |
368 | @include doc/core.doc | |
369 | @page | |
370 | @node Targets, Architectures, Core Files, Top | |
371 | @include doc/targets.doc | |
372 | @page | |
373 | @node Architectures, Opening and Closing, Targets, Top | |
374 | @include doc/archures.doc | |
375 | @page | |
376 | @node Opening and Closing, Internal, Architectures, Top | |
377 | @include doc/opncls.doc | |
378 | @page | |
379 | @node Internal, File Caching, Opening and Closing, Top | |
380 | @include doc/libbfd.doc | |
381 | @page | |
382 | @node File Caching, Top, Internal, Top | |
383 | @include doc/cache.doc | |
384 | @page | |
385 | @chapter BFD back end | |
386 | @node BFD back end, ,BFD front end, Top | |
387 | @menu | |
388 | * What to put where | |
389 | * a.out backends:: | |
390 | * coff backends:: | |
391 | * oasys backend:: | |
392 | * ieee backend:: | |
393 | * srecord backend:: | |
394 | @end menu | |
395 | @node What to Put Where, aout backends, BFD back end, BFD back end | |
396 | All of bfd lives in one directory. | |
397 | @page | |
398 | @node aout backends, coff backends, What to Put Where, BFD back end | |
399 | @include doc/aoutx.doc | |
400 | @page | |
401 | @node coff backends, oasys backends, aout backends, BFD back end | |
402 | @include doc/coffcode.doc | |
403 | @page | |
404 | @node Index, , BFD, Top | |
405 | @unnumbered Function Index | |
406 | @printindex fn | |
407 | @setchapternewpage on | |
408 | @unnumbered Index | |
409 | @printindex cp | |
410 | ||
411 | @tex | |
412 | % I think something like @colophon should be in texinfo. In the | |
413 | % meantime: | |
414 | \long\def\colophon{\hbox to0pt{}\vfill | |
415 | \centerline{The body of this manual is set in} | |
416 | \centerline{\fontname\tenrm,} | |
417 | \centerline{with headings in {\bf\fontname\tenbf}} | |
418 | \centerline{and examples in {\tt\fontname\tentt}.} | |
419 | \centerline{{\it\fontname\tenit\/} and} | |
420 | \centerline{{\sl\fontname\tensl\/}} | |
421 | \centerline{are used for emphasis.}\vfill} | |
422 | \page\colophon | |
423 | % Blame: [email protected], 28mar91. | |
424 | @end tex | |
425 | ||
426 | ||
427 | @contents | |
428 | @bye | |
429 | ||
430 |