public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH,V1 00/14] Definition and support for SFrame unwind format
Date: Mon, 3 Oct 2022 22:16:39 -0700	[thread overview]
Message-ID: <186042dd-15f1-7d0b-abf4-020201d65b2e@oracle.com> (raw)
In-Reply-To: <ef8a4579-50b1-b2e9-f54b-11656db92bc1@suse.com>

On 9/30/22 01:09, Jan Beulich wrote:
> On 30.09.2022 02:04, Indu Bhagat via Binutils wrote:
>> What is SFrame format and why do we need it
>> -------------------------------------------
>> SFrame format is the Simple Frame format.  It can be used to represent the
>> minimal necessary information for backtracing.  As such, it only encodes how to
>> recover the CFA (based on SP/FP) and the return address (RA) for all
>> instructions of a program.
>>
>> The format is supported on AMD64 and AARCH64 ABIs only.  The information stored
>> in the .sframe section is a subset of what .eh_frame can convey: .eh_frame can
>> convey how to resurrect all callee-saved registers, if need be; but .sframe
>> does not.
> 
> I expect the question was asked before, but since the summary here doesn't
> answer it: What about cases where the return address is stored in a
> callee-saved register? You won't be able to determine its value if that
> wasn't the leaf-most function in the active call chain and some inner
> function saved and then modified that (presumably) GPR. The same would
> likely apply if the return address was saved to some secondary stack.
> 
> Jan

Yes, this question was asked before. And thanks for asking this here.

(In the context of recovering return address) As far as x86_64 and 
aarch64 are concerned, I *believe* SFrame can represent most 
ABI-conforming cases with standard stack usage (except the #exceptions 
noted at the end of this message):
  - For x86_64, the return address is saved on stack with every call 
instruction
  - For aarch64, (from the ABI doc) all "Conforming code shall construct 
a linked list of stack-frames. Each frame shall link to the frame of its 
caller by means
of a frame record of two 64-bit values on the stack (independent of the 
data model).". So the return address is tracked as it flows from LR to 
stack and so on in the SFrame format.

So, IIUC, the case you mention will be "non ABI conforming code", 
correct ? In such a case, SFrame format cannot be used as is. It will 
need to be extended to support such cases:
  - first, encode the return register per SFrame FDE (so additional few 
bits per FDE).
  - second, recover all possible return registers (i.e., all 
callee-saved registers per FDE) via stack offsets in every FRE as 
applicable.

The second item will not fly in the SFrame format (atleast not in its 
current form); storing stack offsets explicitly like that (for a bunch 
of registers) will cause the unwind metadata to get quite large.  If 
there is a high usage of non-conforming code in applications, and SFrame 
is still desirable for those, something needs to be done.

My viewpoint here was to keep the format simple by targeting to support 
all ABI-conforming code. Is that reasonable ? (Posing this question to 
also the wider community).

Now a subset your question, I believe, also intends to ask - how do you 
plan to support architectures/ABIs where the return address can be in 
any register. The answer goes back to the above-mentioned two pieces of 
information (needed for non ABI conforming code in context of x86_64 and 
aarch64) and their high cost in SFrame format. Instead, an alternative 
strategy could be to take compiler's help to assign a "recommended 
register" for return register usage in such ABIs. The SFrame format will 
still need extensions (but these extensions are minimal) :
  - an additional field in the SFrame header to designate the 
"recommended return register" (the same register which was used at 
compile time).
  - the new ABI marker in the SFrame header.

Now if the compiler is not able to use the recommended return register 
for some functions, it will mean that SFrame-based backtracing will not 
work through those functions, hence affecting asynchronicity. I must 
admit that I haven't fully thought this one through, so not completely 
sure if such a solution work ? I think it might.

re: return address was saved to some secondary stack. I need some more 
understanding of the issue here. I was thinking an entity higher up, 
like the unwinder, will have enough context to pick the appropriate 
stack to which the stack offsets apply; because the decision as to when 
to switch to a secondary stack (or not) must be a application specific 
property ? If you have some resources to share here, it will be helpful. 
Alternatively, if usage of secondary stack is specified at an ABI level, 
can you please provide a reference so I can take a look ?

