Merge devo/bfd with GDB's bfd.

Remove obstack.h to ../include and obstack.c to ../libiberty.
Move COFF symbol swapping code to coffswap.c where GDB can call it but it
won't be duplicated if we have N different COFF targets.
Add support for traditional Unix core files (with a upage).  This support
is from an Ultrix port, but is probably slightly broken now.
Improve bfd_release's of obstack'd items on error returns.
gcc -Wall fixes.
Handle section alignment slightly better in coff, and comment where it
needs more work (on page-aligning virtual vs file addresses for DPAGED).
Use set_tdata everywhere that tdata is set, to avoid "cast to the left
of assignment" problems with some compilers.
Move bfd_alloc, bfd_zalloc, bfd_realloc, and bfd_release into libbfd.h
(from bfd.h) since they are internal routines.
Remove the redundant suffix "_struct" from struct tags.
Set symbol count early in file reading, before slurping in the syms,
for GDB's use.
This commit is contained in:
John Gilmore
1991-05-02 04:11:40 +00:00
parent ff37ea550b
commit fc7233808a
16 changed files with 772 additions and 1018 deletions

View File

@ -1,4 +1,5 @@
/*** bfd backend for sunos binaries */ /*** bfd backend for sunos binaries */
/** a.out files */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
@ -18,37 +19,23 @@ You should have received a copy of the GNU General Public License
along with BFD; see the file COPYING. If not, write to along with BFD; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id$ /* $Id$ */
*
*/
#define TARGET_BYTE_ORDER_BIG_P 1
#include <ansidecl.h> #include <ansidecl.h>
#include "sysdep.h" #include "sysdep.h"
#include "bfd.h" #include "bfd.h"
#include "libbfd.h" #include "libbfd.h"
#include "a.out.sun4.h"
void (*bfd_error_trap)();
/*SUPPRESS558*/
/*SUPPRESS529*/
/* These values are correct for the SPARC. I dunno about anything else */
#define PAGE_SIZE 0x02000
#define SEGMENT_SIZE PAGE_SIZE
#define TEXT_START_ADDR PAGE_SIZE
#include "a.out.gnu.h" #include "a.out.gnu.h"
#include "stab.gnu.h" #include "stab.gnu.h"
#include "ar.h" #include "ar.h"
#include "liba.out.h" /* BFD a.out internal data structures */ #include "liba.out.h" /* BFD a.out internal data structures */
#include "a.out.sun4.h" void (*bfd_error_trap)();
/*SUPPRESS558*/
/*SUPPRESS529*/
#define CTOR_TABLE_RELOC_IDX 2 #define CTOR_TABLE_RELOC_IDX 2
static reloc_howto_type howto_table_ext[] = static reloc_howto_type howto_table_ext[] =
@ -85,7 +72,7 @@ static reloc_howto_type howto_table_ext[] =
/* Convert standard reloc records to "arelent" format (incl byte swap). */ /* Convert standard reloc records to "arelent" format (incl byte swap). */
static reloc_howto_type howto_table_std[] = { static reloc_howto_type howto_table_std[] = {
/* type rs size bsz pcrel bitpos abs ovrf sf name*/ /* type rs size bsz pcrel bitpos abs ovrf sf name part_inpl readmask setmask pcdone */
HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false), HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false), HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false), HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
@ -98,8 +85,6 @@ HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedfac
bfd_error_vector_type bfd_error_vector; bfd_error_vector_type bfd_error_vector;
/** a.out files */
PROTO (void , sunos4_write_syms, ()); PROTO (void , sunos4_write_syms, ());
PROTO (static boolean,sunos4_squirt_out_relocs,(bfd *abfd, asection *section)); PROTO (static boolean,sunos4_squirt_out_relocs,(bfd *abfd, asection *section));
@ -156,45 +141,6 @@ DEFUN(bfd_aout_swap_exec_header_out,(abfd, execp, raw_bytes),
bfd_h_putlong (abfd, execp->a_drsize, bytes->a_drsize); bfd_h_putlong (abfd, execp->a_drsize, bytes->a_drsize);
} }
/* Steve wants some way to frob this stuff from Saber while he's debugging
ld, so we have these funny shadow functions */
/* ZMAGIC's start at 0 (making the exec part of the text section),
other formats start after the exec
*/
static unsigned int n_txtoff(ptr)
struct exec *ptr;
{return N_MAGIC(*ptr)== ZMAGIC ? 0: sizeof(struct exec);}
static unsigned int n_datoff(ptr)
struct exec *ptr;
{return n_txtoff(ptr) + ptr->a_text;}
static unsigned int n_treloff(ptr)
struct exec *ptr;
{return n_datoff(ptr) + ptr->a_data;}
static unsigned int n_dreloff(ptr)
struct exec *ptr;
{return n_treloff(ptr) + ptr->a_trsize;}
static unsigned int n_symoff(ptr)
struct exec *ptr;
{return n_dreloff(ptr) + ptr->a_drsize;}
static unsigned int n_stroff(ptr)
struct exec *ptr;
{return n_symoff(ptr) + ptr->a_syms;}
static
unsigned int n_badmag(ptr)
struct exec *ptr;
{
switch (N_MAGIC(*ptr)) {
case OMAGIC: case NMAGIC: case ZMAGIC: return 0;
default: return 1;
}
}
bfd_target * bfd_target *
sunos4_object_p (abfd) sunos4_object_p (abfd)
bfd *abfd; bfd *abfd;
@ -212,9 +158,7 @@ sunos4_object_p (abfd)
return 0; return 0;
magic = bfd_h_getlong (abfd, magicbuf); magic = bfd_h_getlong (abfd, magicbuf);
/* Baroque syntax to mask deficiencies of the Sun compiler */ if (N_BADMAG (*((struct exec *) &magic))) return 0;
/* if (N_BADMAG (*((struct exec *) &magic))) return 0; */
if (n_badmag ((struct exec *) &magic)) return 0;
if (bfd_seek (abfd, 0L, false) < 0) return 0; if (bfd_seek (abfd, 0L, false) < 0) return 0;
@ -288,9 +232,11 @@ sunos4_object_p (abfd)
bfd_get_start_address (abfd) = execp->a_entry; bfd_get_start_address (abfd) = execp->a_entry;
bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct nlist);
/* Remember the positions of the string table and symbol table. */ /* Remember the positions of the string table and symbol table. */
obj_str_filepos (abfd) = n_stroff (execp); obj_str_filepos (abfd) = N_STROFF (*execp);
obj_sym_filepos (abfd) = n_symoff (execp); obj_sym_filepos (abfd) = N_SYMOFF (*execp);
/* create the sections. This is raunchy, but bfd_close wants to reclaim /* create the sections. This is raunchy, but bfd_close wants to reclaim
them */ them */
@ -346,7 +292,7 @@ sunos4_mkobject (abfd)
return false; return false;
} }
abfd->tdata = (PTR)((struct sunexdata *) rawptr); set_tdata (abfd, (struct sunexdata *) rawptr);
exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata)); exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata));
/* For simplicity's sake we just make all the sections right here. */ /* For simplicity's sake we just make all the sections right here. */
@ -459,6 +405,8 @@ sunos4_write_object_contents (abfd)
N_SET_MAGIC (*execp, OMAGIC); N_SET_MAGIC (*execp, OMAGIC);
if (abfd->flags & D_PAGED) { if (abfd->flags & D_PAGED) {
/* This is not strictly true, but will probably do for the default
case. FIXME. */
execp->a_text = obj_textsec (abfd)->size + sizeof(struct exec); execp->a_text = obj_textsec (abfd)->size + sizeof(struct exec);
N_SET_MAGIC (*execp, ZMAGIC); N_SET_MAGIC (*execp, ZMAGIC);
} else if (abfd->flags & WP_TEXT) { } else if (abfd->flags & WP_TEXT) {
@ -515,9 +463,8 @@ sunos4_write_object_contents (abfd)
} }
return true; return true;
} }
/** core files */ /* core files */
/** core files */
#define CORE_MAGIC 0x080456 #define CORE_MAGIC 0x080456
#define CORE_NAMELEN 16 #define CORE_NAMELEN 16
@ -640,7 +587,7 @@ sunos4_core_file_p (abfd)
if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) { if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) {
bfd_error = system_call_error; bfd_error = system_call_error;
free ((PTR)rawptr); bfd_release (abfd, rawptr);
return 0; return 0;
} }
@ -654,24 +601,24 @@ sunos4_core_file_p (abfd)
if (core_stacksec (abfd) == NULL) { if (core_stacksec (abfd) == NULL) {
loser: loser:
bfd_error = no_memory; bfd_error = no_memory;
free ((PTR)rawptr); bfd_release (abfd, rawptr);
return 0; return 0;
} }
core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_datasec (abfd) == NULL) { if (core_datasec (abfd) == NULL) {
loser1: loser1:
free ((PTR)core_stacksec (abfd)); bfd_release (abfd, core_stacksec (abfd));
goto loser; goto loser;
} }
core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_regsec (abfd) == NULL) { if (core_regsec (abfd) == NULL) {
loser2: loser2:
free ((PTR)core_datasec (abfd)); bfd_release (abfd, core_datasec (abfd));
goto loser1; goto loser1;
} }
core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_reg2sec (abfd) == NULL) { if (core_reg2sec (abfd) == NULL) {
free ((PTR)core_regsec (abfd)); bfd_release (abfd, core_regsec (abfd));
goto loser2; goto loser2;
} }
@ -809,31 +756,15 @@ sunos4_set_section_contents (abfd, section, location, offset, count)
{ {
if (abfd->output_has_begun == false) if (abfd->output_has_begun == false)
{ /* set by bfd.c handler */ { /* set by bfd.c handler */
if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL))
/*||
(obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size=
0)*/
)
{ {
bfd_error = invalid_operation; bfd_error = invalid_operation;
return false; return false;
} }
#if 0
if (abfd->flags & D_PAGED)
{
obj_textsec (abfd)->filepos = sizeof(struct exec); obj_textsec (abfd)->filepos = sizeof(struct exec);
obj_datasec(abfd)->filepos = obj_textsec (abfd)->size; obj_datasec(abfd)->filepos = obj_textsec (abfd)->filepos
} + obj_textsec (abfd)->size;
else
#endif
{
obj_textsec (abfd)->filepos = sizeof(struct exec);
obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos + obj_textsec (abfd)->size;
}
} }
/* regardless, once we know what we're doing, we might as well get going */ /* regardless, once we know what we're doing, we might as well get going */
if (section != obj_bsssec(abfd)) { if (section != obj_bsssec(abfd)) {
@ -847,6 +778,7 @@ sunos4_set_section_contents (abfd, section, location, offset, count)
} }
return true; return true;
} }
boolean boolean
sunos4_get_section_contents (abfd, section, location, offset, count) sunos4_get_section_contents (abfd, section, location, offset, count)
bfd *abfd; bfd *abfd;
@ -944,14 +876,12 @@ translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd)
} }
cache_ptr->symbol.section = reloc->relent.section; cache_ptr->symbol.section = reloc->relent.section;
reloc->relent.addend = cache_ptr->symbol.value ; reloc->relent.addend = cache_ptr->symbol.value ;
/*
We modify the symbol to belong to a section depending upon the /* We modify the symbol to belong to a section depending upon the
name of the symbol - probably __CTOR__ or __DTOR__ but we don't name of the symbol - probably __CTOR__ or __DTOR__ but we don't
really care, and add to the size of the section to contain a really care, and add to the size of the section to contain a
pointer to the symbol. Build a reloc entry to relocate to this pointer to the symbol. Build a reloc entry to relocate to this
symbol attached to this section. symbol attached to this section. */
*/
section->flags = SEC_CONSTRUCTOR; section->flags = SEC_CONSTRUCTOR;
section->reloc_count++; section->reloc_count++;
@ -1050,7 +980,7 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
{ {
asymbol *cache_ptr = (asymbol *)cache_ptr_g; asymbol *cache_ptr = (asymbol *)cache_ptr_g;
/* FIXME check for wrigin bss */ /* FIXME check for writing bss */
if (bfd_get_section(cache_ptr)) { if (bfd_get_section(cache_ptr)) {
if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) { if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
sym_pointer->n_type |= N_BSS; sym_pointer->n_type |= N_BSS;
@ -1062,9 +992,8 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
sym_pointer->n_type |= N_TEXT; sym_pointer->n_type |= N_TEXT;
} }
else { else {
bfd_error_vector.nonrepresentable_section(abfd,
bfd_error_vector.nonrepresentable_section(abfd, bfd_get_output_section(cache_ptr)->name); bfd_get_output_section(cache_ptr)->name);
} }
/* Turn the symbol from section relative to absolute again */ /* Turn the symbol from section relative to absolute again */
sym_pointer->n_value += sym_pointer->n_value +=
@ -1090,7 +1019,6 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
if (cache_ptr->flags & BSF_DEBUGGING) { if (cache_ptr->flags & BSF_DEBUGGING) {
sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type; sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type;
} }
} }
/* Native-level interface to symbols. */ /* Native-level interface to symbols. */
@ -1114,9 +1042,9 @@ boolean
DEFUN(sunos4_slurp_symbol_table, (abfd), DEFUN(sunos4_slurp_symbol_table, (abfd),
bfd *abfd) bfd *abfd)
{ {
unsigned int symbol_count;
size_t symbol_size; size_t symbol_size;
size_t string_size; size_t string_size;
unsigned char string_chars[LONG_SIZE];
struct nlist *syms; struct nlist *syms;
char *strings; char *strings;
aout_symbol_type *cached; aout_symbol_type *cached;
@ -1130,20 +1058,22 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
} }
bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET); bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
if (bfd_read ((PTR)&string_size, 4, 1, abfd) != 4) if (bfd_read ((PTR)string_chars, LONG_SIZE, 1, abfd) != LONG_SIZE)
return false; return false;
string_size = bfd_h_getlong (abfd, (unsigned char *)&string_size); string_size = bfd_h_getlong (abfd, string_chars);
symbol_count = symbol_size / sizeof (struct nlist);
strings = bfd_alloc(abfd, string_size + 1); strings = bfd_alloc(abfd, string_size + 1);
cached = (aout_symbol_type *) cached = (aout_symbol_type *)
bfd_zalloc(abfd, symbol_count * sizeof(aout_symbol_type)); bfd_zalloc(abfd, bfd_get_symcount (abfd) * sizeof(aout_symbol_type));
/* Alloc this last, so we can free it if obstack is in use. */
syms = (struct nlist *) bfd_alloc(abfd, symbol_size); syms = (struct nlist *) bfd_alloc(abfd, symbol_size);
bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) { if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) {
bailout: bailout:
if (syms) bfd_release (abfd, syms);
if (cached) bfd_release (abfd, cached);
if (strings)bfd_release (abfd, strings);
return false; return false;
} }
@ -1155,7 +1085,7 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
/* OK, now walk the new symtable, cacheing symbol properties */ /* OK, now walk the new symtable, cacheing symbol properties */
{ {
register struct nlist *sym_pointer; register struct nlist *sym_pointer;
register struct nlist *sym_end = syms + symbol_count; register struct nlist *sym_end = syms + bfd_get_symcount (abfd);
register aout_symbol_type *cache_ptr = cached; register aout_symbol_type *cache_ptr = cached;
/* run through the table and byte swap if needed */ /* run through the table and byte swap if needed */
@ -1170,7 +1100,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
bfd_h_get_x(abfd, &sym_pointer->n_other); bfd_h_get_x(abfd, &sym_pointer->n_other);
sym_pointer->n_type = (char) sym_pointer->n_type = (char)
bfd_h_get_x(abfd, &sym_pointer->n_type); bfd_h_get_x(abfd, &sym_pointer->n_type);
} }
/* Run through table and copy values */ /* Run through table and copy values */
@ -1193,7 +1122,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
} }
obj_aout_symbols (abfd) = cached; obj_aout_symbols (abfd) = cached;
bfd_get_symcount (abfd) = symbol_count;
bfd_release (abfd, (PTR)syms); bfd_release (abfd, (PTR)syms);
return true; return true;
@ -1258,7 +1186,7 @@ DEFUN(sunos4_write_syms,(abfd),
{ {
asymbol *g = *(generic++); asymbol *g = *(generic++);
if (g->name != (char *)NULL) if (g->name)
{ {
size_t length = strlen(g->name)+1; size_t length = strlen(g->name)+1;
bfd_write((PTR)g->name, 1, length, abfd); bfd_write((PTR)g->name, 1, length, abfd);
@ -1307,11 +1235,10 @@ sunos4_get_symtab (abfd, location)
/* Output standard relocation information to a file in target byte order. */ /* Output standard relocation information to a file in target byte order. */
void void
swap_std_reloc_out (abfd, p, natptr, count) swap_std_reloc_out (abfd, g, natptr)
bfd *abfd; bfd *abfd;
arelent **p; /* Generic relocation struct */ arelent *g; /* Generic relocation struct */
struct reloc_std_bytes *natptr; struct reloc_std_bytes *natptr;
unsigned int count;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
@ -1319,10 +1246,7 @@ swap_std_reloc_out (abfd, p, natptr, count)
int r_pcrel; int r_pcrel;
int r_baserel, r_jmptable, r_relative; int r_baserel, r_jmptable, r_relative;
unsigned int r_addend; unsigned int r_addend;
unsigned int idx;
for (idx = 0; idx < count; idx++, p++, natptr++)
{
arelent *g = *p;
bfd_h_putlong (abfd, g->address, natptr->r_address); bfd_h_putlong (abfd, g->address, natptr->r_address);
r_length = g->howto->size; /* Size as a power of two */ r_length = g->howto->size; /* Size as a power of two */
@ -1393,9 +1317,6 @@ swap_std_reloc_out (abfd, p, natptr, count)
| (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0)
| (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
} }
}
} }
@ -1403,20 +1324,15 @@ swap_std_reloc_out (abfd, p, natptr, count)
/* Output extended relocation information to a file in target byte order. */ /* Output extended relocation information to a file in target byte order. */
void void
swap_ext_reloc_out (abfd, p, natptr, count) swap_ext_reloc_out (abfd, g, natptr)
bfd *abfd; bfd *abfd;
arelent **p; /* Generic relocation struct */ arelent *g; /* Generic relocation struct */
register struct reloc_ext_bytes *natptr; register struct reloc_ext_bytes *natptr;
unsigned int count;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
unsigned int r_type; unsigned int r_type;
unsigned int r_addend; unsigned int r_addend;
unsigned int idx;
for (idx = 0; idx < count; idx++, p++, natptr++) {
arelent *g = *p;
bfd_h_putlong (abfd, g->address, natptr->r_address); bfd_h_putlong (abfd, g->address, natptr->r_address);
@ -1480,7 +1396,7 @@ swap_ext_reloc_out (abfd, p, natptr, count)
bfd_h_putlong (abfd, r_addend, natptr->r_addend); bfd_h_putlong (abfd, r_addend, natptr->r_addend);
} }
}
#define MOVE_ADDRESS(ad) \ #define MOVE_ADDRESS(ad) \
if (r_extern) { \ if (r_extern) { \
cache_ptr->sym_ptr_ptr = symbols + r_index; \ cache_ptr->sym_ptr_ptr = symbols + r_index; \
@ -1506,9 +1422,13 @@ swap_ext_reloc_out (abfd, p, natptr, count)
break; \ break; \
case N_ABS: \ case N_ABS: \
case N_ABS | N_EXT: \ case N_ABS | N_EXT: \
cache_ptr->section = NULL; /* No section */ \
cache_ptr->addend = ad; /* FIXME, is this right? */ \
BFD_ASSERT(1); \ BFD_ASSERT(1); \
break; \ break; \
default: \ default: \
cache_ptr->section = NULL; /* No section */ \
cache_ptr->addend = ad; /* FIXME, is this right? */ \
BFD_ASSERT(1); \ BFD_ASSERT(1); \
break; \ break; \
} \ } \
@ -1547,7 +1467,6 @@ swap_ext_reloc_in (abfd, bytes, cache_ptr, symbols)
cache_ptr->howto = howto_table_ext + r_type; cache_ptr->howto = howto_table_ext + r_type;
MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend)); MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend));
} }
void void
@ -1563,6 +1482,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols)
int r_pcrel; int r_pcrel;
int r_baserel, r_jmptable, r_relative; int r_baserel, r_jmptable, r_relative;
struct sunexdata *su = (struct sunexdata *)(abfd->tdata); struct sunexdata *su = (struct sunexdata *)(abfd->tdata);
cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address); cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address);
/* now the fun stuff */ /* now the fun stuff */
@ -1636,15 +1556,26 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof
(arelent))); (arelent)));
if (!reloc_cache) {
nomem:
bfd_error = no_memory;
return false;
}
relocs = bfd_alloc (abfd, reloc_size); relocs = bfd_alloc (abfd, reloc_size);
if (!relocs) {
bfd_release (abfd, reloc_cache);
goto nomem;
}
if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) { if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {
bfd_release (abfd, relocs);
bfd_release (abfd, reloc_cache);
bfd_error = system_call_error; bfd_error = system_call_error;
return false; return false;
} }
if (each_size == RELOC_EXT_SIZE) if (each_size == RELOC_EXT_SIZE) {
{
register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs;
unsigned int counter = 0; unsigned int counter = 0;
arelent *cache_ptr = reloc_cache; arelent *cache_ptr = reloc_cache;
@ -1652,8 +1583,7 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
for (; counter < count; counter++, rptr++, cache_ptr++) { for (; counter < count; counter++, rptr++, cache_ptr++) {
swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols);
} }
} } else {
else {
register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs; register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs;
unsigned int counter = 0; unsigned int counter = 0;
arelent *cache_ptr = reloc_cache; arelent *cache_ptr = reloc_cache;
@ -1663,6 +1593,7 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
} }
} }
bfd_release (abfd,relocs); bfd_release (abfd,relocs);
asect->relocation = reloc_cache; asect->relocation = reloc_cache;
asect->reloc_count = count; asect->reloc_count = count;
@ -1679,7 +1610,7 @@ sunos4_squirt_out_relocs (abfd, section)
asection *section; asection *section;
{ {
arelent **generic; arelent **generic;
unsigned char *native; unsigned char *native, *natptr;
size_t each_size; size_t each_size;
unsigned int count = section->reloc_count; unsigned int count = section->reloc_count;
@ -1699,14 +1630,17 @@ sunos4_squirt_out_relocs (abfd, section)
if (each_size == RELOC_EXT_SIZE) if (each_size == RELOC_EXT_SIZE)
{ {
swap_ext_reloc_out (abfd, for (natptr = native;
generic, count != 0;
(struct reloc_ext_bytes *)native, --count, natptr += each_size, ++generic)
count); swap_ext_reloc_out (abfd, generic, (struct reloc_ext_bytes *)native);
} }
else else
{ {
swap_std_reloc_out(abfd, generic, native, count); for (natptr = native;
count != 0;
--count, natptr += each_size, ++generic)
swap_std_reloc_out(abfd, generic, (struct reloc_std_bytes *)native);
} }
if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {

View File

@ -27,9 +27,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
o - all arch headers are the same size (across architectures). o - all arch headers are the same size (across architectures).
*/ */
/* $Id$ /* $Id$ */
*/
#include "sysdep.h" #include "sysdep.h"
#include "bfd.h" #include "bfd.h"
@ -59,16 +57,14 @@ struct ar_cache {
#define arch_hdr(bfd) ((struct ar_hdr *) \ #define arch_hdr(bfd) ((struct ar_hdr *) \
(((struct areltdata *)((bfd)->arelt_data))->arch_header)) (((struct areltdata *)((bfd)->arelt_data))->arch_header))
boolean boolean
_bfd_generic_mkarchive (abfd) _bfd_generic_mkarchive (abfd)
bfd *abfd; bfd *abfd;
{ {
abfd->tdata = bfd_zalloc(abfd, sizeof (struct artdata)); set_tdata (abfd, bfd_zalloc(abfd, sizeof (struct artdata)));
if (abfd->tdata == NULL) { if (bfd_ardata (abfd) == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
return false; return false;
} }
@ -88,7 +84,7 @@ bfd_get_next_mapent (abfd, prev, entry)
} }
if (prev == BFD_NO_MORE_SYMBOLS) prev = 0; if (prev == BFD_NO_MORE_SYMBOLS) prev = 0;
else if (++prev >= (symindex)(bfd_ardata (abfd)->symdef_count)) else if (++prev >= bfd_ardata (abfd)->symdef_count)
return BFD_NO_MORE_SYMBOLS; return BFD_NO_MORE_SYMBOLS;
*entry = (bfd_ardata (abfd)->symdefs + prev); *entry = (bfd_ardata (abfd)->symdefs + prev);
@ -140,7 +136,8 @@ add_bfd_to_cache (arch_bfd, filepos, new_elt)
bfd *arch_bfd, *new_elt; bfd *arch_bfd, *new_elt;
file_ptr filepos; file_ptr filepos;
{ {
struct ar_cache *new_cache = ((struct ar_cache *)bfd_zalloc(arch_bfd,sizeof (struct ar_cache))); struct ar_cache *new_cache = (struct ar_cache *)
bfd_zalloc(arch_bfd, sizeof (struct ar_cache));
if (new_cache == NULL) { if (new_cache == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
@ -172,7 +169,6 @@ get_extended_arelt_filename (arch, name)
bfd *arch; bfd *arch;
char *name; char *name;
{ {
extern int errno;
unsigned long index = 0; unsigned long index = 0;
/* Should extract string so that I can guarantee not to overflow into /* Should extract string so that I can guarantee not to overflow into
@ -296,6 +292,7 @@ get_elt_at_filepos (archive, filepos)
n_nfd = _bfd_create_empty_archive_element_shell (archive); n_nfd = _bfd_create_empty_archive_element_shell (archive);
if (n_nfd == NULL) { if (n_nfd == NULL) {
bfd_release (archive, (PTR)new_areldata);
return NULL; return NULL;
} }
n_nfd->origin = bfd_tell (archive); n_nfd->origin = bfd_tell (archive);
@ -306,6 +303,8 @@ get_elt_at_filepos (archive, filepos)
return n_nfd; return n_nfd;
/* huh? */ /* huh? */
bfd_release (archive, (PTR)n_nfd);
bfd_release (archive, (PTR)new_areldata);
return NULL; return NULL;
} }
@ -350,11 +349,10 @@ bfd *bfd_generic_openr_next_archived_file(archive, last_file)
filestart = bfd_ardata (archive)->first_file_filepos; filestart = bfd_ardata (archive)->first_file_filepos;
else { else {
unsigned int size = arelt_size(last_file); unsigned int size = arelt_size(last_file);
/* Pad to an even boundary... */
filestart = last_file->origin + size + size%2; filestart = last_file->origin + size + size%2;
} }
return get_elt_at_filepos (archive, filestart); return get_elt_at_filepos (archive, filestart);
} }
@ -376,7 +374,9 @@ bfd_generic_archive_p (abfd)
if (strncmp (armag, ARMAG, SARMAG)) return 0; if (strncmp (armag, ARMAG, SARMAG)) return 0;
#endif #endif
bfd_set_ardata(abfd, (struct artdata *) bfd_zalloc(abfd,sizeof (struct artdata))); /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
involves a cast, we can't do it as the left operand of assignment. */
set_tdata (abfd, bfd_zalloc(abfd,sizeof (struct artdata)));
if (bfd_ardata (abfd) == NULL) { if (bfd_ardata (abfd) == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
@ -391,7 +391,6 @@ bfd_generic_archive_p (abfd)
return 0; return 0;
} }
/* armap could be left ungc'd! FIXME -- potential storage leak */
if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) { if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) {
bfd_release(abfd, bfd_ardata (abfd)); bfd_release(abfd, bfd_ardata (abfd));
abfd->tdata = NULL; abfd->tdata = NULL;
@ -413,6 +412,9 @@ bfd_slurp_bsd_armap (abfd)
struct artdata *ardata = bfd_ardata (abfd); struct artdata *ardata = bfd_ardata (abfd);
char *stringbase; char *stringbase;
/* FIXME, if the read fails, this routine quietly returns "true"!!
It should probably do that if the read gives 0 bytes (empty archive),
but fail for any other size... */
if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) { if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
/* The archive has at least 16 bytes in it */ /* The archive has at least 16 bytes in it */
bfd_seek (abfd, -16L, SEEK_CUR); bfd_seek (abfd, -16L, SEEK_CUR);
@ -431,22 +433,24 @@ bfd_slurp_bsd_armap (abfd)
if (raw_armap == NULL) { if (raw_armap == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
byebye: byebye:
bfd_release (abfd, (PTR)mapdata);
return false; return false;
} }
if (bfd_read ((PTR)raw_armap, 1, mapdata->parsed_size, abfd) != if (bfd_read ((PTR)raw_armap, 1, mapdata->parsed_size, abfd) !=
mapdata->parsed_size) { mapdata->parsed_size) {
bfd_error = malformed_archive; bfd_error = malformed_archive;
bfd_release (abfd, (PTR)raw_armap);
goto byebye; goto byebye;
} }
ardata->symdef_count = *(raw_armap) / sizeof (struct symdef); ardata->symdef_count = *raw_armap / sizeof (struct symdef);
ardata->cache = 0; ardata->cache = 0;
rbase = raw_armap+1; rbase = raw_armap+1;
ardata->symdefs = (carsym *) rbase; ardata->symdefs = (carsym *) rbase;
stringbase = ((char *) (ardata->symdefs + ardata->symdef_count)) + 4; stringbase = ((char *) (ardata->symdefs + ardata->symdef_count)) + 4;
for (;counter < (unsigned)( ardata->symdef_count); counter++) { for (;counter < ardata->symdef_count; counter++) {
struct symdef *sym = ((struct symdef *) rbase) + counter; struct symdef *sym = ((struct symdef *) rbase) + counter;
sym->s.name = sym->s.string_offset + stringbase; sym->s.name = sym->s.string_offset + stringbase;
} }
@ -454,6 +458,9 @@ bfd_slurp_bsd_armap (abfd)
ardata->first_file_filepos = bfd_tell (abfd); ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary if you have to */ /* Pad to an even boundary if you have to */
ardata->first_file_filepos += (ardata-> first_file_filepos) %2; ardata->first_file_filepos += (ardata-> first_file_filepos) %2;
/* FIXME, we should provide some way to free raw_ardata when
we are done using the strings from it. For now, it seems
to be allocated on an obstack anyway... */
bfd_has_map (abfd) = true; bfd_has_map (abfd) = true;
} }
return true; return true;
@ -471,15 +478,12 @@ bfd_slurp_coff_armap (abfd)
char *stringbase; char *stringbase;
unsigned int stringsize; unsigned int stringsize;
carsym *carsyms; carsym *carsyms;
int result;
if (bfd_read ((PTR)&nextname, 1, 1, abfd) != 1) { result = bfd_read ((PTR)&nextname, 1, 1, abfd);
bfd_seek (abfd, -1L, SEEK_CUR);
bfd_has_map(abfd) = false;
return true;
}
bfd_seek (abfd, -1L, SEEK_CUR); bfd_seek (abfd, -1L, SEEK_CUR);
if (nextname != '/') { if (result != 1 || nextname != '/') {
/* Actually I think this is an error for a COFF archive */ /* Actually I think this is an error for a COFF archive */
bfd_has_map (abfd) = false; bfd_has_map (abfd) = false;
return true; return true;
@ -492,7 +496,7 @@ bfd_slurp_coff_armap (abfd)
if (raw_armap == NULL) { if (raw_armap == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
byebye: byebye:
bfd_release (abfd, (PTR)mapdata);
return false; return false;
} }
@ -500,7 +504,7 @@ bfd_slurp_coff_armap (abfd)
mapdata->parsed_size) { mapdata->parsed_size) {
bfd_error = malformed_archive; bfd_error = malformed_archive;
oops: oops:
bfd_release (abfd, (PTR)raw_armap);
goto byebye; goto byebye;
} }
@ -540,11 +544,11 @@ bfd_slurp_coff_armap (abfd)
ardata->first_file_filepos = bfd_tell (abfd); ardata->first_file_filepos = bfd_tell (abfd);
/* Pad to an even boundary if you have to */ /* Pad to an even boundary if you have to */
ardata->first_file_filepos += (ardata->first_file_filepos) %2; ardata->first_file_filepos += (ardata->first_file_filepos) %2;
bfd_release (abfd, (PTR)raw_armap);
bfd_release (abfd, (PTR)mapdata);
bfd_has_map (abfd) = true; bfd_has_map (abfd) = true;
return true; return true;
} }
/** Extended name table. /** Extended name table.
@ -562,6 +566,8 @@ _bfd_slurp_extended_name_table (abfd)
char nextname[17]; char nextname[17];
struct areltdata *namedata; struct areltdata *namedata;
/* FIXME: Formatting sucks here, and in case of failure of BFD_READ,
we probably don't want to return true. */
if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) { if (bfd_read ((PTR)nextname, 1, 16, abfd) == 16) {
bfd_seek (abfd, -16L, SEEK_CUR); bfd_seek (abfd, -16L, SEEK_CUR);
@ -574,19 +580,18 @@ _bfd_slurp_extended_name_table (abfd)
namedata = snarf_ar_hdr (abfd); namedata = snarf_ar_hdr (abfd);
if (namedata == NULL) return false; if (namedata == NULL) return false;
bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size); bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size);
if (bfd_ardata (abfd)->extended_names == NULL) { if (bfd_ardata (abfd)->extended_names == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
byebye: byebye:
bfd_release (abfd, (PTR)namedata);
return false; return false;
} }
if (bfd_read ((PTR)bfd_ardata (abfd)->extended_names, 1, if (bfd_read ((PTR)bfd_ardata (abfd)->extended_names, 1,
namedata->parsed_size, abfd) != namedata->parsed_size) { namedata->parsed_size, abfd) != namedata->parsed_size) {
bfd_error = malformed_archive; bfd_error = malformed_archive;
bfd_release (abfd, (PTR)(bfd_ardata (abfd)->extended_names));
bfd_ardata (abfd)->extended_names = NULL; bfd_ardata (abfd)->extended_names = NULL;
goto byebye; goto byebye;
} }
@ -604,7 +609,9 @@ _bfd_slurp_extended_name_table (abfd)
bfd_ardata (abfd)->first_file_filepos += bfd_ardata (abfd)->first_file_filepos +=
(bfd_ardata (abfd)->first_file_filepos) %2; (bfd_ardata (abfd)->first_file_filepos) %2;
/* FIXME, we can't release namedata here because it was allocated
below extended_names on the obstack... */
/* bfd_release (abfd, namedata); */
} }
return true; return true;
} }
@ -791,7 +798,7 @@ bfd_dont_truncate_arname (abfd, pathname, arhdr)
char *pathname; char *pathname;
char *arhdr; char *arhdr;
{ {
/* This interacts unpleasantly with ar's quick-append option. /* FIXME: This interacts unpleasantly with ar's quick-append option.
Fortunately ic960 users will never use that option. Fixing this Fortunately ic960 users will never use that option. Fixing this
is very hard; fortunately I know how to do it and will do so once is very hard; fortunately I know how to do it and will do so once
intel's release is out the door. */ intel's release is out the door. */
@ -901,7 +908,6 @@ _bfd_write_archive_contents (arch)
boolean hasobjects = false; /* if no .o's, don't bother to make a map */ boolean hasobjects = false; /* if no .o's, don't bother to make a map */
unsigned int i; unsigned int i;
/* Verify the viability of all entries; if any of them live in the /* Verify the viability of all entries; if any of them live in the
filesystem (as opposed to living in an archive open for input) filesystem (as opposed to living in an archive open for input)
then construct a fresh ar_hdr for them. then construct a fresh ar_hdr for them.
@ -996,8 +1002,6 @@ return true;
/* Note that the namidx for the first symbol is 0 */ /* Note that the namidx for the first symbol is 0 */
boolean boolean
compute_and_write_armap (arch, elength) compute_and_write_armap (arch, elength)
bfd *arch; bfd *arch;

View File

@ -55,8 +55,6 @@ struct arch_print {
{bfd_arch_pyramid, "pyramid", prt_num_mach, scan_num_mach}, {bfd_arch_pyramid, "pyramid", prt_num_mach, scan_num_mach},
{bfd_arch_h8_300, "H8/300", prt_num_mach, scan_num_mach}, {bfd_arch_h8_300, "H8/300", prt_num_mach, scan_num_mach},
{bfd_arch_unknown, (char *)0, prt_num_mach, scan_num_mach}, {bfd_arch_unknown, (char *)0, prt_num_mach, scan_num_mach},
}; };
/* Return a printable string representing the architecture and machine /* Return a printable string representing the architecture and machine
@ -310,13 +308,13 @@ bfd_arch_compatible (abfd, bbfd, archp, machinep)
/* If particular machine types of one architecture are not /* If particular machine types of one architecture are not
compatible with each other, this is the place to put those tests compatible with each other, this is the place to put those tests
(returning false if incompatible). */ (returning false if incompatible). */
case bfd_arch_i960: case bfd_arch_i960:
/* The i960 has to distinct subspecies which may not interbreed: /* The i960 has two distinct subspecies which may not interbreed:
CORE CA CORE CA
CORE KA KB MC CORE KA KB MC
Any architecture on the same line is compatible, the one on Any architecture on the same line is compatible, the one on
the right is the least restrictive. the right is the least restrictive. */
*/
/* So, if either is a ca then the other must be a be core or ca */ /* So, if either is a ca then the other must be a be core or ca */
if (macha == bfd_mach_i960_ca) { if (macha == bfd_mach_i960_ca) {
if (machb != bfd_mach_i960_ca && if (machb != bfd_mach_i960_ca &&
@ -336,9 +334,6 @@ bfd_arch_compatible (abfd, bbfd, archp, machinep)
/* This must be from the bottom row, so take the higest */ /* This must be from the bottom row, so take the higest */
pick_a = (macha > machb); pick_a = (macha > machb);
} }
break; break;
/* For these chips, as far as we care, "lower" numbers are included /* For these chips, as far as we care, "lower" numbers are included

View File

@ -31,14 +31,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
short _bfd_host_big_endian = 0x0100; short _bfd_host_big_endian = 0x0100;
/* Accessing the above as (*(char*)&_bfd_host_big_endian), will /* Accessing the above as (*(char*)&_bfd_host_big_endian), will
* return 1 if the host is big-endian, 0 otherwise. return 1 if the host is big-endian, 0 otherwise.
* (See HOST_IS_BIG_ENDIAN_P in bfd.h.) (assuming that a short is two bytes long!!! FIXME)
*/ (See HOST_IS_BIG_ENDIAN_P in bfd.h.) */
/** Error handling /** Error handling
o - Most functions return nonzero on success (check doc for o - Most functions return nonzero on success (check doc for
precise semantics); 0 or NULL on error. precise semantics); 0 or NULL on error.
@ -67,7 +63,6 @@ char *bfd_errmsgs[] = {"No error",
"#<Invalid error code>" "#<Invalid error code>"
}; };
static static
void void
DEFUN(bfd_nonrepresentable_section,(abfd, name), DEFUN(bfd_nonrepresentable_section,(abfd, name),
@ -80,6 +75,7 @@ DEFUN(bfd_nonrepresentable_section,(abfd, name),
name); name);
exit(1); exit(1);
} }
bfd_error_vector_type bfd_error_vector = bfd_error_vector_type bfd_error_vector =
{ {
bfd_nonrepresentable_section bfd_nonrepresentable_section
@ -99,12 +95,10 @@ strerror (code)
#endif /* not ANSI_LIBRARIES */ #endif /* not ANSI_LIBRARIES */
char * char *
bfd_errmsg (error_tag) bfd_errmsg (error_tag)
bfd_ec error_tag; bfd_ec error_tag;
{ {
extern int errno;
if (error_tag == system_call_error) if (error_tag == system_call_error)
return strerror (errno); return strerror (errno);
@ -125,12 +119,13 @@ bfd_ec error_tag;
void (*bfd_error_trap)() = bfd_default_error_trap; void (*bfd_error_trap)() = bfd_default_error_trap;
void (*bfd_error_nonrepresentabltrap)() = bfd_default_error_trap; void (*bfd_error_nonrepresentabltrap)() = bfd_default_error_trap;
void void
DEFUN(bfd_perror,(message), DEFUN(bfd_perror,(message),
CONST char *message) CONST char *message)
{ {
if (bfd_error == system_call_error) if (bfd_error == system_call_error)
perror(message); /* must be system error then... */ perror((char *)message); /* must be system error then... */
else { else {
if (message == NULL || *message == '\0') if (message == NULL || *message == '\0')
fprintf (stderr, "%s\n", bfd_errmsg (bfd_error)); fprintf (stderr, "%s\n", bfd_errmsg (bfd_error));
@ -228,9 +223,6 @@ bfd_check_format (abfd, format)
bfd *abfd; bfd *abfd;
bfd_format format; bfd_format format;
{ {
#if obsolete
file_ptr filepos;
#endif
bfd_target **target, *save_targ, *right_targ; bfd_target **target, *save_targ, *right_targ;
int match_count; int match_count;
@ -246,11 +238,7 @@ bfd_check_format (abfd, format)
/* presume the answer is yes */ /* presume the answer is yes */
abfd->format = format; abfd->format = format;
#if obsolete bfd_seek (abfd, (file_ptr)0, SEEK_SET); /* rewind! */
filepos = bfd_tell (abfd);
#endif
bfd_seek (abfd, (file_ptr)0, SEEK_SET); /* instead, rewind! */
right_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); right_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
if (right_targ) { if (right_targ) {
@ -270,9 +258,6 @@ bfd_check_format (abfd, format)
bfd_target *temp; bfd_target *temp;
abfd->xvec = *target; /* Change BFD's target temporarily */ abfd->xvec = *target; /* Change BFD's target temporarily */
#if obsolete
bfd_seek (abfd, filepos, SEEK_SET); /* Restore original file position */
#endif
bfd_seek (abfd, (file_ptr)0, SEEK_SET); bfd_seek (abfd, (file_ptr)0, SEEK_SET);
temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
if (temp) { /* This format checks out as ok! */ if (temp) { /* This format checks out as ok! */
@ -299,9 +284,6 @@ bfd_check_format (abfd, format)
abfd->format = bfd_unknown; /* Restore original format */ abfd->format = bfd_unknown; /* Restore original format */
bfd_error = ((match_count == 0) ? file_not_recognized : bfd_error = ((match_count == 0) ? file_not_recognized :
file_ambiguously_recognized); file_ambiguously_recognized);
#if obsolete
bfd_seek (abfd, filepos, SEEK_SET); /* Restore original file position */
#endif
return false; return false;
} }
@ -311,7 +293,6 @@ bfd_set_format (abfd, format)
bfd_format format; bfd_format format;
{ {
if (bfd_read_p (abfd) || if (bfd_read_p (abfd) ||
((int)abfd->format < (int)bfd_unknown) || ((int)abfd->format < (int)bfd_unknown) ||
((int)abfd->format >= (int)bfd_type_end)) { ((int)abfd->format >= (int)bfd_type_end)) {
@ -324,11 +305,8 @@ bfd_set_format (abfd, format)
/* presume the answer is yes */ /* presume the answer is yes */
abfd->format = format; abfd->format = format;
/* filepos = bfd_tell (abfd);*/
if (!BFD_SEND_FMT (abfd, _bfd_set_format, (abfd))) { if (!BFD_SEND_FMT (abfd, _bfd_set_format, (abfd))) {
abfd->format = bfd_unknown; abfd->format = bfd_unknown;
/* bfd_seek (abfd, filepos, SEEK_SET);*/
return false; return false;
} }
@ -381,7 +359,6 @@ DEFUN(bfd_make_section,(abfd, name),
newsect->index = abfd->section_count++; newsect->index = abfd->section_count++;
newsect->flags = SEC_NO_FLAGS; newsect->flags = SEC_NO_FLAGS;
newsect->userdata = 0; newsect->userdata = 0;
newsect->next = (asection *)NULL; newsect->next = (asection *)NULL;
newsect->relocation = (arelent *)NULL; newsect->relocation = (arelent *)NULL;
@ -674,7 +651,7 @@ bfd *output_bfd;
bfd_vma relocation_before; bfd_vma relocation_before;
bfd_vma addr = reloc_entry->address ; bfd_vma addr = reloc_entry->address ;
bfd_vma output_base = 0; bfd_vma output_base = 0;
CONST struct rint_struct *howto = reloc_entry->howto; reloc_howto_type *howto = reloc_entry->howto;
asection *reloc_target_output_section; asection *reloc_target_output_section;
asection *reloc_target_input_section; asection *reloc_target_input_section;
asymbol *symbol; asymbol *symbol;

View File

@ -23,13 +23,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "bfd.h" #include "bfd.h"
#include "libbfd.h" #include "libbfd.h"
/* These declarations should not be needed; libbfd.h's inclusion should
have handled it.
int fclose();
int fseek();
*/
/* The maximum number of FDs opened by bfd */ /* The maximum number of FDs opened by bfd */
#define BFD_CACHE_MAX_OPEN 10 #define BFD_CACHE_MAX_OPEN 10
@ -38,10 +31,14 @@ static int open_files;
static bfd *cache_sentinel; /* Chain of bfds with active fds we've static bfd *cache_sentinel; /* Chain of bfds with active fds we've
opened */ opened */
static void
bfd_cache_delete();
bfd *bfd_last_cache; bfd *bfd_last_cache; /* Zero, or a pointer to the topmost
bfd on the chain. This is used by the
bfd_cache_lookup() macro in libbfd.h
to determine when it can avoid a function
call. */
static void bfd_cache_delete();
static void static void
@ -60,8 +57,8 @@ DEFUN_VOID(close_one)
kill->where = ftell((FILE *)(kill->iostream)); kill->where = ftell((FILE *)(kill->iostream));
bfd_cache_delete(kill); bfd_cache_delete(kill);
} }
/* Cuts the bfd abfd out of the chain in the cache */ /* Cuts the bfd abfd out of the chain in the cache */
static void static void
DEFUN(snip,(abfd), DEFUN(snip,(abfd),

View File

@ -1,5 +1,6 @@
/* /* Support for Intel 960 COFF and Motorola 88k BCS COFF (and maybe others) */
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Diddler. This file is part of BFD, the Binary File Diddler.
@ -18,37 +19,37 @@ You should have received a copy of the GNU General Public License along with
*/ */
/* $Id$ */ /* $Id$ */
/* /* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
Most of this hacked by Steve Chamberlain, steve@cygnus.com
(All the ugly bits by rich :)
*/
#include "archures.h" /* Machine architectures and types */ #include "archures.h" /* Machine architectures and types */
/* SUPPRESS 558 */ /* SUPPRESS 558 */
/* SUPPRESS 590 */ /* SUPPRESS 590 */
/* SUPPRESS 529 */ /* SUPPRESS 529 */
/* SUPPRESS 530 */ /* SUPPRESS 530 */
/* Align an address upward to a boundary, expressed as a number of bytes.
E.g. align to an 8-byte boundary with argument of 8. */
#define ALIGN(this, boundary) \ #define ALIGN(this, boundary) \
((( (this) + ((boundary) -1)) & (~((boundary)-1)))) ((( (this) + ((boundary) -1)) & (~((boundary)-1))))
#define sp(x) bfd_h_put_x(abfd, x, &x) /* Align an address upward to a power of two. Argument is the power
of two, e.g. 8-byte alignment uses argument of 3 (8 == 2^3). */
/*
Align an address by rounding it up to a power of two. It leaves the
address unchanged if align == 0 (2^0 = alignment of 1 byte)
*/
#define i960_align(addr, align) \ #define i960_align(addr, align) \
( ((addr) + ((1<<(align))-1)) & (-1 << (align))) ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
#define sp(x) bfd_h_put_x(abfd, x, &x)
PROTO(static void,force_indices_file_symbol_relative,(bfd *abfd, SYMENT *symtab)); PROTO(static void,force_indices_file_symbol_relative,(bfd *abfd, SYMENT *symtab));
/* All the swapping routines */ /* All the swapping routines:
FIXME, these routines assume that the sizes, alignments, and offsets of
these fields are the same in the host and target. This is an invalid
assumption, which in particular breaks on the 386 and SPARC. Fix this
the same way that a.out.h and sunos.c were fixed: define char arrays
that represent the headers in the target systems' file, and have these
functions translate in from that format, and out to that format. */
static void static void
DEFUN(swap_reloc,(abfd, reloc), DEFUN(swap_reloc,(abfd, reloc),
@ -114,101 +115,10 @@ DEFUN(swap_scnhdr,(abfd, scnhdr),
sp(scnhdr->s_align); sp(scnhdr->s_align);
#endif #endif
} }
static void
DEFUN(swap_name,(abfd, ptr),
bfd *abfd AND
long *ptr)
{
if (ptr[0] == 0) {
/* There is an index which needs to be swapped */
bfd_h_put_x(abfd, ptr[1], (ptr + 1));
}
else {
/* This is a string .. leave it alone */
}
}
static void
DEFUN(bfd_coff_swap_sym,(abfd, se),
bfd *abfd AND
SYMENT *se)
{
swap_name(abfd, (long*)(se->n_name));
bfd_h_put_x(abfd, se->n_value, &se->n_value);
bfd_h_put_x(abfd, se->n_scnum, &se->n_scnum);
bfd_h_put_x(abfd, se->n_type, &se->n_type);
bfd_h_put_x(abfd, se->n_sclass, &se->n_sclass);
bfd_h_put_x(abfd, se->n_numaux, &se->n_numaux);
}
#ifndef I960
static
#endif
void
DEFUN(bfd_coff_swap_aux,(abfd, au, type, class),
bfd *abfd AND
AUXENT *au AND
int type AND
int class)
{
switch (class) {
case C_FILE:
swap_name(abfd, (long *)(&au->x_file.x_n));
break;
case C_STAT:
#ifdef C_LEAFSTAT
case C_LEAFSTAT:
#endif
case C_HIDDEN:
if (type == T_NULL) {
sp(au->x_scn.x_scnlen);
sp(au->x_scn.x_nreloc);
sp(au->x_scn.x_nlinno);
break;
}
default:
sp(au->x_sym.x_tagndx);
sp(au->x_sym.x_tvndx);
if (ISARY(type)) {
sp(au->x_sym.x_fcnary.x_ary.x_dimen[0]);
sp(au->x_sym.x_fcnary.x_ary.x_dimen[1]);
sp(au->x_sym.x_fcnary.x_ary.x_dimen[2]);
sp(au->x_sym.x_fcnary.x_ary.x_dimen[3]);
}
else {
sp(au->x_sym.x_fcnary.x_fcn.x_lnnoptr);
sp(au->x_sym.x_fcnary.x_fcn.x_endndx);
}
if (ISFCN(type)) {
sp(au->x_sym.x_misc.x_fsize);
}
else {
sp(au->x_sym.x_misc.x_lnsz.x_lnno);
sp(au->x_sym.x_misc.x_lnsz.x_size);
}
}
}
#ifndef I960
static
#endif
void
DEFUN(bfd_coff_swap_lineno,(abfd, lineno),
bfd *abfd AND
LINENO *lineno)
{
sp(lineno->l_addr.l_symndx);
sp(lineno->l_lnno);
}
/* void warning(); */ /* void warning(); */
extern asection abs_section; extern asection abs_section;
static int static int
DEFUN(get_index,(symbol), DEFUN(get_index,(symbol),
asymbol *symbol) asymbol *symbol)
@ -235,12 +145,17 @@ DEFUN(coff_new_section_hook,(abfd_ignore, section_ignore),
asection *section_ignore) asection *section_ignore)
{ {
#ifdef MC88MAGIC #ifdef MC88MAGIC
/* FIXME, shouldn't this ifdef be on something that says we are
actually COMPILING FOR an 88K coff file, rather than simply
knowing its magic number? */
/* Align to at least 16 bytes */ /* Align to at least 16 bytes */
section_ignore->alignment_power = 4; section_ignore->alignment_power = 4;
#endif #endif
return true; return true;
} }
/* actually it makes itself and its children from the file headers */
/* Take a section header read from a coff file (in HOST byte order),
and make a BFD "section" out of it. */
static boolean static boolean
DEFUN(make_a_section_from_file,(abfd, hdr), DEFUN(make_a_section_from_file,(abfd, hdr),
bfd *abfd AND bfd *abfd AND
@ -248,16 +163,18 @@ DEFUN(make_a_section_from_file,(abfd, hdr),
{ {
asection *return_section; asection *return_section;
{ {
char *name = bfd_alloc(abfd, 9); /* Assorted wastage to null-terminate the name, thanks AT&T! */
char *name = bfd_alloc(abfd, sizeof (hdr->s_name)+1);
if (name == NULL) { if (name == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
return false; return false;
} /* on error */ }
strncpy(name, (char *) &hdr->s_name[0], 8); strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name));
name[sizeof (hdr->s_name)] = 0;
return_section = bfd_make_section(abfd, name); return_section = bfd_make_section(abfd, name);
(return_section->name)[8] = 0;
} }
/* s_paddr is presumed to be = to s_vaddr */ /* s_paddr is presumed to be = to s_vaddr */
@ -270,7 +187,7 @@ DEFUN(make_a_section_from_file,(abfd, hdr),
assign(reloc_count, s_nreloc); assign(reloc_count, s_nreloc);
#ifdef I960 #ifdef I960
{ {
/* FIXME, use a temp var rather than alignment_power */
assign(alignment_power, s_align); assign(alignment_power, s_align);
{ {
unsigned int i; unsigned int i;
@ -308,13 +225,13 @@ static boolean
DEFUN(coff_mkobject,(abfd), DEFUN(coff_mkobject,(abfd),
bfd *abfd) bfd *abfd)
{ {
coff_data_type *coff; set_tdata (abfd, bfd_alloc (abfd,sizeof(coff_data_type)));
coff_data(abfd) = if (coff_data(abfd) == 0) {
(coff_data_type*)bfd_alloc(abfd,sizeof(coff_data_type)); bfd_error = no_memory;
coff = coff_data(abfd); return false;
coff->relocbase = 0; }
coff_data(abfd)->relocbase = 0;
return true; return true;
} }
static static
@ -331,26 +248,34 @@ DEFUN(coff_real_object_p,(abfd, nscns, opthdr),
struct scnhdr *sections; /* points into file_info */ struct scnhdr *sections; /* points into file_info */
/* Build a play area */ /* Build a play area */
(void) coff_mkobject(abfd); if (coff_mkobject(abfd) != true)
return 0;
coff = coff_data(abfd); coff = coff_data(abfd);
/*
OK, now we know the format, read in the filehdr, soi-disant "optional /* OK, now we know the format, read in the filehdr, soi-disant "optional
header", and all the sections. header", and all the sections. */
*/
readsize = sizeof(struct filehdr) readsize = sizeof(struct filehdr)
+ opthdr + opthdr
+ (nscns * sizeof(struct scnhdr)); + (nscns * sizeof(struct scnhdr));
file_info = (PTR) bfd_alloc(abfd, readsize); file_info = (PTR) bfd_alloc(abfd, readsize);
if (bfd_seek(abfd, 0L, SEEK_SET) < 0) if (file_info == NULL) {
bfd_error = no_memory;
goto fail; goto fail;
}
if (bfd_read((PTR) file_info, 1, readsize, abfd) != readsize) if (bfd_seek(abfd, 0L, SEEK_SET) < 0) {
bfd_release (abfd, (PTR)file_info);
goto fail; goto fail;
}
if (bfd_read((PTR) file_info, 1, readsize, abfd) != readsize) {
bfd_release (abfd, (PTR)file_info);
goto fail;
}
filehdr = (struct filehdr *) file_info; filehdr = (struct filehdr *) file_info;
sections = (struct scnhdr *) (file_info + sizeof(struct filehdr) + opthdr); sections = (struct scnhdr *) (file_info + sizeof(struct filehdr) + opthdr);
swap_filehdr(abfd, filehdr); swap_filehdr(abfd, filehdr);
/* Now copy data as required; construct all asections etc */ /* Now copy data as required; construct all asections etc */
@ -492,9 +417,9 @@ DEFUN(coff_object_p,(abfd),
nscns = bfd_h_getshort(abfd, (unsigned char *) &nscns); nscns = bfd_h_getshort(abfd, (unsigned char *) &nscns);
if (bfd_seek(abfd, (file_ptr) & (((struct filehdr *) NULL)->f_opthdr), SEEK_SET) if (bfd_seek(abfd, (file_ptr) & (((struct filehdr *) NULL)->f_opthdr), SEEK_SET)
< 0) < 0)
return (bfd_target *) NULL; return 0;
if (bfd_read((PTR) &opthdr, 1, sizeof(opthdr), abfd) != sizeof(opthdr)) if (bfd_read((PTR) &opthdr, 1, sizeof(opthdr), abfd) != sizeof(opthdr))
return (bfd_target *) NULL; return 0;
opthdr = bfd_h_getshort(abfd, (unsigned char *) &opthdr); opthdr = bfd_h_getshort(abfd, (unsigned char *) &opthdr);
/* if the optional header is NULL or not the correct size then /* if the optional header is NULL or not the correct size then
@ -570,10 +495,6 @@ DEFUN(uses_x_sym_x_tagndx_p,(native),
} }
/* /*
This procedure runs through the native entries in a coff symbol table This procedure runs through the native entries in a coff symbol table
and links up all the elements which should point to one another, in and links up all the elements which should point to one another, in
@ -608,10 +529,8 @@ differences between to items, used to work out the true index of the
target. target.
We store in the name field of each syment the actual native index We store in the name field of each syment the actual native index
applied so we can dig it out through a pointer. applied so we can dig it out through a pointer. */
*/
static void static void
coff_mangle_symbols(bfd_ptr) coff_mangle_symbols(bfd_ptr)
bfd *bfd_ptr; bfd *bfd_ptr;
@ -783,11 +702,6 @@ bfd *bfd_ptr;
} }
static void static void
coff_write_symbols(abfd) coff_write_symbols(abfd)
bfd *abfd; bfd *abfd;
@ -1001,6 +915,7 @@ coff_write_relocs(abfd)
} }
} }
} }
static void static void
coff_write_linenumbers(abfd) coff_write_linenumbers(abfd)
bfd *abfd; bfd *abfd;
@ -1085,6 +1000,7 @@ coff_print_symbol(ignore_abfd, file, symbol, how)
break; break;
} }
} }
static alent * static alent *
coff_get_lineno(ignore_abfd, symbol) coff_get_lineno(ignore_abfd, symbol)
bfd *ignore_abfd; bfd *ignore_abfd;
@ -1092,6 +1008,7 @@ coff_get_lineno(ignore_abfd, symbol)
{ {
return coffsymbol(symbol)->lineno; return coffsymbol(symbol)->lineno;
} }
/* /*
Set flags and magic number of a coff file from architecture and machine Set flags and magic number of a coff file from architecture and machine
type. Result is true if we can represent the arch&type, false if not. type. Result is true if we can represent the arch&type, false if not.
@ -1103,7 +1020,6 @@ coff_set_flags(abfd, magicp, flagsp)
*flagsp; *flagsp;
{ {
switch (abfd->obj_arch) { switch (abfd->obj_arch) {
#ifdef I960ROMAGIC #ifdef I960ROMAGIC
@ -1144,11 +1060,13 @@ coff_set_flags(abfd, magicp, flagsp)
} }
break; break;
#endif #endif
#ifdef MC68MAGIC #ifdef MC68MAGIC
case bfd_arch_m68k: case bfd_arch_m68k:
*magicp = MC68MAGIC; *magicp = MC68MAGIC;
return true; return true;
#endif #endif
#ifdef MC88MAGIC #ifdef MC88MAGIC
case bfd_arch_m88k: case bfd_arch_m88k:
*magicp = MC88OMAGIC; *magicp = MC88OMAGIC;
@ -1204,14 +1122,23 @@ coff_compute_section_file_positions(abfd)
for (current = abfd->sections; current != NULL; current = for (current = abfd->sections; current != NULL; current =
current->next) { current->next) {
#ifdef MC88MAGIC /* Only deal with sections which have contents */
sofar = current->filepos = ALIGN(sofar, 1<< if (!(current->flags & SEC_HAS_CONTENTS))
current->alignment_power); continue;
#else
current->filepos = sofar; /* Align the sections in the file to the same boundary on
which they are aligned in virtual memory. I960 doesn't
do this (FIXME) so we can stay in sync with Intel. 960
doesn't yet page from files... */
#ifndef I960
sofar = ALIGN(sofar, 1 << current->alignment_power);
#endif #endif
/* Only add sections which have contents */ /* FIXME, in demand paged files, the low order bits of the file
if (current->flags & SEC_HAS_CONTENTS) offset must match the low order bits of the virtual address.
"Low order" is apparently implementation defined. Add code
here to round sofar up to match the virtual address. */
current->filepos = sofar;
sofar += current->size; sofar += current->size;
} }
obj_relocbase(abfd) = sofar; obj_relocbase(abfd) = sofar;
@ -1290,7 +1217,6 @@ coff_write_object_contents(abfd)
current->line_filepos = lineno_base; current->line_filepos = lineno_base;
current->moving_line_filepos = lineno_base; current->moving_line_filepos = lineno_base;
lineno_base += current->lineno_count * sizeof(struct lineno); lineno_base += current->lineno_count * sizeof(struct lineno);
} }
else { else {
current->line_filepos = 0; current->line_filepos = 0;
@ -1304,17 +1230,19 @@ coff_write_object_contents(abfd)
} }
} }
/* Write section headers to the file. */
bfd_seek(abfd, bfd_seek(abfd,
(file_ptr) ((abfd->flags & EXEC_P) ? (file_ptr) ((abfd->flags & EXEC_P) ?
(FILHSZ + AOUTSZ) : FILHSZ), (FILHSZ + AOUTSZ) : FILHSZ),
SEEK_SET); SEEK_SET);
{ {
#if 0 #if 0
unsigned int pad = abfd->flags & D_PAGED ? data_base : 0; unsigned int pad = abfd->flags & D_PAGED ? data_base : 0;
#endif #endif
unsigned int pad = 0; unsigned int pad = 0;
for (current = abfd->sections; current != NULL; current = current->next) { for (current = abfd->sections; current != NULL; current = current->next) {
SCNHDR section; SCNHDR section;
strncpy(&(section.s_name[0]), current->name, 8); strncpy(&(section.s_name[0]), current->name, 8);
@ -1344,19 +1272,15 @@ coff_write_object_contents(abfd)
if (!strcmp(current->name, _TEXT)) { if (!strcmp(current->name, _TEXT)) {
text_sec = current; text_sec = current;
section.s_flags = STYP_TEXT; /* kind stupid optimisation */ section.s_flags = STYP_TEXT; /* kinda stupid */
} }
else { else if (!strcmp(current->name, _DATA)) {
if (!strcmp(current->name, _DATA)) {
data_sec = current; data_sec = current;
section.s_flags = STYP_DATA; /* kind stupid section.s_flags = STYP_DATA; /* kinda stupid */
optimisation */
} }
else if (!strcmp(current->name, _BSS)) { else if (!strcmp(current->name, _BSS)) {
bss_sec = current; bss_sec = current;
section.s_flags = STYP_BSS; /* kind stupid optimisation */ section.s_flags = STYP_BSS; /* kinda stupid */
}
} }
@ -1370,8 +1294,8 @@ coff_write_object_contents(abfd)
bfd_write((PTR) (&section), 1, SCNHSZ, abfd); bfd_write((PTR) (&section), 1, SCNHSZ, abfd);
pad = 0; pad = 0;
} }
} }
/* OK, now set up the filehdr... */ /* OK, now set up the filehdr... */
bfd_h_put_x(abfd, abfd->section_count, &file_header.f_nscns); bfd_h_put_x(abfd, abfd->section_count, &file_header.f_nscns);
@ -1465,25 +1389,22 @@ coff_write_object_contents(abfd)
if (bss_sec) { if (bss_sec) {
bfd_h_put_x(abfd, bss_sec->size, &coff->hdr.bsize); bfd_h_put_x(abfd, bss_sec->size, &coff->hdr.bsize);
} }
bfd_h_put_x(abfd, bfd_get_start_address(abfd), &coff->hdr.entry);
bfd_h_put_x(abfd, bfd_get_start_address(abfd), &coff->hdr.entry);
bfd_h_put_x(abfd, bfd_get_symcount(abfd), &file_header.f_nsyms);
/* now write them */ /* now write them */
bfd_h_put_x(abfd, bfd_get_symcount(abfd), &file_header.f_nsyms);
if (bfd_seek(abfd, 0L, SEEK_SET) != 0) if (bfd_seek(abfd, 0L, SEEK_SET) != 0)
return false; return false;
bfd_write((PTR) &file_header, 1, FILHSZ, abfd); bfd_write((PTR) &file_header, 1, FILHSZ, abfd);
if (abfd->flags & EXEC_P) { if (abfd->flags & EXEC_P) {
bfd_write((PTR) &coff->hdr, 1, AOUTSZ, abfd); bfd_write((PTR) &coff->hdr, 1, AOUTSZ, abfd);
} }
return true; return true;
} }
static boolean static boolean
coff_set_section_contents(abfd, section, location, offset, count) coff_set_section_contents(abfd, section, location, offset, count)
bfd *abfd; bfd *abfd;
@ -1502,6 +1423,7 @@ coff_set_section_contents(abfd, section, location, offset, count)
} }
return true; return true;
} }
static boolean static boolean
coff_get_section_contents(abfd, section, location, offset, count) coff_get_section_contents(abfd, section, location, offset, count)
bfd *abfd; bfd *abfd;
@ -1539,21 +1461,12 @@ coff_close_and_cleanup(abfd)
return false; return false;
} }
#define cleaner(ptr) if (abfd->ptr) free (abfd->ptr) /* We depend on bfd_close to free all the memory on the obstack. */
cleaner(tdata); /* FIXME if bfd_release is not using obstacks! */
if (abfd->my_archive)
cleaner(filename);
#undef cleaner
return true; return true;
} }
static PTR static PTR
buy_and_read(abfd, where, seek_direction, size) buy_and_read(abfd, where, seek_direction, size)
bfd *abfd; bfd *abfd;
@ -1633,6 +1546,7 @@ offset_symbol_indices(symtab, count, offset)
return; return;
} /* offset_symbol_indices() */ } /* offset_symbol_indices() */
/* swap the entire symbol table */ /* swap the entire symbol table */
static void static void
swap_raw_symtab(abfd, raw_symtab) swap_raw_symtab(abfd, raw_symtab)
@ -1654,6 +1568,7 @@ swap_raw_symtab(abfd, raw_symtab)
return; return;
} /* swap_raw_symtab() */ } /* swap_raw_symtab() */
/* /*
read a symbol table into freshly mallocated memory, swap it, and knit the read a symbol table into freshly mallocated memory, swap it, and knit the
symbol names into a normalized form. By normalized here I mean that all symbol names into a normalized form. By normalized here I mean that all
@ -1673,13 +1588,12 @@ get_normalized_symtab(abfd)
unsigned long size; unsigned long size;
unsigned long string_table_size = 0; unsigned long string_table_size = 0;
if ((size = bfd_get_symcount(abfd) * sizeof(SYMENT)) == 0) { if ((size = bfd_get_symcount(abfd) * sizeof(SYMENT)) == 0) {
bfd_error = no_symbols; bfd_error = no_symbols;
return (NULL); return (NULL);
} /* no symbols */ } /* no symbols */
/*
This is a hack. Some tool chains fail to put a C_FILE symbol at the /* This is a hack. Some tool chains fail to put a C_FILE symbol at the
beginning of the symbol table. To make life simpler for our users, we beginning of the symbol table. To make life simpler for our users, we
inject one if it wasn't there originally. inject one if it wasn't there originally.
@ -1849,7 +1763,7 @@ get_normalized_symtab(abfd)
#ifndef GNU960 #ifndef GNU960
/* I'm not sure of the repercussions of this, so the Intel /* I'm not sure of the repercussions of this, so the Intel
folks will always to the force folks will always do the force
*/ */
if (obj_symbol_slew(abfd) > 0) if (obj_symbol_slew(abfd) > 0)
force_indices_file_symbol_relative(abfd, retval); force_indices_file_symbol_relative(abfd, retval);
@ -1860,19 +1774,17 @@ get_normalized_symtab(abfd)
obj_raw_syments(abfd) = retval; obj_raw_syments(abfd) = retval;
obj_string_table(abfd) = string_table; obj_string_table(abfd) = string_table;
return (retval); return (retval);
} /* get_normalized_symtab() */ } /* get_normalized_symtab() */
static static
struct sec_struct * struct sec *
section_from_bfd_index(abfd, index) section_from_bfd_index(abfd, index)
bfd *abfd; bfd *abfd;
int index; int index;
{ {
if (index > 0) { if (index > 0) {
struct sec_struct *answer = abfd->sections; struct sec *answer = abfd->sections;
while (--index) { while (--index) {
answer = answer->next; answer = answer->next;
} }
@ -1884,16 +1796,15 @@ section_from_bfd_index(abfd, index)
static static boolean
boolean
coff_slurp_line_table(abfd, asect) coff_slurp_line_table(abfd, asect)
bfd *abfd; bfd *abfd;
asection *asect; asection *asect;
{ {
struct lineno *native_lineno; struct lineno *native_lineno;
alent *lineno_cache; alent *lineno_cache;
BFD_ASSERT(asect->lineno == (alent *) NULL);
BFD_ASSERT(asect->lineno == (alent *) NULL);
native_lineno = (struct lineno *) buy_and_read(abfd, native_lineno = (struct lineno *) buy_and_read(abfd,
asect->line_filepos, asect->line_filepos,
@ -1905,10 +1816,11 @@ coff_slurp_line_table(abfd, asect)
if (lineno_cache == NULL) { if (lineno_cache == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
return false; return false;
} { /* on error */ } else {
unsigned int counter = 0; unsigned int counter = 0;
alent *cache_ptr = lineno_cache; alent *cache_ptr = lineno_cache;
struct lineno *src = native_lineno; struct lineno *src = native_lineno;
while (counter < asect->lineno_count) { while (counter < asect->lineno_count) {
bfd_coff_swap_lineno(abfd, src); bfd_coff_swap_lineno(abfd, src);
cache_ptr->line_number = src->l_lnno; cache_ptr->line_number = src->l_lnno;
@ -1934,6 +1846,7 @@ coff_slurp_line_table(abfd, asect)
} }
asect->lineno = lineno_cache; asect->lineno = lineno_cache;
/* FIXME, free native_lineno here, or use alloca or something. */
return true; return true;
} /* coff_slurp_line_table() */ } /* coff_slurp_line_table() */
@ -1942,7 +1855,6 @@ find_next_file_symbol(current, end)
SYMENT *current; SYMENT *current;
SYMENT *end; SYMENT *end;
{ {
unsigned int next = current->n_value;
current += current->n_numaux + 1; current += current->n_numaux + 1;
while (current < end) { while (current < end) {
@ -2019,7 +1931,7 @@ coff_slurp_symbol_table(abfd)
if (table_ptr == NULL) { if (table_ptr == NULL) {
bfd_error = no_memory; bfd_error = no_memory;
return false; return false;
} { /* on error */ } else {
coff_symbol_type *dst = cached_area; coff_symbol_type *dst = cached_area;
unsigned int last_native_index = bfd_get_symcount(abfd); unsigned int last_native_index = bfd_get_symcount(abfd);
unsigned int this_index = 0; unsigned int this_index = 0;
@ -2148,9 +2060,6 @@ coff_slurp_symbol_table(abfd)
break; break;
} }
BFD_ASSERT(dst->symbol.flags != 0); BFD_ASSERT(dst->symbol.flags != 0);
dst->native = src; dst->native = src;
@ -2161,7 +2070,6 @@ coff_slurp_symbol_table(abfd)
dst++; dst++;
number_of_symbols++; number_of_symbols++;
} /* walk the native symtab */ } /* walk the native symtab */
} /* bfdize the native symtab */ } /* bfdize the native symtab */
obj_symbols(abfd) = cached_area; obj_symbols(abfd) = cached_area;
@ -2306,7 +2214,6 @@ coff_slurp_reloc_table(abfd, asect, symbols)
} }
asect->relocation = reloc_cache; asect->relocation = reloc_cache;
return true; return true;
} }
@ -2337,9 +2244,6 @@ coff_canonicalize_reloc(abfd, section, relptr, symbols)
} }
/* /*
provided a bfd, a section and an offset into the section, calculate and provided a bfd, a section and an offset into the section, calculate and
return the name of the source file and the line nearest to the wanted return the name of the source file and the line nearest to the wanted
@ -2387,7 +2291,6 @@ DEFUN(coff_find_nearest_line,(abfd,
if (cof == (struct icofdata *)NULL) if (cof == (struct icofdata *)NULL)
return false; return false;
p = cof->raw_syments; p = cof->raw_syments;
/* /*
I don't know for sure what's right, but this isn't it. First off, an I don't know for sure what's right, but this isn't it. First off, an
@ -2406,8 +2309,6 @@ DEFUN(coff_find_nearest_line,(abfd,
return false; return false;
#endif #endif
for (i = 0; i < cof->raw_syment_count; i++) { for (i = 0; i < cof->raw_syment_count; i++) {
if (p->n_sclass == C_FILE) { if (p->n_sclass == C_FILE) {
/* File name is embeded in auxent */ /* File name is embeded in auxent */
@ -2424,10 +2325,6 @@ DEFUN(coff_find_nearest_line,(abfd,
p += 1 + p->n_numaux; p += 1 + p->n_numaux;
} }
/* Now wander though the raw linenumbers of the section */ /* Now wander though the raw linenumbers of the section */
/* /*
If this is the same bfd as we were previously called with and this is If this is the same bfd as we were previously called with and this is
the same section, and the offset we want is further down then we can the same section, and the offset we want is further down then we can

View File

@ -1,3 +1,5 @@
/* Intel 960 COFF support for BFD. */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Diddler. This file is part of BFD, the Binary File Diddler.
@ -19,6 +21,8 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id$ */ /* $Id$ */
#define I960 1 #define I960 1
#define BADMAG(x) I960BADMAG(x)
#include <ansidecl.h> #include <ansidecl.h>
#include "sysdep.h" #include "sysdep.h"
#include "bfd.h" #include "bfd.h"
@ -28,9 +32,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "libcoff.h" /* to allow easier abstraction-breaking */ #include "libcoff.h" /* to allow easier abstraction-breaking */
#define CALLS 0x66003800 /* Template for 'calls' instruction */ #define CALLS 0x66003800 /* Template for 'calls' instruction */
#define BAL 0x0b000000 /* Template for 'bal' instruction */ #define BAL 0x0b000000 /* Template for 'bal' instruction */
#define BAL_MASK 0x00ffffff #define BAL_MASK 0x00ffffff
@ -49,9 +50,8 @@ asection *ignore_input_section;
bfd_reloc_status_enum_type result; bfd_reloc_status_enum_type result;
coff_symbol_type *cs = coffsymbol(symbol_in); coff_symbol_type *cs = coffsymbol(symbol_in);
/* So the target symbol has to be off coff type, and the symbol /* So the target symbol has to be of coff type, and the symbol
has to have the correct native information within it has to have the correct native information within it */
*/
if ((cs->symbol.the_bfd->xvec->flavour != bfd_target_coff_flavour_enum) if ((cs->symbol.the_bfd->xvec->flavour != bfd_target_coff_flavour_enum)
|| (cs->native == (struct syment *)NULL)) { || (cs->native == (struct syment *)NULL)) {
/* This is interesting, consider the case where we're outputting */ /* This is interesting, consider the case where we're outputting */
@ -60,7 +60,6 @@ asection *ignore_input_section;
/* I complain ? - This will only work if the bout symbol is non */ /* I complain ? - This will only work if the bout symbol is non */
/* leaf. */ /* leaf. */
result = bfd_reloc_dangerous; result = bfd_reloc_dangerous;
} }
else { else {
switch (cs->native->n_sclass) switch (cs->native->n_sclass)
@ -139,9 +138,8 @@ static reloc_howto_type howto_table[] =
}; };
/* The real code is in coff-code.h */
#define BADMAG(x) I960BADMAG(x)
#include "coff-code.h" #include "coff-code.h"
bfd_target icoff_little_vec = bfd_target icoff_little_vec =
@ -166,6 +164,7 @@ bfd_target icoff_little_vec =
bfd_generic_archive_p, _bfd_dummy_target}, bfd_generic_archive_p, _bfd_dummy_target},
{bfd_false, coff_mkobject, /* bfd_set_format */ {bfd_false, coff_mkobject, /* bfd_set_format */
_bfd_generic_mkarchive, bfd_false}, _bfd_generic_mkarchive, bfd_false},
JUMP_TABLE(coff) JUMP_TABLE(coff)
}; };
@ -192,6 +191,7 @@ bfd_target icoff_big_vec =
{_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target}, {_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target},
{bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false}, {bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false},
JUMP_TABLE(coff) JUMP_TABLE(coff)
}; };

