Skip to content

Commit bad0172

Browse files
authored
Fix a panic enabling profiling (#12186)
* Fix a panic enabling profiling This fixes a regression from #11630 where a panic happened when loading a component with profiling enabled. Closes #12158 * Skip test on Windows
1 parent 4137f4f commit bad0172

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

crates/wasmtime/src/runtime/instantiate.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ impl CompiledModule {
176176
let key = self.index.func_by_text_offset(text_offset)?;
177177
match key {
178178
FuncKey::DefinedWasmFunction(module, def_func_index) => {
179-
debug_assert_eq!(module, self.module_index());
180-
Some(def_func_index)
179+
// If this function is for `self` then pass it through,
180+
// otherwise it's for some other module in this image so
181+
// there's no `DefinedFuncIndex` for this offset.
182+
if module == self.module_index() {
183+
Some(def_func_index)
184+
} else {
185+
None
186+
}
181187
}
182188
_ => None,
183189
}

tests/all/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod native_debug;
4343
mod noextern;
4444
mod piped_tests;
4545
mod pooling_allocator;
46+
mod profiling;
4647
mod pulley;
4748
mod relocs;
4849
mod stack_creator;

tests/all/profiling.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use wasmtime::component::Component;
2+
use wasmtime::{Config, Engine, Module, Result};
3+
4+
#[test]
5+
#[cfg_attr(miri, ignore)]
6+
#[cfg_attr(windows, ignore)] // perfmap not supported on Windows
7+
fn perfmap() -> Result<()> {
8+
let mut config = Config::new();
9+
config.profiler(wasmtime::ProfilingStrategy::PerfMap);
10+
let engine = Engine::new(&config)?;
11+
12+
Module::new(&engine, "(module (func))")?;
13+
Component::new(&engine, "(component)")?;
14+
Component::new(&engine, "(component (core module (func)))")?;
15+
Component::new(
16+
&engine,
17+
"(component
18+
(core module (func))
19+
(core module (func))
20+
)",
21+
)?;
22+
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)