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