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