link_reloc_apply.c (1282B)
1 /* The single public relocation byte-patcher entry. 2 * 3 * link_reloc_apply() is the "one encoder, three loaders" boundary (doc/OBJ.md): 4 * the static linker, JIT linker, assembler, and emulator guest loader all call 5 * it unchanged. It first tries the arch-neutral data-word encoders in obj-core 6 * (reloc_apply_neutral), then routes instruction-immediate kinds to the owning 7 * backend via LinkArchDesc.reloc_apply_insn, panicking only if neither claims 8 * the kind. 9 * 10 * It lives in src/link (not obj-core) because resolving the per-arch slice 11 * needs link_arch_desc_for() — housing the dispatcher in obj-core would invert 12 * the obj->link boundary, exactly as for WS-B's reloc_desc(). The neutral 13 * encoders it delegates to stay pure obj-core. See doc/plan/RELOC.md (WS-C). 14 */ 15 16 #include "core/core.h" 17 #include "link/link_arch.h" 18 #include "obj/reloc_apply.h" 19 20 void link_reloc_apply(Compiler* c, RelocKind k, u8* P_bytes, u64 S, i64 A, 21 u64 P) { 22 const LinkArchDesc* d; 23 if (reloc_apply_neutral(c, k, P_bytes, S, A, P)) return; 24 d = link_arch_desc_for(c); 25 if (d && d->reloc_apply_insn && d->reloc_apply_insn(c, k, P_bytes, S, A, P)) 26 return; 27 compiler_panic(c, SRCLOC_NONE, "link: unsupported reloc kind %u", 28 (unsigned)k); 29 }