Skip to content

Commit eea804b

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 3b8a233 commit eea804b

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
@@ -2545,7 +2545,8 @@ endfunction()
25452545
# The Swift installation component that this executable belongs to.
25462546
# Defaults to never_install.
25472547
function(_add_swift_target_executable_single name)
2548-
set(options)
2548+
set(options
2549+
NOSWIFTRT)
25492550
set(single_parameter_options
25502551
ARCHITECTURE
25512552
SDK
@@ -2623,6 +2624,15 @@ function(_add_swift_target_executable_single name)
26232624
${SWIFTEXE_SINGLE_SOURCES}
26242625
${SWIFTEXE_SINGLE_EXTERNAL_SOURCES})
26252626

2627+
# ELF and COFF need swiftrt
2628+
if(("${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
2629+
"${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF")
2630+
AND NOT SWIFTEXE_SINGLE_NOSWIFTRT)
2631+
target_sources(${name}
2632+
PRIVATE
2633+
$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}>)
2634+
endif()
2635+
26262636
add_dependencies_multiple_targets(
26272637
TARGETS "${name}"
26282638
DEPENDS
@@ -2713,7 +2723,8 @@ function(add_swift_target_executable name)
27132723
EXCLUDE_FROM_ALL
27142724
BUILD_WITH_STDLIB
27152725
BUILD_WITH_LIBEXEC
2716-
PREFER_STATIC)
2726+
PREFER_STATIC
2727+
NOSWIFTRT)
27172728
set(SWIFTEXE_single_parameter_options
27182729
INSTALL_IN_COMPONENT)
27192730
set(SWIFTEXE_multiple_parameter_options
@@ -2916,6 +2927,7 @@ function(add_swift_target_executable name)
29162927

29172928
_add_swift_target_executable_single(
29182929
${VARIANT_NAME}
2930+
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
29192931
${SWIFTEXE_TARGET_SOURCES}
29202932
DEPENDS
29212933
${SWIFTEXE_TARGET_DEPENDS_with_suffix}

0 commit comments

Comments
 (0)