diff options
author | Martin Liska <mliska@suse.cz> | 2020-05-15 14:42:12 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-10-22 10:10:50 +0200 |
commit | 346b302d09c1e6db56d9fe69048acb32fbb97845 (patch) | |
tree | dc5b9b9594325c30b81f676d19c75dbc3a34343f /gcc/cfgexpand.c | |
parent | 5a99796b85c93fe9d61ee52fc3a38b8698709479 (diff) | |
download | gcc-346b302d09c1e6db56d9fe69048acb32fbb97845.zip gcc-346b302d09c1e6db56d9fe69048acb32fbb97845.tar.gz gcc-346b302d09c1e6db56d9fe69048acb32fbb97845.tar.bz2 |
Implement no_stack_protector attribute.
gcc/ChangeLog:
2020-05-18 Martin Liska <mliska@suse.cz>
PR c/94722
* cfgexpand.c (stack_protect_decl_phase):
Guard with lookup_attribute("no_stack_protector") at
various places.
(expand_used_vars): Likewise here.
* doc/extend.texi: Document no_stack_protector attribute.
gcc/ada/ChangeLog:
2020-05-18 Martin Liska <mliska@suse.cz>
PR c/94722
* gcc-interface/utils.c (handle_no_stack_protect_attribute):
New.
(handle_stack_protect_attribute): Add error message for a
no_stack_protector function.
gcc/c-family/ChangeLog:
2020-05-18 Martin Liska <mliska@suse.cz>
PR c/94722
* c-attribs.c (handle_no_stack_protect_function_attribute): New.
(handle_stack_protect_attribute): Add error message for a
no_stack_protector function.
gcc/testsuite/ChangeLog:
2020-05-18 Martin Liska <mliska@suse.cz>
PR c/94722
* g++.dg/no-stack-protector-attr-2.C: New test.
* g++.dg/no-stack-protector-attr-3.C: New test.
* g++.dg/no-stack-protector-attr.C: New test.
Diffstat (limited to 'gcc/cfgexpand.c')
-rw-r--r-- | gcc/cfgexpand.c | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 2ac9aef..f3f17d3 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1831,11 +1831,12 @@ stack_protect_decl_phase (tree decl) if (bits & SPCT_HAS_SMALL_CHAR_ARRAY) has_short_buffer = true; - 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)))) + tree attribs = DECL_ATTRIBUTES (current_function_decl); + if (!lookup_attribute ("no_stack_protector", attribs) + && (flag_stack_protect == SPCT_FLAG_ALL + || flag_stack_protect == SPCT_FLAG_STRONG + || (flag_stack_protect == SPCT_FLAG_EXPLICIT + && lookup_attribute ("stack_protect", attribs)))) { if ((bits & (SPCT_HAS_SMALL_CHAR_ARRAY | SPCT_HAS_LARGE_CHAR_ARRAY)) && !(bits & SPCT_HAS_AGGREGATE)) @@ -2136,6 +2137,7 @@ expand_used_vars (void) set are actually used by the optimized function. Lay them out. */ expand_used_vars_for_block (outer_block, true); + tree attribs = DECL_ATTRIBUTES (current_function_decl); if (stack_vars_num > 0) { bool has_addressable_vars = false; @@ -2145,10 +2147,10 @@ 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 != 0 + && !lookup_attribute ("no_stack_protector", attribs) && (flag_stack_protect != SPCT_FLAG_EXPLICIT || (flag_stack_protect == SPCT_FLAG_EXPLICIT - && lookup_attribute ("stack_protect", - DECL_ATTRIBUTES (current_function_decl))))) + && lookup_attribute ("stack_protect", attribs)))) has_addressable_vars = add_stack_protection_conflicts (); if (flag_stack_protect == SPCT_FLAG_STRONG && has_addressable_vars) @@ -2161,38 +2163,40 @@ expand_used_vars (void) dump_stack_var_partition (); } - switch (flag_stack_protect) - { - case SPCT_FLAG_ALL: - create_stack_guard (); - break; - case SPCT_FLAG_STRONG: - if (gen_stack_protect_signal - || cfun->calls_alloca - || has_protected_decls - || lookup_attribute ("stack_protect", - DECL_ATTRIBUTES (current_function_decl))) + if (!lookup_attribute ("no_stack_protector", attribs)) + switch (flag_stack_protect) + { + case SPCT_FLAG_ALL: create_stack_guard (); - break; + break; - case SPCT_FLAG_DEFAULT: - if (cfun->calls_alloca - || has_protected_decls - || lookup_attribute ("stack_protect", - DECL_ATTRIBUTES (current_function_decl))) - create_stack_guard (); - break; + case SPCT_FLAG_STRONG: + if (gen_stack_protect_signal + || 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; + case SPCT_FLAG_DEFAULT: + if (cfun->calls_alloca + || has_protected_decls + || lookup_attribute ("stack_protect", + DECL_ATTRIBUTES (current_function_decl))) + create_stack_guard (); + break; - default: - break; - } + case SPCT_FLAG_EXPLICIT: + if (lookup_attribute ("stack_protect", + DECL_ATTRIBUTES (current_function_decl))) + create_stack_guard (); + break; + + default: + break; + } /* Assign rtl to each variable based on these partitions. */ if (stack_vars_num > 0) @@ -2213,11 +2217,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 == SPCT_FLAG_ALL - || flag_stack_protect == SPCT_FLAG_STRONG - || (flag_stack_protect == SPCT_FLAG_EXPLICIT - && lookup_attribute ("stack_protect", - DECL_ATTRIBUTES (current_function_decl)))) + if (!lookup_attribute ("no_stack_protector", attribs) + && (flag_stack_protect == SPCT_FLAG_ALL + || flag_stack_protect == SPCT_FLAG_STRONG + || (flag_stack_protect == SPCT_FLAG_EXPLICIT + && lookup_attribute ("stack_protect", attribs)))) expand_stack_vars (stack_protect_decl_phase_2, &data); } |