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

John Paul Adrian Glaubitz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 13 12:01:58 PDT 2018


glaubitz created this revision.
glaubitz added reviewers: rsmith, dschuff.
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/D52050

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
@@ -86,10 +86,13 @@
   case llvm::Triple::x86_64:
     if (IsAndroid)
       return "x86_64-linux-android";
-    // 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 (IsAndroid)
@@ -672,6 +675,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",
 
@@ -713,7 +718,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
@@ -1829,7 +1829,10 @@
       "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
       "x86_64-slackware-linux", "x86_64-unknown-linux",
       "x86_64-amazon-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",
@@ -2023,14 +2026,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: D52050.165343.patch
Type: text/x-patch
Size: 3499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/599caa03/attachment.bin>


More information about the cfe-commits mailing list