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, 2012
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
24 /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
25 dependencies. As is the gas & simulator code for the v850. */
33 #include "libiberty.h"
35 /* Sign-extend a 17-bit number. */
36 #define SEXT17(x) ((((x) & 0x1ffff) ^ 0x10000) - 0x10000)
38 /* Sign-extend a 22-bit number. */
39 #define SEXT22(x) ((((x) & 0x3fffff) ^ 0x200000) - 0x200000)
41 static reloc_howto_type v850_elf_howto_table[];
43 /* Look through the relocs for a section during the first phase, and
44 allocate space in the global offset table or procedure linkage
48 v850_elf_check_relocs (bfd *abfd,
49 struct bfd_link_info *info,
51 const Elf_Internal_Rela *relocs)
53 bfd_boolean ret = TRUE;
54 Elf_Internal_Shdr *symtab_hdr;
55 struct elf_link_hash_entry **sym_hashes;
56 const Elf_Internal_Rela *rel;
57 const Elf_Internal_Rela *rel_end;
58 enum v850_reloc_type r_type;
60 const char *common = NULL;
62 if (info->relocatable)
66 _bfd_error_handler ("v850_elf_check_relocs called for section %A in %B",
70 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
71 sym_hashes = elf_sym_hashes (abfd);
73 rel_end = relocs + sec->reloc_count;
74 for (rel = relocs; rel < rel_end; rel++)
76 unsigned long r_symndx;
77 struct elf_link_hash_entry *h;
79 r_symndx = ELF32_R_SYM (rel->r_info);
80 if (r_symndx < symtab_hdr->sh_info)
84 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
85 while (h->root.type == bfd_link_hash_indirect
86 || h->root.type == bfd_link_hash_warning)
87 h = (struct elf_link_hash_entry *) h->root.u.i.link;
90 r_type = (enum v850_reloc_type) ELF32_R_TYPE (rel->r_info);
105 case R_V850_LO16_SPLIT_OFFSET:
111 case R_V850_16_SPLIT_OFFSET:
113 case R_V850_CALLT_6_7_OFFSET:
114 case R_V850_CALLT_15_16_OFFSET:
115 case R_V850_CALLT_16_16_OFFSET:
118 /* This relocation describes the C++ object vtable hierarchy.
119 Reconstruct it for later use during GC. */
120 case R_V850_GNU_VTINHERIT:
121 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
125 /* This relocation describes which C++ vtable entries
126 are actually used. Record for later use during GC. */
127 case R_V850_GNU_VTENTRY:
128 BFD_ASSERT (h != NULL);
130 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
134 case R_V850_SDA_16_16_SPLIT_OFFSET:
135 case R_V850_SDA_16_16_OFFSET:
136 case R_V850_SDA_15_16_OFFSET:
137 other = V850_OTHER_SDA;
139 goto small_data_common;
141 case R_V850_ZDA_16_16_SPLIT_OFFSET:
142 case R_V850_ZDA_16_16_OFFSET:
143 case R_V850_ZDA_15_16_OFFSET:
144 other = V850_OTHER_ZDA;
146 goto small_data_common;
148 case R_V850_TDA_4_4_OFFSET:
149 case R_V850_TDA_4_5_OFFSET:
150 case R_V850_TDA_7_7_OFFSET:
151 case R_V850_TDA_6_8_OFFSET:
152 case R_V850_TDA_7_8_OFFSET:
153 case R_V850_TDA_16_16_OFFSET:
154 other = V850_OTHER_TDA;
158 #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
163 /* Flag which type of relocation was used. */
165 if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
166 && (h->other & V850_OTHER_ERROR) == 0)
169 static char buff[200]; /* XXX */
171 switch (h->other & V850_OTHER_MASK)
174 msg = _("Variable `%s' cannot occupy in multiple small data regions");
176 case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
177 msg = _("Variable `%s' can only be in one of the small, zero, and tiny data regions");
179 case V850_OTHER_SDA | V850_OTHER_ZDA:
180 msg = _("Variable `%s' cannot be in both small and zero data regions simultaneously");
182 case V850_OTHER_SDA | V850_OTHER_TDA:
183 msg = _("Variable `%s' cannot be in both small and tiny data regions simultaneously");
185 case V850_OTHER_ZDA | V850_OTHER_TDA:
186 msg = _("Variable `%s' cannot be in both zero and tiny data regions simultaneously");
190 sprintf (buff, msg, h->root.root.string);
191 info->callbacks->warning (info, buff, h->root.root.string,
192 abfd, h->root.u.def.section,
195 bfd_set_error (bfd_error_bad_value);
196 h->other |= V850_OTHER_ERROR;
201 if (h && h->root.type == bfd_link_hash_common
203 && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON"))
207 section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
208 section->flags |= SEC_IS_COMMON;
212 fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
213 v850_elf_howto_table[ (int)r_type ].name,
214 (h && h->root.root.string) ? h->root.root.string : "<unknown>",
215 (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
224 /* In the old version, when an entry was checked out from the table,
225 it was deleted. This produced an error if the entry was needed
226 more than once, as the second attempted retry failed.
228 In the current version, the entry is not deleted, instead we set
229 the field 'found' to TRUE. If a second lookup matches the same
230 entry, then we know that the hi16s reloc has already been updated
231 and does not need to be updated a second time.
233 TODO - TOFIX: If it is possible that we need to restore 2 different
234 addresses from the same table entry, where the first generates an
235 overflow, whilst the second do not, then this code will fail. */
237 typedef struct hi16s_location
241 unsigned long counter;
243 struct hi16s_location * next;
247 static hi16s_location * previous_hi16s;
248 static hi16s_location * free_hi16s;
249 static unsigned long hi16s_counter;
252 remember_hi16s_reloc (bfd *abfd, bfd_vma addend, bfd_byte *address)
254 hi16s_location * entry = NULL;
255 bfd_size_type amt = sizeof (* free_hi16s);
257 /* Find a free structure. */
258 if (free_hi16s == NULL)
259 free_hi16s = bfd_zalloc (abfd, amt);
262 free_hi16s = free_hi16s->next;
264 entry->addend = addend;
265 entry->address = address;
266 entry->counter = hi16s_counter ++;
267 entry->found = FALSE;
268 entry->next = previous_hi16s;
269 previous_hi16s = entry;
271 /* Cope with wrap around of our counter. */
272 if (hi16s_counter == 0)
274 /* XXX: Assume that all counter entries differ only in their low 16 bits. */
275 for (entry = previous_hi16s; entry != NULL; entry = entry->next)
276 entry->counter &= 0xffff;
278 hi16s_counter = 0x10000;
283 find_remembered_hi16s_reloc (bfd_vma addend, bfd_boolean *already_found)
285 hi16s_location *match = NULL;
286 hi16s_location *entry;
289 /* Search the table. Record the most recent entry that matches. */
290 for (entry = previous_hi16s; entry; entry = entry->next)
292 if (entry->addend == addend
293 && (match == NULL || match->counter < entry->counter))
302 /* Extract the address. */
303 addr = match->address;
305 /* Remember if this entry has already been used before. */
307 * already_found = match->found;
309 /* Note that this entry has now been used. */
315 /* Calculate the final operand value for a R_V850_LO16 or
316 R_V850_LO16_SPLIT_OFFSET. *INSN is the current operand value and
317 ADDEND is the sum of the relocation symbol and offset. Store the
318 operand value in *INSN and return true on success.
320 The assembler has already done some of this: If the value stored in
321 the instruction has its 15th bit set, (counting from zero) then the
322 assembler will have added 1 to the value stored in the associated
323 HI16S reloc. So for example, these relocations:
325 movhi hi( fred ), r0, r1
326 movea lo( fred ), r1, r1
328 will store 0 in the value fields for the MOVHI and MOVEA instructions
329 and addend will be the address of fred, but for these instructions:
331 movhi hi( fred + 0x123456 ), r0, r1
332 movea lo( fred + 0x123456 ), r1, r1
334 the value stored in the MOVHI instruction will be 0x12 and the value
335 stored in the MOVEA instruction will be 0x3456. If however the
338 movhi hi( fred + 0x10ffff ), r0, r1
339 movea lo( fred + 0x10ffff ), r1, r1
341 then the value stored in the MOVHI instruction would be 0x11 (not
342 0x10) and the value stored in the MOVEA instruction would be 0xffff.
343 Thus (assuming for the moment that the addend is 0), at run time the
344 MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction
345 adds 0xffffffff (sign extension!) producing 0x10ffff. Similarly if
346 the instructions were:
348 movhi hi( fred - 1 ), r0, r1
349 movea lo( fred - 1 ), r1, r1
351 then 0 is stored in the MOVHI instruction and -1 is stored in the
354 Overflow can occur if the addition of the value stored in the
355 instruction plus the addend sets the 15th bit when before it was clear.
356 This is because the 15th bit will be sign extended into the high part,
357 thus reducing its value by one, but since the 15th bit was originally
358 clear, the assembler will not have added 1 to the previous HI16S reloc
359 to compensate for this effect. For example:
361 movhi hi( fred + 0x123456 ), r0, r1
362 movea lo( fred + 0x123456 ), r1, r1
364 The value stored in HI16S reloc is 0x12, the value stored in the LO16
365 reloc is 0x3456. If we assume that the address of fred is 0x00007000
366 then the relocations become:
368 HI16S: 0x0012 + (0x00007000 >> 16) = 0x12
369 LO16: 0x3456 + (0x00007000 & 0xffff) = 0xa456
371 but when the instructions are executed, the MOVEA instruction's value
372 is signed extended, so the sum becomes:
377 0x0011a456 but 'fred + 0x123456' = 0x0012a456
379 Note that if the 15th bit was set in the value stored in the LO16
380 reloc, then we do not have to do anything:
382 movhi hi( fred + 0x10ffff ), r0, r1
383 movea lo( fred + 0x10ffff ), r1, r1
385 HI16S: 0x0011 + (0x00007000 >> 16) = 0x11
386 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff
391 0x00116fff = fred + 0x10ffff = 0x7000 + 0x10ffff
393 Overflow can also occur if the computation carries into the 16th bit
394 and it also results in the 15th bit having the same value as the 15th
395 bit of the original value. What happens is that the HI16S reloc
396 will have already examined the 15th bit of the original value and
397 added 1 to the high part if the bit is set. This compensates for the
398 sign extension of 15th bit of the result of the computation. But now
399 there is a carry into the 16th bit, and this has not been allowed for.
401 So, for example if fred is at address 0xf000:
403 movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set]
404 movea lo( fred + 0xffff ), r1, r1
406 HI16S: 0x0001 + (0x0000f000 >> 16) = 0x0001
407 LO16: 0xffff + (0x0000f000 & 0xffff) = 0xefff (carry into bit 16 is lost)
412 0x0000efff but 'fred + 0xffff' = 0x0001efff
414 Similarly, if the 15th bit remains clear, but overflow occurs into
415 the 16th bit then (assuming the address of fred is 0xf000):
417 movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear]
418 movea lo( fred + 0x7000 ), r1, r1
420 HI16S: 0x0000 + (0x0000f000 >> 16) = 0x0000
421 LO16: 0x7000 + (0x0000f000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
426 0x00006fff but 'fred + 0x7000' = 0x00016fff
428 Note - there is no need to change anything if a carry occurs, and the
429 15th bit changes its value from being set to being clear, as the HI16S
430 reloc will have already added in 1 to the high part for us:
432 movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set]
433 movea lo( fred + 0xffff ), r1, r1
435 HI16S: 0x0001 + (0x00007000 >> 16)
436 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
439 + 0x00006fff (bit 15 not set, so the top half is zero)
441 0x00016fff which is right (assuming that fred is at 0x7000)
443 but if the 15th bit goes from being clear to being set, then we must
444 once again handle overflow:
446 movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear]
447 movea lo( fred + 0x7000 ), r1, r1
449 HI16S: 0x0000 + (0x0000ffff >> 16)
450 LO16: 0x7000 + (0x0000ffff & 0xffff) = 0x6fff (carry into bit 16)
453 + 0x00006fff (bit 15 not set, so the top half is zero)
455 0x00006fff which is wrong (assuming that fred is at 0xffff). */
458 v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn,
459 unsigned long addend)
461 #define BIT15_SET(x) ((x) & 0x8000)
462 #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff)
464 if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend))
465 || (OVERFLOWS (addend, *insn)
466 && ((! BIT15_SET (*insn)) || (BIT15_SET (addend)))))
468 bfd_boolean already_updated;
469 bfd_byte *hi16s_address = find_remembered_hi16s_reloc
470 (addend, & already_updated);
472 /* Amend the matching HI16_S relocation. */
473 if (hi16s_address != NULL)
475 if (! already_updated)
477 unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address);
479 bfd_put_16 (abfd, hi_insn, hi16s_address);
484 (*_bfd_error_handler) (_("FAILED to find previous HI16 reloc"));
491 /* Do not complain if value has top bit set, as this has been
493 *insn = (*insn + addend) & 0xffff;
497 /* FIXME: The code here probably ought to be removed and the code in reloc.c
498 allowed to do its stuff instead. At least for most of the relocs, anyway. */
500 static bfd_reloc_status_type
501 v850_elf_perform_relocation (bfd *abfd,
507 unsigned long result;
508 bfd_signed_vma saddend = (bfd_signed_vma) addend;
513 return bfd_reloc_notsupported;
517 bfd_put_32 (abfd, addend, address);
521 insn = bfd_get_32 (abfd, address);
522 insn &= ~((0x7f << 4) | (0x7fff80 << (16-7)));
523 insn |= ((addend & 0x7f) << 4) | ((addend & 0x7fff80) << (16-7));
524 bfd_put_32 (abfd, (bfd_vma) insn, address);
527 case R_V850_22_PCREL:
528 if (saddend > 0x1fffff || saddend < -0x200000)
529 return bfd_reloc_overflow;
531 if ((addend % 2) != 0)
532 return bfd_reloc_dangerous;
534 insn = bfd_get_32 (abfd, address);
536 insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
537 bfd_put_32 (abfd, (bfd_vma) insn, address);
540 case R_V850_17_PCREL:
541 if (saddend > 0xffff || saddend < -0x10000)
542 return bfd_reloc_overflow;
544 if ((addend % 2) != 0)
545 return bfd_reloc_dangerous;
547 insn = bfd_get_32 (abfd, address);
548 insn &= ~ 0xfffe0010;
549 insn |= ((addend & 0xfffe) << 16) | ((addend & 0x10000) >> (16-4));
552 case R_V850_16_PCREL:
553 if ((saddend < -0xffff) || (saddend > 0))
554 return bfd_reloc_overflow;
556 if ((addend % 2) != 0)
557 return bfd_reloc_dangerous;
559 insn = bfd_get_16 (abfd, address);
561 insn |= (-addend & 0xfffe);
565 if (saddend > 0xff || saddend < -0x100)
566 return bfd_reloc_overflow;
568 if ((addend % 2) != 0)
569 return bfd_reloc_dangerous;
571 insn = bfd_get_16 (abfd, address);
573 insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3);
577 addend += (bfd_get_16 (abfd, address) << 16);
578 addend = (addend >> 16);
583 /* Remember where this relocation took place. */
584 remember_hi16s_reloc (abfd, addend, address);
586 addend += (bfd_get_16 (abfd, address) << 16);
587 addend = (addend >> 16) + ((addend & 0x8000) != 0);
589 /* This relocation cannot overflow. */
597 insn = bfd_get_16 (abfd, address);
598 if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend))
599 return bfd_reloc_overflow;
603 addend += (char) bfd_get_8 (abfd, address);
605 saddend = (bfd_signed_vma) addend;
607 if (saddend > 0x7f || saddend < -0x80)
608 return bfd_reloc_overflow;
610 bfd_put_8 (abfd, addend, address);
613 case R_V850_CALLT_16_16_OFFSET:
614 addend += bfd_get_16 (abfd, address);
616 saddend = (bfd_signed_vma) addend;
618 if (saddend > 0xffff || saddend < 0)
619 return bfd_reloc_overflow;
624 case R_V850_CALLT_15_16_OFFSET:
625 insn = bfd_get_16 (abfd, address);
627 addend += insn & 0xfffe;
629 saddend = (bfd_signed_vma) addend;
631 if (saddend > 0xffff || saddend < 0)
632 return bfd_reloc_overflow;
634 insn = (0xfffe & addend)
638 case R_V850_CALLT_6_7_OFFSET:
639 insn = bfd_get_16 (abfd, address);
640 addend += ((insn & 0x3f) << 1);
642 saddend = (bfd_signed_vma) addend;
644 if (saddend > 0x7e || saddend < 0)
645 return bfd_reloc_overflow;
648 return bfd_reloc_dangerous;
651 insn |= (addend >> 1);
655 case R_V850_SDA_16_16_OFFSET:
656 case R_V850_ZDA_16_16_OFFSET:
657 case R_V850_TDA_16_16_OFFSET:
658 addend += bfd_get_16 (abfd, address);
660 saddend = (bfd_signed_vma) addend;
662 if (saddend > 0x7fff || saddend < -0x8000)
663 return bfd_reloc_overflow;
669 case R_V850_SDA_15_16_OFFSET:
670 case R_V850_ZDA_15_16_OFFSET:
671 insn = bfd_get_16 (abfd, address);
672 addend += (insn & 0xfffe);
674 saddend = (bfd_signed_vma) addend;
676 if (saddend > 0x7ffe || saddend < -0x8000)
677 return bfd_reloc_overflow;
680 return bfd_reloc_dangerous;
682 insn = (addend &~ (bfd_vma) 1) | (insn & 1);
685 case R_V850_TDA_6_8_OFFSET:
686 insn = bfd_get_16 (abfd, address);
687 addend += ((insn & 0x7e) << 1);
689 saddend = (bfd_signed_vma) addend;
691 if (saddend > 0xfc || saddend < 0)
692 return bfd_reloc_overflow;
695 return bfd_reloc_dangerous;
698 insn |= (addend >> 1);
701 case R_V850_TDA_7_8_OFFSET:
702 insn = bfd_get_16 (abfd, address);
703 addend += ((insn & 0x7f) << 1);
705 saddend = (bfd_signed_vma) addend;
707 if (saddend > 0xfe || saddend < 0)
708 return bfd_reloc_overflow;
711 return bfd_reloc_dangerous;
714 insn |= (addend >> 1);
717 case R_V850_TDA_7_7_OFFSET:
718 insn = bfd_get_16 (abfd, address);
719 addend += insn & 0x7f;
721 saddend = (bfd_signed_vma) addend;
723 if (saddend > 0x7f || saddend < 0)
724 return bfd_reloc_overflow;
730 case R_V850_TDA_4_5_OFFSET:
731 insn = bfd_get_16 (abfd, address);
732 addend += ((insn & 0xf) << 1);
734 saddend = (bfd_signed_vma) addend;
736 if (saddend > 0x1e || saddend < 0)
737 return bfd_reloc_overflow;
740 return bfd_reloc_dangerous;
743 insn |= (addend >> 1);
746 case R_V850_TDA_4_4_OFFSET:
747 insn = bfd_get_16 (abfd, address);
748 addend += insn & 0xf;
750 saddend = (bfd_signed_vma) addend;
752 if (saddend > 0xf || saddend < 0)
753 return bfd_reloc_overflow;
760 insn = bfd_get_16 (abfd, address);
761 result = insn & 0xfffe;
762 if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
763 return bfd_reloc_overflow;
765 return bfd_reloc_overflow;
766 insn = (result & 0xfffe)
768 bfd_put_16 (abfd, insn, address);
771 case R_V850_LO16_SPLIT_OFFSET:
772 insn = bfd_get_32 (abfd, address);
773 result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5);
774 if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
775 return bfd_reloc_overflow;
776 insn = (((result << 16) & 0xfffe0000)
777 | ((result << 5) & 0x20)
778 | (insn & ~0xfffe0020));
779 bfd_put_32 (abfd, insn, address);
782 case R_V850_16_SPLIT_OFFSET:
783 case R_V850_SDA_16_16_SPLIT_OFFSET:
784 case R_V850_ZDA_16_16_SPLIT_OFFSET:
785 insn = bfd_get_32 (abfd, address);
786 addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5);
788 saddend = (bfd_signed_vma) addend;
790 if (saddend > 0x7fff || saddend < -0x8000)
791 return bfd_reloc_overflow;
794 insn |= (addend & 1) << 5;
795 insn |= (addend &~ (bfd_vma) 1) << 16;
797 bfd_put_32 (abfd, (bfd_vma) insn, address);
800 case R_V850_GNU_VTINHERIT:
801 case R_V850_GNU_VTENTRY:
806 bfd_put_16 (abfd, (bfd_vma) insn, address);
810 /* Insert the addend into the instruction. */
812 static bfd_reloc_status_type
813 v850_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
816 void * data ATTRIBUTE_UNUSED,
819 char **err ATTRIBUTE_UNUSED)
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. */
829 && (symbol->flags & BSF_SECTION_SYM) == 0
830 && (! reloc->howto->partial_inplace
831 || reloc->addend == 0))
833 reloc->address += isection->output_offset;
837 /* Catch relocs involving undefined symbols. */
838 if (bfd_is_und_section (symbol->section)
839 && (symbol->flags & BSF_WEAK) == 0
841 return bfd_reloc_undefined;
843 /* We handle final linking of some relocs ourselves. */
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;
849 /* Work out which section the relocation is targeted at and the
850 initial relocation command value. */
852 if (reloc->howto->pc_relative)
855 /* Get symbol value. (Common symbols are special.) */
856 if (bfd_is_com_section (symbol->section))
859 relocation = symbol->value;
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;
866 reloc->addend = relocation;
870 /* This function is used for relocs which are only used
871 for relaxing, which the linker should otherwise ignore. */
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,
880 char **error_message ATTRIBUTE_UNUSED)
882 if (output_bfd != NULL)
883 reloc_entry->address += input_section->output_offset;
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[] =
892 /* This reloc does nothing. */
893 HOWTO (R_V850_NONE, /* Type. */
895 2, /* Size (0 = byte, 1 = short, 2 = long). */
897 FALSE, /* PC_relative. */
899 complain_overflow_bitfield, /* Complain_on_overflow. */
900 bfd_elf_generic_reloc, /* Special_function. */
901 "R_V850_NONE", /* Name. */
902 FALSE, /* Partial_inplace. */
905 FALSE), /* PCrel_offset. */
907 /* A PC relative 9 bit branch. */
908 HOWTO (R_V850_9_PCREL, /* Type. */
910 1, /* Size (0 = byte, 1 = short, 2 = long). */
912 TRUE, /* PC_relative. */
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. */
922 /* A PC relative 22 bit branch. */
923 HOWTO (R_V850_22_PCREL, /* Type. */
925 2, /* Size (0 = byte, 1 = short, 2 = long). */
927 TRUE, /* PC_relative. */
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. */
937 /* High 16 bits of symbol value. */
938 HOWTO (R_V850_HI16_S, /* Type. */
940 1, /* Size (0 = byte, 1 = short, 2 = long). */
942 FALSE, /* PC_relative. */
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. */
952 /* High 16 bits of symbol value. */
953 HOWTO (R_V850_HI16, /* Type. */
955 1, /* Size (0 = byte, 1 = short, 2 = long). */
957 FALSE, /* PC_relative. */
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. */
967 /* Low 16 bits of symbol value. */
968 HOWTO (R_V850_LO16, /* Type. */
970 1, /* Size (0 = byte, 1 = short, 2 = long). */
972 FALSE, /* PC_relative. */
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. */
982 /* Simple 32bit reloc. */
983 HOWTO (R_V850_ABS32, /* Type. */
985 2, /* Size (0 = byte, 1 = short, 2 = long). */
987 FALSE, /* PC_relative. */
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. */
997 /* Simple 16bit reloc. */
998 HOWTO (R_V850_16, /* Type. */
1000 1, /* Size (0 = byte, 1 = short, 2 = long). */
1002 FALSE, /* PC_relative. */
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. */
1012 /* Simple 8bit reloc. */
1013 HOWTO (R_V850_8, /* Type. */
1014 0, /* Rightshift. */
1015 0, /* Size (0 = byte, 1 = short, 2 = long). */
1017 FALSE, /* PC_relative. */
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. */
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). */
1032 FALSE, /* PC_relative. */
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. */
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). */
1047 FALSE, /* PC_relative. */
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. */
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). */
1062 FALSE, /* PC_relative. */
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. */
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). */
1077 FALSE, /* PC_relative. */
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. */
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). */
1092 FALSE, /* PC_relative. */
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. */
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). */
1107 FALSE, /* PC_relative. */
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. */
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). */
1122 FALSE, /* PC_relative. */
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. */
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). */
1137 FALSE, /* PC_relative. */
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. */
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). */
1152 FALSE, /* PC_relative. */
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. */
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). */
1167 FALSE, /* PC_relative. */
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. */
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). */
1182 FALSE, /* PC_relative. */
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. */
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). */
1197 FALSE, /* PC_relative. */
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. */
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). */
1212 FALSE, /* PC_relative. */
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. */
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). */
1227 FALSE, /* PC_relative. */
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. */
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). */
1243 FALSE, /* PC_relative. */
1245 complain_overflow_dont, /* Complain_on_overflow. */
1246 NULL, /* Special_function. */
1247 "R_V850_GNU_VTINHERIT", /* Name. */
1248 FALSE, /* Partial_inplace. */
1251 FALSE), /* PCrel_offset. */
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). */
1258 FALSE, /* PC_relative. */
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. */
1266 FALSE), /* PCrel_offset. */
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). */
1274 TRUE, /* PC_relative. */
1276 complain_overflow_signed, /* Complain_on_overflow. */
1277 v850_elf_ignore_reloc, /* Special_function. */
1278 "R_V850_LONGCALL", /* Name. */
1279 FALSE, /* Partial_inplace. */
1282 TRUE), /* PCrel_offset. */
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). */
1290 TRUE, /* PC_relative. */
1292 complain_overflow_signed, /* Complain_on_overflow. */
1293 v850_elf_ignore_reloc, /* Special_function. */
1294 "R_V850_LONGJUMP", /* Name. */
1295 FALSE, /* Partial_inplace. */
1298 TRUE), /* PCrel_offset. */
1300 HOWTO (R_V850_ALIGN, /* Type. */
1301 0, /* Rightshift. */
1302 1, /* Size (0 = byte, 1 = short, 2 = long). */
1304 FALSE, /* PC_relative. */
1306 complain_overflow_unsigned, /* Complain_on_overflow. */
1307 v850_elf_ignore_reloc, /* Special_function. */
1308 "R_V850_ALIGN", /* Name. */
1309 FALSE, /* Partial_inplace. */
1312 TRUE), /* PCrel_offset. */
1314 /* Simple pc-relative 32bit reloc. */
1315 HOWTO (R_V850_REL32, /* Type. */
1316 0, /* Rightshift. */
1317 2, /* Size (0 = byte, 1 = short, 2 = long). */
1319 TRUE, /* PC_relative. */
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. */
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). */
1334 FALSE, /* PC_relative. */
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. */
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). */
1349 TRUE, /* PC_relative. */
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. */
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). */
1364 TRUE, /* PC_relative. */
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. */
1374 /* A 23bit offset ld/st. */
1375 HOWTO (R_V850_23, /* type. */
1376 0, /* rightshift. */
1377 2, /* size (0 = byte, 1 = short, 2 = long). */
1379 FALSE, /* pc_relative. */
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. */
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). */
1394 TRUE, /* pc_relative. */
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. */
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). */
1409 TRUE, /* pc_relative. */
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. */
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). */
1424 FALSE, /* PC_relative. */
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. */
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). */
1439 FALSE, /* pc_relative. */
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. */
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). */
1454 FALSE, /* pc_relative. */
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. */
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). */
1469 FALSE, /* pc_relative. */
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. */
1479 /* Like R_V850_32 PCREL, but referring to the GOT table entry for
1481 HOWTO (R_V850_32_GOTPCREL, /* type. */
1482 0, /* rightshift. */
1483 2, /* size (0 = byte, 1 = short, 2 = long). */
1485 TRUE, /* pc_relative. */
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. */
1495 /* Like R_V850_SDA_, but referring to the GOT table entry for
1497 HOWTO (R_V850_16_GOT, /* type. */
1498 0, /* rightshift. */
1499 2, /* size (0 = byte, 1 = short, 2 = long). */
1501 FALSE, /* pc_relative. */
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. */
1511 HOWTO (R_V850_32_GOT, /* type. */
1512 0, /* rightshift. */
1513 2, /* size (0 = byte, 1 = short, 2 = long). */
1515 FALSE, /* pc_relative. */
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. */
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). */
1531 TRUE, /* pc_relative. */
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. */
1541 HOWTO (R_V850_32_PLT, /* type. */
1542 1, /* rightshift. */
1543 2, /* size (0 = byte, 1 = short, 2 = long). */
1545 TRUE, /* pc_relative. */
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. */
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). */
1564 FALSE, /* pc_relative. */
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. */
1574 /* Like R_M32R_24, but used when setting global offset table
1576 HOWTO (R_V850_GLOB_DAT, /* type. */
1577 0, /* rightshift. */
1578 2, /* size (0 = byte, 1 = short, 2 = long) */
1580 FALSE, /* pc_relative. */
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. */
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) */
1595 FALSE, /* pc_relative. */
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. */
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
1608 HOWTO (R_V850_RELATIVE, /* type. */
1609 0, /* rightshift. */
1610 2, /* size (0 = byte, 1 = short, 2 = long) */
1612 FALSE, /* pc_relative. */
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. */
1622 HOWTO (R_V850_16_GOTOFF, /* type. */
1623 0, /* rightshift. */
1624 2, /* size (0 = byte, 1 = short, 2 = long) */
1626 FALSE, /* pc_relative. */
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. */
1636 HOWTO (R_V850_32_GOTOFF, /* type. */
1637 0, /* rightshift. */
1638 2, /* size (0 = byte, 1 = short, 2 = long) */
1640 FALSE, /* pc_relative. */
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. */
1650 HOWTO (R_V850_CODE, /* type. */
1651 0, /* rightshift. */
1652 1, /* size (0 = byte, 1 = short, 2 = long) */
1654 FALSE, /* pc_relative. */
1656 complain_overflow_unsigned, /* complain_on_overflow. */
1657 v850_elf_ignore_reloc, /* special_function. */
1658 "R_V850_CODE", /* name. */
1659 FALSE, /* partial_inplace. */
1662 TRUE), /* pcrel_offset. */
1664 HOWTO (R_V850_DATA, /* type. */
1665 0, /* rightshift. */
1666 1, /* size (0 = byte, 1 = short, 2 = long) */
1668 FALSE, /* pc_relative. */
1670 complain_overflow_unsigned, /* complain_on_overflow. */
1671 v850_elf_ignore_reloc, /* special_function. */
1672 "R_V850_DATA", /* name. */
1673 FALSE, /* partial_inplace. */
1676 TRUE), /* pcrel_offset. */
1680 /* Map BFD reloc types to V850 ELF reloc types. */
1682 struct v850_elf_reloc_map
1684 /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an
1686 bfd_reloc_code_real_type bfd_reloc_val;
1687 unsigned int elf_reloc_val;
1690 static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
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 },
1746 /* Map a bfd relocation into the appropriate howto structure. */
1748 static reloc_howto_type *
1749 v850_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1750 bfd_reloc_code_real_type code)
1754 for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
1755 if (v850_elf_reloc_map[i].bfd_reloc_val == code)
1757 unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
1759 BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
1761 return v850_elf_howto_table + elf_reloc_val;
1767 static reloc_howto_type *
1768 v850_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1774 i < sizeof (v850_elf_howto_table) / sizeof (v850_elf_howto_table[0]);
1776 if (v850_elf_howto_table[i].name != NULL
1777 && strcasecmp (v850_elf_howto_table[i].name, r_name) == 0)
1778 return &v850_elf_howto_table[i];
1783 /* Set the howto pointer for an V850 ELF reloc. */
1786 v850_elf_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1788 Elf_Internal_Rela *dst)
1790 unsigned int r_type;
1792 r_type = ELF32_R_TYPE (dst->r_info);
1793 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
1794 cache_ptr->howto = &v850_elf_howto_table[r_type];
1797 /* Set the howto pointer for a V850 ELF reloc (type RELA). */
1800 v850_elf_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
1801 arelent * cache_ptr,
1802 Elf_Internal_Rela *dst)
1804 unsigned int r_type;
1806 r_type = ELF32_R_TYPE (dst->r_info);
1807 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
1808 cache_ptr->howto = &v850_elf_howto_table[r_type];
1812 v850_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
1814 return ( (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
1815 || (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_'));
1818 /* We overload some of the bfd_reloc error codes for own purposes. */
1819 #define bfd_reloc_gp_not_found bfd_reloc_other
1820 #define bfd_reloc_ep_not_found bfd_reloc_continue
1821 #define bfd_reloc_ctbp_not_found (bfd_reloc_dangerous + 1)
1823 /* Perform a relocation as part of a final link. */
1825 static bfd_reloc_status_type
1826 v850_elf_final_link_relocate (reloc_howto_type *howto,
1828 bfd *output_bfd ATTRIBUTE_UNUSED,
1829 asection *input_section,
1834 struct bfd_link_info *info,
1836 int is_local ATTRIBUTE_UNUSED)
1838 unsigned int r_type = howto->type;
1839 bfd_byte *hit_data = contents + offset;
1841 /* Adjust the value according to the relocation. */
1844 case R_V850_9_PCREL:
1845 value -= (input_section->output_section->vma
1846 + input_section->output_offset);
1850 case R_V850_16_PCREL:
1851 value -= (input_section->output_section->vma
1852 + input_section->output_offset
1855 /* If the sign extension will corrupt the value then we have overflowed. */
1856 if ((value & 0xffff0000) != 0xffff0000)
1857 return bfd_reloc_overflow;
1861 case R_V850_17_PCREL:
1862 value -= (input_section->output_section->vma
1863 + input_section->output_offset
1866 /* If the sign extension will corrupt the value then we have overflowed. */
1867 if (((value & 0xffff0000) != 0x0) && ((value & 0xffff0000) != 0xffff0000))
1868 return bfd_reloc_overflow;
1870 value = SEXT17 (value);
1873 case R_V850_22_PCREL:
1874 value -= (input_section->output_section->vma
1875 + input_section->output_offset
1878 /* If the sign extension will corrupt the value then we have overflowed. */
1879 if (((value & 0xffe00000) != 0x0) && ((value & 0xffe00000) != 0xffe00000))
1880 return bfd_reloc_overflow;
1882 /* Only the bottom 22 bits of the PC are valid. */
1883 value = SEXT22 (value);
1886 case R_V850_32_PCREL:
1887 value -= (input_section->output_section->vma
1888 + input_section->output_offset
1897 case R_V850_LO16_S1:
1898 case R_V850_LO16_SPLIT_OFFSET:
1904 case R_V850_ZDA_15_16_OFFSET:
1905 case R_V850_ZDA_16_16_OFFSET:
1906 case R_V850_ZDA_16_16_SPLIT_OFFSET:
1907 if (sym_sec == NULL)
1908 return bfd_reloc_undefined;
1910 value -= sym_sec->output_section->vma;
1913 case R_V850_SDA_15_16_OFFSET:
1914 case R_V850_SDA_16_16_OFFSET:
1915 case R_V850_SDA_16_16_SPLIT_OFFSET:
1918 struct bfd_link_hash_entry * h;
1920 if (sym_sec == NULL)
1921 return bfd_reloc_undefined;
1923 /* Get the value of __gp. */
1924 h = bfd_link_hash_lookup (info->hash, "__gp", FALSE, FALSE, TRUE);
1926 || h->type != bfd_link_hash_defined)
1927 return bfd_reloc_gp_not_found;
1929 gp = (h->u.def.value
1930 + h->u.def.section->output_section->vma
1931 + h->u.def.section->output_offset);
1933 value -= sym_sec->output_section->vma;
1934 value -= (gp - sym_sec->output_section->vma);
1938 case R_V850_TDA_4_4_OFFSET:
1939 case R_V850_TDA_4_5_OFFSET:
1940 case R_V850_TDA_7_7_OFFSET:
1941 case R_V850_TDA_7_8_OFFSET:
1942 case R_V850_TDA_6_8_OFFSET:
1943 case R_V850_TDA_16_16_OFFSET:
1946 struct bfd_link_hash_entry * h;
1948 /* Get the value of __ep. */
1949 h = bfd_link_hash_lookup (info->hash, "__ep", FALSE, FALSE, TRUE);
1951 || h->type != bfd_link_hash_defined)
1952 return bfd_reloc_ep_not_found;
1954 ep = (h->u.def.value
1955 + h->u.def.section->output_section->vma
1956 + h->u.def.section->output_offset);
1962 case R_V850_CALLT_6_7_OFFSET:
1965 struct bfd_link_hash_entry * h;
1967 /* Get the value of __ctbp. */
1968 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
1970 || h->type != bfd_link_hash_defined)
1971 return bfd_reloc_ctbp_not_found;
1973 ctbp = (h->u.def.value
1974 + h->u.def.section->output_section->vma
1975 + h->u.def.section->output_offset);
1980 case R_V850_CALLT_15_16_OFFSET:
1981 case R_V850_CALLT_16_16_OFFSET:
1984 struct bfd_link_hash_entry * h;
1986 if (sym_sec == NULL)
1987 return bfd_reloc_undefined;
1989 /* Get the value of __ctbp. */
1990 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
1992 || h->type != bfd_link_hash_defined)
1993 return bfd_reloc_ctbp_not_found;
1995 ctbp = (h->u.def.value
1996 + h->u.def.section->output_section->vma
1997 + h->u.def.section->output_offset);
1999 value -= sym_sec->output_section->vma;
2000 value -= (ctbp - sym_sec->output_section->vma);
2005 case R_V850_GNU_VTINHERIT:
2006 case R_V850_GNU_VTENTRY:
2007 case R_V850_LONGCALL:
2008 case R_V850_LONGJUMP:
2010 return bfd_reloc_ok;
2013 return bfd_reloc_notsupported;
2016 /* Perform the relocation. */
2017 return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data);
2020 /* Relocate an V850 ELF section. */
2023 v850_elf_relocate_section (bfd *output_bfd,
2024 struct bfd_link_info *info,
2026 asection *input_section,
2028 Elf_Internal_Rela *relocs,
2029 Elf_Internal_Sym *local_syms,
2030 asection **local_sections)
2032 Elf_Internal_Shdr *symtab_hdr;
2033 struct elf_link_hash_entry **sym_hashes;
2034 Elf_Internal_Rela *rel;
2035 Elf_Internal_Rela *relend;
2037 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2038 sym_hashes = elf_sym_hashes (input_bfd);
2040 /* Reset the list of remembered HI16S relocs to empty. */
2041 free_hi16s = previous_hi16s;
2042 previous_hi16s = NULL;
2046 relend = relocs + input_section->reloc_count;
2047 for (; rel < relend; rel++)
2050 reloc_howto_type *howto;
2051 unsigned long r_symndx;
2052 Elf_Internal_Sym *sym;
2054 struct elf_link_hash_entry *h;
2056 bfd_reloc_status_type r;
2058 r_symndx = ELF32_R_SYM (rel->r_info);
2059 r_type = ELF32_R_TYPE (rel->r_info);
2061 if (r_type == R_V850_GNU_VTENTRY
2062 || r_type == R_V850_GNU_VTINHERIT)
2065 howto = v850_elf_howto_table + r_type;
2069 if (r_symndx < symtab_hdr->sh_info)
2071 sym = local_syms + r_symndx;
2072 sec = local_sections[r_symndx];
2073 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2077 bfd_boolean unresolved_reloc, warned;
2079 /* Note - this check is delayed until now as it is possible and
2080 valid to have a file without any symbols but with relocs that
2081 can be processed. */
2082 if (sym_hashes == NULL)
2084 info->callbacks->warning
2085 (info, "no hash table available",
2086 NULL, input_bfd, input_section, (bfd_vma) 0);
2091 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2092 r_symndx, symtab_hdr, sym_hashes,
2094 unresolved_reloc, warned);
2097 if (sec != NULL && discarded_section (sec))
2098 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2099 rel, 1, relend, howto, 0, contents);
2101 if (info->relocatable)
2104 /* FIXME: We should use the addend, but the COFF relocations don't. */
2105 r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
2107 contents, rel->r_offset,
2108 relocation, rel->r_addend,
2109 info, sec, h == NULL);
2111 if (r != bfd_reloc_ok)
2114 const char * msg = NULL;
2117 name = h->root.root.string;
2120 name = (bfd_elf_string_from_elf_section
2121 (input_bfd, symtab_hdr->sh_link, sym->st_name));
2122 if (name == NULL || *name == '\0')
2123 name = bfd_section_name (input_bfd, sec);
2128 case bfd_reloc_overflow:
2129 if (! ((*info->callbacks->reloc_overflow)
2130 (info, (h ? &h->root : NULL), name, howto->name,
2131 (bfd_vma) 0, input_bfd, input_section,
2136 case bfd_reloc_undefined:
2137 if (! ((*info->callbacks->undefined_symbol)
2138 (info, name, input_bfd, input_section,
2139 rel->r_offset, TRUE)))
2143 case bfd_reloc_outofrange:
2144 msg = _("internal error: out of range error");
2147 case bfd_reloc_notsupported:
2148 msg = _("internal error: unsupported relocation error");
2151 case bfd_reloc_dangerous:
2152 msg = _("internal error: dangerous relocation");
2155 case bfd_reloc_gp_not_found:
2156 msg = _("could not locate special linker symbol __gp");
2159 case bfd_reloc_ep_not_found:
2160 msg = _("could not locate special linker symbol __ep");
2163 case bfd_reloc_ctbp_not_found:
2164 msg = _("could not locate special linker symbol __ctbp");
2168 msg = _("internal error: unknown error");
2172 if (!((*info->callbacks->warning)
2173 (info, msg, name, input_bfd, input_section,
2185 v850_elf_gc_mark_hook (asection *sec,
2186 struct bfd_link_info *info,
2187 Elf_Internal_Rela *rel,
2188 struct elf_link_hash_entry *h,
2189 Elf_Internal_Sym *sym)
2192 switch (ELF32_R_TYPE (rel->r_info))
2194 case R_V850_GNU_VTINHERIT:
2195 case R_V850_GNU_VTENTRY:
2199 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2202 /* Set the right machine number. */
2205 v850_elf_object_p (bfd *abfd)
2207 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
2211 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850);
2214 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e);
2217 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e1);
2220 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e2);
2222 case E_V850E2V3_ARCH:
2223 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e2v3);
2229 /* Store the machine number in the flags field. */
2232 v850_elf_final_write_processing (bfd *abfd,
2233 bfd_boolean linker ATTRIBUTE_UNUSED)
2237 switch (bfd_get_mach (abfd))
2240 case bfd_mach_v850: val = E_V850_ARCH; break;
2241 case bfd_mach_v850e: val = E_V850E_ARCH; break;
2242 case bfd_mach_v850e1: val = E_V850E1_ARCH; break;
2243 case bfd_mach_v850e2: val = E_V850E2_ARCH; break;
2244 case bfd_mach_v850e2v3: val = E_V850E2V3_ARCH; break;
2247 elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH;
2248 elf_elfheader (abfd)->e_flags |= val;
2251 /* Function to keep V850 specific file flags. */
2254 v850_elf_set_private_flags (bfd *abfd, flagword flags)
2256 BFD_ASSERT (!elf_flags_init (abfd)
2257 || elf_elfheader (abfd)->e_flags == flags);
2259 elf_elfheader (abfd)->e_flags = flags;
2260 elf_flags_init (abfd) = TRUE;
2264 /* Merge backend specific data from an object file
2265 to the output object file when linking. */
2268 v850_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
2273 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2274 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2277 in_flags = elf_elfheader (ibfd)->e_flags;
2278 out_flags = elf_elfheader (obfd)->e_flags;
2280 if (! elf_flags_init (obfd))
2282 /* If the input is the default architecture then do not
2283 bother setting the flags for the output architecture,
2284 instead allow future merges to do this. If no future
2285 merges ever set these flags then they will retain their
2286 unitialised values, which surprise surprise, correspond
2287 to the default values. */
2288 if (bfd_get_arch_info (ibfd)->the_default)
2291 elf_flags_init (obfd) = TRUE;
2292 elf_elfheader (obfd)->e_flags = in_flags;
2294 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
2295 && bfd_get_arch_info (obfd)->the_default)
2296 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
2301 /* Check flag compatibility. */
2302 if (in_flags == out_flags)
2305 if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
2306 && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
2309 /* Allow v850e1 binaries to be linked with v850e binaries.
2310 Set the output binary to v850e. */
2311 if ((in_flags & EF_V850_ARCH) == E_V850E1_ARCH
2312 && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
2315 if ((in_flags & EF_V850_ARCH) == E_V850_ARCH
2316 && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
2318 elf_elfheader (obfd)->e_flags =
2319 ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH);
2323 if (((in_flags & EF_V850_ARCH) == E_V850_ARCH
2324 || (in_flags & EF_V850_ARCH) == E_V850E_ARCH)
2325 && (out_flags & EF_V850_ARCH) == E_V850E2_ARCH)
2327 elf_elfheader (obfd)->e_flags =
2328 ((out_flags & ~ EF_V850_ARCH) | E_V850E2_ARCH);
2332 if (((in_flags & EF_V850_ARCH) == E_V850_ARCH
2333 || (in_flags & EF_V850_ARCH) == E_V850E_ARCH
2334 || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH)
2335 && (out_flags & EF_V850_ARCH) == E_V850E2V3_ARCH)
2337 elf_elfheader (obfd)->e_flags =
2338 ((out_flags & ~ EF_V850_ARCH) | E_V850E2V3_ARCH);
2342 _bfd_error_handler (_("%B: Architecture mismatch with previous modules"),
2349 /* Display the flags field. */
2352 v850_elf_print_private_bfd_data (bfd *abfd, void * ptr)
2354 FILE * file = (FILE *) ptr;
2356 BFD_ASSERT (abfd != NULL && ptr != NULL);
2358 _bfd_elf_print_private_bfd_data (abfd, ptr);
2360 /* xgettext:c-format. */
2361 fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags);
2363 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
2366 case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
2367 case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break;
2368 case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break;
2369 case E_V850E2_ARCH: fprintf (file, _("v850e2 architecture")); break;
2370 case E_V850E2V3_ARCH: fprintf (file, _("v850e2v3 architecture")); break;
2378 /* V850 ELF uses four common sections. One is the usual one, and the
2379 others are for (small) objects in one of the special data areas:
2380 small, tiny and zero. All the objects are kept together, and then
2381 referenced via the gp register, the ep register or the r0 register
2382 respectively, which yields smaller, faster assembler code. This
2383 approach is copied from elf32-mips.c. */
2385 static asection v850_elf_scom_section;
2386 static asymbol v850_elf_scom_symbol;
2387 static asymbol * v850_elf_scom_symbol_ptr;
2388 static asection v850_elf_tcom_section;
2389 static asymbol v850_elf_tcom_symbol;
2390 static asymbol * v850_elf_tcom_symbol_ptr;
2391 static asection v850_elf_zcom_section;
2392 static asymbol v850_elf_zcom_symbol;
2393 static asymbol * v850_elf_zcom_symbol_ptr;
2395 /* Given a BFD section, try to locate the
2396 corresponding ELF section index. */
2399 v850_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
2403 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
2404 *retval = SHN_V850_SCOMMON;
2405 else if (strcmp (bfd_get_section_name (abfd, sec), ".tcommon") == 0)
2406 *retval = SHN_V850_TCOMMON;
2407 else if (strcmp (bfd_get_section_name (abfd, sec), ".zcommon") == 0)
2408 *retval = SHN_V850_ZCOMMON;
2415 /* Handle the special V850 section numbers that a symbol may use. */
2418 v850_elf_symbol_processing (bfd *abfd, asymbol *asym)
2420 elf_symbol_type * elfsym = (elf_symbol_type *) asym;
2423 indx = elfsym->internal_elf_sym.st_shndx;
2425 /* If the section index is an "ordinary" index, then it may
2426 refer to a v850 specific section created by the assembler.
2427 Check the section's type and change the index it matches.
2429 FIXME: Should we alter the st_shndx field as well ? */
2431 if (indx < elf_numsections (abfd))
2432 switch (elf_elfsections (abfd)[indx]->sh_type)
2434 case SHT_V850_SCOMMON:
2435 indx = SHN_V850_SCOMMON;
2438 case SHT_V850_TCOMMON:
2439 indx = SHN_V850_TCOMMON;
2442 case SHT_V850_ZCOMMON:
2443 indx = SHN_V850_ZCOMMON;
2452 case SHN_V850_SCOMMON:
2453 if (v850_elf_scom_section.name == NULL)
2455 /* Initialize the small common section. */
2456 v850_elf_scom_section.name = ".scommon";
2457 v850_elf_scom_section.flags = SEC_IS_COMMON | SEC_ALLOC | SEC_DATA;
2458 v850_elf_scom_section.output_section = & v850_elf_scom_section;
2459 v850_elf_scom_section.symbol = & v850_elf_scom_symbol;
2460 v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr;
2461 v850_elf_scom_symbol.name = ".scommon";
2462 v850_elf_scom_symbol.flags = BSF_SECTION_SYM;
2463 v850_elf_scom_symbol.section = & v850_elf_scom_section;
2464 v850_elf_scom_symbol_ptr = & v850_elf_scom_symbol;
2466 asym->section = & v850_elf_scom_section;
2467 asym->value = elfsym->internal_elf_sym.st_size;
2470 case SHN_V850_TCOMMON:
2471 if (v850_elf_tcom_section.name == NULL)
2473 /* Initialize the tcommon section. */
2474 v850_elf_tcom_section.name = ".tcommon";
2475 v850_elf_tcom_section.flags = SEC_IS_COMMON;
2476 v850_elf_tcom_section.output_section = & v850_elf_tcom_section;
2477 v850_elf_tcom_section.symbol = & v850_elf_tcom_symbol;
2478 v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr;
2479 v850_elf_tcom_symbol.name = ".tcommon";
2480 v850_elf_tcom_symbol.flags = BSF_SECTION_SYM;
2481 v850_elf_tcom_symbol.section = & v850_elf_tcom_section;
2482 v850_elf_tcom_symbol_ptr = & v850_elf_tcom_symbol;
2484 asym->section = & v850_elf_tcom_section;
2485 asym->value = elfsym->internal_elf_sym.st_size;
2488 case SHN_V850_ZCOMMON:
2489 if (v850_elf_zcom_section.name == NULL)
2491 /* Initialize the zcommon section. */
2492 v850_elf_zcom_section.name = ".zcommon";
2493 v850_elf_zcom_section.flags = SEC_IS_COMMON;
2494 v850_elf_zcom_section.output_section = & v850_elf_zcom_section;
2495 v850_elf_zcom_section.symbol = & v850_elf_zcom_symbol;
2496 v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr;
2497 v850_elf_zcom_symbol.name = ".zcommon";
2498 v850_elf_zcom_symbol.flags = BSF_SECTION_SYM;
2499 v850_elf_zcom_symbol.section = & v850_elf_zcom_section;
2500 v850_elf_zcom_symbol_ptr = & v850_elf_zcom_symbol;
2502 asym->section = & v850_elf_zcom_section;
2503 asym->value = elfsym->internal_elf_sym.st_size;
2508 /* Hook called by the linker routine which adds symbols from an object
2509 file. We must handle the special v850 section numbers here. */
2512 v850_elf_add_symbol_hook (bfd *abfd,
2513 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2514 Elf_Internal_Sym *sym,
2515 const char **namep ATTRIBUTE_UNUSED,
2516 flagword *flagsp ATTRIBUTE_UNUSED,
2520 unsigned int indx = sym->st_shndx;
2522 /* If the section index is an "ordinary" index, then it may
2523 refer to a v850 specific section created by the assembler.
2524 Check the section's type and change the index it matches.
2526 FIXME: Should we alter the st_shndx field as well ? */
2528 if (indx < elf_numsections (abfd))
2529 switch (elf_elfsections (abfd)[indx]->sh_type)
2531 case SHT_V850_SCOMMON:
2532 indx = SHN_V850_SCOMMON;
2535 case SHT_V850_TCOMMON:
2536 indx = SHN_V850_TCOMMON;
2539 case SHT_V850_ZCOMMON:
2540 indx = SHN_V850_ZCOMMON;
2549 case SHN_V850_SCOMMON:
2550 *secp = bfd_make_section_old_way (abfd, ".scommon");
2551 (*secp)->flags |= SEC_IS_COMMON;
2552 *valp = sym->st_size;
2555 case SHN_V850_TCOMMON:
2556 *secp = bfd_make_section_old_way (abfd, ".tcommon");
2557 (*secp)->flags |= SEC_IS_COMMON;
2558 *valp = sym->st_size;
2561 case SHN_V850_ZCOMMON:
2562 *secp = bfd_make_section_old_way (abfd, ".zcommon");
2563 (*secp)->flags |= SEC_IS_COMMON;
2564 *valp = sym->st_size;
2572 v850_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2573 const char *name ATTRIBUTE_UNUSED,
2574 Elf_Internal_Sym *sym,
2575 asection *input_sec,
2576 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2578 /* If we see a common symbol, which implies a relocatable link, then
2579 if a symbol was in a special common section in an input file, mark
2580 it as a special common in the output file. */
2582 if (sym->st_shndx == SHN_COMMON)
2584 if (strcmp (input_sec->name, ".scommon") == 0)
2585 sym->st_shndx = SHN_V850_SCOMMON;
2586 else if (strcmp (input_sec->name, ".tcommon") == 0)
2587 sym->st_shndx = SHN_V850_TCOMMON;
2588 else if (strcmp (input_sec->name, ".zcommon") == 0)
2589 sym->st_shndx = SHN_V850_ZCOMMON;
2592 /* The price we pay for using h->other unused bits as flags in the
2593 linker is cleaning up after ourselves. */
2595 sym->st_other &= ~(V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA
2596 | V850_OTHER_ERROR);
2602 v850_elf_section_from_shdr (bfd *abfd,
2603 Elf_Internal_Shdr *hdr,
2607 /* There ought to be a place to keep ELF backend specific flags, but
2608 at the moment there isn't one. We just keep track of the
2609 sections by their name, instead. */
2611 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
2614 switch (hdr->sh_type)
2616 case SHT_V850_SCOMMON:
2617 case SHT_V850_TCOMMON:
2618 case SHT_V850_ZCOMMON:
2619 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2620 (bfd_get_section_flags (abfd,
2629 /* Set the correct type for a V850 ELF section. We do this
2630 by the section name, which is a hack, but ought to work. */
2633 v850_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2634 Elf_Internal_Shdr *hdr,
2639 name = bfd_get_section_name (abfd, sec);
2641 if (strcmp (name, ".scommon") == 0)
2642 hdr->sh_type = SHT_V850_SCOMMON;
2643 else if (strcmp (name, ".tcommon") == 0)
2644 hdr->sh_type = SHT_V850_TCOMMON;
2645 else if (strcmp (name, ".zcommon") == 0)
2646 hdr->sh_type = SHT_V850_ZCOMMON;
2651 /* Delete some bytes from a section while relaxing. */
2654 v850_elf_relax_delete_bytes (bfd *abfd,
2660 Elf_Internal_Shdr *symtab_hdr;
2661 Elf32_External_Sym *extsyms;
2662 Elf32_External_Sym *esym;
2663 Elf32_External_Sym *esymend;
2665 unsigned int sec_shndx;
2667 Elf_Internal_Rela *irel;
2668 Elf_Internal_Rela *irelend;
2669 struct elf_link_hash_entry *sym_hash;
2670 Elf_Internal_Shdr *shndx_hdr;
2671 Elf_External_Sym_Shndx *shndx;
2673 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2674 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
2676 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2678 contents = elf_section_data (sec)->this_hdr.contents;
2680 /* The deletion must stop at the next ALIGN reloc for an alignment
2681 power larger than the number of bytes we are deleting. */
2683 /* Actually delete the bytes. */
2684 #if (DEBUG_RELAX & 2)
2685 fprintf (stderr, "relax_delete: contents: sec: %s %p .. %p %x\n",
2686 sec->name, addr, toaddr, count );
2688 memmove (contents + addr, contents + addr + count,
2689 toaddr - addr - count);
2690 memset (contents + toaddr-count, 0, count);
2692 /* Adjust all the relocs. */
2693 irel = elf_section_data (sec)->relocs;
2694 irelend = irel + sec->reloc_count;
2695 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
2696 shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
2698 for (; irel < irelend; irel++)
2700 bfd_vma raddr, paddr, symval;
2701 Elf_Internal_Sym isym;
2703 /* Get the new reloc address. */
2704 raddr = irel->r_offset;
2705 if ((raddr >= (addr + count) && raddr < toaddr))
2706 irel->r_offset -= count;
2708 if (raddr >= addr && raddr < addr + count)
2710 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2715 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
2718 bfd_elf32_swap_symbol_in (abfd,
2719 extsyms + ELF32_R_SYM (irel->r_info),
2720 shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
2723 if (isym.st_shndx != sec_shndx)
2726 /* Get the value of the symbol referred to by the reloc. */
2727 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2729 symval = isym.st_value;
2730 #if (DEBUG_RELAX & 2)
2732 char * name = bfd_elf_string_from_elf_section
2733 (abfd, symtab_hdr->sh_link, isym.st_name);
2735 "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
2736 sec->name, name, isym.st_name,
2737 sec->output_section->vma, sec->output_offset,
2738 isym.st_value, irel->r_addend);
2745 struct elf_link_hash_entry * h;
2747 /* An external symbol. */
2748 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2750 h = elf_sym_hashes (abfd) [indx];
2751 BFD_ASSERT (h != NULL);
2753 symval = h->root.u.def.value;
2754 #if (DEBUG_RELAX & 2)
2756 "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
2757 sec->name, h->root.root.string, h->root.u.def.value,
2758 sec->output_section->vma, sec->output_offset, irel->r_addend);
2762 paddr = symval + irel->r_addend;
2764 if ( (symval >= addr + count && symval < toaddr)
2765 && (paddr < addr + count || paddr >= toaddr))
2766 irel->r_addend += count;
2767 else if ( (symval < addr + count || symval >= toaddr)
2768 && (paddr >= addr + count && paddr < toaddr))
2769 irel->r_addend -= count;
2772 /* Adjust the local symbols defined in this section. */
2774 esymend = esym + symtab_hdr->sh_info;
2776 for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
2778 Elf_Internal_Sym isym;
2780 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2782 if (isym.st_shndx == sec_shndx
2783 && isym.st_value >= addr + count
2784 && isym.st_value < toaddr)
2786 isym.st_value -= count;
2788 if (isym.st_value + isym.st_size >= toaddr)
2789 isym.st_size += count;
2791 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2793 else if (isym.st_shndx == sec_shndx
2794 && isym.st_value < addr + count)
2796 if (isym.st_value+isym.st_size >= addr + count
2797 && isym.st_value+isym.st_size < toaddr)
2798 isym.st_size -= count;
2800 if (isym.st_value >= addr
2801 && isym.st_value < addr + count)
2802 isym.st_value = addr;
2804 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2808 /* Now adjust the global symbols defined in this section. */
2809 esym = extsyms + symtab_hdr->sh_info;
2810 esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
2812 for (sym_index = 0; esym < esymend; esym ++, sym_index ++)
2814 Elf_Internal_Sym isym;
2816 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2817 sym_hash = elf_sym_hashes (abfd) [sym_index];
2819 if (isym.st_shndx == sec_shndx
2820 && ((sym_hash)->root.type == bfd_link_hash_defined
2821 || (sym_hash)->root.type == bfd_link_hash_defweak)
2822 && (sym_hash)->root.u.def.section == sec
2823 && (sym_hash)->root.u.def.value >= addr + count
2824 && (sym_hash)->root.u.def.value < toaddr)
2826 if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
2828 isym.st_size += count;
2829 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2832 (sym_hash)->root.u.def.value -= count;
2834 else if (isym.st_shndx == sec_shndx
2835 && ((sym_hash)->root.type == bfd_link_hash_defined
2836 || (sym_hash)->root.type == bfd_link_hash_defweak)
2837 && (sym_hash)->root.u.def.section == sec
2838 && (sym_hash)->root.u.def.value < addr + count)
2840 if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
2841 && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
2842 isym.st_size -= count;
2844 if ((sym_hash)->root.u.def.value >= addr
2845 && (sym_hash)->root.u.def.value < addr + count)
2846 (sym_hash)->root.u.def.value = addr;
2848 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2858 #define NOP_OPCODE (0x0000)
2859 #define MOVHI 0x0640 /* 4byte. */
2860 #define MOVHI_MASK 0x07e0
2861 #define MOVHI_R1(insn) ((insn) & 0x1f) /* 4byte. */
2862 #define MOVHI_R2(insn) ((insn) >> 11)
2863 #define MOVEA 0x0620 /* 2byte. */
2864 #define MOVEA_MASK 0x07e0
2865 #define MOVEA_R1(insn) ((insn) & 0x1f)
2866 #define MOVEA_R2(insn) ((insn) >> 11)
2867 #define JARL_4 0x00040780 /* 4byte. */
2868 #define JARL_4_MASK 0xFFFF07FF
2869 #define JARL_R2(insn) (int)(((insn) & (~JARL_4_MASK)) >> 11)
2870 #define ADD_I 0x0240 /* 2byte. */
2871 #define ADD_I_MASK 0x07e0
2872 #define ADD_I5(insn) ((((insn) & 0x001f) << 11) >> 11) /* 2byte. */
2873 #define ADD_R2(insn) ((insn) >> 11)
2874 #define JMP_R 0x0060 /* 2byte. */
2875 #define JMP_R_MASK 0xFFE0
2876 #define JMP_R1(insn) ((insn) & 0x1f)
2879 v850_elf_relax_section (bfd *abfd,
2881 struct bfd_link_info *link_info,
2884 Elf_Internal_Shdr *symtab_hdr;
2885 Elf_Internal_Rela *internal_relocs;
2886 Elf_Internal_Rela *irel;
2887 Elf_Internal_Rela *irelend;
2888 Elf_Internal_Rela *irelalign = NULL;
2889 Elf_Internal_Sym *isymbuf = NULL;
2890 bfd_byte *contents = NULL;
2893 int align_pad_size = 0;
2894 bfd_boolean result = TRUE;
2898 if (link_info->relocatable
2899 || (sec->flags & SEC_RELOC) == 0
2900 || sec->reloc_count == 0)
2903 symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
2905 internal_relocs = (_bfd_elf_link_read_relocs
2906 (abfd, sec, NULL, NULL, link_info->keep_memory));
2907 if (internal_relocs == NULL)
2910 irelend = internal_relocs + sec->reloc_count;
2912 while (addr < sec->size)
2916 for (irel = internal_relocs; irel < irelend; irel ++)
2917 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
2918 && irel->r_offset > addr
2919 && irel->r_offset < toaddr)
2920 toaddr = irel->r_offset;
2923 fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
2924 addr, toaddr, align_pad_size);
2929 bfd_vma alignmoveto;
2931 alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
2932 alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
2934 if (alignmoveto < alignto)
2938 align_pad_size = alignto - alignmoveto;
2940 fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
2941 alignmoveto, toaddr, align_pad_size);
2943 if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
2944 toaddr, align_pad_size))
2947 for (i = BFD_ALIGN (toaddr - align_pad_size, 1);
2948 (i + 1) < toaddr; i += 2)
2949 bfd_put_16 (abfd, NOP_OPCODE, contents + i);
2957 for (irel = internal_relocs; irel < irelend; irel++)
2964 Elf_Internal_Rela *hi_irelfn;
2965 Elf_Internal_Rela *lo_irelfn;
2966 Elf_Internal_Rela *irelcall;
2967 bfd_signed_vma foff;
2969 if (! (irel->r_offset >= addr && irel->r_offset < toaddr
2970 && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
2971 || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
2975 fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
2981 /* Get the section contents. */
2982 if (contents == NULL)
2984 if (elf_section_data (sec)->this_hdr.contents != NULL)
2985 contents = elf_section_data (sec)->this_hdr.contents;
2988 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2993 /* Read this BFD's local symbols if we haven't done so already. */
2994 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2996 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2997 if (isymbuf == NULL)
2998 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2999 symtab_hdr->sh_info, 0,
3001 if (isymbuf == NULL)
3005 laddr = irel->r_offset;
3007 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
3009 /* Check code for -mlong-calls output. */
3010 if (laddr + 16 <= (bfd_vma) sec->size)
3012 insn[0] = bfd_get_16 (abfd, contents + laddr);
3013 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
3014 insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
3015 insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
3016 insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
3018 if ((insn[0] & MOVHI_MASK) != MOVHI
3019 || MOVHI_R1 (insn[0]) != 0)
3023 && ((insn[1] & MOVEA_MASK) != MOVEA
3024 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
3028 && (insn[2] & JARL_4_MASK) != JARL_4)
3032 && ((insn[3] & ADD_I_MASK) != ADD_I
3033 || ADD_I5 (insn[3]) != 4
3034 || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
3038 && ((insn[4] & JMP_R_MASK) != JMP_R
3039 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
3044 ((*_bfd_error_handler)
3045 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insns",
3046 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
3053 ((*_bfd_error_handler)
3054 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insn 0x%x",
3055 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
3060 /* Get the reloc for the address from which the register is
3061 being loaded. This reloc will tell us which function is
3062 actually being called. */
3063 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
3064 if (hi_irelfn->r_offset == laddr + 2
3065 && ELF32_R_TYPE (hi_irelfn->r_info)
3066 == (int) R_V850_HI16_S)
3069 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
3070 if (lo_irelfn->r_offset == laddr + 6
3071 && ELF32_R_TYPE (lo_irelfn->r_info)
3072 == (int) R_V850_LO16)
3075 for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
3076 if (irelcall->r_offset == laddr + 8
3077 && ELF32_R_TYPE (irelcall->r_info)
3078 == (int) R_V850_22_PCREL)
3081 if ( hi_irelfn == irelend
3082 || lo_irelfn == irelend
3083 || irelcall == irelend)
3085 ((*_bfd_error_handler)
3086 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc",
3087 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
3092 if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
3094 Elf_Internal_Sym * isym;
3096 /* A local symbol. */
3097 isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
3099 symval = isym->st_value;
3104 struct elf_link_hash_entry * h;
3106 /* An external symbol. */
3107 indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
3108 h = elf_sym_hashes (abfd)[indx];
3109 BFD_ASSERT (h != NULL);
3111 if ( h->root.type != bfd_link_hash_defined
3112 && h->root.type != bfd_link_hash_defweak)
3113 /* This appears to be a reference to an undefined
3114 symbol. Just ignore it--it will be caught by the
3115 regular reloc processing. */
3118 symval = h->root.u.def.value;
3121 if (symval + irelcall->r_addend != irelcall->r_offset + 4)
3123 ((*_bfd_error_handler)
3124 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc 0x%lx",
3125 bfd_get_filename (abfd), (unsigned long) irel->r_offset, irelcall->r_offset ));
3130 /* Get the value of the symbol referred to by the reloc. */
3131 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3133 Elf_Internal_Sym *isym;
3136 /* A local symbol. */
3137 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
3139 if (isym->st_shndx == SHN_UNDEF)
3140 sym_sec = bfd_und_section_ptr;
3141 else if (isym->st_shndx == SHN_ABS)
3142 sym_sec = bfd_abs_section_ptr;
3143 else if (isym->st_shndx == SHN_COMMON)
3144 sym_sec = bfd_com_section_ptr;
3146 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3147 symval = (isym->st_value
3148 + sym_sec->output_section->vma
3149 + sym_sec->output_offset);
3154 struct elf_link_hash_entry *h;
3156 /* An external symbol. */
3157 indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
3158 h = elf_sym_hashes (abfd)[indx];
3159 BFD_ASSERT (h != NULL);
3161 if ( h->root.type != bfd_link_hash_defined
3162 && h->root.type != bfd_link_hash_defweak)
3163 /* This appears to be a reference to an undefined
3164 symbol. Just ignore it--it will be caught by the
3165 regular reloc processing. */
3168 symval = (h->root.u.def.value
3169 + h->root.u.def.section->output_section->vma
3170 + h->root.u.def.section->output_offset);
3173 addend = irel->r_addend;
3175 foff = (symval + addend
3177 + sec->output_section->vma
3178 + sec->output_offset
3181 fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
3184 + sec->output_section->vma
3185 + sec->output_offset),
3186 symval, addend, foff);
3189 if (foff < -0x100000 || foff >= 0x100000)
3190 /* After all that work, we can't shorten this function call. */
3193 /* For simplicity of coding, we are going to modify the section
3194 contents, the section relocs, and the BFD symbol table. We
3195 must tell the rest of the code not to free up this
3196 information. It would be possible to instead create a table
3197 of changes which have to be made, as is done in coff-mips.c;
3198 that would be more work, but would require less memory when
3199 the linker is run. */
3200 elf_section_data (sec)->relocs = internal_relocs;
3201 elf_section_data (sec)->this_hdr.contents = contents;
3202 symtab_hdr->contents = (bfd_byte *) isymbuf;
3204 /* Replace the long call with a jarl. */
3205 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
3209 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3210 /* If this needs to be changed because of future relaxing,
3211 it will be handled here like other internal IND12W
3214 0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
3215 contents + irel->r_offset);
3217 /* We can't fully resolve this yet, because the external
3218 symbol value may be changed by future relaxing.
3219 We let the final link phase handle it. */
3220 bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
3221 contents + irel->r_offset);
3224 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
3226 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
3228 ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
3230 if (! v850_elf_relax_delete_bytes (abfd, sec,
3231 irel->r_offset + 4, toaddr, 12))
3234 align_pad_size += 12;
3236 else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
3238 /* Check code for -mlong-jumps output. */
3239 if (laddr + 10 <= (bfd_vma) sec->size)
3241 insn[0] = bfd_get_16 (abfd, contents + laddr);
3242 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
3243 insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
3245 if ((insn[0] & MOVHI_MASK) != MOVHI
3246 || MOVHI_R1 (insn[0]) != 0)
3250 && ((insn[1] & MOVEA_MASK) != MOVEA
3251 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
3255 && ((insn[2] & JMP_R_MASK) != JMP_R
3256 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
3261 ((*_bfd_error_handler)
3262 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insns",
3263 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
3270 ((*_bfd_error_handler)
3271 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insn 0x%x",
3272 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
3277 /* Get the reloc for the address from which the register is
3278 being loaded. This reloc will tell us which function is
3279 actually being called. */
3280 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
3281 if (hi_irelfn->r_offset == laddr + 2
3282 && ELF32_R_TYPE (hi_irelfn->r_info) == (int) R_V850_HI16_S)
3285 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
3286 if (lo_irelfn->r_offset == laddr + 6
3287 && ELF32_R_TYPE (lo_irelfn->r_info) == (int) R_V850_LO16)
3290 if ( hi_irelfn == irelend
3291 || lo_irelfn == irelend)
3293 ((*_bfd_error_handler)
3294 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized reloc",
3295 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
3300 /* Get the value of the symbol referred to by the reloc. */
3301 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3303 Elf_Internal_Sym * isym;
3306 /* A local symbol. */
3307 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
3309 if (isym->st_shndx == SHN_UNDEF)
3310 sym_sec = bfd_und_section_ptr;
3311 else if (isym->st_shndx == SHN_ABS)
3312 sym_sec = bfd_abs_section_ptr;
3313 else if (isym->st_shndx == SHN_COMMON)
3314 sym_sec = bfd_com_section_ptr;
3316 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3317 symval = (isym->st_value
3318 + sym_sec->output_section->vma
3319 + sym_sec->output_offset);
3322 char * name = bfd_elf_string_from_elf_section
3323 (abfd, symtab_hdr->sh_link, isym->st_name);
3325 fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
3326 sym_sec->name, name, isym->st_name,
3327 sym_sec->output_section->vma,
3328 sym_sec->output_offset,
3329 isym->st_value, irel->r_addend);
3336 struct elf_link_hash_entry * h;
3338 /* An external symbol. */
3339 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
3340 h = elf_sym_hashes (abfd)[indx];
3341 BFD_ASSERT (h != NULL);
3343 if ( h->root.type != bfd_link_hash_defined
3344 && h->root.type != bfd_link_hash_defweak)
3345 /* This appears to be a reference to an undefined
3346 symbol. Just ignore it--it will be caught by the
3347 regular reloc processing. */
3350 symval = (h->root.u.def.value
3351 + h->root.u.def.section->output_section->vma
3352 + h->root.u.def.section->output_offset);
3355 "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
3356 sec->name, h->root.root.string, h->root.u.def.value,
3357 sec->output_section->vma, sec->output_offset, irel->r_addend);
3361 addend = irel->r_addend;
3363 foff = (symval + addend
3365 + sec->output_section->vma
3366 + sec->output_offset
3369 fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
3372 + sec->output_section->vma
3373 + sec->output_offset),
3374 symval, addend, foff);
3376 if (foff < -0x100000 || foff >= 0x100000)
3377 /* After all that work, we can't shorten this function call. */
3380 /* For simplicity of coding, we are going to modify the section
3381 contents, the section relocs, and the BFD symbol table. We
3382 must tell the rest of the code not to free up this
3383 information. It would be possible to instead create a table
3384 of changes which have to be made, as is done in coff-mips.c;
3385 that would be more work, but would require less memory when
3386 the linker is run. */
3387 elf_section_data (sec)->relocs = internal_relocs;
3388 elf_section_data (sec)->this_hdr.contents = contents;
3389 symtab_hdr->contents = (bfd_byte *) isymbuf;
3391 if (foff < -0x100 || foff >= 0x100)
3393 /* Replace the long jump with a jr. */
3396 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
3398 irel->r_addend = addend;
3401 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3402 /* If this needs to be changed because of future relaxing,
3403 it will be handled here like other internal IND12W
3406 0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
3407 contents + irel->r_offset);
3409 /* We can't fully resolve this yet, because the external
3410 symbol value may be changed by future relaxing.
3411 We let the final link phase handle it. */
3412 bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
3415 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
3417 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
3418 if (!v850_elf_relax_delete_bytes (abfd, sec,
3419 irel->r_offset + 4, toaddr, 6))
3422 align_pad_size += 6;
3426 /* Replace the long jump with a br. */
3429 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
3431 irel->r_addend = addend;
3434 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
3435 /* If this needs to be changed because of future relaxing,
3436 it will be handled here like other internal IND12W
3439 0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
3440 contents + irel->r_offset);
3442 /* We can't fully resolve this yet, because the external
3443 symbol value may be changed by future relaxing.
3444 We let the final link phase handle it. */
3445 bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
3448 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
3450 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
3451 if (!v850_elf_relax_delete_bytes (abfd, sec,
3452 irel->r_offset + 2, toaddr, 8))
3455 align_pad_size += 8;
3461 for (irel = internal_relocs; irel < irelend; irel++)
3463 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
3464 && irel->r_offset == toaddr)
3466 irel->r_offset -= align_pad_size;
3468 if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
3479 fprintf (stderr, "relax pad %d shorten %d -> %d\n",
3482 sec->size - align_pad_size);
3484 sec->size -= align_pad_size;
3488 if (internal_relocs != NULL
3489 && elf_section_data (sec)->relocs != internal_relocs)
3490 free (internal_relocs);
3492 if (contents != NULL
3493 && elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
3497 && symtab_hdr->contents != (bfd_byte *) isymbuf)
3507 static const struct bfd_elf_special_section v850_elf_special_sections[] =
3509 { STRING_COMMA_LEN (".call_table_data"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE) },
3510 { STRING_COMMA_LEN (".call_table_text"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3512 { STRING_COMMA_LEN (".rosdata"), -2, SHT_PROGBITS, (SHF_ALLOC
3513 + SHF_V850_GPREL) },
3514 { STRING_COMMA_LEN (".rozdata"), -2, SHT_PROGBITS, (SHF_ALLOC
3515 + SHF_V850_R0REL) },
3516 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3517 + SHF_V850_GPREL) },
3518 { STRING_COMMA_LEN (".scommon"), -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE
3519 + SHF_V850_GPREL) },
3520 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3521 + SHF_V850_GPREL) },
3522 { STRING_COMMA_LEN (".tbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3523 + SHF_V850_EPREL) },
3524 { STRING_COMMA_LEN (".tcommon"), -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE
3525 + SHF_V850_R0REL) },
3526 { STRING_COMMA_LEN (".tdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3527 + SHF_V850_EPREL) },
3528 { STRING_COMMA_LEN (".zbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3529 + SHF_V850_R0REL) },
3530 { STRING_COMMA_LEN (".zcommon"), -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE
3531 + SHF_V850_R0REL) },
3532 { STRING_COMMA_LEN (".zdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3533 + SHF_V850_R0REL) },
3534 { NULL, 0, 0, 0, 0 }
3537 #define TARGET_LITTLE_SYM bfd_elf32_v850_vec
3538 #define TARGET_LITTLE_NAME "elf32-v850"
3539 #define ELF_ARCH bfd_arch_v850
3540 #define ELF_MACHINE_CODE EM_V850
3541 #define ELF_MACHINE_ALT1 EM_CYGNUS_V850
3542 #define ELF_MACHINE_ALT2 EM_V800 /* This is the value used by the GreenHills toolchain. */
3543 #define ELF_MAXPAGESIZE 0x1000
3545 #define elf_info_to_howto v850_elf_info_to_howto_rela
3546 #define elf_info_to_howto_rel v850_elf_info_to_howto_rel
3548 #define elf_backend_check_relocs v850_elf_check_relocs
3549 #define elf_backend_relocate_section v850_elf_relocate_section
3550 #define elf_backend_object_p v850_elf_object_p
3551 #define elf_backend_final_write_processing v850_elf_final_write_processing
3552 #define elf_backend_section_from_bfd_section v850_elf_section_from_bfd_section
3553 #define elf_backend_symbol_processing v850_elf_symbol_processing
3554 #define elf_backend_add_symbol_hook v850_elf_add_symbol_hook
3555 #define elf_backend_link_output_symbol_hook v850_elf_link_output_symbol_hook
3556 #define elf_backend_section_from_shdr v850_elf_section_from_shdr
3557 #define elf_backend_fake_sections v850_elf_fake_sections
3558 #define elf_backend_gc_mark_hook v850_elf_gc_mark_hook
3559 #define elf_backend_special_sections v850_elf_special_sections
3561 #define elf_backend_can_gc_sections 1
3562 #define elf_backend_rela_normal 1
3564 #define bfd_elf32_bfd_is_local_label_name v850_elf_is_local_label_name
3565 #define bfd_elf32_bfd_reloc_type_lookup v850_elf_reloc_type_lookup
3566 #define bfd_elf32_bfd_reloc_name_lookup v850_elf_reloc_name_lookup
3567 #define bfd_elf32_bfd_merge_private_bfd_data v850_elf_merge_private_bfd_data
3568 #define bfd_elf32_bfd_set_private_flags v850_elf_set_private_flags
3569 #define bfd_elf32_bfd_print_private_bfd_data v850_elf_print_private_bfd_data
3570 #define bfd_elf32_bfd_relax_section v850_elf_relax_section
3572 #define elf_symbol_leading_char '_'
3574 #include "elf32-target.h"