Add various small improvements, update attributions file

This commit is contained in:
Mark McCaskey 2020-02-18 17:31:12 -08:00
parent 3653a448f5
commit 1ac59a31f6
3 changed files with 77 additions and 25 deletions

View File

@ -1,21 +1,30 @@
# Wasmer Attributions
Wasmer is a community effort.
In order to build the best WebAssembly runtime it's our duty to see how other runtimes are approaching the same space
and get inspired from them on the things that they got right, so Wasmer and its community can benefit from a solid
foundation.
Wasmer is a community effort and makes use of code from various other
projects. Listed below are notable sections of code that are licensed
from other projects and the relevant license of those projects.
These are the different project that we used as inspiration:
These are the projects that were used as inspiration and/or that we are using code from:
- [Nebulet](https://github.com/nebulet/nebulet): as the base for creating a great Rust WebAssembly runtime
- [WAVM](https://github.com/wavm/wavm): for their great integration and testing framework
- [greenwasm](https://github.com/Kimundi/greenwasm): for their [spectests framework](https://github.com/Kimundi/greenwasm/tree/master/greenwasm-spectest)
- [wasmtime](https://github.com/CraneStation/wasmtime): for their [mmap implementation](https://github.com/CraneStation/wasmtime/blob/3f24098edc81cd9bf0f877fb7fba018cad0f039e/lib/runtime/src/mmap.rs)
- [wasmtime](https://github.com/CraneStation/wasmtime):
- For their [mmap implementation](https://github.com/CraneStation/wasmtime/blob/3f24098edc81cd9bf0f877fb7fba018cad0f039e/lib/runtime/src/mmap.rs)
- For the implementation of the `__jit_debug_register_code` function
in Rust, the structure of using Cranelift with the GDB JIT
interface including implementation details regarding the structure
of generating debug information for each function with Cranelift
(for example, the sorting of the extended basic blocks before
processing the instructions), and the API for transforming DWARF
see wasm-debug's attribution file for more information (TODO: link
and update here).
- [stackoverflow](https://stackoverflow.com/a/45795699/1072990): to create an efficient HashMap with pair keys
- [Emscripten](https://github.com/kripken/emscripten): for emtests test sources to ensure compatibility
- [The WebAssembly spec](https://github.com/WebAssembly/spec/tree/master/test): for implementation details of WebAssembly and spectests
We would love to hear from you if you think we can take inspiration from other projects that we haven't covered here.
😊
Please let us know if you believe there is an error or omission in
this list and we will do our best to correct it.
## Licenses

View File

@ -164,10 +164,6 @@ impl FuncResolverBuilder {
})
.collect::<Vec<_>>();
/*let mut unwind = vec![];
ctx.emit_unwind_info(isa, &mut unwind);
dbg!(unwind.len());*/
let stack_slots = ctx
.func
.stack_slots
@ -228,9 +224,34 @@ impl FuncResolverBuilder {
if let Some(ref mut dbg_metadata) = debug_metadata {
let (entry, vlr, stackslots) = debug_info.unwrap();
dbg_metadata.func_info.push(entry);
dbg_metadata
.inst_info
.push(unsafe { std::mem::transmute(vlr) });
let new_vlr = vlr
.into_iter()
.map(|(k, v)| {
(
wasm_debug::types::ValueLabel::from_u32(k.as_u32()),
v.into_iter()
.map(|item| wasm_debug::types::ValueLocRange {
start: item.start,
end: item.end,
loc: match item.loc {
cranelift_codegen::ir::ValueLoc::Unassigned => {
wasm_debug::types::ValueLoc::Unassigned
}
cranelift_codegen::ir::ValueLoc::Reg(ru) => {
wasm_debug::types::ValueLoc::Reg(ru)
}
cranelift_codegen::ir::ValueLoc::Stack(st) => {
wasm_debug::types::ValueLoc::Stack(
wasm_debug::types::StackSlot::from_u32(st.as_u32()),
)
}
},
})
.collect::<Vec<wasm_debug::types::ValueLocRange>>(),
)
})
.collect::<wasm_debug::types::ValueLabelsRangesInner>();
dbg_metadata.inst_info.push(new_vlr);
dbg_metadata.stack_slot_offsets.push(stackslots);
}

View File

@ -1,40 +1,52 @@
#![allow(missing_docs)]
//! Code for interacting with the
//! [GDB JIT inteface](https://sourceware.org/gdb/current/onlinedocs/gdb.html#JIT-Interface).
use std::ptr;
use std::sync::Arc;
// =============================================================================
// LLDB hook magic:
// see lldb/packages/Python/lldbsuite/test/functionalities/jitloader_gdb in
// llvm repo for example
//
// see also https://sourceware.org/gdb/current/onlinedocs/gdb.html#JIT-Interface
/// Entrypoint that the debugger will use to trigger a read from the
/// [`__jit_debug_descriptor`] global variable.
///
/// The debugger will wait for this function to be called and then take
/// control to read the data we prepared.
// implementation of this function is from wasmtime and is licensed under
// the Apache 2.0 license. See ATTRIBUTIONS.md for full license and more
// information.
#[no_mangle]
#[inline(never)]
extern "C" fn __jit_debug_register_code() {
// implementation of this function copied from wasmtime (TODO: link and attribution)
// prevent optimization of this function
// This code exists to prevent optimization of this function so that the
// GDB JIT interface behaves as expected
let x = 3;
unsafe {
std::ptr::read_volatile(&x);
}
}
/// The operation that the debugger should perform with the entry that we gave it.
#[allow(non_camel_case_types)]
#[derive(Debug)]
#[repr(u32)]
pub(crate) enum JITAction {
/// Do nothing.
JIT_NOACTION = 0,
/// Register the given code.
JIT_REGISTER_FN = 1,
/// Unregister the given code.
JIT_UNREGISTER_FN = 2,
}
/// Node of the doubly linked list that the GDB JIT interface reads from.
#[no_mangle]
#[repr(C)]
pub(crate) struct JITCodeEntry {
/// Next entry in the linked list.
next: *mut JITCodeEntry,
/// Previous entry in the linked list.
prev: *mut JITCodeEntry,
/// Pointer to the data we want the debugger to read.
symfile_addr: *mut u8,
/// The amount of data at the `symfile_addr` pointer.
symfile_size: u64,
}
@ -49,15 +61,24 @@ impl Default for JITCodeEntry {
}
}
/// Head node of the doubly linked list that the GDB JIT interface expects.
#[no_mangle]
#[repr(C)]
pub(crate) struct JitDebugDescriptor {
/// The version of the JIT interface to use (presumably, TODO: double check this)
version: u32,
/// Which action to perform, see [`JITAction`].
action_flag: u32,
/// The entry in the list that the `action_flag` applies to.
relevant_entry: *mut JITCodeEntry,
/// The first entry in the doubly linked list.
first_entry: *mut JITCodeEntry,
}
/// Global variable that the GDB JIT interface will read the data from.
/// 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.
#[no_mangle]
#[allow(non_upper_case_globals)]
pub(crate) static mut __jit_debug_descriptor: JitDebugDescriptor = JitDebugDescriptor {
@ -138,6 +159,7 @@ pub struct JITCodeDebugInfoManager {
}
impl JITCodeDebugInfoManager {
/// Register debug info relating to JIT code with the debugger.
pub(crate) fn register_new_jit_code_entry(
&mut self,
bytes: &[u8],