Documentation
[deliverable/binutils-gdb.git] / bfd / bfd.texinfo
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 Free Software Foundation, Inc.
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, subject to the terms
24 of the GNU General Public License, which includes the provision that the
25 entire resulting derived work is distributed under the terms of a
26 permission notice identical to this one.
27
28 Permission is granted to copy and distribute translations of this manual
29 into another language, under the above conditions for modified versions.
30 @end ifinfo
31 @iftex
32 @c this removes the gaps around @examples
33
34 @c@finalout
35 @c@setchapternewpage odd
36 @settitle LIB BFD, the Binary File Descriptor Library
37 @titlepage
38 @title{libbfd}
39 @subtitle{The Binary File Descriptor Library}
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
60 Copyright @copyright{} 1991 Free Software Foundation, Inc.
61
62 Permission is granted to make and distribute verbatim copies of
63 this manual provided the copyright notice and this permission notice
64 are preserved on all copies.
65
66 Permission is granted to copy and distribute modified versions of this
67 manual under the conditions for verbatim copying, subject to the terms
68 of the GNU General Public License, which includes the provision that the
69 entire resulting derived work is distributed under the terms of a
70 permission notice identical to this one.
71
72 Permission is granted to copy and distribute translations of this manual
73 into another language, under the above conditions for modified versions.
74 @end titlepage
75 @end iftex
76
77 @node Top, Overview, (dir), (dir)
78 @ifinfo
79 This 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
90 BFD body:
91 * Memory usage::
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
104 Bfd 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?
113 Simply put, @code{bfd} is a package which allow applications to use the
114 same routines to operate on object files whatever the object file
115 format. A different object file format can be supported simply by
116 creating a new BFD back end and adding it to the library.
117
118 BFD 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
121 memory, and various canonical data structures. The front end also
122 decides 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
124 end provides a set of calls which the bfd front end can use to maintain
125 its canonical form. The back ends also may keep around information for
126 their own use, for greater efficiency.
127 @end itemize
128 @node History, How It Works, Overview,Top
129 @section History
130
131 One spur behind @code{bfd} was the Intel Oregon's GNU 960 team desire for
132 interoperability of applications on their COFF and b.out file formats.
133 Cygnus was providing GNU support for the team, and Cygnus were
134 contracted to provid the required functionality.
135
136 The name came from a conversation Gumby Wallace was
137 having with Richard Stallman about the library, RMS said that it
138 would be quite hard, Gumby said BFD. (Stallman was right, but the name
139 stuck).
140
141 At the same time, Ready Systems wanted much the same thing, but for
142 different object file formats, IEEE-695, Oasys, Srecords, a.out and 68k coff.
143
144 BFD was first implemented by Steve Chamberlain (steve@@cygnus.com),
145 John Gilmore (gnu@@cygnus.com), K. Richard Pixley (rich@@cygnus.com) and
146 Gumby Wallace (gumby@@cygnus.com) at Cygnus Support in Palo Alto,
147 California.
148
149 @node How It Works, History, Porting, Top
150 @section How It Works
151
152 To use the library, include @code{bfd.h} and link with @code{libbfd.a}.
153
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 number 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 Memory Usage, Sections, bfd, Top
353 @section Memory Usage
354 BFD keeps all its internal structures in obstacks. There is one obstack
355 per open bfd file, into which the current state is stored. When a bfd is
356 closed, the obstack is deleted, and so everything which has been
357 allocated by libbfd for the closing file will be thrown away.
358
359 BFD will not free anything created by an application, but pointers into
360 bfd structures will be invalidated on a @code{bfd_close}; for example,
361 after a @code{bfd_close} the vector passed to
362 @code{bfd_canonicalize_symtab} will still be around, since it has been
363 allocated by the application, but the data that it pointed to will be
364 lost.
365
366 The general rule is not to close a bfd until all operations dependent
367 upon data from the bfd have been completed, or all the data from within
368 the 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
370 associated with the supplied bfd. This could be used to select the
371 greediest open bfd, close it to reclaim the memory, perform some
372 operation and reopen the bfd again, to get a fresh copy of the data structures.
373
374 @node Sections,Symbols ,Memory Usage, Top
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
418 All 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.038869 seconds and 5 git commands to generate.