Skip to content

Commit 9d5ce54

Browse files
committed
[Linux] Make sure we link with swiftrt on ELF/COFF platforms.
This was causing `swift-backtrace` to crash when linked with the static version of the runtime, because the runtime then couldn't locate any of the necessary metadata. rdar://115278959
1 parent 2efd1be commit 9d5ce54

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,8 @@ endfunction()
25772577
# The Swift installation component that this executable belongs to.
25782578
# Defaults to never_install.
25792579
function(_add_swift_target_executable_single name)
2580-
set(options)
2580+
set(options
2581+
NOSWIFTRT)
25812582
set(single_parameter_options
25822583
ARCHITECTURE
25832584
SDK
@@ -2655,6 +2656,15 @@ function(_add_swift_target_executable_single name)
26552656
${SWIFTEXE_SINGLE_SOURCES}
26562657
${SWIFTEXE_SINGLE_EXTERNAL_SOURCES})
26572658

2659+
# ELF and COFF need swiftrt
2660+
if(("${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
2661+
"${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF")
2662+
AND NOT SWIFTEXE_SINGLE_NOSWIFTRT)
2663+
target_sources(${name}
2664+
PRIVATE
2665+
$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}>)
2666+
endif()
2667+
26582668
add_dependencies_multiple_targets(
26592669
TARGETS "${name}"
26602670
DEPENDS
@@ -2745,7 +2755,8 @@ function(add_swift_target_executable name)
27452755
EXCLUDE_FROM_ALL
27462756
BUILD_WITH_STDLIB
27472757
BUILD_WITH_LIBEXEC
2748-
PREFER_STATIC)
2758+
PREFER_STATIC
2759+
NOSWIFTRT)
27492760
set(SWIFTEXE_single_parameter_options
27502761
INSTALL_IN_COMPONENT)
27512762
set(SWIFTEXE_multiple_parameter_options
@@ -2948,6 +2959,7 @@ function(add_swift_target_executable name)
29482959

29492960
_add_swift_target_executable_single(
29502961
${VARIANT_NAME}
2962+
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
29512963
${SWIFTEXE_TARGET_SOURCES}
29522964
DEPENDS
29532965
${SWIFTEXE_TARGET_DEPENDS_with_suffix}

0 commit comments

Comments
 (0)