A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Fix a panic enabling profiling (#12186)
Alex Crichtonbad017279cef
diff --git a/crates/wasmtime/src/runtime/instantiate.rs b/crates/wasmtime/src/runtime/instantiate.rsindex cbb3f4022b..6d0978beaa 100644--- a/crates/wasmtime/src/runtime/instantiate.rs+++ b/crates/wasmtime/src/runtime/instantiate.rs@@ -176,8 +176,14 @@ impl CompiledModule {let key = self.index.func_by_text_offset(text_offset)?;match key {FuncKey::DefinedWasmFunction(module, def_func_index) => {- debug_assert_eq!(module, self.module_index());- Some(def_func_index)+ // If this function is for `self` then pass it through,+ // otherwise it's for some other module in this image so+ // there's no `DefinedFuncIndex` for this offset.+ if module == self.module_index() {+ Some(def_func_index)+ } else {+ None+ }}_ => None,}diff --git a/tests/all/main.rs b/tests/all/main.rsindex e3f3198dc2..7aabc438bd 100644--- a/tests/all/main.rs+++ b/tests/all/main.rs@@ -43,6 +43,7 @@ mod native_debug;mod noextern;mod piped_tests;mod pooling_allocator;+mod profiling;mod pulley;mod relocs;mod stack_creator;diff --git a/tests/all/profiling.rs b/tests/all/profiling.rsnew file mode 100644index 0000000000..902190e616--- /dev/null+++ b/tests/all/profiling.rs@@ -0,0 +1,24 @@+use wasmtime::component::Component;+use wasmtime::{Config, Engine, Module, Result};++#[test]+#[cfg_attr(miri, ignore)]+#[cfg_attr(windows, ignore)] // perfmap not supported on Windows+fn perfmap() -> Result<()> {+ let mut config = Config::new();+ config.profiler(wasmtime::ProfilingStrategy::PerfMap);+ let engine = Engine::new(&config)?;++ Module::new(&engine, "(module (func))")?;+ Component::new(&engine, "(component)")?;+ Component::new(&engine, "(component (core module (func)))")?;+ Component::new(+ &engine,+ "(component+ (core module (func))+ (core module (func))+ )",+ )?;++ Ok(())+}