spi: sprd: adi: Change hwlock to be optional
[linux/fpc-iii.git] / scripts / gcc-plugins / arm_ssp_per_task_plugin.c
blob8c1af9bdcb1bbaadb419e876717cded98ae9c408
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)
11 rtx_insn *insn;
13 for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
14 const char *sym;
15 rtx body;
16 rtx mask, masked_sp;
19 * Find a SET insn involving a SYMBOL_REF to __stack_chk_guard
21 if (!INSN_P(insn))
22 continue;
23 body = PATTERN(insn);
24 if (GET_CODE(body) != SET ||
25 GET_CODE(SET_SRC(body)) != SYMBOL_REF)
26 continue;
27 sym = XSTR(SET_SRC(body), 0);
28 if (strcmp(sym, "__stack_chk_guard"))
29 continue;
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 mask = GEN_INT(sext_hwi(sp_mask, GET_MODE_PRECISION(Pmode)));
37 masked_sp = gen_reg_rtx(Pmode);
39 emit_insn_before(gen_rtx_set(masked_sp,
40 gen_rtx_AND(Pmode,
41 stack_pointer_rtx,
42 mask)),
43 insn);
45 SET_SRC(body) = gen_rtx_PLUS(Pmode, masked_sp,
46 GEN_INT(canary_offset));
48 return 0;
51 #define PASS_NAME arm_pertask_ssp_rtl
53 #define NO_GATE
54 #include "gcc-generate-rtl-pass.h"
56 #if BUILDING_GCC_VERSION >= 9000
57 static bool no(void)
59 return false;
62 static void arm_pertask_ssp_start_unit(void *gcc_data, void *user_data)
64 targetm.have_stack_protect_combined_set = no;
65 targetm.have_stack_protect_combined_test = no;
67 #endif
69 __visible int plugin_init(struct plugin_name_args *plugin_info,
70 struct plugin_gcc_version *version)
72 const char * const plugin_name = plugin_info->base_name;
73 const int argc = plugin_info->argc;
74 const struct plugin_argument *argv = plugin_info->argv;
75 int tso = 0;
76 int i;
78 if (!plugin_default_version_check(version, &gcc_version)) {
79 error(G_("incompatible gcc/plugin versions"));
80 return 1;
83 for (i = 0; i < argc; ++i) {
84 if (!strcmp(argv[i].key, "disable"))
85 return 0;
87 /* all remaining options require a value */
88 if (!argv[i].value) {
89 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
90 plugin_name, argv[i].key);
91 return 1;
94 if (!strcmp(argv[i].key, "tso")) {
95 tso = atoi(argv[i].value);
96 continue;
99 if (!strcmp(argv[i].key, "offset")) {
100 canary_offset = atoi(argv[i].value);
101 continue;
103 error(G_("unknown option '-fplugin-arg-%s-%s'"),
104 plugin_name, argv[i].key);
105 return 1;
108 /* create the mask that produces the base of the stack */
109 sp_mask = ~((1U << (12 + tso)) - 1);
111 PASS_INFO(arm_pertask_ssp_rtl, "expand", 1, PASS_POS_INSERT_AFTER);
113 register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
114 NULL, &arm_pertask_ssp_rtl_pass_info);
116 #if BUILDING_GCC_VERSION >= 9000
117 register_callback(plugin_info->base_name, PLUGIN_START_UNIT,
118 arm_pertask_ssp_start_unit, NULL);
119 #endif
121 return 0;