Skip to content

Commit 7890fa6

Browse files
pepyakinsunfishcode
authored andcommitted
Use __chkstk for aarch64 instead of __rust_probestack. (#800)
* Use __chkstk for aarch64 instead of __rust_probestack. * Demote rustdoc to a regular comment to fix the build.
1 parent d81aa20 commit 7890fa6

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/jit/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ target-lexicon = { version = "0.10.0", default-features = false }
2525
wasmparser = { version = "0.47.0", default-features = false }
2626
more-asserts = "0.2.1"
2727
anyhow = "1.0"
28+
cfg-if = "0.1.9"
2829

2930
[target.'cfg(target_os = "windows")'.dependencies]
3031
winapi = { version = "0.3.7", features = ["winnt", "impl-default"] }

crates/jit/src/link.rs

+30-25
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ pub fn link_module(
4444
FloorF64 => wasmtime_f64_floor as usize,
4545
TruncF64 => wasmtime_f64_trunc as usize,
4646
NearestF64 => wasmtime_f64_nearest as usize,
47-
#[cfg(not(target_os = "windows"))]
48-
Probestack => __rust_probestack as usize,
49-
#[cfg(all(target_os = "windows", target_env = "gnu"))]
50-
Probestack => ___chkstk as usize,
51-
#[cfg(all(
52-
target_os = "windows",
53-
target_env = "msvc",
54-
target_pointer_width = "64"
55-
))]
56-
Probestack => __chkstk as usize,
47+
Probestack => PROBESTACK as usize,
5748
other => panic!("unexpected libcall: {}", other),
5849
}
5950
}
@@ -107,19 +98,33 @@ pub fn link_module(
10798
}
10899
}
109100

110-
/// A declaration for the stack probe function in Rust's standard library, for
111-
/// catching callstack overflow.
112-
extern "C" {
113-
#[cfg(not(target_os = "windows"))]
114-
pub fn __rust_probestack();
115-
#[cfg(all(
116-
target_os = "windows",
117-
target_env = "msvc",
118-
target_pointer_width = "64"
119-
))]
120-
pub fn __chkstk();
121-
// ___chkstk (note the triple underscore) is implemented in compiler-builtins/src/x86_64.rs
122-
// by the Rust compiler for the MinGW target
123-
#[cfg(all(target_os = "windows", target_env = "gnu"))]
124-
pub fn ___chkstk();
101+
// A declaration for the stack probe function in Rust's standard library, for
102+
// catching callstack overflow.
103+
cfg_if::cfg_if! {
104+
if #[cfg(any(
105+
target_arch="aarch64",
106+
all(
107+
target_os = "windows",
108+
target_env = "msvc",
109+
target_pointer_width = "64"
110+
)
111+
))] {
112+
extern "C" {
113+
pub fn __chkstk();
114+
}
115+
const PROBESTACK: unsafe extern "C" fn() = __chkstk;
116+
} else if #[cfg(all(target_os = "windows", target_env = "gnu"))] {
117+
extern "C" {
118+
// ___chkstk (note the triple underscore) is implemented in compiler-builtins/src/x86_64.rs
119+
// by the Rust compiler for the MinGW target
120+
#[cfg(all(target_os = "windows", target_env = "gnu"))]
121+
pub fn ___chkstk();
122+
}
123+
const PROBESTACK: unsafe extern "C" fn() = ___chkstk;
124+
} else {
125+
extern "C" {
126+
pub fn __rust_probestack();
127+
}
128+
static PROBESTACK: unsafe extern "C" fn() = __rust_probestack;
129+
}
125130
}

0 commit comments

Comments
 (0)