[PATCH] D134454: [Driver][Distro] Fix ArchLinux triplet and sysroot detection

Adrian Ratiu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 23 02:06:51 PDT 2022


10ne1 updated this revision to Diff 462423.
10ne1 added a comment.

Regenerated diff with git diff HEAD~1 -U999999


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134454/new/

https://reviews.llvm.org/D134454

Files:
  clang/include/clang/Driver/Distro.h
  clang/lib/Driver/Distro.cpp
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,6 +370,16 @@
     return std::string();
   }
 
+  const Distro Distro(getDriver().getVFS(), getTriple());
+  const StringRef InstallDir = GCCInstallation.getInstallPath();
+  const StringRef TripleStr = GCCInstallation.getTriple().str();
+
+  if (Distro.IsArchLinux()) {
+    std::string Path = (InstallDir + "/../../../../"  + TripleStr).str();
+    if (getVFS().exists(Path))
+      return Path;
+  }
+
   if (!GCCInstallation.isValid() || !getTriple().isMIPS())
     return std::string();
 
@@ -377,8 +387,6 @@
   // and put it into different places. Here we try to check some known
   // variants.
 
-  const StringRef InstallDir = GCCInstallation.getInstallPath();
-  const StringRef TripleStr = GCCInstallation.getTriple().str();
   const Multilib &Multilib = GCCInstallation.getMultilib();
 
   std::string Path =
Index: clang/lib/Driver/Distro.cpp
===================================================================
--- clang/lib/Driver/Distro.cpp
+++ clang/lib/Driver/Distro.cpp
@@ -205,9 +205,16 @@
 
 static Distro::DistroType GetDistro(llvm::vfs::FileSystem &VFS,
                                     const llvm::Triple &TargetOrHost) {
+
+  // Sometimes the OS can't be detected from the triplet due to ambiguity, for
+  // eg. ArchLinux uses aarch64-linux-gnu which results in Uknonwn OS & distro,
+  // so normalize the triplet which results in aarch64-unknown-linux-gnu, such
+  // that the Linux OS and distro are properly detected in this cases.
+  llvm::Triple NormTargetOrHost = llvm::Triple(Twine(TargetOrHost.normalize()));
+
   // If we don't target Linux, no need to check the distro. This saves a few
   // OS calls.
-  if (!TargetOrHost.isOSLinux())
+  if (!NormTargetOrHost.isOSLinux())
     return Distro::UnknownDistro;
 
   // True if we're backed by a real file system.
Index: clang/include/clang/Driver/Distro.h
===================================================================
--- clang/include/clang/Driver/Distro.h
+++ clang/include/clang/Driver/Distro.h
@@ -134,6 +134,8 @@
 
   bool IsGentoo() const { return DistroVal == Gentoo; }
 
+  bool IsArchLinux() const { return DistroVal == ArchLinux; }
+
   /// @}
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134454.462423.patch
Type: text/x-patch
Size: 2359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220923/1639c66a/attachment.bin>


More information about the cfe-commits mailing list