Repository navigation
[AUTOMATED] feat(analysis): resolve printf/scanf format strings at load time so formatstring can be on by default - #673
Merged
Merged
Conversation
mahaloz
force-pushed
the
feat/formatstring
branch
4 times, most recently
from
September 19, 2026 13:11
ba4f924 to
4130b00
Compare
…ad time (formatstring static) Squash of the formatstring branch (rounds 1-3) before the round-4 rebase. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
C11 7.21.6.1p7: l has no effect on a floating printf conversion; for scanf it selects a double destination. Ghidra's longLengthModification fell through to unsigned long, which moved the double out of its register and added phantom parameters once the typing was on by default. %lp is a void pointer. (docs/baseline-stages.json is main's until it is re-recorded.) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… hard-float Passes 15-20 load fmtlf_x86_64 and fmtlf_armhf (one source, gcc -O2 / -marm). The round-3 build fails 8 of the 9 new assertions. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…writes the format first A MIPS or SPARC call runs its delay slot before it transfers, so a format register set there is invisible to the backward window; the site (and a gettext hop) is declined. Also moves the ghidra_sim test's inline note into its header. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…argcount compares argument class Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…argcount over 325 binaries Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…count classes) and PR body draft Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… on LLP64
Win64 has a 4-byte long and 8-byte pointers, so %zu/%zd/%td/%tu sized as a
long kept only the low half of the argument: printf("%zu\n", (n << 32) | 5)
decompiled to printf("%zu\n", 5) and the caller lost its parameter. The
conversion is now the int, long or long long as wide as a pointer. Adds an
LLP64 unit test and a Win64 PE32+ stage pass (fmtzu_pe_x86_64, passes 21-23).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…h; the known limits kept Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…p, typesweep and speed on 75f832e) and a shorter PR body Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ument count; Thumb sites are declined argcount.py now compares the argument count of every non-format call in a changed function (paired per callee in order, a reordered body is not a change) against the callee's own decompiled arity. The spec and analysis say that a Thumb call site's window does not fold, so Thumb code renders as off. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… every target the vararg rule admits A closed format prototype also changes how P4 scores the argument trials of the calls around it. On AArch64 and ARM32 firmware that added more wrong arguments to neighbouring calls than it removed (an x8 of 0 ahead of the real arguments; iproute2 ip's parse_rtattr losing its len), while on x86 every such change removed a phantom. static now resolves at load on x86 only; full still resolves on every target VarargAbi admits. Stage passes 24-26 pin AArch64 default == off and full typed; #13/#19/#23/#28 pin ARM the same way. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…e round-6 neighbouring-call counts Spec and analysis explain how a closed format prototype moves the argument trials of neighbouring calls, with the per-corpus counts (x86-64: 8 moved, all phantoms removed; AArch64/ARM32 firmware: 24 moved, 19 wrong). argcount.txt is the round-6 sweep with a verdict on every moved call. PR body draft updated. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…d ARM, and the post-change verification Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ghbouring-call counts, typesweep and speed on d6c5862) and PR body Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ail through trial scoring A closed format prototype stopped claiming the stack slots it used to take as phantoms, so later calls whose format is not resolved took them instead (gnulib version_etc in /usr/bin/m4: three __fprintf_chk calls 9 -> 12 arguments). The override is now installed as a locked prefix plus ..., scored like the open call, and the tail is shed once no call has trials left. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…arguments when the version line is typed fmtvalist_x86_64 (gcc -O2 -flto) passes 27-29: off keeps the version line's three va_list phantoms, the default and full drop them, and no switch call takes the va_list's slots. The round-6 binary fails #31 and #32. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… arguments through fillinMap; pin the outgoing-slot cases A ninth double goes on the stack behind the four integer registers a "%f ... %d" call leaves unused, and fillinMap's positional rules ended the open-tail call's list there, so the audit withdrew the override. The declared (fixed-position) trials are now kept active. fmtslots_x86_64 (clang -O2) passes 30-32 pin show9's nine doubles and two sscanf destinations in the first outgoing stack slot, which the closed prototype folded to the value stored before the call (return 6; return 0;). The round-6 binary fails #31-#36. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
… and the catalog; scope the neighbouring-call claims Spec 04 describes kuna_formattail (open tail, declared trials kept, shed after the last call finalizes). Spec 01, the reached_by_default doc and the phases.toml row no longer say x86 only ever removed phantoms: closed from the start, x86 calls whose format is not resolved gained phantom stack arguments (m4 version_etc 9 -> 12); with the open tail the 8 neighbouring calls that move over 350 x86-64 binaries all lose one. analysis.md adds the Ubuntu /usr/bin corpus (25 binaries: 115 fixed / 0 new) beside decbench (313 / 0), and the audit's alloca withdrawals (130 -> 0). options.md and phase_catalog.json regenerated. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…r/bin corpus, typesweep and speed on d6c5862), PR body, alloca notes record.json round7: m4 root cause and fix, the clang push-rax fold the closed install hid, stage passes 27-32, decbench 313/0 and Ubuntu 115/0, audit withdrawals 130 -> 0, typesweep 988 -> 1026 (176 better / 0 worse), speed min-of-15 vs main fmt -4.6 ls +0.8 sort -0.4 m4 +0.7. argcount-ubuntu.txt holds the Ubuntu argcount rows. The fmtjoin alloca notes say the site is kept now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
…ges baseline on 3831d70 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz
force-pushed
the
feat/formatstring
branch
from
September 19, 2026 17:40
359fcbb to
b6c0d00
Compare
mahaloz
added a commit
that referenced
this pull request
Sep 19, 2026
…ain 60/60, typesweep 1,026 -> 1,147, arity equal Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
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.
The problem
A
printf/scanfcall states the types of its variadic arguments in itsformat string, and the default output ignores it. Reading the string was
already possible (
--option formatstring on), but it cost a second decompile ofevery caller, +43% to +77% on a whole binary, so it stayed off.
With this change the default prints
main(int a0,unsigned long *a1)andprintf("%d %s\n",a0,(char *)*a1);.The fix
formatstringbecomesoff|static|full, defaultstatic(onstill meansfull).staticreads the format constant out of the image at load, from theListing's call and tail-jump edges and a short constant fold before each call,
and hands the per-call prototype to the first decompile.
fullkeeps the oldsecond-decompile loop for the sites
staticcannot answer.char *justbefore the
..., soerr/warn/error/syslogcount too. A format thatcomes out of
dcgettextis read through its msgid.exactly like the untyped call and drops what it took past its declared
arguments only once every call in the function has its arguments, so the
calls around it keep what
offgives them. Installed closed, it freed thestack slots it used to claim, and calls whose format is not resolved took
them (three
__fprintf_chkcalls in Ubuntu m4'sversion_etcwent from 9to 12 arguments); it also let a clang
sscanf("%d", &a)destination in thefirst outgoing stack slot fold to the value stored before the call.
function decompiled once more, when the call's format is not the resolved
string (a join reached from a jump table) or its argument count disagrees.
same value at a neighbouring call. On x86-64 the 8 calls this moved all lost
a phantom; on AArch64 and ARM32 firmware (measured with the prototype
closed) it gave calls an
x8of0or leftover registers and cost iproute2ip'sparse_rtattritslen.fullstill types those targets.named argument: every conversion on x86 and standard AArch64, integer and
pointer conversions on ARM32, RISC-V, MIPS, PowerPC and Windows AArch64,
nothing on Apple AArch64 or an unchecked processor.
instruction writes the format register itself (a delay slot) is declined.
the caller;
%cis a char and%lcawint_t;%lfis adouble(adouble *for scanf);%zu/%tdare pointer-width, so 8 bytes on Win64where
longis 4;%Lfdeclines the site.The tests
tests/stages/kuna-formatstring-static.xml, 32 passes and 38 assertions:off, default and
fullonfmt_x86_64, the jump-table/allocasites,%lfon x86-64 and ARM hard-float, a Win64 PE with
%zu/%td,fmt_aarch64,gnulib's
version_etcshape, clangsscanfdestinations in the firstoutgoing stack slot and a ninth
doubleon the stack, and default == off onApple arm64, AArch64, ARM and a format in
.data. A build that installs theprototype closed fails 6 of the last 10.
type_matchover 444 slices (x86-64): 988 → 1026 perfect, 176functions better, none worse.
decbench and 25 Ubuntu
/usr/binx86-64 binaries (81,955 functions): noformat call newly disagrees with its format (428 stop disagreeing), no call
whose format is not resolved gains an argument, and the 8 other calls whose
argument count moved all lost a phantom. With
formatstring off, and onevery non-x86 target by default, the output is byte-identical to main.
decompile-allmin-of-15 against main:fmt-4.6%,ls+0.8%,sort-0.4%,
m4+0.7% (againstoff: +1.2%, +1.2%, -0.7%, +1.1%).🤖 Generated with Claude Code
https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG