diff --git a/crates/compiler/gen_dev/src/object_builder.rs b/crates/compiler/gen_dev/src/object_builder.rs index 3520a93c21..4d26bdb7a7 100644 --- a/crates/compiler/gen_dev/src/object_builder.rs +++ b/crates/compiler/gen_dev/src/object_builder.rs @@ -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); }