Skip to content

Commit c8676fc

Browse files
committed
fix dlopen registered module
1 parent 76fbab1 commit c8676fc

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/lind-boot/src/lind_wasmtime/execute.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,17 @@ fn load_library_module(
885885
}
886886
};
887887

888-
// Skip libraries that are already instantiated (checked by inode).
888+
// Skip libraries already instantiated via dlopen (tracked by inode).
889889
if main_module.check_library_loaded(dep_inode).is_some() {
890890
continue;
891891
}
892+
// Also skip libraries instantiated at boot time via --preload
893+
// (tracked by wasm name in named_module_instances, not in the SymbolTable).
894+
if let Some(wasm_name) = dep_module.name() {
895+
if main_module.is_named_instance_registered(wasm_name) {
896+
continue;
897+
}
898+
}
892899

893900
let ret = link_library_into(
894901
&mut main_module,

src/wasmtime/crates/wasmtime/src/runtime/func.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,13 @@ impl<T> Caller<'_, T> {
21172117
self.store.check_library_loaded(inode)
21182118
}
21192119

2120+
/// Return true if a WASM module with the given intrinsic name is already instantiated.
2121+
/// Covers both preloaded libraries (module_with_preload) and dlopen'd libraries
2122+
/// (module_with_caller), since both call register_named_instance.
2123+
pub fn is_named_instance_registered(&self, name: &str) -> bool {
2124+
self.store.is_named_instance_registered(name)
2125+
}
2126+
21202127
pub fn get_asyncify_start_unwind(&mut self) -> Result<TypedFunc<i32, ()>, ()> {
21212128
if let Some(asyncify_start_unwind_extern) = self.get_export("asyncify_start_unwind") {
21222129
match asyncify_start_unwind_extern {

src/wasmtime/crates/wasmtime/src/runtime/store.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,12 @@ impl<'a, T> StoreContextMut<'a, T> {
17621762
self.0.named_module_instances.push((name, id));
17631763
}
17641764

1765+
// Return true if a WASM module with the given intrinsic name has already been
1766+
// instantiated and registered (covers both preloaded and dlopen'd libraries).
1767+
pub fn is_named_instance_registered(&self, name: &str) -> bool {
1768+
self.0.named_module_instances.iter().any(|(n, _)| n == name)
1769+
}
1770+
17651771
// get and set library symbol table, used for cloning symbol table across fork/thread
17661772
#[allow(missing_docs)]
17671773
pub fn get_library_symbol_table(&self) -> &SymbolTable {

0 commit comments

Comments
 (0)