5. Files compiled multiple times in BFD
Several files in BFD are compiled multiple times. By this I mean that
there are header files which contain function definitions. These header
files are included by other files, and thus the functions are compiled
once per file which includes them.
Preprocessor macros are used to control the compilation, so that each
time the files are compiled the resulting functions are slightly
different. Naturally, if they weren't different, there would be no
reason to compile them multiple times.
This is a not a particularly good programming technique, and future BFD
work should avoid it.
-
Since this technique is rarely used, even experienced C programmers find
it confusing.
-
It is difficult to debug programs which use BFD, since there is no way
to describe which version of a particular function you are looking at.
-
Programs which use BFD wind up incorporating two or more slightly
different versions of the same function, which wastes space in the
executable.
-
This technique is never required nor is it especially efficient. It is
always possible to use statically initialized structures holding
function pointers and magic constants instead.
The following is a list of the files which are compiled multiple times.
- `aout-target.h'
-
Describes a few functions and the target vector for a.out targets. This
is used by individual a.out targets with different definitions of
`N_TXTADDR' and similar a.out macros.
- `aoutf1.h'
-
Implements standard SunOS a.out files. In principle it supports 64 bit
a.out targets based on the preprocessor macro `ARCH_SIZE', but
since all known a.out targets are 32 bits, this code may or may not
work. This file is only included by a few other files, and it is
difficult to justify its existence.
- `aoutx.h'
-
Implements basic a.out support routines. This file can be compiled for
either 32 or 64 bit support. Since all known a.out targets are 32 bits,
the 64 bit support may or may not work. I believe the original
intention was that this file would only be included by `aout32.c'
and `aout64.c', and that other a.out targets would simply refer to
the functions it defined. Unfortunately, some other a.out targets
started including it directly, leading to a somewhat confused state of
affairs.
- `coffcode.h'
-
Implements basic COFF support routines. This file is included by every
COFF target. It implements code which handles COFF magic numbers as
well as various hook functions called by the generic COFF functions in
`coffgen.c'. This file is controlled by a number of different
macros, and more are added regularly.
- `coffswap.h'
-
Implements COFF swapping routines. This file is included by
`coffcode.h', and thus by every COFF target. It implements the
routines which swap COFF structures between internal and external
format. The main control for this file is the external structure
definitions in the files in the `include/coff' directory. A COFF
target file will include one of those files before including
`coffcode.h' and thus `coffswap.h'. There are a few other
macros which affect `coffswap.h' as well, mostly describing whether
certain fields are present in the external structures.
- `ecoffswap.h'
-
Implements ECOFF swapping routines. This is like `coffswap.h', but
for ECOFF. It is included by the ECOFF target files (of which there are
only two). The control is the preprocessor macro `ECOFF_32' or
`ECOFF_64'.
- `elfcode.h'
-
Implements ELF functions that use external structure definitions. This
file is included by two other files: `elf32.c' and `elf64.c'.
It is controlled by the `ARCH_SIZE' macro which is defined to be
`32' or `64' before including it. The `NAME' macro is
used internally to give the functions different names for the two target
sizes.
- `elfcore.h'
-
Like `elfcode.h', but for functions that are specific to ELF core
files. This is included only by `elfcode.h'.
- `elfxx-target.h'
-
This file is the source for the generated files `elf32-target.h'
and `elf64-target.h', one of which is included by every ELF target.
It defines the ELF target vector.
- `freebsd.h'
-
Presumably intended to be included by all FreeBSD targets, but in fact
there is only one such target, `i386-freebsd'. This defines a
function used to set the right magic number for FreeBSD, as well as
various macros, and includes `aout-target.h'.
- `netbsd.h'
-
Like `freebsd.h', except that there are several files which include
it.
- `nlm-target.h'
-
Defines the target vector for a standard NLM target.
- `nlmcode.h'
-
Like `elfcode.h', but for NLM targets. This is only included by
`nlm32.c' and `nlm64.c', both of which define the macro
`ARCH_SIZE' to an appropriate value. There are no 64 bit NLM
targets anyhow, so this is sort of useless.
- `nlmswap.h'
-
Like `coffswap.h', but for NLM targets. This is included by each
NLM target, but I think it winds up compiling to the exact same code for
every target, and as such is fairly useless.
- `peicode.h'
-
Provides swapping routines and other hooks for PE targets.
`coffcode.h' will include this rather than `coffswap.h' for a
PE target. This defines PE specific versions of the COFF swapping
routines, and also defines some macros which control `coffcode.h'
itself.
This document was generated
by system on December, 2 2004
using texi2html