-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66ad3fe
commit c49ca1d
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) { |