X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Fcoff-h8300.c;h=e9d19643e43f259a31ea7d414f9389434e99e558;hb=6245e162a6f358a9ff4b97764b6b65822b1d3e66;hp=e21c5b5484227487c56d0cced49cc5dd53de36e9;hpb=19852a2abd4f698ced10f575b2de381dd09e441d;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/coff-h8300.c b/bfd/coff-h8300.c index e21c5b5484..e9d19643e4 100644 --- a/bfd/coff-h8300.c +++ b/bfd/coff-h8300.c @@ -1,6 +1,6 @@ -/* BFD back-end for Hitachi H8/300 COFF binaries. +/* BFD back-end for Renesas H8/300 COFF binaries. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002 + 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Written by Steve Chamberlain, . @@ -61,33 +61,33 @@ struct funcvec_hash_table static struct bfd_hash_entry * funcvec_hash_newfunc - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); + (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); static bfd_boolean funcvec_hash_table_init - PARAMS ((struct funcvec_hash_table *, bfd *, - struct bfd_hash_entry *(*) (struct bfd_hash_entry *, - struct bfd_hash_table *, - const char *))); + (struct funcvec_hash_table *, bfd *, + struct bfd_hash_entry *(*) (struct bfd_hash_entry *, + struct bfd_hash_table *, + const char *)); static bfd_reloc_status_type special - PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); + (bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **); static int select_reloc - PARAMS ((reloc_howto_type *)); + (reloc_howto_type *); static void rtype2howto - PARAMS ((arelent *, struct internal_reloc *)); + (arelent *, struct internal_reloc *); static void reloc_processing - PARAMS ((arelent *, struct internal_reloc *, asymbol **, bfd *, asection *)); + (arelent *, struct internal_reloc *, asymbol **, bfd *, asection *); static bfd_boolean h8300_symbol_address_p - PARAMS ((bfd *, asection *, bfd_vma)); + (bfd *, asection *, bfd_vma); static int h8300_reloc16_estimate - PARAMS ((bfd *, asection *, arelent *, unsigned int, - struct bfd_link_info *)); + (bfd *, asection *, arelent *, unsigned int, + struct bfd_link_info *); static void h8300_reloc16_extra_cases - PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, - bfd_byte *, unsigned int *, unsigned int *)); + (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, + bfd_byte *, unsigned int *, unsigned int *); static bfd_boolean h8300_bfd_link_add_symbols - PARAMS ((bfd *, struct bfd_link_info *)); + (bfd *, struct bfd_link_info *); /* To lookup a value in the function vector hash table. */ #define funcvec_hash_lookup(table, string, create, copy) \ @@ -111,8 +111,7 @@ struct h8300_coff_link_hash_table { struct funcvec_hash_table *funcvec_hash_table; }; -static struct bfd_link_hash_table *h8300_coff_link_hash_table_create - PARAMS ((bfd *)); +static struct bfd_link_hash_table *h8300_coff_link_hash_table_create (bfd *); /* Get the H8/300 COFF linker hash table from a link_info structure. */ @@ -123,10 +122,9 @@ static struct bfd_link_hash_table *h8300_coff_link_hash_table_create a new entry is added to the funcvec hash table. */ static struct bfd_hash_entry * -funcvec_hash_newfunc (entry, gen_table, string) - struct bfd_hash_entry *entry; - struct bfd_hash_table *gen_table; - const char *string; +funcvec_hash_newfunc (struct bfd_hash_entry *entry, + struct bfd_hash_table *gen_table, + const char *string) { struct funcvec_hash_entry *ret; struct funcvec_hash_table *table; @@ -156,13 +154,20 @@ funcvec_hash_newfunc (entry, gen_table, string) /* Bump the offset at which we store entries in the function vector. We'd like to bump up the size of the vectors section, but it's not easily available here. */ - if (bfd_get_mach (table->abfd) == bfd_mach_h8300) - table->offset += 2; - else if (bfd_get_mach (table->abfd) == bfd_mach_h8300h - || bfd_get_mach (table->abfd) == bfd_mach_h8300s) - table->offset += 4; - else - return NULL; + switch (bfd_get_mach (table->abfd)) + { + case bfd_mach_h8300: + case bfd_mach_h8300hn: + case bfd_mach_h8300sn: + table->offset += 2; + break; + case bfd_mach_h8300h: + case bfd_mach_h8300s: + table->offset += 4; + break; + default: + return NULL; + } /* Everything went OK. */ return (struct bfd_hash_entry *) ret; @@ -171,12 +176,12 @@ funcvec_hash_newfunc (entry, gen_table, string) /* Initialize the function vector hash table. */ static bfd_boolean -funcvec_hash_table_init (table, abfd, newfunc) - struct funcvec_hash_table *table; - bfd *abfd; - struct bfd_hash_entry *(*newfunc) - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, - const char *)); +funcvec_hash_table_init (struct funcvec_hash_table *table, + bfd *abfd, + struct bfd_hash_entry *(*newfunc) + (struct bfd_hash_entry *, + struct bfd_hash_table *, + const char *)) { /* Initialize our local fields, then call the generic initialization routine. */ @@ -190,8 +195,7 @@ funcvec_hash_table_init (table, abfd, newfunc) without using static variables. */ static struct bfd_link_hash_table * -h8300_coff_link_hash_table_create (abfd) - bfd *abfd; +h8300_coff_link_hash_table_create (bfd *abfd) { struct h8300_coff_link_hash_table *ret; bfd_size_type amt = sizeof (struct h8300_coff_link_hash_table); @@ -210,7 +214,7 @@ h8300_coff_link_hash_table_create (abfd) ret->vectors_sec = NULL; ret->funcvec_hash_table = NULL; - /* OK. Everything's intialized, return the base pointer. */ + /* OK. Everything's initialized, return the base pointer. */ return &ret->root.root; } @@ -224,15 +228,13 @@ h8300_coff_link_hash_table_create (abfd) the addend until the final link. */ static bfd_reloc_status_type -special (abfd, reloc_entry, symbol, data, input_section, output_bfd, - error_message) - bfd *abfd ATTRIBUTE_UNUSED; - arelent *reloc_entry ATTRIBUTE_UNUSED; - asymbol *symbol ATTRIBUTE_UNUSED; - PTR data ATTRIBUTE_UNUSED; - asection *input_section ATTRIBUTE_UNUSED; - bfd *output_bfd; - char **error_message ATTRIBUTE_UNUSED; +special (bfd *abfd ATTRIBUTE_UNUSED, + arelent *reloc_entry ATTRIBUTE_UNUSED, + asymbol *symbol ATTRIBUTE_UNUSED, + PTR data ATTRIBUTE_UNUSED, + asection *input_section ATTRIBUTE_UNUSED, + bfd *output_bfd, + char **error_message ATTRIBUTE_UNUSED) { if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; @@ -281,8 +283,9 @@ static reloc_howto_type howto_table[] = { #define SELECT_RELOC(x,howto) \ { x.r_type = select_reloc (howto); } -#define BADMAG(x) (H8300BADMAG (x) && H8300HBADMAG (x) && H8300SBADMAG (x)) -#define H8300 1 /* Customize coffcode.h */ +#define BADMAG(x) (H8300BADMAG (x) && H8300HBADMAG (x) && H8300SBADMAG (x) \ + && H8300HNBADMAG(x) && H8300SNBADMAG(x)) +#define H8300 1 /* Customize coffcode.h */ #define __A_MAGIC_SET__ /* Code to swap in the reloc. */ @@ -293,8 +296,7 @@ static reloc_howto_type howto_table[] = { dst->r_stuff[1] = 'C'; static int -select_reloc (howto) - reloc_howto_type *howto; +select_reloc (reloc_howto_type *howto) { return howto->type; } @@ -302,9 +304,7 @@ select_reloc (howto) /* 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; +rtype2howto (arelent *internal, struct internal_reloc *dst) { switch (dst->r_type) { @@ -385,24 +385,16 @@ rtype2howto (internal, dst) 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; +reloc_processing (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]; - } + relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; else - { - relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; - } + relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; relent->addend = reloc->r_offset; @@ -413,10 +405,7 @@ reloc_processing (relent, reloc, symbols, abfd, section) } static bfd_boolean -h8300_symbol_address_p (abfd, input_section, address) - bfd *abfd; - asection *input_section; - bfd_vma address; +h8300_symbol_address_p (bfd *abfd, asection *input_section, bfd_vma address) { asymbol **s; @@ -428,6 +417,7 @@ h8300_symbol_address_p (abfd, input_section, address) while (*s) { asymbol *p = *s; + if (p->section == input_section && (input_section->output_section->vma + input_section->output_offset @@ -447,12 +437,8 @@ h8300_symbol_address_p (abfd, input_section, address) in the howto table. This needs to be fixed. */ 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; +h8300_reloc16_estimate (bfd *abfd, asection *input_section, arelent *reloc, + unsigned int shrink, struct bfd_link_info *link_info) { bfd_vma value; bfd_vma dot; @@ -472,8 +458,8 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) /* Only examine the relocs which might be relaxable. */ switch (reloc->howto->type) { - /* This is the 16/24 bit absolute branch which could become an 8 bit - pc-relative branch. */ + /* This is the 16/24 bit absolute branch which could become an 8 bit + pc-relative branch. */ case R_JMP1: case R_JMPL1: /* Get the address of the target of this branch. */ @@ -594,17 +580,11 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) case R_MOV16B1: /* Get the address of the data referenced by this mov.b insn. */ value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); + value = bfd_h8300_pad_address (abfd, value); - /* The address is in 0xff00..0xffff inclusive on the h8300 or - 0xffff00..0xffffff inclusive on the h8300h, then we can - relax this mov.b */ - if ((bfd_get_mach (abfd) == bfd_mach_h8300 - && value >= 0xff00 - && value <= 0xffff) - || ((bfd_get_mach (abfd) == bfd_mach_h8300h - || bfd_get_mach (abfd) == bfd_mach_h8300s) - && value >= 0xffff00 - && value <= 0xffffff)) + /* If the address is in the top 256 bytes of the address space + then we can relax this instruction. */ + if (value >= 0xffffff00u) { /* Change the reloc type. */ reloc->howto = reloc->howto + 1; @@ -621,13 +601,9 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) case R_MOV24B1: /* Get the address of the data referenced by this mov.b insn. */ value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); + value = bfd_h8300_pad_address (abfd, value); - /* The address is in 0xffff00..0xffffff inclusive on the h8300h, - then we can relax this mov.b */ - if ((bfd_get_mach (abfd) == bfd_mach_h8300h - || bfd_get_mach (abfd) == bfd_mach_h8300s) - && value >= 0xffff00 - && value <= 0xffffff) + if (value >= 0xffffff00u) { /* Change the reloc type. */ reloc->howto = reloc->howto + 1; @@ -648,10 +624,11 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) case R_MOVL1: /* Get the address of the data referenced by this mov insn. */ value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); + value = bfd_h8300_pad_address (abfd, value); - /* If this address is in 0x0000..0x7fff inclusive or - 0xff8000..0xffffff inclusive, then it can be relaxed. */ - if (value <= 0x7fff || value >= 0xff8000) + /* If the address is a sign-extended 16-bit value then we can + relax this instruction. */ + if (value <= 0x7fff || value >= 0xffff8000u) { /* Change the reloc type. */ reloc->howto = howto_table + 17; @@ -678,15 +655,10 @@ h8300_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) FIXME: Not all relocations check for overflow! */ 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; +h8300_reloc16_extra_cases (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; @@ -720,7 +692,6 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, /* Everything looks OK. Apply the relocation and update the src/dst address appropriately. */ - bfd_put_8 (abfd, gap, data + dst_address); dst_address++; src_address++; @@ -752,7 +723,6 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, /* Everything looks OK. Apply the relocation and update the src/dst address appropriately. */ - bfd_put_16 (abfd, (bfd_vma) gap, data + dst_address); dst_address += 2; src_address += 2; @@ -765,27 +735,9 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, /* Get the address of the object referenced by this insn. */ value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); - /* Sanity check. */ - if (value <= 0xff - || (value >= 0x0000ff00 && value <= 0x0000ffff) - || (value >= 0x00ffff00 && value <= 0x00ffffff) - || (value >= 0xffffff00 && value <= 0xffffffff)) - { - /* Everything looks OK. Apply the relocation and update the - src/dst address appropriately. */ - - bfd_put_8 (abfd, value & 0xff, data + dst_address); - dst_address += 1; - src_address += 1; - } - else - { - 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, value & 0xff, data + dst_address); + dst_address += 1; + src_address += 1; /* All done. */ break; @@ -823,13 +775,14 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, src_address += 4; break; - /* A 16bit abolute relocation that was formerlly a 24/32bit + /* A 16bit absolute relocation that was formerly a 24/32bit absolute relocation. */ case R_MOVL2: value = bfd_coff_reloc16_get_value (reloc, link_info, input_section); + value = bfd_h8300_pad_address (abfd, value); /* Sanity check. */ - if (value <= 0x7fff || value >= 0xff8000) + if (value <= 0x7fff || value >= 0xffff8000u) { /* Insert the 16bit value into the proper location. */ bfd_put_16 (abfd, value, data + dst_address); @@ -1150,6 +1103,7 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, if (symbol->flags & BSF_LOCAL) { char *new_name = bfd_malloc ((bfd_size_type) strlen (name) + 9); + if (new_name == NULL) abort (); @@ -1178,21 +1132,28 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, src_address++; /* Now create an entry in the function vector itself. */ - if (bfd_get_mach (input_section->owner) == bfd_mach_h8300) - bfd_put_16 (abfd, - bfd_coff_reloc16_get_value (reloc, - link_info, - input_section), - vectors_sec->contents + h->offset); - else if (bfd_get_mach (input_section->owner) == bfd_mach_h8300h - || bfd_get_mach (input_section->owner) == bfd_mach_h8300s) - bfd_put_32 (abfd, - bfd_coff_reloc16_get_value (reloc, - link_info, - input_section), - vectors_sec->contents + h->offset); - else - abort (); + switch (bfd_get_mach (input_section->owner)) + { + case bfd_mach_h8300: + case bfd_mach_h8300hn: + case bfd_mach_h8300sn: + bfd_put_16 (abfd, + bfd_coff_reloc16_get_value (reloc, + link_info, + input_section), + vectors_sec->contents + h->offset); + break; + case bfd_mach_h8300h: + case bfd_mach_h8300s: + bfd_put_32 (abfd, + bfd_coff_reloc16_get_value (reloc, + link_info, + input_section), + vectors_sec->contents + h->offset); + break; + default: + abort (); + } /* Gross. We've already written the contents of the vector section before we get here... So we write it again with the new data. */ @@ -1226,9 +1187,7 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, selected static symbols to the bfd linker hash table. */ static bfd_boolean -h8300_bfd_link_add_symbols (abfd, info) - bfd *abfd; - struct bfd_link_info *info; +h8300_bfd_link_add_symbols (bfd *abfd, struct bfd_link_info *info) { asection *sec; struct funcvec_hash_table *funcvec_hash_table; @@ -1360,11 +1319,20 @@ h8300_bfd_link_add_symbols (abfd, info) /* Bump the size of the vectors section. Each vector takes 2 bytes on the h8300 and 4 bytes on the h8300h. */ - if (bfd_get_mach (abfd) == bfd_mach_h8300) - htab->vectors_sec->_raw_size += 2; - else if (bfd_get_mach (abfd) == bfd_mach_h8300h - || bfd_get_mach (abfd) == bfd_mach_h8300s) - htab->vectors_sec->_raw_size += 4; + switch (bfd_get_mach (abfd)) + { + case bfd_mach_h8300: + case bfd_mach_h8300hn: + case bfd_mach_h8300sn: + htab->vectors_sec->_raw_size += 2; + break; + case bfd_mach_h8300h: + case bfd_mach_h8300s: + htab->vectors_sec->_raw_size += 4; + break; + default: + abort (); + } } } } @@ -1403,4 +1371,4 @@ h8300_bfd_link_add_symbols (abfd, info) bfd_coff_reloc16_get_relocated_section_contents #define coff_bfd_relax_section bfd_coff_reloc16_relax_section -CREATE_BIG_COFF_TARGET_VEC (h8300coff_vec, "coff-h8300", BFD_IS_RELAXABLE, 0, '_', NULL) +CREATE_BIG_COFF_TARGET_VEC (h8300coff_vec, "coff-h8300", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)