Repository navigation
Conversation
SparcV9_64.cspec declares the hidden struct-return pointer as a stack entry at 0x7ef..0x7f6, inside every function's own frame. restructure_varnode cleared the prototype's parameter range, that entry included, out of local analysis, so a buffer there (gcc's delimiter[2] at fp+0x7f5) never became a symbol: a call that may write it printed as mutate(&Stack00000000000007f5) and the read after the call returned the value from before it. local_param_range releases the slot only when nothing says the function takes a hidden return: no recorded hidden-return input, no output in indirect storage, no input Varnode read from the slot (an unrecovered prototype has no store yet, so the entry read is the only evidence), and no ordinary stack entry sharing it. Without the entry-read test a prototype-less function that writes through its hidden pointer stored through an uninitialized local instead (ablation). Stage test kuna-sparc64-hiddenret-slot-locals: the buffer case and that control. Stage baseline re-recorded (+6 keys, none removed); make test, test-stages, check-spec, lint, test-cli, rust-test and the kuna-ghidra suite pass.
Regenerated with `kuna test --datatests --datatests-dir tests/stages --save-baseline`; adds only this branch's new stage assertions.
This branch has not been deployed
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.
Problem
SparcV9_64.cspecdeclares the hidden struct-return pointer as a stack input entry at stack0x7ef..0x7f6, inside every SPARC V9 function's own frame.restructure_varnodecleared the prototype's whole parameter range, that entry included, out of local-variable analysis, so in a function that returns no struct, locals stored there were never mapped. GCC places ordinary locals there (char delimiter[2]at%fp+0x7f5, ava_listat%fp+0x7ef).This independent example stores its argument into a one-byte buffer at
%fp+0x7f5, lets a callee update the buffer, and returns the updated byte:Before the fix, the buffer is never declared and the result is the stale argument:
That C does not compile (
Stack00000000000007f5is undeclared), and replacing the symbol with any separate object still returns the value from before the call.Fix
funcdata_spacebase.rs (local_param_range)builds the parameter rangerestructure_varnodeclears. Astorage="hiddenret"stack entry is left out of it only when nothing says the function takes a hidden return pointer: no recorded hidden-return input, no output in indirect storage, no input Varnode read from the slot, and no ordinary stack entry sharing its storage. An unrecovered prototype has no store yet, so the read of the slot on entry is the evidence that keeps a real hidden pointer a parameter.hiddenretentry.After the fix:
(The
[686]extent printed forv1is the separate 32-bit local-range spelling inSparcV9_64.cspec, fixed in #1587.)Tests
kuna-sparc64-hiddenret-slot-locals.xml: the buffer case, plus a prototype-less function that reads its hidden return pointer from[%fp+0x7ef]and stores through it. With the entry-read evidence removed, that control writes through an uninitialized local instead (ablation run on the cluster).sparcv9-linux-gnuand run underqemu-sparc64against a callee that xors the byte with 7, over all 256 inputs: before, the C does not compile; after, every input matches the source at both-O0and-O2.decompile-all, 113 executables, 23,142 functions across amd64, arm64, armhf, i386, ppc32, ppc64, riscv32, riscv64, sparc32 and sparc64; a second base run showed no nondeterministic function): only 13 functions change, all SPARC, all reviewed.error/error_at_line(6 binaries): theva_listat0x7efis now a local; the store of&apinto it, and the two variadic spills that fed only that store, are gone because nothing in the C reads them. Both versions already omitapfrom the call toverror; that missing argument is unchanged.sort: the outgoing struct-return word written throughStack00000040(undeclared before) is now written through a declared local array at the same address.dev-vizneeds full git history and could not run in the cluster's export.arm-none-eabi-gcc,i686-w64-mingw32-gcc; every recompiler available): no change from this PR. Each arm scores 95,698 functions, 80,402 recompilable, 15,296 not, 5,836 perfect, 0 metric errors. The default run reported 6 per-function score differences, but the decompiled C is byte-identical between arms for every binary, so they cannot come from this change. They come from the scorer's wall-clock diff timeout on large functions (inflate,template_parse,ssh_tty_parse_modes, ...). Re-scored with that timeout disabled, every pair has byte-identical original and recompiled machine code and equal scores.Timing:
kuna decompile-all --jsonover each Debian set, from node-local copies, one pinned CPU on an exclusive node, 11 rounds (2 warmups discarded), arm order rotated. Process start and spec loading are included.