-
Notifications
You must be signed in to change notification settings - Fork 274
Add --object-bits
option to goto-cc
#5440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --object-bits
option to goto-cc
#5440
Conversation
c53603d
to
63fd092
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5440 +/- ##
========================================
Coverage 68.22% 68.22%
========================================
Files 1178 1178
Lines 97580 97580
========================================
Hits 66573 66573
Misses 31007 31007
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
find_first_set(const size_t max_malloc_size, const size_t bits_accumulator) | ||
{ | ||
// Implemented using recursion to avoid excessive unwinding or specifying an | ||
// unwind limit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does recursion stop excessive unwinding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered this by experimentation. The same algorithm written as a loop spent a long time unwinding if no unwind limit was set. The recursive version only unwinds a sufficient number of times for the value of max_malloc_size
which is actually specified.
I am not familiar with the unwinding code. However I would hazard a guess that loop unwinding happens early on, using a only a local analysis. Whereas recursion unwinding happens later as part of symmex. The constant being passed to the function is been propagated in this case, leading to unwinding the exact number of times required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been able to reproduce the problem I saw with the iterative version and I never committed that version, so I can't get it back even with git reflog
. Therefore I am going to assume there is no problem with unwinding loops / constant propagation. I shall delete this comment in order to avoid being misleading, but leave the recursive version in place because it doesn't seem worth rewriting this.
@@ -28,6 +28,7 @@ const char *goto_cc_options_with_separated_argument[]= | |||
"--native-linker", | |||
"--print-rejected-preprocessed-source", | |||
"--mangle-suffix", | |||
"--object-bits", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be added to the other cmdlinet
s as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original ticket referred to goto-cc
only, fixing goto-cc
only will get a fix ready for use sooner. Yes, the same problem and fix probably applies to the other entry points as well. The time consuming part of fixing the other entry points would be writing tests for each of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no standard list of options in the base class. So it would need to be manually added and tested for each cmdlinet
in the heirarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So adding the option to the cmdlinet was all that was needed to make this work? Neat.
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
assertion object_bits != 8: FAILURE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the expected results for the other assertions in here as well? Clearly it's supposed to be always 2 successes and one failure but that might be easier to see if its spelt out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now this solution is fine. At some point though, the __CPROVER_max_malloc_size
variable will go away anyways (when ADA-576 is implemented) and the conflict will disappear. Then goto-cc
should be able to be oblivious to the object bits setting again.
The reason for __CPROVER_max_malloc_size
going away is that it is currently used to check that not more memory is allocated than can be addressed by cbmc. However, it turns out that a better way to implement this is to check for pointer overflows instead (see discussion on #5401).
return find_first_set(max_malloc_size >> 1, bits_accumulator + 1); | ||
} | ||
|
||
size_t calculate_object_bits() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it would be unnecessary to reverse engineer the object bits here or even use the value of __CPROVER_max_malloc_size
. It's probably sufficient to just run cbmc
with a non-default object bits setting after goto-cc
and check that it suceeds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I chose to do it this way is that the previous incorrect behaviour resulted in a warning, but might not actually cause a failure without giving an input program which depends on the implications of the object-bits
configuration. I could have used a negative regex to check that the warning message does not appear in the output. However this would not be a robust test because if the text of the message were to be updated then the corresponding test could easily be missed. This may be a little over-engineered but I am happy that this is a robust test and it is clear what the positive regexes are actually checking for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense.
7a0ac50
to
8c8fc97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested what happens with linking? I'm thinking of the case where you compile one translation unit with one value for object-bits, and another translation unit with a different value for object-bits. How does the linker handle that? (Hopefully with a nice user-friendly error message... :-) )
@chrisr-diffblue If I feed two different goto binaries into cbmc which were generated using different
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad theres a diagnostic, thanks for checking/demonstrating. It's probably an open question whether that should be an error rather than a warning, but that doesn't have to be fixed in this PR, so feel free to raise a Github bug ticket to cover that. It'd be super nice if there was a test case to demonstrate the diagnostic gets triggered (just so we don't end up accidentally losing that at some point :-) ) but again, I won't block the PR just on that.
So that we can support running with non-default settings of `--object-bits` in `goto-cc`.
8c8fc97
to
06c5aa1
Compare
So that we can support running with non-default settings of
--object-bits
ingoto-cc
. This should address the issue seen in #5272