Skip to content

Commit 8305829

Browse files
authored
[5.7][cmake] Prevent test failures by disabling LTO for swift runtime (#59631)
(cherry picked from commit a81bb11)
1 parent a226261 commit 8305829

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,12 @@ function(add_swift_target_library name)
16351635
BACK_DEPLOYMENT_LIBRARY)
16361636
set(SWIFTLIB_multiple_parameter_options
16371637
C_COMPILE_FLAGS
1638+
C_COMPILE_FLAGS_IOS
1639+
C_COMPILE_FLAGS_OSX
1640+
C_COMPILE_FLAGS_TVOS
1641+
C_COMPILE_FLAGS_WATCHOS
1642+
C_COMPILE_FLAGS_LINUX
1643+
C_COMPILE_FLAGS_WINDOWS
16381644
DEPENDS
16391645
FILE_DEPENDS
16401646
FRAMEWORK_DEPENDS
@@ -1867,7 +1873,7 @@ function(add_swift_target_library name)
18671873
${SWIFTLIB_FRAMEWORK_DEPENDS_IOS_TVOS})
18681874
endif()
18691875

1870-
# Collect architecutre agnostic compiler flags
1876+
# Collect architecture agnostic swift compiler flags
18711877
set(swiftlib_swift_compile_flags_all ${SWIFTLIB_SWIFT_COMPILE_FLAGS})
18721878
if(${sdk} STREQUAL OSX)
18731879
list(APPEND swiftlib_swift_compile_flags_all
@@ -2023,6 +2029,27 @@ function(add_swift_target_library name)
20232029
set(swiftlib_c_compile_flags_all ${SWIFTLIB_C_COMPILE_FLAGS})
20242030
set(swiftlib_link_flags_all ${SWIFTLIB_LINK_FLAGS})
20252031

2032+
# Collect architecture agnostic c compiler flags
2033+
if(${sdk} STREQUAL OSX)
2034+
list(APPEND swiftlib_c_compile_flags_all
2035+
${SWIFTLIB_C_COMPILE_FLAGS_OSX})
2036+
elseif(${sdk} STREQUAL IOS OR ${sdk} STREQUAL IOS_SIMULATOR)
2037+
list(APPEND swiftlib_c_compile_flags_all
2038+
${SWIFTLIB_C_COMPILE_FLAGS_IOS})
2039+
elseif(${sdk} STREQUAL TVOS OR ${sdk} STREQUAL TVOS_SIMULATOR)
2040+
list(APPEND swiftlib_c_compile_flags_all
2041+
${SWIFTLIB_C_COMPILE_FLAGS_TVOS})
2042+
elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR)
2043+
list(APPEND swiftlib_c_compile_flags_all
2044+
${SWIFTLIB_C_COMPILE_FLAGS_WATCHOS})
2045+
elseif(${sdk} STREQUAL LINUX)
2046+
list(APPEND swiftlib_c_compile_flags_all
2047+
${SWIFTLIB_C_COMPILE_FLAGS_LINUX})
2048+
elseif(${sdk} STREQUAL WINDOWS)
2049+
list(APPEND swiftlib_c_compile_flags_all
2050+
${SWIFTLIB_C_COMPILE_FLAGS_WINDOWS})
2051+
endif()
2052+
20262053
# Add flags to prepend framework search paths for the parallel framework
20272054
# hierarchy rooted at /System/iOSSupport/...
20282055
# These paths must come before their normal counterparts so that when compiling

stdlib/public/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
104104
list(APPEND swift_demangling_cflags -DSWIFT_STDLIB_HAS_TYPE_PRINTING)
105105
endif()
106106

107+
# Gold LTO is unsupported. To prevent tests from failing when building
108+
# with LTO, force swiftDemangling library to compile without LTO for Linux.
107109
add_swift_target_library(swiftDemangling OBJECT_LIBRARY
108110
${swiftDemanglingSources}
109111
C_COMPILE_FLAGS
110112
-DswiftCore_EXPORTS
111113
${swift_demangling_cflags}
114+
C_COMPILE_FLAGS_LINUX -fno-lto
112115
INSTALL_IN_COMPONENT never_install)
113116

114117
add_swift_target_library(swiftDemanglingCR OBJECT_LIBRARY

stdlib/public/runtime/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ foreach(sdk ${SWIFT_SDKS})
130130
endforeach()
131131

132132

133+
# Gold LTO is unsupported. To prevent tests from failing when building
134+
# with LTO, force swift runtime to compile without LTO for Linux.
133135
add_swift_target_library(swiftImageRegistrationObjectELF
134136
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
135137
SwiftRT-ELF.cpp
136138
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
139+
C_COMPILE_FLAGS_LINUX -fno-lto
137140
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
138141
TARGET_SDKS ${ELFISH_SDKS}
139142
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}

0 commit comments

Comments
 (0)