Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cleanup during unwinding #1677

Open
bjorn3 opened this issue May 10, 2020 · 5 comments
Open

Support cleanup during unwinding #1677

bjorn3 opened this issue May 10, 2020 · 5 comments

Comments

@bjorn3
Copy link
Contributor

bjorn3 commented May 10, 2020

Feature

Currently the generated unwinding information only restores registers. This issue proposes to make it possible to also run cleanup actions like running destructors during unwinding.

Benefit

This is necessary to support unwinding after a panic in rustc_codegen_cranelift.

Implementation

Add a new invoke terminator that is similar to the call instruction, but has an additional cleanup edge. This cleanup edge will be ignored when emitting actual machine instructions, but it will take part in the regalloc. Next add a way to mark a block as "landing pad". Only "landing pad" blocks can be used as cleanup edge of an invoke terminator. At the start of a "cleanup" block all values are stored either on stack or in any of the registers restored by the system unwinder. The "landing pad" block can also take several arguments. Those will be the values stored in the registers that are allowed for arguments to the landing pad received from the personality function. After codegen the location of every "landing pad" block will be stored in a variable. This will allow the embedder to generate the appropriate LSDA (language specific data area) to reference from the unwinding table.

Alternatives

It is basically impossible to implement cleanup during unwinding without Cranelift support.

References

The "Transferring Control to a Landing Pad" section of https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf

@bjorn3
Copy link
Contributor Author

bjorn3 commented Jul 3, 2021

Original pdf no longer exists. See https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html instead.

@bayedieng
Copy link

Could this issue be solved independently using the aforementioned solution in the OP's comment or would #3427 be needed to be resolved first?

@bjorn3
Copy link
Contributor Author

bjorn3 commented Feb 26, 2023

I'm working on this.

@noverby
Copy link

noverby commented Jun 26, 2024

@bjorn3 Any PR or branch where it is possible to follow progress?

@bjorn3
Copy link
Contributor Author

bjorn3 commented Jun 26, 2024

https://github.com/bjorn3/wasmtime/tree/bsc-unwinding-simple-invoke3 is the latest version I have. I will rebase it and work on upstreaming when I finish my thesis about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants