From 724beaf0f30626a2c26d9f7faaf3887285f229f7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 21 Jun 2021 07:25:58 -0700 Subject: [PATCH] Connect helper C symbols to their static library This commit adds a `#[link]` annotation to the block defining symbols coming from a native static library that we build and link. This is required by rustc to get symbols to get exported correctly when linking wasmtime into a Rust dynamic library instead of always as an rlib. While I was at it I went ahead and renamed the symbols now that they're no longer in C++ and they're doing setjmp/longjmp and not much else. Closes #3006 --- crates/runtime/build.rs | 2 +- crates/runtime/src/helpers.c | 4 ++-- crates/runtime/src/traphandlers.rs | 11 ++++++----- crates/runtime/src/traphandlers/macos.rs | 4 ++-- crates/runtime/src/traphandlers/unix.rs | 4 ++-- crates/runtime/src/traphandlers/windows.rs | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/runtime/build.rs b/crates/runtime/build.rs index 5d618e575f49..6f112f25c9b5 100644 --- a/crates/runtime/build.rs +++ b/crates/runtime/build.rs @@ -9,5 +9,5 @@ fn main() { None, ) .file("src/helpers.c") - .compile("helpers"); + .compile("wasmtime-helpers"); } diff --git a/crates/runtime/src/helpers.c b/crates/runtime/src/helpers.c index da3db5824247..860584405735 100644 --- a/crates/runtime/src/helpers.c +++ b/crates/runtime/src/helpers.c @@ -14,7 +14,7 @@ #define platform_jmp_buf sigjmp_buf #endif -int RegisterSetjmp( +int wasmtime_setjmp( void **buf_storage, void (*body)(void*, void*), void *payload, @@ -28,7 +28,7 @@ int RegisterSetjmp( return 1; } -void Unwind(void *JmpBuf) { +void wasmtime_longjmp(void *JmpBuf) { platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf; platform_longjmp(*buf, 1); } diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs index ba9de7c3d407..901b1c64d196 100644 --- a/crates/runtime/src/traphandlers.rs +++ b/crates/runtime/src/traphandlers.rs @@ -14,15 +14,16 @@ use wasmtime_environ::ir; pub use self::tls::{tls_eager_initialize, TlsRestore}; +#[link(name = "wasmtime-helpers")] extern "C" { #[allow(improper_ctypes)] - fn RegisterSetjmp( + fn wasmtime_setjmp( jmp_buf: *mut *const u8, callback: extern "C" fn(*mut u8, *mut VMContext), payload: *mut u8, callee: *mut VMContext, ) -> i32; - fn Unwind(jmp_buf: *const u8) -> !; + fn wasmtime_longjmp(jmp_buf: *const u8) -> !; } cfg_if::cfg_if! { @@ -177,7 +178,7 @@ where F: FnMut(*mut VMContext), { return CallThreadState::new(signal_handler).with(vminterrupts, |cx| { - RegisterSetjmp( + wasmtime_setjmp( cx.jmp_buf.as_ptr(), call_closure::, &mut closure as *mut F as *mut u8, @@ -251,7 +252,7 @@ impl CallThreadState { fn unwind_with(&self, reason: UnwindReason) -> ! { unsafe { (*self.unwind.get()).as_mut_ptr().write(reason); - Unwind(self.jmp_buf.get()); + wasmtime_longjmp(self.jmp_buf.get()); } } @@ -306,7 +307,7 @@ impl CallThreadState { } // If all that passed then this is indeed a wasm trap, so return the - // `jmp_buf` passed to `Unwind` to resume. + // `jmp_buf` passed to `wasmtime_longjmp` to resume. self.jmp_buf.get() } diff --git a/crates/runtime/src/traphandlers/macos.rs b/crates/runtime/src/traphandlers/macos.rs index 4131da731481..133ae8024525 100644 --- a/crates/runtime/src/traphandlers/macos.rs +++ b/crates/runtime/src/traphandlers/macos.rs @@ -33,7 +33,7 @@ #![allow(non_snake_case)] -use crate::traphandlers::{tls, Trap, Unwind}; +use crate::traphandlers::{tls, wasmtime_longjmp, Trap}; use mach::exception_types::*; use mach::kern_return::*; use mach::mach_init::*; @@ -389,7 +389,7 @@ unsafe extern "C" fn unwind(wasm_pc: *const u8) -> ! { state.jmp_buf.get() }); debug_assert!(!jmp_buf.is_null()); - Unwind(jmp_buf); + wasmtime_longjmp(jmp_buf); } thread_local! { diff --git a/crates/runtime/src/traphandlers/unix.rs b/crates/runtime/src/traphandlers/unix.rs index a4a4573e0d02..42bda28d1a2a 100644 --- a/crates/runtime/src/traphandlers/unix.rs +++ b/crates/runtime/src/traphandlers/unix.rs @@ -1,4 +1,4 @@ -use crate::traphandlers::{tls, Trap, Unwind}; +use crate::traphandlers::{tls, wasmtime_longjmp, Trap}; use std::cell::RefCell; use std::convert::TryInto; use std::io; @@ -99,7 +99,7 @@ unsafe extern "C" fn trap_handler( return true; } info.capture_backtrace(pc); - Unwind(jmp_buf) + wasmtime_longjmp(jmp_buf) }); if handled { diff --git a/crates/runtime/src/traphandlers/windows.rs b/crates/runtime/src/traphandlers/windows.rs index db5ad8caba13..a2a45654c55f 100644 --- a/crates/runtime/src/traphandlers/windows.rs +++ b/crates/runtime/src/traphandlers/windows.rs @@ -1,4 +1,4 @@ -use crate::traphandlers::{tls, Trap, Unwind}; +use crate::traphandlers::{tls, wasmtime_longjmp, Trap}; use std::io; use winapi::um::errhandlingapi::*; use winapi::um::minwinbase::*; @@ -69,7 +69,7 @@ unsafe extern "system" fn exception_handler(exception_info: PEXCEPTION_POINTERS) EXCEPTION_CONTINUE_EXECUTION } else { info.capture_backtrace(ip); - Unwind(jmp_buf) + wasmtime_longjmp(jmp_buf) } }) }