aboutsummaryrefslogtreecommitdiff
path: root/gcc/config
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2017-08-10 22:59:10 +0200
committerUros Bizjak <uros@gcc.gnu.org>2017-08-10 22:59:10 +0200
commite1769bdd4cef522ada32aec863feba41116b183a (patch)
treebfa44ea06ab428cb984cd7189bf283a48a7726bf /gcc/config
parentf18f68226c2abb77008da7bd0aef5d7ee905c4c6 (diff)
downloadgcc-e1769bdd4cef522ada32aec863feba41116b183a.zip
gcc-e1769bdd4cef522ada32aec863feba41116b183a.tar.gz
gcc-e1769bdd4cef522ada32aec863feba41116b183a.tar.bz2
re PR target/81708 (The x86 stack canary location should be customizable)
PR target/81708 * config/i386/i386.opt (mstack-protector-guard-symbol=): New option * config/i386/i386.c (ix86_stack_protect_guard): Use ix86_stack_protect_guard_symbol_str to generate varible declaration. * doc/invoke.texi (x86 Options): Document -mstack-protector-guard-symbol= option. testsuite/ChangeLog: PR target/81708 * gcc.target/i386/stack-prot-sym.c: New test. From-SVN: r251040
Diffstat (limited to 'gcc/config')
-rw-r--r--gcc/config/i386/i386.c48
-rw-r--r--gcc/config/i386/i386.opt4
2 files changed, 45 insertions, 7 deletions
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 9d59c78..1135372 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -45854,21 +45854,55 @@ ix86_mangle_type (const_tree type)
}
}
+static GTY(()) tree ix86_tls_stack_chk_guard_decl;
+
static tree
ix86_stack_protect_guard (void)
{
if (TARGET_SSP_TLS_GUARD)
{
tree type_node = lang_hooks.types.type_for_mode (ptr_mode, 1);
-
int qual = ENCODE_QUAL_ADDR_SPACE (ix86_stack_protector_guard_reg);
-
tree type = build_qualified_type (type_node, qual);
- tree asptrtype = build_pointer_type (type);
- tree sspoff = build_int_cst (asptrtype,
- ix86_stack_protector_guard_offset);
- tree t = build2 (MEM_REF, asptrtype, sspoff,
- build_int_cst (asptrtype, 0));
+ tree t;
+
+ if (global_options_set.x_ix86_stack_protector_guard_symbol_str)
+ {
+ t = ix86_tls_stack_chk_guard_decl;
+
+ if (t == NULL)
+ {
+ rtx x;
+
+ t = build_decl
+ (UNKNOWN_LOCATION, VAR_DECL,
+ get_identifier (ix86_stack_protector_guard_symbol_str),
+ type);
+ TREE_STATIC (t) = 1;
+ TREE_PUBLIC (t) = 1;
+ DECL_EXTERNAL (t) = 1;
+ TREE_USED (t) = 1;
+ TREE_THIS_VOLATILE (t) = 1;
+ DECL_ARTIFICIAL (t) = 1;
+ DECL_IGNORED_P (t) = 1;
+
+ /* Do not share RTL as the declaration is visible outside of
+ current function. */
+ x = DECL_RTL (t);
+ RTX_FLAG (x, used) = 1;
+
+ ix86_tls_stack_chk_guard_decl = t;
+ }
+ }
+ else
+ {
+ tree asptrtype = build_pointer_type (type);
+
+ t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset);
+ t = build2 (MEM_REF, asptrtype, t,
+ build_int_cst (asptrtype, 0));
+ }
+
return t;
}
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 72f2422..cd56431 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -938,6 +938,10 @@ Use the given offset for addressing the stack-protector guard.
TargetVariable
HOST_WIDE_INT ix86_stack_protector_guard_offset = 0
+mstack-protector-guard-symbol=
+Target RejectNegative Joined Integer Var(ix86_stack_protector_guard_symbol_str)
+Use the given symbol for addressing the stack-protector guard.
+
mmitigate-rop
Target Var(flag_mitigate_rop) Init(0)
Attempt to avoid generating instruction sequences containing ret bytes.