-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Allow ASan container annotations to activate piecemeal #6211
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,13 @@ | |
|
|
||
| namespace std { | ||
| extern "C" { | ||
| extern const bool _Asan_string_should_annotate = true; | ||
| extern const bool _Asan_vector_should_annotate = true; | ||
| extern const bool _Asan_optional_should_annotate = true; | ||
| // Retained for compatibility with old headers that add stl_asan.lib to the link. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use the magic words "TRANSITION, ABI". |
||
| // Use __declspec(selectany) to be compatible with new version that define these | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "with new version that define these" isn't grammatical. Should probably be "with the new version that defines these". |
||
| // variables as __declspec(selectany) in __msvc_sanitizer_annotate_container.hpp. | ||
| // The new method is preferred because previously enabling just string would also | ||
| // enable vector and optional. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding ", see GH-6186." would be helpful (we try to avoid the need to |
||
| extern __declspec(selectany) const bool _Asan_string_should_annotate = true; | ||
| extern __declspec(selectany) const bool _Asan_vector_should_annotate = true; | ||
| extern __declspec(selectany) const bool _Asan_optional_should_annotate = true; | ||
|
Comment on lines
+11
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned that bundling these 3 definitions into a single object can still lead to scenarios where annotations are partially activated, the linker drags in Conversely, I am even more concerned that Should we break up |
||
| } // extern "C" | ||
| } // namespace std | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| # This test matrix is the usual test matrix, with all currently unsupported options removed, crossed with the ASan flags. | ||
|
|
||
| # TRANSITION, google/sanitizers#328: clang-cl does not support /MDd or /MTd with ASan | ||
| RUNALL_INCLUDE ..\prefix.lst | ||
| RUNALL_CROSSLIST | ||
| PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /DTEST_ENSURE_STRING_ENABLED /DTEST_ENSURE_OPTIONAL_ENABLED" | ||
| PM_CL="/fsanitize=address /D_DISABLE_VECTOR_ANNOTATION /DTEST_ENSURE_STRING_ENABLED /DTEST_ENSURE_OPTIONAL_ENABLED" | ||
| PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /D_DISABLE_STRING_ANNOTATION /DTEST_ENSURE_OPTIONAL_ENABLED" | ||
| PM_CL="/fsanitize=address /DTEST_ENSURE_VECTOR_ENABLED /DTEST_ENSURE_STRING_ENABLED /D_DISABLE_OPTIONAL_ANNOTATION" | ||
| PM_CL="/D_ANNOTATE_STL" | ||
| RUNALL_CROSSLIST | ||
| PM_CL="/Zi /wd4611 /w14640 /Zc:threadSafeInit-" PM_LINK="/debug" | ||
| RUNALL_CROSSLIST | ||
| PM_CL="/BE /c /EHsc /MD /std:c++14" | ||
| PM_CL="/BE /c /EHsc /MDd /std:c++17 /permissive-" | ||
| PM_CL="/BE /c /EHsc /MT /std:c++20 /permissive-" | ||
| PM_CL="/BE /c /EHsc /MTd /std:c++latest /permissive-" | ||
| PM_CL="/EHsc /MD /std:c++14" | ||
| PM_CL="/EHsc /MD /std:c++17" | ||
| PM_CL="/EHsc /MD /std:c++20" | ||
| PM_CL="/EHsc /MD /std:c++latest /permissive- /Zc:char8_t- /Zc:preprocessor" | ||
| PM_CL="/EHsc /MD /std:c++latest /permissive- /Zc:noexceptTypes-" | ||
| PM_CL="/EHsc /MDd /std:c++14 /fp:except /Zc:preprocessor" | ||
| PM_CL="/EHsc /MDd /std:c++17 /permissive-" | ||
| PM_CL="/EHsc /MDd /std:c++20 /permissive-" | ||
| PM_CL="/EHsc /MDd /std:c++latest /permissive- /Zc:wchar_t-" | ||
| PM_CL="/EHsc /MDd /std:c++latest /permissive-" | ||
| PM_CL="/EHsc /MT /std:c++latest /permissive- /analyze:only /analyze:autolog-" | ||
| PM_CL="/EHsc /MT /std:c++latest /permissive-" | ||
| PM_CL="/EHsc /MTd /std:c++latest /permissive" | ||
| PM_CL="/EHsc /MTd /std:c++latest /permissive- /analyze:only /analyze:autolog-" | ||
| PM_CL="/EHsc /MTd /std:c++latest /permissive- /fp:strict" | ||
| PM_CL="/EHsc /MTd /std:c++latest /permissive-" | ||
| # TRANSITION, we don't use /ALTERNATENAME for Clang (see GH-5224) so we cannot test /D_ANNOTATE_VECTOR without -fsanitize=address | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was copy-pasted from |
||
| PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MD /std:c++14" | ||
| PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MD /std:c++17" | ||
| PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++20 /permissive-" | ||
| PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsing -Wno-unqualified-std-cast-call /EHsc /MT /std:c++latest /permissive- /fp:strict" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // REQUIRES: x64 || x86 || arm64 | ||
|
Comment on lines
+2
to
+3
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: We conventionally put an empty line after the license banner. |
||
|
|
||
| #if defined(__clang__) && defined(_M_ARM64) // TRANSITION, LLVM-184902, fixed in Clang 23 | ||
| #pragma comment(linker, "/INFERASANLIBS") | ||
| int main() {} | ||
| #else // ^^^ workaround / no workaround vvv | ||
|
|
||
| #include <cassert> | ||
| #include <vector> // include __msvc_sanitizer_annotate_container.hpp | ||
|
|
||
| extern "C" const bool _Asan_vector_should_annotate; | ||
| extern "C" const bool _Asan_string_should_annotate; | ||
| extern "C" const bool _Asan_optional_should_annotate; | ||
|
|
||
| int main() { | ||
| #ifdef TEST_ENSURE_VECTOR_ENABLED | ||
| assert(_Asan_vector_should_annotate == true); | ||
| #else | ||
| assert(_Asan_vector_should_annotate == false); | ||
| #endif | ||
|
|
||
| #ifdef TEST_ENSURE_STRING_ENABLED | ||
| assert(_Asan_string_should_annotate == true); | ||
| #else | ||
| assert(_Asan_string_should_annotate == false); | ||
| #endif | ||
|
|
||
| #ifdef TEST_ENSURE_OPTIONAL_ENABLED | ||
| assert(_Asan_optional_should_annotate == true); | ||
| #else | ||
| assert(_Asan_optional_should_annotate == false); | ||
| #endif | ||
| } | ||
|
|
||
| #endif // ^^^ no workaround ^^^ | ||
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.
Instead of individually marking these as
extern "C", I believe it would be better to move up theextern "C" {scope beginning at right line 148, so that these definitions look more similar to the declarations below. The only stuff in between are pragmas and undefs.