From 279c35f13fc261c10700f6e4bf1fd0ed266bd54c Mon Sep 17 00:00:00 2001 From: superriva Date: Fri, 12 Jul 2019 15:47:26 +0300 Subject: [PATCH 1/5] fix libunwind fix compilation panic=abort for target i686-pc-windows-gnu on linux Update libunwind.rs Update libunwind.rs Update libunwind.rs --- src/libunwind/libunwind.rs | 48 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/libunwind/libunwind.rs b/src/libunwind/libunwind.rs index 30897970fa220..27f337ba72e74 100644 --- a/src/libunwind/libunwind.rs +++ b/src/libunwind/libunwind.rs @@ -72,7 +72,6 @@ pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reaso link(name = "unwind", kind = "static"))] 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; @@ -212,32 +211,55 @@ if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm } } // cfg_if! -cfg_if::cfg_if! { -if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { - // Not 32-bit iOS +pub mod dwarf2 { + use crate::{_Unwind_Exception, _Unwind_Reason_Code, _Unwind_Trace_Fn}; + use libc::c_void; #[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), link(name = "unwind", kind = "static"))] 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; + pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, trace_argument: *mut c_void) + -> _Unwind_Reason_Code; } -} else { - // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() +} + +pub mod sjlj { + use crate::{_Unwind_Exception, _Unwind_Reason_Code}; #[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), link(name = "unwind", kind = "static"))] extern "C" { #[unwind(allowed)] - pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; + pub fn _Unwind_Sjlj_Resume(exception: *mut _Unwind_Exception) -> !; + pub fn _Unwind_Sjlj_RaiseException(exception: *mut _Unwind_Exception) + -> _Unwind_Reason_Code; + } + #[inline] + pub unsafe fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> ! { + _Unwind_Sjlj_Resume(exception) } - #[inline] - pub unsafe fn _Unwind_RaiseException(exc: *mut _Unwind_Exception) -> _Unwind_Reason_Code { - _Unwind_SjLj_RaiseException(exc) + pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code { + _Unwind_Sjlj_RaiseException(exception) } } + +cfg_if::cfg_if! { + // 32-bit iOS + if #[cfg(all(target_os = "ios", target_arch = "arm"))] { + pub use sjlj::*; + } + // FIXME: for compatibility with i686-w64-mingw32-gcc on linux + else if #[cfg(all(target_vendor = "pc", + target_os = "windows", + target_arch = "x86", + target_env = "gnu"))] { + pub use sjlj::*; + } + else { + pub use dwarf2::*; + } } // cfg_if! From d3f24f7059c5058f0fc85092cfda7c5ce1fa6858 Mon Sep 17 00:00:00 2001 From: superriva Date: Sun, 14 Jul 2019 18:12:22 +0300 Subject: [PATCH 2/5] Update libunwind.rs --- src/libunwind/libunwind.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libunwind/libunwind.rs b/src/libunwind/libunwind.rs index 27f337ba72e74..00f9115107359 100644 --- a/src/libunwind/libunwind.rs +++ b/src/libunwind/libunwind.rs @@ -252,8 +252,8 @@ cfg_if::cfg_if! { if #[cfg(all(target_os = "ios", target_arch = "arm"))] { pub use sjlj::*; } - // FIXME: for compatibility with i686-w64-mingw32-gcc on linux - else if #[cfg(all(target_vendor = "pc", + // FIXME: i686-unknown-windows-gnu target with sjlj + else if #[cfg(all(target_vendor = "unknown", target_os = "windows", target_arch = "x86", target_env = "gnu"))] { From b7bb5f5c92a1a8df0d631969f0c40437110e9223 Mon Sep 17 00:00:00 2001 From: superriva Date: Sun, 14 Jul 2019 18:16:45 +0300 Subject: [PATCH 3/5] Create i686_unknown_windows_gnu --- .../spec/i686_unknown_windows_gnu | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/librustc_target/spec/i686_unknown_windows_gnu diff --git a/src/librustc_target/spec/i686_unknown_windows_gnu b/src/librustc_target/spec/i686_unknown_windows_gnu new file mode 100644 index 0000000000000..dfe12626af21b --- /dev/null +++ b/src/librustc_target/spec/i686_unknown_windows_gnu @@ -0,0 +1,27 @@ +use crate::spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::windows_base::opts(); + base.cpu = "pentium4".to_string(); + base.max_atomic_width = Some(64); + base.eliminate_frame_pointer = false; // Required for backtraces + + // Mark all dynamic libraries and executables as compatible with the larger 4GiB address + // space available to x86 Windows binaries on x86_64. + base.pre_link_args + .get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--large-address-aware".to_string()); + + Ok(Target { + llvm_target: "i686-unknown-windows-gnu".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(), + arch: "x86".to_string(), + target_os: "windows".to_string(), + target_env: "gnu".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +} From fa6d77dbf83d89f97aef44d42c83672356f704ca Mon Sep 17 00:00:00 2001 From: superriva Date: Sun, 14 Jul 2019 18:18:33 +0300 Subject: [PATCH 4/5] Update mod.rs --- src/librustc_target/spec/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 3054ffabb4f1f..3f763cc70eb70 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -433,6 +433,7 @@ supported_targets! { ("x86_64-pc-windows-gnu", x86_64_pc_windows_gnu), ("i686-pc-windows-gnu", i686_pc_windows_gnu), + ("i686-unknown-windows-gnu", i686_unknown_windows_gnu), ("aarch64-pc-windows-msvc", aarch64_pc_windows_msvc), ("x86_64-pc-windows-msvc", x86_64_pc_windows_msvc), From 95cc7ef9d45d6186683883782f6a602a66a3cbf1 Mon Sep 17 00:00:00 2001 From: superriva Date: Sun, 14 Jul 2019 18:30:57 +0300 Subject: [PATCH 5/5] Rename i686_unknown_windows_gnu to i686_unknown_windows_gnu.rs --- .../{i686_unknown_windows_gnu => i686_unknown_windows_gnu.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/librustc_target/spec/{i686_unknown_windows_gnu => i686_unknown_windows_gnu.rs} (100%) diff --git a/src/librustc_target/spec/i686_unknown_windows_gnu b/src/librustc_target/spec/i686_unknown_windows_gnu.rs similarity index 100% rename from src/librustc_target/spec/i686_unknown_windows_gnu rename to src/librustc_target/spec/i686_unknown_windows_gnu.rs