summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjarcherNV <jarcher@nvidia.com>2025-09-04 21:35:34 -0700
committerGitHub <noreply@github.com>2025-09-05 04:35:34 +0000
commit5500f11768d4d93eef4dfcecf0821fee747bf1a4 (patch)
treecfd73eb93a99fa25f8ef5d64b302a6eb2a3e48b3
parent1e1ff8a1254c114f261271ffe5580183b8402e32 (diff)
Try both LoadLibrary functions on Windows (#8368)
If a given library cannot be found using LoadLibraryExA then try again using LoadLibraryA. Return an error only if both of these failed.
-rw-r--r--source/core/slang-platform.cpp11
-rw-r--r--tests/cpp-compiler/c-compile-shared-library.c3
-rw-r--r--tests/cpp-compiler/cpp-compile-shared-library.cpp3
3 files changed, 12 insertions, 5 deletions
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index c61677673..7f79d99e1 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -125,8 +125,17 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
return SLANG_OK;
}
+ // We try to search the DLL in two different attempts.
+ // First attempt tries on the directories explicitly specified with AddDllDirectory(),
+ // If it failed to find one, we will search over all PATH.
+ // Windows API made two approaches mutually exclusive and we need to try two times.
// https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
- const HMODULE h = LoadLibraryExA(platformFileName, nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
+ HMODULE h = LoadLibraryExA(platformFileName, nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS);
+ // If LoadLibraryExA failed, try again with LoadLibraryA.
+ // https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya
+ if (!h)
+ h = LoadLibraryA(platformFileName);
+ // If still not found, return an error.
if (!h)
{
const DWORD lastError = GetLastError();
diff --git a/tests/cpp-compiler/c-compile-shared-library.c b/tests/cpp-compiler/c-compile-shared-library.c
index 7bf439f1e..5af13b4c9 100644
--- a/tests/cpp-compiler/c-compile-shared-library.c
+++ b/tests/cpp-compiler/c-compile-shared-library.c
@@ -1,5 +1,4 @@
-// This test is failing due to a regression github issue #8362
-// DISABLE_TEST(smoke,shared-library):CPP_COMPILER_SHARED_LIBRARY:
+// TEST(smoke,shared-library):CPP_COMPILER_SHARED_LIBRARY:
#include <stdio.h>
#include <stdlib.h>
diff --git a/tests/cpp-compiler/cpp-compile-shared-library.cpp b/tests/cpp-compiler/cpp-compile-shared-library.cpp
index cd192d9f6..a69e22899 100644
--- a/tests/cpp-compiler/cpp-compile-shared-library.cpp
+++ b/tests/cpp-compiler/cpp-compile-shared-library.cpp
@@ -1,5 +1,4 @@
-// This test is failing due to a regression github issue #8362
-// DISABLE_TEST(smoke):CPP_COMPILER_SHARED_LIBRARY:
+// TEST(smoke):CPP_COMPILER_SHARED_LIBRARY:
#include <iostream>
#include <stdio.h>