Repository navigation
[AUTOMATED] fix(p2): tail-call a veneer whose only target is another function - #793
Merged
Merged
Conversation
mahaloz
force-pushed
the
fix/arm-veneer-bound
branch
from
October 1, 2026 19:07
1f5c529 to
618637b
Compare
mahaloz
force-pushed
the
fix/arm-veneer-bound
branch
2 times, most recently
from
October 1, 2026 22:09
0e19b9b to
91d06b2
Compare
…or lies outside its extent An ARM veneer that jumps through a read-only literal (`ldr r1,[pc]; bx r1`, `ldr pc,[pc,#-4]`, Thumb `ldr r1,[pc]; bx r1`) recovered as a one-entry jump table, so the follower walked into the callee as a one-case switch. With the veneer's exact extent declared, the callee lay outside it and the case became halt_missing() under a "flows out of bounds" warning. Under `option tailcalljump on` (the default), a recovered table whose only destination is another known function's entry becomes a tail call, rewritten exactly like a direct `b f`, when the callee's prototype is input-locked or the destination lies outside the declared extent. A callee with no prototype inside an open extent keeps the copied-in body, which states the return value and arguments a call to it could not. The register the jump read its target from is recorded on the call spec and never recovered as an argument. `option tailcalljump direct` keeps direct-jump tail calls and restores the flow into a veneer's destination. Fixes #781 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017cAUeUBnQ9xRA9oRJNGWjw
…eaches the caller A callee prototype parked as pieces (DWARF, a library signature) now counts as stated, as it does at the call site. Inside an open extent a callee that returns a value is tail-called only when the caller's own output is stated: an unstated caller output never takes a tail call's return value and would print void where the copied-in body returns it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…d say why in the spec Adds ret_veneer to the stage test (an open veneer to a declared helper with no prototype of its own keeps the copied-in body in both passes) and two CLI cases, and rewrites the option text and the chapter 02 prose for the narrowed condition. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…wn return, not void A prototype parked from a demangled C++ name states the arguments but not the return type, so the veneer gate read it as `void` and printed a tail call that dropped the callee's return value. Only a stated `void` return now says the callee returns nothing, and only parked pieces that name a return type or storage (or a locked output) say the veneer's own output is stated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…veneer's return unknown Spec chapter 02 and the tailcalljump row now say that only a stated `void` means the callee returns nothing, that cppsig's demangled signatures leave the return unknown, and that the rule also reaches x86 `-fno-plt` GOT jumps and read-only function-pointer slots. The stages baseline is re-recorded on the new base (+9 VENEERTAILCALL keys only). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…d base Re-recorded on origin/main ffb97ef plus this branch: the 9 VENEERTAILCALL keys are the only additions, none removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
force-pushed
the
fix/arm-veneer-bound
branch
from
October 1, 2026 23:29
91d06b2 to
5e31e88
Compare
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.
An ARM veneer that jumps through a literal to another function (
ldr r1,[pc]; bx r1) is decompiled as a one-caseswitchthat walks into the callee. If the veneer's exact extent is declared, the callee is outside it, and the transfer turns intohalt_missing().With
function 0x02000000=veneer(no end) you get the sameswitchwithreturn value + 1;copied in fromarm_helper. With this PR both printreturn arm_helper(value); // tail-call.Fix
b f: a call, then a return (or the callee's no-return halt), marked// tail-call. The register that held the target is never taken as an argument.halt_missing()), or the callee's prototype is stated (declared, DWARF, a library signature, a demangled C++ name) and its return value reaches the caller, because that prototype states avoidreturn or the caller's own output is stated. kuna's return recovery never takes a tail call's result, so without a stated output the call would printvoidwhere the copied-in body returns the callee's value; those veneers keep the body.void. That is what a demangled C++ name gives (_Z3addiistates(int,int)and nothing about the return), so a C++ veneer or long-call stub keeps its body unless DWARF or a declaration states the return.-fno-pltjmp *GOTand a jump through a read-only function-pointer slot into a tail call, e.g.switch(0x1100){ case 0x1100: return a * b + 7; }becomesreturn g(a,b); // tail-call.option tailcalljumpgains a value:directkeeps direct-jump tail calls and restores the old flow into a veneer's destination.onstays the default.What it does not fix:
switch(0x...)(RuleSwitchSingleis a stub).void veneer(unsigned int a0) { arm_helper(a0); return; }, exactly as a directb arm_helperthere already prints.Tests
tests/stages/kuna-veneer-tailcall.xml: two passes (direct, thenon) over A32ldr/bx,ldr pcand Thumb veneers, bounded and open, with and without prototypes. Thedirectpass reproduces the bug; on the unpatched tree the file errors on the new option value, and withoffsubstituted 5 of its 9 assertions fail.kuna-cli/tests/arm_veneer_tailcall.rs: the issue's CLI path on generated ELFs, including the open veneer with no output of its own (keepsreturn a0 + 1;), a helper declaredvoid(tail-called), and veneers_Z3veniiandven_cinto_Z2g2ii, which keepreturn a0 + a1;as on main.decompile-allbefore and after on 109,815 functions in 258 binaries: 225 ARM firmware ELFs from the decbench corpus at O0/O2/O2-noinline (130 with DWARF, 95 stripped) plus 33 x86-64 DWARF builds. 20 functions changed, all in ARM DWARF builds: libopencm3_usbd_standard_request_{device,interface,endpoint}, FreeRTOSHardFault_Handlerand NuttXirq_dispatch. Each copied-in callee body became a call with the callee's DWARF arguments, e.g.return usb_standard_set_address(usbd_dev,req,buf,len); // tail-call, and each matches the source. No stripped binary changed, and none of those 33 x86-64 builds has a one-target jump to another function. 14 x86-64 C++ binaries and libraries from /usr (libsnappy, libpcrecpp, libgmpxx, pdfunite, ...): 0 of 1,381 functions changed. Small C++ builds with g++ and clang++ (x86-64-fno-pltshared libraries, ARM and Thumb-mlong-calls): every veneer whose return is known only from its mangled name is unchanged from main; with DWARF on the veneer,return add(a,b); // tail-callandvsink(p,a); // tail-call, matching the source.decompile-all, interleaved against main: cdcacm.elf 0.509 s to 0.412 s (min of 21, fewer copied-in bodies), RTOSDemo 1.017 s to 0.971 s and libpcrecpp 0.592 s to 0.592 s (min of 11), x86 gzip 5.93 s to 5.86 s (min of 21).Fixes #781
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU