Skip to content

Commit

Permalink
Fix linkage issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jan 6, 2025
1 parent 5456d4e commit 6fb8253
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ impl Engine {
// handlers, etc.
#[cfg(all(feature = "signals-based-traps", not(miri)))]
crate::runtime::vm::init_traps(config.macos_use_mach_ports);
#[cfg(feature = "debug-builtins")]
crate::runtime::vm::debug_builtins::init();
}

#[cfg(any(feature = "cranelift", feature = "winch"))]
Expand Down
15 changes: 15 additions & 0 deletions crates/wasmtime/src/runtime/vm/debug_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ pub unsafe extern "C" fn set_vmctx_memory(vmctx_ptr: *mut VMContext) {
// TODO multi-memory
VMCTX_AND_MEMORY = (vmctx_ptr, 0);
}

/// A bit of a hack around various linkage things. The goal here is to force the
/// `wasmtime_*` symbols defined in `helpers.c` to actually get exported. That
/// means they need to be referenced for the linker to include them which is
/// what this function does with trickery in C.
pub fn init() {
extern "C" {
#[wasmtime_versioned_export_macros::versioned_link]
fn wasmtime_debug_builtins_init();
}

unsafe {
wasmtime_debug_builtins_init();
}
}
11 changes: 11 additions & 0 deletions crates/wasmtime/src/runtime/vm/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ void VERSIONED_SYMBOL(set_vmctx_memory)(void *);
DEBUG_BUILTIN_EXPORT void VERSIONED_SYMBOL(wasmtime_set_vmctx_memory)(void *p) {
VERSIONED_SYMBOL(set_vmctx_memory)(p);
}

// Helper symbol called from Rust to force the above two functions to not get
// stripped by the linker.
void VERSIONED_SYMBOL(wasmtime_debug_builtins_init)() {
#ifndef CFG_TARGET_OS_windows
void *volatile p;
p = (void *)&VERSIONED_SYMBOL(wasmtime_resolve_vmctx_memory_ptr);
p = (void *)&VERSIONED_SYMBOL(wasmtime_set_vmctx_memory);
(void)p;
#endif
}
#endif // FEATURE_DEBUG_BUILTINS

// For more information about this see `unix/unwind.rs` and the
Expand Down

0 comments on commit 6fb8253

Please sign in to comment.