https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/162831

ec28b95b7491bc2fbb6ec66cdbfd939e71255c42 made liblldb delayloaded, but the 
supplied command line parameter is only valid for MSVC style builds.

For mingw builds using LLD, we can easily pass a similar option. For mingw 
builds with ld.bfd, we can't quite as easily delayload it - for these cases, 
just keep linking it like we usually do, and warn if the user tried to set 
LLDB_PYTHON_DLL_RELATIVE_PATH in a build where it won't have any effect.

Also change the setting for MSVC style builds, to use the simpler 
`$<TARGET_FILE_NAME:liblldb>` instead of 
`$<TARGET_FILE_BASE_NAME:liblldb>.dll`. The former pattern is what we use for 
mingw targets, and it makes the code clearer to use that for both, as that same 
expression should do the right thing for both.

From 41999d279135bc91bfd8e663986060a1096f15f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <[email protected]>
Date: Fri, 10 Oct 2025 14:39:39 +0300
Subject: [PATCH] [lldb] [cmake] Fix delayloading liblldb.dll in mingw builds

ec28b95b7491bc2fbb6ec66cdbfd939e71255c42 made liblldb delayloaded,
but the supplied command line parameter is only valid for
MSVC style builds.

For mingw builds using LLD, we can easily pass a similar option.
For mingw builds with ld.bfd, we can't quite as easily delayload
it - for these cases, just keep linking it like we usually do,
and warn if the user tried to set LLDB_PYTHON_DLL_RELATIVE_PATH
in a build where it won't have any effect.

Also change the setting for MSVC style builds, to use
the simpler `$<TARGET_FILE_NAME:liblldb>` instead of
`$<TARGET_FILE_BASE_NAME:liblldb>.dll`. The former pattern is what
we use for mingw targets, and it makes the code clearer to use
that for both, as that same expression should do the right thing
for both.
---
 lldb/cmake/modules/AddLLDB.cmake | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake
index bdd6f73238422..5d58abf237f58 100644
--- a/lldb/cmake/modules/AddLLDB.cmake
+++ b/lldb/cmake/modules/AddLLDB.cmake
@@ -170,7 +170,19 @@ function(add_lldb_executable name)
   if(WIN32)
     list(FIND ARG_LINK_LIBS liblldb LIBLLDB_INDEX)
     if(NOT LIBLLDB_INDEX EQUAL -1)
-      target_link_options(${name} PRIVATE 
"/DELAYLOAD:$<TARGET_FILE_BASE_NAME:liblldb>.dll")
+      if (MSVC)
+        target_link_options(${name} PRIVATE 
"/DELAYLOAD:$<TARGET_FILE_NAME:liblldb>")
+      elseif (MINGW AND LINKER_IS_LLD)
+        # LLD can delay load just by passing a --delayload flag, as long as 
the import
+        # library is a short type import library (which LLD and MS link.exe 
produce).
+        # With ld.bfd, with long import libraries (as produced by GNU 
binutils), one
+        # has to generate a separate delayload import library with dlltool.
+        target_link_options(${name} PRIVATE 
"-Wl,--delayload=$<TARGET_FILE_NAME:liblldb>")
+      elseif (DEFINED LLDB_PYTHON_DLL_RELATIVE_PATH)
+        # If liblldb can't be delayloaded, then LLDB_PYTHON_DLL_RELATIVE_PATH 
will not
+        # have any effect.
+        message(WARNING "liblldb is not delay loaded, 
LLDB_PYTHON_DLL_RELATIVE_PATH has no effect")
+      endif()
     endif()
   endif()
   if(CLANG_LINK_CLANG_DYLIB)

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

Reply via email to