staticfloat created this revision.
staticfloat added reviewers: rsmith, fedor.sergeev.
staticfloat added a project: clang.
Herald added a subscriber: cfe-commits.

The GNU Toolchain GCCDetector misses GCC installations with the triplet 
`x86_64-linux-musl`, looking only instead for `x86_64-unknown-linux-musl` 
because it does not have the built-in shortcut that it does for glibc-based 
systems.  This patch, taken from the void-linux patch set at 
https://github.com/void-linux/void-packages/blob/ced162673bf1e824529eb04d8c33a4e30dcfb68e/srcpkgs/llvm8/files/patches/cfe/cfe-004-add-musl-triples.patch
 improves clang's ability to find these shorter triplets on `musl`.  This is 
necessary also for environments such as the Julia project's BinaryBuilder, 
which comprises a large collection of cross-compilers, each installed within a 
specific multiarch triplet.


Repository:
  rC Clang

https://reviews.llvm.org/D67516

Files:
  b/lib/Driver/ToolChains/Gnu.cpp


Index: b/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- b/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -1882,7 +1882,8 @@
   static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
                                              "armv7hl-redhat-linux-gnueabi",
                                              "armv6hl-suse-linux-gnueabi",
-                                             "armv7hl-suse-linux-gnueabi"};
+                                             "armv7hl-suse-linux-gnueabi",
+                                             "armv7l-linux-gnueabihf"};
   static const char *const ARMebLibDirs[] = {"/lib"};
   static const char *const ARMebTriples[] = {"armeb-linux-gnueabi",
                                              "armeb-linux-androideabi"};
@@ -2014,6 +2015,78 @@
     return;
   }
 
+  if (TargetTriple.isMusl()) {
+    static const char *const AArch64MuslTriples[] = {"aarch64-linux-musl"};
+    static const char *const ARMHFMuslTriples[] = {
+        "arm-linux-musleabihf", "armv7l-linux-musleabihf"
+    };
+    static const char *const ARMMuslTriples[] = {"arm-linux-musleabi"};
+    static const char *const X86_64MuslTriples[] = {"x86_64-linux-musl"};
+    static const char *const X86MuslTriples[] = {"i686-linux-musl"};
+    static const char *const MIPSMuslTriples[] = {
+        "mips-linux-musl", "mipsel-linux-musl",
+        "mipsel-linux-muslhf", "mips-linux-muslhf"
+    };
+    static const char *const PPCMuslTriples[] = {"powerpc-linux-musl"};
+    static const char *const PPC64MuslTriples[] = {"powerpc64-linux-musl"};
+    static const char *const PPC64LEMuslTriples[] = {"powerpc64le-linux-musl"};
+
+    switch (TargetTriple.getArch()) {
+    case llvm::Triple::aarch64:
+      LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
+      TripleAliases.append(begin(AArch64MuslTriples), end(AArch64MuslTriples));
+      BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
+      BiarchTripleAliases.append(begin(AArch64MuslTriples), 
end(AArch64MuslTriples));
+      break;
+    case llvm::Triple::arm:
+      LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
+      if (TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF) {
+        TripleAliases.append(begin(ARMHFMuslTriples), end(ARMHFMuslTriples));
+      } else {
+        TripleAliases.append(begin(ARMMuslTriples), end(ARMMuslTriples));
+      }
+      break;
+    case llvm::Triple::x86_64:
+      LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+      TripleAliases.append(begin(X86_64MuslTriples), end(X86_64MuslTriples));
+      BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
+      BiarchTripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples));
+      break;
+    case llvm::Triple::x86:
+      LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
+      TripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples));
+      BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+      BiarchTripleAliases.append(begin(X86_64MuslTriples), 
end(X86_64MuslTriples));
+      break;
+    case llvm::Triple::mips:
+      LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
+      TripleAliases.append(begin(MIPSMuslTriples), end(MIPSMuslTriples));
+      break;
+    case llvm::Triple::ppc:
+      LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
+      TripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples));
+      BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
+      BiarchTripleAliases.append(begin(PPC64MuslTriples), 
end(PPC64MuslTriples));
+      break;
+    case llvm::Triple::ppc64:
+      LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
+      TripleAliases.append(begin(PPC64MuslTriples), end(PPC64MuslTriples));
+      BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
+      BiarchTripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples));
+      break;
+    case llvm::Triple::ppc64le:
+      LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
+      TripleAliases.append(begin(PPC64LEMuslTriples), end(PPC64LEMuslTriples));
+      break;
+    default:
+      break;
+    }
+    TripleAliases.push_back(TargetTriple.str());
+    if (TargetTriple.str() != BiarchTriple.str())
+      BiarchTripleAliases.push_back(BiarchTriple.str());
+    return;
+  }
+
   // Android targets should not use GNU/Linux tools or libraries.
   if (TargetTriple.isAndroid()) {
     static const char *const AArch64AndroidTriples[] = {


Index: b/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- b/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -1882,7 +1882,8 @@
   static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
                                              "armv7hl-redhat-linux-gnueabi",
                                              "armv6hl-suse-linux-gnueabi",
-                                             "armv7hl-suse-linux-gnueabi"};
+                                             "armv7hl-suse-linux-gnueabi",
+                                             "armv7l-linux-gnueabihf"};
   static const char *const ARMebLibDirs[] = {"/lib"};
   static const char *const ARMebTriples[] = {"armeb-linux-gnueabi",
                                              "armeb-linux-androideabi"};
