Add linker data for strings, and deduplicate them

For references to addresses of constant strings, we make an entry in
reloc.CODE and configure the relocation type to say it points at a
memory address. (At least I think this is right, I can't test it yet!)

The same info can also be used for de-duplication.

It turns out we don't need reloc.DATA. I had misunderstood it.
The use case for that would be constant nested data structures,
where constant data would contain pointers to other constant data.
I don't think we're doing this in Roc at all, but not sure.
This commit is contained in:
Brian Carroll 2021-11-06 10:25:10 +00:00
parent 2f0296a5fa
commit 38d9fc5bbd
5 changed files with 113 additions and 65 deletions

View file

@ -5,7 +5,7 @@ use std::fmt::Debug;
use roc_module::symbol::Symbol;
use super::linking::{IndexRelocType, RelocationEntry};
use super::linking::{IndexRelocType, OffsetRelocType, RelocationEntry};
use super::opcodes::*;
use super::serialize::{SerialBuffer, Serialize};
use crate::{round_up_to_alignment, FRAME_ALIGNMENT_BYTES, STACK_POINTER_GLOBAL_ID};
@ -461,6 +461,16 @@ impl<'a> CodeBuilder<'a> {
self.code.encode_u32(offset);
}
/// Insert a linker relocation for a memory address
pub fn insert_memory_relocation(&mut self, symbol_index: u32) {
self.relocations.push(RelocationEntry::Offset {
type_id: OffsetRelocType::MemoryAddrLeb,
offset: self.code.len() as u32,
symbol_index,
addend: 0,
});
}
/**********************************************************
INSTRUCTION METHODS