Initial import of GNU binutils version 2.8.1. Believe it or not,

this is heavily stripped down.
This commit is contained in:
John Polstra 1998-03-01 22:58:51 +00:00
commit 52cb49752a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/binutils/dist/; revision=33965
574 changed files with 335157 additions and 0 deletions

1564
contrib/binutils/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

50
contrib/binutils/README Normal file
View File

@ -0,0 +1,50 @@
README for GNU development tools
This directory contains various GNU compilers, assemblers, linkers,
debuggers, etc., plus their support routines, definitions, and documentation.
If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README; if with a libg++ release,
see libg++/README, etc. That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.
It is now possible to automatically configure and build a variety of
tools with one command. To build all of the tools contained herein,
run the ``configure'' script here, e.g.:
./configure
make
To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
make install
(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''. You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)
If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make. For example (assuming sh/bash/ksh):
CC=gcc ./configure
make CC=gcc
A similar example using csh:
setenv CC gcc
./configure
make CC=gcc
See etc/cfg-paper.texi, etc/configure.texi, and/or the README files in
various subdirectories, for more details.
Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc. See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.
REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,83 @@
Preliminary Notes on Porting BFD
--------------------------------
The 'host' is the system a tool runs *on*.
The 'target' is the system a tool runs *for*, i.e.
a tool can read/write the binaries of the target.
Porting to a new host
---------------------
Pick a name for your host. Call that <host>.
(<host> might be sun4, ...)
Create a file hosts/<host>.mh.
Porting to a new target
-----------------------
Pick a name for your target. Call that <target>.
Call the name for your CPU architecture <cpu>.
You need to create <target>.c and config/<target>.mt,
and add a case for it to a case statements in bfd/configure.host and
bfd/config.bfd, which associates each canonical host type with a BFD
host type (used as the base of the makefile fragment names), and to the
table in bfd/configure.in which associates each target vector with
the .o files it uses.
config/<target>.mt is a Makefile fragment.
The following is usually enough:
DEFAULT_VECTOR=<target>_vec
SELECT_ARCHITECTURES=bfd_<cpu>_arch
See the list of cpu types in archures.c, or "ls cpu-*.c".
If your architecture is new, you need to add it to the tables
in bfd/archures.c, opcodes/configure.in, and binutils/objdump.c.
For more information about .mt and .mh files, see config/README.
The file <target>.c is the hard part. It implements the
bfd_target <target>_vec, which includes pointers to
functions that do the actual <target>-specific methods.
Porting to a <target> that uses the a.out binary format
-------------------------------------------------------
In this case, the include file aout-target.h probaby does most
of what you need. The program gen-aout generates <target>.c for
you automatically for many a.out systems. Do:
make gen-aout
./gen-aout <target> > <target>.c
(This only works if you are building on the target ("native").
If you must make a cross-port from scratch, copy the most
similar existing file that includes aout-target.h, and fix what is wrong.)
Check the parameters in <target>.c, and fix anything that is wrong.
(Also let us know about it; perhaps we can improve gen-aout.c.)
TARGET_IS_BIG_ENDIAN_P
Should be defined if <target> is big-endian.
N_HEADER_IN_TEXT(x)
See discussion in ../include/aout/aout64.h.
BYTES_IN_WORD
Number of bytes per word. (Usually 4 but can be 8.)
ARCH
Number of bits per word. (Usually 32, but can be 64.)
ENTRY_CAN_BE_ZERO
Define if the extry point (start address of an
executable program) can be 0x0.
TEXT_START_ADDR
The address of the start of the text segemnt in
virtual memory. Normally, the same as the entry point.
TARGET_PAGE_SIZE
SEGMENT_SIZE
Usually, the same as the TARGET_PAGE_SIZE.
Alignment needed for the data segment.
TARGETNAME
The name of the target, for run-time lookups.
Usually "a.out-<target>"

View File

@ -0,0 +1,48 @@
BFD is a an object file library. It permits applications to use the
same routines to process object files regardless of their format.
BFD is used by the GNU debugger, assembler, linker, and the binary
utilities.
The documentation on using BFD is scanty and may be occasionally
incorrect. Pointers to documentation problems, or an entirely
rewritten manual, would be appreciated.
BFD is normally built as part of another package. See the build
instructions for that package, probably in a README file in the
appropriate directory.
BFD supports the following configure options:
--target=TARGET
The default target for which to build the library. TARGET is
a configuration target triplet, such as sparc-sun-solaris.
--enable-targets=TARGET,TARGET,TARGET...
Additional targets the library should support. To include
support for all known targets, use --enable-targets=all.
--enable-64-bit-bfd
Include support for 64 bit targets. This is automatically
turned on if you explicitly request a 64 bit target, but not
for --enable-targets=all. This requires a compiler with a 64
bit integer type, such as gcc.
--enable-shared
Build BFD as a shared library.
--enable-commonbfdlib
Build BFD, opcodes, and libiberty as a single shared library.
--with-mmap
Use mmap when accessing files. This is faster on some hosts,
but slower on others. It may not work on all hosts.
Report bugs with BFD to bug-gnu-utils@prep.ai.mit.edu.
Patches are encouraged. When sending patches, always send the output
of diff -u or diff -c from the original file to the new file. Do not
send default diff output. Do not make the diff from the new file to
the original file. Remember that any patch must not break other
systems. Remember that BFD must support cross compilation from any
host to any target, so patches which use ``#ifdef HOST'' are not
acceptable. Please also read the ``Reporting Bugs'' section of the
gcc manual.
Bug reports without patches will be remembered, but they may never get
fixed until somebody volunteers to fix them.

25
contrib/binutils/bfd/TODO Normal file
View File

@ -0,0 +1,25 @@
Things that still need to be done: -*- Text -*-
o - A source of space lossage is that all the target-dependent code
is in a single bfd_target structure. Hence all the code for
*writing* object files is still pulled into all the applications
that only care about *reading* (gdb, nm, objdump), while gas has
to carry along all the unneeded baggage for reading objects. And
so on. This would be a substantial change, and the payoff would
not all that great (essentially none if bfd is used as a shared
library).
o - The storage needed by BFD data structures is also larger than strictly
needed. This may be difficult to do much about.
o - implement bfd_abort, which should close the bfd but not alter the
filesystem.
o - update the bfd doc; write a how-to-write-a-backend doc, take out
the stupid quips and fill in all the blanks.
o - upgrade the reloc handling as per Steve's suggestion.

View File

@ -0,0 +1 @@
2.8.1

View File

@ -0,0 +1,28 @@
/* Whether strstr must be declared even if <string.h> is included. */
#undef NEED_DECLARATION_STRSTR
/* Whether malloc must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_MALLOC
/* Whether realloc must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_REALLOC
/* Whether free must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_FREE
/* Whether getenv must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_GETENV
@TOP@
/* Do we need to use the b modifier when opening binary files? */
#undef USE_BINARY_FOPEN
/* Name of host specific header file to include in trad-core.c. */
#undef TRAD_HEADER
/* Define only if <sys/procfs.h> is available *and* it defines prstatus_t. */
#undef HAVE_SYS_PROCFS_H
/* Do we really want to use mmap if it's available? */
#undef USE_MMAP

49
contrib/binutils/bfd/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,49 @@
dnl See whether we need to use fopen-bin.h rather than fopen-same.h.
AC_DEFUN(BFD_BINARY_FOPEN,
[AC_REQUIRE([AC_CANONICAL_SYSTEM])
case "${host}" in
changequote(,)dnl
i[345]86-*-msdos* | i[345]86-*-go32* | *-*-cygwin32 | *-*-windows)
changequote([,])dnl
AC_DEFINE(USE_BINARY_FOPEN) ;;
esac])dnl
dnl Get a default for CC_FOR_BUILD to put into Makefile.
AC_DEFUN(BFD_CC_FOR_BUILD,
[# Put a plausible default for CC_FOR_BUILD in Makefile.
if test -z "$CC_FOR_BUILD"; then
if test "x$cross_compiling" = "xno"; then
CC_FOR_BUILD='$(CC)'
else
CC_FOR_BUILD=gcc
fi
fi
AC_SUBST(CC_FOR_BUILD)])dnl
dnl See whether we need a declaration for a function.
AC_DEFUN(BFD_NEED_DECLARATION,
[AC_MSG_CHECKING([whether $1 must be declared])
AC_CACHE_VAL(bfd_cv_decl_needed_$1,
[AC_TRY_COMPILE([
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif],
[char *(*pfn) = (char *(*)) $1],
bfd_cv_decl_needed_$1=no, bfd_cv_decl_needed_$1=yes)])
AC_MSG_RESULT($bfd_cv_decl_needed_$1)
if test $bfd_cv_decl_needed_$1 = yes; then
bfd_tr_decl=NEED_DECLARATION_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
AC_DEFINE_UNQUOTED($bfd_tr_decl)
fi
])dnl

View File

@ -0,0 +1,236 @@
/* BFD back-end for a.out files encapsulated with COFF headers.
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* THIS MODULE IS NOT FINISHED. IT PROBABLY DOESN'T EVEN COMPILE. */
#if 0
#define TARGET_PAGE_SIZE 4096
#define SEGMENT_SIZE TARGET_PAGE_SIZE
#define TEXT_START_ADDR 0
#define BYTES_IN_WORD 4
#endif
#include "bfd.h"
#include <sysdep.h>
#include "libbfd.h"
#include <aout/aout64.h>
#include "aout/stab_gnu.h"
#include "aout/ar.h"
#include "libaout.h" /* BFD a.out internal data structures */
const bfd_target *encap_real_callback ();
const bfd_target *
encap_object_p (abfd)
bfd *abfd;
{
unsigned char magicbuf[4]; /* Raw bytes of magic number from file */
unsigned long magic; /* Swapped magic number */
short coff_magic;
struct external_exec exec_bytes;
struct internal_exec exec;
if (bfd_read ((PTR)magicbuf, 1, sizeof (magicbuf), abfd) !=
sizeof (magicbuf))
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return 0;
}
coff_magic = bfd_h_get_16 (abfd, magicbuf);
if (coff_magic != COFF_MAGIC)
return 0; /* Not an encap coff file */
__header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
(fseek ((f), HEADER_OFFSET((f)), 1))
magic = bfd_h_get_32 (abfd, magicbuf);
if (N_BADMAG (*((struct internal_exec *) &magic))) return 0;
struct external_exec exec_bytes;
if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
!= EXEC_BYTES_SIZE) {
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return 0;
}
NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
return aout_32_some_aout_object_p (abfd, &exec, encap_realcallback);
}
/* Finish up the reading of a encapsulated-coff a.out file header */
const bfd_target *
encap_real_callback (abfd)
bfd *abfd;
{
struct internal_exec *execp = exec_hdr (abfd);
MY(callback)(abfd, execp);
/* If we have a coff header, it can give us better values for
text_start and exec_data_start. This is particularly useful
for remote debugging of embedded systems. */
if (N_FLAGS(exec_aouthdr) & N_FLAGS_COFF_ENCAPSULATE)
{
struct coffheader ch;
int val;
val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
if (val == -1)
perror_with_name (filename);
val = myread (execchan, &ch, sizeof (ch));
if (val < 0)
perror_with_name (filename);
text_start = ch.text_start;
exec_data_start = ch.data_start;
} else
{
text_start =
IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
exec_data_start = IS_OBJECT_FILE (exec_aouthdr)
? exec_aouthdr.a_text : N_DATADDR (exec_aouthdr);
}
/* Determine the architecture and machine type of the object file. */
bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0); /* FIXME */
return abfd->xvec;
}
/* Write an object file in Encapsulated COFF format.
Section contents have already been written. We write the
file header, symbols, and relocation. */
boolean
encap_write_object_contents (abfd)
bfd *abfd;
{
bfd_size_type data_pad = 0;
struct external_exec exec_bytes;
struct internal_exec *execp = exec_hdr (abfd);
/****** FIXME: Fragments from the old GNU LD program for dealing with
encap coff. */
struct coffheader coffheader;
int need_coff_header;
/* Determine whether to count the header as part of
the text size, and initialize the text size accordingly.
This depends on the kind of system and on the output format selected. */
N_SET_MAGIC (outheader, magic);
#ifdef INITIALIZE_HEADER
INITIALIZE_HEADER;
#endif
text_size = sizeof (struct exec);
#ifdef COFF_ENCAPSULATE
if (relocatable_output == 0 && file_table[0].just_syms_flag == 0)
{
need_coff_header = 1;
/* set this flag now, since it will change the values of N_TXTOFF, etc */
N_SET_FLAGS (outheader, aout_backend_info (abfd)->exec_hdr_flags);
text_size += sizeof (struct coffheader);
}
#endif
#ifdef COFF_ENCAPSULATE
if (need_coff_header)
{
/* We are encapsulating BSD format within COFF format. */
struct coffscn *tp, *dp, *bp;
tp = &coffheader.scns[0];
dp = &coffheader.scns[1];
bp = &coffheader.scns[2];
strcpy (tp->s_name, ".text");
tp->s_paddr = text_start;
tp->s_vaddr = text_start;
tp->s_size = text_size;
tp->s_scnptr = sizeof (struct coffheader) + sizeof (struct exec);
tp->s_relptr = 0;
tp->s_lnnoptr = 0;
tp->s_nreloc = 0;
tp->s_nlnno = 0;
tp->s_flags = 0x20;
strcpy (dp->s_name, ".data");
dp->s_paddr = data_start;
dp->s_vaddr = data_start;
dp->s_size = data_size;
dp->s_scnptr = tp->s_scnptr + tp->s_size;
dp->s_relptr = 0;
dp->s_lnnoptr = 0;
dp->s_nreloc = 0;
dp->s_nlnno = 0;
dp->s_flags = 0x40;
strcpy (bp->s_name, ".bss");
bp->s_paddr = dp->s_vaddr + dp->s_size;
bp->s_vaddr = bp->s_paddr;
bp->s_size = bss_size;
bp->s_scnptr = 0;
bp->s_relptr = 0;
bp->s_lnnoptr = 0;
bp->s_nreloc = 0;
bp->s_nlnno = 0;
bp->s_flags = 0x80;
coffheader.f_magic = COFF_MAGIC;
coffheader.f_nscns = 3;
/* store an unlikely time so programs can
* tell that there is a bsd header
*/
coffheader.f_timdat = 1;
coffheader.f_symptr = 0;
coffheader.f_nsyms = 0;
coffheader.f_opthdr = 28;
coffheader.f_flags = 0x103;
/* aouthdr */
coffheader.magic = ZMAGIC;
coffheader.vstamp = 0;
coffheader.tsize = tp->s_size;
coffheader.dsize = dp->s_size;
coffheader.bsize = bp->s_size;
coffheader.entry = outheader.a_entry;
coffheader.text_start = tp->s_vaddr;
coffheader.data_start = dp->s_vaddr;
}
#endif
#ifdef COFF_ENCAPSULATE
if (need_coff_header)
mywrite (&coffheader, sizeof coffheader, 1, outdesc);
#endif
#ifndef COFF_ENCAPSULATE
padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
#endif
text_size -= N_TXTOFF (outheader);
WRITE_HEADERS(abfd, execp);
return true;
}
#define MY_write_object_content encap_write_object_contents
#define MY_object_p encap_object_p
#define MY_exec_hdr_flags N_FLAGS_COFF_ENCAPSULATE
#include "aout-target.h"

View File

@ -0,0 +1,647 @@
/* Define a target vector and some small routines for a variant of a.out.
Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997
Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "aout/aout64.h"
#include "aout/stab_gnu.h"
#include "aout/ar.h"
/*#include "libaout.h"*/
#ifndef SEGMENT_SIZE
#define SEGMENT_SIZE TARGET_PAGE_SIZE
#endif
extern reloc_howto_type * NAME(aout,reloc_type_lookup)
PARAMS ((bfd *, bfd_reloc_code_real_type));
/* Set parameters about this a.out file that are machine-dependent.
This routine is called from some_aout_object_p just before it returns. */
#ifndef MY_callback
static const bfd_target *MY(callback) PARAMS ((bfd *));
static const bfd_target *
MY(callback) (abfd)
bfd *abfd;
{
struct internal_exec *execp = exec_hdr (abfd);
unsigned int arch_align_power;
unsigned long arch_align;
/* Calculate the file positions of the parts of a newly read aout header */
obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
/* The virtual memory addresses of the sections */
obj_textsec (abfd)->vma = N_TXTADDR(*execp);
obj_datasec (abfd)->vma = N_DATADDR(*execp);
obj_bsssec (abfd)->vma = N_BSSADDR(*execp);
/* For some targets, if the entry point is not in the same page
as the start of the text, then adjust the VMA so that it is.
FIXME: Do this with a macro like SET_ARCH_MACH instead? */
if (aout_backend_info (abfd)->entry_is_text_address
&& execp->a_entry > obj_textsec (abfd)->vma)
{
bfd_vma adjust;
adjust = execp->a_entry - obj_textsec (abfd)->vma;
/* Adjust only by whole pages. */
adjust &= ~(TARGET_PAGE_SIZE - 1);
obj_textsec (abfd)->vma += adjust;
obj_datasec (abfd)->vma += adjust;
obj_bsssec (abfd)->vma += adjust;
}
/* Set the load addresses to be the same as the virtual addresses. */
obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
/* The file offsets of the sections */
obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
obj_datasec (abfd)->filepos = N_DATOFF (*execp);
/* The file offsets of the relocation info */
obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
/* The file offsets of the string table and symbol table. */
obj_sym_filepos (abfd) = N_SYMOFF (*execp);
obj_str_filepos (abfd) = N_STROFF (*execp);
/* Determine the architecture and machine type of the object file. */
#ifdef SET_ARCH_MACH
SET_ARCH_MACH(abfd, *execp);
#else
bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
#endif
/* The number of relocation records. This must be called after
SET_ARCH_MACH. It assumes that SET_ARCH_MACH will set
obj_reloc_entry_size correctly, if the reloc size is not
RELOC_STD_SIZE. */
obj_textsec (abfd)->reloc_count =
execp->a_trsize / obj_reloc_entry_size (abfd);
obj_datasec (abfd)->reloc_count =
execp->a_drsize / obj_reloc_entry_size (abfd);
/* Now that we know the architecture, set the alignments of the
sections. This is normally done by NAME(aout,new_section_hook),
but when the initial sections were created the architecture had
not yet been set. However, for backward compatibility, we don't
set the alignment power any higher than as required by the size
of the section. */
arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
arch_align = 1 << arch_align_power;
if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align)
== obj_textsec (abfd)->_raw_size)
&& (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align)
== obj_datasec (abfd)->_raw_size)
&& (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align)
== obj_bsssec (abfd)->_raw_size))
{
obj_textsec (abfd)->alignment_power = arch_align_power;
obj_datasec (abfd)->alignment_power = arch_align_power;
obj_bsssec (abfd)->alignment_power = arch_align_power;
}
/* Don't set sizes now -- can't be sure until we know arch & mach.
Sizes get set in set_sizes callback, later. */
#if 0
adata(abfd).page_size = TARGET_PAGE_SIZE;
adata(abfd).segment_size = SEGMENT_SIZE;
adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
#endif
return abfd->xvec;
}
#endif
#ifndef MY_object_p
/* Finish up the reading of an a.out file header */
static const bfd_target *MY(object_p) PARAMS ((bfd *));
static const bfd_target *
MY(object_p) (abfd)
bfd *abfd;
{
struct external_exec exec_bytes; /* Raw exec header from file */
struct internal_exec exec; /* Cleaned-up exec header */
const bfd_target *target;
if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
!= EXEC_BYTES_SIZE) {
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return 0;
}
#ifdef SWAP_MAGIC
exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
#else
exec.a_info = bfd_h_get_32 (abfd, exec_bytes.e_info);
#endif /* SWAP_MAGIC */
if (N_BADMAG (exec)) return 0;
#ifdef MACHTYPE_OK
if (!(MACHTYPE_OK (N_MACHTYPE (exec)))) return 0;
#endif
NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
#ifdef SWAP_MAGIC
/* swap_exec_header_in read in a_info with the wrong byte order */
exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
#endif /* SWAP_MAGIC */
target = NAME(aout,some_aout_object_p) (abfd, &exec, MY(callback));
#ifdef ENTRY_CAN_BE_ZERO
/* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
* means that it isn't obvious if EXEC_P should be set.
* All of the following must be true for an executable:
* There must be no relocations, the bfd can be neither an
* archive nor an archive element, and the file must be executable. */
if (exec.a_trsize + exec.a_drsize == 0
&& bfd_get_format(abfd) == bfd_object && abfd->my_archive == NULL)
{
struct stat buf;
#ifndef S_IXUSR
#define S_IXUSR 0100 /* Execute by owner. */
#endif
if (stat(abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
abfd->flags |= EXEC_P;
}
#endif /* ENTRY_CAN_BE_ZERO */
return target;
}
#define MY_object_p MY(object_p)
#endif
#ifndef MY_mkobject
static boolean MY(mkobject) PARAMS ((bfd *));
static boolean
MY(mkobject) (abfd)
bfd *abfd;
{
if (NAME(aout,mkobject)(abfd) == false)
return false;
#if 0 /* Sizes get set in set_sizes callback, later, after we know
the architecture and machine. */
adata(abfd).page_size = TARGET_PAGE_SIZE;
adata(abfd).segment_size = SEGMENT_SIZE;
adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
#endif
return true;
}
#define MY_mkobject MY(mkobject)
#endif
#ifndef MY_bfd_copy_private_section_data
/* Copy private section data. This actually does nothing with the
sections. It copies the subformat field. We copy it here, because
we need to know whether this is a QMAGIC file before we set the
section contents, and copy_private_bfd_data is not called until
after the section contents have been set. */
static boolean MY_bfd_copy_private_section_data
PARAMS ((bfd *, asection *, bfd *, asection *));
/*ARGSUSED*/
static boolean
MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
bfd *ibfd;
asection *isec;
bfd *obfd;
asection *osec;
{
if (bfd_get_flavour (ibfd) == bfd_target_aout_flavour
&& bfd_get_flavour (obfd) == bfd_target_aout_flavour)
obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
return true;
}
#endif
/* Write an object file.
Section contents have already been written. We write the
file header, symbols, and relocation. */
#ifndef MY_write_object_contents
static boolean
MY(write_object_contents) (abfd)
bfd *abfd;
{
struct external_exec exec_bytes;
struct internal_exec *execp = exec_hdr (abfd);
#if CHOOSE_RELOC_SIZE
CHOOSE_RELOC_SIZE(abfd);
#else
obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
#endif
WRITE_HEADERS(abfd, execp);
return true;
}
#define MY_write_object_contents MY(write_object_contents)
#endif
#ifndef MY_set_sizes
static boolean MY(set_sizes) PARAMS ((bfd *));
static boolean
MY(set_sizes) (abfd)
bfd *abfd;
{
adata(abfd).page_size = TARGET_PAGE_SIZE;
adata(abfd).segment_size = SEGMENT_SIZE;
#ifdef ZMAGIC_DISK_BLOCK_SIZE
adata(abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
#else
adata(abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;
#endif
adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
return true;
}
#define MY_set_sizes MY(set_sizes)
#endif
#ifndef MY_exec_hdr_flags
#define MY_exec_hdr_flags 0
#endif
#ifndef MY_backend_data
#ifndef MY_zmagic_contiguous
#define MY_zmagic_contiguous 0
#endif
#ifndef MY_text_includes_header
#define MY_text_includes_header 0
#endif
#ifndef MY_entry_is_text_address
#define MY_entry_is_text_address 0
#endif
#ifndef MY_exec_header_not_counted
#define MY_exec_header_not_counted 0
#endif
#ifndef MY_add_dynamic_symbols
#define MY_add_dynamic_symbols 0
#endif
#ifndef MY_add_one_symbol
#define MY_add_one_symbol 0
#endif
#ifndef MY_link_dynamic_object
#define MY_link_dynamic_object 0
#endif
#ifndef MY_write_dynamic_symbol
#define MY_write_dynamic_symbol 0
#endif
#ifndef MY_check_dynamic_reloc
#define MY_check_dynamic_reloc 0
#endif
#ifndef MY_finish_dynamic_link
#define MY_finish_dynamic_link 0
#endif
static CONST struct aout_backend_data MY(backend_data) = {
MY_zmagic_contiguous,
MY_text_includes_header,
MY_entry_is_text_address,
MY_exec_hdr_flags,
0, /* text vma? */
MY_set_sizes,
MY_exec_header_not_counted,
MY_add_dynamic_symbols,
MY_add_one_symbol,
MY_link_dynamic_object,
MY_write_dynamic_symbol,
MY_check_dynamic_reloc,
MY_finish_dynamic_link
};
#define MY_backend_data &MY(backend_data)
#endif
#ifndef MY_final_link_callback
/* Callback for the final_link routine to set the section offsets. */
static void MY_final_link_callback
PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
static void
MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
bfd *abfd;
file_ptr *ptreloff;
file_ptr *pdreloff;
file_ptr *psymoff;
{
struct internal_exec *execp = exec_hdr (abfd);
*ptreloff = N_TRELOFF (*execp);
*pdreloff = N_DRELOFF (*execp);
*psymoff = N_SYMOFF (*execp);
}
#endif
#ifndef MY_bfd_final_link
/* Final link routine. We need to use a call back to get the correct
offsets in the output file. */
static boolean MY_bfd_final_link PARAMS ((bfd *, struct bfd_link_info *));
static boolean
MY_bfd_final_link (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
{
return NAME(aout,final_link) (abfd, info, MY_final_link_callback);
}
#endif
/* We assume BFD generic archive files. */
#ifndef MY_openr_next_archived_file
#define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
#endif
#ifndef MY_get_elt_at_index
#define MY_get_elt_at_index _bfd_generic_get_elt_at_index
#endif
#ifndef MY_generic_stat_arch_elt
#define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
#endif
#ifndef MY_slurp_armap
#define MY_slurp_armap bfd_slurp_bsd_armap
#endif
#ifndef MY_slurp_extended_name_table
#define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
#endif
#ifndef MY_construct_extended_name_table
#define MY_construct_extended_name_table \
_bfd_archive_bsd_construct_extended_name_table
#endif
#ifndef MY_write_armap
#define MY_write_armap bsd_write_armap
#endif
#ifndef MY_read_ar_hdr
#define MY_read_ar_hdr _bfd_generic_read_ar_hdr
#endif
#ifndef MY_truncate_arname
#define MY_truncate_arname bfd_bsd_truncate_arname
#endif
#ifndef MY_update_armap_timestamp
#define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
#endif
/* No core file defined here -- configure in trad-core.c separately. */
#ifndef MY_core_file_failing_command
#define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
#endif
#ifndef MY_core_file_failing_signal
#define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
#endif
#ifndef MY_core_file_matches_executable_p
#define MY_core_file_matches_executable_p \
_bfd_nocore_core_file_matches_executable_p
#endif
#ifndef MY_core_file_p
#define MY_core_file_p _bfd_dummy_target
#endif
#ifndef MY_bfd_debug_info_start
#define MY_bfd_debug_info_start bfd_void
#endif
#ifndef MY_bfd_debug_info_end
#define MY_bfd_debug_info_end bfd_void
#endif
#ifndef MY_bfd_debug_info_accumulate
#define MY_bfd_debug_info_accumulate \
(void (*) PARAMS ((bfd*, struct sec *))) bfd_void
#endif
#ifndef MY_core_file_failing_command
#define MY_core_file_failing_command NAME(aout,core_file_failing_command)
#endif
#ifndef MY_core_file_failing_signal
#define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
#endif
#ifndef MY_core_file_matches_executable_p
#define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
#endif
#ifndef MY_set_section_contents
#define MY_set_section_contents NAME(aout,set_section_contents)
#endif
#ifndef MY_get_section_contents
#define MY_get_section_contents NAME(aout,get_section_contents)
#endif
#ifndef MY_get_section_contents_in_window
#define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
#endif
#ifndef MY_new_section_hook
#define MY_new_section_hook NAME(aout,new_section_hook)
#endif
#ifndef MY_get_symtab_upper_bound
#define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
#endif
#ifndef MY_get_symtab
#define MY_get_symtab NAME(aout,get_symtab)
#endif
#ifndef MY_get_reloc_upper_bound
#define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
#endif
#ifndef MY_canonicalize_reloc
#define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
#endif
#ifndef MY_make_empty_symbol
#define MY_make_empty_symbol NAME(aout,make_empty_symbol)
#endif
#ifndef MY_print_symbol
#define MY_print_symbol NAME(aout,print_symbol)
#endif
#ifndef MY_get_symbol_info
#define MY_get_symbol_info NAME(aout,get_symbol_info)
#endif
#ifndef MY_get_lineno
#define MY_get_lineno NAME(aout,get_lineno)
#endif
#ifndef MY_set_arch_mach
#define MY_set_arch_mach NAME(aout,set_arch_mach)
#endif
#ifndef MY_find_nearest_line
#define MY_find_nearest_line NAME(aout,find_nearest_line)
#endif
#ifndef MY_sizeof_headers
#define MY_sizeof_headers NAME(aout,sizeof_headers)
#endif
#ifndef MY_bfd_get_relocated_section_contents
#define MY_bfd_get_relocated_section_contents \
bfd_generic_get_relocated_section_contents
#endif
#ifndef MY_bfd_relax_section
#define MY_bfd_relax_section bfd_generic_relax_section
#endif
#ifndef MY_bfd_reloc_type_lookup
#define MY_bfd_reloc_type_lookup NAME(aout,reloc_type_lookup)
#endif
#ifndef MY_bfd_make_debug_symbol
#define MY_bfd_make_debug_symbol 0
#endif
#ifndef MY_read_minisymbols
#define MY_read_minisymbols NAME(aout,read_minisymbols)
#endif
#ifndef MY_minisymbol_to_symbol
#define MY_minisymbol_to_symbol NAME(aout,minisymbol_to_symbol)
#endif
#ifndef MY_bfd_link_hash_table_create
#define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
#endif
#ifndef MY_bfd_link_add_symbols
#define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
#endif
#ifndef MY_bfd_link_split_section
#define MY_bfd_link_split_section _bfd_generic_link_split_section
#endif
#ifndef MY_bfd_copy_private_bfd_data
#define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
#endif
#ifndef MY_bfd_merge_private_bfd_data
#define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
#endif
#ifndef MY_bfd_copy_private_symbol_data
#define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
#endif
#ifndef MY_bfd_print_private_bfd_data
#define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
#endif
#ifndef MY_bfd_set_private_flags
#define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
#endif
#ifndef MY_bfd_is_local_label_name
#define MY_bfd_is_local_label_name bfd_generic_is_local_label_name
#endif
#ifndef MY_bfd_free_cached_info
#define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
#endif
#ifndef MY_close_and_cleanup
#define MY_close_and_cleanup MY_bfd_free_cached_info
#endif
#ifndef MY_get_dynamic_symtab_upper_bound
#define MY_get_dynamic_symtab_upper_bound \
_bfd_nodynamic_get_dynamic_symtab_upper_bound
#endif
#ifndef MY_canonicalize_dynamic_symtab
#define MY_canonicalize_dynamic_symtab \
_bfd_nodynamic_canonicalize_dynamic_symtab
#endif
#ifndef MY_get_dynamic_reloc_upper_bound
#define MY_get_dynamic_reloc_upper_bound \
_bfd_nodynamic_get_dynamic_reloc_upper_bound
#endif
#ifndef MY_canonicalize_dynamic_reloc
#define MY_canonicalize_dynamic_reloc \
_bfd_nodynamic_canonicalize_dynamic_reloc
#endif
/* Aout symbols normally have leading underscores */
#ifndef MY_symbol_leading_char
#define MY_symbol_leading_char '_'
#endif
/* Aout archives normally use spaces for padding */
#ifndef AR_PAD_CHAR
#define AR_PAD_CHAR ' '
#endif
#ifndef MY_BFD_TARGET
const bfd_target MY(vec) =
{
TARGETNAME, /* name */
bfd_target_aout_flavour,
#ifdef TARGET_IS_BIG_ENDIAN_P
BFD_ENDIAN_BIG, /* target byte order (big) */
BFD_ENDIAN_BIG, /* target headers byte order (big) */
#else
BFD_ENDIAN_LITTLE, /* target byte order (little) */
BFD_ENDIAN_LITTLE, /* target headers byte order (little) */
#endif
(HAS_RELOC | EXEC_P | /* object flags */
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
MY_symbol_leading_char,
AR_PAD_CHAR, /* ar_pad_char */
15, /* ar_max_namelen */
#ifdef TARGET_IS_BIG_ENDIAN_P
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
#else
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
#endif
{_bfd_dummy_target, MY_object_p, /* bfd_check_format */
bfd_generic_archive_p, MY_core_file_p},
{bfd_false, MY_mkobject, /* bfd_set_format */
_bfd_generic_mkarchive, bfd_false},
{bfd_false, MY_write_object_contents, /* bfd_write_contents */
_bfd_write_archive_contents, bfd_false},
BFD_JUMP_TABLE_GENERIC (MY),
BFD_JUMP_TABLE_COPY (MY),
BFD_JUMP_TABLE_CORE (MY),
BFD_JUMP_TABLE_ARCHIVE (MY),
BFD_JUMP_TABLE_SYMBOLS (MY),
BFD_JUMP_TABLE_RELOCS (MY),
BFD_JUMP_TABLE_WRITE (MY),
BFD_JUMP_TABLE_LINK (MY),
BFD_JUMP_TABLE_DYNAMIC (MY),
(PTR) MY_backend_data,
};
#endif /* MY_BFD_TARGET */

View File

@ -0,0 +1,32 @@
/* BFD backend for SunOS style a.out with flags set to 0
Copyright (C) 1990, 91, 92, 93, 1994 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define TARGETNAME "a.out-zero-big"
#define MY(OP) CAT(aout0_big_,OP)
#include "bfd.h"
#define MY_exec_hdr_flags 0
#define MACHTYPE_OK(mtype) \
((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020)
/* Include the usual a.out support. */
#include "aoutf1.h"

View File

@ -0,0 +1,23 @@
/* BFD back-end for 32-bit a.out files.
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define ARCH_SIZE 32
#include "aoutx.h"

View File

@ -0,0 +1,31 @@
/* BFD back-end for 64-bit a.out files.
Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define ARCH_SIZE 64
/* aoutx.h requires definitions for BMAGIC and QMAGIC. */
#ifndef BMAGIC
#define BMAGIC 0
#endif
#ifndef QMAGIC
#define QMAGIC 0
#endif
#include "aoutx.h"

View File

@ -0,0 +1,850 @@
/* A.out "format 1" file handling code for BFD.
Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "aout/sun4.h"
#include "libaout.h" /* BFD a.out internal data structures */
#include "aout/aout64.h"
#include "aout/stab_gnu.h"
#include "aout/ar.h"
/* This is needed to reject a NewsOS file, e.g. in
gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
I needed to add M_UNKNOWN to recognize a 68000 object, so this will
probably no longer reject a NewsOS object. <ian@cygnus.com>. */
#ifndef MACHTYPE_OK
#define MACHTYPE_OK(mtype) \
(((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
|| (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
&& bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
#endif
/*
The file @code{aoutf1.h} contains the code for BFD's
a.out back end. Control over the generated back end is given by these
two preprocessor names:
@table @code
@item ARCH_SIZE
This value should be either 32 or 64, depending upon the size of an
int in the target format. It changes the sizes of the structs which
perform the memory/disk mapping of structures.
The 64 bit backend may only be used if the host compiler supports 64
ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
With this name defined, @emph{all} bfd operations are performed with 64bit
arithmetic, not just those to a 64bit target.
@item TARGETNAME
The name put into the target vector.
@item
@end table
*/
/*SUPPRESS558*/
/*SUPPRESS529*/
#if ARCH_SIZE == 64
#define sunos_set_arch_mach sunos_64_set_arch_mach
#define sunos_write_object_contents aout_64_sunos4_write_object_contents
#else
#define sunos_set_arch_mach sunos_32_set_arch_mach
#define sunos_write_object_contents aout_32_sunos4_write_object_contents
#endif
static boolean sunos_merge_private_bfd_data PARAMS ((bfd *, bfd *));
static void sunos_set_arch_mach PARAMS ((bfd *, int));
static void choose_reloc_size PARAMS ((bfd *));
static boolean sunos_write_object_contents PARAMS ((bfd *));
static const bfd_target *sunos4_core_file_p PARAMS ((bfd *));
static char *sunos4_core_file_failing_command PARAMS ((bfd *));
static int sunos4_core_file_failing_signal PARAMS ((bfd *));
static boolean sunos4_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
static boolean sunos4_set_sizes PARAMS ((bfd *));
/* Merge backend data into the output file.
This is necessary on sparclet-aout where we want the resultant machine
number to be M_SPARCLET if any input file is M_SPARCLET. */
#define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
static boolean
sunos_merge_private_bfd_data (ibfd, obfd)
bfd *ibfd, *obfd;
{
if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
|| bfd_get_flavour (obfd) != bfd_target_aout_flavour)
return true;
if (bfd_get_arch (obfd) == bfd_arch_sparc)
{
if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
}
return true;
}
/* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
depending upon ARCH_SIZE. */
static void
sunos_set_arch_mach (abfd, machtype)
bfd *abfd;
int machtype;
{
/* Determine the architecture and machine type of the object file. */
enum bfd_architecture arch;
long machine;
switch (machtype)
{
case M_UNKNOWN:
/* Some Sun3s make magic numbers without cpu types in them, so
we'll default to the 68000. */
arch = bfd_arch_m68k;
machine = 68000;
break;
case M_68010:
case M_HP200:
arch = bfd_arch_m68k;
machine = 68010;
break;
case M_68020:
case M_HP300:
arch = bfd_arch_m68k;
machine = 68020;
break;
case M_SPARC:
arch = bfd_arch_sparc;
machine = 0;
break;
case M_SPARCLET:
arch = bfd_arch_sparc;
machine = bfd_mach_sparc_sparclet;
break;
case M_386:
case M_386_DYNIX:
arch = bfd_arch_i386;
machine = 0;
break;
case M_29K:
arch = bfd_arch_a29k;
machine = 0;
break;
case M_HPUX:
arch = bfd_arch_m68k;
machine = 0;
break;
default:
arch = bfd_arch_obscure;
machine = 0;
break;
}
bfd_set_arch_mach (abfd, arch, machine);
}
#define SET_ARCH_MACH(ABFD, EXEC) \
NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
choose_reloc_size(ABFD);
/* Determine the size of a relocation entry, based on the architecture */
static void
choose_reloc_size (abfd)
bfd *abfd;
{
switch (bfd_get_arch (abfd))
{
case bfd_arch_sparc:
case bfd_arch_a29k:
obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
break;
default:
obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
break;
}
}
/* Write an object file in SunOS format. Section contents have
already been written. We write the file header, symbols, and
relocation. The real name of this function is either
aout_64_sunos4_write_object_contents or
aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */
static boolean
sunos_write_object_contents (abfd)
bfd *abfd;
{
struct external_exec exec_bytes;
struct internal_exec *execp = exec_hdr (abfd);
/* Magic number, maestro, please! */
switch (bfd_get_arch (abfd))
{
case bfd_arch_m68k:
switch (bfd_get_mach (abfd))
{
case 68000:
N_SET_MACHTYPE (*execp, M_UNKNOWN);
break;
case 68010:
N_SET_MACHTYPE (*execp, M_68010);
break;
default:
case 68020:
N_SET_MACHTYPE (*execp, M_68020);
break;
}
break;
case bfd_arch_sparc:
switch (bfd_get_mach (abfd))
{
case bfd_mach_sparc_sparclet:
N_SET_MACHTYPE (*execp, M_SPARCLET);
break;
default:
N_SET_MACHTYPE (*execp, M_SPARC);
break;
}
break;
case bfd_arch_i386:
N_SET_MACHTYPE (*execp, M_386);
break;
case bfd_arch_a29k:
N_SET_MACHTYPE (*execp, M_29K);
break;
default:
N_SET_MACHTYPE (*execp, M_UNKNOWN);
}
choose_reloc_size (abfd);
N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC);
WRITE_HEADERS (abfd, execp);
return true;
}
/* core files */
#define CORE_MAGIC 0x080456
#define CORE_NAMELEN 16
/* The core structure is taken from the Sun documentation.
Unfortunately, they don't document the FPA structure, or at least I
can't find it easily. Fortunately the core header contains its own
length. So this shouldn't cause problems, except for c_ucode, which
so far we don't use but is easy to find with a little arithmetic. */
/* But the reg structure can be gotten from the SPARC processor handbook.
This really should be in a GNU include file though so that gdb can use
the same info. */
struct regs
{
int r_psr;
int r_pc;
int r_npc;
int r_y;
int r_g1;
int r_g2;
int r_g3;
int r_g4;
int r_g5;
int r_g6;
int r_g7;
int r_o0;
int r_o1;
int r_o2;
int r_o3;
int r_o4;
int r_o5;
int r_o6;
int r_o7;
};
/* Taken from Sun documentation: */
/* FIXME: It's worse than we expect. This struct contains TWO substructs
neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
even portably access the stuff in between! */
struct external_sparc_core
{
int c_magic; /* Corefile magic number */
int c_len; /* Sizeof (struct core) */
#define SPARC_CORE_LEN 432
int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */
struct external_exec c_aouthdr; /* A.out header */
int c_signo; /* Killing signal, if any */
int c_tsize; /* Text size (bytes) */
int c_dsize; /* Data size (bytes) */
int c_ssize; /* Stack size (bytes) */
char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
double fp_stuff[1]; /* external FPU state (size unknown by us) */
/* The type "double" is critical here, for alignment.
SunOS declares a struct here, but the struct's alignment
is double since it contains doubles. */
int c_ucode; /* Exception no. from u_code */
/* (this member is not accessible by name since we don't
portably know the size of fp_stuff.) */
};
/* Core files generated by the BCP (the part of Solaris which allows
it to run SunOS4 a.out files). */
struct external_solaris_bcp_core
{
int c_magic; /* Corefile magic number */
int c_len; /* Sizeof (struct core) */
#define SOLARIS_BCP_CORE_LEN 456
int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */
int c_exdata_vp; /* exdata structure */
int c_exdata_tsize;
int c_exdata_dsize;
int c_exdata_bsize;
int c_exdata_lsize;
int c_exdata_nshlibs;
short c_exdata_mach;
short c_exdata_mag;
int c_exdata_toffset;
int c_exdata_doffset;
int c_exdata_loffset;
int c_exdata_txtorg;
int c_exdata_datorg;
int c_exdata_entloc;
int c_signo; /* Killing signal, if any */
int c_tsize; /* Text size (bytes) */
int c_dsize; /* Data size (bytes) */
int c_ssize; /* Stack size (bytes) */
char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
double fp_stuff[1]; /* external FPU state (size unknown by us) */
/* The type "double" is critical here, for alignment.
SunOS declares a struct here, but the struct's alignment
is double since it contains doubles. */
int c_ucode; /* Exception no. from u_code */
/* (this member is not accessible by name since we don't
portably know the size of fp_stuff.) */
};
struct external_sun3_core
{
int c_magic; /* Corefile magic number */
int c_len; /* Sizeof (struct core) */
#define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1 */
int c_regs[18]; /* General purpose registers -- MACHDEP SIZE */
struct external_exec c_aouthdr; /* A.out header */
int c_signo; /* Killing signal, if any */
int c_tsize; /* Text size (bytes) */
int c_dsize; /* Data size (bytes) */
int c_ssize; /* Stack size (bytes) */
char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
double fp_stuff[1]; /* external FPU state (size unknown by us) */
/* The type "double" is critical here, for alignment.
SunOS declares a struct here, but the struct's alignment
is double since it contains doubles. */
int c_ucode; /* Exception no. from u_code */
/* (this member is not accessible by name since we don't
portably know the size of fp_stuff.) */
};
struct internal_sunos_core
{
int c_magic; /* Corefile magic number */
int c_len; /* Sizeof (struct core) */
long c_regs_pos; /* file offset of General purpose registers */
int c_regs_size; /* size of General purpose registers */
struct internal_exec c_aouthdr; /* A.out header */
int c_signo; /* Killing signal, if any */
int c_tsize; /* Text size (bytes) */
int c_dsize; /* Data size (bytes) */
bfd_vma c_data_addr; /* Data start (address) */
int c_ssize; /* Stack size (bytes) */
bfd_vma c_stacktop; /* Stack top (address) */
char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
long fp_stuff_pos; /* file offset of external FPU state (regs) */
int fp_stuff_size; /* Size of it */
int c_ucode; /* Exception no. from u_code */
};
static void swapcore_sun3
PARAMS ((bfd *, char *, struct internal_sunos_core *));
static void swapcore_sparc
PARAMS ((bfd *, char *, struct internal_sunos_core *));
static void swapcore_solaris_bcp
PARAMS ((bfd *, char *, struct internal_sunos_core *));
/* byte-swap in the Sun-3 core structure */
static void
swapcore_sun3 (abfd, ext, intcore)
bfd *abfd;
char *ext;
struct internal_sunos_core *intcore;
{
struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
intcore->c_regs_size = sizeof (extcore->c_regs);
#if ARCH_SIZE == 64
aout_64_swap_exec_header_in
#else
aout_32_swap_exec_header_in
#endif
(abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
/* FP stuff takes up whole rest of struct, except c_ucode. */
intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
(file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
/* Ucode is the last thing in the struct -- just before the end */
intcore->c_ucode =
bfd_h_get_32 (abfd,
intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
intcore->c_stacktop = 0x0E000000; /* By experimentation */
}
/* byte-swap in the Sparc core structure */
static void
swapcore_sparc (abfd, ext, intcore)
bfd *abfd;
char *ext;
struct internal_sunos_core *intcore;
{
struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
intcore->c_regs_size = sizeof (extcore->c_regs);
#if ARCH_SIZE == 64
aout_64_swap_exec_header_in
#else
aout_32_swap_exec_header_in
#endif
(abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
/* FP stuff takes up whole rest of struct, except c_ucode. */
intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
(file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
/* Ucode is the last thing in the struct -- just before the end */
intcore->c_ucode =
bfd_h_get_32 (abfd,
intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
/* Supposedly the user stack grows downward from the bottom of kernel memory.
Presuming that this remains true, this definition will work. */
/* Now sun has provided us with another challenge. The value is different
for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
the other based on the current value of the stack pointer. This
loses (a) if the stack pointer has been clobbered, or (b) if the stack
is larger than 128 megabytes.
It's times like these you're glad they're switching to ELF.
Note that using include files or nlist on /vmunix would be wrong,
because we want the value for this core file, no matter what kind of
machine we were compiled on or are running on. */
#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
{
bfd_vma sp = bfd_h_get_32
(abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
if (sp < SPARC_USRSTACK_SPARC10)
intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
else
intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
}
}
/* byte-swap in the Solaris BCP core structure */
static void
swapcore_solaris_bcp (abfd, ext, intcore)
bfd *abfd;
char *ext;
struct internal_sunos_core *intcore;
{
struct external_solaris_bcp_core *extcore =
(struct external_solaris_bcp_core *) ext;
intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs);
intcore->c_regs_size = sizeof (extcore->c_regs);
/* The Solaris BCP exdata structure does not contain an a_syms field,
so we are unable to synthesize an internal exec header.
Luckily we are able to figure out the start address of the data section,
which is the only thing needed from the internal exec header,
from the exdata structure.
As of Solaris 2.3, BCP core files for statically linked executables
are buggy. The exdata structure is not properly filled in, and
the data section is written from address zero instead of the data
start address. */
memset ((PTR) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
intcore->c_data_addr =
bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_exdata_datorg);
intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
intcore->fp_stuff_pos =
(long) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
/* FP stuff takes up whole rest of struct, except c_ucode. */
intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
(file_ptr) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
/* Ucode is the last thing in the struct -- just before the end */
intcore->c_ucode =
bfd_h_get_32 (abfd,
intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
/* Supposedly the user stack grows downward from the bottom of kernel memory.
Presuming that this remains true, this definition will work. */
/* Now sun has provided us with another challenge. The value is different
for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
the other based on the current value of the stack pointer. This
loses (a) if the stack pointer has been clobbered, or (b) if the stack
is larger than 128 megabytes.
It's times like these you're glad they're switching to ELF.
Note that using include files or nlist on /vmunix would be wrong,
because we want the value for this core file, no matter what kind of
machine we were compiled on or are running on. */
#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
{
bfd_vma sp = bfd_h_get_32
(abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
if (sp < SPARC_USRSTACK_SPARC10)
intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
else
intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
}
}
/* need this cast because ptr is really void * */
#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
#define core_datasec(bfd) (core_hdr(bfd)->data_section)
#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
#define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)
/* These are stored in the bfd's tdata */
struct sun_core_struct
{
struct internal_sunos_core *hdr; /* core file header */
asection *data_section;
asection *stack_section;
asection *reg_section;
asection *reg2_section;
};
static const bfd_target *
sunos4_core_file_p (abfd)
bfd *abfd;
{
unsigned char longbuf[4]; /* Raw bytes of various header fields */
bfd_size_type core_size;
unsigned long core_mag;
struct internal_sunos_core *core;
char *extcore;
struct mergem
{
struct sun_core_struct suncoredata;
struct internal_sunos_core internal_sunos_core;
char external_core[1];
}
*mergem;
if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
sizeof (longbuf))
return 0;
core_mag = bfd_h_get_32 (abfd, longbuf);
if (core_mag != CORE_MAGIC)
return 0;
/* SunOS core headers can vary in length; second word is size; */
if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
sizeof (longbuf))
return 0;
core_size = bfd_h_get_32 (abfd, longbuf);
/* Sanity check */
if (core_size > 20000)
return 0;
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
return 0;
mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
if (mergem == NULL)
return 0;
extcore = mergem->external_core;
if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
{
bfd_release (abfd, (char *) mergem);
return 0;
}
/* Validate that it's a core file we know how to handle, due to sun
botching the positioning of registers and other fields in a machine
dependent way. */
core = &mergem->internal_sunos_core;
switch (core_size)
{
case SPARC_CORE_LEN:
swapcore_sparc (abfd, extcore, core);
break;
case SUN3_CORE_LEN:
swapcore_sun3 (abfd, extcore, core);
break;
case SOLARIS_BCP_CORE_LEN:
swapcore_solaris_bcp (abfd, extcore, core);
break;
default:
bfd_set_error (bfd_error_system_call); /* FIXME */
bfd_release (abfd, (char *) mergem);
return 0;
}
abfd->tdata.sun_core_data = &mergem->suncoredata;
abfd->tdata.sun_core_data->hdr = core;
/* create the sections. This is raunchy, but bfd_close wants to reclaim
them */
core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_stacksec (abfd) == NULL)
{
loser:
bfd_release (abfd, (char *) mergem);
return 0;
}
core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_datasec (abfd) == NULL)
{
loser1:
bfd_release (abfd, core_stacksec (abfd));
goto loser;
}
core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_regsec (abfd) == NULL)
{
loser2:
bfd_release (abfd, core_datasec (abfd));
goto loser1;
}
core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_reg2sec (abfd) == NULL)
{
bfd_release (abfd, core_regsec (abfd));
goto loser2;
}
core_stacksec (abfd)->name = ".stack";
core_datasec (abfd)->name = ".data";
core_regsec (abfd)->name = ".reg";
core_reg2sec (abfd)->name = ".reg2";
core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
core_stacksec (abfd)->_raw_size = core->c_ssize;
core_datasec (abfd)->_raw_size = core->c_dsize;
core_regsec (abfd)->_raw_size = core->c_regs_size;
core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;
core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
core_datasec (abfd)->vma = core->c_data_addr;
core_regsec (abfd)->vma = 0;
core_reg2sec (abfd)->vma = 0;
core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
core_datasec (abfd)->filepos = core->c_len;
/* We'll access the regs afresh in the core file, like any section: */
core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
/* Align to word at least */
core_stacksec (abfd)->alignment_power = 2;
core_datasec (abfd)->alignment_power = 2;
core_regsec (abfd)->alignment_power = 2;
core_reg2sec (abfd)->alignment_power = 2;
abfd->sections = core_stacksec (abfd);
core_stacksec (abfd)->next = core_datasec (abfd);
core_datasec (abfd)->next = core_regsec (abfd);
core_regsec (abfd)->next = core_reg2sec (abfd);
abfd->section_count = 4;
return abfd->xvec;
}
static char *
sunos4_core_file_failing_command (abfd)
bfd *abfd;
{
return core_hdr (abfd)->hdr->c_cmdname;
}
static int
sunos4_core_file_failing_signal (abfd)
bfd *abfd;
{
return core_hdr (abfd)->hdr->c_signo;
}
static boolean
sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd;
bfd *exec_bfd;
{
if (core_bfd->xvec != exec_bfd->xvec)
{
bfd_set_error (bfd_error_system_call);
return false;
}
/* Solaris core files do not include an aouthdr. */
if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
return true;
return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
(char *) exec_hdr (exec_bfd),
sizeof (struct internal_exec)) == 0) ? true : false;
}
#define MY_set_sizes sunos4_set_sizes
static boolean
sunos4_set_sizes (abfd)
bfd *abfd;
{
switch (bfd_get_arch (abfd))
{
default:
return false;
case bfd_arch_sparc:
adata (abfd).page_size = 0x2000;
adata (abfd).segment_size = 0x2000;
adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
return true;
case bfd_arch_m68k:
adata (abfd).page_size = 0x2000;
adata (abfd).segment_size = 0x20000;
adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
return true;
}
}
/* We default to setting the toolversion field to 1, as is required by
SunOS. */
#ifndef MY_exec_hdr_flags
#define MY_exec_hdr_flags 1
#endif
#ifndef MY_entry_is_text_address
#define MY_entry_is_text_address 0
#endif
#ifndef MY_add_dynamic_symbols
#define MY_add_dynamic_symbols 0
#endif
#ifndef MY_add_one_symbol
#define MY_add_one_symbol 0
#endif
#ifndef MY_link_dynamic_object
#define MY_link_dynamic_object 0
#endif
#ifndef MY_write_dynamic_symbol
#define MY_write_dynamic_symbol 0
#endif
#ifndef MY_check_dynamic_reloc
#define MY_check_dynamic_reloc 0
#endif
#ifndef MY_finish_dynamic_link
#define MY_finish_dynamic_link 0
#endif
static CONST struct aout_backend_data sunos4_aout_backend =
{
0, /* zmagic files are not contiguous */
1, /* text includes header */
MY_entry_is_text_address,
MY_exec_hdr_flags,
0, /* default text vma */
sunos4_set_sizes,
0, /* header is counted in zmagic text */
MY_add_dynamic_symbols,
MY_add_one_symbol,
MY_link_dynamic_object,
MY_write_dynamic_symbol,
MY_check_dynamic_reloc,
MY_finish_dynamic_link
};
#define MY_core_file_failing_command sunos4_core_file_failing_command
#define MY_core_file_failing_signal sunos4_core_file_failing_signal
#define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
#define MY_bfd_debug_info_start bfd_void
#define MY_bfd_debug_info_end bfd_void
#define MY_bfd_debug_info_accumulate \
(void (*) PARAMS ((bfd *, struct sec *))) bfd_void
#define MY_core_file_p sunos4_core_file_p
#define MY_write_object_contents NAME(aout,sunos4_write_object_contents)
#define MY_backend_data &sunos4_aout_backend
#ifndef TARGET_IS_LITTLE_ENDIAN_P
#define TARGET_IS_BIG_ENDIAN_P
#endif
#include "aout-target.h"

5648
contrib/binutils/bfd/aoutx.h Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,738 @@
/* BFD library support routines for architectures.
Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Hacked by John Gilmore and Steve Chamberlain of Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include <ctype.h>
/*
SECTION
Architectures
BFD keeps one atom in a BFD describing the
architecture of the data attached to the BFD: a pointer to a
<<bfd_arch_info_type>>.
Pointers to structures can be requested independently of a BFD
so that an architecture's information can be interrogated
without access to an open BFD.
The architecture information is provided by each architecture package.
The set of default architectures is selected by the macro
<<SELECT_ARCHITECTURES>>. This is normally set up in the
@file{config/@var{target}.mt} file of your choice. If the name is not
defined, then all the architectures supported are included.
When BFD starts up, all the architectures are called with an
initialize method. It is up to the architecture back end 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
default case (an item with a machine field of 0).
BFD's idea of an architecture is implemented in @file{archures.c}.
*/
/*
SUBSECTION
bfd_architecture
DESCRIPTION
This enum gives the object file's CPU architecture, in a
global sense---i.e., what processor family does it belong to?
Another field indicates which processor within
the family is in use. The machine gives a number which
distinguishes different versions of the architecture,
containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
and 68020 and 68030 for Motorola 68020 and 68030.
.enum bfd_architecture
.{
. bfd_arch_unknown, {* File arch not known *}
. bfd_arch_obscure, {* Arch known, not one of these *}
. bfd_arch_m68k, {* Motorola 68xxx *}
. bfd_arch_vax, {* DEC Vax *}
. bfd_arch_i960, {* Intel 960 *}
. {* The order of the following is important.
. lower number indicates a machine type that
. only accepts a subset of the instructions
. available to machines with higher numbers.
. The exception is the "ca", which is
. incompatible with all other machines except
. "core". *}
.
.#define bfd_mach_i960_core 1
.#define bfd_mach_i960_ka_sa 2
.#define bfd_mach_i960_kb_sb 3
.#define bfd_mach_i960_mc 4
.#define bfd_mach_i960_xa 5
.#define bfd_mach_i960_ca 6
.#define bfd_mach_i960_jx 7
.#define bfd_mach_i960_hx 8
.
. bfd_arch_a29k, {* AMD 29000 *}
. bfd_arch_sparc, {* SPARC *}
.#define bfd_mach_sparc 1
.{* The difference between v8plus and v9 is that v9 is a true 64 bit env. *}
.#define bfd_mach_sparc_sparclet 2
.#define bfd_mach_sparc_sparclite 3
.#define bfd_mach_sparc_v8plus 4
.#define bfd_mach_sparc_v8plusa 5 {* with ultrasparc add'ns *}
.#define bfd_mach_sparc_v9 6
.#define bfd_mach_sparc_v9a 7 {* with ultrasparc add'ns *}
.{* Nonzero if MACH has the v9 instruction set. *}
.#define bfd_mach_sparc_v9_p(mach) \
. ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
. bfd_arch_mips, {* MIPS Rxxxx *}
. bfd_arch_i386, {* Intel 386 *}
.#define bfd_mach_i386_i386 0
.#define bfd_mach_i386_i8086 1
. bfd_arch_we32k, {* AT&T WE32xxx *}
. bfd_arch_tahoe, {* CCI/Harris Tahoe *}
. bfd_arch_i860, {* Intel 860 *}
. bfd_arch_romp, {* IBM ROMP PC/RT *}
. bfd_arch_alliant, {* Alliant *}
. bfd_arch_convex, {* Convex *}
. bfd_arch_m88k, {* Motorola 88xxx *}
. bfd_arch_pyramid, {* Pyramid Technology *}
. bfd_arch_h8300, {* Hitachi H8/300 *}
.#define bfd_mach_h8300 1
.#define bfd_mach_h8300h 2
.#define bfd_mach_h8300s 3
. bfd_arch_powerpc, {* PowerPC *}
. bfd_arch_rs6000, {* IBM RS/6000 *}
. bfd_arch_hppa, {* HP PA RISC *}
. bfd_arch_d10v, {* Mitsubishi D10V *}
. bfd_arch_z8k, {* Zilog Z8000 *}
.#define bfd_mach_z8001 1
.#define bfd_mach_z8002 2
. bfd_arch_h8500, {* Hitachi H8/500 *}
. bfd_arch_sh, {* Hitachi SH *}
. bfd_arch_alpha, {* Dec Alpha *}
. bfd_arch_arm, {* Advanced Risc Machines ARM *}
. bfd_arch_ns32k, {* National Semiconductors ns32000 *}
. bfd_arch_w65, {* WDC 65816 *}
. bfd_arch_m32r, {* Mitsubishi M32R/D *}
. bfd_arch_mn10200, {* Matsushita MN10200 *}
. bfd_arch_mn10300, {* Matsushita MN10300 *}
. bfd_arch_last
. };
*/
/*
SUBSECTION
bfd_arch_info
DESCRIPTION
This structure contains information on architectures for use
within BFD.
.
.typedef struct bfd_arch_info
.{
. int bits_per_word;
. int bits_per_address;
. int bits_per_byte;
. enum bfd_architecture arch;
. unsigned long mach;
. const char *arch_name;
. const char *printable_name;
. unsigned int section_align_power;
. {* true if this is the default machine for the architecture *}
. boolean the_default;
. const struct bfd_arch_info * (*compatible)
. PARAMS ((const struct bfd_arch_info *a,
. const struct bfd_arch_info *b));
.
. boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
.
. const struct bfd_arch_info *next;
.} bfd_arch_info_type;
*/
extern const bfd_arch_info_type bfd_a29k_arch;
extern const bfd_arch_info_type bfd_alpha_arch;
extern const bfd_arch_info_type bfd_arm_arch;
extern const bfd_arch_info_type bfd_d10v_arch;
extern const bfd_arch_info_type bfd_h8300_arch;
extern const bfd_arch_info_type bfd_h8500_arch;
extern const bfd_arch_info_type bfd_hppa_arch;
extern const bfd_arch_info_type bfd_i386_arch;
extern const bfd_arch_info_type bfd_i860_arch;
extern const bfd_arch_info_type bfd_i960_arch;
extern const bfd_arch_info_type bfd_m32r_arch;
extern const bfd_arch_info_type bfd_m68k_arch;
extern const bfd_arch_info_type bfd_m88k_arch;
extern const bfd_arch_info_type bfd_mips_arch;
extern const bfd_arch_info_type bfd_mn10200_arch;
extern const bfd_arch_info_type bfd_mn10300_arch;
extern const bfd_arch_info_type bfd_powerpc_arch;
extern const bfd_arch_info_type bfd_rs6000_arch;
extern const bfd_arch_info_type bfd_sh_arch;
extern const bfd_arch_info_type bfd_sparc_arch;
extern const bfd_arch_info_type bfd_vax_arch;
extern const bfd_arch_info_type bfd_we32k_arch;
extern const bfd_arch_info_type bfd_z8k_arch;
extern const bfd_arch_info_type bfd_ns32k_arch;
extern const bfd_arch_info_type bfd_w65_arch;
static const bfd_arch_info_type * const bfd_archures_list[] =
{
#ifdef SELECT_ARCHITECTURES
SELECT_ARCHITECTURES,
#else
&bfd_a29k_arch,
&bfd_alpha_arch,
&bfd_arm_arch,
&bfd_d10v_arch,
&bfd_h8300_arch,
&bfd_h8500_arch,
&bfd_hppa_arch,
&bfd_i386_arch,
&bfd_i860_arch,
&bfd_i960_arch,
&bfd_m32r_arch,
&bfd_m68k_arch,
&bfd_m88k_arch,
&bfd_mips_arch,
&bfd_mn10200_arch,
&bfd_mn10300_arch,
&bfd_powerpc_arch,
&bfd_rs6000_arch,
&bfd_sh_arch,
&bfd_sparc_arch,
&bfd_vax_arch,
&bfd_we32k_arch,
&bfd_z8k_arch,
&bfd_ns32k_arch,
&bfd_w65_arch,
#endif
0
};
/*
FUNCTION
bfd_printable_name
SYNOPSIS
const char *bfd_printable_name(bfd *abfd);
DESCRIPTION
Return a printable string representing the architecture and machine
from the pointer to the architecture info structure.
*/
const char *
bfd_printable_name (abfd)
bfd *abfd;
{
return abfd->arch_info->printable_name;
}
/*
FUNCTION
bfd_scan_arch
SYNOPSIS
const bfd_arch_info_type *bfd_scan_arch(const char *string);
DESCRIPTION
Figure out if BFD supports any cpu which could be described with
the name @var{string}. Return a pointer to an <<arch_info>>
structure if a machine is found, otherwise NULL.
*/
const bfd_arch_info_type *
bfd_scan_arch (string)
const char *string;
{
const bfd_arch_info_type * const *app, *ap;
/* Look through all the installed architectures */
for (app = bfd_archures_list; *app != NULL; app++)
{
for (ap = *app; ap != NULL; ap = ap->next)
{
if (ap->scan (ap, string))
return ap;
}
}
return NULL;
}
/*
FUNCTION
bfd_arch_get_compatible
SYNOPSIS
const bfd_arch_info_type *bfd_arch_get_compatible(
const bfd *abfd,
const bfd *bbfd);
DESCRIPTION
Determine whether two BFDs'
architectures and machine types are compatible. Calculates
the lowest common denominator between the two architectures
and machine types implied by the BFDs and returns a pointer to
an <<arch_info>> structure describing the compatible machine.
*/
const bfd_arch_info_type *
bfd_arch_get_compatible (abfd, bbfd)
const bfd *abfd;
const bfd *bbfd;
{
/* If either architecture is unknown, then all we can do is assume
the user knows what he's doing. */
if (abfd->arch_info->arch == bfd_arch_unknown)
return bbfd->arch_info;
if (bbfd->arch_info->arch == bfd_arch_unknown)
return abfd->arch_info;
/* Otherwise architecture-specific code has to decide. */
return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
}
/*
INTERNAL_DEFINITION
bfd_default_arch_struct
DESCRIPTION
The <<bfd_default_arch_struct>> is an item of
<<bfd_arch_info_type>> which has been initialized to a fairly
generic state. A BFD starts life by pointing to this
structure, until the correct back end has determined the real
architecture of the file.
.extern const bfd_arch_info_type bfd_default_arch_struct;
*/
const bfd_arch_info_type bfd_default_arch_struct =
{
32,32,8,bfd_arch_unknown,0,"unknown","unknown",2,true,
bfd_default_compatible,
bfd_default_scan,
0,
};
/*
FUNCTION
bfd_set_arch_info
SYNOPSIS
void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
DESCRIPTION
Set the architecture info of @var{abfd} to @var{arg}.
*/
void
bfd_set_arch_info (abfd, arg)
bfd *abfd;
const bfd_arch_info_type *arg;
{
abfd->arch_info = arg;
}
/*
INTERNAL_FUNCTION
bfd_default_set_arch_mach
SYNOPSIS
boolean bfd_default_set_arch_mach(bfd *abfd,
enum bfd_architecture arch,
unsigned long mach);
DESCRIPTION
Set the architecture and machine type in BFD @var{abfd}
to @var{arch} and @var{mach}. Find the correct
pointer to a structure and insert it into the <<arch_info>>
pointer.
*/
boolean
bfd_default_set_arch_mach (abfd, arch, mach)
bfd *abfd;
enum bfd_architecture arch;
unsigned long mach;
{
const bfd_arch_info_type * const *app, *ap;
for (app = bfd_archures_list; *app != NULL; app++)
{
for (ap = *app; ap != NULL; ap = ap->next)
{
if (ap->arch == arch
&& (ap->mach == mach
|| (mach == 0 && ap->the_default)))
{
abfd->arch_info = ap;
return true;
}
}
}
abfd->arch_info = &bfd_default_arch_struct;
bfd_set_error (bfd_error_bad_value);
return false;
}
/*
FUNCTION
bfd_get_arch
SYNOPSIS
enum bfd_architecture bfd_get_arch(bfd *abfd);
DESCRIPTION
Return the enumerated type which describes the BFD @var{abfd}'s
architecture.
*/
enum bfd_architecture
bfd_get_arch (abfd)
bfd *abfd;
{
return abfd->arch_info->arch;
}
/*
FUNCTION
bfd_get_mach
SYNOPSIS
unsigned long bfd_get_mach(bfd *abfd);
DESCRIPTION
Return the long type which describes the BFD @var{abfd}'s
machine.
*/
unsigned long
bfd_get_mach (abfd)
bfd *abfd;
{
return abfd->arch_info->mach;
}
/*
FUNCTION
bfd_arch_bits_per_byte
SYNOPSIS
unsigned int bfd_arch_bits_per_byte(bfd *abfd);
DESCRIPTION
Return the number of bits in one of the BFD @var{abfd}'s
architecture's bytes.
*/
unsigned int
bfd_arch_bits_per_byte (abfd)
bfd *abfd;
{
return abfd->arch_info->bits_per_byte;
}
/*
FUNCTION
bfd_arch_bits_per_address
SYNOPSIS
unsigned int bfd_arch_bits_per_address(bfd *abfd);
DESCRIPTION
Return the number of bits in one of the BFD @var{abfd}'s
architecture's addresses.
*/
unsigned int
bfd_arch_bits_per_address (abfd)
bfd *abfd;
{
return abfd->arch_info->bits_per_address;
}
/*
INTERNAL_FUNCTION
bfd_default_compatible
SYNOPSIS
const bfd_arch_info_type *bfd_default_compatible
(const bfd_arch_info_type *a,
const bfd_arch_info_type *b);
DESCRIPTION
The default function for testing for compatibility.
*/
const bfd_arch_info_type *
bfd_default_compatible (a,b)
const bfd_arch_info_type *a;
const bfd_arch_info_type *b;
{
if (a->arch != b->arch)
return NULL;
if (a->mach > b->mach)
return a;
if (b->mach > a->mach)
return b;
return a;
}
/*
INTERNAL_FUNCTION
bfd_default_scan
SYNOPSIS
boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
DESCRIPTION
The default function for working out whether this is an
architecture hit and a machine hit.
*/
boolean
bfd_default_scan (info, string)
const struct bfd_arch_info *info;
const char *string;
{
const char *ptr_src;
const char *ptr_tst;
unsigned long number;
enum bfd_architecture arch;
/* First test for an exact match */
if (strcmp (string, info->printable_name) == 0)
return true;
/* See how much of the supplied string matches with the
architecture, eg the string m68k:68020 would match the 68k entry
up to the :, then we get left with the machine number */
for (ptr_src = string, ptr_tst = info->arch_name;
*ptr_src && *ptr_tst;
ptr_src++, ptr_tst++)
{
if (*ptr_src != *ptr_tst) break;
}
/* Chewed up as much of the architecture as will match, skip any
colons */
if (*ptr_src == ':')
ptr_src++;
if (*ptr_src == 0)
{
/* nothing more, then only keep this one if it is the default
machine for this architecture */
return info->the_default;
}
number = 0;
while (isdigit(*ptr_src))
{
number = number * 10 + *ptr_src - '0';
ptr_src++;
}
switch (number)
{
case 65:
arch = bfd_arch_w65;
break;
case 300:
arch = bfd_arch_h8300;
break;
case 500:
arch = bfd_arch_h8500;
break;
case 68010:
case 68020:
case 68030:
case 68040:
case 68332:
case 68050:
case 68000:
arch = bfd_arch_m68k;
break;
case 386:
case 80386:
case 486:
case 80486:
arch = bfd_arch_i386;
break;
case 29000:
arch = bfd_arch_a29k;
break;
case 8000:
arch = bfd_arch_z8k;
break;
case 32000:
arch = bfd_arch_we32k;
break;
case 860:
case 80860:
arch = bfd_arch_i860;
break;
case 960:
case 80960:
arch = bfd_arch_i960;
break;
case 2000:
case 3000:
case 4000:
case 4400:
arch = bfd_arch_mips;
break;
case 6000:
arch = bfd_arch_rs6000;
break;
default:
return false;
}
if (arch != info->arch)
return false;
if (number != info->mach)
return false;
return true;
}
/*
FUNCTION
bfd_get_arch_info
SYNOPSIS
const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
DESCRIPTION
Return the architecture info struct in @var{abfd}.
*/
const bfd_arch_info_type *
bfd_get_arch_info (abfd)
bfd *abfd;
{
return abfd->arch_info;
}
/*
FUNCTION
bfd_lookup_arch
SYNOPSIS
const bfd_arch_info_type *bfd_lookup_arch
(enum bfd_architecture
arch,
unsigned long machine);
DESCRIPTION
Look for the architecure info structure which matches the
arguments @var{arch} and @var{machine}. A machine of 0 matches the
machine/architecture structure which marks itself as the
default.
*/
const bfd_arch_info_type *
bfd_lookup_arch (arch, machine)
enum bfd_architecture arch;
unsigned long machine;
{
const bfd_arch_info_type * const *app, *ap;
for (app = bfd_archures_list; *app != NULL; app++)
{
for (ap = *app; ap != NULL; ap = ap->next)
{
if (ap->arch == arch
&& (ap->mach == machine
|| (machine == 0 && ap->the_default)))
return ap;
}
}
return NULL;
}
/*
FUNCTION
bfd_printable_arch_mach
SYNOPSIS
const char *bfd_printable_arch_mach
(enum bfd_architecture arch, unsigned long machine);
DESCRIPTION
Return a printable string representing the architecture and
machine type.
This routine is depreciated.
*/
const char *
bfd_printable_arch_mach (arch, machine)
enum bfd_architecture arch;
unsigned long machine;
{
const bfd_arch_info_type *ap = bfd_lookup_arch (arch, machine);
if (ap)
return ap->printable_name;
return "UNKNOWN!";
}

View File

@ -0,0 +1,693 @@
/* Main header file for the bfd library -- portable access to object files.
Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Contributed by Cygnus Support.
** NOTE: bfd.h and bfd-in2.h are GENERATED files. Don't change them;
** instead, change bfd-in.h or the other BFD source files processed to
** generate these files.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* bfd.h -- The only header file required by users of the bfd library
The bfd.h file is generated from bfd-in.h and various .c files; if you
change it, your changes will probably be lost.
All the prototypes and definitions following the comment "THE FOLLOWING
IS EXTRACTED FROM THE SOURCE" are extracted from the source files for
BFD. If you change it, someone oneday will extract it from the source
again, and your changes will be lost. To save yourself from this bind,
change the definitions in the source in the bfd directory. Type "make
docs" and then "make headers" in that directory, and magically this file
will change to reflect your changes.
If you don't have the tools to perform the extraction, then you are
safe from someone on your system trampling over your header files.
You should still maintain the equivalence between the source and this
file though; every change you make to the .c file should be reflected
here. */
#ifndef __BFD_H_SEEN__
#define __BFD_H_SEEN__
#ifdef __cplusplus
extern "C" {
#endif
#include "ansidecl.h"
/* These two lines get substitutions done by commands in Makefile.in. */
#define BFD_VERSION "@VERSION@"
#define BFD_ARCH_SIZE @wordsize@
#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
#if @BFD_HOST_64_BIT_DEFINED@
#define BFD_HOST_64_BIT @BFD_HOST_64_BIT@
#define BFD_HOST_U_64_BIT @BFD_HOST_U_64_BIT@
#endif
#if BFD_ARCH_SIZE >= 64
#define BFD64
#endif
#ifndef INLINE
#if __GNUC__ >= 2
#define INLINE __inline__
#else
#define INLINE
#endif
#endif
/* forward declaration */
typedef struct _bfd bfd;
/* To squelch erroneous compiler warnings ("illegal pointer
combination") from the SVR3 compiler, we would like to typedef
boolean to int (it doesn't like functions which return boolean.
Making sure they are never implicitly declared to return int
doesn't seem to help). But this file is not configured based on
the host. */
/* General rules: functions which are boolean return true on success
and false on failure (unless they're a predicate). -- bfd.doc */
/* I'm sure this is going to break something and someone is going to
force me to change it. */
/* typedef enum boolean {false, true} boolean; */
/* Yup, SVR4 has a "typedef enum boolean" in <sys/types.h> -fnf */
/* It gets worse if the host also defines a true/false enum... -sts */
/* And even worse if your compiler has built-in boolean types... -law */
#if defined (__GNUG__) && (__GNUC_MINOR__ > 5)
#define TRUE_FALSE_ALREADY_DEFINED
#endif
#ifdef MPW
/* Pre-emptive strike - get the file with the enum. */
#include <Types.h>
#define TRUE_FALSE_ALREADY_DEFINED
#endif /* MPW */
#ifndef TRUE_FALSE_ALREADY_DEFINED
typedef enum bfd_boolean {false, true} boolean;
#define BFD_TRUE_FALSE
#else
/* Use enum names that will appear nowhere else. */
typedef enum bfd_boolean {bfd_fffalse, bfd_tttrue} boolean;
#endif
/* A pointer to a position in a file. */
/* FIXME: This should be using off_t from <sys/types.h>.
For now, try to avoid breaking stuff by not including <sys/types.h> here.
This will break on systems with 64-bit file offsets (e.g. 4.4BSD).
Probably the best long-term answer is to avoid using file_ptr AND off_t
in this header file, and to handle this in the BFD implementation
rather than in its interface. */
/* typedef off_t file_ptr; */
typedef long int file_ptr;
/* Support for different sizes of target format ints and addresses.
If the type `long' is at least 64 bits, BFD_HOST_64BIT_LONG will be
set to 1 above. Otherwise, if gcc is being used, this code will
use gcc's "long long" type. Otherwise, BFD_HOST_64_BIT must be
defined above. */
#ifdef BFD64
#ifndef BFD_HOST_64_BIT
#if BFD_HOST_64BIT_LONG
#define BFD_HOST_64_BIT long
#define BFD_HOST_U_64_BIT unsigned long
#else
#ifdef __GNUC__
#define BFD_HOST_64_BIT long long
#define BFD_HOST_U_64_BIT unsigned long long
#else /* ! defined (__GNUC__) */
#error No 64 bit integer type available
#endif /* ! defined (__GNUC__) */
#endif /* ! BFD_HOST_64BIT_LONG */
#endif /* ! defined (BFD_HOST_64_BIT) */
typedef BFD_HOST_U_64_BIT bfd_vma;
typedef BFD_HOST_64_BIT bfd_signed_vma;
typedef BFD_HOST_U_64_BIT bfd_size_type;
typedef BFD_HOST_U_64_BIT symvalue;
#ifndef fprintf_vma
#if BFD_HOST_64BIT_LONG
#define sprintf_vma(s,x) sprintf (s, "%016lx", x)
#define fprintf_vma(f,x) fprintf (f, "%016lx", x)
#else
#define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
#define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
#define fprintf_vma(s,x) \
fprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
#define sprintf_vma(s,x) \
sprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
#endif
#endif
#else /* not BFD64 */
/* Represent a target address. Also used as a generic unsigned type
which is guaranteed to be big enough to hold any arithmetic types
we need to deal with. */
typedef unsigned long bfd_vma;
/* A generic signed type which is guaranteed to be big enough to hold any
arithmetic types we need to deal with. Can be assumed to be compatible
with bfd_vma in the same way that signed and unsigned ints are compatible
(as parameters, in assignment, etc). */
typedef long bfd_signed_vma;
typedef unsigned long symvalue;
typedef unsigned long bfd_size_type;
/* Print a bfd_vma x on stream s. */
#define fprintf_vma(s,x) fprintf(s, "%08lx", x)
#define sprintf_vma(s,x) sprintf(s, "%08lx", x)
#endif /* not BFD64 */
#define printf_vma(x) fprintf_vma(stdout,x)
typedef unsigned int flagword; /* 32 bits of flags */
typedef unsigned char bfd_byte;
/** File formats */
typedef enum bfd_format {
bfd_unknown = 0, /* file format is unknown */
bfd_object, /* linker/assember/compiler output */
bfd_archive, /* object archive file */
bfd_core, /* core dump */
bfd_type_end} /* marks the end; don't use it! */
bfd_format;
/* Values that may appear in the flags field of a BFD. These also
appear in the object_flags field of the bfd_target structure, where
they indicate the set of flags used by that backend (not all flags
are meaningful for all object file formats) (FIXME: at the moment,
the object_flags values have mostly just been copied from backend
to another, and are not necessarily correct). */
/* No flags. */
#define BFD_NO_FLAGS 0x00
/* BFD contains relocation entries. */
#define HAS_RELOC 0x01
/* BFD is directly executable. */
#define EXEC_P 0x02
/* BFD has line number information (basically used for F_LNNO in a
COFF header). */
#define HAS_LINENO 0x04
/* BFD has debugging information. */
#define HAS_DEBUG 0x08
/* BFD has symbols. */
#define HAS_SYMS 0x10
/* BFD has local symbols (basically used for F_LSYMS in a COFF
header). */
#define HAS_LOCALS 0x20
/* BFD is a dynamic object. */
#define DYNAMIC 0x40
/* Text section is write protected (if D_PAGED is not set, this is
like an a.out NMAGIC file) (the linker sets this by default, but
clears it for -r or -N). */
#define WP_TEXT 0x80
/* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
linker sets this by default, but clears it for -r or -n or -N). */
#define D_PAGED 0x100
/* BFD is relaxable (this means that bfd_relax_section may be able to
do something) (sometimes bfd_relax_section can do something even if
this is not set). */
#define BFD_IS_RELAXABLE 0x200
/* This may be set before writing out a BFD to request using a
traditional format. For example, this is used to request that when
writing out an a.out object the symbols not be hashed to eliminate
duplicates. */
#define BFD_TRADITIONAL_FORMAT 0x400
/* This flag indicates that the BFD contents are actually cached in
memory. If this is set, iostream points to a bfd_in_memory struct. */
#define BFD_IN_MEMORY 0x800
/* symbols and relocation */
/* A count of carsyms (canonical archive symbols). */
typedef unsigned long symindex;
/* How to perform a relocation. */
typedef const struct reloc_howto_struct reloc_howto_type;
#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
/* General purpose part of a symbol X;
target specific parts are in libcoff.h, libaout.h, etc. */
#define bfd_get_section(x) ((x)->section)
#define bfd_get_output_section(x) ((x)->section->output_section)
#define bfd_set_section(x,y) ((x)->section) = (y)
#define bfd_asymbol_base(x) ((x)->section->vma)
#define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
#define bfd_asymbol_name(x) ((x)->name)
/*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
#define bfd_asymbol_bfd(x) ((x)->the_bfd)
#define bfd_asymbol_flavour(x) (bfd_asymbol_bfd(x)->xvec->flavour)
/* A canonical archive symbol. */
/* This is a type pun with struct ranlib on purpose! */
typedef struct carsym {
char *name;
file_ptr file_offset; /* look here to find the file */
} carsym; /* to make these you call a carsymogen */
/* Used in generating armaps (archive tables of contents).
Perhaps just a forward definition would do? */
struct orl { /* output ranlib */
char **name; /* symbol name */
file_ptr pos; /* bfd* or file position */
int namidx; /* index into string table */
};
/* Linenumber stuff */
typedef struct lineno_cache_entry {
unsigned int line_number; /* Linenumber from start of function*/
union {
struct symbol_cache_entry *sym; /* Function name */
unsigned long offset; /* Offset into section */
} u;
} alent;
/* object and core file sections */
#define align_power(addr, align) \
( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
typedef struct sec *sec_ptr;
#define bfd_get_section_name(bfd, ptr) ((ptr)->name + 0)
#define bfd_get_section_vma(bfd, ptr) ((ptr)->vma + 0)
#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
#define bfd_section_name(bfd, ptr) ((ptr)->name)
#define bfd_section_size(bfd, ptr) (bfd_get_section_size_before_reloc(ptr))
#define bfd_section_vma(bfd, ptr) ((ptr)->vma)
#define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
#define bfd_get_section_flags(bfd, ptr) ((ptr)->flags + 0)
#define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
#define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma= (val)), ((ptr)->user_set_vma = (boolean)true), true)
#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),true)
#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),true)
typedef struct stat stat_type;
typedef enum bfd_print_symbol
{
bfd_print_symbol_name,
bfd_print_symbol_more,
bfd_print_symbol_all
} bfd_print_symbol_type;
/* Information about a symbol that nm needs. */
typedef struct _symbol_info
{
symvalue value;
char type;
CONST char *name; /* Symbol name. */
unsigned char stab_type; /* Stab type. */
char stab_other; /* Stab other. */
short stab_desc; /* Stab desc. */
CONST char *stab_name; /* String for stab type. */
} symbol_info;
/* Get the name of a stabs type code. */
extern const char *bfd_get_stab_name PARAMS ((int));
/* Hash table routines. There is no way to free up a hash table. */
/* An element in the hash table. Most uses will actually use a larger
structure, and an instance of this will be the first field. */
struct bfd_hash_entry
{
/* Next entry for this hash code. */
struct bfd_hash_entry *next;
/* String being hashed. */
const char *string;
/* Hash code. This is the full hash code, not the index into the
table. */
unsigned long hash;
};
/* A hash table. */
struct bfd_hash_table
{
/* The hash array. */
struct bfd_hash_entry **table;
/* The number of slots in the hash table. */
unsigned int size;
/* A function used to create new elements in the hash table. The
first entry is itself a pointer to an element. When this
function is first invoked, this pointer will be NULL. However,
having the pointer permits a hierarchy of method functions to be
built each of which calls the function in the superclass. Thus
each function should be written to allocate a new block of memory
only if the argument is NULL. */
struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *));
/* An objalloc for this hash table. This is a struct objalloc *,
but we use PTR to avoid requiring the inclusion of objalloc.h. */
PTR memory;
};
/* Initialize a hash table. */
extern boolean bfd_hash_table_init
PARAMS ((struct bfd_hash_table *,
struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *)));
/* Initialize a hash table specifying a size. */
extern boolean bfd_hash_table_init_n
PARAMS ((struct bfd_hash_table *,
struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *),
unsigned int size));
/* Free up a hash table. */
extern void bfd_hash_table_free PARAMS ((struct bfd_hash_table *));
/* Look up a string in a hash table. If CREATE is true, a new entry
will be created for this string if one does not already exist. The
COPY argument must be true if this routine should copy the string
into newly allocated memory when adding an entry. */
extern struct bfd_hash_entry *bfd_hash_lookup
PARAMS ((struct bfd_hash_table *, const char *, boolean create,
boolean copy));
/* Replace an entry in a hash table. */
extern void bfd_hash_replace
PARAMS ((struct bfd_hash_table *, struct bfd_hash_entry *old,
struct bfd_hash_entry *nw));
/* Base method for creating a hash table entry. */
extern struct bfd_hash_entry *bfd_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
const char *));
/* Grab some space for a hash table entry. */
extern PTR bfd_hash_allocate PARAMS ((struct bfd_hash_table *,
unsigned int));
/* Traverse a hash table in a random order, calling a function on each
element. If the function returns false, the traversal stops. The
INFO argument is passed to the function. */
extern void bfd_hash_traverse PARAMS ((struct bfd_hash_table *,
boolean (*) (struct bfd_hash_entry *,
PTR),
PTR info));
/* Semi-portable string concatenation in cpp.
The CAT4 hack is to avoid a problem with some strict ANSI C preprocessors.
The problem is, "32_" is not a valid preprocessing token, and we don't
want extra underscores (e.g., "nlm_32_"). The XCAT2 macro will cause the
inner CAT macros to be evaluated first, producing still-valid pp-tokens.
Then the final concatenation can be done. (Sigh.) */
#ifndef CAT
#ifdef SABER
#define CAT(a,b) a##b
#define CAT3(a,b,c) a##b##c
#define CAT4(a,b,c,d) a##b##c##d
#else
#if defined(__STDC__) || defined(ALMOST_STDC)
#define CAT(a,b) a##b
#define CAT3(a,b,c) a##b##c
#define XCAT2(a,b) CAT(a,b)
#define CAT4(a,b,c,d) XCAT2(CAT(a,b),CAT(c,d))
#else
#define CAT(a,b) a/**/b
#define CAT3(a,b,c) a/**/b/**/c
#define CAT4(a,b,c,d) a/**/b/**/c/**/d
#endif
#endif
#endif
#define COFF_SWAP_TABLE (PTR) &bfd_coff_std_swap_table
/* User program access to BFD facilities */
/* Direct I/O routines, for programs which know more about the object
file than BFD does. Use higher level routines if possible. */
extern bfd_size_type bfd_read
PARAMS ((PTR, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
extern bfd_size_type bfd_write
PARAMS ((const PTR, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
extern int bfd_seek PARAMS ((bfd *abfd, file_ptr fp, int direction));
extern long bfd_tell PARAMS ((bfd *abfd));
extern int bfd_flush PARAMS ((bfd *abfd));
extern int bfd_stat PARAMS ((bfd *abfd, struct stat *));
/* Cast from const char * to char * so that caller can assign to
a char * without a warning. */
#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
#define bfd_get_cacheable(abfd) ((abfd)->cacheable)
#define bfd_get_format(abfd) ((abfd)->format)
#define bfd_get_target(abfd) ((abfd)->xvec->name)
#define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
#define bfd_big_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_BIG)
#define bfd_little_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_LITTLE)
#define bfd_header_big_endian(abfd) \
((abfd)->xvec->header_byteorder == BFD_ENDIAN_BIG)
#define bfd_header_little_endian(abfd) \
((abfd)->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
#define bfd_get_file_flags(abfd) ((abfd)->flags)
#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
#define bfd_my_archive(abfd) ((abfd)->my_archive)
#define bfd_has_map(abfd) ((abfd)->has_armap)
#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
#define bfd_usrdata(abfd) ((abfd)->usrdata)
#define bfd_get_start_address(abfd) ((abfd)->start_address)
#define bfd_get_symcount(abfd) ((abfd)->symcount)
#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
#define bfd_count_sections(abfd) ((abfd)->section_count)
#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = (boolean)(bool)), true)
extern boolean bfd_record_phdr
PARAMS ((bfd *, unsigned long, boolean, flagword, boolean, bfd_vma,
boolean, boolean, unsigned int, struct sec **));
/* Byte swapping routines. */
bfd_vma bfd_getb64 PARAMS ((const unsigned char *));
bfd_vma bfd_getl64 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getb_signed_64 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getl_signed_64 PARAMS ((const unsigned char *));
bfd_vma bfd_getb32 PARAMS ((const unsigned char *));
bfd_vma bfd_getl32 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getb_signed_32 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getl_signed_32 PARAMS ((const unsigned char *));
bfd_vma bfd_getb16 PARAMS ((const unsigned char *));
bfd_vma bfd_getl16 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getb_signed_16 PARAMS ((const unsigned char *));
bfd_signed_vma bfd_getl_signed_16 PARAMS ((const unsigned char *));
void bfd_putb64 PARAMS ((bfd_vma, unsigned char *));
void bfd_putl64 PARAMS ((bfd_vma, unsigned char *));
void bfd_putb32 PARAMS ((bfd_vma, unsigned char *));
void bfd_putl32 PARAMS ((bfd_vma, unsigned char *));
void bfd_putb16 PARAMS ((bfd_vma, unsigned char *));
void bfd_putl16 PARAMS ((bfd_vma, unsigned char *));
/* Externally visible ECOFF routines. */
#if defined(__STDC__) || defined(ALMOST_STDC)
struct ecoff_debug_info;
struct ecoff_debug_swap;
struct ecoff_extr;
struct symbol_cache_entry;
struct bfd_link_info;
struct bfd_link_hash_entry;
struct bfd_elf_version_tree;
#endif
extern bfd_vma bfd_ecoff_get_gp_value PARAMS ((bfd * abfd));
extern boolean bfd_ecoff_set_gp_value PARAMS ((bfd *abfd, bfd_vma gp_value));
extern boolean bfd_ecoff_set_regmasks
PARAMS ((bfd *abfd, unsigned long gprmask, unsigned long fprmask,
unsigned long *cprmask));
extern PTR bfd_ecoff_debug_init
PARAMS ((bfd *output_bfd, struct ecoff_debug_info *output_debug,
const struct ecoff_debug_swap *output_swap,
struct bfd_link_info *));
extern void bfd_ecoff_debug_free
PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
const struct ecoff_debug_swap *output_swap,
struct bfd_link_info *));
extern boolean bfd_ecoff_debug_accumulate
PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
const struct ecoff_debug_swap *output_swap,
bfd *input_bfd, struct ecoff_debug_info *input_debug,
const struct ecoff_debug_swap *input_swap,
struct bfd_link_info *));
extern boolean bfd_ecoff_debug_accumulate_other
PARAMS ((PTR handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
struct bfd_link_info *));
extern boolean bfd_ecoff_debug_externals
PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
const struct ecoff_debug_swap *swap,
boolean relocateable,
boolean (*get_extr) (struct symbol_cache_entry *,
struct ecoff_extr *),
void (*set_index) (struct symbol_cache_entry *,
bfd_size_type)));
extern boolean bfd_ecoff_debug_one_external
PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
const struct ecoff_debug_swap *swap,
const char *name, struct ecoff_extr *esym));
extern bfd_size_type bfd_ecoff_debug_size
PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
const struct ecoff_debug_swap *swap));
extern boolean bfd_ecoff_write_debug
PARAMS ((bfd *abfd, struct ecoff_debug_info *debug,
const struct ecoff_debug_swap *swap, file_ptr where));
extern boolean bfd_ecoff_write_accumulated_debug
PARAMS ((PTR handle, bfd *abfd, struct ecoff_debug_info *debug,
const struct ecoff_debug_swap *swap,
struct bfd_link_info *info, file_ptr where));
extern boolean bfd_mips_ecoff_create_embedded_relocs
PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
char **));
/* Externally visible ELF routines. */
struct bfd_link_needed_list
{
struct bfd_link_needed_list *next;
bfd *by;
const char *name;
};
extern boolean bfd_elf32_record_link_assignment
PARAMS ((bfd *, struct bfd_link_info *, const char *, boolean));
extern boolean bfd_elf64_record_link_assignment
PARAMS ((bfd *, struct bfd_link_info *, const char *, boolean));
extern struct bfd_link_needed_list *bfd_elf_get_needed_list
PARAMS ((bfd *, struct bfd_link_info *));
extern boolean bfd_elf32_size_dynamic_sections
PARAMS ((bfd *, const char *, const char *, boolean, const char *,
const char * const *, struct bfd_link_info *, struct sec **,
struct bfd_elf_version_tree *));
extern boolean bfd_elf64_size_dynamic_sections
PARAMS ((bfd *, const char *, const char *, boolean, const char *,
const char * const *, struct bfd_link_info *, struct sec **,
struct bfd_elf_version_tree *));
extern void bfd_elf_set_dt_needed_name PARAMS ((bfd *, const char *));
extern const char *bfd_elf_get_dt_soname PARAMS ((bfd *));
/* SunOS shared library support routines for the linker. */
extern struct bfd_link_needed_list *bfd_sunos_get_needed_list
PARAMS ((bfd *, struct bfd_link_info *));
extern boolean bfd_sunos_record_link_assignment
PARAMS ((bfd *, struct bfd_link_info *, const char *));
extern boolean bfd_sunos_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *, struct sec **, struct sec **,
struct sec **));
/* Linux shared library support routines for the linker. */
extern boolean bfd_i386linux_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
extern boolean bfd_m68klinux_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
extern boolean bfd_sparclinux_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
/* mmap hacks */
struct _bfd_window_internal;
typedef struct _bfd_window_internal bfd_window_internal;
typedef struct _bfd_window {
/* What the user asked for. */
PTR data;
bfd_size_type size;
/* The actual window used by BFD. Small user-requested read-only
regions sharing a page may share a single window into the object
file. Read-write versions shouldn't until I've fixed things to
keep track of which portions have been claimed by the
application; don't want to give the same region back when the
application wants two writable copies! */
struct _bfd_window_internal *i;
} bfd_window;
extern void bfd_init_window PARAMS ((bfd_window *));
extern void bfd_free_window PARAMS ((bfd_window *));
extern boolean bfd_get_file_window
PARAMS ((bfd *, file_ptr, bfd_size_type, bfd_window *, boolean));
/* XCOFF support routines for the linker. */
extern boolean bfd_xcoff_link_record_set
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *,
bfd_size_type));
extern boolean bfd_xcoff_import_symbol
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *,
bfd_vma, const char *, const char *, const char *));
extern boolean bfd_xcoff_export_symbol
PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *,
boolean));
extern boolean bfd_xcoff_link_count_reloc
PARAMS ((bfd *, struct bfd_link_info *, const char *));
extern boolean bfd_xcoff_record_link_assignment
PARAMS ((bfd *, struct bfd_link_info *, const char *));
extern boolean bfd_xcoff_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *, const char *, const char *,
unsigned long, unsigned long, unsigned long, boolean,
int, boolean, boolean, struct sec **));
/* Externally visible COFF routines. */
#if defined(__STDC__) || defined(ALMOST_STDC)
struct internal_syment;
union internal_auxent;
#endif
extern boolean bfd_coff_get_syment
PARAMS ((bfd *, struct symbol_cache_entry *, struct internal_syment *));
extern boolean bfd_coff_get_auxent
PARAMS ((bfd *, struct symbol_cache_entry *, int, union internal_auxent *));
/* And more from the source. */

File diff suppressed because it is too large Load Diff

1137
contrib/binutils/bfd/bfd.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,361 @@
/* BFD back-end for binary objects.
Copyright 1994, 95, 96, 1997 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This is a BFD backend which may be used to write binary objects.
It may only be used for output, not input. The intention is that
this may be used as an output format for objcopy in order to
generate raw binary data.
This is very simple. The only complication is that the real data
will start at some address X, and in some cases we will not want to
include X zeroes just to get to that point. Since the start
address is not meaningful for this object file format, we use it
instead to indicate the number of zeroes to skip at the start of
the file. objcopy cooperates by specially setting the start
address to zero by default. */
#include <ctype.h>
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
/* Any bfd we create by reading a binary file has three symbols:
a start symbol, an end symbol, and an absolute length symbol. */
#define BIN_SYMS 3
static boolean binary_mkobject PARAMS ((bfd *));
static const bfd_target *binary_object_p PARAMS ((bfd *));
static boolean binary_get_section_contents
PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
static long binary_get_symtab_upper_bound PARAMS ((bfd *));
static char *mangle_name PARAMS ((bfd *, char *));
static long binary_get_symtab PARAMS ((bfd *, asymbol **));
static asymbol *binary_make_empty_symbol PARAMS ((bfd *));
static void binary_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
static boolean binary_set_section_contents
PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
static int binary_sizeof_headers PARAMS ((bfd *, boolean));
/* Create a binary object. Invoked via bfd_set_format. */
static boolean
binary_mkobject (abfd)
bfd *abfd;
{
return true;
}
/* Any file may be considered to be a binary file, provided the target
was not defaulted. That is, it must be explicitly specified as
being binary. */
static const bfd_target *
binary_object_p (abfd)
bfd *abfd;
{
struct stat statbuf;
asection *sec;
if (abfd->target_defaulted)
{
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
abfd->symcount = BIN_SYMS;
/* Find the file size. */
if (bfd_stat (abfd, &statbuf) < 0)
{
bfd_set_error (bfd_error_system_call);
return NULL;
}
/* One data section. */
sec = bfd_make_section (abfd, ".data");
if (sec == NULL)
return NULL;
sec->flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS;
sec->vma = 0;
sec->_raw_size = statbuf.st_size;
sec->filepos = 0;
abfd->tdata.any = (PTR) sec;
return abfd->xvec;
}
#define binary_close_and_cleanup _bfd_generic_close_and_cleanup
#define binary_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
#define binary_new_section_hook _bfd_generic_new_section_hook
/* Get contents of the only section. */
static boolean
binary_get_section_contents (abfd, section, location, offset, count)
bfd *abfd;
asection *section;
PTR location;
file_ptr offset;
bfd_size_type count;
{
if (bfd_seek (abfd, offset, SEEK_SET) != 0
|| bfd_read (location, 1, count, abfd) != count)
return false;
return true;
}
/* Return the amount of memory needed to read the symbol table. */
static long
binary_get_symtab_upper_bound (abfd)
bfd *abfd;
{
return (BIN_SYMS + 1) * sizeof (asymbol *);
}
/* Create a symbol name based on the bfd's filename. */
static char *
mangle_name (abfd, suffix)
bfd *abfd;
char *suffix;
{
int size;
char *buf;
char *p;
size = (strlen (bfd_get_filename (abfd))
+ strlen (suffix)
+ sizeof "_binary__");
buf = (char *) bfd_alloc (abfd, size);
if (buf == NULL)
return "";
sprintf (buf, "_binary_%s_%s", bfd_get_filename (abfd), suffix);
/* Change any non-alphanumeric characters to underscores. */
for (p = buf; *p; p++)
if (! isalnum (*p))
*p = '_';
return buf;
}
/* Return the symbol table. */
static long
binary_get_symtab (abfd, alocation)
bfd *abfd;
asymbol **alocation;
{
asection *sec = (asection *) abfd->tdata.any;
asymbol *syms;
unsigned int i;
syms = (asymbol *) bfd_alloc (abfd, BIN_SYMS * sizeof (asymbol));
if (syms == NULL)
return false;
/* Start symbol. */
syms[0].the_bfd = abfd;
syms[0].name = mangle_name (abfd, "start");
syms[0].value = 0;
syms[0].flags = BSF_GLOBAL;
syms[0].section = sec;
syms[0].udata.p = NULL;
/* End symbol. */
syms[1].the_bfd = abfd;
syms[1].name = mangle_name (abfd, "end");
syms[1].value = sec->_raw_size;
syms[1].flags = BSF_GLOBAL;
syms[1].section = sec;
syms[1].udata.p = NULL;
/* Size symbol. */
syms[2].the_bfd = abfd;
syms[2].name = mangle_name (abfd, "size");
syms[2].value = sec->_raw_size;
syms[2].flags = BSF_GLOBAL;
syms[2].section = bfd_abs_section_ptr;
syms[2].udata.p = NULL;
for (i = 0; i < BIN_SYMS; i++)
*alocation++ = syms++;
*alocation = NULL;
return BIN_SYMS;
}
/* Make an empty symbol. */
static asymbol *
binary_make_empty_symbol (abfd)
bfd *abfd;
{
return (asymbol *) bfd_alloc (abfd, sizeof (asymbol));
}
#define binary_print_symbol _bfd_nosymbols_print_symbol
/* Get information about a symbol. */
static void
binary_get_symbol_info (ignore_abfd, symbol, ret)
bfd *ignore_abfd;
asymbol *symbol;
symbol_info *ret;
{
bfd_symbol_info (symbol, ret);
}
#define binary_bfd_is_local_label_name bfd_generic_is_local_label_name
#define binary_get_lineno _bfd_nosymbols_get_lineno
#define binary_find_nearest_line _bfd_nosymbols_find_nearest_line
#define binary_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
#define binary_read_minisymbols _bfd_generic_read_minisymbols
#define binary_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
#define binary_get_reloc_upper_bound \
((long (*) PARAMS ((bfd *, asection *))) bfd_0l)
#define binary_canonicalize_reloc \
((long (*) PARAMS ((bfd *, asection *, arelent **, asymbol **))) bfd_0l)
#define binary_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
/* Set the architecture of a binary file. */
#define binary_set_arch_mach _bfd_generic_set_arch_mach
/* Write section contents of a binary file. */
static boolean
binary_set_section_contents (abfd, sec, data, offset, size)
bfd *abfd;
asection *sec;
PTR data;
file_ptr offset;
bfd_size_type size;
{
/* We don't want to output anything for a section that is neither
loaded nor allocated. The contents of such a section are not
meaningful in the binary format. */
if ((sec->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
return true;
if (! abfd->output_has_begun)
{
boolean found_low;
bfd_vma low;
asection *s;
/* The lowest section LMA sets the virtual address of the start
of the file. We use this to set the file position of all the
sections. */
found_low = false;
low = 0;
for (s = abfd->sections; s != NULL; s = s->next)
if (((s->flags & (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC))
== (SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC))
&& (! found_low || s->lma < low))
{
low = s->lma;
found_low = true;
}
for (s = abfd->sections; s != NULL; s = s->next)
s->filepos = s->lma - low;
abfd->output_has_begun = true;
}
return _bfd_generic_set_section_contents (abfd, sec, data, offset, size);
}
/* No space is required for header information. */
static int
binary_sizeof_headers (abfd, exec)
bfd *abfd;
boolean exec;
{
return 0;
}
#define binary_bfd_get_relocated_section_contents \
bfd_generic_get_relocated_section_contents
#define binary_bfd_relax_section bfd_generic_relax_section
#define binary_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
#define binary_bfd_link_add_symbols _bfd_generic_link_add_symbols
#define binary_bfd_final_link _bfd_generic_final_link
#define binary_bfd_link_split_section _bfd_generic_link_split_section
#define binary_get_section_contents_in_window \
_bfd_generic_get_section_contents_in_window
const bfd_target binary_vec =
{
"binary", /* name */
bfd_target_unknown_flavour, /* flavour */
BFD_ENDIAN_UNKNOWN, /* byteorder */
BFD_ENDIAN_UNKNOWN, /* header_byteorder */
EXEC_P, /* object_flags */
(SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
| SEC_ROM | SEC_HAS_CONTENTS), /* section_flags */
0, /* symbol_leading_char */
' ', /* ar_pad_char */
16, /* ar_max_namelen */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
{ /* bfd_check_format */
_bfd_dummy_target,
binary_object_p, /* bfd_check_format */
_bfd_dummy_target,
_bfd_dummy_target,
},
{ /* bfd_set_format */
bfd_false,
binary_mkobject,
bfd_false,
bfd_false,
},
{ /* bfd_write_contents */
bfd_false,
bfd_true,
bfd_false,
bfd_false,
},
BFD_JUMP_TABLE_GENERIC (binary),
BFD_JUMP_TABLE_COPY (_bfd_generic),
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
BFD_JUMP_TABLE_SYMBOLS (binary),
BFD_JUMP_TABLE_RELOCS (binary),
BFD_JUMP_TABLE_WRITE (binary),
BFD_JUMP_TABLE_LINK (binary),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
NULL
};

View File

@ -0,0 +1,350 @@
/* BFD library -- caching of file descriptors.
Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
SECTION
File caching
The file caching mechanism is embedded within BFD and allows
the application to open as many BFDs as it wants without
regard to the underlying operating system's file descriptor
limit (often as low as 20 open files). The module in
<<cache.c>> maintains a least recently used list of
<<BFD_CACHE_MAX_OPEN>> files, and exports the name
<<bfd_cache_lookup>>, which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file
handle.
*/
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
static void insert PARAMS ((bfd *));
static void snip PARAMS ((bfd *));
static boolean close_one PARAMS ((void));
static boolean bfd_cache_delete PARAMS ((bfd *));
/*
INTERNAL_FUNCTION
BFD_CACHE_MAX_OPEN macro
DESCRIPTION
The maximum number of files which the cache will keep open at
one time.
.#define BFD_CACHE_MAX_OPEN 10
*/
/* The number of BFD files we have open. */
static int open_files;
/*
INTERNAL_FUNCTION
bfd_last_cache
SYNOPSIS
extern bfd *bfd_last_cache;
DESCRIPTION
Zero, or a pointer to the topmost BFD on the chain. This is
used by the <<bfd_cache_lookup>> macro in @file{libbfd.h} to
determine when it can avoid a function call.
*/
bfd *bfd_last_cache;
/*
INTERNAL_FUNCTION
bfd_cache_lookup
DESCRIPTION
Check to see if the required BFD is the same as the last one
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;
otherwise, it has to perform the complicated lookup function.
.#define bfd_cache_lookup(x) \
. ((x)==bfd_last_cache? \
. (FILE*)(bfd_last_cache->iostream): \
. bfd_cache_lookup_worker(x))
*/
/* Insert a BFD into the cache. */
static INLINE void
insert (abfd)
bfd *abfd;
{
if (bfd_last_cache == NULL)
{
abfd->lru_next = abfd;
abfd->lru_prev = abfd;
}
else
{
abfd->lru_next = bfd_last_cache;
abfd->lru_prev = bfd_last_cache->lru_prev;
abfd->lru_prev->lru_next = abfd;
abfd->lru_next->lru_prev = abfd;
}
bfd_last_cache = abfd;
}
/* Remove a BFD from the cache. */
static INLINE void
snip (abfd)
bfd *abfd;
{
abfd->lru_prev->lru_next = abfd->lru_next;
abfd->lru_next->lru_prev = abfd->lru_prev;
if (abfd == bfd_last_cache)
{
bfd_last_cache = abfd->lru_next;
if (abfd == bfd_last_cache)
bfd_last_cache = NULL;
}
}
/* We need to open a new file, and the cache is full. Find the least
recently used cacheable BFD and close it. */
static boolean
close_one ()
{
register bfd *kill;
if (bfd_last_cache == NULL)
kill = NULL;
else
{
for (kill = bfd_last_cache->lru_prev;
! kill->cacheable;
kill = kill->lru_prev)
{
if (kill == bfd_last_cache)
{
kill = NULL;
break;
}
}
}
if (kill == NULL)
{
/* There are no open cacheable BFD's. */
return true;
}
kill->where = ftell ((FILE *) kill->iostream);
return bfd_cache_delete (kill);
}
/* Close a BFD and remove it from the cache. */
static boolean
bfd_cache_delete (abfd)
bfd *abfd;
{
boolean ret;
if (fclose ((FILE *) abfd->iostream) == 0)
ret = true;
else
{
ret = false;
bfd_set_error (bfd_error_system_call);
}
snip (abfd);
abfd->iostream = NULL;
--open_files;
return ret;
}
/*
INTERNAL_FUNCTION
bfd_cache_init
SYNOPSIS
boolean bfd_cache_init (bfd *abfd);
DESCRIPTION
Add a newly opened BFD to the cache.
*/
boolean
bfd_cache_init (abfd)
bfd *abfd;
{
BFD_ASSERT (abfd->iostream != NULL);
if (open_files >= BFD_CACHE_MAX_OPEN)
{
if (! close_one ())
return false;
}
insert (abfd);
++open_files;
return true;
}
/*
INTERNAL_FUNCTION
bfd_cache_close
SYNOPSIS
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
<<false>> is returned if closing the file fails, <<true>> is
returned if all is well.
*/
boolean
bfd_cache_close (abfd)
bfd *abfd;
{
if (abfd->iostream == NULL
|| (abfd->flags & BFD_IN_MEMORY) != 0)
return true;
return bfd_cache_delete (abfd);
}
/*
INTERNAL_FUNCTION
bfd_open_file
SYNOPSIS
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 *
bfd_open_file (abfd)
bfd *abfd;
{
abfd->cacheable = true; /* Allow it to be closed later. */
if (open_files >= BFD_CACHE_MAX_OPEN)
{
if (! close_one ())
return NULL;
}
switch (abfd->direction)
{
case read_direction:
case no_direction:
abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_RB);
break;
case both_direction:
case write_direction:
if (abfd->opened_once == true)
{
abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_RUB);
if (abfd->iostream == NULL)
abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WUB);
}
else
{
/* Create the file. Unlink it first, for the convenience of
operating systems which worry about overwriting running
binaries. */
unlink (abfd->filename);
abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WB);
abfd->opened_once = true;
}
break;
}
if (abfd->iostream != NULL)
{
if (! bfd_cache_init (abfd))
return NULL;
}
return (FILE *) abfd->iostream;
}
/*
INTERNAL_FUNCTION
bfd_cache_lookup_worker
SYNOPSIS
FILE *bfd_cache_lookup_worker(bfd *abfd);
DESCRIPTION
Called when the macro <<bfd_cache_lookup>> fails to find a
quick answer. Find a file descriptor for @var{abfd}. If
necessary, it open it. If there are already more than
<<BFD_CACHE_MAX_OPEN>> files open, it tries to close one first, to
avoid running out of file descriptors.
*/
FILE *
bfd_cache_lookup_worker (abfd)
bfd *abfd;
{
if ((abfd->flags & BFD_IN_MEMORY) != 0)
abort ();
if (abfd->my_archive)
abfd = abfd->my_archive;
if (abfd->iostream != NULL)
{
/* Move the file to the start of the cache. */
if (abfd != bfd_last_cache)
{
snip (abfd);
insert (abfd);
}
}
else
{
if (bfd_open_file (abfd) == NULL)
return NULL;
if (fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
return NULL;
}
return (FILE *) abfd->iostream;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,135 @@
/* BFD back-end for Apple M68K COFF A/UX 3.x files.
Copyright 1996, 1997 Free Software Foundation, Inc.
Written by Richard Henderson <rth@tamu.edu>.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define TARGET_SYM m68kaux_coff_vec
#define TARGET_NAME "coff-m68k-aux"
#ifndef TARG_AUX
#define TARG_AUX
#endif
#define COFF_LONG_FILENAMES
/* 4k pages */
#define COFF_PAGE_SIZE 0x1000
/* On AUX, a STYP_NOLOAD|STYP_BSS section is part of a shared library. */
#define BSS_NOLOAD_IS_SHARED_LIBRARY
#define STATIC_RELOCS
#define COFF_COMMON_ADDEND
#include "bfd.h"
#include "sysdep.h"
static boolean coff_m68k_aux_link_add_one_symbol
PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
asection *, bfd_vma, const char *, boolean, boolean,
struct bfd_link_hash_entry **));
#define coff_link_add_one_symbol coff_m68k_aux_link_add_one_symbol
#include "coff/aux-coff.h" /* override coff/internal.h and coff/m68k.h */
#include "coff-m68k.c"
/* We need non-absolute symbols to override absolute symbols. This
mirrors Apple's "solution" to let a static library symbol override
a shared library symbol. On the whole not a good thing, given how
shared libraries work here, but can work if you are careful with
what you include in the shared object. */
static boolean
coff_m68k_aux_link_add_one_symbol (info, abfd, name, flags, section, value,
string, copy, collect, hashp)
struct bfd_link_info *info;
bfd *abfd;
const char *name;
flagword flags;
asection *section;
bfd_vma value;
const char *string;
boolean copy;
boolean collect;
struct bfd_link_hash_entry **hashp;
{
struct bfd_link_hash_entry *h;
if ((flags & (BSF_WARNING | BSF_CONSTRUCTOR | BSF_WEAK)) == 0 &&
!bfd_is_und_section (section) &&
!bfd_is_com_section (section))
{
/* The new symbol is a definition or an indirect definition */
/* This bit copied from linker.c */
if (hashp != NULL && *hashp != NULL)
{
h = *hashp;
BFD_ASSERT (strcmp (h->root.string, name) == 0);
}
else
{
h = bfd_link_hash_lookup (info->hash, name, true, copy, false);
if (h == NULL)
{
if (hashp != NULL)
*hashp = NULL;
return false;
}
}
if (info->notice_hash != (struct bfd_hash_table *) NULL
&& (bfd_hash_lookup (info->notice_hash, name, false, false)
!= (struct bfd_hash_entry *) NULL))
{
if (! (*info->callbacks->notice) (info, name, abfd, section, value))
return false;
}
if (hashp != (struct bfd_link_hash_entry **) NULL)
*hashp = h;
/* end duplication from linker.c */
if (h->type == bfd_link_hash_defined
|| h->type == bfd_link_hash_indirect)
{
asection *msec;
if (h->type == bfd_link_hash_defined)
msec = h->u.def.section;
else
msec = bfd_ind_section_ptr;
if (bfd_is_abs_section (msec) && !bfd_is_abs_section (section))
{
h->u.def.section = section;
h->u.def.value = value;
return true;
}
else if (bfd_is_abs_section (section) && !bfd_is_abs_section (msec))
return true;
}
}
/* If we didn't exit early, finish processing in the generic routine */
return _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
value, string, copy, collect,
hashp);
}

View File

@ -0,0 +1,498 @@
/* BFD back-end for Intel 386 COFF files.
Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "coff/i386.h"
#include "coff/internal.h"
#ifdef COFF_WITH_PE
#include "coff/pe.h"
#endif
#include "libcoff.h"
static bfd_reloc_status_type coff_i386_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static reloc_howto_type *coff_i386_rtype_to_howto
PARAMS ((bfd *, asection *, struct internal_reloc *,
struct coff_link_hash_entry *, struct internal_syment *,
bfd_vma *));
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
/* The page size is a guess based on ELF. */
#define COFF_PAGE_SIZE 0x1000
/* For some reason when using i386 COFF the value stored in the .text
section for a reference to a common symbol is the value itself plus
any desired offset. Ian Taylor, Cygnus Support. */
/* If we are producing relocateable output, we need to do some
adjustments to the object file that are not done by the
bfd_perform_relocation function. This function is called by every
reloc type to make any required adjustments. */
static bfd_reloc_status_type
coff_i386_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
error_message)
bfd *abfd;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message;
{
symvalue diff;
if (output_bfd == (bfd *) NULL)
return bfd_reloc_continue;
if (bfd_is_com_section (symbol->section))
{
/* We are relocating a common symbol. The current value in the
object file is ORIG + OFFSET, where ORIG is the value of the
common symbol as seen by the object file when it was compiled
(this may be zero if the symbol was undefined) and OFFSET is
the offset into the common symbol (normally zero, but may be
non-zero when referring to a field in a common structure).
ORIG is the negative of reloc_entry->addend, which is set by
the CALC_ADDEND macro below. We want to replace the value in
the object file with NEW + OFFSET, where NEW is the value of
the common symbol which we are going to put in the final
object file. NEW is symbol->value. */
diff = symbol->value + reloc_entry->addend;
}
else
{
/* For some reason bfd_perform_relocation always effectively
ignores the addend for a COFF target when producing
relocateable output. This seems to be always wrong for 386
COFF, so we handle the addend here instead. */
diff = reloc_entry->addend;
}
#ifdef COFF_WITH_PE
if (reloc_entry->howto->type == 7)
{
/* diff -= coff_data(output_bfd)->link_info->pe_info.image_base.value;*/
exit(1);
}
#endif
#define DOIT(x) \
x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
if (diff != 0)
{
reloc_howto_type *howto = reloc_entry->howto;
unsigned char *addr = (unsigned char *) data + reloc_entry->address;
switch (howto->size)
{
case 0:
{
char x = bfd_get_8 (abfd, addr);
DOIT (x);
bfd_put_8 (abfd, x, addr);
}
break;
case 1:
{
short x = bfd_get_16 (abfd, addr);
DOIT (x);
bfd_put_16 (abfd, x, addr);
}
break;
case 2:
{
long x = bfd_get_32 (abfd, addr);
DOIT (x);
bfd_put_32 (abfd, x, addr);
}
break;
default:
abort ();
}
}
/* Now let bfd_perform_relocation finish everything up. */
return bfd_reloc_continue;
}
#ifdef COFF_WITH_PE
/* Return true if this relocation should
appear in the output .reloc section. */
static boolean in_reloc_p(abfd, howto)
bfd * abfd;
reloc_howto_type *howto;
{
return ! howto->pc_relative && howto->type != R_IMAGEBASE;
}
#endif
#ifndef PCRELOFFSET
#define PCRELOFFSET false
#endif
static reloc_howto_type howto_table[] =
{
{0},
{1},
{2},
{3},
{4},
{5},
HOWTO (R_DIR32, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"dir32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
true), /* pcrel_offset */
/* {7}, */
HOWTO (R_IMAGEBASE, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"rva32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
{010},
{011},
{012},
{013},
{014},
{015},
{016},
HOWTO (R_RELBYTE, /* type */
0, /* rightshift */
0, /* size (0 = byte, 1 = short, 2 = long) */
8, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"8", /* name */
true, /* partial_inplace */
0x000000ff, /* src_mask */
0x000000ff, /* dst_mask */
PCRELOFFSET), /* pcrel_offset */
HOWTO (R_RELWORD, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"16", /* name */
true, /* partial_inplace */
0x0000ffff, /* src_mask */
0x0000ffff, /* dst_mask */
PCRELOFFSET), /* pcrel_offset */
HOWTO (R_RELLONG, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
PCRELOFFSET), /* pcrel_offset */
HOWTO (R_PCRBYTE, /* type */
0, /* rightshift */
0, /* size (0 = byte, 1 = short, 2 = long) */
8, /* bitsize */
true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"DISP8", /* name */
true, /* partial_inplace */
0x000000ff, /* src_mask */
0x000000ff, /* dst_mask */
PCRELOFFSET), /* pcrel_offset */
HOWTO (R_PCRWORD, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"DISP16", /* name */
true, /* partial_inplace */
0x0000ffff, /* src_mask */
0x0000ffff, /* dst_mask */
PCRELOFFSET), /* pcrel_offset */
HOWTO (R_PCRLONG, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
coff_i386_reloc, /* special_function */
"DISP32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
PCRELOFFSET) /* pcrel_offset */
};
/* Turn a howto into a reloc nunmber */
#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
#define BADMAG(x) I386BADMAG(x)
#define I386 1 /* Customize coffcode.h */
#define RTYPE2HOWTO(cache_ptr, dst) \
(cache_ptr)->howto = howto_table + (dst)->r_type;
/* For 386 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
library. On some other COFF targets STYP_BSS is normally
STYP_NOLOAD. */
#define BSS_NOLOAD_IS_SHARED_LIBRARY
/* Compute the addend of a reloc. If the reloc is to a common symbol,
the object file contains the value of the common symbol. By the
time this is called, the linker may be using a different symbol
from a different object file with a different value. Therefore, we
hack wildly to locate the original symbol from this file so that we
can make the correct adjustment. This macro sets coffsym to the
symbol from the original file, and uses it to set the addend value
correctly. If this is not a common symbol, the usual addend
calculation is done, except that an additional tweak is needed for
PC relative relocs.
FIXME: This macro refers to symbols and asect; these are from the
calling function, not the macro arguments. */
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
{ \
coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
coffsym = (obj_symbols (abfd) \
+ (cache_ptr->sym_ptr_ptr - symbols)); \
else if (ptr) \
coffsym = coff_symbol_from (abfd, ptr); \
if (coffsym != (coff_symbol_type *) NULL \
&& coffsym->native->u.syment.n_scnum == 0) \
cache_ptr->addend = - coffsym->native->u.syment.n_value; \
else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
&& ptr->section != (asection *) NULL) \
cache_ptr->addend = - (ptr->section->vma + ptr->value); \
else \
cache_ptr->addend = 0; \
if (ptr && howto_table[reloc.r_type].pc_relative) \
cache_ptr->addend += asect->vma; \
}
/* We use the special COFF backend linker. */
#define coff_relocate_section _bfd_coff_generic_relocate_section
static reloc_howto_type *
coff_i386_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
bfd *abfd;
asection *sec;
struct internal_reloc *rel;
struct coff_link_hash_entry *h;
struct internal_syment *sym;
bfd_vma *addendp;
{
reloc_howto_type *howto;
howto = howto_table + rel->r_type;
#ifdef COFF_WITH_PE
*addendp = 0;
#endif
if (howto->pc_relative)
*addendp += sec->vma;
if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
{
/* This is a common symbol. The section contents include the
size (sym->n_value) as an addend. The relocate_section
function will be adding in the final value of the symbol. We
need to subtract out the current size in order to get the
correct result. */
BFD_ASSERT (h != NULL);
#ifndef COFF_WITH_PE
/* I think we *do* want to bypass this. If we don't, I have seen some data
parameters get the wrong relcation address. If I link two versions
with and without this section bypassed and then do a binary comparison,
the addresses which are different can be looked up in the map. The
case in which this section has been bypassed has addresses which correspond
to values I can find in the map */
*addendp -= sym->n_value;
#endif
}
/* If the output symbol is common (in which case this must be a
relocateable link), we need to add in the final size of the
common symbol. */
if (h != NULL && h->root.type == bfd_link_hash_common)
*addendp += h->root.u.c.size;
#ifdef COFF_WITH_PE
if (howto->pc_relative)
*addendp -= 4;
if (rel->r_type == R_IMAGEBASE)
{
*addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
}
#endif
return howto;
}
#define coff_bfd_reloc_type_lookup coff_i386_reloc_type_lookup
static reloc_howto_type *
coff_i386_reloc_type_lookup (abfd, code)
bfd *abfd;
bfd_reloc_code_real_type code;
{
switch (code)
{
case BFD_RELOC_RVA:
return howto_table +R_IMAGEBASE;
case BFD_RELOC_32:
return howto_table + R_DIR32;
case BFD_RELOC_32_PCREL:
return howto_table + R_PCRLONG;
default:
BFD_FAIL ();
return 0;
}
}
#define coff_rtype_to_howto coff_i386_rtype_to_howto
#include "coffcode.h"
static const bfd_target *
i3coff_object_p(a)
bfd *a;
{
return coff_object_p(a);
}
const bfd_target
#ifdef TARGET_SYM
TARGET_SYM =
#else
i386coff_vec =
#endif
{
#ifdef TARGET_NAME
TARGET_NAME,
#else
"coff-i386", /* name */
#endif
bfd_target_coff_flavour,
BFD_ENDIAN_LITTLE, /* data byte order is little */
BFD_ENDIAN_LITTLE, /* header byte order is little */
(HAS_RELOC | EXEC_P | /* object flags */
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
#ifndef COFF_WITH_PE
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
#else
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
| SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
#endif
#ifdef TARGET_UNDERSCORE
TARGET_UNDERSCORE, /* leading underscore */
#else
0, /* leading underscore */
#endif
'/', /* ar_pad_char */
15, /* ar_max_namelen */
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
/* Note that we allow an object file to be treated as a core file as well. */
{_bfd_dummy_target, i3coff_object_p, /* bfd_check_format */
bfd_generic_archive_p, i3coff_object_p},
{bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
bfd_false},
{bfd_false, coff_write_object_contents, /* bfd_write_contents */
_bfd_write_archive_contents, bfd_false},
BFD_JUMP_TABLE_GENERIC (coff),
BFD_JUMP_TABLE_COPY (coff),
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
BFD_JUMP_TABLE_SYMBOLS (coff),
BFD_JUMP_TABLE_RELOCS (coff),
BFD_JUMP_TABLE_WRITE (coff),
BFD_JUMP_TABLE_LINK (coff),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
COFF_SWAP_TABLE,
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,280 @@
/* BFD back-end for Zilog Z800n COFF binaries.
Copyright 1992, 93, 94, 95, 1997 Free Software Foundation, Inc.
Contributed by Cygnus Support.
Written by Steve Chamberlain, <sac@cygnus.com>.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "bfdlink.h"
#include "coff/z8k.h"
#include "coff/internal.h"
#include "libcoff.h"
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
static reloc_howto_type r_imm32 =
HOWTO (R_IMM32, 0, 1, 32, false, 0,
complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff,
0xffffffff, false);
static reloc_howto_type r_imm4l =
HOWTO (R_IMM4L, 0, 1, 4, false, 0,
complain_overflow_bitfield, 0, "r_imm4l", true, 0xf, 0xf, false);
static reloc_howto_type r_da =
HOWTO (R_IMM16, 0, 1, 16, false, 0,
complain_overflow_bitfield, 0, "r_da", true, 0x0000ffff, 0x0000ffff,
false);
static reloc_howto_type r_imm8 =
HOWTO (R_IMM8, 0, 1, 8, false, 0,
complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff,
false);
static reloc_howto_type r_jr =
HOWTO (R_JR, 0, 1, 8, true, 0, complain_overflow_signed, 0,
"r_jr", true, 0, 0, true);
/* Turn a howto into a reloc number */
static int
coff_z8k_select_reloc (howto)
reloc_howto_type *howto;
{
return howto->type;
}
#define SELECT_RELOC(x,howto) x.r_type = coff_z8k_select_reloc(howto)
#define BADMAG(x) Z8KBADMAG(x)
#define Z8K 1 /* Customize coffcode.h */
#define __A_MAGIC_SET__
/* Code to swap in the reloc */
#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
dst->r_stuff[0] = 'S'; \
dst->r_stuff[1] = 'C';
/* Code to turn a r_type into a howto ptr, uses the above howto table
*/
static void
rtype2howto (internal, dst)
arelent * internal;
struct internal_reloc *dst;
{
switch (dst->r_type)
{
default:
abort ();
break;
case R_IMM8:
internal->howto = &r_imm8;
break;
case R_IMM16:
internal->howto = &r_da;
break;
case R_JR:
internal->howto = &r_jr;
break;
case R_IMM32:
internal->howto = &r_imm32;
break;
case R_IMM4L:
internal->howto = &r_imm4l;
break;
}
}
#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
/* Perform any necessary magic to the addend in a reloc entry */
#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
cache_ptr->addend = ext_reloc.r_offset;
#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
reloc_processing(relent, reloc, symbols, abfd, section)
static void
reloc_processing (relent, reloc, symbols, abfd, section)
arelent * relent;
struct internal_reloc *reloc;
asymbol ** symbols;
bfd * abfd;
asection * section;
{
relent->address = reloc->r_vaddr;
rtype2howto (relent, reloc);
if (reloc->r_symndx > 0)
{
relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
}
else
{
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
}
relent->addend = reloc->r_offset;
relent->address -= section->vma;
}
static void
extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
bfd *in_abfd;
struct bfd_link_info *link_info;
struct bfd_link_order *link_order;
arelent *reloc;
bfd_byte *data;
unsigned int *src_ptr;
unsigned int *dst_ptr;
{
asection *input_section = link_order->u.indirect.section;
switch (reloc->howto->type)
{
case R_IMM8:
bfd_put_8 (in_abfd,
bfd_coff_reloc16_get_value (reloc, link_info, input_section),
data + *dst_ptr);
(*dst_ptr) += 1;
(*src_ptr) += 1;
break;
case R_IMM32:
bfd_put_32 (in_abfd,
bfd_coff_reloc16_get_value (reloc, link_info, input_section),
data + *dst_ptr);
(*dst_ptr) += 4;
(*src_ptr) += 4;
break;
case R_IMM4L:
bfd_put_8 (in_abfd,
((bfd_get_8 (in_abfd, data + *dst_ptr) & 0xf0)
| (0x0f
& bfd_coff_reloc16_get_value (reloc, link_info,
input_section))),
data + *dst_ptr);
(*dst_ptr) += 1;
(*src_ptr) += 1;
break;
case R_IMM16:
bfd_put_16 (in_abfd,
bfd_coff_reloc16_get_value (reloc, link_info, input_section),
data + *dst_ptr);
(*dst_ptr) += 2;
(*src_ptr) += 2;
break;
case R_JR:
{
bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
input_section);
bfd_vma dot = (link_order->offset
+ *dst_ptr
+ input_section->output_section->vma);
int gap = dst - dot - 1;/* -1 since were in the odd byte of the
word and the pc's been incremented */
if (gap & 1)
abort ();
gap /= 2;
if (gap > 128 || gap < -128)
{
if (! ((*link_info->callbacks->reloc_overflow)
(link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
reloc->howto->name, reloc->addend, input_section->owner,
input_section, reloc->address)))
abort ();
}
bfd_put_8 (in_abfd, gap, data + *dst_ptr);
(*dst_ptr)++;
(*src_ptr)++;
break;
}
default:
abort ();
}
}
#define coff_reloc16_extra_cases extra_case
#include "coffcode.h"
#undef coff_bfd_get_relocated_section_contents
#undef coff_bfd_relax_section
#define coff_bfd_get_relocated_section_contents \
bfd_coff_reloc16_get_relocated_section_contents
#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
const bfd_target z8kcoff_vec =
{
"coff-z8k", /* name */
bfd_target_coff_flavour,
BFD_ENDIAN_BIG, /* data byte order is big */
BFD_ENDIAN_BIG, /* header byte order is big */
(HAS_RELOC | EXEC_P | /* object flags */
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | WP_TEXT),
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
'_', /* leading symbol underscore */
'/', /* ar_pad_char */
15, /* ar_max_namelen */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
{_bfd_dummy_target, coff_object_p, /* bfd_check_format */
bfd_generic_archive_p, _bfd_dummy_target},
{bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
bfd_false},
{bfd_false, coff_write_object_contents, /* bfd_write_contents */
_bfd_write_archive_contents, bfd_false},
BFD_JUMP_TABLE_GENERIC (coff),
BFD_JUMP_TABLE_COPY (coff),
BFD_JUMP_TABLE_CORE (_bfd_nocore),
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
BFD_JUMP_TABLE_SYMBOLS (coff),
BFD_JUMP_TABLE_RELOCS (coff),
BFD_JUMP_TABLE_WRITE (coff),
BFD_JUMP_TABLE_LINK (coff),
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
COFF_SWAP_TABLE,
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,840 @@
/* Generic COFF swapping routines, for BFD.
Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This file contains routines used to swap COFF data. It is a header
file because the details of swapping depend on the details of the
structures used by each COFF implementation. This is included by
coffcode.h, as well as by the ECOFF backend.
Any file which uses this must first include "coff/internal.h" and
"coff/CPU.h". The functions will then be correct for that CPU. */
#ifndef IMAGE_BASE
#define IMAGE_BASE 0
#endif
#define PUTWORD bfd_h_put_32
#define PUTHALF bfd_h_put_16
#define PUTBYTE bfd_h_put_8
#ifndef GET_FCN_LNNOPTR
#define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
#endif
#ifndef GET_FCN_ENDNDX
#define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
#endif
#ifndef PUT_FCN_LNNOPTR
#define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
#endif
#ifndef PUT_FCN_ENDNDX
#define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
#endif
#ifndef GET_LNSZ_LNNO
#define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
#endif
#ifndef GET_LNSZ_SIZE
#define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
#endif
#ifndef PUT_LNSZ_LNNO
#define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
#endif
#ifndef PUT_LNSZ_SIZE
#define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
#endif
#ifndef GET_SCN_SCNLEN
#define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
#endif
#ifndef GET_SCN_NRELOC
#define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
#endif
#ifndef GET_SCN_NLINNO
#define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
#endif
#ifndef PUT_SCN_SCNLEN
#define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
#endif
#ifndef PUT_SCN_NRELOC
#define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
#endif
#ifndef PUT_SCN_NLINNO
#define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
#endif
#ifndef GET_LINENO_LNNO
#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
#endif
#ifndef PUT_LINENO_LNNO
#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
#endif
/* The f_symptr field in the filehdr is sometimes 64 bits. */
#ifndef GET_FILEHDR_SYMPTR
#define GET_FILEHDR_SYMPTR bfd_h_get_32
#endif
#ifndef PUT_FILEHDR_SYMPTR
#define PUT_FILEHDR_SYMPTR bfd_h_put_32
#endif
/* Some fields in the aouthdr are sometimes 64 bits. */
#ifndef GET_AOUTHDR_TSIZE
#define GET_AOUTHDR_TSIZE bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_TSIZE
#define PUT_AOUTHDR_TSIZE bfd_h_put_32
#endif
#ifndef GET_AOUTHDR_DSIZE
#define GET_AOUTHDR_DSIZE bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_DSIZE
#define PUT_AOUTHDR_DSIZE bfd_h_put_32
#endif
#ifndef GET_AOUTHDR_BSIZE
#define GET_AOUTHDR_BSIZE bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_BSIZE
#define PUT_AOUTHDR_BSIZE bfd_h_put_32
#endif
#ifndef GET_AOUTHDR_ENTRY
#define GET_AOUTHDR_ENTRY bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_ENTRY
#define PUT_AOUTHDR_ENTRY bfd_h_put_32
#endif
#ifndef GET_AOUTHDR_TEXT_START
#define GET_AOUTHDR_TEXT_START bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_TEXT_START
#define PUT_AOUTHDR_TEXT_START bfd_h_put_32
#endif
#ifndef GET_AOUTHDR_DATA_START
#define GET_AOUTHDR_DATA_START bfd_h_get_32
#endif
#ifndef PUT_AOUTHDR_DATA_START
#define PUT_AOUTHDR_DATA_START bfd_h_put_32
#endif
/* Some fields in the scnhdr are sometimes 64 bits. */
#ifndef GET_SCNHDR_PADDR
#define GET_SCNHDR_PADDR bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_PADDR
#define PUT_SCNHDR_PADDR bfd_h_put_32
#endif
#ifndef GET_SCNHDR_VADDR
#define GET_SCNHDR_VADDR bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_VADDR
#define PUT_SCNHDR_VADDR bfd_h_put_32
#endif
#ifndef GET_SCNHDR_SIZE
#define GET_SCNHDR_SIZE bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_SIZE
#define PUT_SCNHDR_SIZE bfd_h_put_32
#endif
#ifndef GET_SCNHDR_SCNPTR
#define GET_SCNHDR_SCNPTR bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_SCNPTR
#define PUT_SCNHDR_SCNPTR bfd_h_put_32
#endif
#ifndef GET_SCNHDR_RELPTR
#define GET_SCNHDR_RELPTR bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_RELPTR
#define PUT_SCNHDR_RELPTR bfd_h_put_32
#endif
#ifndef GET_SCNHDR_LNNOPTR
#define GET_SCNHDR_LNNOPTR bfd_h_get_32
#endif
#ifndef PUT_SCNHDR_LNNOPTR
#define PUT_SCNHDR_LNNOPTR bfd_h_put_32
#endif
static void coff_swap_aouthdr_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_filehdr_out PARAMS ((bfd *, PTR, PTR));
#ifndef NO_COFF_RELOCS
static void coff_swap_reloc_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
#endif /* NO_COFF_RELOCS */
#ifndef NO_COFF_SYMBOLS
static void coff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
static void coff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
static unsigned int coff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
#endif /* NO_COFF_SYMBOLS */
#ifndef NO_COFF_LINENOS
static void coff_swap_lineno_in PARAMS ((bfd *, PTR, PTR));
static unsigned int coff_swap_lineno_out PARAMS ((bfd *, PTR, PTR));
#endif /* NO_COFF_LINENOS */
#ifndef NO_COFF_RELOCS
static void
coff_swap_reloc_in (abfd, src, dst)
bfd *abfd;
PTR src;
PTR dst;
{
RELOC *reloc_src = (RELOC *) src;
struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
reloc_dst->r_symndx = bfd_h_get_signed_32(abfd, (bfd_byte *) reloc_src->r_symndx);
#ifdef RS6000COFF_C
reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
#else
reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
#endif
#ifdef SWAP_IN_RELOC_OFFSET
reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd,
(bfd_byte *) reloc_src->r_offset);
#endif
}
static unsigned int
coff_swap_reloc_out (abfd, src, dst)
bfd *abfd;
PTR src;
PTR dst;
{
struct internal_reloc *reloc_src = (struct internal_reloc *)src;
struct external_reloc *reloc_dst = (struct external_reloc *)dst;
bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
#ifdef RS6000COFF_C
bfd_h_put_8 (abfd, reloc_src->r_type, (bfd_byte *) reloc_dst->r_type);
bfd_h_put_8 (abfd, reloc_src->r_size, (bfd_byte *) reloc_dst->r_size);
#else
bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
reloc_dst->r_type);
#endif
#ifdef SWAP_OUT_RELOC_OFFSET
SWAP_OUT_RELOC_OFFSET(abfd,
reloc_src->r_offset,
(bfd_byte *) reloc_dst->r_offset);
#endif
#ifdef SWAP_OUT_RELOC_EXTRA
SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
#endif
return RELSZ;
}
#endif /* NO_COFF_RELOCS */
static void
coff_swap_filehdr_in (abfd, src, dst)
bfd *abfd;
PTR src;
PTR dst;
{
FILHDR *filehdr_src = (FILHDR *) src;
struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
filehdr_dst->f_symptr =
GET_FILEHDR_SYMPTR (abfd, (bfd_byte *) filehdr_src->f_symptr);
filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
}
static unsigned int
coff_swap_filehdr_out (abfd, in, out)
bfd *abfd;
PTR in;
PTR out;
{
struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
FILHDR *filehdr_out = (FILHDR *)out;
bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
PUT_FILEHDR_SYMPTR (abfd, (bfd_vma) filehdr_in->f_symptr,
(bfd_byte *) filehdr_out->f_symptr);
bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
return FILHSZ;
}
#ifndef NO_COFF_SYMBOLS
static void
coff_swap_sym_in (abfd, ext1, in1)
bfd *abfd;
PTR ext1;
PTR in1;
{
SYMENT *ext = (SYMENT *)ext1;
struct internal_syment *in = (struct internal_syment *)in1;
if( ext->e.e_name[0] == 0) {
in->_n._n_n._n_zeroes = 0;
in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
}
else {
#if SYMNMLEN != E_SYMNMLEN
-> Error, we need to cope with truncating or extending SYMNMLEN!;
#else
memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
#endif
}
in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
if (sizeof(ext->e_type) == 2){
in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
}
else {
in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
}
in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
}
static unsigned int
coff_swap_sym_out (abfd, inp, extp)
bfd *abfd;
PTR inp;
PTR extp;
{
struct internal_syment *in = (struct internal_syment *)inp;
SYMENT *ext =(SYMENT *)extp;
if(in->_n._n_name[0] == 0) {
bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
}
else {
#if SYMNMLEN != E_SYMNMLEN
-> Error, we need to cope with truncating or extending SYMNMLEN!;
#else
memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
#endif
}
bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
if (sizeof(ext->e_type) == 2)
{
bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
}
else
{
bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
}
bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
return SYMESZ;
}
static void
coff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
bfd *abfd;
PTR ext1;
int type;
int class;
int indx;
int numaux;
PTR in1;
{
AUXENT *ext = (AUXENT *)ext1;
union internal_auxent *in = (union internal_auxent *)in1;
switch (class) {
case C_FILE:
if (ext->x_file.x_fname[0] == 0) {
in->x_file.x_n.x_zeroes = 0;
in->x_file.x_n.x_offset =
bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
} else {
#if FILNMLEN != E_FILNMLEN
-> Error, we need to cope with truncating or extending FILNMLEN!;
#else
memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
#endif
}
return;
/* RS/6000 "csect" auxents */
#ifdef RS6000COFF_C
case C_EXT:
case C_HIDEXT:
if (indx + 1 == numaux)
{
in->x_csect.x_scnlen.l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
ext->x_csect.x_parmhash);
in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
/* We don't have to hack bitfields in x_smtyp because it's
defined by shifts-and-ands, which are equivalent on all
byte orders. */
in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
return;
}
break;
#endif
case C_STAT:
#ifdef C_LEAFSTAT
case C_LEAFSTAT:
#endif
case C_HIDDEN:
if (type == T_NULL) {
in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
/* PE defines some extra fields; we zero them out for
safety. */
in->x_scn.x_checksum = 0;
in->x_scn.x_associated = 0;
in->x_scn.x_comdat = 0;
return;
}
break;
}
in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
#ifndef NO_TVNDX
in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
#endif
if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
{
in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR (abfd, ext);
in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX (abfd, ext);
}
else
{
#if DIMNUM != E_DIMNUM
#error we need to cope with truncating or extending DIMNUM
#endif
in->x_sym.x_fcnary.x_ary.x_dimen[0] =
bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
in->x_sym.x_fcnary.x_ary.x_dimen[1] =
bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
in->x_sym.x_fcnary.x_ary.x_dimen[2] =
bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
in->x_sym.x_fcnary.x_ary.x_dimen[3] =
bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
}
if (ISFCN(type)) {
in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
}
else {
in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
}
}
static unsigned int
coff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
bfd *abfd;
PTR inp;
int type;
int class;
int indx;
int numaux;
PTR extp;
{
union internal_auxent *in = (union internal_auxent *)inp;
AUXENT *ext = (AUXENT *)extp;
memset((PTR)ext, 0, AUXESZ);
switch (class) {
case C_FILE:
if (in->x_file.x_fname[0] == 0) {
PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
PUTWORD(abfd,
in->x_file.x_n.x_offset,
(bfd_byte *) ext->x_file.x_n.x_offset);
}
else {
#if FILNMLEN != E_FILNMLEN
-> Error, we need to cope with truncating or extending FILNMLEN!;
#else
memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
#endif
}
return AUXESZ;
#ifdef RS6000COFF_C
/* RS/6000 "csect" auxents */
case C_EXT:
case C_HIDEXT:
if (indx + 1 == numaux)
{
PUTWORD (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
/* We don't have to hack bitfields in x_smtyp because it's
defined by shifts-and-ands, which are equivalent on all
byte orders. */
PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
return AUXESZ;
}
break;
#endif
case C_STAT:
#ifdef C_LEAFSTAT
case C_LEAFSTAT:
#endif
case C_HIDDEN:
if (type == T_NULL) {
PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
return AUXESZ;
}
break;
}
PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
#ifndef NO_TVNDX
bfd_h_put_16(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
#endif
if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
{
PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
}
else
{
#if DIMNUM != E_DIMNUM
#error we need to cope with truncating or extending DIMNUM
#endif
bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
(bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
(bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
(bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
(bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
}
if (ISFCN (type))
PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
(bfd_byte *) ext->x_sym.x_misc.x_fsize);
else
{
PUT_LNSZ_LNNO (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
PUT_LNSZ_SIZE (abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
}
return AUXESZ;
}
#endif /* NO_COFF_SYMBOLS */
#ifndef NO_COFF_LINENOS
static void
coff_swap_lineno_in (abfd, ext1, in1)
bfd *abfd;
PTR ext1;
PTR in1;
{
LINENO *ext = (LINENO *)ext1;
struct internal_lineno *in = (struct internal_lineno *)in1;
in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
in->l_lnno = GET_LINENO_LNNO(abfd, ext);
}
static unsigned int
coff_swap_lineno_out (abfd, inp, outp)
bfd *abfd;
PTR inp;
PTR outp;
{
struct internal_lineno *in = (struct internal_lineno *)inp;
struct external_lineno *ext = (struct external_lineno *)outp;
PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
ext->l_addr.l_symndx);
PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
return LINESZ;
}
#endif /* NO_COFF_LINENOS */
static void
coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1)
bfd *abfd;
PTR aouthdr_ext1;
PTR aouthdr_int1;
{
AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
aouthdr_int->tsize =
GET_AOUTHDR_TSIZE (abfd, (bfd_byte *) aouthdr_ext->tsize);
aouthdr_int->dsize =
GET_AOUTHDR_DSIZE (abfd, (bfd_byte *) aouthdr_ext->dsize);
aouthdr_int->bsize =
GET_AOUTHDR_BSIZE (abfd, (bfd_byte *) aouthdr_ext->bsize);
aouthdr_int->entry =
GET_AOUTHDR_ENTRY (abfd, (bfd_byte *) aouthdr_ext->entry);
aouthdr_int->text_start =
GET_AOUTHDR_TEXT_START (abfd, (bfd_byte *) aouthdr_ext->text_start);
aouthdr_int->data_start =
GET_AOUTHDR_DATA_START (abfd, (bfd_byte *) aouthdr_ext->data_start);
#ifdef I960
aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
#endif
#ifdef APOLLO_M68
bfd_h_put_32(abfd, aouthdr_int->o_inlib, (bfd_byte *) aouthdr_ext->o_inlib);
bfd_h_put_32(abfd, aouthdr_int->o_sri, (bfd_byte *) aouthdr_ext->o_sri);
bfd_h_put_32(abfd, aouthdr_int->vid[0], (bfd_byte *) aouthdr_ext->vid);
bfd_h_put_32(abfd, aouthdr_int->vid[1], (bfd_byte *) aouthdr_ext->vid + 4);
#endif
#ifdef RS6000COFF_C
aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
aouthdr_int->o_cputype = bfd_h_get_16(abfd, aouthdr_ext->o_cputype);
aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
aouthdr_int->o_maxdata = bfd_h_get_32(abfd, aouthdr_ext->o_maxdata);
#endif
#ifdef MIPSECOFF
aouthdr_int->bss_start = bfd_h_get_32(abfd, aouthdr_ext->bss_start);
aouthdr_int->gp_value = bfd_h_get_32(abfd, aouthdr_ext->gp_value);
aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
aouthdr_int->cprmask[0] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[0]);
aouthdr_int->cprmask[1] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[1]);
aouthdr_int->cprmask[2] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[2]);
aouthdr_int->cprmask[3] = bfd_h_get_32(abfd, aouthdr_ext->cprmask[3]);
#endif
#ifdef ALPHAECOFF
aouthdr_int->bss_start = bfd_h_get_64(abfd, aouthdr_ext->bss_start);
aouthdr_int->gp_value = bfd_h_get_64(abfd, aouthdr_ext->gp_value);
aouthdr_int->gprmask = bfd_h_get_32(abfd, aouthdr_ext->gprmask);
aouthdr_int->fprmask = bfd_h_get_32(abfd, aouthdr_ext->fprmask);
#endif
}
static unsigned int
coff_swap_aouthdr_out (abfd, in, out)
bfd *abfd;
PTR in;
PTR out;
{
struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
AOUTHDR *aouthdr_out = (AOUTHDR *)out;
bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
PUT_AOUTHDR_TSIZE (abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
PUT_AOUTHDR_DSIZE (abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
PUT_AOUTHDR_BSIZE (abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
PUT_AOUTHDR_ENTRY (abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
(bfd_byte *) aouthdr_out->text_start);
PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
(bfd_byte *) aouthdr_out->data_start);
#ifdef I960
bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
#endif
#ifdef RS6000COFF_C
bfd_h_put_32 (abfd, aouthdr_in->o_toc, aouthdr_out->o_toc);
bfd_h_put_16 (abfd, aouthdr_in->o_snentry, aouthdr_out->o_snentry);
bfd_h_put_16 (abfd, aouthdr_in->o_sntext, aouthdr_out->o_sntext);
bfd_h_put_16 (abfd, aouthdr_in->o_sndata, aouthdr_out->o_sndata);
bfd_h_put_16 (abfd, aouthdr_in->o_sntoc, aouthdr_out->o_sntoc);
bfd_h_put_16 (abfd, aouthdr_in->o_snloader, aouthdr_out->o_snloader);
bfd_h_put_16 (abfd, aouthdr_in->o_snbss, aouthdr_out->o_snbss);
bfd_h_put_16 (abfd, aouthdr_in->o_algntext, aouthdr_out->o_algntext);
bfd_h_put_16 (abfd, aouthdr_in->o_algndata, aouthdr_out->o_algndata);
bfd_h_put_16 (abfd, aouthdr_in->o_modtype, aouthdr_out->o_modtype);
bfd_h_put_16 (abfd, aouthdr_in->o_cputype, aouthdr_out->o_cputype);
bfd_h_put_32 (abfd, aouthdr_in->o_maxstack, aouthdr_out->o_maxstack);
bfd_h_put_32 (abfd, aouthdr_in->o_maxdata, aouthdr_out->o_maxdata);
memset (aouthdr_out->o_resv2, 0, sizeof aouthdr_out->o_resv2);
#endif
#ifdef MIPSECOFF
bfd_h_put_32(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
bfd_h_put_32(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
bfd_h_put_32(abfd, aouthdr_in->cprmask[0], (bfd_byte *) aouthdr_out->cprmask[0]);
bfd_h_put_32(abfd, aouthdr_in->cprmask[1], (bfd_byte *) aouthdr_out->cprmask[1]);
bfd_h_put_32(abfd, aouthdr_in->cprmask[2], (bfd_byte *) aouthdr_out->cprmask[2]);
bfd_h_put_32(abfd, aouthdr_in->cprmask[3], (bfd_byte *) aouthdr_out->cprmask[3]);
#endif
#ifdef ALPHAECOFF
/* FIXME: What does bldrev mean? */
bfd_h_put_16(abfd, (bfd_vma) 2, (bfd_byte *) aouthdr_out->bldrev);
bfd_h_put_16(abfd, (bfd_vma) 0, (bfd_byte *) aouthdr_out->padding);
bfd_h_put_64(abfd, aouthdr_in->bss_start, (bfd_byte *) aouthdr_out->bss_start);
bfd_h_put_64(abfd, aouthdr_in->gp_value, (bfd_byte *) aouthdr_out->gp_value);
bfd_h_put_32(abfd, aouthdr_in->gprmask, (bfd_byte *) aouthdr_out->gprmask);
bfd_h_put_32(abfd, aouthdr_in->fprmask, (bfd_byte *) aouthdr_out->fprmask);
#endif
return AOUTSZ;
}
static void
coff_swap_scnhdr_in (abfd, ext, in)
bfd *abfd;
PTR ext;
PTR in;
{
SCNHDR *scnhdr_ext = (SCNHDR *) ext;
struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
scnhdr_int->s_vaddr =
GET_SCNHDR_VADDR (abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
scnhdr_int->s_paddr =
GET_SCNHDR_PADDR (abfd, (bfd_byte *) scnhdr_ext->s_paddr);
scnhdr_int->s_size =
GET_SCNHDR_SIZE (abfd, (bfd_byte *) scnhdr_ext->s_size);
scnhdr_int->s_scnptr =
GET_SCNHDR_SCNPTR (abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
scnhdr_int->s_relptr =
GET_SCNHDR_RELPTR (abfd, (bfd_byte *) scnhdr_ext->s_relptr);
scnhdr_int->s_lnnoptr =
GET_SCNHDR_LNNOPTR (abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
#if defined(M88)
scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
#else
scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
#endif
#ifdef I960
scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
#endif
}
static unsigned int
coff_swap_scnhdr_out (abfd, in, out)
bfd *abfd;
PTR in;
PTR out;
{
struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
SCNHDR *scnhdr_ext = (SCNHDR *)out;
unsigned int ret = SCNHSZ;
memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
PUT_SCNHDR_VADDR (abfd, scnhdr_int->s_vaddr,
(bfd_byte *) scnhdr_ext->s_vaddr);
PUT_SCNHDR_PADDR (abfd, scnhdr_int->s_paddr,
(bfd_byte *) scnhdr_ext->s_paddr);
PUT_SCNHDR_SIZE (abfd, scnhdr_int->s_size,
(bfd_byte *) scnhdr_ext->s_size);
PUT_SCNHDR_SCNPTR (abfd, scnhdr_int->s_scnptr,
(bfd_byte *) scnhdr_ext->s_scnptr);
PUT_SCNHDR_RELPTR (abfd, scnhdr_int->s_relptr,
(bfd_byte *) scnhdr_ext->s_relptr);
PUT_SCNHDR_LNNOPTR (abfd, scnhdr_int->s_lnnoptr,
(bfd_byte *) scnhdr_ext->s_lnnoptr);
PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
#if defined(M88)
PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
#else
if (scnhdr_int->s_nlnno <= 0xffff)
PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
else
{
char buf[sizeof (scnhdr_int->s_name) + 1];
memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
buf[sizeof (scnhdr_int->s_name)] = '\0';
(*_bfd_error_handler)
("%s: warning: %s: line number overflow: 0x%lx > 0xffff",
bfd_get_filename (abfd),
buf, scnhdr_int->s_nlnno);
PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nlnno);
}
if (scnhdr_int->s_nreloc <= 0xffff)
PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
else
{
char buf[sizeof (scnhdr_int->s_name) + 1];
memcpy (buf, scnhdr_int->s_name, sizeof (scnhdr_int->s_name));
buf[sizeof (scnhdr_int->s_name)] = '\0';
(*_bfd_error_handler) ("%s: %s: reloc overflow: 0x%lx > 0xffff",
bfd_get_filename (abfd),
buf, scnhdr_int->s_nreloc);
bfd_set_error (bfd_error_file_truncated);
PUTHALF (abfd, 0xffff, (bfd_byte *) scnhdr_ext->s_nreloc);
ret = 0;
}
#endif
#if defined(I960)
PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
#endif
return ret;
}

567
contrib/binutils/bfd/config.bfd Executable file
View File

@ -0,0 +1,567 @@
# config.bfd
# Convert a canonical host type into a BFD host type.
# Set shell variable targ to canonical target name, and run
# using ``. config.bfd''.
# Sets the following shell variables:
# targ_defvec Default vector for this target
# targ_selvecs Vectors to build for this target
# targ_archs Architectures for this target
# targ_cflags $(CFLAGS) for this target (FIXME: pretty bogus)
# targ_underscore Whether underscores are used: yes or no
# Part of this file is processed by targmatch.sed to generate the
# targmatch.h file. The #ifdef and #endif lines that appear below are
# copied directly into targmatch.h.
# The binutils c++filt program wants to know whether underscores are
# stripped or not. That is why we set targ_underscore. c++filt uses
# this information to choose a default. This information is
# duplicated in the symbol_leading_char field of the BFD target
# vector, but c++filt does not deal with object files and is not
# linked against libbfd.a. It is not terribly important that c++filt
# get this right; it is just convenient.
targ_defvec=
targ_selvecs=
targ_cflags=
targ_underscore=no
targ_cpu=`echo $targ | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
case "${targ_cpu}" in
arm*) targ_archs=bfd_arm_arch ;;
hppa*) targ_archs=bfd_hppa_arch ;;
i[3456]86) targ_archs=bfd_i386_arch ;;
m68*) targ_archs=bfd_m68k_arch ;;
m88*) targ_archs=bfd_m88k_arch ;;
mips*) targ_archs=bfd_mips_arch ;;
powerpc*) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
rs6000) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;;
sparc*) targ_archs=bfd_sparc_arch ;;
z8k*) targ_archs=bfd_z8k_arch ;;
*) targ_archs=bfd_${targ_cpu}_arch ;;
esac
# WHEN ADDING ENTRIES TO THIS MATRIX:
# Make sure that the left side always has two dashes. Otherwise you
# can get spurious matches. Even for unambiguous cases, do this as a
# convention, else the table becomes a real mess to understand and maintain.
case "${targ}" in
# START OF targmatch.h
#ifdef BFD64
alpha-*-netware*)
targ_defvec=ecoffalpha_little_vec
targ_selvecs=nlm32_alpha_vec
;;
alpha-*-linuxecoff*)
targ_defvec=ecoffalpha_little_vec
targ_selvecs=bfd_elf64_alpha_vec
;;
alpha-*-linux* | alpha-*-elf*)
targ_defvec=bfd_elf64_alpha_vec
targ_selvecs=ecoffalpha_little_vec
;;
alpha-*-*vms*)
targ_defvec=evax_alpha_vec
;;
alpha-*-*)
targ_defvec=ecoffalpha_little_vec
;;
#endif /* BFD64 */
arm-*-riscix*)
targ_defvec=riscix_vec
;;
arm-*-pe*)
targ_defvec=armpe_little_vec
targ_selvecs="armpe_little_vec armpe_big_vec armpei_little_vec armpei_big_vec"
targ_underscore=yes
;;
arm-*-aout | armel-*-aout)
targ_defvec=aout_arm_little_vec
targ_selvecs=aout_arm_big_vec
;;
armeb-*-aout)
targ_defvec=aout_arm_big_vec
targ_selvecs=aout_arm_little_vec
;;
arm-*-coff)
targ_defvec=armcoff_little_vec
targ_selvecs=armcoff_big_vec
targ_underscore=yes
;;
a29k-*-ebmon* | a29k-*-udi* | a29k-*-coff* | a29k-*-sym1* | \
a29k-*-vxworks* | a29k-*-sysv*)
targ_defvec=a29kcoff_big_vec
targ_selvecs=sunos_big_vec
targ_underscore=yes
;;
a29k-*-aout* | a29k-*-bsd* | a29k-*-vsta*)
targ_defvec=sunos_big_vec
targ_underscore=yes
;;
d10v-*-*)
targ_defvec=bfd_elf32_d10v_vec
;;
h8300*-*-*)
targ_defvec=h8300coff_vec
targ_underscore=yes
;;
h8500-*-*)
targ_defvec=h8500coff_vec
targ_underscore=yes
;;
hppa*-*-*elf* | hppa*-*-lites* | hppa*-*-sysv4* | hppa*-*-rtems*)
targ_defvec=bfd_elf32_hppa_vec
;;
#if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
hppa*-*-bsd*)
targ_defvec=som_vec
targ_selvecs=bfd_elf32_hppa_vec
;;
hppa*-*-hpux* | hppa*-*-hiux*)
targ_defvec=som_vec
;;
hppa*-*-osf*)
targ_defvec=som_vec
targ_selvecs=bfd_elf32_hppa_vec
;;
#endif /* defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF) */
i[3456]86-*-sysv4* | i[3456]86-*-unixware | i[3456]86-*-solaris2* | \
i[3456]86-*-elf | i[3456]86-*-sco*elf* | i[3456]86-*-freebsdelf* | \
i[3456]86-*-dgux*)
targ_defvec=bfd_elf32_i386_vec
targ_selvecs=i386coff_vec
;;
i[3456]86-*-sysv* | i[3456]86-*-isc* | i[3456]86-*-sco* | i[3456]86-*-coff | \
i[3456]86-*-aix* | i[3456]86-*-go32* | i[3456]86*-*-rtems*)
targ_defvec=i386coff_vec
;;
i[3456]86-sequent-bsd*)
targ_defvec=i386dynix_vec
targ_underscore=yes
;;
i[3456]86-*-bsd*)
targ_defvec=i386bsd_vec
targ_underscore=yes
;;
i[3456]86-*-freebsd*)
targ_defvec=i386freebsd_vec
targ_selvecs=i386bsd_vec
targ_underscore=yes
;;
i[3456]86-*-netbsd* | i[3456]86-*-openbsd*)
targ_defvec=i386netbsd_vec
targ_selvecs=i386bsd_vec
targ_underscore=yes
;;
i[3456]86-*-netware*)
targ_defvec=bfd_elf32_i386_vec
targ_selvecs="nlm32_i386_vec i386coff_vec i386aout_vec"
;;
i[3456]86-*-linux*aout*)
targ_defvec=i386linux_vec
targ_selvecs=bfd_elf32_i386_vec
targ_underscore=yes
;;
i[3456]86-*-linux*)
targ_defvec=bfd_elf32_i386_vec
targ_selvecs=i386linux_vec
;;
i[3456]86-*-lynxos*)
targ_defvec=i386lynx_coff_vec
targ_selvecs=i386lynx_aout_vec
;;
i[3456]86-*-gnu*)
targ_defvec=bfd_elf32_i386_vec
targ_selvecs=i386mach3_vec
targ_cflags=-DSTAT_FOR_EXEC
;;
i[3456]86-*-mach* | i[3456]86-*-osf1mk*)
targ_defvec=i386mach3_vec
targ_cflags=-DSTAT_FOR_EXEC
targ_underscore=yes
;;
i[3456]86-*-os9k)
targ_defvec=i386os9k_vec
;;
i[3456]86-*-msdos*)
targ_defvec=i386aout_vec
targ_selvecs=i386msdos_vec
;;
i[3456]86-*-moss*)
targ_defvec=bfd_elf32_i386_vec
targ_selvecs="i386msdos_vec i386aout_vec"
;;
i[3456]86-*-cygwin32 | i[3456]86-*-winnt | i[3456]86-*-pe)
targ_defvec=i386pe_vec
targ_selvecs="i386pe_vec i386pei_vec"
;;
i[3456]86-none-*)
targ_defvec=i386coff_vec
;;
i[3456]86-*-aout* | i[3456]86*-*-vsta*)
targ_defvec=i386aout_vec
;;
i860-*-mach3* | i860-*-osf1* | i860-*-coff*)
targ_defvec=i860coff_vec
;;
i860-*-sysv4* | i860-*-elf*)
targ_defvec=bfd_elf32_i860_vec
;;
i960-*-vxworks4* | i960-*-vxworks5.0)
targ_defvec=b_out_vec_little_host
targ_selvecs="b_out_vec_big_host icoff_little_vec icoff_big_vec ieee_vec"
targ_underscore=yes
;;
i960-*-vxworks5.* | i960-*-coff* | i960-*-sysv* | i960-*-rtems*)
targ_defvec=icoff_little_vec
targ_selvecs="icoff_big_vec b_out_vec_little_host b_out_vec_big_host ieee_vec"
targ_underscore=yes
;;
i960-*-vxworks* | i960-*-aout* | i960-*-bout* | i960-*-nindy*)
targ_defvec=b_out_vec_little_host
targ_selvecs="b_out_vec_big_host icoff_little_vec icoff_big_vec ieee_vec"
targ_underscore=yes
;;
m32r-*-*)
targ_defvec=bfd_elf32_m32r_vec
;;
m68*-apollo-*)
targ_defvec=apollocoff_vec
;;
m68*-bull-sysv*)
targ_defvec=m68kcoffun_vec
targ_underscore=yes
;;
m68*-motorola-sysv*)
targ_defvec=m68ksysvcoff_vec
;;
m68*-hp-bsd*)
targ_defvec=hp300bsd_vec
targ_underscore=yes
;;
m68*-*-aout*)
targ_defvec=aout0_big_vec
# We include cisco_core_vec here, rather than making a separate cisco
# configuration, so that cisco-core.c gets routinely tested at
# least for compilation.
targ_selvecs="cisco_core_vec ieee_vec"
targ_underscore=yes
;;
m68*-*-elf* | m68*-*-sysv4*)
targ_defvec=bfd_elf32_m68k_vec
targ_selvecs="m68kcoff_vec ieee_vec"
;;
m68*-*-coff* | m68*-*-sysv* | m68*-*-rtems*)
targ_defvec=m68kcoff_vec
targ_selvecs="m68kcoff_vec versados_vec ieee_vec"
;;
m68*-*-hpux*)
targ_defvec=hp300hpux_vec
targ_underscore=yes
;;
m68*-*-linux*aout*)
targ_defvec=m68klinux_vec
targ_selvecs=bfd_elf32_m68k_vec
targ_underscore=yes
;;
m68*-*-linux*)
targ_defvec=bfd_elf32_m68k_vec
targ_selvecs=m68klinux_vec
;;
m68*-*-lynxos*)
targ_defvec=m68klynx_coff_vec
targ_selvecs=m68klynx_aout_vec
;;
m68*-hp*-netbsd*)
targ_defvec=m68k4knetbsd_vec
targ_selvecs="m68knetbsd_vec hp300bsd_vec sunos_big_vec"
targ_underscore=yes
;;
m68*-*-netbsd* | m68*-*-openbsd*)
targ_defvec=m68knetbsd_vec
targ_selvecs="m68k4knetbsd_vec hp300bsd_vec sunos_big_vec"
targ_underscore=yes
;;
m68*-*-sunos* | m68*-*-os68k* | m68*-*-vxworks* | m68*-netx-* | \
m68*-*-bsd* | m68*-*-vsta*)
targ_defvec=sunos_big_vec
targ_underscore=yes
;;
m68*-ericsson-*)
targ_defvec=sunos_big_vec
targ_selvecs="m68kcoff_vec versados_vec tekhex_vec"
targ_underscore=yes
;;
m68*-cbm-*)
targ_defvec=bfd_elf32_m68k_vec
targ_selvecs=m68kcoff_vec
;;
m68*-apple-aux*)
targ_defvec=m68kaux_coff_vec
;;
m68*-*-psos*)
targ_defvec=bfd_elf32_m68k_vec
targ_selvecs=ieee_vec
targ_underscore=yes
;;
m88*-harris-cxux* | m88*-*-dgux* | m88*-*-sysv4*)
targ_defvec=bfd_elf32_m88k_vec
targ_selvecs=m88kbcs_vec
;;
m88*-*-mach3*)
targ_defvec=m88kmach3_vec
targ_cflags=-DSTAT_FOR_EXEC
;;
m88*-*-*)
targ_defvec=m88kbcs_vec
targ_underscore=yes
;;
mips*-big-*)
targ_defvec=ecoff_big_vec
targ_selvecs=ecoff_little_vec
;;
mips-dec-netbsd*)
targ_defvec=bfd_elf32_littlemips_vec
targ_selvecs=bfd_elf32_bigmips_vec
;;
mips*-dec-bsd*)
targ_defvec=aout_mips_little_vec
targ_underscore=yes
;;
mips*-dec-mach3*)
targ_defvec=aout_mips_little_vec
targ_cflags=-DSTAT_FOR_EXEC
;;
mips*-dec-* | mips*el-*-ecoff*)
targ_defvec=ecoff_little_vec
targ_selvecs=ecoff_big_vec
;;
mips*-*-ecoff*)
targ_defvec=ecoff_big_vec
targ_selvecs=ecoff_little_vec
;;
mips*-*-irix6*)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
;;
mips*-*-irix5*)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*-sgi-* | mips*-*-bsd*)
targ_defvec=ecoff_big_vec
targ_selvecs=ecoff_little_vec
;;
mips*-*-lnews*)
targ_defvec=ecoff_biglittle_vec
targ_selvecs="ecoff_little_vec ecoff_big_vec"
;;
mips*-*-mach3*)
targ_defvec=aout_mips_little_vec
targ_cflags=-DSTAT_FOR_EXEC
;;
mips*-*-sysv4*)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mips*-*-sysv* | mips*-*-riscos*)
targ_defvec=ecoff_big_vec
targ_selvecs=ecoff_little_vec
;;
mips*el-*-elf*)
targ_defvec=bfd_elf32_littlemips_vec
targ_selvecs="bfd_elf32_bigmips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
;;
mips*-*-elf* | mips*-*-rtems*)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
;;
mips*-*-none)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
;;
mips*el*-*-linux* | mips*el*-*-openbsd*)
targ_defvec=bfd_elf32_littlemips_vec
targ_selvecs="bfd_elf32_bigmips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec ecoff_little_vec ecoff_big_vec"
;;
mips*-*-linux* | mips*-*-openbsd*)
targ_defvec=bfd_elf32_bigmips_vec
targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec ecoff_big_vec ecoff_little_vec"
;;
mn10200-*-*)
targ_defvec=bfd_elf32_mn10200_vec
;;
mn10300-*-*)
targ_defvec=bfd_elf32_mn10300_vec
;;
ns32k-pc532-mach* | ns32k-pc532-ux*)
targ_defvec=pc532machaout_vec
targ_underscore=yes
;;
ns32k-*-netbsd* | ns32k-*-lites* | ns32k-*-openbsd*)
targ_defvec=pc532netbsd_vec
targ_underscore=yes
;;
powerpc-*-aix* | powerpc-*-beos*)
targ_defvec=rs6000coff_vec
;;
powerpc-*-*bsd* | powerpc-*-elf* | powerpc-*-sysv4* | powerpc-*-eabi* | \
powerpc-*-solaris2* | powerpc-*-linux* | powerpc-*-rtems*)
targ_defvec=bfd_elf32_powerpc_vec
targ_selvecs="rs6000coff_vec bfd_elf32_powerpcle_vec bfd_powerpcle_pei_vec bfd_powerpc_pei_vec bfd_powerpcle_pe_vec bfd_powerpc_pe_vec ppcboot_vec"
;;
powerpc-*-macos* | powerpc-*-mpw*)
targ_defvec=pmac_xcoff_vec
;;
powerpc-*-netware*)
targ_defvec=bfd_elf32_powerpc_vec
targ_selvecs="nlm32_powerpc_vec rs6000coff_vec"
;;
powerpcle-*-elf* | powerpcle-*-sysv4* | powerpcle-*-eabi* | \
powerpcle-*-solaris2* | powerpcle-*-linux*)
targ_defvec=bfd_elf32_powerpcle_vec
targ_selvecs="rs6000coff_vec bfd_elf32_powerpc_vec bfd_powerpcle_pei_vec bfd_powerpc_pei_vec bfd_powerpcle_pe_vec bfd_powerpc_pe_vec ppcboot_vec"
;;
powerpcle-*-pe | powerpcle-*-winnt* | powerpcle-*-cygwin32)
targ_defvec=bfd_powerpcle_pe_vec
targ_selvecs="bfd_powerpcle_pei_vec bfd_powerpc_pei_vec bfd_powerpcle_pe_vec bfd_powerpc_pe_vec"
;;
rs6000-*-*)
targ_defvec=rs6000coff_vec
;;
sh-*-elf*)
targ_defvec=bfd_elf32_sh_vec
targ_selvecs="bfd_elf32_shl_vec shcoff_vec shlcoff_vec"
targ_underscore=yes
;;
sh-*-*)
targ_defvec=shcoff_vec
targ_selvecs="shcoff_vec shlcoff_vec"
targ_underscore=yes
;;
sparclet-*-aout*)
targ_defvec=sunos_big_vec
targ_selvecs=sparcle_aout_vec
targ_underscore=yes
;;
sparc-*-linux*aout*)
targ_defvec=sparclinux_vec
targ_selvecs="bfd_elf32_sparc_vec sunos_big_vec"
targ_underscore=yes
;;
sparc-*-linux*)
targ_defvec=bfd_elf32_sparc_vec
targ_selvecs="sparclinux_vec sunos_big_vec"
;;
sparc-*-lynxos*)
targ_defvec=sparclynx_coff_vec
targ_selvecs=sparclynx_aout_vec
;;
sparc-*-netbsd* | sparc-*-openbsd*)
targ_defvec=sparcnetbsd_vec
targ_underscore=yes
;;
sparc-*-elf* | sparc-*-solaris2*)
targ_defvec=bfd_elf32_sparc_vec
targ_selvecs=sunos_big_vec
;;
sparc-*-sysv4*)
targ_defvec=bfd_elf32_sparc_vec
;;
sparc64-*-aout*)
targ_defvec=sunos_big_vec
targ_underscore=yes
;;
#ifdef BFD64
sparc64-*-elf*)
targ_defvec=bfd_elf64_sparc_vec
targ_selvecs=bfd_elf32_sparc_vec
;;
#endif /* BFD64 */
sparc-*-netware*)
targ_defvec=bfd_elf32_sparc_vec
targ_selvecs="nlm32_sparc_vec sunos_big_vec"
;;
sparc*-*-coff*)
targ_defvec=sparccoff_vec
;;
sparc*-*-* | sparc*-*-rtems*)
targ_defvec=sunos_big_vec
targ_underscore=yes
;;
#if HAVE_host_aout_vec
tahoe-*-*)
targ_defvec=host_aout_vec
targ_underscore=yes
;;
#endif
#if HAVE_host_aout_vec
vax-*-bsd* | vax-*-ultrix*)
targ_defvec=host_aout_vec
targ_underscore=yes
;;
#endif
we32k-*-*)
targ_defvec=we32kcoff_vec
;;
w65-*-*)
targ_defvec=w65_vec
;;
z8k*-*-*)
targ_defvec=z8kcoff_vec
targ_underscore=yes
;;
*-*-ieee*)
targ_defvec=ieee_vec
;;
*-adobe-*)
targ_defvec=a_out_adobe_vec
targ_underscore=yes
;;
*-sony-*)
targ_defvec=newsos3_vec
targ_underscore=yes
;;
*-tandem-*)
targ_defvec=m68kcoff_vec
targ_selvecs=ieee_vec
;;
# END OF targmatch.h
*)
echo 1>&2 "*** BFD does not support target ${targ}."
echo 1>&2 "*** Look in bfd/config.bfd for supported targets."
exit 1
;;
esac

View File

@ -0,0 +1,82 @@
/* config.in. Generated automatically from configure.in by autoheader. */
/* Whether strstr must be declared even if <string.h> is included. */
#undef NEED_DECLARATION_STRSTR
/* Whether malloc must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_MALLOC
/* Whether realloc must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_REALLOC
/* Whether free must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_FREE
/* Whether getenv must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_GETENV
/* Define if you have a working `mmap' system call. */
#undef HAVE_MMAP
/* Define if you need to in order for stat and other things to work. */
#undef _POSIX_SOURCE
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Do we need to use the b modifier when opening binary files? */
#undef USE_BINARY_FOPEN
/* Name of host specific header file to include in trad-core.c. */
#undef TRAD_HEADER
/* Define only if <sys/procfs.h> is available *and* it defines prstatus_t. */
#undef HAVE_SYS_PROCFS_H
/* Do we really want to use mmap if it's available? */
#undef USE_MMAP
/* Define if you have the fcntl function. */
#undef HAVE_FCNTL
/* Define if you have the getpagesize function. */
#undef HAVE_GETPAGESIZE
/* Define if you have the madvise function. */
#undef HAVE_MADVISE
/* Define if you have the mprotect function. */
#undef HAVE_MPROTECT
/* Define if you have the setitimer function. */
#undef HAVE_SETITIMER
/* Define if you have the sysconf function. */
#undef HAVE_SYSCONF
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H
/* Define if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define if you have the <sys/file.h> header file. */
#undef HAVE_SYS_FILE_H
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define if you have the <time.h> header file. */
#undef HAVE_TIME_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

2919
contrib/binutils/bfd/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,171 @@
# This file is a shell script that overrides some of the tools and
# flags used on a host specific basis.
# Since the "bfd/hosts" directory is shared by the bfd, opcodes, and
# binutils directories (at least), the index to it is also shared.
# This is that index. Each configure.in file should source this file
# in its per-host part.
# This sets the following shell variables:
# HDEFINES host specific compiler options
# host64 set to true if 64 bit types are as fast as 32 bit
# HOST_64BIT_TYPE host 64 bit type
# HOST_U_64BIT_TYPE unsigned 64 bit type (not needed if 64BIT_TYPE is long)
# SHLIB_CC compiler to use when building shared library
# SHLIB_CFLAGS flags to use when building shared library
# SHLIB_LIBS libraries to use when building shared library
# PICFLAG may be set to flag to use to compile PIC
# SHLINK may be set to the name to link the shared library to
# ALLLIBS may be set to libraries to build
# HLDFLAGS LDFLAGS specific to the host
# HLDENV environment variable to set when linking for the host
# RPATH_ENVVAR environment variable used to find shared libraries
# INSTALL_SHLIB install a shared library
HDEFINES=
host64=false
HOST_64BIT_TYPE=
case "${host}" in
alpha-*-*) host64=true; HOST_64BIT_TYPE=long ;;
hppa*-*-hpux*) HDEFINES=-DHOST_HPPAHPUX ;;
hppa*-*-hiux*) HDEFINES=-DHOST_HPPAHPUX ;;
hppa*-*-bsd*) HDEFINES=-DHOST_HPPABSD ;;
hppa*-*-osf*) HDEFINES=-DHOST_HPPAOSF ;;
i[3456]86-sequent-bsd*) HDEFINES=-Dshared=genshared ;;
i[3456]86-sequent-sysv4*) ;;
i[3456]86-sequent-sysv*) HDEFINES=-Dshared=genshared ;;
mips*-dec-netbsd*) ;;
mips*-*-openbsd*) ;;
mips*-dec-*) HDEFINES="-G 4" ;;
mips*-sgi-irix3*) HDEFINES="-G 4" ;;
mips*-sgi-irix4*) HDEFINES="-G 4" ;;
mips*-sgi-irix6*) host64=true
HOST_64BIT_TYPE="long long";
HOST_U_64BIT_TYPE="unsigned long long";
;;
mips*-*-sysv4*) ;;
mips*-*-sysv*) HDEFINES="-G 4" ;;
mips*-*-riscos*) HDEFINES="-G 4" ;;
m68*-hp-hpux*) HDEFINES=-DHOST_HP300HPUX ;;
*-*-solaris*) HOST_64BIT_TYPE="long long"
HOST_U_64BIT_TYPE="unsigned long long"
;;
*-*-windows*)
HOST_64BIT_TYPE=__int64
HOST_U_64BIT_TYPE="unsigned __int64"
# The following krock is necessary because we can't run the build compiler
# (MSVC) on the configure host, so we have to explicitly set the values here.
# Note that this file is never run through autoconf, so we can't use any
# autoconf macros here. Because of this, we have to muck with autoconf
# variables explicitly.
ac_cv_func_mmap_fixed_mapped=no
ac_cv_header_time=no
ac_cv_func_getpagesize=no
ac_cv_func_madvise=no
ac_cv_func_mprotect=no
ac_cv_header_sys_file_h=no
ac_cv_header_sys_time_h=no
ac_cv_header_unistd_h=no
;;
esac
# If we are configuring with --enable-shared, adjust the shared
# library support based on the host. This support must work for both
# the BFD and the opcodes libraries.
HLDFLAGS=
HLDENV=
RPATH_ENVVAR=LD_LIBRARY_PATH
SHLIB_CC='$(CC)'
SHLIB_CFLAGS='-shared'
SHLIB_LIBS=
INSTALL_SHLIB='$(INSTALL_PROGRAM) $$f $(libdir)/$$tf;'
if [ "${shared}" = "true" ]; then
case "${host}" in
hppa*-*-*) picfrag=${srcdir}/../config/mh-papic ;;
i[34566]86-*-*) picfrag=${srcdir}/../config/mh-x86pic ;;
*-*-*) picfrag=${srcdir}/../config/mh-${host_cpu}pic ;;
esac
if [ -f "${picfrag}" ]; then
pic=`sed -n -e 's/^PICFLAG[ ]*=[ ]*\(.*\)$/\1/p' ${picfrag}`
if [ -n "${pic}" ]; then
PICFLAG=${pic}
fi
fi
case "${host}" in
*-dec-osf*)
# -fpic is not needed on the Alpha.
PICFLAG=
HLDFLAGS='-rpath $(libdir)'
SHLIB_CFLAGS='-shared -Wl,-soname,$(SONAME)'
;;
*-*-hpux*)
# HP/UX uses .sl for shared libraries.
SHLINK=`echo ${SHLINK} | sed -e 's/so$/sl/'`
SHLIB_CFLAGS='-shared $(PICFLAG)'
HLDFLAGS='-Wl,+s,+b,$(libdir)'
RPATH_ENVVAR=SHLIB_PATH
INSTALL_SHLIB='$(INSTALL_PROGRAM) $$f $(libdir)/$$tf; chmod -w $(libdir)/$$tf;'
;;
*-*-irix[56]*)
# -fpic is not needed on Irix 5 or 6.
PICFLAG=
SHLIB_CFLAGS='-shared -Wl,-soname,$(SONAME)'
HLDFLAGS='-Wl,-rpath,$(libdir)'
;;
*-*-linux*aout*)
;;
*-*-linux*)
SHLIB_CFLAGS='-shared -Wl,-soname,$(SONAME)'
case "${libdir}" in
/lib | /usr/lib) ;;
*) HLDFLAGS='-Wl,-rpath,$(libdir)' ;;
esac
# On Linux, apparently, linking against -lc lets ldconfig figure
# out which version of libc should be used.
SHLIB_LIBS=-lc
;;
*-*-solaris*)
SHLIB_CFLAGS='-shared -h $(SONAME)'
HLDFLAGS='-R $(libdir)'
;;
*-*-sysv4*)
SHLIB_CFLAGS='-shared -h $(SONAME)'
HLDENV='if test -z "$${LD_RUN_PATH}"; then LD_RUN_PATH=$(libdir); else LD_RUN_PATH=$${LD_RUN_PATH}:$(libdir); fi; export LD_RUN_PATH;'
;;
*-*-sunos*)
# Build a libTARGET-bfd.so.VERSION symlink in the object directory.
ALLLIBS=`echo ${ALLLIBS} | sed -e 's/\$(SHLINK)/stamp-tshlink/'`
;;
esac
fi
# On SunOS, if the linker supports the -rpath option, use it to
# prevent ../bfd and ../opcodes from being included in the run time
# search path.
case "${host}" in
*-*-sunos*)
echo 'main () { }' > conftest.c
${CC} -o conftest -Wl,-rpath= conftest.c >/dev/null 2>conftest.t
if grep 'unrecognized' conftest.t >/dev/null 2>&1; then
:
elif grep 'No such file' conftest.t >/dev/null 2>&1; then
:
elif grep 'do not mix' conftest.t >/dev/null 2>&1; then
:
elif [ "${shared}" = "true" ]; then
HLDFLAGS='-Wl,-rpath=$(libdir)'
else
HLDFLAGS='-Wl,-rpath='
fi
rm -f conftest.t conftest.c conftest
;;
esac

View File

@ -0,0 +1,631 @@
dnl Process this file with autoconf to produce a configure script.
dnl
AC_PREREQ(2.5)
AC_INIT(libbfd.c)
AC_ARG_ENABLE(64-bit-bfd,
[ --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes)],
[case "${enableval}" in
yes) want64=true ;;
no) want64=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for 64-bit-bfd option) ;;
esac],[want64=false])dnl
AC_ARG_ENABLE(targets,
[ --enable-targets alternative target configurations],
[case "${enableval}" in
yes | "") AC_ERROR(enable-targets option must specify target names or 'all')
;;
no) enable_targets= ;;
*) enable_targets=$enableval ;;
esac])dnl
AC_ARG_ENABLE(shared,
[ --enable-shared build shared BFD library],
[case "${enableval}" in
yes) shared=true ;;
no) shared=false ;;
*bfd*) shared=true ;;
*) shared=false ;;
esac])dnl
AC_ARG_ENABLE(commonbfdlib,
[ --enable-commonbfdlib build shared BFD/opcodes/libiberty library],
[case "${enableval}" in
yes) commonbfdlib=true ;;
no) commonbfdlib=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for BFD commonbfdlib option]) ;;
esac])dnl
AC_ARG_WITH(mmap,
[ --with-mmap try using mmap for BFD input files if available],
[case "${withval}" in
yes) want_mmap=true ;;
no) want_mmap=false ;;
*) AC_MSG_ERROR(bad value ${withval} for BFD with-mmap option) ;;
esac],[want_mmap=false])dnl
AC_CONFIG_HEADER(config.h:config.in)
AC_CONFIG_AUX_DIR(`cd $srcdir/..;pwd`)
AC_CANONICAL_SYSTEM
if test -z "$target" ; then
AC_MSG_ERROR(Unrecognized target system type; please check config.sub.)
fi
AC_ARG_PROGRAM
host64=false
target64=false
# host stuff:
ALLLIBS='$(TARGETLIB)'
PICFLAG=
SHLIB=unused-shlib
SHLINK=unused-shlink
if test "${shared}" = "true"; then
PICFLAG=-fpic
if test "${commonbfdlib}" = "true"; then
ALLLIBS='$(TARGETLIB)'
else
ALLLIBS='$(TARGETLIB) $(SHLIB) $(SHLINK)'
changequote(,)dnl
SHLIB=libbfd.so.`sed -e 's/[^0-9]*\([0-9.]*\).*/\1/' ${srcdir}/VERSION`
changequote([,])dnl
SHLINK=libbfd.so
fi
fi
AC_PROG_CC
AC_ISC_POSIX
# Permit host specific settings.
. ${srcdir}/configure.host
AC_SUBST(HDEFINES)
AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_PROG_INSTALL
if test "${shared}" = "true"; then
if test "${GCC}" != "yes" && test "${shared_non_gcc}" != "yes"; then
AC_MSG_WARN([BFD --enable-shared only supported when using gcc])
shared=false
ALLLIBS='$(TARGETLIB)'
PICFLAG=
SHLIB=unused-shlib
fi
fi
AC_SUBST(ALLLIBS)
AC_SUBST(PICFLAG)
AC_SUBST(SHLIB)
AC_SUBST(SHLIB_CC)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LIBS)
if test "${commonbfdlib}" = "true"; then
COMMON_SHLIB=yes
PICLIST=piclist
else
COMMON_SHLIB=
PICLIST=
fi
AC_SUBST(COMMON_SHLIB)
AC_SUBST(PICLIST)
AC_SUBST(SHLINK)
AC_SUBST(INSTALL_SHLIB)
VERSION=`cat ${srcdir}/VERSION`
AC_SUBST(VERSION)
BFD_HOST_64BIT_LONG=0
BFD_HOST_64_BIT_DEFINED=0
BFD_HOST_64_BIT=
BFD_HOST_U_64_BIT=
if test "x${HOST_64BIT_TYPE}" = "xlong"; then
BFD_HOST_64BIT_LONG=1
elif test "x${HOST_64BIT_TYPE}" != "x"; then
BFD_HOST_64_BIT_DEFINED=1
BFD_HOST_64_BIT=${HOST_64BIT_TYPE}
BFD_HOST_U_64_BIT=${HOST_U_64BIT_TYPE}
fi
AC_SUBST(BFD_HOST_64BIT_LONG)
AC_SUBST(BFD_HOST_64_BIT_DEFINED)
AC_SUBST(BFD_HOST_64_BIT)
AC_SUBST(BFD_HOST_U_64_BIT)
BFD_CC_FOR_BUILD
AC_CHECK_HEADERS(stddef.h string.h strings.h stdlib.h time.h unistd.h)
AC_CHECK_HEADERS(fcntl.h sys/file.h sys/time.h)
AC_HEADER_TIME
AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf)
BFD_BINARY_FOPEN
BFD_NEED_DECLARATION(strstr)
BFD_NEED_DECLARATION(malloc)
BFD_NEED_DECLARATION(realloc)
BFD_NEED_DECLARATION(free)
BFD_NEED_DECLARATION(getenv)
# If we are configured native, pick a core file support file.
COREFILE=
COREFLAG=
if test "${target}" = "${host}"; then
case "${host}" in
alpha*-*-linux*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/alphalinux.h")
;;
alpha*-*-*) COREFILE=osf-core.o ;;
arm-*-riscix) COREFILE=trad-core.o ;;
hppa*-*-hpux*) COREFILE=hpux-core.o ;;
hppa*-*-hiux*) COREFILE=hpux-core.o ;;
hppa*-*-bsd*) COREFILE="hpux-core.o hppabsd-core.o"
COREFLAG="-DHPUX_CORE -DHPPABSD_CORE" ;;
changequote(,)dnl
i[3456]86-sequent-bsd*)
changequote([,])dnl
COREFILE=trad-core.o;
AC_DEFINE(TRAD_HEADER,"hosts/symmetry.h")
;;
changequote(,)dnl
i[3456]86-sequent-sysv4*) ;;
i[3456]86-sequent-sysv*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/symmetry.h")
;;
changequote(,)dnl
i[3456]86-*-bsd* | i[3456]86-*-freebsd*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/i386bsd.h")
;;
changequote(,)dnl
i[3456]86-*-netbsd* | i[3456]86-*-openbsd*)
changequote([,])dnl
COREFILE=netbsd-core.o
;;
changequote(,)dnl
i[3456]86-esix-sysv3*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/esix.h")
;;
changequote(,)dnl
i[3456]86-*-sco* | i[3456]86-*-isc*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/i386sco.h")
;;
changequote(,)dnl
i[3456]86-*-mach3*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/i386mach3.h")
;;
changequote(,)dnl
i[3456]86-*-linux*)
changequote([,])dnl
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/i386linux.h")
;;
changequote(,)dnl
i[3456]86-*-isc*) COREFILE=trad-core.o ;;
i[3456]86-*-aix*) COREFILE=aix386-core.o ;;
changequote([,])dnl
i860-*-mach3* | i860-*-osf1*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/i860mach3.h")
;;
mips-dec-bsd*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/mipsbsd.h")
;;
mips-dec-mach3*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/mipsmach3.h")
;;
mips-*-netbsd* | mips*-*-openbsd*)
COREFILE=netbsd-core.o
;;
mips-dec-*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/decstation.h")
;;
mips-sgi-irix4*) COREFILE=irix-core.o ;;
mips-sgi-irix5*) COREFILE=irix-core.o ;;
mips-sgi-irix6*) COREFILE=irix-core.o ;;
mips-*-mach3*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/mipsmach3.h")
;;
mips-*-sysv4*) ;;
mips-*-sysv* | mips-*-riscos*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/riscos.h")
;;
mips-sony-bsd*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/news-mips.h")
;;
m68*-bull*-sysv*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/dpx2.h")
;;
m68*-hp-hpux*) COREFILE=hpux-core.o ;;
m68*-hp-bsd*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/hp300bsd.h")
;;
m68*-*-linux*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/m68klinux.h")
;;
m68*-motorola-sysv*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER, "hosts/delta68.h")
;;
m68*-sony-*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/news.h")
;;
m68*-*-netbsd* | m68*-*-openbsd*)
COREFILE=netbsd-core.o
;;
m68*-apple-aux*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/m68kaux.h")
;;
m88*-*-sysv4*) ;;
m88*-motorola-sysv*) COREFILE=ptrace-core.o ;;
m88*-*-mach3*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/m88kmach3.h")
;;
ns32k-pc532-mach)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/pc532mach.h")
;;
ns32k-*-netbsd* | ns32k-*-openbsd*)
COREFILE=netbsd-core.o
;;
rs6000-*-lynx*) COREFILE=lynx-core.o ;;
rs6000-*-aix4*) COREFILE=rs6000-core.o ;;
rs6000-*-*) COREFILE=rs6000-core.o ;;
powerpc-*-*bsd*) COREFILE=netbsd-core.o ;;
powerpc-*-aix4*) COREFILE=rs6000-core.o ;;
powerpc-*-aix*) COREFILE=rs6000-core.o ;;
powerpc-*-beos*) ;;
sparc-*-netbsd* | sparc-*-openbsd*)
COREFILE=netbsd-core.o
;;
tahoe-*-*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/tahoe.h")
;;
vax-*-ultrix2*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/vaxult2.h")
;;
vax-*-ultrix*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/vaxult2.h")
;;
vax-*-*)
COREFILE=trad-core.o
AC_DEFINE(TRAD_HEADER,"hosts/vaxbsd.h")
;;
esac
case "$COREFILE" in
aix386-core.o) COREFLAG=-DAIX386_CORE ;;
hppabsd-core.o) COREFLAG=-DHPPABSD_CORE ;;
hpux-core.o) COREFLAG=-DHPUX_CORE ;;
irix-core.o) COREFLAG=-DIRIX_CORE ;;
lynx-core.o) COREFLAG=-DLYNX_CORE ;;
osf-core.o) COREFLAG=-DOSF_CORE ;;
ptrace-core.o) COREFLAG=-DPTRACE_CORE ;;
rs6000-core.o) COREFLAG="$COREFLAG -DAIX_CORE" ;;
trad-core.o) COREFLAG="$COREFLAG -DTRAD_CORE" ;;
esac
# The ELF code uses the native <sys/procfs.h> to handle core files.
# Define HAVE_SYS_PROCFS_H if the file exists and defines
# prstatus_t.
AC_MSG_CHECKING([for sys/procfs.h])
AC_CACHE_VAL(bfd_cv_header_sys_procfs_h,
[AC_TRY_COMPILE([#include <sys/procfs.h>],
[prstatus_t t;],
bfd_cv_header_sys_procfs_h=yes, bfd_cv_header_sys_procfs_h=no)])
AC_MSG_RESULT($bfd_cv_header_sys_procfs_h)
if test $bfd_cv_header_sys_procfs_h = yes; then
AC_DEFINE(HAVE_SYS_PROCFS_H)
fi
fi
AC_SUBST(COREFILE)
AC_SUBST(COREFLAG)
# target stuff:
# Canonicalize the secondary target names.
if test -n "$enable_targets" ; then
for targ in `echo $enable_targets | sed 's/,/ /g'`
do
result=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $targ 2>/dev/null`
if test -n "$result" ; then
canon_targets="$canon_targets $result"
else
# Allow targets that config.sub doesn't recognize, like "all".
canon_targets="$canon_targets $targ"
fi
done
fi
all_targets=false
defvec=
selvecs=
selarchs=
TDEFINES=
for targ in $target $canon_targets
do
if test "x$targ" = "xall"; then
all_targets=true
else
. $srcdir/config.bfd
if test "x$targ" = "x$target"; then
defvec=$targ_defvec
fi
selvecs="$selvecs $targ_defvec $targ_selvecs"
selarchs="$selarchs $targ_archs"
TDEFINES="$TDEFINES $targ_cflags"
fi
done
AC_SUBST(TDEFINES)
# This processing still needs to be done if we're to decide properly whether
# 64-bit support needs to be compiled in. Currently, it will be included if
# the default or any other explicitly requested target requires it; it
# will not be included on a 32-bit host if no 64-bit target is requested, and
# no "--with-64-bit-bfd" option is given, even if "--with-targets=all" is
# used.
# uniq the default and selected vectors in all the configured targets.
f=""
for i in $selvecs ; do
case " $f " in
*" $i "*) ;;
*) f="$f $i" ;;
esac
done
selvecs="$f"
# uniq the architectures in all the configured targets.
f=""
for i in $selarchs ; do
case " $f " in
*" $i "*) ;;
*) f="$f $i" ;;
esac
done
selarchs="$f"
# Target backend .o files.
tb=
elf="elf.o elflink.o"
for vec in $selvecs
do
case "$vec" in
# This list is alphabetized to make it easy to compare
# with the two vector lists in targets.c.
a29kcoff_big_vec) tb="$tb coff-a29k.o cofflink.o" ;;
a_out_adobe_vec) tb="$tb aout-adobe.o aout32.o" ;;
armcoff_little_vec) tb="$tb coff-arm.o cofflink.o " ;;
armcoff_big_vec) tb="$tb coff-arm.o cofflink.o " ;;
armpe_little_vec) tb="$tb pe-arm.o cofflink.o " ;;
armpe_big_vec) tb="$tb pe-arm.o cofflink.o " ;;
armpei_little_vec) tb="$tb pei-arm.o cofflink.o " ;;
armpei_big_vec) tb="$tb pei-arm.o cofflink.o " ;;
aout0_big_vec) tb="$tb aout0.o aout32.o" ;;
aout_arm_big_vec) tb="$tb aout-arm.o aout32.o" ;;
aout_arm_little_vec) tb="$tb aout-arm.o aout32.o" ;;
aout_mips_big_vec) tb="$tb mipsbsd.o aout32.o" ;;
aout_mips_little_vec) tb="$tb mipsbsd.o aout32.o" ;;
apollocoff_vec) tb="$tb coff-apollo.o" ;;
b_out_vec_big_host) tb="$tb bout.o aout32.o" ;;
b_out_vec_little_host) tb="$tb bout.o aout32.o" ;;
bfd_elf64_alpha_vec) tb="$tb elf64-alpha.o elf64.o $elf"
target64=true ;;
bfd_elf32_big_generic_vec) tb="$tb elf32-gen.o elf32.o $elf" ;;
bfd_elf32_bigmips_vec) tb="$tb elf32-mips.o elf32.o $elf ecofflink.o" ;;
bfd_elf64_bigmips_vec) tb="$tb elf64-mips.o elf64.o elf32-mips.o elf32.o $elf ecofflink.o"
target64=true ;;
bfd_elf32_d10v_vec) tb="$tb elf32-d10v.o elf32.o $elf" ;;
bfd_elf32_hppa_vec) tb="$tb elf32-hppa.o elf32.o $elf" ;;
bfd_elf32_i386_vec) tb="$tb elf32-i386.o elf32.o $elf" ;;
bfd_elf32_i860_vec) tb="$tb elf32-i860.o elf32.o $elf" ;;
bfd_elf32_little_generic_vec) tb="$tb elf32-gen.o elf32.o $elf" ;;
bfd_elf32_littlemips_vec) tb="$tb elf32-mips.o elf32.o $elf ecofflink.o" ;;
bfd_elf64_littlemips_vec) tb="$tb elf64-mips.o elf64.o elf32-mips.o elf32.o $elf ecofflink.o"
target64=true ;;
bfd_elf32_m32r_vec) tb="$tb elf32-m32r.o elf32.o $elf" ;;
bfd_elf32_m68k_vec) tb="$tb elf32-m68k.o elf32.o $elf" ;;
bfd_elf32_m88k_vec) tb="$tb elf32-m88k.o elf32.o $elf" ;;
bfd_elf32_mn10200_vec) tb="$tb elf-m10200.o elf32.o $elf" ;;
bfd_elf32_mn10300_vec) tb="$tb elf-m10300.o elf32.o $elf" ;;
bfd_elf32_powerpc_vec) tb="$tb elf32-ppc.o elf32.o $elf" ;;
bfd_elf32_powerpcle_vec) tb="$tb elf32-ppc.o elf32.o $elf" ;;
bfd_elf32_sh_vec) tb="$tb elf32-sh.o elf32.o $elf coff-sh.o" ;;
bfd_elf32_shl_vec) tb="$tb elf32-sh.o elf32.o $elf coff-sh.o" ;;
bfd_elf32_sparc_vec) tb="$tb elf32-sparc.o elf32.o $elf" ;;
bfd_elf64_big_generic_vec) tb="$tb elf64-gen.o elf64.o $elf"
target64=true ;;
bfd_elf64_little_generic_vec) tb="$tb elf64-gen.o elf64.o $elf"
target64=true ;;
bfd_elf64_sparc_vec) tb="$tb elf64-sparc.o elf64.o $elf"
target64=true ;;
cisco_core_vec) tb="$tb cisco-core.o" ;;
demo_64_vec) tb="$tb demo64.o aout64.o"
target64=true ;;
ecoff_big_vec) tb="$tb coff-mips.o ecoff.o ecofflink.o" ;;
ecoff_little_vec) tb="$tb coff-mips.o ecoff.o ecofflink.o" ;;
ecoff_biglittle_vec) tb="$tb coff-mips.o ecoff.o ecofflink.o" ;;
ecoffalpha_little_vec) tb="$tb coff-alpha.o ecoff.o ecofflink.o"
target64=true ;;
evax_alpha_vec) tb="$tb evax-alpha.o evax-emh.o evax-egsd.o evax-etir.o evax-misc.o"
target64=true ;;
h8300coff_vec) tb="$tb coff-h8300.o reloc16.o" ;;
h8500coff_vec) tb="$tb coff-h8500.o reloc16.o" ;;
host_aout_vec) tb="$tb host-aout.o aout32.o" ;;
hp300bsd_vec) tb="$tb hp300bsd.o aout32.o" ;;
hp300hpux_vec) tb="$tb hp300hpux.o aout32.o" ;;
i386aout_vec) tb="$tb i386aout.o aout32.o" ;;
i386bsd_vec) tb="$tb i386bsd.o aout32.o" ;;
i386coff_vec) tb="$tb coff-i386.o cofflink.o" ;;
i386dynix_vec) tb="$tb i386dynix.o aout32.o" ;;
i386freebsd_vec) tb="$tb i386freebsd.o aout32.o" ;;
i386msdos_vec) tb="$tb i386msdos.o" ;;
i386pe_vec) tb="$tb pe-i386.o cofflink.o " ;;
i386pei_vec) tb="$tb pei-i386.o cofflink.o" ;;
i386linux_vec) tb="$tb i386linux.o aout32.o" ;;
i386lynx_aout_vec) tb="$tb i386lynx.o lynx-core.o aout32.o" ;;
i386lynx_coff_vec) tb="$tb cf-i386lynx.o cofflink.o lynx-core.o" ;;
i386mach3_vec) tb="$tb i386mach3.o aout32.o" ;;
i386netbsd_vec) tb="$tb i386netbsd.o aout32.o" ;;
i386os9k_vec) tb="$tb i386os9k.o aout32.o" ;;
i860coff_vec) tb="$tb coff-i860.o cofflink.o" ;;
icoff_big_vec) tb="$tb coff-i960.o cofflink.o" ;;
icoff_little_vec) tb="$tb coff-i960.o cofflink.o" ;;
ieee_vec) tb="$tb ieee.o" ;;
m68kcoff_vec) tb="$tb coff-m68k.o cofflink.o" ;;
m68kcoffun_vec) tb="$tb coff-u68k.o coff-m68k.o cofflink.o" ;;
m68klinux_vec) tb="$tb m68klinux.o aout32.o" ;;
m68klynx_aout_vec) tb="$tb m68klynx.o lynx-core.o aout32.o" ;;
m68klynx_coff_vec) tb="$tb cf-m68klynx.o coff-m68k.o cofflink.o lynx-core.o" ;;
m68knetbsd_vec) tb="$tb m68knetbsd.o aout32.o" ;;
m68k4knetbsd_vec) tb="$tb m68k4knetbsd.o aout32.o" ;;
m68kaux_coff_vec) tb="$tb coff-aux.o coff-m68k.o cofflink.o" ;;
m68ksysvcoff_vec) tb="$tb coff-svm68k.o cofflink.o" ;;
m88kbcs_vec) tb="$tb coff-m88k.o" ;;
newsos3_vec) tb="$tb newsos3.o aout32.o" ;;
nlm32_i386_vec) tb="$tb nlm32-i386.o nlm32.o nlm.o" ;;
nlm32_sparc_vec) tb="$tb nlm32-sparc.o nlm32.o nlm.o" ;;
nlm32_alpha_vec) tb="$tb nlm32-alpha.o nlm32.o nlm.o"
target64=true ;;
riscix_vec) tb="$tb aout32.o riscix.o" ;;
nlm32_powerpc_vec) tb="$tb nlm32-ppc.o nlm32.o nlm.o" ;;
pc532netbsd_vec) tb="$tb ns32knetbsd.o aout-ns32k.o" ;;
pc532machaout_vec) tb="$tb pc532-mach.o aout-ns32k.o" ;;
pmac_xcoff_vec) tb="$tb coff-pmac.o xcofflink.o" ;;
rs6000coff_vec) tb="$tb coff-rs6000.o xcofflink.o" ;;
bfd_powerpc_pe_vec) tb="$tb pe-ppc.o cofflink.o" ;;
bfd_powerpcle_pe_vec) tb="$tb pe-ppc.o cofflink.o" ;;
bfd_powerpc_pei_vec) tb="$tb pei-ppc.o cofflink.o" ;;
bfd_powerpcle_pei_vec) tb="$tb pei-ppc.o cofflink.o" ;;
ppcboot_vec) tb="$tb ppcboot.o" ;;
shcoff_vec) tb="$tb coff-sh.o cofflink.o" ;;
shlcoff_vec) tb="$tb coff-sh.o cofflink.o" ;;
som_vec) tb="$tb som.o" ;;
sparcle_aout_vec) tb="$tb aout-sparcle.o aout32.o" ;;
sparclinux_vec) tb="$tb sparclinux.o aout32.o stab-syms.o" ;;
sparclynx_aout_vec) tb="$tb sparclynx.o lynx-core.o aout32.o" ;;
sparclynx_coff_vec) tb="$tb cf-sparclynx.o lynx-core.o" ;;
sparcnetbsd_vec) tb="$tb sparcnetbsd.o aout32.o" ;;
sparccoff_vec) tb="$tb coff-sparc.o" ;;
srec_vec) tb="$tb srec.o" ;;
sunos_big_vec) tb="$tb sunos.o aout32.o" ;;
symbolsrec_vec) tb="$tb srec.o" ;;
tekhex_vec) tb="$tb tekhex.o" ;;
we32kcoff_vec) tb="$tb coff-we32k.o" ;;
z8kcoff_vec) tb="$tb coff-z8k.o reloc16.o" ;;
w65_vec) tb="$tb coff-w65.o reloc16.o" ;;
versados_vec) tb="$tb versados.o" ;;
"") ;;
*) AC_MSG_ERROR(*** unknown target vector $vec) ;;
esac
done
# Target architecture .o files.
# A couple of CPUs use shorter file names to avoid problems on DOS
# filesystems.
ta=`echo $selarchs | sed -e s/bfd_/cpu-/g -e s/_arch/.o/g -e s/mn10200/m10200/ -e s/mn10300/m10300/`
# Weed out duplicate .o files.
f=""
for i in $tb ; do
case " $f " in
*" $i "*) ;;
*) f="$f $i" ;;
esac
done
tb="$f"
f=""
for i in $ta ; do
case " $f " in
*" $i "*) ;;
*) f="$f $i" ;;
esac
done
ta="$f"
bfd_backends="$tb"
bfd_machines="$ta"
if test x${all_targets} = xtrue ; then
bfd_backends="${bfd_backends}"' $(ALL_BACKENDS)'
bfd_machines="${bfd_machines}"' $(ALL_MACHINES)'
selvecs=
havevecs=
selarchs=
else # all_targets is true
# Only set these if they will be nonempty, for the clever echo.
havevecs=
test -n "$selvecs" &&
havevecs=`echo $selvecs | sed -e 's/^/-DHAVE_/' -e 's/ \(.\)/ -DHAVE_\1/g'`
test -n "$selvecs" &&
selvecs=`echo $selvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
test -n "$selarchs" &&
selarchs=`echo $selarchs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
fi # all_targets is true
case ${host64}-${target64}-${want64} in
*true*)
wordsize=64
all_backends='$(BFD64_BACKENDS) $(BFD32_BACKENDS)'
if test -z "$GCC" && test "$BFD_HOST_64BIT_LONG" = "0" && test "$BFD_HOST_64_BIT_DEFINED" = "0"; then
AC_MSG_WARN([You have requested a 64 bit BFD configuration, but])
AC_MSG_WARN([your compiler may not have a 64 bit integral type])
fi
;;
false-false-false)
wordsize=32
all_backends='$(BFD32_BACKENDS)'
;;
esac
AC_SUBST(wordsize)
AC_SUBST(all_backends)
AC_SUBST(bfd_backends)
AC_SUBST(bfd_machines)
tdefaults=""
test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"
test -n "${selarchs}" && tdefaults="${tdefaults} -DSELECT_ARCHITECTURES='${selarchs}'"
test -n "${havevecs}" && tdefaults="${tdefaults} ${havevecs}"
AC_SUBST(tdefaults)
dnl AC_CHECK_HEADERS(sys/mman.h)
AC_FUNC_MMAP
AC_CHECK_FUNCS(madvise mprotect)
case ${want_mmap}+${ac_cv_func_mmap_fixed_mapped} in
true+yes ) AC_DEFINE(USE_MMAP) ;;
esac
rm -f doc/config.status
AC_OUTPUT(Makefile doc/Makefile bfd-in3.h:bfd-in2.h,
[case x$CONFIG_HEADERS in xconfig.h:config.in) echo > stamp-h ;; esac])

View File

@ -0,0 +1,106 @@
/* Core file generic interface routines for BFD.
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
SECTION
Core files
DESCRIPTION
These are functions pertaining to core files.
*/
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
/*
FUNCTION
bfd_core_file_failing_command
SYNOPSIS
CONST char *bfd_core_file_failing_command(bfd *abfd);
DESCRIPTION
Return a read-only string explaining which program was running
when it failed and produced the core file @var{abfd}.
*/
CONST char *
bfd_core_file_failing_command (abfd)
bfd *abfd;
{
if (abfd->format != bfd_core) {
bfd_set_error (bfd_error_invalid_operation);
return NULL;
}
return BFD_SEND (abfd, _core_file_failing_command, (abfd));
}
/*
FUNCTION
bfd_core_file_failing_signal
SYNOPSIS
int bfd_core_file_failing_signal(bfd *abfd);
DESCRIPTION
Returns the signal number which caused the core dump which
generated the file the BFD @var{abfd} is attached to.
*/
int
bfd_core_file_failing_signal (abfd)
bfd *abfd;
{
if (abfd->format != bfd_core) {
bfd_set_error (bfd_error_invalid_operation);
return 0;
}
return BFD_SEND (abfd, _core_file_failing_signal, (abfd));
}
/*
FUNCTION
core_file_matches_executable_p
SYNOPSIS
boolean core_file_matches_executable_p
(bfd *core_bfd, bfd *exec_bfd);
DESCRIPTION
Return <<true>> if the core file attached to @var{core_bfd}
was generated by a run of the executable file attached to
@var{exec_bfd}, <<false>> otherwise.
*/
boolean
core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd, *exec_bfd;
{
if ((core_bfd->format != bfd_core) || (exec_bfd->format != bfd_object)) {
bfd_set_error (bfd_error_wrong_format);
return false;
}
return BFD_SEND (core_bfd, _core_file_matches_executable_p,
(core_bfd, exec_bfd));
}

View File

@ -0,0 +1,38 @@
/* BFD support for the Alpha architecture.
Copyright 1992 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
const bfd_arch_info_type bfd_alpha_arch =
{
64, /* 32 bits in a word */
64, /* 32 bits in an address */
8, /* 8 bits in a byte */
bfd_arch_alpha,
0, /* only 1 machine */
"alpha",
"alpha",
3,
true, /* the one and only */
bfd_default_compatible,
bfd_default_scan ,
0,
};

View File

@ -0,0 +1,54 @@
/* BFD support for the Intel 386 architecture.
Copyright 1992, 94, 95, 1996 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
static const bfd_arch_info_type i8086_arch =
{
32, /* 32 bits in a word */
32, /* 32 bits in an address (well, not really) */
8, /* 8 bits in a byte */
bfd_arch_i386,
bfd_mach_i386_i8086,
"i8086",
"i8086",
3,
false,
bfd_default_compatible,
bfd_default_scan ,
0,
};
const bfd_arch_info_type bfd_i386_arch =
{
32, /* 32 bits in a word */
32, /* 32 bits in an address */
8, /* 8 bits in a byte */
bfd_arch_i386,
bfd_mach_i386_i386,
"i386",
"i386",
3,
true,
bfd_default_compatible,
bfd_default_scan ,
&i8086_arch,
};

View File

@ -0,0 +1,68 @@
/* BFD library support routines for the Hitachi-SH architecture.
Copyright (C) 1993 Free Software Foundation, Inc.
Hacked by Steve Chamberlain of Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
int bfd_default_scan_num_mach();
static boolean
scan_mach (info, string)
const struct bfd_arch_info *info;
const char *string;
{
if (strcmp(string,"sh") == 0) return true;
if (strcmp(string,"SH") == 0) return true;
return false;
}
#if 0
/* This routine is provided two arch_infos and returns whether
they'd be compatible */
static const bfd_arch_info_type *
compatible (a,b)
const bfd_arch_info_type *a;
const bfd_arch_info_type *b;
{
if (a->arch != b->arch || a->mach != b->mach)
return NULL;
return a;
}
#endif
const bfd_arch_info_type bfd_sh_arch =
{
32, /* 32 bits in a word */
32, /* 32 bits in an address */
8, /* 8 bits in a byte */
bfd_arch_sh,
0, /* only 1 machine */
"sh", /* arch_name */
"sh", /* printable name */
1,
true, /* the default machine */
bfd_default_compatible,
scan_mach,
0,
};

View File

@ -0,0 +1,198 @@
/* BFD library support routines for the Z800n architecture.
Copyright (C) 1992 Free Software Foundation, Inc.
Hacked by Steve Chamberlain of Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#if 0 /* not used currently */
/*
Relocations for the Z8K
*/
static bfd_reloc_status_type
howto16_callback (abfd, reloc_entry, symbol_in, data,
ignore_input_section, ignore_bfd)
bfd *abfd;
arelent *reloc_entry;
struct symbol_cache_entry *symbol_in;
PTR data;
asection *ignore_input_section;
bfd *ignore_bfd;
{
long relocation = 0;
bfd_vma addr = reloc_entry->address;
long x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
HOWTO_PREPARE (relocation, symbol_in);
x = (x + relocation + reloc_entry->addend);
bfd_put_16 (abfd, x, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
static bfd_reloc_status_type
howto8_callback (abfd, reloc_entry, symbol_in, data,
ignore_input_section, ignore_bfd)
bfd *abfd;
arelent *reloc_entry;
struct symbol_cache_entry *symbol_in;
PTR data;
asection *ignore_input_section;
bfd *ignore_bfd;
{
long relocation = 0;
bfd_vma addr = reloc_entry->address;
long x = bfd_get_8 (abfd, (bfd_byte *) data + addr);
HOWTO_PREPARE (relocation, symbol_in);
x = (x + relocation + reloc_entry->addend);
bfd_put_8 (abfd, x, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
static bfd_reloc_status_type
howto8_FFnn_callback (abfd, reloc_entry, symbol_in, data,
ignore_input_section, ignore_bfd)
bfd *abfd;
arelent *reloc_entry;
struct symbol_cache_entry *symbol_in;
PTR data;
asection *ignore_input_section;
bfd *ignore_bfd;
{
long relocation = 0;
bfd_vma addr = reloc_entry->address;
long x = bfd_get_8 (abfd, (bfd_byte *) data + addr);
abort ();
HOWTO_PREPARE (relocation, symbol_in);
x = (x + relocation + reloc_entry->addend);
bfd_put_8 (abfd, x, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
static bfd_reloc_status_type
howto8_pcrel_callback (abfd, reloc_entry, symbol_in, data,
ignore_input_section, ignore_bfd)
bfd *abfd;
arelent *reloc_entry;
struct symbol_cache_entry *symbol_in;
PTR data;
asection *ignore_input_section;
bfd *ignore_bfd;
{
long relocation = 0;
bfd_vma addr = reloc_entry->address;
long x = bfd_get_8 (abfd, (bfd_byte *) data + addr);
abort ();
HOWTO_PREPARE (relocation, symbol_in);
x = (x + relocation + reloc_entry->addend);
bfd_put_8 (abfd, x, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
static reloc_howto_type howto_16
= NEWHOWTO (howto16_callback, "abs16", 1, false, false);
static reloc_howto_type howto_8
= NEWHOWTO (howto8_callback, "abs8", 0, false, false);
static reloc_howto_type howto_8_FFnn
= NEWHOWTO (howto8_FFnn_callback, "ff00+abs8", 0, false, false);
static reloc_howto_type howto_8_pcrel
= NEWHOWTO (howto8_pcrel_callback, "pcrel8", 0, false, true);
static reloc_howto_type *
local_bfd_reloc_type_lookup (arch, code)
const struct bfd_arch_info *arch;
bfd_reloc_code_real_type code;
{
switch (code)
{
case BFD_RELOC_16:
return &howto_16;
case BFD_RELOC_8_FFnn:
return &howto_8_FFnn;
case BFD_RELOC_8:
return &howto_8;
case BFD_RELOC_8_PCREL:
return &howto_8_pcrel;
default:
return (reloc_howto_type *) NULL;
}
}
#endif
int bfd_default_scan_num_mach ();
static boolean
scan_mach (info, string)
const struct bfd_arch_info *info;
const char *string;
{
if (strcmp (string, "z8001") == 0 || strcmp (string, "z8k") == 0)
{
return bfd_mach_z8001 == info->mach;
}
if (strcmp (string, "z8002") == 0)
{
return bfd_mach_z8002 == info->mach;
}
return false;
}
/* This routine is provided two arch_infos and returns whether
they'd be compatible */
static const bfd_arch_info_type *
compatible (a, b)
const bfd_arch_info_type *a;
const bfd_arch_info_type *b;
{
if (a->arch != b->arch || a->mach != b->mach)
return NULL;
return a;
}
static const bfd_arch_info_type arch_info_struct[] =
{
{32, 32, 8, bfd_arch_z8k, bfd_mach_z8001, "z8k", "z8001", 1, false, compatible, scan_mach, 0,},
};
const bfd_arch_info_type bfd_z8k_arch =
{
32, 16, 8, bfd_arch_z8k, bfd_mach_z8002, "z8k", "z8002", 1, true, compatible, scan_mach, &arch_info_struct[0],
};

View File

@ -0,0 +1,24 @@
/* BFD backend for demonstration 64-bit a.out binaries.
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define ARCH_SIZE 64
#define MY(OP) CAT(demo_64_,OP)
#define TARGETNAME "demo64"
#include "aoutf1.h"

View File

@ -0,0 +1,25 @@
:loop
/\\$/N
s/\\\n */ /g
t loop
s! @BFD_H@!!g
s!@INCDIR@!$(INCDIR)!g
s!@SRCDIR@/!!g
s!hosts/[^ ]*\.h ! !g
s/ sysdep.h//g
s! \.\./bfd/sysdep.h!!g
s/ libbfd.h//g
s/ config.h//g
s! \$(INCDIR)/fopen-[^ ]*\.h!!g
s! \$(INCDIR)/ansidecl\.h!!g
s/\\\n */ /g
s/ *$//
s/ */ /g
s/ *:/:/g
/:$/d
s/\(.\{50\}[^ ]*\) /\1 \\\
/g

View File

@ -0,0 +1,290 @@
Tue Apr 8 12:49:46 1997 Ian Lance Taylor <ian@cygnus.com>
* Makefile.in (install-info): Permit info files to be in srcdir.
(stamp-*): Add a stamp-X target for each X.texi target.
(*.texi): Just depend upon stamp-X.
(clean): Remove stamp-*.
(distclean): Depend upon mostlyclean. Remove stamp-*. Don't
remove $(DOCFILES).
Mon Apr 7 15:23:26 1997 Ian Lance Taylor <ian@cygnus.com>
* Makefile.in (distclean): Don't remove *.info files.
Thu Feb 13 20:50:02 1997 Klaus Kaempf (kkaempf@progis.de)
* makefile.vms: New file.
Tue Jun 18 18:32:28 1996 Ian Lance Taylor <ian@cygnus.com>
* chew.c (kill_bogus_lines): Reset sl when not at the start of a
line. From Uwe Ohse <uwe@tirka.gun.de>.
Tue Jan 30 14:10:46 1996 Ian Lance Taylor <ian@cygnus.com>
From Ronald F. Guilmette <rfg@monkeys.com>:
* Makefile.in (libbfd.h): Depend upon proto.str.
(libcoff.h, bfd.h): Likewise.
Fri Nov 3 14:46:48 1995 Fred Fish <fnf@cygnus.com>
* Makefile.in (SRCDOC, SRCPROT, core.texi, bfd.h): Use corefile.c,
renamed from core.c.
Wed Nov 1 14:28:23 1995 Manfred Hollstein KS/EF4A 60/1F/110 #40283 <manfred@lts.sel.alcatel.de>
* chew.c: Include <ctype.h>.
Fri Oct 6 16:23:34 1995 Ken Raeburn <raeburn@cygnus.com>
Mon Sep 25 22:49:32 1995 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* Makefile.in (Makefile): Only remake this Makefile.
Wed Oct 4 15:51:05 1995 Ken Raeburn <raeburn@cygnus.com>
* chew.c: Include <stdio.h>.
Tue Sep 12 18:14:50 1995 Ian Lance Taylor <ian@cygnus.com>
* Makefile.in (maintainer-clean): New target.
Thu Aug 31 12:18:43 1995 Ian Lance Taylor <ian@cygnus.com>
* Makefile.in (bfd.h): Add additional #endif at end of bfd.h if
__cplusplus is defined.
Tue Nov 29 16:13:34 1994 Doug Evans <dje@canuck.cygnus.com>
* chew.c (write_buffer): New argument `f', all callers changed.
(stdout, stderr, print, drop, idrop): New forth words.
* proto.str (COMMENT): New command.
* doc.str (COMMENT): Likewise.
Mon Sep 12 11:44:17 1994 Ian Lance Taylor (ian@sanguine.cygnus.com)
* Makefile.in (DOCFILES): Remove ctor.texi.
(IPROTOS): Remove ctor.ip.
(SRCIPROT): Remove $(srcdir)/../ctor.c.
(ctor.texi): Remove target.
(libbfd.h): Remove dependency on $(srcdir)/../ctor.c. Remove
$(MKDOC) run on $(srcdir)/../ctor.c.
* bfd.texinfo (Constructors): Remove section.
Fri Sep 2 13:33:44 1994 Ken Raeburn (raeburn@cujo.cygnus.com)
* chew.c: Include assert.h. Added prototypes for most functions.
Changed most uses of int to long. Do bounds checking on the
stacks. Added comment at the beginning documenting most of the
intrinsics. Lots of whitespace changes. Re-ordered some
functions.
(die, check_range, icheck_range): New functions.
(strip_trailing_newlines, print_stack_level): New functions.
(translatecomments): Don't insert tab before "/*".
(iscommand): Minimum command length is now 4.
(nextword): Handle some \-sequences.
(push_addr): Deleted.
(main): Add new intrinsics strip_trailing_newlines and
print_stack_level. Complain at end if stack contains more than
one element, or less.
(remchar): Make sure the string is not empty before chopping off a
character.
* doc.str, proto.str: Handle new commands SENUM, ENUM, ENUMX,
ENUMEQ, ENUMEQX, ENUMDOC.
Wed Jan 12 18:37:12 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* bfd.texinfo: Added Linker Functions node.
* doc/Makefile.in (DOCFILES): Added linker.texi.
(SRCDOC): Added linker.c.
(linker.texi): New target.
Tue Jan 4 10:52:56 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* chew.c: Don't rely on a correct declaration of exit.
(chew_exit): New function which just calls exit.
(main): Use it.
Mon Jan 3 11:40:40 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* bfd.texinfo: Added Hash Tables node.
* Makefile.in (DOCFILES): Added hash.texi.
(SRCDOC): Added hash.c.
(hash.texi): New target.
Thu Dec 30 16:57:04 1993 Ken Raeburn (raeburn@cujo.cygnus.com)
* Makefile.in: Delete all references to seclet.c, since it's just
been deleted. Don't mention hash.c, linker.c, or genlink.h yet,
since they don't contain documentation yet (hint, hint!).
Fri Nov 5 10:58:53 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* bfd.texinfo: Small cleanups.
Fri Nov 19 03:46:11 1993 Ken Raeburn (raeburn@cambridge.cygnus.com)
* Makefile.in (archures.texi): Depends on $(MKDOC).
Tue Aug 10 14:22:39 1993 Ken Raeburn (raeburn@cambridge.cygnus.com)
* bfd.texinfo (BFD back end): Don't include elfcode.texi, since
it's empty now and that triggers a makeinfo bug.
Mon Aug 9 16:27:30 1993 Ken Raeburn (raeburn@cambridge.cygnus.com)
* bfd.texinfo (BFD back end): New section on ELF, includes
elf.texi and elfcode.texi.
* Makefile.in (DOCFILES): Include elf.texi, elfcode.texi.
(SRCDOC): Include elfcode.h, elf.c.
(elf.texi, elfcode.texi): New intermediate targets.
Thu Jun 24 13:48:13 1993 David J. Mackenzie (djm@thepub.cygnus.com)
* Makefile.in (.c.o, chew.o): Put CFLAGS last.
* bfdsumm.texi: New file, broken out of bfd.texinfo, to share
with ld.texinfo.
Mon Jun 14 12:07:07 1993 david d `zoo' zuhn (zoo at rtl.cygnus.com)
* Makefile.in (install-info): remove parentdir cruft,
Wed Jun 9 16:00:32 1993 Jim Kingdon (kingdon@cygnus.com)
* Makefile.in (mostlyclean): Remove chew.o.
Tue May 25 14:46:58 1993 Ken Raeburn (raeburn@cambridge.cygnus.com)
* Makefile.in (libbfd.h): Use elfcode.h, not elf32.c.
Mon May 24 15:50:07 1993 Ken Raeburn (raeburn@cygnus.com)
* chew.c (compile): Add a couple of missing casts.
Wed May 12 14:45:14 1993 Ian Lance Taylor (ian@cygnus.com)
* Makefile.in (CC_FOR_BUILD): New variable, define to be $(CC).
(chew.o, $(MKDOC)): Build using CC_FOR_BUILD rather than CC, since
it must run on the build machine.
Tue Apr 6 22:38:10 1993 John Gilmore (gnu@cygnus.com)
* Makefile.in (chew): Don't compile from .c to executable in a
single step; it puts a temporary .o filename into the executable,
which makes multi-stage comparisons fail. Compile chew.c to
chew.o, and link that, which makes identical executables every time.
Wed Mar 24 17:26:29 1993 david d `zoo' zuhn (zoo at poseidon.cygnus.com)
* Makefile.in: fix typo (bfd.texinfo not bfd.texino)
Fri Mar 19 01:13:00 1993 Ken Raeburn (raeburn@kr-pc.cygnus.com)
* bfd.texinfo: Since BFD version number has been bumped, do same
to "version number" on title page, and elsewhere. Should be
fixed to extract real version number.
Tue Mar 16 12:15:13 1993 Per Bothner (bothner@rtl.cygnus.com)
* Makefile.in: Add *clean rules.
Mon Jan 11 18:43:56 1993 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
* Makefile.in (libbfd.h): Removed duplicate init.c and libbfd.c.
Added seclet.c.
(bfd.h): Added dependency on bfd.c and seclet.c. Added seclet.c
to build.
Thu Dec 17 19:35:43 1992 david d `zoo' zuhn (zoo at cirdan.cygnus.com)
* Makefile.in: added dvi target, define and use $(TEXI2DVI)
Thu Dec 3 17:42:48 1992 Ken Raeburn (raeburn@cambridge.cygnus.com)
* Makefile.in (TEXIDIR): New variable.
(bfd.dvi): Look for bfd.texinfo in $(srcdir). Generate index.
* bfd.texinfo: Minor doc fixes.
Thu Nov 5 03:13:55 1992 John Gilmore (gnu@cygnus.com)
Cleanup: Replace all uses of EXFUN in the BFD sources, with PARAMS.
* doc/chew.c (exfunstuff): Eliminate.
(paramstuff): Replace exfunstuff with function to generate PARAMS.
* doc/proto.str: Use paramstuff rather than exfunstuff.
Mon Aug 17 12:40:32 1992 Steve Chamberlain (sac@thepub.cygnus.com)
* chew.c: various patches provided by Howard Chu.
Fri Jun 19 18:59:54 1992 John Gilmore (gnu at cygnus.com)
* Makefile.in (libbfd.h): Add elf.c as a source of prototypes.
Mon May 11 18:55:59 1992 John Gilmore (gnu at cygnus.com)
* chew.c: exit() should be declared by config files, not by
portable source code. Its type could be int or void function.
Mon May 4 13:45:57 1992 K. Richard Pixley (rich@rtl.cygnus.com)
* Makefile.in: another CFLAGS correction.
Tue Apr 28 10:21:32 1992 K. Richard Pixley (rich@rtl.cygnus.com)
* Makefile.in: Do the CFLAGS thing.
Fri Apr 10 22:34:52 1992 Fred Fish (fnf@cygnus.com)
* Makefile.in (MINUS_G): Add macro and default to -g.
Fri Mar 6 18:53:18 1992 Steve Chamberlain (sac@thepub.cygnus.com)
* chew.c: now has -w switch turn on warnings
Wed Feb 26 18:04:40 1992 K. Richard Pixley (rich@cygnus.com)
* Makefile.in, configure.in: removed traces of namesubdir,
-subdirs, $(subdir), $(unsubdir), some rcs triggers. Forced
copyrights to '92, changed some from Cygnus to FSF.
Tue Dec 10 22:11:05 1991 K. Richard Pixley (rich at rtl.cygnus.com)
* Makefile.in: build chew into the current directory. Complete
the MKDOC macro transition.
Tue Dec 10 08:26:28 1991 Steve Chamberlain (sac at rtl.cygnus.com)
* chew.c: don't core dump when can't open file
* Makefile.in: get proto.str from the right place when built in
odd directories
Tue Dec 10 04:07:25 1991 K. Richard Pixley (rich at rtl.cygnus.com)
* Makefile.in: infodir belongs in datadir.
Sat Dec 7 17:01:23 1991 Steve Chamberlain (sac at rtl.cygnus.com)
* chew.c: Much modified
* proto.str, doc.str: New files for extracting to product
prototypes and documents respectively.
Fri Dec 6 22:57:12 1991 K. Richard Pixley (rich at rtl.cygnus.com)
* Makefile.in: added standards.text support, host/site/target
inclusion hooks, install using INSTALL_DATA rather than cp,
don't echo on install.
Thu Dec 5 22:46:17 1991 K. Richard Pixley (rich at rtl.cygnus.com)
* Makefile.in: idestdir and ddestdir go away. Added copyrights
and shift gpl to v2. Added ChangeLog if it didn't exist. docdir
and mandir now keyed off datadir by default.
Local Variables:
version-control: never
End:

View File

@ -0,0 +1,381 @@
#
# Makefile
# Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#
VPATH = @srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
datadir = @datadir@
mandir = @mandir@
man1dir = $(mandir)/man1
man2dir = $(mandir)/man2
man3dir = $(mandir)/man3
man4dir = $(mandir)/man4
man5dir = $(mandir)/man5
man6dir = $(mandir)/man6
man7dir = $(mandir)/man7
man8dir = $(mandir)/man8
man9dir = $(mandir)/man9
infodir = @infodir@
includedir = @includedir@
MKDOC=./chew
SHELL = /bin/sh
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
CFLAGS = -g
CC_FOR_BUILD = $(CC)
#### Host, target, and site specific Makefile fragments come in here.
###
.c.o:
$(CC) -c -I.. -I$(srcdir)/.. -I$(srcdir)/../../include $(H_CFLAGS) $(CFLAGS) $<
DOCFILES = aoutx.texi archive.texi archures.texi \
bfd.texi cache.texi coffcode.texi \
core.texi elf.texi elfcode.texi format.texi libbfd.texi \
opncls.texi reloc.texi section.texi \
syms.texi targets.texi init.texi hash.texi linker.texi
PROTOS = archive.p archures.p bfd.p \
core.p format.p \
libbfd.p opncls.p reloc.p \
section.p syms.p targets.p \
format.p core.p init.p
IPROTOS = cache.ip libbfd.ip reloc.ip init.ip archures.ip coffcode.ip
# SRCDOC, SRCPROT, SRCIPROT only used to sidestep Sun Make bug in interaction
# between VPATH and suffix rules. If you use GNU Make, perhaps other Makes,
# you don't need these three:
SRCDOC = $(srcdir)/../aoutx.h $(srcdir)/../archive.c \
$(srcdir)/../archures.c $(srcdir)/../bfd.c \
$(srcdir)/../cache.c $(srcdir)/../coffcode.h \
$(srcdir)/../corefile.c $(srcdir)/../elf.c \
$(srcdir)/../elfcode.h $(srcdir)/../format.c \
$(srcdir)/../libbfd.c $(srcdir)/../opncls.c \
$(srcdir)/../reloc.c $(srcdir)/../section.c \
$(srcdir)/../syms.c $(srcdir)/../targets.c \
$(srcdir)/../hash.c $(srcdir)/../linker.c
SRCPROT = $(srcdir)/../archive.c $(srcdir)/../archures.c \
$(srcdir)/../bfd.c $(srcdir)/../coffcode.h $(srcdir)/../corefile.c \
$(srcdir)/../format.c $(srcdir)/../libbfd.c \
$(srcdir)/../opncls.c $(srcdir)/../reloc.c \
$(srcdir)/../section.c $(srcdir)/../syms.c \
$(srcdir)/../targets.c $(srcdir)/../init.c
SRCIPROT = $(srcdir)/../cache.c $(srcdir)/../libbfd.c \
$(srcdir)/../reloc.c $(srcdir)/../cpu-h8300.c \
$(srcdir)/../cpu-i960.c $(srcdir)/../archures.c \
$(srcdir)/../init.c
STAGESTUFF = $(DOCFILES) *.info*
TEXIDIR = $(srcdir)/../../texinfo/fsf
all install:
info: bfd.info
dvi: bfd.dvi
install-info: info
if [ -r bfd.info ]; then \
dir=.; \
else \
dir=$(srcdir); \
fi; \
for i in `cd $$dir; echo *.info*`; do \
$(INSTALL_DATA) $$dir/$$i $(infodir)/$$i; \
done
docs: $(MKDOC) protos bfd.info bfd.dvi bfd.ps
$(MKDOC): chew.o
$(CC_FOR_BUILD) -o $(MKDOC) chew.o $(LOADLIBES) $(LDFLAGS)
chew.o: chew.c
$(CC_FOR_BUILD) -c -I.. -I$(srcdir)/.. -I$(srcdir)/../../include $(H_CFLAGS) $(CFLAGS) $(srcdir)/chew.c
protos: libbfd.h libcoff.h bfd.h
# We can't replace these rules with an implicit rule, because
# makes without VPATH support couldn't find the .h files in `..'.
# We use stamp-XXX targets so that we can distribute the info files,
# and permit people to rebuild them, without requiring the makeinfo
# program. If somebody tries to rebuild info, but none of the .texi
# files have changed, then this Makefile will build chew, and will
# build all of the stamp files, but will not actually have to rebuild
# bfd.info.
stamp-aoutx: $(MKDOC) $(srcdir)/../aoutx.h $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../aoutx.h >aoutx.tmp
$(srcdir)/../../move-if-change aoutx.tmp aoutx.texi
touch stamp-aoutx
aoutx.texi: stamp-aoutx
stamp-archive: $(MKDOC) $(srcdir)/../archive.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../archive.c >archive.tmp
$(srcdir)/../../move-if-change archive.tmp archive.texi
touch stamp-archive
archive.texi: stamp-archive
stamp-archures: $(MKDOC) $(srcdir)/../archures.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str < $(srcdir)/../archures.c >archures.tmp
$(srcdir)/../../move-if-change archures.tmp archures.texi
touch stamp-archures
archures.texi: stamp-archures
stamp-bfd: $(MKDOC) $(srcdir)/../bfd.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str < $(srcdir)/../bfd.c >bfd.tmp
$(srcdir)/../../move-if-change bfd.tmp bfd.texi
touch stamp-bfd
bfd.texi: stamp-bfd
stamp-cache: $(MKDOC) $(srcdir)/../cache.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str < $(srcdir)/../cache.c >cache.tmp
$(srcdir)/../../move-if-change cache.tmp cache.texi
touch stamp-cache
cache.texi: stamp-cache
stamp-coffcode: $(MKDOC) $(srcdir)/../coffcode.h $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../coffcode.h >coffcode.tmp
$(srcdir)/../../move-if-change coffcode.tmp coffcode.texi
touch stamp-coffcode
coffcode.texi: stamp-coffcode
stamp-core: $(MKDOC) $(srcdir)/../corefile.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../corefile.c >core.tmp
$(srcdir)/../../move-if-change core.tmp core.texi
touch stamp-core
core.texi: stamp-core
stamp-elf: $(MKDOC) $(srcdir)/../elf.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../elf.c >elf.tmp
$(srcdir)/../../move-if-change elf.tmp elf.texi
touch stamp-elf
elf.texi: stamp-elf
stamp-elfcode: $(MKDOC) $(srcdir)/../elfcode.h $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../elfcode.h >elfcode.tmp
$(srcdir)/../../move-if-change elfcode.tmp elfcode.texi
touch stamp-elfcode
elfcode.texi: stamp-elfcode
stamp-format: $(MKDOC) $(srcdir)/../format.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../format.c >format.tmp
$(srcdir)/../../move-if-change format.tmp format.texi
touch stamp-format
format.texi: stamp-format
stamp-libbfd: $(MKDOC) $(srcdir)/../libbfd.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str < $(srcdir)/../libbfd.c >libbfd.tmp
$(srcdir)/../../move-if-change libbfd.tmp libbfd.texi
touch stamp-libbfd
libbfd.texi: stamp-libbfd
stamp-opncls: $(MKDOC) $(srcdir)/../opncls.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../opncls.c >opncls.tmp
$(srcdir)/../../move-if-change opncls.tmp opncls.texi
touch stamp-opncls
opncls.texi: stamp-opncls
stamp-reloc: $(MKDOC) $(srcdir)/../reloc.c
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../reloc.c >reloc.tmp
$(srcdir)/../../move-if-change reloc.tmp reloc.texi
touch stamp-reloc
reloc.texi: stamp-reloc
stamp-section: $(MKDOC) $(srcdir)/../section.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../section.c >section.tmp
$(srcdir)/../../move-if-change section.tmp section.texi
touch stamp-section
section.texi: stamp-section
stamp-syms: $(MKDOC) $(srcdir)/../syms.c
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../syms.c >syms.tmp
$(srcdir)/../../move-if-change syms.tmp syms.texi
touch stamp-syms
syms.texi: stamp-syms
stamp-targets: $(MKDOC) $(srcdir)/../targets.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../targets.c >targets.tmp
$(srcdir)/../../move-if-change targets.tmp targets.texi
touch stamp-targets
targets.texi: stamp-targets
stamp-init: $(MKDOC) $(srcdir)/../init.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../init.c >init.tmp
$(srcdir)/../../move-if-change init.tmp init.texi
touch stamp-init
init.texi: stamp-init
stamp-hash: $(MKDOC) $(srcdir)/../hash.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../hash.c >hash.tmp
$(srcdir)/../../move-if-change hash.tmp hash.texi
touch stamp-hash
hash.texi: stamp-hash
stamp-linker: $(MKDOC) $(srcdir)/../linker.c $(srcdir)/doc.str
$(MKDOC) -f $(srcdir)/doc.str <$(srcdir)/../linker.c >linker.tmp
$(srcdir)/../../move-if-change linker.tmp linker.texi
touch stamp-linker
linker.texi: stamp-linker
libbfd.h: $(srcdir)/../libbfd-in.h \
$(srcdir)/../init.c \
$(srcdir)/../libbfd.c \
$(srcdir)/../cache.c \
$(srcdir)/../reloc.c \
$(srcdir)/../cpu-h8300.c \
$(srcdir)/../cpu-i960.c \
$(srcdir)/../archures.c \
$(srcdir)/../elfcode.h \
$(srcdir)/proto.str \
$(MKDOC)
cat $(srcdir)/../libbfd-in.h >libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../init.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../libbfd.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../cache.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../reloc.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../cpu-h8300.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../cpu-i960.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../archures.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../elf.c >>libbfd.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../elfcode.h >>libbfd.h
libcoff.h: $(srcdir)/../libcoff-in.h \
$(srcdir)/../coffcode.h \
$(srcdir)/proto.str \
$(MKDOC)
cat $(srcdir)/../libcoff-in.h >libcoff.h
$(MKDOC) -i -f $(srcdir)/proto.str < $(srcdir)/../coffcode.h >>libcoff.h
bfd.h: $(srcdir)/../bfd-in.h \
$(srcdir)/../init.c \
$(srcdir)/../opncls.c \
$(srcdir)/../libbfd.c \
$(srcdir)/../section.c \
$(srcdir)/../archures.c \
$(srcdir)/../reloc.c \
$(srcdir)/../syms.c \
$(srcdir)/../bfd.c \
$(srcdir)/../archive.c \
$(srcdir)/../corefile.c \
$(srcdir)/../targets.c \
$(srcdir)/../format.c \
$(srcdir)/proto.str \
$(MKDOC)
cat $(srcdir)/../bfd-in.h >bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../init.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../opncls.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../libbfd.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../section.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../archures.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../reloc.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../syms.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../bfd.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../archive.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../corefile.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../targets.c >>bfd.h
$(MKDOC) -f $(srcdir)/proto.str<$(srcdir)/../format.c >>bfd.h
echo "#ifdef __cplusplus" >>bfd.h
echo "}" >>bfd.h
echo "#endif" >>bfd.h
echo "#endif" >>bfd.h
clean-info: clean
mostlyclean:
rm -rf *.log *.ps *~* *.dvi *# $(MKDOC) *.o
clean: mostlyclean
rm -rf $(STAGESTUFF) stamp-*
rm -f *.p *.ip bfd.?? bfd.??? bfd.h libbfd.h libcoff.h texput.log
distclean: mostlyclean
rm -f *.p *.ip bfd.?? bfd.??? bfd.h libbfd.h libcoff.h texput.log
rm -f stamp-*
rm -f Makefile config.status
maintainer-clean realclean: clean
rm -f Makefile config.status
bfd.info: $(DOCFILES) bfdsumm.texi bfd.texinfo
$(MAKEINFO) -I$(srcdir) -o bfd.info $(srcdir)/bfd.texinfo
bfd.dvi: $(DOCFILES) bfdsumm.texi bfd.texinfo
$(TEXI2DVI) $(srcdir)/bfd.texinfo
bfd.ps: bfd.dvi
dvips bfd -o
quickdoc: $(DOCFILES) bfdsumm.texi bfd.texinfo
TEXINPUTS=${TEXIDIR}:.:$$TEXINPUTS tex bfd.texinfo
stage1: force
- mkdir stage1
- mv -f $(STAGESTUFF) stage1
stage2: force
- mkdir stage2
- mv -f $(STAGESTUFF) stage2
stage3: force
- mkdir stage3
- mv -f $(STAGESTUFF) stage3
against=stage2
comparison: force
for i in $(STAGESTUFF) ; do cmp $$i $(against)/$$i || exit 1 ; done
de-stage1: force
- (cd stage1 ; mv -f $(STAGESTUFF) ..)
- rmdir stage1
de-stage2: force
- (cd stage2 ; mv -f $(STAGESTUFF) ..)
- rmdir stage2
de-stage3: force
- (cd stage3 ; mv -f $(STAGESTUFF) ..)
- rmdir stage3
force:
Makefile: $(srcdir)/Makefile.in
cd .. && CONFIG_FILES=doc/$@ CONFIG_HEADERS= $(SHELL) ./config.status

View File

@ -0,0 +1,211 @@
@section a.out backends
@*
@strong{Description}@*
BFD supports a number of different flavours of a.out format,
though the major differences are only the sizes of the
structures on disk, and the shape of the relocation
information.
The support is split into a basic support file @file{aoutx.h}
and other files which derive functions from the base. One
derivation file is @file{aoutf1.h} (for a.out flavour 1), and
adds to the basic a.out functions support for sun3, sun4, 386
and 29k a.out files, to create a target jump vector for a
specific target.
This information is further split out into more specific files
for each machine, including @file{sunos.c} for sun3 and sun4,
@file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
demonstration of a 64 bit a.out format.
The base file @file{aoutx.h} defines general mechanisms for
reading and writing records to and from disk and various
other methods which BFD requires. It is included by
@file{aout32.c} and @file{aout64.c} to form the names
@code{aout_32_swap_exec_header_in}, @code{aout_64_swap_exec_header_in}, etc.
As an example, this is what goes on to make the back end for a
sun4, from @file{aout32.c}:
@example
#define ARCH_SIZE 32
#include "aoutx.h"
@end example
Which exports names:
@example
...
aout_32_canonicalize_reloc
aout_32_find_nearest_line
aout_32_get_lineno
aout_32_get_reloc_upper_bound
...
@end example
from @file{sunos.c}:
@example
#define TARGET_NAME "a.out-sunos-big"
#define VECNAME sunos_big_vec
#include "aoutf1.h"
@end example
requires all the names from @file{aout32.c}, and produces the jump vector
@example
sunos_big_vec
@end example
The file @file{host-aout.c} is a special case. It is for a large set
of hosts that use ``more or less standard'' a.out files, and
for which cross-debugging is not interesting. It uses the
standard 32-bit a.out support routines, but determines the
file offsets and addresses of the text, data, and BSS
sections, the machine architecture and machine type, and the
entry point address, in a host-dependent manner. Once these
values have been determined, generic code is used to handle
the object file.
When porting it to run on a new system, you must supply:
@example
HOST_PAGE_SIZE
HOST_SEGMENT_SIZE
HOST_MACHINE_ARCH (optional)
HOST_MACHINE_MACHINE (optional)
HOST_TEXT_START_ADDR
HOST_STACK_END_ADDR
@end example
in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These
values, plus the structures and macros defined in @file{a.out.h} on
your host system, will produce a BFD target that will access
ordinary a.out files on your host. To configure a new machine
to use @file{host-aout.c}, specify:
@example
TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
TDEPFILES= host-aout.o trad-core.o
@end example
in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in}
to use the
@file{@var{XXX}.mt} file (by setting "@code{bfd_target=XXX}") when your
configuration is selected.
@*
@subsection Relocations
@*
@strong{Description}@*
The file @file{aoutx.h} provides for both the @emph{standard}
and @emph{extended} forms of a.out relocation records.
The standard records contain only an
address, a symbol index, and a type field. The extended records
(used on 29ks and sparcs) also have a full integer for an
addend.
@*
@subsection Internal entry points
@*
@strong{Description}@*
@file{aoutx.h} exports several routines for accessing the
contents of an a.out file, which are gathered and exported in
turn by various format specific files (eg sunos.c).
@*
@findex aout_@var{size}_swap_exec_header_in
@subsubsection @code{aout_@var{size}_swap_exec_header_in}
@strong{Synopsis}
@example
void aout_@var{size}_swap_exec_header_in,
(bfd *abfd,
struct external_exec *raw_bytes,
struct internal_exec *execp);
@end example
@strong{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}.
@*
@findex aout_@var{size}_swap_exec_header_out
@subsubsection @code{aout_@var{size}_swap_exec_header_out}
@strong{Synopsis}
@example
void aout_@var{size}_swap_exec_header_out
(bfd *abfd,
struct internal_exec *execp,
struct external_exec *raw_bytes);
@end example
@strong{Description}@*
Swap the information in an internal exec header structure
@var{execp} into the buffer @var{raw_bytes} ready for writing to disk.
@*
@findex aout_@var{size}_some_aout_object_p
@subsubsection @code{aout_@var{size}_some_aout_object_p}
@strong{Synopsis}
@example
const bfd_target *aout_@var{size}_some_aout_object_p
(bfd *abfd,
const bfd_target *(*callback_to_real_object_p)());
@end example
@strong{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.
@*
@findex aout_@var{size}_mkobject
@subsubsection @code{aout_@var{size}_mkobject}
@strong{Synopsis}
@example
boolean aout_@var{size}_mkobject, (bfd *abfd);
@end example
@strong{Description}@*
Initialize BFD @var{abfd} for use with a.out files.
@*
@findex aout_@var{size}_machine_type
@subsubsection @code{aout_@var{size}_machine_type}
@strong{Synopsis}
@example
enum machine_type aout_@var{size}_machine_type
(enum bfd_architecture arch,
unsigned long machine));
@end example
@strong{Description}@*
Keep track of machine architecture and machine type for
a.out's. Return the @code{machine_type} for a particular
architecture and machine, or @code{M_UNKNOWN} if that exact architecture
and machine can't be represented in a.out format.
If the architecture is understood, machine type 0 (default)
is always understood.
@*
@findex aout_@var{size}_set_arch_mach
@subsubsection @code{aout_@var{size}_set_arch_mach}
@strong{Synopsis}
@example
boolean aout_@var{size}_set_arch_mach,
(bfd *,
enum bfd_architecture arch,
unsigned long machine));
@end example
@strong{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.
@*
@findex aout_@var{size}_new_section_hook
@subsubsection @code{aout_@var{size}_new_section_hook}
@strong{Synopsis}
@example
boolean aout_@var{size}_new_section_hook,
(bfd *abfd,
asection *newsect));
@end example
@strong{Description}@*
Called by the BFD in response to a @code{bfd_make_section}
request.
@*

View File

@ -0,0 +1,95 @@
@section Archives
@*
@strong{Description}@*
An archive (or library) is just another BFD. It has a symbol
table, although there's not much a user program will do with it.
The big difference between an archive BFD and an ordinary BFD
is that the archive doesn't have sections. Instead it has a
chain of BFDs that are considered its contents. These BFDs can
be manipulated like any other. The BFDs contained in an
archive opened for reading will all be opened for reading. You
may put either input or output BFDs into an archive opened for
output; they will be handled correctly when the archive is closed.
Use @code{bfd_openr_next_archived_file} to step through
the contents of an archive opened for input. You don't
have to read the entire archive if you don't want
to! Read it until you find what you want.
Archive contents of output BFDs are chained through the
@code{next} pointer in a BFD. The first one is findable through
the @code{archive_head} slot of the archive. Set it with
@code{bfd_set_archive_head} (q.v.). A given BFD may be in only one
open output archive at a time.
As expected, the BFD archive code is more general than the
archive code of any given environment. BFD archives may
contain files of different formats (e.g., a.out and coff) and
even different architectures. You may even place archives
recursively into archives!
This can cause unexpected confusion, since some archive
formats are more expressive than others. For instance, Intel
COFF archives can preserve long filenames; SunOS a.out archives
cannot. If you move a file from the first to the second
format and back again, the filename may be truncated.
Likewise, different a.out environments have different
conventions as to how they truncate filenames, whether they
preserve directory names in filenames, etc. When
interoperating with native tools, be sure your files are
homogeneous.
Beware: most of these formats do not react well to the
presence of spaces in filenames. We do the best we can, but
can't always handle this case due to restrictions in the format of
archives. Many Unix utilities are braindead in regards to
spaces and such in filenames anyway, so this shouldn't be much
of a restriction.
Archives are supported in BFD in @code{archive.c}.
@*
@findex bfd_get_next_mapent
@subsubsection @code{bfd_get_next_mapent}
@strong{Synopsis}
@example
symindex bfd_get_next_mapent(bfd *abfd, symindex previous, carsym **sym);
@end example
@strong{Description}@*
Step through archive @var{abfd}'s symbol table (if it
has one). Successively update @var{sym} with the next symbol's
information, returning that symbol's (internal) index into the
symbol table.
Supply @code{BFD_NO_MORE_SYMBOLS} as the @var{previous} entry to get
the first one; returns @code{BFD_NO_MORE_SYMBOLS} when you've already
got the last one.
A @code{carsym} is a canonical archive symbol. The only
user-visible element is its name, a null-terminated string.
@*
@findex bfd_set_archive_head
@subsubsection @code{bfd_set_archive_head}
@strong{Synopsis}
@example
boolean bfd_set_archive_head(bfd *output, bfd *new_head);
@end example
@strong{Description}@*
Set the head of the chain of
BFDs contained in the archive @var{output} to @var{new_head}.
@*
@findex bfd_openr_next_archived_file
@subsubsection @code{bfd_openr_next_archived_file}
@strong{Synopsis}
@example
bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous);
@end example
@strong{Description}@*
Provided a BFD, @var{archive}, containing an archive and NULL, open
an input BFD on the first contained element and returns that.
Subsequent calls should pass
the archive and the previous return value to return a created
BFD to the next contained element. NULL is returned when there
are no more.
@*

View File

@ -0,0 +1,307 @@
@section Architectures
BFD keeps one atom in a BFD describing the
architecture of the data attached to the BFD: a pointer to a
@code{bfd_arch_info_type}.
Pointers to structures can be requested independently of a BFD
so that an architecture's information can be interrogated
without access to an open BFD.
The architecture information is provided by each architecture package.
The set of default architectures is selected by the macro
@code{SELECT_ARCHITECTURES}. This is normally set up in the
@file{config/@var{target}.mt} file of your choice. If the name is not
defined, then all the architectures supported are included.
When BFD starts up, all the architectures are called with an
initialize method. It is up to the architecture back end 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
default case (an item with a machine field of 0).
BFD's idea of an architecture is implemented in @file{archures.c}.
@*
@subsection bfd_architecture
@*
@strong{Description}@*
This enum gives the object file's CPU architecture, in a
global sense---i.e., what processor family does it belong to?
Another field indicates which processor within
the family is in use. The machine gives a number which
distinguishes different versions of the architecture,
containing, for example, 2 and 3 for Intel i960 KA and i960 KB,
and 68020 and 68030 for Motorola 68020 and 68030.
@example
enum bfd_architecture
@{
bfd_arch_unknown, /* File arch not known */
bfd_arch_obscure, /* Arch known, not one of these */
bfd_arch_m68k, /* Motorola 68xxx */
bfd_arch_vax, /* DEC Vax */
bfd_arch_i960, /* Intel 960 */
/* The order of the following is important.
lower number indicates a machine type that
only accepts a subset of the instructions
available to machines with higher numbers.
The exception is the "ca", which is
incompatible with all other machines except
"core". */
#define bfd_mach_i960_core 1
#define bfd_mach_i960_ka_sa 2
#define bfd_mach_i960_kb_sb 3
#define bfd_mach_i960_mc 4
#define bfd_mach_i960_xa 5
#define bfd_mach_i960_ca 6
#define bfd_mach_i960_jx 7
#define bfd_mach_i960_hx 8
bfd_arch_a29k, /* AMD 29000 */
bfd_arch_sparc, /* SPARC */
#define bfd_mach_sparc 1
/* The difference between v8plus and v9 is that v9 is a true 64 bit env. */
#define bfd_mach_sparc_sparclet 2
#define bfd_mach_sparc_sparclite 3
#define bfd_mach_sparc_v8plus 4
#define bfd_mach_sparc_v8plusa 5 /* with ultrasparc add'ns */
#define bfd_mach_sparc_v9 6
#define bfd_mach_sparc_v9a 7 /* with ultrasparc add'ns */
/* Nonzero if MACH has the v9 instruction set. */
#define bfd_mach_sparc_v9_p(mach) \
((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
bfd_arch_mips, /* MIPS Rxxxx */
bfd_arch_i386, /* Intel 386 */
#define bfd_mach_i386_i386 0
#define bfd_mach_i386_i8086 1
bfd_arch_we32k, /* AT&T WE32xxx */
bfd_arch_tahoe, /* CCI/Harris Tahoe */
bfd_arch_i860, /* Intel 860 */
bfd_arch_romp, /* IBM ROMP PC/RT */
bfd_arch_alliant, /* Alliant */
bfd_arch_convex, /* Convex */
bfd_arch_m88k, /* Motorola 88xxx */
bfd_arch_pyramid, /* Pyramid Technology */
bfd_arch_h8300, /* Hitachi H8/300 */
#define bfd_mach_h8300 1
#define bfd_mach_h8300h 2
#define bfd_mach_h8300s 3
bfd_arch_powerpc, /* PowerPC */
bfd_arch_rs6000, /* IBM RS/6000 */
bfd_arch_hppa, /* HP PA RISC */
bfd_arch_d10v, /* Mitsubishi D10V */
bfd_arch_z8k, /* Zilog Z8000 */
#define bfd_mach_z8001 1
#define bfd_mach_z8002 2
bfd_arch_h8500, /* Hitachi H8/500 */
bfd_arch_sh, /* Hitachi SH */
bfd_arch_alpha, /* Dec Alpha */
bfd_arch_arm, /* Advanced Risc Machines ARM */
bfd_arch_ns32k, /* National Semiconductors ns32000 */
bfd_arch_w65, /* WDC 65816 */
bfd_arch_m32r, /* Mitsubishi M32R/D */
bfd_arch_mn10200, /* Matsushita MN10200 */
bfd_arch_mn10300, /* Matsushita MN10300 */
bfd_arch_last
@};
@end example
@*
@subsection bfd_arch_info
@*
@strong{Description}@*
This structure contains information on architectures for use
within BFD.
@example
typedef struct bfd_arch_info
@{
int bits_per_word;
int bits_per_address;
int bits_per_byte;
enum bfd_architecture arch;
unsigned long mach;
const char *arch_name;
const char *printable_name;
unsigned int section_align_power;
/* true if this is the default machine for the architecture */
boolean the_default;
const struct bfd_arch_info * (*compatible)
PARAMS ((const struct bfd_arch_info *a,
const struct bfd_arch_info *b));
boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
const struct bfd_arch_info *next;
@} bfd_arch_info_type;
@end example
@*
@findex bfd_printable_name
@subsubsection @code{bfd_printable_name}
@strong{Synopsis}
@example
const char *bfd_printable_name(bfd *abfd);
@end example
@strong{Description}@*
Return a printable string representing the architecture and machine
from the pointer to the architecture info structure.
@*
@findex bfd_scan_arch
@subsubsection @code{bfd_scan_arch}
@strong{Synopsis}
@example
const bfd_arch_info_type *bfd_scan_arch(const char *string);
@end example
@strong{Description}@*
Figure out if BFD supports any cpu which could be described with
the name @var{string}. Return a pointer to an @code{arch_info}
structure if a machine is found, otherwise NULL.
@*
@findex bfd_arch_get_compatible
@subsubsection @code{bfd_arch_get_compatible}
@strong{Synopsis}
@example
const bfd_arch_info_type *bfd_arch_get_compatible(
const bfd *abfd,
const bfd *bbfd);
@end example
@strong{Description}@*
Determine whether two BFDs'
architectures and machine types are compatible. Calculates
the lowest common denominator between the two architectures
and machine types implied by the BFDs and returns a pointer to
an @code{arch_info} structure describing the compatible machine.
@*
@findex bfd_default_arch_struct
@subsubsection @code{bfd_default_arch_struct}
@strong{Description}@*
The @code{bfd_default_arch_struct} is an item of
@code{bfd_arch_info_type} which has been initialized to a fairly
generic state. A BFD starts life by pointing to this
structure, until the correct back end has determined the real
architecture of the file.
@example
extern const bfd_arch_info_type bfd_default_arch_struct;
@end example
@*
@findex bfd_set_arch_info
@subsubsection @code{bfd_set_arch_info}
@strong{Synopsis}
@example
void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
@end example
@strong{Description}@*
Set the architecture info of @var{abfd} to @var{arg}.
@*
@findex bfd_default_set_arch_mach
@subsubsection @code{bfd_default_set_arch_mach}
@strong{Synopsis}
@example
boolean bfd_default_set_arch_mach(bfd *abfd,
enum bfd_architecture arch,
unsigned long mach);
@end example
@strong{Description}@*
Set the architecture and machine type in BFD @var{abfd}
to @var{arch} and @var{mach}. Find the correct
pointer to a structure and insert it into the @code{arch_info}
pointer.
@*
@findex bfd_get_arch
@subsubsection @code{bfd_get_arch}
@strong{Synopsis}
@example
enum bfd_architecture bfd_get_arch(bfd *abfd);
@end example
@strong{Description}@*
Return the enumerated type which describes the BFD @var{abfd}'s
architecture.
@*
@findex bfd_get_mach
@subsubsection @code{bfd_get_mach}
@strong{Synopsis}
@example
unsigned long bfd_get_mach(bfd *abfd);
@end example
@strong{Description}@*
Return the long type which describes the BFD @var{abfd}'s
machine.
@*
@findex bfd_arch_bits_per_byte
@subsubsection @code{bfd_arch_bits_per_byte}
@strong{Synopsis}
@example
unsigned int bfd_arch_bits_per_byte(bfd *abfd);
@end example
@strong{Description}@*
Return the number of bits in one of the BFD @var{abfd}'s
architecture's bytes.
@*
@findex bfd_arch_bits_per_address
@subsubsection @code{bfd_arch_bits_per_address}
@strong{Synopsis}
@example
unsigned int bfd_arch_bits_per_address(bfd *abfd);
@end example
@strong{Description}@*
Return the number of bits in one of the BFD @var{abfd}'s
architecture's addresses.
@*
@findex bfd_default_compatible
@subsubsection @code{bfd_default_compatible}
@strong{Synopsis}
@example
const bfd_arch_info_type *bfd_default_compatible
(const bfd_arch_info_type *a,
const bfd_arch_info_type *b);
@end example
@strong{Description}@*
The default function for testing for compatibility.
@*
@findex bfd_default_scan
@subsubsection @code{bfd_default_scan}
@strong{Synopsis}
@example
boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
@end example
@strong{Description}@*
The default function for working out whether this is an
architecture hit and a machine hit.
@*
@findex bfd_get_arch_info
@subsubsection @code{bfd_get_arch_info}
@strong{Synopsis}
@example
const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
@end example
@strong{Description}@*
Return the architecture info struct in @var{abfd}.
@*
@findex bfd_lookup_arch
@subsubsection @code{bfd_lookup_arch}
@strong{Synopsis}
@example
const bfd_arch_info_type *bfd_lookup_arch
(enum bfd_architecture
arch,
unsigned long machine);
@end example
@strong{Description}@*
Look for the architecure info structure which matches the
arguments @var{arch} and @var{machine}. A machine of 0 matches the
machine/architecture structure which marks itself as the
default.
@*
@findex bfd_printable_arch_mach
@subsubsection @code{bfd_printable_arch_mach}
@strong{Synopsis}
@example
const char *bfd_printable_arch_mach
(enum bfd_architecture arch, unsigned long machine);
@end example
@strong{Description}@*
Return a printable string representing the architecture and
machine type.
This routine is depreciated.
@*

View File

@ -0,0 +1,585 @@
@section @code{typedef bfd}
A BFD has type @code{bfd}; objects of this type are the
cornerstone of any application using BFD. Using BFD
consists of making references though the BFD and to data in the BFD.
Here is the structure that defines the type @code{bfd}. It
contains the major data about the file and pointers
to the rest of the data.
@*
.
@example
struct _bfd
@{
/* The filename the application opened the BFD with. */
CONST char *filename;
/* A pointer to the target jump table. */
const struct bfd_target *xvec;
/* To avoid dragging too many header files into every file that
includes `@code{bfd.h}', IOSTREAM has been declared as a "char
*", and MTIME as a "long". Their correct types, to which they
are cast when used, are "FILE *" and "time_t". The iostream
is the result of an fopen on the filename. However, if the
BFD_IN_MEMORY flag is set, then iostream is actually a pointer
to a bfd_in_memory struct. */
PTR iostream;
/* Is the file descriptor being cached? That is, can it be closed as
needed, and re-opened when accessed later? */
boolean cacheable;
/* Marks whether there was a default target specified when the
BFD was opened. This is used to select which matching algorithm
to use to choose the back end. */
boolean target_defaulted;
/* The caching routines use these to maintain a
least-recently-used list of BFDs */
struct _bfd *lru_prev, *lru_next;
/* When a file is closed by the caching routines, BFD retains
state information on the file here: */
file_ptr where;
/* and here: (``once'' means at least once) */
boolean opened_once;
/* Set if we have a locally maintained mtime value, rather than
getting it from the file each time: */
boolean mtime_set;
/* File modified time, if mtime_set is true: */
long mtime;
/* Reserved for an unimplemented file locking extension.*/
int ifd;
/* The format which belongs to the BFD. (object, core, etc.) */
bfd_format format;
/* The direction the BFD was opened with*/
enum bfd_direction @{no_direction = 0,
read_direction = 1,
write_direction = 2,
both_direction = 3@} direction;
/* Format_specific flags*/
flagword flags;
/* Currently my_archive is tested before adding origin to
anything. I believe that this can become always an add of
origin, with origin set to 0 for non archive files. */
file_ptr origin;
/* Remember when output has begun, to stop strange things
from happening. */
boolean output_has_begun;
/* Pointer to linked list of sections*/
struct sec *sections;
/* The number of sections */
unsigned int section_count;
/* Stuff only useful for object files:
The start address. */
bfd_vma start_address;
/* Used for input and output*/
unsigned int symcount;
/* Symbol table for output BFD (with symcount entries) */
struct symbol_cache_entry **outsymbols;
/* Pointer to structure which contains architecture information*/
const struct bfd_arch_info *arch_info;
/* Stuff only useful for archives:*/
PTR arelt_data;
struct _bfd *my_archive; /* The containing archive BFD. */
struct _bfd *next; /* The next BFD in the archive. */
struct _bfd *archive_head; /* The first BFD in the archive. */
boolean has_armap;
/* A chain of BFD structures involved in a link. */
struct _bfd *link_next;
/* A field used by _bfd_generic_link_add_archive_symbols. This will
be used only for archive elements. */
int archive_pass;
/* Used by the back end to hold private data. */
union
@{
struct aout_data_struct *aout_data;
struct artdata *aout_ar_data;
struct _oasys_data *oasys_obj_data;
struct _oasys_ar_data *oasys_ar_data;
struct coff_tdata *coff_obj_data;
struct pe_tdata *pe_obj_data;
struct xcoff_tdata *xcoff_obj_data;
struct ecoff_tdata *ecoff_obj_data;
struct ieee_data_struct *ieee_data;
struct ieee_ar_data_struct *ieee_ar_data;
struct srec_data_struct *srec_data;
struct ihex_data_struct *ihex_data;
struct tekhex_data_struct *tekhex_data;
struct elf_obj_tdata *elf_obj_data;
struct nlm_obj_tdata *nlm_obj_data;
struct bout_data_struct *bout_data;
struct sun_core_struct *sun_core_data;
struct trad_core_struct *trad_core_data;
struct som_data_struct *som_data;
struct hpux_core_struct *hpux_core_data;
struct hppabsd_core_struct *hppabsd_core_data;
struct sgi_core_struct *sgi_core_data;
struct lynx_core_struct *lynx_core_data;
struct osf_core_struct *osf_core_data;
struct cisco_core_struct *cisco_core_data;
struct versados_data_struct *versados_data;
struct netbsd_core_struct *netbsd_core_data;
PTR any;
@} tdata;
/* Used by the application to hold private data*/
PTR usrdata;
/* Where all the allocated stuff under this BFD goes. This is a
struct objalloc *, but we use PTR to avoid requiring the inclusion of
objalloc.h. */
PTR memory;
@};
@end example
@section Error reporting
Most BFD functions return nonzero on success (check their
individual documentation for precise semantics). On an error,
they call @code{bfd_set_error} to set an error condition that callers
can check by calling @code{bfd_get_error}.
If that returns @code{bfd_error_system_call}, then check
@code{errno}.
The easiest way to report a BFD error to the user is to
use @code{bfd_perror}.
@*
@subsection Type @code{bfd_error_type}
The values returned by @code{bfd_get_error} are defined by the
enumerated type @code{bfd_error_type}.
@*
.
@example
typedef enum bfd_error
@{
bfd_error_no_error = 0,
bfd_error_system_call,
bfd_error_invalid_target,
bfd_error_wrong_format,
bfd_error_invalid_operation,
bfd_error_no_memory,
bfd_error_no_symbols,
bfd_error_no_armap,
bfd_error_no_more_archived_files,
bfd_error_malformed_archive,
bfd_error_file_not_recognized,
bfd_error_file_ambiguously_recognized,
bfd_error_no_contents,
bfd_error_nonrepresentable_section,
bfd_error_no_debug_section,
bfd_error_bad_value,
bfd_error_file_truncated,
bfd_error_file_too_big,
bfd_error_invalid_error_code
@} bfd_error_type;
@end example
@findex bfd_get_error
@subsubsection @code{bfd_get_error}
@strong{Synopsis}
@example
bfd_error_type bfd_get_error (void);
@end example
@strong{Description}@*
Return the current BFD error condition.
@*
@findex bfd_set_error
@subsubsection @code{bfd_set_error}
@strong{Synopsis}
@example
void bfd_set_error (bfd_error_type error_tag);
@end example
@strong{Description}@*
Set the BFD error condition to be @var{error_tag}.
@*
@findex bfd_errmsg
@subsubsection @code{bfd_errmsg}
@strong{Synopsis}
@example
CONST char *bfd_errmsg (bfd_error_type error_tag);
@end example
@strong{Description}@*
Return a string describing the error @var{error_tag}, or
the system error if @var{error_tag} is @code{bfd_error_system_call}.
@*
@findex bfd_perror
@subsubsection @code{bfd_perror}
@strong{Synopsis}
@example
void bfd_perror (CONST char *message);
@end example
@strong{Description}@*
Print to the standard error stream a string describing the
last BFD error that occurred, or the last system error if
the last BFD error was a system call failure. If @var{message}
is non-NULL and non-empty, the error string printed is preceded
by @var{message}, a colon, and a space. It is followed by a newline.
@*
@subsection BFD error handler
Some BFD functions want to print messages describing the
problem. They call a BFD error handler function. This
function may be overriden by the program.
The BFD error handler acts like printf.
@*
.
@example
typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
@end example
@findex bfd_set_error_handler
@subsubsection @code{bfd_set_error_handler}
@strong{Synopsis}
@example
bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
@end example
@strong{Description}@*
Set the BFD error handler function. Returns the previous
function.
@*
@findex bfd_set_error_program_name
@subsubsection @code{bfd_set_error_program_name}
@strong{Synopsis}
@example
void bfd_set_error_program_name (const char *);
@end example
@strong{Description}@*
Set the program name to use when printing a BFD error. This
is printed before the error message followed by a colon and
space. The string must not be changed after it is passed to
this function.
@*
@section Symbols
@*
@findex bfd_get_reloc_upper_bound
@subsubsection @code{bfd_get_reloc_upper_bound}
@strong{Synopsis}
@example
long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
@end example
@strong{Description}@*
Return the number of bytes required to store the
relocation information associated with section @var{sect}
attached to bfd @var{abfd}. If an error occurs, return -1.
@*
@findex bfd_canonicalize_reloc
@subsubsection @code{bfd_canonicalize_reloc}
@strong{Synopsis}
@example
long bfd_canonicalize_reloc
(bfd *abfd,
asection *sec,
arelent **loc,
asymbol **syms);
@end example
@strong{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
@code{bfd_get_reloc_upper_bound}. Returns the number of relocs, or
-1 on error.
The @var{syms} table is also needed for horrible internal magic
reasons.
@*
@findex bfd_set_reloc
@subsubsection @code{bfd_set_reloc}
@strong{Synopsis}
@example
void bfd_set_reloc
(bfd *abfd, asection *sec, arelent **rel, unsigned int count)
@end example
@strong{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.
@*
@findex bfd_set_file_flags
@subsubsection @code{bfd_set_file_flags}
@strong{Synopsis}
@example
boolean bfd_set_file_flags(bfd *abfd, flagword flags);
@end example
@strong{Description}@*
Set the flag word in the BFD @var{abfd} to the value @var{flags}.
Possible errors are:
@itemize @bullet
@item
@code{bfd_error_wrong_format} - The target bfd was not of object format.
@item
@code{bfd_error_invalid_operation} - The target bfd was open for reading.
@item
@code{bfd_error_invalid_operation} -
The flag word contained a bit which was not applicable to the
type of file. E.g., an attempt was made to set the @code{D_PAGED} bit
on a BFD format which does not support demand paging.
@end itemize
@*
@findex bfd_set_start_address
@subsubsection @code{bfd_set_start_address}
@strong{Synopsis}
@example
boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
@end example
@strong{Description}@*
Make @var{vma} the entry point of output BFD @var{abfd}.
@*
@strong{Returns}@*
Returns @code{true} on success, @code{false} otherwise.
@*
@findex bfd_get_mtime
@subsubsection @code{bfd_get_mtime}
@strong{Synopsis}
@example
long bfd_get_mtime(bfd *abfd);
@end example
@strong{Description}@*
Return the file modification time (as read from the file system, or
from the archive header for archive members).
@*
@findex bfd_get_size
@subsubsection @code{bfd_get_size}
@strong{Synopsis}
@example
long bfd_get_size(bfd *abfd);
@end example
@strong{Description}@*
Return the file size (as read from file system) for the file
associated with BFD @var{abfd}.
The initial motivation for, and use of, this routine is not
so we can get the exact size of the object the BFD applies to, since
that might not be generally possible (archive members for example).
It would be ideal if someone could eventually modify
it so that such results were guaranteed.
Instead, we want to ask questions like "is this NNN byte sized
object I'm about to try read from file offset YYY reasonable?"
As as example of where we might do this, some object formats
use string tables for which the first @code{sizeof(long)} bytes of the
table contain the size of the table itself, including the size bytes.
If an application tries to read what it thinks is one of these
string tables, without some way to validate the size, and for
some reason the size is wrong (byte swapping error, wrong location
for the string table, etc.), the only clue is likely to be a read
error when it tries to read the table, or a "virtual memory
exhausted" error when it tries to allocate 15 bazillon bytes
of space for the 15 bazillon byte table it is about to read.
This function at least allows us to answer the quesion, "is the
size reasonable?".
@*
@findex bfd_get_gp_size
@subsubsection @code{bfd_get_gp_size}
@strong{Synopsis}
@example
int bfd_get_gp_size(bfd *abfd);
@end example
@strong{Description}@*
Return the maximum size of objects to be optimized using the GP
register under MIPS ECOFF. This is typically set by the @code{-G}
argument to the compiler, assembler or linker.
@*
@findex bfd_set_gp_size
@subsubsection @code{bfd_set_gp_size}
@strong{Synopsis}
@example
void bfd_set_gp_size(bfd *abfd, int i);
@end example
@strong{Description}@*
Set the maximum size of objects to be optimized using the GP
register under ECOFF or MIPS ELF. This is typically set by
the @code{-G} argument to the compiler, assembler or linker.
@*
@findex bfd_scan_vma
@subsubsection @code{bfd_scan_vma}
@strong{Synopsis}
@example
bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
@end example
@strong{Description}@*
Convert, like @code{strtoul}, a numerical expression
@var{string} into a @code{bfd_vma} integer, and return that integer.
(Though without as many bells and whistles as @code{strtoul}.)
The expression is assumed to be unsigned (i.e., positive).
If given a @var{base}, it is used as the base for conversion.
A base of 0 causes the function to interpret the string
in hex if a leading "0x" or "0X" is found, otherwise
in octal if a leading zero is found, otherwise in decimal.
Overflow is not detected.
@*
@findex bfd_copy_private_bfd_data
@subsubsection @code{bfd_copy_private_bfd_data}
@strong{Synopsis}
@example
boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
@end example
@strong{Description}@*
Copy private BFD information from the BFD @var{ibfd} to the
the BFD @var{obfd}. Return @code{true} on success, @code{false} on error.
Possible error returns are:
@itemize @bullet
@item
@code{bfd_error_no_memory} -
Not enough memory exists to create private data for @var{obfd}.
@end itemize
@example
#define bfd_copy_private_bfd_data(ibfd, obfd) \
BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
(ibfd, obfd))
@end example
@*
@findex bfd_merge_private_bfd_data
@subsubsection @code{bfd_merge_private_bfd_data}
@strong{Synopsis}
@example
boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
@end example
@strong{Description}@*
Merge private BFD information from the BFD @var{ibfd} to the
the output file BFD @var{obfd} when linking. Return @code{true}
on success, @code{false} on error. Possible error returns are:
@itemize @bullet
@item
@code{bfd_error_no_memory} -
Not enough memory exists to create private data for @var{obfd}.
@end itemize
@example
#define bfd_merge_private_bfd_data(ibfd, obfd) \
BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
(ibfd, obfd))
@end example
@*
@findex bfd_set_private_flags
@subsubsection @code{bfd_set_private_flags}
@strong{Synopsis}
@example
boolean bfd_set_private_flags(bfd *abfd, flagword flags);
@end example
@strong{Description}@*
Set private BFD flag information in the BFD @var{abfd}.
Return @code{true} on success, @code{false} on error. Possible error
returns are:
@itemize @bullet
@item
@code{bfd_error_no_memory} -
Not enough memory exists to create private data for @var{obfd}.
@end itemize
@example
#define bfd_set_private_flags(abfd, flags) \
BFD_SEND (abfd, _bfd_set_private_flags, \
(abfd, flags))
@end example
@*
@findex stuff
@subsubsection @code{stuff}
@strong{Description}@*
Stuff which should be documented:
@example
#define bfd_sizeof_headers(abfd, reloc) \
BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, sec, syms, off, file, func, line))
/* Do these three do anything useful at all, for any back end? */
#define bfd_debug_info_start(abfd) \
BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
#define bfd_debug_info_end(abfd) \
BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
#define bfd_debug_info_accumulate(abfd, section) \
BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
#define bfd_stat_arch_elt(abfd, stat) \
BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
#define bfd_update_armap_timestamp(abfd) \
BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
#define bfd_set_arch_mach(abfd, arch, mach)\
BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
#define bfd_relax_section(abfd, section, link_info, again) \
BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
#define bfd_link_hash_table_create(abfd) \
BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
#define bfd_link_add_symbols(abfd, info) \
BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
#define bfd_final_link(abfd, info) \
BFD_SEND (abfd, _bfd_final_link, (abfd, info))
#define bfd_free_cached_info(abfd) \
BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
#define bfd_get_dynamic_symtab_upper_bound(abfd) \
BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
#define bfd_print_private_bfd_data(abfd, file)\
BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
#define bfd_get_dynamic_reloc_upper_bound(abfd) \
BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
extern bfd_byte *bfd_get_relocated_section_contents
PARAMS ((bfd *, struct bfd_link_info *,
struct bfd_link_order *, bfd_byte *,
boolean, asymbol **));
@end example
@*

View File

@ -0,0 +1,348 @@
\input texinfo.tex
@setfilename bfd.info
@c $Id: bfd.texinfo,v 1.28 1995/11/10 20:04:12 victoria Exp $
@tex
% NOTE LOCAL KLUGE TO AVOID TOO MUCH WHITESPACE
\global\long\def\example{%
\begingroup
\let\aboveenvbreak=\par
\let\afterenvbreak=\par
\parskip=0pt
\lisp}
\global\long\def\Eexample{%
\Elisp
\endgroup
\vskip -\parskip% to cancel out effect of following \par
}
@end tex
@synindex fn cp
@ifinfo
@format
START-INFO-DIR-ENTRY
* Bfd: (bfd). The Binary File Descriptor library.
END-INFO-DIR-ENTRY
@end format
@end ifinfo
@ifinfo
This file documents the BFD library.
Copyright (C) 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@ignore
Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, subject to the terms
of the GNU General Public License, which includes the provision that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end ifinfo
@iftex
@c@finalout
@setchapternewpage on
@c@setchapternewpage odd
@settitle LIB BFD, the Binary File Descriptor Library
@titlepage
@title{libbfd}
@subtitle{The Binary File Descriptor Library}
@sp 1
@subtitle First Edition---BFD version < 3.0
@subtitle April 1991
@author {Steve Chamberlain}
@author {Cygnus Support}
@page
@tex
\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
\xdef\manvers{\$Revision: 1.28 $} % For use in headers, footers too
{\parskip=0pt
\hfill Cygnus Support\par
\hfill sac\@cygnus.com\par
\hfill {\it BFD}, \manvers\par
\hfill \TeX{}info \texinfoversion\par
}
\global\parindent=0pt % Steve likes it this way
@end tex
@vskip 0pt plus 1filll
Copyright @copyright{} 1991 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, subject to the terms
of the GNU General Public License, which includes the provision that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end titlepage
@end iftex
@node Top, Overview, (dir), (dir)
@ifinfo
This file documents the binary file descriptor library libbfd.
@end ifinfo
@menu
* Overview:: Overview of BFD
* BFD front end:: BFD front end
* BFD back ends:: BFD back ends
* Index:: Index
@end menu
@node Overview, BFD front end, Top, Top
@chapter Introduction
@cindex BFD
@cindex what is it?
BFD is a package which allows applications to use the
same routines to operate on object files whatever the object file
format. A new object file format can be supported simply by
creating a new BFD back end and adding it to the library.
BFD is split into two parts: the front end, and the back ends (one for
each object file format).
@itemize @bullet
@item The front end of BFD provides the interface to the user. It manages
memory and various canonical data structures. The front end also
decides which back end to use and when to call back end routines.
@item The back ends provide BFD its view of the real world. Each back
end provides a set of calls which the BFD front end can use to maintain
its canonical form. The back ends also may keep around information for
their own use, for greater efficiency.
@end itemize
@menu
* History:: History
* How It Works:: How It Works
* What BFD Version 2 Can Do:: What BFD Version 2 Can Do
@end menu
@node History, How It Works, Overview, Overview
@section History
One spur behind BFD was the desire, on the part of the GNU 960 team at
Intel Oregon, for interoperability of applications on their COFF and
b.out file formats. Cygnus was providing GNU support for the team, and
was contracted to provide the required functionality.
The name came from a conversation David Wallace was having with Richard
Stallman about the library: RMS said that it would be quite hard---David
said ``BFD''. Stallman was right, but the name stuck.
At the same time, Ready Systems wanted much the same thing, but for
different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k
coff.
BFD was first implemented by members of Cygnus Support; Steve
Chamberlain (@code{sac@@cygnus.com}), John Gilmore
(@code{gnu@@cygnus.com}), K. Richard Pixley (@code{rich@@cygnus.com})
and David Henkel-Wallace (@code{gumby@@cygnus.com}).
@node How It Works, What BFD Version 2 Can Do, History, Overview
@section How To Use BFD
To use the library, include @file{bfd.h} and link with @file{libbfd.a}.
BFD provides a common interface to the parts of an object file
for a calling application.
When an application sucessfully opens a target file (object, archive, or
whatever), a pointer to an internal structure is returned. This pointer
points to a structure called @code{bfd}, described in
@file{bfd.h}. Our convention is to call this pointer a BFD, and
instances of it within code @code{abfd}. All operations on
the target object file are applied as methods to the BFD. The mapping is
defined within @code{bfd.h} in a set of macros, all beginning
with @samp{bfd_} to reduce namespace pollution.
For example, this sequence does what you would probably expect:
return the number of sections in an object file attached to a BFD
@code{abfd}.
@lisp
@c @cartouche
#include "bfd.h"
unsigned int number_of_sections(abfd)
bfd *abfd;
@{
return bfd_count_sections(abfd);
@}
@c @end cartouche
@end lisp
The abstraction used within BFD is that an object file has:
@itemize @bullet
@item
a header,
@item
a number of sections containing raw data (@pxref{Sections}),
@item
a set of relocations (@pxref{Relocations}), and
@item
some symbol information (@pxref{Symbols}).
@end itemize
@noindent
Also, BFDs opened for archives have the additional attribute of an index
and contain subordinate BFDs. This approach is fine for a.out and coff,
but loses efficiency when applied to formats such as S-records and
IEEE-695.
@node What BFD Version 2 Can Do, , How It Works, Overview
@section What BFD Version 2 Can Do
@include bfdsumm.texi
@node BFD front end, BFD back ends, Overview, Top
@chapter BFD front end
@include bfd.texi
@menu
* Memory Usage::
* Initialization::
* Sections::
* Symbols::
* Archives::
* Formats::
* Relocations::
* Core Files::
* Targets::
* Architectures::
* Opening and Closing::
* Internal::
* File Caching::
* Linker Functions::
* Hash Tables::
@end menu
@node Memory Usage, Initialization, BFD front end, BFD front end
@section Memory usage
BFD keeps all of its internal structures in obstacks. There is one obstack
per open BFD file, into which the current state is stored. When a BFD is
closed, the obstack is deleted, and so everything which has been
allocated by BFD for the closing file is thrown away.
BFD does not free anything created by an application, but pointers into
@code{bfd} structures become invalid on a @code{bfd_close}; for example,
after a @code{bfd_close} the vector passed to
@code{bfd_canonicalize_symtab} is still around, since it has been
allocated by the application, but the data that it pointed to are
lost.
The general rule is to not close a BFD until all operations dependent
upon data from the BFD have been completed, or all the data from within
the file has been copied. To help with the management of memory, there
is a function (@code{bfd_alloc_size}) which returns the number of bytes
in obstacks associated with the supplied BFD. This could be used to
select the greediest open BFD, close it to reclaim the memory, perform
some operation and reopen the BFD again, to get a fresh copy of the data
structures.
@node Initialization, Sections, Memory Usage, BFD front end
@include init.texi
@node Sections, Symbols, Initialization, BFD front end
@include section.texi
@node Symbols, Archives, Sections, BFD front end
@include syms.texi
@node Archives, Formats, Symbols, BFD front end
@include archive.texi
@node Formats, Relocations, Archives, BFD front end
@include format.texi
@node Relocations, Core Files, Formats, BFD front end
@include reloc.texi
@node Core Files, Targets, Relocations, BFD front end
@include core.texi
@node Targets, Architectures, Core Files, BFD front end
@include targets.texi
@node Architectures, Opening and Closing, Targets, BFD front end
@include archures.texi
@node Opening and Closing, Internal, Architectures, BFD front end
@include opncls.texi
@node Internal, File Caching, Opening and Closing, BFD front end
@include libbfd.texi
@node File Caching, Linker Functions, Internal, BFD front end
@include cache.texi
@node Linker Functions, Hash Tables, File Caching, BFD front end
@include linker.texi
@node Hash Tables, , Linker Functions, BFD front end
@include hash.texi
@node BFD back ends, Index, BFD front end, Top
@chapter BFD back ends
@menu
* What to Put Where::
* aout :: a.out backends
* coff :: coff backends
* elf :: elf backends
@ignore
* oasys :: oasys backends
* ieee :: ieee backend
* srecord :: s-record backend
@end ignore
@end menu
@node What to Put Where, aout, BFD back ends, BFD back ends
All of BFD lives in one directory.
@node aout, coff, What to Put Where, BFD back ends
@include aoutx.texi
@node coff, elf, aout, BFD back ends
@include coffcode.texi
@node elf, , coff, BFD back ends
@include elf.texi
@c Leave this out until the file has some actual contents...
@c @include elfcode.texi
@node Index, , BFD back ends , Top
@unnumbered Index
@printindex cp
@tex
% I think something like @colophon should be in texinfo. In the
% meantime:
\long\def\colophon{\hbox to0pt{}\vfill
\centerline{The body of this manual is set in}
\centerline{\fontname\tenrm,}
\centerline{with headings in {\bf\fontname\tenbf}}
\centerline{and examples in {\tt\fontname\tentt}.}
\centerline{{\it\fontname\tenit\/} and}
\centerline{{\sl\fontname\tensl\/}}
\centerline{are used for emphasis.}\vfill}
\page\colophon
% Blame: doc@cygnus.com, 28mar91.
@end tex
@contents
@bye

View File

@ -0,0 +1,148 @@
@c This summary of BFD is shared by the BFD and LD docs.
When an object file is opened, BFD subroutines automatically determine
the format of the input object file. They then build a descriptor in
memory with pointers to routines that will be used to access elements of
the object file's data structures.
As different information from the the object files is required,
BFD reads from different sections of the file and processes them.
For example, a very common operation for the linker is processing symbol
tables. Each BFD back end provides a routine for converting
between the object file's representation of symbols and an internal
canonical format. When the linker asks for the symbol table of an object
file, it calls through a memory pointer to the routine from the
relevant BFD back end which reads and converts the table into a canonical
form. The linker then operates upon the canonical form. When the link is
finished and the linker writes the output file's symbol table,
another BFD back end routine is called to take the newly
created symbol table and convert it into the chosen output format.
@menu
* BFD information loss:: Information Loss
* Canonical format:: The BFD canonical object-file format
@end menu
@node BFD information loss
@subsection Information Loss
@emph{Information can be lost during output.} The output formats
supported by BFD do not provide identical facilities, and
information which can be described in one form has nowhere to go in
another format. One example of this is alignment information in
@code{b.out}. There is nowhere in an @code{a.out} format file to store
alignment information on the contained data, so when a file is linked
from @code{b.out} and an @code{a.out} image is produced, alignment
information will not propagate to the output file. (The linker will
still use the alignment information internally, so the link is performed
correctly).
Another example is COFF section names. COFF files may contain an
unlimited number of sections, each one with a textual section name. If
the target of the link is a format which does not have many sections (e.g.,
@code{a.out}) or has sections without names (e.g., the Oasys format), the
link cannot be done simply. You can circumvent this problem by
describing the desired input-to-output section mapping with the linker command
language.
@emph{Information can be lost during canonicalization.} The BFD
internal canonical form of the external formats is not exhaustive; there
are structures in input formats for which there is no direct
representation internally. This means that the BFD back ends
cannot maintain all possible data richness through the transformation
between external to internal and back to external formats.
This limitation is only a problem when an application reads one
format and writes another. Each BFD back end is responsible for
maintaining as much data as possible, and the internal BFD
canonical form has structures which are opaque to the BFD core,
and exported only to the back ends. When a file is read in one format,
the canonical form is generated for BFD and the application. At the
same time, the back end saves away any information which may otherwise
be lost. If the data is then written back in the same format, the back
end routine will be able to use the canonical form provided by the
BFD core as well as the information it prepared earlier. Since
there is a great deal of commonality between back ends,
there is no information lost when
linking or copying big endian COFF to little endian COFF, or @code{a.out} to
@code{b.out}. When a mixture of formats is linked, the information is
only lost from the files whose format differs from the destination.
@node Canonical format
@subsection The BFD canonical object-file format
The greatest potential for loss of information occurs when there is the least
overlap between the information provided by the source format, that
stored by the canonical format, and that needed by the
destination format. A brief description of the canonical form may help
you understand which kinds of data you can count on preserving across
conversions.
@cindex BFD canonical format
@cindex internal object-file format
@table @emph
@item files
Information stored on a per-file basis includes target machine
architecture, particular implementation format type, a demand pageable
bit, and a write protected bit. Information like Unix magic numbers is
not stored here---only the magic numbers' meaning, so a @code{ZMAGIC}
file would have both the demand pageable bit and the write protected
text bit set. The byte order of the target is stored on a per-file
basis, so that big- and little-endian object files may be used with one
another.
@item sections
Each section in the input file contains the name of the section, the
section's original address in the object file, size and alignment
information, various flags, and pointers into other BFD data
structures.
@item symbols
Each symbol contains a pointer to the information for the object file
which originally defined it, its name, its value, and various flag
bits. When a BFD back end reads in a symbol table, it relocates all
symbols to make them relative to the base of the section where they were
defined. Doing this ensures that each symbol points to its containing
section. Each symbol also has a varying amount of hidden private data
for the BFD back end. Since the symbol points to the original file, the
private data format for that symbol is accessible. @code{ld} can
operate on a collection of symbols of wildly different formats without
problems.
Normal global and simple local symbols are maintained on output, so an
output file (no matter its format) will retain symbols pointing to
functions and to global, static, and common variables. Some symbol
information is not worth retaining; in @code{a.out}, type information is
stored in the symbol table as long symbol names. This information would
be useless to most COFF debuggers; the linker has command line switches
to allow users to throw it away.
There is one word of type information within the symbol, so if the
format supports symbol type information within symbols (for example, COFF,
IEEE, Oasys) and the type is simple enough to fit within one word
(nearly everything but aggregates), the information will be preserved.
@item relocation level
Each canonical BFD relocation record contains a pointer to the symbol to
relocate to, the offset of the data to relocate, the section the data
is in, and a pointer to a relocation type descriptor. Relocation is
performed by passing messages through the relocation type
descriptor and the symbol pointer. Therefore, relocations can be performed
on output data using a relocation method that is only available in one of the
input formats. For instance, Oasys provides a byte relocation format.
A relocation record requesting this relocation type would point
indirectly to a routine to perform this, so the relocation may be
performed on a byte being written to a 68k COFF file, even though 68k COFF
has no such relocation type.
@item line numbers
Object formats can contain, for debugging purposes, some form of mapping
between symbols, source line numbers, and addresses in the output file.
These addresses have to be relocated along with the symbol information.
Each symbol with an associated list of line number records points to the
first record of the list. The head of a line number list consists of a
pointer to the symbol, which allows finding out the address of the
function whose line number is being described. The rest of the list is
made up of pairs: offsets into the section and line numbers. Any format
which can simply derive this information can pass it successfully
between formats (COFF, IEEE and Oasys).
@end table

View File

@ -0,0 +1,95 @@
@section File caching
The file caching mechanism is embedded within BFD and allows
the application to open as many BFDs as it wants without
regard to the underlying operating system's file descriptor
limit (often as low as 20 open files). The module in
@code{cache.c} maintains a least recently used list of
@code{BFD_CACHE_MAX_OPEN} files, and exports the name
@code{bfd_cache_lookup}, which runs around and makes sure that
the required BFD is open. If not, then it chooses a file to
close, closes it and opens the one wanted, returning its file
handle.
@*
@findex BFD_CACHE_MAX_OPEN macro
@subsubsection @code{BFD_CACHE_MAX_OPEN macro}
@strong{Description}@*
The maximum number of files which the cache will keep open at
one time.
@example
#define BFD_CACHE_MAX_OPEN 10
@end example
@*
@findex bfd_last_cache
@subsubsection @code{bfd_last_cache}
@strong{Synopsis}
@example
extern bfd *bfd_last_cache;
@end example
@strong{Description}@*
Zero, or a pointer to the topmost BFD on the chain. This is
used by the @code{bfd_cache_lookup} macro in @file{libbfd.h} to
determine when it can avoid a function call.
@*
@findex bfd_cache_lookup
@subsubsection @code{bfd_cache_lookup}
@strong{Description}@*
Check to see if the required BFD is the same as the last one
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;
otherwise, it has to perform the complicated lookup function.
@example
#define bfd_cache_lookup(x) \
((x)==bfd_last_cache? \
(FILE*)(bfd_last_cache->iostream): \
bfd_cache_lookup_worker(x))
@end example
@*
@findex bfd_cache_init
@subsubsection @code{bfd_cache_init}
@strong{Synopsis}
@example
boolean bfd_cache_init (bfd *abfd);
@end example
@strong{Description}@*
Add a newly opened BFD to the cache.
@*
@findex bfd_cache_close
@subsubsection @code{bfd_cache_close}
@strong{Synopsis}
@example
boolean bfd_cache_close (bfd *abfd);
@end example
@strong{Description}@*
Remove the BFD @var{abfd} from the cache. If the attached file is open,
then close it too.
@*
@strong{Returns}@*
@code{false} is returned if closing the file fails, @code{true} is
returned if all is well.
@*
@findex bfd_open_file
@subsubsection @code{bfd_open_file}
@strong{Synopsis}
@example
FILE* bfd_open_file(bfd *abfd);
@end example
@strong{Description}@*
Call the OS to open a file for @var{abfd}. Return the @code{FILE *}
(possibly @code{NULL}) that results from this operation. Set up the
BFD so that future accesses know the file is open. If the @code{FILE *}
returned is @code{NULL}, then it won't have been put in the
cache, so it won't have to be removed from it.
@*
@findex bfd_cache_lookup_worker
@subsubsection @code{bfd_cache_lookup_worker}
@strong{Synopsis}
@example
FILE *bfd_cache_lookup_worker(bfd *abfd);
@end example
@strong{Description}@*
Called when the macro @code{bfd_cache_lookup} fails to find a
quick answer. Find a file descriptor for @var{abfd}. If
necessary, it open it. If there are already more than
@code{BFD_CACHE_MAX_OPEN} files open, it tries to close one first, to
avoid running out of file descriptors.
@*

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,627 @@
@section coff backends
BFD supports a number of different flavours of coff format.
The major differences between formats are the sizes and
alignments of fields in structures on disk, and the occasional
extra field.
Coff in all its varieties is implemented with a few common
files and a number of implementation specific files. For
example, The 88k bcs coff format is implemented in the file
@file{coff-m88k.c}. This file @code{#include}s
@file{coff/m88k.h} which defines the external structure of the
coff format for the 88k, and @file{coff/internal.h} which
defines the internal structure. @file{coff-m88k.c} also
defines the relocations used by the 88k format
@xref{Relocations}.
The Intel i960 processor version of coff is implemented in
@file{coff-i960.c}. This file has the same structure as
@file{coff-m88k.c}, except that it includes @file{coff/i960.h}
rather than @file{coff-m88k.h}.
@*
@subsection Porting to a new version of coff
The recommended method is to select from the existing
implementations the version of coff which is most like the one
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.
Copy @file{i386coff.c} to @file{foocoff.c}, copy
@file{../include/coff/i386.h} to @file{../include/coff/foo.h},
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
structures in @file{../include/coff/foo.h} so that they match
what you need. You will probably also have to add
@code{#ifdef}s to the code in @file{coff/internal.h} and
@file{coffcode.h} if your version of coff is too wild.
You can verify that your new BFD backend works quite simply by
building @file{objdump} from the @file{binutils} directory,
and making sure that its version of what's going on and your
host system's idea (assuming it has the pretty standard coff
dump utility, usually called @code{att-dump} or just
@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
next release, and you won't have to keep integrating it.
@*
@subsection How the coff backend works
@*
@subsubsection File layout
The Coff backend is split into generic routines that are
applicable to any Coff target and routines that are specific
to a particular target. The target-specific routines are
further split into ones which are basically the same for all
Coff targets except that they use the external symbol format
or use different values for certain constants.
The generic routines are in @file{coffgen.c}. These routines
work for any Coff target. They use some hooks into the target
specific code; the hooks are in a @code{bfd_coff_backend_data}
structure, one of which exists for each target.
The essentially similar target-specific routines are in
@file{coffcode.h}. This header file includes executable C code.
The various Coff targets first include the appropriate Coff
header file, make any special defines that are needed, and
then include @file{coffcode.h}.
Some of the Coff targets then also have additional routines in
the target source file itself.
For example, @file{coff-i960.c} includes
@file{coff/internal.h} and @file{coff/i960.h}. It then
defines a few constants, such as @code{I960}, and includes
@file{coffcode.h}. Since the i960 has complex relocation
types, @file{coff-i960.c} also includes some code to
manipulate the i960 relocs. This code is not in
@file{coffcode.h} because it would not be used by any other
target.
@*
@subsubsection Bit twiddling
Each flavour of coff supported in BFD has its own header file
describing the external layout of the structures. There is also
an internal description of the coff layout, in
@file{coff/internal.h}. A major function of the
coff backend is swapping the bytes and twiddling the bits to
translate the external form of the structures into the normal
internal form. This is all performed in the
@code{bfd_swap}_@i{thing}_@i{direction} routines. Some
elements are different sizes between different versions of
coff; it is the duty of the coff version specific include file
to override the definitions of various packing routines in
@file{coffcode.h}. E.g., the size of line number entry in coff is
sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
@code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
correct one. No doubt, some day someone will find a version of
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}.
Three of the bit twiddling routines are exported to
@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
and @code{coff_swap_linno_in}. @code{GDB} reads the symbol
table on its own, but uses BFD to fix things up. More of the
bit twiddlers are exported for @code{gas};
@code{coff_swap_aux_out}, @code{coff_swap_sym_out},
@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
of all the symbol table and reloc drudgery itself, thereby
saving the internal BFD overhead, but uses BFD to swap things
on the way out, making cross ports much safer. Doing so also
allows BFD (and thus the linker) to use the same header files
as @code{gas}, which makes one avenue to disaster disappear.
@*
@subsubsection Symbol reading
The simple canonical form for symbols used by BFD is not rich
enough to keep all the information available in a coff symbol
table. The back end gets around this problem by keeping the original
symbol table around, "behind the scenes".
When a symbol table is requested (through a call to
@code{bfd_canonicalize_symtab}), a request gets through to
@code{coff_get_normalized_symtab}. This reads the symbol table from
the coff file and swaps all the structures inside into the
internal form. It also fixes up all the pointers in the table
(represented in the file by offsets from the first symbol in
the table) into physical pointers to elements in the new
internal table. This involves some work since the meanings of
fields change depending upon context: a field that is a
pointer to another structure in the symbol table at one moment
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
(@code{C_FILE} symbols) are modified so that the internal
string points to the value in the auxent (the real filename)
rather than the normal text associated with the symbol
(@code{".file"}).
At this time the symbol names are moved around. Coff stores
all symbols less than nine characters long physically
within the symbol table; longer strings are kept at the end of
the file in the string table. This pass moves all strings
into memory and replaces them with pointers to the strings.
The symbol table is massaged once again, this time to create
the canonical table used by the BFD application. Each symbol
is inspected in turn, and a decision made (using the
@code{sclass} field) about the various flags to set in the
@code{asymbol}. @xref{Symbols}. The generated canonical table
shares strings with the hidden internal symbol table.
Any linenumbers are read from the coff file too, and attached
to the symbols which own the functions the linenumbers belong to.
@*
@subsubsection Symbol writing
Writing a symbol to a coff file which didn't come from a coff
file will lose any debugging information. The @code{asymbol}
structure remembers the BFD from which the symbol was taken, and on
output the back end makes sure that the same destination target as
source target is present.
When the symbols have come from a coff file then all the
debugging information is preserved.
Symbol tables are provided for writing to the back end in a
vector of pointers to pointers. This allows applications like
the linker to accumulate and output large symbol tables
without having to do too much byte copying.
This function runs through the provided symbol table and
patches each symbol marked as a file place holder
(@code{C_FILE}) to point to the next file place holder in the
list. It also marks each @code{offset} field in the list with
the offset from the first symbol of the current symbol.
Another function of this procedure is to turn the canonical
value form of BFD into the form used by coff. Internally, BFD
expects symbol values to be offsets from a section base; so a
symbol physically at 0x120, but in a section starting at
0x100, would have the value 0x20. Coff expects symbols to
contain their final value, so symbols have their values
changed at this point to reflect their sum with their owning
section. This transformation uses the
@code{output_section} field of the @code{asymbol}'s
@code{asection} @xref{Sections}.
@itemize @bullet
@item
@code{coff_mangle_symbols}
@end itemize
This routine runs though the provided symbol table and uses
the offsets generated by the previous pass and the pointers
generated when the symbol table was read in to create the
structured hierachy required by coff. It changes each pointer
to a symbol into the index into the symbol table of the asymbol.
@itemize @bullet
@item
@code{coff_write_symbols}
@end itemize
This routine runs through the symbol table and patches up the
symbols from their internal form into the coff way, calls the
bit twiddlers, and writes out the table to the file.
@*
@findex coff_symbol_type
@subsubsection @code{coff_symbol_type}
@strong{Description}@*
The hidden information for an @code{asymbol} is described in a
@code{combined_entry_type}:
@*
.
@example
typedef struct coff_ptr_struct
@{
/* Remembers the offset from the first symbol in the file for
this symbol. Generated by coff_renumber_symbols. */
unsigned int offset;
/* Should the value of this symbol be renumbered. Used for
XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. */
unsigned int fix_value : 1;
/* Should the tag field of this symbol be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_tag : 1;
/* Should the endidx field of this symbol be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_end : 1;
/* Should the x_csect.x_scnlen field be renumbered.
Created by coff_pointerize_aux. */
unsigned int fix_scnlen : 1;
/* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
index into the line number entries. Set by
coff_slurp_symbol_table. */
unsigned int fix_line : 1;
/* The container for the symbol structure as read and translated
from the file. */
union @{
union internal_auxent auxent;
struct internal_syment syment;
@} u;
@} combined_entry_type;
/* Each canonical asymbol really looks like this: */
typedef struct coff_symbol_struct
@{
/* The actual symbol which the rest of BFD works with */
asymbol symbol;
/* A pointer to the hidden information for this symbol */
combined_entry_type *native;
/* A pointer to the linenumber information for this symbol */
struct lineno_cache_entry *lineno;
/* Have the line numbers been relocated yet ? */
boolean done_lineno;
@} coff_symbol_type;
@end example
@findex bfd_coff_backend_data
@subsubsection @code{bfd_coff_backend_data}
Special entry points for gdb to swap in coff symbol table parts:
@example
typedef struct
@{
void (*_bfd_coff_swap_aux_in) PARAMS ((
bfd *abfd,
PTR ext,
int type,
int class,
int indaux,
int numaux,
PTR in));
void (*_bfd_coff_swap_sym_in) PARAMS ((
bfd *abfd ,
PTR ext,
PTR in));
void (*_bfd_coff_swap_lineno_in) PARAMS ((
bfd *abfd,
PTR ext,
PTR in));
@end example
Special entry points for gas to swap out coff parts:
@example
unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
bfd *abfd,
PTR in,
int type,
int class,
int indaux,
int numaux,
PTR ext));
unsigned int (*_bfd_coff_swap_sym_out) PARAMS ((
bfd *abfd,
PTR in,
PTR ext));
unsigned int (*_bfd_coff_swap_lineno_out) PARAMS ((
bfd *abfd,
PTR in,
PTR ext));
unsigned int (*_bfd_coff_swap_reloc_out) PARAMS ((
bfd *abfd,
PTR src,
PTR dst));
unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS ((
bfd *abfd,
PTR in,
PTR out));
unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS ((
bfd *abfd,
PTR in,
PTR out));
unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS ((
bfd *abfd,
PTR in,
PTR out));
@end example
Special entry points for generic COFF routines to call target
dependent COFF routines:
@example
unsigned int _bfd_filhsz;
unsigned int _bfd_aoutsz;
unsigned int _bfd_scnhsz;
unsigned int _bfd_symesz;
unsigned int _bfd_auxesz;
unsigned int _bfd_relsz;
unsigned int _bfd_linesz;
boolean _bfd_coff_long_filenames;
boolean _bfd_coff_long_section_names;
unsigned int _bfd_coff_default_section_alignment_power;
void (*_bfd_coff_swap_filehdr_in) PARAMS ((
bfd *abfd,
PTR ext,
PTR in));
void (*_bfd_coff_swap_aouthdr_in) PARAMS ((
bfd *abfd,
PTR ext,
PTR in));
void (*_bfd_coff_swap_scnhdr_in) PARAMS ((
bfd *abfd,
PTR ext,
PTR in));
void (*_bfd_coff_swap_reloc_in) PARAMS ((
bfd *abfd,
PTR ext,
PTR in));
boolean (*_bfd_coff_bad_format_hook) PARAMS ((
bfd *abfd,
PTR internal_filehdr));
boolean (*_bfd_coff_set_arch_mach_hook) PARAMS ((
bfd *abfd,
PTR internal_filehdr));
PTR (*_bfd_coff_mkobject_hook) PARAMS ((
bfd *abfd,
PTR internal_filehdr,
PTR internal_aouthdr));
flagword (*_bfd_styp_to_sec_flags_hook) PARAMS ((
bfd *abfd,
PTR internal_scnhdr,
const char *name));
void (*_bfd_set_alignment_hook) PARAMS ((
bfd *abfd,
asection *sec,
PTR internal_scnhdr));
boolean (*_bfd_coff_slurp_symbol_table) PARAMS ((
bfd *abfd));
boolean (*_bfd_coff_symname_in_debug) PARAMS ((
bfd *abfd,
struct internal_syment *sym));
boolean (*_bfd_coff_pointerize_aux_hook) PARAMS ((
bfd *abfd,
combined_entry_type *table_base,
combined_entry_type *symbol,
unsigned int indaux,
combined_entry_type *aux));
boolean (*_bfd_coff_print_aux) PARAMS ((
bfd *abfd,
FILE *file,
combined_entry_type *table_base,
combined_entry_type *symbol,
combined_entry_type *aux,
unsigned int indaux));
void (*_bfd_coff_reloc16_extra_cases) PARAMS ((
bfd *abfd,
struct bfd_link_info *link_info,
struct bfd_link_order *link_order,
arelent *reloc,
bfd_byte *data,
unsigned int *src_ptr,
unsigned int *dst_ptr));
int (*_bfd_coff_reloc16_estimate) PARAMS ((
bfd *abfd,
asection *input_section,
arelent *r,
unsigned int shrink,
struct bfd_link_info *link_info));
boolean (*_bfd_coff_sym_is_global) PARAMS ((
bfd *abfd,
struct internal_syment *));
boolean (*_bfd_coff_compute_section_file_positions) PARAMS ((
bfd *abfd));
boolean (*_bfd_coff_start_final_link) PARAMS ((
bfd *output_bfd,
struct bfd_link_info *info));
boolean (*_bfd_coff_relocate_section) PARAMS ((
bfd *output_bfd,
struct bfd_link_info *info,
bfd *input_bfd,
asection *input_section,
bfd_byte *contents,
struct internal_reloc *relocs,
struct internal_syment *syms,
asection **sections));
reloc_howto_type *(*_bfd_coff_rtype_to_howto) PARAMS ((
bfd *abfd,
asection *sec,
struct internal_reloc *rel,
struct coff_link_hash_entry *h,
struct internal_syment *sym,
bfd_vma *addendp));
boolean (*_bfd_coff_adjust_symndx) PARAMS ((
bfd *obfd,
struct bfd_link_info *info,
bfd *ibfd,
asection *sec,
struct internal_reloc *reloc,
boolean *adjustedp));
boolean (*_bfd_coff_link_add_one_symbol) PARAMS ((
struct bfd_link_info *info,
bfd *abfd,
const char *name,
flagword flags,
asection *section,
bfd_vma value,
const char *string,
boolean copy,
boolean collect,
struct bfd_link_hash_entry **hashp));
@} bfd_coff_backend_data;
#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
#define bfd_coff_swap_sym_in(a,e,i) \
((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
#define bfd_coff_swap_lineno_in(a,e,i) \
((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
#define bfd_coff_swap_reloc_out(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
#define bfd_coff_swap_lineno_out(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
#define bfd_coff_swap_sym_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
#define bfd_coff_swap_filehdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
#define bfd_coff_long_filenames(abfd) (coff_backend_info (abfd)->_bfd_coff_long_filenames)
#define bfd_coff_long_section_names(abfd) \
(coff_backend_info (abfd)->_bfd_coff_long_section_names)
#define bfd_coff_default_section_alignment_power(abfd) \
(coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
#define bfd_coff_swap_filehdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
#define bfd_coff_swap_reloc_in(abfd, i, o) \
((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
#define bfd_coff_bad_format_hook(abfd, filehdr) \
((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name)\
((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook) (abfd, scnhdr, name))
#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
#define bfd_coff_slurp_symbol_table(abfd)\
((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
#define bfd_coff_symname_in_debug(abfd, sym)\
((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
((coff_backend_info (abfd)->_bfd_coff_print_aux)\
(abfd, file, base, symbol, aux, indaux))
#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\
((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
(abfd, section, reloc, shrink, link_info))
#define bfd_coff_sym_is_global(abfd, sym)\
((coff_backend_info (abfd)->_bfd_coff_sym_is_global)\
(abfd, sym))
#define bfd_coff_compute_section_file_positions(abfd)\
((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
(abfd))
#define bfd_coff_start_final_link(obfd, info)\
((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
(obfd, info))
#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
(obfd, info, ibfd, o, con, rel, isyms, secs))
#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
(abfd, sec, rel, h, sym, addendp))
#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
(obfd, info, ibfd, sec, rel, adjustedp))
#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\
((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
(info, abfd, name, flags, section, value, string, cp, coll, hashp))
@end example
@subsubsection Writing relocations
To write relocations, the back end steps though the
canonical relocation table and create an
@code{internal_reloc}. The symbol index to use is removed from
the @code{offset} field in the symbol table supplied. The
address comes directly from the sum of the section base
address and the relocation offset; the type is dug directly
from the howto field. Then the @code{internal_reloc} is
swapped into the shape of an @code{external_reloc} and written
out to disk.
@*
@subsubsection Reading linenumbers
Creating the linenumber table is done by reading in the entire
coff linenumber table, and creating another table for internal use.
A coff linenumber table is structured so that each function
is marked as having a line number of 0. Each line within the
function is an offset from the first line in the function. The
base of the line number information for the table is stored in
the symbol associated with the function.
The information is copied from the external to the internal
table, and each symbol which marks a function is marked by
pointing its...
How does this work ?
@*
@subsubsection Reading relocations
Coff relocations are easily transformed into the internal BFD form
(@code{arelent}).
Reading a coff relocation table is done in the following stages:
@itemize @bullet
@item
Read the entire coff relocation table into memory.
@item
Process each relocation in turn; first swap it from the
external to the internal form.
@item
Turn the symbol referenced in the relocation's symbol index
into a pointer into the canonical symbol table.
This table is the same as the one returned by a call to
@code{bfd_canonicalize_symtab}. The back end will call that
routine and save the result if a canonicalization hasn't been done.
@item
The reloc index is turned into a pointer to a howto
structure, in a back end specific way. For instance, the 386
and 960 use the @code{r_type} to directly produce an index
into a howto table vector; the 88k subtracts a number from the
@code{r_type} field and creates an addend field.
@end itemize
@*

View File

@ -0,0 +1,38 @@
@section Core files
@*
@strong{Description}@*
These are functions pertaining to core files.
@*
@findex bfd_core_file_failing_command
@subsubsection @code{bfd_core_file_failing_command}
@strong{Synopsis}
@example
CONST char *bfd_core_file_failing_command(bfd *abfd);
@end example
@strong{Description}@*
Return a read-only string explaining which program was running
when it failed and produced the core file @var{abfd}.
@*
@findex bfd_core_file_failing_signal
@subsubsection @code{bfd_core_file_failing_signal}
@strong{Synopsis}
@example
int bfd_core_file_failing_signal(bfd *abfd);
@end example
@strong{Description}@*
Returns the signal number which caused the core dump which
generated the file the BFD @var{abfd} is attached to.
@*
@findex core_file_matches_executable_p
@subsubsection @code{core_file_matches_executable_p}
@strong{Synopsis}
@example
boolean core_file_matches_executable_p
(bfd *core_bfd, bfd *exec_bfd);
@end example
@strong{Description}@*
Return @code{true} if the core file attached to @var{core_bfd}
was generated by a run of the executable file attached to
@var{exec_bfd}, @code{false} otherwise.
@*

View File

@ -0,0 +1,158 @@
: DOCDD
skip_past_newline
get_stuff_in_command kill_bogus_lines catstr
;
: ENDDD
skip_past_newline
;
: EXAMPLE
skip_past_newline
get_stuff_in_command kill_bogus_lines do_fancy_stuff translatecomments
courierize catstr
;
: INODE
"@node " catstr skip_past_newline copy_past_newline catstr
;
: CODE_FRAGMENT
EXAMPLE
;
: COMMENT
skip_past_newline
get_stuff_in_command
drop
;
: SYNOPSIS
skip_past_newline
"@strong{Synopsis}\n" catstr
"@example\n" catstr
get_stuff_in_command
kill_bogus_lines
indent
catstr
"@end example\n" catstr
;
: func
"@findex " - a
skip_past_newline
copy_past_newline
dup - a x x
"@subsubsection @code{" - a x x b
swap
remchar
"}\n" - a x b x c
catstr catstr catstr catstr catstr
;
: FUNCTION
"@findex " - a
skip_past_newline
copy_past_newline
dup - a x x
"@subsubsection @code{" - a x x b
swap
remchar
"}\n" - a x b x c
catstr catstr catstr catstr catstr
;
: bodytext
get_stuff_in_command
bulletize
kill_bogus_lines
do_fancy_stuff
courierize
catstr
"@*\n" catstr
;
: asection
skip_past_newline
catstr
copy_past_newline
do_fancy_stuff catstr
bodytext
;
: SECTION
"@section " asection ;
: SUBSECTION
"@subsection " asection ;
: SUBSUBSECTION
"@subsubsection " asection ;
: subhead
skip_past_newline
bodytext
;
: DESCRIPTION
"@strong{Description}@*\n" catstr subhead ;
: RETURNS
"@strong{Returns}@*\n" catstr subhead ;
: INTERNAL_FUNCTION
func ;
: INTERNAL_DEFINITION
func ;
: INTERNAL
func ;
: TYPEDEF
FUNCTION ;
: SENUM
skip_past_newline
"Here are the possible values for @code{enum "
copy_past_newline remchar catstr
"}:\n\n" catstr catstr
;
: ENUM
skip_past_newline
"@deffn {} "
copy_past_newline catstr catstr
;
: ENUMX
skip_past_newline
"@deffnx {} "
copy_past_newline catstr
catstr
;
: ENUMEQ
skip_past_newline
"@deffn {} "
copy_past_newline catstr catstr
skip_past_newline
;
: ENUMEQX
skip_past_newline
"@deffnx {} "
copy_past_newline catstr
catstr
skip_past_newline
;
: ENUMDOC
skip_past_newline
get_stuff_in_command
strip_trailing_newlines
catstr
"\n@end deffn\n" catstr
;

View File

@ -0,0 +1,22 @@
@section ELF backends
BFD support for ELF formats is being worked on.
Currently, the best supported back ends are for sparc and i386
(running svr4 or Solaris 2).
Documentation of the internals of the support code still needs
to be written. The code is changing quickly enough that we
haven't bothered yet.
@*
@findex bfd_elf_find_section
@subsubsection @code{bfd_elf_find_section}
@strong{Synopsis}
@example
struct elf_internal_shdr *bfd_elf_find_section (bfd *abfd, char *name);
@end example
@strong{Description}@*
Helper functions for GDB to locate the string tables.
Since BFD hides string tables from callers, GDB needs to use an
internal hook to find them. Sun's .stabstr, in particular,
isn't even pointed to by the .stab section, so ordinary
mechanisms wouldn't work to find it, even if we had some.
@*

View File

View File

@ -0,0 +1,108 @@
@section File formats
A format is a BFD concept of high level file contents type. The
formats supported by BFD are:
@itemize @bullet
@item
@code{bfd_object}
@end itemize
The BFD may contain data, symbols, relocations and debug info.
@itemize @bullet
@item
@code{bfd_archive}
@end itemize
The BFD contains other BFDs and an optional index.
@itemize @bullet
@item
@code{bfd_core}
@end itemize
The BFD contains the result of an executable core dump.
@*
@findex bfd_check_format
@subsubsection @code{bfd_check_format}
@strong{Synopsis}
@example
boolean bfd_check_format(bfd *abfd, bfd_format format);
@end example
@strong{Description}@*
Verify if the file attached to the BFD @var{abfd} is compatible
with the format @var{format} (i.e., one of @code{bfd_object},
@code{bfd_archive} or @code{bfd_core}).
If the BFD has been set to a specific target before the
call, only the named target and format combination is
checked. If the target has not been set, or has been set to
@code{default}, then all the known target backends is
interrogated to determine a match. If the default target
matches, it is used. If not, exactly one target must recognize
the file, or an error results.
The function returns @code{true} on success, otherwise @code{false}
with one of the following error codes:
@itemize @bullet
@item
@code{bfd_error_invalid_operation} -
if @code{format} is not one of @code{bfd_object}, @code{bfd_archive} or
@code{bfd_core}.
@item
@code{bfd_error_system_call} -
if an error occured during a read - even some file mismatches
can cause bfd_error_system_calls.
@item
@code{file_not_recognised} -
none of the backends recognised the file format.
@item
@code{bfd_error_file_ambiguously_recognized} -
more than one backend recognised the file format.
@end itemize
@*
@findex bfd_check_format_matches
@subsubsection @code{bfd_check_format_matches}
@strong{Synopsis}
@example
boolean bfd_check_format_matches(bfd *abfd, bfd_format format, char ***matching);
@end example
@strong{Description}@*
Like @code{bfd_check_format}, except when it returns false with
@code{bfd_errno} set to @code{bfd_error_file_ambiguously_recognized}. In that
case, if @var{matching} is not NULL, it will be filled in with
a NULL-terminated list of the names of the formats that matched,
allocated with @code{malloc}.
Then the user may choose a format and try again.
When done with the list that @var{matching} points to, the caller
should free it.
@*
@findex bfd_set_format
@subsubsection @code{bfd_set_format}
@strong{Synopsis}
@example
boolean bfd_set_format(bfd *abfd, bfd_format format);
@end example
@strong{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.
@*
@findex bfd_format_string
@subsubsection @code{bfd_format_string}
@strong{Synopsis}
@example
CONST char *bfd_format_string(bfd_format format);
@end example
@strong{Description}@*
Return a pointer to a const string
@code{invalid}, @code{object}, @code{archive}, @code{core}, or @code{unknown},
depending upon the value of @var{format}.
@*

View File

@ -0,0 +1,244 @@
@section Hash Tables
@cindex Hash tables
BFD provides a simple set of hash table functions. Routines
are provided to initialize a hash table, to free a hash table,
to look up a string in a hash table and optionally create an
entry for it, and to traverse a hash table. There is
currently no routine to delete an string from a hash table.
The basic hash table does not permit any data to be stored
with a string. However, a hash table is designed to present a
base class from which other types of hash tables may be
derived. These derived types may store additional information
with the string. Hash tables were implemented in this way,
rather than simply providing a data pointer in a hash table
entry, because they were designed for use by the linker back
ends. The linker may create thousands of hash table entries,
and the overhead of allocating private data and storing and
following pointers becomes noticeable.
The basic hash table code is in @code{hash.c}.
@menu
* Creating and Freeing a Hash Table::
* Looking Up or Entering a String::
* Traversing a Hash Table::
* Deriving a New Hash Table Type::
@end menu
@*
@node Creating and Freeing a Hash Table, Looking Up or Entering a String, Hash Tables, Hash Tables
@subsection Creating and freeing a hash table
@findex bfd_hash_table_init
@findex bfd_hash_table_init_n
To create a hash table, create an instance of a @code{struct
bfd_hash_table} (defined in @code{bfd.h}) and call
@code{bfd_hash_table_init} (if you know approximately how many
entries you will need, the function @code{bfd_hash_table_init_n},
which takes a @var{size} argument, may be used).
@code{bfd_hash_table_init} returns @code{false} if some sort of
error occurs.
@findex bfd_hash_newfunc
The function @code{bfd_hash_table_init} take as an argument a
function to use to create new entries. For a basic hash
table, use the function @code{bfd_hash_newfunc}. @xref{Deriving
a New Hash Table Type} for why you would want to use a
different value for this argument.
@findex bfd_hash_allocate
@code{bfd_hash_table_init} will create an objalloc which will be
used to allocate new entries. You may allocate memory on this
objalloc using @code{bfd_hash_allocate}.
@findex bfd_hash_table_free
Use @code{bfd_hash_table_free} to free up all the memory that has
been allocated for a hash table. This will not free up the
@code{struct bfd_hash_table} itself, which you must provide.
@*
@node Looking Up or Entering a String, Traversing a Hash Table, Creating and Freeing a Hash Table, Hash Tables
@subsection Looking up or entering a string
@findex bfd_hash_lookup
The function @code{bfd_hash_lookup} is used both to look up a
string in the hash table and to create a new entry.
If the @var{create} argument is @code{false}, @code{bfd_hash_lookup}
will look up a string. If the string is found, it will
returns a pointer to a @code{struct bfd_hash_entry}. If the
string is not found in the table @code{bfd_hash_lookup} will
return @code{NULL}. You should not modify any of the fields in
the returns @code{struct bfd_hash_entry}.
If the @var{create} argument is @code{true}, the string will be
entered into the hash table if it is not already there.
Either way a pointer to a @code{struct bfd_hash_entry} will be
returned, either to the existing structure or to a newly
created one. In this case, a @code{NULL} return means that an
error occurred.
If the @var{create} argument is @code{true}, and a new entry is
created, the @var{copy} argument is used to decide whether to
copy the string onto the hash table objalloc or not. If
@var{copy} is passed as @code{false}, you must be careful not to
deallocate or modify the string as long as the hash table
exists.
@*
@node Traversing a Hash Table, Deriving a New Hash Table Type, Looking Up or Entering a String, Hash Tables
@subsection Traversing a hash table
@findex bfd_hash_traverse
The function @code{bfd_hash_traverse} may be used to traverse a
hash table, calling a function on each element. The traversal
is done in a random order.
@code{bfd_hash_traverse} takes as arguments a function and a
generic @code{void *} pointer. The function is called with a
hash table entry (a @code{struct bfd_hash_entry *}) and the
generic pointer passed to @code{bfd_hash_traverse}. The function
must return a @code{boolean} value, which indicates whether to
continue traversing the hash table. If the function returns
@code{false}, @code{bfd_hash_traverse} will stop the traversal and
return immediately.
@*
@node Deriving a New Hash Table Type, , Traversing a Hash Table, Hash Tables
@subsection Deriving a new hash table type
Many uses of hash tables want to store additional information
which each entry in the hash table. Some also find it
convenient to store additional information with the hash table
itself. This may be done using a derived hash table.
Since C is not an object oriented language, creating a derived
hash table requires sticking together some boilerplate
routines with a few differences specific to the type of hash
table you want to create.
An example of a derived hash table is the linker hash table.
The structures for this are defined in @code{bfdlink.h}. The
functions are in @code{linker.c}.
You may also derive a hash table from an already derived hash
table. For example, the a.out linker backend code uses a hash
table derived from the linker hash table.
@menu
* Define the Derived Structures::
* Write the Derived Creation Routine::
* Write Other Derived Routines::
@end menu
@*
@node Define the Derived Structures, Write the Derived Creation Routine, Deriving a New Hash Table Type, Deriving a New Hash Table Type
@subsubsection Define the derived structures
You must define a structure for an entry in the hash table,
and a structure for the hash table itself.
The first field in the structure for an entry in the hash
table must be of the type used for an entry in the hash table
you are deriving from. If you are deriving from a basic hash
table this is @code{struct bfd_hash_entry}, which is defined in
@code{bfd.h}. The first field in the structure for the hash
table itself must be of the type of the hash table you are
deriving from itself. If you are deriving from a basic hash
table, this is @code{struct bfd_hash_table}.
For example, the linker hash table defines @code{struct
bfd_link_hash_entry} (in @code{bfdlink.h}). The first field,
@code{root}, is of type @code{struct bfd_hash_entry}. Similarly,
the first field in @code{struct bfd_link_hash_table}, @code{table},
is of type @code{struct bfd_hash_table}.
@*
@node Write the Derived Creation Routine, Write Other Derived Routines, Define the Derived Structures, Deriving a New Hash Table Type
@subsubsection Write the derived creation routine
You must write a routine which will create and initialize an
entry in the hash table. This routine is passed as the
function argument to @code{bfd_hash_table_init}.
In order to permit other hash tables to be derived from the
hash table you are creating, this routine must be written in a
standard way.
The first argument to the creation routine is a pointer to a
hash table entry. This may be @code{NULL}, in which case the
routine should allocate the right amount of space. Otherwise
the space has already been allocated by a hash table type
derived from this one.
After allocating space, the creation routine must call the
creation routine of the hash table type it is derived from,
passing in a pointer to the space it just allocated. This
will initialize any fields used by the base hash table.
Finally the creation routine must initialize any local fields
for the new hash table type.
Here is a boilerplate example of a creation routine.
@var{function_name} is the name of the routine.
@var{entry_type} is the type of an entry in the hash table you
are creating. @var{base_newfunc} is the name of the creation
routine of the hash table type your hash table is derived
from.
@*
.struct bfd_hash_entry *
@example
@var{function_name} (entry, table, string)
struct bfd_hash_entry *entry;
struct bfd_hash_table *table;
const char *string;
@{
struct @var{entry_type} *ret = (@var{entry_type} *) entry;
/* Allocate the structure if it has not already been allocated by a
derived class. */
if (ret == (@var{entry_type} *) NULL)
@{
ret = ((@var{entry_type} *)
bfd_hash_allocate (table, sizeof (@var{entry_type})));
if (ret == (@var{entry_type} *) NULL)
return NULL;
@}
/* Call the allocation method of the base class. */
ret = ((@var{entry_type} *)
@var{base_newfunc} ((struct bfd_hash_entry *) ret, table, string));
/* Initialize the local fields here. */
return (struct bfd_hash_entry *) ret;
@}
@end example
@strong{Description}@*
The creation routine for the linker hash table, which is in
@code{linker.c}, looks just like this example.
@var{function_name} is @code{_bfd_link_hash_newfunc}.
@var{entry_type} is @code{struct bfd_link_hash_entry}.
@var{base_newfunc} is @code{bfd_hash_newfunc}, the creation
routine for a basic hash table.
@code{_bfd_link_hash_newfunc} also initializes the local fields
in a linker hash table entry: @code{type}, @code{written} and
@code{next}.
@*
@node Write Other Derived Routines, , Write the Derived Creation Routine, Deriving a New Hash Table Type
@subsubsection Write other derived routines
You will want to write other routines for your new hash table,
as well.
You will want an initialization routine which calls the
initialization routine of the hash table you are deriving from
and initializes any other local fields. For the linker hash
table, this is @code{_bfd_link_hash_table_init} in @code{linker.c}.
You will want a lookup routine which calls the lookup routine
of the hash table you are deriving from and casts the result.
The linker hash table uses @code{bfd_link_hash_lookup} in
@code{linker.c} (this actually takes an additional argument which
it uses to decide how to return the looked up value).
You may want a traversal routine. This should just call the
traversal routine of the hash table you are deriving from with
appropriate casts. The linker hash table uses
@code{bfd_link_hash_traverse} in @code{linker.c}.
These routines may simply be defined as macros. For example,
the a.out backend linker hash table, which is derived from the
linker hash table, uses macros for the lookup and traversal
routines. These are @code{aout_link_hash_lookup} and
@code{aout_link_hash_traverse} in aoutx.h.
@*

View File

@ -0,0 +1,13 @@
@section Initialization
These are the functions that handle initializing a BFD.
@*
@findex bfd_init
@subsubsection @code{bfd_init}
@strong{Synopsis}
@example
void bfd_init(void);
@end example
@strong{Description}@*
This routine must be called before any other BFD function to
initialize magical internal data structures.
@*

View File

@ -0,0 +1,142 @@
@section Internal functions
@*
@strong{Description}@*
These routines are used within BFD.
They are not intended for export, but are documented here for
completeness.
@*
@findex bfd_write_bigendian_4byte_int
@subsubsection @code{bfd_write_bigendian_4byte_int}
@strong{Synopsis}
@example
void bfd_write_bigendian_4byte_int(bfd *abfd, int i);
@end example
@strong{Description}@*
Write a 4 byte integer @var{i} to the output BFD @var{abfd}, in big
endian order regardless of what else is going on. This is useful in
archives.
@*
@findex bfd_put_size
@subsubsection @code{bfd_put_size}
@findex bfd_get_size
@subsubsection @code{bfd_get_size}
@strong{Description}@*
These macros as used for reading and writing raw data in
sections; each access (except for bytes) is vectored through
the target format of the BFD and mangled accordingly. The
mangling performs any necessary endian translations and
removes alignment restrictions. Note that types accepted and
returned by these macros are identical so they can be swapped
around in macros---for example, @file{libaout.h} defines @code{GET_WORD}
to either @code{bfd_get_32} or @code{bfd_get_64}.
In the put routines, @var{val} must be a @code{bfd_vma}. If we are on a
system without prototypes, the caller is responsible for making
sure that is true, with a cast if necessary. We don't cast
them in the macro definitions because that would prevent @code{lint}
or @code{gcc -Wall} from detecting sins such as passing a pointer.
To detect calling these with less than a @code{bfd_vma}, use
@code{gcc -Wconversion} on a host with 64 bit @code{bfd_vma}'s.
@example
/* Byte swapping macros for user section data. */
#define bfd_put_8(abfd, val, ptr) \
(*((unsigned char *)(ptr)) = (unsigned char)(val))
#define bfd_put_signed_8 \
bfd_put_8
#define bfd_get_8(abfd, ptr) \
(*(unsigned char *)(ptr))
#define bfd_get_signed_8(abfd, ptr) \
((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
#define bfd_put_16(abfd, val, ptr) \
BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
#define bfd_put_signed_16 \
bfd_put_16
#define bfd_get_16(abfd, ptr) \
BFD_SEND(abfd, bfd_getx16, (ptr))
#define bfd_get_signed_16(abfd, ptr) \
BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
#define bfd_put_32(abfd, val, ptr) \
BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
#define bfd_put_signed_32 \
bfd_put_32
#define bfd_get_32(abfd, ptr) \
BFD_SEND(abfd, bfd_getx32, (ptr))
#define bfd_get_signed_32(abfd, ptr) \
BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
#define bfd_put_64(abfd, val, ptr) \
BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
#define bfd_put_signed_64 \
bfd_put_64
#define bfd_get_64(abfd, ptr) \
BFD_SEND(abfd, bfd_getx64, (ptr))
#define bfd_get_signed_64(abfd, ptr) \
BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
@end example
@*
@findex bfd_h_put_size
@subsubsection @code{bfd_h_put_size}
@strong{Description}@*
These macros have the same function as their @code{bfd_get_x}
bretheren, except that they are used for removing information
for the header records of object files. Believe it or not,
some object files keep their header records in big endian
order and their data in little endian order.
@example
/* Byte swapping macros for file header data. */
#define bfd_h_put_8(abfd, val, ptr) \
bfd_put_8 (abfd, val, ptr)
#define bfd_h_put_signed_8(abfd, val, ptr) \
bfd_put_8 (abfd, val, ptr)
#define bfd_h_get_8(abfd, ptr) \
bfd_get_8 (abfd, ptr)
#define bfd_h_get_signed_8(abfd, ptr) \
bfd_get_signed_8 (abfd, ptr)
#define bfd_h_put_16(abfd, val, ptr) \
BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
#define bfd_h_put_signed_16 \
bfd_h_put_16
#define bfd_h_get_16(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx16,(ptr))
#define bfd_h_get_signed_16(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
#define bfd_h_put_32(abfd, val, ptr) \
BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
#define bfd_h_put_signed_32 \
bfd_h_put_32
#define bfd_h_get_32(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx32,(ptr))
#define bfd_h_get_signed_32(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
#define bfd_h_put_64(abfd, val, ptr) \
BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
#define bfd_h_put_signed_64 \
bfd_h_put_64
#define bfd_h_get_64(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx64,(ptr))
#define bfd_h_get_signed_64(abfd, ptr) \
BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
@end example
@*
@findex bfd_log2
@subsubsection @code{bfd_log2}
@strong{Synopsis}
@example
unsigned int bfd_log2(bfd_vma x);
@end example
@strong{Description}@*
Return the log base 2 of the value supplied, rounded up. E.g., an
@var{x} of 1025 returns 11.
@*

View File

@ -0,0 +1,365 @@
@section Linker Functions
@cindex Linker
The linker uses three special entry points in the BFD target
vector. It is not necessary to write special routines for
these entry points when creating a new BFD back end, since
generic versions are provided. However, writing them can
speed up linking and make it use significantly less runtime
memory.
The first routine creates a hash table used by the other
routines. The second routine adds the symbols from an object
file to the hash table. The third routine takes all the
object files and links them together to create the output
file. These routines are designed so that the linker proper
does not need to know anything about the symbols in the object
files that it is linking. The linker merely arranges the
sections as directed by the linker script and lets BFD handle
the details of symbols and relocs.
The second routine and third routines are passed a pointer to
a @code{struct bfd_link_info} structure (defined in
@code{bfdlink.h}) which holds information relevant to the link,
including the linker hash table (which was created by the
first routine) and a set of callback functions to the linker
proper.
The generic linker routines are in @code{linker.c}, and use the
header file @code{genlink.h}. As of this writing, the only back
ends which have implemented versions of these routines are
a.out (in @code{aoutx.h}) and ECOFF (in @code{ecoff.c}). The a.out
routines are used as examples throughout this section.
@menu
* Creating a Linker Hash Table::
* Adding Symbols to the Hash Table::
* Performing the Final Link::
@end menu
@*
@node Creating a Linker Hash Table, Adding Symbols to the Hash Table, Linker Functions, Linker Functions
@subsection Creating a linker hash table
@cindex _bfd_link_hash_table_create in target vector
@cindex target vector (_bfd_link_hash_table_create)
The linker routines must create a hash table, which must be
derived from @code{struct bfd_link_hash_table} described in
@code{bfdlink.c}. @xref{Hash Tables} for information on how to
create a derived hash table. This entry point is called using
the target vector of the linker output file.
The @code{_bfd_link_hash_table_create} entry point must allocate
and initialize an instance of the desired hash table. If the
back end does not require any additional information to be
stored with the entries in the hash table, the entry point may
simply create a @code{struct bfd_link_hash_table}. Most likely,
however, some additional information will be needed.
For example, with each entry in the hash table the a.out
linker keeps the index the symbol has in the final output file
(this index number is used so that when doing a relocateable
link the symbol index used in the output file can be quickly
filled in when copying over a reloc). The a.out linker code
defines the required structures and functions for a hash table
derived from @code{struct bfd_link_hash_table}. The a.out linker
hash table is created by the function
@code{NAME(aout,link_hash_table_create)}; it simply allocates
space for the hash table, initializes it, and returns a
pointer to it.
When writing the linker routines for a new back end, you will
generally not know exactly which fields will be required until
you have finished. You should simply create a new hash table
which defines no additional fields, and then simply add fields
as they become necessary.
@*
@node Adding Symbols to the Hash Table, Performing the Final Link, Creating a Linker Hash Table, Linker Functions
@subsection Adding symbols to the hash table
@cindex _bfd_link_add_symbols in target vector
@cindex target vector (_bfd_link_add_symbols)
The linker proper will call the @code{_bfd_link_add_symbols}
entry point for each object file or archive which is to be
linked (typically these are the files named on the command
line, but some may also come from the linker script). The
entry point is responsible for examining the file. For an
object file, BFD must add any relevant symbol information to
the hash table. For an archive, BFD must determine which
elements of the archive should be used and adding them to the
link.
The a.out version of this entry point is
@code{NAME(aout,link_add_symbols)}.
@menu
* Differing file formats::
* Adding symbols from an object file::
* Adding symbols from an archive::
@end menu
@*
@node Differing file formats, Adding symbols from an object file, Adding Symbols to the Hash Table, Adding Symbols to the Hash Table
@subsubsection Differing file formats
Normally all the files involved in a link will be of the same
format, but it is also possible to link together different
format object files, and the back end must support that. The
@code{_bfd_link_add_symbols} entry point is called via the target
vector of the file to be added. This has an important
consequence: the function may not assume that the hash table
is the type created by the corresponding
@code{_bfd_link_hash_table_create} vector. All the
@code{_bfd_link_add_symbols} function can assume about the hash
table is that it is derived from @code{struct
bfd_link_hash_table}.
Sometimes the @code{_bfd_link_add_symbols} function must store
some information in the hash table entry to be used by the
@code{_bfd_final_link} function. In such a case the @code{creator}
field of the hash table must be checked to make sure that the
hash table was created by an object file of the same format.
The @code{_bfd_final_link} routine must be prepared to handle a
hash entry without any extra information added by the
@code{_bfd_link_add_symbols} function. A hash entry without
extra information will also occur when the linker script
directs the linker to create a symbol. Note that, regardless
of how a hash table entry is added, all the fields will be
initialized to some sort of null value by the hash table entry
initialization function.
See @code{ecoff_link_add_externals} for an example of how to
check the @code{creator} field before saving information (in this
case, the ECOFF external symbol debugging information) in a
hash table entry.
@*
@node Adding symbols from an object file, Adding symbols from an archive, Differing file formats, Adding Symbols to the Hash Table
@subsubsection Adding symbols from an object file
When the @code{_bfd_link_add_symbols} routine is passed an object
file, it must add all externally visible symbols in that
object file to the hash table. The actual work of adding the
symbol to the hash table is normally handled by the function
@code{_bfd_generic_link_add_one_symbol}. The
@code{_bfd_link_add_symbols} routine is responsible for reading
all the symbols from the object file and passing the correct
information to @code{_bfd_generic_link_add_one_symbol}.
The @code{_bfd_link_add_symbols} routine should not use
@code{bfd_canonicalize_symtab} to read the symbols. The point of
providing this routine is to avoid the overhead of converting
the symbols into generic @code{asymbol} structures.
@findex _bfd_generic_link_add_one_symbol
@code{_bfd_generic_link_add_one_symbol} handles the details of
combining common symbols, warning about multiple definitions,
and so forth. It takes arguments which describe the symbol to
add, notably symbol flags, a section, and an offset. The
symbol flags include such things as @code{BSF_WEAK} or
@code{BSF_INDIRECT}. The section is a section in the object
file, or something like @code{bfd_und_section_ptr} for an undefined
symbol or @code{bfd_com_section_ptr} for a common symbol.
If the @code{_bfd_final_link} routine is also going to need to
read the symbol information, the @code{_bfd_link_add_symbols}
routine should save it somewhere attached to the object file
BFD. However, the information should only be saved if the
@code{keep_memory} field of the @code{info} argument is true, so
that the @code{-no-keep-memory} linker switch is effective.
The a.out function which adds symbols from an object file is
@code{aout_link_add_object_symbols}, and most of the interesting
work is in @code{aout_link_add_symbols}. The latter saves
pointers to the hash tables entries created by
@code{_bfd_generic_link_add_one_symbol} indexed by symbol number,
so that the @code{_bfd_final_link} routine does not have to call
the hash table lookup routine to locate the entry.
@*
@node Adding symbols from an archive, , Adding symbols from an object file, Adding Symbols to the Hash Table
@subsubsection Adding symbols from an archive
When the @code{_bfd_link_add_symbols} routine is passed an
archive, it must look through the symbols defined by the
archive and decide which elements of the archive should be
included in the link. For each such element it must call the
@code{add_archive_element} linker callback, and it must add the
symbols from the object file to the linker hash table.
@findex _bfd_generic_link_add_archive_symbols
In most cases the work of looking through the symbols in the
archive should be done by the
@code{_bfd_generic_link_add_archive_symbols} function. This
function builds a hash table from the archive symbol table and
looks through the list of undefined symbols to see which
elements should be included.
@code{_bfd_generic_link_add_archive_symbols} is passed a function
to call to make the final decision about adding an archive
element to the link and to do the actual work of adding the
symbols to the linker hash table.
The function passed to
@code{_bfd_generic_link_add_archive_symbols} must read the
symbols of the archive element and decide whether the archive
element should be included in the link. If the element is to
be included, the @code{add_archive_element} linker callback
routine must be called with the element as an argument, and
the elements symbols must be added to the linker hash table
just as though the element had itself been passed to the
@code{_bfd_link_add_symbols} function.
When the a.out @code{_bfd_link_add_symbols} function receives an
archive, it calls @code{_bfd_generic_link_add_archive_symbols}
passing @code{aout_link_check_archive_element} as the function
argument. @code{aout_link_check_archive_element} calls
@code{aout_link_check_ar_symbols}. If the latter decides to add
the element (an element is only added if it provides a real,
non-common, definition for a previously undefined or common
symbol) it calls the @code{add_archive_element} callback and then
@code{aout_link_check_archive_element} calls
@code{aout_link_add_symbols} to actually add the symbols to the
linker hash table.
The ECOFF back end is unusual in that it does not normally
call @code{_bfd_generic_link_add_archive_symbols}, because ECOFF
archives already contain a hash table of symbols. The ECOFF
back end searches the archive itself to avoid the overhead of
creating a new hash table.
@*
@node Performing the Final Link, , Adding Symbols to the Hash Table, Linker Functions
@subsection Performing the final link
@cindex _bfd_link_final_link in target vector
@cindex target vector (_bfd_final_link)
When all the input files have been processed, the linker calls
the @code{_bfd_final_link} entry point of the output BFD. This
routine is responsible for producing the final output file,
which has several aspects. It must relocate the contents of
the input sections and copy the data into the output sections.
It must build an output symbol table including any local
symbols from the input files and the global symbols from the
hash table. When producing relocateable output, it must
modify the input relocs and write them into the output file.
There may also be object format dependent work to be done.
The linker will also call the @code{write_object_contents} entry
point when the BFD is closed. The two entry points must work
together in order to produce the correct output file.
The details of how this works are inevitably dependent upon
the specific object file format. The a.out
@code{_bfd_final_link} routine is @code{NAME(aout,final_link)}.
@menu
* Information provided by the linker::
* Relocating the section contents::
* Writing the symbol table::
@end menu
@*
@node Information provided by the linker, Relocating the section contents, Performing the Final Link, Performing the Final Link
@subsubsection Information provided by the linker
Before the linker calls the @code{_bfd_final_link} entry point,
it sets up some data structures for the function to use.
The @code{input_bfds} field of the @code{bfd_link_info} structure
will point to a list of all the input files included in the
link. These files are linked through the @code{link_next} field
of the @code{bfd} structure.
Each section in the output file will have a list of
@code{link_order} structures attached to the @code{link_order_head}
field (the @code{link_order} structure is defined in
@code{bfdlink.h}). These structures describe how to create the
contents of the output section in terms of the contents of
various input sections, fill constants, and, eventually, other
types of information. They also describe relocs that must be
created by the BFD backend, but do not correspond to any input
file; this is used to support -Ur, which builds constructors
while generating a relocateable object file.
@*
@node Relocating the section contents, Writing the symbol table, Information provided by the linker, Performing the Final Link
@subsubsection Relocating the section contents
The @code{_bfd_final_link} function should look through the
@code{link_order} structures attached to each section of the
output file. Each @code{link_order} structure should either be
handled specially, or it should be passed to the function
@code{_bfd_default_link_order} which will do the right thing
(@code{_bfd_default_link_order} is defined in @code{linker.c}).
For efficiency, a @code{link_order} of type
@code{bfd_indirect_link_order} whose associated section belongs
to a BFD of the same format as the output BFD must be handled
specially. This type of @code{link_order} describes part of an
output section in terms of a section belonging to one of the
input files. The @code{_bfd_final_link} function should read the
contents of the section and any associated relocs, apply the
relocs to the section contents, and write out the modified
section contents. If performing a relocateable link, the
relocs themselves must also be modified and written out.
@findex _bfd_relocate_contents
@findex _bfd_final_link_relocate
The functions @code{_bfd_relocate_contents} and
@code{_bfd_final_link_relocate} provide some general support for
performing the actual relocations, notably overflow checking.
Their arguments include information about the symbol the
relocation is against and a @code{reloc_howto_type} argument
which describes the relocation to perform. These functions
are defined in @code{reloc.c}.
The a.out function which handles reading, relocating, and
writing section contents is @code{aout_link_input_section}. The
actual relocation is done in @code{aout_link_input_section_std}
and @code{aout_link_input_section_ext}.
@*
@node Writing the symbol table, , Relocating the section contents, Performing the Final Link
@subsubsection Writing the symbol table
The @code{_bfd_final_link} function must gather all the symbols
in the input files and write them out. It must also write out
all the symbols in the global hash table. This must be
controlled by the @code{strip} and @code{discard} fields of the
@code{bfd_link_info} structure.
The local symbols of the input files will not have been
entered into the linker hash table. The @code{_bfd_final_link}
routine must consider each input file and include the symbols
in the output file. It may be convenient to do this when
looking through the @code{link_order} structures, or it may be
done by stepping through the @code{input_bfds} list.
The @code{_bfd_final_link} routine must also traverse the global
hash table to gather all the externally visible symbols. It
is possible that most of the externally visible symbols may be
written out when considering the symbols of each input file,
but it is still necessary to traverse the hash table since the
linker script may have defined some symbols that are not in
any of the input files.
The @code{strip} field of the @code{bfd_link_info} structure
controls which symbols are written out. The possible values
are listed in @code{bfdlink.h}. If the value is @code{strip_some},
then the @code{keep_hash} field of the @code{bfd_link_info}
structure is a hash table of symbols to keep; each symbol
should be looked up in this hash table, and only symbols which
are present should be included in the output file.
If the @code{strip} field of the @code{bfd_link_info} structure
permits local symbols to be written out, the @code{discard} field
is used to further controls which local symbols are included
in the output file. If the value is @code{discard_l}, then all
local symbols which begin with a certain prefix are discarded;
this is controlled by the @code{bfd_is_local_label_name} entry point.
The a.out backend handles symbols by calling
@code{aout_link_write_symbols} on each input BFD and then
traversing the global hash table with the function
@code{aout_link_write_other_symbol}. It builds a string table
while writing out the symbols, which is written to the output
file at the end of @code{NAME(aout,final_link)}.
@*
@findex bfd_link_split_section
@subsubsection @code{bfd_link_split_section}
@strong{Synopsis}
@example
boolean bfd_link_split_section(bfd *abfd, asection *sec);
@end example
@strong{Description}@*
Return nonzero if @var{sec} should be split during a
reloceatable or final link.
@example
#define bfd_link_split_section(abfd, sec) \
BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
@end example
@*

View File

@ -0,0 +1,128 @@
@section Opening and closing BFDs
@*
@findex bfd_openr
@subsubsection @code{bfd_openr}
@strong{Synopsis}
@example
bfd *bfd_openr(CONST char *filename, CONST char *target);
@end example
@strong{Description}@*
Open the file @var{filename} (using @code{fopen}) with the target
@var{target}. Return a pointer to the created BFD.
Calls @code{bfd_find_target}, so @var{target} is interpreted as by
that function.
If @code{NULL} is returned then an error has occured. Possible errors
are @code{bfd_error_no_memory}, @code{bfd_error_invalid_target} or @code{system_call} error.
@*
@findex bfd_fdopenr
@subsubsection @code{bfd_fdopenr}
@strong{Synopsis}
@example
bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
@end example
@strong{Description}@*
@code{bfd_fdopenr} is to @code{bfd_fopenr} much like @code{fdopen} is to @code{fopen}.
It opens a BFD on a file already described by the @var{fd}
supplied.
When the file is later @code{bfd_close}d, the file descriptor will be closed.
If the caller desires that this file descriptor be cached by BFD
(opened as needed, closed as needed to free descriptors for
other opens), with the supplied @var{fd} used as an initial
file descriptor (but subject to closure at any time), call
bfd_set_cacheable(bfd, 1) on the returned BFD. The default is to
assume no cacheing; the file descriptor will remain open until
@code{bfd_close}, and will not be affected by BFD operations on other
files.
Possible errors are @code{bfd_error_no_memory}, @code{bfd_error_invalid_target} and @code{bfd_error_system_call}.
@*
@findex bfd_openstreamr
@subsubsection @code{bfd_openstreamr}
@strong{Synopsis}
@example
bfd *bfd_openstreamr(const char *, const char *, PTR);
@end example
@strong{Description}@*
Open a BFD for read access on an existing stdio stream. When
the BFD is passed to @code{bfd_close}, the stream will be closed.
@*
@findex bfd_openw
@subsubsection @code{bfd_openw}
@strong{Synopsis}
@example
bfd *bfd_openw(CONST char *filename, CONST char *target);
@end example
@strong{Description}@*
Create a BFD, associated with file @var{filename}, using the
file format @var{target}, and return a pointer to it.
Possible errors are @code{bfd_error_system_call}, @code{bfd_error_no_memory},
@code{bfd_error_invalid_target}.
@*
@findex bfd_close
@subsubsection @code{bfd_close}
@strong{Synopsis}
@example
boolean bfd_close(bfd *abfd);
@end example
@strong{Description}@*
Close a BFD. If the BFD was open for writing,
then pending operations are completed and the file written out
and closed. If the created file is executable, then
@code{chmod} is called to mark it as such.
All memory attached to the BFD is released.
The file descriptor associated with the BFD is closed (even
if it was passed in to BFD by @code{bfd_fdopenr}).
@*
@strong{Returns}@*
@code{true} is returned if all is ok, otherwise @code{false}.
@*
@findex bfd_close_all_done
@subsubsection @code{bfd_close_all_done}
@strong{Synopsis}
@example
boolean bfd_close_all_done(bfd *);
@end example
@strong{Description}@*
Close a BFD. Differs from @code{bfd_close}
since it does not complete any pending operations. This
routine would be used if the application had just used BFD for
swapping and didn't want to use any of the writing code.
If the created file is executable, then @code{chmod} is called
to mark it as such.
All memory attached to the BFD is released.
@*
@strong{Returns}@*
@code{true} is returned if all is ok, otherwise @code{false}.
@*
@findex bfd_create
@subsubsection @code{bfd_create}
@strong{Synopsis}
@example
bfd *bfd_create(CONST char *filename, bfd *templ);
@end example
@strong{Description}@*
Create a new BFD in the manner of
@code{bfd_openw}, but without opening a file. The new BFD
takes the target from the target used by @var{template}. The
format is always set to @code{bfd_object}.
@*
@findex bfd_alloc
@subsubsection @code{bfd_alloc}
@strong{Synopsis}
@example
PTR bfd_alloc (bfd *abfd, size_t wanted);
@end example
@strong{Description}@*
Allocate a block of @var{wanted} bytes of memory attached to
@code{abfd} and return a pointer to it.
@*

View File

@ -0,0 +1,135 @@
: SYNOPSIS
skip_past_newline
get_stuff_in_command
paramstuff
indent
maybecatstr
;
: ignore
skip_past_newline
get_stuff_in_command
outputdots
maybecatstr
;
: CODE_FRAGMENT
ignore ;
: external
0 internalmode ignore ;
: internal
1 internalmode ignore ;
- input stack { a b } output b if internal, a if external
: ifinternal
"" swap 1 internalmode maybecatstr
swap
"" swap 0 internalmode maybecatstr
catstr
;
- Put note in output string, regardless of internal mode.
: COMMENT
skip_past_newline
get_stuff_in_command
translatecomments
catstr
;
- SENUM enum-type-name
- ENUM enum-name
- ENUMX addl-enum-name
- ENUMDOC doc for preceding enums
- ENDSENUM max-enum-name
: make_enum_header
dup
"enum " swap catstr
" {\n" catstr
swap " _dummy_first_" swap catstr catstr
",\n" catstr
;
: make_string_table_header
dup
"#ifdef _BFD_MAKE_TABLE_" swap catstr swap
"\n\nstatic const char *const " swap catstr catstr
"_names[] = { \"@@uninitialized@@\",\n" catstr
;
: SENUM
skip_past_newline
copy_past_newline
remchar
dup
make_enum_header
swap
make_string_table_header
ifinternal
catstr
get_stuff_in_command catstr
translatecomments ;
: ENDSENUM
skip_past_newline
copy_past_newline strip_trailing_newlines
dup
" " swap catstr " };\n" catstr swap
" \"@@overflow: " swap catstr "@@\",\n};\n#endif\n\n" catstr
ifinternal
catstr
;
: make_enumerator
" " swap catstr
",\n" catstr
;
: make_enumerator_string
" \"" swap catstr
"\",\n" catstr
;
: ENUM
skip_past_newline
copy_past_newline
remchar
dup
make_enumerator
swap
make_enumerator_string
ifinternal
;
: ENUMX ENUM catstr ;
: ENUMEQ
skip_past_newline
"#define "
copy_past_newline remchar
catstr
" "
catstr
copy_past_newline
catstr
"" swap 0 internalmode maybecatstr
;
: ENUMEQX ENUMEQ catstr ;
: ENUMDOC
skip_past_newline
get_stuff_in_command
strip_trailing_newlines
"\n{* " swap catstr " *}\n" catstr
translatecomments
- discard it if we're doing internal mode
"" swap 0 internalmode maybecatstr
swap
catstr catstr
;
: ENDDD external ;
: SECTION ignore ;
: SUBSECTION ignore ;
: SUBSUBSECTION ignore ;
: INTERNAL_DEFINITION internal ;
: DESCRIPTION ignore ;
: FUNCTION external ;
: RETURNS ignore ;
: TYPEDEF external ;
: INTERNAL_FUNCTION internal ;
: INTERNAL internal ;
: INODE ignore ;

View File

@ -0,0 +1,914 @@
@section Relocations
BFD maintains relocations in much the same way it maintains
symbols: they are left alone until required, then read in
en-mass and translated into an internal form. A common
routine @code{bfd_perform_relocation} acts upon the
canonical form to do the fixup.
Relocations are maintained on a per section basis,
while symbols are maintained on a per BFD basis.
All that a back end has to do to fit the BFD interface is to create
a @code{struct reloc_cache_entry} for each relocation
in a particular section, and fill in the right bits of the structures.
@menu
* typedef arelent::
* howto manager::
@end menu
@*
@node typedef arelent, howto manager, Relocations, Relocations
@subsection typedef arelent
This is the structure of a relocation entry:
@*
.
@example
typedef enum bfd_reloc_status
@{
/* No errors detected */
bfd_reloc_ok,
/* The relocation was performed, but there was an overflow. */
bfd_reloc_overflow,
/* The address to relocate was not within the section supplied. */
bfd_reloc_outofrange,
/* Used by special functions */
bfd_reloc_continue,
/* Unsupported relocation size requested. */
bfd_reloc_notsupported,
/* Unused */
bfd_reloc_other,
/* The symbol to relocate against was undefined. */
bfd_reloc_undefined,
/* The relocation was performed, but may not be ok - presently
generated only when linking i960 coff files with i960 b.out
symbols. If this type is returned, the error_message argument
to bfd_perform_relocation will be set. */
bfd_reloc_dangerous
@}
bfd_reloc_status_type;
typedef struct reloc_cache_entry
@{
/* A pointer into the canonical table of pointers */
struct symbol_cache_entry **sym_ptr_ptr;
/* offset in section */
bfd_size_type address;
/* addend for relocation value */
bfd_vma addend;
/* Pointer to how to perform the required relocation */
reloc_howto_type *howto;
@} arelent;
@end example
@strong{Description}@*
Here is a description of each of the fields within an @code{arelent}:
@itemize @bullet
@item
@code{sym_ptr_ptr}
@end itemize
The symbol table pointer points to a pointer to the symbol
associated with the relocation request. It is
the pointer into the table returned by the back end's
@code{get_symtab} action. @xref{Symbols}. The symbol is referenced
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
one pointer. The relocation routine looks in the symbol and
uses the base of the section the symbol is attached to and the
value of the symbol as the initial relocation offset. If the
symbol pointer is zero, then the section provided is looked up.
@itemize @bullet
@item
@code{address}
@end itemize
The @code{address} field gives the offset in bytes from the base of
the section data which owns the relocation record to the first
byte of relocatable information. The actual data relocated
will be relative to this point; for example, a relocation
type which modifies the bottom two bytes of a four byte word
would not touch the first byte pointed to in a big endian
world.
@itemize @bullet
@item
@code{addend}
@end itemize
The @code{addend} is a value provided by the back end to be added (!)
to the relocation offset. Its interpretation is dependent upon
the howto. For example, on the 68k the code:
@example
char foo[];
main()
@{
return foo[0x12345678];
@}
@end example
Could be compiled into:
@example
linkw fp,#-4
moveb @@#12345678,d0
extbl d0
unlk fp
rts
@end example
This could create a reloc pointing to @code{foo}, but leave the
offset in the data, something like:
@example
RELOCATION RECORDS FOR [.text]:
offset type value
00000006 32 _foo
00000000 4e56 fffc ; linkw fp,#-4
00000004 1039 1234 5678 ; moveb @@#12345678,d0
0000000a 49c0 ; extbl d0
0000000c 4e5e ; unlk fp
0000000e 4e75 ; rts
@end example
Using coff and an 88k, some instructions don't have enough
space in them to represent the full address range, and
pointers have to be loaded in two parts. So you'd get something like:
@example
or.u r13,r0,hi16(_foo+0x12345678)
ld.b r2,r13,lo16(_foo+0x12345678)
jmp r1
@end example
This should create two relocs, both pointing to @code{_foo}, and with
0x12340000 in their addend field. The data would consist of:
@example
RELOCATION RECORDS FOR [.text]:
offset type value
00000002 HVRT16 _foo+0x12340000
00000006 LVRT16 _foo+0x12340000
00000000 5da05678 ; or.u r13,r0,0x5678
00000004 1c4d5678 ; ld.b r2,r13,0x5678
00000008 f400c001 ; jmp r1
@end example
The relocation routine digs out the value from the data, adds
it to the addend to get the original offset, and then adds the
value of @code{_foo}. Note that all 32 bits have to be kept around
somewhere, to cope with carry from bit 15 to bit 16.
One further example is the sparc and the a.out format. The
sparc has a similar problem to the 88k, in that some
instructions don't have room for an entire offset, but on the
sparc the parts are created in odd sized lumps. The designers of
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
the reloc. Anything in the data should be ignored.
@example
save %sp,-112,%sp
sethi %hi(_foo+0x12345678),%g2
ldsb [%g2+%lo(_foo+0x12345678)],%i0
ret
restore
@end example
Both relocs contain a pointer to @code{foo}, and the offsets
contain junk.
@example
RELOCATION RECORDS FOR [.text]:
offset type value
00000004 HI22 _foo+0x12345678
00000008 LO10 _foo+0x12345678
00000000 9de3bf90 ; save %sp,-112,%sp
00000004 05000000 ; sethi %hi(_foo+0),%g2
00000008 f048a000 ; ldsb [%g2+%lo(_foo+0)],%i0
0000000c 81c7e008 ; ret
00000010 81e80000 ; restore
@end example
@itemize @bullet
@item
@code{howto}
@end itemize
The @code{howto} field can be imagined as a
relocation instruction. It is a pointer to a structure which
contains information on what to do with all of the other
information in the reloc record and data section. A back end
would normally have a relocation instruction set and turn
relocations into pointers to the correct structure on input -
but it would be possible to create each howto field on demand.
@*
@subsubsection @code{enum complain_overflow}
Indicates what sort of overflow checking should be done when
performing a relocation.
@*
.
@example
enum complain_overflow
@{
/* Do not complain on overflow. */
complain_overflow_dont,
/* Complain if the bitfield overflows, whether it is considered
as signed or unsigned. */
complain_overflow_bitfield,
/* Complain if the value overflows when considered as signed
number. */
complain_overflow_signed,
/* Complain if the value overflows when considered as an
unsigned number. */
complain_overflow_unsigned
@};
@end example
@subsubsection @code{reloc_howto_type}
The @code{reloc_howto_type} is a structure which contains all the
information that libbfd needs to know to tie up a back end's data.
@*
.struct symbol_cache_entry; /* Forward declaration */
@example
struct reloc_howto_struct
@{
/* The type field has mainly a documentary use - the back end can
do what it wants with it, though normally the back end's
external idea of what a reloc number is stored
in this field. For example, a PC relative word relocation
in a coff environment has the type 023 - because that's
what the outside world calls a R_PCRWORD reloc. */
unsigned int type;
/* The value the final relocation is shifted right by. This drops
unwanted data from the relocation. */
unsigned int rightshift;
/* The size of the item to be relocated. This is *not* a
power-of-two measure. To get the number of bytes operated
on by a type of relocation, use bfd_get_reloc_size. */
int size;
/* The number of bits in the item to be relocated. This is used
when doing overflow checking. */
unsigned int bitsize;
/* Notes that the relocation is relative to the location in the
data section of the addend. The relocation function will
subtract from the relocation value the address of the location
being relocated. */
boolean pc_relative;
/* The bit position of the reloc value in the destination.
The relocated value is left shifted by this amount. */
unsigned int bitpos;
/* What type of overflow error should be checked for when
relocating. */
enum complain_overflow complain_on_overflow;
/* If this field is non null, then the supplied function is
called rather than the normal function. This allows really
strange relocation methods to be accomodated (e.g., i960 callj
instructions). */
bfd_reloc_status_type (*special_function)
PARAMS ((bfd *abfd,
arelent *reloc_entry,
struct symbol_cache_entry *symbol,
PTR data,
asection *input_section,
bfd *output_bfd,
char **error_message));
/* The textual name of the relocation type. */
char *name;
/* When performing a partial link, some formats must modify the
relocations rather than the data - this flag signals this.*/
boolean partial_inplace;
/* 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
bit of data which we read and relocated, this would be
0x000000ff. When we have relocs which have an addend, such as
sun4 extended relocs, the value in the offset part of a
relocating field is garbage so we never use it. In this case
the mask would be 0x00000000. */
bfd_vma src_mask;
/* The dst_mask selects which parts of the instruction are replaced
into the instruction. In most cases src_mask == dst_mask,
except in the above special case, where dst_mask would be
0x000000ff, and src_mask would be 0x00000000. */
bfd_vma dst_mask;
/* When some formats create PC relative instructions, they leave
the value of the pc of the place being relocated in the offset
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).
Some formats leave the displacement part of an instruction
empty (e.g., m88k bcs); this flag signals the fact.*/
boolean pcrel_offset;
@};
@end example
@findex The HOWTO Macro
@subsubsection @code{The HOWTO Macro}
@strong{Description}@*
The HOWTO define is horrible and will go away.
@example
#define HOWTO(C, R,S,B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
@{(unsigned)C,R,S,B, P, BI, O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC@}
@end example
@*
@strong{Description}@*
And will be replaced with the totally magic way. But for the
moment, we are compatible, so do it this way.
@example
#define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,complain_overflow_dont,FUNCTION, NAME,false,0,0,IN)
@end example
@*
@strong{Description}@*
Helper routine to turn a symbol into a relocation value.
@example
#define HOWTO_PREPARE(relocation, symbol) \
@{ \
if (symbol != (asymbol *)NULL) @{ \
if (bfd_is_com_section (symbol->section)) @{ \
relocation = 0; \
@} \
else @{ \
relocation = symbol->value; \
@} \
@} \
@}
@end example
@*
@findex bfd_get_reloc_size
@subsubsection @code{bfd_get_reloc_size}
@strong{Synopsis}
@example
int bfd_get_reloc_size (reloc_howto_type *);
@end example
@strong{Description}@*
For a reloc_howto_type that operates on a fixed number of bytes,
this returns the number of bytes operated on.
@*
@findex arelent_chain
@subsubsection @code{arelent_chain}
@strong{Description}@*
How relocs are tied together in an @code{asection}:
@example
typedef struct relent_chain @{
arelent relent;
struct relent_chain *next;
@} arelent_chain;
@end example
@*
@findex bfd_perform_relocation
@subsubsection @code{bfd_perform_relocation}
@strong{Synopsis}
@example
bfd_reloc_status_type
bfd_perform_relocation
(bfd *abfd,
arelent *reloc_entry,
PTR data,
asection *input_section,
bfd *output_bfd,
char **error_message);
@end example
@strong{Description}@*
If @var{output_bfd} is supplied to this function, the
generated image will be relocatable; the relocations are
copied to the output file after they have been changed to
reflect the new state of the world. There are two ways of
reflecting the results of partial linkage in an output file:
by modifying the output data in place, and by modifying the
relocation record. Some native formats (e.g., basic a.out and
basic coff) have no way of specifying an addend in the
relocation type, so the addend has to go in the output data.
This is no big deal since in these formats the output data
slot will always be big enough for the addend. Complex reloc
types with addends were invented to solve just this problem.
The @var{error_message} argument is set to an error message if
this return @code{bfd_reloc_dangerous}.
@*
@findex bfd_install_relocation
@subsubsection @code{bfd_install_relocation}
@strong{Synopsis}
@example
bfd_reloc_status_type
bfd_install_relocation
(bfd *abfd,
arelent *reloc_entry,
PTR data, bfd_vma data_start,
asection *input_section,
char **error_message);
@end example
@strong{Description}@*
This looks remarkably like @code{bfd_perform_relocation}, except it
does not expect that the section contents have been filled in.
I.e., it's suitable for use when creating, rather than applying
a relocation.
For now, this function should be considered reserved for the
assembler.
@*
@node howto manager, , typedef arelent, Relocations
@section The howto manager
When an application wants to create a relocation, but doesn't
know what the target machine might call it, it can find out by
using this bit of code.
@*
@findex bfd_reloc_code_type
@subsubsection @code{bfd_reloc_code_type}
@strong{Description}@*
The insides of a reloc code. The idea is that, eventually, there
will be one enumerator for every type of relocation we ever do.
Pass one of these values to @code{bfd_reloc_type_lookup}, and it'll
return a howto pointer.
This does mean that the application must determine the correct
enumerator value; you can't get a howto pointer from a random set
of attributes.
@*
Here are the possible values for @code{enum bfd_reloc_code_real}:
@deffn {} BFD_RELOC_64
@deffnx {} BFD_RELOC_32
@deffnx {} BFD_RELOC_26
@deffnx {} BFD_RELOC_24
@deffnx {} BFD_RELOC_16
@deffnx {} BFD_RELOC_14
@deffnx {} BFD_RELOC_8
Basic absolute relocations of N bits.
@end deffn
@deffn {} BFD_RELOC_64_PCREL
@deffnx {} BFD_RELOC_32_PCREL
@deffnx {} BFD_RELOC_24_PCREL
@deffnx {} BFD_RELOC_16_PCREL
@deffnx {} BFD_RELOC_12_PCREL
@deffnx {} BFD_RELOC_8_PCREL
PC-relative relocations. Sometimes these are relative to the address
of the relocation itself; sometimes they are relative to the start of
the section containing the relocation. It depends on the specific target.
The 24-bit relocation is used in some Intel 960 configurations.
@end deffn
@deffn {} BFD_RELOC_32_GOT_PCREL
@deffnx {} BFD_RELOC_16_GOT_PCREL
@deffnx {} BFD_RELOC_8_GOT_PCREL
@deffnx {} BFD_RELOC_32_GOTOFF
@deffnx {} BFD_RELOC_16_GOTOFF
@deffnx {} BFD_RELOC_LO16_GOTOFF
@deffnx {} BFD_RELOC_HI16_GOTOFF
@deffnx {} BFD_RELOC_HI16_S_GOTOFF
@deffnx {} BFD_RELOC_8_GOTOFF
@deffnx {} BFD_RELOC_32_PLT_PCREL
@deffnx {} BFD_RELOC_24_PLT_PCREL
@deffnx {} BFD_RELOC_16_PLT_PCREL
@deffnx {} BFD_RELOC_8_PLT_PCREL
@deffnx {} BFD_RELOC_32_PLTOFF
@deffnx {} BFD_RELOC_16_PLTOFF
@deffnx {} BFD_RELOC_LO16_PLTOFF
@deffnx {} BFD_RELOC_HI16_PLTOFF
@deffnx {} BFD_RELOC_HI16_S_PLTOFF
@deffnx {} BFD_RELOC_8_PLTOFF
For ELF.
@end deffn
@deffn {} BFD_RELOC_68K_GLOB_DAT
@deffnx {} BFD_RELOC_68K_JMP_SLOT
@deffnx {} BFD_RELOC_68K_RELATIVE
Relocations used by 68K ELF.
@end deffn
@deffn {} BFD_RELOC_32_BASEREL
@deffnx {} BFD_RELOC_16_BASEREL
@deffnx {} BFD_RELOC_LO16_BASEREL
@deffnx {} BFD_RELOC_HI16_BASEREL
@deffnx {} BFD_RELOC_HI16_S_BASEREL
@deffnx {} BFD_RELOC_8_BASEREL
@deffnx {} BFD_RELOC_RVA
Linkage-table relative.
@end deffn
@deffn {} BFD_RELOC_8_FFnn
Absolute 8-bit relocation, but used to form an address like 0xFFnn.
@end deffn
@deffn {} BFD_RELOC_32_PCREL_S2
@deffnx {} BFD_RELOC_16_PCREL_S2
@deffnx {} BFD_RELOC_23_PCREL_S2
These PC-relative relocations are stored as word displacements --
i.e., byte displacements shifted right two bits. The 30-bit word
displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
SPARC. (SPARC tools generally refer to this as <<WDISP30>>.) The
signed 16-bit displacement is used on the MIPS, and the 23-bit
displacement is used on the Alpha.
@end deffn
@deffn {} BFD_RELOC_HI22
@deffnx {} BFD_RELOC_LO10
High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
the target word. These are used on the SPARC.
@end deffn
@deffn {} BFD_RELOC_GPREL16
@deffnx {} BFD_RELOC_GPREL32
For systems that allocate a Global Pointer register, these are
displacements off that register. These relocation types are
handled specially, because the value the register will have is
decided relatively late.
@end deffn
@deffn {} BFD_RELOC_I960_CALLJ
Reloc types used for i960/b.out.
@end deffn
@deffn {} BFD_RELOC_NONE
@deffnx {} BFD_RELOC_SPARC_WDISP22
@deffnx {} BFD_RELOC_SPARC22
@deffnx {} BFD_RELOC_SPARC13
@deffnx {} BFD_RELOC_SPARC_GOT10
@deffnx {} BFD_RELOC_SPARC_GOT13
@deffnx {} BFD_RELOC_SPARC_GOT22
@deffnx {} BFD_RELOC_SPARC_PC10
@deffnx {} BFD_RELOC_SPARC_PC22
@deffnx {} BFD_RELOC_SPARC_WPLT30
@deffnx {} BFD_RELOC_SPARC_COPY
@deffnx {} BFD_RELOC_SPARC_GLOB_DAT
@deffnx {} BFD_RELOC_SPARC_JMP_SLOT
@deffnx {} BFD_RELOC_SPARC_RELATIVE
@deffnx {} BFD_RELOC_SPARC_UA32
SPARC ELF relocations. There is probably some overlap with other
relocation types already defined.
@end deffn
@deffn {} BFD_RELOC_SPARC_BASE13
@deffnx {} BFD_RELOC_SPARC_BASE22
I think these are specific to SPARC a.out (e.g., Sun 4).
@end deffn
@deffn {} BFD_RELOC_SPARC_64
@deffnx {} BFD_RELOC_SPARC_10
@deffnx {} BFD_RELOC_SPARC_11
@deffnx {} BFD_RELOC_SPARC_OLO10
@deffnx {} BFD_RELOC_SPARC_HH22
@deffnx {} BFD_RELOC_SPARC_HM10
@deffnx {} BFD_RELOC_SPARC_LM22
@deffnx {} BFD_RELOC_SPARC_PC_HH22
@deffnx {} BFD_RELOC_SPARC_PC_HM10
@deffnx {} BFD_RELOC_SPARC_PC_LM22
@deffnx {} BFD_RELOC_SPARC_WDISP16
@deffnx {} BFD_RELOC_SPARC_WDISP19
@deffnx {} BFD_RELOC_SPARC_GLOB_JMP
@deffnx {} BFD_RELOC_SPARC_7
@deffnx {} BFD_RELOC_SPARC_6
@deffnx {} BFD_RELOC_SPARC_5
Some relocations we're using for SPARC V9 -- subject to change.
@end deffn
@deffn {} BFD_RELOC_ALPHA_GPDISP_HI16
Alpha ECOFF and ELF relocations. Some of these treat the symbol or
"addend" in some special way.
For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
writing; when reading, it will be the absolute section symbol. The
addend is the displacement in bytes of the "lda" instruction from
the "ldah" instruction (which is at the address of this reloc).
@end deffn
@deffn {} BFD_RELOC_ALPHA_GPDISP_LO16
For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
with GPDISP_HI16 relocs. The addend is ignored when writing the
relocations out, and is filled in with the file's GP value on
reading, for convenience.
@end deffn
@deffn {} BFD_RELOC_ALPHA_GPDISP
The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
relocation except that there is no accompanying GPDISP_LO16
relocation.
@end deffn
@deffn {} BFD_RELOC_ALPHA_LITERAL
@deffnx {} BFD_RELOC_ALPHA_ELF_LITERAL
@deffnx {} BFD_RELOC_ALPHA_LITUSE
The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
the assembler turns it into a LDQ instruction to load the address of
the symbol, and then fills in a register in the real instruction.
The LITERAL reloc, at the LDQ instruction, refers to the .lita
section symbol. The addend is ignored when writing, but is filled
in with the file's GP value on reading, for convenience, as with the
GPDISP_LO16 reloc.
The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
It should refer to the symbol to be referenced, as with 16_GOTOFF,
but it generates output not based on the position within the .got
section, but relative to the GP value chosen for the file during the
final link stage.
The LITUSE reloc, on the instruction using the loaded address, gives
information to the linker that it might be able to use to optimize
away some literal section references. The symbol is ignored (read
as the absolute section symbol), and the "addend" indicates the type
of instruction using the register:
1 - "memory" fmt insn
2 - byte-manipulation (byte offset reg)
3 - jsr (target of branch)
The GNU linker currently doesn't do any of this optimizing.
@end deffn
@deffn {} BFD_RELOC_ALPHA_HINT
The HINT relocation indicates a value that should be filled into the
"hint" field of a jmp/jsr/ret instruction, for possible branch-
prediction logic which may be provided on some processors.
@end deffn
@deffn {} BFD_RELOC_ALPHA_LINKAGE
The LINKAGE relocation outputs a linkage pair in the object file,
which is filled by the linker.
@end deffn
@deffn {} BFD_RELOC_ALPHA_CODEADDR
The CODEADDR relocation outputs a STO_CA in the object file,
which is filled by the linker.
@end deffn
@deffn {} BFD_RELOC_MIPS_JMP
Bits 27..2 of the relocation address shifted right 2 bits;
simple reloc otherwise.
@end deffn
@deffn {} BFD_RELOC_MIPS16_JMP
The MIPS16 jump instruction.
@end deffn
@deffn {} BFD_RELOC_MIPS16_GPREL
MIPS16 GP relative reloc.
@end deffn
@deffn {} BFD_RELOC_HI16
High 16 bits of 32-bit value; simple reloc.
@end deffn
@deffn {} BFD_RELOC_HI16_S
High 16 bits of 32-bit value but the low 16 bits will be sign
extended and added to form the final result. If the low 16
bits form a negative number, we need to add one to the high value
to compensate for the borrow when the low bits are added.
@end deffn
@deffn {} BFD_RELOC_LO16
Low 16 bits.
@end deffn
@deffn {} BFD_RELOC_PCREL_HI16_S
Like BFD_RELOC_HI16_S, but PC relative.
@end deffn
@deffn {} BFD_RELOC_PCREL_LO16
Like BFD_RELOC_LO16, but PC relative.
@end deffn
@deffn {} BFD_RELOC_MIPS_GPREL
Relocation relative to the global pointer.
@end deffn
@deffn {} BFD_RELOC_MIPS_LITERAL
Relocation against a MIPS literal section.
@end deffn
@deffn {} BFD_RELOC_MIPS_GOT16
@deffnx {} BFD_RELOC_MIPS_CALL16
@deffnx {} BFD_RELOC_MIPS_GPREL32
@deffnx {} BFD_RELOC_MIPS_GOT_HI16
@deffnx {} BFD_RELOC_MIPS_GOT_LO16
@deffnx {} BFD_RELOC_MIPS_CALL_HI16
@deffnx {} BFD_RELOC_MIPS_CALL_LO16
MIPS ELF relocations.
@end deffn
@deffn {} BFD_RELOC_386_GOT32
@deffnx {} BFD_RELOC_386_PLT32
@deffnx {} BFD_RELOC_386_COPY
@deffnx {} BFD_RELOC_386_GLOB_DAT
@deffnx {} BFD_RELOC_386_JUMP_SLOT
@deffnx {} BFD_RELOC_386_RELATIVE
@deffnx {} BFD_RELOC_386_GOTOFF
@deffnx {} BFD_RELOC_386_GOTPC
i386/elf relocations
@end deffn
@deffn {} BFD_RELOC_NS32K_IMM_8
@deffnx {} BFD_RELOC_NS32K_IMM_16
@deffnx {} BFD_RELOC_NS32K_IMM_32
@deffnx {} BFD_RELOC_NS32K_IMM_8_PCREL
@deffnx {} BFD_RELOC_NS32K_IMM_16_PCREL
@deffnx {} BFD_RELOC_NS32K_IMM_32_PCREL
@deffnx {} BFD_RELOC_NS32K_DISP_8
@deffnx {} BFD_RELOC_NS32K_DISP_16
@deffnx {} BFD_RELOC_NS32K_DISP_32
@deffnx {} BFD_RELOC_NS32K_DISP_8_PCREL
@deffnx {} BFD_RELOC_NS32K_DISP_16_PCREL
@deffnx {} BFD_RELOC_NS32K_DISP_32_PCREL
ns32k relocations
@end deffn
@deffn {} BFD_RELOC_PPC_B26
@deffnx {} BFD_RELOC_PPC_BA26
@deffnx {} BFD_RELOC_PPC_TOC16
@deffnx {} BFD_RELOC_PPC_B16
@deffnx {} BFD_RELOC_PPC_B16_BRTAKEN
@deffnx {} BFD_RELOC_PPC_B16_BRNTAKEN
@deffnx {} BFD_RELOC_PPC_BA16
@deffnx {} BFD_RELOC_PPC_BA16_BRTAKEN
@deffnx {} BFD_RELOC_PPC_BA16_BRNTAKEN
@deffnx {} BFD_RELOC_PPC_COPY
@deffnx {} BFD_RELOC_PPC_GLOB_DAT
@deffnx {} BFD_RELOC_PPC_JMP_SLOT
@deffnx {} BFD_RELOC_PPC_RELATIVE
@deffnx {} BFD_RELOC_PPC_LOCAL24PC
@deffnx {} BFD_RELOC_PPC_EMB_NADDR32
@deffnx {} BFD_RELOC_PPC_EMB_NADDR16
@deffnx {} BFD_RELOC_PPC_EMB_NADDR16_LO
@deffnx {} BFD_RELOC_PPC_EMB_NADDR16_HI
@deffnx {} BFD_RELOC_PPC_EMB_NADDR16_HA
@deffnx {} BFD_RELOC_PPC_EMB_SDAI16
@deffnx {} BFD_RELOC_PPC_EMB_SDA2I16
@deffnx {} BFD_RELOC_PPC_EMB_SDA2REL
@deffnx {} BFD_RELOC_PPC_EMB_SDA21
@deffnx {} BFD_RELOC_PPC_EMB_MRKREF
@deffnx {} BFD_RELOC_PPC_EMB_RELSEC16
@deffnx {} BFD_RELOC_PPC_EMB_RELST_LO
@deffnx {} BFD_RELOC_PPC_EMB_RELST_HI
@deffnx {} BFD_RELOC_PPC_EMB_RELST_HA
@deffnx {} BFD_RELOC_PPC_EMB_BIT_FLD
@deffnx {} BFD_RELOC_PPC_EMB_RELSDA
Power(rs6000) and PowerPC relocations.
@end deffn
@deffn {} BFD_RELOC_CTOR
The type of reloc used to build a contructor table - at the moment
probably a 32 bit wide absolute relocation, but the target can choose.
It generally does map to one of the other relocation types.
@end deffn
@deffn {} BFD_RELOC_ARM_PCREL_BRANCH
ARM 26 bit pc-relative branch. The lowest two bits must be zero and are
not stored in the instruction.
@end deffn
@deffn {} BFD_RELOC_ARM_IMMEDIATE
@deffnx {} BFD_RELOC_ARM_OFFSET_IMM
@deffnx {} BFD_RELOC_ARM_SHIFT_IMM
@deffnx {} BFD_RELOC_ARM_SWI
@deffnx {} BFD_RELOC_ARM_MULTI
@deffnx {} BFD_RELOC_ARM_CP_OFF_IMM
@deffnx {} BFD_RELOC_ARM_ADR_IMM
@deffnx {} BFD_RELOC_ARM_LDR_IMM
@deffnx {} BFD_RELOC_ARM_LITERAL
@deffnx {} BFD_RELOC_ARM_IN_POOL
@deffnx {} BFD_RELOC_ARM_OFFSET_IMM8
@deffnx {} BFD_RELOC_ARM_HWLITERAL
@deffnx {} BFD_RELOC_ARM_THUMB_ADD
@deffnx {} BFD_RELOC_ARM_THUMB_IMM
@deffnx {} BFD_RELOC_ARM_THUMB_SHIFT
@deffnx {} BFD_RELOC_ARM_THUMB_OFFSET
These relocs are only used within the ARM assembler. They are not
(at present) written to any object files.
@end deffn
@deffn {} BFD_RELOC_SH_PCDISP8BY2
@deffnx {} BFD_RELOC_SH_PCDISP12BY2
@deffnx {} BFD_RELOC_SH_IMM4
@deffnx {} BFD_RELOC_SH_IMM4BY2
@deffnx {} BFD_RELOC_SH_IMM4BY4
@deffnx {} BFD_RELOC_SH_IMM8
@deffnx {} BFD_RELOC_SH_IMM8BY2
@deffnx {} BFD_RELOC_SH_IMM8BY4
@deffnx {} BFD_RELOC_SH_PCRELIMM8BY2
@deffnx {} BFD_RELOC_SH_PCRELIMM8BY4
@deffnx {} BFD_RELOC_SH_SWITCH16
@deffnx {} BFD_RELOC_SH_SWITCH32
@deffnx {} BFD_RELOC_SH_USES
@deffnx {} BFD_RELOC_SH_COUNT
@deffnx {} BFD_RELOC_SH_ALIGN
@deffnx {} BFD_RELOC_SH_CODE
@deffnx {} BFD_RELOC_SH_DATA
@deffnx {} BFD_RELOC_SH_LABEL
Hitachi SH relocs. Not all of these appear in object files.
@end deffn
@deffn {} BFD_RELOC_D10V_10_PCREL_R
Mitsubishi D10V relocs.
This is a 10-bit reloc with the right 2 bits
assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_D10V_10_PCREL_L
Mitsubishi D10V relocs.
This is a 10-bit reloc with the right 2 bits
assumed to be 0. This is the same as the previous reloc
except it is in the left container, i.e.,
shifted left 15 bits.
@end deffn
@deffn {} BFD_RELOC_D10V_18
This is an 18-bit reloc with the right 2 bits
assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_D10V_18_PCREL
This is an 18-bit reloc with the right 2 bits
assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_M32R_24
Mitsubishi M32R relocs.
This is a 24 bit absolute address.
@end deffn
@deffn {} BFD_RELOC_M32R_10_PCREL
This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_M32R_18_PCREL
This is an 18-bit reloc with the right 2 bits assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_M32R_26_PCREL
This is a 26-bit reloc with the right 2 bits assumed to be 0.
@end deffn
@deffn {} BFD_RELOC_M32R_HI16_ULO
This is a 16-bit reloc containing the high 16 bits of an address
used when the lower 16 bits are treated as unsigned.
@end deffn
@deffn {} BFD_RELOC_M32R_HI16_SLO
This is a 16-bit reloc containing the high 16 bits of an address
used when the lower 16 bits are treated as signed.
@end deffn
@deffn {} BFD_RELOC_M32R_LO16
This is a 16-bit reloc containing the lower 16 bits of an address.
@end deffn
@deffn {} BFD_RELOC_M32R_SDA16
This is a 16-bit reloc containing the small data area offset for use in
add3, load, and store instructions.
@end deffn
@deffn {} BFD_RELOC_MN10300_32_PCREL
This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
instruction.
@end deffn
@deffn {} BFD_RELOC_MN10300_16_PCREL
This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
instruction.
@end deffn
.
@example
typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
@end example
@findex bfd_reloc_type_lookup
@subsubsection @code{bfd_reloc_type_lookup}
@strong{Synopsis}
@example
reloc_howto_type *
bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code);
@end example
@strong{Description}@*
Return a pointer to a howto structure which, when
invoked, will perform the relocation @var{code} on data from the
architecture noted.
@*
@findex bfd_default_reloc_type_lookup
@subsubsection @code{bfd_default_reloc_type_lookup}
@strong{Synopsis}
@example
reloc_howto_type *bfd_default_reloc_type_lookup
(bfd *abfd, bfd_reloc_code_real_type code);
@end example
@strong{Description}@*
Provides a default relocation lookup routine for any architecture.
@*
@findex bfd_get_reloc_code_name
@subsubsection @code{bfd_get_reloc_code_name}
@strong{Synopsis}
@example
const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
@end example
@strong{Description}@*
Provides a printable name for the supplied relocation code.
Useful mainly for printing error messages.
@*
@findex bfd_generic_relax_section
@subsubsection @code{bfd_generic_relax_section}
@strong{Synopsis}
@example
boolean bfd_generic_relax_section
(bfd *abfd,
asection *section,
struct bfd_link_info *,
boolean *);
@end example
@strong{Description}@*
Provides default handling for relaxing for back ends which
don't do relaxing -- i.e., does nothing.
@*
@findex bfd_generic_get_relocated_section_contents
@subsubsection @code{bfd_generic_get_relocated_section_contents}
@strong{Synopsis}
@example
bfd_byte *
bfd_generic_get_relocated_section_contents (bfd *abfd,
struct bfd_link_info *link_info,
struct bfd_link_order *link_order,
bfd_byte *data,
boolean relocateable,
asymbol **symbols);
@end example
@strong{Description}@*
Provides default handling of relocation effort for back ends
which can't be bothered to do it efficiently.
@*

View File

@ -0,0 +1,649 @@
@section Sections
The raw data contained within a BFD is maintained through the
section abstraction. A single BFD may have any number of
sections. It keeps hold of them by pointing to the first;
each one points to the next in the list.
Sections are supported in BFD in @code{section.c}.
@menu
* Section Input::
* Section Output::
* typedef asection::
* section prototypes::
@end menu
@*
@node Section Input, Section Output, Sections, Sections
@subsection Section input
When a BFD is opened for reading, the section structures are
created and attached to the BFD.
Each section has a name which describes the section in the
outside world---for example, @code{a.out} would contain at least
three sections, called @code{.text}, @code{.data} and @code{.bss}.
Names need not be unique; for example a COFF file may have several
sections named @code{.data}.
Sometimes a BFD will contain more than the ``natural'' number of
sections. A back end may attach other sections containing
constructor data, or an application may add a section (using
@code{bfd_make_section}) to the sections attached to an already open
BFD. For example, the linker creates an extra section
@code{COMMON} for each input file's BFD to hold information about
common storage.
The raw data is not necessarily read in when
the section descriptor is created. Some targets may leave the
data in place until a @code{bfd_get_section_contents} call is
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
size of the data. An IEEE-695 file doesn't contain raw data in
sections, but data and relocation expressions intermixed, so
the data area has to be parsed to get out the data and
relocations.
@*
@node Section Output, typedef asection, Section Input, Sections
@subsection Section output
To write a new object style BFD, the various sections to be
written have to be created. They are attached to the BFD in
the same way as input sections; data is written to the
sections using @code{bfd_set_section_contents}.
Any program that creates or combines sections (e.g., the assembler
and linker) must use the @code{asection} fields @code{output_section} and
@code{output_offset} to indicate the file sections to which each
section must be written. (If the section is being created from
scratch, @code{output_section} should probably point to the section
itself and @code{output_offset} should probably be zero.)
The data to be written comes from input sections attached
(via @code{output_section} pointers) to
the output sections. The output section structure can be
considered a filter for the input section: the output section
determines the vma of the output data and the name, but the
input section determines the offset into the output section of
the data to be written.
E.g., to create a section "O", starting at 0x100, 0x123 long,
containing two subsections, "A" at offset 0x0 (i.e., at vma
0x100) and "B" at offset 0x20 (i.e., at vma 0x120) the @code{asection}
structures would look like:
@example
section name "A"
output_offset 0x00
size 0x20
output_section -----------> section name "O"
| vma 0x100
section name "B" | size 0x123
output_offset 0x20 |
size 0x103 |
output_section --------|
@end example
@*
@subsection Link orders
The data within a section is stored in a @dfn{link_order}.
These are much like the fixups in @code{gas}. The link_order
abstraction allows a section to grow and shrink within itself.
A link_order knows how big it is, and which is the next
link_order and where the raw data for it is; it also points to
a list of relocations which apply to it.
The link_order is used by the linker to perform relaxing on
final code. The compiler creates code which is as big as
necessary to make it work without relaxing, and the user can
select whether to relax. Sometimes relaxing takes a lot of
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
a link_order by link_order basis.
@*
@node typedef asection, section prototypes, Section Output, Sections
@subsection typedef asection
Here is the section structure:
@*
.
@example
typedef struct sec
@{
/* The name of the section; the name isn't a copy, the pointer is
the same as that passed to bfd_make_section. */
CONST char *name;
/* Which section is it; 0..nth. */
int index;
/* The next section in the list belonging to the BFD, or NULL. */
struct sec *next;
/* The field flags contains attributes of the section. Some
flags are read in from the object file, and some are
synthesized from other information. */
flagword flags;
#define SEC_NO_FLAGS 0x000
/* Tells the OS to allocate space for this section when loading.
This is clear for a section containing debug information
only. */
#define SEC_ALLOC 0x001
/* Tells the OS to load the section from the file when loading.
This is clear for a .bss section. */
#define SEC_LOAD 0x002
/* The section contains data still to be relocated, so there is
some relocation information too. */
#define SEC_RELOC 0x004
#if 0 /* Obsolete ? */
#define SEC_BALIGN 0x008
#endif
/* A signal to the OS that the section contains read only
data. */
#define SEC_READONLY 0x010
/* The section contains code only. */
#define SEC_CODE 0x020
/* The section contains data only. */
#define SEC_DATA 0x040
/* The section will reside in ROM. */
#define SEC_ROM 0x080
/* The section contains constructor information. This section
type is used by the linker to create lists of constructors and
destructors used by @code{g++}. When a back end sees a symbol
which should be used in a constructor list, it creates a new
section for the type of name (e.g., @code{__CTOR_LIST__}), attaches
the symbol to it, and builds a relocation. To build the lists
of constructors, all the linker has to do is catenate all the
sections called @code{__CTOR_LIST__} and relocate the data
contained within - exactly the operations it would peform on
standard data. */
#define SEC_CONSTRUCTOR 0x100
/* The section is a constuctor, and should be placed at the
end of the text, data, or bss section(?). */
#define SEC_CONSTRUCTOR_TEXT 0x1100
#define SEC_CONSTRUCTOR_DATA 0x2100
#define SEC_CONSTRUCTOR_BSS 0x3100
/* The section has contents - a data section could be
@code{SEC_ALLOC} | @code{SEC_HAS_CONTENTS}; a debug section could be
@code{SEC_HAS_CONTENTS} */
#define SEC_HAS_CONTENTS 0x200
/* An instruction to the linker to not output the section
even if it has information which would normally be written. */
#define SEC_NEVER_LOAD 0x400
/* The section is a COFF shared library section. This flag is
only for the linker. If this type of section appears in
the input file, the linker must copy it to the output file
without changing the vma or size. FIXME: Although this
was originally intended to be general, it really is COFF
specific (and the flag was renamed to indicate this). It
might be cleaner to have some more general mechanism to
allow the back end to control what the linker does with
sections. */
#define SEC_COFF_SHARED_LIBRARY 0x800
/* The section contains common symbols (symbols may be defined
multiple times, the value of a symbol is the amount of
space it requires, and the largest symbol value is the one
used). Most targets have exactly one of these (which we
translate to bfd_com_section_ptr), but ECOFF has two. */
#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
/* The contents of this section are held in memory pointed to
by the contents field. This is checked by
bfd_get_section_contents, and the data is retrieved from
memory if appropriate. */
#define SEC_IN_MEMORY 0x20000
/* The contents of this section are to be excluded by the
linker for executable and shared objects unless those
objects are to be further relocated. */
#define SEC_EXCLUDE 0x40000
/* The contents of this section are to be sorted by the
based on the address specified in the associated symbol
table. */
#define SEC_SORT_ENTRIES 0x80000
/* When linking, duplicate sections of the same name should be
discarded, rather than being combined into a single section as
is usually done. This is similar to how common symbols are
handled. See SEC_LINK_DUPLICATES below. */
#define SEC_LINK_ONCE 0x100000
/* If SEC_LINK_ONCE is set, this bitfield describes how the linker
should handle duplicate sections. */
#define SEC_LINK_DUPLICATES 0x600000
/* This value for SEC_LINK_DUPLICATES means that duplicate
sections with the same name should simply be discarded. */
#define SEC_LINK_DUPLICATES_DISCARD 0x0
/* This value for SEC_LINK_DUPLICATES means that the linker
should warn if there are any duplicate sections, although
it should still only link one copy. */
#define SEC_LINK_DUPLICATES_ONE_ONLY 0x200000
/* This value for SEC_LINK_DUPLICATES means that the linker
should warn if any duplicate sections are a different size. */
#define SEC_LINK_DUPLICATES_SAME_SIZE 0x400000
/* This value for SEC_LINK_DUPLICATES means that the linker
should warn if any duplicate sections contain different
contents. */
#define SEC_LINK_DUPLICATES_SAME_CONTENTS 0x600000
/* This section was created by the linker as part of dynamic
relocation or other arcane processing. It is skipped when
going through the first-pass output, trusting that someone
else up the line will take care of it later. */
#define SEC_LINKER_CREATED 0x800000
/* End of section flags. */
/* Some internal packed boolean fields. */
/* See the vma field. */
unsigned int user_set_vma : 1;
/* Whether relocations have been processed. */
unsigned int reloc_done : 1;
/* A mark flag used by some of the linker backends. */
unsigned int linker_mark : 1;
/* End of internal packed boolean fields. */
/* The virtual memory address of the section - where it will be
at run time. The symbols are relocated against this. The
user_set_vma flag is maintained by bfd; if it's not set, the
backend can assign addresses (for example, in @code{a.out}, where
the default address for @code{.data} is dependent on the specific
target and various flags). */
bfd_vma vma;
/* The load address of the section - where it would be in a
rom image; really only used for writing section header
information. */
bfd_vma lma;
/* The size of the section in bytes, as it will be output.
contains a value even if the section has no contents (e.g., the
size of @code{.bss}). This will be filled in after relocation */
bfd_size_type _cooked_size;
/* The original size on disk of the section, in bytes. Normally this
value is the same as the size, but if some relaxing has
been done, then this value will be bigger. */
bfd_size_type _raw_size;
/* 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
section. E.g., if this was going to start at the 100th byte in
the output section, this value would be 100. */
bfd_vma output_offset;
/* The output section through which to map on output. */
struct sec *output_section;
/* The alignment requirement of the section, as an exponent of 2 -
e.g., 3 aligns to 2^3 (or 8). */
unsigned int alignment_power;
/* If an input section, a pointer to a vector of relocation
records for the data in this section. */
struct reloc_cache_entry *relocation;
/* If an output section, a pointer to a vector of pointers to
relocation records for the data in this section. */
struct reloc_cache_entry **orelocation;
/* The number of relocation records in one of the above */
unsigned reloc_count;
/* Information below is back end specific - and not always used
or updated. */
/* File position of section data */
file_ptr filepos;
/* File position of relocation info */
file_ptr rel_filepos;
/* File position of line data */
file_ptr line_filepos;
/* Pointer to data for applications */
PTR userdata;
/* If the SEC_IN_MEMORY flag is set, this points to the actual
contents. */
unsigned char *contents;
/* Attached line number information */
alent *lineno;
/* Number of line number records */
unsigned int lineno_count;
/* When a section is being output, this value changes as more
linenumbers are written out */
file_ptr moving_line_filepos;
/* What the section number is in the target world */
int target_index;
PTR used_by_bfd;
/* If this is a constructor section then here is a list of the
relocations created to relocate items within it. */
struct relent_chain *constructor_chain;
/* The BFD which owns the section. */
bfd *owner;
/* A symbol which points at this section only */
struct symbol_cache_entry *symbol;
struct symbol_cache_entry **symbol_ptr_ptr;
struct bfd_link_order *link_order_head;
struct bfd_link_order *link_order_tail;
@} asection ;
/* These sections are global, and are managed by BFD. The application
and target back end are not permitted to change the values in
these sections. New code should use the section_ptr macros rather
than referring directly to the const sections. The const sections
may eventually vanish. */
#define BFD_ABS_SECTION_NAME "*ABS*"
#define BFD_UND_SECTION_NAME "*UND*"
#define BFD_COM_SECTION_NAME "*COM*"
#define BFD_IND_SECTION_NAME "*IND*"
/* the absolute section */
extern const asection bfd_abs_section;
#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
/* Pointer to the undefined section */
extern const asection bfd_und_section;
#define bfd_und_section_ptr ((asection *) &bfd_und_section)
#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
/* Pointer to the common section */
extern const asection bfd_com_section;
#define bfd_com_section_ptr ((asection *) &bfd_com_section)
/* Pointer to the indirect section */
extern const asection bfd_ind_section;
#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
extern const struct symbol_cache_entry * const bfd_abs_symbol;
extern const struct symbol_cache_entry * const bfd_com_symbol;
extern const struct symbol_cache_entry * const bfd_und_symbol;
extern const struct symbol_cache_entry * const bfd_ind_symbol;
#define bfd_get_section_size_before_reloc(section) \
(section->reloc_done ? (abort(),1): (section)->_raw_size)
#define bfd_get_section_size_after_reloc(section) \
((section->reloc_done) ? (section)->_cooked_size: (abort(),1))
@end example
@node section prototypes, , typedef asection, Sections
@subsection Section prototypes
These are the functions exported by the section handling part of BFD.
@*
@findex bfd_get_section_by_name
@subsubsection @code{bfd_get_section_by_name}
@strong{Synopsis}
@example
asection *bfd_get_section_by_name(bfd *abfd, CONST char *name);
@end example
@strong{Description}@*
Run through @var{abfd} and return the one of the
@code{asection}s whose name matches @var{name}, otherwise @code{NULL}.
@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 @code{bfd_map_over_sections} and
@code{strcmp} on the name (or better yet, base it on the section flags
or something else) for each section.
@*
@findex bfd_make_section_old_way
@subsubsection @code{bfd_make_section_old_way}
@strong{Synopsis}
@example
asection *bfd_make_section_old_way(bfd *abfd, CONST char *name);
@end example
@strong{Description}@*
Create a new empty section called @var{name}
and attach it to the end of the chain of sections for the
BFD @var{abfd}. An attempt to create a section with a name which
is already in use returns its pointer without changing the
section chain.
It has the funny name since this is the way it used to be
before it was rewritten....
Possible errors are:
@itemize @bullet
@item
@code{bfd_error_invalid_operation} -
If output has already started for this BFD.
@item
@code{bfd_error_no_memory} -
If memory allocation fails.
@end itemize
@*
@findex bfd_make_section_anyway
@subsubsection @code{bfd_make_section_anyway}
@strong{Synopsis}
@example
asection *bfd_make_section_anyway(bfd *abfd, CONST char *name);
@end example
@strong{Description}@*
Create a new empty section called @var{name} and attach it to the end of
the chain of sections for @var{abfd}. Create a new section even if there
is already a section with that name.
Return @code{NULL} and set @code{bfd_error} on error; possible errors are:
@itemize @bullet
@item
@code{bfd_error_invalid_operation} - If output has already started for @var{abfd}.
@item
@code{bfd_error_no_memory} - If memory allocation fails.
@end itemize
@*
@findex bfd_make_section
@subsubsection @code{bfd_make_section}
@strong{Synopsis}
@example
asection *bfd_make_section(bfd *, CONST char *name);
@end example
@strong{Description}@*
Like @code{bfd_make_section_anyway}, but return @code{NULL} (without calling
bfd_set_error ()) without changing the section chain if there is already a
section named @var{name}. If there is an error, return @code{NULL} and set
@code{bfd_error}.
@*
@findex bfd_set_section_flags
@subsubsection @code{bfd_set_section_flags}
@strong{Synopsis}
@example
boolean bfd_set_section_flags(bfd *abfd, asection *sec, flagword flags);
@end example
@strong{Description}@*
Set the attributes of the section @var{sec} in the BFD
@var{abfd} to the value @var{flags}. Return @code{true} on success,
@code{false} on error. Possible error returns are:
@itemize @bullet
@item
@code{bfd_error_invalid_operation} -
The section cannot have one or more of the attributes
requested. For example, a .bss section in @code{a.out} may not
have the @code{SEC_HAS_CONTENTS} field set.
@end itemize
@*
@findex bfd_map_over_sections
@subsubsection @code{bfd_map_over_sections}
@strong{Synopsis}
@example
void bfd_map_over_sections(bfd *abfd,
void (*func)(bfd *abfd,
asection *sect,
PTR obj),
PTR obj);
@end example
@strong{Description}@*
Call the provided function @var{func} for each section
attached to the BFD @var{abfd}, passing @var{obj} as an
argument. The function will be called as if by
@example
func(abfd, the_section, obj);
@end example
This is the prefered method for iterating over sections; an
alternative would be to use a loop:
@example
section *p;
for (p = abfd->sections; p != NULL; p = p->next)
func(abfd, p, ...)
@end example
@*
@findex bfd_set_section_size
@subsubsection @code{bfd_set_section_size}
@strong{Synopsis}
@example
boolean bfd_set_section_size(bfd *abfd, asection *sec, bfd_size_type val);
@end example
@strong{Description}@*
Set @var{sec} to the size @var{val}. If the operation is
ok, then @code{true} is returned, else @code{false}.
Possible error returns:
@itemize @bullet
@item
@code{bfd_error_invalid_operation} -
Writing has started to the BFD, so setting the size is invalid.
@end itemize
@*
@findex bfd_set_section_contents
@subsubsection @code{bfd_set_section_contents}
@strong{Synopsis}
@example
boolean bfd_set_section_contents
(bfd *abfd,
asection *section,
PTR data,
file_ptr offset,
bfd_size_type count);
@end example
@strong{Description}@*
Sets the contents of the section @var{section} in BFD
@var{abfd} to the data starting in memory at @var{data}. The
data is written to the output section starting at offset
@var{offset} for @var{count} bytes.
Normally @code{true} is returned, else @code{false}. Possible error
returns are:
@itemize @bullet
@item
@code{bfd_error_no_contents} -
The output section does not have the @code{SEC_HAS_CONTENTS}
attribute, so nothing can be written to it.
@item
and some more too
@end itemize
This routine is front end to the back end function
@code{_bfd_set_section_contents}.
@*
@findex bfd_get_section_contents
@subsubsection @code{bfd_get_section_contents}
@strong{Synopsis}
@example
boolean bfd_get_section_contents
(bfd *abfd, asection *section, PTR location,
file_ptr offset, bfd_size_type count);
@end example
@strong{Description}@*
Read data from @var{section} in BFD @var{abfd}
into memory starting at @var{location}. The data is read at an
offset of @var{offset} from the start of the input section,
and is read for @var{count} bytes.
If the contents of a constructor with the @code{SEC_CONSTRUCTOR}
flag set are requested or if the section does not have the
@code{SEC_HAS_CONTENTS} flag set, then the @var{location} is filled
with zeroes. If no errors occur, @code{true} is returned, else
@code{false}.
@*
@findex bfd_copy_private_section_data
@subsubsection @code{bfd_copy_private_section_data}
@strong{Synopsis}
@example
boolean bfd_copy_private_section_data(bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
@end example
@strong{Description}@*
Copy private section information from @var{isec} in the BFD
@var{ibfd} to the section @var{osec} in the BFD @var{obfd}.
Return @code{true} on success, @code{false} on error. Possible error
returns are:
@itemize @bullet
@item
@code{bfd_error_no_memory} -
Not enough memory exists to create private data for @var{osec}.
@end itemize
@example
#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
BFD_SEND (obfd, _bfd_copy_private_section_data, \
(ibfd, isection, obfd, osection))
@end example
@*

View File

@ -0,0 +1,407 @@
@section Symbols
BFD tries to maintain as much symbol information as it can when
it moves information from file to file. BFD passes information
to applications though the @code{asymbol} structure. When the
application requests the symbol table, BFD reads the table in
the native form and translates parts of it into the internal
format. To maintain more than the information passed to
applications, some targets keep some information ``behind the
scenes'' in a structure only the particular back end knows
about. For example, the coff back end keeps the original
symbol table structure as well as the canonical structure when
a BFD is read in. On output, the coff back end can reconstruct
the output symbol table so that no information is lost, even
information unique to coff which BFD doesn't know or
understand. If a coff symbol table were read, but were written
through an a.out back end, all the coff specific information
would be lost. The symbol table of a BFD
is not necessarily read in until a canonicalize request is
made. Then the BFD back end fills in a table provided by the
application with pointers to the canonical information. To
output symbols, the application provides BFD with a table of
pointers to pointers to @code{asymbol}s. This allows applications
like the linker to output a symbol as it was read, since the ``behind
the scenes'' information will be still available.
@menu
* Reading Symbols::
* Writing Symbols::
* Mini Symbols::
* typedef asymbol::
* symbol handling functions::
@end menu
@*
@node Reading Symbols, Writing Symbols, Symbols, Symbols
@subsection Reading symbols
There are two stages to reading a symbol table from a BFD:
allocating storage, and the actual reading process. This is an
excerpt from an application which reads the symbol table:
@example
long storage_needed;
asymbol **symbol_table;
long number_of_symbols;
long i;
storage_needed = bfd_get_symtab_upper_bound (abfd);
if (storage_needed < 0)
FAIL
if (storage_needed == 0) @{
return ;
@}
symbol_table = (asymbol **) xmalloc (storage_needed);
...
number_of_symbols =
bfd_canonicalize_symtab (abfd, symbol_table);
if (number_of_symbols < 0)
FAIL
for (i = 0; i < number_of_symbols; i++) @{
process_symbol (symbol_table[i]);
@}
@end example
All storage for the symbols themselves is in an objalloc
connected to the BFD; it is freed when the BFD is closed.
@*
@node Writing Symbols, Mini Symbols, Reading Symbols, Symbols
@subsection Writing symbols
Writing of a symbol table is automatic when a BFD open for
writing is closed. The application attaches a vector of
pointers to pointers to symbols to the BFD being written, and
fills in the symbol count. The close and cleanup code reads
through the table provided and performs all the necessary
operations. The BFD output code must always be provided with an
``owned'' symbol: one which has come from another BFD, or one
which has been created using @code{bfd_make_empty_symbol}. Here is an
example showing the creation of a symbol table with only one element:
@example
#include "bfd.h"
main()
@{
bfd *abfd;
asymbol *ptrs[2];
asymbol *new;
abfd = bfd_openw("foo","a.out-sunos-big");
bfd_set_format(abfd, bfd_object);
new = bfd_make_empty_symbol(abfd);
new->name = "dummy_symbol";
new->section = bfd_make_section_old_way(abfd, ".text");
new->flags = BSF_GLOBAL;
new->value = 0x12345;
ptrs[0] = new;
ptrs[1] = (asymbol *)0;
bfd_set_symtab(abfd, ptrs, 1);
bfd_close(abfd);
@}
./makesym
nm foo
00012345 A dummy_symbol
@end example
Many formats cannot represent arbitary symbol information; for
instance, the @code{a.out} object format does not allow an
arbitary number of sections. A symbol pointing to a section
which is not one of @code{.text}, @code{.data} or @code{.bss} cannot
be described.
@*
@node Mini Symbols, typedef asymbol, Writing Symbols, Symbols
@subsection Mini Symbols
Mini symbols provide read-only access to the symbol table.
They use less memory space, but require more time to access.
They can be useful for tools like nm or objdump, which may
have to handle symbol tables of extremely large executables.
The @code{bfd_read_minisymbols} function will read the symbols
into memory in an internal form. It will return a @code{void *}
pointer to a block of memory, a symbol count, and the size of
each symbol. The pointer is allocated using @code{malloc}, and
should be freed by the caller when it is no longer needed.
The function @code{bfd_minisymbol_to_symbol} will take a pointer
to a minisymbol, and a pointer to a structure returned by
@code{bfd_make_empty_symbol}, and return a @code{asymbol} structure.
The return value may or may not be the same as the value from
@code{bfd_make_empty_symbol} which was passed in.
@*
@node typedef asymbol, symbol handling functions, Mini Symbols, Symbols
@subsection typedef asymbol
An @code{asymbol} has the form:
@*
.
@example
typedef struct symbol_cache_entry
@{
/* A pointer to the BFD which owns the symbol. This information
is necessary so that a back end can work out what additional
information (invisible to the application writer) is carried
with the symbol.
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. */
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. */
CONST char *name;
/* 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;
/* Attributes of a symbol: */
#define BSF_NO_FLAGS 0x00
/* The symbol has local scope; @code{static} in @code{C}. The value
is the offset into the section of the data. */
#define BSF_LOCAL 0x01
/* The symbol has global scope; initialized data in @code{C}. The
value is the offset into the section of the data. */
#define BSF_GLOBAL 0x02
/* The symbol has global scope and is exported. The value is
the offset into the section of the data. */
#define BSF_EXPORT BSF_GLOBAL /* no real difference */
/* A normal C symbol would be one of:
@code{BSF_LOCAL}, @code{BSF_FORT_COMM}, @code{BSF_UNDEFINED} or
@code{BSF_GLOBAL} */
/* The symbol is a debugging record. The value has an arbitary
meaning. */
#define BSF_DEBUGGING 0x08
/* The symbol denotes a function entry point. Used in ELF,
perhaps others someday. */
#define BSF_FUNCTION 0x10
/* Used by the linker. */
#define BSF_KEEP 0x20
#define BSF_KEEP_G 0x40
/* A weak global symbol, overridable without warnings by
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
allocated. */
#define BSF_OLD_COMMON 0x200
/* The default value for common data. */
#define BFD_FORT_COMM_DEFAULT_VALUE 0
/* In some files the type of a symbol sometimes alters its
location in an output file - ie in coff a @code{ISFCN} symbol
which is also @code{C_EXT} symbol appears where it was
declared and not at the end of a section. This bit is set
by the target BFD part to convey this information. */
#define BSF_NOT_AT_END 0x400
/* Signal that the symbol is the label of constructor section. */
#define BSF_CONSTRUCTOR 0x800
/* Signal that the symbol is a warning symbol. The name is a
warning. The name of the next symbol is the one to warn about;
if a reference is made to a symbol with the same name as the next
symbol, a warning is issued by the linker. */
#define BSF_WARNING 0x1000
/* Signal that the symbol is indirect. This symbol is an indirect
pointer to the symbol with the same name as the next symbol. */
#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
/* Symbol is from dynamic linking information. */
#define BSF_DYNAMIC 0x8000
/* The symbol denotes a data object. Used in ELF, and perhaps
others someday. */
#define BSF_OBJECT 0x10000
flagword flags;
/* A pointer to the section to which this symbol is
relative. This will always be non NULL, there are special
sections for undefined and absolute symbols. */
struct sec *section;
/* Back end special data. */
union
@{
PTR p;
bfd_vma i;
@} udata;
@} asymbol;
@end example
@node symbol handling functions, , typedef asymbol, Symbols
@subsection Symbol handling functions
@*
@findex bfd_get_symtab_upper_bound
@subsubsection @code{bfd_get_symtab_upper_bound}
@strong{Description}@*
Return the number of bytes required to store a vector of pointers
to @code{asymbols} for all the symbols in the BFD @var{abfd},
including a terminal NULL pointer. If there are no symbols in
the BFD, then return 0. If an error occurs, return -1.
@example
#define bfd_get_symtab_upper_bound(abfd) \
BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
@end example
@*
@findex bfd_is_local_label
@subsubsection @code{bfd_is_local_label}
@strong{Synopsis}
@example
boolean bfd_is_local_label(bfd *abfd, asymbol *sym);
@end example
@strong{Description}@*
Return true if the given symbol @var{sym} in the BFD @var{abfd} is
a compiler generated local label, else return false.
@*
@findex bfd_is_local_label_name
@subsubsection @code{bfd_is_local_label_name}
@strong{Synopsis}
@example
boolean bfd_is_local_label_name(bfd *abfd, const char *name);
@end example
@strong{Description}@*
Return true if a symbol with the name @var{name} in the BFD
@var{abfd} is a compiler generated local label, else return
false. This just checks whether the name has the form of a
local label.
@example
#define bfd_is_local_label_name(abfd, name) \
BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
@end example
@*
@findex bfd_canonicalize_symtab
@subsubsection @code{bfd_canonicalize_symtab}
@strong{Description}@*
Read the symbols from the BFD @var{abfd}, and fills in
the vector @var{location} with pointers to the symbols and
a trailing NULL.
Return the actual number of symbol pointers, not
including the NULL.
@example
#define bfd_canonicalize_symtab(abfd, location) \
BFD_SEND (abfd, _bfd_canonicalize_symtab,\
(abfd, location))
@end example
@*
@findex bfd_set_symtab
@subsubsection @code{bfd_set_symtab}
@strong{Synopsis}
@example
boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
@end example
@strong{Description}@*
Arrange that when the output BFD @var{abfd} is closed,
the table @var{location} of @var{count} pointers to symbols
will be written.
@*
@findex bfd_print_symbol_vandf
@subsubsection @code{bfd_print_symbol_vandf}
@strong{Synopsis}
@example
void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
@end example
@strong{Description}@*
Print the value and flags of the @var{symbol} supplied to the
stream @var{file}.
@*
@findex bfd_make_empty_symbol
@subsubsection @code{bfd_make_empty_symbol}
@strong{Description}@*
Create a new @code{asymbol} structure for the BFD @var{abfd}
and return a pointer to it.
This routine is necessary because each back end has private
information surrounding the @code{asymbol}. Building your own
@code{asymbol} and pointing to it will not create the private
information, and will cause problems later on.
@example
#define bfd_make_empty_symbol(abfd) \
BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
@end example
@*
@findex bfd_make_debug_symbol
@subsubsection @code{bfd_make_debug_symbol}
@strong{Description}@*
Create a new @code{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.
@example
#define bfd_make_debug_symbol(abfd,ptr,size) \
BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
@end example
@*
@findex bfd_decode_symclass
@subsubsection @code{bfd_decode_symclass}
@strong{Description}@*
Return a character corresponding to the symbol
class of @var{symbol}, or '?' for an unknown class.
@*
@strong{Synopsis}
@example
int bfd_decode_symclass(asymbol *symbol);
@end example
@findex bfd_symbol_info
@subsubsection @code{bfd_symbol_info}
@strong{Description}@*
Fill in the basic info about symbol that nm needs.
Additional info may be added by the back-ends after
calling this function.
@*
@strong{Synopsis}
@example
void bfd_symbol_info(asymbol *symbol, symbol_info *ret);
@end example
@findex bfd_copy_private_symbol_data
@subsubsection @code{bfd_copy_private_symbol_data}
@strong{Synopsis}
@example
boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
@end example
@strong{Description}@*
Copy private symbol information from @var{isym} in the BFD
@var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.
Return @code{true} on success, @code{false} on error. Possible error
returns are:
@itemize @bullet
@item
@code{bfd_error_no_memory} -
Not enough memory exists to create private data for @var{osec}.
@end itemize
@example
#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
(ibfd, isymbol, obfd, osymbol))
@end example
@*

View File

@ -0,0 +1,478 @@
@section Targets
@*
@strong{Description}@*
Each port of BFD to a different machine requries the creation
of a target back end. All the back end provides to the root
part of BFD is a structure containing pointers to functions
which perform certain low level operations on files. BFD
translates the applications's requests through a pointer into
calls to the back end routines.
When a file is opened with @code{bfd_openr}, its format and
target are unknown. BFD uses various mechanisms to determine
how to interpret the file. The operations performed are:
@itemize @bullet
@item
Create a BFD by calling the internal routine
@code{_bfd_new_bfd}, then call @code{bfd_find_target} with the
target string supplied to @code{bfd_openr} and the new BFD pointer.
@item
If a null target string was provided to @code{bfd_find_target},
look up the environment variable @code{GNUTARGET} and use
that as the target string.
@item
If the target string is still @code{NULL}, or the target string is
@code{default}, then use the first item in the target vector
as the target type, and set @code{target_defaulted} in the BFD to
cause @code{bfd_check_format} to loop through all the targets.
@xref{bfd_target}. @xref{Formats}.
@item
Otherwise, inspect the elements in the target vector
one by one, until a match on target name is found. When found,
use it.
@item
Otherwise return the error @code{bfd_error_invalid_target} to
@code{bfd_openr}.
@item
@code{bfd_openr} attempts to open the file using
@code{bfd_open_file}, and returns the BFD.
@end itemize
Once the BFD has been opened and the target selected, the file
format may be determined. This is done by calling
@code{bfd_check_format} on the BFD with a suggested format.
If @code{target_defaulted} has been set, each possible target
type is tried to see if it recognizes the specified format.
@code{bfd_check_format} returns @code{true} when the caller guesses right.
@menu
* bfd_target::
@end menu
@*
@node bfd_target, , Targets, Targets
@subsection bfd_target
@*
@strong{Description}@*
This structure contains everything that BFD knows about a
target. It includes things like its byte order, name, and which
routines to call to do various operations.
Every BFD points to a target structure with its @code{xvec}
member.
The macros below are used to dispatch to functions through the
@code{bfd_target} vector. They are used in a number of macros further
down in @file{bfd.h}, and are also used when calling various
routines by hand inside the BFD implementation. The @var{arglist}
argument must be parenthesized; it contains all the arguments
to the called function.
They make the documentation (more) unpleasant to read, so if
someone wants to fix this and not break the above, please do.
@example
#define BFD_SEND(bfd, message, arglist) \
((*((bfd)->xvec->message)) arglist)
#ifdef DEBUG_BFD_SEND
#undef BFD_SEND
#define BFD_SEND(bfd, message, arglist) \
(((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
((*((bfd)->xvec->message)) arglist) : \
(bfd_assert (__FILE__,__LINE__), NULL))
#endif
@end example
For operations which index on the BFD format:
@example
#define BFD_SEND_FMT(bfd, message, arglist) \
(((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
#ifdef DEBUG_BFD_SEND
#undef BFD_SEND_FMT
#define BFD_SEND_FMT(bfd, message, arglist) \
(((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
(((bfd)->xvec->message[(int)((bfd)->format)]) arglist) : \
(bfd_assert (__FILE__,__LINE__), NULL))
#endif
@end example
This is the structure which defines the type of BFD this is. The
@code{xvec} member of the struct @code{bfd} itself points here. Each
module that implements access to a different target under BFD,
defines one of these.
FIXME, these names should be rationalised with the names of
the entry points which call them. Too bad we can't have one
macro to define them both!
@example
enum bfd_flavour @{
bfd_target_unknown_flavour,
bfd_target_aout_flavour,
bfd_target_coff_flavour,
bfd_target_ecoff_flavour,
bfd_target_elf_flavour,
bfd_target_ieee_flavour,
bfd_target_nlm_flavour,
bfd_target_oasys_flavour,
bfd_target_tekhex_flavour,
bfd_target_srec_flavour,
bfd_target_ihex_flavour,
bfd_target_som_flavour,
bfd_target_os9k_flavour,
bfd_target_versados_flavour,
bfd_target_msdos_flavour,
bfd_target_evax_flavour
@};
enum bfd_endian @{ BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN @};
/* Forward declaration. */
typedef struct bfd_link_info _bfd_link_info;
typedef struct bfd_target
@{
@end example
Identifies the kind of target, e.g., SunOS4, Ultrix, etc.
@example
char *name;
@end example
The "flavour" of a back end is a general indication about the contents
of a file.
@example
enum bfd_flavour flavour;
@end example
The order of bytes within the data area of a file.
@example
enum bfd_endian byteorder;
@end example
The order of bytes within the header parts of a file.
@example
enum bfd_endian header_byteorder;
@end example
A mask of all the flags which an executable may have set -
from the set @code{BFD_NO_FLAGS}, @code{HAS_RELOC}, ...@code{D_PAGED}.
@example
flagword object_flags;
@end example
A mask of all the flags which a section may have set - from
the set @code{SEC_NO_FLAGS}, @code{SEC_ALLOC}, ...@code{SET_NEVER_LOAD}.
@example
flagword section_flags;
@end example
The character normally found at the front of a symbol
(if any), perhaps `_'.
@example
char symbol_leading_char;
@end example
The pad character for file names within an archive header.
@example
char ar_pad_char;
@end example
The maximum number of characters in an archive header.
@example
unsigned short ar_max_namelen;
@end example
Entries for byte swapping for data. These are different from the other
entry points, since they don't take a BFD asthe first argument.
Certain other handlers could do the same.
@example
bfd_vma (*bfd_getx64) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
void (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
bfd_vma (*bfd_getx32) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
void (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
bfd_vma (*bfd_getx16) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
void (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
@end example
Byte swapping for the headers
@example
bfd_vma (*bfd_h_getx64) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
void (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
bfd_vma (*bfd_h_getx32) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
void (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
bfd_vma (*bfd_h_getx16) PARAMS ((const bfd_byte *));
bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
void (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
@end example
Format dependent routines: these are vectors of entry points
within the target vector structure, one for each format to check.
Check the format of a file being read. Return a @code{bfd_target *} or zero.
@example
const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
@end example
Set the format of a file being written.
@example
boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
@end example
Write cached information into a file being written, at @code{bfd_close}.
@example
boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
@end example
The general target vector.
@example
/* Generic entry points. */
#define BFD_JUMP_TABLE_GENERIC(NAME)\
CAT(NAME,_close_and_cleanup),\
CAT(NAME,_bfd_free_cached_info),\
CAT(NAME,_new_section_hook),\
CAT(NAME,_get_section_contents),\
CAT(NAME,_get_section_contents_in_window)
/* Called when the BFD is being closed to do any necessary cleanup. */
boolean (*_close_and_cleanup) PARAMS ((bfd *));
/* Ask the BFD to free all cached information. */
boolean (*_bfd_free_cached_info) PARAMS ((bfd *));
/* Called when a new section is created. */
boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
/* Read the contents of a section. */
boolean (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
file_ptr, bfd_size_type));
boolean (*_bfd_get_section_contents_in_window)
PARAMS ((bfd *, sec_ptr, bfd_window *,
file_ptr, bfd_size_type));
/* Entry points to copy private data. */
#define BFD_JUMP_TABLE_COPY(NAME)\
CAT(NAME,_bfd_copy_private_bfd_data),\
CAT(NAME,_bfd_merge_private_bfd_data),\
CAT(NAME,_bfd_copy_private_section_data),\
CAT(NAME,_bfd_copy_private_symbol_data),\
CAT(NAME,_bfd_set_private_flags),\
CAT(NAME,_bfd_print_private_bfd_data)\
/* Called to copy BFD general private data from one object file
to another. */
boolean (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));
/* Called to merge BFD general private data from one object file
to a common output file when linking. */
boolean (*_bfd_merge_private_bfd_data) PARAMS ((bfd *, bfd *));
/* Called to copy BFD private section data from one object file
to another. */
boolean (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,
bfd *, sec_ptr));
/* Called to copy BFD private symbol data from one symbol
to another. */
boolean (*_bfd_copy_private_symbol_data) PARAMS ((bfd *, asymbol *,
bfd *, asymbol *));
/* Called to set private backend flags */
boolean (*_bfd_set_private_flags) PARAMS ((bfd *, flagword));
/* Called to print private BFD data */
boolean (*_bfd_print_private_bfd_data) PARAMS ((bfd *, PTR));
/* Core file entry points. */
#define BFD_JUMP_TABLE_CORE(NAME)\
CAT(NAME,_core_file_failing_command),\
CAT(NAME,_core_file_failing_signal),\
CAT(NAME,_core_file_matches_executable_p)
char * (*_core_file_failing_command) PARAMS ((bfd *));
int (*_core_file_failing_signal) PARAMS ((bfd *));
boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
/* Archive entry points. */
#define BFD_JUMP_TABLE_ARCHIVE(NAME)\
CAT(NAME,_slurp_armap),\
CAT(NAME,_slurp_extended_name_table),\
CAT(NAME,_construct_extended_name_table),\
CAT(NAME,_truncate_arname),\
CAT(NAME,_write_armap),\
CAT(NAME,_read_ar_hdr),\
CAT(NAME,_openr_next_archived_file),\
CAT(NAME,_get_elt_at_index),\
CAT(NAME,_generic_stat_arch_elt),\
CAT(NAME,_update_armap_timestamp)
boolean (*_bfd_slurp_armap) PARAMS ((bfd *));
boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
boolean (*_bfd_construct_extended_name_table)
PARAMS ((bfd *, char **, bfd_size_type *, const char **));
void (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
boolean (*write_armap) PARAMS ((bfd *arch,
unsigned int elength,
struct orl *map,
unsigned int orl_count,
int stridx));
PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
bfd * (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
#define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
bfd * (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
int (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
boolean (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
/* Entry points used for symbols. */
#define BFD_JUMP_TABLE_SYMBOLS(NAME)\
CAT(NAME,_get_symtab_upper_bound),\
CAT(NAME,_get_symtab),\
CAT(NAME,_make_empty_symbol),\
CAT(NAME,_print_symbol),\
CAT(NAME,_get_symbol_info),\
CAT(NAME,_bfd_is_local_label_name),\
CAT(NAME,_get_lineno),\
CAT(NAME,_find_nearest_line),\
CAT(NAME,_bfd_make_debug_symbol),\
CAT(NAME,_read_minisymbols),\
CAT(NAME,_minisymbol_to_symbol)
long (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));
long (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
struct symbol_cache_entry **));
struct symbol_cache_entry *
(*_bfd_make_empty_symbol) PARAMS ((bfd *));
void (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
struct symbol_cache_entry *,
bfd_print_symbol_type));
#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
void (*_bfd_get_symbol_info) PARAMS ((bfd *,
struct symbol_cache_entry *,
symbol_info *));
#define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
boolean (*_bfd_is_local_label_name) PARAMS ((bfd *, const char *));
alent * (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
boolean (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
struct sec *section, struct symbol_cache_entry **symbols,
bfd_vma offset, CONST char **file, CONST char **func,
unsigned int *line));
/* Back-door to allow format-aware applications to create debug symbols
while using BFD for everything else. Currently used by the assembler
when creating COFF files. */
asymbol * (*_bfd_make_debug_symbol) PARAMS ((
bfd *abfd,
void *ptr,
unsigned long size));
#define bfd_read_minisymbols(b, d, m, s) \
BFD_SEND (b, _read_minisymbols, (b, d, m, s))
long (*_read_minisymbols) PARAMS ((bfd *, boolean, PTR *,
unsigned int *));
#define bfd_minisymbol_to_symbol(b, d, m, f) \
BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
asymbol *(*_minisymbol_to_symbol) PARAMS ((bfd *, boolean, const PTR,
asymbol *));
/* Routines for relocs. */
#define BFD_JUMP_TABLE_RELOCS(NAME)\
CAT(NAME,_get_reloc_upper_bound),\
CAT(NAME,_canonicalize_reloc),\
CAT(NAME,_bfd_reloc_type_lookup)
long (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
long (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
struct symbol_cache_entry **));
/* See documentation on reloc types. */
reloc_howto_type *
(*reloc_type_lookup) PARAMS ((bfd *abfd,
bfd_reloc_code_real_type code));
/* Routines used when writing an object file. */
#define BFD_JUMP_TABLE_WRITE(NAME)\
CAT(NAME,_set_arch_mach),\
CAT(NAME,_set_section_contents)
boolean (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
unsigned long));
boolean (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
file_ptr, bfd_size_type));
/* Routines used by the linker. */
#define BFD_JUMP_TABLE_LINK(NAME)\
CAT(NAME,_sizeof_headers),\
CAT(NAME,_bfd_get_relocated_section_contents),\
CAT(NAME,_bfd_relax_section),\
CAT(NAME,_bfd_link_hash_table_create),\
CAT(NAME,_bfd_link_add_symbols),\
CAT(NAME,_bfd_final_link),\
CAT(NAME,_bfd_link_split_section)
int (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
struct bfd_link_info *, struct bfd_link_order *,
bfd_byte *data, boolean relocateable,
struct symbol_cache_entry **));
boolean (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
struct bfd_link_info *, boolean *again));
/* Create a hash table for the linker. Different backends store
different information in this table. */
struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
/* Add symbols from this object file into the hash table. */
boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
/* Do a link based on the link_order structures attached to each
section of the BFD. */
boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
/* Should this section be split up into smaller pieces during linking. */
boolean (*_bfd_link_split_section) PARAMS ((bfd *, struct sec *));
/* Routines to handle dynamic symbols and relocs. */
#define BFD_JUMP_TABLE_DYNAMIC(NAME)\
CAT(NAME,_get_dynamic_symtab_upper_bound),\
CAT(NAME,_canonicalize_dynamic_symtab),\
CAT(NAME,_get_dynamic_reloc_upper_bound),\
CAT(NAME,_canonicalize_dynamic_reloc)
/* Get the amount of memory required to hold the dynamic symbols. */
long (*_bfd_get_dynamic_symtab_upper_bound) PARAMS ((bfd *));
/* Read in the dynamic symbols. */
long (*_bfd_canonicalize_dynamic_symtab)
PARAMS ((bfd *, struct symbol_cache_entry **));
/* Get the amount of memory required to hold the dynamic relocs. */
long (*_bfd_get_dynamic_reloc_upper_bound) PARAMS ((bfd *));
/* Read in the dynamic relocs. */
long (*_bfd_canonicalize_dynamic_reloc)
PARAMS ((bfd *, arelent **, struct symbol_cache_entry **));
@end example
Data for use by back-end routines, which isn't generic enough to belong
in this structure.
@example
PTR backend_data;
@} bfd_target;
@end example
@*
@findex bfd_set_default_target
@subsubsection @code{bfd_set_default_target}
@strong{Synopsis}
@example
boolean bfd_set_default_target (const char *name);
@end example
@strong{Description}@*
Set the default target vector to use when recognizing a BFD.
This takes the name of the target, which may be a BFD target
name or a configuration triplet.
@*
@findex bfd_find_target
@subsubsection @code{bfd_find_target}
@strong{Synopsis}
@example
const bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
@end example
@strong{Description}@*
Return a pointer to the transfer vector for the object target
named @var{target_name}. If @var{target_name} is @code{NULL}, choose the
one in the environment variable @code{GNUTARGET}; if that is null or not
defined, then choose the first entry in the target list.
Passing in the string "default" or setting the environment
variable to "default" will cause the first entry in the target
list to be returned, and "target_defaulted" will be set in the
BFD. This causes @code{bfd_check_format} to loop over all the
targets to find the one that matches the file being read.
@*
@findex bfd_target_list
@subsubsection @code{bfd_target_list}
@strong{Synopsis}
@example
const char **bfd_target_list(void);
@end example
@strong{Description}@*
Return a freshly malloced NULL-terminated
vector of the names of all the valid BFD targets. Do not
modify the names.
@*

4824
contrib/binutils/bfd/ecoff.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,853 @@
/* Generic ECOFF swapping routines, for BFD.
Copyright 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* NOTE: This is a header file, but it contains executable routines.
This is done this way because these routines are substantially
similar, but are not identical, for all ECOFF targets.
These are routines to swap the ECOFF symbolic information in and
out. The routines are defined statically. You can set breakpoints
on them in gdb by naming the including source file; e.g.,
'coff-mips.c':ecoff_swap_hdr_in.
Before including this header file, one of ECOFF_32 or ECOFF_64 must
be defined. These are checked when swapping information that
depends upon the target size. This code works for 32 bit and 64
bit ECOFF, but may need to be generalized in the future.
Some header file which defines the external forms of these
structures must also be included before including this header file.
Currently this is either coff/mips.h or coff/alpha.h.
If the symbol TEST is defined when this file is compiled, a
comparison is made to ensure that, in fact, the output is
bit-for-bit the same as the input. Of course, this symbol should
only be defined when deliberately testing the code on a machine
with the proper byte sex and such. */
#ifdef ECOFF_32
#define ecoff_get_off bfd_h_get_32
#define ecoff_put_off bfd_h_put_32
#endif
#ifdef ECOFF_64
#define ecoff_get_off bfd_h_get_64
#define ecoff_put_off bfd_h_put_64
#endif
/* ECOFF auxiliary information swapping routines. These are the same
for all ECOFF targets, so they are defined in ecofflink.c. */
extern void _bfd_ecoff_swap_tir_in
PARAMS ((int, const struct tir_ext *, TIR *));
extern void _bfd_ecoff_swap_tir_out
PARAMS ((int, const TIR *, struct tir_ext *));
extern void _bfd_ecoff_swap_rndx_in
PARAMS ((int, const struct rndx_ext *, RNDXR *));
extern void _bfd_ecoff_swap_rndx_out
PARAMS ((int, const RNDXR *, struct rndx_ext *));
/* Prototypes for functions defined in this file. */
static void ecoff_swap_hdr_in PARAMS ((bfd *, PTR, HDRR *));
static void ecoff_swap_hdr_out PARAMS ((bfd *, const HDRR *, PTR));
static void ecoff_swap_fdr_in PARAMS ((bfd *, PTR, FDR *));
static void ecoff_swap_fdr_out PARAMS ((bfd *, const FDR *, PTR));
static void ecoff_swap_pdr_in PARAMS ((bfd *, PTR, PDR *));
static void ecoff_swap_pdr_out PARAMS ((bfd *, const PDR *, PTR));
static void ecoff_swap_sym_in PARAMS ((bfd *, PTR, SYMR *));
static void ecoff_swap_sym_out PARAMS ((bfd *, const SYMR *, PTR));
static void ecoff_swap_ext_in PARAMS ((bfd *, PTR, EXTR *));
static void ecoff_swap_ext_out PARAMS ((bfd *, const EXTR *, PTR));
static void ecoff_swap_rfd_in PARAMS ((bfd *, PTR, RFDT *));
static void ecoff_swap_rfd_out PARAMS ((bfd *, const RFDT *, PTR));
static void ecoff_swap_opt_in PARAMS ((bfd *, PTR, OPTR *));
static void ecoff_swap_opt_out PARAMS ((bfd *, const OPTR *, PTR));
static void ecoff_swap_dnr_in PARAMS ((bfd *, PTR, DNR *));
static void ecoff_swap_dnr_out PARAMS ((bfd *, const DNR *, PTR));
/* Swap in the symbolic header. */
static void
ecoff_swap_hdr_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
HDRR *intern;
{
struct hdr_ext ext[1];
*ext = *(struct hdr_ext *) ext_copy;
intern->magic = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_magic);
intern->vstamp = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->h_vstamp);
intern->ilineMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ilineMax);
intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLine);
intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbLineOffset);
intern->idnMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_idnMax);
intern->cbDnOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbDnOffset);
intern->ipdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ipdMax);
intern->cbPdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbPdOffset);
intern->isymMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_isymMax);
intern->cbSymOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSymOffset);
intern->ioptMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ioptMax);
intern->cbOptOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbOptOffset);
intern->iauxMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iauxMax);
intern->cbAuxOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbAuxOffset);
intern->issMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issMax);
intern->cbSsOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsOffset);
intern->issExtMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_issExtMax);
intern->cbSsExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbSsExtOffset);
intern->ifdMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_ifdMax);
intern->cbFdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbFdOffset);
intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_crfd);
intern->cbRfdOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbRfdOffset);
intern->iextMax = bfd_h_get_32 (abfd, (bfd_byte *)ext->h_iextMax);
intern->cbExtOffset = ecoff_get_off (abfd, (bfd_byte *)ext->h_cbExtOffset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out the symbolic header. */
static void
ecoff_swap_hdr_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const HDRR *intern_copy;
PTR ext_ptr;
{
struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
HDRR intern[1];
*intern = *intern_copy;
bfd_h_put_signed_16 (abfd, intern->magic, (bfd_byte *)ext->h_magic);
bfd_h_put_signed_16 (abfd, intern->vstamp, (bfd_byte *)ext->h_vstamp);
bfd_h_put_32 (abfd, intern->ilineMax, (bfd_byte *)ext->h_ilineMax);
ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->h_cbLine);
ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->h_cbLineOffset);
bfd_h_put_32 (abfd, intern->idnMax, (bfd_byte *)ext->h_idnMax);
ecoff_put_off (abfd, intern->cbDnOffset, (bfd_byte *)ext->h_cbDnOffset);
bfd_h_put_32 (abfd, intern->ipdMax, (bfd_byte *)ext->h_ipdMax);
ecoff_put_off (abfd, intern->cbPdOffset, (bfd_byte *)ext->h_cbPdOffset);
bfd_h_put_32 (abfd, intern->isymMax, (bfd_byte *)ext->h_isymMax);
ecoff_put_off (abfd, intern->cbSymOffset, (bfd_byte *)ext->h_cbSymOffset);
bfd_h_put_32 (abfd, intern->ioptMax, (bfd_byte *)ext->h_ioptMax);
ecoff_put_off (abfd, intern->cbOptOffset, (bfd_byte *)ext->h_cbOptOffset);
bfd_h_put_32 (abfd, intern->iauxMax, (bfd_byte *)ext->h_iauxMax);
ecoff_put_off (abfd, intern->cbAuxOffset, (bfd_byte *)ext->h_cbAuxOffset);
bfd_h_put_32 (abfd, intern->issMax, (bfd_byte *)ext->h_issMax);
ecoff_put_off (abfd, intern->cbSsOffset, (bfd_byte *)ext->h_cbSsOffset);
bfd_h_put_32 (abfd, intern->issExtMax, (bfd_byte *)ext->h_issExtMax);
ecoff_put_off (abfd, intern->cbSsExtOffset, (bfd_byte *)ext->h_cbSsExtOffset);
bfd_h_put_32 (abfd, intern->ifdMax, (bfd_byte *)ext->h_ifdMax);
ecoff_put_off (abfd, intern->cbFdOffset, (bfd_byte *)ext->h_cbFdOffset);
bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->h_crfd);
ecoff_put_off (abfd, intern->cbRfdOffset, (bfd_byte *)ext->h_cbRfdOffset);
bfd_h_put_32 (abfd, intern->iextMax, (bfd_byte *)ext->h_iextMax);
ecoff_put_off (abfd, intern->cbExtOffset, (bfd_byte *)ext->h_cbExtOffset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap in the file descriptor record. */
static void
ecoff_swap_fdr_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
FDR *intern;
{
struct fdr_ext ext[1];
*ext = *(struct fdr_ext *) ext_copy;
intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->f_adr);
intern->rss = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rss);
#ifdef ECOFF_64
if (intern->rss == 0xffffffff)
intern->rss = -1;
#endif
intern->issBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_issBase);
intern->cbSs = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbSs);
intern->isymBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_isymBase);
intern->csym = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_csym);
intern->ilineBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ilineBase);
intern->cline = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cline);
intern->ioptBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ioptBase);
intern->copt = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_copt);
#ifdef ECOFF_32
intern->ipdFirst = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_ipdFirst);
intern->cpd = bfd_h_get_16 (abfd, (bfd_byte *)ext->f_cpd);
#endif
#ifdef ECOFF_64
intern->ipdFirst = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_ipdFirst);
intern->cpd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_cpd);
#endif
intern->iauxBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_iauxBase);
intern->caux = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_caux);
intern->rfdBase = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_rfdBase);
intern->crfd = bfd_h_get_32 (abfd, (bfd_byte *)ext->f_crfd);
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
>> FDR_BITS1_LANG_SH_BIG;
intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
>> FDR_BITS2_GLEVEL_SH_BIG;
} else {
intern->lang = (ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
>> FDR_BITS1_LANG_SH_LITTLE;
intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
intern->glevel = (ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
>> FDR_BITS2_GLEVEL_SH_LITTLE;
}
intern->reserved = 0;
intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLineOffset);
intern->cbLine = ecoff_get_off (abfd, (bfd_byte *)ext->f_cbLine);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out the file descriptor record. */
static void
ecoff_swap_fdr_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const FDR *intern_copy;
PTR ext_ptr;
{
struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
FDR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->f_adr);
bfd_h_put_32 (abfd, intern->rss, (bfd_byte *)ext->f_rss);
bfd_h_put_32 (abfd, intern->issBase, (bfd_byte *)ext->f_issBase);
ecoff_put_off (abfd, intern->cbSs, (bfd_byte *)ext->f_cbSs);
bfd_h_put_32 (abfd, intern->isymBase, (bfd_byte *)ext->f_isymBase);
bfd_h_put_32 (abfd, intern->csym, (bfd_byte *)ext->f_csym);
bfd_h_put_32 (abfd, intern->ilineBase, (bfd_byte *)ext->f_ilineBase);
bfd_h_put_32 (abfd, intern->cline, (bfd_byte *)ext->f_cline);
bfd_h_put_32 (abfd, intern->ioptBase, (bfd_byte *)ext->f_ioptBase);
bfd_h_put_32 (abfd, intern->copt, (bfd_byte *)ext->f_copt);
#ifdef ECOFF_32
bfd_h_put_16 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
bfd_h_put_16 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
#endif
#ifdef ECOFF_64
bfd_h_put_32 (abfd, intern->ipdFirst, (bfd_byte *)ext->f_ipdFirst);
bfd_h_put_32 (abfd, intern->cpd, (bfd_byte *)ext->f_cpd);
#endif
bfd_h_put_32 (abfd, intern->iauxBase, (bfd_byte *)ext->f_iauxBase);
bfd_h_put_32 (abfd, intern->caux, (bfd_byte *)ext->f_caux);
bfd_h_put_32 (abfd, intern->rfdBase, (bfd_byte *)ext->f_rfdBase);
bfd_h_put_32 (abfd, intern->crfd, (bfd_byte *)ext->f_crfd);
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
& FDR_BITS1_LANG_BIG)
| (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
| (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
| (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
& FDR_BITS2_GLEVEL_BIG);
ext->f_bits2[1] = 0;
ext->f_bits2[2] = 0;
} else {
ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
& FDR_BITS1_LANG_LITTLE)
| (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
| (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
| (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
& FDR_BITS2_GLEVEL_LITTLE);
ext->f_bits2[1] = 0;
ext->f_bits2[2] = 0;
}
ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->f_cbLineOffset);
ecoff_put_off (abfd, intern->cbLine, (bfd_byte *)ext->f_cbLine);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
#ifndef MPW_C
/* Swap in the procedure descriptor record. */
static void
ecoff_swap_pdr_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
PDR *intern;
{
struct pdr_ext ext[1];
*ext = *(struct pdr_ext *) ext_copy;
memset ((PTR) intern, 0, sizeof (*intern));
intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
intern->regoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_regoffset);
intern->iopt = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
intern->fregoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_fregoffset);
intern->frameoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_frameoffset);
intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
#ifdef ECOFF_64
intern->gp_prologue = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_gp_prologue);
if (bfd_header_big_endian (abfd))
{
intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
<< PDR_BITS1_RESERVED_SH_LEFT_BIG)
| ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
>> PDR_BITS2_RESERVED_SH_BIG));
}
else
{
intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
>> PDR_BITS1_RESERVED_SH_LITTLE)
| ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
<< PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
}
intern->localoff = bfd_h_get_8 (abfd, (bfd_byte *) ext->p_localoff);
#endif
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out the procedure descriptor record. */
static void
ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const PDR *intern_copy;
PTR ext_ptr;
{
struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
PDR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
#ifdef ECOFF_64
bfd_h_put_8 (abfd, intern->gp_prologue, (bfd_byte *) ext->p_gp_prologue);
if (bfd_header_big_endian (abfd))
{
ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
| (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
| (intern->prof ? PDR_BITS1_PROF_BIG : 0)
| ((intern->reserved
>> PDR_BITS1_RESERVED_SH_LEFT_BIG)
& PDR_BITS1_RESERVED_BIG));
ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
& PDR_BITS2_RESERVED_BIG);
}
else
{
ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
| (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
| (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
| ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
& PDR_BITS1_RESERVED_LITTLE));
ext->p_bits2[0] = ((intern->reserved >>
PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
& PDR_BITS2_RESERVED_LITTLE);
}
bfd_h_put_8 (abfd, intern->localoff, (bfd_byte *) ext->p_localoff);
#endif
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
#else /* MPW_C */
/* Same routines, but with ECOFF_64 code removed, so ^&%$#&! MPW C doesn't
corrupt itself and then freak out. */
/* Swap in the procedure descriptor record. */
static void
ecoff_swap_pdr_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
PDR *intern;
{
struct pdr_ext ext[1];
*ext = *(struct pdr_ext *) ext_copy;
intern->adr = ecoff_get_off (abfd, (bfd_byte *)ext->p_adr);
intern->isym = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_isym);
intern->iline = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_iline);
intern->regmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_regmask);
intern->regoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_regoffset);
intern->iopt = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->p_iopt);
intern->fregmask = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_fregmask);
intern->fregoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_fregoffset);
intern->frameoffset = bfd_h_get_signed_32 (abfd,
(bfd_byte *)ext->p_frameoffset);
intern->framereg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_framereg);
intern->pcreg = bfd_h_get_16 (abfd, (bfd_byte *)ext->p_pcreg);
intern->lnLow = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnLow);
intern->lnHigh = bfd_h_get_32 (abfd, (bfd_byte *)ext->p_lnHigh);
intern->cbLineOffset = ecoff_get_off (abfd, (bfd_byte *)ext->p_cbLineOffset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out the procedure descriptor record. */
static void
ecoff_swap_pdr_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const PDR *intern_copy;
PTR ext_ptr;
{
struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
PDR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
ecoff_put_off (abfd, intern->adr, (bfd_byte *)ext->p_adr);
bfd_h_put_32 (abfd, intern->isym, (bfd_byte *)ext->p_isym);
bfd_h_put_32 (abfd, intern->iline, (bfd_byte *)ext->p_iline);
bfd_h_put_32 (abfd, intern->regmask, (bfd_byte *)ext->p_regmask);
bfd_h_put_32 (abfd, intern->regoffset, (bfd_byte *)ext->p_regoffset);
bfd_h_put_32 (abfd, intern->iopt, (bfd_byte *)ext->p_iopt);
bfd_h_put_32 (abfd, intern->fregmask, (bfd_byte *)ext->p_fregmask);
bfd_h_put_32 (abfd, intern->fregoffset, (bfd_byte *)ext->p_fregoffset);
bfd_h_put_32 (abfd, intern->frameoffset, (bfd_byte *)ext->p_frameoffset);
bfd_h_put_16 (abfd, intern->framereg, (bfd_byte *)ext->p_framereg);
bfd_h_put_16 (abfd, intern->pcreg, (bfd_byte *)ext->p_pcreg);
bfd_h_put_32 (abfd, intern->lnLow, (bfd_byte *)ext->p_lnLow);
bfd_h_put_32 (abfd, intern->lnHigh, (bfd_byte *)ext->p_lnHigh);
ecoff_put_off (abfd, intern->cbLineOffset, (bfd_byte *)ext->p_cbLineOffset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
#endif /* MPW_C */
/* Swap in a symbol record. */
static void
ecoff_swap_sym_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
SYMR *intern;
{
struct sym_ext ext[1];
*ext = *(struct sym_ext *) ext_copy;
intern->iss = bfd_h_get_32 (abfd, (bfd_byte *)ext->s_iss);
intern->value = ecoff_get_off (abfd, (bfd_byte *)ext->s_value);
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
>> SYM_BITS1_ST_SH_BIG;
intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
<< SYM_BITS1_SC_SH_LEFT_BIG)
| ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
>> SYM_BITS2_SC_SH_BIG);
intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
<< SYM_BITS2_INDEX_SH_LEFT_BIG)
| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
| (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
} else {
intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
>> SYM_BITS1_ST_SH_LITTLE;
intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
>> SYM_BITS1_SC_SH_LITTLE)
| ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
<< SYM_BITS2_SC_SH_LEFT_LITTLE);
intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
>> SYM_BITS2_INDEX_SH_LITTLE)
| (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
| ((unsigned int) ext->s_bits4[0]
<< SYM_BITS4_INDEX_SH_LEFT_LITTLE);
}
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out a symbol record. */
static void
ecoff_swap_sym_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const SYMR *intern_copy;
PTR ext_ptr;
{
struct sym_ext *ext = (struct sym_ext *) ext_ptr;
SYMR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
bfd_h_put_32 (abfd, intern->iss, (bfd_byte *)ext->s_iss);
ecoff_put_off (abfd, intern->value, (bfd_byte *)ext->s_value);
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
& SYM_BITS1_ST_BIG)
| ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
& SYM_BITS1_SC_BIG));
ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
& SYM_BITS2_SC_BIG)
| (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
| ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
& SYM_BITS2_INDEX_BIG));
ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
} else {
ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
& SYM_BITS1_ST_LITTLE)
| ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
& SYM_BITS1_SC_LITTLE));
ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
& SYM_BITS2_SC_LITTLE)
| (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
| ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
& SYM_BITS2_INDEX_LITTLE));
ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
}
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap in an external symbol record. */
static void
ecoff_swap_ext_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
EXTR *intern;
{
struct ext_ext ext[1];
*ext = *(struct ext_ext *) ext_copy;
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
} else {
intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
}
intern->reserved = 0;
#ifdef ECOFF_32
intern->ifd = bfd_h_get_signed_16 (abfd, (bfd_byte *)ext->es_ifd);
#endif
#ifdef ECOFF_64
intern->ifd = bfd_h_get_signed_32 (abfd, (bfd_byte *)ext->es_ifd);
#endif
ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out an external symbol record. */
static void
ecoff_swap_ext_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const EXTR *intern_copy;
PTR ext_ptr;
{
struct ext_ext *ext = (struct ext_ext *) ext_ptr;
EXTR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
/* now the fun stuff... */
if (bfd_header_big_endian (abfd)) {
ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
| (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
ext->es_bits2[0] = 0;
#ifdef ECOFF_64
ext->es_bits2[1] = 0;
ext->es_bits2[2] = 0;
#endif
} else {
ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
| (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
| (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
ext->es_bits2[0] = 0;
#ifdef ECOFF_64
ext->es_bits2[1] = 0;
ext->es_bits2[2] = 0;
#endif
}
#ifdef ECOFF_32
bfd_h_put_signed_16 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
#endif
#ifdef ECOFF_64
bfd_h_put_signed_32 (abfd, intern->ifd, (bfd_byte *)ext->es_ifd);
#endif
ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap in a relative file descriptor. */
static void
ecoff_swap_rfd_in (abfd, ext_ptr, intern)
bfd *abfd;
PTR ext_ptr;
RFDT *intern;
{
struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
*intern = bfd_h_get_32 (abfd, (bfd_byte *)ext->rfd);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out a relative file descriptor. */
static void
ecoff_swap_rfd_out (abfd, intern, ext_ptr)
bfd *abfd;
const RFDT *intern;
PTR ext_ptr;
{
struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
bfd_h_put_32 (abfd, *intern, (bfd_byte *)ext->rfd);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap in an optimization symbol. */
static void
ecoff_swap_opt_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
OPTR *intern;
{
struct opt_ext ext[1];
*ext = *(struct opt_ext *) ext_copy;
if (bfd_header_big_endian (abfd))
{
intern->ot = ext->o_bits1[0];
intern->value = (((unsigned int) ext->o_bits2[0]
<< OPT_BITS2_VALUE_SH_LEFT_BIG)
| ((unsigned int) ext->o_bits3[0]
<< OPT_BITS2_VALUE_SH_LEFT_BIG)
| ((unsigned int) ext->o_bits4[0]
<< OPT_BITS2_VALUE_SH_LEFT_BIG));
}
else
{
intern->ot = ext->o_bits1[0];
intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
| (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
| (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
}
_bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
&ext->o_rndx, &intern->rndx);
intern->offset = bfd_h_get_32 (abfd, (bfd_byte *) ext->o_offset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out an optimization symbol. */
static void
ecoff_swap_opt_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const OPTR *intern_copy;
PTR ext_ptr;
{
struct opt_ext *ext = (struct opt_ext *) ext_ptr;
OPTR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
if (bfd_header_big_endian (abfd))
{
ext->o_bits1[0] = intern->ot;
ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
}
else
{
ext->o_bits1[0] = intern->ot;
ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
}
_bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
&intern->rndx, &ext->o_rndx);
bfd_h_put_32 (abfd, intern->value, (bfd_byte *) ext->o_offset);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap in a dense number. */
static void
ecoff_swap_dnr_in (abfd, ext_copy, intern)
bfd *abfd;
PTR ext_copy;
DNR *intern;
{
struct dnr_ext ext[1];
*ext = *(struct dnr_ext *) ext_copy;
intern->rfd = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_rfd);
intern->index = bfd_h_get_32 (abfd, (bfd_byte *) ext->d_index);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}
/* Swap out a dense number. */
static void
ecoff_swap_dnr_out (abfd, intern_copy, ext_ptr)
bfd *abfd;
const DNR *intern_copy;
PTR ext_ptr;
{
struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
DNR intern[1];
*intern = *intern_copy; /* Make it reasonable to do in-place. */
bfd_h_put_32 (abfd, intern->rfd, (bfd_byte *) ext->d_rfd);
bfd_h_put_32 (abfd, intern->index, (bfd_byte *) ext->d_index);
#ifdef TEST
if (memcmp ((char *)ext, (char *)intern, sizeof (*intern)) != 0)
abort();
#endif
}

File diff suppressed because it is too large Load Diff

4176
contrib/binutils/bfd/elf.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
/* Generic support for 32-bit ELF
Copyright 1993 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "elf-bfd.h"
/* This does not include any relocations, but should be good enough
for GDB to read the file. */
#define TARGET_LITTLE_SYM bfd_elf32_little_generic_vec
#define TARGET_LITTLE_NAME "elf32-little"
#define TARGET_BIG_SYM bfd_elf32_big_generic_vec
#define TARGET_BIG_NAME "elf32-big"
#define ELF_ARCH bfd_arch_unknown
#define ELF_MACHINE_CODE EM_NONE
#define bfd_elf32_bfd_reloc_type_lookup bfd_default_reloc_type_lookup
#define elf_info_to_howto _bfd_elf_no_info_to_howto
#include "elf32-target.h"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
/* ELF 32-bit executable support for BFD.
Copyright 1993 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define ARCH_SIZE 32
#include "elfcode.h"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
/* Generic support for 64-bit ELF
Copyright 1993 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "elf-bfd.h"
/* This does not include any relocations, but should be good enough
for GDB to read the file. */
#define TARGET_LITTLE_SYM bfd_elf64_little_generic_vec
#define TARGET_LITTLE_NAME "elf64-little"
#define TARGET_BIG_SYM bfd_elf64_big_generic_vec
#define TARGET_BIG_NAME "elf64-big"
#define ELF_ARCH bfd_arch_unknown
#define ELF_MACHINE_CODE EM_NONE
#define bfd_elf64_bfd_reloc_type_lookup bfd_default_reloc_type_lookup
#define elf_info_to_howto _bfd_elf_no_info_to_howto
#include "elf64-target.h"

View File

@ -0,0 +1,22 @@
/* ELF 64-bit executable support for BFD.
Copyright 1993 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define ARCH_SIZE 64
#include "elfcode.h"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,550 @@
/* ELF core file support for BFD.
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Core file support */
#ifdef HAVE_SYS_PROCFS_H /* Some core file support requires host /proc files */
#include <signal.h>
#include <sys/procfs.h>
/* Solaris includes the field pr_who that indicates the thread number within
the process. */
#ifdef PIOCOPENLWP
#define get_thread(STATUS) ((((prstatus_t *)(STATUS))->pr_who << 16) \
| ((prstatus_t *)(STATUS))->pr_pid)
#else
#define get_thread(STATUS) (((prstatus_t *)(STATUS))->pr_pid)
#endif
static boolean bfd_prstatus PARAMS ((bfd *, char *, int, long, int));
static boolean bfd_prpsinfo PARAMS ((bfd *, char *, int, long));
static boolean bfd_fpregset PARAMS ((bfd *, char *, int, long, int));
static boolean elf_corefile_note PARAMS ((bfd *, Elf_Internal_Phdr *));
#else
#define bfd_prstatus(abfd, descdata, descsz, filepos, thread) true
#define bfd_fpregset(abfd, descdata, descsz, filepos, thread) true
#define bfd_prpsinfo(abfd, descdata, descsz, filepos) true
#define get_thread(STATUS) (1)
#endif
#ifdef HAVE_SYS_PROCFS_H
static int did_reg;
static int did_reg2;
static boolean
bfd_prstatus (abfd, descdata, descsz, filepos, thread)
bfd *abfd;
char *descdata;
int descsz;
long filepos;
int thread;
{
asection *newsect;
prstatus_t *status = (prstatus_t *) 0;
if (descsz == sizeof (prstatus_t))
{
char secname[100];
char *p;
sprintf (secname, ".reg/%d", thread);
p = bfd_alloc (abfd, strlen (secname) + 1);
if (!p)
return false;
strcpy (p, secname);
newsect = bfd_make_section (abfd, p);
if (newsect == NULL)
return false;
newsect->_raw_size = sizeof (status->pr_reg);
newsect->filepos = filepos + (long) &status->pr_reg;
newsect->flags = SEC_HAS_CONTENTS;
newsect->alignment_power = 2;
if ((core_prstatus (abfd) = bfd_alloc (abfd, descsz)) != NULL)
{
memcpy (core_prstatus (abfd), descdata, descsz);
}
if (!did_reg++)
{
asection *regsect;
regsect = bfd_make_section (abfd, ".reg");
if (regsect == NULL)
return false;
regsect->_raw_size = newsect->_raw_size;
regsect->filepos = newsect->filepos;
regsect->flags = newsect->flags;
regsect->alignment_power = newsect->alignment_power;
}
}
return true;
}
/* Stash a copy of the prpsinfo structure away for future use. */
static boolean
bfd_prpsinfo (abfd, descdata, descsz, filepos)
bfd *abfd;
char *descdata;
int descsz;
long filepos;
{
if (descsz == sizeof (prpsinfo_t))
{
if ((core_prpsinfo (abfd) = bfd_alloc (abfd, descsz)) == NULL)
return false;
memcpy (core_prpsinfo (abfd), descdata, descsz);
}
return true;
}
static boolean
bfd_fpregset (abfd, descdata, descsz, filepos, thread)
bfd *abfd;
char *descdata;
int descsz;
long filepos;
int thread;
{
asection *newsect;
char secname[100];
char *p;
sprintf (secname, ".reg2/%d", thread);
p = bfd_alloc (abfd, strlen (secname) + 1);
if (!p)
return false;
strcpy (p, secname);
newsect = bfd_make_section (abfd, p);
if (newsect == NULL)
return false;
newsect->_raw_size = descsz;
newsect->filepos = filepos;
newsect->flags = SEC_HAS_CONTENTS;
newsect->alignment_power = 2;
if (!did_reg2++)
{
asection *regsect;
regsect = bfd_make_section (abfd, ".reg2");
if (regsect == NULL)
return false;
regsect->_raw_size = newsect->_raw_size;
regsect->filepos = newsect->filepos;
regsect->flags = newsect->flags;
regsect->alignment_power = newsect->alignment_power;
}
return true;
}
#endif /* HAVE_SYS_PROCFS_H */
/* Return a pointer to the args (including the command name) that were
seen by the program that generated the core dump. Note that for
some reason, a spurious space is tacked onto the end of the args
in some (at least one anyway) implementations, so strip it off if
it exists. */
char *
elf_core_file_failing_command (abfd)
bfd *abfd;
{
#ifdef HAVE_SYS_PROCFS_H
if (core_prpsinfo (abfd))
{
prpsinfo_t *p = core_prpsinfo (abfd);
char *scan = p->pr_psargs;
while (*scan++)
{;
}
scan -= 2;
if ((scan > p->pr_psargs) && (*scan == ' '))
{
*scan = '\000';
}
return p->pr_psargs;
}
#endif
return NULL;
}
/* Return the number of the signal that caused the core dump. Presumably,
since we have a core file, we got a signal of some kind, so don't bother
checking the other process status fields, just return the signal number.
*/
int
elf_core_file_failing_signal (abfd)
bfd *abfd;
{
#ifdef HAVE_SYS_PROCFS_H
if (core_prstatus (abfd))
{
return ((prstatus_t *) (core_prstatus (abfd)))->pr_cursig;
}
#endif
return -1;
}
/* Check to see if the core file could reasonably be expected to have
come for the current executable file. Note that by default we return
true unless we find something that indicates that there might be a
problem.
*/
boolean
elf_core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd;
bfd *exec_bfd;
{
#ifdef HAVE_SYS_PROCFS_H
char *corename;
char *execname;
#endif
/* First, xvecs must match since both are ELF files for the same target. */
if (core_bfd->xvec != exec_bfd->xvec)
{
bfd_set_error (bfd_error_system_call);
return false;
}
#ifdef HAVE_SYS_PROCFS_H
/* If no prpsinfo, just return true. Otherwise, grab the last component
of the exec'd pathname from the prpsinfo. */
if (core_prpsinfo (core_bfd))
{
corename = (((prpsinfo_t *) core_prpsinfo (core_bfd))->pr_fname);
}
else
{
return true;
}
/* Find the last component of the executable pathname. */
if ((execname = strrchr (exec_bfd->filename, '/')) != NULL)
{
execname++;
}
else
{
execname = (char *) exec_bfd->filename;
}
/* See if they match */
return strcmp (execname, corename) ? false : true;
#else
return true;
#endif /* HAVE_SYS_PROCFS_H */
}
/* ELF core files contain a segment of type PT_NOTE, that holds much of
the information that would normally be available from the /proc interface
for the process, at the time the process dumped core. Currently this
includes copies of the prstatus, prpsinfo, and fpregset structures.
Since these structures are potentially machine dependent in size and
ordering, bfd provides two levels of support for them. The first level,
available on all machines since it does not require that the host
have /proc support or the relevant include files, is to create a bfd
section for each of the prstatus, prpsinfo, and fpregset structures,
without any interpretation of their contents. With just this support,
the bfd client will have to interpret the structures itself. Even with
/proc support, it might want these full structures for it's own reasons.
In the second level of support, where HAVE_SYS_PROCFS_H is defined,
bfd will pick apart the structures to gather some additional
information that clients may want, such as the general register
set, the name of the exec'ed file and its arguments, the signal (if
any) that caused the core dump, etc.
*/
static boolean
elf_corefile_note (abfd, hdr)
bfd *abfd;
Elf_Internal_Phdr *hdr;
{
Elf_External_Note *x_note_p; /* Elf note, external form */
Elf_Internal_Note i_note; /* Elf note, internal form */
char *buf = NULL; /* Entire note segment contents */
char *namedata; /* Name portion of the note */
char *descdata; /* Descriptor portion of the note */
char *sectname; /* Name to use for new section */
long filepos; /* File offset to descriptor data */
asection *newsect;
int thread = 1; /* Current thread number */
#ifdef HAVE_SYS_PROCFS_H
did_reg = 0; /* Non-zero if we made .reg section */
did_reg2 = 0; /* Ditto for .reg2 */
#endif
if (hdr->p_filesz > 0
&& (buf = (char *) bfd_malloc ((size_t) hdr->p_filesz)) != NULL
&& bfd_seek (abfd, hdr->p_offset, SEEK_SET) != -1
&& bfd_read ((PTR) buf, hdr->p_filesz, 1, abfd) == hdr->p_filesz)
{
x_note_p = (Elf_External_Note *) buf;
while ((char *) x_note_p < (buf + hdr->p_filesz))
{
i_note.namesz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p->namesz);
i_note.descsz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p->descsz);
i_note.type = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p->type);
namedata = x_note_p->name;
descdata = namedata + BFD_ALIGN (i_note.namesz, 4);
filepos = hdr->p_offset + (descdata - buf);
switch (i_note.type)
{
case NT_PRSTATUS:
/* process descdata as prstatus info */
thread = get_thread (descdata);
if (! bfd_prstatus (abfd, descdata, i_note.descsz, filepos,
thread))
return false;
sectname = NULL;
break;
case NT_FPREGSET:
/* process descdata as fpregset info */
if (! bfd_fpregset (abfd, descdata, i_note.descsz, filepos,
thread))
return false;
sectname = NULL;
break;
case NT_PRPSINFO:
/* process descdata as prpsinfo */
if (! bfd_prpsinfo (abfd, descdata, i_note.descsz, filepos))
return false;
sectname = ".prpsinfo";
break;
default:
/* Unknown descriptor, just ignore it. */
sectname = NULL;
break;
}
if (sectname != NULL)
{
newsect = bfd_make_section (abfd, sectname);
if (newsect == NULL)
return false;
newsect->_raw_size = i_note.descsz;
newsect->filepos = filepos;
newsect->flags = SEC_ALLOC | SEC_HAS_CONTENTS;
newsect->alignment_power = 2;
}
x_note_p = (Elf_External_Note *)
(descdata + BFD_ALIGN (i_note.descsz, 4));
}
}
if (buf != NULL)
{
free (buf);
}
else if (hdr->p_filesz > 0)
{
return false;
}
return true;
}
/* Core files are simply standard ELF formatted files that partition
the file using the execution view of the file (program header table)
rather than the linking view. In fact, there is no section header
table in a core file.
The process status information (including the contents of the general
register set) and the floating point register set are stored in a
segment of type PT_NOTE. We handcraft a couple of extra bfd sections
that allow standard bfd access to the general registers (.reg) and the
floating point registers (.reg2).
*/
const bfd_target *
elf_core_file_p (abfd)
bfd *abfd;
{
Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
Elf_External_Phdr x_phdr; /* Program header table entry, external form */
Elf_Internal_Phdr *i_phdrp; /* Program header table, internal form */
unsigned int phindex;
struct elf_backend_data *ebd;
/* Read in the ELF header in external format. */
if (bfd_read ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
/* Now check to see if we have a valid ELF file, and one that BFD can
make use of. The magic number must match, the address size ('class')
and byte-swapping must match our XVEC entry, and it must have a
program header table (FIXME: See comments re segments at top of this
file). */
if (elf_file_p (&x_ehdr) == false)
{
wrong:
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
/* FIXME, Check EI_VERSION here ! */
{
#if ARCH_SIZE == 32
int desired_address_size = ELFCLASS32;
#endif
#if ARCH_SIZE == 64
int desired_address_size = ELFCLASS64;
#endif
if (x_ehdr.e_ident[EI_CLASS] != desired_address_size)
goto wrong;
}
/* Switch xvec to match the specified byte order. */
switch (x_ehdr.e_ident[EI_DATA])
{
case ELFDATA2MSB: /* Big-endian */
if (! bfd_big_endian (abfd))
goto wrong;
break;
case ELFDATA2LSB: /* Little-endian */
if (! bfd_little_endian (abfd))
goto wrong;
break;
case ELFDATANONE: /* No data encoding specified */
default: /* Unknown data encoding specified */
goto wrong;
}
/* Allocate an instance of the elf_obj_tdata structure and hook it up to
the tdata pointer in the bfd. */
elf_tdata (abfd) =
(struct elf_obj_tdata *) bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));
if (elf_tdata (abfd) == NULL)
return NULL;
/* FIXME, `wrong' returns from this point onward, leak memory. */
/* Now that we know the byte order, swap in the rest of the header */
i_ehdrp = elf_elfheader (abfd);
elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
#if DEBUG & 1
elf_debug_file (i_ehdrp);
#endif
ebd = get_elf_backend_data (abfd);
/* Check that the ELF e_machine field matches what this particular
BFD format expects. */
if (ebd->elf_machine_code != i_ehdrp->e_machine
&& (ebd->elf_machine_alt1 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt1)
&& (ebd->elf_machine_alt2 == 0 || i_ehdrp->e_machine != ebd->elf_machine_alt2))
{
const bfd_target * const *target_ptr;
if (ebd->elf_machine_code != EM_NONE)
goto wrong;
/* This is the generic ELF target. Let it match any ELF target
for which we do not have a specific backend. */
for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
{
struct elf_backend_data *back;
if ((*target_ptr)->flavour != bfd_target_elf_flavour)
continue;
back = (struct elf_backend_data *) (*target_ptr)->backend_data;
if (back->elf_machine_code == i_ehdrp->e_machine)
{
/* target_ptr is an ELF backend which matches this
object file, so reject the generic ELF target. */
goto wrong;
}
}
}
/* If there is no program header, or the type is not a core file, then
we are hosed. */
if (i_ehdrp->e_phoff == 0 || i_ehdrp->e_type != ET_CORE)
goto wrong;
/* Allocate space for a copy of the program header table in
internal form, seek to the program header table in the file,
read it in, and convert it to internal form. As a simple sanity
check, verify that the what BFD thinks is the size of each program
header table entry actually matches the size recorded in the file. */
if (i_ehdrp->e_phentsize != sizeof (x_phdr))
goto wrong;
i_phdrp = (Elf_Internal_Phdr *)
bfd_alloc (abfd, sizeof (*i_phdrp) * i_ehdrp->e_phnum);
if (!i_phdrp)
return NULL;
if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) == -1)
return NULL;
for (phindex = 0; phindex < i_ehdrp->e_phnum; phindex++)
{
if (bfd_read ((PTR) & x_phdr, sizeof (x_phdr), 1, abfd)
!= sizeof (x_phdr))
return NULL;
elf_swap_phdr_in (abfd, &x_phdr, i_phdrp + phindex);
}
/* Once all of the program headers have been read and converted, we
can start processing them. */
for (phindex = 0; phindex < i_ehdrp->e_phnum; phindex++)
{
bfd_section_from_phdr (abfd, i_phdrp + phindex, phindex);
if ((i_phdrp + phindex)->p_type == PT_NOTE)
{
if (! elf_corefile_note (abfd, i_phdrp + phindex))
return NULL;
}
}
/* Remember the entry point specified in the ELF file header. */
bfd_get_start_address (abfd) = i_ehdrp->e_entry;
return abfd->xvec;
}

View File

@ -0,0 +1,412 @@
/* ELF linking support for BFD.
Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "bfdlink.h"
#include "libbfd.h"
#define ARCH_SIZE 0
#include "elf-bfd.h"
boolean
_bfd_elf_create_got_section (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
{
flagword flags;
register asection *s;
struct elf_link_hash_entry *h;
struct elf_backend_data *bed = get_elf_backend_data (abfd);
/* This function may be called more than once. */
if (bfd_get_section_by_name (abfd, ".got") != NULL)
return true;
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
| SEC_LINKER_CREATED);
s = bfd_make_section (abfd, ".got");
if (s == NULL
|| !bfd_set_section_flags (abfd, s, flags)
|| !bfd_set_section_alignment (abfd, s, 2))
return false;
if (bed->want_got_plt)
{
s = bfd_make_section (abfd, ".got.plt");
if (s == NULL
|| !bfd_set_section_flags (abfd, s, flags)
|| !bfd_set_section_alignment (abfd, s, 2))
return false;
}
/* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
(or .got.plt) section. We don't do this in the linker script
because we don't want to define the symbol if we are not creating
a global offset table. */
h = NULL;
if (!(_bfd_generic_link_add_one_symbol
(info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, (bfd_vma) 0,
(const char *) NULL, false, get_elf_backend_data (abfd)->collect,
(struct bfd_link_hash_entry **) &h)))
return false;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
if (info->shared
&& ! _bfd_elf_link_record_dynamic_symbol (info, h))
return false;
elf_hash_table (info)->hgot = h;
/* The first three global offset table entries are reserved. */
s->_raw_size += 3 * 4;
return true;
}
/* Create dynamic sections when linking against a dynamic object. */
boolean
_bfd_elf_create_dynamic_sections (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
{
flagword flags;
register asection *s;
struct elf_backend_data *bed = get_elf_backend_data (abfd);
/* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
.rel[a].bss sections. */
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
| SEC_LINKER_CREATED);
s = bfd_make_section (abfd, ".plt");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s,
(flags | SEC_CODE
| (bed->plt_readonly ? SEC_READONLY : 0)))
|| ! bfd_set_section_alignment (abfd, s, 2))
return false;
if (bed->want_plt_sym)
{
/* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
.plt section. */
struct elf_link_hash_entry *h = NULL;
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
(bfd_vma) 0, (const char *) NULL, false,
get_elf_backend_data (abfd)->collect,
(struct bfd_link_hash_entry **) &h)))
return false;
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
h->type = STT_OBJECT;
if (info->shared
&& ! _bfd_elf_link_record_dynamic_symbol (info, h))
return false;
}
s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.plt" : ".rel.plt");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return false;
if (! _bfd_elf_create_got_section (abfd, info))
return false;
/* The .dynbss section is a place to put symbols which are defined
by dynamic objects, are referenced by regular objects, and are
not functions. We must allocate space for them in the process
image and use a R_*_COPY reloc to tell the dynamic linker to
initialize them at run time. The linker script puts the .dynbss
section into the .bss section of the final image. */
s = bfd_make_section (abfd, ".dynbss");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
return false;
/* The .rel[a].bss section holds copy relocs. This section is not
normally needed. We need to create it here, though, so that the
linker will map it to an output section. We can't just create it
only if we need it, because we will not know whether we need it
until we have seen all the input files, and the first time the
main linker code calls BFD after examining all the input files
(size_dynamic_sections) the input sections have already been
mapped to the output sections. If the section turns out not to
be needed, we can discard it later. We will never need this
section when generating a shared object, since they do not use
copy relocs. */
if (! info->shared)
{
s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.bss" : ".rel.bss");
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
|| ! bfd_set_section_alignment (abfd, s, 2))
return false;
}
return true;
}
/* Record a new dynamic symbol. We record the dynamic symbols as we
read the input files, since we need to have a list of all of them
before we can determine the final sizes of the output sections.
Note that we may actually call this function even though we are not
going to output any dynamic symbols; in some cases we know that a
symbol should be in the dynamic symbol table, but only if there is
one. */
boolean
_bfd_elf_link_record_dynamic_symbol (info, h)
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
{
if (h->dynindx == -1)
{
struct bfd_strtab_hash *dynstr;
char *p, *alc;
const char *name;
boolean copy;
bfd_size_type indx;
h->dynindx = elf_hash_table (info)->dynsymcount;
++elf_hash_table (info)->dynsymcount;
dynstr = elf_hash_table (info)->dynstr;
if (dynstr == NULL)
{
/* Create a strtab to hold the dynamic symbol names. */
elf_hash_table (info)->dynstr = dynstr = _bfd_elf_stringtab_init ();
if (dynstr == NULL)
return false;
}
/* We don't put any version information in the dynamic string
table. */
name = h->root.root.string;
p = strchr (name, ELF_VER_CHR);
if (p == NULL)
{
alc = NULL;
copy = false;
}
else
{
alc = bfd_malloc (p - name + 1);
if (alc == NULL)
return false;
strncpy (alc, name, p - name);
alc[p - name] = '\0';
name = alc;
copy = true;
}
indx = _bfd_stringtab_add (dynstr, name, true, copy);
if (alc != NULL)
free (alc);
if (indx == (bfd_size_type) -1)
return false;
h->dynstr_index = indx;
}
return true;
}
/* Create a special linker section, or return a pointer to a linker section already created */
elf_linker_section_t *
_bfd_elf_create_linker_section (abfd, info, which, defaults)
bfd *abfd;
struct bfd_link_info *info;
enum elf_linker_section_enum which;
elf_linker_section_t *defaults;
{
bfd *dynobj = elf_hash_table (info)->dynobj;
elf_linker_section_t *lsect;
/* Record the first bfd section that needs the special section */
if (!dynobj)
dynobj = elf_hash_table (info)->dynobj = abfd;
/* If this is the first time, create the section */
lsect = elf_linker_section (dynobj, which);
if (!lsect)
{
asection *s;
lsect = (elf_linker_section_t *)
bfd_alloc (dynobj, sizeof (elf_linker_section_t));
*lsect = *defaults;
elf_linker_section (dynobj, which) = lsect;
lsect->which = which;
lsect->hole_written_p = false;
/* See if the sections already exist */
lsect->section = s = bfd_get_section_by_name (dynobj, lsect->name);
if (!s || (s->flags & defaults->flags) != defaults->flags)
{
lsect->section = s = bfd_make_section_anyway (dynobj, lsect->name);
if (s == NULL)
return (elf_linker_section_t *)0;
bfd_set_section_flags (dynobj, s, defaults->flags);
bfd_set_section_alignment (dynobj, s, lsect->alignment);
}
else if (bfd_get_section_alignment (dynobj, s) < lsect->alignment)
bfd_set_section_alignment (dynobj, s, lsect->alignment);
s->_raw_size = align_power (s->_raw_size, lsect->alignment);
/* Is there a hole we have to provide? If so check whether the segment is
too big already */
if (lsect->hole_size)
{
lsect->hole_offset = s->_raw_size;
s->_raw_size += lsect->hole_size;
if (lsect->hole_offset > lsect->max_hole_offset)
{
(*_bfd_error_handler) ("%s: Section %s is already to large to put hole of %ld bytes in",
bfd_get_filename (abfd),
lsect->name,
(long)lsect->hole_size);
bfd_set_error (bfd_error_bad_value);
return (elf_linker_section_t *)0;
}
}
#ifdef DEBUG
fprintf (stderr, "Creating section %s, current size = %ld\n",
lsect->name, (long)s->_raw_size);
#endif
if (lsect->sym_name)
{
struct elf_link_hash_entry *h = NULL;
#ifdef DEBUG
fprintf (stderr, "Adding %s to section %s\n",
lsect->sym_name,
lsect->name);
#endif
h = (struct elf_link_hash_entry *)
bfd_link_hash_lookup (info->hash, lsect->sym_name, false, false, false);
if ((h == NULL || h->root.type == bfd_link_hash_undefined)
&& !(_bfd_generic_link_add_one_symbol (info,
abfd,
lsect->sym_name,
BSF_GLOBAL,
s,
((lsect->hole_size)
? s->_raw_size - lsect->hole_size + lsect->sym_offset
: lsect->sym_offset),
(const char *) NULL,
false,
get_elf_backend_data (abfd)->collect,
(struct bfd_link_hash_entry **) &h)))
return (elf_linker_section_t *)0;
if ((defaults->which != LINKER_SECTION_SDATA)
&& (defaults->which != LINKER_SECTION_SDATA2))
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_DYNAMIC;
h->type = STT_OBJECT;
lsect->sym_hash = h;
if (info->shared
&& ! _bfd_elf_link_record_dynamic_symbol (info, h))
return (elf_linker_section_t *)0;
}
}
#if 0
/* This does not make sense. The sections which may exist in the
object file have nothing to do with the sections we want to
create. */
/* Find the related sections if they have been created */
if (lsect->bss_name && !lsect->bss_section)
lsect->bss_section = bfd_get_section_by_name (dynobj, lsect->bss_name);
if (lsect->rel_name && !lsect->rel_section)
lsect->rel_section = bfd_get_section_by_name (dynobj, lsect->rel_name);
#endif
return lsect;
}
/* Find a linker generated pointer with a given addend and type. */
elf_linker_section_pointers_t *
_bfd_elf_find_pointer_linker_section (linker_pointers, addend, which)
elf_linker_section_pointers_t *linker_pointers;
bfd_signed_vma addend;
elf_linker_section_enum_t which;
{
for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
{
if (which == linker_pointers->which && addend == linker_pointers->addend)
return linker_pointers;
}
return (elf_linker_section_pointers_t *)0;
}
/* Make the .rela section corresponding to the generated linker section. */
boolean
_bfd_elf_make_linker_section_rela (dynobj, lsect, alignment)
bfd *dynobj;
elf_linker_section_t *lsect;
int alignment;
{
if (lsect->rel_section)
return true;
lsect->rel_section = bfd_get_section_by_name (dynobj, lsect->rel_name);
if (lsect->rel_section == NULL)
{
lsect->rel_section = bfd_make_section (dynobj, lsect->rel_name);
if (lsect->rel_section == NULL
|| ! bfd_set_section_flags (dynobj,
lsect->rel_section,
(SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
| SEC_READONLY))
|| ! bfd_set_section_alignment (dynobj, lsect->rel_section, alignment))
return false;
}
return true;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,491 @@
/* Target definitions for NN-bit ELF
Copyright 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This structure contains everything that BFD knows about a target.
It includes things like its byte order, name, what routines to call
to do various operations, etc. Every BFD points to a target structure
with its "xvec" member.
There are two such structures here: one for big-endian machines and
one for little-endian machines. */
#define bfd_elfNN_close_and_cleanup _bfd_generic_close_and_cleanup
#define bfd_elfNN_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
#ifndef bfd_elfNN_get_section_contents
#define bfd_elfNN_get_section_contents _bfd_generic_get_section_contents
#endif
#define bfd_elfNN_canonicalize_dynamic_symtab _bfd_elf_canonicalize_dynamic_symtab
#define bfd_elfNN_canonicalize_reloc _bfd_elf_canonicalize_reloc
#ifndef bfd_elfNN_find_nearest_line
#define bfd_elfNN_find_nearest_line _bfd_elf_find_nearest_line
#endif
#define bfd_elfNN_read_minisymbols _bfd_elf_read_minisymbols
#define bfd_elfNN_minisymbol_to_symbol _bfd_elf_minisymbol_to_symbol
#define bfd_elfNN_get_dynamic_symtab_upper_bound _bfd_elf_get_dynamic_symtab_upper_bound
#define bfd_elfNN_get_lineno _bfd_elf_get_lineno
#ifndef bfd_elfNN_get_reloc_upper_bound
#define bfd_elfNN_get_reloc_upper_bound _bfd_elf_get_reloc_upper_bound
#endif
#define bfd_elfNN_get_symbol_info _bfd_elf_get_symbol_info
#define bfd_elfNN_get_symtab _bfd_elf_get_symtab
#define bfd_elfNN_get_symtab_upper_bound _bfd_elf_get_symtab_upper_bound
#if 0 /* done in elf-bfd.h */
#define bfd_elfNN_link_record_dynamic_symbol _bfd_elf_link_record_dynamic_symbol
#endif
#define bfd_elfNN_make_empty_symbol _bfd_elf_make_empty_symbol
#define bfd_elfNN_new_section_hook _bfd_elf_new_section_hook
#define bfd_elfNN_set_arch_mach _bfd_elf_set_arch_mach
#ifndef bfd_elfNN_set_section_contents
#define bfd_elfNN_set_section_contents _bfd_elf_set_section_contents
#endif
#define bfd_elfNN_sizeof_headers _bfd_elf_sizeof_headers
#define bfd_elfNN_write_object_contents _bfd_elf_write_object_contents
#define bfd_elfNN_get_section_contents_in_window \
_bfd_generic_get_section_contents_in_window
#ifndef elf_backend_want_got_plt
#define elf_backend_want_got_plt 0
#endif
#ifndef elf_backend_plt_readonly
#define elf_backend_plt_readonly 0
#endif
#ifndef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
#endif
#define bfd_elfNN_bfd_debug_info_start bfd_void
#define bfd_elfNN_bfd_debug_info_end bfd_void
#define bfd_elfNN_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
#ifndef bfd_elfNN_bfd_get_relocated_section_contents
#define bfd_elfNN_bfd_get_relocated_section_contents \
bfd_generic_get_relocated_section_contents
#endif
#ifndef bfd_elfNN_bfd_relax_section
#define bfd_elfNN_bfd_relax_section bfd_generic_relax_section
#endif
#define bfd_elfNN_bfd_make_debug_symbol \
((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
#ifndef bfd_elfNN_bfd_copy_private_symbol_data
#define bfd_elfNN_bfd_copy_private_symbol_data \
_bfd_elf_copy_private_symbol_data
#endif
#ifndef bfd_elfNN_bfd_copy_private_section_data
#define bfd_elfNN_bfd_copy_private_section_data \
_bfd_elf_copy_private_section_data
#endif
#ifndef bfd_elfNN_bfd_copy_private_bfd_data
#define bfd_elfNN_bfd_copy_private_bfd_data \
((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
#endif
#ifndef bfd_elfNN_bfd_print_private_bfd_data
#define bfd_elfNN_bfd_print_private_bfd_data \
_bfd_elf_print_private_bfd_data
#endif
#ifndef bfd_elfNN_bfd_merge_private_bfd_data
#define bfd_elfNN_bfd_merge_private_bfd_data \
((boolean (*) PARAMS ((bfd *, bfd *))) bfd_true)
#endif
#ifndef bfd_elfNN_bfd_set_private_flags
#define bfd_elfNN_bfd_set_private_flags \
((boolean (*) PARAMS ((bfd *, flagword))) bfd_true)
#endif
#ifndef bfd_elfNN_bfd_is_local_label_name
#define bfd_elfNN_bfd_is_local_label_name _bfd_elf_is_local_label_name
#endif
#ifndef bfd_elfNN_get_dynamic_reloc_upper_bound
#define bfd_elfNN_get_dynamic_reloc_upper_bound \
_bfd_elf_get_dynamic_reloc_upper_bound
#endif
#ifndef bfd_elfNN_canonicalize_dynamic_reloc
#define bfd_elfNN_canonicalize_dynamic_reloc \
_bfd_elf_canonicalize_dynamic_reloc
#endif
#ifdef elf_backend_relocate_section
#ifndef bfd_elfNN_bfd_link_hash_table_create
#define bfd_elfNN_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
#endif
#else /* ! defined (elf_backend_relocate_section) */
/* If no backend relocate_section routine, use the generic linker. */
#ifndef bfd_elfNN_bfd_link_hash_table_create
#define bfd_elfNN_bfd_link_hash_table_create \
_bfd_generic_link_hash_table_create
#endif
#ifndef bfd_elfNN_bfd_link_add_symbols
#define bfd_elfNN_bfd_link_add_symbols _bfd_generic_link_add_symbols
#endif
#ifndef bfd_elfNN_bfd_final_link
#define bfd_elfNN_bfd_final_link _bfd_generic_final_link
#endif
#endif /* ! defined (elf_backend_relocate_section) */
#ifndef bfd_elfNN_bfd_link_split_section
#define bfd_elfNN_bfd_link_split_section _bfd_generic_link_split_section
#endif
#ifndef bfd_elfNN_archive_p
#define bfd_elfNN_archive_p bfd_generic_archive_p
#endif
#ifndef bfd_elfNN_write_archive_contents
#define bfd_elfNN_write_archive_contents _bfd_write_archive_contents
#endif
#ifndef bfd_elfNN_mkobject
#define bfd_elfNN_mkobject bfd_elf_mkobject
#endif
#ifndef bfd_elfNN_mkarchive
#define bfd_elfNN_mkarchive _bfd_generic_mkarchive
#endif
#ifndef elf_symbol_leading_char
#define elf_symbol_leading_char 0
#endif
#ifndef elf_info_to_howto
#define elf_info_to_howto 0
#endif
#ifndef elf_info_to_howto_rel
#define elf_info_to_howto_rel 0
#endif
#ifndef ELF_MAXPAGESIZE
#define ELF_MAXPAGESIZE 1
#endif
#ifndef elf_backend_collect
#define elf_backend_collect false
#endif
#ifndef elf_backend_type_change_ok
#define elf_backend_type_change_ok false
#endif
#ifndef elf_backend_sym_is_global
#define elf_backend_sym_is_global 0
#endif
#ifndef elf_backend_object_p
#define elf_backend_object_p 0
#endif
#ifndef elf_backend_symbol_processing
#define elf_backend_symbol_processing 0
#endif
#ifndef elf_backend_symbol_table_processing
#define elf_backend_symbol_table_processing 0
#endif
#ifndef elf_backend_section_processing
#define elf_backend_section_processing 0
#endif
#ifndef elf_backend_section_from_shdr
#define elf_backend_section_from_shdr 0
#endif
#ifndef elf_backend_fake_sections
#define elf_backend_fake_sections 0
#endif
#ifndef elf_backend_section_from_bfd_section
#define elf_backend_section_from_bfd_section 0
#endif
#ifndef elf_backend_add_symbol_hook
#define elf_backend_add_symbol_hook 0
#endif
#ifndef elf_backend_link_output_symbol_hook
#define elf_backend_link_output_symbol_hook 0
#endif
#ifndef elf_backend_create_dynamic_sections
#define elf_backend_create_dynamic_sections 0
#endif
#ifndef elf_backend_check_relocs
#define elf_backend_check_relocs 0
#endif
#ifndef elf_backend_adjust_dynamic_symbol
#define elf_backend_adjust_dynamic_symbol 0
#endif
#ifndef elf_backend_always_size_sections
#define elf_backend_always_size_sections 0
#endif
#ifndef elf_backend_size_dynamic_sections
#define elf_backend_size_dynamic_sections 0
#endif
#ifndef elf_backend_relocate_section
#define elf_backend_relocate_section 0
#endif
#ifndef elf_backend_finish_dynamic_symbol
#define elf_backend_finish_dynamic_symbol 0
#endif
#ifndef elf_backend_finish_dynamic_sections
#define elf_backend_finish_dynamic_sections 0
#endif
#ifndef elf_backend_begin_write_processing
#define elf_backend_begin_write_processing 0
#endif
#ifndef elf_backend_final_write_processing
#define elf_backend_final_write_processing 0
#endif
#ifndef elf_backend_additional_program_headers
#define elf_backend_additional_program_headers 0
#endif
#ifndef elf_backend_modify_segment_map
#define elf_backend_modify_segment_map 0
#endif
#ifndef elf_backend_ecoff_debug_swap
#define elf_backend_ecoff_debug_swap 0
#endif
#ifndef ELF_MACHINE_ALT1
#define ELF_MACHINE_ALT1 0
#endif
#ifndef ELF_MACHINE_ALT2
#define ELF_MACHINE_ALT2 0
#endif
#ifndef elf_backend_size_info
#define elf_backend_size_info _bfd_elfNN_size_info
#endif
extern const struct elf_size_info _bfd_elfNN_size_info;
static CONST struct elf_backend_data elfNN_bed =
{
#ifdef USE_REL
0, /* use_rela_p */
#else
1, /* use_rela_p */
#endif
ELF_ARCH, /* arch */
ELF_MACHINE_CODE, /* elf_machine_code */
ELF_MAXPAGESIZE, /* maxpagesize */
elf_backend_collect,
elf_backend_type_change_ok,
elf_info_to_howto,
elf_info_to_howto_rel,
elf_backend_sym_is_global,
elf_backend_object_p,
elf_backend_symbol_processing,
elf_backend_symbol_table_processing,
elf_backend_section_processing,
elf_backend_section_from_shdr,
elf_backend_fake_sections,
elf_backend_section_from_bfd_section,
elf_backend_add_symbol_hook,
elf_backend_link_output_symbol_hook,
elf_backend_create_dynamic_sections,
elf_backend_check_relocs,
elf_backend_adjust_dynamic_symbol,
elf_backend_always_size_sections,
elf_backend_size_dynamic_sections,
elf_backend_relocate_section,
elf_backend_finish_dynamic_symbol,
elf_backend_finish_dynamic_sections,
elf_backend_begin_write_processing,
elf_backend_final_write_processing,
elf_backend_additional_program_headers,
elf_backend_modify_segment_map,
elf_backend_ecoff_debug_swap,
ELF_MACHINE_ALT1,
ELF_MACHINE_ALT2,
&elf_backend_size_info,
elf_backend_want_got_plt,
elf_backend_plt_readonly,
elf_backend_want_plt_sym
};
#ifdef TARGET_BIG_SYM
const bfd_target TARGET_BIG_SYM =
{
/* name: identify kind of target */
TARGET_BIG_NAME,
/* flavour: general indication about file */
bfd_target_elf_flavour,
/* byteorder: data is big endian */
BFD_ENDIAN_BIG,
/* header_byteorder: header is also big endian */
BFD_ENDIAN_BIG,
/* object_flags: mask of all file flags */
(HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
DYNAMIC | WP_TEXT | D_PAGED),
/* section_flags: mask of all section flags */
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_EXCLUDE | SEC_SORT_ENTRIES),
/* leading_symbol_char: is the first char of a user symbol
predictable, and if so what is it */
elf_symbol_leading_char,
/* ar_pad_char: pad character for filenames within an archive header
FIXME: this really has nothing to do with ELF, this is a characteristic
of the archiver and/or os and should be independently tunable */
'/',
/* ar_max_namelen: maximum number of characters in an archive header
FIXME: this really has nothing to do with ELF, this is a characteristic
of the archiver and should be independently tunable. This value is
a WAG (wild a** guess) */
14,
/* Routines to byte-swap various sized integers from the data sections */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16,
/* Routines to byte-swap various sized integers from the file headers */
bfd_getb64, bfd_getb_signed_64, bfd_putb64,
bfd_getb32, bfd_getb_signed_32, bfd_putb32,
bfd_getb16, bfd_getb_signed_16, bfd_putb16,
/* bfd_check_format: check the format of a file being read */
{ _bfd_dummy_target, /* unknown format */
bfd_elfNN_object_p, /* assembler/linker output (object file) */
bfd_elfNN_archive_p, /* an archive */
bfd_elfNN_core_file_p /* a core file */
},
/* bfd_set_format: set the format of a file being written */
{ bfd_false,
bfd_elfNN_mkobject,
bfd_elfNN_mkarchive,
bfd_false
},
/* bfd_write_contents: write cached information into a file being written */
{ bfd_false,
bfd_elfNN_write_object_contents,
bfd_elfNN_write_archive_contents,
bfd_false
},
BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
BFD_JUMP_TABLE_COPY (bfd_elfNN),
BFD_JUMP_TABLE_CORE (bfd_elfNN),
#ifdef bfd_elfNN_archive_functions
BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
#else
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
#endif
BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
BFD_JUMP_TABLE_WRITE (bfd_elfNN),
BFD_JUMP_TABLE_LINK (bfd_elfNN),
BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
/* backend_data: */
(PTR) &elfNN_bed,
};
#endif
#ifdef TARGET_LITTLE_SYM
const bfd_target TARGET_LITTLE_SYM =
{
/* name: identify kind of target */
TARGET_LITTLE_NAME,
/* flavour: general indication about file */
bfd_target_elf_flavour,
/* byteorder: data is little endian */
BFD_ENDIAN_LITTLE,
/* header_byteorder: header is also little endian */
BFD_ENDIAN_LITTLE,
/* object_flags: mask of all file flags */
(HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
DYNAMIC | WP_TEXT | D_PAGED),
/* section_flags: mask of all section flags */
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_EXCLUDE | SEC_SORT_ENTRIES),
/* leading_symbol_char: is the first char of a user symbol
predictable, and if so what is it */
elf_symbol_leading_char,
/* ar_pad_char: pad character for filenames within an archive header
FIXME: this really has nothing to do with ELF, this is a characteristic
of the archiver and/or os and should be independently tunable */
'/',
/* ar_max_namelen: maximum number of characters in an archive header
FIXME: this really has nothing to do with ELF, this is a characteristic
of the archiver and should be independently tunable. This value is
a WAG (wild a** guess) */
14,
/* Routines to byte-swap various sized integers from the data sections */
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16,
/* Routines to byte-swap various sized integers from the file headers */
bfd_getl64, bfd_getl_signed_64, bfd_putl64,
bfd_getl32, bfd_getl_signed_32, bfd_putl32,
bfd_getl16, bfd_getl_signed_16, bfd_putl16,
/* bfd_check_format: check the format of a file being read */
{ _bfd_dummy_target, /* unknown format */
bfd_elfNN_object_p, /* assembler/linker output (object file) */
bfd_elfNN_archive_p, /* an archive */
bfd_elfNN_core_file_p /* a core file */
},
/* bfd_set_format: set the format of a file being written */
{ bfd_false,
bfd_elfNN_mkobject,
bfd_elfNN_mkarchive,
bfd_false
},
/* bfd_write_contents: write cached information into a file being written */
{ bfd_false,
bfd_elfNN_write_object_contents,
bfd_elfNN_write_archive_contents,
bfd_false
},
BFD_JUMP_TABLE_GENERIC (bfd_elfNN),
BFD_JUMP_TABLE_COPY (bfd_elfNN),
BFD_JUMP_TABLE_CORE (bfd_elfNN),
#ifdef bfd_elfNN_archive_functions
BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
#else
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
#endif
BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
BFD_JUMP_TABLE_RELOCS (bfd_elfNN),
BFD_JUMP_TABLE_WRITE (bfd_elfNN),
BFD_JUMP_TABLE_LINK (bfd_elfNN),
BFD_JUMP_TABLE_DYNAMIC (bfd_elfNN),
/* backend_data: */
(PTR) &elfNN_bed,
};
#endif

View File

@ -0,0 +1,194 @@
/* filemode.c -- make a string describing file modes
Copyright (C) 1985, 1990 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "sysdep.h"
#include <sys/types.h>
#include <sys/stat.h>
void mode_string ();
static char ftypelet ();
static void rwx ();
static void setst ();
/* filemodestring - fill in string STR with an ls-style ASCII
representation of the st_mode field of file stats block STATP.
10 characters are stored in STR; no terminating null is added.
The characters stored in STR are:
0 File type. 'd' for directory, 'c' for character
special, 'b' for block special, 'm' for multiplex,
'l' for symbolic link, 's' for socket, 'p' for fifo,
'-' for any other file type
1 'r' if the owner may read, '-' otherwise.
2 'w' if the owner may write, '-' otherwise.
3 'x' if the owner may execute, 's' if the file is
set-user-id, '-' otherwise.
'S' if the file is set-user-id, but the execute
bit isn't set.
4 'r' if group members may read, '-' otherwise.
5 'w' if group members may write, '-' otherwise.
6 'x' if group members may execute, 's' if the file is
set-group-id, '-' otherwise.
'S' if it is set-group-id but not executable.
7 'r' if any user may read, '-' otherwise.
8 'w' if any user may write, '-' otherwise.
9 'x' if any user may execute, 't' if the file is "sticky"
(will be retained in swap space after execution), '-'
otherwise.
'T' if the file is sticky but not executable. */
void
filemodestring (statp, str)
struct stat *statp;
char *str;
{
mode_string (statp->st_mode, str);
}
/* Like filemodestring, but only the relevant part of the `struct stat'
is given as an argument. */
void
mode_string (mode, str)
unsigned short mode;
char *str;
{
str[0] = ftypelet (mode);
rwx ((mode & 0700) << 0, &str[1]);
rwx ((mode & 0070) << 3, &str[4]);
rwx ((mode & 0007) << 6, &str[7]);
setst (mode, str);
}
/* Return a character indicating the type of file described by
file mode BITS:
'd' for directories
'b' for block special files
'c' for character special files
'm' for multiplexor files
'l' for symbolic links
's' for sockets
'p' for fifos
'-' for any other file type. */
static char
ftypelet (bits)
unsigned short bits;
{
switch (bits & S_IFMT)
{
default:
return '-';
case S_IFDIR:
return 'd';
#ifdef S_IFLNK
case S_IFLNK:
return 'l';
#endif
#ifdef S_IFCHR
case S_IFCHR:
return 'c';
#endif
#ifdef S_IFBLK
case S_IFBLK:
return 'b';
#endif
#ifdef S_IFMPC
case S_IFMPC:
case S_IFMPB:
return 'm';
#endif
#ifdef S_IFSOCK
case S_IFSOCK:
return 's';
#endif
#ifdef S_IFIFO
#if S_IFIFO != S_IFSOCK
case S_IFIFO:
return 'p';
#endif
#endif
#ifdef S_IFNWK /* HP-UX */
case S_IFNWK:
return 'n';
#endif
}
}
/* Look at read, write, and execute bits in BITS and set
flags in CHARS accordingly. */
static void
rwx (bits, chars)
unsigned short bits;
char *chars;
{
chars[0] = (bits & S_IREAD) ? 'r' : '-';
chars[1] = (bits & S_IWRITE) ? 'w' : '-';
chars[2] = (bits & S_IEXEC) ? 'x' : '-';
}
/* Set the 's' and 't' flags in file attributes string CHARS,
according to the file mode BITS. */
static void
setst (bits, chars)
unsigned short bits;
char *chars;
{
#ifdef S_ISUID
if (bits & S_ISUID)
{
if (chars[3] != 'x')
/* Set-uid, but not executable by owner. */
chars[3] = 'S';
else
chars[3] = 's';
}
#endif
#ifdef S_ISGID
if (bits & S_ISGID)
{
if (chars[6] != 'x')
/* Set-gid, but not executable by group. */
chars[6] = 'S';
else
chars[6] = 's';
}
#endif
#ifdef S_ISVTX
if (bits & S_ISVTX)
{
if (chars[9] != 'x')
/* Sticky, but not executable by others. */
chars[9] = 'T';
else
chars[9] = 't';
}
#endif
}

View File

@ -0,0 +1,319 @@
/* Generic BFD support for file formats.
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
SECTION
File formats
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"
/* IMPORT from targets.c. */
extern const size_t _bfd_target_vector_entries;
/*
FUNCTION
bfd_check_format
SYNOPSIS
boolean bfd_check_format(bfd *abfd, bfd_format format);
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:
o <<bfd_error_invalid_operation>> -
if <<format>> is not one of <<bfd_object>>, <<bfd_archive>> or
<<bfd_core>>.
o <<bfd_error_system_call>> -
if an error occured during a read - even some file mismatches
can cause bfd_error_system_calls.
o <<file_not_recognised>> -
none of the backends recognised the file format.
o <<bfd_error_file_ambiguously_recognized>> -
more than one backend recognised the file format.
*/
boolean
bfd_check_format (abfd, format)
bfd *abfd;
bfd_format format;
{
return bfd_check_format_matches (abfd, format, NULL);
}
/*
FUNCTION
bfd_check_format_matches
SYNOPSIS
boolean bfd_check_format_matches(bfd *abfd, bfd_format format, char ***matching);
DESCRIPTION
Like <<bfd_check_format>>, except when it returns false with
<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>. In that
case, if @var{matching} is not NULL, it will be filled in with
a NULL-terminated list of the names of the formats that matched,
allocated with <<malloc>>.
Then the user may choose a format and try again.
When done with the list that @var{matching} points to, the caller
should free it.
*/
boolean
bfd_check_format_matches (abfd, format, matching)
bfd *abfd;
bfd_format format;
char ***matching;
{
const bfd_target * const *target, *save_targ, *right_targ;
char **matching_vector = NULL;
int match_count;
if (!bfd_read_p (abfd) ||
((int)(abfd->format) < (int)bfd_unknown) ||
((int)(abfd->format) >= (int)bfd_type_end)) {
bfd_set_error (bfd_error_invalid_operation);
return false;
}
if (abfd->format != bfd_unknown)
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;
if (matching)
{
matching_vector =
(char **) bfd_malloc (sizeof (char *) *
(_bfd_target_vector_entries + 1));
if (!matching_vector)
return false;
matching_vector[0] = NULL;
*matching = matching_vector;
}
right_targ = 0;
/* presume the answer is yes */
abfd->format = format;
/* If the target type was explicitly specified, just check that target. */
if (!abfd->target_defaulted) {
if (bfd_seek (abfd, (file_ptr)0, SEEK_SET) != 0) /* rewind! */
return false;
right_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
if (right_targ) {
abfd->xvec = right_targ; /* Set the target as returned */
if (matching)
free (matching_vector);
return true; /* File position has moved, BTW */
}
}
for (target = bfd_target_vector; *target != NULL; target++) {
extern const bfd_target binary_vec;
const bfd_target *temp;
if (*target == &binary_vec)
continue;
abfd->xvec = *target; /* Change BFD's target temporarily */
if (bfd_seek (abfd, (file_ptr)0, SEEK_SET) != 0)
return false;
/* If _bfd_check_format neglects to set bfd_error, assume bfd_error_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_set_error (bfd_error_wrong_format);
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
if (temp) { /* This format checks out as ok! */
right_targ = temp;
if (matching)
{
matching_vector[match_count] = temp->name;
matching_vector[match_count + 1] = NULL;
}
match_count++;
/* If this is the default target, accept it, even if other targets
might match. People who want those other targets have to set
the GNUTARGET variable. */
if (temp == bfd_default_vector[0])
{
if (matching)
{
matching_vector[0] = temp->name;
matching_vector[1] = NULL;
}
match_count = 1;
break;
}
#ifdef GNU960
/* 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
* orders will (I hope) be handled appropriately by bfd. Ditto for big
* and little coff archives. And the 4 coff/b.out object formats are
* unambiguous. So accept the first match we find.
*/
break;
#endif
} else if (bfd_get_error () != bfd_error_wrong_format) {
abfd->xvec = save_targ;
abfd->format = bfd_unknown;
if (matching && bfd_get_error () != bfd_error_file_ambiguously_recognized)
free (matching_vector);
return false;
}
}
if (match_count == 1) {
abfd->xvec = right_targ; /* Change BFD's target permanently */
if (matching)
free (matching_vector);
return true; /* File position has moved, BTW */
}
abfd->xvec = save_targ; /* Restore original target type */
abfd->format = bfd_unknown; /* Restore original format */
if (match_count == 0)
{
bfd_set_error (bfd_error_file_not_recognized);
if (matching)
free (matching_vector);
}
else
bfd_set_error (bfd_error_file_ambiguously_recognized);
return false;
}
/*
FUNCTION
bfd_set_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
bfd_set_format (abfd, format)
bfd *abfd;
bfd_format format;
{
if (bfd_read_p (abfd) ||
((int)abfd->format < (int)bfd_unknown) ||
((int)abfd->format >= (int)bfd_type_end)) {
bfd_set_error (bfd_error_invalid_operation);
return false;
}
if (abfd->format != bfd_unknown)
return (abfd->format == format) ? true:false;
/* presume the answer is yes */
abfd->format = format;
if (!BFD_SEND_FMT (abfd, _bfd_set_format, (abfd))) {
abfd->format = bfd_unknown;
return false;
}
return true;
}
/*
FUNCTION
bfd_format_string
SYNOPSIS
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 *
bfd_format_string (format)
bfd_format format;
{
if (((int)format <(int) bfd_unknown)
|| ((int)format >=(int) bfd_type_end))
return "invalid";
switch (format) {
case bfd_object:
return "object"; /* linker/assember/compiler output */
case bfd_archive:
return "archive"; /* object archive file */
case bfd_core:
return "core"; /* core dump */
default:
return "unknown";
}
}

View File

@ -0,0 +1,110 @@
/* BFD back-end definitions used by all FreeBSD targets.
Copyright (C) 1990, 1991, 1992, 1996 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* FreeBSD ZMAGIC files never have the header in the text. */
#define N_HEADER_IN_TEXT(x) 0
/* ZMAGIC files start at offset 0. Does not apply to QMAGIC files. */
#define TEXT_START_ADDR 0
#define N_GETMAGIC_NET(exec) \
((exec).a_info & 0xffff)
#define N_GETMID_NET(exec) \
(((exec).a_info >> 16) & 0x3ff)
#define N_GETFLAG_NET(ex) \
(((exec).a_info >> 26) & 0x3f)
#define N_MACHTYPE(exec) \
((enum machine_type) \
((N_GETMAGIC_NET (exec) == ZMAGIC) ? N_GETMID_NET (exec) : \
((exec).a_info >> 16) & 0x3ff))
#define N_FLAGS(exec) \
((N_GETMAGIC_NET (exec) == ZMAGIC) ? N_GETFLAG_NET (exec) : \
((exec).a_info >> 26) & 0x3f)
#define N_SET_INFO(exec, magic, type, flags) \
((exec).a_info = ((magic) & 0xffff) \
| (((int)(type) & 0x3ff) << 16) \
| (((flags) & 0x3f) << 26))
#define N_SET_MACHTYPE(exec, machtype) \
((exec).a_info = \
((exec).a_info & 0xfb00ffff) | ((((int)(machtype))&0x3ff) << 16))
#define N_SET_FLAGS(exec, flags) \
((exec).a_info = \
((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "libaout.h"
/* On FreeBSD, the magic number is always in ntohl's "network" (big-endian)
format. I think. */
#define SWAP_MAGIC(ext) bfd_getb32 (ext)
#define MY_write_object_contents MY(write_object_contents)
static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
#include "aout-target.h"
/* Write an object file.
Section contents have already been written. We write the
file header, symbols, and relocation. */
static boolean
MY(write_object_contents) (abfd)
bfd *abfd;
{
struct external_exec exec_bytes;
struct internal_exec *execp = exec_hdr (abfd);
#if CHOOSE_RELOC_SIZE
CHOOSE_RELOC_SIZE(abfd);
#else
obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
#endif
/* Magic number, maestro, please! */
switch (bfd_get_arch(abfd)) {
case bfd_arch_m68k:
if (strcmp (abfd->xvec->name, "a.out-m68k4k-netbsd") == 0)
N_SET_MACHTYPE(*execp, M_68K4K_NETBSD);
else
N_SET_MACHTYPE(*execp, M_68K_NETBSD);
break;
case bfd_arch_sparc:
N_SET_MACHTYPE(*execp, M_SPARC_NETBSD);
break;
case bfd_arch_i386:
N_SET_MACHTYPE(*execp, M_386_NETBSD);
break;
case bfd_arch_ns32k:
N_SET_MACHTYPE(*execp, M_532_NETBSD);
break;
default:
N_SET_MACHTYPE(*execp, M_UNKNOWN);
break;
}
WRITE_HEADERS(abfd, execp);
return true;
}

View File

@ -0,0 +1,101 @@
/* Generate parameters for an a.out system.
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "/usr/include/a.out.h"
#include <stdio.h>
int
main (argc, argv)
int argc; char** argv;
{
struct exec my_exec;
int page_size;
char *target = "unknown", *arch = "unknown";
FILE *file = fopen("gen-aout", "r");
if (file == NULL) {
fprintf(stderr, "Cannot open gen-aout!\n");
return -1;
}
if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
fprintf(stderr, "Cannot read gen-aout!\n");
return -1;
}
target = argv[1];
if (target == NULL) {
fprintf(stderr, "Usage: gen-aout target_name\n");
exit (1);
}
#ifdef N_TXTOFF
page_size = N_TXTOFF(my_exec);
if (page_size == 0)
printf("#define N_HEADER_IN_TEXT(x) 1\n");
else
printf("#define N_HEADER_IN_TEXT(x) 0\n");
#endif
printf("#define BYTES_IN_WORD %d\n", sizeof (int));
if (my_exec.a_entry == 0) {
printf("#define ENTRY_CAN_BE_ZERO\n");
printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
}
else {
printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
printf("/*#define N_SHARED_LIB(x) 0*/\n");
}
printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
#ifdef PAGSIZ
if (page_size == 0)
page_size = PAGSIZ;
#endif
if (page_size != 0)
printf("#define TARGET_PAGE_SIZE %d\n", page_size);
else
printf("/* #define TARGET_PAGE_SIZE ??? */\n");
printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
#ifdef vax
arch = "vax";
#endif
#ifdef m68k
arch = "m68k";
#endif
if (arch[0] == '1')
{
fprintf (stderr, "warning: preprocessor substituted architecture name inside string;");
fprintf (stderr, " fix DEFAULT_ARCH in the output file yourself\n");
arch = "unknown";
}
printf("#define DEFAULT_ARCH bfd_arch_%s\n", arch);
printf("\n#define MY(OP) CAT(%s_,OP)\n", target);
printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
printf("#include \"bfd.h\"\n");
printf("#include \"sysdep.h\"\n");
printf("#include \"libbfd.h\"\n");
printf("#include \"libaout.h\"\n");
printf("\n#include \"aout-target.h\"\n");
return 0;
}

View File

@ -0,0 +1,111 @@
/* genlink.h -- interface to the BFD generic linker
Copyright 1993, 1994 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef GENLINK_H
#define GENLINK_H
/* This header file is internal to BFD. It describes the internal
structures and functions used by the BFD generic linker, in case
any of the more specific linkers want to use or call them. Note
that some functions, such as _bfd_generic_link_hash_table_create,
are declared in libbfd.h, because they are expected to be widely
used. The functions and structures in this file will probably only
be used by a few files besides linker.c itself. In fact, this file
is not particularly complete; I have only put in the interfaces I
actually needed. */
/* The generic linker uses a hash table which is a derived class of
the standard linker hash table, just as the other backend specific
linkers do. Do not confuse the generic linker hash table with the
standard BFD linker hash table it is built upon. */
/* Generic linker hash table entries. */
struct generic_link_hash_entry
{
struct bfd_link_hash_entry root;
/* Whether this symbol has been written out. */
boolean written;
/* Symbol from input BFD. */
asymbol *sym;
};
/* Generic linker hash table. */
struct generic_link_hash_table
{
struct bfd_link_hash_table root;
};
/* Look up an entry in an generic link hash table. */
#define _bfd_generic_link_hash_lookup(table, string, create, copy, follow) \
((struct generic_link_hash_entry *) \
bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
/* Traverse an generic link hash table. */
#define _bfd_generic_link_hash_traverse(table, func, info) \
(bfd_link_hash_traverse \
(&(table)->root, \
(boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
(info)))
/* Get the generic link hash table from the info structure. This is
just a cast. */
#define _bfd_generic_hash_table(p) \
((struct generic_link_hash_table *) ((p)->hash))
/* The generic linker reads in the asymbol structures for an input BFD
and keeps them in the outsymbol and symcount fields. */
#define _bfd_generic_link_get_symbols(abfd) ((abfd)->outsymbols)
#define _bfd_generic_link_get_symcount(abfd) ((abfd)->symcount)
/* Add the symbols of input_bfd to the symbols being built for
output_bfd. */
extern boolean _bfd_generic_link_output_symbols
PARAMS ((bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *,
size_t *psymalloc));
/* This structure is used to pass information to
_bfd_generic_link_write_global_symbol, which may be called via
_bfd_generic_link_hash_traverse. */
struct generic_write_global_symbol_info
{
struct bfd_link_info *info;
bfd *output_bfd;
size_t *psymalloc;
};
/* Write out a single global symbol. This is expected to be called
via _bfd_generic_link_hash_traverse. The second argument must
actually be a struct generic_write_global_symbol_info *. */
extern boolean _bfd_generic_link_write_global_symbol
PARAMS ((struct generic_link_hash_entry *, PTR));
/* Generic link hash table entry creation routine. */
struct bfd_hash_entry *_bfd_generic_link_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
const char *));
#endif

734
contrib/binutils/bfd/hash.c Normal file
View File

@ -0,0 +1,734 @@
/* hash.c -- hash table routines for BFD
Copyright (C) 1993, 94, 95, 1997 Free Software Foundation, Inc.
Written by Steve Chamberlain <sac@cygnus.com>
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "objalloc.h"
/*
SECTION
Hash Tables
@cindex Hash tables
BFD provides a simple set of hash table functions. Routines
are provided to initialize a hash table, to free a hash table,
to look up a string in a hash table and optionally create an
entry for it, and to traverse a hash table. There is
currently no routine to delete an string from a hash table.
The basic hash table does not permit any data to be stored
with a string. However, a hash table is designed to present a
base class from which other types of hash tables may be
derived. These derived types may store additional information
with the string. Hash tables were implemented in this way,
rather than simply providing a data pointer in a hash table
entry, because they were designed for use by the linker back
ends. The linker may create thousands of hash table entries,
and the overhead of allocating private data and storing and
following pointers becomes noticeable.
The basic hash table code is in <<hash.c>>.
@menu
@* Creating and Freeing a Hash Table::
@* Looking Up or Entering a String::
@* Traversing a Hash Table::
@* Deriving a New Hash Table Type::
@end menu
INODE
Creating and Freeing a Hash Table, Looking Up or Entering a String, Hash Tables, Hash Tables
SUBSECTION
Creating and freeing a hash table
@findex bfd_hash_table_init
@findex bfd_hash_table_init_n
To create a hash table, create an instance of a <<struct
bfd_hash_table>> (defined in <<bfd.h>>) and call
<<bfd_hash_table_init>> (if you know approximately how many
entries you will need, the function <<bfd_hash_table_init_n>>,
which takes a @var{size} argument, may be used).
<<bfd_hash_table_init>> returns <<false>> if some sort of
error occurs.
@findex bfd_hash_newfunc
The function <<bfd_hash_table_init>> take as an argument a
function to use to create new entries. For a basic hash
table, use the function <<bfd_hash_newfunc>>. @xref{Deriving
a New Hash Table Type} for why you would want to use a
different value for this argument.
@findex bfd_hash_allocate
<<bfd_hash_table_init>> will create an objalloc which will be
used to allocate new entries. You may allocate memory on this
objalloc using <<bfd_hash_allocate>>.
@findex bfd_hash_table_free
Use <<bfd_hash_table_free>> to free up all the memory that has
been allocated for a hash table. This will not free up the
<<struct bfd_hash_table>> itself, which you must provide.
INODE
Looking Up or Entering a String, Traversing a Hash Table, Creating and Freeing a Hash Table, Hash Tables
SUBSECTION
Looking up or entering a string
@findex bfd_hash_lookup
The function <<bfd_hash_lookup>> is used both to look up a
string in the hash table and to create a new entry.
If the @var{create} argument is <<false>>, <<bfd_hash_lookup>>
will look up a string. If the string is found, it will
returns a pointer to a <<struct bfd_hash_entry>>. If the
string is not found in the table <<bfd_hash_lookup>> will
return <<NULL>>. You should not modify any of the fields in
the returns <<struct bfd_hash_entry>>.
If the @var{create} argument is <<true>>, the string will be
entered into the hash table if it is not already there.
Either way a pointer to a <<struct bfd_hash_entry>> will be
returned, either to the existing structure or to a newly
created one. In this case, a <<NULL>> return means that an
error occurred.
If the @var{create} argument is <<true>>, and a new entry is
created, the @var{copy} argument is used to decide whether to
copy the string onto the hash table objalloc or not. If
@var{copy} is passed as <<false>>, you must be careful not to
deallocate or modify the string as long as the hash table
exists.
INODE
Traversing a Hash Table, Deriving a New Hash Table Type, Looking Up or Entering a String, Hash Tables
SUBSECTION
Traversing a hash table
@findex bfd_hash_traverse
The function <<bfd_hash_traverse>> may be used to traverse a
hash table, calling a function on each element. The traversal
is done in a random order.
<<bfd_hash_traverse>> takes as arguments a function and a
generic <<void *>> pointer. The function is called with a
hash table entry (a <<struct bfd_hash_entry *>>) and the
generic pointer passed to <<bfd_hash_traverse>>. The function
must return a <<boolean>> value, which indicates whether to
continue traversing the hash table. If the function returns
<<false>>, <<bfd_hash_traverse>> will stop the traversal and
return immediately.
INODE
Deriving a New Hash Table Type, , Traversing a Hash Table, Hash Tables
SUBSECTION
Deriving a new hash table type
Many uses of hash tables want to store additional information
which each entry in the hash table. Some also find it
convenient to store additional information with the hash table
itself. This may be done using a derived hash table.
Since C is not an object oriented language, creating a derived
hash table requires sticking together some boilerplate
routines with a few differences specific to the type of hash
table you want to create.
An example of a derived hash table is the linker hash table.
The structures for this are defined in <<bfdlink.h>>. The
functions are in <<linker.c>>.
You may also derive a hash table from an already derived hash
table. For example, the a.out linker backend code uses a hash
table derived from the linker hash table.
@menu
@* Define the Derived Structures::
@* Write the Derived Creation Routine::
@* Write Other Derived Routines::
@end menu
INODE
Define the Derived Structures, Write the Derived Creation Routine, Deriving a New Hash Table Type, Deriving a New Hash Table Type
SUBSUBSECTION
Define the derived structures
You must define a structure for an entry in the hash table,
and a structure for the hash table itself.
The first field in the structure for an entry in the hash
table must be of the type used for an entry in the hash table
you are deriving from. If you are deriving from a basic hash
table this is <<struct bfd_hash_entry>>, which is defined in
<<bfd.h>>. The first field in the structure for the hash
table itself must be of the type of the hash table you are
deriving from itself. If you are deriving from a basic hash
table, this is <<struct bfd_hash_table>>.
For example, the linker hash table defines <<struct
bfd_link_hash_entry>> (in <<bfdlink.h>>). The first field,
<<root>>, is of type <<struct bfd_hash_entry>>. Similarly,
the first field in <<struct bfd_link_hash_table>>, <<table>>,
is of type <<struct bfd_hash_table>>.
INODE
Write the Derived Creation Routine, Write Other Derived Routines, Define the Derived Structures, Deriving a New Hash Table Type
SUBSUBSECTION
Write the derived creation routine
You must write a routine which will create and initialize an
entry in the hash table. This routine is passed as the
function argument to <<bfd_hash_table_init>>.
In order to permit other hash tables to be derived from the
hash table you are creating, this routine must be written in a
standard way.
The first argument to the creation routine is a pointer to a
hash table entry. This may be <<NULL>>, in which case the
routine should allocate the right amount of space. Otherwise
the space has already been allocated by a hash table type
derived from this one.
After allocating space, the creation routine must call the
creation routine of the hash table type it is derived from,
passing in a pointer to the space it just allocated. This
will initialize any fields used by the base hash table.
Finally the creation routine must initialize any local fields
for the new hash table type.
Here is a boilerplate example of a creation routine.
@var{function_name} is the name of the routine.
@var{entry_type} is the type of an entry in the hash table you
are creating. @var{base_newfunc} is the name of the creation
routine of the hash table type your hash table is derived
from.
EXAMPLE
.struct bfd_hash_entry *
.@var{function_name} (entry, table, string)
. struct bfd_hash_entry *entry;
. struct bfd_hash_table *table;
. const char *string;
.{
. struct @var{entry_type} *ret = (@var{entry_type} *) entry;
.
. {* Allocate the structure if it has not already been allocated by a
. derived class. *}
. if (ret == (@var{entry_type} *) NULL)
. {
. ret = ((@var{entry_type} *)
. bfd_hash_allocate (table, sizeof (@var{entry_type})));
. if (ret == (@var{entry_type} *) NULL)
. return NULL;
. }
.
. {* Call the allocation method of the base class. *}
. ret = ((@var{entry_type} *)
. @var{base_newfunc} ((struct bfd_hash_entry *) ret, table, string));
.
. {* Initialize the local fields here. *}
.
. return (struct bfd_hash_entry *) ret;
.}
DESCRIPTION
The creation routine for the linker hash table, which is in
<<linker.c>>, looks just like this example.
@var{function_name} is <<_bfd_link_hash_newfunc>>.
@var{entry_type} is <<struct bfd_link_hash_entry>>.
@var{base_newfunc} is <<bfd_hash_newfunc>>, the creation
routine for a basic hash table.
<<_bfd_link_hash_newfunc>> also initializes the local fields
in a linker hash table entry: <<type>>, <<written>> and
<<next>>.
INODE
Write Other Derived Routines, , Write the Derived Creation Routine, Deriving a New Hash Table Type
SUBSUBSECTION
Write other derived routines
You will want to write other routines for your new hash table,
as well.
You will want an initialization routine which calls the
initialization routine of the hash table you are deriving from
and initializes any other local fields. For the linker hash
table, this is <<_bfd_link_hash_table_init>> in <<linker.c>>.
You will want a lookup routine which calls the lookup routine
of the hash table you are deriving from and casts the result.
The linker hash table uses <<bfd_link_hash_lookup>> in
<<linker.c>> (this actually takes an additional argument which
it uses to decide how to return the looked up value).
You may want a traversal routine. This should just call the
traversal routine of the hash table you are deriving from with
appropriate casts. The linker hash table uses
<<bfd_link_hash_traverse>> in <<linker.c>>.
These routines may simply be defined as macros. For example,
the a.out backend linker hash table, which is derived from the
linker hash table, uses macros for the lookup and traversal
routines. These are <<aout_link_hash_lookup>> and
<<aout_link_hash_traverse>> in aoutx.h.
*/
/* The default number of entries to use when creating a hash table. */
#define DEFAULT_SIZE (4051)
/* Create a new hash table, given a number of entries. */
boolean
bfd_hash_table_init_n (table, newfunc, size)
struct bfd_hash_table *table;
struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *));
unsigned int size;
{
unsigned int alloc;
alloc = size * sizeof (struct bfd_hash_entry *);
table->memory = (PTR) objalloc_create ();
if (table->memory == NULL)
{
bfd_set_error (bfd_error_no_memory);
return false;
}
table->table = ((struct bfd_hash_entry **)
objalloc_alloc ((struct objalloc *) table->memory, alloc));
if (table->table == NULL)
{
bfd_set_error (bfd_error_no_memory);
return false;
}
memset ((PTR) table->table, 0, alloc);
table->size = size;
table->newfunc = newfunc;
return true;
}
/* Create a new hash table with the default number of entries. */
boolean
bfd_hash_table_init (table, newfunc)
struct bfd_hash_table *table;
struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *));
{
return bfd_hash_table_init_n (table, newfunc, DEFAULT_SIZE);
}
/* Free a hash table. */
void
bfd_hash_table_free (table)
struct bfd_hash_table *table;
{
objalloc_free ((struct objalloc *) table->memory);
table->memory = NULL;
}
/* Look up a string in a hash table. */
struct bfd_hash_entry *
bfd_hash_lookup (table, string, create, copy)
struct bfd_hash_table *table;
const char *string;
boolean create;
boolean copy;
{
register const unsigned char *s;
register unsigned long hash;
register unsigned int c;
struct bfd_hash_entry *hashp;
unsigned int len;
unsigned int index;
hash = 0;
len = 0;
s = (const unsigned char *) string;
while ((c = *s++) != '\0')
{
hash += c + (c << 17);
hash ^= hash >> 2;
++len;
}
hash += len + (len << 17);
hash ^= hash >> 2;
index = hash % table->size;
for (hashp = table->table[index];
hashp != (struct bfd_hash_entry *) NULL;
hashp = hashp->next)
{
if (hashp->hash == hash
&& strcmp (hashp->string, string) == 0)
return hashp;
}
if (! create)
return (struct bfd_hash_entry *) NULL;
hashp = (*table->newfunc) ((struct bfd_hash_entry *) NULL, table, string);
if (hashp == (struct bfd_hash_entry *) NULL)
return (struct bfd_hash_entry *) NULL;
if (copy)
{
char *new;
new = (char *) objalloc_alloc ((struct objalloc *) table->memory,
len + 1);
if (!new)
{
bfd_set_error (bfd_error_no_memory);
return (struct bfd_hash_entry *) NULL;
}
strcpy (new, string);
string = new;
}
hashp->string = string;
hashp->hash = hash;
hashp->next = table->table[index];
table->table[index] = hashp;
return hashp;
}
/* Replace an entry in a hash table. */
void
bfd_hash_replace (table, old, nw)
struct bfd_hash_table *table;
struct bfd_hash_entry *old;
struct bfd_hash_entry *nw;
{
unsigned int index;
struct bfd_hash_entry **pph;
index = old->hash % table->size;
for (pph = &table->table[index];
(*pph) != (struct bfd_hash_entry *) NULL;
pph = &(*pph)->next)
{
if (*pph == old)
{
*pph = nw;
return;
}
}
abort ();
}
/* Base method for creating a new hash table entry. */
/*ARGSUSED*/
struct bfd_hash_entry *
bfd_hash_newfunc (entry, table, string)
struct bfd_hash_entry *entry;
struct bfd_hash_table *table;
const char *string;
{
if (entry == (struct bfd_hash_entry *) NULL)
entry = ((struct bfd_hash_entry *)
bfd_hash_allocate (table, sizeof (struct bfd_hash_entry)));
return entry;
}
/* Allocate space in a hash table. */
PTR
bfd_hash_allocate (table, size)
struct bfd_hash_table *table;
unsigned int size;
{
PTR ret;
ret = objalloc_alloc ((struct objalloc *) table->memory, size);
if (ret == NULL && size != 0)
bfd_set_error (bfd_error_no_memory);
return ret;
}
/* Traverse a hash table. */
void
bfd_hash_traverse (table, func, info)
struct bfd_hash_table *table;
boolean (*func) PARAMS ((struct bfd_hash_entry *, PTR));
PTR info;
{
unsigned int i;
for (i = 0; i < table->size; i++)
{
struct bfd_hash_entry *p;
for (p = table->table[i]; p != NULL; p = p->next)
{
if (! (*func) (p, info))
return;
}
}
}
/* A few different object file formats (a.out, COFF, ELF) use a string
table. These functions support adding strings to a string table,
returning the byte offset, and writing out the table.
Possible improvements:
+ look for strings matching trailing substrings of other strings
+ better data structures? balanced trees?
+ look at reducing memory use elsewhere -- maybe if we didn't have
to construct the entire symbol table at once, we could get by
with smaller amounts of VM? (What effect does that have on the
string table reductions?) */
/* An entry in the strtab hash table. */
struct strtab_hash_entry
{
struct bfd_hash_entry root;
/* Index in string table. */
bfd_size_type index;
/* Next string in strtab. */
struct strtab_hash_entry *next;
};
/* The strtab hash table. */
struct bfd_strtab_hash
{
struct bfd_hash_table table;
/* Size of strtab--also next available index. */
bfd_size_type size;
/* First string in strtab. */
struct strtab_hash_entry *first;
/* Last string in strtab. */
struct strtab_hash_entry *last;
/* Whether to precede strings with a two byte length, as in the
XCOFF .debug section. */
boolean xcoff;
};
static struct bfd_hash_entry *strtab_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
/* Routine to create an entry in a strtab. */
static struct bfd_hash_entry *
strtab_hash_newfunc (entry, table, string)
struct bfd_hash_entry *entry;
struct bfd_hash_table *table;
const char *string;
{
struct strtab_hash_entry *ret = (struct strtab_hash_entry *) entry;
/* Allocate the structure if it has not already been allocated by a
subclass. */
if (ret == (struct strtab_hash_entry *) NULL)
ret = ((struct strtab_hash_entry *)
bfd_hash_allocate (table, sizeof (struct strtab_hash_entry)));
if (ret == (struct strtab_hash_entry *) NULL)
return NULL;
/* Call the allocation method of the superclass. */
ret = ((struct strtab_hash_entry *)
bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
if (ret)
{
/* Initialize the local fields. */
ret->index = (bfd_size_type) -1;
ret->next = NULL;
}
return (struct bfd_hash_entry *) ret;
}
/* Look up an entry in an strtab. */
#define strtab_hash_lookup(t, string, create, copy) \
((struct strtab_hash_entry *) \
bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
/* Create a new strtab. */
struct bfd_strtab_hash *
_bfd_stringtab_init ()
{
struct bfd_strtab_hash *table;
table = ((struct bfd_strtab_hash *)
bfd_malloc (sizeof (struct bfd_strtab_hash)));
if (table == NULL)
return NULL;
if (! bfd_hash_table_init (&table->table, strtab_hash_newfunc))
{
free (table);
return NULL;
}
table->size = 0;
table->first = NULL;
table->last = NULL;
table->xcoff = false;
return table;
}
/* Create a new strtab in which the strings are output in the format
used in the XCOFF .debug section: a two byte length precedes each
string. */
struct bfd_strtab_hash *
_bfd_xcoff_stringtab_init ()
{
struct bfd_strtab_hash *ret;
ret = _bfd_stringtab_init ();
if (ret != NULL)
ret->xcoff = true;
return ret;
}
/* Free a strtab. */
void
_bfd_stringtab_free (table)
struct bfd_strtab_hash *table;
{
bfd_hash_table_free (&table->table);
free (table);
}
/* Get the index of a string in a strtab, adding it if it is not
already present. If HASH is false, we don't really use the hash
table, and we don't eliminate duplicate strings. */
bfd_size_type
_bfd_stringtab_add (tab, str, hash, copy)
struct bfd_strtab_hash *tab;
const char *str;
boolean hash;
boolean copy;
{
register struct strtab_hash_entry *entry;
if (hash)
{
entry = strtab_hash_lookup (tab, str, true, copy);
if (entry == NULL)
return (bfd_size_type) -1;
}
else
{
entry = ((struct strtab_hash_entry *)
bfd_hash_allocate (&tab->table,
sizeof (struct strtab_hash_entry)));
if (entry == NULL)
return (bfd_size_type) -1;
if (! copy)
entry->root.string = str;
else
{
char *n;
n = (char *) bfd_hash_allocate (&tab->table, strlen (str) + 1);
if (n == NULL)
return (bfd_size_type) -1;
entry->root.string = n;
}
entry->index = (bfd_size_type) -1;
entry->next = NULL;
}
if (entry->index == (bfd_size_type) -1)
{
entry->index = tab->size;
tab->size += strlen (str) + 1;
if (tab->xcoff)
{
entry->index += 2;
tab->size += 2;
}
if (tab->first == NULL)
tab->first = entry;
else
tab->last->next = entry;
tab->last = entry;
}
return entry->index;
}
/* Get the number of bytes in a strtab. */
bfd_size_type
_bfd_stringtab_size (tab)
struct bfd_strtab_hash *tab;
{
return tab->size;
}
/* Write out a strtab. ABFD must already be at the right location in
the file. */
boolean
_bfd_stringtab_emit (abfd, tab)
register bfd *abfd;
struct bfd_strtab_hash *tab;
{
register boolean xcoff;
register struct strtab_hash_entry *entry;
xcoff = tab->xcoff;
for (entry = tab->first; entry != NULL; entry = entry->next)
{
register const char *str;
register size_t len;
str = entry->root.string;
len = strlen (str) + 1;
if (xcoff)
{
bfd_byte buf[2];
/* The output length includes the null byte. */
bfd_put_16 (abfd, len, buf);
if (bfd_write ((PTR) buf, 1, 2, abfd) != 2)
return false;
}
if (bfd_write ((PTR) str, 1, len, abfd) != len)
return false;
}
return true;
}

View File

@ -0,0 +1,83 @@
/* BFD backend for local host's a.out binaries
Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
Written by Cygnus Support. Probably John Gilmore's fault.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#define ARCH_SIZE 32
/* When porting to a new system, you must supply:
HOST_PAGE_SIZE (optional)
HOST_SEGMENT_SIZE (optional -- defaults to page size)
HOST_MACHINE_ARCH (optional)
HOST_MACHINE_MACHINE (optional)
HOST_TEXT_START_ADDR (optional)
HOST_STACK_END_ADDR (not used, except by trad-core ???)
HOST_BIG_ENDIAN_P (required -- define if big-endian)
in the ./hosts/h-systemname.h file. */
#ifdef TRAD_HEADER
#include TRAD_HEADER
#endif
#ifdef HOST_PAGE_SIZE
#define TARGET_PAGE_SIZE HOST_PAGE_SIZE
#endif
#ifdef HOST_SEGMENT_SIZE
#define SEGMENT_SIZE HOST_SEGMENT_SIZE
#else
#define SEGMENT_SIZE TARGET_PAGE_SIZE
#endif
#ifdef HOST_TEXT_START_ADDR
#define TEXT_START_ADDR HOST_TEXT_START_ADDR
#endif
#ifdef HOST_STACK_END_ADDR
#define STACK_END_ADDR HOST_STACK_END_ADDR
#endif
#ifdef HOST_BIG_ENDIAN_P
#define TARGET_IS_BIG_ENDIAN_P
#else
#undef TARGET_IS_BIG_ENDIAN_P
#endif
#include "libaout.h" /* BFD a.out internal data structures */
#include "aout/aout64.h"
#ifdef HOST_MACHINE_ARCH
#ifdef HOST_MACHINE_MACHINE
#define SET_ARCH_MACH(abfd, execp) \
bfd_default_set_arch_mach(abfd, HOST_MACHINE_ARCH, HOST_MACHINE_MACHINE)
#else
#define SET_ARCH_MACH(abfd, execp) \
bfd_default_set_arch_mach(abfd, HOST_MACHINE_ARCH, 0)
#endif
#endif /* HOST_MACHINE_ARCH */
#define MY(OP) CAT(host_aout_,OP)
#define TARGETNAME "a.out"
#include "aout-target.h"

View File

@ -0,0 +1,6 @@
/* Linux dumps "struct task_struct" at the end of the core-file. This
structure is currently 920 bytes long, but we allow up to 1024
bytes to allow for some future growth. */
#define TRAD_CORE_EXTRA_SIZE_ALLOWED 1024
#define TRAD_UNIX_CORE_FILE_FAILING_SIGNAL(abfd) \
((abfd)->tdata.trad_core_data->u.signal)

View File

@ -0,0 +1,32 @@
/* Intel 386 running any BSD Unix */
#include <machine/param.h>
#include <machine/vmparam.h>
/* Recent versions of FreeBSD don't define NBPG. */
#ifndef NBPG
#ifdef PAGE_SIZE
#define NBPG PAGE_SIZE
#endif
#endif
#define HOST_PAGE_SIZE NBPG
#define HOST_MACHINE_ARCH bfd_arch_i386
#define HOST_TEXT_START_ADDR USRTEXT
/* Jolitz suggested defining HOST_STACK_END_ADDR to
(u.u_kproc.kp_eproc.e_vm.vm_maxsaddr + MAXSSIZ), which should work on
both BSDI and 386BSD, but that is believed not to work for BSD 4.4. */
#ifdef __bsdi__
/* This seems to be the right thing for BSDI. */
#define HOST_STACK_END_ADDR USRSTACK
#define HOST_DATA_START_ADDR ((bfd_vma)u.u_kproc.kp_eproc.e_vm.vm_daddr)
#else
/* This seems to be the right thing for 386BSD release 0.1. */
#define HOST_STACK_END_ADDR (USRSTACK - MAXSSIZ)
#endif
#define TRAD_UNIX_CORE_FILE_FAILING_SIGNAL(core_bfd) \
((core_bfd)->tdata.trad_core_data->u.u_sig)
#define u_comm u_kproc.kp_proc.p_comm

View File

@ -0,0 +1,8 @@
/* Linux writes the task structure at the end of the core file. Currently it
is 2912 bytes. It is possible that this should be a pickier check, but
we should probably not be too picky (the size of the task structure might
vary, and if it's not the length we expect it to be, it doesn't affect
our ability to process the core file). So allow 0-4096 extra bytes at
the end. */
#define TRAD_CORE_EXTRA_SIZE_ALLOWED 4096

View File

@ -0,0 +1,19 @@
/* Core file stuff. At least some, perhaps all, of the following
defines work on many more systems than just SCO. */
#define NBPG NBPC
#define UPAGES USIZE
#define HOST_DATA_START_ADDR u.u_exdata.ux_datorg
#define HOST_STACK_START_ADDR u.u_sub
#define TRAD_UNIX_CORE_FILE_FAILING_SIGNAL(abfd) \
((core_upage(abfd)->u_sysabort != 0) \
? core_upage(abfd)->u_sysabort \
: -1)
/* According to the manpage, a version 2 SCO corefile can contain
various additional sections (it is cleverly arranged so the u area,
data, and stack are first where we can find them). So without
writing lots of code to parse all their headers and stuff, we can't
know whether a corefile is bigger than it should be. */
#define TRAD_CORE_ALLOW_ANY_EXTRA_SIZE 1

View File

@ -0,0 +1,91 @@
/* BFD back-end for i386 a.out binaries.
Copyright 1990, 91, 92, 94, 95, 96, 1997 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* The only 386 aout system we have here is GO32 from DJ.
These numbers make BFD work with that. If your aout 386 system
doesn't work with these, we'll have to split them into different
files. Send me (sac@cygnus.com) the runes to make it work on your
system, and I'll stick it in for the next release. */
#define N_HEADER_IN_TEXT(x) 0
#define BYTES_IN_WORD 4
#define N_TXTOFF(x) 0x20
#define N_TXTADDR(x) (N_MAGIC(x)==ZMAGIC ? 0x1020 : 0)
#define N_TXTSIZE(x) ((x).a_text)
#if 0
#define N_DATADDR(x) (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) : (SEGMENT_SIZE + ((0x1020+(x).a_text-1) & ~(SEGMENT_SIZE-1))))
#define NOSUBEXECB
#endif
#define TARGET_PAGE_SIZE 4096
#define SEGMENT_SIZE 0x400000
#define DEFAULT_ARCH bfd_arch_i386
#define MY(OP) CAT(i386aout_,OP)
#define TARGETNAME "a.out-i386"
#define NO_WRITE_HEADER_KLUDGE 1
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "aout/aout64.h"
#include "libaout.h"
/* Set the machine type correctly. */
static boolean
i386aout_write_object_contents (abfd)
bfd *abfd;
{
struct external_exec exec_bytes;
struct internal_exec *execp = exec_hdr (abfd);
N_SET_MACHTYPE (*execp, M_386);
obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
WRITE_HEADERS (abfd, execp);
return true;
}
#define MY_write_object_contents i386aout_write_object_contents
static boolean MY(set_sizes)();
#define MY_backend_data &MY(backend_data)
static CONST struct aout_backend_data MY(backend_data) = {
0, /* zmagic contiguous */
1, /* text incl header */
0, /* entry is text address */
0, /* exec_hdr_flags */
0, /* text vma? */
MY(set_sizes),
1, /* exec header not counted */
0, /* add_dynamic_symbols */
0, /* add_one_symbol */
0, /* link_dynamic_object */
0, /* write_dynamic_symbol */
0, /* check_dynamic_reloc */
0 /* finish_dynamic_link */
};
#include "aout-target.h"

Some files were not shown because too many files have changed in this diff Show More