* h8300-dis.c: Fix formatting.
[binutils-gdb.git] / bfd / coff-h8300.c
index 6e7ba387f45a4304d1deb58ace910f449088fdf2..1a4bcdd25b1a27f1656ca16a6679920ebc33e5e6 100644 (file)
@@ -1,5 +1,6 @@
 /* BFD back-end for Hitachi H8/300 COFF binaries.
-   Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
+   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
+   Free Software Foundation, Inc.
    Written by Steve Chamberlain, <sac@cygnus.com>.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -20,7 +21,6 @@ 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 "genlink.h"
@@ -204,13 +204,13 @@ h8300_coff_link_hash_table_create (abfd)
 static bfd_reloc_status_type
 special (abfd, reloc_entry, symbol, data, input_section, output_bfd,
                 error_message)
-     bfd *abfd;
-     arelent *reloc_entry;
-     asymbol *symbol;
-     PTR data;
-     asection *input_section;
+     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;
+     char **error_message ATTRIBUTE_UNUSED;
 {
   if (output_bfd == (bfd *) NULL)
     return bfd_reloc_continue;
@@ -359,7 +359,7 @@ rtype2howto (internal, dst)
 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
 
 
-/* Perform any necessaru magic to the addend in a reloc entry */
+/* Perform any necessary magic to the addend in a reloc entry */
 
 
 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
@@ -796,7 +796,7 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
       /* Sanity check.  */
-      if (value < 0x8000 || value > 0xff8000)
+      if (value <= 0x7fff || value >= 0xff8000)
        {
          /* Insert the 16bit value into the proper location.  */
          bfd_put_16 (abfd, value, data + dst_address);
@@ -901,6 +901,10 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
          /* Write it.  */
          bfd_put_8 (abfd, tmp, data + dst_address - 2);
          break;
+       case 0x5c:
+         /* bsr:16 -> bsr:8 */
+         bfd_put_8 (abfd, 0x55, data + dst_address - 2);
+         break;
 
        default:
          abort ();
@@ -1061,13 +1065,13 @@ h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr,
        symbol = *(reloc->sym_ptr_ptr);
        value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
        if (symbol == bfd_abs_section_ptr->symbol
-           || (value >= 0 && value <= 0xff))
+           || value <= 0xff)
          {
            /* This should be handled in a manner very similar to
               R_RELBYTES.   If the value is in range, then just slam
               the value into the right location.  Else trigger a
               reloc overflow callback.  */
-           if (value >= 0 && value <= 0xff)
+           if (value <= 0xff)
              {
                bfd_put_8 (abfd, value, data + dst_address);
                dst_address += 1;
@@ -1226,7 +1230,7 @@ h8300_bfd_link_add_symbols(abfd, info)
      additional space in the .vectors section as needed.  */
   for (sec = abfd->sections; sec; sec = sec->next)
     {
-      unsigned long reloc_size, reloc_count, i;
+      long reloc_size, reloc_count, i;
       asymbol **symbols;
       arelent **relocs;
 
@@ -1244,6 +1248,11 @@ h8300_bfd_link_add_symbols(abfd, info)
         saved in the above call.  */
       symbols = _bfd_generic_link_get_symbols(abfd);
       reloc_count = bfd_canonicalize_reloc (abfd, sec, relocs, symbols);
+      if (reloc_count <= 0)
+       {
+         free (relocs);
+         continue;
+       }
 
       /* Now walk through all the relocations in this section.  */
       for (i = 0; i < reloc_count; i++)
@@ -1341,44 +1350,4 @@ h8300_bfd_link_add_symbols(abfd, info)
 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
 
 
-
-const bfd_target h8300coff_vec =
-{
-  "coff-h8300",                        /* name */
-  bfd_target_coff_flavour,
-  BFD_ENDIAN_BIG,              /* data byte order is big */
-  BFD_ENDIAN_BIG,              /* 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 */
-  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
-  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* data */
-  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
-  bfd_getb32, bfd_getb_signed_32, bfd_putb32,
-  bfd_getb16, bfd_getb_signed_16, bfd_putb16,  /* 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,
-};
+CREATE_BIG_COFF_TARGET_VEC (h8300coff_vec, "coff-h8300", BFD_IS_RELAXABLE, 0, '_', NULL)