diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index b41ae9396f43..6cd656402af8 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -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 diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rs index 9dd637e7143f..c644d742dc2b 100644 --- a/crates/wasmtime/src/engine.rs +++ b/crates/wasmtime/src/engine.rs @@ -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" + ); + } }