diff --git a/src/native/corehost/CMakeLists.txt b/src/native/corehost/CMakeLists.txt index 5ce72395e49f7f..998836366d4806 100644 --- a/src/native/corehost/CMakeLists.txt +++ b/src/native/corehost/CMakeLists.txt @@ -87,6 +87,7 @@ if ((NOT DEFINED CLR_CMAKE_USE_SYSTEM_RAPIDJSON) OR (NOT CLR_CMAKE_USE_SYSTEM_RA include_directories(${CLR_SRC_NATIVE_DIR}/external/) endif() +add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal/ minipal) add_subdirectory(hostcommon) add_subdirectory(hostmisc) add_subdirectory(fxr) diff --git a/src/native/minipal/CMakeLists.txt b/src/native/minipal/CMakeLists.txt index 8ebacd8cd6f404..f2cf2c6d1c8fa0 100644 --- a/src/native/minipal/CMakeLists.txt +++ b/src/native/minipal/CMakeLists.txt @@ -36,8 +36,17 @@ endif() add_library(minipal STATIC) target_link_libraries(minipal PRIVATE minipal_objects) +set(SANITIZER_EXPORTS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/sanitizer_exports.def) + add_library(minipal_sanitizer_support OBJECT sansupport.c) + +set_source_files_properties(sansupport.c PROPERTIES OBJECT_DEPENDS ${SANITIZER_EXPORTS_FILE}) + +if (MSVC) + target_link_options(minipal_sanitizer_support INTERFACE /DEF:${SANITIZER_EXPORTS_FILE}) +endif() + # Exclude this target from the default build as we may not have sanitzer headers available # in a non-sanitized build. set_target_properties(minipal_sanitizer_support PROPERTIES EXCLUDE_FROM_ALL ON) diff --git a/src/native/minipal/sanitizer_exports.def b/src/native/minipal/sanitizer_exports.def new file mode 100644 index 00000000000000..464b82c571ac9e --- /dev/null +++ b/src/native/minipal/sanitizer_exports.def @@ -0,0 +1,6 @@ +; Licensed to the .NET Foundation under one or more agreements. +; The .NET Foundation licenses this file to you under the MIT license. + +EXPORTS + __asan_default_options + __asan_on_error diff --git a/src/native/minipal/sansupport.c b/src/native/minipal/sansupport.c index d6474e21791a3b..952538e27efde2 100644 --- a/src/native/minipal/sansupport.c +++ b/src/native/minipal/sansupport.c @@ -6,6 +6,11 @@ // Use a typedef here as __declspec + pointer return type causes a parse error in MSVC typedef const char* charptr_t; +// This file may be built as C++ in our Windows builds. Make sure we get the linkage right. +#ifdef __cplusplus +extern "C" +{ +#endif charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void) { // symbolize=1 to get symbolized stack traces @@ -20,3 +25,7 @@ charptr_t SANITIZER_CALLBACK_CALLCONV __asan_default_options(void) { void SANITIZER_CALLBACK_CALLCONV __asan_on_error(void) { } + +#ifdef __cplusplus +} +#endif diff --git a/src/native/minipal/utils.h b/src/native/minipal/utils.h index de25c457341e4f..928e461255e624 100644 --- a/src/native/minipal/utils.h +++ b/src/native/minipal/utils.h @@ -63,13 +63,8 @@ #endif #if defined(_MSC_VER) -# ifdef SANITIZER_SHARED_RUNTIME -# define SANITIZER_CALLBACK_CALLCONV __declspec(dllexport no_sanitize_address) __cdecl -# define SANITIZER_INTERFACE_CALLCONV __declspec(dllimport) __cdecl -# else -# define SANITIZER_CALLBACK_CALLCONV __declspec(no_sanitize_address) __cdecl -# define SANITIZER_INTERFACE_CALLCONV __cdecl -# endif +# define SANITIZER_CALLBACK_CALLCONV __declspec(no_sanitize_address) __cdecl +# define SANITIZER_INTERFACE_CALLCONV __cdecl #else # ifdef SANITIZER_SHARED_RUNTIME # define SANITIZER_CALLBACK_CALLCONV __attribute__((no_address_safety_analysis)) __attribute__((visibility("default")))