1 // SPDX-License-Identifier: GPL-2.0
3 #include "gcc-common.h"
5 __visible int plugin_is_GPL_compatible;
7 static unsigned int sp_mask, 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 copy of the stack canary value
34 * stored in struct thread_info
36 masked_sp = gen_reg_rtx(Pmode);
38 emit_insn_before(gen_rtx_SET(masked_sp,
44 SET_SRC(body) = gen_rtx_PLUS(Pmode, masked_sp,
45 GEN_INT(canary_offset));
50 #define PASS_NAME arm_pertask_ssp_rtl
53 #include "gcc-generate-rtl-pass.h"
55 __visible int plugin_init(struct plugin_name_args *plugin_info,
56 struct plugin_gcc_version *version)
58 const char * const plugin_name = plugin_info->base_name;
59 const int argc = plugin_info->argc;
60 const struct plugin_argument *argv = plugin_info->argv;
64 if (!plugin_default_version_check(version, &gcc_version)) {
65 error(G_("incompatible gcc/plugin versions"));
69 for (i = 0; i < argc; ++i) {
70 if (!strcmp(argv[i].key, "disable"))
73 /* all remaining options require a value */
75 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
76 plugin_name, argv[i].key);
80 if (!strcmp(argv[i].key, "tso")) {
81 tso = atoi(argv[i].value);
85 if (!strcmp(argv[i].key, "offset")) {
86 canary_offset = atoi(argv[i].value);
89 error(G_("unknown option '-fplugin-arg-%s-%s'"),
90 plugin_name, argv[i].key);
94 /* create the mask that produces the base of the stack */
95 sp_mask = ~((1U << (12 + tso)) - 1);
97 PASS_INFO(arm_pertask_ssp_rtl, "expand", 1, PASS_POS_INSERT_AFTER);
99 register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
100 NULL, &arm_pertask_ssp_rtl_pass_info);