summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Driver/ToolChains/RISCVToolchain.cpp')
-rw-r--r--clang/lib/Driver/ToolChains/RISCVToolchain.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 8019940b521..bd63873e3c6 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -22,19 +22,39 @@ using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet &Multilibs,
+ const Multilib &Multilib,
+ StringRef InstallPath,
+ ToolChain::path_list &Paths) {
+ if (const auto &PathsCallback = Multilibs.filePathsCallback())
+ for (const auto &Path : PathsCallback(Multilib))
+ addPathIfExists(D, InstallPath + Path, Paths);
+}
+
/// RISCV Toolchain
RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
GCCInstallation.init(Triple, Args);
- getFilePaths().push_back(computeSysRoot() + "/lib");
if (GCCInstallation.isValid()) {
+ Multilibs = GCCInstallation.getMultilibs();
+ SelectedMultilib = GCCInstallation.getMultilib();
+ path_list &Paths = getFilePaths();
+ // Add toolchain/multilib specific file paths.
+ addMultilibsFilePaths(D, Multilibs, SelectedMultilib,
+ GCCInstallation.getInstallPath(), Paths);
getFilePaths().push_back(GCCInstallation.getInstallPath().str());
- getProgramPaths().push_back(
- (GCCInstallation.getParentLibPath() + "/../bin").str());
+ ToolChain::path_list &PPaths = getProgramPaths();
+ // Multilib cross-compiler GCC installations put ld in a triple-prefixed
+ // directory off of the parent of the GCC installation.
+ PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
+ GCCInstallation.getTriple().str() + "/bin")
+ .str());
+ PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
} else {
getProgramPaths().push_back(D.Dir);
}
+ getFilePaths().push_back(computeSysRoot() + "/lib");
}
Tool *RISCVToolChain::buildLinker() const {
@@ -105,6 +125,14 @@ void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!D.SysRoot.empty())
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+ bool IsRV64 = ToolChain.getArch() == llvm::Triple::riscv64;
+ CmdArgs.push_back("-m");
+ if (IsRV64) {
+ CmdArgs.push_back("elf64lriscv");
+ } else {
+ CmdArgs.push_back("elf32lriscv");
+ }
+
std::string Linker = getToolChain().GetProgramPath(getShortName());
bool WantCRTs =
OpenPOWER on IntegriCloud