Home | History | Annotate | Line # | Download | only in bfd
elf32-v850.c revision 1.1.1.10
      1 /* V850-specific support for 32-bit ELF
      2    Copyright (C) 1996-2024 Free Software Foundation, Inc.
      3 
      4    This file is part of BFD, the Binary File Descriptor library.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program; if not, write to the Free Software
     18    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19    MA 02110-1301, USA.  */
     20 
     21 
     22 /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
     23    dependencies.  As is the gas & simulator code for the v850.  */
     24 
     25 #include "sysdep.h"
     26 #include "bfd.h"
     27 #include "bfdlink.h"
     28 #include "libbfd.h"
     29 #include "elf-bfd.h"
     30 #include "elf/v850.h"
     31 #include "libiberty.h"
     32 #include "elf32-v850.h"
     33 
     34 /* Sign-extend a 17-bit number.  */
     35 #define SEXT17(x)	((((x) & 0x1ffff) ^ 0x10000) - 0x10000)
     36 
     37 /* Sign-extend a 22-bit number.  */
     38 #define SEXT22(x)	((((x) & 0x3fffff) ^ 0x200000) - 0x200000)
     39 
     40 static reloc_howto_type v850_elf_howto_table[];
     41 
     42 /* Look through the relocs for a section during the first phase, and
     43    allocate space in the global offset table or procedure linkage
     44    table.  */
     45 
     46 static bool
     47 v850_elf_check_relocs (bfd *abfd,
     48 		       struct bfd_link_info *info,
     49 		       asection *sec,
     50 		       const Elf_Internal_Rela *relocs)
     51 {
     52   bool ret = true;
     53   Elf_Internal_Shdr *symtab_hdr;
     54   struct elf_link_hash_entry **sym_hashes;
     55   const Elf_Internal_Rela *rel;
     56   const Elf_Internal_Rela *rel_end;
     57   unsigned int r_type;
     58   int other = 0;
     59   const char *common = NULL;
     60 
     61   if (bfd_link_relocatable (info))
     62     return true;
     63 
     64 #ifdef DEBUG
     65   _bfd_error_handler ("v850_elf_check_relocs called for section %pA in %pB",
     66 		      sec, abfd);
     67 #endif
     68 
     69   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     70   sym_hashes = elf_sym_hashes (abfd);
     71 
     72   rel_end = relocs + sec->reloc_count;
     73   for (rel = relocs; rel < rel_end; rel++)
     74     {
     75       unsigned long r_symndx;
     76       struct elf_link_hash_entry *h;
     77 
     78       r_symndx = ELF32_R_SYM (rel->r_info);
     79       if (r_symndx < symtab_hdr->sh_info)
     80 	h = NULL;
     81       else
     82 	{
     83 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     84 	  while (h->root.type == bfd_link_hash_indirect
     85 		 || h->root.type == bfd_link_hash_warning)
     86 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     87 	}
     88 
     89       r_type = ELF32_R_TYPE (rel->r_info);
     90       switch (r_type)
     91 	{
     92 	default:
     93 	  break;
     94 
     95 	/* This relocation describes the C++ object vtable hierarchy.
     96 	   Reconstruct it for later use during GC.  */
     97 	case R_V850_GNU_VTINHERIT:
     98 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
     99 	    return false;
    100 	  break;
    101 
    102 	/* This relocation describes which C++ vtable entries
    103 	   are actually used.  Record for later use during GC.  */
    104 	case R_V850_GNU_VTENTRY:
    105 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    106 	    return false;
    107 	  break;
    108 
    109 	case R_V850_SDA_16_16_SPLIT_OFFSET:
    110 	case R_V850_SDA_16_16_OFFSET:
    111 	case R_V850_SDA_15_16_OFFSET:
    112 	case R_V810_GPWLO_1:
    113 	case R_V850_HWLO:
    114 	case R_V850_HWLO_1:
    115 	  other = V850_OTHER_SDA;
    116 	  common = ".scommon";
    117 	  goto small_data_common;
    118 
    119 	case R_V850_ZDA_16_16_SPLIT_OFFSET:
    120 	case R_V850_ZDA_16_16_OFFSET:
    121 	case R_V850_ZDA_15_16_OFFSET:
    122 	  other = V850_OTHER_ZDA;
    123 	  common = ".zcommon";
    124 	  goto small_data_common;
    125 
    126 	case R_V850_TDA_4_4_OFFSET:
    127 	case R_V850_TDA_4_5_OFFSET:
    128 	case R_V850_TDA_7_7_OFFSET:
    129 	case R_V850_TDA_6_8_OFFSET:
    130 	case R_V850_TDA_7_8_OFFSET:
    131 	case R_V850_TDA_16_16_OFFSET:
    132 	  other = V850_OTHER_TDA;
    133 	  common = ".tcommon";
    134 	  /* fall through */
    135 
    136 #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
    137 
    138 	small_data_common:
    139 	  if (h)
    140 	    {
    141 	      /* Flag which type of relocation was used.  */
    142 	      h->other |= other;
    143 	      if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
    144 		  && (h->other & V850_OTHER_ERROR) == 0)
    145 		{
    146 		  const char * msg;
    147 		  char *buff;
    148 
    149 		  switch (h->other & V850_OTHER_MASK)
    150 		    {
    151 		    default:
    152 		      msg = _("variable `%s' cannot occupy in multiple small data regions");
    153 		      break;
    154 		    case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
    155 		      msg = _("variable `%s' can only be in one of the small, zero, and tiny data regions");
    156 		      break;
    157 		    case V850_OTHER_SDA | V850_OTHER_ZDA:
    158 		      msg = _("variable `%s' cannot be in both small and zero data regions simultaneously");
    159 		      break;
    160 		    case V850_OTHER_SDA | V850_OTHER_TDA:
    161 		      msg = _("variable `%s' cannot be in both small and tiny data regions simultaneously");
    162 		      break;
    163 		    case V850_OTHER_ZDA | V850_OTHER_TDA:
    164 		      msg = _("variable `%s' cannot be in both zero and tiny data regions simultaneously");
    165 		      break;
    166 		    }
    167 
    168 		  if (asprintf (&buff, msg, h->root.root.string) < 0)
    169 		    buff = NULL;
    170 		  else
    171 		    msg = buff;
    172 		  info->callbacks->warning (info, msg, h->root.root.string,
    173 					    abfd, h->root.u.def.section,
    174 					    (bfd_vma) 0);
    175 		  free (buff);
    176 
    177 		  bfd_set_error (bfd_error_bad_value);
    178 		  h->other |= V850_OTHER_ERROR;
    179 		  ret = false;
    180 		}
    181 	    }
    182 
    183 	  if (h && h->root.type == bfd_link_hash_common
    184 	      && h->root.u.c.p
    185 	      && !strcmp (bfd_section_name (h->root.u.c.p->section), "COMMON"))
    186 	    {
    187 	      asection * section;
    188 
    189 	      section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
    190 	      section->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
    191 	    }
    192 
    193 #ifdef DEBUG
    194 	  fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
    195 		   v850_elf_howto_table[ (int)r_type ].name,
    196 		   (h && h->root.root.string) ? h->root.root.string : "<unknown>",
    197 		   (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
    198 #endif
    199 	  break;
    200 	}
    201     }
    202 
    203   return ret;
    204 }
    205 
    206 /* In the old version, when an entry was checked out from the table,
    207    it was deleted.  This produced an error if the entry was needed
    208    more than once, as the second attempted retry failed.
    209 
    210    In the current version, the entry is not deleted, instead we set
    211    the field 'found' to TRUE.  If a second lookup matches the same
    212    entry, then we know that the hi16s reloc has already been updated
    213    and does not need to be updated a second time.
    214 
    215    TODO - TOFIX: If it is possible that we need to restore 2 different
    216    addresses from the same table entry, where the first generates an
    217    overflow, whilst the second do not, then this code will fail.  */
    218 
    219 typedef struct hi16s_location
    220 {
    221   bfd_vma addend;
    222   bfd_byte *address;
    223   unsigned long counter;
    224   bool found;
    225   struct hi16s_location *next;
    226 }
    227 hi16s_location;
    228 
    229 static hi16s_location * previous_hi16s;
    230 static hi16s_location * free_hi16s;
    231 static unsigned long    hi16s_counter;
    232 
    233 static void
    234 remember_hi16s_reloc (bfd *abfd, bfd_vma addend, bfd_byte *address)
    235 {
    236   hi16s_location * entry = NULL;
    237   size_t amt = sizeof (* free_hi16s);
    238 
    239   /* Find a free structure.  */
    240   if (free_hi16s == NULL)
    241     free_hi16s = bfd_zalloc (abfd, amt);
    242 
    243   entry      = free_hi16s;
    244   free_hi16s = free_hi16s->next;
    245 
    246   entry->addend  = addend;
    247   entry->address = address;
    248   entry->counter = hi16s_counter ++;
    249   entry->found   = false;
    250   entry->next    = previous_hi16s;
    251   previous_hi16s = entry;
    252 
    253   /* Cope with wrap around of our counter.  */
    254   if (hi16s_counter == 0)
    255     {
    256       /* XXX: Assume that all counter entries differ only in their low 16 bits.  */
    257       for (entry = previous_hi16s; entry != NULL; entry = entry->next)
    258 	entry->counter &= 0xffff;
    259 
    260       hi16s_counter = 0x10000;
    261     }
    262 }
    263 
    264 static bfd_byte *
    265 find_remembered_hi16s_reloc (bfd_vma addend, bool *already_found)
    266 {
    267   hi16s_location *match = NULL;
    268   hi16s_location *entry;
    269   bfd_byte *addr;
    270 
    271   /* Search the table.  Record the most recent entry that matches.  */
    272   for (entry = previous_hi16s; entry; entry = entry->next)
    273     {
    274       if (entry->addend == addend
    275 	  && (match == NULL || match->counter < entry->counter))
    276 	{
    277 	  match    = entry;
    278 	}
    279     }
    280 
    281   if (match == NULL)
    282     return NULL;
    283 
    284   /* Extract the address.  */
    285   addr = match->address;
    286 
    287   /* Remember if this entry has already been used before.  */
    288   if (already_found)
    289     * already_found = match->found;
    290 
    291   /* Note that this entry has now been used.  */
    292   match->found = true;
    293 
    294   return addr;
    295 }
    296 
    297 /* Calculate the final operand value for a R_V850_LO16 or
    298    R_V850_LO16_SPLIT_OFFSET.  *INSN is the current operand value and
    299    ADDEND is the sum of the relocation symbol and offset.  Store the
    300    operand value in *INSN and return true on success.
    301 
    302    The assembler has already done some of this: If the value stored in
    303    the instruction has its 15th bit set, (counting from zero) then the
    304    assembler will have added 1 to the value stored in the associated
    305    HI16S reloc.  So for example, these relocations:
    306 
    307        movhi hi( fred ), r0, r1
    308        movea lo( fred ), r1, r1
    309 
    310    will store 0 in the value fields for the MOVHI and MOVEA instructions
    311    and addend will be the address of fred, but for these instructions:
    312 
    313        movhi hi( fred + 0x123456 ), r0, r1
    314        movea lo( fred + 0x123456 ), r1, r1
    315 
    316    the value stored in the MOVHI instruction will be 0x12 and the value
    317    stored in the MOVEA instruction will be 0x3456.  If however the
    318    instructions were:
    319 
    320        movhi hi( fred + 0x10ffff ), r0, r1
    321        movea lo( fred + 0x10ffff ), r1, r1
    322 
    323    then the value stored in the MOVHI instruction would be 0x11 (not
    324    0x10) and the value stored in the MOVEA instruction would be 0xffff.
    325    Thus (assuming for the moment that the addend is 0), at run time the
    326    MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction
    327    adds 0xffffffff (sign extension!) producing 0x10ffff.  Similarly if
    328    the instructions were:
    329 
    330        movhi hi( fred - 1 ), r0, r1
    331        movea lo( fred - 1 ), r1, r1
    332 
    333    then 0 is stored in the MOVHI instruction and -1 is stored in the
    334    MOVEA instruction.
    335 
    336    Overflow can occur if the addition of the value stored in the
    337    instruction plus the addend sets the 15th bit when before it was clear.
    338    This is because the 15th bit will be sign extended into the high part,
    339    thus reducing its value by one, but since the 15th bit was originally
    340    clear, the assembler will not have added 1 to the previous HI16S reloc
    341    to compensate for this effect.  For example:
    342 
    343       movhi hi( fred + 0x123456 ), r0, r1
    344       movea lo( fred + 0x123456 ), r1, r1
    345 
    346    The value stored in HI16S reloc is 0x12, the value stored in the LO16
    347    reloc is 0x3456.  If we assume that the address of fred is 0x00007000
    348    then the relocations become:
    349 
    350      HI16S: 0x0012 + (0x00007000 >> 16)    = 0x12
    351      LO16:  0x3456 + (0x00007000 & 0xffff) = 0xa456
    352 
    353    but when the instructions are executed, the MOVEA instruction's value
    354    is signed extended, so the sum becomes:
    355 
    356 	0x00120000
    357       + 0xffffa456
    358       ------------
    359 	0x0011a456    but 'fred + 0x123456' = 0x0012a456
    360 
    361    Note that if the 15th bit was set in the value stored in the LO16
    362    reloc, then we do not have to do anything:
    363 
    364       movhi hi( fred + 0x10ffff ), r0, r1
    365       movea lo( fred + 0x10ffff ), r1, r1
    366 
    367       HI16S:  0x0011 + (0x00007000 >> 16)    = 0x11
    368       LO16:   0xffff + (0x00007000 & 0xffff) = 0x6fff
    369 
    370 	0x00110000
    371       + 0x00006fff
    372       ------------
    373 	0x00116fff  = fred + 0x10ffff = 0x7000 + 0x10ffff
    374 
    375    Overflow can also occur if the computation carries into the 16th bit
    376    and it also results in the 15th bit having the same value as the 15th
    377    bit of the original value.   What happens is that the HI16S reloc
    378    will have already examined the 15th bit of the original value and
    379    added 1 to the high part if the bit is set.  This compensates for the
    380    sign extension of 15th bit of the result of the computation.  But now
    381    there is a carry into the 16th bit, and this has not been allowed for.
    382 
    383    So, for example if fred is at address 0xf000:
    384 
    385      movhi hi( fred + 0xffff ), r0, r1    [bit 15 of the offset is set]
    386      movea lo( fred + 0xffff ), r1, r1
    387 
    388      HI16S: 0x0001 + (0x0000f000 >> 16)    = 0x0001
    389      LO16:  0xffff + (0x0000f000 & 0xffff) = 0xefff   (carry into bit 16 is lost)
    390 
    391        0x00010000
    392      + 0xffffefff
    393      ------------
    394        0x0000efff   but 'fred + 0xffff' = 0x0001efff
    395 
    396    Similarly, if the 15th bit remains clear, but overflow occurs into
    397    the 16th bit then (assuming the address of fred is 0xf000):
    398 
    399      movhi hi( fred + 0x7000 ), r0, r1    [bit 15 of the offset is clear]
    400      movea lo( fred + 0x7000 ), r1, r1
    401 
    402      HI16S: 0x0000 + (0x0000f000 >> 16)    = 0x0000
    403      LO16:  0x7000 + (0x0000f000 & 0xffff) = 0x6fff  (carry into bit 16 is lost)
    404 
    405        0x00000000
    406      + 0x00006fff
    407      ------------
    408        0x00006fff   but 'fred + 0x7000' = 0x00016fff
    409 
    410    Note - there is no need to change anything if a carry occurs, and the
    411    15th bit changes its value from being set to being clear, as the HI16S
    412    reloc will have already added in 1 to the high part for us:
    413 
    414      movhi hi( fred + 0xffff ), r0, r1     [bit 15 of the offset is set]
    415      movea lo( fred + 0xffff ), r1, r1
    416 
    417      HI16S: 0x0001 + (0x00007000 >> 16)
    418      LO16:  0xffff + (0x00007000 & 0xffff) = 0x6fff  (carry into bit 16 is lost)
    419 
    420        0x00010000
    421      + 0x00006fff   (bit 15 not set, so the top half is zero)
    422      ------------
    423        0x00016fff   which is right (assuming that fred is at 0x7000)
    424 
    425    but if the 15th bit goes from being clear to being set, then we must
    426    once again handle overflow:
    427 
    428      movhi hi( fred + 0x7000 ), r0, r1     [bit 15 of the offset is clear]
    429      movea lo( fred + 0x7000 ), r1, r1
    430 
    431      HI16S: 0x0000 + (0x0000ffff >> 16)
    432      LO16:  0x7000 + (0x0000ffff & 0xffff) = 0x6fff  (carry into bit 16)
    433 
    434        0x00000000
    435      + 0x00006fff   (bit 15 not set, so the top half is zero)
    436      ------------
    437        0x00006fff   which is wrong (assuming that fred is at 0xffff).  */
    438 
    439 static bool
    440 v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn,
    441 				  unsigned long addend)
    442 {
    443 #define BIT15_SET(x) ((x) & 0x8000)
    444 #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff)
    445 
    446   if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend))
    447       || (OVERFLOWS (addend, *insn)
    448 	  && ((! BIT15_SET (*insn)) || (BIT15_SET (addend)))))
    449     {
    450       bool already_updated;
    451       bfd_byte *hi16s_address = find_remembered_hi16s_reloc
    452 	(addend, & already_updated);
    453 
    454       /* Amend the matching HI16_S relocation.  */
    455       if (hi16s_address != NULL)
    456 	{
    457 	  if (! already_updated)
    458 	    {
    459 	      unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address);
    460 	      hi_insn += 1;
    461 	      bfd_put_16 (abfd, hi_insn, hi16s_address);
    462 	    }
    463 	}
    464       else
    465 	{
    466 	  _bfd_error_handler (_("failed to find previous HI16 reloc"));
    467 	  return false;
    468 	}
    469     }
    470 #undef OVERFLOWS
    471 #undef BIT15_SET
    472 
    473   /* Do not complain if value has top bit set, as this has been
    474      anticipated.  */
    475   *insn = (*insn + addend) & 0xffff;
    476   return true;
    477 }
    478 
    479 /* FIXME:  The code here probably ought to be removed and the code in reloc.c
    480    allowed to do its stuff instead.  At least for most of the relocs, anyway.  */
    481 
    482 static bfd_reloc_status_type
    483 v850_elf_perform_relocation (bfd *abfd,
    484 			     unsigned int r_type,
    485 			     bfd_vma addend,
    486 			     bfd_byte *address)
    487 {
    488   unsigned long insn;
    489   unsigned long result;
    490   bfd_signed_vma saddend = (bfd_signed_vma) addend;
    491 
    492   switch (r_type)
    493     {
    494     default:
    495 #ifdef DEBUG
    496       _bfd_error_handler ("%pB: unsupported relocation type %#x",
    497 			  abfd, r_type);
    498 #endif
    499       return bfd_reloc_notsupported;
    500 
    501     case R_V850_REL32:
    502     case R_V850_ABS32:
    503     case R_V810_WORD:
    504     case R_V850_PC32:
    505       bfd_put_32 (abfd, addend, address);
    506       return bfd_reloc_ok;
    507 
    508     case R_V850_WLO23:
    509     case R_V850_23:
    510       insn  = bfd_get_32 (abfd, address);
    511       insn &= ~((0x7f << 4) | (0x7fff80 << (16-7)));
    512       insn |= ((addend & 0x7f) << 4) | ((addend & 0x7fff80) << (16-7));
    513       bfd_put_32 (abfd, (bfd_vma) insn, address);
    514       return bfd_reloc_ok;
    515 
    516     case R_V850_PCR22:
    517     case R_V850_22_PCREL:
    518       if (saddend > 0x1fffff || saddend < -0x200000)
    519 	return bfd_reloc_overflow;
    520 
    521       if ((addend % 2) != 0)
    522 	return bfd_reloc_dangerous;
    523 
    524       insn  = bfd_get_32 (abfd, address);
    525       insn &= ~0xfffe003f;
    526       insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
    527       bfd_put_32 (abfd, (bfd_vma) insn, address);
    528       return bfd_reloc_ok;
    529 
    530     case R_V850_PC17:
    531     case R_V850_17_PCREL:
    532       if (saddend > 0xffff || saddend < -0x10000)
    533 	return bfd_reloc_overflow;
    534 
    535       if ((addend % 2) != 0)
    536 	return bfd_reloc_dangerous;
    537 
    538       insn  = bfd_get_32 (abfd, address);
    539       insn &= ~ 0xfffe0010;
    540       insn |= ((addend & 0xfffe) << 16) | ((addend & 0x10000) >> (16-4));
    541       break;
    542 
    543     case R_V850_PC16U:
    544     case R_V850_16_PCREL:
    545       if ((saddend < -0xffff) || (saddend > 0))
    546 	return bfd_reloc_overflow;
    547 
    548       if ((addend % 2) != 0)
    549 	return bfd_reloc_dangerous;
    550 
    551       insn  = bfd_get_16 (abfd, address);
    552       insn &= ~0xfffe;
    553       insn |= (-addend & 0xfffe);
    554       break;
    555 
    556     case R_V850_PC9:
    557     case R_V850_9_PCREL:
    558       if (saddend > 0xff || saddend < -0x100)
    559 	return bfd_reloc_overflow;
    560 
    561       if ((addend % 2) != 0)
    562 	return bfd_reloc_dangerous;
    563 
    564       insn  = bfd_get_16 (abfd, address);
    565       insn &= ~ 0xf870;
    566       insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3);
    567       break;
    568 
    569     case R_V810_WHI:
    570     case R_V850_HI16:
    571       addend += (bfd_get_16 (abfd, address) << 16);
    572       addend = (addend >> 16);
    573       insn = addend;
    574       break;
    575 
    576     case R_V810_WHI1:
    577     case R_V850_HI16_S:
    578       /* Remember where this relocation took place.  */
    579       remember_hi16s_reloc (abfd, addend, address);
    580 
    581       addend += (bfd_get_16 (abfd, address) << 16);
    582       addend = (addend >> 16) + ((addend & 0x8000) != 0);
    583 
    584       /* This relocation cannot overflow.  */
    585       if (addend > 0xffff)
    586 	addend = 0;
    587 
    588       insn = addend;
    589       break;
    590 
    591     case R_V810_WLO:
    592     case R_V850_LO16:
    593       insn = bfd_get_16 (abfd, address);
    594       if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend))
    595 	return bfd_reloc_overflow;
    596       break;
    597 
    598     case R_V810_BYTE:
    599     case R_V850_8:
    600       addend += (char) bfd_get_8 (abfd, address);
    601 
    602       saddend = (bfd_signed_vma) addend;
    603 
    604       if (saddend > 0x7f || saddend < -0x80)
    605 	return bfd_reloc_overflow;
    606 
    607       bfd_put_8 (abfd, addend, address);
    608       return bfd_reloc_ok;
    609 
    610     case R_V850_CALLT_16_16_OFFSET:
    611       addend += bfd_get_16 (abfd, address);
    612 
    613       saddend = (bfd_signed_vma) addend;
    614 
    615       if (saddend > 0xffff || saddend < 0)
    616 	return bfd_reloc_overflow;
    617 
    618       insn = addend;
    619       break;
    620 
    621     case R_V850_CALLT_15_16_OFFSET:
    622       insn = bfd_get_16 (abfd, address);
    623 
    624       addend += insn & 0xfffe;
    625 
    626       saddend = (bfd_signed_vma) addend;
    627 
    628       if (saddend > 0xffff || saddend < 0)
    629 	return bfd_reloc_overflow;
    630 
    631       insn = (0xfffe & addend)
    632 	| (insn & ~0xfffe);
    633       break;
    634 
    635     case R_V850_CALLT_6_7_OFFSET:
    636       insn = bfd_get_16 (abfd, address);
    637       addend += ((insn & 0x3f) << 1);
    638 
    639       saddend = (bfd_signed_vma) addend;
    640 
    641       if (saddend > 0x7e || saddend < 0)
    642 	return bfd_reloc_overflow;
    643 
    644       if (addend & 1)
    645 	return bfd_reloc_dangerous;
    646 
    647       insn &= 0xff80;
    648       insn |= (addend >> 1);
    649       break;
    650 
    651     case R_V850_16:
    652     case R_V810_HWORD:
    653     case R_V850_SDA_16_16_OFFSET:
    654     case R_V850_ZDA_16_16_OFFSET:
    655     case R_V850_TDA_16_16_OFFSET:
    656       addend += bfd_get_16 (abfd, address);
    657 
    658       saddend = (bfd_signed_vma) addend;
    659 
    660       if (saddend > 0x7fff || saddend < -0x8000)
    661 	return bfd_reloc_overflow;
    662 
    663       insn = addend;
    664       break;
    665 
    666     case R_V850_16_S1:
    667     case R_V850_SDA_15_16_OFFSET:
    668     case R_V850_ZDA_15_16_OFFSET:
    669     case R_V810_GPWLO_1:
    670       insn = bfd_get_16 (abfd, address);
    671       addend += (insn & 0xfffe);
    672 
    673       saddend = (bfd_signed_vma) addend;
    674 
    675       if (saddend > 0x7ffe || saddend < -0x8000)
    676 	return bfd_reloc_overflow;
    677 
    678       if (addend & 1)
    679 	return bfd_reloc_dangerous;
    680 
    681       insn = (addend &~ (bfd_vma) 1) | (insn & 1);
    682       break;
    683 
    684     case R_V850_TDA_6_8_OFFSET:
    685       insn = bfd_get_16 (abfd, address);
    686       addend += ((insn & 0x7e) << 1);
    687 
    688       saddend = (bfd_signed_vma) addend;
    689 
    690       if (saddend > 0xfc || saddend < 0)
    691 	return bfd_reloc_overflow;
    692 
    693       if (addend & 3)
    694 	return bfd_reloc_dangerous;
    695 
    696       insn &= 0xff81;
    697       insn |= (addend >> 1);
    698       break;
    699 
    700     case R_V850_TDA_7_8_OFFSET:
    701       insn = bfd_get_16 (abfd, address);
    702       addend += ((insn & 0x7f) << 1);
    703 
    704       saddend = (bfd_signed_vma) addend;
    705 
    706       if (saddend > 0xfe || saddend < 0)
    707 	return bfd_reloc_overflow;
    708 
    709       if (addend & 1)
    710 	return bfd_reloc_dangerous;
    711 
    712       insn &= 0xff80;
    713       insn |= (addend >> 1);
    714       break;
    715 
    716     case R_V850_TDA_7_7_OFFSET:
    717       insn = bfd_get_16 (abfd, address);
    718       addend += insn & 0x7f;
    719 
    720       saddend = (bfd_signed_vma) addend;
    721 
    722       if (saddend > 0x7f || saddend < 0)
    723 	return bfd_reloc_overflow;
    724 
    725       insn &= 0xff80;
    726       insn |= addend;
    727       break;
    728 
    729     case R_V850_TDA_4_5_OFFSET:
    730       insn = bfd_get_16 (abfd, address);
    731       addend += ((insn & 0xf) << 1);
    732 
    733       saddend = (bfd_signed_vma) addend;
    734 
    735       if (saddend > 0x1e || saddend < 0)
    736 	return bfd_reloc_overflow;
    737 
    738       if (addend & 1)
    739 	return bfd_reloc_dangerous;
    740 
    741       insn &= 0xfff0;
    742       insn |= (addend >> 1);
    743       break;
    744 
    745     case R_V850_TDA_4_4_OFFSET:
    746       insn = bfd_get_16 (abfd, address);
    747       addend += insn & 0xf;
    748 
    749       saddend = (bfd_signed_vma) addend;
    750 
    751       if (saddend > 0xf || saddend < 0)
    752 	return bfd_reloc_overflow;
    753 
    754       insn &= 0xfff0;
    755       insn |= addend;
    756       break;
    757 
    758     case R_V810_WLO_1:
    759     case R_V850_HWLO:
    760     case R_V850_HWLO_1:
    761     case R_V850_LO16_S1:
    762       insn = bfd_get_16 (abfd, address);
    763       result = insn & 0xfffe;
    764       if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
    765 	return bfd_reloc_overflow;
    766       if (result & 1)
    767 	return bfd_reloc_overflow;
    768       insn = (result & 0xfffe)
    769 	| (insn & ~0xfffe);
    770 	bfd_put_16 (abfd, insn, address);
    771       return bfd_reloc_ok;
    772 
    773     case R_V850_BLO:
    774     case R_V850_LO16_SPLIT_OFFSET:
    775       insn = bfd_get_32 (abfd, address);
    776       result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5);
    777       if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
    778 	return bfd_reloc_overflow;
    779       insn = (((result << 16) & 0xfffe0000)
    780 	      | ((result << 5) & 0x20)
    781 	      | (insn & ~0xfffe0020));
    782       bfd_put_32 (abfd, insn, address);
    783       return bfd_reloc_ok;
    784 
    785     case R_V850_16_SPLIT_OFFSET:
    786     case R_V850_SDA_16_16_SPLIT_OFFSET:
    787     case R_V850_ZDA_16_16_SPLIT_OFFSET:
    788       insn = bfd_get_32 (abfd, address);
    789       addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5);
    790 
    791       saddend = (bfd_signed_vma) addend;
    792 
    793       if (saddend > 0x7fff || saddend < -0x8000)
    794 	return bfd_reloc_overflow;
    795 
    796       insn &= 0x0001ffdf;
    797       insn |= (addend & 1) << 5;
    798       insn |= (addend &~ (bfd_vma) 1) << 16;
    799 
    800       bfd_put_32 (abfd, (bfd_vma) insn, address);
    801       return bfd_reloc_ok;
    802 
    803     case R_V850_GNU_VTINHERIT:
    804     case R_V850_GNU_VTENTRY:
    805       return bfd_reloc_ok;
    806 
    807     }
    808 
    809   bfd_put_16 (abfd, (bfd_vma) insn, address);
    810   return bfd_reloc_ok;
    811 }
    812 
    813 /* Insert the addend into the instruction.  */
    815 
    816 static bfd_reloc_status_type
    817 v850_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    818 		arelent *reloc,
    819 		asymbol *symbol,
    820 		void * data ATTRIBUTE_UNUSED,
    821 		asection *isection,
    822 		bfd *obfd,
    823 		char **err ATTRIBUTE_UNUSED)
    824 {
    825   long relocation;
    826 
    827   /* If there is an output BFD,
    828      and the symbol is not a section name (which is only defined at final link time),
    829      and either we are not putting the addend into the instruction
    830       or the addend is zero, so there is nothing to add into the instruction
    831      then just fixup the address and return.  */
    832   if (obfd != NULL
    833       && (symbol->flags & BSF_SECTION_SYM) == 0
    834       && (! reloc->howto->partial_inplace
    835 	  || reloc->addend == 0))
    836     {
    837       reloc->address += isection->output_offset;
    838       return bfd_reloc_ok;
    839     }
    840 
    841   /* Catch relocs involving undefined symbols.  */
    842   if (bfd_is_und_section (symbol->section)
    843       && (symbol->flags & BSF_WEAK) == 0
    844       && obfd == NULL)
    845     return bfd_reloc_undefined;
    846 
    847   /* We handle final linking of some relocs ourselves.  */
    848 
    849   /* Is the address of the relocation really within the section?  */
    850   if (reloc->address > bfd_get_section_limit (abfd, isection))
    851     return bfd_reloc_outofrange;
    852 
    853   /* Work out which section the relocation is targeted at and the
    854      initial relocation command value.  */
    855 
    856   if (reloc->howto->pc_relative)
    857     return bfd_reloc_ok;
    858 
    859   /* Get symbol value.  (Common symbols are special.)  */
    860   if (bfd_is_com_section (symbol->section))
    861     relocation = 0;
    862   else
    863     relocation = symbol->value;
    864 
    865   /* Convert input-section-relative symbol value to absolute + addend.  */
    866   relocation += symbol->section->output_section->vma;
    867   relocation += symbol->section->output_offset;
    868   relocation += reloc->addend;
    869 
    870   reloc->addend = relocation;
    871   return bfd_reloc_ok;
    872 }
    873 
    874 /* This function is used for relocs which are only used
    875    for relaxing, which the linker should otherwise ignore.  */
    876 
    877 static bfd_reloc_status_type
    878 v850_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    879 		       arelent *reloc_entry,
    880 		       asymbol *symbol ATTRIBUTE_UNUSED,
    881 		       void * data ATTRIBUTE_UNUSED,
    882 		       asection *input_section,
    883 		       bfd *output_bfd,
    884 		       char **error_message ATTRIBUTE_UNUSED)
    885 {
    886   if (output_bfd != NULL)
    887     reloc_entry->address += input_section->output_offset;
    888 
    889   return bfd_reloc_ok;
    890 }
    891 /* Note: It is REQUIRED that the 'type' value of each entry
    892    in this array match the index of the entry in the array.
    893    SeeAlso: RELOC_NUBMER in include/elf/v850.h.  */
    894 static reloc_howto_type v850_elf_howto_table[] =
    895 {
    896   /* This reloc does nothing.  */
    897   HOWTO (R_V850_NONE,			/* Type.  */
    898 	 0,				/* Rightshift.  */
    899 	 0,				/* Size.  */
    900 	 0,				/* Bitsize.  */
    901 	 false,				/* PC_relative.  */
    902 	 0,				/* Bitpos.  */
    903 	 complain_overflow_dont,	/* Complain_on_overflow.  */
    904 	 bfd_elf_generic_reloc,		/* Special_function.  */
    905 	 "R_V850_NONE",			/* Name.  */
    906 	 false,				/* Partial_inplace.  */
    907 	 0,				/* Src_mask.  */
    908 	 0,				/* Dst_mask.  */
    909 	 false),			/* PCrel_offset.  */
    910 
    911   /* A PC relative 9 bit branch.  */
    912   HOWTO (R_V850_9_PCREL,		/* Type.  */
    913 	 0,				/* Rightshift.  */
    914 	 2,				/* Size.  */
    915 	 9,				/* Bitsize.  */
    916 	 true,				/* PC_relative.  */
    917 	 0,				/* Bitpos.  */
    918 	 complain_overflow_bitfield,	/* Complain_on_overflow.  */
    919 	 v850_elf_reloc,		/* Special_function.  */
    920 	 "R_V850_9_PCREL",		/* Name.  */
    921 	 false,				/* Partial_inplace.  */
    922 	 0x00ffffff,			/* Src_mask.  */
    923 	 0x00ffffff,			/* Dst_mask.  */
    924 	 true),				/* PCrel_offset.  */
    925 
    926   /* A PC relative 22 bit branch.  */
    927   HOWTO (R_V850_22_PCREL,		/* Type.  */
    928 	 0,				/* Rightshift.  */
    929 	 4,				/* Size.  */
    930 	 22,				/* Bitsize.  */
    931 	 true,				/* PC_relative.  */
    932 	 0,				/* Bitpos.  */
    933 	 complain_overflow_signed,	/* Complain_on_overflow.  */
    934 	 v850_elf_reloc,		/* Special_function.  */
    935 	 "R_V850_22_PCREL",		/* Name.  */
    936 	 false,				/* Partial_inplace.  */
    937 	 0x07ffff80,			/* Src_mask.  */
    938 	 0x07ffff80,			/* Dst_mask.  */
    939 	 true),				/* PCrel_offset.  */
    940 
    941   /* High 16 bits of symbol value.  */
    942   HOWTO (R_V850_HI16_S,			/* Type.  */
    943 	 0,				/* Rightshift.  */
    944 	 2,				/* Size.  */
    945 	 16,				/* Bitsize.  */
    946 	 false,				/* PC_relative.  */
    947 	 0,				/* Bitpos.  */
    948 	 complain_overflow_dont,	/* Complain_on_overflow.  */
    949 	 v850_elf_reloc,		/* Special_function.  */
    950 	 "R_V850_HI16_S",		/* Name.  */
    951 	 false,				/* Partial_inplace.  */
    952 	 0xffff,			/* Src_mask.  */
    953 	 0xffff,			/* Dst_mask.  */
    954 	 false),			/* PCrel_offset.  */
    955 
    956   /* High 16 bits of symbol value.  */
    957   HOWTO (R_V850_HI16,			/* Type.  */
    958 	 0,				/* Rightshift.  */
    959 	 2,				/* Size.  */
    960 	 16,				/* Bitsize.  */
    961 	 false,				/* PC_relative.  */
    962 	 0,				/* Bitpos.  */
    963 	 complain_overflow_dont,	/* Complain_on_overflow.  */
    964 	 v850_elf_reloc,		/* Special_function.  */
    965 	 "R_V850_HI16",			/* Name.  */
    966 	 false,				/* Partial_inplace.  */
    967 	 0xffff,			/* Src_mask.  */
    968 	 0xffff,			/* Dst_mask.  */
    969 	 false),			/* PCrel_offset.  */
    970 
    971   /* Low 16 bits of symbol value.  */
    972   HOWTO (R_V850_LO16,			/* Type.  */
    973 	 0,				/* Rightshift.  */
    974 	 2,				/* Size.  */
    975 	 16,				/* Bitsize.  */
    976 	 false,				/* PC_relative.  */
    977 	 0,				/* Bitpos.  */
    978 	 complain_overflow_dont,	/* Complain_on_overflow.  */
    979 	 v850_elf_reloc,		/* Special_function.  */
    980 	 "R_V850_LO16",			/* Name.  */
    981 	 false,				/* Partial_inplace.  */
    982 	 0xffff,			/* Src_mask.  */
    983 	 0xffff,			/* Dst_mask.  */
    984 	 false),			/* PCrel_offset.  */
    985 
    986   /* Simple 32bit reloc.  */
    987   HOWTO (R_V850_ABS32,			/* Type.  */
    988 	 0,				/* Rightshift.  */
    989 	 4,				/* Size.  */
    990 	 32,				/* Bitsize.  */
    991 	 false,				/* PC_relative.  */
    992 	 0,				/* Bitpos.  */
    993 	 complain_overflow_dont,	/* Complain_on_overflow.  */
    994 	 v850_elf_reloc,		/* Special_function.  */
    995 	 "R_V850_ABS32",		/* Name.  */
    996 	 false,				/* Partial_inplace.  */
    997 	 0xffffffff,			/* Src_mask.  */
    998 	 0xffffffff,			/* Dst_mask.  */
    999 	 false),			/* PCrel_offset.  */
   1000 
   1001   /* Simple 16bit reloc.  */
   1002   HOWTO (R_V850_16,			/* Type.  */
   1003 	 0,				/* Rightshift.  */
   1004 	 2,				/* Size.  */
   1005 	 16,				/* Bitsize.  */
   1006 	 false,				/* PC_relative.  */
   1007 	 0,				/* Bitpos.  */
   1008 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1009 	 bfd_elf_generic_reloc,		/* Special_function.  */
   1010 	 "R_V850_16",			/* Name.  */
   1011 	 false,				/* Partial_inplace.  */
   1012 	 0xffff,			/* Src_mask.  */
   1013 	 0xffff,			/* Dst_mask.  */
   1014 	 false),			/* PCrel_offset.  */
   1015 
   1016   /* Simple 8bit reloc.  */
   1017   HOWTO (R_V850_8,			/* Type.  */
   1018 	 0,				/* Rightshift.  */
   1019 	 1,				/* Size.  */
   1020 	 8,				/* Bitsize.  */
   1021 	 false,				/* PC_relative.  */
   1022 	 0,				/* Bitpos.  */
   1023 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1024 	 bfd_elf_generic_reloc,		/* Special_function.  */
   1025 	 "R_V850_8",			/* Name.  */
   1026 	 false,				/* Partial_inplace.  */
   1027 	 0xff,				/* Src_mask.  */
   1028 	 0xff,				/* Dst_mask.  */
   1029 	 false),			/* PCrel_offset.  */
   1030 
   1031   /* 16 bit offset from the short data area pointer.  */
   1032   HOWTO (R_V850_SDA_16_16_OFFSET,	/* Type.  */
   1033 	 0,				/* Rightshift.  */
   1034 	 2,				/* Size.  */
   1035 	 16,				/* Bitsize.  */
   1036 	 false,				/* PC_relative.  */
   1037 	 0,				/* Bitpos.  */
   1038 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1039 	 v850_elf_reloc,		/* Special_function.  */
   1040 	 "R_V850_SDA_16_16_OFFSET",	/* Name.  */
   1041 	 false,				/* Partial_inplace.  */
   1042 	 0xffff,			/* Src_mask.  */
   1043 	 0xffff,			/* Dst_mask.  */
   1044 	 false),			/* PCrel_offset.  */
   1045 
   1046   /* 15 bit offset from the short data area pointer.  */
   1047   HOWTO (R_V850_SDA_15_16_OFFSET,	/* Type.  */
   1048 	 1,				/* Rightshift.  */
   1049 	 2,				/* Size.  */
   1050 	 16,				/* Bitsize.  */
   1051 	 false,				/* PC_relative.  */
   1052 	 1,				/* Bitpos.  */
   1053 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1054 	 v850_elf_reloc,		/* Special_function.  */
   1055 	 "R_V850_SDA_15_16_OFFSET",	/* Name.  */
   1056 	 false,				/* Partial_inplace.  */
   1057 	 0xfffe,			/* Src_mask.  */
   1058 	 0xfffe,			/* Dst_mask.  */
   1059 	 false),			/* PCrel_offset.  */
   1060 
   1061   /* 16 bit offset from the zero data area pointer.  */
   1062   HOWTO (R_V850_ZDA_16_16_OFFSET,	/* Type.  */
   1063 	 0,				/* Rightshift.  */
   1064 	 2,				/* Size.  */
   1065 	 16,				/* Bitsize.  */
   1066 	 false,				/* PC_relative.  */
   1067 	 0,				/* Bitpos.  */
   1068 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1069 	 v850_elf_reloc,		/* Special_function.  */
   1070 	 "R_V850_ZDA_16_16_OFFSET",	/* Name.  */
   1071 	 false,				/* Partial_inplace.  */
   1072 	 0xffff,			/* Src_mask.  */
   1073 	 0xffff,			/* Dst_mask.  */
   1074 	 false),			/* PCrel_offset.  */
   1075 
   1076   /* 15 bit offset from the zero data area pointer.  */
   1077   HOWTO (R_V850_ZDA_15_16_OFFSET,	/* Type.  */
   1078 	 1,				/* Rightshift.  */
   1079 	 2,				/* Size.  */
   1080 	 16,				/* Bitsize.  */
   1081 	 false,				/* PC_relative.  */
   1082 	 1,				/* Bitpos.  */
   1083 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1084 	 v850_elf_reloc,		/* Special_function.  */
   1085 	 "R_V850_ZDA_15_16_OFFSET",	/* Name.  */
   1086 	 false,				/* Partial_inplace.  */
   1087 	 0xfffe,			/* Src_mask.  */
   1088 	 0xfffe,			/* Dst_mask.  */
   1089 	 false),			/* PCrel_offset.  */
   1090 
   1091   /* 6 bit offset from the tiny data area pointer.  */
   1092   HOWTO (R_V850_TDA_6_8_OFFSET,		/* Type.  */
   1093 	 2,				/* Rightshift.  */
   1094 	 2,				/* Size.  */
   1095 	 8,				/* Bitsize.  */
   1096 	 false,				/* PC_relative.  */
   1097 	 1,				/* Bitpos.  */
   1098 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1099 	 v850_elf_reloc,		/* Special_function.  */
   1100 	 "R_V850_TDA_6_8_OFFSET",	/* Name.  */
   1101 	 false,				/* Partial_inplace.  */
   1102 	 0x7e,				/* Src_mask.  */
   1103 	 0x7e,				/* Dst_mask.  */
   1104 	 false),			/* PCrel_offset.  */
   1105 
   1106   /* 8 bit offset from the tiny data area pointer.  */
   1107   HOWTO (R_V850_TDA_7_8_OFFSET,		/* Type.  */
   1108 	 1,				/* Rightshift.  */
   1109 	 2,				/* Size.  */
   1110 	 8,				/* Bitsize.  */
   1111 	 false,				/* PC_relative.  */
   1112 	 0,				/* Bitpos.  */
   1113 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1114 	 v850_elf_reloc,		/* Special_function.  */
   1115 	 "R_V850_TDA_7_8_OFFSET",	/* Name.  */
   1116 	 false,				/* Partial_inplace.  */
   1117 	 0x7f,				/* Src_mask.  */
   1118 	 0x7f,				/* Dst_mask.  */
   1119 	 false),			/* PCrel_offset.  */
   1120 
   1121   /* 7 bit offset from the tiny data area pointer.  */
   1122   HOWTO (R_V850_TDA_7_7_OFFSET,		/* Type.  */
   1123 	 0,				/* Rightshift.  */
   1124 	 2,				/* Size.  */
   1125 	 7,				/* Bitsize.  */
   1126 	 false,				/* PC_relative.  */
   1127 	 0,				/* Bitpos.  */
   1128 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1129 	 v850_elf_reloc,		/* Special_function.  */
   1130 	 "R_V850_TDA_7_7_OFFSET",	/* Name.  */
   1131 	 false,				/* Partial_inplace.  */
   1132 	 0x7f,				/* Src_mask.  */
   1133 	 0x7f,				/* Dst_mask.  */
   1134 	 false),			/* PCrel_offset.  */
   1135 
   1136   /* 16 bit offset from the tiny data area pointer!  */
   1137   HOWTO (R_V850_TDA_16_16_OFFSET,	/* Type.  */
   1138 	 0,				/* Rightshift.  */
   1139 	 2,				/* Size.  */
   1140 	 16,				/* Bitsize.  */
   1141 	 false,				/* PC_relative.  */
   1142 	 0,				/* Bitpos.  */
   1143 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1144 	 v850_elf_reloc,		/* Special_function.  */
   1145 	 "R_V850_TDA_16_16_OFFSET",	/* Name.  */
   1146 	 false,				/* Partial_inplace.  */
   1147 	 0xffff,			/* Src_mask.  */
   1148 	 0xfff,				/* Dst_mask.  */
   1149 	 false),			/* PCrel_offset.  */
   1150 
   1151   /* 5 bit offset from the tiny data area pointer.  */
   1152   HOWTO (R_V850_TDA_4_5_OFFSET,		/* Type.  */
   1153 	 1,				/* Rightshift.  */
   1154 	 2,				/* Size.  */
   1155 	 5,				/* Bitsize.  */
   1156 	 false,				/* PC_relative.  */
   1157 	 0,				/* Bitpos.  */
   1158 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1159 	 v850_elf_reloc,		/* Special_function.  */
   1160 	 "R_V850_TDA_4_5_OFFSET",	/* Name.  */
   1161 	 false,				/* Partial_inplace.  */
   1162 	 0x0f,				/* Src_mask.  */
   1163 	 0x0f,				/* Dst_mask.  */
   1164 	 false),			/* PCrel_offset.  */
   1165 
   1166   /* 4 bit offset from the tiny data area pointer.  */
   1167   HOWTO (R_V850_TDA_4_4_OFFSET,		/* Type.  */
   1168 	 0,				/* Rightshift.  */
   1169 	 2,				/* Size.  */
   1170 	 4,				/* Bitsize.  */
   1171 	 false,				/* PC_relative.  */
   1172 	 0,				/* Bitpos.  */
   1173 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1174 	 v850_elf_reloc,		/* Special_function.  */
   1175 	 "R_V850_TDA_4_4_OFFSET",	/* Name.  */
   1176 	 false,				/* Partial_inplace.  */
   1177 	 0x0f,				/* Src_mask.  */
   1178 	 0x0f,				/* Dst_mask.  */
   1179 	 false),			/* PCrel_offset.  */
   1180 
   1181   /* 16 bit offset from the short data area pointer.  */
   1182   HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET,	/* Type.  */
   1183 	 0,				/* Rightshift.  */
   1184 	 4,				/* Size.  */
   1185 	 16,				/* Bitsize.  */
   1186 	 false,				/* PC_relative.  */
   1187 	 0,				/* Bitpos.  */
   1188 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1189 	 v850_elf_reloc,		/* Special_function.  */
   1190 	 "R_V850_SDA_16_16_SPLIT_OFFSET",/* Name.  */
   1191 	 false,				/* Partial_inplace.  */
   1192 	 0xfffe0020,			/* Src_mask.  */
   1193 	 0xfffe0020,			/* Dst_mask.  */
   1194 	 false),			/* PCrel_offset.  */
   1195 
   1196   /* 16 bit offset from the zero data area pointer.  */
   1197   HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET,	/* Type.  */
   1198 	 0,				/* Rightshift.  */
   1199 	 4,				/* Size.  */
   1200 	 16,				/* Bitsize.  */
   1201 	 false,				/* PC_relative.  */
   1202 	 0,				/* Bitpos.  */
   1203 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1204 	 v850_elf_reloc,		/* Special_function.  */
   1205 	 "R_V850_ZDA_16_16_SPLIT_OFFSET",/* Name.  */
   1206 	 false,				/* Partial_inplace.  */
   1207 	 0xfffe0020,			/* Src_mask.  */
   1208 	 0xfffe0020,			/* Dst_mask.  */
   1209 	 false),			/* PCrel_offset.  */
   1210 
   1211   /* 6 bit offset from the call table base pointer.  */
   1212   HOWTO (R_V850_CALLT_6_7_OFFSET,	/* Type.  */
   1213 	 0,				/* Rightshift.  */
   1214 	 2,				/* Size.  */
   1215 	 7,				/* Bitsize.  */
   1216 	 false,				/* PC_relative.  */
   1217 	 0,				/* Bitpos.  */
   1218 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1219 	 v850_elf_reloc,		/* Special_function.  */
   1220 	 "R_V850_CALLT_6_7_OFFSET",	/* Name.  */
   1221 	 false,				/* Partial_inplace.  */
   1222 	 0x3f,				/* Src_mask.  */
   1223 	 0x3f,				/* Dst_mask.  */
   1224 	 false),			/* PCrel_offset.  */
   1225 
   1226   /* 16 bit offset from the call table base pointer.  */
   1227   HOWTO (R_V850_CALLT_16_16_OFFSET,	/* Type.  */
   1228 	 0,				/* Rightshift.  */
   1229 	 2,				/* Size.  */
   1230 	 16,				/* Bitsize.  */
   1231 	 false,				/* PC_relative.  */
   1232 	 0,				/* Bitpos.  */
   1233 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1234 	 v850_elf_reloc,		/* Special_function.  */
   1235 	 "R_V850_CALLT_16_16_OFFSET",	/* Name.  */
   1236 	 false,				/* Partial_inplace.  */
   1237 	 0xffff,			/* Src_mask.  */
   1238 	 0xffff,			/* Dst_mask.  */
   1239 	 false),			/* PCrel_offset.  */
   1240 
   1241 
   1242   /* GNU extension to record C++ vtable hierarchy */
   1243   HOWTO (R_V850_GNU_VTINHERIT, /* Type.  */
   1244 	 0,			/* Rightshift.  */
   1245 	 4,			/* Size.  */
   1246 	 0,			/* Bitsize.  */
   1247 	 false,			/* PC_relative.  */
   1248 	 0,			/* Bitpos.  */
   1249 	 complain_overflow_dont, /* Complain_on_overflow.  */
   1250 	 NULL,			/* Special_function.  */
   1251 	 "R_V850_GNU_VTINHERIT", /* Name.  */
   1252 	 false,			/* Partial_inplace.  */
   1253 	 0,			/* Src_mask.  */
   1254 	 0,			/* Dst_mask.  */
   1255 	 false),		/* PCrel_offset.  */
   1256 
   1257   /* GNU extension to record C++ vtable member usage.  */
   1258   HOWTO (R_V850_GNU_VTENTRY,	 /* Type.  */
   1259 	 0,			/* Rightshift.  */
   1260 	 4,			/* Size.  */
   1261 	 0,			/* Bitsize.  */
   1262 	 false,			/* PC_relative.  */
   1263 	 0,			/* Bitpos.  */
   1264 	 complain_overflow_dont, /* Complain_on_overflow.  */
   1265 	 _bfd_elf_rel_vtable_reloc_fn,	/* Special_function.  */
   1266 	 "R_V850_GNU_VTENTRY",	 /* Name.  */
   1267 	 false,			/* Partial_inplace.  */
   1268 	 0,			/* Src_mask.  */
   1269 	 0,			/* Dst_mask.  */
   1270 	 false),		/* PCrel_offset.  */
   1271 
   1272   /* Indicates a .longcall pseudo-op.  The compiler will generate a .longcall
   1273      pseudo-op when it finds a function call which can be relaxed.  */
   1274   HOWTO (R_V850_LONGCALL,     /* Type.  */
   1275 	 0,			/* Rightshift.  */
   1276 	 4,			/* Size.  */
   1277 	 32,			/* Bitsize.  */
   1278 	 true,			/* PC_relative.  */
   1279 	 0,			/* Bitpos.  */
   1280 	 complain_overflow_signed, /* Complain_on_overflow.  */
   1281 	 v850_elf_ignore_reloc, /* Special_function.  */
   1282 	 "R_V850_LONGCALL",	/* Name.  */
   1283 	 false,			/* Partial_inplace.  */
   1284 	 0,			/* Src_mask.  */
   1285 	 0,			/* Dst_mask.  */
   1286 	 true),			/* PCrel_offset.  */
   1287 
   1288   /* Indicates a .longjump pseudo-op.  The compiler will generate a
   1289      .longjump pseudo-op when it finds a branch which can be relaxed.  */
   1290   HOWTO (R_V850_LONGJUMP,     /* Type.  */
   1291 	 0,			/* Rightshift.  */
   1292 	 4,			/* Size.  */
   1293 	 32,			/* Bitsize.  */
   1294 	 true,			/* PC_relative.  */
   1295 	 0,			/* Bitpos.  */
   1296 	 complain_overflow_signed, /* Complain_on_overflow.  */
   1297 	 v850_elf_ignore_reloc, /* Special_function.  */
   1298 	 "R_V850_LONGJUMP",	/* Name.  */
   1299 	 false,			/* Partial_inplace.  */
   1300 	 0,			/* Src_mask.  */
   1301 	 0,			/* Dst_mask.  */
   1302 	 true),			/* PCrel_offset.  */
   1303 
   1304   HOWTO (R_V850_ALIGN,	      /* Type.  */
   1305 	 0,			/* Rightshift.  */
   1306 	 2,			/* Size.  */
   1307 	 0,			/* Bitsize.  */
   1308 	 false,			/* PC_relative.  */
   1309 	 0,			/* Bitpos.  */
   1310 	 complain_overflow_unsigned, /* Complain_on_overflow.  */
   1311 	 v850_elf_ignore_reloc, /* Special_function.  */
   1312 	 "R_V850_ALIGN",	/* Name.  */
   1313 	 false,			/* Partial_inplace.  */
   1314 	 0,			/* Src_mask.  */
   1315 	 0,			/* Dst_mask.  */
   1316 	 true),			/* PCrel_offset.  */
   1317 
   1318   /* Simple pc-relative 32bit reloc.  */
   1319   HOWTO (R_V850_REL32,			/* Type.  */
   1320 	 0,				/* Rightshift.  */
   1321 	 4,				/* Size.  */
   1322 	 32,				/* Bitsize.  */
   1323 	 true,				/* PC_relative.  */
   1324 	 0,				/* Bitpos.  */
   1325 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1326 	 v850_elf_reloc,		/* Special_function.  */
   1327 	 "R_V850_REL32",		/* Name.  */
   1328 	 false,				/* Partial_inplace.  */
   1329 	 0xffffffff,			/* Src_mask.  */
   1330 	 0xffffffff,			/* Dst_mask.  */
   1331 	 false),			/* PCrel_offset.  */
   1332 
   1333   /* An ld.bu version of R_V850_LO16.  */
   1334   HOWTO (R_V850_LO16_SPLIT_OFFSET,	/* Type.  */
   1335 	 0,				/* Rightshift.  */
   1336 	 4,				/* Size.  */
   1337 	 16,				/* Bitsize.  */
   1338 	 false,				/* PC_relative.  */
   1339 	 0,				/* Bitpos.  */
   1340 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1341 	 v850_elf_reloc,		/* Special_function.  */
   1342 	 "R_V850_LO16_SPLIT_OFFSET",	/* Name.  */
   1343 	 false,				/* Partial_inplace.  */
   1344 	 0xfffe0020,			/* Src_mask.  */
   1345 	 0xfffe0020,			/* Dst_mask.  */
   1346 	 false),			/* PCrel_offset.  */
   1347 
   1348   /* A unsigned PC relative 16 bit loop.  */
   1349   HOWTO (R_V850_16_PCREL,		/* Type.  */
   1350 	 0,				/* Rightshift.  */
   1351 	 2,				/* Size.  */
   1352 	 16,				/* Bitsize.  */
   1353 	 true,				/* PC_relative.  */
   1354 	 0,				/* Bitpos.  */
   1355 	 complain_overflow_bitfield,	/* Complain_on_overflow.  */
   1356 	 v850_elf_reloc,		/* Special_function.  */
   1357 	 "R_V850_16_PCREL",		/* Name.  */
   1358 	 false,				/* Partial_inplace.  */
   1359 	 0xfffe,			/* Src_mask.  */
   1360 	 0xfffe,			/* Dst_mask.  */
   1361 	 true),				/* PCrel_offset.  */
   1362 
   1363   /* A PC relative 17 bit branch.  */
   1364   HOWTO (R_V850_17_PCREL,		/* Type.  */
   1365 	 0,				/* Rightshift.  */
   1366 	 4,				/* Size.  */
   1367 	 17,				/* Bitsize.  */
   1368 	 true,				/* PC_relative.  */
   1369 	 0,				/* Bitpos.  */
   1370 	 complain_overflow_bitfield,	/* Complain_on_overflow.  */
   1371 	 v850_elf_reloc,		/* Special_function.  */
   1372 	 "R_V850_17_PCREL",		/* Name.  */
   1373 	 false,				/* Partial_inplace.  */
   1374 	 0x0010fffe,			/* Src_mask.  */
   1375 	 0x0010fffe,			/* Dst_mask.  */
   1376 	 true),				/* PCrel_offset.  */
   1377 
   1378   /* A 23bit offset ld/st.  */
   1379   HOWTO (R_V850_23,			/* type.  */
   1380 	 0,				/* rightshift.  */
   1381 	 4,				/* size.  */
   1382 	 23,				/* bitsize.  */
   1383 	 false,				/* pc_relative.  */
   1384 	 0,				/* bitpos.  */
   1385 	 complain_overflow_dont,	/* complain_on_overflow.  */
   1386 	 v850_elf_reloc,		/* special_function.  */
   1387 	 "R_V850_23",			/* name.  */
   1388 	 false,				/* partial_inplace.  */
   1389 	 0xffff07f0,			/* src_mask.  */
   1390 	 0xffff07f0,			/* dst_mask.  */
   1391 	 false),			/* pcrel_offset.  */
   1392 
   1393   /* A PC relative 32 bit branch.  */
   1394   HOWTO (R_V850_32_PCREL,		/* type.  */
   1395 	 1,				/* rightshift.  */
   1396 	 4,				/* size.  */
   1397 	 32,				/* bitsize.  */
   1398 	 true,				/* pc_relative.  */
   1399 	 1,				/* bitpos.  */
   1400 	 complain_overflow_signed,	/* complain_on_overflow.  */
   1401 	 v850_elf_reloc,		/* special_function.  */
   1402 	 "R_V850_32_PCREL",		/* name.  */
   1403 	 false,				/* partial_inplace.  */
   1404 	 0xfffffffe,			/* src_mask.  */
   1405 	 0xfffffffe,			/* dst_mask.  */
   1406 	 true),				/* pcrel_offset.  */
   1407 
   1408   /* A absolute 32 bit branch.  */
   1409   HOWTO (R_V850_32_ABS,			/* type.  */
   1410 	 1,				/* rightshift.  */
   1411 	 4,				/* size.  */
   1412 	 32,				/* bitsize.  */
   1413 	 true,				/* pc_relative.  */
   1414 	 1,				/* bitpos.  */
   1415 	 complain_overflow_signed,	/* complain_on_overflow.  */
   1416 	 v850_elf_reloc,		/* special_function.  */
   1417 	 "R_V850_32_ABS",		/* name.  */
   1418 	 false,				/* partial_inplace.  */
   1419 	 0xfffffffe,			/* src_mask.  */
   1420 	 0xfffffffe,			/* dst_mask.  */
   1421 	 false),			/* pcrel_offset.  */
   1422 
   1423   /* High 16 bits of symbol value.  */
   1424   HOWTO (R_V850_HI16,			/* Type.  */
   1425 	 0,				/* Rightshift.  */
   1426 	 2,				/* Size.  */
   1427 	 16,				/* Bitsize.  */
   1428 	 false,				/* PC_relative.  */
   1429 	 0,				/* Bitpos.  */
   1430 	 complain_overflow_dont,	/* Complain_on_overflow.  */
   1431 	 v850_elf_reloc,		/* Special_function.  */
   1432 	 "R_V850_HI16",			/* Name.  */
   1433 	 false,				/* Partial_inplace.  */
   1434 	 0xffff,			/* Src_mask.  */
   1435 	 0xffff,			/* Dst_mask.  */
   1436 	 false),			/* PCrel_offset.  */
   1437 
   1438   /* Low 16 bits of symbol value.  */
   1439   HOWTO (R_V850_16_S1,			/* type.  */
   1440 	 1,				/* rightshift.  */
   1441 	 2,				/* size.  */
   1442 	 16,				/* bitsize.  */
   1443 	 false,				/* pc_relative.  */
   1444 	 1,				/* bitpos.  */
   1445 	 complain_overflow_dont,	/* complain_on_overflow.  */
   1446 	 v850_elf_reloc,		/* special_function.  */
   1447 	 "R_V850_16_S1",		/* name.  */
   1448 	 false,				/* partial_inplace.  */
   1449 	 0xfffe,			/* src_mask.  */
   1450 	 0xfffe,			/* dst_mask.  */
   1451 	 false),			/* pcrel_offset.  */
   1452 
   1453   /* Low 16 bits of symbol value.  */
   1454   HOWTO (R_V850_LO16_S1,		/* type.  */
   1455 	 1,				/* rightshift.  */
   1456 	 2,				/* size.  */
   1457 	 16,				/* bitsize.  */
   1458 	 false,				/* pc_relative.  */
   1459 	 1,				/* bitpos.  */
   1460 	 complain_overflow_dont,	/* complain_on_overflow.  */
   1461 	 v850_elf_reloc,		/* special_function.  */
   1462 	 "R_V850_LO16_S1",		/* name.  */
   1463 	 false,				/* partial_inplace.  */
   1464 	 0xfffe,			/* src_mask.  */
   1465 	 0xfffe,			/* dst_mask.  */
   1466 	 false),			/* pcrel_offset.  */
   1467 
   1468   /* 16 bit offset from the call table base pointer.  */
   1469   HOWTO (R_V850_CALLT_15_16_OFFSET,	/* type.  */
   1470 	 1,				/* rightshift.  */
   1471 	 2,				/* size.  */
   1472 	 16,				/* bitsize.  */
   1473 	 false,				/* pc_relative.  */
   1474 	 1,				/* bitpos.  */
   1475 	 complain_overflow_dont,	/* complain_on_overflow.  */
   1476 	 v850_elf_reloc,		/* special_function.  */
   1477 	 "R_V850_CALLT_15_16_OFFSET",	/* name.  */
   1478 	 false,				/* partial_inplace.  */
   1479 	 0xfffe,			/* src_mask.  */
   1480 	 0xfffe,			/* dst_mask.  */
   1481 	 false),			/* pcrel_offset.  */
   1482 
   1483   /* Like R_V850_32 PCREL, but referring to the GOT table entry for
   1484      the symbol.  */
   1485   HOWTO (R_V850_32_GOTPCREL,		/* type.  */
   1486 	 0,				/* rightshift.  */
   1487 	 4,				/* size.  */
   1488 	 32,				/* bitsize.  */
   1489 	 true,				/* pc_relative.  */
   1490 	 0,				/* bitpos.  */
   1491 	 complain_overflow_unsigned,	/* complain_on_overflow.  */
   1492 	 v850_elf_reloc,		/* special_function.  */
   1493 	 "R_V850_32_GOTPCREL",		/* name.  */
   1494 	 false,				/* partial_inplace.  */
   1495 	 0xffffffff,			/* src_mask.  */
   1496 	 0xffffffff,			/* dst_mask.  */
   1497 	 true),				/* pcrel_offset.  */
   1498 
   1499   /* Like R_V850_SDA_, but referring to the GOT table entry for
   1500      the symbol.  */
   1501   HOWTO (R_V850_16_GOT,			/* type.  */
   1502 	 0,				/* rightshift.  */
   1503 	 4,				/* size.  */
   1504 	 16,				/* bitsize.  */
   1505 	 false,				/* pc_relative.  */
   1506 	 0,				/* bitpos.  */
   1507 	 complain_overflow_unsigned,	/* complain_on_overflow.  */
   1508 	 bfd_elf_generic_reloc,		/* special_function.  */
   1509 	 "R_V850_16_GOT",		/* name.  */
   1510 	 false,				/* partial_inplace.  */
   1511 	 0xffff,			/* src_mask.  */
   1512 	 0xffff,			/* dst_mask.  */
   1513 	 false),			/* pcrel_offset.  */
   1514 
   1515   HOWTO (R_V850_32_GOT,			/* type.  */
   1516 	 0,				/* rightshift.  */
   1517 	 4,				/* size.  */
   1518 	 32,				/* bitsize.  */
   1519 	 false,				/* pc_relative.  */
   1520 	 0,				/* bitpos.  */
   1521 	 complain_overflow_unsigned,	/* complain_on_overflow.  */
   1522 	 bfd_elf_generic_reloc,		/* special_function.  */
   1523 	 "R_V850_32_GOT",		/* name.  */
   1524 	 false,				/* partial_inplace.  */
   1525 	 0xffffffff,			/* src_mask.  */
   1526 	 0xffffffff,			/* dst_mask.  */
   1527 	 false),			/* pcrel_offset.  */
   1528 
   1529   /* Like R_V850_22_PCREL, but referring to the procedure linkage table
   1530      entry for the symbol.  */
   1531   HOWTO (R_V850_22_PLT,			/* type.  */
   1532 	 1,				/* rightshift.  */
   1533 	 4,				/* size.  */
   1534 	 22,				/* bitsize.  */
   1535 	 true,				/* pc_relative.  */
   1536 	 7,				/* bitpos.  */
   1537 	 complain_overflow_signed,	/* complain_on_overflow.  */
   1538 	 bfd_elf_generic_reloc,		/* special_function.  */
   1539 	 "R_V850_22_PLT",		/* name.  */
   1540 	 false,				/* partial_inplace.  */
   1541 	 0x07ffff80,			/* src_mask.  */
   1542 	 0x07ffff80,			/* dst_mask.  */
   1543 	 true),				/* pcrel_offset.  */
   1544 
   1545   HOWTO (R_V850_32_PLT,			/* type.  */
   1546 	 1,				/* rightshift.  */
   1547 	 4,				/* size.  */
   1548 	 32,				/* bitsize.  */
   1549 	 true,				/* pc_relative.  */
   1550 	 1,				/* bitpos.  */
   1551 	 complain_overflow_signed,	/* complain_on_overflow.  */
   1552 	 bfd_elf_generic_reloc,		/* special_function.  */
   1553 	 "R_V850_32_PLT",		/* name.  */
   1554 	 false,				/* partial_inplace.  */
   1555 	 0xffffffff,			/* src_mask.  */
   1556 	 0xffffffff,			/* dst_mask.  */
   1557 	 true),				/* pcrel_offset.  */
   1558 
   1559   /* This is used only by the dynamic linker.  The symbol should exist
   1560      both in the object being run and in some shared library.  The
   1561      dynamic linker copies the data addressed by the symbol from the
   1562      shared library into the object, because the object being
   1563      run has to have the data at some particular address.  */
   1564   HOWTO (R_V850_COPY,			/* type.  */
   1565 	 0,				/* rightshift.  */
   1566 	 4,				/* size.  */
   1567 	 32,				/* bitsize.  */
   1568 	 false,				/* pc_relative.  */
   1569 	 0,				/* bitpos.  */
   1570 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1571 	 bfd_elf_generic_reloc,		/* special_function.  */
   1572 	 "R_V850_COPY",			/* name.  */
   1573 	 false,				/* partial_inplace.  */
   1574 	 0xffffffff,			/* src_mask.  */
   1575 	 0xffffffff,			/* dst_mask.  */
   1576 	 false),			/* pcrel_offset.  */
   1577 
   1578   /* Like R_M32R_24, but used when setting global offset table
   1579      entries.  */
   1580   HOWTO (R_V850_GLOB_DAT,		/* type.  */
   1581 	 0,				/* rightshift.  */
   1582 	 4,				/* size */
   1583 	 32,				/* bitsize.  */
   1584 	 false,				/* pc_relative.  */
   1585 	 0,				/* bitpos.  */
   1586 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1587 	 bfd_elf_generic_reloc,		/* special_function.  */
   1588 	 "R_V850_GLOB_DAT",		/* name.  */
   1589 	 false,				/* partial_inplace.  */
   1590 	 0xffffffff,			/* src_mask.  */
   1591 	 0xffffffff,			/* dst_mask.  */
   1592 	 false),			/* pcrel_offset.  */
   1593 
   1594   /* Marks a procedure linkage table entry for a symbol.  */
   1595   HOWTO (R_V850_JMP_SLOT,		/* type.  */
   1596 	 0,				/* rightshift.  */
   1597 	 4,				/* size */
   1598 	 32,				/* bitsize.  */
   1599 	 false,				/* pc_relative.  */
   1600 	 0,				/* bitpos.  */
   1601 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1602 	 bfd_elf_generic_reloc,		/* special_function.  */
   1603 	 "R_V850_JMP_SLOT",		/* name.  */
   1604 	 false,				/* partial_inplace.  */
   1605 	 0xffffffff,			/* src_mask.  */
   1606 	 0xffffffff,			/* dst_mask.  */
   1607 	 false),			/* pcrel_offset.  */
   1608 
   1609   /* Used only by the dynamic linker.  When the object is run, this
   1610      longword is set to the load address of the object, plus the
   1611      addend.  */
   1612   HOWTO (R_V850_RELATIVE,		/* type.  */
   1613 	 0,				/* rightshift.  */
   1614 	 4,				/* size */
   1615 	 32,				/* bitsize.  */
   1616 	 false,				/* pc_relative.  */
   1617 	 0,				/* bitpos.  */
   1618 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1619 	 bfd_elf_generic_reloc,		/* special_function.  */
   1620 	 "R_V850_RELATIVE",		/* name.  */
   1621 	 false,				/* partial_inplace.  */
   1622 	 0xffffffff,			/* src_mask.  */
   1623 	 0xffffffff,			/* dst_mask.  */
   1624 	 false),			/* pcrel_offset.  */
   1625 
   1626   HOWTO (R_V850_16_GOTOFF,		/* type.  */
   1627 	 0,				/* rightshift.  */
   1628 	 4,				/* size */
   1629 	 16,				/* bitsize.  */
   1630 	 false,				/* pc_relative.  */
   1631 	 0,				/* bitpos.  */
   1632 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1633 	 bfd_elf_generic_reloc,		/* special_function.  */
   1634 	 "R_V850_16_GOTOFF",		/* name.  */
   1635 	 false,				/* partial_inplace.  */
   1636 	 0xffff,			/* src_mask.  */
   1637 	 0xffff,			/* dst_mask.  */
   1638 	 false),			/* pcrel_offset.  */
   1639 
   1640   HOWTO (R_V850_32_GOTOFF,		/* type.  */
   1641 	 0,				/* rightshift.  */
   1642 	 4,				/* size */
   1643 	 32,				/* bitsize.  */
   1644 	 false,				/* pc_relative.  */
   1645 	 0,				/* bitpos.  */
   1646 	 complain_overflow_bitfield,	/* complain_on_overflow.  */
   1647 	 bfd_elf_generic_reloc,		/* special_function.  */
   1648 	 "R_V850_32_GOTOFF",		/* name.  */
   1649 	 false,				/* partial_inplace.  */
   1650 	 0xffffffff,			/* src_mask.  */
   1651 	 0xffffffff,			/* dst_mask.  */
   1652 	 false),			/* pcrel_offset.  */
   1653 
   1654   HOWTO (R_V850_CODE,			/* type.  */
   1655 	 0,				/* rightshift.  */
   1656 	 2,				/* size */
   1657 	 0,				/* bitsize.  */
   1658 	 false,				/* pc_relative.  */
   1659 	 0,				/* bitpos.  */
   1660 	 complain_overflow_unsigned,	/* complain_on_overflow.  */
   1661 	 v850_elf_ignore_reloc,		/* special_function.  */
   1662 	 "R_V850_CODE",			/* name.  */
   1663 	 false,				/* partial_inplace.  */
   1664 	 0,				/* src_mask.  */
   1665 	 0,				/* dst_mask.  */
   1666 	 true),				/* pcrel_offset.  */
   1667 
   1668   HOWTO (R_V850_DATA,			/* type.  */
   1669 	 0,				/* rightshift.  */
   1670 	 2,				/* size */
   1671 	 0,				/* bitsize.  */
   1672 	 false,				/* pc_relative.  */
   1673 	 0,				/* bitpos.  */
   1674 	 complain_overflow_unsigned,	/* complain_on_overflow.  */
   1675 	 v850_elf_ignore_reloc,		/* special_function.  */
   1676 	 "R_V850_DATA",			/* name.  */
   1677 	 false,				/* partial_inplace.  */
   1678 	 0,				/* src_mask.  */
   1679 	 0,				/* dst_mask.  */
   1680 	 true),				/* pcrel_offset.  */
   1681 
   1682 };
   1683 
   1684 /* Map BFD reloc types to V850 ELF reloc types.  */
   1685 
   1686 struct v850_elf_reloc_map
   1687 {
   1688   /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an
   1689      unsigned char.  */
   1690   bfd_reloc_code_real_type bfd_reloc_val;
   1691   unsigned int elf_reloc_val;
   1692 };
   1693 
   1694 static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
   1695 {
   1696   { BFD_RELOC_NONE,			   R_V850_NONE			 },
   1697   { BFD_RELOC_V850_9_PCREL,		   R_V850_9_PCREL		 },
   1698   { BFD_RELOC_V850_22_PCREL,		   R_V850_22_PCREL		 },
   1699   { BFD_RELOC_HI16_S,			   R_V850_HI16_S		 },
   1700   { BFD_RELOC_HI16,			   R_V850_HI16			 },
   1701   { BFD_RELOC_LO16,			   R_V850_LO16			 },
   1702   { BFD_RELOC_32,			   R_V850_ABS32			 },
   1703   { BFD_RELOC_32_PCREL,			   R_V850_REL32			 },
   1704   { BFD_RELOC_16,			   R_V850_16			 },
   1705   { BFD_RELOC_8,			   R_V850_8			 },
   1706   { BFD_RELOC_V850_SDA_16_16_OFFSET,	   R_V850_SDA_16_16_OFFSET	 },
   1707   { BFD_RELOC_V850_SDA_15_16_OFFSET,	   R_V850_SDA_15_16_OFFSET	 },
   1708   { BFD_RELOC_V850_ZDA_16_16_OFFSET,	   R_V850_ZDA_16_16_OFFSET	 },
   1709   { BFD_RELOC_V850_ZDA_15_16_OFFSET,	   R_V850_ZDA_15_16_OFFSET	 },
   1710   { BFD_RELOC_V850_TDA_6_8_OFFSET,	   R_V850_TDA_6_8_OFFSET	 },
   1711   { BFD_RELOC_V850_TDA_7_8_OFFSET,	   R_V850_TDA_7_8_OFFSET	 },
   1712   { BFD_RELOC_V850_TDA_7_7_OFFSET,	   R_V850_TDA_7_7_OFFSET	 },
   1713   { BFD_RELOC_V850_TDA_16_16_OFFSET,	   R_V850_TDA_16_16_OFFSET	 },
   1714   { BFD_RELOC_V850_TDA_4_5_OFFSET,	   R_V850_TDA_4_5_OFFSET	 },
   1715   { BFD_RELOC_V850_TDA_4_4_OFFSET,	   R_V850_TDA_4_4_OFFSET	 },
   1716   { BFD_RELOC_V850_LO16_SPLIT_OFFSET,	   R_V850_LO16_SPLIT_OFFSET	 },
   1717   { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET },
   1718   { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET },
   1719   { BFD_RELOC_V850_CALLT_6_7_OFFSET,	   R_V850_CALLT_6_7_OFFSET	 },
   1720   { BFD_RELOC_V850_CALLT_16_16_OFFSET,	   R_V850_CALLT_16_16_OFFSET	 },
   1721   { BFD_RELOC_VTABLE_INHERIT,		   R_V850_GNU_VTINHERIT		 },
   1722   { BFD_RELOC_VTABLE_ENTRY,		   R_V850_GNU_VTENTRY		 },
   1723   { BFD_RELOC_V850_LONGCALL,		   R_V850_LONGCALL		 },
   1724   { BFD_RELOC_V850_LONGJUMP,		   R_V850_LONGJUMP		 },
   1725   { BFD_RELOC_V850_ALIGN,		   R_V850_ALIGN			 },
   1726   { BFD_RELOC_V850_16_PCREL,		   R_V850_16_PCREL		 },
   1727   { BFD_RELOC_V850_17_PCREL,		   R_V850_17_PCREL		 },
   1728   { BFD_RELOC_V850_23,			   R_V850_23			 },
   1729   { BFD_RELOC_V850_32_PCREL,		   R_V850_32_PCREL		 },
   1730   { BFD_RELOC_V850_32_ABS,		   R_V850_32_ABS		 },
   1731   { BFD_RELOC_V850_16_SPLIT_OFFSET,	   R_V850_HI16			 },
   1732   { BFD_RELOC_V850_16_S1,		   R_V850_16_S1			 },
   1733   { BFD_RELOC_V850_LO16_S1,		   R_V850_LO16_S1		 },
   1734   { BFD_RELOC_V850_CALLT_15_16_OFFSET,	   R_V850_CALLT_15_16_OFFSET	 },
   1735   { BFD_RELOC_V850_32_GOTPCREL,		   R_V850_32_GOTPCREL		 },
   1736   { BFD_RELOC_V850_16_GOT,		   R_V850_16_GOT		 },
   1737   { BFD_RELOC_V850_32_GOT,		   R_V850_32_GOT		 },
   1738   { BFD_RELOC_V850_22_PLT_PCREL,	   R_V850_22_PLT		 },
   1739   { BFD_RELOC_V850_32_PLT_PCREL,	   R_V850_32_PLT		 },
   1740   { BFD_RELOC_V850_COPY,		   R_V850_COPY			 },
   1741   { BFD_RELOC_V850_GLOB_DAT,		   R_V850_GLOB_DAT		 },
   1742   { BFD_RELOC_V850_JMP_SLOT,		   R_V850_JMP_SLOT		 },
   1743   { BFD_RELOC_V850_RELATIVE,		   R_V850_RELATIVE		 },
   1744   { BFD_RELOC_V850_16_GOTOFF,		   R_V850_16_GOTOFF		 },
   1745   { BFD_RELOC_V850_32_GOTOFF,		   R_V850_32_GOTOFF		 },
   1746   { BFD_RELOC_V850_CODE,		   R_V850_CODE			 },
   1747   { BFD_RELOC_V850_DATA,		   R_V850_DATA			 },
   1748 };
   1749 
   1750 #define V800_RELOC(name,sz,bit,shift,complain,pcrel,resolver)		 \
   1751   HOWTO (name, shift, sz, bit, pcrel, 0, complain_overflow_ ## complain, \
   1752 	 bfd_elf_ ## resolver ## _reloc, #name, false, 0, ~0, false)
   1753 
   1754 #define V800_EMPTY(name) EMPTY_HOWTO (name - R_V810_NONE)
   1755 
   1756 #define bfd_elf_v850_reloc v850_elf_reloc
   1757 
   1758 /* Note: It is REQUIRED that the 'type' value (R_V810_...) of each entry
   1759    in this array match the index of the entry in the array minus 0x30.
   1760    See: bfd_elf_v850_relocate_section(), v800_elf_reloc_type_lookup()
   1761    and v800_elf_info_to_howto().  */
   1762 
   1763 static reloc_howto_type v800_elf_howto_table[] =
   1764 {
   1765   V800_RELOC (R_V810_NONE,      0,  0, 0, dont,     false, generic),	/* Type = 0x30 */
   1766   V800_RELOC (R_V810_BYTE,      1,  8, 0, dont,     false, generic),
   1767   V800_RELOC (R_V810_HWORD,     2, 16, 0, dont,     false, generic),
   1768   V800_RELOC (R_V810_WORD,      4, 32, 0, dont,     false, generic),
   1769   V800_RELOC (R_V810_WLO,       2, 16, 0, dont,     false, generic),
   1770   V800_RELOC (R_V810_WHI,       2, 16, 0, dont,     false, generic),
   1771   V800_RELOC (R_V810_WHI1,      2, 16, 0, dont,     false, generic),
   1772   V800_RELOC (R_V810_GPBYTE,    1,  8, 0, dont,     false, v850),
   1773   V800_RELOC (R_V810_GPHWORD,   2, 16, 0, dont,     false, v850),
   1774   V800_RELOC (R_V810_GPWORD,    4, 32, 0, dont,     false, v850),
   1775   V800_RELOC (R_V810_GPWLO,     2, 16, 0, dont,     false, v850),
   1776   V800_RELOC (R_V810_GPWHI,     2, 16, 0, dont,     false, v850),
   1777   V800_RELOC (R_V810_GPWHI1,    2, 16, 0, dont,     false, v850),
   1778   V800_RELOC (R_V850_HWLO,      2, 16, 0, dont,     false, generic),
   1779   V800_EMPTY (R_V810_reserved1),
   1780   V800_RELOC (R_V850_EP7BIT,    1,  7, 0, unsigned, false, v850),
   1781   V800_RELOC (R_V850_EPHBYTE,   1,  8, 1, unsigned, false, v850),
   1782   V800_RELOC (R_V850_EPWBYTE,   1,  8, 2, unsigned, false, v850),
   1783   V800_RELOC (R_V850_REGHWLO,   2, 16, 0, dont,     false, v850),
   1784   V800_EMPTY (R_V810_reserved2),
   1785   V800_RELOC (R_V850_GPHWLO,    2, 16, 0, dont,     false, v850),
   1786   V800_EMPTY (R_V810_reserved3),
   1787   V800_RELOC (R_V850_PCR22,     4, 22, 0, signed,   true,  generic),
   1788   V800_RELOC (R_V850_BLO,       4, 24, 0, dont,     false, v850),
   1789   V800_RELOC (R_V850_EP4BIT,    1,  4, 0, unsigned, false, v850),
   1790   V800_RELOC (R_V850_EP5BIT,    1,  5, 0, unsigned, false, v850),
   1791   V800_RELOC (R_V850_REGBLO,    4, 24, 0, dont,     false, v850),
   1792   V800_RELOC (R_V850_GPBLO,     4, 24, 0, dont,     false, v850),
   1793   V800_RELOC (R_V810_WLO_1,     2, 16, 0, dont,     false, v850),
   1794   V800_RELOC (R_V810_GPWLO_1,   2, 16, 0, signed,   false, v850),
   1795   V800_RELOC (R_V850_BLO_1,     4, 16, 0, signed,   false, v850),
   1796   V800_RELOC (R_V850_HWLO_1,    2, 16, 0, signed,   false, v850),
   1797   V800_EMPTY  (R_V810_reserved4),
   1798   V800_RELOC (R_V850_GPBLO_1,   4, 16, 1, signed,   false, v850),
   1799   V800_RELOC (R_V850_GPHWLO_1,  2, 16, 1, signed,   false, v850),
   1800   V800_EMPTY (R_V810_reserved5),
   1801   V800_RELOC (R_V850_EPBLO,     4, 16, 1, signed,   false, v850),
   1802   V800_RELOC (R_V850_EPHWLO,    2, 16, 1, signed,   false, v850),
   1803   V800_EMPTY (R_V810_reserved6),
   1804   V800_RELOC (R_V850_EPWLO_N,   2, 16, 1, signed,   false, v850),
   1805   V800_RELOC (R_V850_PC32,      4, 32, 1, signed,   true,  v850),
   1806   V800_RELOC (R_V850_W23BIT,    4, 23, 1, signed,   false, v850),
   1807   V800_RELOC (R_V850_GPW23BIT,  4, 23, 1, signed,   false, v850),
   1808   V800_RELOC (R_V850_EPW23BIT,  4, 23, 1, signed,   false, v850),
   1809   V800_RELOC (R_V850_B23BIT,    4, 23, 1, signed,   false, v850),
   1810   V800_RELOC (R_V850_GPB23BIT,  4, 23, 1, signed,   false, v850),
   1811   V800_RELOC (R_V850_EPB23BIT,  4, 23, 1, signed,   false, v850),
   1812   V800_RELOC (R_V850_PC16U,     2, 16, 1, unsigned, true,  generic),
   1813   V800_RELOC (R_V850_PC17,      4, 17, 1, signed,   true,  generic),
   1814   V800_RELOC (R_V850_DW8,       4,  8, 2, signed,   false, v850),
   1815   V800_RELOC (R_V850_GPDW8,     4,  8, 2, signed,   false, v850),
   1816   V800_RELOC (R_V850_EPDW8,     4,  8, 2, signed,   false, v850),
   1817   V800_RELOC (R_V850_PC9,       2,  9, 3, signed,   true,  v850),
   1818   V800_RELOC (R_V810_REGBYTE,   1,  8, 0, dont,     false, v850),
   1819   V800_RELOC (R_V810_REGHWORD,  2, 16, 0, dont,     false, v850),
   1820   V800_RELOC (R_V810_REGWORD,   4, 32, 0, dont,     false, v850),
   1821   V800_RELOC (R_V810_REGWLO,    2, 16, 0, dont,     false, v850),
   1822   V800_RELOC (R_V810_REGWHI,    2, 16, 0, dont,     false, v850),
   1823   V800_RELOC (R_V810_REGWHI1,   2, 16, 0, dont,     false, v850),
   1824   V800_RELOC (R_V850_REGW23BIT, 4, 23, 1, signed,   false, v850),
   1825   V800_RELOC (R_V850_REGB23BIT, 4, 23, 1, signed,   false, v850),
   1826   V800_RELOC (R_V850_REGDW8,    4,  8, 2, signed,   false, v850),
   1827   V800_RELOC (R_V810_EPBYTE,    1,  8, 0, dont,     false, v850),
   1828   V800_RELOC (R_V810_EPHWORD,   2, 16, 0, dont,     false, v850),
   1829   V800_RELOC (R_V810_EPWORD,    4, 32, 0, dont,     false, v850),
   1830   V800_RELOC (R_V850_WLO23,     4, 32, 1, dont,     false, v850),
   1831   V800_RELOC (R_V850_WORD_E,    4, 32, 1, dont,     false, v850),
   1832   V800_RELOC (R_V850_REGWORD_E, 4, 32, 1, dont,     false, v850),
   1833   V800_RELOC (R_V850_WORD,      4, 32, 0, dont,     false, v850),
   1834   V800_RELOC (R_V850_GPWORD,    4, 32, 0, dont,     false, v850),
   1835   V800_RELOC (R_V850_REGWORD,   4, 32, 0, dont,     false, v850),
   1836   V800_RELOC (R_V850_EPWORD,    4, 32, 0, dont,     false, v850),
   1837   V800_RELOC (R_V810_TPBYTE,    1,  8, 0, dont,     false, v850),
   1838   V800_RELOC (R_V810_TPHWORD,   2, 16, 0, dont,     false, v850),
   1839   V800_RELOC (R_V810_TPWORD,    4, 32, 0, dont,     false, v850),
   1840   V800_RELOC (R_V810_TPWLO,     2, 16, 0, dont,     false, v850),
   1841   V800_RELOC (R_V810_TPWHI,     2, 16, 0, dont,     false, v850),
   1842   V800_RELOC (R_V810_TPWHI1,    2, 16, 0, dont,     false, v850),
   1843   V800_RELOC (R_V850_TPHWLO,    2, 16, 1, dont,     false, v850),
   1844   V800_RELOC (R_V850_TPBLO,     4, 24, 0, dont,     false, v850),
   1845   V800_RELOC (R_V810_TPWLO_1,   2, 16, 0, signed,   false, v850),
   1846   V800_RELOC (R_V850_TPBLO_1,   4, 16, 0, signed,   false, v850),
   1847   V800_RELOC (R_V850_TPHWLO_1,  2, 16, 0, signed,   false, v850),
   1848   V800_RELOC (R_V850_TP23BIT,   4, 23, 0, signed,   false, v850),
   1849   V800_RELOC (R_V850_TPW23BIT,  4, 23, 0, signed,   false, v850),
   1850   V800_RELOC (R_V850_TPDW8,     4,  8, 0, signed,   false, v850)
   1851 };
   1852 
   1853 /* Map a bfd relocation into the appropriate howto structure.  */
   1855 
   1856 static reloc_howto_type *
   1857 v850_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1858 			    bfd_reloc_code_real_type code)
   1859 {
   1860   unsigned int i;
   1861 
   1862   for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
   1863     if (v850_elf_reloc_map[i].bfd_reloc_val == code)
   1864       {
   1865 	unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
   1866 
   1867 	BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
   1868 
   1869 	return v850_elf_howto_table + elf_reloc_val;
   1870       }
   1871 
   1872   return NULL;
   1873 }
   1874 
   1875 static reloc_howto_type *
   1876 v850_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1877 			    const char *r_name)
   1878 {
   1879   unsigned int i;
   1880 
   1881   for (i = 0;
   1882        i < sizeof (v850_elf_howto_table) / sizeof (v850_elf_howto_table[0]);
   1883        i++)
   1884     if (v850_elf_howto_table[i].name != NULL
   1885 	&& strcasecmp (v850_elf_howto_table[i].name, r_name) == 0)
   1886       return &v850_elf_howto_table[i];
   1887 
   1888   return NULL;
   1889 }
   1890 
   1891 /* Set the howto pointer for an V850 ELF reloc.  */
   1893 
   1894 static bool
   1895 v850_elf_info_to_howto_rel (bfd *abfd,
   1896 			    arelent *cache_ptr,
   1897 			    Elf_Internal_Rela *dst)
   1898 {
   1899   unsigned int r_type;
   1900 
   1901   r_type = ELF32_R_TYPE (dst->r_info);
   1902   if (r_type >= (unsigned int) R_V850_max)
   1903     {
   1904       /* xgettext:c-format */
   1905       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1906 			  abfd, r_type);
   1907       bfd_set_error (bfd_error_bad_value);
   1908       return false;
   1909     }
   1910   cache_ptr->howto = &v850_elf_howto_table[r_type];
   1911   return true;
   1912 }
   1913 
   1914 /* Set the howto pointer for a V850 ELF reloc (type RELA).  */
   1915 
   1916 static bool
   1917 v850_elf_info_to_howto_rela (bfd *abfd,
   1918 			     arelent * cache_ptr,
   1919 			     Elf_Internal_Rela *dst)
   1920 {
   1921   unsigned int r_type;
   1922 
   1923   r_type = ELF32_R_TYPE (dst->r_info);
   1924   if (r_type >= (unsigned int) R_V850_max)
   1925     {
   1926       /* xgettext:c-format */
   1927       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   1928 			  abfd, r_type);
   1929       bfd_set_error (bfd_error_bad_value);
   1930       return false;
   1931     }
   1932   cache_ptr->howto = &v850_elf_howto_table[r_type];
   1933   return true;
   1934 }
   1935 
   1936 static bool
   1938 v850_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
   1939 {
   1940   return (   (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
   1941 	  || (name[0] == '_' &&  name[1] == '.' && name[2] == 'L' && name[3] == '_'));
   1942 }
   1943 
   1944 static bool
   1945 v850_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)
   1946 {
   1947   return v850_elf_is_local_label_name (abfd, sym->name);
   1948 }
   1949 
   1950 /* We overload some of the bfd_reloc error codes for own purposes.  */
   1952 #define bfd_reloc_gp_not_found		bfd_reloc_other
   1953 #define bfd_reloc_ep_not_found		bfd_reloc_continue
   1954 #define bfd_reloc_ctbp_not_found	(bfd_reloc_dangerous + 1)
   1955 
   1956 /* Perform a relocation as part of a final link.  */
   1957 
   1958 static bfd_reloc_status_type
   1959 v850_elf_final_link_relocate (reloc_howto_type *howto,
   1960 			      bfd *input_bfd,
   1961 			      bfd *output_bfd ATTRIBUTE_UNUSED,
   1962 			      asection *input_section,
   1963 			      bfd_byte *contents,
   1964 			      bfd_vma offset,
   1965 			      bfd_vma value,
   1966 			      bfd_vma addend,
   1967 			      struct bfd_link_info *info,
   1968 			      asection *sym_sec,
   1969 			      int is_local ATTRIBUTE_UNUSED)
   1970 {
   1971   unsigned int r_type = howto->type;
   1972   bfd_byte *hit_data = contents + offset;
   1973 
   1974   /* Adjust the value according to the relocation.  */
   1975   switch (r_type)
   1976     {
   1977     case R_V850_PC9:
   1978     case R_V850_9_PCREL:
   1979       value -= (input_section->output_section->vma
   1980 		+ input_section->output_offset);
   1981       value -= offset;
   1982       break;
   1983 
   1984     case R_V850_PC16U:
   1985     case R_V850_16_PCREL:
   1986       value -= (input_section->output_section->vma
   1987 		+ input_section->output_offset
   1988 		+ offset);
   1989 
   1990       /* If the sign extension will corrupt the value then we have overflowed.  */
   1991       if ((value & 0xffff0000) != 0xffff0000)
   1992 	return bfd_reloc_overflow;
   1993 
   1994       break;
   1995 
   1996     case R_V850_PC17:
   1997     case R_V850_17_PCREL:
   1998       value -= (input_section->output_section->vma
   1999 		+ input_section->output_offset
   2000 		+ offset);
   2001 
   2002       /* If the sign extension will corrupt the value then we have overflowed.  */
   2003       if (((value & 0xffff0000) != 0x0) && ((value & 0xffff0000) != 0xffff0000))
   2004 	return bfd_reloc_overflow;
   2005 
   2006       value = SEXT17 (value);
   2007       break;
   2008 
   2009     case R_V850_PCR22:
   2010     case R_V850_22_PCREL:
   2011       value -= (input_section->output_section->vma
   2012 		+ input_section->output_offset
   2013 		+ offset);
   2014 
   2015       /* If the sign extension will corrupt the value then we have overflowed.  */
   2016       if (((value & 0xffe00000) != 0x0) && ((value & 0xffe00000) != 0xffe00000))
   2017 	return bfd_reloc_overflow;
   2018 
   2019       /* Only the bottom 22 bits of the PC are valid.  */
   2020       value = SEXT22 (value);
   2021       break;
   2022 
   2023     case R_V850_PC32:
   2024     case R_V850_32_PCREL:
   2025       value -= (input_section->output_section->vma
   2026 		+ input_section->output_offset
   2027 		+ offset);
   2028       break;
   2029 
   2030     case R_V850_32_ABS:
   2031     case R_V850_23:
   2032     case R_V850_HI16_S:
   2033     case R_V850_HI16:
   2034     case R_V850_LO16:
   2035     case R_V850_LO16_S1:
   2036     case R_V850_LO16_SPLIT_OFFSET:
   2037     case R_V850_16:
   2038     case R_V850_ABS32:
   2039     case R_V850_8:
   2040     case R_V810_BYTE:
   2041     case R_V810_HWORD:
   2042     case R_V810_WORD:
   2043     case R_V810_WLO:
   2044     case R_V810_WHI:
   2045     case R_V810_WHI1:
   2046     case R_V810_WLO_1:
   2047     case R_V850_WLO23:
   2048     case R_V850_BLO:
   2049       break;
   2050 
   2051     case R_V850_ZDA_15_16_OFFSET:
   2052     case R_V850_ZDA_16_16_OFFSET:
   2053     case R_V850_ZDA_16_16_SPLIT_OFFSET:
   2054       if (sym_sec == NULL)
   2055 	return bfd_reloc_undefined;
   2056 
   2057       value -= sym_sec->output_section->vma;
   2058       break;
   2059 
   2060     case R_V850_SDA_15_16_OFFSET:
   2061     case R_V850_SDA_16_16_OFFSET:
   2062     case R_V850_SDA_16_16_SPLIT_OFFSET:
   2063     case R_V810_GPWLO_1:
   2064       {
   2065 	unsigned long		     gp;
   2066 	struct bfd_link_hash_entry * h;
   2067 
   2068 	if (sym_sec == NULL)
   2069 	  return bfd_reloc_undefined;
   2070 
   2071 	/* Get the value of __gp.  */
   2072 	h = bfd_link_hash_lookup (info->hash, "__gp", false, false, true);
   2073 	if (h == NULL
   2074 	    || h->type != bfd_link_hash_defined)
   2075 	  return bfd_reloc_gp_not_found;
   2076 
   2077 	gp = (h->u.def.value
   2078 	      + h->u.def.section->output_section->vma
   2079 	      + h->u.def.section->output_offset);
   2080 
   2081 	value -= sym_sec->output_section->vma;
   2082 	value -= (gp - sym_sec->output_section->vma);
   2083       }
   2084     break;
   2085 
   2086     case R_V850_TDA_4_4_OFFSET:
   2087     case R_V850_TDA_4_5_OFFSET:
   2088     case R_V850_TDA_7_7_OFFSET:
   2089     case R_V850_TDA_7_8_OFFSET:
   2090     case R_V850_TDA_6_8_OFFSET:
   2091     case R_V850_TDA_16_16_OFFSET:
   2092       {
   2093 	unsigned long		     ep;
   2094 	struct bfd_link_hash_entry * h;
   2095 
   2096 	/* Get the value of __ep.  */
   2097 	h = bfd_link_hash_lookup (info->hash, "__ep", false, false, true);
   2098 	if (h == NULL
   2099 	    || h->type != bfd_link_hash_defined)
   2100 	  return bfd_reloc_ep_not_found;
   2101 
   2102 	ep = (h->u.def.value
   2103 	      + h->u.def.section->output_section->vma
   2104 	      + h->u.def.section->output_offset);
   2105 
   2106 	value -= ep;
   2107       }
   2108     break;
   2109 
   2110     case R_V850_CALLT_6_7_OFFSET:
   2111       {
   2112 	unsigned long		     ctbp;
   2113 	struct bfd_link_hash_entry * h;
   2114 
   2115 	/* Get the value of __ctbp.  */
   2116 	h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
   2117 	if (h == NULL
   2118 	    || h->type != bfd_link_hash_defined)
   2119 	  return bfd_reloc_ctbp_not_found;
   2120 
   2121 	ctbp = (h->u.def.value
   2122 	      + h->u.def.section->output_section->vma
   2123 	      + h->u.def.section->output_offset);
   2124 	value -= ctbp;
   2125       }
   2126     break;
   2127 
   2128     case R_V850_CALLT_15_16_OFFSET:
   2129     case R_V850_CALLT_16_16_OFFSET:
   2130       {
   2131 	unsigned long		     ctbp;
   2132 	struct bfd_link_hash_entry * h;
   2133 
   2134 	if (sym_sec == NULL)
   2135 	  return bfd_reloc_undefined;
   2136 
   2137 	/* Get the value of __ctbp.  */
   2138 	h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
   2139 	if (h == NULL
   2140 	    || h->type != bfd_link_hash_defined)
   2141 	  return bfd_reloc_ctbp_not_found;
   2142 
   2143 	ctbp = (h->u.def.value
   2144 	      + h->u.def.section->output_section->vma
   2145 	      + h->u.def.section->output_offset);
   2146 
   2147 	value -= sym_sec->output_section->vma;
   2148 	value -= (ctbp - sym_sec->output_section->vma);
   2149       }
   2150     break;
   2151 
   2152     case R_V850_NONE:
   2153     case R_V810_NONE:
   2154     case R_V850_GNU_VTINHERIT:
   2155     case R_V850_GNU_VTENTRY:
   2156     case R_V850_LONGCALL:
   2157     case R_V850_LONGJUMP:
   2158     case R_V850_ALIGN:
   2159       return bfd_reloc_ok;
   2160 
   2161     default:
   2162 #ifdef DEBUG
   2163       _bfd_error_handler ("%pB: unsupported relocation type %#x",
   2164 	       input_bfd, r_type);
   2165 #endif
   2166       return bfd_reloc_notsupported;
   2167     }
   2168 
   2169   /* Perform the relocation.  */
   2170   return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data);
   2171 }
   2172 
   2173 /* Relocate an V850 ELF section.  */
   2175 
   2176 static int
   2177 v850_elf_relocate_section (bfd *output_bfd,
   2178 			   struct bfd_link_info *info,
   2179 			   bfd *input_bfd,
   2180 			   asection *input_section,
   2181 			   bfd_byte *contents,
   2182 			   Elf_Internal_Rela *relocs,
   2183 			   Elf_Internal_Sym *local_syms,
   2184 			   asection **local_sections)
   2185 {
   2186   Elf_Internal_Shdr *symtab_hdr;
   2187   struct elf_link_hash_entry **sym_hashes;
   2188   Elf_Internal_Rela *rel;
   2189   Elf_Internal_Rela *relend;
   2190 
   2191   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   2192   sym_hashes = elf_sym_hashes (input_bfd);
   2193 
   2194   /* Reset the list of remembered HI16S relocs to empty.  */
   2195   free_hi16s     = previous_hi16s;
   2196   previous_hi16s = NULL;
   2197   hi16s_counter  = 0;
   2198 
   2199   rel    = relocs;
   2200   relend = relocs + input_section->reloc_count;
   2201   for (; rel < relend; rel++)
   2202     {
   2203       unsigned int r_type;
   2204       reloc_howto_type *howto;
   2205       unsigned long r_symndx;
   2206       Elf_Internal_Sym *sym;
   2207       asection *sec;
   2208       struct elf_link_hash_entry *h;
   2209       bfd_vma relocation;
   2210       bfd_reloc_status_type r;
   2211 
   2212       r_symndx = ELF32_R_SYM (rel->r_info);
   2213       r_type   = ELF32_R_TYPE (rel->r_info);
   2214 
   2215       if (r_type == R_V850_GNU_VTENTRY
   2216 	  || r_type == R_V850_GNU_VTINHERIT)
   2217 	continue;
   2218 
   2219       if (bfd_get_arch (input_bfd) == bfd_arch_v850_rh850)
   2220 	howto = v800_elf_howto_table + (r_type - R_V810_NONE);
   2221       else
   2222 	howto = v850_elf_howto_table + r_type;
   2223 
   2224       BFD_ASSERT (r_type == howto->type);
   2225 
   2226       h = NULL;
   2227       sym = NULL;
   2228       sec = NULL;
   2229       if (r_symndx < symtab_hdr->sh_info)
   2230 	{
   2231 	  sym = local_syms + r_symndx;
   2232 	  sec = local_sections[r_symndx];
   2233 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   2234 	}
   2235       else
   2236 	{
   2237 	  bool unresolved_reloc, warned, ignored;
   2238 
   2239 	  /* Note - this check is delayed until now as it is possible and
   2240 	     valid to have a file without any symbols but with relocs that
   2241 	     can be processed.  */
   2242 	  if (sym_hashes == NULL)
   2243 	    {
   2244 	      info->callbacks->warning
   2245 		(info, "no hash table available",
   2246 		 NULL, input_bfd, input_section, (bfd_vma) 0);
   2247 
   2248 	      return false;
   2249 	    }
   2250 
   2251 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   2252 				   r_symndx, symtab_hdr, sym_hashes,
   2253 				   h, sec, relocation,
   2254 				   unresolved_reloc, warned, ignored);
   2255 	}
   2256 
   2257       if (sec != NULL && discarded_section (sec))
   2258 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   2259 					 rel, 1, relend, howto, 0, contents);
   2260 
   2261       if (bfd_link_relocatable (info))
   2262 	continue;
   2263 
   2264       /* FIXME: We should use the addend, but the COFF relocations don't.  */
   2265       r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
   2266 					input_section,
   2267 					contents, rel->r_offset,
   2268 					relocation, rel->r_addend,
   2269 					info, sec, h == NULL);
   2270 
   2271       if (r != bfd_reloc_ok)
   2272 	{
   2273 	  const char * name;
   2274 	  const char * msg = NULL;
   2275 
   2276 	  if (h != NULL)
   2277 	    name = h->root.root.string;
   2278 	  else
   2279 	    {
   2280 	      name = (bfd_elf_string_from_elf_section
   2281 		      (input_bfd, symtab_hdr->sh_link, sym->st_name));
   2282 	      if (name == NULL || *name == '\0')
   2283 		name = bfd_section_name (sec);
   2284 	    }
   2285 
   2286 	  switch ((int) r)
   2287 	    {
   2288 	    case bfd_reloc_overflow:
   2289 	      (*info->callbacks->reloc_overflow)
   2290 		(info, (h ? &h->root : NULL), name, howto->name,
   2291 		 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   2292 	      break;
   2293 
   2294 	    case bfd_reloc_undefined:
   2295 	      (*info->callbacks->undefined_symbol)
   2296 		(info, name, input_bfd, input_section, rel->r_offset, true);
   2297 	      break;
   2298 
   2299 	    case bfd_reloc_outofrange:
   2300 	      msg = _("internal error: out of range error");
   2301 	      goto common_error;
   2302 
   2303 	    case bfd_reloc_notsupported:
   2304 	      msg = _("internal error: unsupported relocation error");
   2305 	      goto common_error;
   2306 
   2307 	    case bfd_reloc_dangerous:
   2308 	      msg = _("internal error: dangerous relocation");
   2309 	      goto common_error;
   2310 
   2311 	    case bfd_reloc_gp_not_found:
   2312 	      msg = _("could not locate special linker symbol __gp");
   2313 	      goto common_error;
   2314 
   2315 	    case bfd_reloc_ep_not_found:
   2316 	      msg = _("could not locate special linker symbol __ep");
   2317 	      goto common_error;
   2318 
   2319 	    case bfd_reloc_ctbp_not_found:
   2320 	      msg = _("could not locate special linker symbol __ctbp");
   2321 	      goto common_error;
   2322 
   2323 	    default:
   2324 	      msg = _("internal error: unknown error");
   2325 	      /* fall through */
   2326 
   2327 	    common_error:
   2328 	      (*info->callbacks->warning) (info, msg, name, input_bfd,
   2329 					   input_section, rel->r_offset);
   2330 	      break;
   2331 	    }
   2332 	}
   2333     }
   2334 
   2335   return true;
   2336 }
   2337 
   2338 static asection *
   2339 v850_elf_gc_mark_hook (asection *sec,
   2340 		       struct bfd_link_info *info,
   2341 		       Elf_Internal_Rela *rel,
   2342 		       struct elf_link_hash_entry *h,
   2343 		       Elf_Internal_Sym *sym)
   2344 {
   2345   if (h != NULL)
   2346     switch (ELF32_R_TYPE (rel->r_info))
   2347       {
   2348       case R_V850_GNU_VTINHERIT:
   2349       case R_V850_GNU_VTENTRY:
   2350 	return NULL;
   2351       }
   2352 
   2353   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
   2354 }
   2355 
   2356 static void
   2357 v850_set_note (bfd * abfd, asection * s, enum v850_notes note, unsigned int val)
   2358 {
   2359   bfd_byte * data = s->contents + ((note - 1) * SIZEOF_V850_NOTE);
   2360 
   2361   bfd_put_32 (abfd, 4, data + 0);
   2362   bfd_put_32 (abfd, 4, data + 4);
   2363   bfd_put_32 (abfd, note, data + 8);
   2364   memcpy (data + 12, V850_NOTE_NAME, 4);
   2365   bfd_put_32 (abfd, val, data + 16);
   2366 }
   2367 
   2368 /* Create the note section if not already present.  This is done early so
   2369    that the linker maps the sections to the right place in the output.  */
   2370 
   2371 static asection *
   2372 v850_elf_make_note_section (bfd * abfd)
   2373 {
   2374   asection *s;
   2375   bfd_byte *data;
   2376   flagword flags;
   2377   enum v850_notes id;
   2378 
   2379   /* Make the note section.  */
   2380   flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_MERGE;
   2381 
   2382   s = bfd_make_section_anyway_with_flags (abfd, V850_NOTE_SECNAME, flags);
   2383   if (s == NULL)
   2384     return NULL;
   2385 
   2386   if (!bfd_set_section_alignment (s, 2))
   2387     return NULL;
   2388 
   2389   /* Allocate space for all known notes.  */
   2390   if (!bfd_set_section_size (s, NUM_V850_NOTES * SIZEOF_V850_NOTE))
   2391     return NULL;
   2392 
   2393   data = bfd_zalloc (abfd, NUM_V850_NOTES * SIZEOF_V850_NOTE);
   2394   if (data == NULL)
   2395     return NULL;
   2396 
   2397   s->contents = data;
   2398 
   2399   /* Provide default (= uninitilaised) values for all of the notes.  */
   2400   for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
   2401     v850_set_note (abfd, s, id,  0);
   2402 
   2403   return s;
   2404 }
   2405 
   2406 /* Create the note section if not already present.  This is done early so
   2407    that the linker maps the sections to the right place in the output.  */
   2408 
   2409 bool
   2410 v850_elf_create_sections (struct bfd_link_info * info)
   2411 {
   2412   bfd * ibfd;
   2413 
   2414   /* If we already have a note section, do not make another.  */
   2415   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
   2416     if (bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME) != NULL)
   2417       return true;
   2418 
   2419   return v850_elf_make_note_section (info->input_bfds) != NULL;
   2420 }
   2421 
   2422 bool
   2423 v850_elf_set_note (bfd * abfd, unsigned int note, unsigned int val)
   2424 {
   2425   asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME);
   2426 
   2427   if (val > 2)
   2428     /* At the moment, no known note has a value over 2.  */
   2429     return false;
   2430 
   2431   if (notes == NULL)
   2432     notes = v850_elf_make_note_section (abfd);
   2433   if (notes == NULL)
   2434     return false;
   2435 
   2436   v850_set_note (abfd, notes, note, val);
   2437   return true;
   2438 }
   2439 
   2440 /* Copy a v850 note section from one object module to another.  */
   2441 
   2442 static void
   2443 v850_elf_copy_notes (bfd *ibfd, bfd *obfd)
   2444 {
   2445   asection * onotes;
   2446   asection * inotes;
   2447 
   2448   /* If the output bfd does not have a note section, then
   2449      skip the merge.  The normal input to output section
   2450      copying will take care of everythng for us.  */
   2451   if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL)
   2452     return;
   2453 
   2454   if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) == NULL)
   2455     return;
   2456 
   2457   if (bfd_section_size (inotes) == bfd_section_size (onotes))
   2458     {
   2459       bfd_byte * icont;
   2460       bfd_byte * ocont;
   2461 
   2462       if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL)
   2463 	BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont));
   2464 
   2465       if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL)
   2466 	/* If the output is being stripped then it is possible for
   2467 	   the notes section to disappear.  In this case do nothing.  */
   2468 	return;
   2469 
   2470       /* Copy/overwrite notes from the input to the output.  */
   2471       memcpy (ocont, icont, bfd_section_size (onotes));
   2472     }
   2473 }
   2474 
   2475 /* Copy backend specific data from one object module to another.  */
   2476 
   2477 static bool
   2478 v850_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
   2479 {
   2480   v850_elf_copy_notes (ibfd, obfd);
   2481   return _bfd_elf_copy_private_bfd_data (ibfd, obfd);
   2482 }
   2483 #define bfd_elf32_bfd_copy_private_bfd_data	v850_elf_copy_private_bfd_data
   2484 
   2485 static bool
   2486 v850_elf_merge_notes (bfd * ibfd, bfd *obfd)
   2487 {
   2488   asection * onotes;
   2489   asection * inotes;
   2490   bool result = true;
   2491 
   2492   /* If the output bfd does not have a note section, then
   2493      skip the merge.  The normal input to output section
   2494      copying will take care of everythng for us.  */
   2495   if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL)
   2496     return true;
   2497 
   2498   if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) != NULL)
   2499     {
   2500       enum v850_notes id;
   2501       bfd_byte * icont;
   2502       bfd_byte * ocont;
   2503 
   2504       BFD_ASSERT (bfd_section_size (inotes) == bfd_section_size (onotes));
   2505 
   2506       if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL)
   2507 	BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont));
   2508 
   2509       if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL)
   2510 	BFD_ASSERT (bfd_malloc_and_get_section (obfd, onotes, & ocont));
   2511 
   2512       for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
   2513 	{
   2514 	  unsigned int ival;
   2515 	  unsigned int oval;
   2516 	  bfd_byte * idata = icont + ((id - 1) * SIZEOF_V850_NOTE) + 16;
   2517 	  bfd_byte * odata = ocont + ((id - 1) * SIZEOF_V850_NOTE) + 16;
   2518 
   2519 	  ival = bfd_get_32 (ibfd, idata);
   2520 	  oval = bfd_get_32 (obfd, odata);
   2521 
   2522 	  if (ival == 0 || ival == oval)
   2523 	    continue;
   2524 
   2525 	  if (oval == 0)
   2526 	    {
   2527 	      bfd_put_32 (obfd, ival, odata);
   2528 	      v850_set_note (obfd, onotes, id, ival);
   2529 	      continue;
   2530 	    }
   2531 
   2532 	  /* We have a mismatch.  The ABI defines how to handle
   2533 	     this siutation on a per note type basis.  */
   2534 	  switch (id)
   2535 	    {
   2536 	    case V850_NOTE_ALIGNMENT:
   2537 	      if (oval == EF_RH850_DATA_ALIGN4)
   2538 		{
   2539 		  _bfd_error_handler
   2540 		    /* xgettext:c-format */
   2541 		    (_("error: %pB needs 8-byte alignment but %pB is set for 4-byte alignment"),
   2542 				      ibfd, obfd);
   2543 		  result = false;
   2544 		}
   2545 	      else
   2546 		/* ibfd uses 4-byte alignment, obfd uses 8-byte alignment.
   2547 		   Leave the obfd alignment as it is.  */
   2548 		BFD_ASSERT (oval == EF_RH850_DATA_ALIGN8);
   2549 
   2550 	      break;
   2551 
   2552 	    case V850_NOTE_DATA_SIZE:
   2553 	      if (oval == EF_RH850_DOUBLE32)
   2554 		{
   2555 		  _bfd_error_handler
   2556 		    /* xgettext:c-format */
   2557 		    (_("error: %pB uses 64-bit doubles but "
   2558 		       "%pB uses 32-bit doubles"), ibfd, obfd);
   2559 		  result = false;
   2560 		}
   2561 	      else
   2562 		/* ibfd uses 32-bit doubles, obfd uses 64-bit doubles.
   2563 		   This is acceptable.  Honest, that is what the ABI says.  */
   2564 		BFD_ASSERT (oval == EF_RH850_DOUBLE64);
   2565 	      break;
   2566 
   2567 	    case V850_NOTE_FPU_INFO:
   2568 	      if (oval == EF_RH850_FPU20)
   2569 		{
   2570 		  _bfd_error_handler
   2571 		    /* xgettext:c-format */
   2572 		    (_("error: %pB uses FPU-3.0 but %pB only supports FPU-2.0"),
   2573 		     ibfd, obfd);
   2574 		  result = false;
   2575 		}
   2576 	      else
   2577 		/* ibfd uses FPU-2.0, obfd uses FPU-3.0.  Leave obfd as it is.  */
   2578 		BFD_ASSERT (oval == EF_RH850_FPU30);
   2579 
   2580 	      break;
   2581 
   2582 	    default:
   2583 	      /* None of the other conflicts matter.
   2584 		 Stick with the current output values.  */
   2585 	      break;
   2586 	    }
   2587 	}
   2588 
   2589       /* FIXME:  We should also check for conflicts between the notes
   2590 	 and the EF flags in the ELF header.  */
   2591     }
   2592 
   2593   return result;
   2594 }
   2595 
   2596 static void
   2597 print_v850_note (bfd * abfd, FILE * file, bfd_byte * data, enum v850_notes id)
   2598 {
   2599   unsigned int value = bfd_get_32 (abfd, data + ((id - 1) * SIZEOF_V850_NOTE) + 16);
   2600 
   2601   switch (id)
   2602     {
   2603     case V850_NOTE_ALIGNMENT:
   2604       fprintf (file, _(" alignment of 8-byte entities: "));
   2605       switch (value)
   2606 	{
   2607 	case EF_RH850_DATA_ALIGN4: fprintf (file, _("4-byte")); break;
   2608 	case EF_RH850_DATA_ALIGN8: fprintf (file, _("8-byte")); break;
   2609 	case 0:  fprintf (file, _("not set")); break;
   2610 	default: fprintf (file, _("unknown: %x"), value); break;
   2611 	}
   2612       fputc ('\n', file);
   2613       break;
   2614 
   2615     case V850_NOTE_DATA_SIZE:
   2616       fprintf (file, _(" size of doubles: "));
   2617       switch (value)
   2618 	{
   2619 	case EF_RH850_DOUBLE32: fprintf (file, _("4-bytes")); break;
   2620 	case EF_RH850_DOUBLE64: fprintf (file, _("8-bytes")); break;
   2621 	case 0:  fprintf (file, _("not set")); break;
   2622 	default: fprintf (file, _("unknown: %x"), value); break;
   2623 	}
   2624       fputc ('\n', file);
   2625       break;
   2626 
   2627     case V850_NOTE_FPU_INFO:
   2628       fprintf (file, _(" FPU support required: "));
   2629       switch (value)
   2630 	{
   2631 	case EF_RH850_FPU20: fprintf (file, _("FPU-2.0")); break;
   2632 	case EF_RH850_FPU30: fprintf (file, _("FPU-3.0")); break;
   2633 	case 0:  fprintf (file, _("none")); break;
   2634 	default: fprintf (file, _("unknown: %x"), value); break;
   2635 	}
   2636       fputc ('\n', file);
   2637       break;
   2638 
   2639     case V850_NOTE_SIMD_INFO:
   2640       fprintf (file, _("SIMD use: "));
   2641       switch (value)
   2642 	{
   2643 	case EF_RH850_SIMD: fprintf (file, _("yes")); break;
   2644 	case 0:  fprintf (file, _("no")); break;
   2645 	default: fprintf (file, _("unknown: %x"), value); break;
   2646 	}
   2647       fputc ('\n', file);
   2648       break;
   2649 
   2650     case V850_NOTE_CACHE_INFO:
   2651       fprintf (file, _("CACHE use: "));
   2652       switch (value)
   2653 	{
   2654 	case EF_RH850_CACHE: fprintf (file, _("yes")); break;
   2655 	case 0:  fprintf (file, _("no")); break;
   2656 	default: fprintf (file, _("unknown: %x"), value); break;
   2657 	}
   2658       fputc ('\n', file);
   2659       break;
   2660 
   2661     case V850_NOTE_MMU_INFO:
   2662       fprintf (file, _("MMU use: "));
   2663       switch (value)
   2664 	{
   2665 	case EF_RH850_MMU: fprintf (file, _("yes")); break;
   2666 	case 0:  fprintf (file, _("no")); break;
   2667 	default: fprintf (file, _("unknown: %x"), value); break;
   2668 	}
   2669       fputc ('\n', file);
   2670       break;
   2671 
   2672     default:
   2673       BFD_ASSERT (0);
   2674     }
   2675 }
   2676 
   2677 static void
   2678 v850_elf_print_notes (bfd * abfd, FILE * file)
   2679 {
   2680   asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME);
   2681   enum v850_notes id;
   2682 
   2683   if (notes == NULL || notes->contents == NULL)
   2684     return;
   2685 
   2686   BFD_ASSERT (bfd_section_size (notes) == NUM_V850_NOTES * SIZEOF_V850_NOTE);
   2687 
   2688   for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
   2689     print_v850_note (abfd, file, notes->contents, id);
   2690 }
   2691 
   2692 /* Set the right machine number and architecture.  */
   2693 
   2694 static bool
   2695 v850_elf_object_p (bfd *abfd)
   2696 {
   2697   enum bfd_architecture arch;
   2698   unsigned long mach;
   2699 
   2700   switch (elf_elfheader (abfd)->e_machine)
   2701     {
   2702     case EM_V800:
   2703       arch = bfd_arch_v850_rh850;
   2704       mach = (elf_elfheader (abfd)->e_flags & EF_V800_850E3)
   2705 	? bfd_mach_v850e3v5 : bfd_mach_v850e2v3;
   2706       break;
   2707 
   2708     case EM_CYGNUS_V850:
   2709     case EM_V850:
   2710       arch = bfd_arch_v850;
   2711       switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
   2712 	{
   2713 	default:
   2714 	case E_V850_ARCH:     mach = bfd_mach_v850; break;
   2715 	case E_V850E_ARCH:    mach = bfd_mach_v850e; break;
   2716 	case E_V850E1_ARCH:   mach = bfd_mach_v850e1; break;
   2717 	case E_V850E2_ARCH:   mach = bfd_mach_v850e2; break;
   2718 	case E_V850E2V3_ARCH: mach = bfd_mach_v850e2v3; break;
   2719 	case E_V850E3V5_ARCH: mach = bfd_mach_v850e3v5; break;
   2720 	}
   2721       break;
   2722 
   2723     default:
   2724       return false;
   2725     }
   2726 
   2727   return bfd_default_set_arch_mach (abfd, arch, mach);
   2728 }
   2729 
   2730 /* Store the machine number in the flags field.  */
   2731 
   2732 static bool
   2733 v850_elf_final_write_processing (bfd *abfd)
   2734 {
   2735   unsigned long val;
   2736 
   2737   switch (bfd_get_arch (abfd))
   2738     {
   2739     case bfd_arch_v850_rh850:
   2740       val = EF_RH850_ABI;
   2741       if (bfd_get_mach (abfd) == bfd_mach_v850e3v5)
   2742 	val |= EF_V800_850E3;
   2743       elf_elfheader (abfd)->e_flags |= val;
   2744       break;
   2745 
   2746     case bfd_arch_v850:
   2747       switch (bfd_get_mach (abfd))
   2748 	{
   2749 	default:
   2750 	case bfd_mach_v850:     val = E_V850_ARCH; break;
   2751 	case bfd_mach_v850e:    val = E_V850E_ARCH; break;
   2752 	case bfd_mach_v850e1:   val = E_V850E1_ARCH; break;
   2753 	case bfd_mach_v850e2:   val = E_V850E2_ARCH; break;
   2754 	case bfd_mach_v850e2v3: val = E_V850E2V3_ARCH; break;
   2755 	case bfd_mach_v850e3v5: val = E_V850E3V5_ARCH; break;
   2756 	}
   2757       elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH;
   2758       elf_elfheader (abfd)->e_flags |= val;
   2759       break;
   2760     default:
   2761       break;
   2762     }
   2763   return _bfd_elf_final_write_processing (abfd);
   2764 }
   2765 
   2766 /* Function to keep V850 specific file flags.  */
   2767 
   2768 static bool
   2769 v850_elf_set_private_flags (bfd *abfd, flagword flags)
   2770 {
   2771   BFD_ASSERT (!elf_flags_init (abfd)
   2772 	      || elf_elfheader (abfd)->e_flags == flags);
   2773 
   2774   elf_elfheader (abfd)->e_flags = flags;
   2775   elf_flags_init (abfd) = true;
   2776   return true;
   2777 }
   2778 
   2779 /* Merge backend specific data from an object file
   2780    to the output object file when linking.  */
   2781 
   2782 static bool
   2783 v850_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   2784 {
   2785   bfd *obfd = info->output_bfd;
   2786   flagword out_flags;
   2787   flagword in_flags;
   2788   bool result = true;
   2789 
   2790   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
   2791       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
   2792     return true;
   2793 
   2794   result &= v850_elf_merge_notes (ibfd, obfd);
   2795 
   2796   in_flags = elf_elfheader (ibfd)->e_flags;
   2797   out_flags = elf_elfheader (obfd)->e_flags;
   2798 
   2799   if (! elf_flags_init (obfd))
   2800     {
   2801       /* If the input is the default architecture then do not
   2802 	 bother setting the flags for the output architecture,
   2803 	 instead allow future merges to do this.  If no future
   2804 	 merges ever set these flags then they will retain their
   2805 	 unitialised values, which surprise surprise, correspond
   2806 	 to the default values.  */
   2807       if (bfd_get_arch_info (ibfd)->the_default)
   2808 	return true;
   2809 
   2810       elf_flags_init (obfd) = true;
   2811       elf_elfheader (obfd)->e_flags = in_flags;
   2812 
   2813       if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
   2814 	  && bfd_get_arch_info (obfd)->the_default)
   2815 	result &= bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
   2816 
   2817       return result;
   2818     }
   2819 
   2820   /* Check flag compatibility.  */
   2821   if (in_flags == out_flags)
   2822     return result;
   2823 
   2824   if (bfd_get_arch (obfd) == bfd_arch_v850_rh850)
   2825     {
   2826       if ((in_flags & EF_V800_850E3) != (out_flags & EF_V800_850E3))
   2827 	{
   2828 	  _bfd_error_handler
   2829 	    (_("%pB: architecture mismatch with previous modules"), ibfd);
   2830 	  elf_elfheader (obfd)->e_flags |= EF_V800_850E3;
   2831 	}
   2832 
   2833       return result;
   2834     }
   2835 
   2836   if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
   2837       && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
   2838     {
   2839       /* Allow earlier architecture binaries to be linked with later binaries.
   2840 	 Set the output binary to the later architecture, except for v850e1,
   2841 	 which we set to v850e.  */
   2842       if (   (in_flags  & EF_V850_ARCH) == E_V850E1_ARCH
   2843 	  && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
   2844 	return result;
   2845 
   2846       if (   (in_flags  & EF_V850_ARCH) == E_V850_ARCH
   2847 	  && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
   2848 	{
   2849 	  elf_elfheader (obfd)->e_flags =
   2850 	    ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH);
   2851 	  return result;
   2852 	}
   2853 
   2854       if ((   (in_flags & EF_V850_ARCH) == E_V850_ARCH
   2855 	   || (in_flags & EF_V850_ARCH) == E_V850E_ARCH)
   2856 	  && (out_flags & EF_V850_ARCH) == E_V850E2_ARCH)
   2857 	{
   2858 	  elf_elfheader (obfd)->e_flags =
   2859 	    ((out_flags & ~ EF_V850_ARCH) | E_V850E2_ARCH);
   2860 	  return result;
   2861 	}
   2862 
   2863       if ((   (in_flags & EF_V850_ARCH) == E_V850_ARCH
   2864 	   || (in_flags & EF_V850_ARCH) == E_V850E_ARCH
   2865 	   || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH)
   2866 	  && (out_flags & EF_V850_ARCH) == E_V850E2V3_ARCH)
   2867 	{
   2868 	  elf_elfheader (obfd)->e_flags =
   2869 	    ((out_flags & ~ EF_V850_ARCH) | E_V850E2V3_ARCH);
   2870 	  return result;
   2871 	}
   2872 
   2873       if ((   (in_flags & EF_V850_ARCH) == E_V850_ARCH
   2874 	   || (in_flags & EF_V850_ARCH) == E_V850E_ARCH
   2875 	   || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH
   2876 	   || (in_flags & EF_V850_ARCH) == E_V850E2V3_ARCH)
   2877 	  && (out_flags & EF_V850_ARCH) == E_V850E3V5_ARCH)
   2878 	{
   2879 	  elf_elfheader (obfd)->e_flags =
   2880 	    ((out_flags & ~ EF_V850_ARCH) | E_V850E3V5_ARCH);
   2881 	  return result;
   2882 	}
   2883 
   2884       _bfd_error_handler
   2885 	(_("%pB: architecture mismatch with previous modules"), ibfd);
   2886     }
   2887 
   2888   return result;
   2889 }
   2890 
   2891 /* Display the flags field.  */
   2892 
   2893 static bool
   2894 v850_elf_print_private_bfd_data (bfd *abfd, void * ptr)
   2895 {
   2896   FILE * file = (FILE *) ptr;
   2897 
   2898   BFD_ASSERT (abfd != NULL && ptr != NULL);
   2899 
   2900   _bfd_elf_print_private_bfd_data (abfd, ptr);
   2901 
   2902   /* xgettext:c-format.  */
   2903   fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags);
   2904 
   2905   if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
   2906     {
   2907       if ((elf_elfheader (abfd)->e_flags & EF_RH850_ABI) != EF_RH850_ABI)
   2908 	fprintf (file, _("unknown v850 architecture"));
   2909       else if (elf_elfheader (abfd)->e_flags & EF_V800_850E3)
   2910 	fprintf (file, _("v850 E3 architecture"));
   2911       else
   2912 	fprintf (file, _("v850 architecture"));
   2913     }
   2914   else
   2915     {
   2916       switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
   2917 	{
   2918 	default:
   2919 	case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
   2920 	case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break;
   2921 	case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break;
   2922 	case E_V850E2_ARCH: fprintf (file, _("v850e2 architecture")); break;
   2923 	case E_V850E2V3_ARCH: fprintf (file, _("v850e2v3 architecture")); break;
   2924 	case E_V850E3V5_ARCH: fprintf (file, _("v850e3v5 architecture")); break;
   2925 	}
   2926     }
   2927 
   2928   fputc ('\n', file);
   2929 
   2930   v850_elf_print_notes (abfd, file);
   2931 
   2932   return true;
   2933 }
   2934 
   2935 /* V850 ELF uses four common sections.  One is the usual one, and the
   2936    others are for (small) objects in one of the special data areas:
   2937    small, tiny and zero.  All the objects are kept together, and then
   2938    referenced via the gp register, the ep register or the r0 register
   2939    respectively, which yields smaller, faster assembler code.  This
   2940    approach is copied from elf32-mips.c.  */
   2941 
   2942 static asection v850_elf_scom_section;
   2943 static const asymbol v850_elf_scom_symbol =
   2944   GLOBAL_SYM_INIT (".scommon", &v850_elf_scom_section);
   2945 static asection v850_elf_scom_section =
   2946   BFD_FAKE_SECTION (v850_elf_scom_section, &v850_elf_scom_symbol,
   2947 		    ".scommon", 0,
   2948 		    SEC_IS_COMMON | SEC_SMALL_DATA | SEC_ALLOC | SEC_DATA);
   2949 
   2950 static asection v850_elf_tcom_section;
   2951 static const asymbol v850_elf_tcom_symbol =
   2952   GLOBAL_SYM_INIT (".tcommon", &v850_elf_tcom_section);
   2953 static asection v850_elf_tcom_section =
   2954   BFD_FAKE_SECTION (v850_elf_tcom_section, &v850_elf_tcom_symbol,
   2955 		    ".tcommon", 0,
   2956 		    SEC_IS_COMMON | SEC_SMALL_DATA);
   2957 
   2958 static asection v850_elf_zcom_section;
   2959 static const asymbol v850_elf_zcom_symbol =
   2960   GLOBAL_SYM_INIT (".zcommon", &v850_elf_zcom_section);
   2961 static asection v850_elf_zcom_section =
   2962   BFD_FAKE_SECTION (v850_elf_zcom_section, &v850_elf_zcom_symbol,
   2963 		    ".zcommon", 0,
   2964 		    SEC_IS_COMMON | SEC_SMALL_DATA);
   2965 
   2966 /* Given a BFD section, try to locate the
   2967    corresponding ELF section index.  */
   2968 
   2969 static bool
   2970 v850_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
   2971 				   asection *sec,
   2972 				   int *retval)
   2973 {
   2974   if (strcmp (bfd_section_name (sec), ".scommon") == 0)
   2975     *retval = SHN_V850_SCOMMON;
   2976   else if (strcmp (bfd_section_name (sec), ".tcommon") == 0)
   2977     *retval = SHN_V850_TCOMMON;
   2978   else if (strcmp (bfd_section_name (sec), ".zcommon") == 0)
   2979     *retval = SHN_V850_ZCOMMON;
   2980   else
   2981     return false;
   2982 
   2983   return true;
   2984 }
   2985 
   2986 /* Handle the special V850 section numbers that a symbol may use.  */
   2987 
   2988 static void
   2989 v850_elf_symbol_processing (bfd *abfd, asymbol *asym)
   2990 {
   2991   elf_symbol_type * elfsym = (elf_symbol_type *) asym;
   2992   unsigned int indx;
   2993 
   2994   indx = elfsym->internal_elf_sym.st_shndx;
   2995 
   2996   /* If the section index is an "ordinary" index, then it may
   2997      refer to a v850 specific section created by the assembler.
   2998      Check the section's type and change the index it matches.
   2999 
   3000      FIXME: Should we alter the st_shndx field as well ?  */
   3001 
   3002   if (indx < elf_numsections (abfd))
   3003     switch (elf_elfsections (abfd)[indx]->sh_type)
   3004       {
   3005       case SHT_V850_SCOMMON:
   3006 	indx = SHN_V850_SCOMMON;
   3007 	break;
   3008 
   3009       case SHT_V850_TCOMMON:
   3010 	indx = SHN_V850_TCOMMON;
   3011 	break;
   3012 
   3013       case SHT_V850_ZCOMMON:
   3014 	indx = SHN_V850_ZCOMMON;
   3015 	break;
   3016 
   3017       default:
   3018 	break;
   3019       }
   3020 
   3021   switch (indx)
   3022     {
   3023     case SHN_V850_SCOMMON:
   3024       asym->section = & v850_elf_scom_section;
   3025       asym->value = elfsym->internal_elf_sym.st_size;
   3026       break;
   3027 
   3028     case SHN_V850_TCOMMON:
   3029       asym->section = & v850_elf_tcom_section;
   3030       asym->value = elfsym->internal_elf_sym.st_size;
   3031       break;
   3032 
   3033     case SHN_V850_ZCOMMON:
   3034       asym->section = & v850_elf_zcom_section;
   3035       asym->value = elfsym->internal_elf_sym.st_size;
   3036       break;
   3037     }
   3038 }
   3039 
   3040 /* Hook called by the linker routine which adds symbols from an object
   3041    file.  We must handle the special v850 section numbers here.  */
   3042 
   3043 static bool
   3044 v850_elf_add_symbol_hook (bfd *abfd,
   3045 			  struct bfd_link_info *info ATTRIBUTE_UNUSED,
   3046 			  Elf_Internal_Sym *sym,
   3047 			  const char **namep ATTRIBUTE_UNUSED,
   3048 			  flagword *flagsp ATTRIBUTE_UNUSED,
   3049 			  asection **secp,
   3050 			  bfd_vma *valp)
   3051 {
   3052   unsigned int indx = sym->st_shndx;
   3053 
   3054   /* If the section index is an "ordinary" index, then it may
   3055      refer to a v850 specific section created by the assembler.
   3056      Check the section's type and change the index it matches.
   3057 
   3058      FIXME: Should we alter the st_shndx field as well ?  */
   3059 
   3060   if (indx < elf_numsections (abfd))
   3061     switch (elf_elfsections (abfd)[indx]->sh_type)
   3062       {
   3063       case SHT_V850_SCOMMON:
   3064 	indx = SHN_V850_SCOMMON;
   3065 	break;
   3066 
   3067       case SHT_V850_TCOMMON:
   3068 	indx = SHN_V850_TCOMMON;
   3069 	break;
   3070 
   3071       case SHT_V850_ZCOMMON:
   3072 	indx = SHN_V850_ZCOMMON;
   3073 	break;
   3074 
   3075       default:
   3076 	break;
   3077       }
   3078 
   3079   switch (indx)
   3080     {
   3081     case SHN_V850_SCOMMON:
   3082       *secp = bfd_make_section_old_way (abfd, ".scommon");
   3083       (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
   3084       *valp = sym->st_size;
   3085       break;
   3086 
   3087     case SHN_V850_TCOMMON:
   3088       *secp = bfd_make_section_old_way (abfd, ".tcommon");
   3089       (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
   3090       *valp = sym->st_size;
   3091       break;
   3092 
   3093     case SHN_V850_ZCOMMON:
   3094       *secp = bfd_make_section_old_way (abfd, ".zcommon");
   3095       (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
   3096       *valp = sym->st_size;
   3097       break;
   3098     }
   3099 
   3100   return true;
   3101 }
   3102 
   3103 static int
   3104 v850_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   3105 				  const char *name ATTRIBUTE_UNUSED,
   3106 				  Elf_Internal_Sym *sym,
   3107 				  asection *input_sec,
   3108 				  struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
   3109 {
   3110   /* If we see a common symbol, which implies a relocatable link, then
   3111      if a symbol was in a special common section in an input file, mark
   3112      it as a special common in the output file.  */
   3113 
   3114   if (sym->st_shndx == SHN_COMMON)
   3115     {
   3116       if (strcmp (input_sec->name, ".scommon") == 0)
   3117 	sym->st_shndx = SHN_V850_SCOMMON;
   3118       else if (strcmp (input_sec->name, ".tcommon") == 0)
   3119 	sym->st_shndx = SHN_V850_TCOMMON;
   3120       else if (strcmp (input_sec->name, ".zcommon") == 0)
   3121 	sym->st_shndx = SHN_V850_ZCOMMON;
   3122     }
   3123 
   3124   /* The price we pay for using h->other unused bits as flags in the
   3125      linker is cleaning up after ourselves.  */
   3126 
   3127   sym->st_other &= ~(V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA
   3128 		     | V850_OTHER_ERROR);
   3129 
   3130   return 1;
   3131 }
   3132 
   3133 static bool
   3134 v850_elf_section_from_shdr (bfd *abfd,
   3135 			    Elf_Internal_Shdr *hdr,
   3136 			    const char *name,
   3137 			    int shindex)
   3138 {
   3139   flagword flags;
   3140 
   3141   /* There ought to be a place to keep ELF backend specific flags, but
   3142      at the moment there isn't one.  We just keep track of the
   3143      sections by their name, instead.  */
   3144 
   3145   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
   3146     return false;
   3147 
   3148   flags = 0;
   3149   switch (hdr->sh_type)
   3150     {
   3151     case SHT_V850_SCOMMON:
   3152     case SHT_V850_TCOMMON:
   3153     case SHT_V850_ZCOMMON:
   3154       flags = SEC_IS_COMMON;
   3155     }
   3156 
   3157   if ((hdr->sh_flags & SHF_V850_GPREL) != 0)
   3158     flags |= SEC_SMALL_DATA;
   3159 
   3160   return (flags == 0
   3161 	  || bfd_set_section_flags (hdr->bfd_section,
   3162 				    hdr->bfd_section->flags | flags));
   3163 }
   3164 
   3165 /* Set the correct type for a V850 ELF section.  We do this
   3166    by the section name, which is a hack, but ought to work.  */
   3167 
   3168 static bool
   3169 v850_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
   3170 			Elf_Internal_Shdr *hdr,
   3171 			asection *sec)
   3172 {
   3173   const char * name;
   3174 
   3175   name = bfd_section_name (sec);
   3176 
   3177   if (strcmp (name, ".scommon") == 0)
   3178     hdr->sh_type = SHT_V850_SCOMMON;
   3179   else if (strcmp (name, ".tcommon") == 0)
   3180     hdr->sh_type = SHT_V850_TCOMMON;
   3181   else if (strcmp (name, ".zcommon") == 0)
   3182     hdr->sh_type = SHT_V850_ZCOMMON;
   3183   /* Tweak the section type of .note.renesas.  */
   3184   else if (strcmp (name, V850_NOTE_SECNAME) == 0)
   3185     {
   3186       hdr->sh_type = SHT_RENESAS_INFO;
   3187       hdr->sh_entsize = SIZEOF_V850_NOTE;
   3188     }
   3189 
   3190   return true;
   3191 }
   3192 
   3193 /* Delete some bytes from a section while relaxing.  */
   3194 
   3195 static bool
   3196 v850_elf_relax_delete_bytes (bfd *abfd,
   3197 			     asection *sec,
   3198 			     bfd_vma addr,
   3199 			     bfd_vma toaddr,
   3200 			     int count)
   3201 {
   3202   Elf_Internal_Shdr *symtab_hdr;
   3203   Elf32_External_Sym *extsyms;
   3204   Elf32_External_Sym *esym;
   3205   Elf32_External_Sym *esymend;
   3206   int sym_index;
   3207   unsigned int sec_shndx;
   3208   bfd_byte *contents;
   3209   Elf_Internal_Rela *irel;
   3210   Elf_Internal_Rela *irelend;
   3211   struct elf_link_hash_entry *sym_hash;
   3212   Elf_External_Sym_Shndx *shndx;
   3213 
   3214   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   3215   extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
   3216 
   3217   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
   3218 
   3219   contents = elf_section_data (sec)->this_hdr.contents;
   3220 
   3221   /* The deletion must stop at the next ALIGN reloc for an alignment
   3222      power larger than the number of bytes we are deleting.  */
   3223 
   3224   /* Actually delete the bytes.  */
   3225 #if (DEBUG_RELAX & 2)
   3226   fprintf (stderr, "relax_delete: contents: sec: %s  %p .. %p %x\n",
   3227 	   sec->name, addr, toaddr, count );
   3228 #endif
   3229   memmove (contents + addr, contents + addr + count,
   3230 	   toaddr - addr - count);
   3231   memset (contents + toaddr-count, 0, count);
   3232 
   3233   /* Adjust all the relocs.  */
   3234   irel = elf_section_data (sec)->relocs;
   3235   irelend = irel + sec->reloc_count;
   3236   if (elf_symtab_shndx_list (abfd))
   3237     {
   3238       Elf_Internal_Shdr *shndx_hdr;
   3239 
   3240       shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
   3241       shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
   3242     }
   3243   else
   3244     {
   3245       shndx = NULL;
   3246     }
   3247 
   3248   for (; irel < irelend; irel++)
   3249     {
   3250       bfd_vma raddr, paddr, symval;
   3251       Elf_Internal_Sym isym;
   3252 
   3253       /* Get the new reloc address.  */
   3254       raddr = irel->r_offset;
   3255       if ((raddr >= (addr + count) && raddr < toaddr))
   3256 	irel->r_offset -= count;
   3257 
   3258       if (raddr >= addr && raddr < addr + count)
   3259 	{
   3260 	  irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
   3261 				       (int) R_V850_NONE);
   3262 	  continue;
   3263 	}
   3264 
   3265       if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
   3266 	continue;
   3267 
   3268       bfd_elf32_swap_symbol_in (abfd,
   3269 				extsyms + ELF32_R_SYM (irel->r_info),
   3270 				shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
   3271 				& isym);
   3272 
   3273       if (isym.st_shndx != sec_shndx)
   3274 	continue;
   3275 
   3276       /* Get the value of the symbol referred to by the reloc.  */
   3277       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
   3278 	{
   3279 	  symval = isym.st_value;
   3280 #if (DEBUG_RELAX & 2)
   3281 	  {
   3282 	    char * name = bfd_elf_string_from_elf_section
   3283 			   (abfd, symtab_hdr->sh_link, isym.st_name);
   3284 	    fprintf (stderr,
   3285 	       "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
   3286 	       sec->name, name, isym.st_name,
   3287 	       sec->output_section->vma, sec->output_offset,
   3288 	       isym.st_value, irel->r_addend);
   3289 	  }
   3290 #endif
   3291 	}
   3292       else
   3293 	{
   3294 	  unsigned long indx;
   3295 	  struct elf_link_hash_entry * h;
   3296 
   3297 	  /* An external symbol.  */
   3298 	  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   3299 
   3300 	  h = elf_sym_hashes (abfd) [indx];
   3301 	  BFD_ASSERT (h != NULL);
   3302 
   3303 	  symval = h->root.u.def.value;
   3304 #if (DEBUG_RELAX & 2)
   3305 	  fprintf (stderr,
   3306 		   "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
   3307 		   sec->name, h->root.root.string, h->root.u.def.value,
   3308 		   sec->output_section->vma, sec->output_offset, irel->r_addend);
   3309 #endif
   3310 	}
   3311 
   3312       paddr = symval + irel->r_addend;
   3313 
   3314       if ( (symval >= addr + count && symval < toaddr)
   3315 	  && (paddr < addr + count || paddr >= toaddr))
   3316 	irel->r_addend += count;
   3317       else if (    (symval < addr + count || symval >= toaddr)
   3318 		&& (paddr >= addr + count && paddr < toaddr))
   3319 	irel->r_addend -= count;
   3320     }
   3321 
   3322   /* Adjust the local symbols defined in this section.  */
   3323   esym = extsyms;
   3324   esymend = esym + symtab_hdr->sh_info;
   3325 
   3326   for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
   3327     {
   3328       Elf_Internal_Sym isym;
   3329 
   3330       bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
   3331 
   3332       if (isym.st_shndx == sec_shndx
   3333 	  && isym.st_value >= addr + count
   3334 	  && isym.st_value < toaddr)
   3335 	{
   3336 	  isym.st_value -= count;
   3337 
   3338 	  if (isym.st_value + isym.st_size >= toaddr)
   3339 	    isym.st_size += count;
   3340 
   3341 	  bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
   3342 	}
   3343       else if (isym.st_shndx == sec_shndx
   3344 	       && isym.st_value < addr + count)
   3345 	{
   3346 	  if (isym.st_value+isym.st_size >= addr + count
   3347 	      && isym.st_value+isym.st_size < toaddr)
   3348 	    isym.st_size -= count;
   3349 
   3350 	  if (isym.st_value >= addr
   3351 	      && isym.st_value <  addr + count)
   3352 	    isym.st_value = addr;
   3353 
   3354 	  bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
   3355 	}
   3356     }
   3357 
   3358   /* Now adjust the global symbols defined in this section.  */
   3359   esym = extsyms + symtab_hdr->sh_info;
   3360   esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
   3361 
   3362   for (sym_index = 0; esym < esymend; esym ++, sym_index ++)
   3363     {
   3364       Elf_Internal_Sym isym;
   3365 
   3366       bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
   3367       sym_hash = elf_sym_hashes (abfd) [sym_index];
   3368 
   3369       if (isym.st_shndx == sec_shndx
   3370 	  && ((sym_hash)->root.type == bfd_link_hash_defined
   3371 	      || (sym_hash)->root.type == bfd_link_hash_defweak)
   3372 	  && (sym_hash)->root.u.def.section == sec
   3373 	  && (sym_hash)->root.u.def.value >= addr + count
   3374 	  && (sym_hash)->root.u.def.value < toaddr)
   3375 	{
   3376 	  if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
   3377 	    {
   3378 	      isym.st_size += count;
   3379 	      bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
   3380 	    }
   3381 
   3382 	  (sym_hash)->root.u.def.value -= count;
   3383 	}
   3384       else if (isym.st_shndx == sec_shndx
   3385 	       && ((sym_hash)->root.type == bfd_link_hash_defined
   3386 		   || (sym_hash)->root.type == bfd_link_hash_defweak)
   3387 	       && (sym_hash)->root.u.def.section == sec
   3388 	       && (sym_hash)->root.u.def.value < addr + count)
   3389 	{
   3390 	  if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
   3391 	      && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
   3392 	    isym.st_size -= count;
   3393 
   3394 	  if ((sym_hash)->root.u.def.value >= addr
   3395 	      && (sym_hash)->root.u.def.value < addr + count)
   3396 	    (sym_hash)->root.u.def.value = addr;
   3397 
   3398 	  bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
   3399 	}
   3400 
   3401       if (shndx)
   3402 	++ shndx;
   3403     }
   3404 
   3405   return true;
   3406 }
   3407 
   3408 #define NOP_OPCODE	(0x0000)
   3409 #define MOVHI		0x0640				/* 4byte.  */
   3410 #define MOVHI_MASK	0x07e0
   3411 #define MOVHI_R1(insn)	((insn) & 0x1f)			/* 4byte.  */
   3412 #define MOVHI_R2(insn)	((insn) >> 11)
   3413 #define MOVEA		0x0620				/* 2byte.  */
   3414 #define MOVEA_MASK	0x07e0
   3415 #define MOVEA_R1(insn)	((insn) & 0x1f)
   3416 #define MOVEA_R2(insn)	((insn) >> 11)
   3417 #define JARL_4		0x00040780				/* 4byte.  */
   3418 #define JARL_4_MASK	0xFFFF07FF
   3419 #define JARL_R2(insn)	(int)(((insn) & (~JARL_4_MASK)) >> 11)
   3420 #define ADD_I		0x0240					/* 2byte.  */
   3421 #define ADD_I_MASK	0x07e0
   3422 #define ADD_I5(insn)	((((insn) & 0x001f) << 11) >> 11)	/* 2byte.  */
   3423 #define ADD_R2(insn)	((insn) >> 11)
   3424 #define JMP_R		0x0060					/* 2byte.  */
   3425 #define JMP_R_MASK	0xFFE0
   3426 #define JMP_R1(insn)	((insn) & 0x1f)
   3427 
   3428 static bool
   3429 v850_elf_relax_section (bfd *abfd,
   3430 			asection *sec,
   3431 			struct bfd_link_info *link_info,
   3432 			bool *again)
   3433 {
   3434   Elf_Internal_Shdr *symtab_hdr;
   3435   Elf_Internal_Rela *internal_relocs;
   3436   Elf_Internal_Rela *irel;
   3437   Elf_Internal_Rela *irelend;
   3438   Elf_Internal_Rela *irelalign = NULL;
   3439   Elf_Internal_Sym *isymbuf = NULL;
   3440   bfd_byte *contents = NULL;
   3441   bfd_vma addr = 0;
   3442   bfd_vma toaddr;
   3443   int align_pad_size = 0;
   3444   bool result = true;
   3445 
   3446   *again = false;
   3447 
   3448   if (bfd_link_relocatable (link_info)
   3449       || (sec->flags & SEC_HAS_CONTENTS) == 0
   3450       || (sec->flags & SEC_RELOC) == 0
   3451       || sec->reloc_count == 0)
   3452     return true;
   3453 
   3454   symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
   3455 
   3456   internal_relocs = (_bfd_elf_link_read_relocs
   3457 		     (abfd, sec, NULL, NULL, link_info->keep_memory));
   3458   if (internal_relocs == NULL)
   3459     goto error_return;
   3460 
   3461   irelend = internal_relocs + sec->reloc_count;
   3462 
   3463   while (addr < sec->size)
   3464     {
   3465       toaddr = sec->size;
   3466 
   3467       for (irel = internal_relocs; irel < irelend; irel ++)
   3468 	if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
   3469 	    && irel->r_offset > addr
   3470 	    && irel->r_offset < toaddr)
   3471 	  toaddr = irel->r_offset;
   3472 
   3473 #ifdef DEBUG_RELAX
   3474       fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
   3475 	       addr, toaddr, align_pad_size);
   3476 #endif
   3477       if (irelalign)
   3478 	{
   3479 	  bfd_vma alignto;
   3480 	  bfd_vma alignmoveto;
   3481 
   3482 	  alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
   3483 	  alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
   3484 
   3485 	  if (alignmoveto < alignto)
   3486 	    {
   3487 	      bfd_vma i;
   3488 
   3489 	      align_pad_size = alignto - alignmoveto;
   3490 #ifdef DEBUG_RELAX
   3491 	      fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
   3492 		       alignmoveto, toaddr, align_pad_size);
   3493 #endif
   3494 	      if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
   3495 						toaddr, align_pad_size))
   3496 		goto error_return;
   3497 
   3498 	      for (i  = BFD_ALIGN (toaddr - align_pad_size, 1);
   3499 		   (i + 1) < toaddr; i += 2)
   3500 		bfd_put_16 (abfd, NOP_OPCODE, contents + i);
   3501 
   3502 	      addr = alignmoveto;
   3503 	    }
   3504 	  else
   3505 	    align_pad_size = 0;
   3506 	}
   3507 
   3508       for (irel = internal_relocs; irel < irelend; irel++)
   3509 	{
   3510 	  bfd_vma laddr;
   3511 	  bfd_vma addend;
   3512 	  bfd_vma symval;
   3513 	  int insn[5];
   3514 	  int no_match = -1;
   3515 	  Elf_Internal_Rela *hi_irelfn;
   3516 	  Elf_Internal_Rela *lo_irelfn;
   3517 	  Elf_Internal_Rela *irelcall;
   3518 	  bfd_signed_vma foff;
   3519 	  unsigned int r_type;
   3520 
   3521 	  if (! (irel->r_offset >= addr && irel->r_offset < toaddr
   3522 		 && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
   3523 		     || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
   3524 	    continue;
   3525 
   3526 #ifdef DEBUG_RELAX
   3527 	  fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
   3528 		   irel->r_info,
   3529 		   irel->r_offset,
   3530 		   irel->r_addend );
   3531 #endif
   3532 
   3533 	  /* Get the section contents.  */
   3534 	  if (contents == NULL)
   3535 	    {
   3536 	      if (elf_section_data (sec)->this_hdr.contents != NULL)
   3537 		contents = elf_section_data (sec)->this_hdr.contents;
   3538 	      else
   3539 		{
   3540 		  if (! bfd_malloc_and_get_section (abfd, sec, &contents))
   3541 		    goto error_return;
   3542 		}
   3543 	    }
   3544 
   3545 	  /* Read this BFD's local symbols if we haven't done so already.  */
   3546 	  if (isymbuf == NULL && symtab_hdr->sh_info != 0)
   3547 	    {
   3548 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   3549 	      if (isymbuf == NULL)
   3550 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
   3551 						symtab_hdr->sh_info, 0,
   3552 						NULL, NULL, NULL);
   3553 	      if (isymbuf == NULL)
   3554 		goto error_return;
   3555 	    }
   3556 
   3557 	  laddr = irel->r_offset;
   3558 
   3559 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
   3560 	    {
   3561 	      /* Check code for -mlong-calls output. */
   3562 	      if (laddr + 16 <= (bfd_vma) sec->size)
   3563 		{
   3564 		  insn[0] = bfd_get_16 (abfd, contents + laddr);
   3565 		  insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
   3566 		  insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
   3567 		  insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
   3568 		  insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
   3569 
   3570 		  if ((insn[0] & MOVHI_MASK) != MOVHI
   3571 		       || MOVHI_R1 (insn[0]) != 0)
   3572 		    no_match = 0;
   3573 
   3574 		  if (no_match < 0
   3575 		      && ((insn[1] & MOVEA_MASK) != MOVEA
   3576 			   || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
   3577 		    no_match = 1;
   3578 
   3579 		  if (no_match < 0
   3580 		      && (insn[2] & JARL_4_MASK) != JARL_4)
   3581 		    no_match = 2;
   3582 
   3583 		  if (no_match < 0
   3584 		      && ((insn[3] & ADD_I_MASK) != ADD_I
   3585 			   || ADD_I5 (insn[3]) != 4
   3586 			   || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
   3587 		    no_match = 3;
   3588 
   3589 		  if (no_match < 0
   3590 		      && ((insn[4] & JMP_R_MASK) != JMP_R
   3591 			   || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
   3592 		    no_match = 4;
   3593 		}
   3594 	      else
   3595 		{
   3596 		  _bfd_error_handler
   3597 		    /* xgettext:c-format */
   3598 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3599 		       "unrecognized insns"),
   3600 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
   3601 		  continue;
   3602 		}
   3603 
   3604 	      if (no_match >= 0)
   3605 		{
   3606 		  _bfd_error_handler
   3607 		    /* xgettext:c-format */
   3608 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3609 		       "unrecognized insn %#x"),
   3610 		     abfd,
   3611 		     (uint64_t) (irel->r_offset + no_match),
   3612 		     "R_V850_LONGCALL",
   3613 		     insn[no_match]);
   3614 		  continue;
   3615 		}
   3616 
   3617 	      /* Get the reloc for the address from which the register is
   3618 		 being loaded.  This reloc will tell us which function is
   3619 		 actually being called.  */
   3620 
   3621 	      for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
   3622 		{
   3623 		  r_type = ELF32_R_TYPE (hi_irelfn->r_info);
   3624 
   3625 		  if (hi_irelfn->r_offset == laddr + 2
   3626 		      && (r_type == (int) R_V850_HI16_S || r_type == (int) R_V810_WHI1))
   3627 		    break;
   3628 		}
   3629 
   3630 	      for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
   3631 		{
   3632 		  r_type = ELF32_R_TYPE (lo_irelfn->r_info);
   3633 
   3634 		  if (lo_irelfn->r_offset == laddr + 6
   3635 		      && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO))
   3636 		    break;
   3637 		}
   3638 
   3639 	      for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
   3640 		{
   3641 		  r_type = ELF32_R_TYPE (irelcall->r_info);
   3642 
   3643 		  if (irelcall->r_offset == laddr + 8
   3644 		      && (r_type == (int) R_V850_22_PCREL || r_type == (int) R_V850_PCR22))
   3645 		    break;
   3646 		}
   3647 
   3648 	      if (   hi_irelfn == irelend
   3649 		  || lo_irelfn == irelend
   3650 		  || irelcall  == irelend)
   3651 		{
   3652 		  _bfd_error_handler
   3653 		    /* xgettext:c-format */
   3654 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3655 		       "unrecognized reloc"),
   3656 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
   3657 
   3658 		  continue;
   3659 		}
   3660 
   3661 	      if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
   3662 		{
   3663 		  Elf_Internal_Sym *  isym;
   3664 
   3665 		  /* A local symbol.  */
   3666 		  isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
   3667 
   3668 		  symval = isym->st_value;
   3669 		}
   3670 	      else
   3671 		{
   3672 		  unsigned long indx;
   3673 		  struct elf_link_hash_entry * h;
   3674 
   3675 		  /* An external symbol.  */
   3676 		  indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
   3677 		  h = elf_sym_hashes (abfd)[indx];
   3678 		  BFD_ASSERT (h != NULL);
   3679 
   3680 		  if (   h->root.type != bfd_link_hash_defined
   3681 		      && h->root.type != bfd_link_hash_defweak)
   3682 		    /* This appears to be a reference to an undefined
   3683 		       symbol.  Just ignore it--it will be caught by the
   3684 		       regular reloc processing.  */
   3685 		    continue;
   3686 
   3687 		  symval = h->root.u.def.value;
   3688 		}
   3689 
   3690 	      if (symval + irelcall->r_addend != irelcall->r_offset + 4)
   3691 		{
   3692 		  _bfd_error_handler
   3693 		    /* xgettext:c-format */
   3694 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3695 		       "unrecognized reloc %#" PRIx64),
   3696 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL",
   3697 		     (uint64_t) irelcall->r_offset);
   3698 		  continue;
   3699 		}
   3700 
   3701 	      /* Get the value of the symbol referred to by the reloc.  */
   3702 	      if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
   3703 		{
   3704 		  Elf_Internal_Sym *isym;
   3705 		  asection *sym_sec;
   3706 
   3707 		  /* A local symbol.  */
   3708 		  isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
   3709 
   3710 		  if (isym->st_shndx == SHN_UNDEF)
   3711 		    sym_sec = bfd_und_section_ptr;
   3712 		  else if (isym->st_shndx == SHN_ABS)
   3713 		    sym_sec = bfd_abs_section_ptr;
   3714 		  else if (isym->st_shndx == SHN_COMMON)
   3715 		    sym_sec = bfd_com_section_ptr;
   3716 		  else
   3717 		    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   3718 		  symval = (isym->st_value
   3719 			    + sym_sec->output_section->vma
   3720 			    + sym_sec->output_offset);
   3721 		}
   3722 	      else
   3723 		{
   3724 		  unsigned long indx;
   3725 		  struct elf_link_hash_entry *h;
   3726 
   3727 		  /* An external symbol.  */
   3728 		  indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
   3729 		  h = elf_sym_hashes (abfd)[indx];
   3730 		  BFD_ASSERT (h != NULL);
   3731 
   3732 		  if (   h->root.type != bfd_link_hash_defined
   3733 		      && h->root.type != bfd_link_hash_defweak)
   3734 		    /* This appears to be a reference to an undefined
   3735 		       symbol.  Just ignore it--it will be caught by the
   3736 		       regular reloc processing.  */
   3737 		    continue;
   3738 
   3739 		  symval = (h->root.u.def.value
   3740 			    + h->root.u.def.section->output_section->vma
   3741 			    + h->root.u.def.section->output_offset);
   3742 		}
   3743 
   3744 	      addend = irel->r_addend;
   3745 
   3746 	      foff = (symval + addend
   3747 		      - (irel->r_offset
   3748 			 + sec->output_section->vma
   3749 			 + sec->output_offset
   3750 			 + 4));
   3751 #ifdef DEBUG_RELAX
   3752 	      fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
   3753 		       irel->r_offset,
   3754 		       (irel->r_offset
   3755 			+ sec->output_section->vma
   3756 			+ sec->output_offset),
   3757 		       symval, addend, foff);
   3758 #endif
   3759 
   3760 	      if (foff < -0x100000 || foff >= 0x100000)
   3761 		/* After all that work, we can't shorten this function call.  */
   3762 		continue;
   3763 
   3764 	      /* For simplicity of coding, we are going to modify the section
   3765 		 contents, the section relocs, and the BFD symbol table.  We
   3766 		 must tell the rest of the code not to free up this
   3767 		 information.  It would be possible to instead create a table
   3768 		 of changes which have to be made, as is done in coff-mips.c;
   3769 		 that would be more work, but would require less memory when
   3770 		 the linker is run.  */
   3771 	      elf_section_data (sec)->relocs = internal_relocs;
   3772 	      elf_section_data (sec)->this_hdr.contents = contents;
   3773 	      symtab_hdr->contents = (bfd_byte *) isymbuf;
   3774 
   3775 	      /* Replace the long call with a jarl.  */
   3776 	      if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
   3777 		irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_PCR22);
   3778 	      else
   3779 		irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
   3780 
   3781 	      addend = 0;
   3782 
   3783 	      if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
   3784 		/* If this needs to be changed because of future relaxing,
   3785 		   it will be handled here like other internal IND12W
   3786 		   relocs.  */
   3787 		bfd_put_32 (abfd,
   3788 			    0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
   3789 			    contents + irel->r_offset);
   3790 	      else
   3791 		/* We can't fully resolve this yet, because the external
   3792 		   symbol value may be changed by future relaxing.
   3793 		   We let the final link phase handle it.  */
   3794 		bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
   3795 			    contents + irel->r_offset);
   3796 
   3797 	      hi_irelfn->r_info =
   3798 		ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
   3799 	      lo_irelfn->r_info =
   3800 		ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
   3801 	      irelcall->r_info =
   3802 		ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
   3803 
   3804 	      if (! v850_elf_relax_delete_bytes (abfd, sec,
   3805 						 irel->r_offset + 4, toaddr, 12))
   3806 		goto error_return;
   3807 
   3808 	      align_pad_size += 12;
   3809 	    }
   3810 	  else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
   3811 	    {
   3812 	      /* Check code for -mlong-jumps output.  */
   3813 	      if (laddr + 10 <= (bfd_vma) sec->size)
   3814 		{
   3815 		  insn[0] = bfd_get_16 (abfd, contents + laddr);
   3816 		  insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
   3817 		  insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
   3818 
   3819 		  if ((insn[0] & MOVHI_MASK) != MOVHI
   3820 		       || MOVHI_R1 (insn[0]) != 0)
   3821 		    no_match = 0;
   3822 
   3823 		  if (no_match < 0
   3824 		      && ((insn[1] & MOVEA_MASK) != MOVEA
   3825 			   || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
   3826 		    no_match = 1;
   3827 
   3828 		  if (no_match < 0
   3829 		      && ((insn[2] & JMP_R_MASK) != JMP_R
   3830 			   || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
   3831 		    no_match = 2;
   3832 		}
   3833 	      else
   3834 		{
   3835 		  _bfd_error_handler
   3836 		    /* xgettext:c-format */
   3837 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3838 		       "unrecognized insns"),
   3839 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
   3840 		  continue;
   3841 		}
   3842 
   3843 	      if (no_match >= 0)
   3844 		{
   3845 		  _bfd_error_handler
   3846 		    /* xgettext:c-format */
   3847 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3848 		       "unrecognized insn %#x"),
   3849 		     abfd,
   3850 		     (uint64_t) (irel->r_offset + no_match),
   3851 		     "R_V850_LONGJUMP",
   3852 		     insn[no_match]);
   3853 		  continue;
   3854 		}
   3855 
   3856 	      /* Get the reloc for the address from which the register is
   3857 		 being loaded.  This reloc will tell us which function is
   3858 		 actually being called.  */
   3859 	      for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
   3860 		{
   3861 		  r_type = ELF32_R_TYPE (hi_irelfn->r_info);
   3862 
   3863 		  if (hi_irelfn->r_offset == laddr + 2
   3864 		      && ((r_type == (int) R_V850_HI16_S) || r_type == (int) R_V810_WHI1))
   3865 		    break;
   3866 		}
   3867 
   3868 	      for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
   3869 		{
   3870 		  r_type = ELF32_R_TYPE (lo_irelfn->r_info);
   3871 
   3872 		  if (lo_irelfn->r_offset == laddr + 6
   3873 		      && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO))
   3874 		    break;
   3875 		}
   3876 
   3877 	      if (   hi_irelfn == irelend
   3878 		  || lo_irelfn == irelend)
   3879 		{
   3880 		  _bfd_error_handler
   3881 		    /* xgettext:c-format */
   3882 		    (_("%pB: %#" PRIx64 ": warning: %s points to "
   3883 		       "unrecognized reloc"),
   3884 		     abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
   3885 		  continue;
   3886 		}
   3887 
   3888 	      /* Get the value of the symbol referred to by the reloc.  */
   3889 	      if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
   3890 		{
   3891 		  Elf_Internal_Sym *  isym;
   3892 		  asection *	      sym_sec;
   3893 
   3894 		  /* A local symbol.  */
   3895 		  isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
   3896 
   3897 		  if (isym->st_shndx == SHN_UNDEF)
   3898 		    sym_sec = bfd_und_section_ptr;
   3899 		  else if (isym->st_shndx == SHN_ABS)
   3900 		    sym_sec = bfd_abs_section_ptr;
   3901 		  else if (isym->st_shndx == SHN_COMMON)
   3902 		    sym_sec = bfd_com_section_ptr;
   3903 		  else
   3904 		    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
   3905 		  symval = (isym->st_value
   3906 			    + sym_sec->output_section->vma
   3907 			    + sym_sec->output_offset);
   3908 #ifdef DEBUG_RELAX
   3909 		  {
   3910 		    char * name = bfd_elf_string_from_elf_section
   3911 		      (abfd, symtab_hdr->sh_link, isym->st_name);
   3912 
   3913 		    fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
   3914 			     sym_sec->name, name, isym->st_name,
   3915 			     sym_sec->output_section->vma,
   3916 			     sym_sec->output_offset,
   3917 			     isym->st_value, irel->r_addend);
   3918 		  }
   3919 #endif
   3920 		}
   3921 	      else
   3922 		{
   3923 		  unsigned long indx;
   3924 		  struct elf_link_hash_entry * h;
   3925 
   3926 		  /* An external symbol.  */
   3927 		  indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
   3928 		  h = elf_sym_hashes (abfd)[indx];
   3929 		  BFD_ASSERT (h != NULL);
   3930 
   3931 		  if (   h->root.type != bfd_link_hash_defined
   3932 		      && h->root.type != bfd_link_hash_defweak)
   3933 		    /* This appears to be a reference to an undefined
   3934 		       symbol.  Just ignore it--it will be caught by the
   3935 		       regular reloc processing.  */
   3936 		    continue;
   3937 
   3938 		  symval = (h->root.u.def.value
   3939 			    + h->root.u.def.section->output_section->vma
   3940 			    + h->root.u.def.section->output_offset);
   3941 #ifdef DEBUG_RELAX
   3942 		  fprintf (stderr,
   3943 			   "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
   3944 			   sec->name, h->root.root.string, h->root.u.def.value,
   3945 			   sec->output_section->vma, sec->output_offset, irel->r_addend);
   3946 #endif
   3947 		}
   3948 
   3949 	      addend = irel->r_addend;
   3950 
   3951 	      foff = (symval + addend
   3952 		      - (irel->r_offset
   3953 			 + sec->output_section->vma
   3954 			 + sec->output_offset
   3955 			 + 4));
   3956 #ifdef DEBUG_RELAX
   3957 	      fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
   3958 		       irel->r_offset,
   3959 		       (irel->r_offset
   3960 			+ sec->output_section->vma
   3961 			+ sec->output_offset),
   3962 		       symval, addend, foff);
   3963 #endif
   3964 	      if (foff < -0x100000 || foff >= 0x100000)
   3965 		/* After all that work, we can't shorten this function call.  */
   3966 		continue;
   3967 
   3968 	      /* For simplicity of coding, we are going to modify the section
   3969 		 contents, the section relocs, and the BFD symbol table.  We
   3970 		 must tell the rest of the code not to free up this
   3971 		 information.  It would be possible to instead create a table
   3972 		 of changes which have to be made, as is done in coff-mips.c;
   3973 		 that would be more work, but would require less memory when
   3974 		 the linker is run.  */
   3975 	      elf_section_data (sec)->relocs = internal_relocs;
   3976 	      elf_section_data (sec)->this_hdr.contents = contents;
   3977 	      symtab_hdr->contents = (bfd_byte *) isymbuf;
   3978 
   3979 	      if (foff < -0x100 || foff >= 0x100)
   3980 		{
   3981 		  /* Replace the long jump with a jr.  */
   3982 
   3983 		  if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
   3984 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PCR22);
   3985 		  else
   3986 		    irel->r_info =
   3987 		      ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
   3988 
   3989 		  irel->r_addend = addend;
   3990 		  addend = 0;
   3991 
   3992 		  if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
   3993 		    /* If this needs to be changed because of future relaxing,
   3994 		       it will be handled here like other internal IND12W
   3995 		       relocs.  */
   3996 		    bfd_put_32 (abfd,
   3997 				0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
   3998 				contents + irel->r_offset);
   3999 		  else
   4000 		    /* We can't fully resolve this yet, because the external
   4001 		       symbol value may be changed by future relaxing.
   4002 		       We let the final link phase handle it.  */
   4003 		    bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
   4004 
   4005 		  hi_irelfn->r_info =
   4006 			ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
   4007 		  lo_irelfn->r_info =
   4008 			ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
   4009 		  if (!v850_elf_relax_delete_bytes (abfd, sec,
   4010 						    irel->r_offset + 4, toaddr, 6))
   4011 		    goto error_return;
   4012 
   4013 		  align_pad_size += 6;
   4014 		}
   4015 	      else
   4016 		{
   4017 		  /* Replace the long jump with a br.  */
   4018 
   4019 		  if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
   4020 		    irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PC9);
   4021 		  else
   4022 		    irel->r_info =
   4023 		      ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
   4024 
   4025 		  irel->r_addend = addend;
   4026 		  addend = 0;
   4027 
   4028 		  if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
   4029 		    /* If this needs to be changed because of future relaxing,
   4030 		       it will be handled here like other internal IND12W
   4031 		       relocs.  */
   4032 		    bfd_put_16 (abfd,
   4033 				0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
   4034 				contents + irel->r_offset);
   4035 		  else
   4036 		    /* We can't fully resolve this yet, because the external
   4037 		       symbol value may be changed by future relaxing.
   4038 		       We let the final link phase handle it.  */
   4039 		    bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
   4040 
   4041 		  hi_irelfn->r_info =
   4042 			ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
   4043 		  lo_irelfn->r_info =
   4044 			ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
   4045 		  if (!v850_elf_relax_delete_bytes (abfd, sec,
   4046 						    irel->r_offset + 2, toaddr, 8))
   4047 		    goto error_return;
   4048 
   4049 		  align_pad_size += 8;
   4050 		}
   4051 	    }
   4052 	}
   4053 
   4054       irelalign = NULL;
   4055       for (irel = internal_relocs; irel < irelend; irel++)
   4056 	{
   4057 	  if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
   4058 	      && irel->r_offset == toaddr)
   4059 	    {
   4060 	      irel->r_offset -= align_pad_size;
   4061 
   4062 	      if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
   4063 		irelalign = irel;
   4064 	    }
   4065 	}
   4066 
   4067       addr = toaddr;
   4068     }
   4069 
   4070   if (!irelalign)
   4071     {
   4072 #ifdef DEBUG_RELAX
   4073       fprintf (stderr, "relax pad %d shorten %d -> %d\n",
   4074 	       align_pad_size,
   4075 	       sec->size,
   4076 	       sec->size - align_pad_size);
   4077 #endif
   4078       sec->size -= align_pad_size;
   4079     }
   4080 
   4081  finish:
   4082   if (elf_section_data (sec)->relocs != internal_relocs)
   4083     free (internal_relocs);
   4084 
   4085   if (elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
   4086     free (contents);
   4087 
   4088   if (symtab_hdr->contents != (bfd_byte *) isymbuf)
   4089     free (isymbuf);
   4090 
   4091   return result;
   4092 
   4093  error_return:
   4094   result = false;
   4095   goto finish;
   4096 }
   4097 
   4098 static const struct bfd_elf_special_section v850_elf_special_sections[] =
   4099 {
   4100   { STRING_COMMA_LEN (".call_table_data"), 0, SHT_PROGBITS,     (SHF_ALLOC + SHF_WRITE) },
   4101   { STRING_COMMA_LEN (".call_table_text"), 0, SHT_PROGBITS,     (SHF_ALLOC + SHF_WRITE
   4102 								 + SHF_EXECINSTR) },
   4103   { STRING_COMMA_LEN (".rosdata"),	  -2, SHT_PROGBITS,	(SHF_ALLOC
   4104 								 + SHF_V850_GPREL) },
   4105   { STRING_COMMA_LEN (".rozdata"),	  -2, SHT_PROGBITS,	(SHF_ALLOC
   4106 								 + SHF_V850_R0REL) },
   4107   { STRING_COMMA_LEN (".sbss"),		  -2, SHT_NOBITS,	(SHF_ALLOC + SHF_WRITE
   4108 								 + SHF_V850_GPREL) },
   4109   { STRING_COMMA_LEN (".scommon"),	  -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE
   4110 								 + SHF_V850_GPREL) },
   4111   { STRING_COMMA_LEN (".sdata"),	  -2, SHT_PROGBITS,	(SHF_ALLOC + SHF_WRITE
   4112 								 + SHF_V850_GPREL) },
   4113   { STRING_COMMA_LEN (".tbss"),		  -2, SHT_NOBITS,	(SHF_ALLOC + SHF_WRITE
   4114 								 + SHF_V850_EPREL) },
   4115   { STRING_COMMA_LEN (".tcommon"),	  -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE
   4116 								 + SHF_V850_R0REL) },
   4117   { STRING_COMMA_LEN (".tdata"),	  -2, SHT_PROGBITS,	(SHF_ALLOC + SHF_WRITE
   4118 								 + SHF_V850_EPREL) },
   4119   { STRING_COMMA_LEN (".zbss"),		  -2, SHT_NOBITS,	(SHF_ALLOC + SHF_WRITE
   4120 								 + SHF_V850_R0REL) },
   4121   { STRING_COMMA_LEN (".zcommon"),	  -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE
   4122 								 + SHF_V850_R0REL) },
   4123   { STRING_COMMA_LEN (".zdata"),	  -2, SHT_PROGBITS,	(SHF_ALLOC + SHF_WRITE
   4124 								 + SHF_V850_R0REL) },
   4125   { NULL,		      0,	   0, 0,		0 }
   4126 };
   4127 
   4128 #define TARGET_LITTLE_SYM			v850_elf32_vec
   4130 #define TARGET_LITTLE_NAME			"elf32-v850"
   4131 #define ELF_ARCH				bfd_arch_v850
   4132 #define ELF_MACHINE_CODE			EM_V850
   4133 #define ELF_MACHINE_ALT1			EM_CYGNUS_V850
   4134 #define ELF_MAXPAGESIZE				0x1000
   4135 
   4136 #define elf_info_to_howto			v850_elf_info_to_howto_rela
   4137 #define elf_info_to_howto_rel			v850_elf_info_to_howto_rel
   4138 
   4139 #define elf_backend_check_relocs		v850_elf_check_relocs
   4140 #define elf_backend_relocate_section		v850_elf_relocate_section
   4141 #define elf_backend_object_p			v850_elf_object_p
   4142 #define elf_backend_final_write_processing	v850_elf_final_write_processing
   4143 #define elf_backend_section_from_bfd_section	v850_elf_section_from_bfd_section
   4144 #define elf_backend_symbol_processing		v850_elf_symbol_processing
   4145 #define elf_backend_add_symbol_hook		v850_elf_add_symbol_hook
   4146 #define elf_backend_link_output_symbol_hook	v850_elf_link_output_symbol_hook
   4147 #define elf_backend_section_from_shdr		v850_elf_section_from_shdr
   4148 #define elf_backend_fake_sections		v850_elf_fake_sections
   4149 #define elf_backend_gc_mark_hook		v850_elf_gc_mark_hook
   4150 #define elf_backend_special_sections		v850_elf_special_sections
   4151 
   4152 #define elf_backend_can_gc_sections		1
   4153 #define elf_backend_rela_normal			1
   4154 
   4155 #define bfd_elf32_bfd_is_local_label_name	v850_elf_is_local_label_name
   4156 #define bfd_elf32_bfd_is_target_special_symbol	v850_elf_is_target_special_symbol
   4157 
   4158 #define bfd_elf32_bfd_reloc_type_lookup		v850_elf_reloc_type_lookup
   4159 #define bfd_elf32_bfd_reloc_name_lookup		v850_elf_reloc_name_lookup
   4160 #define bfd_elf32_bfd_merge_private_bfd_data	v850_elf_merge_private_bfd_data
   4161 #define bfd_elf32_bfd_set_private_flags		v850_elf_set_private_flags
   4162 #define bfd_elf32_bfd_print_private_bfd_data	v850_elf_print_private_bfd_data
   4163 #define bfd_elf32_bfd_relax_section		v850_elf_relax_section
   4164 
   4165 #define elf_symbol_leading_char			'_'
   4166 
   4167 #undef  elf32_bed
   4168 #define elf32_bed elf32_v850_bed
   4169 
   4170 #include "elf32-target.h"
   4171 
   4172 /* Map BFD reloc types to V800 ELF reloc types.  */
   4173 
   4174 static const struct v850_elf_reloc_map v800_elf_reloc_map[] =
   4175 {
   4176   { BFD_RELOC_NONE,		      R_V810_NONE    },
   4177   { BFD_RELOC_8,		      R_V810_BYTE    },
   4178   { BFD_RELOC_16,		      R_V810_HWORD   },
   4179   { BFD_RELOC_32,		      R_V810_WORD    },
   4180   { BFD_RELOC_LO16,		      R_V810_WLO     },
   4181   { BFD_RELOC_HI16,		      R_V810_WHI     },
   4182   { BFD_RELOC_HI16_S,		      R_V810_WHI1    },
   4183   { BFD_RELOC_V850_32_PCREL,	      R_V850_PC32    },
   4184   { BFD_RELOC_V850_22_PCREL,	      R_V850_PCR22   },
   4185   { BFD_RELOC_V850_17_PCREL,	      R_V850_PC17    },
   4186   { BFD_RELOC_V850_16_PCREL,	      R_V850_PC16U   },
   4187   { BFD_RELOC_V850_9_PCREL,	      R_V850_PC9     },
   4188   { BFD_RELOC_V850_LO16_S1,	      R_V810_WLO_1   }, /* Or R_V850_HWLO or R_V850_HWLO_1.  */
   4189   { BFD_RELOC_V850_23,		      R_V850_WLO23   },
   4190   { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_BLO     },
   4191   { BFD_RELOC_V850_ZDA_16_16_OFFSET,  R_V810_HWORD   },
   4192   { BFD_RELOC_V850_TDA_16_16_OFFSET,  R_V810_HWORD   },
   4193   { BFD_RELOC_V850_SDA_16_16_OFFSET,  R_V810_HWORD   },
   4194   { BFD_RELOC_V850_SDA_15_16_OFFSET,  R_V810_GPWLO_1 }
   4195 };
   4196 
   4197 /* Map a bfd relocation into the appropriate howto structure.  */
   4198 
   4199 static reloc_howto_type *
   4200 v800_elf_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code)
   4201 {
   4202   unsigned int i;
   4203 
   4204   BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850);
   4205 
   4206   for (i = ARRAY_SIZE (v800_elf_reloc_map); i --;)
   4207     if (v800_elf_reloc_map[i].bfd_reloc_val == code)
   4208       {
   4209 	unsigned int elf_reloc_val = v800_elf_reloc_map[i].elf_reloc_val;
   4210 	unsigned int idx = elf_reloc_val - R_V810_NONE;
   4211 
   4212 	BFD_ASSERT (v800_elf_howto_table[idx].type == elf_reloc_val);
   4213 
   4214 	return v800_elf_howto_table + idx;
   4215       }
   4216 
   4217 #ifdef DEBUG
   4218   fprintf (stderr, "failed to find v800 equiv of bfd reloc code %d\n", code);
   4219 #endif
   4220   return NULL;
   4221 }
   4222 
   4223 static reloc_howto_type *
   4224 v800_elf_reloc_name_lookup (bfd * abfd, const char * r_name)
   4225 {
   4226   unsigned int i;
   4227 
   4228   BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850);
   4229 
   4230   for (i = ARRAY_SIZE (v800_elf_howto_table); i--;)
   4231     if (v800_elf_howto_table[i].name != NULL
   4232 	&& strcasecmp (v800_elf_howto_table[i].name, r_name) == 0)
   4233       return v800_elf_howto_table + i;
   4234 
   4235   return NULL;
   4236 }
   4237 
   4238 
   4239 /* Set the howto pointer in CACHE_PTR for a V800 ELF reloc.  */
   4240 
   4241 static bool
   4242 v800_elf_info_to_howto (bfd *		    abfd,
   4243 			arelent *	    cache_ptr,
   4244 			Elf_Internal_Rela * dst)
   4245 {
   4246   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
   4247 
   4248   if (r_type == R_V800_NONE)
   4249     r_type = R_V810_NONE;
   4250 
   4251   if (bfd_get_arch (abfd) != bfd_arch_v850_rh850
   4252       || r_type >= (unsigned int) R_V800_max
   4253       || r_type < (unsigned int) R_V810_NONE
   4254       || (r_type - R_V810_NONE) >= ARRAY_SIZE (v800_elf_howto_table))
   4255     {
   4256       /* xgettext:c-format */
   4257       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
   4258 			  abfd, r_type);
   4259       bfd_set_error (bfd_error_bad_value);
   4260       return false;
   4261     }
   4262 
   4263   cache_ptr->howto = v800_elf_howto_table + (r_type - R_V810_NONE);
   4264   return true;
   4265 }
   4266 
   4267 #undef  TARGET_LITTLE_SYM
   4269 #define TARGET_LITTLE_SYM			v800_elf32_vec
   4270 #undef  TARGET_LITTLE_NAME
   4271 #define TARGET_LITTLE_NAME			"elf32-v850-rh850"
   4272 #undef  ELF_ARCH
   4273 #define ELF_ARCH				bfd_arch_v850_rh850
   4274 #undef  ELF_MACHINE_CODE
   4275 #define ELF_MACHINE_CODE			EM_V800
   4276 #undef  ELF_MACHINE_ALT1
   4277 
   4278 #undef  elf32_bed
   4279 #define elf32_bed elf32_v850_rh850_bed
   4280 
   4281 #undef  elf_info_to_howto
   4282 #define elf_info_to_howto			v800_elf_info_to_howto
   4283 #undef  elf_info_to_howto_rel
   4284 #define elf_info_to_howto_rel			NULL
   4285 #undef  bfd_elf32_bfd_reloc_type_lookup
   4286 #define bfd_elf32_bfd_reloc_type_lookup		v800_elf_reloc_type_lookup
   4287 #undef  bfd_elf32_bfd_reloc_name_lookup
   4288 #define bfd_elf32_bfd_reloc_name_lookup		v800_elf_reloc_name_lookup
   4289 
   4290 #include "elf32-target.h"
   4291