Skip to content

[AUTOMATED] fix(p3): calloverlap - complete the two stubbed upstream call-overlap guards (GH-275) - #284

Merged
mahaloz merged 2 commits into
mainfrom
fix/gh275-packedcallarg
Aug 11, 2026
Merged

mahaloz merged 2 commits into
mainfrom
fix/gh275-packedcallarg

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Completes the two partial-range call-overlap guards kuna shipped as comment-only
stubs, behind option calloverlap off|in|full (default off). Filed against
GH-275, which it partly — but explicitly not fully — closes; the issue stays open
and carries the full decomposition as a comment.

GH-275 is three defects, not one

Traced end to end (instrumented Heritage/ParamActive/only_op_use, one-byte
causal ablations on the filed binary, and a re-run of Ghidra 11.4.3 with atan2's
imported signature stripped so both decompilers see the same unknown callee).

Defect Site
A the dropped 2nd argument at the first call Funcdata::only_op_use returning false on its CPUI_STORE arm, substrate/funcdata_varnode.rs:2258-2265 (STORE at :2263) — the argument varnode has a second descendant, the caller's own 16-byte spill
B the 4-byte second argument at the second call heritage refinement + cspec width: movaps is packed-single, four 32-bit lane writes (ia.sinc:7287), so Heritage::refinement partitions XMM1 at 4-byte boundaries and the float pentry is minsize="4"; no re-join because ActionParamDouble is a no-op stub (p4_calls/coreaction_protos.rs:1017)
C the copysign variant's zero arguments the two partial-range overlap guards, p3_dataflow/heritage.rs:1523-1525 (input) and :1470-1475 (output), both comment-only stubs

The obvious hypothesis is dead: in every failing trial AncestorRealistic returns
realistic=true, solid=true. The rejector in (A) is only_op_use, downstream of a
passing realism check.

Upstream calibration: A and B are Ghidra's behavior too

Ghidra 11.4.3 on the unmodified packed_two_atan2 with atan2 stripped to
undefined atan2(void):

  dVar1 = (double)atan2(auVar4._0_8_);            // same dropped 2nd argument
  local_18 = auVar4._8_4_;                        // same 4-byte second argument
  dVar2 = (double)atan2(auVar4._0_8_ ^ _DAT_00102010,local_18);

So (A) and (B) are upstream-faithful, not kuna regressions — Ghidra only gets the
filed binary right because it applies an imported double atan2(double,double), and a
locked prototype makes FuncCallSpecs::isInputActive false, bypassing trial recovery
entirely. (C) is the one place kuna was worse, and it emitted a wrong value, not
merely a missing one.

The trigger is not packed-double, not float, not SIMD

The predicate is any whole-width write to a register holding an ABI parameter or
return entry
: that write blocks Heritage::refinement (gate size > 4 && maxw < size),
so the range stays ContainedBy and the whole-range guards see nothing. In the vendored
ia.sinc, PXOR, POR, PAND, MOVDQA, MOVDQU, MOVQ-to-xmm and ORPD are all
single 128-bit writes (MOVAPD/ANDPD/XORPD are two 8-byte lanes — one byte separates
a working case from a broken one). orpd, the instruction GH-275 was filed on, is 2 of
2,703 occurrences of the shape.

Five lines of plain C at gcc -O2 — no intrinsics, no SIMD, no libm — reproduce it, and
they are the stage test's vector:

double u(double a, double b);
double sink;
double f(long n, double b) { double r = u((double)n, b); sink = r; return r + 1.0; }

The change

decompiler/crates/kuna-decomp/src/p3_dataflow/heritage.rs — three methods ported
verbatim from upstream:

  • Heritage::guard_call_overlapping_input (C++ heritage.cc:1210)
  • Heritage::try_output_overlap_guard (C++ heritage.cc:1249)
  • Heritage::guard_output_overlap (C++ heritage.cc:1293) — not the existing
    guard_output_overlap_stack: the register form makes every piece an INDIRECT
    creation, where the stack form pulls the flanking pieces off a pre-call value.

The input branch of guard_calls is also restructured to upstream's nesting. kuna had
collapsed it to if (ic == ContainsJustified && whichTrial(...) < 0), so a naive
else if for the ContainedBy arm would have fired on a range that is not
ContainedBy whenever a trial already existed. Upstream's else if tests the
characterization alone.

