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,