[PATCH] D43630: [Driver] Fix search paths on x32

James Clarke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 22 09:33:31 PST 2018


jrtc27 created this revision.
Herald added a subscriber: cfe-commits.

When targeting x32, the x32 libraries and headers should be used, not
the x86_64 ones (which may not even be available), so prioritise those
and use the right multiarch triple.


Repository:
  rC Clang

https://reviews.llvm.org/D43630

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


Index: lib/Driver/ToolChains/Linux.cpp
===================================================================
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -78,10 +78,13 @@
       return "i386-linux-gnu";
     break;
   case llvm::Triple::x86_64:
-    // We don't want this for x32, otherwise it will match x86_64 libs
-    if (TargetEnvironment != llvm::Triple::GNUX32 &&
-        D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
-      return "x86_64-linux-gnu";
+    if (TargetEnvironment == llvm::Triple::GNUX32) {
+      if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32"))
+        return "x86_64-linux-gnux32";
+    } else {
+      if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu"))
+        return "x86_64-linux-gnu";
+    }
     break;
   case llvm::Triple::aarch64:
     if (D.getVFS().exists(SysRoot + "/lib/aarch64-linux-gnu"))
@@ -620,6 +623,8 @@
       // in use in any released version of Debian, so we should consider
       // removing them.
       "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"};
+  const StringRef X32MultiarchIncludeDirs[] = {
+      "/usr/include/x86_64-linux-gnux32"};
   const StringRef X86MultiarchIncludeDirs[] = {
       "/usr/include/i386-linux-gnu",
 
@@ -661,7 +666,10 @@
   ArrayRef<StringRef> MultiarchIncludeDirs;
   switch (getTriple().getArch()) {
   case llvm::Triple::x86_64:
-    MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
+    if (getTriple().getEnvironment() == llvm::Triple::GNUX32)
+      MultiarchIncludeDirs = X32MultiarchIncludeDirs;
+    else
+      MultiarchIncludeDirs = X86_64MultiarchIncludeDirs;
     break;
   case llvm::Triple::x86:
     MultiarchIncludeDirs = X86MultiarchIncludeDirs;
Index: lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1848,7 +1848,10 @@
       "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
       "x86_64-slackware-linux", "x86_64-linux-android",
       "x86_64-unknown-linux"};
-  static const char *const X32LibDirs[] = {"/libx32"};
+  static const char *const X32LibDirs[] = {"/libx32", "/lib"};
+  static const char *const X32Triples[] = {
+      "x86_64-linux-gnux32",    "x86_64-unknown-linux-gnux32",
+      "x86_64-pc-linux-gnux32"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
       "i686-linux-gnu",       "i686-pc-linux-gnu",     "i486-linux-gnu",
@@ -1989,14 +1992,16 @@
     }
     break;
   case llvm::Triple::x86_64:
-    LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
-    TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
     // x32 is always available when x86_64 is available, so adding it as
     // secondary arch with x86_64 triples
     if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) {
-      BiarchLibDirs.append(begin(X32LibDirs), end(X32LibDirs));
+      LibDirs.append(begin(X32LibDirs), end(X32LibDirs));
+      TripleAliases.append(begin(X32Triples), end(X32Triples));
+      BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
       BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
     } else {
+      LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs));
+      TripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
       BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs));
       BiarchTripleAliases.append(begin(X86Triples), end(X86Triples));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43630.135444.patch
Type: text/x-patch
Size: 3530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180222/0896b36c/attachment.bin>


More information about the cfe-commits mailing list