Skip to main content

Module stub_object

Module stub_object 

Source
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 into HotpatchModuleCache).
  • The device tells us, on its hello handshake, its subsecond::aslr_reference() — the runtime address of whisker_aslr_anchor in the loaded host process (Whisker’s subsecond fork anchors on this unique symbol rather than main; see crates/whisker-subsecond/src/lib.rs).
  • aslr_offset = aslr_reference - host_static_anchor_addr is the ASLR slide between the recorded .so and the live process.
  • For each symbol the patch needs, we compute runtime_addr = host_static_addr + aslr_offset and 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 needed list. Split out so callers (the Patcher’s in-session cache) can hash needed against a key and skip the rebuild when the UND set hasn’t changed.
compute_needed_symbols
Parse patch_obj and 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 in patch_obj whose name is also present in cache.symbols as a defined symbol.