Skip to content

Commit

Permalink
Rollup merge of rust-lang#130077 - madsmtm:watchos-arm-unwind, r=work…
Browse files Browse the repository at this point in the history
…ingjubilee

Fix linking error when compiling for 32-bit watchOS

In rust-lang#124494 (or rust-lang#124748), I mistakenly conflated "not SjLj" to mean "ARM EHABI", which isn't true, 32-bit watchOS uses a third unwinding method called "DWARF CFI".

So this PR is effectively a revert of rust-lang#124494, with a few more comments explaining what's going on.

Fixes rust-lang#130071.

r? Mark-Simulacrum (since you reviewed the original)
  • Loading branch information
workingjubilee authored Sep 11, 2024
2 parents a498fdc + f98ca32 commit 2994fde
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions library/std/src/sys/personality/dwarf/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub enum EHAction {
Terminate,
}

/// 32-bit Apple ARM uses SjLj exceptions, except for watchOS.
/// 32-bit ARM Darwin platforms uses SjLj exceptions.
///
/// I.e. iOS and tvOS, as those are the only Apple OSes that used 32-bit ARM
/// devices.
/// The exception is watchOS armv7k (specifically that subarchitecture), which
/// instead uses DWARF Call Frame Information (CFI) unwinding.
///
/// <https://github.com/llvm/llvm-project/blob/llvmorg-18.1.4/clang/lib/Driver/ToolChains/Darwin.cpp#L3107-L3119>
pub const USING_SJLJ_EXCEPTIONS: bool =
Expand Down
13 changes: 7 additions & 6 deletions library/std/src/sys/personality/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ const UNWIND_DATA_REG: (i32, i32) = (4, 5); // a0, a1

cfg_if::cfg_if! {
if #[cfg(all(
target_arch = "arm",
not(all(target_vendor = "apple", not(target_os = "watchos"))),
not(target_os = "netbsd"),
))] {
target_arch = "arm",
not(target_vendor = "apple"),
not(target_os = "netbsd"),
))] {
/// personality fn called by [ARM EHABI][armeabi-eh]
///
/// Apple 32-bit ARM (but not watchOS) uses the default routine instead
/// since it uses "setjmp-longjmp" unwinding.
/// 32-bit ARM on iOS/tvOS/watchOS does not use ARM EHABI, it uses
/// either "setjmp-longjmp" unwinding or DWARF CFI unwinding, which is
/// handled by the default routine.
///
/// [armeabi-eh]: https://web.archive.org/web/20190728160938/https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
#[lang = "eh_personality"]
Expand Down
13 changes: 8 additions & 5 deletions library/unwind/src/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub const unwinder_private_data_size: usize = 2;
#[cfg(all(target_arch = "x86_64", target_os = "windows"))]
pub const unwinder_private_data_size: usize = 6;

#[cfg(all(target_arch = "arm", not(all(target_vendor = "apple", not(target_os = "watchos")))))]
#[cfg(all(target_arch = "arm", not(target_vendor = "apple")))]
pub const unwinder_private_data_size: usize = 20;

#[cfg(all(target_arch = "arm", all(target_vendor = "apple", not(target_os = "watchos"))))]
#[cfg(all(target_arch = "arm", target_vendor = "apple"))]
pub const unwinder_private_data_size: usize = 5;

#[cfg(all(target_arch = "aarch64", target_pointer_width = "64", not(target_os = "windows")))]
Expand Down Expand Up @@ -123,8 +123,11 @@ extern "C" {
}

cfg_if::cfg_if! {
if #[cfg(any(all(target_vendor = "apple", not(target_os = "watchos")), target_os = "netbsd", not(target_arch = "arm")))] {
if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "arm")))] {
// Not ARM EHABI
//
// 32-bit ARM on iOS/tvOS/watchOS use either DWARF/Compact unwinding or
// "setjmp-longjmp" / SjLj unwinding.
#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum _Unwind_Action {
Expand Down Expand Up @@ -259,8 +262,8 @@ if #[cfg(any(all(target_vendor = "apple", not(target_os = "watchos")), target_os

cfg_if::cfg_if! {
if #[cfg(all(target_vendor = "apple", not(target_os = "watchos"), target_arch = "arm"))] {
// 32-bit ARM Apple (except for watchOS) uses SjLj and does not provide
// _Unwind_Backtrace()
// 32-bit ARM Apple (except for watchOS armv7k specifically) uses SjLj and
// does not provide _Unwind_Backtrace()
extern "C-unwind" {
pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
}
Expand Down

0 comments on commit 2994fde

Please sign in to comment.