Skip to content

Exception support #2049

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

Open
carlokok opened this issue Jul 20, 2020 · 6 comments
Open

Exception support #2049

carlokok opened this issue Jul 20, 2020 · 6 comments

Comments

@carlokok
Copy link
Contributor

Feature

Cranelift currently doesn't support SEH (but has some support for finally I think). This is a feature request to support properly exception (landingpads on Posix, SEH on windows, maybe SLJL for others)

Benefit

WASM has plans to support exceptions, at which point it's going to be needed. Win64 has partial SEH support (iirc it just emits what's needed, nothing more), this would allow for c++ /java/.net exception support.

Implementation

Tricky one. I know LLVM has two alternative ways of doing this. I think with that in mind it should be possible to do a single implementation. What's basically needed is a way to say:
from here
[code]

till here is a protected block, on exceptions go to X, for finalization go to Y. For the handler itself it should be possible to define the personality to call.

Throw, Rethrow etc can all probably be done on a library level.

Alternatives

The only alternative is to not do it.

@bjorn3
Copy link
Contributor

bjorn3 commented Jul 20, 2020

Duplicate of #1677

@carlokok
Copy link
Contributor Author

I agree it's related, but unwind and catch are slightly distinct actions and your issue doesn't cover that?

@bjorn3
Copy link
Contributor

bjorn3 commented Jul 20, 2020

Catch is implemented by returning _URC_HANDLER_FOUND instead of _URC_INSTALL_CONTEXT from the personality function and then jumping from the landing pad to the block handling the catch instead of calling _Unwind_Resume like for cleanup.

@bjorn3
Copy link
Contributor

bjorn3 commented Feb 3, 2021

Given the above comments I think this can be closed as duplicate.

@carlokok
Copy link
Contributor Author

carlokok commented Feb 3, 2021

I missed your reply last year but does that cover windows at all? Windows doesn't use personalities? At least not like that?

@bjorn3
Copy link
Contributor

bjorn3 commented Feb 3, 2021

SEH seems to use exception handlers and termination handlers. I think catching an exception instead of doing cleanup is done by using an exception handler instead of termination handler. This is based on a cursory reading of the docs though, so I may be wrong. In any case both catching exceptions and cleanup needs the same codegen handling to support an alternative location to which a call can "return".

aykevl added a commit to tinygo-org/tinygo that referenced this issue Aug 4, 2024
Add unwinding and recover support for wasm using WebAssembly exception
handling. This still has a few gotchas:

  * Many WASI systems don't support exception handling yet.
    For example, see:
    bytecodealliance/wasmtime#2049
  * Asyncify doesn't support wasm exception handling:
    WebAssembly/binaryen#4470
    This means it's not possible to use goroutines together with
    panic/recover.
  * The current way that exceptions are implemented pretend to be C++
    exceptions, but work slightly differently. If C++ code is called
    (for example through CGo) that raises an exception, that exception
    will be eaten by TinyGo and not be propagated. This is fixable, it
    just hasn't been implemented (because we don't actually support C++
    right now).

I hope that these issues will be resolved over time. At least for now,
people who need `recover()` have a way to use it.
aykevl added a commit to tinygo-org/tinygo that referenced this issue Aug 4, 2024
Add unwinding and recover support for wasm using WebAssembly exception
handling. This still has a few gotchas:

  * Many WASI systems don't support exception handling yet.
    For example, see:
    bytecodealliance/wasmtime#2049
  * Asyncify doesn't support wasm exception handling:
    WebAssembly/binaryen#4470
    This means it's not possible to use goroutines together with
    panic/recover.
  * The current way that exceptions are implemented pretend to be C++
    exceptions, but work slightly differently. If C++ code is called
    (for example through CGo) that raises an exception, that exception
    will be eaten by TinyGo and not be propagated. This is fixable, it
    just hasn't been implemented (because we don't actually support C++
    right now).

I hope that these issues will be resolved over time. At least for now,
people who need `recover()` have a way to use it.
aykevl added a commit to tinygo-org/tinygo that referenced this issue Aug 14, 2024
Add unwinding and recover support for wasm using WebAssembly exception
handling. This still has a few gotchas:

  * Many WASI systems don't support exception handling yet.
    For example, see:
    bytecodealliance/wasmtime#2049
  * Asyncify doesn't support wasm exception handling:
    WebAssembly/binaryen#4470
    This means it's not possible to use goroutines together with
    panic/recover.
  * The current way that exceptions are implemented pretend to be C++
    exceptions, but work slightly differently. If C++ code is called
    (for example through CGo) that raises an exception, that exception
    will be eaten by TinyGo and not be propagated. This is fixable, it
    just hasn't been implemented (because we don't actually support C++
    right now).

I hope that these issues will be resolved over time. At least for now,
people who need `recover()` have a way to use 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

2 participants