Parse a relocation to a different user function out of the object file.

This updates to a newer inkwell to pick up a fix to Section::get_contents. Picking that up changed builder.build_struct_gep to return a Result, and there's many API updates scattered around to support that.

Compute the function names for all local and imported functions in the module in advance and pass that mapping to the function code generation.

debug_trap is added to Intrinsics, though all users are commented out.
This commit is contained in:
Nick Lewycky
2020-04-29 17:38:57 -07:00
parent d88fb959b9
commit 71eeb135bc
5 changed files with 159 additions and 66 deletions

View File

@@ -81,8 +81,8 @@ impl FuncTrampoline {
.write_to_memory_buffer(&mut module, FileType::Object)
.unwrap();
// TODO: remove debugging
/*
// TODO: remove debugging
let mem_buf_slice = memory_buffer.as_slice();
let mut file = fs::File::create("/home/nicholas/trampoline.o").unwrap();
let mut pos = 0;
@@ -100,10 +100,12 @@ impl FuncTrampoline {
if section.get_name().map(std::ffi::CStr::to_bytes)
== Some("wasmer_trampoline".as_bytes())
{
bytes.extend(section.get_contents().to_bytes());
bytes.extend(section.get_contents().to_vec());
break;
}
}
// TODO: remove debugging
//dbg!(&bytes);
let address_map = FunctionAddressMap {
instructions: vec![],
@@ -134,6 +136,14 @@ fn generate_trampoline<'ctx>(
let builder = context.create_builder();
builder.position_at_end(entry_block);
/*
// TODO: remove debugging
builder.build_call(
intrinsics.debug_trap,
&[],
"");
*/
let (callee_vmctx_ptr, caller_vmctx_ptr, func_ptr, args_rets_ptr) =
match trampoline_func.get_params().as_slice() {
&[callee_vmctx_ptr, caller_vmctx_ptr, func_ptr, args_rets_ptr] => (