-
Notifications
You must be signed in to change notification settings - Fork 37
Add CMake options for turning on ASAN and HWASAN #1106
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
Conversation
Add CMake options to build with AddressSanitizer/HWAddressSanitizer turned on. HWAddressSanitizer only works on ARM platforms due to hardware support but runs faster than AddressSanitizer.
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 it's a good idea to add those.
How much slower does the code run with those options?
I'm asking wrt to whether it's worth to activate this by default to one of the short or extended tests (once the issue reported in #1107 are fixed).
PS: Changelog entry is missing;)
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment) | ||
add_link_options(-fsanitize=address -fsanitize=undefined) |
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.
This will then also be forwarded to all submodules, we include, isn't it?
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, it should be.
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.
LGTM, this will definitely be helpful to have. I am going to take a look at the logical location bit shift issue, I think it will be straightforward to fix.
I definitely support having it run on one of the extended tests (unless it takes hours to run with these options on). |
Running the test suite with this turned on is only about a factor of 2-3 slower on my laptop, so I think it should be fine to enable for the extended CI. |
PR Summary
Add CMake options
ENABLE_ASAN
andENABLE_HWASAN
to build with AddressSanitizer and HWAddressSanitizer, respectively, turned on.ASAN is supported in both clang and gcc. HWASAN is support by clang and (in theory) gcc.
Then the app is run as normal. It will stop and print an error if a memory bug is detected. This should detect almost all out of bounds access, uninitalized values, and other memory errors for CPU builds.
Usage notes:
Miscellaneous useful env vars to configure its behavior when running:
HWAddressSanitizer only works on Linux ARM platforms but runs significantly faster than AddressSanitizer. In my testing, additional flags are required for HWAsan:
(I was not able to get it working with gcc, since building HWASAN support in gcc is optional and distros don't do it.)
PR Checklist