Skip to content

Commit c6cc769

Browse files
committed
build: default the lld/gold enabling as per reality
Rather than defaulting both of these to true, enable gold by default only on ELFish targets, and enable LLD by default for Windows on non-Windows hosts.
1 parent ced7dc1 commit c6cc769

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

CMakeLists.txt

+12-2
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,22 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
147147
"The internal version of the Clang compiler")
148148

149149
# Indicate whether Swift should attempt to use the lld linker.
150-
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
150+
if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
151+
set(SWIFT_ENABLE_LLD_LINKER_default TRUE)
152+
else()
153+
set(SWIFT_ENABLE_LLD_LINKER_default FALSE)
154+
endif()
155+
set(SWIFT_ENABLE_LLD_LINKER ${SWIFT_ENABLE_LLD_LINKER_default} CACHE BOOL
151156
"Enable using the lld linker when available")
152157

153158
# Indicate whether Swift should attempt to use the gold linker.
154159
# This is not used on Darwin.
155-
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
160+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL Windows)
161+
set(SWIFT_ENABLE_GOLD_LINKER_default FALSE)
162+
else()
163+
set(SWIFT_ENABLE_GOLD_LINKER_default TRUE)
164+
endif()
165+
set(SWIFT_ENABLE_GOLD_LINKER ${SWIFT_ENABLE_GOLD_LINKER_default} CACHE BOOL
156166
"Enable using the gold linker when available")
157167

158168
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One

cmake/modules/AddSwift.cmake

+6-12
Original file line numberDiff line numberDiff line change
@@ -403,18 +403,12 @@ function(_add_host_variant_link_flags target)
403403
endif()
404404

405405
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
406-
# FIXME: On Apple platforms, find_program needs to look for "ld64.lld"
407-
find_program(LDLLD_PATH "ld.lld")
408-
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
409-
(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS AND NOT CMAKE_SYSTEM_NAME STREQUAL WINDOWS))
410-
target_link_options(${target} PRIVATE -fuse-ld=lld)
411-
elseif(SWIFT_ENABLE_GOLD_LINKER AND
412-
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
413-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
414-
target_link_options(${target} PRIVATE -fuse-ld=gold.exe)
415-
else()
416-
target_link_options(${target} PRIVATE -fuse-ld=gold)
417-
endif()
406+
if(SWIFT_ENABLE_LLD_LINKER)
407+
target_link_options(${target} PRIVATE
408+
-fuse-ld=lld$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
409+
elseif(SWIFT_ENABLE_GOLD_LINKER)
410+
target_link_options(${target} PRIVATE
411+
-fuse-ld=gold$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
418412
endif()
419413
endif()
420414

0 commit comments

Comments
 (0)