doc cleanup

This commit is contained in:
David MacKenzie 1993-11-05 19:51:52 +00:00
parent 5090e82cca
commit c188b0bec3
19 changed files with 1524 additions and 1144 deletions

View File

@ -1,3 +1,13 @@
Fri Nov 5 10:41:07 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* aoutx.h, archive.c, archures.c, bfd.c, cache.c, coffcode.h,
core.c, ctor.c, format.c, init.c, libbfd.c, opncls.c, reloc.c,
section.c, syms.c, targets.c:
Doc cleanup (spelling, punctuation, grammar, formatting).
* bfd-in2.h, libbfd.h: Rebuild.
* reloc.c (bfd_get_reloc_upper_bound, bfd_canonicalize_reloc,
bfd_set_reloc): Moved from bfd.c.
Thu Nov 4 14:46:14 1993 John Gilmore (gnu@rtl.cygnus.com) Thu Nov 4 14:46:14 1993 John Gilmore (gnu@rtl.cygnus.com)
* bfd-in.h (bfd_get_cacheable, bfd_set_cacheable): New accessors. * bfd-in.h (bfd_get_cacheable, bfd_set_cacheable): New accessors.
@ -75,6 +85,10 @@ Sun Oct 31 09:35:49 1993 Jim Kingdon (kingdon@lioth.cygnus.com)
* som.c: Add comment about how abort() on corrupt executable is evil. * som.c: Add comment about how abort() on corrupt executable is evil.
Sat Oct 30 12:27:09 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* aoutx.h (aout,slurp_reloc_table): Avoid a goto.
Fri Oct 29 16:04:33 1993 David J. Mackenzie (djm@thepub.cygnus.com) Fri Oct 29 16:04:33 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* gen-aout.c, libbfd.c: exit(1) instead of exit(-1). * gen-aout.c, libbfd.c: exit(1) instead of exit(-1).

View File

@ -30,26 +30,26 @@ DESCRIPTION
structures on disk, and the shape of the relocation structures on disk, and the shape of the relocation
information. information.
The support is split into a basic support file @code{aoutx.h} The support is split into a basic support file @file{aoutx.h}
and other files which derive functions from the base. One and other files which derive functions from the base. One
derivation file is @code{aoutf1.h} (for a.out flavour 1), and derivation file is @file{aoutf1.h} (for a.out flavour 1), and
adds to the basic a.out functions support for sun3, sun4, 386 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 and 29k a.out files, to create a target jump vector for a
specific target. specific target.
This information is further split out into more specific files This information is further split out into more specific files
for each machine, including @code{sunos.c} for sun3 and sun4, for each machine, including @file{sunos.c} for sun3 and sun4,
@code{newsos3.c} for the Sony NEWS, and @code{demo64.c} for a @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
demonstration of a 64 bit a.out format. demonstration of a 64 bit a.out format.
The base file @code{aoutx.h} defines general mechanisms for The base file @file{aoutx.h} defines general mechanisms for
reading and writing records to and from disk, and various reading and writing records to and from disk and various
other methods which BFD requires. It is included by other methods which BFD requires. It is included by
@code{aout32.c} and @code{aout64.c} to form the names @file{aout32.c} and @file{aout64.c} to form the names
aout_32_swap_exec_header_in, aout_64_swap_exec_header_in, etc. <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc.
As an example, this is what goes on to make the back end for a As an example, this is what goes on to make the back end for a
sun4, from aout32.c sun4, from @file{aout32.c}:
| #define ARCH_SIZE 32 | #define ARCH_SIZE 32
| #include "aoutx.h" | #include "aoutx.h"
@ -63,18 +63,18 @@ DESCRIPTION
| aout_32_get_reloc_upper_bound | aout_32_get_reloc_upper_bound
| ... | ...
from sunos.c from @file{sunos.c}:
| #define ARCH 32 | #define ARCH 32
| #define TARGET_NAME "a.out-sunos-big" | #define TARGET_NAME "a.out-sunos-big"
| #define VECNAME sunos_big_vec | #define VECNAME sunos_big_vec
| #include "aoutf1.h" | #include "aoutf1.h"
requires all the names from aout32.c, and produces the jump vector requires all the names from @file{aout32.c}, and produces the jump vector
| sunos_big_vec | sunos_big_vec
The file host-aout.c is a special case. It is for a large set 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 of hosts that use ``more or less standard'' a.out files, and
for which cross-debugging is not interesting. It uses the for which cross-debugging is not interesting. It uses the
standard 32-bit a.out support routines, but determines the standard 32-bit a.out support routines, but determines the
@ -102,7 +102,7 @@ DESCRIPTION
| TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
| TDEPFILES= host-aout.o trad-core.o | TDEPFILES= host-aout.o trad-core.o
in the <<config/mt-XXX>> file, and modify configure.in to use the in the <<config/mt-XXX>> file, and modify @file{configure.in} to use the
<<mt-XXX>> file (by setting "<<bfd_target=XXX>>") when your <<mt-XXX>> file (by setting "<<bfd_target=XXX>>") when your
configuration is selected. configuration is selected.
@ -140,11 +140,11 @@ SUBSECTION
relocations relocations
DESCRIPTION DESCRIPTION
The file @code{aoutx.h} caters for both the @emph{standard} The file @file{aoutx.h} provides for both the @emph{standard}
and @emph{extended} forms of a.out relocation records. and @emph{extended} forms of a.out relocation records.
The standard records are characterised by containing only an The standard records contain only an
address, a symbol index and a type field. The extended records address, a symbol index, and a type field. The extended records
(used on 29ks and sparcs) also have a full integer for an (used on 29ks and sparcs) also have a full integer for an
addend. addend.
@ -190,13 +190,18 @@ reloc_howto_type howto_table_std[] = {
HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false), HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false),
HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false), HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false),
HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false), HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false),
HOWTO( 3, 0, 3, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false), HOWTO( 3, 0, 4, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false),
HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false), HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false),
HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false), HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),
HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false), HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false),
HOWTO( 7, 0, 3, 64, true, 0, complain_overflow_signed,0,"DISP64", true, 0xfeedface,0xfeedface, false), HOWTO( 7, 0, 4, 64, true, 0, complain_overflow_signed, 0,"DISP64", true, 0xfeedface,0xfeedface, false),
{ -1 },
HOWTO( 9, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"BASE16", false,0xffffffff,0xffffffff, false),
HOWTO(10, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"BASE32", false,0xffffffff,0xffffffff, false),
}; };
#define TABLE_SIZE(TABLE) (sizeof(TABLE)/sizeof(TABLE[0]))
CONST struct reloc_howto_struct * CONST struct reloc_howto_struct *
DEFUN(NAME(aout,reloc_type_lookup),(abfd,code), DEFUN(NAME(aout,reloc_type_lookup),(abfd,code),
bfd *abfd AND bfd *abfd AND
@ -219,6 +224,7 @@ DEFUN(NAME(aout,reloc_type_lookup),(abfd,code),
EXT (BFD_RELOC_HI22, 8); EXT (BFD_RELOC_HI22, 8);
EXT (BFD_RELOC_LO10, 11); EXT (BFD_RELOC_LO10, 11);
EXT (BFD_RELOC_32_PCREL_S2, 6); EXT (BFD_RELOC_32_PCREL_S2, 6);
EXT (BFD_RELOC_SPARC_WDISP22, 7);
default: return (CONST struct reloc_howto_struct *) 0; default: return (CONST struct reloc_howto_struct *) 0;
} }
else else
@ -230,6 +236,8 @@ DEFUN(NAME(aout,reloc_type_lookup),(abfd,code),
STD (BFD_RELOC_8_PCREL, 4); STD (BFD_RELOC_8_PCREL, 4);
STD (BFD_RELOC_16_PCREL, 5); STD (BFD_RELOC_16_PCREL, 5);
STD (BFD_RELOC_32_PCREL, 6); STD (BFD_RELOC_32_PCREL, 6);
STD (BFD_RELOC_16_BASEREL, 9);
STD (BFD_RELOC_32_BASEREL, 10);
default: return (CONST struct reloc_howto_struct *) 0; default: return (CONST struct reloc_howto_struct *) 0;
} }
} }
@ -241,7 +249,7 @@ SUBSECTION
Internal Entry Points Internal Entry Points
DESCRIPTION DESCRIPTION
@code{aoutx.h} exports several routines for accessing the @file{aoutx.h} exports several routines for accessing the
contents of an a.out file, which are gathered and exported in contents of an a.out file, which are gathered and exported in
turn by various format specific files (eg sunos.c). turn by various format specific files (eg sunos.c).
@ -249,18 +257,18 @@ DESCRIPTION
/* /*
FUNCTION FUNCTION
aout_<size>_swap_exec_header_in aout_@var{size}_swap_exec_header_in
DESCRIPTION
Swaps the information in an executable header taken from a raw
byte stream memory image, into the internal exec_header
structure.
SYNOPSIS SYNOPSIS
void aout_<size>_swap_exec_header_in, void aout_@var{size}_swap_exec_header_in,
(bfd *abfd, (bfd *abfd,
struct external_exec *raw_bytes, struct external_exec *raw_bytes,
struct internal_exec *execp); struct internal_exec *execp);
DESCRIPTION
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}.
*/ */
#ifndef NAME_swap_exec_header_in #ifndef NAME_swap_exec_header_in
@ -292,17 +300,17 @@ DEFUN(NAME(aout,swap_exec_header_in),(abfd, raw_bytes, execp),
/* /*
FUNCTION FUNCTION
aout_<size>_swap_exec_header_out aout_@var{size}_swap_exec_header_out
DESCRIPTION
Swaps the information in an internal exec header structure
into the supplied buffer ready for writing to disk.
SYNOPSIS SYNOPSIS
void aout_<size>_swap_exec_header_out void aout_@var{size}_swap_exec_header_out
(bfd *abfd, (bfd *abfd,
struct internal_exec *execp, struct internal_exec *execp,
struct external_exec *raw_bytes); struct external_exec *raw_bytes);
DESCRIPTION
Swap the information in an internal exec header structure
@var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
*/ */
void void
DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes), DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes),
@ -327,19 +335,19 @@ DEFUN(NAME(aout,swap_exec_header_out),(abfd, execp, raw_bytes),
/* /*
FUNCTION FUNCTION
aout_<size>_some_aout_object_p aout_@var{size}_some_aout_object_p
DESCRIPTION
Some A.OUT variant thinks that the file whose format we're
checking is an a.out file. Do some more checking, and set up
for access if it really is. Call back to the calling
environments "finish up" function just before returning, to
handle any last-minute setup.
SYNOPSIS SYNOPSIS
bfd_target *aout_<size>_some_aout_object_p bfd_target *aout_@var{size}_some_aout_object_p
(bfd *abfd, (bfd *abfd,
bfd_target *(*callback_to_real_object_p)()); bfd_target *(*callback_to_real_object_p)());
DESCRIPTION
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.
*/ */
bfd_target * bfd_target *
@ -515,13 +523,13 @@ DEFUN(NAME(aout,some_aout_object_p),(abfd, execp, callback_to_real_object_p),
/* /*
FUNCTION FUNCTION
aout_<size>_mkobject aout_@var{size}_mkobject
DESCRIPTION
This routine initializes a BFD for use with a.out files.
SYNOPSIS SYNOPSIS
boolean aout_<size>_mkobject, (bfd *); boolean aout_@var{size}_mkobject, (bfd *abfd);
DESCRIPTION
Initialize BFD @var{abfd} for use with a.out files.
*/ */
boolean boolean
@ -561,21 +569,21 @@ DEFUN(NAME(aout,mkobject),(abfd),
/* /*
FUNCTION FUNCTION
aout_<size>_machine_type aout_@var{size}_machine_type
SYNOPSIS
enum machine_type aout_@var{size}_machine_type
(enum bfd_architecture arch,
unsigned long machine));
DESCRIPTION DESCRIPTION
Keep track of machine architecture and machine type for Keep track of machine architecture and machine type for
a.out's. Return the machine_type for a particular a.out's. Return the <<machine_type>> for a particular
arch&machine, or M_UNKNOWN if that exact arch&machine can't be architecture and machine, or <<M_UNKNOWN>> if that exact architecture
represented in a.out format. and machine can't be represented in a.out format.
If the architecture is understood, machine type 0 (default) If the architecture is understood, machine type 0 (default)
should always be understood. is always understood.
SYNOPSIS
enum machine_type aout_<size>_machine_type
(enum bfd_architecture arch,
unsigned long machine));
*/ */
enum machine_type enum machine_type
@ -631,18 +639,18 @@ DEFUN(NAME(aout,machine_type),(arch, machine),
/* /*
FUNCTION FUNCTION
aout_<size>_set_arch_mach aout_@var{size}_set_arch_mach
DESCRIPTION
Sets the architecture and the machine of the BFD to those
values supplied. Verifies that the format can support the
architecture required.
SYNOPSIS SYNOPSIS
boolean aout_<size>_set_arch_mach, boolean aout_@var{size}_set_arch_mach,
(bfd *, (bfd *,
enum bfd_architecture, enum bfd_architecture arch,
unsigned long machine)); unsigned long machine));
DESCRIPTION
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.
*/ */
boolean boolean
@ -894,16 +902,16 @@ DEFUN (NAME (aout,adjust_sizes_and_vmas), (abfd, text_size, text_end),
/* /*
FUNCTION FUNCTION
aout_<size>_new_section_hook aout_@var{size}_new_section_hook
SYNOPSIS
boolean aout_@var{size}_new_section_hook,
(bfd *abfd,
asection *newsect));
DESCRIPTION DESCRIPTION
Called by the BFD in response to a @code{bfd_make_section} Called by the BFD in response to a @code{bfd_make_section}
request. request.
SYNOPSIS
boolean aout_<size>_new_section_hook,
(bfd *abfd,
asection *newsect));
*/ */
boolean boolean
DEFUN(NAME(aout,new_section_hook),(abfd, newsect), DEFUN(NAME(aout,new_section_hook),(abfd, newsect),
@ -998,7 +1006,7 @@ DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),
/* Symbol is debugger info if any bits outside N_TYPE or N_EXT /* Symbol is debugger info if any bits outside N_TYPE or N_EXT
are on. */ are on. */
#define sym_is_debugger_info(sym) \ #define sym_is_debugger_info(sym) \
((sym)->type & ~(N_EXT | N_TYPE)) (((sym)->type & ~(N_EXT | N_TYPE)) || (sym)->type == N_FN)
#define sym_is_fortrancommon(sym) \ #define sym_is_fortrancommon(sym) \
(((sym)->type == (N_EXT)) && (sym)->symbol.value != 0) (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)
@ -1882,8 +1890,9 @@ DEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),
r_length = g->howto->size ; /* Size as a power of two */ r_length = g->howto->size ; /* Size as a power of two */
r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */
/* r_baserel, r_jmptable, r_relative??? FIXME-soon */ /* XXX This relies on relocs coming from a.out files. */
r_baserel = 0; r_baserel = (g->howto->type & 8) != 0;
/* r_jmptable, r_relative??? FIXME-soon */
r_jmptable = 0; r_jmptable = 0;
r_relative = 0; r_relative = 0;
@ -1975,14 +1984,12 @@ DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma; r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;
/* If this relocation is relative to a symbol then set the /* If this relocation is relative to a symbol then set the
r_index to the symbols index, and the r_extern bit. r_index to the symbols index, and the r_extern bit.
Absolute symbols can come in in two ways, either as an offset Absolute symbols can come in in two ways, either as an offset
from the abs section, or as a symbol which has an abs value. from the abs section, or as a symbol which has an abs value.
check for that here check for that here. */
*/
if (bfd_is_com_section (output_section) if (bfd_is_com_section (output_section)
|| output_section == &bfd_abs_section || output_section == &bfd_abs_section
@ -2008,15 +2015,14 @@ DEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),
r_index = output_section->target_index; r_index = output_section->target_index;
} }
/* now the fun stuff */ /* now the fun stuff */
if (abfd->xvec->header_byteorder_big_p != false) { if (abfd->xvec->header_byteorder_big_p != false) {
natptr->r_index[0] = r_index >> 16; natptr->r_index[0] = r_index >> 16;
natptr->r_index[1] = r_index >> 8; natptr->r_index[1] = r_index >> 8;
natptr->r_index[2] = r_index; natptr->r_index[2] = r_index;
natptr->r_type[0] = natptr->r_type[0] =
(r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) ((r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)
| (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG));
} else { } else {
natptr->r_index[2] = r_index >> 16; natptr->r_index[2] = r_index >> 16;
natptr->r_index[1] = r_index >> 8; natptr->r_index[1] = r_index >> 8;
@ -2119,6 +2125,7 @@ DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
int r_pcrel; int r_pcrel;
int r_baserel, r_jmptable, r_relative; int r_baserel, r_jmptable, r_relative;
struct aoutdata *su = &(abfd->tdata.aout_data->a); struct aoutdata *su = &(abfd->tdata.aout_data->a);
int howto_idx;
cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address); cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address);
@ -2147,8 +2154,13 @@ DEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),
>> RELOC_STD_BITS_LENGTH_SH_LITTLE; >> RELOC_STD_BITS_LENGTH_SH_LITTLE;
} }
cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel; howto_idx = r_length + 4 * r_pcrel + 8 * r_baserel;
/* FIXME-soon: Roll baserel, jmptable, relative bits into howto setting */ BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std));
cache_ptr->howto = howto_table_std + howto_idx;
BFD_ASSERT (cache_ptr->howto->type != -1);
BFD_ASSERT (r_jmptable == 0);
BFD_ASSERT (r_relative == 0);
/* FIXME-soon: Roll jmptable, relative bits into howto setting */
MOVE_ADDRESS(0); MOVE_ADDRESS(0);
} }
@ -2173,18 +2185,13 @@ DEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),
if (asect == obj_datasec (abfd)) { if (asect == obj_datasec (abfd)) {
reloc_size = exec_hdr(abfd)->a_drsize; reloc_size = exec_hdr(abfd)->a_drsize;
goto doit; } else if (asect == obj_textsec (abfd)) {
}
if (asect == obj_textsec (abfd)) {
reloc_size = exec_hdr(abfd)->a_trsize; reloc_size = exec_hdr(abfd)->a_trsize;
goto doit; } else {
}
bfd_error = invalid_operation; bfd_error = invalid_operation;
return false; return false;
}
doit:
bfd_seek (abfd, asect->rel_filepos, SEEK_SET); bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
each_size = obj_reloc_entry_size (abfd); each_size = obj_reloc_entry_size (abfd);

View File

