mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
centralize relocation logic
This commit is contained in:
parent
821cc0cfd8
commit
c98d9356ac
1 changed files with 21 additions and 32 deletions
|
@ -275,22 +275,7 @@ fn generate_wrapper<'a, B: Backend<'a>>(
|
|||
};
|
||||
output.add_symbol(symbol);
|
||||
if let Some(sym_id) = output.symbol_id(name) {
|
||||
let (encoding, size) = match backend.target_info().architecture {
|
||||
roc_target::Architecture::Aarch32 => todo!(),
|
||||
roc_target::Architecture::Aarch64 => (RelocationEncoding::AArch64Call, 26),
|
||||
roc_target::Architecture::Wasm32 => todo!(),
|
||||
roc_target::Architecture::X86_32 => todo!(),
|
||||
roc_target::Architecture::X86_64 => (RelocationEncoding::X86Branch, 32),
|
||||
};
|
||||
|
||||
let reloc = write::Relocation {
|
||||
offset: offset + proc_offset,
|
||||
size,
|
||||
kind: RelocationKind::PltRelative,
|
||||
encoding,
|
||||
symbol: sym_id,
|
||||
addend: -4,
|
||||
};
|
||||
let reloc = create_relocation(backend.target_info(), sym_id, offset + proc_offset);
|
||||
|
||||
match output.add_relocation(text_section, reloc) {
|
||||
Ok(obj) => obj,
|
||||
|
@ -301,6 +286,25 @@ fn generate_wrapper<'a, B: Backend<'a>>(
|
|||
}
|
||||
}
|
||||
|
||||
fn create_relocation(target_info: TargetInfo, symbol: SymbolId, offset: u64) -> write::Relocation {
|
||||
let (encoding, size) = match target_info.architecture {
|
||||
roc_target::Architecture::Aarch32 => todo!(),
|
||||
roc_target::Architecture::Aarch64 => (RelocationEncoding::AArch64Call, 26),
|
||||
roc_target::Architecture::Wasm32 => todo!(),
|
||||
roc_target::Architecture::X86_32 => todo!(),
|
||||
roc_target::Architecture::X86_64 => (RelocationEncoding::X86Branch, 32),
|
||||
};
|
||||
|
||||
write::Relocation {
|
||||
offset,
|
||||
size,
|
||||
kind: RelocationKind::PltRelative,
|
||||
encoding,
|
||||
symbol,
|
||||
addend: -4,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_object<'a, B: Backend<'a>>(
|
||||
procedures: MutMap<(symbol::Symbol, ProcLayout<'a>), Proc<'a>>,
|
||||
mut backend: B,
|
||||
|
@ -891,22 +895,7 @@ fn build_proc<'a, B: Backend<'a>>(
|
|||
}
|
||||
|
||||
if let Some(sym_id) = output.symbol_id(name.as_bytes()) {
|
||||
let (encoding, size) = match target_info.architecture {
|
||||
roc_target::Architecture::Aarch32 => todo!(),
|
||||
roc_target::Architecture::Aarch64 => (RelocationEncoding::AArch64Call, 26),
|
||||
roc_target::Architecture::Wasm32 => todo!(),
|
||||
roc_target::Architecture::X86_32 => todo!(),
|
||||
roc_target::Architecture::X86_64 => (RelocationEncoding::X86Branch, 32),
|
||||
};
|
||||
|
||||
write::Relocation {
|
||||
offset: offset + proc_offset,
|
||||
size,
|
||||
kind: RelocationKind::PltRelative,
|
||||
encoding,
|
||||
symbol: sym_id,
|
||||
addend: -4,
|
||||
}
|
||||
create_relocation(target_info, sym_id, offset + proc_offset)
|
||||
} else {
|
||||
internal_error!("failed to find fn symbol for {:?}", name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue