Improve handling of JumpBound truncation constraints #403
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.
Background
Given some symbolic value,
x
, we'd like to compute its possible upper and lower bounds after it is truncated tow
bits.To do this, we first find the bound of x by (recursively) calling
exprRangePred
. This bound is a statement of the following form (seeRangePred
for more info): "r
bits ofx
are bounded betweenlow
andhigh
".Then, we check the following:
x
has a bound(r, l, h)
ANDr
is less than or equal tow
=> Pass-through the bound(r, l, h)
Otherwise, we deem
x
"unbounded"Proposal
Declaring
x
unbounded in the second case seems to throw away useful information that causes many jump tables to remain unclassified. We attempt to improve on that in this commit.Consider an example where
x
is bounded by(64, 0, 10)
(that is, the 64 bits ofx
are constrained to be between 0 and 10) and we want to find the bound of truncatingx
to 8 bits.With the current logic, since 64 > 8, we'd declare x unbounded. However, the bound
(8, 0, 10)
should also be valid: if 64 bits ofx
are bounded to [0, 10], then surely 8 bits ofx
also lie between 0 and 10.If the upper bound is instead larger than the largest 8-bit value, we can truncate it to the largest value.
For example,
(64, 0, 10000)
becomes(8, 0, 255)
.Instead of losing the bound completely, we're able to tighten it!
Evaluation
Using Reopt's ground truth evaluation, we found that this change significantly improved jump table classification in coreutil binaries compiled with
GCC_O1
. Out of 912 total jump tables in the dataset, macaw (launched through Reopt) currently reaches + classifies 109 jump tables. After this change, macaw correctly classifies 857/912 jump tables.