Changeset 609 for branches/GNU/src/binutils/bfd/elf-m10200.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf-m10200.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* Matsushita 10200 specific support for 32-bit ELF 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001 2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 3 3 Free Software Foundation, Inc. 4 4 … … 27 27 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); 28 28 static void mn10200_info_to_howto 29 PARAMS ((bfd *, arelent *, Elf 32_Internal_Rela *));30 static b oolean mn10200_elf_relax_delete_bytes29 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 30 static bfd_boolean mn10200_elf_relax_delete_bytes 31 31 PARAMS ((bfd *, asection *, bfd_vma, int)); 32 static boolean mn10200_elf_symbol_address_p 33 PARAMS ((bfd *, asection *, Elf32_External_Sym *, bfd_vma)); 34 35 /* We have to use RELA instructions since md_apply_fix3 in the assembler 36 does absolutely nothing. */ 37 #define USE_RELA 32 static bfd_boolean mn10200_elf_symbol_address_p 33 PARAMS ((bfd *, asection *, Elf_Internal_Sym *, bfd_vma)); 34 static bfd_reloc_status_type mn10200_elf_final_link_relocate 35 PARAMS ((reloc_howto_type *, bfd *, bfd *, asection *, 36 bfd_byte *, bfd_vma, bfd_vma, bfd_vma, 37 struct bfd_link_info *, asection *, int)); 38 static bfd_boolean mn10200_elf_relocate_section 39 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, 40 bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, 41 asection **)); 42 static bfd_boolean mn10200_elf_relax_section 43 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); 44 static bfd_byte * mn10200_elf_get_relocated_section_contents 45 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, 46 bfd_byte *, bfd_boolean, asymbol **)); 38 47 39 48 enum reloc_type { … … 55 64 2, 56 65 16, 57 false,66 FALSE, 58 67 0, 59 68 complain_overflow_bitfield, 60 69 bfd_elf_generic_reloc, 61 70 "R_MN10200_NONE", 62 false,63 0, 64 0, 65 false),71 FALSE, 72 0, 73 0, 74 FALSE), 66 75 /* Standard 32 bit reloc. */ 67 76 HOWTO (R_MN10200_32, … … 69 78 2, 70 79 32, 71 false,80 FALSE, 72 81 0, 73 82 complain_overflow_bitfield, 74 83 bfd_elf_generic_reloc, 75 84 "R_MN10200_32", 76 false,85 FALSE, 77 86 0xffffffff, 78 87 0xffffffff, 79 false),88 FALSE), 80 89 /* Standard 16 bit reloc. */ 81 90 HOWTO (R_MN10200_16, … … 83 92 1, 84 93 16, 85 false,94 FALSE, 86 95 0, 87 96 complain_overflow_bitfield, 88 97 bfd_elf_generic_reloc, 89 98 "R_MN10200_16", 90 false,99 FALSE, 91 100 0xffff, 92 101 0xffff, 93 false),102 FALSE), 94 103 /* Standard 8 bit reloc. */ 95 104 HOWTO (R_MN10200_8, … … 97 106 0, 98 107 8, 99 false,108 FALSE, 100 109 0, 101 110 complain_overflow_bitfield, 102 111 bfd_elf_generic_reloc, 103 112 "R_MN10200_8", 104 false,113 FALSE, 105 114 0xff, 106 115 0xff, 107 false),116 FALSE), 108 117 /* Standard 24 bit reloc. */ 109 118 HOWTO (R_MN10200_24, … … 111 120 2, 112 121 24, 113 false,122 FALSE, 114 123 0, 115 124 complain_overflow_bitfield, 116 125 bfd_elf_generic_reloc, 117 126 "R_MN10200_24", 118 false,127 FALSE, 119 128 0xffffff, 120 129 0xffffff, 121 false),130 FALSE), 122 131 /* Simple 8 pc-relative reloc. */ 123 132 HOWTO (R_MN10200_PCREL8, … … 125 134 0, 126 135 8, 127 true,136 TRUE, 128 137 0, 129 138 complain_overflow_bitfield, 130 139 bfd_elf_generic_reloc, 131 140 "R_MN10200_PCREL8", 132 false,141 FALSE, 133 142 0xff, 134 143 0xff, 135 true),144 TRUE), 136 145 /* Simple 16 pc-relative reloc. */ 137 146 HOWTO (R_MN10200_PCREL16, … … 139 148 1, 140 149 16, 141 true,150 TRUE, 142 151 0, 143 152 complain_overflow_bitfield, 144 153 bfd_elf_generic_reloc, 145 154 "R_MN10200_PCREL16", 146 false,155 FALSE, 147 156 0xffff, 148 157 0xffff, 149 true),158 TRUE), 150 159 /* Simple 32bit pc-relative reloc with a 1 byte adjustment 151 160 to get the pc-relative offset correct. */ … … 154 163 2, 155 164 24, 156 true,165 TRUE, 157 166 0, 158 167 complain_overflow_bitfield, 159 168 bfd_elf_generic_reloc, 160 169 "R_MN10200_PCREL24", 161 false,170 FALSE, 162 171 0xffffff, 163 172 0xffffff, 164 true),173 TRUE), 165 174 }; 166 175 … … 205 214 bfd *abfd ATTRIBUTE_UNUSED; 206 215 arelent *cache_ptr; 207 Elf 32_Internal_Rela *dst;216 Elf_Internal_Rela *dst; 208 217 { 209 218 unsigned int r_type; … … 215 224 216 225 /* Perform a relocation as part of a final link. */ 226 217 227 static bfd_reloc_status_type 218 228 mn10200_elf_final_link_relocate (howto, input_bfd, output_bfd, … … 319 329 320 330 /* Relocate an MN10200 ELF section. */ 321 static b oolean331 static bfd_boolean 322 332 mn10200_elf_relocate_section (output_bfd, info, input_bfd, input_section, 323 333 contents, relocs, local_syms, local_sections) … … 335 345 Elf_Internal_Rela *rel, *relend; 336 346 347 if (info->relocateable) 348 return TRUE; 349 337 350 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 338 351 sym_hashes = elf_sym_hashes (input_bfd); … … 355 368 howto = elf_mn10200_howto_table + r_type; 356 369 357 if (info->relocateable)358 {359 /* This is a relocateable link. We don't have to change360 anything, unless the reloc is against a section symbol,361 in which case we have to adjust according to where the362 section symbol winds up in the output section. */363 if (r_symndx < symtab_hdr->sh_info)364 {365 sym = local_syms + r_symndx;366 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)367 {368 sec = local_sections[r_symndx];369 rel->r_addend += sec->output_offset + sym->st_value;370 }371 }372 373 continue;374 }375 376 /* This is a final link. */377 370 h = NULL; 378 371 sym = NULL; … … 382 375 sym = local_syms + r_symndx; 383 376 sec = local_sections[r_symndx]; 384 relocation = (sec->output_section->vma 385 + sec->output_offset 386 + sym->st_value); 377 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); 387 378 } 388 379 else … … 406 397 if (! ((*info->callbacks->undefined_symbol) 407 398 (info, h->root.root.string, input_bfd, 408 input_section, rel->r_offset, true)))409 return false;399 input_section, rel->r_offset, TRUE))) 400 return FALSE; 410 401 relocation = 0; 411 402 } … … 439 430 (info, name, howto->name, (bfd_vma) 0, 440 431 input_bfd, input_section, rel->r_offset))) 441 return false;432 return FALSE; 442 433 break; 443 434 … … 445 436 if (! ((*info->callbacks->undefined_symbol) 446 437 (info, name, input_bfd, input_section, 447 rel->r_offset, true)))448 return false;438 rel->r_offset, TRUE))) 439 return FALSE; 449 440 break; 450 441 … … 469 460 (info, msg, name, input_bfd, input_section, 470 461 rel->r_offset))) 471 return false;462 return FALSE; 472 463 break; 473 464 } … … 475 466 } 476 467 477 return true;468 return TRUE; 478 469 } 479 470 … … 507 498 and somewhat more difficult to support. */ 508 499 509 static b oolean500 static bfd_boolean 510 501 mn10200_elf_relax_section (abfd, sec, link_info, again) 511 502 bfd *abfd; 512 503 asection *sec; 513 504 struct bfd_link_info *link_info; 514 b oolean *again;505 bfd_boolean *again; 515 506 { 516 507 Elf_Internal_Shdr *symtab_hdr; 517 508 Elf_Internal_Rela *internal_relocs; 518 Elf_Internal_Rela *free_relocs = NULL;519 509 Elf_Internal_Rela *irel, *irelend; 520 510 bfd_byte *contents = NULL; 521 bfd_byte *free_contents = NULL; 522 Elf32_External_Sym *extsyms = NULL; 523 Elf32_External_Sym *free_extsyms = NULL; 511 Elf_Internal_Sym *isymbuf = NULL; 524 512 525 513 /* Assume nothing changes. */ 526 *again = false;514 *again = FALSE; 527 515 528 516 /* We don't have to do anything for a relocateable link, if … … 533 521 || sec->reloc_count == 0 534 522 || (sec->flags & SEC_CODE) == 0) 535 return true;523 return TRUE; 536 524 537 525 /* If this is the first time we have been called for this section, … … 548 536 if (internal_relocs == NULL) 549 537 goto error_return; 550 if (! link_info->keep_memory)551 free_relocs = internal_relocs;552 538 553 539 /* Walk through them looking for relaxing opportunities. */ … … 576 562 if (contents == NULL) 577 563 goto error_return; 578 free_contents = contents;579 564 580 565 if (! bfd_get_section_contents (abfd, sec, contents, … … 584 569 } 585 570 586 /* Read this BFD's symbols if we haven't done so already. */ 587 if (extsyms == NULL) 588 { 589 /* Get cached copy if it exists. */ 590 if (symtab_hdr->contents != NULL) 591 extsyms = (Elf32_External_Sym *) symtab_hdr->contents; 592 else 593 { 594 /* Go get them off disk. */ 595 extsyms = ((Elf32_External_Sym *) 596 bfd_malloc (symtab_hdr->sh_size)); 597 if (extsyms == NULL) 598 goto error_return; 599 free_extsyms = extsyms; 600 if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0 601 || (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd) 602 != symtab_hdr->sh_size)) 603 goto error_return; 604 } 571 /* Read this BFD's local symbols if we haven't done so already. */ 572 if (isymbuf == NULL && symtab_hdr->sh_info != 0) 573 { 574 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 575 if (isymbuf == NULL) 576 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 577 symtab_hdr->sh_info, 0, 578 NULL, NULL, NULL); 579 if (isymbuf == NULL) 580 goto error_return; 605 581 } 606 582 … … 608 584 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 609 585 { 610 Elf_Internal_Sym isym; 586 /* A local symbol. */ 587 Elf_Internal_Sym *isym; 611 588 asection *sym_sec; 612 589 613 /* A local symbol. */ 614 bfd_elf32_swap_symbol_in (abfd, 615 extsyms + ELF32_R_SYM (irel->r_info), 616 &isym); 617 618 sym_sec = bfd_section_from_elf_index (abfd, isym.st_shndx); 619 symval = (isym.st_value 590 isym = isymbuf + ELF32_R_SYM (irel->r_info); 591 if (isym->st_shndx == SHN_UNDEF) 592 sym_sec = bfd_und_section_ptr; 593 else if (isym->st_shndx == SHN_ABS) 594 sym_sec = bfd_abs_section_ptr; 595 else if (isym->st_shndx == SHN_COMMON) 596 sym_sec = bfd_com_section_ptr; 597 else 598 sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); 599 symval = (isym->st_value 620 600 + sym_sec->output_section->vma 621 601 + sym_sec->output_offset); … … 678 658 /* Note that we've changed the relocs, section contents, etc. */ 679 659 elf_section_data (sec)->relocs = internal_relocs; 680 free_relocs = NULL;681 682 660 elf_section_data (sec)->this_hdr.contents = contents; 683 free_contents = NULL; 684 685 symtab_hdr->contents = (bfd_byte *) extsyms; 686 free_extsyms = NULL; 661 symtab_hdr->contents = (unsigned char *) isymbuf; 687 662 688 663 /* Fix the opcode. */ … … 706 681 /* That will change things, so, we should relax again. 707 682 Note that this is not required, and it may be slow. */ 708 *again = true;683 *again = TRUE; 709 684 } 710 685 } … … 736 711 /* Note that we've changed the relocs, section contents, etc. */ 737 712 elf_section_data (sec)->relocs = internal_relocs; 738 free_relocs = NULL;739 740 713 elf_section_data (sec)->this_hdr.contents = contents; 741 free_contents = NULL; 742 743 symtab_hdr->contents = (bfd_byte *) extsyms; 744 free_extsyms = NULL; 714 symtab_hdr->contents = (unsigned char *) isymbuf; 745 715 746 716 /* Fix the opcode. */ … … 758 728 /* That will change things, so, we should relax again. 759 729 Note that this is not required, and it may be slow. */ 760 *again = true;730 *again = TRUE; 761 731 } 762 732 } … … 827 797 /* We also have to be sure there is no symbol/label 828 798 at the unconditional branch. */ 829 if (mn10200_elf_symbol_address_p (abfd, sec, extsyms,799 if (mn10200_elf_symbol_address_p (abfd, sec, isymbuf, 830 800 irel->r_offset + 1)) 831 801 continue; … … 833 803 /* Note that we've changed the relocs, section contents, etc. */ 834 804 elf_section_data (sec)->relocs = internal_relocs; 835 free_relocs = NULL;836 837 805 elf_section_data (sec)->this_hdr.contents = contents; 838 free_contents = NULL; 839 840 symtab_hdr->contents = (bfd_byte *) extsyms; 841 free_extsyms = NULL; 806 symtab_hdr->contents = (unsigned char *) isymbuf; 842 807 843 808 /* Reverse the condition of the first branch. */ … … 916 881 /* That will change things, so, we should relax again. 917 882 Note that this is not required, and it may be slow. */ 918 *again = true;883 *again = TRUE; 919 884 } 920 885 … … 957 922 /* Note that we've changed the reldection contents, etc. */ 958 923 elf_section_data (sec)->relocs = internal_relocs; 959 free_relocs = NULL;960 961 924 elf_section_data (sec)->this_hdr.contents = contents; 962 free_contents = NULL; 963 964 symtab_hdr->contents = (bfd_byte *) extsyms; 965 free_extsyms = NULL; 925 symtab_hdr->contents = (unsigned char *) isymbuf; 966 926 967 927 /* Fix the opcode. */ … … 984 944 /* That will change things, so, we should relax again. 985 945 Note that this is not required, and it may be slow. */ 986 *again = true;946 *again = TRUE; 987 947 break; 988 948 … … 1001 961 /* Note that we've changed the reldection contents, etc. */ 1002 962 elf_section_data (sec)->relocs = internal_relocs; 1003 free_relocs = NULL;1004 1005 963 elf_section_data (sec)->this_hdr.contents = contents; 1006 free_contents = NULL; 1007 1008 symtab_hdr->contents = (bfd_byte *) extsyms; 1009 free_extsyms = NULL; 964 symtab_hdr->contents = (unsigned char *) isymbuf; 1010 965 1011 966 if ((code & 0xfc) == 0x74) … … 1040 995 /* That will change things, so, we should relax again. 1041 996 Note that this is not required, and it may be slow. */ 1042 *again = true;997 *again = TRUE; 1043 998 break; 1044 999 … … 1089 1044 /* Note that we've changed the reldection contents, etc. */ 1090 1045 elf_section_data (sec)->relocs = internal_relocs; 1091 free_relocs = NULL;1092 1093 1046 elf_section_data (sec)->this_hdr.contents = contents; 1094 free_contents = NULL; 1095 1096 symtab_hdr->contents = (bfd_byte *) extsyms; 1097 free_extsyms = NULL; 1047 symtab_hdr->contents = (unsigned char *) isymbuf; 1098 1048 1099 1049 /* Fix the opcode. */ … … 1146 1096 /* That will change things, so, we should relax again. 1147 1097 Note that this is not required, and it may be slow. */ 1148 *again = true;1098 *again = TRUE; 1149 1099 break; 1150 1100 … … 1153 1103 /* Note that we've changed the reldection contents, etc. */ 1154 1104 elf_section_data (sec)->relocs = internal_relocs; 1155 free_relocs = NULL;1156 1157 1105 elf_section_data (sec)->this_hdr.contents = contents; 1158 free_contents = NULL; 1159 1160 symtab_hdr->contents = (bfd_byte *) extsyms; 1161 free_extsyms = NULL; 1106 symtab_hdr->contents = (unsigned char *) isymbuf; 1162 1107 1163 1108 bfd_put_8 (abfd, 0xcc + (code & 0x03), … … 1182 1127 /* That will change things, so, we should relax again. 1183 1128 Note that this is not required, and it may be slow. */ 1184 *again = true;1129 *again = TRUE; 1185 1130 break; 1186 1131 } … … 1189 1134 } 1190 1135 1191 if (free_relocs != NULL) 1192 { 1193 free (free_relocs); 1194 free_relocs = NULL; 1195 } 1196 1197 if (free_contents != NULL) 1136 if (isymbuf != NULL 1137 && symtab_hdr->contents != (unsigned char *) isymbuf) 1198 1138 { 1199 1139 if (! link_info->keep_memory) 1200 free (free_contents); 1140 free (isymbuf); 1141 else 1142 { 1143 /* Cache the symbols for elf_link_input_bfd. */ 1144 symtab_hdr->contents = (unsigned char *) isymbuf; 1145 } 1146 } 1147 1148 if (contents != NULL 1149 && elf_section_data (sec)->this_hdr.contents != contents) 1150 { 1151 if (! link_info->keep_memory) 1152 free (contents); 1201 1153 else 1202 1154 { … … 1204 1156 elf_section_data (sec)->this_hdr.contents = contents; 1205 1157 } 1206 free_contents = NULL;1207 1158 } 1208 1159 1209 if (free_extsyms != NULL) 1210 { 1211 if (! link_info->keep_memory) 1212 free (free_extsyms); 1213 else 1214 { 1215 /* Cache the symbols for elf_link_input_bfd. */ 1216 symtab_hdr->contents = extsyms; 1217 } 1218 free_extsyms = NULL; 1219 } 1220 1221 return true; 1160 if (internal_relocs != NULL 1161 && elf_section_data (sec)->relocs != internal_relocs) 1162 free (internal_relocs); 1163 1164 return TRUE; 1222 1165 1223 1166 error_return: 1224 if (free_relocs != NULL) 1225 free (free_relocs); 1226 if (free_contents != NULL) 1227 free (free_contents); 1228 if (free_extsyms != NULL) 1229 free (free_extsyms); 1230 return false; 1167 if (isymbuf != NULL 1168 && symtab_hdr->contents != (unsigned char *) isymbuf) 1169 free (isymbuf); 1170 if (contents != NULL 1171 && elf_section_data (sec)->this_hdr.contents != contents) 1172 free (contents); 1173 if (internal_relocs != NULL 1174 && elf_section_data (sec)->relocs != internal_relocs) 1175 free (internal_relocs); 1176 1177 return FALSE; 1231 1178 } 1232 1179 1233 1180 /* Delete some bytes from a section while relaxing. */ 1234 1181 1235 static b oolean1182 static bfd_boolean 1236 1183 mn10200_elf_relax_delete_bytes (abfd, sec, addr, count) 1237 1184 bfd *abfd; … … 1241 1188 { 1242 1189 Elf_Internal_Shdr *symtab_hdr; 1243 Elf32_External_Sym *extsyms; 1244 int shndx, index; 1190 unsigned int sec_shndx; 1245 1191 bfd_byte *contents; 1246 1192 Elf_Internal_Rela *irel, *irelend; 1247 1193 Elf_Internal_Rela *irelalign; 1248 1194 bfd_vma toaddr; 1249 Elf 32_External_Sym *esym, *esymend;1250 struct elf_link_hash_entry *sym_hash;1251 1252 s ymtab_hdr = &elf_tdata (abfd)->symtab_hdr;1253 extsyms = (Elf32_External_Sym *) symtab_hdr->contents;1254 1255 s hndx = _bfd_elf_section_from_bfd_section (abfd, sec);1195 Elf_Internal_Sym *isym; 1196 Elf_Internal_Sym *isymend; 1197 struct elf_link_hash_entry **sym_hashes; 1198 struct elf_link_hash_entry **end_hashes; 1199 unsigned int symcount; 1200 1201 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 1256 1202 1257 1203 contents = elf_section_data (sec)->this_hdr.contents; … … 1267 1213 1268 1214 /* Actually delete the bytes. */ 1269 memmove (contents + addr, contents + addr + count, toaddr - addr - count); 1215 memmove (contents + addr, contents + addr + count, 1216 (size_t) (toaddr - addr - count)); 1270 1217 sec->_cooked_size -= count; 1271 1218 … … 1280 1227 1281 1228 /* Adjust the local symbols defined in this section. */ 1282 esym = extsyms;1283 esymend = esym + symtab_hdr->sh_info;1284 for ( ; esym < esymend; esym++)1229 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1230 isym = (Elf_Internal_Sym *) symtab_hdr->contents; 1231 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++) 1285 1232 { 1286 Elf_Internal_Sym isym; 1287 1288 bfd_elf32_swap_symbol_in (abfd, esym, &isym); 1289 1290 if (isym.st_shndx == shndx 1291 && isym.st_value > addr 1292 && isym.st_value < toaddr) 1293 { 1294 isym.st_value -= count; 1295 bfd_elf32_swap_symbol_out (abfd, &isym, esym); 1296 } 1233 if (isym->st_shndx == sec_shndx 1234 && isym->st_value > addr 1235 && isym->st_value < toaddr) 1236 isym->st_value -= count; 1297 1237 } 1298 1238 1299 1239 /* Now adjust the global symbols defined in this section. */ 1300 esym = extsyms + symtab_hdr->sh_info; 1301 esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)); 1302 for (index = 0; esym < esymend; esym++, index++) 1240 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) 1241 - symtab_hdr->sh_info); 1242 sym_hashes = elf_sym_hashes (abfd); 1243 end_hashes = sym_hashes + symcount; 1244 for (; sym_hashes < end_hashes; sym_hashes++) 1303 1245 { 1304 Elf_Internal_Sym isym; 1305 1306 bfd_elf32_swap_symbol_in (abfd, esym, &isym); 1307 sym_hash = elf_sym_hashes (abfd)[index]; 1308 if (isym.st_shndx == shndx 1309 && ((sym_hash)->root.type == bfd_link_hash_defined 1310 || (sym_hash)->root.type == bfd_link_hash_defweak) 1311 && (sym_hash)->root.u.def.section == sec 1312 && (sym_hash)->root.u.def.value > addr 1313 && (sym_hash)->root.u.def.value < toaddr) 1314 { 1315 (sym_hash)->root.u.def.value -= count; 1246 struct elf_link_hash_entry *sym_hash = *sym_hashes; 1247 if ((sym_hash->root.type == bfd_link_hash_defined 1248 || sym_hash->root.type == bfd_link_hash_defweak) 1249 && sym_hash->root.u.def.section == sec 1250 && sym_hash->root.u.def.value > addr 1251 && sym_hash->root.u.def.value < toaddr) 1252 { 1253 sym_hash->root.u.def.value -= count; 1316 1254 } 1317 1255 } 1318 1256 1319 return true;1257 return TRUE; 1320 1258 } 1321 1259 1322 /* Return trueif a symbol exists at the given address, else return1323 false. */1324 static b oolean1325 mn10200_elf_symbol_address_p (abfd, sec, extsyms, addr)1260 /* Return TRUE if a symbol exists at the given address, else return 1261 FALSE. */ 1262 static bfd_boolean 1263 mn10200_elf_symbol_address_p (abfd, sec, isym, addr) 1326 1264 bfd *abfd; 1327 1265 asection *sec; 1328 Elf 32_External_Sym *extsyms;1266 Elf_Internal_Sym *isym; 1329 1267 bfd_vma addr; 1330 1268 { 1331 1269 Elf_Internal_Shdr *symtab_hdr; 1332 int shndx; 1333 Elf32_External_Sym *esym, *esymend; 1334 struct elf_link_hash_entry **sym_hash, **sym_hash_end; 1335 1270 unsigned int sec_shndx; 1271 Elf_Internal_Sym *isymend; 1272 struct elf_link_hash_entry **sym_hashes; 1273 struct elf_link_hash_entry **end_hashes; 1274 unsigned int symcount; 1275 1276 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 1277 1278 /* Examine all the local symbols. */ 1336 1279 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1337 shndx = _bfd_elf_section_from_bfd_section (abfd, sec); 1338 1339 /* Examine all the symbols. */ 1340 esym = extsyms; 1341 esymend = esym + symtab_hdr->sh_info; 1342 for (; esym < esymend; esym++) 1280 for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++) 1343 1281 { 1344 Elf_Internal_Sym isym; 1345 1346 bfd_elf32_swap_symbol_in (abfd, esym, &isym); 1347 1348 if (isym.st_shndx == shndx 1349 && isym.st_value == addr) 1350 return true; 1282 if (isym->st_shndx == sec_shndx 1283 && isym->st_value == addr) 1284 return TRUE; 1351 1285 } 1352 1286 1353 sym _hash = elf_sym_hashes (abfd);1354 sym_hash_end = (sym_hash 1355 + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) 1356 - symtab_hdr->sh_info));1357 for (; sym_hash < sym_hash_end; sym_hash++)1287 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) 1288 - symtab_hdr->sh_info); 1289 sym_hashes = elf_sym_hashes (abfd); 1290 end_hashes = sym_hashes + symcount; 1291 for (; sym_hashes < end_hashes; sym_hashes++) 1358 1292 { 1359 if (((*sym_hash)->root.type == bfd_link_hash_defined 1360 || (*sym_hash)->root.type == bfd_link_hash_defweak) 1361 && (*sym_hash)->root.u.def.section == sec 1362 && (*sym_hash)->root.u.def.value == addr) 1363 return true; 1293 struct elf_link_hash_entry *sym_hash = *sym_hashes; 1294 if ((sym_hash->root.type == bfd_link_hash_defined 1295 || sym_hash->root.type == bfd_link_hash_defweak) 1296 && sym_hash->root.u.def.section == sec 1297 && sym_hash->root.u.def.value == addr) 1298 return TRUE; 1364 1299 } 1365 return false; 1300 1301 return FALSE; 1366 1302 } 1367 1303 … … 1376 1312 struct bfd_link_order *link_order; 1377 1313 bfd_byte *data; 1378 b oolean relocateable;1314 bfd_boolean relocateable; 1379 1315 asymbol **symbols; 1380 1316 { … … 1384 1320 asection **sections = NULL; 1385 1321 Elf_Internal_Rela *internal_relocs = NULL; 1386 Elf32_External_Sym *external_syms = NULL; 1387 Elf_Internal_Sym *internal_syms = NULL; 1322 Elf_Internal_Sym *isymbuf = NULL; 1388 1323 1389 1324 /* We only need to handle the case of relaxing, or of having a … … 1399 1334 1400 1335 memcpy (data, elf_section_data (input_section)->this_hdr.contents, 1401 input_section->_raw_size);1336 (size_t) input_section->_raw_size); 1402 1337 1403 1338 if ((input_section->flags & SEC_RELOC) != 0 1404 1339 && input_section->reloc_count > 0) 1405 1340 { 1406 Elf_Internal_Sym *isymp; 1341 Elf_Internal_Sym *isym; 1342 Elf_Internal_Sym *isymend; 1407 1343 asection **secpp; 1408 Elf32_External_Sym *esym, *esymend; 1409 1410 if (symtab_hdr->contents != NULL) 1411 external_syms = (Elf32_External_Sym *) symtab_hdr->contents; 1412 else 1413 { 1414 external_syms = ((Elf32_External_Sym *) 1415 bfd_malloc (symtab_hdr->sh_info 1416 * sizeof (Elf32_External_Sym))); 1417 if (external_syms == NULL && symtab_hdr->sh_info > 0) 1418 goto error_return; 1419 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0 1420 || (bfd_read (external_syms, sizeof (Elf32_External_Sym), 1421 symtab_hdr->sh_info, input_bfd) 1422 != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)))) 1423 goto error_return; 1424 } 1344 bfd_size_type amt; 1425 1345 1426 1346 internal_relocs = (_bfd_elf32_link_read_relocs 1427 1347 (input_bfd, input_section, (PTR) NULL, 1428 (Elf_Internal_Rela *) NULL, false));1348 (Elf_Internal_Rela *) NULL, FALSE)); 1429 1349 if (internal_relocs == NULL) 1430 1350 goto error_return; 1431 1351 1432 internal_syms = ((Elf_Internal_Sym *) 1433 bfd_malloc (symtab_hdr->sh_info 1434 * sizeof (Elf_Internal_Sym))); 1435 if (internal_syms == NULL && symtab_hdr->sh_info > 0) 1352 if (symtab_hdr->sh_info != 0) 1353 { 1354 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 1355 if (isymbuf == NULL) 1356 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, 1357 symtab_hdr->sh_info, 0, 1358 NULL, NULL, NULL); 1359 if (isymbuf == NULL) 1360 goto error_return; 1361 } 1362 1363 amt = symtab_hdr->sh_info; 1364 amt *= sizeof (asection *); 1365 sections = (asection **) bfd_malloc (amt); 1366 if (sections == NULL && amt != 0) 1436 1367 goto error_return; 1437 1368 1438 sections = (asection **) bfd_malloc (symtab_hdr->sh_info 1439 * sizeof (asection *)); 1440 if (sections == NULL && symtab_hdr->sh_info > 0) 1441 goto error_return; 1442 1443 isymp = internal_syms; 1444 secpp = sections; 1445 esym = external_syms; 1446 esymend = esym + symtab_hdr->sh_info; 1447 for (; esym < esymend; ++esym, ++isymp, ++secpp) 1369 isymend = isymbuf + symtab_hdr->sh_info; 1370 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp) 1448 1371 { 1449 1372 asection *isec; 1450 1373 1451 bfd_elf32_swap_symbol_in (input_bfd, esym, isymp); 1452 1453 if (isymp->st_shndx == SHN_UNDEF) 1374 if (isym->st_shndx == SHN_UNDEF) 1454 1375 isec = bfd_und_section_ptr; 1455 else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE) 1456 isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); 1457 else if (isymp->st_shndx == SHN_ABS) 1376 else if (isym->st_shndx == SHN_ABS) 1458 1377 isec = bfd_abs_section_ptr; 1459 else if (isym p->st_shndx == SHN_COMMON)1378 else if (isym->st_shndx == SHN_COMMON) 1460 1379 isec = bfd_com_section_ptr; 1461 1380 else 1462 { 1463 /* Who knows? */ 1464 isec = NULL; 1465 } 1381 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); 1466 1382 1467 1383 *secpp = isec; … … 1470 1386 if (! mn10200_elf_relocate_section (output_bfd, link_info, input_bfd, 1471 1387 input_section, data, internal_relocs, 1472 i nternal_syms, sections))1388 isymbuf, sections)) 1473 1389 goto error_return; 1474 1390 1475 1391 if (sections != NULL) 1476 1392 free (sections); 1477 sections = NULL; 1478 if (internal_syms != NULL) 1479 free (internal_syms); 1480 internal_syms = NULL; 1481 if (external_syms != NULL && symtab_hdr->contents == NULL) 1482 free (external_syms); 1483 external_syms = NULL; 1484 if (internal_relocs != elf_section_data (input_section)->relocs) 1393 if (isymbuf != NULL 1394 && symtab_hdr->contents != (unsigned char *) isymbuf) 1395 free (isymbuf); 1396 if (elf_section_data (input_section)->relocs != internal_relocs) 1485 1397 free (internal_relocs); 1486 internal_relocs = NULL;1487 1398 } 1488 1399 … … 1490 1401 1491 1402 error_return: 1492 if (internal_relocs != NULL1493 && internal_relocs != elf_section_data (input_section)->relocs)1494 free (internal_relocs);1495 if (external_syms != NULL && symtab_hdr->contents == NULL)1496 free (external_syms);1497 if (internal_syms != NULL)1498 free (internal_syms);1499 1403 if (sections != NULL) 1500 1404 free (sections); 1405 if (isymbuf != NULL 1406 && symtab_hdr->contents != (unsigned char *) isymbuf) 1407 free (isymbuf); 1408 if (internal_relocs != NULL 1409 && elf_section_data (input_section)->relocs != internal_relocs) 1410 free (internal_relocs); 1501 1411 return NULL; 1502 1412 } … … 1505 1415 #define TARGET_LITTLE_NAME "elf32-mn10200" 1506 1416 #define ELF_ARCH bfd_arch_mn10200 1507 #define ELF_MACHINE_CODE EM_CYGNUS_MN10200 1417 #define ELF_MACHINE_CODE EM_MN10200 1418 #define ELF_MACHINE_ALT1 EM_CYGNUS_MN10200 1508 1419 #define ELF_MAXPAGESIZE 0x1000 1509 1420 1421 #define elf_backend_rela_normal 1 1510 1422 #define elf_info_to_howto mn10200_info_to_howto 1511 1423 #define elf_info_to_howto_rel 0 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.