Skip to content

Commit aec8f16

Browse files
authored
_Unwind_FindEnclosingFunction fails on macOS (#439)
As [explained in a rust-lang/rust issue][1], `_Unwind_FindEnclosingFunction` intermittently produces incorrect results on macOS due to the "compact" unwind table emitted by its linker not including entries for every function. [1]: rust-lang/rust#74771 (comment)
1 parent cc89bb6 commit aec8f16

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/backtrace/libunwind.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ impl Frame {
5555
return symbol_address;
5656
}
5757

58-
// It seems that on OSX `_Unwind_FindEnclosingFunction` returns a
59-
// pointer to... something that's unclear. It's definitely not always
60-
// the enclosing function for whatever reason. It's not entirely clear
61-
// to me what's going on here, so pessimize this for now and just always
58+
// The macOS linker emits a "compact" unwind table that only includes an
59+
// entry for a function if that function either has an LSDA or its
60+
// encoding differs from that of the previous entry. Consequently, on
61+
// macOS, `_Unwind_FindEnclosingFunction` is unreliable (it can return a
62+
// pointer to some totally unrelated function). Instead, we just always
6263
// return the ip.
6364
//
64-
// Note the `skip_inner_frames.rs` test is skipped on OSX due to this
65-
// clause, and if this is fixed that test in theory can be run on OSX!
65+
// https://github.com/rust-lang/rust/issues/74771#issuecomment-664056788
66+
//
67+
// Note the `skip_inner_frames.rs` test is skipped on macOS due to this
68+
// clause, and if this is fixed that test in theory can be run on macOS!
6669
if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
6770
self.ip()
6871
} else {

0 commit comments

Comments
 (0)