diff options
author | Ian Lance Taylor <ian@airs.com> | 1995-09-12 16:23:25 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 1995-09-12 16:23:25 +0000 |
commit | ae115e5114deb0326333c80f7af9e689b2e7d01f (patch) | |
tree | 2c592646411768ec9a95b17070181cb5b068cf9c | |
parent | d8586e35caeb6ffea7058bce844023ec19140cc7 (diff) | |
download | gdb-ae115e5114deb0326333c80f7af9e689b2e7d01f.zip gdb-ae115e5114deb0326333c80f7af9e689b2e7d01f.tar.gz gdb-ae115e5114deb0326333c80f7af9e689b2e7d01f.tar.bz2 |
Extensive minor changes to avoid various gcc warnings. Also:
* Makefile.in (BFD32_BACKENDS): Remove coff-arm.o.
* archures.c (bfd_arch_info_type): Change mach field from long to
unsigned long.
(bfd_lookup_arch): Change machine parameter from long to unsigned
long.
-rw-r--r-- | bfd/ChangeLog | 9 | ||||
-rw-r--r-- | bfd/Makefile.in | 1 | ||||
-rw-r--r-- | bfd/aout-adobe.c | 40 | ||||
-rw-r--r-- | bfd/aoutx.h | 465 | ||||
-rw-r--r-- | bfd/archive.c | 46 | ||||
-rw-r--r-- | bfd/archures.c | 6 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 4 | ||||
-rw-r--r-- | bfd/bout.c | 98 | ||||
-rw-r--r-- | bfd/coff-rs6000.c | 30 | ||||
-rw-r--r-- | bfd/coff-sh.c | 20 | ||||
-rw-r--r-- | bfd/coff-sparc.c | 22 | ||||
-rw-r--r-- | bfd/coff-w65.c | 447 | ||||
-rw-r--r-- | bfd/coffgen.c | 219 | ||||
-rw-r--r-- | bfd/cofflink.c | 327 | ||||
-rw-r--r-- | bfd/cpu-arc.c | 77 | ||||
-rw-r--r-- | bfd/cpu-i960.c | 89 | ||||
-rw-r--r-- | bfd/cpu-mips.c | 92 | ||||
-rw-r--r-- | bfd/ecoff.c | 38 | ||||
-rw-r--r-- | bfd/elf.c | 91 | ||||
-rw-r--r-- | bfd/elflink.h | 2 | ||||
-rw-r--r-- | bfd/i386linux.c | 6 | ||||
-rw-r--r-- | bfd/ieee.c | 9 | ||||
-rw-r--r-- | bfd/libecoff.h | 4 | ||||
-rw-r--r-- | bfd/libelf.h | 7 | ||||
-rw-r--r-- | bfd/linker.c | 105 | ||||
-rw-r--r-- | bfd/oasys.c | 3 | ||||
-rw-r--r-- | bfd/peicode.h | 49 | ||||
-rw-r--r-- | bfd/srec.c | 7 | ||||
-rw-r--r-- | bfd/sunos.c | 20 | ||||
-rw-r--r-- | bfd/tekhex.c | 71 | ||||
-rw-r--r-- | bfd/versados.c | 9 |
31 files changed, 1687 insertions, 726 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4181377..17027a8 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +Tue Sep 12 12:14:33 1995 Ian Lance Taylor <ian@cygnus.com> + + Extensive minor changes to avoid various gcc warnings. Also: + * Makefile.in (BFD32_BACKENDS): Remove coff-arm.o. + * archures.c (bfd_arch_info_type): Change mach field from long to + unsigned long. + (bfd_lookup_arch): Change machine parameter from long to unsigned + long. + Mon Sep 11 10:55:47 1995 Ian Lance Taylor <ian@cygnus.com> * sunos.c (sunos_scan_std_relocs): Fix BFD_ASSERT: it's OK to find diff --git a/bfd/Makefile.in b/bfd/Makefile.in index 8d7f967..d01a03d 100644 --- a/bfd/Makefile.in +++ b/bfd/Makefile.in @@ -134,7 +134,6 @@ BFD32_BACKENDS = \ cf-sparclynx.o \ coff-a29k.o \ coff-apollo.o \ - coff-arm.o \ coff-h8300.o \ coff-h8500.o \ coff-i386.o \ diff --git a/bfd/aout-adobe.c b/bfd/aout-adobe.c index 9709423..ee8b780 100644 --- a/bfd/aout-adobe.c +++ b/bfd/aout-adobe.c @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" @@ -27,21 +27,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "aout/stab_gnu.h" #include "libaout.h" /* BFD a.out internal data structures */ -extern bfd_target a_out_adobe_vec; /* Forward decl */ +extern const bfd_target a_out_adobe_vec; /* Forward decl */ -PROTO (static bfd_target *, aout_adobe_callback, (bfd *)); +static const bfd_target *aout_adobe_callback PARAMS ((bfd *)); -PROTO (boolean, aout_32_slurp_symbol_table, (bfd *abfd)); -PROTO (boolean , aout_32_write_syms, ()); -PROTO (static void, aout_adobe_write_section, (bfd *abfd, sec_ptr sect)); +extern boolean aout_32_slurp_symbol_table PARAMS ((bfd *abfd)); +extern boolean aout_32_write_syms PARAMS ((bfd *)); +static void aout_adobe_write_section PARAMS ((bfd *abfd, sec_ptr sect)); /* Swaps the information in an executable header taken from a raw byte stream memory image, into the internal exec_header structure. */ -PROTO(void, aout_adobe_swap_exec_header_in, - (bfd *abfd, - struct external_exec *raw_bytes, - struct internal_exec *execp)); +void aout_adobe_swap_exec_header_in + PARAMS ((bfd *abfd, struct external_exec *raw_bytes, + struct internal_exec *execp)); void aout_adobe_swap_exec_header_in (abfd, raw_bytes, execp) @@ -89,7 +88,7 @@ aout_adobe_swap_exec_header_out (abfd, execp, raw_bytes) } -static bfd_target * +static const bfd_target * aout_adobe_object_p (abfd) bfd *abfd; { @@ -133,7 +132,7 @@ aout_adobe_object_p (abfd) /* Finish up the opening of a b.out file for reading. Fill in all the fields that are not handled by common code. */ -static bfd_target * +static const bfd_target * aout_adobe_callback (abfd) bfd *abfd; { @@ -387,10 +386,10 @@ aout_adobe_write_section (abfd, sect) static boolean aout_adobe_set_section_contents (abfd, section, location, offset, count) bfd *abfd; - sec_ptr section; - unsigned char *location; + asection *section; + PTR location; file_ptr offset; - int count; + bfd_size_type count; { file_ptr section_start; sec_ptr sect; @@ -444,9 +443,11 @@ aout_adobe_set_arch_mach (abfd, arch, machine) enum bfd_architecture arch; unsigned long machine; { - bfd_default_set_arch_mach(abfd, arch, machine); + if (! bfd_default_set_arch_mach (abfd, arch, machine)) + return false; - if (arch == bfd_arch_unknown) /* Unknown machine arch is OK */ + if (arch == bfd_arch_unknown + || arch == bfd_arch_m68k) return true; return false; @@ -471,7 +472,7 @@ aout_adobe_sizeof_headers (ignore_abfd, ignore) ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) #define aout_32_bfd_reloc_type_lookup \ - ((CONST struct reloc_howto_struct *(*) \ + ((reloc_howto_type *(*) \ PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) #define aout_32_set_arch_mach aout_adobe_set_arch_mach @@ -485,8 +486,9 @@ aout_adobe_sizeof_headers (ignore_abfd, ignore) _bfd_generic_link_hash_table_create #define aout_32_bfd_link_add_symbols _bfd_generic_link_add_symbols #define aout_32_bfd_final_link _bfd_generic_final_link +#define aout_32_bfd_link_split_section _bfd_generic_link_split_section -bfd_target a_out_adobe_vec = +const bfd_target a_out_adobe_vec = { "a.out.adobe", /* name */ bfd_target_aout_flavour, diff --git a/bfd/aoutx.h b/bfd/aoutx.h index 506d5ee..64b826e 100644 --- a/bfd/aoutx.h +++ b/bfd/aoutx.h @@ -117,8 +117,7 @@ DESCRIPTION (Just want to make these explicit, so the conditions tested in this file make sense if you're more familiar with a.out than with BFD.) */ -#define KEEPIT flags -#define KEEPITTYPE int +#define KEEPIT udata.i #include <string.h> /* For strchr and friends */ #include "bfd.h" @@ -189,9 +188,9 @@ reloc_howto_type howto_table_ext[] = HOWTO(RELOC_BASE10, 0, 2, 16, false, 0, complain_overflow_bitfield,0,"BASE10", false, 0,0x0000ffff, false), HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"BASE13", false, 0,0x00001fff, false), HOWTO(RELOC_BASE22, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x00000000, false), - HOWTO(RELOC_PC10, 0, 2, 10, false, 0, complain_overflow_bitfield,0,"PC10", false, 0,0x000003ff, false), - HOWTO(RELOC_PC22, 0, 2, 22, false, 0, complain_overflow_bitfield,0,"PC22", false, 0,0x003fffff, false), - HOWTO(RELOC_JMP_TBL,0, 2, 32, false, 0, complain_overflow_bitfield,0,"JMP_TBL", false, 0,0xffffffff, false), + HOWTO(RELOC_PC10, 0, 2, 10, true, 0, complain_overflow_dont,0,"PC10", false, 0,0x000003ff, true), + HOWTO(RELOC_PC22, 10, 2, 22, true, 0, complain_overflow_signed,0,"PC22", false, 0,0x003fffff, true), + HOWTO(RELOC_JMP_TBL,2, 2, 30, true, 0, complain_overflow_signed,0,"JMP_TBL", false, 0,0x3fffffff, false), HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, complain_overflow_bitfield,0,"SEGOFF16", false, 0,0x00000000, false), HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"GLOB_DAT", false, 0,0x00000000, false), HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_SLOT", false, 0,0x00000000, false), @@ -267,7 +266,13 @@ NAME(aout,reloc_type_lookup) (abfd,code) EXT (BFD_RELOC_32_PCREL_S2, 6); EXT (BFD_RELOC_SPARC_WDISP22, 7); EXT (BFD_RELOC_SPARC13, 10); + EXT (BFD_RELOC_SPARC_GOT10, 14); EXT (BFD_RELOC_SPARC_BASE13, 15); + EXT (BFD_RELOC_SPARC_GOT13, 15); + EXT (BFD_RELOC_SPARC_GOT22, 16); + EXT (BFD_RELOC_SPARC_PC10, 17); + EXT (BFD_RELOC_SPARC_PC22, 18); + EXT (BFD_RELOC_SPARC_WPLT30, 19); default: return (reloc_howto_type *) NULL; } else @@ -675,7 +680,10 @@ NAME(aout,machine_type) (arch, machine, unknown) switch (arch) { case bfd_arch_sparc: - if (machine == 0) arch_flags = M_SPARC; + if (machine == 0 + || machine == bfd_mach_sparc + || machine == bfd_mach_sparc64) + arch_flags = M_SPARC; break; case bfd_arch_m68k: @@ -1873,7 +1881,7 @@ NAME(aout,write_syms) (abfd) != EXTERNAL_NLIST_SIZE) goto error_return; - /* NB: `KEEPIT' currently overlays `flags', so set this only + /* NB: `KEEPIT' currently overlays `udata.p', so set this only here, at the end. */ g->KEEPIT = count; } @@ -1966,7 +1974,7 @@ NAME(aout,swap_std_reloc_out) (abfd, g, natptr) { /* Fill in symbol */ r_extern = 1; - r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT); + r_index = (*(g->sym_ptr_ptr))->KEEPIT; } } @@ -2024,7 +2032,9 @@ NAME(aout,swap_ext_reloc_out) (abfd, g, natptr) r_type = (unsigned int) g->howto->type; - r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma; + r_addend = g->addend; + if ((sym->flags & BSF_SECTION_SYM) != 0) + r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma; /* If this relocation is relative to a symbol then set the r_index to the symbols index, and the r_extern bit. @@ -2033,29 +2043,22 @@ NAME(aout,swap_ext_reloc_out) (abfd, g, natptr) from the abs section, or as a symbol which has an abs value. check for that here. */ - if (bfd_is_com_section (output_section) - || bfd_is_abs_section (output_section) - || bfd_is_und_section (output_section)) - { - if (bfd_abs_section_ptr->symbol == sym) + if (bfd_is_abs_section (bfd_get_section (sym))) { - /* Whoops, looked like an abs symbol, but is really an offset - from the abs section */ - r_index = 0; r_extern = 0; - } - else + r_index = 0; + } + else if ((sym->flags & BSF_SECTION_SYM) == 0) { r_extern = 1; - r_index = stoi((*(g->sym_ptr_ptr))->KEEPIT); + r_index = (*(g->sym_ptr_ptr))->KEEPIT; } - } else - { - /* Just an ordinary section */ - r_extern = 0; - r_index = output_section->target_index; - } + { + /* Just an ordinary section */ + r_extern = 0; + r_index = output_section->target_index; + } /* now the fun stuff */ if (abfd->xvec->header_byteorder_big_p != false) { @@ -2127,7 +2130,7 @@ NAME(aout,swap_ext_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount) asymbol **symbols; bfd_size_type symcount; { - int r_index; + unsigned int r_index; int r_extern; unsigned int r_type; struct aoutdata *su = &(abfd->tdata.aout_data->a); @@ -2180,13 +2183,13 @@ NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount) asymbol **symbols; bfd_size_type symcount; { - int r_index; + unsigned int r_index; int r_extern; unsigned int r_length; int r_pcrel; int r_baserel, r_jmptable, r_relative; struct aoutdata *su = &(abfd->tdata.aout_data->a); - int howto_idx; + unsigned int howto_idx; cache_ptr->address = bfd_h_get_32 (abfd, bytes->r_address); @@ -2219,7 +2222,7 @@ NAME(aout,swap_std_reloc_in) (abfd, bytes, cache_ptr, symbols, symcount) + 16 * r_jmptable + 32 * r_relative; BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std)); cache_ptr->howto = howto_table_std + howto_idx; - BFD_ASSERT (cache_ptr->howto->type != -1); + BFD_ASSERT (cache_ptr->howto->type != (unsigned int) -1); /* Base relative relocs are always against the symbol table, regardless of the setting of r_extern. r_extern just reflects @@ -2636,7 +2639,7 @@ NAME(aout,find_nearest_line) CONST char *main_file_name = NULL; CONST char *current_file_name = NULL; CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */ - bfd_vma high_line_vma = ~0; + bfd_vma low_line_vma = 0; bfd_vma low_func_vma = 0; asymbol *func = 0; *filename_ptr = abfd->filename; @@ -2671,13 +2674,15 @@ NAME(aout,find_nearest_line) case N_DSLINE: case N_BSLINE: - /* We'll keep this if it resolves nearer than the one we have already */ - if (q->symbol.value >= offset && - q->symbol.value < high_line_vma) { - *line_ptr = q->desc; - high_line_vma = q->symbol.value; - line_file_name = current_file_name; - } + /* We'll keep this if it resolves nearer than the one we have + already. */ + if (q->symbol.value >= low_line_vma + && q->symbol.value <= offset) + { + *line_ptr = q->desc; + low_line_vma = q->symbol.value; + line_file_name = current_file_name; + } break; case N_FUN: { @@ -2687,29 +2692,8 @@ NAME(aout,find_nearest_line) low_func_vma = q->symbol.value; func = (asymbol *)q; } - if (*line_ptr && func) { - CONST char *function = func->name; - char *p; - - /* The caller expects a symbol name. We actually have a - function name, without the leading underscore. Put the - underscore back in, so that the caller gets a symbol - name. */ - if (bfd_get_symbol_leading_char (abfd) == '\0') - strncpy (buffer, function, sizeof (buffer) - 1); - else - { - buffer[0] = bfd_get_symbol_leading_char (abfd); - strncpy (buffer + 1, function, sizeof (buffer) - 2); - } - buffer[sizeof(buffer)-1] = 0; - /* Have to remove : stuff */ - p = strchr(buffer,':'); - if (p != NULL) { *p = '\0'; } - *functionname_ptr = buffer; + else if (q->symbol.value > offset) goto done; - - } } break; } @@ -2728,8 +2712,29 @@ NAME(aout,find_nearest_line) *filename_ptr = filename_buffer; } } + if (func) + { + CONST char *function = func->name; + char *p; + + /* The caller expects a symbol name. We actually have a + function name, without the leading underscore. Put the + underscore back in, so that the caller gets a symbol name. */ + if (bfd_get_symbol_leading_char (abfd) == '\0') + strncpy (buffer, function, sizeof (buffer) - 1); + else + { + buffer[0] = bfd_get_symbol_leading_char (abfd); + strncpy (buffer + 1, function, sizeof (buffer) - 2); + } + buffer[sizeof(buffer)-1] = 0; + /* Have to remove : stuff */ + p = strchr(buffer,':'); + if (p != NULL) + *p = '\0'; + *functionname_ptr = buffer; + } return true; - } /*ARGSUSED*/ @@ -3405,6 +3410,9 @@ NAME(aout,final_link) (abfd, info, callback) asection *o; boolean have_link_order_relocs; + if (info->shared) + abfd->flags |= DYNAMIC; + aout_info.info = info; aout_info.output_bfd = abfd; aout_info.contents = NULL; @@ -4324,7 +4332,8 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, boolean (*check_dynamic_reloc) PARAMS ((struct bfd_link_info *, bfd *, asection *, struct aout_link_hash_entry *, - PTR, boolean *)); + PTR, bfd_byte *, boolean *, + bfd_vma *)); bfd *output_bfd; boolean relocateable; struct external_nlist *syms; @@ -4357,12 +4366,9 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, int r_index; int r_extern; int r_pcrel; - int r_baserel; - int r_jmptable; - int r_relative; - int r_length; - int howto_idx; + int r_baserel = 0; reloc_howto_type *howto; + struct aout_link_hash_entry *h = NULL; bfd_vma relocation; bfd_reloc_status_type r; @@ -4371,37 +4377,47 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, #ifdef MY_reloc_howto howto = MY_reloc_howto(input_bfd, rel, r_index, r_extern, r_pcrel); #else - if (input_bfd->xvec->header_byteorder_big_p) - { - r_index = ((rel->r_index[0] << 16) - | (rel->r_index[1] << 8) - | rel->r_index[2]); - r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); - r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); - r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); - r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); - r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); - r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) - >> RELOC_STD_BITS_LENGTH_SH_BIG); - } - else - { - r_index = ((rel->r_index[2] << 16) - | (rel->r_index[1] << 8) - | rel->r_index[0]); - r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); - r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); - r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE)); - r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE)); - r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE)); - r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) - >> RELOC_STD_BITS_LENGTH_SH_LITTLE); - } + { + int r_jmptable; + int r_relative; + int r_length; + unsigned int howto_idx; + + if (input_bfd->xvec->header_byteorder_big_p) + { + r_index = ((rel->r_index[0] << 16) + | (rel->r_index[1] << 8) + | rel->r_index[2]); + r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG)); + r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_BIG)); + r_baserel = (0 != (rel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG)); + r_jmptable= (0 != (rel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG)); + r_relative= (0 != (rel->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG)); + r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) + >> RELOC_STD_BITS_LENGTH_SH_BIG); + } + else + { + r_index = ((rel->r_index[2] << 16) + | (rel->r_index[1] << 8) + | rel->r_index[0]); + r_extern = (0 != (rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE)); + r_pcrel = (0 != (rel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE)); + r_baserel = (0 != (rel->r_type[0] + & RELOC_STD_BITS_BASEREL_LITTLE)); + r_jmptable= (0 != (rel->r_type[0] + & RELOC_STD_BITS_JMPTABLE_LITTLE)); + r_relative= (0 != (rel->r_type[0] + & RELOC_STD_BITS_RELATIVE_LITTLE)); + r_length = ((rel->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) + >> RELOC_STD_BITS_LENGTH_SH_LITTLE); + } - howto_idx = r_length + 4 * r_pcrel + 8 * r_baserel - + 16 * r_jmptable + 32 * r_relative; - BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std)); - howto = howto_table_std + howto_idx; + howto_idx = (r_length + 4 * r_pcrel + 8 * r_baserel + + 16 * r_jmptable + 32 * r_relative); + BFD_ASSERT (howto_idx < TABLE_SIZE (howto_table_std)); + howto = howto_table_std + howto_idx; + } #endif if (relocateable) @@ -4410,8 +4426,6 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, modify the reloc accordingly. */ if (r_extern) { - struct aout_link_hash_entry *h; - /* If we know the symbol this relocation is against, convert it into a relocation against a section. This is what the native linker does. */ @@ -4539,26 +4553,15 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, } else { + boolean hundef; + /* We are generating an executable, and must do a full relocation. */ + hundef = false; if (r_extern) { - struct aout_link_hash_entry *h; - h = sym_hashes[r_index]; - if (check_dynamic_reloc != NULL) - { - boolean skip; - - if (! ((*check_dynamic_reloc) - (finfo->info, input_bfd, input_section, h, - (PTR) rel, &skip))) - return false; - if (skip) - continue; - } - if (h != (struct aout_link_hash_entry *) NULL && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)) @@ -4572,13 +4575,7 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, relocation = 0; else { - const char *name; - - name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); - if (! ((*finfo->info->callbacks->undefined_symbol) - (finfo->info, name, input_bfd, input_section, - r_addr))) - return false; + hundef = true; relocation = 0; } } @@ -4594,6 +4591,31 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs, relocation += input_section->vma; } + if (check_dynamic_reloc != NULL) + { + boolean skip; + + if (! ((*check_dynamic_reloc) + (finfo->info, input_bfd, input_section, h, + (PTR) rel, contents, &skip, &relocation))) + return false; + if (skip) + continue; + } + + /* Now warn if a global symbol is undefined. We could not + do this earlier, because check_dynamic_reloc might want + to skip this reloc. */ + if (hundef && ! finfo->info->shared && ! r_baserel) + { + const char *name; + + name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); + if (! ((*finfo->info->callbacks->undefined_symbol) + (finfo->info, name, input_bfd, input_section, r_addr))) + return false; + } + r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, r_addr, relocation, @@ -4649,7 +4671,8 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, boolean (*check_dynamic_reloc) PARAMS ((struct bfd_link_info *, bfd *, asection *, struct aout_link_hash_entry *, - PTR, boolean *)); + PTR, bfd_byte *, boolean *, + bfd_vma *)); bfd *output_bfd; boolean relocateable; struct external_nlist *syms; @@ -4681,8 +4704,10 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, bfd_vma r_addr; int r_index; int r_extern; - int r_type; + unsigned int r_type; bfd_vma r_addend; + struct aout_link_hash_entry *h = NULL; + asection *r_section = NULL; bfd_vma relocation; r_addr = GET_SWORD (input_bfd, rel->r_address); @@ -4708,8 +4733,7 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, r_addend = GET_SWORD (input_bfd, rel->r_addend); - BFD_ASSERT (r_type >= 0 - && r_type < TABLE_SIZE (howto_table_ext)); + BFD_ASSERT (r_type < TABLE_SIZE (howto_table_ext)); if (relocateable) { @@ -4717,8 +4741,6 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, modify the reloc accordingly. */ if (r_extern) { - struct aout_link_hash_entry *h; - /* If we know the symbol this relocation is against, convert it into a relocation against a section. This is what the native linker does. */ @@ -4823,14 +4845,12 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, } else { - asection *section; - /* This is a relocation against a section. We must adjust by the amount that the section moved. */ - section = aout_reloc_index_to_section (input_bfd, r_index); - relocation = (section->output_section->vma - + section->output_offset - - section->vma); + r_section = aout_reloc_index_to_section (input_bfd, r_index); + relocation = (r_section->output_section->vma + + r_section->output_offset + - r_section->vma); /* If this is a PC relative reloc, then the addend is the difference in VMA between the destination and the @@ -4857,28 +4877,16 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, } else { + boolean hundef; bfd_reloc_status_type r; /* We are generating an executable, and must do a full relocation. */ + hundef = false; if (r_extern) { - struct aout_link_hash_entry *h; - h = sym_hashes[r_index]; - if (check_dynamic_reloc != NULL) - { - boolean skip; - - if (! ((*check_dynamic_reloc) - (finfo->info, input_bfd, input_section, h, - (PTR) rel, &skip))) - return false; - if (skip) - continue; - } - if (h != (struct aout_link_hash_entry *) NULL && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)) @@ -4892,21 +4900,43 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, relocation = 0; else { - const char *name; - - name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); - if (! ((*finfo->info->callbacks->undefined_symbol) - (finfo->info, name, input_bfd, input_section, - r_addr))) - return false; + hundef = true; relocation = 0; } } + else if (r_type == RELOC_BASE10 + || r_type == RELOC_BASE13 + || r_type == RELOC_BASE22) + { + struct external_nlist *sym; + int type; + + /* For base relative relocs, r_index is always an index + into the symbol table, even if r_extern is 0. */ + sym = syms + r_index; + type = bfd_h_get_8 (input_bfd, sym->e_type); + if ((type & N_TYPE) == N_TEXT + || type == N_WEAKT) + r_section = obj_textsec (input_bfd); + else if ((type & N_TYPE) == N_DATA + || type == N_WEAKD) + r_section = obj_datasec (input_bfd); + else if ((type & N_TYPE) == N_BSS + || type == N_WEAKB) + r_section = obj_bsssec (input_bfd); + else if ((type & N_TYPE) == N_ABS + || type == N_WEAKA) + r_section = bfd_abs_section_ptr; + else + abort (); + relocation = (r_section->output_section->vma + + r_section->output_offset + + (GET_WORD (input_bfd, sym->e_value) + - r_section->vma)); + } else { - asection *section; - - section = aout_reloc_index_to_section (input_bfd, r_index); + r_section = aout_reloc_index_to_section (input_bfd, r_index); /* If this is a PC relative reloc, then R_ADDEND is the difference between the two vmas, or @@ -4934,13 +4964,42 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, RELOCATION to the change in the destination VMA, or new_dest_sec - old_dest_sec */ - relocation = (section->output_section->vma - + section->output_offset - - section->vma); + relocation = (r_section->output_section->vma + + r_section->output_offset + - r_section->vma); if (howto_table_ext[r_type].pc_relative) relocation += input_section->vma; } + if (check_dynamic_reloc != NULL) + { + boolean skip; + + if (! ((*check_dynamic_reloc) + (finfo->info, input_bfd, input_section, h, + (PTR) rel, contents, &skip, &relocation))) + return false; + if (skip) + continue; + } + + /* Now warn if a global symbol is undefined. We could not + do this earlier, because check_dynamic_reloc might want + to skip this reloc. */ + if (hundef + && ! finfo->info->shared + && r_type != RELOC_BASE10 + && r_type != RELOC_BASE13 + && r_type != RELOC_BASE22) + { + const char *name; + + name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); + if (! ((*finfo->info->callbacks->undefined_symbol) + (finfo->info, name, input_bfd, input_section, r_addr))) + return false; + } + r = _bfd_final_link_relocate (howto_table_ext + r_type, input_bfd, input_section, contents, r_addr, relocation, @@ -4956,7 +5015,10 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs, { const char *name; - if (r_extern) + if (r_extern + || r_type == RELOC_BASE10 + || r_type == RELOC_BASE13 + || r_type == RELOC_BASE22) name = strings + GET_WORD (input_bfd, syms[r_index].e_strx); else @@ -5059,48 +5121,51 @@ aout_link_reloc_link_order (finfo, o, p) if (obj_reloc_entry_size (finfo->output_bfd) == RELOC_STD_SIZE) { - int r_pcrel; - int r_baserel; - int r_jmptable; - int r_relative; - int r_length; - #ifdef MY_put_reloc - MY_put_reloc(finfo->output_bfd, r_extern, r_index, p->offset, howto, &srel); + MY_put_reloc(finfo->output_bfd, r_extern, r_index, p->offset, howto, + &srel); #else - r_pcrel = howto->pc_relative; - r_baserel = (howto->type & 8) != 0; - r_jmptable = (howto->type & 16) != 0; - r_relative = (howto->type & 32) != 0; - r_length = howto->size; - - PUT_WORD (finfo->output_bfd, p->offset, srel.r_address); - if (finfo->output_bfd->xvec->header_byteorder_big_p) - { - srel.r_index[0] = r_index >> 16; - srel.r_index[1] = r_index >> 8; - srel.r_index[2] = r_index; - srel.r_type[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 - { - srel.r_index[2] = r_index >> 16; - srel.r_index[1] = r_index >> 8; - srel.r_index[0] = r_index; - srel.r_type[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)); - } + { + int r_pcrel; + int r_baserel; + int r_jmptable; + int r_relative; + int r_length; + + r_pcrel = howto->pc_relative; + r_baserel = (howto->type & 8) != 0; + r_jmptable = (howto->type & 16) != 0; + r_relative = (howto->type & 32) != 0; + r_length = howto->size; + + PUT_WORD (finfo->output_bfd, p->offset, srel.r_address); + if (finfo->output_bfd->xvec->header_byteorder_big_p) + { + srel.r_index[0] = r_index >> 16; + srel.r_index[1] = r_index >> 8; + srel.r_index[2] = r_index; + srel.r_type[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 + { + srel.r_index[2] = r_index >> 16; + srel.r_index[1] = r_index >> 8; + srel.r_index[0] = r_index; + srel.r_type[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)); + } + } #endif rel_ptr = (PTR) &srel; diff --git a/bfd/archive.c b/bfd/archive.c index 44cad84..fbf5bec 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* @setfilename archive-info @@ -677,6 +677,40 @@ bfd_generic_archive_p (abfd) return NULL; } + if (bfd_has_map (abfd) && abfd->target_defaulted) + { + bfd *first; + + /* This archive has a map, so we may presume that the contents + are object files. Make sure that the first file in the + archive can be recognized as an object file for this target. + If not, assume that this is the wrong format. + + This is done because any normal format will recognize any + normal archive, regardless of the format of the object files. + We do accept an empty archive. */ + + first = bfd_openr_next_archived_file (abfd, (bfd *) NULL); + if (first != NULL) + { + first->target_defaulted = false; + if (! bfd_check_format (first, bfd_object)) + { + bfd_error_type err; + + err = bfd_get_error (); + (void) bfd_close (first); + bfd_release (abfd, bfd_ardata (abfd)); + abfd->tdata.aout_ar_data = NULL; + bfd_set_error (err); + return NULL; + } + + /* We ought to close first here, but we can't, because we + have no way to remove it from the archive cache. FIXME. */ + } + } + return abfd->xvec; } @@ -1450,9 +1484,9 @@ bfd_dont_truncate_arname (abfd, pathname, arhdr) intel's release is out the door. */ struct ar_hdr *hdr = (struct ar_hdr *) arhdr; - int length; + size_t length; const char *filename; - int maxlen = ar_maxnamelen (abfd); + size_t maxlen = ar_maxnamelen (abfd); if ((bfd_get_file_flags (abfd) & BFD_TRADITIONAL_FORMAT) != 0) { @@ -1871,7 +1905,7 @@ bsd_write_armap (arch, elength, map, orl_count, stridx) bfd *current = arch->archive_head; bfd *last_elt = current; /* last element arch seen */ bfd_byte temp[4]; - int count; + unsigned int count; struct ar_hdr hdr; struct stat statbuf; unsigned int i; @@ -1957,7 +1991,7 @@ _bfd_archive_bsd_update_armap_timestamp (arch) { struct stat archstat; struct ar_hdr hdr; - int i; + unsigned int i; /* Flush writes, get last-write timestamp from file, and compare it to the timestamp IN the file. */ @@ -2024,7 +2058,7 @@ coff_write_armap (arch, elength, map, symbol_count, stridx) unsigned int mapsize = stringsize + ranlibsize; file_ptr archive_member_file_ptr; bfd *current = arch->archive_head; - int count; + unsigned int count; struct ar_hdr hdr; unsigned int i; int padit = mapsize & 1; diff --git a/bfd/archures.c b/bfd/archures.c index 1b8f58e..c045061 100644 --- a/bfd/archures.c +++ b/bfd/archures.c @@ -151,7 +151,7 @@ DESCRIPTION . int bits_per_address; . int bits_per_byte; . enum bfd_architecture arch; -. long mach; +. unsigned long mach; . char *arch_name; . CONST char *printable_name; . unsigned int section_align_power; @@ -732,7 +732,7 @@ SYNOPSIS bfd_arch_info_type *bfd_lookup_arch (enum bfd_architecture arch, - long machine); + unsigned long machine); DESCRIPTION Look for the architecure info structure which matches the @@ -744,7 +744,7 @@ DESCRIPTION bfd_arch_info_type * bfd_lookup_arch (arch, machine) enum bfd_architecture arch; - long machine; + unsigned long machine; { bfd_arch_info_type *ap; bfd_check_init(); diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 62858a5..caccc84 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1078,7 +1078,7 @@ typedef struct bfd_arch_info int bits_per_address; int bits_per_byte; enum bfd_architecture arch; - long mach; + unsigned long mach; char *arch_name; CONST char *printable_name; unsigned int section_align_power; @@ -1132,7 +1132,7 @@ bfd_arch_info_type * bfd_lookup_arch PARAMS ((enum bfd_architecture arch, - long machine)); + unsigned long machine)); CONST char * bfd_printable_arch_mach @@ -1,5 +1,5 @@ /* BFD back-end for Intel 960 b.out binaries. - Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. + Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Written by Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" @@ -41,7 +41,7 @@ static bfd_reloc_status_type calljx_callback asection *)); static bfd_reloc_status_type callj_callback PARAMS ((bfd *, struct bfd_link_info *, arelent *, PTR data, - unsigned int srcidx, unsigned int dstidx, asection *)); + unsigned int srcidx, unsigned int dstidx, asection *, boolean)); static bfd_vma get_value PARAMS ((arelent *, struct bfd_link_info *, asection *)); static int abs32code PARAMS ((bfd *, asection *, arelent *, @@ -330,7 +330,7 @@ calljx_callback (abfd, link_info, reloc_entry, src, dst, input_section) /* Magic to turn call into callj */ static bfd_reloc_status_type callj_callback (abfd, link_info, reloc_entry, data, srcidx, dstidx, - input_section) + input_section, shrinking) bfd *abfd; struct bfd_link_info *link_info; arelent *reloc_entry; @@ -338,6 +338,7 @@ callj_callback (abfd, link_info, reloc_entry, data, srcidx, dstidx, unsigned int srcidx; unsigned int dstidx; asection *input_section; + boolean shrinking; { int word = bfd_get_32 (abfd, (bfd_byte *) data + srcidx); asymbol *symbol_in = *(reloc_entry->sym_ptr_ptr); @@ -368,12 +369,21 @@ callj_callback (abfd, link_info, reloc_entry, data, srcidx, dstidx, - output_addr (input_section)) & BAL_MASK); } + else if ((symbol->symbol.flags & BSF_SECTION_SYM) != 0) + { + /* A callj against a symbol in the same section is a fully + resolved relative call. We don't need to do anything here. + If the symbol is not in the same section, I'm not sure what + to do; fortunately, this case will probably never arise. */ + BFD_ASSERT (! shrinking); + BFD_ASSERT (symbol->symbol.section == input_section); + } else { word = CALL | (((word & BAL_MASK) + value + reloc_entry->addend - - dstidx + - (shrinking ? dstidx : 0) - output_addr (input_section)) & BAL_MASK); } @@ -425,7 +435,7 @@ static reloc_howto_type howto_done_align_table[] = { HOWTO (ALIGNDONE, 0xf, 0xf, 0, false, 0, complain_overflow_dont, 0, "donealign128", false, 0, 0, false), }; -static const reloc_howto_type * +static reloc_howto_type * b_out_bfd_reloc_type_lookup (abfd, code) bfd *abfd; bfd_reloc_code_real_type code; @@ -479,6 +489,11 @@ b_out_slurp_reloc_table (abfd, asect, symbols) goto doit; } + if (asect == obj_bsssec (abfd)) { + reloc_size = 0; + goto doit; + } + bfd_set_error (bfd_error_invalid_operation); return false; @@ -494,14 +509,16 @@ b_out_slurp_reloc_table (abfd, asect, symbols) } reloc_cache = (arelent *) malloc ((count+1) * sizeof (arelent)); if (!reloc_cache) { - free ((char*)relocs); + if (relocs != NULL) + free ((char*)relocs); bfd_set_error (bfd_error_no_memory); return false; } if (bfd_read ((PTR) relocs, 1, reloc_size, abfd) != reloc_size) { free (reloc_cache); - free (relocs); + if (relocs != NULL) + free (relocs); return false; } @@ -593,7 +610,7 @@ b_out_slurp_reloc_table (abfd, asect, symbols) if (raw[7] & pcrel_mask) { cache_ptr->howto = &howto_align_table[(raw[7] >> length_shift) & 3]; - cache_ptr->sym_ptr_ptr = &bfd_abs_symbol; + cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; } else { @@ -657,7 +674,8 @@ b_out_slurp_reloc_table (abfd, asect, symbols) } - free (relocs); + if (relocs != NULL) + free (relocs); asect->relocation = reloc_cache; asect->reloc_count = count; @@ -758,11 +776,11 @@ b_out_squirt_out_relocs (abfd, section) if (r_idx != 0) /* already mucked with r_extern, r_idx */; else if (bfd_is_com_section (output_section) - || output_section == &bfd_abs_section - || output_section == &bfd_und_section) + || bfd_is_abs_section (output_section) + || bfd_is_und_section (output_section)) { - if (bfd_abs_section.symbol == sym) + if (bfd_abs_section_ptr->symbol == sym) { /* Whoops, looked like an abs symbol, but is really an offset from the abs section */ @@ -814,17 +832,30 @@ b_out_canonicalize_reloc (abfd, section, relptr, symbols) arelent **relptr; asymbol **symbols; { - arelent *tblptr = section->relocation; - unsigned int count = 0; + arelent *tblptr; + unsigned int count; - if (!(tblptr || b_out_slurp_reloc_table (abfd, section, symbols))) - return -1; - tblptr = section->relocation; + if ((section->flags & SEC_CONSTRUCTOR) != 0) + { + arelent_chain *chain = section->constructor_chain; + for (count = 0; count < section->reloc_count; count++) + { + *relptr++ = &chain->relent; + chain = chain->next; + } + } + else + { + if (section->relocation == NULL + && ! b_out_slurp_reloc_table (abfd, section, symbols)) + return -1; - for (; count++ < section->reloc_count;) - *relptr++ = tblptr++; + tblptr = section->relocation; + for (count = 0; count++ < section->reloc_count;) + *relptr++ = tblptr++; + } - *relptr = 0; + *relptr = NULL; return section->reloc_count; } @@ -839,6 +870,9 @@ b_out_get_reloc_upper_bound (abfd, asect) return -1; } + if (asect->flags & SEC_CONSTRUCTOR) + return sizeof (arelent *) * (asect->reloc_count + 1); + if (asect == obj_datasec (abfd)) return (sizeof (arelent *) * ((exec_hdr(abfd)->a_drsize / sizeof (struct relocation_info)) @@ -859,10 +893,10 @@ b_out_get_reloc_upper_bound (abfd, asect) static boolean b_out_set_section_contents (abfd, section, location, offset, count) bfd *abfd; - sec_ptr section; - unsigned char *location; + asection *section; + PTR location; file_ptr offset; - int count; + bfd_size_type count; { if (abfd->output_has_begun == false) { /* set by bfd.c handler */ @@ -935,7 +969,7 @@ get_value (reloc, link_info, input_section) base of the section. To relocate, we find where the section will live in the output and add that in */ - if (symbol->section == &bfd_und_section) + if (bfd_is_und_section (symbol->section)) { struct bfd_link_hash_entry *h; @@ -947,7 +981,8 @@ get_value (reloc, link_info, input_section) h = bfd_link_hash_lookup (link_info->hash, bfd_asymbol_name (symbol), false, false, true); if (h != (struct bfd_link_hash_entry *) NULL - && h->type == bfd_link_hash_defined) + && (h->type == bfd_link_hash_defined + || h->type == bfd_link_hash_defweak)) value = h->u.def.value + output_addr (h->u.def.section); else if (h != (struct bfd_link_hash_entry *) NULL && h->type == bfd_link_hash_common) @@ -995,11 +1030,11 @@ perform_slip (abfd, slip, input_section, value) if (p->value > value) { p->value -=slip; - if (p->udata != NULL) + if (p->udata.p != NULL) { struct generic_link_hash_entry *h; - h = (struct generic_link_hash_entry *) p->udata; + h = (struct generic_link_hash_entry *) p->udata.p; BFD_ASSERT (h->root.type == bfd_link_hash_defined); h->root.u.def.value -= slip; BFD_ASSERT (h->root.u.def.value == p->value); @@ -1275,7 +1310,7 @@ b_out_bfd_get_relocated_section_contents (in_abfd, link_info, link_order, break; case CALLJ: callj_callback (in_abfd, link_info, reloc, data, src_address, - dst_address, input_section); + dst_address, input_section, false); src_address+=4; dst_address+=4; break; @@ -1290,7 +1325,8 @@ b_out_bfd_get_relocated_section_contents (in_abfd, link_info, link_order, /* This used to be a callx, but we've found out that a callj will reach, so do the right thing. */ callj_callback (in_abfd, link_info, reloc, data, - src_address + 4, dst_address, input_section); + src_address + 4, dst_address, input_section, + true); dst_address+=4; src_address+=8; break; @@ -1358,6 +1394,8 @@ b_out_bfd_get_relocated_section_contents (in_abfd, link_info, link_order, #define b_out_bfd_link_hash_table_create _bfd_generic_link_hash_table_create #define b_out_bfd_link_add_symbols _bfd_generic_link_add_symbols #define b_out_bfd_final_link _bfd_generic_final_link +#define b_out_bfd_link_split_section _bfd_generic_link_split_section + const bfd_target b_out_vec_big_host = { diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 0b1ba78..51bfd18 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -23,7 +23,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* This port currently only handles reading object files, except when compiled on an RS/6000 host. -- no archive support, no core files. @@ -44,6 +44,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* The main body of code is in coffcode.h. */ +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) + /* The XCOFF reloc table. Actually, XCOFF relocations specify the bitsize and whether they are signed or not, along with a conventional type. This table is for the types, which are used for @@ -410,7 +412,7 @@ rs6000coff_rtype2howto (relent, internal) relocation, as well as indicating whether it is signed or not. Doublecheck that the relocation information gathered from the type matches this information. */ - if (relent->howto->bitsize != (internal->r_size & 0x1f) + 1) + if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1) abort (); #if 0 if ((internal->r_size & 0x80) != 0 @@ -422,10 +424,10 @@ rs6000coff_rtype2howto (relent, internal) #define coff_bfd_reloc_type_lookup rs6000coff_reloc_type_lookup -static const struct reloc_howto_struct *rs6000coff_reloc_type_lookup +static reloc_howto_type *rs6000coff_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_code_real_type)); -static const struct reloc_howto_struct * +static reloc_howto_type * rs6000coff_reloc_type_lookup (abfd, code) bfd *abfd; bfd_reloc_code_real_type code; @@ -471,7 +473,10 @@ rs6000coff_reloc_type_lookup (abfd, code) #define rs6000coff_slurp_armap bfd_slurp_coff_armap #define rs6000coff_slurp_extended_name_table _bfd_slurp_extended_name_table +#define rs6000coff_construct_extended_name_table \ + _bfd_archive_coff_construct_extended_name_table #define rs6000coff_truncate_arname bfd_dont_truncate_arname +#define rs6000coff_update_armap_timestamp bfd_true #undef coff_mkarchive #define coff_mkarchive rs6000coff_mkarchive @@ -620,7 +625,7 @@ rs6000coff_openr_next_archived_file(archive, last_file) } -static bfd_target * +static const bfd_target * rs6000coff_archive_p (abfd) bfd *abfd; { @@ -710,10 +715,10 @@ rs6000coff_write_armap (arch, elength, map, orl_count, stridx) #define coff_core_file_matches_executable_p \ _bfd_nocore_core_file_matches_executable_p -#ifdef HOST_AIX +#ifdef AIX_CORE #undef CORE_FILE_P #define CORE_FILE_P rs6000coff_core_p -extern bfd_target * rs6000coff_core_p (); +extern const bfd_target * rs6000coff_core_p (); extern boolean rs6000coff_get_section_contents (); extern boolean rs6000coff_core_file_matches_executable_p (); @@ -723,13 +728,13 @@ extern boolean rs6000coff_core_file_matches_executable_p (); #undef coff_get_section_contents #define coff_get_section_contents rs6000coff_get_section_contents -#endif /* HOST_AIX */ +#endif /* AIX_CORE */ -#ifdef HOST_LYNX +#ifdef LYNX_CORE #undef CORE_FILE_P #define CORE_FILE_P lynx_core_file_p -extern bfd_target *lynx_core_file_p PARAMS ((bfd *abfd)); +extern const bfd_target *lynx_core_file_p PARAMS ((bfd *abfd)); extern boolean lynx_core_file_matches_executable_p PARAMS ((bfd *core_bfd, bfd *exec_bfd)); @@ -744,11 +749,11 @@ extern int lynx_core_file_failing_signal PARAMS ((bfd *abfd)); #undef coff_core_file_failing_signal #define coff_core_file_failing_signal lynx_core_file_failing_signal -#endif /* HOST_LYNX */ +#endif /* LYNX_CORE */ /* The transfer vector that leads the outside world to all of the above. */ -bfd_target rs6000coff_vec = +const bfd_target rs6000coff_vec = { "aixcoff-rs6000", /* name */ bfd_target_coff_flavour, @@ -791,6 +796,7 @@ bfd_target rs6000coff_vec = BFD_JUMP_TABLE_RELOCS (coff), BFD_JUMP_TABLE_WRITE (coff), BFD_JUMP_TABLE_LINK (coff), + BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), COFF_SWAP_TABLE, }; diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c index bc66663..7a3e938 100644 --- a/bfd/coff-sh.c +++ b/bfd/coff-sh.c @@ -368,7 +368,7 @@ sh_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, sym_value -= 0x1000; insn = (insn & 0xf000) | (sym_value & 0xfff); bfd_put_16 (abfd, insn, hit_data); - if (sym_value < -0x1000 || sym_value >= 0x1000) + if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000) return bfd_reloc_overflow; break; default: @@ -624,8 +624,7 @@ sh_relax_section (abfd, sec, link_info, again) if (coff_section_data (abfd, sec) == NULL) { sec->used_by_bfd = - ((struct coff_section_tdata *) - bfd_zalloc (abfd, sizeof (struct coff_section_tdata))); + ((PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata))); if (sec->used_by_bfd == NULL) { bfd_set_error (bfd_error_no_memory); @@ -748,8 +747,7 @@ sh_relax_section (abfd, sec, link_info, again) if (coff_section_data (abfd, sec) == NULL) { sec->used_by_bfd = - ((struct coff_section_tdata *) - bfd_zalloc (abfd, sizeof (struct coff_section_tdata))); + ((PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata))); if (sec->used_by_bfd == NULL) { bfd_set_error (bfd_error_no_memory); @@ -877,8 +875,8 @@ sh_relax_delete_bytes (abfd, sec, addr, count) &sym); if (sym.n_sclass != C_EXT && sym.n_scnum == sec->target_index - && (sym.n_value < addr - || sym.n_value >= toaddr)) + && ((bfd_vma) sym.n_value <= addr + || (bfd_vma) sym.n_value >= toaddr)) { bfd_vma val; @@ -1080,8 +1078,8 @@ sh_relax_delete_bytes (abfd, sec, addr, count) &sym); if (sym.n_sclass != C_EXT && sym.n_scnum == sec->target_index - && (sym.n_value < addr - || sym.n_value >= toaddr)) + && ((bfd_vma) sym.n_value <= addr + || (bfd_vma) sym.n_value >= toaddr)) { bfd_vma val; @@ -1146,8 +1144,8 @@ sh_relax_delete_bytes (abfd, sec, addr, count) bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &isym); if (isym.n_scnum == sec->target_index - && isym.n_value >= addr - && isym.n_value < toaddr) + && (bfd_vma) isym.n_value > addr + && (bfd_vma) isym.n_value < toaddr) { isym.n_value -= count; diff --git a/bfd/coff-sparc.c b/bfd/coff-sparc.c index 273e30b..1159c3a 100644 --- a/bfd/coff-sparc.c +++ b/bfd/coff-sparc.c @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" @@ -26,6 +26,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "coff/internal.h" #include "libcoff.h" +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) + #define BADMAG(x) ((x).f_magic != SPARCMAGIC && (x).f_magic != LYNXCOFFMAGIC) /* The page size is a guess based on ELF. */ @@ -156,12 +158,12 @@ static CONST struct coff_reloc_map sparc_reloc_map[] = /* { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */ }; -static CONST struct reloc_howto_struct * +static reloc_howto_type * coff_sparc_reloc_type_lookup (abfd, code) bfd *abfd; bfd_reloc_code_real_type code; { - int i; + unsigned int i; for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct coff_reloc_map); i++) { if (sparc_reloc_map[i].bfd_reloc_val == code) @@ -184,8 +186,9 @@ rtype2howto (cache_ptr, dst) #define SWAP_IN_RELOC_OFFSET bfd_h_get_32 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32 -/* This is just like the standard one, except for the addition of the - last line, the adjustment of the addend. */ +/* This is just like the standard one, except that we don't set up an + addend for relocs against global symbols (otherwise linking objects + created by -r fails), and we add in the reloc offset at the end. */ #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \ { \ coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \ @@ -198,7 +201,8 @@ rtype2howto (cache_ptr, dst) && coffsym->native->u.syment.n_scnum == 0) \ cache_ptr->addend = 0; \ else if (ptr && bfd_asymbol_bfd (ptr) == abfd \ - && ptr->section != (asection *) NULL) \ + && ptr->section != (asection *) NULL \ + && (ptr->flags & BSF_GLOBAL) == 0) \ cache_ptr->addend = - (ptr->section->vma + ptr->value); \ else \ cache_ptr->addend = 0; \ @@ -220,7 +224,7 @@ rtype2howto (cache_ptr, dst) #include "coffcode.h" -bfd_target +const bfd_target #ifdef TARGET_SYM TARGET_SYM = #else @@ -238,10 +242,10 @@ bfd_target (HAS_RELOC | EXEC_P | /* object flags */ HAS_LINENO | HAS_DEBUG | - HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), + HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ - 0, /* leading underscore */ + '_', /* leading underscore */ '/', /* ar_pad_char */ 15, /* ar_max_namelen */ diff --git a/bfd/coff-w65.c b/bfd/coff-w65.c new file mode 100644 index 0000000..7f92cb7 --- /dev/null +++ b/bfd/coff-w65.c @@ -0,0 +1,447 @@ +/* BFD back-end for WDC 65816 COFF binaries. + Copyright 1995 Free Software Foundation, Inc. + Written by Steve Chamberlain, <sac@cygnus.com>. + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "obstack.h" +#include "libbfd.h" +#include "bfdlink.h" +#include "coff/w65.h" +#include "coff/internal.h" +#include "libcoff.h" + +#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1) +static reloc_howto_type howto_table[] = +{ + HOWTO (R_W65_ABS8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "abs8", true, 0x000000ff, 0x000000ff, false), + HOWTO (R_W65_ABS16, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, "abs16", true, 0x0000ffff, 0x0000ffff, false), + HOWTO (R_W65_ABS24, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "abs24", true, 0x00ffffff, 0x00ffffff, false), + HOWTO (R_W65_ABS8S8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, ">abs8", true, 0x000000ff, 0x000000ff, false), + HOWTO (R_W65_ABS8S16, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "^abs8", true, 0x000000ff, 0x000000ff, false), + HOWTO (R_W65_ABS16S8, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, ">abs16", true, 0x0000ffff, 0x0000ffff, false), + HOWTO (R_W65_ABS16S16,1, 0, 16, false, 0, complain_overflow_bitfield, 0, "^abs16", true, 0x0000ffff, 0x0000ffff, false), + HOWTO (R_W65_PCR8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "pcrel8", true, 0x000000ff, 0x000000ff, true), + HOWTO (R_W65_PCR16, 1, 0, 16, false, 0, complain_overflow_bitfield, 0, "pcrel16", true, 0x0000ffff, 0x0000ffff, true), + HOWTO (R_W65_DP, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "dp", true, 0x000000ff, 0x000000ff, false), + +}; + + +/* Turn a howto into a reloc number */ + +#define SELECT_RELOC(x,howto) \ + { x.r_type = select_reloc(howto); } + +#define BADMAG(x) (W65BADMAG(x)) +#define W65 1 /* Customize coffcode.h */ +#define __A_MAGIC_SET__ + + +/* Code to swap in the reloc */ +#define SWAP_IN_RELOC_OFFSET bfd_h_get_32 +#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32 +#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ + dst->r_stuff[0] = 'S'; \ + dst->r_stuff[1] = 'C'; + + +static int +select_reloc (howto) + reloc_howto_type *howto; +{ + return howto->type ; +} + +/* Code to turn a r_type into a howto ptr, uses the above howto table + */ + +static void +rtype2howto (internal, dst) + arelent *internal; + struct internal_reloc *dst; +{ + internal->howto = howto_table + dst->r_type - 1; +} + +#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry) + + +/* Perform any necessaru magic to the addend in a reloc entry */ + + +#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ + cache_ptr->addend = ext_reloc.r_offset; + + +#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ + reloc_processing(relent, reloc, symbols, abfd, section) + +static void +reloc_processing (relent, reloc, symbols, abfd, section) + arelent * relent; + struct internal_reloc *reloc; + asymbol ** symbols; + bfd * abfd; + asection * section; +{ + relent->address = reloc->r_vaddr; + rtype2howto (relent, reloc); + + if (((int) reloc->r_symndx) > 0) + { + relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; + } + else + { + relent->sym_ptr_ptr = (asymbol **)&(bfd_abs_symbol); + } + + + + relent->addend = reloc->r_offset; + + relent->address -= section->vma; + /* relent->section = 0;*/ +} + + +static int +h8300_reloc16_estimate(abfd, input_section, reloc, shrink, link_info) + bfd *abfd; + asection *input_section; + arelent *reloc; + unsigned int shrink; + struct bfd_link_info *link_info; +{ + bfd_vma value; + bfd_vma dot; + bfd_vma gap; + + /* The address of the thing to be relocated will have moved back by + the size of the shrink - but we don't change reloc->address here, + since we need it to know where the relocation lives in the source + uncooked section */ + + /* reloc->address -= shrink; conceptual */ + + bfd_vma address = reloc->address - shrink; + + + switch (reloc->howto->type) + { + case R_MOVB2: + case R_JMP2: + shrink+=2; + break; + + /* Thing is a move one byte */ + case R_MOVB1: + value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); + + if (value >= 0xff00) + { + + /* Change the reloc type from 16bit, possible 8 to 8bit + possible 16 */ + reloc->howto = reloc->howto + 1; + /* The place to relc moves back by one */ + /* This will be two bytes smaller in the long run */ + shrink +=2 ; + bfd_perform_slip(abfd, 2, input_section, address); + } + + break; + /* This is the 24 bit branch which could become an 8 bitter, + the relocation points to the first byte of the insn, not the + actual data */ + + case R_JMPL1: + value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); + + dot = input_section->output_section->vma + + input_section->output_offset + address; + + /* See if the address we're looking at within 127 bytes of where + we are, if so then we can use a small branch rather than the + jump we were going to */ + + gap = value - dot ; + + if (-120 < (long)gap && (long)gap < 120 ) + { + + /* Change the reloc type from 24bit, possible 8 to 8bit + possible 32 */ + reloc->howto = reloc->howto + 1; + /* This will be two bytes smaller in the long run */ + shrink +=2 ; + bfd_perform_slip(abfd, 2, input_section, address); + } + break; + + case R_JMP1: + + value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); + + dot = input_section->output_section->vma + + input_section->output_offset + address; + + /* See if the address we're looking at within 127 bytes of where + we are, if so then we can use a small branch rather than the + jump we were going to */ + + gap = value - (dot - shrink); + + + if (-120 < (long)gap && (long)gap < 120 ) + { + + /* Change the reloc type from 16bit, possible 8 to 8bit + possible 16 */ + reloc->howto = reloc->howto + 1; + /* The place to relc moves back by one */ + + /* This will be two bytes smaller in the long run */ + shrink +=2 ; + bfd_perform_slip(abfd, 2, input_section, address); + } + break; + } + + + return shrink; +} + + +/* First phase of a relaxing link */ + +/* Reloc types + large small + R_MOVB1 R_MOVB2 mov.b with 16bit or 8 bit address + R_JMP1 R_JMP2 jmp or pcrel branch + R_JMPL1 R_JMPL_B8 24jmp or pcrel branch + R_MOVLB1 R_MOVLB2 24 or 8 bit reloc for mov.b + +*/ + +static void +h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, + dst_ptr) + bfd *abfd; + struct bfd_link_info *link_info; + struct bfd_link_order *link_order; + arelent *reloc; + bfd_byte *data; + unsigned int *src_ptr; + unsigned int *dst_ptr; +{ + unsigned int src_address = *src_ptr; + unsigned int dst_address = *dst_ptr; + asection *input_section = link_order->u.indirect.section; + + switch (reloc->howto->type) + { + case R_W65_ABS8: + case R_W65_DP: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + bfd_put_8 (abfd, gap, data + dst_address); + dst_address += 1; + src_address += 1; + } + break; + + case R_W65_ABS8S8: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + gap >>= 8; + bfd_put_8 (abfd, gap, data + dst_address); + dst_address += 1; + src_address += 1; + } + break; + + case R_W65_ABS8S16: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + gap >>=16; + bfd_put_8 (abfd, gap, data + dst_address); + dst_address += 1; + src_address += 1; + } + break; + + case R_W65_ABS16: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + + bfd_put_16 (abfd, gap, data + dst_address); + dst_address += 2; + src_address += 2; + } + break; + case R_W65_ABS16S8: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + gap >>= 8; + bfd_put_16 (abfd, gap, data + dst_address); + dst_address += 2; + src_address += 2; + } + break; + case R_W65_ABS16S16: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + gap >>= 16; + bfd_put_16 (abfd, gap, data + dst_address); + dst_address += 2; + src_address += 2; + } + break; + + case R_W65_ABS24: + { + unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + bfd_put_16 (abfd, gap, data + dst_address); + bfd_put_8 (abfd, gap>>16, data+dst_address+2); + dst_address += 3; + src_address += 3; + } + break; + + case R_W65_PCR8: + { + int gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + bfd_vma dot = link_order->offset + + dst_address + + link_order->u.indirect.section->output_section->vma; + + gap -= dot + 1; + if (gap < -128 || gap > 127) { + if (! ((*link_info->callbacks->reloc_overflow) + (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), + reloc->howto->name, reloc->addend, input_section->owner, + input_section, reloc->address))) + abort(); + } + bfd_put_8 (abfd, gap, data + dst_address); + dst_address += 1; + src_address += 1; + } + break; + + case R_W65_PCR16: + { + bfd_vma gap = bfd_coff_reloc16_get_value (reloc, link_info, + input_section); + bfd_vma dot = link_order->offset + + dst_address + + link_order->u.indirect.section->output_section->vma; + + + /* This wraps within the page, so ignore the relativeness, look at the + high part */ + if ((gap & 0xf0000) != (dot & 0xf0000)) { + if (! ((*link_info->callbacks->reloc_overflow) + (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), + reloc->howto->name, reloc->addend, input_section->owner, + input_section, reloc->address))) + abort(); + } + + gap -= dot + 2; + bfd_put_16 (abfd, gap, data + dst_address); + dst_address += 2; + src_address += 2; + } + break; + default: + printf("ignoring reloc %s\n", reloc->howto->name); + break; + + } + *src_ptr = src_address; + *dst_ptr = dst_address; + +} + +#define coff_reloc16_extra_cases h8300_reloc16_extra_cases +#define coff_reloc16_estimate h8300_reloc16_estimate + +#include "coffcode.h" + + +#undef coff_bfd_get_relocated_section_contents +#undef coff_bfd_relax_section +#define coff_bfd_get_relocated_section_contents \ + bfd_coff_reloc16_get_relocated_section_contents +#define coff_bfd_relax_section bfd_coff_reloc16_relax_section + + + +bfd_target w65_vec = +{ + "coff-w65", /* name */ + bfd_target_coff_flavour, + false, /* data byte order is big */ + false, /* header byte order is big */ + + (HAS_RELOC | EXEC_P | /* object flags */ + HAS_LINENO | HAS_DEBUG | + HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ), + (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ + '_', /* leading char */ + '/', /* ar_pad_char */ + 15, /* ar_max_namelen */ + 1, /* minimum section alignment */ + bfd_getl64, bfd_getl_signed_64, bfd_putl64, + bfd_getl32, bfd_getl_signed_32, bfd_putl32, + bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ + bfd_getl64, bfd_getl_signed_64, bfd_putl64, + bfd_getl32, bfd_getl_signed_32, bfd_putl32, + bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ + + {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ + bfd_generic_archive_p, _bfd_dummy_target}, + {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ + bfd_false}, + {bfd_false, coff_write_object_contents, /* bfd_write_contents */ + _bfd_write_archive_contents, bfd_false}, + + BFD_JUMP_TABLE_GENERIC (coff), + BFD_JUMP_TABLE_COPY (coff), + BFD_JUMP_TABLE_CORE (_bfd_nocore), + BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), + BFD_JUMP_TABLE_SYMBOLS (coff), + BFD_JUMP_TABLE_RELOCS (coff), + BFD_JUMP_TABLE_WRITE (coff), + BFD_JUMP_TABLE_LINK (coff), + BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), + + COFF_SWAP_TABLE, +}; diff --git a/bfd/coffgen.c b/bfd/coffgen.c index f5b2cc0..be94580 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Most of this hacked by Steve Chamberlain, sac@cygnus.com. Split out of coffcode.h by Ian Taylor, ian@cygnus.com. */ @@ -476,7 +476,7 @@ coff_renumber_symbols (bfd_ptr, first_undef) I'm not certain. [raeburn:19920508.1711EST] */ { asymbol **newsyms; - int i; + unsigned int i; newsyms = (asymbol **) bfd_alloc_by_size_t (bfd_ptr, sizeof (asymbol *) @@ -1167,8 +1167,8 @@ static void coff_pointerize_aux (abfd, table_base, type, class, auxent) bfd *abfd; combined_entry_type *table_base; - int type; - int class; + unsigned int type; + unsigned int class; combined_entry_type *auxent; { /* Don't bother if this is a file or a section */ @@ -1198,39 +1198,6 @@ coff_pointerize_aux (abfd, table_base, type, class, auxent) } } -static char * -build_string_table (abfd) - bfd *abfd; -{ - char string_table_size_buffer[STRING_SIZE_SIZE]; - unsigned int string_table_size; - char *string_table; - - /* At this point we should be "seek"'d to the end of the - symbols === the symbol table size. */ - if (bfd_read ((char *) string_table_size_buffer, - sizeof (string_table_size_buffer), - 1, abfd) != sizeof (string_table_size)) - return (NULL); - -#if STRING_SIZE_SIZE == 4 - string_table_size = bfd_h_get_32 (abfd, (bfd_byte *) string_table_size_buffer); -#else - #error Change bfd_h_get_32 -#endif - - if ((string_table = (PTR) bfd_alloc (abfd, - string_table_size -= STRING_SIZE_SIZE)) - == NULL) - { - bfd_set_error (bfd_error_no_memory); - return (NULL); - } /* on mallocation error */ - if (bfd_read (string_table, string_table_size, 1, abfd) != string_table_size) - return (NULL); - return string_table; -} - /* Allocate space for the ".debug" section, and read it. We did not read the debug section until now, because we didn't want to go to the trouble until someone needed it. */ @@ -1303,6 +1270,122 @@ copy_name (abfd, name, maxlen) return newname; } +/* Read in the external symbols. */ + +boolean +_bfd_coff_get_external_symbols (abfd) + bfd *abfd; +{ + bfd_size_type symesz; + size_t size; + PTR syms; + + if (obj_coff_external_syms (abfd) != NULL) + return true; + + symesz = bfd_coff_symesz (abfd); + + size = obj_raw_syment_count (abfd) * symesz; + + syms = malloc (size); + if (syms == NULL && size != 0) + { + bfd_set_error (bfd_error_no_memory); + return false; + } + + if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 + || bfd_read (syms, size, 1, abfd) != size) + { + if (syms != NULL) + free (syms); + return false; + } + + obj_coff_external_syms (abfd) = syms; + + return true; +} + +/* Read in the external strings. The strings are not loaded until + they are needed. This is because we have no simple way of + detecting a missing string table in an archive. */ + +const char * +_bfd_coff_read_string_table (abfd) + bfd *abfd; +{ + char extstrsize[STRING_SIZE_SIZE]; + size_t strsize; + char *strings; + + if (obj_coff_strings (abfd) != NULL) + return obj_coff_strings (abfd); + + if (bfd_seek (abfd, + (obj_sym_filepos (abfd) + + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd)), + SEEK_SET) != 0) + return NULL; + + if (bfd_read (extstrsize, sizeof extstrsize, 1, abfd) != sizeof extstrsize) + { + if (bfd_get_error () != bfd_error_file_truncated) + return NULL; + + /* There is no string table. */ + strsize = STRING_SIZE_SIZE; + } + else + { +#if STRING_SIZE_SIZE == 4 + strsize = bfd_h_get_32 (abfd, (bfd_byte *) extstrsize); +#else + #error Change bfd_h_get_32 +#endif + } + + strings = malloc (strsize); + if (strings == NULL) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } + + if (bfd_read (strings + STRING_SIZE_SIZE, + strsize - STRING_SIZE_SIZE, 1, abfd) + != strsize - STRING_SIZE_SIZE) + { + free (strings); + return NULL; + } + + obj_coff_strings (abfd) = strings; + + return strings; +} + +/* Free up the external symbols and strings read from a COFF file. */ + +boolean +_bfd_coff_free_symbols (abfd) + bfd *abfd; +{ + if (obj_coff_external_syms (abfd) != NULL + && ! obj_coff_keep_syms (abfd)) + { + free (obj_coff_external_syms (abfd)); + obj_coff_external_syms (abfd) = NULL; + } + if (obj_coff_strings (abfd) != NULL + && ! obj_coff_keep_strings (abfd)) + { + free (obj_coff_strings (abfd)); + obj_coff_strings (abfd) = NULL; + } + return true; +} + /* Read a symbol table into freshly bfd_allocated memory, swap it, and knit the symbol names into a normalized form. By normalized here I mean that all symbols have an n_offset pointer that points to a null- @@ -1317,13 +1400,11 @@ coff_get_normalized_symtab (abfd) combined_entry_type *symbol_ptr; combined_entry_type *internal_end; bfd_size_type symesz; - PTR raw; char *raw_src; char *raw_end; - char *string_table = NULL; + const char *string_table = NULL; char *debug_section = NULL; unsigned long size; - unsigned int raw_size; if (obj_raw_syments (abfd) != NULL) return obj_raw_syments (abfd); @@ -1337,27 +1418,20 @@ coff_get_normalized_symtab (abfd) } internal_end = internal + obj_raw_syment_count (abfd); - symesz = bfd_coff_symesz (abfd); - raw_size = obj_raw_syment_count (abfd) * symesz; - raw = bfd_alloc (abfd, raw_size); - if (raw == NULL && raw_size != 0) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } - - if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) == -1 - || bfd_read (raw, raw_size, 1, abfd) != raw_size) + if (! _bfd_coff_get_external_symbols (abfd)) return NULL; + raw_src = (char *) obj_coff_external_syms (abfd); + /* mark the end of the symbols */ - raw_end = (char *) raw + obj_raw_syment_count (abfd) * symesz; + symesz = bfd_coff_symesz (abfd); + raw_end = (char *) raw_src + obj_raw_syment_count (abfd) * symesz; /* FIXME SOMEDAY. A string table size of zero is very weird, but probably possible. If one shows up, it will probably kill us. */ /* Swap all the raw entries */ - for (raw_src = (char *) raw, internal_ptr = internal; + for (internal_ptr = internal; raw_src < raw_end; raw_src += symesz, internal_ptr++) { @@ -1401,9 +1475,10 @@ coff_get_normalized_symtab (abfd) } } - /* Free all the raw stuff */ - if (raw != NULL) - bfd_release (abfd, raw); + /* Free the raw symbols, but not the strings (if we have them). */ + obj_coff_keep_strings (abfd) = true; + if (! _bfd_coff_free_symbols (abfd)) + return NULL; for (internal_ptr = internal; internal_ptr < internal_end; internal_ptr++) @@ -1417,11 +1492,16 @@ coff_get_normalized_symtab (abfd) { /* the filename is a long one, point into the string table */ if (string_table == NULL) - string_table = build_string_table (abfd); + { + string_table = _bfd_coff_read_string_table (abfd); + if (string_table == NULL) + return NULL; + } internal_ptr->u.syment._n._n_n._n_offset = - (long) (string_table - STRING_SIZE_SIZE + - (internal_ptr + 1)->u.auxent.x_file.x_n.x_offset); + ((long) + (string_table + + (internal_ptr + 1)->u.auxent.x_file.x_n.x_offset)); } else { @@ -1466,11 +1546,15 @@ coff_get_normalized_symtab (abfd) /* Long name already. Point symbol at the string in the table. */ if (string_table == NULL) - string_table = build_string_table (abfd); - internal_ptr->u.syment._n._n_n._n_offset = (long int) - (string_table - - STRING_SIZE_SIZE - + internal_ptr->u.syment._n._n_n._n_offset); + { + string_table = _bfd_coff_read_string_table (abfd); + if (string_table == NULL) + return NULL; + } + internal_ptr->u.syment._n._n_n._n_offset = + ((long int) + (string_table + + internal_ptr->u.syment._n._n_n._n_offset)); } else { @@ -1485,7 +1569,8 @@ coff_get_normalized_symtab (abfd) } obj_raw_syments (abfd) = internal; - BFD_ASSERT (obj_raw_syment_count (abfd) == internal_ptr - internal); + BFD_ASSERT (obj_raw_syment_count (abfd) + == (unsigned int) (internal_ptr - internal)); return (internal); } /* coff_get_normalized_symtab() */ @@ -1753,8 +1838,8 @@ coff_find_nearest_line (abfd, section, ignore_symbols, offset, filename_ptr, } if (p2 < pend - && offset >= p2->u.syment.n_value - && offset - p2->u.syment.n_value < maxdiff) + && offset >= (bfd_vma) p2->u.syment.n_value + && offset - (bfd_vma) p2->u.syment.n_value < maxdiff) { *filename_ptr = (char *) p->u.syment._n._n_n._n_offset; maxdiff = offset - p2->u.syment.n_value; diff --git a/bfd/cofflink.c b/bfd/cofflink.c index 43bb69f..ea99908 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -100,45 +100,6 @@ static boolean coff_reloc_link_order PARAMS ((bfd *, struct coff_final_link_info *, asection *, struct bfd_link_order *)); - -/* These new data and data types are used to keep track of the .idata$4 and - .idata$5 relocations which are put into the .idata section for all of the - *.dll input libraries linked in. This is not a great solution, and may - break in the future if MS changes the format of its libraries, but it - does work for the collection of mstools libraries we are currently working - with. The main problem is that there are some new majic symbols defined - in the libraries which are non-standard coff and simply aren't handled - completely by ld. What has been included here will help finish up the job. - Basically, during the link, .idata$4 and .idata$5 pointers are correctly - relocated to the image. At the very end of the link, the .idata$2 - information is written. This data appears at the beginning of the .idata - section and a 'set' of information appears for each *.dll passed in. - Each set of information consists of 3 addresses, a pointer to the .idata$4 - start, a pointer to .idata$6 (which has the name of the dll), and a pointer - to .idata$5 start. The idata$4 and 5 information is a list of pointers - which appear to point to the name of various functions found within the dll. - When invoked, the loader will write over these names with the correct - addresses to use for these functions. - Without this 'fix', all information appears correctly except for the - addresses of the .idata$4 and 5 starts within the .idata$2 portion of the - .idata section. What we will do is to keep track of the dll's processed - and the number of functions needed from each dll. From this information - we can correctly compute the start of the idata$4 and 5 lists for each - dll in the idata section */ -static int num_DLLs_done = 0; -static int num_DLLs = 0; -static int all_entries = 0; -struct DLL_struct { - const char * DLL_name; - int num_entries; -}; -struct DLL_struct MS_DLL[10]; -static bfd_vma idata_4_prev = 0; -static bfd_vma idata_5_prev = 0; -static bfd_vma add_to_val = 0; - - - /* Create an entry in a COFF linker hash table. */ static struct bfd_hash_entry * @@ -519,128 +480,7 @@ coff_link_add_symbols (abfd, info) return true; } -/* parse out a -heap <reserved>,<commit> line */ - -static char * -dores_com (ptr, res, com) - char *ptr; - bfd_link_pe_info_dval *res; - bfd_link_pe_info_dval *com; -{ - res->defined = 1; - res->value = strtoul (ptr, &ptr, 0); - if (ptr[0] == ',') - { - com->value = strtoul (ptr+1, &ptr, 0); - com->defined = 1; - } - return ptr; -} - -static char *get_name(ptr, dst) -char *ptr; -char **dst; -{ - while (*ptr == ' ') - ptr++; - *dst = ptr; - while (*ptr && *ptr != ' ') - ptr++; - *ptr = 0; - return ptr+1; -} -/* Process any magic embedded commands in a section called .drectve */ - -static int -process_embedded_commands (info, abfd) - struct bfd_link_info *info; - bfd *abfd; -{ - asection *sec = bfd_get_section_by_name (abfd, ".drectve"); - char *s; - char *e; - char *copy; - if (!sec) - return 1; - - copy = malloc ((size_t) sec->_raw_size); - if (!copy) - { - bfd_set_error (bfd_error_no_memory); - return 0; - } - if (! bfd_get_section_contents(abfd, sec, copy, 0, sec->_raw_size)) - { - free (copy); - return 0; - } - e = copy + sec->_raw_size; - for (s = copy; s < e ; ) - { - if (s[0]!= '-') { - s++; - continue; - } - if (strncmp (s,"-attr", 5) == 0) - { - char *name; - char *attribs; - asection *asec; - - int loop = 1; - int had_write = 0; - int had_read = 0; - int had_exec= 0; - int had_shared= 0; - s += 5; - s = get_name(s, &name); - s = get_name(s, &attribs); - while (loop) { - switch (*attribs++) - { - case 'W': - had_write = 1; - break; - case 'R': - had_read = 1; - break; - case 'S': - had_shared = 1; - break; - case 'X': - had_exec = 1; - break; - default: - loop = 0; - } - } - asec = bfd_get_section_by_name (abfd, name); - if (asec) { - if (had_exec) - asec->flags |= SEC_CODE; - if (!had_write) - asec->flags |= SEC_READONLY; - } - } - else if (strncmp (s,"-heap", 5) == 0) - { - s = dores_com (s+5, - &info->pe_info->heap_reserve, - &info->pe_info->heap_commit); - } - else if (strncmp (s,"-stack", 6) == 0) - { - s = dores_com (s+6, - &info->pe_info->stack_reserve, - &info->pe_info->stack_commit); - } - else - s++; - } - free (copy); - return 1; -} /* Do the final link step. */ boolean @@ -941,7 +781,7 @@ _bfd_coff_final_link (abfd, info) index of the first external symbol. Write it out again if necessary. */ if (finfo.last_file_index != -1 - && finfo.last_file.n_value != obj_raw_syment_count (abfd)) + && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd)) { finfo.last_file.n_value = obj_raw_syment_count (abfd); bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file, @@ -1202,6 +1042,137 @@ _bfd_coff_read_internal_relocs (abfd, sec, cache, external_relocs, return NULL; } + + +/* parse out a -heap <reserved>,<commit> line */ + +static char * +dores_com (ptr, output_bfd, heap) + char *ptr; + bfd *output_bfd; + int heap; +{ + if (coff_data(output_bfd)->pe) + { + int val = strtoul (ptr, &ptr, 0); + if (heap) + pe_data(output_bfd)->pe_opthdr.SizeOfHeapReserve =val; + else + pe_data(output_bfd)->pe_opthdr.SizeOfStackReserve =val; + + if (ptr[0] == ',') + { + int val = strtoul (ptr+1, &ptr, 0); + if (heap) + pe_data(output_bfd)->pe_opthdr.SizeOfHeapCommit =val; + else + pe_data(output_bfd)->pe_opthdr.SizeOfStackCommit =val; + } + } + return ptr; +} + +static char *get_name(ptr, dst) +char *ptr; +char **dst; +{ + while (*ptr == ' ') + ptr++; + *dst = ptr; + while (*ptr && *ptr != ' ') + ptr++; + *ptr = 0; + return ptr+1; +} +/* Process any magic embedded commands in a section called .drectve */ + +int +process_embedded_commands (output_bfd, info, abfd) + bfd *output_bfd; + struct bfd_link_info *info; + bfd *abfd; +{ + asection *sec = bfd_get_section_by_name (abfd, ".drectve"); + char *s; + char *e; + char *copy; + if (!sec) + return 1; + + copy = malloc ((size_t) sec->_raw_size); + if (!copy) + { + bfd_set_error (bfd_error_no_memory); + return 0; + } + if (! bfd_get_section_contents(abfd, sec, copy, 0, sec->_raw_size)) + { + free (copy); + return 0; + } + e = copy + sec->_raw_size; + for (s = copy; s < e ; ) + { + if (s[0]!= '-') { + s++; + continue; + } + if (strncmp (s,"-attr", 5) == 0) + { + char *name; + char *attribs; + asection *asec; + + int loop = 1; + int had_write = 0; + int had_read = 0; + int had_exec= 0; + int had_shared= 0; + s += 5; + s = get_name(s, &name); + s = get_name(s, &attribs); + while (loop) { + switch (*attribs++) + { + case 'W': + had_write = 1; + break; + case 'R': + had_read = 1; + break; + case 'S': + had_shared = 1; + break; + case 'X': + had_exec = 1; + break; + default: + loop = 0; + } + } + asec = bfd_get_section_by_name (abfd, name); + if (asec) { + if (had_exec) + asec->flags |= SEC_CODE; + if (!had_write) + asec->flags |= SEC_READONLY; + } + } + else if (strncmp (s,"-heap", 5) == 0) + { + s = dores_com (s+5, output_bfd, 1); + } + else if (strncmp (s,"-stack", 6) == 0) + { + s = dores_com (s+6, output_bfd, 0); + } + else + s++; + } + free (copy); + return 1; +} + /* Link an input file into the linker output file. This function handles all the sections and relocations of the input file at once. */ @@ -1228,7 +1199,7 @@ coff_link_input_bfd (finfo, input_bfd) struct internal_syment *isymp; asection **secpp; long *indexp; - long output_index; + unsigned long output_index; bfd_byte *outsym; struct coff_link_hash_entry **sym_hash; asection *o; @@ -1269,9 +1240,9 @@ coff_link_input_bfd (finfo, input_bfd) output_index = syment_base; outsym = finfo->outsyms; - if (obj_pe (output_bfd)) + if (coff_data(output_bfd)->pe) { - if (!process_embedded_commands (finfo->info, input_bfd)) + if (!process_embedded_commands (output_bfd, finfo->info, input_bfd)) return false; } @@ -1408,11 +1379,11 @@ coff_link_input_bfd (finfo, input_bfd) if (isym.n_sclass == C_FILE) { if (finfo->last_file_index != -1 - && finfo->last_file.n_value != output_index) + && finfo->last_file.n_value != (long) output_index) { /* We must correct the value of the last C_FILE entry. */ finfo->last_file.n_value = output_index; - if (finfo->last_file_index >= syment_base) + if ((bfd_size_type) finfo->last_file_index >= syment_base) { /* The last C_FILE symbol is in this input file. */ bfd_coff_swap_sym_out (output_bfd, @@ -1559,7 +1530,7 @@ coff_link_input_bfd (finfo, input_bfd) } else if (isymp->n_sclass != C_STAT || isymp->n_type != T_NULL) { - long indx; + unsigned long indx; if (ISFCN (isymp->n_type) || ISTAG (isymp->n_sclass) @@ -1587,11 +1558,13 @@ coff_link_input_bfd (finfo, input_bfd) indx = auxp->x_sym.x_tagndx.l; if (indx > 0 && indx < obj_raw_syment_count (input_bfd)) { - indx = finfo->sym_indices[indx]; - if (indx < 0) + long symindx; + + symindx = finfo->sym_indices[indx]; + if (symindx < 0) auxp->x_sym.x_tagndx.l = 0; else - auxp->x_sym.x_tagndx.l = indx; + auxp->x_sym.x_tagndx.l = symindx; } } @@ -1652,7 +1625,7 @@ coff_link_input_bfd (finfo, input_bfd) if (iline.l_lnno != 0) iline.l_addr.l_paddr += offset; else if (iline.l_addr.l_symndx >= 0 - && (iline.l_addr.l_symndx + && ((unsigned long) iline.l_addr.l_symndx < obj_raw_syment_count (input_bfd))) { long indx; @@ -1730,7 +1703,7 @@ coff_link_input_bfd (finfo, input_bfd) normal case, this will save us from writing out the C_FILE symbol again. */ if (finfo->last_file_index != -1 - && finfo->last_file_index >= syment_base) + && (bfd_size_type) finfo->last_file_index >= syment_base) { finfo->last_file.n_value = output_index; bfd_coff_swap_sym_out (output_bfd, (PTR) &finfo->last_file, @@ -1745,8 +1718,9 @@ coff_link_input_bfd (finfo, input_bfd) if (bfd_seek (output_bfd, obj_sym_filepos (output_bfd) + syment_base * osymesz, SEEK_SET) != 0 - || bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1, - output_bfd) != outsym - finfo->outsyms) + || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1, + output_bfd) + != (bfd_size_type) (outsym - finfo->outsyms))) return false; BFD_ASSERT ((obj_raw_syment_count (output_bfd) @@ -2282,8 +2256,7 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, /* So if this is non pcrelative, and is referenced to a section or a common symbol, then it needs a reloc */ if (!howto->pc_relative - && (sym->n_scnum - || sym->n_value)) + && sym && (sym->n_scnum || sym->n_value)) { /* relocation to a symbol in a section which isn't absolute - we output the address here @@ -2291,6 +2264,8 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd, bfd_vma addr = rel->r_vaddr + input_section->output_offset + input_section->output_section->vma; + if (coff_data(output_bfd)->pe) + addr -= pe_data(output_bfd)->pe_opthdr.ImageBase; fwrite (&addr, 1,4, (FILE *) info->base_file); } } diff --git a/bfd/cpu-arc.c b/bfd/cpu-arc.c new file mode 100644 index 0000000..b7e9a7c --- /dev/null +++ b/bfd/cpu-arc.c @@ -0,0 +1,77 @@ +/* BFD support for the ARC processor + Copyright 1994, 1995 Free Software Foundation, Inc. + Contributed by Doug Evans (dje@cygnus.com). + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" + +#define ARC(mach, print_name, default_p) \ +{ \ + 32, /* 32 bits in a word */ \ + 32, /* 32 bits in an address */ \ + 8, /* 8 bits in a byte */ \ + bfd_arch_arc, \ + mach, \ + "arc", \ + print_name, \ + 4, /* section alignment power */ \ + default_p, \ + bfd_default_compatible, \ + bfd_default_scan, \ + 0, \ + } + +static bfd_arch_info_type arch_info_struct[] = +{ + ARC (bfd_mach_arc_base, "arc-base", true), + ARC (bfd_mach_arc_host, "arc-host", false), + ARC (bfd_mach_arc_graphics, "arc-graphics", false), + ARC (bfd_mach_arc_audio, "arc-audio", false), +}; + +void +bfd_arc_arch () +{ + register unsigned int i; + + for (i = 0; i < sizeof (arch_info_struct) / sizeof (arch_info_struct[0]); i++) + bfd_arch_linkin (&arch_info_struct[i]); +} + +/* Utility routines. */ + +/* Given cpu type NAME, return its bfd_mach_arc_xxx value. + NAME is one of "base, audio, etc.". + Returns -1 if not found. */ + +int +arc_get_mach (name) + char *name; +{ + register unsigned int i; + + for (i = 0; i < sizeof (arch_info_struct) / sizeof (arch_info_struct[0]); i++) + { + /* +4: skip over "arc-" */ + if (strcmp (name, arch_info_struct[i].printable_name + 4) == 0) + return arch_info_struct[i].mach; + } + return -1; +} diff --git a/bfd/cpu-i960.c b/bfd/cpu-i960.c index 5efa726..74ec218 100644 --- a/bfd/cpu-i960.c +++ b/bfd/cpu-i960.c @@ -1,5 +1,5 @@ /* BFD library support routines for the i960 architecture. - Copyright (C) 1990-1991 Free Software Foundation, Inc. + Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. Hacked by Steve Chamberlain of Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -16,11 +16,11 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <sysdep.h> #include "bfd.h" +#include "sysdep.h" #include "libbfd.h" @@ -29,15 +29,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ info_struct pointer */ static boolean -DEFUN(scan_960_mach, (ap, string), - CONST bfd_arch_info_struct_type *ap AND - CONST char *string) +scan_960_mach (ap, string) + CONST bfd_arch_info_type *ap; + CONST char *string; { unsigned long machine; /* Look for the string i960, or somesuch at the front of the string */ - if (strncmp("i960",string) == 0) { + if (strncmp("i960",string,4) == 0) { string+=4; } else { @@ -75,6 +75,10 @@ DEFUN(scan_960_mach, (ap, string), machine = bfd_mach_i960_ka_sa; else if (string[0] == 's' && string[1] == 'a') machine = bfd_mach_i960_ka_sa; + /* start-sanitize-i960xl */ + else if (string[0] == 'x' && string[1] == 'l') + machine = bfd_mach_i960_xl; + /* end-sanitize-i960xl */ else return false; if (machine == ap->mach) return true; @@ -87,15 +91,18 @@ DEFUN(scan_960_mach, (ap, string), machine which would be compatible with both and returns a pointer to its info structure */ -CONST bfd_arch_info_struct_type * -DEFUN(compatible,(a,b), - CONST bfd_arch_info_struct_type *a AND - CONST bfd_arch_info_struct_type *b) +static CONST bfd_arch_info_type * +compatible (a,b) + CONST bfd_arch_info_type *a; + CONST bfd_arch_info_type *b; { - /* The i960 has two distinct subspecies which may not interbreed: - CORE CA - CORE KA KB MC XA + /* The i960 has distinct subspecies which may not interbreed: + CORE CA + CORE KA KB MC XA + start-sanitize-i960xl + CORE XL + end-sanitize-i960xl Any architecture on the same line is compatible, the one on the right is the least restrictive. @@ -108,23 +115,33 @@ DEFUN(compatible,(a,b), #define MC bfd_mach_i960_mc /*4*/ #define XA bfd_mach_i960_xa /*5*/ #define CA bfd_mach_i960_ca /*6*/ +#define MAX_ARCH ((int)CA) +/* start-sanitize-i960xl */ +#define XL bfd_mach_i960_xl /*7*/ +#undef MAX_ARCH +#define MAX_ARCH ((int)XL) +/* end-sanitize-i960xl */ - static CONST char matrix[7][7] = - { - ERROR,CORE, KA, KB, MC, XA, CA, - CORE, CORE, KA, KB, MC, XA, CA, - KA, KA, KA, KB, MC, XA, ERROR, - KB, KB, KB, KB, MC, XA, ERROR, - MC, MC, MC, MC, MC, XA, ERROR, - XA, XA, XA, XA, XA, XA, ERROR, - CA, CA, ERROR, ERROR, ERROR, ERROR, CA - }; + + static CONST unsigned long matrix[MAX_ARCH+1][MAX_ARCH+1] = + { + { ERROR, CORE, KA, KB, MC, XA, CA }, + { CORE, CORE, KA, KB, MC, XA, CA }, + { KA, KA, KA, KB, MC, XA, ERROR }, + { KB, KB, KB, KB, MC, XA, ERROR }, + { MC, MC, MC, MC, MC, XA, ERROR }, + { XA, XA, XA, XA, XA, XA, ERROR }, + { CA, CA, ERROR, ERROR, ERROR, ERROR, CA }, + /* start-sanitize-i960xl */ + { XL, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR, XL }, + /* end-sanitize-i960xl */ + }; if (a->arch != b->arch || matrix[a->mach][b->mach] == ERROR) { - return (bfd_arch_info_struct_type *)NULL; + return NULL; } else { @@ -136,23 +153,27 @@ DEFUN(compatible,(a,b), int bfd_default_scan_num_mach(); #define N(a,b,d) \ -{ 32, 32, 8,bfd_arch_i960,a,"i960",b,d,compatible,scan_960_mach,0,} +{ 32, 32, 8,bfd_arch_i960,a,"i960",b,3,d,compatible,scan_960_mach,0,} -static bfd_arch_info_struct_type arch_info_struct[] = +static bfd_arch_info_type arch_info_struct[] = { - N(bfd_mach_i960_core,"i960:core",true), + N(bfd_mach_i960_core, "i960:core", true), N(bfd_mach_i960_ka_sa,"i960:ka_sa",false), N(bfd_mach_i960_kb_sb,"i960:kb_sb",false), - N(bfd_mach_i960_mc,"i960:mc",false), - N(bfd_mach_i960_xa,"i960:xa",false), - N(bfd_mach_i960_ca,"i960:ca",false) - }; + N(bfd_mach_i960_mc, "i960:mc", false), + N(bfd_mach_i960_xa, "i960:xa", false), + N(bfd_mach_i960_ca, "i960:ca", false), + /* start-sanitize-i960xl */ + N(bfd_mach_i960_xl, "i960:xl", false), + /* end-sanitize-i960xl */ +}; -void DEFUN_VOID(bfd_i960_arch) +void +bfd_i960_arch () { unsigned int i; - for (i = 0; i < 6; i++) { + for (i = 0; i < sizeof(arch_info_struct)/sizeof (*arch_info_struct); i++) { bfd_arch_linkin(arch_info_struct + i); } } diff --git a/bfd/cpu-mips.c b/bfd/cpu-mips.c new file mode 100644 index 0000000..10c72cf --- /dev/null +++ b/bfd/cpu-mips.c @@ -0,0 +1,92 @@ +/* bfd back-end for mips support + Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. + Written by Steve Chamberlain of Cygnus Support. + +This file is part of BFD, the Binary File Descriptor library. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" + +static bfd_arch_info_type arch_info_struct[] = +{ + { + 32, /* 32 bits in a word */ + 32, /* 32 bits in an address */ + 8, /* 8 bits in a byte */ + bfd_arch_mips, + 3000, + "mips", + "mips:3000", + 3, + true, + bfd_default_compatible, + bfd_default_scan, + 0, + }, + { + 32, /* 32 bits in a word */ + 32, /* 32 bits in an address */ + 8, /* 8 bits in a byte */ + bfd_arch_mips, + 6000, + "mips", + "mips:6000", + 3, + false, + bfd_default_compatible, + bfd_default_scan, + 0, + }, + { + 64, /* 64 bits in a word */ + 64, /* 64 bits in an address */ + 8, /* 8 bits in a byte */ + bfd_arch_mips, + 4000, + "mips", + "mips:4000", + 3, + false, + bfd_default_compatible, + bfd_default_scan , + 0, + }, + { + 64, /* 64 bits in a word */ + 64, /* 64 bits in an address */ + 8, /* 8 bits in a byte */ + bfd_arch_mips, + 8000, + "mips", + "mips:8000", + 3, + false, + bfd_default_compatible, + bfd_default_scan , + 0, + } +}; + +void +bfd_mips_arch () +{ + register unsigned int i; + + for (i = 0; i < sizeof (arch_info_struct) / sizeof (*arch_info_struct); i++) + bfd_arch_linkin(&arch_info_struct[i]); +} diff --git a/bfd/ecoff.c b/bfd/ecoff.c index a5ad16b..37af7ab 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -579,8 +579,8 @@ _bfd_ecoff_slurp_symbolic_info (abfd, ignore, debug) debug->off2 = (type) NULL; \ else \ debug->off2 = (type) ((char *) raw \ - + internal_symhdr->off1 \ - - raw_base) + + (internal_symhdr->off1 \ + - raw_base)) FIX (cbLineOffset, line, unsigned char *); FIX (cbDnOffset, external_dnr, PTR); FIX (cbPdOffset, external_pdr, PTR); @@ -1181,7 +1181,7 @@ ecoff_type_to_string (abfd, fdr, indx) qualifiers[i].stride = 0; } - if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1) + if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == (bfd_vma) -1) return "-1 (no type)"; _bfd_ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti); @@ -2437,7 +2437,7 @@ _bfd_ecoff_write_object_contents (abfd) siz = filhsz; if (siz < aoutsz) siz = aoutsz; - buff = (PTR) malloc (siz); + buff = (PTR) malloc ((size_t) siz); if (buff == NULL) { bfd_set_error (bfd_error_no_memory); @@ -3313,12 +3313,12 @@ _bfd_ecoff_bfd_link_hash_table_create (abfd) struct ecoff_link_hash_table *ret; ret = ((struct ecoff_link_hash_table *) - malloc (sizeof (struct ecoff_link_hash_table))); - if (!ret) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } + bfd_alloc (abfd, sizeof (struct ecoff_link_hash_table))); + if (ret == NULL) + { + bfd_set_error (bfd_error_no_memory); + return NULL; + } if (! _bfd_link_hash_table_init (&ret->root, abfd, ecoff_link_hash_newfunc)) { @@ -3574,7 +3574,8 @@ ecoff_link_check_archive_element (abfd, info, pneeded) } if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0 - || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax) + || (bfd_read (ssext, 1, symhdr->issExtMax, abfd) != + (bfd_size_type) symhdr->issExtMax)) goto error_return; /* Look through the external symbols to see if they define some @@ -3698,7 +3699,8 @@ ecoff_link_add_object_symbols (abfd, info) } if (bfd_seek (abfd, symhdr->cbSsExtOffset, SEEK_SET) != 0 - || bfd_read (ssext, 1, symhdr->issExtMax, abfd) != symhdr->issExtMax) + || (bfd_read (ssext, 1, symhdr->issExtMax, abfd) + != (bfd_size_type) symhdr->issExtMax)) goto error_return; result = ecoff_link_add_externals (abfd, info, external_ext, ssext); @@ -4161,7 +4163,7 @@ ecoff_final_link_debug_accumulate (output_bfd, input_bfd, info, handle) debug->ptr = NULL; \ else \ { \ - debug->ptr = (type) malloc (size * symhdr->count); \ + debug->ptr = (type) malloc ((size_t) (size * symhdr->count)); \ if (debug->ptr == NULL) \ { \ bfd_set_error (bfd_error_no_memory); \ @@ -4404,8 +4406,8 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order) /* Get the section contents. We allocate memory for the larger of the size before relocating and the size after relocating. */ contents = (bfd_byte *) malloc (raw_size >= cooked_size - ? raw_size - : cooked_size); + ? (size_t) raw_size + : (size_t) cooked_size); if (contents == NULL && raw_size != 0) { bfd_set_error (bfd_error_no_memory); @@ -4417,7 +4419,7 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order) simply reuse the old buffer in case cooked_size > raw_size. */ if (section_tdata != (struct ecoff_section_tdata *) NULL && section_tdata->contents != (bfd_byte *) NULL) - memcpy (contents, section_tdata->contents, raw_size); + memcpy (contents, section_tdata->contents, (size_t) raw_size); else { if (! bfd_get_section_contents (input_bfd, input_section, @@ -4435,7 +4437,7 @@ ecoff_indirect_link_order (output_bfd, info, output_section, link_order) external_relocs = section_tdata->external_relocs; else { - external_relocs = (PTR) malloc (external_relocs_size); + external_relocs = (PTR) malloc ((size_t) external_relocs_size); if (external_relocs == NULL && external_relocs_size != 0) { bfd_set_error (bfd_error_no_memory); @@ -4651,7 +4653,7 @@ ecoff_reloc_link_order (output_bfd, info, output_section, link_order) /* Get some memory and swap out the reloc. */ external_reloc_size = ecoff_backend (output_bfd)->external_reloc_size; - rbuf = (bfd_byte *) malloc (external_reloc_size); + rbuf = (bfd_byte *) malloc ((size_t) external_reloc_size); if (rbuf == (bfd_byte *) NULL) { bfd_set_error (bfd_error_no_memory); @@ -77,7 +77,7 @@ static char * elf_read (abfd, offset, size) bfd * abfd; long offset; - int size; + unsigned int size; { char *buf; @@ -609,8 +609,40 @@ bfd_section_from_shdr (abfd, shindex) Elf_Internal_Shdr *hdr2; int use_rela_p = get_elf_backend_data (abfd)->use_rela_p; + /* For some incomprehensible reason Oracle distributes + libraries for Solaris in which some of the objects have + bogus sh_link fields. It would be nice if we could just + reject them, but, unfortunately, some people need to use + them. We scan through the section headers; if we find only + one suitable symbol table, we clobber the sh_link to point + to it. I hope this doesn't break anything. */ + if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_SYMTAB + && elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_DYNSYM) + { + int scan; + int found; + + found = 0; + for (scan = 1; scan < ehdr->e_shnum; scan++) + { + if (elf_elfsections (abfd)[scan]->sh_type == SHT_SYMTAB + || elf_elfsections (abfd)[scan]->sh_type == SHT_DYNSYM) + { + if (found != 0) + { + found = 0; + break; + } + found = scan; + } + } + if (found != 0) + hdr->sh_link = found; + } + /* Get the symbol table. */ - if (! bfd_section_from_shdr (abfd, hdr->sh_link)) + if (elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB + && ! bfd_section_from_shdr (abfd, hdr->sh_link)) return false; /* If this reloc section does not use the main symbol table we @@ -757,6 +789,7 @@ bfd_section_from_phdr (abfd, hdr, index) if (newsect == NULL) return false; newsect->vma = hdr->p_vaddr; + newsect->lma = hdr->p_paddr; newsect->_raw_size = hdr->p_filesz; newsect->filepos = hdr->p_offset; newsect->flags |= SEC_HAS_CONTENTS; @@ -790,6 +823,7 @@ bfd_section_from_phdr (abfd, hdr, index) if (newsect == NULL) return false; newsect->vma = hdr->p_vaddr + hdr->p_filesz; + newsect->lma = hdr->p_paddr + hdr->p_filesz; newsect->_raw_size = hdr->p_memsz - hdr->p_filesz; if (hdr->p_type == PT_LOAD) { @@ -836,10 +870,22 @@ elf_fake_sections (abfd, asect, failedptrarg) } this_hdr->sh_flags = 0; + + /* FIXME: This should really use vma, rather than lma. However, + that would mean that the lma information was lost, which would + mean that the AT keyword in linker scripts would not work. + Fortunately, native scripts do not use the AT keyword, so we can + get away with using lma here. The right way to handle this is to + 1) read the program headers as well as the section headers, and + set the lma fields of the BFD sections based on the p_paddr + fields of the program headers, and 2) set the p_paddr fields of + the program headers based on the section lma fields when writing + them out. */ if ((asect->flags & SEC_ALLOC) != 0) - this_hdr->sh_addr = asect->vma; + this_hdr->sh_addr = asect->lma; else this_hdr->sh_addr = 0; + this_hdr->sh_offset = 0; this_hdr->sh_size = asect->_raw_size; this_hdr->sh_link = 0; @@ -1434,6 +1480,7 @@ get_program_header_size (abfd, sorted_hdrs, count, maxpagesize) { size_t segs; asection *s; + struct elf_backend_data *bed = get_elf_backend_data (abfd); /* We can't return a different result each time we're called. */ if (elf_tdata (abfd)->program_header_size != 0) @@ -1538,7 +1585,12 @@ get_program_header_size (abfd, sorted_hdrs, count, maxpagesize) ++segs; } - elf_tdata (abfd)->program_header_size = segs * get_elf_backend_data (abfd)->s->sizeof_phdr; + /* Let the backend count up any program headers it might need. */ + if (bed->elf_backend_create_program_headers) + segs = ((*bed->elf_backend_create_program_headers) + (abfd, (Elf_Internal_Phdr *) NULL, segs)); + + elf_tdata (abfd)->program_header_size = segs * bed->s->sizeof_phdr; return elf_tdata (abfd)->program_header_size; } @@ -1574,7 +1626,10 @@ map_program_segments (abfd, off, first, sorted_hdrs, phdr_size) phdr_count = 0; phdr = phdrs; - phdr_size_adjust = 0; + if (bed->want_hdr_in_seg) + phdr_size_adjust = first->sh_offset - phdr_size; + else + phdr_size_adjust = 0; /* If we have a loadable .interp section, we must create a PT_INTERP segment which must precede all PT_LOAD segments. We assume that @@ -1693,8 +1748,9 @@ map_program_segments (abfd, off, first, sorted_hdrs, phdr_size) phdr->p_align = bed->maxpagesize; if (hdr == first - && sinterp != NULL - && (sinterp->flags & SEC_LOAD) != 0) + && (bed->want_hdr_in_seg + || (sinterp != NULL + && (sinterp->flags & SEC_LOAD) != 0))) { phdr->p_offset -= phdr_size + phdr_size_adjust; phdr->p_vaddr -= phdr_size + phdr_size_adjust; @@ -1732,6 +1788,12 @@ map_program_segments (abfd, off, first, sorted_hdrs, phdr_size) ++phdr_count; } + /* Let the backend create additional program headers. */ + if (bed->elf_backend_create_program_headers) + phdr_count = (*bed->elf_backend_create_program_headers) (abfd, + phdrs, + phdr_count); + /* Make sure the return value from get_program_header_size matches what we computed here. Actually, it's OK if we allocated too much space in the program header. */ @@ -1864,8 +1926,8 @@ assign_file_positions_except_relocs (abfd, dosyms) } memcpy (sorted_hdrs, i_shdrpp + 1, hdrppsize); - qsort (sorted_hdrs, i_ehdrp->e_shnum - 1, sizeof (Elf_Internal_Shdr *), - elf_sort_hdrs); + qsort (sorted_hdrs, (size_t) i_ehdrp->e_shnum - 1, + sizeof (Elf_Internal_Shdr *), elf_sort_hdrs); /* We can't actually create the program header until we have set the file positions for the sections, and we can't do that until we know @@ -1874,7 +1936,7 @@ assign_file_positions_except_relocs (abfd, dosyms) phdr_size = get_program_header_size (abfd, sorted_hdrs, i_ehdrp->e_shnum - 1, maxpagesize); - if (phdr_size == (file_ptr) -1) + if (phdr_size == (bfd_size_type) -1) return false; /* Compute the file offsets of each section. */ @@ -1900,6 +1962,8 @@ assign_file_positions_except_relocs (abfd, dosyms) hdr->sh_offset = -1; continue; } + off = _bfd_elf_assign_file_position_for_section (hdr, off, + true); } else { @@ -1910,9 +1974,9 @@ assign_file_positions_except_relocs (abfd, dosyms) the page size. This is required by the program header. */ off += (hdr->sh_addr - off) % maxpagesize; + off = _bfd_elf_assign_file_position_for_section (hdr, off, + false); } - - off = _bfd_elf_assign_file_position_for_section (hdr, off, false); } /* Create the program header. */ @@ -1920,7 +1984,8 @@ assign_file_positions_except_relocs (abfd, dosyms) phdr_size); if (phdr_map == (file_ptr) -1) return false; - BFD_ASSERT ((bfd_size_type) phdr_map <= (bfd_size_type) phdr_off + phdr_size); + BFD_ASSERT ((bfd_size_type) phdr_map + <= (bfd_size_type) phdr_off + phdr_size); free (sorted_hdrs); } diff --git a/bfd/elflink.h b/bfd/elflink.h index e1c22dd..f4674f4 100644 --- a/bfd/elflink.h +++ b/bfd/elflink.h @@ -2808,7 +2808,7 @@ elf_link_input_bfd (finfo, input_bfd) + o->output_section->reloc_count); for (; irela < irelaend; irela++, rel_hash++) { - long r_symndx; + unsigned long r_symndx; Elf_Internal_Sym *isym; asection *sec; diff --git a/bfd/i386linux.c b/bfd/i386linux.c index a40b5c5..ebc9388 100644 --- a/bfd/i386linux.c +++ b/bfd/i386linux.c @@ -217,7 +217,7 @@ linux_link_hash_table_create (abfd) struct linux_link_hash_table *ret; ret = ((struct linux_link_hash_table *) - malloc (sizeof (struct linux_link_hash_table))); + bfd_alloc (abfd, sizeof (struct linux_link_hash_table))); if (ret == (struct linux_link_hash_table *) NULL) { bfd_set_error (bfd_error_no_memory); @@ -586,7 +586,7 @@ bfd_linux_size_dynamic_sections (output_bfd, info) bfd_set_error (bfd_error_no_memory); return false; } - memset (s->contents, 0, s->_raw_size); + memset (s->contents, 0, (size_t) s->_raw_size); } return true; @@ -607,7 +607,7 @@ linux_finish_dynamic_link (output_bfd, info) struct fixup *f; unsigned int new_addr; int section_offset; - int fixups_written; + unsigned int fixups_written; if (linux_hash_table (info)->dynobj == NULL) return true; @@ -543,7 +543,8 @@ parse_expression (ieee, value, symbol, pcrel, extra, section) #define ieee_seek(abfd, offset) \ IEEE_DATA(abfd)->h.input_p = IEEE_DATA(abfd)->h.first_byte + offset -#define ieee_pos(abfd) IEEE_DATA(abfd)->h.input_p -IEEE_DATA(abfd)->h.first_byte +#define ieee_pos(abfd) \ + (IEEE_DATA(abfd)->h.input_p - IEEE_DATA(abfd)->h.first_byte) static unsigned int last_index; static char last_type; /* is the index for an X or a D */ @@ -1133,7 +1134,7 @@ ieee_archive_p (abfd) /* Make sure that we don't go over the end of the buffer */ - if (ieee_pos (abfd) > sizeof (buffer) / 2) + if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2) { /* Past half way, reseek and reprime */ buffer_offset += ieee_pos (abfd); @@ -1936,7 +1937,7 @@ do_with_relocs (abfd, s) bfd_set_error (bfd_error_no_memory); return false; } - memset ((PTR) stream, 0, s->_raw_size); + memset ((PTR) stream, 0, (size_t) s->_raw_size); } while (current_byte_index < s->_raw_size) { @@ -2116,7 +2117,7 @@ flush () { if (bfd_write ((PTR) (output_ptr_start), 1, output_ptr - output_ptr_start, output_bfd) - != output_ptr - output_ptr_start) + != (bfd_size_type) (output_ptr - output_ptr_start)) abort (); output_ptr = output_ptr_start; output_buffer++; diff --git a/bfd/libecoff.h b/bfd/libecoff.h index 8dbd3d8..d16e3fa 100644 --- a/bfd/libecoff.h +++ b/bfd/libecoff.h @@ -94,7 +94,7 @@ typedef struct ecoff_tdata /* The maximum size of objects to optimize using gp. This is typically set by the -G option to the compiler, assembler or linker. */ - int gp_size; + unsigned int gp_size; /* The register masks. When linking, all the masks found in the input files are combined into the masks of the output file. @@ -253,7 +253,7 @@ extern boolean _bfd_ecoff_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *)); _bfd_generic_bfd_copy_private_symbol_data #define _bfd_ecoff_bfd_print_private_bfd_data \ - _bfd_generic_bfd_pritn_private_bfd_data + _bfd_generic_bfd_print_private_bfd_data #define _bfd_ecoff_bfd_merge_private_bfd_data \ _bfd_generic_bfd_merge_private_bfd_data diff --git a/bfd/libelf.h b/bfd/libelf.h index 7a41be5..92c0bc2 100644 --- a/bfd/libelf.h +++ b/bfd/libelf.h @@ -249,7 +249,7 @@ struct elf_backend_data entire ELF symbol table. */ boolean (*elf_backend_symbol_table_processing) PARAMS ((bfd *, elf_symbol_type *, - int)); + unsigned int)); /* A function to do additional processing on the ELF section header just before writing it out. This is used to set the flags and @@ -488,12 +488,13 @@ struct elf_obj_tdata Elf_Internal_Shdr strtab_hdr; Elf_Internal_Shdr dynsymtab_hdr; Elf_Internal_Shdr dynstrtab_hdr; - int symtab_section, shstrtab_section, strtab_section, dynsymtab_section; + unsigned int symtab_section, shstrtab_section; + unsigned int strtab_section, dynsymtab_section; file_ptr next_file_pos; void *prstatus; /* The raw /proc prstatus structure */ void *prpsinfo; /* The raw /proc prpsinfo structure */ bfd_vma gp; /* The gp value (MIPS only, for now) */ - int gp_size; /* The gp size (MIPS only, for now) */ + unsigned int gp_size; /* The gp size (MIPS only, for now) */ /* This is set to true if the object was created by the backend linker. */ diff --git a/bfd/linker.c b/bfd/linker.c index ef9469b..efd1664 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -424,6 +424,7 @@ static boolean generic_link_check_archive_element static boolean generic_link_add_symbol_list PARAMS ((bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **, boolean collect)); +static bfd *hash_entry_bfd PARAMS ((struct bfd_link_hash_entry *)); static void set_symbol_from_hash PARAMS ((asymbol *, struct bfd_link_hash_entry *)); static boolean generic_add_output_symbol @@ -455,10 +456,7 @@ _bfd_link_hash_newfunc (entry, table, string) ret = ((struct bfd_link_hash_entry *) bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry))); if (ret == (struct bfd_link_hash_entry *) NULL) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } + return NULL; /* Call the allocation method of the superclass. */ ret = ((struct bfd_link_hash_entry *) @@ -568,10 +566,7 @@ generic_link_hash_newfunc (entry, table, string) ret = ((struct generic_link_hash_entry *) bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry))); if (ret == (struct generic_link_hash_entry *) NULL) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } + return NULL; /* Call the allocation method of the superclass. */ ret = ((struct generic_link_hash_entry *) @@ -770,10 +765,7 @@ archive_hash_newfunc (entry, table, string) ret = ((struct archive_hash_entry *) bfd_hash_allocate (table, sizeof (struct archive_hash_entry))); if (ret == (struct archive_hash_entry *) NULL) - { - bfd_set_error (bfd_error_no_memory); - return NULL; - } + return NULL; /* Call the allocation method of the superclass. */ ret = ((struct archive_hash_entry *) @@ -1321,7 +1313,7 @@ enum link_action static const enum link_action link_action[8][8] = { /* current\prev new undef undefw def defw com indr warn */ - /* UNDEF_ROW */ {UND, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, + /* UNDEF_ROW */ {UND, NOACT, UND, REF, REF, NOACT, REFC, WARNC }, /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE }, /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE }, @@ -1354,6 +1346,30 @@ static const enum link_action link_action[8][8] = Adding an entry to a set does not count as a reference to a set, and no warning is issued (SET_ROW/warn). */ +/* Return the BFD in which a hash entry has been defined, if known. */ + +static bfd * +hash_entry_bfd (h) + struct bfd_link_hash_entry *h; +{ + while (h->type == bfd_link_hash_warning) + h = h->u.i.link; + switch (h->type) + { + default: + return NULL; + case bfd_link_hash_undefined: + case bfd_link_hash_undefweak: + return h->u.undef.abfd; + case bfd_link_hash_defined: + case bfd_link_hash_defweak: + return h->u.def.section->owner; + case bfd_link_hash_common: + return h->u.c.p->section->owner; + } + /*NOTREACHED*/ +} + /* Add a symbol to the global hash table. ABFD is the BFD the symbol comes from. NAME is the name of the symbol. @@ -1737,7 +1753,9 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value, /* Issue a warning and cycle. */ if (h->u.i.warning != NULL) { - if (! (*info->callbacks->warning) (info, h->u.i.warning)) + if (! (*info->callbacks->warning) (info, h->u.i.warning, + abfd, (asection *) NULL, + (bfd_vma) 0)) return false; /* Only issue a warning once. */ h->u.i.warning = NULL; @@ -1759,7 +1777,9 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value, case WARN: /* Issue a warning. */ - if (! (*info->callbacks->warning) (info, string)) + if (! (*info->callbacks->warning) (info, string, + hash_entry_bfd (h), + (asection *) NULL, (bfd_vma) 0)) return false; break; @@ -1771,7 +1791,10 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value, ensure this. */ if (h->next != NULL || info->hash->undefs_tail == h) { - if (! (*info->callbacks->warning) (info, string)) + if (! (*info->callbacks->warning) (info, string, + hash_entry_bfd (h), + (asection *) NULL, + (bfd_vma) 0)) return false; break; } @@ -1783,27 +1806,33 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value, /* STRING is the warning to give. */ sub = ((struct bfd_link_hash_entry *) - bfd_hash_allocate (&info->hash->table, - sizeof (struct bfd_link_hash_entry))); - if (!sub) - { - bfd_set_error (bfd_error_no_memory); - return false; - } + ((*info->hash->table.newfunc) + ((struct bfd_hash_entry *) NULL, &info->hash->table, + h->root.string))); + if (sub == NULL) + return false; *sub = *h; - h->type = bfd_link_hash_warning; - h->u.i.link = sub; + sub->type = bfd_link_hash_warning; + sub->u.i.link = h; if (! copy) - h->u.i.warning = string; + sub->u.i.warning = string; else { char *w; w = bfd_hash_allocate (&info->hash->table, strlen (string) + 1); + if (w == NULL) + return false; strcpy (w, string); - h->u.i.warning = w; + sub->u.i.warning = w; } + + bfd_hash_replace (&info->hash->table, + (struct bfd_hash_entry *) h, + (struct bfd_hash_entry *) sub); + if (hashp != NULL) + *hashp = sub; } break; } @@ -1886,7 +1915,8 @@ _bfd_generic_final_link (abfd, info) symbols); if (reloc_count < 0) return false; - BFD_ASSERT (reloc_count == input_section->reloc_count); + BFD_ASSERT ((unsigned long) reloc_count + == input_section->reloc_count); o->reloc_count += reloc_count; free (relocs); } @@ -2209,8 +2239,22 @@ set_symbol_from_hash (sym, h) switch (h->type) { default: - case bfd_link_hash_new: abort (); + break; + case bfd_link_hash_new: + /* This can happen when a constructor symbol is seen but we are + not building constructors. */ + if (sym->section != NULL) + { + BFD_ASSERT ((sym->flags & BSF_CONSTRUCTOR) != 0); + } + else + { + sym->flags |= BSF_CONSTRUCTOR; + sym->section = bfd_abs_section_ptr; + sym->value = 0; + } + break; case bfd_link_hash_undefined: sym->section = bfd_und_section_ptr; sym->value = 0; @@ -2598,7 +2642,8 @@ default_indirect_link_order (output_bfd, info, output_section, link_order, } /* Get and relocate the section contents. */ - contents = (bfd_byte *) malloc (bfd_section_size (input_bfd, input_section)); + contents = ((bfd_byte *) + malloc ((size_t) bfd_section_size (input_bfd, input_section))); if (contents == NULL && bfd_section_size (input_bfd, input_section) != 0) { bfd_set_error (bfd_error_no_memory); diff --git a/bfd/oasys.c b/bfd/oasys.c index 8cd8505..4e543af 100644 --- a/bfd/oasys.c +++ b/bfd/oasys.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define UNDERSCORE_HACK 1 #include "bfd.h" #include "sysdep.h" +#include <ctype.h> #include "libbfd.h" #include "oasys.h" #include "liboasys.h" @@ -1351,7 +1352,7 @@ oasys_set_section_contents (abfd, section, location, offset, count) } (void) memcpy ((PTR) (oasys_per_section (section)->data + offset), location, - count); + (size_t) count); } return true; } diff --git a/bfd/peicode.h b/bfd/peicode.h index 56a0c82..a72fe9f 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -704,6 +704,13 @@ coff_swap_aouthdr_in (abfd, aouthdr_ext1, aouthdr_int1) bfd_h_get_32 (abfd, src->DataDirectory[idx][1]); } } + + if (aouthdr_int->entry) + aouthdr_int->entry += a->ImageBase; + if (aouthdr_int->tsize) + aouthdr_int->text_start += a->ImageBase; + if (aouthdr_int->dsize) + aouthdr_int->data_start += a->ImageBase; } @@ -993,35 +1000,43 @@ pe_print_private_bfd_data (abfd, vfile) int j; pe_data_type *pe = pe_data (abfd); struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr; - fprintf (file,"ImageBase\t\t%08x\n", i->ImageBase); - fprintf (file,"SectionAlignment\t%08x\n", i->SectionAlignment); - fprintf (file,"FileAlignment\t\t%08x\n", i->FileAlignment); + fprintf (file,"ImageBase\t\t"); + fprintf_vma (file, i->ImageBase); + fprintf (file,"SectionAlignment\t"); + fprintf_vma (file, i->SectionAlignment); + fprintf (file,"FileAlignment\t\t"); + fprintf_vma (file, i->FileAlignment); fprintf (file,"MajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion); fprintf (file,"MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion); fprintf (file,"MajorImageVersion\t%d\n", i->MajorImageVersion); fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion); fprintf (file,"MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion); fprintf (file,"MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion); - fprintf (file,"Reserved1\t\t%08x\n", i->Reserved1); - fprintf (file,"SizeOfImage\t\t%08x\n", i->SizeOfImage); - fprintf (file,"SizeOfHeaders\t\t%08x\n", i->SizeOfHeaders); - fprintf (file,"CheckSum\t\t%08x\n", i->CheckSum); + fprintf (file,"Reserved1\t\t%08lx\n", i->Reserved1); + fprintf (file,"SizeOfImage\t\t%08lx\n", i->SizeOfImage); + fprintf (file,"SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders); + fprintf (file,"CheckSum\t\t%08lx\n", i->CheckSum); fprintf (file,"Subsystem\t\t%08x\n", i->Subsystem); fprintf (file,"DllCharacteristics\t%08x\n", i->DllCharacteristics); - fprintf (file,"SizeOfStackReserve\t%08x\n", i->SizeOfStackReserve); - fprintf (file,"SizeOfStackCommit\t%08x\n", i->SizeOfStackCommit); - fprintf (file,"SizeOfHeapReserve\t%08x\n", i->SizeOfHeapReserve); - fprintf (file,"SizeOfHeapCommit\t%08x\n", i->SizeOfHeapCommit); - fprintf (file,"LoaderFlags\t\t%08x\n", i->LoaderFlags); - fprintf (file,"NumberOfRvaAndSizes\t%08x\n", i->NumberOfRvaAndSizes); + fprintf (file,"SizeOfStackReserve\t"); + fprintf_vma (file, i->SizeOfStackReserve); + fprintf (file,"SizeOfStackCommit\t"); + fprintf_vma (file, i->SizeOfStackCommit); + fprintf (file,"SizeOfHeapReserve\t"); + fprintf_vma (file, i->SizeOfHeapReserve); + fprintf (file,"SizeOfHeapCommit\t"); + fprintf_vma (file, i->SizeOfHeapCommit); + fprintf (file,"LoaderFlags\t\t%08lx\n", i->LoaderFlags); + fprintf (file,"NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes); for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++) { - fprintf(file, "Entry %2d %08x %08x\n", - j, - i->DataDirectory[j].VirtualAddress, - i->DataDirectory[j].Size); + fprintf (file, "Entry %2d ", j); + fprintf_vma (file, i->DataDirectory[j].VirtualAddress); + fprintf (file, " %08lx\n", i->DataDirectory[j].Size); } + + return true; } static boolean @@ -874,6 +874,7 @@ srec_write_record (abfd, type, address, data, end) CONST bfd_byte *src = data; char *dst = buffer; char *length; + bfd_size_type wrlen; *dst++ = 'S'; *dst++ = '0' + type; @@ -916,7 +917,8 @@ srec_write_record (abfd, type, address, data, end) *dst++ = '\r'; *dst++ = '\n'; - if (bfd_write ((PTR) buffer, 1, dst - buffer, abfd) != dst - buffer) + wrlen = dst - buffer; + if (bfd_write ((PTR) buffer, 1, wrlen, abfd) != wrlen) return false; return true; } @@ -1032,8 +1034,7 @@ srec_write_symbols (abfd) && s->name[0] != 't') { /* Just dump out non debug symbols */ - - int l; + bfd_size_type l; char buf2[40], *p; sprintf_vma (buf2, diff --git a/bfd/sunos.c b/bfd/sunos.c index 2e2f1fd..e3d0699 100644 --- a/bfd/sunos.c +++ b/bfd/sunos.c @@ -89,7 +89,7 @@ struct sunos_dynamic_info /* Dynamic information. */ struct internal_sun4_dynamic_link dyninfo; /* Number of dynamic symbols. */ - long dynsym_count; + unsigned long dynsym_count; /* Read in nlists for dynamic symbols. */ struct external_nlist *dynsym; /* asymbol structures for dynamic symbols. */ @@ -97,7 +97,7 @@ struct sunos_dynamic_info /* Read in dynamic string table. */ char *dynstr; /* Number of dynamic relocs. */ - long dynrel_count; + unsigned long dynrel_count; /* Read in dynamic relocs. This may be reloc_std_external or reloc_ext_external. */ PTR dynrel; @@ -122,7 +122,7 @@ sunos_read_dynamic_info (abfd) { struct sunos_dynamic_info *info; asection *dynsec; - file_ptr dynoff; + bfd_vma dynoff; struct external_sun4_dynamic dyninfo; unsigned long dynver; struct external_sun4_dynamic_link linkinfo; @@ -177,7 +177,7 @@ sunos_read_dynamic_info (abfd) else dynsec = obj_datasec (abfd); dynoff -= bfd_get_section_vma (abfd, dynsec); - if (dynoff < 0 || dynoff > bfd_section_size (abfd, dynsec)) + if (dynoff > bfd_section_size (abfd, dynsec)) return true; /* This executable appears to be dynamically linked in a way that we @@ -207,13 +207,15 @@ sunos_read_dynamic_info (abfd) info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab) / EXTERNAL_NLIST_SIZE); BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE - == info->dyninfo.ld_symbols - info->dyninfo.ld_stab); + == (unsigned long) (info->dyninfo.ld_symbols + - info->dyninfo.ld_stab)); /* Similarly, the relocs end at the hash table. */ info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel) / obj_reloc_entry_size (abfd)); BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd) - == info->dyninfo.ld_hash - info->dyninfo.ld_rel); + == (unsigned long) (info->dyninfo.ld_hash + - info->dyninfo.ld_rel)); info->valid = true; @@ -249,7 +251,7 @@ sunos_canonicalize_dynamic_symtab (abfd, storage) asymbol **storage; { struct sunos_dynamic_info *info; - long i; + unsigned long i; /* Get the general dynamic information. */ if (obj_aout_dynamic_info (abfd) == NULL) @@ -422,7 +424,7 @@ sunos_canonicalize_dynamic_reloc (abfd, storage, syms) asymbol **syms; { struct sunos_dynamic_info *info; - long i; + unsigned long i; /* Get the general dynamic information. */ if (obj_aout_dynamic_info (abfd) == (PTR) NULL) @@ -1520,7 +1522,7 @@ sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size) relend = relocs + rel_size / RELOC_EXT_SIZE; for (rel = relocs; rel < relend; rel++) { - int r_index; + unsigned int r_index; int r_extern; int r_type; struct sunos_link_hash_entry *h = NULL; diff --git a/bfd/tekhex.c b/bfd/tekhex.c index 12ab48f..48d7e5c 100644 --- a/bfd/tekhex.c +++ b/bfd/tekhex.c @@ -1,5 +1,5 @@ /* BFD backend for Extended Tektronix Hex Format objects. - Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>. @@ -17,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* SUBSECTION @@ -72,6 +72,7 @@ serial protocol, so big files are unlikely, so we keep a list of 8k chunks #include "bfd.h" #include "sysdep.h" #include "libbfd.h" +#include "libiberty.h" typedef struct { @@ -87,23 +88,17 @@ typedef struct tekhex_symbol_struct } tekhex_symbol_type; -static char digs[] = "0123456789ABCDEF"; +static const char digs[] = "0123456789ABCDEF"; static char sum_block[256]; -/* Horrible ascii dependent macros for converting between hex and - binary */ - -#define CHARS_IN_SET 256 -static char hex_value[CHARS_IN_SET]; - #define NOT_HEX 20 -#define NIBBLE(x) hex_value[x] +#define NIBBLE(x) hex_value(x) #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1])) #define TOHEX(d,x) \ (d)[1] = digs[(x) & 0xf]; \ (d)[0] = digs[((x)>>4)&0xf]; -#define ISHEX(x) (hex_value[x] != NOT_HEX) +#define ISHEX(x) hex_p(x) /* Here's an example @@ -223,24 +218,8 @@ tekhex_init () if (inited == false) { - inited = true; - - for (i = 0; i < CHARS_IN_SET; i++) - { - hex_value[i] = NOT_HEX; - } - - for (i = 0; i < 10; i++) - { - hex_value[i + '0'] = i; - - } - for (i = 0; i < 6; i++) - { - hex_value[i + 'a'] = i + 10; - hex_value[i + 'A'] = i + 10; - } + hex_init (); val = 0; for (i = 0; i < 10; i++) { @@ -305,13 +284,13 @@ getvalue (srcp) { char *src = *srcp; bfd_vma value = 0; - unsigned int len = hex_value[*src++]; + unsigned int len = hex_value(*src++); if (len == 0) len = 16; while (len--) { - value = value << 4 | hex_value[*src++]; + value = value << 4 | hex_value(*src++); } *srcp = src; return value; @@ -324,7 +303,7 @@ getsym (dstp, srcp) { char *src = *srcp; unsigned int i; - unsigned int len = hex_value[*src++]; + unsigned int len = hex_value(*src++); if (len == 0) len = 16; @@ -350,7 +329,6 @@ find_chunk (abfd, vma) if (!d) { char *sname = bfd_alloc (abfd, 12); - asection *s; /* No chunk for this address, so make one up */ d = (struct data_struct *) @@ -392,7 +370,7 @@ first_phase (abfd, type, src) char type; char *src; { - asection *section = &bfd_abs_section; + asection *section = bfd_abs_section_ptr; int len; char sym[17]; /* A symbol can only be 16chars long */ @@ -432,15 +410,13 @@ first_phase (abfd, type, src) { switch (*src) { - asection *s; - case '1': /* section range */ src++; section->vma = getvalue (&src); section->_raw_size = getvalue (&src) - section->vma; section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC; break; - + case '0': case '2': case '3': case '4': @@ -504,7 +480,6 @@ static void char buffer[MAXCHUNK]; char *src = buffer; char type; - bfd_vma address = 0; /* Find first '%' */ eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1); @@ -591,7 +566,6 @@ tekhex_object_p (abfd) bfd *abfd; { char b[4]; - asection *section; tekhex_init (); @@ -608,7 +582,7 @@ tekhex_object_p (abfd) return abfd->xvec; } -static boolean +static void move_section_contents (abfd, section, locationp, offset, count, get) bfd *abfd; asection *section; @@ -797,6 +771,7 @@ out (abfd, type, start, end) int sum = 0; char *s; char front[6]; + bfd_size_type wrlen; front[0] = '%'; TOHEX (front + 1, end - start + 5); @@ -804,17 +779,18 @@ out (abfd, type, start, end) for (s = start; s < end; s++) { - sum += sum_block[*s]; + sum += sum_block[(unsigned char) *s]; } - sum += sum_block[front[1]]; /* length */ - sum += sum_block[front[2]]; - sum += sum_block[front[3]]; /* type */ + sum += sum_block[(unsigned char) front[1]]; /* length */ + sum += sum_block[(unsigned char) front[2]]; + sum += sum_block[(unsigned char) front[3]]; /* type */ TOHEX (front + 4, sum); if (bfd_write (front, 1, 6, abfd) != 6) abort (); end[0] = '\n'; - if (bfd_write (start, 1, end - start + 1, abfd) != end - start + 1) + wrlen = end - start + 1; + if (bfd_write (start, 1, wrlen, abfd) != wrlen) abort (); } @@ -825,8 +801,6 @@ tekhex_write_object_contents (abfd) int bytes_written; char buffer[100]; asymbol **p; - tdata_type *tdata = abfd->tdata.tekhex_data; - tekhex_data_list_type *list; asection *s; struct data_struct *d; @@ -929,7 +903,7 @@ tekhex_write_object_contents (abfd) } /* And the terminator */ - if (bfd_write ("%7081010\n", 1, 9, abfd) != 9) + if (bfd_write ("%0781010\n", 1, 9, abfd) != 9) abort (); return true; } @@ -1007,6 +981,8 @@ tekhex_print_symbol (ignore_abfd, filep, symbol, how) #define tekhex_get_lineno _bfd_nosymbols_get_lineno #define tekhex_find_nearest_line _bfd_nosymbols_find_nearest_line #define tekhex_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol +#define tekhex_read_minisymbols _bfd_generic_read_minisymbols +#define tekhex_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol #define tekhex_bfd_get_relocated_section_contents \ bfd_generic_get_relocated_section_contents @@ -1014,6 +990,7 @@ tekhex_print_symbol (ignore_abfd, filep, symbol, how) #define tekhex_bfd_link_hash_table_create _bfd_generic_link_hash_table_create #define tekhex_bfd_link_add_symbols _bfd_generic_link_add_symbols #define tekhex_bfd_final_link _bfd_generic_final_link +#define tekhex_bfd_link_split_section _bfd_generic_link_split_section const bfd_target tekhex_vec = { diff --git a/bfd/versados.c b/bfd/versados.c index b555085..72bf141 100644 --- a/bfd/versados.c +++ b/bfd/versados.c @@ -387,7 +387,6 @@ process_otr (abfd, otr, pass) int pass; { unsigned long shift; - long val; unsigned char *srcp = otr->data; unsigned char *endp = (unsigned char *) otr + otr->size; unsigned int bits = (otr->map[0] << 24) @@ -398,7 +397,7 @@ process_otr (abfd, otr, pass) struct esdid *esdid = &EDATA (abfd, otr->esdid - 1); unsigned char *contents = esdid->contents; int need_contents = 0; - int dst_idx = esdid->pc; + unsigned int dst_idx = esdid->pc; for (shift = (1 << 31); shift && srcp < endp; shift >>= 1) { @@ -668,7 +667,7 @@ versados_get_section_contents (abfd, section, location, offset, count) memcpy (location, EDATA (abfd, section->target_index).contents + offset, - count); + (size_t) count); return true; } @@ -721,7 +720,7 @@ versados_get_symtab (abfd, alocation) asymbol **alocation; { unsigned int symcount = bfd_get_symcount (abfd); - int i; + unsigned int i; asymbol *s; versados_pass_2 (abfd); @@ -787,7 +786,7 @@ versados_canonicalize_reloc (abfd, section, relptr, symbols) arelent **relptr; asymbol **symbols; { - int count; + unsigned int count; arelent *src; versados_pass_2 (abfd); |