[PATCH] D101967: [Driver] Use x86-64 libc++ headers with -m32

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 5 18:57:50 PDT 2021


phosek created this revision.
phosek added reviewers: mcgrathr, leonardchan.
Herald added a subscriber: pengfei.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

x86 is only used for the bootloader and we use x86-64 libc++ headers
in that case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101967

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/i386-unknown-fuchsia/libclang_rt.builtins.a
  clang/test/Driver/fuchsia.cpp


Index: clang/test/Driver/fuchsia.cpp
===================================================================
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -13,16 +13,23 @@
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s
+// RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia -m32 \
+// RUN:     -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     | FileCheck -check-prefixes=CHECK,CHECK-X86_64-M32 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
 // CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia"
 // CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia"
+// CHECK-X86_64-M32: "-triple" "i386-unknown-fuchsia"
 // CHECK-NOT: "-fno-use-init-array"
 // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK-X86_64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1"
 // CHECK-AARCH64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}aarch64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1"
 // CHECK-RISCV64: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}riscv64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1"
+// CHECK-X86_64-M32: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}c++{{/|\\\\}}v1"
 // CHECK: "-internal-isystem" "{{.*[/\\]}}include{{/|\\\\}}c++{{/|\\\\}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include"
 // CHECK: {{.*}}ld.lld{{.*}}" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments"
@@ -42,6 +49,7 @@
 // CHECK-X86_64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a"
 // CHECK-AARCH64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aarch64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a"
 // CHECK-RISCV64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}riscv64-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a"
+// CHECK-X86_64-M32: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}i386-unknown-fuchsia{{/|\\\\}}libclang_rt.builtins.a"
 // CHECK: "-lc"
 // CHECK-NOT: crtend.o
 // CHECK-NOT: crtn.o
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -358,31 +358,30 @@
       DriverArgs.hasArg(options::OPT_nostdincxx))
     return;
 
-  const Driver &D = getDriver();
-  std::string Target = getTripleString();
+  llvm::Triple Triple = getTriple();
+  // x86 is only used for the bootloader and we use x86-64 headers in that case.
+  if (Triple.getArch() == llvm::Triple::x86)
+    Triple.setArch(llvm::Triple::x86_64);
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+    SmallString<128> P(getDriver().Dir);
+    llvm::sys::path::append(P, "..", "include");
 
-  auto AddCXXIncludePath = [&](StringRef Path) {
-    std::string Version = detectLibcxxVersion(Path);
+    std::string Version = detectLibcxxVersion(P);
     if (Version.empty())
       return;
 
-    // First add the per-target include path.
-    SmallString<128> TargetDir(Path);
-    llvm::sys::path::append(TargetDir, Target, "c++", Version);
+    // First add the per-target include path if it exists.
+    SmallString<128> TargetDir(P);
+    llvm::sys::path::append(TargetDir, Triple.str(), "c++", Version);
     if (getVFS().exists(TargetDir))
       addSystemInclude(DriverArgs, CC1Args, TargetDir);
 
     // Second add the generic one.
-    SmallString<128> Dir(Path);
+    SmallString<128> Dir(P);
     llvm::sys::path::append(Dir, "c++", Version);
     addSystemInclude(DriverArgs, CC1Args, Dir);
-  };
-
-  switch (GetCXXStdlibType(DriverArgs)) {
-  case ToolChain::CST_Libcxx: {
-    SmallString<128> P(D.Dir);
-    llvm::sys::path::append(P, "..", "include");
-    AddCXXIncludePath(P);
     break;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101967.343266.patch
Type: text/x-patch
Size: 4151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210506/413ee09b/attachment.bin>


More information about the cfe-commits mailing list