https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/200843

When building with `LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS` on Windows, there 
were a few issues:

1. Building `lldb` didn't build the shared library for the script interpreter. 
This was fixed by adding a dependency on `lldbPluginScriptInterpreterPython`. 
I'm not sure how this works on other platforms.
2. The library failed to link, because symbols for LLVMSupport were missing. I 
added `Support` as a dependency. Are the symbols resolved through liblldb on 
other platforms?
3. After adding Support, the library failed to find 
`lldb_private::File::kInvalidDescriptor`. The fix is rather hacky, because it 
declares the static as `constexpr static`. Again, my guess is that this 
resolves through liblldb on other platforms where symbols are always exported.

With this, you can build lldb, but it still fails to load the plugin. I'll fix 
that in a followup.

>From 051c4c84ac4c6d033c4cdb46272e0d0a7d5accf8 Mon Sep 17 00:00:00 2001
From: Nerixyz <[email protected]>
Date: Mon, 1 Jun 2026 16:30:50 +0200
Subject: [PATCH] [lldb] Fix Windows build with dynamic Python plugin

---
 lldb/bindings/python/CMakeLists.txt                    |  3 +++
 lldb/include/lldb/Host/FileBase.h                      |  2 +-
 lldb/source/Host/common/File.cpp                       |  1 -
 .../Plugins/ScriptInterpreter/Python/CMakeLists.txt    | 10 ++++++++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lldb/bindings/python/CMakeLists.txt 
b/lldb/bindings/python/CMakeLists.txt
index 2916d004a389e..d76b4d5f4951e 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -157,6 +157,9 @@ function(finish_swig_python swig_target 
lldb_python_bindings_dir lldb_python_tar
   create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST}
                           ${lldb_python_target_dir}/native/ 
${LIBLLDB_SYMLINK_OUTPUT_FILE})
 
+  if (LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS)
+    add_dependencies(${swig_target} lldbPluginScriptInterpreterPython)
+  endif()
 
   if (NOT WIN32)
   add_dependencies(${swig_target} lldb-python-wrapper)
diff --git a/lldb/include/lldb/Host/FileBase.h 
b/lldb/include/lldb/Host/FileBase.h
index 54ca89f3201c6..bc0b2914ded8c 100644
--- a/lldb/include/lldb/Host/FileBase.h
+++ b/lldb/include/lldb/Host/FileBase.h
@@ -33,7 +33,7 @@ LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 /// or stream functionality but are not backed by any host OS file.
 class File : public IOObject {
 public:
-  static int kInvalidDescriptor;
+  static constexpr int kInvalidDescriptor = -1;
   static FILE *kInvalidStream;
 
   // NB this enum is used in the lldb platform gdb-remote packet
diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 499df4e542ab2..a863e323c65ff 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -93,7 +93,6 @@ Expected<File::OpenOptions> 
File::GetOptionsFromMode(llvm::StringRef mode) {
       "invalid mode, cannot convert to File::OpenOptions");
 }
 
-int File::kInvalidDescriptor = -1;
 FILE *File::kInvalidStream = nullptr;
 
 Status File::Read(void *buf, size_t &num_bytes) {
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
index 574dcdf874ada..55d8b6060486c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -48,6 +48,8 @@ if (LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS)
   # resolved via liblldb's re-exports, so lldb_private libs aren't linked here.
   add_lldb_library(lldbPluginScriptInterpreterPython SHARED
     ${python_plugin_sources}
+    LINK_COMPONENTS
+      Support
     LINK_LIBS
       liblldb
       ${Python3_LIBRARIES}
@@ -78,6 +80,14 @@ if (LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS)
 
   target_link_directories(lldbPluginScriptInterpreterPython PRIVATE 
${PYTHON_SABI_LIBRARY_DIRS})
   target_link_directories(lldbStaticScriptInterpreterPython PUBLIC 
${PYTHON_SABI_LIBRARY_DIRS})
+  if(WIN32 AND NOT MINGW)
+    # Windows doesn't have "lib" as CMAKE_SHARED_LIBRARY_PREFIX. To be
+    # consistent with Unix, the output is still prefixed with "lib".
+    set_target_properties(lldbPluginScriptInterpreterPython
+      PROPERTIES
+      OUTPUT_NAME liblldbPluginScriptInterpreterPython
+    )
+  endif()
 else()
   add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN
     ${python_plugin_sources}

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to