aboutsummaryrefslogtreecommitdiff
path: root/gcc/cfgexpand.c
diff options
context:
space:
mode:
authorMarcos Diaz <marcos.diaz@tallertechnologies.com>2015-01-15 05:29:12 +0000
committerJeff Law <law@gcc.gnu.org>2015-01-14 22:29:12 -0700
commit5434dc0730795cf6a2ef8a9fe20e4dcc9cd077be (patch)
tree491382b1163238c05c384ce06c8581bc06d76bfb /gcc/cfgexpand.c
parent1a0c69834516bf7731d34aa47febea6850ed773f (diff)
downloadgcc-5434dc0730795cf6a2ef8a9fe20e4dcc9cd077be.zip
gcc-5434dc0730795cf6a2ef8a9fe20e4dcc9cd077be.tar.gz
gcc-5434dc0730795cf6a2ef8a9fe20e4dcc9cd077be.tar.bz2
common.opt: New option -fstack-protector-explicit.
2015-01-14 Marcos Diaz <marcos.diaz@tallertechnologies.com> * common.opt: New option -fstack-protector-explicit. * cfgexpand.c (SPCT_FLAG_EXPLICIT): New enum. (stack_protect_decl_phase): Handle stack_protect attribute for explicit stack protection requests. (expand_used_vars): Similarly. * doc/cpp.texi (__SSP_EXPLICIT__): Document predefined macro. * doc/extend.texi: Add documentation for "stack_protect" attribute. * doc/invoke.texi: Add documentation for -fstack-protector-explicit. * c-cppbuiltin.c (c_cpp_builtins): New cpp define __SSP_EXPLICIT__ for the new option fstack-protector_explicit. * c-common.c (c_common_attribute_table): Add stack_protect attribute. (handle_stack_protect_attribute): New function. * gcc.dg/stackprotectexplicit1.c: New test. * g++.dg/stackprotectexplicit2.c: New test. From-SVN: r219633
Diffstat (limited to 'gcc/cfgexpand.c')
-rw-r--r--gcc/cfgexpand.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 8926e8f..c92c786 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -1411,7 +1411,8 @@ clear_tree_used (tree block)
enum {
SPCT_FLAG_DEFAULT = 1,
SPCT_FLAG_ALL = 2,
- SPCT_FLAG_STRONG = 3
+ SPCT_FLAG_STRONG = 3,
+ SPCT_FLAG_EXPLICIT = 4
};
/* Examine TYPE and determine a bit mask of the following features. */
@@ -1484,7 +1485,10 @@ stack_protect_decl_phase (tree decl)
has_short_buffer = true;
if (flag_stack_protect == SPCT_FLAG_ALL
- || flag_stack_protect == SPCT_FLAG_STRONG)
+ || flag_stack_protect == SPCT_FLAG_STRONG
+ || (flag_stack_protect == SPCT_FLAG_EXPLICIT
+ && lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl))))
{
if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY))
&& !(bits & SPCT_HAS_AGGREGATE))
@@ -1859,7 +1863,11 @@ expand_used_vars (void)
/* If stack protection is enabled, we don't share space between
vulnerable data and non-vulnerable data. */
- if (flag_stack_protect)
+ if (flag_stack_protect != 0
+ && (flag_stack_protect != SPCT_FLAG_EXPLICIT
+ || (flag_stack_protect == SPCT_FLAG_EXPLICIT
+ && lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl)))))
add_stack_protection_conflicts ();
/* Now that we have collected all stack variables, and have computed a
@@ -1877,15 +1885,24 @@ expand_used_vars (void)
case SPCT_FLAG_STRONG:
if (gen_stack_protect_signal
- || cfun->calls_alloca || has_protected_decls)
+ || cfun->calls_alloca || has_protected_decls
+ || lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl)))
create_stack_guard ();
break;
case SPCT_FLAG_DEFAULT:
- if (cfun->calls_alloca || has_protected_decls)
+ if (cfun->calls_alloca || has_protected_decls
+ || lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl)))
create_stack_guard ();
break;
+ case SPCT_FLAG_EXPLICIT:
+ if (lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl)))
+ create_stack_guard ();
+ break;
default:
;
}
@@ -1911,7 +1928,11 @@ expand_used_vars (void)
expand_stack_vars (stack_protect_decl_phase_1, &data);
/* Phase 2 contains other kinds of arrays. */
- if (flag_stack_protect == 2)
+ if (flag_stack_protect == SPCT_FLAG_ALL
+ || flag_stack_protect == SPCT_FLAG_STRONG
+ || (flag_stack_protect == SPCT_FLAG_EXPLICIT
+ && lookup_attribute ("stack_protect",
+ DECL_ATTRIBUTES (current_function_decl))))
expand_stack_vars (stack_protect_decl_phase_2, &data);
}