Add ability to relocate constants using RelocSink
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
use super::{Addend, CodeInfo, CodeOffset, CodeSink, Reloc};
|
||||
use crate::binemit::stackmap::Stackmap;
|
||||
use crate::ir::entities::Value;
|
||||
use crate::ir::{ExternalName, Function, JumpTable, SourceLoc, TrapCode};
|
||||
use crate::ir::{ConstantOffset, ExternalName, Function, JumpTable, SourceLoc, TrapCode};
|
||||
use crate::isa::TargetIsa;
|
||||
use core::ptr::write_unaligned;
|
||||
|
||||
@@ -78,6 +78,9 @@ pub trait RelocSink {
|
||||
/// Add a relocation referencing an external symbol at the current offset.
|
||||
fn reloc_external(&mut self, _: CodeOffset, _: Reloc, _: &ExternalName, _: Addend);
|
||||
|
||||
/// Add a relocation referencing a constant.
|
||||
fn reloc_constant(&mut self, _: CodeOffset, _: Reloc, _: ConstantOffset);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_jt(&mut self, _: CodeOffset, _: Reloc, _: JumpTable);
|
||||
}
|
||||
@@ -132,6 +135,11 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
|
||||
self.relocs.reloc_external(ofs, rel, name, addend);
|
||||
}
|
||||
|
||||
fn reloc_constant(&mut self, rel: Reloc, constant_offset: ConstantOffset) {
|
||||
let ofs = self.offset();
|
||||
self.relocs.reloc_constant(ofs, rel, constant_offset);
|
||||
}
|
||||
|
||||
fn reloc_jt(&mut self, rel: Reloc, jt: JumpTable) {
|
||||
let ofs = self.offset();
|
||||
self.relocs.reloc_jt(ofs, rel, jt);
|
||||
@@ -169,6 +177,7 @@ pub struct NullRelocSink {}
|
||||
impl RelocSink for NullRelocSink {
|
||||
fn reloc_ebb(&mut self, _: u32, _: Reloc, _: u32) {}
|
||||
fn reloc_external(&mut self, _: u32, _: Reloc, _: &ExternalName, _: i64) {}
|
||||
fn reloc_constant(&mut self, _: CodeOffset, _: Reloc, _: ConstantOffset) {}
|
||||
fn reloc_jt(&mut self, _: u32, _: Reloc, _: JumpTable) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub use self::relaxation::relax_branches;
|
||||
pub use self::shrink::shrink_instructions;
|
||||
pub use self::stackmap::Stackmap;
|
||||
use crate::ir::entities::Value;
|
||||
use crate::ir::{ExternalName, Function, Inst, JumpTable, SourceLoc, TrapCode};
|
||||
use crate::ir::{ConstantOffset, ExternalName, Function, Inst, JumpTable, SourceLoc, TrapCode};
|
||||
use crate::isa::TargetIsa;
|
||||
pub use crate::regalloc::RegDiversions;
|
||||
use core::fmt;
|
||||
@@ -133,6 +133,9 @@ pub trait CodeSink {
|
||||
/// Add a relocation referencing an external symbol plus the addend at the current offset.
|
||||
fn reloc_external(&mut self, _: Reloc, _: &ExternalName, _: Addend);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_constant(&mut self, _: Reloc, _: ConstantOffset);
|
||||
|
||||
/// Add a relocation referencing a jump table.
|
||||
fn reloc_jt(&mut self, _: Reloc, _: JumpTable);
|
||||
|
||||
@@ -192,7 +195,13 @@ where
|
||||
}
|
||||
|
||||
sink.begin_rodata();
|
||||
// TODO: No read-only data (constant pools) at this time.
|
||||
|
||||
// output constants
|
||||
for (_, constant_data) in func.dfg.constants.iter() {
|
||||
for byte in constant_data.iter() {
|
||||
sink.put1(*byte)
|
||||
}
|
||||
}
|
||||
|
||||
sink.end_codegen();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ use crate::iterators::IteratorExtras;
|
||||
use crate::regalloc::RegDiversions;
|
||||
use crate::timing;
|
||||
use crate::CodegenResult;
|
||||
use core::convert::TryFrom;
|
||||
use log::debug;
|
||||
|
||||
#[cfg(feature = "basic-blocks")]
|
||||
@@ -135,7 +136,11 @@ pub fn relax_branches(
|
||||
let jumptables_size = offset - jumptables;
|
||||
let rodata = offset;
|
||||
|
||||
// TODO: Once we have constant pools we'll do some processing here to update offset.
|
||||
for constant in func.dfg.constants.entries_mut() {
|
||||
constant.set_offset(offset);
|
||||
offset +=
|
||||
u32::try_from(constant.len()).expect("Constants must have a length that fits in a u32")
|
||||
}
|
||||
|
||||
let rodata_size = offset - rodata;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user