Skip to content

[AUTOMATED] fix(p4): a tail call's result yields to a float the function computes itself - #772

Merged
mahaloz merged 1 commit into
mainfrom
fix/passthrough-float-return
Sep 30, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/passthrough-float-return

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #752.

Problem

A function that calls something and then computes a float return value is decompiled as returning the callee's integer result, and its float parameter disappears. #752 made this happen on hard-float ARM and MIPS; x86-64 and AArch64 have done the same since passthrough became the default.

cat > f.c <<'EOF'
extern int counter;
__attribute__((noinline)) int ise(int x) { counter++; return x * 3; }
float float_after_i(int x, float y) { ise(x); return y * 2.0f; }
EOF
clang --target=armv7a-linux-gnueabihf -mfloat-abi=hard -mfpu=vfpv3-d16 -O2 -c f.c -o f.o
decompiler/target/release/kuna decompile-all f.o
// Function: float_after_i @ 0x400020
int float_after_i(int a0)
{
  return ise(a0);
}

gcc -O2 -fno-ipa-ra -c f.c on x86-64 prints the same (call ise; movss 4(%rsp),%xmm0; addss %xmm0,%xmm0; ret), and so do AArch64 and MIPS builds of it.

Fix

  • passthrough only hands back a tail call's result when the function returns nothing of its own. Once the return trials are scored, it runs the output model over the trials it does not own, which gives the return value the function would have with passthrough off. If that value is in another storage class (s0, xmm0, $f0 against r0, rax, $v0), the claim is dropped. The example now prints float float_after_i(float a0,int a1) { ise(a1); return a0 + a0; }. That is the pre-[AUTOMATED] fix(p4): passthrough hands back an ARM or MIPS wrapper's call result #752 output, and it is the same with armfloatreturn on or off.
  • A register of the same class, like the r1 in bl g; mov r1,#0, can be the rest of the claimed value, so it keeps the claim.
  • A value that is zero at every RETURN keeps the claim too. -fzero-call-used-regs writes zero into every call-used register a function does not return in, so openssh's sshkey_certify ends call ...; pxor %xmm0,%xmm0; ret, and it still returns its int. The cost is that g(); return 0.0; keeps the callee's result, as it does today.
  • There is no new option. This is a bug fix inside passthrough's own rule.

Tests

  • kuna-cli/tests/passthrough_own_return.rs builds ARM, x86-64, AArch64 and little- and big-endian MIPS objects inside the test. It fails on main at the first ARM function.
    • The failing cases are a float computed after the call on every architecture, a float constant loaded after it (ARM, with armfloatreturn off and on) and an x86-64 double.
    • The controls keep their callee's result: a plain wrapper on every arch, the ARM r1 write, and an x86-64 forwarder that ends in the zeroing epilogue.
  • Base vs head decompile-all changes no function over the 274 ELF fixtures and 562 debug-stripped decbench binaries: 98 ARM firmware images at O0, O2 and O2-noinline, also run with armfloatreturn on, and 464 x86-64 binaries at O2 and O2-noinline. Without the zero rule, the nine copies of openssh's sshkey_certify in that set became return 0;.
  • Datatests and stages are unchanged, and arm_wrapper_returns.rs and the passthrough-* CLI probes pass unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG

…ion computes itself

passthrough's tail-return rule handed a call-then-return function its
callee's integer result whenever the function never touched the integer
return register. A function that computes its own float return after the
call (ARM `bl g; vadd.f32 s0,s16,s16; pop {r11,pc}`, x86-64 `call g;
addss %xmm0,%xmm0; ret`, AArch64, MIPS `add.s $f0,$f0,$f0`) was printed as
`int f(int a0) { return g(a0); }` and lost its float parameter. #752 made
ARM and MIPS reach this through the injected `r0 = r0` / `v0 = v0`; x86-64
and AArch64 had it since passthrough became the default.

Once the return trials are scored, the claim is dropped when the output
model, run over the trials the claim does not own, derives a return value
in another storage class. A same-class register (the r1 of `bl g; mov
r1,#0`) and a value that is zero at every RETURN (the -fzero-call-used-regs
scrub in openssh's forwarders) keep the claim.

Test: kuna-cli/tests/passthrough_own_return.rs (ARM, x86-64, AArch64,
MIPS LE/BE objects built in the test; ARM also with armfloatreturn on).
Base vs head decompile-all changes no function over 274 ELF fixtures and
562 debug-stripped decbench binaries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TzSHsg8KAakpogyVw5dtjG
@mahaloz
mahaloz merged commit ea7f659 into main Sep 30, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/passthrough-float-return branch September 30, 2026 05:48
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