Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #include "gcc-common.h"
0004 
0005 __visible int plugin_is_GPL_compatible;
0006 
0007 static unsigned int canary_offset;
0008 
0009 static unsigned int arm_pertask_ssp_rtl_execute(void)
0010 {
0011     rtx_insn *insn;
0012 
0013     for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
0014         const char *sym;
0015         rtx body;
0016         rtx current;
0017 
0018         /*
0019          * Find a SET insn involving a SYMBOL_REF to __stack_chk_guard
0020          */
0021         if (!INSN_P(insn))
0022             continue;
0023         body = PATTERN(insn);
0024         if (GET_CODE(body) != SET ||
0025             GET_CODE(SET_SRC(body)) != SYMBOL_REF)
0026             continue;
0027         sym = XSTR(SET_SRC(body), 0);
0028         if (strcmp(sym, "__stack_chk_guard"))
0029             continue;
0030 
0031         /*
0032          * Replace the source of the SET insn with an expression that
0033          * produces the address of the current task's stack canary value
0034          */
0035         current = gen_reg_rtx(Pmode);
0036 
0037         emit_insn_before(gen_load_tp_hard(current), insn);
0038 
0039         SET_SRC(body) = gen_rtx_PLUS(Pmode, current,
0040                          GEN_INT(canary_offset));
0041     }
0042     return 0;
0043 }
0044 
0045 #define PASS_NAME arm_pertask_ssp_rtl
0046 
0047 #define NO_GATE
0048 #include "gcc-generate-rtl-pass.h"
0049 
0050 #if BUILDING_GCC_VERSION >= 9000
0051 static bool no(void)
0052 {
0053     return false;
0054 }
0055 
0056 static void arm_pertask_ssp_start_unit(void *gcc_data, void *user_data)
0057 {
0058     targetm.have_stack_protect_combined_set = no;
0059     targetm.have_stack_protect_combined_test = no;
0060 }
0061 #endif
0062 
0063 __visible int plugin_init(struct plugin_name_args *plugin_info,
0064               struct plugin_gcc_version *version)
0065 {
0066     const char * const plugin_name = plugin_info->base_name;
0067     const int argc = plugin_info->argc;
0068     const struct plugin_argument *argv = plugin_info->argv;
0069     int i;
0070 
0071     if (!plugin_default_version_check(version, &gcc_version)) {
0072         error(G_("incompatible gcc/plugin versions"));
0073         return 1;
0074     }
0075 
0076     for (i = 0; i < argc; ++i) {
0077         if (!strcmp(argv[i].key, "disable"))
0078             return 0;
0079 
0080         /* all remaining options require a value */
0081         if (!argv[i].value) {
0082             error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
0083                   plugin_name, argv[i].key);
0084             return 1;
0085         }
0086 
0087         if (!strcmp(argv[i].key, "offset")) {
0088             canary_offset = atoi(argv[i].value);
0089             continue;
0090         }
0091         error(G_("unknown option '-fplugin-arg-%s-%s'"),
0092               plugin_name, argv[i].key);
0093         return 1;
0094     }
0095 
0096     PASS_INFO(arm_pertask_ssp_rtl, "expand", 1, PASS_POS_INSERT_AFTER);
0097 
0098     register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
0099               NULL, &arm_pertask_ssp_rtl_pass_info);
0100 
0101 #if BUILDING_GCC_VERSION >= 9000
0102     register_callback(plugin_info->base_name, PLUGIN_START_UNIT,
0103               arm_pertask_ssp_start_unit, NULL);
0104 #endif
0105 
0106     return 0;
0107 }