Repository navigation
Conversation
tail_dup admitted any shared tail of at most six statements, including one
that contains an `if` or a loop, so a decision the program makes once was
printed at every place that reaches it: `if (!color) REMOVE_COLOR(); return`
four times in every BSD `RB_REMOVE`, a `do { } while (busy)` wait eight times
in libopencm3's `sdram_command`. angr's ReturnDuplicatorHigh, which the module
cites, duplicates only a return-only block.
Both admission points -- the gotoless split and the goto-driven clone -- now
require the region to be straight-line when it would end up in more than one
place. A single-reference region that is moved rather than copied is exempt.
The stack-protector check is the one branch that does not count: it is the
compiler's, it precedes every return of a protected function, and the last
cleanup pass removes it. `stack_protector_pass_arm` recognises it in the
two-armed shape it has when tail_dup runs; the existing predicate matches
only the settled one-armed guard. Without this exemption the same rule loses
25-27 perfects per config, all of them canary epilogues.
Measured on the full local DecBench configs against main, same rows:
unoptimized distance 394,148 -> 392,704, perfect 12,976 -> 12,994 (18 new,
0 lost); -O2 621,358 -> 619,683, perfect 7,378 -> 7,379 (1 new, 0 lost).
Sample-set gate: perfect 67 -> 67, distance 7,603 -> 7,611 (one row).
In the changed functions gotos rise (1,429 -> 1,695 and 1,732 -> 2,063) and
lines fall (39,192 -> 37,701 and 32,727 -> 31,052).
Proposal: docs/proposals/2026-11-16-tail-dup-straight-line-tails.md
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The pass matched one layout: the handler call alone inside a one-armed
`if`. The check also reaches the output with a label in the arm (left by an
earlier clone, unprinted when unreferenced), with the handler laid out after
the `if` (`if (!x) { return v; } __stack_chk_fail();`), as a jump to the one
block that calls the handler, and with the handler past the end of the arm
the check sits in.
One rule now covers them: a branch exactly one side of which does nothing
but reach the handler is the check, and it is replaced by its other side.
A handler that control merely runs into (behind a call not known to be
no-return) is not a check and stays.
After a removal only the handler block nothing reaches is swept. Re-running
the general unreachable-tail pass there deleted dead code unrelated to the
canary (`list_disks`: 371 lines to 13) and scored better for it.
The check is removed before the `else` unwrap, not after: the handler is a
call that never returns and unwrapped an `else` the source wrote. `tail_dup`
reads the same definition of the check.
Measured against 0d3eb0c on the full local DecBench configs, same rows:
-O2 structure distance 619,683 -> 616,056, perfect 7,379 -> 7,409 (30 new,
0 lost); -O0 392,704 -> 392,625, perfect unchanged. Functions printing the
handler: 1,071 -> 529 and 44 -> 3. Sample-set gate: perfect 67 -> 67,
distance 7,611 -> 7,592.
Proposal: docs/proposals/2026-11-16-stack-protector-check-forms.md
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Stacked on #902 (its commit is the first one here). Merge #902 first; this PR then shows only its own commit.
What
-fstack-protectorputs a check in front of every return of a function with a local buffer.stack_protector.rsremoved it in one layout only — the handler call alone inside a one-armedif. The output still printed__stack_chk_failin 44-O0and 1,071-O2functions of the full local DecBench configs. The checks among them have four layouts:if (x) { __stack_chk_fail(); }if (!x) { return v; } __stack_chk_fail();if (x) goto block_f;if (c) { ...; if (!x) { return v; } } else { ... } __stack_chk_fail();One rule covers them: a branch exactly one side of which does nothing but reach the handler is the compiler's check; it is replaced by its other side. A handler that control merely runs into — behind a call Fission does not know to be no-return — is not a check and stays.
Why this is better without mentioning a score: the reader is shown "if this value is non-zero, abort" in front of each return and has to recognise it as the canary. The source has no such decision.
Changes
stack_protector.rs: the rule above; after a removal, the handler block nothing reaches is swept (the handler only), and a jump left pointing at a removed label becomes the call it stood for.cleanup/mod.rs: the check is removed beforeunwrap_else_after_diverging_then. The handler is a call that never returns; left in, it unwrapped anelsethe source wrote.tail_dup.rs: reads the same definition, so the rule from fix(tail-dup): copy only a straight-line tail to more than one place #902 ("a return behind the check is still the function's return") holds for the handler-after layout.Measurement
Against
0d3eb0cf2(#902), full configs, same rows, caches off:-O0base-O0change-O2base-O2changeSample-set gate: perfect 67 → 67, total distance 7,611 → 7,592. (The gate prints
REGRESSION 68 -> 67against its stored floor;maindoes too.)Every changed function printed the handler before; no other function changes. No output has a
gototo a missing label, before or after.What the numbers hide
tilde_expand_filename) in 12 openssh binaries.-O0rows and 151 of the 158-O2rows the output already had fewer CFG nodes than the source, and removing the check's two nodes takes it further under: the check was standing in for nodes Fission fails to recover elsewhere. One row's +141 is the scorer switching from a size lower bound to a computed distance.list_disks: 371 lines → 13) and measured 1,593 better on-O2than what is proposed here. Found by reading the largest line drops; replaced by a handler-only sweep.-O2−3,385,-O0+76. One-O2function stopped compiling in the byte harness and three started; the cause of the one is not established.Tests
15 new tests in
stack_protector.rs, 1 intail_dup.rs. Each rule was broken on its own (19 mutations) and the intended tests, and only those, failed; the table is in the proposal.cargo nextest run -p fission-midend-structuring -p fission-pcode(debug and--release), the CI clippy line,cargo fmt --all --check.Not fixed
-O2functions still print the handler because code runs into it: behind a call not known to be no-return (438), or behind a block one path of which runs out (79 — tail calls printed as__fission_branchind,switchwithout a default). Correct to keep until the code in front is known to diverge; that is no-return analysis, a different owner.-O2, 2-O0).Proposal:
docs/proposals/2026-11-16-stack-protector-check-forms.md🤖 Generated with Claude Code