cranelift codegen: pass source locations with external relocations;
This commit is contained in:
@@ -205,7 +205,8 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
|
||||
|
||||
recipes.push(EncodingRecipeBuilder::new("UJcall", &formats.call, 4).emit(
|
||||
r#"
|
||||
sink.reloc_external(Reloc::RiscvCall,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::RiscvCall,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
0);
|
||||
// rd=%x1 is the standard link register.
|
||||
|
||||
@@ -1258,7 +1258,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
0);
|
||||
sink.put4(0);
|
||||
@@ -1273,7 +1274,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs8,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs8,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
0);
|
||||
sink.put8(0);
|
||||
@@ -1288,7 +1290,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
0);
|
||||
// Write the immediate as `!0` for the benefit of BaldrMonkey.
|
||||
@@ -1304,7 +1307,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs8,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs8,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
0);
|
||||
// Write the immediate as `!0` for the benefit of BaldrMonkey.
|
||||
@@ -1324,7 +1328,8 @@ pub(crate) fn define<'shared>(
|
||||
modrm_riprel(out_reg0, sink);
|
||||
// The addend adjusts for the difference between the end of the
|
||||
// instruction and the beginning of the immediate field.
|
||||
sink.reloc_external(Reloc::X86PCRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86PCRel4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -1343,7 +1348,8 @@ pub(crate) fn define<'shared>(
|
||||
modrm_riprel(out_reg0, sink);
|
||||
// The addend adjusts for the difference between the end of the
|
||||
// instruction and the beginning of the immediate field.
|
||||
sink.reloc_external(Reloc::X86GOTPCRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86GOTPCRel4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -1358,7 +1364,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs4,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
0);
|
||||
sink.put4(0);
|
||||
@@ -1373,7 +1380,8 @@ pub(crate) fn define<'shared>(
|
||||
.emit(
|
||||
r#"
|
||||
{{PUT_OP}}(bits | (out_reg0 & 7), rex1(out_reg0), sink);
|
||||
sink.reloc_external(Reloc::Abs8,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::Abs8,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
0);
|
||||
sink.put8(0);
|
||||
@@ -1391,7 +1399,8 @@ pub(crate) fn define<'shared>(
|
||||
modrm_rm(5, out_reg0, sink);
|
||||
// The addend adjusts for the difference between the end of the
|
||||
// instruction and the beginning of the immediate field.
|
||||
sink.reloc_external(Reloc::X86PCRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86PCRel4,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -1409,7 +1418,8 @@ pub(crate) fn define<'shared>(
|
||||
modrm_rm(5, out_reg0, sink);
|
||||
// The addend adjusts for the difference between the end of the
|
||||
// instruction and the beginning of the immediate field.
|
||||
sink.reloc_external(Reloc::X86GOTPCRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86GOTPCRel4,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -2402,7 +2412,8 @@ pub(crate) fn define<'shared>(
|
||||
{{PUT_OP}}(bits, BASE_REX, sink);
|
||||
// The addend adjusts for the difference between the end of the
|
||||
// instruction and the beginning of the immediate field.
|
||||
sink.reloc_external(Reloc::X86CallPCRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86CallPCRel4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -2415,7 +2426,8 @@ pub(crate) fn define<'shared>(
|
||||
r#"
|
||||
sink.trap(TrapCode::StackOverflow, func.srclocs[inst]);
|
||||
{{PUT_OP}}(bits, BASE_REX, sink);
|
||||
sink.reloc_external(Reloc::X86CallPLTRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86CallPLTRel4,
|
||||
&func.dfg.ext_funcs[func_ref].name,
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -3320,7 +3332,8 @@ pub(crate) fn define<'shared>(
|
||||
const LEA: u8 = 0x8d;
|
||||
sink.put1(LEA); // lea
|
||||
modrm_riprel(0b111/*out_reg0*/, sink); // 0x3d
|
||||
sink.reloc_external(Reloc::ElfX86_64TlsGd,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::ElfX86_64TlsGd,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -3330,7 +3343,8 @@ pub(crate) fn define<'shared>(
|
||||
sink.put1(0x66); // data16
|
||||
sink.put1(0b01001000); // rex.w
|
||||
sink.put1(0xe8); // call
|
||||
sink.reloc_external(Reloc::X86CallPLTRel4,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::X86CallPLTRel4,
|
||||
&ExternalName::LibCall(LibCall::ElfTlsGetAddr),
|
||||
-4);
|
||||
sink.put4(0);
|
||||
@@ -3351,7 +3365,8 @@ pub(crate) fn define<'shared>(
|
||||
sink.put1(0x48); // rex
|
||||
sink.put1(0x8b); // mov
|
||||
modrm_riprel(0b111/*out_reg0*/, sink); // 0x3d
|
||||
sink.reloc_external(Reloc::MachOX86_64Tlv,
|
||||
sink.reloc_external(func.srclocs[inst],
|
||||
Reloc::MachOX86_64Tlv,
|
||||
&func.global_values[global_value].symbol_name(),
|
||||
-4);
|
||||
sink.put4(0);
|
||||
|
||||
@@ -78,7 +78,14 @@ pub trait RelocSink {
|
||||
fn reloc_block(&mut self, _: CodeOffset, _: Reloc, _: CodeOffset);
|
||||
|
||||
/// Add a relocation referencing an external symbol at the current offset.
|
||||
fn reloc_external(&mut self, _: CodeOffset, _: Reloc, _: &ExternalName, _: Addend);
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_: CodeOffset,
|
||||
_: SourceLoc,
|
||||
_: Reloc,
|
||||
_: &ExternalName,
|
||||
_: Addend,
|
||||
);
|
||||
|
||||
/// Add a relocation referencing a constant.
|
||||
fn reloc_constant(&mut self, _: CodeOffset, _: Reloc, _: ConstantOffset);
|
||||
@@ -132,9 +139,15 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
||||
self.relocs.reloc_block(ofs, rel, block_offset);
|
||||
}
|
||||
|
||||
fn reloc_external(&mut self, rel: Reloc, name: &ExternalName, addend: Addend) {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
srcloc: SourceLoc,
|
||||
rel: Reloc,
|
||||
name: &ExternalName,
|
||||
addend: Addend,
|
||||
) {
|
||||
let ofs = self.offset();
|
||||
self.relocs.reloc_external(ofs, rel, name, addend);
|
||||
self.relocs.reloc_external(ofs, srcloc, rel, name, addend);
|
||||
}
|
||||
|
||||
fn reloc_constant(&mut self, rel: Reloc, constant_offset: ConstantOffset) {
|
||||
@@ -177,10 +190,18 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
||||
pub struct NullRelocSink {}
|
||||
|
||||
impl RelocSink for NullRelocSink {
|
||||
fn reloc_block(&mut self, _: u32, _: Reloc, _: u32) {}
|
||||
fn reloc_external(&mut self, _: u32, _: Reloc, _: &ExternalName, _: i64) {}
|
||||
fn reloc_block(&mut self, _: CodeOffset, _: Reloc, _: CodeOffset) {}
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_: CodeOffset,
|
||||
_: SourceLoc,
|
||||
_: Reloc,
|
||||
_: &ExternalName,
|
||||
_: Addend,
|
||||
) {
|
||||
}
|
||||
fn reloc_constant(&mut self, _: CodeOffset, _: Reloc, _: ConstantOffset) {}
|
||||
fn reloc_jt(&mut self, _: u32, _: Reloc, _: JumpTable) {}
|
||||
fn reloc_jt(&mut self, _: CodeOffset, _: Reloc, _: JumpTable) {}
|
||||
}
|
||||
|
||||
/// A `TrapSink` implementation that does nothing, which is convenient when
|
||||
|
||||
@@ -140,7 +140,7 @@ pub trait CodeSink {
|
||||
fn reloc_block(&mut self, _: Reloc, _: CodeOffset);
|
||||
|
||||
/// Add a relocation referencing an external symbol plus the addend at the current offset.
|
||||
fn reloc_external(&mut self, _: Reloc, _: &ExternalName, _: Addend);
|
||||
fn reloc_external(&mut self, _: SourceLoc, _: Reloc, _: &ExternalName, _: Addend);
|
||||
|
||||
/// Add a relocation referencing a constant.
|
||||
fn reloc_constant(&mut self, _: Reloc, _: ConstantOffset);
|
||||
|
||||
@@ -386,6 +386,7 @@ impl<'a> RelocSink for FaerieRelocSink<'a> {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: Addend,
|
||||
|
||||
@@ -79,6 +79,7 @@ impl binemit::CodeSink for TextSink {
|
||||
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: binemit::Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: binemit::Addend,
|
||||
|
||||
@@ -101,6 +101,7 @@ impl binemit::CodeSink for SizeSink {
|
||||
fn reloc_block(&mut self, _reloc: binemit::Reloc, _block_offset: binemit::CodeOffset) {}
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_srcloc: ir::SourceLoc,
|
||||
_reloc: binemit::Reloc,
|
||||
_name: &ir::ExternalName,
|
||||
_addend: binemit::Addend,
|
||||
|
||||
@@ -109,7 +109,14 @@ impl binemit::CodeSink for RodataSink {
|
||||
}
|
||||
|
||||
fn reloc_block(&mut self, _reloc: binemit::Reloc, _block_offset: binemit::CodeOffset) {}
|
||||
fn reloc_external(&mut self, _: binemit::Reloc, _: &ir::ExternalName, _: binemit::Addend) {}
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_: ir::SourceLoc,
|
||||
_: binemit::Reloc,
|
||||
_: &ir::ExternalName,
|
||||
_: binemit::Addend,
|
||||
) {
|
||||
}
|
||||
fn reloc_constant(&mut self, _: binemit::Reloc, _: ir::ConstantOffset) {}
|
||||
fn reloc_jt(&mut self, _reloc: binemit::Reloc, _jt: ir::JumpTable) {}
|
||||
fn trap(&mut self, _code: ir::TrapCode, _srcloc: ir::SourceLoc) {}
|
||||
|
||||
@@ -530,6 +530,7 @@ impl RelocSink for ObjectRelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: Reloc,
|
||||
name: &ir::ExternalName,
|
||||
mut addend: Addend,
|
||||
|
||||
@@ -631,6 +631,7 @@ impl RelocSink for SimpleJITRelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: Addend,
|
||||
|
||||
@@ -37,6 +37,7 @@ impl binemit::RelocSink for PrintRelocs {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
where_: binemit::CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
r: binemit::Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: binemit::Addend,
|
||||
|
||||
@@ -41,6 +41,7 @@ impl binemit::RelocSink for RelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: binemit::CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: binemit::Reloc,
|
||||
name: &ExternalName,
|
||||
addend: binemit::Addend,
|
||||
|
||||
@@ -434,6 +434,7 @@ impl binemit::RelocSink for RelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
offset: binemit::CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
reloc: binemit::Reloc,
|
||||
name: &ir::ExternalName,
|
||||
addend: binemit::Addend,
|
||||
|
||||
@@ -31,6 +31,7 @@ pub mod binemit {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_offset: binemit::CodeOffset,
|
||||
_srcloc: ir::SourceLoc,
|
||||
_reloc: binemit::Reloc,
|
||||
_name: &ir::ExternalName,
|
||||
_addend: binemit::Addend,
|
||||
|
||||
@@ -5404,6 +5404,8 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
||||
.unwrap()
|
||||
.0) as u32
|
||||
+ 2,
|
||||
// Passing a default location here, since until proven otherwise, it's not used.
|
||||
ir::SourceLoc::default(),
|
||||
binemit::Reloc::Abs8,
|
||||
name,
|
||||
0,
|
||||
|
||||
@@ -87,6 +87,7 @@ impl binemit::RelocSink for UnimplementedRelocSink {
|
||||
fn reloc_external(
|
||||
&mut self,
|
||||
_: binemit::CodeOffset,
|
||||
_: ir::SourceLoc,
|
||||
_: binemit::Reloc,
|
||||
_: &ir::ExternalName,
|
||||
_: binemit::Addend,
|
||||
|
||||
Reference in New Issue
Block a user