2018-09-28 04:36:28 +08:00
|
|
|
//===--- RISCVToolchain.cpp - RISCV ToolChain Implementations ---*- C++ -*-===//
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-09-28 04:36:28 +08:00
|
|
|
#include "RISCVToolchain.h"
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
#include "CommonArgs.h"
|
|
|
|
#include "InputInfo.h"
|
|
|
|
#include "clang/Driver/Compilation.h"
|
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
2018-09-07 21:03:31 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::toolchains;
|
|
|
|
using namespace clang::driver::tools;
|
|
|
|
using namespace clang;
|
|
|
|
using namespace llvm::opt;
|
|
|
|
|
|
|
|
/// RISCV Toolchain
|
|
|
|
RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
|
|
|
|
const ArgList &Args)
|
|
|
|
: Generic_ELF(D, Triple, Args) {
|
|
|
|
GCCInstallation.init(Triple, Args);
|
2018-09-07 21:03:31 +08:00
|
|
|
getFilePaths().push_back(computeSysRoot() + "/lib");
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
if (GCCInstallation.isValid()) {
|
|
|
|
getFilePaths().push_back(GCCInstallation.getInstallPath().str());
|
|
|
|
getProgramPaths().push_back(
|
|
|
|
(GCCInstallation.getParentLibPath() + "/../bin").str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *RISCVToolChain::buildLinker() const {
|
|
|
|
return new tools::RISCV::Linker(*this);
|
|
|
|
}
|
|
|
|
|
2018-09-07 21:03:31 +08:00
|
|
|
void RISCVToolChain::addClangTargetOptions(
|
|
|
|
const llvm::opt::ArgList &DriverArgs,
|
|
|
|
llvm::opt::ArgStringList &CC1Args,
|
|
|
|
Action::OffloadKind) const {
|
|
|
|
CC1Args.push_back("-nostdsysteminc");
|
|
|
|
CC1Args.push_back("-fuse-init-array");
|
|
|
|
}
|
|
|
|
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
void RISCVToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdinc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
|
2018-09-07 21:03:31 +08:00
|
|
|
SmallString<128> Dir(computeSysRoot());
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
llvm::sys::path::append(Dir, "include");
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, Dir.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RISCVToolChain::addLibStdCxxIncludePaths(
|
|
|
|
const llvm::opt::ArgList &DriverArgs,
|
|
|
|
llvm::opt::ArgStringList &CC1Args) const {
|
|
|
|
const GCCVersion &Version = GCCInstallation.getVersion();
|
|
|
|
StringRef TripleStr = GCCInstallation.getTriple().str();
|
|
|
|
const Multilib &Multilib = GCCInstallation.getMultilib();
|
2018-09-07 21:03:31 +08:00
|
|
|
addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
"", TripleStr, "", "", Multilib.includeSuffix(), DriverArgs, CC1Args);
|
|
|
|
}
|
|
|
|
|
2018-09-07 21:03:31 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
[RISCV] Add driver for riscv32-unknown-elf baremetal target
Summary:
This patch adds a driver for the baremetal RISC-V target (i.e. riscv32-unknown-elf). For reference, D39963 added basic target info and added support for riscv32-linux-unknown-elf.
Patch by: asb (Alex Bradbury)
Reviewers: efriedma, phosek, apazos, espindola, mgrang
Reviewed By: mgrang
Subscribers: jrtc27, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, emaste, mgorny, arichardson, rbar, johnrusso, simoncook, jordy.potman.lists, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46822
llvm-svn: 338385
2018-07-31 22:21:46 +08:00
|
|
|
void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
const ToolChain &ToolChain = getToolChain();
|
|
|
|
const Driver &D = ToolChain.getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if (!D.SysRoot.empty())
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
|
|
|
|
|
|
|
std::string Linker = getToolChain().GetProgramPath(getShortName());
|
|
|
|
|
|
|
|
bool WantCRTs =
|
|
|
|
!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
|
|
|
|
|
|
|
|
if (WantCRTs) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
|
|
|
|
Args.AddAllArgs(CmdArgs,
|
|
|
|
{options::OPT_T_Group, options::OPT_e, options::OPT_s,
|
|
|
|
options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
|
|
|
|
|
|
|
|
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
|
|
|
|
|
|
|
|
// TODO: add C++ includes and libs if compiling C++.
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (ToolChain.ShouldLinkCXXStdlib(Args))
|
|
|
|
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
|
|
|
|
CmdArgs.push_back("--start-group");
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
CmdArgs.push_back("-lgloss");
|
|
|
|
CmdArgs.push_back("--end-group");
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WantCRTs)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
C.addCommand(llvm::make_unique<Command>(JA, *this, Args.MakeArgString(Linker),
|
|
|
|
CmdArgs, Inputs));
|
|
|
|
}
|
|
|
|
// RISCV tools end.
|