Skip to content

[AUTOMATED] Pass a call's result on to the tail call that reads it - #1908

Merged
mahaloz merged 8 commits into
Noelo-Lab:mainfrom
sjkim1127:fix/tail-callee-result-forwarding
Nov 23, 2026
Merged

mahaloz merged 8 commits into
Noelo-Lab:mainfrom
sjkim1127:fix/tail-callee-result-forwarding

Conversation

@sjkim1127

@sjkim1127 sjkim1127 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

A function that calls h and then tail-calls g with h's result (AArch64 bl h; b g, which is return g(h(a0))) drops the link between them: h's result is discarded and g is called with nothing, while the function returns g's result.

kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/macho_arm64e_auth _tail_auth
int _tail_auth(int a0)
{
  _helper(a0);
  return _helper2(); // tail-call
}

_helper and _helper2 each take an int in w0 and return one. decompile-all prints the same two calls.

The fix:

  • passthrough also claims a register at a call whose previous direct call's callee states its result in that register, when the later callee's stated parameter lies inside it. Heritage then links the read to the earlier call's output, which becomes that call's result.
  • A single-function decompile (and a narrowed decompile-all) now also states the callee just before each tail call to a callee that takes a parameter, within the existing budget of four, so the earlier call's result is known there too. A tail call that takes nothing, such as __stack_chk_fail, adds nothing.

Now:

int _tail_auth(int a0)
{
  int v1; // w0

  v1 = _helper(a0);
  return _helper2(v1); // tail-call
}

Tests: tests/stages/kuna-protoorder-tailcallees.xml gains two _tail_auth passes (passthrough off keeps the argument-less calls, the default pins the chain); kuna-ptrauthtrap.xml's _tail_auth assertions now pin the arguments. Whole-binary decompile-all of macOS less (arm64e) is byte-identical at the same cost; a --limit 500 run costs 1.3% more instructions on less and 0.1% on zip, and the 64 changed lines move toward the whole-binary output.

🤖 Generated with Claude Code

Model: claude-opus-5-5

AArch64 `bl h; b g` is `return g(h(a0))`, but kuna printed
`int f(void) { h(); return g(); }` for a single function (and
`h(a0); return g();` in decompile-all): the tail call returned a value
computed from no argument.

passthrough now also claims a register at a call whose previous direct
call's callee states its result there, when the later callee's stated
parameter lies inside it; heritage links the read to the earlier call's
output.  The protoorder single-function bootstrap also states the callee
just before each tail call to a callee that takes a parameter, within the
existing budget of four.

Automated change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sjkim1127
sjkim1127 force-pushed the fix/tail-callee-result-forwarding branch from f1577fb to 79e8d98 Compare November 23, 2026 13:02
mahaloz and others added 4 commits November 23, 2026 13:35
…tailcallees stage comment

Since the forwarded-register change merged, a single-function decompile
already passes a0 to _helper; what it still lacked was _helper's result at
the tail call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…ee's first register is one the function never touches

The single-function and narrowed drive stated the callee before every tail
call to a callee with a parameter. The result can only be handed on when the
tail callee's first parameter register is untouched by the function (the
passthrough claim's own precondition), so elsewhere, e.g. every x86-64
integer tail call, the extra statement only retyped the rest of the function,
and in a narrowed batch it carried over to later functions. Gate the feeder
statement on that precondition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed on top of 79e8d98: c124a2a (docs), 30b4bc0 (a narrower feeder statement), and two merges of current main (5f4505f, 12c8676). Only docs/baseline-stages.json conflicted; I resolved it by keeping both sides' assertions.

What changed in the drive. The single-function and narrowed drive stated the callee before every tail call to a callee with a parameter. That callee's result can only be passed on when the tail callee's first parameter register is one the function never touches, which is the claim's own precondition. Everywhere else, including every x86-64 integer tail call (call h; mov edi,eax; jmp g), the extra statement only retyped the function. In a narrowed batch it also carried over to later functions. 30b4bc0 states the feeder only when that register is untouched. _tail_auth and the new stage passes are unchanged.

Measured on decompile-all --sort addr --limit N-1 (a narrowed run) against DWARF:

  • Before the change: 8-18% of functions changed on gcc-12 sqlite builds (AArch64, Thumb, PPC32), with no result passed on. These included arguments lost relative to DWARF (Thumb sqlite3ReadSchema(a0) became sqlite3ReadSchema() at 6 sites, AArch64 jsonInsertIntoBlob went from 4 arguments to 3) and invented ones (AArch64 clang gzip warning(a0) became warning(a0..a7)).
  • After: 0 argument-count changes on those binaries. The feeder recoveries per run drop from 19 to 0 (dash) and from 63 to 0 (sqlite).

Whole-binary decompile-all is unaffected: 0 of 51,580 functions change across decbench DWARF builds, 907 fixture images and the gcc sqlite/zlib builds. The 21 chain call sites in a small AArch64/PPC32/x86-64 test (return g(h(a)), vg(h(a)); vv();, gd(hd(x))) all match DWARF, with 0 invented. Main's spelling of _tail_auth in spec 04 and the stage comment is also updated, since main already passes a0 to _helper.

@mahaloz
mahaloz merged commit 0c89748 into Noelo-Lab:main Nov 23, 2026
2 checks passed
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.

2 participants