This is the version of devo/bfd/ChangeLog that was in the gdb-4.3 release.
[deliverable/binutils-gdb.git] / bfd / bfd.texinfo
CommitLineData
39db05ea 1\input texinfo
2013f9b4
SC
2@setfilename bfdinfo
3@c $Id$
56996262 4@syncodeindex fn cp
2013f9b4
SC
5@ifinfo
6This file documents the BFD library.
7
fd644025 8Copyright (C) 1991 Free Software Foundation, Inc.
2013f9b4
SC
9
10Permission is granted to make and distribute verbatim copies of
11this manual provided the copyright notice and this permission notice
12are preserved on all copies.
13
14@ignore
15Permission is granted to process this file through Tex and print the
16results, provided the printed document carries copying permission
17notice 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
21Permission is granted to copy and distribute modified versions of this
fd644025
RP
22manual under the conditions for verbatim copying, subject to the terms
23of the GNU General Public License, which includes the provision that the
24entire resulting derived work is distributed under the terms of a
25permission notice identical to this one.
2013f9b4
SC
26
27Permission is granted to copy and distribute translations of this manual
fd644025 28into 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 58Copyright @copyright{} 1991 Free Software Foundation, Inc.
2013f9b4
SC
59
60Permission is granted to make and distribute verbatim copies of
61this manual provided the copyright notice and this permission notice
62are preserved on all copies.
63
64Permission is granted to copy and distribute modified versions of this
fd644025
RP
65manual under the conditions for verbatim copying, subject to the terms
66of the GNU General Public License, which includes the provision that the
67entire resulting derived work is distributed under the terms of a
2013f9b4
SC
68permission notice identical to this one.
69
70Permission is granted to copy and distribute translations of this manual
71into 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
77This 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
88BFD 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 102BFD 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
111BFD is a package for manipulating binary files required for developing
112programs. It implements a group of structured operations designed to
113shield the programmer from the underlying representation of these
114binary files. It understands object (compiled) files, archive
115libraries, and core files. It is designed to work in a variety of
116target environments.
117
118Most simply put, BFD is a package which allows applications to use the
2013f9b4 119same routines to operate on object files whatever the object file
56996262 120format.
2013f9b4
SC
121
122BFD is split into two parts; the front end and the many back ends.
123@itemize @bullet
56996262
RP
124@item
125The front end of BFD provides the interface to the user. It manages
2013f9b4
SC
126memory, and various canonical data structures. The front end also
127decides which back end to use, and when to call back end routines.
56996262
RP
128@item
129The back ends provide BFD its view of the real world. A different
130object file format can be supported simply by creating a new BFD back
131end and adding it to the library. Each back end provides a set of calls
132which the BFD front end can use to maintain its canonical form. The back
133ends also may keep around information for their own use, for greater
134efficiency.
2013f9b4
SC
135@end itemize
136@node History, How It Works, Overview,Top
137@section History
138
6724ff46
RP
139One spur behind BFD was the desire, on the part of the GNU 960 team at
140Intel Oregon, for interoperability of applications on their COFF and
141b.out file formats. Cygnus was providing GNU support for the team, and
142Cygnus was contracted to provide the required functionality.
2013f9b4 143
6724ff46
RP
144The name came from a conversation David Wallace was having with Richard
145Stallman about the library: RMS said that it would be quite hard---David
146said ``BFD''. Stallman was right, but the name stuck.
2013f9b4
SC
147
148At the same time, Ready Systems wanted much the same thing, but for
6724ff46
RP
149different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k
150coff.
2013f9b4
SC
151
152BFD was first implemented by Steve Chamberlain (steve@@cygnus.com),
153John Gilmore (gnu@@cygnus.com), K. Richard Pixley (rich@@cygnus.com) and
6724ff46 154David Wallace (gumby@@cygnus.com) at Cygnus Support in Palo Alto,
990778ee 155California.
2013f9b4
SC
156
157@node How It Works, History, Porting, Top
158@section How It Works
d1c61021
SC
159
160To use the library, include @code{bfd.h} and link with @code{libbfd.a}.
161
6724ff46
RP
162BFD provides a common interface to the parts of an object file
163for a calling application.
2013f9b4 164
6724ff46
RP
165When an application sucessfully opens a target file (object, archive or
166whatever) a pointer to an internal structure is returned. This pointer
167points to a structure called @code{bfd}, described in
168@code{include/bfd.h}. Our convention is to call this pointer a BFD, and
169instances of it within code @code{abfd}. All operations on
170the target object file are applied as methods to the BFD. The mapping is
171defined within @code{bfd.h} in a set of macros, all beginning
56996262
RP
172@samp{bfd_}.
173
174In short, a BFD is a representation for a particular file. It is opened
175in a manner similar to a file; code then manipulates it rather than the
176raw files.
6724ff46
RP
177
178For example, this sequence would do what you would probably expect:
179return 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
186unsigned int number_of_sections(abfd)
187bfd *abfd;
188@{
189 return bfd_count_sections(abfd);
190@}
39db05ea 191@end cartouche
2013f9b4
SC
192@end lisp
193
6724ff46 194The abstraction used within BFD is that an object file has a header,
1fc712b8 195a number of sections containing raw data, a set of relocations, and some
6724ff46
RP
196symbol information. Also, BFDs opened for archives have the
197additional attribute of an index and contain subordinate BFDs. This approach is
198fine for a.out and coff, but loses efficiency when applied to formats
2013f9b4
SC
199such as S-records and IEEE-695.
200
56996262
RP
201@cindex targets
202@cindex formats
203BFD makes a distinction between @dfn{targets} (families of file
204formats) and @dfn{formats} (individual file formats). For instance,
205the @code{"sun4os4"} target can handle core, object and archive formats of
206files. The exact layout of the different formats depends on the target
207environment.
208
209The target @code{"default"} means the first one known (usually used for
210environments that only support one format, or where the common format
211is known at compile or link time). The target @code{NULL} means the one
212specified at runtime in the environment variable @code{GNUTARGET}; if that is
213null or not defined then, on output, the first entry in the target list
214is chosen; or, on input, all targets are searched to find a matching
215one.
216
217Most programs should use the target @code{NULL}. See the descriptions
218of @code{bfd_target_list} and @code{bfd_format_string} for functions to
219inquire on targets and formats.
220
6724ff46 221@section What BFD Version 1 Can Do
2013f9b4
SC
222As different information from the the object files is required,
223BFD reads from different sections of the file and processes them.
224For example a very common operation for the linker is processing symbol
225tables. Each BFD back end provides a routine for converting
226between the object file's representation of symbols and an internal
227canonical format. When the linker asks for the symbol table of an object
228file, it calls through the memory pointer to the relevant BFD
229back end routine which reads and converts the table into a canonical
6724ff46
RP
230form. The linker then operates upon the canonical form. When the link is
231finished and the linker writes the output file's symbol table,
2013f9b4
SC
232another BFD back end routine is called which takes the newly
233created 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
238supported by BFD do not provide identical facilities, and
239information which may be described in one form has nowhere to go in
240another 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
242alignment information on the contained data, so when a file is linked
243from @code{b.out} and an @code{a.out} image is produced, alignment
244information will not propagate to the output file. (The linker will
245still use the alignment information internally, so the link is performed
246correctly).
247
248Another example is COFF section names. COFF files may contain an
249unlimited number of sections, each one with a textual section name. If
250the 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
252link cannot be done simply. You can circumvent this problem by
253describing the desired input-to-output section mapping with the linker command
254language.
255
256@emph{Information can be lost during canonicalization.} The BFD
257internal canonical form of the external formats is not exhaustive; there
258are structures in input formats for which there is no direct
259representation internally. This means that the BFD back ends
260cannot maintain all possible data richness through the transformation
261between external to internal and back to external formats.
262
dd260c23
RP
263This limitation is only a problem when an application reads one
264format and writes another. Each BFD back end is responsible for
2013f9b4
SC
265maintaining as much data as possible, and the internal BFD
266canonical form has structures which are opaque to the BFD core,
267and exported only to the back ends. When a file is read in one format,
dd260c23 268the canonical form is generated for BFD and the application. At the
2013f9b4
SC
269same time, the back end saves away any information which may otherwise
270be lost. If the data is then written back in the same format, the back
271end routine will be able to use the canonical form provided by the
272BFD core as well as the information it prepared earlier. Since
273there is a great deal of commonality between back ends, this mechanism
274is very useful. There is no information lost for this reason when
dd260c23 275linking 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
277only lost from the files whose format differs from the destination.
278
279@node Mechanism, , BFD information loss, BFD
280@subsection Mechanism
281The greatest potential for loss of information is when there is least
282overlap between the information provided by the source format, that
283stored by the canonical format, and the information needed by the
284destination format. A brief description of the canonical form may help
285you appreciate what kinds of data you can count on preserving across
286conversions.
287@cindex BFD canonical format
288@cindex internal object-file format
289
290@table @emph
291@item files
292Information on target machine architecture, particular implementation
293and format type are stored on a per-file basis. Other information
294includes a demand pageable bit and a write protected bit. Note that
295information like Unix magic numbers is not stored here---only the magic
dd260c23
RP
296numbers' meaning, so a @code{ZMAGIC} file would have both the demand
297pageable bit and the write protected text bit set. The byte order of
298the target is stored on a per-file basis, so that big- and little-endian
299object files may be linked with one another.
300@c FIXME: generalize above from "link"?
2013f9b4
SC
301
302@item sections
303Each section in the input file contains the name of the section, the
304original address in the object file, various flags, size and alignment
305information and pointers into other BFD data structures.
306
307@item symbols
308Each symbol contains a pointer to the object file which originally
309defined it, its name, its value, and various flag bits. When a
310BFD back end reads in a symbol table, the back end relocates all
311symbols to make them relative to the base of the section where they were
312defined. This ensures that each symbol points to its containing
313section. Each symbol also has a varying amount of hidden data to contain
314private data for the BFD back end. Since the symbol points to the
315original file, the private data format for that symbol is accessible.
316@code{gld} can operate on a collection of symbols of wildly different
317formats without problems.
318
319Normal global and simple local symbols are maintained on output, so an
320output file (no matter its format) will retain symbols pointing to
321functions and to global, static, and common variables. Some symbol
322information is not worth retaining; in @code{a.out} type information is
dd260c23
RP
323stored in the symbol table as long symbol names. This information would
324be useless to most COFF debuggers; the linker has command line switches
325to allow users to throw it away.
2013f9b4
SC
326
327There is one word of type information within the symbol, so if the
328format supports symbol type information within symbols (for example COFF,
329IEEE, 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
333Each canonical BFD relocation record contains a pointer to the symbol to
334relocate to, the offset of the data to relocate, the section the data
335is in and a pointer to a relocation type descriptor. Relocation is
336performed effectively by message passing through the relocation type
337descriptor and symbol pointer. It allows relocations to be performed
338on output data using a relocation method only available in one of the
339input formats. For instance, Oasys provides a byte relocation format.
340A relocation record requesting this relocation type would point
341indirectly to a routine to perform this, so the relocation may be
342performed on a byte being written to a COFF file, even though 68k COFF
343has no such relocation type.
344
345@item line numbers
346Object formats can contain, for debugging purposes, some form of mapping
347between symbols, source line numbers, and addresses in the output file.
348These addresses have to be relocated along with the symbol information.
349Each symbol with an associated list of line number records points to the
350first record of the list. The head of a line number list consists of a
351pointer to the symbol, which allows divination of the address of the
352function whose line number is being described. The rest of the list is
353made up of pairs: offsets into the section and line numbers. Any format
354which can simply derive this information can pass it successfully
355between 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
367BFD keeps all its internal structures in obstacks. There is one obstack
6724ff46 368per open BFD file, into which the current state is stored. When a BFD is
ed0a7395
SC
369closed, the obstack is deleted, and so everything which has been
370allocated by libbfd for the closing file will be thrown away.
371
372BFD 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
374after a @code{bfd_close} the vector passed to
375@code{bfd_canonicalize_symtab} will still be around, since it has been
376allocated by the application, but the data that it pointed to will be
377lost.
378
6724ff46
RP
379The general rule is not to close a BFD until all operations dependent
380upon data from the BFD have been completed, or all the data from within
ed0a7395
SC
381the 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
383associated with the supplied BFD. This could be used to select the
384greediest open BFD, close it to reclaim the memory, perform some
56996262
RP
385operation and reopen the BFD again, to get a fresh copy of the data
386structures.
387
388@node Errors, Sections, Memory Usage, Top
389@section Error Handling
390
391@cindex errors
392In general, a boolean function returns true on success and false on failure
393(unless it's a predicate). Functions which return pointers to
394objects return @code{NULL} on error. The specifics are documented with each
395function.
396
397If a function fails, you should check the variable @code{bfd_error}. If
398the value is @code{no_error}, then check the C variable @code{errno}
399just 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
403If you would prefer a comprehensible string for the error message, use
404the function @code{bfd_errmsg}:
405@example
406char * bfd_errmsg (error_tag)
407@end example
408This function returns a read-only string which documents the error
409code. If the error code is @code{no_error} then it will return a string
410depending 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 461All 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
This page took 0.053574 seconds and 4 git commands to generate.