diff options
author | John Gilmore <gnu@cygnus> | 1991-05-02 04:11:40 +0000 |
---|---|---|
committer | John Gilmore <gnu@cygnus> | 1991-05-02 04:11:40 +0000 |
commit | fc7233808a1d88db99a5181e1ee0f6865f8f5206 (patch) | |
tree | 2f0626920d2d237a52aae12eccd0d5b8dd54ec1c /bfd | |
parent | ff37ea550b842cdb18aca531e5e705c03d4eed72 (diff) | |
download | gdb-fc7233808a1d88db99a5181e1ee0f6865f8f5206.zip gdb-fc7233808a1d88db99a5181e1ee0f6865f8f5206.tar.gz gdb-fc7233808a1d88db99a5181e1ee0f6865f8f5206.tar.bz2 |
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.
Diffstat (limited to 'bfd')
-rwxr-xr-x | bfd/aout.c | 478 | ||||
-rw-r--r-- | bfd/archive.c | 82 | ||||
-rw-r--r-- | bfd/archures.c | 55 | ||||
-rw-r--r-- | bfd/bfd.c | 71 | ||||
-rw-r--r-- | bfd/cache.c | 27 | ||||
-rwxr-xr-x | bfd/coff-code.h | 403 | ||||
-rw-r--r-- | bfd/coff-i960.c | 26 | ||||
-rw-r--r-- | bfd/coff-mips.c | 4 | ||||
-rw-r--r-- | bfd/libaout.h | 8 | ||||
-rw-r--r-- | bfd/libbfd.c | 2 | ||||
-rw-r--r-- | bfd/libbfd.h | 36 | ||||
-rw-r--r-- | bfd/libcoff.h | 8 | ||||
-rw-r--r-- | bfd/libieee.h | 34 | ||||
-rw-r--r-- | bfd/liboasys.h | 6 | ||||
-rw-r--r-- | bfd/opncls.c | 46 | ||||
-rw-r--r-- | bfd/sunos.c | 478 |
16 files changed, 759 insertions, 1005 deletions
@@ -1,4 +1,5 @@ /*** bfd backend for sunos binaries */ +/** a.out files */ /* 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 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id$ - * - */ - -#define TARGET_BYTE_ORDER_BIG_P 1 +/* $Id$ */ #include <ansidecl.h> #include "sysdep.h" #include "bfd.h" #include "libbfd.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.sun4.h" #include "a.out.gnu.h" #include "stab.gnu.h" #include "ar.h" #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 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). */ 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( 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), @@ -98,8 +85,6 @@ HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedfac bfd_error_vector_type bfd_error_vector; -/** a.out files */ - PROTO (void , sunos4_write_syms, ()); 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); } -/* 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 * sunos4_object_p (abfd) bfd *abfd; @@ -212,9 +158,7 @@ sunos4_object_p (abfd) return 0; 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; @@ -288,9 +232,11 @@ sunos4_object_p (abfd) 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. */ - obj_str_filepos (abfd) = n_stroff (execp); - obj_sym_filepos (abfd) = n_symoff (execp); + obj_str_filepos (abfd) = N_STROFF (*execp); + obj_sym_filepos (abfd) = N_SYMOFF (*execp); /* create the sections. This is raunchy, but bfd_close wants to reclaim them */ @@ -339,14 +285,14 @@ sunos4_mkobject (abfd) bfd_error = system_call_error; /* Use an intermediate variable for clarity */ - rawptr = bfd_zalloc (abfd,sizeof (struct sunexdata) + sizeof (struct exec)); + rawptr = bfd_zalloc (abfd, sizeof (struct sunexdata) + sizeof (struct exec)); if (rawptr == NULL) { bfd_error = no_memory; return false; } - abfd->tdata = (PTR)((struct sunexdata *) rawptr); + set_tdata (abfd, (struct sunexdata *) rawptr); exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata)); /* 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); 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); N_SET_MAGIC (*execp, ZMAGIC); } else if (abfd->flags & WP_TEXT) { @@ -515,9 +463,8 @@ sunos4_write_object_contents (abfd) } return true; } - -/** core files */ -/** core files */ + +/* core files */ #define CORE_MAGIC 0x080456 #define CORE_NAMELEN 16 @@ -640,7 +587,7 @@ sunos4_core_file_p (abfd) if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) { bfd_error = system_call_error; - free ((PTR)rawptr); + bfd_release (abfd, rawptr); return 0; } @@ -654,24 +601,24 @@ sunos4_core_file_p (abfd) if (core_stacksec (abfd) == NULL) { loser: bfd_error = no_memory; - free ((PTR)rawptr); + bfd_release (abfd, rawptr); return 0; } core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_datasec (abfd) == NULL) { loser1: - free ((PTR)core_stacksec (abfd)); + bfd_release (abfd, core_stacksec (abfd)); goto loser; } core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_regsec (abfd) == NULL) { loser2: - free ((PTR)core_datasec (abfd)); + bfd_release (abfd, core_datasec (abfd)); goto loser1; } core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_reg2sec (abfd) == NULL) { - free ((PTR)core_regsec (abfd)); + bfd_release (abfd, core_regsec (abfd)); goto loser2; } @@ -809,31 +756,15 @@ sunos4_set_section_contents (abfd, section, location, offset, count) { if (abfd->output_has_begun == false) { /* set by bfd.c handler */ - if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) - - /*|| - (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size= - 0)*/ - ) + if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL)) { bfd_error = invalid_operation; return false; } - -#if 0 - if (abfd->flags & D_PAGED) - { - obj_textsec (abfd)->filepos = sizeof(struct exec); - obj_datasec(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; - - } + 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 */ if (section != obj_bsssec(abfd)) { @@ -847,6 +778,7 @@ sunos4_set_section_contents (abfd, section, location, offset, count) } return true; } + boolean sunos4_get_section_contents (abfd, section, location, offset, count) bfd *abfd; @@ -944,14 +876,12 @@ translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd) } cache_ptr->symbol.section = reloc->relent.section; 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 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 - symbol attached to this section. - */ - + symbol attached to this section. */ section->flags = SEC_CONSTRUCTOR; 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; - /* FIXME check for wrigin bss */ + /* FIXME check for writing bss */ if (bfd_get_section(cache_ptr)) { if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) { 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; } else { - - bfd_error_vector.nonrepresentable_section(abfd, bfd_get_output_section(cache_ptr)->name); - + bfd_error_vector.nonrepresentable_section(abfd, + bfd_get_output_section(cache_ptr)->name); } /* Turn the symbol from section relative to absolute again */ 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) { sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type; } - } /* Native-level interface to symbols. */ @@ -1114,9 +1042,9 @@ boolean DEFUN(sunos4_slurp_symbol_table, (abfd), bfd *abfd) { - unsigned int symbol_count; size_t symbol_size; size_t string_size; + unsigned char string_chars[LONG_SIZE]; struct nlist *syms; char *strings; aout_symbol_type *cached; @@ -1130,20 +1058,22 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), } 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; - string_size = bfd_h_getlong (abfd, (unsigned char *)&string_size); - - symbol_count = symbol_size / sizeof (struct nlist); + string_size = bfd_h_getlong (abfd, string_chars); strings = bfd_alloc(abfd, string_size + 1); 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); bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) { bailout: + if (syms) bfd_release (abfd, syms); + if (cached) bfd_release (abfd, cached); + if (strings)bfd_release (abfd, strings); return false; } @@ -1155,7 +1085,7 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), /* OK, now walk the new symtable, cacheing symbol properties */ { 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; /* 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); sym_pointer->n_type = (char) bfd_h_get_x(abfd, &sym_pointer->n_type); - } /* Run through table and copy values */ @@ -1193,7 +1122,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), } obj_aout_symbols (abfd) = cached; - bfd_get_symcount (abfd) = symbol_count; bfd_release (abfd, (PTR)syms); return true; @@ -1258,7 +1186,7 @@ DEFUN(sunos4_write_syms,(abfd), { asymbol *g = *(generic++); - if (g->name != (char *)NULL) + if (g->name) { size_t length = strlen(g->name)+1; 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. */ void -swap_std_reloc_out (abfd, p, natptr, count) +swap_std_reloc_out (abfd, g, natptr) bfd *abfd; - arelent **p; /* Generic relocation struct */ + arelent *g; /* Generic relocation struct */ struct reloc_std_bytes *natptr; - unsigned int count; { int r_index; int r_extern; @@ -1319,83 +1246,77 @@ swap_std_reloc_out (abfd, p, natptr, count) int r_pcrel; int r_baserel, r_jmptable, r_relative; 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); - - r_length = g->howto->size; /* Size as a power of two */ - r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ - /* r_baserel, r_jmptable, r_relative??? FIXME-soon */ - r_baserel = 0; - r_jmptable = 0; - r_relative = 0; - r_addend = g->addend; /* Start here, see how it goes */ + bfd_h_putlong (abfd, g->address, natptr->r_address); - /* name was clobbered by sunos4_write_syms to be symbol index */ + r_length = g->howto->size; /* Size as a power of two */ + r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ + /* r_baserel, r_jmptable, r_relative??? FIXME-soon */ + r_baserel = 0; + r_jmptable = 0; + r_relative = 0; - if (g->sym_ptr_ptr != NULL) - { - if ((*(g->sym_ptr_ptr))->section) { - /* put the section offset into the addend for output */ - r_addend += (*(g->sym_ptr_ptr))->section->vma; - } + r_addend = g->addend; /* Start here, see how it goes */ - r_index = stoi((*(g->sym_ptr_ptr))->name); - r_extern = 1; - } - else { - r_extern = 0; - if (g->section == NULL) { - BFD_ASSERT(0); - r_index = N_ABS | N_EXT; - } - else if(g->section->output_section == obj_textsec(abfd)) { - r_index = N_TEXT | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_datasec(abfd)) { - r_index = N_DATA | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_bsssec(abfd)) { - r_index = N_BSS | N_EXT ; - r_addend += g->section->output_section->vma; - } - else { - BFD_ASSERT(0); - } - } + /* name was clobbered by sunos4_write_syms to be symbol index */ - /* now the fun stuff */ - if (abfd->xvec->header_byteorder_big_p != false) { - natptr->r_index[0] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[2] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0) - | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0) - | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0) - | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0) - | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0) - | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG); - } else { - natptr->r_index[2] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[0] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) - | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) - | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0) - | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0) - | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) - | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); + if (g->sym_ptr_ptr != NULL) + { + if ((*(g->sym_ptr_ptr))->section) { + /* put the section offset into the addend for output */ + r_addend += (*(g->sym_ptr_ptr))->section->vma; } - + r_index = stoi((*(g->sym_ptr_ptr))->name); + r_extern = 1; + } + else { + r_extern = 0; + if (g->section == NULL) { + BFD_ASSERT(0); + r_index = N_ABS | N_EXT; } + else if(g->section->output_section == obj_textsec(abfd)) { + r_index = N_TEXT | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_datasec(abfd)) { + r_index = N_DATA | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_bsssec(abfd)) { + r_index = N_BSS | N_EXT ; + r_addend += g->section->output_section->vma; + } + else { + BFD_ASSERT(0); + } + } + + /* now the fun stuff */ + if (abfd->xvec->header_byteorder_big_p != false) { + natptr->r_index[0] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[2] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0) + | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0) + | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0) + | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0) + | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0) + | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG); + } else { + natptr->r_index[2] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[0] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) + | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) + | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0) + | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0) + | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) + | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); + } } @@ -1403,84 +1324,79 @@ swap_std_reloc_out (abfd, p, natptr, count) /* Output extended relocation information to a file in target byte order. */ void -swap_ext_reloc_out (abfd, p, natptr, count) +swap_ext_reloc_out (abfd, g, natptr) bfd *abfd; - arelent **p; /* Generic relocation struct */ + arelent *g; /* Generic relocation struct */ register struct reloc_ext_bytes *natptr; - unsigned int count; { - int r_index; int r_extern; unsigned int r_type; 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); - /* Find a type in the output format which matches the input howto - - at the moment we assume input format == output format FIXME!! */ - r_type = (enum reloc_type) g->howto->type; + bfd_h_putlong (abfd, g->address, natptr->r_address); - r_addend = g->addend; /* Start here, see how it goes */ + /* Find a type in the output format which matches the input howto - + at the moment we assume input format == output format FIXME!! */ + r_type = (enum reloc_type) g->howto->type; - /* name was clobbered by sunos4_write_syms to be symbol index*/ + r_addend = g->addend; /* Start here, see how it goes */ - if (g->sym_ptr_ptr != NULL) - { - if ((*(g->sym_ptr_ptr))->section) { - /* put the section offset into the addend for output */ - r_addend += (*(g->sym_ptr_ptr))->section->vma; - } + /* name was clobbered by sunos4_write_syms to be symbol index*/ - r_index = stoi((*(g->sym_ptr_ptr))->name); - r_extern = 1; - } - else { - r_extern = 0; - if (g->section == NULL) { - BFD_ASSERT(0); - r_index = N_ABS | N_EXT; - } - else if(g->section->output_section == obj_textsec(abfd)) { - r_index = N_TEXT | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_datasec(abfd)) { - r_index = N_DATA | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_bsssec(abfd)) { - r_index = N_BSS | N_EXT ; - r_addend += g->section->output_section->vma; - } - else { - BFD_ASSERT(0); + if (g->sym_ptr_ptr != NULL) + { + if ((*(g->sym_ptr_ptr))->section) { + /* put the section offset into the addend for output */ + r_addend += (*(g->sym_ptr_ptr))->section->vma; } - } - /* now the fun stuff */ - if (abfd->xvec->header_byteorder_big_p != false) { - natptr->r_index[0] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[2] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) - || (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); - } else { - natptr->r_index[2] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[0] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0) - || (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE); + r_index = stoi((*(g->sym_ptr_ptr))->name); + r_extern = 1; + } + else { + r_extern = 0; + if (g->section == NULL) { + BFD_ASSERT(0); + r_index = N_ABS | N_EXT; } + else if(g->section->output_section == obj_textsec(abfd)) { + r_index = N_TEXT | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_datasec(abfd)) { + r_index = N_DATA | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_bsssec(abfd)) { + r_index = N_BSS | N_EXT ; + r_addend += g->section->output_section->vma; + } + else { + BFD_ASSERT(0); + } + } - bfd_h_putlong (abfd, r_addend, natptr->r_addend); + /* now the fun stuff */ + if (abfd->xvec->header_byteorder_big_p != false) { + natptr->r_index[0] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[2] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) + || (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); + } else { + natptr->r_index[2] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[0] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0) + || (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE); } + + bfd_h_putlong (abfd, r_addend, natptr->r_addend); } + #define MOVE_ADDRESS(ad) \ if (r_extern) { \ cache_ptr->sym_ptr_ptr = symbols + r_index; \ @@ -1506,9 +1422,13 @@ swap_ext_reloc_out (abfd, p, natptr, count) break; \ case N_ABS: \ case N_ABS | N_EXT: \ + cache_ptr->section = NULL; /* No section */ \ + cache_ptr->addend = ad; /* FIXME, is this right? */ \ BFD_ASSERT(1); \ break; \ default: \ + cache_ptr->section = NULL; /* No section */ \ + cache_ptr->addend = ad; /* FIXME, is this right? */ \ BFD_ASSERT(1); \ break; \ } \ @@ -1547,13 +1467,12 @@ swap_ext_reloc_in (abfd, bytes, cache_ptr, symbols) cache_ptr->howto = howto_table_ext + r_type; MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend)); - } void swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) bfd *abfd; - struct reloc_std_bytes *bytes; + struct reloc_std_bytes *bytes; arelent *cache_ptr; asymbol **symbols; { @@ -1563,6 +1482,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) int r_pcrel; int r_baserel, r_jmptable, r_relative; struct sunexdata *su = (struct sunexdata *)(abfd->tdata); + cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address); /* now the fun stuff */ @@ -1576,7 +1496,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) r_jmptable= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_JMPTABLE_BIG)); r_relative= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_RELATIVE_BIG)); r_length = (bytes->r_bits[0] & RELOC_STD_BITS_LENGTH_BIG) - >> RELOC_STD_BITS_LENGTH_SH_BIG; + >> RELOC_STD_BITS_LENGTH_SH_BIG; } else { r_index = (bytes->r_index[2] << 16) | (bytes->r_index[1] << 8) @@ -1587,7 +1507,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) r_jmptable= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); r_relative= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); r_length = (bytes->r_bits[0] & RELOC_STD_BITS_LENGTH_LITTLE) - >> RELOC_STD_BITS_LENGTH_SH_LITTLE; + >> RELOC_STD_BITS_LENGTH_SH_LITTLE; } cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel; @@ -1636,24 +1556,34 @@ sunos4_slurp_reloc_table (abfd, asect, symbols) reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof (arelent))); + if (!reloc_cache) { +nomem: + bfd_error = no_memory; + return false; + } + 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; return false; } - if (each_size == RELOC_EXT_SIZE) - { - register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; - unsigned int counter = 0; - arelent *cache_ptr = reloc_cache; + if (each_size == RELOC_EXT_SIZE) { + register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; + unsigned int counter = 0; + arelent *cache_ptr = reloc_cache; - for (; counter < count; counter++, rptr++, cache_ptr++) { - swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); - } + for (; counter < count; counter++, rptr++, cache_ptr++) { + swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); } - else { + } else { register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs; unsigned int counter = 0; arelent *cache_ptr = reloc_cache; @@ -1663,7 +1593,8 @@ sunos4_slurp_reloc_table (abfd, asect, symbols) } } -bfd_release (abfd,relocs); + + bfd_release (abfd,relocs); asect->relocation = reloc_cache; asect->reloc_count = count; return true; @@ -1679,7 +1610,7 @@ sunos4_squirt_out_relocs (abfd, section) asection *section; { arelent **generic; - unsigned char *native; + unsigned char *native, *natptr; size_t each_size; unsigned int count = section->reloc_count; @@ -1699,14 +1630,17 @@ sunos4_squirt_out_relocs (abfd, section) if (each_size == RELOC_EXT_SIZE) { - swap_ext_reloc_out (abfd, - generic, - (struct reloc_ext_bytes *)native, - count); + for (natptr = native; + count != 0; + --count, natptr += each_size, ++generic) + swap_ext_reloc_out (abfd, generic, (struct reloc_ext_bytes *)native); } 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) { @@ -1811,7 +1745,7 @@ bfd_print_symbol_enum_type how; break; case bfd_print_symbol_type_enum: fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff), - (unsigned)( aout_symbol(symbol)->other & 0xff), + (unsigned)(aout_symbol(symbol)->other & 0xff), (unsigned)(aout_symbol(symbol)->type)); break; case bfd_print_symbol_all_enum: @@ -1824,7 +1758,7 @@ bfd_print_symbol_enum_type how; fprintf(file," %-5s %04x %02x %02x %s", section_name, (unsigned)(aout_symbol(symbol)->desc & 0xffff), - (unsigned)(aout_symbol(symbol)->other & 0xff), + (unsigned)(aout_symbol(symbol)->other & 0xff), (unsigned)(aout_symbol(symbol)->type & 0xff), symbol->name); } diff --git a/bfd/archive.c b/bfd/archive.c index 1313540..4999469 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -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). */ -/* $Id$ - */ - +/* $Id$ */ #include "sysdep.h" #include "bfd.h" @@ -59,16 +57,14 @@ struct ar_cache { #define arch_hdr(bfd) ((struct ar_hdr *) \ (((struct areltdata *)((bfd)->arelt_data))->arch_header)) - - boolean _bfd_generic_mkarchive (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; return false; } @@ -79,7 +75,7 @@ _bfd_generic_mkarchive (abfd) symindex bfd_get_next_mapent (abfd, prev, entry) bfd *abfd; - symindex prev; + symindex prev; carsym **entry; { if (!bfd_has_map (abfd)) { @@ -88,7 +84,7 @@ bfd_get_next_mapent (abfd, prev, entry) } 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; *entry = (bfd_ardata (abfd)->symdefs + prev); @@ -115,7 +111,7 @@ boolean bfd_set_archive_head (output_archive, new_head) bfd *output_archive, *new_head; { - + output_archive->archive_head = new_head; return true; } @@ -140,7 +136,8 @@ add_bfd_to_cache (arch_bfd, filepos, new_elt) bfd *arch_bfd, *new_elt; 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) { bfd_error = no_memory; @@ -172,7 +169,6 @@ get_extended_arelt_filename (arch, name) bfd *arch; char *name; { - extern int errno; unsigned long index = 0; /* 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); if (n_nfd == NULL) { + bfd_release (archive, (PTR)new_areldata); return NULL; } n_nfd->origin = bfd_tell (archive); @@ -306,6 +303,8 @@ get_elt_at_filepos (archive, filepos) return n_nfd; /* huh? */ + bfd_release (archive, (PTR)n_nfd); + bfd_release (archive, (PTR)new_areldata); return NULL; } @@ -349,11 +348,10 @@ bfd *bfd_generic_openr_next_archived_file(archive, last_file) if (!last_file) filestart = bfd_ardata (archive)->first_file_filepos; else { - unsigned int size = arelt_size(last_file); - filestart = last_file->origin +size + size %2; -} - - + unsigned int size = arelt_size(last_file); + /* Pad to an even boundary... */ + filestart = last_file->origin + size + size%2; + } return get_elt_at_filepos (archive, filestart); } @@ -376,7 +374,9 @@ bfd_generic_archive_p (abfd) if (strncmp (armag, ARMAG, SARMAG)) return 0; #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) { bfd_error = no_memory; @@ -391,7 +391,6 @@ bfd_generic_archive_p (abfd) return 0; } - /* armap could be left ungc'd! FIXME -- potential storage leak */ if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd))) { bfd_release(abfd, bfd_ardata (abfd)); abfd->tdata = NULL; @@ -413,6 +412,9 @@ bfd_slurp_bsd_armap (abfd) struct artdata *ardata = bfd_ardata (abfd); 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) { /* The archive has at least 16 bytes in it */ bfd_seek (abfd, -16L, SEEK_CUR); @@ -431,22 +433,24 @@ bfd_slurp_bsd_armap (abfd) if (raw_armap == NULL) { bfd_error = no_memory; byebye: + bfd_release (abfd, (PTR)mapdata); return false; } if (bfd_read ((PTR)raw_armap, 1, mapdata->parsed_size, abfd) != mapdata->parsed_size) { bfd_error = malformed_archive; + bfd_release (abfd, (PTR)raw_armap); goto byebye; } - ardata->symdef_count = *(raw_armap) / sizeof (struct symdef); + ardata->symdef_count = *raw_armap / sizeof (struct symdef); ardata->cache = 0; rbase = raw_armap+1; ardata->symdefs = (carsym *) rbase; 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; sym->s.name = sym->s.string_offset + stringbase; } @@ -454,6 +458,9 @@ bfd_slurp_bsd_armap (abfd) ardata->first_file_filepos = bfd_tell (abfd); /* Pad to an even boundary if you have to */ 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; } return true; @@ -471,15 +478,12 @@ bfd_slurp_coff_armap (abfd) char *stringbase; unsigned int stringsize; carsym *carsyms; + int result; - if (bfd_read ((PTR)&nextname, 1, 1, abfd) != 1) { - bfd_seek (abfd, -1L, SEEK_CUR); - bfd_has_map(abfd) = false; - return true; - } + result = bfd_read ((PTR)&nextname, 1, 1, abfd); bfd_seek (abfd, -1L, SEEK_CUR); - if (nextname != '/') { + if (result != 1 || nextname != '/') { /* Actually I think this is an error for a COFF archive */ bfd_has_map (abfd) = false; return true; @@ -492,7 +496,7 @@ bfd_slurp_coff_armap (abfd) if (raw_armap == NULL) { bfd_error = no_memory; byebye: - + bfd_release (abfd, (PTR)mapdata); return false; } @@ -500,7 +504,7 @@ bfd_slurp_coff_armap (abfd) mapdata->parsed_size) { bfd_error = malformed_archive; oops: - + bfd_release (abfd, (PTR)raw_armap); goto byebye; } @@ -540,11 +544,11 @@ bfd_slurp_coff_armap (abfd) ardata->first_file_filepos = bfd_tell (abfd); /* Pad to an even boundary if you have to */ 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; return true; } - /** Extended name table. @@ -562,6 +566,8 @@ _bfd_slurp_extended_name_table (abfd) char nextname[17]; 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) { bfd_seek (abfd, -16L, SEEK_CUR); @@ -574,19 +580,18 @@ _bfd_slurp_extended_name_table (abfd) namedata = snarf_ar_hdr (abfd); if (namedata == NULL) return false; - bfd_ardata (abfd)->extended_names = bfd_zalloc(abfd,namedata->parsed_size); if (bfd_ardata (abfd)->extended_names == NULL) { bfd_error = no_memory; byebye: - + bfd_release (abfd, (PTR)namedata); return false; } if (bfd_read ((PTR)bfd_ardata (abfd)->extended_names, 1, namedata->parsed_size, abfd) != namedata->parsed_size) { bfd_error = malformed_archive; - + bfd_release (abfd, (PTR)(bfd_ardata (abfd)->extended_names)); bfd_ardata (abfd)->extended_names = NULL; goto byebye; } @@ -604,7 +609,9 @@ _bfd_slurp_extended_name_table (abfd) bfd_ardata (abfd)->first_file_filepos += (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; } @@ -791,7 +798,7 @@ bfd_dont_truncate_arname (abfd, pathname, arhdr) char *pathname; 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 is very hard; fortunately I know how to do it and will do so once 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 */ unsigned int i; - /* Verify the viability of all entries; if any of them live in the filesystem (as opposed to living in an archive open for input) then construct a fresh ar_hdr for them. @@ -996,8 +1002,6 @@ return true; /* Note that the namidx for the first symbol is 0 */ - - boolean compute_and_write_armap (arch, elength) bfd *arch; diff --git a/bfd/archures.c b/bfd/archures.c index 2e151ed..18d49de 100644 --- a/bfd/archures.c +++ b/bfd/archures.c @@ -55,8 +55,6 @@ struct arch_print { {bfd_arch_pyramid, "pyramid", 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}, - - }; /* Return a printable string representing the architecture and machine @@ -310,36 +308,33 @@ bfd_arch_compatible (abfd, bbfd, archp, machinep) /* If particular machine types of one architecture are not compatible with each other, this is the place to put those tests (returning false if incompatible). */ - case bfd_arch_i960: - /* The i960 has to distinct subspecies which may not interbreed: - CORE CA - CORE KA KB MC - Any architecture on the same line is compatible, the one on - the right is the least restrictive. - */ - /* So, if either is a ca then the other must be a be core or ca */ - if (macha == bfd_mach_i960_ca) { - if (machb != bfd_mach_i960_ca && - machb != bfd_mach_i960_core) { - return false; + + case bfd_arch_i960: + /* The i960 has two distinct subspecies which may not interbreed: + CORE CA + CORE KA KB MC + Any architecture on the same line is compatible, the one on + the right is the least restrictive. */ + /* So, if either is a ca then the other must be a be core or ca */ + if (macha == bfd_mach_i960_ca) { + if (machb != bfd_mach_i960_ca && + machb != bfd_mach_i960_core) { + return false; + } + pick_a = 1; } - pick_a = 1; - } - else if (machb == bfd_mach_i960_ca) { - if (macha != bfd_mach_i960_ca && - macha != bfd_mach_i960_core) { - return false; + else if (machb == bfd_mach_i960_ca) { + if (macha != bfd_mach_i960_ca && + macha != bfd_mach_i960_core) { + return false; + } + pick_a = 0; } - pick_a = 0; - } - else { - /* This must be from the bottom row, so take the higest */ - pick_a = (macha > machb); - } - - - - break; + else { + /* This must be from the bottom row, so take the higest */ + pick_a = (macha > machb); + } + break; /* For these chips, as far as we care, "lower" numbers are included by "higher" numbers, e.g. merge 68010 and 68020 into 68020, @@ -31,14 +31,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ short _bfd_host_big_endian = 0x0100; /* Accessing the above as (*(char*)&_bfd_host_big_endian), will - * return 1 if the host is big-endian, 0 otherwise. - * (See HOST_IS_BIG_ENDIAN_P in bfd.h.) - */ - - - + return 1 if the host is big-endian, 0 otherwise. + (assuming that a short is two bytes long!!! FIXME) + (See HOST_IS_BIG_ENDIAN_P in bfd.h.) */ - /** Error handling o - Most functions return nonzero on success (check doc for precise semantics); 0 or NULL on error. @@ -49,25 +45,24 @@ short _bfd_host_big_endian = 0x0100; bfd_ec bfd_error = no_error; -char *bfd_errmsgs[] = {"No error", - "System call error", - "Invalid target", - "File in wrong format", - "Invalid operation", - "Memory exhausted", - "No symbols", - "No relocation info", - "No more archived files", - "Malformed archive", - "Symbol not found", - "File format not recognized", - "File format is ambiguous", - "Section has no contents", - "Nonrepresentable section on output", - "#<Invalid error code>" +char *bfd_errmsgs[] = { "No error", + "System call error", + "Invalid target", + "File in wrong format", + "Invalid operation", + "Memory exhausted", + "No symbols", + "No relocation info", + "No more archived files", + "Malformed archive", + "Symbol not found", + "File format not recognized", + "File format is ambiguous", + "Section has no contents", + "Nonrepresentable section on output", + "#<Invalid error code>" }; - static void DEFUN(bfd_nonrepresentable_section,(abfd, name), @@ -80,6 +75,7 @@ DEFUN(bfd_nonrepresentable_section,(abfd, name), name); exit(1); } + bfd_error_vector_type bfd_error_vector = { bfd_nonrepresentable_section @@ -99,12 +95,10 @@ strerror (code) #endif /* not ANSI_LIBRARIES */ - char * bfd_errmsg (error_tag) bfd_ec error_tag; { - extern int errno; if (error_tag == system_call_error) return strerror (errno); @@ -125,12 +119,13 @@ bfd_ec error_tag; void (*bfd_error_trap)() = bfd_default_error_trap; void (*bfd_error_nonrepresentabltrap)() = bfd_default_error_trap; + void DEFUN(bfd_perror,(message), CONST char *message) { if (bfd_error == system_call_error) - perror(message); /* must be system error then... */ + perror((char *)message); /* must be system error then... */ else { if (message == NULL || *message == '\0') fprintf (stderr, "%s\n", bfd_errmsg (bfd_error)); @@ -228,9 +223,6 @@ bfd_check_format (abfd, format) bfd *abfd; bfd_format format; { -#if obsolete - file_ptr filepos; -#endif bfd_target **target, *save_targ, *right_targ; int match_count; @@ -246,11 +238,7 @@ bfd_check_format (abfd, format) /* presume the answer is yes */ abfd->format = format; -#if obsolete - filepos = bfd_tell (abfd); -#endif - bfd_seek (abfd, (file_ptr)0, SEEK_SET); /* instead, rewind! */ - + bfd_seek (abfd, (file_ptr)0, SEEK_SET); /* rewind! */ right_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); if (right_targ) { @@ -270,9 +258,6 @@ bfd_check_format (abfd, format) bfd_target *temp; 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); temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd)); if (temp) { /* This format checks out as ok! */ @@ -299,9 +284,6 @@ bfd_check_format (abfd, format) abfd->format = bfd_unknown; /* Restore original format */ bfd_error = ((match_count == 0) ? file_not_recognized : file_ambiguously_recognized); -#if obsolete - bfd_seek (abfd, filepos, SEEK_SET); /* Restore original file position */ -#endif return false; } @@ -311,7 +293,6 @@ bfd_set_format (abfd, format) bfd_format format; { - if (bfd_read_p (abfd) || ((int)abfd->format < (int)bfd_unknown) || ((int)abfd->format >= (int)bfd_type_end)) { @@ -324,11 +305,8 @@ bfd_set_format (abfd, format) /* presume the answer is yes */ abfd->format = format; -/* filepos = bfd_tell (abfd);*/ - if (!BFD_SEND_FMT (abfd, _bfd_set_format, (abfd))) { abfd->format = bfd_unknown; -/* bfd_seek (abfd, filepos, SEEK_SET);*/ return false; } @@ -381,7 +359,6 @@ DEFUN(bfd_make_section,(abfd, name), newsect->index = abfd->section_count++; newsect->flags = SEC_NO_FLAGS; - newsect->userdata = 0; newsect->next = (asection *)NULL; newsect->relocation = (arelent *)NULL; @@ -674,7 +651,7 @@ bfd *output_bfd; bfd_vma relocation_before; bfd_vma addr = reloc_entry->address ; 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_input_section; asymbol *symbol; diff --git a/bfd/cache.c b/bfd/cache.c index d1172fb..c3418ea 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -23,13 +23,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "bfd.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 */ #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 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 @@ -60,8 +57,8 @@ DEFUN_VOID(close_one) kill->where = ftell((FILE *)(kill->iostream)); bfd_cache_delete(kill); - } + /* Cuts the bfd abfd out of the chain in the cache */ static void DEFUN(snip,(abfd), @@ -135,12 +132,12 @@ DEFUN(bfd_open_file, (abfd), close_one(); } switch (abfd->direction) { - case read_direction: - case no_direction: + case read_direction: + case no_direction: abfd->iostream = (char *) fopen(abfd->filename, "r"); break; - case both_direction: - case write_direction: + case both_direction: + case write_direction: if (abfd->opened_once == true) { abfd->iostream = (char *) fopen(abfd->filename, "r+"); if (!abfd->iostream) { diff --git a/bfd/coff-code.h b/bfd/coff-code.h index bc07f79..c649285 100755 --- a/bfd/coff-code.h +++ b/bfd/coff-code.h @@ -1,5 +1,6 @@ -/* - Copyright (C) 1990, 1991 Free Software Foundation, Inc. +/* Support for Intel 960 COFF and Motorola 88k BCS COFF (and maybe others) */ + +/* Copyright (C) 1990, 1991 Free Software Foundation, Inc. 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$ */ -/* -Most of this hacked by Steve Chamberlain, steve@cygnus.com -(All the ugly bits by rich :) -*/ +/* Most of this hacked by Steve Chamberlain, steve@cygnus.com */ #include "archures.h" /* Machine architectures and types */ - /* SUPPRESS 558 */ /* SUPPRESS 590 */ /* SUPPRESS 529 */ /* 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) \ ((( (this) + ((boundary) -1)) & (~((boundary)-1)))) -#define sp(x) bfd_h_put_x(abfd, x, &x) - - - -/* - 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) -*/ +/* 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). */ #define i960_align(addr, 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)); -/* 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 DEFUN(swap_reloc,(abfd, reloc), @@ -114,101 +115,10 @@ DEFUN(swap_scnhdr,(abfd, scnhdr), sp(scnhdr->s_align); #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(); */ extern asection abs_section; - - static int DEFUN(get_index,(symbol), asymbol *symbol) @@ -235,12 +145,17 @@ DEFUN(coff_new_section_hook,(abfd_ignore, section_ignore), asection *section_ignore) { #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 */ section_ignore->alignment_power = 4; #endif 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 DEFUN(make_a_section_from_file,(abfd, hdr), bfd *abfd AND @@ -248,16 +163,18 @@ DEFUN(make_a_section_from_file,(abfd, hdr), { 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) { bfd_error = no_memory; 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->name)[8] = 0; } /* 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); #ifdef I960 { - + /* FIXME, use a temp var rather than alignment_power */ assign(alignment_power, s_align); { unsigned int i; @@ -308,13 +225,13 @@ static boolean DEFUN(coff_mkobject,(abfd), bfd *abfd) { - coff_data_type *coff; - coff_data(abfd) = - (coff_data_type*)bfd_alloc(abfd,sizeof(coff_data_type)); - coff = coff_data(abfd); - coff->relocbase = 0; + set_tdata (abfd, bfd_alloc (abfd,sizeof(coff_data_type))); + if (coff_data(abfd) == 0) { + bfd_error = no_memory; + return false; + } + coff_data(abfd)->relocbase = 0; return true; - } static @@ -331,26 +248,34 @@ DEFUN(coff_real_object_p,(abfd, nscns, opthdr), struct scnhdr *sections; /* points into file_info */ /* Build a play area */ - (void) coff_mkobject(abfd); + if (coff_mkobject(abfd) != true) + return 0; coff = coff_data(abfd); - /* - OK, now we know the format, read in the filehdr, soi-disant "optional - header", and all the sections. - */ + + /* OK, now we know the format, read in the filehdr, soi-disant "optional + header", and all the sections. */ + readsize = sizeof(struct filehdr) + opthdr + (nscns * sizeof(struct scnhdr)); 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; + } - 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; + } + if (bfd_read((PTR) file_info, 1, readsize, abfd) != readsize) { + bfd_release (abfd, (PTR)file_info); goto fail; + } filehdr = (struct filehdr *) file_info; sections = (struct scnhdr *) (file_info + sizeof(struct filehdr) + opthdr); - swap_filehdr(abfd, filehdr); /* 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); if (bfd_seek(abfd, (file_ptr) & (((struct filehdr *) NULL)->f_opthdr), SEEK_SET) < 0) - return (bfd_target *) NULL; + return 0; 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); /* if the optional header is NULL or not the correct size then @@ -564,16 +489,12 @@ DEFUN(uses_x_sym_x_tagndx_p,(native), SYMENT *native) { if (BTYPE(native->n_type) == T_STRUCT) return true; - if (BTYPE(native->n_type) == T_UNION) return true; - if (BTYPE(native->n_type) == T_ENUM)return true; + if (BTYPE(native->n_type) == T_UNION) return true; + if (BTYPE(native->n_type) == T_ENUM) return true; return false; } - - - - /* 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 @@ -608,10 +529,8 @@ differences between to items, used to work out the true index of the target. 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 coff_mangle_symbols(bfd_ptr) bfd *bfd_ptr; @@ -781,12 +700,7 @@ bfd *bfd_ptr; } } } - - - - - static void coff_write_symbols(abfd) @@ -1001,6 +915,7 @@ coff_write_relocs(abfd) } } } + static void coff_write_linenumbers(abfd) bfd *abfd; @@ -1085,6 +1000,7 @@ coff_print_symbol(ignore_abfd, file, symbol, how) break; } } + static alent * coff_get_lineno(ignore_abfd, symbol) bfd *ignore_abfd; @@ -1092,6 +1008,7 @@ coff_get_lineno(ignore_abfd, symbol) { return coffsymbol(symbol)->lineno; } + /* 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. @@ -1103,7 +1020,6 @@ coff_set_flags(abfd, magicp, flagsp) *flagsp; { - switch (abfd->obj_arch) { #ifdef I960ROMAGIC @@ -1144,11 +1060,13 @@ coff_set_flags(abfd, magicp, flagsp) } break; #endif + #ifdef MC68MAGIC case bfd_arch_m68k: *magicp = MC68MAGIC; return true; #endif + #ifdef MC88MAGIC case bfd_arch_m88k: *magicp = MC88OMAGIC; @@ -1204,15 +1122,24 @@ coff_compute_section_file_positions(abfd) for (current = abfd->sections; current != NULL; current = current->next) { -#ifdef MC88MAGIC - sofar = current->filepos = ALIGN(sofar, 1<< - current->alignment_power); -#else - current->filepos = sofar; + /* Only deal with sections which have contents */ + if (!(current->flags & SEC_HAS_CONTENTS)) + continue; + + /* 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 - /* Only add sections which have contents */ - if (current->flags & SEC_HAS_CONTENTS) - sofar += current->size; + /* FIXME, in demand paged files, the low order bits of the file + 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; } obj_relocbase(abfd) = sofar; } @@ -1290,7 +1217,6 @@ coff_write_object_contents(abfd) current->line_filepos = lineno_base; current->moving_line_filepos = lineno_base; lineno_base += current->lineno_count * sizeof(struct lineno); - } else { current->line_filepos = 0; @@ -1304,74 +1230,72 @@ coff_write_object_contents(abfd) } } - + /* Write section headers to the file. */ bfd_seek(abfd, (file_ptr) ((abfd->flags & EXEC_P) ? (FILHSZ + AOUTSZ) : FILHSZ), SEEK_SET); - { + + { #if 0 - unsigned int pad = abfd->flags & D_PAGED ? data_base : 0; + unsigned int pad = abfd->flags & D_PAGED ? data_base : 0; #endif - unsigned int pad = 0; - for (current = abfd->sections; current != NULL; current = current->next) { - SCNHDR section; - strncpy(&(section.s_name[0]), current->name, 8); - section.s_vaddr = current->vma + pad; - section.s_paddr = current->vma + pad; - section.s_size = current->size - pad; - /* - If this section has no size or is unloadable then the scnptr - will be 0 too - */ - if (current->size - pad == 0 || - (current->flags & SEC_LOAD) == 0) { - section.s_scnptr = 0; - - } - else { - section.s_scnptr = current->filepos; - } - section.s_relptr = current->rel_filepos; - section.s_lnnoptr = current->line_filepos; - section.s_nreloc = current->reloc_count; - section.s_nlnno = current->lineno_count; - if (current->reloc_count != 0) - hasrelocs = true; - if (current->lineno_count != 0) - haslinno = true; - - if (!strcmp(current->name, _TEXT)) { - text_sec = current; - section.s_flags = STYP_TEXT; /* kind stupid optimisation */ - } - else { + unsigned int pad = 0; + + for (current = abfd->sections; current != NULL; current = current->next) { + SCNHDR section; + strncpy(&(section.s_name[0]), current->name, 8); + section.s_vaddr = current->vma + pad; + section.s_paddr = current->vma + pad; + section.s_size = current->size - pad; + /* + If this section has no size or is unloadable then the scnptr + will be 0 too + */ + if (current->size - pad == 0 || + (current->flags & SEC_LOAD) == 0) { + section.s_scnptr = 0; - if (!strcmp(current->name, _DATA)) { - data_sec = current; - section.s_flags = STYP_DATA; /* kind stupid - optimisation */ - } - else if (!strcmp(current->name, _BSS)) { - bss_sec = current; - section.s_flags = STYP_BSS; /* kind stupid optimisation */ - } - } + } + else { + section.s_scnptr = current->filepos; + } + section.s_relptr = current->rel_filepos; + section.s_lnnoptr = current->line_filepos; + section.s_nreloc = current->reloc_count; + section.s_nlnno = current->lineno_count; + if (current->reloc_count != 0) + hasrelocs = true; + if (current->lineno_count != 0) + haslinno = true; + + if (!strcmp(current->name, _TEXT)) { + text_sec = current; + section.s_flags = STYP_TEXT; /* kinda stupid */ + } + else if (!strcmp(current->name, _DATA)) { + data_sec = current; + section.s_flags = STYP_DATA; /* kinda stupid */ + } + else if (!strcmp(current->name, _BSS)) { + bss_sec = current; + section.s_flags = STYP_BSS; /* kinda stupid */ + } #ifdef I960 - section.s_align = (current->alignment_power - ? 1 << current->alignment_power - : 0); + section.s_align = (current->alignment_power + ? 1 << current->alignment_power + : 0); #endif - swap_scnhdr(abfd, §ion); - bfd_write((PTR) (§ion), 1, SCNHSZ, abfd); - pad = 0; - } - + swap_scnhdr(abfd, §ion); + bfd_write((PTR) (§ion), 1, SCNHSZ, abfd); + pad = 0; } + } + /* OK, now set up the filehdr... */ bfd_h_put_x(abfd, abfd->section_count, &file_header.f_nscns); @@ -1465,25 +1389,22 @@ coff_write_object_contents(abfd) if (bss_sec) { 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 */ - bfd_h_put_x(abfd, bfd_get_symcount(abfd), &file_header.f_nsyms); if (bfd_seek(abfd, 0L, SEEK_SET) != 0) return false; bfd_write((PTR) &file_header, 1, FILHSZ, abfd); if (abfd->flags & EXEC_P) { - bfd_write((PTR) &coff->hdr, 1, AOUTSZ, abfd); } return true; } - - static boolean coff_set_section_contents(abfd, section, location, offset, count) bfd *abfd; @@ -1502,6 +1423,7 @@ coff_set_section_contents(abfd, section, location, offset, count) } return true; } + static boolean coff_get_section_contents(abfd, section, location, offset, count) bfd *abfd; @@ -1539,21 +1461,12 @@ coff_close_and_cleanup(abfd) return false; } -#define cleaner(ptr) if (abfd->ptr) free (abfd->ptr) - cleaner(tdata); - - if (abfd->my_archive) - cleaner(filename); - -#undef cleaner + /* We depend on bfd_close to free all the memory on the obstack. */ + /* FIXME if bfd_release is not using obstacks! */ return true; } - - - - static PTR buy_and_read(abfd, where, seek_direction, size) bfd *abfd; @@ -1633,6 +1546,7 @@ offset_symbol_indices(symtab, count, offset) return; } /* offset_symbol_indices() */ + /* swap the entire symbol table */ static void swap_raw_symtab(abfd, raw_symtab) @@ -1654,6 +1568,7 @@ swap_raw_symtab(abfd, raw_symtab) return; } /* swap_raw_symtab() */ + /* 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 @@ -1673,13 +1588,12 @@ get_normalized_symtab(abfd) unsigned long size; unsigned long string_table_size = 0; - if ((size = bfd_get_symcount(abfd) * sizeof(SYMENT)) == 0) { bfd_error = no_symbols; return (NULL); } /* 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 inject one if it wasn't there originally. @@ -1849,7 +1763,7 @@ get_normalized_symtab(abfd) #ifndef GNU960 /* 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) force_indices_file_symbol_relative(abfd, retval); @@ -1860,19 +1774,17 @@ get_normalized_symtab(abfd) obj_raw_syments(abfd) = retval; obj_string_table(abfd) = string_table; - - return (retval); } /* get_normalized_symtab() */ static -struct sec_struct * +struct sec * section_from_bfd_index(abfd, index) bfd *abfd; int index; { if (index > 0) { - struct sec_struct *answer = abfd->sections; + struct sec *answer = abfd->sections; while (--index) { answer = answer->next; } @@ -1884,16 +1796,15 @@ section_from_bfd_index(abfd, index) -static - boolean +static boolean coff_slurp_line_table(abfd, asect) bfd *abfd; asection *asect; { struct lineno *native_lineno; alent *lineno_cache; - BFD_ASSERT(asect->lineno == (alent *) NULL); + BFD_ASSERT(asect->lineno == (alent *) NULL); native_lineno = (struct lineno *) buy_and_read(abfd, asect->line_filepos, @@ -1905,10 +1816,11 @@ coff_slurp_line_table(abfd, asect) if (lineno_cache == NULL) { bfd_error = no_memory; return false; - } { /* on error */ + } else { unsigned int counter = 0; alent *cache_ptr = lineno_cache; struct lineno *src = native_lineno; + while (counter < asect->lineno_count) { bfd_coff_swap_lineno(abfd, src); cache_ptr->line_number = src->l_lnno; @@ -1934,6 +1846,7 @@ coff_slurp_line_table(abfd, asect) } asect->lineno = lineno_cache; + /* FIXME, free native_lineno here, or use alloca or something. */ return true; } /* coff_slurp_line_table() */ @@ -1942,7 +1855,6 @@ find_next_file_symbol(current, end) SYMENT *current; SYMENT *end; { - unsigned int next = current->n_value; current += current->n_numaux + 1; while (current < end) { @@ -2019,7 +1931,7 @@ coff_slurp_symbol_table(abfd) if (table_ptr == NULL) { bfd_error = no_memory; return false; - } { /* on error */ + } else { coff_symbol_type *dst = cached_area; unsigned int last_native_index = bfd_get_symcount(abfd); unsigned int this_index = 0; @@ -2148,9 +2060,6 @@ coff_slurp_symbol_table(abfd) break; } - - - BFD_ASSERT(dst->symbol.flags != 0); dst->native = src; @@ -2161,7 +2070,6 @@ coff_slurp_symbol_table(abfd) dst++; number_of_symbols++; } /* walk the native symtab */ - } /* bfdize the native symtab */ obj_symbols(abfd) = cached_area; @@ -2306,7 +2214,6 @@ coff_slurp_reloc_table(abfd, asect, symbols) } - asect->relocation = reloc_cache; 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 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) return false; - p = cof->raw_syments; /* 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; #endif - - for (i = 0; i < cof->raw_syment_count; i++) { if (p->n_sclass == C_FILE) { /* File name is embeded in auxent */ @@ -2424,10 +2325,6 @@ DEFUN(coff_find_nearest_line,(abfd, p += 1 + p->n_numaux; } /* Now wander though the raw linenumbers of the section */ - - - - /* 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 diff --git a/bfd/coff-i960.c b/bfd/coff-i960.c index 8f6e688..4768104 100644 --- a/bfd/coff-i960.c +++ b/bfd/coff-i960.c @@ -1,3 +1,5 @@ +/* Intel 960 COFF support for BFD. */ + /* Copyright (C) 1990, 1991 Free Software Foundation, Inc. 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$ */ #define I960 1 +#define BADMAG(x) I960BADMAG(x) + #include <ansidecl.h> #include "sysdep.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 */ - - - #define CALLS 0x66003800 /* Template for 'calls' instruction */ #define BAL 0x0b000000 /* Template for 'bal' instruction */ #define BAL_MASK 0x00ffffff @@ -49,9 +50,8 @@ asection *ignore_input_section; bfd_reloc_status_enum_type result; coff_symbol_type *cs = coffsymbol(symbol_in); - /* So the target symbol has to be off coff type, and the symbol - has to have the correct native information within it - */ + /* So the target symbol has to be of coff type, and the symbol + has to have the correct native information within it */ if ((cs->symbol.the_bfd->xvec->flavour != bfd_target_coff_flavour_enum) || (cs->native == (struct syment *)NULL)) { /* 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 */ /* leaf. */ result = bfd_reloc_dangerous; - } else { 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" bfd_target icoff_little_vec = @@ -166,7 +164,8 @@ bfd_target icoff_little_vec = bfd_generic_archive_p, _bfd_dummy_target}, {bfd_false, coff_mkobject, /* bfd_set_format */ _bfd_generic_mkarchive, bfd_false}, -JUMP_TABLE(coff) + + JUMP_TABLE(coff) }; @@ -190,8 +189,9 @@ bfd_target icoff_big_vec = _do_getllong, _do_putllong, _do_getlshort, _do_putlshort, /* data */ _do_getblong, _do_putblong, _do_getbshort, _do_putbshort, /* hdrs */ - {_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target}, - {bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false}, + {_bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target}, + {bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false}, + JUMP_TABLE(coff) - }; +}; diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c index c27e8c3..81c2a53 100644 --- a/bfd/coff-mips.c +++ b/bfd/coff-mips.c @@ -565,12 +565,12 @@ unsigned int size; } static -struct sec_struct *section_from_bfd_index(abfd, index) +struct sec *section_from_bfd_index(abfd, index) bfd *abfd; int index; { if (index > 0) { - struct sec_struct *answer = abfd->sections; + struct sec *answer = abfd->sections; while (--index) { answer = answer->next; diff --git a/bfd/libaout.h b/bfd/libaout.h index 43195f5..35d795b 100644 --- a/bfd/libaout.h +++ b/bfd/libaout.h @@ -65,9 +65,8 @@ struct sunexdata { -/* We case the address of the first element of a asymbol to ensure that the - * macro is only every applied to an asymbol - */ +/* We take the address of the first element of an asymbol to ensure that the + * macro is only ever applied to an asymbol */ #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd)) /*#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 get_tdata(x) ((struct sunexdata *)((x)->tdata)) -#define set_tdata(x,y) ((x)->tdata = (PTR) (y)) - - diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 7521c48..f612343 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -56,12 +56,14 @@ bfd *ignore; { return (void *)NULL; } + int bfd_0(ignore) bfd *ignore; { return 0; } + unsigned int bfd_0u(ignore) bfd *ignore; diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 2ff951f..0c84796 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -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. 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$ */ -/*** 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 in quanta of this amount */ #define DEFAULT_BUFFERSIZE 8192 -/* tdata for an archive. For an input archive cache - needs to be free()'d. For an output archive, symdefs do. -*/ +/* Set a tdata field. Can't use the other macros for this, since they + 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 { file_ptr first_file_filepos; @@ -44,7 +43,6 @@ struct artdata { }; #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 */ struct areltdata { @@ -59,13 +57,19 @@ struct areltdata { This can't always work, because of alignment restrictions. We should change it before it becomes a problem -- Gumby */ -PROTO (char *, zalloc, (size_t size)); +PROTO (char *, zalloc, (bfd_size_type size)); -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 (size_t, bfd_write, (PTR ptr, size_t size, size_t nitems, bfd *abfd)); +/* 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_size_type, bfd_read, (PTR ptr, bfd_size_type size, bfd_size_type 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 (void, bfd_cache_close, (bfd *)); @@ -103,7 +107,6 @@ PROTO (int, bfd_0, (bfd *ignore)); PROTO (unsigned int, bfd_0u, (bfd *ignore)); PROTO (void, bfd_void, (bfd *ignore)); - PROTO (bfd *,new_bfd_contained_in,(bfd *)); PROTO (boolean, _bfd_dummy_new_section_hook, (bfd *ignore, asection *newsect)); 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(int, bfd_generic_stat_arch_elt, (bfd *, struct stat *)); + /* Macros to tell if bfds are read or write enabled. Note that bfds open for read may be scribbled into if the fd passed diff --git a/bfd/libcoff.h b/bfd/libcoff.h index c00970f..67b9c98 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -59,6 +59,12 @@ typedef struct icofdata long int relocbase; } 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. */ #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 *)); diff --git a/bfd/libieee.h b/bfd/libieee.h index aefc5fd..8d5679d 100644 --- a/bfd/libieee.h +++ b/bfd/libieee.h @@ -3,35 +3,34 @@ typedef struct { char letter; } ieee_symbol_index_type; -typedef struct ieee_symbol_struct { +typedef struct ieee_symbol { asymbol symbol; - struct ieee_symbol_struct *next; + struct ieee_symbol *next; unsigned int index; } ieee_symbol_type; -typedef struct ieee_reloc_struct { +typedef struct ieee_reloc { arelent relent; - struct ieee_reloc_struct *next; + struct ieee_reloc *next; ieee_symbol_index_type symbol; } ieee_reloc_type; #define ieee_symbol(x) ((ieee_symbol_type *)(x)) -typedef struct ieee_per_section_struct +typedef struct ieee_per_section { asection *section; bfd_byte *data; bfd_vma offset; - struct obstack reloc_obstack; - ieee_reloc_type **reloc_tail_ptr; -bfd_vma pc; + bfd_vma pc; /* For output */ file_ptr current_pos; unsigned int current_byte; boolean initialized; + ieee_reloc_type **reloc_tail_ptr; } ieee_per_section_type; #define ieee_per_section(x) ((ieee_per_section_type *)((x)->used_by_bfd)) @@ -41,24 +40,28 @@ bfd_vma pc; typedef struct { boolean read_symbols; -boolean read_data; + boolean read_data; +unsigned char *input_p; +unsigned char *first_byte; file_ptr output_cursor; /* Map of section indexes to section ptrs */ - asection * section_table[NSECTIONS]; + asection * section_table[NSECTIONS]; ieee_address_descriptor_type ad; ieee_module_begin_type mb; ieee_w_variable_type w; unsigned int section_count; + struct obstack ieee_obstack; + unsigned int map_idx; /* List of GLOBAL EXPORT symbols */ ieee_symbol_type *external_symbols; - /* List of UNDEFINED symbols */ + /* List of UNDEFINED symbols */ ieee_symbol_type *external_reference; -/* When the symbols have been canonicalized, they are in a - * special order, we remember various bases here.. */ + /* When the symbols have been canonicalized, they are in a + * special order, we remember various bases here.. */ unsigned int external_symbol_max_index; unsigned int external_symbol_min_index; unsigned int external_symbol_count; @@ -70,7 +73,7 @@ boolean read_data; int external_reference_base_offset; -boolean symbol_table_full; + boolean symbol_table_full; } ieee_data_type; typedef struct { @@ -85,6 +88,7 @@ typedef struct { unsigned int element_count; } ieee_ar_data_type; #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) diff --git a/bfd/liboasys.h b/bfd/liboasys.h index 2c57e59..437035d 100644 --- a/bfd/liboasys.h +++ b/bfd/liboasys.h @@ -5,9 +5,9 @@ typedef struct asymbol symbol; } oasys_symbol_type; -typedef struct oasys_reloc_struct { +typedef struct oasys_reloc { arelent relent; - struct oasys_reloc_struct *next; + struct oasys_reloc *next; unsigned int symbol; } oasys_reloc_type; @@ -15,7 +15,7 @@ typedef struct oasys_reloc_struct { #define oasys_symbol(x) ((oasys_symbol_type *)(x)) #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; bfd_byte *data; diff --git a/bfd/opncls.c b/bfd/opncls.c index 8b656bb..9b91c2f 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1,3 +1,5 @@ +/* opncls.c -- open and close a bfd. */ + /* Copyright (C) 1990, 1991 Free Software Foundation, Inc. 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$ */ -/*** opncls.c -- open and close a bfd. */ - #include "sysdep.h" #include "bfd.h" #include "libbfd.h" - - extern void bfd_cache_init(); FILE *bfd_open_file(); @@ -52,11 +50,12 @@ FILE *bfd_open_file(); Perhaps, since unix has so many different kinds of locking anyway, we should use the emacs lock scheme?... */ - #define obstack_chunk_alloc malloc #define obstack_chunk_free free +/* Return a new BFD. All BFD's are allocated through this routine. */ + bfd *new_bfd() { struct obstack tmp; @@ -64,6 +63,8 @@ bfd *new_bfd() obstack_begin(&tmp,128); nbfd = (bfd *)obstack_alloc(&tmp,sizeof(bfd)); + memset((PTR)nbfd, 0, sizeof (bfd)); /* Clear it */ + nbfd->memory = tmp; nbfd->direction = no_direction; @@ -80,8 +81,12 @@ bfd *new_bfd() nbfd->sections = (asection *)NULL; nbfd->cacheable = false; nbfd->flags = NO_FLAGS; + nbfd->mtime_set = 0; return nbfd; } + +/* Allocate a new BFD as a member of archive OBFD. */ + bfd *new_bfd_contained_in(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: */ nbfd->iostream = (char *) fdopen (fd, "r+"); if (nbfd->iostream == NULL) { - free (nbfd); + (void) obstack_free (&nbfd->memory, (PTR)0); return NULL; } @@ -240,7 +245,7 @@ DEFUN(bfd_openw,(filename, target), if (bfd_open_file (nbfd) == NULL) { bfd_error = system_call_error; /* File not writeable, etc */ - free (nbfd); + (void) obstack_free (&nbfd->memory, (PTR)0); return NULL; } return nbfd; @@ -264,12 +269,12 @@ bfd_close (abfd) stat(abfd->filename, &buf); 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; } -/* - called to create a bfd with no ascociated file or target - */ + +/* Create a bfd with no associated file or target. */ + bfd * DEFUN(bfd_create,(filename, template), CONST char *filename AND @@ -287,40 +292,39 @@ DEFUN(bfd_create,(filename, template), nbfd->direction = no_direction; bfd_set_format(nbfd, bfd_object); return nbfd; - - - } +/* Memory allocation */ + DEFUN(PTR bfd_alloc, (abfd, size), 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; } DEFUN(PTR bfd_zalloc,(abfd, size), bfd *abfd AND - size_t size) + bfd_size_type size) { PTR res = bfd_alloc(abfd, size); - memset(res, 0, size); + memset(res, 0, (size_t)size); return res; } DEFUN(PTR bfd_realloc,(abfd, old, size), bfd *abfd AND PTR old AND - size_t size) + bfd_size_type size) { PTR res = bfd_alloc(abfd, size); - memcpy(res, old, size); + memcpy(res, old, (size_t)size); return res; } -DEFUN(size_t bfd_alloc_size,(abfd), +DEFUN(bfd_size_type bfd_alloc_size,(abfd), bfd *abfd) { struct _obstack_chunk *chunk = abfd->memory.chunk; diff --git a/bfd/sunos.c b/bfd/sunos.c index fb9dfd2..55e7547 100644 --- a/bfd/sunos.c +++ b/bfd/sunos.c @@ -1,4 +1,5 @@ /*** bfd backend for sunos binaries */ +/** a.out files */ /* 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 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id$ - * - */ - -#define TARGET_BYTE_ORDER_BIG_P 1 +/* $Id$ */ #include <ansidecl.h> #include "sysdep.h" #include "bfd.h" #include "libbfd.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.sun4.h" #include "a.out.gnu.h" #include "stab.gnu.h" #include "ar.h" #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 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). */ 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( 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), @@ -98,8 +85,6 @@ HOWTO( 7, 0, 3, 64, true, 0, false, true,0,"DISP64", true, 0xfeedfac bfd_error_vector_type bfd_error_vector; -/** a.out files */ - PROTO (void , sunos4_write_syms, ()); 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); } -/* 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 * sunos4_object_p (abfd) bfd *abfd; @@ -212,9 +158,7 @@ sunos4_object_p (abfd) return 0; 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; @@ -288,9 +232,11 @@ sunos4_object_p (abfd) 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. */ - obj_str_filepos (abfd) = n_stroff (execp); - obj_sym_filepos (abfd) = n_symoff (execp); + obj_str_filepos (abfd) = N_STROFF (*execp); + obj_sym_filepos (abfd) = N_SYMOFF (*execp); /* create the sections. This is raunchy, but bfd_close wants to reclaim them */ @@ -339,14 +285,14 @@ sunos4_mkobject (abfd) bfd_error = system_call_error; /* Use an intermediate variable for clarity */ - rawptr = bfd_zalloc (abfd,sizeof (struct sunexdata) + sizeof (struct exec)); + rawptr = bfd_zalloc (abfd, sizeof (struct sunexdata) + sizeof (struct exec)); if (rawptr == NULL) { bfd_error = no_memory; return false; } - abfd->tdata = (PTR)((struct sunexdata *) rawptr); + set_tdata (abfd, (struct sunexdata *) rawptr); exec_hdr (abfd) = (struct exec *) (rawptr + sizeof (struct sunexdata)); /* 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); 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); N_SET_MAGIC (*execp, ZMAGIC); } else if (abfd->flags & WP_TEXT) { @@ -515,9 +463,8 @@ sunos4_write_object_contents (abfd) } return true; } - -/** core files */ -/** core files */ + +/* core files */ #define CORE_MAGIC 0x080456 #define CORE_NAMELEN 16 @@ -640,7 +587,7 @@ sunos4_core_file_p (abfd) if ((bfd_read ((PTR) core, 1, core_size, abfd)) != core_size) { bfd_error = system_call_error; - free ((PTR)rawptr); + bfd_release (abfd, rawptr); return 0; } @@ -654,24 +601,24 @@ sunos4_core_file_p (abfd) if (core_stacksec (abfd) == NULL) { loser: bfd_error = no_memory; - free ((PTR)rawptr); + bfd_release (abfd, rawptr); return 0; } core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_datasec (abfd) == NULL) { loser1: - free ((PTR)core_stacksec (abfd)); + bfd_release (abfd, core_stacksec (abfd)); goto loser; } core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_regsec (abfd) == NULL) { loser2: - free ((PTR)core_datasec (abfd)); + bfd_release (abfd, core_datasec (abfd)); goto loser1; } core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection)); if (core_reg2sec (abfd) == NULL) { - free ((PTR)core_regsec (abfd)); + bfd_release (abfd, core_regsec (abfd)); goto loser2; } @@ -809,31 +756,15 @@ sunos4_set_section_contents (abfd, section, location, offset, count) { if (abfd->output_has_begun == false) { /* set by bfd.c handler */ - if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL) - - /*|| - (obj_textsec (abfd)->size == 0) || (obj_datasec (abfd)->size= - 0)*/ - ) + if ((obj_textsec (abfd) == NULL) || (obj_datasec (abfd) == NULL)) { bfd_error = invalid_operation; return false; } - -#if 0 - if (abfd->flags & D_PAGED) - { - obj_textsec (abfd)->filepos = sizeof(struct exec); - obj_datasec(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; - - } + 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 */ if (section != obj_bsssec(abfd)) { @@ -847,6 +778,7 @@ sunos4_set_section_contents (abfd, section, location, offset, count) } return true; } + boolean sunos4_get_section_contents (abfd, section, location, offset, count) bfd *abfd; @@ -944,14 +876,12 @@ translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd) } cache_ptr->symbol.section = reloc->relent.section; 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 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 - symbol attached to this section. - */ - + symbol attached to this section. */ section->flags = SEC_CONSTRUCTOR; 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; - /* FIXME check for wrigin bss */ + /* FIXME check for writing bss */ if (bfd_get_section(cache_ptr)) { if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) { 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; } else { - - bfd_error_vector.nonrepresentable_section(abfd, bfd_get_output_section(cache_ptr)->name); - + bfd_error_vector.nonrepresentable_section(abfd, + bfd_get_output_section(cache_ptr)->name); } /* Turn the symbol from section relative to absolute again */ 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) { sym_pointer->n_type = ((aout_symbol_type *)cache_ptr)->type; } - } /* Native-level interface to symbols. */ @@ -1114,9 +1042,9 @@ boolean DEFUN(sunos4_slurp_symbol_table, (abfd), bfd *abfd) { - unsigned int symbol_count; size_t symbol_size; size_t string_size; + unsigned char string_chars[LONG_SIZE]; struct nlist *syms; char *strings; aout_symbol_type *cached; @@ -1130,20 +1058,22 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), } 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; - string_size = bfd_h_getlong (abfd, (unsigned char *)&string_size); - - symbol_count = symbol_size / sizeof (struct nlist); + string_size = bfd_h_getlong (abfd, string_chars); strings = bfd_alloc(abfd, string_size + 1); 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); bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET); if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) { bailout: + if (syms) bfd_release (abfd, syms); + if (cached) bfd_release (abfd, cached); + if (strings)bfd_release (abfd, strings); return false; } @@ -1155,7 +1085,7 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), /* OK, now walk the new symtable, cacheing symbol properties */ { 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; /* 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); sym_pointer->n_type = (char) bfd_h_get_x(abfd, &sym_pointer->n_type); - } /* Run through table and copy values */ @@ -1193,7 +1122,6 @@ DEFUN(sunos4_slurp_symbol_table, (abfd), } obj_aout_symbols (abfd) = cached; - bfd_get_symcount (abfd) = symbol_count; bfd_release (abfd, (PTR)syms); return true; @@ -1258,7 +1186,7 @@ DEFUN(sunos4_write_syms,(abfd), { asymbol *g = *(generic++); - if (g->name != (char *)NULL) + if (g->name) { size_t length = strlen(g->name)+1; 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. */ void -swap_std_reloc_out (abfd, p, natptr, count) +swap_std_reloc_out (abfd, g, natptr) bfd *abfd; - arelent **p; /* Generic relocation struct */ + arelent *g; /* Generic relocation struct */ struct reloc_std_bytes *natptr; - unsigned int count; { int r_index; int r_extern; @@ -1319,83 +1246,77 @@ swap_std_reloc_out (abfd, p, natptr, count) int r_pcrel; int r_baserel, r_jmptable, r_relative; 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); - - r_length = g->howto->size; /* Size as a power of two */ - r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ - /* r_baserel, r_jmptable, r_relative??? FIXME-soon */ - r_baserel = 0; - r_jmptable = 0; - r_relative = 0; - r_addend = g->addend; /* Start here, see how it goes */ + bfd_h_putlong (abfd, g->address, natptr->r_address); - /* name was clobbered by sunos4_write_syms to be symbol index */ + r_length = g->howto->size; /* Size as a power of two */ + r_pcrel = (int) g->howto->pc_relative; /* Relative to PC? */ + /* r_baserel, r_jmptable, r_relative??? FIXME-soon */ + r_baserel = 0; + r_jmptable = 0; + r_relative = 0; - if (g->sym_ptr_ptr != NULL) - { - if ((*(g->sym_ptr_ptr))->section) { - /* put the section offset into the addend for output */ - r_addend += (*(g->sym_ptr_ptr))->section->vma; - } + r_addend = g->addend; /* Start here, see how it goes */ - r_index = stoi((*(g->sym_ptr_ptr))->name); - r_extern = 1; - } - else { - r_extern = 0; - if (g->section == NULL) { - BFD_ASSERT(0); - r_index = N_ABS | N_EXT; - } - else if(g->section->output_section == obj_textsec(abfd)) { - r_index = N_TEXT | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_datasec(abfd)) { - r_index = N_DATA | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_bsssec(abfd)) { - r_index = N_BSS | N_EXT ; - r_addend += g->section->output_section->vma; - } - else { - BFD_ASSERT(0); - } - } + /* name was clobbered by sunos4_write_syms to be symbol index */ - /* now the fun stuff */ - if (abfd->xvec->header_byteorder_big_p != false) { - natptr->r_index[0] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[2] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0) - | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0) - | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0) - | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0) - | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0) - | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG); - } else { - natptr->r_index[2] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[0] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) - | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) - | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0) - | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0) - | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) - | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); + if (g->sym_ptr_ptr != NULL) + { + if ((*(g->sym_ptr_ptr))->section) { + /* put the section offset into the addend for output */ + r_addend += (*(g->sym_ptr_ptr))->section->vma; } - + r_index = stoi((*(g->sym_ptr_ptr))->name); + r_extern = 1; + } + else { + r_extern = 0; + if (g->section == NULL) { + BFD_ASSERT(0); + r_index = N_ABS | N_EXT; } + else if(g->section->output_section == obj_textsec(abfd)) { + r_index = N_TEXT | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_datasec(abfd)) { + r_index = N_DATA | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_bsssec(abfd)) { + r_index = N_BSS | N_EXT ; + r_addend += g->section->output_section->vma; + } + else { + BFD_ASSERT(0); + } + } + + /* now the fun stuff */ + if (abfd->xvec->header_byteorder_big_p != false) { + natptr->r_index[0] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[2] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_STD_BITS_EXTERN_BIG: 0) + | (r_pcrel? RELOC_STD_BITS_PCREL_BIG: 0) + | (r_baserel? RELOC_STD_BITS_BASEREL_BIG: 0) + | (r_jmptable? RELOC_STD_BITS_JMPTABLE_BIG: 0) + | (r_relative? RELOC_STD_BITS_RELATIVE_BIG: 0) + | (r_length << RELOC_STD_BITS_LENGTH_SH_BIG); + } else { + natptr->r_index[2] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[0] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_STD_BITS_EXTERN_LITTLE: 0) + | (r_pcrel? RELOC_STD_BITS_PCREL_LITTLE: 0) + | (r_baserel? RELOC_STD_BITS_BASEREL_LITTLE: 0) + | (r_jmptable? RELOC_STD_BITS_JMPTABLE_LITTLE: 0) + | (r_relative? RELOC_STD_BITS_RELATIVE_LITTLE: 0) + | (r_length << RELOC_STD_BITS_LENGTH_SH_LITTLE); + } } @@ -1403,84 +1324,79 @@ swap_std_reloc_out (abfd, p, natptr, count) /* Output extended relocation information to a file in target byte order. */ void -swap_ext_reloc_out (abfd, p, natptr, count) +swap_ext_reloc_out (abfd, g, natptr) bfd *abfd; - arelent **p; /* Generic relocation struct */ + arelent *g; /* Generic relocation struct */ register struct reloc_ext_bytes *natptr; - unsigned int count; { - int r_index; int r_extern; unsigned int r_type; 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); - /* Find a type in the output format which matches the input howto - - at the moment we assume input format == output format FIXME!! */ - r_type = (enum reloc_type) g->howto->type; + bfd_h_putlong (abfd, g->address, natptr->r_address); - r_addend = g->addend; /* Start here, see how it goes */ + /* Find a type in the output format which matches the input howto - + at the moment we assume input format == output format FIXME!! */ + r_type = (enum reloc_type) g->howto->type; - /* name was clobbered by sunos4_write_syms to be symbol index*/ + r_addend = g->addend; /* Start here, see how it goes */ - if (g->sym_ptr_ptr != NULL) - { - if ((*(g->sym_ptr_ptr))->section) { - /* put the section offset into the addend for output */ - r_addend += (*(g->sym_ptr_ptr))->section->vma; - } + /* name was clobbered by sunos4_write_syms to be symbol index*/ - r_index = stoi((*(g->sym_ptr_ptr))->name); - r_extern = 1; - } - else { - r_extern = 0; - if (g->section == NULL) { - BFD_ASSERT(0); - r_index = N_ABS | N_EXT; - } - else if(g->section->output_section == obj_textsec(abfd)) { - r_index = N_TEXT | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_datasec(abfd)) { - r_index = N_DATA | N_EXT; - r_addend += g->section->output_section->vma; - } - else if (g->section->output_section == obj_bsssec(abfd)) { - r_index = N_BSS | N_EXT ; - r_addend += g->section->output_section->vma; - } - else { - BFD_ASSERT(0); + if (g->sym_ptr_ptr != NULL) + { + if ((*(g->sym_ptr_ptr))->section) { + /* put the section offset into the addend for output */ + r_addend += (*(g->sym_ptr_ptr))->section->vma; } - } - /* now the fun stuff */ - if (abfd->xvec->header_byteorder_big_p != false) { - natptr->r_index[0] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[2] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) - || (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); - } else { - natptr->r_index[2] = r_index >> 16; - natptr->r_index[1] = r_index >> 8; - natptr->r_index[0] = r_index; - natptr->r_bits[0] = - (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0) - || (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE); + r_index = stoi((*(g->sym_ptr_ptr))->name); + r_extern = 1; + } + else { + r_extern = 0; + if (g->section == NULL) { + BFD_ASSERT(0); + r_index = N_ABS | N_EXT; } + else if(g->section->output_section == obj_textsec(abfd)) { + r_index = N_TEXT | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_datasec(abfd)) { + r_index = N_DATA | N_EXT; + r_addend += g->section->output_section->vma; + } + else if (g->section->output_section == obj_bsssec(abfd)) { + r_index = N_BSS | N_EXT ; + r_addend += g->section->output_section->vma; + } + else { + BFD_ASSERT(0); + } + } - bfd_h_putlong (abfd, r_addend, natptr->r_addend); + /* now the fun stuff */ + if (abfd->xvec->header_byteorder_big_p != false) { + natptr->r_index[0] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[2] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0) + || (r_type << RELOC_EXT_BITS_TYPE_SH_BIG); + } else { + natptr->r_index[2] = r_index >> 16; + natptr->r_index[1] = r_index >> 8; + natptr->r_index[0] = r_index; + natptr->r_bits[0] = + (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0) + || (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE); } + + bfd_h_putlong (abfd, r_addend, natptr->r_addend); } + #define MOVE_ADDRESS(ad) \ if (r_extern) { \ cache_ptr->sym_ptr_ptr = symbols + r_index; \ @@ -1506,9 +1422,13 @@ swap_ext_reloc_out (abfd, p, natptr, count) break; \ case N_ABS: \ case N_ABS | N_EXT: \ + cache_ptr->section = NULL; /* No section */ \ + cache_ptr->addend = ad; /* FIXME, is this right? */ \ BFD_ASSERT(1); \ break; \ default: \ + cache_ptr->section = NULL; /* No section */ \ + cache_ptr->addend = ad; /* FIXME, is this right? */ \ BFD_ASSERT(1); \ break; \ } \ @@ -1547,13 +1467,12 @@ swap_ext_reloc_in (abfd, bytes, cache_ptr, symbols) cache_ptr->howto = howto_table_ext + r_type; MOVE_ADDRESS(bfd_h_getlong(abfd,bytes->r_addend)); - } void swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) bfd *abfd; - struct reloc_std_bytes *bytes; + struct reloc_std_bytes *bytes; arelent *cache_ptr; asymbol **symbols; { @@ -1563,6 +1482,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) int r_pcrel; int r_baserel, r_jmptable, r_relative; struct sunexdata *su = (struct sunexdata *)(abfd->tdata); + cache_ptr->address = bfd_h_getlong (abfd, bytes->r_address); /* now the fun stuff */ @@ -1576,7 +1496,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) r_jmptable= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_JMPTABLE_BIG)); r_relative= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_RELATIVE_BIG)); r_length = (bytes->r_bits[0] & RELOC_STD_BITS_LENGTH_BIG) - >> RELOC_STD_BITS_LENGTH_SH_BIG; + >> RELOC_STD_BITS_LENGTH_SH_BIG; } else { r_index = (bytes->r_index[2] << 16) | (bytes->r_index[1] << 8) @@ -1587,7 +1507,7 @@ swap_std_reloc_in (abfd, bytes, cache_ptr, symbols) r_jmptable= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); r_relative= (0 != (bytes->r_bits[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); r_length = (bytes->r_bits[0] & RELOC_STD_BITS_LENGTH_LITTLE) - >> RELOC_STD_BITS_LENGTH_SH_LITTLE; + >> RELOC_STD_BITS_LENGTH_SH_LITTLE; } cache_ptr->howto = howto_table_std + r_length + 4 * r_pcrel; @@ -1636,24 +1556,34 @@ sunos4_slurp_reloc_table (abfd, asect, symbols) reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof (arelent))); + if (!reloc_cache) { +nomem: + bfd_error = no_memory; + return false; + } + 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; return false; } - if (each_size == RELOC_EXT_SIZE) - { - register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; - unsigned int counter = 0; - arelent *cache_ptr = reloc_cache; + if (each_size == RELOC_EXT_SIZE) { + register struct reloc_ext_bytes *rptr = (struct reloc_ext_bytes *) relocs; + unsigned int counter = 0; + arelent *cache_ptr = reloc_cache; - for (; counter < count; counter++, rptr++, cache_ptr++) { - swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); - } + for (; counter < count; counter++, rptr++, cache_ptr++) { + swap_ext_reloc_in(abfd, rptr, cache_ptr, symbols); } - else { + } else { register struct reloc_std_bytes *rptr = (struct reloc_std_bytes *) relocs; unsigned int counter = 0; arelent *cache_ptr = reloc_cache; @@ -1663,7 +1593,8 @@ sunos4_slurp_reloc_table (abfd, asect, symbols) } } -bfd_release (abfd,relocs); + + bfd_release (abfd,relocs); asect->relocation = reloc_cache; asect->reloc_count = count; return true; @@ -1679,7 +1610,7 @@ sunos4_squirt_out_relocs (abfd, section) asection *section; { arelent **generic; - unsigned char *native; + unsigned char *native, *natptr; size_t each_size; unsigned int count = section->reloc_count; @@ -1699,14 +1630,17 @@ sunos4_squirt_out_relocs (abfd, section) if (each_size == RELOC_EXT_SIZE) { - swap_ext_reloc_out (abfd, - generic, - (struct reloc_ext_bytes *)native, - count); + for (natptr = native; + count != 0; + --count, natptr += each_size, ++generic) + swap_ext_reloc_out (abfd, generic, (struct reloc_ext_bytes *)native); } 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) { @@ -1811,7 +1745,7 @@ bfd_print_symbol_enum_type how; break; case bfd_print_symbol_type_enum: fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff), - (unsigned)( aout_symbol(symbol)->other & 0xff), + (unsigned)(aout_symbol(symbol)->other & 0xff), (unsigned)(aout_symbol(symbol)->type)); break; case bfd_print_symbol_all_enum: @@ -1824,7 +1758,7 @@ bfd_print_symbol_enum_type how; fprintf(file," %-5s %04x %02x %02x %s", section_name, (unsigned)(aout_symbol(symbol)->desc & 0xffff), - (unsigned)(aout_symbol(symbol)->other & 0xff), + (unsigned)(aout_symbol(symbol)->other & 0xff), (unsigned)(aout_symbol(symbol)->type & 0xff), symbol->name); } |