Skip to main content

Module patch

Module patch 

Source
Expand description

Relocation patchers — pure byte math, compiled (and unit-tested) on EVERY host so the x86-64 patchers are exercised on an arm64 dev machine and vice versa. Each function rewrites one relocation site in a staging buffer given the site’s final runtime address and its target’s address.

Enums§

PatchError
Patch errors carry enough context to identify the failing site.

Functions§

is_indirect
Whether this reloc kind resolves through a pointer slot (GOT/IAT/refptr) — the buffer layout must provide one and point the site at it.
patch_aarch64_branch26
aarch64 b/bl imm26: PC-relative, ±128 MiB, 4-byte units. Preserves the opcode bits, rewriting only the immediate.
patch_aarch64_page21
aarch64 adrp hi21: the PAGE delta (4 KiB pages), split immlo[30:29] / immhi[23:5]. Range ±4 GiB.
patch_aarch64_pageoff12
aarch64 add/ldr lo12: the low 12 bits of the target, shifted right by the access-size scale for loads/stores.
patch_abs64
8-byte absolute address, little-endian.
patch_x64_rel32
x86-64 rip-relative disp32 (jmp/call/lea/mov): disp = target + addend − field_address, with the rip-after-displacement distance already NORMALIZED into the addend at extraction time (ELF bakes it in natively; build.rs adjusts Mach-O and COFF to match).