diff --git a/CMakeLists.txt b/CMakeLists.txt index baeb525d1f737..d699d69d04a50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,24 +147,20 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING set(CLANG_COMPILER_VERSION "" CACHE STRING "The internal version of the Clang compiler") -# Indicate whether Swift should attempt to use the lld linker. -if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - set(SWIFT_ENABLE_LLD_LINKER_default TRUE) +# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use +# our own defaults. This should only be possible in a unified (not stand alone) +# build environment. +if(LLVM_USE_LINKER) + set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}") +elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + set(SWIFT_USE_LINKER_default "lld") +elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(SWIFT_USE_LINKER_default "") else() - set(SWIFT_ENABLE_LLD_LINKER_default FALSE) + set(SWIFT_USE_LINKER_default "gold") endif() -set(SWIFT_ENABLE_LLD_LINKER ${SWIFT_ENABLE_LLD_LINKER_default} CACHE BOOL - "Enable using the lld linker when available") - -# Indicate whether Swift should attempt to use the gold linker. -# This is not used on Darwin. -if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL Windows) - set(SWIFT_ENABLE_GOLD_LINKER_default FALSE) -else() - set(SWIFT_ENABLE_GOLD_LINKER_default TRUE) -endif() -set(SWIFT_ENABLE_GOLD_LINKER ${SWIFT_ENABLE_GOLD_LINKER_default} CACHE BOOL - "Enable using the gold linker when available") +set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING + "Build Swift with a non-default linker") set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One must specify the form of LTO by setting this to one of: 'full', 'thin'. This diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index ae109498abce4..ff24b14198b4a 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -116,7 +116,7 @@ function(_add_host_variant_c_compile_link_flags name) if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID) # lld can handle targeting the android build. However, if lld is not # enabled, then fallback to the linker included in the android NDK. - if(NOT SWIFT_ENABLE_LLD_LINKER) + if(NOT SWIFT_USE_LINKER STREQUAL "lld") swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path) target_compile_options(${name} PRIVATE -B${tools_path}) endif() @@ -368,12 +368,9 @@ function(_add_host_variant_link_flags target) endif() if(NOT SWIFT_COMPILER_IS_MSVC_LIKE) - if(SWIFT_ENABLE_LLD_LINKER) + if(SWIFT_USE_LINKER) target_link_options(${target} PRIVATE - -fuse-ld=lld$<$:.exe>) - elseif(SWIFT_ENABLE_GOLD_LINKER) - target_link_options(${target} PRIVATE - -fuse-ld=gold$<$:.exe>) + -fuse-ld=${SWIFT_USE_LINKER}$<$:.exe>) endif() endif() diff --git a/cmake/modules/AddSwiftUnittests.cmake b/cmake/modules/AddSwiftUnittests.cmake index e088997741eb1..811b455bd3ed2 100644 --- a/cmake/modules/AddSwiftUnittests.cmake +++ b/cmake/modules/AddSwiftUnittests.cmake @@ -57,15 +57,9 @@ function(add_swift_unittest test_dirname) _ENABLE_EXTENDED_ALIGNED_STORAGE) endif() - find_program(LDLLD_PATH "ld.lld") - # Strangely, macOS finds lld and then can't find it when using -fuse-ld= - if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) + if(SWIFT_USE_LINKER) set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY - LINK_FLAGS " -fuse-ld=lld") - elseif(SWIFT_ENABLE_GOLD_LINKER AND - "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF") - set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY - LINK_FLAGS " -fuse-ld=gold") + LINK_FLAGS " -fuse-ld=${SWIFT_USE_LINKER}") endif() if(SWIFT_ANALYZE_CODE_COVERAGE) diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 8a4432fb46a0a..05123d1d8e127 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -93,7 +93,7 @@ function(_add_target_variant_c_compile_link_flags) if("${CFLAGS_SDK}" STREQUAL "ANDROID") # lld can handle targeting the android build. However, if lld is not # enabled, then fallback to the linker included in the android NDK. - if(NOT SWIFT_ENABLE_LLD_LINKER) + if(NOT SWIFT_USE_LINKER STREQUAL "lld") swift_android_tools_path(${CFLAGS_ARCH} tools_path) list(APPEND result "-B" "${tools_path}") endif() @@ -414,20 +414,11 @@ function(_add_target_variant_link_flags) list(APPEND library_search_directories "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N_LIBDIR}") endif() - if(NOT SWIFT_COMPILER_IS_MSVC_LIKE) - # FIXME: On Apple platforms, find_program needs to look for "ld64.lld" - find_program(LDLLD_PATH "ld.lld") - if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR - ("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND - NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS")) - list(APPEND result "-fuse-ld=lld") - elseif(SWIFT_ENABLE_GOLD_LINKER AND - "${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF") - if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) - list(APPEND result "-fuse-ld=gold.exe") - else() - list(APPEND result "-fuse-ld=gold") - endif() + if(SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE) + if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}.exe") + else() + list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}") endif() endif() diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index 7df41178b775c..a3b4188eb030f 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -116,10 +116,10 @@ if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE": if "@SWIFT_HAVE_LIBXML2@" == "TRUE": config.available_features.add('libxml2') -if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE": +if "@SWIFT_USE_LINKER@" == "lld": config.android_linker_name = "lld" else: - # even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android + # even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android config.android_linker_name = "gold" if '@SWIFT_INCLUDE_TOOLS@' == 'TRUE': diff --git a/validation-test/lit.site.cfg.in b/validation-test/lit.site.cfg.in index 6a00ee3ab5ef7..3666329b720d6 100644 --- a/validation-test/lit.site.cfg.in +++ b/validation-test/lit.site.cfg.in @@ -98,10 +98,10 @@ if "@CMAKE_GENERATOR@" == "Xcode": config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@") -if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE": +if "@SWIFT_USE_LINKER@" == "lld": config.android_linker_name = "lld" else: - # even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android + # even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android config.android_linker_name = "gold" # Let the main config do the real work.