cranelift codegen: add a supplementary method add_call_site to CodeSink;

This allows keeping track of indirect call sites, for instance.
This commit is contained in:
Benjamin Bouvier
2020-04-01 16:05:34 +02:00
parent f4c4a84b84
commit 6a68130d5b
3 changed files with 25 additions and 2 deletions

View File

@@ -16,7 +16,7 @@
use super::{Addend, CodeInfo, CodeOffset, CodeSink, Reloc};
use crate::binemit::stackmap::Stackmap;
use crate::ir::entities::Value;
use crate::ir::{ConstantOffset, ExternalName, Function, JumpTable, SourceLoc, TrapCode};
use crate::ir::{ConstantOffset, ExternalName, Function, JumpTable, Opcode, SourceLoc, TrapCode};
use crate::isa::TargetIsa;
use core::ptr::write_unaligned;
@@ -92,6 +92,10 @@ pub trait RelocSink {
/// Add a relocation referencing a jump table.
fn reloc_jt(&mut self, _: CodeOffset, _: Reloc, _: JumpTable);
/// Track a call site whose return address is the given CodeOffset, for the given opcode. Does
/// nothing in general, only useful for certain embedders (SpiderMonkey).
fn add_call_site(&mut self, _: Opcode, _: CodeOffset, _: SourceLoc) {}
}
/// A trait for receiving trap codes and offsets.
@@ -183,6 +187,15 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
let stackmap = Stackmap::from_values(&val_list, func, isa);
self.stackmaps.add_stackmap(ofs, stackmap);
}
fn add_call_site(&mut self, opcode: Opcode, loc: SourceLoc) {
debug_assert!(
opcode.is_call(),
"adding call site info for a non-call instruction."
);
let ret_addr = self.offset();
self.relocs.add_call_site(opcode, ret_addr, loc);
}
}
/// A `RelocSink` implementation that does nothing, which is convenient when