#exceptions (PS: I plan to work on these) :
  - .cfi_negate_ra_state handling in aarch64: if the code uses pointer 
signing for the return address, SFrame needs extensions to represent that.
  - .cfi_escape asm directives: these are also being skipped at this 
time. I may not be able to handle everything here, but even if we handle 
the most commonly occurring cases, I think we can get close.

Thanks

  reply	other threads:[~2022-10-04  5:16 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02  8:04 [PATCH,V6 00/10] Definition and Implementation of CTF Frame format Indu Bhagat
2022-08-02  8:04 ` [PATCH,V6 01/10] ctf-frame.h: Add CTF Frame format definition Indu Bhagat
2022-08-15 12:04   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 02/10] gas: add new command line option --gctf-frame Indu Bhagat
2022-08-15 12:07   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 03/10] gas: generate .ctf_frame Indu Bhagat
2022-08-15 12:22   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 04/10] libctfframe: add the CTF Frame library Indu Bhagat
2022-08-15 12:46   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 05/10] libctfframe: add GNU poke pickles for CTF Frame Indu Bhagat
2022-08-15 12:50   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 06/10] bfd: linker: merge .ctf_frame sections Indu Bhagat
2022-08-15 13:02   ` Nick Clifton
2022-08-18  2:11     ` Indu Bhagat
2022-08-02  8:04 ` [PATCH,V6 07/10] readelf/objdump: support for CTF Frame section Indu Bhagat
2022-08-15 13:11   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 08/10] unwinder: generate backtrace using CTF Frame format Indu Bhagat
2022-08-15 13:16   ` Nick Clifton
2022-08-02  8:04 ` [PATCH,V6 09/10] unwinder: Add CTF Frame unwinder tests Indu Bhagat
2022-08-15 13:27   ` Nick Clifton
2022-08-02  8:04 ` [PATCH, V6 10/10] gdb: sim: buildsystem changes to accommodate libctfframe Indu Bhagat
2022-08-05 14:43   ` Tom Tromey
2022-08-15 12:18 ` [PATCH,V6 00/10] Definition and Implementation of CTF Frame format Nick Clifton
2022-08-18  1:38   ` Indu Bhagat
2022-08-15 14:25 ` Nick Clifton
2022-09-30  0:04   ` [PATCH,V1 00/14] Definition and support for SFrame unwind format Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 01/14] sframe.h: Add SFrame format definition Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 02/14] gas: add new command line option --gsframe Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 03/14] gas: generate .sframe from CFI directives Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 04/14] gas: testsuite: add new tests for SFrame unwind info Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 05/14] libsframe: add the SFrame library Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 06/14] bfd: linker: merge .sframe sections Indu Bhagat
2022-09-30 10:51       ` Nick Clifton
2022-09-30  0:04     ` [PATCH,V1 07/14] readelf/objdump: support for SFrame section Indu Bhagat
2022-09-30 11:08       ` Nick Clifton
2022-09-30  0:04     ` [PATCH,V1 08/14] unwinder: generate backtrace using SFrame format Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 09/14] unwinder: Add SFrame unwinder tests Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 10/14] gdb: sim: buildsystem changes to accommodate libsframe Indu Bhagat
2022-10-11 16:08       ` [PATCH, V1 " Tom Tromey
2022-09-30  0:04     ` [PATCH,V1 11/14] libctf: add libsframe to LDFLAGS and LIBS Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 12/14] src-release.sh: Add libsframe Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 13/14] binutils/NEWS: add text for SFrame support Indu Bhagat
2022-09-30  0:04     ` [PATCH,V1 14/14] gas/NEWS: add text about new command line option and " Indu Bhagat
2022-09-30  8:09     ` [PATCH,V1 00/14] Definition and support for SFrame unwind format Jan Beulich
2022-10-04  5:16       ` Indu Bhagat [this message]
2022-10-04  6:53         ` Jan Beulich
2022-09-30  8:24     ` Fangrui Song
2022-10-01  0:15       ` Indu Bhagat
2022-09-30  9:12     ` Nick Clifton
2022-10-01  0:29       ` Indu Bhagat
2022-10-01  9:51       ` Jose E. Marchesi

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=186042dd-15f1-7d0b-abf4-020201d65b2e@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.com \
    /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).