@ -24,28 +24,26 @@ SECTION
Archives Archives
DESCRIPTION DESCRIPTION
Archives are supported in BFD in <<archive.c>>.
An archive (or library) is just another BFD. It has a symbol 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. table, although there's not much a user program will do with it.
The big difference between an archive BFD and an ordinary BFD The big difference between an archive BFD and an ordinary BFD
is that the archive doesn't have sections. Instead it has a is that the archive doesn't have sections. Instead it has a
chain of BFDs considered its contents. These BFDs can be chain of BFDs that are considered its contents. These BFDs can
manipulated just like any other. The BFDs contained in an be manipulated like any other. The BFDs contained in an
archive opened for reading will all be opened for reading; you archive opened for reading will all be opened for reading. You
may put either input or output BFDs into an archive opened for may put either input or output BFDs into an archive opened for
output; it will be handled correctly when the archive is closed. output; they will be handled correctly when the archive is closed.
Use <<bfd_openr_next_archived_file>> to step through all Use <<bfd_openr_next_archived_file>> to step through
the contents of an archive opened for input. It's not the contents of an archive opened for input. You don't
required that you read the entire archive if you don't want have to read the entire archive if you don't want
to! Read it until you find what you want. to! Read it until you find what you want.
Archive contents of output BFDs are chained through the Archive contents of output BFDs are chained through the
<<next>> pointer in a BFD. The first one is findable through <<next>> pointer in a BFD. The first one is findable through
the <<archive_head>> slot of the archive. Set it with the <<archive_head>> slot of the archive. Set it with
<<set_archive_head>> (q.v.). A given BFD may be in only one <<bfd_set_archive_head>> (q.v.). A given BFD may be in only one
open output archive at a time. open output archive at a time.
As expected, the BFD archive code is more general than the As expected, the BFD archive code is more general than the
@ -56,7 +54,7 @@ DESCRIPTION
This can cause unexpected confusion, since some archive This can cause unexpected confusion, since some archive
formats are more expressive than others. For instance, Intel formats are more expressive than others. For instance, Intel
COFF archives can preserve long filenames; Sun a.out archives COFF archives can preserve long filenames; SunOS a.out archives
cannot. If you move a file from the first to the second cannot. If you move a file from the first to the second
format and back again, the filename may be truncated. format and back again, the filename may be truncated.
Likewise, different a.out environments have different Likewise, different a.out environments have different
@ -67,10 +65,13 @@ DESCRIPTION
Beware: most of these formats do not react well to the Beware: most of these formats do not react well to the
presence of spaces in filenames. We do the best we can, but presence of spaces in filenames. We do the best we can, but
can't always handle this due to restrctions in the format of can't always handle this case due to restrictions in the format of
archives. Many unix utilities are braindead in regards to archives. Many Unix utilities are braindead in regards to
spaces and such in filenames anyway, so this shouldn't be much spaces and such in filenames anyway, so this shouldn't be much
of a restriction. of a restriction.
Archives are supported in BFD in <<archive.c>>.
*/ */
/* Assumes: /* Assumes:
@ -80,12 +81,12 @@ DESCRIPTION
*/ */
/* Some formats provide a way to cram a long filename into the short /* Some formats provide a way to cram a long filename into the short
(16 chars) space provided by a bsd archive. The trick is: make a (16 chars) space provided by a BSD archive. The trick is: make a
special "file" in the front of the archive, sort of like the SYMDEF special "file" in the front of the archive, sort of like the SYMDEF
entry. If the filename is too long to fit, put it in the extended entry. If the filename is too long to fit, put it in the extended
name table, and use its index as the filename. To prevent name table, and use its index as the filename. To prevent
confusion prepend the index with a space. This means you can't confusion prepend the index with a space. This means you can't
have filenames that start with a space, but then again, many unix have filenames that start with a space, but then again, many Unix
utilities can't handle that anyway. utilities can't handle that anyway.
This scheme unfortunately requires that you stand on your head in This scheme unfortunately requires that you stand on your head in
@ -99,7 +100,7 @@ DESCRIPTION
BSD 4.4 uses a third scheme: It writes a long filename BSD 4.4 uses a third scheme: It writes a long filename
directly after the header. This allows 'ar q' to work. directly after the header. This allows 'ar q' to work.
We current can read BSD 4.4 archives, but not write them. We currently can read BSD 4.4 archives, but not write them.
*/ */
/* Summary of archive member names: /* Summary of archive member names:
@ -141,6 +142,15 @@ extern int errno;
#define BFD_GNU960_ARMAG(abfd) (BFD_COFF_FILE_P((abfd)) ? ARMAG : ARMAGB) #define BFD_GNU960_ARMAG(abfd) (BFD_COFF_FILE_P((abfd)) ? ARMAG : ARMAGB)
#endif #endif
/* Can't define this in hosts/foo.h, because (e.g. in gprof) the hosts file
is included, then obstack.h, which thinks if offsetof is defined, it
doesn't need to include stddef.h. */
/* Define offsetof for those systems which lack it */
#if !defined (offsetof)
#define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
#endif
/* We keep a cache of archive filepointers to archive elements to /* We keep a cache of archive filepointers to archive elements to
speed up searching the archive by filepos. We only add an entry to speed up searching the archive by filepos. We only add an entry to
the cache when we actually read one. We also don't sort the cache; the cache when we actually read one. We also don't sort the cache;
@ -190,15 +200,15 @@ FUNCTION
bfd_get_next_mapent bfd_get_next_mapent
SYNOPSIS SYNOPSIS
symindex bfd_get_next_mapent(bfd *, symindex previous, carsym ** sym); symindex bfd_get_next_mapent(bfd *abfd, symindex previous, carsym **sym);
DESCRIPTION DESCRIPTION
This function steps through an archive's symbol table (if it Step through archive @var{abfd}'s symbol table (if it
has one). Successively updates <<sym>> with the next symbol's has one). Successively update @var{sym} with the next symbol's
information, returning that symbol's (internal) index into the information, returning that symbol's (internal) index into the
symbol table. symbol table.
Supply BFD_NO_MORE_SYMBOLS as the <<previous>> entry to get Supply BFD_NO_MORE_SYMBOLS as the @var{previous} entry to get
the first one; returns BFD_NO_MORE_SYMBOLS when you're already the first one; returns BFD_NO_MORE_SYMBOLS when you're already
got the last one. got the last one.
@ -226,6 +236,7 @@ DEFUN(bfd_get_next_mapent,(abfd, prev, entry),
} }
/* To be called by backends only */ /* To be called by backends only */
bfd * bfd *
_bfd_create_empty_archive_element_shell (obfd) _bfd_create_empty_archive_element_shell (obfd)
bfd *obfd; bfd *obfd;
@ -233,7 +244,8 @@ _bfd_create_empty_archive_element_shell (obfd)
bfd *nbfd; bfd *nbfd;
nbfd = new_bfd_contained_in(obfd); nbfd = new_bfd_contained_in(obfd);
if (nbfd == NULL) { if (nbfd == NULL)
{
bfd_error = no_memory; bfd_error = no_memory;
return NULL; return NULL;
} }
@ -248,8 +260,8 @@ SYNOPSIS
boolean bfd_set_archive_head(bfd *output, bfd *new_head); boolean bfd_set_archive_head(bfd *output, bfd *new_head);
DESCRIPTION DESCRIPTION
Used whilst processing archives. Sets the head of the chain of Set the head of the chain of
BFDs contained in an archive to @var{new_head}. BFDs contained in the archive @var{output} to @var{new_head}.
*/ */
boolean boolean
@ -463,28 +475,33 @@ snarf_ar_hdr (abfd)
*/ */
bfd * bfd *
DEFUN (get_elt_at_filepos, (archive, filepos), get_elt_at_filepos (archive, filepos)
bfd *archive AND bfd *archive;
file_ptr filepos) file_ptr filepos;
{ {
struct areltdata *new_areldata; struct areltdata *new_areldata;
bfd *n_nfd; bfd *n_nfd;
n_nfd = look_for_bfd_in_cache (archive, filepos); n_nfd = look_for_bfd_in_cache (archive, filepos);
if (n_nfd) return n_nfd; if (n_nfd)
return n_nfd;
if (0 > bfd_seek (archive, filepos, SEEK_SET)) { if (0 > bfd_seek (archive, filepos, SEEK_SET))
{
bfd_error = system_call_error; bfd_error = system_call_error;
return NULL; return NULL;
} }
if ((new_areldata = snarf_ar_hdr (archive)) == NULL) return NULL; if ((new_areldata = snarf_ar_hdr (archive)) == NULL)
return NULL;
n_nfd = _bfd_create_empty_archive_element_shell (archive); n_nfd = _bfd_create_empty_archive_element_shell (archive);
if (n_nfd == NULL) { if (n_nfd == NULL)
{
bfd_release (archive, (PTR)new_areldata); bfd_release (archive, (PTR)new_areldata);
return NULL; return NULL;
} }
n_nfd->origin = bfd_tell (archive); n_nfd->origin = bfd_tell (archive);
n_nfd->arelt_data = (PTR) new_areldata; n_nfd->arelt_data = (PTR) new_areldata;
n_nfd->filename = new_areldata->filename; n_nfd->filename = new_areldata->filename;
@ -506,8 +523,9 @@ SYNOPSIS
bfd *bfd_get_elt_at_index(bfd *archive, int index); bfd *bfd_get_elt_at_index(bfd *archive, int index);
DESCRIPTION DESCRIPTION
Return the bfd which is referenced by the symbol indexed by <<index>>. Return the BFD which is referenced by the symbol in @var{archive}
<<index>> should have been returned by <<bfd_get_next_mapent>> (q.v.). indexed by @var{index}. @var{index} should have been returned by
<<bfd_get_next_mapent>> (q.v.).
*/ */
bfd * bfd *
@ -529,9 +547,9 @@ SYNOPSIS
bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous); bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous);
DESCRIPTION DESCRIPTION
Initially provided a BFD containing an archive and NULL, opens Provided a BFD, @var{archive}, containing an archive and NULL, open
an inpout BFD on the first contained element and returns that. an input BFD on the first contained element and returns that.
Subsequent calls to bfd_openr_next_archived_file should pass Subsequent calls should pass
the archive and the previous return value to return a created the archive and the previous return value to return a created
BFD to the next contained element. NULL is returned when there BFD to the next contained element. NULL is returned when there
are no more. are no more.
@ -539,26 +557,25 @@ DESCRIPTION
*/ */
bfd * bfd *
DEFUN(bfd_openr_next_archived_file,(archive, last_file), bfd_openr_next_archived_file (archive, last_file)
bfd *archive AND bfd *archive;
bfd*last_file) bfd *last_file;
{ {
if ((bfd_get_format (archive) != bfd_archive) || if ((bfd_get_format (archive) != bfd_archive) ||
(archive->direction == write_direction)) { (archive->direction == write_direction))
{
bfd_error = invalid_operation; bfd_error = invalid_operation;
return NULL; return NULL;
} }
return BFD_SEND (archive, return BFD_SEND (archive,
openr_next_archived_file, openr_next_archived_file,
(archive, (archive,
last_file)); last_file));
} }
bfd *bfd_generic_openr_next_archived_file(archive, last_file) bfd *
bfd_generic_openr_next_archived_file (archive, last_file)
bfd *archive; bfd *archive;
bfd *last_file; bfd *last_file;
{ {
@ -1496,6 +1513,7 @@ compute_and_write_armap (arch, elength)
syms[src_count]->section; syms[src_count]->section;
if ((flags & BSF_GLOBAL || if ((flags & BSF_GLOBAL ||
flags & BSF_WEAK ||
flags & BSF_INDIRECT || flags & BSF_INDIRECT ||
bfd_is_com_section (sec)) bfd_is_com_section (sec))
&& (sec != &bfd_und_section)) { && (sec != &bfd_und_section)) {
@ -1559,7 +1577,8 @@ bsd_write_armap (arch, elength, map, orl_count, stridx)
sprintf (hdr.ar_name, RANLIBMAG); sprintf (hdr.ar_name, RANLIBMAG);
/* Remember the timestamp, to keep it holy. But fudge it a little. */ /* Remember the timestamp, to keep it holy. But fudge it a little. */
bfd_ardata(arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET; bfd_ardata(arch)->armap_timestamp = statbuf.st_mtime + ARMAP_TIME_OFFSET;
bfd_ardata(arch)->armap_datepos = SARMAG + offsetof(struct ar_hdr, ar_date); bfd_ardata(arch)->armap_datepos = SARMAG +
offsetof(struct ar_hdr, ar_date[0]);
sprintf (hdr.ar_date, "%ld", bfd_ardata(arch)->armap_timestamp); sprintf (hdr.ar_date, "%ld", bfd_ardata(arch)->armap_timestamp);
sprintf (hdr.ar_uid, "%d", getuid()); sprintf (hdr.ar_uid, "%d", getuid());
sprintf (hdr.ar_gid, "%d", getgid()); sprintf (hdr.ar_gid, "%d", getgid());

View File

@ -24,17 +24,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
Architectures Architectures
BFD's idea of an architecture is implimented in BFD keeps one atom in a BFD describing the
<<archures.c>>. BFD keeps one atom in a BFD describing the architecture of the data attached to the BFD: a pointer to a
architecture of the data attached to the BFD; a pointer to a
<<bfd_arch_info_type>>. <<bfd_arch_info_type>>.
Pointers to structures can be requested independently of a bfd Pointers to structures can be requested independently of a BFD
so that an architecture's information can be interrogated so that an architecture's information can be interrogated
without access to an open bfd. without access to an open BFD.
The arch information is provided by each architecture package. The architecture information is provided by each architecture package.
The set of default architectures is selected by the #define The set of default architectures is selected by the macro
<<SELECT_ARCHITECTURES>>. This is normally set up in the <<SELECT_ARCHITECTURES>>. This is normally set up in the
<<config/target.mt>> file of your choice. If the name is not <<config/target.mt>> file of your choice. If the name is not
defined, then all the architectures supported are included. defined, then all the architectures supported are included.
@ -44,6 +43,8 @@ SECTION
insert as many items into the list of architectures as it wants to; insert as many items into the list of architectures as it wants to;
generally this would be one for each machine and one for the generally this would be one for each machine and one for the
default case (an item with a machine field of 0). default case (an item with a machine field of 0).
BFD's idea of an architecture is implemented in <<archures.c>>.
*/ */
/* /*
@ -54,10 +55,10 @@ SUBSECTION
DESCRIPTION DESCRIPTION
This enum gives the object file's CPU architecture, in a This enum gives the object file's CPU architecture, in a
global sense---i.e., what processor family does it belong to? global sense---i.e., what processor family does it belong to?
There is another field, which indicates what processor within Another field indicates which processor within
the family is in use. The machine gives a number which the family is in use. The machine gives a number which
distingushes different versions of the architecture, distinguishes different versions of the architecture,
containing for example 2 and 3 for Intel i960 KA and i960 KB, containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
and 68020 and 68030 for Motorola 68020 and 68030. and 68020 and 68030 for Motorola 68020 and 68030.
.enum bfd_architecture .enum bfd_architecture
@ -166,7 +167,7 @@ SYNOPSIS
DESCRIPTION DESCRIPTION
Return a printable string representing the architecture and machine Return a printable string representing the architecture and machine
from the pointer to the arch info structure from the pointer to the architecture info structure.
*/ */
@ -184,12 +185,11 @@ FUNCTION
bfd_scan_arch bfd_scan_arch
SYNOPSIS SYNOPSIS
bfd_arch_info_type *bfd_scan_arch(CONST char *); bfd_arch_info_type *bfd_scan_arch(CONST char *string);
DESCRIPTION DESCRIPTION
This routine is provided with a string and tries to work out Figure out if BFD supports any cpu which could be described with
if bfd supports any cpu which could be described with the name the name @var{string}. Return a pointer to an <<arch_info>>
provided. The routine returns a pointer to an arch_info
structure if a machine is found, otherwise NULL. structure if a machine is found, otherwise NULL.
*/ */
@ -223,11 +223,11 @@ SYNOPSIS
CONST bfd *bbfd); CONST bfd *bbfd);
DESCRIPTION DESCRIPTION
This routine is used to determine whether two BFDs' Determine whether two BFDs'
architectures and achine types are compatible. It calculates architectures and machine types are compatible. Calculates
the lowest common denominator between the two architectures the lowest common denominator between the two architectures
and machine types implied by the BFDs and returns a pointer to and machine types implied by the BFDs and returns a pointer to
an arch_info structure describing the compatible machine. an <<arch_info>> structure describing the compatible machine.
*/ */
CONST bfd_arch_info_type * CONST bfd_arch_info_type *
@ -268,8 +268,10 @@ FUNCTION
bfd_set_arch_info bfd_set_arch_info
SYNOPSIS SYNOPSIS
void bfd_set_arch_info(bfd *, bfd_arch_info_type *); void bfd_set_arch_info(bfd *abfd, bfd_arch_info_type *arg);
DESCRIPTION
Set the architecture info of @var{abfd} to @var{arg}.
*/ */
void DEFUN(bfd_set_arch_info,(abfd, arg), void DEFUN(bfd_set_arch_info,(abfd, arg),
@ -289,8 +291,9 @@ SYNOPSIS
unsigned long mach); unsigned long mach);
DESCRIPTION DESCRIPTION
Set the architecture and machine type in a bfd. This finds the Set the architecture and machine type in BFD @var{abfd}
correct pointer to structure and inserts it into the arch_info to @var{arch} and @var{mach}. Find the correct
pointer to a structure and insert it into the <<arch_info>>
pointer. pointer.
*/ */
@ -333,9 +336,6 @@ boolean DEFUN(bfd_default_set_arch_mach,(abfd, arch, mach),
} }
/* /*
FUNCTION FUNCTION
bfd_get_arch bfd_get_arch
@ -344,8 +344,8 @@ SYNOPSIS
enum bfd_architecture bfd_get_arch(bfd *abfd); enum bfd_architecture bfd_get_arch(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns the enumerated type which describes the supplied bfd's Return the enumerated type which describes the BFD @var{abfd}'s
architecture architecture.
*/ */
@ -362,8 +362,8 @@ SYNOPSIS
unsigned long bfd_get_mach(bfd *abfd); unsigned long bfd_get_mach(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns the long type which describes the supplied bfd's Return the long type which describes the BFD @var{abfd}'s
machine machine.
*/ */
unsigned long unsigned long
@ -380,7 +380,8 @@ SYNOPSIS
unsigned int bfd_arch_bits_per_byte(bfd *abfd); unsigned int bfd_arch_bits_per_byte(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns the number of bits in one of the architectures bytes Return the number of bits in one of the BFD @var{abfd}'s
architecture's bytes.
*/ */
@ -397,7 +398,8 @@ SYNOPSIS
unsigned int bfd_arch_bits_per_address(bfd *abfd); unsigned int bfd_arch_bits_per_address(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns the number of bits in one of the architectures addresses Return the number of bits in one of the BFD @var{abfd}'s
architecture's addresses.
*/ */
unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd) unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd)
@ -406,24 +408,22 @@ unsigned int DEFUN(bfd_arch_bits_per_address, (abfd), bfd *abfd)
} }
extern void bfd_h8300_arch PARAMS ((void));
extern void bfd_sh_arch PARAMS ((void));
extern void bfd_h8500_arch PARAMS ((void));
extern void bfd_alpha_arch PARAMS ((void));
extern void bfd_i960_arch PARAMS ((void));
extern void bfd_empty_arch PARAMS ((void));
extern void bfd_sparc_arch PARAMS ((void));
extern void bfd_m88k_arch PARAMS ((void));
extern void bfd_m68k_arch PARAMS ((void));
extern void bfd_vax_arch PARAMS ((void));
extern void bfd_a29k_arch PARAMS ((void)); extern void bfd_a29k_arch PARAMS ((void));
extern void bfd_mips_arch PARAMS ((void)); extern void bfd_alpha_arch PARAMS ((void));
extern void bfd_i386_arch PARAMS ((void)); extern void bfd_h8300_arch PARAMS ((void));
extern void bfd_rs6000_arch PARAMS ((void)); extern void bfd_h8500_arch PARAMS ((void));
extern void bfd_hppa_arch PARAMS ((void)); extern void bfd_hppa_arch PARAMS ((void));
extern void bfd_z8k_arch PARAMS ((void)); extern void bfd_i386_arch PARAMS ((void));
extern void bfd_i960_arch PARAMS ((void));
extern void bfd_m68k_arch PARAMS ((void));
extern void bfd_m88k_arch PARAMS ((void));
extern void bfd_mips_arch PARAMS ((void));
extern void bfd_rs6000_arch PARAMS ((void));
extern void bfd_sh_arch PARAMS ((void));
extern void bfd_sparc_arch PARAMS ((void));
extern void bfd_vax_arch PARAMS ((void));
extern void bfd_we32k_arch PARAMS ((void)); extern void bfd_we32k_arch PARAMS ((void));
extern void bfd_z8k_arch PARAMS ((void));
static void (*archures_init_table[]) PARAMS ((void)) = static void (*archures_init_table[]) PARAMS ((void)) =
{ {
@ -460,7 +460,7 @@ SYNOPSIS
void bfd_arch_init(void); void bfd_arch_init(void);
DESCRIPTION DESCRIPTION
This routine initializes the architecture dispatch table by Initialize the architecture dispatch table by
calling all installed architecture packages and getting them calling all installed architecture packages and getting them
to poke around. to poke around.
*/ */
@ -483,10 +483,10 @@ INTERNAL_FUNCTION
bfd_arch_linkin bfd_arch_linkin
SYNOPSIS SYNOPSIS
void bfd_arch_linkin(bfd_arch_info_type *); void bfd_arch_linkin(bfd_arch_info_type *ptr);
DESCRIPTION DESCRIPTION
Link the provided arch info structure into the list Link the architecture info structure @var{ptr} into the list.
*/ */
void DEFUN(bfd_arch_linkin,(ptr), void DEFUN(bfd_arch_linkin,(ptr),
@ -532,7 +532,7 @@ INTERNAL_FUNCTION
bfd_default_scan bfd_default_scan
SYNOPSIS SYNOPSIS
boolean bfd_default_scan(CONST struct bfd_arch_info *, CONST char *); boolean bfd_default_scan(CONST struct bfd_arch_info *info, CONST char *string);
DESCRIPTION DESCRIPTION
The default function for working out whether this is an The default function for working out whether this is an
@ -649,16 +649,15 @@ CONST char *string)
} }
/* /*
FUNCTION FUNCTION
bfd_get_arch_info bfd_get_arch_info
SYNOPSIS SYNOPSIS
bfd_arch_info_type * bfd_get_arch_info(bfd *); bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
DESCRIPTION
Return the architecture info struct in @var{abfd}.
*/ */
bfd_arch_info_type * bfd_arch_info_type *
@ -680,8 +679,8 @@ SYNOPSIS
long machine); long machine);
DESCRIPTION DESCRIPTION
Look for the architecure info struct which matches the Look for the architecure info structure which matches the
arguments given. A machine of 0 will match the arguments @var{arch} and @var{machine}. A machine of 0 matches the
machine/architecture structure which marks itself as the machine/architecture structure which marks itself as the
default. default.
*/ */
@ -706,7 +705,6 @@ long machine)
} }
/* /*
FUNCTION FUNCTION
bfd_printable_arch_mach bfd_printable_arch_mach
@ -719,7 +717,7 @@ DESCRIPTION
Return a printable string representing the architecture and Return a printable string representing the architecture and
machine type. machine type.
NB. The use of this routine is depreciated. This routine is depreciated.
*/ */
CONST char * CONST char *

View File

