1 /* V850-specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
23 dependencies. As is the gas & simulator code for the v850. */
31 #include "libiberty.h"
33 /* Sign-extend a 24-bit number. */
34 #define SEXT24(x) ((((x) & 0xffffff) ^ 0x800000) - 0x800000)
36 static reloc_howto_type v850_elf_howto_table[];
38 /* Look through the relocs for a section during the first phase, and
39 allocate space in the global offset table or procedure linkage
43 v850_elf_check_relocs (bfd *abfd,
44 struct bfd_link_info *info,
46 const Elf_Internal_Rela *relocs)
48 bfd_boolean ret = TRUE;
50 Elf_Internal_Shdr *symtab_hdr;
51 struct elf_link_hash_entry **sym_hashes;
52 const Elf_Internal_Rela *rel;
53 const Elf_Internal_Rela *rel_end;
55 enum v850_reloc_type r_type;
57 const char *common = NULL;
59 if (info->relocatable)
63 _bfd_error_handler ("v850_elf_check_relocs called for section %A in %B",
67 dynobj = elf_hash_table (info)->dynobj;
68 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
69 sym_hashes = elf_sym_hashes (abfd);
72 rel_end = relocs + sec->reloc_count;
73 for (rel = relocs; rel < rel_end; rel++)
75 unsigned long r_symndx;
76 struct elf_link_hash_entry *h;
78 r_symndx = ELF32_R_SYM (rel->r_info);
79 if (r_symndx < symtab_hdr->sh_info)
83 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
84 while (h->root.type == bfd_link_hash_indirect
85 || h->root.type == bfd_link_hash_warning)
86 h = (struct elf_link_hash_entry *) h->root.u.i.link;
89 r_type = (enum v850_reloc_type) ELF32_R_TYPE (rel->r_info);
99 case R_V850_LO16_SPLIT_OFFSET:
104 case R_V850_CALLT_6_7_OFFSET:
105 case R_V850_CALLT_16_16_OFFSET:
108 /* This relocation describes the C++ object vtable hierarchy.
109 Reconstruct it for later use during GC. */
110 case R_V850_GNU_VTINHERIT:
111 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
115 /* This relocation describes which C++ vtable entries
116 are actually used. Record for later use during GC. */
117 case R_V850_GNU_VTENTRY:
118 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
122 case R_V850_SDA_16_16_SPLIT_OFFSET:
123 case R_V850_SDA_16_16_OFFSET:
124 case R_V850_SDA_15_16_OFFSET:
125 other = V850_OTHER_SDA;
127 goto small_data_common;
129 case R_V850_ZDA_16_16_SPLIT_OFFSET:
130 case R_V850_ZDA_16_16_OFFSET:
131 case R_V850_ZDA_15_16_OFFSET:
132 other = V850_OTHER_ZDA;
134 goto small_data_common;
136 case R_V850_TDA_4_5_OFFSET:
137 case R_V850_TDA_4_4_OFFSET:
138 case R_V850_TDA_6_8_OFFSET:
139 case R_V850_TDA_7_8_OFFSET:
140 case R_V850_TDA_7_7_OFFSET:
141 case R_V850_TDA_16_16_OFFSET:
142 other = V850_OTHER_TDA;
146 #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
151 /* Flag which type of relocation was used. */
153 if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
154 && (h->other & V850_OTHER_ERROR) == 0)
157 static char buff[200]; /* XXX */
159 switch (h->other & V850_OTHER_MASK)
162 msg = _("Variable `%s' cannot occupy in multiple small data regions");
164 case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
165 msg = _("Variable `%s' can only be in one of the small, zero, and tiny data regions");
167 case V850_OTHER_SDA | V850_OTHER_ZDA:
168 msg = _("Variable `%s' cannot be in both small and zero data regions simultaneously");
170 case V850_OTHER_SDA | V850_OTHER_TDA:
171 msg = _("Variable `%s' cannot be in both small and tiny data regions simultaneously");
173 case V850_OTHER_ZDA | V850_OTHER_TDA:
174 msg = _("Variable `%s' cannot be in both zero and tiny data regions simultaneously");
178 sprintf (buff, msg, h->root.root.string);
179 info->callbacks->warning (info, buff, h->root.root.string,
180 abfd, h->root.u.def.section,
183 bfd_set_error (bfd_error_bad_value);
184 h->other |= V850_OTHER_ERROR;
189 if (h && h->root.type == bfd_link_hash_common
191 && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON"))
195 section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
196 section->flags |= SEC_IS_COMMON;
200 fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
201 v850_elf_howto_table[ (int)r_type ].name,
202 (h && h->root.root.string) ? h->root.root.string : "<unknown>",
203 (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
212 /* In the old version, when an entry was checked out from the table,
213 it was deleted. This produced an error if the entry was needed
214 more than once, as the second attempted retry failed.
216 In the current version, the entry is not deleted, instead we set
217 the field 'found' to TRUE. If a second lookup matches the same
218 entry, then we know that the hi16s reloc has already been updated
219 and does not need to be updated a second time.
221 TODO - TOFIX: If it is possible that we need to restore 2 different
222 addresses from the same table entry, where the first generates an
223 overflow, whilst the second do not, then this code will fail. */
225 typedef struct hi16s_location
229 unsigned long counter;
231 struct hi16s_location * next;
235 static hi16s_location * previous_hi16s;
236 static hi16s_location * free_hi16s;
237 static unsigned long hi16s_counter;
240 remember_hi16s_reloc (bfd *abfd, bfd_vma addend, bfd_byte *address)
242 hi16s_location * entry = NULL;
243 bfd_size_type amt = sizeof (* free_hi16s);
245 /* Find a free structure. */
246 if (free_hi16s == NULL)
247 free_hi16s = bfd_zalloc (abfd, amt);
250 free_hi16s = free_hi16s->next;
252 entry->addend = addend;
253 entry->address = address;
254 entry->counter = hi16s_counter ++;
255 entry->found = FALSE;
256 entry->next = previous_hi16s;
257 previous_hi16s = entry;
259 /* Cope with wrap around of our counter. */
260 if (hi16s_counter == 0)
262 /* XXX: Assume that all counter entries differ only in their low 16 bits. */
263 for (entry = previous_hi16s; entry != NULL; entry = entry->next)
264 entry->counter &= 0xffff;
266 hi16s_counter = 0x10000;
271 find_remembered_hi16s_reloc (bfd_vma addend, bfd_boolean *already_found)
273 hi16s_location *match = NULL;
274 hi16s_location *entry;
275 hi16s_location *previous = NULL;
276 hi16s_location *prev;
279 /* Search the table. Record the most recent entry that matches. */
280 for (entry = previous_hi16s; entry; entry = entry->next)
282 if (entry->addend == addend
283 && (match == NULL || match->counter < entry->counter))
295 /* Extract the address. */
296 addr = match->address;
298 /* Remember if this entry has already been used before. */
300 * already_found = match->found;
302 /* Note that this entry has now been used. */
308 /* Calculate the final operand value for a R_V850_LO16 or
309 R_V850_LO16_SPLIT_OFFSET. *INSN is the current operand value and
310 ADDEND is the sum of the relocation symbol and offset. Store the
311 operand value in *INSN and return true on success.
313 The assembler has already done some of this: If the value stored in
314 the instruction has its 15th bit set, (counting from zero) then the
315 assembler will have added 1 to the value stored in the associated
316 HI16S reloc. So for example, these relocations:
318 movhi hi( fred ), r0, r1
319 movea lo( fred ), r1, r1
321 will store 0 in the value fields for the MOVHI and MOVEA instructions
322 and addend will be the address of fred, but for these instructions:
324 movhi hi( fred + 0x123456), r0, r1
325 movea lo( fred + 0x123456), r1, r1
327 the value stored in the MOVHI instruction will be 0x12 and the value
328 stored in the MOVEA instruction will be 0x3456. If however the
331 movhi hi( fred + 0x10ffff), r0, r1
332 movea lo( fred + 0x10ffff), r1, r1
334 then the value stored in the MOVHI instruction would be 0x11 (not
335 0x10) and the value stored in the MOVEA instruction would be 0xffff.
336 Thus (assuming for the moment that the addend is 0), at run time the
337 MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction
338 adds 0xffffffff (sign extension!) producing 0x10ffff. Similarly if
339 the instructions were:
341 movhi hi( fred - 1), r0, r1
342 movea lo( fred - 1), r1, r1
344 then 0 is stored in the MOVHI instruction and -1 is stored in the
347 Overflow can occur if the addition of the value stored in the
348 instruction plus the addend sets the 15th bit when before it was clear.
349 This is because the 15th bit will be sign extended into the high part,
350 thus reducing its value by one, but since the 15th bit was originally
351 clear, the assembler will not have added 1 to the previous HI16S reloc
352 to compensate for this effect. For example:
354 movhi hi( fred + 0x123456), r0, r1
355 movea lo( fred + 0x123456), r1, r1
357 The value stored in HI16S reloc is 0x12, the value stored in the LO16
358 reloc is 0x3456. If we assume that the address of fred is 0x00007000
359 then the relocations become:
361 HI16S: 0x0012 + (0x00007000 >> 16) = 0x12
362 LO16: 0x3456 + (0x00007000 & 0xffff) = 0xa456
364 but when the instructions are executed, the MOVEA instruction's value
365 is signed extended, so the sum becomes:
370 0x0011a456 but 'fred + 0x123456' = 0x0012a456
372 Note that if the 15th bit was set in the value stored in the LO16
373 reloc, then we do not have to do anything:
375 movhi hi( fred + 0x10ffff), r0, r1
376 movea lo( fred + 0x10ffff), r1, r1
378 HI16S: 0x0011 + (0x00007000 >> 16) = 0x11
379 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff
384 0x00116fff = fred + 0x10ffff = 0x7000 + 0x10ffff
386 Overflow can also occur if the computation carries into the 16th bit
387 and it also results in the 15th bit having the same value as the 15th
388 bit of the original value. What happens is that the HI16S reloc
389 will have already examined the 15th bit of the original value and
390 added 1 to the high part if the bit is set. This compensates for the
391 sign extension of 15th bit of the result of the computation. But now
392 there is a carry into the 16th bit, and this has not been allowed for.
394 So, for example if fred is at address 0xf000:
396 movhi hi( fred + 0xffff), r0, r1 [bit 15 of the offset is set]
397 movea lo( fred + 0xffff), r1, r1
399 HI16S: 0x0001 + (0x0000f000 >> 16) = 0x0001
400 LO16: 0xffff + (0x0000f000 & 0xffff) = 0xefff (carry into bit 16 is lost)
405 0x0000efff but 'fred + 0xffff' = 0x0001efff
407 Similarly, if the 15th bit remains clear, but overflow occurs into
408 the 16th bit then (assuming the address of fred is 0xf000):
410 movhi hi( fred + 0x7000), r0, r1 [bit 15 of the offset is clear]
411 movea lo( fred + 0x7000), r1, r1
413 HI16S: 0x0000 + (0x0000f000 >> 16) = 0x0000
414 LO16: 0x7000 + (0x0000f000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
419 0x00006fff but 'fred + 0x7000' = 0x00016fff
421 Note - there is no need to change anything if a carry occurs, and the
422 15th bit changes its value from being set to being clear, as the HI16S
423 reloc will have already added in 1 to the high part for us:
425 movhi hi( fred + 0xffff), r0, r1 [bit 15 of the offset is set]
426 movea lo( fred + 0xffff), r1, r1
428 HI16S: 0x0001 + (0x00007000 >> 16)
429 LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
432 + 0x00006fff (bit 15 not set, so the top half is zero)
434 0x00016fff which is right (assuming that fred is at 0x7000)
436 but if the 15th bit goes from being clear to being set, then we must
437 once again handle overflow:
439 movhi hi( fred + 0x7000), r0, r1 [bit 15 of the offset is clear]
440 movea lo( fred + 0x7000), r1, r1
442 HI16S: 0x0000 + (0x0000ffff >> 16)
443 LO16: 0x7000 + (0x0000ffff & 0xffff) = 0x6fff (carry into bit 16)
446 + 0x00006fff (bit 15 not set, so the top half is zero)
448 0x00006fff which is wrong (assuming that fred is at 0xffff). */
451 v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn,
452 unsigned long addend)
454 #define BIT15_SET(x) ((x) & 0x8000)
455 #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff)
457 if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend))
458 || (OVERFLOWS (addend, *insn)
459 && ((! BIT15_SET (*insn)) || (BIT15_SET (addend)))))
461 bfd_boolean already_updated;
462 bfd_byte *hi16s_address = find_remembered_hi16s_reloc
463 (addend, & already_updated);
465 /* Amend the matching HI16_S relocation. */
466 if (hi16s_address != NULL)
468 if (! already_updated)
470 unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address);
472 bfd_put_16 (abfd, hi_insn, hi16s_address);
477 fprintf (stderr, _("FAILED to find previous HI16 reloc\n"));
484 /* Do not complain if value has top bit set, as this has been
486 *insn = (*insn + addend) & 0xffff;
490 /* FIXME: The code here probably ought to be removed and the code in reloc.c
491 allowed to do its stuff instead. At least for most of the relocs, anyway. */
493 static bfd_reloc_status_type
494 v850_elf_perform_relocation (bfd *abfd,
500 unsigned long result;
501 bfd_signed_vma saddend = (bfd_signed_vma) addend;
506 return bfd_reloc_notsupported;
510 bfd_put_32 (abfd, addend, address);
513 case R_V850_22_PCREL:
514 if (saddend > 0x1fffff || saddend < -0x200000)
515 return bfd_reloc_overflow;
517 if ((addend % 2) != 0)
518 return bfd_reloc_dangerous;
520 insn = bfd_get_32 (abfd, address);
522 insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
523 bfd_put_32 (abfd, (bfd_vma) insn, address);
527 if (saddend > 0xff || saddend < -0x100)
528 return bfd_reloc_overflow;
530 if ((addend % 2) != 0)
531 return bfd_reloc_dangerous;
533 insn = bfd_get_16 (abfd, address);
535 insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3);
539 addend += (bfd_get_16 (abfd, address) << 16);
540 addend = (addend >> 16);
545 /* Remember where this relocation took place. */
546 remember_hi16s_reloc (abfd, addend, address);
548 addend += (bfd_get_16 (abfd, address) << 16);
549 addend = (addend >> 16) + ((addend & 0x8000) != 0);
551 /* This relocation cannot overflow. */
559 insn = bfd_get_16 (abfd, address);
560 if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend))
561 return bfd_reloc_overflow;
565 addend += (char) bfd_get_8 (abfd, address);
567 saddend = (bfd_signed_vma) addend;
569 if (saddend > 0x7f || saddend < -0x80)
570 return bfd_reloc_overflow;
572 bfd_put_8 (abfd, addend, address);
575 case R_V850_CALLT_16_16_OFFSET:
576 addend += bfd_get_16 (abfd, address);
578 saddend = (bfd_signed_vma) addend;
580 if (saddend > 0xffff || saddend < 0)
581 return bfd_reloc_overflow;
587 case R_V850_SDA_16_16_OFFSET:
588 case R_V850_ZDA_16_16_OFFSET:
589 case R_V850_TDA_16_16_OFFSET:
590 addend += bfd_get_16 (abfd, address);
592 saddend = (bfd_signed_vma) addend;
594 if (saddend > 0x7fff || saddend < -0x8000)
595 return bfd_reloc_overflow;
600 case R_V850_SDA_15_16_OFFSET:
601 case R_V850_ZDA_15_16_OFFSET:
602 insn = bfd_get_16 (abfd, address);
603 addend += (insn & 0xfffe);
605 saddend = (bfd_signed_vma) addend;
607 if (saddend > 0x7ffe || saddend < -0x8000)
608 return bfd_reloc_overflow;
611 return bfd_reloc_dangerous;
613 insn = (addend &~ (bfd_vma) 1) | (insn & 1);
616 case R_V850_TDA_6_8_OFFSET:
617 insn = bfd_get_16 (abfd, address);
618 addend += ((insn & 0x7e) << 1);
620 saddend = (bfd_signed_vma) addend;
622 if (saddend > 0xfc || saddend < 0)
623 return bfd_reloc_overflow;
626 return bfd_reloc_dangerous;
629 insn |= (addend >> 1);
632 case R_V850_TDA_7_8_OFFSET:
633 insn = bfd_get_16 (abfd, address);
634 addend += ((insn & 0x7f) << 1);
636 saddend = (bfd_signed_vma) addend;
638 if (saddend > 0xfe || saddend < 0)
639 return bfd_reloc_overflow;
642 return bfd_reloc_dangerous;
645 insn |= (addend >> 1);
648 case R_V850_TDA_7_7_OFFSET:
649 insn = bfd_get_16 (abfd, address);
650 addend += insn & 0x7f;
652 saddend = (bfd_signed_vma) addend;
654 if (saddend > 0x7f || saddend < 0)
655 return bfd_reloc_overflow;
661 case R_V850_TDA_4_5_OFFSET:
662 insn = bfd_get_16 (abfd, address);
663 addend += ((insn & 0xf) << 1);
665 saddend = (bfd_signed_vma) addend;
667 if (saddend > 0x1e || saddend < 0)
668 return bfd_reloc_overflow;
671 return bfd_reloc_dangerous;
674 insn |= (addend >> 1);
677 case R_V850_TDA_4_4_OFFSET:
678 insn = bfd_get_16 (abfd, address);
679 addend += insn & 0xf;
681 saddend = (bfd_signed_vma) addend;
683 if (saddend > 0xf || saddend < 0)
684 return bfd_reloc_overflow;
690 case R_V850_LO16_SPLIT_OFFSET:
691 insn = bfd_get_32 (abfd, address);
692 result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5);
693 if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
694 return bfd_reloc_overflow;
695 insn = (((result << 16) & 0xfffe0000)
696 | ((result << 5) & 0x20)
697 | (insn & ~0xfffe0020));
698 bfd_put_32 (abfd, insn, address);
701 case R_V850_ZDA_16_16_SPLIT_OFFSET:
702 case R_V850_SDA_16_16_SPLIT_OFFSET:
703 insn = bfd_get_32 (abfd, address);
704 addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5);
706 saddend = (bfd_signed_vma) addend;
708 if (saddend > 0x7fff || saddend < -0x8000)
709 return bfd_reloc_overflow;
712 insn |= (addend & 1) << 5;
713 insn |= (addend &~ (bfd_vma) 1) << 16;
715 bfd_put_32 (abfd, (bfd_vma) insn, address);
718 case R_V850_CALLT_6_7_OFFSET:
719 insn = bfd_get_16 (abfd, address);
720 addend += ((insn & 0x3f) << 1);
722 saddend = (bfd_signed_vma) addend;
724 if (saddend > 0x7e || saddend < 0)
725 return bfd_reloc_overflow;
728 return bfd_reloc_dangerous;
731 insn |= (addend >> 1);
734 case R_V850_GNU_VTINHERIT:
735 case R_V850_GNU_VTENTRY:
740 bfd_put_16 (abfd, (bfd_vma) insn, address);
744 /* Insert the addend into the instruction. */
746 static bfd_reloc_status_type
747 v850_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
750 void * data ATTRIBUTE_UNUSED,
753 char **err ATTRIBUTE_UNUSED)
757 /* If there is an output BFD,
758 and the symbol is not a section name (which is only defined at final link time),
759 and either we are not putting the addend into the instruction
760 or the addend is zero, so there is nothing to add into the instruction
761 then just fixup the address and return. */
763 && (symbol->flags & BSF_SECTION_SYM) == 0
764 && (! reloc->howto->partial_inplace
765 || reloc->addend == 0))
767 reloc->address += isection->output_offset;
771 /* Catch relocs involving undefined symbols. */
772 if (bfd_is_und_section (symbol->section)
773 && (symbol->flags & BSF_WEAK) == 0
775 return bfd_reloc_undefined;
777 /* We handle final linking of some relocs ourselves. */
779 /* Is the address of the relocation really within the section? */
780 if (reloc->address > bfd_get_section_limit (abfd, isection))
781 return bfd_reloc_outofrange;
783 /* Work out which section the relocation is targeted at and the
784 initial relocation command value. */
786 if (reloc->howto->pc_relative)
789 /* Get symbol value. (Common symbols are special.) */
790 if (bfd_is_com_section (symbol->section))
793 relocation = symbol->value;
795 /* Convert input-section-relative symbol value to absolute + addend. */
796 relocation += symbol->section->output_section->vma;
797 relocation += symbol->section->output_offset;
798 relocation += reloc->addend;
800 reloc->addend = relocation;
804 /* This function is used for relocs which are only used
805 for relaxing, which the linker should otherwise ignore. */
807 static bfd_reloc_status_type
808 v850_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
809 arelent *reloc_entry,
810 asymbol *symbol ATTRIBUTE_UNUSED,
811 void * data ATTRIBUTE_UNUSED,
812 asection *input_section,
814 char **error_message ATTRIBUTE_UNUSED)
816 if (output_bfd != NULL)
817 reloc_entry->address += input_section->output_offset;
821 /* Note: It is REQUIRED that the 'type' value of each entry
822 in this array match the index of the entry in the array. */
823 static reloc_howto_type v850_elf_howto_table[] =
825 /* This reloc does nothing. */
826 HOWTO (R_V850_NONE, /* Type. */
828 2, /* Size (0 = byte, 1 = short, 2 = long). */
830 FALSE, /* PC_relative. */
832 complain_overflow_bitfield, /* Complain_on_overflow. */
833 bfd_elf_generic_reloc, /* Special_function. */
834 "R_V850_NONE", /* Name. */
835 FALSE, /* Partial_inplace. */
838 FALSE), /* PCrel_offset. */
840 /* A PC relative 9 bit branch. */
841 HOWTO (R_V850_9_PCREL, /* Type. */
843 2, /* Size (0 = byte, 1 = short, 2 = long). */
845 TRUE, /* PC_relative. */
847 complain_overflow_bitfield, /* Complain_on_overflow. */
848 v850_elf_reloc, /* Special_function. */
849 "R_V850_9_PCREL", /* Name. */
850 FALSE, /* Partial_inplace. */
851 0x00ffffff, /* Src_mask. */
852 0x00ffffff, /* Dst_mask. */
853 TRUE), /* PCrel_offset. */
855 /* A PC relative 22 bit branch. */
856 HOWTO (R_V850_22_PCREL, /* Type. */
858 2, /* Size (0 = byte, 1 = short, 2 = long). */
860 TRUE, /* PC_relative. */
862 complain_overflow_signed, /* Complain_on_overflow. */
863 v850_elf_reloc, /* Special_function. */
864 "R_V850_22_PCREL", /* Name. */
865 FALSE, /* Partial_inplace. */
866 0x07ffff80, /* Src_mask. */
867 0x07ffff80, /* Dst_mask. */
868 TRUE), /* PCrel_offset. */
870 /* High 16 bits of symbol value. */
871 HOWTO (R_V850_HI16_S, /* Type. */
873 1, /* Size (0 = byte, 1 = short, 2 = long). */
875 FALSE, /* PC_relative. */
877 complain_overflow_dont, /* Complain_on_overflow. */
878 v850_elf_reloc, /* Special_function. */
879 "R_V850_HI16_S", /* Name. */
880 FALSE, /* Partial_inplace. */
881 0xffff, /* Src_mask. */
882 0xffff, /* Dst_mask. */
883 FALSE), /* PCrel_offset. */
885 /* High 16 bits of symbol value. */
886 HOWTO (R_V850_HI16, /* Type. */
888 1, /* Size (0 = byte, 1 = short, 2 = long). */
890 FALSE, /* PC_relative. */
892 complain_overflow_dont, /* Complain_on_overflow. */
893 v850_elf_reloc, /* Special_function. */
894 "R_V850_HI16", /* Name. */
895 FALSE, /* Partial_inplace. */
896 0xffff, /* Src_mask. */
897 0xffff, /* Dst_mask. */
898 FALSE), /* PCrel_offset. */
900 /* Low 16 bits of symbol value. */
901 HOWTO (R_V850_LO16, /* Type. */
903 1, /* Size (0 = byte, 1 = short, 2 = long). */
905 FALSE, /* PC_relative. */
907 complain_overflow_dont, /* Complain_on_overflow. */
908 v850_elf_reloc, /* Special_function. */
909 "R_V850_LO16", /* Name. */
910 FALSE, /* Partial_inplace. */
911 0xffff, /* Src_mask. */
912 0xffff, /* Dst_mask. */
913 FALSE), /* PCrel_offset. */
915 /* Simple 32bit reloc. */
916 HOWTO (R_V850_ABS32, /* Type. */
918 2, /* Size (0 = byte, 1 = short, 2 = long). */
920 FALSE, /* PC_relative. */
922 complain_overflow_dont, /* Complain_on_overflow. */
923 v850_elf_reloc, /* Special_function. */
924 "R_V850_ABS32", /* Name. */
925 FALSE, /* Partial_inplace. */
926 0xffffffff, /* Src_mask. */
927 0xffffffff, /* Dst_mask. */
928 FALSE), /* PCrel_offset. */
930 /* Simple 16bit reloc. */
931 HOWTO (R_V850_16, /* Type. */
933 1, /* Size (0 = byte, 1 = short, 2 = long). */
935 FALSE, /* PC_relative. */
937 complain_overflow_dont, /* Complain_on_overflow. */
938 bfd_elf_generic_reloc, /* Special_function. */
939 "R_V850_16", /* Name. */
940 FALSE, /* Partial_inplace. */
941 0xffff, /* Src_mask. */
942 0xffff, /* Dst_mask. */
943 FALSE), /* PCrel_offset. */
945 /* Simple 8bit reloc. */
946 HOWTO (R_V850_8, /* Type. */
948 0, /* Size (0 = byte, 1 = short, 2 = long). */
950 FALSE, /* PC_relative. */
952 complain_overflow_dont, /* Complain_on_overflow. */
953 bfd_elf_generic_reloc, /* Special_function. */
954 "R_V850_8", /* Name. */
955 FALSE, /* Partial_inplace. */
956 0xff, /* Src_mask. */
957 0xff, /* Dst_mask. */
958 FALSE), /* PCrel_offset. */
960 /* 16 bit offset from the short data area pointer. */
961 HOWTO (R_V850_SDA_16_16_OFFSET, /* Type. */
963 1, /* Size (0 = byte, 1 = short, 2 = long). */
965 FALSE, /* PC_relative. */
967 complain_overflow_dont, /* Complain_on_overflow. */
968 v850_elf_reloc, /* Special_function. */
969 "R_V850_SDA_16_16_OFFSET", /* Name. */
970 FALSE, /* Partial_inplace. */
971 0xffff, /* Src_mask. */
972 0xffff, /* Dst_mask. */
973 FALSE), /* PCrel_offset. */
975 /* 15 bit offset from the short data area pointer. */
976 HOWTO (R_V850_SDA_15_16_OFFSET, /* Type. */
978 1, /* Size (0 = byte, 1 = short, 2 = long). */
980 FALSE, /* PC_relative. */
982 complain_overflow_dont, /* Complain_on_overflow. */
983 v850_elf_reloc, /* Special_function. */
984 "R_V850_SDA_15_16_OFFSET", /* Name. */
985 FALSE, /* Partial_inplace. */
986 0xfffe, /* Src_mask. */
987 0xfffe, /* Dst_mask. */
988 FALSE), /* PCrel_offset. */
990 /* 16 bit offset from the zero data area pointer. */
991 HOWTO (R_V850_ZDA_16_16_OFFSET, /* Type. */
993 1, /* Size (0 = byte, 1 = short, 2 = long). */
995 FALSE, /* PC_relative. */
997 complain_overflow_dont, /* Complain_on_overflow. */
998 v850_elf_reloc, /* Special_function. */
999 "R_V850_ZDA_16_16_OFFSET", /* Name. */
1000 FALSE, /* Partial_inplace. */
1001 0xffff, /* Src_mask. */
1002 0xffff, /* Dst_mask. */
1003 FALSE), /* PCrel_offset. */
1005 /* 15 bit offset from the zero data area pointer. */
1006 HOWTO (R_V850_ZDA_15_16_OFFSET, /* Type. */
1007 1, /* Rightshift. */
1008 1, /* Size (0 = byte, 1 = short, 2 = long). */
1010 FALSE, /* PC_relative. */
1012 complain_overflow_dont, /* Complain_on_overflow. */
1013 v850_elf_reloc, /* Special_function. */
1014 "R_V850_ZDA_15_16_OFFSET", /* Name. */
1015 FALSE, /* Partial_inplace. */
1016 0xfffe, /* Src_mask. */
1017 0xfffe, /* Dst_mask. */
1018 FALSE), /* PCrel_offset. */
1020 /* 6 bit offset from the tiny data area pointer. */
1021 HOWTO (R_V850_TDA_6_8_OFFSET, /* Type. */
1022 2, /* Rightshift. */
1023 1, /* Size (0 = byte, 1 = short, 2 = long). */
1025 FALSE, /* PC_relative. */
1027 complain_overflow_dont, /* Complain_on_overflow. */
1028 v850_elf_reloc, /* Special_function. */
1029 "R_V850_TDA_6_8_OFFSET", /* Name. */
1030 FALSE, /* Partial_inplace. */
1031 0x7e, /* Src_mask. */
1032 0x7e, /* Dst_mask. */
1033 FALSE), /* PCrel_offset. */
1035 /* 8 bit offset from the tiny data area pointer. */
1036 HOWTO (R_V850_TDA_7_8_OFFSET, /* Type. */
1037 1, /* Rightshift. */
1038 1, /* Size (0 = byte, 1 = short, 2 = long). */
1040 FALSE, /* PC_relative. */
1042 complain_overflow_dont, /* Complain_on_overflow. */
1043 v850_elf_reloc, /* Special_function. */
1044 "R_V850_TDA_7_8_OFFSET", /* Name. */
1045 FALSE, /* Partial_inplace. */
1046 0x7f, /* Src_mask. */
1047 0x7f, /* Dst_mask. */
1048 FALSE), /* PCrel_offset. */
1050 /* 7 bit offset from the tiny data area pointer. */
1051 HOWTO (R_V850_TDA_7_7_OFFSET, /* Type. */
1052 0, /* Rightshift. */
1053 1, /* Size (0 = byte, 1 = short, 2 = long). */
1055 FALSE, /* PC_relative. */
1057 complain_overflow_dont, /* Complain_on_overflow. */
1058 v850_elf_reloc, /* Special_function. */
1059 "R_V850_TDA_7_7_OFFSET", /* Name. */
1060 FALSE, /* Partial_inplace. */
1061 0x7f, /* Src_mask. */
1062 0x7f, /* Dst_mask. */
1063 FALSE), /* PCrel_offset. */
1065 /* 16 bit offset from the tiny data area pointer! */
1066 HOWTO (R_V850_TDA_16_16_OFFSET, /* Type. */
1067 0, /* Rightshift. */
1068 1, /* Size (0 = byte, 1 = short, 2 = long). */
1070 FALSE, /* PC_relative. */
1072 complain_overflow_dont, /* Complain_on_overflow. */
1073 v850_elf_reloc, /* Special_function. */
1074 "R_V850_TDA_16_16_OFFSET", /* Name. */
1075 FALSE, /* Partial_inplace. */
1076 0xffff, /* Src_mask. */
1077 0xfff, /* Dst_mask. */
1078 FALSE), /* PCrel_offset. */
1080 /* 5 bit offset from the tiny data area pointer. */
1081 HOWTO (R_V850_TDA_4_5_OFFSET, /* Type. */
1082 1, /* Rightshift. */
1083 1, /* Size (0 = byte, 1 = short, 2 = long). */
1085 FALSE, /* PC_relative. */
1087 complain_overflow_dont, /* Complain_on_overflow. */
1088 v850_elf_reloc, /* Special_function. */
1089 "R_V850_TDA_4_5_OFFSET", /* Name. */
1090 FALSE, /* Partial_inplace. */
1091 0x0f, /* Src_mask. */
1092 0x0f, /* Dst_mask. */
1093 FALSE), /* PCrel_offset. */
1095 /* 4 bit offset from the tiny data area pointer. */
1096 HOWTO (R_V850_TDA_4_4_OFFSET, /* Type. */
1097 0, /* Rightshift. */
1098 1, /* Size (0 = byte, 1 = short, 2 = long). */
1100 FALSE, /* PC_relative. */
1102 complain_overflow_dont, /* Complain_on_overflow. */
1103 v850_elf_reloc, /* Special_function. */
1104 "R_V850_TDA_4_4_OFFSET", /* Name. */
1105 FALSE, /* Partial_inplace. */
1106 0x0f, /* Src_mask. */
1107 0x0f, /* Dst_mask. */
1108 FALSE), /* PCrel_offset. */
1110 /* 16 bit offset from the short data area pointer. */
1111 HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET, /* Type. */
1112 0, /* Rightshift. */
1113 2, /* Size (0 = byte, 1 = short, 2 = long). */
1115 FALSE, /* PC_relative. */
1117 complain_overflow_dont, /* Complain_on_overflow. */
1118 v850_elf_reloc, /* Special_function. */
1119 "R_V850_SDA_16_16_SPLIT_OFFSET",/* Name. */
1120 FALSE, /* Partial_inplace. */
1121 0xfffe0020, /* Src_mask. */
1122 0xfffe0020, /* Dst_mask. */
1123 FALSE), /* PCrel_offset. */
1125 /* 16 bit offset from the zero data area pointer. */
1126 HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET, /* Type. */
1127 0, /* Rightshift. */
1128 2, /* Size (0 = byte, 1 = short, 2 = long). */
1130 FALSE, /* PC_relative. */
1132 complain_overflow_dont, /* Complain_on_overflow. */
1133 v850_elf_reloc, /* Special_function. */
1134 "R_V850_ZDA_16_16_SPLIT_OFFSET",/* Name. */
1135 FALSE, /* Partial_inplace. */
1136 0xfffe0020, /* Src_mask. */
1137 0xfffe0020, /* Dst_mask. */
1138 FALSE), /* PCrel_offset. */
1140 /* 6 bit offset from the call table base pointer. */
1141 HOWTO (R_V850_CALLT_6_7_OFFSET, /* Type. */
1142 0, /* Rightshift. */
1143 1, /* Size (0 = byte, 1 = short, 2 = long). */
1145 FALSE, /* PC_relative. */
1147 complain_overflow_dont, /* Complain_on_overflow. */
1148 v850_elf_reloc, /* Special_function. */
1149 "R_V850_CALLT_6_7_OFFSET", /* Name. */
1150 FALSE, /* Partial_inplace. */
1151 0x3f, /* Src_mask. */
1152 0x3f, /* Dst_mask. */
1153 FALSE), /* PCrel_offset. */
1155 /* 16 bit offset from the call table base pointer. */
1156 HOWTO (R_V850_CALLT_16_16_OFFSET, /* Type. */
1157 0, /* Rightshift. */
1158 1, /* Size (0 = byte, 1 = short, 2 = long). */
1160 FALSE, /* PC_relative. */
1162 complain_overflow_dont, /* Complain_on_overflow. */
1163 v850_elf_reloc, /* Special_function. */
1164 "R_V850_CALLT_16_16_OFFSET", /* Name. */
1165 FALSE, /* Partial_inplace. */
1166 0xffff, /* Src_mask. */
1167 0xffff, /* Dst_mask. */
1168 FALSE), /* PCrel_offset. */
1170 /* GNU extension to record C++ vtable hierarchy */
1171 HOWTO (R_V850_GNU_VTINHERIT, /* Type. */
1172 0, /* Rightshift. */
1173 2, /* Size (0 = byte, 1 = short, 2 = long). */
1175 FALSE, /* PC_relative. */
1177 complain_overflow_dont, /* Complain_on_overflow. */
1178 NULL, /* Special_function. */
1179 "R_V850_GNU_VTINHERIT", /* Name. */
1180 FALSE, /* Partial_inplace. */
1183 FALSE), /* PCrel_offset. */
1185 /* GNU extension to record C++ vtable member usage */
1186 HOWTO (R_V850_GNU_VTENTRY, /* Type. */
1187 0, /* Rightshift. */
1188 2, /* Size (0 = byte, 1 = short, 2 = long). */
1190 FALSE, /* PC_relative. */
1192 complain_overflow_dont, /* Complain_on_overflow. */
1193 _bfd_elf_rel_vtable_reloc_fn, /* Special_function. */
1194 "R_V850_GNU_VTENTRY", /* Name. */
1195 FALSE, /* Partial_inplace. */
1198 FALSE), /* PCrel_offset. */
1200 /* Indicates a .longcall pseudo-op. The compiler will generate a .longcall
1201 pseudo-op when it finds a function call which can be relaxed. */
1202 HOWTO (R_V850_LONGCALL, /* Type. */
1203 0, /* Rightshift. */
1204 2, /* Size (0 = byte, 1 = short, 2 = long). */
1206 TRUE, /* PC_relative. */
1208 complain_overflow_signed, /* Complain_on_overflow. */
1209 v850_elf_ignore_reloc, /* Special_function. */
1210 "R_V850_LONGCALL", /* Name. */
1211 FALSE, /* Partial_inplace. */
1214 TRUE), /* PCrel_offset. */
1216 /* Indicates a .longjump pseudo-op. The compiler will generate a
1217 .longjump pseudo-op when it finds a branch which can be relaxed. */
1218 HOWTO (R_V850_LONGJUMP, /* Type. */
1219 0, /* Rightshift. */
1220 2, /* Size (0 = byte, 1 = short, 2 = long). */
1222 TRUE, /* PC_relative. */
1224 complain_overflow_signed, /* Complain_on_overflow. */
1225 v850_elf_ignore_reloc, /* Special_function. */
1226 "R_V850_LONGJUMP", /* Name. */
1227 FALSE, /* Partial_inplace. */
1230 TRUE), /* PCrel_offset. */
1232 HOWTO (R_V850_ALIGN, /* Type. */
1233 0, /* Rightshift. */
1234 1, /* Size (0 = byte, 1 = short, 2 = long). */
1236 FALSE, /* PC_relative. */
1238 complain_overflow_unsigned, /* Complain_on_overflow. */
1239 v850_elf_ignore_reloc, /* Special_function. */
1240 "R_V850_ALIGN", /* Name. */
1241 FALSE, /* Partial_inplace. */
1244 TRUE), /* PCrel_offset. */
1246 /* Simple pc-relative 32bit reloc. */
1247 HOWTO (R_V850_REL32, /* Type. */
1248 0, /* Rightshift. */
1249 2, /* Size (0 = byte, 1 = short, 2 = long). */
1251 TRUE, /* PC_relative. */
1253 complain_overflow_dont, /* Complain_on_overflow. */
1254 v850_elf_reloc, /* Special_function. */
1255 "R_V850_REL32", /* Name. */
1256 FALSE, /* Partial_inplace. */
1257 0xffffffff, /* Src_mask. */
1258 0xffffffff, /* Dst_mask. */
1259 FALSE), /* PCrel_offset. */
1261 /* An ld.bu version of R_V850_LO16. */
1262 HOWTO (R_V850_LO16_SPLIT_OFFSET, /* Type. */
1263 0, /* Rightshift. */
1264 2, /* Size (0 = byte, 1 = short, 2 = long). */
1266 FALSE, /* PC_relative. */
1268 complain_overflow_dont, /* Complain_on_overflow. */
1269 v850_elf_reloc, /* Special_function. */
1270 "R_V850_LO16_SPLIT_OFFSET", /* Name. */
1271 FALSE, /* Partial_inplace. */
1272 0xfffe0020, /* Src_mask. */
1273 0xfffe0020, /* Dst_mask. */
1274 FALSE), /* PCrel_offset. */
1277 /* Map BFD reloc types to V850 ELF reloc types. */
1279 struct v850_elf_reloc_map
1281 /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an
1283 bfd_reloc_code_real_type bfd_reloc_val;
1284 unsigned int elf_reloc_val;
1287 static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
1289 { BFD_RELOC_NONE, R_V850_NONE },
1290 { BFD_RELOC_V850_9_PCREL, R_V850_9_PCREL },
1291 { BFD_RELOC_V850_22_PCREL, R_V850_22_PCREL },
1292 { BFD_RELOC_HI16_S, R_V850_HI16_S },
1293 { BFD_RELOC_HI16, R_V850_HI16 },
1294 { BFD_RELOC_LO16, R_V850_LO16 },
1295 { BFD_RELOC_32, R_V850_ABS32 },
1296 { BFD_RELOC_32_PCREL, R_V850_REL32 },
1297 { BFD_RELOC_16, R_V850_16 },
1298 { BFD_RELOC_8, R_V850_8 },
1299 { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V850_SDA_16_16_OFFSET },
1300 { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V850_SDA_15_16_OFFSET },
1301 { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V850_ZDA_16_16_OFFSET },
1302 { BFD_RELOC_V850_ZDA_15_16_OFFSET, R_V850_ZDA_15_16_OFFSET },
1303 { BFD_RELOC_V850_TDA_6_8_OFFSET, R_V850_TDA_6_8_OFFSET },
1304 { BFD_RELOC_V850_TDA_7_8_OFFSET, R_V850_TDA_7_8_OFFSET },
1305 { BFD_RELOC_V850_TDA_7_7_OFFSET, R_V850_TDA_7_7_OFFSET },
1306 { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V850_TDA_16_16_OFFSET },
1307 { BFD_RELOC_V850_TDA_4_5_OFFSET, R_V850_TDA_4_5_OFFSET },
1308 { BFD_RELOC_V850_TDA_4_4_OFFSET, R_V850_TDA_4_4_OFFSET },
1309 { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_LO16_SPLIT_OFFSET },
1310 { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET },
1311 { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET },
1312 { BFD_RELOC_V850_CALLT_6_7_OFFSET, R_V850_CALLT_6_7_OFFSET },
1313 { BFD_RELOC_V850_CALLT_16_16_OFFSET, R_V850_CALLT_16_16_OFFSET },
1314 { BFD_RELOC_VTABLE_INHERIT, R_V850_GNU_VTINHERIT },
1315 { BFD_RELOC_VTABLE_ENTRY, R_V850_GNU_VTENTRY },
1316 { BFD_RELOC_V850_LONGCALL, R_V850_LONGCALL },
1317 { BFD_RELOC_V850_LONGJUMP, R_V850_LONGJUMP },
1318 { BFD_RELOC_V850_ALIGN, R_V850_ALIGN },
1322 /* Map a bfd relocation into the appropriate howto structure. */
1324 static reloc_howto_type *
1325 v850_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1326 bfd_reloc_code_real_type code)
1330 for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
1331 if (v850_elf_reloc_map[i].bfd_reloc_val == code)
1333 unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
1335 BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
1337 return v850_elf_howto_table + elf_reloc_val;
1343 /* Set the howto pointer for an V850 ELF reloc. */
1346 v850_elf_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
1348 Elf_Internal_Rela *dst)
1350 unsigned int r_type;
1352 r_type = ELF32_R_TYPE (dst->r_info);
1353 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
1354 cache_ptr->howto = &v850_elf_howto_table[r_type];
1357 /* Set the howto pointer for a V850 ELF reloc (type RELA). */
1360 v850_elf_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
1361 arelent * cache_ptr,
1362 Elf_Internal_Rela *dst)
1364 unsigned int r_type;
1366 r_type = ELF32_R_TYPE (dst->r_info);
1367 BFD_ASSERT (r_type < (unsigned int) R_V850_max);
1368 cache_ptr->howto = &v850_elf_howto_table[r_type];
1372 v850_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
1374 return ( (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
1375 || (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_'));
1378 /* We overload some of the bfd_reloc error codes for own purposes. */
1379 #define bfd_reloc_gp_not_found bfd_reloc_other
1380 #define bfd_reloc_ep_not_found bfd_reloc_continue
1381 #define bfd_reloc_ctbp_not_found (bfd_reloc_dangerous + 1)
1383 /* Perform a relocation as part of a final link. */
1385 static bfd_reloc_status_type
1386 v850_elf_final_link_relocate (reloc_howto_type *howto,
1388 bfd *output_bfd ATTRIBUTE_UNUSED,
1389 asection *input_section,
1394 struct bfd_link_info *info,
1396 int is_local ATTRIBUTE_UNUSED)
1398 unsigned int r_type = howto->type;
1399 bfd_byte *hit_data = contents + offset;
1401 /* Adjust the value according to the relocation. */
1404 case R_V850_9_PCREL:
1405 value -= (input_section->output_section->vma
1406 + input_section->output_offset);
1410 case R_V850_22_PCREL:
1411 value -= (input_section->output_section->vma
1412 + input_section->output_offset
1415 /* If the sign extension will corrupt the value then we have overflowed. */
1416 if (((value & 0xff000000) != 0x0) && ((value & 0xff000000) != 0xff000000))
1417 return bfd_reloc_overflow;
1419 /* Only the bottom 24 bits of the PC are valid. */
1420 value = SEXT24 (value);
1424 value -= (input_section->output_section->vma
1425 + input_section->output_offset
1432 case R_V850_LO16_SPLIT_OFFSET:
1438 case R_V850_ZDA_15_16_OFFSET:
1439 case R_V850_ZDA_16_16_OFFSET:
1440 case R_V850_ZDA_16_16_SPLIT_OFFSET:
1441 if (sym_sec == NULL)
1442 return bfd_reloc_undefined;
1444 value -= sym_sec->output_section->vma;
1447 case R_V850_SDA_15_16_OFFSET:
1448 case R_V850_SDA_16_16_OFFSET:
1449 case R_V850_SDA_16_16_SPLIT_OFFSET:
1452 struct bfd_link_hash_entry * h;
1454 if (sym_sec == NULL)
1455 return bfd_reloc_undefined;
1457 /* Get the value of __gp. */
1458 h = bfd_link_hash_lookup (info->hash, "__gp", FALSE, FALSE, TRUE);
1460 || h->type != bfd_link_hash_defined)
1461 return bfd_reloc_gp_not_found;
1463 gp = (h->u.def.value
1464 + h->u.def.section->output_section->vma
1465 + h->u.def.section->output_offset);
1467 value -= sym_sec->output_section->vma;
1468 value -= (gp - sym_sec->output_section->vma);
1472 case R_V850_TDA_4_4_OFFSET:
1473 case R_V850_TDA_4_5_OFFSET:
1474 case R_V850_TDA_16_16_OFFSET:
1475 case R_V850_TDA_7_7_OFFSET:
1476 case R_V850_TDA_7_8_OFFSET:
1477 case R_V850_TDA_6_8_OFFSET:
1480 struct bfd_link_hash_entry * h;
1482 /* Get the value of __ep. */
1483 h = bfd_link_hash_lookup (info->hash, "__ep", FALSE, FALSE, TRUE);
1485 || h->type != bfd_link_hash_defined)
1486 return bfd_reloc_ep_not_found;
1488 ep = (h->u.def.value
1489 + h->u.def.section->output_section->vma
1490 + h->u.def.section->output_offset);
1496 case R_V850_CALLT_6_7_OFFSET:
1499 struct bfd_link_hash_entry * h;
1501 /* Get the value of __ctbp. */
1502 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
1504 || h->type != bfd_link_hash_defined)
1505 return bfd_reloc_ctbp_not_found;
1507 ctbp = (h->u.def.value
1508 + h->u.def.section->output_section->vma
1509 + h->u.def.section->output_offset);
1514 case R_V850_CALLT_16_16_OFFSET:
1517 struct bfd_link_hash_entry * h;
1519 if (sym_sec == NULL)
1520 return bfd_reloc_undefined;
1522 /* Get the value of __ctbp. */
1523 h = bfd_link_hash_lookup (info->hash, "__ctbp", FALSE, FALSE, TRUE);
1525 || h->type != bfd_link_hash_defined)
1526 return bfd_reloc_ctbp_not_found;
1528 ctbp = (h->u.def.value
1529 + h->u.def.section->output_section->vma
1530 + h->u.def.section->output_offset);
1532 value -= sym_sec->output_section->vma;
1533 value -= (ctbp - sym_sec->output_section->vma);
1538 case R_V850_GNU_VTINHERIT:
1539 case R_V850_GNU_VTENTRY:
1540 case R_V850_LONGCALL:
1541 case R_V850_LONGJUMP:
1543 return bfd_reloc_ok;
1546 return bfd_reloc_notsupported;
1549 /* Perform the relocation. */
1550 return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data);
1553 /* Relocate an V850 ELF section. */
1556 v850_elf_relocate_section (bfd *output_bfd,
1557 struct bfd_link_info *info,
1559 asection *input_section,
1561 Elf_Internal_Rela *relocs,
1562 Elf_Internal_Sym *local_syms,
1563 asection **local_sections)
1565 Elf_Internal_Shdr *symtab_hdr;
1566 struct elf_link_hash_entry **sym_hashes;
1567 Elf_Internal_Rela *rel;
1568 Elf_Internal_Rela *relend;
1570 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
1571 sym_hashes = elf_sym_hashes (input_bfd);
1573 /* Reset the list of remembered HI16S relocs to empty. */
1574 free_hi16s = previous_hi16s;
1575 previous_hi16s = NULL;
1579 relend = relocs + input_section->reloc_count;
1580 for (; rel < relend; rel++)
1583 reloc_howto_type *howto;
1584 unsigned long r_symndx;
1585 Elf_Internal_Sym *sym;
1587 struct elf_link_hash_entry *h;
1589 bfd_reloc_status_type r;
1591 r_symndx = ELF32_R_SYM (rel->r_info);
1592 r_type = ELF32_R_TYPE (rel->r_info);
1594 if (r_type == R_V850_GNU_VTENTRY
1595 || r_type == R_V850_GNU_VTINHERIT)
1598 howto = v850_elf_howto_table + r_type;
1602 if (r_symndx < symtab_hdr->sh_info)
1604 sym = local_syms + r_symndx;
1605 sec = local_sections[r_symndx];
1606 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1610 bfd_boolean unresolved_reloc, warned;
1612 /* Note - this check is delayed until now as it is possible and
1613 valid to have a file without any symbols but with relocs that
1614 can be processed. */
1615 if (sym_hashes == NULL)
1617 info->callbacks->warning
1618 (info, "no hash table available",
1619 NULL, input_bfd, input_section, (bfd_vma) 0);
1624 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1625 r_symndx, symtab_hdr, sym_hashes,
1627 unresolved_reloc, warned);
1630 if (sec != NULL && elf_discarded_section (sec))
1632 /* For relocs against symbols from removed linkonce sections,
1633 or sections discarded by a linker script, we just want the
1634 section contents zeroed. Avoid any special processing. */
1635 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
1641 if (info->relocatable)
1644 /* FIXME: We should use the addend, but the COFF relocations don't. */
1645 r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
1647 contents, rel->r_offset,
1648 relocation, rel->r_addend,
1649 info, sec, h == NULL);
1651 if (r != bfd_reloc_ok)
1654 const char * msg = NULL;
1657 name = h->root.root.string;
1660 name = (bfd_elf_string_from_elf_section
1661 (input_bfd, symtab_hdr->sh_link, sym->st_name));
1662 if (name == NULL || *name == '\0')
1663 name = bfd_section_name (input_bfd, sec);
1668 case bfd_reloc_overflow:
1669 if (! ((*info->callbacks->reloc_overflow)
1670 (info, (h ? &h->root : NULL), name, howto->name,
1671 (bfd_vma) 0, input_bfd, input_section,
1676 case bfd_reloc_undefined:
1677 if (! ((*info->callbacks->undefined_symbol)
1678 (info, name, input_bfd, input_section,
1679 rel->r_offset, TRUE)))
1683 case bfd_reloc_outofrange:
1684 msg = _("internal error: out of range error");
1687 case bfd_reloc_notsupported:
1688 msg = _("internal error: unsupported relocation error");
1691 case bfd_reloc_dangerous:
1692 msg = _("internal error: dangerous relocation");
1695 case bfd_reloc_gp_not_found:
1696 msg = _("could not locate special linker symbol __gp");
1699 case bfd_reloc_ep_not_found:
1700 msg = _("could not locate special linker symbol __ep");
1703 case bfd_reloc_ctbp_not_found:
1704 msg = _("could not locate special linker symbol __ctbp");
1708 msg = _("internal error: unknown error");
1712 if (!((*info->callbacks->warning)
1713 (info, msg, name, input_bfd, input_section,
1725 v850_elf_gc_mark_hook (asection *sec,
1726 struct bfd_link_info *info,
1727 Elf_Internal_Rela *rel,
1728 struct elf_link_hash_entry *h,
1729 Elf_Internal_Sym *sym)
1732 switch (ELF32_R_TYPE (rel->r_info))
1734 case R_V850_GNU_VTINHERIT:
1735 case R_V850_GNU_VTENTRY:
1739 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1742 /* Set the right machine number. */
1745 v850_elf_object_p (bfd *abfd)
1747 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
1751 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850);
1754 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e);
1757 bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e1);
1763 /* Store the machine number in the flags field. */
1766 v850_elf_final_write_processing (bfd *abfd,
1767 bfd_boolean linker ATTRIBUTE_UNUSED)
1771 switch (bfd_get_mach (abfd))
1774 case bfd_mach_v850: val = E_V850_ARCH; break;
1775 case bfd_mach_v850e: val = E_V850E_ARCH; break;
1776 case bfd_mach_v850e1: val = E_V850E1_ARCH; break;
1779 elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH;
1780 elf_elfheader (abfd)->e_flags |= val;
1783 /* Function to keep V850 specific file flags. */
1786 v850_elf_set_private_flags (bfd *abfd, flagword flags)
1788 BFD_ASSERT (!elf_flags_init (abfd)
1789 || elf_elfheader (abfd)->e_flags == flags);
1791 elf_elfheader (abfd)->e_flags = flags;
1792 elf_flags_init (abfd) = TRUE;
1796 /* Merge backend specific data from an object file
1797 to the output object file when linking. */
1800 v850_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
1805 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1806 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1809 in_flags = elf_elfheader (ibfd)->e_flags;
1810 out_flags = elf_elfheader (obfd)->e_flags;
1812 if (! elf_flags_init (obfd))
1814 /* If the input is the default architecture then do not
1815 bother setting the flags for the output architecture,
1816 instead allow future merges to do this. If no future
1817 merges ever set these flags then they will retain their
1818 unitialised values, which surprise surprise, correspond
1819 to the default values. */
1820 if (bfd_get_arch_info (ibfd)->the_default)
1823 elf_flags_init (obfd) = TRUE;
1824 elf_elfheader (obfd)->e_flags = in_flags;
1826 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
1827 && bfd_get_arch_info (obfd)->the_default)
1828 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
1833 /* Check flag compatibility. */
1834 if (in_flags == out_flags)
1837 if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
1838 && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
1840 /* Allow v850e1 binaries to be linked with v850e binaries.
1841 Set the output binary to v850e. */
1842 if ((in_flags & EF_V850_ARCH) == E_V850E1_ARCH
1843 && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
1846 if ((in_flags & EF_V850_ARCH) == E_V850E_ARCH
1847 && (out_flags & EF_V850_ARCH) == E_V850E1_ARCH)
1849 elf_elfheader (obfd)->e_flags =
1850 ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH);
1854 _bfd_error_handler (_("%B: Architecture mismatch with previous modules"),
1861 /* Display the flags field. */
1864 v850_elf_print_private_bfd_data (bfd *abfd, void * ptr)
1866 FILE * file = (FILE *) ptr;
1868 BFD_ASSERT (abfd != NULL && ptr != NULL);
1870 _bfd_elf_print_private_bfd_data (abfd, ptr);
1872 /* xgettext:c-format */
1873 fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags);
1875 switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
1878 case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
1879 case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break;
1880 case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break;
1888 /* V850 ELF uses four common sections. One is the usual one, and the
1889 others are for (small) objects in one of the special data areas:
1890 small, tiny and zero. All the objects are kept together, and then
1891 referenced via the gp register, the ep register or the r0 register
1892 respectively, which yields smaller, faster assembler code. This
1893 approach is copied from elf32-mips.c. */
1895 static asection v850_elf_scom_section;
1896 static asymbol v850_elf_scom_symbol;
1897 static asymbol * v850_elf_scom_symbol_ptr;
1898 static asection v850_elf_tcom_section;
1899 static asymbol v850_elf_tcom_symbol;
1900 static asymbol * v850_elf_tcom_symbol_ptr;
1901 static asection v850_elf_zcom_section;
1902 static asymbol v850_elf_zcom_symbol;
1903 static asymbol * v850_elf_zcom_symbol_ptr;
1905 /* Given a BFD section, try to locate the
1906 corresponding ELF section index. */
1909 v850_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
1913 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1914 *retval = SHN_V850_SCOMMON;
1915 else if (strcmp (bfd_get_section_name (abfd, sec), ".tcommon") == 0)
1916 *retval = SHN_V850_TCOMMON;
1917 else if (strcmp (bfd_get_section_name (abfd, sec), ".zcommon") == 0)
1918 *retval = SHN_V850_ZCOMMON;
1925 /* Handle the special V850 section numbers that a symbol may use. */
1928 v850_elf_symbol_processing (bfd *abfd, asymbol *asym)
1930 elf_symbol_type * elfsym = (elf_symbol_type *) asym;
1933 indx = elfsym->internal_elf_sym.st_shndx;
1935 /* If the section index is an "ordinary" index, then it may
1936 refer to a v850 specific section created by the assembler.
1937 Check the section's type and change the index it matches.
1939 FIXME: Should we alter the st_shndx field as well ? */
1941 if (indx < elf_numsections (abfd))
1942 switch (elf_elfsections(abfd)[indx]->sh_type)
1944 case SHT_V850_SCOMMON:
1945 indx = SHN_V850_SCOMMON;
1948 case SHT_V850_TCOMMON:
1949 indx = SHN_V850_TCOMMON;
1952 case SHT_V850_ZCOMMON:
1953 indx = SHN_V850_ZCOMMON;
1962 case SHN_V850_SCOMMON:
1963 if (v850_elf_scom_section.name == NULL)
1965 /* Initialize the small common section. */
1966 v850_elf_scom_section.name = ".scommon";
1967 v850_elf_scom_section.flags = SEC_IS_COMMON | SEC_ALLOC | SEC_DATA;
1968 v850_elf_scom_section.output_section = & v850_elf_scom_section;
1969 v850_elf_scom_section.symbol = & v850_elf_scom_symbol;
1970 v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr;
1971 v850_elf_scom_symbol.name = ".scommon";
1972 v850_elf_scom_symbol.flags = BSF_SECTION_SYM;
1973 v850_elf_scom_symbol.section = & v850_elf_scom_section;
1974 v850_elf_scom_symbol_ptr = & v850_elf_scom_symbol;
1976 asym->section = & v850_elf_scom_section;
1977 asym->value = elfsym->internal_elf_sym.st_size;
1980 case SHN_V850_TCOMMON:
1981 if (v850_elf_tcom_section.name == NULL)
1983 /* Initialize the tcommon section. */
1984 v850_elf_tcom_section.name = ".tcommon";
1985 v850_elf_tcom_section.flags = SEC_IS_COMMON;
1986 v850_elf_tcom_section.output_section = & v850_elf_tcom_section;
1987 v850_elf_tcom_section.symbol = & v850_elf_tcom_symbol;
1988 v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr;
1989 v850_elf_tcom_symbol.name = ".tcommon";
1990 v850_elf_tcom_symbol.flags = BSF_SECTION_SYM;
1991 v850_elf_tcom_symbol.section = & v850_elf_tcom_section;
1992 v850_elf_tcom_symbol_ptr = & v850_elf_tcom_symbol;
1994 asym->section = & v850_elf_tcom_section;
1995 asym->value = elfsym->internal_elf_sym.st_size;
1998 case SHN_V850_ZCOMMON:
1999 if (v850_elf_zcom_section.name == NULL)
2001 /* Initialize the zcommon section. */
2002 v850_elf_zcom_section.name = ".zcommon";
2003 v850_elf_zcom_section.flags = SEC_IS_COMMON;
2004 v850_elf_zcom_section.output_section = & v850_elf_zcom_section;
2005 v850_elf_zcom_section.symbol = & v850_elf_zcom_symbol;
2006 v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr;
2007 v850_elf_zcom_symbol.name = ".zcommon";
2008 v850_elf_zcom_symbol.flags = BSF_SECTION_SYM;
2009 v850_elf_zcom_symbol.section = & v850_elf_zcom_section;
2010 v850_elf_zcom_symbol_ptr = & v850_elf_zcom_symbol;
2012 asym->section = & v850_elf_zcom_section;
2013 asym->value = elfsym->internal_elf_sym.st_size;
2018 /* Hook called by the linker routine which adds symbols from an object
2019 file. We must handle the special v850 section numbers here. */
2022 v850_elf_add_symbol_hook (bfd *abfd,
2023 struct bfd_link_info *info ATTRIBUTE_UNUSED,
2024 Elf_Internal_Sym *sym,
2025 const char **namep ATTRIBUTE_UNUSED,
2026 flagword *flagsp ATTRIBUTE_UNUSED,
2030 unsigned int indx = sym->st_shndx;
2032 /* If the section index is an "ordinary" index, then it may
2033 refer to a v850 specific section created by the assembler.
2034 Check the section's type and change the index it matches.
2036 FIXME: Should we alter the st_shndx field as well ? */
2038 if (indx < elf_numsections (abfd))
2039 switch (elf_elfsections(abfd)[indx]->sh_type)
2041 case SHT_V850_SCOMMON:
2042 indx = SHN_V850_SCOMMON;
2045 case SHT_V850_TCOMMON:
2046 indx = SHN_V850_TCOMMON;
2049 case SHT_V850_ZCOMMON:
2050 indx = SHN_V850_ZCOMMON;
2059 case SHN_V850_SCOMMON:
2060 *secp = bfd_make_section_old_way (abfd, ".scommon");
2061 (*secp)->flags |= SEC_IS_COMMON;
2062 *valp = sym->st_size;
2065 case SHN_V850_TCOMMON:
2066 *secp = bfd_make_section_old_way (abfd, ".tcommon");
2067 (*secp)->flags |= SEC_IS_COMMON;
2068 *valp = sym->st_size;
2071 case SHN_V850_ZCOMMON:
2072 *secp = bfd_make_section_old_way (abfd, ".zcommon");
2073 (*secp)->flags |= SEC_IS_COMMON;
2074 *valp = sym->st_size;
2082 v850_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
2083 const char *name ATTRIBUTE_UNUSED,
2084 Elf_Internal_Sym *sym,
2085 asection *input_sec,
2086 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
2088 /* If we see a common symbol, which implies a relocatable link, then
2089 if a symbol was in a special common section in an input file, mark
2090 it as a special common in the output file. */
2092 if (sym->st_shndx == SHN_COMMON)
2094 if (strcmp (input_sec->name, ".scommon") == 0)
2095 sym->st_shndx = SHN_V850_SCOMMON;
2096 else if (strcmp (input_sec->name, ".tcommon") == 0)
2097 sym->st_shndx = SHN_V850_TCOMMON;
2098 else if (strcmp (input_sec->name, ".zcommon") == 0)
2099 sym->st_shndx = SHN_V850_ZCOMMON;
2102 /* The price we pay for using h->other unused bits as flags in the
2103 linker is cleaning up after ourselves. */
2105 sym->st_other &= ~(V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA
2106 | V850_OTHER_ERROR);
2112 v850_elf_section_from_shdr (bfd *abfd,
2113 Elf_Internal_Shdr *hdr,
2117 /* There ought to be a place to keep ELF backend specific flags, but
2118 at the moment there isn't one. We just keep track of the
2119 sections by their name, instead. */
2121 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
2124 switch (hdr->sh_type)
2126 case SHT_V850_SCOMMON:
2127 case SHT_V850_TCOMMON:
2128 case SHT_V850_ZCOMMON:
2129 if (! bfd_set_section_flags (abfd, hdr->bfd_section,
2130 (bfd_get_section_flags (abfd,
2139 /* Set the correct type for a V850 ELF section. We do this
2140 by the section name, which is a hack, but ought to work. */
2143 v850_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
2144 Elf_Internal_Shdr *hdr,
2149 name = bfd_get_section_name (abfd, sec);
2151 if (strcmp (name, ".scommon") == 0)
2152 hdr->sh_type = SHT_V850_SCOMMON;
2153 else if (strcmp (name, ".tcommon") == 0)
2154 hdr->sh_type = SHT_V850_TCOMMON;
2155 else if (strcmp (name, ".zcommon") == 0)
2156 hdr->sh_type = SHT_V850_ZCOMMON;
2161 /* Delete some bytes from a section while relaxing. */
2164 v850_elf_relax_delete_bytes (bfd *abfd,
2170 Elf_Internal_Shdr *symtab_hdr;
2171 Elf32_External_Sym *extsyms;
2172 Elf32_External_Sym *esym;
2173 Elf32_External_Sym *esymend;
2175 unsigned int sec_shndx;
2177 Elf_Internal_Rela *irel;
2178 Elf_Internal_Rela *irelend;
2179 struct elf_link_hash_entry *sym_hash;
2180 Elf_Internal_Shdr *shndx_hdr;
2181 Elf_External_Sym_Shndx *shndx;
2183 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2184 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
2186 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2188 contents = elf_section_data (sec)->this_hdr.contents;
2190 /* The deletion must stop at the next ALIGN reloc for an alignment
2191 power larger than the number of bytes we are deleting. */
2193 /* Actually delete the bytes. */
2194 #if (DEBUG_RELAX & 2)
2195 fprintf (stderr, "relax_delete: contents: sec: %s %p .. %p %x\n",
2196 sec->name, addr, toaddr, count );
2198 memmove (contents + addr, contents + addr + count,
2199 toaddr - addr - count);
2200 memset (contents + toaddr-count, 0, count);
2202 /* Adjust all the relocs. */
2203 irel = elf_section_data (sec)->relocs;
2204 irelend = irel + sec->reloc_count;
2205 shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
2206 shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
2208 for (; irel < irelend; irel++)
2210 bfd_vma raddr, paddr, symval;
2211 Elf_Internal_Sym isym;
2213 /* Get the new reloc address. */
2214 raddr = irel->r_offset;
2215 if ((raddr >= (addr + count) && raddr < toaddr))
2216 irel->r_offset -= count;
2218 if (raddr >= addr && raddr < addr + count)
2220 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2225 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
2228 bfd_elf32_swap_symbol_in (abfd,
2229 extsyms + ELF32_R_SYM (irel->r_info),
2230 shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
2233 if (isym.st_shndx != sec_shndx)
2236 /* Get the value of the symbol referred to by the reloc. */
2237 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2239 symval = isym.st_value;
2240 #if (DEBUG_RELAX & 2)
2242 char * name = bfd_elf_string_from_elf_section
2243 (abfd, symtab_hdr->sh_link, isym.st_name);
2245 "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
2246 sec->name, name, isym.st_name,
2247 sec->output_section->vma, sec->output_offset,
2248 isym.st_value, irel->r_addend);
2255 struct elf_link_hash_entry * h;
2257 /* An external symbol. */
2258 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2260 h = elf_sym_hashes (abfd) [indx];
2261 BFD_ASSERT (h != NULL);
2263 symval = h->root.u.def.value;
2264 #if (DEBUG_RELAX & 2)
2266 "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
2267 sec->name, h->root.root.string, h->root.u.def.value,
2268 sec->output_section->vma, sec->output_offset, irel->r_addend);
2272 paddr = symval + irel->r_addend;
2274 if ( (symval >= addr + count && symval < toaddr)
2275 && (paddr < addr + count || paddr >= toaddr))
2276 irel->r_addend += count;
2277 else if ( (symval < addr + count || symval >= toaddr)
2278 && (paddr >= addr + count && paddr < toaddr))
2279 irel->r_addend -= count;
2282 /* Adjust the local symbols defined in this section. */
2284 esymend = esym + symtab_hdr->sh_info;
2286 for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
2288 Elf_Internal_Sym isym;
2290 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2292 if (isym.st_shndx == sec_shndx
2293 && isym.st_value >= addr + count
2294 && isym.st_value < toaddr)
2296 isym.st_value -= count;
2298 if (isym.st_value + isym.st_size >= toaddr)
2299 isym.st_size += count;
2301 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2303 else if (isym.st_shndx == sec_shndx
2304 && isym.st_value < addr + count)
2306 if (isym.st_value+isym.st_size >= addr + count
2307 && isym.st_value+isym.st_size < toaddr)
2308 isym.st_size -= count;
2310 if (isym.st_value >= addr
2311 && isym.st_value < addr + count)
2312 isym.st_value = addr;
2314 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2318 /* Now adjust the global symbols defined in this section. */
2319 esym = extsyms + symtab_hdr->sh_info;
2320 esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
2322 for (index = 0; esym < esymend; esym ++, index ++)
2324 Elf_Internal_Sym isym;
2326 bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
2327 sym_hash = elf_sym_hashes (abfd) [index];
2329 if (isym.st_shndx == sec_shndx
2330 && ((sym_hash)->root.type == bfd_link_hash_defined
2331 || (sym_hash)->root.type == bfd_link_hash_defweak)
2332 && (sym_hash)->root.u.def.section == sec
2333 && (sym_hash)->root.u.def.value >= addr + count
2334 && (sym_hash)->root.u.def.value < toaddr)
2336 if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
2338 isym.st_size += count;
2339 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2342 (sym_hash)->root.u.def.value -= count;
2344 else if (isym.st_shndx == sec_shndx
2345 && ((sym_hash)->root.type == bfd_link_hash_defined
2346 || (sym_hash)->root.type == bfd_link_hash_defweak)
2347 && (sym_hash)->root.u.def.section == sec
2348 && (sym_hash)->root.u.def.value < addr + count)
2350 if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
2351 && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
2352 isym.st_size -= count;
2354 if ((sym_hash)->root.u.def.value >= addr
2355 && (sym_hash)->root.u.def.value < addr + count)
2356 (sym_hash)->root.u.def.value = addr;
2358 bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
2368 #define NOP_OPCODE (0x0000)
2369 #define MOVHI 0x0640 /* 4byte */
2370 #define MOVHI_MASK 0x07e0
2371 #define MOVHI_R1(insn) ((insn) & 0x1f) /* 4byte */
2372 #define MOVHI_R2(insn) ((insn) >> 11)
2373 #define MOVEA 0x0620 /* 2byte */
2374 #define MOVEA_MASK 0x07e0
2375 #define MOVEA_R1(insn) ((insn) & 0x1f)
2376 #define MOVEA_R2(insn) ((insn) >> 11)
2377 #define JARL_4 0x00040780 /* 4byte */
2378 #define JARL_4_MASK 0xFFFF07FF
2379 #define JARL_R2(insn) (int)(((insn) & (~JARL_4_MASK)) >> 11)
2380 #define ADD_I 0x0240 /* 2byte */
2381 #define ADD_I_MASK 0x07e0
2382 #define ADD_I5(insn) ((((insn) & 0x001f) << 11) >> 11) /* 2byte */
2383 #define ADD_R2(insn) ((insn) >> 11)
2384 #define JMP_R 0x0060 /* 2byte */
2385 #define JMP_R_MASK 0xFFE0
2386 #define JMP_R1(insn) ((insn) & 0x1f)
2389 v850_elf_relax_section (bfd *abfd,
2391 struct bfd_link_info *link_info,
2394 Elf_Internal_Shdr *symtab_hdr;
2395 Elf_Internal_Rela *internal_relocs;
2396 Elf_Internal_Rela *irel;
2397 Elf_Internal_Rela *irelend;
2398 Elf_Internal_Rela *irelalign = NULL;
2399 Elf_Internal_Sym *isymbuf = NULL;
2400 bfd_byte *contents = NULL;
2403 int align_pad_size = 0;
2404 bfd_boolean result = TRUE;
2408 if (link_info->relocatable
2409 || (sec->flags & SEC_RELOC) == 0
2410 || sec->reloc_count == 0)
2413 symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
2415 internal_relocs = (_bfd_elf_link_read_relocs
2416 (abfd, sec, NULL, NULL, link_info->keep_memory));
2417 if (internal_relocs == NULL)
2420 irelend = internal_relocs + sec->reloc_count;
2422 while (addr < sec->size)
2426 for (irel = internal_relocs; irel < irelend; irel ++)
2427 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
2428 && irel->r_offset > addr
2429 && irel->r_offset < toaddr)
2430 toaddr = irel->r_offset;
2433 fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
2434 addr, toaddr, align_pad_size);
2439 bfd_vma alignmoveto;
2441 alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
2442 alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
2444 if (alignmoveto < alignto)
2448 align_pad_size = alignto - alignmoveto;
2450 fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
2451 alignmoveto, toaddr, align_pad_size);
2453 if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
2454 toaddr, align_pad_size))
2457 for (i = BFD_ALIGN (toaddr - align_pad_size, 1);
2458 (i + 1) < toaddr; i += 2)
2459 bfd_put_16 (abfd, NOP_OPCODE, contents + i);
2467 for (irel = internal_relocs; irel < irelend; irel++)
2474 Elf_Internal_Rela *hi_irelfn;
2475 Elf_Internal_Rela *lo_irelfn;
2476 Elf_Internal_Rela *irelcall;
2477 bfd_signed_vma foff;
2479 if (! (irel->r_offset >= addr && irel->r_offset < toaddr
2480 && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
2481 || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
2485 fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
2491 /* Get the section contents. */
2492 if (contents == NULL)
2494 if (elf_section_data (sec)->this_hdr.contents != NULL)
2495 contents = elf_section_data (sec)->this_hdr.contents;
2498 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2503 /* Read this BFD's local symbols if we haven't done so already. */
2504 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2506 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2507 if (isymbuf == NULL)
2508 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2509 symtab_hdr->sh_info, 0,
2511 if (isymbuf == NULL)
2515 laddr = irel->r_offset;
2517 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
2519 /* Check code for -mlong-calls output. */
2520 if (laddr + 16 <= (bfd_vma) sec->size)
2522 insn[0] = bfd_get_16 (abfd, contents + laddr);
2523 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
2524 insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
2525 insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
2526 insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
2528 if ((insn[0] & MOVHI_MASK) != MOVHI
2529 || MOVHI_R1 (insn[0]) != 0)
2533 && ((insn[1] & MOVEA_MASK) != MOVEA
2534 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
2538 && (insn[2] & JARL_4_MASK) != JARL_4)
2542 && ((insn[3] & ADD_I_MASK) != ADD_I
2543 || ADD_I5 (insn[3]) != 4
2544 || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
2548 && ((insn[4] & JMP_R_MASK) != JMP_R
2549 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
2554 ((*_bfd_error_handler)
2555 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insns",
2556 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
2563 ((*_bfd_error_handler)
2564 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized insn 0x%x",
2565 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
2570 /* Get the reloc for the address from which the register is
2571 being loaded. This reloc will tell us which function is
2572 actually being called. */
2573 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
2574 if (hi_irelfn->r_offset == laddr + 2
2575 && ELF32_R_TYPE (hi_irelfn->r_info)
2576 == (int) R_V850_HI16_S)
2579 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
2580 if (lo_irelfn->r_offset == laddr + 6
2581 && ELF32_R_TYPE (lo_irelfn->r_info)
2582 == (int) R_V850_LO16)
2585 for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
2586 if (irelcall->r_offset == laddr + 8
2587 && ELF32_R_TYPE (irelcall->r_info)
2588 == (int) R_V850_22_PCREL)
2591 if ( hi_irelfn == irelend
2592 || lo_irelfn == irelend
2593 || irelcall == irelend)
2595 ((*_bfd_error_handler)
2596 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc",
2597 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
2602 if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
2604 Elf_Internal_Sym * isym;
2606 /* A local symbol. */
2607 isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
2609 symval = isym->st_value;
2614 struct elf_link_hash_entry * h;
2616 /* An external symbol. */
2617 indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
2618 h = elf_sym_hashes (abfd)[indx];
2619 BFD_ASSERT (h != NULL);
2621 if ( h->root.type != bfd_link_hash_defined
2622 && h->root.type != bfd_link_hash_defweak)
2623 /* This appears to be a reference to an undefined
2624 symbol. Just ignore it--it will be caught by the
2625 regular reloc processing. */
2628 symval = h->root.u.def.value;
2631 if (symval + irelcall->r_addend != irelcall->r_offset + 4)
2633 ((*_bfd_error_handler)
2634 ("%s: 0x%lx: warning: R_V850_LONGCALL points to unrecognized reloc 0x%lx",
2635 bfd_get_filename (abfd), (unsigned long) irel->r_offset, irelcall->r_offset ));
2640 /* Get the value of the symbol referred to by the reloc. */
2641 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2643 Elf_Internal_Sym *isym;
2646 /* A local symbol. */
2647 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
2649 if (isym->st_shndx == SHN_UNDEF)
2650 sym_sec = bfd_und_section_ptr;
2651 else if (isym->st_shndx == SHN_ABS)
2652 sym_sec = bfd_abs_section_ptr;
2653 else if (isym->st_shndx == SHN_COMMON)
2654 sym_sec = bfd_com_section_ptr;
2656 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2657 symval = (isym->st_value
2658 + sym_sec->output_section->vma
2659 + sym_sec->output_offset);
2664 struct elf_link_hash_entry *h;
2666 /* An external symbol. */
2667 indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
2668 h = elf_sym_hashes (abfd)[indx];
2669 BFD_ASSERT (h != NULL);
2671 if ( h->root.type != bfd_link_hash_defined
2672 && h->root.type != bfd_link_hash_defweak)
2673 /* This appears to be a reference to an undefined
2674 symbol. Just ignore it--it will be caught by the
2675 regular reloc processing. */
2678 symval = (h->root.u.def.value
2679 + h->root.u.def.section->output_section->vma
2680 + h->root.u.def.section->output_offset);
2683 addend = irel->r_addend;
2685 foff = (symval + addend
2687 + sec->output_section->vma
2688 + sec->output_offset
2691 fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
2694 + sec->output_section->vma
2695 + sec->output_offset),
2696 symval, addend, foff);
2699 if (foff < -0x100000 || foff >= 0x100000)
2700 /* After all that work, we can't shorten this function call. */
2703 /* For simplicity of coding, we are going to modify the section
2704 contents, the section relocs, and the BFD symbol table. We
2705 must tell the rest of the code not to free up this
2706 information. It would be possible to instead create a table
2707 of changes which have to be made, as is done in coff-mips.c;
2708 that would be more work, but would require less memory when
2709 the linker is run. */
2710 elf_section_data (sec)->relocs = internal_relocs;
2711 elf_section_data (sec)->this_hdr.contents = contents;
2712 symtab_hdr->contents = (bfd_byte *) isymbuf;
2714 /* Replace the long call with a jarl. */
2715 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
2719 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2720 /* If this needs to be changed because of future relaxing,
2721 it will be handled here like other internal IND12W
2724 0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
2725 contents + irel->r_offset);
2727 /* We can't fully resolve this yet, because the external
2728 symbol value may be changed by future relaxing.
2729 We let the final link phase handle it. */
2730 bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
2731 contents + irel->r_offset);
2734 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
2736 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
2738 ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
2740 if (! v850_elf_relax_delete_bytes (abfd, sec,
2741 irel->r_offset + 4, toaddr, 12))
2744 align_pad_size += 12;
2746 else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
2748 /* Check code for -mlong-jumps output. */
2749 if (laddr + 10 <= (bfd_vma) sec->size)
2751 insn[0] = bfd_get_16 (abfd, contents + laddr);
2752 insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
2753 insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
2755 if ((insn[0] & MOVHI_MASK) != MOVHI
2756 || MOVHI_R1 (insn[0]) != 0)
2760 && ((insn[1] & MOVEA_MASK) != MOVEA
2761 || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
2765 && ((insn[2] & JMP_R_MASK) != JMP_R
2766 || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
2771 ((*_bfd_error_handler)
2772 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insns",
2773 bfd_get_filename (abfd), (unsigned long) irel->r_offset));
2780 ((*_bfd_error_handler)
2781 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized insn 0x%x",
2782 bfd_get_filename (abfd), (unsigned long) irel->r_offset+no_match, insn[no_match]));
2787 /* Get the reloc for the address from which the register is
2788 being loaded. This reloc will tell us which function is
2789 actually being called. */
2790 for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
2791 if (hi_irelfn->r_offset == laddr + 2
2792 && ELF32_R_TYPE (hi_irelfn->r_info) == (int) R_V850_HI16_S)
2795 for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
2796 if (lo_irelfn->r_offset == laddr + 6
2797 && ELF32_R_TYPE (lo_irelfn->r_info) == (int) R_V850_LO16)
2800 if ( hi_irelfn == irelend
2801 || lo_irelfn == irelend)
2803 ((*_bfd_error_handler)
2804 ("%s: 0x%lx: warning: R_V850_LONGJUMP points to unrecognized reloc",
2805 bfd_get_filename (abfd), (unsigned long) irel->r_offset ));
2810 /* Get the value of the symbol referred to by the reloc. */
2811 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2813 Elf_Internal_Sym * isym;
2816 /* A local symbol. */
2817 isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
2819 if (isym->st_shndx == SHN_UNDEF)
2820 sym_sec = bfd_und_section_ptr;
2821 else if (isym->st_shndx == SHN_ABS)
2822 sym_sec = bfd_abs_section_ptr;
2823 else if (isym->st_shndx == SHN_COMMON)
2824 sym_sec = bfd_com_section_ptr;
2826 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
2827 symval = (isym->st_value
2828 + sym_sec->output_section->vma
2829 + sym_sec->output_offset);
2832 char * name = bfd_elf_string_from_elf_section
2833 (abfd, symtab_hdr->sh_link, isym->st_name);
2835 fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
2836 sym_sec->name, name, isym->st_name,
2837 sym_sec->output_section->vma,
2838 sym_sec->output_offset,
2839 isym->st_value, irel->r_addend);
2846 struct elf_link_hash_entry * h;
2848 /* An external symbol. */
2849 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
2850 h = elf_sym_hashes (abfd)[indx];
2851 BFD_ASSERT (h != NULL);
2853 if ( h->root.type != bfd_link_hash_defined
2854 && h->root.type != bfd_link_hash_defweak)
2855 /* This appears to be a reference to an undefined
2856 symbol. Just ignore it--it will be caught by the
2857 regular reloc processing. */
2860 symval = (h->root.u.def.value
2861 + h->root.u.def.section->output_section->vma
2862 + h->root.u.def.section->output_offset);
2865 "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
2866 sec->name, h->root.root.string, h->root.u.def.value,
2867 sec->output_section->vma, sec->output_offset, irel->r_addend);
2871 addend = irel->r_addend;
2873 foff = (symval + addend
2875 + sec->output_section->vma
2876 + sec->output_offset
2879 fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
2882 + sec->output_section->vma
2883 + sec->output_offset),
2884 symval, addend, foff);
2886 if (foff < -0x100000 || foff >= 0x100000)
2887 /* After all that work, we can't shorten this function call. */
2890 /* For simplicity of coding, we are going to modify the section
2891 contents, the section relocs, and the BFD symbol table. We
2892 must tell the rest of the code not to free up this
2893 information. It would be possible to instead create a table
2894 of changes which have to be made, as is done in coff-mips.c;
2895 that would be more work, but would require less memory when
2896 the linker is run. */
2897 elf_section_data (sec)->relocs = internal_relocs;
2898 elf_section_data (sec)->this_hdr.contents = contents;
2899 symtab_hdr->contents = (bfd_byte *) isymbuf;
2901 if (foff < -0x100 || foff >= 0x100)
2903 /* Replace the long jump with a jr. */
2906 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
2908 irel->r_addend = addend;
2911 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2912 /* If this needs to be changed because of future relaxing,
2913 it will be handled here like other internal IND12W
2916 0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
2917 contents + irel->r_offset);
2919 /* We can't fully resolve this yet, because the external
2920 symbol value may be changed by future relaxing.
2921 We let the final link phase handle it. */
2922 bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
2925 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
2927 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
2928 if (!v850_elf_relax_delete_bytes (abfd, sec,
2929 irel->r_offset + 4, toaddr, 6))
2932 align_pad_size += 6;
2936 /* Replace the long jump with a br. */
2939 ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
2941 irel->r_addend = addend;
2944 if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
2945 /* If this needs to be changed because of future relaxing,
2946 it will be handled here like other internal IND12W
2949 0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
2950 contents + irel->r_offset);
2952 /* We can't fully resolve this yet, because the external
2953 symbol value may be changed by future relaxing.
2954 We let the final link phase handle it. */
2955 bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
2958 ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
2960 ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
2961 if (!v850_elf_relax_delete_bytes (abfd, sec,
2962 irel->r_offset + 2, toaddr, 8))
2965 align_pad_size += 8;
2971 for (irel = internal_relocs; irel < irelend; irel++)
2973 if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
2974 && irel->r_offset == toaddr)
2976 irel->r_offset -= align_pad_size;
2978 if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
2989 fprintf (stderr, "relax pad %d shorten %d -> %d\n",
2992 sec->size - align_pad_size);
2994 sec->size -= align_pad_size;
2998 if (internal_relocs != NULL
2999 && elf_section_data (sec)->relocs != internal_relocs)
3000 free (internal_relocs);
3002 if (contents != NULL
3003 && elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
3007 && symtab_hdr->contents != (bfd_byte *) isymbuf)
3017 static const struct bfd_elf_special_section v850_elf_special_sections[] =
3019 { STRING_COMMA_LEN (".call_table_data"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE) },
3020 { STRING_COMMA_LEN (".call_table_text"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3022 { STRING_COMMA_LEN (".rosdata"), -2, SHT_PROGBITS, (SHF_ALLOC
3023 + SHF_V850_GPREL) },
3024 { STRING_COMMA_LEN (".rozdata"), -2, SHT_PROGBITS, (SHF_ALLOC
3025 + SHF_V850_R0REL) },
3026 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3027 + SHF_V850_GPREL) },
3028 { STRING_COMMA_LEN (".scommon"), -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE
3029 + SHF_V850_GPREL) },
3030 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3031 + SHF_V850_GPREL) },
3032 { STRING_COMMA_LEN (".tbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3033 + SHF_V850_EPREL) },
3034 { STRING_COMMA_LEN (".tcommon"), -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE
3035 + SHF_V850_R0REL) },
3036 { STRING_COMMA_LEN (".tdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3037 + SHF_V850_EPREL) },
3038 { STRING_COMMA_LEN (".zbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
3039 + SHF_V850_R0REL) },
3040 { STRING_COMMA_LEN (".zcommon"), -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE
3041 + SHF_V850_R0REL) },
3042 { STRING_COMMA_LEN (".zdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
3043 + SHF_V850_R0REL) },
3044 { NULL, 0, 0, 0, 0 }
3047 #define TARGET_LITTLE_SYM bfd_elf32_v850_vec
3048 #define TARGET_LITTLE_NAME "elf32-v850"
3049 #define ELF_ARCH bfd_arch_v850
3050 #define ELF_MACHINE_CODE EM_V850
3051 #define ELF_MACHINE_ALT1 EM_CYGNUS_V850
3052 #define ELF_MACHINE_ALT2 EM_V800 /* This is the value used by the GreenHills toolchain. */
3053 #define ELF_MAXPAGESIZE 0x1000
3055 #define elf_info_to_howto v850_elf_info_to_howto_rela
3056 #define elf_info_to_howto_rel v850_elf_info_to_howto_rel
3058 #define elf_backend_check_relocs v850_elf_check_relocs
3059 #define elf_backend_relocate_section v850_elf_relocate_section
3060 #define elf_backend_object_p v850_elf_object_p
3061 #define elf_backend_final_write_processing v850_elf_final_write_processing
3062 #define elf_backend_section_from_bfd_section v850_elf_section_from_bfd_section
3063 #define elf_backend_symbol_processing v850_elf_symbol_processing
3064 #define elf_backend_add_symbol_hook v850_elf_add_symbol_hook
3065 #define elf_backend_link_output_symbol_hook v850_elf_link_output_symbol_hook
3066 #define elf_backend_section_from_shdr v850_elf_section_from_shdr
3067 #define elf_backend_fake_sections v850_elf_fake_sections
3068 #define elf_backend_gc_mark_hook v850_elf_gc_mark_hook
3069 #define elf_backend_special_sections v850_elf_special_sections
3071 #define elf_backend_can_gc_sections 1
3072 #define elf_backend_rela_normal 1
3074 #define bfd_elf32_bfd_is_local_label_name v850_elf_is_local_label_name
3075 #define bfd_elf32_bfd_reloc_type_lookup v850_elf_reloc_type_lookup
3076 #define bfd_elf32_bfd_merge_private_bfd_data v850_elf_merge_private_bfd_data
3077 #define bfd_elf32_bfd_set_private_flags v850_elf_set_private_flags
3078 #define bfd_elf32_bfd_print_private_bfd_data v850_elf_print_private_bfd_data
3079 #define bfd_elf32_bfd_relax_section v850_elf_relax_section
3081 #define elf_symbol_leading_char '_'
3083 #include "elf32-target.h"