* elf32-xtensa.c (analyze_relocations): Zero src_count if not relaxing.
[binutils.git] / bfd / xsym.c
blob174fb820ada5ba2f51985c6ffe56bc1ed68345f3
1 /* xSYM symbol-file support for BFD.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "xsym.h"
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "libbfd.h"
26 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
27 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
28 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
29 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
30 #define bfd_sym_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
31 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
32 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
33 #define bfd_sym_find_inliner_info _bfd_nosymbols_find_inliner_info
34 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
35 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols
36 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
37 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach
38 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents
39 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents
40 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
41 #define bfd_sym_bfd_relax_section bfd_generic_relax_section
42 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections
43 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections
44 #define bfd_sym_bfd_is_group_section bfd_generic_is_group_section
45 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
46 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked
47 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
48 #define bfd_sym_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
49 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
50 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
51 #define bfd_sym_bfd_final_link _bfd_generic_final_link
52 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
53 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
55 extern const bfd_target sym_vec;
57 static int
58 pstrcmp (const char *as, const char *bs)
60 const unsigned char *a = (const unsigned char *) as;
61 const unsigned char *b = (const unsigned char *) bs;
62 unsigned char clen;
63 int ret;
65 clen = (a[0] > b[0]) ? b[0] : a[0];
66 ret = memcmp (a + 1, b + 1, clen);
67 if (ret != 0)
68 return ret;
70 if (a[0] == b[0])
71 return 0;
72 else if (a[0] < b[0])
73 return -1;
74 else
75 return 1;
78 static unsigned long
79 compute_offset (unsigned long first_page,
80 unsigned long page_size,
81 unsigned long entry_size,
82 unsigned long index)
84 unsigned long entries_per_page = page_size / entry_size;
85 unsigned long page_number = first_page + (index / entries_per_page);
86 unsigned long page_offset = (index % entries_per_page) * entry_size;
88 return (page_number * page_size) + page_offset;
91 bfd_boolean
92 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
94 return 1;
97 void
98 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
99 void * afile ATTRIBUTE_UNUSED,
100 asymbol *symbol ATTRIBUTE_UNUSED,
101 bfd_print_symbol_type how ATTRIBUTE_UNUSED)
103 return;
106 bfd_boolean
107 bfd_sym_valid (bfd *abfd)
109 if (abfd == NULL || abfd->xvec == NULL)
110 return 0;
112 return abfd->xvec == &sym_vec;
115 unsigned char *
116 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
118 unsigned char *rstr;
119 long ret;
120 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
121 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
123 rstr = bfd_alloc (abfd, table_size);
124 if (rstr == NULL)
125 return rstr;
127 bfd_seek (abfd, table_offset, SEEK_SET);
128 ret = bfd_bread (rstr, table_size, abfd);
129 if (ret < 0 || (unsigned long) ret != table_size)
131 bfd_release (abfd, rstr);
132 return NULL;
135 return rstr;
138 void
139 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
140 size_t len,
141 bfd_sym_file_reference *entry)
143 BFD_ASSERT (len == 6);
145 entry->fref_frte_index = bfd_getb16 (buf);
146 entry->fref_offset = bfd_getb32 (buf + 2);
149 void
150 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
151 size_t len,
152 bfd_sym_table_info *table)
154 BFD_ASSERT (len == 8);
156 table->dti_first_page = bfd_getb16 (buf);
157 table->dti_page_count = bfd_getb16 (buf + 2);
158 table->dti_object_count = bfd_getb32 (buf + 4);
161 void
162 bfd_sym_parse_header_v32 (unsigned char *buf,
163 size_t len,
164 bfd_sym_header_block *header)
166 BFD_ASSERT (len == 154);
168 memcpy (header->dshb_id, buf, 32);
169 header->dshb_page_size = bfd_getb16 (buf + 32);
170 header->dshb_hash_page = bfd_getb16 (buf + 34);
171 header->dshb_root_mte = bfd_getb16 (buf + 36);
172 header->dshb_mod_date = bfd_getb32 (buf + 38);
174 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
175 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
176 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
177 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
178 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
179 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
180 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
181 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
182 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
183 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
184 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
185 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
186 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
188 memcpy (&header->dshb_file_creator, buf + 146, 4);
189 memcpy (&header->dshb_file_type, buf + 150, 4);
193 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
195 unsigned char buf[154];
196 long ret;
198 ret = bfd_bread (buf, 154, abfd);
199 if (ret != 154)
200 return -1;
202 bfd_sym_parse_header_v32 (buf, 154, header);
204 return 0;
208 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
209 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
211 abort ();
215 bfd_sym_read_header (bfd *abfd,
216 bfd_sym_header_block *header,
217 bfd_sym_version version)
219 switch (version)
221 case BFD_SYM_VERSION_3_5:
222 case BFD_SYM_VERSION_3_4:
223 return bfd_sym_read_header_v34 (abfd, header);
224 case BFD_SYM_VERSION_3_3:
225 case BFD_SYM_VERSION_3_2:
226 return bfd_sym_read_header_v32 (abfd, header);
227 case BFD_SYM_VERSION_3_1:
228 default:
229 return 0;
234 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
236 char version_string[32];
237 long ret;
239 ret = bfd_bread (version_string, sizeof (version_string), abfd);
240 if (ret != sizeof (version_string))
241 return -1;
243 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
244 *version = BFD_SYM_VERSION_3_1;
245 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
246 *version = BFD_SYM_VERSION_3_2;
247 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
248 *version = BFD_SYM_VERSION_3_3;
249 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
250 *version = BFD_SYM_VERSION_3_4;
251 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
252 *version = BFD_SYM_VERSION_3_5;
253 else
254 return -1;
256 return 0;
259 void
260 bfd_sym_display_table_summary (FILE *f,
261 bfd_sym_table_info *dti,
262 const char *name)
264 fprintf (f, "%-6s %13ld %13ld %13ld\n",
265 name,
266 dti->dti_first_page,
267 dti->dti_page_count,
268 dti->dti_object_count);
271 void
272 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
274 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
275 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
276 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
277 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
278 fprintf (f, " Modification Date: ");
279 fprintf (f, "[unimplemented]");
280 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
282 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
283 dshb->dshb_file_creator, dshb->dshb_file_type);
285 fprintf (f, "Table Name First Page Page Count Object Count\n");
286 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
288 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
289 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
290 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
291 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
292 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
293 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
294 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
295 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
296 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
297 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
298 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
299 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
300 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
302 fprintf (f, "\n");
305 void
306 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
307 size_t len,
308 bfd_sym_resources_table_entry *entry)
310 BFD_ASSERT (len == 18);
312 memcpy (&entry->rte_res_type, buf, 4);
313 entry->rte_res_number = bfd_getb16 (buf + 4);
314 entry->rte_nte_index = bfd_getb32 (buf + 6);
315 entry->rte_mte_first = bfd_getb16 (buf + 10);
316 entry->rte_mte_last = bfd_getb16 (buf + 12);
317 entry->rte_res_size = bfd_getb32 (buf + 14);
320 void
321 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
322 size_t len,
323 bfd_sym_modules_table_entry *entry)
325 BFD_ASSERT (len == 46);
327 entry->mte_rte_index = bfd_getb16 (buf);
328 entry->mte_res_offset = bfd_getb32 (buf + 2);
329 entry->mte_size = bfd_getb32 (buf + 6);
330 entry->mte_kind = buf[10];
331 entry->mte_scope = buf[11];
332 entry->mte_parent = bfd_getb16 (buf + 12);
333 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
334 entry->mte_imp_end = bfd_getb32 (buf + 20);
335 entry->mte_nte_index = bfd_getb32 (buf + 24);
336 entry->mte_cmte_index = bfd_getb16 (buf + 28);
337 entry->mte_cvte_index = bfd_getb32 (buf + 30);
338 entry->mte_clte_index = bfd_getb16 (buf + 34);
339 entry->mte_ctte_index = bfd_getb16 (buf + 36);
340 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
341 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
344 void
345 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
346 size_t len,
347 bfd_sym_file_references_table_entry *entry)
349 unsigned int type;
351 BFD_ASSERT (len == 10);
353 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
354 type = bfd_getb16 (buf);
356 switch (type)
358 case BFD_SYM_END_OF_LIST_3_2:
359 entry->generic.type = BFD_SYM_END_OF_LIST;
360 break;
362 case BFD_SYM_FILE_NAME_INDEX_3_2:
363 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
364 entry->filename.nte_index = bfd_getb32 (buf + 2);
365 entry->filename.mod_date = bfd_getb32 (buf + 6);
366 break;
368 default:
369 entry->entry.mte_index = type;
370 entry->entry.file_offset = bfd_getb32 (buf + 2);
374 void
375 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
376 size_t len,
377 bfd_sym_contained_modules_table_entry *entry)
379 unsigned int type;
381 BFD_ASSERT (len == 6);
383 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
384 type = bfd_getb16 (buf);
386 switch (type)
388 case BFD_SYM_END_OF_LIST_3_2:
389 entry->generic.type = BFD_SYM_END_OF_LIST;
390 break;
392 default:
393 entry->entry.mte_index = type;
394 entry->entry.nte_index = bfd_getb32 (buf + 2);
395 break;
399 void
400 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
401 size_t len,
402 bfd_sym_contained_variables_table_entry *entry)
404 unsigned int type;
406 BFD_ASSERT (len == 26);
408 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
409 type = bfd_getb16 (buf);
411 switch (type)
413 case BFD_SYM_END_OF_LIST_3_2:
414 entry->generic.type = BFD_SYM_END_OF_LIST;
415 break;
417 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
418 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
419 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
420 break;
422 default:
423 entry->entry.tte_index = type;
424 entry->entry.nte_index = bfd_getb32 (buf + 2);
425 entry->entry.file_delta = bfd_getb16 (buf + 6);
426 entry->entry.scope = buf[8];
427 entry->entry.la_size = buf[9];
429 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
431 entry->entry.address.scstruct.sca_kind = buf[10];
432 entry->entry.address.scstruct.sca_class = buf[11];
433 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
435 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
437 #if BFD_SYM_CVTE_SCA > 0
438 memcpy (&entry->entry.address.lastruct.la, buf + 10,
439 BFD_SYM_CVTE_SCA);
440 #endif
441 entry->entry.address.lastruct.la_kind = buf[23];
443 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
445 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
446 entry->entry.address.biglastruct.big_la_kind = buf[12];
451 void
452 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
453 size_t len,
454 bfd_sym_contained_statements_table_entry *entry)
456 unsigned int type;
458 BFD_ASSERT (len == 8);
460 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
461 type = bfd_getb16 (buf);
463 switch (type)
465 case BFD_SYM_END_OF_LIST_3_2:
466 entry->generic.type = BFD_SYM_END_OF_LIST;
467 break;
469 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
470 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
471 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
472 break;
474 default:
475 entry->entry.mte_index = type;
476 entry->entry.mte_offset = bfd_getb16 (buf + 2);
477 entry->entry.file_delta = bfd_getb32 (buf + 4);
478 break;
482 void
483 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
484 size_t len,
485 bfd_sym_contained_labels_table_entry *entry)
487 unsigned int type;
489 BFD_ASSERT (len == 12);
491 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
492 type = bfd_getb16 (buf);
494 switch (type)
496 case BFD_SYM_END_OF_LIST_3_2:
497 entry->generic.type = BFD_SYM_END_OF_LIST;
498 break;
500 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
501 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
502 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
503 break;
505 default:
506 entry->entry.mte_index = type;
507 entry->entry.mte_offset = bfd_getb16 (buf + 2);
508 entry->entry.nte_index = bfd_getb32 (buf + 4);
509 entry->entry.file_delta = bfd_getb16 (buf + 8);
510 entry->entry.scope = bfd_getb16 (buf + 10);
511 break;
515 void
516 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
517 size_t len,
518 bfd_sym_type_table_entry *entry)
520 BFD_ASSERT (len == 4);
522 *entry = bfd_getb32 (buf);
526 bfd_sym_fetch_resources_table_entry (bfd *abfd,
527 bfd_sym_resources_table_entry *entry,
528 unsigned long index)
530 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
531 unsigned long offset;
532 unsigned long entry_size;
533 unsigned char buf[18];
534 bfd_sym_data_struct *sdata = NULL;
536 parser = NULL;
537 BFD_ASSERT (bfd_sym_valid (abfd));
538 sdata = abfd->tdata.sym_data;
540 if (index == 0)
541 return -1;
543 switch (sdata->version)
545 case BFD_SYM_VERSION_3_5:
546 case BFD_SYM_VERSION_3_4:
547 return -1;
549 case BFD_SYM_VERSION_3_3:
550 case BFD_SYM_VERSION_3_2:
551 entry_size = 18;
552 parser = bfd_sym_parse_resources_table_entry_v32;
553 break;
555 case BFD_SYM_VERSION_3_1:
556 default:
557 return -1;
559 if (parser == NULL)
560 return -1;
562 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
563 sdata->header.dshb_page_size,
564 entry_size, index);
566 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
567 return -1;
568 if (bfd_bread (buf, entry_size, abfd) != entry_size)
569 return -1;
571 (*parser) (buf, entry_size, entry);
573 return 0;
577 bfd_sym_fetch_modules_table_entry (bfd *abfd,
578 bfd_sym_modules_table_entry *entry,
579 unsigned long index)
581 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
582 unsigned long offset;
583 unsigned long entry_size;
584 unsigned char buf[46];
585 bfd_sym_data_struct *sdata = NULL;
587 parser = NULL;
588 BFD_ASSERT (bfd_sym_valid (abfd));
589 sdata = abfd->tdata.sym_data;
591 if (index == 0)
592 return -1;
594 switch (sdata->version)
596 case BFD_SYM_VERSION_3_5:
597 case BFD_SYM_VERSION_3_4:
598 return -1;
600 case BFD_SYM_VERSION_3_3:
601 entry_size = 46;
602 parser = bfd_sym_parse_modules_table_entry_v33;
603 break;
605 case BFD_SYM_VERSION_3_2:
606 case BFD_SYM_VERSION_3_1:
607 default:
608 return -1;
610 if (parser == NULL)
611 return -1;
613 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
614 sdata->header.dshb_page_size,
615 entry_size, index);
617 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
618 return -1;
619 if (bfd_bread (buf, entry_size, abfd) != entry_size)
620 return -1;
622 (*parser) (buf, entry_size, entry);
624 return 0;
628 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
629 bfd_sym_file_references_table_entry *entry,
630 unsigned long index)
632 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
633 unsigned long offset;
634 unsigned long entry_size = 0;
635 unsigned char buf[8];
636 bfd_sym_data_struct *sdata = NULL;
638 parser = NULL;
639 BFD_ASSERT (bfd_sym_valid (abfd));
640 sdata = abfd->tdata.sym_data;
642 if (index == 0)
643 return -1;
645 switch (sdata->version)
647 case BFD_SYM_VERSION_3_3:
648 case BFD_SYM_VERSION_3_2:
649 entry_size = 10;
650 parser = bfd_sym_parse_file_references_table_entry_v32;
651 break;
653 case BFD_SYM_VERSION_3_5:
654 case BFD_SYM_VERSION_3_4:
655 case BFD_SYM_VERSION_3_1:
656 default:
657 break;
660 if (parser == NULL)
661 return -1;
663 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
664 sdata->header.dshb_page_size,
665 entry_size, index);
667 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
668 return -1;
669 if (bfd_bread (buf, entry_size, abfd) != entry_size)
670 return -1;
672 (*parser) (buf, entry_size, entry);
674 return 0;
678 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
679 bfd_sym_contained_modules_table_entry *entry,
680 unsigned long index)
682 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
683 unsigned long offset;
684 unsigned long entry_size = 0;
685 unsigned char buf[6];
686 bfd_sym_data_struct *sdata = NULL;
688 parser = NULL;
689 BFD_ASSERT (bfd_sym_valid (abfd));
690 sdata = abfd->tdata.sym_data;
692 if (index == 0)
693 return -1;
695 switch (sdata->version)
697 case BFD_SYM_VERSION_3_3:
698 case BFD_SYM_VERSION_3_2:
699 entry_size = 6;
700 parser = bfd_sym_parse_contained_modules_table_entry_v32;
701 break;
703 case BFD_SYM_VERSION_3_5:
704 case BFD_SYM_VERSION_3_4:
705 case BFD_SYM_VERSION_3_1:
706 default:
707 break;
710 if (parser == NULL)
711 return -1;
713 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
714 sdata->header.dshb_page_size,
715 entry_size, index);
717 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
718 return -1;
719 if (bfd_bread (buf, entry_size, abfd) != entry_size)
720 return -1;
722 (*parser) (buf, entry_size, entry);
724 return 0;
728 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
729 bfd_sym_contained_variables_table_entry *entry,
730 unsigned long index)
732 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
733 unsigned long offset;
734 unsigned long entry_size = 0;
735 unsigned char buf[26];
736 bfd_sym_data_struct *sdata = NULL;
738 parser = NULL;
739 BFD_ASSERT (bfd_sym_valid (abfd));
740 sdata = abfd->tdata.sym_data;
742 if (index == 0)
743 return -1;
745 switch (sdata->version)
747 case BFD_SYM_VERSION_3_3:
748 case BFD_SYM_VERSION_3_2:
749 entry_size = 26;
750 parser = bfd_sym_parse_contained_variables_table_entry_v32;
751 break;
753 case BFD_SYM_VERSION_3_5:
754 case BFD_SYM_VERSION_3_4:
755 case BFD_SYM_VERSION_3_1:
756 default:
757 break;
760 if (parser == NULL)
761 return -1;
763 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
764 sdata->header.dshb_page_size,
765 entry_size, index);
767 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
768 return -1;
769 if (bfd_bread (buf, entry_size, abfd) != entry_size)
770 return -1;
772 (*parser) (buf, entry_size, entry);
774 return 0;
778 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
779 bfd_sym_contained_statements_table_entry *entry,
780 unsigned long index)
782 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
783 unsigned long offset;
784 unsigned long entry_size = 0;
785 unsigned char buf[8];
786 bfd_sym_data_struct *sdata = NULL;
788 parser = NULL;
789 BFD_ASSERT (bfd_sym_valid (abfd));
790 sdata = abfd->tdata.sym_data;
792 if (index == 0)
793 return -1;
795 switch (sdata->version)
797 case BFD_SYM_VERSION_3_3:
798 case BFD_SYM_VERSION_3_2:
799 entry_size = 8;
800 parser = bfd_sym_parse_contained_statements_table_entry_v32;
801 break;
803 case BFD_SYM_VERSION_3_5:
804 case BFD_SYM_VERSION_3_4:
805 case BFD_SYM_VERSION_3_1:
806 default:
807 break;
810 if (parser == NULL)
811 return -1;
813 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
814 sdata->header.dshb_page_size,
815 entry_size, index);
817 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
818 return -1;
819 if (bfd_bread (buf, entry_size, abfd) != entry_size)
820 return -1;
822 (*parser) (buf, entry_size, entry);
824 return 0;
828 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
829 bfd_sym_contained_labels_table_entry *entry,
830 unsigned long index)
832 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
833 unsigned long offset;
834 unsigned long entry_size = 0;
835 unsigned char buf[12];
836 bfd_sym_data_struct *sdata = NULL;
838 parser = NULL;
839 BFD_ASSERT (bfd_sym_valid (abfd));
840 sdata = abfd->tdata.sym_data;
842 if (index == 0)
843 return -1;
845 switch (sdata->version)
847 case BFD_SYM_VERSION_3_3:
848 case BFD_SYM_VERSION_3_2:
849 entry_size = 12;
850 parser = bfd_sym_parse_contained_labels_table_entry_v32;
851 break;
853 case BFD_SYM_VERSION_3_5:
854 case BFD_SYM_VERSION_3_4:
855 case BFD_SYM_VERSION_3_1:
856 default:
857 break;
860 if (parser == NULL)
861 return -1;
863 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
864 sdata->header.dshb_page_size,
865 entry_size, index);
867 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
868 return -1;
869 if (bfd_bread (buf, entry_size, abfd) != entry_size)
870 return -1;
872 (*parser) (buf, entry_size, entry);
874 return 0;
878 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
879 bfd_sym_contained_types_table_entry *entry,
880 unsigned long index)
882 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
883 unsigned long offset;
884 unsigned long entry_size = 0;
885 unsigned char buf[0];
886 bfd_sym_data_struct *sdata = NULL;
888 parser = NULL;
889 BFD_ASSERT (bfd_sym_valid (abfd));
890 sdata = abfd->tdata.sym_data;
892 if (index == 0)
893 return -1;
895 switch (sdata->version)
897 case BFD_SYM_VERSION_3_3:
898 case BFD_SYM_VERSION_3_2:
899 entry_size = 0;
900 parser = NULL;
901 break;
903 case BFD_SYM_VERSION_3_5:
904 case BFD_SYM_VERSION_3_4:
905 case BFD_SYM_VERSION_3_1:
906 default:
907 break;
910 if (parser == NULL)
911 return -1;
913 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
914 sdata->header.dshb_page_size,
915 entry_size, index);
917 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
918 return -1;
919 if (bfd_bread (buf, entry_size, abfd) != entry_size)
920 return -1;
922 (*parser) (buf, entry_size, entry);
924 return 0;
928 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
929 bfd_sym_file_references_index_table_entry *entry,
930 unsigned long index)
932 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
933 unsigned long offset;
934 unsigned long entry_size = 0;
935 unsigned char buf[0];
936 bfd_sym_data_struct *sdata = NULL;
938 parser = NULL;
939 BFD_ASSERT (bfd_sym_valid (abfd));
940 sdata = abfd->tdata.sym_data;
942 if (index == 0)
943 return -1;
945 switch (sdata->version)
947 case BFD_SYM_VERSION_3_3:
948 case BFD_SYM_VERSION_3_2:
949 entry_size = 0;
950 parser = NULL;
951 break;
953 case BFD_SYM_VERSION_3_5:
954 case BFD_SYM_VERSION_3_4:
955 case BFD_SYM_VERSION_3_1:
956 default:
957 break;
960 if (parser == NULL)
961 return -1;
963 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
964 sdata->header.dshb_page_size,
965 entry_size, index);
967 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
968 return -1;
969 if (bfd_bread (buf, entry_size, abfd) != entry_size)
970 return -1;
972 (*parser) (buf, entry_size, entry);
974 return 0;
978 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
979 bfd_sym_constant_pool_entry *entry,
980 unsigned long index)
982 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
983 unsigned long offset;
984 unsigned long entry_size = 0;
985 unsigned char buf[0];
986 bfd_sym_data_struct *sdata = NULL;
988 parser = NULL;
989 BFD_ASSERT (bfd_sym_valid (abfd));
990 sdata = abfd->tdata.sym_data;
992 if (index == 0)
993 return -1;
995 switch (sdata->version)
997 case BFD_SYM_VERSION_3_3:
998 case BFD_SYM_VERSION_3_2:
999 entry_size = 0;
1000 parser = NULL;
1001 break;
1003 case BFD_SYM_VERSION_3_5:
1004 case BFD_SYM_VERSION_3_4:
1005 case BFD_SYM_VERSION_3_1:
1006 default:
1007 break;
1010 if (parser == NULL)
1011 return -1;
1013 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1014 sdata->header.dshb_page_size,
1015 entry_size, index);
1017 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1018 return -1;
1019 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1020 return -1;
1022 (*parser) (buf, entry_size, entry);
1024 return 0;
1028 bfd_sym_fetch_type_table_entry (bfd *abfd,
1029 bfd_sym_type_table_entry *entry,
1030 unsigned long index)
1032 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1033 unsigned long offset;
1034 unsigned long entry_size = 0;
1035 unsigned char buf[4];
1036 bfd_sym_data_struct *sdata = NULL;
1038 parser = NULL;
1039 BFD_ASSERT (bfd_sym_valid (abfd));
1040 sdata = abfd->tdata.sym_data;
1042 switch (sdata->version)
1044 case BFD_SYM_VERSION_3_3:
1045 case BFD_SYM_VERSION_3_2:
1046 entry_size = 4;
1047 parser = bfd_sym_parse_type_table_entry_v32;
1048 break;
1050 case BFD_SYM_VERSION_3_5:
1051 case BFD_SYM_VERSION_3_4:
1052 case BFD_SYM_VERSION_3_1:
1053 default:
1054 break;
1057 if (parser == NULL)
1058 return -1;
1060 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1061 sdata->header.dshb_page_size,
1062 entry_size, index);
1064 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1065 return -1;
1066 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1067 return -1;
1069 (*parser) (buf, entry_size, entry);
1071 return 0;
1075 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1076 bfd_sym_type_information_table_entry *entry,
1077 unsigned long offset)
1079 unsigned char buf[4];
1080 bfd_sym_data_struct *sdata = NULL;
1082 BFD_ASSERT (bfd_sym_valid (abfd));
1083 sdata = abfd->tdata.sym_data;
1085 if (offset == 0)
1086 return -1;
1088 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1089 return -1;
1091 if (bfd_bread (buf, 4, abfd) != 4)
1092 return -1;
1093 entry->nte_index = bfd_getb32 (buf);
1095 if (bfd_bread (buf, 2, abfd) != 2)
1096 return -1;
1097 entry->physical_size = bfd_getb16 (buf);
1099 if (entry->physical_size & 0x8000)
1101 if (bfd_bread (buf, 4, abfd) != 4)
1102 return -1;
1103 entry->physical_size &= 0x7fff;
1104 entry->logical_size = bfd_getb32 (buf);
1105 entry->offset = offset + 10;
1107 else
1109 if (bfd_bread (buf, 2, abfd) != 2)
1110 return -1;
1111 entry->physical_size &= 0x7fff;
1112 entry->logical_size = bfd_getb16 (buf);
1113 entry->offset = offset + 8;
1116 return 0;
1120 bfd_sym_fetch_type_table_information (bfd *abfd,
1121 bfd_sym_type_information_table_entry *entry,
1122 unsigned long index)
1124 bfd_sym_type_table_entry tindex;
1125 bfd_sym_data_struct *sdata = NULL;
1127 BFD_ASSERT (bfd_sym_valid (abfd));
1128 sdata = abfd->tdata.sym_data;
1130 if (sdata->header.dshb_tte.dti_object_count <= 99)
1131 return -1;
1132 if (index < 100)
1133 return -1;
1135 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, index - 100) < 0)
1136 return -1;
1137 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1138 return -1;
1140 return 0;
1143 const unsigned char *
1144 bfd_sym_symbol_name (bfd *abfd, unsigned long index)
1146 bfd_sym_data_struct *sdata = NULL;
1148 BFD_ASSERT (bfd_sym_valid (abfd));
1149 sdata = abfd->tdata.sym_data;
1151 if (index == 0)
1152 return (const unsigned char *) "";
1154 index *= 2;
1155 if ((index / sdata->header.dshb_page_size)
1156 > sdata->header.dshb_nte.dti_page_count)
1157 return (const unsigned char *) "\09[INVALID]";
1159 return (const unsigned char *) sdata->name_table + index;
1162 const unsigned char *
1163 bfd_sym_module_name (bfd *abfd, unsigned long index)
1165 bfd_sym_modules_table_entry entry;
1167 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0)
1168 return (const unsigned char *) "\09[INVALID]";
1170 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1173 const char *
1174 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1176 switch (kind)
1178 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1179 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1180 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1181 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1182 default: return "[UNKNOWN]";
1186 const char *
1187 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1189 switch (kind)
1191 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1192 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1193 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1194 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1195 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1196 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1197 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1198 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1199 default: return "[UNKNOWN]";
1203 const char *
1204 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1206 switch (kind)
1208 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1209 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1210 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1211 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1212 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1213 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1214 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1215 default: return "[UNKNOWN]";
1219 const char *
1220 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1222 switch (scope)
1224 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1225 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1226 default:
1227 return "[UNKNOWN]";
1231 void
1232 bfd_sym_print_file_reference (bfd *abfd,
1233 FILE *f,
1234 bfd_sym_file_reference *entry)
1236 bfd_sym_file_references_table_entry frtentry;
1237 int ret;
1239 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1240 entry->fref_frte_index);
1241 fprintf (f, "FILE ");
1243 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1244 fprintf (f, "[INVALID]");
1245 else
1246 fprintf (f, "\"%.*s\"",
1247 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1248 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1250 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1253 void
1254 bfd_sym_print_resources_table_entry (bfd *abfd,
1255 FILE *f,
1256 bfd_sym_resources_table_entry *entry)
1258 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1259 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1260 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1261 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1262 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1265 void
1266 bfd_sym_print_modules_table_entry (bfd *abfd,
1267 FILE *f,
1268 bfd_sym_modules_table_entry *entry)
1270 fprintf (f, "\"%.*s\" (NTE %lu)",
1271 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1272 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1273 entry->mte_nte_index);
1275 fprintf (f, "\n ");
1277 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1278 fprintf (f, " range %lu -- %lu",
1279 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1281 fprintf (f, "\n ");
1283 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1284 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1286 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1287 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1289 fprintf (f, "\n ");
1291 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1292 entry->mte_cmte_index, entry->mte_cvte_index,
1293 entry->mte_clte_index, entry->mte_ctte_index,
1294 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1296 if (entry->mte_parent != 0)
1297 fprintf (f, ", parent %lu", entry->mte_parent);
1298 else
1299 fprintf (f, ", no parent");
1301 if (entry->mte_cmte_index != 0)
1302 fprintf (f, ", child %lu", entry->mte_cmte_index);
1303 else
1304 fprintf (f, ", no child");
1307 void
1308 bfd_sym_print_file_references_table_entry (bfd *abfd,
1309 FILE *f,
1310 bfd_sym_file_references_table_entry *entry)
1312 switch (entry->generic.type)
1314 case BFD_SYM_FILE_NAME_INDEX:
1315 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1316 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1317 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1318 entry->filename.nte_index);
1320 fprintf (f, "[UNIMPLEMENTED]");
1321 /* printModDate (entry->filename.mod_date); */
1322 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1323 break;
1325 case BFD_SYM_END_OF_LIST:
1326 fprintf (f, "END");
1327 break;
1329 default:
1330 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1331 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1332 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1333 entry->entry.mte_index,
1334 entry->entry.file_offset);
1335 break;
1339 void
1340 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1341 FILE *f,
1342 bfd_sym_contained_modules_table_entry *entry)
1344 switch (entry->generic.type)
1346 case BFD_SYM_END_OF_LIST:
1347 fprintf (f, "END");
1348 break;
1350 default:
1351 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1352 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1353 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1354 entry->entry.mte_index,
1355 entry->entry.nte_index);
1356 break;
1360 void
1361 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1362 FILE *f,
1363 bfd_sym_contained_variables_table_entry *entry)
1365 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1367 fprintf (f, "END");
1368 return;
1371 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1373 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1374 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1375 return;
1378 fprintf (f, "\"%.*s\" (NTE %lu)",
1379 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1380 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1381 entry->entry.nte_index);
1383 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1384 fprintf (f, ", offset %lu", entry->entry.file_delta);
1385 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1387 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1388 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1389 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1390 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1391 entry->entry.address.scstruct.sca_offset);
1392 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1394 unsigned long i;
1396 fprintf (f, ", la [");
1397 for (i = 0; i < entry->entry.la_size; i++)
1398 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1399 fprintf (f, "]");
1401 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1402 fprintf (f, ", bigla %lu, biglakind %u",
1403 entry->entry.address.biglastruct.big_la,
1404 entry->entry.address.biglastruct.big_la_kind);
1406 else
1407 fprintf (f, ", la [INVALID]");
1410 void
1411 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1412 FILE *f,
1413 bfd_sym_contained_statements_table_entry *entry)
1415 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1417 fprintf (f, "END");
1418 return;
1421 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1423 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1424 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1425 return;
1428 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1429 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1430 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1431 entry->entry.mte_index,
1432 entry->entry.mte_offset,
1433 entry->entry.file_delta);
1436 void
1437 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1438 FILE *f,
1439 bfd_sym_contained_labels_table_entry *entry)
1441 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1443 fprintf (f, "END");
1444 return;
1447 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1449 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1450 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1451 return;
1454 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1455 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1456 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1457 entry->entry.mte_index,
1458 entry->entry.mte_offset,
1459 entry->entry.file_delta,
1460 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1463 void
1464 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1465 FILE *f,
1466 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1468 fprintf (f, "[UNIMPLEMENTED]");
1471 const char *
1472 bfd_sym_type_operator_name (unsigned char num)
1474 switch (num)
1476 case 1: return "TTE";
1477 case 2: return "PointerTo";
1478 case 3: return "ScalarOf";
1479 case 4: return "ConstantOf";
1480 case 5: return "EnumerationOf";
1481 case 6: return "VectorOf";
1482 case 7: return "RecordOf";
1483 case 8: return "UnionOf";
1484 case 9: return "SubRangeOf";
1485 case 10: return "SetOf";
1486 case 11: return "NamedTypeOf";
1487 case 12: return "ProcOf";
1488 case 13: return "ValueOf";
1489 case 14: return "ArrayOf";
1490 default: return "[UNKNOWN OPERATOR]";
1494 const char *
1495 bfd_sym_type_basic_name (unsigned char num)
1497 switch (num)
1499 case 0: return "void";
1500 case 1: return "pascal string";
1501 case 2: return "unsigned long";
1502 case 3: return "signed long";
1503 case 4: return "extended (10 bytes)";
1504 case 5: return "pascal boolean (1 byte)";
1505 case 6: return "unsigned byte";
1506 case 7: return "signed byte";
1507 case 8: return "character (1 byte)";
1508 case 9: return "wide character (2 bytes)";
1509 case 10: return "unsigned short";
1510 case 11: return "signed short";
1511 case 12: return "singled";
1512 case 13: return "double";
1513 case 14: return "extended (12 bytes)";
1514 case 15: return "computational (8 bytes)";
1515 case 16: return "c string";
1516 case 17: return "as-is string";
1517 default: return "[UNKNOWN BASIC TYPE]";
1522 bfd_sym_fetch_long (unsigned char *buf,
1523 unsigned long len,
1524 unsigned long offset,
1525 unsigned long *offsetptr,
1526 long *value)
1528 int ret;
1530 if (offset >= len)
1532 *value = 0;
1533 offset += 0;
1534 ret = -1;
1536 else if (! (buf[offset] & 0x80))
1538 *value = buf[offset];
1539 offset += 1;
1540 ret = 0;
1542 else if (buf[offset] == 0xc0)
1544 if ((offset + 5) > len)
1546 *value = 0;
1547 offset = len;
1548 ret = -1;
1550 else
1552 *value = bfd_getb32 (buf + offset + 1);
1553 offset += 5;
1554 ret = 0;
1557 else if ((buf[offset] & 0xc0) == 0xc0)
1559 *value = -(buf[offset] & 0x3f);
1560 offset += 1;
1561 ret = 0;
1563 else if ((buf[offset] & 0xc0) == 0x80)
1565 if ((offset + 2) > len)
1567 *value = 0;
1568 offset = len;
1569 ret = -1;
1571 else
1573 *value = bfd_getb16 (buf + offset) & 0x3fff;
1574 offset += 2;
1575 ret = 0;
1578 else
1579 abort ();
1581 if (offsetptr != NULL)
1582 *offsetptr = offset;
1584 return ret;
1587 void
1588 bfd_sym_print_type_information (bfd *abfd,
1589 FILE *f,
1590 unsigned char *buf,
1591 unsigned long len,
1592 unsigned long offset,
1593 unsigned long *offsetptr)
1595 unsigned int type;
1597 if (offset >= len)
1599 fprintf (f, "[NULL]");
1601 if (offsetptr != NULL)
1602 *offsetptr = offset;
1603 return;
1606 type = buf[offset];
1607 offset++;
1609 if (! (type & 0x80))
1611 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1613 if (offsetptr != NULL)
1614 *offsetptr = offset;
1615 return;
1618 if (type & 0x40)
1619 fprintf (f, "[packed ");
1620 else
1621 fprintf (f, "[");
1623 switch (type & 0x3f)
1625 case 1:
1627 long value;
1628 bfd_sym_type_information_table_entry tinfo;
1630 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1631 if (value <= 0)
1632 fprintf (f, "[INVALID]");
1633 else
1635 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1636 fprintf (f, "[INVALID]");
1637 else
1638 fprintf (f, "\"%.*s\"",
1639 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1640 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1642 fprintf (f, " (TTE %lu)", value);
1643 break;
1646 case 2:
1647 fprintf (f, "pointer (0x%x) to ", type);
1648 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1649 break;
1651 case 3:
1653 long value;
1655 fprintf (f, "scalar (0x%x) of ", type);
1656 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1657 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1658 fprintf (f, " (%lu)", (unsigned long) value);
1659 break;
1662 case 5:
1664 long lower, upper, nelem;
1665 int i;
1667 fprintf (f, "enumeration (0x%x) of ", type);
1668 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1669 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1670 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1671 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1672 fprintf (f, " from %lu to %lu with %lu elements: ",
1673 (unsigned long) lower, (unsigned long) upper,
1674 (unsigned long) nelem);
1676 for (i = 0; i < nelem; i++)
1678 fprintf (f, "\n ");
1679 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1681 break;
1684 case 6:
1685 fprintf (f, "vector (0x%x)", type);
1686 fprintf (f, "\n index ");
1687 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1688 fprintf (f, "\n target ");
1689 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1690 break;
1692 case 7:
1693 case 8:
1695 long nrec, eloff, i;
1697 if ((type & 0x3f) == 7)
1698 fprintf (f, "record (0x%x) of ", type);
1699 else
1700 fprintf (f, "union (0x%x) of ", type);
1702 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1703 fprintf (f, "%lu elements: ", nrec);
1705 for (i = 0; i < nrec; i++)
1707 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1708 fprintf (f, "\n ");
1709 fprintf (f, "offset %lu: ", eloff);
1710 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1712 break;
1715 case 9:
1716 fprintf (f, "subrange (0x%x) of ", type);
1717 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1718 fprintf (f, " lower ");
1719 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1720 fprintf (f, " upper ");
1721 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1722 break;
1724 case 11:
1726 long value;
1728 fprintf (f, "named type (0x%x) ", type);
1729 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1730 if (value <= 0)
1731 fprintf (f, "[INVALID]");
1732 else
1733 fprintf (f, "\"%.*s\"",
1734 bfd_sym_symbol_name (abfd, value)[0],
1735 &bfd_sym_symbol_name (abfd, value)[1]);
1737 fprintf (f, " (NTE %lu) with type ", value);
1738 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1739 break;
1742 default:
1743 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1744 break;
1747 if (type == (0x40 | 0x6))
1749 /* Vector. */
1750 long n, width, m;
1751 long l;
1752 long i;
1754 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1755 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1756 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1757 /* fprintf (f, "\n "); */
1758 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1759 for (i = 0; i < m; i++)
1761 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1762 if (i != 0)
1763 fprintf (f, " ");
1764 fprintf (f, "%ld", l);
1767 else if (type & 0x40)
1769 /* Other packed type. */
1770 long msb, lsb;
1772 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1773 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1774 /* fprintf (f, "\n "); */
1775 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1778 fprintf (f, "]");
1780 if (offsetptr != NULL)
1781 *offsetptr = offset;
1784 void
1785 bfd_sym_print_type_information_table_entry (bfd *abfd,
1786 FILE *f,
1787 bfd_sym_type_information_table_entry *entry)
1789 unsigned char *buf;
1790 unsigned long offset;
1791 unsigned int i;
1793 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1794 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1795 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1796 entry->nte_index,
1797 entry->physical_size, entry->offset, entry->logical_size);
1799 fprintf (f, "\n ");
1801 buf = alloca (entry->physical_size);
1802 if (buf == NULL)
1804 fprintf (f, "[ERROR]\n");
1805 return;
1807 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1809 fprintf (f, "[ERROR]\n");
1810 return;
1812 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1814 fprintf (f, "[ERROR]\n");
1815 return;
1818 fprintf (f, "[");
1819 for (i = 0; i < entry->physical_size; i++)
1821 if (i == 0)
1822 fprintf (f, "0x%02x", buf[i]);
1823 else
1824 fprintf (f, " 0x%02x", buf[i]);
1827 fprintf (f, "]");
1828 fprintf (f, "\n ");
1830 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1832 if (offset != entry->physical_size)
1833 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1836 void
1837 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1838 FILE *f,
1839 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1841 fprintf (f, "[UNIMPLEMENTED]");
1844 void
1845 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1846 FILE *f,
1847 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1849 fprintf (f, "[UNIMPLEMENTED]");
1852 unsigned char *
1853 bfd_sym_display_name_table_entry (bfd *abfd,
1854 FILE *f,
1855 unsigned char *entry)
1857 unsigned long index;
1858 unsigned long offset;
1859 bfd_sym_data_struct *sdata = NULL;
1861 BFD_ASSERT (bfd_sym_valid (abfd));
1862 sdata = abfd->tdata.sym_data;
1863 index = (entry - sdata->name_table) / 2;
1865 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1867 unsigned short length = bfd_getb16 (entry + 2);
1868 fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4);
1869 offset = 2 + length + 1;
1871 else
1873 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1874 fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1);
1876 if (sdata->version >= BFD_SYM_VERSION_3_4)
1877 offset = entry[0] + 2;
1878 else
1879 offset = entry[0] + 1;
1882 return (entry + offset + (offset % 2));
1885 void
1886 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1888 unsigned long name_table_len;
1889 unsigned char *name_table, *name_table_end, *cur;
1890 bfd_sym_data_struct *sdata = NULL;
1892 BFD_ASSERT (bfd_sym_valid (abfd));
1893 sdata = abfd->tdata.sym_data;
1895 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1896 name_table = sdata->name_table;
1897 name_table_end = name_table + name_table_len;
1899 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1901 cur = name_table;
1902 for (;;)
1904 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1905 if (cur >= name_table_end)
1906 break;
1910 void
1911 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1913 unsigned long i;
1914 bfd_sym_resources_table_entry entry;
1915 bfd_sym_data_struct *sdata = NULL;
1917 BFD_ASSERT (bfd_sym_valid (abfd));
1918 sdata = abfd->tdata.sym_data;
1920 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1921 sdata->header.dshb_rte.dti_object_count);
1923 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1925 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1926 fprintf (f, " [%8lu] [INVALID]\n", i);
1927 else
1929 fprintf (f, " [%8lu] ", i);
1930 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1931 fprintf (f, "\n");
1936 void
1937 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1939 unsigned long i;
1940 bfd_sym_modules_table_entry entry;
1941 bfd_sym_data_struct *sdata = NULL;
1943 BFD_ASSERT (bfd_sym_valid (abfd));
1944 sdata = abfd->tdata.sym_data;
1946 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1947 sdata->header.dshb_mte.dti_object_count);
1949 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1951 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1952 fprintf (f, " [%8lu] [INVALID]\n", i);
1953 else
1955 fprintf (f, " [%8lu] ", i);
1956 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1957 fprintf (f, "\n");
1962 void
1963 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1965 unsigned long i;
1966 bfd_sym_file_references_table_entry entry;
1967 bfd_sym_data_struct *sdata = NULL;
1969 BFD_ASSERT (bfd_sym_valid (abfd));
1970 sdata = abfd->tdata.sym_data;
1972 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1973 sdata->header.dshb_frte.dti_object_count);
1975 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1977 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1978 fprintf (f, " [%8lu] [INVALID]\n", i);
1979 else
1981 fprintf (f, " [%8lu] ", i);
1982 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1983 fprintf (f, "\n");
1988 void
1989 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
1991 unsigned long i;
1992 bfd_sym_contained_modules_table_entry entry;
1993 bfd_sym_data_struct *sdata = NULL;
1995 BFD_ASSERT (bfd_sym_valid (abfd));
1996 sdata = abfd->tdata.sym_data;
1998 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
1999 sdata->header.dshb_cmte.dti_object_count);
2001 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2003 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2004 fprintf (f, " [%8lu] [INVALID]\n", i);
2005 else
2007 fprintf (f, " [%8lu] ", i);
2008 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2009 fprintf (f, "\n");
2014 void
2015 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2017 unsigned long i;
2018 bfd_sym_contained_variables_table_entry entry;
2019 bfd_sym_data_struct *sdata = NULL;
2021 BFD_ASSERT (bfd_sym_valid (abfd));
2022 sdata = abfd->tdata.sym_data;
2024 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2025 sdata->header.dshb_cvte.dti_object_count);
2027 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2029 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2030 fprintf (f, " [%8lu] [INVALID]\n", i);
2031 else
2033 fprintf (f, " [%8lu] ", i);
2034 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2035 fprintf (f, "\n");
2039 fprintf (f, "\n");
2042 void
2043 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2045 unsigned long i;
2046 bfd_sym_contained_statements_table_entry entry;
2047 bfd_sym_data_struct *sdata = NULL;
2049 BFD_ASSERT (bfd_sym_valid (abfd));
2050 sdata = abfd->tdata.sym_data;
2052 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2053 sdata->header.dshb_csnte.dti_object_count);
2055 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2057 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2058 fprintf (f, " [%8lu] [INVALID]\n", i);
2059 else
2061 fprintf (f, " [%8lu] ", i);
2062 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2063 fprintf (f, "\n");
2068 void
2069 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2071 unsigned long i;
2072 bfd_sym_contained_labels_table_entry entry;
2073 bfd_sym_data_struct *sdata = NULL;
2075 BFD_ASSERT (bfd_sym_valid (abfd));
2076 sdata = abfd->tdata.sym_data;
2078 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2079 sdata->header.dshb_clte.dti_object_count);
2081 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2083 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2084 fprintf (f, " [%8lu] [INVALID]\n", i);
2085 else
2087 fprintf (f, " [%8lu] ", i);
2088 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2089 fprintf (f, "\n");
2094 void
2095 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2097 unsigned long i;
2098 bfd_sym_contained_types_table_entry entry;
2099 bfd_sym_data_struct *sdata = NULL;
2101 BFD_ASSERT (bfd_sym_valid (abfd));
2102 sdata = abfd->tdata.sym_data;
2104 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2105 sdata->header.dshb_ctte.dti_object_count);
2107 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2109 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2110 fprintf (f, " [%8lu] [INVALID]\n", i);
2111 else
2113 fprintf (f, " [%8lu] ", i);
2114 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2115 fprintf (f, "\n");
2120 void
2121 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2123 unsigned long i;
2124 bfd_sym_file_references_index_table_entry entry;
2125 bfd_sym_data_struct *sdata = NULL;
2127 BFD_ASSERT (bfd_sym_valid (abfd));
2128 sdata = abfd->tdata.sym_data;
2130 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2131 sdata->header.dshb_fite.dti_object_count);
2133 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2135 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2136 fprintf (f, " [%8lu] [INVALID]\n", i);
2137 else
2139 fprintf (f, " [%8lu] ", i);
2140 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2141 fprintf (f, "\n");
2146 void
2147 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2149 unsigned long i;
2150 bfd_sym_constant_pool_entry entry;
2151 bfd_sym_data_struct *sdata = NULL;
2153 BFD_ASSERT (bfd_sym_valid (abfd));
2154 sdata = abfd->tdata.sym_data;
2156 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2157 sdata->header.dshb_const.dti_object_count);
2159 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2161 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2162 fprintf (f, " [%8lu] [INVALID]\n", i);
2163 else
2165 fprintf (f, " [%8lu] ", i);
2166 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2167 fprintf (f, "\n");
2172 void
2173 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2175 unsigned long i;
2176 bfd_sym_type_table_entry index;
2177 bfd_sym_type_information_table_entry entry;
2178 bfd_sym_data_struct *sdata = NULL;
2180 BFD_ASSERT (bfd_sym_valid (abfd));
2181 sdata = abfd->tdata.sym_data;
2183 if (sdata->header.dshb_tte.dti_object_count > 99)
2184 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2185 sdata->header.dshb_tte.dti_object_count - 99);
2186 else
2188 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2189 return;
2192 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2194 if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0)
2195 fprintf (f, " [%8lu] [INVALID]\n", i);
2196 else
2198 fprintf (f, " [%8lu] (TINFO %lu) ", i, index);
2200 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, index) < 0)
2201 fprintf (f, "[INVALID]");
2202 else
2203 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2205 fprintf (f, "\n");
2211 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2213 asection *bfdsec;
2214 const char *name = "symbols";
2216 mdata->name_table = 0;
2217 mdata->sbfd = abfd;
2218 mdata->version = version;
2220 bfd_seek (abfd, 0, SEEK_SET);
2221 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2222 return -1;
2224 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2225 if (mdata->name_table == NULL)
2226 return -1;
2228 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2229 if (bfdsec == NULL)
2230 return -1;
2232 bfdsec->vma = 0;
2233 bfdsec->lma = 0;
2234 bfdsec->size = 0;
2235 bfdsec->filepos = 0;
2236 bfdsec->alignment_power = 0;
2238 abfd->tdata.sym_data = mdata;
2240 return 0;
2243 const bfd_target *
2244 bfd_sym_object_p (bfd *abfd)
2246 struct bfd_preserve preserve;
2247 bfd_sym_version version = -1;
2249 preserve.marker = NULL;
2250 bfd_seek (abfd, 0, SEEK_SET);
2251 if (bfd_sym_read_version (abfd, &version) != 0)
2252 goto wrong;
2254 preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
2255 if (preserve.marker == NULL
2256 || ! bfd_preserve_save (abfd, &preserve))
2257 goto fail;
2259 if (bfd_sym_scan (abfd, version,
2260 (bfd_sym_data_struct *) preserve.marker) != 0)
2261 goto wrong;
2263 bfd_preserve_finish (abfd, &preserve);
2264 return abfd->xvec;
2266 wrong:
2267 bfd_set_error (bfd_error_wrong_format);
2269 fail:
2270 if (preserve.marker != NULL)
2271 bfd_preserve_restore (abfd, &preserve);
2272 return NULL;
2275 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2277 void
2278 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2280 bfd_symbol_info (symbol, ret);
2283 long
2284 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2286 return 0;
2289 long
2290 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2292 return 0;
2296 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2297 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2299 return 0;
2302 const bfd_target sym_vec =
2304 "sym", /* Name. */
2305 bfd_target_sym_flavour, /* Flavour. */
2306 BFD_ENDIAN_BIG, /* Byteorder. */
2307 BFD_ENDIAN_BIG, /* Header byteorder. */
2308 (HAS_RELOC | EXEC_P | /* Object flags. */
2309 HAS_LINENO | HAS_DEBUG |
2310 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2311 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2312 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2313 0, /* Symbol_leading_char. */
2314 ' ', /* AR_pad_char. */
2315 16, /* AR_max_namelen. */
2316 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2317 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2318 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2319 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2320 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2321 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2322 { /* bfd_check_format. */
2323 _bfd_dummy_target,
2324 bfd_sym_object_p, /* bfd_check_format. */
2325 _bfd_dummy_target,
2326 _bfd_dummy_target,
2328 { /* bfd_set_format. */
2329 bfd_false,
2330 bfd_sym_mkobject,
2331 bfd_false,
2332 bfd_false,
2334 { /* bfd_write_contents. */
2335 bfd_false,
2336 bfd_true,
2337 bfd_false,
2338 bfd_false,
2341 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2342 BFD_JUMP_TABLE_COPY (_bfd_generic),
2343 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2344 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2345 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2346 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2347 BFD_JUMP_TABLE_WRITE (bfd_sym),
2348 BFD_JUMP_TABLE_LINK (bfd_sym),
2349 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2351 NULL,
2353 NULL