From patchwork Wed Jan 16 17:03:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 1026043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494161-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DHFeUMLg"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="ll5xCgkS"; dkim-atps=neutral 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 43ftpR5l8zz9sBQ for ; Thu, 17 Jan 2019 04:03:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=jhk2x7Et6WB3wtyS6B6N3g11CHq2wRlN2dBajI9iO19mme2h/O nquDSI4CxRUYSqpm/0sXpA5y5LFctshhJXy/5jI0KPbXmMajTj+el3WWWPo2ELCN eiEL3H/esqmVbH3C5aznEPYsQ4S4ItcP3B7SSUTtXlV5djKdJZXLrWQSc= 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:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=sRO8Gm5SEXEy9KrsOTuzYmFRLi8=; b=DHFeUMLg0MAcdHyUCkug z6h8tauKe7MBG4AgYKCYceYZQsNiVJWoBJgOIMM3cNECgebCB8O1dTCM4tPE1nGi gyqFyc6QjRVdNjGqTf/nKafJuYgLx9vntRIn4ArcmrVknN4JrWB7tVO9baPRG+Sp DdCytlReViOFFPSCC7xPUgw= Received: (qmail 7778 invoked by alias); 16 Jan 2019 17:03:49 -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 7756 invoked by uid 89); 16 Jan 2019 17:03:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=flight, r15, 88851, clash X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60064.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.64) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 Jan 2019 17:03:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mr9OkVUvigwceE4/X827aDjxw7jPm1YwDX6TvlS562Y=; b=ll5xCgkSvCjt34fwJTI9+FHxdQuKJmA82C1RL0PfEvn7FowHu0w0cCYql+54jGL/YzHXXFqL8h3HM0bMPO2U7v4KIyH20uZhAQK+gRrfZeDSITunozZBsxYh4hoZYpmx89tidfRrEltBAw10i/umNAImIusKnEk96NOqXkYr9aI= Received: from DB6PR0802MB2309.eurprd08.prod.outlook.com (10.172.228.13) by DB6PR0802MB2421.eurprd08.prod.outlook.com (10.172.250.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Wed, 16 Jan 2019 17:03:41 +0000 Received: from DB6PR0802MB2309.eurprd08.prod.outlook.com ([fe80::ad19:20e5:52a5:b3df]) by DB6PR0802MB2309.eurprd08.prod.outlook.com ([fe80::ad19:20e5:52a5:b3df%7]) with mapi id 15.20.1537.018; Wed, 16 Jan 2019 17:03:41 +0000 From: Tamar Christina To: "gcc-patches@gcc.gnu.org" CC: nd , James Greenhalgh , Richard Earnshaw , Marcus Shawcroft Subject: [PATCH][GCC][AArch64] Rename stack-clash CFA register to avoid clash. Date: Wed, 16 Jan 2019 17:03:41 +0000 Message-ID: <20190116170338.GA19942@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Tamar.Christina@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) MIME-Version: 1.0 X-IsSubscribed: yes Hi All, We had multiple patches in flight that required used of scratch registers in frame layout code. As it happens two of these features picked the same register and landed at around the same time. As such there is a clash when both are used at the same time. This patch changes the temporary r15 to r11 for stack clash and documents the "reserved" registers in the frame layout comment. Cross compiled and regtested on aarch64-none-elf with SVE on by default and no issues. Bootstrapped on aarch64-none-linux-gnu and no issues. Ok for trunk? Thanks, Tamar gcc/ChangeLog: 2019-01-16 Tamar Christina PR target/88851 * config/aarch64/aarch64.md (STACK_CLASH_SVE_CFA_REGNUM): New. * config/aarch64/aarch64.c (aarch64_allocate_and_probe_stack_space): Use it and document registers. gcc/testsuite/ChangeLog: 2019-01-16 Tamar Christina PR target/88851 * gcc.target/aarch64/stack-check-cfa-3.c: Update test. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index fd60bddb1e1cbcb3dd46c319ccd182c7b9d1cd41..6a5f4956247b89932f955abbe96776a1b1ffb9cb 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -5317,11 +5317,11 @@ aarch64_allocate_and_probe_stack_space (rtx temp1, rtx temp2, { /* This is done to provide unwinding information for the stack adjustments we're about to do, however to prevent the optimizers - from removing the R15 move and leaving the CFA note (which would be + from removing the R11 move and leaving the CFA note (which would be very wrong) we tie the old and new stack pointer together. The tie will expand to nothing but the optimizers will not touch the instruction. */ - rtx stack_ptr_copy = gen_rtx_REG (Pmode, R15_REGNUM); + rtx stack_ptr_copy = gen_rtx_REG (Pmode, STACK_CLASH_SVE_CFA_REGNUM); emit_move_insn (stack_ptr_copy, stack_pointer_rtx); emit_insn (gen_stack_tie (stack_ptr_copy, stack_pointer_rtx)); @@ -5548,7 +5548,18 @@ aarch64_add_cfa_expression (rtx_insn *insn, unsigned int reg, to the stack we track as implicit probes are the FP/LR stores. For outgoing arguments we probe if the size is larger than 1KB, such that - the ABI specified buffer is maintained for the next callee. */ + the ABI specified buffer is maintained for the next callee. + + Aside from LR, FP, IP1 and IP0 there are a few other registers that if used + would clash with other features: + + - r14 and r15: Used by mitigation code. + - r16 and r17: Used by indirect tailcalls + - r12 and r13: Used as temporaries for stack adjustment + (EP0_REGNUM/EP1_REGNUM) + - r11: Used by stack clash protection when SVE is enabled. + + These registers should be avoided in frame layout related code. */ /* Generate the prologue instructions for entry into a function. Establish the stack frame by decreasing the stack pointer with a diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 513aec1872a7a5d29233d0bcb0bd1331d306eaaf..eb95a3c0935505e5c13c6e83a92b4e4db832ef94 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -35,15 +35,10 @@ (R11_REGNUM 11) (R12_REGNUM 12) (R13_REGNUM 13) - ;; Scratch registers for prologue/epilogue use. - (EP0_REGNUM 12) - (EP1_REGNUM 13) (R14_REGNUM 14) (R15_REGNUM 15) (R16_REGNUM 16) - (IP0_REGNUM 16) (R17_REGNUM 17) - (IP1_REGNUM 17) (R18_REGNUM 18) (R19_REGNUM 19) (R20_REGNUM 20) @@ -57,7 +52,6 @@ (R28_REGNUM 28) (R29_REGNUM 29) (R30_REGNUM 30) - (LR_REGNUM 30) (SP_REGNUM 31) (V0_REGNUM 32) (V1_REGNUM 33) @@ -113,10 +107,20 @@ (P13_REGNUM 81) (P14_REGNUM 82) (P15_REGNUM 83) + ;; Scratch register used by stack clash protection to calculate + ;; SVE CFA offsets during probing. + (STACK_CLASH_SVE_CFA_REGNUM 11) + ;; Scratch registers for prologue/epilogue use. + (EP0_REGNUM 12) + (EP1_REGNUM 13) ;; A couple of call-clobbered registers that we need to reserve when ;; tracking speculation this is not ABI, so is subject to change. - (SPECULATION_TRACKER_REGNUM 15) (SPECULATION_SCRATCH_REGNUM 14) + (SPECULATION_TRACKER_REGNUM 15) + ;; Scratch registers used in frame layout. + (IP0_REGNUM 16) + (IP1_REGNUM 17) + (LR_REGNUM 30) ] ) diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c index 41579f26ba9156f3e500f090d132ba9cf28364d3..c4b7bb601c442a981ca309d0c3e8f29341b9b466 100644 --- a/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c +++ b/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c @@ -8,6 +8,6 @@ need to make sure we can unwind correctly before the frame is set up. So check that we're emitting r15 with a copy of sp an setting the CFA there. */ -/* { dg-final { scan-assembler-times {mov\tx15, sp} 1 } } */ -/* { dg-final { scan-assembler-times {\.cfi_def_cfa_register 15} 1 } } */ +/* { dg-final { scan-assembler-times {mov\tx11, sp} 1 } } */ +/* { dg-final { scan-assembler-times {\.cfi_def_cfa_register 11} 1 } } */ /* { dg-final { scan-assembler-times {\.cfi_escape 0xf,0xc,0x8f,0,0x92,0x2e,0,.*} 1 } } */