Implement inline stack probes for AArch64 (#5353)
* Turn off probestack by default in Cranelift The probestack feature is not implemented for the aarch64 and s390x backends and currently the on-by-default status requires the aarch64 and s390x implementations to be a stub. Turning off probestack by default allows the s390x and aarch64 backends to panic with an error message to avoid providing a false sense of security. When the probestack option is implemented for all backends, however, it may be reasonable to re-enable. * aarch64: Improve codegen for AMode fallback Currently the final fallback for finalizing an `AMode` will generate both a constant-loading instruction as well as an `add` instruction to the base register into the same temporary. This commit improves the codegen by removing the `add` instruction and folding the final add into the finalized `AMode`. This changes the `extendop` used but both registers are 64-bit so shouldn't be affected by the extending operation. * aarch64: Implement inline stack probes This commit implements inline stack probes for the aarch64 backend in Cranelift. The support here is modeled after the x64 support where unrolled probes are used up to a particular threshold after which a loop is generated. The instructions here are similar in spirit to x64 except that unlike x64 the stack pointer isn't modified during the unrolled loop to avoid needing to re-adjust it back up at the end of the loop. * Enable inline probestack for AArch64 and Riscv64 This commit enables inline probestacks for the AArch64 and Riscv64 architectures in the same manner that x86_64 has it enabled now. Some more testing was additionally added since on Unix platforms we should be guaranteed that Rust's stack overflow message is now printed too. * Enable probestack for aarch64 in cranelift-fuzzgen * Address review comments * Remove implicit stack overflow traps from x64 backend This commit removes implicit `StackOverflow` traps inserted by the x64 backend for stack-based operations. This was historically required when stack overflow was detected with page faults but Wasmtime no longer requires that since it's not suitable for wasm modules which call host functions. Additionally no other backend implements this form of implicit trap-code additions so this is intended to synchronize the behavior of all the backends. This fixes a test added prior for aarch64 to properly abort the process instead of accidentally being caught by Wasmtime. * Fix a style issue
This commit is contained in:
@@ -7,6 +7,7 @@ use std::fmt;
|
||||
#[cfg(feature = "cache")]
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use target_lexicon::Architecture;
|
||||
use wasmparser::WasmFeatures;
|
||||
#[cfg(feature = "cache")]
|
||||
use wasmtime_cache::CacheConfig;
|
||||
@@ -1470,8 +1471,6 @@ impl Config {
|
||||
|
||||
#[cfg(compiler)]
|
||||
pub(crate) fn build_compiler(&mut self) -> Result<Box<dyn wasmtime_environ::Compiler>> {
|
||||
use target_lexicon::Architecture;
|
||||
|
||||
let mut compiler = match self.compiler_config.strategy {
|
||||
Strategy::Auto | Strategy::Cranelift => wasmtime_cranelift::builder(),
|
||||
};
|
||||
@@ -1480,35 +1479,30 @@ impl Config {
|
||||
compiler.target(target.clone())?;
|
||||
}
|
||||
|
||||
// On x86-64 targets, we enable stack probing by default.
|
||||
// If probestack is enabled for a target, Wasmtime will always use the
|
||||
// inline strategy which doesn't require us to define a `__probestack`
|
||||
// function or similar.
|
||||
self.compiler_config
|
||||
.settings
|
||||
.insert("probestack_strategy".into(), "inline".into());
|
||||
|
||||
let host = target_lexicon::Triple::host();
|
||||
let target = self.compiler_config.target.as_ref().unwrap_or(&host);
|
||||
|
||||
// On supported targets, we enable stack probing by default.
|
||||
// This is required on Windows because of the way Windows
|
||||
// commits its stacks, but it's also a good idea on other
|
||||
// platforms to ensure guard pages are hit for large frame
|
||||
// sizes.
|
||||
if self
|
||||
.compiler_config
|
||||
.target
|
||||
.as_ref()
|
||||
.map(|t| t.architecture == Architecture::X86_64)
|
||||
.unwrap_or(cfg!(target_arch = "x86_64"))
|
||||
{
|
||||
if probestack_supported(target.architecture) {
|
||||
self.compiler_config
|
||||
.flags
|
||||
.insert("enable_probestack".into());
|
||||
self.compiler_config
|
||||
.settings
|
||||
.insert("probestack_strategy".into(), "inline".into());
|
||||
}
|
||||
|
||||
if self.native_unwind_info ||
|
||||
// Windows always needs unwind info, since it is part of the ABI.
|
||||
self
|
||||
.compiler_config
|
||||
.target
|
||||
.as_ref()
|
||||
.map_or(cfg!(target_os = "windows"), |target| {
|
||||
target.operating_system == target_lexicon::OperatingSystem::Windows
|
||||
})
|
||||
// Windows always needs unwind info, since it is part of the ABI.
|
||||
target.operating_system == target_lexicon::OperatingSystem::Windows
|
||||
{
|
||||
if !self
|
||||
.compiler_config
|
||||
@@ -1905,3 +1899,10 @@ impl PoolingAllocationConfig {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn probestack_supported(arch: Architecture) -> bool {
|
||||
matches!(
|
||||
arch,
|
||||
Architecture::X86_64 | Architecture::Aarch64(_) | Architecture::Riscv64(_)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -359,8 +359,6 @@ impl Engine {
|
||||
flag: &str,
|
||||
value: &FlagValue,
|
||||
) -> Result<(), String> {
|
||||
use target_lexicon::Architecture;
|
||||
|
||||
let target = self.target();
|
||||
let ok = match flag {
|
||||
// These settings must all have be enabled, since their value
|
||||
@@ -369,11 +367,8 @@ impl Engine {
|
||||
"avoid_div_traps" => *value == FlagValue::Bool(true),
|
||||
"libcall_call_conv" => *value == FlagValue::Enum("isa_default".into()),
|
||||
"preserve_frame_pointers" => *value == FlagValue::Bool(true),
|
||||
|
||||
// On x86-64 targets, stack probing is enabled by default.
|
||||
"enable_probestack" => *value == FlagValue::Bool(target.architecture == Architecture::X86_64),
|
||||
// On x86-64 targets, the default stack probing strategy is inline.
|
||||
"probestack_strategy" => *value == FlagValue::Enum(if target.architecture == Architecture::X86_64 { "inline" } else { "outline" }.into()),
|
||||
"enable_probestack" => *value == FlagValue::Bool(crate::config::probestack_supported(target.architecture)),
|
||||
"probestack_strategy" => *value == FlagValue::Enum("inline".into()),
|
||||
|
||||
// Features wasmtime doesn't use should all be disabled, since
|
||||
// otherwise if they are enabled it could change the behavior of
|
||||
|
||||
Reference in New Issue
Block a user