diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2017-08-10 22:59:10 +0200 |
---|---|---|
committer | Uros Bizjak <uros@gcc.gnu.org> | 2017-08-10 22:59:10 +0200 |
commit | e1769bdd4cef522ada32aec863feba41116b183a (patch) | |
tree | bfa44ea06ab428cb984cd7189bf283a48a7726bf /gcc | |
parent | f18f68226c2abb77008da7bd0aef5d7ee905c4c6 (diff) | |
download | gcc-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')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/config/i386/i386.c | 48 | ||||
-rw-r--r-- | gcc/config/i386/i386.opt | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/stack-prot-sym.c | 6 |
6 files changed, 71 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f210597..c73897f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,14 @@ 2017-08-10 Uros Bizjak <ubizjak@gmail.com> + 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. + +2017-08-10 Uros Bizjak <ubizjak@gmail.com> + * config/i386/i386-protos.h (ix86_split_stack_guard): New prototype. * config/i386/i386.c (ix86_split_stack_guard): New function. (ix86_xpand_split_stack_prologue): Call ix86_split_stack_guard. 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. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3753d8a..ec29f1d 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1216,7 +1216,8 @@ See RS/6000 and PowerPC Options. -mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol -malign-data=@var{type} -mstack-protector-guard=@var{guard} @gol -mstack-protector-guard-reg=@var{reg} @gol --mstack-protector-guard-offset=@var{offset} -mmitigate-rop @gol +-mstack-protector-guard-offset=@var{offset} @gol +-mstack-protector-guard-symbol=@var{symbol} -mmitigate-rop @gol -mgeneral-regs-only -mcall-ms2sysv-xlogues} @emph{x86 Windows Options} @@ -22757,9 +22758,11 @@ The @option{-mno-compat-align-parm} option is the default. @item -mstack-protector-guard=@var{guard} @itemx -mstack-protector-guard-reg=@var{reg} @itemx -mstack-protector-guard-offset=@var{offset} +@itemx -mstack-protector-guard-symbol=@var{symbol} @opindex mstack-protector-guard @opindex mstack-protector-guard-reg @opindex mstack-protector-guard-offset +@opindex mstack-protector-guard-symbol Generate stack protection code using canary at @var{guard}. Supported locations are @samp{global} for global canary or @samp{tls} for per-thread canary in the TLS block (the default with GNU libc version 2.4 or later). @@ -22769,7 +22772,8 @@ With the latter choice the options @option{-mstack-protector-guard-offset=@var{offset}} furthermore specify which register to use as base register for reading the canary, and from what offset from that base register. The default for those is as specified in the -relevant ABI. +relevant ABI. @option{-mstack-protector-guard-symbol=@var{symbol}} overrides +the offset with a symbol reference to a canary in the TLS block. @end table @node RX Options diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da63e03..3100618 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-10 Uros Bizjak <ubizjak@gmail.com> + + PR target/81708 + * gcc.target/i386/stack-prot-sym.c: New test. + 2017-08-10 Richard Sandiford <richard.sandiford@linaro.org> PR testsuite/81738 diff --git a/gcc/testsuite/gcc.target/i386/stack-prot-sym.c b/gcc/testsuite/gcc.target/i386/stack-prot-sym.c new file mode 100644 index 0000000..7f63424 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/stack-prot-sym.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fstack-protector-all -mstack-protector-guard=tls -mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=my_guard" } */ + +void f(void) { } + +/* { dg-final { scan-assembler "gs:my_guard" } } */ |