Repository navigation
Conversation
…below checkInputTrialUse drops a stack trial when the frame's alias boundary reaches it: some pointer formed from the stack pointer sits at or below the slot. A LOAD/STORE through such a pointer counts until heritage turns it into a stack variable, and a pointer whose offset only becomes known late (a stack pointer restored from the frame slot it was saved in after an alloca) is still one when call inputs are scored. The call after the restore stores its own argument through it, below the earlier calls' arguments, and those were dropped (reg(1) printed for reg(1, n)). kuna_directalias: a pointer that is the stack-pointer input plus constants, through copies and frame slots only, and is used solely as the address of LOADs and STOREs, aliases a trial only when the bytes it touches overlap it (AliasChecker::has_local_alias_among draws the boundary from the other pointers). Indexed pointers keep the upstream boundary. Stage test kuna-x86-directalias; Debian corpus (23,142 functions, 10 architectures) and the public decbench corpus (95,698 functions) are unchanged.
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
When a function saves
%espin a frame slot around analloca/VLA and restores it from that slot, an earlier call loses a stack argument. This independent example (clang-O0shape: arguments stored through a copy of%esp) makes two calls, then allocates, restores%espfrom the slot, and calls again:Before the fix the first call loses
n:Compiled and run against a
sub_100100that records its variadic arguments, the first call receivescount = 1and no second argument.Cause
checkInputTrialUsedrops a stack trial when the frame's alias boundary reaches it: some pointer formed from the stack pointer sits at or below the slot, so anything above it may be reached. EveryLOAD/STOREthrough a stack pointer counts as such a pointer until heritage turns it into a stack variable. A stack pointer restored from the frame slot it was saved in only becomes a known constant offset a pass later, so when call inputs are scored the last call's own argument store is still a pointer store at-0x2c, and the first call's argument at-0x28is "above" it. One pass later the store is converted and the pointer is gone, but the trial verdict is final.Fix
p4_calls/kuna_directalias.rs: a gathered pointer that is the stack-pointer input plus constants, through copies and frame slots only, and that is used solely as the address ofLOADs andSTOREs, touches exactly[offset, offset + size). It aliases a trial only when those bytes overlap it. Every other pointer, including any indexed access, keeps the upstream boundary (AliasChecker::has_local_alias_amongdraws it from them). No option: the previous output drops an argument the program passes.After the fix:
Tests
kuna-x86-directalias.xml: the same function without the allocation (unchanged control) and with it.i686-linux-gnuand run underqemu-i386against a recording variadic callee: before, the first call receives nonat-O0and-O2; after,(1, n)at both.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): no function changes.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 5 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; re-scored with that timeout disabled, every pair has byte-identical original and recompiled machine code and equal scores.