@ -475,7 +475,7 @@ bfd *
bfd_openw PARAMS ((CONST char *filename, CONST char *target)); bfd_openw PARAMS ((CONST char *filename, CONST char *target));
boolean boolean
bfd_close PARAMS ((bfd *)); bfd_close PARAMS ((bfd *abfd));
boolean boolean
bfd_close_all_done PARAMS ((bfd *)); bfd_close_all_done PARAMS ((bfd *));
@ -566,12 +566,12 @@ bfd_create PARAMS ((CONST char *filename, bfd *templ));
typedef struct sec typedef struct sec
{ {
/* The name of the section, the name isn't a copy, the pointer is /* The name of the section; the name isn't a copy, the pointer is
the same as that passed to bfd_make_section. */ the same as that passed to bfd_make_section. */
CONST char *name; CONST char *name;
/* Which section is it 0.nth */ /* Which section is it; 0..nth. */
int index; int index;
@ -579,7 +579,7 @@ typedef struct sec
struct sec *next; struct sec *next;
/* The field flags contains attributes of the section. Some of /* The field flags contains attributes of the section. Some
flags are read in from the object file, and some are flags are read in from the object file, and some are
synthesized from other information. */ synthesized from other information. */
@ -587,17 +587,17 @@ typedef struct sec
#define SEC_NO_FLAGS 0x000 #define SEC_NO_FLAGS 0x000
/* Tells the OS to allocate space for this section when loaded. /* Tells the OS to allocate space for this section when loading.
This would clear for a section containing debug information This is clear for a section containing debug information
only. */ only. */
#define SEC_ALLOC 0x001 #define SEC_ALLOC 0x001
/* Tells the OS to load the section from the file when loading. /* Tells the OS to load the section from the file when loading.
This would be clear for a .bss section */ This is clear for a .bss section. */
#define SEC_LOAD 0x002 #define SEC_LOAD 0x002
/* The section contains data still to be relocated, so there will /* The section contains data still to be relocated, so there is
be some relocation information too. */ some relocation information too. */
#define SEC_RELOC 0x004 #define SEC_RELOC 0x004
#if 0 /* Obsolete ? */ #if 0 /* Obsolete ? */
@ -621,10 +621,10 @@ typedef struct sec
type is used by the linker to create lists of constructors and type is used by the linker to create lists of constructors and
destructors used by <<g++>>. When a back end sees a symbol destructors used by <<g++>>. When a back end sees a symbol
which should be used in a constructor list, it creates a new which should be used in a constructor list, it creates a new
section for the type of name (eg <<__CTOR_LIST__>>), attaches section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
the symbol to it and builds a relocation. To build the lists the symbol to it, and builds a relocation. To build the lists
of constructors, all the linker has to do is catenate all the of constructors, all the linker has to do is catenate all the
sections called <<__CTOR_LIST__>> and relocte the data sections called <<__CTOR_LIST__>> and relocate the data
contained within - exactly the operations it would peform on contained within - exactly the operations it would peform on
standard data. */ standard data. */
#define SEC_CONSTRUCTOR 0x100 #define SEC_CONSTRUCTOR 0x100
@ -636,13 +636,12 @@ typedef struct sec
#define SEC_CONSTRUCTOR_BSS 0x3100 #define SEC_CONSTRUCTOR_BSS 0x3100
/* The section has contents - a data section could be /* The section has contents - a data section could be
<<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>, a debug section could be <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
<<SEC_HAS_CONTENTS>> */ <<SEC_HAS_CONTENTS>> */
#define SEC_HAS_CONTENTS 0x200 #define SEC_HAS_CONTENTS 0x200
/* An instruction to the linker not to output sections /* An instruction to the linker to not output the section
containing this flag even if they have information which even if it has information which would normally be written. */
would normally be written. */
#define SEC_NEVER_LOAD 0x400 #define SEC_NEVER_LOAD 0x400
/* The section is a shared library section. The linker must leave /* The section is a shared library section. The linker must leave
@ -676,18 +675,18 @@ typedef struct sec
boolean user_set_vma; boolean user_set_vma;
/* The load address of the section - where it would be in a /* The load address of the section - where it would be in a
rom image, really only used for writing section header rom image; really only used for writing section header
information. */ information. */
bfd_vma lma; bfd_vma lma;
/* The size of the section in bytes, as it will be output. /* The size of the section in bytes, as it will be output.
contains a value even if the section has no contents (eg, the contains a value even if the section has no contents (e.g., the
size of <<.bss>>). This will be filled in after relocation */ size of <<.bss>>). This will be filled in after relocation */
bfd_size_type _cooked_size; bfd_size_type _cooked_size;
/* The size on disk of the section in bytes originally. Normally this /* The original size on disk of the section, in bytes. Normally this
value is the same as the size, but if some relaxing has value is the same as the size, but if some relaxing has
been done, then this value will be bigger. */ been done, then this value will be bigger. */
@ -695,7 +694,7 @@ typedef struct sec
/* If this section is going to be output, then this value is the /* If this section is going to be output, then this value is the
offset into the output section of the first byte in the input offset into the output section of the first byte in the input
section. Eg, if this was going to start at the 100th byte in section. E.g., if this was going to start at the 100th byte in
the output section, this value would be 100. */ the output section, this value would be 100. */
bfd_vma output_offset; bfd_vma output_offset;
@ -704,8 +703,8 @@ typedef struct sec
struct sec *output_section; struct sec *output_section;
/* The alignment requirement of the section, as an exponent - eg /* The alignment requirement of the section, as an exponent of 2 -
3 aligns to 2^3 (or 8) */ e.g., 3 aligns to 2^3 (or 8). */
unsigned int alignment_power; unsigned int alignment_power;
@ -757,7 +756,7 @@ typedef struct sec
file_ptr moving_line_filepos; file_ptr moving_line_filepos;
/* what the section number is in the target world */ /* What the section number is in the target world */
int target_index; int target_index;
@ -811,16 +810,16 @@ asection *
bfd_get_section_by_name PARAMS ((bfd *abfd, CONST char *name)); bfd_get_section_by_name PARAMS ((bfd *abfd, CONST char *name));
asection * asection *
bfd_make_section_old_way PARAMS ((bfd *, CONST char *name)); bfd_make_section_old_way PARAMS ((bfd *abfd, CONST char *name));
asection * asection *
bfd_make_section_anyway PARAMS ((bfd *, CONST char *name)); bfd_make_section_anyway PARAMS ((bfd *abfd, CONST char *name));
asection * asection *
bfd_make_section PARAMS ((bfd *, CONST char *name)); bfd_make_section PARAMS ((bfd *, CONST char *name));
boolean boolean
bfd_set_section_flags PARAMS ((bfd *, asection *, flagword)); bfd_set_section_flags PARAMS ((bfd *abfd, asection *sec, flagword flags));
void void
bfd_map_over_sections PARAMS ((bfd *abfd, bfd_map_over_sections PARAMS ((bfd *abfd,
@ -830,7 +829,7 @@ bfd_map_over_sections PARAMS ((bfd *abfd,
PTR obj)); PTR obj));
boolean boolean
bfd_set_section_size PARAMS ((bfd *, asection *, bfd_size_type val)); bfd_set_section_size PARAMS ((bfd *abfd, asection *sec, bfd_size_type val));
boolean boolean
bfd_set_section_contents bfd_set_section_contents
@ -924,7 +923,7 @@ CONST char *
bfd_printable_name PARAMS ((bfd *abfd)); bfd_printable_name PARAMS ((bfd *abfd));
bfd_arch_info_type * bfd_arch_info_type *
bfd_scan_arch PARAMS ((CONST char *)); bfd_scan_arch PARAMS ((CONST char *string));
CONST bfd_arch_info_type * CONST bfd_arch_info_type *
bfd_arch_get_compatible PARAMS (( bfd_arch_get_compatible PARAMS ((
@ -932,7 +931,7 @@ bfd_arch_get_compatible PARAMS ((
CONST bfd *bbfd)); CONST bfd *bbfd));
void void
bfd_set_arch_info PARAMS ((bfd *, bfd_arch_info_type *)); bfd_set_arch_info PARAMS ((bfd *abfd, bfd_arch_info_type *arg));
enum bfd_architecture enum bfd_architecture
bfd_get_arch PARAMS ((bfd *abfd)); bfd_get_arch PARAMS ((bfd *abfd));
@ -947,7 +946,7 @@ unsigned int
bfd_arch_bits_per_address PARAMS ((bfd *abfd)); bfd_arch_bits_per_address PARAMS ((bfd *abfd));
bfd_arch_info_type * bfd_arch_info_type *
bfd_get_arch_info PARAMS ((bfd *)); bfd_get_arch_info PARAMS ((bfd *abfd));
bfd_arch_info_type * bfd_arch_info_type *
bfd_lookup_arch bfd_lookup_arch
@ -973,10 +972,10 @@ typedef enum bfd_reloc_status
/* Used by special functions */ /* Used by special functions */
bfd_reloc_continue, bfd_reloc_continue,
/* Unused */ /* Unsupported relocation size requested. */
bfd_reloc_notsupported, bfd_reloc_notsupported,
/* Unsupported relocation size requested. */ /* Unused */
bfd_reloc_other, bfd_reloc_other,
/* The symbol to relocate against was undefined. */ /* The symbol to relocate against was undefined. */
@ -1023,13 +1022,13 @@ enum complain_overflow
complain_overflow_unsigned complain_overflow_unsigned
}; };
typedef CONST struct reloc_howto_struct typedef struct reloc_howto_struct
{ {
/* The type field has mainly a documetary use - the back end can /* The type field has mainly a documetary use - the back end can
to what it wants with it, though the normally the back end's do what it wants with it, though normally the back end's
external idea of what a reloc number would be would be stored external idea of what a reloc number is stored
in this field. For example, the a PC relative word relocation in this field. For example, a PC relative word relocation
in a coff environment would have the type 023 - because that's in a coff environment has the type 023 - because that's
what the outside world calls a R_PCRWORD reloc. */ what the outside world calls a R_PCRWORD reloc. */
unsigned int type; unsigned int type;
@ -1087,7 +1086,7 @@ typedef CONST struct reloc_howto_struct
relocations rather than the data - this flag signals this.*/ relocations rather than the data - this flag signals this.*/
boolean partial_inplace; boolean partial_inplace;
/* The src_mask is used to select what parts of the read in data /* The src_mask selects which parts of the read in data
are to be used in the relocation sum. E.g., if this was an 8 bit are to be used in the relocation sum. E.g., if this was an 8 bit
bit of data which we read and relocated, this would be bit of data which we read and relocated, this would be
0x000000ff. When we have relocs which have an addend, such as 0x000000ff. When we have relocs which have an addend, such as
@ -1096,7 +1095,7 @@ typedef CONST struct reloc_howto_struct
the mask would be 0x00000000. */ the mask would be 0x00000000. */
bfd_vma src_mask; bfd_vma src_mask;
/* The dst_mask is what parts of the instruction are replaced /* The dst_mask selects which parts of the instruction are replaced
into the instruction. In most cases src_mask == dst_mask, into the instruction. In most cases src_mask == dst_mask,
except in the above special case, where dst_mask would be except in the above special case, where dst_mask would be
0x000000ff, and src_mask would be 0x00000000. */ 0x000000ff, and src_mask would be 0x00000000. */
@ -1107,7 +1106,7 @@ typedef CONST struct reloc_howto_struct
slot of the instruction, so that a PC relative relocation can slot of the instruction, so that a PC relative relocation can
be made just by adding in an ordinary offset (e.g., sun3 a.out). be made just by adding in an ordinary offset (e.g., sun3 a.out).
Some formats leave the displacement part of an instruction Some formats leave the displacement part of an instruction
empty (e.g., m88k bcs), this flag signals the fact.*/ empty (e.g., m88k bcs); this flag signals the fact.*/
boolean pcrel_offset; boolean pcrel_offset;
} reloc_howto_type; } reloc_howto_type;
@ -1361,6 +1360,22 @@ CONST struct reloc_howto_struct *
bfd_reloc_type_lookup PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); bfd_reloc_type_lookup PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
unsigned int
bfd_get_reloc_upper_bound PARAMS ((bfd *abfd, asection *sect));
unsigned int
bfd_canonicalize_reloc
PARAMS ((bfd *abfd,
asection *sec,
arelent **loc,
asymbol **syms));
void
bfd_set_reloc
PARAMS ((bfd *abfd, sec_ptr *sec, arelent **rel, unsigned int count)
);
typedef struct symbol_cache_entry typedef struct symbol_cache_entry
{ {
@ -1376,7 +1391,7 @@ typedef struct symbol_cache_entry
struct _bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field. */ struct _bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field. */
/* The text of the symbol. The name is left alone, and not copied - the /* The text of the symbol. The name is left alone, and not copied; the
application may not alter it. */ application may not alter it. */
CONST char *name; CONST char *name;
@ -1397,7 +1412,7 @@ typedef struct symbol_cache_entry
value is the offset into the section of the data. */ value is the offset into the section of the data. */
#define BSF_GLOBAL 0x02 #define BSF_GLOBAL 0x02
/* The symbol has global scope, and is exported. The value is /* The symbol has global scope and is exported. The value is
the offset into the section of the data. */ the offset into the section of the data. */
#define BSF_EXPORT BSF_GLOBAL /* no real difference */ #define BSF_EXPORT BSF_GLOBAL /* no real difference */
@ -1476,7 +1491,7 @@ typedef struct symbol_cache_entry
BFD_SEND (abfd, _bfd_canonicalize_symtab,\ BFD_SEND (abfd, _bfd_canonicalize_symtab,\
(abfd, location)) (abfd, location))
boolean boolean
bfd_set_symtab PARAMS ((bfd *, asymbol **, unsigned int )); bfd_set_symtab PARAMS ((bfd *abfd, asymbol **location, unsigned int count));
void void
bfd_print_symbol_vandf PARAMS ((PTR file, asymbol *symbol)); bfd_print_symbol_vandf PARAMS ((PTR file, asymbol *symbol));
@ -1512,8 +1527,8 @@ struct _bfd
boolean cacheable; boolean cacheable;
/* Marks whether there was a default target specified when the /* Marks whether there was a default target specified when the
BFD was opened. This is used to select what matching algorithm BFD was opened. This is used to select which matching algorithm
to use to chose the back end. */ to use to choose the back end. */
boolean target_defaulted; boolean target_defaulted;
@ -1523,12 +1538,11 @@ struct _bfd
struct _bfd *lru_prev, *lru_next; struct _bfd *lru_prev, *lru_next;
/* When a file is closed by the caching routines, BFD retains /* When a file is closed by the caching routines, BFD retains
state information on the file here: state information on the file here: */
*/
file_ptr where; file_ptr where;
/* and here:*/ /* and here: (``once'' means at least once) */
boolean opened_once; boolean opened_once;
@ -1545,7 +1559,7 @@ struct _bfd
int ifd; int ifd;
/* The format which belongs to the BFD.*/ /* The format which belongs to the BFD. (object, core, etc.) */
bfd_format format; bfd_format format;
@ -1567,7 +1581,7 @@ struct _bfd
file_ptr origin; file_ptr origin;
/* Remember when output has begun, to stop strange things /* Remember when output has begun, to stop strange things
happening. */ from happening. */
boolean output_has_begun; boolean output_has_begun;
/* Pointer to linked list of sections*/ /* Pointer to linked list of sections*/
@ -1583,7 +1597,7 @@ struct _bfd
/* Used for input and output*/ /* Used for input and output*/
unsigned int symcount; unsigned int symcount;
/* Symbol table for output BFD*/ /* Symbol table for output BFD (with symcount entries) */
struct symbol_cache_entry **outsymbols; struct symbol_cache_entry **outsymbols;
/* Pointer to structure which contains architecture information*/ /* Pointer to structure which contains architecture information*/
@ -1591,9 +1605,9 @@ struct _bfd
/* Stuff only useful for archives:*/ /* Stuff only useful for archives:*/
PTR arelt_data; PTR arelt_data;
struct _bfd *my_archive; struct _bfd *my_archive; /* The containing archive BFD. */
struct _bfd *next; struct _bfd *next; /* The next BFD in the archive. */
struct _bfd *archive_head; struct _bfd *archive_head; /* The first BFD in the archive. */
boolean has_armap; boolean has_armap;
/* Used by the back end to hold private data. */ /* Used by the back end to hold private data. */
@ -1633,39 +1647,23 @@ struct _bfd
asymbol **ld_symbols; asymbol **ld_symbols;
}; };
unsigned int
bfd_get_reloc_upper_bound PARAMS ((bfd *abfd, asection *sect));
unsigned int
bfd_canonicalize_reloc
PARAMS ((bfd *abfd,
asection *sec,
arelent **loc,
asymbol **syms));
boolean boolean
bfd_set_file_flags PARAMS ((bfd *abfd, flagword flags)); bfd_set_file_flags PARAMS ((bfd *abfd, flagword flags));
void
bfd_set_reloc
PARAMS ((bfd *abfd, asection *sec, arelent **rel, unsigned int count)
);
boolean boolean
bfd_set_start_address PARAMS ((bfd *, bfd_vma)); bfd_set_start_address PARAMS ((bfd *abfd, bfd_vma vma));
long long
bfd_get_mtime PARAMS ((bfd *)); bfd_get_mtime PARAMS ((bfd *abfd));
long long
bfd_get_size PARAMS ((bfd *)); bfd_get_size PARAMS ((bfd *abfd));
int int
bfd_get_gp_size PARAMS ((bfd *)); bfd_get_gp_size PARAMS ((bfd *abfd));
void void
bfd_set_gp_size PARAMS ((bfd *, int)); bfd_set_gp_size PARAMS ((bfd *abfd, int i));
bfd_vma bfd_vma
bfd_scan_vma PARAMS ((CONST char *string, CONST char **end, int base)); bfd_scan_vma PARAMS ((CONST char *string, CONST char **end, int base));
@ -1702,7 +1700,7 @@ bfd_scan_vma PARAMS ((CONST char *string, CONST char **end, int base));
#define bfd_seclet_link(abfd, data, relocateable) \ #define bfd_seclet_link(abfd, data, relocateable) \
BFD_SEND (abfd, _bfd_seclet_link, (abfd, data, relocateable)) BFD_SEND (abfd, _bfd_seclet_link, (abfd, data, relocateable))
symindex symindex
bfd_get_next_mapent PARAMS ((bfd *, symindex previous, carsym ** sym)); bfd_get_next_mapent PARAMS ((bfd *abfd, symindex previous, carsym **sym));
boolean boolean
bfd_set_archive_head PARAMS ((bfd *output, bfd *new_head)); bfd_set_archive_head PARAMS ((bfd *output, bfd *new_head));
@ -1714,10 +1712,10 @@ bfd*
bfd_openr_next_archived_file PARAMS ((bfd *archive, bfd *previous)); bfd_openr_next_archived_file PARAMS ((bfd *archive, bfd *previous));
CONST char * CONST char *
bfd_core_file_failing_command PARAMS ((bfd *)); bfd_core_file_failing_command PARAMS ((bfd *abfd));
int int
bfd_core_file_failing_signal PARAMS ((bfd *)); bfd_core_file_failing_signal PARAMS ((bfd *abfd));
boolean boolean
core_file_matches_executable_p core_file_matches_executable_p
@ -1849,7 +1847,7 @@ typedef struct bfd_target
PTR backend_data; PTR backend_data;
} bfd_target; } bfd_target;
bfd_target * bfd_target *
bfd_find_target PARAMS ((CONST char *, bfd *)); bfd_find_target PARAMS ((CONST char *target_name, bfd *abfd));
CONST char ** CONST char **
bfd_target_list PARAMS ((void)); bfd_target_list PARAMS ((void));
@ -1858,9 +1856,9 @@ boolean
bfd_check_format PARAMS ((bfd *abfd, bfd_format format)); bfd_check_format PARAMS ((bfd *abfd, bfd_format format));
boolean boolean
bfd_set_format PARAMS ((bfd *, bfd_format)); bfd_set_format PARAMS ((bfd *abfd, bfd_format format));
CONST char * CONST char *
bfd_format_string PARAMS ((bfd_format)); bfd_format_string PARAMS ((bfd_format format));
#endif #endif

203
bfd/bfd.c
View File

@ -22,13 +22,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
<<typedef bfd>> <<typedef bfd>>
A BFD is has type <<bfd>>; objects of this type are the A BFD has type <<bfd>>; objects of this type are the
cornerstone of any application using <<libbfd>>. References cornerstone of any application using <<libbfd>>. Using BFD
though the BFD and to data in the BFD give the entire BFD consists of making references though the BFD and to data in the BFD.
functionality.
Here is the struct used to define the type <<bfd>>. This Here is the structure that defines the type <<bfd>>. It
contains the major data about the file, and contains pointers contains the major data about the file and pointers
to the rest of the data. to the rest of the data.
CODE_FRAGMENT CODE_FRAGMENT
@ -54,8 +53,8 @@ CODE_FRAGMENT
. boolean cacheable; . boolean cacheable;
. .
. {* Marks whether there was a default target specified when the . {* Marks whether there was a default target specified when the
. BFD was opened. This is used to select what matching algorithm . BFD was opened. This is used to select which matching algorithm
. to use to chose the back end. *} . to use to choose the back end. *}
. .
. boolean target_defaulted; . boolean target_defaulted;
. .
@ -65,12 +64,11 @@ CODE_FRAGMENT
. struct _bfd *lru_prev, *lru_next; . struct _bfd *lru_prev, *lru_next;
. .
. {* When a file is closed by the caching routines, BFD retains . {* When a file is closed by the caching routines, BFD retains
. state information on the file here: . state information on the file here: *}
. *}
. .
. file_ptr where; . file_ptr where;
. .
. {* and here:*} . {* and here: (``once'' means at least once) *}
. .
. boolean opened_once; . boolean opened_once;
. .
@ -87,7 +85,7 @@ CODE_FRAGMENT
. .
. int ifd; . int ifd;
. .
. {* The format which belongs to the BFD.*} . {* The format which belongs to the BFD. (object, core, etc.) *}
. .
. bfd_format format; . bfd_format format;
. .
@ -109,7 +107,7 @@ CODE_FRAGMENT
. file_ptr origin; . file_ptr origin;
. .
. {* Remember when output has begun, to stop strange things . {* Remember when output has begun, to stop strange things
. happening. *} . from happening. *}
. boolean output_has_begun; . boolean output_has_begun;
. .
. {* Pointer to linked list of sections*} . {* Pointer to linked list of sections*}
@ -125,7 +123,7 @@ CODE_FRAGMENT
. {* Used for input and output*} . {* Used for input and output*}
. unsigned int symcount; . unsigned int symcount;
. .
. {* Symbol table for output BFD*} . {* Symbol table for output BFD (with symcount entries) *}
. struct symbol_cache_entry **outsymbols; . struct symbol_cache_entry **outsymbols;
. .
. {* Pointer to structure which contains architecture information*} . {* Pointer to structure which contains architecture information*}
@ -133,9 +131,9 @@ CODE_FRAGMENT
. .
. {* Stuff only useful for archives:*} . {* Stuff only useful for archives:*}
. PTR arelt_data; . PTR arelt_data;
. struct _bfd *my_archive; . struct _bfd *my_archive; {* The containing archive BFD. *}
. struct _bfd *next; . struct _bfd *next; {* The next BFD in the archive. *}
. struct _bfd *archive_head; . struct _bfd *archive_head; {* The first BFD in the archive. *}
. boolean has_armap; . boolean has_armap;
. .
. {* Used by the back end to hold private data. *} . {* Used by the back end to hold private data. *}
@ -319,77 +317,6 @@ DEFUN(bfd_perror,(message),
} }
} }
/** Symbols */
/*
FUNCTION
bfd_get_reloc_upper_bound
SYNOPSIS
unsigned int bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
DESCRIPTION
This function return the number of bytes required to store the
relocation information associated with section <<sect>>
attached to bfd <<abfd>>
*/
unsigned int
DEFUN(bfd_get_reloc_upper_bound,(abfd, asect),
bfd *abfd AND
sec_ptr asect)
{
if (abfd->format != bfd_object) {
bfd_error = invalid_operation;
return 0;
}
return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));
}
/*
FUNCTION
bfd_canonicalize_reloc
SYNOPSIS
unsigned int bfd_canonicalize_reloc
(bfd *abfd,
asection *sec,
arelent **loc,
asymbol **syms);
DESCRIPTION
This function calls the back end associated with the open
<<abfd>> and translates the external form of the relocation
information attached to <<sec>> into the internal canonical
form. The table is placed into memory at <<loc>>, which has
been preallocated, usually by a call to
<<bfd_get_reloc_upper_bound>>.
The <<syms>> table is also needed for horrible internal magic
reasons.
*/
unsigned int
DEFUN(bfd_canonicalize_reloc,(abfd, asect, location, symbols),
bfd *abfd AND
sec_ptr asect AND
arelent **location AND
asymbol **symbols)
{
if (abfd->format != bfd_object) {
bfd_error = invalid_operation;
return 0;
}
return BFD_SEND (abfd, _bfd_canonicalize_reloc,
(abfd, asect, location, symbols));
}
/* /*
FUNCTION FUNCTION
@ -399,16 +326,15 @@ SYNOPSIS
boolean bfd_set_file_flags(bfd *abfd, flagword flags); boolean bfd_set_file_flags(bfd *abfd, flagword flags);
DESCRIPTION DESCRIPTION
This function attempts to set the flag word in the referenced Set the flag word in the BFD @var{abfd} to the value @var{flags}.
BFD structure to the value supplied.
Possible errors are: Possible errors are:
o wrong_format - The target bfd was not of object format. o wrong_format - The target bfd was not of object format.
o invalid_operation - The target bfd was open for reading. o invalid_operation - The target bfd was open for reading.
o invalid_operation - o invalid_operation -
The flag word contained a bit which was not applicable to the The flag word contained a bit which was not applicable to the
type of file. eg, an attempt was made to set the D_PAGED bit type of file. E.g., an attempt was made to set the D_PAGED bit
on a bfd format which does not support demand paging on a bfd format which does not support demand paging.
*/ */
@ -436,31 +362,6 @@ bfd_set_file_flags (abfd, flags)
return true; return true;
} }
/*
FUNCTION
bfd_set_reloc
SYNOPSIS
void bfd_set_reloc
(bfd *abfd, asection *sec, arelent **rel, unsigned int count)
DESCRIPTION
This function sets the relocation pointer and count within a
section to the supplied values.
*/
/*ARGSUSED*/
void
bfd_set_reloc (ignore_abfd, asect, location, count)
bfd *ignore_abfd;
sec_ptr asect;
arelent **location;
unsigned int count;
{
asect->orelocation = location;
asect->reloc_count = count;
}
void void
bfd_assert(file, line) bfd_assert(file, line)
char *file; char *file;
@ -474,14 +375,14 @@ int line;
FUNCTION FUNCTION
bfd_set_start_address bfd_set_start_address
SYNOPSIS
boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
DESCRIPTION DESCRIPTION
Marks the entry point of an output BFD. Make @var{vma} the entry point of output BFD @var{abfd}.
RETURNS RETURNS
Returns <<true>> on success, <<false>> otherwise. Returns <<true>> on success, <<false>> otherwise.
SYNOPSIS
boolean bfd_set_start_address(bfd *, bfd_vma);
*/ */
boolean boolean
@ -496,14 +397,14 @@ bfd_vma vma;
/* /*
FUNCTION FUNCTION
The bfd_get_mtime function bfd_get_mtime
SYNOPSIS SYNOPSIS
long bfd_get_mtime(bfd *); long bfd_get_mtime(bfd *abfd);
DESCRIPTION DESCRIPTION
Return file modification time (as read from file system, or Return the file modification time (as read from the file system, or
from archive header for archive members). from the archive header for archive members).
*/ */
@ -527,32 +428,32 @@ bfd_get_mtime (abfd)
/* /*
FUNCTION FUNCTION
The bfd_get_size function bfd_get_size
SYNOPSIS SYNOPSIS
long bfd_get_size(bfd *); long bfd_get_size(bfd *abfd);
DESCRIPTION DESCRIPTION
Return file size (as read from file system) for the file Return the file size (as read from file system) for the file
associated with a bfd. associated with BFD @var{abfd}.
Note that the initial motivation for, and use of, this routine is not 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 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?). that might not be generally possible (archive members for example).
Although it would be ideal if someone could eventually modify It would be ideal if someone could eventually modify
it so that such results were guaranteed. it so that such results were guaranteed.
Instead, we want to ask questions like "is this NNN byte sized Instead, we want to ask questions like "is this NNN byte sized
object I'm about to try read from file offset YYY reasonable?" object I'm about to try read from file offset YYY reasonable?"
As as example of where we might want to do this, some object formats As as example of where we might do this, some object formats
use string tables for which the first sizeof(long) bytes of the table use string tables for which the first <<sizeof(long)>> bytes of the
contain the size of the table itself, including the size bytes. 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 If an application tries to read what it thinks is one of these
string tables, without some way to validate the size, and for string tables, without some way to validate the size, and for
some reason the size is wrong (byte swapping error, wrong location 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 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 error when it tries to read the table, or a "virtual memory
exhausted" error when it tries to allocated 15 bazillon bytes exhausted" error when it tries to allocate 15 bazillon bytes
of space for the 15 bazillon byte table it is about to read. of space for the 15 bazillon byte table it is about to read.
This function at least allows us to answer the quesion, "is the This function at least allows us to answer the quesion, "is the
size reasonable?". size reasonable?".
@ -574,13 +475,13 @@ bfd_get_size (abfd)
/* /*
FUNCTION FUNCTION
The bfd_get_gp_size function bfd_get_gp_size
SYNOPSIS SYNOPSIS
int bfd_get_gp_size(bfd *); int bfd_get_gp_size(bfd *abfd);
DESCRIPTION DESCRIPTION
Get the maximum size of objects to be optimized using the GP Return the maximum size of objects to be optimized using the GP
register under MIPS ECOFF. This is typically set by the -G register under MIPS ECOFF. This is typically set by the -G
argument to the compiler, assembler or linker. argument to the compiler, assembler or linker.
*/ */
@ -596,10 +497,10 @@ bfd_get_gp_size (abfd)
/* /*
FUNCTION FUNCTION
The bfd_set_gp_size function bfd_set_gp_size
SYNOPSIS SYNOPSIS
void bfd_set_gp_size(bfd *, int); void bfd_set_gp_size(bfd *abfd, int i);
DESCRIPTION DESCRIPTION
Set the maximum size of objects to be optimized using the GP Set the maximum size of objects to be optimized using the GP
@ -622,20 +523,20 @@ bfd_set_gp_size (abfd, i)
FUNCTION FUNCTION
bfd_scan_vma bfd_scan_vma
SYNOPSIS
bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
DESCRIPTION DESCRIPTION
Converts, like strtoul, a numerical expression as a Convert, like <<strtoul>>, a numerical expression
string into a bfd_vma integer, and returns that integer. @var{string} into a bfd_vma integer, and returns that integer.
(Though without as many bells and whistles as strtoul.) (Though without as many bells and whistles as <<strtoul>>.)
The expression is assumed to be unsigned (i.e. positive). The expression is assumed to be unsigned (i.e. positive).
If given a base, it is used as the base for conversion. If given a @var{base}, it is used as the base for conversion.
A base of 0 causes the function to interpret the string A base of 0 causes the function to interpret the string
in hex if a leading "0x" or "0X" is found, otherwise in hex if a leading "0x" or "0X" is found, otherwise
in octal if a leading zero is found, otherwise in decimal. in octal if a leading zero is found, otherwise in decimal.
Overflow is not detected. Overflow is not detected.
SYNOPSIS
bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
*/ */
bfd_vma bfd_vma
@ -697,7 +598,7 @@ FUNCTION
stuff stuff
DESCRIPTION DESCRIPTION
stuff which should be documented Stuff which should be documented:
.#define bfd_sizeof_headers(abfd, reloc) \ .#define bfd_sizeof_headers(abfd, reloc) \
. BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc)) . BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))

