aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-attribs.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-05-15 14:42:12 +0200
committerMartin Liska <mliska@suse.cz>2020-10-22 10:10:50 +0200
commit346b302d09c1e6db56d9fe69048acb32fbb97845 (patch)
treedc5b9b9594325c30b81f676d19c75dbc3a34343f /gcc/c-family/c-attribs.c
parent5a99796b85c93fe9d61ee52fc3a38b8698709479 (diff)
downloadgcc-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/c-family/c-attribs.c')
-rw-r--r--gcc/c-family/c-attribs.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 8283e95..a3b2b3d 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -65,6 +65,8 @@ static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int,
static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int,
bool *);
static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *);
+static tree handle_no_stack_protector_function_attribute (tree *, tree,
+ tree, int, bool *);
static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *);
@@ -248,6 +250,14 @@ static const struct attribute_spec::exclusions attr_noinit_exclusions[] =
ATTR_EXCL (NULL, false, false, false),
};
+static const struct attribute_spec::exclusions attr_stack_protect_exclusions[] =
+{
+ ATTR_EXCL ("stack_protect", true, false, false),
+ ATTR_EXCL ("no_stack_protector", true, false, false),
+ ATTR_EXCL (NULL, false, false, false),
+};
+
+
/* Table of machine-independent attributes common to all C-like languages.
Current list of processed common attributes: nonnull. */
@@ -275,7 +285,11 @@ const struct attribute_spec c_common_attribute_table[] =
{ "volatile", 0, 0, true, false, false, false,
handle_noreturn_attribute, NULL },
{ "stack_protect", 0, 0, true, false, false, false,
- handle_stack_protect_attribute, NULL },
+ handle_stack_protect_attribute,
+ attr_stack_protect_exclusions },
+ { "no_stack_protector", 0, 0, true, false, false, false,
+ handle_no_stack_protector_function_attribute,
+ attr_stack_protect_exclusions },
{ "noinline", 0, 0, true, false, false, false,
handle_noinline_attribute,
attr_noinline_exclusions },
@@ -1156,6 +1170,22 @@ handle_stack_protect_attribute (tree *node, tree name, tree, int,
return NULL_TREE;
}
+/* Handle a "no_stack_protector" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_no_stack_protector_function_attribute (tree *node, tree name, tree,
+ int, bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) != FUNCTION_DECL)
+ {
+ warning (OPT_Wattributes, "%qE attribute ignored", name);
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
/* Handle a "noipa" attribute; arguments as in
struct attribute_spec.handler. */