Skip to content

Commit 946d7e4

Browse files
author
Kai Luo
committed
Fix actual function pointer for AIX
1 parent e63ef53 commit 946d7e4

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

tests/smoke.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
use backtrace::Frame;
22
use std::thread;
33

4+
fn get_actual_fn_pointer(fp: usize) -> usize {
5+
// On AIX, the function name references a function descriptor.
6+
// A function descriptor is consisted of (See https://reviews.llvm.org/D62532)
7+
// * The address of the entry point of the function.
8+
// * The TOC base address for the function.
9+
// * The environment pointer.
10+
// Deref `fp` directly so that we can get the address of `fp`'s
11+
// entry point in text section.
12+
if cfg!(target_os = "aix") {
13+
unsafe {
14+
let actual_fn_entry = *(fp as *const usize);
15+
actual_fn_entry
16+
}
17+
} else {
18+
fp
19+
}
20+
}
21+
422
#[test]
523
// FIXME: shouldn't ignore this test on i686-msvc, unsure why it's failing
624
#[cfg_attr(all(target_arch = "x86", target_env = "msvc"), ignore)]
@@ -20,7 +38,7 @@ fn smoke_test_frames() {
2038
// Various platforms have various bits of weirdness about their
2139
// backtraces. To find a good starting spot let's search through the
2240
// frames
23-
let target = frame_4 as usize;
41+
let target = get_actual_fn_pointer(frame_4 as usize);
2442
let offset = v
2543
.iter()
2644
.map(|frame| frame.symbol_address() as usize)
@@ -39,39 +57,39 @@ fn smoke_test_frames() {
3957

4058
assert_frame(
4159
frames.next().unwrap(),
42-
frame_4 as usize,
60+
get_actual_fn_pointer(frame_4 as usize),
4361
"frame_4",
4462
"tests/smoke.rs",
4563
start_line + 6,
4664
9,
4765
);
4866
assert_frame(
4967
frames.next().unwrap(),
50-
frame_3 as usize,
68+
get_actual_fn_pointer(frame_3 as usize),
5169
"frame_3",
5270
"tests/smoke.rs",
5371
start_line + 3,
5472
52,
5573
);
5674
assert_frame(
5775
frames.next().unwrap(),
58-
frame_2 as usize,
76+
get_actual_fn_pointer(frame_2 as usize),
5977
"frame_2",
6078
"tests/smoke.rs",
6179
start_line + 2,
6280
52,
6381
);
6482
assert_frame(
6583
frames.next().unwrap(),
66-
frame_1 as usize,
84+
get_actual_fn_pointer(frame_1 as usize),
6785
"frame_1",
6886
"tests/smoke.rs",
6987
start_line + 1,
7088
52,
7189
);
7290
assert_frame(
7391
frames.next().unwrap(),
74-
smoke_test_frames as usize,
92+
get_actual_fn_pointer(smoke_test_frames as usize),
7593
"smoke_test_frames",
7694
"",
7795
0,

0 commit comments

Comments
 (0)