Skip to content

Commit ed95655

Browse files
committed
[Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker
Differential Revision: https://reviews.llvm.org/D99308
1 parent 886f9ff commit ed95655

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
401401
case llvm::Triple::x86:
402402
ArchName = "i386";
403403
break;
404+
case llvm::Triple::x86_64:
405+
ArchName = Triple.getEnvironment() == llvm::Triple::MuslX32
406+
? "x32"
407+
: Triple.getArchName().str();
408+
break;
404409
default:
405410
ArchName = Triple.getArchName().str();
406411
}

clang/test/Driver/linux-cross.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@
7575
// RUN: %clang -### %s --target=i686-linux-musl --sysroot= \
7676
// RUN: --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=MUSL_I686
7777
// MUSL_I686: "-dynamic-linker" "/lib/ld-musl-i386.so.1"
78+
79+
// RUN: %clang -### %s --target=x86_64-linux-muslx32 --sysroot= \
80+
// RUN: --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=MUSL_X32
81+
// MUSL_X32: "-dynamic-linker" "/lib/ld-musl-x32.so.1"

llvm/include/llvm/ADT/Triple.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class Triple {
218218
Musl,
219219
MuslEABI,
220220
MuslEABIHF,
221+
MuslX32,
221222

222223
MSVC,
223224
Itanium,
@@ -688,7 +689,8 @@ class Triple {
688689
bool isMusl() const {
689690
return getEnvironment() == Triple::Musl ||
690691
getEnvironment() == Triple::MuslEABI ||
691-
getEnvironment() == Triple::MuslEABIHF;
692+
getEnvironment() == Triple::MuslEABIHF ||
693+
getEnvironment() == Triple::MuslX32;
692694
}
693695

694696
/// Tests whether the target is SPIR (32- or 64-bit).

llvm/lib/Support/Triple.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
250250
case Musl: return "musl";
251251
case MuslEABI: return "musleabi";
252252
case MuslEABIHF: return "musleabihf";
253+
case MuslX32: return "muslx32";
253254
case Simulator: return "simulator";
254255
}
255256

@@ -555,6 +556,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
555556
.StartsWith("android", Triple::Android)
556557
.StartsWith("musleabihf", Triple::MuslEABIHF)
557558
.StartsWith("musleabi", Triple::MuslEABI)
559+
.StartsWith("muslx32", Triple::MuslX32)
558560
.StartsWith("musl", Triple::Musl)
559561
.StartsWith("msvc", Triple::MSVC)
560562
.StartsWith("itanium", Triple::Itanium)

llvm/unittests/ADT/TripleTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ TEST(TripleTest, ParsedIDs) {
111111
EXPECT_EQ(Triple::Linux, T.getOS());
112112
EXPECT_EQ(Triple::Musl, T.getEnvironment());
113113

114+
T = Triple("x86_64-pc-linux-muslx32");
115+
EXPECT_EQ(Triple::x86_64, T.getArch());
116+
EXPECT_EQ(Triple::PC, T.getVendor());
117+
EXPECT_EQ(Triple::Linux, T.getOS());
118+
EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
119+
114120
// PS4 has two spellings for the vendor.
115121
T = Triple("x86_64-scei-ps4");
116122
EXPECT_EQ(Triple::x86_64, T.getArch());

0 commit comments

Comments
 (0)