a1431199a1bc82e190b6179f9c8ed683ecc97c4b
[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---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, BFD is a package which allows 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 BFD was the desire, on the part of the GNU 960 team at
129 Intel Oregon, for interoperability of applications on their COFF and
130 b.out file formats. Cygnus was providing GNU support for the team, and
131 Cygnus was contracted to provide the required functionality.
132
133 The name came from a conversation David Wallace was having with Richard
134 Stallman about the library: RMS said that it would be quite hard---David
135 said ``BFD''. Stallman was right, but the name stuck.
136
137 At the same time, Ready Systems wanted much the same thing, but for
138 different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k
139 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 David 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 BFD provides a common interface to the parts of an object file
152 for a calling application.
153
154 When an application sucessfully opens a target file (object, archive or
155 whatever) a pointer to an internal structure is returned. This pointer
156 points to a structure called @code{bfd}, described in
157 @code{include/bfd.h}. Our convention is to call this pointer a BFD, and
158 instances of it within code @code{abfd}. All operations on
159 the target object file are applied as methods to the BFD. The mapping is
160 defined within @code{bfd.h} in a set of macros, all beginning
161 @samp{bfd}_.
162
163 For example, this sequence would do what you would probably expect:
164 return the number of sections in an object file attached to a BFD
165 @code{abfd}.
166
167 @lisp
168 @cartouche
169 #include "bfd.h"
170
171 unsigned int number_of_sections(abfd)
172 bfd *abfd;
173 @{
174 return bfd_count_sections(abfd);
175 @}
176 @end cartouche
177 @end lisp
178
179 The abstraction used within BFD is that an object file has a header,
180 a number of sections containing raw data, a set of relocations, and some
181 symbol information. Also, BFDs opened for archives have the
182 additional attribute of an index and contain subordinate BFDs. This approach is
183 fine for a.out and coff, but loses efficiency when applied to formats
184 such as S-records and IEEE-695.
185
186 @section What BFD Version 1 Can Do
187 As different information from the the object files is required,
188 BFD reads from different sections of the file and processes them.
189 For example a very common operation for the linker is processing symbol
190 tables. Each BFD back end provides a routine for converting
191 between the object file's representation of symbols and an internal
192 canonical format. When the linker asks for the symbol table of an object
193 file, it calls through the memory pointer to the relevant BFD
194 back end routine which reads and converts the table into a canonical
195 form. The linker then operates upon the canonical form. When the link is
196 finished and the linker writes the output file's symbol table,
197 another BFD back end routine is called which takes the newly
198 created symbol table and converts it into the chosen output format.
199
200 @node BFD information loss, Mechanism, BFD outline, BFD
201 @subsection Information Loss
202 @emph{Some information is lost due to the nature of the file format.} The output targets
203 supported by BFD do not provide identical facilities, and
204 information which may be described in one form has nowhere to go in
205 another format. One example of this is alignment information in
206 @code{b.out}. There is nowhere in an @code{a.out} format file to store
207 alignment information on the contained data, so when a file is linked
208 from @code{b.out} and an @code{a.out} image is produced, alignment
209 information will not propagate to the output file. (The linker will
210 still use the alignment information internally, so the link is performed
211 correctly).
212
213 Another example is COFF section names. COFF files may contain an
214 unlimited number of sections, each one with a textual section name. If
215 the target of the link is a format which does not have many sections (eg
216 @code{a.out}) or has sections without names (eg the Oasys format) the
217 link cannot be done simply. You can circumvent this problem by
218 describing the desired input-to-output section mapping with the linker command
219 language.
220
221 @emph{Information can be lost during canonicalization.} The BFD
222 internal canonical form of the external formats is not exhaustive; there
223 are structures in input formats for which there is no direct
224 representation internally. This means that the BFD back ends
225 cannot maintain all possible data richness through the transformation
226 between external to internal and back to external formats.
227
228 This limitation is only a problem when using the linker to read one
229 format and write another. Each BFD back end is responsible for
230 maintaining as much data as possible, and the internal BFD
231 canonical form has structures which are opaque to the BFD core,
232 and exported only to the back ends. When a file is read in one format,
233 the canonical form is generated for BFD and the linker. At the
234 same time, the back end saves away any information which may otherwise
235 be lost. If the data is then written back in the same format, the back
236 end routine will be able to use the canonical form provided by the
237 BFD core as well as the information it prepared earlier. Since
238 there is a great deal of commonality between back ends, this mechanism
239 is very useful. There is no information lost for this reason when
240 linking big endian COFF to little endian COFF, or from @code{a.out} to
241 @code{b.out}. When a mixture of formats is linked, the information is
242 only lost from the files whose format differs from the destination.
243
244 @node Mechanism, , BFD information loss, BFD
245 @subsection Mechanism
246 The greatest potential for loss of information is when there is least
247 overlap between the information provided by the source format, that
248 stored by the canonical format, and the information needed by the
249 destination format. A brief description of the canonical form may help
250 you appreciate what kinds of data you can count on preserving across
251 conversions.
252 @cindex BFD canonical format
253 @cindex internal object-file format
254
255 @table @emph
256 @item files
257 Information on target machine architecture, particular implementation
258 and format type are stored on a per-file basis. Other information
259 includes a demand pageable bit and a write protected bit. Note that
260 information like Unix magic numbers is not stored here---only the magic
261 numbers' meaning, so a @code{ZMAGIC} file would have both the demand pageable
262 bit and the write protected text bit set.
263
264 The byte order of the target is stored on a per-file basis, so that big-
265 and little-endian object files may be linked with one another.
266
267 @item sections
268 Each section in the input file contains the name of the section, the
269 original address in the object file, various flags, size and alignment
270 information and pointers into other BFD data structures.
271
272 @item symbols
273 Each symbol contains a pointer to the object file which originally
274 defined it, its name, its value, and various flag bits. When a
275 BFD back end reads in a symbol table, the back end relocates all
276 symbols to make them relative to the base of the section where they were
277 defined. This ensures that each symbol points to its containing
278 section. Each symbol also has a varying amount of hidden data to contain
279 private data for the BFD back end. Since the symbol points to the
280 original file, the private data format for that symbol is accessible.
281 @code{gld} can operate on a collection of symbols of wildly different
282 formats without problems.
283
284 Normal global and simple local symbols are maintained on output, so an
285 output file (no matter its format) will retain symbols pointing to
286 functions and to global, static, and common variables. Some symbol
287 information is not worth retaining; in @code{a.out} type information is
288 stored in the symbol table as long symbol names.
289 @c FIXME: is the enclosed text linker-specific?
290 This information would
291 be useless to most COFF debuggers and may be thrown away with
292 appropriate command line switches. (The GNU debugger @code{gdb} does
293 support @code{a.out} style debugging information in COFF).
294 @c end linker-query FIXME
295
296 There is one word of type information within the symbol, so if the
297 format supports symbol type information within symbols (for example COFF,
298 IEEE, Oasys) and the type is simple enough to fit within one word
299 (nearly everything but aggregates) the information will be preserved.
300
301 @item relocation level
302 Each canonical BFD relocation record contains a pointer to the symbol to
303 relocate to, the offset of the data to relocate, the section the data
304 is in and a pointer to a relocation type descriptor. Relocation is
305 performed effectively by message passing through the relocation type
306 descriptor and symbol pointer. It allows relocations to be performed
307 on output data using a relocation method only available in one of the
308 input formats. For instance, Oasys provides a byte relocation format.
309 A relocation record requesting this relocation type would point
310 indirectly to a routine to perform this, so the relocation may be
311 performed on a byte being written to a COFF file, even though 68k COFF
312 has no such relocation type.
313
314 @item line numbers
315 Object formats can contain, for debugging purposes, some form of mapping
316 between symbols, source line numbers, and addresses in the output file.
317 These addresses have to be relocated along with the symbol information.
318 Each symbol with an associated list of line number records points to the
319 first record of the list. The head of a line number list consists of a
320 pointer to the symbol, which allows divination of the address of the
321 function whose line number is being described. The rest of the list is
322 made up of pairs: offsets into the section and line numbers. Any format
323 which can simply derive this information can pass it successfully
324 between formats (COFF, IEEE and Oasys).
325 @end table
326
327
328 What is a backend
329 @node BFD front end, BFD back end, Mechanism, Top
330 @page
331 @chapter BFD front end
332 @include bfd.texi
333 @page
334 @node Memory Usage, Sections, bfd, Top
335 @section Memory Usage
336 BFD keeps all its internal structures in obstacks. There is one obstack
337 per open BFD file, into which the current state is stored. When a BFD is
338 closed, the obstack is deleted, and so everything which has been
339 allocated by libbfd for the closing file will be thrown away.
340
341 BFD will not free anything created by an application, but pointers into
342 @code{bfd} structures will be invalidated on a @code{bfd_close}; for example,
343 after a @code{bfd_close} the vector passed to
344 @code{bfd_canonicalize_symtab} will still be around, since it has been
345 allocated by the application, but the data that it pointed to will be
346 lost.
347
348 The general rule is not to close a BFD until all operations dependent
349 upon data from the BFD have been completed, or all the data from within
350 the file has been copied. To help with the management of memory, there is a function
351 (@code{bfd_alloc_size}) which returns the number of bytes in obstacks
352 associated with the supplied BFD. This could be used to select the
353 greediest open BFD, close it to reclaim the memory, perform some
354 operation and reopen the BFD again, to get a fresh copy of the data structures.
355
356 @node Sections,Symbols ,Memory Usage, Top
357 @include section.texi
358 @page
359 @node Symbols, Archives ,Sections, To
360 @include syms.texi
361 @page
362 @node Archives, Formats, Symbols, Top
363 @include archive.texi
364 @page
365 @node Formats, Relocations, Archives, Top
366 @include format.texi
367 @page
368 @node Relocations, Core Files,Formats, Top
369 @include reloc.texi
370 @page
371 @node Core Files, Targets, Relocations, Top
372 @include core.texi
373 @page
374 @node Targets, Architectures, Core Files, Top
375 @include targets.texi
376 @page
377 @node Architectures, Opening and Closing, Targets, Top
378 @include archures.texi
379 @page
380 @node Opening and Closing, Internal, Architectures, Top
381 @include opncls.texi
382 @page
383 @node Internal, File Caching, Opening and Closing, Top
384 @include libbfd.texi
385 @page
386 @node File Caching, Top, Internal, Top
387 @include cache.texi
388 @page
389 @chapter BFD back end
390 @node BFD back end, ,BFD front end, Top
391 @menu
392 * What to put where
393 * a.out backends::
394 * coff backends::
395 * oasys backend::
396 * ieee backend::
397 * srecord backend::
398 @end menu
399 @node What to Put Where, aout backends, BFD back end, BFD back end
400 All of BFD lives in one directory.
401 @page
402 @node aout backends, coff backends, What to Put Where, BFD back end
403 @include aoutx.texi
404 @page
405 @node coff backends, oasys backends, aout backends, BFD back end
406 @include coffcode.texi
407 @page
408 @node Index, , BFD, Top
409 @unnumbered Function Index
410 @printindex fn
411 @setchapternewpage on
412 @unnumbered Index
413 @printindex cp
414
415 @tex
416 % I think something like @colophon should be in texinfo. In the
417 % meantime:
418 \long\def\colophon{\hbox to0pt{}\vfill
419 \centerline{The body of this manual is set in}
420 \centerline{\fontname\tenrm,}
421 \centerline{with headings in {\bf\fontname\tenbf}}
422 \centerline{and examples in {\tt\fontname\tentt}.}
423 \centerline{{\it\fontname\tenit\/} and}
424 \centerline{{\sl\fontname\tensl\/}}
425 \centerline{are used for emphasis.}\vfill}
426 \page\colophon
427 % Blame: pesch@cygnus.com, 28mar91.
428 @end tex
429
430
431 @contents
432 @bye
433
434
This page took 0.050048 seconds and 3 git commands to generate.