diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index d009d9645c35a..a773cd4f78808 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -150,6 +150,11 @@ pub fn std_cargo(builder: &Builder, cargo.env("MACOSX_DEPLOYMENT_TARGET", target); } + // FIXME: Temporary detection of SJLJ MinGW compilers. + if build.build.build.contains("linux") && target == "i686-pc-windows-gnu" { + features.push_str(" sjlj_eh"); + } + if builder.no_std(target) == Some(true) { // for no-std targets we only compile a few no_std crates cargo.arg("--features").arg("c mem") diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index cd1e3438fc372..6e17c5e57de91 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -58,3 +58,6 @@ wasm_syscall = [] # the environment for hooking up some thread-related information like the # current thread id and accessing/getting the current thread's TCB wasm-bindgen-threads = [] + +# setjmp / longjmp exception handling for i686-pc-windows-gnu +sjlj_eh = ["unwind/sjlj_eh"] diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml index 4760461df64e3..27c7303604de0 100644 --- a/src/libunwind/Cargo.toml +++ b/src/libunwind/Cargo.toml @@ -15,3 +15,6 @@ doc = false core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } compiler_builtins = { path = "../rustc/compiler_builtins_shim" } + +[features] +sjlj_eh = [] diff --git a/src/libunwind/libunwind.rs b/src/libunwind/libunwind.rs index 43c3e1e766623..178ec3a9cd5e6 100644 --- a/src/libunwind/libunwind.rs +++ b/src/libunwind/libunwind.rs @@ -84,7 +84,6 @@ pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reaso exception: *mut _Unwind_Exception); extern "C" { #[unwind(allowed)] - pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; pub fn _Unwind_DeleteException(exception: *mut _Unwind_Exception); pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void; pub fn _Unwind_GetRegionStart(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; @@ -216,26 +215,49 @@ if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm pc } } +} // cfg_if! -if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { - // Not 32-bit iOS +cfg_if! { +if #[cfg(all(target_os = "ios", target_arch = "arm"))] { + // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() extern "C" { #[unwind(allowed)] - pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code; - pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, - trace_argument: *mut c_void) - -> _Unwind_Reason_Code; + pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; + pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; } -} else { - // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() + + #[inline] + pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code { + _Unwind_SjLj_RaiseException(exc) + } + +} else if #[cfg(feature = "sjlj_eh")] { extern "C" { #[unwind(allowed)] + pub fn _Unwind_SjLj_Resume(e: *mut _Unwind_Exception) -> !; pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; + pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, + trace_argument: *mut c_void) + -> _Unwind_Reason_Code; + } + + #[inline] + pub unsafe fn _Unwind_Resume(exc: *mut _Unwind_Exception) -> ! { + _Unwind_SjLj_Resume(exc) } #[inline] pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code { _Unwind_SjLj_RaiseException(exc) } +} else { + extern "C" { + #[unwind(allowed)] + pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !; + pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code; + pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, + trace_argument: *mut c_void) + -> _Unwind_Reason_Code; + } } } // cfg_if!