Skip to content

Commit 9182327

Browse files
authored
[build system] Prefer LLD if it exists (#14165)
Other changes: 1) Minimize unified versus build-script build differences. 2) Stop trying to make runtime variables have "protected" visibility. This combination is meaningless and lld rightly complains. Finally, this blog post is worth reading: http://www.airs.com/blog/archives/307
1 parent 39f8978 commit 9182327

File tree

5 files changed

+14
-64
lines changed

5 files changed

+14
-64
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
129129
"The internal version of the Clang compiler")
130130

131131
# Indicate whether Swift should attempt to use the lld linker.
132-
set(SWIFT_ENABLE_LLD_LINKER FALSE CACHE BOOL
132+
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
133133
"Enable using the lld linker when available")
134134

135135
# Indicate whether Swift should attempt to use the gold linker.
136136
# This is not used on Darwin.
137-
set(SWIFT_ENABLE_GOLD_LINKER FALSE CACHE BOOL
137+
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
138138
"Enable using the gold linker when available")
139139

140140
set(SWIFT_SDKS "" CACHE STRING

cmake/modules/AddSwift.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,14 @@ function(_add_variant_link_flags)
404404
endif()
405405

406406
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
407-
if(SWIFT_ENABLE_GOLD_LINKER AND
408-
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
409-
list(APPEND result "-fuse-ld=gold")
410-
endif()
411-
if(SWIFT_ENABLE_LLD_LINKER OR
407+
find_program(LDLLD_PATH "ld.lld")
408+
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH) OR
412409
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
413410
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
414411
list(APPEND result "-fuse-ld=lld")
412+
elseif(SWIFT_ENABLE_GOLD_LINKER AND
413+
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
414+
list(APPEND result "-fuse-ld=gold")
415415
endif()
416416
endif()
417417

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ function(add_swift_unittest test_dirname)
4747
LINK_FLAGS " -latomic")
4848
endif()
4949

50-
if(SWIFT_ENABLE_GOLD_LINKER AND
50+
find_program(LDLLD_PATH "ld.lld")
51+
if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH)
52+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
53+
LINK_FLAGS " -fuse-ld=lld")
54+
elseif(SWIFT_ENABLE_GOLD_LINKER AND
5155
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
5256
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
5357
LINK_FLAGS " -fuse-ld=gold")
5458
endif()
55-
if(SWIFT_ENABLE_LLD_LINKER)
56-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
57-
LINK_FLAGS " -fuse-ld=lld")
58-
endif()
5959

6060
if(SWIFT_ANALYZE_CODE_COVERAGE)
6161
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY

stdlib/public/SwiftShims/Visibility.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,11 @@
6969
#endif
7070

7171
// TODO: support using shims headers in overlays by parameterizing
72-
// SWIFT_RUNTIME_EXPORT on the library it's exported from, then setting
73-
// protected vs. default based on the current value of __SWIFT_CURRENT_DYLIB.
72+
// SWIFT_RUNTIME_EXPORT on the library it's exported from.
7473

7574
/// Attribute used to export symbols from the runtime.
76-
#if __MACH__
75+
#if defined(__MACH__) || defined(__ELF__)
7776
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
78-
#elif __ELF__
79-
80-
// Use protected visibility for ELF, since we don't want Swift symbols to be
81-
// interposable. The relative relocations we form to metadata aren't
82-
// valid in ELF shared objects, and leaving them relocatable at load time
83-
// defeats the purpose of the relative references.
84-
//
85-
// Protected visibility on a declaration is interpreted to mean that the
86-
// symbol is defined in the current dynamic library, so if we're building
87-
// something else, we need to fall back on using default visibility.
88-
#ifdef __SWIFT_CURRENT_DYLIB
89-
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("protected")))
90-
#else
91-
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
92-
#endif
9377

9478
#else // FIXME: this #else should be some sort of #elif Windows
9579
# if defined(__CYGWIN__)

utils/build-script-impl

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ function set_build_options_for_host() {
411411
SWIFT_HOST_VARIANT_SDK=
412412
SWIFT_HOST_VARIANT_ARCH=
413413
SWIFT_HOST_TRIPLE=
414-
USE_GOLD_LINKER=
415414
local host="$1"
416415

417416
# Hosts which can be cross-compiled must specify:
@@ -422,7 +421,6 @@ function set_build_options_for_host() {
422421
SWIFT_HOST_VARIANT="freebsd"
423422
SWIFT_HOST_VARIANT_SDK="FREEBSD"
424423
SWIFT_HOST_VARIANT_ARCH="x86_64"
425-
USE_GOLD_LINKER=1
426424
;;
427425
cygwin-x86_64)
428426
SWIFT_HOST_VARIANT="cygwin"
@@ -437,7 +435,6 @@ function set_build_options_for_host() {
437435
linux-*)
438436
SWIFT_HOST_VARIANT="linux"
439437
SWIFT_HOST_VARIANT_SDK="LINUX"
440-
USE_GOLD_LINKER=1
441438
case ${host} in
442439
linux-x86_64)
443440
SWIFT_HOST_VARIANT_ARCH="x86_64"
@@ -1922,22 +1919,6 @@ for host in "${ALL_HOSTS[@]}"; do
19221919

19231920
cmake_options=("${common_cmake_options_host[@]}")
19241921

1925-
# Add in gold linker support if requested.
1926-
if [[ "${USE_GOLD_LINKER}" ]]; then
1927-
echo "${product}: using gold linker"
1928-
if [[ "${product}" != "swift" ]]; then
1929-
# All other projects override the linker flags to add in
1930-
# gold linker support.
1931-
cmake_options=(
1932-
"${cmake_options[@]}"
1933-
-DCMAKE_EXE_LINKER_FLAGS:STRING="-fuse-ld=gold"
1934-
-DCMAKE_SHARED_LINKER_FLAGS:STRING="-fuse-ld=gold"
1935-
)
1936-
fi
1937-
else
1938-
echo "${product}: using standard linker"
1939-
fi
1940-
19411922
llvm_build_dir=$(build_directory ${host} llvm)
19421923
module_cache="${build_dir}/module-cache"
19431924

@@ -2035,17 +2016,6 @@ for host in "${ALL_HOSTS[@]}"; do
20352016

20362017
swift)
20372018

2038-
if [[ "${USE_GOLD_LINKER}" ]]; then
2039-
# Swift will selectively use the gold linker on all
2040-
# parts except building the standard library. We
2041-
# let the Swift cmake setup figure out how to apply
2042-
# that.
2043-
cmake_options=(
2044-
"${cmake_options[@]}"
2045-
-DSWIFT_ENABLE_GOLD_LINKER=TRUE
2046-
)
2047-
fi
2048-
20492019
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
20502020
cmake_options=(
20512021
"${cmake_options[@]}"
@@ -2451,10 +2421,6 @@ for host in "${ALL_HOSTS[@]}"; do
24512421
LIBDISPATCH_BUILD_ARGS="-DLIBDISPATCH_SOURCE_DIR=${LIBDISPATCH_SOURCE_DIR} -DLIBDISPATCH_BUILD_DIR=${LIBDISPATCH_BUILD_DIR}"
24522422
fi
24532423

2454-
if [[ "${USE_GOLD_LINKER}" ]]; then
2455-
SWIFT_USE_LINKER="-fuse-ld=gold"
2456-
fi
2457-
24582424
# FIXME CROSSCOMPILING:
24592425
# Foundation is a target library (like the Swift standard library),
24602426
# so technically we should build it for all stdlib_targets, not just for the host.

0 commit comments

Comments
 (0)