Skip to content

Commit fae8d20

Browse files
authored
Merge pull request swiftlang#59425 from thevinster/lto
[cmake] Prevent test failures by disabling LTO for swift runtime
2 parents 34445a0 + a81bb11 commit fae8d20

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
@@ -1639,6 +1639,12 @@ function(add_swift_target_library name)
16391639
BACK_DEPLOYMENT_LIBRARY)
16401640
set(SWIFTLIB_multiple_parameter_options
16411641
C_COMPILE_FLAGS
1642+
C_COMPILE_FLAGS_IOS
1643+
C_COMPILE_FLAGS_OSX
1644+
C_COMPILE_FLAGS_TVOS
1645+
C_COMPILE_FLAGS_WATCHOS
1646+
C_COMPILE_FLAGS_LINUX
1647+
C_COMPILE_FLAGS_WINDOWS
16421648
DEPENDS
16431649
FILE_DEPENDS
16441650
FRAMEWORK_DEPENDS
@@ -1871,7 +1877,7 @@ function(add_swift_target_library name)
18711877
${SWIFTLIB_FRAMEWORK_DEPENDS_IOS_TVOS})
18721878
endif()
18731879

1874-
# Collect architecture agnostic compiler flags
1880+
# Collect architecture agnostic swift compiler flags
18751881
set(swiftlib_swift_compile_flags_all ${SWIFTLIB_SWIFT_COMPILE_FLAGS})
18761882
if(${sdk} STREQUAL OSX)
18771883
list(APPEND swiftlib_swift_compile_flags_all
@@ -2027,6 +2033,27 @@ function(add_swift_target_library name)
20272033
set(swiftlib_c_compile_flags_all ${SWIFTLIB_C_COMPILE_FLAGS})
20282034
set(swiftlib_link_flags_all ${SWIFTLIB_LINK_FLAGS})
20292035

2036+
# Collect architecture agnostic c compiler flags
2037+
if(${sdk} STREQUAL OSX)
2038+
list(APPEND swiftlib_c_compile_flags_all
2039+
${SWIFTLIB_C_COMPILE_FLAGS_OSX})
2040+
elseif(${sdk} STREQUAL IOS OR ${sdk} STREQUAL IOS_SIMULATOR)
2041+
list(APPEND swiftlib_c_compile_flags_all
2042+
${SWIFTLIB_C_COMPILE_FLAGS_IOS})
2043+
elseif(${sdk} STREQUAL TVOS OR ${sdk} STREQUAL TVOS_SIMULATOR)
2044+
list(APPEND swiftlib_c_compile_flags_all
2045+
${SWIFTLIB_C_COMPILE_FLAGS_TVOS})
2046+
elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR)
2047+
list(APPEND swiftlib_c_compile_flags_all
2048+
${SWIFTLIB_C_COMPILE_FLAGS_WATCHOS})
2049+
elseif(${sdk} STREQUAL LINUX)
2050+
list(APPEND swiftlib_c_compile_flags_all
2051+
${SWIFTLIB_C_COMPILE_FLAGS_LINUX})
2052+
elseif(${sdk} STREQUAL WINDOWS)
2053+
list(APPEND swiftlib_c_compile_flags_all
2054+
${SWIFTLIB_C_COMPILE_FLAGS_WINDOWS})
2055+
endif()
2056+
20302057
# Add flags to prepend framework search paths for the parallel framework
20312058
# hierarchy rooted at /System/iOSSupport/...
20322059
# 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
@@ -105,11 +105,14 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
105105
list(APPEND swift_demangling_cflags -DSWIFT_STDLIB_HAS_TYPE_PRINTING)
106106
endif()
107107

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

115118
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
@@ -128,10 +128,13 @@ foreach(sdk ${SWIFT_SDKS})
128128
endforeach()
129129

130130

131+
# Gold LTO is unsupported. To prevent tests from failing when building
132+
# with LTO, force swift runtime to compile without LTO for Linux.
131133
add_swift_target_library(swiftImageRegistrationObjectELF
132134
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
133135
SwiftRT-ELF.cpp
134136
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
137+
C_COMPILE_FLAGS_LINUX -fno-lto
135138
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
136139
TARGET_SDKS ${ELFISH_SDKS}
137140
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}

0 commit comments

Comments
 (0)