Skip to content
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

[lldb][dotest] Add an arg to add DLL search paths. #104514

Closed

Conversation

kendalharland
Copy link
Contributor

@kendalharland kendalharland commented Aug 15, 2024

In python 3.8 PATH is no longer used to search for DLLs on Windows. When building Swift's patched version of LLDB this prevents LLDB from starting up, because it cannot find DLLs like swiftCore.dll, cmark-gfm.dll, etc. This PR adds a flag that can be passed to manually add specific directories as DLL search paths. This is preferred over simply expanding all directories in PATH which would recreate the code-injection security issues that the Python 3.8 change was designed to address.

For context in this change to Python 3.8, see: https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew

Fixes #46235

Related to swiftlang#9141

In python 3.8 PATH is no longer used to search for DLLs
on Windows. When building Swift's patched version of LLDB
this prevents LLDB from starting up, because it cannot find
DLLs like swiftCore.dll, cmark-gfm.dll, etc..

For context in this change to Python 3.8, see:
https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew
@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2024

@llvm/pr-subscribers-lldb

Author: Kendal Harland (kendalharland)

Changes

In python 3.8 PATH is no longer used to search for DLLs on Windows. When building Swift's patched version of LLDB this prevents LLDB from starting up, because it cannot find DLLs like swiftCore.dll, cmark-gfm.dll, etc. This PR adds a flag that can be passed to manually add specific directories as DLL search paths. This is preferred over simply expanding all directories in PATH which would recreate the code-injection security issues that the Python 3.8 change was designed to address.

For context in this change to Python 3.8, see: https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew

Fixes #46235


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

2 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/dotest.py (+4)
  • (modified) lldb/packages/Python/lldbsuite/test/dotest_args.py (+6)
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index f14a00a2394b0b..aa9581a0aedc23 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -219,6 +219,10 @@ def parseOptionsAndInitTestdirs():
     except:
         raise
 
+    if args.dll_directory:
+        for dir in args.dll_directory:
+            os.add_dll_directory(dir)
+
     if args.unset_env_varnames:
         for env_var in args.unset_env_varnames:
             if env_var in os.environ:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec5891..cdcc659df61b1f 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -321,6 +321,12 @@ def create_parser():
         action="append",
         help="Specify an environment variable to set to the given value for the inferior.",
     )
+    # See https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew.
+    group.add_argument(
+        "--dll-directory",
+        action="append",
+        help="Specify a directory to include when searching for .dll files. This can be passed multiple times.",
+    )
     X(
         "-v",
         "Do verbose mode of unittest framework (print out each test case invocation)",

@labath
Copy link
Collaborator

labath commented Aug 16, 2024

Can those swift libraries be found automatically? For example if they're at some known path relative to lldb or the swift compiler?

@kendalharland
Copy link
Contributor Author

Can those swift libraries be found automatically? For example if they're at some known path relative to lldb or the swift compiler?

Yes. They can be copied into the python module where _lldb resides. Help me understand: why is this preferrable over an explicit input to add dll search paths?

@kendalharland
Copy link
Contributor Author

kendalharland commented Aug 16, 2024

Actually, @labath I missed the last suggestion in #46235 which says this can be done by modifying bindings/python.swig. That sounds like something that I can do in Swift's fork? I'll see if that works.

@kendalharland kendalharland marked this pull request as draft August 18, 2024 04:44
@labath
Copy link
Collaborator

labath commented Aug 26, 2024

I think that having fewer knobs that one needs to remember to set to correct values is better. Sometimes that's unavoidable, but I wanted to make sure this is one of those cases. Embedding this information into the swig bindings sounds like a good idea.

@weliveindetail
Copy link
Member

@labath @kendalharland Here is an attempt to fix this in the bindings themselves: swiftlang#9370 What do you think?

@kendalharland
Copy link
Contributor Author

Superceded by swiftlang#9370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"import _lldb" doesn't work on Windows with Python 3.8+
4 participants