Add support for a function referring to its own bytes.

This commit is contained in:
Nick Lewycky
2020-05-05 14:15:39 -07:00
parent 50664f9aaa
commit 187324b3d3

View File

@ -102,14 +102,14 @@ impl FuncTranslator {
pub fn translate(
&mut self,
wasm_module: &WasmerCompilerModule,
func_index: &LocalFunctionIndex,
local_func_index: &LocalFunctionIndex,
function_body: &FunctionBodyData,
config: &LLVMConfig,
memory_plans: &PrimaryMap<MemoryIndex, MemoryPlan>,
table_plans: &PrimaryMap<TableIndex, TablePlan>,
func_names: &SecondaryMap<FunctionIndex, String>,
) -> Result<(CompiledFunction, Vec<LocalRelocation>, Vec<CustomSection>), CompileError> {
let func_index = wasm_module.func_index(*func_index);
let func_index = wasm_module.func_index(*local_func_index);
let func_name = func_names.get(func_index).unwrap();
let module_name = match wasm_module.name.as_ref() {
None => format!("<anonymous module> function {}", func_name),
@ -376,6 +376,16 @@ impl FuncTranslator {
offset,
addend,
});
} else if target.st_type() == goblin::elf::sym::STT_FUNC
&& target.st_shndx == wasmer_function_idx
{
// This is a function referencing its own byte stream.
relocations.push(Relocation {
kind,
reloc_target: RelocationTarget::LocalFunc(*local_func_index),
offset,
addend,
});
} else if target.st_type() == goblin::elf::sym::STT_NOTYPE
&& target.st_shndx == goblin::elf::section_header::SHN_UNDEF as _
{