2009-03-20 08:20:03 +08:00
|
|
|
//===--- ToolChains.cpp - ToolChain Implementations ---------------------*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ToolChains.h"
|
|
|
|
|
2009-03-25 12:13:45 +08:00
|
|
|
#include "clang/Driver/Arg.h"
|
|
|
|
#include "clang/Driver/ArgList.h"
|
2009-03-24 00:15:50 +08:00
|
|
|
#include "clang/Driver/Driver.h"
|
2009-03-25 14:12:34 +08:00
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
2009-03-24 00:15:50 +08:00
|
|
|
#include "clang/Driver/HostInfo.h"
|
2009-03-25 14:12:34 +08:00
|
|
|
#include "clang/Driver/Option.h"
|
2009-03-24 00:15:50 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-09-10 06:33:15 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-03-25 14:58:31 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-03-24 00:15:50 +08:00
|
|
|
#include "llvm/System/Path.h"
|
|
|
|
|
2009-04-11 05:00:07 +08:00
|
|
|
#include <cstdlib> // ::getenv
|
|
|
|
|
2009-03-20 08:20:03 +08:00
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::toolchains;
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
/// Darwin - Darwin tool chain for i386 and x86_64.
|
2009-03-20 08:57:52 +08:00
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
|
|
|
|
const unsigned (&_DarwinVersion)[3],
|
2009-09-05 02:35:21 +08:00
|
|
|
const unsigned (&_GCCVersion)[3],
|
|
|
|
bool _IsIPhone)
|
2009-05-22 10:53:45 +08:00
|
|
|
: ToolChain(Host, Triple) {
|
2009-03-24 00:15:50 +08:00
|
|
|
DarwinVersion[0] = _DarwinVersion[0];
|
|
|
|
DarwinVersion[1] = _DarwinVersion[1];
|
|
|
|
DarwinVersion[2] = _DarwinVersion[2];
|
|
|
|
GCCVersion[0] = _GCCVersion[0];
|
|
|
|
GCCVersion[1] = _GCCVersion[1];
|
|
|
|
GCCVersion[2] = _GCCVersion[2];
|
2009-09-05 02:35:21 +08:00
|
|
|
IsIPhone = _IsIPhone;
|
2009-03-24 00:15:50 +08:00
|
|
|
|
2009-03-27 00:23:12 +08:00
|
|
|
llvm::raw_string_ostream(MacosxVersionMin)
|
|
|
|
<< "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
|
|
|
|
|
2009-09-05 02:35:21 +08:00
|
|
|
// FIXME: Lift default up.
|
|
|
|
IPhoneOSVersionMin = "3.0";
|
|
|
|
|
2009-03-24 00:15:50 +08:00
|
|
|
ToolChainDir = "i686-apple-darwin";
|
|
|
|
ToolChainDir += llvm::utostr(DarwinVersion[0]);
|
|
|
|
ToolChainDir += "/";
|
|
|
|
ToolChainDir += llvm::utostr(GCCVersion[0]);
|
|
|
|
ToolChainDir += '.';
|
|
|
|
ToolChainDir += llvm::utostr(GCCVersion[1]);
|
|
|
|
ToolChainDir += '.';
|
|
|
|
ToolChainDir += llvm::utostr(GCCVersion[2]);
|
|
|
|
|
|
|
|
std::string Path;
|
|
|
|
if (getArchName() == "x86_64") {
|
|
|
|
Path = getHost().getDriver().Dir;
|
|
|
|
Path += "/../lib/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
Path += "/x86_64";
|
|
|
|
getFilePaths().push_back(Path);
|
|
|
|
|
|
|
|
Path = "/usr/lib/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
Path += "/x86_64";
|
|
|
|
getFilePaths().push_back(Path);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 00:15:50 +08:00
|
|
|
Path = getHost().getDriver().Dir;
|
|
|
|
Path += "/../lib/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
getFilePaths().push_back(Path);
|
|
|
|
|
|
|
|
Path = "/usr/lib/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
getFilePaths().push_back(Path);
|
|
|
|
|
|
|
|
Path = getHost().getDriver().Dir;
|
|
|
|
Path += "/../libexec/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
getProgramPaths().push_back(Path);
|
|
|
|
|
|
|
|
Path = "/usr/libexec/gcc/";
|
2009-09-18 16:14:36 +08:00
|
|
|
Path += ToolChainDir;
|
2009-03-24 00:15:50 +08:00
|
|
|
getProgramPaths().push_back(Path);
|
|
|
|
|
2009-03-24 12:07:10 +08:00
|
|
|
Path = getHost().getDriver().Dir;
|
|
|
|
Path += "/../libexec";
|
|
|
|
getProgramPaths().push_back(Path);
|
|
|
|
|
2009-03-24 00:15:50 +08:00
|
|
|
getProgramPaths().push_back(getHost().getDriver().Dir);
|
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
Darwin::~Darwin() {
|
2009-03-20 08:57:52 +08:00
|
|
|
// Free tool implementations.
|
|
|
|
for (llvm::DenseMap<unsigned, Tool*>::iterator
|
|
|
|
it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
|
2009-03-20 08:57:52 +08:00
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-03-20 08:57:52 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
|
|
|
case Action::InputClass:
|
|
|
|
case Action::BindArchClass:
|
|
|
|
assert(0 && "Invalid tool kind.");
|
|
|
|
case Action::PreprocessJobClass:
|
2009-03-30 06:27:40 +08:00
|
|
|
T = new tools::darwin::Preprocess(*this); break;
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::AnalyzeJobClass:
|
|
|
|
T = new tools::Clang(*this); break;
|
2009-03-30 06:27:40 +08:00
|
|
|
case Action::PrecompileJobClass:
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::CompileJobClass:
|
2009-03-30 06:27:40 +08:00
|
|
|
T = new tools::darwin::Compile(*this); break;
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::AssembleJobClass:
|
2009-03-21 00:06:39 +08:00
|
|
|
T = new tools::darwin::Assemble(*this); break;
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::LinkJobClass:
|
2009-09-05 01:39:02 +08:00
|
|
|
T = new tools::darwin::Link(*this); break;
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::LipoJobClass:
|
|
|
|
T = new tools::darwin::Lipo(*this); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|
|
|
|
|
2009-09-18 16:14:36 +08:00
|
|
|
void Darwin::AddLinkSearchPathArgs(const ArgList &Args,
|
|
|
|
ArgStringList &CmdArgs) const {
|
|
|
|
// FIXME: Derive these correctly.
|
|
|
|
if (getArchName() == "x86_64") {
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
|
|
|
|
"/x86_64"));
|
|
|
|
// Intentionally duplicated for (temporary) gcc bug compatibility.
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
|
|
|
|
"/x86_64"));
|
|
|
|
}
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
|
|
|
|
// Intentionally duplicated for (temporary) gcc bug compatibility.
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
|
|
|
|
"/../../../" + ToolChainDir));
|
|
|
|
CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
|
|
|
|
"/../../.."));
|
|
|
|
}
|
|
|
|
|
2009-09-10 02:36:12 +08:00
|
|
|
DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
|
|
|
|
const char *BoundArch) const {
|
2009-03-25 14:12:34 +08:00
|
|
|
DerivedArgList *DAL = new DerivedArgList(Args, false);
|
2009-03-25 14:58:31 +08:00
|
|
|
const OptTable &Opts = getHost().getDriver().getOpts();
|
|
|
|
|
|
|
|
// FIXME: We really want to get out of the tool chain level argument
|
|
|
|
// translation business, as it makes the driver functionality much
|
|
|
|
// more opaque. For now, we follow gcc closely solely for the
|
|
|
|
// purpose of easily achieving feature parity & testability. Once we
|
|
|
|
// have something that works, we should reevaluate each translation
|
2009-09-09 23:08:12 +08:00
|
|
|
// and try to push it down into tool specific logic.
|
2009-03-25 14:58:31 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
Arg *OSXVersion =
|
2009-04-11 04:11:50 +08:00
|
|
|
Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
|
|
|
|
Arg *iPhoneVersion =
|
2009-09-09 23:08:12 +08:00
|
|
|
Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
|
2009-04-11 04:11:50 +08:00
|
|
|
if (OSXVersion && iPhoneVersion) {
|
|
|
|
getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
|
|
|
|
<< OSXVersion->getAsString(Args)
|
2009-09-09 23:08:12 +08:00
|
|
|
<< iPhoneVersion->getAsString(Args);
|
2009-04-11 04:11:50 +08:00
|
|
|
} else if (!OSXVersion && !iPhoneVersion) {
|
|
|
|
// Chose the default version based on the arch.
|
|
|
|
//
|
2009-09-05 02:35:21 +08:00
|
|
|
// FIXME: Are there iPhone overrides for this?
|
|
|
|
|
|
|
|
if (!isIPhone()) {
|
|
|
|
// Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
|
|
|
|
// from the host.
|
|
|
|
const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
|
|
|
|
if (!Version)
|
|
|
|
Version = MacosxVersionMin.c_str();
|
|
|
|
const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, O, Version));
|
|
|
|
} else {
|
|
|
|
const char *Version = IPhoneOSVersionMin.c_str();
|
|
|
|
const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, O, Version));
|
|
|
|
}
|
2009-03-25 14:58:31 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-25 14:12:34 +08:00
|
|
|
for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
|
|
|
|
Arg *A = *it;
|
|
|
|
|
|
|
|
if (A->getOption().matches(options::OPT_Xarch__)) {
|
|
|
|
// FIXME: Canonicalize name.
|
|
|
|
if (getArchName() != A->getValue(Args, 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// FIXME: The arg is leaked here, and we should have a nicer
|
|
|
|
// interface for this.
|
|
|
|
unsigned Prev, Index = Prev = A->getIndex() + 1;
|
2009-03-25 14:58:31 +08:00
|
|
|
Arg *XarchArg = Opts.ParseOneArg(Args, Index);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-25 14:12:34 +08:00
|
|
|
// If the argument parsing failed or more than one argument was
|
|
|
|
// consumed, the -Xarch_ argument's parameter tried to consume
|
|
|
|
// extra arguments. Emit an error and ignore.
|
|
|
|
//
|
|
|
|
// We also want to disallow any options which would alter the
|
|
|
|
// driver behavior; that isn't going to work in our model. We
|
|
|
|
// use isDriverOption() as an approximation, although things
|
|
|
|
// like -O4 are going to slip through.
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!XarchArg || Index > Prev + 1 ||
|
2009-03-25 14:12:34 +08:00
|
|
|
XarchArg->getOption().isDriverOption()) {
|
2009-03-25 14:58:31 +08:00
|
|
|
getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
|
2009-03-25 14:12:34 +08:00
|
|
|
<< A->getAsString(Args);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-03-30 06:29:05 +08:00
|
|
|
XarchArg->setBaseArg(A);
|
2009-03-25 14:12:34 +08:00
|
|
|
A = XarchArg;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-03-25 14:12:34 +08:00
|
|
|
|
2009-03-25 14:58:31 +08:00
|
|
|
// Sob. These is strictly gcc compatible for the time being. Apple
|
|
|
|
// gcc translates options twice, which means that self-expanding
|
|
|
|
// options add duplicates.
|
|
|
|
options::ID id = A->getOption().getId();
|
|
|
|
switch (id) {
|
|
|
|
default:
|
|
|
|
DAL->append(A);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_mkernel:
|
|
|
|
case options::OPT_fapple_kext:
|
|
|
|
DAL->append(A);
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
|
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
|
2009-03-25 14:58:31 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-25 14:58:31 +08:00
|
|
|
case options::OPT_dependency_file:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
|
2009-03-25 14:58:31 +08:00
|
|
|
A->getValue(Args)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_gfull:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
|
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_gused:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
|
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_fterminated_vtables:
|
|
|
|
case options::OPT_findirect_virtual_calls:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
|
|
|
Opts.getOption(options::OPT_fapple_kext)));
|
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
|
2009-03-25 14:58:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_shared:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
|
2009-03-25 14:58:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_fconstant_cfstrings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mconstant_cfstrings)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_fno_constant_cfstrings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mno_constant_cfstrings)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_Wnonportable_cfstrings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_Wno_nonportable_cfstrings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_fpascal_strings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mpascal_strings)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case options::OPT_fno_pascal_strings:
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(A,
|
2009-03-25 14:58:31 +08:00
|
|
|
Opts.getOption(options::OPT_mno_pascal_strings)));
|
|
|
|
break;
|
|
|
|
}
|
2009-03-25 14:12:34 +08:00
|
|
|
}
|
|
|
|
|
2009-09-10 06:33:15 +08:00
|
|
|
if (getTriple().getArch() == llvm::Triple::x86 ||
|
|
|
|
getTriple().getArch() == llvm::Triple::x86_64)
|
|
|
|
if (!Args.hasArg(options::OPT_mtune_EQ, false))
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
|
|
|
|
"core2"));
|
|
|
|
|
|
|
|
// Add the arch options based on the particular spelling of -arch, to match
|
|
|
|
// how the driver driver works.
|
|
|
|
if (BoundArch) {
|
|
|
|
llvm::StringRef Name = BoundArch;
|
|
|
|
const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
|
|
|
|
const Option *MArch = Opts.getOption(options::OPT_march_EQ);
|
|
|
|
|
|
|
|
// This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
|
|
|
|
// which defines the list of which architectures we accept.
|
|
|
|
if (Name == "ppc")
|
|
|
|
;
|
|
|
|
else if (Name == "ppc601")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
|
|
|
|
else if (Name == "ppc603")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
|
|
|
|
else if (Name == "ppc604")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
|
|
|
|
else if (Name == "ppc604e")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
|
|
|
|
else if (Name == "ppc750")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
|
|
|
|
else if (Name == "ppc7400")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
|
|
|
|
else if (Name == "ppc7450")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
|
|
|
|
else if (Name == "ppc970")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
|
|
|
|
|
|
|
|
else if (Name == "ppc64")
|
|
|
|
DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
|
|
|
|
|
|
|
|
else if (Name == "i386")
|
|
|
|
;
|
|
|
|
else if (Name == "i486")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
|
|
|
|
else if (Name == "i586")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
|
|
|
|
else if (Name == "i686")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
|
|
|
|
else if (Name == "pentium")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
|
|
|
|
else if (Name == "pentium2")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
|
|
|
|
else if (Name == "pentpro")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
|
|
|
|
else if (Name == "pentIIm3")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
|
|
|
|
|
|
|
|
else if (Name == "x86_64")
|
2009-03-30 06:29:05 +08:00
|
|
|
DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
|
2009-03-25 14:58:31 +08:00
|
|
|
|
2009-09-10 06:33:15 +08:00
|
|
|
else if (Name == "arm")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
|
|
|
|
else if (Name == "armv4t")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
|
|
|
|
else if (Name == "armv5")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
|
|
|
|
else if (Name == "xscale")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
|
|
|
|
else if (Name == "armv6")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
|
|
|
|
else if (Name == "armv7")
|
|
|
|
DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
|
|
|
|
|
|
|
|
else
|
|
|
|
llvm::llvm_unreachable("invalid Darwin arch");
|
|
|
|
}
|
2009-03-25 14:58:31 +08:00
|
|
|
|
2009-03-25 14:12:34 +08:00
|
|
|
return DAL;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-03-20 08:57:52 +08:00
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
bool Darwin::IsMathErrnoDefault() const {
|
2009-09-09 23:08:12 +08:00
|
|
|
return false;
|
2009-03-20 08:57:52 +08:00
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
bool Darwin::IsUnwindTablesDefault() const {
|
2009-03-20 08:57:52 +08:00
|
|
|
// FIXME: Gross; we should probably have some separate target
|
|
|
|
// definition, possibly even reusing the one in clang.
|
|
|
|
return getArchName() == "x86_64";
|
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
const char *Darwin::GetDefaultRelocationModel() const {
|
2009-03-20 08:57:52 +08:00
|
|
|
return "pic";
|
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
const char *Darwin::GetForcedPicModel() const {
|
2009-03-20 08:57:52 +08:00
|
|
|
if (getArchName() == "x86_64")
|
|
|
|
return "pic";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-20 08:20:03 +08:00
|
|
|
/// Generic_GCC - A tool chain using the 'gcc' command to perform
|
|
|
|
/// all subcommands; this relies on gcc translating the majority of
|
|
|
|
/// command line options.
|
|
|
|
|
2009-05-22 10:53:45 +08:00
|
|
|
Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
|
2009-09-09 23:08:12 +08:00
|
|
|
: ToolChain(Host, Triple) {
|
2009-03-24 12:07:10 +08:00
|
|
|
std::string Path(getHost().getDriver().Dir);
|
|
|
|
Path += "/../libexec";
|
|
|
|
getProgramPaths().push_back(Path);
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
getProgramPaths().push_back(getHost().getDriver().Dir);
|
2009-03-24 00:15:50 +08:00
|
|
|
}
|
|
|
|
|
2009-03-20 08:20:03 +08:00
|
|
|
Generic_GCC::~Generic_GCC() {
|
|
|
|
// Free tool implementations.
|
|
|
|
for (llvm::DenseMap<unsigned, Tool*>::iterator
|
|
|
|
it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
Tool &Generic_GCC::SelectTool(const Compilation &C,
|
2009-03-20 08:20:03 +08:00
|
|
|
const JobAction &JA) const {
|
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-03-20 08:20:03 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
2009-03-20 08:57:52 +08:00
|
|
|
case Action::InputClass:
|
|
|
|
case Action::BindArchClass:
|
2009-03-20 08:20:03 +08:00
|
|
|
assert(0 && "Invalid tool kind.");
|
|
|
|
case Action::PreprocessJobClass:
|
|
|
|
T = new tools::gcc::Preprocess(*this); break;
|
|
|
|
case Action::PrecompileJobClass:
|
|
|
|
T = new tools::gcc::Precompile(*this); break;
|
|
|
|
case Action::AnalyzeJobClass:
|
|
|
|
T = new tools::Clang(*this); break;
|
|
|
|
case Action::CompileJobClass:
|
|
|
|
T = new tools::gcc::Compile(*this); break;
|
|
|
|
case Action::AssembleJobClass:
|
|
|
|
T = new tools::gcc::Assemble(*this); break;
|
|
|
|
case Action::LinkJobClass:
|
|
|
|
T = new tools::gcc::Link(*this); break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-20 08:57:52 +08:00
|
|
|
// This is a bit ungeneric, but the only platform using a driver
|
|
|
|
// driver is Darwin.
|
|
|
|
case Action::LipoJobClass:
|
|
|
|
T = new tools::darwin::Lipo(*this); break;
|
2009-03-20 08:20:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|
|
|
|
|
2009-09-05 02:34:51 +08:00
|
|
|
bool Generic_GCC::IsMathErrnoDefault() const {
|
2009-09-09 23:08:12 +08:00
|
|
|
return true;
|
2009-03-20 08:20:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Generic_GCC::IsUnwindTablesDefault() const {
|
2009-03-20 08:57:52 +08:00
|
|
|
// FIXME: Gross; we should probably have some separate target
|
|
|
|
// definition, possibly even reusing the one in clang.
|
2009-03-20 08:20:03 +08:00
|
|
|
return getArchName() == "x86_64";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Generic_GCC::GetDefaultRelocationModel() const {
|
|
|
|
return "static";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Generic_GCC::GetForcedPicModel() const {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-25 12:13:45 +08:00
|
|
|
|
2009-09-10 02:36:12 +08:00
|
|
|
DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
|
|
|
|
const char *BoundArch) const {
|
2009-03-25 12:13:45 +08:00
|
|
|
return new DerivedArgList(Args, true);
|
|
|
|
}
|
2009-03-31 05:06:03 +08:00
|
|
|
|
2009-06-30 04:52:51 +08:00
|
|
|
/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
|
|
|
|
|
|
|
|
OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
|
|
|
|
: Generic_GCC(Host, Triple) {
|
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
|
|
|
|
getFilePaths().push_back("/usr/lib");
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
|
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-06-30 04:52:51 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
|
|
|
case Action::AssembleJobClass:
|
|
|
|
T = new tools::openbsd::Assemble(*this); break;
|
|
|
|
case Action::LinkJobClass:
|
|
|
|
T = new tools::openbsd::Link(*this); break;
|
|
|
|
default:
|
|
|
|
T = &Generic_GCC::SelectTool(C, JA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|
|
|
|
|
2009-03-31 05:06:03 +08:00
|
|
|
/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
|
|
|
|
|
2009-05-22 10:53:45 +08:00
|
|
|
FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
|
|
|
|
: Generic_GCC(Host, Triple) {
|
2009-04-03 02:30:04 +08:00
|
|
|
if (Lib32) {
|
2009-03-31 05:06:03 +08:00
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
|
2009-04-03 02:30:04 +08:00
|
|
|
getFilePaths().push_back("/usr/lib32");
|
|
|
|
} else {
|
2009-03-31 05:06:03 +08:00
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
|
2009-04-03 02:30:04 +08:00
|
|
|
getFilePaths().push_back("/usr/lib");
|
|
|
|
}
|
2009-03-31 05:06:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
|
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-03-31 05:06:03 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
2009-04-01 01:45:15 +08:00
|
|
|
case Action::AssembleJobClass:
|
|
|
|
T = new tools::freebsd::Assemble(*this); break;
|
2009-04-02 03:36:32 +08:00
|
|
|
case Action::LinkJobClass:
|
|
|
|
T = new tools::freebsd::Link(*this); break;
|
2009-03-31 05:06:03 +08:00
|
|
|
default:
|
|
|
|
T = &Generic_GCC::SelectTool(C, JA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|
2009-05-03 02:28:39 +08:00
|
|
|
|
2009-08-22 09:06:46 +08:00
|
|
|
/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
|
|
|
|
|
|
|
|
AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
|
|
|
|
: Generic_GCC(Host, Triple) {
|
|
|
|
|
|
|
|
// Path mangling to find libexec
|
|
|
|
std::string Path(getHost().getDriver().Dir);
|
|
|
|
|
|
|
|
Path += "/../libexec";
|
|
|
|
getProgramPaths().push_back(Path);
|
2009-09-09 23:08:12 +08:00
|
|
|
getProgramPaths().push_back(getHost().getDriver().Dir);
|
2009-08-22 09:06:46 +08:00
|
|
|
|
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
|
|
|
|
getFilePaths().push_back("/usr/lib");
|
|
|
|
getFilePaths().push_back("/usr/sfw/lib");
|
|
|
|
getFilePaths().push_back("/opt/gcc4/lib");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
|
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-08-22 09:06:46 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
|
|
|
case Action::AssembleJobClass:
|
|
|
|
T = new tools::auroraux::Assemble(*this); break;
|
|
|
|
case Action::LinkJobClass:
|
|
|
|
T = new tools::auroraux::Link(*this); break;
|
|
|
|
default:
|
|
|
|
T = &Generic_GCC::SelectTool(C, JA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-26 15:52:18 +08:00
|
|
|
/// Linux toolchain (very bare-bones at the moment).
|
|
|
|
|
|
|
|
Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
|
|
|
|
: Generic_GCC(Host, Triple) {
|
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
|
|
|
|
getFilePaths().push_back("/lib/");
|
|
|
|
getFilePaths().push_back("/usr/lib/");
|
2009-08-06 09:47:11 +08:00
|
|
|
|
|
|
|
// Depending on the Linux distribution, any combination of lib{,32,64} is
|
|
|
|
// possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
|
|
|
|
// openSUSE uses lib and lib64 for the same purpose.
|
|
|
|
getFilePaths().push_back("/lib32/");
|
|
|
|
getFilePaths().push_back("/usr/lib32/");
|
|
|
|
getFilePaths().push_back("/lib64/");
|
|
|
|
getFilePaths().push_back("/usr/lib64/");
|
|
|
|
|
2009-05-26 15:52:18 +08:00
|
|
|
// FIXME: Figure out some way to get gcc's libdir
|
|
|
|
// (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
|
|
|
|
// crtbegin.o/crtend.o/etc., and want static versions of various
|
|
|
|
// libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
|
|
|
|
// get away with using shared versions in /usr/lib, though.
|
|
|
|
// We could fall back to the approach we used for includes (a massive
|
|
|
|
// list), but that's messy at best.
|
|
|
|
}
|
|
|
|
|
2009-05-03 02:28:39 +08:00
|
|
|
/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
|
|
|
|
|
2009-05-22 10:53:45 +08:00
|
|
|
DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
|
|
|
|
: Generic_GCC(Host, Triple) {
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
// Path mangling to find libexec
|
|
|
|
std::string Path(getHost().getDriver().Dir);
|
|
|
|
|
|
|
|
Path += "/../libexec";
|
|
|
|
getProgramPaths().push_back(Path);
|
2009-09-09 23:08:12 +08:00
|
|
|
getProgramPaths().push_back(getHost().getDriver().Dir);
|
2009-05-03 02:28:39 +08:00
|
|
|
|
|
|
|
getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
|
|
|
|
getFilePaths().push_back("/usr/lib");
|
|
|
|
getFilePaths().push_back("/usr/lib/gcc41");
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
|
|
|
|
Action::ActionClass Key;
|
2009-09-09 07:36:55 +08:00
|
|
|
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
|
2009-05-03 02:28:39 +08:00
|
|
|
Key = Action::AnalyzeJobClass;
|
|
|
|
else
|
|
|
|
Key = JA.getKind();
|
|
|
|
|
|
|
|
Tool *&T = Tools[Key];
|
|
|
|
if (!T) {
|
|
|
|
switch (Key) {
|
|
|
|
case Action::AssembleJobClass:
|
|
|
|
T = new tools::dragonfly::Assemble(*this); break;
|
|
|
|
case Action::LinkJobClass:
|
|
|
|
T = new tools::dragonfly::Link(*this); break;
|
|
|
|
default:
|
|
|
|
T = &Generic_GCC::SelectTool(C, JA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *T;
|
|
|
|
}
|