@@ -2014,6 +2015,78 @@
     return;
   }
 
+  if (TargetTriple.isMusl()) {
+    static const char *const AArch64MuslTriples[] = {"aarch64-linux-musl"};
+    static const char *const ARMHFMuslTriples[] = {
+        "arm-linux-musleabihf", "armv7l-linux-musleabihf"
+    };
+    static const char *const ARMMuslTriples[] = {"arm-linux-musleabi"};
+    static const char *const X86_64MuslTriples[] = {"x86_64-linux-musl"};
+    static const char *const X86MuslTriples[] = {"i686-linux-musl"};
+    static const char *const MIPSMuslTriples[] = {
+        "mips-linux-musl", "mipsel-linux-musl",
+        "mipsel-linux-muslhf", "mips-linux-muslhf"
+    };
+    static const char *const PPCMuslTriples[] = {"powerpc-linux-musl"};
+    static const char *const PPC64MuslTriples[] = {"powerpc64-linux-musl"};
+    static const char *const PPC64LEMuslTriples[] = {"powerpc64le-linux-musl"};
+
+    switch (TargetTriple.getArch()) {
+    case llvm::Triple::aarch64:
+      LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
+      TripleAliases.append(begin(AArch64MuslTriples), end(AArch64MuslTriples));
+      BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
+      BiarchTripleAliases.append(begin(AArch64MuslTriples), end(AArch64MuslTriples));
+      break;
+    case llvm::Triple::arm:
+      LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
+      if (TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF) {
+        TripleAliases.append(begin(ARMHFMuslTriples), end(ARMHFMuslTriples));
+      } else {
+        TripleAliases.append(begin(ARMMuslTriples), end(ARMMuslTriples));
+      }
+      break;
+    case llvm::Triple::x86_64:
+      LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+      TripleAliases.append(begin(X86_64MuslTriples), end(X86_64MuslTriples));
+      BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
+      BiarchTripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples));
+      break;
+    case llvm::Triple::x86:
+      LibDirs.append(begin(X86LibDirs), end(X86LibDirs));
+      TripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples));
+      BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+      BiarchTripleAliases.append(begin(X86_64MuslTriples), end(X86_64MuslTriples));
+      break;
+    case llvm::Triple::mips:
+      LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
+      TripleAliases.append(begin(MIPSMuslTriples), end(MIPSMuslTriples));
+      break;
+    case llvm::Triple::ppc:
+      LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
+      TripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples));
+      BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
+      BiarchTripleAliases.append(begin(PPC64MuslTriples), end(PPC64MuslTriples));
+      break;
+    case llvm::Triple::ppc64:
+      LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs));
+      TripleAliases.append(begin(PPC64MuslTriples), end(PPC64MuslTriples));
+      BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs));
+      BiarchTripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples));
+      break;
+    case llvm::Triple::ppc64le:
+      LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs));
+      TripleAliases.append(begin(PPC64LEMuslTriples), end(PPC64LEMuslTriples));
+      break;
+    default:
+      break;
+    }
+    TripleAliases.push_back(TargetTriple.str());
+    if (TargetTriple.str() != BiarchTriple.str())
+      BiarchTripleAliases.push_back(BiarchTriple.str());
+    return;
+  }
+
   // Android targets should not use GNU/Linux tools or libraries.
   if (TargetTriple.isAndroid()) {
     static const char *const AArch64AndroidTriples[] = {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to