2010-09-24 07:48:20 +08:00
|
|
|
//===--- Tools.cpp - Tools Implementations --------------------------------===//
|
2009-03-18 14:00:36 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Tools.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "InputInfo.h"
|
|
|
|
#include "SanitizerArgs.h"
|
|
|
|
#include "ToolChains.h"
|
|
|
|
#include "clang/Basic/ObjCRuntime.h"
|
2013-01-18 05:38:06 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2009-03-18 18:01:51 +08:00
|
|
|
#include "clang/Driver/Action.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Driver/Compilation.h"
|
2009-10-29 10:39:57 +08:00
|
|
|
#include "clang/Driver/Driver.h"
|
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
2009-03-18 15:06:02 +08:00
|
|
|
#include "clang/Driver/Job.h"
|
2009-11-19 12:25:22 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
2009-03-18 16:07:30 +08:00
|
|
|
#include "clang/Driver/ToolChain.h"
|
2009-03-18 15:06:02 +08:00
|
|
|
#include "clang/Driver/Util.h"
|
2009-09-10 06:32:48 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-10-29 08:41:01 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2009-09-10 06:32:34 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-01-10 10:34:13 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2009-03-27 00:23:12 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
2013-06-25 22:29:51 +08:00
|
|
|
#include "llvm/Support/Program.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Process.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include <sys/stat.h>
|
2009-03-18 15:06:02 +08:00
|
|
|
|
2009-03-18 14:00:36 +08:00
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::tools;
|
2011-07-23 18:55:15 +08:00
|
|
|
using namespace clang;
|
2013-06-15 01:17:23 +08:00
|
|
|
using namespace llvm::opt;
|
2009-03-18 14:00:36 +08:00
|
|
|
|
2009-09-10 09:21:05 +08:00
|
|
|
/// CheckPreprocessingOptions - Perform some validation of preprocessing
|
|
|
|
/// arguments that is shared with gcc.
|
|
|
|
static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC))
|
2011-03-07 07:31:01 +08:00
|
|
|
if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_argument_only_allowed_with)
|
2009-09-10 09:21:05 +08:00
|
|
|
<< A->getAsString(Args) << "-E";
|
|
|
|
}
|
|
|
|
|
2009-09-10 09:21:12 +08:00
|
|
|
/// CheckCodeGenerationOptions - Perform some validation of code generation
|
|
|
|
/// arguments that is shared with gcc.
|
|
|
|
static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) {
|
|
|
|
// In gcc, only ARM checks this, but it seems reasonable to check universally.
|
|
|
|
if (Args.hasArg(options::OPT_static))
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_dynamic,
|
|
|
|
options::OPT_mdynamic_no_pic))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
2009-09-10 09:21:12 +08:00
|
|
|
<< A->getAsString(Args) << "-static";
|
|
|
|
}
|
|
|
|
|
2010-03-30 01:55:58 +08:00
|
|
|
// Quote target names for inclusion in GNU Make dependency files.
|
|
|
|
// Only the characters '$', '#', ' ', '\t' are quoted.
|
2011-07-23 18:55:15 +08:00
|
|
|
static void QuoteTarget(StringRef Target,
|
|
|
|
SmallVectorImpl<char> &Res) {
|
2010-03-30 01:55:58 +08:00
|
|
|
for (unsigned i = 0, e = Target.size(); i != e; ++i) {
|
|
|
|
switch (Target[i]) {
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
// Escape the preceding backslashes
|
|
|
|
for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
|
|
|
|
Res.push_back('\\');
|
|
|
|
|
|
|
|
// Escape the space/tab
|
|
|
|
Res.push_back('\\');
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
Res.push_back('$');
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
Res.push_back('\\');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Res.push_back(Target[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 06:10:06 +08:00
|
|
|
static void addDirectoryList(const ArgList &Args,
|
2012-03-13 05:22:35 +08:00
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
const char *ArgName,
|
2012-03-13 06:10:06 +08:00
|
|
|
const char *EnvVar) {
|
|
|
|
const char *DirList = ::getenv(EnvVar);
|
2012-10-31 05:42:09 +08:00
|
|
|
bool CombinedArg = false;
|
|
|
|
|
2012-03-13 05:22:35 +08:00
|
|
|
if (!DirList)
|
|
|
|
return; // Nothing to do.
|
|
|
|
|
2012-10-31 05:42:09 +08:00
|
|
|
StringRef Name(ArgName);
|
|
|
|
if (Name.equals("-I") || Name.equals("-L"))
|
|
|
|
CombinedArg = true;
|
|
|
|
|
2012-03-13 05:22:35 +08:00
|
|
|
StringRef Dirs(DirList);
|
|
|
|
if (Dirs.empty()) // Empty string should not add '.'.
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringRef::size_type Delim;
|
2013-06-25 22:29:51 +08:00
|
|
|
while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
|
2012-03-13 05:22:35 +08:00
|
|
|
if (Delim == 0) { // Leading colon.
|
2012-10-31 05:42:09 +08:00
|
|
|
if (CombinedArg) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + "."));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(ArgName);
|
|
|
|
CmdArgs.push_back(".");
|
|
|
|
}
|
2012-03-13 05:22:35 +08:00
|
|
|
} else {
|
2012-10-31 05:42:09 +08:00
|
|
|
if (CombinedArg) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(ArgName);
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
|
|
|
|
}
|
2012-03-13 05:22:35 +08:00
|
|
|
}
|
2012-03-19 23:00:03 +08:00
|
|
|
Dirs = Dirs.substr(Delim + 1);
|
2012-03-13 05:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Dirs.empty()) { // Trailing colon.
|
2012-10-31 05:42:09 +08:00
|
|
|
if (CombinedArg) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + "."));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(ArgName);
|
|
|
|
CmdArgs.push_back(".");
|
|
|
|
}
|
2012-03-13 05:22:35 +08:00
|
|
|
} else { // Add the last path.
|
2012-10-31 05:42:09 +08:00
|
|
|
if (CombinedArg) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(ArgName);
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Dirs));
|
|
|
|
}
|
2012-03-13 05:22:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
static void AddLinkerInputs(const ToolChain &TC,
|
|
|
|
const InputInfoList &Inputs, const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) {
|
|
|
|
const Driver &D = TC.getDriver();
|
|
|
|
|
2011-02-19 13:33:51 +08:00
|
|
|
// Add extra linker input arguments which are not treated as inputs
|
|
|
|
// (constructed via -Xarch_).
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
|
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
|
|
|
if (!TC.HasNativeLLVMSupport()) {
|
|
|
|
// Don't try to pass LLVM inputs unless we have native support.
|
|
|
|
if (II.getType() == types::TY_LLVM_IR ||
|
|
|
|
II.getType() == types::TY_LTO_IR ||
|
|
|
|
II.getType() == types::TY_LLVM_BC ||
|
|
|
|
II.getType() == types::TY_LTO_BC)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_no_linker_llvm_support)
|
2010-09-17 08:24:54 +08:00
|
|
|
<< TC.getTripleString();
|
|
|
|
}
|
|
|
|
|
2010-09-17 08:45:02 +08:00
|
|
|
// Add filenames immediately.
|
|
|
|
if (II.isFilename()) {
|
2010-09-17 08:24:54 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2010-09-17 08:45:02 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, this is a linker input argument.
|
|
|
|
const Arg &A = II.getInputArg();
|
|
|
|
|
|
|
|
// Handle reserved library options.
|
|
|
|
if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
|
2010-09-17 09:20:05 +08:00
|
|
|
TC.AddCXXStdlibLibArgs(Args, CmdArgs);
|
2010-09-18 02:39:08 +08:00
|
|
|
} else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) {
|
|
|
|
TC.AddCCKextLibArgs(Args, CmdArgs);
|
2010-09-17 08:45:02 +08:00
|
|
|
} else
|
|
|
|
A.renderAsInput(Args, CmdArgs);
|
2010-09-17 08:24:54 +08:00
|
|
|
}
|
2012-03-13 05:22:35 +08:00
|
|
|
|
|
|
|
// LIBRARY_PATH - included following the user specified library paths.
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
|
2010-09-17 08:24:54 +08:00
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// \brief Determine whether Objective-C automated reference counting is
|
|
|
|
/// enabled.
|
|
|
|
static bool isObjCAutoRefCount(const ArgList &Args) {
|
|
|
|
return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false);
|
|
|
|
}
|
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
/// \brief Determine whether we are linking the ObjC runtime.
|
|
|
|
static bool isObjCRuntimeLinked(const ArgList &Args) {
|
2012-08-08 03:58:00 +08:00
|
|
|
if (isObjCAutoRefCount(Args)) {
|
|
|
|
Args.ClaimAllArgs(options::OPT_fobjc_link_runtime);
|
2012-03-07 04:05:56 +08:00
|
|
|
return true;
|
2012-08-08 03:58:00 +08:00
|
|
|
}
|
2012-03-07 04:05:56 +08:00
|
|
|
return Args.hasArg(options::OPT_fobjc_link_runtime);
|
|
|
|
}
|
|
|
|
|
2011-06-03 02:58:46 +08:00
|
|
|
static void addProfileRT(const ToolChain &TC, const ArgList &Args,
|
2011-06-28 03:15:03 +08:00
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
llvm::Triple Triple) {
|
|
|
|
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_generate) ||
|
|
|
|
Args.hasArg(options::OPT_fcreate_profile) ||
|
|
|
|
Args.hasArg(options::OPT_coverage)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to
|
|
|
|
// the link line. We cannot do the same thing because unlike gcov there is a
|
|
|
|
// libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is
|
|
|
|
// not supported by old linkers.
|
2011-11-08 00:02:25 +08:00
|
|
|
std::string ProfileRT =
|
|
|
|
std::string(TC.getDriver().Dir) + "/../lib/libprofile_rt.a";
|
2011-06-28 03:15:03 +08:00
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ProfileRT));
|
2011-06-03 02:58:46 +08:00
|
|
|
}
|
|
|
|
|
2012-10-20 06:37:06 +08:00
|
|
|
static bool forwardToGCC(const Option &O) {
|
2013-06-19 23:09:06 +08:00
|
|
|
// Don't forward inputs from the original command line. They are added from
|
|
|
|
// InputInfoList.
|
2013-06-20 09:33:59 +08:00
|
|
|
return O.getKind() != Option::InputClass &&
|
2013-06-19 23:09:06 +08:00
|
|
|
!O.hasFlag(options::NoForward) &&
|
2012-10-20 06:37:06 +08:00
|
|
|
!O.hasFlag(options::DriverOption) &&
|
|
|
|
!O.hasFlag(options::LinkerInput);
|
|
|
|
}
|
|
|
|
|
2011-11-06 08:40:05 +08:00
|
|
|
void Clang::AddPreprocessingOptions(Compilation &C,
|
2013-01-25 03:14:47 +08:00
|
|
|
const JobAction &JA,
|
2011-11-06 08:40:05 +08:00
|
|
|
const Driver &D,
|
2009-04-18 08:34:01 +08:00
|
|
|
const ArgList &Args,
|
2009-04-09 07:54:23 +08:00
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs) const {
|
|
|
|
Arg *A;
|
2009-06-09 05:48:20 +08:00
|
|
|
|
2009-09-10 09:21:05 +08:00
|
|
|
CheckPreprocessingOptions(D, Args);
|
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_C);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_CC);
|
2009-06-09 05:48:20 +08:00
|
|
|
|
|
|
|
// Handle dependency file generation.
|
2010-12-09 05:33:40 +08:00
|
|
|
if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) ||
|
2009-04-09 07:54:23 +08:00
|
|
|
(A = Args.getLastArg(options::OPT_MD)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_MMD))) {
|
|
|
|
// Determine the output location.
|
|
|
|
const char *DepFile;
|
2012-09-27 03:01:49 +08:00
|
|
|
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
DepFile = MF->getValue();
|
2013-01-25 03:14:47 +08:00
|
|
|
C.addFailureResultFile(DepFile, &JA);
|
2012-09-27 03:01:49 +08:00
|
|
|
} else if (Output.getType() == types::TY_Dependencies) {
|
|
|
|
DepFile = Output.getFilename();
|
2009-11-19 11:26:40 +08:00
|
|
|
} else if (A->getOption().matches(options::OPT_M) ||
|
|
|
|
A->getOption().matches(options::OPT_MM)) {
|
2009-04-09 07:54:23 +08:00
|
|
|
DepFile = "-";
|
|
|
|
} else {
|
2012-11-23 14:14:39 +08:00
|
|
|
DepFile = getDependencyFileName(Args, Inputs);
|
2013-01-25 03:14:47 +08:00
|
|
|
C.addFailureResultFile(DepFile, &JA);
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
CmdArgs.push_back("-dependency-file");
|
|
|
|
CmdArgs.push_back(DepFile);
|
|
|
|
|
2010-03-30 01:55:58 +08:00
|
|
|
// Add a default target if one wasn't specified.
|
2009-04-09 07:54:23 +08:00
|
|
|
if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {
|
|
|
|
const char *DepTarget;
|
|
|
|
|
|
|
|
// If user provided -o, that is the dependency target, except
|
|
|
|
// when we are only generating a dependency file.
|
|
|
|
Arg *OutputOpt = Args.getLastArg(options::OPT_o);
|
|
|
|
if (OutputOpt && Output.getType() != types::TY_Dependencies) {
|
2012-11-01 12:30:05 +08:00
|
|
|
DepTarget = OutputOpt->getValue();
|
2009-04-09 07:54:23 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise derive from the base input.
|
|
|
|
//
|
|
|
|
// FIXME: This should use the computed output file location.
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> P(Inputs[0].getBaseInput());
|
2010-12-18 08:19:12 +08:00
|
|
|
llvm::sys::path::replace_extension(P, "o");
|
|
|
|
DepTarget = Args.MakeArgString(llvm::sys::path::filename(P));
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-MT");
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> Quoted;
|
2010-03-30 01:55:58 +08:00
|
|
|
QuoteTarget(DepTarget, Quoted);
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Quoted));
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
2009-11-19 11:26:40 +08:00
|
|
|
if (A->getOption().matches(options::OPT_M) ||
|
|
|
|
A->getOption().matches(options::OPT_MD))
|
2009-04-09 07:54:23 +08:00
|
|
|
CmdArgs.push_back("-sys-header-deps");
|
|
|
|
}
|
|
|
|
|
2011-07-13 03:35:15 +08:00
|
|
|
if (Args.hasArg(options::OPT_MG)) {
|
|
|
|
if (!A || A->getOption().matches(options::OPT_MD) ||
|
|
|
|
A->getOption().matches(options::OPT_MMD))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_mg_requires_m_or_mm);
|
2011-07-13 03:35:15 +08:00
|
|
|
CmdArgs.push_back("-MG");
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_MP);
|
2010-03-30 01:55:58 +08:00
|
|
|
|
|
|
|
// Convert all -MQ <target> args to -MT <quoted target>
|
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_MT,
|
|
|
|
options::OPT_MQ),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
const Arg *A = *it;
|
|
|
|
A->claim();
|
2010-03-30 01:55:58 +08:00
|
|
|
|
2010-06-12 06:00:13 +08:00
|
|
|
if (A->getOption().matches(options::OPT_MQ)) {
|
2010-03-30 01:55:58 +08:00
|
|
|
CmdArgs.push_back("-MT");
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<128> Quoted;
|
2012-11-01 12:30:05 +08:00
|
|
|
QuoteTarget(A->getValue(), Quoted);
|
2010-03-30 01:55:58 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(Quoted));
|
|
|
|
|
|
|
|
// -MT flag - no change
|
|
|
|
} else {
|
2010-06-12 06:00:13 +08:00
|
|
|
A->render(Args, CmdArgs);
|
2010-03-30 01:55:58 +08:00
|
|
|
}
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-04-18 08:34:01 +08:00
|
|
|
// Add -i* options, and automatically translate to
|
|
|
|
// -include-pch/-include-pth for transparent PCH support. It's
|
|
|
|
// wonky, but we include looking for .gch so we can support seamless
|
|
|
|
// replacement into a build system already set up to be generating
|
|
|
|
// .gch files.
|
2010-10-01 00:53:47 +08:00
|
|
|
bool RenderedImplicitInclude = false;
|
2009-11-25 19:53:23 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_clang_i_Group),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = it;
|
2009-04-09 07:54:23 +08:00
|
|
|
|
|
|
|
if (A->getOption().matches(options::OPT_include)) {
|
2010-10-01 00:53:47 +08:00
|
|
|
bool IsFirstImplicitInclude = !RenderedImplicitInclude;
|
|
|
|
RenderedImplicitInclude = true;
|
|
|
|
|
2010-08-12 07:27:58 +08:00
|
|
|
// Use PCH if the user requested it.
|
2009-10-16 04:02:44 +08:00
|
|
|
bool UsePCH = D.CCCUsePCH;
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
bool FoundPTH = false;
|
2009-04-18 08:34:01 +08:00
|
|
|
bool FoundPCH = false;
|
2013-06-25 23:03:59 +08:00
|
|
|
SmallString<128> P(A->getValue());
|
|
|
|
// We want the files to have a name like foo.h.pch. Add a dummy extension
|
|
|
|
// so that replace_extension does the right thing.
|
|
|
|
P += ".dummy";
|
2009-10-16 04:02:44 +08:00
|
|
|
if (UsePCH) {
|
2013-06-25 23:03:59 +08:00
|
|
|
llvm::sys::path::replace_extension(P, "pch");
|
2013-06-25 22:48:00 +08:00
|
|
|
if (llvm::sys::fs::exists(P.str()))
|
2009-04-18 08:34:01 +08:00
|
|
|
FoundPCH = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FoundPCH) {
|
2013-06-25 23:03:59 +08:00
|
|
|
llvm::sys::path::replace_extension(P, "pth");
|
2013-06-25 22:48:00 +08:00
|
|
|
if (llvm::sys::fs::exists(P.str()))
|
2009-04-09 07:54:23 +08:00
|
|
|
FoundPTH = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2009-04-18 08:34:01 +08:00
|
|
|
if (!FoundPCH && !FoundPTH) {
|
2013-06-25 23:03:59 +08:00
|
|
|
llvm::sys::path::replace_extension(P, "gch");
|
2013-06-25 22:48:00 +08:00
|
|
|
if (llvm::sys::fs::exists(P.str())) {
|
2009-10-16 04:02:44 +08:00
|
|
|
FoundPCH = UsePCH;
|
|
|
|
FoundPTH = !UsePCH;
|
2009-04-18 08:34:01 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
2009-04-18 08:34:01 +08:00
|
|
|
if (FoundPCH || FoundPTH) {
|
2010-10-01 00:53:47 +08:00
|
|
|
if (IsFirstImplicitInclude) {
|
|
|
|
A->claim();
|
|
|
|
if (UsePCH)
|
|
|
|
CmdArgs.push_back("-include-pch");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-include-pth");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(P.str()));
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// Ignore the PCH if not first on command line and emit warning.
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_pch_not_first_include)
|
2010-10-01 00:53:47 +08:00
|
|
|
<< P.str() << A->getAsString(Args);
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not translated, render as usual.
|
|
|
|
A->claim();
|
|
|
|
A->render(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
|
2011-07-28 12:45:53 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F,
|
|
|
|
options::OPT_index_header_map);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
|
|
|
// Add -Wp, and -Xassembler if using the preprocessor.
|
|
|
|
|
|
|
|
// FIXME: There is a very unfortunate problem here, some troubled
|
|
|
|
// souls abuse -Wp, to pass preprocessor options in gcc syntax. To
|
|
|
|
// really support that we would have to parse and then translate
|
|
|
|
// those options. :(
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
|
|
|
|
options::OPT_Xpreprocessor);
|
2009-10-29 09:53:44 +08:00
|
|
|
|
|
|
|
// -I- is a deprecated GCC feature, reject it.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_I_))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
|
2010-10-20 15:00:47 +08:00
|
|
|
|
|
|
|
// If we have a --sysroot, and don't have an explicit -isysroot flag, add an
|
|
|
|
// -isysroot to the CC1 invocation.
|
2012-04-16 12:16:43 +08:00
|
|
|
StringRef sysroot = C.getSysRoot();
|
|
|
|
if (sysroot != "") {
|
2010-10-20 15:00:47 +08:00
|
|
|
if (!Args.hasArg(options::OPT_isysroot)) {
|
|
|
|
CmdArgs.push_back("-isysroot");
|
2012-04-16 12:16:43 +08:00
|
|
|
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
|
2010-10-20 15:00:47 +08:00
|
|
|
}
|
|
|
|
}
|
2013-02-07 08:21:12 +08:00
|
|
|
|
2011-09-23 05:41:16 +08:00
|
|
|
// Parse additional include paths from environment variables.
|
2011-11-04 15:12:58 +08:00
|
|
|
// FIXME: We should probably sink the logic for handling these from the
|
|
|
|
// frontend into the driver. It will allow deleting 4 otherwise unused flags.
|
2011-09-23 05:41:16 +08:00
|
|
|
// CPATH - included following the user specified includes (but prior to
|
|
|
|
// builtin and standard includes).
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-I", "CPATH");
|
2011-09-23 05:41:16 +08:00
|
|
|
// C_INCLUDE_PATH - system includes enabled when compiling C.
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-c-isystem", "C_INCLUDE_PATH");
|
2011-09-23 05:41:16 +08:00
|
|
|
// CPLUS_INCLUDE_PATH - system includes enabled when compiling C++.
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-cxx-isystem", "CPLUS_INCLUDE_PATH");
|
2011-09-23 05:41:16 +08:00
|
|
|
// OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC.
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-objc-isystem", "OBJC_INCLUDE_PATH");
|
2011-09-23 05:41:16 +08:00
|
|
|
// OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++.
|
2012-03-13 06:10:06 +08:00
|
|
|
addDirectoryList(Args, CmdArgs, "-objcxx-isystem", "OBJCPLUS_INCLUDE_PATH");
|
2011-11-04 15:12:53 +08:00
|
|
|
|
|
|
|
// Add C++ include arguments, if needed.
|
2011-11-04 15:43:33 +08:00
|
|
|
if (types::isCXX(Inputs[0].getType()))
|
2011-11-04 15:34:47 +08:00
|
|
|
getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs);
|
2011-11-06 04:17:13 +08:00
|
|
|
|
|
|
|
// Add system include arguments.
|
|
|
|
getToolChain().AddClangSystemIncludeArgs(Args, CmdArgs);
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
2012-06-27 06:20:06 +08:00
|
|
|
/// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
|
|
|
|
/// CPU.
|
|
|
|
//
|
|
|
|
// FIXME: This is redundant with -mcpu, why does LLVM use this.
|
|
|
|
// FIXME: tblgen this, or kill it!
|
|
|
|
static const char *getLLVMArchSuffixForARM(StringRef CPU) {
|
|
|
|
return llvm::StringSwitch<const char *>(CPU)
|
2013-06-13 23:02:46 +08:00
|
|
|
.Case("strongarm", "v4")
|
2012-06-27 06:20:06 +08:00
|
|
|
.Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "v4t")
|
|
|
|
.Cases("arm720t", "arm9", "arm9tdmi", "v4t")
|
|
|
|
.Cases("arm920", "arm920t", "arm922t", "v4t")
|
|
|
|
.Cases("arm940t", "ep9312","v4t")
|
|
|
|
.Cases("arm10tdmi", "arm1020t", "v5")
|
|
|
|
.Cases("arm9e", "arm926ej-s", "arm946e-s", "v5e")
|
|
|
|
.Cases("arm966e-s", "arm968e-s", "arm10e", "v5e")
|
|
|
|
.Cases("arm1020e", "arm1022e", "xscale", "iwmmxt", "v5e")
|
|
|
|
.Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "v6")
|
|
|
|
.Cases("arm1176jzf-s", "mpcorenovfp", "mpcore", "v6")
|
|
|
|
.Cases("arm1156t2-s", "arm1156t2f-s", "v6t2")
|
2013-03-05 06:37:46 +08:00
|
|
|
.Cases("cortex-a5", "cortex-a7", "cortex-a8", "v7")
|
|
|
|
.Cases("cortex-a9", "cortex-a15", "v7")
|
2012-12-22 01:57:47 +08:00
|
|
|
.Case("cortex-r5", "v7r")
|
2012-06-27 06:20:06 +08:00
|
|
|
.Case("cortex-m0", "v6m")
|
2013-03-05 06:37:49 +08:00
|
|
|
.Case("cortex-m3", "v7m")
|
|
|
|
.Case("cortex-m4", "v7em")
|
2012-09-30 07:52:50 +08:00
|
|
|
.Case("cortex-a9-mp", "v7f")
|
|
|
|
.Case("swift", "v7s")
|
2012-06-27 06:20:06 +08:00
|
|
|
.Default("");
|
|
|
|
}
|
|
|
|
|
2011-04-15 13:22:18 +08:00
|
|
|
/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
|
2009-09-10 14:49:20 +08:00
|
|
|
//
|
|
|
|
// FIXME: tblgen this.
|
2012-06-27 06:20:06 +08:00
|
|
|
static std::string getARMTargetCPU(const ArgList &Args,
|
2010-06-29 01:18:09 +08:00
|
|
|
const llvm::Triple &Triple) {
|
2009-09-10 14:49:20 +08:00
|
|
|
// FIXME: Warn on inconsistent use of -mcpu and -march.
|
2009-09-10 12:57:17 +08:00
|
|
|
|
|
|
|
// If we have -mcpu=, use that.
|
2012-06-27 06:20:06 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef MCPU = A->getValue();
|
2012-06-27 06:20:06 +08:00
|
|
|
// Handle -mcpu=native.
|
|
|
|
if (MCPU == "native")
|
|
|
|
return llvm::sys::getHostCPUName();
|
|
|
|
else
|
|
|
|
return MCPU;
|
|
|
|
}
|
2009-09-10 12:57:17 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef MArch;
|
2009-09-10 12:57:17 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
2010-06-29 01:18:09 +08:00
|
|
|
// Otherwise, if we have -march= choose the base CPU for that arch.
|
2012-11-01 12:30:05 +08:00
|
|
|
MArch = A->getValue();
|
2010-06-29 01:18:09 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise, use the Arch from the triple.
|
|
|
|
MArch = Triple.getArchName();
|
2009-09-10 12:57:17 +08:00
|
|
|
}
|
|
|
|
|
2012-06-27 06:20:06 +08:00
|
|
|
// Handle -march=native.
|
|
|
|
std::string NativeMArch;
|
|
|
|
if (MArch == "native") {
|
|
|
|
std::string CPU = llvm::sys::getHostCPUName();
|
|
|
|
if (CPU != "generic") {
|
|
|
|
// Translate the native cpu into the architecture. The switch below will
|
|
|
|
// then chose the minimum cpu for that arch.
|
|
|
|
NativeMArch = std::string("arm") + getLLVMArchSuffixForARM(CPU);
|
|
|
|
MArch = NativeMArch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-08 01:48:56 +08:00
|
|
|
return llvm::StringSwitch<const char *>(MArch)
|
|
|
|
.Cases("armv2", "armv2a","arm2")
|
|
|
|
.Case("armv3", "arm6")
|
|
|
|
.Case("armv3m", "arm7m")
|
2013-06-13 23:02:46 +08:00
|
|
|
.Case("armv4", "strongarm")
|
|
|
|
.Case("armv4t", "arm7tdmi")
|
2011-10-08 01:48:56 +08:00
|
|
|
.Cases("armv5", "armv5t", "arm10tdmi")
|
2012-04-25 16:35:56 +08:00
|
|
|
.Cases("armv5e", "armv5te", "arm1022e")
|
2011-10-08 01:48:56 +08:00
|
|
|
.Case("armv5tej", "arm926ej-s")
|
|
|
|
.Cases("armv6", "armv6k", "arm1136jf-s")
|
|
|
|
.Case("armv6j", "arm1136j-s")
|
|
|
|
.Cases("armv6z", "armv6zk", "arm1176jzf-s")
|
|
|
|
.Case("armv6t2", "arm1156t2-s")
|
2013-03-05 06:37:49 +08:00
|
|
|
.Cases("armv6m", "armv6-m", "cortex-m0")
|
2011-10-08 01:48:56 +08:00
|
|
|
.Cases("armv7", "armv7a", "armv7-a", "cortex-a8")
|
2013-03-05 06:37:49 +08:00
|
|
|
.Cases("armv7em", "armv7e-m", "cortex-m4")
|
2012-09-30 07:52:50 +08:00
|
|
|
.Cases("armv7f", "armv7-f", "cortex-a9-mp")
|
|
|
|
.Cases("armv7s", "armv7-s", "swift")
|
2011-10-08 01:48:56 +08:00
|
|
|
.Cases("armv7r", "armv7-r", "cortex-r4")
|
|
|
|
.Cases("armv7m", "armv7-m", "cortex-m3")
|
2013-06-27 01:19:48 +08:00
|
|
|
.Cases("armv8", "armv8a", "armv8-a", "cortex-a53")
|
2011-10-08 01:48:56 +08:00
|
|
|
.Case("ep9312", "ep9312")
|
|
|
|
.Case("iwmmxt", "iwmmxt")
|
|
|
|
.Case("xscale", "xscale")
|
2013-06-13 23:02:46 +08:00
|
|
|
// If all else failed, return the most base CPU with thumb interworking
|
|
|
|
// supported by LLVM.
|
2011-10-08 01:48:56 +08:00
|
|
|
.Default("arm7tdmi");
|
2009-09-10 12:57:17 +08:00
|
|
|
}
|
|
|
|
|
2009-11-17 14:37:03 +08:00
|
|
|
// FIXME: Move to target hook.
|
|
|
|
static bool isSignedCharDefault(const llvm::Triple &Triple) {
|
|
|
|
switch (Triple.getArch()) {
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
|
2013-01-31 20:13:10 +08:00
|
|
|
case llvm::Triple::aarch64:
|
2011-05-24 23:40:46 +08:00
|
|
|
case llvm::Triple::arm:
|
2009-11-17 14:37:03 +08:00
|
|
|
case llvm::Triple::ppc:
|
|
|
|
case llvm::Triple::ppc64:
|
2011-10-14 13:03:44 +08:00
|
|
|
if (Triple.isOSDarwin())
|
2009-11-17 14:37:03 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
2013-05-07 00:26:41 +08:00
|
|
|
|
|
|
|
case llvm::Triple::systemz:
|
|
|
|
return false;
|
2009-11-17 14:37:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-05 04:51:35 +08:00
|
|
|
// Handle -mfpu=.
|
|
|
|
//
|
|
|
|
// FIXME: Centralize feature selection, defaulting shouldn't be also in the
|
|
|
|
// frontend target.
|
|
|
|
static void addFPUArgs(const Driver &D, const Arg *A, const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef FPU = A->getValue();
|
2012-04-05 04:51:35 +08:00
|
|
|
|
|
|
|
// Set the target features based on the FPU.
|
|
|
|
if (FPU == "fpa" || FPU == "fpe2" || FPU == "fpe3" || FPU == "maverick") {
|
|
|
|
// Disable any default FPU support.
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-vfp2");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-vfp3");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neon");
|
|
|
|
} else if (FPU == "vfp3-d16" || FPU == "vfpv3-d16") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+vfp3");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+d16");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neon");
|
|
|
|
} else if (FPU == "vfp") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+vfp2");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neon");
|
|
|
|
} else if (FPU == "vfp3" || FPU == "vfpv3") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+vfp3");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neon");
|
|
|
|
} else if (FPU == "neon") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+neon");
|
|
|
|
} else
|
|
|
|
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
2012-04-05 04:39:32 +08:00
|
|
|
// Handle -mfpmath=.
|
|
|
|
static void addFPMathArgs(const Driver &D, const Arg *A, const ArgList &Args,
|
2012-04-05 06:13:40 +08:00
|
|
|
ArgStringList &CmdArgs, StringRef CPU) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef FPMath = A->getValue();
|
2012-04-05 04:39:32 +08:00
|
|
|
|
|
|
|
// Set the target features based on the FPMath.
|
|
|
|
if (FPMath == "neon") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+neonfp");
|
2012-04-05 06:13:40 +08:00
|
|
|
|
2013-03-05 06:37:46 +08:00
|
|
|
if (CPU != "cortex-a5" && CPU != "cortex-a7" &&
|
|
|
|
CPU != "cortex-a8" && CPU != "cortex-a9" &&
|
|
|
|
CPU != "cortex-a9-mp" && CPU != "cortex-a15")
|
2012-04-05 06:13:40 +08:00
|
|
|
D.Diag(diag::err_drv_invalid_feature) << "-mfpmath=neon" << CPU;
|
|
|
|
|
2012-04-05 04:39:32 +08:00
|
|
|
} else if (FPMath == "vfp" || FPMath == "vfp2" || FPMath == "vfp3" ||
|
|
|
|
FPMath == "vfp4") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neonfp");
|
2012-04-05 06:13:40 +08:00
|
|
|
|
|
|
|
// FIXME: Add warnings when disabling a feature not present for a given CPU.
|
2012-04-05 04:39:32 +08:00
|
|
|
} else
|
|
|
|
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
2012-04-09 21:38:30 +08:00
|
|
|
// Select the float ABI as determined by -msoft-float, -mhard-float, and
|
|
|
|
// -mfloat-abi=.
|
|
|
|
static StringRef getARMFloatABI(const Driver &D,
|
|
|
|
const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef FloatABI;
|
2009-09-11 07:00:09 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
|
|
|
|
options::OPT_mhard_float,
|
|
|
|
options::OPT_mfloat_abi_EQ)) {
|
|
|
|
if (A->getOption().matches(options::OPT_msoft_float))
|
|
|
|
FloatABI = "soft";
|
|
|
|
else if (A->getOption().matches(options::OPT_mhard_float))
|
|
|
|
FloatABI = "hard";
|
|
|
|
else {
|
2012-11-01 12:30:05 +08:00
|
|
|
FloatABI = A->getValue();
|
2009-09-11 07:00:09 +08:00
|
|
|
if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") {
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_invalid_mfloat_abi)
|
2009-09-11 07:00:09 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
FloatABI = "soft";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If unspecified, choose the default based on the platform.
|
|
|
|
if (FloatABI.empty()) {
|
2010-06-29 01:18:09 +08:00
|
|
|
switch (Triple.getOS()) {
|
2011-10-14 13:03:44 +08:00
|
|
|
case llvm::Triple::Darwin:
|
|
|
|
case llvm::Triple::MacOSX:
|
|
|
|
case llvm::Triple::IOS: {
|
2009-09-11 07:00:09 +08:00
|
|
|
// Darwin defaults to "softfp" for v6 and v7.
|
|
|
|
//
|
|
|
|
// FIXME: Factor out an ARM class so we can cache the arch somewhere.
|
2012-06-27 06:20:06 +08:00
|
|
|
std::string ArchName =
|
2010-06-29 01:18:09 +08:00
|
|
|
getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
|
2012-06-27 06:20:06 +08:00
|
|
|
if (StringRef(ArchName).startswith("v6") ||
|
|
|
|
StringRef(ArchName).startswith("v7"))
|
2009-09-11 07:00:09 +08:00
|
|
|
FloatABI = "softfp";
|
|
|
|
else
|
|
|
|
FloatABI = "soft";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-13 12:17:14 +08:00
|
|
|
case llvm::Triple::FreeBSD:
|
|
|
|
// FreeBSD defaults to soft float
|
|
|
|
FloatABI = "soft";
|
|
|
|
break;
|
|
|
|
|
2009-09-11 07:00:09 +08:00
|
|
|
default:
|
2011-02-05 01:59:28 +08:00
|
|
|
switch(Triple.getEnvironment()) {
|
2012-07-31 16:06:29 +08:00
|
|
|
case llvm::Triple::GNUEABIHF:
|
|
|
|
FloatABI = "hard";
|
|
|
|
break;
|
2011-02-05 01:59:28 +08:00
|
|
|
case llvm::Triple::GNUEABI:
|
|
|
|
FloatABI = "softfp";
|
|
|
|
break;
|
|
|
|
case llvm::Triple::EABI:
|
|
|
|
// EABI is always AAPCS, and if it was not marked 'hard', it's softfp
|
|
|
|
FloatABI = "softfp";
|
|
|
|
break;
|
2012-09-02 17:30:11 +08:00
|
|
|
case llvm::Triple::Android: {
|
2012-06-27 06:20:06 +08:00
|
|
|
std::string ArchName =
|
2012-01-11 03:47:42 +08:00
|
|
|
getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
|
2012-06-27 06:20:06 +08:00
|
|
|
if (StringRef(ArchName).startswith("v7"))
|
2012-01-11 03:47:42 +08:00
|
|
|
FloatABI = "softfp";
|
|
|
|
else
|
|
|
|
FloatABI = "soft";
|
|
|
|
break;
|
|
|
|
}
|
2011-02-05 01:59:28 +08:00
|
|
|
default:
|
|
|
|
// Assume "soft", but warn the user we are guessing.
|
|
|
|
FloatABI = "soft";
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft";
|
2011-02-05 01:59:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-11 07:00:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-09 21:38:30 +08:00
|
|
|
return FloatABI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Clang::AddARMTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
bool KernelOrKext) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
2012-10-16 06:23:53 +08:00
|
|
|
// Get the effective triple, which takes into account the deployment target.
|
|
|
|
std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
|
|
|
|
llvm::Triple Triple(TripleStr);
|
2012-10-23 02:30:51 +08:00
|
|
|
std::string CPUName = getARMTargetCPU(Args, Triple);
|
2012-04-09 21:38:30 +08:00
|
|
|
|
|
|
|
// Select the ABI to use.
|
|
|
|
//
|
|
|
|
// FIXME: Support -meabi.
|
|
|
|
const char *ABIName = 0;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
ABIName = A->getValue();
|
2012-10-23 02:30:51 +08:00
|
|
|
} else if (Triple.isOSDarwin()) {
|
|
|
|
// The backend is hardwired to assume AAPCS for M-class processors, ensure
|
|
|
|
// the frontend matches that.
|
|
|
|
if (StringRef(CPUName).startswith("cortex-m")) {
|
|
|
|
ABIName = "aapcs";
|
|
|
|
} else {
|
|
|
|
ABIName = "apcs-gnu";
|
|
|
|
}
|
2012-04-09 21:38:30 +08:00
|
|
|
} else {
|
|
|
|
// Select the default based on the platform.
|
|
|
|
switch(Triple.getEnvironment()) {
|
2012-09-02 17:30:11 +08:00
|
|
|
case llvm::Triple::Android:
|
2012-04-09 21:38:30 +08:00
|
|
|
case llvm::Triple::GNUEABI:
|
2012-07-31 16:06:29 +08:00
|
|
|
case llvm::Triple::GNUEABIHF:
|
2012-04-09 21:38:30 +08:00
|
|
|
ABIName = "aapcs-linux";
|
|
|
|
break;
|
|
|
|
case llvm::Triple::EABI:
|
|
|
|
ABIName = "aapcs";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ABIName = "apcs-gnu";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("-target-abi");
|
|
|
|
CmdArgs.push_back(ABIName);
|
|
|
|
|
|
|
|
// Set the CPU based on -march= and -mcpu=.
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
2012-10-23 02:30:51 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(CPUName));
|
2012-04-09 21:38:30 +08:00
|
|
|
|
|
|
|
// Determine floating point ABI from the options & target defaults.
|
|
|
|
StringRef FloatABI = getARMFloatABI(D, Args, Triple);
|
2009-09-11 07:00:09 +08:00
|
|
|
if (FloatABI == "soft") {
|
|
|
|
// Floating point operations and argument passing are soft.
|
|
|
|
//
|
|
|
|
// FIXME: This changes CPP defines, we need -target-soft-float.
|
2009-11-30 16:42:00 +08:00
|
|
|
CmdArgs.push_back("-msoft-float");
|
2009-12-09 03:49:51 +08:00
|
|
|
CmdArgs.push_back("-mfloat-abi");
|
|
|
|
CmdArgs.push_back("soft");
|
2009-09-11 07:00:09 +08:00
|
|
|
} else if (FloatABI == "softfp") {
|
|
|
|
// Floating point operations are hard, but argument passing is soft.
|
2009-12-09 03:49:51 +08:00
|
|
|
CmdArgs.push_back("-mfloat-abi");
|
|
|
|
CmdArgs.push_back("soft");
|
2009-09-11 07:00:09 +08:00
|
|
|
} else {
|
|
|
|
// Floating point operations and argument passing are hard.
|
|
|
|
assert(FloatABI == "hard" && "Invalid float abi!");
|
2009-12-09 03:49:51 +08:00
|
|
|
CmdArgs.push_back("-mfloat-abi");
|
|
|
|
CmdArgs.push_back("hard");
|
2009-09-11 07:00:09 +08:00
|
|
|
}
|
2009-12-19 12:15:38 +08:00
|
|
|
|
|
|
|
// Set appropriate target features for floating point mode.
|
|
|
|
//
|
|
|
|
// FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
|
|
|
|
// yet (it uses the -mfloat-abi and -msoft-float options above), and it is
|
|
|
|
// stripped out by the ARM target.
|
|
|
|
|
|
|
|
// Use software floating point operations?
|
|
|
|
if (FloatABI == "soft") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+soft-float");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use software floating point argument passing?
|
|
|
|
if (FloatABI != "hard") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+soft-float-abi");
|
|
|
|
}
|
2009-12-22 07:28:17 +08:00
|
|
|
|
|
|
|
// Honor -mfpu=.
|
2012-04-05 04:51:35 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ))
|
2012-04-05 04:56:36 +08:00
|
|
|
addFPUArgs(D, A, Args, CmdArgs);
|
2011-03-17 08:07:34 +08:00
|
|
|
|
2012-04-05 04:39:32 +08:00
|
|
|
// Honor -mfpmath=.
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ))
|
2012-04-05 06:13:40 +08:00
|
|
|
addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple));
|
2012-04-05 04:39:32 +08:00
|
|
|
|
2011-03-17 08:07:34 +08:00
|
|
|
// Setting -msoft-float effectively disables NEON because of the GCC
|
|
|
|
// implementation, although the same isn't true of VFP or VFP3.
|
|
|
|
if (FloatABI == "soft") {
|
2011-03-18 01:10:06 +08:00
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-neon");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Kernel code has more strict alignment requirements.
|
|
|
|
if (KernelOrKext) {
|
2012-10-16 06:23:53 +08:00
|
|
|
if (Triple.getOS() != llvm::Triple::IOS || Triple.isOSVersionLT(6)) {
|
|
|
|
CmdArgs.push_back("-backend-option");
|
|
|
|
CmdArgs.push_back("-arm-long-calls");
|
|
|
|
}
|
2011-03-18 01:10:06 +08:00
|
|
|
|
2011-03-23 00:48:17 +08:00
|
|
|
CmdArgs.push_back("-backend-option");
|
2011-03-18 01:10:06 +08:00
|
|
|
CmdArgs.push_back("-arm-strict-align");
|
2011-04-19 05:26:42 +08:00
|
|
|
|
|
|
|
// The kext linker doesn't know how to deal with movw/movt.
|
|
|
|
CmdArgs.push_back("-backend-option");
|
|
|
|
CmdArgs.push_back("-arm-darwin-use-movt=0");
|
2011-03-17 08:07:34 +08:00
|
|
|
}
|
2011-08-26 08:26:29 +08:00
|
|
|
|
|
|
|
// Setting -mno-global-merge disables the codegen global merge pass. Setting
|
|
|
|
// -mglobal-merge has no effect as the pass is enabled by default.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
|
|
|
|
options::OPT_mno_global_merge)) {
|
|
|
|
if (A->getOption().matches(options::OPT_mno_global_merge))
|
|
|
|
CmdArgs.push_back("-mno-global-merge");
|
|
|
|
}
|
2012-05-17 04:40:09 +08:00
|
|
|
|
2013-04-12 02:53:25 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_mimplicit_float,
|
|
|
|
options::OPT_mno_implicit_float,
|
|
|
|
true))
|
2012-05-17 04:40:09 +08:00
|
|
|
CmdArgs.push_back("-no-implicit-float");
|
2009-09-10 12:57:17 +08:00
|
|
|
}
|
|
|
|
|
2012-09-22 04:19:32 +08:00
|
|
|
// Translate MIPS CPU name alias option to CPU name.
|
|
|
|
static StringRef getMipsCPUFromAlias(const Arg &A) {
|
|
|
|
if (A.getOption().matches(options::OPT_mips32))
|
|
|
|
return "mips32";
|
|
|
|
if (A.getOption().matches(options::OPT_mips32r2))
|
|
|
|
return "mips32r2";
|
|
|
|
if (A.getOption().matches(options::OPT_mips64))
|
|
|
|
return "mips64";
|
|
|
|
if (A.getOption().matches(options::OPT_mips64r2))
|
|
|
|
return "mips64r2";
|
|
|
|
llvm_unreachable("Unexpected option");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-04-08 06:09:23 +08:00
|
|
|
// Get CPU and ABI names. They are not independent
|
|
|
|
// so we have to calculate them together.
|
|
|
|
static void getMipsCPUAndABI(const ArgList &Args,
|
|
|
|
const ToolChain &TC,
|
|
|
|
StringRef &CPUName,
|
|
|
|
StringRef &ABIName) {
|
2012-09-10 16:32:41 +08:00
|
|
|
const char *DefMips32CPU = "mips32";
|
|
|
|
const char *DefMips64CPU = "mips64";
|
2011-09-27 05:07:52 +08:00
|
|
|
|
2012-09-10 16:32:41 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_march_EQ,
|
2012-09-22 04:19:32 +08:00
|
|
|
options::OPT_mcpu_EQ,
|
|
|
|
options::OPT_mips_CPUs_Group)) {
|
|
|
|
if (A->getOption().matches(options::OPT_mips_CPUs_Group))
|
|
|
|
CPUName = getMipsCPUFromAlias(*A);
|
|
|
|
else
|
2012-11-01 12:30:05 +08:00
|
|
|
CPUName = A->getValue();
|
2012-09-22 04:19:32 +08:00
|
|
|
}
|
2012-09-10 16:32:41 +08:00
|
|
|
|
2013-04-21 21:30:10 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
ABIName = A->getValue();
|
2013-04-21 21:30:10 +08:00
|
|
|
// Convert a GNU style Mips ABI name to the name
|
|
|
|
// accepted by LLVM Mips backend.
|
|
|
|
ABIName = llvm::StringSwitch<llvm::StringRef>(ABIName)
|
|
|
|
.Case("32", "o32")
|
|
|
|
.Case("64", "n64")
|
|
|
|
.Default(ABIName);
|
|
|
|
}
|
2012-09-10 16:32:41 +08:00
|
|
|
|
|
|
|
// Setup default CPU and ABI names.
|
|
|
|
if (CPUName.empty() && ABIName.empty()) {
|
|
|
|
switch (TC.getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected triple arch name");
|
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
|
|
|
CPUName = DefMips32CPU;
|
|
|
|
break;
|
|
|
|
case llvm::Triple::mips64:
|
|
|
|
case llvm::Triple::mips64el:
|
|
|
|
CPUName = DefMips64CPU;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ABIName.empty()) {
|
|
|
|
// Deduce CPU name from ABI name.
|
|
|
|
CPUName = llvm::StringSwitch<const char *>(ABIName)
|
2013-02-27 22:55:49 +08:00
|
|
|
.Cases("32", "o32", "eabi", DefMips32CPU)
|
|
|
|
.Cases("n32", "n64", "64", DefMips64CPU)
|
2012-09-10 16:32:41 +08:00
|
|
|
.Default("");
|
|
|
|
}
|
|
|
|
else if (!CPUName.empty()) {
|
|
|
|
// Deduce ABI name from CPU name.
|
|
|
|
ABIName = llvm::StringSwitch<const char *>(CPUName)
|
|
|
|
.Cases("mips32", "mips32r2", "o32")
|
|
|
|
.Cases("mips64", "mips64r2", "n64")
|
|
|
|
.Default("");
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Warn on inconsistent cpu and abi usage.
|
2012-04-08 06:09:23 +08:00
|
|
|
}
|
|
|
|
|
2013-02-27 22:55:49 +08:00
|
|
|
// Convert ABI name to the GNU tools acceptable variant.
|
|
|
|
static StringRef getGnuCompatibleMipsABIName(StringRef ABI) {
|
|
|
|
return llvm::StringSwitch<llvm::StringRef>(ABI)
|
|
|
|
.Case("o32", "32")
|
|
|
|
.Case("n64", "64")
|
|
|
|
.Default(ABI);
|
|
|
|
}
|
|
|
|
|
2012-06-02 23:06:29 +08:00
|
|
|
// Select the MIPS float ABI as determined by -msoft-float, -mhard-float,
|
|
|
|
// and -mfloat-abi=.
|
|
|
|
static StringRef getMipsFloatABI(const Driver &D, const ArgList &Args) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef FloatABI;
|
2010-03-02 10:41:08 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
|
2012-03-24 07:07:09 +08:00
|
|
|
options::OPT_mhard_float,
|
|
|
|
options::OPT_mfloat_abi_EQ)) {
|
2010-03-02 10:41:08 +08:00
|
|
|
if (A->getOption().matches(options::OPT_msoft_float))
|
|
|
|
FloatABI = "soft";
|
|
|
|
else if (A->getOption().matches(options::OPT_mhard_float))
|
|
|
|
FloatABI = "hard";
|
2012-03-24 07:07:09 +08:00
|
|
|
else {
|
2012-11-01 12:30:05 +08:00
|
|
|
FloatABI = A->getValue();
|
2013-04-14 16:37:15 +08:00
|
|
|
if (FloatABI != "soft" && FloatABI != "hard") {
|
2012-06-02 23:06:29 +08:00
|
|
|
D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
|
2012-03-24 07:07:09 +08:00
|
|
|
FloatABI = "hard";
|
|
|
|
}
|
|
|
|
}
|
2010-03-02 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If unspecified, choose the default based on the platform.
|
|
|
|
if (FloatABI.empty()) {
|
2012-03-24 07:07:09 +08:00
|
|
|
// Assume "hard", because it's a default value used by gcc.
|
|
|
|
// When we start to recognize specific target MIPS processors,
|
|
|
|
// we will be able to select the default more correctly.
|
|
|
|
FloatABI = "hard";
|
2010-03-02 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
2012-06-02 23:06:29 +08:00
|
|
|
return FloatABI;
|
|
|
|
}
|
|
|
|
|
2012-07-06 02:51:43 +08:00
|
|
|
static void AddTargetFeature(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
OptSpecifier OnOpt,
|
|
|
|
OptSpecifier OffOpt,
|
|
|
|
StringRef FeatureName) {
|
|
|
|
if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
if (A->getOption().matches(OnOpt))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("+" + FeatureName));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-" + FeatureName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 23:06:29 +08:00
|
|
|
void Clang::AddMIPSTargetArgs(const ArgList &Args,
|
2013-04-14 22:07:41 +08:00
|
|
|
ArgStringList &CmdArgs) const {
|
2012-06-02 23:06:29 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
StringRef CPUName;
|
|
|
|
StringRef ABIName;
|
|
|
|
getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
|
|
|
CmdArgs.push_back(CPUName.data());
|
|
|
|
|
|
|
|
CmdArgs.push_back("-target-abi");
|
|
|
|
CmdArgs.push_back(ABIName.data());
|
|
|
|
|
|
|
|
StringRef FloatABI = getMipsFloatABI(D, Args);
|
|
|
|
|
2013-01-10 20:36:19 +08:00
|
|
|
bool IsMips16 = Args.getLastArg(options::OPT_mips16) != NULL;
|
|
|
|
|
|
|
|
if (FloatABI == "soft" || (FloatABI == "hard" && IsMips16)) {
|
2010-03-02 10:41:08 +08:00
|
|
|
// Floating point operations and argument passing are soft.
|
|
|
|
CmdArgs.push_back("-msoft-float");
|
2012-03-24 07:07:09 +08:00
|
|
|
CmdArgs.push_back("-mfloat-abi");
|
|
|
|
CmdArgs.push_back("soft");
|
|
|
|
|
|
|
|
// FIXME: Note, this is a hack. We need to pass the selected float
|
|
|
|
// mode to the MipsTargetInfoBase to define appropriate macros there.
|
|
|
|
// Now it is the only method.
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+soft-float");
|
2013-01-10 20:36:19 +08:00
|
|
|
|
|
|
|
if (FloatABI == "hard" && IsMips16) {
|
|
|
|
CmdArgs.push_back("-mllvm");
|
|
|
|
CmdArgs.push_back("-mips16-hard-float");
|
|
|
|
}
|
2012-03-24 07:07:09 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Floating point operations and argument passing are hard.
|
2010-03-02 10:41:08 +08:00
|
|
|
assert(FloatABI == "hard" && "Invalid float abi!");
|
2012-03-24 07:07:09 +08:00
|
|
|
CmdArgs.push_back("-mfloat-abi");
|
|
|
|
CmdArgs.push_back("hard");
|
2010-03-02 10:41:08 +08:00
|
|
|
}
|
2012-07-05 22:19:39 +08:00
|
|
|
|
2013-04-14 22:07:36 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_msingle_float, options::OPT_mdouble_float,
|
|
|
|
"single-float");
|
2012-07-06 02:51:43 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mips16, options::OPT_mno_mips16,
|
|
|
|
"mips16");
|
2013-04-14 22:07:51 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mmicromips, options::OPT_mno_micromips,
|
|
|
|
"micromips");
|
2012-07-06 03:23:00 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mdsp, options::OPT_mno_dsp,
|
|
|
|
"dsp");
|
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mdspr2, options::OPT_mno_dspr2,
|
|
|
|
"dspr2");
|
2012-08-28 04:55:56 +08:00
|
|
|
|
2012-12-02 02:27:21 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) {
|
|
|
|
if (A->getOption().matches(options::OPT_mxgot)) {
|
|
|
|
CmdArgs.push_back("-mllvm");
|
|
|
|
CmdArgs.push_back("-mxgot");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 14:33:44 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1,
|
|
|
|
options::OPT_mno_ldc1_sdc1)) {
|
|
|
|
if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) {
|
|
|
|
CmdArgs.push_back("-mllvm");
|
|
|
|
CmdArgs.push_back("-mno-ldc1-sdc1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-28 04:55:56 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_G)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef v = A->getValue();
|
2012-08-28 04:55:56 +08:00
|
|
|
CmdArgs.push_back("-mllvm");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-mips-ssection-threshold=" + v));
|
|
|
|
A->claim();
|
|
|
|
}
|
2010-03-02 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 06:35:19 +08:00
|
|
|
/// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
|
|
|
|
static std::string getPPCTargetCPU(const ArgList &Args) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef CPUName = A->getValue();
|
2012-06-12 06:35:19 +08:00
|
|
|
|
|
|
|
if (CPUName == "native") {
|
|
|
|
std::string CPU = llvm::sys::getHostCPUName();
|
|
|
|
if (!CPU.empty() && CPU != "generic")
|
|
|
|
return CPU;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return llvm::StringSwitch<const char *>(CPUName)
|
|
|
|
.Case("common", "generic")
|
|
|
|
.Case("440", "440")
|
|
|
|
.Case("440fp", "440")
|
|
|
|
.Case("450", "450")
|
|
|
|
.Case("601", "601")
|
|
|
|
.Case("602", "602")
|
|
|
|
.Case("603", "603")
|
|
|
|
.Case("603e", "603e")
|
|
|
|
.Case("603ev", "603ev")
|
|
|
|
.Case("604", "604")
|
|
|
|
.Case("604e", "604e")
|
|
|
|
.Case("620", "620")
|
2013-02-02 04:23:10 +08:00
|
|
|
.Case("630", "pwr3")
|
2012-06-12 06:35:19 +08:00
|
|
|
.Case("G3", "g3")
|
|
|
|
.Case("7400", "7400")
|
|
|
|
.Case("G4", "g4")
|
|
|
|
.Case("7450", "7450")
|
|
|
|
.Case("G4+", "g4+")
|
|
|
|
.Case("750", "750")
|
|
|
|
.Case("970", "970")
|
|
|
|
.Case("G5", "g5")
|
|
|
|
.Case("a2", "a2")
|
2013-02-01 13:53:33 +08:00
|
|
|
.Case("a2q", "a2q")
|
2012-09-19 06:25:03 +08:00
|
|
|
.Case("e500mc", "e500mc")
|
|
|
|
.Case("e5500", "e5500")
|
2013-02-02 04:23:10 +08:00
|
|
|
.Case("power3", "pwr3")
|
|
|
|
.Case("power4", "pwr4")
|
|
|
|
.Case("power5", "pwr5")
|
|
|
|
.Case("power5x", "pwr5x")
|
2012-06-12 06:35:19 +08:00
|
|
|
.Case("power6", "pwr6")
|
2013-02-02 04:23:10 +08:00
|
|
|
.Case("power6x", "pwr6x")
|
2012-06-12 06:35:19 +08:00
|
|
|
.Case("power7", "pwr7")
|
2013-02-02 04:23:10 +08:00
|
|
|
.Case("pwr3", "pwr3")
|
|
|
|
.Case("pwr4", "pwr4")
|
|
|
|
.Case("pwr5", "pwr5")
|
|
|
|
.Case("pwr5x", "pwr5x")
|
|
|
|
.Case("pwr6", "pwr6")
|
|
|
|
.Case("pwr6x", "pwr6x")
|
|
|
|
.Case("pwr7", "pwr7")
|
2012-06-12 06:35:19 +08:00
|
|
|
.Case("powerpc", "ppc")
|
|
|
|
.Case("powerpc64", "ppc64")
|
|
|
|
.Default("");
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clang::AddPPCTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
std::string TargetCPUName = getPPCTargetCPU(Args);
|
|
|
|
|
|
|
|
// LLVM may default to generating code for the native CPU,
|
|
|
|
// but, like gcc, we default to a more generic option for
|
|
|
|
// each architecture. (except on Darwin)
|
|
|
|
llvm::Triple Triple = getToolChain().getTriple();
|
|
|
|
if (TargetCPUName.empty() && !Triple.isOSDarwin()) {
|
|
|
|
if (Triple.getArch() == llvm::Triple::ppc64)
|
|
|
|
TargetCPUName = "ppc64";
|
|
|
|
else
|
|
|
|
TargetCPUName = "ppc";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TargetCPUName.empty()) {
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(TargetCPUName.c_str()));
|
|
|
|
}
|
2013-02-01 10:14:03 +08:00
|
|
|
|
|
|
|
// Allow override of the Altivec feature.
|
2013-03-28 16:38:53 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_faltivec, options::OPT_fno_altivec,
|
|
|
|
"altivec");
|
|
|
|
|
2013-03-30 21:47:44 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mfprnd, options::OPT_mno_fprnd,
|
|
|
|
"fprnd");
|
|
|
|
|
2013-03-28 16:38:53 +08:00
|
|
|
// Note that gcc calls this mfcrf and LLVM calls this mfocrf.
|
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mmfcrf, options::OPT_mno_mfcrf,
|
|
|
|
"mfocrf");
|
2013-02-02 02:44:19 +08:00
|
|
|
|
2013-03-28 21:51:36 +08:00
|
|
|
AddTargetFeature(Args, CmdArgs,
|
|
|
|
options::OPT_mpopcntd, options::OPT_mno_popcntd,
|
|
|
|
"popcntd");
|
|
|
|
|
2013-03-28 16:38:53 +08:00
|
|
|
// It is really only possible to turn qpx off because turning qpx on is tied
|
|
|
|
// to using the a2q CPU.
|
2013-02-02 02:44:19 +08:00
|
|
|
if (Args.hasFlag(options::OPT_mno_qpx, options::OPT_mqpx, false)) {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("-qpx");
|
|
|
|
}
|
2012-06-12 06:35:19 +08:00
|
|
|
}
|
|
|
|
|
2013-04-02 04:56:53 +08:00
|
|
|
/// Get the (LLVM) name of the R600 gpu we are targeting.
|
|
|
|
static std::string getR600TargetGPU(const ArgList &Args) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
|
|
|
|
std::string GPUName = A->getValue();
|
|
|
|
return llvm::StringSwitch<const char *>(GPUName)
|
2013-05-07 00:12:05 +08:00
|
|
|
.Cases("rv630", "rv635", "r600")
|
|
|
|
.Cases("rv610", "rv620", "rs780", "rs880")
|
2013-04-02 04:56:53 +08:00
|
|
|
.Case("rv740", "rv770")
|
|
|
|
.Case("palm", "cedar")
|
2013-05-07 00:12:05 +08:00
|
|
|
.Cases("sumo", "sumo2", "sumo")
|
2013-04-02 04:56:53 +08:00
|
|
|
.Case("hemlock", "cypress")
|
|
|
|
.Case("aruba", "cayman")
|
|
|
|
.Default(GPUName.c_str());
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clang::AddR600TargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
std::string TargetGPUName = getR600TargetGPU(Args);
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(TargetGPUName.c_str()));
|
|
|
|
}
|
|
|
|
|
2010-11-10 01:21:19 +08:00
|
|
|
void Clang::AddSparcTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-11-10 01:21:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select the float ABI as determined by -msoft-float, -mhard-float, and
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef FloatABI;
|
2010-11-10 01:21:19 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
|
|
|
|
options::OPT_mhard_float)) {
|
|
|
|
if (A->getOption().matches(options::OPT_msoft_float))
|
|
|
|
FloatABI = "soft";
|
|
|
|
else if (A->getOption().matches(options::OPT_mhard_float))
|
|
|
|
FloatABI = "hard";
|
|
|
|
}
|
|
|
|
|
|
|
|
// If unspecified, choose the default based on the platform.
|
|
|
|
if (FloatABI.empty()) {
|
|
|
|
switch (getToolChain().getTriple().getOS()) {
|
|
|
|
default:
|
|
|
|
// Assume "soft", but warn the user we are guessing.
|
|
|
|
FloatABI = "soft";
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_assuming_mfloat_abi_is) << "soft";
|
2010-11-10 01:21:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FloatABI == "soft") {
|
|
|
|
// Floating point operations and argument passing are soft.
|
|
|
|
//
|
|
|
|
// FIXME: This changes CPP defines, we need -target-soft-float.
|
|
|
|
CmdArgs.push_back("-msoft-float");
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+soft-float");
|
|
|
|
} else {
|
|
|
|
assert(FloatABI == "hard" && "Invalid float abi!");
|
|
|
|
CmdArgs.push_back("-mhard-float");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 19:46:33 +08:00
|
|
|
static const char *getX86TargetCPU(const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
|
|
|
if (StringRef(A->getValue()) != "native")
|
|
|
|
return A->getValue();
|
|
|
|
|
|
|
|
// FIXME: Reject attempts to use -march=native unless the target matches
|
|
|
|
// the host.
|
|
|
|
//
|
|
|
|
// FIXME: We should also incorporate the detected target features for use
|
|
|
|
// with -native.
|
|
|
|
std::string CPU = llvm::sys::getHostCPUName();
|
|
|
|
if (!CPU.empty() && CPU != "generic")
|
|
|
|
return Args.MakeArgString(CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the default CPU if none was given (or detection failed).
|
|
|
|
|
|
|
|
if (Triple.getArch() != llvm::Triple::x86_64 &&
|
|
|
|
Triple.getArch() != llvm::Triple::x86)
|
|
|
|
return 0; // This routine is only handling x86 targets.
|
|
|
|
|
|
|
|
bool Is64Bit = Triple.getArch() == llvm::Triple::x86_64;
|
|
|
|
|
|
|
|
// FIXME: Need target hooks.
|
|
|
|
if (Triple.isOSDarwin())
|
|
|
|
return Is64Bit ? "core2" : "yonah";
|
|
|
|
|
|
|
|
// Everything else goes to x86-64 in 64-bit mode.
|
|
|
|
if (Is64Bit)
|
|
|
|
return "x86-64";
|
|
|
|
|
|
|
|
if (Triple.getOSName().startswith("haiku"))
|
|
|
|
return "i586";
|
|
|
|
if (Triple.getOSName().startswith("openbsd"))
|
|
|
|
return "i486";
|
|
|
|
if (Triple.getOSName().startswith("bitrig"))
|
|
|
|
return "i686";
|
|
|
|
if (Triple.getOSName().startswith("freebsd"))
|
|
|
|
return "i486";
|
|
|
|
if (Triple.getOSName().startswith("netbsd"))
|
|
|
|
return "i486";
|
|
|
|
// All x86 devices running Android have core2 as their common
|
|
|
|
// denominator. This makes a better choice than pentium4.
|
|
|
|
if (Triple.getEnvironment() == llvm::Triple::Android)
|
|
|
|
return "core2";
|
|
|
|
|
|
|
|
// Fallback to p4.
|
|
|
|
return "pentium4";
|
|
|
|
}
|
|
|
|
|
2009-09-10 06:33:08 +08:00
|
|
|
void Clang::AddX86TargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-09-11 06:59:57 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_mred_zone,
|
|
|
|
options::OPT_mno_red_zone,
|
|
|
|
true) ||
|
|
|
|
Args.hasArg(options::OPT_mkernel) ||
|
|
|
|
Args.hasArg(options::OPT_fapple_kext))
|
2009-11-21 06:21:36 +08:00
|
|
|
CmdArgs.push_back("-disable-red-zone");
|
2009-09-11 06:59:57 +08:00
|
|
|
|
2013-02-11 00:01:41 +08:00
|
|
|
// Default to avoid implicit floating-point for kernel/kext code, but allow
|
|
|
|
// that to be overridden with -mno-soft-float.
|
|
|
|
bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) ||
|
|
|
|
Args.hasArg(options::OPT_fapple_kext));
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
|
|
|
|
options::OPT_mno_soft_float,
|
2013-04-12 02:53:25 +08:00
|
|
|
options::OPT_mimplicit_float,
|
2013-02-11 00:01:41 +08:00
|
|
|
options::OPT_mno_implicit_float)) {
|
|
|
|
const Option &O = A->getOption();
|
|
|
|
NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) ||
|
|
|
|
O.matches(options::OPT_msoft_float));
|
|
|
|
}
|
|
|
|
if (NoImplicitFloat)
|
2009-11-21 06:21:36 +08:00
|
|
|
CmdArgs.push_back("-no-implicit-float");
|
2009-09-11 06:59:57 +08:00
|
|
|
|
2013-01-13 19:46:33 +08:00
|
|
|
if (const char *CPUName = getX86TargetCPU(Args, getToolChain().getTriple())) {
|
2009-12-18 14:30:12 +08:00
|
|
|
CmdArgs.push_back("-target-cpu");
|
2009-11-15 06:04:54 +08:00
|
|
|
CmdArgs.push_back(CPUName);
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:34:19 +08:00
|
|
|
// The required algorithm here is slightly strange: the options are applied
|
|
|
|
// in order (so -mno-sse -msse2 disables SSE3), but any option that gets
|
|
|
|
// directly overridden later is ignored (so "-mno-sse -msse2 -mno-sse2 -msse"
|
|
|
|
// is equivalent to "-mno-sse2 -msse"). The -cc1 handling deals with the
|
|
|
|
// former correctly, but not the latter; handle directly-overridden
|
|
|
|
// attributes here.
|
|
|
|
llvm::StringMap<unsigned> PrevFeature;
|
|
|
|
std::vector<const char*> Features;
|
2009-11-25 19:53:23 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name = (*it)->getOption().getName();
|
2010-06-12 06:00:13 +08:00
|
|
|
(*it)->claim();
|
2009-09-10 06:33:08 +08:00
|
|
|
|
2009-11-25 19:53:23 +08:00
|
|
|
// Skip over "-m".
|
2012-10-23 06:13:48 +08:00
|
|
|
assert(Name.startswith("m") && "Invalid feature name.");
|
|
|
|
Name = Name.substr(1);
|
2009-09-10 06:33:08 +08:00
|
|
|
|
2009-11-25 19:53:23 +08:00
|
|
|
bool IsNegative = Name.startswith("no-");
|
|
|
|
if (IsNegative)
|
|
|
|
Name = Name.substr(3);
|
2009-09-10 06:33:08 +08:00
|
|
|
|
2011-07-02 08:34:19 +08:00
|
|
|
unsigned& Prev = PrevFeature[Name];
|
|
|
|
if (Prev)
|
|
|
|
Features[Prev - 1] = 0;
|
|
|
|
Prev = Features.size() + 1;
|
|
|
|
Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < Features.size(); i++) {
|
|
|
|
if (Features[i]) {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back(Features[i]);
|
|
|
|
}
|
2009-09-10 06:33:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:49:03 +08:00
|
|
|
static inline bool HasPICArg(const ArgList &Args) {
|
|
|
|
return Args.hasArg(options::OPT_fPIC)
|
|
|
|
|| Args.hasArg(options::OPT_fpic);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Arg *GetLastSmallDataThresholdArg(const ArgList &Args) {
|
|
|
|
return Args.getLastArg(options::OPT_G,
|
|
|
|
options::OPT_G_EQ,
|
|
|
|
options::OPT_msmall_data_threshold_EQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetHexagonSmallDataThresholdValue(const ArgList &Args) {
|
|
|
|
std::string value;
|
|
|
|
if (HasPICArg(Args))
|
|
|
|
value = "0";
|
|
|
|
else if (Arg *A = GetLastSmallDataThresholdArg(Args)) {
|
|
|
|
value = A->getValue();
|
|
|
|
A->claim();
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
void Clang::AddHexagonTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
llvm::Triple Triple = getToolChain().getTriple();
|
|
|
|
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
2012-12-06 22:16:43 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
"hexagon"
|
|
|
|
+ toolchains::Hexagon_TC::GetTargetCPU(Args)));
|
2011-12-13 05:14:55 +08:00
|
|
|
CmdArgs.push_back("-fno-signed-char");
|
2012-12-07 21:52:44 +08:00
|
|
|
CmdArgs.push_back("-mqdsp6-compat");
|
|
|
|
CmdArgs.push_back("-Wreturn-type");
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-07 01:49:03 +08:00
|
|
|
std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
|
|
|
|
if (!SmallDataThreshold.empty()) {
|
2011-12-13 05:14:55 +08:00
|
|
|
CmdArgs.push_back ("-mllvm");
|
2012-12-07 01:49:03 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
"-hexagon-small-data-threshold=" + SmallDataThreshold));
|
2011-12-13 05:14:55 +08:00
|
|
|
}
|
|
|
|
|
2012-05-11 04:19:54 +08:00
|
|
|
if (!Args.hasArg(options::OPT_fno_short_enums))
|
|
|
|
CmdArgs.push_back("-fshort-enums");
|
|
|
|
if (Args.getLastArg(options::OPT_mieee_rnd_near)) {
|
|
|
|
CmdArgs.push_back ("-mllvm");
|
|
|
|
CmdArgs.push_back ("-enable-hexagon-ieee-rnd-near");
|
|
|
|
}
|
2011-12-13 05:14:55 +08:00
|
|
|
CmdArgs.push_back ("-mllvm");
|
|
|
|
CmdArgs.push_back ("-machine-sink-split=0");
|
|
|
|
}
|
|
|
|
|
2011-08-19 08:30:14 +08:00
|
|
|
static bool
|
2012-06-20 14:18:46 +08:00
|
|
|
shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime,
|
2011-02-28 08:44:51 +08:00
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
// We use the zero-cost exception tables for Objective-C if the non-fragile
|
|
|
|
// ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and
|
|
|
|
// later.
|
2012-06-20 14:18:46 +08:00
|
|
|
if (runtime.isNonFragile())
|
2011-02-28 08:44:51 +08:00
|
|
|
return true;
|
|
|
|
|
2011-10-14 13:03:44 +08:00
|
|
|
if (!Triple.isOSDarwin())
|
2011-02-28 08:44:51 +08:00
|
|
|
return false;
|
|
|
|
|
2011-07-02 08:20:22 +08:00
|
|
|
return (!Triple.isMacOSXVersionLT(10,5) &&
|
2011-02-28 08:44:51 +08:00
|
|
|
(Triple.getArch() == llvm::Triple::x86_64 ||
|
2011-08-19 08:30:14 +08:00
|
|
|
Triple.getArch() == llvm::Triple::arm));
|
2011-02-28 08:44:51 +08:00
|
|
|
}
|
|
|
|
|
2011-02-28 10:27:16 +08:00
|
|
|
/// addExceptionArgs - Adds exception related arguments to the driver command
|
|
|
|
/// arguments. There's a master flag, -fexceptions and also language specific
|
|
|
|
/// flags to enable/disable C++ and Objective-C exceptions.
|
|
|
|
/// This makes it possible to for example disable C++ exceptions but enable
|
|
|
|
/// Objective-C exceptions.
|
|
|
|
static void addExceptionArgs(const ArgList &Args, types::ID InputType,
|
|
|
|
const llvm::Triple &Triple,
|
2012-04-05 02:28:00 +08:00
|
|
|
bool KernelOrKext,
|
2012-06-20 14:18:46 +08:00
|
|
|
const ObjCRuntime &objcRuntime,
|
2011-02-28 10:27:16 +08:00
|
|
|
ArgStringList &CmdArgs) {
|
2012-03-27 06:04:46 +08:00
|
|
|
if (KernelOrKext) {
|
|
|
|
// -mkernel and -fapple-kext imply no exceptions, so claim exception related
|
|
|
|
// arguments now to avoid warnings about unused arguments.
|
|
|
|
Args.ClaimAllArgs(options::OPT_fexceptions);
|
|
|
|
Args.ClaimAllArgs(options::OPT_fno_exceptions);
|
|
|
|
Args.ClaimAllArgs(options::OPT_fobjc_exceptions);
|
|
|
|
Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
|
|
|
|
Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
|
|
|
|
Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
|
2011-02-28 10:27:16 +08:00
|
|
|
return;
|
2012-03-27 06:04:46 +08:00
|
|
|
}
|
2011-02-28 10:27:16 +08:00
|
|
|
|
|
|
|
// Exceptions are enabled by default.
|
|
|
|
bool ExceptionsEnabled = true;
|
|
|
|
|
|
|
|
// This keeps track of whether exceptions were explicitly turned on or off.
|
|
|
|
bool DidHaveExplicitExceptionFlag = false;
|
|
|
|
|
2009-10-01 21:33:33 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
|
|
|
|
options::OPT_fno_exceptions)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fexceptions))
|
2011-02-28 10:27:16 +08:00
|
|
|
ExceptionsEnabled = true;
|
2011-08-19 08:30:14 +08:00
|
|
|
else
|
2011-02-28 10:27:16 +08:00
|
|
|
ExceptionsEnabled = false;
|
|
|
|
|
|
|
|
DidHaveExplicitExceptionFlag = true;
|
2009-10-01 21:33:33 +08:00
|
|
|
}
|
2010-09-15 07:12:31 +08:00
|
|
|
|
2011-02-28 10:27:16 +08:00
|
|
|
bool ShouldUseExceptionTables = false;
|
|
|
|
|
|
|
|
// Exception tables and cleanups can be enabled with -fexceptions even if the
|
|
|
|
// language itself doesn't support exceptions.
|
|
|
|
if (ExceptionsEnabled && DidHaveExplicitExceptionFlag)
|
|
|
|
ShouldUseExceptionTables = true;
|
|
|
|
|
2011-03-18 07:28:31 +08:00
|
|
|
// Obj-C exceptions are enabled by default, regardless of -fexceptions. This
|
|
|
|
// is not necessarily sensible, but follows GCC.
|
|
|
|
if (types::isObjC(InputType) &&
|
2011-08-19 08:30:14 +08:00
|
|
|
Args.hasFlag(options::OPT_fobjc_exceptions,
|
2011-03-18 07:28:31 +08:00
|
|
|
options::OPT_fno_objc_exceptions,
|
|
|
|
true)) {
|
|
|
|
CmdArgs.push_back("-fobjc-exceptions");
|
|
|
|
|
2011-08-19 08:30:14 +08:00
|
|
|
ShouldUseExceptionTables |=
|
2012-06-20 14:18:46 +08:00
|
|
|
shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple);
|
2011-02-28 10:27:16 +08:00
|
|
|
}
|
2009-10-02 04:30:46 +08:00
|
|
|
|
2011-02-28 10:27:16 +08:00
|
|
|
if (types::isCXX(InputType)) {
|
|
|
|
bool CXXExceptionsEnabled = ExceptionsEnabled;
|
2010-09-15 07:12:31 +08:00
|
|
|
|
2011-08-19 08:30:14 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions,
|
|
|
|
options::OPT_fno_cxx_exceptions,
|
2011-02-28 10:27:16 +08:00
|
|
|
options::OPT_fexceptions,
|
|
|
|
options::OPT_fno_exceptions)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fcxx_exceptions))
|
|
|
|
CXXExceptionsEnabled = true;
|
2011-02-28 15:25:18 +08:00
|
|
|
else if (A->getOption().matches(options::OPT_fno_cxx_exceptions))
|
2011-02-28 10:27:16 +08:00
|
|
|
CXXExceptionsEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CXXExceptionsEnabled) {
|
|
|
|
CmdArgs.push_back("-fcxx-exceptions");
|
|
|
|
|
|
|
|
ShouldUseExceptionTables = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldUseExceptionTables)
|
|
|
|
CmdArgs.push_back("-fexceptions");
|
2009-10-01 21:33:33 +08:00
|
|
|
}
|
|
|
|
|
2013-04-17 02:21:19 +08:00
|
|
|
static bool ShouldDisableAutolink(const ArgList &Args,
|
|
|
|
const ToolChain &TC) {
|
|
|
|
bool Default = true;
|
|
|
|
if (TC.getTriple().isOSDarwin()) {
|
|
|
|
// The native darwin assembler doesn't support the linker_option directives,
|
|
|
|
// so we disable them if we think the .s file will be passed to it.
|
|
|
|
Default = TC.useIntegratedAs();
|
|
|
|
}
|
|
|
|
return !Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
|
|
|
|
Default);
|
|
|
|
}
|
|
|
|
|
2011-05-03 01:43:32 +08:00
|
|
|
static bool ShouldDisableCFI(const ArgList &Args,
|
|
|
|
const ToolChain &TC) {
|
2012-03-08 22:39:55 +08:00
|
|
|
bool Default = true;
|
2011-10-14 13:03:44 +08:00
|
|
|
if (TC.getTriple().isOSDarwin()) {
|
2011-05-18 00:26:17 +08:00
|
|
|
// The native darwin assembler doesn't support cfi directives, so
|
2011-05-18 03:06:58 +08:00
|
|
|
// we disable them if we think the .s file will be passed to it.
|
2013-03-19 02:10:27 +08:00
|
|
|
Default = TC.useIntegratedAs();
|
2011-05-18 00:26:17 +08:00
|
|
|
}
|
2012-03-08 22:39:55 +08:00
|
|
|
return !Args.hasFlag(options::OPT_fdwarf2_cfi_asm,
|
2012-12-18 08:31:10 +08:00
|
|
|
options::OPT_fno_dwarf2_cfi_asm,
|
|
|
|
Default);
|
2011-05-03 01:43:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-13 01:02:12 +08:00
|
|
|
static bool ShouldDisableDwarfDirectory(const ArgList &Args,
|
|
|
|
const ToolChain &TC) {
|
2011-10-18 07:05:52 +08:00
|
|
|
bool UseDwarfDirectory = Args.hasFlag(options::OPT_fdwarf_directory_asm,
|
|
|
|
options::OPT_fno_dwarf_directory_asm,
|
2013-03-19 02:10:27 +08:00
|
|
|
TC.useIntegratedAs());
|
2011-10-18 07:05:52 +08:00
|
|
|
return !UseDwarfDirectory;
|
|
|
|
}
|
|
|
|
|
2011-05-06 22:35:16 +08:00
|
|
|
/// \brief Check whether the given input tree contains any compilation actions.
|
|
|
|
static bool ContainsCompileAction(const Action *A) {
|
2011-07-23 18:55:15 +08:00
|
|
|
if (isa<CompileJobAction>(A))
|
2011-05-06 22:35:16 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it)
|
|
|
|
if (ContainsCompileAction(*it))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Check if -relax-all should be passed to the internal assembler.
|
|
|
|
/// This is done by default when compiling non-assembler source with -O0.
|
|
|
|
static bool UseRelaxAll(Compilation &C, const ArgList &Args) {
|
|
|
|
bool RelaxDefault = true;
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
RelaxDefault = A->getOption().matches(options::OPT_O0);
|
|
|
|
|
|
|
|
if (RelaxDefault) {
|
|
|
|
RelaxDefault = false;
|
|
|
|
for (ActionList::const_iterator it = C.getActions().begin(),
|
|
|
|
ie = C.getActions().end(); it != ie; ++it) {
|
|
|
|
if (ContainsCompileAction(*it)) {
|
|
|
|
RelaxDefault = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all,
|
|
|
|
RelaxDefault);
|
|
|
|
}
|
|
|
|
|
2013-04-09 12:35:11 +08:00
|
|
|
SanitizerArgs::SanitizerArgs(const ToolChain &TC, const ArgList &Args)
|
2013-01-20 21:12:12 +08:00
|
|
|
: Kind(0), BlacklistFile(""), MsanTrackOrigins(false),
|
|
|
|
AsanZeroBaseShadow(false) {
|
2013-01-28 15:20:44 +08:00
|
|
|
unsigned AllKinds = 0; // All kinds of sanitizers that were turned on
|
|
|
|
// at least once (possibly, disabled further).
|
2013-04-09 12:35:11 +08:00
|
|
|
const Driver &D = TC.getDriver();
|
2012-11-06 06:04:41 +08:00
|
|
|
for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I) {
|
2012-11-29 01:34:24 +08:00
|
|
|
unsigned Add, Remove;
|
|
|
|
if (!parse(D, Args, *I, Add, Remove, true))
|
2012-11-06 06:04:41 +08:00
|
|
|
continue;
|
|
|
|
(*I)->claim();
|
2012-11-06 23:09:03 +08:00
|
|
|
Kind |= Add;
|
|
|
|
Kind &= ~Remove;
|
2013-01-28 15:20:44 +08:00
|
|
|
AllKinds |= Add;
|
2012-11-06 06:04:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-30 07:31:22 +08:00
|
|
|
UbsanTrapOnError =
|
|
|
|
Args.hasArg(options::OPT_fcatch_undefined_behavior) ||
|
|
|
|
Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error,
|
|
|
|
options::OPT_fno_sanitize_undefined_trap_on_error, false);
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fcatch_undefined_behavior) &&
|
|
|
|
!Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error,
|
|
|
|
options::OPT_fno_sanitize_undefined_trap_on_error, true)) {
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< "-fcatch-undefined-behavior"
|
|
|
|
<< "-fno-sanitize-undefined-trap-on-error";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warn about undefined sanitizer options that require runtime support.
|
|
|
|
if (UbsanTrapOnError && notAllowedWithTrap()) {
|
|
|
|
if (Args.hasArg(options::OPT_fcatch_undefined_behavior))
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NotAllowedWithTrap)
|
|
|
|
<< "-fcatch-undefined-behavior";
|
|
|
|
else if (Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error,
|
|
|
|
options::OPT_fno_sanitize_undefined_trap_on_error,
|
|
|
|
false))
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NotAllowedWithTrap)
|
|
|
|
<< "-fsanitize-undefined-trap-on-error";
|
|
|
|
}
|
|
|
|
|
2012-11-06 06:04:41 +08:00
|
|
|
// Only one runtime library can be used at once.
|
2012-11-06 23:09:03 +08:00
|
|
|
bool NeedsAsan = needsAsanRt();
|
|
|
|
bool NeedsTsan = needsTsanRt();
|
2012-12-05 21:37:12 +08:00
|
|
|
bool NeedsMsan = needsMsanRt();
|
2013-05-27 19:17:01 +08:00
|
|
|
bool NeedsLsan = needsLeakDetection();
|
2012-12-01 09:02:45 +08:00
|
|
|
if (NeedsAsan && NeedsTsan)
|
2012-11-06 06:04:41 +08:00
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
2012-12-01 09:02:45 +08:00
|
|
|
<< lastArgumentForKind(D, Args, NeedsAsanRt)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsTsanRt);
|
2012-12-05 21:37:12 +08:00
|
|
|
if (NeedsAsan && NeedsMsan)
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsAsanRt)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsMsanRt);
|
|
|
|
if (NeedsTsan && NeedsMsan)
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsTsanRt)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsMsanRt);
|
2013-05-27 19:17:01 +08:00
|
|
|
if (NeedsLsan && NeedsTsan)
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsLeakDetection)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsTsanRt);
|
|
|
|
if (NeedsLsan && NeedsMsan)
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsLeakDetection)
|
|
|
|
<< lastArgumentForKind(D, Args, NeedsMsanRt);
|
|
|
|
// FIXME: Currenly -fsanitize=leak is silently ignored in the presence of
|
|
|
|
// -fsanitize=address. Perhaps it should print an error, or perhaps
|
|
|
|
// -f(-no)sanitize=leak should change whether leak detection is enabled by
|
|
|
|
// default in ASan?
|
2012-11-30 06:36:21 +08:00
|
|
|
|
|
|
|
// If -fsanitize contains extra features of ASan, it should also
|
2013-01-28 15:20:44 +08:00
|
|
|
// explicitly contain -fsanitize=address (probably, turned off later in the
|
|
|
|
// command line).
|
|
|
|
if ((Kind & AddressFull) != 0 && (AllKinds & Address) == 0)
|
|
|
|
D.Diag(diag::warn_drv_unused_sanitizer)
|
|
|
|
<< lastArgumentForKind(D, Args, AddressFull)
|
|
|
|
<< "-fsanitize=address";
|
2012-12-04 03:12:58 +08:00
|
|
|
|
|
|
|
// Parse -f(no-)sanitize-blacklist options.
|
|
|
|
if (Arg *BLArg = Args.getLastArg(options::OPT_fsanitize_blacklist,
|
|
|
|
options::OPT_fno_sanitize_blacklist)) {
|
|
|
|
if (BLArg->getOption().matches(options::OPT_fsanitize_blacklist)) {
|
|
|
|
std::string BLPath = BLArg->getValue();
|
2013-06-25 22:48:00 +08:00
|
|
|
if (llvm::sys::fs::exists(BLPath))
|
2012-12-04 03:12:58 +08:00
|
|
|
BlacklistFile = BLPath;
|
|
|
|
else
|
|
|
|
D.Diag(diag::err_drv_no_such_file) << BLPath;
|
|
|
|
}
|
2013-02-19 19:25:29 +08:00
|
|
|
} else {
|
|
|
|
// If no -fsanitize-blacklist option is specified, try to look up for
|
|
|
|
// blacklist in the resource directory.
|
|
|
|
std::string BLPath;
|
|
|
|
if (getDefaultBlacklistForKind(D, Kind, BLPath) &&
|
2013-06-25 22:48:00 +08:00
|
|
|
llvm::sys::fs::exists(BLPath))
|
2013-02-19 19:25:29 +08:00
|
|
|
BlacklistFile = BLPath;
|
2012-12-04 03:12:58 +08:00
|
|
|
}
|
2012-12-24 16:42:34 +08:00
|
|
|
|
|
|
|
// Parse -f(no-)sanitize-memory-track-origins options.
|
2013-01-20 21:12:12 +08:00
|
|
|
if (NeedsMsan)
|
2012-12-24 16:42:34 +08:00
|
|
|
MsanTrackOrigins =
|
|
|
|
Args.hasFlag(options::OPT_fsanitize_memory_track_origins,
|
|
|
|
options::OPT_fno_sanitize_memory_track_origins,
|
|
|
|
/* Default */false);
|
2013-01-20 21:12:12 +08:00
|
|
|
|
|
|
|
// Parse -f(no-)sanitize-address-zero-base-shadow options.
|
2013-04-09 15:27:44 +08:00
|
|
|
if (NeedsAsan) {
|
|
|
|
bool IsAndroid = (TC.getTriple().getEnvironment() == llvm::Triple::Android);
|
|
|
|
bool ZeroBaseShadowDefault = IsAndroid;
|
2013-01-20 21:12:12 +08:00
|
|
|
AsanZeroBaseShadow =
|
2013-04-09 15:27:44 +08:00
|
|
|
Args.hasFlag(options::OPT_fsanitize_address_zero_base_shadow,
|
|
|
|
options::OPT_fno_sanitize_address_zero_base_shadow,
|
|
|
|
ZeroBaseShadowDefault);
|
|
|
|
// Zero-base shadow is a requirement on Android.
|
|
|
|
if (IsAndroid && !AsanZeroBaseShadow) {
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< "-fno-sanitize-address-zero-base-shadow"
|
|
|
|
<< lastArgumentForKind(D, Args, Address);
|
|
|
|
}
|
|
|
|
}
|
2012-11-06 06:04:41 +08:00
|
|
|
}
|
|
|
|
|
2013-06-23 19:28:48 +08:00
|
|
|
static void addProfileRTLinux(
|
|
|
|
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
|
|
|
|
if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_generate) ||
|
|
|
|
Args.hasArg(options::OPT_fcreate_profile) ||
|
|
|
|
Args.hasArg(options::OPT_coverage)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The profile runtime is located in the Linux library directory and has name
|
|
|
|
// "libclang_rt.profile-<ArchName>.a".
|
|
|
|
SmallString<128> LibProfile(TC.getDriver().ResourceDir);
|
|
|
|
llvm::sys::path::append(
|
|
|
|
LibProfile, "lib", "linux",
|
|
|
|
Twine("libclang_rt.profile-") + TC.getArchName() + ".a");
|
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibProfile));
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:14:55 +08:00
|
|
|
static void addSanitizerRTLinkFlagsLinux(
|
|
|
|
const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs,
|
2013-03-23 08:30:08 +08:00
|
|
|
const StringRef Sanitizer, bool BeforeLibStdCXX,
|
|
|
|
bool ExportSymbols = true) {
|
2013-02-27 19:14:55 +08:00
|
|
|
// Sanitizer runtime is located in the Linux library directory and
|
|
|
|
// has name "libclang_rt.<Sanitizer>-<ArchName>.a".
|
|
|
|
SmallString<128> LibSanitizer(TC.getDriver().ResourceDir);
|
|
|
|
llvm::sys::path::append(
|
|
|
|
LibSanitizer, "lib", "linux",
|
|
|
|
(Twine("libclang_rt.") + Sanitizer + "-" + TC.getArchName() + ".a"));
|
2013-03-21 07:49:07 +08:00
|
|
|
|
2013-02-27 19:14:55 +08:00
|
|
|
// Sanitizer runtime may need to come before -lstdc++ (or -lc++, libstdc++.a,
|
|
|
|
// etc.) so that the linker picks custom versions of the global 'operator
|
|
|
|
// new' and 'operator delete' symbols. We take the extreme (but simple)
|
|
|
|
// strategy of inserting it at the front of the link command. It also
|
|
|
|
// needs to be forced to end up in the executable, so wrap it in
|
|
|
|
// whole-archive.
|
2013-03-21 07:49:07 +08:00
|
|
|
SmallVector<const char *, 3> LibSanitizerArgs;
|
|
|
|
LibSanitizerArgs.push_back("-whole-archive");
|
|
|
|
LibSanitizerArgs.push_back(Args.MakeArgString(LibSanitizer));
|
|
|
|
LibSanitizerArgs.push_back("-no-whole-archive");
|
|
|
|
|
|
|
|
CmdArgs.insert(BeforeLibStdCXX ? CmdArgs.begin() : CmdArgs.end(),
|
|
|
|
LibSanitizerArgs.begin(), LibSanitizerArgs.end());
|
|
|
|
|
2013-02-27 19:14:55 +08:00
|
|
|
CmdArgs.push_back("-lpthread");
|
2013-05-24 22:28:03 +08:00
|
|
|
CmdArgs.push_back("-lrt");
|
2013-02-27 19:14:55 +08:00
|
|
|
CmdArgs.push_back("-ldl");
|
2013-03-23 08:30:08 +08:00
|
|
|
|
|
|
|
// If possible, use a dynamic symbols file to export the symbols from the
|
|
|
|
// runtime library. If we can't do so, use -export-dynamic instead to export
|
|
|
|
// all symbols from the binary.
|
|
|
|
if (ExportSymbols) {
|
|
|
|
if (llvm::sys::fs::exists(LibSanitizer + ".syms"))
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString("--dynamic-list=" + LibSanitizer + ".syms"));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
|
|
|
}
|
2013-02-27 19:14:55 +08:00
|
|
|
}
|
|
|
|
|
2011-11-30 09:39:16 +08:00
|
|
|
/// If AddressSanitizer is enabled, add appropriate linker flags (Linux).
|
|
|
|
/// This needs to be called before we add the C run-time (malloc, etc).
|
|
|
|
static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
2011-12-07 03:18:44 +08:00
|
|
|
ArgStringList &CmdArgs) {
|
2012-09-02 17:30:11 +08:00
|
|
|
if(TC.getTriple().getEnvironment() == llvm::Triple::Android) {
|
2012-09-12 17:09:08 +08:00
|
|
|
SmallString<128> LibAsan(TC.getDriver().ResourceDir);
|
|
|
|
llvm::sys::path::append(LibAsan, "lib", "linux",
|
|
|
|
(Twine("libclang_rt.asan-") +
|
|
|
|
TC.getArchName() + "-android.so"));
|
2012-12-05 05:18:26 +08:00
|
|
|
CmdArgs.insert(CmdArgs.begin(), Args.MakeArgString(LibAsan));
|
2012-04-25 16:59:22 +08:00
|
|
|
} else {
|
2013-05-27 19:17:01 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2013-02-27 19:14:55 +08:00
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "asan", true);
|
2012-04-25 16:59:22 +08:00
|
|
|
}
|
2011-11-30 09:39:16 +08:00
|
|
|
}
|
|
|
|
|
2012-05-16 14:36:00 +08:00
|
|
|
/// If ThreadSanitizer is enabled, add appropriate linker flags (Linux).
|
|
|
|
/// This needs to be called before we add the C run-time (malloc, etc).
|
|
|
|
static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) {
|
2013-05-27 19:17:01 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2013-02-27 19:14:55 +08:00
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "tsan", true);
|
2012-05-16 14:36:00 +08:00
|
|
|
}
|
|
|
|
|
2012-12-03 21:20:43 +08:00
|
|
|
/// If MemorySanitizer is enabled, add appropriate linker flags (Linux).
|
|
|
|
/// This needs to be called before we add the C run-time (malloc, etc).
|
|
|
|
static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) {
|
2013-05-27 19:17:01 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2013-02-27 19:14:55 +08:00
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "msan", true);
|
2013-05-27 19:17:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If LeakSanitizer is enabled, add appropriate linker flags (Linux).
|
|
|
|
/// This needs to be called before we add the C run-time (malloc, etc).
|
|
|
|
static void addLsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "lsan", true);
|
2012-12-03 21:20:43 +08:00
|
|
|
}
|
|
|
|
|
2012-10-10 03:52:38 +08:00
|
|
|
/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags
|
|
|
|
/// (Linux).
|
|
|
|
static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
2013-03-21 07:49:07 +08:00
|
|
|
ArgStringList &CmdArgs, bool IsCXX,
|
|
|
|
bool HasOtherSanitizerRt) {
|
|
|
|
if (Args.hasArg(options::OPT_shared))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Need a copy of sanitizer_common. This could come from another sanitizer
|
|
|
|
// runtime; if we're not including one, include our own copy.
|
|
|
|
if (!HasOtherSanitizerRt)
|
2013-03-23 08:30:08 +08:00
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "san", true, false);
|
2013-03-21 07:49:07 +08:00
|
|
|
|
2013-02-27 19:14:55 +08:00
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "ubsan", false);
|
2013-03-21 07:49:07 +08:00
|
|
|
|
|
|
|
// Only include the bits of the runtime which need a C++ ABI library if
|
|
|
|
// we're linking in C++ mode.
|
|
|
|
if (IsCXX)
|
|
|
|
addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "ubsan_cxx", false);
|
2012-10-10 03:52:38 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 05:02:23 +08:00
|
|
|
static bool shouldUseFramePointer(const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
|
|
|
|
options::OPT_fomit_frame_pointer))
|
|
|
|
return A->getOption().matches(options::OPT_fno_omit_frame_pointer);
|
|
|
|
|
2011-12-15 05:50:24 +08:00
|
|
|
// Don't use a frame pointer on linux x86 and x86_64 if optimizing.
|
2011-12-15 05:02:23 +08:00
|
|
|
if ((Triple.getArch() == llvm::Triple::x86_64 ||
|
|
|
|
Triple.getArch() == llvm::Triple::x86) &&
|
|
|
|
Triple.getOS() == llvm::Triple::Linux) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
if (!A->getOption().matches(options::OPT_O0))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-03 09:58:53 +08:00
|
|
|
static bool shouldUseLeafFramePointer(const ArgList &Args,
|
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer,
|
|
|
|
options::OPT_momit_leaf_frame_pointer))
|
|
|
|
return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
|
|
|
|
|
|
|
|
// Don't use a leaf frame pointer on linux x86 and x86_64 if optimizing.
|
|
|
|
if ((Triple.getArch() == llvm::Triple::x86_64 ||
|
|
|
|
Triple.getArch() == llvm::Triple::x86) &&
|
|
|
|
Triple.getOS() == llvm::Triple::Linux) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
if (!A->getOption().matches(options::OPT_O0))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-18 05:40:04 +08:00
|
|
|
/// If the PWD environment variable is set, add a CC1 option to specify the
|
|
|
|
/// debug compilation directory.
|
|
|
|
static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
|
2013-04-27 04:49:50 +08:00
|
|
|
struct stat StatPWDBuf, StatDotBuf;
|
|
|
|
|
2013-04-27 16:42:33 +08:00
|
|
|
const char *pwd = ::getenv("PWD");
|
|
|
|
if (!pwd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (llvm::sys::path::is_absolute(pwd) &&
|
2013-04-27 04:49:50 +08:00
|
|
|
stat(pwd, &StatPWDBuf) == 0 &&
|
|
|
|
stat(".", &StatDotBuf) == 0 &&
|
|
|
|
StatPWDBuf.st_ino == StatDotBuf.st_ino &&
|
|
|
|
StatPWDBuf.st_dev == StatDotBuf.st_dev) {
|
|
|
|
CmdArgs.push_back("-fdebug-compilation-dir");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(pwd));
|
|
|
|
return;
|
|
|
|
}
|
2013-04-27 16:12:29 +08:00
|
|
|
|
2013-04-27 04:49:50 +08:00
|
|
|
// Fall back to using getcwd.
|
2013-04-27 16:12:29 +08:00
|
|
|
SmallString<128> cwd;
|
|
|
|
if (!llvm::sys::fs::current_path(cwd)) {
|
2013-04-27 04:49:50 +08:00
|
|
|
CmdArgs.push_back("-fdebug-compilation-dir");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(cwd));
|
2012-12-18 05:40:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 04:12:52 +08:00
|
|
|
static const char *SplitDebugName(const ArgList &Args,
|
|
|
|
const InputInfoList &Inputs) {
|
|
|
|
Arg *FinalOutput = Args.getLastArg(options::OPT_o);
|
|
|
|
if (FinalOutput && Args.hasArg(options::OPT_c)) {
|
|
|
|
SmallString<128> T(FinalOutput->getValue());
|
|
|
|
llvm::sys::path::replace_extension(T, "dwo");
|
|
|
|
return Args.MakeArgString(T);
|
|
|
|
} else {
|
|
|
|
// Use the compilation dir.
|
|
|
|
SmallString<128> T(Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
|
|
|
|
SmallString<128> F(llvm::sys::path::stem(Inputs[0].getBaseInput()));
|
|
|
|
llvm::sys::path::replace_extension(F, "dwo");
|
|
|
|
T += F;
|
|
|
|
return Args.MakeArgString(F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SplitDebugInfo(const ToolChain &TC, Compilation &C,
|
|
|
|
const Tool &T, const JobAction &JA,
|
|
|
|
const ArgList &Args, const InputInfo &Output,
|
|
|
|
const char *OutFile) {
|
2013-02-22 06:35:01 +08:00
|
|
|
ArgStringList ExtractArgs;
|
|
|
|
ExtractArgs.push_back("--extract-dwo");
|
|
|
|
|
|
|
|
ArgStringList StripArgs;
|
|
|
|
StripArgs.push_back("--strip-dwo");
|
|
|
|
|
|
|
|
// Grabbing the output of the earlier compile step.
|
|
|
|
StripArgs.push_back(Output.getFilename());
|
|
|
|
ExtractArgs.push_back(Output.getFilename());
|
|
|
|
ExtractArgs.push_back(OutFile);
|
|
|
|
|
|
|
|
const char *Exec =
|
2013-02-23 04:12:52 +08:00
|
|
|
Args.MakeArgString(TC.GetProgramPath("objcopy"));
|
2013-02-22 06:35:01 +08:00
|
|
|
|
|
|
|
// First extract the dwo sections.
|
2013-02-23 04:12:52 +08:00
|
|
|
C.addCommand(new Command(JA, T, Exec, ExtractArgs));
|
2013-02-22 06:35:01 +08:00
|
|
|
|
|
|
|
// Then remove them from the original .o file.
|
2013-02-23 04:12:52 +08:00
|
|
|
C.addCommand(new Command(JA, T, Exec, StripArgs));
|
2013-02-22 06:35:01 +08:00
|
|
|
}
|
|
|
|
|
2013-04-25 02:09:54 +08:00
|
|
|
static bool isOptimizationLevelFast(const ArgList &Args) {
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
if (A->getOption().matches(options::OPT_Ofast))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-18 14:00:36 +08:00
|
|
|
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
2009-03-18 15:06:02 +08:00
|
|
|
const InputInfo &Output,
|
2009-03-18 14:07:59 +08:00
|
|
|
const InputInfoList &Inputs,
|
2009-03-18 18:01:51 +08:00
|
|
|
const ArgList &Args,
|
2009-03-18 14:00:36 +08:00
|
|
|
const char *LinkingOutput) const {
|
2010-03-20 12:52:14 +08:00
|
|
|
bool KernelOrKext = Args.hasArg(options::OPT_mkernel,
|
|
|
|
options::OPT_fapple_kext);
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-03-18 16:07:30 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2009-04-01 04:53:55 +08:00
|
|
|
assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
|
|
|
|
|
2009-12-12 07:00:49 +08:00
|
|
|
// Invoke ourselves in -cc1 mode.
|
|
|
|
//
|
|
|
|
// FIXME: Implement custom jobs for internal actions.
|
|
|
|
CmdArgs.push_back("-cc1");
|
|
|
|
|
2009-10-31 02:12:20 +08:00
|
|
|
// Add the "effective" target triple.
|
2009-04-01 01:35:15 +08:00
|
|
|
CmdArgs.push_back("-triple");
|
2010-08-24 06:35:37 +08:00
|
|
|
std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
|
2009-10-31 02:12:20 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(TripleStr));
|
2009-09-10 14:49:20 +08:00
|
|
|
|
2009-10-31 02:12:20 +08:00
|
|
|
// Select the appropriate action.
|
2012-06-20 14:18:46 +08:00
|
|
|
RewriteKind rewriteKind = RK_None;
|
2012-04-05 02:50:28 +08:00
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
if (isa<AnalyzeJobAction>(JA)) {
|
|
|
|
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
|
|
|
|
CmdArgs.push_back("-analyze");
|
2012-03-07 04:06:33 +08:00
|
|
|
} else if (isa<MigrateJobAction>(JA)) {
|
|
|
|
CmdArgs.push_back("-migrate");
|
2009-03-18 18:01:51 +08:00
|
|
|
} else if (isa<PreprocessJobAction>(JA)) {
|
2009-03-30 14:36:42 +08:00
|
|
|
if (Output.getType() == types::TY_Dependencies)
|
|
|
|
CmdArgs.push_back("-Eonly");
|
2013-03-19 03:41:18 +08:00
|
|
|
else {
|
2009-03-30 14:36:42 +08:00
|
|
|
CmdArgs.push_back("-E");
|
2013-03-19 03:41:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_rewrite_objc) &&
|
|
|
|
!Args.hasArg(options::OPT_g_Group))
|
|
|
|
CmdArgs.push_back("-P");
|
|
|
|
}
|
2010-02-03 11:07:56 +08:00
|
|
|
} else if (isa<AssembleJobAction>(JA)) {
|
|
|
|
CmdArgs.push_back("-emit-obj");
|
2010-05-27 14:18:05 +08:00
|
|
|
|
2011-05-06 22:35:16 +08:00
|
|
|
if (UseRelaxAll(C, Args))
|
2010-05-27 14:18:05 +08:00
|
|
|
CmdArgs.push_back("-mrelax-all");
|
2010-08-25 00:47:49 +08:00
|
|
|
|
2010-10-19 06:36:15 +08:00
|
|
|
// When using an integrated assembler, translate -Wa, and -Xassembler
|
|
|
|
// options.
|
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
A->claim();
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef Value = A->getValue(i);
|
2010-10-19 06:36:15 +08:00
|
|
|
|
|
|
|
if (Value == "-force_cpusubtype_ALL") {
|
|
|
|
// Do nothing, this is the default and we don't support anything else.
|
2010-10-29 04:36:23 +08:00
|
|
|
} else if (Value == "-L") {
|
2011-03-29 06:49:28 +08:00
|
|
|
CmdArgs.push_back("-msave-temp-labels");
|
2011-05-20 04:46:39 +08:00
|
|
|
} else if (Value == "--fatal-warnings") {
|
2011-05-20 02:42:29 +08:00
|
|
|
CmdArgs.push_back("-mllvm");
|
|
|
|
CmdArgs.push_back("-fatal-assembler-warnings");
|
2011-06-21 08:14:18 +08:00
|
|
|
} else if (Value == "--noexecstack") {
|
|
|
|
CmdArgs.push_back("-mnoexecstack");
|
2010-10-19 06:36:15 +08:00
|
|
|
} else {
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_unsupported_option_argument)
|
2010-10-19 06:36:15 +08:00
|
|
|
<< A->getOption().getName() << Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-20 00:23:35 +08:00
|
|
|
|
|
|
|
// Also ignore explicit -force_cpusubtype_ALL option.
|
|
|
|
(void) Args.hasArg(options::OPT_force__cpusubtype__ALL);
|
2009-03-18 18:01:51 +08:00
|
|
|
} else if (isa<PrecompileJobAction>(JA)) {
|
2010-08-12 07:27:58 +08:00
|
|
|
// Use PCH if the user requested it.
|
2009-10-16 04:02:44 +08:00
|
|
|
bool UsePCH = D.CCCUsePCH;
|
|
|
|
|
2012-07-31 09:21:00 +08:00
|
|
|
if (JA.getType() == types::TY_Nothing)
|
|
|
|
CmdArgs.push_back("-fsyntax-only");
|
|
|
|
else if (UsePCH)
|
2009-04-18 08:34:01 +08:00
|
|
|
CmdArgs.push_back("-emit-pch");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-emit-pth");
|
2009-03-18 18:01:51 +08:00
|
|
|
} else {
|
|
|
|
assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool.");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
if (JA.getType() == types::TY_Nothing) {
|
|
|
|
CmdArgs.push_back("-fsyntax-only");
|
2010-06-08 07:28:45 +08:00
|
|
|
} else if (JA.getType() == types::TY_LLVM_IR ||
|
|
|
|
JA.getType() == types::TY_LTO_IR) {
|
2009-03-18 18:01:51 +08:00
|
|
|
CmdArgs.push_back("-emit-llvm");
|
2010-06-08 07:28:45 +08:00
|
|
|
} else if (JA.getType() == types::TY_LLVM_BC ||
|
|
|
|
JA.getType() == types::TY_LTO_BC) {
|
2009-03-18 18:01:51 +08:00
|
|
|
CmdArgs.push_back("-emit-llvm-bc");
|
|
|
|
} else if (JA.getType() == types::TY_PP_Asm) {
|
2009-09-17 08:47:53 +08:00
|
|
|
CmdArgs.push_back("-S");
|
2009-09-02 00:57:46 +08:00
|
|
|
} else if (JA.getType() == types::TY_AST) {
|
|
|
|
CmdArgs.push_back("-emit-pch");
|
2013-03-28 00:47:18 +08:00
|
|
|
} else if (JA.getType() == types::TY_ModuleFile) {
|
|
|
|
CmdArgs.push_back("-module-file-info");
|
2010-02-11 11:16:21 +08:00
|
|
|
} else if (JA.getType() == types::TY_RewrittenObjC) {
|
|
|
|
CmdArgs.push_back("-rewrite-objc");
|
2012-06-20 14:18:46 +08:00
|
|
|
rewriteKind = RK_NonFragile;
|
2012-04-02 23:59:19 +08:00
|
|
|
} else if (JA.getType() == types::TY_RewrittenLegacyObjC) {
|
|
|
|
CmdArgs.push_back("-rewrite-objc");
|
2012-06-20 14:18:46 +08:00
|
|
|
rewriteKind = RK_Fragile;
|
2010-02-11 11:16:21 +08:00
|
|
|
} else {
|
|
|
|
assert(JA.getType() == types::TY_PP_Asm &&
|
|
|
|
"Unexpected output type!");
|
2009-03-18 18:01:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The make clang go fast button.
|
|
|
|
CmdArgs.push_back("-disable-free");
|
|
|
|
|
2010-02-13 11:50:24 +08:00
|
|
|
// Disable the verification pass in -asserts builds.
|
|
|
|
#ifdef NDEBUG
|
|
|
|
CmdArgs.push_back("-disable-llvm-verifier");
|
|
|
|
#endif
|
|
|
|
|
2009-04-08 13:11:16 +08:00
|
|
|
// Set the main file name, so that debug info works even with
|
|
|
|
// -save-temps.
|
|
|
|
CmdArgs.push_back("-main-file-name");
|
2012-11-23 14:14:39 +08:00
|
|
|
CmdArgs.push_back(getBaseInputName(Args, Inputs));
|
2009-04-08 13:11:16 +08:00
|
|
|
|
2009-04-09 02:03:55 +08:00
|
|
|
// Some flags which affect the language (via preprocessor
|
2012-11-23 14:14:39 +08:00
|
|
|
// defines).
|
2009-04-09 02:03:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_static))
|
|
|
|
CmdArgs.push_back("-static-define");
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
if (isa<AnalyzeJobAction>(JA)) {
|
2009-09-25 13:55:59 +08:00
|
|
|
// Enable region store model by default.
|
|
|
|
CmdArgs.push_back("-analyzer-store=region");
|
|
|
|
|
2009-12-08 06:26:14 +08:00
|
|
|
// Treat blocks as analysis entry points.
|
|
|
|
CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
|
|
|
|
|
2011-03-24 08:28:47 +08:00
|
|
|
CmdArgs.push_back("-analyzer-eagerly-assume");
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
// Add default argument set.
|
2009-05-22 08:38:15 +08:00
|
|
|
if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
|
2011-02-15 15:42:33 +08:00
|
|
|
CmdArgs.push_back("-analyzer-checker=core");
|
2011-03-24 08:28:47 +08:00
|
|
|
|
2011-02-15 15:42:33 +08:00
|
|
|
if (getToolChain().getTriple().getOS() != llvm::Triple::Win32)
|
|
|
|
CmdArgs.push_back("-analyzer-checker=unix");
|
|
|
|
|
2011-03-24 08:28:47 +08:00
|
|
|
if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple)
|
|
|
|
CmdArgs.push_back("-analyzer-checker=osx");
|
2012-01-20 14:00:17 +08:00
|
|
|
|
|
|
|
CmdArgs.push_back("-analyzer-checker=deadcode");
|
2012-01-26 10:27:38 +08:00
|
|
|
|
2013-04-06 01:55:07 +08:00
|
|
|
if (types::isCXX(Inputs[0].getType()))
|
|
|
|
CmdArgs.push_back("-analyzer-checker=cplusplus");
|
|
|
|
|
2012-01-26 10:27:38 +08:00
|
|
|
// Enable the following experimental checkers for testing.
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.UncheckedReturn");
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.getpw");
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.gets");
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp");
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mkstemp");
|
|
|
|
CmdArgs.push_back("-analyzer-checker=security.insecureAPI.vfork");
|
2009-05-22 08:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the output format. The default is plist, for (lame) historical
|
|
|
|
// reasons.
|
|
|
|
CmdArgs.push_back("-analyzer-output");
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-05-22 08:38:15 +08:00
|
|
|
else
|
|
|
|
CmdArgs.push_back("plist");
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2010-03-23 06:32:05 +08:00
|
|
|
// Disable the presentation of standard compiler warnings when
|
|
|
|
// using --analyze. We only want to show static analyzer diagnostics
|
|
|
|
// or frontend errors.
|
|
|
|
CmdArgs.push_back("-w");
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
// Add -Xanalyzer arguments when running as analyzer.
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2009-09-10 09:21:12 +08:00
|
|
|
CheckCodeGenerationOptions(D, Args);
|
|
|
|
|
2013-04-09 12:35:11 +08:00
|
|
|
bool PIE = getToolChain().isPIEDefault();
|
|
|
|
bool PIC = PIE || getToolChain().isPICDefault();
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
bool IsPICLevelTwo = PIC;
|
2013-04-09 12:35:11 +08:00
|
|
|
|
2013-04-09 20:28:19 +08:00
|
|
|
// For the PIC and PIE flag options, this logic is different from the
|
|
|
|
// legacy logic in very old versions of GCC, as that logic was just
|
|
|
|
// a bug no one had ever fixed. This logic is both more rational and
|
|
|
|
// consistent with GCC's new logic now that the bugs are fixed. The last
|
|
|
|
// argument relating to either PIC or PIE wins, and no other argument is
|
|
|
|
// used. If the last argument is any flavor of the '-fno-...' arguments,
|
|
|
|
// both PIC and PIE are disabled. Any PIE option implicitly enables PIC
|
|
|
|
// at the same level.
|
|
|
|
Arg *LastPICArg =Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
|
|
|
|
options::OPT_fpic, options::OPT_fno_pic,
|
|
|
|
options::OPT_fPIE, options::OPT_fno_PIE,
|
|
|
|
options::OPT_fpie, options::OPT_fno_pie);
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
// Check whether the tool chain trumps the PIC-ness decision. If the PIC-ness
|
|
|
|
// is forced, then neither PIC nor PIE flags will have no effect.
|
2013-04-09 12:35:11 +08:00
|
|
|
if (!getToolChain().isPICDefaultForced()) {
|
2013-04-09 20:28:19 +08:00
|
|
|
if (LastPICArg) {
|
|
|
|
Option O = LastPICArg->getOption();
|
2013-04-09 12:35:11 +08:00
|
|
|
if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
|
|
|
|
O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
|
|
|
|
PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
|
|
|
|
PIC = PIE || O.matches(options::OPT_fPIC) ||
|
|
|
|
O.matches(options::OPT_fpic);
|
|
|
|
IsPICLevelTwo = O.matches(options::OPT_fPIE) ||
|
|
|
|
O.matches(options::OPT_fPIC);
|
|
|
|
} else {
|
|
|
|
PIE = PIC = false;
|
|
|
|
}
|
|
|
|
}
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inroduce a Darwin-specific hack. If the default is PIC but the flags
|
|
|
|
// specified while enabling PIC enabled level 1 PIC, just force it back to
|
|
|
|
// level 2 PIC instead. This matches the behavior of Darwin GCC (based on my
|
|
|
|
// informal testing).
|
|
|
|
if (PIC && getToolChain().getTriple().isOSDarwin())
|
|
|
|
IsPICLevelTwo |= getToolChain().isPICDefault();
|
|
|
|
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
// Note that these flags are trump-cards. Regardless of the order w.r.t. the
|
|
|
|
// PIC or PIE options above, if these show up, PIC is disabled.
|
2012-10-16 06:23:53 +08:00
|
|
|
llvm::Triple Triple(TripleStr);
|
2013-02-18 09:16:37 +08:00
|
|
|
if (KernelOrKext &&
|
2012-10-16 06:23:53 +08:00
|
|
|
(Triple.getOS() != llvm::Triple::IOS ||
|
|
|
|
Triple.isOSVersionLT(6)))
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
PIC = PIE = false;
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
if (Args.hasArg(options::OPT_static))
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
PIC = PIE = false;
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
|
|
|
|
// This is a very special mode. It trumps the other modes, almost no one
|
|
|
|
// uses it, and it isn't even valid on any OS but Darwin.
|
|
|
|
if (!getToolChain().getTriple().isOSDarwin())
|
|
|
|
D.Diag(diag::err_drv_unsupported_opt_for_target)
|
|
|
|
<< A->getSpelling() << getToolChain().getTriple().str();
|
|
|
|
|
|
|
|
// FIXME: Warn when this flag trumps some other PIC or PIE flag.
|
|
|
|
|
2009-11-29 15:18:39 +08:00
|
|
|
CmdArgs.push_back("-mrelocation-model");
|
Completely re-work how the Clang driver interprets PIC and PIE options.
There were numerous issues here that were all entangled, and so I've
tried to do a general simplification of the logic.
1) The logic was mimicing actual GCC bugs, rather than "features". These
have been fixed in trunk GCC, and this fixes Clang as well. Notably,
the logic was always intended to be last-match-wins like any other
flag.
2) The logic for handling '-mdynamic-no-pic' was preposterously unclear.
It also allowed the use of this flag on non-Darwin platforms where it
has no actual meaning. Now this option is handled directly based on
tests of how llvm-gcc behaves, and it is only supported on Darwin.
3) The APIs for the Driver's ToolChains had the implementation ugliness
of dynamic-no-pic leaking through them. They also had the
implementation details of the LLVM relocation model flag names
leaking through.
4) The actual results of passing these flags was incorrect on Darwin in
many cases. For example, Darwin *always* uses PIC level 2 if it uses
in PIC level, and Darwin *always* uses PIC on 64-bit regardless of
the flags specified, including -fPIE. Darwin never compiles in PIE
mode, but it can *link* in PIE mode.
5) Also, PIC was not always being enabled even when PIE was. This isn't
a supported mode at all and may have caused some fallout in builds
with complex PIC and PIE interactions.
The result is (I hope) cleaner and clearer for readers. I've also left
comments and tests about some of the truly strage behavior that is
observed on Darwin platforms. We have no real testing of Windows
platforms and PIC, but I don't have the tools handy to figure that out.
Hopefully others can beef up our testing here.
Unfortunately, I can't test this for every platform. =/ If folks have
dependencies on these flags that aren't covered by tests, they may
break. I've audited and ensured that all the changes in behavior of the
existing tests are intentional and good. In particular I've tried to
make sure the Darwin behavior (which is more suprising than the Linux
behavior) also matches that of 'gcc' on my mac.
llvm-svn: 168297
2012-11-19 11:52:03 +08:00
|
|
|
CmdArgs.push_back("dynamic-no-pic");
|
|
|
|
|
|
|
|
// Only a forced PIC mode can cause the actual compile to have PIC defines
|
|
|
|
// etc., no flags are sufficient. This behavior was selected to closely
|
|
|
|
// match that of llvm-gcc and Apple GCC before that.
|
|
|
|
if (getToolChain().isPICDefault() && getToolChain().isPICDefaultForced()) {
|
|
|
|
CmdArgs.push_back("-pic-level");
|
|
|
|
CmdArgs.push_back("2");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Currently, LLVM only knows about PIC vs. static; the PIE differences are
|
|
|
|
// handled in Clang's IRGen by the -pie-level flag.
|
|
|
|
CmdArgs.push_back("-mrelocation-model");
|
|
|
|
CmdArgs.push_back(PIC ? "pic" : "static");
|
|
|
|
|
|
|
|
if (PIC) {
|
|
|
|
CmdArgs.push_back("-pic-level");
|
|
|
|
CmdArgs.push_back(IsPICLevelTwo ? "2" : "1");
|
|
|
|
if (PIE) {
|
|
|
|
CmdArgs.push_back("-pie-level");
|
|
|
|
CmdArgs.push_back(IsPICLevelTwo ? "2" : "1");
|
|
|
|
}
|
|
|
|
}
|
2009-04-30 02:32:25 +08:00
|
|
|
}
|
Teach Clang about PIE compilations. This is the first step of PR12380.
First, this patch cleans up the parsing of the PIC and PIE family of
options in the driver. The existing logic failed to claim arguments all
over the place resulting in kludges that marked the options as unused.
Instead actually walk all of the arguments and claim them properly.
We now treat -f{,no-}{pic,PIC,pie,PIE} as a single set, accepting the
last one on the commandline. Previously there were lots of ordering bugs
that could creep in due to the nature of the parsing. Let me know if
folks would like weird things such as "-fPIE -fno-pic" to turn on PIE,
but disable full PIC. This doesn't make any sense to me, but we could in
theory support it.
Options that seem to have intentional "trump" status (-static, -mkernel,
etc) continue to do so and are commented as such.
Next, a -pie-level flag is threaded into the frontend, rigged to
a language option, and handled preprocessor, setting up the appropriate
defines. We'll now have the correct defines when compiling with -fpie.
The one place outside of the preprocessor that was inspecting the PIC
level (as opposed to the relocation model, which is set and handled
separately, yay!) is in the GNU ObjC runtime. I changed it to exactly
preserve existing behavior. If folks want to change its behavior in the
face of PIE, they can do that in a separate patch.
Essentially the only functionality changed here is the preprocessor
defines and bug-fixes to the argument management.
Tests have been updated and extended to test all of this a bit more
thoroughly.
llvm-svn: 154291
2012-04-09 00:40:35 +08:00
|
|
|
|
2009-11-29 15:18:39 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fmerge_all_constants,
|
|
|
|
options::OPT_fno_merge_all_constants))
|
2011-04-09 02:06:54 +08:00
|
|
|
CmdArgs.push_back("-fno-merge-all-constants");
|
2009-11-29 15:18:39 +08:00
|
|
|
|
|
|
|
// LLVM Code Generator Options.
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2011-02-10 01:54:19 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
|
|
|
|
CmdArgs.push_back("-mregparm");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2011-02-10 01:54:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-25 09:49:44 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
|
|
|
|
options::OPT_freg_struct_return)) {
|
2013-06-18 10:46:29 +08:00
|
|
|
if (getToolChain().getTriple().getArch() != llvm::Triple::x86) {
|
|
|
|
D.Diag(diag::err_drv_unsupported_opt_for_target)
|
|
|
|
<< A->getSpelling() << getToolChain().getTriple().str();
|
|
|
|
} else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
|
|
|
|
CmdArgs.push_back("-fpcc-struct-return");
|
|
|
|
} else {
|
|
|
|
assert(A->getOption().matches(options::OPT_freg_struct_return));
|
|
|
|
CmdArgs.push_back("-freg-struct-return");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 01:40:53 +08:00
|
|
|
if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false))
|
|
|
|
CmdArgs.push_back("-mrtd");
|
|
|
|
|
2011-12-15 05:02:23 +08:00
|
|
|
if (shouldUseFramePointer(Args, getToolChain().getTriple()))
|
2009-11-29 15:18:39 +08:00
|
|
|
CmdArgs.push_back("-mdisable-fp-elim");
|
2009-04-30 02:32:25 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
|
2009-11-29 15:18:39 +08:00
|
|
|
options::OPT_fno_zero_initialized_in_bss))
|
|
|
|
CmdArgs.push_back("-mno-zero-initialized-in-bss");
|
2013-04-25 02:09:54 +08:00
|
|
|
|
|
|
|
bool OFastEnabled = isOptimizationLevelFast(Args);
|
|
|
|
// If -Ofast is the optimization level, then -fstrict-aliasing should be
|
|
|
|
// enabled. This alias option is being used to simplify the hasFlag logic.
|
|
|
|
OptSpecifier StrictAliasingAliasOption = OFastEnabled ? options::OPT_Ofast :
|
|
|
|
options::OPT_fstrict_aliasing;
|
|
|
|
if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
|
2011-02-04 10:20:39 +08:00
|
|
|
options::OPT_fno_strict_aliasing,
|
|
|
|
getToolChain().IsStrictAliasingDefault()))
|
2010-10-15 06:36:56 +08:00
|
|
|
CmdArgs.push_back("-relaxed-aliasing");
|
2013-04-05 05:53:22 +08:00
|
|
|
if (Args.hasArg(options::OPT_fstruct_path_tbaa))
|
|
|
|
CmdArgs.push_back("-struct-path-tbaa");
|
2012-03-28 07:58:37 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fstrict_enums, options::OPT_fno_strict_enums,
|
|
|
|
false))
|
|
|
|
CmdArgs.push_back("-fstrict-enums");
|
2012-01-23 16:29:12 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_foptimize_sibling_calls,
|
|
|
|
options::OPT_fno_optimize_sibling_calls))
|
|
|
|
CmdArgs.push_back("-mdisable-tail-calls");
|
2010-05-15 06:00:22 +08:00
|
|
|
|
2013-04-04 14:29:47 +08:00
|
|
|
// Handle segmented stacks.
|
|
|
|
if (Args.hasArg(options::OPT_fsplit_stack))
|
|
|
|
CmdArgs.push_back("-split-stacks");
|
2013-04-25 02:09:54 +08:00
|
|
|
|
|
|
|
// If -Ofast is the optimization level, then -ffast-math should be enabled.
|
|
|
|
// This alias option is being used to simplify the getLastArg logic.
|
|
|
|
OptSpecifier FastMathAliasOption = OFastEnabled ? options::OPT_Ofast :
|
|
|
|
options::OPT_ffast_math;
|
2013-04-04 14:29:47 +08:00
|
|
|
|
2012-01-02 22:19:45 +08:00
|
|
|
// Handle various floating point optimization flags, mapping them to the
|
|
|
|
// appropriate LLVM code generation flags. The pattern for all of these is to
|
|
|
|
// default off the codegen optimizations, and if any flag enables them and no
|
|
|
|
// flag disables them after the flag enabling them, enable the codegen
|
|
|
|
// optimization. This is complicated by several "umbrella" flags.
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_ffinite_math_only,
|
|
|
|
options::OPT_fno_finite_math_only,
|
|
|
|
options::OPT_fhonor_infinities,
|
|
|
|
options::OPT_fno_honor_infinities))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_finite_math_only &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_fhonor_infinities)
|
|
|
|
CmdArgs.push_back("-menable-no-infs");
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_ffinite_math_only,
|
|
|
|
options::OPT_fno_finite_math_only,
|
|
|
|
options::OPT_fhonor_nans,
|
|
|
|
options::OPT_fno_honor_nans))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_finite_math_only &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_fhonor_nans)
|
|
|
|
CmdArgs.push_back("-menable-no-nans");
|
|
|
|
|
2012-05-02 22:55:48 +08:00
|
|
|
// -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
|
|
|
|
bool MathErrno = getToolChain().IsMathErrnoDefault();
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_fmath_errno,
|
2013-05-19 04:47:36 +08:00
|
|
|
options::OPT_fno_math_errno)) {
|
|
|
|
// Turning on -ffast_math (with either flag) removes the need for MathErrno.
|
|
|
|
// However, turning *off* -ffast_math merely restores the toolchain default
|
|
|
|
// (which may be false).
|
|
|
|
if (A->getOption().getID() == options::OPT_fno_math_errno ||
|
|
|
|
A->getOption().getID() == options::OPT_ffast_math ||
|
|
|
|
A->getOption().getID() == options::OPT_Ofast)
|
|
|
|
MathErrno = false;
|
|
|
|
else if (A->getOption().getID() == options::OPT_fmath_errno)
|
|
|
|
MathErrno = true;
|
|
|
|
}
|
2012-04-26 10:10:51 +08:00
|
|
|
if (MathErrno)
|
|
|
|
CmdArgs.push_back("-fmath-errno");
|
2012-01-02 22:19:45 +08:00
|
|
|
|
|
|
|
// There are several flags which require disabling very specific
|
|
|
|
// optimizations. Any of these being disabled forces us to turn off the
|
|
|
|
// entire set of LLVM optimizations, so collect them through all the flag
|
|
|
|
// madness.
|
|
|
|
bool AssociativeMath = false;
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_funsafe_math_optimizations,
|
|
|
|
options::OPT_fno_unsafe_math_optimizations,
|
|
|
|
options::OPT_fassociative_math,
|
|
|
|
options::OPT_fno_associative_math))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_fno_associative_math)
|
|
|
|
AssociativeMath = true;
|
|
|
|
bool ReciprocalMath = false;
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_funsafe_math_optimizations,
|
|
|
|
options::OPT_fno_unsafe_math_optimizations,
|
|
|
|
options::OPT_freciprocal_math,
|
|
|
|
options::OPT_fno_reciprocal_math))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_fno_reciprocal_math)
|
|
|
|
ReciprocalMath = true;
|
|
|
|
bool SignedZeros = true;
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_funsafe_math_optimizations,
|
|
|
|
options::OPT_fno_unsafe_math_optimizations,
|
|
|
|
options::OPT_fsigned_zeros,
|
|
|
|
options::OPT_fno_signed_zeros))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_fsigned_zeros)
|
|
|
|
SignedZeros = false;
|
|
|
|
bool TrappingMath = true;
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-01-02 22:19:45 +08:00
|
|
|
options::OPT_funsafe_math_optimizations,
|
|
|
|
options::OPT_fno_unsafe_math_optimizations,
|
|
|
|
options::OPT_ftrapping_math,
|
|
|
|
options::OPT_fno_trapping_math))
|
2012-09-26 06:03:25 +08:00
|
|
|
if (A->getOption().getID() != options::OPT_fno_fast_math &&
|
|
|
|
A->getOption().getID() != options::OPT_fno_unsafe_math_optimizations &&
|
2012-01-02 22:19:45 +08:00
|
|
|
A->getOption().getID() != options::OPT_ftrapping_math)
|
|
|
|
TrappingMath = false;
|
|
|
|
if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros &&
|
|
|
|
!TrappingMath)
|
|
|
|
CmdArgs.push_back("-menable-unsafe-fp-math");
|
|
|
|
|
2012-07-06 08:59:19 +08:00
|
|
|
|
|
|
|
// Validate and pass through -fp-contract option.
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
2012-09-26 06:03:25 +08:00
|
|
|
options::OPT_fno_fast_math,
|
2012-07-06 08:59:19 +08:00
|
|
|
options::OPT_ffp_contract)) {
|
|
|
|
if (A->getOption().getID() == options::OPT_ffp_contract) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef Val = A->getValue();
|
2012-07-06 08:59:19 +08:00
|
|
|
if (Val == "fast" || Val == "on" || Val == "off") {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + Val));
|
|
|
|
} else {
|
|
|
|
D.Diag(diag::err_drv_unsupported_option_argument)
|
|
|
|
<< A->getOption().getName() << Val;
|
|
|
|
}
|
2013-04-25 02:09:54 +08:00
|
|
|
} else if (A->getOption().matches(options::OPT_ffast_math) ||
|
|
|
|
(OFastEnabled && A->getOption().matches(options::OPT_Ofast))) {
|
2012-07-06 08:59:19 +08:00
|
|
|
// If fast-math is set then set the fp-contract mode to fast.
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 11:52:53 +08:00
|
|
|
// We separately look for the '-ffast-math' and '-ffinite-math-only' flags,
|
|
|
|
// and if we find them, tell the frontend to provide the appropriate
|
|
|
|
// preprocessor macros. This is distinct from enabling any optimizations as
|
|
|
|
// these options induce language changes which must survive serialization
|
|
|
|
// and deserialization, etc.
|
2013-04-25 02:09:54 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
|
|
|
|
options::OPT_fno_fast_math))
|
|
|
|
if (!A->getOption().matches(options::OPT_fno_fast_math))
|
|
|
|
CmdArgs.push_back("-ffast-math");
|
2012-09-26 06:03:25 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ffinite_math_only, options::OPT_fno_fast_math))
|
|
|
|
if (A->getOption().matches(options::OPT_ffinite_math_only))
|
|
|
|
CmdArgs.push_back("-ffinite-math-only");
|
2012-01-02 22:19:45 +08:00
|
|
|
|
2010-05-15 06:00:22 +08:00
|
|
|
// Decide whether to use verbose asm. Verbose assembly is the default on
|
|
|
|
// toolchains which have the integrated assembler on by default.
|
|
|
|
bool IsVerboseAsmDefault = getToolChain().IsIntegratedAssemblerDefault();
|
|
|
|
if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
|
2010-10-21 11:16:25 +08:00
|
|
|
IsVerboseAsmDefault) ||
|
2010-05-15 06:00:22 +08:00
|
|
|
Args.hasArg(options::OPT_dA))
|
2009-11-29 15:18:39 +08:00
|
|
|
CmdArgs.push_back("-masm-verbose");
|
2010-05-15 06:00:22 +08:00
|
|
|
|
2009-11-29 15:18:39 +08:00
|
|
|
if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
|
|
|
|
CmdArgs.push_back("-mdebug-pass");
|
|
|
|
CmdArgs.push_back("Structure");
|
|
|
|
}
|
|
|
|
if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
|
|
|
|
CmdArgs.push_back("-mdebug-pass");
|
|
|
|
CmdArgs.push_back("Arguments");
|
|
|
|
}
|
2009-09-16 14:17:29 +08:00
|
|
|
|
2010-02-19 10:45:38 +08:00
|
|
|
// Enable -mconstructor-aliases except on darwin, where we have to
|
|
|
|
// work around a linker bug; see <rdar://problem/7651567>.
|
2011-10-14 13:03:44 +08:00
|
|
|
if (!getToolChain().getTriple().isOSDarwin())
|
2010-02-19 10:45:38 +08:00
|
|
|
CmdArgs.push_back("-mconstructor-aliases");
|
2011-02-17 16:50:50 +08:00
|
|
|
|
2011-03-18 10:56:14 +08:00
|
|
|
// Darwin's kernel doesn't support guard variables; just die if we
|
|
|
|
// try to use them.
|
2011-10-14 13:03:44 +08:00
|
|
|
if (KernelOrKext && getToolChain().getTriple().isOSDarwin())
|
2011-03-18 10:56:14 +08:00
|
|
|
CmdArgs.push_back("-fforbid-guard-variables");
|
|
|
|
|
2011-02-01 23:15:22 +08:00
|
|
|
if (Args.hasArg(options::OPT_mms_bitfields)) {
|
|
|
|
CmdArgs.push_back("-mms-bitfields");
|
|
|
|
}
|
2010-02-19 10:45:38 +08:00
|
|
|
|
2009-09-16 14:17:29 +08:00
|
|
|
// This is a coarse approximation of what llvm-gcc actually does, both
|
|
|
|
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
|
|
|
|
// complicated ways.
|
|
|
|
bool AsynchronousUnwindTables =
|
|
|
|
Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
|
|
|
|
options::OPT_fno_asynchronous_unwind_tables,
|
|
|
|
getToolChain().IsUnwindTablesDefault() &&
|
2010-03-20 12:52:14 +08:00
|
|
|
!KernelOrKext);
|
2009-09-16 14:17:29 +08:00
|
|
|
if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
|
|
|
|
AsynchronousUnwindTables))
|
2009-11-29 15:18:39 +08:00
|
|
|
CmdArgs.push_back("-munwind-tables");
|
|
|
|
|
2012-11-22 07:40:23 +08:00
|
|
|
getToolChain().addClangTargetOptions(Args, CmdArgs);
|
2012-06-19 09:26:10 +08:00
|
|
|
|
2009-11-29 15:18:39 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
|
|
|
|
CmdArgs.push_back("-mlimit-float-precision");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-11-29 15:18:39 +08:00
|
|
|
}
|
2009-04-30 02:32:25 +08:00
|
|
|
|
2009-05-06 11:16:41 +08:00
|
|
|
// FIXME: Handle -mtune=.
|
|
|
|
(void) Args.hasArg(options::OPT_mtune_EQ);
|
2009-04-30 02:32:25 +08:00
|
|
|
|
2009-08-05 22:30:52 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
|
2009-11-29 15:18:39 +08:00
|
|
|
CmdArgs.push_back("-mcode-model");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-08-05 22:30:52 +08:00
|
|
|
}
|
|
|
|
|
2009-09-10 06:33:08 +08:00
|
|
|
// Add target specific cpu and features flags.
|
|
|
|
switch(getToolChain().getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
break;
|
2009-05-06 11:16:41 +08:00
|
|
|
|
2009-09-10 12:57:17 +08:00
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb:
|
2011-03-18 01:10:06 +08:00
|
|
|
AddARMTargetArgs(Args, CmdArgs, KernelOrKext);
|
2009-09-10 12:57:17 +08:00
|
|
|
break;
|
|
|
|
|
2010-03-02 10:41:08 +08:00
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
2011-09-21 10:13:07 +08:00
|
|
|
case llvm::Triple::mips64:
|
|
|
|
case llvm::Triple::mips64el:
|
2010-03-02 10:41:08 +08:00
|
|
|
AddMIPSTargetArgs(Args, CmdArgs);
|
2010-11-10 01:21:19 +08:00
|
|
|
break;
|
|
|
|
|
2012-06-12 06:35:19 +08:00
|
|
|
case llvm::Triple::ppc:
|
|
|
|
case llvm::Triple::ppc64:
|
|
|
|
AddPPCTargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
|
|
|
|
2013-04-02 04:56:53 +08:00
|
|
|
case llvm::Triple::r600:
|
|
|
|
AddR600TargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
|
|
|
|
2010-11-10 01:21:19 +08:00
|
|
|
case llvm::Triple::sparc:
|
|
|
|
AddSparcTargetArgs(Args, CmdArgs);
|
2010-03-02 10:41:08 +08:00
|
|
|
break;
|
|
|
|
|
2009-09-10 06:33:08 +08:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
AddX86TargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
2011-12-13 05:14:55 +08:00
|
|
|
|
|
|
|
case llvm::Triple::hexagon:
|
|
|
|
AddHexagonTargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
2009-04-30 02:32:25 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
|
|
|
|
|
2010-08-12 07:07:47 +08:00
|
|
|
// Pass the linker version in use.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
|
|
|
|
CmdArgs.push_back("-target-linker-version");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-08-12 07:07:47 +08:00
|
|
|
}
|
|
|
|
|
2013-04-03 09:58:53 +08:00
|
|
|
if (!shouldUseLeafFramePointer(Args, getToolChain().getTriple()))
|
2010-07-01 09:31:45 +08:00
|
|
|
CmdArgs.push_back("-momit-leaf-frame-pointer");
|
|
|
|
|
2010-05-13 02:19:58 +08:00
|
|
|
// Explicitly error on some things we know we don't support and can't just
|
|
|
|
// ignore.
|
|
|
|
types::ID InputType = Inputs[0].getType();
|
2010-09-25 03:39:37 +08:00
|
|
|
if (!Args.hasArg(options::OPT_fallow_unsupported)) {
|
|
|
|
Arg *Unsupported;
|
|
|
|
if (types::isCXX(InputType) &&
|
2011-10-14 13:03:44 +08:00
|
|
|
getToolChain().getTriple().isOSDarwin() &&
|
2010-09-25 03:39:37 +08:00
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::x86) {
|
2011-08-14 07:48:55 +08:00
|
|
|
if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) ||
|
|
|
|
(Unsupported = Args.getLastArg(options::OPT_mkernel)))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
|
2010-09-25 03:39:37 +08:00
|
|
|
<< Unsupported->getOption().getName();
|
|
|
|
}
|
2010-05-13 02:19:58 +08:00
|
|
|
}
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_v);
|
2010-08-25 06:44:13 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_H);
|
2011-08-03 01:58:04 +08:00
|
|
|
if (D.CCPrintHeaders && !D.CCGenDiagnostics) {
|
2011-02-03 05:11:35 +08:00
|
|
|
CmdArgs.push_back("-header-include-file");
|
|
|
|
CmdArgs.push_back(D.CCPrintHeadersFilename ?
|
|
|
|
D.CCPrintHeadersFilename : "-");
|
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_P);
|
2009-09-09 23:08:12 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2011-08-03 01:58:04 +08:00
|
|
|
if (D.CCLogDiagnostics && !D.CCGenDiagnostics) {
|
2011-04-08 02:01:20 +08:00
|
|
|
CmdArgs.push_back("-diagnostic-log-file");
|
|
|
|
CmdArgs.push_back(D.CCLogDiagnosticsFilename ?
|
|
|
|
D.CCLogDiagnosticsFilename : "-");
|
|
|
|
}
|
|
|
|
|
2013-02-05 15:29:57 +08:00
|
|
|
// Use the last option from "-g" group. "-gline-tables-only"
|
|
|
|
// is preserved, all other debug options are substituted with "-g".
|
2010-03-07 12:46:18 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
2012-05-29 16:10:34 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
|
2013-02-05 15:29:57 +08:00
|
|
|
if (A->getOption().matches(options::OPT_gline_tables_only))
|
2012-05-29 16:10:34 +08:00
|
|
|
CmdArgs.push_back("-gline-tables-only");
|
2013-06-19 09:46:49 +08:00
|
|
|
else if (A->getOption().matches(options::OPT_gdwarf_2))
|
|
|
|
CmdArgs.push_back("-gdwarf-2");
|
|
|
|
else if (A->getOption().matches(options::OPT_gdwarf_3))
|
|
|
|
CmdArgs.push_back("-gdwarf-3");
|
|
|
|
else if (A->getOption().matches(options::OPT_gdwarf_4))
|
|
|
|
CmdArgs.push_back("-gdwarf-4");
|
2013-02-05 15:29:57 +08:00
|
|
|
else if (!A->getOption().matches(options::OPT_g0) &&
|
|
|
|
!A->getOption().matches(options::OPT_ggdb0))
|
2011-11-08 03:52:29 +08:00
|
|
|
CmdArgs.push_back("-g");
|
2012-05-29 16:10:34 +08:00
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2012-06-21 16:22:39 +08:00
|
|
|
// We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now.
|
|
|
|
Args.ClaimAllArgs(options::OPT_g_flags_Group);
|
2012-10-19 05:52:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_gcolumn_info))
|
|
|
|
CmdArgs.push_back("-dwarf-column-info");
|
2012-06-21 16:22:39 +08:00
|
|
|
|
2013-02-05 15:29:57 +08:00
|
|
|
// -gsplit-dwarf should turn on -g and enable the backend dwarf
|
|
|
|
// splitting and extraction.
|
2013-02-22 06:35:05 +08:00
|
|
|
// FIXME: Currently only works on Linux.
|
|
|
|
if (getToolChain().getTriple().getOS() == llvm::Triple::Linux &&
|
|
|
|
Args.hasArg(options::OPT_gsplit_dwarf)) {
|
2013-02-05 15:29:57 +08:00
|
|
|
CmdArgs.push_back("-g");
|
|
|
|
CmdArgs.push_back("-backend-option");
|
|
|
|
CmdArgs.push_back("-split-dwarf=Enable");
|
|
|
|
}
|
|
|
|
|
2013-06-18 08:03:50 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_fdebug_types_section);
|
|
|
|
|
2010-05-07 05:06:04 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections);
|
|
|
|
|
2010-06-22 08:03:40 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
|
|
|
|
|
2011-04-22 07:44:07 +08:00
|
|
|
if (Args.hasArg(options::OPT_ftest_coverage) ||
|
|
|
|
Args.hasArg(options::OPT_coverage))
|
|
|
|
CmdArgs.push_back("-femit-coverage-notes");
|
|
|
|
if (Args.hasArg(options::OPT_fprofile_arcs) ||
|
|
|
|
Args.hasArg(options::OPT_coverage))
|
|
|
|
CmdArgs.push_back("-femit-coverage-data");
|
|
|
|
|
2011-05-05 04:46:58 +08:00
|
|
|
if (C.getArgs().hasArg(options::OPT_c) ||
|
|
|
|
C.getArgs().hasArg(options::OPT_S)) {
|
|
|
|
if (Output.isFilename()) {
|
2011-05-05 08:08:20 +08:00
|
|
|
CmdArgs.push_back("-coverage-file");
|
2013-02-22 08:24:40 +08:00
|
|
|
SmallString<128> CoverageFilename(Output.getFilename());
|
2013-03-07 16:28:53 +08:00
|
|
|
if (llvm::sys::path::is_relative(CoverageFilename.str())) {
|
|
|
|
if (const char *pwd = ::getenv("PWD")) {
|
|
|
|
if (llvm::sys::path::is_absolute(pwd)) {
|
|
|
|
SmallString<128> Pwd(pwd);
|
|
|
|
llvm::sys::path::append(Pwd, CoverageFilename.str());
|
|
|
|
CoverageFilename.swap(Pwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-22 08:24:40 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
|
2011-05-05 04:46:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-12 02:20:10 +08:00
|
|
|
// Pass options for controlling the default header search paths.
|
|
|
|
if (Args.hasArg(options::OPT_nostdinc)) {
|
|
|
|
CmdArgs.push_back("-nostdsysteminc");
|
|
|
|
CmdArgs.push_back("-nobuiltininc");
|
|
|
|
} else {
|
2011-10-12 02:20:16 +08:00
|
|
|
if (Args.hasArg(options::OPT_nostdlibinc))
|
|
|
|
CmdArgs.push_back("-nostdsysteminc");
|
2011-10-12 02:20:10 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
|
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2009-12-15 09:02:52 +08:00
|
|
|
// Pass the path to compiler resource files.
|
|
|
|
CmdArgs.push_back("-resource-dir");
|
2010-01-20 10:35:16 +08:00
|
|
|
CmdArgs.push_back(D.ResourceDir.c_str());
|
2009-04-08 05:42:00 +08:00
|
|
|
|
2010-11-04 06:45:23 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_working_directory);
|
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
bool ARCMTEnabled = false;
|
2011-06-16 07:25:17 +08:00
|
|
|
if (!Args.hasArg(options::OPT_fno_objc_arc)) {
|
2011-07-07 12:00:39 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
|
2011-07-10 04:00:58 +08:00
|
|
|
options::OPT_ccc_arcmt_modify,
|
|
|
|
options::OPT_ccc_arcmt_migrate)) {
|
2012-03-07 04:06:33 +08:00
|
|
|
ARCMTEnabled = true;
|
2011-06-16 07:25:17 +08:00
|
|
|
switch (A->getOption().getID()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("missed a case");
|
2011-07-07 12:00:39 +08:00
|
|
|
case options::OPT_ccc_arcmt_check:
|
2011-06-16 07:25:17 +08:00
|
|
|
CmdArgs.push_back("-arcmt-check");
|
|
|
|
break;
|
2011-07-07 12:00:39 +08:00
|
|
|
case options::OPT_ccc_arcmt_modify:
|
2011-06-16 07:25:17 +08:00
|
|
|
CmdArgs.push_back("-arcmt-modify");
|
|
|
|
break;
|
2011-07-10 04:00:58 +08:00
|
|
|
case options::OPT_ccc_arcmt_migrate:
|
|
|
|
CmdArgs.push_back("-arcmt-migrate");
|
2012-03-07 04:06:33 +08:00
|
|
|
CmdArgs.push_back("-mt-migrate-directory");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2011-07-20 01:20:03 +08:00
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
|
2011-07-10 04:00:58 +08:00
|
|
|
break;
|
2011-06-16 07:25:17 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-25 03:01:18 +08:00
|
|
|
} else {
|
|
|
|
Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
|
|
|
|
Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
|
|
|
|
Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
|
2011-06-16 07:25:17 +08:00
|
|
|
}
|
2011-08-19 08:30:14 +08:00
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
|
|
|
|
if (ARCMTEnabled) {
|
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "-ccc-arcmt-migrate";
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("-mt-migrate-directory");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2012-03-07 04:06:33 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
|
|
|
|
options::OPT_objcmt_migrate_subscripting)) {
|
|
|
|
// None specified, means enable them all.
|
|
|
|
CmdArgs.push_back("-objcmt-migrate-literals");
|
|
|
|
CmdArgs.push_back("-objcmt-migrate-subscripting");
|
|
|
|
} else {
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
// Add preprocessing options like -I, -D, etc. if we are using the
|
|
|
|
// preprocessor.
|
|
|
|
//
|
|
|
|
// FIXME: Support -fpreprocessed
|
|
|
|
if (types::getPreprocessedType(InputType) != types::TY_INVALID)
|
2013-01-25 03:14:47 +08:00
|
|
|
AddPreprocessingOptions(C, JA, D, Args, CmdArgs, Output, Inputs);
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2011-07-22 07:40:37 +08:00
|
|
|
// Don't warn about "clang -c -DPIC -fPIC test.i" because libtool.m4 assumes
|
|
|
|
// that "The compiler can only warn and ignore the option if not recognized".
|
|
|
|
// When building with ccache, it will pass -D options to clang even on
|
|
|
|
// preprocessed inputs and configure concludes that -fPIC is not supported.
|
|
|
|
Args.ClaimAllArgs(options::OPT_D);
|
|
|
|
|
2009-09-17 14:53:36 +08:00
|
|
|
// Manually translate -O to -O2 and -O4 to -O3; let clang reject
|
2009-03-25 04:17:30 +08:00
|
|
|
// others.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
|
2009-11-19 11:26:40 +08:00
|
|
|
if (A->getOption().matches(options::OPT_O4))
|
2009-03-25 04:17:30 +08:00
|
|
|
CmdArgs.push_back("-O3");
|
2010-05-27 14:51:08 +08:00
|
|
|
else if (A->getOption().matches(options::OPT_O) &&
|
2012-11-01 12:30:05 +08:00
|
|
|
A->getValue()[0] == '\0')
|
2009-09-17 14:53:36 +08:00
|
|
|
CmdArgs.push_back("-O2");
|
2009-03-18 18:01:51 +08:00
|
|
|
else
|
2009-03-19 07:39:35 +08:00
|
|
|
A->render(Args, CmdArgs);
|
2009-03-18 18:01:51 +08:00
|
|
|
}
|
|
|
|
|
2012-12-13 04:06:31 +08:00
|
|
|
// Don't warn about unused -flto. This can happen when we're preprocessing or
|
|
|
|
// precompiling.
|
|
|
|
Args.ClaimAllArgs(options::OPT_flto);
|
|
|
|
|
2009-10-29 10:24:45 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_W_Group);
|
2012-07-07 13:53:30 +08:00
|
|
|
if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic, false))
|
|
|
|
CmdArgs.push_back("-pedantic");
|
2009-10-29 10:24:45 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_w);
|
2009-04-08 06:13:21 +08:00
|
|
|
|
|
|
|
// Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
|
|
|
|
// (-ansi is equivalent to -std=c89).
|
|
|
|
//
|
|
|
|
// If a std is supplied, only add -trigraphs if it follows the
|
|
|
|
// option.
|
|
|
|
if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
|
|
|
|
if (Std->getOption().matches(options::OPT_ansi))
|
2009-10-16 22:28:06 +08:00
|
|
|
if (types::isCXX(InputType))
|
2009-11-04 14:24:38 +08:00
|
|
|
CmdArgs.push_back("-std=c++98");
|
2009-10-16 22:28:06 +08:00
|
|
|
else
|
2009-11-04 14:24:38 +08:00
|
|
|
CmdArgs.push_back("-std=c89");
|
2009-04-08 06:13:21 +08:00
|
|
|
else
|
|
|
|
Std->render(Args, CmdArgs);
|
|
|
|
|
2010-06-15 05:23:08 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
|
|
|
|
options::OPT_trigraphs))
|
|
|
|
if (A != Std)
|
2009-04-08 06:13:21 +08:00
|
|
|
A->render(Args, CmdArgs);
|
2009-04-26 09:10:38 +08:00
|
|
|
} else {
|
|
|
|
// Honor -std-default.
|
2010-01-30 05:03:02 +08:00
|
|
|
//
|
|
|
|
// FIXME: Clang doesn't correctly handle -std= when the input language
|
|
|
|
// doesn't match. For the time being just ignore this for C++ inputs;
|
|
|
|
// eventually we want to do all the standard defaulting here instead of
|
|
|
|
// splitting it between the driver and clang -cc1.
|
|
|
|
if (!types::isCXX(InputType))
|
2012-08-30 10:08:31 +08:00
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
|
|
|
|
"-std=", /*Joined=*/true);
|
|
|
|
else if (getToolChain().getTriple().getOS() == llvm::Triple::Win32)
|
|
|
|
CmdArgs.push_back("-std=c++11");
|
|
|
|
|
2009-04-08 06:13:21 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_trigraphs);
|
2009-04-26 09:10:38 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2011-04-23 14:30:43 +08:00
|
|
|
// Map the bizarre '-Wwrite-strings' flag to a more sensible
|
|
|
|
// '-fconst-strings'; this better indicates its actual behavior.
|
|
|
|
if (Args.hasFlag(options::OPT_Wwrite_strings, options::OPT_Wno_write_strings,
|
|
|
|
false)) {
|
|
|
|
// For perfect compatibility with GCC, we do this even in the presence of
|
|
|
|
// '-w'. This flag names something other than a warning for GCC.
|
|
|
|
CmdArgs.push_back("-fconst-strings");
|
|
|
|
}
|
|
|
|
|
2011-04-23 17:27:53 +08:00
|
|
|
// GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active
|
2011-04-24 03:48:40 +08:00
|
|
|
// during C++ compilation, which it is by default. GCC keeps this define even
|
|
|
|
// in the presence of '-w', match this behavior bug-for-bug.
|
|
|
|
if (types::isCXX(InputType) &&
|
|
|
|
Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
|
|
|
|
true)) {
|
|
|
|
CmdArgs.push_back("-fdeprecated-macro");
|
2011-04-23 17:27:53 +08:00
|
|
|
}
|
|
|
|
|
2010-05-22 10:21:53 +08:00
|
|
|
// Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
|
|
|
|
if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
|
|
|
|
if (Asm->getOption().matches(options::OPT_fasm))
|
|
|
|
CmdArgs.push_back("-fgnu-keywords");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-fno-gnu-keywords");
|
|
|
|
}
|
|
|
|
|
2011-05-03 01:43:32 +08:00
|
|
|
if (ShouldDisableCFI(Args, getToolChain()))
|
|
|
|
CmdArgs.push_back("-fno-dwarf2-cfi-asm");
|
2011-05-01 02:35:43 +08:00
|
|
|
|
2011-10-18 07:05:52 +08:00
|
|
|
if (ShouldDisableDwarfDirectory(Args, getToolChain()))
|
|
|
|
CmdArgs.push_back("-fno-dwarf-directory-asm");
|
|
|
|
|
2013-04-17 02:21:19 +08:00
|
|
|
if (ShouldDisableAutolink(Args, getToolChain()))
|
|
|
|
CmdArgs.push_back("-fno-autolink");
|
|
|
|
|
2012-12-18 05:40:04 +08:00
|
|
|
// Add in -fdebug-compilation-dir if necessary.
|
|
|
|
addDebugCompDirArg(Args, CmdArgs);
|
2011-10-21 10:32:14 +08:00
|
|
|
|
2011-11-22 03:36:32 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_,
|
|
|
|
options::OPT_ftemplate_depth_EQ)) {
|
2009-03-18 18:01:51 +08:00
|
|
|
CmdArgs.push_back("-ftemplate-depth");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 03:36:32 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) {
|
|
|
|
CmdArgs.push_back("-fconstexpr-depth");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2011-11-22 03:36:32 +08:00
|
|
|
}
|
|
|
|
|
2013-05-08 10:12:03 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_steps_EQ)) {
|
|
|
|
CmdArgs.push_back("-fconstexpr-steps");
|
|
|
|
CmdArgs.push_back(A->getValue());
|
|
|
|
}
|
|
|
|
|
2013-02-22 09:59:51 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) {
|
|
|
|
CmdArgs.push_back("-fbracket-depth");
|
|
|
|
CmdArgs.push_back(A->getValue());
|
|
|
|
}
|
|
|
|
|
2010-11-18 08:20:36 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
|
|
|
|
options::OPT_Wlarge_by_value_copy_def)) {
|
2012-05-04 16:08:37 +08:00
|
|
|
if (A->getNumValues()) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef bytes = A->getValue();
|
2012-05-04 16:08:37 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString("-Wlarge-by-value-copy=" + bytes));
|
|
|
|
} else
|
|
|
|
CmdArgs.push_back("-Wlarge-by-value-copy=64"); // default value
|
2010-11-18 07:11:54 +08:00
|
|
|
}
|
|
|
|
|
2012-05-09 06:10:46 +08:00
|
|
|
|
2012-10-23 06:13:48 +08:00
|
|
|
if (Args.hasArg(options::OPT_relocatable_pch))
|
2009-11-21 06:21:36 +08:00
|
|
|
CmdArgs.push_back("-relocatable-pch");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-04 14:24:38 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
|
|
|
|
CmdArgs.push_back("-fconstant-string-class");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-11-04 14:24:38 +08:00
|
|
|
}
|
2009-09-01 00:41:57 +08:00
|
|
|
|
2010-01-10 05:54:33 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
|
|
|
|
CmdArgs.push_back("-ftabstop");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-01-10 05:54:33 +08:00
|
|
|
}
|
|
|
|
|
2010-04-08 04:49:23 +08:00
|
|
|
CmdArgs.push_back("-ferror-limit");
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-04-08 04:49:23 +08:00
|
|
|
else
|
|
|
|
CmdArgs.push_back("19");
|
2010-04-20 15:18:24 +08:00
|
|
|
|
2010-05-06 12:55:18 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) {
|
|
|
|
CmdArgs.push_back("-fmacro-backtrace-limit");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-05-06 12:55:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) {
|
|
|
|
CmdArgs.push_back("-ftemplate-backtrace-limit");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-05-06 12:55:18 +08:00
|
|
|
}
|
|
|
|
|
2011-12-17 03:06:07 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_backtrace_limit_EQ)) {
|
|
|
|
CmdArgs.push_back("-fconstexpr-backtrace-limit");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2011-12-17 03:06:07 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 14:24:47 +08:00
|
|
|
// Pass -fmessage-length=.
|
2009-11-30 16:40:54 +08:00
|
|
|
CmdArgs.push_back("-fmessage-length");
|
2009-11-04 14:24:47 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-11-04 14:24:47 +08:00
|
|
|
} else {
|
|
|
|
// If -fmessage-length=N was not specified, determine whether this is a
|
|
|
|
// terminal and, if so, implicitly define -fmessage-length appropriately.
|
|
|
|
unsigned N = llvm::sys::Process::StandardErrColumns();
|
2011-07-23 18:55:15 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(Twine(N)));
|
2009-11-04 14:24:47 +08:00
|
|
|
}
|
|
|
|
|
2013-02-19 09:57:35 +08:00
|
|
|
// -fvisibility= and -fvisibility-ms-compat are of a piece.
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,
|
|
|
|
options::OPT_fvisibility_ms_compat)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fvisibility_EQ)) {
|
|
|
|
CmdArgs.push_back("-fvisibility");
|
|
|
|
CmdArgs.push_back(A->getValue());
|
|
|
|
} else {
|
|
|
|
assert(A->getOption().matches(options::OPT_fvisibility_ms_compat));
|
|
|
|
CmdArgs.push_back("-fvisibility");
|
|
|
|
CmdArgs.push_back("hidden");
|
|
|
|
CmdArgs.push_back("-ftype-visibility");
|
|
|
|
CmdArgs.push_back("default");
|
|
|
|
}
|
2009-12-04 02:42:11 +08:00
|
|
|
}
|
|
|
|
|
2010-06-16 01:05:35 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden);
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2012-06-28 16:01:44 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
|
|
|
|
|
2010-03-20 12:52:14 +08:00
|
|
|
// -fhosted is default.
|
2012-03-27 06:04:46 +08:00
|
|
|
if (Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted, false) ||
|
|
|
|
KernelOrKext)
|
2010-03-20 12:52:14 +08:00
|
|
|
CmdArgs.push_back("-ffreestanding");
|
|
|
|
|
2009-12-04 02:42:11 +08:00
|
|
|
// Forward -f (flag) options which we can pass directly.
|
2009-04-08 05:51:40 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
|
2010-10-01 03:05:55 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info);
|
2011-11-05 04:05:58 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fno_limit_debug_info);
|
2011-10-25 15:13:06 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
|
2011-12-24 04:23:19 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_faltivec);
|
2012-06-27 02:18:47 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
|
2012-03-14 07:45:51 +08:00
|
|
|
|
2013-04-09 12:35:11 +08:00
|
|
|
SanitizerArgs Sanitize(getToolChain(), Args);
|
2012-11-06 06:04:41 +08:00
|
|
|
Sanitize.addArgs(Args, CmdArgs);
|
|
|
|
|
2012-12-31 04:53:28 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fsanitize_recover,
|
|
|
|
options::OPT_fno_sanitize_recover,
|
|
|
|
true))
|
|
|
|
CmdArgs.push_back("-fno-sanitize-recover");
|
|
|
|
|
2013-01-30 07:31:22 +08:00
|
|
|
if (Args.hasArg(options::OPT_fcatch_undefined_behavior) ||
|
|
|
|
Args.hasFlag(options::OPT_fsanitize_undefined_trap_on_error,
|
|
|
|
options::OPT_fno_sanitize_undefined_trap_on_error, false))
|
|
|
|
CmdArgs.push_back("-fsanitize-undefined-trap-on-error");
|
|
|
|
|
2013-02-19 14:16:53 +08:00
|
|
|
// Report an error for -faltivec on anything other than PowerPC.
|
2012-03-14 07:45:51 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_faltivec))
|
|
|
|
if (!(getToolChain().getTriple().getArch() == llvm::Triple::ppc ||
|
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::ppc64))
|
|
|
|
D.Diag(diag::err_drv_argument_only_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "ppc/ppc64";
|
|
|
|
|
2011-03-02 02:49:30 +08:00
|
|
|
if (getToolChain().SupportsProfiling())
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_pg);
|
2010-03-17 00:57:46 +08:00
|
|
|
|
|
|
|
// -flax-vector-conversions is default.
|
|
|
|
if (!Args.hasFlag(options::OPT_flax_vector_conversions,
|
|
|
|
options::OPT_fno_lax_vector_conversions))
|
|
|
|
CmdArgs.push_back("-fno-lax-vector-conversions");
|
|
|
|
|
2011-01-07 09:05:02 +08:00
|
|
|
if (Args.getLastArg(options::OPT_fapple_kext))
|
|
|
|
CmdArgs.push_back("-fapple-kext");
|
|
|
|
|
2012-06-15 02:55:27 +08:00
|
|
|
if (Args.hasFlag(options::OPT_frewrite_includes,
|
|
|
|
options::OPT_fno_rewrite_includes, false))
|
|
|
|
CmdArgs.push_back("-frewrite-includes");
|
|
|
|
|
2009-05-23 04:17:16 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
|
2009-04-21 13:34:31 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
|
2010-08-20 04:24:43 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
|
2009-04-08 05:51:40 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
|
2010-09-18 02:29:54 +08:00
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
|
|
|
|
CmdArgs.push_back("-ftrapv-handler");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-09-18 02:29:54 +08:00
|
|
|
}
|
|
|
|
|
2012-02-03 14:27:22 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
|
2011-04-09 05:37:45 +08:00
|
|
|
|
2011-03-27 08:04:55 +08:00
|
|
|
// -fno-strict-overflow implies -fwrapv if it isn't disabled, but
|
|
|
|
// -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fwrapv,
|
|
|
|
options::OPT_fno_wrapv)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fwrapv))
|
|
|
|
CmdArgs.push_back("-fwrapv");
|
|
|
|
} else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
|
|
|
|
options::OPT_fno_strict_overflow)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fno_strict_overflow))
|
|
|
|
CmdArgs.push_back("-fwrapv");
|
|
|
|
}
|
2009-04-08 05:51:40 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
|
2010-08-08 07:08:14 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_funroll_loops);
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2009-09-03 12:54:28 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_pthread);
|
|
|
|
|
2012-10-27 15:47:56 +08:00
|
|
|
|
2009-11-17 16:07:36 +08:00
|
|
|
// -stack-protector=0 is default.
|
|
|
|
unsigned StackProtectorLevel = 0;
|
2009-06-28 15:36:13 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
|
|
|
|
options::OPT_fstack_protector_all,
|
|
|
|
options::OPT_fstack_protector)) {
|
2009-11-17 16:07:36 +08:00
|
|
|
if (A->getOption().matches(options::OPT_fstack_protector))
|
|
|
|
StackProtectorLevel = 1;
|
|
|
|
else if (A->getOption().matches(options::OPT_fstack_protector_all))
|
|
|
|
StackProtectorLevel = 2;
|
2011-08-23 15:38:27 +08:00
|
|
|
} else {
|
|
|
|
StackProtectorLevel =
|
|
|
|
getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
|
|
|
|
}
|
2009-11-17 16:07:36 +08:00
|
|
|
if (StackProtectorLevel) {
|
|
|
|
CmdArgs.push_back("-stack-protector");
|
2011-07-23 18:55:15 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
|
2012-09-12 21:51:14 +08:00
|
|
|
}
|
2012-08-22 00:16:06 +08:00
|
|
|
|
2012-09-12 21:51:14 +08:00
|
|
|
// --param ssp-buffer-size=
|
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT__param),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef Str((*it)->getValue());
|
2012-09-12 21:51:14 +08:00
|
|
|
if (Str.startswith("ssp-buffer-size=")) {
|
|
|
|
if (StackProtectorLevel) {
|
2012-08-22 00:16:06 +08:00
|
|
|
CmdArgs.push_back("-stack-protector-buffer-size");
|
|
|
|
// FIXME: Verify the argument is a valid integer.
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
|
|
|
|
}
|
2012-09-12 21:51:14 +08:00
|
|
|
(*it)->claim();
|
2012-08-22 00:16:06 +08:00
|
|
|
}
|
2009-06-28 15:36:13 +08:00
|
|
|
}
|
|
|
|
|
2011-12-06 11:33:03 +08:00
|
|
|
// Translate -mstackrealign
|
|
|
|
if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
|
|
|
|
false)) {
|
|
|
|
CmdArgs.push_back("-backend-option");
|
|
|
|
CmdArgs.push_back("-force-align-stack");
|
|
|
|
}
|
|
|
|
if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign,
|
|
|
|
false)) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-mstackrealign"));
|
|
|
|
}
|
|
|
|
|
2011-12-06 07:05:23 +08:00
|
|
|
if (Args.hasArg(options::OPT_mstack_alignment)) {
|
|
|
|
StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment));
|
2011-05-03 05:18:22 +08:00
|
|
|
}
|
2012-11-29 08:42:06 +08:00
|
|
|
// -mkernel implies -mstrict-align; don't add the redundant option.
|
|
|
|
if (Args.hasArg(options::OPT_mstrict_align) && !KernelOrKext) {
|
2012-11-10 02:27:01 +08:00
|
|
|
CmdArgs.push_back("-backend-option");
|
|
|
|
CmdArgs.push_back("-arm-strict-align");
|
2012-11-10 01:29:19 +08:00
|
|
|
}
|
2011-08-19 08:30:14 +08:00
|
|
|
|
2009-04-08 05:16:11 +08:00
|
|
|
// Forward -f options with positive and negative forms; we translate
|
|
|
|
// these by hand.
|
|
|
|
|
2011-01-07 09:05:02 +08:00
|
|
|
if (Args.hasArg(options::OPT_mkernel)) {
|
2011-02-05 01:24:47 +08:00
|
|
|
if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType))
|
2011-01-07 09:05:02 +08:00
|
|
|
CmdArgs.push_back("-fapple-kext");
|
|
|
|
if (!Args.hasArg(options::OPT_fbuiltin))
|
|
|
|
CmdArgs.push_back("-fno-builtin");
|
2012-03-27 05:29:17 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_fno_builtin);
|
2011-01-07 09:05:02 +08:00
|
|
|
}
|
2009-11-17 16:07:36 +08:00
|
|
|
// -fbuiltin is default.
|
2011-01-07 09:05:02 +08:00
|
|
|
else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
|
2009-11-19 12:55:23 +08:00
|
|
|
CmdArgs.push_back("-fno-builtin");
|
2009-04-08 05:16:11 +08:00
|
|
|
|
2009-12-17 00:59:22 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
|
|
|
|
options::OPT_fno_assume_sane_operator_new))
|
|
|
|
CmdArgs.push_back("-fno-assume-sane-operator-new");
|
|
|
|
|
2009-11-17 16:07:36 +08:00
|
|
|
// -fblocks=0 is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
|
2011-03-01 01:11:43 +08:00
|
|
|
getToolChain().IsBlocksDefault()) ||
|
|
|
|
(Args.hasArg(options::OPT_fgnu_runtime) &&
|
|
|
|
Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
|
|
|
|
!Args.hasArg(options::OPT_fno_blocks))) {
|
2009-11-17 16:07:36 +08:00
|
|
|
CmdArgs.push_back("-fblocks");
|
2011-09-10 04:41:01 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_fgnu_runtime) &&
|
|
|
|
!getToolChain().hasBlocksRuntime())
|
|
|
|
CmdArgs.push_back("-fblocks-runtime-optional");
|
2009-11-18 03:33:30 +08:00
|
|
|
}
|
2009-04-08 05:16:11 +08:00
|
|
|
|
2012-01-18 23:19:58 +08:00
|
|
|
// -fmodules enables modules (off by default). However, for C++/Objective-C++,
|
|
|
|
// users must also pass -fcxx-modules. The latter flag will disappear once the
|
|
|
|
// modules implementation is solid for C++/Objective-C++ programs as well.
|
2013-01-16 09:23:41 +08:00
|
|
|
bool HaveModules = false;
|
2012-01-18 23:19:58 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) {
|
|
|
|
bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
|
|
|
|
options::OPT_fno_cxx_modules,
|
|
|
|
false);
|
2013-01-16 09:23:41 +08:00
|
|
|
if (AllowedInCXX || !types::isCXX(InputType)) {
|
2012-01-18 23:19:58 +08:00
|
|
|
CmdArgs.push_back("-fmodules");
|
2013-01-16 09:23:41 +08:00
|
|
|
HaveModules = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 03:01:24 +08:00
|
|
|
// If a module path was provided, pass it along. Otherwise, use a temporary
|
|
|
|
// directory.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path)) {
|
|
|
|
A->claim();
|
|
|
|
if (HaveModules) {
|
|
|
|
A->render(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
} else if (HaveModules) {
|
|
|
|
SmallString<128> DefaultModuleCache;
|
|
|
|
llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false,
|
|
|
|
DefaultModuleCache);
|
2013-03-22 05:48:48 +08:00
|
|
|
llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");
|
|
|
|
llvm::sys::path::append(DefaultModuleCache, "ModuleCache");
|
2013-02-08 06:59:12 +08:00
|
|
|
const char Arg[] = "-fmodules-cache-path=";
|
|
|
|
DefaultModuleCache.insert(DefaultModuleCache.begin(),
|
|
|
|
Arg, Arg + strlen(Arg));
|
2013-02-08 03:01:24 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(DefaultModuleCache));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass through all -fmodules-ignore-macro arguments.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
|
2013-03-26 05:19:16 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
|
2013-02-08 03:01:24 +08:00
|
|
|
|
2010-04-10 03:12:06 +08:00
|
|
|
// -faccess-control is default.
|
2010-04-10 03:03:51 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fno_access_control,
|
|
|
|
options::OPT_faccess_control,
|
2010-04-10 03:12:06 +08:00
|
|
|
false))
|
2010-04-10 03:03:51 +08:00
|
|
|
CmdArgs.push_back("-fno-access-control");
|
2010-03-17 09:32:13 +08:00
|
|
|
|
2010-11-21 08:09:52 +08:00
|
|
|
// -felide-constructors is the default.
|
|
|
|
if (Args.hasFlag(options::OPT_fno_elide_constructors,
|
|
|
|
options::OPT_felide_constructors,
|
|
|
|
false))
|
|
|
|
CmdArgs.push_back("-fno-elide-constructors");
|
|
|
|
|
2009-11-17 15:06:20 +08:00
|
|
|
// -frtti is default.
|
2012-03-27 06:04:46 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti) ||
|
2012-11-06 06:04:41 +08:00
|
|
|
KernelOrKext) {
|
2009-11-19 12:55:23 +08:00
|
|
|
CmdArgs.push_back("-fno-rtti");
|
2009-08-01 07:15:31 +08:00
|
|
|
|
2012-11-06 06:04:41 +08:00
|
|
|
// -fno-rtti cannot usefully be combined with -fsanitize=vptr.
|
2012-11-06 23:09:03 +08:00
|
|
|
if (Sanitize.sanitizesVptr()) {
|
2012-11-07 06:02:00 +08:00
|
|
|
std::string NoRttiArg =
|
2012-11-06 06:04:41 +08:00
|
|
|
Args.getLastArg(options::OPT_mkernel,
|
|
|
|
options::OPT_fapple_kext,
|
2012-11-06 09:12:02 +08:00
|
|
|
options::OPT_fno_rtti)->getAsString(Args);
|
2012-11-06 06:04:41 +08:00
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< "-fsanitize=vptr" << NoRttiArg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
// -fshort-enums=0 is default for all architectures except Hexagon.
|
2010-10-08 08:25:19 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fshort_enums,
|
2011-12-13 05:14:55 +08:00
|
|
|
options::OPT_fno_short_enums,
|
|
|
|
getToolChain().getTriple().getArch() ==
|
|
|
|
llvm::Triple::hexagon))
|
2010-10-08 08:25:19 +08:00
|
|
|
CmdArgs.push_back("-fshort-enums");
|
|
|
|
|
2009-11-17 14:37:03 +08:00
|
|
|
// -fsigned-char is default.
|
2009-11-25 18:14:30 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char,
|
2009-11-17 14:37:03 +08:00
|
|
|
isSignedCharDefault(getToolChain().getTriple())))
|
2009-11-29 10:39:08 +08:00
|
|
|
CmdArgs.push_back("-fno-signed-char");
|
2009-06-05 15:21:14 +08:00
|
|
|
|
2010-02-07 07:23:06 +08:00
|
|
|
// -fthreadsafe-static is default.
|
2010-10-21 11:16:25 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
|
2010-02-07 07:23:06 +08:00
|
|
|
options::OPT_fno_threadsafe_statics))
|
|
|
|
CmdArgs.push_back("-fno-threadsafe-statics");
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
// -fuse-cxa-atexit is default.
|
2012-03-27 06:04:46 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fuse_cxa_atexit,
|
|
|
|
options::OPT_fno_use_cxa_atexit,
|
|
|
|
getToolChain().getTriple().getOS() != llvm::Triple::Cygwin &&
|
2011-12-13 05:14:55 +08:00
|
|
|
getToolChain().getTriple().getOS() != llvm::Triple::MinGW32 &&
|
2012-03-27 06:04:46 +08:00
|
|
|
getToolChain().getTriple().getArch() != llvm::Triple::hexagon) ||
|
|
|
|
KernelOrKext)
|
2010-03-20 12:15:41 +08:00
|
|
|
CmdArgs.push_back("-fno-use-cxa-atexit");
|
|
|
|
|
2009-11-17 15:06:20 +08:00
|
|
|
// -fms-extensions=0 is default.
|
2009-11-25 18:14:30 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
|
2009-11-17 15:06:20 +08:00
|
|
|
getToolChain().getTriple().getOS() == llvm::Triple::Win32))
|
|
|
|
CmdArgs.push_back("-fms-extensions");
|
|
|
|
|
2011-09-17 12:32:15 +08:00
|
|
|
// -fms-compatibility=0 is default.
|
2011-10-24 23:49:38 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fms_compatibility,
|
|
|
|
options::OPT_fno_ms_compatibility,
|
|
|
|
(getToolChain().getTriple().getOS() == llvm::Triple::Win32 &&
|
|
|
|
Args.hasFlag(options::OPT_fms_extensions,
|
|
|
|
options::OPT_fno_ms_extensions,
|
|
|
|
true))))
|
2011-09-17 12:32:15 +08:00
|
|
|
CmdArgs.push_back("-fms-compatibility");
|
|
|
|
|
2010-10-21 13:21:48 +08:00
|
|
|
// -fmsc-version=1300 is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
|
|
|
|
getToolChain().getTriple().getOS() == llvm::Triple::Win32) ||
|
|
|
|
Args.hasArg(options::OPT_fmsc_version)) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef msc_ver = Args.getLastArgValue(options::OPT_fmsc_version);
|
2010-10-21 13:21:48 +08:00
|
|
|
if (msc_ver.empty())
|
|
|
|
CmdArgs.push_back("-fmsc-version=1300");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-fmsc-version=" + msc_ver));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-18 08:38:31 +08:00
|
|
|
// -fno-borland-extensions is default.
|
2010-09-03 07:59:25 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fborland_extensions,
|
|
|
|
options::OPT_fno_borland_extensions, false))
|
|
|
|
CmdArgs.push_back("-fborland-extensions");
|
|
|
|
|
2011-09-02 00:38:08 +08:00
|
|
|
// -fno-delayed-template-parsing is default, except for Windows where MSVC STL
|
|
|
|
// needs it.
|
2011-04-23 06:18:13 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
|
|
|
|
options::OPT_fno_delayed_template_parsing,
|
2011-09-02 00:38:08 +08:00
|
|
|
getToolChain().getTriple().getOS() == llvm::Triple::Win32))
|
2011-08-26 08:22:34 +08:00
|
|
|
CmdArgs.push_back("-fdelayed-template-parsing");
|
2011-04-23 06:18:13 +08:00
|
|
|
|
2010-04-18 04:17:31 +08:00
|
|
|
// -fgnu-keywords default varies depending on language; only pass if
|
|
|
|
// specified.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords,
|
2010-04-25 01:56:39 +08:00
|
|
|
options::OPT_fno_gnu_keywords))
|
|
|
|
A->render(Args, CmdArgs);
|
2010-04-18 04:17:31 +08:00
|
|
|
|
2011-06-03 01:30:53 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fgnu89_inline,
|
|
|
|
options::OPT_fno_gnu89_inline,
|
|
|
|
false))
|
2011-06-03 00:13:27 +08:00
|
|
|
CmdArgs.push_back("-fgnu89-inline");
|
|
|
|
|
2012-03-16 06:31:42 +08:00
|
|
|
if (Args.hasArg(options::OPT_fno_inline))
|
|
|
|
CmdArgs.push_back("-fno-inline");
|
|
|
|
|
2012-03-07 05:17:19 +08:00
|
|
|
if (Args.hasArg(options::OPT_fno_inline_functions))
|
|
|
|
CmdArgs.push_back("-fno-inline-functions");
|
2012-03-07 02:49:20 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
ObjCRuntime objcRuntime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind);
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
// -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
|
|
|
|
// legacy is the default.
|
|
|
|
if (objcRuntime.isNonFragile()) {
|
2011-09-30 21:32:35 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
|
|
|
|
options::OPT_fno_objc_legacy_dispatch,
|
2012-07-04 19:52:24 +08:00
|
|
|
objcRuntime.isLegacyDispatchDefaultForArch(
|
|
|
|
getToolChain().getTriple().getArch()))) {
|
2011-09-30 21:32:35 +08:00
|
|
|
if (getToolChain().UseObjCMixedDispatch())
|
|
|
|
CmdArgs.push_back("-fobjc-dispatch-method=mixed");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-fobjc-dispatch-method=non-legacy");
|
2010-02-02 05:07:25 +08:00
|
|
|
}
|
2011-09-30 21:32:35 +08:00
|
|
|
}
|
2011-02-17 16:50:50 +08:00
|
|
|
|
2012-03-10 05:19:44 +08:00
|
|
|
// -fobjc-default-synthesize-properties=1 is default. This only has an effect
|
|
|
|
// if the nonfragile objc abi is used.
|
2012-04-10 02:58:55 +08:00
|
|
|
if (getToolChain().IsObjCDefaultSynthPropertiesDefault()) {
|
2011-09-30 21:32:35 +08:00
|
|
|
CmdArgs.push_back("-fobjc-default-synthesize-properties");
|
2009-11-17 16:07:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-16 03:02:45 +08:00
|
|
|
// -fencode-extended-block-signature=1 is default.
|
|
|
|
if (getToolChain().IsEncodeExtendedBlockSignatureDefault()) {
|
|
|
|
CmdArgs.push_back("-fencode-extended-block-signature");
|
|
|
|
}
|
|
|
|
|
2011-07-06 08:26:06 +08:00
|
|
|
// Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc.
|
|
|
|
// NOTE: This logic is duplicated in ToolChains.cpp.
|
|
|
|
bool ARC = isObjCAutoRefCount(Args);
|
|
|
|
if (ARC) {
|
2012-08-21 10:47:43 +08:00
|
|
|
getToolChain().CheckObjCARC();
|
2012-02-29 11:43:52 +08:00
|
|
|
|
2011-07-06 08:26:06 +08:00
|
|
|
CmdArgs.push_back("-fobjc-arc");
|
|
|
|
|
2011-11-04 15:34:47 +08:00
|
|
|
// FIXME: It seems like this entire block, and several around it should be
|
|
|
|
// wrapped in isObjC, but for now we just use it here as this is where it
|
|
|
|
// was being used previously.
|
|
|
|
if (types::isCXX(InputType) && types::isObjC(InputType)) {
|
|
|
|
if (getToolChain().GetCXXStdlibType(Args) == ToolChain::CST_Libcxx)
|
|
|
|
CmdArgs.push_back("-fobjc-arc-cxxlib=libc++");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-fobjc-arc-cxxlib=libstdc++");
|
|
|
|
}
|
|
|
|
|
2011-07-06 08:26:06 +08:00
|
|
|
// Allow the user to enable full exceptions code emission.
|
|
|
|
// We define off for Objective-CC, on for Objective-C++.
|
|
|
|
if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
|
|
|
|
options::OPT_fno_objc_arc_exceptions,
|
|
|
|
/*default*/ types::isCXX(InputType)))
|
|
|
|
CmdArgs.push_back("-fobjc-arc-exceptions");
|
|
|
|
}
|
|
|
|
|
|
|
|
// -fobjc-infer-related-result-type is the default, except in the Objective-C
|
|
|
|
// rewriter.
|
2012-06-20 14:18:46 +08:00
|
|
|
if (rewriteKind != RK_None)
|
2011-07-06 08:26:06 +08:00
|
|
|
CmdArgs.push_back("-fno-objc-infer-related-result-type");
|
2011-08-19 08:30:14 +08:00
|
|
|
|
2011-07-06 08:26:06 +08:00
|
|
|
// Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
|
|
|
|
// takes precedence.
|
|
|
|
const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only);
|
|
|
|
if (!GCArg)
|
|
|
|
GCArg = Args.getLastArg(options::OPT_fobjc_gc);
|
|
|
|
if (GCArg) {
|
|
|
|
if (ARC) {
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_objc_gc_arr)
|
2011-07-06 08:26:06 +08:00
|
|
|
<< GCArg->getAsString(Args);
|
|
|
|
} else if (getToolChain().SupportsObjCGC()) {
|
|
|
|
GCArg->render(Args, CmdArgs);
|
|
|
|
} else {
|
|
|
|
// FIXME: We should move this to a hard error.
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_objc_gc_unsupported)
|
2011-07-06 08:26:06 +08:00
|
|
|
<< GCArg->getAsString(Args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 08:53:57 +08:00
|
|
|
// Add exception args.
|
|
|
|
addExceptionArgs(Args, InputType, getToolChain().getTriple(),
|
2012-06-20 14:18:46 +08:00
|
|
|
KernelOrKext, objcRuntime, CmdArgs);
|
2011-06-22 08:53:57 +08:00
|
|
|
|
|
|
|
if (getToolChain().UseSjLjExceptions())
|
|
|
|
CmdArgs.push_back("-fsjlj-exceptions");
|
|
|
|
|
|
|
|
// C++ "sane" operator new.
|
2010-02-02 05:07:25 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
|
|
|
|
options::OPT_fno_assume_sane_operator_new))
|
|
|
|
CmdArgs.push_back("-fno-assume-sane-operator-new");
|
|
|
|
|
2010-04-27 23:34:57 +08:00
|
|
|
// -fconstant-cfstrings is default, and may be subject to argument translation
|
|
|
|
// on Darwin.
|
|
|
|
if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
|
|
|
|
options::OPT_fno_constant_cfstrings) ||
|
|
|
|
!Args.hasFlag(options::OPT_mconstant_cfstrings,
|
|
|
|
options::OPT_mno_constant_cfstrings))
|
|
|
|
CmdArgs.push_back("-fno-constant-cfstrings");
|
|
|
|
|
2009-11-06 04:14:16 +08:00
|
|
|
// -fshort-wchar default varies depending on platform; only
|
|
|
|
// pass if specified.
|
2010-04-27 23:35:03 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar))
|
|
|
|
A->render(Args, CmdArgs);
|
2009-11-06 04:14:16 +08:00
|
|
|
|
2009-10-29 10:39:57 +08:00
|
|
|
// -fno-pascal-strings is default, only pass non-default. If the tool chain
|
|
|
|
// happened to translate to -mpascal-strings, we want to back translate here.
|
2009-04-08 07:51:44 +08:00
|
|
|
//
|
|
|
|
// FIXME: This is gross; that translation should be pulled from the
|
|
|
|
// tool chain.
|
2009-04-09 07:54:23 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fpascal_strings,
|
2009-04-08 07:51:44 +08:00
|
|
|
options::OPT_fno_pascal_strings,
|
|
|
|
false) ||
|
|
|
|
Args.hasFlag(options::OPT_mpascal_strings,
|
|
|
|
options::OPT_mno_pascal_strings,
|
|
|
|
false))
|
2009-04-08 05:16:11 +08:00
|
|
|
CmdArgs.push_back("-fpascal-strings");
|
2011-02-17 16:50:50 +08:00
|
|
|
|
2011-10-06 05:04:55 +08:00
|
|
|
// Honor -fpack-struct= and -fpack-struct, if given. Note that
|
|
|
|
// -fno-pack-struct doesn't apply to -fpack-struct=.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
|
2012-05-02 15:56:14 +08:00
|
|
|
std::string PackStructStr = "-fpack-struct=";
|
2012-11-01 12:30:05 +08:00
|
|
|
PackStructStr += A->getValue();
|
2012-05-02 15:56:14 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(PackStructStr));
|
2011-10-06 05:04:55 +08:00
|
|
|
} else if (Args.hasFlag(options::OPT_fpack_struct,
|
|
|
|
options::OPT_fno_pack_struct, false)) {
|
2012-05-02 15:56:14 +08:00
|
|
|
CmdArgs.push_back("-fpack-struct=1");
|
2011-10-06 05:04:55 +08:00
|
|
|
}
|
|
|
|
|
2013-02-18 09:16:37 +08:00
|
|
|
if (KernelOrKext) {
|
2011-01-07 09:05:02 +08:00
|
|
|
if (!Args.hasArg(options::OPT_fcommon))
|
|
|
|
CmdArgs.push_back("-fno-common");
|
2012-03-27 05:35:40 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_fno_common);
|
2011-01-07 09:05:02 +08:00
|
|
|
}
|
2011-10-06 05:04:55 +08:00
|
|
|
|
2009-04-08 05:16:11 +08:00
|
|
|
// -fcommon is default, only pass non-default.
|
2011-01-07 09:05:02 +08:00
|
|
|
else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
|
2009-04-08 05:16:11 +08:00
|
|
|
CmdArgs.push_back("-fno-common");
|
|
|
|
|
2009-04-15 10:37:43 +08:00
|
|
|
// -fsigned-bitfields is default, and clang doesn't yet support
|
2010-10-16 06:30:42 +08:00
|
|
|
// -funsigned-bitfields.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fsigned_bitfields,
|
2009-04-15 10:37:43 +08:00
|
|
|
options::OPT_funsigned_bitfields))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_clang_unsupported)
|
2009-04-15 10:37:43 +08:00
|
|
|
<< Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
|
|
|
|
|
2010-10-16 06:30:42 +08:00
|
|
|
// -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
|
|
|
|
if (!Args.hasFlag(options::OPT_ffor_scope,
|
|
|
|
options::OPT_fno_for_scope))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_clang_unsupported)
|
2010-10-16 06:30:42 +08:00
|
|
|
<< Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
|
|
|
|
|
2010-06-08 12:56:20 +08:00
|
|
|
// -fcaret-diagnostics is default.
|
|
|
|
if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
|
|
|
|
options::OPT_fno_caret_diagnostics, true))
|
|
|
|
CmdArgs.push_back("-fno-caret-diagnostics");
|
|
|
|
|
2009-04-20 05:09:34 +08:00
|
|
|
// -fdiagnostics-fixit-info is default, only pass non-default.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info,
|
2009-04-20 05:09:34 +08:00
|
|
|
options::OPT_fno_diagnostics_fixit_info))
|
|
|
|
CmdArgs.push_back("-fno-diagnostics-fixit-info");
|
2011-08-19 08:30:14 +08:00
|
|
|
|
2009-04-16 14:32:38 +08:00
|
|
|
// Enable -fdiagnostics-show-option by default.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fdiagnostics_show_option,
|
2009-04-16 14:32:38 +08:00
|
|
|
options::OPT_fno_diagnostics_show_option))
|
|
|
|
CmdArgs.push_back("-fdiagnostics-show-option");
|
2009-11-04 14:24:57 +08:00
|
|
|
|
2010-05-05 05:55:25 +08:00
|
|
|
if (const Arg *A =
|
|
|
|
Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
|
|
|
|
CmdArgs.push_back("-fdiagnostics-show-category");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2010-05-05 05:55:25 +08:00
|
|
|
}
|
2010-08-25 00:47:49 +08:00
|
|
|
|
2011-05-22 01:07:29 +08:00
|
|
|
if (const Arg *A =
|
|
|
|
Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
|
|
|
|
CmdArgs.push_back("-fdiagnostics-format");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2011-05-22 01:07:29 +08:00
|
|
|
}
|
|
|
|
|
2011-03-27 09:50:55 +08:00
|
|
|
if (Arg *A = Args.getLastArg(
|
|
|
|
options::OPT_fdiagnostics_show_note_include_stack,
|
|
|
|
options::OPT_fno_diagnostics_show_note_include_stack)) {
|
|
|
|
if (A->getOption().matches(
|
|
|
|
options::OPT_fdiagnostics_show_note_include_stack))
|
|
|
|
CmdArgs.push_back("-fdiagnostics-show-note-include-stack");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-fno-diagnostics-show-note-include-stack");
|
|
|
|
}
|
|
|
|
|
2009-11-04 14:24:57 +08:00
|
|
|
// Color diagnostics are the default, unless the terminal doesn't support
|
|
|
|
// them.
|
2013-04-18 05:52:44 +08:00
|
|
|
// Support both clang's -f[no-]color-diagnostics and gcc's
|
|
|
|
// -f[no-]diagnostics-colors[=never|always|auto].
|
|
|
|
enum { Colors_On, Colors_Off, Colors_Auto } ShowColors = Colors_Auto;
|
|
|
|
for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
|
|
|
|
it != ie; ++it) {
|
|
|
|
const Option &O = (*it)->getOption();
|
|
|
|
if (!O.matches(options::OPT_fcolor_diagnostics) &&
|
|
|
|
!O.matches(options::OPT_fdiagnostics_color) &&
|
|
|
|
!O.matches(options::OPT_fno_color_diagnostics) &&
|
|
|
|
!O.matches(options::OPT_fno_diagnostics_color) &&
|
|
|
|
!O.matches(options::OPT_fdiagnostics_color_EQ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
(*it)->claim();
|
|
|
|
if (O.matches(options::OPT_fcolor_diagnostics) ||
|
|
|
|
O.matches(options::OPT_fdiagnostics_color)) {
|
|
|
|
ShowColors = Colors_On;
|
|
|
|
} else if (O.matches(options::OPT_fno_color_diagnostics) ||
|
|
|
|
O.matches(options::OPT_fno_diagnostics_color)) {
|
|
|
|
ShowColors = Colors_Off;
|
|
|
|
} else {
|
|
|
|
assert(O.matches(options::OPT_fdiagnostics_color_EQ));
|
|
|
|
StringRef value((*it)->getValue());
|
|
|
|
if (value == "always")
|
|
|
|
ShowColors = Colors_On;
|
|
|
|
else if (value == "never")
|
|
|
|
ShowColors = Colors_Off;
|
|
|
|
else if (value == "auto")
|
|
|
|
ShowColors = Colors_Auto;
|
|
|
|
else
|
|
|
|
getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported)
|
|
|
|
<< ("-fdiagnostics-color=" + value).str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ShowColors == Colors_On ||
|
|
|
|
(ShowColors == Colors_Auto && llvm::sys::Process::StandardErrHasColors()))
|
2009-11-04 14:24:57 +08:00
|
|
|
CmdArgs.push_back("-fcolor-diagnostics");
|
|
|
|
|
2009-06-09 05:13:54 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fshow_source_location,
|
|
|
|
options::OPT_fno_show_source_location))
|
|
|
|
CmdArgs.push_back("-fno-show-source-location");
|
2009-04-16 14:32:38 +08:00
|
|
|
|
2011-05-22 01:07:29 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fshow_column,
|
|
|
|
options::OPT_fno_show_column,
|
|
|
|
true))
|
|
|
|
CmdArgs.push_back("-fno-show-column");
|
|
|
|
|
2010-07-10 01:35:33 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fspell_checking,
|
|
|
|
options::OPT_fno_spell_checking))
|
|
|
|
CmdArgs.push_back("-fno-spell-checking");
|
2010-08-25 00:47:49 +08:00
|
|
|
|
2010-10-19 06:49:46 +08:00
|
|
|
|
2012-12-06 05:08:21 +08:00
|
|
|
// -fno-asm-blocks is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks,
|
|
|
|
false))
|
|
|
|
CmdArgs.push_back("-fasm-blocks");
|
2010-10-19 06:49:46 +08:00
|
|
|
|
2013-04-25 02:29:59 +08:00
|
|
|
// If -Ofast is the optimization level, then -fvectorize should be enabled.
|
|
|
|
// This alias option is being used to simplify the hasFlag logic.
|
|
|
|
OptSpecifier VectorizeAliasOption = OFastEnabled ? options::OPT_Ofast :
|
|
|
|
options::OPT_fvectorize;
|
|
|
|
|
2012-12-19 07:10:16 +08:00
|
|
|
// -fvectorize is default.
|
2013-04-25 02:29:59 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
|
2013-06-25 09:49:44 +08:00
|
|
|
options::OPT_fno_vectorize, true))
|
2012-12-12 01:12:28 +08:00
|
|
|
CmdArgs.push_back("-vectorize-loops");
|
|
|
|
|
2012-12-12 03:59:32 +08:00
|
|
|
// -fno-slp-vectorize is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fslp_vectorize,
|
2013-06-25 09:49:44 +08:00
|
|
|
options::OPT_fno_slp_vectorize, false))
|
2013-04-15 12:57:18 +08:00
|
|
|
CmdArgs.push_back("-vectorize-slp");
|
2012-12-12 03:59:32 +08:00
|
|
|
|
2013-04-15 13:38:41 +08:00
|
|
|
// -fno-slp-vectorize-aggressive is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fslp_vectorize_aggressive,
|
2013-06-25 09:49:44 +08:00
|
|
|
options::OPT_fno_slp_vectorize_aggressive, false))
|
2013-04-15 13:38:41 +08:00
|
|
|
CmdArgs.push_back("-vectorize-slp-aggressive");
|
|
|
|
|
2010-06-11 13:57:47 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ))
|
|
|
|
A->render(Args, CmdArgs);
|
|
|
|
|
2009-04-20 05:20:32 +08:00
|
|
|
// -fdollars-in-identifiers default varies depending on platform and
|
|
|
|
// language; only pass if specified.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
|
2009-04-20 05:20:32 +08:00
|
|
|
options::OPT_fno_dollars_in_identifiers)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
|
2009-12-17 04:10:18 +08:00
|
|
|
CmdArgs.push_back("-fdollars-in-identifiers");
|
2009-04-20 05:20:32 +08:00
|
|
|
else
|
2009-12-17 04:10:18 +08:00
|
|
|
CmdArgs.push_back("-fno-dollars-in-identifiers");
|
2009-04-20 05:20:32 +08:00
|
|
|
}
|
|
|
|
|
2009-05-23 03:02:20 +08:00
|
|
|
// -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
|
|
|
|
// practical purposes.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time,
|
2009-05-23 03:02:20 +08:00
|
|
|
options::OPT_fno_unit_at_a_time)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fno_unit_at_a_time))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::warn_drv_clang_unsupported) << A->getAsString(Args);
|
2009-05-23 03:02:20 +08:00
|
|
|
}
|
2009-07-15 05:58:17 +08:00
|
|
|
|
2011-11-02 09:53:16 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fapple_pragma_pack,
|
|
|
|
options::OPT_fno_apple_pragma_pack, false))
|
|
|
|
CmdArgs.push_back("-fapple-pragma-pack");
|
|
|
|
|
2009-09-10 11:37:02 +08:00
|
|
|
// Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
|
2009-09-10 12:57:27 +08:00
|
|
|
//
|
2009-12-12 07:00:49 +08:00
|
|
|
// FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
|
2009-09-10 12:57:27 +08:00
|
|
|
#if 0
|
2011-10-14 13:03:44 +08:00
|
|
|
if (getToolChain().getTriple().isOSDarwin() &&
|
2009-09-10 11:37:02 +08:00
|
|
|
(getToolChain().getTriple().getArch() == llvm::Triple::arm ||
|
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::thumb)) {
|
|
|
|
if (!Args.hasArg(options::OPT_fbuiltin_strcat))
|
|
|
|
CmdArgs.push_back("-fno-builtin-strcat");
|
|
|
|
if (!Args.hasArg(options::OPT_fbuiltin_strcpy))
|
|
|
|
CmdArgs.push_back("-fno-builtin-strcpy");
|
|
|
|
}
|
2009-09-10 12:57:27 +08:00
|
|
|
#endif
|
2009-09-10 11:37:02 +08:00
|
|
|
|
2011-03-19 05:23:40 +08:00
|
|
|
// Only allow -traditional or -traditional-cpp outside in preprocessing modes.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_traditional,
|
2011-03-19 05:23:40 +08:00
|
|
|
options::OPT_traditional_cpp)) {
|
|
|
|
if (isa<PreprocessJobAction>(JA))
|
|
|
|
CmdArgs.push_back("-traditional-cpp");
|
2011-08-19 08:30:14 +08:00
|
|
|
else
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
2011-03-19 05:23:40 +08:00
|
|
|
}
|
2009-07-15 05:58:17 +08:00
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_dM);
|
2009-04-12 09:56:53 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_dD);
|
2011-11-11 08:07:43 +08:00
|
|
|
|
|
|
|
// Handle serialized diagnostics.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
|
|
|
|
CmdArgs.push_back("-serialize-diagnostic-file");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(A->getValue()));
|
2011-11-11 08:07:43 +08:00
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2012-09-13 14:41:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
|
|
|
|
CmdArgs.push_back("-fretain-comments-from-system-headers");
|
|
|
|
|
2013-02-22 22:21:27 +08:00
|
|
|
// Forward -fcomment-block-commands to -cc1.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
|
2013-04-10 23:35:17 +08:00
|
|
|
// Forward -fparse-all-comments to -cc1.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
|
2013-02-22 22:21:27 +08:00
|
|
|
|
2010-04-15 14:09:03 +08:00
|
|
|
// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
|
|
|
|
// parser.
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
|
2010-04-15 14:09:03 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
(*it)->claim();
|
2010-04-17 14:10:00 +08:00
|
|
|
|
2010-04-15 14:09:03 +08:00
|
|
|
// We translate this by hand to the -cc1 argument, since nightly test uses
|
|
|
|
// it and developers have been trained to spell it with -mllvm.
|
2012-11-01 12:30:05 +08:00
|
|
|
if (StringRef((*it)->getValue(0)) == "-disable-llvm-optzns")
|
2010-04-15 14:09:03 +08:00
|
|
|
CmdArgs.push_back("-disable-llvm-optzns");
|
|
|
|
else
|
2010-06-12 06:00:13 +08:00
|
|
|
(*it)->render(Args, CmdArgs);
|
2010-04-15 14:09:03 +08:00
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2009-03-30 14:36:42 +08:00
|
|
|
if (Output.getType() == types::TY_Dependencies) {
|
|
|
|
// Handled with other dependency code.
|
2009-03-19 15:29:38 +08:00
|
|
|
} else if (Output.isFilename()) {
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-o");
|
2009-03-19 15:29:38 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
CmdArgs.push_back("-x");
|
2012-09-29 03:05:17 +08:00
|
|
|
if (Args.hasArg(options::OPT_rewrite_objc))
|
|
|
|
CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(types::getTypeName(II.getType()));
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-03-19 15:29:38 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-03-18 18:01:51 +08:00
|
|
|
else
|
2009-03-19 15:29:38 +08:00
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
2009-03-18 18:01:51 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-11-04 03:50:27 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_undef);
|
|
|
|
|
2010-07-19 05:16:15 +08:00
|
|
|
const char *Exec = getToolChain().getDriver().getClangProgramPath();
|
2009-12-18 10:43:17 +08:00
|
|
|
|
|
|
|
// Optionally embed the -cc1 level arguments into the debug info, for build
|
|
|
|
// analysis.
|
|
|
|
if (getToolChain().UseDwarfDebugFlags()) {
|
2010-06-05 02:47:06 +08:00
|
|
|
ArgStringList OriginalArgs;
|
|
|
|
for (ArgList::const_iterator it = Args.begin(),
|
|
|
|
ie = Args.end(); it != ie; ++it)
|
|
|
|
(*it)->render(Args, OriginalArgs);
|
2010-08-25 00:47:49 +08:00
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Flags;
|
2009-12-18 10:43:17 +08:00
|
|
|
Flags += Exec;
|
2010-06-05 02:47:06 +08:00
|
|
|
for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
|
2009-12-18 10:43:17 +08:00
|
|
|
Flags += " ";
|
2010-06-05 02:47:06 +08:00
|
|
|
Flags += OriginalArgs[i];
|
2009-12-18 10:43:17 +08:00
|
|
|
}
|
|
|
|
CmdArgs.push_back("-dwarf-debug-flags");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Flags.str()));
|
|
|
|
}
|
|
|
|
|
2013-02-23 04:12:52 +08:00
|
|
|
// Add the split debug info name to the command lines here so we
|
|
|
|
// can propagate it to the backend.
|
|
|
|
bool SplitDwarf = Args.hasArg(options::OPT_gsplit_dwarf) &&
|
|
|
|
(getToolChain().getTriple().getOS() == llvm::Triple::Linux) &&
|
2013-02-23 07:50:16 +08:00
|
|
|
(isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA));
|
2013-02-23 04:12:52 +08:00
|
|
|
const char *SplitDwarfOut;
|
|
|
|
if (SplitDwarf) {
|
|
|
|
CmdArgs.push_back("-split-dwarf-file");
|
|
|
|
SplitDwarfOut = SplitDebugName(Args, Inputs);
|
|
|
|
CmdArgs.push_back(SplitDwarfOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally add the compile command to the compilation.
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
Driver: Add two special groups of "whitelisted" options which we know
clang doesn't support, and don't want to warn are unused. Eventually
these should disappear.
Here is a more readable list than is in the diff:
W options: -Wall, -Wcast-align, -Wchar-align, -Wchar-subscripts,
-Werror, -Wextra, -Winline, -Wint-to-pointer-cast, -Wmissing-braces,
-Wmost, -Wnested-externs, -Wno-format-y2k, -Wno-four-char-constants,
-Wno-missing-field-initializers, -Wno-trigraphs, -Wno-unknown-pragmas,
-Wno-unused-parameter, -Wparentheses, -Wpointer-arith,
-Wpointer-to-int-cast, -Wreturn-type, -Wshorten-64-to-32, -Wswitch,
-Wunused-function, -Wunused-label, -Wunused-value, -Wunused-variable,
-Wwrite-strings.
f options: -fasm-blocks, -fmessage-length=.
llvm-svn: 67549
2009-03-24 03:03:36 +08:00
|
|
|
|
2013-02-23 07:50:16 +08:00
|
|
|
// Handle the debug info splitting at object creation time if we're
|
|
|
|
// creating an object.
|
2013-02-22 06:35:01 +08:00
|
|
|
// TODO: Currently only works on linux with newer objcopy.
|
2013-02-23 07:50:16 +08:00
|
|
|
if (SplitDwarf && !isa<CompileJobAction>(JA))
|
2013-02-23 04:12:52 +08:00
|
|
|
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDwarfOut);
|
2013-02-22 06:35:01 +08:00
|
|
|
|
2011-02-11 00:52:03 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_pg))
|
|
|
|
if (Args.hasArg(options::OPT_fomit_frame_pointer))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
2011-02-11 00:52:03 +08:00
|
|
|
<< "-fomit-frame-pointer" << A->getAsString(Args);
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2009-04-04 04:51:31 +08:00
|
|
|
// Claim some arguments which clang supports automatically.
|
|
|
|
|
2010-04-15 14:18:42 +08:00
|
|
|
// -fpch-preprocess is used with gcc to add a special marker in the output to
|
|
|
|
// include the PCH file. Clang's PTH solution is completely transparent, so we
|
|
|
|
// do not need to deal with it at all.
|
2009-04-04 04:51:31 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_fpch_preprocess);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
Driver: Add two special groups of "whitelisted" options which we know
clang doesn't support, and don't want to warn are unused. Eventually
these should disappear.
Here is a more readable list than is in the diff:
W options: -Wall, -Wcast-align, -Wchar-align, -Wchar-subscripts,
-Werror, -Wextra, -Winline, -Wint-to-pointer-cast, -Wmissing-braces,
-Wmost, -Wnested-externs, -Wno-format-y2k, -Wno-four-char-constants,
-Wno-missing-field-initializers, -Wno-trigraphs, -Wno-unknown-pragmas,
-Wno-unused-parameter, -Wparentheses, -Wpointer-arith,
-Wpointer-to-int-cast, -Wreturn-type, -Wshorten-64-to-32, -Wswitch,
-Wunused-function, -Wunused-label, -Wunused-value, -Wunused-variable,
-Wwrite-strings.
f options: -fasm-blocks, -fmessage-length=.
llvm-svn: 67549
2009-03-24 03:03:36 +08:00
|
|
|
// Claim some arguments which clang doesn't support, but we don't
|
|
|
|
// care to warn the user about.
|
2009-11-25 19:53:23 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
|
|
|
|
Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
|
2011-03-01 07:29:45 +08:00
|
|
|
|
2011-03-01 13:25:27 +08:00
|
|
|
// Disable warnings for clang -E -use-gold-plugin -emit-llvm foo.c
|
2011-03-01 07:29:45 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_use_gold_plugin);
|
2011-03-01 13:25:27 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
2012-02-11 04:37:10 +08:00
|
|
|
void ClangAs::AddARMTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
llvm::Triple Triple = getToolChain().getTriple();
|
|
|
|
|
|
|
|
// Set the CPU based on -march= and -mcpu=.
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
2012-06-27 06:20:06 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getARMTargetCPU(Args, Triple)));
|
2012-02-11 04:37:10 +08:00
|
|
|
|
|
|
|
// Honor -mfpu=.
|
2012-04-05 04:51:35 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ))
|
2012-04-05 04:56:36 +08:00
|
|
|
addFPUArgs(D, A, Args, CmdArgs);
|
2012-04-05 04:39:32 +08:00
|
|
|
|
|
|
|
// Honor -mfpmath=.
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ))
|
2012-04-05 06:13:40 +08:00
|
|
|
addFPMathArgs(D, A, Args, CmdArgs, getARMTargetCPU(Args, Triple));
|
2012-02-11 04:37:10 +08:00
|
|
|
}
|
|
|
|
|
2013-02-23 04:55:17 +08:00
|
|
|
void ClangAs::AddX86TargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
// Set the CPU based on -march=.
|
|
|
|
if (const char *CPUName = getX86TargetCPU(Args, getToolChain().getTriple())) {
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
|
|
|
CmdArgs.push_back(CPUName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
/// Add options related to the Objective-C runtime/ABI.
|
|
|
|
///
|
|
|
|
/// Returns true if the runtime is non-fragile.
|
|
|
|
ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
|
|
|
|
ArgStringList &cmdArgs,
|
|
|
|
RewriteKind rewriteKind) const {
|
|
|
|
// Look for the controlling runtime option.
|
|
|
|
Arg *runtimeArg = args.getLastArg(options::OPT_fnext_runtime,
|
|
|
|
options::OPT_fgnu_runtime,
|
|
|
|
options::OPT_fobjc_runtime_EQ);
|
|
|
|
|
|
|
|
// Just forward -fobjc-runtime= to the frontend. This supercedes
|
|
|
|
// options about fragility.
|
|
|
|
if (runtimeArg &&
|
|
|
|
runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) {
|
|
|
|
ObjCRuntime runtime;
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef value = runtimeArg->getValue();
|
2012-06-20 14:18:46 +08:00
|
|
|
if (runtime.tryParse(value)) {
|
|
|
|
getToolChain().getDriver().Diag(diag::err_drv_unknown_objc_runtime)
|
|
|
|
<< value;
|
|
|
|
}
|
|
|
|
|
|
|
|
runtimeArg->render(args, cmdArgs);
|
|
|
|
return runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we'll need the ABI "version". Version numbers are
|
|
|
|
// slightly confusing for historical reasons:
|
|
|
|
// 1 - Traditional "fragile" ABI
|
|
|
|
// 2 - Non-fragile ABI, version 1
|
|
|
|
// 3 - Non-fragile ABI, version 2
|
|
|
|
unsigned objcABIVersion = 1;
|
|
|
|
// If -fobjc-abi-version= is present, use that to set the version.
|
|
|
|
if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef value = abiArg->getValue();
|
2012-06-20 14:18:46 +08:00
|
|
|
if (value == "1")
|
|
|
|
objcABIVersion = 1;
|
|
|
|
else if (value == "2")
|
|
|
|
objcABIVersion = 2;
|
|
|
|
else if (value == "3")
|
|
|
|
objcABIVersion = 3;
|
|
|
|
else
|
|
|
|
getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported)
|
|
|
|
<< value;
|
|
|
|
} else {
|
|
|
|
// Otherwise, determine if we are using the non-fragile ABI.
|
|
|
|
bool nonFragileABIIsDefault =
|
|
|
|
(rewriteKind == RK_NonFragile ||
|
|
|
|
(rewriteKind == RK_None &&
|
|
|
|
getToolChain().IsObjCNonFragileABIDefault()));
|
|
|
|
if (args.hasFlag(options::OPT_fobjc_nonfragile_abi,
|
|
|
|
options::OPT_fno_objc_nonfragile_abi,
|
|
|
|
nonFragileABIIsDefault)) {
|
|
|
|
// Determine the non-fragile ABI version to use.
|
|
|
|
#ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
|
|
|
|
unsigned nonFragileABIVersion = 1;
|
|
|
|
#else
|
|
|
|
unsigned nonFragileABIVersion = 2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (Arg *abiArg = args.getLastArg(
|
|
|
|
options::OPT_fobjc_nonfragile_abi_version_EQ)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
StringRef value = abiArg->getValue();
|
2012-06-20 14:18:46 +08:00
|
|
|
if (value == "1")
|
|
|
|
nonFragileABIVersion = 1;
|
|
|
|
else if (value == "2")
|
|
|
|
nonFragileABIVersion = 2;
|
|
|
|
else
|
|
|
|
getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported)
|
|
|
|
<< value;
|
|
|
|
}
|
|
|
|
|
|
|
|
objcABIVersion = 1 + nonFragileABIVersion;
|
|
|
|
} else {
|
|
|
|
objcABIVersion = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't actually care about the ABI version other than whether
|
|
|
|
// it's non-fragile.
|
|
|
|
bool isNonFragile = objcABIVersion != 1;
|
|
|
|
|
|
|
|
// If we have no runtime argument, ask the toolchain for its default runtime.
|
|
|
|
// However, the rewriter only really supports the Mac runtime, so assume that.
|
|
|
|
ObjCRuntime runtime;
|
|
|
|
if (!runtimeArg) {
|
|
|
|
switch (rewriteKind) {
|
|
|
|
case RK_None:
|
|
|
|
runtime = getToolChain().getDefaultObjCRuntime(isNonFragile);
|
|
|
|
break;
|
|
|
|
case RK_Fragile:
|
|
|
|
runtime = ObjCRuntime(ObjCRuntime::FragileMacOSX, VersionTuple());
|
|
|
|
break;
|
|
|
|
case RK_NonFragile:
|
|
|
|
runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -fnext-runtime
|
|
|
|
} else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) {
|
|
|
|
// On Darwin, make this use the default behavior for the toolchain.
|
|
|
|
if (getToolChain().getTriple().isOSDarwin()) {
|
|
|
|
runtime = getToolChain().getDefaultObjCRuntime(isNonFragile);
|
|
|
|
|
|
|
|
// Otherwise, build for a generic macosx port.
|
|
|
|
} else {
|
|
|
|
runtime = ObjCRuntime(ObjCRuntime::MacOSX, VersionTuple());
|
|
|
|
}
|
|
|
|
|
|
|
|
// -fgnu-runtime
|
|
|
|
} else {
|
|
|
|
assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime));
|
2012-07-04 18:37:03 +08:00
|
|
|
// Legacy behaviour is to target the gnustep runtime if we are i
|
|
|
|
// non-fragile mode or the GCC runtime in fragile mode.
|
|
|
|
if (isNonFragile)
|
2012-10-16 23:11:55 +08:00
|
|
|
runtime = ObjCRuntime(ObjCRuntime::GNUstep, VersionTuple(1,6));
|
2012-07-04 18:37:03 +08:00
|
|
|
else
|
|
|
|
runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple());
|
2012-06-20 14:18:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cmdArgs.push_back(args.MakeArgString(
|
|
|
|
"-fobjc-runtime=" + runtime.getAsString()));
|
|
|
|
return runtime;
|
|
|
|
}
|
|
|
|
|
2010-05-21 05:30:13 +08:00
|
|
|
void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unexpected number of inputs.");
|
|
|
|
const InputInfo &Input = Inputs[0];
|
|
|
|
|
2010-11-18 06:13:25 +08:00
|
|
|
// Don't warn about "clang -w -c foo.s"
|
|
|
|
Args.ClaimAllArgs(options::OPT_w);
|
2011-03-01 13:25:27 +08:00
|
|
|
// and "clang -emit-llvm -c foo.s"
|
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
|
|
|
// and "clang -use-gold-plugin -c foo.s"
|
|
|
|
Args.ClaimAllArgs(options::OPT_use_gold_plugin);
|
2010-11-18 06:13:25 +08:00
|
|
|
|
2010-05-21 05:30:13 +08:00
|
|
|
// Invoke ourselves in -cc1as mode.
|
|
|
|
//
|
|
|
|
// FIXME: Implement custom jobs for internal actions.
|
|
|
|
CmdArgs.push_back("-cc1as");
|
|
|
|
|
|
|
|
// Add the "effective" target triple.
|
|
|
|
CmdArgs.push_back("-triple");
|
2011-09-21 04:44:06 +08:00
|
|
|
std::string TripleStr =
|
|
|
|
getToolChain().ComputeEffectiveClangTriple(Args, Input.getType());
|
2010-05-21 05:30:13 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(TripleStr));
|
|
|
|
|
|
|
|
// Set the output mode, we currently only expect to be used as a real
|
|
|
|
// assembler.
|
|
|
|
CmdArgs.push_back("-filetype");
|
|
|
|
CmdArgs.push_back("obj");
|
|
|
|
|
2012-12-18 08:31:10 +08:00
|
|
|
// Set the main file name, so that debug info works even with
|
|
|
|
// -save-temps or preprocessed assembly.
|
|
|
|
CmdArgs.push_back("-main-file-name");
|
|
|
|
CmdArgs.push_back(Clang::getBaseInputName(Args, Inputs));
|
|
|
|
|
2011-05-06 22:35:16 +08:00
|
|
|
if (UseRelaxAll(C, Args))
|
2010-05-29 00:43:21 +08:00
|
|
|
CmdArgs.push_back("-relax-all");
|
2010-05-27 14:18:05 +08:00
|
|
|
|
2012-02-11 04:37:10 +08:00
|
|
|
// Add target specific cpu and features flags.
|
|
|
|
switch(getToolChain().getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb:
|
|
|
|
AddARMTargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
2013-02-23 04:55:17 +08:00
|
|
|
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
AddX86TargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
2012-02-11 04:37:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-18 01:37:29 +08:00
|
|
|
// Ignore explicit -force_cpusubtype_ALL option.
|
|
|
|
(void) Args.hasArg(options::OPT_force__cpusubtype__ALL);
|
2010-05-21 05:30:13 +08:00
|
|
|
|
2012-01-10 08:38:01 +08:00
|
|
|
// Determine the original source input.
|
|
|
|
const Action *SourceAction = &JA;
|
|
|
|
while (SourceAction->getKind() != Action::InputClass) {
|
|
|
|
assert(!SourceAction->getInputs().empty() && "unexpected root action!");
|
|
|
|
SourceAction = SourceAction->getInputs()[0];
|
|
|
|
}
|
|
|
|
|
2012-12-18 05:40:04 +08:00
|
|
|
// Forward -g and handle debug info related flags, assuming we are dealing
|
|
|
|
// with an actual assembly file.
|
2012-01-10 08:38:01 +08:00
|
|
|
if (SourceAction->getType() == types::TY_Asm ||
|
|
|
|
SourceAction->getType() == types::TY_PP_Asm) {
|
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_g_Group))
|
|
|
|
if (!A->getOption().matches(options::OPT_g0))
|
|
|
|
CmdArgs.push_back("-g");
|
2012-12-18 05:40:04 +08:00
|
|
|
|
|
|
|
// Add the -fdebug-compilation-dir flag if needed.
|
|
|
|
addDebugCompDirArg(Args, CmdArgs);
|
2013-01-18 05:38:06 +08:00
|
|
|
|
|
|
|
// Set the AT_producer to the clang version when using the integrated
|
|
|
|
// assembler on assembly source files.
|
|
|
|
CmdArgs.push_back("-dwarf-debug-producer");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(getClangFullVersion()));
|
2012-01-10 08:38:01 +08:00
|
|
|
}
|
2011-12-23 03:31:58 +08:00
|
|
|
|
|
|
|
// Optionally embed the -cc1as level arguments into the debug info, for build
|
|
|
|
// analysis.
|
|
|
|
if (getToolChain().UseDwarfDebugFlags()) {
|
|
|
|
ArgStringList OriginalArgs;
|
|
|
|
for (ArgList::const_iterator it = Args.begin(),
|
|
|
|
ie = Args.end(); it != ie; ++it)
|
|
|
|
(*it)->render(Args, OriginalArgs);
|
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Flags;
|
2011-12-23 03:31:58 +08:00
|
|
|
const char *Exec = getToolChain().getDriver().getClangProgramPath();
|
|
|
|
Flags += Exec;
|
|
|
|
for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
|
|
|
|
Flags += " ";
|
|
|
|
Flags += OriginalArgs[i];
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("-dwarf-debug-flags");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Flags.str()));
|
|
|
|
}
|
2010-05-21 05:30:13 +08:00
|
|
|
|
|
|
|
// FIXME: Add -static support, once we have it.
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
2011-04-30 01:53:18 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
|
2010-05-21 05:30:13 +08:00
|
|
|
|
|
|
|
assert(Output.isFilename() && "Unexpected lipo output.");
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
assert(Input.isFilename() && "Invalid input.");
|
|
|
|
CmdArgs.push_back(Input.getFilename());
|
2010-05-21 05:30:13 +08:00
|
|
|
|
2010-07-19 05:16:15 +08:00
|
|
|
const char *Exec = getToolChain().getDriver().getClangProgramPath();
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2013-04-11 05:30:40 +08:00
|
|
|
|
|
|
|
// Handle the debug info splitting at object creation time if we're
|
|
|
|
// creating an object.
|
|
|
|
// TODO: Currently only works on linux with newer objcopy.
|
|
|
|
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
|
|
|
|
(getToolChain().getTriple().getOS() == llvm::Triple::Linux))
|
|
|
|
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
|
|
|
|
SplitDebugName(Args, Inputs));
|
2010-05-21 05:30:13 +08:00
|
|
|
}
|
|
|
|
|
2009-03-18 16:07:30 +08:00
|
|
|
void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
2009-03-18 18:01:51 +08:00
|
|
|
const ArgList &Args,
|
2009-03-18 16:07:30 +08:00
|
|
|
const char *LinkingOutput) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-03-18 16:07:30 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
for (ArgList::const_iterator
|
2009-03-18 18:01:51 +08:00
|
|
|
it = Args.begin(), ie = Args.end(); it != ie; ++it) {
|
2009-03-18 16:07:30 +08:00
|
|
|
Arg *A = *it;
|
2012-10-20 06:37:06 +08:00
|
|
|
if (forwardToGCC(A->getOption())) {
|
2010-08-04 00:14:14 +08:00
|
|
|
// Don't forward any -g arguments to assembly steps.
|
|
|
|
if (isa<AssembleJobAction>(JA) &&
|
|
|
|
A->getOption().matches(options::OPT_g_Group))
|
|
|
|
continue;
|
|
|
|
|
2009-03-19 15:55:12 +08:00
|
|
|
// It is unfortunate that we have to claim here, as this means
|
|
|
|
// we will basically never report anything interesting for
|
2009-05-03 05:41:52 +08:00
|
|
|
// platforms using a generic gcc, even if we are just using gcc
|
|
|
|
// to get to the assembler.
|
2009-03-19 15:55:12 +08:00
|
|
|
A->claim();
|
2009-03-18 18:01:51 +08:00
|
|
|
A->render(Args, CmdArgs);
|
2009-03-19 15:55:12 +08:00
|
|
|
}
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
RenderExtraToolArgs(JA, CmdArgs);
|
2009-03-18 16:07:30 +08:00
|
|
|
|
|
|
|
// If using a driver driver, force the arch.
|
2012-10-07 12:44:33 +08:00
|
|
|
llvm::Triple::ArchType Arch = getToolChain().getArch();
|
2011-10-14 13:03:44 +08:00
|
|
|
if (getToolChain().getTriple().isOSDarwin()) {
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-arch");
|
2009-04-02 04:33:11 +08:00
|
|
|
|
|
|
|
// FIXME: Remove these special cases.
|
2012-10-07 12:44:33 +08:00
|
|
|
if (Arch == llvm::Triple::ppc)
|
2009-05-22 10:21:04 +08:00
|
|
|
CmdArgs.push_back("ppc");
|
2012-10-07 12:44:33 +08:00
|
|
|
else if (Arch == llvm::Triple::ppc64)
|
2009-05-22 10:21:04 +08:00
|
|
|
CmdArgs.push_back("ppc64");
|
|
|
|
else
|
2012-10-07 12:44:33 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName()));
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2009-05-03 05:41:52 +08:00
|
|
|
// Try to force gcc to match the tool chain we want, if we recognize
|
|
|
|
// the arch.
|
2009-05-22 10:21:04 +08:00
|
|
|
//
|
|
|
|
// FIXME: The triple class should directly provide the information we want
|
|
|
|
// here.
|
2012-10-07 12:44:33 +08:00
|
|
|
if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::ppc)
|
2009-05-03 05:41:52 +08:00
|
|
|
CmdArgs.push_back("-m32");
|
2013-03-20 15:34:27 +08:00
|
|
|
else if (Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::ppc64)
|
2009-05-03 05:41:52 +08:00
|
|
|
CmdArgs.push_back("-m64");
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-o");
|
2009-03-19 15:29:38 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Unexpected output");
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-fsyntax-only");
|
2009-03-19 15:29:38 +08:00
|
|
|
}
|
2009-03-18 16:07:30 +08:00
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
2009-03-18 16:07:30 +08:00
|
|
|
|
|
|
|
// Only pass -x if gcc will understand it; otherwise hope gcc
|
|
|
|
// understands the suffix correctly. The main use case this would go
|
|
|
|
// wrong in is for linker inputs if they happened to have an odd
|
|
|
|
// suffix; really the only way to get this to happen is a command
|
|
|
|
// like '-x foobar a.c' which will treat a.c like a linker input.
|
|
|
|
//
|
|
|
|
// FIXME: For the linker case specifically, can we safely convert
|
|
|
|
// inputs into '-Wl,' options?
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2009-05-03 04:14:53 +08:00
|
|
|
|
2009-09-02 00:57:46 +08:00
|
|
|
// Don't try to pass LLVM or AST inputs to a generic gcc.
|
2010-06-08 07:28:45 +08:00
|
|
|
if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
|
|
|
|
II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_no_linker_llvm_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-09-02 00:57:46 +08:00
|
|
|
else if (II.getType() == types::TY_AST)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_no_ast_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2013-03-28 00:47:18 +08:00
|
|
|
else if (II.getType() == types::TY_ModuleFile)
|
|
|
|
D.Diag(diag::err_drv_no_module_support)
|
|
|
|
<< getToolChain().getTripleString();
|
2009-05-03 04:14:53 +08:00
|
|
|
|
2009-03-18 16:07:30 +08:00
|
|
|
if (types::canTypeBeUserSpecified(II.getType())) {
|
|
|
|
CmdArgs.push_back("-x");
|
|
|
|
CmdArgs.push_back(types::getTypeName(II.getType()));
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-03-19 15:29:38 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2010-09-26 02:10:05 +08:00
|
|
|
else {
|
|
|
|
const Arg &A = II.getInputArg();
|
|
|
|
|
|
|
|
// Reverse translate some rewritten options.
|
|
|
|
if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-03-19 15:29:38 +08:00
|
|
|
// Don't render as input, we need gcc to do the translations.
|
2010-09-26 02:10:05 +08:00
|
|
|
A.render(Args, CmdArgs);
|
|
|
|
}
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2011-04-09 21:31:59 +08:00
|
|
|
const std::string customGCCName = D.getCCCGenericGCCName();
|
|
|
|
const char *GCCName;
|
|
|
|
if (!customGCCName.empty())
|
|
|
|
GCCName = customGCCName.c_str();
|
|
|
|
else if (D.CCCIsCXX) {
|
|
|
|
GCCName = "g++";
|
|
|
|
} else
|
|
|
|
GCCName = "gcc";
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
void gcc::Preprocess::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-E");
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
void gcc::Precompile::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-03-18 16:07:30 +08:00
|
|
|
// The type is good enough.
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
void gcc::Compile::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2010-02-11 11:16:21 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
// If -flto, etc. are present then make sure not to force assembly output.
|
2010-06-08 07:28:45 +08:00
|
|
|
if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR ||
|
|
|
|
JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC)
|
2010-01-26 06:35:08 +08:00
|
|
|
CmdArgs.push_back("-c");
|
2010-02-11 11:16:21 +08:00
|
|
|
else {
|
|
|
|
if (JA.getType() != types::TY_PP_Asm)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_invalid_gcc_output_type)
|
2010-02-11 11:16:21 +08:00
|
|
|
<< getTypeName(JA.getType());
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
CmdArgs.push_back("-S");
|
2010-02-11 11:16:21 +08:00
|
|
|
}
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-03-18 16:07:30 +08:00
|
|
|
CmdArgs.push_back("-c");
|
|
|
|
}
|
2009-03-18 14:00:36 +08:00
|
|
|
|
2010-01-26 06:35:08 +08:00
|
|
|
void gcc::Link::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-03-18 16:07:30 +08:00
|
|
|
// The types are (hopefully) good enough.
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
2009-03-18 16:07:30 +08:00
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
// Hexagon tools start.
|
|
|
|
void hexagon::Assemble::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
|
|
|
|
}
|
|
|
|
void hexagon::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
std::string MarchString = "-march=";
|
2012-12-06 22:16:43 +08:00
|
|
|
MarchString += toolchains::Hexagon_TC::GetTargetCPU(Args);
|
2011-12-13 05:14:55 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(MarchString));
|
|
|
|
|
|
|
|
RenderExtraToolArgs(JA, CmdArgs);
|
|
|
|
|
|
|
|
if (Output.isFilename()) {
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Unexpected output");
|
|
|
|
CmdArgs.push_back("-fsyntax-only");
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:49:03 +08:00
|
|
|
std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
|
|
|
|
if (!SmallDataThreshold.empty())
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString(std::string("-G") + SmallDataThreshold));
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-08 01:23:04 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
// Only pass -x if gcc will understand it; otherwise hope gcc
|
|
|
|
// understands the suffix correctly. The main use case this would go
|
|
|
|
// wrong in is for linker inputs if they happened to have an odd
|
|
|
|
// suffix; really the only way to get this to happen is a command
|
|
|
|
// like '-x foobar a.c' which will treat a.c like a linker input.
|
|
|
|
//
|
|
|
|
// FIXME: For the linker case specifically, can we safely convert
|
|
|
|
// inputs into '-Wl,' options?
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
|
|
|
// Don't try to pass LLVM or AST inputs to a generic gcc.
|
|
|
|
if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
|
|
|
|
II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC)
|
|
|
|
D.Diag(clang::diag::err_drv_no_linker_llvm_support)
|
|
|
|
<< getToolChain().getTripleString();
|
|
|
|
else if (II.getType() == types::TY_AST)
|
|
|
|
D.Diag(clang::diag::err_drv_no_ast_support)
|
|
|
|
<< getToolChain().getTripleString();
|
2013-03-28 00:47:18 +08:00
|
|
|
else if (II.getType() == types::TY_ModuleFile)
|
|
|
|
D.Diag(diag::err_drv_no_module_support)
|
|
|
|
<< getToolChain().getTripleString();
|
2011-12-13 05:14:55 +08:00
|
|
|
|
|
|
|
if (II.isFilename())
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
// Don't render as input, we need gcc to do the translations. FIXME: Pranav: What is this ?
|
|
|
|
II.getInputArg().render(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *GCCName = "hexagon-as";
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
|
|
|
|
}
|
|
|
|
void hexagon::Link::RenderExtraToolArgs(const JobAction &JA,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
// The types are (hopefully) good enough.
|
|
|
|
}
|
|
|
|
|
|
|
|
void hexagon::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
const toolchains::Hexagon_TC& ToolChain =
|
|
|
|
static_cast<const toolchains::Hexagon_TC&>(getToolChain());
|
|
|
|
const Driver &D = ToolChain.getDriver();
|
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool hasStaticArg = Args.hasArg(options::OPT_static);
|
|
|
|
bool buildingLib = Args.hasArg(options::OPT_shared);
|
2012-12-07 01:49:03 +08:00
|
|
|
bool buildPIE = Args.hasArg(options::OPT_pie);
|
2012-12-06 23:46:07 +08:00
|
|
|
bool incStdLib = !Args.hasArg(options::OPT_nostdlib);
|
|
|
|
bool incStartFiles = !Args.hasArg(options::OPT_nostartfiles);
|
|
|
|
bool incDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
|
|
|
|
bool useShared = buildingLib && !hasStaticArg;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Silence warnings for various options
|
|
|
|
//----------------------------------------------------------------------------
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
|
|
|
Args.ClaimAllArgs(options::OPT_w); // Other warning options are already
|
|
|
|
// handled somewhere else.
|
|
|
|
Args.ClaimAllArgs(options::OPT_static_libgcc);
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(),
|
|
|
|
e = ToolChain.ExtraOpts.end();
|
|
|
|
i != e; ++i)
|
|
|
|
CmdArgs.push_back(i->c_str());
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 22:16:43 +08:00
|
|
|
std::string MarchString = toolchains::Hexagon_TC::GetTargetCPU(Args);
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-m" + MarchString));
|
2012-01-14 04:37:10 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
if (buildingLib) {
|
|
|
|
CmdArgs.push_back("-shared");
|
|
|
|
CmdArgs.push_back("-call_shared"); // should be the default, but doing as
|
|
|
|
// hexagon-gcc does
|
|
|
|
}
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
if (hasStaticArg)
|
|
|
|
CmdArgs.push_back("-static");
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-07 01:49:03 +08:00
|
|
|
if (buildPIE && !buildingLib)
|
|
|
|
CmdArgs.push_back("-pie");
|
|
|
|
|
|
|
|
std::string SmallDataThreshold = GetHexagonSmallDataThresholdValue(Args);
|
|
|
|
if (!SmallDataThreshold.empty()) {
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString(std::string("-G") + SmallDataThreshold));
|
|
|
|
}
|
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
const std::string MarchSuffix = "/" + MarchString;
|
|
|
|
const std::string G0Suffix = "/G0";
|
|
|
|
const std::string MarchG0Suffix = MarchSuffix + G0Suffix;
|
|
|
|
const std::string RootDir = toolchains::Hexagon_TC::GetGnuDir(D.InstalledDir)
|
|
|
|
+ "/";
|
|
|
|
const std::string StartFilesDir = RootDir
|
|
|
|
+ "hexagon/lib"
|
|
|
|
+ (buildingLib
|
|
|
|
? MarchG0Suffix : MarchSuffix);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// moslib
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::vector<std::string> oslibs;
|
|
|
|
bool hasStandalone= false;
|
|
|
|
|
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_moslib_EQ),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
(*it)->claim();
|
|
|
|
oslibs.push_back((*it)->getValue());
|
|
|
|
hasStandalone = hasStandalone || (oslibs.back() == "standalone");
|
|
|
|
}
|
|
|
|
if (oslibs.empty()) {
|
|
|
|
oslibs.push_back("standalone");
|
|
|
|
hasStandalone = true;
|
2011-12-13 05:14:55 +08:00
|
|
|
}
|
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Start Files
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
if (incStdLib && incStartFiles) {
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
if (!buildingLib) {
|
|
|
|
if (hasStandalone) {
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString(StartFilesDir + "/crt0_standalone.o"));
|
|
|
|
}
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(StartFilesDir + "/crt0.o"));
|
|
|
|
}
|
|
|
|
std::string initObj = useShared ? "/initS.o" : "/init.o";
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(StartFilesDir + initObj));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Library Search Paths
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
const ToolChain::path_list &LibPaths = ToolChain.getFilePaths();
|
|
|
|
for (ToolChain::path_list::const_iterator
|
|
|
|
i = LibPaths.begin(),
|
|
|
|
e = LibPaths.end();
|
|
|
|
i != e;
|
|
|
|
++i)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
|
|
|
|
|
|
|
|
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Libraries
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
if (incStdLib && incDefLibs) {
|
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
|
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
CmdArgs.push_back("--start-group");
|
|
|
|
|
|
|
|
if (!buildingLib) {
|
|
|
|
for(std::vector<std::string>::iterator i = oslibs.begin(),
|
|
|
|
e = oslibs.end(); i != e; ++i)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-l" + *i));
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
|
|
|
|
CmdArgs.push_back("--end-group");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// End files
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
if (incStdLib && incStartFiles) {
|
|
|
|
std::string finiObj = useShared ? "/finiS.o" : "/fini.o";
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(StartFilesDir + finiObj));
|
2011-12-13 05:14:55 +08:00
|
|
|
}
|
|
|
|
|
2012-12-06 23:46:07 +08:00
|
|
|
std::string Linker = ToolChain.GetProgramPath("hexagon-ld");
|
|
|
|
C.addCommand(
|
|
|
|
new Command(
|
|
|
|
JA, *this,
|
|
|
|
Args.MakeArgString(Linker), CmdArgs));
|
2011-12-13 05:14:55 +08:00
|
|
|
}
|
|
|
|
// Hexagon tools end.
|
|
|
|
|
2012-11-01 02:51:07 +08:00
|
|
|
llvm::Triple::ArchType darwin::getArchTypeForDarwinArchName(StringRef Str) {
|
|
|
|
// See arch(3) and llvm-gcc's driver-driver.c. We don't implement support for
|
|
|
|
// archs which Darwin doesn't use.
|
|
|
|
|
|
|
|
// The matching this routine does is fairly pointless, since it is neither the
|
|
|
|
// complete architecture list, nor a reasonable subset. The problem is that
|
|
|
|
// historically the driver driver accepts this and also ties its -march=
|
|
|
|
// handling to the architecture name, so we need to be careful before removing
|
|
|
|
// support for it.
|
|
|
|
|
|
|
|
// This code must be kept in sync with Clang's Darwin specific argument
|
|
|
|
// translation.
|
|
|
|
|
|
|
|
return llvm::StringSwitch<llvm::Triple::ArchType>(Str)
|
|
|
|
.Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc)
|
|
|
|
.Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc)
|
|
|
|
.Case("ppc64", llvm::Triple::ppc64)
|
|
|
|
.Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86)
|
|
|
|
.Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4",
|
|
|
|
llvm::Triple::x86)
|
|
|
|
.Case("x86_64", llvm::Triple::x86_64)
|
|
|
|
// This is derived from the driver driver.
|
2013-03-05 06:37:49 +08:00
|
|
|
.Cases("arm", "armv4t", "armv5", "armv6", "armv6m", llvm::Triple::arm)
|
|
|
|
.Cases("armv7", "armv7em", "armv7f", "armv7k", "armv7m", llvm::Triple::arm)
|
|
|
|
.Cases("armv7s", "xscale", llvm::Triple::arm)
|
2012-11-01 02:51:07 +08:00
|
|
|
.Case("r600", llvm::Triple::r600)
|
|
|
|
.Case("nvptx", llvm::Triple::nvptx)
|
|
|
|
.Case("nvptx64", llvm::Triple::nvptx64)
|
|
|
|
.Case("amdil", llvm::Triple::amdil)
|
|
|
|
.Case("spir", llvm::Triple::spir)
|
|
|
|
.Default(llvm::Triple::UnknownArch);
|
|
|
|
}
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2012-11-23 14:14:39 +08:00
|
|
|
const char *Clang::getBaseInputName(const ArgList &Args,
|
|
|
|
const InputInfoList &Inputs) {
|
2010-12-18 08:19:12 +08:00
|
|
|
return Args.MakeArgString(
|
|
|
|
llvm::sys::path::filename(Inputs[0].getBaseInput()));
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
2012-11-23 14:14:39 +08:00
|
|
|
const char *Clang::getBaseInputStem(const ArgList &Args,
|
|
|
|
const InputInfoList &Inputs) {
|
2009-03-30 02:40:18 +08:00
|
|
|
const char *Str = getBaseInputName(Args, Inputs);
|
|
|
|
|
2011-01-16 16:14:11 +08:00
|
|
|
if (const char *End = strrchr(Str, '.'))
|
2009-09-10 06:32:48 +08:00
|
|
|
return Args.MakeArgString(std::string(Str, End));
|
2009-03-30 02:40:18 +08:00
|
|
|
|
|
|
|
return Str;
|
|
|
|
}
|
|
|
|
|
2012-11-23 14:14:39 +08:00
|
|
|
const char *Clang::getDependencyFileName(const ArgList &Args,
|
|
|
|
const InputInfoList &Inputs) {
|
2009-03-30 02:40:18 +08:00
|
|
|
// FIXME: Think about this more.
|
|
|
|
std::string Res;
|
|
|
|
|
|
|
|
if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
|
2012-11-01 12:30:05 +08:00
|
|
|
std::string Str(OutputOpt->getValue());
|
2009-03-30 02:40:18 +08:00
|
|
|
Res = Str.substr(0, Str.rfind('.'));
|
2011-08-18 07:08:45 +08:00
|
|
|
} else {
|
2012-11-23 14:14:39 +08:00
|
|
|
Res = getBaseInputStem(Args, Inputs);
|
2011-08-18 07:08:45 +08:00
|
|
|
}
|
2009-09-10 06:32:48 +08:00
|
|
|
return Args.MakeArgString(Res + ".d");
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
2012-11-15 13:36:36 +08:00
|
|
|
|
2009-03-21 00:06:39 +08:00
|
|
|
void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-04-09 07:54:23 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-03-21 00:06:39 +08:00
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unexpected number of inputs.");
|
|
|
|
const InputInfo &Input = Inputs[0];
|
|
|
|
|
2011-04-13 07:59:20 +08:00
|
|
|
// Determine the original source input.
|
|
|
|
const Action *SourceAction = &JA;
|
|
|
|
while (SourceAction->getKind() != Action::InputClass) {
|
|
|
|
assert(!SourceAction->getInputs().empty() && "unexpected root action!");
|
|
|
|
SourceAction = SourceAction->getInputs()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward -g, assuming we are dealing with an actual assembly file.
|
2011-08-19 08:30:14 +08:00
|
|
|
if (SourceAction->getType() == types::TY_Asm ||
|
2011-04-13 07:59:20 +08:00
|
|
|
SourceAction->getType() == types::TY_PP_Asm) {
|
2009-04-01 08:27:44 +08:00
|
|
|
if (Args.hasArg(options::OPT_gstabs))
|
|
|
|
CmdArgs.push_back("--gstabs");
|
|
|
|
else if (Args.hasArg(options::OPT_g_Group))
|
2011-11-02 13:10:45 +08:00
|
|
|
CmdArgs.push_back("-g");
|
2009-04-01 08:27:44 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-21 00:06:39 +08:00
|
|
|
// Derived from asm spec.
|
2009-09-10 02:36:27 +08:00
|
|
|
AddDarwinArch(Args, CmdArgs);
|
|
|
|
|
2010-07-22 09:47:22 +08:00
|
|
|
// Use -force_cpusubtype_ALL on x86 by default.
|
|
|
|
if (getToolChain().getTriple().getArch() == llvm::Triple::x86 ||
|
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::x86_64 ||
|
2009-09-10 02:36:27 +08:00
|
|
|
Args.hasArg(options::OPT_force__cpusubtype__ALL))
|
|
|
|
CmdArgs.push_back("-force_cpusubtype_ALL");
|
2009-03-21 00:06:39 +08:00
|
|
|
|
2009-08-25 06:26:16 +08:00
|
|
|
if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 &&
|
2012-10-16 06:23:53 +08:00
|
|
|
(((Args.hasArg(options::OPT_mkernel) ||
|
2013-02-22 06:35:01 +08:00
|
|
|
Args.hasArg(options::OPT_fapple_kext)) &&
|
2012-10-16 06:23:53 +08:00
|
|
|
(!getDarwinToolChain().isTargetIPhoneOS() ||
|
|
|
|
getDarwinToolChain().isIPhoneOSVersionLT(6, 0))) ||
|
|
|
|
Args.hasArg(options::OPT_static)))
|
2009-04-09 07:54:23 +08:00
|
|
|
CmdArgs.push_back("-static");
|
|
|
|
|
2009-03-21 00:06:39 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
assert(Output.isFilename() && "Unexpected lipo output.");
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
assert(Input.isFilename() && "Invalid input.");
|
|
|
|
CmdArgs.push_back(Input.getFilename());
|
2009-03-21 00:06:39 +08:00
|
|
|
|
|
|
|
// asm_final spec is empty.
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-21 00:06:39 +08:00
|
|
|
}
|
2009-03-20 08:52:38 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void darwin::DarwinTool::anchor() {}
|
|
|
|
|
2009-09-10 02:36:20 +08:00
|
|
|
void darwin::DarwinTool::AddDarwinArch(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args);
|
2010-01-22 10:04:58 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// Derived from darwin_arch spec.
|
|
|
|
CmdArgs.push_back("-arch");
|
2010-01-22 10:04:58 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ArchName));
|
2009-09-05 02:35:31 +08:00
|
|
|
|
2010-01-22 10:04:58 +08:00
|
|
|
// FIXME: Is this needed anymore?
|
|
|
|
if (ArchName == "arm")
|
2009-09-05 02:35:31 +08:00
|
|
|
CmdArgs.push_back("-force_cpusubtype_ALL");
|
2009-03-27 00:23:12 +08:00
|
|
|
}
|
|
|
|
|
2012-10-03 02:02:50 +08:00
|
|
|
bool darwin::Link::NeedsTempPath(const InputInfoList &Inputs) const {
|
|
|
|
// We only need to generate a temp path for LTO if we aren't compiling object
|
|
|
|
// files. When compiling source files, we run 'dsymutil' after linking. We
|
|
|
|
// don't run 'dsymutil' when compiling object files.
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it)
|
|
|
|
if (it->getType() != types::TY_Object)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-10 05:51:05 +08:00
|
|
|
void darwin::Link::AddLinkArgs(Compilation &C,
|
|
|
|
const ArgList &Args,
|
2012-10-03 02:02:50 +08:00
|
|
|
ArgStringList &CmdArgs,
|
|
|
|
const InputInfoList &Inputs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2011-04-29 05:23:41 +08:00
|
|
|
const toolchains::Darwin &DarwinTC = getDarwinToolChain();
|
2009-03-27 00:23:12 +08:00
|
|
|
|
2010-08-12 07:07:50 +08:00
|
|
|
unsigned Version[3] = { 0, 0, 0 };
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
|
|
|
|
bool HadExtra;
|
2012-11-01 12:30:05 +08:00
|
|
|
if (!Driver::GetReleaseVersion(A->getValue(), Version[0],
|
2010-08-12 07:07:50 +08:00
|
|
|
Version[1], Version[2], HadExtra) ||
|
|
|
|
HadExtra)
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_invalid_version_number)
|
2010-08-12 07:07:50 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Newer linkers support -demangle, pass it if supported and not disabled by
|
|
|
|
// the user.
|
2012-01-05 05:45:27 +08:00
|
|
|
if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) {
|
2010-09-08 01:07:49 +08:00
|
|
|
// Don't pass -demangle to ld_classic.
|
|
|
|
//
|
|
|
|
// FIXME: This is a temporary workaround, ld should be handling this.
|
|
|
|
bool UsesLdClassic = (getToolChain().getArch() == llvm::Triple::x86 &&
|
|
|
|
Args.hasArg(options::OPT_static));
|
2010-09-08 01:50:41 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86) {
|
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_Xlinker,
|
|
|
|
options::OPT_Wl_COMMA),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
|
|
|
const Arg *A = *it;
|
|
|
|
for (unsigned i = 0, e = A->getNumValues(); i != e; ++i)
|
2012-11-01 12:30:05 +08:00
|
|
|
if (StringRef(A->getValue(i)) == "-kext")
|
2010-09-08 01:50:41 +08:00
|
|
|
UsesLdClassic = true;
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 01:07:49 +08:00
|
|
|
if (!UsesLdClassic)
|
|
|
|
CmdArgs.push_back("-demangle");
|
2010-08-12 07:07:50 +08:00
|
|
|
}
|
|
|
|
|
2012-11-17 07:03:00 +08:00
|
|
|
// If we are using LTO, then automatically create a temporary file path for
|
|
|
|
// the linker to use, so that it's lifetime will extend past a possible
|
|
|
|
// dsymutil step.
|
|
|
|
if (Version[0] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) {
|
|
|
|
const char *TmpPath = C.getArgs().MakeArgString(
|
|
|
|
D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
|
|
|
|
C.addTempFile(TmpPath);
|
|
|
|
CmdArgs.push_back("-object_path_lto");
|
|
|
|
CmdArgs.push_back(TmpPath);
|
2011-06-22 04:55:11 +08:00
|
|
|
}
|
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// Derived from the "link" spec.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_static);
|
|
|
|
if (!Args.hasArg(options::OPT_static))
|
|
|
|
CmdArgs.push_back("-dynamic");
|
|
|
|
if (Args.hasArg(options::OPT_fgnu_runtime)) {
|
|
|
|
// FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
|
|
|
|
// here. How do we wish to handle such things?
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
if (!Args.hasArg(options::OPT_dynamiclib)) {
|
2010-01-22 10:04:52 +08:00
|
|
|
AddDarwinArch(Args, CmdArgs);
|
|
|
|
// FIXME: Why do this only on this path?
|
2010-01-22 11:37:33 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL);
|
2009-03-27 00:23:12 +08:00
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_bundle);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_client__name);
|
|
|
|
|
|
|
|
Arg *A;
|
|
|
|
if ((A = Args.getLastArg(options::OPT_compatibility__version)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_current__version)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_install__name)))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_argument_only_allowed_with)
|
2009-03-27 00:23:12 +08:00
|
|
|
<< A->getAsString(Args) << "-dynamiclib";
|
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_private__bundle);
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-dylib");
|
|
|
|
|
|
|
|
Arg *A;
|
|
|
|
if ((A = Args.getLastArg(options::OPT_bundle)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_bundle__loader)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_client__name)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_force__flat__namespace)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_keep__private__externs)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_private__bundle)))
|
2011-07-23 18:55:15 +08:00
|
|
|
D.Diag(diag::err_drv_argument_not_allowed_with)
|
2009-03-27 00:23:12 +08:00
|
|
|
<< A->getAsString(Args) << "-dynamiclib";
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version,
|
|
|
|
"-dylib_compatibility_version");
|
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version,
|
|
|
|
"-dylib_current_version");
|
|
|
|
|
2010-01-22 10:04:52 +08:00
|
|
|
AddDarwinArch(Args, CmdArgs);
|
2009-03-27 00:23:12 +08:00
|
|
|
|
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name,
|
|
|
|
"-dylib_install_name");
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_all__load);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_allowable__client);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_bind__at__load);
|
2011-04-29 05:23:41 +08:00
|
|
|
if (DarwinTC.isTargetIPhoneOS())
|
2009-09-05 02:35:41 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal);
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_dead__strip);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_dylib__file);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_dynamic);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_flat__namespace);
|
2011-06-29 04:16:02 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_force__load);
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_image__base);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_init);
|
|
|
|
|
2011-04-29 05:23:41 +08:00
|
|
|
// Add the deployment target.
|
2012-03-11 04:55:36 +08:00
|
|
|
VersionTuple TargetVersion = DarwinTC.getTargetVersion();
|
2011-04-30 12:22:58 +08:00
|
|
|
|
|
|
|
// If we had an explicit -mios-simulator-version-min argument, honor that,
|
|
|
|
// otherwise use the traditional deployment targets. We can't just check the
|
|
|
|
// is-sim attribute because existing code follows this path, and the linker
|
|
|
|
// may not handle the argument.
|
|
|
|
//
|
|
|
|
// FIXME: We may be able to remove this, once we can verify no one depends on
|
|
|
|
// it.
|
|
|
|
if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ))
|
|
|
|
CmdArgs.push_back("-ios_simulator_version_min");
|
|
|
|
else if (DarwinTC.isTargetIPhoneOS())
|
|
|
|
CmdArgs.push_back("-iphoneos_version_min");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-macosx_version_min");
|
2012-03-11 04:55:36 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(TargetVersion.getAsString()));
|
2011-04-29 05:23:41 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_multi__module);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_single__module);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2010-07-14 07:31:40 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE,
|
|
|
|
options::OPT_fno_pie,
|
|
|
|
options::OPT_fno_PIE)) {
|
|
|
|
if (A->getOption().matches(options::OPT_fpie) ||
|
|
|
|
A->getOption().matches(options::OPT_fPIE))
|
|
|
|
CmdArgs.push_back("-pie");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-no_pie");
|
|
|
|
}
|
2009-03-27 00:23:12 +08:00
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_prebind);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_noprebind);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sectcreate);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sectorder);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_seg1addr);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segprot);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segaddr);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
|
2009-09-05 02:35:41 +08:00
|
|
|
|
2011-05-03 05:03:47 +08:00
|
|
|
// Give --sysroot= preference, over the Apple specific behavior to also use
|
|
|
|
// --isysroot as the syslibroot.
|
2012-04-16 12:16:43 +08:00
|
|
|
StringRef sysroot = C.getSysRoot();
|
|
|
|
if (sysroot != "") {
|
2011-05-03 05:03:47 +08:00
|
|
|
CmdArgs.push_back("-syslibroot");
|
2012-04-16 12:16:43 +08:00
|
|
|
CmdArgs.push_back(C.getArgs().MakeArgString(sysroot));
|
2011-05-03 05:03:47 +08:00
|
|
|
} else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
|
|
|
|
CmdArgs.push_back("-syslibroot");
|
2012-11-01 12:30:05 +08:00
|
|
|
CmdArgs.push_back(A->getValue());
|
2009-09-05 02:35:41 +08:00
|
|
|
}
|
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_umbrella);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_undefined);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list);
|
2009-09-05 02:35:41 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches);
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_X_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_y);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_w);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segs__read__);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_seglinkedit);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sectalign);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_segcreate);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_whyload);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_whatsloaded);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_dylinker);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_Mach);
|
|
|
|
}
|
|
|
|
|
|
|
|
void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-04-09 07:54:23 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-03-27 00:23:12 +08:00
|
|
|
const char *LinkingOutput) const {
|
|
|
|
assert(Output.getType() == types::TY_Image && "Invalid linker output type.");
|
2009-09-09 00:39:16 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// The logic here is derived from gcc's behavior; most of which
|
|
|
|
// comes from specs (starting with link_command). Consult gcc for
|
|
|
|
// more information.
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2011-10-08 06:58:08 +08:00
|
|
|
/// Hack(tm) to ignore linking errors when we are doing ARC migration.
|
|
|
|
if (Args.hasArg(options::OPT_ccc_arcmt_check,
|
|
|
|
options::OPT_ccc_arcmt_migrate)) {
|
|
|
|
for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I)
|
|
|
|
(*I)->claim();
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("touch"));
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// I'm not sure why this particular decomposition exists in gcc, but
|
|
|
|
// we follow suite for ease of comparison.
|
2012-10-03 02:02:50 +08:00
|
|
|
AddLinkArgs(C, Args, CmdArgs, Inputs);
|
2009-03-27 00:23:12 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_d_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_e);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_m_Separate);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
|
|
|
|
2010-10-19 06:08:36 +08:00
|
|
|
// Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
|
|
|
|
// members of static archive libraries which implement Objective-C classes or
|
|
|
|
// categories.
|
|
|
|
if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX))
|
|
|
|
CmdArgs.push_back("-ObjC");
|
2010-10-21 11:16:25 +08:00
|
|
|
|
2012-12-11 05:48:41 +08:00
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export_dynamic");
|
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
2012-05-17 07:45:12 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
2009-03-27 00:23:12 +08:00
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
// Derived from startfile spec.
|
|
|
|
if (Args.hasArg(options::OPT_dynamiclib)) {
|
2009-04-09 07:54:23 +08:00
|
|
|
// Derived from darwin_dylib1 spec.
|
2011-04-02 05:02:42 +08:00
|
|
|
if (getDarwinToolChain().isTargetIOSSimulator()) {
|
|
|
|
// The simulator doesn't have a versioned crt1 file.
|
|
|
|
CmdArgs.push_back("-ldylib1.o");
|
|
|
|
} else if (getDarwinToolChain().isTargetIPhoneOS()) {
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
|
|
|
|
CmdArgs.push_back("-ldylib1.o");
|
|
|
|
} else {
|
2010-01-27 08:57:03 +08:00
|
|
|
if (getDarwinToolChain().isMacosxVersionLT(10, 5))
|
2010-01-27 08:56:56 +08:00
|
|
|
CmdArgs.push_back("-ldylib1.o");
|
2010-01-27 08:57:03 +08:00
|
|
|
else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
|
2010-01-27 08:56:56 +08:00
|
|
|
CmdArgs.push_back("-ldylib1.10.5.o");
|
|
|
|
}
|
2009-03-27 00:23:12 +08:00
|
|
|
} else {
|
|
|
|
if (Args.hasArg(options::OPT_bundle)) {
|
2009-04-01 11:17:40 +08:00
|
|
|
if (!Args.hasArg(options::OPT_static)) {
|
|
|
|
// Derived from darwin_bundle1 spec.
|
2011-04-02 05:02:42 +08:00
|
|
|
if (getDarwinToolChain().isTargetIOSSimulator()) {
|
|
|
|
// The simulator doesn't have a versioned crt1 file.
|
|
|
|
CmdArgs.push_back("-lbundle1.o");
|
|
|
|
} else if (getDarwinToolChain().isTargetIPhoneOS()) {
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
|
|
|
|
CmdArgs.push_back("-lbundle1.o");
|
|
|
|
} else {
|
2010-01-27 08:57:03 +08:00
|
|
|
if (getDarwinToolChain().isMacosxVersionLT(10, 6))
|
2010-01-27 08:56:56 +08:00
|
|
|
CmdArgs.push_back("-lbundle1.o");
|
|
|
|
}
|
2009-04-01 11:17:40 +08:00
|
|
|
}
|
2009-03-27 00:23:12 +08:00
|
|
|
} else {
|
2011-03-02 02:49:30 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg) &&
|
|
|
|
getToolChain().SupportsProfiling()) {
|
2009-03-27 00:23:12 +08:00
|
|
|
if (Args.hasArg(options::OPT_static) ||
|
|
|
|
Args.hasArg(options::OPT_object) ||
|
|
|
|
Args.hasArg(options::OPT_preload)) {
|
|
|
|
CmdArgs.push_back("-lgcrt0.o");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-lgcrt1.o");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// darwin_crt2 spec is empty.
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
2012-07-04 08:18:41 +08:00
|
|
|
// By default on OS X 10.8 and later, we don't link with a crt1.o
|
|
|
|
// file and the linker knows to use _main as the entry point. But,
|
|
|
|
// when compiling with -pg, we need to link with the gcrt1.o file,
|
|
|
|
// so pass the -no_new_main option to tell the linker to use the
|
|
|
|
// "start" symbol as the entry point.
|
2012-07-04 04:42:10 +08:00
|
|
|
if (getDarwinToolChain().isTargetMacOS() &&
|
|
|
|
!getDarwinToolChain().isMacosxVersionLT(10, 8))
|
|
|
|
CmdArgs.push_back("-no_new_main");
|
2009-03-27 00:23:12 +08:00
|
|
|
} else {
|
|
|
|
if (Args.hasArg(options::OPT_static) ||
|
|
|
|
Args.hasArg(options::OPT_object) ||
|
|
|
|
Args.hasArg(options::OPT_preload)) {
|
|
|
|
CmdArgs.push_back("-lcrt0.o");
|
|
|
|
} else {
|
|
|
|
// Derived from darwin_crt1 spec.
|
2011-04-01 01:12:33 +08:00
|
|
|
if (getDarwinToolChain().isTargetIOSSimulator()) {
|
|
|
|
// The simulator doesn't have a versioned crt1 file.
|
|
|
|
CmdArgs.push_back("-lcrt1.o");
|
|
|
|
} else if (getDarwinToolChain().isTargetIPhoneOS()) {
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
|
|
|
|
CmdArgs.push_back("-lcrt1.o");
|
2012-10-16 06:23:53 +08:00
|
|
|
else if (getDarwinToolChain().isIPhoneOSVersionLT(6, 0))
|
2010-01-27 08:56:56 +08:00
|
|
|
CmdArgs.push_back("-lcrt1.3.1.o");
|
2010-01-27 08:57:03 +08:00
|
|
|
} else {
|
|
|
|
if (getDarwinToolChain().isMacosxVersionLT(10, 5))
|
|
|
|
CmdArgs.push_back("-lcrt1.o");
|
|
|
|
else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
|
|
|
|
CmdArgs.push_back("-lcrt1.10.5.o");
|
2012-03-07 04:05:56 +08:00
|
|
|
else if (getDarwinToolChain().isMacosxVersionLT(10, 8))
|
2010-01-27 08:57:03 +08:00
|
|
|
CmdArgs.push_back("-lcrt1.10.6.o");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2010-01-27 08:57:03 +08:00
|
|
|
// darwin_crt2 spec is empty.
|
|
|
|
}
|
2009-03-27 00:23:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-27 08:57:03 +08:00
|
|
|
if (!getDarwinToolChain().isTargetIPhoneOS() &&
|
|
|
|
Args.hasArg(options::OPT_shared_libgcc) &&
|
|
|
|
getDarwinToolChain().isMacosxVersionLT(10, 5)) {
|
2009-09-10 06:32:48 +08:00
|
|
|
const char *Str =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crt3.o"));
|
2009-09-10 06:32:48 +08:00
|
|
|
CmdArgs.push_back(Str);
|
2009-03-27 00:23:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2013-04-09 12:35:11 +08:00
|
|
|
SanitizerArgs Sanitize(getToolChain(), Args);
|
2013-01-21 16:45:02 +08:00
|
|
|
// If we're building a dynamic lib with -fsanitize=address,
|
|
|
|
// unresolved symbols may appear. Mark all
|
2012-11-16 20:53:14 +08:00
|
|
|
// of them as dynamic_lookup. Linking executables is handled in
|
|
|
|
// lib/Driver/ToolChains.cpp.
|
2013-01-21 16:45:02 +08:00
|
|
|
if (Sanitize.needsAsanRt()) {
|
2011-12-07 03:18:44 +08:00
|
|
|
if (Args.hasArg(options::OPT_dynamiclib) ||
|
|
|
|
Args.hasArg(options::OPT_bundle)) {
|
|
|
|
CmdArgs.push_back("-undefined");
|
|
|
|
CmdArgs.push_back("dynamic_lookup");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
if (Args.hasArg(options::OPT_fopenmp))
|
|
|
|
// This is more complicated in gcc...
|
|
|
|
CmdArgs.push_back("-lgomp");
|
|
|
|
|
2012-05-16 05:00:27 +08:00
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
|
|
|
|
2012-05-16 02:57:39 +08:00
|
|
|
if (isObjCRuntimeLinked(Args) &&
|
|
|
|
!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2012-03-07 04:05:56 +08:00
|
|
|
// Avoid linking compatibility stubs on i386 mac.
|
|
|
|
if (!getDarwinToolChain().isTargetMacOS() ||
|
2012-10-07 12:44:33 +08:00
|
|
|
getDarwinToolChain().getArch() != llvm::Triple::x86) {
|
2012-03-07 04:05:56 +08:00
|
|
|
// If we don't have ARC or subscripting runtime support, link in the
|
|
|
|
// runtime stubs. We have to do this *before* adding any of the normal
|
|
|
|
// linker inputs so that its initializer gets run first.
|
2012-06-20 14:18:46 +08:00
|
|
|
ObjCRuntime runtime =
|
|
|
|
getDarwinToolChain().getDefaultObjCRuntime(/*nonfragile*/ true);
|
2012-03-07 04:05:56 +08:00
|
|
|
// We use arclite library for both ARC and subscripting support.
|
2012-08-21 10:47:43 +08:00
|
|
|
if ((!runtime.hasNativeARC() && isObjCAutoRefCount(Args)) ||
|
2012-06-20 14:18:46 +08:00
|
|
|
!runtime.hasSubscripting())
|
2012-03-07 04:05:56 +08:00
|
|
|
getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs);
|
|
|
|
}
|
2012-04-21 08:21:42 +08:00
|
|
|
CmdArgs.push_back("-framework");
|
|
|
|
CmdArgs.push_back("Foundation");
|
2012-03-07 04:05:56 +08:00
|
|
|
// Link libobj.
|
|
|
|
CmdArgs.push_back("-lobjc");
|
2011-07-06 08:26:06 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
if (LinkingOutput) {
|
|
|
|
CmdArgs.push_back("-arch_multiple");
|
|
|
|
CmdArgs.push_back("-final_output");
|
|
|
|
CmdArgs.push_back(LinkingOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fnested_functions))
|
|
|
|
CmdArgs.push_back("-allow_stack_execute");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2009-12-22 02:54:17 +08:00
|
|
|
if (getToolChain().getDriver().CCCIsCXX)
|
2010-09-17 09:20:05 +08:00
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2009-04-08 14:06:21 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
// link_ssp spec is empty.
|
|
|
|
|
2009-09-18 16:15:03 +08:00
|
|
|
// Let the tool chain choose which runtime library to link.
|
|
|
|
getDarwinToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
|
2009-03-27 00:23:12 +08:00
|
|
|
}
|
|
|
|
|
2012-05-17 07:45:12 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
2009-03-27 00:23:12 +08:00
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
// endfile_spec is empty.
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_F);
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-27 00:23:12 +08:00
|
|
|
}
|
|
|
|
|
2009-03-20 08:52:38 +08:00
|
|
|
void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-04-09 07:54:23 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-03-20 08:52:38 +08:00
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
CmdArgs.push_back("-create");
|
|
|
|
assert(Output.isFilename() && "Unexpected lipo output.");
|
2009-03-24 08:24:37 +08:00
|
|
|
|
|
|
|
CmdArgs.push_back("-output");
|
2009-03-20 08:52:38 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-03-24 08:24:37 +08:00
|
|
|
|
2009-03-20 08:52:38 +08:00
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
assert(II.isFilename() && "Unexpected lipo input.");
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-20 08:52:38 +08:00
|
|
|
}
|
2009-04-01 01:45:15 +08:00
|
|
|
|
2010-06-05 02:28:36 +08:00
|
|
|
void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2010-06-05 02:28:36 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2011-05-10 01:23:16 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
2010-06-05 02:28:36 +08:00
|
|
|
assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
|
|
|
|
const InputInfo &Input = Inputs[0];
|
|
|
|
assert(Input.isFilename() && "Unexpected dsymutil input.");
|
|
|
|
CmdArgs.push_back(Input.getFilename());
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2010-06-05 02:28:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-24 01:56:55 +08:00
|
|
|
void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
|
2012-12-18 08:31:10 +08:00
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2011-08-24 01:56:55 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
CmdArgs.push_back("--verify");
|
2012-02-07 03:13:09 +08:00
|
|
|
CmdArgs.push_back("--debug-info");
|
|
|
|
CmdArgs.push_back("--eh-frame");
|
2012-02-07 03:43:51 +08:00
|
|
|
CmdArgs.push_back("--quiet");
|
2011-08-24 01:56:55 +08:00
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
|
|
|
|
const InputInfo &Input = Inputs[0];
|
|
|
|
assert(Input.isFilename() && "Unexpected verify input");
|
|
|
|
|
|
|
|
// Grabbing the output of the earlier dsymutil run.
|
|
|
|
CmdArgs.push_back(Input.getFilename());
|
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
2012-02-15 21:39:01 +08:00
|
|
|
void solaris::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
// FIXME: Find a real GCC, don't hard-code versions here
|
|
|
|
std::string GCCLibPath = "/usr/gcc/4.5/lib/gcc/";
|
|
|
|
const llvm::Triple &T = getToolChain().getTriple();
|
|
|
|
std::string LibPath = "/usr/lib/";
|
|
|
|
llvm::Triple::ArchType Arch = T.getArch();
|
|
|
|
switch (Arch) {
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
GCCLibPath += ("i386-" + T.getVendorName() + "-" +
|
|
|
|
T.getOSName()).str() + "/4.5.2/";
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
GCCLibPath += ("i386-" + T.getVendorName() + "-" +
|
|
|
|
T.getOSName()).str();
|
|
|
|
GCCLibPath += "/4.5.2/amd64/";
|
|
|
|
LibPath += "amd64/";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unsupported architecture");
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2012-02-29 23:06:12 +08:00
|
|
|
// Demangle C++ names in errors
|
|
|
|
CmdArgs.push_back("-C");
|
|
|
|
|
2012-02-15 21:39:01 +08:00
|
|
|
if ((!Args.hasArg(options::OPT_nostdlib)) &&
|
|
|
|
(!Args.hasArg(options::OPT_shared))) {
|
|
|
|
CmdArgs.push_back("-e");
|
|
|
|
CmdArgs.push_back("_start");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
CmdArgs.push_back("-dn");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-Bdynamic");
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-shared");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("--dynamic-linker");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "ld.so.1"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Output.isFilename()) {
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "crt1.o"));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o"));
|
2012-02-29 01:10:04 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o"));
|
2012-02-15 21:39:01 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o"));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "crti.o"));
|
2012-02-29 01:10:04 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "values-Xa.o"));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtbegin.o"));
|
2012-02-15 21:39:01 +08:00
|
|
|
}
|
2012-03-13 22:14:54 +08:00
|
|
|
if (getToolChain().getDriver().CCCIsCXX)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "cxa_finalize.o"));
|
2012-02-15 21:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L" + GCCLibPath));
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
2012-02-29 01:10:04 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
2012-02-15 21:39:01 +08:00
|
|
|
|
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2012-04-10 19:49:50 +08:00
|
|
|
if (getToolChain().getDriver().CCCIsCXX)
|
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2012-02-16 02:24:31 +08:00
|
|
|
CmdArgs.push_back("-lgcc_s");
|
2012-02-29 01:10:04 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-lgcc");
|
2012-02-15 21:39:01 +08:00
|
|
|
CmdArgs.push_back("-lc");
|
2012-02-29 04:06:45 +08:00
|
|
|
CmdArgs.push_back("-lm");
|
2012-02-29 01:10:04 +08:00
|
|
|
}
|
2012-02-15 21:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2012-02-29 01:10:04 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(GCCLibPath + "crtend.o"));
|
2012-02-15 21:39:01 +08:00
|
|
|
}
|
2012-02-17 00:00:47 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(LibPath + "crtn.o"));
|
2012-02-15 21:39:01 +08:00
|
|
|
|
|
|
|
addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
2009-08-22 09:06:46 +08:00
|
|
|
void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-11-04 14:24:38 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2009-08-22 09:06:46 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-08-22 09:06:46 +08:00
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("gas"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-11-04 14:24:38 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2009-08-22 09:06:46 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if ((!Args.hasArg(options::OPT_nostdlib)) &&
|
2009-11-04 14:24:38 +08:00
|
|
|
(!Args.hasArg(options::OPT_shared))) {
|
2009-08-22 09:06:46 +08:00
|
|
|
CmdArgs.push_back("-e");
|
2009-10-15 15:44:07 +08:00
|
|
|
CmdArgs.push_back("_start");
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
2009-10-15 15:44:07 +08:00
|
|
|
CmdArgs.push_back("-dn");
|
2009-08-22 09:06:46 +08:00
|
|
|
} else {
|
2009-10-15 15:44:07 +08:00
|
|
|
// CmdArgs.push_back("--eh-frame-hdr");
|
2009-08-22 09:06:46 +08:00
|
|
|
CmdArgs.push_back("-Bdynamic");
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-shared");
|
|
|
|
} else {
|
2009-10-17 03:44:18 +08:00
|
|
|
CmdArgs.push_back("--dynamic-linker");
|
2009-08-22 09:06:46 +08:00
|
|
|
CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2009-08-22 09:06:46 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crt1.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crti.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtbegin.o")));
|
2009-08-22 09:06:46 +08:00
|
|
|
} else {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crti.o")));
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtn.o")));
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 14:24:38 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/opt/gcc4/lib/gcc/"
|
|
|
|
+ getToolChain().getTripleString()
|
2009-10-29 10:24:37 +08:00
|
|
|
+ "/4.2.4"));
|
2009-08-22 09:06:46 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
2009-08-22 09:06:46 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
// FIXME: For some reason GCC passes -lgcc before adding
|
|
|
|
// the default system libraries. Just mimic this for now.
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-pthread");
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtend.o")));
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
2011-06-28 03:15:03 +08:00
|
|
|
addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
2011-05-25 05:54:59 +08:00
|
|
|
|
2009-08-22 09:06:46 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-08-22 09:06:46 +08:00
|
|
|
}
|
|
|
|
|
2009-06-30 04:52:51 +08:00
|
|
|
void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-06-30 04:52:51 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-09-09 23:08:12 +08:00
|
|
|
const char *LinkingOutput) const {
|
2009-06-30 04:52:51 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-06-30 04:52:51 +08:00
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-06-30 04:52:51 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-06-30 04:52:51 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2013-01-01 06:41:36 +08:00
|
|
|
// Silence warning for "clang -g foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
|
|
|
// and "clang -emit-llvm foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
|
|
|
// and for "clang -w foo.o -o foo". Other warning options are already
|
|
|
|
// handled somewhere else.
|
|
|
|
Args.ClaimAllArgs(options::OPT_w);
|
|
|
|
|
2009-08-03 09:28:59 +08:00
|
|
|
if ((!Args.hasArg(options::OPT_nostdlib)) &&
|
2009-11-04 14:24:38 +08:00
|
|
|
(!Args.hasArg(options::OPT_shared))) {
|
2009-08-03 09:28:59 +08:00
|
|
|
CmdArgs.push_back("-e");
|
|
|
|
CmdArgs.push_back("__start");
|
|
|
|
}
|
|
|
|
|
2009-06-30 04:52:51 +08:00
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
2010-11-11 10:17:51 +08:00
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
2009-06-30 04:52:51 +08:00
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
2009-08-03 09:28:59 +08:00
|
|
|
CmdArgs.push_back("-Bdynamic");
|
2009-06-30 04:52:51 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
2009-08-03 09:28:59 +08:00
|
|
|
CmdArgs.push_back("-shared");
|
2009-06-30 04:52:51 +08:00
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
|
|
|
CmdArgs.push_back("/usr/libexec/ld.so");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 12:28:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_nopie))
|
|
|
|
CmdArgs.push_back("-nopie");
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2009-06-30 04:52:51 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
2011-12-15 10:15:56 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("gcrt0.o")));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crt0.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtbegin.o")));
|
2009-06-30 04:52:51 +08:00
|
|
|
} else {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtbeginS.o")));
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 23:13:08 +08:00
|
|
|
std::string Triple = getToolChain().getTripleString();
|
|
|
|
if (Triple.substr(0, 6) == "x86_64")
|
2009-11-04 14:24:38 +08:00
|
|
|
Triple.replace(0, 6, "amd64");
|
2009-10-29 10:24:37 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple +
|
2010-08-02 07:13:54 +08:00
|
|
|
"/4.2.1"));
|
2009-08-03 09:28:59 +08:00
|
|
|
|
2009-06-30 04:52:51 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
2013-01-01 06:41:36 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
2009-06-30 04:52:51 +08:00
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
2009-06-30 04:52:51 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2010-08-02 07:13:54 +08:00
|
|
|
if (D.CCCIsCXX) {
|
2010-09-17 09:20:05 +08:00
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2011-12-15 10:15:56 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lm_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lm");
|
2010-08-02 07:13:54 +08:00
|
|
|
}
|
|
|
|
|
2009-08-03 09:28:59 +08:00
|
|
|
// FIXME: For some reason GCC passes -lgcc before adding
|
|
|
|
// the default system libraries. Just mimic this for now.
|
|
|
|
CmdArgs.push_back("-lgcc");
|
2009-06-30 04:52:51 +08:00
|
|
|
|
2012-09-13 14:32:34 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared) &&
|
|
|
|
Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lpthread_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lpthread");
|
|
|
|
}
|
|
|
|
|
2011-12-18 06:32:42 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
2012-09-13 14:32:34 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
2011-12-15 10:15:56 +08:00
|
|
|
CmdArgs.push_back("-lc_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lc");
|
2011-12-18 06:32:42 +08:00
|
|
|
}
|
2012-09-13 14:32:34 +08:00
|
|
|
|
2009-08-03 09:28:59 +08:00
|
|
|
CmdArgs.push_back("-lgcc");
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtend.o")));
|
2009-06-30 04:52:51 +08:00
|
|
|
else
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
getToolChain().GetFilePath("crtendS.o")));
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-06-30 04:52:51 +08:00
|
|
|
}
|
2009-04-03 03:13:12 +08:00
|
|
|
|
2012-08-09 07:57:20 +08:00
|
|
|
void bitrig::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
void bitrig::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if ((!Args.hasArg(options::OPT_nostdlib)) &&
|
|
|
|
(!Args.hasArg(options::OPT_shared))) {
|
|
|
|
CmdArgs.push_back("-e");
|
|
|
|
CmdArgs.push_back("__start");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
|
|
|
CmdArgs.push_back("-Bdynamic");
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-shared");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
|
|
|
CmdArgs.push_back("/usr/libexec/ld.so");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Output.isFilename()) {
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("gcrt0.o")));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crt0.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbegin.o")));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbeginS.o")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
|
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lm_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
2012-10-24 01:07:31 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared) &&
|
|
|
|
Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lpthread_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lpthread");
|
|
|
|
}
|
|
|
|
|
2012-08-09 07:57:20 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lc_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string myarch = "-lclang_rt.";
|
|
|
|
const llvm::Triple &T = getToolChain().getTriple();
|
|
|
|
llvm::Triple::ArchType Arch = T.getArch();
|
|
|
|
switch (Arch) {
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
myarch += ("arm");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
myarch += ("i386");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
myarch += ("amd64");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unsupported architecture");
|
|
|
|
}
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(myarch));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtend.o")));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtendS.o")));
|
|
|
|
}
|
2012-08-10 06:42:04 +08:00
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2012-08-09 07:57:20 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 01:45:15 +08:00
|
|
|
void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-04-09 07:54:23 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-09-09 23:08:12 +08:00
|
|
|
const char *LinkingOutput) const {
|
2009-04-01 01:45:15 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2009-04-02 03:36:32 +08:00
|
|
|
// When building 32-bit code on FreeBSD/amd64, we have to explicitly
|
|
|
|
// instruct as in the base system to assemble 32-bit code.
|
2012-09-06 05:32:44 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86)
|
2009-04-01 01:45:15 +08:00
|
|
|
CmdArgs.push_back("--32");
|
2012-09-06 05:32:44 +08:00
|
|
|
else if (getToolChain().getArch() == llvm::Triple::ppc)
|
2011-06-04 15:37:31 +08:00
|
|
|
CmdArgs.push_back("-a32");
|
2012-09-06 05:32:44 +08:00
|
|
|
else if (getToolChain().getArch() == llvm::Triple::mips ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mipsel ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64 ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64el) {
|
|
|
|
StringRef CPUName;
|
|
|
|
StringRef ABIName;
|
|
|
|
getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-march");
|
|
|
|
CmdArgs.push_back(CPUName.data());
|
|
|
|
|
|
|
|
CmdArgs.push_back("-mabi");
|
2013-02-27 22:55:49 +08:00
|
|
|
CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data());
|
2012-09-06 05:32:44 +08:00
|
|
|
|
|
|
|
if (getToolChain().getArch() == llvm::Triple::mips ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64)
|
|
|
|
CmdArgs.push_back("-EB");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-EL");
|
|
|
|
|
|
|
|
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
|
|
|
|
options::OPT_fpic, options::OPT_fno_pic,
|
|
|
|
options::OPT_fPIE, options::OPT_fno_PIE,
|
|
|
|
options::OPT_fpie, options::OPT_fno_pie);
|
|
|
|
if (LastPICArg &&
|
|
|
|
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fpic) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fPIE) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fpie))) {
|
|
|
|
CmdArgs.push_back("-KPIC");
|
|
|
|
}
|
2012-12-13 12:17:14 +08:00
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::arm ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::thumb) {
|
|
|
|
CmdArgs.push_back("-mfpu=softvfp");
|
|
|
|
switch(getToolChain().getTriple().getEnvironment()) {
|
|
|
|
case llvm::Triple::GNUEABI:
|
|
|
|
case llvm::Triple::EABI:
|
2013-03-18 15:59:20 +08:00
|
|
|
CmdArgs.push_back("-meabi=5");
|
2012-12-13 12:17:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
CmdArgs.push_back("-matpcs");
|
|
|
|
}
|
2012-09-06 05:32:44 +08:00
|
|
|
}
|
2010-03-02 10:41:08 +08:00
|
|
|
|
2009-04-01 01:45:15 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-04-01 01:45:15 +08:00
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-04-01 01:45:15 +08:00
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-04-01 01:45:15 +08:00
|
|
|
}
|
2009-04-02 03:36:32 +08:00
|
|
|
|
|
|
|
void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-04-09 07:54:23 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
2009-05-03 04:14:53 +08:00
|
|
|
const char *LinkingOutput) const {
|
2012-08-28 23:09:03 +08:00
|
|
|
const toolchains::FreeBSD& ToolChain =
|
|
|
|
static_cast<const toolchains::FreeBSD&>(getToolChain());
|
|
|
|
const Driver &D = ToolChain.getDriver();
|
2009-04-02 03:36:32 +08:00
|
|
|
ArgStringList CmdArgs;
|
2012-07-29 23:24:44 +08:00
|
|
|
|
|
|
|
// Silence warning for "clang -g foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
|
|
|
// and "clang -emit-llvm foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
|
|
|
// and for "clang -w foo.o -o foo". Other warning options are already
|
|
|
|
// handled somewhere else.
|
|
|
|
Args.ClaimAllArgs(options::OPT_w);
|
2009-04-02 03:36:32 +08:00
|
|
|
|
2011-03-21 21:51:29 +08:00
|
|
|
if (!D.SysRoot.empty())
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
|
|
|
|
2012-08-28 23:09:03 +08:00
|
|
|
if (Args.hasArg(options::OPT_pie))
|
|
|
|
CmdArgs.push_back("-pie");
|
|
|
|
|
2009-04-02 03:36:32 +08:00
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
2010-11-11 10:17:51 +08:00
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
2009-04-02 03:36:32 +08:00
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-Bshareable");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
|
|
|
CmdArgs.push_back("/libexec/ld-elf.so.1");
|
|
|
|
}
|
2012-08-28 23:09:03 +08:00
|
|
|
if (ToolChain.getTriple().getOSMajorVersion() >= 9) {
|
|
|
|
llvm::Triple::ArchType Arch = ToolChain.getArch();
|
2012-07-29 23:24:44 +08:00
|
|
|
if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc ||
|
|
|
|
Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
|
|
|
|
CmdArgs.push_back("--hash-style=both");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("--enable-new-dtags");
|
2009-04-02 03:36:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// When building 32-bit code on FreeBSD/amd64, we have to explicitly
|
|
|
|
// instruct ld in the base system to link 32-bit code.
|
2012-10-07 12:44:33 +08:00
|
|
|
if (ToolChain.getArch() == llvm::Triple::x86) {
|
2009-04-02 03:36:32 +08:00
|
|
|
CmdArgs.push_back("-m");
|
|
|
|
CmdArgs.push_back("elf_i386_fbsd");
|
|
|
|
}
|
|
|
|
|
2012-10-07 12:44:33 +08:00
|
|
|
if (ToolChain.getArch() == llvm::Triple::ppc) {
|
2011-06-04 15:40:24 +08:00
|
|
|
CmdArgs.push_back("-m");
|
2011-11-22 00:50:32 +08:00
|
|
|
CmdArgs.push_back("elf32ppc_fbsd");
|
2011-06-04 15:40:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2009-04-02 03:36:32 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2012-08-28 23:09:03 +08:00
|
|
|
const char *crt1 = NULL;
|
2009-04-02 03:36:32 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
2011-02-11 00:59:40 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
2012-08-28 23:09:03 +08:00
|
|
|
crt1 = "gcrt1.o";
|
|
|
|
else if (Args.hasArg(options::OPT_pie))
|
|
|
|
crt1 = "Scrt1.o";
|
|
|
|
else
|
|
|
|
crt1 = "crt1.o";
|
2009-04-02 03:36:32 +08:00
|
|
|
}
|
2012-08-28 23:09:03 +08:00
|
|
|
if (crt1)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
|
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
|
|
|
|
|
|
|
|
const char *crtbegin = NULL;
|
|
|
|
if (Args.hasArg(options::OPT_static))
|
|
|
|
crtbegin = "crtbeginT.o";
|
|
|
|
else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
|
|
|
crtbegin = "crtbeginS.o";
|
|
|
|
else
|
|
|
|
crtbegin = "crtbegin.o";
|
|
|
|
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
|
2009-04-02 03:36:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
2012-08-28 23:09:03 +08:00
|
|
|
const ToolChain::path_list Paths = ToolChain.getFilePaths();
|
2011-03-02 01:53:14 +08:00
|
|
|
for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
|
|
|
|
i != e; ++i)
|
2011-07-23 18:55:15 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
|
2009-04-02 03:36:32 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
2010-08-16 06:58:12 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
2009-04-02 03:36:32 +08:00
|
|
|
|
2012-08-28 23:09:03 +08:00
|
|
|
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
2011-02-03 02:59:27 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (D.CCCIsCXX) {
|
2012-08-28 23:09:03 +08:00
|
|
|
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
|
2011-02-11 00:59:40 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lm_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lm");
|
2011-02-03 02:59:27 +08:00
|
|
|
}
|
|
|
|
// FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
|
|
|
|
// the default system libraries. Just mimic this for now.
|
2011-02-11 00:59:40 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lgcc_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lgcc");
|
2011-02-03 02:59:27 +08:00
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
2011-02-11 00:59:40 +08:00
|
|
|
} else if (Args.hasArg(options::OPT_pg)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh_p");
|
2011-02-03 02:59:27 +08:00
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_s");
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
|
|
|
|
2011-02-11 04:35:01 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread)) {
|
2011-02-11 00:59:40 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-lpthread_p");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lpthread");
|
2011-02-11 04:35:01 +08:00
|
|
|
}
|
2011-02-11 00:59:40 +08:00
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pg)) {
|
|
|
|
if (Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-lc_p");
|
|
|
|
CmdArgs.push_back("-lgcc_p");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
}
|
2011-02-03 02:59:27 +08:00
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
2011-02-11 00:59:40 +08:00
|
|
|
} else if (Args.hasArg(options::OPT_pg)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh_p");
|
2011-02-03 02:59:27 +08:00
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_s");
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2012-09-07 21:36:21 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
2012-08-28 23:09:03 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
|
2012-09-07 21:36:21 +08:00
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
|
2012-08-28 23:09:03 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
|
2011-02-03 02:59:27 +08:00
|
|
|
}
|
|
|
|
|
2012-08-28 23:09:03 +08:00
|
|
|
addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple());
|
2011-05-25 05:54:59 +08:00
|
|
|
|
2011-02-03 02:59:27 +08:00
|
|
|
const char *Exec =
|
2012-08-28 23:09:03 +08:00
|
|
|
Args.MakeArgString(ToolChain.GetProgramPath("ld"));
|
2011-02-03 02:59:27 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
// When building 32-bit code on NetBSD/amd64, we have to explicitly
|
|
|
|
// instruct as in the base system to assemble 32-bit code.
|
2012-01-27 06:27:52 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86)
|
2011-02-03 02:59:27 +08:00
|
|
|
CmdArgs.push_back("--32");
|
|
|
|
|
|
|
|
// Set byte order explicitly
|
2012-10-07 12:44:33 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::mips)
|
2011-02-03 02:59:27 +08:00
|
|
|
CmdArgs.push_back("-EB");
|
2012-10-07 12:44:33 +08:00
|
|
|
else if (getToolChain().getArch() == llvm::Triple::mipsel)
|
2011-02-03 02:59:27 +08:00
|
|
|
CmdArgs.push_back("-EL");
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
}
|
|
|
|
|
2011-09-28 06:03:18 +08:00
|
|
|
const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as")));
|
2011-02-03 02:59:27 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2011-03-21 21:51:29 +08:00
|
|
|
if (!D.SysRoot.empty())
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
|
|
|
|
2011-02-03 02:59:27 +08:00
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-Bshareable");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
|
|
|
CmdArgs.push_back("/libexec/ld.elf_so");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When building 32-bit code on NetBSD/amd64, we have to explicitly
|
|
|
|
// instruct ld in the base system to link 32-bit code.
|
2012-01-27 06:27:52 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86) {
|
2011-02-03 02:59:27 +08:00
|
|
|
CmdArgs.push_back("-m");
|
|
|
|
CmdArgs.push_back("elf_i386");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Output.isFilename()) {
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crt0.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crti.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbegin.o")));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crti.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbeginS.o")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
|
|
|
|
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
2009-04-02 03:36:32 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2010-02-17 16:07:51 +08:00
|
|
|
if (D.CCCIsCXX) {
|
2010-09-17 09:20:05 +08:00
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2010-02-17 16:07:51 +08:00
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
2009-04-02 03:36:32 +08:00
|
|
|
// FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
|
|
|
|
// the default system libraries. Just mimic this for now.
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_s");
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
2011-06-08 07:39:17 +08:00
|
|
|
CmdArgs.push_back("-lgcc");
|
2009-04-02 03:36:32 +08:00
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-lpthread");
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_s");
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
2010-07-15 02:46:23 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
2010-07-08 00:01:42 +08:00
|
|
|
"crtend.o")));
|
2009-04-02 03:36:32 +08:00
|
|
|
else
|
2010-07-15 02:46:23 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
2010-07-08 00:01:42 +08:00
|
|
|
"crtendS.o")));
|
2010-07-15 02:46:23 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
2010-07-08 00:01:42 +08:00
|
|
|
"crtn.o")));
|
2009-04-02 03:36:32 +08:00
|
|
|
}
|
|
|
|
|
2011-06-28 03:15:03 +08:00
|
|
|
addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
2011-05-25 05:54:59 +08:00
|
|
|
|
2011-09-28 06:03:18 +08:00
|
|
|
const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-04-02 03:36:32 +08:00
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
|
2013-03-29 03:04:25 +08:00
|
|
|
void gnutools::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2010-08-10 08:25:48 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
// Add --32/--64 to make sure we get the format we want.
|
|
|
|
// This is incomplete
|
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86) {
|
|
|
|
CmdArgs.push_back("--32");
|
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::x86_64) {
|
|
|
|
CmdArgs.push_back("--64");
|
2011-11-29 07:46:52 +08:00
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::ppc) {
|
|
|
|
CmdArgs.push_back("-a32");
|
|
|
|
CmdArgs.push_back("-mppc");
|
|
|
|
CmdArgs.push_back("-many");
|
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::ppc64) {
|
|
|
|
CmdArgs.push_back("-a64");
|
|
|
|
CmdArgs.push_back("-mppc64");
|
|
|
|
CmdArgs.push_back("-many");
|
2010-08-10 08:25:48 +08:00
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::arm) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef MArch = getToolChain().getArchName();
|
2010-08-10 08:25:48 +08:00
|
|
|
if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a")
|
|
|
|
CmdArgs.push_back("-mfpu=neon");
|
2012-04-20 17:03:40 +08:00
|
|
|
|
|
|
|
StringRef ARMFloatABI = getARMFloatABI(getToolChain().getDriver(), Args,
|
|
|
|
getToolChain().getTriple());
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-mfloat-abi=" + ARMFloatABI));
|
2012-04-24 17:05:31 +08:00
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_march_EQ);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mcpu_EQ);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mfpu_EQ);
|
2011-12-01 03:31:38 +08:00
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::mips ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mipsel ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64 ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64el) {
|
2012-04-08 06:31:29 +08:00
|
|
|
StringRef CPUName;
|
|
|
|
StringRef ABIName;
|
|
|
|
getMipsCPUAndABI(Args, getToolChain(), CPUName, ABIName);
|
2011-12-01 03:31:38 +08:00
|
|
|
|
2012-04-08 06:31:29 +08:00
|
|
|
CmdArgs.push_back("-march");
|
|
|
|
CmdArgs.push_back(CPUName.data());
|
|
|
|
|
|
|
|
CmdArgs.push_back("-mabi");
|
2013-02-27 22:55:49 +08:00
|
|
|
CmdArgs.push_back(getGnuCompatibleMipsABIName(ABIName).data());
|
2012-04-07 03:15:24 +08:00
|
|
|
|
|
|
|
if (getToolChain().getArch() == llvm::Triple::mips ||
|
|
|
|
getToolChain().getArch() == llvm::Triple::mips64)
|
|
|
|
CmdArgs.push_back("-EB");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-EL");
|
2012-05-30 03:07:33 +08:00
|
|
|
|
2013-04-30 15:47:13 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mips16, options::OPT_mno_mips16);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mmicromips,
|
|
|
|
options::OPT_mno_micromips);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mdsp, options::OPT_mno_dsp);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_mdspr2, options::OPT_mno_dspr2);
|
|
|
|
|
2012-05-30 03:07:33 +08:00
|
|
|
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
|
|
|
|
options::OPT_fpic, options::OPT_fno_pic,
|
|
|
|
options::OPT_fPIE, options::OPT_fno_PIE,
|
|
|
|
options::OPT_fpie, options::OPT_fno_pie);
|
|
|
|
if (LastPICArg &&
|
|
|
|
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fpic) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fPIE) ||
|
|
|
|
LastPICArg->getOption().matches(options::OPT_fpie))) {
|
|
|
|
CmdArgs.push_back("-KPIC");
|
|
|
|
}
|
2013-05-07 00:26:41 +08:00
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::systemz) {
|
|
|
|
// At the moment we always produce z10 code.
|
|
|
|
CmdArgs.push_back("-march=z10");
|
2010-08-10 08:25:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2013-06-06 07:58:15 +08:00
|
|
|
|
|
|
|
// Handle the debug info splitting at object creation time if we're
|
|
|
|
// creating an object.
|
|
|
|
// TODO: Currently only works on linux with newer objcopy.
|
|
|
|
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
|
|
|
|
(getToolChain().getTriple().getOS() == llvm::Triple::Linux))
|
|
|
|
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
|
|
|
|
SplitDebugName(Args, Inputs));
|
2010-08-10 08:25:48 +08:00
|
|
|
}
|
|
|
|
|
2012-04-25 16:59:22 +08:00
|
|
|
static void AddLibgcc(llvm::Triple Triple, const Driver &D,
|
|
|
|
ArgStringList &CmdArgs, const ArgList &Args) {
|
2012-09-02 17:30:11 +08:00
|
|
|
bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android;
|
2013-03-04 10:07:55 +08:00
|
|
|
bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
|
|
|
|
Args.hasArg(options::OPT_static);
|
2011-10-18 05:39:04 +08:00
|
|
|
if (!D.CCCIsCXX)
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
|
2012-11-19 20:04:11 +08:00
|
|
|
if (StaticLibgcc || isAndroid) {
|
2011-10-18 05:39:04 +08:00
|
|
|
if (D.CCCIsCXX)
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
} else {
|
|
|
|
if (!D.CCCIsCXX)
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_s");
|
|
|
|
if (!D.CCCIsCXX)
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
|
|
|
|
2012-04-25 16:59:22 +08:00
|
|
|
if (StaticLibgcc && !isAndroid)
|
2011-10-18 05:39:04 +08:00
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
|
|
|
else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
|
|
|
|
CmdArgs.push_back("-lgcc");
|
2012-11-19 20:04:11 +08:00
|
|
|
|
|
|
|
// According to Android ABI, we have to link with libdl if we are
|
|
|
|
// linking with non-static libgcc.
|
|
|
|
//
|
|
|
|
// NOTE: This fixes a link error on Android MIPS as well. The non-static
|
|
|
|
// libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl.
|
|
|
|
if (isAndroid && !StaticLibgcc)
|
|
|
|
CmdArgs.push_back("-ldl");
|
2011-10-18 05:39:04 +08:00
|
|
|
}
|
|
|
|
|
2012-10-21 19:44:57 +08:00
|
|
|
static bool hasMipsN32ABIArg(const ArgList &Args) {
|
|
|
|
Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
|
2012-11-01 12:30:05 +08:00
|
|
|
return A && (A->getValue() == StringRef("n32"));
|
2012-10-21 19:44:57 +08:00
|
|
|
}
|
|
|
|
|
2013-05-28 05:40:20 +08:00
|
|
|
static StringRef getLinuxDynamicLinker(const ArgList &Args,
|
|
|
|
const toolchains::Linux &ToolChain) {
|
|
|
|
if (ToolChain.getTriple().getEnvironment() == llvm::Triple::Android)
|
|
|
|
return "/system/bin/linker";
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::x86)
|
|
|
|
return "/lib/ld-linux.so.2";
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::aarch64)
|
|
|
|
return "/lib/ld-linux-aarch64.so.1";
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::arm ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::thumb) {
|
|
|
|
if (ToolChain.getTriple().getEnvironment() == llvm::Triple::GNUEABIHF)
|
|
|
|
return "/lib/ld-linux-armhf.so.3";
|
|
|
|
else
|
|
|
|
return "/lib/ld-linux.so.3";
|
|
|
|
} else if (ToolChain.getArch() == llvm::Triple::mips ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::mipsel)
|
|
|
|
return "/lib/ld.so.1";
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::mips64 ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::mips64el) {
|
|
|
|
if (hasMipsN32ABIArg(Args))
|
|
|
|
return "/lib32/ld.so.1";
|
|
|
|
else
|
|
|
|
return "/lib64/ld.so.1";
|
|
|
|
} else if (ToolChain.getArch() == llvm::Triple::ppc)
|
|
|
|
return "/lib/ld.so.1";
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::ppc64 ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::systemz)
|
|
|
|
return "/lib64/ld64.so.1";
|
|
|
|
else
|
|
|
|
return "/lib64/ld-linux-x86-64.so.2";
|
|
|
|
}
|
|
|
|
|
2013-03-29 03:04:25 +08:00
|
|
|
void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2010-11-08 04:14:31 +08:00
|
|
|
const toolchains::Linux& ToolChain =
|
|
|
|
static_cast<const toolchains::Linux&>(getToolChain());
|
|
|
|
const Driver &D = ToolChain.getDriver();
|
2012-11-03 04:41:30 +08:00
|
|
|
const bool isAndroid =
|
|
|
|
ToolChain.getTriple().getEnvironment() == llvm::Triple::Android;
|
2013-04-09 12:35:11 +08:00
|
|
|
SanitizerArgs Sanitize(getToolChain(), Args);
|
|
|
|
const bool IsPIE =
|
|
|
|
!Args.hasArg(options::OPT_shared) &&
|
|
|
|
(Args.hasArg(options::OPT_pie) || Sanitize.hasZeroBaseShadow());
|
2012-04-25 16:59:22 +08:00
|
|
|
|
2010-11-08 04:14:31 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2010-11-16 02:28:16 +08:00
|
|
|
// Silence warning for "clang -g foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
2011-03-01 13:25:27 +08:00
|
|
|
// and "clang -emit-llvm foo.o -o foo"
|
|
|
|
Args.ClaimAllArgs(options::OPT_emit_llvm);
|
2012-07-29 23:24:44 +08:00
|
|
|
// and for "clang -w foo.o -o foo". Other warning options are already
|
2010-11-18 04:37:10 +08:00
|
|
|
// handled somewhere else.
|
|
|
|
Args.ClaimAllArgs(options::OPT_w);
|
2010-11-16 02:28:16 +08:00
|
|
|
|
2011-03-21 21:51:29 +08:00
|
|
|
if (!D.SysRoot.empty())
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2013-04-09 12:35:11 +08:00
|
|
|
if (IsPIE)
|
2010-11-18 06:26:15 +08:00
|
|
|
CmdArgs.push_back("-pie");
|
|
|
|
|
2010-11-08 06:57:16 +08:00
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
|
|
|
|
2010-11-12 03:34:42 +08:00
|
|
|
if (Args.hasArg(options::OPT_s))
|
|
|
|
CmdArgs.push_back("-s");
|
|
|
|
|
2010-11-08 04:14:31 +08:00
|
|
|
for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(),
|
|
|
|
e = ToolChain.ExtraOpts.end();
|
|
|
|
i != e; ++i)
|
|
|
|
CmdArgs.push_back(i->c_str());
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-m");
|
|
|
|
if (ToolChain.getArch() == llvm::Triple::x86)
|
|
|
|
CmdArgs.push_back("elf_i386");
|
2013-01-31 20:13:10 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::aarch64)
|
|
|
|
CmdArgs.push_back("aarch64linux");
|
2011-08-19 08:30:14 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::arm
|
2011-03-07 03:11:49 +08:00
|
|
|
|| ToolChain.getArch() == llvm::Triple::thumb)
|
2010-11-08 04:14:31 +08:00
|
|
|
CmdArgs.push_back("armelf_linux_eabi");
|
2011-04-06 06:04:27 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::ppc)
|
|
|
|
CmdArgs.push_back("elf32ppclinux");
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::ppc64)
|
|
|
|
CmdArgs.push_back("elf64ppc");
|
2011-11-09 03:43:37 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::mips)
|
|
|
|
CmdArgs.push_back("elf32btsmip");
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::mipsel)
|
|
|
|
CmdArgs.push_back("elf32ltsmip");
|
2012-10-21 19:44:57 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::mips64) {
|
|
|
|
if (hasMipsN32ABIArg(Args))
|
|
|
|
CmdArgs.push_back("elf32btsmipn32");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("elf64btsmip");
|
|
|
|
}
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::mips64el) {
|
|
|
|
if (hasMipsN32ABIArg(Args))
|
|
|
|
CmdArgs.push_back("elf32ltsmipn32");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("elf64ltsmip");
|
|
|
|
}
|
2013-05-07 00:26:41 +08:00
|
|
|
else if (ToolChain.getArch() == llvm::Triple::systemz)
|
|
|
|
CmdArgs.push_back("elf64_s390");
|
2010-11-08 04:14:31 +08:00
|
|
|
else
|
|
|
|
CmdArgs.push_back("elf_x86_64");
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
2011-03-07 03:11:49 +08:00
|
|
|
if (ToolChain.getArch() == llvm::Triple::arm
|
|
|
|
|| ToolChain.getArch() == llvm::Triple::thumb)
|
2010-11-08 04:14:31 +08:00
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-static");
|
|
|
|
} else if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-shared");
|
2012-11-03 04:41:30 +08:00
|
|
|
if (isAndroid) {
|
2012-04-25 16:59:22 +08:00
|
|
|
CmdArgs.push_back("-Bsymbolic");
|
|
|
|
}
|
2010-11-08 04:14:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ToolChain.getArch() == llvm::Triple::arm ||
|
2011-03-07 03:11:49 +08:00
|
|
|
ToolChain.getArch() == llvm::Triple::thumb ||
|
2010-11-08 04:14:31 +08:00
|
|
|
(!Args.hasArg(options::OPT_static) &&
|
|
|
|
!Args.hasArg(options::OPT_shared))) {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
2013-05-28 05:40:20 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
D.DyldPrefix + getLinuxDynamicLinker(Args, ToolChain)));
|
2010-11-08 04:14:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
2010-12-01 09:52:43 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2012-04-25 16:59:22 +08:00
|
|
|
if (!isAndroid) {
|
|
|
|
const char *crt1 = NULL;
|
|
|
|
if (!Args.hasArg(options::OPT_shared)){
|
2013-06-08 07:25:01 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
crt1 = "gcrt1.o";
|
|
|
|
else if (IsPIE)
|
2012-04-25 16:59:22 +08:00
|
|
|
crt1 = "Scrt1.o";
|
|
|
|
else
|
|
|
|
crt1 = "crt1.o";
|
|
|
|
}
|
|
|
|
if (crt1)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2012-04-25 16:59:22 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
|
|
|
|
}
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2010-11-12 11:00:39 +08:00
|
|
|
const char *crtbegin;
|
|
|
|
if (Args.hasArg(options::OPT_static))
|
2012-04-25 16:59:22 +08:00
|
|
|
crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o";
|
2012-09-10 18:30:12 +08:00
|
|
|
else if (Args.hasArg(options::OPT_shared))
|
2012-04-25 16:59:22 +08:00
|
|
|
crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o";
|
2013-04-09 12:35:11 +08:00
|
|
|
else if (IsPIE)
|
2012-09-10 18:30:12 +08:00
|
|
|
crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o";
|
2010-11-12 11:00:39 +08:00
|
|
|
else
|
2012-04-25 16:59:22 +08:00
|
|
|
crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o";
|
2010-11-12 11:00:39 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
|
2012-10-05 03:42:20 +08:00
|
|
|
|
|
|
|
// Add crtfastmath.o if available and fast math is enabled.
|
|
|
|
ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs);
|
2010-11-12 11:00:39 +08:00
|
|
|
}
|
2010-11-08 04:14:31 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
|
|
|
|
const ToolChain::path_list Paths = ToolChain.getFilePaths();
|
|
|
|
|
2011-03-02 01:53:14 +08:00
|
|
|
for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
|
|
|
|
i != e; ++i)
|
2011-07-23 18:55:15 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2012-04-10 07:53:34 +08:00
|
|
|
// Tell the linker to load the plugin. This has to come before AddLinkerInputs
|
|
|
|
// as gold requires -plugin to come before any -plugin-opt that -Wl might
|
|
|
|
// forward.
|
|
|
|
if (D.IsUsingLTO(Args) || Args.hasArg(options::OPT_use_gold_plugin)) {
|
|
|
|
CmdArgs.push_back("-plugin");
|
|
|
|
std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so";
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(Plugin));
|
2013-01-13 19:46:33 +08:00
|
|
|
|
|
|
|
// Try to pass driver level flags relevant to LTO code generation down to
|
|
|
|
// the plugin.
|
|
|
|
|
|
|
|
// Handle architecture-specific flags for selecting CPU variants.
|
|
|
|
if (ToolChain.getArch() == llvm::Triple::x86 ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::x86_64)
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString(Twine("-plugin-opt=mcpu=") +
|
|
|
|
getX86TargetCPU(Args, ToolChain.getTriple())));
|
|
|
|
else if (ToolChain.getArch() == llvm::Triple::arm ||
|
|
|
|
ToolChain.getArch() == llvm::Triple::thumb)
|
|
|
|
CmdArgs.push_back(
|
|
|
|
Args.MakeArgString(Twine("-plugin-opt=mcpu=") +
|
|
|
|
getARMTargetCPU(Args, ToolChain.getTriple())));
|
|
|
|
|
|
|
|
// FIXME: Factor out logic for MIPS, PPC, and other targets to support this
|
|
|
|
// as well.
|
2012-04-10 07:53:34 +08:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:46:33 +08:00
|
|
|
|
2012-08-17 11:39:16 +08:00
|
|
|
if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
|
|
|
|
CmdArgs.push_back("--no-demangle");
|
|
|
|
|
2010-11-08 04:14:31 +08:00
|
|
|
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
|
|
|
|
|
2012-11-30 02:51:05 +08:00
|
|
|
// Call these before we add the C++ ABI library.
|
2012-11-06 06:04:41 +08:00
|
|
|
if (Sanitize.needsUbsanRt())
|
2013-03-21 07:49:07 +08:00
|
|
|
addUbsanRTLinux(getToolChain(), Args, CmdArgs, D.CCCIsCXX,
|
|
|
|
Sanitize.needsAsanRt() || Sanitize.needsTsanRt() ||
|
2013-05-27 19:17:01 +08:00
|
|
|
Sanitize.needsMsanRt() || Sanitize.needsLsanRt());
|
2012-11-30 02:51:05 +08:00
|
|
|
if (Sanitize.needsAsanRt())
|
|
|
|
addAsanRTLinux(getToolChain(), Args, CmdArgs);
|
|
|
|
if (Sanitize.needsTsanRt())
|
|
|
|
addTsanRTLinux(getToolChain(), Args, CmdArgs);
|
2012-12-03 21:20:43 +08:00
|
|
|
if (Sanitize.needsMsanRt())
|
|
|
|
addMsanRTLinux(getToolChain(), Args, CmdArgs);
|
2013-05-27 19:17:01 +08:00
|
|
|
if (Sanitize.needsLsanRt())
|
|
|
|
addLsanRTLinux(getToolChain(), Args, CmdArgs);
|
2012-10-25 10:14:12 +08:00
|
|
|
|
2013-06-24 17:38:45 +08:00
|
|
|
// The profile runtime also needs access to system libraries.
|
|
|
|
addProfileRTLinux(getToolChain(), Args, CmdArgs);
|
|
|
|
|
2012-05-15 02:31:18 +08:00
|
|
|
if (D.CCCIsCXX &&
|
|
|
|
!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2011-10-18 06:14:51 +08:00
|
|
|
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
|
|
|
|
!Args.hasArg(options::OPT_static);
|
|
|
|
if (OnlyLibstdcxxStatic)
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
2010-11-08 04:14:31 +08:00
|
|
|
ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
|
2011-10-18 06:14:51 +08:00
|
|
|
if (OnlyLibstdcxxStatic)
|
|
|
|
CmdArgs.push_back("-Bdynamic");
|
2010-11-08 04:14:31 +08:00
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
2010-11-12 11:00:39 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib)) {
|
2012-05-15 02:31:18 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (Args.hasArg(options::OPT_static))
|
|
|
|
CmdArgs.push_back("--start-group");
|
2010-11-12 03:34:42 +08:00
|
|
|
|
2013-01-17 21:19:29 +08:00
|
|
|
bool OpenMP = Args.hasArg(options::OPT_fopenmp);
|
|
|
|
if (OpenMP) {
|
|
|
|
CmdArgs.push_back("-lgomp");
|
|
|
|
|
|
|
|
// FIXME: Exclude this for platforms whith libgomp that doesn't require
|
|
|
|
// librt. Most modern Linux platfroms require it, but some may not.
|
|
|
|
CmdArgs.push_back("-lrt");
|
|
|
|
}
|
|
|
|
|
2012-05-15 02:31:18 +08:00
|
|
|
AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2012-05-15 02:31:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread) ||
|
2013-01-17 21:19:29 +08:00
|
|
|
Args.hasArg(options::OPT_pthreads) || OpenMP)
|
2012-05-15 02:31:18 +08:00
|
|
|
CmdArgs.push_back("-lpthread");
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2012-05-15 02:31:18 +08:00
|
|
|
CmdArgs.push_back("-lc");
|
2010-11-08 04:14:31 +08:00
|
|
|
|
2012-05-15 02:31:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_static))
|
|
|
|
CmdArgs.push_back("--end-group");
|
|
|
|
else
|
|
|
|
AddLibgcc(ToolChain.getTriple(), D, CmdArgs, Args);
|
|
|
|
}
|
2010-11-18 06:26:15 +08:00
|
|
|
|
2010-12-01 09:52:43 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
const char *crtend;
|
2012-09-10 18:30:12 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared))
|
2012-04-25 16:59:22 +08:00
|
|
|
crtend = isAndroid ? "crtend_so.o" : "crtendS.o";
|
2013-04-09 12:35:11 +08:00
|
|
|
else if (IsPIE)
|
2012-09-10 18:30:12 +08:00
|
|
|
crtend = isAndroid ? "crtend_android.o" : "crtendS.o";
|
2010-12-01 09:52:43 +08:00
|
|
|
else
|
2012-04-25 16:59:22 +08:00
|
|
|
crtend = isAndroid ? "crtend_android.o" : "crtend.o";
|
2010-11-12 11:00:39 +08:00
|
|
|
|
2010-12-01 09:52:43 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
|
2012-04-25 16:59:22 +08:00
|
|
|
if (!isAndroid)
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
|
2010-12-01 09:52:43 +08:00
|
|
|
}
|
2010-11-12 11:00:39 +08:00
|
|
|
}
|
2010-11-08 04:14:31 +08:00
|
|
|
|
|
|
|
C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs));
|
|
|
|
}
|
2010-08-10 08:25:48 +08:00
|
|
|
|
2010-07-08 00:01:42 +08:00
|
|
|
void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2010-07-08 00:01:42 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2010-07-08 00:01:42 +08:00
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2010-07-08 00:01:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2011-12-09 07:54:21 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2010-07-08 00:01:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2010-07-08 00:01:42 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
2011-12-09 07:54:21 +08:00
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
|
|
|
|
}
|
2010-07-08 00:01:42 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
2010-07-08 00:01:42 +08:00
|
|
|
|
2011-12-09 07:54:21 +08:00
|
|
|
addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
|
|
|
|
2010-07-08 00:01:42 +08:00
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (D.CCCIsCXX) {
|
2010-09-17 09:20:05 +08:00
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2011-12-09 07:54:21 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-lpthread");
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
CmdArgs.push_back("-lCompilerRT-Generic");
|
|
|
|
CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
|
|
|
|
CmdArgs.push_back(
|
2012-12-18 08:31:10 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
}
|
|
|
|
|
2011-12-09 07:54:21 +08:00
|
|
|
const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2010-07-08 00:01:42 +08:00
|
|
|
}
|
|
|
|
|
2009-05-03 02:28:39 +08:00
|
|
|
/// DragonFly Tools
|
|
|
|
|
|
|
|
// For now, DragonFly Assemble does just about the same as for
|
|
|
|
// FreeBSD, but this may change soon.
|
|
|
|
void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
2009-11-04 14:24:38 +08:00
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2009-05-03 02:28:39 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
// When building 32-bit code on DragonFly/pc64, we have to explicitly
|
|
|
|
// instruct as in the base system to assemble 32-bit code.
|
2012-10-07 12:44:33 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86)
|
2009-05-03 02:28:39 +08:00
|
|
|
CmdArgs.push_back("--32");
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
|
|
|
|
options::OPT_Xassembler);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("as"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
2010-08-02 10:38:28 +08:00
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
2013-04-12 06:55:55 +08:00
|
|
|
bool UseGCC47 = false;
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-05-03 02:28:39 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
2013-04-12 06:55:55 +08:00
|
|
|
if (llvm::sys::fs::exists("/usr/lib/gcc47", UseGCC47))
|
|
|
|
UseGCC47 = false;
|
|
|
|
|
2011-03-21 21:51:29 +08:00
|
|
|
if (!D.SysRoot.empty())
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
|
|
|
|
2013-04-12 06:55:55 +08:00
|
|
|
CmdArgs.push_back("--eh-frame-hdr");
|
2009-05-03 02:28:39 +08:00
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
2013-04-12 06:55:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_rdynamic))
|
|
|
|
CmdArgs.push_back("-export-dynamic");
|
2009-05-03 02:28:39 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back("-Bshareable");
|
|
|
|
else {
|
|
|
|
CmdArgs.push_back("-dynamic-linker");
|
|
|
|
CmdArgs.push_back("/usr/libexec/ld-elf.so.2");
|
|
|
|
}
|
2013-04-12 06:55:55 +08:00
|
|
|
CmdArgs.push_back("--hash-style=both");
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// When building 32-bit code on DragonFly/pc64, we have to explicitly
|
|
|
|
// instruct ld in the base system to link 32-bit code.
|
2012-10-07 12:44:33 +08:00
|
|
|
if (getToolChain().getArch() == llvm::Triple::x86) {
|
2009-05-03 02:28:39 +08:00
|
|
|
CmdArgs.push_back("-m");
|
|
|
|
CmdArgs.push_back("elf_i386");
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isFilename()) {
|
2009-05-03 02:28:39 +08:00
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
if (!Args.hasArg(options::OPT_shared)) {
|
2013-04-12 06:55:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("gcrt1.o")));
|
|
|
|
else {
|
|
|
|
if (Args.hasArg(options::OPT_pie))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("Scrt1.o")));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crt1.o")));
|
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
2013-04-12 06:55:55 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crti.o")));
|
|
|
|
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbeginS.o")));
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
|
|
|
getToolChain().GetFilePath("crtbegin.o")));
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
|
2010-09-17 08:24:54 +08:00
|
|
|
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
// FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
|
|
|
|
// rpaths
|
2013-04-12 06:55:55 +08:00
|
|
|
if (UseGCC47)
|
|
|
|
CmdArgs.push_back("-L/usr/lib/gcc47");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-L/usr/lib/gcc44");
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_static)) {
|
2013-04-12 06:55:55 +08:00
|
|
|
if (UseGCC47) {
|
|
|
|
CmdArgs.push_back("-rpath");
|
|
|
|
CmdArgs.push_back("/usr/lib/gcc47");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-rpath");
|
|
|
|
CmdArgs.push_back("/usr/lib/gcc44");
|
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
2010-07-20 20:59:03 +08:00
|
|
|
if (D.CCCIsCXX) {
|
2010-09-17 09:20:05 +08:00
|
|
|
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
|
2010-07-20 20:59:03 +08:00
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
2009-05-03 02:28:39 +08:00
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
2009-11-01 04:11:46 +08:00
|
|
|
CmdArgs.push_back("-lpthread");
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nolibc)) {
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
}
|
|
|
|
|
2013-04-12 06:55:55 +08:00
|
|
|
if (UseGCC47) {
|
|
|
|
if (Args.hasArg(options::OPT_static) ||
|
|
|
|
Args.hasArg(options::OPT_static_libgcc)) {
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
CmdArgs.push_back("-lgcc_eh");
|
|
|
|
} else {
|
|
|
|
if (Args.hasArg(options::OPT_shared_libgcc)) {
|
|
|
|
CmdArgs.push_back("-lgcc_pic");
|
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
CmdArgs.push_back("--as-needed");
|
|
|
|
CmdArgs.push_back("-lgcc_pic");
|
|
|
|
CmdArgs.push_back("--no-as-needed");
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
} else {
|
2013-04-12 06:55:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-lgcc_pic");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2013-04-12 06:55:55 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2013-04-12 06:55:55 +08:00
|
|
|
getToolChain().GetFilePath("crtendS.o")));
|
2009-05-03 02:28:39 +08:00
|
|
|
else
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2013-04-12 06:55:55 +08:00
|
|
|
getToolChain().GetFilePath("crtend.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2013-04-12 06:55:55 +08:00
|
|
|
getToolChain().GetFilePath("crtn.o")));
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
|
|
|
|
2011-06-28 03:15:03 +08:00
|
|
|
addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
|
2011-05-25 05:54:59 +08:00
|
|
|
|
2009-05-03 02:28:39 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("ld"));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-05-03 02:28:39 +08:00
|
|
|
}
|
2010-08-22 05:55:07 +08:00
|
|
|
|
|
|
|
void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if (Output.isFilename()) {
|
2010-09-17 08:45:02 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(std::string("-out:") +
|
|
|
|
Output.getFilename()));
|
2010-08-22 05:55:07 +08:00
|
|
|
} else {
|
|
|
|
assert(Output.isNothing() && "Invalid output.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
|
|
|
CmdArgs.push_back("-defaultlib:libcmt");
|
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-nologo");
|
|
|
|
|
2012-06-19 00:56:04 +08:00
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_l);
|
|
|
|
|
|
|
|
// Add filenames immediately.
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
if (it->isFilename())
|
|
|
|
CmdArgs.push_back(it->getFilename());
|
|
|
|
}
|
2010-08-22 05:55:07 +08:00
|
|
|
|
|
|
|
const char *Exec =
|
2010-09-17 08:24:54 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("link.exe"));
|
2010-08-22 05:55:07 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
|
|
|
}
|