Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elf32-d10v.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* D10V-specific support for 32-bit ELF
    2    Copyright 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
     2   Copyright 1996, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    33   Contributed by Martin Hunt (hunt@cygnus.com).
    44
     
    2828  PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
    2929static void d10v_info_to_howto_rel
    30   PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
    31 
    32 /* Use REL instead of RELA to save space */
    33 #define USE_REL
     30  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
     31static asection * elf32_d10v_gc_mark_hook
     32  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
     33           struct elf_link_hash_entry *, Elf_Internal_Sym *));
     34static bfd_boolean elf32_d10v_gc_sweep_hook
     35  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     36           const Elf_Internal_Rela *));
     37static bfd_boolean elf32_d10v_check_relocs
     38  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     39           const Elf_Internal_Rela *));
     40static bfd_boolean elf32_d10v_relocate_section
     41  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
     42           bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *,
     43           asection **));
     44
     45/* Use REL instead of RELA to save space.  */
     46#define USE_REL 1
    3447
    3548static reloc_howto_type elf_d10v_howto_table[] =
    36 {
    37   /* This reloc does nothing.  */
    38   HOWTO (R_D10V_NONE,           /* type */
    39          0,                     /* rightshift */
    40          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    41          32,                    /* bitsize */
    42          false,                 /* pc_relative */
    43          0,                     /* bitpos */
    44          complain_overflow_bitfield, /* complain_on_overflow */
    45          bfd_elf_generic_reloc, /* special_function */
    46          "R_D10V_NONE",         /* name */
    47          false,                 /* partial_inplace */
    48          0,                     /* src_mask */
    49          0,                     /* dst_mask */
    50          false),                /* pcrel_offset */
    51 
    52   /* An PC Relative 10-bit relocation, shifted by 2  */
    53   /* right container */
    54   HOWTO (R_D10V_10_PCREL_R,     /* type */
    55          2,                     /* rightshift */
    56          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    57          10,                    /* bitsize */
    58          true,                  /* pc_relative */
    59          0,                     /* bitpos */
    60          complain_overflow_bitfield, /* complain_on_overflow */
    61          bfd_elf_generic_reloc, /* special_function */
    62          "R_D10V_10_PCREL_R",   /* name */
    63          false,                 /* partial_inplace */
    64          0xff,                  /* src_mask */
    65          0xff,                  /* dst_mask */
    66          true),                 /* pcrel_offset */
    67 
    68   /* An PC Relative 10-bit relocation, shifted by 2  */
    69   /* left container */
    70   HOWTO (R_D10V_10_PCREL_L,     /* type */
    71          2,                     /* rightshift */
    72          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    73          10,                    /* bitsize */
    74          true,                  /* pc_relative */
    75          15,                    /* bitpos */
    76          complain_overflow_bitfield, /* complain_on_overflow */
    77          bfd_elf_generic_reloc, /* special_function */
    78          "R_D10V_10_PCREL_L",   /* name */
    79          false,                 /* partial_inplace */
    80          0x07f8000,                     /* src_mask */
    81          0x07f8000,             /* dst_mask */
    82          true),                 /* pcrel_offset */
    83 
    84   /* A 16 bit absolute relocation */
    85   HOWTO (R_D10V_16,             /* type */
    86          0,                     /* rightshift */
    87          1,                     /* size (0 = byte, 1 = short, 2 = long) */
    88          16,                    /* bitsize */
    89          false,                 /* pc_relative */
    90          0,                     /* bitpos */
    91          complain_overflow_dont, /* complain_on_overflow */
    92          bfd_elf_generic_reloc, /* special_function */
    93          "R_D10V_16",           /* name */
    94          false,                 /* partial_inplace */
    95          0xffff,                /* src_mask */
    96          0xffff,                /* dst_mask */
    97          false),                /* pcrel_offset */
    98 
    99   /* An 18 bit absolute relocation, right shifted 2 */
    100   HOWTO (R_D10V_18,             /* type */
    101          2,                     /* rightshift */
    102          1,                     /* size (0 = byte, 1 = short, 2 = long) */
    103          18,                    /* bitsize */
    104          false,                 /* pc_relative */
    105          0,                     /* bitpos */
    106          complain_overflow_dont, /* complain_on_overflow */
    107          bfd_elf_generic_reloc, /* special_function */
    108          "R_D10V_18",           /* name */
    109          false,                 /* partial_inplace */
    110          0xffff,                /* src_mask */
    111          0xffff,                /* dst_mask */
    112          false),                /* pcrel_offset */
    113 
    114   /* A relative 18 bit relocation, right shifted by 2  */
    115   HOWTO (R_D10V_18_PCREL,       /* type */
    116          2,                     /* rightshift */
    117          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    118          18,                    /* bitsize */
    119          true,                  /* pc_relative */
    120          0,                     /* bitpos */
    121          complain_overflow_signed, /* complain_on_overflow */
    122          bfd_elf_generic_reloc, /* special_function */
    123          "R_D10V_18_PCREL",     /* name */
    124          false,                 /* partial_inplace */
    125          0xffff,                /* src_mask */
    126          0xffff,                /* dst_mask */
    127          true),                 /* pcrel_offset */
    128 
    129   /* A 32 bit absolute relocation */
    130   HOWTO (R_D10V_32,             /* type */
    131          0,                     /* rightshift */
    132          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    133          32,                    /* bitsize */
    134          false,                 /* pc_relative */
    135          0,                     /* bitpos */
    136          complain_overflow_bitfield, /* complain_on_overflow */
    137          bfd_elf_generic_reloc, /* special_function */
    138          "R_D10V_32",           /* name */
    139          false,                 /* partial_inplace */
    140          0xffffffff,            /* src_mask */
    141          0xffffffff,            /* dst_mask */
    142          false),                /* pcrel_offset */
    143 
    144   /* GNU extension to record C++ vtable hierarchy */
    145   HOWTO (R_D10V_GNU_VTINHERIT, /* type */
    146          0,                     /* rightshift */
    147          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    148          0,                     /* bitsize */
    149          false,                 /* pc_relative */
    150          0,                     /* bitpos */
    151          complain_overflow_dont, /* complain_on_overflow */
    152          NULL,                  /* special_function */
    153          "R_D10V_GNU_VTINHERIT", /* name */
    154          false,                 /* partial_inplace */
    155          0,                     /* src_mask */
    156          0,                     /* dst_mask */
    157          false),                /* pcrel_offset */
    158 
    159   /* GNU extension to record C++ vtable member usage */
    160   HOWTO (R_D10V_GNU_VTENTRY,     /* type */
    161          0,                     /* rightshift */
    162          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    163          0,                     /* bitsize */
    164          false,                 /* pc_relative */
    165          0,                     /* bitpos */
    166          complain_overflow_dont, /* complain_on_overflow */
    167          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
    168          "R_D10V_GNU_VTENTRY",   /* name */
    169          false,                 /* partial_inplace */
    170          0,                     /* src_mask */
    171          0,                     /* dst_mask */
    172          false),                /* pcrel_offset */
    173 
    174 };
     49  {
     50    /* This reloc does nothing.  */
     51    HOWTO (R_D10V_NONE,         /* type */
     52           0,                   /* rightshift */
     53           2,                   /* size (0 = byte, 1 = short, 2 = long) */
     54           32,                  /* bitsize */
     55           FALSE,               /* pc_relative */
     56           0,                   /* bitpos */
     57           complain_overflow_dont, /* complain_on_overflow */
     58           bfd_elf_generic_reloc, /* special_function */
     59           "R_D10V_NONE",       /* name */
     60           FALSE,               /* partial_inplace */
     61           0,                   /* src_mask */
     62           0,                   /* dst_mask */
     63           FALSE),              /* pcrel_offset */
     64
     65    /* An PC Relative 10-bit relocation, shifted by 2  */
     66    /* right container */
     67    HOWTO (R_D10V_10_PCREL_R,   /* type */
     68           2,                   /* rightshift */
     69           2,                   /* size (0 = byte, 1 = short, 2 = long) */
     70           7,                   /* bitsize */
     71           TRUE,                /* pc_relative */
     72           0,                   /* bitpos */
     73           complain_overflow_bitfield, /* complain_on_overflow */
     74           bfd_elf_generic_reloc, /* special_function */
     75           "R_D10V_10_PCREL_R", /* name */
     76           FALSE,               /* partial_inplace */
     77           0xff,                /* src_mask */
     78           0xff,                /* dst_mask */
     79           TRUE),               /* pcrel_offset */
     80
     81    /* An PC Relative 10-bit relocation, shifted by 2  */
     82    /* left container */
     83    HOWTO (R_D10V_10_PCREL_L,   /* type */
     84           2,                   /* rightshift */
     85           2,                   /* size (0 = byte, 1 = short, 2 = long) */
     86           7,                   /* bitsize */
     87           TRUE,                /* pc_relative */
     88           15,                  /* bitpos */
     89           complain_overflow_bitfield, /* complain_on_overflow */
     90           bfd_elf_generic_reloc, /* special_function */
     91           "R_D10V_10_PCREL_L", /* name */
     92           FALSE,               /* partial_inplace */
     93           0x07f8000,           /* src_mask */
     94           0x07f8000,           /* dst_mask */
     95           TRUE),               /* pcrel_offset */
     96
     97    /* A 16 bit absolute relocation */
     98    HOWTO (R_D10V_16,           /* type */
     99           0,                   /* rightshift */
     100           1,                   /* size (0 = byte, 1 = short, 2 = long) */
     101           16,                  /* bitsize */
     102           FALSE,               /* pc_relative */
     103           0,                   /* bitpos */
     104           complain_overflow_dont, /* complain_on_overflow */
     105           bfd_elf_generic_reloc, /* special_function */
     106           "R_D10V_16",         /* name */
     107           FALSE,               /* partial_inplace */
     108           0xffff,              /* src_mask */
     109           0xffff,              /* dst_mask */
     110           FALSE),              /* pcrel_offset */
     111
     112    /* An 18 bit absolute relocation, right shifted 2 */
     113    HOWTO (R_D10V_18,           /* type */
     114           2,                   /* rightshift */
     115           1,                   /* size (0 = byte, 1 = short, 2 = long) */
     116           16,                  /* bitsize */
     117           FALSE,               /* pc_relative */
     118           0,                   /* bitpos */
     119           complain_overflow_dont, /* complain_on_overflow */
     120           bfd_elf_generic_reloc, /* special_function */
     121           "R_D10V_18",         /* name */
     122           FALSE,               /* partial_inplace */
     123           0xffff,              /* src_mask */
     124           0xffff,              /* dst_mask */
     125           FALSE),              /* pcrel_offset */
     126
     127    /* A relative 18 bit relocation, right shifted by 2  */
     128    HOWTO (R_D10V_18_PCREL,     /* type */
     129           2,                   /* rightshift */
     130           2,                   /* size (0 = byte, 1 = short, 2 = long) */
     131           15,                  /* bitsize */
     132           TRUE,                /* pc_relative */
     133           0,                   /* bitpos */
     134           complain_overflow_bitfield, /* complain_on_overflow */
     135           bfd_elf_generic_reloc, /* special_function */
     136           "R_D10V_18_PCREL",   /* name */
     137           FALSE,               /* partial_inplace */
     138           0xffff,              /* src_mask */
     139           0xffff,              /* dst_mask */
     140           TRUE),                       /* pcrel_offset */
     141
     142    /* A 32 bit absolute relocation */
     143    HOWTO (R_D10V_32,           /* type */
     144           0,                   /* rightshift */
     145           2,                   /* size (0 = byte, 1 = short, 2 = long) */
     146           32,                  /* bitsize */
     147           FALSE,               /* pc_relative */
     148           0,                   /* bitpos */
     149           complain_overflow_dont, /* complain_on_overflow */
     150           bfd_elf_generic_reloc, /* special_function */
     151           "R_D10V_32",         /* name */
     152           FALSE,               /* partial_inplace */
     153           0xffffffff,          /* src_mask */
     154           0xffffffff,          /* dst_mask */
     155           FALSE),              /* pcrel_offset */
     156
     157    /* GNU extension to record C++ vtable hierarchy */
     158    HOWTO (R_D10V_GNU_VTINHERIT, /* type */
     159           0,                     /* rightshift */
     160           2,                     /* size (0 = byte, 1 = short, 2 = long) */
     161           0,                     /* bitsize */
     162           FALSE,                 /* pc_relative */
     163           0,                     /* bitpos */
     164           complain_overflow_dont, /* complain_on_overflow */
     165           NULL,                  /* special_function */
     166           "R_D10V_GNU_VTINHERIT", /* name */
     167           FALSE,                 /* partial_inplace */
     168           0,                     /* src_mask */
     169           0,                     /* dst_mask */
     170           FALSE),                /* pcrel_offset */
     171
     172    /* GNU extension to record C++ vtable member usage */
     173    HOWTO (R_D10V_GNU_VTENTRY,     /* type */
     174           0,                     /* rightshift */
     175           2,                     /* size (0 = byte, 1 = short, 2 = long) */
     176           0,                     /* bitsize */
     177           FALSE,                 /* pc_relative */
     178           0,                     /* bitpos */
     179           complain_overflow_dont, /* complain_on_overflow */
     180           _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
     181           "R_D10V_GNU_VTENTRY",   /* name */
     182           FALSE,                 /* partial_inplace */
     183           0,                     /* src_mask */
     184           0,                     /* dst_mask */
     185           FALSE),                /* pcrel_offset */
     186  };
    175187
    176188/* Map BFD reloc types to D10V ELF reloc types.  */
    177189
    178190struct d10v_reloc_map
    179 {
    180   bfd_reloc_code_real_type bfd_reloc_val;
    181   unsigned char elf_reloc_val;
    182 };
    183 
    184  static const struct d10v_reloc_map d10v_reloc_map[] =
    185 {
    186   { BFD_RELOC_NONE, R_D10V_NONE, },
    187   { BFD_RELOC_D10V_10_PCREL_R, R_D10V_10_PCREL_R },
    188   { BFD_RELOC_D10V_10_PCREL_L, R_D10V_10_PCREL_L },
    189   { BFD_RELOC_16, R_D10V_16 },
    190   { BFD_RELOC_D10V_18, R_D10V_18 },
    191   { BFD_RELOC_D10V_18_PCREL, R_D10V_18_PCREL },
    192   { BFD_RELOC_32, R_D10V_32 },
    193   { BFD_RELOC_VTABLE_INHERIT, R_D10V_GNU_VTINHERIT },
    194   { BFD_RELOC_VTABLE_ENTRY, R_D10V_GNU_VTENTRY },
    195 };
     191  {
     192    bfd_reloc_code_real_type bfd_reloc_val;
     193    unsigned char elf_reloc_val;
     194  };
     195
     196static const struct d10v_reloc_map d10v_reloc_map[] =
     197  {
     198    { BFD_RELOC_NONE, R_D10V_NONE, },
     199    { BFD_RELOC_D10V_10_PCREL_R, R_D10V_10_PCREL_R },
     200    { BFD_RELOC_D10V_10_PCREL_L, R_D10V_10_PCREL_L },
     201    { BFD_RELOC_16, R_D10V_16 },
     202    { BFD_RELOC_D10V_18, R_D10V_18 },
     203    { BFD_RELOC_D10V_18_PCREL, R_D10V_18_PCREL },
     204    { BFD_RELOC_32, R_D10V_32 },
     205    { BFD_RELOC_VTABLE_INHERIT, R_D10V_GNU_VTINHERIT },
     206    { BFD_RELOC_VTABLE_ENTRY, R_D10V_GNU_VTENTRY },
     207  };
    196208
    197209static reloc_howto_type *
     
    219231     bfd *abfd ATTRIBUTE_UNUSED;
    220232     arelent *cache_ptr;
    221      Elf32_Internal_Rel *dst;
     233     Elf_Internal_Rela *dst;
    222234{
    223235  unsigned int r_type;
     
    229241
    230242static asection *
    231 elf32_d10v_gc_mark_hook (abfd, info, rel, h, sym)
    232        bfd *abfd;
    233        struct bfd_link_info *info ATTRIBUTE_UNUSED;
    234        Elf_Internal_Rela *rel;
    235        struct elf_link_hash_entry *h;
    236        Elf_Internal_Sym *sym;
     243elf32_d10v_gc_mark_hook (sec, info, rel, h, sym)
     244     asection *sec;
     245     struct bfd_link_info *info ATTRIBUTE_UNUSED;
     246     Elf_Internal_Rela *rel;
     247     struct elf_link_hash_entry *h;
     248     Elf_Internal_Sym *sym;
    237249{
    238250  if (h != NULL)
     
    260272     }
    261273   else
    262      {
    263        if (!(elf_bad_symtab (abfd)
    264            && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    265          && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    266                 && sym->st_shndx != SHN_COMMON))
    267           {
    268             return bfd_section_from_elf_index (abfd, sym->st_shndx);
    269           }
    270       }
     274     return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
     275
    271276  return NULL;
    272277}
    273278
    274 static boolean
     279static bfd_boolean
    275280elf32_d10v_gc_sweep_hook (abfd, info, sec, relocs)
    276281     bfd *abfd ATTRIBUTE_UNUSED;
     
    280285{
    281286  /* we don't use got and plt entries for d10v */
    282   return true;
     287  return TRUE;
    283288}
    284289
     
    287292   virtual table relocs for gc.  */
    288293
    289 static boolean
     294static bfd_boolean
    290295elf32_d10v_check_relocs (abfd, info, sec, relocs)
    291296     bfd *abfd;
     
    300305
    301306  if (info->relocateable)
    302     return true;
     307    return TRUE;
    303308
    304309  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     
    326331        case R_D10V_GNU_VTINHERIT:
    327332          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    328             return false;
     333            return FALSE;
    329334          break;
    330335
     
    333338        case R_D10V_GNU_VTENTRY:
    334339          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset))
    335             return false;
     340            return FALSE;
    336341          break;
    337342        }
    338343    }
    339344
    340   return true;
     345  return TRUE;
    341346}
    342347
    343348/* Relocate a D10V ELF section.  */
    344 static boolean
     349static bfd_boolean
    345350elf32_d10v_relocate_section (output_bfd, info, input_bfd, input_section,
    346351                            contents, relocs, local_syms, local_sections)
    347      bfd *output_bfd ATTRIBUTE_UNUSED;
     352     bfd *output_bfd;
    348353     struct bfd_link_info *info;
    349354     bfd *input_bfd;
     
    411416          sym = local_syms + r_symndx;
    412417          sec = local_sections[r_symndx];
    413           relocation = (sec->output_section->vma
    414                         + sec->output_offset
    415                         + sym->st_value);
     418          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
    416419        }
    417420      else
     
    435438              if (!((*info->callbacks->undefined_symbol)
    436439                    (info, h->root.root.string, input_bfd,
    437                      input_section, rel->r_offset, true)))
    438                 return false;
     440                     input_section, rel->r_offset, TRUE)))
     441                return FALSE;
    439442              relocation = 0;
    440443            }
     
    465468                    (info, name, howto->name, (bfd_vma) 0,
    466469                     input_bfd, input_section, rel->r_offset)))
    467                 return false;
     470                return FALSE;
    468471              break;
    469472
     
    471474              if (!((*info->callbacks->undefined_symbol)
    472475                    (info, name, input_bfd, input_section,
    473                      rel->r_offset, true)))
    474                 return false;
     476                     rel->r_offset, TRUE)))
     477                return FALSE;
    475478              break;
    476479
    477480            case bfd_reloc_outofrange:
    478               msg = _ ("internal error: out of range error");
     481              msg = _("internal error: out of range error");
    479482              goto common_error;
    480483
    481484            case bfd_reloc_notsupported:
    482               msg = _ ("internal error: unsupported relocation error");
     485              msg = _("internal error: unsupported relocation error");
    483486              goto common_error;
    484487
    485488            case bfd_reloc_dangerous:
    486               msg = _ ("internal error: dangerous error");
     489              msg = _("internal error: dangerous error");
    487490              goto common_error;
    488491
    489492            default:
    490               msg = _ ("internal error: unknown error");
     493              msg = _("internal error: unknown error");
    491494              /* fall through */
    492495
     
    495498                    (info, msg, name, input_bfd, input_section,
    496499                     rel->r_offset)))
    497                 return false;
     500                return FALSE;
    498501              break;
    499502            }
     
    501504    }
    502505
    503   return true;
     506  return TRUE;
    504507}
    505508#define ELF_ARCH                bfd_arch_d10v
    506 #define ELF_MACHINE_CODE        EM_CYGNUS_D10V
     509#define ELF_MACHINE_CODE        EM_D10V
     510#define ELF_MACHINE_ALT1        EM_CYGNUS_D10V
    507511#define ELF_MAXPAGESIZE         0x1000
    508512
Note: See TracChangeset for help on using the changeset viewer.