-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 per-allocator disablement of ASan #5241
base: main
Are you sure you want to change the base?
Add per-allocator disablement of ASan #5241
Conversation
Co-authored-by: Casey Carter <[email protected]>
Co-authored-by: Casey Carter <[email protected]>
// FIXME: IntelliSense claims '_Is_ASan_enabled_for_allocator is not a templateC/C++(864)', | ||
// but it works somehow. |
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 is probably due to IntelliSense picking up the installed STL headers instead of the headers in your STL repo.
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.
Oh, that makes sense. I'll remove this comment in my next commit then.
Just curious - do we have a good way of teling intellisense about this, or do we just 'ignore' the false alarm?
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.
We test IntelliSense via the /BE
command-line option. That should pick up your freshly built STL headers.
As for actual IntelliSense in the IDE, no idea. I would expect that if you've built something with the freshly built STL picked up (remember set_environment.bat
!), then it would know the correct paths.
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'll do some digging and find out, would be good to document :-) . Thanks!
Marking as draft for now to try and simplify the test. |
…sto/add-asan-per-container-disablement
stl/inc/xmemory
Outdated
@@ -805,6 +805,10 @@ struct _Simple_types { // wraps types from allocators with simple addressing for | |||
_INLINE_VAR constexpr size_t _Asan_granularity = 8; | |||
_INLINE_VAR constexpr size_t _Asan_granularity_mask = _Asan_granularity - 1; | |||
|
|||
// Represents whether ASan container annotations are enabled a given allocator. | |||
template <class> | |||
constexpr bool _Is_ASan_enabled_for_allocator = true; |
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.
Nice!
I may have missed some conversation about it, but I'm wondering if the name should be changed. The feature is disabling annotations based on the container's underlying allocator.
Since the options for compiler are _DISABLE_X_ANNOTATION
should we try to follow suite with Disable
in the name?
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.
Since the options for compiler are _DISABLE_X_ANNOTATION should we try to follow suite with Disable in the name?
Oh I didn't realize the compiler options / flags followed that naming convention? Do you have a link or example where I can see this?
But yeah, don't feel strongly about naming. If it matches the flags, I'm happy to have Disabled
over Enabled
in the name. I'll tackle that on my next push.
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.
Yeah, I'm basically commenting on staying in line with these
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.
Incorporated: 57e7aff
Please note this PR is blocked on: #5251
Context:
The STL "annotates" the
vector
andbasic_string
containers so that ASan will fire an error whenever allocated but initialized container data is accessed. A simple repro is thecontainer overflow
error fired in this sample program (assuming it's/fsanitize=address
'ed):This is sensible behavior in most cases.
One case where it does not bode well is when an arena allocator is used as the custom allocator of the container. Arena allocators often tamper with the entire allocated memory at once (e.g. they commonly deallocate their entire 'arena' at once) which would trigger ASan AVs when the capacity of the container exceeds it's size.
We encountered one such bug in the
msvc
front end.This PR:
This PR introduces the ability for custom allocators to opt-out of
vector
andbasic_string
's ASan annotations. This is controlled by the newly introduced template variable:_Is_ASan_enabled_for_allocator<...some allocator type...>
.A simple test for the
vector
andbasic_string
container cases was added as well.Ask for reviewers:
TODO
andFIXME
comments in the diff, those are pending and I'd appreciate guidance on those. I'll mark the PR as "ready to review" to get visibility on those. I hope that's appropriate, let me know if not.Why not provide better support for arena allocators instead of opting out?
This opt-out feature does not replace the need to additionally provide better support for arena-type allocators (and other exceptional cases) in our STL ASan annotations. This is just meant to be a simple 'catch-all' workaround for those cases but is not the ideal afaict. I'm hoping to push for a more principled long-term solution for the
msvc
FE ASan bug, but this just a "band aid fix" for now.