Change load_object_file to take a RelocationTarget instead of a LocalFunctionIndex.

This removes its last connection to the implementation details of having a wasm_module, which we don't want to have to rely on when building trampolines.

There currently isn't a RelocationTarget for a trampoline function that refers to itself (none of been observed to done so yet), so we make the RelocationTarget optional.
This commit is contained in:
Nick Lewycky
2020-05-21 13:40:08 -07:00
parent 02f7e58c01
commit 3764e7b9f8
2 changed files with 7 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use wasm_common::entity::{PrimaryMap, SecondaryMap};
use wasm_common::LocalFunctionIndex;
use wasmer_compiler::{
CompileError, CompiledFunction, CompiledFunctionFrameInfo, CustomSection,
CustomSectionProtection, CustomSections, FunctionAddressMap, FunctionBody,
@@ -38,7 +37,7 @@ impl ElfSectionIndex {
pub fn load_object_file<F>(
mem_buf_slice: &[u8],
root_section: &str,
local_func_index: LocalFunctionIndex,
self_referential_relocation_target: Option<RelocationTarget>,
mut symbol_name_to_relocation_target: F,
) -> Result<(CompiledFunction, CustomSections), CompileError>
where
@@ -103,10 +102,9 @@ where
let mut section_to_custom_section = HashMap::new();
section_targets.insert(
root_section_index,
RelocationTarget::LocalFunc(local_func_index),
);
if let Some(reloc_target) = self_referential_relocation_target {
section_targets.insert(root_section_index, reloc_target);
};
let mut next_custom_section: u32 = 0;
let mut elf_section_to_target = |elf_section_index: ElfSectionIndex| {
@@ -174,9 +172,10 @@ where
elf_section_to_target(elf_target_section)
} else if elf_target.st_type() == goblin::elf::sym::STT_FUNC
&& elf_target_section == root_section_index
&& self_referential_relocation_target.is_some()
{
// This is a function referencing its own byte stream.
RelocationTarget::LocalFunc(local_func_index)
self_referential_relocation_target.unwrap()
} else if elf_target.st_type() == goblin::elf::sym::STT_NOTYPE
&& elf_target_section.is_undef()
{

View File

@@ -279,7 +279,7 @@ impl FuncTranslator {
load_object_file(
mem_buf_slice,
".wasmer_function",
*local_func_index,
Some(RelocationTarget::LocalFunc(*local_func_index)),
|name: &String| {
if let Some((index, _)) = func_names
.iter()