From 7c2230bc564ccd0456e78d6817ca63dab32c5d08 Mon Sep 17 00:00:00 2001 From: Thomas Roughton Date: Thu, 1 Feb 2018 11:19:32 +1300 Subject: [PATCH 1/2] Fix cross-compilation for the Windows stdlib Disable SwiftPrivate, remove -Wl,-z,defs, and use the VFS overlay for compiling the runtime. --- cmake/modules/AddSwift.cmake | 19 +++++++++++++++++++ cmake/modules/SwiftSharedCMakeConfig.cmake | 14 +++++++++++--- .../public/SwiftRemoteMirror/CMakeLists.txt | 3 --- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 19bf77720ec1c..ed96bd97c4ed4 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -734,6 +734,7 @@ function(_add_swift_library_single target name) swift_windows_generate_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS) foreach(flag ${SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS}) list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;${flag}) + list(APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS ${flag}) endforeach() foreach(directory ${SWIFTLIB_INCLUDE}) list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xfrontend;-I${directory}) @@ -1474,6 +1475,11 @@ function(add_swift_library name) continue() endif() + # TODO: Currently SwiftPrivate runs into linker problems on Windows. See SR-6489. + if ("${sdk}" STREQUAL "WINDOWS" AND "${name}" MATCHES "SwiftPrivate") + continue() + endif() + set(THIN_INPUT_TARGETS) # For each architecture supported by this SDK @@ -1613,6 +1619,19 @@ function(add_swift_library name) endif() endif() + # We unconditionally removed "-z,defs" from CMAKE_SHARED_LINKER_FLAGS in + # swift_common_standalone_build_config_llvm within SwiftSharedCMakeConfig.cmake, + # where it was added by a call to HandleLLVMOptions. + # + # Rather than applying it to all targets and libraries, we here add it back to + # supported targets and libraries only. + # This is needed for ELF targets only; however, RemoteMirror needs to build + # with undefined symbols. + if("${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" + AND NOT "${name}" STREQUAL "swiftRemoteMirror") + list(APPEND swiftlib_link_flags_all "-Wl,-z,defs") + endif() + # Add this library variant. _add_swift_library_single( ${VARIANT_NAME} diff --git a/cmake/modules/SwiftSharedCMakeConfig.cmake b/cmake/modules/SwiftSharedCMakeConfig.cmake index a832224ece6e8..ad012b5a22742 100644 --- a/cmake/modules/SwiftSharedCMakeConfig.cmake +++ b/cmake/modules/SwiftSharedCMakeConfig.cmake @@ -78,9 +78,17 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling) include(AddSwiftTableGen) # This imports TableGen from LLVM. include(HandleLLVMOptions) - # HACK: this ugly tweaking is to prevent the propagation of the flag from LLVM - # into swift. The use of this flag pollutes all targets, and we are not able - # to remove it on a per-target basis which breaks cross-compilation. + # HACK: Not all targets support -z,defs as a linker flag. + # + # Normally, LLVM would only add it as an option for known ELF targets; + # however, due to the custom scheme Swift uses for cross-compilation, the + # CMAKE_SHARED_LINKER_FLAGS are determined based on the host system and + # then applied to all targets. This causes issues in cross-compiling to + # Windows from a Linux host. + # + # To work around this, we unconditionally remove the flag here and then + # selectively add it to the per-target link flags; this is currently done + # in add_swift_library within AddSwift.cmake. string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") diff --git a/stdlib/public/SwiftRemoteMirror/CMakeLists.txt b/stdlib/public/SwiftRemoteMirror/CMakeLists.txt index bacdf0da01a82..f00b6c5200a75 100644 --- a/stdlib/public/SwiftRemoteMirror/CMakeLists.txt +++ b/stdlib/public/SwiftRemoteMirror/CMakeLists.txt @@ -1,6 +1,3 @@ -# HACK: Force this library to build with undefined symbols. -string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") - # libswiftRemoteMirror.dylib should not have runtime dependencies; it's # always built as a shared library. if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR) From 5173e3c7993a086d6d2698f2cff9ea4cf16e05d2 Mon Sep 17 00:00:00 2001 From: Thomas Roughton Date: Tue, 20 Feb 2018 22:21:54 +1300 Subject: [PATCH 2/2] SwiftPrivate now builds on Windows with Pull-14710 --- cmake/modules/AddSwift.cmake | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index ed96bd97c4ed4..b0eee5f302245 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -1475,11 +1475,6 @@ function(add_swift_library name) continue() endif() - # TODO: Currently SwiftPrivate runs into linker problems on Windows. See SR-6489. - if ("${sdk}" STREQUAL "WINDOWS" AND "${name}" MATCHES "SwiftPrivate") - continue() - endif() - set(THIN_INPUT_TARGETS) # For each architecture supported by this SDK