-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add support for wasm exception handling to Emscripten target #131830
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/doc/unstable-book/src/compiler-flags/emscripten-wasm-eh.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# `emscripten-wasm-eh` | ||
|
||
Use the WebAssembly exception handling ABI to unwind for the | ||
`wasm32-unknown-emscripten`. If compiling with this setting, the `emcc` linker | ||
should be invoked with `-fwasm-exceptions`. If linking with C/C++ files, the | ||
C/C++ files should also be compiled with `-fwasm-exceptions`. |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//@ compile-flags: -O --target wasm32-unknown-emscripten -Z emscripten-wasm-eh | ||
//@ needs-llvm-components: webassembly | ||
|
||
// Emscripten catch_unwind using wasm exceptions | ||
|
||
#![feature(no_core, lang_items, intrinsics, rustc_attrs)] | ||
#![crate_type = "lib"] | ||
#![no_std] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "freeze"] | ||
trait Freeze {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
impl<T> Copy for *mut T {} | ||
|
||
#[rustc_intrinsic] | ||
fn size_of<T>() -> usize { | ||
loop {} | ||
} | ||
|
||
extern "rust-intrinsic" { | ||
fn catch_unwind( | ||
try_fn: fn(_: *mut u8), | ||
data: *mut u8, | ||
catch_fn: fn(_: *mut u8, _: *mut u8), | ||
) -> i32; | ||
} | ||
|
||
// CHECK-LABEL: @ptr_size | ||
#[no_mangle] | ||
pub fn ptr_size() -> usize { | ||
// CHECK: ret [[PTR_SIZE:.*]] | ||
size_of::<*mut u8>() | ||
} | ||
|
||
// CHECK-LABEL: @test_catch_unwind | ||
#[no_mangle] | ||
pub unsafe fn test_catch_unwind( | ||
try_fn: fn(_: *mut u8), | ||
data: *mut u8, | ||
catch_fn: fn(_: *mut u8, _: *mut u8), | ||
) -> i32 { | ||
// CHECK: start: | ||
// CHECK: invoke void %try_fn(ptr %data) | ||
// CHECK: to label %__rust_try.exit unwind label %catchswitch.i | ||
// CHECK: catchswitch.i: ; preds = %start | ||
// CHECK: %catchswitch1.i = catchswitch within none [label %catchpad.i] unwind to caller | ||
|
||
// CHECK: catchpad.i: ; preds = %catchswitch.i | ||
// CHECK: %catchpad2.i = catchpad within %catchswitch1.i [ptr null] | ||
// CHECK: %0 = tail call ptr @llvm.wasm.get.exception(token %catchpad2.i) | ||
// CHECK: %1 = tail call i32 @llvm.wasm.get.ehselector(token %catchpad2.i) | ||
// CHECK: call void %catch_fn(ptr %data, ptr %0) [ "funclet"(token %catchpad2.i) ] | ||
// CHECK: catchret from %catchpad2.i to label %__rust_try.exit | ||
|
||
// CHECK: __rust_try.exit: ; preds = %start, %catchpad.i | ||
// CHECK: %common.ret.op.i = phi i32 [ 0, %start ], [ 1, %catchpad.i ] | ||
// CHECK: ret i32 %common.ret.op.i | ||
|
||
catch_unwind(try_fn, data, catch_fn) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: unexpected `--cfg emscripten_wasm_eh` flag | ||
| | ||
= note: config `emscripten_wasm_eh` is only supposed to be controlled by `-Z emscripten_wasm_eh` | ||
= note: manually setting a built-in cfg can and does create incoherent behaviors | ||
= note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/ui/feature-gates/feature-gate-cfg-emscripten-wasm-eh.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//@ compile-flags: --check-cfg=cfg(emscripten_wasm_eh) | ||
#[cfg(not(emscripten_wasm_eh))] | ||
//~^ `cfg(emscripten_wasm_eh)` is experimental | ||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui/feature-gates/feature-gate-cfg-emscripten-wasm-eh.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: `cfg(emscripten_wasm_eh)` is experimental and subject to change | ||
--> $DIR/feature-gate-cfg-emscripten-wasm-eh.rs:2:11 | ||
| | ||
LL | #[cfg(not(emscripten_wasm_eh))] | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(cfg_emscripten_wasm_eh)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.