[PATCH] D70306: clang: Exherbo multiarch ajustments

Marc-Antoine Perennou via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 05:55:24 PST 2019


Keruspe created this revision.
Keruspe added reviewers: dlj, rsmith, compnerd.
Keruspe added a project: clang.
Herald added a subscriber: cfe-commits.

Exherbo multiarch layout being somewhat specific, some adjustments need to be made wrt the lookup paths.

Based in parts on patches by Marvin Schmidt


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70306

Files:
  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
@@ -350,9 +350,21 @@
     //
     // Note that this matches the GCC behavior. See the below comment for where
     // Clang diverges from GCC's behavior.
-    addPathIfExists(D, LibPath + "/../" + GCCTriple.str() + "/lib/../" +
-                           OSLibDir + SelectedMultilib.osSuffix(),
-                    Paths);
+    //
+    // On Exherbo, the GCC installation will reside in e.g.
+    //   /usr/x86_64-pc-linux-gnu/lib/gcc/armv7-unknown-linux-gnueabihf/9.2.0
+    // while the matching lib path is
+    //   /usr/armv7-unknown-linux-gnueabihf/lib
+    if (Distro == Distro::Exherbo)
+      addPathIfExists(D,
+                      LibPath + "/../../" + GCCTriple.str() + "/lib/../" +
+                          OSLibDir + SelectedMultilib.osSuffix(),
+                      Paths);
+    else
+      addPathIfExists(D,
+                      LibPath + "/../" + GCCTriple.str() + "/lib/../" +
+                          OSLibDir + SelectedMultilib.osSuffix(),
+                      Paths);
 
     // If the GCC installation we found is inside of the sysroot, we want to
     // prefer libraries installed in the parent prefix of the GCC installation.
@@ -844,6 +856,31 @@
   if (getTriple().isAndroid())
     MultiarchIncludeDirs = AndroidMultiarchIncludeDirs;
 
+  // Exherbo's multiarch layout is /usr/<triple>/include and not
+  // /usr/include/<triple>
+  const Distro Distro(D.getVFS());
+  std::string ExherboMultiarchIncludeDir =
+      std::string("/usr/") + getTriple().str() + "/include";
+  if (Distro == Distro::Exherbo) {
+    switch (getTriple().getArch()) {
+    case llvm::Triple::x86_64:
+      if (getTriple().isMusl())
+        ExherboMultiarchIncludeDir = "/usr/x86_64-pc-linux-musl/include";
+      else
+        ExherboMultiarchIncludeDir = "/usr/x86_64-pc-linux-gnu/include";
+      break;
+    case llvm::Triple::x86:
+      if (getTriple().isMusl())
+        ExherboMultiarchIncludeDir = "/usr/i686-pc-linux-musl/include";
+      else
+        ExherboMultiarchIncludeDir = "/usr/i686-pc-linux-gnu/include";
+      break;
+    default:
+      break;
+    }
+    MultiarchIncludeDirs = {ExherboMultiarchIncludeDir};
+  }
+
   for (StringRef Dir : MultiarchIncludeDirs) {
     if (D.getVFS().exists(SysRoot + Dir)) {
       addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + Dir);
@@ -917,12 +954,30 @@
   StringRef LibDir = GCCInstallation.getParentLibPath();
   StringRef InstallDir = GCCInstallation.getInstallPath();
   StringRef TripleStr = GCCInstallation.getTriple().str();
+  const Driver &D = getDriver();
   const Multilib &Multilib = GCCInstallation.getMultilib();
-  const std::string GCCMultiarchTriple = getMultiarchTriple(
-      getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot);
+  const std::string GCCMultiarchTriple =
+      getMultiarchTriple(D, GCCInstallation.getTriple(), D.SysRoot);
   const std::string TargetMultiarchTriple =
-      getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
+      getMultiarchTriple(D, getTriple(), D.SysRoot);
   const GCCVersion &Version = GCCInstallation.getVersion();
+  const Distro Distro(D.getVFS());
+
+  // On Exherbo the consecutive addLibStdCXXIncludePaths call would evaluate to:
+  //   LibDir = /usr/lib/gcc/<triple>/9.2.0/../../..
+  //          = /usr/lib/
+  //   LibDir + "/../include" = /usr/include
+  // addLibStdCXXIncludePaths would then check if "/usr/include/c++/<version>"
+  // exists, and add that as include path when what we want is
+  // "/usr/<triple>/include/c++/<version>"
+  // Note that "/../../" is needed and not just "/../" as /usr/include points to
+  // /usr/host/include
+  if (Distro == Distro::Exherbo &&
+      addLibStdCXXIncludePaths(
+          LibDir.str() + "/../../" + TripleStr + "/include",
+          "/c++/" + Version.Text, TripleStr, GCCMultiarchTriple,
+          TargetMultiarchTriple, Multilib.includeSuffix(), DriverArgs, CC1Args))
+    return;
 
   // The primary search for libstdc++ supports multiarch variants.
   if (addLibStdCXXIncludePaths(LibDir.str() + "/../include",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70306.229520.patch
Type: text/x-patch
Size: 4257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191115/f8942dc0/attachment-0001.bin>


More information about the cfe-commits mailing list