Commit 031b3dfc authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-25123 support MSVC ASAN

parent 4c2b6be3
...@@ -68,17 +68,12 @@ MACRO(ENABLE_SANITIZERS) ...@@ -68,17 +68,12 @@ MACRO(ENABLE_SANITIZERS)
MESSAGE(FATAL_ERROR "clang-cl or MSVC necessary to enable asan/ubsan") MESSAGE(FATAL_ERROR "clang-cl or MSVC necessary to enable asan/ubsan")
ENDIF() ENDIF()
# currently, asan is broken with static CRT. # currently, asan is broken with static CRT.
IF(NOT(MSVC_CRT_TYPE STREQUAL "/MD")) IF(CLANG_CL AND NOT(MSVC_CRT_TYPE STREQUAL "/MD"))
IF(NOT DYNAMIC_UCRT_LINK) SET(MSVC_CRT_TYPE "/MD" CACHE INTERNAL "" FORCE)
MESSAGE(FATAL_ERROR "-DWITH_ASAN cmake parameter also requires -DMSVC_CRT_TYPE=/MD OR DYNAMIC_UCRT_LINK=ON")
ENDIF()
ENDIF() ENDIF()
IF(CMAKE_SIZEOF_VOID_P EQUAL 4) IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(ASAN_ARCH i386) SET(ASAN_ARCH i386)
ELSE() ELSE()
IF(NOT CLANG_CL)
MESSAGE(FATAL_ERROR "sanitizers do not yet work on MSVC x64, try 32 bit or clang-cl")
ENDIF()
SET(ASAN_ARCH x86_64) SET(ASAN_ARCH x86_64)
ENDIF() ENDIF()
...@@ -88,8 +83,10 @@ MACRO(ENABLE_SANITIZERS) ...@@ -88,8 +83,10 @@ MACRO(ENABLE_SANITIZERS)
SET(SANITIZER_LINK_LIBRARIES) SET(SANITIZER_LINK_LIBRARIES)
SET(SANITIZER_COMPILE_FLAGS) SET(SANITIZER_COMPILE_FLAGS)
IF(WITH_ASAN) IF(WITH_ASAN)
LIST(APPEND SANITIZER_LIBS IF(CLANG_CL)
clang_rt.asan_dynamic-${ASAN_ARCH}.lib clang_rt.asan_dynamic_runtime_thunk-${ASAN_ARCH}.lib) LIST(APPEND SANITIZER_LIBS
clang_rt.asan_dynamic-${ASAN_ARCH}.lib clang_rt.asan_dynamic_runtime_thunk-${ASAN_ARCH}.lib)
ENDIF()
STRING(APPEND SANITIZER_COMPILE_FLAGS " -fsanitize=address") STRING(APPEND SANITIZER_COMPILE_FLAGS " -fsanitize=address")
ENDIF() ENDIF()
IF(WITH_UBSAN) IF(WITH_UBSAN)
...@@ -134,7 +131,13 @@ IF(MSVC) ...@@ -134,7 +131,13 @@ IF(MSVC)
INCLUDE(InstallRequiredSystemLibraries) INCLUDE(InstallRequiredSystemLibraries)
ENDIF() ENDIF()
OPTION(DYNAMIC_UCRT_LINK "Link Universal CRT dynamically, if MSVC_CRT_TYPE=/MT" ON) IF(WITH_ASAN AND (NOT CLANG_CL))
SET(DYNAMIC_UCRT_LINK_DEFAULT OFF)
ELSE()
SET(DYNAMIC_UCRT_LINK_DEFAULT ON)
ENDIF()
OPTION(DYNAMIC_UCRT_LINK "Link Universal CRT dynamically, if MSVC_CRT_TYPE=/MT" ${DYNAMIC_UCRT_LINK_DEFAULT})
SET(DYNAMIC_UCRT_LINKER_OPTION " /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") SET(DYNAMIC_UCRT_LINKER_OPTION " /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib")
# Enable debug info also in Release build, # Enable debug info also in Release build,
...@@ -191,8 +194,15 @@ IF(MSVC) ...@@ -191,8 +194,15 @@ IF(MSVC)
FOREACH(type EXE SHARED MODULE) FOREACH(type EXE SHARED MODULE)
STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}") STRING(REGEX REPLACE "/STACK:([^ ]+)" "" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}")
STRING(REGEX REPLACE "/INCREMENTAL:([^ ]+)" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO}") IF(WITH_ASAN)
STRING(REGEX REPLACE "/INCREMENTAL$" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO}") SET(build_types RELWITHDEBINFO DEBUG)
ELSE()
SET(build_types RELWITHDEBINFO)
ENDIF()
FOREACH(btype ${build_types})
STRING(REGEX REPLACE "/INCREMENTAL:([^ ]+)" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_${btype} "${CMAKE_${type}_LINKER_FLAGS_${btype}}")
STRING(REGEX REPLACE "/INCREMENTAL$" "/INCREMENTAL:NO" CMAKE_${type}_LINKER_FLAGS_${btype} "${CMAKE_${type}_LINKER_FLAGS_${btype}}")
ENDFOREACH()
IF(NOT CLANG_CL) IF(NOT CLANG_CL)
STRING(APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO " /release /OPT:REF,ICF") STRING(APPEND CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO " /release /OPT:REF,ICF")
ENDIF() ENDIF()
......
...@@ -36,8 +36,8 @@ MACRO(BUNDLE_PCRE2) ...@@ -36,8 +36,8 @@ MACRO(BUNDLE_PCRE2)
IF(MSVC) IF(MSVC)
# Suppress a warning # Suppress a warning
STRING(APPEND pcre2_flags${v} " /wd4244 " ) STRING(APPEND pcre2_flags${v} " /wd4244 " )
# Need this only for ASAN support # Disable asan support
SET(stdlibs "-DCMAKE_C_STANDARD_LIBRARIES=${CMAKE_C_STANDARD_LIBRARIES}") STRING(REPLACE "-fsanitize=address" "" pcre2_flags${v} "${CMAKE_C_FLAGS${v}}")
ENDIF() ENDIF()
ENDFOREACH() ENDFOREACH()
ExternalProject_Add( ExternalProject_Add(
......
...@@ -667,7 +667,11 @@ extern void my_mutex_end(void); ...@@ -667,7 +667,11 @@ extern void my_mutex_end(void);
with the current number of keys and key parts. with the current number of keys and key parts.
*/ */
#if defined(__SANITIZE_ADDRESS__) || defined(WITH_UBSAN) #if defined(__SANITIZE_ADDRESS__) || defined(WITH_UBSAN)
#ifndef DBUG_OFF
#define DEFAULT_THREAD_STACK (1024*1024L)
#else
#define DEFAULT_THREAD_STACK (383*1024L) /* 392192 */ #define DEFAULT_THREAD_STACK (383*1024L) /* 392192 */
#endif
#else #else
#define DEFAULT_THREAD_STACK (292*1024L) /* 299008 */ #define DEFAULT_THREAD_STACK (292*1024L) /* 299008 */
#endif #endif
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
# define MEM_GET_VBITS(a,b,len) VALGRIND_GET_VBITS(a,b,len) # define MEM_GET_VBITS(a,b,len) VALGRIND_GET_VBITS(a,b,len)
# define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len) # define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len)
# define REDZONE_SIZE 8 # define REDZONE_SIZE 8
#elif defined(__SANITIZE_ADDRESS__) #elif defined(__SANITIZE_ADDRESS__) && (!defined(_MSC_VER) || defined (__clang__))
# include <sanitizer/asan_interface.h> # include <sanitizer/asan_interface.h>
/* How to do manual poisoning: /* How to do manual poisoning:
https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */ https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment