1 /* xSYM symbol-file support for BFD. 2 Copyright (C) 1999-2016 Free Software Foundation, Inc. 3 4 This file is part of BFD, the Binary File Descriptor library. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 /* xSYM is the debugging format used by CodeWarrior on Mac OS classic. */ 22 23 #include "sysdep.h" 24 #include "alloca-conf.h" 25 #include "xsym.h" 26 #include "bfd.h" 27 #include "libbfd.h" 28 29 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup 30 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info 31 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook 32 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name 33 #define bfd_sym_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) 34 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno 35 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line 36 #define bfd_sym_find_line _bfd_nosymbols_find_line 37 #define bfd_sym_find_inliner_info _bfd_nosymbols_find_inliner_info 38 #define bfd_sym_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string 39 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol 40 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols 41 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol 42 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach 43 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents 44 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents 45 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents 46 #define bfd_sym_bfd_relax_section bfd_generic_relax_section 47 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections 48 #define bfd_sym_bfd_lookup_section_flags bfd_generic_lookup_section_flags 49 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections 50 #define bfd_sym_bfd_is_group_section bfd_generic_is_group_section 51 #define bfd_sym_bfd_discard_group bfd_generic_discard_group 52 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked 53 #define bfd_sym_bfd_define_common_symbol bfd_generic_define_common_symbol 54 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create 55 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols 56 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms 57 #define bfd_sym_bfd_copy_link_hash_symbol_type \ 58 _bfd_generic_copy_link_hash_symbol_type 59 #define bfd_sym_bfd_final_link _bfd_generic_final_link 60 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section 61 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window 62 #define bfd_sym_bfd_link_check_relocs _bfd_generic_link_check_relocs 63 64 extern const bfd_target sym_vec; 65 66 static int 67 pstrcmp (const char *as, const char *bs) 68 { 69 const unsigned char *a = (const unsigned char *) as; 70 const unsigned char *b = (const unsigned char *) bs; 71 unsigned char clen; 72 int ret; 73 74 clen = (a[0] > b[0]) ? b[0] : a[0]; 75 ret = memcmp (a + 1, b + 1, clen); 76 if (ret != 0) 77 return ret; 78 79 if (a[0] == b[0]) 80 return 0; 81 else if (a[0] < b[0]) 82 return -1; 83 else 84 return 1; 85 } 86 87 static unsigned long 88 compute_offset (unsigned long first_page, 89 unsigned long page_size, 90 unsigned long entry_size, 91 unsigned long sym_index) 92 { 93 unsigned long entries_per_page = page_size / entry_size; 94 unsigned long page_number = first_page + (sym_index / entries_per_page); 95 unsigned long page_offset = (sym_index % entries_per_page) * entry_size; 96 97 return (page_number * page_size) + page_offset; 98 } 99 100 bfd_boolean 101 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED) 102 { 103 return 1; 104 } 105 106 void 107 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED, 108 void * afile ATTRIBUTE_UNUSED, 109 asymbol *symbol ATTRIBUTE_UNUSED, 110 bfd_print_symbol_type how ATTRIBUTE_UNUSED) 111 { 112 return; 113 } 114 115 bfd_boolean 116 bfd_sym_valid (bfd *abfd) 117 { 118 if (abfd == NULL || abfd->xvec == NULL) 119 return 0; 120 121 return abfd->xvec == &sym_vec; 122 } 123 124 unsigned char * 125 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb) 126 { 127 unsigned char *rstr; 128 long ret; 129 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size; 130 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size; 131 132 rstr = bfd_alloc (abfd, table_size); 133 if (rstr == NULL) 134 return rstr; 135 136 bfd_seek (abfd, table_offset, SEEK_SET); 137 ret = bfd_bread (rstr, table_size, abfd); 138 if (ret < 0 || (unsigned long) ret != table_size) 139 { 140 bfd_release (abfd, rstr); 141 return NULL; 142 } 143 144 return rstr; 145 } 146 147 void 148 bfd_sym_parse_file_reference_v32 (unsigned char *buf, 149 size_t len, 150 bfd_sym_file_reference *entry) 151 { 152 BFD_ASSERT (len == 6); 153 154 entry->fref_frte_index = bfd_getb16 (buf); 155 entry->fref_offset = bfd_getb32 (buf + 2); 156 } 157 158 void 159 bfd_sym_parse_disk_table_v32 (unsigned char *buf, 160 size_t len, 161 bfd_sym_table_info *table) 162 { 163 BFD_ASSERT (len == 8); 164 165 table->dti_first_page = bfd_getb16 (buf); 166 table->dti_page_count = bfd_getb16 (buf + 2); 167 table->dti_object_count = bfd_getb32 (buf + 4); 168 } 169 170 void 171 bfd_sym_parse_header_v32 (unsigned char *buf, 172 size_t len, 173 bfd_sym_header_block *header) 174 { 175 BFD_ASSERT (len == 154); 176 177 memcpy (header->dshb_id, buf, 32); 178 header->dshb_page_size = bfd_getb16 (buf + 32); 179 header->dshb_hash_page = bfd_getb16 (buf + 34); 180 header->dshb_root_mte = bfd_getb16 (buf + 36); 181 header->dshb_mod_date = bfd_getb32 (buf + 38); 182 183 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte); 184 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte); 185 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte); 186 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte); 187 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte); 188 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte); 189 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte); 190 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte); 191 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte); 192 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte); 193 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo); 194 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite); 195 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const); 196 197 memcpy (&header->dshb_file_creator, buf + 146, 4); 198 memcpy (&header->dshb_file_type, buf + 150, 4); 199 } 200 201 int 202 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header) 203 { 204 unsigned char buf[154]; 205 long ret; 206 207 ret = bfd_bread (buf, 154, abfd); 208 if (ret != 154) 209 return -1; 210 211 bfd_sym_parse_header_v32 (buf, 154, header); 212 213 return 0; 214 } 215 216 int 217 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED, 218 bfd_sym_header_block *header ATTRIBUTE_UNUSED) 219 { 220 abort (); 221 } 222 223 int 224 bfd_sym_read_header (bfd *abfd, 225 bfd_sym_header_block *header, 226 bfd_sym_version version) 227 { 228 switch (version) 229 { 230 case BFD_SYM_VERSION_3_5: 231 case BFD_SYM_VERSION_3_4: 232 return bfd_sym_read_header_v34 (abfd, header); 233 case BFD_SYM_VERSION_3_3: 234 case BFD_SYM_VERSION_3_2: 235 return bfd_sym_read_header_v32 (abfd, header); 236 case BFD_SYM_VERSION_3_1: 237 default: 238 return 0; 239 } 240 } 241 242 int 243 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version) 244 { 245 char version_string[32]; 246 long ret; 247 248 ret = bfd_bread (version_string, sizeof (version_string), abfd); 249 if (ret != sizeof (version_string)) 250 return -1; 251 252 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0) 253 *version = BFD_SYM_VERSION_3_1; 254 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0) 255 *version = BFD_SYM_VERSION_3_2; 256 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0) 257 *version = BFD_SYM_VERSION_3_3; 258 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0) 259 *version = BFD_SYM_VERSION_3_4; 260 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0) 261 *version = BFD_SYM_VERSION_3_5; 262 else 263 return -1; 264 265 return 0; 266 } 267 268 void 269 bfd_sym_display_table_summary (FILE *f, 270 bfd_sym_table_info *dti, 271 const char *name) 272 { 273 fprintf (f, "%-6s %13ld %13ld %13ld\n", 274 name, 275 dti->dti_first_page, 276 dti->dti_page_count, 277 dti->dti_object_count); 278 } 279 280 void 281 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb) 282 { 283 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1); 284 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size); 285 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page); 286 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte); 287 fprintf (f, " Modification Date: "); 288 fprintf (f, "[unimplemented]"); 289 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date); 290 291 fprintf (f, " File Creator: %.4s Type: %.4s\n\n", 292 dshb->dshb_file_creator, dshb->dshb_file_type); 293 294 fprintf (f, "Table Name First Page Page Count Object Count\n"); 295 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); 296 297 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE"); 298 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE"); 299 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE"); 300 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE"); 301 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE"); 302 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE"); 303 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE"); 304 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE"); 305 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE"); 306 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE"); 307 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO"); 308 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE"); 309 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST"); 310 311 fprintf (f, "\n"); 312 } 313 314 void 315 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf, 316 size_t len, 317 bfd_sym_resources_table_entry *entry) 318 { 319 BFD_ASSERT (len == 18); 320 321 memcpy (&entry->rte_res_type, buf, 4); 322 entry->rte_res_number = bfd_getb16 (buf + 4); 323 entry->rte_nte_index = bfd_getb32 (buf + 6); 324 entry->rte_mte_first = bfd_getb16 (buf + 10); 325 entry->rte_mte_last = bfd_getb16 (buf + 12); 326 entry->rte_res_size = bfd_getb32 (buf + 14); 327 } 328 329 void 330 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf, 331 size_t len, 332 bfd_sym_modules_table_entry *entry) 333 { 334 BFD_ASSERT (len == 46); 335 336 entry->mte_rte_index = bfd_getb16 (buf); 337 entry->mte_res_offset = bfd_getb32 (buf + 2); 338 entry->mte_size = bfd_getb32 (buf + 6); 339 entry->mte_kind = buf[10]; 340 entry->mte_scope = buf[11]; 341 entry->mte_parent = bfd_getb16 (buf + 12); 342 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref); 343 entry->mte_imp_end = bfd_getb32 (buf + 20); 344 entry->mte_nte_index = bfd_getb32 (buf + 24); 345 entry->mte_cmte_index = bfd_getb16 (buf + 28); 346 entry->mte_cvte_index = bfd_getb32 (buf + 30); 347 entry->mte_clte_index = bfd_getb16 (buf + 34); 348 entry->mte_ctte_index = bfd_getb16 (buf + 36); 349 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38); 350 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42); 351 } 352 353 void 354 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf, 355 size_t len, 356 bfd_sym_file_references_table_entry *entry) 357 { 358 unsigned int type; 359 360 BFD_ASSERT (len == 10); 361 362 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry)); 363 type = bfd_getb16 (buf); 364 365 switch (type) 366 { 367 case BFD_SYM_END_OF_LIST_3_2: 368 entry->generic.type = BFD_SYM_END_OF_LIST; 369 break; 370 371 case BFD_SYM_FILE_NAME_INDEX_3_2: 372 entry->filename.type = BFD_SYM_FILE_NAME_INDEX; 373 entry->filename.nte_index = bfd_getb32 (buf + 2); 374 entry->filename.mod_date = bfd_getb32 (buf + 6); 375 break; 376 377 default: 378 entry->entry.mte_index = type; 379 entry->entry.file_offset = bfd_getb32 (buf + 2); 380 } 381 } 382 383 void 384 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf, 385 size_t len, 386 bfd_sym_contained_modules_table_entry *entry) 387 { 388 unsigned int type; 389 390 BFD_ASSERT (len == 6); 391 392 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry)); 393 type = bfd_getb16 (buf); 394 395 switch (type) 396 { 397 case BFD_SYM_END_OF_LIST_3_2: 398 entry->generic.type = BFD_SYM_END_OF_LIST; 399 break; 400 401 default: 402 entry->entry.mte_index = type; 403 entry->entry.nte_index = bfd_getb32 (buf + 2); 404 break; 405 } 406 } 407 408 void 409 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf, 410 size_t len, 411 bfd_sym_contained_variables_table_entry *entry) 412 { 413 unsigned int type; 414 415 BFD_ASSERT (len == 26); 416 417 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry)); 418 type = bfd_getb16 (buf); 419 420 switch (type) 421 { 422 case BFD_SYM_END_OF_LIST_3_2: 423 entry->generic.type = BFD_SYM_END_OF_LIST; 424 break; 425 426 case BFD_SYM_SOURCE_FILE_CHANGE_3_2: 427 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE; 428 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref); 429 break; 430 431 default: 432 entry->entry.tte_index = type; 433 entry->entry.nte_index = bfd_getb32 (buf + 2); 434 entry->entry.file_delta = bfd_getb16 (buf + 6); 435 entry->entry.scope = buf[8]; 436 entry->entry.la_size = buf[9]; 437 438 if (entry->entry.la_size == BFD_SYM_CVTE_SCA) 439 { 440 entry->entry.address.scstruct.sca_kind = buf[10]; 441 entry->entry.address.scstruct.sca_class = buf[11]; 442 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12); 443 } 444 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA) 445 { 446 #if BFD_SYM_CVTE_SCA > 0 447 memcpy (&entry->entry.address.lastruct.la, buf + 10, 448 BFD_SYM_CVTE_SCA); 449 #endif 450 entry->entry.address.lastruct.la_kind = buf[23]; 451 } 452 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA) 453 { 454 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10); 455 entry->entry.address.biglastruct.big_la_kind = buf[12]; 456 } 457 } 458 } 459 460 void 461 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf, 462 size_t len, 463 bfd_sym_contained_statements_table_entry *entry) 464 { 465 unsigned int type; 466 467 BFD_ASSERT (len == 8); 468 469 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry)); 470 type = bfd_getb16 (buf); 471 472 switch (type) 473 { 474 case BFD_SYM_END_OF_LIST_3_2: 475 entry->generic.type = BFD_SYM_END_OF_LIST; 476 break; 477 478 case BFD_SYM_SOURCE_FILE_CHANGE_3_2: 479 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE; 480 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref); 481 break; 482 483 default: 484 entry->entry.mte_index = type; 485 entry->entry.mte_offset = bfd_getb16 (buf + 2); 486 entry->entry.file_delta = bfd_getb32 (buf + 4); 487 break; 488 } 489 } 490 491 void 492 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf, 493 size_t len, 494 bfd_sym_contained_labels_table_entry *entry) 495 { 496 unsigned int type; 497 498 BFD_ASSERT (len == 12); 499 500 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry)); 501 type = bfd_getb16 (buf); 502 503 switch (type) 504 { 505 case BFD_SYM_END_OF_LIST_3_2: 506 entry->generic.type = BFD_SYM_END_OF_LIST; 507 break; 508 509 case BFD_SYM_SOURCE_FILE_CHANGE_3_2: 510 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE; 511 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref); 512 break; 513 514 default: 515 entry->entry.mte_index = type; 516 entry->entry.mte_offset = bfd_getb16 (buf + 2); 517 entry->entry.nte_index = bfd_getb32 (buf + 4); 518 entry->entry.file_delta = bfd_getb16 (buf + 8); 519 entry->entry.scope = bfd_getb16 (buf + 10); 520 break; 521 } 522 } 523 524 void 525 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf, 526 size_t len, 527 bfd_sym_type_table_entry *entry) 528 { 529 BFD_ASSERT (len == 4); 530 531 *entry = bfd_getb32 (buf); 532 } 533 534 int 535 bfd_sym_fetch_resources_table_entry (bfd *abfd, 536 bfd_sym_resources_table_entry *entry, 537 unsigned long sym_index) 538 { 539 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *); 540 unsigned long offset; 541 unsigned long entry_size; 542 unsigned char buf[18]; 543 bfd_sym_data_struct *sdata = NULL; 544 545 parser = NULL; 546 BFD_ASSERT (bfd_sym_valid (abfd)); 547 sdata = abfd->tdata.sym_data; 548 549 if (sym_index == 0) 550 return -1; 551 552 switch (sdata->version) 553 { 554 case BFD_SYM_VERSION_3_5: 555 case BFD_SYM_VERSION_3_4: 556 return -1; 557 558 case BFD_SYM_VERSION_3_3: 559 case BFD_SYM_VERSION_3_2: 560 entry_size = 18; 561 parser = bfd_sym_parse_resources_table_entry_v32; 562 break; 563 564 case BFD_SYM_VERSION_3_1: 565 default: 566 return -1; 567 } 568 if (parser == NULL) 569 return -1; 570 571 offset = compute_offset (sdata->header.dshb_rte.dti_first_page, 572 sdata->header.dshb_page_size, 573 entry_size, sym_index); 574 575 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 576 return -1; 577 if (bfd_bread (buf, entry_size, abfd) != entry_size) 578 return -1; 579 580 (*parser) (buf, entry_size, entry); 581 582 return 0; 583 } 584 585 int 586 bfd_sym_fetch_modules_table_entry (bfd *abfd, 587 bfd_sym_modules_table_entry *entry, 588 unsigned long sym_index) 589 { 590 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *); 591 unsigned long offset; 592 unsigned long entry_size; 593 unsigned char buf[46]; 594 bfd_sym_data_struct *sdata = NULL; 595 596 parser = NULL; 597 BFD_ASSERT (bfd_sym_valid (abfd)); 598 sdata = abfd->tdata.sym_data; 599 600 if (sym_index == 0) 601 return -1; 602 603 switch (sdata->version) 604 { 605 case BFD_SYM_VERSION_3_5: 606 case BFD_SYM_VERSION_3_4: 607 return -1; 608 609 case BFD_SYM_VERSION_3_3: 610 entry_size = 46; 611 parser = bfd_sym_parse_modules_table_entry_v33; 612 break; 613 614 case BFD_SYM_VERSION_3_2: 615 case BFD_SYM_VERSION_3_1: 616 default: 617 return -1; 618 } 619 if (parser == NULL) 620 return -1; 621 622 offset = compute_offset (sdata->header.dshb_mte.dti_first_page, 623 sdata->header.dshb_page_size, 624 entry_size, sym_index); 625 626 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 627 return -1; 628 if (bfd_bread (buf, entry_size, abfd) != entry_size) 629 return -1; 630 631 (*parser) (buf, entry_size, entry); 632 633 return 0; 634 } 635 636 int 637 bfd_sym_fetch_file_references_table_entry (bfd *abfd, 638 bfd_sym_file_references_table_entry *entry, 639 unsigned long sym_index) 640 { 641 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *); 642 unsigned long offset; 643 unsigned long entry_size = 0; 644 unsigned char buf[8]; 645 bfd_sym_data_struct *sdata = NULL; 646 647 parser = NULL; 648 BFD_ASSERT (bfd_sym_valid (abfd)); 649 sdata = abfd->tdata.sym_data; 650 651 if (sym_index == 0) 652 return -1; 653 654 switch (sdata->version) 655 { 656 case BFD_SYM_VERSION_3_3: 657 case BFD_SYM_VERSION_3_2: 658 entry_size = 10; 659 parser = bfd_sym_parse_file_references_table_entry_v32; 660 break; 661 662 case BFD_SYM_VERSION_3_5: 663 case BFD_SYM_VERSION_3_4: 664 case BFD_SYM_VERSION_3_1: 665 default: 666 break; 667 } 668 669 if (parser == NULL) 670 return -1; 671 672 offset = compute_offset (sdata->header.dshb_frte.dti_first_page, 673 sdata->header.dshb_page_size, 674 entry_size, sym_index); 675 676 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 677 return -1; 678 if (bfd_bread (buf, entry_size, abfd) != entry_size) 679 return -1; 680 681 (*parser) (buf, entry_size, entry); 682 683 return 0; 684 } 685 686 int 687 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd, 688 bfd_sym_contained_modules_table_entry *entry, 689 unsigned long sym_index) 690 { 691 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *); 692 unsigned long offset; 693 unsigned long entry_size = 0; 694 unsigned char buf[6]; 695 bfd_sym_data_struct *sdata = NULL; 696 697 parser = NULL; 698 BFD_ASSERT (bfd_sym_valid (abfd)); 699 sdata = abfd->tdata.sym_data; 700 701 if (sym_index == 0) 702 return -1; 703 704 switch (sdata->version) 705 { 706 case BFD_SYM_VERSION_3_3: 707 case BFD_SYM_VERSION_3_2: 708 entry_size = 6; 709 parser = bfd_sym_parse_contained_modules_table_entry_v32; 710 break; 711 712 case BFD_SYM_VERSION_3_5: 713 case BFD_SYM_VERSION_3_4: 714 case BFD_SYM_VERSION_3_1: 715 default: 716 break; 717 } 718 719 if (parser == NULL) 720 return -1; 721 722 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page, 723 sdata->header.dshb_page_size, 724 entry_size, sym_index); 725 726 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 727 return -1; 728 if (bfd_bread (buf, entry_size, abfd) != entry_size) 729 return -1; 730 731 (*parser) (buf, entry_size, entry); 732 733 return 0; 734 } 735 736 int 737 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd, 738 bfd_sym_contained_variables_table_entry *entry, 739 unsigned long sym_index) 740 { 741 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *); 742 unsigned long offset; 743 unsigned long entry_size = 0; 744 unsigned char buf[26]; 745 bfd_sym_data_struct *sdata = NULL; 746 747 parser = NULL; 748 BFD_ASSERT (bfd_sym_valid (abfd)); 749 sdata = abfd->tdata.sym_data; 750 751 if (sym_index == 0) 752 return -1; 753 754 switch (sdata->version) 755 { 756 case BFD_SYM_VERSION_3_3: 757 case BFD_SYM_VERSION_3_2: 758 entry_size = 26; 759 parser = bfd_sym_parse_contained_variables_table_entry_v32; 760 break; 761 762 case BFD_SYM_VERSION_3_5: 763 case BFD_SYM_VERSION_3_4: 764 case BFD_SYM_VERSION_3_1: 765 default: 766 break; 767 } 768 769 if (parser == NULL) 770 return -1; 771 772 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page, 773 sdata->header.dshb_page_size, 774 entry_size, sym_index); 775 776 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 777 return -1; 778 if (bfd_bread (buf, entry_size, abfd) != entry_size) 779 return -1; 780 781 (*parser) (buf, entry_size, entry); 782 783 return 0; 784 } 785 786 int 787 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd, 788 bfd_sym_contained_statements_table_entry *entry, 789 unsigned long sym_index) 790 { 791 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *); 792 unsigned long offset; 793 unsigned long entry_size = 0; 794 unsigned char buf[8]; 795 bfd_sym_data_struct *sdata = NULL; 796 797 parser = NULL; 798 BFD_ASSERT (bfd_sym_valid (abfd)); 799 sdata = abfd->tdata.sym_data; 800 801 if (sym_index == 0) 802 return -1; 803 804 switch (sdata->version) 805 { 806 case BFD_SYM_VERSION_3_3: 807 case BFD_SYM_VERSION_3_2: 808 entry_size = 8; 809 parser = bfd_sym_parse_contained_statements_table_entry_v32; 810 break; 811 812 case BFD_SYM_VERSION_3_5: 813 case BFD_SYM_VERSION_3_4: 814 case BFD_SYM_VERSION_3_1: 815 default: 816 break; 817 } 818 819 if (parser == NULL) 820 return -1; 821 822 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page, 823 sdata->header.dshb_page_size, 824 entry_size, sym_index); 825 826 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 827 return -1; 828 if (bfd_bread (buf, entry_size, abfd) != entry_size) 829 return -1; 830 831 (*parser) (buf, entry_size, entry); 832 833 return 0; 834 } 835 836 int 837 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd, 838 bfd_sym_contained_labels_table_entry *entry, 839 unsigned long sym_index) 840 { 841 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *); 842 unsigned long offset; 843 unsigned long entry_size = 0; 844 unsigned char buf[12]; 845 bfd_sym_data_struct *sdata = NULL; 846 847 parser = NULL; 848 BFD_ASSERT (bfd_sym_valid (abfd)); 849 sdata = abfd->tdata.sym_data; 850 851 if (sym_index == 0) 852 return -1; 853 854 switch (sdata->version) 855 { 856 case BFD_SYM_VERSION_3_3: 857 case BFD_SYM_VERSION_3_2: 858 entry_size = 12; 859 parser = bfd_sym_parse_contained_labels_table_entry_v32; 860 break; 861 862 case BFD_SYM_VERSION_3_5: 863 case BFD_SYM_VERSION_3_4: 864 case BFD_SYM_VERSION_3_1: 865 default: 866 break; 867 } 868 869 if (parser == NULL) 870 return -1; 871 872 offset = compute_offset (sdata->header.dshb_clte.dti_first_page, 873 sdata->header.dshb_page_size, 874 entry_size, sym_index); 875 876 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 877 return -1; 878 if (bfd_bread (buf, entry_size, abfd) != entry_size) 879 return -1; 880 881 (*parser) (buf, entry_size, entry); 882 883 return 0; 884 } 885 886 int 887 bfd_sym_fetch_contained_types_table_entry (bfd *abfd, 888 bfd_sym_contained_types_table_entry *entry, 889 unsigned long sym_index) 890 { 891 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *); 892 unsigned long offset; 893 unsigned long entry_size = 0; 894 unsigned char buf[0]; 895 bfd_sym_data_struct *sdata = NULL; 896 897 parser = NULL; 898 BFD_ASSERT (bfd_sym_valid (abfd)); 899 sdata = abfd->tdata.sym_data; 900 901 if (sym_index == 0) 902 return -1; 903 904 switch (sdata->version) 905 { 906 case BFD_SYM_VERSION_3_3: 907 case BFD_SYM_VERSION_3_2: 908 entry_size = 0; 909 parser = NULL; 910 break; 911 912 case BFD_SYM_VERSION_3_5: 913 case BFD_SYM_VERSION_3_4: 914 case BFD_SYM_VERSION_3_1: 915 default: 916 break; 917 } 918 919 if (parser == NULL) 920 return -1; 921 922 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page, 923 sdata->header.dshb_page_size, 924 entry_size, sym_index); 925 926 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 927 return -1; 928 if (bfd_bread (buf, entry_size, abfd) != entry_size) 929 return -1; 930 931 (*parser) (buf, entry_size, entry); 932 933 return 0; 934 } 935 936 int 937 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd, 938 bfd_sym_file_references_index_table_entry *entry, 939 unsigned long sym_index) 940 { 941 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *); 942 unsigned long offset; 943 unsigned long entry_size = 0; 944 unsigned char buf[0]; 945 bfd_sym_data_struct *sdata = NULL; 946 947 parser = NULL; 948 BFD_ASSERT (bfd_sym_valid (abfd)); 949 sdata = abfd->tdata.sym_data; 950 951 if (sym_index == 0) 952 return -1; 953 954 switch (sdata->version) 955 { 956 case BFD_SYM_VERSION_3_3: 957 case BFD_SYM_VERSION_3_2: 958 entry_size = 0; 959 parser = NULL; 960 break; 961 962 case BFD_SYM_VERSION_3_5: 963 case BFD_SYM_VERSION_3_4: 964 case BFD_SYM_VERSION_3_1: 965 default: 966 break; 967 } 968 969 if (parser == NULL) 970 return -1; 971 972 offset = compute_offset (sdata->header.dshb_fite.dti_first_page, 973 sdata->header.dshb_page_size, 974 entry_size, sym_index); 975 976 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 977 return -1; 978 if (bfd_bread (buf, entry_size, abfd) != entry_size) 979 return -1; 980 981 (*parser) (buf, entry_size, entry); 982 983 return 0; 984 } 985 986 int 987 bfd_sym_fetch_constant_pool_entry (bfd *abfd, 988 bfd_sym_constant_pool_entry *entry, 989 unsigned long sym_index) 990 { 991 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *); 992 unsigned long offset; 993 unsigned long entry_size = 0; 994 unsigned char buf[0]; 995 bfd_sym_data_struct *sdata = NULL; 996 997 parser = NULL; 998 BFD_ASSERT (bfd_sym_valid (abfd)); 999 sdata = abfd->tdata.sym_data; 1000 1001 if (sym_index == 0) 1002 return -1; 1003 1004 switch (sdata->version) 1005 { 1006 case BFD_SYM_VERSION_3_3: 1007 case BFD_SYM_VERSION_3_2: 1008 entry_size = 0; 1009 parser = NULL; 1010 break; 1011 1012 case BFD_SYM_VERSION_3_5: 1013 case BFD_SYM_VERSION_3_4: 1014 case BFD_SYM_VERSION_3_1: 1015 default: 1016 break; 1017 } 1018 1019 if (parser == NULL) 1020 return -1; 1021 1022 offset = compute_offset (sdata->header.dshb_fite.dti_first_page, 1023 sdata->header.dshb_page_size, 1024 entry_size, sym_index); 1025 1026 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 1027 return -1; 1028 if (bfd_bread (buf, entry_size, abfd) != entry_size) 1029 return -1; 1030 1031 (*parser) (buf, entry_size, entry); 1032 1033 return 0; 1034 } 1035 1036 int 1037 bfd_sym_fetch_type_table_entry (bfd *abfd, 1038 bfd_sym_type_table_entry *entry, 1039 unsigned long sym_index) 1040 { 1041 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *); 1042 unsigned long offset; 1043 unsigned long entry_size = 0; 1044 unsigned char buf[4]; 1045 bfd_sym_data_struct *sdata = NULL; 1046 1047 parser = NULL; 1048 BFD_ASSERT (bfd_sym_valid (abfd)); 1049 sdata = abfd->tdata.sym_data; 1050 1051 switch (sdata->version) 1052 { 1053 case BFD_SYM_VERSION_3_3: 1054 case BFD_SYM_VERSION_3_2: 1055 entry_size = 4; 1056 parser = bfd_sym_parse_type_table_entry_v32; 1057 break; 1058 1059 case BFD_SYM_VERSION_3_5: 1060 case BFD_SYM_VERSION_3_4: 1061 case BFD_SYM_VERSION_3_1: 1062 default: 1063 break; 1064 } 1065 1066 if (parser == NULL) 1067 return -1; 1068 1069 offset = compute_offset (sdata->header.dshb_tte.dti_first_page, 1070 sdata->header.dshb_page_size, 1071 entry_size, sym_index); 1072 1073 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 1074 return -1; 1075 if (bfd_bread (buf, entry_size, abfd) != entry_size) 1076 return -1; 1077 1078 (*parser) (buf, entry_size, entry); 1079 1080 return 0; 1081 } 1082 1083 int 1084 bfd_sym_fetch_type_information_table_entry (bfd *abfd, 1085 bfd_sym_type_information_table_entry *entry, 1086 unsigned long offset) 1087 { 1088 unsigned char buf[4]; 1089 1090 BFD_ASSERT (bfd_sym_valid (abfd)); 1091 1092 if (offset == 0) 1093 return -1; 1094 1095 if (bfd_seek (abfd, offset, SEEK_SET) < 0) 1096 return -1; 1097 1098 if (bfd_bread (buf, 4, abfd) != 4) 1099 return -1; 1100 entry->nte_index = bfd_getb32 (buf); 1101 1102 if (bfd_bread (buf, 2, abfd) != 2) 1103 return -1; 1104 entry->physical_size = bfd_getb16 (buf); 1105 1106 if (entry->physical_size & 0x8000) 1107 { 1108 if (bfd_bread (buf, 4, abfd) != 4) 1109 return -1; 1110 entry->physical_size &= 0x7fff; 1111 entry->logical_size = bfd_getb32 (buf); 1112 entry->offset = offset + 10; 1113 } 1114 else 1115 { 1116 if (bfd_bread (buf, 2, abfd) != 2) 1117 return -1; 1118 entry->physical_size &= 0x7fff; 1119 entry->logical_size = bfd_getb16 (buf); 1120 entry->offset = offset + 8; 1121 } 1122 1123 return 0; 1124 } 1125 1126 int 1127 bfd_sym_fetch_type_table_information (bfd *abfd, 1128 bfd_sym_type_information_table_entry *entry, 1129 unsigned long sym_index) 1130 { 1131 bfd_sym_type_table_entry tindex; 1132 bfd_sym_data_struct *sdata = NULL; 1133 1134 BFD_ASSERT (bfd_sym_valid (abfd)); 1135 sdata = abfd->tdata.sym_data; 1136 1137 if (sdata->header.dshb_tte.dti_object_count <= 99) 1138 return -1; 1139 if (sym_index < 100) 1140 return -1; 1141 1142 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0) 1143 return -1; 1144 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0) 1145 return -1; 1146 1147 return 0; 1148 } 1149 1150 const unsigned char * 1151 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index) 1152 { 1153 bfd_sym_data_struct *sdata = NULL; 1154 1155 BFD_ASSERT (bfd_sym_valid (abfd)); 1156 sdata = abfd->tdata.sym_data; 1157 1158 if (sym_index == 0) 1159 return (const unsigned char *) ""; 1160 1161 sym_index *= 2; 1162 if ((sym_index / sdata->header.dshb_page_size) 1163 > sdata->header.dshb_nte.dti_page_count) 1164 return (const unsigned char *) "\09[INVALID]"; 1165 1166 return (const unsigned char *) sdata->name_table + sym_index; 1167 } 1168 1169 const unsigned char * 1170 bfd_sym_module_name (bfd *abfd, unsigned long sym_index) 1171 { 1172 bfd_sym_modules_table_entry entry; 1173 1174 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0) 1175 return (const unsigned char *) "\09[INVALID]"; 1176 1177 return bfd_sym_symbol_name (abfd, entry.mte_nte_index); 1178 } 1179 1180 const char * 1181 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind) 1182 { 1183 switch (kind) 1184 { 1185 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL"; 1186 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE"; 1187 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE"; 1188 case BFD_SYM_STORAGE_KIND_WITH: return "WITH"; 1189 default: return "[UNKNOWN]"; 1190 } 1191 } 1192 1193 const char * 1194 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind) 1195 { 1196 switch (kind) 1197 { 1198 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER"; 1199 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL"; 1200 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE"; 1201 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE"; 1202 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE"; 1203 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT"; 1204 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE"; 1205 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT"; 1206 default: return "[UNKNOWN]"; 1207 } 1208 } 1209 1210 const char * 1211 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind) 1212 { 1213 switch (kind) 1214 { 1215 case BFD_SYM_MODULE_KIND_NONE: return "NONE"; 1216 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM"; 1217 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT"; 1218 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE"; 1219 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION"; 1220 case BFD_SYM_MODULE_KIND_DATA: return "DATA"; 1221 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK"; 1222 default: return "[UNKNOWN]"; 1223 } 1224 } 1225 1226 const char * 1227 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope) 1228 { 1229 switch (scope) 1230 { 1231 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL"; 1232 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL"; 1233 default: 1234 return "[UNKNOWN]"; 1235 } 1236 } 1237 1238 void 1239 bfd_sym_print_file_reference (bfd *abfd, 1240 FILE *f, 1241 bfd_sym_file_reference *entry) 1242 { 1243 bfd_sym_file_references_table_entry frtentry; 1244 int ret; 1245 1246 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry, 1247 entry->fref_frte_index); 1248 fprintf (f, "FILE "); 1249 1250 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX)) 1251 fprintf (f, "[INVALID]"); 1252 else 1253 fprintf (f, "\"%.*s\"", 1254 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0], 1255 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]); 1256 1257 fprintf (f, " (FRTE %lu)", entry->fref_frte_index); 1258 } 1259 1260 void 1261 bfd_sym_print_resources_table_entry (bfd *abfd, 1262 FILE *f, 1263 bfd_sym_resources_table_entry *entry) 1264 { 1265 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu", 1266 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0], 1267 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1], 1268 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number, 1269 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last); 1270 } 1271 1272 void 1273 bfd_sym_print_modules_table_entry (bfd *abfd, 1274 FILE *f, 1275 bfd_sym_modules_table_entry *entry) 1276 { 1277 fprintf (f, "\"%.*s\" (NTE %lu)", 1278 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0], 1279 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1], 1280 entry->mte_nte_index); 1281 1282 fprintf (f, "\n "); 1283 1284 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref); 1285 fprintf (f, " range %lu -- %lu", 1286 entry->mte_imp_fref.fref_offset, entry->mte_imp_end); 1287 1288 fprintf (f, "\n "); 1289 1290 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind)); 1291 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope)); 1292 1293 fprintf (f, ", RTE %lu, offset %lu, size %lu", 1294 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size); 1295 1296 fprintf (f, "\n "); 1297 1298 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu", 1299 entry->mte_cmte_index, entry->mte_cvte_index, 1300 entry->mte_clte_index, entry->mte_ctte_index, 1301 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2); 1302 1303 if (entry->mte_parent != 0) 1304 fprintf (f, ", parent %lu", entry->mte_parent); 1305 else 1306 fprintf (f, ", no parent"); 1307 1308 if (entry->mte_cmte_index != 0) 1309 fprintf (f, ", child %lu", entry->mte_cmte_index); 1310 else 1311 fprintf (f, ", no child"); 1312 } 1313 1314 void 1315 bfd_sym_print_file_references_table_entry (bfd *abfd, 1316 FILE *f, 1317 bfd_sym_file_references_table_entry *entry) 1318 { 1319 switch (entry->generic.type) 1320 { 1321 case BFD_SYM_FILE_NAME_INDEX: 1322 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ", 1323 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0], 1324 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1], 1325 entry->filename.nte_index); 1326 1327 fprintf (f, "[UNIMPLEMENTED]"); 1328 /* printModDate (entry->filename.mod_date); */ 1329 fprintf (f, " (0x%lx)", entry->filename.mod_date); 1330 break; 1331 1332 case BFD_SYM_END_OF_LIST: 1333 fprintf (f, "END"); 1334 break; 1335 1336 default: 1337 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu", 1338 bfd_sym_module_name (abfd, entry->entry.mte_index)[0], 1339 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1], 1340 entry->entry.mte_index, 1341 entry->entry.file_offset); 1342 break; 1343 } 1344 } 1345 1346 void 1347 bfd_sym_print_contained_modules_table_entry (bfd *abfd, 1348 FILE *f, 1349 bfd_sym_contained_modules_table_entry *entry) 1350 { 1351 switch (entry->generic.type) 1352 { 1353 case BFD_SYM_END_OF_LIST: 1354 fprintf (f, "END"); 1355 break; 1356 1357 default: 1358 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)", 1359 bfd_sym_module_name (abfd, entry->entry.mte_index)[0], 1360 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1], 1361 entry->entry.mte_index, 1362 entry->entry.nte_index); 1363 break; 1364 } 1365 } 1366 1367 void 1368 bfd_sym_print_contained_variables_table_entry (bfd *abfd, 1369 FILE *f, 1370 bfd_sym_contained_variables_table_entry *entry) 1371 { 1372 if (entry->generic.type == BFD_SYM_END_OF_LIST) 1373 { 1374 fprintf (f, "END"); 1375 return; 1376 } 1377 1378 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) 1379 { 1380 bfd_sym_print_file_reference (abfd, f, &entry->file.fref); 1381 fprintf (f, " offset %lu", entry->file.fref.fref_offset); 1382 return; 1383 } 1384 1385 fprintf (f, "\"%.*s\" (NTE %lu)", 1386 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0], 1387 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1], 1388 entry->entry.nte_index); 1389 1390 fprintf (f, ", TTE %lu", entry->entry.tte_index); 1391 fprintf (f, ", offset %lu", entry->entry.file_delta); 1392 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope)); 1393 1394 if (entry->entry.la_size == BFD_SYM_CVTE_SCA) 1395 fprintf (f, ", latype %s, laclass %s, laoffset %lu", 1396 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind), 1397 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class), 1398 entry->entry.address.scstruct.sca_offset); 1399 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE) 1400 { 1401 unsigned long i; 1402 1403 fprintf (f, ", la ["); 1404 for (i = 0; i < entry->entry.la_size; i++) 1405 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]); 1406 fprintf (f, "]"); 1407 } 1408 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA) 1409 fprintf (f, ", bigla %lu, biglakind %u", 1410 entry->entry.address.biglastruct.big_la, 1411 entry->entry.address.biglastruct.big_la_kind); 1412 1413 else 1414 fprintf (f, ", la [INVALID]"); 1415 } 1416 1417 void 1418 bfd_sym_print_contained_statements_table_entry (bfd *abfd, 1419 FILE *f, 1420 bfd_sym_contained_statements_table_entry *entry) 1421 { 1422 if (entry->generic.type == BFD_SYM_END_OF_LIST) 1423 { 1424 fprintf (f, "END"); 1425 return; 1426 } 1427 1428 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) 1429 { 1430 bfd_sym_print_file_reference (abfd, f, &entry->file.fref); 1431 fprintf (f, " offset %lu", entry->file.fref.fref_offset); 1432 return; 1433 } 1434 1435 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu", 1436 bfd_sym_module_name (abfd, entry->entry.mte_index)[0], 1437 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1], 1438 entry->entry.mte_index, 1439 entry->entry.mte_offset, 1440 entry->entry.file_delta); 1441 } 1442 1443 void 1444 bfd_sym_print_contained_labels_table_entry (bfd *abfd, 1445 FILE *f, 1446 bfd_sym_contained_labels_table_entry *entry) 1447 { 1448 if (entry->generic.type == BFD_SYM_END_OF_LIST) 1449 { 1450 fprintf (f, "END"); 1451 return; 1452 } 1453 1454 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE) 1455 { 1456 bfd_sym_print_file_reference (abfd, f, &entry->file.fref); 1457 fprintf (f, " offset %lu", entry->file.fref.fref_offset); 1458 return; 1459 } 1460 1461 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s", 1462 bfd_sym_module_name (abfd, entry->entry.mte_index)[0], 1463 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1], 1464 entry->entry.mte_index, 1465 entry->entry.mte_offset, 1466 entry->entry.file_delta, 1467 bfd_sym_unparse_symbol_scope (entry->entry.scope)); 1468 } 1469 1470 void 1471 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED, 1472 FILE *f, 1473 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED) 1474 { 1475 fprintf (f, "[UNIMPLEMENTED]"); 1476 } 1477 1478 const char * 1479 bfd_sym_type_operator_name (unsigned char num) 1480 { 1481 switch (num) 1482 { 1483 case 1: return "TTE"; 1484 case 2: return "PointerTo"; 1485 case 3: return "ScalarOf"; 1486 case 4: return "ConstantOf"; 1487 case 5: return "EnumerationOf"; 1488 case 6: return "VectorOf"; 1489 case 7: return "RecordOf"; 1490 case 8: return "UnionOf"; 1491 case 9: return "SubRangeOf"; 1492 case 10: return "SetOf"; 1493 case 11: return "NamedTypeOf"; 1494 case 12: return "ProcOf"; 1495 case 13: return "ValueOf"; 1496 case 14: return "ArrayOf"; 1497 default: return "[UNKNOWN OPERATOR]"; 1498 } 1499 } 1500 1501 const char * 1502 bfd_sym_type_basic_name (unsigned char num) 1503 { 1504 switch (num) 1505 { 1506 case 0: return "void"; 1507 case 1: return "pascal string"; 1508 case 2: return "unsigned long"; 1509 case 3: return "signed long"; 1510 case 4: return "extended (10 bytes)"; 1511 case 5: return "pascal boolean (1 byte)"; 1512 case 6: return "unsigned byte"; 1513 case 7: return "signed byte"; 1514 case 8: return "character (1 byte)"; 1515 case 9: return "wide character (2 bytes)"; 1516 case 10: return "unsigned short"; 1517 case 11: return "signed short"; 1518 case 12: return "singled"; 1519 case 13: return "double"; 1520 case 14: return "extended (12 bytes)"; 1521 case 15: return "computational (8 bytes)"; 1522 case 16: return "c string"; 1523 case 17: return "as-is string"; 1524 default: return "[UNKNOWN BASIC TYPE]"; 1525 } 1526 } 1527 1528 int 1529 bfd_sym_fetch_long (unsigned char *buf, 1530 unsigned long len, 1531 unsigned long offset, 1532 unsigned long *offsetptr, 1533 long *value) 1534 { 1535 int ret; 1536 1537 if (offset >= len) 1538 { 1539 *value = 0; 1540 offset += 0; 1541 ret = -1; 1542 } 1543 else if (! (buf[offset] & 0x80)) 1544 { 1545 *value = buf[offset]; 1546 offset += 1; 1547 ret = 0; 1548 } 1549 else if (buf[offset] == 0xc0) 1550 { 1551 if ((offset + 5) > len) 1552 { 1553 *value = 0; 1554 offset = len; 1555 ret = -1; 1556 } 1557 else 1558 { 1559 *value = bfd_getb32 (buf + offset + 1); 1560 offset += 5; 1561 ret = 0; 1562 } 1563 } 1564 else if ((buf[offset] & 0xc0) == 0xc0) 1565 { 1566 *value = -(buf[offset] & 0x3f); 1567 offset += 1; 1568 ret = 0; 1569 } 1570 else if ((buf[offset] & 0xc0) == 0x80) 1571 { 1572 if ((offset + 2) > len) 1573 { 1574 *value = 0; 1575 offset = len; 1576 ret = -1; 1577 } 1578 else 1579 { 1580 *value = bfd_getb16 (buf + offset) & 0x3fff; 1581 offset += 2; 1582 ret = 0; 1583 } 1584 } 1585 else 1586 abort (); 1587 1588 if (offsetptr != NULL) 1589 *offsetptr = offset; 1590 1591 return ret; 1592 } 1593 1594 void 1595 bfd_sym_print_type_information (bfd *abfd, 1596 FILE *f, 1597 unsigned char *buf, 1598 unsigned long len, 1599 unsigned long offset, 1600 unsigned long *offsetptr) 1601 { 1602 unsigned int type; 1603 1604 if (offset >= len) 1605 { 1606 fprintf (f, "[NULL]"); 1607 1608 if (offsetptr != NULL) 1609 *offsetptr = offset; 1610 return; 1611 } 1612 1613 type = buf[offset]; 1614 offset++; 1615 1616 if (! (type & 0x80)) 1617 { 1618 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type); 1619 1620 if (offsetptr != NULL) 1621 *offsetptr = offset; 1622 return; 1623 } 1624 1625 if (type & 0x40) 1626 fprintf (f, "[packed "); 1627 else 1628 fprintf (f, "["); 1629 1630 switch (type & 0x3f) 1631 { 1632 case 1: 1633 { 1634 long value; 1635 bfd_sym_type_information_table_entry tinfo; 1636 1637 bfd_sym_fetch_long (buf, len, offset, &offset, &value); 1638 if (value <= 0) 1639 fprintf (f, "[INVALID]"); 1640 else 1641 { 1642 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0) 1643 fprintf (f, "[INVALID]"); 1644 else 1645 fprintf (f, "\"%.*s\"", 1646 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0], 1647 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]); 1648 } 1649 fprintf (f, " (TTE %lu)", (unsigned long) value); 1650 break; 1651 } 1652 1653 case 2: 1654 fprintf (f, "pointer (0x%x) to ", type); 1655 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1656 break; 1657 1658 case 3: 1659 { 1660 long value; 1661 1662 fprintf (f, "scalar (0x%x) of ", type); 1663 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1664 bfd_sym_fetch_long (buf, len, offset, &offset, &value); 1665 fprintf (f, " (%lu)", (unsigned long) value); 1666 break; 1667 } 1668 1669 case 5: 1670 { 1671 long lower, upper, nelem; 1672 int i; 1673 1674 fprintf (f, "enumeration (0x%x) of ", type); 1675 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1676 bfd_sym_fetch_long (buf, len, offset, &offset, &lower); 1677 bfd_sym_fetch_long (buf, len, offset, &offset, &upper); 1678 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem); 1679 fprintf (f, " from %lu to %lu with %lu elements: ", 1680 (unsigned long) lower, (unsigned long) upper, 1681 (unsigned long) nelem); 1682 1683 for (i = 0; i < nelem; i++) 1684 { 1685 fprintf (f, "\n "); 1686 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1687 } 1688 break; 1689 } 1690 1691 case 6: 1692 fprintf (f, "vector (0x%x)", type); 1693 fprintf (f, "\n index "); 1694 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1695 fprintf (f, "\n target "); 1696 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1697 break; 1698 1699 case 7: 1700 case 8: 1701 { 1702 long nrec, eloff, i; 1703 1704 if ((type & 0x3f) == 7) 1705 fprintf (f, "record (0x%x) of ", type); 1706 else 1707 fprintf (f, "union (0x%x) of ", type); 1708 1709 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec); 1710 fprintf (f, "%lu elements: ", (unsigned long) nrec); 1711 1712 for (i = 0; i < nrec; i++) 1713 { 1714 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff); 1715 fprintf (f, "\n "); 1716 fprintf (f, "offset %lu: ", (unsigned long) eloff); 1717 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1718 } 1719 break; 1720 } 1721 1722 case 9: 1723 fprintf (f, "subrange (0x%x) of ", type); 1724 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1725 fprintf (f, " lower "); 1726 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1727 fprintf (f, " upper "); 1728 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1729 break; 1730 1731 case 11: 1732 { 1733 long value; 1734 1735 fprintf (f, "named type (0x%x) ", type); 1736 bfd_sym_fetch_long (buf, len, offset, &offset, &value); 1737 if (value <= 0) 1738 fprintf (f, "[INVALID]"); 1739 else 1740 fprintf (f, "\"%.*s\"", 1741 bfd_sym_symbol_name (abfd, value)[0], 1742 &bfd_sym_symbol_name (abfd, value)[1]); 1743 1744 fprintf (f, " (NTE %lu) with type ", (unsigned long) value); 1745 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset); 1746 break; 1747 } 1748 1749 default: 1750 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type); 1751 break; 1752 } 1753 1754 if (type == (0x40 | 0x6)) 1755 { 1756 /* Vector. */ 1757 long n, width, m; 1758 long l; 1759 long i; 1760 1761 bfd_sym_fetch_long (buf, len, offset, &offset, &n); 1762 bfd_sym_fetch_long (buf, len, offset, &offset, &width); 1763 bfd_sym_fetch_long (buf, len, offset, &offset, &m); 1764 /* fprintf (f, "\n "); */ 1765 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m); 1766 for (i = 0; i < m; i++) 1767 { 1768 bfd_sym_fetch_long (buf, len, offset, &offset, &l); 1769 if (i != 0) 1770 fprintf (f, " "); 1771 fprintf (f, "%ld", l); 1772 } 1773 } 1774 else if (type & 0x40) 1775 { 1776 /* Other packed type. */ 1777 long msb, lsb; 1778 1779 bfd_sym_fetch_long (buf, len, offset, &offset, &msb); 1780 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb); 1781 /* fprintf (f, "\n "); */ 1782 fprintf (f, " msb %ld, lsb %ld", msb, lsb); 1783 } 1784 1785 fprintf (f, "]"); 1786 1787 if (offsetptr != NULL) 1788 *offsetptr = offset; 1789 } 1790 1791 void 1792 bfd_sym_print_type_information_table_entry (bfd *abfd, 1793 FILE *f, 1794 bfd_sym_type_information_table_entry *entry) 1795 { 1796 unsigned char *buf; 1797 unsigned long offset; 1798 unsigned int i; 1799 1800 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu", 1801 bfd_sym_symbol_name (abfd, entry->nte_index)[0], 1802 &bfd_sym_symbol_name (abfd, entry->nte_index)[1], 1803 entry->nte_index, 1804 entry->physical_size, entry->offset, entry->logical_size); 1805 1806 fprintf (f, "\n "); 1807 1808 buf = malloc (entry->physical_size); 1809 if (buf == NULL) 1810 { 1811 fprintf (f, "[ERROR]\n"); 1812 return; 1813 } 1814 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0) 1815 { 1816 fprintf (f, "[ERROR]\n"); 1817 free (buf); 1818 return; 1819 } 1820 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size) 1821 { 1822 fprintf (f, "[ERROR]\n"); 1823 free (buf); 1824 return; 1825 } 1826 1827 fprintf (f, "["); 1828 for (i = 0; i < entry->physical_size; i++) 1829 { 1830 if (i == 0) 1831 fprintf (f, "0x%02x", buf[i]); 1832 else 1833 fprintf (f, " 0x%02x", buf[i]); 1834 } 1835 1836 fprintf (f, "]"); 1837 fprintf (f, "\n "); 1838 1839 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset); 1840 1841 if (offset != entry->physical_size) 1842 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size); 1843 free (buf); 1844 } 1845 1846 void 1847 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED, 1848 FILE *f, 1849 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED) 1850 { 1851 fprintf (f, "[UNIMPLEMENTED]"); 1852 } 1853 1854 void 1855 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED, 1856 FILE *f, 1857 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED) 1858 { 1859 fprintf (f, "[UNIMPLEMENTED]"); 1860 } 1861 1862 unsigned char * 1863 bfd_sym_display_name_table_entry (bfd *abfd, 1864 FILE *f, 1865 unsigned char *entry) 1866 { 1867 unsigned long sym_index; 1868 unsigned long offset; 1869 bfd_sym_data_struct *sdata = NULL; 1870 1871 BFD_ASSERT (bfd_sym_valid (abfd)); 1872 sdata = abfd->tdata.sym_data; 1873 sym_index = (entry - sdata->name_table) / 2; 1874 1875 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0) 1876 { 1877 unsigned short length = bfd_getb16 (entry + 2); 1878 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4); 1879 offset = 2 + length + 1; 1880 } 1881 else 1882 { 1883 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0'))) 1884 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1); 1885 1886 if (sdata->version >= BFD_SYM_VERSION_3_4) 1887 offset = entry[0] + 2; 1888 else 1889 offset = entry[0] + 1; 1890 } 1891 1892 return (entry + offset + (offset % 2)); 1893 } 1894 1895 void 1896 bfd_sym_display_name_table (bfd *abfd, FILE *f) 1897 { 1898 unsigned long name_table_len; 1899 unsigned char *name_table, *name_table_end, *cur; 1900 bfd_sym_data_struct *sdata = NULL; 1901 1902 BFD_ASSERT (bfd_sym_valid (abfd)); 1903 sdata = abfd->tdata.sym_data; 1904 1905 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size; 1906 name_table = sdata->name_table; 1907 name_table_end = name_table + name_table_len; 1908 1909 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len); 1910 1911 cur = name_table; 1912 for (;;) 1913 { 1914 cur = bfd_sym_display_name_table_entry (abfd, f, cur); 1915 if (cur >= name_table_end) 1916 break; 1917 } 1918 } 1919 1920 void 1921 bfd_sym_display_resources_table (bfd *abfd, FILE *f) 1922 { 1923 unsigned long i; 1924 bfd_sym_resources_table_entry entry; 1925 bfd_sym_data_struct *sdata = NULL; 1926 1927 BFD_ASSERT (bfd_sym_valid (abfd)); 1928 sdata = abfd->tdata.sym_data; 1929 1930 fprintf (f, "resource table (RTE) contains %lu objects:\n\n", 1931 sdata->header.dshb_rte.dti_object_count); 1932 1933 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++) 1934 { 1935 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0) 1936 fprintf (f, " [%8lu] [INVALID]\n", i); 1937 else 1938 { 1939 fprintf (f, " [%8lu] ", i); 1940 bfd_sym_print_resources_table_entry (abfd, f, &entry); 1941 fprintf (f, "\n"); 1942 } 1943 } 1944 } 1945 1946 void 1947 bfd_sym_display_modules_table (bfd *abfd, FILE *f) 1948 { 1949 unsigned long i; 1950 bfd_sym_modules_table_entry entry; 1951 bfd_sym_data_struct *sdata = NULL; 1952 1953 BFD_ASSERT (bfd_sym_valid (abfd)); 1954 sdata = abfd->tdata.sym_data; 1955 1956 fprintf (f, "module table (MTE) contains %lu objects:\n\n", 1957 sdata->header.dshb_mte.dti_object_count); 1958 1959 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++) 1960 { 1961 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0) 1962 fprintf (f, " [%8lu] [INVALID]\n", i); 1963 else 1964 { 1965 fprintf (f, " [%8lu] ", i); 1966 bfd_sym_print_modules_table_entry (abfd, f, &entry); 1967 fprintf (f, "\n"); 1968 } 1969 } 1970 } 1971 1972 void 1973 bfd_sym_display_file_references_table (bfd *abfd, FILE *f) 1974 { 1975 unsigned long i; 1976 bfd_sym_file_references_table_entry entry; 1977 bfd_sym_data_struct *sdata = NULL; 1978 1979 BFD_ASSERT (bfd_sym_valid (abfd)); 1980 sdata = abfd->tdata.sym_data; 1981 1982 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n", 1983 sdata->header.dshb_frte.dti_object_count); 1984 1985 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++) 1986 { 1987 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0) 1988 fprintf (f, " [%8lu] [INVALID]\n", i); 1989 else 1990 { 1991 fprintf (f, " [%8lu] ", i); 1992 bfd_sym_print_file_references_table_entry (abfd, f, &entry); 1993 fprintf (f, "\n"); 1994 } 1995 } 1996 } 1997 1998 void 1999 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f) 2000 { 2001 unsigned long i; 2002 bfd_sym_contained_modules_table_entry entry; 2003 bfd_sym_data_struct *sdata = NULL; 2004 2005 BFD_ASSERT (bfd_sym_valid (abfd)); 2006 sdata = abfd->tdata.sym_data; 2007 2008 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n", 2009 sdata->header.dshb_cmte.dti_object_count); 2010 2011 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++) 2012 { 2013 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0) 2014 fprintf (f, " [%8lu] [INVALID]\n", i); 2015 else 2016 { 2017 fprintf (f, " [%8lu] ", i); 2018 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry); 2019 fprintf (f, "\n"); 2020 } 2021 } 2022 } 2023 2024 void 2025 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f) 2026 { 2027 unsigned long i; 2028 bfd_sym_contained_variables_table_entry entry; 2029 bfd_sym_data_struct *sdata = NULL; 2030 2031 BFD_ASSERT (bfd_sym_valid (abfd)); 2032 sdata = abfd->tdata.sym_data; 2033 2034 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n", 2035 sdata->header.dshb_cvte.dti_object_count); 2036 2037 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++) 2038 { 2039 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0) 2040 fprintf (f, " [%8lu] [INVALID]\n", i); 2041 else 2042 { 2043 fprintf (f, " [%8lu] ", i); 2044 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry); 2045 fprintf (f, "\n"); 2046 } 2047 } 2048 2049 fprintf (f, "\n"); 2050 } 2051 2052 void 2053 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f) 2054 { 2055 unsigned long i; 2056 bfd_sym_contained_statements_table_entry entry; 2057 bfd_sym_data_struct *sdata = NULL; 2058 2059 BFD_ASSERT (bfd_sym_valid (abfd)); 2060 sdata = abfd->tdata.sym_data; 2061 2062 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n", 2063 sdata->header.dshb_csnte.dti_object_count); 2064 2065 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++) 2066 { 2067 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0) 2068 fprintf (f, " [%8lu] [INVALID]\n", i); 2069 else 2070 { 2071 fprintf (f, " [%8lu] ", i); 2072 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry); 2073 fprintf (f, "\n"); 2074 } 2075 } 2076 } 2077 2078 void 2079 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f) 2080 { 2081 unsigned long i; 2082 bfd_sym_contained_labels_table_entry entry; 2083 bfd_sym_data_struct *sdata = NULL; 2084 2085 BFD_ASSERT (bfd_sym_valid (abfd)); 2086 sdata = abfd->tdata.sym_data; 2087 2088 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n", 2089 sdata->header.dshb_clte.dti_object_count); 2090 2091 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++) 2092 { 2093 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0) 2094 fprintf (f, " [%8lu] [INVALID]\n", i); 2095 else 2096 { 2097 fprintf (f, " [%8lu] ", i); 2098 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry); 2099 fprintf (f, "\n"); 2100 } 2101 } 2102 } 2103 2104 void 2105 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f) 2106 { 2107 unsigned long i; 2108 bfd_sym_contained_types_table_entry entry; 2109 bfd_sym_data_struct *sdata = NULL; 2110 2111 BFD_ASSERT (bfd_sym_valid (abfd)); 2112 sdata = abfd->tdata.sym_data; 2113 2114 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n", 2115 sdata->header.dshb_ctte.dti_object_count); 2116 2117 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++) 2118 { 2119 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0) 2120 fprintf (f, " [%8lu] [INVALID]\n", i); 2121 else 2122 { 2123 fprintf (f, " [%8lu] ", i); 2124 bfd_sym_print_contained_types_table_entry (abfd, f, &entry); 2125 fprintf (f, "\n"); 2126 } 2127 } 2128 } 2129 2130 void 2131 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f) 2132 { 2133 unsigned long i; 2134 bfd_sym_file_references_index_table_entry entry; 2135 bfd_sym_data_struct *sdata = NULL; 2136 2137 BFD_ASSERT (bfd_sym_valid (abfd)); 2138 sdata = abfd->tdata.sym_data; 2139 2140 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n", 2141 sdata->header.dshb_fite.dti_object_count); 2142 2143 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++) 2144 { 2145 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0) 2146 fprintf (f, " [%8lu] [INVALID]\n", i); 2147 else 2148 { 2149 fprintf (f, " [%8lu] ", i); 2150 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry); 2151 fprintf (f, "\n"); 2152 } 2153 } 2154 } 2155 2156 void 2157 bfd_sym_display_constant_pool (bfd *abfd, FILE *f) 2158 { 2159 unsigned long i; 2160 bfd_sym_constant_pool_entry entry; 2161 bfd_sym_data_struct *sdata = NULL; 2162 2163 BFD_ASSERT (bfd_sym_valid (abfd)); 2164 sdata = abfd->tdata.sym_data; 2165 2166 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n", 2167 sdata->header.dshb_const.dti_object_count); 2168 2169 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++) 2170 { 2171 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0) 2172 fprintf (f, " [%8lu] [INVALID]\n", i); 2173 else 2174 { 2175 fprintf (f, " [%8lu] ", i); 2176 bfd_sym_print_constant_pool_entry (abfd, f, &entry); 2177 fprintf (f, "\n"); 2178 } 2179 } 2180 } 2181 2182 void 2183 bfd_sym_display_type_information_table (bfd *abfd, FILE *f) 2184 { 2185 unsigned long i; 2186 bfd_sym_type_table_entry sym_index; 2187 bfd_sym_type_information_table_entry entry; 2188 bfd_sym_data_struct *sdata = NULL; 2189 2190 BFD_ASSERT (bfd_sym_valid (abfd)); 2191 sdata = abfd->tdata.sym_data; 2192 2193 if (sdata->header.dshb_tte.dti_object_count > 99) 2194 fprintf (f, "type table (TINFO) contains %lu objects:\n\n", 2195 sdata->header.dshb_tte.dti_object_count - 99); 2196 else 2197 { 2198 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n"); 2199 return; 2200 } 2201 2202 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++) 2203 { 2204 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0) 2205 fprintf (f, " [%8lu] [INVALID]\n", i); 2206 else 2207 { 2208 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index); 2209 2210 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0) 2211 fprintf (f, "[INVALID]"); 2212 else 2213 bfd_sym_print_type_information_table_entry (abfd, f, &entry); 2214 2215 fprintf (f, "\n"); 2216 } 2217 } 2218 } 2219 2220 int 2221 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata) 2222 { 2223 asection *bfdsec; 2224 const char *name = "symbols"; 2225 2226 mdata->name_table = 0; 2227 mdata->sbfd = abfd; 2228 mdata->version = version; 2229 2230 bfd_seek (abfd, 0, SEEK_SET); 2231 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0) 2232 return -1; 2233 2234 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header); 2235 if (mdata->name_table == NULL) 2236 return -1; 2237 2238 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS); 2239 if (bfdsec == NULL) 2240 return -1; 2241 2242 bfdsec->vma = 0; 2243 bfdsec->lma = 0; 2244 bfdsec->size = 0; 2245 bfdsec->filepos = 0; 2246 bfdsec->alignment_power = 0; 2247 2248 abfd->tdata.sym_data = mdata; 2249 2250 return 0; 2251 } 2252 2253 const bfd_target * 2254 bfd_sym_object_p (bfd *abfd) 2255 { 2256 bfd_sym_version version = -1; 2257 bfd_sym_data_struct *mdata; 2258 2259 bfd_seek (abfd, 0, SEEK_SET); 2260 if (bfd_sym_read_version (abfd, &version) != 0) 2261 goto wrong; 2262 2263 mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata)); 2264 if (mdata == NULL) 2265 goto fail; 2266 2267 if (bfd_sym_scan (abfd, version, mdata) != 0) 2268 goto wrong; 2269 2270 return abfd->xvec; 2271 2272 wrong: 2273 bfd_set_error (bfd_error_wrong_format); 2274 2275 fail: 2276 return NULL; 2277 } 2278 2279 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol 2280 2281 void 2282 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret) 2283 { 2284 bfd_symbol_info (symbol, ret); 2285 } 2286 2287 long 2288 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED) 2289 { 2290 return 0; 2291 } 2292 2293 long 2294 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED) 2295 { 2296 return 0; 2297 } 2298 2299 int 2300 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED, 2301 struct bfd_link_info *info ATTRIBUTE_UNUSED) 2302 { 2303 return 0; 2304 } 2305 2306 const bfd_target sym_vec = 2307 { 2308 "sym", /* Name. */ 2309 bfd_target_sym_flavour, /* Flavour. */ 2310 BFD_ENDIAN_BIG, /* Byteorder. */ 2311 BFD_ENDIAN_BIG, /* Header byteorder. */ 2312 (HAS_RELOC | EXEC_P | /* Object flags. */ 2313 HAS_LINENO | HAS_DEBUG | 2314 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), 2315 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA 2316 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */ 2317 0, /* Symbol_leading_char. */ 2318 ' ', /* AR_pad_char. */ 2319 16, /* AR_max_namelen. */ 2320 0, /* match priority. */ 2321 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 2322 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 2323 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */ 2324 bfd_getb64, bfd_getb_signed_64, bfd_putb64, 2325 bfd_getb32, bfd_getb_signed_32, bfd_putb32, 2326 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */ 2327 { /* bfd_check_format. */ 2328 _bfd_dummy_target, 2329 bfd_sym_object_p, /* bfd_check_format. */ 2330 _bfd_dummy_target, 2331 _bfd_dummy_target, 2332 }, 2333 { /* bfd_set_format. */ 2334 bfd_false, 2335 bfd_sym_mkobject, 2336 bfd_false, 2337 bfd_false, 2338 }, 2339 { /* bfd_write_contents. */ 2340 bfd_false, 2341 bfd_true, 2342 bfd_false, 2343 bfd_false, 2344 }, 2345 2346 BFD_JUMP_TABLE_GENERIC (bfd_sym), 2347 BFD_JUMP_TABLE_COPY (_bfd_generic), 2348 BFD_JUMP_TABLE_CORE (_bfd_nocore), 2349 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), 2350 BFD_JUMP_TABLE_SYMBOLS (bfd_sym), 2351 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), 2352 BFD_JUMP_TABLE_WRITE (bfd_sym), 2353 BFD_JUMP_TABLE_LINK (bfd_sym), 2354 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 2355 2356 NULL, 2357 2358 NULL 2359 }; 2360