mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-31 12:49:28 +00:00
Force jump tables to be for local functions
This commit is contained in:
@ -31,7 +31,7 @@ pub struct RelocSink<'a> {
|
|||||||
module: &'a Module,
|
module: &'a Module,
|
||||||
|
|
||||||
/// Current function index.
|
/// Current function index.
|
||||||
func_index: FuncIndex,
|
local_func_index: LocalFuncIndex,
|
||||||
|
|
||||||
/// Relocations recorded for the function.
|
/// Relocations recorded for the function.
|
||||||
pub func_relocs: Vec<Relocation>,
|
pub func_relocs: Vec<Relocation>,
|
||||||
@ -87,7 +87,10 @@ impl<'a> binemit::RelocSink for RelocSink<'a> {
|
|||||||
fn reloc_jt(&mut self, offset: binemit::CodeOffset, reloc: binemit::Reloc, jt: ir::JumpTable) {
|
fn reloc_jt(&mut self, offset: binemit::CodeOffset, reloc: binemit::Reloc, jt: ir::JumpTable) {
|
||||||
self.func_relocs.push(Relocation {
|
self.func_relocs.push(Relocation {
|
||||||
kind: irreloc_to_relocationkind(reloc),
|
kind: irreloc_to_relocationkind(reloc),
|
||||||
reloc_target: RelocationTarget::JumpTable(self.func_index, JumpTable::new(jt.index())),
|
reloc_target: RelocationTarget::JumpTable(
|
||||||
|
self.local_func_index,
|
||||||
|
JumpTable::new(jt.index()),
|
||||||
|
),
|
||||||
offset,
|
offset,
|
||||||
addend: 0,
|
addend: 0,
|
||||||
});
|
});
|
||||||
@ -97,9 +100,12 @@ impl<'a> binemit::RelocSink for RelocSink<'a> {
|
|||||||
impl<'a> RelocSink<'a> {
|
impl<'a> RelocSink<'a> {
|
||||||
/// Return a new `RelocSink` instance.
|
/// Return a new `RelocSink` instance.
|
||||||
pub fn new(module: &'a Module, func_index: FuncIndex) -> Self {
|
pub fn new(module: &'a Module, func_index: FuncIndex) -> Self {
|
||||||
|
let local_func_index = module
|
||||||
|
.local_func_index(func_index)
|
||||||
|
.expect("The provided function should be local");
|
||||||
Self {
|
Self {
|
||||||
module,
|
module,
|
||||||
func_index,
|
local_func_index,
|
||||||
func_relocs: Vec::new(),
|
func_relocs: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ pub enum RelocationTarget {
|
|||||||
/// A compiler-generated libcall.
|
/// A compiler-generated libcall.
|
||||||
LibCall(LibCall),
|
LibCall(LibCall),
|
||||||
/// Jump table index.
|
/// Jump table index.
|
||||||
JumpTable(FuncIndex, JumpTable),
|
JumpTable(LocalFuncIndex, JumpTable),
|
||||||
/// Custom sections generated by the compiler
|
/// Custom sections generated by the compiler
|
||||||
CustomSection(SectionIndex),
|
CustomSection(SectionIndex),
|
||||||
}
|
}
|
||||||
|
@ -28,17 +28,12 @@ pub fn link_module(
|
|||||||
unimplemented!("Custom Sections not yet implemented");
|
unimplemented!("Custom Sections not yet implemented");
|
||||||
}
|
}
|
||||||
RelocationTarget::JumpTable(func_index, jt) => {
|
RelocationTarget::JumpTable(func_index, jt) => {
|
||||||
match module.local_func_index(func_index) {
|
let offset = *jt_offsets
|
||||||
Some(f) => {
|
.get(func_index)
|
||||||
let offset = *jt_offsets
|
.and_then(|ofs| ofs.get(JumpTable::new(jt.index())))
|
||||||
.get(f)
|
.expect("func jump table");
|
||||||
.and_then(|ofs| ofs.get(JumpTable::new(jt.index())))
|
let fatptr: *const [VMFunctionBody] = allocated_functions[func_index];
|
||||||
.expect("func jump table");
|
fatptr as *const VMFunctionBody as usize + offset as usize
|
||||||
let fatptr: *const [VMFunctionBody] = allocated_functions[f];
|
|
||||||
fatptr as *const VMFunctionBody as usize + offset as usize
|
|
||||||
}
|
|
||||||
None => panic!("func index of jump table"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user