stackleak_plugin.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright 2011-2017 by the PaX Team <[email protected]>
  3. * Modified by Alexander Popov <[email protected]>
  4. * Licensed under the GPL v2
  5. *
  6. * Note: the choice of the license means that the compilation process is
  7. * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
  8. * but for the kernel it doesn't matter since it doesn't link against
  9. * any of the gcc libraries
  10. *
  11. * This gcc plugin is needed for tracking the lowest border of the kernel stack.
  12. * It instruments the kernel code inserting stackleak_track_stack() calls:
  13. * - after alloca();
  14. * - for the functions with a stack frame size greater than or equal
  15. * to the "track-min-size" plugin parameter.
  16. *
  17. * This plugin is ported from grsecurity/PaX. For more information see:
  18. * https://grsecurity.net/
  19. * https://pax.grsecurity.net/
  20. *
  21. * Debugging:
  22. * - use fprintf() to stderr, debug_generic_expr(), debug_gimple_stmt(),
  23. * print_rtl_single() and debug_rtx();
  24. * - add "-fdump-tree-all -fdump-rtl-all" to the plugin CFLAGS in
  25. * Makefile.gcc-plugins to see the verbose dumps of the gcc passes;
  26. * - use gcc -E to understand the preprocessing shenanigans;
  27. * - use gcc with enabled CFG/GIMPLE/SSA verification (--enable-checking).
  28. */
  29. #include "gcc-common.h"
  30. __visible int plugin_is_GPL_compatible;
  31. static int track_frame_size = -1;
  32. static bool build_for_x86 = false;
  33. static const char track_function[] = "stackleak_track_stack";
  34. static bool disable = false;
  35. static bool verbose = false;
  36. /*
  37. * Mark these global variables (roots) for gcc garbage collector since
  38. * they point to the garbage-collected memory.
  39. */
  40. static GTY(()) tree track_function_decl;
  41. static struct plugin_info stackleak_plugin_info = {
  42. .version = "201707101337",
  43. .help = "track-min-size=nn\ttrack stack for functions with a stack frame size >= nn bytes\n"
  44. "arch=target_arch\tspecify target build arch\n"
  45. "disable\t\tdo not activate the plugin\n"
  46. "verbose\t\tprint info about the instrumentation\n"
  47. };
  48. static void add_stack_tracking_gcall(gimple_stmt_iterator *gsi, bool after)
  49. {
  50. gimple stmt;
  51. gcall *gimple_call;
  52. cgraph_node_ptr node;
  53. basic_block bb;
  54. /* Insert calling stackleak_track_stack() */
  55. stmt = gimple_build_call(track_function_decl, 0);
  56. gimple_call = as_a_gcall(stmt);
  57. if (after)
  58. gsi_insert_after(gsi, gimple_call, GSI_CONTINUE_LINKING);
  59. else
  60. gsi_insert_before(gsi, gimple_call, GSI_SAME_STMT);
  61. /* Update the cgraph */
  62. bb = gimple_bb(gimple_call);
  63. node = cgraph_get_create_node(track_function_decl);
  64. gcc_assert(node);
  65. cgraph_create_edge(cgraph_get_node(current_function_decl), node,
  66. gimple_call, bb->count,
  67. compute_call_stmt_bb_frequency(current_function_decl, bb));
  68. }
  69. static bool is_alloca(gimple stmt)
  70. {
  71. if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
  72. return true;
  73. #if BUILDING_GCC_VERSION >= 4007
  74. if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
  75. return true;
  76. #endif
  77. return false;
  78. }
  79. static tree get_current_stack_pointer_decl(void)
  80. {
  81. varpool_node_ptr node;
  82. FOR_EACH_VARIABLE(node) {
  83. tree var = NODE_DECL(node);
  84. tree name = DECL_NAME(var);
  85. if (DECL_NAME_LENGTH(var) != sizeof("current_stack_pointer") - 1)
  86. continue;
  87. if (strcmp(IDENTIFIER_POINTER(name), "current_stack_pointer"))
  88. continue;
  89. return var;
  90. }
  91. if (verbose) {
  92. fprintf(stderr, "stackleak: missing current_stack_pointer in %s()\n",
  93. DECL_NAME_POINTER(current_function_decl));
  94. }
  95. return NULL_TREE;
  96. }
  97. static void add_stack_tracking_gasm(gimple_stmt_iterator *gsi, bool after)
  98. {
  99. gasm *asm_call = NULL;
  100. tree sp_decl, input;
  101. vec<tree, va_gc> *inputs = NULL;
  102. /* 'no_caller_saved_registers' is currently supported only for x86 */
  103. gcc_assert(build_for_x86);
  104. /*
  105. * Insert calling stackleak_track_stack() in asm:
  106. * asm volatile("call stackleak_track_stack"
  107. * :: "r" (current_stack_pointer))
  108. * Use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h.
  109. * This constraint is taken into account during gcc shrink-wrapping
  110. * optimization. It is needed to be sure that stackleak_track_stack()
  111. * call is inserted after the prologue of the containing function,
  112. * when the stack frame is prepared.
  113. */
  114. sp_decl = get_current_stack_pointer_decl();
  115. if (sp_decl == NULL_TREE) {
  116. add_stack_tracking_gcall(gsi, after);
  117. return;
  118. }
  119. input = build_tree_list(NULL_TREE, build_const_char_string(2, "r"));
  120. input = chainon(NULL_TREE, build_tree_list(input, sp_decl));
  121. vec_safe_push(inputs, input);
  122. asm_call = gimple_build_asm_vec("call stackleak_track_stack",
  123. inputs, NULL, NULL, NULL);
  124. gimple_asm_set_volatile(asm_call, true);
  125. if (after)
  126. gsi_insert_after(gsi, asm_call, GSI_CONTINUE_LINKING);
  127. else
  128. gsi_insert_before(gsi, asm_call, GSI_SAME_STMT);
  129. update_stmt(asm_call);
  130. }
  131. static void add_stack_tracking(gimple_stmt_iterator *gsi, bool after)
  132. {
  133. /*
  134. * The 'no_caller_saved_registers' attribute is used for
  135. * stackleak_track_stack(). If the compiler supports this attribute for
  136. * the target arch, we can add calling stackleak_track_stack() in asm.
  137. * That improves performance: we avoid useless operations with the
  138. * caller-saved registers in the functions from which we will remove
  139. * stackleak_track_stack() call during the stackleak_cleanup pass.
  140. */
  141. if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
  142. add_stack_tracking_gasm(gsi, after);
  143. else
  144. add_stack_tracking_gcall(gsi, after);
  145. }
  146. /*
  147. * Work with the GIMPLE representation of the code. Insert the
  148. * stackleak_track_stack() call after alloca() and into the beginning
  149. * of the function if it is not instrumented.
  150. */
  151. static unsigned int stackleak_instrument_execute(void)
  152. {
  153. basic_block bb, entry_bb;
  154. bool prologue_instrumented = false, is_leaf = true;
  155. gimple_stmt_iterator gsi = { 0 };
  156. /*
  157. * ENTRY_BLOCK_PTR is a basic block which represents possible entry
  158. * point of a function. This block does not contain any code and
  159. * has a CFG edge to its successor.
  160. */
  161. gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
  162. entry_bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
  163. /*
  164. * Loop through the GIMPLE statements in each of cfun basic blocks.
  165. * cfun is a global variable which represents the function that is
  166. * currently processed.
  167. */
  168. FOR_EACH_BB_FN(bb, cfun) {
  169. for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
  170. gimple stmt;
  171. stmt = gsi_stmt(gsi);
  172. /* Leaf function is a function which makes no calls */
  173. if (is_gimple_call(stmt))
  174. is_leaf = false;
  175. if (!is_alloca(stmt))
  176. continue;
  177. if (verbose) {
  178. fprintf(stderr, "stackleak: be careful, alloca() in %s()\n",
  179. DECL_NAME_POINTER(current_function_decl));
  180. }
  181. /* Insert stackleak_track_stack() call after alloca() */
  182. add_stack_tracking(&gsi, true);
  183. if (bb == entry_bb)
  184. prologue_instrumented = true;
  185. }
  186. }
  187. if (prologue_instrumented)
  188. return 0;
  189. /*
  190. * Special cases to skip the instrumentation.
  191. *
  192. * Taking the address of static inline functions materializes them,
  193. * but we mustn't instrument some of them as the resulting stack
  194. * alignment required by the function call ABI will break other
  195. * assumptions regarding the expected (but not otherwise enforced)
  196. * register clobbering ABI.
  197. *
  198. * Case in point: native_save_fl on amd64 when optimized for size
  199. * clobbers rdx if it were instrumented here.
  200. *
  201. * TODO: any more special cases?
  202. */
  203. if (is_leaf &&
  204. !TREE_PUBLIC(current_function_decl) &&
  205. DECL_DECLARED_INLINE_P(current_function_decl)) {
  206. return 0;
  207. }
  208. if (is_leaf &&
  209. !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)),
  210. "_paravirt_", 10)) {
  211. return 0;
  212. }
  213. /* Insert stackleak_track_stack() call at the function beginning */
  214. bb = entry_bb;
  215. if (!single_pred_p(bb)) {
  216. /* gcc_assert(bb_loop_depth(bb) ||
  217. (bb->flags & BB_IRREDUCIBLE_LOOP)); */
  218. split_edge(single_succ_edge(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
  219. gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
  220. bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
  221. }
  222. gsi = gsi_after_labels(bb);
  223. add_stack_tracking(&gsi, false);
  224. return 0;
  225. }
  226. static bool large_stack_frame(void)
  227. {
  228. #if BUILDING_GCC_VERSION >= 8000
  229. return maybe_ge(get_frame_size(), track_frame_size);
  230. #else
  231. return (get_frame_size() >= track_frame_size);
  232. #endif
  233. }
  234. static void remove_stack_tracking_gcall(void)
  235. {
  236. rtx_insn *insn, *next;
  237. /*
  238. * Find stackleak_track_stack() calls. Loop through the chain of insns,
  239. * which is an RTL representation of the code for a function.
  240. *
  241. * The example of a matching insn:
  242. * (call_insn 8 4 10 2 (call (mem (symbol_ref ("stackleak_track_stack")
  243. * [flags 0x41] <function_decl 0x7f7cd3302a80 stackleak_track_stack>)
  244. * [0 stackleak_track_stack S1 A8]) (0)) 675 {*call} (expr_list
  245. * (symbol_ref ("stackleak_track_stack") [flags 0x41] <function_decl
  246. * 0x7f7cd3302a80 stackleak_track_stack>) (expr_list (0) (nil))) (nil))
  247. */
  248. for (insn = get_insns(); insn; insn = next) {
  249. rtx body;
  250. next = NEXT_INSN(insn);
  251. /* Check the expression code of the insn */
  252. if (!CALL_P(insn))
  253. continue;
  254. /*
  255. * Check the expression code of the insn body, which is an RTL
  256. * Expression (RTX) describing the side effect performed by
  257. * that insn.
  258. */
  259. body = PATTERN(insn);
  260. if (GET_CODE(body) == PARALLEL)
  261. body = XVECEXP(body, 0, 0);
  262. if (GET_CODE(body) != CALL)
  263. continue;
  264. /*
  265. * Check the first operand of the call expression. It should
  266. * be a mem RTX describing the needed subroutine with a
  267. * symbol_ref RTX.
  268. */
  269. body = XEXP(body, 0);
  270. if (GET_CODE(body) != MEM)
  271. continue;
  272. body = XEXP(body, 0);
  273. if (GET_CODE(body) != SYMBOL_REF)
  274. continue;
  275. if (SYMBOL_REF_DECL(body) != track_function_decl)
  276. continue;
  277. /* Delete the stackleak_track_stack() call */
  278. delete_insn_and_edges(insn);
  279. #if BUILDING_GCC_VERSION >= 4007 && BUILDING_GCC_VERSION < 8000
  280. if (GET_CODE(next) == NOTE &&
  281. NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
  282. insn = next;
  283. next = NEXT_INSN(insn);
  284. delete_insn_and_edges(insn);
  285. }
  286. #endif
  287. }
  288. }
  289. static bool remove_stack_tracking_gasm(void)
  290. {
  291. bool removed = false;
  292. rtx_insn *insn, *next;
  293. /* 'no_caller_saved_registers' is currently supported only for x86 */
  294. gcc_assert(build_for_x86);
  295. /*
  296. * Find stackleak_track_stack() asm calls. Loop through the chain of
  297. * insns, which is an RTL representation of the code for a function.
  298. *
  299. * The example of a matching insn:
  300. * (insn 11 5 12 2 (parallel [ (asm_operands/v
  301. * ("call stackleak_track_stack") ("") 0
  302. * [ (reg/v:DI 7 sp [ current_stack_pointer ]) ]
  303. * [ (asm_input:DI ("r")) ] [])
  304. * (clobber (reg:CC 17 flags)) ]) -1 (nil))
  305. */
  306. for (insn = get_insns(); insn; insn = next) {
  307. rtx body;
  308. next = NEXT_INSN(insn);
  309. /* Check the expression code of the insn */
  310. if (!NONJUMP_INSN_P(insn))
  311. continue;
  312. /*
  313. * Check the expression code of the insn body, which is an RTL
  314. * Expression (RTX) describing the side effect performed by
  315. * that insn.
  316. */
  317. body = PATTERN(insn);
  318. if (GET_CODE(body) != PARALLEL)
  319. continue;
  320. body = XVECEXP(body, 0, 0);
  321. if (GET_CODE(body) != ASM_OPERANDS)
  322. continue;
  323. if (strcmp(ASM_OPERANDS_TEMPLATE(body),
  324. "call stackleak_track_stack")) {
  325. continue;
  326. }
  327. delete_insn_and_edges(insn);
  328. gcc_assert(!removed);
  329. removed = true;
  330. }
  331. return removed;
  332. }
  333. /*
  334. * Work with the RTL representation of the code.
  335. * Remove the unneeded stackleak_track_stack() calls from the functions
  336. * which don't call alloca() and don't have a large enough stack frame size.
  337. */
  338. static unsigned int stackleak_cleanup_execute(void)
  339. {
  340. const char *fn = DECL_NAME_POINTER(current_function_decl);
  341. bool removed = false;
  342. /*
  343. * Leave stack tracking in functions that call alloca().
  344. * Additional case:
  345. * gcc before version 7 called allocate_dynamic_stack_space() from
  346. * expand_stack_vars() for runtime alignment of constant-sized stack
  347. * variables. That caused cfun->calls_alloca to be set for functions
  348. * that in fact don't use alloca().
  349. * For more info see gcc commit 7072df0aae0c59ae437e.
  350. * Let's leave such functions instrumented as well.
  351. */
  352. if (cfun->calls_alloca) {
  353. if (verbose)
  354. fprintf(stderr, "stackleak: instrument %s(): calls_alloca\n", fn);
  355. return 0;
  356. }
  357. /* Leave stack tracking in functions with large stack frame */
  358. if (large_stack_frame()) {
  359. if (verbose)
  360. fprintf(stderr, "stackleak: instrument %s()\n", fn);
  361. return 0;
  362. }
  363. if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
  364. removed = remove_stack_tracking_gasm();
  365. if (!removed)
  366. remove_stack_tracking_gcall();
  367. return 0;
  368. }
  369. /*
  370. * STRING_CST may or may not be NUL terminated:
  371. * https://gcc.gnu.org/onlinedocs/gccint/Constant-expressions.html
  372. */
  373. static inline bool string_equal(tree node, const char *string, int length)
  374. {
  375. if (TREE_STRING_LENGTH(node) < length)
  376. return false;
  377. if (TREE_STRING_LENGTH(node) > length + 1)
  378. return false;
  379. if (TREE_STRING_LENGTH(node) == length + 1 &&
  380. TREE_STRING_POINTER(node)[length] != '\0')
  381. return false;
  382. return !memcmp(TREE_STRING_POINTER(node), string, length);
  383. }
  384. #define STRING_EQUAL(node, str) string_equal(node, str, strlen(str))
  385. static bool stackleak_gate(void)
  386. {
  387. tree section;
  388. section = lookup_attribute("section",
  389. DECL_ATTRIBUTES(current_function_decl));
  390. if (section && TREE_VALUE(section)) {
  391. section = TREE_VALUE(TREE_VALUE(section));
  392. if (STRING_EQUAL(section, ".init.text"))
  393. return false;
  394. if (STRING_EQUAL(section, ".devinit.text"))
  395. return false;
  396. if (STRING_EQUAL(section, ".cpuinit.text"))
  397. return false;
  398. if (STRING_EQUAL(section, ".meminit.text"))
  399. return false;
  400. }
  401. return track_frame_size >= 0;
  402. }
  403. /* Build the function declaration for stackleak_track_stack() */
  404. static void stackleak_start_unit(void *gcc_data __unused,
  405. void *user_data __unused)
  406. {
  407. tree fntype;
  408. /* void stackleak_track_stack(void) */
  409. fntype = build_function_type_list(void_type_node, NULL_TREE);
  410. track_function_decl = build_fn_decl(track_function, fntype);
  411. DECL_ASSEMBLER_NAME(track_function_decl); /* for LTO */
  412. TREE_PUBLIC(track_function_decl) = 1;
  413. TREE_USED(track_function_decl) = 1;
  414. DECL_EXTERNAL(track_function_decl) = 1;
  415. DECL_ARTIFICIAL(track_function_decl) = 1;
  416. DECL_PRESERVE_P(track_function_decl) = 1;
  417. }
  418. /*
  419. * Pass gate function is a predicate function that gets executed before the
  420. * corresponding pass. If the return value is 'true' the pass gets executed,
  421. * otherwise, it is skipped.
  422. */
  423. static bool stackleak_instrument_gate(void)
  424. {
  425. return stackleak_gate();
  426. }
  427. #define PASS_NAME stackleak_instrument
  428. #define PROPERTIES_REQUIRED PROP_gimple_leh | PROP_cfg
  429. #define TODO_FLAGS_START TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts
  430. #define TODO_FLAGS_FINISH TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func \
  431. | TODO_update_ssa | TODO_rebuild_cgraph_edges
  432. #include "gcc-generate-gimple-pass.h"
  433. static bool stackleak_cleanup_gate(void)
  434. {
  435. return stackleak_gate();
  436. }
  437. #define PASS_NAME stackleak_cleanup
  438. #define TODO_FLAGS_FINISH TODO_dump_func
  439. #include "gcc-generate-rtl-pass.h"
  440. /*
  441. * Every gcc plugin exports a plugin_init() function that is called right
  442. * after the plugin is loaded. This function is responsible for registering
  443. * the plugin callbacks and doing other required initialization.
  444. */
  445. __visible int plugin_init(struct plugin_name_args *plugin_info,
  446. struct plugin_gcc_version *version)
  447. {
  448. const char * const plugin_name = plugin_info->base_name;
  449. const int argc = plugin_info->argc;
  450. const struct plugin_argument * const argv = plugin_info->argv;
  451. int i = 0;
  452. /* Extra GGC root tables describing our GTY-ed data */
  453. static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
  454. {
  455. .base = &track_function_decl,
  456. .nelt = 1,
  457. .stride = sizeof(track_function_decl),
  458. .cb = &gt_ggc_mx_tree_node,
  459. .pchw = &gt_pch_nx_tree_node
  460. },
  461. LAST_GGC_ROOT_TAB
  462. };
  463. /*
  464. * The stackleak_instrument pass should be executed before the
  465. * "optimized" pass, which is the control flow graph cleanup that is
  466. * performed just before expanding gcc trees to the RTL. In former
  467. * versions of the plugin this new pass was inserted before the
  468. * "tree_profile" pass, which is currently called "profile".
  469. */
  470. PASS_INFO(stackleak_instrument, "optimized", 1,
  471. PASS_POS_INSERT_BEFORE);
  472. /*
  473. * The stackleak_cleanup pass should be executed before the "*free_cfg"
  474. * pass. It's the moment when the stack frame size is already final,
  475. * function prologues and epilogues are generated, and the
  476. * machine-dependent code transformations are not done.
  477. */
  478. PASS_INFO(stackleak_cleanup, "*free_cfg", 1, PASS_POS_INSERT_BEFORE);
  479. if (!plugin_default_version_check(version, &gcc_version)) {
  480. error(G_("incompatible gcc/plugin versions"));
  481. return 1;
  482. }
  483. /* Parse the plugin arguments */
  484. for (i = 0; i < argc; i++) {
  485. if (!strcmp(argv[i].key, "track-min-size")) {
  486. if (!argv[i].value) {
  487. error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
  488. plugin_name, argv[i].key);
  489. return 1;
  490. }
  491. track_frame_size = atoi(argv[i].value);
  492. if (track_frame_size < 0) {
  493. error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"),
  494. plugin_name, argv[i].key, argv[i].value);
  495. return 1;
  496. }
  497. } else if (!strcmp(argv[i].key, "arch")) {
  498. if (!argv[i].value) {
  499. error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
  500. plugin_name, argv[i].key);
  501. return 1;
  502. }
  503. if (!strcmp(argv[i].value, "x86"))
  504. build_for_x86 = true;
  505. } else if (!strcmp(argv[i].key, "disable")) {
  506. disable = true;
  507. } else if (!strcmp(argv[i].key, "verbose")) {
  508. verbose = true;
  509. } else {
  510. error(G_("unknown option '-fplugin-arg-%s-%s'"),
  511. plugin_name, argv[i].key);
  512. return 1;
  513. }
  514. }
  515. if (disable) {
  516. if (verbose)
  517. fprintf(stderr, "stackleak: disabled for this translation unit\n");
  518. return 0;
  519. }
  520. /* Give the information about the plugin */
  521. register_callback(plugin_name, PLUGIN_INFO, NULL,
  522. &stackleak_plugin_info);
  523. /* Register to be called before processing a translation unit */
  524. register_callback(plugin_name, PLUGIN_START_UNIT,
  525. &stackleak_start_unit, NULL);
  526. /* Register an extra GCC garbage collector (GGC) root table */
  527. register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL,
  528. (void *)&gt_ggc_r_gt_stackleak);
  529. /*
  530. * Hook into the Pass Manager to register new gcc passes.
  531. *
  532. * The stack frame size info is available only at the last RTL pass,
  533. * when it's too late to insert complex code like a function call.
  534. * So we register two gcc passes to instrument every function at first
  535. * and remove the unneeded instrumentation later.
  536. */
  537. register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
  538. &stackleak_instrument_pass_info);
  539. register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
  540. &stackleak_cleanup_pass_info);
  541. return 0;
  542. }