Skip to content

Commit 205aceb

Browse files
committed
Auto merge of #148291 - purplesyringa:move-throw-to-unwind, r=bjorn3
Move wasm `throw` intrinsic back to `unwind` Fixes rust-lang/rust#148246, less invasive than the previously proposed rust-lang/rust#148269. Removes the publicly visible unstable intrinsic tracked in rust-lang/rust#122465 since it's not clear how to export it in a sound manner. r? `@bjorn3` --- rustc assumes that regular `extern "Rust"` functions unwind only if the `unwind` panic runtime is linked. `throw` was annotated as such, but unwound unconditionally. This could cause UB when a crate built with `-C panic=abort` called `throw` from `core` built with `-C panic=unwind`, since no terminator was added to handle the panic arising from calling an allegedly non-unwinding `extern "Rust"` function. rustc was taught to recognize this condition since rust-lang/rust#144225 and prevented such linkage, but this caused regressions in rust-lang/rust#148246, since this meant that Emscripten projects could not be built with `-C panic=abort` without recompiling std. The most straightforward solution would be to move `throw` into the `panic_unwind` crate, so that it's only compiled if the panic runtime is guaranteed to be `unwind`, but this is messy due to our architecture. Instead, move it into `unwind::wasm`, which is only compiled for bare-metal targets that default to `panic = "abort"`, rendering the issue moot.
2 parents 606be5c + 30ac459 commit 205aceb

File tree

1 file changed

+0
-32
lines changed
  • crates/core_arch/src/wasm32

1 file changed

+0
-32
lines changed

crates/core_arch/src/wasm32/mod.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -173,35 +173,3 @@ pub fn f64_nearest(a: f64) -> f64 {
173173
pub fn f64_sqrt(a: f64) -> f64 {
174174
crate::intrinsics::sqrtf64(a)
175175
}
176-
177-
unsafe extern "C-unwind" {
178-
#[link_name = "llvm.wasm.throw"]
179-
fn wasm_throw(tag: i32, ptr: *mut u8) -> !;
180-
}
181-
182-
/// Generates the [`throw`] instruction from the [exception-handling proposal] for WASM.
183-
///
184-
/// This function is unlikely to be stabilized until codegen backends have better support.
185-
///
186-
/// [`throw`]: https://webassembly.github.io/exception-handling/core/syntax/instructions.html#syntax-instr-control
187-
/// [exception-handling proposal]: https://github.com/WebAssembly/exception-handling
188-
// FIXME: wasmtime does not currently support exception-handling, so cannot execute
189-
// a wasm module with the throw instruction in it. once it does, we can
190-
// reenable this attribute.
191-
// #[cfg_attr(test, assert_instr(throw, TAG = 0, ptr = core::ptr::null_mut()))]
192-
#[inline]
193-
#[unstable(feature = "wasm_exception_handling_intrinsics", issue = "122465")]
194-
// FIXME: Since this instruction unwinds, `core` built with `-C panic=unwind`
195-
// cannot be linked with `-C panic=abort` programs. But that's not
196-
// entirely supported anyway, because runtimes without EH support won't
197-
// be able to handle `try` blocks in `-C panic=unwind` crates either.
198-
// We ship `-C panic=abort` `core`, so this doesn't affect users
199-
// directly. Resolving this will likely require patching out both `try`
200-
// and `throw` instructions, at which point we can look into whitelisting
201-
// this function in the compiler to allow linking.
202-
// See https://github.com/rust-lang/rust/issues/118168.
203-
#[allow(ffi_unwind_calls)]
204-
pub unsafe fn throw<const TAG: i32>(ptr: *mut u8) -> ! {
205-
static_assert!(TAG == 0); // LLVM only supports tag 0 == C++ right now.
206-
wasm_throw(TAG, ptr)
207-
}

0 commit comments

Comments
 (0)