Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2011-2017 by the PaX Team <pageexec@freemail.hu>
0004  * Modified by Alexander Popov <alex.popov@linux.com>
0005  *
0006  * Note: the choice of the license means that the compilation process is
0007  * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
0008  * but for the kernel it doesn't matter since it doesn't link against
0009  * any of the gcc libraries
0010  *
0011  * This gcc plugin is needed for tracking the lowest border of the kernel stack.
0012  * It instruments the kernel code inserting stackleak_track_stack() calls:
0013  *  - after alloca();
0014  *  - for the functions with a stack frame size greater than or equal
0015  *     to the "track-min-size" plugin parameter.
0016  *
0017  * This plugin is ported from grsecurity/PaX. For more information see:
0018  *   https://grsecurity.net/
0019  *   https://pax.grsecurity.net/
0020  *
0021  * Debugging:
0022  *  - use fprintf() to stderr, debug_generic_expr(), debug_gimple_stmt(),
0023  *     print_rtl_single() and debug_rtx();
0024  *  - add "-fdump-tree-all -fdump-rtl-all" to the plugin CFLAGS in
0025  *     Makefile.gcc-plugins to see the verbose dumps of the gcc passes;
0026  *  - use gcc -E to understand the preprocessing shenanigans;
0027  *  - use gcc with enabled CFG/GIMPLE/SSA verification (--enable-checking).
0028  */
0029 
0030 #include "gcc-common.h"
0031 
0032 __visible int plugin_is_GPL_compatible;
0033 
0034 static int track_frame_size = -1;
0035 static bool build_for_x86 = false;
0036 static const char track_function[] = "stackleak_track_stack";
0037 static bool disable = false;
0038 static bool verbose = false;
0039 
0040 /*
0041  * Mark these global variables (roots) for gcc garbage collector since
0042  * they point to the garbage-collected memory.
0043  */
0044 static GTY(()) tree track_function_decl;
0045 
0046 static struct plugin_info stackleak_plugin_info = {
0047     .version = PLUGIN_VERSION,
0048     .help = "track-min-size=nn\ttrack stack for functions with a stack frame size >= nn bytes\n"
0049         "arch=target_arch\tspecify target build arch\n"
0050         "disable\t\tdo not activate the plugin\n"
0051         "verbose\t\tprint info about the instrumentation\n"
0052 };
0053 
0054 static void add_stack_tracking_gcall(gimple_stmt_iterator *gsi, bool after)
0055 {
0056     gimple stmt;
0057     gcall *gimple_call;
0058     cgraph_node_ptr node;
0059     basic_block bb;
0060 
0061     /* Insert calling stackleak_track_stack() */
0062     stmt = gimple_build_call(track_function_decl, 0);
0063     gimple_call = as_a_gcall(stmt);
0064     if (after)
0065         gsi_insert_after(gsi, gimple_call, GSI_CONTINUE_LINKING);
0066     else
0067         gsi_insert_before(gsi, gimple_call, GSI_SAME_STMT);
0068 
0069     /* Update the cgraph */
0070     bb = gimple_bb(gimple_call);
0071     node = cgraph_get_create_node(track_function_decl);
0072     gcc_assert(node);
0073     cgraph_create_edge(cgraph_get_node(current_function_decl), node,
0074             gimple_call, bb->count,
0075             compute_call_stmt_bb_frequency(current_function_decl, bb));
0076 }
0077 
0078 static bool is_alloca(gimple stmt)
0079 {
0080     if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
0081         return true;
0082 
0083     if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
0084         return true;
0085 
0086     return false;
0087 }
0088 
0089 static tree get_current_stack_pointer_decl(void)
0090 {
0091     varpool_node_ptr node;
0092 
0093     FOR_EACH_VARIABLE(node) {
0094         tree var = NODE_DECL(node);
0095         tree name = DECL_NAME(var);
0096 
0097         if (DECL_NAME_LENGTH(var) != sizeof("current_stack_pointer") - 1)
0098             continue;
0099 
0100         if (strcmp(IDENTIFIER_POINTER(name), "current_stack_pointer"))
0101             continue;
0102 
0103         return var;
0104     }
0105 
0106     if (verbose) {
0107         fprintf(stderr, "stackleak: missing current_stack_pointer in %s()\n",
0108             DECL_NAME_POINTER(current_function_decl));
0109     }
0110     return NULL_TREE;
0111 }
0112 
0113 static void add_stack_tracking_gasm(gimple_stmt_iterator *gsi, bool after)
0114 {
0115     gasm *asm_call = NULL;
0116     tree sp_decl, input;
0117     vec<tree, va_gc> *inputs = NULL;
0118 
0119     /* 'no_caller_saved_registers' is currently supported only for x86 */
0120     gcc_assert(build_for_x86);
0121 
0122     /*
0123      * Insert calling stackleak_track_stack() in asm:
0124      *   asm volatile("call stackleak_track_stack"
0125      *        :: "r" (current_stack_pointer))
0126      * Use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h.
0127      * This constraint is taken into account during gcc shrink-wrapping
0128      * optimization. It is needed to be sure that stackleak_track_stack()
0129      * call is inserted after the prologue of the containing function,
0130      * when the stack frame is prepared.
0131      */
0132     sp_decl = get_current_stack_pointer_decl();
0133     if (sp_decl == NULL_TREE) {
0134         add_stack_tracking_gcall(gsi, after);
0135         return;
0136     }
0137     input = build_tree_list(NULL_TREE, build_const_char_string(2, "r"));
0138     input = chainon(NULL_TREE, build_tree_list(input, sp_decl));
0139     vec_safe_push(inputs, input);
0140     asm_call = gimple_build_asm_vec("call stackleak_track_stack",
0141                     inputs, NULL, NULL, NULL);
0142     gimple_asm_set_volatile(asm_call, true);
0143     if (after)
0144         gsi_insert_after(gsi, asm_call, GSI_CONTINUE_LINKING);
0145     else
0146         gsi_insert_before(gsi, asm_call, GSI_SAME_STMT);
0147     update_stmt(asm_call);
0148 }
0149 
0150 static void add_stack_tracking(gimple_stmt_iterator *gsi, bool after)
0151 {
0152     /*
0153      * The 'no_caller_saved_registers' attribute is used for
0154      * stackleak_track_stack(). If the compiler supports this attribute for
0155      * the target arch, we can add calling stackleak_track_stack() in asm.
0156      * That improves performance: we avoid useless operations with the
0157      * caller-saved registers in the functions from which we will remove
0158      * stackleak_track_stack() call during the stackleak_cleanup pass.
0159      */
0160     if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
0161         add_stack_tracking_gasm(gsi, after);
0162     else
0163         add_stack_tracking_gcall(gsi, after);
0164 }
0165 
0166 /*
0167  * Work with the GIMPLE representation of the code. Insert the
0168  * stackleak_track_stack() call after alloca() and into the beginning
0169  * of the function if it is not instrumented.
0170  */
0171 static unsigned int stackleak_instrument_execute(void)
0172 {
0173     basic_block bb, entry_bb;
0174     bool prologue_instrumented = false, is_leaf = true;
0175     gimple_stmt_iterator gsi = { 0 };
0176 
0177     /*
0178      * ENTRY_BLOCK_PTR is a basic block which represents possible entry
0179      * point of a function. This block does not contain any code and
0180      * has a CFG edge to its successor.
0181      */
0182     gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
0183     entry_bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
0184 
0185     /*
0186      * Loop through the GIMPLE statements in each of cfun basic blocks.
0187      * cfun is a global variable which represents the function that is
0188      * currently processed.
0189      */
0190     FOR_EACH_BB_FN(bb, cfun) {
0191         for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
0192             gimple stmt;
0193 
0194             stmt = gsi_stmt(gsi);
0195 
0196             /* Leaf function is a function which makes no calls */
0197             if (is_gimple_call(stmt))
0198                 is_leaf = false;
0199 
0200             if (!is_alloca(stmt))
0201                 continue;
0202 
0203             if (verbose) {
0204                 fprintf(stderr, "stackleak: be careful, alloca() in %s()\n",
0205                     DECL_NAME_POINTER(current_function_decl));
0206             }
0207 
0208             /* Insert stackleak_track_stack() call after alloca() */
0209             add_stack_tracking(&gsi, true);
0210             if (bb == entry_bb)
0211                 prologue_instrumented = true;
0212         }
0213     }
0214 
0215     if (prologue_instrumented)
0216         return 0;
0217 
0218     /*
0219      * Special cases to skip the instrumentation.
0220      *
0221      * Taking the address of static inline functions materializes them,
0222      * but we mustn't instrument some of them as the resulting stack
0223      * alignment required by the function call ABI will break other
0224      * assumptions regarding the expected (but not otherwise enforced)
0225      * register clobbering ABI.
0226      *
0227      * Case in point: native_save_fl on amd64 when optimized for size
0228      * clobbers rdx if it were instrumented here.
0229      *
0230      * TODO: any more special cases?
0231      */
0232     if (is_leaf &&
0233         !TREE_PUBLIC(current_function_decl) &&
0234         DECL_DECLARED_INLINE_P(current_function_decl)) {
0235         return 0;
0236     }
0237 
0238     if (is_leaf &&
0239         !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)),
0240              "_paravirt_", 10)) {
0241         return 0;
0242     }
0243 
0244     /* Insert stackleak_track_stack() call at the function beginning */
0245     bb = entry_bb;
0246     if (!single_pred_p(bb)) {
0247         /* gcc_assert(bb_loop_depth(bb) ||
0248                 (bb->flags & BB_IRREDUCIBLE_LOOP)); */
0249         split_edge(single_succ_edge(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
0250         gcc_assert(single_succ_p(ENTRY_BLOCK_PTR_FOR_FN(cfun)));
0251         bb = single_succ(ENTRY_BLOCK_PTR_FOR_FN(cfun));
0252     }
0253     gsi = gsi_after_labels(bb);
0254     add_stack_tracking(&gsi, false);
0255 
0256     return 0;
0257 }
0258 
0259 static bool large_stack_frame(void)
0260 {
0261 #if BUILDING_GCC_VERSION >= 8000
0262     return maybe_ge(get_frame_size(), track_frame_size);
0263 #else
0264     return (get_frame_size() >= track_frame_size);
0265 #endif
0266 }
0267 
0268 static void remove_stack_tracking_gcall(void)
0269 {
0270     rtx_insn *insn, *next;
0271 
0272     /*
0273      * Find stackleak_track_stack() calls. Loop through the chain of insns,
0274      * which is an RTL representation of the code for a function.
0275      *
0276      * The example of a matching insn:
0277      *  (call_insn 8 4 10 2 (call (mem (symbol_ref ("stackleak_track_stack")
0278      *  [flags 0x41] <function_decl 0x7f7cd3302a80 stackleak_track_stack>)
0279      *  [0 stackleak_track_stack S1 A8]) (0)) 675 {*call} (expr_list
0280      *  (symbol_ref ("stackleak_track_stack") [flags 0x41] <function_decl
0281      *  0x7f7cd3302a80 stackleak_track_stack>) (expr_list (0) (nil))) (nil))
0282      */
0283     for (insn = get_insns(); insn; insn = next) {
0284         rtx body;
0285 
0286         next = NEXT_INSN(insn);
0287 
0288         /* Check the expression code of the insn */
0289         if (!CALL_P(insn))
0290             continue;
0291 
0292         /*
0293          * Check the expression code of the insn body, which is an RTL
0294          * Expression (RTX) describing the side effect performed by
0295          * that insn.
0296          */
0297         body = PATTERN(insn);
0298 
0299         if (GET_CODE(body) == PARALLEL)
0300             body = XVECEXP(body, 0, 0);
0301 
0302         if (GET_CODE(body) != CALL)
0303             continue;
0304 
0305         /*
0306          * Check the first operand of the call expression. It should
0307          * be a mem RTX describing the needed subroutine with a
0308          * symbol_ref RTX.
0309          */
0310         body = XEXP(body, 0);
0311         if (GET_CODE(body) != MEM)
0312             continue;
0313 
0314         body = XEXP(body, 0);
0315         if (GET_CODE(body) != SYMBOL_REF)
0316             continue;
0317 
0318         if (SYMBOL_REF_DECL(body) != track_function_decl)
0319             continue;
0320 
0321         /* Delete the stackleak_track_stack() call */
0322         delete_insn_and_edges(insn);
0323 #if BUILDING_GCC_VERSION < 8000
0324         if (GET_CODE(next) == NOTE &&
0325             NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
0326             insn = next;
0327             next = NEXT_INSN(insn);
0328             delete_insn_and_edges(insn);
0329         }
0330 #endif
0331     }
0332 }
0333 
0334 static bool remove_stack_tracking_gasm(void)
0335 {
0336     bool removed = false;
0337     rtx_insn *insn, *next;
0338 
0339     /* 'no_caller_saved_registers' is currently supported only for x86 */
0340     gcc_assert(build_for_x86);
0341 
0342     /*
0343      * Find stackleak_track_stack() asm calls. Loop through the chain of
0344      * insns, which is an RTL representation of the code for a function.
0345      *
0346      * The example of a matching insn:
0347      *  (insn 11 5 12 2 (parallel [ (asm_operands/v
0348      *  ("call stackleak_track_stack") ("") 0
0349      *  [ (reg/v:DI 7 sp [ current_stack_pointer ]) ]
0350      *  [ (asm_input:DI ("r")) ] [])
0351      *  (clobber (reg:CC 17 flags)) ]) -1 (nil))
0352      */
0353     for (insn = get_insns(); insn; insn = next) {
0354         rtx body;
0355 
0356         next = NEXT_INSN(insn);
0357 
0358         /* Check the expression code of the insn */
0359         if (!NONJUMP_INSN_P(insn))
0360             continue;
0361 
0362         /*
0363          * Check the expression code of the insn body, which is an RTL
0364          * Expression (RTX) describing the side effect performed by
0365          * that insn.
0366          */
0367         body = PATTERN(insn);
0368 
0369         if (GET_CODE(body) != PARALLEL)
0370             continue;
0371 
0372         body = XVECEXP(body, 0, 0);
0373 
0374         if (GET_CODE(body) != ASM_OPERANDS)
0375             continue;
0376 
0377         if (strcmp(ASM_OPERANDS_TEMPLATE(body),
0378                         "call stackleak_track_stack")) {
0379             continue;
0380         }
0381 
0382         delete_insn_and_edges(insn);
0383         gcc_assert(!removed);
0384         removed = true;
0385     }
0386 
0387     return removed;
0388 }
0389 
0390 /*
0391  * Work with the RTL representation of the code.
0392  * Remove the unneeded stackleak_track_stack() calls from the functions
0393  * which don't call alloca() and don't have a large enough stack frame size.
0394  */
0395 static unsigned int stackleak_cleanup_execute(void)
0396 {
0397     const char *fn = DECL_NAME_POINTER(current_function_decl);
0398     bool removed = false;
0399 
0400     /*
0401      * Leave stack tracking in functions that call alloca().
0402      * Additional case:
0403      *   gcc before version 7 called allocate_dynamic_stack_space() from
0404      *   expand_stack_vars() for runtime alignment of constant-sized stack
0405      *   variables. That caused cfun->calls_alloca to be set for functions
0406      *   that in fact don't use alloca().
0407      *   For more info see gcc commit 7072df0aae0c59ae437e.
0408      *   Let's leave such functions instrumented as well.
0409      */
0410     if (cfun->calls_alloca) {
0411         if (verbose)
0412             fprintf(stderr, "stackleak: instrument %s(): calls_alloca\n", fn);
0413         return 0;
0414     }
0415 
0416     /* Leave stack tracking in functions with large stack frame */
0417     if (large_stack_frame()) {
0418         if (verbose)
0419             fprintf(stderr, "stackleak: instrument %s()\n", fn);
0420         return 0;
0421     }
0422 
0423     if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
0424         removed = remove_stack_tracking_gasm();
0425 
0426     if (!removed)
0427         remove_stack_tracking_gcall();
0428 
0429     return 0;
0430 }
0431 
0432 /*
0433  * STRING_CST may or may not be NUL terminated:
0434  * https://gcc.gnu.org/onlinedocs/gccint/Constant-expressions.html
0435  */
0436 static inline bool string_equal(tree node, const char *string, int length)
0437 {
0438     if (TREE_STRING_LENGTH(node) < length)
0439         return false;
0440     if (TREE_STRING_LENGTH(node) > length + 1)
0441         return false;
0442     if (TREE_STRING_LENGTH(node) == length + 1 &&
0443         TREE_STRING_POINTER(node)[length] != '\0')
0444         return false;
0445     return !memcmp(TREE_STRING_POINTER(node), string, length);
0446 }
0447 #define STRING_EQUAL(node, str) string_equal(node, str, strlen(str))
0448 
0449 static bool stackleak_gate(void)
0450 {
0451     tree section;
0452 
0453     section = lookup_attribute("section",
0454                    DECL_ATTRIBUTES(current_function_decl));
0455     if (section && TREE_VALUE(section)) {
0456         section = TREE_VALUE(TREE_VALUE(section));
0457 
0458         if (STRING_EQUAL(section, ".init.text"))
0459             return false;
0460         if (STRING_EQUAL(section, ".devinit.text"))
0461             return false;
0462         if (STRING_EQUAL(section, ".cpuinit.text"))
0463             return false;
0464         if (STRING_EQUAL(section, ".meminit.text"))
0465             return false;
0466         if (STRING_EQUAL(section, ".noinstr.text"))
0467             return false;
0468         if (STRING_EQUAL(section, ".entry.text"))
0469             return false;
0470     }
0471 
0472     return track_frame_size >= 0;
0473 }
0474 
0475 /* Build the function declaration for stackleak_track_stack() */
0476 static void stackleak_start_unit(void *gcc_data __unused,
0477                  void *user_data __unused)
0478 {
0479     tree fntype;
0480 
0481     /* void stackleak_track_stack(void) */
0482     fntype = build_function_type_list(void_type_node, NULL_TREE);
0483     track_function_decl = build_fn_decl(track_function, fntype);
0484     DECL_ASSEMBLER_NAME(track_function_decl); /* for LTO */
0485     TREE_PUBLIC(track_function_decl) = 1;
0486     TREE_USED(track_function_decl) = 1;
0487     DECL_EXTERNAL(track_function_decl) = 1;
0488     DECL_ARTIFICIAL(track_function_decl) = 1;
0489     DECL_PRESERVE_P(track_function_decl) = 1;
0490 }
0491 
0492 /*
0493  * Pass gate function is a predicate function that gets executed before the
0494  * corresponding pass. If the return value is 'true' the pass gets executed,
0495  * otherwise, it is skipped.
0496  */
0497 static bool stackleak_instrument_gate(void)
0498 {
0499     return stackleak_gate();
0500 }
0501 
0502 #define PASS_NAME stackleak_instrument
0503 #define PROPERTIES_REQUIRED PROP_gimple_leh | PROP_cfg
0504 #define TODO_FLAGS_START TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts
0505 #define TODO_FLAGS_FINISH TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func \
0506             | TODO_update_ssa | TODO_rebuild_cgraph_edges
0507 #include "gcc-generate-gimple-pass.h"
0508 
0509 static bool stackleak_cleanup_gate(void)
0510 {
0511     return stackleak_gate();
0512 }
0513 
0514 #define PASS_NAME stackleak_cleanup
0515 #define TODO_FLAGS_FINISH TODO_dump_func
0516 #include "gcc-generate-rtl-pass.h"
0517 
0518 /*
0519  * Every gcc plugin exports a plugin_init() function that is called right
0520  * after the plugin is loaded. This function is responsible for registering
0521  * the plugin callbacks and doing other required initialization.
0522  */
0523 __visible int plugin_init(struct plugin_name_args *plugin_info,
0524               struct plugin_gcc_version *version)
0525 {
0526     const char * const plugin_name = plugin_info->base_name;
0527     const int argc = plugin_info->argc;
0528     const struct plugin_argument * const argv = plugin_info->argv;
0529     int i = 0;
0530 
0531     /* Extra GGC root tables describing our GTY-ed data */
0532     static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
0533         {
0534             .base = &track_function_decl,
0535             .nelt = 1,
0536             .stride = sizeof(track_function_decl),
0537             .cb = &gt_ggc_mx_tree_node,
0538             .pchw = &gt_pch_nx_tree_node
0539         },
0540         LAST_GGC_ROOT_TAB
0541     };
0542 
0543     /*
0544      * The stackleak_instrument pass should be executed before the
0545      * "optimized" pass, which is the control flow graph cleanup that is
0546      * performed just before expanding gcc trees to the RTL. In former
0547      * versions of the plugin this new pass was inserted before the
0548      * "tree_profile" pass, which is currently called "profile".
0549      */
0550     PASS_INFO(stackleak_instrument, "optimized", 1,
0551                         PASS_POS_INSERT_BEFORE);
0552 
0553     /*
0554      * The stackleak_cleanup pass should be executed before the "*free_cfg"
0555      * pass. It's the moment when the stack frame size is already final,
0556      * function prologues and epilogues are generated, and the
0557      * machine-dependent code transformations are not done.
0558      */
0559     PASS_INFO(stackleak_cleanup, "*free_cfg", 1, PASS_POS_INSERT_BEFORE);
0560 
0561     if (!plugin_default_version_check(version, &gcc_version)) {
0562         error(G_("incompatible gcc/plugin versions"));
0563         return 1;
0564     }
0565 
0566     /* Parse the plugin arguments */
0567     for (i = 0; i < argc; i++) {
0568         if (!strcmp(argv[i].key, "track-min-size")) {
0569             if (!argv[i].value) {
0570                 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
0571                     plugin_name, argv[i].key);
0572                 return 1;
0573             }
0574 
0575             track_frame_size = atoi(argv[i].value);
0576             if (track_frame_size < 0) {
0577                 error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"),
0578                     plugin_name, argv[i].key, argv[i].value);
0579                 return 1;
0580             }
0581         } else if (!strcmp(argv[i].key, "arch")) {
0582             if (!argv[i].value) {
0583                 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
0584                     plugin_name, argv[i].key);
0585                 return 1;
0586             }
0587 
0588             if (!strcmp(argv[i].value, "x86"))
0589                 build_for_x86 = true;
0590         } else if (!strcmp(argv[i].key, "disable")) {
0591             disable = true;
0592         } else if (!strcmp(argv[i].key, "verbose")) {
0593             verbose = true;
0594         } else {
0595             error(G_("unknown option '-fplugin-arg-%s-%s'"),
0596                     plugin_name, argv[i].key);
0597             return 1;
0598         }
0599     }
0600 
0601     if (disable) {
0602         if (verbose)
0603             fprintf(stderr, "stackleak: disabled for this translation unit\n");
0604         return 0;
0605     }
0606 
0607     /* Give the information about the plugin */
0608     register_callback(plugin_name, PLUGIN_INFO, NULL,
0609                         &stackleak_plugin_info);
0610 
0611     /* Register to be called before processing a translation unit */
0612     register_callback(plugin_name, PLUGIN_START_UNIT,
0613                     &stackleak_start_unit, NULL);
0614 
0615     /* Register an extra GCC garbage collector (GGC) root table */
0616     register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL,
0617                     (void *)&gt_ggc_r_gt_stackleak);
0618 
0619     /*
0620      * Hook into the Pass Manager to register new gcc passes.
0621      *
0622      * The stack frame size info is available only at the last RTL pass,
0623      * when it's too late to insert complex code like a function call.
0624      * So we register two gcc passes to instrument every function at first
0625      * and remove the unneeded instrumentation later.
0626      */
0627     register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
0628                     &stackleak_instrument_pass_info);
0629     register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
0630                     &stackleak_cleanup_pass_info);
0631 
0632     return 0;
0633 }