2011-01-01 01:31:54 +08:00
|
|
|
//===--- ToolChain.cpp - Collections of tools for one platform ------------===//
|
2009-03-16 13:25:36 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-03-19 04:48:54 +08:00
|
|
|
#include "Tools.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/ObjCRuntime.h"
|
2009-03-16 13:25:36 +08:00
|
|
|
#include "clang/Driver/Action.h"
|
|
|
|
#include "clang/Driver/Driver.h"
|
2010-08-24 06:35:37 +08:00
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
|
|
|
#include "clang/Driver/Options.h"
|
2013-11-02 02:16:25 +08:00
|
|
|
#include "clang/Driver/SanitizerArgs.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "clang/Driver/ToolChain.h"
|
2014-06-26 22:23:45 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-03-22 01:19:12 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2011-07-06 08:26:06 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2013-04-20 16:15:03 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2015-09-26 01:44:31 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2015-10-28 18:10:03 +08:00
|
|
|
#include "llvm/Support/TargetParser.h"
|
2015-10-02 00:54:58 +08:00
|
|
|
|
2009-03-16 13:25:36 +08:00
|
|
|
using namespace clang::driver;
|
2015-10-02 00:54:58 +08:00
|
|
|
using namespace clang::driver::tools;
|
2011-07-23 18:55:15 +08:00
|
|
|
using namespace clang;
|
2015-10-28 18:10:03 +08:00
|
|
|
using namespace llvm;
|
2013-06-15 01:17:23 +08:00
|
|
|
using namespace llvm::opt;
|
2009-03-16 13:25:36 +08:00
|
|
|
|
Improve our handling of rtti/sanitize=vptr/sanitize=undefined
This patch removes the huge blob of code that is dealing with
rtti/exceptions/sanitizers and replaces it with:
A ToolChain function which, for a given set of Args, figures out if rtti
should be:
- enabled
- disabled implicitly
- disabled explicitly
A change in the way SanitizerArgs figures out what sanitizers to enable
(or if it should error out, or warn);
And a check for exceptions/rtti interaction inside addExceptionArgs.
The RTTIMode algorithm is:
- If -mkernel, -fapple-kext, or -fno-rtti are passed, rtti was disabled explicitly;
- If -frtti was passed or we're not targetting the PS4, rtti is enabled;
- If -fexceptions or -fcxx-exceptions was passed and we're targetting
the PS4, rtti was enabled implicitly;
- If we're targetting the PS4, rtti is disabled implicitly;
- Otherwise, rtti is enabled;
Since the only flag needed to pass to -cc1 is -fno-rtti if we want to
disable it, there's no problem in saying rtti is enabled if we're
compiling C code, so we don't look at the input file type.
addExceptionArgs now looks at the RTTIMode and warns that rtti is being
enabled implicitly if targetting the PS4 and exceptions are on. It also
errors out if, targetting the PS4, -fno-rtti was passed, and exceptions
were turned on.
SanitizerArgs now errors out if rtti was disabled explicitly and the vptr
sanitizer was enabled implicitly, but just turns off vptr if rtti is
disabled but -fsanitize=undefined was passed.
Also fixed tests, removed duplicate name from addExceptionArgs comment,
and added one or two surrounding lines when running clang-format.
This changes test/Driver/fsanitize.c to make it not expect a warning when
passed -fsanitize=undefined -fno-rtti, but expect vptr to not be on.
Removed all users and definition of SanitizerArgs::sanitizesVptr().
Reviewers: samsonov
Subscribers: llvm-commits, samsonov, rsmith
Differential Revision: http://reviews.llvm.org/D7525
llvm-svn: 229801
2015-02-19 09:04:49 +08:00
|
|
|
static llvm::opt::Arg *GetRTTIArgument(const ArgList &Args) {
|
|
|
|
return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
|
|
|
|
options::OPT_fno_rtti, options::OPT_frtti);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple,
|
|
|
|
const Arg *CachedRTTIArg) {
|
|
|
|
// Explicit rtti/no-rtti args
|
|
|
|
if (CachedRTTIArg) {
|
|
|
|
if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
|
|
|
|
return ToolChain::RM_EnabledExplicitly;
|
|
|
|
else
|
|
|
|
return ToolChain::RM_DisabledExplicitly;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -frtti is default, except for the PS4 CPU.
|
|
|
|
if (!Triple.isPS4CPU())
|
|
|
|
return ToolChain::RM_EnabledImplicitly;
|
|
|
|
|
|
|
|
// On the PS4, turning on c++ exceptions turns on rtti.
|
|
|
|
// We're assuming that, if we see -fexceptions, rtti gets turned on.
|
2015-03-21 07:33:23 +08:00
|
|
|
Arg *Exceptions = Args.getLastArgNoClaim(
|
Improve our handling of rtti/sanitize=vptr/sanitize=undefined
This patch removes the huge blob of code that is dealing with
rtti/exceptions/sanitizers and replaces it with:
A ToolChain function which, for a given set of Args, figures out if rtti
should be:
- enabled
- disabled implicitly
- disabled explicitly
A change in the way SanitizerArgs figures out what sanitizers to enable
(or if it should error out, or warn);
And a check for exceptions/rtti interaction inside addExceptionArgs.
The RTTIMode algorithm is:
- If -mkernel, -fapple-kext, or -fno-rtti are passed, rtti was disabled explicitly;
- If -frtti was passed or we're not targetting the PS4, rtti is enabled;
- If -fexceptions or -fcxx-exceptions was passed and we're targetting
the PS4, rtti was enabled implicitly;
- If we're targetting the PS4, rtti is disabled implicitly;
- Otherwise, rtti is enabled;
Since the only flag needed to pass to -cc1 is -fno-rtti if we want to
disable it, there's no problem in saying rtti is enabled if we're
compiling C code, so we don't look at the input file type.
addExceptionArgs now looks at the RTTIMode and warns that rtti is being
enabled implicitly if targetting the PS4 and exceptions are on. It also
errors out if, targetting the PS4, -fno-rtti was passed, and exceptions
were turned on.
SanitizerArgs now errors out if rtti was disabled explicitly and the vptr
sanitizer was enabled implicitly, but just turns off vptr if rtti is
disabled but -fsanitize=undefined was passed.
Also fixed tests, removed duplicate name from addExceptionArgs comment,
and added one or two surrounding lines when running clang-format.
This changes test/Driver/fsanitize.c to make it not expect a warning when
passed -fsanitize=undefined -fno-rtti, but expect vptr to not be on.
Removed all users and definition of SanitizerArgs::sanitizesVptr().
Reviewers: samsonov
Subscribers: llvm-commits, samsonov, rsmith
Differential Revision: http://reviews.llvm.org/D7525
llvm-svn: 229801
2015-02-19 09:04:49 +08:00
|
|
|
options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
|
|
|
|
options::OPT_fexceptions, options::OPT_fno_exceptions);
|
|
|
|
if (Exceptions &&
|
|
|
|
(Exceptions->getOption().matches(options::OPT_fexceptions) ||
|
|
|
|
Exceptions->getOption().matches(options::OPT_fcxx_exceptions)))
|
|
|
|
return ToolChain::RM_EnabledImplicitly;
|
|
|
|
|
|
|
|
return ToolChain::RM_DisabledImplicitly;
|
|
|
|
}
|
|
|
|
|
2013-03-19 02:10:27 +08:00
|
|
|
ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
|
2014-10-04 05:57:44 +08:00
|
|
|
const ArgList &Args)
|
Improve our handling of rtti/sanitize=vptr/sanitize=undefined
This patch removes the huge blob of code that is dealing with
rtti/exceptions/sanitizers and replaces it with:
A ToolChain function which, for a given set of Args, figures out if rtti
should be:
- enabled
- disabled implicitly
- disabled explicitly
A change in the way SanitizerArgs figures out what sanitizers to enable
(or if it should error out, or warn);
And a check for exceptions/rtti interaction inside addExceptionArgs.
The RTTIMode algorithm is:
- If -mkernel, -fapple-kext, or -fno-rtti are passed, rtti was disabled explicitly;
- If -frtti was passed or we're not targetting the PS4, rtti is enabled;
- If -fexceptions or -fcxx-exceptions was passed and we're targetting
the PS4, rtti was enabled implicitly;
- If we're targetting the PS4, rtti is disabled implicitly;
- Otherwise, rtti is enabled;
Since the only flag needed to pass to -cc1 is -fno-rtti if we want to
disable it, there's no problem in saying rtti is enabled if we're
compiling C code, so we don't look at the input file type.
addExceptionArgs now looks at the RTTIMode and warns that rtti is being
enabled implicitly if targetting the PS4 and exceptions are on. It also
errors out if, targetting the PS4, -fno-rtti was passed, and exceptions
were turned on.
SanitizerArgs now errors out if rtti was disabled explicitly and the vptr
sanitizer was enabled implicitly, but just turns off vptr if rtti is
disabled but -fsanitize=undefined was passed.
Also fixed tests, removed duplicate name from addExceptionArgs comment,
and added one or two surrounding lines when running clang-format.
This changes test/Driver/fsanitize.c to make it not expect a warning when
passed -fsanitize=undefined -fno-rtti, but expect vptr to not be on.
Removed all users and definition of SanitizerArgs::sanitizesVptr().
Reviewers: samsonov
Subscribers: llvm-commits, samsonov, rsmith
Differential Revision: http://reviews.llvm.org/D7525
llvm-svn: 229801
2015-02-19 09:04:49 +08:00
|
|
|
: D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
|
|
|
|
CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
|
2014-10-04 05:57:44 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mthread_model))
|
|
|
|
if (!isThreadModelSupported(A->getValue()))
|
|
|
|
D.Diag(diag::err_drv_invalid_thread_model_for_target)
|
Improve our handling of rtti/sanitize=vptr/sanitize=undefined
This patch removes the huge blob of code that is dealing with
rtti/exceptions/sanitizers and replaces it with:
A ToolChain function which, for a given set of Args, figures out if rtti
should be:
- enabled
- disabled implicitly
- disabled explicitly
A change in the way SanitizerArgs figures out what sanitizers to enable
(or if it should error out, or warn);
And a check for exceptions/rtti interaction inside addExceptionArgs.
The RTTIMode algorithm is:
- If -mkernel, -fapple-kext, or -fno-rtti are passed, rtti was disabled explicitly;
- If -frtti was passed or we're not targetting the PS4, rtti is enabled;
- If -fexceptions or -fcxx-exceptions was passed and we're targetting
the PS4, rtti was enabled implicitly;
- If we're targetting the PS4, rtti is disabled implicitly;
- Otherwise, rtti is enabled;
Since the only flag needed to pass to -cc1 is -fno-rtti if we want to
disable it, there's no problem in saying rtti is enabled if we're
compiling C code, so we don't look at the input file type.
addExceptionArgs now looks at the RTTIMode and warns that rtti is being
enabled implicitly if targetting the PS4 and exceptions are on. It also
errors out if, targetting the PS4, -fno-rtti was passed, and exceptions
were turned on.
SanitizerArgs now errors out if rtti was disabled explicitly and the vptr
sanitizer was enabled implicitly, but just turns off vptr if rtti is
disabled but -fsanitize=undefined was passed.
Also fixed tests, removed duplicate name from addExceptionArgs comment,
and added one or two surrounding lines when running clang-format.
This changes test/Driver/fsanitize.c to make it not expect a warning when
passed -fsanitize=undefined -fno-rtti, but expect vptr to not be on.
Removed all users and definition of SanitizerArgs::sanitizesVptr().
Reviewers: samsonov
Subscribers: llvm-commits, samsonov, rsmith
Differential Revision: http://reviews.llvm.org/D7525
llvm-svn: 229801
2015-02-19 09:04:49 +08:00
|
|
|
<< A->getValue() << A->getAsString(Args);
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
ToolChain::~ToolChain() {
|
|
|
|
}
|
2009-03-16 13:25:36 +08:00
|
|
|
|
2015-10-07 23:48:01 +08:00
|
|
|
vfs::FileSystem &ToolChain::getVFS() const { return getDriver().getVFS(); }
|
2009-12-22 02:54:17 +08:00
|
|
|
|
2013-03-19 02:10:27 +08:00
|
|
|
bool ToolChain::useIntegratedAs() const {
|
2014-02-23 08:40:30 +08:00
|
|
|
return Args.hasFlag(options::OPT_fintegrated_as,
|
|
|
|
options::OPT_fno_integrated_as,
|
2013-03-19 01:52:57 +08:00
|
|
|
IsIntegratedAssemblerDefault());
|
|
|
|
}
|
|
|
|
|
2013-08-19 17:14:21 +08:00
|
|
|
const SanitizerArgs& ToolChain::getSanitizerArgs() const {
|
2013-11-02 02:16:25 +08:00
|
|
|
if (!SanitizerArguments.get())
|
|
|
|
SanitizerArguments.reset(new SanitizerArgs(*this, Args));
|
|
|
|
return *SanitizerArguments.get();
|
2013-08-19 17:14:21 +08:00
|
|
|
}
|
|
|
|
|
2015-09-26 01:44:31 +08:00
|
|
|
namespace {
|
|
|
|
struct DriverSuffix {
|
|
|
|
const char *Suffix;
|
|
|
|
const char *ModeFlag;
|
|
|
|
};
|
|
|
|
|
|
|
|
const DriverSuffix *FindDriverSuffix(StringRef ProgName) {
|
|
|
|
// A list of known driver suffixes. Suffixes are compared against the
|
|
|
|
// program name in order. If there is a match, the frontend type is updated as
|
|
|
|
// necessary by applying the ModeFlag.
|
|
|
|
static const DriverSuffix DriverSuffixes[] = {
|
|
|
|
{"clang", nullptr},
|
|
|
|
{"clang++", "--driver-mode=g++"},
|
|
|
|
{"clang-c++", "--driver-mode=g++"},
|
|
|
|
{"clang-cc", nullptr},
|
|
|
|
{"clang-cpp", "--driver-mode=cpp"},
|
|
|
|
{"clang-g++", "--driver-mode=g++"},
|
|
|
|
{"clang-gcc", nullptr},
|
|
|
|
{"clang-cl", "--driver-mode=cl"},
|
|
|
|
{"cc", nullptr},
|
|
|
|
{"cpp", "--driver-mode=cpp"},
|
|
|
|
{"cl", "--driver-mode=cl"},
|
|
|
|
{"++", "--driver-mode=g++"},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < llvm::array_lengthof(DriverSuffixes); ++i)
|
|
|
|
if (ProgName.endswith(DriverSuffixes[i].Suffix))
|
|
|
|
return &DriverSuffixes[i];
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Normalize the program name from argv[0] by stripping the file extension if
|
|
|
|
/// present and lower-casing the string on Windows.
|
|
|
|
std::string normalizeProgramName(llvm::StringRef Argv0) {
|
|
|
|
std::string ProgName = llvm::sys::path::stem(Argv0);
|
|
|
|
#ifdef LLVM_ON_WIN32
|
|
|
|
// Transform to lowercase for case insensitive file systems.
|
|
|
|
std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(), ::tolower);
|
|
|
|
#endif
|
|
|
|
return ProgName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DriverSuffix *parseDriverSuffix(StringRef ProgName) {
|
|
|
|
// Try to infer frontend type and default target from the program name by
|
|
|
|
// comparing it against DriverSuffixes in order.
|
|
|
|
|
|
|
|
// If there is a match, the function tries to identify a target as prefix.
|
|
|
|
// E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
|
|
|
|
// prefix "x86_64-linux". If such a target prefix is found, it may be
|
|
|
|
// added via -target as implicit first argument.
|
|
|
|
const DriverSuffix *DS = FindDriverSuffix(ProgName);
|
|
|
|
|
|
|
|
if (!DS) {
|
|
|
|
// Try again after stripping any trailing version number:
|
|
|
|
// clang++3.5 -> clang++
|
|
|
|
ProgName = ProgName.rtrim("0123456789.");
|
|
|
|
DS = FindDriverSuffix(ProgName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DS) {
|
|
|
|
// Try again after stripping trailing -component.
|
|
|
|
// clang++-tot -> clang++
|
|
|
|
ProgName = ProgName.slice(0, ProgName.rfind('-'));
|
|
|
|
DS = FindDriverSuffix(ProgName);
|
|
|
|
}
|
|
|
|
return DS;
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
std::pair<std::string, std::string>
|
|
|
|
ToolChain::getTargetAndModeFromProgramName(StringRef PN) {
|
|
|
|
std::string ProgName = normalizeProgramName(PN);
|
|
|
|
const DriverSuffix *DS = parseDriverSuffix(ProgName);
|
|
|
|
if (!DS)
|
|
|
|
return std::make_pair("", "");
|
|
|
|
std::string ModeFlag = DS->ModeFlag == nullptr ? "" : DS->ModeFlag;
|
|
|
|
|
|
|
|
std::string::size_type LastComponent =
|
|
|
|
ProgName.rfind('-', ProgName.size() - strlen(DS->Suffix));
|
|
|
|
if (LastComponent == std::string::npos)
|
|
|
|
return std::make_pair("", ModeFlag);
|
|
|
|
|
|
|
|
// Infer target from the prefix.
|
|
|
|
StringRef Prefix(ProgName);
|
|
|
|
Prefix = Prefix.slice(0, LastComponent);
|
|
|
|
std::string IgnoredError;
|
|
|
|
std::string Target;
|
|
|
|
if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
|
|
|
|
Target = Prefix;
|
|
|
|
}
|
|
|
|
return std::make_pair(Target, ModeFlag);
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:22:51 +08:00
|
|
|
StringRef ToolChain::getDefaultUniversalArchName() const {
|
2012-11-08 11:38:26 +08:00
|
|
|
// In universal driver terms, the arch name accepted by -arch isn't exactly
|
|
|
|
// the same as the ones that appear in the triple. Roughly speaking, this is
|
|
|
|
// an inverse of the darwin::getArchTypeForDarwinArchName() function, but the
|
|
|
|
// only interesting special case is powerpc.
|
|
|
|
switch (Triple.getArch()) {
|
|
|
|
case llvm::Triple::ppc:
|
|
|
|
return "ppc";
|
|
|
|
case llvm::Triple::ppc64:
|
|
|
|
return "ppc64";
|
2013-07-26 09:36:11 +08:00
|
|
|
case llvm::Triple::ppc64le:
|
|
|
|
return "ppc64le";
|
2012-11-08 11:38:26 +08:00
|
|
|
default:
|
|
|
|
return Triple.getArchName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-23 11:05:41 +08:00
|
|
|
bool ToolChain::IsUnwindTablesDefault() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-20 11:05:54 +08:00
|
|
|
Tool *ToolChain::getClang() const {
|
|
|
|
if (!Clang)
|
|
|
|
Clang.reset(new tools::Clang(*this));
|
|
|
|
return Clang.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::buildAssembler() const {
|
|
|
|
return new tools::ClangAs(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::buildLinker() const {
|
|
|
|
llvm_unreachable("Linking is not supported by this toolchain");
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::getAssemble() const {
|
|
|
|
if (!Assemble)
|
|
|
|
Assemble.reset(buildAssembler());
|
|
|
|
return Assemble.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::getClangAs() const {
|
|
|
|
if (!Assemble)
|
|
|
|
Assemble.reset(new tools::ClangAs(*this));
|
|
|
|
return Assemble.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::getLink() const {
|
|
|
|
if (!Link)
|
|
|
|
Link.reset(buildLinker());
|
|
|
|
return Link.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *ToolChain::getTool(Action::ActionClass AC) const {
|
2013-03-19 08:36:57 +08:00
|
|
|
switch (AC) {
|
|
|
|
case Action::AssembleJobClass:
|
2013-03-20 11:05:54 +08:00
|
|
|
return getAssemble();
|
|
|
|
|
2013-03-19 08:36:57 +08:00
|
|
|
case Action::LinkJobClass:
|
2013-03-20 11:05:54 +08:00
|
|
|
return getLink();
|
|
|
|
|
|
|
|
case Action::InputClass:
|
|
|
|
case Action::BindArchClass:
|
2015-07-14 07:27:56 +08:00
|
|
|
case Action::CudaDeviceClass:
|
|
|
|
case Action::CudaHostClass:
|
2013-03-19 08:36:57 +08:00
|
|
|
case Action::LipoJobClass:
|
|
|
|
case Action::DsymutilJobClass:
|
2014-02-07 02:53:25 +08:00
|
|
|
case Action::VerifyDebugInfoJobClass:
|
2013-03-19 08:36:57 +08:00
|
|
|
llvm_unreachable("Invalid tool kind.");
|
|
|
|
|
|
|
|
case Action::CompileJobClass:
|
|
|
|
case Action::PrecompileJobClass:
|
|
|
|
case Action::PreprocessJobClass:
|
|
|
|
case Action::AnalyzeJobClass:
|
|
|
|
case Action::MigrateJobClass:
|
2014-02-07 02:53:25 +08:00
|
|
|
case Action::VerifyPCHJobClass:
|
Reapply "Change -save-temps to emit unoptimized bitcode files."
This reapplies r224503 along with a fix for compiling Fortran by having the
clang driver invoke gcc (see r224546, where it was reverted). I have added
a testcase for that as well.
Original commit message:
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
llvm-svn: 224688
2014-12-21 15:00:00 +08:00
|
|
|
case Action::BackendJobClass:
|
2013-03-20 11:05:54 +08:00
|
|
|
return getClang();
|
2013-03-19 08:36:57 +08:00
|
|
|
}
|
2013-03-22 03:45:46 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid tool kind.");
|
2013-03-19 08:36:57 +08:00
|
|
|
}
|
|
|
|
|
2015-10-02 00:54:58 +08:00
|
|
|
static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
|
|
|
|
const ArgList &Args) {
|
|
|
|
const llvm::Triple &Triple = TC.getTriple();
|
|
|
|
bool IsWindows = Triple.isOSWindows();
|
|
|
|
|
|
|
|
if (Triple.isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86)
|
|
|
|
return "i386";
|
|
|
|
|
|
|
|
if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
|
|
|
|
return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
|
|
|
|
? "armhf"
|
|
|
|
: "arm";
|
|
|
|
|
|
|
|
return TC.getArchName();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
|
|
|
|
bool Shared) const {
|
|
|
|
const llvm::Triple &TT = getTriple();
|
2015-10-09 05:21:44 +08:00
|
|
|
const char *Env = TT.isAndroid() ? "-android" : "";
|
2015-10-02 00:54:58 +08:00
|
|
|
bool IsITANMSVCWindows =
|
|
|
|
TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
|
|
|
|
|
|
|
|
StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
|
|
|
|
const char *Prefix = IsITANMSVCWindows ? "" : "lib";
|
|
|
|
const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so")
|
|
|
|
: (IsITANMSVCWindows ? ".lib" : ".a");
|
|
|
|
|
|
|
|
SmallString<128> Path(getDriver().ResourceDir);
|
|
|
|
StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
|
|
|
|
llvm::sys::path::append(Path, "lib", OSLibName);
|
|
|
|
llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
|
|
|
|
Arch + Env + Suffix);
|
|
|
|
return Path.str();
|
|
|
|
}
|
|
|
|
|
2015-10-22 14:15:31 +08:00
|
|
|
const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
|
|
|
|
StringRef Component,
|
|
|
|
bool Shared) const {
|
|
|
|
return Args.MakeArgString(getCompilerRT(Args, Component, Shared));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToolChain::needsProfileRT(const ArgList &Args) {
|
|
|
|
if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
|
|
|
|
false) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_generate) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_generate_EQ) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_instr_generate) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
|
|
|
|
Args.hasArg(options::OPT_fcreate_profile) ||
|
|
|
|
Args.hasArg(options::OPT_coverage))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-24 23:06:53 +08:00
|
|
|
Tool *ToolChain::SelectTool(const JobAction &JA) const {
|
2015-10-22 14:15:31 +08:00
|
|
|
if (getDriver().ShouldUseClangCompiler(JA)) return getClang();
|
2013-03-20 11:05:54 +08:00
|
|
|
Action::ActionClass AC = JA.getKind();
|
|
|
|
if (AC == Action::AssembleJobClass && useIntegratedAs())
|
2013-03-24 23:06:53 +08:00
|
|
|
return getClangAs();
|
|
|
|
return getTool(AC);
|
2013-03-19 04:48:54 +08:00
|
|
|
}
|
|
|
|
|
2010-07-15 02:46:23 +08:00
|
|
|
std::string ToolChain::GetFilePath(const char *Name) const {
|
2012-01-25 17:12:06 +08:00
|
|
|
return D.GetFilePath(Name, *this);
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-04 03:52:37 +08:00
|
|
|
std::string ToolChain::GetProgramPath(const char *Name) const {
|
|
|
|
return D.GetProgramPath(Name, *this);
|
2009-03-16 13:25:36 +08:00
|
|
|
}
|
2010-08-02 13:43:56 +08:00
|
|
|
|
2014-06-26 22:23:45 +08:00
|
|
|
std::string ToolChain::GetLinkerPath() const {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
|
|
|
|
StringRef Suffix = A->getValue();
|
|
|
|
|
|
|
|
// If we're passed -fuse-ld= with no argument, or with the argument ld,
|
|
|
|
// then use whatever the default system linker is.
|
|
|
|
if (Suffix.empty() || Suffix == "ld")
|
|
|
|
return GetProgramPath("ld");
|
|
|
|
|
|
|
|
llvm::SmallString<8> LinkerName("ld.");
|
|
|
|
LinkerName.append(Suffix);
|
|
|
|
|
|
|
|
std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
|
|
|
|
if (llvm::sys::fs::exists(LinkerPath))
|
|
|
|
return LinkerPath;
|
|
|
|
|
|
|
|
getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-11-21 04:49:39 +08:00
|
|
|
return GetProgramPath(DefaultLinker);
|
2014-06-26 22:23:45 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 13:43:56 +08:00
|
|
|
types::ID ToolChain::LookupTypeForExtension(const char *Ext) const {
|
|
|
|
return types::lookupTypeForExtension(Ext);
|
|
|
|
}
|
2010-08-24 06:35:37 +08:00
|
|
|
|
2010-09-17 08:24:52 +08:00
|
|
|
bool ToolChain::HasNativeLLVMSupport() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-17 19:11:25 +08:00
|
|
|
bool ToolChain::isCrossCompiling() const {
|
|
|
|
llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
|
|
|
|
switch (HostTriple.getArch()) {
|
2013-12-18 01:25:19 +08:00
|
|
|
// The A32/T32/T16 instruction sets are not separate architectures in this
|
|
|
|
// context.
|
|
|
|
case llvm::Triple::arm:
|
2014-03-28 22:40:46 +08:00
|
|
|
case llvm::Triple::armeb:
|
2013-12-18 01:25:19 +08:00
|
|
|
case llvm::Triple::thumb:
|
2014-03-28 22:40:46 +08:00
|
|
|
case llvm::Triple::thumbeb:
|
|
|
|
return getArch() != llvm::Triple::arm && getArch() != llvm::Triple::thumb &&
|
|
|
|
getArch() != llvm::Triple::armeb && getArch() != llvm::Triple::thumbeb;
|
2013-12-18 01:25:19 +08:00
|
|
|
default:
|
|
|
|
return HostTriple.getArch() != getArch();
|
2013-12-17 19:11:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
ObjCRuntime ToolChain::getDefaultObjCRuntime(bool isNonFragile) const {
|
2012-07-04 04:49:52 +08:00
|
|
|
return ObjCRuntime(isNonFragile ? ObjCRuntime::GNUstep : ObjCRuntime::GCC,
|
2012-06-20 14:18:46 +08:00
|
|
|
VersionTuple());
|
2011-07-06 08:26:06 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 05:57:44 +08:00
|
|
|
bool ToolChain::isThreadModelSupported(const StringRef Model) const {
|
|
|
|
if (Model == "single") {
|
2015-09-04 06:51:53 +08:00
|
|
|
// FIXME: 'single' is only supported on ARM and WebAssembly so far.
|
2014-10-04 05:57:44 +08:00
|
|
|
return Triple.getArch() == llvm::Triple::arm ||
|
|
|
|
Triple.getArch() == llvm::Triple::armeb ||
|
|
|
|
Triple.getArch() == llvm::Triple::thumb ||
|
2015-09-04 06:51:53 +08:00
|
|
|
Triple.getArch() == llvm::Triple::thumbeb ||
|
|
|
|
Triple.getArch() == llvm::Triple::wasm32 ||
|
|
|
|
Triple.getArch() == llvm::Triple::wasm64;
|
2014-10-04 05:57:44 +08:00
|
|
|
} else if (Model == "posix")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-16 08:53:35 +08:00
|
|
|
std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
|
2011-09-21 04:44:06 +08:00
|
|
|
types::ID InputType) const {
|
2010-08-24 06:35:37 +08:00
|
|
|
switch (getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
return getTripleString();
|
|
|
|
|
2013-11-16 08:53:35 +08:00
|
|
|
case llvm::Triple::x86_64: {
|
|
|
|
llvm::Triple Triple = getTriple();
|
2014-01-16 16:48:16 +08:00
|
|
|
if (!Triple.isOSBinFormatMachO())
|
2013-11-16 08:53:35 +08:00
|
|
|
return getTripleString();
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
|
|
|
// x86_64h goes in the triple. Other -march options just use the
|
|
|
|
// vanilla triple we already have.
|
|
|
|
StringRef MArch = A->getValue();
|
|
|
|
if (MArch == "x86_64h")
|
|
|
|
Triple.setArchName(MArch);
|
|
|
|
}
|
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
2014-07-24 18:25:34 +08:00
|
|
|
case llvm::Triple::aarch64: {
|
|
|
|
llvm::Triple Triple = getTriple();
|
|
|
|
if (!Triple.isOSBinFormatMachO())
|
|
|
|
return getTripleString();
|
|
|
|
|
|
|
|
// FIXME: older versions of ld64 expect the "arm64" component in the actual
|
|
|
|
// triple string and query it to determine whether an LTO file can be
|
|
|
|
// handled. Remove this when we don't care any more.
|
|
|
|
Triple.setArchName("arm64");
|
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
2010-08-24 06:35:37 +08:00
|
|
|
case llvm::Triple::arm:
|
2014-03-28 22:40:46 +08:00
|
|
|
case llvm::Triple::armeb:
|
|
|
|
case llvm::Triple::thumb:
|
|
|
|
case llvm::Triple::thumbeb: {
|
2010-08-24 06:35:37 +08:00
|
|
|
// FIXME: Factor into subclasses.
|
|
|
|
llvm::Triple Triple = getTriple();
|
2014-03-28 22:40:46 +08:00
|
|
|
bool IsBigEndian = getTriple().getArch() == llvm::Triple::armeb ||
|
|
|
|
getTriple().getArch() == llvm::Triple::thumbeb;
|
2010-08-24 06:35:37 +08:00
|
|
|
|
2014-04-10 21:59:32 +08:00
|
|
|
// Handle pseudo-target flags '-mlittle-endian'/'-EL' and
|
|
|
|
// '-mbig-endian'/'-EB'.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
|
|
|
|
options::OPT_mbig_endian)) {
|
2015-03-09 10:02:07 +08:00
|
|
|
IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
|
2014-04-10 21:59:32 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 06:35:37 +08:00
|
|
|
// Thumb2 is the default for V7 on Darwin.
|
|
|
|
//
|
|
|
|
// FIXME: Thumb should just be another -target-feaure, not in the triple.
|
2015-07-28 07:44:42 +08:00
|
|
|
StringRef MCPU, MArch;
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
|
|
|
|
MCPU = A->getValue();
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
|
|
|
|
MArch = A->getValue();
|
2015-08-30 15:51:18 +08:00
|
|
|
std::string CPU =
|
|
|
|
Triple.isOSBinFormatMachO()
|
|
|
|
? tools::arm::getARMCPUForMArch(MArch, Triple).str()
|
|
|
|
: tools::arm::getARMTargetCPU(MCPU, MArch, Triple);
|
2015-08-07 06:36:24 +08:00
|
|
|
StringRef Suffix =
|
2015-09-23 17:29:32 +08:00
|
|
|
tools::arm::getLLVMArchSuffixForARM(CPU, MArch, Triple);
|
2015-10-28 18:10:03 +08:00
|
|
|
bool IsMProfile = ARM::parseArchProfile(Suffix) == ARM::PK_M;
|
|
|
|
bool ThumbDefault = IsMProfile || (ARM::parseArchVersion(Suffix) == 7 &&
|
|
|
|
getTriple().isOSBinFormatMachO());
|
2014-04-05 04:31:19 +08:00
|
|
|
// FIXME: this is invalid for WindowsCE
|
|
|
|
if (getTriple().isOSWindows())
|
|
|
|
ThumbDefault = true;
|
2014-03-28 22:40:46 +08:00
|
|
|
std::string ArchName;
|
|
|
|
if (IsBigEndian)
|
|
|
|
ArchName = "armeb";
|
|
|
|
else
|
|
|
|
ArchName = "arm";
|
2011-09-21 04:44:06 +08:00
|
|
|
|
2015-10-28 18:10:03 +08:00
|
|
|
// Assembly files should start in ARM mode, unless arch is M-profile.
|
2015-11-06 01:11:55 +08:00
|
|
|
if ((InputType != types::TY_PP_Asm && Args.hasFlag(options::OPT_mthumb,
|
|
|
|
options::OPT_mno_thumb, ThumbDefault)) || IsMProfile) {
|
2014-03-28 22:40:46 +08:00
|
|
|
if (IsBigEndian)
|
|
|
|
ArchName = "thumbeb";
|
|
|
|
else
|
|
|
|
ArchName = "thumb";
|
|
|
|
}
|
2010-08-24 06:35:37 +08:00
|
|
|
Triple.setArchName(ArchName + Suffix.str());
|
|
|
|
|
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 06:36:24 +08:00
|
|
|
std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
|
2011-09-21 04:44:06 +08:00
|
|
|
types::ID InputType) const {
|
|
|
|
return ComputeLLVMTriple(Args, InputType);
|
2010-08-24 06:35:37 +08:00
|
|
|
}
|
|
|
|
|
2011-11-04 15:12:53 +08:00
|
|
|
void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
|
|
|
// Each toolchain should provide the appropriate include flags.
|
|
|
|
}
|
|
|
|
|
2012-11-22 07:40:23 +08:00
|
|
|
void ToolChain::addClangTargetOptions(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
2012-06-19 09:26:10 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 21:16:12 +08:00
|
|
|
void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {}
|
|
|
|
|
2015-10-22 14:15:31 +08:00
|
|
|
void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args,
|
|
|
|
llvm::opt::ArgStringList &CmdArgs) const {
|
|
|
|
if (!needsProfileRT(Args)) return;
|
|
|
|
|
|
|
|
CmdArgs.push_back(getCompilerRTArgString(Args, "profile"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-08 07:03:15 +08:00
|
|
|
ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
|
2015-10-22 14:15:31 +08:00
|
|
|
const ArgList &Args) const {
|
2011-12-08 07:03:15 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef Value = A->getValue();
|
2011-12-08 07:03:15 +08:00
|
|
|
if (Value == "compiler-rt")
|
|
|
|
return ToolChain::RLT_CompilerRT;
|
|
|
|
if (Value == "libgcc")
|
|
|
|
return ToolChain::RLT_Libgcc;
|
|
|
|
getDriver().Diag(diag::err_drv_invalid_rtlib_name)
|
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetDefaultRuntimeLibType();
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
|
2010-09-15 07:12:40 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef Value = A->getValue();
|
2010-09-15 07:12:40 +08:00
|
|
|
if (Value == "libc++")
|
|
|
|
return ToolChain::CST_Libcxx;
|
|
|
|
if (Value == "libstdc++")
|
|
|
|
return ToolChain::CST_Libstdcxx;
|
2011-07-23 18:55:15 +08:00
|
|
|
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
|
2010-09-15 07:12:40 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
return ToolChain::CST_Libstdcxx;
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
/// \brief Utility function to add a system include directory to CC1 arguments.
|
|
|
|
/*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const Twine &Path) {
|
|
|
|
CC1Args.push_back("-internal-isystem");
|
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(Path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Utility function to add a system include directory with extern "C"
|
|
|
|
/// semantics to CC1 arguments.
|
|
|
|
///
|
|
|
|
/// Note that this should be used rarely, and only for directories that
|
|
|
|
/// historically and for legacy reasons are treated as having implicit extern
|
|
|
|
/// "C" semantics. These semantics are *ignored* by and large today, but its
|
|
|
|
/// important to preserve the preprocessor changes resulting from the
|
|
|
|
/// classification.
|
|
|
|
/*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const Twine &Path) {
|
|
|
|
CC1Args.push_back("-internal-externc-isystem");
|
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(Path));
|
|
|
|
}
|
|
|
|
|
2013-04-20 16:15:03 +08:00
|
|
|
void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const Twine &Path) {
|
|
|
|
if (llvm::sys::fs::exists(Path))
|
|
|
|
addExternCSystemInclude(DriverArgs, CC1Args, Path);
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
/// \brief Utility function to add a list of system include directories to CC1.
|
|
|
|
/*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
ArrayRef<StringRef> Paths) {
|
2015-08-07 06:36:24 +08:00
|
|
|
for (StringRef Path : Paths) {
|
2011-12-18 07:10:01 +08:00
|
|
|
CC1Args.push_back("-internal-isystem");
|
2015-08-07 06:36:24 +08:00
|
|
|
CC1Args.push_back(DriverArgs.MakeArgString(Path));
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:49:01 +08:00
|
|
|
void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
2011-11-04 15:43:33 +08:00
|
|
|
// Header search paths should be handled by each of the subclasses.
|
|
|
|
// Historically, they have not been, and instead have been handled inside of
|
|
|
|
// the CC1-layer frontend. As the logic is hoisted out, this generic function
|
|
|
|
// will slowly stop being called.
|
|
|
|
//
|
|
|
|
// While it is being called, replicate a bit of a hack to propagate the
|
|
|
|
// '-stdlib=' flag down to CC1 so that it can in turn customize the C++
|
|
|
|
// header search paths with it. Once all systems are overriding this
|
|
|
|
// function, the CC1 flag and this line can be removed.
|
2011-11-05 07:49:01 +08:00
|
|
|
DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
|
2010-09-15 07:12:35 +08:00
|
|
|
}
|
|
|
|
|
2010-09-17 09:20:05 +08:00
|
|
|
void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2010-09-15 07:12:35 +08:00
|
|
|
CXXStdlibType Type = GetCXXStdlibType(Args);
|
|
|
|
|
|
|
|
switch (Type) {
|
2010-09-15 07:12:40 +08:00
|
|
|
case ToolChain::CST_Libcxx:
|
|
|
|
CmdArgs.push_back("-lc++");
|
|
|
|
break;
|
|
|
|
|
2010-09-15 07:12:35 +08:00
|
|
|
case ToolChain::CST_Libstdcxx:
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-18 02:39:08 +08:00
|
|
|
|
2015-11-18 01:41:23 +08:00
|
|
|
void ToolChain::AddFilePathLibArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
for (const auto &LibPath : getFilePaths())
|
2015-11-26 09:02:07 +08:00
|
|
|
if(LibPath.length() > 0)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
|
2015-11-18 01:41:23 +08:00
|
|
|
}
|
|
|
|
|
2010-09-18 02:39:08 +08:00
|
|
|
void ToolChain::AddCCKextLibArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
CmdArgs.push_back("-lcc_kext");
|
|
|
|
}
|
2012-10-05 03:42:20 +08:00
|
|
|
|
|
|
|
bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2014-03-26 02:02:07 +08:00
|
|
|
// Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed
|
|
|
|
// (to keep the linker options consistent with gcc and clang itself).
|
|
|
|
if (!isOptimizationLevelFast(Args)) {
|
|
|
|
// Check if -ffast-math or -funsafe-math.
|
|
|
|
Arg *A =
|
|
|
|
Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math,
|
|
|
|
options::OPT_funsafe_math_optimizations,
|
|
|
|
options::OPT_fno_unsafe_math_optimizations);
|
|
|
|
|
|
|
|
if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
|
|
|
|
A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-05 03:42:20 +08:00
|
|
|
// If crtfastmath.o exists add it to the arguments.
|
|
|
|
std::string Path = GetFilePath("crtfastmath.o");
|
|
|
|
if (Path == "crtfastmath.o") // Not found.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Path));
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-20 05:36:47 +08:00
|
|
|
|
|
|
|
SanitizerMask ToolChain::getSupportedSanitizers() const {
|
|
|
|
// Return sanitizers which don't require runtime support and are not
|
2015-09-11 03:18:05 +08:00
|
|
|
// platform dependent.
|
2015-06-20 05:36:47 +08:00
|
|
|
using namespace SanitizerKind;
|
2015-09-11 03:18:05 +08:00
|
|
|
SanitizerMask Res = (Undefined & ~Vptr & ~Function) | (CFI & ~CFIICall) |
|
|
|
|
CFICastStrict | UnsignedIntegerOverflow | LocalBounds;
|
|
|
|
if (getTriple().getArch() == llvm::Triple::x86 ||
|
|
|
|
getTriple().getArch() == llvm::Triple::x86_64)
|
|
|
|
Res |= CFIICall;
|
|
|
|
return Res;
|
2015-06-20 05:36:47 +08:00
|
|
|
}
|
2015-11-18 06:28:46 +08:00
|
|
|
|
|
|
|
void ToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {}
|