Skip to content

Commit b85baf3

Browse files
committed
Auto merge of #159010 - bjorn3:refactor_unwind, r=<try>
Simplify the unwind crate try-job: dist-various* try-job:
2 parents b26c8ef + aa31851 commit b85baf3

6 files changed

Lines changed: 42 additions & 176 deletions

File tree

library/panic_unwind/src/gcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6363
_uwe: uw::_Unwind_Exception {
6464
exception_class: RUST_EXCEPTION_CLASS,
6565
exception_cleanup: Some(exception_cleanup),
66-
private: [core::ptr::null(); uw::unwinder_private_data_size],
66+
private: [core::ptr::null(); _],
6767
},
6868
canary: &CANARY,
6969
cause: data,

library/unwind/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ version = "0.0.0"
44
license = "MIT OR Apache-2.0"
55
repository = "https://github.com/rust-lang/rust.git"
66
edition = "2024"
7-
include = [
8-
'/libunwind/*',
9-
]
107

118
[lib]
129
test = false

library/unwind/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ cfg_select! {
3333
target_os = "solid_asp3",
3434
all(target_vendor = "fortanix", target_env = "sgx"),
3535
all(target_os = "wasi", panic = "unwind"),
36+
target_os = "xous",
3637
) => {
3738
mod libunwind;
3839
pub use libunwind::*;
3940
}
40-
target_os = "xous" => {
41-
mod unwinding;
42-
pub use unwinding::*;
43-
}
4441
target_family = "wasm" => {
4542
mod wasm;
4643
pub use wasm::*;

library/unwind/src/libunwind.rs

Lines changed: 39 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
use core::ffi::{c_int, c_void};
44

5+
// Use the unwinding crate as unwinder on Xous
6+
#[cfg(target_os = "xous")]
7+
pub use unwinding::custom_eh_frame_finder::{
8+
EhFrameFinder, FrameInfo, FrameInfoKind, set_custom_eh_frame_finder,
9+
};
10+
511
#[repr(C)]
612
#[derive(Debug, Copy, Clone, PartialEq)]
713
pub enum _Unwind_Reason_Code {
@@ -24,65 +30,28 @@ pub type _Unwind_Ptr = *const u8;
2430
pub type _Unwind_Trace_Fn =
2531
extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c_void) -> _Unwind_Reason_Code;
2632

27-
#[cfg(target_arch = "x86")]
28-
pub const unwinder_private_data_size: usize = 5;
29-
30-
#[cfg(all(target_arch = "x86_64", not(any(target_os = "windows", target_os = "cygwin"))))]
31-
pub const unwinder_private_data_size: usize = 2;
32-
33-
#[cfg(all(target_arch = "x86_64", any(target_os = "windows", target_os = "cygwin")))]
34-
pub const unwinder_private_data_size: usize = 6;
35-
36-
#[cfg(all(target_arch = "arm", not(target_vendor = "apple")))]
37-
pub const unwinder_private_data_size: usize = 20;
38-
39-
#[cfg(all(target_arch = "arm", target_vendor = "apple"))]
40-
pub const unwinder_private_data_size: usize = 5;
41-
42-
#[cfg(all(target_arch = "aarch64", target_pointer_width = "64", not(target_os = "windows")))]
43-
pub const unwinder_private_data_size: usize = 2;
44-
45-
#[cfg(all(target_arch = "aarch64", target_pointer_width = "64", target_os = "windows"))]
46-
pub const unwinder_private_data_size: usize = 6;
47-
48-
#[cfg(all(target_arch = "aarch64", target_pointer_width = "32"))]
49-
pub const unwinder_private_data_size: usize = 5;
50-
51-
#[cfg(target_arch = "m68k")]
52-
pub const unwinder_private_data_size: usize = 2;
53-
54-
#[cfg(any(target_arch = "mips", target_arch = "mips32r6"))]
55-
pub const unwinder_private_data_size: usize = 2;
56-
57-
#[cfg(target_arch = "csky")]
58-
pub const unwinder_private_data_size: usize = 2;
59-
60-
#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
61-
pub const unwinder_private_data_size: usize = 2;
62-
63-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
64-
pub const unwinder_private_data_size: usize = 2;
65-
66-
#[cfg(target_arch = "s390x")]
67-
pub const unwinder_private_data_size: usize = 2;
68-
69-
#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
70-
pub const unwinder_private_data_size: usize = 2;
71-
72-
#[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
73-
pub const unwinder_private_data_size: usize = 2;
74-
75-
#[cfg(all(target_family = "wasm", target_os = "emscripten"))]
76-
pub const unwinder_private_data_size: usize = 20;
77-
78-
#[cfg(all(target_arch = "wasm32", any(target_os = "linux", target_os = "wasi")))]
79-
pub const unwinder_private_data_size: usize = 2;
80-
81-
#[cfg(target_arch = "hexagon")]
82-
pub const unwinder_private_data_size: usize = 5;
83-
84-
#[cfg(any(target_arch = "loongarch32", target_arch = "loongarch64"))]
85-
pub const unwinder_private_data_size: usize = 2;
33+
pub const unwinder_private_data_size: usize = cfg_select! {
34+
target_arch = "x86" => 5,
35+
all(target_arch = "x86_64", not(any(target_os = "windows", target_os = "cygwin"))) => 2,
36+
all(target_arch = "x86_64", any(target_os = "windows", target_os = "cygwin")) => 6,
37+
all(target_arch = "arm", not(target_vendor = "apple")) => 20,
38+
all(target_arch = "arm", target_vendor = "apple") => 5,
39+
all(target_arch = "aarch64", target_pointer_width = "64", not(target_os = "windows")) => 2,
40+
all(target_arch = "aarch64", target_pointer_width = "64", target_os = "windows") => 6,
41+
all(target_arch = "aarch64", target_pointer_width = "32") => 5,
42+
target_arch = "m68k" => 2,
43+
any(target_arch = "mips", target_arch = "mips32r6") => 2,
44+
target_arch = "csky" => 2,
45+
any(target_arch = "mips64", target_arch = "mips64r6") => 2,
46+
any(target_arch = "powerpc", target_arch = "powerpc64") => 2,
47+
target_arch = "s390x" => 2,
48+
any(target_arch = "sparc", target_arch = "sparc64") => 2,
49+
any(target_arch = "riscv64", target_arch = "riscv32") => 2,
50+
all(target_family = "wasm", target_os = "emscripten") => 20,
51+
all(target_arch = "wasm32", any(target_os = "linux", target_os = "wasi")) => 2,
52+
target_arch = "hexagon" => 5,
53+
any(target_arch = "loongarch32", target_arch = "loongarch64") => 2,
54+
};
8655

8756
#[repr(C)]
8857
pub struct _Unwind_Exception {
@@ -91,6 +60,12 @@ pub struct _Unwind_Exception {
9160
pub private: [_Unwind_Word; unwinder_private_data_size],
9261
}
9362

63+
// Check the size of _Unwind_Exception against the source of thruth when using the unwinding crate.
64+
#[cfg(target_os = "xous")]
65+
const _: () = {
66+
assert!(size_of::<unwinding::abi::UnwindException>() == size_of::<_Unwind_Exception>());
67+
};
68+
9469
pub enum _Unwind_Context {}
9570

9671
pub type _Unwind_Exception_Cleanup_Fn =
@@ -105,10 +80,7 @@ pub type _Unwind_Exception_Cleanup_Fn =
10580
// rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols
10681
// and RFC 2841
10782
#[cfg_attr(
108-
all(
109-
feature = "llvm-libunwind",
110-
any(target_os = "fuchsia", target_os = "linux", target_os = "xous")
111-
),
83+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
11284
link(name = "unwind", kind = "static", modifiers = "-bundle")
11385
)]
11486
// Explicitly link the `unwind` library on WASI targets.
@@ -144,7 +116,7 @@ cfg_select! {
144116
pub const _UA_END_OF_STACK: c_int = 16;
145117

146118
#[cfg_attr(
147-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
119+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
148120
link(name = "unwind", kind = "static", modifiers = "-bundle")
149121
)]
150122
unsafe extern "C" {
@@ -203,7 +175,7 @@ cfg_select! {
203175
pub const UNWIND_IP_REG: c_int = 15;
204176

205177
#[cfg_attr(
206-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
178+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
207179
link(name = "unwind", kind = "static", modifiers = "-bundle")
208180
)]
209181
unsafe extern "C" {
@@ -283,14 +255,14 @@ cfg_select! {
283255
}
284256
_ => {
285257
#[cfg_attr(
286-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
258+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
287259
link(name = "unwind", kind = "static", modifiers = "-bundle")
288260
)]
289261
unsafe extern "C-unwind" {
290262
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
291263
}
292264
#[cfg_attr(
293-
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
265+
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
294266
link(name = "unwind", kind = "static", modifiers = "-bundle")
295267
)]
296268
unsafe extern "C" {

library/unwind/src/unwinding.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/tools/miri/tests/pass/panic/unwind_dwarf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn panic(data: Box<dyn Any + Send>) -> u32 {
2727
_uwe: uw::_Unwind_Exception {
2828
exception_class: miri_exception_class(),
2929
exception_cleanup: Some(exception_cleanup),
30-
private: [core::ptr::null(); uw::unwinder_private_data_size],
30+
private: [core::ptr::null(); _],
3131
},
3232
cause: data,
3333
});

0 commit comments

Comments
 (0)