FuncProto::get_biggest_contained_input_param (p4_calls/fspec.rs:5880) ends
return res.size == 0;, which reads inverted — fspec.cc:4482 is literally
if (locktest) return (res.size == 0);. kuna's port is faithful; left alone.

What is closed and what is not

Witness base calloverlap full
gcc_pxor f (plain gcc -O2 pxor) float8 f(void) { u(); sink = v1; return v1 + dat_2008; } (v1 never assigned) float8 f(int8 a0) { sink = (float8)u((float8)a0); return sink + dat_2008; } — exact Ghidra parity
packed_copysign_atan2 atan2(); ... atan2(v2,v2); return v2 + a0; atan2(v6); ... atan2(v6,v3 | v4) + v2 — exact Ghidra parity
two_orpd atan2(); atan2(a0,v3); return a0 + a0; matches Ghidra
real mix void mix(void) { scale(); } void mix(int4 a0) { scale((float8)a0); } (partial)
packed_two_atan2 (GH-275's own binary) 1st call drops its 2nd argument byte-identical — this is defect (A)

The last row is a required negative control and it holds: GH-275's headline symptom is
defect (A), which Ghidra shares, so calloverlap does not close it.

Corpus sweep, both directions

All 268 decbench O2 stripped binaries (231 x86-64, 33 ARM Cortex-M, 4 PE32),
77,014 functions, one kuna decompile-all --json per (binary, arm), every changed
function text-diffed and classified:

base -> in base -> full
functions changed 209 (0.27%) 283 (0.37%), in 62 binaries
new decompile errors / LOSS / timeouts 0 0 (4,024 error-marked functions before and after)
total call arguments +674 +708
call sites gaining args / losing args 223 / 9 240 / 9
zero-argument calls 12.46% -> 12.36% 12.46% -> 12.36%
stops reading a never-assigned local 10 94
starts reading a never-assigned local 12 6
gains 16-byte lane rendering 27 54 (19% of changed)

Per architecture at full: x86-64 217/59,378, ARM Cortex-M 66/17,327, PE32 0/309. A
separate pass over the 20 non-x86-64 kuna-analysis fixtures (aarch64, arm, riscv64,
mips LE and BE, sparc64 BE, ppc64le, i386; 323 functions) changed nothing — so
the big-endian slot_new flip in guard_output_overlap is transcribed from upstream
but remains unexercised by any test I could find.

Hand-audited samples, both directions:

  • find sub_86e0: __fprintf_chk(a0,1," [est success rate %.4g] ") -> the same call
    with (float8)*(float4 *)(a1 + 0x24). The format string is the ground truth.
  • bzip2 sub_3890 (compressStream): void sub_3890(unsigned long a0,void *a1,void *a2)
    -> void sub_3890(void *a0,void *a1) (the real signature is two FILE*), the
    BZ2_bzWriteClose64 call goes 5 -> 7 arguments (its real arity), and the summary
    __fprintf_chk goes 4 -> 5 varargs for 5 conversions.
  • ssh sub_91960, wc/sort physmem_total: sub_X(); return v1; with v1 never
    assigned -> return sub_X();.
  • Against: df/chcon/chgrp/... sub_88c0 renders a formerly scalar float4 v9 as
    char v9 [16] with v9[0] = ...; SUB164(v9,0) lane traffic — faithful, noisier.
  • Against: at 6 call sites a recovered float argument is emitted in slot 0, ahead of
    the format string (log_out((float8)x,(float8)y,a0,"time: %5.2f/%5.2f/%5.2f\n")),
    because build_input_from_trials does not interleave the integer and float
    ParamEntry groups back into source order for an unprototyped mixed call.

GED (scripts.decbench.optsweep, O2, 10 projects, 10,036 scored functions, controls
clean — 9,968 unchanged bodies all scoring identically, 99.8% baseline agreement):
to-perfect 1, off-perfect 0, improved 2 / worsened 5, aggregate dGED +21. Topology is
essentially neutral: GED is blind to arity, and the few movements are the lane-array
if/else expansion adding CFG nodes (find/do_fprintf 29 -> 44) against
gzip/display_ratio 10 -> 0 (perfect) and tar/format_total_stats 77 -> 69.

Speed

Interleaved A/B, alternating arm order per iteration, measuring child CPU time
(getrusage(RUSAGE_CHILDREN)) as well as wall clock — this box is shared with other
agents, and wall clock alone is unusable here.

workload N load CPU delta (min) CPU delta (median)
coreutils/sort decompile-all 21 3 (quiet) +0.26% -1.49%
coreutils/wc decompile-all 25 28 +0.73% +2.92%

Well inside the 5% budget. The quiet-box sort run is the number to trust; an earlier
sort run at N=11 under load 21 returned min -12.65%, which is impossible for a
change that can only add work and is exactly the noise the campaign notes warn about.
Cost is structurally small because the guards fire only on ContainedBy ranges, which
is 0.37% of functions.

Why default off

The flip would clear the repo's stated bar — with the option forced on over every test
file, make test is 675/675 PARITY OK and make test-stages is 411/411 PARITY OK
(a control injection of an invalid value proves the injected command really executes),
there are zero new decompile errors over 77k functions, and the correctness ledger is
94:6 in favour. It is left off anyway because the sweep turned up two ways the
guards make output worse on the functions they touch, both of them pre-existing kuna
defects the guards merely expose:

  1. 54 of 283 changed functions render a formerly scalar XMM read as 16-byte lane traffic.
  2. 6 call sites emit a recovered float argument ahead of the format string.

Neither is visible to any of the four gates. They should be fixed first; then the flip is
a one-line change plus a DIV row, and this PR body is its evidence package. Not added to
AGGRESSIVE_OVERRIDES for the same reason (auto picks aggressive under 500 KiB, which
would make it the de facto default).

in is a bisect level, not a recommendation: recovering the argument without recovering
the return value is net-negative on use-before-def (12 introduced against 10 fixed).

Gates

Run on the rebased tree (origin/main = 11f40f46, funcboundflow), after
re-deriving every shared count from a green build of this tree.

$ make test
cd /home/mahaloz/github/kuna-wt-gh275 && .../target/release/kuna test --datatests --baseline docs/baseline.json
datatests: 675/675 assertions passed
exit: 0

=== baseline parity ===
PARITY OK

$ make test-stages
  --datatests-dir tests/stages --baseline docs/baseline-stages.json
datatests: 413/413 assertions passed
exit: 0

=== baseline parity ===
PARITY OK

$ make check-spec
python3 tools/check_spec.py
check-spec OK (lenient mode)
(and `tools/check_spec.py --strict` -> check-spec OK (strict mode))

$ make rust-test
     Running tests/options_md_fresh.rs
test options_md_matches_the_generator_byte_for_byte ... ok
... 306 `test result:` lines, `0 failed` in every one
EXIT=0

docs/baseline.json is untouched. docs/baseline-stages.json is re-recorded (not
hand-merged) for the six new assertions, 407 -> 413. Shared counts, all derived from
this tree rather than computed: settables 95 -> 97, tiers (20,41,34) -> (21,42,34), stage
corpus files 193 -> 195, the mid-table },\n tally 94 -> 96, and the no-program catalog
fixture regenerated. Two further count sites the plan did not list also needed bumping:
option_values_live_value_present_for_* (calloverlap's live reader is console-side, like
cppsig's, so it belongs in the codegen-suppressed allowlist) and
emit_catalog_json_static_form_brackets_and_commas.

No docs/history.md DIV row: the shipped default does not change.

What remains: spillargtrial (scoping, no PR yet)

Mechanism. GH-275's headline symptom is defect (A). The argument varnode reaching the
call has a second descendant — the caller's own movapd XMMWORD PTR [rsp+0x20],xmm1
spill — so Funcdata::only_op_use hits its CPUI_STORE arm
(substrate/funcdata_varnode.rs:2263) and returns false, check_input_trial_use
(p4_calls/funcdata_callsite.rs:186 -> :196) marks the trial inactive, mark_inactive
sets CHECKED so it is never revisited (:80), and the chain dies to DCE. The candidate
change is to narrow that arm: a STORE whose value operand in(2) is the walked varnode
and whose pointer is a caller-frame stack slot does not set res = false — optionally
requiring a later reload of the same slot into the same register, i.e. a genuine
caller-save spill/reload pair (both GH-275 repros have one; hand-written asm probes
mostly do not, so the two predicates are separable and should be A/B'd).

Risk. This is a deliberate divergence from upstream, not a bug fix — kuna's
only_op_use is byte-faithful to funcdata_varnode.cc:1891, and the blanket STORE
rejection exists precisely to stop a caller-saved value spilled just before a call from
becoming a bogus extra argument. Relaxing it admits non-arguments: any local written to
the frame in the instructions before a call now looks like a parameter. The failure mode
is a spurious trailing argument, which no gate can see (the datatests are
prototype-declared, and GED is blind to arity).

What would have to be measured. The same bidirectional sweep as above, plus: (a) the
spurious-argument rate, by sampling newly-appearing trailing arguments against the
disassembly at both predicate strengths (bare STORE-value vs. requiring the reload);
(b) the arity-shortfall rate against kuna's own recovered callee signatures, which must
fall; (c) the four gates and a speed delta, since the change increases the number of
active trials that survive to buildInputFromTrials. Default-off regardless, and it
needs its own DIV row if it is ever flipped.

Not opened as a second PR: the predicate choice is unresolved and the false-positive
surface is exactly the thing upstream's rule guards against, so it wants its own
measurement round rather than being bolted on here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH

mahaloz and others added 2 commits August 11, 2026 22:31
…call-overlap guards (GH-275)

Squashed from the branch's four commits (the fix, the two catalog-count bumps,
the flip-guidance prose and the post-funcboundflow reconciliation) so the merge
train replays one commit instead of four rounds of the same shared-counter edit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH
…e stages baseline

Rebased onto #278/#281/#283. Every shared counter re-derived from the BUILT
artifact rather than by arithmetic: live catalog 100, phases.toml 100,
catalog_bytecompat.rs 100, kuna_phases/tests.rs 100 / tiers (21, 44, 35) /
`},\n` 99, phase_catalog.json 100 (recaptured), docs/options.md 100
(regenerated), xml.rs corpus 198. `kuna-catalog.xml` structure-recovery stays 25
because calloverlap is a correctness-fix, not a structure-recovery row. Stages
baseline re-recorded on the merged base: 419 -> 425, +6 CALLOVERLAP keys, none
removed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH
@mahaloz
mahaloz force-pushed the fix/gh275-packedcallarg branch from e67f01a to 467fafe Compare August 11, 2026 22:38
@mahaloz
mahaloz merged commit f5b8376 into main Aug 11, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/gh275-packedcallarg branch August 11, 2026 22:43
mahaloz added a commit that referenced this pull request Aug 11, 2026
…e stages baseline

Rebased onto #278/#281/#283/#284. Every shared counter re-derived from the BUILT
artifact rather than by arithmetic: live catalog 101, phases.toml 101,
catalog_bytecompat.rs 101, kuna_phases/tests.rs 101 / tiers (21, 45, 35) /
`},\n` 100, phase_catalog.json 101 (recaptured), docs/options.md 101
(regenerated), xml.rs corpus 199, kuna-catalog.xml structure-recovery 26. Stages
baseline re-recorded on the merged base: 425 -> 433, +8 orchain keys and the #7
text update, nothing removed. DIV-69 re-checked against origin/main immediately
before pushing: main's highest row is DIV-68 (#277), so 69 stands unrenumbered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH
mahaloz added a commit that referenced this pull request Aug 11, 2026
…chain of a short-circuit (DIV-69) (#285)

* [AUTOMATED] feat(p8): orchain - returndup must not split the operand chain of a short-circuit (DIV-69)

DIV-54 flipped `returndup` on evidence from two of the three optimisation levels.
Extended to all three (795 slices / 85,195 scored functions) the pass is +640
GED-perfect corpus-wide but -192 at -O0, and one sub-shape carries essentially all
of that harm and almost none of the optimized benefit: the split that permanently
blocks `CollapseStructure::rule_block_or`.

`returndup` gives every predecessor of a shared bare-epilogue RETURN its own private
return. For a guard clause that recovers the source; but the operand blocks of a
short-circuit expression are predecessors of that same block, and the shared
out-target IS ruleBlockOr's entire precondition. ActionReturnDup runs in fullloop's
`returnsplit` group and collapse_conditions runs later, so the fold is lost for good
and one source `return a || (b && (c || d));` prints as a five-return constant-guard
cascade (iproute2 ip::sci_complete, GED 21 against 0).

New option `orchain on|off` (default ON, DIV-69, ELEM 4122). `kuna_orchain.rs
(shortcircuit_shared_targets)` replays collapse_conditions read-only on the bblocks
CFG, mirroring ruleBlockOr's own admission test rather than approximating it (one
in-edge, two out-edges, not a switch, not BlockBasic::isComplex, a shared out-target,
sibling's other target is not the head), and `returndup_apply` declines the whole
function's splits when one of its own candidates is a recorded target. It also
protects a block joining two or more single-exit arms that are themselves fold
targets, because the first returndup invocation of the fullloop still sees the
constant-materialisation blocks in between.

Sweep over the same corpus (base = shipped defaults at merge-base 82dd39a):
O0 +611 GED-perfect / -2,816 GED, O2 -13 / +1,232, O2-noinline -15 / +617 --
+583 net and -967 aggregate, 781 functions to perfect against 198 off (3.94 : 1).
That is 92% of the +630 the post-hoc "a short-circuit was lost" signal prices as a
ceiling, at a smaller optimized-level cost than the ceiling itself (-28 vs -35).
Predicate fidelity to that signal: 2,933 of 2,951 O0 positives recognised (99.4%
recall) at 126 further firings (95.9% precision); 94.2% of firings reproduce the
`option returndup off` body byte for byte.

Default-ON rather than an `aggressive` preset member because `returndup` is a shipped
default in every mode and 45% of the corpus (38,216 of 85,195 functions, 36 of 795
slices) is over the 500 KiB `auto` threshold and runs `reliable`, where a preset-only
gate never runs -- measured: with the gate in the preset only, the no-option arm
reproduced the ungated body on iproute2 ip (76 functions), bash (366), sshd (201).

675/675 PARITY OK with the raw flip, zero assertion movement and no per-test opt-out;
stages 415/415 with the new two-pass tests/stages/ghdec-orchain.xml; rust-test 4,540
passed / 0 failed; check-spec OK lenient + strict; catalog --check OK. Speed worst
+1.01% (two of four probes are net speedups). Rebased onto #280 (funcboundflow,
DIV-67): every shared counter re-derived from the built artifact on the rebased tree
(97 settables, tiers 20/43/34, xml corpus 195), and DIV-68 was renumbered to 69 after

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH

* [AUTOMATED] chore(p0): re-derive the shared counters and re-record the stages baseline

Rebased onto #278/#281/#283/#284. Every shared counter re-derived from the BUILT
artifact rather than by arithmetic: live catalog 101, phases.toml 101,
catalog_bytecompat.rs 101, kuna_phases/tests.rs 101 / tiers (21, 45, 35) /
`},\n` 100, phase_catalog.json 101 (recaptured), docs/options.md 101
(regenerated), xml.rs corpus 199, kuna-catalog.xml structure-recovery 26. Stages
baseline re-recorded on the merged base: 425 -> 433, +8 orchain keys and the #7
text update, nothing removed. DIV-69 re-checked against origin/main immediately
before pushing: main's highest row is DIV-68 (#277), so 69 stands unrenumbered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mahaloz added a commit that referenced this pull request Aug 17, 2026
…ll (#315)

[AUTOMATED]

GH-275's headline symptom, scoped as defect (A) in PR #284: on x86-64 SysV no
xmm register is callee-saved, so a floating-point value that is both an
argument and live across the call MUST be spilled by the caller - and that
spill is a second descendant of the very Varnode the input trial is scoring.
`Funcdata::only_op_use` rejects on any CPUI_STORE, `check_input_trial_use`
calls `mark_inactive` (which also sets CHECKED, so the trial is never
re-scored), and the argument's producer dies to DCE.

New settable `spillargtrial off|reload|spill`, default off.  At `reload` a
frame STORE stops rejecting only when it writes the walked Varnode's own value
into a caller-frame slot AND a later LOAD reads that slot back at the same
width; at `spill` the reload requirement is dropped.  Since ActionActiveParam
runs before ActionStackPtrFlow the frame reference is still the raw
INT_ADD(sp, #const), and the reload straddles the call that re-defines the
stack pointer, so the search walks forward from the store's own base Varnode
carrying the running offset delta rather than matching raw constants.

This is a deliberate divergence from upstream, not a port repair: the rule it
relaxes exists to stop an ordinary frame store from becoming a bogus argument.
No DIV row - the shipped default does not change.


Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant