Commit 2c491451 authored by Tristan Gingold's avatar Tristan Gingold
Browse files

Add generated files

parent 30788923
@section a.out backends
BFD supports a number of different flavours of a.out format,
though the major differences are only the sizes of the
structures on disk, and the shape of the relocation
The support is split into a basic support file @file{aoutx.h}
and other files which derive functions from the base. One
derivation file is @file{aoutf1.h} (for a.out flavour 1), and
adds to the basic a.out functions support for sun3, sun4, 386
and 29k a.out files, to create a target jump vector for a
specific target.
This information is further split out into more specific files
for each machine, including @file{sunos.c} for sun3 and sun4,
@file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
demonstration of a 64 bit a.out format.
The base file @file{aoutx.h} defines general mechanisms for
reading and writing records to and from disk and various
other methods which BFD requires. It is included by
@file{aout32.c} and @file{aout64.c} to form the names
@code{aout_32_swap_exec_header_in}, @code{aout_64_swap_exec_header_in}, etc.
As an example, this is what goes on to make the back end for a
sun4, from @file{aout32.c}:
#define ARCH_SIZE 32
#include "aoutx.h"
@end example
Which exports names:
@end example
from @file{sunos.c}:
#define TARGET_NAME "a.out-sunos-big"
#define VECNAME sparc_aout_sunos_be_vec
#include "aoutf1.h"
@end example
requires all the names from @file{aout32.c}, and produces the jump vector
@end example
The file @file{host-aout.c} is a special case. It is for a large set
of hosts that use ``more or less standard'' a.out files, and
for which cross-debugging is not interesting. It uses the
standard 32-bit a.out support routines, but determines the
file offsets and addresses of the text, data, and BSS
sections, the machine architecture and machine type, and the
entry point address, in a host-dependent manner. Once these
values have been determined, generic code is used to handle
the object file.
When porting it to run on a new system, you must supply:
@end example
in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
values, plus the structures and macros defined in @file{a.out.h} on
your host system, will produce a BFD target that will access
ordinary a.out files on your host. To configure a new machine
to use @file{host-aout.c}, specify:
TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
TDEPFILES= host-aout.o trad-core.o
@end example
in the @file{config/@var{XXX}.mt} file, and modify @file{}
to use the
@file{@var{XXX}.mt} file (by setting "@code{bfd_target=XXX}") when your
configuration is selected.
@subsection Relocations
The file @file{aoutx.h} provides for both the @emph{standard}
and @emph{extended} forms of a.out relocation records.
The standard records contain only an
address, a symbol index, and a type field. The extended records
(used on 29ks and sparcs) also have a full integer for an
@subsection Internal entry points
@file{aoutx.h} exports several routines for accessing the
contents of an a.out file, which are gathered and exported in
turn by various format specific files (eg sunos.c).
@findex aout_@var{size}_swap_exec_header_in
@subsubsection @code{aout_@var{size}_swap_exec_header_in}
void aout_@var{size}_swap_exec_header_in,
(bfd *abfd,
struct external_exec *bytes,
struct internal_exec *execp);
@end example
Swap the information in an executable header @var{raw_bytes} taken
from a raw byte stream memory image into the internal exec header
structure @var{execp}.
@findex aout_@var{size}_swap_exec_header_out
@subsubsection @code{aout_@var{size}_swap_exec_header_out}
void aout_@var{size}_swap_exec_header_out
(bfd *abfd,
struct internal_exec *execp,
struct external_exec *raw_bytes);
@end example
Swap the information in an internal exec header structure
@var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
@findex aout_@var{size}_some_aout_object_p
@subsubsection @code{aout_@var{size}_some_aout_object_p}
const bfd_target *aout_@var{size}_some_aout_object_p
(bfd *abfd,
struct internal_exec *execp,
const bfd_target *(*callback_to_real_object_p) (bfd *));
@end example
Some a.out variant thinks that the file open in @var{abfd}
checking is an a.out file. Do some more checking, and set up
for access if it really is. Call back to the calling
environment's "finish up" function just before returning, to
handle any last-minute setup.
@findex aout_@var{size}_mkobject
@subsubsection @code{aout_@var{size}_mkobject}
bfd_boolean aout_@var{size}_mkobject, (bfd *abfd);
@end example
Initialize BFD @var{abfd} for use with a.out files.
@findex aout_@var{size}_machine_type
@subsubsection @code{aout_@var{size}_machine_type}
enum machine_type aout_@var{size}_machine_type
(enum bfd_architecture arch,
unsigned long machine,
bfd_boolean *unknown);
@end example
Keep track of machine architecture and machine type for
a.out's. Return the @code{machine_type} for a particular
architecture and machine, or @code{M_UNKNOWN} if that exact architecture
and machine can't be represented in a.out format.
If the architecture is understood, machine type 0 (default)
is always understood.
@findex aout_@var{size}_set_arch_mach
@subsubsection @code{aout_@var{size}_set_arch_mach}
bfd_boolean aout_@var{size}_set_arch_mach,
(bfd *,
enum bfd_architecture arch,
unsigned long machine);
@end example
Set the architecture and the machine of the BFD @var{abfd} to the
values @var{arch} and @var{machine}. Verify that @var{abfd}'s format
can support the architecture required.
@findex aout_@var{size}_new_section_hook
@subsubsection @code{aout_@var{size}_new_section_hook}
bfd_boolean aout_@var{size}_new_section_hook,
(bfd *abfd,
asection *newsect);
@end example
Called by the BFD in response to a @code{bfd_make_section}
@section Archives
An archive (or library) is just another BFD. It has a symbol
table, although there's not much a user program will do with it.
The big difference between an archive BFD and an ordinary BFD
is that the archive doesn't have sections. Instead it has a
chain of BFDs that are considered its contents. These BFDs can
be manipulated like any other. The BFDs contained in an
archive opened for reading will all be opened for reading. You
may put either input or output BFDs into an archive opened for
output; they will be handled correctly when the archive is closed.
Use @code{bfd_openr_next_archived_file} to step through
the contents of an archive opened for input. You don't
have to read the entire archive if you don't want
to! Read it until you find what you want.
A BFD returned by @code{bfd_openr_next_archived_file} can be
closed manually with @code{bfd_close}. If you do not close it,
then a second iteration through the members of an archive may
return the same BFD. If you close the archive BFD, then all
the member BFDs will automatically be closed as well.
Archive contents of output BFDs are chained through the
@code{archive_next} pointer in a BFD. The first one is findable
through the @code{archive_head} slot of the archive. Set it with
@code{bfd_set_archive_head} (q.v.). A given BFD may be in only
one open output archive at a time.
As expected, the BFD archive code is more general than the
archive code of any given environment. BFD archives may
contain files of different formats (e.g., a.out and coff) and
even different architectures. You may even place archives
recursively into archives!
This can cause unexpected confusion, since some archive
formats are more expressive than others. For instance, Intel
COFF archives can preserve long filenames; SunOS a.out archives
cannot. If you move a file from the first to the second
format and back again, the filename may be truncated.
Likewise, different a.out environments have different
conventions as to how they truncate filenames, whether they
preserve directory names in filenames, etc. When
interoperating with native tools, be sure your files are
Beware: most of these formats do not react well to the
presence of spaces in filenames. We do the best we can, but
can't always handle this case due to restrictions in the format of
archives. Many Unix utilities are braindead in regards to
spaces and such in filenames anyway, so this shouldn't be much
of a restriction.
Archives are supported in BFD in @code{archive.c}.
@subsection Archive functions
@findex bfd_get_next_mapent
@subsubsection @code{bfd_get_next_mapent}
symindex bfd_get_next_mapent
(bfd *abfd, symindex previous, carsym **sym);
@end example
Step through archive @var{abfd}'s symbol table (if it
has one). Successively update @var{sym} with the next symbol's
information, returning that symbol's (internal) index into the
symbol table.
Supply @code{BFD_NO_MORE_SYMBOLS} as the @var{previous} entry to get
the first one; returns @code{BFD_NO_MORE_SYMBOLS} when you've already
got the last one.
A @code{carsym} is a canonical archive symbol. The only
user-visible element is its name, a null-terminated string.
@findex bfd_set_archive_head
@subsubsection @code{bfd_set_archive_head}
bfd_boolean bfd_set_archive_head (bfd *output, bfd *new_head);
@end example
Set the head of the chain of
BFDs contained in the archive @var{output} to @var{new_head}.
@findex bfd_openr_next_archived_file
@subsubsection @code{bfd_openr_next_archived_file}
bfd *bfd_openr_next_archived_file (bfd *archive, bfd *previous);
@end example
Provided a BFD, @var{archive}, containing an archive and NULL, open
an input BFD on the first contained element and returns that.
Subsequent calls should pass
the archive and the previous return value to return a created
BFD to the next contained element. NULL is returned when there
are no more.
This diff is collapsed.
This diff is collapsed.
@findex struct bfd_iovec
@subsubsection @code{struct bfd_iovec}
The @code{struct bfd_iovec} contains the internal file I/O class.
Each @code{BFD} has an instance of this class and all file I/O is
routed through it (it is assumed that the instance implements
all methods listed below).
struct bfd_iovec
/* To avoid problems with macros, a "b" rather than "f"
prefix is prepended to each method name. */
/* Attempt to read/write NBYTES on ABFD's IOSTREAM storing/fetching
bytes starting at PTR. Return the number of bytes actually
transfered (a read past end-of-file returns less than NBYTES),
or -1 (setting @code{bfd_error}) if an error occurs. */
file_ptr (*bread) (struct bfd *abfd, void *ptr, file_ptr nbytes);
file_ptr (*bwrite) (struct bfd *abfd, const void *ptr,
file_ptr nbytes);
/* Return the current IOSTREAM file offset, or -1 (setting @code{bfd_error}
if an error occurs. */
file_ptr (*btell) (struct bfd *abfd);
/* For the following, on successful completion a value of 0 is returned.
Otherwise, a value of -1 is returned (and @code{bfd_error} is set). */
int (*bseek) (struct bfd *abfd, file_ptr offset, int whence);
int (*bclose) (struct bfd *abfd);
int (*bflush) (struct bfd *abfd);
int (*bstat) (struct bfd *abfd, struct stat *sb);
/* Mmap a part of the files. ADDR, LEN, PROT, FLAGS and OFFSET are the usual
mmap parameter, except that LEN and OFFSET do not need to be page
aligned. Returns (void *)-1 on failure, mmapped address on success.
Also write in MAP_ADDR the address of the page aligned buffer and in
MAP_LEN the size mapped (a page multiple). Use unmap with MAP_ADDR and
MAP_LEN to unmap. */
void *(*bmmap) (struct bfd *abfd, void *addr, bfd_size_type len,
int prot, int flags, file_ptr offset,
void **map_addr, bfd_size_type *map_len);
extern const struct bfd_iovec _bfd_memory_iovec;
@end example
@findex bfd_get_mtime
@subsubsection @code{bfd_get_mtime}
long bfd_get_mtime (bfd *abfd);
@end example
Return the file modification time (as read from the file system, or
from the archive header for archive members).
@findex bfd_get_size
@subsubsection @code{bfd_get_size}
file_ptr bfd_get_size (bfd *abfd);
@end example
Return the file size (as read from file system) for the file
associated with BFD @var{abfd}.
The initial motivation for, and use of, this routine is not
so we can get the exact size of the object the BFD applies to, since
that might not be generally possible (archive members for example).
It would be ideal if someone could eventually modify
it so that such results were guaranteed.
Instead, we want to ask questions like "is this NNN byte sized
object I'm about to try read from file offset YYY reasonable?"
As as example of where we might do this, some object formats
use string tables for which the first @code{sizeof (long)} bytes of the
table contain the size of the table itself, including the size bytes.
If an application tries to read what it thinks is one of these
string tables, without some way to validate the size, and for
some reason the size is wrong (byte swapping error, wrong location
for the string table, etc.), the only clue is likely to be a read
error when it tries to read the table, or a "virtual memory
exhausted" error when it tries to allocate 15 bazillon bytes
of space for the 15 bazillon byte table it is about to read.
This function at least allows us to answer the question, "is the
size reasonable?".
@findex bfd_mmap
@subsubsection @code{bfd_mmap}
void *bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
int prot, int flags, file_ptr offset,
void **map_addr, bfd_size_type *map_len);
@end example
Return mmap()ed region of the file, if possible and implemented.
LEN and OFFSET do not need to be page aligned. The page aligned
address and length are written to MAP_ADDR and MAP_LEN.
This diff is collapsed.
@set VERSION 2.26
@set UPDATED January 2016
@set BUGURL @uref{}
@subsubsection @code{}
@section File caching
The file caching mechanism is embedded within BFD and allows
the application to open as many BFDs as it wants without
regard to the underlying operating system's file descriptor
limit (often as low as 20 open files). The module in
@code{cache.c} maintains a least recently used list of
@code{bfd_cache_max_open} files, and exports the name
@code{bfd_cache_lookup}, which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file
@subsection Caching functions
@findex bfd_cache_init
@subsubsection @code{bfd_cache_init}
bfd_boolean bfd_cache_init (bfd *abfd);
@end example
Add a newly opened BFD to the cache.
@findex bfd_cache_close
@subsubsection @code{bfd_cache_close}
bfd_boolean bfd_cache_close (bfd *abfd);
@end example
Remove the BFD @var{abfd} from the cache. If the attached file is open,
then close it too.
@code{FALSE} is returned if closing the file fails, @code{TRUE} is
returned if all is well.
@findex bfd_cache_close_all
@subsubsection @code{bfd_cache_close_all}
bfd_boolean bfd_cache_close_all (void);
@end example
Remove all BFDs from the cache. If the attached file is open,
then close it too.
@code{FALSE} is returned if closing one of the file fails, @code{TRUE} is
returned if all is well.
@findex bfd_open_file
@subsubsection @code{bfd_open_file}
FILE* bfd_open_file (bfd *abfd);
@end example
Call the OS to open a file for @var{abfd}. Return the @code{FILE *}
(possibly @code{NULL}) that results from this operation. Set up the
BFD so that future accesses know the file is open. If the @code{FILE *}
returned is @code{NULL}, then it won't have been put in the
cache, so it won't have to be removed from it.
This diff is collapsed.
@section Core files
@subsection Core file functions
These are functions pertaining to core files.
@findex bfd_core_file_failing_command
@subsubsection @code{bfd_core_file_failing_command}
const char *bfd_core_file_failing_command (bfd *abfd);
@end example
Return a read-only string explaining which program was running
when it failed and produced the core file @var{abfd}.
@findex bfd_core_file_failing_signal
@subsubsection @code{bfd_core_file_failing_signal}
int bfd_core_file_failing_signal (bfd *abfd);
@end example
Returns the signal number which caused the core dump which
generated the file the BFD @var{abfd} is attached to.
@findex bfd_core_file_pid
@subsubsection @code{bfd_core_file_pid}
int bfd_core_file_pid (bfd *abfd);
@end example
Returns the PID of the process the core dump the BFD
@var{abfd} is attached to was generated from.
@findex core_file_matches_executable_p
@subsubsection @code{core_file_matches_executable_p}
bfd_boolean core_file_matches_executable_p
(bfd *core_bfd, bfd *exec_bfd);
@end example
Return @code{TRUE} if the core file attached to @var{core_bfd}
was generated by a run of the executable file attached to
@var{exec_bfd}, @code{FALSE} otherwise.
@findex generic_core_file_matches_executable_p
@subsubsection @code{generic_core_file_matches_executable_p}
bfd_boolean generic_core_file_matches_executable_p
(bfd *core_bfd, bfd *exec_bfd);
@end example
Return TRUE if the core file attached to @var{core_bfd}
was generated by a run of the executable file attached
to @var{exec_bfd}. The match is based on executable
basenames only.
Note: When not able to determine the core file failing
command or the executable name, we still return TRUE even
though we're not sure that core file and executable match.
This is to avoid generating a false warning in situations
where we really don't know whether they match or not.
@section ELF backends
BFD support for ELF formats is being worked on.
Currently, the best supported back ends are for sparc and i386
(running svr4 or Solaris 2).
Documentation of the internals of the support code still needs
to be written. The code is changing quickly enough that we
haven't bothered yet.
@section File formats
A format is a BFD concept of high level file contents type. The
formats supported by BFD are:
@itemize @bullet
@end itemize
The BFD may contain data, symbols, relocations and debug info.
@itemize @bullet
@end itemize
The BFD contains other BFDs and an optional index.
@itemize @bullet
@end itemize
The BFD contains the result of an executable core dump.
@subsection File format functions
@findex bfd_check_format
@subsubsection @code{bfd_check_format}
bfd_boolean bfd_check_format (bfd *abfd, bfd_format format);
@end example
Verify if the file attached to the BFD @var{abfd} is compatible
with the format @var{format} (i.e., one of @code{bfd_object},
@code{bfd_archive} or @code{bfd_core}).
If the BFD has been set to a specific target before the
call, only the named target and format combination is
checked. If the target has not been set, or has been set to
@code{default}, then all the known target backends is
interrogated to determine a match. If the default target
matches, it is used. If not, exactly one target must recognize
the file, or an error results.
The function returns @code{TRUE} on success, otherwise @code{FALSE}
with one of the following error codes:
@itemize @bullet
@code{bfd_error_invalid_operation} -
if @code{format} is not one of @code{bfd_object}, @code{bfd_archive} or
@code{bfd_error_system_call} -
if an error occured during a read - even some file mismatches
can cause bfd_error_system_calls.
@code{file_not_recognised} -
none of the backends recognised the file format.
@code{bfd_error_file_ambiguously_recognized} -
more than one backend recognised the file format.
@end itemize
@findex bfd_check_format_matches
@subsubsection @code{bfd_check_format_matches}
bfd_boolean bfd_check_format_matches
(bfd *abfd, bfd_format format, char ***matching);
@end example