cranelift: Add a new, optional flag for preserving frame pointers#4469
Conversation
cfallin
left a comment
There was a problem hiding this comment.
LGTM, and good to merge once we have s390x supported as well -- thanks!
cranelift/filetests/filetests/isa/aarch64/leaf_with_preserve_frame_pointers.clif
Show resolved
Hide resolved
As I just said over in #4431 (comment) I think we can actually land this PR now, since it doesn't break anything by itself, as nothing is relying on the frame pointers yet. But we shouldn't land #4431 until there is |
|
Ah, my mistake, I had misunderstood the intended order of changes; yep, r+ for merging this now. Thanks! |
Preserving frame pointers -- even inside leaf functions -- makes it easy to capture the stack of a running program, without requiring any side tables or metadata (like `.eh_frame` sections). Many sampling profilers and similar tools walk frame pointers to capture stacks. Enabling this option will play nice with those tools.
14f6155 to
709a762
Compare
Subscribe to Label Actioncc @peterhuene DetailsThis issue or pull request has been labeled: "cranelift", "cranelift:area:machinst", "cranelift:meta", "wasmtime:api"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Sure, I will post a follow-up PR to add |
Thanks! |
On s390x, we do not have a frame pointer that can be used to chain stack frames for easy unwinding. Instead, our ABI defines a stack "backchain" mechanism that can be used to the same effect. This PR uses that backchain mechanism to implement the new preserve_frame_pointers flags introduced here: bytecodealliance#4469
On s390x, we do not have a frame pointer that can be used to chain stack frames for easy unwinding. Instead, our ABI defines a stack "backchain" mechanism that can be used to the same effect. This PR uses that backchain mechanism to implement the new preserve_frame_pointers flags introduced here: bytecodealliance#4469
| Enabling this option will play nice with those tools. | ||
| "#, | ||
| false, | ||
| ); |
There was a problem hiding this comment.
LLVM has a tri-state value of "always", "non-leaf" and "may-omit". It would be nice if Cranelift could have the same so I don't have to use the equivalent of "always" if "non-leaf" was chosen by the rustc target. For example Apple AArch64 targets require "non-leaf".
There was a problem hiding this comment.
This is something we can do in the future as needed.
There was a problem hiding this comment.
Actually with the way the AArch64 backend works right now it is either "always" (i.e. preserve_frame_pointers being true) or "non-leaf" (i.e. false value). "may-omit" sounds as if it would be fine to treat it as "non-leaf".
P.S. Technically even leaf functions always preserve frame pointers as long as they use the stack, e.g. define an explicit stack slot.
There was a problem hiding this comment.
The name preserve_frame_pointers makes it seem like false means that frame pointers may always be omitted.
There was a problem hiding this comment.
Yes, thinking a bit more about this, actually the AArch64 backend always "preserves" the frame pointer (i.e. it always has a valid value - either 0 or an address that points to a frame record on the stack), since the respective register is not allocatable; it is just that some functions (simple leaf functions that do not use the stack) opt not to update it, and keep its value as set by their callers.
On s390x, we do not have a frame pointer that can be used to chain stack frames for easy unwinding. Instead, our ABI defines a stack "backchain" mechanism that can be used to the same effect. This PR uses that backchain mechanism to implement the new preserve_frame_pointers flags introduced here: #4469
This flag is optional, but when it is set then Cranelift backends must preserve frame pointers (or ISA equivalent).
Preserving frame pointers -- even inside leaf functions -- makes it easy to capture the stack of a running program, without requiring any side tables or metadata (like
.eh_framesections). Many sampling profilers and similar tools walk frame pointers to capture stacks. Enabling this option will play nice with those tools.Our
x64backend already unconditionally preserves frame pointers, so it is trivially conforming with this new flag.Our
aarch64backend preserves frame pointers or not based on whether themachinstframework tells it to or not by callinggen_prologue_frame_setup, and themachinstframework looks at this new flag when deciding whether to call the backend's implementation ofgen_prologue_frame_setup, so it is conforming with this new flag.However, our
s390xbackend has an empty implementation ofgen_prologue_frame_setup, and so it is not preserving frame pointers when this new flag is set. We will need a follow up PR that brings ours390xbackend into conformance with this new flag.cc @uweigand, your help with this last bit would be very appreciated, as I'm not familiar with
s390x.cc #4431