Expand description
Build a “stub” object file that defines every symbol the patch references but doesn’t itself supply. Each defined-here-only-for- the-patch symbol resolves to a tiny assembly trampoline that branches to the corresponding runtime address in the live host process.
This is the load-bearing piece of the Option B / Dioxus-style patch-resolution scheme:
- The dev server already knows every symbol’s static address in
the host
.so(parsed once intoHotpatchModuleCache). - The device tells us, on its
hellohandshake, itssubsecond::aslr_reference()— the runtime address ofwhisker_aslr_anchorin the loaded host process (Whisker’s subsecond fork anchors on this unique symbol rather thanmain; seecrates/whisker-subsecond/src/lib.rs). aslr_offset = aslr_reference - host_static_anchor_addris the ASLR slide between the recorded.soand the live process.- For each symbol the patch needs, we compute
runtime_addr = host_static_addr + aslr_offsetand write a stub that jumps straight there.
After linking the patch with this stub object, the patch has no
DT_NEEDED back-edge to the host and no dlopen-time symbol
resolution to perform: every call from the patch into the host
lands at the correct address by construction. This sidesteps the
Android linker-namespace + RTLD_LOCAL problems that the prior
“back-edge to host dylib” scheme tripped over.
Mirrors dioxus-cli-0.7.9::build::patch::create_undefined_symbol_stub.
Differences:
- We don’t support Windows (
__imp_prefix handling and PE32+ stubs are skipped — Whisker targets Android + iOS-sim + the macOS / Linux host). - We only emit Text stubs; Data symbol stubs are deferred (none of our hot-patches reference data symbols in the host so far; the tests in B-4 confirm this).
Functions§
- build_
stub_ for_ needed - Build the stub object bytes for a precomputed
neededlist. Split out so callers (the Patcher’s in-session cache) can hashneededagainst a key and skip the rebuild when the UND set hasn’t changed. - compute_
needed_ symbols - Parse
patch_objand return the sorted list of symbol names the patch refers to but doesn’t itself define. Sorted (Vec, not Set) so callers can hash the result deterministically for caching. - compute_
needed_ symbols_ multi - Multi-input variant of
compute_needed_symbols. Take the union of every input’s undefined set minus the union of every input’s defined set — i.e. symbols still unresolved after the inputs satisfy each other’s references. - create_
undefined_ symbol_ stub - Build a stub
.o(bytes ready to write to disk) that satisfies every undefined symbol inpatch_objwhose name is also present incache.symbolsas a defined symbol.