-
Notifications
You must be signed in to change notification settings - Fork 208
Fail tests when UBSan finds issues #343
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
base: master
Are you sure you want to change the base?
Conversation
include/flatcc/portable/pprintint.h
Outdated
/* The UBSan will warn about storing to misaligned address. */ | ||
#if !(defined(__has_feature) && __has_feature(undefined_behavior_sanitizer)) && \ | ||
(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) | ||
#define __print_unaligned_copy_16(p, q) (*(uint16_t*)(p) = *(uint16_t*)(q)) |
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.
It would be better to avoid the special handling for the sanitizer here and use memcpy
as default instead, but I see this was an active choice.
An alternative would be to add a build options similar to PORTABLE_UNALIGNED_ACCESS to let users choose here too. We would then have to define theses in CI to get the test target to pass which might be suboptimal..
Thanks for digging into this. I'll need to look a bit closer to better understand the issue. In general we don't want #if whatever, if can be avoided, except for dedicated portable/* files. punligned.h is the ultimate reference so clearly this need to work. I'm not sure using sanitizer flags is right here, rather we need to understand the core issue and maybe adapt to the problematic platform using another branch in the file perhaps. pprintint.h really should be using punaligned, but that might be an unnecessary dependency, but it depends on what we can come up with. The general solution is to use memcpy as you mention, but it is not always optimized. Once did made a larger effort to ensure all runtime used memcpy, but it was involved, and resulted in some poor performance occasionally, but that was a while back. I don't have any answers yet, and need to look into it a bit more. I'm also not very familiar with sanitizer thingy. Another thought: If we get this problem in monster_test.c, then other users are going to get it in their own code, so we definitely should not fix it in the test unless there is an actual bug. |
Wrt. monstertest: I think the problem may be that we reuse the pointer after changing the underlying content:
I don't recall the exact interface of Vec3_from_pe(v) - whether it needs a typed pointer or not, but we need a new pointer cast from char * or maybe void * before we attempt to access the data. // declare v_pe earlier ... I don't have test setup handy atm. It may also be that the problem is inside the operation: Vec3_from_pe. That is a bit more messy because then we have to dig into the runtime access interface: https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/flatcc_accessors.h |
wrt printint: I think we should just use memcpy here, it's an isolated case and probably fast anywhere JSON printer performance matters. EDIT: probably better to use mem_copy_word from pmemaccess.h and then just have one place to deal with. Maybe we can do the same with punaligned, but I'm a bit concerned about performance. |
Some checks are recoverable and will only print an error log to stderr. Set build flag -fno-sanitize-recover=all so a testprocess halts with an error status, triggering ctest runs to fail. Signed-off-by: Björn Svensson <[email protected]>
Signed-off-by: Björn Svensson <[email protected]>
Signed-off-by: Björn Svensson <[email protected]>
Signed-off-by: Björn Svensson <[email protected]>
I have re-done some parts of the PR and investigated a bit more. I used The last warnings comes from the json_parser optimizations, which I temporarily disabled. Another finding is that we probably can get rid of |
som thoughts:
Background:
sure, but for production the %8 test would defeat any kind of optimization attempted. |
We have found that there are a couple of issues when building with the UndefinedBehaviorSanitizer.
Some checkers in the UBSan arsenal are recoverable and just gives a printout to stderr, i.e. ctest does not fail.
Adding
-fno-sanitize-recover=all
triggers tests to exit instead, and issues are visible.While enabling this a couple issues surfaces, like unaligned access warnings in 10 test binaries, and most are fixed by a change in
pprintint.h
andpunaligned.h
.There is an open question about how to solve the issue in
monster_test.c
, I'm not sure if there is proper fix.This warning is only seen on macOS and 32bit builds on ubuntu.
Any feedback/ideas?
Weekly test runs OK.