Skip to content

Commit 93d3260

Browse files
authored
[lldb] [cmake] Fix delayloading liblldb.dll in mingw builds (#162831)
ec28b95 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.
1 parent 13784f7 commit 93d3260

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lldb/cmake/modules/AddLLDB.cmake

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,19 @@ function(add_lldb_executable name)
170170
if(WIN32)
171171
list(FIND ARG_LINK_LIBS liblldb LIBLLDB_INDEX)
172172
if(NOT LIBLLDB_INDEX EQUAL -1)
173-
target_link_options(${name} PRIVATE "/DELAYLOAD:$<TARGET_FILE_BASE_NAME:liblldb>.dll")
173+
if (MSVC)
174+
target_link_options(${name} PRIVATE "/DELAYLOAD:$<TARGET_FILE_NAME:liblldb>")
175+
elseif (MINGW AND LINKER_IS_LLD)
176+
# LLD can delay load just by passing a --delayload flag, as long as the import
177+
# library is a short type import library (which LLD and MS link.exe produce).
178+
# With ld.bfd, with long import libraries (as produced by GNU binutils), one
179+
# has to generate a separate delayload import library with dlltool.
180+
target_link_options(${name} PRIVATE "-Wl,--delayload=$<TARGET_FILE_NAME:liblldb>")
181+
elseif (DEFINED LLDB_PYTHON_DLL_RELATIVE_PATH)
182+
# If liblldb can't be delayloaded, then LLDB_PYTHON_DLL_RELATIVE_PATH will not
183+
# have any effect.
184+
message(WARNING "liblldb is not delay loaded, LLDB_PYTHON_DLL_RELATIVE_PATH has no effect")
185+
endif()
174186
endif()
175187
endif()
176188
if(CLANG_LINK_CLANG_DYLIB)

0 commit comments

Comments
 (0)