1 /* xSYM symbol-file support for BFD.
2 Copyright (C) 1999-2016 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
21 /* xSYM is the debugging format used by CodeWarrior on Mac OS classic. */
24 #include "alloca-conf.h"
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
64 extern const bfd_target sym_vec;
67 pstrcmp (const char *as, const char *bs)
69 const unsigned char *a = (const unsigned char *) as;
70 const unsigned char *b = (const unsigned char *) bs;
74 clen = (a[0] > b[0]) ? b[0] : a[0];
75 ret = memcmp (a + 1, b + 1, clen);
88 compute_offset (unsigned long first_page,
89 unsigned long page_size,
90 unsigned long entry_size,
91 unsigned long sym_index)
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;
97 return (page_number * page_size) + page_offset;
101 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
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)
116 bfd_sym_valid (bfd *abfd)
118 if (abfd == NULL || abfd->xvec == NULL)
121 return abfd->xvec == &sym_vec;
125 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
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;
132 rstr = bfd_alloc (abfd, table_size);
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)
140 bfd_release (abfd, rstr);
148 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
150 bfd_sym_file_reference *entry)
152 BFD_ASSERT (len == 6);
154 entry->fref_frte_index = bfd_getb16 (buf);
155 entry->fref_offset = bfd_getb32 (buf + 2);
159 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
161 bfd_sym_table_info *table)
163 BFD_ASSERT (len == 8);
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);
171 bfd_sym_parse_header_v32 (unsigned char *buf,
173 bfd_sym_header_block *header)
175 BFD_ASSERT (len == 154);
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);
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);
197 memcpy (&header->dshb_file_creator, buf + 146, 4);
198 memcpy (&header->dshb_file_type, buf + 150, 4);
202 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
204 unsigned char buf[154];
207 ret = bfd_bread (buf, 154, abfd);
211 bfd_sym_parse_header_v32 (buf, 154, header);
217 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
218 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
224 bfd_sym_read_header (bfd *abfd,
225 bfd_sym_header_block *header,
226 bfd_sym_version version)
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:
243 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
245 char version_string[32];
248 ret = bfd_bread (version_string, sizeof (version_string), abfd);
249 if (ret != sizeof (version_string))
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;
269 bfd_sym_display_table_summary (FILE *f,
270 bfd_sym_table_info *dti,
273 fprintf (f, "%-6s %13ld %13ld %13ld\n",
277 dti->dti_object_count);
281 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
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);
291 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
292 dshb->dshb_file_creator, dshb->dshb_file_type);
294 fprintf (f, "Table Name First Page Page Count Object Count\n");
295 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
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");
315 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
317 bfd_sym_resources_table_entry *entry)
319 BFD_ASSERT (len == 18);
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);
330 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
332 bfd_sym_modules_table_entry *entry)
334 BFD_ASSERT (len == 46);
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);
354 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
356 bfd_sym_file_references_table_entry *entry)
360 BFD_ASSERT (len == 10);
362 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
363 type = bfd_getb16 (buf);
367 case BFD_SYM_END_OF_LIST_3_2:
368 entry->generic.type = BFD_SYM_END_OF_LIST;
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);
378 entry->entry.mte_index = type;
379 entry->entry.file_offset = bfd_getb32 (buf + 2);
384 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
386 bfd_sym_contained_modules_table_entry *entry)
390 BFD_ASSERT (len == 6);
392 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
393 type = bfd_getb16 (buf);
397 case BFD_SYM_END_OF_LIST_3_2:
398 entry->generic.type = BFD_SYM_END_OF_LIST;
402 entry->entry.mte_index = type;
403 entry->entry.nte_index = bfd_getb32 (buf + 2);
409 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
411 bfd_sym_contained_variables_table_entry *entry)
415 BFD_ASSERT (len == 26);
417 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
418 type = bfd_getb16 (buf);
422 case BFD_SYM_END_OF_LIST_3_2:
423 entry->generic.type = BFD_SYM_END_OF_LIST;
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);
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];
438 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
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);
444 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
446 #if BFD_SYM_CVTE_SCA > 0
447 memcpy (&entry->entry.address.lastruct.la, buf + 10,
450 entry->entry.address.lastruct.la_kind = buf[23];
452 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
454 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
455 entry->entry.address.biglastruct.big_la_kind = buf[12];
461 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
463 bfd_sym_contained_statements_table_entry *entry)
467 BFD_ASSERT (len == 8);
469 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
470 type = bfd_getb16 (buf);
474 case BFD_SYM_END_OF_LIST_3_2:
475 entry->generic.type = BFD_SYM_END_OF_LIST;
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);
484 entry->entry.mte_index = type;
485 entry->entry.mte_offset = bfd_getb16 (buf + 2);
486 entry->entry.file_delta = bfd_getb32 (buf + 4);
492 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
494 bfd_sym_contained_labels_table_entry *entry)
498 BFD_ASSERT (len == 12);
500 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
501 type = bfd_getb16 (buf);
505 case BFD_SYM_END_OF_LIST_3_2:
506 entry->generic.type = BFD_SYM_END_OF_LIST;
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);
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);
525 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
527 bfd_sym_type_table_entry *entry)
529 BFD_ASSERT (len == 4);
531 *entry = bfd_getb32 (buf);
535 bfd_sym_fetch_resources_table_entry (bfd *abfd,
536 bfd_sym_resources_table_entry *entry,
537 unsigned long sym_index)
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;
546 BFD_ASSERT (bfd_sym_valid (abfd));
547 sdata = abfd->tdata.sym_data;
552 switch (sdata->version)
554 case BFD_SYM_VERSION_3_5:
555 case BFD_SYM_VERSION_3_4:
558 case BFD_SYM_VERSION_3_3:
559 case BFD_SYM_VERSION_3_2:
561 parser = bfd_sym_parse_resources_table_entry_v32;
564 case BFD_SYM_VERSION_3_1:
571 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
572 sdata->header.dshb_page_size,
573 entry_size, sym_index);
575 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
577 if (bfd_bread (buf, entry_size, abfd) != entry_size)
580 (*parser) (buf, entry_size, entry);
586 bfd_sym_fetch_modules_table_entry (bfd *abfd,
587 bfd_sym_modules_table_entry *entry,
588 unsigned long sym_index)
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;
597 BFD_ASSERT (bfd_sym_valid (abfd));
598 sdata = abfd->tdata.sym_data;
603 switch (sdata->version)
605 case BFD_SYM_VERSION_3_5:
606 case BFD_SYM_VERSION_3_4:
609 case BFD_SYM_VERSION_3_3:
611 parser = bfd_sym_parse_modules_table_entry_v33;
614 case BFD_SYM_VERSION_3_2:
615 case BFD_SYM_VERSION_3_1:
622 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
623 sdata->header.dshb_page_size,
624 entry_size, sym_index);
626 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
628 if (bfd_bread (buf, entry_size, abfd) != entry_size)
631 (*parser) (buf, entry_size, entry);
637 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
638 bfd_sym_file_references_table_entry *entry,
639 unsigned long sym_index)
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;
648 BFD_ASSERT (bfd_sym_valid (abfd));
649 sdata = abfd->tdata.sym_data;
654 switch (sdata->version)
656 case BFD_SYM_VERSION_3_3:
657 case BFD_SYM_VERSION_3_2:
659 parser = bfd_sym_parse_file_references_table_entry_v32;
662 case BFD_SYM_VERSION_3_5:
663 case BFD_SYM_VERSION_3_4:
664 case BFD_SYM_VERSION_3_1:
672 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
673 sdata->header.dshb_page_size,
674 entry_size, sym_index);
676 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
678 if (bfd_bread (buf, entry_size, abfd) != entry_size)
681 (*parser) (buf, entry_size, entry);
687 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
688 bfd_sym_contained_modules_table_entry *entry,
689 unsigned long sym_index)
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;
698 BFD_ASSERT (bfd_sym_valid (abfd));
699 sdata = abfd->tdata.sym_data;
704 switch (sdata->version)
706 case BFD_SYM_VERSION_3_3:
707 case BFD_SYM_VERSION_3_2:
709 parser = bfd_sym_parse_contained_modules_table_entry_v32;
712 case BFD_SYM_VERSION_3_5:
713 case BFD_SYM_VERSION_3_4:
714 case BFD_SYM_VERSION_3_1:
722 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
723 sdata->header.dshb_page_size,
724 entry_size, sym_index);
726 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
728 if (bfd_bread (buf, entry_size, abfd) != entry_size)
731 (*parser) (buf, entry_size, entry);
737 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
738 bfd_sym_contained_variables_table_entry *entry,
739 unsigned long sym_index)
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;
748 BFD_ASSERT (bfd_sym_valid (abfd));
749 sdata = abfd->tdata.sym_data;
754 switch (sdata->version)
756 case BFD_SYM_VERSION_3_3:
757 case BFD_SYM_VERSION_3_2:
759 parser = bfd_sym_parse_contained_variables_table_entry_v32;
762 case BFD_SYM_VERSION_3_5:
763 case BFD_SYM_VERSION_3_4:
764 case BFD_SYM_VERSION_3_1:
772 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
773 sdata->header.dshb_page_size,
774 entry_size, sym_index);
776 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
778 if (bfd_bread (buf, entry_size, abfd) != entry_size)
781 (*parser) (buf, entry_size, entry);
787 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
788 bfd_sym_contained_statements_table_entry *entry,
789 unsigned long sym_index)
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;
798 BFD_ASSERT (bfd_sym_valid (abfd));
799 sdata = abfd->tdata.sym_data;
804 switch (sdata->version)
806 case BFD_SYM_VERSION_3_3:
807 case BFD_SYM_VERSION_3_2:
809 parser = bfd_sym_parse_contained_statements_table_entry_v32;
812 case BFD_SYM_VERSION_3_5:
813 case BFD_SYM_VERSION_3_4:
814 case BFD_SYM_VERSION_3_1:
822 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
823 sdata->header.dshb_page_size,
824 entry_size, sym_index);
826 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
828 if (bfd_bread (buf, entry_size, abfd) != entry_size)
831 (*parser) (buf, entry_size, entry);
837 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
838 bfd_sym_contained_labels_table_entry *entry,
839 unsigned long sym_index)
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;
848 BFD_ASSERT (bfd_sym_valid (abfd));
849 sdata = abfd->tdata.sym_data;
854 switch (sdata->version)
856 case BFD_SYM_VERSION_3_3:
857 case BFD_SYM_VERSION_3_2:
859 parser = bfd_sym_parse_contained_labels_table_entry_v32;
862 case BFD_SYM_VERSION_3_5:
863 case BFD_SYM_VERSION_3_4:
864 case BFD_SYM_VERSION_3_1:
872 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
873 sdata->header.dshb_page_size,
874 entry_size, sym_index);
876 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
878 if (bfd_bread (buf, entry_size, abfd) != entry_size)
881 (*parser) (buf, entry_size, entry);
887 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
888 bfd_sym_contained_types_table_entry *entry,
889 unsigned long sym_index)
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;
898 BFD_ASSERT (bfd_sym_valid (abfd));
899 sdata = abfd->tdata.sym_data;
904 switch (sdata->version)
906 case BFD_SYM_VERSION_3_3:
907 case BFD_SYM_VERSION_3_2:
912 case BFD_SYM_VERSION_3_5:
913 case BFD_SYM_VERSION_3_4:
914 case BFD_SYM_VERSION_3_1:
922 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
923 sdata->header.dshb_page_size,
924 entry_size, sym_index);
926 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
928 if (bfd_bread (buf, entry_size, abfd) != entry_size)
931 (*parser) (buf, entry_size, entry);
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)
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;
948 BFD_ASSERT (bfd_sym_valid (abfd));
949 sdata = abfd->tdata.sym_data;
954 switch (sdata->version)
956 case BFD_SYM_VERSION_3_3:
957 case BFD_SYM_VERSION_3_2:
962 case BFD_SYM_VERSION_3_5:
963 case BFD_SYM_VERSION_3_4:
964 case BFD_SYM_VERSION_3_1:
972 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
973 sdata->header.dshb_page_size,
974 entry_size, sym_index);
976 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
978 if (bfd_bread (buf, entry_size, abfd) != entry_size)
981 (*parser) (buf, entry_size, entry);
987 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
988 bfd_sym_constant_pool_entry *entry,
989 unsigned long sym_index)
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;
998 BFD_ASSERT (bfd_sym_valid (abfd));
999 sdata = abfd->tdata.sym_data;
1004 switch (sdata->version)
1006 case BFD_SYM_VERSION_3_3:
1007 case BFD_SYM_VERSION_3_2:
1012 case BFD_SYM_VERSION_3_5:
1013 case BFD_SYM_VERSION_3_4:
1014 case BFD_SYM_VERSION_3_1:
1022 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1023 sdata->header.dshb_page_size,
1024 entry_size, sym_index);
1026 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1028 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1031 (*parser) (buf, entry_size, entry);
1037 bfd_sym_fetch_type_table_entry (bfd *abfd,
1038 bfd_sym_type_table_entry *entry,
1039 unsigned long sym_index)
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;
1048 BFD_ASSERT (bfd_sym_valid (abfd));
1049 sdata = abfd->tdata.sym_data;
1051 switch (sdata->version)
1053 case BFD_SYM_VERSION_3_3:
1054 case BFD_SYM_VERSION_3_2:
1056 parser = bfd_sym_parse_type_table_entry_v32;
1059 case BFD_SYM_VERSION_3_5:
1060 case BFD_SYM_VERSION_3_4:
1061 case BFD_SYM_VERSION_3_1:
1069 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1070 sdata->header.dshb_page_size,
1071 entry_size, sym_index);
1073 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1075 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1078 (*parser) (buf, entry_size, entry);
1084 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1085 bfd_sym_type_information_table_entry *entry,
1086 unsigned long offset)
1088 unsigned char buf[4];
1090 BFD_ASSERT (bfd_sym_valid (abfd));
1095 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1098 if (bfd_bread (buf, 4, abfd) != 4)
1100 entry->nte_index = bfd_getb32 (buf);
1102 if (bfd_bread (buf, 2, abfd) != 2)
1104 entry->physical_size = bfd_getb16 (buf);
1106 if (entry->physical_size & 0x8000)
1108 if (bfd_bread (buf, 4, abfd) != 4)
1110 entry->physical_size &= 0x7fff;
1111 entry->logical_size = bfd_getb32 (buf);
1112 entry->offset = offset + 10;
1116 if (bfd_bread (buf, 2, abfd) != 2)
1118 entry->physical_size &= 0x7fff;
1119 entry->logical_size = bfd_getb16 (buf);
1120 entry->offset = offset + 8;
1127 bfd_sym_fetch_type_table_information (bfd *abfd,
1128 bfd_sym_type_information_table_entry *entry,
1129 unsigned long sym_index)
1131 bfd_sym_type_table_entry tindex;
1132 bfd_sym_data_struct *sdata = NULL;
1134 BFD_ASSERT (bfd_sym_valid (abfd));
1135 sdata = abfd->tdata.sym_data;
1137 if (sdata->header.dshb_tte.dti_object_count <= 99)
1139 if (sym_index < 100)
1142 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1144 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1150 const unsigned char *
1151 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1153 bfd_sym_data_struct *sdata = NULL;
1155 BFD_ASSERT (bfd_sym_valid (abfd));
1156 sdata = abfd->tdata.sym_data;
1159 return (const unsigned char *) "";
1162 if ((sym_index / sdata->header.dshb_page_size)
1163 > sdata->header.dshb_nte.dti_page_count)
1164 return (const unsigned char *) "\09[INVALID]";
1166 return (const unsigned char *) sdata->name_table + sym_index;
1169 const unsigned char *
1170 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1172 bfd_sym_modules_table_entry entry;
1174 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1175 return (const unsigned char *) "\09[INVALID]";
1177 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1181 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
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]";
1194 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
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]";
1211 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
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]";
1227 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1231 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1232 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1239 bfd_sym_print_file_reference (bfd *abfd,
1241 bfd_sym_file_reference *entry)
1243 bfd_sym_file_references_table_entry frtentry;
1246 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1247 entry->fref_frte_index);
1248 fprintf (f, "FILE ");
1250 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1251 fprintf (f, "[INVALID]");
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]);
1257 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1261 bfd_sym_print_resources_table_entry (bfd *abfd,
1263 bfd_sym_resources_table_entry *entry)
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);
1273 bfd_sym_print_modules_table_entry (bfd *abfd,
1275 bfd_sym_modules_table_entry *entry)
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);
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);
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));
1293 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1294 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
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);
1303 if (entry->mte_parent != 0)
1304 fprintf (f, ", parent %lu", entry->mte_parent);
1306 fprintf (f, ", no parent");
1308 if (entry->mte_cmte_index != 0)
1309 fprintf (f, ", child %lu", entry->mte_cmte_index);
1311 fprintf (f, ", no child");
1315 bfd_sym_print_file_references_table_entry (bfd *abfd,
1317 bfd_sym_file_references_table_entry *entry)
1319 switch (entry->generic.type)
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);
1327 fprintf (f, "[UNIMPLEMENTED]");
1328 /* printModDate (entry->filename.mod_date); */
1329 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1332 case BFD_SYM_END_OF_LIST:
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);
1347 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1349 bfd_sym_contained_modules_table_entry *entry)
1351 switch (entry->generic.type)
1353 case BFD_SYM_END_OF_LIST:
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);
1368 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1370 bfd_sym_contained_variables_table_entry *entry)
1372 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1378 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1380 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1381 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
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);
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));
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)
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]);
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);
1414 fprintf (f, ", la [INVALID]");
1418 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1420 bfd_sym_contained_statements_table_entry *entry)
1422 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1428 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1430 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1431 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
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);
1444 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1446 bfd_sym_contained_labels_table_entry *entry)
1448 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1454 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1456 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1457 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
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));
1471 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1473 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1475 fprintf (f, "[UNIMPLEMENTED]");
1479 bfd_sym_type_operator_name (unsigned char num)
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]";
1502 bfd_sym_type_basic_name (unsigned char num)
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]";
1529 bfd_sym_fetch_long (unsigned char *buf,
1531 unsigned long offset,
1532 unsigned long *offsetptr,
1543 else if (! (buf[offset] & 0x80))
1545 *value = buf[offset];
1549 else if (buf[offset] == 0xc0)
1551 if ((offset + 5) > len)
1559 *value = bfd_getb32 (buf + offset + 1);
1564 else if ((buf[offset] & 0xc0) == 0xc0)
1566 *value = -(buf[offset] & 0x3f);
1570 else if ((buf[offset] & 0xc0) == 0x80)
1572 if ((offset + 2) > len)
1580 *value = bfd_getb16 (buf + offset) & 0x3fff;
1588 if (offsetptr != NULL)
1589 *offsetptr = offset;
1595 bfd_sym_print_type_information (bfd *abfd,
1599 unsigned long offset,
1600 unsigned long *offsetptr)
1606 fprintf (f, "[NULL]");
1608 if (offsetptr != NULL)
1609 *offsetptr = offset;
1616 if (! (type & 0x80))
1618 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1620 if (offsetptr != NULL)
1621 *offsetptr = offset;
1626 fprintf (f, "[packed ");
1630 switch (type & 0x3f)
1635 bfd_sym_type_information_table_entry tinfo;
1637 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1639 fprintf (f, "[INVALID]");
1642 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1643 fprintf (f, "[INVALID]");
1645 fprintf (f, "\"%.*s\"",
1646 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1647 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1649 fprintf (f, " (TTE %lu)", (unsigned long) value);
1654 fprintf (f, "pointer (0x%x) to ", type);
1655 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
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);
1671 long lower, upper, nelem;
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);
1683 for (i = 0; i < nelem; i++)
1686 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
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);
1702 long nrec, eloff, i;
1704 if ((type & 0x3f) == 7)
1705 fprintf (f, "record (0x%x) of ", type);
1707 fprintf (f, "union (0x%x) of ", type);
1709 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1710 fprintf (f, "%lu elements: ", (unsigned long) nrec);
1712 for (i = 0; i < nrec; i++)
1714 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1716 fprintf (f, "offset %lu: ", (unsigned long) eloff);
1717 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
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);
1735 fprintf (f, "named type (0x%x) ", type);
1736 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1738 fprintf (f, "[INVALID]");
1740 fprintf (f, "\"%.*s\"",
1741 bfd_sym_symbol_name (abfd, value)[0],
1742 &bfd_sym_symbol_name (abfd, value)[1]);
1744 fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1745 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1750 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1754 if (type == (0x40 | 0x6))
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++)
1768 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1771 fprintf (f, "%ld", l);
1774 else if (type & 0x40)
1776 /* Other packed type. */
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);
1787 if (offsetptr != NULL)
1788 *offsetptr = offset;
1792 bfd_sym_print_type_information_table_entry (bfd *abfd,
1794 bfd_sym_type_information_table_entry *entry)
1797 unsigned long offset;
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],
1804 entry->physical_size, entry->offset, entry->logical_size);
1808 buf = malloc (entry->physical_size);
1811 fprintf (f, "[ERROR]\n");
1814 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1816 fprintf (f, "[ERROR]\n");
1820 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1822 fprintf (f, "[ERROR]\n");
1828 for (i = 0; i < entry->physical_size; i++)
1831 fprintf (f, "0x%02x", buf[i]);
1833 fprintf (f, " 0x%02x", buf[i]);
1839 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1841 if (offset != entry->physical_size)
1842 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1847 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1849 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1851 fprintf (f, "[UNIMPLEMENTED]");
1855 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1857 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1859 fprintf (f, "[UNIMPLEMENTED]");
1863 bfd_sym_display_name_table_entry (bfd *abfd,
1865 unsigned char *entry)
1867 unsigned long sym_index;
1868 unsigned long offset;
1869 bfd_sym_data_struct *sdata = NULL;
1871 BFD_ASSERT (bfd_sym_valid (abfd));
1872 sdata = abfd->tdata.sym_data;
1873 sym_index = (entry - sdata->name_table) / 2;
1875 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1877 unsigned short length = bfd_getb16 (entry + 2);
1878 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1879 offset = 2 + length + 1;
1883 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1884 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1886 if (sdata->version >= BFD_SYM_VERSION_3_4)
1887 offset = entry[0] + 2;
1889 offset = entry[0] + 1;
1892 return (entry + offset + (offset % 2));
1896 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1898 unsigned long name_table_len;
1899 unsigned char *name_table, *name_table_end, *cur;
1900 bfd_sym_data_struct *sdata = NULL;
1902 BFD_ASSERT (bfd_sym_valid (abfd));
1903 sdata = abfd->tdata.sym_data;
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;
1909 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1914 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1915 if (cur >= name_table_end)
1921 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1924 bfd_sym_resources_table_entry entry;
1925 bfd_sym_data_struct *sdata = NULL;
1927 BFD_ASSERT (bfd_sym_valid (abfd));
1928 sdata = abfd->tdata.sym_data;
1930 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1931 sdata->header.dshb_rte.dti_object_count);
1933 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1935 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1936 fprintf (f, " [%8lu] [INVALID]\n", i);
1939 fprintf (f, " [%8lu] ", i);
1940 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1947 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1950 bfd_sym_modules_table_entry entry;
1951 bfd_sym_data_struct *sdata = NULL;
1953 BFD_ASSERT (bfd_sym_valid (abfd));
1954 sdata = abfd->tdata.sym_data;
1956 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1957 sdata->header.dshb_mte.dti_object_count);
1959 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1961 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1962 fprintf (f, " [%8lu] [INVALID]\n", i);
1965 fprintf (f, " [%8lu] ", i);
1966 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1973 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1976 bfd_sym_file_references_table_entry entry;
1977 bfd_sym_data_struct *sdata = NULL;
1979 BFD_ASSERT (bfd_sym_valid (abfd));
1980 sdata = abfd->tdata.sym_data;
1982 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1983 sdata->header.dshb_frte.dti_object_count);
1985 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1987 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1988 fprintf (f, " [%8lu] [INVALID]\n", i);
1991 fprintf (f, " [%8lu] ", i);
1992 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1999 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
2002 bfd_sym_contained_modules_table_entry entry;
2003 bfd_sym_data_struct *sdata = NULL;
2005 BFD_ASSERT (bfd_sym_valid (abfd));
2006 sdata = abfd->tdata.sym_data;
2008 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2009 sdata->header.dshb_cmte.dti_object_count);
2011 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2013 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2014 fprintf (f, " [%8lu] [INVALID]\n", i);
2017 fprintf (f, " [%8lu] ", i);
2018 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2025 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2028 bfd_sym_contained_variables_table_entry entry;
2029 bfd_sym_data_struct *sdata = NULL;
2031 BFD_ASSERT (bfd_sym_valid (abfd));
2032 sdata = abfd->tdata.sym_data;
2034 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2035 sdata->header.dshb_cvte.dti_object_count);
2037 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2039 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2040 fprintf (f, " [%8lu] [INVALID]\n", i);
2043 fprintf (f, " [%8lu] ", i);
2044 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2053 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2056 bfd_sym_contained_statements_table_entry entry;
2057 bfd_sym_data_struct *sdata = NULL;
2059 BFD_ASSERT (bfd_sym_valid (abfd));
2060 sdata = abfd->tdata.sym_data;
2062 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2063 sdata->header.dshb_csnte.dti_object_count);
2065 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2067 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2068 fprintf (f, " [%8lu] [INVALID]\n", i);
2071 fprintf (f, " [%8lu] ", i);
2072 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2079 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2082 bfd_sym_contained_labels_table_entry entry;
2083 bfd_sym_data_struct *sdata = NULL;
2085 BFD_ASSERT (bfd_sym_valid (abfd));
2086 sdata = abfd->tdata.sym_data;
2088 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2089 sdata->header.dshb_clte.dti_object_count);
2091 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2093 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2094 fprintf (f, " [%8lu] [INVALID]\n", i);
2097 fprintf (f, " [%8lu] ", i);
2098 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2105 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2108 bfd_sym_contained_types_table_entry entry;
2109 bfd_sym_data_struct *sdata = NULL;
2111 BFD_ASSERT (bfd_sym_valid (abfd));
2112 sdata = abfd->tdata.sym_data;
2114 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2115 sdata->header.dshb_ctte.dti_object_count);
2117 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2119 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2120 fprintf (f, " [%8lu] [INVALID]\n", i);
2123 fprintf (f, " [%8lu] ", i);
2124 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2131 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2134 bfd_sym_file_references_index_table_entry entry;
2135 bfd_sym_data_struct *sdata = NULL;
2137 BFD_ASSERT (bfd_sym_valid (abfd));
2138 sdata = abfd->tdata.sym_data;
2140 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2141 sdata->header.dshb_fite.dti_object_count);
2143 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2145 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2146 fprintf (f, " [%8lu] [INVALID]\n", i);
2149 fprintf (f, " [%8lu] ", i);
2150 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2157 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2160 bfd_sym_constant_pool_entry entry;
2161 bfd_sym_data_struct *sdata = NULL;
2163 BFD_ASSERT (bfd_sym_valid (abfd));
2164 sdata = abfd->tdata.sym_data;
2166 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2167 sdata->header.dshb_const.dti_object_count);
2169 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2171 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2172 fprintf (f, " [%8lu] [INVALID]\n", i);
2175 fprintf (f, " [%8lu] ", i);
2176 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2183 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2186 bfd_sym_type_table_entry sym_index;
2187 bfd_sym_type_information_table_entry entry;
2188 bfd_sym_data_struct *sdata = NULL;
2190 BFD_ASSERT (bfd_sym_valid (abfd));
2191 sdata = abfd->tdata.sym_data;
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);
2198 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2202 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2204 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2205 fprintf (f, " [%8lu] [INVALID]\n", i);
2208 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2210 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2211 fprintf (f, "[INVALID]");
2213 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2221 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2224 const char *name = "symbols";
2226 mdata->name_table = 0;
2228 mdata->version = version;
2230 bfd_seek (abfd, 0, SEEK_SET);
2231 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2234 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2235 if (mdata->name_table == NULL)
2238 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2245 bfdsec->filepos = 0;
2246 bfdsec->alignment_power = 0;
2248 abfd->tdata.sym_data = mdata;
2254 bfd_sym_object_p (bfd *abfd)
2256 bfd_sym_version version = -1;
2257 bfd_sym_data_struct *mdata;
2259 bfd_seek (abfd, 0, SEEK_SET);
2260 if (bfd_sym_read_version (abfd, &version) != 0)
2263 mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
2267 if (bfd_sym_scan (abfd, version, mdata) != 0)
2273 bfd_set_error (bfd_error_wrong_format);
2279 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2282 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2284 bfd_symbol_info (symbol, ret);
2288 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2294 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2300 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2301 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2306 const bfd_target sym_vec =
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. */
2329 bfd_sym_object_p, /* bfd_check_format. */
2333 { /* bfd_set_format. */
2339 { /* bfd_write_contents. */
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),