[PATCH] D68391: [RISCV] Improve sysroot computation if no GCC install detected

Edward Jones via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 3 07:10:47 PDT 2019


edward-jones created this revision.
Herald added subscribers: cfe-commits, pzheng, simoncook, s.egerton, lenary, Jim, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, zzheng, MaskRay, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, apazos, johnrusso, rbar, asb.
Herald added a project: clang.

If a GCC installed is not detected, the driver would default to the root of the filesystem. This is not ideal when this doesn't match the install directory of the toolchain and can cause undesireable behavior such as picking up system libraries or the system linker when cross-compiling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68391

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp


Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===================================================================
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -73,17 +73,20 @@
   if (!getDriver().SysRoot.empty())
     return getDriver().SysRoot;
 
-  if (!GCCInstallation.isValid())
-    return std::string();
-
-  StringRef LibDir = GCCInstallation.getParentLibPath();
-  StringRef TripleStr = GCCInstallation.getTriple().str();
-  std::string SysRootDir = LibDir.str() + "/../" + TripleStr.str();
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+    StringRef LibDir = GCCInstallation.getParentLibPath();
+    StringRef TripleStr = GCCInstallation.getTriple().str();
+    llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+    llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+                            getTriple().str());
+  }
 
   if (!llvm::sys::fs::exists(SysRootDir))
     return std::string();
 
-  return SysRootDir;
+  return SysRootDir.str();
 }
 
 void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68391.223008.patch
Type: text/x-patch
Size: 1154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191003/c59ee83c/attachment.bin>


More information about the cfe-commits mailing list