View File

@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* /*
SECTION SECTION
File Caching File caching
The file caching mechanism is embedded within BFD and allows The file caching mechanism is embedded within BFD and allows
the application to open as many BFDs as it wants without the application to open as many BFDs as it wants without
@ -28,7 +28,7 @@ SECTION
limit (often as low as 20 open files). The module in limit (often as low as 20 open files). The module in
<<cache.c>> maintains a least recently used list of <<cache.c>> maintains a least recently used list of
<<BFD_CACHE_MAX_OPEN>> files, and exports the name <<BFD_CACHE_MAX_OPEN>> files, and exports the name
<<bfd_cache_lookup>> which runs around and makes sure that <<bfd_cache_lookup>>, which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file close, closes it and opens the one wanted, returning its file
handle. handle.
@ -52,6 +52,12 @@ DESCRIPTION
*/ */
static boolean
bfd_cache_delete PARAMS ((bfd *));
/* Number of bfds on the chain. All such bfds have their file open;
if it closed, they get snipd()d from the chain. */
static int open_files; static int open_files;
static bfd *cache_sentinel; /* Chain of BFDs with active fds we've static bfd *cache_sentinel; /* Chain of BFDs with active fds we've
@ -73,26 +79,23 @@ DESCRIPTION
bfd *bfd_last_cache; bfd *bfd_last_cache;
/* /*
* INTERNAL_FUNCTION INTERNAL_FUNCTION
* bfd_cache_lookup bfd_cache_lookup
*
* DESCRIPTION DESCRIPTION
* Checks to see if the required BFD is the same as the last one Check to see if the required BFD is the same as the last one
* looked up. If so then it can use the iostream in the BFD with looked up. If so, then it can use the stream in the BFD with
* impunity, since it can't have changed since the last lookup, impunity, since it can't have changed since the last lookup;
* otherwise it has to perform the complicated lookup function otherwise, it has to perform the complicated lookup function.
*
* .#define bfd_cache_lookup(x) \ .#define bfd_cache_lookup(x) \
* . ((x)==bfd_last_cache? \ . ((x)==bfd_last_cache? \
* . (FILE*)(bfd_last_cache->iostream): \ . (FILE*)(bfd_last_cache->iostream): \
* . bfd_cache_lookup_worker(x)) . bfd_cache_lookup_worker(x))
*
*
*/ */
static boolean EXFUN(bfd_cache_delete,(bfd *));
static void static void
DEFUN_VOID(close_one) DEFUN_VOID(close_one)
{ {
@ -161,22 +164,16 @@ DEFUN(insert,(x,y),
} }
/* /* Initialize a BFD by putting it on the cache LRU. */
INTERNAL_FUNCTION
bfd_cache_init
SYNOPSIS
void bfd_cache_init (bfd *);
DESCRIPTION
Initialize a BFD by putting it on the cache LRU.
*/
void void
DEFUN(bfd_cache_init,(abfd), DEFUN(bfd_cache_init,(abfd),
bfd *abfd) bfd *abfd)
{ {
if (open_files >= BFD_CACHE_MAX_OPEN)
close_one ();
cache_sentinel = insert(abfd, cache_sentinel); cache_sentinel = insert(abfd, cache_sentinel);
++open_files;
} }
@ -184,12 +181,12 @@ DEFUN(bfd_cache_init,(abfd),
INTERNAL_FUNCTION INTERNAL_FUNCTION
bfd_cache_close bfd_cache_close
DESCRIPTION
Remove the BFD from the cache. If the attached file is open,
then close it too.
SYNOPSIS SYNOPSIS
boolean bfd_cache_close (bfd *); boolean bfd_cache_close (bfd *abfd);
DESCRIPTION
Remove the BFD @var{abfd} from the cache. If the attached file is open,
then close it too.
RETURNS RETURNS
<<false>> is returned if closing the file fails, <<true>> is <<false>> is returned if closing the file fails, <<true>> is
@ -214,15 +211,15 @@ DEFUN(bfd_cache_close,(abfd),
INTERNAL_FUNCTION INTERNAL_FUNCTION
bfd_open_file bfd_open_file
DESCRIPTION
Call the OS to open a file for this BFD. Returns the FILE *
(possibly null) that results from this operation. Sets up the
BFD so that future accesses know the file is open. If the FILE
* returned is null, then there is won't have been put in the
cache, so it won't have to be removed from it.
SYNOPSIS SYNOPSIS
FILE* bfd_open_file(bfd *); FILE* bfd_open_file(bfd *abfd);
DESCRIPTION
Call the OS to open a file for @var{abfd}. Return the <<FILE *>>
(possibly NULL) that results from this operation. Set up the
BFD so that future accesses know the file is open. If the <<FILE *>>
returned is NULL, then it won't have been put in the
cache, so it won't have to be removed from it.
*/ */
FILE * FILE *
@ -256,7 +253,6 @@ DEFUN(bfd_open_file, (abfd),
} }
if (abfd->iostream) { if (abfd->iostream) {
open_files++;
bfd_cache_init (abfd); bfd_cache_init (abfd);
} }
@ -267,16 +263,16 @@ DEFUN(bfd_open_file, (abfd),
INTERNAL_FUNCTION INTERNAL_FUNCTION
bfd_cache_lookup_worker bfd_cache_lookup_worker
SYNOPSIS
FILE *bfd_cache_lookup_worker(bfd *abfd);
DESCRIPTION DESCRIPTION
Called when the macro <<bfd_cache_lookup>> fails to find a Called when the macro <<bfd_cache_lookup>> fails to find a
quick answer. Finds a file descriptor for this BFD. If quick answer. Find a file descriptor for @var{abfd}. If
necessary, it open it. If there are already more than necessary, it open it. If there are already more than
BFD_CACHE_MAX_OPEN files open, it trys to close one first, to <<BFD_CACHE_MAX_OPEN>> files open, it tries to close one first, to
avoid running out of file descriptors. avoid running out of file descriptors.
SYNOPSIS
FILE *bfd_cache_lookup_worker(bfd *);
*/ */
FILE * FILE *

View File

@ -28,55 +28,55 @@ SECTION
coff backends coff backends
BFD supports a number of different flavours of coff format. BFD supports a number of different flavours of coff format.
The major difference between formats are the sizes and The major differences between formats are the sizes and
alignments of fields in structures on disk, and the occasional alignments of fields in structures on disk, and the occasional
extra field. extra field.
Coff in all its varieties is implimented with a few common Coff in all its varieties is implemented with a few common
files and a number of implementation specific files. For files and a number of implementation specific files. For
example, The 88k bcs coff format is implemented in the file example, The 88k bcs coff format is implemented in the file
@code{coff-m88k.c}. This file @code{#include}s @file{coff-m88k.c}. This file @code{#include}s
@code{coff/m88k.h} which defines the external structure of the @file{coff/m88k.h} which defines the external structure of the
coff format for the 88k, and @code{coff/internal.h} which coff format for the 88k, and @file{coff/internal.h} which
defines the internal structure. @code{coff-m88k.c} also defines the internal structure. @file{coff-m88k.c} also
defines the relocations used by the 88k format defines the relocations used by the 88k format
@xref{Relocations}. @xref{Relocations}.
The Intel i960 processor version of coff is implemented in The Intel i960 processor version of coff is implemented in
@code{coff-i960.c}. This file has the same structure as @file{coff-i960.c}. This file has the same structure as
@code{coff-m88k.c}, except that it includes @code{coff/i960.h} @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
rather than @code{coff-m88k.h}. rather than @file{coff-m88k.h}.
SUBSECTION SUBSECTION
Porting To A New Version of Coff Porting to a new version of coff
The recommended method is to select from the existing The recommended method is to select from the existing
implimentations the version of coff which is most like the one implementations the version of coff which is most like the one
you want to use, for our purposes, we'll say that i386 coff is you want to use. For example, we'll say that i386 coff is
the one you select, and that your coff flavour is called foo. the one you select, and that your coff flavour is called foo.
Copy the @code{i386coff.c} to @code{foocoff.c}, copy Copy @file{i386coff.c} to @file{foocoff.c}, copy
@code{../include/coff/i386.h} to @code{../include/coff/foo.h} @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
and add the lines to @code{targets.c} and @code{Makefile.in} and add the lines to @file{targets.c} and @file{Makefile.in}
so that your new back end is used. Alter the shapes of the so that your new back end is used. Alter the shapes of the
structures in @code{../include/coff/foo.h} so that they match structures in @file{../include/coff/foo.h} so that they match
what you need. You will probably also have to add what you need. You will probably also have to add
@code{#ifdef}s to the code in @code{coff/internal.h} and @code{#ifdef}s to the code in @file{coff/internal.h} and
@code{coffcode.h} if your version of coff is too wild. @file{coffcode.h} if your version of coff is too wild.
You can verify that your new BFD backend works quite simply by You can verify that your new BFD backend works quite simply by
building @code{objdump} from the @code{binutils} directory, building @file{objdump} from the @file{binutils} directory,
and making sure that its version of what's going on at your and making sure that its version of what's going on and your
host systems idea (assuming it has the pretty standard coff host system's idea (assuming it has the pretty standard coff
dump utility (usually called @code{att-dump} or just dump utility, usually called @code{att-dump} or just
@code{dump})) are the same. Then clean up your code, and send @code{dump}) are the same. Then clean up your code, and send
what you've done to Cygnus. Then your stuff will be in the what you've done to Cygnus. Then your stuff will be in the
next release, and you won't have to keep integrating it. next release, and you won't have to keep integrating it.
SUBSECTION SUBSECTION
How The Coff Backend Works How the coff backend works
SUBSUBSECTION SUBSUBSECTION
File Layout File layout
The Coff backend is split into generic routines that are The Coff backend is split into generic routines that are
applicable to any Coff target and routines that are specific applicable to any Coff target and routines that are specific
@ -91,7 +91,7 @@ SUBSUBSECTION
structure, one of which exists for each target. structure, one of which exists for each target.
The essentially similar target-specific routines are in The essentially similar target-specific routines are in
@file{coffcode.h}. This header file includes executable code. @file{coffcode.h}. This header file includes executable C code.
The various Coff targets first include the appropriate Coff The various Coff targets first include the appropriate Coff
header file, make any special defines that are needed, and header file, make any special defines that are needed, and
then include @file{coffcode.h}. then include @file{coffcode.h}.
@ -109,24 +109,24 @@ SUBSUBSECTION
target. target.
SUBSUBSECTION SUBSUBSECTION
Bit Twiddling Bit twiddling
Each flavour of coff supported in BFD has its own header file Each flavour of coff supported in BFD has its own header file
descibing the external layout of the structures. There is also describing the external layout of the structures. There is also
an internal description of the coff layout (in an internal description of the coff layout, in
@code{coff/internal.h}). A major function of the @file{coff/internal.h}. A major function of the
coff backend is swapping the bytes and twiddling the bits to coff backend is swapping the bytes and twiddling the bits to
translate the external form of the structures into the normal translate the external form of the structures into the normal
internal form. This is all performed in the internal form. This is all performed in the
@code{bfd_swap}_@i{thing}_@i{direction} routines. Some @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
elements are different sizes between different versions of elements are different sizes between different versions of
coff, it is the duty of the coff version specific include file coff; it is the duty of the coff version specific include file
to override the definitions of various packing routines in to override the definitions of various packing routines in
@code{coffcode.h}. Eg the size of line number entry in coff is @file{coffcode.h}. E.g., the size of line number entry in coff is
sometimes 16 bits, and sometimes 32 bits. @code{#define}ing sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
correct one. No doubt, some day someone will find a version of correct one. No doubt, some day someone will find a version of
coff which has a varying field size not catered for at the coff which has a varying field size not catered to at the
moment. To port BFD, that person will have to add more @code{#defines}. moment. To port BFD, that person will have to add more @code{#defines}.
Three of the bit twiddling routines are exported to Three of the bit twiddling routines are exported to
@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in} @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
@ -139,29 +139,29 @@ SUBSUBSECTION
@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
of all the symbol table and reloc drudgery itself, thereby of all the symbol table and reloc drudgery itself, thereby
saving the internal BFD overhead, but uses BFD to swap things saving the internal BFD overhead, but uses BFD to swap things
on the way out, making cross ports much safer. This also on the way out, making cross ports much safer. Doing so also
allows BFD (and thus the linker) to use the same header files allows BFD (and thus the linker) to use the same header files
as @code{gas}, which makes one avenue to disaster disappear. as @code{gas}, which makes one avenue to disaster disappear.
SUBSUBSECTION SUBSUBSECTION
Symbol Reading Symbol reading
The simple canonical form for symbols used by BFD is not rich The simple canonical form for symbols used by BFD is not rich
enough to keep all the information available in a coff symbol enough to keep all the information available in a coff symbol
table. The back end gets around this by keeping the original table. The back end gets around this problem by keeping the original
symbol table around, "behind the scenes". symbol table around, "behind the scenes".
When a symbol table is requested (through a call to When a symbol table is requested (through a call to
@code{bfd_canonicalize_symtab}, a request gets through to @code{bfd_canonicalize_symtab}), a request gets through to
@code{coff_get_normalized_symtab}. This reads the symbol table from @code{coff_get_normalized_symtab}. This reads the symbol table from
the coff file and swaps all the structures inside into the the coff file and swaps all the structures inside into the
internal form. It also fixes up all the pointers in the table internal form. It also fixes up all the pointers in the table
(represented in the file by offsets from the first symbol in (represented in the file by offsets from the first symbol in
the table) into physical pointers to elements in the new the table) into physical pointers to elements in the new
internal table. This involves some work since the meanings of internal table. This involves some work since the meanings of
fields changes depending upon context; a field that is a fields change depending upon context: a field that is a
pointer to another structure in the symbol table at one moment pointer to another structure in the symbol table at one moment
may be the size in bytes of a structure in the next. Another may be the size in bytes of a structure at the next. Another
pass is made over the table. All symbols which mark file names pass is made over the table. All symbols which mark file names
(<<C_FILE>> symbols) are modified so that the internal (<<C_FILE>> symbols) are modified so that the internal
string points to the value in the auxent (the real filename) string points to the value in the auxent (the real filename)
@ -170,28 +170,28 @@ SUBSUBSECTION
At this time the symbol names are moved around. Coff stores At this time the symbol names are moved around. Coff stores
all symbols less than nine characters long physically all symbols less than nine characters long physically
within the symbol table, longer strings are kept at the end of within the symbol table; longer strings are kept at the end of
the file in the string table. This pass moves all strings the file in the string table. This pass moves all strings
into memory, and replaces them with pointers to the strings. into memory and replaces them with pointers to the strings.
The symbol table is massaged once again, this time to create The symbol table is massaged once again, this time to create
the canonical table used by the BFD application. Each symbol the canonical table used by the BFD application. Each symbol
is inspected in turn, and a decision made (using the is inspected in turn, and a decision made (using the
@code{sclass} field) about the various flags to set in the @code{sclass} field) about the various flags to set in the
@code{asymbol} @xref{Symbols}. The generated canonical table @code{asymbol}. @xref{Symbols}. The generated canonical table
shares strings with the hidden internal symbol table. shares strings with the hidden internal symbol table.
Any linenumbers are read from the coff file too, and attached Any linenumbers are read from the coff file too, and attached
to the symbols which own the functions the linenumbers belong to. to the symbols which own the functions the linenumbers belong to.
SUBSUBSECTION SUBSUBSECTION
Symbol Writing Symbol writing
Writing a symbol to a coff file which didn't come from a coff Writing a symbol to a coff file which didn't come from a coff
file will lose any debugging information. The @code{asymbol} file will lose any debugging information. The @code{asymbol}
structure remembers the BFD from which was born, and on output structure remembers the BFD from which the symbol was taken, and on
the back end makes sure that the same destination target as output the back end makes sure that the same destination target as
source target is present. source target is present.
When the symbols have come from a coff file then all the When the symbols have come from a coff file then all the
@ -215,24 +215,23 @@ SUBSUBSECTION
0x100, would have the value 0x20. Coff expects symbols to 0x100, would have the value 0x20. Coff expects symbols to
contain their final value, so symbols have their values contain their final value, so symbols have their values
changed at this point to reflect their sum with their owning changed at this point to reflect their sum with their owning
section. Note that this transformation uses the section. This transformation uses the
<<output_section>> field of the @code{asymbol}'s <<output_section>> field of the @code{asymbol}'s
@code{asection} @xref{Sections}. @code{asection} @xref{Sections}.
o coff_mangle_symbols o <<coff_mangle_symbols>>
This routine runs though the provided symbol table and uses This routine runs though the provided symbol table and uses
the offsets generated by the previous pass and the pointers the offsets generated by the previous pass and the pointers
generated when the symbol table was read in to create the generated when the symbol table was read in to create the
structured hierachy required by coff. It changes each pointer structured hierachy required by coff. It changes each pointer
to a symbol to an index into the symbol table of the symbol to a symbol into the index into the symbol table of the asymbol.
being referenced.
o coff_write_symbols o <<coff_write_symbols>>
This routine runs through the symbol table and patches up the This routine runs through the symbol table and patches up the
symbols from their internal form into the coff way, calls the symbols from their internal form into the coff way, calls the
bit twiddlers and writes out the tabel to the file. bit twiddlers, and writes out the table to the file.
*/ */
@ -241,8 +240,8 @@ INTERNAL_DEFINITION
coff_symbol_type coff_symbol_type
DESCRIPTION DESCRIPTION
The hidden information for an asymbol is described in a The hidden information for an <<asymbol>> is described in a
coff_ptr_struct, which is typedefed to a combined_entry_type <<combined_entry_type>>:
CODE_FRAGMENT CODE_FRAGMENT
. .
@ -472,7 +471,7 @@ INTERNAL_DEFINITION
CODE_FRAGMENT CODE_FRAGMENT
Special entry points for gdb to swap in coff symbol table parts Special entry points for gdb to swap in coff symbol table parts:
.typedef struct .typedef struct
.{ .{
. void (*_bfd_coff_swap_aux_in) PARAMS (( . void (*_bfd_coff_swap_aux_in) PARAMS ((
@ -493,7 +492,7 @@ Special entry points for gdb to swap in coff symbol table parts
. PTR in)); . PTR in));
. .
Special entry points for gas to swap coff parts Special entry points for gas to swap out coff parts:
. unsigned int (*_bfd_coff_swap_aux_out) PARAMS (( . unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
. bfd *abfd, . bfd *abfd,
@ -534,7 +533,7 @@ Special entry points for gas to swap coff parts
. .
Special entry points for generic COFF routines to call target Special entry points for generic COFF routines to call target
dependent COFF routines dependent COFF routines:
. unsigned int _bfd_filhsz; . unsigned int _bfd_filhsz;
. unsigned int _bfd_aoutsz; . unsigned int _bfd_aoutsz;
@ -845,7 +844,7 @@ coff_set_arch_mach_hook(abfd, filehdr)
case I386MAGIC: case I386MAGIC:
case I386PTXMAGIC: case I386PTXMAGIC:
case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */ case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */
case I386LYNXMAGIC: case LYNXCOFFMAGIC: /* shadows the m68k Lynx number below, sigh */
arch = bfd_arch_i386; arch = bfd_arch_i386;
machine = 0; machine = 0;
break; break;
@ -867,6 +866,9 @@ coff_set_arch_mach_hook(abfd, filehdr)
#endif #endif
#ifdef APOLLOM68KMAGIC #ifdef APOLLOM68KMAGIC
case APOLLOM68KMAGIC: case APOLLOM68KMAGIC:
#endif
#ifdef LYNXCOFFMAGIC
case LYNXCOFFMAGIC:
#endif #endif
arch = bfd_arch_m68k; arch = bfd_arch_m68k;
machine = 68020; machine = 68020;
@ -975,6 +977,13 @@ coff_set_arch_mach_hook(abfd, filehdr)
break; break;
#endif #endif
#ifdef SPARCMAGIC
case SPARCMAGIC:
arch = bfd_arch_sparc;
machine = 0;
break;
#endif
default: /* Unreadable input file type */ default: /* Unreadable input file type */
arch = bfd_arch_obscure; arch = bfd_arch_obscure;
break; break;
@ -1003,14 +1012,14 @@ DEFUN (symname_in_debug_hook, (abfd, sym),
/* /*
SUBSUBSECTION SUBSUBSECTION
Writing Relocations Writing relocations
To write relocations, all the back end does is step though the To write relocations, the back end steps though the
canonical relocation table, and create an canonical relocation table and create an
@code{internal_reloc}. The symbol index to use is removed from @code{internal_reloc}. The symbol index to use is removed from
the @code{offset} field in the symbol table supplied, the the @code{offset} field in the symbol table supplied. The
address comes directly from the sum of the section base address comes directly from the sum of the section base
address and the relocation offset and the type is dug directly address and the relocation offset; the type is dug directly
from the howto field. Then the @code{internal_reloc} is from the howto field. Then the @code{internal_reloc} is
swapped into the shape of an @code{external_reloc} and written swapped into the shape of an @code{external_reloc} and written
out to disk. out to disk.
@ -1142,6 +1151,10 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
#ifdef I386MAGIC #ifdef I386MAGIC
case bfd_arch_i386: case bfd_arch_i386:
*magicp = I386MAGIC; *magicp = I386MAGIC;
#ifdef LYNXOS
/* Just overwrite the usual value if we're doing Lynx. */
*magicp = LYNXCOFFMAGIC;
#endif
return true; return true;
break; break;
#endif #endif
@ -1151,6 +1164,10 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
*magicp = APOLLO_COFF_VERSION_NUMBER; *magicp = APOLLO_COFF_VERSION_NUMBER;
#else #else
*magicp = MC68MAGIC; *magicp = MC68MAGIC;
#endif
#ifdef LYNXOS
/* Just overwrite the usual value if we're doing Lynx. */
*magicp = LYNXCOFFMAGIC;
#endif #endif
return true; return true;
break; break;
@ -1183,6 +1200,17 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
break; break;
#endif #endif
#ifdef SPARCMAGIC
case bfd_arch_sparc:
*magicp = SPARCMAGIC;
#ifdef LYNXOS
/* Just overwrite the usual value if we're doing Lynx. */
*magicp = LYNXCOFFMAGIC;
#endif
return true;
break;
#endif
#ifdef H8500MAGIC #ifdef H8500MAGIC
case bfd_arch_h8500: case bfd_arch_h8500:
*magicp = H8500MAGIC; *magicp = H8500MAGIC;
@ -1795,7 +1823,7 @@ buy_and_read(abfd, where, seek_direction, size)
/* /*
SUBSUBSECTION SUBSUBSECTION
Reading Linenumbers Reading linenumbers
Creating the linenumber table is done by reading in the entire Creating the linenumber table is done by reading in the entire
coff linenumber table, and creating another table for internal use. coff linenumber table, and creating another table for internal use.
@ -2093,22 +2121,22 @@ DEFUN(coff_slurp_symbol_table,(abfd),
/* /*
SUBSUBSECTION SUBSUBSECTION
Reading Relocations Reading relocations
Coff relocations are easily transformed into the internal BFD form Coff relocations are easily transformed into the internal BFD form
(@code{arelent}). (@code{arelent}).
Reading a coff relocation table is done in the following stages: Reading a coff relocation table is done in the following stages:
o The entire coff relocation table is read into memory. o Read the entire coff relocation table into memory.
o Each relocation is processed in turn, first it is swapped from the o Process each relocation in turn; first swap it from the
external to the internal form. external to the internal form.
o The symbol referenced in the relocation's symbol index is o Turn the symbol referenced in the relocation's symbol index
turned intoa pointer into the canonical symbol table. Note into a pointer into the canonical symbol table.
that this table is the same as the one returned by a call to This table is the same as the one returned by a call to
@code{bfd_canonicalize_symtab}. The back end will call the @code{bfd_canonicalize_symtab}. The back end will call that
routine and save the result if a canonicalization hasn't been done. routine and save the result if a canonicalization hasn't been done.
o The reloc index is turned into a pointer to a howto o The reloc index is turned into a pointer to a howto

View File

@ -23,7 +23,7 @@ SECTION
Core files Core files
DESCRIPTION DESCRIPTION
Buff output this facinating topic These are functions pertaining to core files.
*/ */
#include "bfd.h" #include "bfd.h"
@ -36,11 +36,11 @@ FUNCTION
bfd_core_file_failing_command bfd_core_file_failing_command
SYNOPSIS SYNOPSIS
CONST char *bfd_core_file_failing_command(bfd *); CONST char *bfd_core_file_failing_command(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns a read-only string explaining what program was running Return a read-only string explaining which program was running
when it failed and produced the core file being read when it failed and produced the core file @var{abfd}.
*/ */
@ -60,11 +60,11 @@ FUNCTION
bfd_core_file_failing_signal bfd_core_file_failing_signal
SYNOPSIS SYNOPSIS
int bfd_core_file_failing_signal(bfd *); int bfd_core_file_failing_signal(bfd *abfd);
DESCRIPTION DESCRIPTION
Returns the signal number which caused the core dump which Returns the signal number which caused the core dump which
generated the file the BFD is attached to. generated the file the BFD @var{abfd} is attached to.
*/ */
int int
@ -88,7 +88,7 @@ SYNOPSIS
(bfd *core_bfd, bfd *exec_bfd); (bfd *core_bfd, bfd *exec_bfd);
DESCRIPTION DESCRIPTION
Returns <<true>> if the core file attached to @var{core_bfd} Return <<true>> if the core file attached to @var{core_bfd}
was generated by a run of the executable file attached to was generated by a run of the executable file attached to
@var{exec_bfd}, or else <<false>>. @var{exec_bfd}, or else <<false>>.
*/ */

View File

@ -25,27 +25,27 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
Constructors Constructors
Classes in C++ have `constructors' and `destructors'. These Classes in C++ have @dfn{constructors} and @dfn{destructors}. These
are functions which are called automatically by the language are functions which are called automatically by the language
whenever data of a class is created or destroyed. Class data whenever data of a class is created or destroyed. Class data
which is static data may also be have a type which requires which is static may also be have a type which requires
`construction', the contructor must be called before the data `construction'; the contructor must be called before the data
can be referenced, so the contructor must be called before the can be referenced, so the contructor must be called before the
program begins. program begins.
The common solution to this problem is for the compiler to The common solution to this problem is for the compiler to
call a magic function as the first statement <<main>>. call a magic function as the first statement before <<main>>.
This magic function, (often called <<__main>>) runs around This magic function (often called <<__main>>) runs around
calling the constructors for all the things needing it. calling the constructors for all the things needing it.
With COFF the compile has a bargain with the linker et al. With COFF, the compiler has a bargain with the linker et al.
All constructors are given strange names, for example All constructors are given strange names; for example,
<<__GLOBAL__$I$foo>> might be the label of a contructor for <<__GLOBAL__$I$foo>> might be the label of a contructor for
the class @var{foo}. The solution on unfortunate systems the class @var{foo}. The solution on unfortunate systems
(most system V machines) is to perform a partial link on all (most System V machines) is to perform a partial link on all
the <<.o>> files, do an <<nm>> on the result, run <<awk>> or some the <<.o>> files, do an <<nm>> on the result, run <<awk>> or some
such over the result looking for strange <<__GLOBAL__$>> such over the result looking for strange <<__GLOBAL__$>>
symbols, generate a C program from this, compile it and link symbols, generate a C program from this, compile it, and link
with the partially linked input. This process is usually with the partially linked input. This process is usually
called <<collect>>. called <<collect>>.
@ -54,10 +54,10 @@ SECTION
from the compiler with a special stab code saying that they from the compiler with a special stab code saying that they
are constructors, and the linker can deal with them directly. are constructors, and the linker can deal with them directly.
BFD allows applications (ie the linker) to deal with BFD allows applications (i.e., the linker) to deal with
constructor information independently of their external constructor information independently of their external
implimentation by providing a set of entry points for the implementation by providing a set of entry points for the
indiviual object back ends to call which maintains a database indiviual object back ends to call to maintain a database
of the contructor information. The application can of the contructor information. The application can
interrogate the database to find out what it wants. The interrogate the database to find out what it wants. The
construction data essential for the linker to be able to construction data essential for the linker to be able to
@ -71,15 +71,15 @@ SECTION
The type of symbol, i.e., is it a constructor, a destructor or The type of symbol, i.e., is it a constructor, a destructor or
something else someone dreamed up to make our lives difficult. something else someone dreamed up to make our lives difficult.
This module takes this information and then builds extra The constructor module takes this information and builds extra
sections attached to the bfds which own the entry points. It sections attached to the BFDs which own the entry points. It
creates these sections as if they were tables of pointers to creates these sections as if they were tables of pointers to
the entry points, and builds relocation entries to go with the entry points, and builds relocation entries to go with
them so that the tables can be relocated along with the data them so that the tables can be relocated along with the data
they reference. they reference.
These sections are marked with a special bit These sections are marked with a special bit
(<<SEC_CONSTRUCTOR>>) which the linker notices and do with (<<SEC_CONSTRUCTOR>>), which the linker notices and does with
what it wants. what it wants.
*/ */
@ -101,11 +101,11 @@ SYNOPSIS
DESCRIPTION DESCRIPTION
This function is called with an a symbol describing the @var{symbol_ptr_ptr} describes the
function to be called, an string which descibes the xtor type, function to be called; @var{type} descibes the xtor type,
e.g., something like "CTOR" or "DTOR" would be fine. And the bfd e.g., something like "CTOR" or "DTOR" would be fine. @var{abfd}
which owns the function. Its duty is to create a section is the BFD which owns the function. Create a section
called "CTOR" or "DTOR" or whatever if the bfd doesn't already called "CTOR" or "DTOR" or whatever if the BFD doesn't already
have one, and grow a relocation table for the entry points as have one, and grow a relocation table for the entry points as
they accumulate. they accumulate.
@ -116,7 +116,6 @@ void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
bfd *abfd AND bfd *abfd AND
asymbol **symbol_ptr_ptr AND asymbol **symbol_ptr_ptr AND
CONST char *type) CONST char *type)
{ {
/* Look up the section we're using to store the table in */ /* Look up the section we're using to store the table in */
asection *rel_section = bfd_get_section_by_name (abfd, type); asection *rel_section = bfd_get_section_by_name (abfd, type);

View File

@ -18,57 +18,74 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/*doc* /*
@section File Formats SECTION
A format is a BFD concept of high level file contents. The File Formats
formats supported by BFD are:
@table @code
@item bfd_object
The BFD may contain data, symbols, relocations and debug info.
@item bfd_archive
The BFD contains other BFDs and an optional index.
@item bfd_core
The BFD contains the result of an executable core dump.
@end table
*/
#include "sysdep.h"
#include "bfd.h"
#include "libbfd.h"
A format is a BFD concept of high level file contents type. The
formats supported by BFD are:
o <<bfd_object>>
The BFD may contain data, symbols, relocations and debug info.
o <<bfd_archive>>
The BFD contains other BFDs and an optional index.
o <<bfd_core>>
The BFD contains the result of an executable core dump.
*/
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
extern bfd_target *target_vector[]; extern bfd_target *target_vector[];
extern bfd_target *default_vector[]; extern bfd_target *default_vector[];
/*proto* /*
*i bfd_check_format FUNCTION
This routine is supplied a BFD and a format. It attempts to verify if bfd_check_format
the file attatched to the BFD is indeed compatible with the format
specified (ie, one of @code{bfd_object}, @code{bfd_archive} or
@code{bfd_core}).
If the BFD has been set to a specific @var{target} before the call, SYNOPSIS
only the named target and format combination will be checked. If the boolean bfd_check_format(bfd *abfd, bfd_format format);
target has not been set, or has been set to @code{default} then all
the known target backends will be interrogated to determine a match.
The function returns @code{true} on success, otherwise @code{false} DESCRIPTION
Verify if the file attached to the BFD @var{abfd} is compatible
with the format @var{format} (i.e., one of <<bfd_object>>,
<<bfd_archive>> or <<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
<<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 <<true>> on success, otherwise <<false>>
with one of the following error codes: with one of the following error codes:
@table @code
@item o invalid_operation -
invalid_operation if <<format>> is not one of <<bfd_object>>, <<bfd_archive>> or
if @code{format} is not one of @code{bfd_object}, @code{bfd_archive} <<bfd_core>>.
or @code{bfd_core}.
@item system_call_error o system_call_error -
if an error occured during a read - even some file mismatches can if an error occured during a read - even some file mismatches
cause system_call_errros can cause system_call_errors.
@item file_not_recognised
none of the backends recognised the file format o file_not_recognised -
@item file_ambiguously_recognized none of the backends recognised the file format.
o file_ambiguously_recognized -
more than one backend recognised the file format. more than one backend recognised the file format.
@end table
*; PROTO(boolean, bfd_check_format, (bfd *abfd, bfd_format format)); */
*-*/
boolean boolean
DEFUN(bfd_check_format,(abfd, format), DEFUN(bfd_check_format,(abfd, format),
@ -88,6 +105,15 @@ DEFUN(bfd_check_format,(abfd, format),
if (abfd->format != bfd_unknown) if (abfd->format != bfd_unknown)
return (abfd->format == format)? true: false; return (abfd->format == format)? true: false;
/* Since the target type was defaulted, check them
all in the hope that one will be uniquely recognized. */
save_targ = abfd->xvec;
match_count = 0;
right_targ = 0;
/* presume the answer is yes */ /* presume the answer is yes */
abfd->format = format; abfd->format = format;
@ -101,22 +127,17 @@ DEFUN(bfd_check_format,(abfd, format),
abfd->xvec = right_targ; /* Set the target as returned */ abfd->xvec = right_targ; /* Set the target as returned */
return true; /* File position has moved, BTW */ return true; /* File position has moved, BTW */
} }
abfd->format = bfd_unknown;
return false; /* Specified target is not right */
} }
/* Since the target type was defaulted, check them
all in the hope that one will be uniquely recognized. */
save_targ = abfd->xvec;
match_count = 0;
right_targ = 0;
for (target = target_vector; *target != NULL; target++) { for (target = target_vector; *target != NULL; target++) {
bfd_target *temp; bfd_target *temp;
abfd->xvec = *target; /* Change BFD's target temporarily */ abfd->xvec = *target; /* Change BFD's target temporarily */
bfd_seek (abfd, (file_ptr)0, SEEK_SET); bfd_seek (abfd, (file_ptr)0, SEEK_SET);
/* If _bfd_check_format neglects to set bfd_error, assume wrong_format.
We didn't used to even pay any attention to bfd_error, so I suspect
that some _bfd_check_format might have this problem. */
bfd_error = wrong_format;
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
if (temp) { /* This format checks out as ok! */ if (temp) { /* This format checks out as ok! */
right_targ = temp; right_targ = temp;
@ -125,7 +146,10 @@ DEFUN(bfd_check_format,(abfd, format),
might match. People who want those other targets have to set might match. People who want those other targets have to set
the GNUTARGET variable. */ the GNUTARGET variable. */
if (temp == default_vector[0]) if (temp == default_vector[0])
{
match_count = 1;
break; break;
}
#ifdef GNU960 #ifdef GNU960
/* Big- and little-endian b.out archives look the same, but it doesn't /* Big- and little-endian b.out archives look the same, but it doesn't
* matter: there is no difference in their headers, and member file byte * matter: there is no difference in their headers, and member file byte
@ -135,6 +159,10 @@ DEFUN(bfd_check_format,(abfd, format),
*/ */
break; break;
#endif #endif
} else if (bfd_error != wrong_format) {
abfd->xvec = save_targ;
abfd->format = bfd_unknown;
return false;
} }
} }
@ -149,14 +177,23 @@ DEFUN(bfd_check_format,(abfd, format),
file_ambiguously_recognized); file_ambiguously_recognized);
return false; return false;
} }
/*proto*
*i bfd_set_format
This function sets the file format of the supplied BFD to the format /*
requested. If the target set in the BFD does not support the format FUNCTION
requested, the format is illegal or the BFD is not open for writing bfd_set_format
than an error occurs.
*; PROTO(boolean,bfd_set_format,(bfd *, bfd_format)); SYNOPSIS
*-*/ boolean bfd_set_format(bfd *abfd, bfd_format format);
DESCRIPTION
This function sets the file format of the BFD @var{abfd} to the
format @var{format}. If the target set in the BFD does not
support the format requested, the format is invalid, or the BFD
is not open for writing, then an error occurs.
*/
boolean boolean
DEFUN(bfd_set_format,(abfd, format), DEFUN(bfd_set_format,(abfd, format),
bfd *abfd AND bfd *abfd AND
@ -185,13 +222,18 @@ DEFUN(bfd_set_format,(abfd, format),
} }
/*proto* /*
*i bfd_format_string FUNCTION
This function takes one argument, and enumerated type (bfd_format) and bfd_format_string
returns a pointer to a const string "invalid", "object", "archive",
"core" or "unknown" depending upon the value of the enumeration. SYNOPSIS
*; PROTO(CONST char *, bfd_format_string, (bfd_format)); CONST char *bfd_format_string(bfd_format format);
*-*/
DESCRIPTION
Return a pointer to a const string
<<invalid>>, <<object>>, <<archive>>, <<core>>, or <<unknown>>,
depending upon the value of @var{format}.
*/
CONST char * CONST char *
DEFUN(bfd_format_string,(format), DEFUN(bfd_format_string,(format),

View File

@ -17,21 +17,36 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <sysdep.h>
#include "bfd.h" #include "bfd.h"
#include "sysdep.h"
#include "libbfd.h" #include "libbfd.h"
extern void DEFUN_VOID (bfd_section_init);
static boolean initialized = false; static boolean initialized = false;
/*proto* bfd_init /*
SECTION
Initialization
This routine must be called before any other bfd function to initialize These are the functions that handle initializing a BFD.
magical internal data structures.
*; void EXFUN(bfd_init,(void));
*/ */
void DEFUN_VOID(bfd_init) /*
FUNCTION
bfd_init
SYNOPSIS
void bfd_init(void);
DESCRIPTION
This routine must be called before any other libbfd function to
initialize magical internal data structures.
*/
void
bfd_init ()
{ {
if (initialized == false) { if (initialized == false) {
initialized = true; initialized = true;
@ -41,22 +56,24 @@ void DEFUN_VOID(bfd_init)
} }
/*proto-internal* bfd_check_init /*
INTERNAL_FUNCTION
bfd_check_init
This routine is called before any other bfd function using initialized SYNOPSIS
data is used to ensure that the structures have been initialized. void bfd_check_init(void);
Soon this function will go away, and the bfd library will assume that
bfd_init has been called.
*; void EXFUN(bfd_check_init,(void)); DESCRIPTION
This routine is called before any other libbfd function using
initialized data. It ensures that the structures have
been initialized. Soon this function will go away, and the bfd
library will assume that <<bfd_init>> has been called.
*/ */
void DEFUN_VOID(bfd_check_init) void
bfd_check_init ()
{ {
if (initialized == false) { if (initialized == false) {
fprintf(stderr,"The bfd library now requires you to call bfd_init()\n");
fprintf(stderr,"before any other calls to bfd routines. Please\n");
fprintf(stderr,"change your source\n");
bfd_init(); bfd_init();
} }
} }

View File

@ -27,7 +27,7 @@ SECTION
libbfd libbfd
DESCRIPTION DESCRIPTION
This file contains various routines which are used within BFD. These routines are used within BFD.
They are not intended for export, but are documented here for They are not intended for export, but are documented here for
completeness. completeness.
*/ */
@ -138,7 +138,7 @@ SYNOPSIS
PTR bfd_xmalloc( bfd_size_type size); PTR bfd_xmalloc( bfd_size_type size);
DESCRIPTION DESCRIPTION
Like malloc, but exit if no more memory. Like <<malloc>>, but exit if no more memory.
*/ */
@ -157,7 +157,7 @@ DEFUN(PTR bfd_xmalloc,(size),
if (!ptr) if (!ptr)
{ {
write (2, no_memory_message, sizeof(no_memory_message)-1); write (2, no_memory_message, sizeof(no_memory_message)-1);
exit (-1); exit (1);
} }
return ptr; return ptr;
} }
@ -170,8 +170,8 @@ SYNOPSIS
PTR bfd_xmalloc_by_size_t ( size_t size); PTR bfd_xmalloc_by_size_t ( size_t size);
DESCRIPTION DESCRIPTION
Like malloc, but exit if no more memory. Like <<malloc>>, but exit if no more memory.
Uses size_t, so it's suitable for use as obstack_chunk_alloc. Uses <<size_t>>, so it's suitable for use as <<obstack_chunk_alloc>>.
*/ */
PTR PTR
DEFUN(bfd_xmalloc_by_size_t, (size), DEFUN(bfd_xmalloc_by_size_t, (size),
@ -246,8 +246,8 @@ SYNOPSIS
void bfd_write_bigendian_4byte_int(bfd *abfd, int i); void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
DESCRIPTION DESCRIPTION
Writes a 4 byte integer to the outputing bfd, in big endian Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
mode regardless of what else is going on. This is useful in endian order regardless of what else is going on. This is useful in
archives. archives.
*/ */
@ -501,15 +501,14 @@ DESCRIPTION
/* /*
FUNCTION FUNCTION
bfd_h_put_size bfd_h_put_size
FUNCTION
bfd_h_get_size bfd_h_get_size
DESCRIPTION DESCRIPTION
These macros have the same function as their <<bfd_get_x>> These macros have the same function as their <<bfd_get_x>>
bretherin, except that they are used for removing information bretheren, except that they are used for removing information
for the header records of object files. Believe it or not, for the header records of object files. Believe it or not,
some object files keep their header records in big endian some object files keep their header records in big endian
order, and their data in little endian order. order and their data in little endian order.
. .
.{* Byte swapping macros for file header data. *} .{* Byte swapping macros for file header data. *}
. .
@ -850,8 +849,8 @@ INTERNAL_FUNCTION
bfd_log2 bfd_log2
DESCRIPTION DESCRIPTION
Return the log base 2 of the value supplied, rounded up. eg an Return the log base 2 of the value supplied, rounded up. E.g., an
arg of 1025 would return 11. @var{x} of 1025 returns 11.
SYNOPSIS SYNOPSIS
unsigned int bfd_log2(bfd_vma x); unsigned int bfd_log2(bfd_vma x);

View File

@ -44,8 +44,8 @@ struct artdata {
carsym *symdefs; /* the symdef entries */ carsym *symdefs; /* the symdef entries */
symindex symdef_count; /* how many there are */ symindex symdef_count; /* how many there are */
char *extended_names; /* clever intel extension */ char *extended_names; /* clever intel extension */
/* when more compilers are standard C, this can be a time_t */
time_t armap_timestamp; /* Timestamp value written into armap. long armap_timestamp; /* Timestamp value written into armap.
This is used for BSD archives to check This is used for BSD archives to check
that the timestamp is recent enough that the timestamp is recent enough
for the BSD linker to not complain, for the BSD linker to not complain,
@ -212,13 +212,13 @@ extern bfd *bfd_last_cache;
(FILE*)(bfd_last_cache->iostream): \ (FILE*)(bfd_last_cache->iostream): \
bfd_cache_lookup_worker(x)) bfd_cache_lookup_worker(x))
boolean boolean
bfd_cache_close PARAMS ((bfd *)); bfd_cache_close PARAMS ((bfd *abfd));
FILE* FILE*
bfd_open_file PARAMS ((bfd *)); bfd_open_file PARAMS ((bfd *abfd));
FILE * FILE *
bfd_cache_lookup_worker PARAMS ((bfd *)); bfd_cache_lookup_worker PARAMS ((bfd *abfd));
void void
bfd_constructor_entry PARAMS ((bfd *abfd, bfd_constructor_entry PARAMS ((bfd *abfd,
@ -259,7 +259,7 @@ void
bfd_arch_init PARAMS ((void)); bfd_arch_init PARAMS ((void));
void void
bfd_arch_linkin PARAMS ((bfd_arch_info_type *)); bfd_arch_linkin PARAMS ((bfd_arch_info_type *ptr));
CONST bfd_arch_info_type * CONST bfd_arch_info_type *
bfd_default_compatible bfd_default_compatible
@ -267,7 +267,7 @@ bfd_default_compatible
CONST bfd_arch_info_type *b)); CONST bfd_arch_info_type *b));
boolean boolean
bfd_default_scan PARAMS ((CONST struct bfd_arch_info *, CONST char *)); bfd_default_scan PARAMS ((CONST struct bfd_arch_info *info, CONST char *string));
struct elf_internal_shdr * struct elf_internal_shdr *
bfd_elf_find_section PARAMS ((bfd *abfd, char *name)); bfd_elf_find_section PARAMS ((bfd *abfd, char *name));

View File

@ -96,11 +96,14 @@ SYNOPSIS
bfd *bfd_openr(CONST char *filename, CONST char *target); bfd *bfd_openr(CONST char *filename, CONST char *target);
DESCRIPTION DESCRIPTION
This function opens the file supplied (using <<fopen>>) with the target Open the file @var{filename} (using <<fopen>>) with the target
supplied, it returns a pointer to the created BFD. @var{target}. Return a pointer to the created BFD.
If NULL is returned then an error has occured. Possible errors If NULL is returned then an error has occured. Possible errors
are <<no_memory>>, <<invalid_target>> or <<system_call>> error. are <<no_memory>>, <<invalid_target>> or <<system_call>> error.
Calls <<bfd_find_target>>, so @var{target} is interpreted as by
that function.
*/ */
bfd * bfd *
@ -151,11 +154,11 @@ SYNOPSIS
bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd); bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
DESCRIPTION DESCRIPTION
bfd_fdopenr is to bfd_fopenr much like fdopen is to fopen. <<bfd_fdopenr>> is to <<bfd_fopenr>> much like <<fdopen>> is to <<fopen>>.
It opens a BFD on a file already described by the @var{fd} It opens a BFD on a file already described by the @var{fd}
supplied. supplied.
When the file is later bfd_closed, the file descriptor will be closed. When the file is later <<bfd_close>>d, the file descriptor will be closed.
If the caller desires that this file descriptor be cached by BFD If the caller desires that this file descriptor be cached by BFD
(opened as needed, closed as needed to free descriptors for (opened as needed, closed as needed to free descriptors for
@ -163,11 +166,10 @@ DESCRIPTION
file descriptor (but subject to closure at any time), call file descriptor (but subject to closure at any time), call
bfd_set_cacheable(bfd, 1) on the returned BFD. The default is to bfd_set_cacheable(bfd, 1) on the returned BFD. The default is to
assume no cacheing; the file descriptor will remain open until assume no cacheing; the file descriptor will remain open until
bfd_close, and will not be affected by BFD operations on other <<bfd_close>>, and will not be affected by BFD operations on other
files. files.
Possible errors are no_memory, invalid_target and system_call Possible errors are <<no_memory>>, <<invalid_target>> and <<system_call_error>>.
error.
*/ */
bfd * bfd *
@ -250,11 +252,11 @@ SYNOPSIS
bfd *bfd_openw(CONST char *filename, CONST char *target); bfd *bfd_openw(CONST char *filename, CONST char *target);
DESCRIPTION DESCRIPTION
Creates a BFD, associated with file @var{filename}, using the Create a BFD, associated with file @var{filename}, using the
file format @var{target}, and returns a pointer to it. file format @var{target}, and return a pointer to it.
Possible errors are system_call_error, no_memory, Possible errors are <<system_call_error>>, <<no_memory>>,
invalid_target. <<invalid_target>>.
*/ */
bfd * bfd *
@ -296,11 +298,11 @@ FUNCTION
bfd_close bfd_close
SYNOPSIS SYNOPSIS
boolean bfd_close(bfd *); boolean bfd_close(bfd *abfd);
DESCRIPTION DESCRIPTION
This function closes a BFD. If the BFD was open for writing, Close a BFD. If the BFD was open for writing,
then pending operations are completed and the file written out then pending operations are completed and the file written out
and closed. If the created file is executable, then and closed. If the created file is executable, then
<<chmod>> is called to mark it as such. <<chmod>> is called to mark it as such.
@ -308,7 +310,7 @@ DESCRIPTION
All memory attached to the BFD's obstacks is released. All memory attached to the BFD's obstacks is released.
The file descriptor associated with the BFD is closed (even The file descriptor associated with the BFD is closed (even
if it was passed in to BFD by bfd_fdopenr). if it was passed in to BFD by <<bfd_fdopenr>>).
RETURNS RETURNS
<<true>> is returned if all is ok, otherwise <<false>>. <<true>> is returned if all is ok, otherwise <<false>>.
@ -361,7 +363,7 @@ SYNOPSIS
boolean bfd_close_all_done(bfd *); boolean bfd_close_all_done(bfd *);
DESCRIPTION DESCRIPTION
This function closes a BFD. It differs from <<bfd_close>> Close a BFD. Differs from <<bfd_close>>
since it does not complete any pending operations. This since it does not complete any pending operations. This
routine would be used if the application had just used BFD for routine would be used if the application had just used BFD for
swapping and didn't want to use any of the writing code. swapping and didn't want to use any of the writing code.
@ -417,8 +419,7 @@ SYNOPSIS
bfd_size_type bfd_alloc_size(bfd *abfd); bfd_size_type bfd_alloc_size(bfd *abfd);
DESCRIPTION DESCRIPTION
Return the number of bytes in the obstacks connected to the Return the number of bytes in the obstacks connected to @var{abfd}.
supplied BFD.
*/ */
@ -445,7 +446,7 @@ SYNOPSIS
bfd *bfd_create(CONST char *filename, bfd *templ); bfd *bfd_create(CONST char *filename, bfd *templ);
DESCRIPTION DESCRIPTION
This routine creates a new BFD in the manner of Create a new BFD in the manner of
<<bfd_openw>>, but without opening a file. The new BFD <<bfd_openw>>, but without opening a file. The new BFD
takes the target from the target used by @var{template}. The takes the target from the target used by @var{template}. The
format is always set to <<bfd_object>>. format is always set to <<bfd_object>>.
@ -479,8 +480,8 @@ SYNOPSIS
PTR bfd_alloc_by_size_t(bfd *abfd, size_t wanted); PTR bfd_alloc_by_size_t(bfd *abfd, size_t wanted);
DESCRIPTION DESCRIPTION
This function allocates a block of memory in the obstack Allocate a block of @var{wanted} bytes of memory in the obstack
attatched to <<abfd>> and returns a pointer to it. attatched to <<abfd>> and return a pointer to it.
*/ */

View File

@ -22,18 +22,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
Relocations Relocations
BFD maintains relocations in much the same was as it maintains BFD maintains relocations in much the same way it maintains
symbols; they are left alone until required, then read in symbols: they are left alone until required, then read in
en-mass and traslated into an internal form. There is a common en-mass and translated into an internal form. A common
routine <<bfd_perform_relocation>> which acts upon the routine <<bfd_perform_relocation>> acts upon the
canonical form to do the actual fixup. canonical form to do the fixup.
Note that relocations are maintained on a per section basis, Relocations are maintained on a per section basis,
whilst symbols are maintained on a per BFD basis. while symbols are maintained on a per BFD basis.
All a back end has to do to fit the BFD interface is to create All that a back end has to do to fit the BFD interface is to create
as many <<struct reloc_cache_entry>> as there are relocations a <<struct reloc_cache_entry>> for each relocation
in a particular section, and fill in the right bits: in a particular section, and fill in the right bits of the structures.
@menu @menu
@* typedef arelent:: @* typedef arelent::
@ -71,10 +71,10 @@ CODE_FRAGMENT
. {* Used by special functions *} . {* Used by special functions *}
. bfd_reloc_continue, . bfd_reloc_continue,
. .
. {* Unused *} . {* Unsupported relocation size requested. *}
. bfd_reloc_notsupported, . bfd_reloc_notsupported,
. .
. {* Unsupported relocation size requested. *} . {* Unused *}
. bfd_reloc_other, . bfd_reloc_other,
. .
. {* The symbol to relocate against was undefined. *} . {* The symbol to relocate against was undefined. *}
@ -109,14 +109,14 @@ CODE_FRAGMENT
/* /*
DESCRIPTION DESCRIPTION
Here is a description of each of the fields within a relent: Here is a description of each of the fields within an <<arelent>>:
o sym_ptr_ptr o <<sym_ptr_ptr>>
The symbol table pointer points to a pointer to the symbol The symbol table pointer points to a pointer to the symbol
associated with the relocation request. This would naturally associated with the relocation request. It is
be the pointer into the table returned by the back end's the pointer into the table returned by the back end's
get_symtab action. @xref{Symbols}. The symbol is referenced <<get_symtab>> action. @xref{Symbols}. The symbol is referenced
through a pointer to a pointer so that tools like the linker through a pointer to a pointer so that tools like the linker
can fix up all the symbols of the same name by modifying only can fix up all the symbols of the same name by modifying only
one pointer. The relocation routine looks in the symbol and one pointer. The relocation routine looks in the symbol and
@ -124,19 +124,19 @@ DESCRIPTION
value of the symbol as the initial relocation offset. If the value of the symbol as the initial relocation offset. If the
symbol pointer is zero, then the section provided is looked up. symbol pointer is zero, then the section provided is looked up.
o address o <<address>>
The address field gives the offset in bytes from the base of The <<address>> field gives the offset in bytes from the base of
the section data which owns the relocation record to the first the section data which owns the relocation record to the first
byte of relocatable information. The actual data relocated byte of relocatable information. The actual data relocated
will be relative to this point - for example, a relocation will be relative to this point; for example, a relocation
type which modifies the bottom two bytes of a four byte word type which modifies the bottom two bytes of a four byte word
would not touch the first byte pointed to in a big endian would not touch the first byte pointed to in a big endian
world. world.
o addend o <<addend>>
The addend is a value provided by the back end to be added (!) The <<addend>> is a value provided by the back end to be added (!)
to the relocation offset. Its interpretation is dependent upon to the relocation offset. Its interpretation is dependent upon
the howto. For example, on the 68k the code: the howto. For example, on the 68k the code:
@ -156,8 +156,8 @@ DESCRIPTION
| rts | rts
This could create a reloc pointing to foo, but leave the This could create a reloc pointing to <<foo>>, but leave the
offset in the data (something like) offset in the data, something like:
|RELOCATION RECORDS FOR [.text]: |RELOCATION RECORDS FOR [.text]:
@ -181,7 +181,7 @@ DESCRIPTION
| jmp r1 | jmp r1
This should create two relocs, both pointing to _foo, and with This should create two relocs, both pointing to <<_foo>>, and with
0x12340000 in their addend field. The data would consist of: 0x12340000 in their addend field. The data would consist of:
@ -196,15 +196,15 @@ DESCRIPTION
The relocation routine digs out the value from the data, adds The relocation routine digs out the value from the data, adds
it to the addend to get the original offset and then adds the it to the addend to get the original offset, and then adds the
value of _foo. Note that all 32 bits have to be kept around value of <<_foo>>. Note that all 32 bits have to be kept around
somewhere, to cope with carry from bit 15 to bit 16. somewhere, to cope with carry from bit 15 to bit 16.
One further example is the sparc and the a.out format. The One further example is the sparc and the a.out format. The
sparc has a similar problem to the 88k, in that some sparc has a similar problem to the 88k, in that some
instructions don't have room for an entire offset, but on the instructions don't have room for an entire offset, but on the
sparc the parts are created odd sized lumps. The designers of sparc the parts are created in odd sized lumps. The designers of
the a.out format chose not to use the data within the section the a.out format chose to not use the data within the section
for storing part of the offset; all the offset is kept within for storing part of the offset; all the offset is kept within
the reloc. Anything in the data should be ignored. the reloc. Anything in the data should be ignored.
@ -214,7 +214,7 @@ DESCRIPTION
| ret | ret
| restore | restore
Both relocs contains a pointer to foo, and the offsets would Both relocs contains a pointer to <<foo>>, and the offsets
contain junk. contain junk.
@ -230,11 +230,11 @@ DESCRIPTION
|00000010 81e80000 ; restore |00000010 81e80000 ; restore
o howto o <<howto>>
The howto field can be imagined as a The <<howto>> field can be imagined as a
relocation instruction. It is a pointer to a struct which relocation instruction. It is a pointer to a structure which
contains information on what to do with all the other contains information on what to do with all of the other
information in the reloc record and data section. A back end information in the reloc record and data section. A back end
would normally have a relocation instruction set and turn would normally have a relocation instruction set and turn
relocations into pointers to the correct structure on input - relocations into pointers to the correct structure on input -
@ -276,18 +276,18 @@ SUBSUBSECTION
<<reloc_howto_type>> <<reloc_howto_type>>
The <<reloc_howto_type>> is a structure which contains all the The <<reloc_howto_type>> is a structure which contains all the
information that BFD needs to know to tie up a back end's data. information that libbfd needs to know to tie up a back end's data.
CODE_FRAGMENT CODE_FRAGMENT
.struct symbol_cache_entry; {* Forward declaration *} .struct symbol_cache_entry; {* Forward declaration *}
. .
.typedef CONST struct reloc_howto_struct .typedef struct reloc_howto_struct
.{ .{
. {* The type field has mainly a documetary use - the back end can . {* The type field has mainly a documetary use - the back end can
. to what it wants with it, though the normally the back end's . do what it wants with it, though normally the back end's
. external idea of what a reloc number would be would be stored . external idea of what a reloc number is stored
. in this field. For example, the a PC relative word relocation . in this field. For example, a PC relative word relocation
. in a coff environment would have the type 023 - because that's . in a coff environment has the type 023 - because that's
. what the outside world calls a R_PCRWORD reloc. *} . what the outside world calls a R_PCRWORD reloc. *}
. unsigned int type; . unsigned int type;
. .
@ -345,7 +345,7 @@ CODE_FRAGMENT
. relocations rather than the data - this flag signals this.*} . relocations rather than the data - this flag signals this.*}
. boolean partial_inplace; . boolean partial_inplace;
. .
. {* The src_mask is used to select what parts of the read in data . {* The src_mask selects which parts of the read in data
. are to be used in the relocation sum. E.g., if this was an 8 bit . are to be used in the relocation sum. E.g., if this was an 8 bit
. bit of data which we read and relocated, this would be . bit of data which we read and relocated, this would be
. 0x000000ff. When we have relocs which have an addend, such as . 0x000000ff. When we have relocs which have an addend, such as
@ -354,7 +354,7 @@ CODE_FRAGMENT
. the mask would be 0x00000000. *} . the mask would be 0x00000000. *}
. bfd_vma src_mask; . bfd_vma src_mask;
. .
. {* The dst_mask is what parts of the instruction are replaced . {* The dst_mask selects which parts of the instruction are replaced
. into the instruction. In most cases src_mask == dst_mask, . into the instruction. In most cases src_mask == dst_mask,
. except in the above special case, where dst_mask would be . except in the above special case, where dst_mask would be
. 0x000000ff, and src_mask would be 0x00000000. *} . 0x000000ff, and src_mask would be 0x00000000. *}
@ -365,7 +365,7 @@ CODE_FRAGMENT
. slot of the instruction, so that a PC relative relocation can . slot of the instruction, so that a PC relative relocation can
. be made just by adding in an ordinary offset (e.g., sun3 a.out). . be made just by adding in an ordinary offset (e.g., sun3 a.out).
. Some formats leave the displacement part of an instruction . Some formats leave the displacement part of an instruction
. empty (e.g., m88k bcs), this flag signals the fact.*} . empty (e.g., m88k bcs); this flag signals the fact.*}
. boolean pcrel_offset; . boolean pcrel_offset;
. .
.} reloc_howto_type; .} reloc_howto_type;
@ -374,7 +374,7 @@ CODE_FRAGMENT
/* /*
FUNCTION FUNCTION
the HOWTO macro The HOWTO Macro
DESCRIPTION DESCRIPTION
The HOWTO define is horrible and will go away. The HOWTO define is horrible and will go away.
@ -385,7 +385,7 @@ DESCRIPTION
DESCRIPTION DESCRIPTION
And will be replaced with the totally magic way. But for the And will be replaced with the totally magic way. But for the
moment, we are compatible, so do it this way.. moment, we are compatible, so do it this way.
.#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN) .#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN)
@ -409,11 +409,11 @@ DESCRIPTION
/* /*
TYPEDEF TYPEDEF
reloc_chain arelent_chain
DESCRIPTION DESCRIPTION
How relocs are tied together How relocs are tied together in an <<asection>>:
.typedef unsigned char bfd_byte; .typedef unsigned char bfd_byte;
. .
@ -440,11 +440,11 @@ SYNOPSIS
bfd *output_bfd); bfd *output_bfd);
DESCRIPTION DESCRIPTION
If an output_bfd is supplied to this function the generated If @var{output_bfd} is supplied to this function, the generated
image will be relocatable, the relocations are copied to the image will be relocatable; the relocations are copied to the
output file after they have been changed to reflect the new output file after they have been changed to reflect the new
state of the world. There are two ways of reflecting the state of the world. There are two ways of reflecting the
results of partial linkage in an output file; by modifying the results of partial linkage in an output file: by modifying the
output data in place, and by modifying the relocation record. output data in place, and by modifying the relocation record.
Some native formats (e.g., basic a.out and basic coff) have no Some native formats (e.g., basic a.out and basic coff) have no
way of specifying an addend in the relocation type, so the way of specifying an addend in the relocation type, so the
@ -532,16 +532,38 @@ DEFUN(bfd_perform_relocation,(abfd,
/* Add in supplied addend. */ /* Add in supplied addend. */
relocation += reloc_entry->addend; relocation += reloc_entry->addend;
/* Here the variable relocation holds the final address of the
symbol we are relocating against, plus any addend. */
if (howto->pc_relative == true) if (howto->pc_relative == true)
{ {
/* Anything which started out as pc relative should end up that /* This is a PC relative relocation. We want to set RELOCATION
way too. to the distance between the address of the symbol and the
location. RELOCATION is already the address of the symbol.
There are two ways we can see a pcrel instruction. Sometimes We start by subtracting the address of the section containing
the pcrel displacement has been partially calculated, it the location.
includes the distance from the start of the section to the
instruction in it (e.g., sun3), and sometimes the field is If pcrel_offset is set, we must further subtract the position
totally blank - e.g., m88kbcs. */ of the location within the section. Some targets arrange for
the addend to be the negative of the position of the location
within the section; for example, i386-aout does this. For
i386-aout, pcrel_offset is false. Some other targets do not
include the position of the location; for example, m88kbcs,
or ELF. For those targets, pcrel_offset is true.
If we are producing relocateable output, then we must ensure
that this reloc will be correctly computed when the final
relocation is done. If pcrel_offset is false we want to wind
up with the negative of the location within the section,
which means we must adjust the existing addend by the change
in the location within the section. If pcrel_offset is true
we do not want to adjust the existing addend at all.
FIXME: This seems logical to me, but for the case of
producing relocateable output it is not what the code
actually does. I don't want to change it, because it seems
far too likely that something will break. */
relocation -= relocation -=
input_section->output_section->vma + input_section->output_offset; input_section->output_section->vma + input_section->output_offset;
@ -574,7 +596,78 @@ DEFUN(bfd_perform_relocation,(abfd,
/* WTF?? */ /* WTF?? */
if (abfd->xvec->flavour == bfd_target_coff_flavour) if (abfd->xvec->flavour == bfd_target_coff_flavour)
{ {
#if 1
/* For m68k-coff, the addend was being subtracted twice during
relocation with -r. Removing the line below this comment
fixes that problem; see PR 2953.
However, Ian wrote the following, regarding removing the line below,
which explains why it is still enabled: --djm
If you put a patch like that into BFD you need to check all the COFF
linkers. I am fairly certain that patch will break coff-i386 (e.g.,
SCO); see coff_i386_reloc in coff-i386.c where I worked around the
problem in a different way. There may very well be a reason that the
code works as it does.
Hmmm. The first obvious point is that bfd_perform_relocation should
not have any tests that depend upon the flavour. It's seem like
entirely the wrong place for such a thing. The second obvious point
is that the current code ignores the reloc addend when producing
relocateable output for COFF. That's peculiar. In fact, I really
have no idea what the point of the line you want to remove is.
A typical COFF reloc subtracts the old value of the symbol and adds in
the new value to the location in the object file (if it's a pc
relative reloc it adds the difference between the symbol value and the
location). When relocating we need to preserve that property.
BFD handles this by setting the addend to the negative of the old
value of the symbol. Unfortunately it handles common symbols in a
non-standard way (it doesn't subtract the old value) but that's a
different story (we can't change it without losing backward
compatibility with old object files) (coff-i386 does subtract the old
value, to be compatible with existing coff-i386 targets, like SCO).
So everything works fine when not producing relocateable output. When
we are producing relocateable output, logically we should do exactly
what we do when not producing relocateable output. Therefore, your
patch is correct. In fact, it should probably always just set
reloc_entry->addend to 0 for all cases, since it is, in fact, going to
add the value into the object file. This won't hurt the COFF code,
which doesn't use the addend; I'm not sure what it will do to other
formats (the thing to check for would be whether any formats both use
the addend and set partial_inplace).
When I wanted to make coff-i386 produce relocateable output, I ran
into the problem that you are running into: I wanted to remove that
line. Rather than risk it, I made the coff-i386 relocs use a special
function; it's coff_i386_reloc in coff-i386.c. The function
specifically adds the addend field into the object file, knowing that
bfd_perform_relocation is not going to. If you remove that line, then
coff-i386.c will wind up adding the addend field in twice. It's
trivial to fix; it just needs to be done.
The problem with removing the line is just that it may break some
working code. With BFD it's hard to be sure of anything. The right
way to deal with this is simply to build and test at least all the
supported COFF targets. It should be straightforward if time and disk
space consuming. For each target:
1) build the linker
2) generate some executable, and link it using -r (I would
probably use paranoia.o and link against newlib/libc.a, which
for all the supported targets would be available in
/usr/cygnus/progressive/H-host/target/lib/libc.a).
3) make the change to reloc.c
4) rebuild the linker
5) repeat step 2
6) if the resulting object files are the same, you have at least
made it no worse
7) if they are different you have to figure out which version is
right
*/
relocation -= reloc_entry->addend; relocation -= reloc_entry->addend;
#endif
reloc_entry->addend = 0; reloc_entry->addend = 0;
} }
else else
@ -674,11 +767,35 @@ DEFUN(bfd_perform_relocation,(abfd,
the relocation to the reloc entry (probably because there isn't the relocation to the reloc entry (probably because there isn't
any room in the output format to describe addends to relocs) any room in the output format to describe addends to relocs)
*/ */
relocation >>= howto->rightshift;
/* The cast to bfd_vma avoids a bug in the Alpha OSF/1 C compiler
(OSF version 1.3, compiler version 3.11). It miscompiles the
following program:
struct str
{
unsigned int i0;
} s = { 0 };
int
main ()
{
unsigned long x;
x = 0x100000000;
x <<= (unsigned long) s.i0;
if (x == 0)
printf ("failed\n");
else
printf ("succeeded (%lx)\n", x);
}
*/
relocation >>= (bfd_vma) howto->rightshift;
/* Shift everything up to where it's going to be used */ /* Shift everything up to where it's going to be used */
relocation <<= howto->bitpos; relocation <<= (bfd_vma) howto->bitpos;
/* Wait for the day when all have the mask in them */ /* Wait for the day when all have the mask in them */
@ -904,6 +1021,14 @@ CODE_FRAGMENT
. {* 16 bit relocation relative to the global pointer. *} . {* 16 bit relocation relative to the global pointer. *}
. BFD_RELOC_MIPS_GPREL, . BFD_RELOC_MIPS_GPREL,
. .
. {* Relocation against a MIPS literal section. *}
. BFD_RELOC_MIPS_LITERAL,
.
. {* MIPS ELF relocations. *}
. BFD_RELOC_MIPS_GOT16,
. BFD_RELOC_MIPS_CALL16,
. BFD_RELOC_MIPS_GPREL32,
.
. {* These are, so far, specific to HPPA processors. I'm not sure that some . {* These are, so far, specific to HPPA processors. I'm not sure that some
. don't duplicate other reloc types, such as BFD_RELOC_32 and _32_PCREL. . don't duplicate other reloc types, such as BFD_RELOC_32 and _32_PCREL.
. Also, many more were in the list I got that don't fit in well in the . Also, many more were in the list I got that don't fit in well in the
@ -1018,7 +1143,7 @@ CODE_FRAGMENT
/* /*
SECTION FUNCTION
bfd_reloc_type_lookup bfd_reloc_type_lookup
SYNOPSIS SYNOPSIS
@ -1026,8 +1151,8 @@ SYNOPSIS
bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code); bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
DESCRIPTION DESCRIPTION
This routine returns a pointer to a howto struct which when Return a pointer to a howto struct which, when
invoked, will perform the supplied relocation on data from the invoked, will perform the relocation @var{code} on data from the
architecture noted. architecture noted.
*/ */
@ -1216,4 +1341,101 @@ DEFUN(bfd_generic_get_relocated_section_contents,(abfd,
return data; return data;
}
/** Symbols */
/*
FUNCTION
bfd_get_reloc_upper_bound
SYNOPSIS
unsigned int bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
DESCRIPTION
Return the number of bytes required to store the
relocation information associated with section @var{sect}
attached to bfd @var{abfd}.
*/
unsigned int
DEFUN(bfd_get_reloc_upper_bound,(abfd, asect),
bfd *abfd AND
sec_ptr asect)
{
if (abfd->format != bfd_object) {
bfd_error = invalid_operation;
return 0;
}
return BFD_SEND (abfd, _get_reloc_upper_bound, (abfd, asect));
}
/*
FUNCTION
bfd_canonicalize_reloc
SYNOPSIS
unsigned int bfd_canonicalize_reloc
(bfd *abfd,
asection *sec,
arelent **loc,
asymbol **syms);
DESCRIPTION
Call the back end associated with the open BFD
@var{abfd} and translate the external form of the relocation
information attached to @var{sec} into the internal canonical
form. Place the table into memory at @var{loc}, which has
been preallocated, usually by a call to
<<bfd_get_reloc_upper_bound>>.
The @var{syms} table is also needed for horrible internal magic
reasons.
*/
unsigned int
DEFUN(bfd_canonicalize_reloc,(abfd, asect, location, symbols),
bfd *abfd AND
sec_ptr asect AND
arelent **location AND
asymbol **symbols)
{
if (abfd->format != bfd_object) {
bfd_error = invalid_operation;
return 0;
}
return BFD_SEND (abfd, _bfd_canonicalize_reloc,
(abfd, asect, location, symbols));
}
/*
FUNCTION
bfd_set_reloc
SYNOPSIS
void bfd_set_reloc
(bfd *abfd, sec_ptr *sec, arelent **rel, unsigned int count)
DESCRIPTION
Set the relocation pointer and count within
section @var{sec} to the values @var{rel} and @var{count}.
The argument @var{abfd} is ignored.
*/
/*ARGSUSED*/
void
bfd_set_reloc (ignore_abfd, asect, location, count)
bfd *ignore_abfd;
sec_ptr asect;
arelent **location;
unsigned int count;
{
asect->orelocation = location;
asect->reloc_count = count;
} }

View File

@ -22,13 +22,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
Sections Sections
Sections are supported in BFD in <<section.c>>.
The raw data contained within a BFD is maintained through the The raw data contained within a BFD is maintained through the
section abstraction. A single BFD may have any number of section abstraction. A single BFD may have any number of
sections, and keeps hold of them by pointing to the first, sections. It keeps hold of them by pointing to the first;
each one points to the next in the list. each one points to the next in the list.
Sections are supported in BFD in <<section.c>>.
@menu @menu
@* Section Input:: @* Section Input::
@* Section Output:: @* Section Output::
@ -45,22 +45,25 @@ SUBSECTION
created and attached to the BFD. created and attached to the BFD.
Each section has a name which describes the section in the Each section has a name which describes the section in the
outside world - for example, <<a.out>> would contain at least outside world---for example, <<a.out>> would contain at least
three sections, called <<.text>>, <<.data>> and <<.bss>>. three sections, called <<.text>>, <<.data>> and <<.bss>>.
Sometimes a BFD will contain more than the 'natural' number of Names need not be unique; for example a COFF file may have several
sections named <<.data>>.
Sometimes a BFD will contain more than the ``natural'' number of
sections. A back end may attach other sections containing sections. A back end may attach other sections containing
constructor data, or an application may add a section (using constructor data, or an application may add a section (using
bfd_make_section) to the sections attached to an already open <<bfd_make_section>>) to the sections attached to an already open
BFD. For example, the linker creates a supernumary section BFD. For example, the linker creates an extra section
<<COMMON>> for each input file's BFD to hold information about <<COMMON>> for each input file's BFD to hold information about
common storage. common storage.
The raw data is not necessarily read in at the same time as The raw data is not necessarily read in when
the section descriptor is created. Some targets may leave the the section descriptor is created. Some targets may leave the
data in place until a <<bfd_get_section_contents>> call is data in place until a <<bfd_get_section_contents>> call is
made. Other back ends may read in all the data at once - For made. Other back ends may read in all the data at once. For
example; an S-record file has to be read once to determine the example, an S-record file has to be read once to determine the
size of the data. An IEEE-695 file doesn't contain raw data in size of the data. An IEEE-695 file doesn't contain raw data in
sections, but data and relocation expressions intermixed, so sections, but data and relocation expressions intermixed, so
the data area has to be parsed to get out the data and the data area has to be parsed to get out the data and
@ -74,27 +77,28 @@ SUBSECTION
To write a new object style BFD, the various sections to be To write a new object style BFD, the various sections to be
written have to be created. They are attached to the BFD in written have to be created. They are attached to the BFD in
the same way as input sections, data is written to the the same way as input sections; data is written to the
sections using <<bfd_set_section_contents>>. sections using <<bfd_set_section_contents>>.
Any program that creates or combines sections (e.g., the assembler Any program that creates or combines sections (e.g., the assembler
and linker) must use the fields <<output_section>> and and linker) must use the <<asection>> fields <<output_section>> and
<<output_offset>> to indicate the file sections to which each <<output_offset>> to indicate the file sections to which each
section must be written. (If the section is being created from section must be written. (If the section is being created from
scratch, <<output_section>> should probably point to the section scratch, <<output_section>> should probably point to the section
itself, and <<output_offset>> should probably be zero.) itself and <<output_offset>> should probably be zero.)
The data to be written comes from input sections attached to The data to be written comes from input sections attached
(via <<output_section>> pointers) to
the output sections. The output section structure can be the output sections. The output section structure can be
considered a filter for the input section, the output section considered a filter for the input section: the output section
determines the vma of the output data and the name, but the determines the vma of the output data and the name, but the
input section determines the offset into the output section of input section determines the offset into the output section of
the data to be written. the data to be written.
E.g., to create a section "O", starting at 0x100, 0x123 long, E.g., to create a section "O", starting at 0x100, 0x123 long,
containing two subsections, "A" at offset 0x0 (ie at vma containing two subsections, "A" at offset 0x0 (i.e., at vma
0x100) and "B" at offset 0x20 (ie at vma 0x120) the structures 0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the <<asection>>
would look like: structures would look like:
| section name "A" | section name "A"
| output_offset 0x00 | output_offset 0x00
@ -108,23 +112,23 @@ SUBSECTION
SUBSECTION SUBSECTION
Seglets Seclets
The data within a section is stored in a <<seglet>>. These The data within a section is stored in a <<seclet>>. These
are much like the fixups in <<gas>>. The seglet abstraction are much like the fixups in <<gas>>. The seclet abstraction
allows the a section to grow and shrink within itself. allows a section to grow and shrink within itself.
A seglet knows how big it is, and which is the next seglet and A seclet knows how big it is, and which is the next seclet and
where the raw data for it is, and also points to a list of where the raw data for it is; it also points to a list of
relocations which apply to it. relocations which apply to it.
The seglet is used by the linker to perform relaxing on final The seclet is used by the linker to perform relaxing on final
code. The application creates code which is as big as code. The compiler creates code which is as big as
necessary to make it work without relaxing, and the user can necessary to make it work without relaxing, and the user can
select whether to relax. Sometimes relaxing takes a lot of select whether to relax. Sometimes relaxing takes a lot of
time. The linker runs around the relocations to see if any time. The linker runs around the relocations to see if any
are attached to data which can be shrunk, if so it does it on are attached to data which can be shrunk, if so it does it on
a seglet by seglet basis. a seclet by seclet basis.
*/ */
@ -141,18 +145,18 @@ typedef asection, section prototypes, Section Output, Sections
SUBSECTION SUBSECTION
typedef asection typedef asection
The shape of a section struct: Here is the section structure:
CODE_FRAGMENT CODE_FRAGMENT
. .
.typedef struct sec .typedef struct sec
.{ .{
. {* The name of the section, the name isn't a copy, the pointer is . {* The name of the section; the name isn't a copy, the pointer is
. the same as that passed to bfd_make_section. *} . the same as that passed to bfd_make_section. *}
. .
. CONST char *name; . CONST char *name;
. .
. {* Which section is it 0.nth *} . {* Which section is it; 0..nth. *}
. .
. int index; . int index;
. .
@ -160,7 +164,7 @@ CODE_FRAGMENT
. .
. struct sec *next; . struct sec *next;
. .
. {* The field flags contains attributes of the section. Some of . {* The field flags contains attributes of the section. Some
. flags are read in from the object file, and some are . flags are read in from the object file, and some are
. synthesized from other information. *} . synthesized from other information. *}
. .
@ -168,17 +172,17 @@ CODE_FRAGMENT
. .
.#define SEC_NO_FLAGS 0x000 .#define SEC_NO_FLAGS 0x000
. .
. {* Tells the OS to allocate space for this section when loaded. . {* Tells the OS to allocate space for this section when loading.
. This would clear for a section containing debug information . This is clear for a section containing debug information
. only. *} . only. *}
.#define SEC_ALLOC 0x001 .#define SEC_ALLOC 0x001
. .
. {* Tells the OS to load the section from the file when loading. . {* Tells the OS to load the section from the file when loading.
. This would be clear for a .bss section *} . This is clear for a .bss section. *}
.#define SEC_LOAD 0x002 .#define SEC_LOAD 0x002
. .
. {* The section contains data still to be relocated, so there will . {* The section contains data still to be relocated, so there is
. be some relocation information too. *} . some relocation information too. *}
.#define SEC_RELOC 0x004 .#define SEC_RELOC 0x004
. .
.#if 0 {* Obsolete ? *} .#if 0 {* Obsolete ? *}
@ -202,10 +206,10 @@ CODE_FRAGMENT
. type is used by the linker to create lists of constructors and . type is used by the linker to create lists of constructors and
. destructors used by <<g++>>. When a back end sees a symbol . destructors used by <<g++>>. When a back end sees a symbol
. which should be used in a constructor list, it creates a new . which should be used in a constructor list, it creates a new
. section for the type of name (eg <<__CTOR_LIST__>>), attaches . section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
. the symbol to it and builds a relocation. To build the lists . the symbol to it, and builds a relocation. To build the lists
. of constructors, all the linker has to to is catenate all the . of constructors, all the linker has to do is catenate all the
. sections called <<__CTOR_LIST__>> and relocte the data . sections called <<__CTOR_LIST__>> and relocate the data
. contained within - exactly the operations it would peform on . contained within - exactly the operations it would peform on
. standard data. *} . standard data. *}
.#define SEC_CONSTRUCTOR 0x100 .#define SEC_CONSTRUCTOR 0x100
@ -217,13 +221,12 @@ CODE_FRAGMENT
.#define SEC_CONSTRUCTOR_BSS 0x3100 .#define SEC_CONSTRUCTOR_BSS 0x3100
. .
. {* The section has contents - a data section could be . {* The section has contents - a data section could be
. <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>, a debug section could be . <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
. <<SEC_HAS_CONTENTS>> *} . <<SEC_HAS_CONTENTS>> *}
.#define SEC_HAS_CONTENTS 0x200 .#define SEC_HAS_CONTENTS 0x200
. .
. {* An instruction to the linker not to output sections . {* An instruction to the linker to not output the section
. containing this flag even if they have information which . even if it has information which would normally be written. *}
. would normally be written. *}
.#define SEC_NEVER_LOAD 0x400 .#define SEC_NEVER_LOAD 0x400
. .
. {* The section is a shared library section. The linker must leave . {* The section is a shared library section. The linker must leave
@ -238,6 +241,12 @@ CODE_FRAGMENT
. translate to bfd_com_section), but ECOFF has two. *} . translate to bfd_com_section), but ECOFF has two. *}
.#define SEC_IS_COMMON 0x8000 .#define SEC_IS_COMMON 0x8000
. .
. {* The section contains only debugging information. For
. example, this is set for ELF .debug and .stab sections.
. strip tests this flag to see if a section can be
. discarded. *}
.#define SEC_DEBUGGING 0x10000
.
. {* End of section flags. *} . {* End of section flags. *}
. .
. {* The virtual memory address of the section - where it will be . {* The virtual memory address of the section - where it will be
@ -251,18 +260,18 @@ CODE_FRAGMENT
. boolean user_set_vma; . boolean user_set_vma;
. .
. {* The load address of the section - where it would be in a . {* The load address of the section - where it would be in a
. rom image, really only used for writing section header . rom image; really only used for writing section header
. information. *} . information. *}
. .
. bfd_vma lma; . bfd_vma lma;
. .
. {* The size of the section in bytes, as it will be output. . {* The size of the section in bytes, as it will be output.
. contains a value even if the section has no contents (eg, the . contains a value even if the section has no contents (e.g., the
. size of <<.bss>>). This will be filled in after relocation *} . size of <<.bss>>). This will be filled in after relocation *}
. .
. bfd_size_type _cooked_size; . bfd_size_type _cooked_size;
. .
. {* The size on disk of the section in bytes originally. Normally this . {* The original size on disk of the section, in bytes. Normally this
. value is the same as the size, but if some relaxing has . value is the same as the size, but if some relaxing has
. been done, then this value will be bigger. *} . been done, then this value will be bigger. *}
. .
@ -270,7 +279,7 @@ CODE_FRAGMENT
. .
. {* If this section is going to be output, then this value is the . {* If this section is going to be output, then this value is the
. offset into the output section of the first byte in the input . offset into the output section of the first byte in the input
. section. Eg, if this was going to start at the 100th byte in . section. E.g., if this was going to start at the 100th byte in
. the output section, this value would be 100. *} . the output section, this value would be 100. *}
. .
. bfd_vma output_offset; . bfd_vma output_offset;
@ -279,8 +288,8 @@ CODE_FRAGMENT
. .
. struct sec *output_section; . struct sec *output_section;
. .
. {* The alignment requirement of the section, as an exponent - eg . {* The alignment requirement of the section, as an exponent of 2 -
. 3 aligns to 2^3 (or 8) *} . e.g., 3 aligns to 2^3 (or 8). *}
. .
. unsigned int alignment_power; . unsigned int alignment_power;
. .
@ -332,7 +341,7 @@ CODE_FRAGMENT
. .
. file_ptr moving_line_filepos; . file_ptr moving_line_filepos;
. .
. {* what the section number is in the target world *} . {* What the section number is in the target world *}
. .
. int target_index; . int target_index;
. .
@ -414,7 +423,7 @@ SUBSECTION
section prototypes section prototypes
These are the functions exported by the section handling part of These are the functions exported by the section handling part of
<<libbfd>. <<libbfd>>.
*/ */
/* /*
@ -425,10 +434,14 @@ SYNOPSIS
asection *bfd_get_section_by_name(bfd *abfd, CONST char *name); asection *bfd_get_section_by_name(bfd *abfd, CONST char *name);
DESCRIPTION DESCRIPTION
Runs through the provided @var{abfd} and returns the Run through the provided @var{abfd} and return the one of the
<<asection>> who's name matches that provided, otherwise NULL. <<asection>>s whose name matches @var{name}, otherwise NULL.
@xref{Sections}, for more information. @xref{Sections}, for more information.
This should only be used in special cases; the normal way to process
all sections of a given name is to use bfd_map_over_sections and
strcmp on the name (or better yet, base it on the section flags
or something else) for each section.
*/ */
asection * asection *
@ -449,17 +462,17 @@ FUNCTION
bfd_make_section_old_way bfd_make_section_old_way
SYNOPSIS SYNOPSIS
asection *bfd_make_section_old_way(bfd *, CONST char *name); asection *bfd_make_section_old_way(bfd *abfd, CONST char *name);
DESCRIPTION DESCRIPTION
This function creates a new empty section called @var{name} Create a new empty section called @var{name}
and attaches it to the end of the chain of sections for the and attach it to the end of the chain of sections for the
BFD supplied. An attempt to create a section with a name which BFD @var{abfd}. An attempt to create a section with a name which
is already in use, returns its pointer without changing the is already in use, returns its pointer without changing the
section chain. section chain.
It has the funny name since this is the way it used to be It has the funny name since this is the way it used to be
before is was rewritten... before it was rewritten....
Possible errors are: Possible errors are:
o invalid_operation - o invalid_operation -
@ -483,62 +496,39 @@ DEFUN(bfd_make_section_old_way,(abfd, name),
return sec; return sec;
} }
/* /*
FUNCTION FUNCTION
bfd_make_section bfd_make_section_anyway
SYNOPSIS SYNOPSIS
asection * bfd_make_section(bfd *, CONST char *name); asection *bfd_make_section_anyway(bfd *abfd, CONST char *name);
DESCRIPTION DESCRIPTION
This function creates a new empty section called @var{name} Create a new empty section called @var{name} and attach it to the end of
and attaches it to the end of the chain of sections for the the chain of sections for @var{abfd}. Create a new section even if there
BFD supplied. An attempt to create a section with a name which is already a section with that name.
is already in use, returns NULL without changing the section
chain.
Possible errors are: Returns NULL and sets bfd_error on error; possible errors are:
o invalid_operation - If output has already started for this BFD. o invalid_operation - If output has already started for @var{abfd}.
o no_memory - If obstack alloc fails. o no_memory - If obstack alloc fails.
*/ */
sec_ptr sec_ptr
DEFUN(bfd_make_section,(abfd, name), bfd_make_section_anyway (abfd, name)
bfd *abfd AND bfd *abfd;
CONST char * name) CONST char *name;
{ {
asection *newsect; asection *newsect;
asection **prev = &abfd->sections; asection **prev = &abfd->sections;
asection * sect = abfd->sections; asection * sect = abfd->sections;
if (abfd->output_has_begun) { if (abfd->output_has_begun)
{
bfd_error = invalid_operation; bfd_error = invalid_operation;
return NULL; return NULL;
} }
if (strcmp(name, BFD_ABS_SECTION_NAME) == 0)
{
return &bfd_abs_section;
}
if (strcmp(name, BFD_COM_SECTION_NAME) == 0)
{
return &bfd_com_section;
}
if (strcmp(name, BFD_UND_SECTION_NAME) == 0)
{
return &bfd_und_section;
}
if (strcmp(name, BFD_IND_SECTION_NAME) == 0)
{
return &bfd_ind_section;
}
while (sect) { while (sect) {
if (!strcmp(sect->name, name)) return NULL;
prev = &sect->next; prev = &sect->next;
sect = sect->next; sect = sect->next;
} }
@ -569,7 +559,6 @@ DEFUN(bfd_make_section,(abfd, name),
newsect->symbol->section = newsect; newsect->symbol->section = newsect;
newsect->symbol->flags = BSF_SECTION_SYM; newsect->symbol->flags = BSF_SECTION_SYM;
newsect->symbol_ptr_ptr = &newsect->symbol; newsect->symbol_ptr_ptr = &newsect->symbol;
if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true) { if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true) {
@ -581,18 +570,66 @@ DEFUN(bfd_make_section,(abfd, name),
return newsect; return newsect;
} }
/*
FUNCTION
bfd_make_section
SYNOPSIS
asection *bfd_make_section(bfd *, CONST char *name);
DESCRIPTION
Like <<bfd_make_section_anyway>>, but return NULL (without setting
bfd_error) without changing the section chain if there is already a
section named @var{name}. If there is an error, return NULL and set
bfd_error.
*/
sec_ptr
DEFUN(bfd_make_section,(abfd, name),
bfd *abfd AND
CONST char * name)
{
asection * sect = abfd->sections;
if (strcmp(name, BFD_ABS_SECTION_NAME) == 0)
{
return &bfd_abs_section;
}
if (strcmp(name, BFD_COM_SECTION_NAME) == 0)
{
return &bfd_com_section;
}
if (strcmp(name, BFD_UND_SECTION_NAME) == 0)
{
return &bfd_und_section;
}
if (strcmp(name, BFD_IND_SECTION_NAME) == 0)
{
return &bfd_ind_section;
}
while (sect) {
if (!strcmp(sect->name, name)) return NULL;
sect = sect->next;
}
/* The name is not already used; go ahead and make a new section. */
return bfd_make_section_anyway (abfd, name);
}
/* /*
FUNCTION FUNCTION
bfd_set_section_flags bfd_set_section_flags
SYNOPSIS SYNOPSIS
boolean bfd_set_section_flags(bfd *, asection *, flagword); boolean bfd_set_section_flags(bfd *abfd, asection *sec, flagword flags);
DESCRIPTION DESCRIPTION
Attempts to set the attributes of the section named in the BFD Set the attributes of the section @var{sec} in the BFD
supplied to the value. Returns true on success, false on @var{abfd} to the value @var{flags}. Returns <<true>> on success,
error. Possible error returns are: <<false>> on error. Possible error returns are:
o invalid operation - o invalid operation -
The section cannot have one or more of the attributes The section cannot have one or more of the attributes
@ -636,13 +673,13 @@ SYNOPSIS
PTR obj); PTR obj);
DESCRIPTION DESCRIPTION
Calls the provided function @var{func} for each section Call the provided function @var{func} for each section
attached to the BFD @var{abfd}, passing @var{obj} as an attached to the BFD @var{abfd}, passing @var{obj} as an
argument. The function will be called as if by argument. The function will be called as if by
| func(abfd, the_section, obj); | func(abfd, the_section, obj);
This is the prefered method for iterating over sections, an This is the prefered method for iterating over sections; an
alternative would be to use a loop: alternative would be to use a loop:
| section *p; | section *p;
@ -675,10 +712,10 @@ FUNCTION
bfd_set_section_size bfd_set_section_size
SYNOPSIS SYNOPSIS
boolean bfd_set_section_size(bfd *, asection *, bfd_size_type val); boolean bfd_set_section_size(bfd *abfd, asection *sec, bfd_size_type val);
DESCRIPTION DESCRIPTION
Sets @var{section} to the size @var{val}. If the operation is Set @var{sec} to the size @var{val}. If the operation is
ok, then <<true>> is returned, else <<false>>. ok, then <<true>> is returned, else <<false>>.
Possible error returns: Possible error returns:
@ -812,7 +849,7 @@ SYNOPSIS
file_ptr offset, bfd_size_type count); file_ptr offset, bfd_size_type count);
DESCRIPTION DESCRIPTION
This function reads data from @var{section} in BFD @var{abfd} Read data from @var{section} in BFD @var{abfd}
into memory starting at @var{location}. The data is read at an into memory starting at @var{location}. The data is read at an
offset of @var{offset} from the start of the input section, offset of @var{offset} from the start of the input section,
and is read for @var{count} bytes. and is read for @var{count} bytes.

View File

@ -1,5 +1,5 @@
/* Generic symbol-table support for the BFD library. /* Generic symbol-table support for the BFD library.
Copyright (C) 1990-1991 Free Software Foundation, Inc. Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
Written by Cygnus Support. Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library. This file is part of BFD, the Binary File Descriptor library.
@ -22,20 +22,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
SECTION SECTION
Symbols Symbols
BFD trys to maintain as much symbol information as it can when BFD tries to maintain as much symbol information as it can when
it moves information from file to file. BFD passes information it moves information from file to file. BFD passes information
to applications though the <<asymbol>> structure. When the to applications though the <<asymbol>> structure. When the
application requests the symbol table, BFD reads the table in application requests the symbol table, BFD reads the table in
the native form and translates parts of it into the internal the native form and translates parts of it into the internal
format. To maintain more than the infomation passed to format. To maintain more than the information passed to
applications some targets keep some information 'behind the applications, some targets keep some information ``behind the
sceans', in a structure only the particular back end knows scenes'' in a structure only the particular back end knows
about. For example, the coff back end keeps the original about. For example, the coff back end keeps the original
symbol table structure as well as the canonical structure when symbol table structure as well as the canonical structure when
a BFD is read in. On output, the coff back end can reconstruct a BFD is read in. On output, the coff back end can reconstruct
the output symbol table so that no information is lost, even the output symbol table so that no information is lost, even
information unique to coff which BFD doesn't know or information unique to coff which BFD doesn't know or
understand. If a coff symbol table was read, but was written understand. If a coff symbol table were read, but were written
through an a.out back end, all the coff specific information through an a.out back end, all the coff specific information
would be lost. The symbol table of a BFD would be lost. The symbol table of a BFD
is not necessarily read in until a canonicalize request is is not necessarily read in until a canonicalize request is
@ -43,8 +43,8 @@ SECTION
application with pointers to the canonical information. To application with pointers to the canonical information. To
output symbols, the application provides BFD with a table of output symbols, the application provides BFD with a table of
pointers to pointers to <<asymbol>>s. This allows applications pointers to pointers to <<asymbol>>s. This allows applications
like the linker to output a symbol as read, since the 'behind like the linker to output a symbol as it was read, since the ``behind
the sceens' information will be still available. the scenes'' information will be still available.
@menu @menu
@* Reading Symbols:: @* Reading Symbols::
@* Writing Symbols:: @* Writing Symbols::
@ -52,13 +52,14 @@ SECTION
@* symbol handling functions:: @* symbol handling functions::
@end menu @end menu
@node Reading Symbols, Writing Symbols, Symbols, Symbols INODE
Reading Symbols, Writing Symbols, Symbols, Symbols
SUBSECTION SUBSECTION
Reading Symbols Reading Symbols
There are two stages to reading a symbol table from a BFD; There are two stages to reading a symbol table from a BFD:
allocating storage, and the actual reading process. This is an allocating storage, and the actual reading process. This is an
excerpt from an appliction which reads the symbol table: excerpt from an application which reads the symbol table:
| unsigned int storage_needed; | unsigned int storage_needed;
| asymbol **symbol_table; | asymbol **symbol_table;
@ -80,10 +81,11 @@ SUBSECTION
| } | }
All storage for the symbols themselves is in an obstack All storage for the symbols themselves is in an obstack
connected to the BFD, and is freed when the BFD is closed. connected to the BFD; it is freed when the BFD is closed.
@node Writing Symbols, typedef asymbol, Reading Symbols, Symbols INODE
Writing Symbols, typedef asymbol, Reading Symbols, Symbols
SUBSECTION SUBSECTION
Writing Symbols Writing Symbols
@ -92,9 +94,9 @@ SUBSECTION
pointers to pointers to symbols to the BFD being written, and pointers to pointers to symbols to the BFD being written, and
fills in the symbol count. The close and cleanup code reads fills in the symbol count. The close and cleanup code reads
through the table provided and performs all the necessary through the table provided and performs all the necessary
operations. The outputing code must always be provided with an operations. The BFD output code must always be provided with an
'owned' symbol; one which has come from another BFD, or one ``owned'' symbol: one which has come from another BFD, or one
which has been created using <<bfd_make_empty_symbol>>. An which has been created using <<bfd_make_empty_symbol>>. Here is an
example showing the creation of a symbol table with only one element: example showing the creation of a symbol table with only one element:
| #include "bfd.h" | #include "bfd.h"
@ -124,7 +126,7 @@ SUBSECTION
| 00012345 A dummy_symbol | 00012345 A dummy_symbol
Many formats cannot represent arbitary symbol information; for Many formats cannot represent arbitary symbol information; for
instance the <<a.out>> object format does not allow an instance, the <<a.out>> object format does not allow an
arbitary number of sections. A symbol pointing to a section arbitary number of sections. A symbol pointing to a section
which is not one of <<.text>>, <<.data>> or <<.bss>> cannot which is not one of <<.text>>, <<.data>> or <<.bss>> cannot
be described. be described.
@ -132,8 +134,11 @@ SUBSECTION
*/ */
/* /*
@node typedef asymbol, symbol handling functions, Writing Symbols, Symbols DOCDD
INODE
typedef asymbol, symbol handling functions, Writing Symbols, Symbols
*/ */
/* /*
@ -147,20 +152,28 @@ SUBSECTION
/* /*
CODE_FRAGMENT CODE_FRAGMENT
.
.typedef struct symbol_cache_entry .typedef struct symbol_cache_entry
.{ .{
. {* A pointer to the BFD which owns the symbol. This information . {* A pointer to the BFD which owns the symbol. This information
. is necessary so that a back end can work out what additional . is necessary so that a back end can work out what additional
. (invisible to the application writer) information is carried . information (invisible to the application writer) is carried
. with the symbol. *} . with the symbol.
. .
. struct _bfd *the_bfd; . This field is *almost* redundant, since you can use section->owner
. instead, except that some symbols point to the global sections
. bfd_{abs,com,und}_section. This could be fixed by making
. these globals be per-bfd (or per-target-flavor). FIXME. *}
. .
. {* The text of the symbol. The name is left alone, and not copied - the . struct _bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field. *}
.
. {* The text of the symbol. The name is left alone, and not copied; the
. application may not alter it. *} . application may not alter it. *}
. CONST char *name; . CONST char *name;
. .
. {* The value of the symbol.*} . {* The value of the symbol. This really should be a union of a
. numeric value with a pointer, since some flags indicate that
. a pointer to another symbol is stored here. *}
. symvalue value; . symvalue value;
. .
. {* Attributes of a symbol: *} . {* Attributes of a symbol: *}
@ -175,43 +188,37 @@ CODE_FRAGMENT
. value is the offset into the section of the data. *} . value is the offset into the section of the data. *}
.#define BSF_GLOBAL 0x02 .#define BSF_GLOBAL 0x02
. .
. {* Obsolete *} . {* The symbol has global scope and is exported. The value is
.#define BSF_IMPORT 0x04
.
. {* The symbol has global scope, and is exported. The value is
. the offset into the section of the data. *} . the offset into the section of the data. *}
.#define BSF_EXPORT 0x08 .#define BSF_EXPORT BSF_GLOBAL {* no real difference *}
.
. {* The symbol is undefined. <<extern>> in <<C>>. The value has
. no meaning. *}
.#define BSF_UNDEFINED_OBS 0x10
.
. {* The symbol is common, initialized to zero; default in
. <<C>>. The value is the size of the object in bytes. *}
.#define BSF_FORT_COMM_OBS 0x20
. .
. {* A normal C symbol would be one of: . {* A normal C symbol would be one of:
. <<BSF_LOCAL>>, <<BSF_FORT_COMM>>, <<BSF_UNDEFINED>> or . <<BSF_LOCAL>>, <<BSF_FORT_COMM>>, <<BSF_UNDEFINED>> or
. <<BSF_EXPORT|BSD_GLOBAL>> *} . <<BSF_GLOBAL>> *}
. .
. {* The symbol is a debugging record. The value has an arbitary . {* The symbol is a debugging record. The value has an arbitary
. meaning. *} . meaning. *}
.#define BSF_DEBUGGING 0x40 .#define BSF_DEBUGGING 0x08
. .
. {* Used by the linker *} . {* The symbol denotes a function entry point. Used in ELF,
.#define BSF_KEEP 0x10000 . perhaps others someday. *}
.#define BSF_KEEP_G 0x80000 .#define BSF_FUNCTION 0x10
. .
. {* Unused *} . {* Used by the linker. *}
.#define BSF_WEAK 0x100000 .#define BSF_KEEP 0x20
.#define BSF_CTOR 0x200000 .#define BSF_KEEP_G 0x40
. .
. {* This symbol was created to point to a section *} . {* A weak global symbol, overridable without warnings by
.#define BSF_SECTION_SYM 0x400000 . a regular global symbol of the same name. *}
.#define BSF_WEAK 0x80
.
. {* This symbol was created to point to a section, e.g. ELF's
. STT_SECTION symbols. *}
.#define BSF_SECTION_SYM 0x100
. .
. {* The symbol used to be a common symbol, but now it is . {* The symbol used to be a common symbol, but now it is
. allocated. *} . allocated. *}
.#define BSF_OLD_COMMON 0x800000 .#define BSF_OLD_COMMON 0x200
. .
. {* The default value for common data. *} . {* The default value for common data. *}
.#define BFD_FORT_COMM_DEFAULT_VALUE 0 .#define BFD_FORT_COMM_DEFAULT_VALUE 0
@ -222,21 +229,25 @@ CODE_FRAGMENT
. declared and not at the end of a section. This bit is set . declared and not at the end of a section. This bit is set
. by the target BFD part to convey this information. *} . by the target BFD part to convey this information. *}
. .
.#define BSF_NOT_AT_END 0x40000 .#define BSF_NOT_AT_END 0x400
. .
. {* Signal that the symbol is the label of constructor section. *} . {* Signal that the symbol is the label of constructor section. *}
.#define BSF_CONSTRUCTOR 0x1000000 .#define BSF_CONSTRUCTOR 0x800
. .
. {* Signal that the symbol is a warning symbol. If the symbol . {* Signal that the symbol is a warning symbol. If the symbol
. is a warning symbol, then the value field (I know this is . is a warning symbol, then the value field (I know this is
. tacky) will point to the asymbol which when referenced will . tacky) will point to the asymbol which when referenced will
. cause the warning. *} . cause the warning. *}
.#define BSF_WARNING 0x2000000 .#define BSF_WARNING 0x1000
. .
. {* Signal that the symbol is indirect. The value of the symbol . {* Signal that the symbol is indirect. The value of the symbol
. is a pointer to an undefined asymbol which contains the . is a pointer to an undefined asymbol which contains the
. name to use instead. *} . name to use instead. *}
.#define BSF_INDIRECT 0x4000000 .#define BSF_INDIRECT 0x2000
.
. {* BSF_FILE marks symbols that contain a file name. This is used
. for ELF STT_FILE symbols. *}
.#define BSF_FILE 0x4000
. .
. flagword flags; . flagword flags;
. .
@ -254,11 +265,14 @@ CODE_FRAGMENT
#include "bfd.h" #include "bfd.h"
#include "sysdep.h" #include "sysdep.h"
#include "libbfd.h" #include "libbfd.h"
#include "aout/stab_gnu.h" #include "aout/stab_gnu.h"
/* /*
@node symbol handling functions, , typedef asymbol, Symbols DOCDD
INODE
symbol handling functions, , typedef asymbol, Symbols
SUBSECTION SUBSECTION
Symbol Handling Functions Symbol Handling Functions
*/ */
@ -268,10 +282,10 @@ FUNCTION
get_symtab_upper_bound get_symtab_upper_bound
DESCRIPTION DESCRIPTION
Returns the number of bytes required in a vector of pointers Return the number of bytes required to store a vector of pointers
to <<asymbols>> for all the symbols in the supplied BFD, to <<asymbols>> for all the symbols in the BFD @var{abfd},
including a terminal NULL pointer. If there are no symbols in including a terminal NULL pointer. If there are no symbols in
the BFD, then 0 is returned. the BFD, then return 0.
.#define get_symtab_upper_bound(abfd) \ .#define get_symtab_upper_bound(abfd) \
. BFD_SEND (abfd, _get_symtab_upper_bound, (abfd)) . BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
@ -283,10 +297,10 @@ FUNCTION
bfd_canonicalize_symtab bfd_canonicalize_symtab
DESCRIPTION DESCRIPTION
Supplied a BFD and a pointer to an uninitialized vector of Read the symbols from the BFD @var{abfd}, and fills in
pointers. This reads in the symbols from the BFD, and fills in the vector @var{location} with pointers to the symbols and
the table with pointers to the symbols, and a trailing NULL. a trailing NULL.
The routine returns the actual number of symbol pointers not Return the actual number of symbol pointers, not
including the NULL. including the NULL.
@ -301,12 +315,13 @@ DESCRIPTION
FUNCTION FUNCTION
bfd_set_symtab bfd_set_symtab
DESCRIPTION
Provided a table of pointers to symbols and a count, writes to
the output BFD the symbols when closed.
SYNOPSIS SYNOPSIS
boolean bfd_set_symtab (bfd *, asymbol **, unsigned int ); boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
DESCRIPTION
Arrange that when the output BFD @var{abfd} is closed,
the table @var{location} of @var{count} pointers to symbols
will be written.
*/ */
boolean boolean
@ -329,11 +344,12 @@ bfd_set_symtab (abfd, location, symcount)
FUNCTION FUNCTION
bfd_print_symbol_vandf bfd_print_symbol_vandf
DESCRIPTION
Prints the value and flags of the symbol supplied to the stream file.
SYNOPSIS SYNOPSIS
void bfd_print_symbol_vandf(PTR file, asymbol *symbol); void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
DESCRIPTION
Print the value and flags of the @var{symbol} supplied to the
stream @var{file}.
*/ */
void void
DEFUN(bfd_print_symbol_vandf,(file, symbol), DEFUN(bfd_print_symbol_vandf,(file, symbol),
@ -349,11 +365,10 @@ asymbol *symbol)
{ {
fprintf_vma(file, symbol->value); fprintf_vma(file, symbol->value);
} }
fprintf(file," %c%c%c%c%c%c%c%c", fprintf(file," %c%c%c%c%c%c%c",
(type & BSF_LOCAL) ? 'l':' ', (type & BSF_LOCAL) ? 'l':' ',
(type & BSF_GLOBAL) ? 'g' : ' ', (type & BSF_GLOBAL) ? 'g' : ' ',
(type & BSF_IMPORT) ? 'i' : ' ', (type & BSF_WEAK) ? 'w' : ' ',
(type & BSF_EXPORT) ? 'e' : ' ',
(type & BSF_CONSTRUCTOR) ? 'C' : ' ', (type & BSF_CONSTRUCTOR) ? 'C' : ' ',
(type & BSF_WARNING) ? 'W' : ' ', (type & BSF_WARNING) ? 'W' : ' ',
(type & BSF_INDIRECT) ? 'I' : ' ', (type & BSF_INDIRECT) ? 'I' : ' ',
@ -367,10 +382,10 @@ FUNCTION
bfd_make_empty_symbol bfd_make_empty_symbol
DESCRIPTION DESCRIPTION
This function creates a new <<asymbol>> structure for the BFD, Create a new <<asymbol>> structure for the BFD @var{abfd}
and returns a pointer to it. and return a pointer to it.
This routine is necessary, since each back end has private This routine is necessary because each back end has private
information surrounding the <<asymbol>>. Building your own information surrounding the <<asymbol>>. Building your own
<<asymbol>> and pointing to it will not create the private <<asymbol>> and pointing to it will not create the private
information, and will cause problems later on. information, and will cause problems later on.
@ -379,13 +394,68 @@ DESCRIPTION
. BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd)) . BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
*/ */
/*
FUNCTION
bfd_make_debug_symbol
DESCRIPTION
Create a new <<asymbol>> structure for the BFD @var{abfd},
to be used as a debugging symbol. Further details of its use have
yet to be worked out.
.#define bfd_make_debug_symbol(abfd,ptr,size) \
. BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
*/
struct section_to_type
{
CONST char *section;
char type;
};
/* Map section names to POSIX/BSD single-character symbol types.
This table is probably incomplete. It is sorted for convenience of
adding entries. Since it is so short, a linear search is used. */
static CONST struct section_to_type stt[] = {
{"*DEBUG*", 'N'},
{".bss", 'b'},
{".data", 'd'},
{".sbss", 's'}, /* Small BSS (uninitialized data) */
{".scommon", 'c'}, /* Small common */
{".sdata", 'g'}, /* Small initialized data */
{".text", 't'},
{0, 0}
};
/* Return the single-character symbol type corresponding to
section S, or '?' for an unknown COFF section. */
static char
coff_section_type (s)
char *s;
{
CONST struct section_to_type *t;
for (t = &stt[0]; t->section; t++)
if (!strcmp (s, t->section))
return t->type;
return '?';
}
#ifndef islower
#define islower(c) ((c) >= 'a' && (c) <= 'z')
#endif
#ifndef toupper
#define toupper(c) (islower(c) ? ((c) & ~0x20) : (c))
#endif
/* /*
FUNCTION FUNCTION
bfd_decode_symclass bfd_decode_symclass
DESCRIPTION DESCRIPTION
Return a lower-case character corresponding to the symbol Return a character corresponding to the symbol
class of symbol. class of @var{symbol}, or '?' for an unknown class.
SYNOPSIS SYNOPSIS
int bfd_decode_symclass(asymbol *symbol); int bfd_decode_symclass(asymbol *symbol);
@ -394,23 +464,26 @@ int
DEFUN(bfd_decode_symclass,(symbol), DEFUN(bfd_decode_symclass,(symbol),
asymbol *symbol) asymbol *symbol)
{ {
flagword flags = symbol->flags; char c;
if (symbol->section == &bfd_com_section) return 'C'; if (bfd_is_com_section (symbol->section))
if (symbol->section == &bfd_und_section) return 'U'; return 'C';
if (symbol->section == &bfd_und_section)
return 'U';
if (symbol->section == &bfd_ind_section)
return 'I';
if (!(symbol->flags & (BSF_GLOBAL|BSF_LOCAL)))
return '?';
if ( flags & (BSF_GLOBAL|BSF_LOCAL) ) {
if (symbol->section == &bfd_abs_section) if (symbol->section == &bfd_abs_section)
return (flags & BSF_GLOBAL) ? 'A' : 'a'; c = 'a';
else if ( !strcmp(symbol->section->name, ".text") ) else if (symbol->section)
return (flags & BSF_GLOBAL) ? 'T' : 't'; c = coff_section_type (symbol->section->name);
else if ( !strcmp(symbol->section->name, ".data") )
return (flags & BSF_GLOBAL) ? 'D' : 'd';
else if ( !strcmp(symbol->section->name, ".bss") )
return (flags & BSF_GLOBAL) ? 'B' : 'b';
else else
return (flags & BSF_GLOBAL) ? 'O' : 'o'; return '?';
} if (symbol->flags & BSF_GLOBAL)
c = toupper (c);
return c;
/* We don't have to handle these cases just yet, but we will soon: /* We don't have to handle these cases just yet, but we will soon:
N_SETV: 'v'; N_SETV: 'v';
@ -420,14 +493,37 @@ asymbol *symbol)
N_SETB: 's'; N_SETB: 's';
N_INDR: 'i'; N_INDR: 'i';
*/ */
return '?';
} }
/*
FUNCTION
bfd_symbol_info
DESCRIPTION
Fill in the basic info about symbol that nm needs.
Additional info may be added by the back-ends after
calling this function.
SYNOPSIS
void bfd_symbol_info(asymbol *symbol, symbol_info *ret);
*/
void
DEFUN(bfd_symbol_info,(symbol, ret),
asymbol *symbol AND
symbol_info *ret)
{
ret->type = bfd_decode_symclass (symbol);
if (ret->type != 'U')
ret->value = symbol->value+symbol->section->vma;
else
ret->value = 0;
ret->name = symbol->name;
}
void
bfd_symbol_is_absolute() bfd_symbol_is_absolute()
{ {
abort(); abort();
} }

View File

@ -38,25 +38,25 @@ DESCRIPTION
target are unknown. BFD uses various mechanisms to determine target are unknown. BFD uses various mechanisms to determine
how to interpret the file. The operations performed are: how to interpret the file. The operations performed are:
o First a BFD is created by calling the internal routine o Create a BFD by calling the internal routine
<<new_bfd>>, then <<bfd_find_target>> is called with the <<new_bfd>>, then call <<bfd_find_target>> with the
target string supplied to <<bfd_openr>> and the new BFD pointer. target string supplied to <<bfd_openr>> and the new BFD pointer.
o If a null target string was provided to <<bfd_find_target>>, o If a null target string was provided to <<bfd_find_target>>,
it looks up the environment variable <<GNUTARGET>> and uses look up the environment variable <<GNUTARGET>> and use
that as the target string. that as the target string.
o If the target string is still NULL, or the target string is o If the target string is still NULL, or the target string is
<<default>>, then the first item in the target vector is used <<default>>, then use the first item in the target vector
as the target type, and <<target_defaulted>> is set to as the target type, and set <<target_defaulted>> in the BFD to
cause <<bfd_check_format>> to loop through all the targets. cause <<bfd_check_format>> to loop through all the targets.
@xref{bfd_target}. @xref{Formats}. @xref{bfd_target}. @xref{Formats}.
o Otherwise, the elements in the target vector are inspected o Otherwise, inspect the elements in the target vector
one by one, until a match on target name is found. When found, one by one, until a match on target name is found. When found,
that is used. use it.
o Otherwise the error <<invalid_target>> is returned to o Otherwise return the error <<invalid_target>> to
<<bfd_openr>>. <<bfd_openr>>.
o <<bfd_openr>> attempts to open the file using o <<bfd_openr>> attempts to open the file using
@ -66,8 +66,8 @@ DESCRIPTION
format may be determined. This is done by calling format may be determined. This is done by calling
<<bfd_check_format>> on the BFD with a suggested format. <<bfd_check_format>> on the BFD with a suggested format.
If <<target_defaulted>> has been set, each possible target If <<target_defaulted>> has been set, each possible target
type is tried to see if it recognizes the specified format. The type is tried to see if it recognizes the specified format.
routine returns <<true>> when the application guesses right. <<bfd_check_format>> returns <<true>> when the caller guesses right.
@menu @menu
@* bfd_target:: @* bfd_target::
@end menu @end menu
@ -84,16 +84,16 @@ SUBSECTION
DESCRIPTION DESCRIPTION
This structure contains everything that BFD knows about a This structure contains everything that BFD knows about a
target. It includes things like its byte order, name, what target. It includes things like its byte order, name, and which
routines to call to do various operations, etc. routines to call to do various operations.
Every BFD points to a target structure with its <<xvec>> Every BFD points to a target structure with its <<xvec>>
member. member.
These macros are used to dispatch to functions through the The macros below are used to dispatch to functions through the
bfd_target vector. They are used in a number of macros further <<bfd_target>> vector. They are used in a number of macros further
down in @file{bfd.h}, and are also used when calling various down in @file{bfd.h}, and are also used when calling various
routines by hand inside the BFD implementation. The "arglist" routines by hand inside the BFD implementation. The @var{arglist}
argument must be parenthesized; it contains all the arguments argument must be parenthesized; it contains all the arguments
to the called function. to the called function.
@ -103,12 +103,12 @@ DESCRIPTION
.#define BFD_SEND(bfd, message, arglist) \ .#define BFD_SEND(bfd, message, arglist) \
. ((*((bfd)->xvec->message)) arglist) . ((*((bfd)->xvec->message)) arglist)
For operations which index on the BFD format For operations which index on the BFD format:
.#define BFD_SEND_FMT(bfd, message, arglist) \ .#define BFD_SEND_FMT(bfd, message, arglist) \
. (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) . (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
This is the struct which defines the type of BFD this is. The This is the structure which defines the type of BFD this is. The
<<xvec>> member of the struct <<bfd>> itself points here. Each <<xvec>> member of the struct <<bfd>> itself points here. Each
module that implements access to a different target under BFD, module that implements access to a different target under BFD,
defines one of these. defines one of these.
@ -118,17 +118,7 @@ DESCRIPTION
the entry points which call them. Too bad we can't have one the entry points which call them. Too bad we can't have one
macro to define them both! macro to define them both!
.typedef struct bfd_target .enum bfd_flavour {
.{
Identifies the kind of target, eg SunOS4, Ultrix, etc.
. char *name;
The "flavour" of a back end is a general indication about the contents
of a file.
. enum target_flavour {
. bfd_target_unknown_flavour, . bfd_target_unknown_flavour,
. bfd_target_aout_flavour, . bfd_target_aout_flavour,
. bfd_target_coff_flavour, . bfd_target_coff_flavour,
@ -139,7 +129,19 @@ of a file.
. bfd_target_oasys_flavour, . bfd_target_oasys_flavour,
. bfd_target_tekhex_flavour, . bfd_target_tekhex_flavour,
. bfd_target_srec_flavour, . bfd_target_srec_flavour,
. bfd_target_som_flavour} flavour; . bfd_target_som_flavour};
.typedef struct bfd_target
.{
Identifies the kind of target, e.g., SunOS4, Ultrix, etc.
. char *name;
The "flavour" of a back end is a general indication about the contents
of a file.
. enum bfd_flavour flavour;
The order of bytes within the data area of a file. The order of bytes within the data area of a file.
@ -149,18 +151,18 @@ The order of bytes within the header parts of a file.
. boolean header_byteorder_big_p; . boolean header_byteorder_big_p;
This is a mask of all the flags which an executable may have set - A mask of all the flags which an executable may have set -
from the set <<NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>. from the set <<NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.
. flagword object_flags; . flagword object_flags;
This is a mask of all the flags which a section may have set - from A mask of all the flags which a section may have set - from
the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>. the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.
. flagword section_flags; . flagword section_flags;
The character normally found at the front of a symbol The character normally found at the front of a symbol
(if any), perhaps _. (if any), perhaps `_'.
. char symbol_leading_char; . char symbol_leading_char;
@ -176,9 +178,9 @@ The minimum alignment restriction for any section.
. unsigned int align_power_min; . unsigned int align_power_min;
Entries for byte swapping for data. These are different to the other Entries for byte swapping for data. These are different from the other
entry points, since they don't take BFD as first arg. Certain other handlers entry points, since they don't take a BFD asthe first argument.
could do the same. Certain other handlers could do the same.
. bfd_vma (*bfd_getx64) PARAMS ((bfd_byte *)); . bfd_vma (*bfd_getx64) PARAMS ((bfd_byte *));
. bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((bfd_byte *)); . bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((bfd_byte *));
@ -205,7 +207,7 @@ Byte swapping for the headers
Format dependent routines: these are vectors of entry points Format dependent routines: these are vectors of entry points
within the target vector structure, one for each format to check. within the target vector structure, one for each format to check.
Check the format of a file being read. Return bfd_target * or zero. Check the format of a file being read. Return a <<bfd_target *>> or zero.
. struct bfd_target * (*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *)); . struct bfd_target * (*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
@ -213,22 +215,22 @@ Set the format of a file being written.
. boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *)); . boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
Write cached information into a file being written, at bfd_close. Write cached information into a file being written, at <<bfd_close>>.
. boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *)); . boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
The following functions are defined in <<JUMP_TABLE>>. The idea is The following functions are defined in <<JUMP_TABLE>>. The idea is
that the back end writer of <<foo>> names all the routines that the back end writer of <<foo>> names all the routines
<<foo_>>@var{entry_point}, <<JUMP_TABLE>> will built the entries <<foo_>>@var{entry_point}; <<JUMP_TABLE>> will build the entries
in this structure in the right order. in this structure in the right order.
Core file entry points Core file entry points.
. char * (*_core_file_failing_command) PARAMS ((bfd *)); . char * (*_core_file_failing_command) PARAMS ((bfd *));
. int (*_core_file_failing_signal) PARAMS ((bfd *)); . int (*_core_file_failing_signal) PARAMS ((bfd *));
. boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *)); . boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
Archive entry points Archive entry points.
. boolean (*_bfd_slurp_armap) PARAMS ((bfd *)); . boolean (*_bfd_slurp_armap) PARAMS ((bfd *));
. boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *)); . boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
@ -248,7 +250,7 @@ Standard stuff.
. file_ptr, bfd_size_type)); . file_ptr, bfd_size_type));
. boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr)); . boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
Symbols and relocations Symbols and relocations.
. unsigned int (*_get_symtab_upper_bound) PARAMS ((bfd *)); . unsigned int (*_get_symtab_upper_bound) PARAMS ((bfd *));
. unsigned int (*_bfd_canonicalize_symtab) PARAMS ((bfd *, . unsigned int (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
@ -379,6 +381,8 @@ extern bfd_target nlm64_little_generic_vec;
extern bfd_target oasys_vec; extern bfd_target oasys_vec;
extern bfd_target rs6000coff_vec; extern bfd_target rs6000coff_vec;
extern bfd_target shcoff_vec; extern bfd_target shcoff_vec;
extern bfd_target sparclynx_aout_vec;
extern bfd_target sparclynx_coff_vec;
extern bfd_target sunos_big_vec; extern bfd_target sunos_big_vec;
extern bfd_target tekhex_vec; extern bfd_target tekhex_vec;
extern bfd_target we32kcoff_vec; extern bfd_target we32kcoff_vec;
@ -503,6 +507,8 @@ bfd_target *target_vector[] = {
#endif #endif
&rs6000coff_vec, &rs6000coff_vec,
&shcoff_vec, &shcoff_vec,
&sparclynx_aout_vec,
&sparclynx_coff_vec,
&sunos_big_vec, &sunos_big_vec,
#if 0 #if 0
&tekhex_vec, &tekhex_vec,
@ -551,19 +557,19 @@ bfd_target *default_vector[] = {
FUNCTION FUNCTION
bfd_find_target bfd_find_target
SYNOPSIS
bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
DESCRIPTION DESCRIPTION
Returns a pointer to the transfer vector for the object target Return a pointer to the transfer vector for the object target
named target_name. If target_name is NULL, chooses the one in named @var{target_name}. If @var{target_name} is NULL, choose the
the environment variable GNUTARGET; if that is null or not one in the environment variable GNUTARGET; if that is null or not
defined thenthe first entry in the target list is chosen. defined, then choose the first entry in the target list.
Passing in the string "default" or setting the environment Passing in the string "default" or setting the environment
variable to "default" will cause the first entry in the target variable to "default" will cause the first entry in the target
list to be returned, and "target_defaulted" will be set in the list to be returned, and "target_defaulted" will be set in the
BFD. This causes <<bfd_check_format>> to loop over all the BFD. This causes <<bfd_check_format>> to loop over all the
targets to find the one that matches the file being read. targets to find the one that matches the file being read.
SYNOPSIS
bfd_target *bfd_find_target(CONST char *, bfd *);
*/ */
bfd_target * bfd_target *
@ -598,14 +604,14 @@ DEFUN(bfd_find_target,(target_name, abfd),
FUNCTION FUNCTION
bfd_target_list bfd_target_list
DESCRIPTION
This function returns a freshly malloced NULL-terminated
vector of the names of all the valid BFD targets. Do not
modify the names
SYNOPSIS SYNOPSIS
CONST char **bfd_target_list(void); CONST char **bfd_target_list(void);
DESCRIPTION
Return a freshly malloced NULL-terminated
vector of the names of all the valid BFD targets. Do not
modify the names.
*/ */
CONST char ** CONST char **