Skip to content

[AUTOMATED] feat(p4): drop a trailing register argument a call clobber put there - #652

Merged
mahaloz merged 10 commits into
mainfrom
feat/phantomargs
Sep 17, 2026
Merged

mahaloz merged 10 commits into
mainfrom
feat/phantomargs

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

The problem

kuna hands a call an argument nobody passed. The caller below clobbers rdx on
one path and leaves an idiv remainder in it on the other, and target gets a
third argument built out of the two:

$ cat t.s
.globl _start
caller: push %rbx;  mov %rdi,%rbx;  test %rsi,%rsi;  je 1f
        call clobber;  jmp 2f
1:      mov %ebx,%eax;  cltd;  mov $200,%ecx;  idivl %ecx;  mov %eax,%ebx
2:      mov %rbx,%rdi;  mov $5,%esi;  call target;  pop %rbx;  ret
clobber: call helper; ret
target:  push %rbx; mov %rdi,%rbx; call helper; mov %rbx,%rax; pop %rbx; ret
helper:  ret
_start:  mov $1,%rdi;  mov $3,%rsi;  call caller;  ret
$ gcc -nostdlib -static -o t.elf t.s
$ kuna decompile-all t.elf --addr 0x401000
void sub_401000(unsigned long a0,long a1)
{
  ...
  else {
    v3 = (long)v1 % 200 & 0xffffffff;          <- the idiv's other half
    a0 = (long)v1 / 200 & 0xffffffff;
  }
  sub_401031(a0,5,v3);                         <- three arguments
}

In the field it costs a whole variable chain. coreutils fmt -O2 calls one
static function three times with three different arities, the longest reading two
// rdx locals that are assigned nowhere, against a DWARF prototype of two
parameters.

The register is a possible output location of the callee's model, so
Heritage::guardCalls plants an INDIRECT creation for it, AncestorRealistic
answers realistic and records isIndCreateFormed, and every active trial is
marked used. Upstream reads that bit back on the return list only
(ParamListStandardOut::fillinMap, fspec.cc:1721) — the input list has no such
test, which is why stock Ghidra emits the same call and names the phantom
extraout_RDX.

The fix

  • New option argclobber (P4, default off): score the trailing register
    argument no-use when nothing on the caller's side put a value in its register.
  • Eight clauses keep it off a real argument. Three carry the weight: every
    indirect creation feeding the trial has to be a creation of the argument
    register itself
    (a preceding call's result is an indirect creation too, so
    a value the caller moved into an argument register is not a clobber); every
    other input of that join
    has to be a division by-product, because one clobber
    among a phi's inputs says nothing about the other paths; and the callee's own
    body must not read those bytes before writing them, which is also what
    answers for a callee kuna never recovered as variadic.
  • Off by default because one shape is still invisible: a callee that really
    returns a 16-byte value in rax:rdx and forwards the high half. It is out of
    AGGRESSIVE_OVERRIDES for the same reason, and because a wrong drop deletes an
    expression rather than producing a visibly odd one.

The tests

Four stage cases: the bug/fix pair above, plus one per guard clause — a callee
that reads rdx, an ARM caller that moves a return value into r3 (u-boot's
printf("… value %u!\n", …) reduced), and a caller that forwards its own second
parameter on the non-clobber path. All three negatives must render the same call
in both passes.

Whole-corpus decompile-all sweep, off vs on, 46 stripped binaries / 41,258
functions across 21 x86-64 projects and 8 ARM images: 4 functions change, each
losing exactly one trailing argument, and all four are the shape above. Each
lands on its callee's own recovered arity and on an external prototype —
fmt(FILE *, char const *) by DWARF, ext2fs_dblist_sort2(dblist, sortfunc) and
xrealloc(void *, size_t) by their headers. The variables[] rows decbench
scores are identical on three of the four; the fourth gains a typed char *
where an uncommitted undefined8 slot was, and no kind: arg row is deleted
anywhere. Details in docs/features/phantomargs/.

Gates: make test 675/675 PARITY OK, make test-stages 1029/1029 PARITY OK,
make test-cli 178/178, make check-spec + --strict, kuna catalog --check,
counters --check clean, make rust-test green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29

@mahaloz mahaloz added full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) and removed full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) labels Sep 16, 2026
@mahaloz
mahaloz force-pushed the feat/phantomargs branch 3 times, most recently from 3c52f42 to 7008707 Compare September 17, 2026 00:48
mahaloz and others added 10 commits September 17, 2026 01:44
…r put there (argclobber)

Rebased onto origin/main (32b2518). Counter sites re-derived on a freshly built
tree, the catalog fixture re-captured and the stages baseline re-recorded rather
than hand-merged.

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

A MULTIEQUAL input that was not an indirect creation was skipped outright, so
one clobber among a join's incoming values condemned the whole join and a value
the caller demonstrably wrote on another path -- a constant, or the caller's own
parameter -- was deleted with it.  Every other input must now be positively
classified as a division by-product, which is the evidence upstream itself
scores this way on the return side.

Re-cuts the positive stage fixture (its non-clobber path wrote `mov $0x7,%edx`,
a value the caller really wrote) onto the fmt witness's real shape: a call
clobber on one path and a dead idiv remainder on the other.  Adds
kuna-argclobber-forward.xml for the parameter-forwarding negative.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…ect the shipped claims

The whole-corpus sweep is re-run on the tightened rule and extended with the
ARM/RTOS family the first one skipped (crazyflie, cleanflight, nuttx, chibios,
freertos) plus gnutls, sysvinit and two -O0 builds: 46 binaries, 41,258
functions, 4 changed functions, all one shape.

Two sentences that the earlier sweep artifact itself contradicted are replaced
by measurements: the variables[] rows are identical on 3 of 4 changed functions
(the fourth gains a typed slot), and the arity claim is re-measured on the sites
that still fire.  The blind-spot disclosure in the spec chapter, phases.toml,
modes.rs and docs/modes.md now names the join as a clause rather than a gap.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…pros

Each builds with gcc -nostdlib -static and is read with kuna decompile-all, so
the positive case and both negative clauses can be reproduced without the
decbench corpus.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…rgclobber text change

catalog_bytecompat pins the `phase catalog` bytes verbatim, so a settable's
summary/use_when text moves it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
fmt main -0.61%, a 1,000-line control -0.05% (min of 21 interleaved pairs).
The +2.03% recorded earlier was the workspace suite running underneath.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…fmain

settables 209 -> 210, tiers (67,80,62) -> (68,80,62), catalog rows 209, stage
corpus 299; phase_catalog.json recaptured, docs/options.md regenerated and
docs/baseline-stages.json re-recorded (1029 keys) rather than hand-merged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
…ebased tree

The corpus sweep is unchanged after the rebase onto elfmain (46 binaries /
41,258 functions / 4 changed), and the default-ON ablation is re-run against the
re-recorded stages baseline: 675/675 and 1029/1029, both PARITY OK.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MAeimyWm5oSewpeCgAwY29
@mahaloz
mahaloz merged commit 74a8892 into main Sep 17, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/phantomargs branch September 17, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant