Automatic date update in version.in
[binutils-gdb.git] / bfd / xsym.c
blobfe14acc121fbff91340db3f22550ef999449c1bc
1 /* xSYM symbol-file support for BFD.
2 Copyright (C) 1999-2024 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. */
23 #include "sysdep.h"
24 #include "xsym.h"
25 #include "bfd.h"
26 #include "libbfd.h"
28 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
29 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
30 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
31 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
32 #define bfd_sym_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false
33 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
34 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
35 #define bfd_sym_find_nearest_line_with_alt _bfd_nosymbols_find_nearest_line_with_alt
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_group_name bfd_generic_group_name
52 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
53 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked
54 #define bfd_sym_bfd_define_common_symbol bfd_generic_define_common_symbol
55 #define bfd_sym_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
56 #define bfd_sym_bfd_define_start_stop bfd_generic_define_start_stop
57 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
58 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
59 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
60 #define bfd_sym_bfd_copy_link_hash_symbol_type \
61 _bfd_generic_copy_link_hash_symbol_type
62 #define bfd_sym_bfd_final_link _bfd_generic_final_link
63 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
64 #define bfd_sym_bfd_link_check_relocs _bfd_generic_link_check_relocs
66 extern const bfd_target sym_vec;
68 static int
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;
73 unsigned char clen;
74 int ret;
76 clen = (a[0] > b[0]) ? b[0] : a[0];
77 ret = memcmp (a + 1, b + 1, clen);
78 if (ret != 0)
79 return ret;
81 if (a[0] == b[0])
82 return 0;
83 else if (a[0] < b[0])
84 return -1;
85 else
86 return 1;
89 static unsigned long
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;
102 bool
103 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
105 return 1;
108 void
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)
114 return;
117 bool
118 bfd_sym_valid (bfd *abfd)
120 if (abfd == NULL || abfd->xvec == NULL)
121 return 0;
123 return abfd->xvec == &sym_vec;
126 unsigned char *
127 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 if (bfd_seek (abfd, table_offset, SEEK_SET) != 0)
133 return NULL;
134 return _bfd_alloc_and_read (abfd, table_size, table_size);
137 void
138 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
139 size_t len,
140 bfd_sym_file_reference *entry)
142 BFD_ASSERT (len == 6);
144 entry->fref_frte_index = bfd_getb16 (buf);
145 entry->fref_offset = bfd_getb32 (buf + 2);
148 void
149 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
150 size_t len,
151 bfd_sym_table_info *table)
153 BFD_ASSERT (len == 8);
155 table->dti_first_page = bfd_getb16 (buf);
156 table->dti_page_count = bfd_getb16 (buf + 2);
157 table->dti_object_count = bfd_getb32 (buf + 4);
160 void
161 bfd_sym_parse_header_v32 (unsigned char *buf,
162 size_t len,
163 bfd_sym_header_block *header)
165 BFD_ASSERT (len == 154);
167 memcpy (header->dshb_id, buf, 32);
168 header->dshb_page_size = bfd_getb16 (buf + 32);
169 header->dshb_hash_page = bfd_getb16 (buf + 34);
170 header->dshb_root_mte = bfd_getb16 (buf + 36);
171 header->dshb_mod_date = bfd_getb32 (buf + 38);
173 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
174 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
175 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
176 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
177 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
178 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
179 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
180 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
181 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
182 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
183 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
184 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
185 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
187 memcpy (&header->dshb_file_creator, buf + 146, 4);
188 memcpy (&header->dshb_file_type, buf + 150, 4);
192 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
194 unsigned char buf[154];
195 long ret;
197 ret = bfd_read (buf, 154, abfd);
198 if (ret != 154)
199 return -1;
201 bfd_sym_parse_header_v32 (buf, 154, header);
203 return 0;
207 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
208 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
210 abort ();
214 bfd_sym_read_header (bfd *abfd,
215 bfd_sym_header_block *header,
216 bfd_sym_version version)
218 switch (version)
220 case BFD_SYM_VERSION_3_5:
221 case BFD_SYM_VERSION_3_4:
222 return bfd_sym_read_header_v34 (abfd, header);
223 case BFD_SYM_VERSION_3_3:
224 case BFD_SYM_VERSION_3_2:
225 return bfd_sym_read_header_v32 (abfd, header);
226 case BFD_SYM_VERSION_3_1:
227 default:
228 return 0;
233 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
235 char version_string[32];
236 long ret;
238 ret = bfd_read (version_string, sizeof (version_string), abfd);
239 if (ret != sizeof (version_string))
240 return -1;
242 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
243 *version = BFD_SYM_VERSION_3_1;
244 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
245 *version = BFD_SYM_VERSION_3_2;
246 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
247 *version = BFD_SYM_VERSION_3_3;
248 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
249 *version = BFD_SYM_VERSION_3_4;
250 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
251 *version = BFD_SYM_VERSION_3_5;
252 else
253 return -1;
255 return 0;
258 void
259 bfd_sym_display_table_summary (FILE *f,
260 bfd_sym_table_info *dti,
261 const char *name)
263 fprintf (f, "%-6s %13ld %13ld %13ld\n",
264 name,
265 dti->dti_first_page,
266 dti->dti_page_count,
267 dti->dti_object_count);
270 void
271 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
273 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
274 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
275 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
276 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
277 fprintf (f, " Modification Date: ");
278 fprintf (f, "[unimplemented]");
279 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
281 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
282 dshb->dshb_file_creator, dshb->dshb_file_type);
284 fprintf (f, "Table Name First Page Page Count Object Count\n");
285 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
287 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
288 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
289 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
290 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
291 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
292 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
293 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
294 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
295 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
296 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
297 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
298 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
299 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
301 fprintf (f, "\n");
304 void
305 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
306 size_t len,
307 bfd_sym_resources_table_entry *entry)
309 BFD_ASSERT (len == 18);
311 memcpy (&entry->rte_res_type, buf, 4);
312 entry->rte_res_number = bfd_getb16 (buf + 4);
313 entry->rte_nte_index = bfd_getb32 (buf + 6);
314 entry->rte_mte_first = bfd_getb16 (buf + 10);
315 entry->rte_mte_last = bfd_getb16 (buf + 12);
316 entry->rte_res_size = bfd_getb32 (buf + 14);
319 void
320 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
321 size_t len,
322 bfd_sym_modules_table_entry *entry)
324 BFD_ASSERT (len == 46);
326 entry->mte_rte_index = bfd_getb16 (buf);
327 entry->mte_res_offset = bfd_getb32 (buf + 2);
328 entry->mte_size = bfd_getb32 (buf + 6);
329 entry->mte_kind = buf[10];
330 entry->mte_scope = buf[11];
331 entry->mte_parent = bfd_getb16 (buf + 12);
332 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
333 entry->mte_imp_end = bfd_getb32 (buf + 20);
334 entry->mte_nte_index = bfd_getb32 (buf + 24);
335 entry->mte_cmte_index = bfd_getb16 (buf + 28);
336 entry->mte_cvte_index = bfd_getb32 (buf + 30);
337 entry->mte_clte_index = bfd_getb16 (buf + 34);
338 entry->mte_ctte_index = bfd_getb16 (buf + 36);
339 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
340 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
343 void
344 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
345 size_t len,
346 bfd_sym_file_references_table_entry *entry)
348 unsigned int type;
350 BFD_ASSERT (len == 10);
352 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
353 type = bfd_getb16 (buf);
355 switch (type)
357 case BFD_SYM_END_OF_LIST_3_2:
358 entry->generic.type = BFD_SYM_END_OF_LIST;
359 break;
361 case BFD_SYM_FILE_NAME_INDEX_3_2:
362 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
363 entry->filename.nte_index = bfd_getb32 (buf + 2);
364 entry->filename.mod_date = bfd_getb32 (buf + 6);
365 break;
367 default:
368 entry->entry.mte_index = type;
369 entry->entry.file_offset = bfd_getb32 (buf + 2);
373 void
374 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
375 size_t len,
376 bfd_sym_contained_modules_table_entry *entry)
378 unsigned int type;
380 BFD_ASSERT (len == 6);
382 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
383 type = bfd_getb16 (buf);
385 switch (type)
387 case BFD_SYM_END_OF_LIST_3_2:
388 entry->generic.type = BFD_SYM_END_OF_LIST;
389 break;
391 default:
392 entry->entry.mte_index = type;
393 entry->entry.nte_index = bfd_getb32 (buf + 2);
394 break;
398 void
399 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
400 size_t len,
401 bfd_sym_contained_variables_table_entry *entry)
403 unsigned int type;
405 BFD_ASSERT (len == 26);
407 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
408 type = bfd_getb16 (buf);
410 switch (type)
412 case BFD_SYM_END_OF_LIST_3_2:
413 entry->generic.type = BFD_SYM_END_OF_LIST;
414 break;
416 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
417 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
418 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
419 break;
421 default:
422 entry->entry.tte_index = type;
423 entry->entry.nte_index = bfd_getb32 (buf + 2);
424 entry->entry.file_delta = bfd_getb16 (buf + 6);
425 entry->entry.scope = buf[8];
426 entry->entry.la_size = buf[9];
428 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
430 entry->entry.address.scstruct.sca_kind = buf[10];
431 entry->entry.address.scstruct.sca_class = buf[11];
432 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
434 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
436 #if BFD_SYM_CVTE_SCA > 0
437 memcpy (&entry->entry.address.lastruct.la, buf + 10,
438 BFD_SYM_CVTE_SCA);
439 #endif
440 entry->entry.address.lastruct.la_kind = buf[23];
442 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
444 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
445 entry->entry.address.biglastruct.big_la_kind = buf[12];
450 void
451 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
452 size_t len,
453 bfd_sym_contained_statements_table_entry *entry)
455 unsigned int type;
457 BFD_ASSERT (len == 8);
459 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
460 type = bfd_getb16 (buf);
462 switch (type)
464 case BFD_SYM_END_OF_LIST_3_2:
465 entry->generic.type = BFD_SYM_END_OF_LIST;
466 break;
468 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
469 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
470 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
471 break;
473 default:
474 entry->entry.mte_index = type;
475 entry->entry.mte_offset = bfd_getb16 (buf + 2);
476 entry->entry.file_delta = bfd_getb32 (buf + 4);
477 break;
481 void
482 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
483 size_t len,
484 bfd_sym_contained_labels_table_entry *entry)
486 unsigned int type;
488 BFD_ASSERT (len == 12);
490 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
491 type = bfd_getb16 (buf);
493 switch (type)
495 case BFD_SYM_END_OF_LIST_3_2:
496 entry->generic.type = BFD_SYM_END_OF_LIST;
497 break;
499 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
500 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
501 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
502 break;
504 default:
505 entry->entry.mte_index = type;
506 entry->entry.mte_offset = bfd_getb16 (buf + 2);
507 entry->entry.nte_index = bfd_getb32 (buf + 4);
508 entry->entry.file_delta = bfd_getb16 (buf + 8);
509 entry->entry.scope = bfd_getb16 (buf + 10);
510 break;
514 void
515 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
516 size_t len,
517 bfd_sym_type_table_entry *entry)
519 BFD_ASSERT (len == 4);
521 *entry = bfd_getb32 (buf);
525 bfd_sym_fetch_resources_table_entry (bfd *abfd,
526 bfd_sym_resources_table_entry *entry,
527 unsigned long sym_index)
529 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
530 unsigned long offset;
531 unsigned long entry_size;
532 unsigned char buf[18];
533 bfd_sym_data_struct *sdata = NULL;
535 parser = NULL;
536 BFD_ASSERT (bfd_sym_valid (abfd));
537 sdata = abfd->tdata.sym_data;
539 if (sym_index == 0)
540 return -1;
542 switch (sdata->version)
544 case BFD_SYM_VERSION_3_5:
545 case BFD_SYM_VERSION_3_4:
546 return -1;
548 case BFD_SYM_VERSION_3_3:
549 case BFD_SYM_VERSION_3_2:
550 entry_size = 18;
551 parser = bfd_sym_parse_resources_table_entry_v32;
552 break;
554 case BFD_SYM_VERSION_3_1:
555 default:
556 return -1;
558 if (parser == NULL)
559 return -1;
561 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
562 sdata->header.dshb_page_size,
563 entry_size, sym_index);
565 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
566 return -1;
567 if (bfd_read (buf, entry_size, abfd) != entry_size)
568 return -1;
570 (*parser) (buf, entry_size, entry);
572 return 0;
576 bfd_sym_fetch_modules_table_entry (bfd *abfd,
577 bfd_sym_modules_table_entry *entry,
578 unsigned long sym_index)
580 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
581 unsigned long offset;
582 unsigned long entry_size;
583 unsigned char buf[46];
584 bfd_sym_data_struct *sdata = NULL;
586 parser = NULL;
587 BFD_ASSERT (bfd_sym_valid (abfd));
588 sdata = abfd->tdata.sym_data;
590 if (sym_index == 0)
591 return -1;
593 switch (sdata->version)
595 case BFD_SYM_VERSION_3_5:
596 case BFD_SYM_VERSION_3_4:
597 return -1;
599 case BFD_SYM_VERSION_3_3:
600 entry_size = 46;
601 parser = bfd_sym_parse_modules_table_entry_v33;
602 break;
604 case BFD_SYM_VERSION_3_2:
605 case BFD_SYM_VERSION_3_1:
606 default:
607 return -1;
609 if (parser == NULL)
610 return -1;
612 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
613 sdata->header.dshb_page_size,
614 entry_size, sym_index);
616 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
617 return -1;
618 if (bfd_read (buf, entry_size, abfd) != entry_size)
619 return -1;
621 (*parser) (buf, entry_size, entry);
623 return 0;
627 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
628 bfd_sym_file_references_table_entry *entry,
629 unsigned long sym_index)
631 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
632 unsigned long offset;
633 unsigned long entry_size = 0;
634 unsigned char buf[8];
635 bfd_sym_data_struct *sdata = NULL;
637 parser = NULL;
638 BFD_ASSERT (bfd_sym_valid (abfd));
639 sdata = abfd->tdata.sym_data;
641 if (sym_index == 0)
642 return -1;
644 switch (sdata->version)
646 case BFD_SYM_VERSION_3_3:
647 case BFD_SYM_VERSION_3_2:
648 entry_size = 10;
649 parser = bfd_sym_parse_file_references_table_entry_v32;
650 break;
652 case BFD_SYM_VERSION_3_5:
653 case BFD_SYM_VERSION_3_4:
654 case BFD_SYM_VERSION_3_1:
655 default:
656 break;
659 if (parser == NULL)
660 return -1;
662 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
663 sdata->header.dshb_page_size,
664 entry_size, sym_index);
666 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
667 return -1;
668 if (bfd_read (buf, entry_size, abfd) != entry_size)
669 return -1;
671 (*parser) (buf, entry_size, entry);
673 return 0;
677 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
678 bfd_sym_contained_modules_table_entry *entry,
679 unsigned long sym_index)
681 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
682 unsigned long offset;
683 unsigned long entry_size = 0;
684 unsigned char buf[6];
685 bfd_sym_data_struct *sdata = NULL;
687 parser = NULL;
688 BFD_ASSERT (bfd_sym_valid (abfd));
689 sdata = abfd->tdata.sym_data;
691 if (sym_index == 0)
692 return -1;
694 switch (sdata->version)
696 case BFD_SYM_VERSION_3_3:
697 case BFD_SYM_VERSION_3_2:
698 entry_size = 6;
699 parser = bfd_sym_parse_contained_modules_table_entry_v32;
700 break;
702 case BFD_SYM_VERSION_3_5:
703 case BFD_SYM_VERSION_3_4:
704 case BFD_SYM_VERSION_3_1:
705 default:
706 break;
709 if (parser == NULL)
710 return -1;
712 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
713 sdata->header.dshb_page_size,
714 entry_size, sym_index);
716 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
717 return -1;
718 if (bfd_read (buf, entry_size, abfd) != entry_size)
719 return -1;
721 (*parser) (buf, entry_size, entry);
723 return 0;
727 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
728 bfd_sym_contained_variables_table_entry *entry,
729 unsigned long sym_index)
731 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
732 unsigned long offset;
733 unsigned long entry_size = 0;
734 unsigned char buf[26];
735 bfd_sym_data_struct *sdata = NULL;
737 parser = NULL;
738 BFD_ASSERT (bfd_sym_valid (abfd));
739 sdata = abfd->tdata.sym_data;
741 if (sym_index == 0)
742 return -1;
744 switch (sdata->version)
746 case BFD_SYM_VERSION_3_3:
747 case BFD_SYM_VERSION_3_2:
748 entry_size = 26;
749 parser = bfd_sym_parse_contained_variables_table_entry_v32;
750 break;
752 case BFD_SYM_VERSION_3_5:
753 case BFD_SYM_VERSION_3_4:
754 case BFD_SYM_VERSION_3_1:
755 default:
756 break;
759 if (parser == NULL)
760 return -1;
762 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
763 sdata->header.dshb_page_size,
764 entry_size, sym_index);
766 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
767 return -1;
768 if (bfd_read (buf, entry_size, abfd) != entry_size)
769 return -1;
771 (*parser) (buf, entry_size, entry);
773 return 0;
777 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
778 bfd_sym_contained_statements_table_entry *entry,
779 unsigned long sym_index)
781 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
782 unsigned long offset;
783 unsigned long entry_size = 0;
784 unsigned char buf[8];
785 bfd_sym_data_struct *sdata = NULL;
787 parser = NULL;
788 BFD_ASSERT (bfd_sym_valid (abfd));
789 sdata = abfd->tdata.sym_data;
791 if (sym_index == 0)
792 return -1;
794 switch (sdata->version)
796 case BFD_SYM_VERSION_3_3:
797 case BFD_SYM_VERSION_3_2:
798 entry_size = 8;
799 parser = bfd_sym_parse_contained_statements_table_entry_v32;
800 break;
802 case BFD_SYM_VERSION_3_5:
803 case BFD_SYM_VERSION_3_4:
804 case BFD_SYM_VERSION_3_1:
805 default:
806 break;
809 if (parser == NULL)
810 return -1;
812 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
813 sdata->header.dshb_page_size,
814 entry_size, sym_index);
816 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
817 return -1;
818 if (bfd_read (buf, entry_size, abfd) != entry_size)
819 return -1;
821 (*parser) (buf, entry_size, entry);
823 return 0;
827 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
828 bfd_sym_contained_labels_table_entry *entry,
829 unsigned long sym_index)
831 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
832 unsigned long offset;
833 unsigned long entry_size = 0;
834 unsigned char buf[12];
835 bfd_sym_data_struct *sdata = NULL;
837 parser = NULL;
838 BFD_ASSERT (bfd_sym_valid (abfd));
839 sdata = abfd->tdata.sym_data;
841 if (sym_index == 0)
842 return -1;
844 switch (sdata->version)
846 case BFD_SYM_VERSION_3_3:
847 case BFD_SYM_VERSION_3_2:
848 entry_size = 12;
849 parser = bfd_sym_parse_contained_labels_table_entry_v32;
850 break;
852 case BFD_SYM_VERSION_3_5:
853 case BFD_SYM_VERSION_3_4:
854 case BFD_SYM_VERSION_3_1:
855 default:
856 break;
859 if (parser == NULL)
860 return -1;
862 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
863 sdata->header.dshb_page_size,
864 entry_size, sym_index);
866 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
867 return -1;
868 if (bfd_read (buf, entry_size, abfd) != entry_size)
869 return -1;
871 (*parser) (buf, entry_size, entry);
873 return 0;
877 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
878 bfd_sym_contained_types_table_entry *entry,
879 unsigned long sym_index)
881 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
882 unsigned long offset;
883 unsigned long entry_size = 0;
884 unsigned char buf[0];
885 bfd_sym_data_struct *sdata = NULL;
887 parser = NULL;
888 BFD_ASSERT (bfd_sym_valid (abfd));
889 sdata = abfd->tdata.sym_data;
891 if (sym_index == 0)
892 return -1;
894 switch (sdata->version)
896 case BFD_SYM_VERSION_3_3:
897 case BFD_SYM_VERSION_3_2:
898 entry_size = 0;
899 parser = NULL;
900 break;
902 case BFD_SYM_VERSION_3_5:
903 case BFD_SYM_VERSION_3_4:
904 case BFD_SYM_VERSION_3_1:
905 default:
906 break;
909 if (parser == NULL)
910 return -1;
912 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
913 sdata->header.dshb_page_size,
914 entry_size, sym_index);
916 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
917 return -1;
918 if (bfd_read (buf, entry_size, abfd) != entry_size)
919 return -1;
921 (*parser) (buf, entry_size, entry);
923 return 0;
927 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
928 bfd_sym_file_references_index_table_entry *entry,
929 unsigned long sym_index)
931 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
932 unsigned long offset;
933 unsigned long entry_size = 0;
934 unsigned char buf[0];
935 bfd_sym_data_struct *sdata = NULL;
937 parser = NULL;
938 BFD_ASSERT (bfd_sym_valid (abfd));
939 sdata = abfd->tdata.sym_data;
941 if (sym_index == 0)
942 return -1;
944 switch (sdata->version)
946 case BFD_SYM_VERSION_3_3:
947 case BFD_SYM_VERSION_3_2:
948 entry_size = 0;
949 parser = NULL;
950 break;
952 case BFD_SYM_VERSION_3_5:
953 case BFD_SYM_VERSION_3_4:
954 case BFD_SYM_VERSION_3_1:
955 default:
956 break;
959 if (parser == NULL)
960 return -1;
962 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
963 sdata->header.dshb_page_size,
964 entry_size, sym_index);
966 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
967 return -1;
968 if (bfd_read (buf, entry_size, abfd) != entry_size)
969 return -1;
971 (*parser) (buf, entry_size, entry);
973 return 0;
977 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
978 bfd_sym_constant_pool_entry *entry,
979 unsigned long sym_index)
981 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
982 unsigned long offset;
983 unsigned long entry_size = 0;
984 unsigned char buf[0];
985 bfd_sym_data_struct *sdata = NULL;
987 parser = NULL;
988 BFD_ASSERT (bfd_sym_valid (abfd));
989 sdata = abfd->tdata.sym_data;
991 if (sym_index == 0)
992 return -1;
994 switch (sdata->version)
996 case BFD_SYM_VERSION_3_3:
997 case BFD_SYM_VERSION_3_2:
998 entry_size = 0;
999 parser = NULL;
1000 break;
1002 case BFD_SYM_VERSION_3_5:
1003 case BFD_SYM_VERSION_3_4:
1004 case BFD_SYM_VERSION_3_1:
1005 default:
1006 break;
1009 if (parser == NULL)
1010 return -1;
1012 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1013 sdata->header.dshb_page_size,
1014 entry_size, sym_index);
1016 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1017 return -1;
1018 if (bfd_read (buf, entry_size, abfd) != entry_size)
1019 return -1;
1021 (*parser) (buf, entry_size, entry);
1023 return 0;
1027 bfd_sym_fetch_type_table_entry (bfd *abfd,
1028 bfd_sym_type_table_entry *entry,
1029 unsigned long sym_index)
1031 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1032 unsigned long offset;
1033 unsigned long entry_size = 0;
1034 unsigned char buf[4];
1035 bfd_sym_data_struct *sdata = NULL;
1037 parser = NULL;
1038 BFD_ASSERT (bfd_sym_valid (abfd));
1039 sdata = abfd->tdata.sym_data;
1041 switch (sdata->version)
1043 case BFD_SYM_VERSION_3_3:
1044 case BFD_SYM_VERSION_3_2:
1045 entry_size = 4;
1046 parser = bfd_sym_parse_type_table_entry_v32;
1047 break;
1049 case BFD_SYM_VERSION_3_5:
1050 case BFD_SYM_VERSION_3_4:
1051 case BFD_SYM_VERSION_3_1:
1052 default:
1053 break;
1056 if (parser == NULL)
1057 return -1;
1059 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1060 sdata->header.dshb_page_size,
1061 entry_size, sym_index);
1063 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1064 return -1;
1065 if (bfd_read (buf, entry_size, abfd) != entry_size)
1066 return -1;
1068 (*parser) (buf, entry_size, entry);
1070 return 0;
1074 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1075 bfd_sym_type_information_table_entry *entry,
1076 unsigned long offset)
1078 unsigned char buf[4];
1080 BFD_ASSERT (bfd_sym_valid (abfd));
1082 if (offset == 0)
1083 return -1;
1085 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1086 return -1;
1088 if (bfd_read (buf, 4, abfd) != 4)
1089 return -1;
1090 entry->nte_index = bfd_getb32 (buf);
1092 if (bfd_read (buf, 2, abfd) != 2)
1093 return -1;
1094 entry->physical_size = bfd_getb16 (buf);
1096 if (entry->physical_size & 0x8000)
1098 if (bfd_read (buf, 4, abfd) != 4)
1099 return -1;
1100 entry->physical_size &= 0x7fff;
1101 entry->logical_size = bfd_getb32 (buf);
1102 entry->offset = offset + 10;
1104 else
1106 if (bfd_read (buf, 2, abfd) != 2)
1107 return -1;
1108 entry->physical_size &= 0x7fff;
1109 entry->logical_size = bfd_getb16 (buf);
1110 entry->offset = offset + 8;
1113 return 0;
1117 bfd_sym_fetch_type_table_information (bfd *abfd,
1118 bfd_sym_type_information_table_entry *entry,
1119 unsigned long sym_index)
1121 bfd_sym_type_table_entry tindex;
1122 bfd_sym_data_struct *sdata = NULL;
1124 BFD_ASSERT (bfd_sym_valid (abfd));
1125 sdata = abfd->tdata.sym_data;
1127 if (sdata->header.dshb_tte.dti_object_count <= 99)
1128 return -1;
1129 if (sym_index < 100)
1130 return -1;
1132 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1133 return -1;
1134 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1135 return -1;
1137 return 0;
1140 const unsigned char *
1141 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1143 bfd_sym_data_struct *sdata = NULL;
1145 BFD_ASSERT (bfd_sym_valid (abfd));
1146 sdata = abfd->tdata.sym_data;
1148 if (sym_index == 0)
1149 return (const unsigned char *) "";
1151 sym_index *= 2;
1152 if ((sym_index / sdata->header.dshb_page_size)
1153 > sdata->header.dshb_nte.dti_page_count)
1154 return (const unsigned char *) "\09[INVALID]";
1156 return (const unsigned char *) sdata->name_table + sym_index;
1159 const unsigned char *
1160 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1162 bfd_sym_modules_table_entry entry;
1164 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1165 return (const unsigned char *) "\09[INVALID]";
1167 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1170 const char *
1171 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1173 switch (kind)
1175 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1176 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1177 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1178 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1179 default: return "[UNKNOWN]";
1183 const char *
1184 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1186 switch (kind)
1188 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1189 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1190 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1191 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1192 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1193 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1194 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1195 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1196 default: return "[UNKNOWN]";
1200 const char *
1201 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1203 switch (kind)
1205 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1206 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1207 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1208 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1209 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1210 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1211 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1212 default: return "[UNKNOWN]";
1216 const char *
1217 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1219 switch (scope)
1221 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1222 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1223 default:
1224 return "[UNKNOWN]";
1228 void
1229 bfd_sym_print_file_reference (bfd *abfd,
1230 FILE *f,
1231 bfd_sym_file_reference *entry)
1233 bfd_sym_file_references_table_entry frtentry;
1234 int ret;
1236 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1237 entry->fref_frte_index);
1238 fprintf (f, "FILE ");
1240 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1241 fprintf (f, "[INVALID]");
1242 else
1243 fprintf (f, "\"%.*s\"",
1244 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1245 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1247 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1250 void
1251 bfd_sym_print_resources_table_entry (bfd *abfd,
1252 FILE *f,
1253 bfd_sym_resources_table_entry *entry)
1255 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1256 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1257 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1258 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1259 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1262 void
1263 bfd_sym_print_modules_table_entry (bfd *abfd,
1264 FILE *f,
1265 bfd_sym_modules_table_entry *entry)
1267 fprintf (f, "\"%.*s\" (NTE %lu)",
1268 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1269 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1270 entry->mte_nte_index);
1272 fprintf (f, "\n ");
1274 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1275 fprintf (f, " range %lu -- %lu",
1276 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1278 fprintf (f, "\n ");
1280 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1281 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1283 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1284 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1286 fprintf (f, "\n ");
1288 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1289 entry->mte_cmte_index, entry->mte_cvte_index,
1290 entry->mte_clte_index, entry->mte_ctte_index,
1291 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1293 if (entry->mte_parent != 0)
1294 fprintf (f, ", parent %lu", entry->mte_parent);
1295 else
1296 fprintf (f, ", no parent");
1298 if (entry->mte_cmte_index != 0)
1299 fprintf (f, ", child %lu", entry->mte_cmte_index);
1300 else
1301 fprintf (f, ", no child");
1304 void
1305 bfd_sym_print_file_references_table_entry (bfd *abfd,
1306 FILE *f,
1307 bfd_sym_file_references_table_entry *entry)
1309 switch (entry->generic.type)
1311 case BFD_SYM_FILE_NAME_INDEX:
1312 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1313 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1314 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1315 entry->filename.nte_index);
1317 fprintf (f, "[UNIMPLEMENTED]");
1318 /* printModDate (entry->filename.mod_date); */
1319 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1320 break;
1322 case BFD_SYM_END_OF_LIST:
1323 fprintf (f, "END");
1324 break;
1326 default:
1327 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1328 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1329 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1330 entry->entry.mte_index,
1331 entry->entry.file_offset);
1332 break;
1336 void
1337 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1338 FILE *f,
1339 bfd_sym_contained_modules_table_entry *entry)
1341 switch (entry->generic.type)
1343 case BFD_SYM_END_OF_LIST:
1344 fprintf (f, "END");
1345 break;
1347 default:
1348 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1349 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1350 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1351 entry->entry.mte_index,
1352 entry->entry.nte_index);
1353 break;
1357 void
1358 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1359 FILE *f,
1360 bfd_sym_contained_variables_table_entry *entry)
1362 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1364 fprintf (f, "END");
1365 return;
1368 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1370 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1371 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1372 return;
1375 fprintf (f, "\"%.*s\" (NTE %lu)",
1376 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1377 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1378 entry->entry.nte_index);
1380 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1381 fprintf (f, ", offset %lu", entry->entry.file_delta);
1382 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1384 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1385 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1386 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1387 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1388 entry->entry.address.scstruct.sca_offset);
1389 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1391 unsigned long i;
1393 fprintf (f, ", la [");
1394 for (i = 0; i < entry->entry.la_size; i++)
1395 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1396 fprintf (f, "]");
1398 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1399 fprintf (f, ", bigla %lu, biglakind %u",
1400 entry->entry.address.biglastruct.big_la,
1401 entry->entry.address.biglastruct.big_la_kind);
1403 else
1404 fprintf (f, ", la [INVALID]");
1407 void
1408 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1409 FILE *f,
1410 bfd_sym_contained_statements_table_entry *entry)
1412 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1414 fprintf (f, "END");
1415 return;
1418 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1420 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1421 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1422 return;
1425 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1426 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1427 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1428 entry->entry.mte_index,
1429 entry->entry.mte_offset,
1430 entry->entry.file_delta);
1433 void
1434 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1435 FILE *f,
1436 bfd_sym_contained_labels_table_entry *entry)
1438 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1440 fprintf (f, "END");
1441 return;
1444 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1446 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1447 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1448 return;
1451 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1452 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1453 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1454 entry->entry.mte_index,
1455 entry->entry.mte_offset,
1456 entry->entry.file_delta,
1457 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1460 void
1461 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1462 FILE *f,
1463 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1465 fprintf (f, "[UNIMPLEMENTED]");
1468 const char *
1469 bfd_sym_type_operator_name (unsigned char num)
1471 switch (num)
1473 case 1: return "TTE";
1474 case 2: return "PointerTo";
1475 case 3: return "ScalarOf";
1476 case 4: return "ConstantOf";
1477 case 5: return "EnumerationOf";
1478 case 6: return "VectorOf";
1479 case 7: return "RecordOf";
1480 case 8: return "UnionOf";
1481 case 9: return "SubRangeOf";
1482 case 10: return "SetOf";
1483 case 11: return "NamedTypeOf";
1484 case 12: return "ProcOf";
1485 case 13: return "ValueOf";
1486 case 14: return "ArrayOf";
1487 default: return "[UNKNOWN OPERATOR]";
1491 const char *
1492 bfd_sym_type_basic_name (unsigned char num)
1494 switch (num)
1496 case 0: return "void";
1497 case 1: return "pascal string";
1498 case 2: return "unsigned long";
1499 case 3: return "signed long";
1500 case 4: return "extended (10 bytes)";
1501 case 5: return "pascal boolean (1 byte)";
1502 case 6: return "unsigned byte";
1503 case 7: return "signed byte";
1504 case 8: return "character (1 byte)";
1505 case 9: return "wide character (2 bytes)";
1506 case 10: return "unsigned short";
1507 case 11: return "signed short";
1508 case 12: return "singled";
1509 case 13: return "double";
1510 case 14: return "extended (12 bytes)";
1511 case 15: return "computational (8 bytes)";
1512 case 16: return "c string";
1513 case 17: return "as-is string";
1514 default: return "[UNKNOWN BASIC TYPE]";
1519 bfd_sym_fetch_long (unsigned char *buf,
1520 unsigned long len,
1521 unsigned long offset,
1522 unsigned long *offsetptr,
1523 long *value)
1525 int ret;
1527 if (offset >= len)
1529 *value = 0;
1530 offset += 0;
1531 ret = -1;
1533 else if (! (buf[offset] & 0x80))
1535 *value = buf[offset];
1536 offset += 1;
1537 ret = 0;
1539 else if (buf[offset] == 0xc0)
1541 if ((offset + 5) > len)
1543 *value = 0;
1544 offset = len;
1545 ret = -1;
1547 else
1549 *value = bfd_getb32 (buf + offset + 1);
1550 offset += 5;
1551 ret = 0;
1554 else if ((buf[offset] & 0xc0) == 0xc0)
1556 *value = -(buf[offset] & 0x3f);
1557 offset += 1;
1558 ret = 0;
1560 else if ((buf[offset] & 0xc0) == 0x80)
1562 if ((offset + 2) > len)
1564 *value = 0;
1565 offset = len;
1566 ret = -1;
1568 else
1570 *value = bfd_getb16 (buf + offset) & 0x3fff;
1571 offset += 2;
1572 ret = 0;
1575 else
1576 abort ();
1578 if (offsetptr != NULL)
1579 *offsetptr = offset;
1581 return ret;
1584 void
1585 bfd_sym_print_type_information (bfd *abfd,
1586 FILE *f,
1587 unsigned char *buf,
1588 unsigned long len,
1589 unsigned long offset,
1590 unsigned long *offsetptr)
1592 unsigned int type;
1594 if (offset >= len)
1596 fprintf (f, "[NULL]");
1598 if (offsetptr != NULL)
1599 *offsetptr = offset;
1600 return;
1603 type = buf[offset];
1604 offset++;
1606 if (! (type & 0x80))
1608 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1610 if (offsetptr != NULL)
1611 *offsetptr = offset;
1612 return;
1615 if (type & 0x40)
1616 fprintf (f, "[packed ");
1617 else
1618 fprintf (f, "[");
1620 switch (type & 0x3f)
1622 case 1:
1624 long value;
1625 bfd_sym_type_information_table_entry tinfo;
1627 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1628 if (value <= 0)
1629 fprintf (f, "[INVALID]");
1630 else
1632 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1633 fprintf (f, "[INVALID]");
1634 else
1635 fprintf (f, "\"%.*s\"",
1636 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1637 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1639 fprintf (f, " (TTE %lu)", (unsigned long) value);
1640 break;
1643 case 2:
1644 fprintf (f, "pointer (0x%x) to ", type);
1645 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1646 break;
1648 case 3:
1650 long value;
1652 fprintf (f, "scalar (0x%x) of ", type);
1653 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1654 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1655 fprintf (f, " (%lu)", (unsigned long) value);
1656 break;
1659 case 5:
1661 long lower, upper, nelem;
1662 int i;
1664 fprintf (f, "enumeration (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, &lower);
1667 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1668 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1669 fprintf (f, " from %lu to %lu with %lu elements: ",
1670 (unsigned long) lower, (unsigned long) upper,
1671 (unsigned long) nelem);
1673 for (i = 0; i < nelem; i++)
1675 fprintf (f, "\n ");
1676 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1678 break;
1681 case 6:
1682 fprintf (f, "vector (0x%x)", type);
1683 fprintf (f, "\n index ");
1684 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1685 fprintf (f, "\n target ");
1686 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1687 break;
1689 case 7:
1690 case 8:
1692 long nrec, eloff, i;
1694 if ((type & 0x3f) == 7)
1695 fprintf (f, "record (0x%x) of ", type);
1696 else
1697 fprintf (f, "union (0x%x) of ", type);
1699 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1700 fprintf (f, "%lu elements: ", (unsigned long) nrec);
1702 for (i = 0; i < nrec; i++)
1704 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1705 fprintf (f, "\n ");
1706 fprintf (f, "offset %lu: ", (unsigned long) eloff);
1707 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1709 break;
1712 case 9:
1713 fprintf (f, "subrange (0x%x) of ", type);
1714 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1715 fprintf (f, " lower ");
1716 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1717 fprintf (f, " upper ");
1718 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1719 break;
1721 case 11:
1723 long value;
1725 fprintf (f, "named type (0x%x) ", type);
1726 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1727 if (value <= 0)
1728 fprintf (f, "[INVALID]");
1729 else
1730 fprintf (f, "\"%.*s\"",
1731 bfd_sym_symbol_name (abfd, value)[0],
1732 &bfd_sym_symbol_name (abfd, value)[1]);
1734 fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1735 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1736 break;
1739 default:
1740 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1741 break;
1744 if (type == (0x40 | 0x6))
1746 /* Vector. */
1747 long n, width, m;
1748 long l;
1749 long i;
1751 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1752 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1753 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1754 /* fprintf (f, "\n "); */
1755 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1756 for (i = 0; i < m; i++)
1758 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1759 if (i != 0)
1760 fprintf (f, " ");
1761 fprintf (f, "%ld", l);
1764 else if (type & 0x40)
1766 /* Other packed type. */
1767 long msb, lsb;
1769 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1770 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1771 /* fprintf (f, "\n "); */
1772 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1775 fprintf (f, "]");
1777 if (offsetptr != NULL)
1778 *offsetptr = offset;
1781 void
1782 bfd_sym_print_type_information_table_entry (bfd *abfd,
1783 FILE *f,
1784 bfd_sym_type_information_table_entry *entry)
1786 unsigned char *buf;
1787 unsigned long offset;
1788 unsigned int i;
1790 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1791 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1792 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1793 entry->nte_index,
1794 entry->physical_size, entry->offset, entry->logical_size);
1796 fprintf (f, "\n ");
1798 if (bfd_seek (abfd, entry->offset, SEEK_SET) != 0
1799 || (buf = _bfd_malloc_and_read (abfd, entry->physical_size,
1800 entry->physical_size)) == NULL)
1802 fprintf (f, "[ERROR]\n");
1803 return;
1806 fprintf (f, "[");
1807 for (i = 0; i < entry->physical_size; i++)
1809 if (i == 0)
1810 fprintf (f, "0x%02x", buf[i]);
1811 else
1812 fprintf (f, " 0x%02x", buf[i]);
1815 fprintf (f, "]");
1816 fprintf (f, "\n ");
1818 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1820 if (offset != entry->physical_size)
1821 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1822 free (buf);
1825 void
1826 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1827 FILE *f,
1828 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1830 fprintf (f, "[UNIMPLEMENTED]");
1833 void
1834 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1835 FILE *f,
1836 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1838 fprintf (f, "[UNIMPLEMENTED]");
1841 unsigned char *
1842 bfd_sym_display_name_table_entry (bfd *abfd,
1843 FILE *f,
1844 unsigned char *entry)
1846 unsigned long sym_index;
1847 unsigned long offset;
1848 bfd_sym_data_struct *sdata = NULL;
1850 BFD_ASSERT (bfd_sym_valid (abfd));
1851 sdata = abfd->tdata.sym_data;
1852 sym_index = (entry - sdata->name_table) / 2;
1854 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1856 unsigned short length = bfd_getb16 (entry + 2);
1857 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1858 offset = 2 + length + 1;
1860 else
1862 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1863 fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1865 if (sdata->version >= BFD_SYM_VERSION_3_4)
1866 offset = entry[0] + 2;
1867 else
1868 offset = entry[0] + 1;
1871 return (entry + offset + (offset % 2));
1874 void
1875 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1877 unsigned long name_table_len;
1878 unsigned char *name_table, *name_table_end, *cur;
1879 bfd_sym_data_struct *sdata = NULL;
1881 BFD_ASSERT (bfd_sym_valid (abfd));
1882 sdata = abfd->tdata.sym_data;
1884 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1885 name_table = sdata->name_table;
1886 name_table_end = name_table + name_table_len;
1888 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1890 cur = name_table;
1891 for (;;)
1893 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1894 if (cur >= name_table_end)
1895 break;
1899 void
1900 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1902 unsigned long i;
1903 bfd_sym_resources_table_entry entry;
1904 bfd_sym_data_struct *sdata = NULL;
1906 BFD_ASSERT (bfd_sym_valid (abfd));
1907 sdata = abfd->tdata.sym_data;
1909 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1910 sdata->header.dshb_rte.dti_object_count);
1912 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1914 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1915 fprintf (f, " [%8lu] [INVALID]\n", i);
1916 else
1918 fprintf (f, " [%8lu] ", i);
1919 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1920 fprintf (f, "\n");
1925 void
1926 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1928 unsigned long i;
1929 bfd_sym_modules_table_entry entry;
1930 bfd_sym_data_struct *sdata = NULL;
1932 BFD_ASSERT (bfd_sym_valid (abfd));
1933 sdata = abfd->tdata.sym_data;
1935 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1936 sdata->header.dshb_mte.dti_object_count);
1938 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1940 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1941 fprintf (f, " [%8lu] [INVALID]\n", i);
1942 else
1944 fprintf (f, " [%8lu] ", i);
1945 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1946 fprintf (f, "\n");
1951 void
1952 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1954 unsigned long i;
1955 bfd_sym_file_references_table_entry entry;
1956 bfd_sym_data_struct *sdata = NULL;
1958 BFD_ASSERT (bfd_sym_valid (abfd));
1959 sdata = abfd->tdata.sym_data;
1961 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1962 sdata->header.dshb_frte.dti_object_count);
1964 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1966 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1967 fprintf (f, " [%8lu] [INVALID]\n", i);
1968 else
1970 fprintf (f, " [%8lu] ", i);
1971 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1972 fprintf (f, "\n");
1977 void
1978 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
1980 unsigned long i;
1981 bfd_sym_contained_modules_table_entry entry;
1982 bfd_sym_data_struct *sdata = NULL;
1984 BFD_ASSERT (bfd_sym_valid (abfd));
1985 sdata = abfd->tdata.sym_data;
1987 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
1988 sdata->header.dshb_cmte.dti_object_count);
1990 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
1992 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
1993 fprintf (f, " [%8lu] [INVALID]\n", i);
1994 else
1996 fprintf (f, " [%8lu] ", i);
1997 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
1998 fprintf (f, "\n");
2003 void
2004 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2006 unsigned long i;
2007 bfd_sym_contained_variables_table_entry entry;
2008 bfd_sym_data_struct *sdata = NULL;
2010 BFD_ASSERT (bfd_sym_valid (abfd));
2011 sdata = abfd->tdata.sym_data;
2013 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2014 sdata->header.dshb_cvte.dti_object_count);
2016 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2018 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2019 fprintf (f, " [%8lu] [INVALID]\n", i);
2020 else
2022 fprintf (f, " [%8lu] ", i);
2023 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2024 fprintf (f, "\n");
2028 fprintf (f, "\n");
2031 void
2032 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2034 unsigned long i;
2035 bfd_sym_contained_statements_table_entry entry;
2036 bfd_sym_data_struct *sdata = NULL;
2038 BFD_ASSERT (bfd_sym_valid (abfd));
2039 sdata = abfd->tdata.sym_data;
2041 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2042 sdata->header.dshb_csnte.dti_object_count);
2044 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2046 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2047 fprintf (f, " [%8lu] [INVALID]\n", i);
2048 else
2050 fprintf (f, " [%8lu] ", i);
2051 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2052 fprintf (f, "\n");
2057 void
2058 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2060 unsigned long i;
2061 bfd_sym_contained_labels_table_entry entry;
2062 bfd_sym_data_struct *sdata = NULL;
2064 BFD_ASSERT (bfd_sym_valid (abfd));
2065 sdata = abfd->tdata.sym_data;
2067 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2068 sdata->header.dshb_clte.dti_object_count);
2070 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2072 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2073 fprintf (f, " [%8lu] [INVALID]\n", i);
2074 else
2076 fprintf (f, " [%8lu] ", i);
2077 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2078 fprintf (f, "\n");
2083 void
2084 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2086 unsigned long i;
2087 bfd_sym_contained_types_table_entry entry;
2088 bfd_sym_data_struct *sdata = NULL;
2090 BFD_ASSERT (bfd_sym_valid (abfd));
2091 sdata = abfd->tdata.sym_data;
2093 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2094 sdata->header.dshb_ctte.dti_object_count);
2096 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2098 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2099 fprintf (f, " [%8lu] [INVALID]\n", i);
2100 else
2102 fprintf (f, " [%8lu] ", i);
2103 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2104 fprintf (f, "\n");
2109 void
2110 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2112 unsigned long i;
2113 bfd_sym_file_references_index_table_entry entry;
2114 bfd_sym_data_struct *sdata = NULL;
2116 BFD_ASSERT (bfd_sym_valid (abfd));
2117 sdata = abfd->tdata.sym_data;
2119 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2120 sdata->header.dshb_fite.dti_object_count);
2122 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2124 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2125 fprintf (f, " [%8lu] [INVALID]\n", i);
2126 else
2128 fprintf (f, " [%8lu] ", i);
2129 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2130 fprintf (f, "\n");
2135 void
2136 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2138 unsigned long i;
2139 bfd_sym_constant_pool_entry entry;
2140 bfd_sym_data_struct *sdata = NULL;
2142 BFD_ASSERT (bfd_sym_valid (abfd));
2143 sdata = abfd->tdata.sym_data;
2145 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2146 sdata->header.dshb_const.dti_object_count);
2148 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2150 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2151 fprintf (f, " [%8lu] [INVALID]\n", i);
2152 else
2154 fprintf (f, " [%8lu] ", i);
2155 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2156 fprintf (f, "\n");
2161 void
2162 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2164 unsigned long i;
2165 bfd_sym_type_table_entry sym_index;
2166 bfd_sym_type_information_table_entry entry;
2167 bfd_sym_data_struct *sdata = NULL;
2169 BFD_ASSERT (bfd_sym_valid (abfd));
2170 sdata = abfd->tdata.sym_data;
2172 if (sdata->header.dshb_tte.dti_object_count > 99)
2173 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2174 sdata->header.dshb_tte.dti_object_count - 99);
2175 else
2177 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2178 return;
2181 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2183 if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2184 fprintf (f, " [%8lu] [INVALID]\n", i);
2185 else
2187 fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2189 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2190 fprintf (f, "[INVALID]");
2191 else
2192 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2194 fprintf (f, "\n");
2200 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2202 asection *bfdsec;
2203 const char *name = "symbols";
2205 mdata->name_table = 0;
2206 mdata->sbfd = abfd;
2207 mdata->version = version;
2209 if (bfd_seek (abfd, 0, SEEK_SET) != 0
2210 || bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2211 return -1;
2213 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2214 if (mdata->name_table == NULL)
2215 return -1;
2217 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2218 if (bfdsec == NULL)
2219 return -1;
2221 bfdsec->vma = 0;
2222 bfdsec->lma = 0;
2223 bfdsec->size = 0;
2224 bfdsec->filepos = 0;
2225 bfdsec->alignment_power = 0;
2227 abfd->tdata.sym_data = mdata;
2229 return 0;
2232 bfd_cleanup
2233 bfd_sym_object_p (bfd *abfd)
2235 bfd_sym_version version = -1;
2236 bfd_sym_data_struct *mdata;
2238 if (bfd_seek (abfd, 0, SEEK_SET) != 0
2239 || bfd_sym_read_version (abfd, &version) != 0)
2240 goto wrong;
2242 mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
2243 if (mdata == NULL)
2244 goto fail;
2246 if (bfd_sym_scan (abfd, version, mdata) != 0)
2247 goto wrong;
2249 return _bfd_no_cleanup;
2251 wrong:
2252 bfd_set_error (bfd_error_wrong_format);
2254 fail:
2255 return NULL;
2258 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2260 void
2261 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2263 bfd_symbol_info (symbol, ret);
2266 long
2267 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2269 return 0;
2272 long
2273 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2275 return 0;
2279 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2280 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2282 return 0;
2285 const bfd_target sym_vec =
2287 "sym", /* Name. */
2288 bfd_target_sym_flavour, /* Flavour. */
2289 BFD_ENDIAN_BIG, /* Byteorder. */
2290 BFD_ENDIAN_BIG, /* Header byteorder. */
2291 (HAS_RELOC | EXEC_P | /* Object flags. */
2292 HAS_LINENO | HAS_DEBUG |
2293 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2294 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2295 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2296 0, /* Symbol_leading_char. */
2297 ' ', /* AR_pad_char. */
2298 16, /* AR_max_namelen. */
2299 0, /* match priority. */
2300 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
2301 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2302 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2303 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2304 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2305 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2306 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2307 { /* bfd_check_format. */
2308 _bfd_dummy_target,
2309 bfd_sym_object_p, /* bfd_check_format. */
2310 _bfd_dummy_target,
2311 _bfd_dummy_target,
2313 { /* bfd_set_format. */
2314 _bfd_bool_bfd_false_error,
2315 bfd_sym_mkobject,
2316 _bfd_bool_bfd_false_error,
2317 _bfd_bool_bfd_false_error,
2319 { /* bfd_write_contents. */
2320 _bfd_bool_bfd_false_error,
2321 _bfd_bool_bfd_true,
2322 _bfd_bool_bfd_false_error,
2323 _bfd_bool_bfd_false_error,
2326 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2327 BFD_JUMP_TABLE_COPY (_bfd_generic),
2328 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2329 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2330 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2331 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2332 BFD_JUMP_TABLE_WRITE (bfd_sym),
2333 BFD_JUMP_TABLE_LINK (bfd_sym),
2334 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2336 NULL,
2338 NULL