[PATCH 2/6] [2/6] gas: sframe: add support for .cfi_negate_ra_state
Indu Bhagat
indu.bhagat@oracle.com
Wed Dec 14 19:58:55 GMT 2022
DW_CFA_AARCH64_negate_ra_state in aarch64 is multiplexed with
DW_CFA_GNU_window_save in the DWARF format.
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): 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):
(struct sframe_version_ops): Add a new argument for mangled_ra_p.
---
gas/gen-sframe.c | 41 +++++++++++++++++++++++++++++++++--------
gas/gen-sframe.h | 6 +++++-
2 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 075720facd6..f31a66da377 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,22 @@ 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;
+
+ return SFRAME_XLATE_OK;
+}
+
/* Process CFI_INSN and update the translation context with the FRE
information.
@@ -1195,6 +1218,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 +1235,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..aa8be5df457 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -50,6 +50,9 @@ struct sframe_row_entry
on it. */
bool merge_candidate;
+ /* Toggle RA state wrt pointer authentication 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);
};
--
2.37.2
More information about the Binutils
mailing list