1 /* xSYM symbol-file support for BFD.
2 Copyright (C) 1999-2018 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_bool_bfd_asymbol_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_hide_symbol _bfd_generic_link_hide_symbol
55 #define bfd_sym_bfd_define_start_stop bfd_generic_define_start_stop
56 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
57 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
58 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
59 #define bfd_sym_bfd_copy_link_hash_symbol_type \
60 _bfd_generic_copy_link_hash_symbol_type
61 #define bfd_sym_bfd_final_link _bfd_generic_final_link
62 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
63 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
64 #define bfd_sym_bfd_link_check_relocs _bfd_generic_link_check_relocs
66 extern const bfd_target sym_vec;
69 pstrcmp (const char *as, const char *bs)
71 const unsigned char *a = (const unsigned char *) as;
72 const unsigned char *b = (const unsigned char *) bs;
76 clen = (a[0] > b[0]) ? b[0] : a[0];
77 ret = memcmp (a + 1, b + 1, clen);
90 compute_offset (unsigned long first_page,
91 unsigned long page_size,
92 unsigned long entry_size,
93 unsigned long sym_index)
95 unsigned long entries_per_page = page_size / entry_size;
96 unsigned long page_number = first_page + (sym_index / entries_per_page);
97 unsigned long page_offset = (sym_index % entries_per_page) * entry_size;
99 return (page_number * page_size) + page_offset;
103 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
109 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
110 void * afile ATTRIBUTE_UNUSED,
111 asymbol *symbol ATTRIBUTE_UNUSED,
112 bfd_print_symbol_type how ATTRIBUTE_UNUSED)
118 bfd_sym_valid (bfd *abfd)
120 if (abfd == NULL || abfd->xvec == NULL)
123 return abfd->xvec == &sym_vec;
127 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
131 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
132 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
134 rstr = bfd_alloc (abfd, table_size);
138 bfd_seek (abfd, table_offset, SEEK_SET);
139 ret = bfd_bread (rstr, table_size, abfd);
140 if (ret < 0 || (unsigned long) ret != table_size)
142 bfd_release (abfd, rstr);
150 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
152 bfd_sym_file_reference *entry)
154 BFD_ASSERT (len == 6);
156 entry->fref_frte_index = bfd_getb16 (buf);
157 entry->fref_offset = bfd_getb32 (buf + 2);
161 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
163 bfd_sym_table_info *table)
165 BFD_ASSERT (len == 8);
167 table->dti_first_page = bfd_getb16 (buf);
168 table->dti_page_count = bfd_getb16 (buf + 2);
169 table->dti_object_count = bfd_getb32 (buf + 4);
173 bfd_sym_parse_header_v32 (unsigned char *buf,
175 bfd_sym_header_block *header)
177 BFD_ASSERT (len == 154);
179 memcpy (header->dshb_id, buf, 32);
180 header->dshb_page_size = bfd_getb16 (buf + 32);
181 header->dshb_hash_page = bfd_getb16 (buf + 34);
182 header->dshb_root_mte = bfd_getb16 (buf + 36);
183 header->dshb_mod_date = bfd_getb32 (buf + 38);
185 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
186 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
187 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
188 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
189 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
190 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
191 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
192 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
193 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
194 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
195 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
196 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
197 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
199 memcpy (&header->dshb_file_creator, buf + 146, 4);
200 memcpy (&header->dshb_file_type, buf + 150, 4);
204 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
206 unsigned char buf[154];
209 ret = bfd_bread (buf, 154, abfd);
213 bfd_sym_parse_header_v32 (buf, 154, header);
219 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
220 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
226 bfd_sym_read_header (bfd *abfd,
227 bfd_sym_header_block *header,
228 bfd_sym_version version)
232 case BFD_SYM_VERSION_3_5:
233 case BFD_SYM_VERSION_3_4:
234 return bfd_sym_read_header_v34 (abfd, header);
235 case BFD_SYM_VERSION_3_3:
236 case BFD_SYM_VERSION_3_2:
237 return bfd_sym_read_header_v32 (abfd, header);
238 case BFD_SYM_VERSION_3_1:
245 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
247 char version_string[32];
250 ret = bfd_bread (version_string, sizeof (version_string), abfd);
251 if (ret != sizeof (version_string))
254 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
255 *version = BFD_SYM_VERSION_3_1;
256 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
257 *version = BFD_SYM_VERSION_3_2;
258 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
259 *version = BFD_SYM_VERSION_3_3;
260 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
261 *version = BFD_SYM_VERSION_3_4;
262 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
263 *version = BFD_SYM_VERSION_3_5;
271 bfd_sym_display_table_summary (FILE *f,
272 bfd_sym_table_info *dti,
275 fprintf (f, "%-6s %13ld %13ld %13ld\n",
279 dti->dti_object_count);
283 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
285 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
286 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
287 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
288 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
289 fprintf (f, " Modification Date: ");
290 fprintf (f, "[unimplemented]");
291 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
293 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
294 dshb->dshb_file_creator, dshb->dshb_file_type);
296 fprintf (f, "Table Name First Page Page Count Object Count\n");
297 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
299 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
300 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
301 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
302 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
303 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
304 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
305 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
306 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
307 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
308 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
309 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
310 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
311 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
317 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
319 bfd_sym_resources_table_entry *entry)
321 BFD_ASSERT (len == 18);
323 memcpy (&entry->rte_res_type, buf, 4);
324 entry->rte_res_number = bfd_getb16 (buf + 4);
325 entry->rte_nte_index = bfd_getb32 (buf + 6);
326 entry->rte_mte_first = bfd_getb16 (buf + 10);
327 entry->rte_mte_last = bfd_getb16 (buf + 12);
328 entry->rte_res_size = bfd_getb32 (buf + 14);
332 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
334 bfd_sym_modules_table_entry *entry)
336 BFD_ASSERT (len == 46);
338 entry->mte_rte_index = bfd_getb16 (buf);
339 entry->mte_res_offset = bfd_getb32 (buf + 2);
340 entry->mte_size = bfd_getb32 (buf + 6);
341 entry->mte_kind = buf[10];
342 entry->mte_scope = buf[11];
343 entry->mte_parent = bfd_getb16 (buf + 12);
344 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
345 entry->mte_imp_end = bfd_getb32 (buf + 20);
346 entry->mte_nte_index = bfd_getb32 (buf + 24);
347 entry->mte_cmte_index = bfd_getb16 (buf + 28);
348 entry->mte_cvte_index = bfd_getb32 (buf + 30);
349 entry->mte_clte_index = bfd_getb16 (buf + 34);
350 entry->mte_ctte_index = bfd_getb16 (buf + 36);
351 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
352 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
356 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
358 bfd_sym_file_references_table_entry *entry)
362 BFD_ASSERT (len == 10);
364 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
365 type = bfd_getb16 (buf);
369 case BFD_SYM_END_OF_LIST_3_2:
370 entry->generic.type = BFD_SYM_END_OF_LIST;
373 case BFD_SYM_FILE_NAME_INDEX_3_2:
374 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
375 entry->filename.nte_index = bfd_getb32 (buf + 2);
376 entry->filename.mod_date = bfd_getb32 (buf + 6);
380 entry->entry.mte_index = type;
381 entry->entry.file_offset = bfd_getb32 (buf + 2);
386 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
388 bfd_sym_contained_modules_table_entry *entry)
392 BFD_ASSERT (len == 6);
394 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
395 type = bfd_getb16 (buf);
399 case BFD_SYM_END_OF_LIST_3_2:
400 entry->generic.type = BFD_SYM_END_OF_LIST;
404 entry->entry.mte_index = type;
405 entry->entry.nte_index = bfd_getb32 (buf + 2);
411 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
413 bfd_sym_contained_variables_table_entry *entry)
417 BFD_ASSERT (len == 26);
419 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
420 type = bfd_getb16 (buf);
424 case BFD_SYM_END_OF_LIST_3_2:
425 entry->generic.type = BFD_SYM_END_OF_LIST;
428 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
429 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
430 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
434 entry->entry.tte_index = type;
435 entry->entry.nte_index = bfd_getb32 (buf + 2);
436 entry->entry.file_delta = bfd_getb16 (buf + 6);
437 entry->entry.scope = buf[8];
438 entry->entry.la_size = buf[9];
440 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
442 entry->entry.address.scstruct.sca_kind = buf[10];
443 entry->entry.address.scstruct.sca_class = buf[11];
444 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
446 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
448 #if BFD_SYM_CVTE_SCA > 0
449 memcpy (&entry->entry.address.lastruct.la, buf + 10,
452 entry->entry.address.lastruct.la_kind = buf[23];
454 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
456 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
457 entry->entry.address.biglastruct.big_la_kind = buf[12];
463 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
465 bfd_sym_contained_statements_table_entry *entry)
469 BFD_ASSERT (len == 8);
471 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
472 type = bfd_getb16 (buf);
476 case BFD_SYM_END_OF_LIST_3_2:
477 entry->generic.type = BFD_SYM_END_OF_LIST;
480 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
481 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
482 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
486 entry->entry.mte_index = type;
487 entry->entry.mte_offset = bfd_getb16 (buf + 2);
488 entry->entry.file_delta = bfd_getb32 (buf + 4);
494 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
496 bfd_sym_contained_labels_table_entry *entry)
500 BFD_ASSERT (len == 12);
502 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
503 type = bfd_getb16 (buf);
507 case BFD_SYM_END_OF_LIST_3_2:
508 entry->generic.type = BFD_SYM_END_OF_LIST;
511 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
512 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
513 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
517 entry->entry.mte_index = type;
518 entry->entry.mte_offset = bfd_getb16 (buf + 2);
519 entry->entry.nte_index = bfd_getb32 (buf + 4);
520 entry->entry.file_delta = bfd_getb16 (buf + 8);
521 entry->entry.scope = bfd_getb16 (buf + 10);
527 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
529 bfd_sym_type_table_entry *entry)
531 BFD_ASSERT (len == 4);
533 *entry = bfd_getb32 (buf);
537 bfd_sym_fetch_resources_table_entry (bfd *abfd,
538 bfd_sym_resources_table_entry *entry,
539 unsigned long sym_index)
541 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
542 unsigned long offset;
543 unsigned long entry_size;
544 unsigned char buf[18];
545 bfd_sym_data_struct *sdata = NULL;
548 BFD_ASSERT (bfd_sym_valid (abfd));
549 sdata = abfd->tdata.sym_data;
554 switch (sdata->version)
556 case BFD_SYM_VERSION_3_5:
557 case BFD_SYM_VERSION_3_4:
560 case BFD_SYM_VERSION_3_3:
561 case BFD_SYM_VERSION_3_2:
563 parser = bfd_sym_parse_resources_table_entry_v32;
566 case BFD_SYM_VERSION_3_1:
573 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
574 sdata->header.dshb_page_size,
575 entry_size, sym_index);
577 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
579 if (bfd_bread (buf, entry_size, abfd) != entry_size)
582 (*parser) (buf, entry_size, entry);
588 bfd_sym_fetch_modules_table_entry (bfd *abfd,
589 bfd_sym_modules_table_entry *entry,
590 unsigned long sym_index)
592 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
593 unsigned long offset;
594 unsigned long entry_size;
595 unsigned char buf[46];
596 bfd_sym_data_struct *sdata = NULL;
599 BFD_ASSERT (bfd_sym_valid (abfd));
600 sdata = abfd->tdata.sym_data;
605 switch (sdata->version)
607 case BFD_SYM_VERSION_3_5:
608 case BFD_SYM_VERSION_3_4:
611 case BFD_SYM_VERSION_3_3:
613 parser = bfd_sym_parse_modules_table_entry_v33;
616 case BFD_SYM_VERSION_3_2:
617 case BFD_SYM_VERSION_3_1:
624 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
625 sdata->header.dshb_page_size,
626 entry_size, sym_index);
628 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
630 if (bfd_bread (buf, entry_size, abfd) != entry_size)
633 (*parser) (buf, entry_size, entry);
639 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
640 bfd_sym_file_references_table_entry *entry,
641 unsigned long sym_index)
643 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
644 unsigned long offset;
645 unsigned long entry_size = 0;
646 unsigned char buf[8];
647 bfd_sym_data_struct *sdata = NULL;
650 BFD_ASSERT (bfd_sym_valid (abfd));
651 sdata = abfd->tdata.sym_data;
656 switch (sdata->version)
658 case BFD_SYM_VERSION_3_3:
659 case BFD_SYM_VERSION_3_2:
661 parser = bfd_sym_parse_file_references_table_entry_v32;
664 case BFD_SYM_VERSION_3_5:
665 case BFD_SYM_VERSION_3_4:
666 case BFD_SYM_VERSION_3_1:
674 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
675 sdata->header.dshb_page_size,
676 entry_size, sym_index);
678 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
680 if (bfd_bread (buf, entry_size, abfd) != entry_size)
683 (*parser) (buf, entry_size, entry);
689 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
690 bfd_sym_contained_modules_table_entry *entry,
691 unsigned long sym_index)
693 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
694 unsigned long offset;
695 unsigned long entry_size = 0;
696 unsigned char buf[6];
697 bfd_sym_data_struct *sdata = NULL;
700 BFD_ASSERT (bfd_sym_valid (abfd));
701 sdata = abfd->tdata.sym_data;
706 switch (sdata->version)
708 case BFD_SYM_VERSION_3_3:
709 case BFD_SYM_VERSION_3_2:
711 parser = bfd_sym_parse_contained_modules_table_entry_v32;
714 case BFD_SYM_VERSION_3_5:
715 case BFD_SYM_VERSION_3_4:
716 case BFD_SYM_VERSION_3_1:
724 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
725 sdata->header.dshb_page_size,
726 entry_size, sym_index);
728 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
730 if (bfd_bread (buf, entry_size, abfd) != entry_size)
733 (*parser) (buf, entry_size, entry);
739 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
740 bfd_sym_contained_variables_table_entry *entry,
741 unsigned long sym_index)
743 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
744 unsigned long offset;
745 unsigned long entry_size = 0;
746 unsigned char buf[26];
747 bfd_sym_data_struct *sdata = NULL;
750 BFD_ASSERT (bfd_sym_valid (abfd));
751 sdata = abfd->tdata.sym_data;
756 switch (sdata->version)
758 case BFD_SYM_VERSION_3_3:
759 case BFD_SYM_VERSION_3_2:
761 parser = bfd_sym_parse_contained_variables_table_entry_v32;
764 case BFD_SYM_VERSION_3_5:
765 case BFD_SYM_VERSION_3_4:
766 case BFD_SYM_VERSION_3_1:
774 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
775 sdata->header.dshb_page_size,
776 entry_size, sym_index);
778 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
780 if (bfd_bread (buf, entry_size, abfd) != entry_size)
783 (*parser) (buf, entry_size, entry);
789 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
790 bfd_sym_contained_statements_table_entry *entry,
791 unsigned long sym_index)
793 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
794 unsigned long offset;
795 unsigned long entry_size = 0;
796 unsigned char buf[8];
797 bfd_sym_data_struct *sdata = NULL;
800 BFD_ASSERT (bfd_sym_valid (abfd));
801 sdata = abfd->tdata.sym_data;
806 switch (sdata->version)
808 case BFD_SYM_VERSION_3_3:
809 case BFD_SYM_VERSION_3_2:
811 parser = bfd_sym_parse_contained_statements_table_entry_v32;
814 case BFD_SYM_VERSION_3_5:
815 case BFD_SYM_VERSION_3_4:
816 case BFD_SYM_VERSION_3_1:
824 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
825 sdata->header.dshb_page_size,
826 entry_size, sym_index);
828 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
830 if (bfd_bread (buf, entry_size, abfd) != entry_size)
833 (*parser) (buf, entry_size, entry);
839 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
840 bfd_sym_contained_labels_table_entry *entry,
841 unsigned long sym_index)
843 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
844 unsigned long offset;
845 unsigned long entry_size = 0;
846 unsigned char buf[12];
847 bfd_sym_data_struct *sdata = NULL;
850 BFD_ASSERT (bfd_sym_valid (abfd));
851 sdata = abfd->tdata.sym_data;
856 switch (sdata->version)
858 case BFD_SYM_VERSION_3_3:
859 case BFD_SYM_VERSION_3_2:
861 parser = bfd_sym_parse_contained_labels_table_entry_v32;
864 case BFD_SYM_VERSION_3_5:
865 case BFD_SYM_VERSION_3_4:
866 case BFD_SYM_VERSION_3_1:
874 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
875 sdata->header.dshb_page_size,
876 entry_size, sym_index);
878 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
880 if (bfd_bread (buf, entry_size, abfd) != entry_size)
883 (*parser) (buf, entry_size, entry);
889 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
890 bfd_sym_contained_types_table_entry *entry,
891 unsigned long sym_index)
893 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
894 unsigned long offset;
895 unsigned long entry_size = 0;
896 unsigned char buf[0];
897 bfd_sym_data_struct *sdata = NULL;
900 BFD_ASSERT (bfd_sym_valid (abfd));
901 sdata = abfd->tdata.sym_data;
906 switch (sdata->version)
908 case BFD_SYM_VERSION_3_3:
909 case BFD_SYM_VERSION_3_2:
914 case BFD_SYM_VERSION_3_5:
915 case BFD_SYM_VERSION_3_4:
916 case BFD_SYM_VERSION_3_1:
924 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
925 sdata->header.dshb_page_size,
926 entry_size, sym_index);
928 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
930 if (bfd_bread (buf, entry_size, abfd) != entry_size)
933 (*parser) (buf, entry_size, entry);
939 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
940 bfd_sym_file_references_index_table_entry *entry,
941 unsigned long sym_index)
943 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
944 unsigned long offset;
945 unsigned long entry_size = 0;
946 unsigned char buf[0];
947 bfd_sym_data_struct *sdata = NULL;
950 BFD_ASSERT (bfd_sym_valid (abfd));
951 sdata = abfd->tdata.sym_data;
956 switch (sdata->version)
958 case BFD_SYM_VERSION_3_3:
959 case BFD_SYM_VERSION_3_2:
964 case BFD_SYM_VERSION_3_5:
965 case BFD_SYM_VERSION_3_4:
966 case BFD_SYM_VERSION_3_1:
974 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
975 sdata->header.dshb_page_size,
976 entry_size, sym_index);
978 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
980 if (bfd_bread (buf, entry_size, abfd) != entry_size)
983 (*parser) (buf, entry_size, entry);
989 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
990 bfd_sym_constant_pool_entry *entry,
991 unsigned long sym_index)
993 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
994 unsigned long offset;
995 unsigned long entry_size = 0;
996 unsigned char buf[0];
997 bfd_sym_data_struct *sdata = NULL;
1000 BFD_ASSERT (bfd_sym_valid (abfd));
1001 sdata = abfd->tdata.sym_data;
1006 switch (sdata->version)
1008 case BFD_SYM_VERSION_3_3:
1009 case BFD_SYM_VERSION_3_2:
1014 case BFD_SYM_VERSION_3_5:
1015 case BFD_SYM_VERSION_3_4:
1016 case BFD_SYM_VERSION_3_1:
1024 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1025 sdata->header.dshb_page_size,
1026 entry_size, sym_index);
1028 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1030 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1033 (*parser) (buf, entry_size, entry);
1039 bfd_sym_fetch_type_table_entry (bfd *abfd,
1040 bfd_sym_type_table_entry *entry,
1041 unsigned long sym_index)
1043 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1044 unsigned long offset;
1045 unsigned long entry_size = 0;
1046 unsigned char buf[4];
1047 bfd_sym_data_struct *sdata = NULL;
1050 BFD_ASSERT (bfd_sym_valid (abfd));
1051 sdata = abfd->tdata.sym_data;
1053 switch (sdata->version)
1055 case BFD_SYM_VERSION_3_3:
1056 case BFD_SYM_VERSION_3_2:
1058 parser = bfd_sym_parse_type_table_entry_v32;
1061 case BFD_SYM_VERSION_3_5:
1062 case BFD_SYM_VERSION_3_4:
1063 case BFD_SYM_VERSION_3_1:
1071 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1072 sdata->header.dshb_page_size,
1073 entry_size, sym_index);
1075 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1077 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1080 (*parser) (buf, entry_size, entry);
1086 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1087 bfd_sym_type_information_table_entry *entry,
1088 unsigned long offset)
1090 unsigned char buf[4];
1092 BFD_ASSERT (bfd_sym_valid (abfd));
1097 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1100 if (bfd_bread (buf, 4, abfd) != 4)
1102 entry->nte_index = bfd_getb32 (buf);
1104 if (bfd_bread (buf, 2, abfd) != 2)
1106 entry->physical_size = bfd_getb16 (buf);
1108 if (entry->physical_size & 0x8000)
1110 if (bfd_bread (buf, 4, abfd) != 4)
1112 entry->physical_size &= 0x7fff;
1113 entry->logical_size = bfd_getb32 (buf);
1114 entry->offset = offset + 10;
1118 if (bfd_bread (buf, 2, abfd) != 2)
1120 entry->physical_size &= 0x7fff;
1121 entry->logical_size = bfd_getb16 (buf);
1122 entry->offset = offset + 8;
1129 bfd_sym_fetch_type_table_information (bfd *abfd,
1130 bfd_sym_type_information_table_entry *entry,
1131 unsigned long sym_index)
1133 bfd_sym_type_table_entry tindex;
1134 bfd_sym_data_struct *sdata = NULL;
1136 BFD_ASSERT (bfd_sym_valid (abfd));
1137 sdata = abfd->tdata.sym_data;
1139 if (sdata->header.dshb_tte.dti_object_count <= 99)
1141 if (sym_index < 100)
1144 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1146 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1152 const unsigned char *
1153 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1155 bfd_sym_data_struct *sdata = NULL;
1157 BFD_ASSERT (bfd_sym_valid (abfd));
1158 sdata = abfd->tdata.sym_data;
1161 return (const unsigned char *) "";
1164 if ((sym_index / sdata->header.dshb_page_size)
1165 > sdata->header.dshb_nte.dti_page_count)
1166 return (const unsigned char *) "\09[INVALID]";
1168 return (const unsigned char *) sdata->name_table + sym_index;
1171 const unsigned char *
1172 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1174 bfd_sym_modules_table_entry entry;
1176 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1177 return (const unsigned char *) "\09[INVALID]";
1179 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1183 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1187 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1188 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1189 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1190 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1191 default: return "[UNKNOWN]";
1196 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1200 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1201 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1202 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1203 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1204 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1205 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1206 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1207 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1208 default: return "[UNKNOWN]";
1213 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1217 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1218 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1219 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1220 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1221 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1222 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1223 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1224 default: return "[UNKNOWN]";
1229 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1233 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1234 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1241 bfd_sym_print_file_reference (bfd *abfd,
1243 bfd_sym_file_reference *entry)
1245 bfd_sym_file_references_table_entry frtentry;
1248 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1249 entry->fref_frte_index);
1250 fprintf (f, "FILE ");
1252 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1253 fprintf (f, "[INVALID]");
1255 fprintf (f, "\"%.*s\"",
1256 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1257 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1259 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1263 bfd_sym_print_resources_table_entry (bfd *abfd,
1265 bfd_sym_resources_table_entry *entry)
1267 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1268 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1269 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1270 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1271 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1275 bfd_sym_print_modules_table_entry (bfd *abfd,
1277 bfd_sym_modules_table_entry *entry)
1279 fprintf (f, "\"%.*s\" (NTE %lu)",
1280 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1281 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1282 entry->mte_nte_index);
1286 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1287 fprintf (f, " range %lu -- %lu",
1288 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1292 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1293 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1295 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1296 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1300 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1301 entry->mte_cmte_index, entry->mte_cvte_index,
1302 entry->mte_clte_index, entry->mte_ctte_index,
1303 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1305 if (entry->mte_parent != 0)
1306 fprintf (f, ", parent %lu", entry->mte_parent);
1308 fprintf (f, ", no parent");
1310 if (entry->mte_cmte_index != 0)
1311 fprintf (f, ", child %lu", entry->mte_cmte_index);
1313 fprintf (f, ", no child");
1317 bfd_sym_print_file_references_table_entry (bfd *abfd,
1319 bfd_sym_file_references_table_entry *entry)
1321 switch (entry->generic.type)
1323 case BFD_SYM_FILE_NAME_INDEX:
1324 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1325 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1326 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1327 entry->filename.nte_index);
1329 fprintf (f, "[UNIMPLEMENTED]");
1330 /* printModDate (entry->filename.mod_date); */
1331 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1334 case BFD_SYM_END_OF_LIST:
1339 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1340 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1341 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1342 entry->entry.mte_index,
1343 entry->entry.file_offset);
1349 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1351 bfd_sym_contained_modules_table_entry *entry)
1353 switch (entry->generic.type)
1355 case BFD_SYM_END_OF_LIST:
1360 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1361 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1362 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1363 entry->entry.mte_index,
1364 entry->entry.nte_index);
1370 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1372 bfd_sym_contained_variables_table_entry *entry)
1374 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1380 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1382 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1383 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1387 fprintf (f, "\"%.*s\" (NTE %lu)",
1388 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1389 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1390 entry->entry.nte_index);
1392 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1393 fprintf (f, ", offset %lu", entry->entry.file_delta);
1394 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1396 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1397 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1398 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1399 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1400 entry->entry.address.scstruct.sca_offset);
1401 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1405 fprintf (f, ", la [");
1406 for (i = 0; i < entry->entry.la_size; i++)
1407 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1410 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1411 fprintf (f, ", bigla %lu, biglakind %u",
1412 entry->entry.address.biglastruct.big_la,
1413 entry->entry.address.biglastruct.big_la_kind);
1416 fprintf (f, ", la [INVALID]");
1420 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1422 bfd_sym_contained_statements_table_entry *entry)
1424 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1430 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1432 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1433 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1437 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1438 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1439 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1440 entry->entry.mte_index,
1441 entry->entry.mte_offset,
1442 entry->entry.file_delta);
1446 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1448 bfd_sym_contained_labels_table_entry *entry)
1450 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1456 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1458 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1459 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1463 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1464 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1465 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1466 entry->entry.mte_index,
1467 entry->entry.mte_offset,
1468 entry->entry.file_delta,
1469 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1473 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1475 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1477 fprintf (f, "[UNIMPLEMENTED]");
1481 bfd_sym_type_operator_name (unsigned char num)
1485 case 1: return "TTE";
1486 case 2: return "PointerTo";
1487 case 3: return "ScalarOf";
1488 case 4: return "ConstantOf";
1489 case 5: return "EnumerationOf";
1490 case 6: return "VectorOf";
1491 case 7: return "RecordOf";
1492 case 8: return "UnionOf";
1493 case 9: return "SubRangeOf";
1494 case 10: return "SetOf";
1495 case 11: return "NamedTypeOf";
1496 case 12: return "ProcOf";
1497 case 13: return "ValueOf";
1498 case 14: return "ArrayOf";
1499 default: return "[UNKNOWN OPERATOR]";
1504 bfd_sym_type_basic_name (unsigned char num)
1508 case 0: return "void";
1509 case 1: return "pascal string";
1510 case 2: return "unsigned long";
1511 case 3: return "signed long";
1512 case 4: return "extended (10 bytes)";
1513 case 5: return "pascal boolean (1 byte)";
1514 case 6: return "unsigned byte";
1515 case 7: return "signed byte";
1516 case 8: return "character (1 byte)";
1517 case 9: return "wide character (2 bytes)";
1518 case 10: return "unsigned short";
1519 case 11: return "signed short";
1520 case 12: return "singled";
1521 case 13: return "double";
1522 case 14: return "extended (12 bytes)";
1523 case 15: return "computational (8 bytes)";
1524 case 16: return "c string";
1525 case 17: return "as-is string";
1526 default: return "[UNKNOWN BASIC TYPE]";
1531 bfd_sym_fetch_long (unsigned char *buf,
1533 unsigned long offset,
1534 unsigned long *offsetptr,
1545 else if (! (buf[offset] & 0x80))
1547 *value = buf[offset];
1551 else if (buf[offset] == 0xc0)
1553 if ((offset + 5) > len)
1561 *value = bfd_getb32 (buf + offset + 1);
1566 else if ((buf[offset] & 0xc0) == 0xc0)
1568 *value = -(buf[offset] & 0x3f);
1572 else if ((buf[offset] & 0xc0) == 0x80)
1574 if ((offset + 2) > len)
1582 *value = bfd_getb16 (buf + offset) & 0x3fff;
1590 if (offsetptr != NULL)
1591 *offsetptr = offset;
1597 bfd_sym_print_type_information (bfd *abfd,
1601 unsigned long offset,
1602 unsigned long *offsetptr)
1608 fprintf (f, "[NULL]");
1610 if (offsetptr != NULL)
1611 *offsetptr = offset;
1618 if (! (type & 0x80))
1620 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1622 if (offsetptr != NULL)
1623 *offsetptr = offset;
1628 fprintf (f, "[packed ");
1632 switch (type & 0x3f)
1637 bfd_sym_type_information_table_entry tinfo;
1639 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1641 fprintf (f, "[INVALID]");
1644 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1645 fprintf (f, "[INVALID]");
1647 fprintf (f, "\"%.*s\"",
1648 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1649 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1651 fprintf (f, " (TTE %lu)", (unsigned long) value);
1656 fprintf (f, "pointer (0x%x) to ", type);
1657 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1664 fprintf (f, "scalar (0x%x) of ", type);
1665 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1666 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1667 fprintf (f, " (%lu)", (unsigned long) value);
1673 long lower, upper, nelem;
1676 fprintf (f, "enumeration (0x%x) of ", type);
1677 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1678 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1679 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1680 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1681 fprintf (f, " from %lu to %lu with %lu elements: ",
1682 (unsigned long) lower, (unsigned long) upper,
1683 (unsigned long) nelem);
1685 for (i = 0; i < nelem; i++)
1688 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1694 fprintf (f, "vector (0x%x)", type);
1695 fprintf (f, "\n index ");
1696 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1697 fprintf (f, "\n target ");
1698 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1704 long nrec, eloff, i;
1706 if ((type & 0x3f) == 7)
1707 fprintf (f, "record (0x%x) of ", type);
1709 fprintf (f, "union (0x%x) of ", type);
1711 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1712 fprintf (f, "%lu elements: ", (unsigned long) nrec);
1714 for (i = 0; i < nrec; i++)
1716 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1718 fprintf (f, "offset %lu: ", (unsigned long) eloff);
1719 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1725 fprintf (f, "subrange (0x%x) of ", type);
1726 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1727 fprintf (f, " lower ");
1728 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1729 fprintf (f, " upper ");
1730 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1737 fprintf (f, "named type (0x%x) ", type);
1738 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1740 fprintf (f, "[INVALID]");
1742 fprintf (f, "\"%.*s\"",
1743 bfd_sym_symbol_name (abfd, value)[0],
1744 &bfd_sym_symbol_name (abfd, value)[1]);
1746 fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1747 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1752 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1756 if (type == (0x40 | 0x6))
1763 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1764 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1765 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1766 /* fprintf (f, "\n "); */
1767 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1768 for (i = 0; i < m; i++)
1770 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1773 fprintf (f, "%ld", l);
1776 else if (type & 0x40)
1778 /* Other packed type. */
1781 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1782 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1783 /* fprintf (f, "\n "); */
1784 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1789 if (offsetptr != NULL)
1790 *offsetptr = offset;
1794 bfd_sym_print_type_information_table_entry (bfd *abfd,
1796 bfd_sym_type_information_table_entry *entry)
1799 unsigned long offset;
1802 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1803 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1804 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1806 entry->physical_size, entry->offset, entry->logical_size);
1810 buf = malloc (entry->physical_size);
1813 fprintf (f, "[ERROR]\n");
1816 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1818 fprintf (f, "[ERROR]\n");
1822 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1824 fprintf (f, "[ERROR]\n");
1830 for (i = 0; i < entry->physical_size; i++)
1833 fprintf (f, "0x%02x", buf[i]);
1835 fprintf (f, " 0x%02x", buf[i]);
1841 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1843 if (offset != entry->physical_size)
1844 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1849 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1851 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1853 fprintf (f, "[UNIMPLEMENTED]");
1857 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1859 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1861 fprintf (f, "[UNIMPLEMENTED]");
1865 bfd_sym_display_name_table_entry (bfd *abfd,
1867 unsigned char *entry)
1869 unsigned long sym_index;
1870 unsigned long offset;
1871 bfd_sym_data_struct *sdata = NULL;
1873 BFD_ASSERT (bfd_sym_valid (abfd));
1874 sdata = abfd->tdata.sym_data;
1875 sym_index = (entry - sdata->name_table) / 2;
1877 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1879 unsigned short length = bfd_getb16 (entry + 2);
1880 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1881 offset = 2 + length + 1;
1885 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1886 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1888 if (sdata->version >= BFD_SYM_VERSION_3_4)
1889 offset = entry[0] + 2;
1891 offset = entry[0] + 1;
1894 return (entry + offset + (offset % 2));
1898 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1900 unsigned long name_table_len;
1901 unsigned char *name_table, *name_table_end, *cur;
1902 bfd_sym_data_struct *sdata = NULL;
1904 BFD_ASSERT (bfd_sym_valid (abfd));
1905 sdata = abfd->tdata.sym_data;
1907 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1908 name_table = sdata->name_table;
1909 name_table_end = name_table + name_table_len;
1911 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1916 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1917 if (cur >= name_table_end)
1923 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1926 bfd_sym_resources_table_entry entry;
1927 bfd_sym_data_struct *sdata = NULL;
1929 BFD_ASSERT (bfd_sym_valid (abfd));
1930 sdata = abfd->tdata.sym_data;
1932 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1933 sdata->header.dshb_rte.dti_object_count);
1935 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1937 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1938 fprintf (f, " [%8lu] [INVALID]\n", i);
1941 fprintf (f, " [%8lu] ", i);
1942 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1949 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1952 bfd_sym_modules_table_entry entry;
1953 bfd_sym_data_struct *sdata = NULL;
1955 BFD_ASSERT (bfd_sym_valid (abfd));
1956 sdata = abfd->tdata.sym_data;
1958 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1959 sdata->header.dshb_mte.dti_object_count);
1961 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1963 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1964 fprintf (f, " [%8lu] [INVALID]\n", i);
1967 fprintf (f, " [%8lu] ", i);
1968 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1975 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1978 bfd_sym_file_references_table_entry entry;
1979 bfd_sym_data_struct *sdata = NULL;
1981 BFD_ASSERT (bfd_sym_valid (abfd));
1982 sdata = abfd->tdata.sym_data;
1984 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1985 sdata->header.dshb_frte.dti_object_count);
1987 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1989 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1990 fprintf (f, " [%8lu] [INVALID]\n", i);
1993 fprintf (f, " [%8lu] ", i);
1994 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
2001 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
2004 bfd_sym_contained_modules_table_entry entry;
2005 bfd_sym_data_struct *sdata = NULL;
2007 BFD_ASSERT (bfd_sym_valid (abfd));
2008 sdata = abfd->tdata.sym_data;
2010 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2011 sdata->header.dshb_cmte.dti_object_count);
2013 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2015 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2016 fprintf (f, " [%8lu] [INVALID]\n", i);
2019 fprintf (f, " [%8lu] ", i);
2020 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2027 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2030 bfd_sym_contained_variables_table_entry entry;
2031 bfd_sym_data_struct *sdata = NULL;
2033 BFD_ASSERT (bfd_sym_valid (abfd));
2034 sdata = abfd->tdata.sym_data;
2036 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2037 sdata->header.dshb_cvte.dti_object_count);
2039 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2041 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2042 fprintf (f, " [%8lu] [INVALID]\n", i);
2045 fprintf (f, " [%8lu] ", i);
2046 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2055 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2058 bfd_sym_contained_statements_table_entry entry;
2059 bfd_sym_data_struct *sdata = NULL;
2061 BFD_ASSERT (bfd_sym_valid (abfd));
2062 sdata = abfd->tdata.sym_data;
2064 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2065 sdata->header.dshb_csnte.dti_object_count);
2067 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2069 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2070 fprintf (f, " [%8lu] [INVALID]\n", i);
2073 fprintf (f, " [%8lu] ", i);
2074 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2081 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2084 bfd_sym_contained_labels_table_entry entry;
2085 bfd_sym_data_struct *sdata = NULL;
2087 BFD_ASSERT (bfd_sym_valid (abfd));
2088 sdata = abfd->tdata.sym_data;
2090 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2091 sdata->header.dshb_clte.dti_object_count);
2093 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2095 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2096 fprintf (f, " [%8lu] [INVALID]\n", i);
2099 fprintf (f, " [%8lu] ", i);
2100 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2107 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2110 bfd_sym_contained_types_table_entry entry;
2111 bfd_sym_data_struct *sdata = NULL;
2113 BFD_ASSERT (bfd_sym_valid (abfd));
2114 sdata = abfd->tdata.sym_data;
2116 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2117 sdata->header.dshb_ctte.dti_object_count);
2119 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2121 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2122 fprintf (f, " [%8lu] [INVALID]\n", i);
2125 fprintf (f, " [%8lu] ", i);
2126 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2133 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2136 bfd_sym_file_references_index_table_entry entry;
2137 bfd_sym_data_struct *sdata = NULL;
2139 BFD_ASSERT (bfd_sym_valid (abfd));
2140 sdata = abfd->tdata.sym_data;
2142 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2143 sdata->header.dshb_fite.dti_object_count);
2145 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2147 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2148 fprintf (f, " [%8lu] [INVALID]\n", i);
2151 fprintf (f, " [%8lu] ", i);
2152 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2159 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2162 bfd_sym_constant_pool_entry entry;
2163 bfd_sym_data_struct *sdata = NULL;
2165 BFD_ASSERT (bfd_sym_valid (abfd));
2166 sdata = abfd->tdata.sym_data;
2168 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2169 sdata->header.dshb_const.dti_object_count);
2171 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2173 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2174 fprintf (f, " [%8lu] [INVALID]\n", i);
2177 fprintf (f, " [%8lu] ", i);
2178 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2185 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2188 bfd_sym_type_table_entry sym_index;
2189 bfd_sym_type_information_table_entry entry;
2190 bfd_sym_data_struct *sdata = NULL;
2192 BFD_ASSERT (bfd_sym_valid (abfd));
2193 sdata = abfd->tdata.sym_data;
2195 if (sdata->header.dshb_tte.dti_object_count > 99)
2196 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2197 sdata->header.dshb_tte.dti_object_count - 99);
2200 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2204 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2206 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2207 fprintf (f, " [%8lu] [INVALID]\n", i);
2210 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2212 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2213 fprintf (f, "[INVALID]");
2215 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2223 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2226 const char *name = "symbols";
2228 mdata->name_table = 0;
2230 mdata->version = version;
2232 bfd_seek (abfd, 0, SEEK_SET);
2233 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2236 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2237 if (mdata->name_table == NULL)
2240 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2247 bfdsec->filepos = 0;
2248 bfdsec->alignment_power = 0;
2250 abfd->tdata.sym_data = mdata;
2256 bfd_sym_object_p (bfd *abfd)
2258 bfd_sym_version version = -1;
2259 bfd_sym_data_struct *mdata;
2261 bfd_seek (abfd, 0, SEEK_SET);
2262 if (bfd_sym_read_version (abfd, &version) != 0)
2265 mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
2269 if (bfd_sym_scan (abfd, version, mdata) != 0)
2275 bfd_set_error (bfd_error_wrong_format);
2281 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2284 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2286 bfd_symbol_info (symbol, ret);
2290 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2296 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2302 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2303 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2308 const bfd_target sym_vec =
2311 bfd_target_sym_flavour, /* Flavour. */
2312 BFD_ENDIAN_BIG, /* Byteorder. */
2313 BFD_ENDIAN_BIG, /* Header byteorder. */
2314 (HAS_RELOC | EXEC_P | /* Object flags. */
2315 HAS_LINENO | HAS_DEBUG |
2316 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2317 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2318 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2319 0, /* Symbol_leading_char. */
2320 ' ', /* AR_pad_char. */
2321 16, /* AR_max_namelen. */
2322 0, /* match priority. */
2323 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2324 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2325 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2326 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2327 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2328 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2329 { /* bfd_check_format. */
2331 bfd_sym_object_p, /* bfd_check_format. */
2335 { /* bfd_set_format. */
2336 _bfd_bool_bfd_false_error,
2338 _bfd_bool_bfd_false_error,
2339 _bfd_bool_bfd_false_error,
2341 { /* bfd_write_contents. */
2342 _bfd_bool_bfd_false_error,
2344 _bfd_bool_bfd_false_error,
2345 _bfd_bool_bfd_false_error,
2348 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2349 BFD_JUMP_TABLE_COPY (_bfd_generic),
2350 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2351 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2352 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2353 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2354 BFD_JUMP_TABLE_WRITE (bfd_sym),
2355 BFD_JUMP_TABLE_LINK (bfd_sym),
2356 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),