folly icon indicating copy to clipboard operation
folly copied to clipboard

Add address sanitizer annotations to UninitializedMemoryHacks.h when building with msvc 2022

Open pps83 opened this issue 2 years ago • 19 comments

I use UninitializedMemoryHacks.h, but it adds lots of false positives when running with address sanitizer. I grepped MS includes and based on the version that comes with VS2022 I added these annotations. In my case, this fixed all the issues. I did check vs 2019 headers and didn't see the same annotation code used there.

pps83 avatar Feb 17 '23 19:02 pps83

check __sanitizer_annotate_contiguous_container in https://github.com/microsoft/STL/blob/main/stl/inc/string and https://github.com/microsoft/STL/blob/main/stl/inc/vector

pps83 avatar Feb 17 '23 19:02 pps83

based on git history, seems that these are available only in vs 2022: image

pps83 avatar Feb 17 '23 19:02 pps83

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Feb 21 '23 20:02 facebook-github-bot

FYI, it looks like in current version that ships with latest VS2022 asan annotations are commented out in std::string. I had some false positives because of that with asan reporting and had to comment out the string part in UninitializedMemoryHacks.h

pps83 avatar Feb 21 '23 20:02 pps83

More fixes added (support for std::string annotations was added starting from _MSC_VER >= 1938)

pps83 avatar Nov 21 '23 01:11 pps83

Has folly considered asking for an _Ugly member that does what they need rather than trying to incapability declare standard library parts?

BillyONeal avatar Nov 21 '23 22:11 BillyONeal

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Nov 28 '23 00:11 facebook-github-bot

@yfeldblum thanks for the review. I'm traveling in remote locations and rarely connect, so, will take some time before I can address it. There was also a suggestion by @BillyONeal and I think that would be a better approach.

pps83 avatar Dec 02 '23 10:12 pps83

There was also a suggestion by @BillyONeal and I think that would be a better approach.

To be clear, while in the long term doing this with some mechanism that isn't a hack would have the benefit that it doesn't break every 3 seconds.

That doesn't change that VS2022 17.8 is already out there which means Windows customers who want to use Folly are broken

BillyONeal avatar Dec 04 '23 19:12 BillyONeal

@yfeldblum all issues should be addressed

pps83 avatar Dec 06 '23 14:12 pps83

_INSERT_STRING_ANNOTATION / _INSERT_VECTOR_ANNOTATION are defined by https://github.com/microsoft/STL/blob/0403d19f5461fd15983737c3f01ec34800ea9275/stl/inc/__msvc_sanitizer_annotate_container.hpp (this file is included by string/vector). string/vector undef these defines at the end. This PR replicates what the MS headers do.

_Asan_string_should_annotate also comes from __msvc_sanitizer_annotate_container.hpp

pps83 avatar Dec 06 '23 14:12 pps83

@yfeldblum ping

pps83 avatar Apr 01 '24 11:04 pps83

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Apr 01 '24 21:04 facebook-github-bot

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Apr 01 '24 21:04 facebook-github-bot

There are merge conflicts in this that need to be resolved before the tooling will let me import this PR. Would you be able to rebase this PR?

Orvid avatar Apr 01 '24 21:04 Orvid

There are merge conflicts in this that need to be resolved before the tooling will let me import this PR. Would you be able to rebase this PR?

give me a few mins

pps83 avatar Apr 01 '24 22:04 pps83

I rebased, but I didn't have any merge conflicts. @Orvid @yfeldblum

pps83 avatar Apr 01 '24 22:04 pps83

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Apr 02 '24 01:04 facebook-github-bot

Thanks, the import worked that time. Not sure why it was having issues before if there weren't merge conflicts.

Orvid avatar Apr 02 '24 01:04 Orvid