From patchwork Wed Mar 30 17:45:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 603552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qZw6G2VdJz9sBm for ; Thu, 31 Mar 2016 04:45:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=gxVVutvL; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=idZ5dxjsM9AasLbzwlu5RiQrIO9pej/f7dkIZeVgckmi+uiFRH NyTo35I1SHLzyqb9EhRhvsR1yPL0VFnc8qGPqSYnzZ0Z2HWQMiJ/4dNkI7j0hyta SrP1gurz0u29k0rlqW41Wnf5usZcyp2qIMRg5TlZ7o0W9CBPRYSf9ymtY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=ikFY8XPmwC2xAxcx1PFANDL8IZo=; b=gxVVutvL+6f2RoAVId1C D9xPgFQydM3018uFoh+U2JKy7lxGAfvO44iob/OCi6dt8+fk7THs1t6UwJwpDVED agnXGdYsh6lAO1OwXHf1KeZ0AEX6F1ILcMhq1R6hfHD05rFKeEAJYNdiy1Hw+Uo6 NxR53B6c/SL27XTd5LK0uFs= Received: (qmail 40409 invoked by alias); 30 Mar 2016 17:45:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 40317 invoked by uid 89); 30 Mar 2016 17:45:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, KAM_LOTSOFHASH, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=get_identifier, 20, 9, 986, among X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Mar 2016 17:45:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 32E1F3C for ; Wed, 30 Mar 2016 10:44:03 -0700 (PDT) Received: from [10.2.206.221] (e107157-lin.cambridge.arm.com [10.2.206.221]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 975113F25E for ; Wed, 30 Mar 2016 10:45:10 -0700 (PDT) To: GCC Patches From: "Andre Vieira (lists)" Subject: [PATCH 6/8, GCC, V8M][arm-embedded] Handling ARMv8-M Security Extension's cmse_nonsecure_call attribute Message-ID: <56FC10A5.3020900@arm.com> Date: Wed, 30 Mar 2016 18:45:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, Applied https://gcc.gnu.org/ml/gcc-patches/2015-12/msg02153.html on embedded-5-branch using included patch at revision r234586. *** gcc *** 2016-03-30 Andre Vieira Thomas Preud'homme * config/arm/arm.c (gimplify.h): New include. (arm_handle_cmse_nonsecure_call): New. (arm_attribute_table): Added cmse_nonsecure_call. *** gcc/testsuite *** 2016-03-30 Andre Vieira Thomas Preud'homme * gcc.target/arm/cmse/cmse-3.c: Add tests. * gcc.target/arm/cmse/cmse-4.c: Add tests. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index d1be6eed1ac153903d50160f3b08d325187acf0b..d13bc2d49508863cf5b45a5f447a70fb468a115c 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -98,6 +98,7 @@ #include "tm-constrs.h" #include "rtl-iter.h" #include "sched-int.h" +#include "gimplify.h" /* Forward definitions of types. */ typedef struct minipool_node Mnode; @@ -168,6 +169,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); @@ -372,6 +374,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 } }; @@ -6463,6 +6467,76 @@ 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 diagnose. The + reason we check this at declaration time is to only allow the use of the + attribute with declartions of function pointers and not function + declartions. */ + +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 tree's 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/testsuite/gcc.target/arm/cmse/cmse-3.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c index f806951e90256e8286d2d0f9467b51a73a522e2b..0fe6eff45d2884736ba7049ce4ed5b9785b1018d 100644 --- a/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-3.c @@ -36,3 +36,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 ee4121f2e3f49aed4cae7bcc0e70217cbf1bd809..3521dc61f8fb974b43f504e3f634baf27a559b0b 100644 --- a/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-4.c @@ -20,9 +20,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:" } } */