xsym.c 61 KB

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