diff --git a/Cargo.toml b/Cargo.toml index 1bf73378b..8ad43687f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,7 @@ backend-llvm = [ "wasmer-llvm-backend", "wasmer-runtime/llvm", "wasmer-middleware-common-tests/llvm", + "wasmer-runtime-core/generate-debug-information-no-export-symbols", ] backend-singlepass = [ "wasmer-singlepass-backend", diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index ef7db2e80..6a0479458 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -56,3 +56,6 @@ managed = [] deterministic-execution = ["wasmparser/deterministic"] # generate debug information from Wasm DWARF for use with the GDB JIT interface generate-debug-information = ["wasm-debug"] +# don't export symbols related to the GDB JIT interafce, LLVM or some other native +# code will be providing them +generate-debug-information-no-export-symbols = ["generate-debug-information", "wasm-debug"] diff --git a/lib/runtime-core/src/jit_debug.rs b/lib/runtime-core/src/jit_debug.rs index 45a620cae..59a8e3642 100644 --- a/lib/runtime-core/src/jit_debug.rs +++ b/lib/runtime-core/src/jit_debug.rs @@ -15,7 +15,7 @@ use std::sync::{Arc, Mutex}; // Implementation of this function is derived from wasmtime and is licensed under // the Apache 2.0 license. See ATTRIBUTIONS.md for full license and more // information. -#[linkage = "linkonce"] +#[cfg(not(feature = "generate-debug-information-no-export-symbols"))] #[no_mangle] #[inline(never)] extern "C" fn __jit_debug_register_code() { @@ -81,7 +81,7 @@ struct JitDebugDescriptor { /// The data is in the form of a doubly linked list. This global variable acts /// as a head node with extra information about the operation that we want the /// debugger to perform. -#[linkage = "linkonce"] +#[cfg(not(feature = "generate-debug-information-no-export-symbols"))] #[no_mangle] #[allow(non_upper_case_globals)] static mut __jit_debug_descriptor: JitDebugDescriptor = JitDebugDescriptor { @@ -91,6 +91,12 @@ static mut __jit_debug_descriptor: JitDebugDescriptor = JitDebugDescriptor { first_entry: ptr::null_mut(), }; +#[cfg(feature = "generate-debug-information-no-export-symbols")] +extern "C" { + static mut __jit_debug_descriptor: JitDebugDescriptor; + fn __jit_debug_register_code(); +} + lazy_static! { /// Global lock on [`__jit_debug_descriptor`]. Acquire this lock when /// reading or writing to the global variable. This includes calls to @@ -173,12 +179,28 @@ impl Drop for JitCodeDebugInfoEntryHandleInner { } /// Manager of debug info registered with the debugger. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub(crate) struct JitCodeDebugInfoManager { inner: Vec, } +impl Default for JitCodeDebugInfoManager { + fn default() -> Self { + Self::new() + } +} + impl JitCodeDebugInfoManager { + pub(crate) fn new() -> Self { + unsafe { + // ensure we set the version, even if externally linked + __jit_debug_descriptor.version = 1; + } + Self { + inner: vec![], + } + } + /// Register debug info relating to JIT code with the debugger. pub(crate) fn register_new_jit_code_entry( &mut self, diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index 220912ef4..7072f23d9 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -99,7 +99,7 @@ pub fn read_module< generate_debug_info: compiler_config.should_generate_debug_info(), #[cfg(feature = "generate-debug-information")] - debug_info_manager: Default::default(), + debug_info_manager: crate::jit_debug::JitCodeDebugInfoManager::new(), })); let mut parser = wasmparser::ValidatingParser::new(