From patchwork Mon Oct 24 08:54:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 8247 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp327839wru; Mon, 24 Oct 2022 01:55:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VMmfd2U4tAvY3eLgPKFQo9PQAmAjlwHN+9bCsrL6Oz6soSgHmQY72OKnccP+/7wQSAJIh X-Received: by 2002:a17:907:808:b0:730:54cc:b597 with SMTP id wv8-20020a170907080800b0073054ccb597mr26425564ejb.434.1666601744800; Mon, 24 Oct 2022 01:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666601744; cv=none; d=google.com; s=arc-20160816; b=kL2PcaXU0qMaRUPnHh0AclPDiF/awZJ63kSGv1Azl8n6rTF+n+TddKf8ssAE58/ps0 bPnBdLM3vINJ1xMIOeQy/tSNZwsGQ7WUY0KHywvFAZuf+feQQxWWPMPgD2FUvT+B0GCu wGKSsFIb2tjlYLRBcFGRFfYQ+Q+AP+YB0Txf8ulqRTtEAkfUKXI3ZRPLYuHShxOdOQMN qHUuhGndHPYCt+suqBIghhM0/ATeNFwpNVcJ/wtDCs3DmEtcaxJpLbfSSB9S6kTo549d sMtc6R5c1THBVTnIGI0dyXVS+hadfzHPDfR2hpxe3U0CqUU9P6cS7bExwMIdAyxA2RYX LH9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UB8/VB32GN/NW8zvRd6fgSsRgiA8CNtQuEXBVif3EDA=; b=rzpd04ArcoRjGAnER4lGeqDRFHV+D6CyCgUW87Vl0C4QWdDSZFjR322tGLCYlbE/mJ Gz6UqeOZ7C1wmY6yQ3LODv/4Q9V+8v7v15M97RuaZZDUnNIddFBQRnYRFDIcAWDJQ2eG dns8YgGZ5oftFW+zRXYmKmAibq33lx0DmOXrF+CNIvzD/9zZR7gfuZqvWFSKzmoTbAcM OcoujbcpDBctdkgBjPQndDo7EdmFxDf4iRpvoyq6EKQkU3QfaixTR7gc0vndwzZmH198 ZyA+JciXuPant4Wg2jmyXon6BtgMDyOU1A9XihYfp9pZJe0GysukvVQmLxgJU9JU2Eo/ gOAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sT661RkU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eb8-20020a0564020d0800b0045028bed6e7si31792292edb.600.2022.10.24.01.55.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 01:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sT661RkU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 997E23857B93 for ; Mon, 24 Oct 2022 08:55:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 997E23857B93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666601743; bh=UB8/VB32GN/NW8zvRd6fgSsRgiA8CNtQuEXBVif3EDA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=sT661RkU3yIFy3aduG6+Dri5w/2eRbEZgeyJNKwnsVBHZfh1r/QCLMtPWefrpQvR6 hnYPyachGps5r7GaBBRxxUoE6vs2smx3N1UbloBvik/VhzzuMlxOfV0SwTI2xSxku+ iGCmITFljVFOCtCzIiyc655xOBe4HMe/Svi+wvDA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 76B45385840A for ; Mon, 24 Oct 2022 08:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76B45385840A Received: by mail-wr1-x430.google.com with SMTP id k8so6334124wrh.1 for ; Mon, 24 Oct 2022 01:54:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UB8/VB32GN/NW8zvRd6fgSsRgiA8CNtQuEXBVif3EDA=; b=dPbryHX9lXGssnx+g3flgYsDYc7ardl3at/onjrqPevw9ursEDt8i3zQuSe/bPjU8h D4rSBqqL5DLGdqLlHsqGAB9txfm10vrGoVU00dv2/p9FbvN6BTG4kL0xcI5meUwrVGlh yBCM/545Tn7T9XMWUtqm57+JAoRLvzRaNrj3y3T8FnT+tIOVAQiSZe9s6QtGarBZ1UAk mYX+83ZSXPxochauWCEVxi8wisBug4uwD8i76nSteqWwaULHzEofNfkrjNO90/0d247w r+Vhwv+Q6zxqHzNKQcQKTwym5As8EUbhh8xRKob902GNWpgeM+Z4wHg+OciN8LMRt2YA OftA== X-Gm-Message-State: ACrzQf0u/5UBbpYbHYo1kdyp90veBYBUhdcujowgiMQBp240NneGdqou c42KB+yyX3amjBDTSkslpUTrPskexUQsdQ== X-Received: by 2002:a05:6000:d:b0:236:6662:5bb9 with SMTP id h13-20020a056000000d00b0023666625bb9mr5478796wrx.619.1666601697172; Mon, 24 Oct 2022 01:54:57 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id j5-20020a05600c488500b003c6c4639ac6sm9925107wmp.34.2022.10.24.01.54.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 01:54:56 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] ARM: Make ARMv8-M attribute cmse_nonsecure_call work in Ada Date: Mon, 24 Oct 2022 10:54:55 +0200 Message-ID: <3519176.R56niFO833@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747558590947123613?= X-GMAIL-MSGID: =?utf-8?q?1747558590947123613?= Hi, until most other machine attributes, this one does not work in Ada because, while it applies to pointer-to-function types, it is explicitly marked as requiring declarations in the implementation. Now, in Ada, machine attributes are specified like this: type Non_Secure is access procedure; pragma Machine_Attribute (Non_Secure, "cmse_nonsecure_call"); i.e. not attached to the declaration of Non_Secure (testcase attached). So the attached patch extends the support to Ada by also accepting pointer-to-function types in the handler. Tested on arm-eabi, OK for the mainline? 2022-10-24 Eric Botcazou * config/arm/arm.cc (arm_attribute_table) : Change decl_required field to false. (arm_handle_cmse_nonsecure_call): Deal with a TYPE node. diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index ee8f1babf8a..fc96ed9cce4 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -375,7 +375,7 @@ static const struct attribute_spec arm_attribute_table[] = /* ARMv8-M Security Extensions support. */ { "cmse_nonsecure_entry", 0, 0, true, false, false, false, arm_handle_cmse_nonsecure_entry, NULL }, - { "cmse_nonsecure_call", 0, 0, true, false, false, true, + { "cmse_nonsecure_call", 0, 0, false, false, false, true, arm_handle_cmse_nonsecure_call, NULL }, { "Advanced SIMD type", 1, 1, false, true, false, true, NULL, NULL }, { NULL, 0, 0, false, false, false, false, NULL, NULL } @@ -7605,8 +7605,8 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, int /* flags */, bool *no_add_attrs) { - tree decl = NULL_TREE, fntype = NULL_TREE; - tree type; + tree decl = NULL_TREE; + tree fntype, type; if (!use_cmse) { @@ -7616,16 +7616,20 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, return NULL_TREE; } - if (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == TYPE_DECL) + if (DECL_P (*node)) { - decl = *node; - fntype = TREE_TYPE (decl); + fntype = TREE_TYPE (*node); + + if (TREE_CODE (*node) == VAR_DECL || TREE_CODE (*node) == TYPE_DECL) + decl = *node; } + else + fntype = *node; - while (fntype != NULL_TREE && TREE_CODE (fntype) == POINTER_TYPE) + while (fntype && TREE_CODE (fntype) == POINTER_TYPE) fntype = TREE_TYPE (fntype); - if (!decl || TREE_CODE (fntype) != FUNCTION_TYPE) + if ((DECL_P (*node) && !decl) || TREE_CODE (fntype) != FUNCTION_TYPE) { warning (OPT_Wattributes, "%qE attribute only applies to base type of a " "function pointer", name); @@ -7640,10 +7644,17 @@ arm_handle_cmse_nonsecure_call (tree *node, tree name, /* Prevent trees being shared among function types with and without cmse_nonsecure_call attribute. */ - type = TREE_TYPE (decl); + if (decl) + { + type = build_distinct_type_copy (TREE_TYPE (decl)); + TREE_TYPE (decl) = type; + } + else + { + type = build_distinct_type_copy (*node); + *node = type; + } - type = build_distinct_type_copy (type); - TREE_TYPE (decl) = type; fntype = type; while (TREE_CODE (fntype) != FUNCTION_TYPE)