From: Indu Bhagat <indu.bhagat@oracle.com>
To: binutils@sourceware.org
Cc: Indu Bhagat <indu.bhagat@oracle.com>
Subject: [COMMITTED, V2 2/6] gas: sframe: add support for .cfi_negate_ra_state
Date: Fri, 16 Dec 2022 22:41:24 -0800 [thread overview]
Message-ID: <20221217064128.11326-3-indu.bhagat@oracle.com> (raw)
In-Reply-To: <20221217064128.11326-1-indu.bhagat@oracle.com>
[Changes in V2]
- bugfix: set merge_candidate to false when processing
DW_CFA_GNU_window_save.
- Instead of removing common-empty-4.s test in a later commit, remove
the testcase common-empty-4 here in this commit.
[End of changes in V2]
DW_CFA_AARCH64_negate_ra_state in aarch64 is multiplexed with
DW_CFA_GNU_window_save in the DWARF format.
Remove the common-empty-4 testcase because the generated SFrame section
will not be be empty anymore. A relevant test will be added in a later
commit.
ChangeLog:
* gas/gen-sframe.c (sframe_v1_set_fre_info): Add new argument
for mangled_ra_p.
(sframe_set_fre_info): Likewise.
(output_sframe_row_entry): Handle mangled_ra_p.
(sframe_row_entry_new): Reset mangled_ra_p.
(sframe_row_entry_initialize): Initialize mangled_ra_p.
(sframe_xlate_do_gnu_window_save): New definition.
(sframe_do_cfi_insn): Handle DW_CFA_GNU_window_save.
* gas/gen-sframe.h (struct sframe_row_entry): New member.
(struct sframe_version_ops): Add a new argument for
mangled_ra_p.
* gas/testsuite/gas/cfi-sframe/cfi-sframe.exp: Remove test.
* gas/testsuite/gas/cfi-sframe/common-empty-4.d: Removed.
* gas/testsuite/gas/cfi-sframe/common-empty-4.s: Removed.
---
gas/gen-sframe.c | 42 +++++++++++++++----
gas/gen-sframe.h | 6 ++-
gas/testsuite/gas/cfi-sframe/cfi-sframe.exp | 1 -
gas/testsuite/gas/cfi-sframe/common-empty-4.d | 14 -------
gas/testsuite/gas/cfi-sframe/common-empty-4.s | 17 --------
5 files changed, 39 insertions(+), 41 deletions(-)
delete mode 100644 gas/testsuite/gas/cfi-sframe/common-empty-4.d
delete mode 100644 gas/testsuite/gas/cfi-sframe/common-empty-4.s
diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 075720facd6..9baf20bd873 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -243,10 +243,11 @@ static struct sframe_version_ops sframe_ver_ops;
static unsigned char
sframe_v1_set_fre_info (unsigned int base_reg, unsigned int num_offsets,
- unsigned int offset_size)
+ unsigned int offset_size, bool mangled_ra_p)
{
unsigned char fre_info;
fre_info = SFRAME_V1_FRE_INFO (base_reg, num_offsets, offset_size);
+ fre_info = SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P (mangled_ra_p, fre_info);
return fre_info;
}
@@ -275,10 +276,10 @@ sframe_set_version (uint32_t sframe_version __attribute__((unused)))
static unsigned char
sframe_set_fre_info (unsigned int base_reg, unsigned int num_offsets,
- unsigned int offset_size)
+ unsigned int offset_size, bool mangled_ra_p)
{
return sframe_ver_ops.set_fre_info (base_reg, num_offsets,
- offset_size);
+ offset_size, mangled_ra_p);
}
/* SFrame set func info. */
@@ -507,7 +508,7 @@ output_sframe_row_entry (symbolS *fde_start_addr,
fre_num_offsets = get_fre_num_offsets (sframe_fre);
fre_offset_size = sframe_get_fre_offset_size (sframe_fre);
fre_info = sframe_set_fre_info (fre_base_reg, fre_num_offsets,
- fre_offset_size);
+ fre_offset_size, sframe_fre->mangled_ra_p);
out_one (fre_info);
idx = sframe_fre_offset_func_map_index (fre_offset_size);
@@ -845,6 +846,9 @@ sframe_row_entry_new (void)
for the supported arches. */
fre->cfa_base_reg = -1;
fre->merge_candidate = true;
+ /* Reset the mangled RA status bit to zero by default. We will initialize it in
+ sframe_row_entry_initialize () with the sticky bit if set. */
+ fre->mangled_ra_p = false;
return fre;
}
@@ -890,6 +894,9 @@ sframe_row_entry_initialize (struct sframe_row_entry *cur_fre,
cur_fre->bp_offset = prev_fre->bp_offset;
cur_fre->ra_loc = prev_fre->ra_loc;
cur_fre->ra_offset = prev_fre->ra_offset;
+ /* Treat RA mangling as a sticky bit. It retains its value until another
+ .cfi_negate_ra_state is seen. */
+ cur_fre->mangled_ra_p = prev_fre->mangled_ra_p;
}
/* Translate DW_CFA_advance_loc into SFrame context.
@@ -1150,6 +1157,23 @@ sframe_xlate_do_restore (struct sframe_xlate_ctx *xlate_ctx,
return SFRAME_XLATE_OK;
}
+/* Translate DW_CFA_GNU_window_save into SFrame context.
+ Return SFRAME_XLATE_OK if success. */
+
+static int
+sframe_xlate_do_gnu_window_save (struct sframe_xlate_ctx *xlate_ctx,
+ struct cfi_insn_data *cfi_insn ATTRIBUTE_UNUSED)
+{
+ struct sframe_row_entry *cur_fre = xlate_ctx->cur_fre;
+
+ gas_assert (cur_fre);
+ /* Toggle the mangled RA status bit. */
+ cur_fre->mangled_ra_p = !cur_fre->mangled_ra_p;
+ cur_fre->merge_candidate = false;
+
+ return SFRAME_XLATE_OK;
+}
+
/* Process CFI_INSN and update the translation context with the FRE
information.
@@ -1195,6 +1219,11 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx,
case DW_CFA_restore:
err = sframe_xlate_do_restore (xlate_ctx, cfi_insn);
break;
+ /* DW_CFA_AARCH64_negate_ra_state is multiplexed with
+ DW_CFA_GNU_window_save. */
+ case DW_CFA_GNU_window_save:
+ err = sframe_xlate_do_gnu_window_save (xlate_ctx, cfi_insn);
+ break;
case DW_CFA_undefined:
case DW_CFA_same_value:
break;
@@ -1207,10 +1236,7 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx,
- ...
Following skipped operations do, however, impact the asynchronicity:
- - CFI_escape,
- - DW_CFA_GNU_window_save,
- - DW_CFA_AARCH64_negate_ra_state (multiplexed with
- DW_CFA_GNU_window_save) */
+ - CFI_escape */
err = SFRAME_XLATE_ERR_NOTREPRESENTED;
// printf (_("SFrame Unsupported or unknown Dwarf CFI number: %#x\n"), op);
diff --git a/gas/gen-sframe.h b/gas/gen-sframe.h
index 93af499278c..5d5702a57ca 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -50,6 +50,9 @@ struct sframe_row_entry
on it. */
bool merge_candidate;
+ /* Whether the return address is mangled with pauth code. */
+ bool mangled_ra_p;
+
/* Track CFA base (architectural) register ID. */
unsigned int cfa_base_reg;
/* Offset from the CFA base register for recovering CFA. */
@@ -140,7 +143,8 @@ struct sframe_version_ops
{
unsigned char format_version; /* SFrame format version. */
/* set SFrame FRE info. */
- unsigned char (*set_fre_info) (unsigned int, unsigned int, unsigned int);
+ unsigned char (*set_fre_info) (unsigned int, unsigned int, unsigned int,
+ bool);
/* set SFrame Func info. */
unsigned char (*set_func_info) (unsigned int, unsigned int);
};
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
index eb6da614c2f..8129e86ccce 100644
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
@@ -82,7 +82,6 @@ if { ([istarget "x86_64-*-*"] || [istarget "aarch64*-*-*"]) \
run_dump_test "common-empty-1"
run_dump_test "common-empty-2"
run_dump_test "common-empty-3"
- run_dump_test "common-empty-4"
}
# x86-64 specific tests
diff --git a/gas/testsuite/gas/cfi-sframe/common-empty-4.d b/gas/testsuite/gas/cfi-sframe/common-empty-4.d
deleted file mode 100644
index f7a6062d392..00000000000
--- a/gas/testsuite/gas/cfi-sframe/common-empty-4.d
+++ /dev/null
@@ -1,14 +0,0 @@
-#as: --gsframe
-#objdump: --sframe=.sframe
-#name: SFrame supports only default return column
-#...
-Contents of the SFrame section .sframe:
-
- Header :
-
- Version: SFRAME_VERSION_1
- Flags: NONE
- Num FDEs: 0
- Num FREs: 0
-
-#pass
diff --git a/gas/testsuite/gas/cfi-sframe/common-empty-4.s b/gas/testsuite/gas/cfi-sframe/common-empty-4.s
deleted file mode 100644
index f97ca2f7ff9..00000000000
--- a/gas/testsuite/gas/cfi-sframe/common-empty-4.s
+++ /dev/null
@@ -1,17 +0,0 @@
-## ARMv8.3 addded support a new security feature named Pointer Authentication. The
-## main idea behind this is to use the unused bits in the pointer values.
-## Each pointer is patched with a PAC before writing to memory, and is verified
-## before using it.
-## When the pointers are mangled, the unwinder needs to know so it can mask off
-## the PAC from the pointer value to recover the return address, and
-## conversely, skip doing so if the pointers are not mangled.
-##
-## .cfi_negate_ra_state CFI directive is used to convey this information.
-##
-## SFrame does not have any means to represent this information at this time.
- .cfi_startproc
- .long 0
- .cfi_def_cfa_offset 16
- .cfi_negate_ra_state
- .long 0
- .cfi_endproc
--
2.37.2
next prev parent reply other threads:[~2022-12-17 6:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-17 6:41 [COMMITTED, V2 0/6] SFrame: support for .cfi_negate_ra_state in aarch64 Indu Bhagat
2022-12-17 6:41 ` [COMMITTED, V2 1/6] sframe.h: add support for .cfi_negate_ra_state Indu Bhagat
2022-12-17 6:41 ` Indu Bhagat [this message]
2022-12-17 6:41 ` [COMMITTED, V2 3/6] libsframe: provide new access API for mangled RA bit Indu Bhagat
2022-12-17 6:41 ` [COMMITTED, V2 4/6] objdump/readelf: sframe: emit marker for FREs with mangled RA Indu Bhagat
2022-12-17 6:41 ` [COMMITTED, V2 5/6] gas: sframe: testsuite: add testcase for .cfi_negate_ra_state Indu Bhagat
2022-12-17 6:41 ` [COMMITTED, V2 6/6] sframe: doc: update spec for the mangled-RA bit in FRE Indu Bhagat
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=20221217064128.11326-3-indu.bhagat@oracle.com \
--to=indu.bhagat@oracle.com \
--cc=binutils@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).