[PATCH] D53012: [compiler-rt] [sanitizers] [windows] Use a linker directive pragma for psapi

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 9 01:15:52 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, smeenai.
Herald added subscribers: Sanitizers, mgorny, dberris, kubamracek.

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.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D53012

Files:
  lib/asan/CMakeLists.txt
  lib/sanitizer_common/sanitizer_win.cc


Index: lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_win.cc
+++ lib/sanitizer_common/sanitizer_win.cc
@@ -29,6 +29,14 @@
 #include "sanitizer_placement_new.h"
 #include "sanitizer_win_defs.h"
 
+#if defined(PSAPI_VERSION) && PSAPI_VERSION == 1
+#ifdef __MINGW32__
+#pragma comment(lib, "libpsapi.a")
+#else
+#pragma comment(lib, "psapi")
+#endif
+#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
Index: lib/asan/CMakeLists.txt
===================================================================
--- lib/asan/CMakeLists.txt
+++ lib/asan/CMakeLists.txt
@@ -100,7 +100,6 @@
 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.
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53012.168753.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181009/8f6c30b2/attachment.bin>


More information about the llvm-commits mailing list