[llvm] [Windows] Use absolute path when loading system shared library (PR #90520)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 13:28:45 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-llvm-support

Author: None (jofrn)

<details>
<summary>Changes</summary>

Find and use absolute path to system shared library instead of relative path.

---
Full diff: https://github.com/llvm/llvm-project/pull/90520.diff


2 Files Affected:

- (modified) llvm/lib/Support/CMakeLists.txt (+16) 
- (modified) llvm/lib/Support/Windows/Signals.inc (+6-3) 


``````````diff
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 03e888958a0711..46a9ffea50fc39 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -41,6 +41,22 @@ if( MSVC OR MINGW )
   # libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
   # advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
   set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 ws2_32)
+  # find dbgcore.dll and dbghelp.dll together in their system folder,
+  # required for lib/Support/Windows/Signals.inc.
+  set(tempsuffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
+  set(CMAKE_FIND_LIBRARY_SUFFIXES .DLL ${CMAKE_FIND_LIBRARY_SUFFIXES})
+  find_library(DBGCORE dbgcore REQUIRED NO_CACHE)
+  cmake_path(GET DBGCORE PARENT_PATH DBGSYSPATH)
+  find_library(DBGHELP dbghelp REQUIRED HINTS "${DBGSYSPATH}" NO_DEFAULT_PATH NO_CACHE)
+  cmake_path(CONVERT "${DBGCORE}" TO_NATIVE_PATH_LIST DBGCORE)
+  cmake_path(CONVERT "${DBGHELP}" TO_NATIVE_PATH_LIST DBGHELP)
+  string(REPLACE "\\" "\\\\" DBGCORE "${DBGCORE}")
+  string(REPLACE "\\" "\\\\" DBGHELP "${DBGHELP}")
+  message("-DDBGCORE is ${DBGCORE}")
+  message("-DDBGHELP is ${DBGHELP}")
+  add_compile_definitions(DBGCOREDLL="${DBGCORE}"
+                          DBGHELPDLL="${DBGHELP}")
+  set(CMAKE_FIND_LIBRARY_SUFFIXES ${tempsuffixes})
 elseif( CMAKE_HOST_UNIX )
   if( HAVE_LIBRT )
     set(system_libs ${system_libs} rt)
diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc
index 34635b5aba7a1b..c4cfc19553b9ad 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -168,10 +168,13 @@ static bool isDebugHelpInitialized() {
 }
 
 static bool load64BitDebugHelp(void) {
-  HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll");
-  if (hLib) {
+  HMODULE hLibCore = ::LoadLibraryW(L"" DBGCOREDLL);
+  if (hLibCore) {
     fMiniDumpWriteDump =
-        (fpMiniDumpWriteDump)::GetProcAddress(hLib, "MiniDumpWriteDump");
+        (fpMiniDumpWriteDump)::GetProcAddress(hLibCore, "MiniDumpWriteDump");
+  }
+  HMODULE hLib = ::LoadLibraryW(L"" DBGHELPDLL);
+  if (hLib) {
     fStackWalk64 = (fpStackWalk64)::GetProcAddress(hLib, "StackWalk64");
     fSymGetModuleBase64 =
         (fpSymGetModuleBase64)::GetProcAddress(hLib, "SymGetModuleBase64");

``````````

</details>


https://github.com/llvm/llvm-project/pull/90520


More information about the llvm-commits mailing list