Skip to content

Commit b122d8a

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 8e0325e commit b122d8a

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
@@ -2557,7 +2557,8 @@ endfunction()
25572557
# The Swift installation component that this executable belongs to.
25582558
# Defaults to never_install.
25592559
function(_add_swift_target_executable_single name)
2560-
set(options)
2560+
set(options
2561+
NOSWIFTRT)
25612562
set(single_parameter_options
25622563
ARCHITECTURE
25632564
SDK
@@ -2635,6 +2636,15 @@ function(_add_swift_target_executable_single name)
26352636
${SWIFTEXE_SINGLE_SOURCES}
26362637
${SWIFTEXE_SINGLE_EXTERNAL_SOURCES})
26372638

2639+
# ELF and COFF need swiftrt
2640+
if(("${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
2641+
"${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF")
2642+
AND NOT SWIFTEXE_SINGLE_NOSWIFTRT)
2643+
target_sources(${name}
2644+
PRIVATE
2645+
$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE}>)
2646+
endif()
2647+
26382648
add_dependencies_multiple_targets(
26392649
TARGETS "${name}"
26402650
DEPENDS
@@ -2725,7 +2735,8 @@ function(add_swift_target_executable name)
27252735
EXCLUDE_FROM_ALL
27262736
BUILD_WITH_STDLIB
27272737
BUILD_WITH_LIBEXEC
2728-
PREFER_STATIC)
2738+
PREFER_STATIC
2739+
NOSWIFTRT)
27292740
set(SWIFTEXE_single_parameter_options
27302741
INSTALL_IN_COMPONENT)
27312742
set(SWIFTEXE_multiple_parameter_options
@@ -2928,6 +2939,7 @@ function(add_swift_target_executable name)
29282939

29292940
_add_swift_target_executable_single(
29302941
${VARIANT_NAME}
2942+
${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
29312943
${SWIFTEXE_TARGET_SOURCES}
29322944
DEPENDS
29332945
${SWIFTEXE_TARGET_DEPENDS_with_suffix}

0 commit comments

Comments
 (0)