From patchwork Mon Apr 25 14:03:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: German Gomez X-Patchwork-Id: 53188 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F0F43858430 for ; Mon, 25 Apr 2022 14:03:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F0F43858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1650895432; bh=V/lBf4jsMWRbllSpf+9uRUhlhGAtfUhVHdygBeXCKQQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:From; b=Xnyy95DVcYTaQidVwJLrNxaR1LJqKRsOMT6r9OAWerqwYqRM4i7dStRZHYTwtA9xH Vcupi3Jp9nP4kab/lPC8Oh62grsQ7GZ3092zMtiVvbVVhHubcJOz5UFnSufLEQM/km AX6lidat6wWSieHZFZfhrRxfcT2i3aK+IprRFOXA= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 730CD3858403 for ; Mon, 25 Apr 2022 14:03:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 730CD3858403 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 38BFD1FB; Mon, 25 Apr 2022 07:03:25 -0700 (PDT) Received: from ip-10-252-15-96.eu-west-1.compute.internal (unknown [10.252.15.96]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9524F3F774; Mon, 25 Apr 2022 07:03:24 -0700 (PDT) To: elfutils-devel@sourceware.org Subject: [PATCH 2/4] libdw, aarch64: Implement DW_CFA_AARCH64_negate_ra_state CFI instruction Date: Mon, 25 Apr 2022 14:03:09 +0000 Message-Id: <20220425140311.95231-3-german.gomez@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425140311.95231-1-german.gomez@arm.com> References: <20220425140311.95231-1-german.gomez@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: German Gomez via Elfutils-devel From: German Gomez Reply-To: German Gomez Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" Implement DW_CFA_AARCH64_negate_ra_state in accordance with the DWARF AARCH64 ABI [1]. Followup commits will use the value of this register to remove the PAC from return addresses. [1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#44call-frame-instructions Signed-off-by: German Gomez --- libdw/cfi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libdw/cfi.c b/libdw/cfi.c index a73fb03f..f985b4d8 100644 --- a/libdw/cfi.c +++ b/libdw/cfi.c @@ -125,6 +125,15 @@ execute_cfi (Dwarf_CFI *cache, fs->regs[regno].value = (r_value); \ } while (0) + /* The AARCH64 DWARF ABI states that register 34 (ra_sign_state) must + be initialized to 0. So do it before executing the CFI. */ + if (cache->e_machine == EM_AARCH64) + { + if (unlikely (! enough_registers (DW_AARCH64_RA_SIGN_STATE, &fs, &result))) + goto out; + fs->regs[DW_AARCH64_RA_SIGN_STATE].value = 0; + } + while (program < end) { uint8_t opcode = *program++; @@ -355,7 +364,10 @@ execute_cfi (Dwarf_CFI *cache, { /* Toggles the return address state, indicating whether the return address is encrypted or not on - aarch64. XXX not handled yet. */ + aarch64. */ + if (unlikely (! enough_registers (DW_AARCH64_RA_SIGN_STATE, &fs, &result))) + goto out; + fs->regs[DW_AARCH64_RA_SIGN_STATE].value ^= 0x1; } else {