-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[windows] improve python3.dll load check #168864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[windows] improve python3.dll load check #168864
Conversation
|
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-lldb Author: Charles Zablit (charles-zablit) ChangesThis patch improves the detection of
This patch ensures that the driver uses the same mechanism as the loader to attempt to load Full diff: https://github.com/llvm/llvm-project/pull/168864.diff 1 Files Affected:
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp
index bebf1a70d50e9..33cce42696372 100644
--- a/lldb/tools/driver/Driver.cpp
+++ b/lldb/tools/driver/Driver.cpp
@@ -477,18 +477,17 @@ bool AddPythonDLLToSearchPath() {
#endif
#ifdef LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME
-/// Returns whether `python3x.dll` is in the DLL search path.
+/// Returns true if `python3x.dll` can be loaded.
bool IsPythonDLLInPath() {
#define WIDEN2(x) L##x
#define WIDEN(x) WIDEN2(x)
- WCHAR foundPath[MAX_PATH];
- DWORD result =
- SearchPathW(nullptr, WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME), nullptr,
- MAX_PATH, foundPath, nullptr);
+ HMODULE h = LoadLibraryW(WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME));
+ if (!h)
+ return false;
+ FreeLibrary(h);
+ return true;
#undef WIDEN2
#undef WIDEN
-
- return result > 0;
}
#endif
|
🐧 Linux x64 Test Results
|
mstorsjo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, looks reasonable.
This has a slight other effect as well; if python3.dll did exist but has missing dependencies, we'd previously mark it as found, while we now would conclude that it's not found. The error message for that would be slightly misleading though, but it's probably not an issue.
| DWORD result = | ||
| SearchPathW(nullptr, WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME), nullptr, | ||
| MAX_PATH, foundPath, nullptr); | ||
| HMODULE h = LoadLibraryW(WIDEN(LLDB_PYTHON_RUNTIME_LIBRARY_FILENAME)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit more expensive. This is going to do the search and load the module (performing any dynamic relocations required) and then follow that with an unload.
I wonder if this is appropriate given that we use this in the start up path.
This patch improves the detection of
python3x.dll.SearchPathWdoes not account forSetDllDirectoryW. Therefore, when manually addingpython3x.dllto the search path,SearchPathWwill still return that it has not been found, resulting in a false negative.This patch ensures that the driver uses the same mechanism as the loader to attempt to load
python3x.dllusingLoadLibraryW.rdar://165123628