Commit | Line | Data |
---|---|---|
39db05ea | 1 | \input texinfo |
2013f9b4 SC |
2 | @setfilename bfdinfo |
3 | @c $Id$ | |
56996262 | 4 | @syncodeindex fn cp |
2013f9b4 SC |
5 | @ifinfo |
6 | This file documents the BFD library. | |
7 | ||
fd644025 | 8 | Copyright (C) 1991 Free Software Foundation, Inc. |
2013f9b4 SC |
9 | |
10 | Permission is granted to make and distribute verbatim copies of | |
11 | this manual provided the copyright notice and this permission notice | |
12 | are preserved on all copies. | |
13 | ||
14 | @ignore | |
15 | Permission is granted to process this file through Tex and print the | |
16 | results, provided the printed document carries copying permission | |
17 | notice identical to this one except for the removal of this paragraph | |
18 | (this paragraph not being relevant to the printed manual). | |
19 | ||
20 | @end ignore | |
21 | Permission is granted to copy and distribute modified versions of this | |
fd644025 RP |
22 | manual under the conditions for verbatim copying, subject to the terms |
23 | of the GNU General Public License, which includes the provision that the | |
24 | entire resulting derived work is distributed under the terms of a | |
25 | permission notice identical to this one. | |
2013f9b4 SC |
26 | |
27 | Permission is granted to copy and distribute translations of this manual | |
fd644025 | 28 | into another language, under the above conditions for modified versions. |
2013f9b4 SC |
29 | @end ifinfo |
30 | @iftex | |
2013f9b4 | 31 | @c@finalout |
188d6d22 | 32 | @setchapternewpage on |
2013f9b4 | 33 | @c@setchapternewpage odd |
990778ee | 34 | @settitle LIB BFD, the Binary File Descriptor Library |
2013f9b4 SC |
35 | @titlepage |
36 | @title{libbfd} | |
990778ee | 37 | @subtitle{The Binary File Descriptor Library} |
2013f9b4 | 38 | @sp 1 |
6724ff46 | 39 | @subtitle First Edition---BFD version < 2.0 |
2013f9b4 SC |
40 | @subtitle April 1991 |
41 | @author {Steve Chamberlain} | |
42 | @author {Cygnus Support} | |
43 | @page | |
44 | ||
45 | @tex | |
46 | \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ | |
47 | \xdef\manvers{\$Revision$} % For use in headers, footers too | |
48 | {\parskip=0pt | |
49 | \hfill Cygnus Support\par | |
50 | \hfill steve\@cygnus.com\par | |
51 | \hfill {\it BFD}, \manvers\par | |
52 | \hfill \TeX{}info \texinfoversion\par | |
53 | } | |
54 | \global\parindent=0pt % Steve likes it this way | |
55 | @end tex | |
56 | ||
57 | @vskip 0pt plus 1filll | |
fd644025 | 58 | Copyright @copyright{} 1991 Free Software Foundation, Inc. |
2013f9b4 SC |
59 | |
60 | Permission is granted to make and distribute verbatim copies of | |
61 | this manual provided the copyright notice and this permission notice | |
62 | are preserved on all copies. | |
63 | ||
64 | Permission is granted to copy and distribute modified versions of this | |
fd644025 RP |
65 | manual under the conditions for verbatim copying, subject to the terms |
66 | of the GNU General Public License, which includes the provision that the | |
67 | entire resulting derived work is distributed under the terms of a | |
2013f9b4 SC |
68 | permission notice identical to this one. |
69 | ||
70 | Permission is granted to copy and distribute translations of this manual | |
71 | into another language, under the above conditions for modified versions. | |
72 | @end titlepage | |
73 | @end iftex | |
2013f9b4 SC |
74 | |
75 | @node Top, Overview, (dir), (dir) | |
76 | @ifinfo | |
77 | This file documents the binary file descriptor library libbfd. | |
78 | @end ifinfo | |
79 | ||
80 | @menu | |
6724ff46 RP |
81 | * Overview:: Overview of BFD |
82 | * History:: History of BFD | |
2013f9b4 SC |
83 | * Backends:: Backends |
84 | * Porting:: Porting | |
85 | * Future:: Future | |
86 | * Index:: Index | |
87 | ||
88 | BFD body: | |
ed0a7395 | 89 | * Memory usage:: |
2013f9b4 SC |
90 | * Sections:: |
91 | * Symbols:: | |
92 | * Archives:: | |
93 | * Formats:: | |
94 | * Relocations:: | |
95 | * Core Files:: | |
96 | * Targets:: | |
97 | * Architecturs:: | |
98 | * Opening and Closing:: | |
99 | * Internal:: | |
100 | * File Caching:: | |
101 | ||
6724ff46 | 102 | BFD backends: |
2013f9b4 SC |
103 | * a.out backends:: |
104 | * coff backends:: | |
105 | @end menu | |
106 | ||
107 | @node Overview, History, Top, Top | |
108 | @chapter Introduction | |
109 | @cindex BFD | |
110 | @cindex what is it? | |
56996262 RP |
111 | BFD is a package for manipulating binary files required for developing |
112 | programs. It implements a group of structured operations designed to | |
113 | shield the programmer from the underlying representation of these | |
114 | binary files. It understands object (compiled) files, archive | |
115 | libraries, and core files. It is designed to work in a variety of | |
116 | target environments. | |
117 | ||
118 | Most simply put, BFD is a package which allows applications to use the | |
2013f9b4 | 119 | same routines to operate on object files whatever the object file |
56996262 | 120 | format. |
2013f9b4 SC |
121 | |
122 | BFD is split into two parts; the front end and the many back ends. | |
123 | @itemize @bullet | |
56996262 RP |
124 | @item |
125 | The front end of BFD provides the interface to the user. It manages | |
2013f9b4 SC |
126 | memory, and various canonical data structures. The front end also |
127 | decides which back end to use, and when to call back end routines. | |
56996262 RP |
128 | @item |
129 | The back ends provide BFD its view of the real world. A different | |
130 | object file format can be supported simply by creating a new BFD back | |
131 | end and adding it to the library. Each back end provides a set of calls | |
132 | which the BFD front end can use to maintain its canonical form. The back | |
133 | ends also may keep around information for their own use, for greater | |
134 | efficiency. | |
2013f9b4 SC |
135 | @end itemize |
136 | @node History, How It Works, Overview,Top | |
137 | @section History | |
138 | ||
6724ff46 RP |
139 | One spur behind BFD was the desire, on the part of the GNU 960 team at |
140 | Intel Oregon, for interoperability of applications on their COFF and | |
141 | b.out file formats. Cygnus was providing GNU support for the team, and | |
142 | Cygnus was contracted to provide the required functionality. | |
2013f9b4 | 143 | |
6724ff46 RP |
144 | The name came from a conversation David Wallace was having with Richard |
145 | Stallman about the library: RMS said that it would be quite hard---David | |
146 | said ``BFD''. Stallman was right, but the name stuck. | |
2013f9b4 SC |
147 | |
148 | At the same time, Ready Systems wanted much the same thing, but for | |
6724ff46 RP |
149 | different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k |
150 | coff. | |
2013f9b4 SC |
151 | |
152 | BFD was first implemented by Steve Chamberlain (steve@@cygnus.com), | |
153 | John Gilmore (gnu@@cygnus.com), K. Richard Pixley (rich@@cygnus.com) and | |
6724ff46 | 154 | David Wallace (gumby@@cygnus.com) at Cygnus Support in Palo Alto, |
990778ee | 155 | California. |
2013f9b4 SC |
156 | |
157 | @node How It Works, History, Porting, Top | |
158 | @section How It Works | |
d1c61021 SC |
159 | |
160 | To use the library, include @code{bfd.h} and link with @code{libbfd.a}. | |
161 | ||
6724ff46 RP |
162 | BFD provides a common interface to the parts of an object file |
163 | for a calling application. | |
2013f9b4 | 164 | |
6724ff46 RP |
165 | When an application sucessfully opens a target file (object, archive or |
166 | whatever) a pointer to an internal structure is returned. This pointer | |
167 | points to a structure called @code{bfd}, described in | |
168 | @code{include/bfd.h}. Our convention is to call this pointer a BFD, and | |
169 | instances of it within code @code{abfd}. All operations on | |
170 | the target object file are applied as methods to the BFD. The mapping is | |
171 | defined within @code{bfd.h} in a set of macros, all beginning | |
56996262 RP |
172 | @samp{bfd_}. |
173 | ||
174 | In short, a BFD is a representation for a particular file. It is opened | |
175 | in a manner similar to a file; code then manipulates it rather than the | |
176 | raw files. | |
6724ff46 RP |
177 | |
178 | For example, this sequence would do what you would probably expect: | |
179 | return the number of sections in an object file attached to a BFD | |
180 | @code{abfd}. | |
2013f9b4 | 181 | |
2013f9b4 | 182 | @lisp |
39db05ea | 183 | @cartouche |
2013f9b4 SC |
184 | #include "bfd.h" |
185 | ||
186 | unsigned int number_of_sections(abfd) | |
187 | bfd *abfd; | |
188 | @{ | |
189 | return bfd_count_sections(abfd); | |
190 | @} | |
39db05ea | 191 | @end cartouche |
2013f9b4 SC |
192 | @end lisp |
193 | ||
6724ff46 | 194 | The abstraction used within BFD is that an object file has a header, |
1fc712b8 | 195 | a number of sections containing raw data, a set of relocations, and some |
6724ff46 RP |
196 | symbol information. Also, BFDs opened for archives have the |
197 | additional attribute of an index and contain subordinate BFDs. This approach is | |
198 | fine for a.out and coff, but loses efficiency when applied to formats | |
2013f9b4 SC |
199 | such as S-records and IEEE-695. |
200 | ||
56996262 RP |
201 | @cindex targets |
202 | @cindex formats | |
203 | BFD makes a distinction between @dfn{targets} (families of file | |
204 | formats) and @dfn{formats} (individual file formats). For instance, | |
205 | the @code{"sun4os4"} target can handle core, object and archive formats of | |
206 | files. The exact layout of the different formats depends on the target | |
207 | environment. | |
208 | ||
209 | The target @code{"default"} means the first one known (usually used for | |
210 | environments that only support one format, or where the common format | |
211 | is known at compile or link time). The target @code{NULL} means the one | |
212 | specified at runtime in the environment variable @code{GNUTARGET}; if that is | |
213 | null or not defined then, on output, the first entry in the target list | |
214 | is chosen; or, on input, all targets are searched to find a matching | |
215 | one. | |
216 | ||
217 | Most programs should use the target @code{NULL}. See the descriptions | |
218 | of @code{bfd_target_list} and @code{bfd_format_string} for functions to | |
219 | inquire on targets and formats. | |
220 | ||
6724ff46 | 221 | @section What BFD Version 1 Can Do |
2013f9b4 SC |
222 | As different information from the the object files is required, |
223 | BFD reads from different sections of the file and processes them. | |
224 | For example a very common operation for the linker is processing symbol | |
225 | tables. Each BFD back end provides a routine for converting | |
226 | between the object file's representation of symbols and an internal | |
227 | canonical format. When the linker asks for the symbol table of an object | |
228 | file, it calls through the memory pointer to the relevant BFD | |
229 | back end routine which reads and converts the table into a canonical | |
6724ff46 RP |
230 | form. The linker then operates upon the canonical form. When the link is |
231 | finished and the linker writes the output file's symbol table, | |
2013f9b4 SC |
232 | another BFD back end routine is called which takes the newly |
233 | created symbol table and converts it into the chosen output format. | |
234 | ||
235 | @node BFD information loss, Mechanism, BFD outline, BFD | |
236 | @subsection Information Loss | |
237 | @emph{Some information is lost due to the nature of the file format.} The output targets | |
238 | supported by BFD do not provide identical facilities, and | |
239 | information which may be described in one form has nowhere to go in | |
240 | another format. One example of this is alignment information in | |
241 | @code{b.out}. There is nowhere in an @code{a.out} format file to store | |
242 | alignment information on the contained data, so when a file is linked | |
243 | from @code{b.out} and an @code{a.out} image is produced, alignment | |
244 | information will not propagate to the output file. (The linker will | |
245 | still use the alignment information internally, so the link is performed | |
246 | correctly). | |
247 | ||
248 | Another example is COFF section names. COFF files may contain an | |
249 | unlimited number of sections, each one with a textual section name. If | |
250 | the target of the link is a format which does not have many sections (eg | |
251 | @code{a.out}) or has sections without names (eg the Oasys format) the | |
252 | link cannot be done simply. You can circumvent this problem by | |
253 | describing the desired input-to-output section mapping with the linker command | |
254 | language. | |
255 | ||
256 | @emph{Information can be lost during canonicalization.} The BFD | |
257 | internal canonical form of the external formats is not exhaustive; there | |
258 | are structures in input formats for which there is no direct | |
259 | representation internally. This means that the BFD back ends | |
260 | cannot maintain all possible data richness through the transformation | |
261 | between external to internal and back to external formats. | |
262 | ||
dd260c23 RP |
263 | This limitation is only a problem when an application reads one |
264 | format and writes another. Each BFD back end is responsible for | |
2013f9b4 SC |
265 | maintaining as much data as possible, and the internal BFD |
266 | canonical form has structures which are opaque to the BFD core, | |
267 | and exported only to the back ends. When a file is read in one format, | |
dd260c23 | 268 | the canonical form is generated for BFD and the application. At the |
2013f9b4 SC |
269 | same time, the back end saves away any information which may otherwise |
270 | be lost. If the data is then written back in the same format, the back | |
271 | end routine will be able to use the canonical form provided by the | |
272 | BFD core as well as the information it prepared earlier. Since | |
273 | there is a great deal of commonality between back ends, this mechanism | |
274 | is very useful. There is no information lost for this reason when | |
dd260c23 | 275 | linking or copying big endian COFF to little endian COFF, or @code{a.out} to |
2013f9b4 SC |
276 | @code{b.out}. When a mixture of formats is linked, the information is |
277 | only lost from the files whose format differs from the destination. | |
278 | ||
279 | @node Mechanism, , BFD information loss, BFD | |
280 | @subsection Mechanism | |
281 | The greatest potential for loss of information is when there is least | |
282 | overlap between the information provided by the source format, that | |
283 | stored by the canonical format, and the information needed by the | |
284 | destination format. A brief description of the canonical form may help | |
285 | you appreciate what kinds of data you can count on preserving across | |
286 | conversions. | |
287 | @cindex BFD canonical format | |
288 | @cindex internal object-file format | |
289 | ||
290 | @table @emph | |
291 | @item files | |
292 | Information on target machine architecture, particular implementation | |
293 | and format type are stored on a per-file basis. Other information | |
294 | includes a demand pageable bit and a write protected bit. Note that | |
295 | information like Unix magic numbers is not stored here---only the magic | |
dd260c23 RP |
296 | numbers' meaning, so a @code{ZMAGIC} file would have both the demand |
297 | pageable bit and the write protected text bit set. The byte order of | |
298 | the target is stored on a per-file basis, so that big- and little-endian | |
299 | object files may be linked with one another. | |
300 | @c FIXME: generalize above from "link"? | |
2013f9b4 SC |
301 | |
302 | @item sections | |
303 | Each section in the input file contains the name of the section, the | |
304 | original address in the object file, various flags, size and alignment | |
305 | information and pointers into other BFD data structures. | |
306 | ||
307 | @item symbols | |
308 | Each symbol contains a pointer to the object file which originally | |
309 | defined it, its name, its value, and various flag bits. When a | |
310 | BFD back end reads in a symbol table, the back end relocates all | |
311 | symbols to make them relative to the base of the section where they were | |
312 | defined. This ensures that each symbol points to its containing | |
313 | section. Each symbol also has a varying amount of hidden data to contain | |
314 | private data for the BFD back end. Since the symbol points to the | |
315 | original file, the private data format for that symbol is accessible. | |
316 | @code{gld} can operate on a collection of symbols of wildly different | |
317 | formats without problems. | |
318 | ||
319 | Normal global and simple local symbols are maintained on output, so an | |
320 | output file (no matter its format) will retain symbols pointing to | |
321 | functions and to global, static, and common variables. Some symbol | |
322 | information is not worth retaining; in @code{a.out} type information is | |
dd260c23 RP |
323 | stored in the symbol table as long symbol names. This information would |
324 | be useless to most COFF debuggers; the linker has command line switches | |
325 | to allow users to throw it away. | |
2013f9b4 SC |
326 | |
327 | There is one word of type information within the symbol, so if the | |
328 | format supports symbol type information within symbols (for example COFF, | |
329 | IEEE, Oasys) and the type is simple enough to fit within one word | |
330 | (nearly everything but aggregates) the information will be preserved. | |
331 | ||
332 | @item relocation level | |
333 | Each canonical BFD relocation record contains a pointer to the symbol to | |
334 | relocate to, the offset of the data to relocate, the section the data | |
335 | is in and a pointer to a relocation type descriptor. Relocation is | |
336 | performed effectively by message passing through the relocation type | |
337 | descriptor and symbol pointer. It allows relocations to be performed | |
338 | on output data using a relocation method only available in one of the | |
339 | input formats. For instance, Oasys provides a byte relocation format. | |
340 | A relocation record requesting this relocation type would point | |
341 | indirectly to a routine to perform this, so the relocation may be | |
342 | performed on a byte being written to a COFF file, even though 68k COFF | |
343 | has no such relocation type. | |
344 | ||
345 | @item line numbers | |
346 | Object formats can contain, for debugging purposes, some form of mapping | |
347 | between symbols, source line numbers, and addresses in the output file. | |
348 | These addresses have to be relocated along with the symbol information. | |
349 | Each symbol with an associated list of line number records points to the | |
350 | first record of the list. The head of a line number list consists of a | |
351 | pointer to the symbol, which allows divination of the address of the | |
352 | function whose line number is being described. The rest of the list is | |
353 | made up of pairs: offsets into the section and line numbers. Any format | |
354 | which can simply derive this information can pass it successfully | |
355 | between formats (COFF, IEEE and Oasys). | |
356 | @end table | |
357 | ||
188d6d22 RP |
358 | @c FIXME: what is this line about? Do we want introductory remarks |
359 | @c FIXME... on back ends? commented out for now. | |
360 | @c What is a backend | |
2013f9b4 | 361 | @node BFD front end, BFD back end, Mechanism, Top |
2013f9b4 | 362 | @chapter BFD front end |
fd186007 | 363 | @include bfd.texi |
188d6d22 | 364 | |
56996262 | 365 | @node Memory Usage, Errors, bfd, Top |
ed0a7395 SC |
366 | @section Memory Usage |
367 | BFD keeps all its internal structures in obstacks. There is one obstack | |
6724ff46 | 368 | per open BFD file, into which the current state is stored. When a BFD is |
ed0a7395 SC |
369 | closed, the obstack is deleted, and so everything which has been |
370 | allocated by libbfd for the closing file will be thrown away. | |
371 | ||
372 | BFD will not free anything created by an application, but pointers into | |
6724ff46 | 373 | @code{bfd} structures will be invalidated on a @code{bfd_close}; for example, |
ed0a7395 SC |
374 | after a @code{bfd_close} the vector passed to |
375 | @code{bfd_canonicalize_symtab} will still be around, since it has been | |
376 | allocated by the application, but the data that it pointed to will be | |
377 | lost. | |
378 | ||
6724ff46 RP |
379 | The general rule is not to close a BFD until all operations dependent |
380 | upon data from the BFD have been completed, or all the data from within | |
ed0a7395 SC |
381 | the file has been copied. To help with the management of memory, there is a function |
382 | (@code{bfd_alloc_size}) which returns the number of bytes in obstacks | |
6724ff46 RP |
383 | associated with the supplied BFD. This could be used to select the |
384 | greediest open BFD, close it to reclaim the memory, perform some | |
56996262 RP |
385 | operation and reopen the BFD again, to get a fresh copy of the data |
386 | structures. | |
387 | ||
388 | @node Errors, Sections, Memory Usage, Top | |
389 | @section Error Handling | |
390 | ||
391 | @cindex errors | |
392 | In general, a boolean function returns true on success and false on failure | |
393 | (unless it's a predicate). Functions which return pointers to | |
394 | objects return @code{NULL} on error. The specifics are documented with each | |
395 | function. | |
396 | ||
397 | If a function fails, you should check the variable @code{bfd_error}. If | |
398 | the value is @code{no_error}, then check the C variable @code{errno} | |
399 | just as you would with any other program. Other values for | |
400 | @code{bfd_error} are documented in @file{bfd.h}. | |
401 | ||
402 | @findex bfd_errmsg | |
403 | If you would prefer a comprehensible string for the error message, use | |
404 | the function @code{bfd_errmsg}: | |
405 | @example | |
406 | char * bfd_errmsg (error_tag) | |
407 | @end example | |
408 | This function returns a read-only string which documents the error | |
409 | code. If the error code is @code{no_error} then it will return a string | |
410 | depending on the value of @code{errno}. | |
411 | ||
412 | @findex bfd_perror | |
413 | @code{bfd_perror()} is like the @code{perror()} function except it understands | |
414 | @code{bfd_error}. | |
415 | ||
416 | ||
417 | @node Sections, Symbols, Errors, Top | |
d3f2a82c | 418 | @include section.texi |
188d6d22 | 419 | |
2013f9b4 | 420 | @node Symbols, Archives ,Sections, To |
d3f2a82c | 421 | @include syms.texi |
188d6d22 | 422 | |
2013f9b4 | 423 | @node Archives, Formats, Symbols, Top |
d3f2a82c | 424 | @include archive.texi |
188d6d22 | 425 | |
2013f9b4 | 426 | @node Formats, Relocations, Archives, Top |
d3f2a82c | 427 | @include format.texi |
188d6d22 | 428 | |
2013f9b4 | 429 | @node Relocations, Core Files,Formats, Top |
d3f2a82c | 430 | @include reloc.texi |
188d6d22 | 431 | |
2013f9b4 | 432 | @node Core Files, Targets, Relocations, Top |
d3f2a82c | 433 | @include core.texi |
188d6d22 | 434 | |
2013f9b4 | 435 | @node Targets, Architectures, Core Files, Top |
d3f2a82c | 436 | @include targets.texi |
188d6d22 | 437 | |
2013f9b4 | 438 | @node Architectures, Opening and Closing, Targets, Top |
d3f2a82c | 439 | @include archures.texi |
188d6d22 | 440 | |
2013f9b4 | 441 | @node Opening and Closing, Internal, Architectures, Top |
d3f2a82c | 442 | @include opncls.texi |
188d6d22 | 443 | |
2013f9b4 | 444 | @node Internal, File Caching, Opening and Closing, Top |
d3f2a82c | 445 | @include libbfd.texi |
188d6d22 | 446 | |
2013f9b4 | 447 | @node File Caching, Top, Internal, Top |
d3f2a82c | 448 | @include cache.texi |
188d6d22 | 449 | |
2013f9b4 SC |
450 | @chapter BFD back end |
451 | @node BFD back end, ,BFD front end, Top | |
452 | @menu | |
453 | * What to put where | |
454 | * a.out backends:: | |
455 | * coff backends:: | |
456 | * oasys backend:: | |
457 | * ieee backend:: | |
458 | * srecord backend:: | |
459 | @end menu | |
460 | @node What to Put Where, aout backends, BFD back end, BFD back end | |
6724ff46 | 461 | All of BFD lives in one directory. |
188d6d22 | 462 | |
2013f9b4 | 463 | @node aout backends, coff backends, What to Put Where, BFD back end |
d33cfbd8 | 464 | @include aoutx.texi |
188d6d22 | 465 | |
2013f9b4 | 466 | @node coff backends, oasys backends, aout backends, BFD back end |
d33cfbd8 | 467 | @include coffcode.texi |
188d6d22 | 468 | |
2013f9b4 | 469 | @node Index, , BFD, Top |
2013f9b4 SC |
470 | @unnumbered Index |
471 | @printindex cp | |
472 | ||
473 | @tex | |
474 | % I think something like @colophon should be in texinfo. In the | |
475 | % meantime: | |
476 | \long\def\colophon{\hbox to0pt{}\vfill | |
477 | \centerline{The body of this manual is set in} | |
478 | \centerline{\fontname\tenrm,} | |
479 | \centerline{with headings in {\bf\fontname\tenbf}} | |
480 | \centerline{and examples in {\tt\fontname\tentt}.} | |
481 | \centerline{{\it\fontname\tenit\/} and} | |
482 | \centerline{{\sl\fontname\tensl\/}} | |
483 | \centerline{are used for emphasis.}\vfill} | |
484 | \page\colophon | |
485 | % Blame: pesch@cygnus.com, 28mar91. | |
486 | @end tex | |
487 | ||
488 | ||
489 | @contents | |
490 | @bye | |
491 | ||
492 |