[PATCH] D50246: [RISCV] Add support for computing sysroot for riscv32-unknown-elf
Lewis Revill via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 3 06:19:23 PDT 2018
lewis-revill updated this revision to Diff 158994.
lewis-revill added a comment.
Modified test which assumed the path to C++ includes was determined without use of the sysroot path.
Repository:
rC Clang
https://reviews.llvm.org/D50246
Files:
lib/Driver/ToolChains/RISCV.cpp
lib/Driver/ToolChains/RISCV.h
test/Driver/riscv32-toolchain.c
Index: test/Driver/riscv32-toolchain.c
===================================================================
--- test/Driver/riscv32-toolchain.c
+++ test/Driver/riscv32-toolchain.c
@@ -24,7 +24,7 @@
// RUN: --sysroot=%S/Inputs/basic_riscv32_tree/riscv32-unknown-elf 2>&1 \
// RUN: | FileCheck -check-prefix=CXX-RV32-BAREMETAL-ILP32 %s
-// CXX-RV32-BAREMETAL-ILP32: "-internal-isystem" "{{.*}}Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/../../../../riscv32-unknown-elf/include/c++{{/|\\\\}}8.0.1"
+// CXX-RV32-BAREMETAL-ILP32: "-internal-isystem" "{{.*}}Inputs/basic_riscv32_tree/riscv32-unknown-elf/include/c++{{/|\\\\}}8.0.1"
// CXX-RV32-BAREMETAL-ILP32: "{{.*}}Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1/../../../../bin{{/|\\\\}}riscv32-unknown-elf-ld"
// CXX-RV32-BAREMETAL-ILP32: "--sysroot={{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf"
// CXX-RV32-BAREMETAL-ILP32: "{{.*}}/Inputs/basic_riscv32_tree/riscv32-unknown-elf/lib{{/|\\\\}}crt0.o"
Index: lib/Driver/ToolChains/RISCV.h
===================================================================
--- lib/Driver/ToolChains/RISCV.h
+++ lib/Driver/ToolChains/RISCV.h
@@ -32,6 +32,9 @@
protected:
Tool *buildLinker() const override;
+
+private:
+ std::string computeSysRoot() const;
};
} // end namespace toolchains
Index: lib/Driver/ToolChains/RISCV.cpp
===================================================================
--- lib/Driver/ToolChains/RISCV.cpp
+++ lib/Driver/ToolChains/RISCV.cpp
@@ -13,6 +13,7 @@
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@@ -27,7 +28,7 @@
const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
GCCInstallation.init(Triple, Args);
- getFilePaths().push_back(D.SysRoot + "/lib");
+ getFilePaths().push_back(computeSysRoot() + "/lib");
if (GCCInstallation.isValid()) {
getFilePaths().push_back(GCCInstallation.getInstallPath().str());
getProgramPaths().push_back(
@@ -45,24 +46,39 @@
return;
if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
- SmallString<128> Dir(getDriver().SysRoot);
+ SmallString<128> Dir(computeSysRoot());
llvm::sys::path::append(Dir, "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
}
}
void RISCVToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
- StringRef LibDir = GCCInstallation.getParentLibPath();
const GCCVersion &Version = GCCInstallation.getVersion();
StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
- addLibStdCXXIncludePaths(
- LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,
+ addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
"", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args);
}
+std::string RISCVToolChain::computeSysRoot() const {
+ 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();
+
+ if (!llvm::sys::fs::exists(SysRootDir))
+ return std::string();
+
+ return SysRootDir;
+}
+
void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50246.158994.patch
Type: text/x-patch
Size: 3753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180803/a85b5a99/attachment.bin>
More information about the cfe-commits
mailing list