From febe274260f89d5126d7a691d08dcc2ab664d209 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 14 Jun 2022 00:40:02 -0700 Subject: [PATCH] [5.7][cmake] Prevent test failures by disabling LTO for swift runtime (cherry picked from commit a81bb11f35912b08355865232688d7e9cff4eeaa) --- stdlib/cmake/modules/AddSwiftStdlib.cmake | 29 ++++++++++++++++++++++- stdlib/public/CMakeLists.txt | 3 +++ stdlib/public/runtime/CMakeLists.txt | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index f81f9856149fa..b41261feb2b9d 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -1635,6 +1635,12 @@ function(add_swift_target_library name) BACK_DEPLOYMENT_LIBRARY) set(SWIFTLIB_multiple_parameter_options C_COMPILE_FLAGS + C_COMPILE_FLAGS_IOS + C_COMPILE_FLAGS_OSX + C_COMPILE_FLAGS_TVOS + C_COMPILE_FLAGS_WATCHOS + C_COMPILE_FLAGS_LINUX + C_COMPILE_FLAGS_WINDOWS DEPENDS FILE_DEPENDS FRAMEWORK_DEPENDS @@ -1867,7 +1873,7 @@ function(add_swift_target_library name) ${SWIFTLIB_FRAMEWORK_DEPENDS_IOS_TVOS}) endif() - # Collect architecutre agnostic compiler flags + # Collect architecture agnostic swift compiler flags set(swiftlib_swift_compile_flags_all ${SWIFTLIB_SWIFT_COMPILE_FLAGS}) if(${sdk} STREQUAL OSX) list(APPEND swiftlib_swift_compile_flags_all @@ -2023,6 +2029,27 @@ function(add_swift_target_library name) set(swiftlib_c_compile_flags_all ${SWIFTLIB_C_COMPILE_FLAGS}) set(swiftlib_link_flags_all ${SWIFTLIB_LINK_FLAGS}) + # Collect architecture agnostic c compiler flags + if(${sdk} STREQUAL OSX) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_OSX}) + elseif(${sdk} STREQUAL IOS OR ${sdk} STREQUAL IOS_SIMULATOR) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_IOS}) + elseif(${sdk} STREQUAL TVOS OR ${sdk} STREQUAL TVOS_SIMULATOR) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_TVOS}) + elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_WATCHOS}) + elseif(${sdk} STREQUAL LINUX) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_LINUX}) + elseif(${sdk} STREQUAL WINDOWS) + list(APPEND swiftlib_c_compile_flags_all + ${SWIFTLIB_C_COMPILE_FLAGS_WINDOWS}) + endif() + # Add flags to prepend framework search paths for the parallel framework # hierarchy rooted at /System/iOSSupport/... # These paths must come before their normal counterparts so that when compiling diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index 31c17f91c29b5..f4b836ab41d44 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -104,11 +104,14 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR) list(APPEND swift_demangling_cflags -DSWIFT_STDLIB_HAS_TYPE_PRINTING) endif() + # Gold LTO is unsupported. To prevent tests from failing when building + # with LTO, force swiftDemangling library to compile without LTO for Linux. add_swift_target_library(swiftDemangling OBJECT_LIBRARY ${swiftDemanglingSources} C_COMPILE_FLAGS -DswiftCore_EXPORTS ${swift_demangling_cflags} + C_COMPILE_FLAGS_LINUX -fno-lto INSTALL_IN_COMPONENT never_install) add_swift_target_library(swiftDemanglingCR OBJECT_LIBRARY diff --git a/stdlib/public/runtime/CMakeLists.txt b/stdlib/public/runtime/CMakeLists.txt index e87bda0ed6057..037634b351fb3 100644 --- a/stdlib/public/runtime/CMakeLists.txt +++ b/stdlib/public/runtime/CMakeLists.txt @@ -130,10 +130,13 @@ foreach(sdk ${SWIFT_SDKS}) endforeach() +# Gold LTO is unsupported. To prevent tests from failing when building +# with LTO, force swift runtime to compile without LTO for Linux. add_swift_target_library(swiftImageRegistrationObjectELF OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE SwiftRT-ELF.cpp C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS} + C_COMPILE_FLAGS_LINUX -fno-lto LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS} TARGET_SDKS ${ELFISH_SDKS} SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}