Stream: general

Topic: ✔ cranelift opcode get_return_address.


view this post on Zulip yang yu (Aug 12 2022 at 02:35):

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????

Standalone JIT-style runtime for WebAssembly, using Cranelift - wasmtime/abi.rs at risc-v · yuyang-ok/wasmtime

view this post on Zulip yang yu (Aug 18 2022 at 03:38):

https://github.com/bytecodealliance/wasmtime/pull/4271#issuecomment-1216070467

I am been trying to add riscv64 backend for cranelift these days. right now I have pass all run test in filetests. some features not implemented right now. i128 mul div rem, all simd type and com...

view this post on Zulip yang yu (Aug 18 2022 at 03:39):

@bjorn3

view this post on Zulip Anton Kirilov (Aug 18 2022 at 11:55):

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).

view this post on Zulip Anton Kirilov (Aug 18 2022 at 12:01):

The trampolines use this operation only once per function, and nothing clobbers LR before it, so things work out fine.

view this post on Zulip Anton Kirilov (Aug 18 2022 at 12:03):

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.

view this post on Zulip Anton Kirilov (Aug 18 2022 at 12:07):

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.

view this post on Zulip Anton Kirilov (Aug 18 2022 at 12:14):

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).

view this post on Zulip yang yu (Aug 21 2022 at 00:33):

@Anton Kirilov ok , thanks a lot.

view this post on Zulip yang yu (Aug 21 2022 at 07:04):

@Anton Kirilov right now load from LR is always ok, I think I can fellow the aarch64 implementation.

view this post on Zulip Anton Kirilov (Sep 02 2022 at 12:43):

@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.

The previous implementation assumed that nothing had clobbered the LR register since the current function had started executing, so it would be incorrect for a non-leaf function, for example, that ...

view this post on Zulip yang yu (Sep 03 2022 at 06:37):

@Anton Kirilov ok, I will fellow.

view this post on Zulip Notification Bot (Sep 21 2022 at 01:00):

yang yu has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC