Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
futurejones committed Mar 5, 2024
1 parent 91eadcc commit b4f09db
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test-patches/amazonlinux-lld-CMakeLists-5.10.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c758792bf4a..e7fb71577f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -890,6 +890,9 @@ if(XCODE)
swift_common_xcode_cxx_config()
endif()

+# Check what linux distribution is being used.
+cmake_host_system_information(RESULT DISTRO_ID QUERY DISTRIB_ID)
+
# 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 +904,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_ID STREQUAL "amzn")
+ set(SWIFT_USE_LINKER_default "lld")
else()
set(SWIFT_USE_LINKER_default "gold")
endif()
23 changes: 23 additions & 0 deletions test-patches/amazonlinux-lld-CMakeLists-main-v2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 43747db4d55..e96519c9169 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -948,6 +948,9 @@ if(XCODE)
swift_common_xcode_cxx_config()
endif()

+# Check what linux distribution is being used.
+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.
@@ -959,6 +962,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()
39 changes: 39 additions & 0 deletions test-patches/amazonlinux-lld-UnixToolchains-main-bool.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp
index f6856c17e16..f9162d82c07 100644
--- a/lib/Driver/UnixToolChains.cpp
+++ b/lib/Driver/UnixToolChains.cpp
@@ -9,6 +9,8 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
+#include <iostream>
+#include <fstream>

#include "ToolChains.h"

@@ -109,8 +111,24 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
return II;
}

+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()) {
34 changes: 34 additions & 0 deletions test-patches/amazonlinux-lld-UnixToolchains-main-v2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp
index f6856c17e16..a34eecaefe1 100644
--- a/lib/Driver/UnixToolChains.cpp
+++ b/lib/Driver/UnixToolChains.cpp
@@ -9,6 +9,8 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
+#include <iostream>
+#include <fstream>

#include "ToolChains.h"

@@ -110,6 +112,20 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
}

std::string toolchains::GenericUnix::getDefaultLinker() const {
+ if (getTriple().isOSLinux()) {
+ 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 "lld";
+ }
+ }
+ }
+ }
+
if (getTriple().isAndroid())
return "lld";

13 changes: 13 additions & 0 deletions test-patches/amazonlinux-lld-swift-corelibs-foundation-main.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/lib/target.py b/lib/target.py
index d1db48b1..44fd41da 100644
--- a/lib/target.py
+++ b/lib/target.py
@@ -342,7 +342,7 @@ class Target:
if "linux" in triple:
self.sdk = OSType.Linux
self.dynamic_library_suffix = ".so"
- self.linker = "gold"
+ self.linker = "lld"
elif "freebsd" in triple:
self.sdk = OSType.FreeBSD
self.dynamic_library_suffix = ".so"

0 comments on commit b4f09db

Please sign in to comment.