mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Moved Unwind info a bit to make refactor easier
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
//! Support for compiling with Cranelift.
|
//! Support for compiling with Cranelift.
|
||||||
|
|
||||||
use crate::translator::{
|
use crate::translator::{
|
||||||
compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind,
|
irlibcall_to_libcall, irreloc_to_relocationkind, signature_to_cranelift_ir,
|
||||||
signature_to_cranelift_ir, transform_jump_table, FuncTranslator,
|
transform_jump_table, FuncTranslator,
|
||||||
};
|
};
|
||||||
use cranelift_codegen::binemit;
|
use cranelift_codegen::binemit;
|
||||||
use cranelift_codegen::ir::{self, ExternalName};
|
use cranelift_codegen::ir::{self, ExternalName};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use wasmer_compiler::{CompiledFunctionUnwindInfo, FDERelocEntry};
|
|||||||
pub fn compiled_function_unwind_info(
|
pub fn compiled_function_unwind_info(
|
||||||
isa: &dyn isa::TargetIsa,
|
isa: &dyn isa::TargetIsa,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
) -> CompiledFunctionUnwindInfo {
|
) -> Option<CompiledFunctionUnwindInfo> {
|
||||||
use cranelift_codegen::binemit::{FrameUnwindKind, FrameUnwindOffset, FrameUnwindSink, Reloc};
|
use cranelift_codegen::binemit::{FrameUnwindKind, FrameUnwindOffset, FrameUnwindSink, Reloc};
|
||||||
use cranelift_codegen::isa::CallConv;
|
use cranelift_codegen::isa::CallConv;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ pub fn compiled_function_unwind_info(
|
|||||||
CallConv::SystemV | CallConv::Fast | CallConv::Cold => FrameUnwindKind::Libunwind,
|
CallConv::SystemV | CallConv::Fast | CallConv::Cold => FrameUnwindKind::Libunwind,
|
||||||
CallConv::WindowsFastcall => FrameUnwindKind::Fastcall,
|
CallConv::WindowsFastcall => FrameUnwindKind::Fastcall,
|
||||||
_ => {
|
_ => {
|
||||||
return CompiledFunctionUnwindInfo::None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -54,11 +54,13 @@ pub fn compiled_function_unwind_info(
|
|||||||
|
|
||||||
let Sink(data, offset, relocs) = sink;
|
let Sink(data, offset, relocs) = sink;
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
return CompiledFunctionUnwindInfo::None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
FrameUnwindKind::Fastcall => CompiledFunctionUnwindInfo::Windows(data),
|
FrameUnwindKind::Fastcall => Some(CompiledFunctionUnwindInfo::Windows(data)),
|
||||||
FrameUnwindKind::Libunwind => CompiledFunctionUnwindInfo::FrameLayout(data, offset, relocs),
|
FrameUnwindKind::Libunwind => Some(CompiledFunctionUnwindInfo::FrameLayout(
|
||||||
|
data, offset, relocs,
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use inkwell::{
|
|||||||
values::FunctionValue, AddressSpace,
|
values::FunctionValue, AddressSpace,
|
||||||
};
|
};
|
||||||
use wasm_common::{FunctionType, Type};
|
use wasm_common::{FunctionType, Type};
|
||||||
use wasmer_compiler::{CompileError, CompiledFunctionUnwindInfo, FunctionBody};
|
use wasmer_compiler::{CompileError, FunctionBody};
|
||||||
|
|
||||||
pub struct FuncTrampoline {
|
pub struct FuncTrampoline {
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
@@ -97,7 +97,7 @@ impl FuncTrampoline {
|
|||||||
|
|
||||||
Ok(FunctionBody {
|
Ok(FunctionBody {
|
||||||
body: bytes,
|
body: bytes,
|
||||||
unwind_info: CompiledFunctionUnwindInfo::None,
|
unwind_info: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ use wasm_common::{
|
|||||||
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
|
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
|
||||||
use wasmer_compiler::{
|
use wasmer_compiler::{
|
||||||
to_wasm_error, wasm_unsupported, Addend, CodeOffset, CompileError, CompiledFunction,
|
to_wasm_error, wasm_unsupported, Addend, CodeOffset, CompileError, CompiledFunction,
|
||||||
CompiledFunctionFrameInfo, CompiledFunctionUnwindInfo, CustomSection, CustomSectionProtection,
|
CompiledFunctionFrameInfo, CustomSection, CustomSectionProtection, FunctionAddressMap,
|
||||||
FunctionAddressMap, FunctionBody, FunctionBodyData, Relocation, RelocationKind,
|
FunctionBody, FunctionBodyData, Relocation, RelocationKind, RelocationTarget, SectionBody,
|
||||||
RelocationTarget, SectionBody, SourceLoc, WasmResult,
|
SourceLoc, WasmResult,
|
||||||
};
|
};
|
||||||
use wasmer_runtime::libcalls::LibCall;
|
use wasmer_runtime::libcalls::LibCall;
|
||||||
use wasmer_runtime::Module as WasmerCompilerModule;
|
use wasmer_runtime::Module as WasmerCompilerModule;
|
||||||
@@ -413,7 +413,7 @@ impl FuncTranslator {
|
|||||||
CompiledFunction {
|
CompiledFunction {
|
||||||
body: FunctionBody {
|
body: FunctionBody {
|
||||||
body: bytes,
|
body: bytes,
|
||||||
unwind_info: CompiledFunctionUnwindInfo::None,
|
unwind_info: None,
|
||||||
},
|
},
|
||||||
jt_offsets: SecondaryMap::new(),
|
jt_offsets: SecondaryMap::new(),
|
||||||
relocations,
|
relocations,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub struct FunctionBody {
|
|||||||
pub body: Vec<u8>,
|
pub body: Vec<u8>,
|
||||||
|
|
||||||
/// The function unwind info
|
/// The function unwind info
|
||||||
pub unwind_info: CompiledFunctionUnwindInfo,
|
pub unwind_info: Option<CompiledFunctionUnwindInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The result of compiling a WebAssembly function.
|
/// The result of compiling a WebAssembly function.
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ pub struct FunctionTableReloc {
|
|||||||
/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
|
/// [unwind info]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=vs-2019
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum CompiledFunctionUnwindInfo {
|
pub enum CompiledFunctionUnwindInfo {
|
||||||
/// No unwind information.
|
|
||||||
None,
|
|
||||||
|
|
||||||
/// Windows UNWIND_INFO.
|
/// Windows UNWIND_INFO.
|
||||||
Windows(Vec<u8>),
|
Windows(Vec<u8>),
|
||||||
|
|
||||||
@@ -45,7 +42,6 @@ impl CompiledFunctionUnwindInfo {
|
|||||||
/// Retuns true is no unwind info data.
|
/// Retuns true is no unwind info data.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
CompiledFunctionUnwindInfo::None => true,
|
|
||||||
CompiledFunctionUnwindInfo::Windows(d) => d.is_empty(),
|
CompiledFunctionUnwindInfo::Windows(d) => d.is_empty(),
|
||||||
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.is_empty(),
|
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.is_empty(),
|
||||||
}
|
}
|
||||||
@@ -54,7 +50,6 @@ impl CompiledFunctionUnwindInfo {
|
|||||||
/// Returns size of serilized unwind info.
|
/// Returns size of serilized unwind info.
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
CompiledFunctionUnwindInfo::None => 0,
|
|
||||||
CompiledFunctionUnwindInfo::Windows(d) => d.len(),
|
CompiledFunctionUnwindInfo::Windows(d) => d.len(),
|
||||||
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.len(),
|
CompiledFunctionUnwindInfo::FrameLayout(c, _, _) => c.len(),
|
||||||
}
|
}
|
||||||
@@ -63,7 +58,6 @@ impl CompiledFunctionUnwindInfo {
|
|||||||
/// Serializes data into byte array.
|
/// Serializes data into byte array.
|
||||||
pub fn serialize(&self, dest: &mut [u8], relocs: &mut Vec<FunctionTableReloc>) {
|
pub fn serialize(&self, dest: &mut [u8], relocs: &mut Vec<FunctionTableReloc>) {
|
||||||
match self {
|
match self {
|
||||||
CompiledFunctionUnwindInfo::None => (),
|
|
||||||
CompiledFunctionUnwindInfo::Windows(d) => {
|
CompiledFunctionUnwindInfo::Windows(d) => {
|
||||||
dest.copy_from_slice(d);
|
dest.copy_from_slice(d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,11 +168,11 @@ impl CodeMemory {
|
|||||||
|
|
||||||
/// Calculates the allocation size of the given compiled function.
|
/// Calculates the allocation size of the given compiled function.
|
||||||
fn function_allocation_size(func: &FunctionBody) -> usize {
|
fn function_allocation_size(func: &FunctionBody) -> usize {
|
||||||
if func.unwind_info.is_empty() {
|
if let Some(unwind_info) = &func.unwind_info {
|
||||||
func.body.len()
|
|
||||||
} else {
|
|
||||||
// Account for necessary unwind information alignment padding (32-bit)
|
// Account for necessary unwind information alignment padding (32-bit)
|
||||||
((func.body.len() + 3) & !3) + func.unwind_info.len()
|
((func.body.len() + 3) & !3) + unwind_info.len()
|
||||||
|
} else {
|
||||||
|
func.body.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,19 +196,19 @@ impl CodeMemory {
|
|||||||
body.copy_from_slice(&func.body);
|
body.copy_from_slice(&func.body);
|
||||||
let vmfunc = Self::view_as_mut_vmfunc_slice(body);
|
let vmfunc = Self::view_as_mut_vmfunc_slice(body);
|
||||||
|
|
||||||
if func.unwind_info.is_empty() {
|
if func.unwind_info.is_none() {
|
||||||
return (func_end, remainder, table, vmfunc);
|
return (func_end, remainder, table, vmfunc);
|
||||||
}
|
}
|
||||||
|
let unwind_info = func.unwind_info.as_ref().unwrap();
|
||||||
|
|
||||||
// Keep unwind information 32-bit aligned (round up to the nearest 4 byte boundary)
|
// Keep unwind information 32-bit aligned (round up to the nearest 4 byte boundary)
|
||||||
let padding = ((func.body.len() + 3) & !3) - func.body.len();
|
let padding = ((func.body.len() + 3) & !3) - func.body.len();
|
||||||
let (unwind, remainder) = remainder.split_at_mut(padding + func.unwind_info.len());
|
let (unwind, remainder) = remainder.split_at_mut(padding + unwind_info.len());
|
||||||
let mut relocs = Vec::new();
|
let mut relocs = Vec::new();
|
||||||
func.unwind_info
|
unwind_info.serialize(&mut unwind[padding..], &mut relocs);
|
||||||
.serialize(&mut unwind[padding..], &mut relocs);
|
|
||||||
|
|
||||||
let unwind_start = func_end + (padding as u32);
|
let unwind_start = func_end + (padding as u32);
|
||||||
let unwind_end = unwind_start + (func.unwind_info.len() as u32);
|
let unwind_end = unwind_start + (unwind_info.len() as u32);
|
||||||
|
|
||||||
relocs.iter_mut().for_each(move |r| {
|
relocs.iter_mut().for_each(move |r| {
|
||||||
r.offset += unwind_start;
|
r.offset += unwind_start;
|
||||||
|
|||||||
Reference in New Issue
Block a user