Skip to content

Commit e112478

Browse files
authored
Merge pull request #72049 from futurejones/amazonlinux-use-lld-linker
Set default linker to lld for Amazon Linux 2023
2 parents f933f2a + 03a364e commit e112478

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ if(XCODE)
959959
swift_common_xcode_cxx_config()
960960
endif()
961961

962+
# Check what linux distribution is being used.
963+
# This can be used to determine the default linker to use.
964+
cmake_host_system_information(RESULT DISTRO_NAME QUERY DISTRIB_PRETTY_NAME)
965+
962966
# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use
963967
# our own defaults. This should only be possible in a unified (not stand alone)
964968
# build environment.
@@ -970,6 +974,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_HOST_SYSTEM_NAME STREQ
970974
set(SWIFT_USE_LINKER_default "lld")
971975
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
972976
set(SWIFT_USE_LINKER_default "")
977+
elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
978+
set(SWIFT_USE_LINKER_default "lld")
973979
else()
974980
set(SWIFT_USE_LINKER_default "gold")
975981
endif()

lib/Driver/UnixToolChains.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include <fstream>
14+
1315
#include "ToolChains.h"
1416

1517
#include "swift/Basic/LLVM.h"
@@ -108,9 +110,24 @@ ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(
108110

109111
return II;
110112
}
113+
// Amazon Linux 2023 requires lld as the default linker.
114+
bool isAmazonLinux2023Host() {
115+
std::ifstream file("/etc/os-release");
116+
std::string line;
117+
118+
while (std::getline(file, line)) {
119+
if (line.substr(0, 12) == "PRETTY_NAME=") {
120+
if (line.substr(12) == "\"Amazon Linux 2023\"") {
121+
file.close();
122+
return true;
123+
}
124+
}
125+
}
126+
return false;
127+
}
111128

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

116133
switch (getTriple().getArch()) {

0 commit comments

Comments
 (0)