View File

@ -565,12 +565,12 @@ unsigned int size;
} }
static static
struct sec_struct *section_from_bfd_index(abfd, index) struct sec *section_from_bfd_index(abfd, index)
bfd *abfd; bfd *abfd;
int index; int index;
{ {
if (index > 0) { if (index > 0) {
struct sec_struct *answer = abfd->sections; struct sec *answer = abfd->sections;
while (--index) { while (--index) {
answer = answer->next; answer = answer->next;

View File

@ -65,9 +65,8 @@ struct sunexdata {
/* We case the address of the first element of a asymbol to ensure that the /* We take the address of the first element of an asymbol to ensure that the
* macro is only every applied to an asymbol * macro is only ever applied to an asymbol */
*/
#define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd)) #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
/*#define obj_symbols(bfd) ((((struct sunexdata *) ((bfd)->tdata))->symbols))*/ /*#define obj_symbols(bfd) ((((struct sunexdata *) ((bfd)->tdata))->symbols))*/
@ -75,6 +74,3 @@ struct sunexdata {
#define obj_arch_flags(bfd) ((((struct sunexdata *) (bfd)->tdata))->arch_flags) #define obj_arch_flags(bfd) ((((struct sunexdata *) (bfd)->tdata))->arch_flags)
#define get_tdata(x) ((struct sunexdata *)((x)->tdata)) #define get_tdata(x) ((struct sunexdata *)((x)->tdata))
#define set_tdata(x,y) ((x)->tdata = (PTR) (y))

View File

@ -56,12 +56,14 @@ bfd *ignore;
{ {
return (void *)NULL; return (void *)NULL;
} }
int int
bfd_0(ignore) bfd_0(ignore)
bfd *ignore; bfd *ignore;
{ {
return 0; return 0;
} }
unsigned int unsigned int
bfd_0u(ignore) bfd_0u(ignore)
bfd *ignore; bfd *ignore;

View File

@ -1,3 +1,6 @@
/* libbfd.h -- Declarations used by bfd library implementation.
This include file is not for users of the library */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Diddler. This file is part of BFD, the Binary File Diddler.
@ -18,20 +21,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id$ */ /* $Id$ */
/*** libbfd.h -- Declarations used by bfd library implementation.
This include file is not for users of the library */
/* If you want to read and write large blocks, you might want to do it /* If you want to read and write large blocks, you might want to do it
in quanta of this amount */ in quanta of this amount */
#define DEFAULT_BUFFERSIZE 8192 #define DEFAULT_BUFFERSIZE 8192
/* tdata for an archive. For an input archive cache /* Set a tdata field. Can't use the other macros for this, since they
needs to be free()'d. For an output archive, symdefs do. do casts, and casting to the left of assignment isn't portable. */
*/ #define set_tdata(bfd, v) ((bfd)->tdata = (PTR) (v))
/* tdata for an archive. For an input archive, cache
needs to be free()'d. For an output archive, symdefs do. */
struct artdata { struct artdata {
file_ptr first_file_filepos; file_ptr first_file_filepos;
@ -44,7 +43,6 @@ struct artdata {
}; };
#define bfd_ardata(bfd) ((struct artdata *) ((bfd)->tdata)) #define bfd_ardata(bfd) ((struct artdata *) ((bfd)->tdata))
#define bfd_set_ardata(bfd, v) ((bfd)->tdata = (PTR) (v))
/* Goes in bfd's arelt_data slot */ /* Goes in bfd's arelt_data slot */
struct areltdata { struct areltdata {
@ -59,13 +57,19 @@ struct areltdata {
This can't always work, because of alignment restrictions. We should change This can't always work, because of alignment restrictions. We should change
it before it becomes a problem -- Gumby */ it before it becomes a problem -- Gumby */
PROTO (char *, zalloc, (size_t size)); PROTO (char *, zalloc, (bfd_size_type size));
/* These routines allocate and free things on the BFD's obstack. Note
that realloc can never occur in place. */
PROTO(PTR, bfd_alloc, (bfd *abfd, bfd_size_type size));
PROTO(PTR, bfd_zalloc,(bfd *abfd, bfd_size_type size));
PROTO(PTR, bfd_realloc,(bfd *abfd, PTR orig, bfd_size_type new));
#define bfd_release(x,y) (void) obstack_free(&(x->memory),y)
PROTO (bfd_target *, bfd_find_target, (CONST char *target_name)); PROTO (bfd_target *, bfd_find_target, (CONST char *target_name));
PROTO (size_t, bfd_read, (PTR ptr, size_t size, size_t nitems, bfd *abfd)); PROTO (bfd_size_type, bfd_read, (PTR ptr, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
PROTO (size_t, bfd_write, (PTR ptr, size_t size, size_t nitems, bfd *abfd)); PROTO (bfd_size_type, bfd_write, (PTR ptr, bfd_size_type size, bfd_size_type nitems, bfd *abfd));
PROTO (FILE *, bfd_cache_lookup, (bfd *)); PROTO (FILE *, bfd_cache_lookup, (bfd *));
PROTO (void, bfd_cache_close, (bfd *)); PROTO (void, bfd_cache_close, (bfd *));
@ -103,7 +107,6 @@ PROTO (int, bfd_0, (bfd *ignore));
PROTO (unsigned int, bfd_0u, (bfd *ignore)); PROTO (unsigned int, bfd_0u, (bfd *ignore));
PROTO (void, bfd_void, (bfd *ignore)); PROTO (void, bfd_void, (bfd *ignore));
PROTO (bfd *,new_bfd_contained_in,(bfd *)); PROTO (bfd *,new_bfd_contained_in,(bfd *));
PROTO (boolean, _bfd_dummy_new_section_hook, (bfd *ignore, asection *newsect)); PROTO (boolean, _bfd_dummy_new_section_hook, (bfd *ignore, asection *newsect));
PROTO (char *, _bfd_dummy_core_file_failing_command, (bfd *abfd)); PROTO (char *, _bfd_dummy_core_file_failing_command, (bfd *abfd));
@ -125,6 +128,7 @@ PROTO (boolean, coff_write_armap, (bfd *arch, unsigned int elength,
PROTO ( bfd *,bfd_generic_openr_next_archived_file, (bfd *archive, bfd *last_file)); PROTO ( bfd *,bfd_generic_openr_next_archived_file, (bfd *archive, bfd *last_file));
PROTO(int, bfd_generic_stat_arch_elt, (bfd *, struct stat *)); PROTO(int, bfd_generic_stat_arch_elt, (bfd *, struct stat *));
/* Macros to tell if bfds are read or write enabled. /* Macros to tell if bfds are read or write enabled.
Note that bfds open for read may be scribbled into if the fd passed Note that bfds open for read may be scribbled into if the fd passed

View File

@ -59,6 +59,12 @@ typedef struct icofdata
long int relocbase; long int relocbase;
} coff_data_type; } coff_data_type;
/* We cast the address of the first element of a asymbol to ensure that the /* We take the address of the first element of a asymbol to ensure that the
* macro is only ever applied to an asymbol. */ * macro is only ever applied to an asymbol. */
#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd))) #define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
/* Generic COFF swapping routines -- also used by GDB. */
PROTO (void, bfd_coff_swap_sym, (bfd *, SYMENT *));
PROTO (void, bfd_coff_swap_aux, (bfd *, AUXENT *, int, int));
PROTO (void, bfd_coff_swap_lineno, (bfd *, LINENO *));

View File

@ -3,35 +3,34 @@ typedef struct {
char letter; char letter;
} ieee_symbol_index_type; } ieee_symbol_index_type;
typedef struct ieee_symbol_struct { typedef struct ieee_symbol {
asymbol symbol; asymbol symbol;
struct ieee_symbol_struct *next; struct ieee_symbol *next;
unsigned int index; unsigned int index;
} ieee_symbol_type; } ieee_symbol_type;
typedef struct ieee_reloc_struct { typedef struct ieee_reloc {
arelent relent; arelent relent;
struct ieee_reloc_struct *next; struct ieee_reloc *next;
ieee_symbol_index_type symbol; ieee_symbol_index_type symbol;
} ieee_reloc_type; } ieee_reloc_type;
#define ieee_symbol(x) ((ieee_symbol_type *)(x)) #define ieee_symbol(x) ((ieee_symbol_type *)(x))
typedef struct ieee_per_section_struct typedef struct ieee_per_section
{ {
asection *section; asection *section;
bfd_byte *data; bfd_byte *data;
bfd_vma offset; bfd_vma offset;
struct obstack reloc_obstack;
ieee_reloc_type **reloc_tail_ptr;
bfd_vma pc; bfd_vma pc;
/* For output */ /* For output */
file_ptr current_pos; file_ptr current_pos;
unsigned int current_byte; unsigned int current_byte;
boolean initialized; boolean initialized;
ieee_reloc_type **reloc_tail_ptr;
} ieee_per_section_type; } ieee_per_section_type;
#define ieee_per_section(x) ((ieee_per_section_type *)((x)->used_by_bfd)) #define ieee_per_section(x) ((ieee_per_section_type *)((x)->used_by_bfd))
@ -42,6 +41,8 @@ bfd_vma pc;
typedef struct { typedef struct {
boolean read_symbols; boolean read_symbols;
boolean read_data; boolean read_data;
unsigned char *input_p;
unsigned char *first_byte;
file_ptr output_cursor; file_ptr output_cursor;
/* Map of section indexes to section ptrs */ /* Map of section indexes to section ptrs */
asection * section_table[NSECTIONS]; asection * section_table[NSECTIONS];
@ -50,6 +51,8 @@ boolean read_data;
ieee_w_variable_type w; ieee_w_variable_type w;
unsigned int section_count; unsigned int section_count;
struct obstack ieee_obstack;
unsigned int map_idx; unsigned int map_idx;
/* List of GLOBAL EXPORT symbols */ /* List of GLOBAL EXPORT symbols */
@ -85,6 +88,7 @@ typedef struct {
unsigned int element_count; unsigned int element_count;
} ieee_ar_data_type; } ieee_ar_data_type;
#define ieee_data(abfd) ((ieee_data_type *)((abfd)->tdata)) #define ieee_data(abfd) ((ieee_data_type *)((abfd)->tdata))
#define ieee_ar_data(abfd) ((ieee_ar_data_type *)((abfd)->tdata)) #define ieee_ar_data(abfd) ((ieee_ar_data_type *)((abfd)->arelt_data))
#define ptr(abfd) (ieee_data(abfd)->input_p)

View File

@ -5,9 +5,9 @@ typedef struct
asymbol symbol; asymbol symbol;
} oasys_symbol_type; } oasys_symbol_type;
typedef struct oasys_reloc_struct { typedef struct oasys_reloc {
arelent relent; arelent relent;
struct oasys_reloc_struct *next; struct oasys_reloc *next;
unsigned int symbol; unsigned int symbol;
} oasys_reloc_type; } oasys_reloc_type;
@ -15,7 +15,7 @@ typedef struct oasys_reloc_struct {
#define oasys_symbol(x) ((oasys_symbol_type *)(x)) #define oasys_symbol(x) ((oasys_symbol_type *)(x))
#define oasys_per_section(x) ((oasys_per_section_type *)(x->used_by_bfd)) #define oasys_per_section(x) ((oasys_per_section_type *)(x->used_by_bfd))
typedef struct oasys_per_section_struct typedef struct oasys_per_section
{ {
asection *section; asection *section;
bfd_byte *data; bfd_byte *data;

View File

@ -1,3 +1,5 @@
/* opncls.c -- open and close a bfd. */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Diddler. This file is part of BFD, the Binary File Diddler.
@ -18,14 +20,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id$ */ /* $Id$ */
/*** opncls.c -- open and close a bfd. */
#include "sysdep.h" #include "sysdep.h"
#include "bfd.h" #include "bfd.h"
#include "libbfd.h" #include "libbfd.h"
extern void bfd_cache_init(); extern void bfd_cache_init();
FILE *bfd_open_file(); FILE *bfd_open_file();
@ -52,11 +50,12 @@ FILE *bfd_open_file();
Perhaps, since unix has so many different kinds of locking anyway, Perhaps, since unix has so many different kinds of locking anyway,
we should use the emacs lock scheme?... */ we should use the emacs lock scheme?... */
#define obstack_chunk_alloc malloc #define obstack_chunk_alloc malloc
#define obstack_chunk_free free #define obstack_chunk_free free
/* Return a new BFD. All BFD's are allocated through this routine. */
bfd *new_bfd() bfd *new_bfd()
{ {
struct obstack tmp; struct obstack tmp;
@ -64,6 +63,8 @@ bfd *new_bfd()
obstack_begin(&tmp,128); obstack_begin(&tmp,128);
nbfd = (bfd *)obstack_alloc(&tmp,sizeof(bfd)); nbfd = (bfd *)obstack_alloc(&tmp,sizeof(bfd));
memset((PTR)nbfd, 0, sizeof (bfd)); /* Clear it */
nbfd->memory = tmp; nbfd->memory = tmp;
nbfd->direction = no_direction; nbfd->direction = no_direction;
@ -80,8 +81,12 @@ bfd *new_bfd()
nbfd->sections = (asection *)NULL; nbfd->sections = (asection *)NULL;
nbfd->cacheable = false; nbfd->cacheable = false;
nbfd->flags = NO_FLAGS; nbfd->flags = NO_FLAGS;
nbfd->mtime_set = 0;
return nbfd; return nbfd;
} }
/* Allocate a new BFD as a member of archive OBFD. */
bfd *new_bfd_contained_in(obfd) bfd *new_bfd_contained_in(obfd)
bfd *obfd; bfd *obfd;
{ {
@ -179,7 +184,7 @@ DEFUN(bfd_fdopenr,(filename, target, fd),
/* if the fd were open for read only, this still would not hurt: */ /* if the fd were open for read only, this still would not hurt: */
nbfd->iostream = (char *) fdopen (fd, "r+"); nbfd->iostream = (char *) fdopen (fd, "r+");
if (nbfd->iostream == NULL) { if (nbfd->iostream == NULL) {
free (nbfd); (void) obstack_free (&nbfd->memory, (PTR)0);
return NULL; return NULL;
} }
@ -240,7 +245,7 @@ DEFUN(bfd_openw,(filename, target),
if (bfd_open_file (nbfd) == NULL) { if (bfd_open_file (nbfd) == NULL) {
bfd_error = system_call_error; /* File not writeable, etc */ bfd_error = system_call_error; /* File not writeable, etc */
free (nbfd); (void) obstack_free (&nbfd->memory, (PTR)0);
return NULL; return NULL;
} }
return nbfd; return nbfd;
@ -264,12 +269,12 @@ bfd_close (abfd)
stat(abfd->filename, &buf); stat(abfd->filename, &buf);
chmod(abfd->filename,buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH); chmod(abfd->filename,buf.st_mode | S_IXUSR | S_IXGRP | S_IXOTH);
} }
obstack_free(&abfd->memory, (PTR)0); (void) obstack_free (&abfd->memory, (PTR)0);
return true; return true;
} }
/*
called to create a bfd with no ascociated file or target /* Create a bfd with no associated file or target. */
*/
bfd * bfd *
DEFUN(bfd_create,(filename, template), DEFUN(bfd_create,(filename, template),
CONST char *filename AND CONST char *filename AND
@ -287,40 +292,39 @@ DEFUN(bfd_create,(filename, template),
nbfd->direction = no_direction; nbfd->direction = no_direction;
bfd_set_format(nbfd, bfd_object); bfd_set_format(nbfd, bfd_object);
return nbfd; return nbfd;
} }
/* Memory allocation */
DEFUN(PTR bfd_alloc, (abfd, size), DEFUN(PTR bfd_alloc, (abfd, size),
bfd *abfd AND bfd *abfd AND
size_t size) bfd_size_type size)
{ {
PTR res = obstack_alloc(&(abfd->memory),size); PTR res = obstack_alloc(&(abfd->memory), (int)size);
return res; return res;
} }
DEFUN(PTR bfd_zalloc,(abfd, size), DEFUN(PTR bfd_zalloc,(abfd, size),
bfd *abfd AND bfd *abfd AND
size_t size) bfd_size_type size)
{ {
PTR res = bfd_alloc(abfd, size); PTR res = bfd_alloc(abfd, size);
memset(res, 0, size); memset(res, 0, (size_t)size);
return res; return res;
} }
DEFUN(PTR bfd_realloc,(abfd, old, size), DEFUN(PTR bfd_realloc,(abfd, old, size),
bfd *abfd AND bfd *abfd AND
PTR old AND PTR old AND
size_t size) bfd_size_type size)
{ {
PTR res = bfd_alloc(abfd, size); PTR res = bfd_alloc(abfd, size);
memcpy(res, old, size); memcpy(res, old, (size_t)size);
return res; return res;
} }
DEFUN(size_t bfd_alloc_size,(abfd), DEFUN(bfd_size_type bfd_alloc_size,(abfd),
bfd *abfd) bfd *abfd)
{ {
struct _obstack_chunk *chunk = abfd->memory.chunk; struct _obstack_chunk *chunk = abfd->memory.chunk;

View File

@ -1,4 +1,5 @@
/*** bfd backend for sunos binaries */ /*** bfd backend for sunos binaries */
/** a.out files */
/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
@ -18,37 +19,23 @@ You should have received a copy of the GNU General Public License
along with BFD; see the file COPYING. If not, write to along with BFD; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* $Id$ /* $Id$ */
*
*/
#define TARGET_BYTE_ORDER_BIG_P 1
#include <ansidecl.h> #include <ansidecl.h>
#include "sysdep.h" #include "sysdep.h"
#include "bfd.h" #include "bfd.h"
#include "libbfd.h" #include "libbfd.h"
#include "a.out.sun4.h"
void (*bfd_error_trap)();
/*SUPPRESS558*/
/*SUPPRESS529*/
/* These values are correct for the SPARC. I dunno about anything else */
#define PAGE_SIZE 0x02000
#define SEGMENT_SIZE PAGE_SIZE
#define TEXT_START_ADDR PAGE_SIZE
#include "a.out.gnu.h" #include "a.out.gnu.h"
#include "stab.gnu.h" #include "stab.gnu.h"
#include "ar.h" #include "ar.h"
#include "liba.out.h" /* BFD a.out internal data structures */ #include "liba.out.h" /* BFD a.out internal data structures */
#include "a.out.sun4.h" void (*bfd_error_trap)();
/*SUPPRESS558*/
/*SUPPRESS529*/
#define CTOR_TABLE_RELOC_IDX 2 #define CTOR_TABLE_RELOC_IDX 2
static reloc_howto_type howto_table_ext[] = static reloc_howto_type howto_table_ext[] =
@ -85,7 +72,7 @@ static reloc_howto_type howto_table_ext[] =
/* Convert standard reloc records to "arelent" format (incl byte swap). */ /* Convert standard reloc records to "arelent" format (incl byte swap). */
static reloc_howto_type howto_table_std[] = { static reloc_howto_type howto_table_std[] = {
/* type rs size bsz pcrel bitpos abs ovrf sf name*/ /* type rs size bsz pcrel bitpos abs ovrf sf name part_inpl readmask setmask pcdone */
HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false), HOWTO( 0, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false), HOWTO( 1, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false), HOWTO( 2, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
@ -98,8 +85,6 @@ HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedfac
bfd_error_vector_type bfd_error_vector; bfd_error_vector_type bfd_error_vector;
/** a.out files */
PROTO (void , sunos4_write_syms, ()); PROTO (void , sunos4_write_syms, ());
PROTO (static boolean,sunos4_squirt_out_relocs,(bfd *abfd, asection *section)); PROTO (static boolean,sunos4_squirt_out_relocs,(bfd *abfd, asection *section));
@ -156,45 +141,6 @@ DEFUN(bfd_aout_swap_exec_header_out,(abfd, execp, raw_bytes),
bfd_h_putlong (abfd, execp->a_drsize, bytes->a_drsize); bfd_h_putlong (abfd, execp->a_drsize, bytes->a_drsize);
} }
/* Steve wants some way to frob this stuff from Saber while he's debugging
ld, so we have these funny shadow functions */
/* ZMAGIC's start at 0 (making the exec part of the text section),
other formats start after the exec
*/
static unsigned int n_txtoff(ptr)
struct exec *ptr;
{return N_MAGIC(*ptr)== ZMAGIC ? 0: sizeof(struct exec);}
static unsigned int n_datoff(ptr)
struct exec *ptr;
{return n_txtoff(ptr) + ptr->a_text;}
static unsigned int n_treloff(ptr)
struct exec *ptr;
{return n_datoff(ptr) + ptr->a_data;}
static unsigned int n_dreloff(ptr)
struct exec *ptr;
{return n_treloff(ptr) + ptr->a_trsize;}
static unsigned int n_symoff(ptr)
struct exec *ptr;
{return n_dreloff(ptr) + ptr->a_drsize;}
static unsigned int n_stroff(ptr)
struct exec *ptr;
{return n_symoff(ptr) + ptr->a_syms;}
static
unsigned int n_badmag(ptr)
struct exec *ptr;
{
switch (N_MAGIC(*ptr)) {
case OMAGIC: case NMAGIC: case ZMAGIC: return 0;
default: return 1;
}
}
bfd_target * bfd_target *
sunos4_object_p (abfd) sunos4_object_p (abfd)
bfd *abfd; bfd *abfd;
@ -212,9 +158,7 @@ sunos4_object_p (abfd)
return 0; return 0;
magic = bfd_h_getlong (abfd, magicbuf); magic = bfd_h_getlong (abfd, magicbuf);
/* Baroque syntax to mask deficiencies of the Sun compiler */ if (N_BADMAG (*((struct exec *) &magic))) return 0;
/* if (N_BADMAG (*((struct exec *) &magic))) return 0; */
if (n_badmag ((struct exec *) &magic)) return 0;
if (bfd_seek (abfd, 0L, false) < 0) return 0; if (bfd_seek (abfd, 0L, false) < 0) return 0;
@ -288,9 +232,11 @@ sunos4_object_p (abfd)
bfd_get_start_address (abfd) = execp->a_entry; bfd_get_start_address (abfd) = execp->a_entry;
bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct nlist);
/* Remember the positions of the string table and symbol table. */ /* Remember the positions of the string table and symbol table. */
obj_str_filepos (abfd) = n_stroff (execp); obj_str_filepos (abfd) = N_STROFF (*execp);
obj_sym_filepos (abfd) = n_symoff (execp); obj_sym_filepos (abfd) = N_SYMOFF (*execp);
/* create the sections. This is raunchy, but bfd_close wants to reclaim /* create the sections. This is raunchy, but bfd_close wants to reclaim
them */ them */
@ -346,7 +292,7 @@ sunos4_mkobject (abfd)
return false; return false;
} }
abfd->tdata = (PTR)((struct sunexdata *) rawptr); set_tdata (abfd, (struct sunexdata *) rawptr);
exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata)); exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata));
/* For simplicity's sake we just make all the sections right here. */ /* For simplicity's sake we just make all the sections right here. */
@ -459,6 +405,8 @@ sunos4_write_object_contents (abfd)
N_SET_MAGIC (*execp, OMAGIC); N_SET_MAGIC (*execp, OMAGIC);
if (abfd->flags & D_PAGED) { if (abfd->flags & D_PAGED) {
/* This is not strictly true, but will probably do for the default
case. FIXME. */
execp->a_text = obj_textsec (abfd)->size + sizeof(struct exec); execp->a_text = obj_textsec (abfd)->size + sizeof(struct exec);
N_SET_MAGIC (*execp, ZMAGIC); N_SET_MAGIC (*execp, ZMAGIC);
} else if (abfd->flags & WP_TEXT) { } else if (abfd->flags & WP_TEXT) {
@ -515,9 +463,8 @@ sunos4_write_object_contents (abfd)
} }
return true; return true;
} }
/** core files */ /* core files */
/** core files */
#define CORE_MAGIC 0x080456 #define CORE_MAGIC 0x080456
#define CORE_NAMELEN 16 #define CORE_NAMELEN 16
@ -640,7 +587,7 @@ sunos4_core_file_p (abfd)
if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) { if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) {
bfd_error = system_call_error; bfd_error = system_call_error;
free ((PTR)rawptr); bfd_release (abfd, rawptr);
return 0; return 0;
} }
@ -654,24 +601,24 @@ sunos4_core_file_p (abfd)
if (core_stacksec (abfd) == NULL) { if (core_stacksec (abfd) == NULL) {
loser: loser:
bfd_error = no_memory; bfd_error = no_memory;
free ((PTR)rawptr); bfd_release (abfd, rawptr);
return 0; return 0;
} }
core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_datasec (abfd) == NULL) { if (core_datasec (abfd) == NULL) {
loser1: loser1:
free ((PTR)core_stacksec (abfd)); bfd_release (abfd, core_stacksec (abfd));
goto loser; goto loser;
} }
core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_regsec (abfd) == NULL) { if (core_regsec (abfd) == NULL) {
loser2: loser2:
free ((PTR)core_datasec (abfd)); bfd_release (abfd, core_datasec (abfd));
goto loser1; goto loser1;
} }
core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
if (core_reg2sec (abfd) == NULL) { if (core_reg2sec (abfd) == NULL) {
free ((PTR)core_regsec (abfd)); bfd_release (abfd, core_regsec (abfd));
goto loser2; goto loser2;
} }
@ -809,31 +756,15 @@ sunos4_set_section_contents (abfd, section, location, offset, count)
{ {
if (abfd->output_has_begun == false) if (abfd->output_has_begun == false)
{ /* set by bfd.c handler */ { /* set by bfd.c handler */
if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL))
/*||
(obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size=
0)*/
)
{ {
bfd_error = invalid_operation; bfd_error = invalid_operation;
return false; return false;
} }
#if 0
if (abfd->flags & D_PAGED)
{
obj_textsec (abfd)->filepos = sizeof(struct exec); obj_textsec (abfd)->filepos = sizeof(struct exec);
obj_datasec(abfd)->filepos = obj_textsec (abfd)->size; obj_datasec(abfd)->filepos = obj_textsec (abfd)->filepos
} + obj_textsec (abfd)->size;
else
#endif
{
obj_textsec (abfd)->filepos = sizeof(struct exec);
obj_datasec(abfd)->filepos = obj_textsec(abfd)->filepos + obj_textsec (abfd)->size;
}
} }
/* regardless, once we know what we're doing, we might as well get going */ /* regardless, once we know what we're doing, we might as well get going */
if (section != obj_bsssec(abfd)) { if (section != obj_bsssec(abfd)) {
@ -847,6 +778,7 @@ sunos4_set_section_contents (abfd, section, location, offset, count)
} }
return true; return true;
} }
boolean boolean
sunos4_get_section_contents (abfd, section, location, offset, count) sunos4_get_section_contents (abfd, section, location, offset, count)
bfd *abfd; bfd *abfd;
@ -944,14 +876,12 @@ translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd)
} }
cache_ptr->symbol.section = reloc->relent.section; cache_ptr->symbol.section = reloc->relent.section;
reloc->relent.addend = cache_ptr->symbol.value ; reloc->relent.addend = cache_ptr->symbol.value ;
/*
We modify the symbol to belong to a section depending upon the /* We modify the symbol to belong to a section depending upon the
name of the symbol - probably __CTOR__ or __DTOR__ but we don't name of the symbol - probably __CTOR__ or __DTOR__ but we don't
really care, and add to the size of the section to contain a really care, and add to the size of the section to contain a
pointer to the symbol. Build a reloc entry to relocate to this pointer to the symbol. Build a reloc entry to relocate to this
symbol attached to this section. symbol attached to this section. */
*/
section->flags = SEC_CONSTRUCTOR; section->flags = SEC_CONSTRUCTOR;
section->reloc_count++; section->reloc_count++;
@ -1050,7 +980,7 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
{ {
asymbol *cache_ptr = (asymbol *)cache_ptr_g; asymbol *cache_ptr = (asymbol *)cache_ptr_g;
/* FIXME check for wrigin bss */ /* FIXME check for writing bss */
if (bfd_get_section(cache_ptr)) { if (bfd_get_section(cache_ptr)) {
if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) { if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {
sym_pointer->n_type |= N_BSS; sym_pointer->n_type |= N_BSS;
@ -1062,9 +992,8 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
sym_pointer->n_type |= N_TEXT; sym_pointer->n_type |= N_TEXT;
} }
else { else {
bfd_error_vector.nonrepresentable_section(abfd,
bfd_error_vector.nonrepresentable_section(abfd, bfd_get_output_section(cache_ptr)->name); bfd_get_output_section(cache_ptr)->name);
} }
/* Turn the symbol from section relative to absolute again */ /* Turn the symbol from section relative to absolute again */
sym_pointer->n_value += sym_pointer->n_value +=
@ -1090,7 +1019,6 @@ translate_to_native_sym_flags (sym_pointer, cache_ptr_g, abfd)
if (cache_ptr->flags & BSF_DEBUGGING) { if (cache_ptr->flags & BSF_DEBUGGING) {
sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type; sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type;
} }
} }
/* Native-level interface to symbols. */ /* Native-level interface to symbols. */
@ -1114,9 +1042,9 @@ boolean
DEFUN(sunos4_slurp_symbol_table, (abfd), DEFUN(sunos4_slurp_symbol_table, (abfd),
bfd *abfd) bfd *abfd)
{ {
unsigned int symbol_count;
size_t symbol_size; size_t symbol_size;
size_t string_size; size_t string_size;
unsigned char string_chars[LONG_SIZE];
struct nlist *syms; struct nlist *syms;
char *strings; char *strings;
aout_symbol_type *cached; aout_symbol_type *cached;
@ -1130,20 +1058,22 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
} }
bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET); bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);
if (bfd_read ((PTR)&string_size, 4, 1, abfd) != 4) if (bfd_read ((PTR)string_chars, LONG_SIZE, 1, abfd) != LONG_SIZE)
return false; return false;
string_size = bfd_h_getlong (abfd, (unsigned char *)&string_size); string_size = bfd_h_getlong (abfd, string_chars);
symbol_count = symbol_size / sizeof (struct nlist);
strings = bfd_alloc(abfd, string_size + 1); strings = bfd_alloc(abfd, string_size + 1);
cached = (aout_symbol_type *) cached = (aout_symbol_type *)
bfd_zalloc(abfd, symbol_count * sizeof(aout_symbol_type)); bfd_zalloc(abfd, bfd_get_symcount (abfd) * sizeof(aout_symbol_type));
/* Alloc this last, so we can free it if obstack is in use. */
syms = (struct nlist *) bfd_alloc(abfd, symbol_size); syms = (struct nlist *) bfd_alloc(abfd, symbol_size);
bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);
if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) { if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) {
bailout: bailout:
if (syms) bfd_release (abfd, syms);
if (cached) bfd_release (abfd, cached);
if (strings)bfd_release (abfd, strings);
return false; return false;
} }
@ -1155,7 +1085,7 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
/* OK, now walk the new symtable, cacheing symbol properties */ /* OK, now walk the new symtable, cacheing symbol properties */
{ {
register struct nlist *sym_pointer; register struct nlist *sym_pointer;
register struct nlist *sym_end = syms + symbol_count; register struct nlist *sym_end = syms + bfd_get_symcount (abfd);
register aout_symbol_type *cache_ptr = cached; register aout_symbol_type *cache_ptr = cached;
/* run through the table and byte swap if needed */ /* run through the table and byte swap if needed */
@ -1170,7 +1100,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
bfd_h_get_x(abfd, &sym_pointer->n_other); bfd_h_get_x(abfd, &sym_pointer->n_other);
sym_pointer->n_type = (char) sym_pointer->n_type = (char)
bfd_h_get_x(abfd, &sym_pointer->n_type); bfd_h_get_x(abfd, &sym_pointer->n_type);
} }
/* Run through table and copy values */ /* Run through table and copy values */
@ -1193,7 +1122,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd),
} }
obj_aout_symbols (abfd) = cached; obj_aout_symbols (abfd) = cached;
bfd_get_symcount (abfd) = symbol_count;
bfd_release (abfd, (PTR)syms); bfd_release (abfd, (PTR)syms);
return true; return true;
@ -1258,7 +1186,7 @@ DEFUN(sunos4_write_syms,(abfd),
{ {
asymbol *g = *(generic++); asymbol *g = *(generic++);
if (g->name != (char *)NULL) if (g->name)
{ {
size_t length = strlen(g->name)+1; size_t length = strlen(g->name)+1;
bfd_write((PTR)g->name, 1, length, abfd); bfd_write((PTR)g->name, 1, length, abfd);
@ -1307,11 +1235,10 @@ sunos4_get_symtab (abfd, location)
/* Output standard relocation information to a file in target byte order. */ /* Output standard relocation information to a file in target byte order. */
void void
swap_std_reloc_out (abfd, p, natptr, count) swap_std_reloc_out (abfd, g, natptr)
bfd *abfd; bfd *abfd;
arelent **p; /* Generic relocation struct */ arelent *g; /* Generic relocation struct */
struct reloc_std_bytes *natptr; struct reloc_std_bytes *natptr;
unsigned int count;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
@ -1319,10 +1246,7 @@ swap_std_reloc_out (abfd, p, natptr, count)
int r_pcrel; int r_pcrel;
int r_baserel, r_jmptable, r_relative; int r_baserel, r_jmptable, r_relative;
unsigned int r_addend; unsigned int r_addend;
unsigned int idx;
for (idx = 0; idx < count; idx++, p++, natptr++)
{
arelent *g = *p;
bfd_h_putlong (abfd, g->address, natptr->r_address); bfd_h_putlong (abfd, g->address, natptr->r_address);
r_length = g->howto->size; /* Size as a power of two */ r_length = g->howto->size; /* Size as a power of two */
@ -1393,9 +1317,6 @@ swap_std_reloc_out (abfd, p, natptr, count)
| (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0)
| (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE);
} }
}
} }
@ -1403,20 +1324,15 @@ swap_std_reloc_out (abfd, p, natptr, count)
/* Output extended relocation information to a file in target byte order. */ /* Output extended relocation information to a file in target byte order. */
void void
swap_ext_reloc_out (abfd, p, natptr, count) swap_ext_reloc_out (abfd, g, natptr)
bfd *abfd; bfd *abfd;
arelent **p; /* Generic relocation struct */ arelent *g; /* Generic relocation struct */
register struct reloc_ext_bytes *natptr; register struct reloc_ext_bytes *natptr;
unsigned int count;
{ {
int r_index; int r_index;
int r_extern; int r_extern;
unsigned int r_type; unsigned int r_type;
unsigned int r_addend; unsigned int r_addend;
unsigned int idx;
for (idx = 0; idx < count; idx++, p++, natptr++) {
arelent *g = *p;
bfd_h_putlong (abfd, g->address, natptr->r_address); bfd_h_putlong (abfd, g->address, natptr->r_address);
@ -1480,7 +1396,7 @@ swap_ext_reloc_out (abfd, p, natptr, count)
bfd_h_putlong (abfd, r_addend, natptr->r_addend); bfd_h_putlong (abfd, r_addend, natptr->r_addend);
} }
}
#define MOVE_ADDRESS(ad) \ #define MOVE_ADDRESS(ad) \
if (r_extern) { \ if (r_extern) { \
cache_ptr->sym_ptr_ptr = symbols + r_index; \ cache_ptr->sym_ptr_ptr = symbols + r_index; \
@ -1506,9 +1422,13 @@ swap_ext_reloc_out (abfd, p, natptr, count)
break; \ break; \
case N_ABS: \ case N_ABS: \
case N_ABS | N_EXT: \ case N_ABS | N_EXT: \
cache_ptr->section = NULL; /* No section */ \
cache_ptr->addend = ad; /* FIXME, is this right? */ \
BFD_ASSERT(1); \ BFD_ASSERT(1); \
break; \ break; \
default: \ default: \
cache_ptr->section = NULL; /* No section */ \
cache_ptr->addend = ad; /* FIXME, is this right? */ \
BFD_ASSERT(1); \ BFD_ASSERT(1); \
break; \ break; \
} \ } \
@ -1547,7 +1467,6 @@ swap_ext_reloc_in (abfd, bytes, cache_ptr, symbols)
cache_ptr->howto = howto_table_ext + r_type; cache_ptr->howto = howto_table_ext + r_type;
MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend)); MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend));
} }
void void
@ -1563,6 +1482,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols)
int r_pcrel; int r_pcrel;
int r_baserel, r_jmptable, r_relative; int r_baserel, r_jmptable, r_relative;
struct sunexdata *su = (struct sunexdata *)(abfd->tdata); struct sunexdata *su = (struct sunexdata *)(abfd->tdata);
cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address); cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address);
/* now the fun stuff */ /* now the fun stuff */
@ -1636,15 +1556,26 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof
(arelent))); (arelent)));
if (!reloc_cache) {
nomem:
bfd_error = no_memory;
return false;
}
relocs = bfd_alloc (abfd, reloc_size); relocs = bfd_alloc (abfd, reloc_size);
if (!relocs) {
bfd_release (abfd, reloc_cache);
goto nomem;
}
if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) { if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {
bfd_release (abfd, relocs);
bfd_release (abfd, reloc_cache);
bfd_error = system_call_error; bfd_error = system_call_error;
return false; return false;
} }
if (each_size == RELOC_EXT_SIZE) if (each_size == RELOC_EXT_SIZE) {
{
register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs;
unsigned int counter = 0; unsigned int counter = 0;
arelent *cache_ptr = reloc_cache; arelent *cache_ptr = reloc_cache;
@ -1652,8 +1583,7 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
for (; counter < count; counter++, rptr++, cache_ptr++) { for (; counter < count; counter++, rptr++, cache_ptr++) {
swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols);
} }
} } else {
else {
register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs; register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs;
unsigned int counter = 0; unsigned int counter = 0;
arelent *cache_ptr = reloc_cache; arelent *cache_ptr = reloc_cache;
@ -1663,6 +1593,7 @@ sunos4_slurp_reloc_table (abfd, asect, symbols)
} }
} }
bfd_release (abfd,relocs); bfd_release (abfd,relocs);
asect->relocation = reloc_cache; asect->relocation = reloc_cache;
asect->reloc_count = count; asect->reloc_count = count;
@ -1679,7 +1610,7 @@ sunos4_squirt_out_relocs (abfd, section)
asection *section; asection *section;
{ {
arelent **generic; arelent **generic;
unsigned char *native; unsigned char *native, *natptr;
size_t each_size; size_t each_size;
unsigned int count = section->reloc_count; unsigned int count = section->reloc_count;
@ -1699,14 +1630,17 @@ sunos4_squirt_out_relocs (abfd, section)
if (each_size == RELOC_EXT_SIZE) if (each_size == RELOC_EXT_SIZE)
{ {
swap_ext_reloc_out (abfd, for (natptr = native;
generic, count != 0;
(struct reloc_ext_bytes *)native, --count, natptr += each_size, ++generic)
count); swap_ext_reloc_out (abfd, generic, (struct reloc_ext_bytes *)native);
} }
else else
{ {
swap_std_reloc_out(abfd, generic, native, count); for (natptr = native;
count != 0;
--count, natptr += each_size, ++generic)
swap_std_reloc_out(abfd, generic, (struct reloc_std_bytes *)native);
} }
if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) { if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {