get_return_address should always return "return address", I have no doubt.
https://github.com/yuyang-ok/wasmtime/blob/risc-v/cranelift/codegen/src/isa/riscv64/abi.rs#L693
but frame can be set when need, return address can save in different place (on stack or in ra register).
when lowring should base on is_frame_setup_needed
load from differrent place????
https://github.com/bytecodealliance/wasmtime/pull/4271#issuecomment-1216070467
@bjorn3
The AArch64 backend has the same issue, but right now get_return_address
is only used by trampolines, so the implementation is a bit sloppy and assumes that the return address is in the regular register (LR
).
The trampolines use this operation only once per function, and nothing clobbers LR
before it, so things work out fine.
Also, note that it is up to the backend to implement is_frame_setup_needed()
, so you can just make it always return true
, if it will make things simpler for you.
You must implement the case in which the frame set-up is necessary because Wasmtime requires it for unwinding purposes, but the other case is just an optimization, so there is no obligation to cover it.
As a side note, a proper AArch64 implementation of get_return_address
would need to account for whether there is a frame record on stack or not, whether return addresses are signed or not, and whether the target supports pointer authentication or not (because stripping signed return addresses of the pointer authentication code is easier if we can use some of the the non-HINT
instructions).
@Anton Kirilov ok , thanks a lot.
@Anton Kirilov right now load from LR
is always ok, I think I can fellow the aarch64
implementation.
@yang yu I decided to fix the AArch64 implementation and did it in PR #4851. Note that the verifier rejects the get_return_address
operation if the preserve_frame_pointers
option is false, but my implementation checks for its presence as an additional safety net.
@Anton Kirilov ok, I will fellow.
yang yu has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC