Wasmtime: disable unwind_info unless needed (#4351)
* Wasmtime: disable unwind_info unless needed fixes #4350 Otherwise wasm modules will be built with unwind info, even if backtraces are disabled. This can get expensive in deeply recursive modules. * Wasmtime: test that disabling backtraces disables unwind_info * fix: make sure we have unwind_info when the engine needs it
This commit is contained in:
@@ -1423,6 +1423,10 @@ impl Config {
|
|||||||
{
|
{
|
||||||
bail!("compiler option 'unwind_info' must be enabled when either 'backtraces' or 'reference types' are enabled");
|
bail!("compiler option 'unwind_info' must be enabled when either 'backtraces' or 'reference types' are enabled");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.compiler_config
|
||||||
|
.settings
|
||||||
|
.insert("unwind_info".to_string(), "false".to_string());
|
||||||
}
|
}
|
||||||
if self.features.reference_types {
|
if self.features.reference_types {
|
||||||
if !self
|
if !self
|
||||||
|
|||||||
@@ -345,7 +345,6 @@ impl Engine {
|
|||||||
// can affect the way the generated code performs or behaves at
|
// can affect the way the generated code performs or behaves at
|
||||||
// runtime.
|
// runtime.
|
||||||
"avoid_div_traps" => *value == FlagValue::Bool(true),
|
"avoid_div_traps" => *value == FlagValue::Bool(true),
|
||||||
"unwind_info" => *value == FlagValue::Bool(true),
|
|
||||||
"libcall_call_conv" => *value == FlagValue::Enum("isa_default".into()),
|
"libcall_call_conv" => *value == FlagValue::Enum("isa_default".into()),
|
||||||
|
|
||||||
// Features wasmtime doesn't use should all be disabled, since
|
// Features wasmtime doesn't use should all be disabled, since
|
||||||
@@ -369,6 +368,16 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If reference types or backtraces are enabled, we need unwind info. Otherwise, we
|
||||||
|
// don't care.
|
||||||
|
"unwind_info" => {
|
||||||
|
if self.config().wasm_backtrace || self.config().features.reference_types {
|
||||||
|
*value == FlagValue::Bool(true)
|
||||||
|
} else {
|
||||||
|
return Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// These settings don't affect the interface or functionality of
|
// These settings don't affect the interface or functionality of
|
||||||
// the module itself, so their configuration values shouldn't
|
// the module itself, so their configuration values shouldn't
|
||||||
// matter.
|
// matter.
|
||||||
@@ -519,8 +528,10 @@ impl Default for Engine {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{Config, Engine, Module, OptLevel};
|
use crate::{Config, Engine, Module, OptLevel};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
use wasmtime_environ::FlagValue;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cache_accounts_for_opt_level() -> Result<()> {
|
fn cache_accounts_for_opt_level() -> Result<()> {
|
||||||
@@ -585,4 +596,20 @@ mod tests {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(compiler)]
|
||||||
|
fn test_disable_backtraces() {
|
||||||
|
let engine = Engine::new(
|
||||||
|
Config::new()
|
||||||
|
.wasm_backtrace(false)
|
||||||
|
.wasm_reference_types(false),
|
||||||
|
)
|
||||||
|
.expect("failed to construct engine");
|
||||||
|
assert_eq!(
|
||||||
|
engine.compiler().flags().get("unwind_info"),
|
||||||
|
Some(&FlagValue::Bool(false)),
|
||||||
|
"unwind info should be disabled unless needed"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user