home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / coff-sparc.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  10KB  |  242 lines

  1. /* BFD back-end for Sparc COFF files.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "bfd.h"
  22. #include "sysdep.h"
  23. #include "libbfd.h"
  24. #include "obstack.h"
  25. #include "coff/sparc.h"
  26. #include "coff/internal.h"
  27. #include "libcoff.h"
  28.  
  29. #define BADMAG(x) ((x).f_magic != SPARCMAGIC)
  30.  
  31. enum reloc_type
  32.   {
  33.     R_SPARC_NONE = 0,
  34.     R_SPARC_8,        R_SPARC_16,        R_SPARC_32, 
  35.     R_SPARC_DISP8,    R_SPARC_DISP16,        R_SPARC_DISP32, 
  36.     R_SPARC_WDISP30,    R_SPARC_WDISP22,
  37.     R_SPARC_HI22,    R_SPARC_22,
  38.     R_SPARC_13,        R_SPARC_LO10,
  39.     R_SPARC_GOT10,    R_SPARC_GOT13,        R_SPARC_GOT22,
  40.     R_SPARC_PC10,    R_SPARC_PC22,
  41.     R_SPARC_WPLT30,
  42.     R_SPARC_COPY,
  43.     R_SPARC_GLOB_DAT,    R_SPARC_JMP_SLOT,
  44.     R_SPARC_RELATIVE,
  45.     R_SPARC_UA32,
  46.     R_SPARC_max
  47.   };
  48.  
  49. #if 0
  50. static CONST char *CONST reloc_type_names[] =
  51. {
  52.   "R_SPARC_NONE",
  53.   "R_SPARC_8",        "R_SPARC_16",        "R_SPARC_32",
  54.   "R_SPARC_DISP8",    "R_SPARC_DISP16",    "R_SPARC_DISP32",
  55.   "R_SPARC_WDISP30",    "R_SPARC_WDISP22",
  56.   "R_SPARC_HI22",    "R_SPARC_22",
  57.   "R_SPARC_13",        "R_SPARC_LO10",
  58.   "R_SPARC_GOT10",    "R_SPARC_GOT13",    "R_SPARC_GOT22",
  59.   "R_SPARC_PC10",    "R_SPARC_PC22",
  60.   "R_SPARC_WPLT30",
  61.   "R_SPARC_COPY",
  62.   "R_SPARC_GLOB_DAT",    "R_SPARC_JMP_SLOT",
  63.   "R_SPARC_RELATIVE",
  64.   "R_SPARC_UA32",
  65. };
  66. #endif
  67.  
  68. /* This is stolen pretty directly from elf.c.  */
  69. static bfd_reloc_status_type
  70. bfd_coff_generic_reloc (abfd, reloc_entry, symbol, data, input_section,
  71.             output_bfd)
  72.      bfd *abfd;
  73.      arelent *reloc_entry;
  74.      asymbol *symbol;
  75.      PTR data;
  76.      asection *input_section;
  77.      bfd *output_bfd;
  78. {
  79.   if (output_bfd != (bfd *) NULL
  80.       && (symbol->flags & BSF_SECTION_SYM) == 0
  81.       && reloc_entry->addend == 0)
  82.     {
  83.       reloc_entry->address += input_section->output_offset;
  84.       return bfd_reloc_ok;
  85.     }
  86.  
  87.   return bfd_reloc_continue;
  88. }
  89.  
  90. static reloc_howto_type coff_sparc_howto_table[] = 
  91. {
  92.   HOWTO(R_SPARC_NONE,    0,0, 0,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_NONE",    false,0,0x00000000,true),
  93.   HOWTO(R_SPARC_8,       0,0, 8,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_8",       false,0,0x000000ff,true),
  94.   HOWTO(R_SPARC_16,      0,1,16,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_16",      false,0,0x0000ffff,true),
  95.   HOWTO(R_SPARC_32,      0,2,32,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_32",      false,0,0xffffffff,true),
  96.   HOWTO(R_SPARC_DISP8,   0,0, 8,true, 0,complain_overflow_signed,  bfd_coff_generic_reloc,"R_SPARC_DISP8",   false,0,0x000000ff,true),
  97.   HOWTO(R_SPARC_DISP16,  0,1,16,true, 0,complain_overflow_signed,  bfd_coff_generic_reloc,"R_SPARC_DISP16",  false,0,0x0000ffff,true),
  98.   HOWTO(R_SPARC_DISP32,  0,2,32,true, 0,complain_overflow_signed,  bfd_coff_generic_reloc,"R_SPARC_DISP32",  false,0,0x00ffffff,true),
  99.   HOWTO(R_SPARC_WDISP30, 2,2,30,true, 0,complain_overflow_signed,  bfd_coff_generic_reloc,"R_SPARC_WDISP30", false,0,0x3fffffff,true),
  100.   HOWTO(R_SPARC_WDISP22, 2,2,22,true, 0,complain_overflow_signed,  bfd_coff_generic_reloc,"R_SPARC_WDISP22", false,0,0x003fffff,true),
  101.   HOWTO(R_SPARC_HI22,   10,2,22,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_HI22",    false,0,0x003fffff,true),
  102.   HOWTO(R_SPARC_22,      0,2,22,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_22",      false,0,0x003fffff,true),
  103.   HOWTO(R_SPARC_13,      0,2,13,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_13",      false,0,0x00001fff,true),
  104.   HOWTO(R_SPARC_LO10,    0,2,10,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_LO10",    false,0,0x000003ff,true),
  105.   HOWTO(R_SPARC_GOT10,   0,2,10,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT10",   false,0,0x000003ff,true),
  106.   HOWTO(R_SPARC_GOT13,   0,2,13,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT13",   false,0,0x00001fff,true),
  107.   HOWTO(R_SPARC_GOT22,  10,2,22,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_GOT22",   false,0,0x003fffff,true),
  108.   HOWTO(R_SPARC_PC10,    0,2,10,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC10",    false,0,0x000003ff,true),
  109.   HOWTO(R_SPARC_PC22,    0,2,22,false,0,complain_overflow_bitfield,bfd_coff_generic_reloc,"R_SPARC_PC22",    false,0,0x003fffff,true),
  110.   HOWTO(R_SPARC_WPLT30,  0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_WPLT30",  false,0,0x00000000,true),
  111.   HOWTO(R_SPARC_COPY,    0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_COPY",    false,0,0x00000000,true),
  112.   HOWTO(R_SPARC_GLOB_DAT,0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_GLOB_DAT",false,0,0x00000000,true),
  113.   HOWTO(R_SPARC_JMP_SLOT,0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_JMP_SLOT",false,0,0x00000000,true),
  114.   HOWTO(R_SPARC_RELATIVE,0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_RELATIVE",false,0,0x00000000,true),
  115.   HOWTO(R_SPARC_UA32,    0,0,00,false,0,complain_overflow_dont,    bfd_coff_generic_reloc,"R_SPARC_UA32",    false,0,0x00000000,true),
  116. };
  117.  
  118. struct coff_reloc_map {
  119.   unsigned char bfd_reloc_val;
  120.   unsigned char coff_reloc_val;
  121. };
  122.  
  123. static CONST struct coff_reloc_map sparc_reloc_map[] =
  124. {
  125.   { BFD_RELOC_NONE, R_SPARC_NONE, },
  126.   { BFD_RELOC_16, R_SPARC_16, },
  127.   { BFD_RELOC_8, R_SPARC_8 },
  128.   { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
  129.   { BFD_RELOC_CTOR, R_SPARC_32 }, /* @@ Assumes 32 bits.  */
  130.   { BFD_RELOC_32, R_SPARC_32 },
  131.   { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
  132.   { BFD_RELOC_HI22, R_SPARC_HI22 },
  133.   { BFD_RELOC_LO10, R_SPARC_LO10, },
  134.   { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
  135.   { BFD_RELOC_SPARC22, R_SPARC_22 },
  136.   { BFD_RELOC_SPARC13, R_SPARC_13 },
  137.   { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
  138.   { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
  139.   { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
  140.   { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
  141.   { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
  142.   { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
  143.   { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
  144.   { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
  145.   { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
  146.   { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
  147.   { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
  148.   /*  { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
  149. };
  150.  
  151. static CONST struct reloc_howto_struct *
  152. DEFUN (coff_sparc_reloc_type_lookup, (abfd, code),
  153.        bfd *abfd AND
  154.        bfd_reloc_code_real_type code)
  155. {
  156.   int i;
  157.   for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct coff_reloc_map); i++)
  158.     {
  159.       if (sparc_reloc_map[i].bfd_reloc_val == code)
  160.     return &coff_sparc_howto_table[(int) sparc_reloc_map[i].coff_reloc_val];
  161.     }
  162.   return 0;
  163. }
  164. #define coff_bfd_reloc_type_lookup    coff_sparc_reloc_type_lookup
  165.  
  166. static void
  167. DEFUN (rtype2howto, (cache_ptr, dst),
  168.        arelent *cache_ptr AND
  169.        struct internal_reloc *dst)
  170. {
  171.   BFD_ASSERT (dst->r_type < (unsigned int) R_SPARC_max);
  172.   cache_ptr->howto = &coff_sparc_howto_table[dst->r_type];
  173. }
  174.  
  175. #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
  176.  
  177. #define SWAP_IN_RELOC_OFFSET    bfd_h_get_32
  178. #define SWAP_OUT_RELOC_OFFSET    bfd_h_put_32
  179. /* This is just like the standard one, except for the addition of the
  180.    last line, the adjustment of the addend.  */
  181. #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)     \
  182.         if (ptr && bfd_asymbol_bfd(ptr) == abfd    \
  183.         && !bfd_is_com_section(ptr->section)    \
  184.         && !(ptr->flags & BSF_OLD_COMMON))    \
  185.         {                        \
  186.         cache_ptr->addend = -(ptr->section->vma + ptr->value);    \
  187.         }                        \
  188.         else {                    \
  189.         cache_ptr->addend = 0;            \
  190.         }                        \
  191.         cache_ptr->addend += dst.r_offset;
  192.  
  193. #define __A_MAGIC_SET__
  194.  
  195. #include "coffcode.h"
  196.  
  197. bfd_target
  198. #ifdef TARGET_SYM
  199.   TARGET_SYM =
  200. #else
  201.   sparccoff_vec =
  202. #endif
  203. {
  204. #ifdef TARGET_NAME
  205.   TARGET_NAME,
  206. #else
  207.   "coff-sparc",            /* name */
  208. #endif
  209.   bfd_target_coff_flavour,
  210.   true,            /* data byte order is big */
  211.   true,            /* header byte order is big */
  212.  
  213.   (HAS_RELOC | EXEC_P |        /* object flags */
  214.    HAS_LINENO | HAS_DEBUG |
  215.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
  216.  
  217.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  218.   0,                /* leading underscore */
  219.   '/',                /* ar_pad_char */
  220.   15,                /* ar_max_namelen */
  221.  
  222.   2,                /* minimum alignment power */
  223.   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  224.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  225.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
  226.   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  227.      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  228.      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  229.  
  230. /* Note that we allow an object file to be treated as a core file as well. */
  231.     {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  232.        bfd_generic_archive_p, coff_object_p},
  233.     {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
  234.        bfd_false},
  235.     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
  236.        _bfd_write_archive_contents, bfd_false},
  237.  
  238.   JUMP_TABLE(coff),
  239.   COFF_SWAP_TABLE,
  240. };
  241.  
  242.