xcoffout.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /* Output xcoff-format symbol table information from GNU compiler.
  2. Copyright (C) 1992-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* Output xcoff-format symbol table data. The main functionality is contained
  16. in dbxout.c. This file implements the sdbout-like parts of the xcoff
  17. interface. Many functions are very similar to their counterparts in
  18. sdbout.c. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "tm.h"
  23. #include "hash-set.h"
  24. #include "machmode.h"
  25. #include "vec.h"
  26. #include "double-int.h"
  27. #include "input.h"
  28. #include "alias.h"
  29. #include "symtab.h"
  30. #include "wide-int.h"
  31. #include "inchash.h"
  32. #include "tree.h"
  33. #include "varasm.h"
  34. #include "rtl.h"
  35. #include "flags.h"
  36. #include "diagnostic-core.h"
  37. #include "output.h"
  38. #include "ggc.h"
  39. #include "target.h"
  40. #include "debug.h"
  41. #ifdef XCOFF_DEBUGGING_INFO
  42. /* This defines the C_* storage classes. */
  43. #include "xcoff.h"
  44. #include "xcoffout.h"
  45. #include "dbxout.h"
  46. #include "gstab.h"
  47. /* Line number of beginning of current function, minus one.
  48. Negative means not in a function or not using xcoff. */
  49. static int xcoff_begin_function_line = -1;
  50. static int xcoff_inlining = 0;
  51. /* Name of the current include file. */
  52. const char *xcoff_current_include_file;
  53. /* Name of the current function file. This is the file the `.bf' is
  54. emitted from. In case a line is emitted from a different file,
  55. (by including that file of course), then the line number will be
  56. absolute. */
  57. static const char *xcoff_current_function_file;
  58. /* Names of bss and data sections. These should be unique names for each
  59. compilation unit. */
  60. char *xcoff_bss_section_name;
  61. char *xcoff_private_data_section_name;
  62. char *xcoff_tls_data_section_name;
  63. char *xcoff_tbss_section_name;
  64. char *xcoff_read_only_section_name;
  65. /* Last source file name mentioned in a NOTE insn. */
  66. const char *xcoff_lastfile;
  67. /* Macro definitions used below. */
  68. #define ABS_OR_RELATIVE_LINENO(LINENO) \
  69. ((xcoff_inlining) ? (LINENO) : (LINENO) - xcoff_begin_function_line)
  70. /* Output source line numbers via ".line". */
  71. #define ASM_OUTPUT_LINE(FILE,LINENUM) \
  72. do \
  73. { \
  74. /* Make sure we're in a function and prevent output of .line 0, as \
  75. line # 0 is meant for symbol addresses in xcoff. Additionally, \
  76. line numbers are 'unsigned short' in 32-bit mode. */ \
  77. if (xcoff_begin_function_line >= 0) \
  78. { \
  79. int lno = ABS_OR_RELATIVE_LINENO (LINENUM); \
  80. if (lno > 0 && (TARGET_64BIT || lno <= (int)USHRT_MAX)) \
  81. fprintf (FILE, "\t.line\t%d\n", lno); \
  82. } \
  83. } \
  84. while (0)
  85. #define ASM_OUTPUT_LFB(FILE,LINENUM) \
  86. { \
  87. if (xcoff_begin_function_line == -1) \
  88. { \
  89. xcoff_begin_function_line = (LINENUM) - 1;\
  90. fprintf (FILE, "\t.bf\t%d\n", (LINENUM)); \
  91. } \
  92. xcoff_current_function_file \
  93. = (xcoff_current_include_file \
  94. ? xcoff_current_include_file : main_input_filename); \
  95. }
  96. #define ASM_OUTPUT_LFE(FILE,LINENUM) \
  97. do \
  98. { \
  99. fprintf (FILE, "\t.ef\t%d\n", (LINENUM)); \
  100. xcoff_begin_function_line = -1; \
  101. } \
  102. while (0)
  103. #define ASM_OUTPUT_LBB(FILE,LINENUM,BLOCKNUM) \
  104. fprintf (FILE, "\t.bb\t%d\n", ABS_OR_RELATIVE_LINENO (LINENUM))
  105. #define ASM_OUTPUT_LBE(FILE,LINENUM,BLOCKNUM) \
  106. fprintf (FILE, "\t.eb\t%d\n", ABS_OR_RELATIVE_LINENO (LINENUM))
  107. static void xcoffout_block (tree, int, tree);
  108. static void xcoffout_source_file (FILE *, const char *, int);
  109. /* Support routines for XCOFF debugging info. */
  110. struct xcoff_type_number
  111. {
  112. const char *name;
  113. int number;
  114. };
  115. static const struct xcoff_type_number xcoff_type_numbers[] = {
  116. { "int", -1 },
  117. { "char", -2 },
  118. { "short int", -3 },
  119. { "long int", -4 }, /* fiddled to -31 if 64 bits */
  120. { "unsigned char", -5 },
  121. { "signed char", -6 },
  122. { "short unsigned int", -7 },
  123. { "unsigned int", -8 },
  124. /* No such type "unsigned". */
  125. { "long unsigned int", -10 }, /* fiddled to -32 if 64 bits */
  126. { "void", -11 },
  127. { "float", -12 },
  128. { "double", -13 },
  129. { "long double", -14 },
  130. /* Pascal and Fortran types run from -15 to -29. */
  131. { "wchar", -30 }, /* XXX Should be "wchar_t" ? */
  132. { "long long int", -31 },
  133. { "long long unsigned int", -32 },
  134. /* Additional Fortran types run from -33 to -37. */
  135. /* ??? Should also handle built-in C++ and Obj-C types. There perhaps
  136. aren't any that C doesn't already have. */
  137. };
  138. /* Returns an XCOFF fundamental type number for DECL (assumed to be a
  139. TYPE_DECL), or 0 if dbxout.c should assign a type number normally. */
  140. int
  141. xcoff_assign_fundamental_type_number (tree decl)
  142. {
  143. const char *name;
  144. size_t i;
  145. /* Do not waste time searching the list for non-intrinsic types. */
  146. if (DECL_NAME (decl) == 0 || ! DECL_IS_BUILTIN (decl))
  147. return 0;
  148. name = IDENTIFIER_POINTER (DECL_NAME (decl));
  149. /* Linear search, blech, but the list is too small to bother
  150. doing anything else. */
  151. for (i = 0; i < ARRAY_SIZE (xcoff_type_numbers); i++)
  152. if (!strcmp (xcoff_type_numbers[i].name, name))
  153. goto found;
  154. return 0;
  155. found:
  156. /* -4 and -10 should be replaced with -31 and -32, respectively,
  157. when used for a 64-bit type. */
  158. if (int_size_in_bytes (TREE_TYPE (decl)) == 8)
  159. {
  160. if (xcoff_type_numbers[i].number == -4)
  161. return -31;
  162. if (xcoff_type_numbers[i].number == -10)
  163. return -32;
  164. }
  165. return xcoff_type_numbers[i].number;
  166. }
  167. /* Print an error message for unrecognized stab codes. */
  168. #define UNKNOWN_STAB(STR) \
  169. internal_error ("no sclass for %s stab (0x%x)", STR, stab)
  170. /* Conversion routine from BSD stabs to AIX storage classes. */
  171. int
  172. stab_to_sclass (int stab)
  173. {
  174. switch (stab)
  175. {
  176. case N_GSYM:
  177. return C_GSYM;
  178. case N_FNAME:
  179. UNKNOWN_STAB ("N_FNAME");
  180. case N_FUN:
  181. return C_FUN;
  182. case N_STSYM:
  183. case N_LCSYM:
  184. return C_STSYM;
  185. case N_MAIN:
  186. UNKNOWN_STAB ("N_MAIN");
  187. case N_RSYM:
  188. return C_RSYM;
  189. case N_SSYM:
  190. UNKNOWN_STAB ("N_SSYM");
  191. case N_RPSYM:
  192. return C_RPSYM;
  193. case N_PSYM:
  194. return C_PSYM;
  195. case N_LSYM:
  196. return C_LSYM;
  197. case N_DECL:
  198. return C_DECL;
  199. case N_ENTRY:
  200. return C_ENTRY;
  201. case N_SO:
  202. UNKNOWN_STAB ("N_SO");
  203. case N_SOL:
  204. UNKNOWN_STAB ("N_SOL");
  205. case N_SLINE:
  206. UNKNOWN_STAB ("N_SLINE");
  207. case N_DSLINE:
  208. UNKNOWN_STAB ("N_DSLINE");
  209. case N_BSLINE:
  210. UNKNOWN_STAB ("N_BSLINE");
  211. case N_BINCL:
  212. UNKNOWN_STAB ("N_BINCL");
  213. case N_EINCL:
  214. UNKNOWN_STAB ("N_EINCL");
  215. case N_EXCL:
  216. UNKNOWN_STAB ("N_EXCL");
  217. case N_LBRAC:
  218. UNKNOWN_STAB ("N_LBRAC");
  219. case N_RBRAC:
  220. UNKNOWN_STAB ("N_RBRAC");
  221. case N_BCOMM:
  222. return C_BCOMM;
  223. case N_ECOMM:
  224. return C_ECOMM;
  225. case N_ECOML:
  226. return C_ECOML;
  227. case N_LENG:
  228. UNKNOWN_STAB ("N_LENG");
  229. case N_PC:
  230. UNKNOWN_STAB ("N_PC");
  231. case N_M2C:
  232. UNKNOWN_STAB ("N_M2C");
  233. case N_SCOPE:
  234. UNKNOWN_STAB ("N_SCOPE");
  235. case N_CATCH:
  236. UNKNOWN_STAB ("N_CATCH");
  237. case N_OPT:
  238. UNKNOWN_STAB ("N_OPT");
  239. default:
  240. UNKNOWN_STAB ("?");
  241. }
  242. }
  243. /* Output debugging info to FILE to switch to sourcefile FILENAME.
  244. INLINE_P is true if this is from an inlined function. */
  245. static void
  246. xcoffout_source_file (FILE *file, const char *filename, int inline_p)
  247. {
  248. if (filename
  249. && (xcoff_lastfile == 0 || strcmp (filename, xcoff_lastfile)
  250. || (inline_p && ! xcoff_inlining)
  251. || (! inline_p && xcoff_inlining)))
  252. {
  253. if (xcoff_current_include_file)
  254. {
  255. fprintf (file, "\t.ei\t");
  256. output_quoted_string (file,
  257. remap_debug_filename (xcoff_current_include_file));
  258. fprintf (file, "\n");
  259. xcoff_current_include_file = NULL;
  260. }
  261. xcoff_inlining = inline_p;
  262. if (strcmp (main_input_filename, filename) || inline_p)
  263. {
  264. fprintf (file, "\t.bi\t");
  265. output_quoted_string (file, remap_debug_filename (filename));
  266. fprintf (file, "\n");
  267. xcoff_current_include_file = filename;
  268. }
  269. xcoff_lastfile = filename;
  270. }
  271. }
  272. /* Output a line number symbol entry for location (FILENAME, LINE). */
  273. void
  274. xcoffout_source_line (unsigned int line, const char *filename,
  275. int discriminator ATTRIBUTE_UNUSED,
  276. bool is_stmt ATTRIBUTE_UNUSED)
  277. {
  278. bool inline_p = (strcmp (xcoff_current_function_file, filename) != 0
  279. || (int) line < xcoff_begin_function_line);
  280. xcoffout_source_file (asm_out_file, filename, inline_p);
  281. ASM_OUTPUT_LINE (asm_out_file, line);
  282. }
  283. /* Output the symbols defined in block number DO_BLOCK.
  284. This function works by walking the tree structure of blocks,
  285. counting blocks until it finds the desired block. */
  286. static int do_block = 0;
  287. static void
  288. xcoffout_block (tree block, int depth, tree args)
  289. {
  290. while (block)
  291. {
  292. /* Ignore blocks never expanded or otherwise marked as real. */
  293. if (TREE_USED (block))
  294. {
  295. /* When we reach the specified block, output its symbols. */
  296. if (BLOCK_NUMBER (block) == do_block)
  297. {
  298. /* Output the syms of the block. */
  299. if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
  300. dbxout_syms (BLOCK_VARS (block));
  301. if (args)
  302. dbxout_reg_parms (args);
  303. /* We are now done with the block. Don't go to inner blocks. */
  304. return;
  305. }
  306. /* If we are past the specified block, stop the scan. */
  307. else if (BLOCK_NUMBER (block) >= do_block)
  308. return;
  309. /* Output the subblocks. */
  310. xcoffout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
  311. }
  312. block = BLOCK_CHAIN (block);
  313. }
  314. }
  315. /* Describe the beginning of an internal block within a function.
  316. Also output descriptions of variables defined in this block.
  317. N is the number of the block, by order of beginning, counting from 1,
  318. and not counting the outermost (function top-level) block.
  319. The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
  320. if the count starts at 0 for the outermost one. */
  321. void
  322. xcoffout_begin_block (unsigned int line, unsigned int n)
  323. {
  324. tree decl = current_function_decl;
  325. /* The IBM AIX compiler does not emit a .bb for the function level scope,
  326. so we avoid it here also. */
  327. if (n != 1)
  328. ASM_OUTPUT_LBB (asm_out_file, line, n);
  329. do_block = n;
  330. xcoffout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
  331. }
  332. /* Describe the end line-number of an internal block within a function. */
  333. void
  334. xcoffout_end_block (unsigned int line, unsigned int n)
  335. {
  336. if (n != 1)
  337. ASM_OUTPUT_LBE (asm_out_file, line, n);
  338. }
  339. /* Called at beginning of function (before prologue).
  340. Declare function as needed for debugging. */
  341. void
  342. xcoffout_declare_function (FILE *file, tree decl, const char *name)
  343. {
  344. size_t len;
  345. if (*name == '*')
  346. name++;
  347. len = strlen (name);
  348. if (name[len - 1] == ']')
  349. {
  350. char *n = XALLOCAVEC (char, len - 3);
  351. memcpy (n, name, len - 4);
  352. n[len - 4] = '\0';
  353. name = n;
  354. }
  355. /* Any pending .bi or .ei must occur before the .function pseudo op.
  356. Otherwise debuggers will think that the function is in the previous
  357. file and/or at the wrong line number. */
  358. xcoffout_source_file (file, DECL_SOURCE_FILE (decl), 0);
  359. dbxout_symbol (decl, 0);
  360. /* .function NAME, TOP, MAPPING, TYPE, SIZE
  361. 16 and 044 are placeholders for backwards compatibility */
  362. fprintf (file, "\t.function .%s,.%s,16,044,FE..%s-.%s\n",
  363. name, name, name, name);
  364. }
  365. /* Called at beginning of function body (at start of prologue).
  366. Record the function's starting line number, so we can output
  367. relative line numbers for the other lines.
  368. Record the file name that this function is contained in. */
  369. void
  370. xcoffout_begin_prologue (unsigned int line,
  371. const char *file ATTRIBUTE_UNUSED)
  372. {
  373. ASM_OUTPUT_LFB (asm_out_file, line);
  374. dbxout_parms (DECL_ARGUMENTS (current_function_decl));
  375. /* Emit the symbols for the outermost BLOCK's variables. sdbout.c does this
  376. in sdbout_begin_block, but there is no guarantee that there will be any
  377. inner block 1, so we must do it here. This gives a result similar to
  378. dbxout, so it does make some sense. */
  379. do_block = BLOCK_NUMBER (DECL_INITIAL (current_function_decl));
  380. xcoffout_block (DECL_INITIAL (current_function_decl), 0,
  381. DECL_ARGUMENTS (current_function_decl));
  382. ASM_OUTPUT_LINE (asm_out_file, line);
  383. }
  384. /* Called at end of function (before epilogue).
  385. Describe end of outermost block. */
  386. void
  387. xcoffout_end_function (unsigned int last_linenum)
  388. {
  389. ASM_OUTPUT_LFE (asm_out_file, last_linenum);
  390. }
  391. /* Output xcoff info for the absolute end of a function.
  392. Called after the epilogue is output. */
  393. void
  394. xcoffout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
  395. const char *file ATTRIBUTE_UNUSED)
  396. {
  397. /* We need to pass the correct function size to .function, otherwise,
  398. the xas assembler can't figure out the correct size for the function
  399. aux entry. So, we emit a label after the last instruction which can
  400. be used by the .function pseudo op to calculate the function size. */
  401. const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
  402. if (*fname == '*')
  403. ++fname;
  404. fprintf (asm_out_file, "FE..");
  405. ASM_OUTPUT_LABEL (asm_out_file, fname);
  406. }
  407. #endif /* XCOFF_DEBUGGING_INFO */