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:
Steven Allen
2022-06-30 08:13:43 -07:00
committed by GitHub
parent e179e736b9
commit b4830ef1e7
2 changed files with 32 additions and 1 deletions

View File

@@ -1423,6 +1423,10 @@ impl Config {
{
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

View File

@@ -345,7 +345,6 @@ impl Engine {
// can affect the way the generated code performs or behaves at
// runtime.
"avoid_div_traps" => *value == FlagValue::Bool(true),
"unwind_info" => *value == FlagValue::Bool(true),
"libcall_call_conv" => *value == FlagValue::Enum("isa_default".into()),
// 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
// the module itself, so their configuration values shouldn't
// matter.
@@ -519,8 +528,10 @@ impl Default for Engine {
#[cfg(test)]
mod tests {
use crate::{Config, Engine, Module, OptLevel};
use anyhow::Result;
use tempfile::TempDir;
use wasmtime_environ::FlagValue;
#[test]
fn cache_accounts_for_opt_level() -> Result<()> {
@@ -585,4 +596,20 @@ mod tests {
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"
);
}
}