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 3633425feb3..f0b27e06382 100644 --- a/stl/inc/__msvc_sanitizer_annotate_container.hpp +++ b/stl/inc/__msvc_sanitizer_annotate_container.hpp @@ -15,7 +15,51 @@ _STL_DISABLE_CLANG_WARNINGS #pragma push_macro("new") #undef new -#if !defined(_M_CEE_PURE) && !(defined(_DISABLE_STRING_ANNOTATION) && defined(_DISABLE_VECTOR_ANNOTATION)) +// The following macros change the behavior of this file: +// - _DISABLE_STL_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_STL_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` + +#if !defined(_DISABLE_STL_ANNOTATION) && !defined(_ENABLE_STL_ANNOTATION_ON_UNSUPPORTED_PLATFORMS) + +#if defined(_M_ARM64EC) || defined(_M_ARM64) || defined(_M_ARM) || defined(_M_CEE_PURE) +#define _DISABLE_STL_ANNOTATION +#endif // ^^^ unsupported platform ^^^ + +#endif // ^^^ !defined(_DISABLE_STL_ANNOTATION) && !defined(_ENABLE_STL_ANNOTATION_ON_UNSUPPORTED_PLATFORMS) ^^^ + +#ifdef _DISABLE_STL_ANNOTATION + +#ifdef _ENABLE_STL_ANNOTATION_ON_UNSUPPORTED_PLATFORMS +#error _ENABLE_STL_ANNOTATION_ON_UNSUPPORTED_PLATFORMS and _DISABLE_STL_ANNOTATION are mutually exclusive +#endif // ^^^ defined(_ENABLE_STL_ANNOTATION_ON_UNSUPPORTED_PLATFORMS) ^^^ + +#ifndef _DISABLE_STRING_ANNOTATION +#define _DISABLE_STRING_ANNOTATION +#endif // ^^^ !defined(_DISABLE_STRING_ANNOTATION) ^^^ +#ifndef _DISABLE_VECTOR_ANNOTATION +#define _DISABLE_VECTOR_ANNOTATION +#endif // ^^^ !defined(_DISABLE_VECTOR_ANNOTATION) ^^^ + +#endif // ^^^ defined(_DISABLE_STL_ANNOTATION) ^^^ + +#ifdef _ANNOTATE_STL + +#ifndef _ANNOTATE_STRING +#define _ANNOTATE_STRING +#endif // ^^^ !defined(_ANNOTATE_STRING) ^^^ + +#ifndef _ANNOTATE_VECTOR +#define _ANNOTATE_VECTOR +#endif // ^^^ !defined(_ANNOTATE_VECTOR) ^^^ + +#endif // ^^^ defined(_ANNOTATE_STL) ^^^ #ifdef __SANITIZE_ADDRESS__ @@ -34,41 +78,41 @@ _STL_DISABLE_CLANG_WARNINGS #pragma comment(linker, "/INFERASANLIBS") #endif // __has_feature(address_sanitizer) -#else // ^^^ defined(__clang__) / !defined(__clang__) && !defined(__SANITIZE_ADDRESS__) vvv +#endif // ^^^ defined(__clang__) ^^^ -#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__) && !defined(__SANITIZE_ADDRESS__) ^^^ #ifdef _DISABLE_STRING_ANNOTATION #undef _ACTIVATE_STRING_ANNOTATION #undef _INSERT_STRING_ANNOTATION -#endif // defined(_DISABLE_STRING_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 @@ -121,9 +165,7 @@ void __cdecl __sanitizer_annotate_contiguous_container( #error Unknown architecture #endif // ^^^ unknown architecture ^^^ -#endif // insert asan annotations - -#endif // !defined(_M_CEE_PURE) && asan not disabled +#endif // ^^^ insert ASan annotations ^^^ #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS diff --git a/stl/msbuild/stl_base/libcp.settings.targets b/stl/msbuild/stl_base/libcp.settings.targets index 23f4ca72a5d..0e03b8a714e 100644 --- a/stl/msbuild/stl_base/libcp.settings.targets +++ b/stl/msbuild/stl_base/libcp.settings.targets @@ -27,7 +27,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception $(OutputLibPdbPath)$(OutputName)$(PdbVerName).pdb - $(ClDefines);_VCRT_ALLOW_INTERNALS;_ANNOTATE_VECTOR;_ANNOTATE_STRING + $(ClDefines);_VCRT_ALLOW_INTERNALS;_ANNOTATE_STL