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