[PATCH] D134478: BareMetal: detect usr/include/c++/v1 path in sysroot

Manoj Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 21:26:00 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e5d21462d1e: BareMetal: detect usr/include/c++/v1 path in sysroot (authored by manojgupta).

Changed prior to commit:
  https://reviews.llvm.org/D134478?vs=465647&id=466250#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134478

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===================================================================
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -77,6 +77,22 @@
 // CHECK-V6M-NDL-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-NDL-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 
+// RUN: rm -rf %T/baremetal_cxx_sysroot
+// RUN: mkdir -p %T/baremetal_cxx_sysroot/usr/include/c++/v1
+// RUN: %clangxx %s -### 2>&1 \
+// RUN:     --target=armv6m-none-eabi \
+// RUN:     --sysroot=%T/baremetal_cxx_sysroot \
+// RUN:     -stdlib=libc++ \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBCXX-USR %s
+// CHECK-V6M-LIBCXX-USR: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-V6M-LIBCXX-USR-NOT: "-internal-isystem" "{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
+// CHECK-V6M-LIBCXX-USR-SAME: "-internal-isystem" "{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}usr{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-V6M-LIBCXX-USR: "{{[^"]*}}-Bstatic"
+// CHECK-V6M-LIBCXX-USR-SAME: "-L{{[^"]*}}{{[/\\]+}}baremetal_cxx_sysroot{{[/\\]+}}lib"
+// CHECK-V6M-LIBCXX-USR-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc++" "-lc++abi" "-lunwind"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
+
 // RUN: %clangxx --target=arm-none-eabi -v 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-THREAD-MODEL
 // CHECK-THREAD-MODEL: Thread model: posix
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===================================================================
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -217,12 +217,21 @@
       DriverArgs.hasArg(options::OPT_nostdincxx))
     return;
 
+  const Driver &D = getDriver();
   std::string SysRoot(computeSysRoot());
   if (SysRoot.empty())
     return;
 
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
+    // First check sysroot/usr/include/c++/v1 if it exists.
+    SmallString<128> TargetDir(SysRoot);
+    llvm::sys::path::append(TargetDir, "usr", "include", "c++", "v1");
+    if (D.getVFS().exists(TargetDir)) {
+      addSystemInclude(DriverArgs, CC1Args, TargetDir.str());
+      break;
+    }
+    // Add generic path if nothing else succeeded so far.
     SmallString<128> Dir(SysRoot);
     llvm::sys::path::append(Dir, "include", "c++", "v1");
     addSystemInclude(DriverArgs, CC1Args, Dir.str());
@@ -234,9 +243,8 @@
     std::error_code EC;
     Generic_GCC::GCCVersion Version = {"", -1, -1, -1, "", "", ""};
     // Walk the subdirs, and find the one with the newest gcc version:
-    for (llvm::vfs::directory_iterator
-             LI = getDriver().getVFS().dir_begin(Dir.str(), EC),
-             LE;
+    for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(Dir.str(), EC),
+                                       LE;
          !EC && LI != LE; LI = LI.increment(EC)) {
       StringRef VersionText = llvm::sys::path::filename(LI->path());
       auto CandidateVersion = Generic_GCC::GCCVersion::Parse(VersionText);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134478.466250.patch
Type: text/x-patch
Size: 3165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221008/1b3ba2e8/attachment-0001.bin>


More information about the cfe-commits mailing list