mirror of
https://github.com/gentoo-mirror/guru.git
synced 2026-07-11 08:03:16 -04:00
dev-lang/swift: switch to source-based builds
Signed-off-by: Itai Ferber <itai@itaiferber.net>
This commit is contained in:
144
dev-lang/swift/files/swift-5.10.1-link-with-lld.patch
Normal file
144
dev-lang/swift/files/swift-5.10.1-link-with-lld.patch
Normal file
@@ -0,0 +1,144 @@
|
||||
# Swift defaults to building with `gold` on Linux because it doesn't build with
|
||||
# `bfd`; Gentoo no longer supports `gold`, so we have to build with `lld`.
|
||||
#
|
||||
# We need to:
|
||||
# 1. Have the Swift drivers default to linking with `lld` over `gold` (both for)
|
||||
# eventual end-user code, but also for the built Swift compiler stages to
|
||||
# bootstrap the next stage,
|
||||
# 2. Have the `SWIFT_USE_LINKER` flag be correctly respected everywhere, and
|
||||
# 3. Set the right linker flags for `lld` because its behavior for ELF on Linux
|
||||
# differs from other platforms, and certain Swift symbols need to not be GC'd
|
||||
# out
|
||||
#
|
||||
# See https://github.com/swiftlang/swift/pull/69538 (merged to main after 5.10
|
||||
# branched).
|
||||
|
||||
--- a/swift/lib/Driver/UnixToolChains.cpp
|
||||
+++ b/swift/lib/Driver/UnixToolChains.cpp
|
||||
@@ -110,34 +110,7 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
|
||||
return II;
|
||||
}
|
||||
|
||||
-std::string toolchains::GenericUnix::getDefaultLinker() const {
|
||||
- if (getTriple().isAndroid())
|
||||
- return "lld";
|
||||
-
|
||||
- switch (getTriple().getArch()) {
|
||||
- case llvm::Triple::arm:
|
||||
- case llvm::Triple::aarch64:
|
||||
- case llvm::Triple::aarch64_32:
|
||||
- case llvm::Triple::armeb:
|
||||
- case llvm::Triple::thumb:
|
||||
- case llvm::Triple::thumbeb:
|
||||
- // BFD linker has issues wrt relocation of the protocol conformance
|
||||
- // section on these targets, it also generates COPY relocations for
|
||||
- // final executables, as such, unless specified, we default to gold
|
||||
- // linker.
|
||||
- return "gold";
|
||||
- case llvm::Triple::x86:
|
||||
- case llvm::Triple::x86_64:
|
||||
- case llvm::Triple::ppc64:
|
||||
- case llvm::Triple::ppc64le:
|
||||
- case llvm::Triple::systemz:
|
||||
- // BFD linker has issues wrt relocations against protected symbols.
|
||||
- return "gold";
|
||||
- default:
|
||||
- // Otherwise, use the default BFD linker.
|
||||
- return "";
|
||||
- }
|
||||
-}
|
||||
+std::string toolchains::GenericUnix::getDefaultLinker() const { return "lld"; }
|
||||
|
||||
bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T,
|
||||
const llvm::opt::ArgList &Args) const {
|
||||
|
||||
--- a/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
|
||||
+++ b/swift-driver/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift
|
||||
@@ -17,25 +17,7 @@ import struct TSCBasic.AbsolutePath
|
||||
|
||||
extension GenericUnixToolchain {
|
||||
private func defaultLinker(for targetTriple: Triple) -> String? {
|
||||
- if targetTriple.os == .openbsd || targetTriple.os == .freeBSD ||
|
||||
- targetTriple.environment == .android {
|
||||
- return "lld"
|
||||
- }
|
||||
-
|
||||
- switch targetTriple.arch {
|
||||
- case .arm, .aarch64, .armeb, .thumb, .thumbeb:
|
||||
- // BFD linker has issues wrt relocation of the protocol conformance
|
||||
- // section on these targets, it also generates COPY relocations for
|
||||
- // final executables, as such, unless specified, we default to gold
|
||||
- // linker.
|
||||
- return "gold"
|
||||
- case .x86, .x86_64, .ppc64, .ppc64le, .systemz:
|
||||
- // BFD linker has issues wrt relocations against protected symbols.
|
||||
- return "gold"
|
||||
- default:
|
||||
- // Otherwise, use the default BFD linker.
|
||||
- return ""
|
||||
- }
|
||||
+ "lld"
|
||||
}
|
||||
|
||||
private func majorArchitectureName(for triple: Triple) -> String {
|
||||
--- a/swift/cmake/modules/AddPureSwift.cmake
|
||||
+++ b/swift/cmake/modules/AddPureSwift.cmake
|
||||
@@ -224,6 +224,10 @@ function(add_pure_swift_host_library name)
|
||||
target_link_options(${name} PRIVATE
|
||||
"-use-ld=${LLVM_USE_LINKER}"
|
||||
)
|
||||
+ elseif(SWIFT_USE_LINKER)
|
||||
+ target_link_options(${name} PRIVATE
|
||||
+ "-use-ld=${SWIFT_USE_LINKER}"
|
||||
+ )
|
||||
endif()
|
||||
|
||||
# Export this target.
|
||||
@@ -322,6 +326,10 @@ function(add_pure_swift_host_tool name)
|
||||
target_link_options(${name} PRIVATE
|
||||
"-use-ld=${LLVM_USE_LINKER}"
|
||||
)
|
||||
+ elseif(SWIFT_USE_LINKER)
|
||||
+ target_link_options(${name} PRIVATE
|
||||
+ "-use-ld=${SWIFT_USE_LINKER}"
|
||||
+ )
|
||||
endif()
|
||||
|
||||
# Workaround to touch the library and its objects so that we don't
|
||||
--- a/swift/cmake/modules/AddSwift.cmake
|
||||
+++ b/swift/cmake/modules/AddSwift.cmake
|
||||
@@ -629,6 +629,10 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
+
|
||||
+ if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld")
|
||||
+ target_link_options(${target} PRIVATE "LINKER:-z,nostart-stop-gc")
|
||||
+ endif()
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH YES)
|
||||
--- a/swift/tools/libStaticMirror/CMakeLists.txt
|
||||
+++ b/swift/tools/libStaticMirror/CMakeLists.txt
|
||||
@@ -29,6 +29,10 @@ add_llvm_symbol_exports(libStaticMirror ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
# Adds -dead_strip option
|
||||
add_link_opts(libStaticMirror)
|
||||
|
||||
+if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld")
|
||||
+ target_link_options(libStaticMirror PRIVATE "LINKER:-z,nostart-stop-gc")
|
||||
+endif()
|
||||
+
|
||||
add_dependencies(static-mirror-lib libStaticMirror)
|
||||
swift_install_in_component(TARGETS libStaticMirror
|
||||
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" COMPONENT static-mirror-lib
|
||||
--- a/swift/tools/libSwiftScan/CMakeLists.txt
|
||||
+++ b/swift/tools/libSwiftScan/CMakeLists.txt
|
||||
@@ -67,6 +67,10 @@ add_llvm_symbol_exports(libSwiftScan ${LLVM_EXPORTED_SYMBOL_FILE})
|
||||
# Adds -dead_strip option
|
||||
add_link_opts(libSwiftScan)
|
||||
|
||||
+if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld")
|
||||
+ target_link_options(libSwiftScan PRIVATE "LINKER:-z,nostart-stop-gc")
|
||||
+endif()
|
||||
+
|
||||
add_dependencies(compiler libSwiftScan)
|
||||
@@ -0,0 +1,142 @@
|
||||
# `llbuild` requires various products to link against `curses`; Gentoo doesn't
|
||||
# offer `curses` as an alias for `ncurses`, so `llbuild` has to link against
|
||||
# `ncurses` explicitly. `ncurses` on Gentoo also doesn't expose the `curses`
|
||||
# terminfo database interface (e.g., `set_curterm`, `del_curterm`, etc.), so we
|
||||
# have to also explicitly link against `tinfo`.
|
||||
|
||||
--- a/llbuild/Package.swift
|
||||
+++ b/llbuild/Package.swift
|
||||
@@ -227,7 +227,8 @@ let package = Package(
|
||||
path: "lib/llvm/Support",
|
||||
linkerSettings: [
|
||||
.linkedLibrary("m", .when(platforms: [.linux])),
|
||||
- .linkedLibrary("ncurses", .when(platforms: [.linux, .macOS, .android]))]
|
||||
+ .linkedLibrary("ncurses", .when(platforms: [.linux, .macOS, .android])),
|
||||
+ .linkedLibrary("tinfo", .when(platforms: [.linux]))]
|
||||
),
|
||||
],
|
||||
cxxLanguageStandard: .cxx14
|
||||
--- a/llbuild/lib/llvm/Support/CMakeLists.txt
|
||||
+++ b/llbuild/lib/llvm/Support/CMakeLists.txt
|
||||
@@ -65,5 +65,5 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Android|Darwin|Linux")
|
||||
- target_link_libraries(llvmSupport PRIVATE curses)
|
||||
+ target_link_libraries(llvmSupport PRIVATE ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/products/libllbuild/CMakeLists.txt
|
||||
+++ b/llbuild/products/libllbuild/CMakeLists.txt
|
||||
@@ -28,7 +28,7 @@ endif()
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||
target_link_libraries(libllbuild PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
|
||||
target_include_directories(libllbuild
|
||||
@@ -79,7 +79,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
llbuildNinja
|
||||
llvmSupport
|
||||
SQLite::SQLite3
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
|
||||
# Manually set up the remaining framework structure.
|
||||
set(LLBUILD_FW_INPUTS)
|
||||
--- a/llbuild/products/llbuild/CMakeLists.txt
|
||||
+++ b/llbuild/products/llbuild/CMakeLists.txt
|
||||
@@ -16,5 +16,5 @@ endif()
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(llbuild PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/products/swift-build-tool/CMakeLists.txt
|
||||
+++ b/llbuild/products/swift-build-tool/CMakeLists.txt
|
||||
@@ -10,7 +10,7 @@ target_link_libraries(swift-build-tool PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(swift-build-tool PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
|
||||
install(TARGETS swift-build-tool
|
||||
--- a/llbuild/unittests/Basic/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/Basic/CMakeLists.txt
|
||||
@@ -14,5 +14,5 @@ target_link_libraries(BasicTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(BasicTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/unittests/BuildSystem/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/BuildSystem/CMakeLists.txt
|
||||
@@ -16,5 +16,5 @@ target_link_libraries(BuildSystemTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(BuildSystemTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/unittests/CAPI/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/CAPI/CMakeLists.txt
|
||||
@@ -15,5 +15,5 @@ target_link_libraries(CAPITests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(CAPITests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/unittests/CAS/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/CAS/CMakeLists.txt
|
||||
@@ -8,6 +8,6 @@ target_link_libraries(CASTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(CASTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
|
||||
--- a/llbuild/unittests/Core/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/Core/CMakeLists.txt
|
||||
@@ -15,6 +15,6 @@ target_link_libraries(CoreTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(CoreTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
|
||||
--- a/llbuild/unittests/Evo/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/Evo/CMakeLists.txt
|
||||
@@ -11,6 +11,6 @@ target_link_libraries(EvoTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(EvoTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
|
||||
--- a/llbuild/unittests/Ninja/CMakeLists.txt
|
||||
+++ b/llbuild/unittests/Ninja/CMakeLists.txt
|
||||
@@ -8,5 +8,5 @@ target_link_libraries(NinjaTests PRIVATE
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(NinjaTests PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
--- a/llbuild/utils/adjust-times/CMakeLists.txt
|
||||
+++ b/llbuild/utils/adjust-times/CMakeLists.txt
|
||||
@@ -7,5 +7,5 @@ target_link_libraries(adjust-times PRIVATE llvmSupport)
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
target_link_libraries(adjust-times PRIVATE
|
||||
- curses)
|
||||
+ ncurses tinfo)
|
||||
endif()
|
||||
Reference in New Issue
Block a user