1 /* xSYM symbol-file support for BFD.
2    Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 
4    This file is part of BFD, the Binary File Descriptor library.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 /* xSYM is the debugging format used by CodeWarrior on Mac OS classic.  */
22 
23 #include "sysdep.h"
24 #include "xsym.h"
25 #include "bfd.h"
26 #include "libbfd.h"
27 
28 #define bfd_sym_close_and_cleanup		    _bfd_generic_close_and_cleanup
29 #define bfd_sym_bfd_free_cached_info		    _bfd_generic_bfd_free_cached_info
30 #define bfd_sym_new_section_hook		    _bfd_generic_new_section_hook
31 #define bfd_sym_bfd_is_local_label_name		    bfd_generic_is_local_label_name
32 #define bfd_sym_bfd_is_target_special_symbol	    _bfd_bool_bfd_asymbol_false
33 #define bfd_sym_get_lineno			    _bfd_nosymbols_get_lineno
34 #define bfd_sym_find_nearest_line		    _bfd_nosymbols_find_nearest_line
35 #define bfd_sym_find_line			    _bfd_nosymbols_find_line
36 #define bfd_sym_find_inliner_info		    _bfd_nosymbols_find_inliner_info
37 #define bfd_sym_get_symbol_version_string	    _bfd_nosymbols_get_symbol_version_string
38 #define bfd_sym_bfd_make_debug_symbol		    _bfd_nosymbols_bfd_make_debug_symbol
39 #define bfd_sym_read_minisymbols		    _bfd_generic_read_minisymbols
40 #define bfd_sym_minisymbol_to_symbol		    _bfd_generic_minisymbol_to_symbol
41 #define bfd_sym_set_arch_mach			    _bfd_generic_set_arch_mach
42 #define bfd_sym_get_section_contents		    _bfd_generic_get_section_contents
43 #define bfd_sym_set_section_contents		    _bfd_generic_set_section_contents
44 #define bfd_sym_bfd_get_relocated_section_contents  bfd_generic_get_relocated_section_contents
45 #define bfd_sym_bfd_relax_section		    bfd_generic_relax_section
46 #define bfd_sym_bfd_gc_sections			    bfd_generic_gc_sections
47 #define bfd_sym_bfd_lookup_section_flags	    bfd_generic_lookup_section_flags
48 #define bfd_sym_bfd_merge_sections		    bfd_generic_merge_sections
49 #define bfd_sym_bfd_is_group_section		    bfd_generic_is_group_section
50 #define bfd_sym_bfd_group_name			    bfd_generic_group_name
51 #define bfd_sym_bfd_discard_group		    bfd_generic_discard_group
52 #define bfd_sym_section_already_linked		    _bfd_generic_section_already_linked
53 #define bfd_sym_bfd_define_common_symbol	    bfd_generic_define_common_symbol
54 #define bfd_sym_bfd_link_hide_symbol		    _bfd_generic_link_hide_symbol
55 #define bfd_sym_bfd_define_start_stop		    bfd_generic_define_start_stop
56 #define bfd_sym_bfd_link_hash_table_create	    _bfd_generic_link_hash_table_create
57 #define bfd_sym_bfd_link_add_symbols		    _bfd_generic_link_add_symbols
58 #define bfd_sym_bfd_link_just_syms		    _bfd_generic_link_just_syms
59 #define bfd_sym_bfd_copy_link_hash_symbol_type \
60   _bfd_generic_copy_link_hash_symbol_type
61 #define bfd_sym_bfd_final_link			    _bfd_generic_final_link
62 #define bfd_sym_bfd_link_split_section		    _bfd_generic_link_split_section
63 #define bfd_sym_get_section_contents_in_window	    _bfd_generic_get_section_contents_in_window
64 #define bfd_sym_bfd_link_check_relocs		    _bfd_generic_link_check_relocs
65 
66 extern const bfd_target sym_vec;
67 
68 static int
pstrcmp(const char * as,const char * bs)69 pstrcmp (const char *as, const char *bs)
70 {
71   const unsigned char *a = (const unsigned char *) as;
72   const unsigned char *b = (const unsigned char *) bs;
73   unsigned char clen;
74   int ret;
75 
76   clen = (a[0] > b[0]) ? b[0] : a[0];
77   ret = memcmp (a + 1, b + 1, clen);
78   if (ret != 0)
79     return ret;
80 
81   if (a[0] == b[0])
82     return 0;
83   else if (a[0] < b[0])
84     return -1;
85   else
86     return 1;
87 }
88 
89 static unsigned long
compute_offset(unsigned long first_page,unsigned long page_size,unsigned long entry_size,unsigned long sym_index)90 compute_offset (unsigned long first_page,
91 		unsigned long page_size,
92 		unsigned long entry_size,
93 		unsigned long sym_index)
94 {
95   unsigned long entries_per_page = page_size / entry_size;
96   unsigned long page_number = first_page + (sym_index / entries_per_page);
97   unsigned long page_offset = (sym_index % entries_per_page) * entry_size;
98 
99   return (page_number * page_size) + page_offset;
100 }
101 
102 bool
bfd_sym_mkobject(bfd * abfd ATTRIBUTE_UNUSED)103 bfd_sym_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
104 {
105   return 1;
106 }
107 
108 void
bfd_sym_print_symbol(bfd * abfd ATTRIBUTE_UNUSED,void * afile ATTRIBUTE_UNUSED,asymbol * symbol ATTRIBUTE_UNUSED,bfd_print_symbol_type how ATTRIBUTE_UNUSED)109 bfd_sym_print_symbol (bfd *abfd ATTRIBUTE_UNUSED,
110 		      void * afile ATTRIBUTE_UNUSED,
111 		      asymbol *symbol ATTRIBUTE_UNUSED,
112 		      bfd_print_symbol_type how ATTRIBUTE_UNUSED)
113 {
114   return;
115 }
116 
117 bool
bfd_sym_valid(bfd * abfd)118 bfd_sym_valid (bfd *abfd)
119 {
120   if (abfd == NULL || abfd->xvec == NULL)
121     return 0;
122 
123   return abfd->xvec == &sym_vec;
124 }
125 
126 unsigned char *
bfd_sym_read_name_table(bfd * abfd,bfd_sym_header_block * dshb)127 bfd_sym_read_name_table (bfd *abfd, bfd_sym_header_block *dshb)
128 {
129   size_t table_size = dshb->dshb_nte.dti_page_count * dshb->dshb_page_size;
130   size_t table_offset = dshb->dshb_nte.dti_first_page * dshb->dshb_page_size;
131 
132   if (bfd_seek (abfd, table_offset, SEEK_SET) != 0)
133     return false;
134   return _bfd_alloc_and_read (abfd, table_size, table_size);
135 }
136 
137 void
bfd_sym_parse_file_reference_v32(unsigned char * buf,size_t len,bfd_sym_file_reference * entry)138 bfd_sym_parse_file_reference_v32 (unsigned char *buf,
139 				  size_t len,
140 				  bfd_sym_file_reference *entry)
141 {
142   BFD_ASSERT (len == 6);
143 
144   entry->fref_frte_index = bfd_getb16 (buf);
145   entry->fref_offset = bfd_getb32 (buf + 2);
146 }
147 
148 void
bfd_sym_parse_disk_table_v32(unsigned char * buf,size_t len,bfd_sym_table_info * table)149 bfd_sym_parse_disk_table_v32 (unsigned char *buf,
150 			      size_t len,
151 			      bfd_sym_table_info *table)
152 {
153   BFD_ASSERT (len == 8);
154 
155   table->dti_first_page = bfd_getb16 (buf);
156   table->dti_page_count = bfd_getb16 (buf + 2);
157   table->dti_object_count = bfd_getb32 (buf + 4);
158 }
159 
160 void
bfd_sym_parse_header_v32(unsigned char * buf,size_t len,bfd_sym_header_block * header)161 bfd_sym_parse_header_v32 (unsigned char *buf,
162 			  size_t len,
163 			  bfd_sym_header_block *header)
164 {
165   BFD_ASSERT (len == 154);
166 
167   memcpy (header->dshb_id, buf, 32);
168   header->dshb_page_size = bfd_getb16 (buf + 32);
169   header->dshb_hash_page = bfd_getb16 (buf + 34);
170   header->dshb_root_mte = bfd_getb16 (buf + 36);
171   header->dshb_mod_date = bfd_getb32 (buf + 38);
172 
173   bfd_sym_parse_disk_table_v32 (buf + 42, 8, &header->dshb_frte);
174   bfd_sym_parse_disk_table_v32 (buf + 50, 8, &header->dshb_rte);
175   bfd_sym_parse_disk_table_v32 (buf + 58, 8, &header->dshb_mte);
176   bfd_sym_parse_disk_table_v32 (buf + 66, 8, &header->dshb_cmte);
177   bfd_sym_parse_disk_table_v32 (buf + 74, 8, &header->dshb_cvte);
178   bfd_sym_parse_disk_table_v32 (buf + 82, 8, &header->dshb_csnte);
179   bfd_sym_parse_disk_table_v32 (buf + 90, 8, &header->dshb_clte);
180   bfd_sym_parse_disk_table_v32 (buf + 98, 8, &header->dshb_ctte);
181   bfd_sym_parse_disk_table_v32 (buf + 106, 8, &header->dshb_tte);
182   bfd_sym_parse_disk_table_v32 (buf + 114, 8, &header->dshb_nte);
183   bfd_sym_parse_disk_table_v32 (buf + 122, 8, &header->dshb_tinfo);
184   bfd_sym_parse_disk_table_v32 (buf + 130, 8, &header->dshb_fite);
185   bfd_sym_parse_disk_table_v32 (buf + 138, 8, &header->dshb_const);
186 
187   memcpy (&header->dshb_file_creator, buf + 146, 4);
188   memcpy (&header->dshb_file_type, buf + 150, 4);
189 }
190 
191 int
bfd_sym_read_header_v32(bfd * abfd,bfd_sym_header_block * header)192 bfd_sym_read_header_v32 (bfd *abfd, bfd_sym_header_block *header)
193 {
194   unsigned char buf[154];
195   long ret;
196 
197   ret = bfd_bread (buf, 154, abfd);
198   if (ret != 154)
199     return -1;
200 
201   bfd_sym_parse_header_v32 (buf, 154, header);
202 
203   return 0;
204 }
205 
206 int
bfd_sym_read_header_v34(bfd * abfd ATTRIBUTE_UNUSED,bfd_sym_header_block * header ATTRIBUTE_UNUSED)207 bfd_sym_read_header_v34 (bfd *abfd ATTRIBUTE_UNUSED,
208 			 bfd_sym_header_block *header ATTRIBUTE_UNUSED)
209 {
210   abort ();
211 }
212 
213 int
bfd_sym_read_header(bfd * abfd,bfd_sym_header_block * header,bfd_sym_version version)214 bfd_sym_read_header (bfd *abfd,
215 		     bfd_sym_header_block *header,
216 		     bfd_sym_version version)
217 {
218   switch (version)
219     {
220     case BFD_SYM_VERSION_3_5:
221     case BFD_SYM_VERSION_3_4:
222       return bfd_sym_read_header_v34 (abfd, header);
223     case BFD_SYM_VERSION_3_3:
224     case BFD_SYM_VERSION_3_2:
225       return bfd_sym_read_header_v32 (abfd, header);
226     case BFD_SYM_VERSION_3_1:
227     default:
228       return 0;
229     }
230 }
231 
232 int
bfd_sym_read_version(bfd * abfd,bfd_sym_version * version)233 bfd_sym_read_version (bfd *abfd, bfd_sym_version *version)
234 {
235   char version_string[32];
236   long ret;
237 
238   ret = bfd_bread (version_string, sizeof (version_string), abfd);
239   if (ret != sizeof (version_string))
240     return -1;
241 
242   if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_1) == 0)
243     *version = BFD_SYM_VERSION_3_1;
244   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_2) == 0)
245     *version = BFD_SYM_VERSION_3_2;
246   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_3) == 0)
247     *version = BFD_SYM_VERSION_3_3;
248   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_4) == 0)
249     *version = BFD_SYM_VERSION_3_4;
250   else if (pstrcmp (version_string, BFD_SYM_VERSION_STR_3_5) == 0)
251     *version = BFD_SYM_VERSION_3_5;
252   else
253     return -1;
254 
255   return 0;
256 }
257 
258 void
bfd_sym_display_table_summary(FILE * f,bfd_sym_table_info * dti,const char * name)259 bfd_sym_display_table_summary (FILE *f,
260 			       bfd_sym_table_info *dti,
261 			       const char *name)
262 {
263   fprintf (f, "%-6s %13ld %13ld %13ld\n",
264 	   name,
265 	   dti->dti_first_page,
266 	   dti->dti_page_count,
267 	   dti->dti_object_count);
268 }
269 
270 void
bfd_sym_display_header(FILE * f,bfd_sym_header_block * dshb)271 bfd_sym_display_header (FILE *f, bfd_sym_header_block *dshb)
272 {
273   fprintf (f, "            Version: %.*s\n", dshb->dshb_id[0], dshb->dshb_id + 1);
274   fprintf (f, "          Page Size: 0x%x\n", dshb->dshb_page_size);
275   fprintf (f, "          Hash Page: %lu\n", dshb->dshb_hash_page);
276   fprintf (f, "           Root MTE: %lu\n", dshb->dshb_root_mte);
277   fprintf (f, "  Modification Date: ");
278   fprintf (f, "[unimplemented]");
279   fprintf (f, " (0x%lx)\n", dshb->dshb_mod_date);
280 
281   fprintf (f, "       File Creator:  %.4s  Type: %.4s\n\n",
282 	   dshb->dshb_file_creator, dshb->dshb_file_type);
283 
284   fprintf (f, "Table Name   First Page    Page Count   Object Count\n");
285   fprintf (f, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
286 
287   bfd_sym_display_table_summary (f, &dshb->dshb_nte, "NTE");
288   bfd_sym_display_table_summary (f, &dshb->dshb_rte, "RTE");
289   bfd_sym_display_table_summary (f, &dshb->dshb_mte, "MTE");
290   bfd_sym_display_table_summary (f, &dshb->dshb_frte, "FRTE");
291   bfd_sym_display_table_summary (f, &dshb->dshb_cmte, "CMTE");
292   bfd_sym_display_table_summary (f, &dshb->dshb_cvte, "CVTE");
293   bfd_sym_display_table_summary (f, &dshb->dshb_csnte, "CSNTE");
294   bfd_sym_display_table_summary (f, &dshb->dshb_clte, "CLTE");
295   bfd_sym_display_table_summary (f, &dshb->dshb_ctte, "CTTE");
296   bfd_sym_display_table_summary (f, &dshb->dshb_tte, "TTE");
297   bfd_sym_display_table_summary (f, &dshb->dshb_tinfo, "TINFO");
298   bfd_sym_display_table_summary (f, &dshb->dshb_fite, "FITE");
299   bfd_sym_display_table_summary (f, &dshb->dshb_const, "CONST");
300 
301   fprintf (f, "\n");
302 }
303 
304 void
bfd_sym_parse_resources_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_resources_table_entry * entry)305 bfd_sym_parse_resources_table_entry_v32 (unsigned char *buf,
306 					 size_t len,
307 					 bfd_sym_resources_table_entry *entry)
308 {
309   BFD_ASSERT (len == 18);
310 
311   memcpy (&entry->rte_res_type, buf, 4);
312   entry->rte_res_number = bfd_getb16 (buf + 4);
313   entry->rte_nte_index = bfd_getb32 (buf + 6);
314   entry->rte_mte_first = bfd_getb16 (buf + 10);
315   entry->rte_mte_last = bfd_getb16 (buf + 12);
316   entry->rte_res_size = bfd_getb32 (buf + 14);
317 }
318 
319 void
bfd_sym_parse_modules_table_entry_v33(unsigned char * buf,size_t len,bfd_sym_modules_table_entry * entry)320 bfd_sym_parse_modules_table_entry_v33 (unsigned char *buf,
321 				       size_t len,
322 				       bfd_sym_modules_table_entry *entry)
323 {
324   BFD_ASSERT (len == 46);
325 
326   entry->mte_rte_index = bfd_getb16 (buf);
327   entry->mte_res_offset = bfd_getb32 (buf + 2);
328   entry->mte_size = bfd_getb32 (buf + 6);
329   entry->mte_kind = buf[10];
330   entry->mte_scope = buf[11];
331   entry->mte_parent = bfd_getb16 (buf + 12);
332   bfd_sym_parse_file_reference_v32 (buf + 14, 6, &entry->mte_imp_fref);
333   entry->mte_imp_end = bfd_getb32 (buf + 20);
334   entry->mte_nte_index = bfd_getb32 (buf + 24);
335   entry->mte_cmte_index = bfd_getb16 (buf + 28);
336   entry->mte_cvte_index = bfd_getb32 (buf + 30);
337   entry->mte_clte_index = bfd_getb16 (buf + 34);
338   entry->mte_ctte_index = bfd_getb16 (buf + 36);
339   entry->mte_csnte_idx_1 = bfd_getb32 (buf + 38);
340   entry->mte_csnte_idx_2 = bfd_getb32 (buf + 42);
341 }
342 
343 void
bfd_sym_parse_file_references_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_file_references_table_entry * entry)344 bfd_sym_parse_file_references_table_entry_v32 (unsigned char *buf,
345 					       size_t len,
346 					       bfd_sym_file_references_table_entry *entry)
347 {
348   unsigned int type;
349 
350   BFD_ASSERT (len == 10);
351 
352   memset (entry, 0, sizeof (bfd_sym_file_references_table_entry));
353   type = bfd_getb16 (buf);
354 
355   switch (type)
356     {
357     case BFD_SYM_END_OF_LIST_3_2:
358       entry->generic.type = BFD_SYM_END_OF_LIST;
359       break;
360 
361     case BFD_SYM_FILE_NAME_INDEX_3_2:
362       entry->filename.type = BFD_SYM_FILE_NAME_INDEX;
363       entry->filename.nte_index = bfd_getb32 (buf + 2);
364       entry->filename.mod_date = bfd_getb32 (buf + 6);
365       break;
366 
367     default:
368       entry->entry.mte_index = type;
369       entry->entry.file_offset = bfd_getb32 (buf + 2);
370     }
371 }
372 
373 void
bfd_sym_parse_contained_modules_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_contained_modules_table_entry * entry)374 bfd_sym_parse_contained_modules_table_entry_v32 (unsigned char *buf,
375 						 size_t len,
376 						 bfd_sym_contained_modules_table_entry *entry)
377 {
378   unsigned int type;
379 
380   BFD_ASSERT (len == 6);
381 
382   memset (entry, 0, sizeof (bfd_sym_contained_modules_table_entry));
383   type = bfd_getb16 (buf);
384 
385   switch (type)
386     {
387     case BFD_SYM_END_OF_LIST_3_2:
388       entry->generic.type = BFD_SYM_END_OF_LIST;
389       break;
390 
391     default:
392       entry->entry.mte_index = type;
393       entry->entry.nte_index = bfd_getb32 (buf + 2);
394       break;
395     }
396 }
397 
398 void
bfd_sym_parse_contained_variables_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_contained_variables_table_entry * entry)399 bfd_sym_parse_contained_variables_table_entry_v32 (unsigned char *buf,
400 						   size_t len,
401 						   bfd_sym_contained_variables_table_entry *entry)
402 {
403   unsigned int type;
404 
405   BFD_ASSERT (len == 26);
406 
407   memset (entry, 0, sizeof (bfd_sym_contained_variables_table_entry));
408   type = bfd_getb16 (buf);
409 
410   switch (type)
411     {
412     case BFD_SYM_END_OF_LIST_3_2:
413       entry->generic.type = BFD_SYM_END_OF_LIST;
414       break;
415 
416     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
417       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
418       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
419       break;
420 
421     default:
422       entry->entry.tte_index = type;
423       entry->entry.nte_index = bfd_getb32 (buf + 2);
424       entry->entry.file_delta = bfd_getb16 (buf + 6);
425       entry->entry.scope = buf[8];
426       entry->entry.la_size = buf[9];
427 
428       if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
429 	{
430 	  entry->entry.address.scstruct.sca_kind = buf[10];
431 	  entry->entry.address.scstruct.sca_class = buf[11];
432 	  entry->entry.address.scstruct.sca_offset = bfd_getb32 (buf + 12);
433 	}
434       else if (entry->entry.la_size <= BFD_SYM_CVTE_SCA)
435 	{
436 #if BFD_SYM_CVTE_SCA > 0
437 	  memcpy (&entry->entry.address.lastruct.la, buf + 10,
438 		  BFD_SYM_CVTE_SCA);
439 #endif
440 	  entry->entry.address.lastruct.la_kind = buf[23];
441 	}
442       else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
443 	{
444 	  entry->entry.address.biglastruct.big_la = bfd_getb32 (buf + 10);
445 	  entry->entry.address.biglastruct.big_la_kind = buf[12];
446 	}
447     }
448 }
449 
450 void
bfd_sym_parse_contained_statements_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_contained_statements_table_entry * entry)451 bfd_sym_parse_contained_statements_table_entry_v32 (unsigned char *buf,
452 						    size_t len,
453 						    bfd_sym_contained_statements_table_entry *entry)
454 {
455   unsigned int type;
456 
457   BFD_ASSERT (len == 8);
458 
459   memset (entry, 0, sizeof (bfd_sym_contained_statements_table_entry));
460   type = bfd_getb16 (buf);
461 
462   switch (type)
463     {
464     case BFD_SYM_END_OF_LIST_3_2:
465       entry->generic.type = BFD_SYM_END_OF_LIST;
466       break;
467 
468     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
469       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
470       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
471       break;
472 
473     default:
474       entry->entry.mte_index = type;
475       entry->entry.mte_offset = bfd_getb16 (buf + 2);
476       entry->entry.file_delta = bfd_getb32 (buf + 4);
477       break;
478     }
479 }
480 
481 void
bfd_sym_parse_contained_labels_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_contained_labels_table_entry * entry)482 bfd_sym_parse_contained_labels_table_entry_v32 (unsigned char *buf,
483 						size_t len,
484 						bfd_sym_contained_labels_table_entry *entry)
485 {
486   unsigned int type;
487 
488   BFD_ASSERT (len == 12);
489 
490   memset (entry, 0, sizeof (bfd_sym_contained_labels_table_entry));
491   type = bfd_getb16 (buf);
492 
493   switch (type)
494     {
495     case BFD_SYM_END_OF_LIST_3_2:
496       entry->generic.type = BFD_SYM_END_OF_LIST;
497       break;
498 
499     case BFD_SYM_SOURCE_FILE_CHANGE_3_2:
500       entry->file.type = BFD_SYM_SOURCE_FILE_CHANGE;
501       bfd_sym_parse_file_reference_v32 (buf + 2, 6, &entry->file.fref);
502       break;
503 
504     default:
505       entry->entry.mte_index = type;
506       entry->entry.mte_offset = bfd_getb16 (buf + 2);
507       entry->entry.nte_index = bfd_getb32 (buf + 4);
508       entry->entry.file_delta = bfd_getb16 (buf + 8);
509       entry->entry.scope = bfd_getb16 (buf + 10);
510       break;
511     }
512 }
513 
514 void
bfd_sym_parse_type_table_entry_v32(unsigned char * buf,size_t len,bfd_sym_type_table_entry * entry)515 bfd_sym_parse_type_table_entry_v32 (unsigned char *buf,
516 				    size_t len,
517 				    bfd_sym_type_table_entry *entry)
518 {
519   BFD_ASSERT (len == 4);
520 
521   *entry = bfd_getb32 (buf);
522 }
523 
524 int
bfd_sym_fetch_resources_table_entry(bfd * abfd,bfd_sym_resources_table_entry * entry,unsigned long sym_index)525 bfd_sym_fetch_resources_table_entry (bfd *abfd,
526 				     bfd_sym_resources_table_entry *entry,
527 				     unsigned long sym_index)
528 {
529   void (*parser) (unsigned char *, size_t, bfd_sym_resources_table_entry *);
530   unsigned long offset;
531   unsigned long entry_size;
532   unsigned char buf[18];
533   bfd_sym_data_struct *sdata = NULL;
534 
535   parser = NULL;
536   BFD_ASSERT (bfd_sym_valid (abfd));
537   sdata = abfd->tdata.sym_data;
538 
539   if (sym_index == 0)
540     return -1;
541 
542   switch (sdata->version)
543     {
544     case BFD_SYM_VERSION_3_5:
545     case BFD_SYM_VERSION_3_4:
546       return -1;
547 
548     case BFD_SYM_VERSION_3_3:
549     case BFD_SYM_VERSION_3_2:
550       entry_size = 18;
551       parser = bfd_sym_parse_resources_table_entry_v32;
552       break;
553 
554     case BFD_SYM_VERSION_3_1:
555     default:
556       return -1;
557     }
558   if (parser == NULL)
559     return -1;
560 
561   offset = compute_offset (sdata->header.dshb_rte.dti_first_page,
562 			   sdata->header.dshb_page_size,
563 			   entry_size, sym_index);
564 
565   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
566     return -1;
567   if (bfd_bread (buf, entry_size, abfd) != entry_size)
568     return -1;
569 
570   (*parser) (buf, entry_size, entry);
571 
572   return 0;
573 }
574 
575 int
bfd_sym_fetch_modules_table_entry(bfd * abfd,bfd_sym_modules_table_entry * entry,unsigned long sym_index)576 bfd_sym_fetch_modules_table_entry (bfd *abfd,
577 				   bfd_sym_modules_table_entry *entry,
578 				   unsigned long sym_index)
579 {
580   void (*parser) (unsigned char *, size_t, bfd_sym_modules_table_entry *);
581   unsigned long offset;
582   unsigned long entry_size;
583   unsigned char buf[46];
584   bfd_sym_data_struct *sdata = NULL;
585 
586   parser = NULL;
587   BFD_ASSERT (bfd_sym_valid (abfd));
588   sdata = abfd->tdata.sym_data;
589 
590   if (sym_index == 0)
591     return -1;
592 
593   switch (sdata->version)
594     {
595     case BFD_SYM_VERSION_3_5:
596     case BFD_SYM_VERSION_3_4:
597       return -1;
598 
599     case BFD_SYM_VERSION_3_3:
600       entry_size = 46;
601       parser = bfd_sym_parse_modules_table_entry_v33;
602       break;
603 
604     case BFD_SYM_VERSION_3_2:
605     case BFD_SYM_VERSION_3_1:
606     default:
607       return -1;
608     }
609   if (parser == NULL)
610     return -1;
611 
612   offset = compute_offset (sdata->header.dshb_mte.dti_first_page,
613 			   sdata->header.dshb_page_size,
614 			   entry_size, sym_index);
615 
616   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
617     return -1;
618   if (bfd_bread (buf, entry_size, abfd) != entry_size)
619     return -1;
620 
621   (*parser) (buf, entry_size, entry);
622 
623   return 0;
624 }
625 
626 int
bfd_sym_fetch_file_references_table_entry(bfd * abfd,bfd_sym_file_references_table_entry * entry,unsigned long sym_index)627 bfd_sym_fetch_file_references_table_entry (bfd *abfd,
628 					   bfd_sym_file_references_table_entry *entry,
629 					   unsigned long sym_index)
630 {
631   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_table_entry *);
632   unsigned long offset;
633   unsigned long entry_size = 0;
634   unsigned char buf[8];
635   bfd_sym_data_struct *sdata = NULL;
636 
637   parser = NULL;
638   BFD_ASSERT (bfd_sym_valid (abfd));
639   sdata = abfd->tdata.sym_data;
640 
641   if (sym_index == 0)
642     return -1;
643 
644   switch (sdata->version)
645     {
646     case BFD_SYM_VERSION_3_3:
647     case BFD_SYM_VERSION_3_2:
648       entry_size = 10;
649       parser = bfd_sym_parse_file_references_table_entry_v32;
650       break;
651 
652     case BFD_SYM_VERSION_3_5:
653     case BFD_SYM_VERSION_3_4:
654     case BFD_SYM_VERSION_3_1:
655     default:
656       break;
657     }
658 
659   if (parser == NULL)
660     return -1;
661 
662   offset = compute_offset (sdata->header.dshb_frte.dti_first_page,
663 			   sdata->header.dshb_page_size,
664 			   entry_size, sym_index);
665 
666   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
667     return -1;
668   if (bfd_bread (buf, entry_size, abfd) != entry_size)
669     return -1;
670 
671   (*parser) (buf, entry_size, entry);
672 
673   return 0;
674 }
675 
676 int
bfd_sym_fetch_contained_modules_table_entry(bfd * abfd,bfd_sym_contained_modules_table_entry * entry,unsigned long sym_index)677 bfd_sym_fetch_contained_modules_table_entry (bfd *abfd,
678 					     bfd_sym_contained_modules_table_entry *entry,
679 					     unsigned long sym_index)
680 {
681   void (*parser) (unsigned char *, size_t, bfd_sym_contained_modules_table_entry *);
682   unsigned long offset;
683   unsigned long entry_size = 0;
684   unsigned char buf[6];
685   bfd_sym_data_struct *sdata = NULL;
686 
687   parser = NULL;
688   BFD_ASSERT (bfd_sym_valid (abfd));
689   sdata = abfd->tdata.sym_data;
690 
691   if (sym_index == 0)
692     return -1;
693 
694   switch (sdata->version)
695     {
696     case BFD_SYM_VERSION_3_3:
697     case BFD_SYM_VERSION_3_2:
698       entry_size = 6;
699       parser = bfd_sym_parse_contained_modules_table_entry_v32;
700       break;
701 
702     case BFD_SYM_VERSION_3_5:
703     case BFD_SYM_VERSION_3_4:
704     case BFD_SYM_VERSION_3_1:
705     default:
706       break;
707     }
708 
709   if (parser == NULL)
710     return -1;
711 
712   offset = compute_offset (sdata->header.dshb_cmte.dti_first_page,
713 			   sdata->header.dshb_page_size,
714 			   entry_size, sym_index);
715 
716   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
717     return -1;
718   if (bfd_bread (buf, entry_size, abfd) != entry_size)
719     return -1;
720 
721   (*parser) (buf, entry_size, entry);
722 
723   return 0;
724 }
725 
726 int
bfd_sym_fetch_contained_variables_table_entry(bfd * abfd,bfd_sym_contained_variables_table_entry * entry,unsigned long sym_index)727 bfd_sym_fetch_contained_variables_table_entry (bfd *abfd,
728 					       bfd_sym_contained_variables_table_entry *entry,
729 					       unsigned long sym_index)
730 {
731   void (*parser) (unsigned char *, size_t, bfd_sym_contained_variables_table_entry *);
732   unsigned long offset;
733   unsigned long entry_size = 0;
734   unsigned char buf[26];
735   bfd_sym_data_struct *sdata = NULL;
736 
737   parser = NULL;
738   BFD_ASSERT (bfd_sym_valid (abfd));
739   sdata = abfd->tdata.sym_data;
740 
741   if (sym_index == 0)
742     return -1;
743 
744   switch (sdata->version)
745     {
746     case BFD_SYM_VERSION_3_3:
747     case BFD_SYM_VERSION_3_2:
748       entry_size = 26;
749       parser = bfd_sym_parse_contained_variables_table_entry_v32;
750       break;
751 
752     case BFD_SYM_VERSION_3_5:
753     case BFD_SYM_VERSION_3_4:
754     case BFD_SYM_VERSION_3_1:
755     default:
756       break;
757     }
758 
759   if (parser == NULL)
760     return -1;
761 
762   offset = compute_offset (sdata->header.dshb_cvte.dti_first_page,
763 			   sdata->header.dshb_page_size,
764 			   entry_size, sym_index);
765 
766   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
767     return -1;
768   if (bfd_bread (buf, entry_size, abfd) != entry_size)
769     return -1;
770 
771   (*parser) (buf, entry_size, entry);
772 
773   return 0;
774 }
775 
776 int
bfd_sym_fetch_contained_statements_table_entry(bfd * abfd,bfd_sym_contained_statements_table_entry * entry,unsigned long sym_index)777 bfd_sym_fetch_contained_statements_table_entry (bfd *abfd,
778 						bfd_sym_contained_statements_table_entry *entry,
779 						unsigned long sym_index)
780 {
781   void (*parser) (unsigned char *, size_t, bfd_sym_contained_statements_table_entry *);
782   unsigned long offset;
783   unsigned long entry_size = 0;
784   unsigned char buf[8];
785   bfd_sym_data_struct *sdata = NULL;
786 
787   parser = NULL;
788   BFD_ASSERT (bfd_sym_valid (abfd));
789   sdata = abfd->tdata.sym_data;
790 
791   if (sym_index == 0)
792     return -1;
793 
794   switch (sdata->version)
795     {
796     case BFD_SYM_VERSION_3_3:
797     case BFD_SYM_VERSION_3_2:
798       entry_size = 8;
799       parser = bfd_sym_parse_contained_statements_table_entry_v32;
800       break;
801 
802     case BFD_SYM_VERSION_3_5:
803     case BFD_SYM_VERSION_3_4:
804     case BFD_SYM_VERSION_3_1:
805     default:
806       break;
807     }
808 
809   if (parser == NULL)
810     return -1;
811 
812   offset = compute_offset (sdata->header.dshb_csnte.dti_first_page,
813 			   sdata->header.dshb_page_size,
814 			   entry_size, sym_index);
815 
816   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
817     return -1;
818   if (bfd_bread (buf, entry_size, abfd) != entry_size)
819     return -1;
820 
821   (*parser) (buf, entry_size, entry);
822 
823   return 0;
824 }
825 
826 int
bfd_sym_fetch_contained_labels_table_entry(bfd * abfd,bfd_sym_contained_labels_table_entry * entry,unsigned long sym_index)827 bfd_sym_fetch_contained_labels_table_entry (bfd *abfd,
828 					    bfd_sym_contained_labels_table_entry *entry,
829 					    unsigned long sym_index)
830 {
831   void (*parser) (unsigned char *, size_t, bfd_sym_contained_labels_table_entry *);
832   unsigned long offset;
833   unsigned long entry_size = 0;
834   unsigned char buf[12];
835   bfd_sym_data_struct *sdata = NULL;
836 
837   parser = NULL;
838   BFD_ASSERT (bfd_sym_valid (abfd));
839   sdata = abfd->tdata.sym_data;
840 
841   if (sym_index == 0)
842     return -1;
843 
844   switch (sdata->version)
845     {
846     case BFD_SYM_VERSION_3_3:
847     case BFD_SYM_VERSION_3_2:
848       entry_size = 12;
849       parser = bfd_sym_parse_contained_labels_table_entry_v32;
850       break;
851 
852     case BFD_SYM_VERSION_3_5:
853     case BFD_SYM_VERSION_3_4:
854     case BFD_SYM_VERSION_3_1:
855     default:
856       break;
857     }
858 
859   if (parser == NULL)
860     return -1;
861 
862   offset = compute_offset (sdata->header.dshb_clte.dti_first_page,
863 			   sdata->header.dshb_page_size,
864 			   entry_size, sym_index);
865 
866   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
867     return -1;
868   if (bfd_bread (buf, entry_size, abfd) != entry_size)
869     return -1;
870 
871   (*parser) (buf, entry_size, entry);
872 
873   return 0;
874 }
875 
876 int
bfd_sym_fetch_contained_types_table_entry(bfd * abfd,bfd_sym_contained_types_table_entry * entry,unsigned long sym_index)877 bfd_sym_fetch_contained_types_table_entry (bfd *abfd,
878 					   bfd_sym_contained_types_table_entry *entry,
879 					   unsigned long sym_index)
880 {
881   void (*parser) (unsigned char *, size_t, bfd_sym_contained_types_table_entry *);
882   unsigned long offset;
883   unsigned long entry_size = 0;
884   unsigned char buf[0];
885   bfd_sym_data_struct *sdata = NULL;
886 
887   parser = NULL;
888   BFD_ASSERT (bfd_sym_valid (abfd));
889   sdata = abfd->tdata.sym_data;
890 
891   if (sym_index == 0)
892     return -1;
893 
894   switch (sdata->version)
895     {
896     case BFD_SYM_VERSION_3_3:
897     case BFD_SYM_VERSION_3_2:
898       entry_size = 0;
899       parser = NULL;
900       break;
901 
902     case BFD_SYM_VERSION_3_5:
903     case BFD_SYM_VERSION_3_4:
904     case BFD_SYM_VERSION_3_1:
905     default:
906       break;
907     }
908 
909   if (parser == NULL)
910     return -1;
911 
912   offset = compute_offset (sdata->header.dshb_ctte.dti_first_page,
913 			   sdata->header.dshb_page_size,
914 			   entry_size, sym_index);
915 
916   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
917     return -1;
918   if (bfd_bread (buf, entry_size, abfd) != entry_size)
919     return -1;
920 
921   (*parser) (buf, entry_size, entry);
922 
923   return 0;
924 }
925 
926 int
bfd_sym_fetch_file_references_index_table_entry(bfd * abfd,bfd_sym_file_references_index_table_entry * entry,unsigned long sym_index)927 bfd_sym_fetch_file_references_index_table_entry (bfd *abfd,
928 						 bfd_sym_file_references_index_table_entry *entry,
929 						 unsigned long sym_index)
930 {
931   void (*parser) (unsigned char *, size_t, bfd_sym_file_references_index_table_entry *);
932   unsigned long offset;
933   unsigned long entry_size = 0;
934   unsigned char buf[0];
935   bfd_sym_data_struct *sdata = NULL;
936 
937   parser = NULL;
938   BFD_ASSERT (bfd_sym_valid (abfd));
939   sdata = abfd->tdata.sym_data;
940 
941   if (sym_index == 0)
942     return -1;
943 
944   switch (sdata->version)
945     {
946     case BFD_SYM_VERSION_3_3:
947     case BFD_SYM_VERSION_3_2:
948       entry_size = 0;
949       parser = NULL;
950       break;
951 
952     case BFD_SYM_VERSION_3_5:
953     case BFD_SYM_VERSION_3_4:
954     case BFD_SYM_VERSION_3_1:
955     default:
956       break;
957     }
958 
959   if (parser == NULL)
960     return -1;
961 
962   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
963 			   sdata->header.dshb_page_size,
964 			   entry_size, sym_index);
965 
966   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
967     return -1;
968   if (bfd_bread (buf, entry_size, abfd) != entry_size)
969     return -1;
970 
971   (*parser) (buf, entry_size, entry);
972 
973   return 0;
974 }
975 
976 int
bfd_sym_fetch_constant_pool_entry(bfd * abfd,bfd_sym_constant_pool_entry * entry,unsigned long sym_index)977 bfd_sym_fetch_constant_pool_entry (bfd *abfd,
978 				   bfd_sym_constant_pool_entry *entry,
979 				   unsigned long sym_index)
980 {
981   void (*parser) (unsigned char *, size_t, bfd_sym_constant_pool_entry *);
982   unsigned long offset;
983   unsigned long entry_size = 0;
984   unsigned char buf[0];
985   bfd_sym_data_struct *sdata = NULL;
986 
987   parser = NULL;
988   BFD_ASSERT (bfd_sym_valid (abfd));
989   sdata = abfd->tdata.sym_data;
990 
991   if (sym_index == 0)
992     return -1;
993 
994   switch (sdata->version)
995     {
996     case BFD_SYM_VERSION_3_3:
997     case BFD_SYM_VERSION_3_2:
998       entry_size = 0;
999       parser = NULL;
1000       break;
1001 
1002     case BFD_SYM_VERSION_3_5:
1003     case BFD_SYM_VERSION_3_4:
1004     case BFD_SYM_VERSION_3_1:
1005     default:
1006       break;
1007     }
1008 
1009   if (parser == NULL)
1010     return -1;
1011 
1012   offset = compute_offset (sdata->header.dshb_fite.dti_first_page,
1013 			   sdata->header.dshb_page_size,
1014 			   entry_size, sym_index);
1015 
1016   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1017     return -1;
1018   if (bfd_bread (buf, entry_size, abfd) != entry_size)
1019     return -1;
1020 
1021   (*parser) (buf, entry_size, entry);
1022 
1023   return 0;
1024 }
1025 
1026 int
bfd_sym_fetch_type_table_entry(bfd * abfd,bfd_sym_type_table_entry * entry,unsigned long sym_index)1027 bfd_sym_fetch_type_table_entry (bfd *abfd,
1028 				bfd_sym_type_table_entry *entry,
1029 				unsigned long sym_index)
1030 {
1031   void (*parser) (unsigned char *, size_t, bfd_sym_type_table_entry *);
1032   unsigned long offset;
1033   unsigned long entry_size = 0;
1034   unsigned char buf[4];
1035   bfd_sym_data_struct *sdata = NULL;
1036 
1037   parser = NULL;
1038   BFD_ASSERT (bfd_sym_valid (abfd));
1039   sdata = abfd->tdata.sym_data;
1040 
1041   switch (sdata->version)
1042     {
1043     case BFD_SYM_VERSION_3_3:
1044     case BFD_SYM_VERSION_3_2:
1045       entry_size = 4;
1046       parser = bfd_sym_parse_type_table_entry_v32;
1047       break;
1048 
1049     case BFD_SYM_VERSION_3_5:
1050     case BFD_SYM_VERSION_3_4:
1051     case BFD_SYM_VERSION_3_1:
1052     default:
1053       break;
1054     }
1055 
1056   if (parser == NULL)
1057     return -1;
1058 
1059   offset = compute_offset (sdata->header.dshb_tte.dti_first_page,
1060 			   sdata->header.dshb_page_size,
1061 			   entry_size, sym_index);
1062 
1063   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1064     return -1;
1065   if (bfd_bread (buf, entry_size, abfd) != entry_size)
1066     return -1;
1067 
1068   (*parser) (buf, entry_size, entry);
1069 
1070   return 0;
1071 }
1072 
1073 int
bfd_sym_fetch_type_information_table_entry(bfd * abfd,bfd_sym_type_information_table_entry * entry,unsigned long offset)1074 bfd_sym_fetch_type_information_table_entry (bfd *abfd,
1075 					    bfd_sym_type_information_table_entry *entry,
1076 					    unsigned long offset)
1077 {
1078   unsigned char buf[4];
1079 
1080   BFD_ASSERT (bfd_sym_valid (abfd));
1081 
1082   if (offset == 0)
1083     return -1;
1084 
1085   if (bfd_seek (abfd, offset, SEEK_SET) < 0)
1086     return -1;
1087 
1088   if (bfd_bread (buf, 4, abfd) != 4)
1089     return -1;
1090   entry->nte_index = bfd_getb32 (buf);
1091 
1092   if (bfd_bread (buf, 2, abfd) != 2)
1093     return -1;
1094   entry->physical_size = bfd_getb16 (buf);
1095 
1096   if (entry->physical_size & 0x8000)
1097     {
1098       if (bfd_bread (buf, 4, abfd) != 4)
1099 	return -1;
1100       entry->physical_size &= 0x7fff;
1101       entry->logical_size = bfd_getb32 (buf);
1102       entry->offset = offset + 10;
1103     }
1104   else
1105     {
1106       if (bfd_bread (buf, 2, abfd) != 2)
1107 	return -1;
1108       entry->physical_size &= 0x7fff;
1109       entry->logical_size = bfd_getb16 (buf);
1110       entry->offset = offset + 8;
1111     }
1112 
1113   return 0;
1114 }
1115 
1116 int
bfd_sym_fetch_type_table_information(bfd * abfd,bfd_sym_type_information_table_entry * entry,unsigned long sym_index)1117 bfd_sym_fetch_type_table_information (bfd *abfd,
1118 				      bfd_sym_type_information_table_entry *entry,
1119 				      unsigned long sym_index)
1120 {
1121   bfd_sym_type_table_entry tindex;
1122   bfd_sym_data_struct *sdata = NULL;
1123 
1124   BFD_ASSERT (bfd_sym_valid (abfd));
1125   sdata = abfd->tdata.sym_data;
1126 
1127   if (sdata->header.dshb_tte.dti_object_count <= 99)
1128     return -1;
1129   if (sym_index < 100)
1130     return -1;
1131 
1132   if (bfd_sym_fetch_type_table_entry (abfd, &tindex, sym_index - 100) < 0)
1133     return -1;
1134   if (bfd_sym_fetch_type_information_table_entry (abfd, entry, tindex) < 0)
1135     return -1;
1136 
1137   return 0;
1138 }
1139 
1140 const unsigned char *
bfd_sym_symbol_name(bfd * abfd,unsigned long sym_index)1141 bfd_sym_symbol_name (bfd *abfd, unsigned long sym_index)
1142 {
1143   bfd_sym_data_struct *sdata = NULL;
1144 
1145   BFD_ASSERT (bfd_sym_valid (abfd));
1146   sdata = abfd->tdata.sym_data;
1147 
1148   if (sym_index == 0)
1149     return (const unsigned char *) "";
1150 
1151   sym_index *= 2;
1152   if ((sym_index / sdata->header.dshb_page_size)
1153       > sdata->header.dshb_nte.dti_page_count)
1154     return (const unsigned char *) "\09[INVALID]";
1155 
1156   return (const unsigned char *) sdata->name_table + sym_index;
1157 }
1158 
1159 const unsigned char *
bfd_sym_module_name(bfd * abfd,unsigned long sym_index)1160 bfd_sym_module_name (bfd *abfd, unsigned long sym_index)
1161 {
1162   bfd_sym_modules_table_entry entry;
1163 
1164   if (bfd_sym_fetch_modules_table_entry (abfd, &entry, sym_index) < 0)
1165     return (const unsigned char *) "\09[INVALID]";
1166 
1167   return bfd_sym_symbol_name (abfd, entry.mte_nte_index);
1168 }
1169 
1170 const char *
bfd_sym_unparse_storage_kind(enum bfd_sym_storage_kind kind)1171 bfd_sym_unparse_storage_kind (enum bfd_sym_storage_kind kind)
1172 {
1173   switch (kind)
1174     {
1175     case BFD_SYM_STORAGE_KIND_LOCAL: return "LOCAL";
1176     case BFD_SYM_STORAGE_KIND_VALUE: return "VALUE";
1177     case BFD_SYM_STORAGE_KIND_REFERENCE: return "REFERENCE";
1178     case BFD_SYM_STORAGE_KIND_WITH: return "WITH";
1179     default: return "[UNKNOWN]";
1180     }
1181 }
1182 
1183 const char *
bfd_sym_unparse_storage_class(enum bfd_sym_storage_class kind)1184 bfd_sym_unparse_storage_class (enum bfd_sym_storage_class kind)
1185 {
1186   switch (kind)
1187     {
1188     case BFD_SYM_STORAGE_CLASS_REGISTER: return "REGISTER";
1189     case BFD_SYM_STORAGE_CLASS_GLOBAL: return "GLOBAL";
1190     case BFD_SYM_STORAGE_CLASS_FRAME_RELATIVE: return "FRAME_RELATIVE";
1191     case BFD_SYM_STORAGE_CLASS_STACK_RELATIVE: return "STACK_RELATIVE";
1192     case BFD_SYM_STORAGE_CLASS_ABSOLUTE: return "ABSOLUTE";
1193     case BFD_SYM_STORAGE_CLASS_CONSTANT: return "CONSTANT";
1194     case BFD_SYM_STORAGE_CLASS_RESOURCE: return "RESOURCE";
1195     case BFD_SYM_STORAGE_CLASS_BIGCONSTANT: return "BIGCONSTANT";
1196     default: return "[UNKNOWN]";
1197     }
1198 }
1199 
1200 const char *
bfd_sym_unparse_module_kind(enum bfd_sym_module_kind kind)1201 bfd_sym_unparse_module_kind (enum bfd_sym_module_kind kind)
1202 {
1203   switch (kind)
1204     {
1205     case BFD_SYM_MODULE_KIND_NONE: return "NONE";
1206     case BFD_SYM_MODULE_KIND_PROGRAM: return "PROGRAM";
1207     case BFD_SYM_MODULE_KIND_UNIT: return "UNIT";
1208     case BFD_SYM_MODULE_KIND_PROCEDURE: return "PROCEDURE";
1209     case BFD_SYM_MODULE_KIND_FUNCTION: return "FUNCTION";
1210     case BFD_SYM_MODULE_KIND_DATA: return "DATA";
1211     case BFD_SYM_MODULE_KIND_BLOCK: return "BLOCK";
1212     default: return "[UNKNOWN]";
1213     }
1214 }
1215 
1216 const char *
bfd_sym_unparse_symbol_scope(enum bfd_sym_symbol_scope scope)1217 bfd_sym_unparse_symbol_scope (enum bfd_sym_symbol_scope scope)
1218 {
1219   switch (scope)
1220     {
1221     case BFD_SYM_SYMBOL_SCOPE_LOCAL: return "LOCAL";
1222     case BFD_SYM_SYMBOL_SCOPE_GLOBAL: return "GLOBAL";
1223     default:
1224       return "[UNKNOWN]";
1225     }
1226 }
1227 
1228 void
bfd_sym_print_file_reference(bfd * abfd,FILE * f,bfd_sym_file_reference * entry)1229 bfd_sym_print_file_reference (bfd *abfd,
1230 			      FILE *f,
1231 			      bfd_sym_file_reference *entry)
1232 {
1233   bfd_sym_file_references_table_entry frtentry;
1234   int ret;
1235 
1236   ret = bfd_sym_fetch_file_references_table_entry (abfd, &frtentry,
1237 						   entry->fref_frte_index);
1238   fprintf (f, "FILE ");
1239 
1240   if ((ret < 0) || (frtentry.generic.type != BFD_SYM_FILE_NAME_INDEX))
1241     fprintf (f, "[INVALID]");
1242   else
1243     fprintf (f, "\"%.*s\"",
1244 	     bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[0],
1245 	     &bfd_sym_symbol_name (abfd, frtentry.filename.nte_index)[1]);
1246 
1247   fprintf (f, " (FRTE %lu)", entry->fref_frte_index);
1248 }
1249 
1250 void
bfd_sym_print_resources_table_entry(bfd * abfd,FILE * f,bfd_sym_resources_table_entry * entry)1251 bfd_sym_print_resources_table_entry (bfd *abfd,
1252 				     FILE *f,
1253 				     bfd_sym_resources_table_entry *entry)
1254 {
1255   fprintf (f, " \"%.*s\" (NTE %lu), type \"%.4s\", num %u, size %lu, MTE %lu -- %lu",
1256 	   bfd_sym_symbol_name (abfd, entry->rte_nte_index)[0],
1257 	   &bfd_sym_symbol_name (abfd, entry->rte_nte_index)[1],
1258 	   entry->rte_nte_index, entry->rte_res_type, entry->rte_res_number,
1259 	   entry->rte_res_size, entry->rte_mte_first, entry->rte_mte_last);
1260 }
1261 
1262 void
bfd_sym_print_modules_table_entry(bfd * abfd,FILE * f,bfd_sym_modules_table_entry * entry)1263 bfd_sym_print_modules_table_entry (bfd *abfd,
1264 				   FILE *f,
1265 				   bfd_sym_modules_table_entry *entry)
1266 {
1267   fprintf (f, "\"%.*s\" (NTE %lu)",
1268 	   bfd_sym_symbol_name (abfd, entry->mte_nte_index)[0],
1269 	   &bfd_sym_symbol_name (abfd, entry->mte_nte_index)[1],
1270 	   entry->mte_nte_index);
1271 
1272   fprintf (f, "\n            ");
1273 
1274   bfd_sym_print_file_reference (abfd, f, &entry->mte_imp_fref);
1275   fprintf (f, " range %lu -- %lu",
1276 	   entry->mte_imp_fref.fref_offset, entry->mte_imp_end);
1277 
1278   fprintf (f, "\n            ");
1279 
1280   fprintf (f, "kind %s", bfd_sym_unparse_module_kind (entry->mte_kind));
1281   fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->mte_scope));
1282 
1283   fprintf (f, ", RTE %lu, offset %lu, size %lu",
1284 	   entry->mte_rte_index, entry->mte_res_offset, entry->mte_size);
1285 
1286   fprintf (f, "\n            ");
1287 
1288   fprintf (f, "CMTE %lu, CVTE %lu, CLTE %lu, CTTE %lu, CSNTE1 %lu, CSNTE2 %lu",
1289 	   entry->mte_cmte_index, entry->mte_cvte_index,
1290 	   entry->mte_clte_index, entry->mte_ctte_index,
1291 	   entry->mte_csnte_idx_1, entry->mte_csnte_idx_2);
1292 
1293   if (entry->mte_parent != 0)
1294     fprintf (f, ", parent %lu", entry->mte_parent);
1295   else
1296     fprintf (f, ", no parent");
1297 
1298   if (entry->mte_cmte_index != 0)
1299     fprintf (f, ", child %lu", entry->mte_cmte_index);
1300   else
1301     fprintf (f, ", no child");
1302 }
1303 
1304 void
bfd_sym_print_file_references_table_entry(bfd * abfd,FILE * f,bfd_sym_file_references_table_entry * entry)1305 bfd_sym_print_file_references_table_entry (bfd *abfd,
1306 					   FILE *f,
1307 					   bfd_sym_file_references_table_entry *entry)
1308 {
1309   switch (entry->generic.type)
1310     {
1311     case BFD_SYM_FILE_NAME_INDEX:
1312       fprintf (f, "FILE \"%.*s\" (NTE %lu), modtime ",
1313 	       bfd_sym_symbol_name (abfd, entry->filename.nte_index)[0],
1314 	       &bfd_sym_symbol_name (abfd, entry->filename.nte_index)[1],
1315 	       entry->filename.nte_index);
1316 
1317       fprintf (f, "[UNIMPLEMENTED]");
1318       /* printModDate (entry->filename.mod_date); */
1319       fprintf (f, " (0x%lx)", entry->filename.mod_date);
1320       break;
1321 
1322     case BFD_SYM_END_OF_LIST:
1323       fprintf (f, "END");
1324       break;
1325 
1326     default:
1327       fprintf (f, "\"%.*s\" (MTE %lu), offset %lu",
1328 	       bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1329 	       &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1330 	       entry->entry.mte_index,
1331 	       entry->entry.file_offset);
1332       break;
1333     }
1334 }
1335 
1336 void
bfd_sym_print_contained_modules_table_entry(bfd * abfd,FILE * f,bfd_sym_contained_modules_table_entry * entry)1337 bfd_sym_print_contained_modules_table_entry (bfd *abfd,
1338 					     FILE *f,
1339 					     bfd_sym_contained_modules_table_entry *entry)
1340 {
1341   switch (entry->generic.type)
1342     {
1343     case BFD_SYM_END_OF_LIST:
1344       fprintf (f, "END");
1345       break;
1346 
1347     default:
1348       fprintf (f, "\"%.*s\" (MTE %lu, NTE %lu)",
1349 	       bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1350 	       &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1351 	       entry->entry.mte_index,
1352 	       entry->entry.nte_index);
1353       break;
1354     }
1355 }
1356 
1357 void
bfd_sym_print_contained_variables_table_entry(bfd * abfd,FILE * f,bfd_sym_contained_variables_table_entry * entry)1358 bfd_sym_print_contained_variables_table_entry (bfd *abfd,
1359 					       FILE *f,
1360 					       bfd_sym_contained_variables_table_entry *entry)
1361 {
1362   if (entry->generic.type == BFD_SYM_END_OF_LIST)
1363     {
1364       fprintf (f, "END");
1365       return;
1366     }
1367 
1368   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1369     {
1370       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1371       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1372       return;
1373     }
1374 
1375   fprintf (f, "\"%.*s\" (NTE %lu)",
1376 	   bfd_sym_symbol_name (abfd, entry->entry.nte_index)[0],
1377 	   &bfd_sym_symbol_name (abfd, entry->entry.nte_index)[1],
1378 	   entry->entry.nte_index);
1379 
1380   fprintf (f, ", TTE %lu", entry->entry.tte_index);
1381   fprintf (f, ", offset %lu", entry->entry.file_delta);
1382   fprintf (f, ", scope %s", bfd_sym_unparse_symbol_scope (entry->entry.scope));
1383 
1384   if (entry->entry.la_size == BFD_SYM_CVTE_SCA)
1385     fprintf (f, ", latype %s, laclass %s, laoffset %lu",
1386 	     bfd_sym_unparse_storage_kind (entry->entry.address.scstruct.sca_kind),
1387 	     bfd_sym_unparse_storage_class (entry->entry.address.scstruct.sca_class),
1388 	     entry->entry.address.scstruct.sca_offset);
1389   else if (entry->entry.la_size <= BFD_SYM_CVTE_LA_MAX_SIZE)
1390     {
1391       unsigned long i;
1392 
1393       fprintf (f, ", la [");
1394       for (i = 0; i < entry->entry.la_size; i++)
1395 	fprintf (f, "0x%02x ", entry->entry.address.lastruct.la[i]);
1396       fprintf (f, "]");
1397     }
1398   else if (entry->entry.la_size == BFD_SYM_CVTE_BIG_LA)
1399     fprintf (f, ", bigla %lu, biglakind %u",
1400 	     entry->entry.address.biglastruct.big_la,
1401 	     entry->entry.address.biglastruct.big_la_kind);
1402 
1403   else
1404     fprintf (f, ", la [INVALID]");
1405 }
1406 
1407 void
bfd_sym_print_contained_statements_table_entry(bfd * abfd,FILE * f,bfd_sym_contained_statements_table_entry * entry)1408 bfd_sym_print_contained_statements_table_entry (bfd *abfd,
1409 						FILE *f,
1410 						bfd_sym_contained_statements_table_entry *entry)
1411 {
1412   if (entry->generic.type == BFD_SYM_END_OF_LIST)
1413     {
1414       fprintf (f, "END");
1415       return;
1416     }
1417 
1418   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1419     {
1420       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1421       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1422       return;
1423     }
1424 
1425   fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu",
1426 	   bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1427 	   &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1428 	   entry->entry.mte_index,
1429 	   entry->entry.mte_offset,
1430 	   entry->entry.file_delta);
1431 }
1432 
1433 void
bfd_sym_print_contained_labels_table_entry(bfd * abfd,FILE * f,bfd_sym_contained_labels_table_entry * entry)1434 bfd_sym_print_contained_labels_table_entry (bfd *abfd,
1435 					    FILE *f,
1436 					    bfd_sym_contained_labels_table_entry *entry)
1437 {
1438   if (entry->generic.type == BFD_SYM_END_OF_LIST)
1439     {
1440       fprintf (f, "END");
1441       return;
1442     }
1443 
1444   if (entry->generic.type == BFD_SYM_SOURCE_FILE_CHANGE)
1445     {
1446       bfd_sym_print_file_reference (abfd, f, &entry->file.fref);
1447       fprintf (f, " offset %lu", entry->file.fref.fref_offset);
1448       return;
1449     }
1450 
1451   fprintf (f, "\"%.*s\" (MTE %lu), offset %lu, delta %lu, scope %s",
1452 	   bfd_sym_module_name (abfd, entry->entry.mte_index)[0],
1453 	   &bfd_sym_module_name (abfd, entry->entry.mte_index)[1],
1454 	   entry->entry.mte_index,
1455 	   entry->entry.mte_offset,
1456 	   entry->entry.file_delta,
1457 	   bfd_sym_unparse_symbol_scope (entry->entry.scope));
1458 }
1459 
1460 void
bfd_sym_print_contained_types_table_entry(bfd * abfd ATTRIBUTE_UNUSED,FILE * f,bfd_sym_contained_types_table_entry * entry ATTRIBUTE_UNUSED)1461 bfd_sym_print_contained_types_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1462 					   FILE *f,
1463 					   bfd_sym_contained_types_table_entry *entry ATTRIBUTE_UNUSED)
1464 {
1465   fprintf (f, "[UNIMPLEMENTED]");
1466 }
1467 
1468 const char *
bfd_sym_type_operator_name(unsigned char num)1469 bfd_sym_type_operator_name (unsigned char num)
1470 {
1471   switch (num)
1472     {
1473     case 1: return "TTE";
1474     case 2: return "PointerTo";
1475     case 3: return "ScalarOf";
1476     case 4: return "ConstantOf";
1477     case 5: return "EnumerationOf";
1478     case 6: return "VectorOf";
1479     case 7: return "RecordOf";
1480     case 8: return "UnionOf";
1481     case 9: return "SubRangeOf";
1482     case 10: return "SetOf";
1483     case 11: return "NamedTypeOf";
1484     case 12: return "ProcOf";
1485     case 13: return "ValueOf";
1486     case 14: return "ArrayOf";
1487     default: return "[UNKNOWN OPERATOR]";
1488     }
1489 }
1490 
1491 const char *
bfd_sym_type_basic_name(unsigned char num)1492 bfd_sym_type_basic_name (unsigned char num)
1493 {
1494   switch (num)
1495     {
1496     case 0: return "void";
1497     case 1: return "pascal string";
1498     case 2: return "unsigned long";
1499     case 3: return "signed long";
1500     case 4: return "extended (10 bytes)";
1501     case 5: return "pascal boolean (1 byte)";
1502     case 6: return "unsigned byte";
1503     case 7: return "signed byte";
1504     case 8: return "character (1 byte)";
1505     case 9: return "wide character (2 bytes)";
1506     case 10: return "unsigned short";
1507     case 11: return "signed short";
1508     case 12: return "singled";
1509     case 13: return "double";
1510     case 14: return "extended (12 bytes)";
1511     case 15: return "computational (8 bytes)";
1512     case 16: return "c string";
1513     case 17: return "as-is string";
1514     default: return "[UNKNOWN BASIC TYPE]";
1515     }
1516 }
1517 
1518 int
bfd_sym_fetch_long(unsigned char * buf,unsigned long len,unsigned long offset,unsigned long * offsetptr,long * value)1519 bfd_sym_fetch_long (unsigned char *buf,
1520 		    unsigned long len,
1521 		    unsigned long offset,
1522 		    unsigned long *offsetptr,
1523 		    long *value)
1524 {
1525   int ret;
1526 
1527   if (offset >= len)
1528     {
1529       *value = 0;
1530       offset += 0;
1531       ret = -1;
1532     }
1533   else if (! (buf[offset] & 0x80))
1534     {
1535       *value = buf[offset];
1536       offset += 1;
1537       ret = 0;
1538     }
1539   else if (buf[offset] == 0xc0)
1540     {
1541       if ((offset + 5) > len)
1542 	{
1543 	  *value = 0;
1544 	  offset = len;
1545 	  ret = -1;
1546 	}
1547       else
1548 	{
1549 	  *value = bfd_getb32 (buf + offset + 1);
1550 	  offset += 5;
1551 	  ret = 0;
1552 	}
1553     }
1554   else if ((buf[offset] & 0xc0) == 0xc0)
1555     {
1556       *value =  -(buf[offset] & 0x3f);
1557       offset += 1;
1558       ret = 0;
1559     }
1560   else if ((buf[offset] & 0xc0) == 0x80)
1561     {
1562       if ((offset + 2) > len)
1563 	{
1564 	  *value = 0;
1565 	  offset = len;
1566 	  ret = -1;
1567 	}
1568       else
1569 	{
1570 	  *value = bfd_getb16 (buf + offset) & 0x3fff;
1571 	  offset += 2;
1572 	  ret = 0;
1573 	}
1574     }
1575   else
1576     abort ();
1577 
1578   if (offsetptr != NULL)
1579     *offsetptr = offset;
1580 
1581   return ret;
1582 }
1583 
1584 void
bfd_sym_print_type_information(bfd * abfd,FILE * f,unsigned char * buf,unsigned long len,unsigned long offset,unsigned long * offsetptr)1585 bfd_sym_print_type_information (bfd *abfd,
1586 				FILE *f,
1587 				unsigned char *buf,
1588 				unsigned long len,
1589 				unsigned long offset,
1590 				unsigned long *offsetptr)
1591 {
1592   unsigned int type;
1593 
1594   if (offset >= len)
1595     {
1596       fprintf (f, "[NULL]");
1597 
1598       if (offsetptr != NULL)
1599 	*offsetptr = offset;
1600       return;
1601   }
1602 
1603   type = buf[offset];
1604   offset++;
1605 
1606   if (! (type & 0x80))
1607     {
1608       fprintf (f, "[%s] (0x%x)", bfd_sym_type_basic_name (type & 0x7f), type);
1609 
1610       if (offsetptr != NULL)
1611 	*offsetptr = offset;
1612       return;
1613     }
1614 
1615   if (type & 0x40)
1616     fprintf (f, "[packed ");
1617   else
1618     fprintf (f, "[");
1619 
1620   switch (type & 0x3f)
1621     {
1622     case 1:
1623       {
1624 	long value;
1625 	bfd_sym_type_information_table_entry tinfo;
1626 
1627 	bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1628 	if (value <= 0)
1629 	  fprintf (f, "[INVALID]");
1630 	else
1631 	  {
1632 	    if (bfd_sym_fetch_type_table_information (abfd, &tinfo, value) < 0)
1633 	      fprintf (f, "[INVALID]");
1634 	    else
1635 	      fprintf (f, "\"%.*s\"",
1636 		       bfd_sym_symbol_name (abfd, tinfo.nte_index)[0],
1637 		       &bfd_sym_symbol_name (abfd, tinfo.nte_index)[1]);
1638 	  }
1639 	fprintf (f, " (TTE %lu)", (unsigned long) value);
1640 	break;
1641       }
1642 
1643     case 2:
1644       fprintf (f, "pointer (0x%x) to ", type);
1645       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1646       break;
1647 
1648     case 3:
1649       {
1650 	long value;
1651 
1652 	fprintf (f, "scalar (0x%x) of ", type);
1653 	bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1654 	bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1655 	fprintf (f, " (%lu)", (unsigned long) value);
1656 	break;
1657       }
1658 
1659     case 5:
1660       {
1661 	long lower, upper, nelem;
1662 	int i;
1663 
1664 	fprintf (f, "enumeration (0x%x) of ", type);
1665 	bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1666 	bfd_sym_fetch_long (buf, len, offset, &offset, &lower);
1667 	bfd_sym_fetch_long (buf, len, offset, &offset, &upper);
1668 	bfd_sym_fetch_long (buf, len, offset, &offset, &nelem);
1669 	fprintf (f, " from %lu to %lu with %lu elements: ",
1670 		 (unsigned long) lower, (unsigned long) upper,
1671 		 (unsigned long) nelem);
1672 
1673 	for (i = 0; i < nelem; i++)
1674 	  {
1675 	    fprintf (f, "\n                    ");
1676 	    bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1677 	  }
1678 	break;
1679       }
1680 
1681     case 6:
1682       fprintf (f, "vector (0x%x)", type);
1683       fprintf (f, "\n                index ");
1684       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1685       fprintf (f, "\n                target ");
1686       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1687       break;
1688 
1689     case 7:
1690     case 8:
1691       {
1692 	long nrec, eloff, i;
1693 
1694 	if ((type & 0x3f) == 7)
1695 	  fprintf (f, "record (0x%x) of ", type);
1696 	else
1697 	  fprintf (f, "union (0x%x) of ", type);
1698 
1699 	bfd_sym_fetch_long (buf, len, offset, &offset, &nrec);
1700 	fprintf (f, "%lu elements: ", (unsigned long) nrec);
1701 
1702 	for (i = 0; i < nrec; i++)
1703 	  {
1704 	    bfd_sym_fetch_long (buf, len, offset, &offset, &eloff);
1705 	    fprintf (f, "\n                ");
1706 	    fprintf (f, "offset %lu: ", (unsigned long) eloff);
1707 	    bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1708 	  }
1709 	break;
1710       }
1711 
1712     case 9:
1713       fprintf (f, "subrange (0x%x) of ", type);
1714       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1715       fprintf (f, " lower ");
1716       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1717       fprintf (f, " upper ");
1718       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1719       break;
1720 
1721   case 11:
1722     {
1723       long value;
1724 
1725       fprintf (f, "named type (0x%x) ", type);
1726       bfd_sym_fetch_long (buf, len, offset, &offset, &value);
1727       if (value <= 0)
1728 	fprintf (f, "[INVALID]");
1729       else
1730 	fprintf (f, "\"%.*s\"",
1731 		 bfd_sym_symbol_name (abfd, value)[0],
1732 		 &bfd_sym_symbol_name (abfd, value)[1]);
1733 
1734       fprintf (f, " (NTE %lu) with type ", (unsigned long) value);
1735       bfd_sym_print_type_information (abfd, f, buf, len, offset, &offset);
1736       break;
1737     }
1738 
1739   default:
1740     fprintf (f, "%s (0x%x)", bfd_sym_type_operator_name (type), type);
1741     break;
1742     }
1743 
1744   if (type == (0x40 | 0x6))
1745     {
1746       /* Vector.  */
1747       long n, width, m;
1748       long l;
1749       long i;
1750 
1751       bfd_sym_fetch_long (buf, len, offset, &offset, &n);
1752       bfd_sym_fetch_long (buf, len, offset, &offset, &width);
1753       bfd_sym_fetch_long (buf, len, offset, &offset, &m);
1754       /* fprintf (f, "\n                "); */
1755       fprintf (f, " N %ld, width %ld, M %ld, ", n, width, m);
1756       for (i = 0; i < m; i++)
1757 	{
1758 	  bfd_sym_fetch_long (buf, len, offset, &offset, &l);
1759 	  if (i != 0)
1760 	    fprintf (f, " ");
1761 	  fprintf (f, "%ld", l);
1762 	}
1763     }
1764   else  if (type & 0x40)
1765     {
1766       /* Other packed type.  */
1767       long msb, lsb;
1768 
1769       bfd_sym_fetch_long (buf, len, offset, &offset, &msb);
1770       bfd_sym_fetch_long (buf, len, offset, &offset, &lsb);
1771       /* fprintf (f, "\n                "); */
1772       fprintf (f, " msb %ld, lsb %ld", msb, lsb);
1773     }
1774 
1775   fprintf (f, "]");
1776 
1777   if (offsetptr != NULL)
1778     *offsetptr = offset;
1779 }
1780 
1781 void
bfd_sym_print_type_information_table_entry(bfd * abfd,FILE * f,bfd_sym_type_information_table_entry * entry)1782 bfd_sym_print_type_information_table_entry (bfd *abfd,
1783 					    FILE *f,
1784 					    bfd_sym_type_information_table_entry *entry)
1785 {
1786   unsigned char *buf;
1787   unsigned long offset;
1788   unsigned int i;
1789 
1790   fprintf (f, "\"%.*s\" (NTE %lu), %lu bytes at %lu, logical size %lu",
1791 	   bfd_sym_symbol_name (abfd, entry->nte_index)[0],
1792 	   &bfd_sym_symbol_name (abfd, entry->nte_index)[1],
1793 	   entry->nte_index,
1794 	   entry->physical_size, entry->offset, entry->logical_size);
1795 
1796   fprintf (f, "\n            ");
1797 
1798   if (bfd_seek (abfd, entry->offset, SEEK_SET) != 0
1799       || (buf = _bfd_malloc_and_read (abfd, entry->physical_size,
1800 				      entry->physical_size)) == NULL)
1801     {
1802       fprintf (f, "[ERROR]\n");
1803       return;
1804     }
1805 
1806   fprintf (f, "[");
1807   for (i = 0; i < entry->physical_size; i++)
1808     {
1809       if (i == 0)
1810 	fprintf (f, "0x%02x", buf[i]);
1811       else
1812 	fprintf (f, " 0x%02x", buf[i]);
1813     }
1814 
1815   fprintf (f, "]");
1816   fprintf (f, "\n            ");
1817 
1818   bfd_sym_print_type_information (abfd, f, buf, entry->physical_size, 0, &offset);
1819 
1820   if (offset != entry->physical_size)
1821     fprintf (f, "\n            [parser used %lu bytes instead of %lu]", offset, entry->physical_size);
1822   free (buf);
1823 }
1824 
1825 void
bfd_sym_print_file_references_index_table_entry(bfd * abfd ATTRIBUTE_UNUSED,FILE * f,bfd_sym_file_references_index_table_entry * entry ATTRIBUTE_UNUSED)1826 bfd_sym_print_file_references_index_table_entry (bfd *abfd ATTRIBUTE_UNUSED,
1827 						 FILE *f,
1828 						 bfd_sym_file_references_index_table_entry *entry ATTRIBUTE_UNUSED)
1829 {
1830   fprintf (f, "[UNIMPLEMENTED]");
1831 }
1832 
1833 void
bfd_sym_print_constant_pool_entry(bfd * abfd ATTRIBUTE_UNUSED,FILE * f,bfd_sym_constant_pool_entry * entry ATTRIBUTE_UNUSED)1834 bfd_sym_print_constant_pool_entry (bfd *abfd ATTRIBUTE_UNUSED,
1835 				   FILE *f,
1836 				   bfd_sym_constant_pool_entry *entry ATTRIBUTE_UNUSED)
1837 {
1838   fprintf (f, "[UNIMPLEMENTED]");
1839 }
1840 
1841 unsigned char *
bfd_sym_display_name_table_entry(bfd * abfd,FILE * f,unsigned char * entry)1842 bfd_sym_display_name_table_entry (bfd *abfd,
1843 				  FILE *f,
1844 				  unsigned char *entry)
1845 {
1846   unsigned long sym_index;
1847   unsigned long offset;
1848   bfd_sym_data_struct *sdata = NULL;
1849 
1850   BFD_ASSERT (bfd_sym_valid (abfd));
1851   sdata = abfd->tdata.sym_data;
1852   sym_index = (entry - sdata->name_table) / 2;
1853 
1854   if (sdata->version >= BFD_SYM_VERSION_3_4 && entry[0] == 255 && entry[1] == 0)
1855     {
1856       unsigned short length = bfd_getb16 (entry + 2);
1857       fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, length, entry + 4);
1858       offset = 2 + length + 1;
1859     }
1860   else
1861     {
1862       if (! (entry[0] == 0 || (entry[0] == 1 && entry[1] == '\0')))
1863 	fprintf (f, "[%8lu] \"%.*s\"\n", sym_index, entry[0], entry + 1);
1864 
1865       if (sdata->version >= BFD_SYM_VERSION_3_4)
1866 	offset = entry[0] + 2;
1867       else
1868 	offset = entry[0] + 1;
1869     }
1870 
1871   return (entry + offset + (offset % 2));
1872 }
1873 
1874 void
bfd_sym_display_name_table(bfd * abfd,FILE * f)1875 bfd_sym_display_name_table (bfd *abfd, FILE *f)
1876 {
1877   unsigned long name_table_len;
1878   unsigned char *name_table, *name_table_end, *cur;
1879   bfd_sym_data_struct *sdata = NULL;
1880 
1881   BFD_ASSERT (bfd_sym_valid (abfd));
1882   sdata = abfd->tdata.sym_data;
1883 
1884   name_table_len = sdata->header.dshb_nte.dti_page_count * sdata->header.dshb_page_size;
1885   name_table = sdata->name_table;
1886   name_table_end = name_table + name_table_len;
1887 
1888   fprintf (f, "name table (NTE) contains %lu bytes:\n\n", name_table_len);
1889 
1890   cur = name_table;
1891   for (;;)
1892     {
1893       cur = bfd_sym_display_name_table_entry (abfd, f, cur);
1894       if (cur >= name_table_end)
1895 	break;
1896     }
1897 }
1898 
1899 void
bfd_sym_display_resources_table(bfd * abfd,FILE * f)1900 bfd_sym_display_resources_table (bfd *abfd, FILE *f)
1901 {
1902   unsigned long i;
1903   bfd_sym_resources_table_entry entry;
1904   bfd_sym_data_struct *sdata = NULL;
1905 
1906   BFD_ASSERT (bfd_sym_valid (abfd));
1907   sdata = abfd->tdata.sym_data;
1908 
1909   fprintf (f, "resource table (RTE) contains %lu objects:\n\n",
1910 	   sdata->header.dshb_rte.dti_object_count);
1911 
1912   for (i = 1; i <= sdata->header.dshb_rte.dti_object_count; i++)
1913     {
1914       if (bfd_sym_fetch_resources_table_entry (abfd, &entry, i) < 0)
1915 	fprintf (f, " [%8lu] [INVALID]\n", i);
1916       else
1917 	{
1918 	  fprintf (f, " [%8lu] ", i);
1919 	  bfd_sym_print_resources_table_entry (abfd, f, &entry);
1920 	  fprintf (f, "\n");
1921 	}
1922     }
1923 }
1924 
1925 void
bfd_sym_display_modules_table(bfd * abfd,FILE * f)1926 bfd_sym_display_modules_table (bfd *abfd, FILE *f)
1927 {
1928   unsigned long i;
1929   bfd_sym_modules_table_entry entry;
1930   bfd_sym_data_struct *sdata = NULL;
1931 
1932   BFD_ASSERT (bfd_sym_valid (abfd));
1933   sdata = abfd->tdata.sym_data;
1934 
1935   fprintf (f, "module table (MTE) contains %lu objects:\n\n",
1936 	   sdata->header.dshb_mte.dti_object_count);
1937 
1938   for (i = 1; i <= sdata->header.dshb_mte.dti_object_count; i++)
1939     {
1940       if (bfd_sym_fetch_modules_table_entry (abfd, &entry, i) < 0)
1941 	fprintf (f, " [%8lu] [INVALID]\n", i);
1942       else
1943 	{
1944 	  fprintf (f, " [%8lu] ", i);
1945 	  bfd_sym_print_modules_table_entry (abfd, f, &entry);
1946 	  fprintf (f, "\n");
1947 	}
1948     }
1949 }
1950 
1951 void
bfd_sym_display_file_references_table(bfd * abfd,FILE * f)1952 bfd_sym_display_file_references_table (bfd *abfd, FILE *f)
1953 {
1954   unsigned long i;
1955   bfd_sym_file_references_table_entry entry;
1956   bfd_sym_data_struct *sdata = NULL;
1957 
1958   BFD_ASSERT (bfd_sym_valid (abfd));
1959   sdata = abfd->tdata.sym_data;
1960 
1961   fprintf (f, "file reference table (FRTE) contains %lu objects:\n\n",
1962 	   sdata->header.dshb_frte.dti_object_count);
1963 
1964   for (i = 1; i <= sdata->header.dshb_frte.dti_object_count; i++)
1965     {
1966       if (bfd_sym_fetch_file_references_table_entry (abfd, &entry, i) < 0)
1967 	fprintf (f, " [%8lu] [INVALID]\n", i);
1968       else
1969 	{
1970 	  fprintf (f, " [%8lu] ", i);
1971 	  bfd_sym_print_file_references_table_entry (abfd, f, &entry);
1972 	  fprintf (f, "\n");
1973 	}
1974     }
1975 }
1976 
1977 void
bfd_sym_display_contained_modules_table(bfd * abfd,FILE * f)1978 bfd_sym_display_contained_modules_table (bfd *abfd, FILE *f)
1979 {
1980   unsigned long i;
1981   bfd_sym_contained_modules_table_entry entry;
1982   bfd_sym_data_struct *sdata = NULL;
1983 
1984   BFD_ASSERT (bfd_sym_valid (abfd));
1985   sdata = abfd->tdata.sym_data;
1986 
1987   fprintf (f, "contained modules table (CMTE) contains %lu objects:\n\n",
1988 	   sdata->header.dshb_cmte.dti_object_count);
1989 
1990   for (i = 1; i <= sdata->header.dshb_cmte.dti_object_count; i++)
1991     {
1992       if (bfd_sym_fetch_contained_modules_table_entry (abfd, &entry, i) < 0)
1993 	fprintf (f, " [%8lu] [INVALID]\n", i);
1994       else
1995 	{
1996 	  fprintf (f, " [%8lu] ", i);
1997 	  bfd_sym_print_contained_modules_table_entry (abfd, f, &entry);
1998 	  fprintf (f, "\n");
1999 	}
2000     }
2001 }
2002 
2003 void
bfd_sym_display_contained_variables_table(bfd * abfd,FILE * f)2004 bfd_sym_display_contained_variables_table (bfd *abfd, FILE *f)
2005 {
2006   unsigned long i;
2007   bfd_sym_contained_variables_table_entry entry;
2008   bfd_sym_data_struct *sdata = NULL;
2009 
2010   BFD_ASSERT (bfd_sym_valid (abfd));
2011   sdata = abfd->tdata.sym_data;
2012 
2013   fprintf (f, "contained variables table (CVTE) contains %lu objects:\n\n",
2014 	   sdata->header.dshb_cvte.dti_object_count);
2015 
2016   for (i = 1; i <= sdata->header.dshb_cvte.dti_object_count; i++)
2017     {
2018       if (bfd_sym_fetch_contained_variables_table_entry (abfd, &entry, i) < 0)
2019 	fprintf (f, " [%8lu] [INVALID]\n", i);
2020       else
2021 	{
2022 	  fprintf (f, " [%8lu] ", i);
2023 	  bfd_sym_print_contained_variables_table_entry (abfd, f, &entry);
2024 	  fprintf (f, "\n");
2025 	}
2026     }
2027 
2028   fprintf (f, "\n");
2029 }
2030 
2031 void
bfd_sym_display_contained_statements_table(bfd * abfd,FILE * f)2032 bfd_sym_display_contained_statements_table (bfd *abfd, FILE *f)
2033 {
2034   unsigned long i;
2035   bfd_sym_contained_statements_table_entry entry;
2036   bfd_sym_data_struct *sdata = NULL;
2037 
2038   BFD_ASSERT (bfd_sym_valid (abfd));
2039   sdata = abfd->tdata.sym_data;
2040 
2041   fprintf (f, "contained statements table (CSNTE) contains %lu objects:\n\n",
2042 	   sdata->header.dshb_csnte.dti_object_count);
2043 
2044   for (i = 1; i <= sdata->header.dshb_csnte.dti_object_count; i++)
2045     {
2046       if (bfd_sym_fetch_contained_statements_table_entry (abfd, &entry, i) < 0)
2047 	fprintf (f, " [%8lu] [INVALID]\n", i);
2048       else
2049 	{
2050 	  fprintf (f, " [%8lu] ", i);
2051 	  bfd_sym_print_contained_statements_table_entry (abfd, f, &entry);
2052 	  fprintf (f, "\n");
2053 	}
2054     }
2055 }
2056 
2057 void
bfd_sym_display_contained_labels_table(bfd * abfd,FILE * f)2058 bfd_sym_display_contained_labels_table (bfd *abfd, FILE *f)
2059 {
2060   unsigned long i;
2061   bfd_sym_contained_labels_table_entry entry;
2062   bfd_sym_data_struct *sdata = NULL;
2063 
2064   BFD_ASSERT (bfd_sym_valid (abfd));
2065   sdata = abfd->tdata.sym_data;
2066 
2067   fprintf (f, "contained labels table (CLTE) contains %lu objects:\n\n",
2068 	   sdata->header.dshb_clte.dti_object_count);
2069 
2070   for (i = 1; i <= sdata->header.dshb_clte.dti_object_count; i++)
2071     {
2072       if (bfd_sym_fetch_contained_labels_table_entry (abfd, &entry, i) < 0)
2073 	fprintf (f, " [%8lu] [INVALID]\n", i);
2074       else
2075 	{
2076 	  fprintf (f, " [%8lu] ", i);
2077 	  bfd_sym_print_contained_labels_table_entry (abfd, f, &entry);
2078 	  fprintf (f, "\n");
2079 	}
2080     }
2081 }
2082 
2083 void
bfd_sym_display_contained_types_table(bfd * abfd,FILE * f)2084 bfd_sym_display_contained_types_table (bfd *abfd, FILE *f)
2085 {
2086   unsigned long i;
2087   bfd_sym_contained_types_table_entry entry;
2088   bfd_sym_data_struct *sdata = NULL;
2089 
2090   BFD_ASSERT (bfd_sym_valid (abfd));
2091   sdata = abfd->tdata.sym_data;
2092 
2093   fprintf (f, "contained types table (CTTE) contains %lu objects:\n\n",
2094 	   sdata->header.dshb_ctte.dti_object_count);
2095 
2096   for (i = 1; i <= sdata->header.dshb_ctte.dti_object_count; i++)
2097     {
2098       if (bfd_sym_fetch_contained_types_table_entry (abfd, &entry, i) < 0)
2099 	fprintf (f, " [%8lu] [INVALID]\n", i);
2100       else
2101 	{
2102 	  fprintf (f, " [%8lu] ", i);
2103 	  bfd_sym_print_contained_types_table_entry (abfd, f, &entry);
2104 	  fprintf (f, "\n");
2105 	}
2106     }
2107 }
2108 
2109 void
bfd_sym_display_file_references_index_table(bfd * abfd,FILE * f)2110 bfd_sym_display_file_references_index_table (bfd *abfd, FILE *f)
2111 {
2112   unsigned long i;
2113   bfd_sym_file_references_index_table_entry entry;
2114   bfd_sym_data_struct *sdata = NULL;
2115 
2116   BFD_ASSERT (bfd_sym_valid (abfd));
2117   sdata = abfd->tdata.sym_data;
2118 
2119   fprintf (f, "file references index table (FITE) contains %lu objects:\n\n",
2120 	   sdata->header.dshb_fite.dti_object_count);
2121 
2122   for (i = 1; i <= sdata->header.dshb_fite.dti_object_count; i++)
2123     {
2124       if (bfd_sym_fetch_file_references_index_table_entry (abfd, &entry, i) < 0)
2125 	fprintf (f, " [%8lu] [INVALID]\n", i);
2126       else
2127 	{
2128 	  fprintf (f, " [%8lu] ", i);
2129 	  bfd_sym_print_file_references_index_table_entry (abfd, f, &entry);
2130 	  fprintf (f, "\n");
2131 	}
2132     }
2133 }
2134 
2135 void
bfd_sym_display_constant_pool(bfd * abfd,FILE * f)2136 bfd_sym_display_constant_pool (bfd *abfd, FILE *f)
2137 {
2138   unsigned long i;
2139   bfd_sym_constant_pool_entry entry;
2140   bfd_sym_data_struct *sdata = NULL;
2141 
2142   BFD_ASSERT (bfd_sym_valid (abfd));
2143   sdata = abfd->tdata.sym_data;
2144 
2145   fprintf (f, "constant pool (CONST) contains %lu objects:\n\n",
2146 	   sdata->header.dshb_const.dti_object_count);
2147 
2148   for (i = 1; i <= sdata->header.dshb_const.dti_object_count; i++)
2149     {
2150       if (bfd_sym_fetch_constant_pool_entry (abfd, &entry, i) < 0)
2151 	fprintf (f, " [%8lu] [INVALID]\n", i);
2152       else
2153 	{
2154 	  fprintf (f, " [%8lu] ", i);
2155 	  bfd_sym_print_constant_pool_entry (abfd, f, &entry);
2156 	  fprintf (f, "\n");
2157 	}
2158     }
2159 }
2160 
2161 void
bfd_sym_display_type_information_table(bfd * abfd,FILE * f)2162 bfd_sym_display_type_information_table (bfd *abfd, FILE *f)
2163 {
2164   unsigned long i;
2165   bfd_sym_type_table_entry sym_index;
2166   bfd_sym_type_information_table_entry entry;
2167   bfd_sym_data_struct *sdata = NULL;
2168 
2169   BFD_ASSERT (bfd_sym_valid (abfd));
2170   sdata = abfd->tdata.sym_data;
2171 
2172   if (sdata->header.dshb_tte.dti_object_count > 99)
2173     fprintf (f, "type table (TINFO) contains %lu objects:\n\n",
2174 	     sdata->header.dshb_tte.dti_object_count - 99);
2175   else
2176     {
2177       fprintf (f, "type table (TINFO) contains [INVALID] objects:\n\n");
2178       return;
2179     }
2180 
2181   for (i = 100; i <= sdata->header.dshb_tte.dti_object_count; i++)
2182     {
2183       if (bfd_sym_fetch_type_table_entry (abfd, &sym_index, i - 100) < 0)
2184 	fprintf (f, " [%8lu] [INVALID]\n", i);
2185       else
2186 	{
2187 	  fprintf (f, " [%8lu] (TINFO %lu) ", i, sym_index);
2188 
2189 	  if (bfd_sym_fetch_type_information_table_entry (abfd, &entry, sym_index) < 0)
2190 	    fprintf (f, "[INVALID]");
2191 	  else
2192 	    bfd_sym_print_type_information_table_entry (abfd, f, &entry);
2193 
2194 	  fprintf (f, "\n");
2195 	}
2196     }
2197 }
2198 
2199 int
bfd_sym_scan(bfd * abfd,bfd_sym_version version,bfd_sym_data_struct * mdata)2200 bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
2201 {
2202   asection *bfdsec;
2203   const char *name = "symbols";
2204 
2205   mdata->name_table = 0;
2206   mdata->sbfd = abfd;
2207   mdata->version = version;
2208 
2209   bfd_seek (abfd, 0, SEEK_SET);
2210   if (bfd_sym_read_header (abfd, &mdata->header, mdata->version) != 0)
2211     return -1;
2212 
2213   mdata->name_table = bfd_sym_read_name_table (abfd, &mdata->header);
2214   if (mdata->name_table == NULL)
2215     return -1;
2216 
2217   bfdsec = bfd_make_section_anyway_with_flags (abfd, name, SEC_HAS_CONTENTS);
2218   if (bfdsec == NULL)
2219     return -1;
2220 
2221   bfdsec->vma = 0;
2222   bfdsec->lma = 0;
2223   bfdsec->size = 0;
2224   bfdsec->filepos = 0;
2225   bfdsec->alignment_power = 0;
2226 
2227   abfd->tdata.sym_data = mdata;
2228 
2229   return 0;
2230 }
2231 
2232 bfd_cleanup
bfd_sym_object_p(bfd * abfd)2233 bfd_sym_object_p (bfd *abfd)
2234 {
2235   bfd_sym_version version = -1;
2236   bfd_sym_data_struct *mdata;
2237 
2238   bfd_seek (abfd, 0, SEEK_SET);
2239   if (bfd_sym_read_version (abfd, &version) != 0)
2240     goto wrong;
2241 
2242   mdata = (bfd_sym_data_struct *) bfd_alloc (abfd, sizeof (*mdata));
2243   if (mdata == NULL)
2244     goto fail;
2245 
2246   if (bfd_sym_scan (abfd, version, mdata) != 0)
2247     goto wrong;
2248 
2249   return _bfd_no_cleanup;
2250 
2251  wrong:
2252   bfd_set_error (bfd_error_wrong_format);
2253 
2254  fail:
2255   return NULL;
2256 }
2257 
2258 #define bfd_sym_make_empty_symbol _bfd_generic_make_empty_symbol
2259 
2260 void
bfd_sym_get_symbol_info(bfd * abfd ATTRIBUTE_UNUSED,asymbol * symbol,symbol_info * ret)2261 bfd_sym_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, asymbol *symbol, symbol_info *ret)
2262 {
2263   bfd_symbol_info (symbol, ret);
2264 }
2265 
2266 long
bfd_sym_get_symtab_upper_bound(bfd * abfd ATTRIBUTE_UNUSED)2267 bfd_sym_get_symtab_upper_bound (bfd *abfd ATTRIBUTE_UNUSED)
2268 {
2269   return 0;
2270 }
2271 
2272 long
bfd_sym_canonicalize_symtab(bfd * abfd ATTRIBUTE_UNUSED,asymbol ** sym ATTRIBUTE_UNUSED)2273 bfd_sym_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, asymbol **sym ATTRIBUTE_UNUSED)
2274 {
2275   return 0;
2276 }
2277 
2278 int
bfd_sym_sizeof_headers(bfd * abfd ATTRIBUTE_UNUSED,struct bfd_link_info * info ATTRIBUTE_UNUSED)2279 bfd_sym_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
2280 			struct bfd_link_info *info ATTRIBUTE_UNUSED)
2281 {
2282   return 0;
2283 }
2284 
2285 const bfd_target sym_vec =
2286 {
2287   "sym",			/* Name.  */
2288   bfd_target_sym_flavour,	/* Flavour.  */
2289   BFD_ENDIAN_BIG,		/* Byteorder.  */
2290   BFD_ENDIAN_BIG,		/* Header byteorder.  */
2291   (HAS_RELOC | EXEC_P |		/* Object flags.  */
2292    HAS_LINENO | HAS_DEBUG |
2293    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
2294   (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | SEC_DATA
2295    | SEC_ROM | SEC_HAS_CONTENTS), /* Section_flags.  */
2296   0,				/* Symbol_leading_char.  */
2297   ' ',				/* AR_pad_char.  */
2298   16,				/* AR_max_namelen.  */
2299   0,				/* match priority.  */
2300   TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
2301   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2302   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2303   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Data.  */
2304   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2305   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2306   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Hdrs.  */
2307   {				/* bfd_check_format.  */
2308     _bfd_dummy_target,
2309     bfd_sym_object_p,		/* bfd_check_format.  */
2310     _bfd_dummy_target,
2311     _bfd_dummy_target,
2312   },
2313   {				/* bfd_set_format.  */
2314     _bfd_bool_bfd_false_error,
2315     bfd_sym_mkobject,
2316     _bfd_bool_bfd_false_error,
2317     _bfd_bool_bfd_false_error,
2318   },
2319   {				/* bfd_write_contents.  */
2320     _bfd_bool_bfd_false_error,
2321     _bfd_bool_bfd_true,
2322     _bfd_bool_bfd_false_error,
2323     _bfd_bool_bfd_false_error,
2324   },
2325 
2326   BFD_JUMP_TABLE_GENERIC (bfd_sym),
2327   BFD_JUMP_TABLE_COPY (_bfd_generic),
2328   BFD_JUMP_TABLE_CORE (_bfd_nocore),
2329   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
2330   BFD_JUMP_TABLE_SYMBOLS (bfd_sym),
2331   BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
2332   BFD_JUMP_TABLE_WRITE (bfd_sym),
2333   BFD_JUMP_TABLE_LINK (bfd_sym),
2334   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2335 
2336   NULL,
2337 
2338   NULL
2339 };
2340