From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7810) id 0898E3857C45; Fri, 24 Feb 2023 17:34:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0898E3857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677260078; bh=1lTSu0/kiU3n6OM25BKUDW342Z/+JnWLPa7u/kgWnqU=; h=From:To:Subject:Date:From; b=r5tkxPbmeZtleRno+KKAqaqJAM4ZW8EOolaPQvMkwq9VgLQBU+XhBKp6dpUl9k5xC SvpopSTaf+6ZwrMIUCIxfkueM0zcYymIlfbWPUaUqSPFbyneVvAIWOrUUIrImmP6dW 2R6dDcRLWb6ysWbQVc5d2vuPwIy9XAPJ61emUIaQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alex Coplan To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] aarch64: -mtrack-speculation pass capability enablement X-Act-Checkin: gcc X-Git-Author: Victor Do Nascimento X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: e5aa9a91a270cee887b49630da14cd62cd7ce04a X-Git-Newrev: ce2e4f958b407ae0bb9a66c34a708c74ba15eb3f Message-Id: <20230224173438.0898E3857C45@sourceware.org> Date: Fri, 24 Feb 2023 17:34:38 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ce2e4f958b407ae0bb9a66c34a708c74ba15eb3f commit ce2e4f958b407ae0bb9a66c34a708c74ba15eb3f Author: Victor Do Nascimento Date: Mon Jan 16 17:09:32 2023 +0000 aarch64: -mtrack-speculation pass capability enablement Fix the code sequence generated for speculative execution tracking so that it uses the proper capability-handling instructions, thus preventing the invalidation of the CSP stack pointer capability when the speculation tracking state is encoded into the stack pointer. For capability-enabled targets, we see the following change in the generated tracking code from: mov tmp, sp and tmp, tmp, tracker mov SP, tmp to: mov tmp, sp and tmp, tmp, tracker scvalue CSP, CSP, tmp Diff: --- gcc/config/aarch64/aarch64-speculation.cc | 9 ++++++--- .../gcc.target/aarch64/morello/mtrack-speculation.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/config/aarch64/aarch64-speculation.cc b/gcc/config/aarch64/aarch64-speculation.cc index f490b64ae61..2453f62c96c 100644 --- a/gcc/config/aarch64/aarch64-speculation.cc +++ b/gcc/config/aarch64/aarch64-speculation.cc @@ -141,14 +141,17 @@ static rtx_insn * aarch64_speculation_clobber_sp () { - rtx sp = gen_rtx_REG (DImode, SP_REGNUM); + rtx sp = gen_rtx_REG (Pmode, SP_REGNUM); rtx tracker = gen_rtx_REG (DImode, SPECULATION_TRACKER_REGNUM); rtx scratch = gen_rtx_REG (DImode, SPECULATION_SCRATCH_REGNUM); start_sequence (); - emit_insn (gen_rtx_SET (scratch, sp)); + emit_insn (gen_rtx_SET (scratch, drop_capability (sp))); emit_insn (gen_anddi3 (scratch, scratch, tracker)); - emit_insn (gen_rtx_SET (sp, scratch)); + if (CAPABILITY_MODE_P (Pmode)) + emit_insn (gen_replace_address_value_cadi (sp, sp, scratch)); + else + emit_insn (gen_rtx_SET (sp, scratch)); rtx_insn *seq = get_insns (); end_sequence (); return seq; diff --git a/gcc/testsuite/gcc.target/aarch64/morello/mtrack-speculation.c b/gcc/testsuite/gcc.target/aarch64/morello/mtrack-speculation.c new file mode 100644 index 00000000000..ec7f3ba6a53 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/morello/mtrack-speculation.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ +/* { dg-additional-options "-mtrack-speculation" } */ +/* Ensure the speculation tracker code does not invalidate the + stack pointer capability. */ + +int +main() { + int a = 10; + while (a) + a--; + return 0; +}