[sanitizers] [windows] Use a linker directive pragma for psapi
authorMartin Storsjo <martin@martin.st>
Wed, 10 Oct 2018 09:03:58 +0000 (09:03 +0000)
committerMartin Storsjo <martin@martin.st>
Wed, 10 Oct 2018 09:03:58 +0000 (09:03 +0000)
This allows users of static libraries (such as ubsan) to link without
knowing about this transitive dependency, if using the psapi functions
that require linking to a separate psapi library. Since Windows 7,
these functions (EnumProcessModules, GetModuleInformation,
GetProcessMemoryInfo) are remapped to K32- prefixed ones, available in
kernel32.dll.

Differential Revision: https://reviews.llvm.org/D53012

llvm-svn: 344126

compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/sanitizer_common/sanitizer_win.cc

index 2460227..4afc8c9 100644 (file)
@@ -100,7 +100,6 @@ append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
 append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
 append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
-append_list_if(MINGW psapi ASAN_DYNAMIC_LIBS)
 
 # Compile ASan sources into an object library.
 
index 38e567d..e8f5919 100644 (file)
 #include "sanitizer_placement_new.h"
 #include "sanitizer_win_defs.h"
 
+#if defined(PSAPI_VERSION) && PSAPI_VERSION == 1
+#pragma comment(lib, "psapi")
+#endif
+
 // A macro to tell the compiler that this part of the code cannot be reached,
 // if the compiler supports this feature. Since we're using this in
 // code that is called when terminating the process, the expansion of the