[llvm] [Windows] Avoid loading shared libraries from load directory (PR #90520)

Daniel Paoliello via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 16:03:59 PDT 2024


================
@@ -43,6 +43,10 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
   assert(!Initialized && "InitLLVM was already initialized!");
   Initialized = true;
 #endif
+#ifdef _WIN32
+  // Avoid searching the directory from which the application is loaded.
----------------
dpaoliello wrote:

That's not what `SetDllDirectoryA("")` does, from <https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectorya#parameters>:
"If this parameter is an empty string (""), the call removes the current directory from the default DLL search order."

So, this is removing the current directory (not the directory where the application is loaded) from the search order: that's a good thing.

Except that Windows already prefers system and the application directory over the current directory by default: <https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-unpackaged-apps>

If removing the current directory from the search path is the desired behavior, then I'd recommend using `SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)` instead, since it's much easier to understand.

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


More information about the llvm-commits mailing list