public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: binutils@sourceware.org
Cc: Richard.Earnshaw@arm.com, Indu Bhagat <indu.bhagat@oracle.com>
Subject: [PATCH,V2 1/7] gas: scfi: make scfi_state_restore_reg function more precise
Date: Sat,  1 Jun 2024 00:34:50 -0700	[thread overview]
Message-ID: <20240601073456.2715287-2-indu.bhagat@oracle.com> (raw)
In-Reply-To: <20240601073456.2715287-1-indu.bhagat@oracle.com>

[New in V2]
 - This patch is orthogonal to aarch64 support.  It is included here
   because the testcase added for it is aarch64 specific.  It is a
   bugfix really.
[End of New in V2]

When the SCFI machinery detects that a register has been restored from
stack, it makes some state changes in the SCFI state object.

Prior to the patch, scfi_state_restore_reg () was setting a value of
(reg, CFI_IN_REG) for (base, state) respectively.  This was causing
issues in the cmp_scfi_state () function:
  - The default state of all (callee-saved) regs at the beginning of
    function is set to (0, CFI_UNDEFINED).
  - If a register is saved and restored on some control path, the state
    of reg is (reg, CFI_IN_REG) on that path.
  - On another control path where the register was perhaps not
    used (or saved/restored on stack) remains (0, CFI_UNDEFINED).
  - The two states should be treated equal, however, at the point in
    program after the register has been restored.

Fix this by resetting the state to (0, CFI_UNDEFINED) in
scfi_state_restore_reg ().

A testcase (scfi-cfg-4.s) for this is added in a subsequent commit.

gas/
        * scfi.c (scfi_state_restore_reg): Reset to 0, CFI_UNDEFINED
	for base, state.
---
 gas/scfi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gas/scfi.c b/gas/scfi.c
index 744822d8102..5898a57b330 100644
--- a/gas/scfi.c
+++ b/gas/scfi.c
@@ -223,11 +223,12 @@ scfi_state_restore_reg (scfi_stateS *state, unsigned int reg)
   gas_assert (state->regs[reg].state == CFI_ON_STACK);
   gas_assert (state->regs[reg].base == REG_CFA);
 
-  state->regs[reg].base = reg;
+  /* PS: the register may still be on stack much after the restore.  Reset the
+     SCFI state to CFI_UNDEFINED, however, to indicate that the most updated
+     source of value is register itself from here onwards.  */
+  state->regs[reg].base = 0;
   state->regs[reg].offset = 0;
-  /* PS: the register may still be on stack much after the restore, but the
-     SCFI state keeps the state as 'in register'.  */
-  state->regs[reg].state = CFI_IN_REG;
+  state->regs[reg].state = CFI_UNDEFINED;
 }
 
 /* Identify if the given GAS instruction GINSN saves a register
-- 
2.43.0


  reply	other threads:[~2024-06-01  7:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-01  7:34 [PATCH,V2 0/7] Add SCFI support for aarch64 Indu Bhagat
2024-06-01  7:34 ` Indu Bhagat [this message]
2024-06-06 16:09   ` [PATCH, V2 1/7] gas: scfi: make scfi_state_restore_reg function more precise Richard Earnshaw (lists)
2024-07-01  0:56     ` Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 2/7] opcodes: aarch64: flags to denote subclasses of ldst insns Indu Bhagat
2024-06-06 16:50   ` [PATCH, V2 " Richard Earnshaw (lists)
2024-06-06 20:31     ` Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 3/7] opcodes: aarch64: allow FLAGS in CPA_INSN, CPA_SVE_INSNC Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 4/7] opcodes: aarch64: flags to denote subclasses of arithmetic insns Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 5/7] opcodes: aarch64: flags to denote subclasses of uncond branches Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 6/7] gas: aarch64: add experimental support for SCFI Indu Bhagat
2024-06-01  7:34 ` [PATCH,V2 7/7] gas: aarch64: testsuite: add new tests " 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=20240601073456.2715287-2-indu.bhagat@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=Richard.Earnshaw@arm.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).