[clang] ed95655 - [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 25 16:25:54 PDT 2021


Author: Fangrui Song
Date: 2021-03-25T16:25:47-07:00
New Revision: ed956554f96c0a37cc1f1291dbad303d3f1d495c

URL: https://github.com/llvm/llvm-project/commit/ed956554f96c0a37cc1f1291dbad303d3f1d495c
DIFF: https://github.com/llvm/llvm-project/commit/ed956554f96c0a37cc1f1291dbad303d3f1d495c.diff

LOG: [Triple][Driver] Add muslx32 environment and use /lib/ld-musl-x32.so.1 for -dynamic-linker

Differential Revision: https://reviews.llvm.org/D99308

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Linux.cpp
    clang/test/Driver/linux-cross.cpp
    llvm/include/llvm/ADT/Triple.h
    llvm/lib/Support/Triple.cpp
    llvm/unittests/ADT/TripleTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index eacc540fee30b..895e76e0c448f 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -401,6 +401,11 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     case llvm::Triple::x86:
       ArchName = "i386";
       break;
+    case llvm::Triple::x86_64:
+      ArchName = Triple.getEnvironment() == llvm::Triple::MuslX32
+                     ? "x32"
+                     : Triple.getArchName().str();
+      break;
     default:
       ArchName = Triple.getArchName().str();
     }

diff  --git a/clang/test/Driver/linux-cross.cpp b/clang/test/Driver/linux-cross.cpp
index 49e7861923ba3..3b34d27b1a97b 100644
--- a/clang/test/Driver/linux-cross.cpp
+++ b/clang/test/Driver/linux-cross.cpp
@@ -75,3 +75,7 @@
 // RUN: %clang -### %s --target=i686-linux-musl --sysroot= \
 // RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=MUSL_I686
 // MUSL_I686: "-dynamic-linker" "/lib/ld-musl-i386.so.1"
+
+// RUN: %clang -### %s --target=x86_64-linux-muslx32 --sysroot= \
+// RUN:   --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=MUSL_X32
+// MUSL_X32: "-dynamic-linker" "/lib/ld-musl-x32.so.1"

diff  --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index 3b351b732e9af..b6a6fe67b7af1 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -218,6 +218,7 @@ class Triple {
     Musl,
     MuslEABI,
     MuslEABIHF,
+    MuslX32,
 
     MSVC,
     Itanium,
@@ -688,7 +689,8 @@ class Triple {
   bool isMusl() const {
     return getEnvironment() == Triple::Musl ||
            getEnvironment() == Triple::MuslEABI ||
-           getEnvironment() == Triple::MuslEABIHF;
+           getEnvironment() == Triple::MuslEABIHF ||
+           getEnvironment() == Triple::MuslX32;
   }
 
   /// Tests whether the target is SPIR (32- or 64-bit).

diff  --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
index e5dd32fb58278..3c2182ecb09a0 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -250,6 +250,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case MuslX32: return "muslx32";
   case Simulator: return "simulator";
   }
 
@@ -555,6 +556,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
       .StartsWith("android", Triple::Android)
       .StartsWith("musleabihf", Triple::MuslEABIHF)
       .StartsWith("musleabi", Triple::MuslEABI)
+      .StartsWith("muslx32", Triple::MuslX32)
       .StartsWith("musl", Triple::Musl)
       .StartsWith("msvc", Triple::MSVC)
       .StartsWith("itanium", Triple::Itanium)

diff  --git a/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp
index 0e49a1aa143a0..2e3c78aa4f640 100644
--- a/llvm/unittests/ADT/TripleTest.cpp
+++ b/llvm/unittests/ADT/TripleTest.cpp
@@ -111,6 +111,12 @@ TEST(TripleTest, ParsedIDs) {
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::Musl, T.getEnvironment());
 
+  T = Triple("x86_64-pc-linux-muslx32");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::MuslX32, T.getEnvironment());
+
   // PS4 has two spellings for the vendor.
   T = Triple("x86_64-scei-ps4");
   EXPECT_EQ(Triple::x86_64, T.getArch());


        


More information about the cfe-commits mailing list