From patchwork Tue Aug 24 10:59:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Earnshaw X-Patchwork-Id: 1520230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=n7B3QBru; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gv5kr6QDDz9sWl for ; Tue, 24 Aug 2021 21:01:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E505385843D for ; Tue, 24 Aug 2021 11:01:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E505385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1629802864; bh=eeAUOiUe2xFEBlzL191dimQrUhueELdqSQ6cPuiWmF8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=n7B3QBruQh1jG/kDGaSwHdoSu1G/rzXLL/8+O/aVKp5wRQETY5qMVuRfcEVLPfDc6 3qwNqXsDfK+YfRY24hm6KjeEGzSUvmjGJxbaB0ezh8rdaKDDbV7aB1lRc6gVZn4Y9L zLL5UnP3wCT3+OL62ctT3LYoYPRFX7k7zidpDjwY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 5A1163858C2C for ; Tue, 24 Aug 2021 10:59:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A1163858C2C Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 08A7B150C; Tue, 24 Aug 2021 03:59:49 -0700 (PDT) Received: from e126323.arm.com (unknown [10.57.39.244]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81C793F66F; Tue, 24 Aug 2021 03:59:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [committed 2/6] arm: testsuite: improve detection of CMSE hardware. Date: Tue, 24 Aug 2021 11:59:24 +0100 Message-Id: <20210824105928.3869183-3-rearnsha@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824105928.3869183-1-rearnsha@arm.com> References: <20210824105928.3869183-1-rearnsha@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Earnshaw via Gcc-patches From: Richard Earnshaw Reply-To: Richard Earnshaw Cc: Richard Earnshaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The test for CMSE support being available in hardware currently relies on the compiler not optimizing away a secure gateway operation. But even that is suspect, because the SG instruction is just a NOP on armv8-m implementations that do not support the security extension. Replace the existing test with a new one that reads and checks the appropriate hardware feature register (memory mapped). This has to be run from secure mode, but that shouldn't matter, because if we can't do that we can't really test the CMSE extensions anyway. We retain the SG instruction to ensure the test can't pass accidentally if run on pre-armv8-m devices. gcc/testsuite: * lib/target-supports.exp (check_effective_target_arm_cmse_hw): Check the CMSE feature register, rather than relying on the SG operation causing an execution fault. --- gcc/testsuite/lib/target-supports.exp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 66ce48d7dfd..06f5b1eb54d 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -4878,15 +4878,16 @@ proc check_effective_target_arm_cmse_ok {} { proc check_effective_target_arm_cmse_hw { } { return [check_runtime arm_cmse_hw_available { - int __attribute__ ((cmse_nonsecure_entry)) ns_func(void) - { - return 0; - } int main (void) { - return ns_func(); - } - } "-mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000"] + unsigned id_pfr1; + asm ("ldr\t%0, =0xe000ed44\n" \ + "ldr\t%0, [%0]\n" \ + "sg" : "=l" (id_pfr1)); + /* Exit with code 0 iff security extension is available. */ + return !(id_pfr1 & 0xf0); + } + } "-mcmse"] } # Return 1 if the target supports executing MVE instructions, 0 # otherwise.