Files
rea/docs/native-function-matching.md
T
gensokyo-dev 1417bf943b feat(native): match retained function inventories across builds (#5390)
Match retained native inventories through shared CLI/MCP workflows with conservative symbol/byte correspondence, unresolved structural candidates, complete Evidence provenance and bounded paged reads.

Closes #5343.
2026-10-20 09:48:52 +00:00

6.4 KiB
Raw Blame History

Match native functions across builds

match_native_functions pairs two existing list_procedures Evidence inventories. Select list_procedures detail: "summary" to retain complete source rows without transferring the entire inventory. Its parent_evidence_id is the reference matching consumes. Targets may be opened sequentially; matching never opens a target, rereads its file, executes it or starts a provider. Preserve each inventory before closing its target, or import its Evidence bundle later. close_binary clears session records. Export each bundle before closing; after collecting both sides and closing the last target, import both bundles, then use their references. Keeping only an Evidence ID across close is insufficient. Complete inline Evidence and CLI source_bundle inputs are portable alternatives. Pass Evidence or exact session references as left and right:

{
  "left": { "kind": "retained-evidence", "evidence_id": "ev_<left digest>" },
  "right": { "kind": "retained-evidence", "evidence_id": "ev_<right digest>" }
}

Unique exact reported names are paired first. Optional list_names Evidence identifies dynamic/default names to exclude. If origin is unavailable, the existing automatic-name exclusion rule applies and each function retains that limitation. Exact names establish name correspondence, not unchanged code or original-source identity.

For unmatched candidates, optionally supply left_observations and right_observations. procedure_info or existing analyze_function Evidence gives exact inclusive body ranges; read_bytes supplies memory bytes. Observations must belong to the side's exact target/provider/profile and document context. Adjacent, consistent overlapping and partially returned reads compose by their observed extent; conflicting intervals remain gaps. A byte match requires every body byte, equal total size, equal ordered range lengths, a unique SHA-256 fingerprint and the same known architecture. Extents are never guessed from the next entry, and relocations are not normalized. A larger mapped read can serve several observed bodies; only needed ranges need to be captured.

This first slice reuses existing range observations. Stripped builds can require many lightweight range queries when those facts are not retained yet. Matching does not hide that acquisition cost or silently start those queries. Full decompilation is unnecessary.

Repeated candidates stay unresolved groups without a Cartesian pair expansion. only_left/only_right mean no exact counterpart in the supplied observations; renaming, inlining, stripping, changed bytes