Skip to content

Commit

Permalink
Rollup merge of #127214 - bjorn3:miri_native_unwind, r=oli-obk
Browse files Browse the repository at this point in the history
Use the native unwind function in miri where possible

Continuation of rust-lang/miri#3319

cc `@RalfJung`
  • Loading branch information
GuillaumeGomez authored Jul 5, 2024
2 parents e66f4d3 + e03c3b6 commit 7a208c7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
34 changes: 13 additions & 21 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ use core::panic::PanicPayload;
cfg_if::cfg_if! {
if #[cfg(target_os = "emscripten")] {
#[path = "emcc.rs"]
mod real_imp;
mod imp;
} else if #[cfg(target_os = "hermit")] {
#[path = "hermit.rs"]
mod real_imp;
mod imp;
} else if #[cfg(target_os = "l4re")] {
// L4Re is unix family but does not yet support unwinding.
#[path = "dummy.rs"]
mod real_imp;
} else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] {
// LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc)
#[path = "seh.rs"]
mod real_imp;
mod imp;
} else if #[cfg(any(
all(target_family = "windows", target_env = "gnu"),
target_os = "psp",
Expand All @@ -58,7 +54,16 @@ cfg_if::cfg_if! {
target_family = "wasm",
))] {
#[path = "gcc.rs"]
mod real_imp;
mod imp;
} else if #[cfg(miri)] {
// Use the Miri runtime on Windows as miri doesn't support funclet based unwinding,
// only landingpad based unwinding. Also use the Miri runtime on unsupported platforms.
#[path = "miri.rs"]
mod imp;
} else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] {
// LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc)
#[path = "seh.rs"]
mod imp;
} else {
// Targets that don't support unwinding.
// - os=none ("bare metal" targets)
Expand All @@ -67,20 +72,7 @@ cfg_if::cfg_if! {
// - nvptx64-nvidia-cuda
// - arch=avr
#[path = "dummy.rs"]
mod real_imp;
}
}

cfg_if::cfg_if! {
if #[cfg(miri)] {
// Use the Miri runtime.
// We still need to also load the normal runtime above, as rustc expects certain lang
// items from there to be defined.
#[path = "miri.rs"]
mod imp;
} else {
// Use the real runtime.
use real_imp as imp;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/tools/miri/src/shims/windows/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_null(dest)?;
}

"_Unwind_RaiseException" => {
// This is not formally part of POSIX, but it is very wide-spread on POSIX systems.
// It was originally specified as part of the Itanium C++ ABI:
// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-throw.
// MinGW implements _Unwind_RaiseException on top of SEH exceptions.
if this.tcx.sess.target.env != "gnu" {
throw_unsup_format!(
"`_Unwind_RaiseException` is not supported on non-MinGW Windows",
);
}
// This function looks and behaves excatly like miri_start_unwind.
let [payload] = this.check_shim(abi, Abi::C { unwind: true }, link_name, args)?;
this.handle_miri_start_unwind(payload)?;
return Ok(EmulateItemResult::NeedsUnwind);
}

_ => return Ok(EmulateItemResult::NotSupported),
}

Expand Down

0 comments on commit 7a208c7

Please sign in to comment.