2009-03-18 14:00:36 +08:00
|
|
|
//===--- Tools.cpp - Tools Implementations ------------------------------*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Tools.h"
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
#include "clang/Driver/Action.h"
|
2009-03-18 15:06:02 +08:00
|
|
|
#include "clang/Driver/Arg.h"
|
2009-03-18 16:07:30 +08:00
|
|
|
#include "clang/Driver/ArgList.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/Compilation.h"
|
|
|
|
#include "clang/Driver/Job.h"
|
2009-03-18 16:07:30 +08:00
|
|
|
#include "clang/Driver/HostInfo.h"
|
|
|
|
#include "clang/Driver/Option.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"
|
2009-03-27 00:23:12 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-11-15 06:04:54 +08:00
|
|
|
#include "llvm/System/Host.h"
|
2009-11-04 14:24:47 +08:00
|
|
|
#include "llvm/System/Process.h"
|
2009-03-18 15:06:02 +08:00
|
|
|
|
|
|
|
#include "InputInfo.h"
|
2009-03-27 00:23:12 +08:00
|
|
|
#include "ToolChains.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;
|
|
|
|
|
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))
|
|
|
|
if (!Args.hasArg(options::OPT_E))
|
|
|
|
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
|
|
|
|
<< 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))
|
|
|
|
D.Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< 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.
|
|
|
|
static void QuoteTarget(llvm::StringRef Target,
|
|
|
|
llvm::SmallVectorImpl<char> &Res) {
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void Clang::AddPreprocessingOptions(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.
|
2009-04-09 07:54:23 +08:00
|
|
|
if ((A = Args.getLastArg(options::OPT_M)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_MM)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_MD)) ||
|
|
|
|
(A = Args.getLastArg(options::OPT_MMD))) {
|
|
|
|
// Determine the output location.
|
|
|
|
const char *DepFile;
|
|
|
|
if (Output.getType() == types::TY_Dependencies) {
|
2010-08-02 10:38:21 +08:00
|
|
|
DepFile = Output.getFilename();
|
2009-04-09 07:54:23 +08:00
|
|
|
} else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
|
|
|
|
DepFile = MF->getValue(Args);
|
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 {
|
|
|
|
DepFile = darwin::CC1::getDependencyFileName(Args, Inputs);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
DepTarget = OutputOpt->getValue(Args);
|
|
|
|
} else {
|
|
|
|
// Otherwise derive from the base input.
|
|
|
|
//
|
|
|
|
// FIXME: This should use the computed output file location.
|
|
|
|
llvm::sys::Path P(Inputs[0].getBaseInput());
|
|
|
|
|
|
|
|
P.eraseSuffix();
|
|
|
|
P.appendSuffix("o");
|
2009-09-10 06:32:48 +08:00
|
|
|
DepTarget = Args.MakeArgString(P.getLast());
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-MT");
|
2010-03-30 01:55:58 +08:00
|
|
|
llvm::SmallString<128> Quoted;
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
llvm::SmallString<128> Quoted;
|
2010-06-12 06:00:13 +08:00
|
|
|
QuoteTarget(A->getValue(Args), 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.
|
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-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;
|
2009-04-09 07:54:23 +08:00
|
|
|
llvm::sys::Path P(A->getValue(Args));
|
2009-10-16 04:02:44 +08:00
|
|
|
if (UsePCH) {
|
2009-04-18 08:34:01 +08:00
|
|
|
P.appendSuffix("pch");
|
2009-04-09 07:54:23 +08:00
|
|
|
if (P.exists())
|
2009-04-18 08:34:01 +08:00
|
|
|
FoundPCH = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
else
|
2009-04-18 08:34:01 +08:00
|
|
|
P.eraseSuffix();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FoundPCH) {
|
|
|
|
P.appendSuffix("pth");
|
2009-09-09 23:08:12 +08:00
|
|
|
if (P.exists())
|
2009-04-09 07:54:23 +08:00
|
|
|
FoundPTH = true;
|
2009-04-18 08:34:01 +08:00
|
|
|
else
|
|
|
|
P.eraseSuffix();
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2009-04-18 08:34:01 +08:00
|
|
|
if (!FoundPCH && !FoundPTH) {
|
|
|
|
P.appendSuffix("gch");
|
|
|
|
if (P.exists()) {
|
2009-10-16 04:02:44 +08:00
|
|
|
FoundPCH = UsePCH;
|
|
|
|
FoundPTH = !UsePCH;
|
2009-04-18 08:34:01 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
else
|
2009-04-18 08:34:01 +08:00
|
|
|
P.eraseSuffix();
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
2009-04-18 08:34:01 +08:00
|
|
|
if (FoundPCH || FoundPTH) {
|
2009-04-09 07:54:23 +08:00
|
|
|
A->claim();
|
2009-10-16 04:02:44 +08:00
|
|
|
if (UsePCH)
|
2009-04-18 08:34:01 +08:00
|
|
|
CmdArgs.push_back("-include-pch");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-include-pth");
|
2009-09-10 06:32:48 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(P.str()));
|
2009-04-09 07:54:23 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not translated, render as usual.
|
|
|
|
A->claim();
|
|
|
|
A->render(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
|
|
|
|
|
|
|
|
// 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_))
|
|
|
|
D.Diag(clang::diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
|
|
|
|
2009-09-10 14:49:20 +08:00
|
|
|
/// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.
|
|
|
|
//
|
|
|
|
// FIXME: tblgen this.
|
2010-06-29 01:18:09 +08:00
|
|
|
static const char *getARMTargetCPU(const ArgList &Args,
|
|
|
|
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.
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
|
|
|
|
return A->getValue(Args);
|
|
|
|
|
2010-06-29 01:18:09 +08:00
|
|
|
llvm::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.
|
|
|
|
MArch = A->getValue(Args);
|
|
|
|
} else {
|
|
|
|
// Otherwise, use the Arch from the triple.
|
|
|
|
MArch = Triple.getArchName();
|
2009-09-10 12:57:17 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 01:18:09 +08:00
|
|
|
if (MArch == "armv2" || MArch == "armv2a")
|
|
|
|
return "arm2";
|
|
|
|
if (MArch == "armv3")
|
|
|
|
return "arm6";
|
|
|
|
if (MArch == "armv3m")
|
|
|
|
return "arm7m";
|
|
|
|
if (MArch == "armv4" || MArch == "armv4t")
|
|
|
|
return "arm7tdmi";
|
|
|
|
if (MArch == "armv5" || MArch == "armv5t")
|
|
|
|
return "arm10tdmi";
|
|
|
|
if (MArch == "armv5e" || MArch == "armv5te")
|
|
|
|
return "arm1026ejs";
|
|
|
|
if (MArch == "armv5tej")
|
|
|
|
return "arm926ej-s";
|
|
|
|
if (MArch == "armv6" || MArch == "armv6k")
|
|
|
|
return "arm1136jf-s";
|
|
|
|
if (MArch == "armv6j")
|
|
|
|
return "arm1136j-s";
|
|
|
|
if (MArch == "armv6z" || MArch == "armv6zk")
|
|
|
|
return "arm1176jzf-s";
|
|
|
|
if (MArch == "armv6t2")
|
|
|
|
return "arm1156t2-s";
|
|
|
|
if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a")
|
|
|
|
return "cortex-a8";
|
|
|
|
if (MArch == "armv7r" || MArch == "armv7-r")
|
|
|
|
return "cortex-r4";
|
|
|
|
if (MArch == "armv7m" || MArch == "armv7-m")
|
|
|
|
return "cortex-m3";
|
|
|
|
if (MArch == "ep9312")
|
|
|
|
return "ep9312";
|
|
|
|
if (MArch == "iwmmxt")
|
|
|
|
return "iwmmxt";
|
|
|
|
if (MArch == "xscale")
|
|
|
|
return "xscale";
|
|
|
|
|
|
|
|
// If all else failed, return the most base CPU LLVM supports.
|
2009-09-10 12:57:17 +08:00
|
|
|
return "arm7tdmi";
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:59:51 +08:00
|
|
|
/// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
|
2009-09-10 14:49:20 +08:00
|
|
|
/// CPU.
|
|
|
|
//
|
|
|
|
// FIXME: This is redundant with -mcpu, why does LLVM use this.
|
|
|
|
// FIXME: tblgen this, or kill it!
|
2009-09-11 06:59:51 +08:00
|
|
|
static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU) {
|
2009-09-10 14:49:20 +08:00
|
|
|
if (CPU == "arm7tdmi" || CPU == "arm7tdmi-s" || CPU == "arm710t" ||
|
|
|
|
CPU == "arm720t" || CPU == "arm9" || CPU == "arm9tdmi" ||
|
|
|
|
CPU == "arm920" || CPU == "arm920t" || CPU == "arm922t" ||
|
|
|
|
CPU == "arm940t" || CPU == "ep9312")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v4t";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
|
|
|
if (CPU == "arm10tdmi" || CPU == "arm1020t")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v5";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
|
|
|
if (CPU == "arm9e" || CPU == "arm926ej-s" || CPU == "arm946e-s" ||
|
|
|
|
CPU == "arm966e-s" || CPU == "arm968e-s" || CPU == "arm10e" ||
|
|
|
|
CPU == "arm1020e" || CPU == "arm1022e" || CPU == "xscale" ||
|
|
|
|
CPU == "iwmmxt")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v5e";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
|
|
|
if (CPU == "arm1136j-s" || CPU == "arm1136jf-s" || CPU == "arm1176jz-s" ||
|
|
|
|
CPU == "arm1176jzf-s" || CPU == "mpcorenovfp" || CPU == "mpcore")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v6";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
|
|
|
if (CPU == "arm1156t2-s" || CPU == "arm1156t2f-s")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v6t2";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
|
|
|
if (CPU == "cortex-a8" || CPU == "cortex-a9")
|
2009-09-11 06:59:51 +08:00
|
|
|
return "v7";
|
2009-09-10 14:49:20 +08:00
|
|
|
|
2009-09-11 06:59:51 +08:00
|
|
|
return "";
|
2009-09-10 14:49:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getLLVMTriple - Get the LLVM triple to use for a particular toolchain, which
|
|
|
|
/// may depend on command line arguments.
|
|
|
|
static std::string getLLVMTriple(const ToolChain &TC, const ArgList &Args) {
|
|
|
|
switch (TC.getTriple().getArch()) {
|
|
|
|
default:
|
|
|
|
return TC.getTripleString();
|
|
|
|
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb: {
|
2009-09-11 09:14:50 +08:00
|
|
|
// FIXME: Factor into subclasses.
|
2009-09-10 14:49:20 +08:00
|
|
|
llvm::Triple Triple = TC.getTriple();
|
2009-09-11 09:14:50 +08:00
|
|
|
|
|
|
|
// Thumb2 is the default for V7 on Darwin.
|
|
|
|
//
|
|
|
|
// FIXME: Thumb should just be another -target-feaure, not in the triple.
|
2010-06-29 01:18:09 +08:00
|
|
|
llvm::StringRef Suffix =
|
|
|
|
getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
|
2009-09-11 09:14:50 +08:00
|
|
|
bool ThumbDefault =
|
|
|
|
(Suffix == "v7" && TC.getTriple().getOS() == llvm::Triple::Darwin);
|
2009-09-11 06:59:51 +08:00
|
|
|
std::string ArchName = "arm";
|
2009-09-11 09:14:50 +08:00
|
|
|
if (Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault))
|
|
|
|
ArchName = "thumb";
|
|
|
|
Triple.setArchName(ArchName + Suffix.str());
|
|
|
|
|
2009-09-10 14:49:20 +08:00
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case llvm::Triple::ppc:
|
|
|
|
case llvm::Triple::ppc64:
|
|
|
|
if (Triple.getOS() == llvm::Triple::Darwin)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case llvm::Triple::systemz:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 12:57:17 +08:00
|
|
|
void Clang::AddARMTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2010-06-29 01:18:09 +08:00
|
|
|
llvm::Triple Triple = getToolChain().getTriple();
|
2009-09-11 07:00:09 +08:00
|
|
|
|
2009-09-14 08:34:46 +08:00
|
|
|
// Select the ABI to use.
|
|
|
|
//
|
|
|
|
// FIXME: Support -meabi.
|
|
|
|
const char *ABIName = 0;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
|
|
|
|
ABIName = A->getValue(Args);
|
|
|
|
} else {
|
|
|
|
// Select the default based on the platform.
|
2010-06-29 01:18:09 +08:00
|
|
|
llvm::StringRef env = Triple.getEnvironmentName();
|
2010-06-17 03:01:17 +08:00
|
|
|
if (env == "gnueabi")
|
|
|
|
ABIName = "aapcs-linux";
|
|
|
|
else if (env == "eabi")
|
2009-09-14 08:34:46 +08:00
|
|
|
ABIName = "aapcs";
|
2010-06-17 03:01:17 +08:00
|
|
|
else
|
2009-09-14 08:34:46 +08:00
|
|
|
ABIName = "apcs-gnu";
|
|
|
|
}
|
|
|
|
CmdArgs.push_back("-target-abi");
|
|
|
|
CmdArgs.push_back(ABIName);
|
|
|
|
|
2009-09-10 12:57:17 +08:00
|
|
|
// Set the CPU based on -march= and -mcpu=.
|
2009-12-18 14:30:12 +08:00
|
|
|
CmdArgs.push_back("-target-cpu");
|
2010-06-29 01:18:09 +08:00
|
|
|
CmdArgs.push_back(getARMTargetCPU(Args, Triple));
|
2009-09-10 12:57:17 +08:00
|
|
|
|
2009-09-11 07:00:09 +08:00
|
|
|
// Select the float ABI as determined by -msoft-float, -mhard-float, and
|
|
|
|
// -mfloat-abi=.
|
|
|
|
llvm::StringRef FloatABI;
|
|
|
|
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 {
|
|
|
|
FloatABI = A->getValue(Args);
|
|
|
|
if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") {
|
|
|
|
D.Diag(clang::diag::err_drv_invalid_mfloat_abi)
|
|
|
|
<< 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
|
|
|
const llvm::Triple &Triple = getToolChain().getTriple();
|
|
|
|
switch (Triple.getOS()) {
|
2009-09-11 07:00:09 +08:00
|
|
|
case llvm::Triple::Darwin: {
|
|
|
|
// Darwin defaults to "softfp" for v6 and v7.
|
|
|
|
//
|
|
|
|
// FIXME: Factor out an ARM class so we can cache the arch somewhere.
|
2010-06-29 01:18:09 +08:00
|
|
|
llvm::StringRef ArchName =
|
|
|
|
getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
|
2009-09-11 07:00:09 +08:00
|
|
|
if (ArchName.startswith("v6") || ArchName.startswith("v7"))
|
|
|
|
FloatABI = "softfp";
|
|
|
|
else
|
|
|
|
FloatABI = "soft";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-28 02:29:21 +08:00
|
|
|
case llvm::Triple::Linux: {
|
|
|
|
llvm::StringRef Env = getToolChain().getTriple().getEnvironmentName();
|
|
|
|
if (Env == "gnueabi") {
|
|
|
|
FloatABI = "softfp";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
|
2009-09-11 07:00:09 +08:00
|
|
|
default:
|
|
|
|
// Assume "soft", but warn the user we are guessing.
|
|
|
|
FloatABI = "soft";
|
|
|
|
D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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=.
|
|
|
|
//
|
|
|
|
// FIXME: Centralize feature selection, defaulting shouldn't be also in the
|
|
|
|
// frontend target.
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
|
|
|
|
llvm::StringRef FPU = A->getValue(Args);
|
|
|
|
|
|
|
|
// 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 == "vfp") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+vfp2");
|
|
|
|
} else if (FPU == "vfp3") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+vfp3");
|
|
|
|
} else if (FPU == "neon") {
|
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back("+neon");
|
|
|
|
} else
|
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
|
|
|
}
|
2009-09-10 12:57:17 +08:00
|
|
|
}
|
|
|
|
|
2010-03-02 10:41:08 +08:00
|
|
|
void Clang::AddMIPSTargetArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
|
|
|
|
// Select the ABI to use.
|
|
|
|
const char *ABIName = 0;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
|
|
|
|
ABIName = A->getValue(Args);
|
|
|
|
} else {
|
|
|
|
ABIName = "o32";
|
|
|
|
}
|
|
|
|
|
|
|
|
CmdArgs.push_back("-target-abi");
|
|
|
|
CmdArgs.push_back(ABIName);
|
|
|
|
|
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
|
|
|
llvm::StringRef MArch = A->getValue(Args);
|
|
|
|
CmdArgs.push_back("-target-cpu");
|
|
|
|
|
|
|
|
if ((MArch == "r2000") || (MArch == "r3000"))
|
|
|
|
CmdArgs.push_back("mips1");
|
|
|
|
else if (MArch == "r6000")
|
|
|
|
CmdArgs.push_back("mips2");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back(MArch.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the float ABI as determined by -msoft-float, -mhard-float, and
|
|
|
|
llvm::StringRef FloatABI;
|
|
|
|
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()) {
|
2010-04-08 23:44:22 +08:00
|
|
|
// Assume "soft", but warn the user we are guessing.
|
|
|
|
FloatABI = "soft";
|
|
|
|
D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
|
2010-03-02 10:41:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
} else {
|
|
|
|
assert(FloatABI == "hard" && "Invalid float abi!");
|
|
|
|
CmdArgs.push_back("-mhard-float");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (Args.hasFlag(options::OPT_msoft_float,
|
|
|
|
options::OPT_mno_soft_float,
|
|
|
|
false))
|
2009-11-21 06:21:36 +08:00
|
|
|
CmdArgs.push_back("-no-implicit-float");
|
2009-09-11 06:59:57 +08:00
|
|
|
|
2009-11-15 06:04:54 +08:00
|
|
|
const char *CPUName = 0;
|
2009-09-10 06:33:08 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
|
2009-11-15 06:04:54 +08:00
|
|
|
if (llvm::StringRef(A->getValue(Args)) == "native") {
|
|
|
|
// 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())
|
|
|
|
CPUName = Args.MakeArgString(CPU);
|
|
|
|
} else
|
|
|
|
CPUName = A->getValue(Args);
|
|
|
|
}
|
2009-09-10 06:33:08 +08:00
|
|
|
|
2009-11-15 06:04:54 +08:00
|
|
|
// Select the default CPU if none was given (or detection failed).
|
|
|
|
if (!CPUName) {
|
2009-09-10 06:33:08 +08:00
|
|
|
// FIXME: Need target hooks.
|
2010-01-30 23:01:47 +08:00
|
|
|
if (getToolChain().getOS().startswith("darwin")) {
|
2009-09-10 06:33:08 +08:00
|
|
|
if (getToolChain().getArchName() == "x86_64")
|
2009-11-15 06:04:54 +08:00
|
|
|
CPUName = "core2";
|
2009-09-10 06:33:08 +08:00
|
|
|
else if (getToolChain().getArchName() == "i386")
|
2009-11-15 06:04:54 +08:00
|
|
|
CPUName = "yonah";
|
2010-04-12 03:29:39 +08:00
|
|
|
} else if (getToolChain().getOS().startswith("haiku")) {
|
|
|
|
if (getToolChain().getArchName() == "x86_64")
|
|
|
|
CPUName = "x86-64";
|
|
|
|
else if (getToolChain().getArchName() == "i386")
|
|
|
|
CPUName = "i586";
|
2010-08-02 07:13:54 +08:00
|
|
|
} else if (getToolChain().getOS().startswith("openbsd")) {
|
|
|
|
if (getToolChain().getArchName() == "x86_64")
|
|
|
|
CPUName = "x86-64";
|
|
|
|
else if (getToolChain().getArchName() == "i386")
|
|
|
|
CPUName = "i486";
|
2009-09-10 06:33:08 +08:00
|
|
|
} else {
|
|
|
|
if (getToolChain().getArchName() == "x86_64")
|
2009-11-15 06:04:54 +08:00
|
|
|
CPUName = "x86-64";
|
2009-09-10 06:33:08 +08:00
|
|
|
else if (getToolChain().getArchName() == "i386")
|
2009-11-15 06:04:54 +08:00
|
|
|
CPUName = "pentium4";
|
2009-09-10 06:33:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 06:04:54 +08:00
|
|
|
if (CPUName) {
|
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);
|
|
|
|
}
|
|
|
|
|
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) {
|
2010-06-12 06:00:13 +08:00
|
|
|
llvm::StringRef Name = (*it)->getOption().getName();
|
|
|
|
(*it)->claim();
|
2009-09-10 06:33:08 +08:00
|
|
|
|
2009-11-25 19:53:23 +08:00
|
|
|
// Skip over "-m".
|
|
|
|
assert(Name.startswith("-m") && "Invalid feature name.");
|
|
|
|
Name = Name.substr(2);
|
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
|
|
|
|
2009-11-25 19:53:23 +08:00
|
|
|
CmdArgs.push_back("-target-feature");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
|
2009-09-10 06:33:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 04:30:46 +08:00
|
|
|
static bool needsExceptions(const ArgList &Args, types::ID InputType,
|
|
|
|
const llvm::Triple &Triple) {
|
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))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (InputType) {
|
|
|
|
case types::TY_CXX: case types::TY_CXXHeader:
|
|
|
|
case types::TY_PP_CXX: case types::TY_PP_CXXHeader:
|
|
|
|
case types::TY_ObjCXX: case types::TY_ObjCXXHeader:
|
|
|
|
case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader:
|
|
|
|
return true;
|
2009-10-02 04:30:46 +08:00
|
|
|
|
2009-10-01 21:33:33 +08:00
|
|
|
case types::TY_ObjC: case types::TY_ObjCHeader:
|
|
|
|
case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader:
|
|
|
|
if (Args.hasArg(options::OPT_fobjc_nonfragile_abi))
|
|
|
|
return true;
|
2009-10-02 04:30:46 +08:00
|
|
|
if (Triple.getOS() != llvm::Triple::Darwin)
|
2009-10-01 21:33:33 +08:00
|
|
|
return false;
|
2009-10-02 04:30:46 +08:00
|
|
|
return (Triple.getDarwinMajorNumber() >= 9 &&
|
|
|
|
Triple.getArch() == llvm::Triple::x86_64);
|
|
|
|
|
2009-10-01 21:33:33 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-31 02:12:20 +08:00
|
|
|
/// getEffectiveClangTriple - Get the "effective" target triple, which is the
|
|
|
|
/// triple for the target but with the OS version potentially modified for
|
|
|
|
/// Darwin's -mmacosx-version-min.
|
|
|
|
static std::string getEffectiveClangTriple(const Driver &D,
|
|
|
|
const ToolChain &TC,
|
|
|
|
const ArgList &Args) {
|
|
|
|
llvm::Triple Triple(getLLVMTriple(TC, Args));
|
|
|
|
|
2010-01-27 08:56:49 +08:00
|
|
|
// Handle -mmacosx-version-min and -miphoneos-version-min.
|
2009-10-31 02:12:20 +08:00
|
|
|
if (Triple.getOS() != llvm::Triple::Darwin) {
|
|
|
|
// Diagnose use of -mmacosx-version-min and -miphoneos-version-min on
|
|
|
|
// non-Darwin.
|
2010-01-27 08:56:49 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ,
|
|
|
|
options::OPT_miphoneos_version_min_EQ))
|
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
2010-01-26 09:44:04 +08:00
|
|
|
} else {
|
2010-01-27 08:56:49 +08:00
|
|
|
const toolchains::Darwin &DarwinTC(
|
|
|
|
reinterpret_cast<const toolchains::Darwin&>(TC));
|
2010-03-20 08:50:21 +08:00
|
|
|
|
|
|
|
// If the target isn't initialized (e.g., an unknown Darwin platform, return
|
|
|
|
// the default triple).
|
|
|
|
if (!DarwinTC.isTargetInitialized())
|
|
|
|
return Triple.getTriple();
|
|
|
|
|
2010-01-27 08:56:49 +08:00
|
|
|
unsigned Version[3];
|
|
|
|
DarwinTC.getTargetVersion(Version);
|
2010-01-26 09:44:04 +08:00
|
|
|
|
|
|
|
// Mangle the target version into the OS triple component. For historical
|
|
|
|
// reasons that make little sense, the version passed here is the "darwin"
|
|
|
|
// version, which drops the 10 and offsets by 4. See inverse code when
|
|
|
|
// setting the OS version preprocessor define.
|
2010-01-27 08:56:49 +08:00
|
|
|
if (!DarwinTC.isTargetIPhoneOS()) {
|
|
|
|
Version[0] = Version[1] + 4;
|
|
|
|
Version[1] = Version[2];
|
|
|
|
Version[2] = 0;
|
|
|
|
} else {
|
|
|
|
// Use the environment to communicate that we are targetting iPhoneOS.
|
|
|
|
Triple.setEnvironmentName("iphoneos");
|
2010-01-26 09:44:04 +08:00
|
|
|
}
|
2009-10-31 02:12:20 +08:00
|
|
|
|
|
|
|
llvm::SmallString<16> Str;
|
2010-01-27 08:56:49 +08:00
|
|
|
llvm::raw_svector_ostream(Str) << "darwin" << Version[0]
|
|
|
|
<< "." << Version[1] << "." << Version[2];
|
2009-10-31 02:12:20 +08:00
|
|
|
Triple.setOSName(Str.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
|
|
|
|
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");
|
2009-10-31 02:12:20 +08:00
|
|
|
std::string TripleStr = getEffectiveClangTriple(D, getToolChain(), Args);
|
|
|
|
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.
|
2010-07-20 03:44:22 +08:00
|
|
|
bool IsRewriter = false;
|
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");
|
|
|
|
} else if (isa<PreprocessJobAction>(JA)) {
|
2009-03-30 14:36:42 +08:00
|
|
|
if (Output.getType() == types::TY_Dependencies)
|
|
|
|
CmdArgs.push_back("-Eonly");
|
|
|
|
else
|
|
|
|
CmdArgs.push_back("-E");
|
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
|
|
|
|
|
|
|
// At -O0, we use -mrelax-all by default.
|
|
|
|
bool IsOpt = false;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
IsOpt = !A->getOption().matches(options::OPT_O0);
|
|
|
|
if (Args.hasFlag(options::OPT_mrelax_all,
|
|
|
|
options::OPT_mno_relax_all,
|
|
|
|
!IsOpt))
|
|
|
|
CmdArgs.push_back("-mrelax-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;
|
|
|
|
|
|
|
|
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");
|
2010-02-11 11:16:21 +08:00
|
|
|
} else if (JA.getType() == types::TY_RewrittenObjC) {
|
|
|
|
CmdArgs.push_back("-rewrite-objc");
|
2010-07-20 03:44:22 +08:00
|
|
|
IsRewriter = true;
|
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");
|
|
|
|
CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs));
|
|
|
|
|
2009-04-09 02:03:55 +08:00
|
|
|
// Some flags which affect the language (via preprocessor
|
|
|
|
// defines). See darwin::CC1::AddCPPArgs.
|
|
|
|
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");
|
|
|
|
|
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)) {
|
2010-02-05 09:52:40 +08:00
|
|
|
CmdArgs.push_back("-analyzer-check-dead-stores");
|
2010-04-30 06:50:22 +08:00
|
|
|
// Do not enable the security-syntatic check since it
|
|
|
|
// it needs to be refined (known issues).
|
|
|
|
// CmdArgs.push_back("-analyzer-check-security-syntactic");
|
2010-02-05 10:06:54 +08:00
|
|
|
CmdArgs.push_back("-analyzer-check-objc-mem");
|
2009-05-22 08:38:15 +08:00
|
|
|
CmdArgs.push_back("-analyzer-eagerly-assume");
|
2010-02-05 09:57:44 +08:00
|
|
|
CmdArgs.push_back("-analyzer-check-objc-methodsigs");
|
2009-05-22 08:38:15 +08:00
|
|
|
// Do not enable the missing -dealloc check.
|
2010-02-05 09:59:21 +08:00
|
|
|
// '-analyzer-check-objc-missing-dealloc',
|
2010-02-05 09:55:01 +08:00
|
|
|
CmdArgs.push_back("-analyzer-check-objc-unused-ivars");
|
2010-08-11 02:03:13 +08:00
|
|
|
CmdArgs.push_back("-analyzer-check-idempotent-operations");
|
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))
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
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);
|
|
|
|
|
2009-04-30 02:32:25 +08:00
|
|
|
// Perform argument translation for LLVM backend. This
|
|
|
|
// takes some care in reconciling with llvm-gcc. The
|
|
|
|
// issue is that llvm-gcc translates these options based on
|
|
|
|
// the values in cc1, whereas we are processing based on
|
|
|
|
// the driver arguments.
|
2009-04-08 11:03:23 +08:00
|
|
|
|
2009-04-30 02:32:25 +08:00
|
|
|
// This comes from the default translation the driver + cc1
|
|
|
|
// would do to enable flag_pic.
|
|
|
|
//
|
|
|
|
// FIXME: Centralize this code.
|
|
|
|
bool PICEnabled = (Args.hasArg(options::OPT_fPIC) ||
|
|
|
|
Args.hasArg(options::OPT_fpic) ||
|
|
|
|
Args.hasArg(options::OPT_fPIE) ||
|
|
|
|
Args.hasArg(options::OPT_fpie));
|
|
|
|
bool PICDisabled = (Args.hasArg(options::OPT_mkernel) ||
|
|
|
|
Args.hasArg(options::OPT_static));
|
|
|
|
const char *Model = getToolChain().GetForcedPicModel();
|
|
|
|
if (!Model) {
|
|
|
|
if (Args.hasArg(options::OPT_mdynamic_no_pic))
|
|
|
|
Model = "dynamic-no-pic";
|
|
|
|
else if (PICDisabled)
|
|
|
|
Model = "static";
|
|
|
|
else if (PICEnabled)
|
|
|
|
Model = "pic";
|
2009-03-18 18:01:51 +08:00
|
|
|
else
|
2009-04-30 02:32:25 +08:00
|
|
|
Model = getToolChain().GetDefaultRelocationModel();
|
|
|
|
}
|
2009-11-29 15:18:39 +08:00
|
|
|
if (llvm::StringRef(Model) != "pic") {
|
|
|
|
CmdArgs.push_back("-mrelocation-model");
|
|
|
|
CmdArgs.push_back(Model);
|
|
|
|
}
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2009-04-30 02:32:25 +08:00
|
|
|
// Infer the __PIC__ value.
|
|
|
|
//
|
|
|
|
// FIXME: This isn't quite right on Darwin, which always sets
|
|
|
|
// __PIC__=2.
|
|
|
|
if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) {
|
2009-11-29 10:39:08 +08:00
|
|
|
CmdArgs.push_back("-pic-level");
|
|
|
|
CmdArgs.push_back(Args.hasArg(options::OPT_fPIC) ? "2" : "1");
|
2009-04-30 02:32:25 +08:00
|
|
|
}
|
2009-11-29 15:18:39 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fmerge_all_constants,
|
|
|
|
options::OPT_fno_merge_all_constants))
|
|
|
|
CmdArgs.push_back("-no-merge-all-constants");
|
|
|
|
|
|
|
|
// LLVM Code Generator Options.
|
2009-03-18 18:01:51 +08:00
|
|
|
|
2009-04-30 02:32:25 +08:00
|
|
|
// FIXME: Set --enable-unsafe-fp-math.
|
2009-08-06 03:47:38 +08:00
|
|
|
if (Args.hasFlag(options::OPT_fno_omit_frame_pointer,
|
|
|
|
options::OPT_fomit_frame_pointer))
|
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");
|
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,
|
|
|
|
IsVerboseAsmDefault) ||
|
|
|
|
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>.
|
|
|
|
if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin)
|
|
|
|
CmdArgs.push_back("-mconstructor-aliases");
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
|
|
|
|
CmdArgs.push_back("-mlimit-float-precision");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
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");
|
2009-08-05 22:30:52 +08:00
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
AddARMTargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
|
|
|
|
2010-03-02 10:41:08 +08:00
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
|
|
|
AddMIPSTargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
|
|
|
|
2009-09-10 06:33:08 +08:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
AddX86TargetArgs(Args, CmdArgs);
|
|
|
|
break;
|
2009-04-30 02:32:25 +08:00
|
|
|
}
|
2009-04-09 07:54:23 +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");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
2010-07-01 09:31:45 +08:00
|
|
|
// -mno-omit-leaf-frame-pointer is default.
|
|
|
|
if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
|
|
|
|
options::OPT_mno_omit_leaf_frame_pointer, false))
|
|
|
|
CmdArgs.push_back("-momit-leaf-frame-pointer");
|
|
|
|
|
2010-01-08 10:20:44 +08:00
|
|
|
// -fno-math-errno is default.
|
|
|
|
if (Args.hasFlag(options::OPT_fmath_errno,
|
2009-04-30 02:32:25 +08:00
|
|
|
options::OPT_fno_math_errno,
|
2010-01-08 10:20:44 +08:00
|
|
|
false))
|
|
|
|
CmdArgs.push_back("-fmath-errno");
|
2009-03-18 18:01:51 +08:00
|
|
|
|
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();
|
2009-04-30 02:32:25 +08:00
|
|
|
Arg *Unsupported;
|
|
|
|
if ((Unsupported = Args.getLastArg(options::OPT_MG)) ||
|
2009-12-12 08:38:18 +08:00
|
|
|
(Unsupported = Args.getLastArg(options::OPT_iframework)) ||
|
|
|
|
(Unsupported = Args.getLastArg(options::OPT_fshort_enums)))
|
2009-05-23 03:02:20 +08:00
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported)
|
2009-04-30 02:32:25 +08:00
|
|
|
<< Unsupported->getOption().getName();
|
|
|
|
|
2010-05-13 02:19:58 +08:00
|
|
|
if (types::isCXX(InputType) &&
|
|
|
|
getToolChain().getTriple().getOS() == llvm::Triple::Darwin &&
|
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::x86) {
|
|
|
|
if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)))
|
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
|
|
|
|
<< Unsupported->getOption().getName();
|
|
|
|
}
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_v);
|
|
|
|
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
|
|
|
|
|
|
|
// Special case debug options to only pass -g to clang. This is
|
|
|
|
// wrong.
|
2010-03-07 12:46:18 +08:00
|
|
|
Args.ClaimAllArgs(options::OPT_g_Group);
|
2010-05-13 02:19:55 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_g_Group))
|
|
|
|
if (!A->getOption().matches(options::OPT_g0))
|
|
|
|
CmdArgs.push_back("-g");
|
2009-03-18 18:01:51 +08:00
|
|
|
|
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);
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
|
2010-03-25 04:13:48 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
|
2009-10-26 21:36:57 +08:00
|
|
|
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
|
|
|
|
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)
|
2009-04-18 08:34:01 +08:00
|
|
|
AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs);
|
2009-03-18 18:01:51 +08:00
|
|
|
|
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) &&
|
|
|
|
A->getValue(Args)[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
|
|
|
}
|
|
|
|
|
2009-10-29 10:24:45 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_W_Group);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_pedantic);
|
|
|
|
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))
|
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
|
|
|
|
"-std=", /*Joined=*/true);
|
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
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2009-03-18 18:01:51 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
|
|
|
|
CmdArgs.push_back("-ftemplate-depth");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2009-11-19 12:00:53 +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");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
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");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
2010-04-08 04:49:23 +08:00
|
|
|
CmdArgs.push_back("-ferror-limit");
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
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");
|
2010-05-05 01:13:42 +08:00
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
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");
|
2010-04-20 15:18:24 +08:00
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
2010-05-06 12:55:18 +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)) {
|
2009-11-30 16:40:54 +08:00
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
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();
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(llvm::Twine(N)));
|
|
|
|
}
|
|
|
|
|
2009-12-04 02:42:11 +08:00
|
|
|
if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ)) {
|
|
|
|
CmdArgs.push_back("-fvisibility");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
2010-06-16 01:05:35 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden);
|
|
|
|
|
2010-03-20 12:52:14 +08:00
|
|
|
// -fhosted is default.
|
|
|
|
if (KernelOrKext || Args.hasFlag(options::OPT_ffreestanding,
|
|
|
|
options::OPT_fhosted,
|
|
|
|
false))
|
|
|
|
CmdArgs.push_back("-ffreestanding");
|
|
|
|
|
2009-12-04 02:42:11 +08:00
|
|
|
// Forward -f (flag) options which we can pass directly.
|
2009-12-12 09:27:46 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fcatch_undefined_behavior);
|
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-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");
|
|
|
|
|
2010-04-11 00:20:23 +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 (getToolChain().SupportsObjCGC()) {
|
|
|
|
GCArg->render(Args, CmdArgs);
|
|
|
|
} else {
|
|
|
|
// FIXME: We should move this to a hard error.
|
|
|
|
D.Diag(clang::diag::warn_drv_objc_gc_unsupported)
|
|
|
|
<< GCArg->getAsString(Args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 05:51:40 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fno_show_column);
|
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);
|
2009-04-08 05:51:40 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
|
2010-06-27 05:25:03 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_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);
|
|
|
|
|
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;
|
|
|
|
} else
|
|
|
|
StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel();
|
|
|
|
if (StackProtectorLevel) {
|
|
|
|
CmdArgs.push_back("-stack-protector");
|
|
|
|
CmdArgs.push_back(Args.MakeArgString(llvm::Twine(StackProtectorLevel)));
|
2009-06-28 15:36:13 +08:00
|
|
|
}
|
|
|
|
|
2009-04-08 05:16:11 +08:00
|
|
|
// Forward -f options with positive and negative forms; we translate
|
|
|
|
// these by hand.
|
|
|
|
|
2009-11-17 16:07:36 +08:00
|
|
|
// -fbuiltin is default.
|
2009-04-08 05:16:11 +08:00
|
|
|
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,
|
2009-11-18 03:33:30 +08:00
|
|
|
getToolChain().IsBlocksDefault())) {
|
2009-11-17 16:07:36 +08:00
|
|
|
CmdArgs.push_back("-fblocks");
|
2009-11-18 03:33:30 +08:00
|
|
|
}
|
2009-04-08 05:16:11 +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
|
|
|
|
2009-11-25 18:14:30 +08:00
|
|
|
// -fexceptions=0 is default.
|
2009-10-02 04:30:46 +08:00
|
|
|
if (needsExceptions(Args, InputType, getToolChain().getTriple()))
|
2009-10-01 21:33:33 +08:00
|
|
|
CmdArgs.push_back("-fexceptions");
|
2009-08-01 07:15:31 +08:00
|
|
|
|
2010-02-11 02:49:11 +08:00
|
|
|
if (getToolChain().UseSjLjExceptions())
|
|
|
|
CmdArgs.push_back("-fsjlj-exceptions");
|
|
|
|
|
2009-11-17 15:06:20 +08:00
|
|
|
// -frtti is default.
|
2010-03-20 12:52:14 +08:00
|
|
|
if (KernelOrKext ||
|
|
|
|
!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
|
2009-11-19 12:55:23 +08:00
|
|
|
CmdArgs.push_back("-fno-rtti");
|
2009-08-01 07:15:31 +08:00
|
|
|
|
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.
|
|
|
|
if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
|
|
|
|
options::OPT_fno_threadsafe_statics))
|
|
|
|
CmdArgs.push_back("-fno-threadsafe-statics");
|
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
// -fuse-cxa-atexit is default.
|
2010-03-20 12:52:14 +08:00
|
|
|
if (KernelOrKext || !Args.hasFlag(options::OPT_fuse_cxa_atexit,
|
|
|
|
options::OPT_fno_use_cxa_atexit))
|
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");
|
|
|
|
|
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
|
|
|
|
2010-07-20 03:44:22 +08:00
|
|
|
// -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
|
|
|
|
// -the -cc1 default.
|
|
|
|
bool NeXTRuntimeIsDefault =
|
|
|
|
IsRewriter || getToolChain().getTriple().getOS() == llvm::Triple::Darwin;
|
2009-11-25 18:14:30 +08:00
|
|
|
if (!Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
|
2010-07-20 03:44:22 +08:00
|
|
|
NeXTRuntimeIsDefault))
|
2009-11-17 15:07:28 +08:00
|
|
|
CmdArgs.push_back("-fgnu-runtime");
|
|
|
|
|
2009-11-17 16:07:36 +08:00
|
|
|
// -fobjc-nonfragile-abi=0 is default.
|
|
|
|
if (types::isObjC(InputType)) {
|
2010-04-29 07:25:24 +08:00
|
|
|
unsigned Version = 1;
|
2009-11-17 16:07:36 +08:00
|
|
|
if (Args.hasArg(options::OPT_fobjc_nonfragile_abi) ||
|
2010-04-29 07:25:24 +08:00
|
|
|
getToolChain().IsObjCNonFragileABIDefault())
|
|
|
|
Version = 2;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
|
|
|
|
if (llvm::StringRef(A->getValue(Args)) == "1")
|
|
|
|
Version = 1;
|
|
|
|
else if (llvm::StringRef(A->getValue(Args)) == "2")
|
|
|
|
Version = 2;
|
|
|
|
else
|
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Version == 2) {
|
2009-11-17 16:07:36 +08:00
|
|
|
CmdArgs.push_back("-fobjc-nonfragile-abi");
|
2010-04-25 01:56:46 +08:00
|
|
|
|
|
|
|
// -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
|
|
|
|
// legacy is the default.
|
|
|
|
if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
|
|
|
|
options::OPT_fno_objc_legacy_dispatch,
|
|
|
|
getToolChain().IsObjCLegacyDispatchDefault())) {
|
|
|
|
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
|
|
|
}
|
2010-05-20 10:12:37 +08:00
|
|
|
|
|
|
|
// FIXME: -fobjc-nonfragile-abi2 is a transient option meant to expose
|
|
|
|
// features in testing. It will eventually be removed.
|
|
|
|
if (Args.hasArg(options::OPT_fobjc_nonfragile_abi2))
|
|
|
|
CmdArgs.push_back("-fobjc-nonfragile-abi2");
|
2009-11-17 16:07:36 +08:00
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
// -fcommon is default, only pass non-default.
|
|
|
|
if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
|
|
|
|
CmdArgs.push_back("-fno-common");
|
|
|
|
|
2009-04-15 10:37:43 +08:00
|
|
|
// -fsigned-bitfields is default, and clang doesn't yet support
|
|
|
|
// --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))
|
|
|
|
D.Diag(clang::diag::warn_drv_clang_unsupported)
|
|
|
|
<< Args.getLastArg(options::OPT_funsigned_bitfields)->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");
|
|
|
|
|
2010-01-31 07:31:57 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_binary);
|
2010-01-28 14:00:51 +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");
|
|
|
|
CmdArgs.push_back(A->getValue(Args));
|
|
|
|
}
|
|
|
|
|
2009-11-04 14:24:57 +08:00
|
|
|
// Color diagnostics are the default, unless the terminal doesn't support
|
|
|
|
// them.
|
|
|
|
if (Args.hasFlag(options::OPT_fcolor_diagnostics,
|
|
|
|
options::OPT_fno_color_diagnostics) &&
|
|
|
|
llvm::sys::Process::StandardErrHasColors())
|
|
|
|
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
|
|
|
|
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-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))
|
2009-10-14 00:41:34 +08:00
|
|
|
D.Diag(clang::diag::warn_drv_clang_unsupported) << A->getAsString(Args);
|
2009-05-23 03:02:20 +08:00
|
|
|
}
|
2009-07-15 05:58:17 +08:00
|
|
|
|
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
|
2009-09-10 11:37:02 +08:00
|
|
|
if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin &&
|
|
|
|
(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
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_traditional,
|
2009-07-15 05:58:17 +08:00
|
|
|
options::OPT_traditional_cpp))
|
|
|
|
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
|
|
|
|
|
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);
|
2009-03-18 18:01:51 +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.
|
2010-06-12 06:00:13 +08:00
|
|
|
if (llvm::StringRef((*it)->getValue(Args, 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");
|
|
|
|
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);
|
|
|
|
|
2009-12-18 10:43:17 +08:00
|
|
|
llvm::SmallString<256> Flags;
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-04-08 03:18:24 +08:00
|
|
|
// Explicitly warn that these options are unsupported, even though
|
|
|
|
// we are allowing compilation to continue.
|
2009-11-25 19:53:23 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_pg),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
(*it)->claim();
|
|
|
|
D.Diag(clang::diag::warn_drv_clang_unsupported) << (*it)->getAsString(Args);
|
2009-04-08 03:18:24 +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);
|
2009-03-18 14:00:36 +08:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
const Driver &D = getToolChain().getDriver();
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unexpected number of inputs.");
|
|
|
|
const InputInfo &Input = Inputs[0];
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
std::string TripleStr = getEffectiveClangTriple(D, getToolChain(), Args);
|
|
|
|
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");
|
|
|
|
|
2010-05-27 14:18:05 +08:00
|
|
|
// At -O0, we use -mrelax-all by default.
|
|
|
|
bool IsOpt = false;
|
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_O_Group))
|
|
|
|
IsOpt = !A->getOption().matches(options::OPT_O0);
|
|
|
|
if (Args.hasFlag(options::OPT_mrelax_all,
|
|
|
|
options::OPT_mno_relax_all,
|
|
|
|
!IsOpt))
|
2010-05-29 00:43:21 +08:00
|
|
|
CmdArgs.push_back("-relax-all");
|
2010-05-27 14:18:05 +08:00
|
|
|
|
2010-05-21 05:30:13 +08:00
|
|
|
// FIXME: Add -force_cpusubtype_ALL support, once we have it.
|
|
|
|
|
|
|
|
// FIXME: Add -g support, once we have it.
|
|
|
|
|
|
|
|
// FIXME: Add -static support, once we have it.
|
|
|
|
|
|
|
|
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());
|
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));
|
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;
|
2009-03-19 15:55:12 +08:00
|
|
|
if (A->getOption().hasForwardToGCC()) {
|
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.
|
2009-05-22 10:21:04 +08:00
|
|
|
const std::string &Arch = getToolChain().getArchName();
|
2009-12-23 08:46:38 +08:00
|
|
|
if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin) {
|
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.
|
2009-05-22 10:21:04 +08:00
|
|
|
if (Arch == "powerpc")
|
|
|
|
CmdArgs.push_back("ppc");
|
|
|
|
else if (Arch == "powerpc64")
|
|
|
|
CmdArgs.push_back("ppc64");
|
|
|
|
else
|
2009-09-10 06:32:48 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(Arch));
|
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.
|
|
|
|
if (Arch == "i386" || Arch == "powerpc")
|
2009-05-03 05:41:52 +08:00
|
|
|
CmdArgs.push_back("-m32");
|
2009-05-22 10:21:04 +08:00
|
|
|
else if (Arch == "x86_64" || Arch == "powerpc64")
|
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
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
2009-05-03 04:14:53 +08:00
|
|
|
D.Diag(clang::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)
|
|
|
|
D.Diag(clang::diag::err_drv_no_ast_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< 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());
|
2009-03-18 16:07:30 +08:00
|
|
|
else
|
2009-03-19 15:29:38 +08:00
|
|
|
// Don't render as input, we need gcc to do the translations.
|
|
|
|
II.getInputArg().render(Args, CmdArgs);
|
2009-03-18 16:07:30 +08:00
|
|
|
}
|
|
|
|
|
2009-12-22 02:54:17 +08:00
|
|
|
const char *GCCName = getToolChain().getDriver().CCCGenericGCCName.c_str();
|
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)
|
|
|
|
D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
|
|
|
|
<< getTypeName(JA.getType());
|
|
|
|
|
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
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
const char *darwin::CC1::getCC1Name(types::ID Type) const {
|
|
|
|
switch (Type) {
|
|
|
|
default:
|
|
|
|
assert(0 && "Unexpected type for Darwin CC1 tool.");
|
|
|
|
case types::TY_Asm:
|
|
|
|
case types::TY_C: case types::TY_CHeader:
|
|
|
|
case types::TY_PP_C: case types::TY_PP_CHeader:
|
|
|
|
return "cc1";
|
|
|
|
case types::TY_ObjC: case types::TY_ObjCHeader:
|
|
|
|
case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader:
|
|
|
|
return "cc1obj";
|
|
|
|
case types::TY_CXX: case types::TY_CXXHeader:
|
|
|
|
case types::TY_PP_CXX: case types::TY_PP_CXXHeader:
|
|
|
|
return "cc1plus";
|
|
|
|
case types::TY_ObjCXX: case types::TY_ObjCXXHeader:
|
|
|
|
case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader:
|
|
|
|
return "cc1objplus";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *darwin::CC1::getBaseInputName(const ArgList &Args,
|
2009-03-30 08:34:04 +08:00
|
|
|
const InputInfoList &Inputs) {
|
2009-03-30 02:40:18 +08:00
|
|
|
llvm::sys::Path P(Inputs[0].getBaseInput());
|
2009-09-10 06:32:48 +08:00
|
|
|
return Args.MakeArgString(P.getLast());
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *darwin::CC1::getBaseInputStem(const ArgList &Args,
|
2009-03-30 08:34:04 +08:00
|
|
|
const InputInfoList &Inputs) {
|
2009-03-30 02:40:18 +08:00
|
|
|
const char *Str = getBaseInputName(Args, Inputs);
|
|
|
|
|
|
|
|
if (const char *End = strchr(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2009-04-09 07:54:23 +08:00
|
|
|
darwin::CC1::getDependencyFileName(const ArgList &Args,
|
2009-03-30 08:34:04 +08:00
|
|
|
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)) {
|
|
|
|
std::string Str(OutputOpt->getValue(Args));
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
Res = Str.substr(0, Str.rfind('.'));
|
|
|
|
} else
|
2009-03-30 08:34:04 +08:00
|
|
|
Res = darwin::CC1::getBaseInputStem(Args, Inputs);
|
2009-03-30 02:40:18 +08:00
|
|
|
|
2009-09-10 06:32:48 +08:00
|
|
|
return Args.MakeArgString(Res + ".d");
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
void darwin::CC1::AddCC1Args(const ArgList &Args,
|
2009-03-30 02:40:18 +08:00
|
|
|
ArgStringList &CmdArgs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-09-10 09:21:12 +08:00
|
|
|
|
|
|
|
CheckCodeGenerationOptions(D, Args);
|
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// Derived from cc1 spec.
|
|
|
|
if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) &&
|
|
|
|
!Args.hasArg(options::OPT_mdynamic_no_pic))
|
|
|
|
CmdArgs.push_back("-fPIC");
|
|
|
|
|
2009-09-10 11:37:02 +08:00
|
|
|
if (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-03-30 02:40:18 +08:00
|
|
|
// gcc has some code here to deal with when no -mmacosx-version-min
|
|
|
|
// and no -miphoneos-version-min is present, but this never happens
|
|
|
|
// due to tool chain specific argument translation.
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_g_Flag) &&
|
|
|
|
!Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols))
|
|
|
|
CmdArgs.push_back("-feliminate-unused-debug-symbols");
|
|
|
|
}
|
|
|
|
|
|
|
|
void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgStringList &OutputArgs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-03-30 02:40:18 +08:00
|
|
|
|
|
|
|
// Derived from cc1_options spec.
|
|
|
|
if (Args.hasArg(options::OPT_fast) ||
|
|
|
|
Args.hasArg(options::OPT_fastf) ||
|
|
|
|
Args.hasArg(options::OPT_fastcp))
|
|
|
|
CmdArgs.push_back("-O3");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
if (Arg *A = Args.getLastArg(options::OPT_pg))
|
|
|
|
if (Args.hasArg(options::OPT_fomit_frame_pointer))
|
|
|
|
D.Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "-fomit-frame-pointer";
|
|
|
|
|
|
|
|
AddCC1Args(Args, CmdArgs);
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_Q))
|
|
|
|
CmdArgs.push_back("-quiet");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-dumpbase");
|
2009-03-30 08:34:04 +08:00
|
|
|
CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs));
|
2009-03-30 02:40:18 +08:00
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_d_Group);
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_m_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_a_Group);
|
|
|
|
|
|
|
|
// FIXME: The goal is to use the user provided -o if that is our
|
|
|
|
// final output, otherwise to drive from the original input
|
|
|
|
// name. Find a clean way to go about this.
|
|
|
|
if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) &&
|
|
|
|
Args.hasArg(options::OPT_o)) {
|
|
|
|
Arg *OutputOpt = Args.getLastArg(options::OPT_o);
|
|
|
|
CmdArgs.push_back("-auxbase-strip");
|
|
|
|
CmdArgs.push_back(OutputOpt->getValue(Args));
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-auxbase");
|
2009-03-30 08:34:04 +08:00
|
|
|
CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs));
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_g_Group);
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_O);
|
|
|
|
// FIXME: -Wall is getting some special treatment. Investigate.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_w);
|
2009-04-09 07:54:23 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
|
2009-03-30 02:40:18 +08:00
|
|
|
options::OPT_trigraphs);
|
2009-04-26 09:10:38 +08:00
|
|
|
if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
|
|
|
|
// Honor -std-default.
|
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
|
|
|
|
"-std=", /*Joined=*/true);
|
|
|
|
}
|
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_v))
|
|
|
|
CmdArgs.push_back("-version");
|
|
|
|
if (Args.hasArg(options::OPT_pg))
|
|
|
|
CmdArgs.push_back("-p");
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_p);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// The driver treats -fsyntax-only specially.
|
2009-09-10 11:37:02 +08:00
|
|
|
if (getToolChain().getTriple().getArch() == llvm::Triple::arm ||
|
|
|
|
getToolChain().getTriple().getArch() == llvm::Triple::thumb) {
|
|
|
|
// Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
|
|
|
|
// used to inhibit the default -fno-builtin-str{cat,cpy}.
|
|
|
|
//
|
|
|
|
// FIXME: Should we grow a better way to deal with "removing" args?
|
2009-11-25 19:53:23 +08:00
|
|
|
for (arg_iterator it = Args.filtered_begin(options::OPT_f_Group,
|
|
|
|
options::OPT_fsyntax_only),
|
|
|
|
ie = Args.filtered_end(); it != ie; ++it) {
|
2010-06-12 06:00:13 +08:00
|
|
|
if (!(*it)->getOption().matches(options::OPT_fbuiltin_strcat) &&
|
|
|
|
!(*it)->getOption().matches(options::OPT_fbuiltin_strcpy)) {
|
|
|
|
(*it)->claim();
|
|
|
|
(*it)->render(Args, CmdArgs);
|
2009-09-10 11:37:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_undef);
|
|
|
|
if (Args.hasArg(options::OPT_Qn))
|
|
|
|
CmdArgs.push_back("-fno-ident");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// FIXME: This isn't correct.
|
|
|
|
//Args.AddLastArg(CmdArgs, options::OPT__help)
|
|
|
|
//Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
|
|
|
|
|
|
|
|
CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
|
|
|
|
|
|
|
|
// FIXME: Still don't get what is happening here. Investigate.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT__param);
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fmudflap) ||
|
|
|
|
Args.hasArg(options::OPT_fmudflapth)) {
|
|
|
|
CmdArgs.push_back("-fno-builtin");
|
|
|
|
CmdArgs.push_back("-fno-merge-constants");
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
if (Args.hasArg(options::OPT_coverage)) {
|
|
|
|
CmdArgs.push_back("-fprofile-arcs");
|
|
|
|
CmdArgs.push_back("-ftest-coverage");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types::isCXX(Inputs[0].getType()))
|
|
|
|
CmdArgs.push_back("-D__private_extern__=extern");
|
|
|
|
}
|
|
|
|
|
|
|
|
void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgStringList &OutputArgs) const {
|
|
|
|
// Derived from cpp_options
|
|
|
|
AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
|
|
|
|
|
|
|
|
AddCC1Args(Args, CmdArgs);
|
|
|
|
|
|
|
|
// NOTE: The code below has some commonality with cpp_options, but
|
|
|
|
// in classic gcc style ends up sending things in different
|
|
|
|
// orders. This may be a good merge candidate once we drop pedantic
|
|
|
|
// compatibility.
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_m_Group);
|
2009-04-09 07:54:23 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
|
2009-03-30 02:40:18 +08:00
|
|
|
options::OPT_trigraphs);
|
2009-04-26 09:10:38 +08:00
|
|
|
if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
|
|
|
|
// Honor -std-default.
|
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
|
|
|
|
"-std=", /*Joined=*/true);
|
|
|
|
}
|
2009-03-30 02:40:18 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_w);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// The driver treats -fsyntax-only specially.
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only);
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) &&
|
|
|
|
!Args.hasArg(options::OPT_fno_working_directory))
|
|
|
|
CmdArgs.push_back("-fworking-directory");
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_O);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_undef);
|
|
|
|
if (Args.hasArg(options::OPT_save_temps))
|
|
|
|
CmdArgs.push_back("-fpch-preprocess");
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args,
|
2009-03-30 02:40:18 +08:00
|
|
|
ArgStringList &CmdArgs,
|
2009-09-09 23:08:12 +08:00
|
|
|
const InputInfoList &Inputs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-03-30 02:40:18 +08:00
|
|
|
|
2009-09-10 09:21:05 +08:00
|
|
|
CheckPreprocessingOptions(D, Args);
|
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// Derived from cpp_unique_options.
|
2009-09-10 09:21:05 +08:00
|
|
|
// -{C,CC} only with -E is checked in CheckPreprocessingOptions().
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_C);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_CC);
|
2009-03-30 02:40:18 +08:00
|
|
|
if (!Args.hasArg(options::OPT_Q))
|
|
|
|
CmdArgs.push_back("-quiet");
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_nostdinc);
|
2010-03-25 04:13:48 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_nostdincxx);
|
2009-03-30 02:40:18 +08:00
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_v);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_P);
|
|
|
|
|
|
|
|
// FIXME: Handle %I properly.
|
|
|
|
if (getToolChain().getArchName() == "x86_64") {
|
|
|
|
CmdArgs.push_back("-imultilib");
|
|
|
|
CmdArgs.push_back("x86_64");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_MD)) {
|
|
|
|
CmdArgs.push_back("-MD");
|
2009-03-30 08:34:04 +08:00
|
|
|
CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs));
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_MMD)) {
|
|
|
|
CmdArgs.push_back("-MMD");
|
2009-03-30 08:34:04 +08:00
|
|
|
CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs));
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_M);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_MM);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_MF);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_MG);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_MP);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_MQ);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_MT);
|
|
|
|
if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) &&
|
|
|
|
(Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) {
|
|
|
|
if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
|
|
|
|
CmdArgs.push_back("-MQ");
|
|
|
|
CmdArgs.push_back(OutputOpt->getValue(Args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_remap);
|
|
|
|
if (Args.hasArg(options::OPT_g3))
|
|
|
|
CmdArgs.push_back("-dD");
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_H);
|
|
|
|
|
|
|
|
AddCPPArgs(Args, CmdArgs);
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_i_Group);
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-03-30 02:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
|
|
|
|
options::OPT_Xpreprocessor);
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fmudflap)) {
|
|
|
|
CmdArgs.push_back("-D_MUDFLAP");
|
|
|
|
CmdArgs.push_back("-include");
|
|
|
|
CmdArgs.push_back("mf-runtime.h");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fmudflapth)) {
|
|
|
|
CmdArgs.push_back("-D_MUDFLAP");
|
|
|
|
CmdArgs.push_back("-D_MUDFLAPTH");
|
|
|
|
CmdArgs.push_back("-include");
|
|
|
|
CmdArgs.push_back("mf-runtime.h");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
void darwin::CC1::AddCPPArgs(const ArgList &Args,
|
2009-03-30 02:40:18 +08:00
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
// Derived from cpp spec.
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
// The gcc spec is broken here, it refers to dynamic but
|
|
|
|
// that has been translated. Start by being bug compatible.
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 02:40:18 +08:00
|
|
|
// if (!Args.hasArg(arglist.parser.dynamicOption))
|
|
|
|
CmdArgs.push_back("-D__STATIC__");
|
|
|
|
} else
|
|
|
|
CmdArgs.push_back("-D__DYNAMIC__");
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-D_REENTRANT");
|
|
|
|
}
|
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
void darwin::Preprocess::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-30 01:08:39 +08:00
|
|
|
const char *LinkingOutput) const {
|
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unexpected number of inputs!");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-E");
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_traditional) ||
|
|
|
|
Args.hasArg(options::OPT_traditional_cpp))
|
|
|
|
CmdArgs.push_back("-traditional-cpp");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
ArgStringList OutputArgs;
|
2010-08-02 10:38:21 +08:00
|
|
|
assert(Output.isFilename() && "Unexpected CC1 output.");
|
|
|
|
OutputArgs.push_back("-o");
|
|
|
|
OutputArgs.push_back(Output.getFilename());
|
2009-03-30 01:08:39 +08:00
|
|
|
|
2009-03-30 06:27:40 +08:00
|
|
|
if (Args.hasArg(options::OPT_E)) {
|
|
|
|
AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
|
|
|
|
} else {
|
|
|
|
AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
|
|
|
|
CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-04-03 09:27:06 +08:00
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_d_Group);
|
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
const char *CC1Name = getCC1Name(Inputs[0].getType());
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath(CC1Name));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-30 01:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void darwin::Compile::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-30 01:08:39 +08:00
|
|
|
const char *LinkingOutput) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-03-30 01:08:39 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
assert(Inputs.size() == 1 && "Unexpected number of inputs!");
|
|
|
|
|
|
|
|
types::ID InputType = Inputs[0].getType();
|
|
|
|
const Arg *A;
|
2009-07-15 05:58:17 +08:00
|
|
|
if ((A = Args.getLastArg(options::OPT_traditional)))
|
2009-03-30 01:08:39 +08:00
|
|
|
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
|
|
|
|
<< A->getAsString(Args) << "-E";
|
|
|
|
|
2010-06-08 07:28:45 +08:00
|
|
|
if (JA.getType() == types::TY_LLVM_IR ||
|
|
|
|
JA.getType() == types::TY_LTO_IR)
|
2009-03-30 01:08:39 +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-30 01:08:39 +08:00
|
|
|
CmdArgs.push_back("-emit-llvm-bc");
|
2009-09-02 00:57:46 +08:00
|
|
|
else if (Output.getType() == types::TY_AST)
|
|
|
|
D.Diag(clang::diag::err_drv_no_ast_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2010-02-12 01:33:45 +08:00
|
|
|
else if (JA.getType() != types::TY_PP_Asm &&
|
|
|
|
JA.getType() != types::TY_PCH)
|
2010-02-11 11:16:21 +08:00
|
|
|
D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
|
|
|
|
<< getTypeName(JA.getType());
|
2009-03-30 01:08:39 +08:00
|
|
|
|
|
|
|
ArgStringList OutputArgs;
|
|
|
|
if (Output.getType() != types::TY_PCH) {
|
|
|
|
OutputArgs.push_back("-o");
|
2010-08-02 10:38:21 +08:00
|
|
|
if (Output.isNothing())
|
2009-03-30 01:08:39 +08:00
|
|
|
OutputArgs.push_back("/dev/null");
|
|
|
|
else
|
|
|
|
OutputArgs.push_back(Output.getFilename());
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no need for this level of compatibility, but it makes
|
|
|
|
// diffing easier.
|
|
|
|
bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) ||
|
|
|
|
Args.hasArg(options::OPT_S));
|
|
|
|
|
|
|
|
if (types::getPreprocessedType(InputType) != types::TY_INVALID) {
|
2009-03-30 02:40:18 +08:00
|
|
|
AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs);
|
2009-03-30 01:08:39 +08:00
|
|
|
if (OutputArgsEarly) {
|
|
|
|
AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
|
|
|
|
} else {
|
|
|
|
AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
|
|
|
|
CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-fpreprocessed");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
2009-09-02 00:57:46 +08:00
|
|
|
// Reject AST inputs.
|
|
|
|
if (II.getType() == types::TY_AST) {
|
|
|
|
D.Diag(clang::diag::err_drv_no_ast_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-09-02 00:57:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-03-30 01:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OutputArgsEarly) {
|
|
|
|
AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
|
|
|
|
} else {
|
|
|
|
AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
|
|
|
|
CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
|
|
|
|
}
|
|
|
|
}
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-30 01:08:39 +08:00
|
|
|
if (Output.getType() == types::TY_PCH) {
|
|
|
|
assert(Output.isFilename() && "Invalid PCH output.");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
// NOTE: gcc uses a temp .s file for this, but there doesn't seem
|
|
|
|
// to be a good reason.
|
|
|
|
CmdArgs.push_back("/dev/null");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-11-21 10:31:29 +08:00
|
|
|
CmdArgs.push_back("--output-pch=");
|
2009-03-30 01:08:39 +08:00
|
|
|
CmdArgs.push_back(Output.getFilename());
|
2009-04-09 07:54:23 +08:00
|
|
|
}
|
2009-03-30 01:08:39 +08:00
|
|
|
|
|
|
|
const char *CC1Name = getCC1Name(Inputs[0].getType());
|
2009-04-09 07:54:23 +08:00
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath(CC1Name));
|
2010-08-02 10:38:28 +08:00
|
|
|
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
|
2009-03-30 01:08:39 +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];
|
|
|
|
|
|
|
|
// Bit of a hack, this is only used for original inputs.
|
2009-04-09 07:54:23 +08:00
|
|
|
//
|
2009-04-01 08:27:44 +08:00
|
|
|
// FIXME: This is broken for preprocessed .s inputs.
|
2009-03-21 00:06:39 +08:00
|
|
|
if (Input.isFilename() &&
|
2009-04-01 08:27:44 +08:00
|
|
|
strcmp(Input.getFilename(), Input.getBaseInput()) == 0) {
|
|
|
|
if (Args.hasArg(options::OPT_gstabs))
|
|
|
|
CmdArgs.push_back("--gstabs");
|
|
|
|
else if (Args.hasArg(options::OPT_g_Group))
|
|
|
|
CmdArgs.push_back("--gdwarf2");
|
|
|
|
}
|
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 &&
|
|
|
|
(Args.hasArg(options::OPT_mkernel) ||
|
2009-03-21 00:06:39 +08:00
|
|
|
Args.hasArg(options::OPT_static) ||
|
2009-08-25 06:26:16 +08:00
|
|
|
Args.hasArg(options::OPT_fapple_kext)))
|
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
|
|
|
|
2009-09-10 02:36:20 +08:00
|
|
|
void darwin::DarwinTool::AddDarwinArch(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
2010-01-22 10:04:58 +08:00
|
|
|
llvm::StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-04-09 07:54:23 +08:00
|
|
|
void darwin::Link::AddLinkArgs(const ArgList &Args,
|
2009-03-27 00:23:12 +08:00
|
|
|
ArgStringList &CmdArgs) const {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
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;
|
|
|
|
if (!Driver::GetReleaseVersion(A->getValue(Args), Version[0],
|
|
|
|
Version[1], Version[2], HadExtra) ||
|
|
|
|
HadExtra)
|
|
|
|
D.Diag(clang::diag::err_drv_invalid_version_number)
|
|
|
|
<< A->getAsString(Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Newer linkers support -demangle, pass it if supported and not disabled by
|
|
|
|
// the user.
|
|
|
|
if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) {
|
|
|
|
CmdArgs.push_back("-demangle");
|
|
|
|
}
|
|
|
|
|
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)))
|
|
|
|
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
|
|
|
|
<< 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)))
|
|
|
|
D.Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< 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);
|
2010-01-27 08:56:37 +08:00
|
|
|
if (getDarwinToolChain().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);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_image__base);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_init);
|
|
|
|
|
2010-01-26 11:56:40 +08:00
|
|
|
// Adding all arguments doesn't make sense here but this is what gcc does. One
|
|
|
|
// of this should always be present thanks to argument translation.
|
|
|
|
assert((Args.hasArg(options::OPT_mmacosx_version_min_EQ) ||
|
|
|
|
Args.hasArg(options::OPT_miphoneos_version_min_EQ)) &&
|
|
|
|
"Missing version argument (lost in translation)?");
|
2009-09-05 02:35:21 +08:00
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ,
|
2009-11-04 14:24:38 +08:00
|
|
|
"-macosx_version_min");
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ,
|
|
|
|
"-iphoneos_version_min");
|
|
|
|
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
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot");
|
2010-01-27 08:56:37 +08:00
|
|
|
if (getDarwinToolChain().isTargetIPhoneOS()) {
|
2009-09-05 02:35:41 +08:00
|
|
|
if (!Args.hasArg(options::OPT_isysroot)) {
|
|
|
|
CmdArgs.push_back("-syslibroot");
|
|
|
|
CmdArgs.push_back("/Developer/SDKs/Extra");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// I'm not sure why this particular decomposition exists in gcc, but
|
|
|
|
// we follow suite for ease of comparison.
|
|
|
|
AddLinkArgs(Args, CmdArgs);
|
|
|
|
|
|
|
|
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.AddAllArgs(CmdArgs, options::OPT_A);
|
|
|
|
Args.AddLastArg(CmdArgs, options::OPT_e);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_m_Separate);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_r);
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.getFilename());
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_A) &&
|
|
|
|
!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!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.
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isTargetIPhoneOS()) {
|
|
|
|
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.
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isTargetIPhoneOS()) {
|
|
|
|
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 {
|
|
|
|
if (Args.hasArg(options::OPT_pg)) {
|
|
|
|
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
|
|
|
}
|
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.
|
2010-01-27 08:56:37 +08:00
|
|
|
if (getDarwinToolChain().isTargetIPhoneOS()) {
|
2010-01-27 08:56:56 +08:00
|
|
|
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
|
|
|
|
CmdArgs.push_back("-lcrt1.o");
|
|
|
|
else
|
|
|
|
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");
|
|
|
|
else
|
|
|
|
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
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
if (Args.hasArg(options::OPT_fopenmp))
|
|
|
|
// This is more complicated in gcc...
|
|
|
|
CmdArgs.push_back("-lgomp");
|
|
|
|
|
2009-09-18 16:14:36 +08:00
|
|
|
getDarwinToolChain().AddLinkSearchPathArgs(Args, CmdArgs);
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
if (II.isFilename())
|
|
|
|
CmdArgs.push_back(II.getFilename());
|
2009-04-09 07:54:23 +08:00
|
|
|
else
|
2009-03-27 00:23:12 +08:00
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LinkingOutput) {
|
|
|
|
CmdArgs.push_back("-arch_multiple");
|
|
|
|
CmdArgs.push_back("-final_output");
|
|
|
|
CmdArgs.push_back(LinkingOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_fprofile_arcs) ||
|
|
|
|
Args.hasArg(options::OPT_fprofile_generate) ||
|
|
|
|
Args.hasArg(options::OPT_fcreate_profile) ||
|
|
|
|
Args.hasArg(options::OPT_coverage))
|
|
|
|
CmdArgs.push_back("-lgcov");
|
2009-04-09 07:54:23 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
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-04-08 14:06:21 +08:00
|
|
|
// FIXME: g++ is more complicated here, it tries to put -lstdc++
|
|
|
|
// before -lm, for example.
|
2009-12-22 02:54:17 +08:00
|
|
|
if (getToolChain().getDriver().CCCIsCXX)
|
2009-04-08 14:06:21 +08:00
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_A) &&
|
|
|
|
!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!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;
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
CmdArgs.push_back("-o");
|
|
|
|
CmdArgs.push_back(Output.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
|
|
|
}
|
|
|
|
|
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-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
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);
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
|
|
|
// Don't try to pass LLVM 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)
|
2009-08-22 09:06:46 +08:00
|
|
|
D.Diag(clang::diag::err_drv_no_linker_llvm_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-08-22 09:06:46 +08:00
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-08-22 09:06:46 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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 {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(
|
2010-07-15 02:46:23 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
|
|
|
// Don't try to pass LLVM 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)
|
2009-06-30 04:52:51 +08:00
|
|
|
D.Diag(clang::diag::err_drv_no_linker_llvm_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-06-30 04:52:51 +08:00
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-06-30 04:52:51 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2010-08-02 07:13:54 +08:00
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-pthread");
|
2009-08-03 09:28:59 +08:00
|
|
|
if (!Args.hasArg(options::OPT_shared))
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
if (getToolChain().getArchName() == "i386")
|
2009-04-01 01:45:15 +08:00
|
|
|
CmdArgs.push_back("--32");
|
|
|
|
|
2010-03-02 10:41:08 +08:00
|
|
|
|
|
|
|
// Set byte order explicitly
|
|
|
|
if (getToolChain().getArchName() == "mips")
|
|
|
|
CmdArgs.push_back("-EB");
|
|
|
|
else if (getToolChain().getArchName() == "mipsel")
|
|
|
|
CmdArgs.push_back("-EL");
|
|
|
|
|
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 {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-04-02 03:36:32 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When building 32-bit code on FreeBSD/amd64, we have to explicitly
|
|
|
|
// instruct ld in the base system to link 32-bit code.
|
|
|
|
if (getToolChain().getArchName() == "i386") {
|
|
|
|
CmdArgs.push_back("-m");
|
|
|
|
CmdArgs.push_back("elf_i386_fbsd");
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
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-04-02 03:36:32 +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")));
|
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-04-02 03:36:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
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
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
2009-04-09 07:54:23 +08:00
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
2009-04-02 03:36:32 +08:00
|
|
|
const InputInfo &II = *it;
|
2009-05-03 04:14:53 +08:00
|
|
|
|
|
|
|
// Don't try to pass LLVM 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)
|
2009-05-03 04:14:53 +08:00
|
|
|
D.Diag(clang::diag::err_drv_no_linker_llvm_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-05-03 04:14:53 +08:00
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-04-02 03:36:32 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
2010-02-17 16:07:51 +08:00
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
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.
|
|
|
|
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_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
|
|
|
}
|
|
|
|
|
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-04-02 03:36:32 +08:00
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
|
2010-08-10 08:25:48 +08:00
|
|
|
void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
|
|
|
|
const InputInfo &Output,
|
|
|
|
const InputInfoList &Inputs,
|
|
|
|
const ArgList &Args,
|
|
|
|
const char *LinkingOutput) const {
|
|
|
|
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");
|
|
|
|
} else if (getToolChain().getArch() == llvm::Triple::arm) {
|
|
|
|
llvm::StringRef MArch = getToolChain().getArchName();
|
|
|
|
if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a")
|
|
|
|
CmdArgs.push_back("-mfpu=neon");
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 =
|
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));
|
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) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles))
|
2010-07-15 02:46:23 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
2010-07-08 00:01:42 +08:00
|
|
|
"/usr/gnu/lib/crtso.o")));
|
|
|
|
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
|
|
Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
|
|
|
|
|
|
for (InputInfoList::const_iterator
|
|
|
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
|
|
|
const InputInfo &II = *it;
|
|
|
|
|
|
|
|
// Don't try to pass LLVM 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();
|
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_pthread))
|
|
|
|
CmdArgs.push_back("-lpthread");
|
|
|
|
CmdArgs.push_back("-lc");
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
CmdArgs.push_back("-L/usr/gnu/lib");
|
|
|
|
// FIXME: fill in the correct search path for the final
|
|
|
|
// support libraries.
|
|
|
|
CmdArgs.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nostartfiles)) {
|
2010-07-15 02:46:23 +08:00
|
|
|
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
|
2010-07-08 00:01:42 +08:00
|
|
|
"/usr/gnu/lib/libend.a")));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Exec =
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
|
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.
|
|
|
|
if (getToolChain().getArchName() == "i386")
|
|
|
|
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 {
|
2009-12-22 02:54:17 +08:00
|
|
|
const Driver &D = getToolChain().getDriver();
|
2009-05-03 02:28:39 +08:00
|
|
|
ArgStringList CmdArgs;
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-Bstatic");
|
|
|
|
} else {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When building 32-bit code on DragonFly/pc64, we have to explicitly
|
|
|
|
// instruct ld in the base system to link 32-bit code.
|
|
|
|
if (getToolChain().getArchName() == "i386") {
|
|
|
|
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)) {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
|
2009-05-03 02:28:39 +08:00
|
|
|
} else {
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
|
2010-07-08 00:01:42 +08:00
|
|
|
CmdArgs.push_back(
|
2010-07-15 02:46:23 +08:00
|
|
|
Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Don't try to pass LLVM 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)
|
2009-05-03 04:14:53 +08:00
|
|
|
D.Diag(clang::diag::err_drv_no_linker_llvm_support)
|
2009-09-10 06:32:48 +08:00
|
|
|
<< getToolChain().getTripleString();
|
2009-05-03 04:14:53 +08:00
|
|
|
|
2010-08-02 10:38:21 +08:00
|
|
|
if (II.isFilename())
|
2009-05-03 02:28:39 +08:00
|
|
|
CmdArgs.push_back(II.getFilename());
|
|
|
|
else
|
|
|
|
II.getInputArg().renderAsInput(Args, CmdArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_nostdlib) &&
|
|
|
|
!Args.hasArg(options::OPT_nodefaultlibs)) {
|
|
|
|
// FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
|
|
|
|
// rpaths
|
|
|
|
CmdArgs.push_back("-L/usr/lib/gcc41");
|
|
|
|
|
|
|
|
if (!Args.hasArg(options::OPT_static)) {
|
|
|
|
CmdArgs.push_back("-rpath");
|
|
|
|
CmdArgs.push_back("/usr/lib/gcc41");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-rpath-link");
|
|
|
|
CmdArgs.push_back("/usr/lib/gcc41");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-rpath");
|
|
|
|
CmdArgs.push_back("/usr/lib");
|
|
|
|
|
|
|
|
CmdArgs.push_back("-rpath-link");
|
|
|
|
CmdArgs.push_back("/usr/lib");
|
|
|
|
}
|
|
|
|
|
2010-07-20 20:59:03 +08:00
|
|
|
if (D.CCCIsCXX) {
|
|
|
|
CmdArgs.push_back("-lstdc++");
|
|
|
|
CmdArgs.push_back("-lm");
|
|
|
|
}
|
|
|
|
|
2009-05-03 02:28:39 +08:00
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-lgcc_pic");
|
|
|
|
} else {
|
|
|
|
CmdArgs.push_back("-lgcc");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Args.hasArg(options::OPT_shared)) {
|
|
|
|
CmdArgs.push_back("-lgcc_pic");
|
|
|
|
} else {
|
|
|
|
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-05-03 02:28:39 +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")));
|
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-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
|
|
|
}
|