[PATCH] D99852: [Driver] Detect libstdc++ include paths for native gcc (-m32 and -m64) on Debian i386

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 3 21:54:14 PDT 2021


MaskRay updated this revision to Diff 335127.
MaskRay added a comment.

`git add` two .keep files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99852

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/Inputs/debian_i386_tree/lib/i386-linux-gnu/.keep
  clang/test/Driver/Inputs/debian_i386_tree/lib/x86_64-linux-gnu/.keep
  clang/test/Driver/Inputs/debian_i386_tree/lib64/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/include/c++/10/backward/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/include/i386-linux-gnu/c++/10/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/include/i386-linux-gnu/c++/10/64/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/include/x86_64-linux-gnu/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/gcc/i686-linux-gnu/10/64/crtbegin.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/gcc/i686-linux-gnu/10/crtbegin.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/gcc/i686-linux-gnu/10/crtend.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/i386-linux-gnu/crt1.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/i386-linux-gnu/crti.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/i386-linux-gnu/crtn.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib/x86_64-linux-gnu/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib64/.keep
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib64/crt1.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib64/crti.o
  clang/test/Driver/Inputs/debian_i386_tree/usr/lib64/crtn.o
  clang/test/Driver/linux-cross.cpp


Index: clang/test/Driver/linux-cross.cpp
===================================================================
--- clang/test/Driver/linux-cross.cpp
+++ clang/test/Driver/linux-cross.cpp
@@ -49,6 +49,55 @@
 // DEBIAN_X86_64_M32-SAME: {{^}} "-L[[SYSROOT]]/lib"
 // DEBIAN_X86_64_M32-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
 
+/// Test native GCC installation on Debian i386.
+// RUN: %clang -### %s --target=i686-linux-gnu --sysroot=%S/Inputs/debian_i386_tree \
+// RUN:   -resource-dir=%S/Inputs/resource_dir --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=DEBIAN_I686
+// DEBIAN_I686:      "-resource-dir" "[[RESOURCE:[^"]+]]"
+// DEBIAN_I686:      "-internal-isystem"
+// DEBIAN_I686-SAME: {{^}} "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/c++/10"
+/// Debian specific - the path component after 'include' is i386-linux-gnu even
+/// though the installation is i686-linux-gnu.
+// DEBIAN_I686-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/i386-linux-gnu/c++/10"
+// DEBIAN_I686-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/c++/10/backward"
+// DEBIAN_I686-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// DEBIAN_I686-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+/// This resolves to /usr/i686-linux-gnu/include. Because it does not exist,
+/// having it does no harm albeit not ideal.
+// DEBIAN_I686-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../i686-linux-gnu/include"
+// DEBIAN_I686:      "-internal-externc-isystem"
+// DEBIAN_I686-SAME: {{^}} "[[SYSROOT]]/usr/include/i386-linux-gnu"
+// DEBIAN_I686:      "-L
+// DEBIAN_I686-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/10"
+// DEBIAN_I686-SAME: {{^}} "-L[[SYSROOT]]/lib/i386-linux-gnu"
+// DEBIAN_I686-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/i386-linux-gnu"
+// DEBIAN_I686-SAME: {{^}} "-L[[SYSROOT]]/lib"
+// DEBIAN_I686-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
+/// Test -m64 on Debian i386.
+// RUN: %clang -### %s --target=i686-linux-gnu --sysroot=%S/Inputs/debian_i386_tree -m64 \
+// RUN:   -resource-dir=%S/Inputs/resource_dir --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=DEBIAN_I686_M64
+// DEBIAN_I686_M64:      "-resource-dir" "[[RESOURCE:[^"]+]]"
+// DEBIAN_I686_M64:      "-internal-isystem"
+// DEBIAN_I686_M64-SAME: {{^}} "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/c++/10"
+/// Debian specific - the path component after 'include' is i386-linux-gnu even
+/// though the installation is i686-linux-gnu.
+// DEBIAN_I686_M64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/i386-linux-gnu/c++/10/64"
+// DEBIAN_I686_M64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../include/c++/10/backward"
+// DEBIAN_I686_M64-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]/include"
+// DEBIAN_I686_M64-SAME: {{^}} "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// DEBIAN_I686_M64-SAME: {{^}} "-internal-isystem" "[[SYSROOT:[^"]+]]/usr/lib/gcc/i686-linux-gnu/10/../../../../i686-linux-gnu/include"
+// DEBIAN_I686_M64:      "-internal-externc-isystem"
+// DEBIAN_I686_M64-SAME: {{^}} "[[SYSROOT]]/usr/include/x86_64-linux-gnu"
+// DEBIAN_I686_M64:      "-L
+// DEBIAN_I686_M64-SAME: {{^}}[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/10/64"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/gcc/i686-linux-gnu/10/../../../../lib64"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/lib/x86_64-linux-gnu"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/lib/../lib64"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/x86_64-linux-gnu"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib/../lib64"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/lib"
+// DEBIAN_I686_M64-SAME: {{^}} "-L[[SYSROOT]]/usr/lib"
+
 /// Test a cross compiler.
 // RUN: %clang -### %s --target=aarch64-linux-gnu --sysroot=%S/Inputs/debian_multiarch_tree \
 // RUN:   -resource-dir=%S/Inputs/resource_dir --stdlib=platform --rtlib=platform 2>&1 | FileCheck %s --check-prefix=DEBIAN_AARCH64
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2983,9 +2983,13 @@
           TripleStr, Multilib.includeSuffix(), DriverArgs, CC1Args))
     return true;
   // Detect Debian g++-multiarch-incdir.diff.
+  StringRef DebianMultiarch =
+      GCCInstallation.getTriple().getArch() == llvm::Triple::x86
+          ? "i386-linux-gnu"
+          : TripleStr;
   if (addLibStdCXXIncludePaths(LibDir.str() + "/../include/c++/" + Version.Text,
-                               TripleStr, Multilib.includeSuffix(), DriverArgs,
-                               CC1Args, /*Debian=*/true))
+                               DebianMultiarch, Multilib.includeSuffix(),
+                               DriverArgs, CC1Args, /*Debian=*/true))
     return true;
 
   // Otherwise, fall back on a bunch of options which don't use multiarch


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99852.335127.patch
Type: text/x-patch
Size: 5163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210404/26a1c425/attachment-0001.bin>


More information about the cfe-commits mailing list