Changeset 609 for branches/GNU/src/binutils/bfd/elf32-fr30.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf32-fr30.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* FR30-specific support for 32-bit ELF. 2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 3 4 4 This file is part of BFD, the Binary File Descriptor library. … … 32 32 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); 33 33 static void fr30_info_to_howto_rela 34 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); 35 static boolean fr30_elf_relocate_section 36 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 34 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 35 static bfd_boolean fr30_elf_relocate_section 36 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 37 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 37 38 static bfd_reloc_status_type fr30_final_link_relocate 38 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, bfd_vma)); 39 static boolean fr30_elf_gc_sweep_hook 40 PARAMS ((bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *)); 39 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, 40 Elf_Internal_Rela *, bfd_vma)); 41 static bfd_boolean fr30_elf_gc_sweep_hook 42 PARAMS ((bfd *, struct bfd_link_info *, asection *, 43 const Elf_Internal_Rela *)); 41 44 static asection * fr30_elf_gc_mark_hook 42 PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *, struct elf_link_hash_entry *, Elf_Internal_Sym *)); 45 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 46 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 47 static bfd_boolean fr30_elf_check_relocs 48 PARAMS ((bfd *, struct bfd_link_info *, asection *, 49 const Elf_Internal_Rela *)); 43 50 44 51 static reloc_howto_type fr30_elf_howto_table [] = … … 49 56 2, /* size (0 = byte, 1 = short, 2 = long) */ 50 57 32, /* bitsize */ 51 false, /* pc_relative */58 FALSE, /* pc_relative */ 52 59 0, /* bitpos */ 53 60 complain_overflow_bitfield, /* complain_on_overflow */ 54 61 bfd_elf_generic_reloc, /* special_function */ 55 62 "R_FR30_NONE", /* name */ 56 false, /* partial_inplace */63 FALSE, /* partial_inplace */ 57 64 0, /* src_mask */ 58 65 0, /* dst_mask */ 59 false), /* pcrel_offset */66 FALSE), /* pcrel_offset */ 60 67 61 68 /* An 8 bit absolute relocation. */ … … 64 71 1, /* size (0 = byte, 1 = short, 2 = long) */ 65 72 8, /* bitsize */ 66 false, /* pc_relative */73 FALSE, /* pc_relative */ 67 74 4, /* bitpos */ 68 75 complain_overflow_bitfield, /* complain_on_overflow */ 69 76 bfd_elf_generic_reloc, /* special_function */ 70 77 "R_FR30_8", /* name */ 71 true, /* partial_inplace */78 TRUE, /* partial_inplace */ 72 79 0x0000, /* src_mask */ 73 80 0x0ff0, /* dst_mask */ 74 false), /* pcrel_offset */81 FALSE), /* pcrel_offset */ 75 82 76 83 /* A 20 bit absolute relocation. */ … … 79 86 2, /* size (0 = byte, 1 = short, 2 = long) */ 80 87 20, /* bitsize */ 81 false, /* pc_relative */88 FALSE, /* pc_relative */ 82 89 0, /* bitpos */ 83 90 complain_overflow_bitfield, /* complain_on_overflow */ 84 91 fr30_elf_i20_reloc, /* special_function */ 85 92 "R_FR30_20", /* name */ 86 true, /* partial_inplace */93 TRUE, /* partial_inplace */ 87 94 0x00000000, /* src_mask */ 88 95 0x00f0ffff, /* dst_mask */ 89 false), /* pcrel_offset */96 FALSE), /* pcrel_offset */ 90 97 91 98 /* A 32 bit absolute relocation. */ … … 94 101 2, /* size (0 = byte, 1 = short, 2 = long) */ 95 102 32, /* bitsize */ 96 false, /* pc_relative */103 FALSE, /* pc_relative */ 97 104 0, /* bitpos */ 98 105 complain_overflow_bitfield, /* complain_on_overflow */ 99 106 bfd_elf_generic_reloc, /* special_function */ 100 107 "R_FR30_32", /* name */ 101 true, /* partial_inplace */108 TRUE, /* partial_inplace */ 102 109 0x00000000, /* src_mask */ 103 110 0xffffffff, /* dst_mask */ 104 false), /* pcrel_offset */111 FALSE), /* pcrel_offset */ 105 112 106 113 /* A 32 bit into 48 bits absolute relocation. */ … … 109 116 2, /* size (0 = byte, 1 = short, 2 = long) */ 110 117 32, /* bitsize */ 111 false, /* pc_relative */118 FALSE, /* pc_relative */ 112 119 0, /* bitpos */ 113 120 complain_overflow_bitfield, /* complain_on_overflow */ 114 121 fr30_elf_i32_reloc, /* special_function */ 115 122 "R_FR30_48", /* name */ 116 true, /* partial_inplace */123 TRUE, /* partial_inplace */ 117 124 0x00000000, /* src_mask */ 118 125 0xffffffff, /* dst_mask */ 119 false), /* pcrel_offset */126 FALSE), /* pcrel_offset */ 120 127 121 128 /* A 6 bit absolute relocation. */ … … 124 131 1, /* size (0 = byte, 1 = short, 2 = long) */ 125 132 6, /* bitsize */ 126 false, /* pc_relative */133 FALSE, /* pc_relative */ 127 134 4, /* bitpos */ 128 135 complain_overflow_unsigned, /* complain_on_overflow */ 129 136 bfd_elf_generic_reloc, /* special_function */ 130 137 "R_FR30_6_IN_4", /* name */ 131 true, /* partial_inplace */138 TRUE, /* partial_inplace */ 132 139 0x0000, /* src_mask */ 133 140 0x00f0, /* dst_mask */ 134 false), /* pcrel_offset */141 FALSE), /* pcrel_offset */ 135 142 136 143 /* An 8 bit absolute relocation. */ … … 139 146 1, /* size (0 = byte, 1 = short, 2 = long) */ 140 147 8, /* bitsize */ 141 false, /* pc_relative */148 FALSE, /* pc_relative */ 142 149 4, /* bitpos */ 143 150 complain_overflow_signed, /* complain_on_overflow */ 144 151 bfd_elf_generic_reloc,/* special_function */ 145 152 "R_FR30_8_IN_8", /* name */ 146 true, /* partial_inplace */153 TRUE, /* partial_inplace */ 147 154 0x0000, /* src_mask */ 148 155 0x0ff0, /* dst_mask */ 149 false), /* pcrel_offset */156 FALSE), /* pcrel_offset */ 150 157 151 158 /* A 9 bit absolute relocation. */ … … 154 161 1, /* size (0 = byte, 1 = short, 2 = long) */ 155 162 9, /* bitsize */ 156 false, /* pc_relative */163 FALSE, /* pc_relative */ 157 164 4, /* bitpos */ 158 165 complain_overflow_signed, /* complain_on_overflow */ 159 166 bfd_elf_generic_reloc,/* special_function */ 160 167 "R_FR30_9_IN_8", /* name */ 161 true, /* partial_inplace */168 TRUE, /* partial_inplace */ 162 169 0x0000, /* src_mask */ 163 170 0x0ff0, /* dst_mask */ 164 false), /* pcrel_offset */171 FALSE), /* pcrel_offset */ 165 172 166 173 /* A 10 bit absolute relocation. */ … … 169 176 1, /* size (0 = byte, 1 = short, 2 = long) */ 170 177 10, /* bitsize */ 171 false, /* pc_relative */178 FALSE, /* pc_relative */ 172 179 4, /* bitpos */ 173 180 complain_overflow_signed, /* complain_on_overflow */ 174 181 bfd_elf_generic_reloc,/* special_function */ 175 182 "R_FR30_10_IN_8", /* name */ 176 true, /* partial_inplace */183 TRUE, /* partial_inplace */ 177 184 0x0000, /* src_mask */ 178 185 0x0ff0, /* dst_mask */ 179 false), /* pcrel_offset */186 FALSE), /* pcrel_offset */ 180 187 181 188 /* A PC relative 9 bit relocation, right shifted by 1. */ … … 184 191 1, /* size (0 = byte, 1 = short, 2 = long) */ 185 192 9, /* bitsize */ 186 true, /* pc_relative */193 TRUE, /* pc_relative */ 187 194 0, /* bitpos */ 188 195 complain_overflow_signed, /* complain_on_overflow */ 189 196 bfd_elf_generic_reloc, /* special_function */ 190 197 "R_FR30_9_PCREL", /* name */ 191 false, /* partial_inplace */198 FALSE, /* partial_inplace */ 192 199 0x0000, /* src_mask */ 193 200 0x00ff, /* dst_mask */ 194 false), /* pcrel_offset */201 FALSE), /* pcrel_offset */ 195 202 196 203 /* A PC relative 12 bit relocation, right shifted by 1. */ … … 199 206 1, /* size (0 = byte, 1 = short, 2 = long) */ 200 207 12, /* bitsize */ 201 true, /* pc_relative */208 TRUE, /* pc_relative */ 202 209 0, /* bitpos */ 203 210 complain_overflow_signed, /* complain_on_overflow */ 204 211 bfd_elf_generic_reloc, /* special_function */ 205 212 "R_FR30_12_PCREL", /* name */ 206 false, /* partial_inplace */213 FALSE, /* partial_inplace */ 207 214 0x0000, /* src_mask */ 208 215 0x07ff, /* dst_mask */ 209 false), /* pcrel_offset */216 FALSE), /* pcrel_offset */ 210 217 /* GNU extension to record C++ vtable hierarchy */ 211 218 HOWTO (R_FR30_GNU_VTINHERIT, /* type */ … … 213 220 2, /* size (0 = byte, 1 = short, 2 = long) */ 214 221 0, /* bitsize */ 215 false, /* pc_relative */222 FALSE, /* pc_relative */ 216 223 0, /* bitpos */ 217 224 complain_overflow_dont, /* complain_on_overflow */ 218 225 NULL, /* special_function */ 219 226 "R_FR30_GNU_VTINHERIT", /* name */ 220 false, /* partial_inplace */227 FALSE, /* partial_inplace */ 221 228 0, /* src_mask */ 222 229 0, /* dst_mask */ 223 false), /* pcrel_offset */230 FALSE), /* pcrel_offset */ 224 231 225 232 /* GNU extension to record C++ vtable member usage */ … … 228 235 2, /* size (0 = byte, 1 = short, 2 = long) */ 229 236 0, /* bitsize */ 230 false, /* pc_relative */237 FALSE, /* pc_relative */ 231 238 0, /* bitpos */ 232 239 complain_overflow_dont, /* complain_on_overflow */ 233 240 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 234 241 "R_FR30_GNU_VTENTRY", /* name */ 235 false, /* partial_inplace */242 FALSE, /* partial_inplace */ 236 243 0, /* src_mask */ 237 244 0, /* dst_mask */ 238 false), /* pcrel_offset */245 FALSE), /* pcrel_offset */ 239 246 }; 240 247 … … 245 252 fr30_elf_i20_reloc (abfd, reloc_entry, symbol, data, 246 253 input_section, output_bfd, error_message) 247 bfd * 248 arelent * 249 asymbol * 250 PTR 251 asection * 252 bfd * 253 char ** 254 { 255 bfd_vma 254 bfd *abfd; 255 arelent *reloc_entry; 256 asymbol *symbol; 257 PTR data; 258 asection *input_section; 259 bfd *output_bfd; 260 char **error_message ATTRIBUTE_UNUSED; 261 { 262 bfd_vma relocation; 256 263 unsigned long x; 257 264 … … 281 288 x = bfd_get_32 (abfd, (char *) data + reloc_entry->address); 282 289 x = (x & 0xff0f0000) | (relocation & 0x0000ffff) | ((relocation & 0x000f0000) << 4); 283 bfd_put_32 (abfd, x, (char *) data + reloc_entry->address);290 bfd_put_32 (abfd, (bfd_vma) x, (char *) data + reloc_entry->address); 284 291 285 292 return bfd_reloc_ok; … … 292 299 fr30_elf_i32_reloc (abfd, reloc_entry, symbol, data, 293 300 input_section, output_bfd, error_message) 294 bfd * 295 arelent * 296 asymbol * 297 PTR 298 asection * 299 bfd * 300 char ** 301 { 302 bfd_vma 301 bfd *abfd; 302 arelent *reloc_entry; 303 asymbol *symbol; 304 PTR data; 305 asection *input_section; 306 bfd *output_bfd; 307 char **error_message ATTRIBUTE_UNUSED; 308 { 309 bfd_vma relocation; 303 310 304 311 /* This part is from bfd_elf_generic_reloc. */ … … 355 362 static reloc_howto_type * 356 363 fr30_reloc_type_lookup (abfd, code) 357 bfd * 364 bfd *abfd ATTRIBUTE_UNUSED; 358 365 bfd_reloc_code_real_type code; 359 366 { … … 372 379 static void 373 380 fr30_info_to_howto_rela (abfd, cache_ptr, dst) 374 bfd * 375 arelent * 376 Elf 32_Internal_Rela *dst;381 bfd *abfd ATTRIBUTE_UNUSED; 382 arelent *cache_ptr; 383 Elf_Internal_Rela *dst; 377 384 { 378 385 unsigned int r_type; … … 388 395 389 396 static bfd_reloc_status_type 390 fr30_final_link_relocate (howto, input_bfd, input_section, contents, rel, relocation) 391 reloc_howto_type * howto; 392 bfd * input_bfd; 393 asection * input_section; 394 bfd_byte * contents; 395 Elf_Internal_Rela * rel; 396 bfd_vma relocation; 397 fr30_final_link_relocate (howto, input_bfd, input_section, contents, rel, 398 relocation) 399 reloc_howto_type *howto; 400 bfd *input_bfd; 401 asection *input_section; 402 bfd_byte *contents; 403 Elf_Internal_Rela *rel; 404 bfd_vma relocation; 397 405 { 398 406 bfd_reloc_status_type r = bfd_reloc_ok; 399 bfd_vma 400 bfd_signed_vma 407 bfd_vma x; 408 bfd_signed_vma srel; 401 409 402 410 switch (howto->type) … … 467 475 468 476 /* Relocate an FR30 ELF section. 469 There is some attempt to make this function usable for many architectures,470 both USE_REL and USE_RELA ['twould be nice if such a critter existed],471 if only to serve as a learning tool.472 477 473 478 The RELOCATE_SECTION function is called by the new ELF backend linker … … 499 504 accordingly. */ 500 505 501 static b oolean506 static bfd_boolean 502 507 fr30_elf_relocate_section (output_bfd, info, input_bfd, input_section, 503 508 contents, relocs, local_syms, local_sections) 504 bfd * output_bfd ATTRIBUTE_UNUSED; 505 struct bfd_link_info * info; 506 bfd * input_bfd; 507 asection * input_section; 508 bfd_byte * contents; 509 Elf_Internal_Rela * relocs; 510 Elf_Internal_Sym * local_syms; 511 asection ** local_sections; 512 { 513 Elf_Internal_Shdr * symtab_hdr; 514 struct elf_link_hash_entry ** sym_hashes; 515 Elf_Internal_Rela * rel; 516 Elf_Internal_Rela * relend; 509 bfd *output_bfd; 510 struct bfd_link_info *info; 511 bfd *input_bfd; 512 asection *input_section; 513 bfd_byte *contents; 514 Elf_Internal_Rela *relocs; 515 Elf_Internal_Sym *local_syms; 516 asection **local_sections; 517 { 518 Elf_Internal_Shdr *symtab_hdr; 519 struct elf_link_hash_entry **sym_hashes; 520 Elf_Internal_Rela *rel; 521 Elf_Internal_Rela *relend; 522 523 if (info->relocateable) 524 return TRUE; 517 525 518 526 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; … … 522 530 for (rel = relocs; rel < relend; rel ++) 523 531 { 524 reloc_howto_type * 525 unsigned long 526 Elf_Internal_Sym * 527 asection * 528 struct elf_link_hash_entry * 529 bfd_vma 530 bfd_reloc_status_type 531 const char * 532 int 532 reloc_howto_type *howto; 533 unsigned long r_symndx; 534 Elf_Internal_Sym *sym; 535 asection *sec; 536 struct elf_link_hash_entry *h; 537 bfd_vma relocation; 538 bfd_reloc_status_type r; 539 const char *name = NULL; 540 int r_type; 533 541 534 542 r_type = ELF32_R_TYPE (rel->r_info); … … 540 548 r_symndx = ELF32_R_SYM (rel->r_info); 541 549 542 if (info->relocateable)543 {544 /* This is a relocateable link. We don't have to change545 anything, unless the reloc is against a section symbol,546 in which case we have to adjust according to where the547 section symbol winds up in the output section. */548 if (r_symndx < symtab_hdr->sh_info)549 {550 sym = local_syms + r_symndx;551 552 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)553 {554 sec = local_sections [r_symndx];555 rel->r_addend += sec->output_offset + sym->st_value;556 }557 }558 559 continue;560 }561 562 /* This is a final link. */563 550 howto = fr30_elf_howto_table + ELF32_R_TYPE (rel->r_info); 564 551 h = NULL; … … 570 557 sym = local_syms + r_symndx; 571 558 sec = local_sections [r_symndx]; 572 relocation = (sec->output_section->vma 573 + sec->output_offset 574 + sym->st_value); 559 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); 575 560 576 561 name = bfd_elf_string_from_elf_section … … 620 605 if (! ((*info->callbacks->undefined_symbol) 621 606 (info, h->root.root.string, input_bfd, 622 input_section, rel->r_offset, true)))623 return false;607 input_section, rel->r_offset, TRUE))) 608 return FALSE; 624 609 #if 0 625 610 fprintf (stderr, "unknown: name: %s\n", name); … … 647 632 r = info->callbacks->undefined_symbol 648 633 (info, name, input_bfd, input_section, rel->r_offset, 649 true);634 TRUE); 650 635 break; 651 636 … … 672 657 673 658 if (! r) 674 return false;659 return FALSE; 675 660 } 676 661 } 677 662 678 return true;663 return TRUE; 679 664 } 680 665 … … 684 669 685 670 static asection * 686 fr30_elf_gc_mark_hook ( abfd, info, rel, h, sym)687 bfd * abfd;688 struct bfd_link_info * 689 Elf_Internal_Rela * 690 struct elf_link_hash_entry * 691 Elf_Internal_Sym * 671 fr30_elf_gc_mark_hook (sec, info, rel, h, sym) 672 asection *sec; 673 struct bfd_link_info *info ATTRIBUTE_UNUSED; 674 Elf_Internal_Rela *rel; 675 struct elf_link_hash_entry *h; 676 Elf_Internal_Sym * sym; 692 677 { 693 678 if (h != NULL) … … 715 700 } 716 701 else 717 { 718 if (!(elf_bad_symtab (abfd) 719 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 720 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 721 && sym->st_shndx != SHN_COMMON)) 722 { 723 return bfd_section_from_elf_index (abfd, sym->st_shndx); 724 } 725 } 702 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 726 703 727 704 return NULL; … … 730 707 /* Update the got entry reference counts for the section being removed. */ 731 708 732 static b oolean709 static bfd_boolean 733 710 fr30_elf_gc_sweep_hook (abfd, info, sec, relocs) 734 bfd * 735 struct bfd_link_info * 736 asection * 737 const Elf_Internal_Rela * 738 { 739 return true;711 bfd *abfd ATTRIBUTE_UNUSED; 712 struct bfd_link_info *info ATTRIBUTE_UNUSED; 713 asection *sec ATTRIBUTE_UNUSED; 714 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; 715 { 716 return TRUE; 740 717 } 741 718 … … 744 721 virtual table relocs for gc. */ 745 722 746 static b oolean723 static bfd_boolean 747 724 fr30_elf_check_relocs (abfd, info, sec, relocs) 748 725 bfd *abfd; … … 757 734 758 735 if (info->relocateable) 759 return true;736 return TRUE; 760 737 761 738 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; … … 783 760 case R_FR30_GNU_VTINHERIT: 784 761 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 785 return false;762 return FALSE; 786 763 break; 787 764 … … 790 767 case R_FR30_GNU_VTENTRY: 791 768 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 792 return false;769 return FALSE; 793 770 break; 794 771 } 795 772 } 796 773 797 return true;774 return TRUE; 798 775 } 799 776 800 777 801 778 #define ELF_ARCH bfd_arch_fr30 802 #define ELF_MACHINE_CODE EM_CYGNUS_FR30 779 #define ELF_MACHINE_CODE EM_FR30 780 #define ELF_MACHINE_ALT1 EM_CYGNUS_FR30 803 781 #define ELF_MAXPAGESIZE 0x1000 804 782 … … 814 792 815 793 #define elf_backend_can_gc_sections 1 794 #define elf_backend_rela_normal 1 816 795 817 796 #define bfd_elf32_bfd_reloc_type_lookup fr30_reloc_type_lookup -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.