Repository navigation
tee-o2-tail-jumps-4a1f49: recover -O2 tail jumps as tail calls (option tailcalljump) - #59
Merged
Merged
Conversation
…n tailcalljump) Closes the angr-vs-kuna gap on test_decompiling_tee_O2_tail_jumps :: setlocale_null_androidfix. At -O2 a leaf function whose last act is "call X; return" is compiled to a direct tail jump (`jmp setlocale@plt`). kuna's flow follower treated the direct jmp as intraprocedural flow and followed it INTO the PLT thunk, whose `jmp qword [GOT]` then failed jump-table recovery and became a `(*dat_...)(...)` CALLIND + a "Treating indirect jump as call" warning. New S2 flow-classification predicate kuna_is_tail_call_branch (kuna_tailcalljump.rs, ElementId 4100, modeled on kuna_v850indbranch): in FlowInfo::xref_control_flow's CPUI_BRANCH arm, when `option tailcalljump on` and a direct branch targets another known function's entry (query_call resolves it, incl. PLT thunks) and not the function's own entry, rewrite BRANCH -> CALL + an artificial RETURN instead of flowing into the callee. The callee then resolves by name (setlocale) and the spurious warning / GOT-pointer indirect call are gone. Default OFF (default-pipeline byte-identical; default-ON regresses 2 datatests Long double #1/#2). make test PARITY OK 675/675, test-stages 162/162, catalog OK. Speed +2.26% (within budget). New firing stage test tests/stages/ghangr-tee-o2-tail-jumps-4a1f49.xml. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
We need the following changes:
|
…low-up)
Reviewer asked to (a) make `option tailcalljump` on-by-default and (b) add a
logger when the pass introduces a new call. Resolved as follows:
- LOGGER (done): when the S2 pass rewrites a tail `jmp <func>` into a CALL it
now emits `Funcdata::warning("tailcalljump: recovered tail call -> introduced
call to <dest>")` at the branch site, rendered as a /* WARNING: ... */ comment
so the introduced call is observable in the output (output-changing-feature
logging contract). New stage-test assertion #4 asserts it.
- DEFAULT-ON (could NOT ship): flipping `tail_call_jumps` default-true in
`Architecture::reset_defaults_internal` regresses 2 of the 675 upstream
datatest assertions (Long double #1/#2), exactly as the original PR's ablation
predicted. Per the standing rule (never modify docs/baseline.json; default-on
must not change any datatest assertion), the feature STAYS default-OFF opt-in.
No DIV entry.
Merge with main (branch was behind): union the option-registration files
(stages.toml settable/surface rows + counts, options.rs KUNA_OPTION_NAMES,
architecture.rs flags, kuna-catalog.xml provenance counts angr 10->11 /
structure-recovery 6->7, baseline-stages.json, assertions.md). Renumbered the
tailcalljump ElementId 4100 -> 4101 (gotoreduce took 4100 on main). Bumped the
merged-tree count tests: stages 91->92 surfaces / 45->46 settables /
21->22 live-readers, catalog byte-compat fixture regenerated (46 settables),
xml-corpus file count 137->138.
Gates: `make test` PARITY OK 675/675; `make test-stages` PARITY OK 175/175;
`make rust-test` green; `kuna catalog --check` OK. Speed: off ~= on (within
noise, well under the 5% budget).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Resolve union conflicts with main (which landed #60 switchguardbound + #68/#60 region work). Both opt-in/default-off knobs coexist: - stages.toml: union [[settable]]/[[surface]] -> surface 91->93, settable 45->47 (29 stage-model + 15 analysis + 3 loader); header counts updated. - kuna_stages/tests.rs: surface_count 93, settable_count 47, live_value present-for-23 (switch_guard_bound + tail_call_jumps both field-backed), catalog-json trailing-commas 46. - catalog_bytecompat.rs: fixture_has_all_47_settables; stage_catalog.json fixture auto-unioned (byte-for-byte test green). - xml.rs corpus count 138->139 (83 datatests + 56 stage tests: both the missing-function-call and tee-o2-tail-jumps stage tests present). - kuna-catalog.xml: source_decompiler=angr 12, structure-recovery 7, opt-in-tool 8. - PROGRESS.md: union both session entries. - tailcalljump ElementId stays 4101 (no collision; gotoreduce=4100 on main). Regenerated docs/assertions.md + docs/baseline-stages.json (180/180). Gates: kuna catalog --check OK; make test PARITY OK 675/675; make test-stages PARITY OK 180/180. docs/baseline.json untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
Resolve union conflicts with main (which since this branch's base landed gotoreduce, loopbreak_recovery/DIV-10, switchguardbound/#60, tailcalljump/#59, macho-arm64e, and more). branchflip (S8 readability, opt-in/default-off, ElementId-free) coexists with all of them: - stages.toml: union [[settable]]/[[surface]] -> surface 93->94, settable 47->48 (30 stage-model + 15 analysis + 3 loader); branchflip inserted after stackguard, before loopbreak_recovery; header counts updated. - options.rs KUNA_OPTION_NAMES: union (branchflip + loopbreak_recovery). - architecture.rs: union the set_kuna_option arm (branchflip on_off! + loopbreak_recovery); branch_flip field/ctor/reset/seam-copy all preserved. - kuna_stages/tests.rs: surface_count 94, settable_count 48, live_value present-for-23 / suppressed-for-25 (branchflip is NOT field-backed), catalog-json trailing-commas 47. - catalog_bytecompat.rs: fixture_has_all_48_settables; stage_catalog.json fixture regenerated from the binary (byte-for-byte test green). - verify_w8_fw_universalaction.rs: nonblank 261 (252 C++ + branchflip + gotoreduce + 7 headers); list_action_decompile_oracle.txt re-numbered for the branchflip + gotoreduce leaves (byte-equal test green). - xml.rs corpus count 139->140 (83 datatests + 57 stage tests). - kuna-catalog.xml: source_decompiler=angr 13, structure-recovery 7, opt-in-tool 9. - PROGRESS.md: union both session sets. No DIV entry (opt-in/default-off; output byte-identical when off). Regenerated docs/assertions.md + docs/baseline-stages.json (183/183). Gates: kuna catalog --check OK; make test PARITY OK 675/675; make test-stages PARITY OK 183/183. docs/baseline.json untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
Follow-up on PR #59's reviewer note (tee_O2 :: setlocale_null_androidfix): "why are we not returning the setlocale call? Why is our function type wrong? It should be char*." Two independent defects sat behind that one report. This commit fixes the clean, parity-safe one; the other is a documented larger follow-up. Defect 1 (FIXED) - missing libc prototype. kuna's ApplyDataArchiveAnalyzer analog (kuna-analysis::s1_protos, the built-in LIBC prototype table) had no setlocale entry, so the call's result was an untyped undefined8: `category` came out `unsigned long` not `int`, the NULL `locale` arg rendered bare `0`, and main's setlocale(LC_ALL,"") idiom rendered setlocale(6,0x6dc1) (string literal lost). Fix: one row, `char *setlocale(int, const char *)`. The pass already parks the PrototypePieces on the callee and ActionDefaultParams types the callers. Now main -> setlocale(6,""), the NULL arg -> (char *)0x0, and any wrapper that keeps the result alive returns char*. Parity-safe (0/675), default-on, DIV-11, no option flag (like every other LIBC entry). Defect 2 (NOT fixed; follow-up) - a tail-position `return F();` compiled to `call F; ret` (or the -O2 tail jmp PR #59 recovers) with no intervening use of the return register leaves the wrapper `void` + bare `return;` and drops the call output. This is GENERAL (reproduces with `return strchr(s,c);` and any already-typed libc fn, NOT prototype-related) and is a faithful port of Ghidra's AncestorRealistic killedbycall rejection. A fix is a new return-recovery heuristic (output-changing, own option/ablation) entangled with PR #59's artificial RETURN; documented in docs/features/setlocale-rettype/analysis.md. Tests/gates: unit s1_protos::tests::setlocale_signature_is_char_ptr_int_char_ptr; stage tests/stages/ghangr-setlocale-rettype.xml (NULL arg types (char *)0x0, call resolves to named setlocale, vs pre-fix bare 0; parse line stands in for the analysis-tier seeding the stage harness does not run). make test PARITY OK 675/675, make test-stages 179/179 (+3), make rust-test green (corpus file-count bumped to 139 in kuna-base/src/xml.rs), kuna catalog --check OK. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tee-o2-tail-jumps: recover -O2 tail jumps as tail calls (
option tailcalljump)Closes the gap where angr's decompiler beats kuna on
test_decompiling_tee_O2_tail_jumps :: setlocale_null_androidfix(
binaries/tests/x86_64/decompiler/tee_O2, x86-64 PIE,-O2).See
docs/features/tee-o2-tail-jumps-4a1f49/analysis.mdfor the full analysis.
The gap
At
-O2, a leaf function whose last act is "call X; return" is compiled to a directtail jump -
jmp Xinstead ofcall X; ret. When X is an external symbol the jumptargets the PLT thunk:
kuna's flow follower runs with the whole address space in-bounds, so it treats the direct
jmp setlocale@pltas ordinary intraprocedural flow and follows it into the PLT thunk.The thunk's body is
jmp qword [rip+GOT](an indirect jump); jump-table recovery fails onit, so it is rewritten to a
CALLINDthrough the GOT pointer plus a"Treating indirect jump as call"warning. The thunk got inlined instead of thejmpbeing recognized as a tail call, so the callee renders as
(*dat_209f68)(...)rather thanthe named
setlocale.The mechanism
A new S2 flow-classification predicate
kuna_is_tail_call_branch(
decompiler/crates/kuna-decomp/src/s2_lift/kuna_tailcalljump.rs, ElementId 4100), modeledexactly on the existing
kuna_v850indbranchfeature (aFlowEnvironmentpredicate consultedinside
xref_control_flow, gated by an Architecture bool flag). In theCPUI_BRANCHarm ofFlowInfo::xref_control_flow, when the option is on and a direct branch's target is the entryof another known function (
query_call(dest).is_some(), which includes PLT thunks) and not thefunction's own entry, the
BRANCHis rewritten to aCPUI_CALL+ an artificialRETURN(thein-file
truncate_indirect_jump/setup_callind_specshalt-insert idiom), instead of flowinginto the callee. The callee then resolves by name and the spurious warning / GOT-pointer
indirect call are gone.
(The remaining
void/return;vs angr'sreturn setlocale(...)is an S4return-value-recovery concern - the option-OFF path is also
void, so it is inherent tokuna's wrapper-return recovery, not introduced or fixable by this S2 change.)
The option
option tailcalljump on|off(default off, default-pipeline byte-identical). Flip perdecompilation:
It is LLM-discoverable via
kuna catalog --json(provenance:source_decompiler=angr,change_kind=structure-recovery).Ablation / parity / speed
make testPARITY OK (675/675),make test-stagesPARITY OK (162/162).Long double #1/#2), so thefeature ships default-OFF opt-in (no DIV entry).
setlocale_null_androidfix, median of 5): off 259.0 ms / on 264.9 ms (+2.26%,within the 5% budget).
tests/stages/ghangr-tee-o2-tail-jumps-4a1f49.xml(pass 1 off provesthe bug; pass 2 on proves the fix).
🤖 Generated with Claude Code
Before / after —
setlocale_null_androidfixintee_O2Real captured kuna output on the function this feature was built for, with
option tailcalljumpflipped. Ported from angr — test_decompiling_tee_O2_tail_jumps; angr tail-call handling (direct jmp to a function/PLT thunk); setlocale_null_androidfix.tailcalljump off(default)tailcalljump onkuna — before (
option tailcalljump off)kuna — after (
option tailcalljump on)angr reference (the goal, v9.2.213)