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);
|
||||
|
||||
Reference in New Issue
Block a user