Change load_object_file to take a callback that converts symbol names into relocation targets.

This change means that load_object_file no longer needs a ModuleInfo, which trampoline generation doesn't have.
This commit is contained in:
Nick Lewycky
2020-05-21 13:32:03 -07:00
parent a3a4a74596
commit 02f7e58c01
2 changed files with 29 additions and 22 deletions

View File

@ -30,7 +30,7 @@ use wasm_common::{
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
use wasmer_compiler::{
to_wasm_error, wasm_unsupported, CompileError, CompiledFunction, CustomSections,
FunctionBodyData, WasmResult,
FunctionBodyData, RelocationTarget, WasmResult,
};
use wasmer_runtime::{MemoryPlan, ModuleInfo, TablePlan, VMBuiltinFunctionIndex, VMOffsets};
@ -279,9 +279,20 @@ impl FuncTranslator {
load_object_file(
mem_buf_slice,
".wasmer_function",
local_func_index,
func_names,
wasm_module,
*local_func_index,
|name: &String| {
if let Some((index, _)) = func_names
.iter()
.find(|(_, func_name)| **func_name == *name)
{
let local_index = wasm_module
.local_func_index(index)
.expect("relocation to non-local function");
Ok(Some(RelocationTarget::LocalFunc(local_index)))
} else {
Ok(None)
}
},
)
}
}