This repository has been archived on 2026-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
molotov/crates/molotov-core/tests/reloc_test.rs

20 lines
672 B
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
use molotov_core::reloc::{apply_relative_relocation, RelocationEntry, R_X86_64_RELATIVE};
#[test]
fn test_relative_relocation_adds_slide_and_addend() {
let mut memory = vec![0u8; 64];
let base_slide: u64 = 0x7fff_0000_0000;
let addend: i64 = 0x1000;
let reloc = RelocationEntry {
offset: 8,
r_type: R_X86_64_RELATIVE,
symbol_index: 0,
addend,
};
apply_relative_relocation(&mut memory, base_slide, &reloc).expect("Relocation should apply cleanly");
let resolved = u64::from_le_bytes(memory[8..16].try_into().unwrap());
assert_eq!(resolved, 0x7fff_0000_1000);
}