Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
futurejones authored Mar 7, 2024
1 parent 66ad3fe commit c49ca1d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions amazonlinux-2023/patches/swift-5.10/72049-5.10.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c758792bf4a..af361fa2bc5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -890,6 +890,10 @@ if(XCODE)
swift_common_xcode_cxx_config()
endif()

+# Check what linux distribution is being used.
+# This can be used to determine the default linker to use.
+cmake_host_system_information(RESULT DISTRO_NAME QUERY DISTRIB_PRETTY_NAME)
+
# 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.
@@ -901,6 +905,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_HOST_SYSTEM_NAME STREQ
set(SWIFT_USE_LINKER_default "lld")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(SWIFT_USE_LINKER_default "")
+elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
+ set(SWIFT_USE_LINKER_default "lld")
else()
set(SWIFT_USE_LINKER_default "gold")
endif()
diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp
index 61498c144a2..2f95393b3ec 100644
--- a/lib/Driver/UnixToolChains.cpp
+++ b/lib/Driver/UnixToolChains.cpp
@@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//

+#include <fstream>
+
#include "ToolChains.h"

#include "swift/Basic/Dwarf.h"
@@ -109,9 +111,24 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(

return II;
}
+// Amazon Linux 2023 requires lld as the default linker.
+bool isAmazonLinux2023Host() {
+ std::ifstream file("/etc/os-release");
+ std::string line;
+
+ while (std::getline(file, line)) {
+ if (line.substr(0, 12) == "PRETTY_NAME=") {
+ if (line.substr(12) == "\"Amazon Linux 2023\"") {
+ file.close();
+ return true;
+ }
+ }
+ }
+ return false;
+ }

std::string toolchains::GenericUnix::getDefaultLinker() const {
- if (getTriple().isAndroid())
+ if (getTriple().isAndroid() || isAmazonLinux2023Host())
return "lld";

switch (getTriple().getArch()) {

0 comments on commit c49ca1d

Please sign in to comment.