]> Git Repo - binutils.git/blame - bfd/doc/bfdint.texi
Tue Apr 28 12:16:57 1998 Jason Molenda ([email protected])
[binutils.git] / bfd / doc / bfdint.texi
CommitLineData
c91a48dd
ILT
1\input texinfo
2@setfilename bfdint.info
3@node Top
4@top BFD Internals
5@raisesections
6@cindex bfd internals
7
8This document describes some BFD internal information which may be
9helpful when working on BFD. It is very incomplete.
10
11This document is not updated regularly, and may be out of date. It was
12last modified on $Date$.
13
14The initial version of this document was written by Ian Lance Taylor
15@email{ian@@cygnus.com}.
16
17@menu
18* BFD glossary:: BFD glossary
19* BFD guidelines:: BFD programming guidelines
20* BFD generated files:: BFD generated files
21* BFD multiple compilations:: Files compiled multiple times in BFD
22* Index:: Index
23@end menu
24
25@node BFD glossary
26@section BFD glossary
27@cindex glossary for bfd
28@cindex bfd glossary
29
30This is a short glossary of some BFD terms.
31
32@table @asis
33@item a.out
34The a.out object file format. The original Unix object file format.
35Still used on SunOS, though not Solaris. Supports only three sections.
36
37@item archive
38A collection of object files produced and manipulated by the @samp{ar}
39program.
40
41@item BFD
42The BFD library itself. Also, each object file, archive, or exectable
43opened by the BFD library has the type @samp{bfd *}, and is sometimes
44referred to as a bfd.
45
46@item COFF
47The Common Object File Format. Used on Unix SVR3. Used by some
48embedded targets, although ELF is normally better.
49
50@item DLL
51A shared library on Windows.
52
53@item dynamic linker
54When a program linked against a shared library is run, the dynamic
55linker will locate the appropriate shared library and arrange to somehow
56include it in the running image.
57
58@item dynamic object
59Another name for an ELF shared library.
60
61@item ECOFF
62The Extended Common Object File Format. Used on Alpha Digital Unix
63(formerly OSF/1), as well as Ultrix and Irix 4. A variant of COFF.
64
65@item ELF
66The Executable and Linking Format. The object file format used on most
67modern Unix systems, including GNU/Linux, Solaris, Irix, and SVR4. Also
68used on many embedded systems.
69
70@item executable
71A program, with instructions and symbols, and perhaps dynamic linking
72information. Normally produced by a linker.
73
74@item NLM
75NetWare Loadable Module. Used to describe the format of an object which
76be loaded into NetWare, which is some kind of PC based network server
77program.
78
79@item object file
80A binary file including machine instructions, symbols, and relocation
81information. Normally produced by an assembler.
82
83@item object file format
84The format of an object file. Typically object files and executables
85for a particular system are in the same format, although executables
86will not contain any relocation information.
87
88@item PE
89The Portable Executable format. This is the object file format used for
90Windows (specifically, Win32) object files. It is based closely on
91COFF, but has a few significant differences.
92
93@item PEI
94The Portable Executable Image format. This is the object file format
95used for Windows (specifically, Win32) executables. It is very similar
96to PE, but includes some additional header information.
97
98@item relocations
99Information used by the linker to adjust section contents.
100
101@item section
102Object files and executable are composed of sections. Sections have
103optional data and optional relocation information.
104
105@item shared library
106A library of functions which may be used by many executables without
107actually being linked into each executable. There are several different
108implementations of shared libraries, each having slightly different
109features.
110
111@item symbol
112Each object file and executable may have a list of symbols, often
113referred to as the symbol table. A symbol is basically a name and an
114address. There may also be some additional information like the type of
115symbol, although the type of a symbol is normally something simple like
116function or object, and should be confused with the more complex C
117notion of type. Typically every global function and variable in a C
118program will have an associated symbol.
119
120@item Win32
121The current Windows API, implemented by Windows 95 and later and Windows
122NT 3.51 and later, but not by Windows 3.1.
123
124@item XCOFF
125The eXtended Common Object File Format. Used on AIX. A variant of
126COFF, with a completely different symbol table implementation.
127@end table
128
129@node BFD guidelines
130@section BFD programming guidelines
131@cindex bfd programming guidelines
132@cindex programming guidelines for bfd
133@cindex guidelines, bfd programming
134
135There is a lot of poorly written and confusing code in BFD. New BFD
136code should be written to a higher standard. Merely because some BFD
137code is written in a particular manner does not mean that you should
138emulate it.
139
140Here are some general BFD programming guidelines:
141
142@itemize @bullet
143@item
144Avoid global variables. We ideally want BFD to be fully reentrant, so
145that it can be used in multiple threads. All uses of global or static
146variables interfere with that. Initialized constant variables are OK,
147and they should be explicitly marked with const. Instead of global
148variables, use data attached to a BFD or to a linker hash table.
149
150@item
151All externally visible functions should have names which start with
152@samp{bfd_}. All such functions should be declared in some header file,
153typically @file{bfd.h}. See, for example, the various declarations near
154the end of @file{bfd-in.h}, which mostly declare functions required by
155specific linker emulations.
156
157@item
158All functions which need to be visible from one file to another within
159BFD, but should not be visible outside of BFD, should start with
160@samp{_bfd_}. Although external names beginning with @samp{_} are
161prohibited by the ANSI standard, in practice this usage will always
162work, and it is required by the GNU coding standards.
163
164@item
165Always remember that people can compile using --enable-targets to build
166several, or all, targets at once. It must be possible to link together
167the files for all targets.
168
169@item
170BFD code should compile with few or no warnings using @samp{gcc -Wall}.
171Some warnings are OK, like the absence of certain function declarations
172which may or may not be declared in system header files. Warnings about
173ambiguous expressions and the like should always be fixed.
174@end itemize
175
176@node BFD generated files
177@section BFD generated files
178@cindex generated files in bfd
179@cindex bfd generated files
180
181BFD contains several automatically generated files. This section
182describes them. Some files are created at configure time, when you
183configure BFD. Some files are created at make time, when you build
184time. Some files are automatically rebuilt at make time, but only if
185you configure with the @samp{--enable-maintainer-mode} option. Some
186files live in the object directory---the directory from which you run
187configure---and some live in the source directory. All files that live
188in the source directory are checked into the CVS repository.
189
190@table @file
191@item bfd.h
192@cindex @file{bfd.h}
193@cindex @file{bfd-in3.h}
194Lives in the object directory. Created at make time from
195@file{bfd-in2.h} via @file{bfd-in3.h}. @file{bfd-in3.h} is created at
196configure time from @file{bfd-in2.h}. There are automatic dependencies
197to rebuild @file{bfd-in3.h} and hence @file{bfd.h} if @file{bfd-in2.h}
198changes, so you can normally ignore @file{bfd-in3.h}, and just think
199about @file{bfd-in2.h} and @file{bfd.h}.
200
201@file{bfd.h} is built by replacing a few strings in @file{bfd-in2.h}.
202To see them, search for @samp{@@} in @file{bfd-in2.h}. They mainly
203control whether BFD is built for a 32 bit target or a 64 bit target.
204
205@item bfd-in2.h
206@cindex @file{bfd-in2.h}
207Lives in the source directory. Created from @file{bfd-in.h} and several
208other BFD source files. If you configure with the
209@samp{--enable-maintainer-mode} option, @file{bfd-in2.h} is rebuilt
210automatically when a source file changes.
211
212@item elf32-target.h
213@itemx elf64-target.h
214@cindex @file{elf32-target.h}
215@cindex @file{elf64-target.h}
216Live in the object directory. Created from @file{elfxx-target.h}.
217These files are versions of @file{elfxx-target.h} customized for either
218a 32 bit ELF target or a 64 bit ELF target.
219
220@item libbfd.h
221@cindex @file{libbfd.h}
222Lives in the source directory. Created from @file{libbfd-in.h} and
223several other BFD source files. If you configure with the
224@samp{--enable-maintainer-mode} option, @file{libbfd.h} is rebuilt
225automatically when a source file changes.
226
227@item libcoff.h
228@cindex @file{libcoff.h}
229Lives in the source directory. Created from @file{libcoff-in.h} and
230@file{coffcode.h}. If you configure with the
231@samp{--enable-maintainer-mode} option, @file{libcoff.h} is rebuilt
232automatically when a source file changes.
233
234@item targmatch.h
235@cindex @file{targmatch.h}
236Lives in the object directory. Created at make time from
237@file{config.bfd}. This file is used to map configuration triplets into
238BFD target vector variable names at run time.
239@end table
240
241@node BFD multiple compilations
242@section Files compiled multiple times in BFD
243Several files in BFD are compiled multiple times. By this I mean that
244there are header files which contain function definitions. These header
245filesare included by other files, and thus the functions are compiled
246once per file which includes them.
247
248Preprocessor macros are used to control the compilation, so that each
249time the files are compiled the resulting functions are slightly
250different. Naturally, if they weren't different, there would be no
251reason to compile them multiple times.
252
253This is a not a particularly good programming technique, and future BFD
254work should avoid it.
255
256@itemize @bullet
257@item
258Since this technique is rarely used, even experienced C programmers find
259it confusing.
260
261@item
262It is difficult to debug programs which use BFD, since there is no way
263to describe which version of a particular function you are looking at.
264
265@item
266Programs which use BFD wind up incorporating two or more slightly
267different versions of the same function, which wastes space in the
268executable.
269
270@item
271This technique is never required nor is it especially efficient. It is
272always possible to use statically initialized structures holding
273function pointers and magic constants instead.
274@end itemize
275
276The following a list of the files which are compiled multiple times.
277
278@table @file
279@item aout-target.h
280@cindex @file{aout-target.h}
281Describes a few functions and the target vector for a.out targets. This
282is used by individual a.out targets with different definitions of
283@samp{N_TXTADDR} and similar a.out macros.
284
285@item aoutf1.h
286@cindex @file{aoutf1.h}
287Implements standard SunOS a.out files. In principle it supports 64 bit
288a.out targets based on the preprocessor macro @samp{ARCH_SIZE}, but
289since all known a.out targets are 32 bits, this code may or may not
290work. This file is only included by a few other files, and it is
291difficult to justify its existence.
292
293@item aoutx.h
294@cindex @file{aoutx.h}
295Implements basic a.out support routines. This file can be compiled for
296either 32 or 64 bit support. Since all known a.out targets are 32 bits,
297the 64 bit support may or may not work. I believe the original
298intention was that this file would only be included by @samp{aout32.c}
299and @samp{aout64.c}, and that other a.out targets would simply refer to
300the functions it defined. Unfortunately, some other a.out targets
301started including it directly, leading to a somewhat confused state of
302affairs.
303
304@item coffcode.h
305@cindex @file{coffcode.h}
306Implements basic COFF support routines. This file is included by every
307COFF target. It implements code which handles COFF magic numbers as
308well as various hook functions called by the generic COFF functions in
309@file{coffgen.c}. This file is controlled by a number of different
310macros, and more are added regularly.
311
312@item coffswap.h
313@cindex @file{coffswap.h}
314Implements COFF swapping routines. This file is included by
315@file{coffcode.h}, and thus by every COFF target. It implements the
316routines which swap COFF structures between internal and external
317format. The main control for this file is the external structure
318definitions in the files in the @file{include/coff} directory. A COFF
319target file will include one of those files before including
320@file{coffcode.h} and thus @file{coffswap.h}. There are a few other
321macros which affect @file{coffswap.h} as well, mostly describing whether
322certain fields are present in the external structures.
323
324@item ecoffswap.h
325@cindex @file{ecoffswap.h}
326Implements ECOFF swapping routines. This is like @file{coffswap.h}, but
327for ECOFF. It is included by the ECOFF target files (of which there are
328only two). The control is the preprocessor macro @samp{ECOFF_32} or
329@samp{ECOFF_64}.
330
331@item elfcode.h
332@cindex @file{elfcode.h}
333Implements ELF functions that use external structure definitions. This
334file is included by two other files: @file{elf32.c} and @file{elf64.c}.
335It is controlled by the @samp{ARCH_SIZE} macro which is defined to be
336@samp{32} or @samp{64} before including it. The @samp{NAME} macro is
337used internally to give the functions different names for the two target
338sizes.
339
340@item elfcore.h
341@cindex @file{elfcore.h}
342Like @file{elfcode.h}, but for functions that are specific to ELF core
343files. This is included only by @file{elfcode.h}.
344
345@item elflink.h
346@cindex @file{elflink.h}
347Like @file{elfcode.h}, but for functions used by the ELF linker. This
348is included only by @file{elfcode.h}.
349
350@item elfxx-target.h
351@cindex @file{elfxx-target.h}
352This file is the source for the generated files @file{elf32-target.h}
353and @file{elf64-target.h}, one of which is included by every ELF target.
354It defines the ELF target vector.
355
356@item freebsd.h
357@cindex @file{freebsd.h}
358Presumably intended to be included by all FreeBSD targets, but in fact
359there is only one such target, @samp{i386-freebsd}. This defines a
360function used to set the right magic number for FreeBSD, as well as
361various macros, and includes @file{aout-target.h}.
362
363@item netbsd.h
364@cindex @file{netbsd.h}
365Like @file{freebsd.h}, except that there are several files which include
366it.
367
368@item nlm-target.h
369@cindex @file{nlm-target.h}
370Defines the target vector for a standard NLM target.
371
372@item nlmcode.h
373@cindex @file{nlmcode.h}
374Like @file{elfcode.h}, but for NLM targets. This is only included by
375@file{nlm32.c} and @file{nlm64.c}, both of which define the macro
376@samp{ARCH_SIZE} to an appropriate value. There are no 64 bit NLM
377targets anyhow, so this is sort of useless.
378
379@item nlmswap.h
380@cindex @file{nlmswap.h}
381Like @file{coffswap.h}, but for NLM targets. This is included by each
382NLM target, but I think it winds up compiling to the exact same code for
383every target, and as such is fairly useless.
384
385@item peicode.h
386@cindex @file{peicode.h}
387Provides swapping routines and other hooks for PE targets.
388@file{coffcode.h} will include this rather than @file{coffswap.h} for a
389PE target. This defines PE specific versions of the COFF swapping
390routines, and also defines some macros which control @file{coffcode.h}
391itself.
392@end table
393
394@node Index
395@unnumberedsec Index
396@printindex cp
397
398@contents
399@bye
This page took 0.060006 seconds and 4 git commands to generate.