From 4bb2b41e561fe9d6750c3985d15667f777dc8a5e Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 29 Sep 2023 10:45:57 -0700 Subject: [PATCH] code reviews, plus more bug fixes I've also cleaned up everything in a way that's hopefully more obvious. --- stl/CMakeLists.txt | 4 +- .../__msvc_sanitizer_annotate_container.hpp | 82 +++++++++++-------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 4483dfeb8e1..ab6d74bfcb4 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -663,12 +663,12 @@ add_stl_dlls("d" Debug) function(add_stl_statics FLAVOR_SUFFIX REL_OR_DBG IDL_VALUE) add_library(libcpmt${FLAVOR_SUFFIX}_eha OBJECT ${EHA_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_STL "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE /EHa) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX}_eha ${REL_OR_DBG}) add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_STL "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX} ${REL_OR_DBG}) diff --git a/stl/inc/__msvc_sanitizer_annotate_container.hpp b/stl/inc/__msvc_sanitizer_annotate_container.hpp index 8dac1a4cb05..81ee58c4ac0 100644 --- a/stl/inc/__msvc_sanitizer_annotate_container.hpp +++ b/stl/inc/__msvc_sanitizer_annotate_container.hpp @@ -15,28 +15,42 @@ _STL_DISABLE_CLANG_WARNINGS #pragma push_macro("new") #undef new -#ifdef _DISABLE_ASAN_ANNOTATIONS +// The following macros change the behavior of this file: +// - _DISABLE_ASAN_ANNOTATION: Disable ASan annotations in the standard library +// (this will be auto-defined on unsupported platforms) +// + _DISABLE_STRING_ANNOTATION: same, but for only `basic_string` +// + _DISABLE_VECTOR_ANNOTATION: same, but for only `vector` +// - _ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORMS: Don't auto-disable ASan annotations +// - _ANNOTATE_STL: Even when ASan annotations are disabled, insert the code for annotating into the STL anyways; +// this is useful when building static libraries which may be linked against both ASan and non-ASan binaries. +// + _ANNOTATE_STRING: same, but only for `basic_string` +// + _ANNOTATE_VECTOR: same, but only for `vector` -#ifdef _ENABLE_ASAN_ANNOTATIONS_ON_UNSUPPORTED_PLATFORMS -#error \ - "Invalid set of defines - one cannot define both _ENABLE_ASAN_ANNOTATIONS_ON_UNSUPPORTED_PLATFORMS and _DISABLE_ASAN_ANNOTATIONS at the same time" -#endif +// if our user hasn't defined `_DISABLE_ASAN_ANNOTATION`, then we may disable it anyways +#if !defined(_DISABLE_ASAN_ANNOTATION) && !defined(_ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORMS) -#else // ^^^ _DISABLE_ASAN_ANNOTATIONS / !_DISABLE_ASAN_ANNOTATIONS vvv +#if defined(_M_ARM64EC) || defined(_M_ARM64) || defined(_M_ARM) || defined(_M_CEE_PURE) +#define _DISABLE_ASAN_ANNOTATION +#endif // ^^^ unsupported platform -#if defined(_DISABLE_STRING_ANNOTATION) && defined(_DISABLE_VECTOR_ANNOTATION) -#define _DISABLE_ASAN_ANNOTATIONS -#elif defined(_M_ARM64EC) || defined(_M_ARM64) || defined(_M_ARM) +#endif // ^^^ !defined(_DISABLE_ASAN_ANNOTATION) && !defined(_ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORM) -#ifndef _ENABLE_ASAN_ANNOTATIONS_ON_UNSUPPORTED_PLATFORMS -#define _DISABLE_ASAN_ANNOTATIONS -#endif +// this may be user-defined, or we may be on an unsupported platform +#ifdef _DISABLE_ASAN_ANNOTATION -#elif defined(_M_CEE_PURE) -#define _DISABLE_ASAN_ANNOTATIONS -#endif +#ifdef _ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORMS +#error _ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORMS and _DISABLE_ASAN_ANNOTATION are mutually exclusive +#endif // ^^^ defined(_ENABLE_ASAN_ANNOTATION_ON_UNSUPPORTED_PLATFORMS) + +#define _DISABLE_STRING_ANNOTATION +#define _DISABLE_VECTOR_ANNOTATION -#endif // ^^^ !_DISABLE_ASAN_ANNOTATIONS +#endif // ^^^ defined(_DISABLE_ASAN_ANNOTATION) + +#ifdef _ANNOTATE_STL +#define _ANNOTATE_STRING +#define _ANNOTATE_VECTOR +#endif // ^^^ defined(_ANNOTATE_STL) #ifdef __SANITIZE_ADDRESS__ @@ -55,41 +69,41 @@ _STL_DISABLE_CLANG_WARNINGS #pragma comment(linker, "/INFERASANLIBS") #endif // __has_feature(address_sanitizer) -#else // ^^^ defined(__clang__) / !defined(__clang__) && !defined(__SANITIZE_ADDRESS__) vvv - -#ifdef _ANNOTATE_STRING -#define _INSERT_STRING_ANNOTATION -#endif // defined(_ANNOTATE_STRING) -#ifdef _ANNOTATE_VECTOR -#define _INSERT_VECTOR_ANNOTATION -#endif // defined(_ANNOTATE_VECTOR) +#endif // ^^^ defined(__clang__) -#endif // ^^^ !defined(__clang__) && !defined(__SANITIZE_ADDRESS__) ^^^ -#if defined(_DISABLE_ASAN_ANNOTATION) || defined(_DISABLE_STRING_ANNOTATION) +#ifdef _DISABLE_STRING_ANNOTATION #undef _ACTIVATE_STRING_ANNOTATION #undef _INSERT_STRING_ANNOTATION -#endif // defined(_DISABLE_STRING_ANNOTATION) -#if defined(_DISABLE_ASAN_ANNOTATION) || defined(_DISABLE_VECTOR_ANNOTATION) +#endif // ^^^ defined(_DISABLE_STRING_ANNOTATION) +#ifdef _DISABLE_VECTOR_ANNOTATION #undef _ACTIVATE_VECTOR_ANNOTATION #undef _INSERT_VECTOR_ANNOTATION -#endif // defined(_DISABLE_VECTOR_ANNOTATION) +#endif // ^^^ defined(_DISABLE_VECTOR_ANNOTATION) + +#ifdef _ANNOTATE_STRING +#define _INSERT_STRING_ANNOTATION +#endif // ^^^ defined(_ANNOTATE_STRING) +#ifdef _ANNOTATE_VECTOR +#define _INSERT_VECTOR_ANNOTATION +#endif // ^^^ defined(_ANNOTATE_VECTOR) + #ifndef _INSERT_STRING_ANNOTATION #pragma detect_mismatch("annotate_string", "0") -#endif // !defined(_INSERT_STRING_ANNOTATION) +#endif // ^^^ !defined(_INSERT_STRING_ANNOTATION) #ifndef _INSERT_VECTOR_ANNOTATION #pragma detect_mismatch("annotate_vector", "0") -#endif // !defined(_INSERT_VECTOR_ANNOTATION) +#endif // ^^^ !defined(_INSERT_VECTOR_ANNOTATION) #ifdef _ACTIVATE_STRING_ANNOTATION #pragma comment(lib, "stl_asan") #pragma detect_mismatch("annotate_string", "1") -#endif // defined(_ACTIVATE_STRING_ANNOTATION) +#endif // ^^^ defined(_ACTIVATE_STRING_ANNOTATION) #ifdef _ACTIVATE_VECTOR_ANNOTATION #pragma comment(lib, "stl_asan") #pragma detect_mismatch("annotate_vector", "1") -#endif // defined(_ACTIVATE_VECTOR_ANNOTATION) +#endif // ^^^ defined(_ACTIVATE_VECTOR_ANNOTATION) #undef _ACTIVATE_STRING_ANNOTATION #undef _ACTIVATE_VECTOR_ANNOTATION @@ -142,7 +156,7 @@ void __cdecl __sanitizer_annotate_contiguous_container( #error Unknown architecture #endif // ^^^ unknown architecture ^^^ -#endif // insert asan annotations +#endif // ^^^ insert asan annotations #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS