home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / bfd / coff-sh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.8 KB  |  225 lines

  1. /* BFD back-end for Hitachi Super-H COFF binaries.
  2.    Copyright 1993, 1994, 1995 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.
  4.    Written by Steve Chamberlain, <sac@cygnus.com>.
  5.  
  6. This file is part of BFD, the Binary File Descriptor library.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "bfd.h"
  23. #include "sysdep.h"
  24. #include "obstack.h"
  25. #include "libbfd.h"
  26. #include "bfdlink.h"
  27. #include "coff/sh.h"
  28. #include "coff/internal.h"
  29. #include "libcoff.h"
  30.  
  31. static bfd_reloc_status_type sh_reloc();
  32.  
  33. #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
  34.  
  35. /*#define COFF_LONG_FILENAMES*/
  36.  
  37. static reloc_howto_type r_imm32 =
  38.   {R_SH_IMM32,  0, 2, 32, false, 0, 
  39.      complain_overflow_bitfield, sh_reloc,"r_imm32",    true, 0xffffffff,0xffffffff, false};
  40.  
  41.  
  42. #define BADMAG(x) SHBADMAG(x)
  43. #define SH 1            /* Customize coffcode.h */
  44.  
  45. #define __A_MAGIC_SET__
  46.  
  47. /* Code to swap in the reloc */
  48. #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
  49.   dst->r_stuff[0] = 'S'; \
  50.   dst->r_stuff[1] = 'C';
  51.  
  52. /* Code to turn a r_type into a howto ptr, uses the above howto table.  */
  53. static long
  54. get_symbol_value (symbol)       
  55.      asymbol *symbol;
  56. {                                             
  57.   long relocation = 0;
  58.  
  59.   if (bfd_is_com_section (symbol->section))
  60.   {
  61.     relocation = 0;                           
  62.   }
  63.   else 
  64.   {                                      
  65.     relocation = symbol->value +
  66.      symbol->section->output_section->vma +
  67.       symbol->section->output_offset;
  68.   }                                           
  69.  
  70.   return(relocation);
  71. }
  72.  
  73. #define RTYPE2HOWTO(x,y) ((x)->howto = &r_imm32)
  74.  
  75. /* this function is in charge of performing all the 29k relocations */
  76.  
  77. static bfd_reloc_status_type
  78. sh_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
  79.         error_message)
  80.      bfd *abfd;
  81.      arelent *reloc_entry;
  82.      asymbol *symbol_in;
  83.      PTR data;
  84.      asection *input_section;
  85.      bfd *output_bfd;
  86.      char **error_message;
  87. {
  88.   /* the consth relocation comes in two parts, we have to remember
  89.      the state between calls, in these variables */
  90.   unsigned long insn;
  91.   unsigned long sym_value;
  92.   unsigned short r_type;
  93.  
  94.   unsigned long addr = reloc_entry->address ; /*+ input_section->vma*/
  95.   bfd_byte  *hit_data =addr + (bfd_byte *)(data);
  96.     
  97.   r_type = reloc_entry->howto->type;
  98.  
  99.   if (output_bfd) {
  100.     /* Partial linking - do nothing */
  101.     reloc_entry->address += input_section->output_offset;
  102.     return bfd_reloc_ok;
  103.   }
  104.  
  105.   if (symbol_in != NULL
  106.       && bfd_is_und_section (symbol_in->section))
  107.     {
  108.       /* Keep the state machine happy in case we're called again */
  109.       return (bfd_reloc_undefined);
  110.     }
  111.  
  112.  
  113.   sym_value = get_symbol_value(symbol_in);
  114.  
  115.   switch (r_type) 
  116.     {
  117.     case R_SH_IMM32:
  118.       insn = sym_value + reloc_entry->addend;  
  119.       insn += bfd_get_32 (abfd, hit_data);
  120.       bfd_put_32(abfd, insn, hit_data);
  121.       break;
  122.     default:
  123.       *error_message = "Unrecognized reloc";
  124.       return (bfd_reloc_dangerous);
  125.     }
  126.  
  127.  
  128.   return(bfd_reloc_ok);    
  129. }
  130.  
  131. /* We use the special COFF backend linker.  */
  132. #define coff_relocate_section _bfd_coff_generic_relocate_section
  133.  
  134. #include "coffcode.h"
  135.  
  136. const bfd_target shcoff_vec =
  137. {
  138.   "coff-sh",            /* name */
  139.   bfd_target_coff_flavour,
  140.   true,                /* data byte order is big */
  141.   true,                /* header byte order is big */
  142.  
  143.   (HAS_RELOC | EXEC_P |        /* object flags */
  144.    HAS_LINENO | HAS_DEBUG |
  145.    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
  146.  
  147.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),    /* section flags */
  148.   '_',                /* leading symbol underscore */
  149.   '/',                /* ar_pad_char */
  150.   15,                /* ar_max_namelen */
  151.   2,                /* minimum section alignment */
  152.      bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  153.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  154.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
  155.      bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  156.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  157.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  158.  
  159.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  160.      bfd_generic_archive_p, _bfd_dummy_target},
  161.   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
  162.      bfd_false},
  163.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  164.      _bfd_write_archive_contents, bfd_false},
  165.  
  166.      BFD_JUMP_TABLE_GENERIC (coff),
  167.      BFD_JUMP_TABLE_COPY (coff),
  168.      BFD_JUMP_TABLE_CORE (_bfd_nocore),
  169.      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
  170.      BFD_JUMP_TABLE_SYMBOLS (coff),
  171.      BFD_JUMP_TABLE_RELOCS (coff),
  172.      BFD_JUMP_TABLE_WRITE (coff),
  173.      BFD_JUMP_TABLE_LINK (coff),
  174.      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  175.  
  176.     COFF_SWAP_TABLE,
  177. };
  178.  
  179. const bfd_target shlcoff_vec =
  180. {
  181.   "coff-shl",            /* name */
  182.   bfd_target_coff_flavour,
  183.   false,            /* data byte order is little */
  184.   false,            /* header byte order is little endian too*/
  185.  
  186.   (HAS_RELOC | EXEC_P |        /* object flags */
  187.    HAS_LINENO | HAS_DEBUG |
  188.    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ),
  189.  
  190.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),    /* section flags */
  191.   '_',                /* leading symbol underscore */
  192.   '/',                /* ar_pad_char */
  193.   15,                /* ar_max_namelen */
  194.   2,                /* minimum section alignment */
  195.      bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  196.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  197.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  198.      bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  199.      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  200.      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  201.  
  202. /* Note that we use a special archive recognizer.
  203.    This is so that we only use one archive format for both
  204.    object file types */
  205.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  206.      _bfd_dummy_target, _bfd_dummy_target},   
  207.   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
  208.      bfd_false},
  209.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  210.      _bfd_write_archive_contents, bfd_false},
  211.  
  212.      BFD_JUMP_TABLE_GENERIC (coff),
  213.      BFD_JUMP_TABLE_COPY (coff),
  214.      BFD_JUMP_TABLE_CORE (_bfd_nocore),
  215.      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
  216.      BFD_JUMP_TABLE_SYMBOLS (coff),
  217.      BFD_JUMP_TABLE_RELOCS (coff),
  218.      BFD_JUMP_TABLE_WRITE (coff),
  219.      BFD_JUMP_TABLE_LINK (coff),
  220.      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  221.  
  222.     COFF_SWAP_TABLE,
  223. };
  224.  
  225.