public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Andre Vieira (lists)" <Andre.SimoesDiasVieira@arm.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCHv2 5/7, GCC, ARM, V8M] Handling ARMv8-M Security Extension's cmse_nonsecure_call attribute
Date: Wed, 24 Aug 2016 11:01:00 -0000	[thread overview]
Message-ID: <57BD7E93.5000108@arm.com> (raw)
In-Reply-To: <57961342.4080108@arm.com>

[-- Attachment #1: Type: text/plain, Size: 2292 bytes --]

On 25/07/16 14:25, Andre Vieira (lists) wrote:
> This patch adds support for the ARMv8-M Security Extensions
> 'cmse_nonsecure_call' attribute. This attribute may only be used for
> function types and when used in combination with the '-mcmse'
> compilation flag. See Section 5.5 of ARM®v8-M Security Extensions
> (http://infocenter.arm.com/help/topic/com.arm.doc.ecm0359818/index.html).
> 
> We currently do not support cmse_nonsecure_call functions that pass
> arguments or return variables on the stack and we diagnose this.
> 
> *** gcc/ChangeLog ***
> 2016-07-25  Andre Vieira        <andre.simoesdiasvieira@arm.com>
>             Thomas Preud'homme  <thomas.preudhomme@arm.com>
> 
>         * config/arm/arm.c (gimplify.h): New include.
>         (arm_handle_cmse_nonsecure_call): New.
>         (arm_attribute_table): Added cmse_nonsecure_call.
> 
> *** gcc/testsuite/ChangeLog ***
> 2016-07-25  Andre Vieira        <andre.simoesdiasvieira@arm.com>
>             Thomas Preud'homme  <thomas.preudhomme@arm.com>
> 
>         * gcc.target/arm/cmse/cmse-3.c: Add tests.
>         * gcc.target/arm/cmse/cmse-4.c: Add tests.
> 

Added more documentation as requested.

---

This patch adds support for the ARMv8-M Security Extensions
'cmse_nonsecure_call' attribute. This attribute may only be used for
function types and when used in combination with the '-mcmse'
compilation flag. See Section 5.5 of ARM®v8-M Security Extensions
(http://infocenter.arm.com/help/topic/com.arm.doc.ecm0359818/index.html).

We currently do not support cmse_nonsecure_call functions that pass
arguments or return variables on the stack and we diagnose this.

*** gcc/ChangeLog ***
2016-07-xx  Andre Vieira        <andre.simoesdiasvieira@arm.com>
            Thomas Preud'homme  <thomas.preudhomme@arm.com>

        * config/arm/arm.c (gimplify.h): New include.
        (arm_handle_cmse_nonsecure_call): New.
        (arm_attribute_table): Added cmse_nonsecure_call.
        * doc/extend.texi (ARM ARMv8-M Security Extensions): New attribute.

*** gcc/testsuite/ChangeLog ***
2016-07-xx  Andre Vieira        <andre.simoesdiasvieira@arm.com>
            Thomas Preud'homme  <thomas.preudhomme@arm.com>

        * gcc.target/arm/cmse/cmse-3.c: Add tests.
        * gcc.target/arm/cmse/cmse-4.c: Add tests.

[-- Attachment #2: diff5 --]
[-- Type: text/plain, Size: 7129 bytes --]

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 680b648a218d166d49e89be78ee30397dac7e87f..647e41677834573db1b921d3e8445145767779c4 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -61,6 +61,7 @@
 #include "builtins.h"
 #include "tm-constrs.h"
 #include "rtl-iter.h"
+#include "gimplify.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -135,6 +136,7 @@ static tree arm_handle_isr_attribute (tree *, tree, tree, int, bool *);
 static tree arm_handle_notshared_attribute (tree *, tree, tree, int, bool *);
 #endif
 static tree arm_handle_cmse_nonsecure_entry (tree *, tree, tree, int, bool *);
+static tree arm_handle_cmse_nonsecure_call (tree *, tree, tree, int, bool *);
 static void arm_output_function_epilogue (FILE *, HOST_WIDE_INT);
 static void arm_output_function_prologue (FILE *, HOST_WIDE_INT);
 static int arm_comp_type_attributes (const_tree, const_tree);
@@ -347,6 +349,8 @@ static const struct attribute_spec arm_attribute_table[] =
   /* ARMv8-M Security Extensions support.  */
   { "cmse_nonsecure_entry", 0, 0, true, false, false,
     arm_handle_cmse_nonsecure_entry, false },
+  { "cmse_nonsecure_call", 0, 0, true, false, false,
+    arm_handle_cmse_nonsecure_call, false },
   { NULL,           0, 0, false, false, false, NULL, false }
 };
 \f
@@ -6750,6 +6754,78 @@ arm_handle_cmse_nonsecure_entry (tree *node, tree name,
   return NULL_TREE;
 }
 
+
+/* Called upon detection of the use of the cmse_nonsecure_call attribute, this
+   function will check whether the attribute is allowed here and will add the
+   attribute to the function type tree or otherwise issue a diagnostic.  The
+   reason we check this at declaration time is to only allow the use of the
+   attribute with declarations of function pointers and not function
+   declarations.  This function checks NODE is of the expected type and issues
+   diagnostics otherwise using NAME.  If it is not of the expected type
+   *NO_ADD_ATTRS will be set to true.  */
+
+static tree
+arm_handle_cmse_nonsecure_call (tree *node, tree name,
+				 tree /* args */,
+				 int /* flags */,
+				 bool *no_add_attrs)
+{
+  tree decl = NULL_TREE;
+  tree type, fntype, main_variant;
+
+  if (!use_cmse)
+    {
+      *no_add_attrs = true;
+      return NULL_TREE;
+    }
+
+  if (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == TYPE_DECL)
+    {
+      decl = *node;
+      type = TREE_TYPE (decl);
+    }
+
+  if (!decl
+      || (!(TREE_CODE (type) == POINTER_TYPE
+	    && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
+	  && TREE_CODE (type) != FUNCTION_TYPE))
+    {
+	warning (OPT_Wattributes, "%qE attribute only applies to base type of a "
+		 "function pointer", name);
+	*no_add_attrs = true;
+	return NULL_TREE;
+    }
+
+  /* type is either a function pointer, when the attribute is used on a function
+   * pointer, or a function type when used in a typedef.  */
+  if (TREE_CODE (type) == FUNCTION_TYPE)
+    fntype = type;
+  else
+    fntype = TREE_TYPE (type);
+
+  *no_add_attrs |= cmse_func_args_or_return_in_stack (NULL, name, fntype);
+
+  if (*no_add_attrs)
+    return NULL_TREE;
+
+  /* Prevent trees being shared among function types with and without
+     cmse_nonsecure_call attribute.  Do however make sure they keep the same
+     main_variant, this is required for correct DIE output.  */
+  main_variant = TYPE_MAIN_VARIANT (fntype);
+  fntype = build_distinct_type_copy (fntype);
+  TYPE_MAIN_VARIANT (fntype) = main_variant;
+  if (TREE_CODE (type) == FUNCTION_TYPE)
+    TREE_TYPE (decl) = fntype;
+  else
+    TREE_TYPE (type) = fntype;
+
+  /* Construct a type attribute and add it to the function type.  */
+  tree attrs = tree_cons (get_identifier ("cmse_nonsecure_call"), NULL_TREE,
+			  TYPE_ATTRIBUTES (fntype));
+  TYPE_ATTRIBUTES (fntype) = attrs;
+  return NULL_TREE;
+}
+
 /* Return 0 if the attributes for two types are incompatible, 1 if they
    are compatible, and 2 if they are nearly compatible (which causes a
    warning to be generated).  */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 1531ed66bdd0b51c268c2a666c2e078b4f0d7ea6..f1e6a20583f9b16d5a670144a162203a12b239bd 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -12421,8 +12421,8 @@ Security Extensions: Requiremenets on Development Tools Engineering
 Specification, which can be found at
 @uref{http://infocenter.arm.com/help/topic/com.arm.doc.ecm0359818/ECM0359818_armv8m_security_extensions_reqs_on_dev_tools_1_0.pdf}.
 
-As part of the Security Extensions GCC implements a new function attribute
-@code{cmse_nonsecure_entry}.
+As part of the Security Extensions GCC implements two new function attributes:
+@code{cmse_nonsecure_entry} and @code{cmse_nonsecure_call}.
 
 As part of the Security Extensions GCC implements the intrinsics below.  FPTR
 is used here to mean any function pointer type.
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c
index 2c2920e1dc310106d83203eb51e1a68a275d0152..7f92a4c28b3333e4c8fdc256211f3ed74a383cd4 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c
@@ -35,3 +35,11 @@ norf (struct span2 a) {}
 
 void __attribute__ ((cmse_nonsecure_entry))
 foo2 (long long a, int b, union test_union c) {} /* { dg-error "not available to functions with arguments passed on the stack" } */
+
+typedef void __attribute__ ((cmse_nonsecure_call)) bar2 (long long a, int b, long long c); /* { dg-error "not available to functions with arguments passed on the stack" } */
+
+typedef void __attribute__ ((cmse_nonsecure_call)) baz2 (long long a, int b, struct span c); /* { dg-error "not available to functions with arguments passed on the stack" } */
+
+typedef struct span __attribute__ ((cmse_nonsecure_call)) qux2 (void); /* { dg-error "not available to functions that return value on the stack" } */
+
+typedef void __attribute__ ((cmse_nonsecure_call)) norf2 (int a, ...); /* { dg-error "not available to functions with variable number of arguments" } */
diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c
index 6f930ab04a1097c64097a4e003296bbe85733319..d0999a4181ac022b115ae20cf3e1c8bf78f6becf 100644
--- a/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c
+++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c
@@ -19,9 +19,16 @@ baz (void)
   return qux ();
 }
 
+void __attribute__ ((cmse_nonsecure_call))
+quux (void) {} /* { dg-warning "attribute only applies to base type of a function pointer" } */
+
+int __attribute__ ((cmse_nonsecure_call)) norf; /* { dg-warning "attribute only applies to base type of a function pointer" } */
+
 /* { dg-final { scan-assembler-times "bxns" 2 } } */
 /* { dg-final { scan-assembler "foo:" } } */
 /* { dg-final { scan-assembler "__acle_se_foo:" } } */
 /* { dg-final { scan-assembler-not "__acle_se_bar:" } } */
 /* { dg-final { scan-assembler "baz:" } } */
 /* { dg-final { scan-assembler "__acle_se_baz:" } } */
+/* { dg-final { scan-assembler-not "__acle_se_quux:" } } */
+/* { dg-final { scan-assembler-not "__acle_se_norf:" } } */

  reply	other threads:[~2016-08-24 11:01 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25 13:17 [PATCH 0/7, GCC, V8M] ARMv8-M Security Extensions Andre Vieira (lists)
2016-07-25 13:20 ` [PATCH 1/7, GCC, ARM, V8M] Add support for ARMv8-M's Secure Extensions flag and intrinsics Andre Vieira (lists)
2016-08-24 11:00   ` [PATCHv2 " Andre Vieira (lists)
2016-10-25 16:26     ` Andre Vieira (lists)
2016-10-26  9:13       ` Kyrill Tkachov
2016-10-26 13:00         ` Kyrill Tkachov
2016-10-27  9:54           ` Andre Vieira (lists)
2016-10-27 10:01             ` Kyrill Tkachov
2016-12-05 11:27               ` [arm-embedded][committed][PATCH 1/7] " Andre Vieira (lists)
2016-07-25 13:21 ` [PATCH 2/7, GCC, ARM, V8M] Handling ARMv8-M Security Extension's cmse_nonsecure_entry attribute Andre Vieira (lists)
2016-08-24 11:01   ` [PATCHv2 " Andre Vieira (lists)
2016-10-25 16:28     ` Andre Vieira (lists)
2016-10-26  9:33       ` Kyrill Tkachov
2016-10-26 16:28         ` Andre Vieira (lists)
2016-10-26 16:28           ` Kyrill Tkachov
2016-10-27  9:54             ` Andre Vieira (lists)
2016-10-27 10:19               ` Kyrill Tkachov
2016-12-05 11:31                 ` [arm-embedded][committed][PATCH 2/7] " Andre Vieira (lists)
2016-07-25 13:23 ` [PATCH 3/7, GCC, ARM, V8M] ARMv8-M Security Extension's cmse_nonsecure_entry: __acle_se label and bxns return Andre Vieira (lists)
2016-10-25 16:29   ` Andre Vieira (lists)
2016-10-26 10:03     ` Kyrill Tkachov
2016-10-27  9:55       ` Andre Vieira (lists)
2016-12-05 11:34         ` [arm-embedded][committed][PATCH 3/7] " Andre Vieira (lists)
2016-07-25 13:24 ` [PATCH 4/7, GCC, ARM, V8M] ARMv8-M Security Extension's cmse_nonsecure_entry: clear registers Andre Vieira (lists)
2016-08-24 11:01   ` [PATCHv2 " Andre Vieira (lists)
2016-10-25 16:29     ` Andre Vieira (lists)
2016-10-26 12:51       ` Kyrill Tkachov
2016-10-26 16:26         ` Andre Vieira (lists)
2016-10-26 16:30           ` Kyrill Tkachov
2016-10-27 10:00             ` Andre Vieira (lists)
2016-10-27 10:44               ` Kyrill Tkachov
2016-10-28 16:08                 ` Andre Vieira (lists)
2016-11-08 12:16                   ` Kyrill Tkachov
2016-11-23 11:52                     ` Andre Vieira (lists)
2016-11-30 15:32                       ` Andre Vieira (lists)
2016-11-30 17:22                         ` Kyrill Tkachov
2016-12-05 11:36                           ` [arm-embedded][committed][PATCH 4/7] " Andre Vieira (lists)
2016-10-26 14:14       ` [PATCHv2 4/7, GCC, ARM, V8M] " Kyrill Tkachov
2016-07-25 13:25 ` [PATCH 5/7, GCC, ARM, V8M] Handling ARMv8-M Security Extension's cmse_nonsecure_call attribute Andre Vieira (lists)
2016-08-24 11:01   ` Andre Vieira (lists) [this message]
2016-10-25 16:29     ` [PATCHv2 " Andre Vieira (lists)
2016-10-27 10:00       ` Andre Vieira (lists)
2016-11-04  9:30       ` Kyrill Tkachov
2016-11-30 12:05         ` [PATCHv3 " Andre Vieira (lists)
2016-11-30 17:22           ` Kyrill Tkachov
2016-12-05 11:38             ` [PATCHv3 5/7, GCC[arm-embedded][committed][PATCH 5/7] Handling ARMv8-M Security Extension's cmse_nonsecure_call attribute, " Andre Vieira (lists)
2016-07-25 13:26 ` [PATCH 6/7, GCC, ARM, V8M] ARMv8-M Security Extension's cmse_nonsecure_call: use __gnu_cmse_nonsecure_call Andre Vieira (lists)
2016-08-24 11:02   ` [PATCHv2 " Andre Vieira (lists)
2016-10-25 16:30     ` Andre Vieira (lists)
2016-10-27 10:01       ` Andre Vieira (lists)
2016-11-09 14:54         ` Andre Vieira (lists)
2016-11-11 11:52           ` Kyrill Tkachov
2016-11-11 16:15             ` Andre Vieira (lists)
2016-11-11 16:19               ` Kyrill Tkachov
2016-11-11 16:19                 ` Kyrill Tkachov
2016-11-23 11:54                   ` Andre Vieira (lists)
2016-12-02 13:36                     ` Andre Vieira (lists)
2016-12-02 13:42                       ` Kyrill Tkachov
2016-12-05 11:44                         ` [arm-embedded][committed][PATCH 6/7] " Andre Vieira (lists)
2016-07-25 13:29 ` [PATCH 7/7, GCC, ARM, V8M] Added support for ARMV8-M Security Extension cmse_nonsecure_caller intrinsic Andre Vieira (lists)
2016-08-24 11:02   ` Andre Vieira (lists)
2016-10-25 16:30     ` Andre Vieira (lists)
2016-11-09 10:27       ` Kyrill Tkachov
2016-11-09 14:53         ` Andre Vieira (lists)
2016-11-30 12:06           ` Andre Vieira (lists)
2016-12-05 11:46             ` [arm-embedded][committed][PATCH 7/7] " Andre Vieira (lists)
2016-08-08  4:20 ` [PATCH 0/7, GCC, V8M] ARMv8-M Security Extensions Sandra Loosemore
2016-08-09 12:01   ` Andre Vieira (lists)
2016-08-09 16:47     ` Sandra Loosemore
2016-08-10  8:09       ` Andre Vieira (lists)
2016-08-24 11:02         ` Andre Vieira (lists)
2016-10-24 16:14           ` Kyrill Tkachov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57BD7E93.5000108@arm.com \
    --to=andre.simoesdiasvieira@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).