From: German Gomez <german.gomez@arm.com>
To: elfutils-devel@sourceware.org
Subject: [PATCH 3/4] libdwfl, aarch64: Demangle return addresses using a PAC mask
Date: Mon, 25 Apr 2022 14:03:10 +0000 [thread overview]
Message-ID: <20220425140311.95231-4-german.gomez@arm.com> (raw)
In-Reply-To: <20220425140311.95231-1-german.gomez@arm.com>
Demangle mangled return addresses on AARCH64. The value of the masks is
stored in the struct Dwfl_Thread.
Signed-off-by: German Gomez <german.gomez@arm.com>
---
libdwfl/dwfl_frame.c | 3 +++
libdwfl/frame_unwind.c | 14 +++++++++++++-
libdwfl/libdwflP.h | 7 +++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index 77e0c5cb..88972d8e 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -270,6 +270,8 @@ dwfl_getthreads (Dwfl *dwfl, int (*callback) (Dwfl_Thread *thread, void *arg),
thread.process = process;
thread.unwound = NULL;
thread.callbacks_arg = NULL;
+ thread.aarch64.pauth_insn_mask = 0;
+
for (;;)
{
thread.tid = process->callbacks->next_thread (dwfl,
@@ -340,6 +342,7 @@ getthread (Dwfl *dwfl, pid_t tid,
thread.process = process;
thread.unwound = NULL;
thread.callbacks_arg = NULL;
+ thread.aarch64.pauth_insn_mask = 0;
if (process->callbacks->get_thread (dwfl, tid, process->callbacks_arg,
&thread.callbacks_arg))
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index 9ac33833..839d1eff 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -610,7 +610,19 @@ handle_cfi (Dwfl_Frame *state, Dwarf_Addr pc, Dwarf_CFI *cfi, Dwarf_Addr bias)
/* Some architectures encode some extra info in the return address. */
if (regno == frame->fde->cie->return_address_register)
- regval &= ebl_func_addr_mask (ebl);
+ {
+ regval &= ebl_func_addr_mask (ebl);
+
+ /* In aarch64, pseudo-register RA_SIGN_STATE indicates whether the
+ return address needs demangling using the PAC mask from the
+ thread. */
+ if (cfi->e_machine == EM_AARCH64 &&
+ frame->nregs > DW_AARCH64_RA_SIGN_STATE &&
+ frame->regs[DW_AARCH64_RA_SIGN_STATE].value & 0x1)
+ {
+ regval &= ~(state->thread->aarch64.pauth_insn_mask);
+ }
+ }
/* This is another strange PPC[64] case. There are two
registers numbers that can represent the same DWARF return
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 7503a627..d3fe8118 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -244,6 +244,12 @@ struct Dwfl_Thread
/* Bottom (innermost) frame while we're initializing, NULL afterwards. */
Dwfl_Frame *unwound;
void *callbacks_arg;
+
+ /* Data for handling AARCH64 (currently limited to demangling PAC from
+ return addresses). */
+ struct {
+ Dwarf_Addr pauth_insn_mask;
+ } aarch64;
};
/* See its typedef in libdwfl.h. */
@@ -782,6 +788,7 @@ INTDECL (dwfl_thread_tid)
INTDECL (dwfl_frame_thread)
INTDECL (dwfl_thread_state_registers)
INTDECL (dwfl_thread_state_register_pc)
+INTDECL (dwfl_thread_state_aarch64_pauth)
INTDECL (dwfl_getthread_frames)
INTDECL (dwfl_getthreads)
INTDECL (dwfl_thread_getframes)
--
2.25.1
next prev parent reply other threads:[~2022-04-25 14:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 14:03 [PATCH 0/4] Add AARCH64 pointer authentication support German Gomez
2022-04-25 14:03 ` [PATCH 1/4] aarch64: Create definitions for AARCH64_RA_SIGN_STATE register German Gomez
2023-02-23 16:22 ` Mark Wielaard
2022-04-25 14:03 ` [PATCH 2/4] libdw, aarch64: Implement DW_CFA_AARCH64_negate_ra_state CFI instruction German Gomez
2023-02-23 16:27 ` Mark Wielaard
2022-04-25 14:03 ` German Gomez [this message]
2022-04-25 14:03 ` [PATCH 4/4] libdwfl, eu-stack, aarch64: Add API for setting AARCH64 PAC mask German Gomez
2022-04-28 19:56 ` [PATCH 0/4] Add AARCH64 pointer authentication support Mark Wielaard
2022-05-19 13:30 ` German Gomez
2022-05-19 14:20 ` German Gomez
2023-02-24 0:17 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220425140311.95231-4-german.gomez@arm.com \
--to=german.gomez@arm.com \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).