1 // SPDX-License-Identifier: GPL-2.0
3 #include "gcc-common.h"
5 __visible int plugin_is_GPL_compatible;
7 static unsigned int canary_offset;
9 static unsigned int arm_pertask_ssp_rtl_execute(void)
13 for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
19 * Find a SET insn involving a SYMBOL_REF to __stack_chk_guard
24 if (GET_CODE(body) != SET ||
25 GET_CODE(SET_SRC(body)) != SYMBOL_REF)
27 sym = XSTR(SET_SRC(body), 0);
28 if (strcmp(sym, "__stack_chk_guard"))
32 * Replace the source of the SET insn with an expression that
33 * produces the address of the current task's stack canary value
35 current = gen_reg_rtx(Pmode);
37 emit_insn_before(gen_load_tp_hard(current), insn);
39 SET_SRC(body) = gen_rtx_PLUS(Pmode, current,
40 GEN_INT(canary_offset));
45 #define PASS_NAME arm_pertask_ssp_rtl
48 #include "gcc-generate-rtl-pass.h"
50 #if BUILDING_GCC_VERSION >= 9000
56 static void arm_pertask_ssp_start_unit(void *gcc_data, void *user_data)
58 targetm.have_stack_protect_combined_set = no;
59 targetm.have_stack_protect_combined_test = no;
63 __visible int plugin_init(struct plugin_name_args *plugin_info,
64 struct plugin_gcc_version *version)
66 const char * const plugin_name = plugin_info->base_name;
67 const int argc = plugin_info->argc;
68 const struct plugin_argument *argv = plugin_info->argv;
71 if (!plugin_default_version_check(version, &gcc_version)) {
72 error(G_("incompatible gcc/plugin versions"));
76 for (i = 0; i < argc; ++i) {
77 if (!strcmp(argv[i].key, "disable"))
80 /* all remaining options require a value */
82 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
83 plugin_name, argv[i].key);
87 if (!strcmp(argv[i].key, "offset")) {
88 canary_offset = atoi(argv[i].value);
91 error(G_("unknown option '-fplugin-arg-%s-%s'"),
92 plugin_name, argv[i].key);
96 PASS_INFO(arm_pertask_ssp_rtl, "expand", 1, PASS_POS_INSERT_AFTER);
98 register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
99 NULL, &arm_pertask_ssp_rtl_pass_info);
101 #if BUILDING_GCC_VERSION >= 9000
102 register_callback(plugin_info->base_name, PLUGIN_START_UNIT,
103 arm_pertask_ssp_start_unit, NULL);