Skip to content

lldb: link swift's libswift to lldb #3537

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

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lldb/cmake/modules/AddLLDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,40 @@ function(add_lldb_library name)
endif()
endfunction(add_lldb_library)

# BEGIN Swift Mods
function(add_properties_for_swift_modules target)
if (BOOTSTRAPPING_MODE)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|.*HOSTLIBS")
target_link_directories(${target} PRIVATE
"${CMAKE_OSX_SYSROOT}/usr/lib/swift"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks suspicious to me but I also don't fully understand what it does. Does this end up being in an rpath pointing into the build machine's SDK?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For macOS: only in "bootstrapping" mode, which is only used for testing. For other modes the rpath is pointing to /usr/lib/swift.

For Linux: yes, but I couldn't figure out how to fix that. But this is already the case without this change.

"${LLDB_SWIFT_LIBS}/macosx")
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
"/usr/lib/swift")
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
target_link_directories(${target} PRIVATE "${LLDB_SWIFT_LIBS}/macosx")
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
"${LLDB_SWIFT_LIBS}/macosx")
else()
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${BOOTSTRAPPING_MODE}'")
endif()

# Workaround for a linker crash related to autolinking: rdar://77839981
set_property(TARGET ${target} APPEND_STRING PROPERTY
LINK_FLAGS " -lobjc ")
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
string(REGEX MATCH "^[^-]*" arch ${TARGET_TRIPLE})
target_link_libraries(${target} PRIVATE swiftCore-linux-${arch})

# TODO: add "${LLDB_SWIFT_LIBS}/linux" to BUILD_RPATH and not INSTALL_RPATH.
# This does not work for some reason.
set_property(TARGET ${target} APPEND PROPERTY INSTALL_RPATH
"${LLDB_SWIFT_LIBS}/linux;$ORIGIN/../lib/swift/linux")
endif()
endif()
endfunction()
# END Swift Mods

function(add_lldb_executable name)
cmake_parse_arguments(ARG
"GENERATE_INSTALL"
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ add_lldb_library(liblldb SHARED ${option_framework}
${option_install_prefix}
)

# BEGIN Swift Mods
add_properties_for_swift_modules(liblldb)
# END Swift Mods

# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/ExpressionParser/Swift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_lldb_library(lldbPluginExpressionParserSwift PLUGIN
swiftSIL
swiftSILOptimizer
swiftSerialization
swiftCompilerModules
clangAST
clangBasic
clangRewrite
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "swift/AST/Module.h"
#include "swift/AST/Type.h"
#include "swift/AST/Types.h"
#include "swift/Basic/InitializeSwiftModules.h"
#include "swift/Demangling/ManglingMacros.h"
#include "llvm/Support/ConvertUTF.h"

Expand Down Expand Up @@ -79,6 +80,8 @@ void SwiftLanguage::Initialize() {
lldb_private::formatters::NSArray_Additionals::GetAdditionalSynthetics()
.emplace(g_NSArrayClass1,
lldb_private::formatters::swift::ArraySyntheticFrontEndCreator);

initializeSwiftModules();
}

void SwiftLanguage::Terminate() {
Expand Down
4 changes: 4 additions & 0 deletions lldb/tools/lldb-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ add_lldb_tool(lldb-test
Support
)

# BEGIN Swift Mods
add_properties_for_swift_modules(lldb-test)
# END Swift Mods

if(Python3_RPATH)
set_property(TARGET lldb-test APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
set_property(TARGET lldb-test APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}")
Expand Down