* tls.m4 (GCC_CHECK_TLS): Rename have_tls to gcc_cv_have_tls.
[binutils.git] / bfd / xsym.c
blob49a1d60755df67355a13d39f0c49e4b1e52170e4
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 3 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,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "xsym.h"
24 #include "bfd.h"
25 #include "libbfd.h"
27 #define bfd_sym_close_and_cleanup _bfd_generic_close_and_cleanup
28 #define bfd_sym_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
29 #define bfd_sym_new_section_hook _bfd_generic_new_section_hook
30 #define bfd_sym_bfd_is_local_label_name bfd_generic_is_local_label_name
31 #define bfd_sym_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
32 #define bfd_sym_get_lineno _bfd_nosymbols_get_lineno
33 #define bfd_sym_find_nearest_line _bfd_nosymbols_find_nearest_line
34 #define bfd_sym_find_inliner_info _bfd_nosymbols_find_inliner_info
35 #define bfd_sym_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
36 #define bfd_sym_read_minisymbols _bfd_generic_read_minisymbols
37 #define bfd_sym_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
38 #define bfd_sym_set_arch_mach _bfd_generic_set_arch_mach
39 #define bfd_sym_get_section_contents _bfd_generic_get_section_contents
40 #define bfd_sym_set_section_contents _bfd_generic_set_section_contents
41 #define bfd_sym_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
42 #define bfd_sym_bfd_relax_section bfd_generic_relax_section
43 #define bfd_sym_bfd_gc_sections bfd_generic_gc_sections
44 #define bfd_sym_bfd_merge_sections bfd_generic_merge_sections
45 #define bfd_sym_bfd_is_group_section bfd_generic_is_group_section
46 #define bfd_sym_bfd_discard_group bfd_generic_discard_group
47 #define bfd_sym_section_already_linked _bfd_generic_section_already_linked
48 #define bfd_sym_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
49 #define bfd_sym_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
50 #define bfd_sym_bfd_link_add_symbols _bfd_generic_link_add_symbols
51 #define bfd_sym_bfd_link_just_syms _bfd_generic_link_just_syms
52 #define bfd_sym_bfd_final_link _bfd_generic_final_link
53 #define bfd_sym_bfd_link_split_section _bfd_generic_link_split_section
54 #define bfd_sym_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
56 extern const bfd_target sym_vec;
58 static int
59 pstrcmp (const char *as, const char *bs)
61 const unsigned char *a = (const unsigned char *) as;
62 const unsigned char *b = (const unsigned char *) bs;
63 unsigned char clen;
64 int ret;
66 clen = (a[0] > b[0]) ? b[0] : a[0];
67 ret = memcmp (a + 1, b + 1, clen);
68 if (ret != 0)
69 return ret;
71 if (a[0] == b[0])
72 return 0;
73 else if (a[0] < b[0])
74 return -1;
75 else
76 return 1;
79 static unsigned long
80 compute_offset (unsigned long first_page,
81 unsigned long page_size,
82 unsigned long entry_size,
83 unsigned long index)
85 unsigned long entries_per_page = page_size / entry_size;
86 unsigned long page_number = first_page + (index / entries_per_page);
87 unsigned long page_offset = (index % entries_per_page) * entry_size;
89 return (page_number * page_size) + page_offset;
92 bfd_boolean
93 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
95 return 1;
98 void
99 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
100 void * afile ATTRIBUTE_UNUSED,
101 asymbol *symbol ATTRIBUTE_UNUSED,
102 bfd_print_symbol_type how ATTRIBUTE_UNUSED)
104 return;
107 bfd_boolean
108 bfd_sym_valid (bfd *abfd)
110 if (abfd == NULL || abfd->xvec == NULL)
111 return 0;
113 return abfd->xvec == &sym_vec;
116 unsigned char *
117 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
119 unsigned char *rstr;
120 long ret;
121 size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
122 size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
124 rstr = bfd_alloc (abfd, table_size);
125 if (rstr == NULL)
126 return rstr;
128 bfd_seek (abfd, table_offset, SEEK_SET);
129 ret = bfd_bread (rstr, table_size, abfd);
130 if (ret < 0 || (unsigned long) ret != table_size)
132 bfd_release (abfd, rstr);
133 return NULL;
136 return rstr;
139 void
140 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
141 size_t len,
142 bfd_sym_file_reference *entry)
144 BFD_ASSERT (len == 6);
146 entry->fref_frte_index = bfd_getb16 (buf);
147 entry->fref_offset = bfd_getb32 (buf + 2);
150 void
151 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
152 size_t len,
153 bfd_sym_table_info *table)
155 BFD_ASSERT (len == 8);
157 table->dti_first_page = bfd_getb16 (buf);
158 table->dti_page_count = bfd_getb16 (buf + 2);
159 table->dti_object_count = bfd_getb32 (buf + 4);
162 void
163 bfd_sym_parse_header_v32 (unsigned char *buf,
164 size_t len,
165 bfd_sym_header_block *header)
167 BFD_ASSERT (len == 154);
169 memcpy (header->dshb_id, buf, 32);
170 header->dshb_page_size = bfd_getb16 (buf + 32);
171 header->dshb_hash_page = bfd_getb16 (buf + 34);
172 header->dshb_root_mte = bfd_getb16 (buf + 36);
173 header->dshb_mod_date = bfd_getb32 (buf + 38);
175 bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
176 bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
177 bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
178 bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
179 bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
180 bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
181 bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
182 bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
183 bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
184 bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
185 bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
186 bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
187 bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
189 memcpy (&header->dshb_file_creator, buf + 146, 4);
190 memcpy (&header->dshb_file_type, buf + 150, 4);
194 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
196 unsigned char buf[154];
197 long ret;
199 ret = bfd_bread (buf, 154, abfd);
200 if (ret != 154)
201 return -1;
203 bfd_sym_parse_header_v32 (buf, 154, header);
205 return 0;
209 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
210 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
212 abort ();
216 bfd_sym_read_header (bfd *abfd,
217 bfd_sym_header_block *header,
218 bfd_sym_version version)
220 switch (version)
222 case BFD_SYM_VERSION_3_5:
223 case BFD_SYM_VERSION_3_4:
224 return bfd_sym_read_header_v34 (abfd, header);
225 case BFD_SYM_VERSION_3_3:
226 case BFD_SYM_VERSION_3_2:
227 return bfd_sym_read_header_v32 (abfd, header);
228 case BFD_SYM_VERSION_3_1:
229 default:
230 return 0;
235 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
237 char version_string[32];
238 long ret;
240 ret = bfd_bread (version_string, sizeof (version_string), abfd);
241 if (ret != sizeof (version_string))
242 return -1;
244 if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
245 *version = BFD_SYM_VERSION_3_1;
246 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
247 *version = BFD_SYM_VERSION_3_2;
248 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
249 *version = BFD_SYM_VERSION_3_3;
250 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
251 *version = BFD_SYM_VERSION_3_4;
252 else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
253 *version = BFD_SYM_VERSION_3_5;
254 else
255 return -1;
257 return 0;
260 void
261 bfd_sym_display_table_summary (FILE *f,
262 bfd_sym_table_info *dti,
263 const char *name)
265 fprintf (f, "%-6s %13ld %13ld %13ld\n",
266 name,
267 dti->dti_first_page,
268 dti->dti_page_count,
269 dti->dti_object_count);
272 void
273 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
275 fprintf (f, " Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
276 fprintf (f, " Page Size: 0x%x\n", dshb->dshb_page_size);
277 fprintf (f, " Hash Page: %lu\n", dshb->dshb_hash_page);
278 fprintf (f, " Root MTE: %lu\n", dshb->dshb_root_mte);
279 fprintf (f, " Modification Date: ");
280 fprintf (f, "[unimplemented]");
281 fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
283 fprintf (f, " File Creator: %.4s Type: %.4s\n\n",
284 dshb->dshb_file_creator, dshb->dshb_file_type);
286 fprintf (f, "Table Name First Page Page Count Object Count\n");
287 fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
289 bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
290 bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
291 bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
292 bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
293 bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
294 bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
295 bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
296 bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
297 bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
298 bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
299 bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
300 bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
301 bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
303 fprintf (f, "\n");
306 void
307 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
308 size_t len,
309 bfd_sym_resources_table_entry *entry)
311 BFD_ASSERT (len == 18);
313 memcpy (&entry->rte_res_type, buf, 4);
314 entry->rte_res_number = bfd_getb16 (buf + 4);
315 entry->rte_nte_index = bfd_getb32 (buf + 6);
316 entry->rte_mte_first = bfd_getb16 (buf + 10);
317 entry->rte_mte_last = bfd_getb16 (buf + 12);
318 entry->rte_res_size = bfd_getb32 (buf + 14);
321 void
322 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
323 size_t len,
324 bfd_sym_modules_table_entry *entry)
326 BFD_ASSERT (len == 46);
328 entry->mte_rte_index = bfd_getb16 (buf);
329 entry->mte_res_offset = bfd_getb32 (buf + 2);
330 entry->mte_size = bfd_getb32 (buf + 6);
331 entry->mte_kind = buf[10];
332 entry->mte_scope = buf[11];
333 entry->mte_parent = bfd_getb16 (buf + 12);
334 bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
335 entry->mte_imp_end = bfd_getb32 (buf + 20);
336 entry->mte_nte_index = bfd_getb32 (buf + 24);
337 entry->mte_cmte_index = bfd_getb16 (buf + 28);
338 entry->mte_cvte_index = bfd_getb32 (buf + 30);
339 entry->mte_clte_index = bfd_getb16 (buf + 34);
340 entry->mte_ctte_index = bfd_getb16 (buf + 36);
341 entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
342 entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
345 void
346 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
347 size_t len,
348 bfd_sym_file_references_table_entry *entry)
350 unsigned int type;
352 BFD_ASSERT (len == 10);
354 memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
355 type = bfd_getb16 (buf);
357 switch (type)
359 case BFD_SYM_END_OF_LIST_3_2:
360 entry->generic.type = BFD_SYM_END_OF_LIST;
361 break;
363 case BFD_SYM_FILE_NAME_INDEX_3_2:
364 entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
365 entry->filename.nte_index = bfd_getb32 (buf + 2);
366 entry->filename.mod_date = bfd_getb32 (buf + 6);
367 break;
369 default:
370 entry->entry.mte_index = type;
371 entry->entry.file_offset = bfd_getb32 (buf + 2);
375 void
376 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
377 size_t len,
378 bfd_sym_contained_modules_table_entry *entry)
380 unsigned int type;
382 BFD_ASSERT (len == 6);
384 memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
385 type = bfd_getb16 (buf);
387 switch (type)
389 case BFD_SYM_END_OF_LIST_3_2:
390 entry->generic.type = BFD_SYM_END_OF_LIST;
391 break;
393 default:
394 entry->entry.mte_index = type;
395 entry->entry.nte_index = bfd_getb32 (buf + 2);
396 break;
400 void
401 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
402 size_t len,
403 bfd_sym_contained_variables_table_entry *entry)
405 unsigned int type;
407 BFD_ASSERT (len == 26);
409 memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
410 type = bfd_getb16 (buf);
412 switch (type)
414 case BFD_SYM_END_OF_LIST_3_2:
415 entry->generic.type = BFD_SYM_END_OF_LIST;
416 break;
418 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
419 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
420 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
421 break;
423 default:
424 entry->entry.tte_index = type;
425 entry->entry.nte_index = bfd_getb32 (buf + 2);
426 entry->entry.file_delta = bfd_getb16 (buf + 6);
427 entry->entry.scope = buf[8];
428 entry->entry.la_size = buf[9];
430 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
432 entry->entry.address.scstruct.sca_kind = buf[10];
433 entry->entry.address.scstruct.sca_class = buf[11];
434 entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
436 else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
438 #if BFD_SYM_CVTE_SCA > 0
439 memcpy (&entry->entry.address.lastruct.la, buf + 10,
440 BFD_SYM_CVTE_SCA);
441 #endif
442 entry->entry.address.lastruct.la_kind = buf[23];
444 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
446 entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
447 entry->entry.address.biglastruct.big_la_kind = buf[12];
452 void
453 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
454 size_t len,
455 bfd_sym_contained_statements_table_entry *entry)
457 unsigned int type;
459 BFD_ASSERT (len == 8);
461 memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
462 type = bfd_getb16 (buf);
464 switch (type)
466 case BFD_SYM_END_OF_LIST_3_2:
467 entry->generic.type = BFD_SYM_END_OF_LIST;
468 break;
470 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
471 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
472 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
473 break;
475 default:
476 entry->entry.mte_index = type;
477 entry->entry.mte_offset = bfd_getb16 (buf + 2);
478 entry->entry.file_delta = bfd_getb32 (buf + 4);
479 break;
483 void
484 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
485 size_t len,
486 bfd_sym_contained_labels_table_entry *entry)
488 unsigned int type;
490 BFD_ASSERT (len == 12);
492 memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
493 type = bfd_getb16 (buf);
495 switch (type)
497 case BFD_SYM_END_OF_LIST_3_2:
498 entry->generic.type = BFD_SYM_END_OF_LIST;
499 break;
501 case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
502 entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
503 bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
504 break;
506 default:
507 entry->entry.mte_index = type;
508 entry->entry.mte_offset = bfd_getb16 (buf + 2);
509 entry->entry.nte_index = bfd_getb32 (buf + 4);
510 entry->entry.file_delta = bfd_getb16 (buf + 8);
511 entry->entry.scope = bfd_getb16 (buf + 10);
512 break;
516 void
517 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
518 size_t len,
519 bfd_sym_type_table_entry *entry)
521 BFD_ASSERT (len == 4);
523 *entry = bfd_getb32 (buf);
527 bfd_sym_fetch_resources_table_entry (bfd *abfd,
528 bfd_sym_resources_table_entry *entry,
529 unsigned long index)
531 void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
532 unsigned long offset;
533 unsigned long entry_size;
534 unsigned char buf[18];
535 bfd_sym_data_struct *sdata = NULL;
537 parser = NULL;
538 BFD_ASSERT (bfd_sym_valid (abfd));
539 sdata = abfd->tdata.sym_data;
541 if (index == 0)
542 return -1;
544 switch (sdata->version)
546 case BFD_SYM_VERSION_3_5:
547 case BFD_SYM_VERSION_3_4:
548 return -1;
550 case BFD_SYM_VERSION_3_3:
551 case BFD_SYM_VERSION_3_2:
552 entry_size = 18;
553 parser = bfd_sym_parse_resources_table_entry_v32;
554 break;
556 case BFD_SYM_VERSION_3_1:
557 default:
558 return -1;
560 if (parser == NULL)
561 return -1;
563 offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
564 sdata->header.dshb_page_size,
565 entry_size, index);
567 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
568 return -1;
569 if (bfd_bread (buf, entry_size, abfd) != entry_size)
570 return -1;
572 (*parser) (buf, entry_size, entry);
574 return 0;
578 bfd_sym_fetch_modules_table_entry (bfd *abfd,
579 bfd_sym_modules_table_entry *entry,
580 unsigned long index)
582 void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
583 unsigned long offset;
584 unsigned long entry_size;
585 unsigned char buf[46];
586 bfd_sym_data_struct *sdata = NULL;
588 parser = NULL;
589 BFD_ASSERT (bfd_sym_valid (abfd));
590 sdata = abfd->tdata.sym_data;
592 if (index == 0)
593 return -1;
595 switch (sdata->version)
597 case BFD_SYM_VERSION_3_5:
598 case BFD_SYM_VERSION_3_4:
599 return -1;
601 case BFD_SYM_VERSION_3_3:
602 entry_size = 46;
603 parser = bfd_sym_parse_modules_table_entry_v33;
604 break;
606 case BFD_SYM_VERSION_3_2:
607 case BFD_SYM_VERSION_3_1:
608 default:
609 return -1;
611 if (parser == NULL)
612 return -1;
614 offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
615 sdata->header.dshb_page_size,
616 entry_size, index);
618 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
619 return -1;
620 if (bfd_bread (buf, entry_size, abfd) != entry_size)
621 return -1;
623 (*parser) (buf, entry_size, entry);
625 return 0;
629 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
630 bfd_sym_file_references_table_entry *entry,
631 unsigned long index)
633 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
634 unsigned long offset;
635 unsigned long entry_size = 0;
636 unsigned char buf[8];
637 bfd_sym_data_struct *sdata = NULL;
639 parser = NULL;
640 BFD_ASSERT (bfd_sym_valid (abfd));
641 sdata = abfd->tdata.sym_data;
643 if (index == 0)
644 return -1;
646 switch (sdata->version)
648 case BFD_SYM_VERSION_3_3:
649 case BFD_SYM_VERSION_3_2:
650 entry_size = 10;
651 parser = bfd_sym_parse_file_references_table_entry_v32;
652 break;
654 case BFD_SYM_VERSION_3_5:
655 case BFD_SYM_VERSION_3_4:
656 case BFD_SYM_VERSION_3_1:
657 default:
658 break;
661 if (parser == NULL)
662 return -1;
664 offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
665 sdata->header.dshb_page_size,
666 entry_size, index);
668 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
669 return -1;
670 if (bfd_bread (buf, entry_size, abfd) != entry_size)
671 return -1;
673 (*parser) (buf, entry_size, entry);
675 return 0;
679 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
680 bfd_sym_contained_modules_table_entry *entry,
681 unsigned long index)
683 void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
684 unsigned long offset;
685 unsigned long entry_size = 0;
686 unsigned char buf[6];
687 bfd_sym_data_struct *sdata = NULL;
689 parser = NULL;
690 BFD_ASSERT (bfd_sym_valid (abfd));
691 sdata = abfd->tdata.sym_data;
693 if (index == 0)
694 return -1;
696 switch (sdata->version)
698 case BFD_SYM_VERSION_3_3:
699 case BFD_SYM_VERSION_3_2:
700 entry_size = 6;
701 parser = bfd_sym_parse_contained_modules_table_entry_v32;
702 break;
704 case BFD_SYM_VERSION_3_5:
705 case BFD_SYM_VERSION_3_4:
706 case BFD_SYM_VERSION_3_1:
707 default:
708 break;
711 if (parser == NULL)
712 return -1;
714 offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
715 sdata->header.dshb_page_size,
716 entry_size, index);
718 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
719 return -1;
720 if (bfd_bread (buf, entry_size, abfd) != entry_size)
721 return -1;
723 (*parser) (buf, entry_size, entry);
725 return 0;
729 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
730 bfd_sym_contained_variables_table_entry *entry,
731 unsigned long index)
733 void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
734 unsigned long offset;
735 unsigned long entry_size = 0;
736 unsigned char buf[26];
737 bfd_sym_data_struct *sdata = NULL;
739 parser = NULL;
740 BFD_ASSERT (bfd_sym_valid (abfd));
741 sdata = abfd->tdata.sym_data;
743 if (index == 0)
744 return -1;
746 switch (sdata->version)
748 case BFD_SYM_VERSION_3_3:
749 case BFD_SYM_VERSION_3_2:
750 entry_size = 26;
751 parser = bfd_sym_parse_contained_variables_table_entry_v32;
752 break;
754 case BFD_SYM_VERSION_3_5:
755 case BFD_SYM_VERSION_3_4:
756 case BFD_SYM_VERSION_3_1:
757 default:
758 break;
761 if (parser == NULL)
762 return -1;
764 offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
765 sdata->header.dshb_page_size,
766 entry_size, index);
768 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
769 return -1;
770 if (bfd_bread (buf, entry_size, abfd) != entry_size)
771 return -1;
773 (*parser) (buf, entry_size, entry);
775 return 0;
779 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
780 bfd_sym_contained_statements_table_entry *entry,
781 unsigned long index)
783 void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
784 unsigned long offset;
785 unsigned long entry_size = 0;
786 unsigned char buf[8];
787 bfd_sym_data_struct *sdata = NULL;
789 parser = NULL;
790 BFD_ASSERT (bfd_sym_valid (abfd));
791 sdata = abfd->tdata.sym_data;
793 if (index == 0)
794 return -1;
796 switch (sdata->version)
798 case BFD_SYM_VERSION_3_3:
799 case BFD_SYM_VERSION_3_2:
800 entry_size = 8;
801 parser = bfd_sym_parse_contained_statements_table_entry_v32;
802 break;
804 case BFD_SYM_VERSION_3_5:
805 case BFD_SYM_VERSION_3_4:
806 case BFD_SYM_VERSION_3_1:
807 default:
808 break;
811 if (parser == NULL)
812 return -1;
814 offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
815 sdata->header.dshb_page_size,
816 entry_size, index);
818 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
819 return -1;
820 if (bfd_bread (buf, entry_size, abfd) != entry_size)
821 return -1;
823 (*parser) (buf, entry_size, entry);
825 return 0;
829 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
830 bfd_sym_contained_labels_table_entry *entry,
831 unsigned long index)
833 void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
834 unsigned long offset;
835 unsigned long entry_size = 0;
836 unsigned char buf[12];
837 bfd_sym_data_struct *sdata = NULL;
839 parser = NULL;
840 BFD_ASSERT (bfd_sym_valid (abfd));
841 sdata = abfd->tdata.sym_data;
843 if (index == 0)
844 return -1;
846 switch (sdata->version)
848 case BFD_SYM_VERSION_3_3:
849 case BFD_SYM_VERSION_3_2:
850 entry_size = 12;
851 parser = bfd_sym_parse_contained_labels_table_entry_v32;
852 break;
854 case BFD_SYM_VERSION_3_5:
855 case BFD_SYM_VERSION_3_4:
856 case BFD_SYM_VERSION_3_1:
857 default:
858 break;
861 if (parser == NULL)
862 return -1;
864 offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
865 sdata->header.dshb_page_size,
866 entry_size, index);
868 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
869 return -1;
870 if (bfd_bread (buf, entry_size, abfd) != entry_size)
871 return -1;
873 (*parser) (buf, entry_size, entry);
875 return 0;
879 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
880 bfd_sym_contained_types_table_entry *entry,
881 unsigned long index)
883 void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
884 unsigned long offset;
885 unsigned long entry_size = 0;
886 unsigned char buf[0];
887 bfd_sym_data_struct *sdata = NULL;
889 parser = NULL;
890 BFD_ASSERT (bfd_sym_valid (abfd));
891 sdata = abfd->tdata.sym_data;
893 if (index == 0)
894 return -1;
896 switch (sdata->version)
898 case BFD_SYM_VERSION_3_3:
899 case BFD_SYM_VERSION_3_2:
900 entry_size = 0;
901 parser = NULL;
902 break;
904 case BFD_SYM_VERSION_3_5:
905 case BFD_SYM_VERSION_3_4:
906 case BFD_SYM_VERSION_3_1:
907 default:
908 break;
911 if (parser == NULL)
912 return -1;
914 offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
915 sdata->header.dshb_page_size,
916 entry_size, index);
918 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
919 return -1;
920 if (bfd_bread (buf, entry_size, abfd) != entry_size)
921 return -1;
923 (*parser) (buf, entry_size, entry);
925 return 0;
929 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
930 bfd_sym_file_references_index_table_entry *entry,
931 unsigned long index)
933 void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
934 unsigned long offset;
935 unsigned long entry_size = 0;
936 unsigned char buf[0];
937 bfd_sym_data_struct *sdata = NULL;
939 parser = NULL;
940 BFD_ASSERT (bfd_sym_valid (abfd));
941 sdata = abfd->tdata.sym_data;
943 if (index == 0)
944 return -1;
946 switch (sdata->version)
948 case BFD_SYM_VERSION_3_3:
949 case BFD_SYM_VERSION_3_2:
950 entry_size = 0;
951 parser = NULL;
952 break;
954 case BFD_SYM_VERSION_3_5:
955 case BFD_SYM_VERSION_3_4:
956 case BFD_SYM_VERSION_3_1:
957 default:
958 break;
961 if (parser == NULL)
962 return -1;
964 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
965 sdata->header.dshb_page_size,
966 entry_size, index);
968 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
969 return -1;
970 if (bfd_bread (buf, entry_size, abfd) != entry_size)
971 return -1;
973 (*parser) (buf, entry_size, entry);
975 return 0;
979 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
980 bfd_sym_constant_pool_entry *entry,
981 unsigned long index)
983 void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
984 unsigned long offset;
985 unsigned long entry_size = 0;
986 unsigned char buf[0];
987 bfd_sym_data_struct *sdata = NULL;
989 parser = NULL;
990 BFD_ASSERT (bfd_sym_valid (abfd));
991 sdata = abfd->tdata.sym_data;
993 if (index == 0)
994 return -1;
996 switch (sdata->version)
998 case BFD_SYM_VERSION_3_3:
999 case BFD_SYM_VERSION_3_2:
1000 entry_size = 0;
1001 parser = NULL;
1002 break;
1004 case BFD_SYM_VERSION_3_5:
1005 case BFD_SYM_VERSION_3_4:
1006 case BFD_SYM_VERSION_3_1:
1007 default:
1008 break;
1011 if (parser == NULL)
1012 return -1;
1014 offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1015 sdata->header.dshb_page_size,
1016 entry_size, index);
1018 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1019 return -1;
1020 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1021 return -1;
1023 (*parser) (buf, entry_size, entry);
1025 return 0;
1029 bfd_sym_fetch_type_table_entry (bfd *abfd,
1030 bfd_sym_type_table_entry *entry,
1031 unsigned long index)
1033 void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1034 unsigned long offset;
1035 unsigned long entry_size = 0;
1036 unsigned char buf[4];
1037 bfd_sym_data_struct *sdata = NULL;
1039 parser = NULL;
1040 BFD_ASSERT (bfd_sym_valid (abfd));
1041 sdata = abfd->tdata.sym_data;
1043 switch (sdata->version)
1045 case BFD_SYM_VERSION_3_3:
1046 case BFD_SYM_VERSION_3_2:
1047 entry_size = 4;
1048 parser = bfd_sym_parse_type_table_entry_v32;
1049 break;
1051 case BFD_SYM_VERSION_3_5:
1052 case BFD_SYM_VERSION_3_4:
1053 case BFD_SYM_VERSION_3_1:
1054 default:
1055 break;
1058 if (parser == NULL)
1059 return -1;
1061 offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1062 sdata->header.dshb_page_size,
1063 entry_size, index);
1065 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1066 return -1;
1067 if (bfd_bread (buf, entry_size, abfd) != entry_size)
1068 return -1;
1070 (*parser) (buf, entry_size, entry);
1072 return 0;
1076 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1077 bfd_sym_type_information_table_entry *entry,
1078 unsigned long offset)
1080 unsigned char buf[4];
1081 bfd_sym_data_struct *sdata = NULL;
1083 BFD_ASSERT (bfd_sym_valid (abfd));
1084 sdata = abfd->tdata.sym_data;
1086 if (offset == 0)
1087 return -1;
1089 if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1090 return -1;
1092 if (bfd_bread (buf, 4, abfd) != 4)
1093 return -1;
1094 entry->nte_index = bfd_getb32 (buf);
1096 if (bfd_bread (buf, 2, abfd) != 2)
1097 return -1;
1098 entry->physical_size = bfd_getb16 (buf);
1100 if (entry->physical_size & 0x8000)
1102 if (bfd_bread (buf, 4, abfd) != 4)
1103 return -1;
1104 entry->physical_size &= 0x7fff;
1105 entry->logical_size = bfd_getb32 (buf);
1106 entry->offset = offset + 10;
1108 else
1110 if (bfd_bread (buf, 2, abfd) != 2)
1111 return -1;
1112 entry->physical_size &= 0x7fff;
1113 entry->logical_size = bfd_getb16 (buf);
1114 entry->offset = offset + 8;
1117 return 0;
1121 bfd_sym_fetch_type_table_information (bfd *abfd,
1122 bfd_sym_type_information_table_entry *entry,
1123 unsigned long index)
1125 bfd_sym_type_table_entry tindex;
1126 bfd_sym_data_struct *sdata = NULL;
1128 BFD_ASSERT (bfd_sym_valid (abfd));
1129 sdata = abfd->tdata.sym_data;
1131 if (sdata->header.dshb_tte.dti_object_count <= 99)
1132 return -1;
1133 if (index < 100)
1134 return -1;
1136 if (bfd_sym_fetch_type_table_entry (abfd, &tindex, index - 100) < 0)
1137 return -1;
1138 if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1139 return -1;
1141 return 0;
1144 const unsigned char *
1145 bfd_sym_symbol_name (bfd *abfd, unsigned long index)
1147 bfd_sym_data_struct *sdata = NULL;
1149 BFD_ASSERT (bfd_sym_valid (abfd));
1150 sdata = abfd->tdata.sym_data;
1152 if (index == 0)
1153 return (const unsigned char *) "";
1155 index *= 2;
1156 if ((index / sdata->header.dshb_page_size)
1157 > sdata->header.dshb_nte.dti_page_count)
1158 return (const unsigned char *) "\09[INVALID]";
1160 return (const unsigned char *) sdata->name_table + index;
1163 const unsigned char *
1164 bfd_sym_module_name (bfd *abfd, unsigned long index)
1166 bfd_sym_modules_table_entry entry;
1168 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, index) < 0)
1169 return (const unsigned char *) "\09[INVALID]";
1171 return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1174 const char *
1175 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1177 switch (kind)
1179 case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1180 case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1181 case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1182 case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1183 default: return "[UNKNOWN]";
1187 const char *
1188 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1190 switch (kind)
1192 case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1193 case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1194 case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1195 case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1196 case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1197 case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1198 case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1199 case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1200 default: return "[UNKNOWN]";
1204 const char *
1205 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1207 switch (kind)
1209 case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1210 case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1211 case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1212 case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1213 case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1214 case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1215 case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1216 default: return "[UNKNOWN]";
1220 const char *
1221 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1223 switch (scope)
1225 case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1226 case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1227 default:
1228 return "[UNKNOWN]";
1232 void
1233 bfd_sym_print_file_reference (bfd *abfd,
1234 FILE *f,
1235 bfd_sym_file_reference *entry)
1237 bfd_sym_file_references_table_entry frtentry;
1238 int ret;
1240 ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1241 entry->fref_frte_index);
1242 fprintf (f, "FILE ");
1244 if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1245 fprintf (f, "[INVALID]");
1246 else
1247 fprintf (f, "\"%.*s\"",
1248 bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1249 &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1251 fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1254 void
1255 bfd_sym_print_resources_table_entry (bfd *abfd,
1256 FILE *f,
1257 bfd_sym_resources_table_entry *entry)
1259 fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1260 bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1261 &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1262 entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1263 entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1266 void
1267 bfd_sym_print_modules_table_entry (bfd *abfd,
1268 FILE *f,
1269 bfd_sym_modules_table_entry *entry)
1271 fprintf (f, "\"%.*s\" (NTE %lu)",
1272 bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1273 &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1274 entry->mte_nte_index);
1276 fprintf (f, "\n ");
1278 bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1279 fprintf (f, " range %lu -- %lu",
1280 entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1282 fprintf (f, "\n ");
1284 fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1285 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1287 fprintf (f, ", RTE %lu, offset %lu, size %lu",
1288 entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1290 fprintf (f, "\n ");
1292 fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1293 entry->mte_cmte_index, entry->mte_cvte_index,
1294 entry->mte_clte_index, entry->mte_ctte_index,
1295 entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1297 if (entry->mte_parent != 0)
1298 fprintf (f, ", parent %lu", entry->mte_parent);
1299 else
1300 fprintf (f, ", no parent");
1302 if (entry->mte_cmte_index != 0)
1303 fprintf (f, ", child %lu", entry->mte_cmte_index);
1304 else
1305 fprintf (f, ", no child");
1308 void
1309 bfd_sym_print_file_references_table_entry (bfd *abfd,
1310 FILE *f,
1311 bfd_sym_file_references_table_entry *entry)
1313 switch (entry->generic.type)
1315 case BFD_SYM_FILE_NAME_INDEX:
1316 fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1317 bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1318 &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1319 entry->filename.nte_index);
1321 fprintf (f, "[UNIMPLEMENTED]");
1322 /* printModDate (entry->filename.mod_date); */
1323 fprintf (f, " (0x%lx)", entry->filename.mod_date);
1324 break;
1326 case BFD_SYM_END_OF_LIST:
1327 fprintf (f, "END");
1328 break;
1330 default:
1331 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1332 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1333 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1334 entry->entry.mte_index,
1335 entry->entry.file_offset);
1336 break;
1340 void
1341 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1342 FILE *f,
1343 bfd_sym_contained_modules_table_entry *entry)
1345 switch (entry->generic.type)
1347 case BFD_SYM_END_OF_LIST:
1348 fprintf (f, "END");
1349 break;
1351 default:
1352 fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1353 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1354 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1355 entry->entry.mte_index,
1356 entry->entry.nte_index);
1357 break;
1361 void
1362 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1363 FILE *f,
1364 bfd_sym_contained_variables_table_entry *entry)
1366 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1368 fprintf (f, "END");
1369 return;
1372 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1374 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1375 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1376 return;
1379 fprintf (f, "\"%.*s\" (NTE %lu)",
1380 bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1381 &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1382 entry->entry.nte_index);
1384 fprintf (f, ", TTE %lu", entry->entry.tte_index);
1385 fprintf (f, ", offset %lu", entry->entry.file_delta);
1386 fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1388 if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1389 fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1390 bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1391 bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1392 entry->entry.address.scstruct.sca_offset);
1393 else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1395 unsigned long i;
1397 fprintf (f, ", la [");
1398 for (i = 0; i < entry->entry.la_size; i++)
1399 fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1400 fprintf (f, "]");
1402 else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1403 fprintf (f, ", bigla %lu, biglakind %u",
1404 entry->entry.address.biglastruct.big_la,
1405 entry->entry.address.biglastruct.big_la_kind);
1407 else
1408 fprintf (f, ", la [INVALID]");
1411 void
1412 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1413 FILE *f,
1414 bfd_sym_contained_statements_table_entry *entry)
1416 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1418 fprintf (f, "END");
1419 return;
1422 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1424 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1425 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1426 return;
1429 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1430 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1431 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1432 entry->entry.mte_index,
1433 entry->entry.mte_offset,
1434 entry->entry.file_delta);
1437 void
1438 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1439 FILE *f,
1440 bfd_sym_contained_labels_table_entry *entry)
1442 if (entry->generic.type == BFD_SYM_END_OF_LIST)
1444 fprintf (f, "END");
1445 return;
1448 if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1450 bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1451 fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1452 return;
1455 fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1456 bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1457 &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1458 entry->entry.mte_index,
1459 entry->entry.mte_offset,
1460 entry->entry.file_delta,
1461 bfd_sym_unparse_symbol_scope (entry->entry.scope));
1464 void
1465 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1466 FILE *f,
1467 bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1469 fprintf (f, "[UNIMPLEMENTED]");
1472 const char *
1473 bfd_sym_type_operator_name (unsigned char num)
1475 switch (num)
1477 case 1: return "TTE";
1478 case 2: return "PointerTo";
1479 case 3: return "ScalarOf";
1480 case 4: return "ConstantOf";
1481 case 5: return "EnumerationOf";
1482 case 6: return "VectorOf";
1483 case 7: return "RecordOf";
1484 case 8: return "UnionOf";
1485 case 9: return "SubRangeOf";
1486 case 10: return "SetOf";
1487 case 11: return "NamedTypeOf";
1488 case 12: return "ProcOf";
1489 case 13: return "ValueOf";
1490 case 14: return "ArrayOf";
1491 default: return "[UNKNOWN OPERATOR]";
1495 const char *
1496 bfd_sym_type_basic_name (unsigned char num)
1498 switch (num)
1500 case 0: return "void";
1501 case 1: return "pascal string";
1502 case 2: return "unsigned long";
1503 case 3: return "signed long";
1504 case 4: return "extended (10 bytes)";
1505 case 5: return "pascal boolean (1 byte)";
1506 case 6: return "unsigned byte";
1507 case 7: return "signed byte";
1508 case 8: return "character (1 byte)";
1509 case 9: return "wide character (2 bytes)";
1510 case 10: return "unsigned short";
1511 case 11: return "signed short";
1512 case 12: return "singled";
1513 case 13: return "double";
1514 case 14: return "extended (12 bytes)";
1515 case 15: return "computational (8 bytes)";
1516 case 16: return "c string";
1517 case 17: return "as-is string";
1518 default: return "[UNKNOWN BASIC TYPE]";
1523 bfd_sym_fetch_long (unsigned char *buf,
1524 unsigned long len,
1525 unsigned long offset,
1526 unsigned long *offsetptr,
1527 long *value)
1529 int ret;
1531 if (offset >= len)
1533 *value = 0;
1534 offset += 0;
1535 ret = -1;
1537 else if (! (buf[offset] & 0x80))
1539 *value = buf[offset];
1540 offset += 1;
1541 ret = 0;
1543 else if (buf[offset] == 0xc0)
1545 if ((offset + 5) > len)
1547 *value = 0;
1548 offset = len;
1549 ret = -1;
1551 else
1553 *value = bfd_getb32 (buf + offset + 1);
1554 offset += 5;
1555 ret = 0;
1558 else if ((buf[offset] & 0xc0) == 0xc0)
1560 *value = -(buf[offset] & 0x3f);
1561 offset += 1;
1562 ret = 0;
1564 else if ((buf[offset] & 0xc0) == 0x80)
1566 if ((offset + 2) > len)
1568 *value = 0;
1569 offset = len;
1570 ret = -1;
1572 else
1574 *value = bfd_getb16 (buf + offset) & 0x3fff;
1575 offset += 2;
1576 ret = 0;
1579 else
1580 abort ();
1582 if (offsetptr != NULL)
1583 *offsetptr = offset;
1585 return ret;
1588 void
1589 bfd_sym_print_type_information (bfd *abfd,
1590 FILE *f,
1591 unsigned char *buf,
1592 unsigned long len,
1593 unsigned long offset,
1594 unsigned long *offsetptr)
1596 unsigned int type;
1598 if (offset >= len)
1600 fprintf (f, "[NULL]");
1602 if (offsetptr != NULL)
1603 *offsetptr = offset;
1604 return;
1607 type = buf[offset];
1608 offset++;
1610 if (! (type & 0x80))
1612 fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1614 if (offsetptr != NULL)
1615 *offsetptr = offset;
1616 return;
1619 if (type & 0x40)
1620 fprintf (f, "[packed ");
1621 else
1622 fprintf (f, "[");
1624 switch (type & 0x3f)
1626 case 1:
1628 long value;
1629 bfd_sym_type_information_table_entry tinfo;
1631 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1632 if (value <= 0)
1633 fprintf (f, "[INVALID]");
1634 else
1636 if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1637 fprintf (f, "[INVALID]");
1638 else
1639 fprintf (f, "\"%.*s\"",
1640 bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1641 &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1643 fprintf (f, " (TTE %lu)", value);
1644 break;
1647 case 2:
1648 fprintf (f, "pointer (0x%x) to ", type);
1649 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1650 break;
1652 case 3:
1654 long value;
1656 fprintf (f, "scalar (0x%x) of ", type);
1657 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1658 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1659 fprintf (f, " (%lu)", (unsigned long) value);
1660 break;
1663 case 5:
1665 long lower, upper, nelem;
1666 int i;
1668 fprintf (f, "enumeration (0x%x) of ", type);
1669 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1670 bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1671 bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1672 bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1673 fprintf (f, " from %lu to %lu with %lu elements: ",
1674 (unsigned long) lower, (unsigned long) upper,
1675 (unsigned long) nelem);
1677 for (i = 0; i < nelem; i++)
1679 fprintf (f, "\n ");
1680 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1682 break;
1685 case 6:
1686 fprintf (f, "vector (0x%x)", type);
1687 fprintf (f, "\n index ");
1688 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1689 fprintf (f, "\n target ");
1690 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1691 break;
1693 case 7:
1694 case 8:
1696 long nrec, eloff, i;
1698 if ((type & 0x3f) == 7)
1699 fprintf (f, "record (0x%x) of ", type);
1700 else
1701 fprintf (f, "union (0x%x) of ", type);
1703 bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1704 fprintf (f, "%lu elements: ", nrec);
1706 for (i = 0; i < nrec; i++)
1708 bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1709 fprintf (f, "\n ");
1710 fprintf (f, "offset %lu: ", eloff);
1711 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1713 break;
1716 case 9:
1717 fprintf (f, "subrange (0x%x) of ", type);
1718 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1719 fprintf (f, " lower ");
1720 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1721 fprintf (f, " upper ");
1722 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1723 break;
1725 case 11:
1727 long value;
1729 fprintf (f, "named type (0x%x) ", type);
1730 bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1731 if (value <= 0)
1732 fprintf (f, "[INVALID]");
1733 else
1734 fprintf (f, "\"%.*s\"",
1735 bfd_sym_symbol_name (abfd, value)[0],
1736 &bfd_sym_symbol_name (abfd, value)[1]);
1738 fprintf (f, " (NTE %lu) with type ", value);
1739 bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1740 break;
1743 default:
1744 fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1745 break;
1748 if (type == (0x40 | 0x6))
1750 /* Vector. */
1751 long n, width, m;
1752 long l;
1753 long i;
1755 bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1756 bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1757 bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1758 /* fprintf (f, "\n "); */
1759 fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1760 for (i = 0; i < m; i++)
1762 bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1763 if (i != 0)
1764 fprintf (f, " ");
1765 fprintf (f, "%ld", l);
1768 else if (type & 0x40)
1770 /* Other packed type. */
1771 long msb, lsb;
1773 bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1774 bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1775 /* fprintf (f, "\n "); */
1776 fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1779 fprintf (f, "]");
1781 if (offsetptr != NULL)
1782 *offsetptr = offset;
1785 void
1786 bfd_sym_print_type_information_table_entry (bfd *abfd,
1787 FILE *f,
1788 bfd_sym_type_information_table_entry *entry)
1790 unsigned char *buf;
1791 unsigned long offset;
1792 unsigned int i;
1794 fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1795 bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1796 &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1797 entry->nte_index,
1798 entry->physical_size, entry->offset, entry->logical_size);
1800 fprintf (f, "\n ");
1802 buf = alloca (entry->physical_size);
1803 if (buf == NULL)
1805 fprintf (f, "[ERROR]\n");
1806 return;
1808 if (bfd_seek (abfd, entry->offset, SEEK_SET) < 0)
1810 fprintf (f, "[ERROR]\n");
1811 return;
1813 if (bfd_bread (buf, entry->physical_size, abfd) != entry->physical_size)
1815 fprintf (f, "[ERROR]\n");
1816 return;
1819 fprintf (f, "[");
1820 for (i = 0; i < entry->physical_size; i++)
1822 if (i == 0)
1823 fprintf (f, "0x%02x", buf[i]);
1824 else
1825 fprintf (f, " 0x%02x", buf[i]);
1828 fprintf (f, "]");
1829 fprintf (f, "\n ");
1831 bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1833 if (offset != entry->physical_size)
1834 fprintf (f, "\n [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1837 void
1838 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1839 FILE *f,
1840 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1842 fprintf (f, "[UNIMPLEMENTED]");
1845 void
1846 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1847 FILE *f,
1848 bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1850 fprintf (f, "[UNIMPLEMENTED]");
1853 unsigned char *
1854 bfd_sym_display_name_table_entry (bfd *abfd,
1855 FILE *f,
1856 unsigned char *entry)
1858 unsigned long index;
1859 unsigned long offset;
1860 bfd_sym_data_struct *sdata = NULL;
1862 BFD_ASSERT (bfd_sym_valid (abfd));
1863 sdata = abfd->tdata.sym_data;
1864 index = (entry - sdata->name_table) / 2;
1866 if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1868 unsigned short length = bfd_getb16 (entry + 2);
1869 fprintf (f, "[%8lu] \"%.*s\"\n", index, length, entry + 4);
1870 offset = 2 + length + 1;
1872 else
1874 if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1875 fprintf (f, "[%8lu] \"%.*s\"\n", index, entry[0], entry + 1);
1877 if (sdata->version >= BFD_SYM_VERSION_3_4)
1878 offset = entry[0] + 2;
1879 else
1880 offset = entry[0] + 1;
1883 return (entry + offset + (offset % 2));
1886 void
1887 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1889 unsigned long name_table_len;
1890 unsigned char *name_table, *name_table_end, *cur;
1891 bfd_sym_data_struct *sdata = NULL;
1893 BFD_ASSERT (bfd_sym_valid (abfd));
1894 sdata = abfd->tdata.sym_data;
1896 name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1897 name_table = sdata->name_table;
1898 name_table_end = name_table + name_table_len;
1900 fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1902 cur = name_table;
1903 for (;;)
1905 cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1906 if (cur >= name_table_end)
1907 break;
1911 void
1912 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1914 unsigned long i;
1915 bfd_sym_resources_table_entry entry;
1916 bfd_sym_data_struct *sdata = NULL;
1918 BFD_ASSERT (bfd_sym_valid (abfd));
1919 sdata = abfd->tdata.sym_data;
1921 fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1922 sdata->header.dshb_rte.dti_object_count);
1924 for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1926 if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1927 fprintf (f, " [%8lu] [INVALID]\n", i);
1928 else
1930 fprintf (f, " [%8lu] ", i);
1931 bfd_sym_print_resources_table_entry (abfd, f, &entry);
1932 fprintf (f, "\n");
1937 void
1938 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1940 unsigned long i;
1941 bfd_sym_modules_table_entry entry;
1942 bfd_sym_data_struct *sdata = NULL;
1944 BFD_ASSERT (bfd_sym_valid (abfd));
1945 sdata = abfd->tdata.sym_data;
1947 fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1948 sdata->header.dshb_mte.dti_object_count);
1950 for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1952 if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1953 fprintf (f, " [%8lu] [INVALID]\n", i);
1954 else
1956 fprintf (f, " [%8lu] ", i);
1957 bfd_sym_print_modules_table_entry (abfd, f, &entry);
1958 fprintf (f, "\n");
1963 void
1964 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1966 unsigned long i;
1967 bfd_sym_file_references_table_entry entry;
1968 bfd_sym_data_struct *sdata = NULL;
1970 BFD_ASSERT (bfd_sym_valid (abfd));
1971 sdata = abfd->tdata.sym_data;
1973 fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1974 sdata->header.dshb_frte.dti_object_count);
1976 for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1978 if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1979 fprintf (f, " [%8lu] [INVALID]\n", i);
1980 else
1982 fprintf (f, " [%8lu] ", i);
1983 bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1984 fprintf (f, "\n");
1989 void
1990 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
1992 unsigned long i;
1993 bfd_sym_contained_modules_table_entry entry;
1994 bfd_sym_data_struct *sdata = NULL;
1996 BFD_ASSERT (bfd_sym_valid (abfd));
1997 sdata = abfd->tdata.sym_data;
1999 fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
2000 sdata->header.dshb_cmte.dti_object_count);
2002 for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
2004 if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
2005 fprintf (f, " [%8lu] [INVALID]\n", i);
2006 else
2008 fprintf (f, " [%8lu] ", i);
2009 bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
2010 fprintf (f, "\n");
2015 void
2016 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2018 unsigned long i;
2019 bfd_sym_contained_variables_table_entry entry;
2020 bfd_sym_data_struct *sdata = NULL;
2022 BFD_ASSERT (bfd_sym_valid (abfd));
2023 sdata = abfd->tdata.sym_data;
2025 fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2026 sdata->header.dshb_cvte.dti_object_count);
2028 for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2030 if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2031 fprintf (f, " [%8lu] [INVALID]\n", i);
2032 else
2034 fprintf (f, " [%8lu] ", i);
2035 bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2036 fprintf (f, "\n");
2040 fprintf (f, "\n");
2043 void
2044 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2046 unsigned long i;
2047 bfd_sym_contained_statements_table_entry entry;
2048 bfd_sym_data_struct *sdata = NULL;
2050 BFD_ASSERT (bfd_sym_valid (abfd));
2051 sdata = abfd->tdata.sym_data;
2053 fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2054 sdata->header.dshb_csnte.dti_object_count);
2056 for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2058 if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2059 fprintf (f, " [%8lu] [INVALID]\n", i);
2060 else
2062 fprintf (f, " [%8lu] ", i);
2063 bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2064 fprintf (f, "\n");
2069 void
2070 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2072 unsigned long i;
2073 bfd_sym_contained_labels_table_entry entry;
2074 bfd_sym_data_struct *sdata = NULL;
2076 BFD_ASSERT (bfd_sym_valid (abfd));
2077 sdata = abfd->tdata.sym_data;
2079 fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2080 sdata->header.dshb_clte.dti_object_count);
2082 for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2084 if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2085 fprintf (f, " [%8lu] [INVALID]\n", i);
2086 else
2088 fprintf (f, " [%8lu] ", i);
2089 bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2090 fprintf (f, "\n");
2095 void
2096 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2098 unsigned long i;
2099 bfd_sym_contained_types_table_entry entry;
2100 bfd_sym_data_struct *sdata = NULL;
2102 BFD_ASSERT (bfd_sym_valid (abfd));
2103 sdata = abfd->tdata.sym_data;
2105 fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2106 sdata->header.dshb_ctte.dti_object_count);
2108 for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2110 if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2111 fprintf (f, " [%8lu] [INVALID]\n", i);
2112 else
2114 fprintf (f, " [%8lu] ", i);
2115 bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2116 fprintf (f, "\n");
2121 void
2122 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2124 unsigned long i;
2125 bfd_sym_file_references_index_table_entry entry;
2126 bfd_sym_data_struct *sdata = NULL;
2128 BFD_ASSERT (bfd_sym_valid (abfd));
2129 sdata = abfd->tdata.sym_data;
2131 fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2132 sdata->header.dshb_fite.dti_object_count);
2134 for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2136 if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2137 fprintf (f, " [%8lu] [INVALID]\n", i);
2138 else
2140 fprintf (f, " [%8lu] ", i);
2141 bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2142 fprintf (f, "\n");
2147 void
2148 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2150 unsigned long i;
2151 bfd_sym_constant_pool_entry entry;
2152 bfd_sym_data_struct *sdata = NULL;
2154 BFD_ASSERT (bfd_sym_valid (abfd));
2155 sdata = abfd->tdata.sym_data;
2157 fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2158 sdata->header.dshb_const.dti_object_count);
2160 for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2162 if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2163 fprintf (f, " [%8lu] [INVALID]\n", i);
2164 else
2166 fprintf (f, " [%8lu] ", i);
2167 bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2168 fprintf (f, "\n");
2173 void
2174 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2176 unsigned long i;
2177 bfd_sym_type_table_entry index;
2178 bfd_sym_type_information_table_entry entry;
2179 bfd_sym_data_struct *sdata = NULL;
2181 BFD_ASSERT (bfd_sym_valid (abfd));
2182 sdata = abfd->tdata.sym_data;
2184 if (sdata->header.dshb_tte.dti_object_count > 99)
2185 fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2186 sdata->header.dshb_tte.dti_object_count - 99);
2187 else
2189 fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2190 return;
2193 for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2195 if (bfd_sym_fetch_type_table_entry (abfd, &index, i - 100) < 0)
2196 fprintf (f, " [%8lu] [INVALID]\n", i);
2197 else
2199 fprintf (f, " [%8lu] (TINFO %lu) ", i, index);
2201 if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, index) < 0)
2202 fprintf (f, "[INVALID]");
2203 else
2204 bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2206 fprintf (f, "\n");
2212 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2214 asection *bfdsec;
2215 const char *name = "symbols";
2217 mdata->name_table = 0;
2218 mdata->sbfd = abfd;
2219 mdata->version = version;
2221 bfd_seek (abfd, 0, SEEK_SET);
2222 if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2223 return -1;
2225 mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2226 if (mdata->name_table == NULL)
2227 return -1;
2229 bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2230 if (bfdsec == NULL)
2231 return -1;
2233 bfdsec->vma = 0;
2234 bfdsec->lma = 0;
2235 bfdsec->size = 0;
2236 bfdsec->filepos = 0;
2237 bfdsec->alignment_power = 0;
2239 abfd->tdata.sym_data = mdata;
2241 return 0;
2244 const bfd_target *
2245 bfd_sym_object_p (bfd *abfd)
2247 struct bfd_preserve preserve;
2248 bfd_sym_version version = -1;
2250 preserve.marker = NULL;
2251 bfd_seek (abfd, 0, SEEK_SET);
2252 if (bfd_sym_read_version (abfd, &version) != 0)
2253 goto wrong;
2255 preserve.marker = bfd_alloc (abfd, sizeof (bfd_sym_data_struct));
2256 if (preserve.marker == NULL
2257 || ! bfd_preserve_save (abfd, &preserve))
2258 goto fail;
2260 if (bfd_sym_scan (abfd, version,
2261 (bfd_sym_data_struct *) preserve.marker) != 0)
2262 goto wrong;
2264 bfd_preserve_finish (abfd, &preserve);
2265 return abfd->xvec;
2267 wrong:
2268 bfd_set_error (bfd_error_wrong_format);
2270 fail:
2271 if (preserve.marker != NULL)
2272 bfd_preserve_restore (abfd, &preserve);
2273 return NULL;
2276 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2278 void
2279 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2281 bfd_symbol_info (symbol, ret);
2284 long
2285 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2287 return 0;
2290 long
2291 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2293 return 0;
2297 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2298 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2300 return 0;
2303 const bfd_target sym_vec =
2305 "sym", /* Name. */
2306 bfd_target_sym_flavour, /* Flavour. */
2307 BFD_ENDIAN_BIG, /* Byteorder. */
2308 BFD_ENDIAN_BIG, /* Header byteorder. */
2309 (HAS_RELOC | EXEC_P | /* Object flags. */
2310 HAS_LINENO | HAS_DEBUG |
2311 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2312 (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2313 | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags. */
2314 0, /* Symbol_leading_char. */
2315 ' ', /* AR_pad_char. */
2316 16, /* AR_max_namelen. */
2317 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2318 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2319 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
2320 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2321 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2322 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Hdrs. */
2323 { /* bfd_check_format. */
2324 _bfd_dummy_target,
2325 bfd_sym_object_p, /* bfd_check_format. */
2326 _bfd_dummy_target,
2327 _bfd_dummy_target,
2329 { /* bfd_set_format. */
2330 bfd_false,
2331 bfd_sym_mkobject,
2332 bfd_false,
2333 bfd_false,
2335 { /* bfd_write_contents. */
2336 bfd_false,
2337 bfd_true,
2338 bfd_false,
2339 bfd_false,
2342 BFD_JUMP_TABLE_GENERIC (bfd_sym),
2343 BFD_JUMP_TABLE_COPY (_bfd_generic),
2344 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2345 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2346 BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2347 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2348 BFD_JUMP_TABLE_WRITE (bfd_sym),
2349 BFD_JUMP_TABLE_LINK (bfd_sym),
2350 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2352 NULL,
2354 NULL