Repository navigation
[AUTOMATED] fix(p3): (NOVEL) restore the stubbed RuleSubRight truncation lowering - #251
Merged
Merged
Conversation
…ion lowering
`RuleSubRight::apply_op` (`p3_dataflow/ruleaction_6.rs`, upstream
`ruleaction.cc:7271`) was a port stub: only the leading `doesSpecialPrinting` /
`isPieceStructured` half was transcribed and the body then returned 0 under a
`// Remainder transcribed for the next wave ... W6` comment, so upstream's
`sub(V,c) => sub(V>>c*8,0)` rewrite never ran. Every SUBPIECE with a NONZERO
byte offset therefore reached the printer, which renders one as the raw p-code
operator. `SUB41` / `SUB81` / `SUB84` are undeclared identifiers -- kuna emits
no header defining them -- so those function bodies were not compilable C:
unsigned long sub_4cd60(unsigned long a0,unsigned long a1) // openssh ssh
{ // sshbuf_put_u64
...
*v2 = SUB81(a1,7); -> *v2 = (char)((uint8)a1 >> 0x38);
v2[1] = SUB81(a1,6); -> v2[1] = (char)((uint8)a1 >> 0x30);
...
v2[7] = (char)a1; v2[7] = (char)a1;
Ghidra emits `*local_18 = (char)((ulong)param_2 >> 0x38);` and the source is a
plain shift (`((u_char *)(p))[0] = (__v >> 56) & 0xff;`). The last line of
kuna's own pre-fix pane is the proof the printer was never at fault: the
offset-0 SUBPIECE already rendered `(char)a1`.
The ~45-line tail is now transcribed from `ruleaction.cc:7291-7340`
(GHIDRA_REV=cef869af) with every guard upstream applies, because each one
protects a rendering kuna already gets right: the `c == 0` bail; the
address-tied `overlap == c` bail that leaves ActionCopyMarker's storage markers
alone; and the already-ported `isPieceStructured` special-print branch. Then
the rewrite proper, including the lone-`INT_RIGHT`/`INT_SRIGHT`-descendant
lumping (declining an `INT_RIGHT` whose combined amount would evaluate to zero,
clamping `INT_SRIGHT` to the sign bit). Nothing needed wiring: the rule was
already registered in upstream's own schedule position
(`rrow!("subright", "cleanup", ...)`, `infra/universalaction.rs:552`).
One kuna-side deviation, marked `// (kuna)`: the type-factory availability check
is hoisted above the first mutation, so a hand-built Funcdata with no type
factory cannot leave a half-applied transform behind.
No option. `SUBnn` is an undeclared identifier, so this is a strict correctness
fix, and it restores upstream Ghidra's own behavior from a port stub rather than
making a judgment call -- there is no honest `use_when` prose for a `subright`
option. The switch already exists anyway: `subright` is a registered rule-group
name, so `option togglerule subright off` reproduces the pre-fix rendering for
bisection. An independent decider subagent returned `ungated`; its verdict is
recorded verbatim in `docs/features/subright/record.json`. Recorded in
docs/history.md under Convergences, not as a DIV row -- a port defect whose fix
moves kuna back onto upstream's default earns no DIV row.
Breadth (two release builds of this worktree, stubbed vs ported, 7 whole-binary
`decompile-all --mode reliable` runs over x86-64 -O0/-O2 and ARM Cortex-M;
totals over the 14,720 functions common to both panes, so the 120 s
per-function watchdog cannot move them on a loaded box): nonzero-offset raw
`SUBnn` operators 1,912 -> 95 (95.0%), functions carrying one 733 -> 20, blast
radius 728 functions (4.95%), emitted lines +0.011%. Every one of the 95
residuals is a case upstream's own guards decline: 42 address-tied global-array
stores (round 1's separately-filed `rodata-phantom-store`), 47 address-tied
local partial-symbol writes (the P6 thread that renders `sym._2_2_` upstream),
6 piece-structured field extractions. Measured cost: exactly two functions in
14,720 gain a dead partial-register shift statement
(`(undefined7)((uint8)a2 >> 8)` in bzip2 sub_da00 and one
`(undefined3)((uint4)v11 >> 8)` on ARM) -- the form upstream lowers the same
way; corpus-wide count of that shape 0 -> 2.
GED unchanged by construction on both mined cluster cases (netns_add 8.0 -> 8.0,
applyLedFixedLayers 25.0 -> 25.0): the rewrite changes expressions inside blocks
and moves no block. Rank this by correctness, not by the metric.
Speed (interleaved medians, `decompile-all --mode reliable`): openssh ssh
@0x4cd60 2,307 -> 2,165 ms (-6.16%, 9 pairs), gzip -O0 3,387 -> 3,325 ms
(-1.84%, 7), bzip2 -O2 12,016 -> 11,512 ms (-4.20%, 7), e2fsck -O2 21,378 ->
21,430 ms (+0.24%, 5) -- worst case +0.24%, inside the +5% budget.
Gates (on main @d89a4d95): make test 675/675 PARITY OK (docs/baseline.json NOT
re-pinned); make test-stages 369/369 PARITY OK (baseline re-recorded, purely
additive 361 -> 369 keys, no existing assertion moved); make rust-test green;
make check-spec OK (lenient + strict); kuna catalog --check OK. No catalog
surface is touched -- the diff vs main for phases.toml, src/p0_knowledge/,
kuna-decomp/tests/ and docs/options.md is empty, and the settable-row count
stays at #250's 85. Corpus file count 186 -> 187.
#250's ActionParamCopyHoist is a default-OFF P6 pass and this is a P3 cleanup
rule; confirmed rather than assumed, `decompile-all --mode reliable` with
`--option paramcopyhoist on` vs default is identical on openssh ssh, gzip -O0
and bzip2 -O2 (residual raw operators 0/0 each, subright output shapes 23->23,
12->12, 1->1) and the witness at 0x4cd60 is byte-identical either way. `tests/stages/ghdec-subright.xml` is two-pass
(1 of 8 assertions passes pre-fix, 8/8 post-fix) plus two new rule-level unit
tests pinning the guards that must not be dropped.
Provenance: decbench round-2 triage, case `novel-concat-subpiece-soup`, NOVEL
pool (the CONCAT half of that cluster is disproven as a kuna defect and is not
touched here).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
force-pushed
the
fix/decbench-subright
branch
from
August 3, 2026 08:31
279b922 to
a8af59c
Compare
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round Docs-only. No .rs, no phases.toml, no baselines, no tests. Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist (merged) and #254 peimportcall (IN FLIGHT), each with its measured effect. - Named the structural finding that outlives them: three separate ported passes were dead -- RuleSubRight (stub body), RuleFuncPtrEncoding (live body, stubbed input) and ActionDeindirect (live body, a gate bit set nowhere). Each was invisible to every test and each had large breadth, so "grep for registered-but-unreachable passes" is now a mining route of its own. - Carried forward what did not ship: undefname-leak (283 functions, 221 with uninitialised reads) and catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 381/381 PARITY OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round Docs-only. No .rs, no phases.toml, no baselines, no tests. Rebased onto origin/main 4c2b59b (after #254, #255 and #257). Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md) - Round 2 ran up to four output-changing PRs over the same hard-coded counters and produced three failure shapes, only one of which announced itself: a conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale baseline-stages.json data_footer, and five rounds of keep-both duplicating a row in tests/stages/README.md). - Rules written down: derive every shared counter from a fresh capture and a green run on the rebased tree, never by arithmetic; diff every keep-both resolution against main asserting you removed nothing and added nothing twice; DIV numbers are claimed on merge; re-run the gates AFTER the rebase. - New standing requirement 9: re-measure after every rebase, never carry a number forward. #257's placeholder count moved 2,143 -> 2,142 because #254 landed underneath it, caught only by re-measuring. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the ARM entry-recall sequence (#239). Only three of the nine move GED on a mined case; four are correctness fixes the metric cannot see and two are recall. - The dead-pass finding is now three DISTINCT shapes to grep for, not one anecdote: stub body (RuleSubRight), live body with a permanently-zero input (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a gate bit that has no writer anywhere (ActionDeindirect / externref). The third had a second gap in the same chain -- GlobalEntry::func_no_return never copied the callee's no-return flag into the snapshot -- so one dead gate can hide another. - The ARM sequence is cross-referenced to the live table on PR #239 rather than duplicated here, so it cannot go stale in-repo. - Carried forward as the one still-open candidate: catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates on the rebased base: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz
added a commit
that referenced
this pull request
Aug 3, 2026
…cost this round (#256) Docs-only. No .rs, no phases.toml, no baselines, no tests. Rebased onto origin/main 4c2b59b (after #254, #255 and #257). Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims were provably stale and several hard-won operational facts existed only in agent transcripts. Both fixed, every number re-verified against the live tree. docs/decbench-loop.md - Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20, overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first). Stated plainly that kuna's column is current while the rivals' are from their own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard. - Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary failures, now almost entirely embedded ARM Cortex-M. All three named causes corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact and never a kuna discovery failure (angr and ida score nothing there); "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed (comm/join/timeout/uniq all produce full bodies today). - The `--mode auto` degrades-to-fast warning is moot for this corpus: the largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803 binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs- reliable distinction is kept and sharpened; the stale 21-of-24 default-off count is now 20 of 25, with the five exclusions named. - Two operational traps recorded for the first time: (a) byte_match RECOMPILES with an arch-matched toolchain and this box has neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every rival keeps theirs. The coverage guard caught 34 slices; O2 and O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without reading every [guard] line. (b) The pools store a PE address as an RVA where kuna uses the VA, so scripts.decbench.rescore fails on every PE case (119 across the three pools). Recorded with a fix direction. - Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's published scores for EVERY re-decompiled opt level, not just the one being refreshed (an O0-only baseline died with "cannot reproduce published fallback 58.0" on an O2 slice). Method corrections (decbench-loop.md + improvement-pipeline.md standing rules) - "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the proposed hook reached the printer and it was still the wrong site: it deleted an assignment, lost an early return, and made another function return the wrong parameter. The refute brief now carries an explicit "would this produce WRONG output?" axis. - Diff every changed function, not the witness. Those designs all passed on their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions; two caught real problems that way. - The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in every case. Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md) - Round 2 ran up to four output-changing PRs over the same hard-coded counters and produced three failure shapes, only one of which announced itself: a conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale baseline-stages.json data_footer, and five rounds of keep-both duplicating a row in tests/stages/README.md). - Rules written down: derive every shared counter from a fresh capture and a green run on the rebased tree, never by arithmetic; diff every keep-both resolution against main asserting you removed nothing and added nothing twice; DIV numbers are claimed on merge; re-run the gates AFTER the rebase. - New standing requirement 9: re-measure after every rebase, never carry a number forward. #257's placeholder count moved 2,143 -> 2,142 because #254 landed underneath it, caught only by re-measuring. docs/decbench/features.md - Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors, #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the ARM entry-recall sequence (#239). Only three of the nine move GED on a mined case; four are correctness fixes the metric cannot see and two are recall. - The dead-pass finding is now three DISTINCT shapes to grep for, not one anecdote: stub body (RuleSubRight), live body with a permanently-zero input (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a gate bit that has no writer anywhere (ActionDeindirect / externref). The third had a second gap in the same chain -- GlobalEntry::func_no_return never copied the callee's no-return flag into the snapshot -- so one dead gate can hide another. - The ARM sequence is cross-referenced to the live table on PR #239 rather than duplicated here, so it cannot go stale in-repo. - Carried forward as the one still-open candidate: catalog-upstream-options (38 upstream-inherited ArchOptions invisible to `kuna catalog`). Re-mined pool tables regenerated against the refreshed tree (snapshot 2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json. Gates on the rebased base: make check-spec OK (lenient and strict); make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK. Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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 bug
RuleSubRight::apply_op(p3_dataflow/ruleaction_6.rs, upstreamruleaction.cc:7271) wasa port stub. Only the leading
doesSpecialPrinting/isPieceStructuredhalf wastranscribed; the body then read
so upstream's
sub(V,c) => sub(V>>c*8,0)rewrite never ran and every SUBPIECE with anonzero byte offset reached the printer, which renders one as the raw p-code operator.
SUB41/SUB81/SUB84are undeclared identifiers — kuna emits no header thatdefines them — so those function bodies were not compilable C.
openssh
ssh(O2-noinline, stripped)sshbuf_put_u64@0x4cd60,--mode reliable:Upstream Ghidra on the same function emits
*local_18 = (char)((ulong)param_2 >> 0x38);,and the source (
sshbuf-getput-basic.i) is a plain shift:((u_char *)(p))[0] = (__v >> 56) & 0xff;. The last line of kuna's own before pane isthe proof that the printer was never at fault — the offset-0 SUBPIECE already rendered
(char)a1.The fix
The ~45-line tail is now transcribed from
ruleaction.cc:7291-7340(
GHIDRA_REV=cef869af), with every guard upstream applies, because each one protects arendering kuna already gets right:
c == 0— already least-significant; it prints as a cast.overlap == c— the SUBPIECE is the storagemarker
ActionCopyMarkerconverts; rewriting it would turn stack-piece writes back intoshift chains.
isPieceStructuredspecial-print branch (already ported) still runs first, sostruct/union/array field extraction is untouched.
Then the rewrite: lump a lone
INT_RIGHT/INT_SRIGHTdescendant with a constant shift whenoutvn->getSize() + c == a->getSize()(declining anINT_RIGHTwhose combined amount wouldevaluate to zero, clamping
INT_SRIGHTto the sign bit), synthesize the shift ahead of theSUBPIECE typed
TYPE_UINT/TYPE_INTat the input width, and zero the SUBPIECE's offset.Nothing needed wiring: the rule was already registered in upstream's own schedule position
(
rrow!("subright", "cleanup", ...),infra/universalaction.rs:552).One kuna-side deviation, marked
// (kuna): the type-factory availability check is hoistedabove the first mutation, so a hand-built
Funcdatawith no type factory (the rule-levelunit-test fixtures) cannot leave a half-applied transform behind. On a real architecture the
factory is always present.
No option — and why
CLAUDE.mdgates features ("behavior that is a judgment call, not universally better") andexempts "a strict bug fix that only corrects wrong output". This is the exempt case:
use_whenprose for asubrightoption —nobody wants the non-compiling spelling.
output shape is byte-identical to Ghidra's on the witness.
exactly what "restoring upstream behavior" predicts.
subrightis a registered rule-group name, sooption togglerule subright offalready gives a bisector the pre-fix rendering. A newsettableTablerow would add catalog-count churn and a knob nobody should flip.An independent decider subagent was asked to make this call from the repo's own rules and
precedent and returned
ungated; its verdict is recorded verbatim indocs/features/subright/record.json. Precedent is unanimous for this shape — #226 (DIV-46),#232 (DIV-48), #235 (DIV-49), #238 (DIV-50), #242 (DIV-52) are all
fix(pN):correctionsthat change emitted C with no settable option.
Recorded in
docs/history.mdunder Convergences, not as a DIV row — the registry's ownrule is that "a port defect whose fix moves kuna back onto upstream's default earns no DIV
row, but a corpus-wide output shift still needs a record for anyone bisecting."
Breadth
Triage's corpus-wide count (matched per-function comparison over 788 binaries / 76,046
functions both tools recovered): nonzero-offset SUBPIECE kuna 5,919 in 2,394 functions
(3.1%) vs ghidra 18 in 13 (0.017%) vs ida 0 — a 329x ratio.
Measured directly for this PR, two release builds of this worktree (stubbed vs ported),
7 whole-binary
decompile-all --mode reliableruns, x86-64 -O0/-O2 and ARM Cortex-M.All totals are over the function set common to both panes, so the 120 s per-function
watchdog cannot move them on this (loaded) box:
SUBnn(offset != 0)sshipe2fsckgzipbzip2Emitted lines over the same set: 443,737 → 443,785 (+0.011%).
Every one of the 95 residuals is a case upstream's own guards decline — 42 address-tied
global-array stores (
s_92e50[7] = SUB81(s_92e50[0],7);, round 1's separately-filedrodata-phantom-store), 47 address-tied local partial-symbol writes (v19 = SUB42(v14,2);,the P6 thread that renders
sym._2_2_upstream), and 6 piece-structured field extractions onthe special-print branch.
subrightowns 1,817 of the 1,912.Measured cost: exactly two functions in 14,720 gain a dead partial-register shift
statement —
v5 = (undefined7)((uint8)a2 >> 8);in bzip2sub_da00and one(undefined3)((uint4)v11 >> 8)on ARM. That is theSUB87/SUB43partial-register form,which upstream lowers the same way. Corpus-wide count of that shape: 0 → 2.
Test
tests/stages/ghdec-subright.xml, two-pass over a realbinary -> decompilepath, on a44-byte i386 bytechunk built from
put_u32_becovers the plain rewrite and thec == 0bail;mulhi_shiftcovers thelone-descendant lumping — the
mullhigh half isSUBPIECE(prod,4)read only by a constantINT_RIGHT, folded into one shift by32+3 == 0x23— and uses a variable multiplier soRuleDivOptdeclines and the truncation actually reaches the printer. Pass 1 is the default(the fix); pass 2 sets
option togglerule subright offand pins the pre-fix rendering.1 of 8 assertions passes pre-fix, 8/8 post-fix.
Two new rule-level unit tests pin the guards that must not be dropped
(
sub_right_least_significant_bails,sub_right_addr_tied_marker_bails).Benchmark
Both cluster cases that are in the mined pool, rescored against the current build:
O2-noinline-iproute2-ip-netns_addO2-noinline-betaflight-betaflight_STM32F405-applyLedFixedLayersGED-neutral by construction, and exactly as the triage predicted: the rewrite changes
expressions inside basic blocks and moves no block, so the graph-edit-distance metric cannot
see it. This case is ranked by correctness (undeclared identifier → valid C), not by GED.
Speed
Interleaved A/B on the two builds, medians (interleaved because this box runs sibling agents
and a decbench sweep, so a blocked measurement would fold load drift into the delta):
ssh@0x4cd60 (the witness)decompile-alldecompile-alle2fsck-O2decompile-allWorst case +0.24%, inside the +5% budget; three of four arms are faster (one op more in
the cleanup pool, but a normalized shift that the downstream pools fold instead of carrying).
Gates
All re-run on the rebased base (
main@d89a4d95):Corpus file count in
decompiler/crates/kuna-base/src/xml.rs: 186 -> 187 (base + #249'sghdec-funcptralign+ #250'sghdec-paramcopyhoist+ this PR'sghdec-subright; 83 datatestsNo catalog surface is touched — the diff against
mainforphases.toml,src/p0_knowledge/,decompiler/crates/kuna-decomp/tests/anddocs/options.mdis empty, andthe settable-row count stays at #250's 85.
Interaction with #250
ActionParamCopyHoistis a default-OFF P6 pass; this is a P3 cleanup rule. Confirmed ratherthan assumed — whole-binary
decompile-all --mode reliablewith--option paramcopyhoist onvs default gives identical results on openssh
ssh, gzip -O0 and bzip2 -O2: residual rawoperators 0/0 in each, subright output shapes 23→23, 12→12, 1→1, and the witness function at
0x4cd60byte-identical either way. Both stage tests pass explicitly(
ghdec-paramcopyhoist3/3,ghdec-subright8/8).Bundle:
docs/features/subright/(analysis.md,plan.md,record.json).Spec prose:
docs/spec/03-ssa-and-simplification.md.🤖 Generated with Claude Code