[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:14 PDT 2024


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

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

>From 4c78b147d8cc7682cfacb8a206b472b04a3a5c21 Mon Sep 17 00:00:00 2001
From: jofernau <jofernau at amd.com>
Date: Mon, 29 Apr 2024 13:17:40 -0700
Subject: [PATCH] [Windows] Find absolute path to dll

---
 llvm/lib/Support/CMakeLists.txt      | 16 ++++++++++++++++
 llvm/lib/Support/Windows/Signals.inc |  9 ++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

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");



More information about the llvm-commits mailing list