Skip to content

[WIP] fix libunwind #62622

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/librustc_target/spec/i686_unknown_windows_gnu.rs
Original file line number Diff line number Diff line change
@@ -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,
})
}
1 change: 1 addition & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
48 changes: 35 additions & 13 deletions src/libunwind/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: i686-unknown-windows-gnu target with sjlj
else if #[cfg(all(target_vendor = "unknown",
target_os = "windows",
target_arch = "x86",
target_env = "gnu"))] {
pub use sjlj::*;
}
else {
pub use dwarf2::*;
}
} // cfg_if!