Skip to content

Commit 8e5ca4b

Browse files
committed
std: Fix backtraces on arm linux
On android, libgcc is missing the _Unwind_GetIP symbol because it's defined as a macro. This is the same case for arm linux, so this commit adds the necessary cfgs in place to use the "expanded macro" in rust for arm linux.
1 parent 770b6e2 commit 8e5ca4b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/libstd/rt/libunwind.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,26 @@ extern "C" {
9898
pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
9999
trace_argument: *libc::c_void)
100100
-> _Unwind_Reason_Code;
101-
#[cfg(not(target_os = "android"))]
101+
#[cfg(stage0, not(target_os = "android"))]
102102
pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t;
103-
#[cfg(not(target_os = "android"))]
103+
#[cfg(stage0, not(target_os = "android"))]
104+
pub fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void;
105+
106+
#[cfg(not(stage0),
107+
not(target_os = "android"),
108+
not(target_os = "linux", target_arch = "arm"))]
109+
pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t;
110+
#[cfg(not(stage0),
111+
not(target_os = "android"),
112+
not(target_os = "linux", target_arch = "arm"))]
104113
pub fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void;
105114
}
106115

107116
// On android, the function _Unwind_GetIP is a macro, and this is the expansion
108117
// of the macro. This is all copy/pasted directly from the header file with the
109118
// definition of _Unwind_GetIP.
110119
#[cfg(target_os = "android")]
120+
#[cfg(target_os = "linux", target_os = "arm")]
111121
pub unsafe fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t {
112122
#[repr(C)]
113123
enum _Unwind_VRS_Result {
@@ -151,6 +161,7 @@ pub unsafe fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t {
151161

152162
// This function also doesn't exist on android, so make it a no-op
153163
#[cfg(target_os = "android")]
164+
#[cfg(target_os = "linux", target_os = "arm")]
154165
pub unsafe fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) -> *libc::c_void{
155166
pc
156167
}

0 commit comments

Comments
 (0)