mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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
This commit is contained in:
@@ -129,12 +129,12 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
|
|||||||
"The internal version of the Clang compiler")
|
"The internal version of the Clang compiler")
|
||||||
|
|
||||||
# Indicate whether Swift should attempt to use the lld linker.
|
# Indicate whether Swift should attempt to use the lld linker.
|
||||||
set(SWIFT_ENABLE_LLD_LINKER FALSE CACHE BOOL
|
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
|
||||||
"Enable using the lld linker when available")
|
"Enable using the lld linker when available")
|
||||||
|
|
||||||
# Indicate whether Swift should attempt to use the gold linker.
|
# Indicate whether Swift should attempt to use the gold linker.
|
||||||
# This is not used on Darwin.
|
# This is not used on Darwin.
|
||||||
set(SWIFT_ENABLE_GOLD_LINKER FALSE CACHE BOOL
|
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
|
||||||
"Enable using the gold linker when available")
|
"Enable using the gold linker when available")
|
||||||
|
|
||||||
set(SWIFT_SDKS "" CACHE STRING
|
set(SWIFT_SDKS "" CACHE STRING
|
||||||
|
|||||||
@@ -404,14 +404,14 @@ function(_add_variant_link_flags)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
|
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
|
||||||
if(SWIFT_ENABLE_GOLD_LINKER AND
|
find_program(LDLLD_PATH "ld.lld")
|
||||||
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH) OR
|
||||||
list(APPEND result "-fuse-ld=gold")
|
|
||||||
endif()
|
|
||||||
if(SWIFT_ENABLE_LLD_LINKER OR
|
|
||||||
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
|
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
|
||||||
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
|
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
|
||||||
list(APPEND result "-fuse-ld=lld")
|
list(APPEND result "-fuse-ld=lld")
|
||||||
|
elseif(SWIFT_ENABLE_GOLD_LINKER AND
|
||||||
|
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
||||||
|
list(APPEND result "-fuse-ld=gold")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -47,15 +47,15 @@ function(add_swift_unittest test_dirname)
|
|||||||
LINK_FLAGS " -latomic")
|
LINK_FLAGS " -latomic")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SWIFT_ENABLE_GOLD_LINKER AND
|
find_program(LDLLD_PATH "ld.lld")
|
||||||
|
if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH)
|
||||||
|
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")
|
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
|
||||||
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
|
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
|
||||||
LINK_FLAGS " -fuse-ld=gold")
|
LINK_FLAGS " -fuse-ld=gold")
|
||||||
endif()
|
endif()
|
||||||
if(SWIFT_ENABLE_LLD_LINKER)
|
|
||||||
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
|
|
||||||
LINK_FLAGS " -fuse-ld=lld")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(SWIFT_ANALYZE_CODE_COVERAGE)
|
if(SWIFT_ANALYZE_CODE_COVERAGE)
|
||||||
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
|
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
|
||||||
|
|||||||
@@ -69,27 +69,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: support using shims headers in overlays by parameterizing
|
// TODO: support using shims headers in overlays by parameterizing
|
||||||
// SWIFT_RUNTIME_EXPORT on the library it's exported from, then setting
|
// SWIFT_RUNTIME_EXPORT on the library it's exported from.
|
||||||
// protected vs. default based on the current value of __SWIFT_CURRENT_DYLIB.
|
|
||||||
|
|
||||||
/// Attribute used to export symbols from the runtime.
|
/// Attribute used to export symbols from the runtime.
|
||||||
#if __MACH__
|
#if defined(__MACH__) || defined(__ELF__)
|
||||||
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
|
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
|
||||||
#elif __ELF__
|
|
||||||
|
|
||||||
// Use protected visibility for ELF, since we don't want Swift symbols to be
|
|
||||||
// interposable. The relative relocations we form to metadata aren't
|
|
||||||
// valid in ELF shared objects, and leaving them relocatable at load time
|
|
||||||
// defeats the purpose of the relative references.
|
|
||||||
//
|
|
||||||
// Protected visibility on a declaration is interpreted to mean that the
|
|
||||||
// symbol is defined in the current dynamic library, so if we're building
|
|
||||||
// something else, we need to fall back on using default visibility.
|
|
||||||
#ifdef __SWIFT_CURRENT_DYLIB
|
|
||||||
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("protected")))
|
|
||||||
#else
|
|
||||||
# define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // FIXME: this #else should be some sort of #elif Windows
|
#else // FIXME: this #else should be some sort of #elif Windows
|
||||||
# if defined(__CYGWIN__)
|
# if defined(__CYGWIN__)
|
||||||
|
|||||||
@@ -411,7 +411,6 @@ function set_build_options_for_host() {
|
|||||||
SWIFT_HOST_VARIANT_SDK=
|
SWIFT_HOST_VARIANT_SDK=
|
||||||
SWIFT_HOST_VARIANT_ARCH=
|
SWIFT_HOST_VARIANT_ARCH=
|
||||||
SWIFT_HOST_TRIPLE=
|
SWIFT_HOST_TRIPLE=
|
||||||
USE_GOLD_LINKER=
|
|
||||||
local host="$1"
|
local host="$1"
|
||||||
|
|
||||||
# Hosts which can be cross-compiled must specify:
|
# Hosts which can be cross-compiled must specify:
|
||||||
@@ -422,7 +421,6 @@ function set_build_options_for_host() {
|
|||||||
SWIFT_HOST_VARIANT="freebsd"
|
SWIFT_HOST_VARIANT="freebsd"
|
||||||
SWIFT_HOST_VARIANT_SDK="FREEBSD"
|
SWIFT_HOST_VARIANT_SDK="FREEBSD"
|
||||||
SWIFT_HOST_VARIANT_ARCH="x86_64"
|
SWIFT_HOST_VARIANT_ARCH="x86_64"
|
||||||
USE_GOLD_LINKER=1
|
|
||||||
;;
|
;;
|
||||||
cygwin-x86_64)
|
cygwin-x86_64)
|
||||||
SWIFT_HOST_VARIANT="cygwin"
|
SWIFT_HOST_VARIANT="cygwin"
|
||||||
@@ -437,7 +435,6 @@ function set_build_options_for_host() {
|
|||||||
linux-*)
|
linux-*)
|
||||||
SWIFT_HOST_VARIANT="linux"
|
SWIFT_HOST_VARIANT="linux"
|
||||||
SWIFT_HOST_VARIANT_SDK="LINUX"
|
SWIFT_HOST_VARIANT_SDK="LINUX"
|
||||||
USE_GOLD_LINKER=1
|
|
||||||
case ${host} in
|
case ${host} in
|
||||||
linux-x86_64)
|
linux-x86_64)
|
||||||
SWIFT_HOST_VARIANT_ARCH="x86_64"
|
SWIFT_HOST_VARIANT_ARCH="x86_64"
|
||||||
@@ -1922,22 +1919,6 @@ for host in "${ALL_HOSTS[@]}"; do
|
|||||||
|
|
||||||
cmake_options=("${common_cmake_options_host[@]}")
|
cmake_options=("${common_cmake_options_host[@]}")
|
||||||
|
|
||||||
# Add in gold linker support if requested.
|
|
||||||
if [[ "${USE_GOLD_LINKER}" ]]; then
|
|
||||||
echo "${product}: using gold linker"
|
|
||||||
if [[ "${product}" != "swift" ]]; then
|
|
||||||
# All other projects override the linker flags to add in
|
|
||||||
# gold linker support.
|
|
||||||
cmake_options=(
|
|
||||||
"${cmake_options[@]}"
|
|
||||||
-DCMAKE_EXE_LINKER_FLAGS:STRING="-fuse-ld=gold"
|
|
||||||
-DCMAKE_SHARED_LINKER_FLAGS:STRING="-fuse-ld=gold"
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "${product}: using standard linker"
|
|
||||||
fi
|
|
||||||
|
|
||||||
llvm_build_dir=$(build_directory ${host} llvm)
|
llvm_build_dir=$(build_directory ${host} llvm)
|
||||||
module_cache="${build_dir}/module-cache"
|
module_cache="${build_dir}/module-cache"
|
||||||
|
|
||||||
@@ -2035,17 +2016,6 @@ for host in "${ALL_HOSTS[@]}"; do
|
|||||||
|
|
||||||
swift)
|
swift)
|
||||||
|
|
||||||
if [[ "${USE_GOLD_LINKER}" ]]; then
|
|
||||||
# Swift will selectively use the gold linker on all
|
|
||||||
# parts except building the standard library. We
|
|
||||||
# let the Swift cmake setup figure out how to apply
|
|
||||||
# that.
|
|
||||||
cmake_options=(
|
|
||||||
"${cmake_options[@]}"
|
|
||||||
-DSWIFT_ENABLE_GOLD_LINKER=TRUE
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
|
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
|
||||||
cmake_options=(
|
cmake_options=(
|
||||||
"${cmake_options[@]}"
|
"${cmake_options[@]}"
|
||||||
@@ -2451,10 +2421,6 @@ for host in "${ALL_HOSTS[@]}"; do
|
|||||||
LIBDISPATCH_BUILD_ARGS="-DLIBDISPATCH_SOURCE_DIR=${LIBDISPATCH_SOURCE_DIR} -DLIBDISPATCH_BUILD_DIR=${LIBDISPATCH_BUILD_DIR}"
|
LIBDISPATCH_BUILD_ARGS="-DLIBDISPATCH_SOURCE_DIR=${LIBDISPATCH_SOURCE_DIR} -DLIBDISPATCH_BUILD_DIR=${LIBDISPATCH_BUILD_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${USE_GOLD_LINKER}" ]]; then
|
|
||||||
SWIFT_USE_LINKER="-fuse-ld=gold"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# FIXME CROSSCOMPILING:
|
# FIXME CROSSCOMPILING:
|
||||||
# Foundation is a target library (like the Swift standard library),
|
# Foundation is a target library (like the Swift standard library),
|
||||||
# so technically we should build it for all stdlib_targets, not just for the host.
|
# so technically we should build it for all stdlib_targets, not just for the host.
|
||||||
|
|||||||
Reference in New Issue
Block a user