/* Support for the generic parts of most COFF variants, for BFD.
- Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
+ Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
coff backends
BFD supports a number of different flavours of coff format.
- The major difference between formats are the sizes and
+ The major differences between formats are the sizes and
alignments of fields in structures on disk, and the occasional
extra field.
- Coff in all its varieties is implimented with a few common
+ Coff in all its varieties is implemented with a few common
files and a number of implementation specific files. For
example, The 88k bcs coff format is implemented in the file
- @code{coff-m88k.c}. This file @code{#include}s
- @code{coff/m88k.h} which defines the external structure of the
- coff format for the 88k, and @code{coff/internal.h} which
- defines the internal structure. @code{coff-m88k.c} also
+ @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
- @code{coff-i960.c}. This file has the same structure as
- @code{coff-m88k.c}, except that it includes @code{coff/i960.h}
- rather than @code{coff-m88k.h}.
+ @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
+ Porting to a new version of coff
The recommended method is to select from the existing
- implimentations the version of coff which is most like the one
- you want to use, for our purposes, we'll say that i386 coff is
+ 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 the @code{i386coff.c} to @code{foocoff.c}, copy
- @code{../include/coff/i386.h} to @code{../include/coff/foo.h}
- and add the lines to @code{targets.c} and @code{Makefile.in}
+ 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 @code{../include/coff/foo.h} so that they match
+ structures in @file{../include/coff/foo.h} so that they match
what you need. You will probably also have to add
- @code{#ifdef}s to the code in @code{coff/internal.h} and
- @code{coffcode.h} if your version of coff is too wild.
+ @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 @code{objdump} from the @code{binutils} directory,
- and making sure that its version of what's going on at your
- host systems 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
+ 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
+ How the coff backend works
SUBSUBSECTION
- File Layout
+ File layout
The Coff backend is split into generic routines that are
applicable to any Coff target and routines that are specific
structure, one of which exists for each target.
The essentially similar target-specific routines are in
- @file{coffcode.h}. This header file includes executable code.
+ @file{coffcode.h}. This header file includes executable C code.
The various Coff targets first include the appropriate Coff
header file, make any special defines that are needed, and
then include @file{coffcode.h}.
target.
SUBSUBSECTION
- Bit Twiddling
+ Bit twiddling
Each flavour of coff supported in BFD has its own header file
- descibing the external layout of the structures. There is also
- an internal description of the coff layout (in
- @code{coff/internal.h}). A major function of the
+ 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
+ coff; it is the duty of the coff version specific include file
to override the definitions of various packing routines in
- @code{coffcode.h}. Eg the size of line number entry in coff is
+ @file{coffcode.h}. E.g., the size of line number entry in coff is
sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
@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 for at the
+ coff which has a varying field size not catered to at the
moment. To port BFD, that person will have to add more @code{#defines}.
Three of the bit twiddling routines are exported to
@code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
@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. This also
+ on the way out, making cross ports much safer. Doing so also
allows BFD (and thus the linker) to use the same header files
as @code{gas}, which makes one avenue to disaster disappear.
SUBSUBSECTION
- Symbol Reading
+ 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 by keeping the original
+ 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{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 changes depending upon context; a field that is a
+ fields change depending upon context: a field that is a
pointer to another structure in the symbol table at one moment
- may be the size in bytes of a structure in the next. Another
+ may be the size in bytes of a structure at the next. Another
pass is made over the table. All symbols which mark file names
(<<C_FILE>> symbols) are modified so that the internal
string points to the value in the auxent (the real filename)
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
+ 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.
+ 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
+ @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
+ 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 was born, and on output
- the back end makes sure that the same destination target as
+ 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
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. Note that this transformation uses the
+ section. This transformation uses the
<<output_section>> field of the @code{asymbol}'s
@code{asection} @xref{Sections}.
- o coff_mangle_symbols
+ o <<coff_mangle_symbols>>
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 to an index into the symbol table of the symbol
- being referenced.
+ to a symbol into the index into the symbol table of the asymbol.
- o coff_write_symbols
+ o <<coff_write_symbols>>
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 tabel to the file.
+ bit twiddlers, and writes out the table to the file.
*/
coff_symbol_type
DESCRIPTION
- The hidden information for an asymbol is described in a
- coff_ptr_struct, which is typedefed to a combined_entry_type
+ The hidden information for an <<asymbol>> is described in a
+ <<combined_entry_type>>:
CODE_FRAGMENT
.
* in styp_to_sec_flags().
*/
static long
-DEFUN(sec_to_styp_flags, (sec_name, sec_flags),
- CONST char * sec_name AND
- flagword sec_flags)
+sec_to_styp_flags (sec_name, sec_flags)
+ CONST char *sec_name;
+ flagword sec_flags;
{
long styp_flags = 0;
if (!strcmp(sec_name, _TEXT))
- {
- styp_flags = STYP_TEXT;
- }
+ {
+ styp_flags = STYP_TEXT;
+ }
else if (!strcmp(sec_name, _DATA))
- {
- styp_flags = STYP_DATA;
+ {
+ styp_flags = STYP_DATA;
#ifdef TWO_DATA_SECS
- }
+ }
else if (!strcmp(sec_name, ".data2"))
- {
- styp_flags = STYP_DATA;
+ {
+ styp_flags = STYP_DATA;
#endif /* TWO_DATA_SECS */
- }
+ }
else if (!strcmp(sec_name, _BSS))
- {
- styp_flags = STYP_BSS;
+ {
+ styp_flags = STYP_BSS;
#ifdef _COMMENT
- }
+ }
else if (!strcmp(sec_name, _COMMENT))
- {
- styp_flags = STYP_INFO;
+ {
+ styp_flags = STYP_INFO;
#endif /* _COMMENT */
#ifdef _LIB
- }
+ }
else if (!strcmp(sec_name, _LIB))
- {
- styp_flags = STYP_LIB;
+ {
+ styp_flags = STYP_LIB;
#endif /* _LIB */
-
- }
+#ifdef _LIT
+ }
+ else if (!strcmp (sec_name, _LIT))
+ {
+ styp_flags = STYP_LIT;
+#endif /* _LIT */
+ }
+ else if (!strcmp(sec_name, ".debug"))
+ {
+ styp_flags = STYP_INFO;
+ }
+ else if (!strcmp(sec_name, ".stab")
+ || !strncmp(sec_name, ".stabstr", 8))
+ {
+ styp_flags = STYP_INFO;
+ }
/* Try and figure out what it should be */
else if (sec_flags & SEC_CODE)
- {
- styp_flags = STYP_TEXT;
- }
+ {
+ styp_flags = STYP_TEXT;
+ }
else if (sec_flags & SEC_DATA)
- {
- styp_flags = STYP_DATA;
- }
+ {
+ styp_flags = STYP_DATA;
+ }
else if (sec_flags & SEC_READONLY)
- {
+ {
#ifdef STYP_LIT /* 29k readonly text/data section */
- styp_flags = STYP_LIT;
+ styp_flags = STYP_LIT;
#else
- styp_flags = STYP_TEXT;
+ styp_flags = STYP_TEXT;
#endif /* STYP_LIT */
- }
+ }
else if (sec_flags & SEC_LOAD)
- {
- styp_flags = STYP_TEXT;
- }
- else {
- styp_flags = STYP_BSS;
- }
+ {
+ styp_flags = STYP_TEXT;
+ }
+ else if (sec_flags & SEC_ALLOC)
+ {
+ styp_flags = STYP_BSS;
+ }
#ifdef STYP_NOLOAD
if (sec_flags & SEC_NEVER_LOAD)
}
else if (styp_flags & STYP_BSS)
{
- sec_flags |= SEC_ALLOC;
+#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
+ if (sec_flags & SEC_NEVER_LOAD)
+ sec_flags |= SEC_ALLOC | SEC_SHARED_LIBRARY;
+ else
+#endif
+ sec_flags |= SEC_ALLOC;
}
else if (styp_flags & STYP_INFO)
- {
- sec_flags |= SEC_NEVER_LOAD;
- }
+ {
+ /* This should be marked as SEC_DEBUGGING, but that can't be
+ done until we make sure that strip can still work. strip
+ will probably have to preserve the same number of sections to
+ ensure that the section vma matches the section file
+ position. */
+ }
else
{
sec_flags |= SEC_ALLOC | SEC_LOAD;
return(sec_flags);
}
-#define get_index(symbol) ((int) (symbol)->udata)
+#define get_index(symbol) ((long) (symbol)->udata)
/*
INTERNAL_DEFINITION
CODE_FRAGMENT
-Special entry points for gdb to swap in coff symbol table parts
+Special entry points for gdb to swap in coff symbol table parts:
.typedef struct
.{
. void (*_bfd_coff_swap_aux_in) PARAMS ((
. PTR in));
.
-Special entry points for gas to swap coff parts
+Special entry points for gas to swap out coff parts:
. unsigned int (*_bfd_coff_swap_aux_out) PARAMS ((
. bfd *abfd,
.
Special entry points for generic COFF routines to call target
-dependent COFF routines
+dependent COFF routines:
. unsigned int _bfd_filhsz;
. unsigned int _bfd_aoutsz;
. bfd_byte *data,
. unsigned int *src_ptr,
. unsigned int *dst_ptr));
+. int (*_bfd_coff_reloc16_estimate) PARAMS ((
+. asection *input_section,
+. asymbol **symbols,
+. arelent *r,
+. unsigned int shrink));
+.
.} bfd_coff_backend_data;
.
.#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
.#define bfd_coff_reloc16_extra_cases(abfd, seclet, reloc, data, src_ptr, dst_ptr)\
. ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
. (abfd, seclet, reloc, data, src_ptr, dst_ptr))
+.
+.#define bfd_coff_reloc16_estimate(abfd, section, symbols, reloc, shrink)\
+. ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
+. (section, symbols, reloc, shrink))
.
*/
char *name)
{
#ifdef TWO_DATA_SECS
+ /* FIXME: This predates the call to bfd_make_section_anyway
+ in make_a_section_from_file, and can probably go away. */
/* On SCO a file created by the Microsoft assembler can have two
.data sections. We use .data2 for the second one. */
if (strcmp (name, _DATA) == 0)
at linking together COFF files for different architectures. */
static boolean
-DEFUN (coff_set_arch_mach_hook, (abfd, filehdr),
- bfd *abfd AND
- PTR filehdr)
+coff_set_arch_mach_hook(abfd, filehdr)
+ bfd *abfd;
+ PTR filehdr;
{
long machine;
enum bfd_architecture arch;
switch (internal_f->f_magic) {
#ifdef I386MAGIC
case I386MAGIC:
-#ifdef I386AIXMAGIC
+ case I386PTXMAGIC:
case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */
-#endif
+ case LYNXCOFFMAGIC: /* shadows the m68k Lynx number below, sigh */
arch = bfd_arch_i386;
machine = 0;
break;
break;
#endif
-#ifdef MIPS
- case MIPS_MAGIC_1:
- case MIPS_MAGIC_2:
- case MIPS_MAGIC_3:
- arch = bfd_arch_mips;
- machine = 0;
- break;
-#endif
-
#ifdef MC68MAGIC
case MC68MAGIC:
case M68MAGIC:
+#ifdef MC68KBCSMAGIC
+ case MC68KBCSMAGIC:
+#endif
+#ifdef APOLLOM68KMAGIC
+ case APOLLOM68KMAGIC:
+#endif
+#ifdef LYNXCOFFMAGIC
+ case LYNXCOFFMAGIC:
+#endif
arch = bfd_arch_m68k;
machine = 68020;
break;
#ifdef H8300MAGIC
case H8300MAGIC:
arch = bfd_arch_h8300;
+ machine = bfd_mach_h8300;
+ /* !! FIXME this probably isn't the right place for this */
+ abfd->flags |= BFD_IS_RELAXABLE;
+ break;
+#endif
+
+#ifdef H8300HMAGIC
+ case H8300HMAGIC:
+ arch = bfd_arch_h8300;
+ machine = bfd_mach_h8300h;
+ /* !! FIXME this probably isn't the right place for this */
+ abfd->flags |= BFD_IS_RELAXABLE;
+ break;
+#endif
+
+#ifdef SHMAGIC
+ case SHMAGIC:
+ arch = bfd_arch_sh;
+ machine = 0;
+ break;
+#endif
+
+#ifdef H8500MAGIC
+ case H8500MAGIC:
+ arch = bfd_arch_h8500;
+ machine = 0;
+ break;
+#endif
+
+#ifdef SPARCMAGIC
+ case SPARCMAGIC:
+ arch = bfd_arch_sparc;
machine = 0;
break;
#endif
/*
SUBSUBSECTION
- Writing Relocations
+ Writing relocations
- To write relocations, all the back end does is step though the
- canonical relocation table, and create an
+ 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
+ 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 and the type is dug directly
+ address and the relocation offset; the type is dug directly
from the howto field. Then the @code{internal_reloc} is
swapped into the shape of an @code{external_reloc} and written
out to disk.
{
asection *s;
for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
- unsigned int i;
+ unsigned int i;
struct external_reloc dst;
- arelent **p = s->orelocation;
+ arelent **p = s->orelocation;
bfd_seek(abfd, s->rel_filepos, SEEK_SET);
for (i = 0; i < s->reloc_count; i++) {
struct internal_reloc n;
memset((PTR)&n, 0, sizeof(n));
n.r_vaddr = q->address + s->vma;
- /* The 29k const/consth reloc pair is a real kludge - the consth
- part doesn't have a symbol - it has an offset. So rebuilt
- that here */
+
#ifdef R_IHCONST
+ /* The 29k const/consth reloc pair is a real kludge. The consth
+ part doesn't have a symbol; it has an offset. So rebuilt
+ that here. */
if (q->howto->type == R_IHCONST)
n.r_symndx = q->addend;
else
#endif
+ if (q->sym_ptr_ptr)
+ {
+ if (q->sym_ptr_ptr == bfd_abs_section.symbol_ptr_ptr)
+ /* This is a relocation relative to the absolute symbol. */
+ n.r_symndx = -1;
+ else
+ {
+ n.r_symndx = get_index((*(q->sym_ptr_ptr)));
+ /* Take notice if the symbol reloc points to a symbol
+ we don't have in our symbol table. What should we
+ do for this?? */
+ if (n.r_symndx > obj_conv_table_size (abfd))
+ abort ();
+ }
+ }
-
- if (q->sym_ptr_ptr)
- {
- if (q->sym_ptr_ptr == bfd_abs_section.symbol_ptr_ptr)
- {
- /* This is a relocation relative to the absolute symbol */
- n.r_symndx = -1;
- }
- else
- {
- n.r_symndx = get_index((*(q->sym_ptr_ptr)));
- /* Take notice if the symbol reloc points to a symbol we don't have
- in our symbol table. What should we do for this?? */
- if (n.r_symndx > obj_conv_table_size (abfd))
- abort ();
- }
-
-
- }
+#ifdef SWAP_OUT_RELOC_OFFSET
+ n.r_offset = q->addend;
+#endif
#ifdef SELECT_RELOC
/* Work out reloc type from what is required */
}
break;
#endif
-#ifdef MIPS
- case bfd_arch_mips:
- *magicp = MIPS_MAGIC_2;
- return true;
- break;
-#endif
#ifdef I386MAGIC
case bfd_arch_i386:
*magicp = I386MAGIC;
+#ifdef LYNXOS
+ /* Just overwrite the usual value if we're doing Lynx. */
+ *magicp = LYNXCOFFMAGIC;
+#endif
return true;
break;
#endif
#ifdef MC68MAGIC
case bfd_arch_m68k:
+#ifdef APOLLOM68KMAGIC
+ *magicp = APOLLO_COFF_VERSION_NUMBER;
+#else
*magicp = MC68MAGIC;
+#endif
+#ifdef LYNXOS
+ /* Just overwrite the usual value if we're doing Lynx. */
+ *magicp = LYNXCOFFMAGIC;
+#endif
return true;
break;
#endif
#endif
#ifdef H8300MAGIC
case bfd_arch_h8300:
- *magicp = H8300MAGIC;
+ switch (bfd_get_mach (abfd))
+ {
+ case bfd_mach_h8300:
+ *magicp = H8300MAGIC;
+ return true;
+ case bfd_mach_h8300h:
+ *magicp = H8300HMAGIC;
+ return true;
+ }
+ break;
+#endif
+
+#ifdef SHMAGIC
+ case bfd_arch_sh:
+ *magicp = SHMAGIC;
+ return true;
+ break;
+#endif
+
+#ifdef SPARCMAGIC
+ case bfd_arch_sparc:
+ *magicp = SPARCMAGIC;
+#ifdef LYNXOS
+ /* Just overwrite the usual value if we're doing Lynx. */
+ *magicp = LYNXCOFFMAGIC;
+#endif
+ return true;
+ break;
+#endif
+
+#ifdef H8500MAGIC
+ case bfd_arch_h8500:
+ *magicp = H8500MAGIC;
return true;
break;
#endif
asection *current;
asection *previous = (asection *)NULL;
file_ptr sofar = FILHSZ;
+#ifndef I960
file_ptr old_sofar;
+#endif
if (bfd_get_start_address(abfd))
{
/* A start address may have been added to the original file. In this
current->_raw_size += sofar - old_sofar ;
#endif
+#ifdef _LIB
+ /* Force .lib sections to start at zero. The vma is then
+ incremented in coff_set_section_contents. This is right for
+ SVR3.2. */
+ if (strcmp (current->name, _LIB) == 0)
+ bfd_set_section_vma (abfd, current, 0);
+#endif
+
previous = current;
}
obj_relocbase(abfd) = sofar;
continue;
if (!strcmp (name, _TEXT))
need_text = 0;
+#ifdef APOLLO_M68
+ else if (!strcmp(name, ".wtext"))
+ need_text = 0;
+#endif
else if (!strcmp (name, _DATA))
need_data = 0;
else if (!strcmp (name, _BSS))
section.s_vaddr = 0;
else
#endif
- section.s_vaddr = current->vma + pad;
- section.s_paddr = current->vma + pad;
+ section.s_vaddr = current->lma + pad;
+ section.s_paddr = current->lma + pad;
section.s_size = current->_raw_size - pad;
/*
If this section has no size or is unloadable then the scnptr
architectures.
*/
+ memset (&internal_a, 0, sizeof internal_a);
+
/* Set up architecture-dependent stuff */
{ unsigned int magic = 0;
internal_a.magic = PAGEMAGICBCS;
#endif /* M88 */
-#if M68 || MIPS || WE32K
+#if APOLLO_M68
+#define __A_MAGIC_SET__
+ internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
+#endif
+
+#if M68 || WE32K
#define __A_MAGIC_SET__
/* Never was anything here for the 68k */
-#endif /* M68 || MIPS || WE32K */
+#endif /* M68 || WE32K */
#if I386
# define __A_MAGIC_SET__
right for SVR3.2. Shared libraries should probably get more
generic support. Ian Taylor <ian@cygnus.com>. */
if (strcmp (section->name, _LIB) == 0)
- ++section->vma;
+ ++section->lma;
#endif
+ /* Don't write out bss sections - one way to do this is to
+ see if the filepos has not been set. */
+ if (section->filepos == 0)
+ return true;
+
bfd_seek(abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
if (count != 0) {
/*
SUBSUBSECTION
- Reading Linenumbers
+ 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 line number table is structured so that each function
+ 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
static boolean
coff_slurp_line_table(abfd, asect)
-bfd *abfd;
-asection *asect;
- {
- LINENO *native_lineno;
- alent *lineno_cache;
-
- BFD_ASSERT(asect->lineno == (alent *) NULL);
-
- native_lineno = (LINENO *) buy_and_read(abfd,
- asect->line_filepos,
- SEEK_SET,
- (size_t) (LINESZ *
- asect->lineno_count));
- lineno_cache =
- (alent *) bfd_alloc(abfd, (size_t) ((asect->lineno_count + 1) * sizeof(alent)));
- if (lineno_cache == NULL) {
+ bfd *abfd;
+ asection *asect;
+{
+ LINENO *native_lineno;
+ alent *lineno_cache;
+
+ BFD_ASSERT(asect->lineno == (alent *) NULL);
+
+ native_lineno = (LINENO *) buy_and_read(abfd,
+ asect->line_filepos,
+ SEEK_SET,
+ (size_t) (LINESZ *
+ asect->lineno_count));
+ lineno_cache =
+ (alent *) bfd_alloc(abfd, (size_t) ((asect->lineno_count + 1) * sizeof(alent)));
+ if (lineno_cache == NULL)
+ {
bfd_error = no_memory;
return false;
- } else {
+ }
+ else
+ {
unsigned int counter = 0;
alent *cache_ptr = lineno_cache;
LINENO *src = native_lineno;
- while (counter < asect->lineno_count) {
- struct internal_lineno dst;
- coff_swap_lineno_in(abfd, src, &dst);
- cache_ptr->line_number = dst.l_lnno;
-
- if (cache_ptr->line_number == 0) {
- coff_symbol_type *sym =
- (coff_symbol_type *) (dst.l_addr.l_symndx
- + obj_raw_syments(abfd))->u.syment._n._n_n._n_zeroes;
- cache_ptr->u.sym = (asymbol *) sym;
- sym->lineno = cache_ptr;
+ while (counter < asect->lineno_count)
+ {
+ struct internal_lineno dst;
+ coff_swap_lineno_in(abfd, src, &dst);
+ cache_ptr->line_number = dst.l_lnno;
+
+ if (cache_ptr->line_number == 0)
+ {
+ coff_symbol_type *sym =
+ (coff_symbol_type *) (dst.l_addr.l_symndx
+ + obj_raw_syments(abfd))->u.syment._n._n_n._n_zeroes;
+ cache_ptr->u.sym = (asymbol *) sym;
+ sym->lineno = cache_ptr;
+ }
+ else
+ {
+ cache_ptr->u.offset = dst.l_addr.l_paddr
+ - bfd_section_vma(abfd, asect);
+ } /* If no linenumber expect a symbol index */
+
+ cache_ptr++;
+ src++;
+ counter++;
}
- else {
- cache_ptr->u.offset = dst.l_addr.l_paddr
- - bfd_section_vma(abfd, asect);
- } /* If no linenumber expect a symbol index */
-
- cache_ptr++;
- src++;
- counter++;
- }
cache_ptr->line_number = 0;
}
- asect->lineno = lineno_cache;
- /* FIXME, free native_lineno here, or use alloca or something. */
- return true;
- } /* coff_slurp_line_table() */
+ asect->lineno = lineno_cache;
+ /* FIXME, free native_lineno here, or use alloca or something. */
+ return true;
+}
-static boolean
+static boolean
DEFUN(coff_slurp_symbol_table,(abfd),
bfd *abfd)
{
dst->symbol.the_bfd = abfd;
dst->symbol.name = (char *)(src->u.syment._n._n_n._n_offset);
- /*
- We use the native name field to point to the cached field
- */
- src->u.syment._n._n_n._n_zeroes = (int) dst;
+ /* We use the native name field to point to the cached field. */
+ src->u.syment._n._n_n._n_zeroes = (long) dst;
dst->symbol.section = coff_section_from_bfd_index(abfd,
src->u.syment.n_scnum);
dst->symbol.flags = 0;
case C_HIDDEN: /* ext symbol in dmert public lib */
default:
- fprintf(stderr,"Unrecognized storage class %d\n",
- src->u.syment.n_sclass);
+ fprintf(stderr,"Unrecognized storage class %d (assuming debugging)\n for %s symbol `%s'\n",
+ src->u.syment.n_sclass, dst->symbol.section->name,
+ dst->symbol.name);
/* abort();*/
dst->symbol.flags = BSF_DEBUGGING;
dst->symbol.value = (src->u.syment.n_value);
/*
SUBSUBSECTION
- Reading Relocations
+ 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:
- o The entire coff relocation table is read into memory.
+ o Read the entire coff relocation table into memory.
- o Each relocation is processed in turn, first it is swapped from the
+ o Process each relocation in turn; first swap it from the
external to the internal form.
- o The symbol referenced in the relocation's symbol index is
- turned intoa pointer into the canonical symbol table. Note
- that this table is the same as the one returned by a call to
- @code{bfd_canonicalize_symtab}. The back end will call the
+ o 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.
o The reloc index is turned into a pointer to a howto
#ifndef CALC_ADDEND
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
- if (ptr && bfd_asymbol_bfd(ptr) == abfd \
- && ((ptr->flags & BSF_OLD_COMMON)== 0)) \
+ if (ptr && bfd_asymbol_bfd(ptr) == abfd \
+ && !bfd_is_com_section(ptr->section) \
+ && !(ptr->flags & BSF_OLD_COMMON)) \
{ \
cache_ptr->addend = -(ptr->section->vma + ptr->value); \
} \
ptr = 0;
}
- /*
- The symbols definitions that we have read in have been
- relocated as if their sections started at 0. But the offsets
- refering to the symbols in the raw data have not been
- modified, so we have to have a negative addend to compensate.
-
- Note that symbols which used to be common must be left alone */
+ /* The symbols definitions that we have read in have been
+ relocated as if their sections started at 0. But the offsets
+ refering to the symbols in the raw data have not been
+ modified, so we have to have a negative addend to compensate.
+
+ Note that symbols which used to be common must be left alone */
/* Calculate any reloc addend by looking at the symbol */
CALC_ADDEND(abfd, ptr, dst, cache_ptr);
}
-/* This is stupid. This function should be a boolean predicate */
+/* This is stupid. This function should be a boolean predicate. */
static unsigned int
DEFUN(coff_canonicalize_reloc, (abfd, section, relptr, symbols),
bfd *abfd AND
}
#endif
+#ifndef coff_reloc16_estimate
+#define coff_reloc16_estimate dummy_reloc16_estimate
+
+static int
+dummy_reloc16_estimate(input_section, symbols, reloc, shrink)
+ asection *input_section;
+ asymbol **symbols;
+ arelent *reloc;
+ unsigned int shrink;
+{
+ abort ();
+}
+
+#endif
+
#ifndef coff_reloc16_extra_cases
-#define coff_reloc16_extra_cases \
- (void (*) PARAMS ((bfd *, bfd_seclet_type *, arelent *, bfd_byte *,\
- unsigned int *, unsigned int *))) abort
+#define coff_reloc16_extra_cases dummy_reloc16_extra_cases
+/* This works even if abort is not declared in any header file. */
+static void
+dummy_reloc16_extra_cases (abfd, seclet, reloc, data, src_ptr, dst_ptr)
+ bfd *abfd;
+ struct bfd_seclet *seclet;
+ arelent *reloc;
+ bfd_byte *data;
+ unsigned int *src_ptr;
+ unsigned int *dst_ptr;
+{
+ fprintf(stderr, "%s\n", reloc->howto->name);
+ abort ();
+}
#endif
static CONST bfd_coff_backend_data bfd_coff_std_swap_table = {
coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
coff_bad_format_hook, coff_set_arch_mach_hook, coff_mkobject_hook,
styp_to_sec_flags, coff_make_section_hook, coff_set_alignment_hook,
- coff_slurp_symbol_table, symname_in_debug_hook, coff_reloc16_extra_cases
+ coff_slurp_symbol_table, symname_in_debug_hook,
+ coff_reloc16_extra_cases, coff_reloc16_estimate
};
#define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
#define coff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
#define coff_bfd_relax_section bfd_generic_relax_section
#define coff_bfd_seclet_link bfd_generic_seclet_link
+#ifndef coff_bfd_reloc_type_lookup
+#define coff_bfd_reloc_type_lookup \
+ ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
+#endif