18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/Option/Arg.h"
21 #include "llvm/Option/ArgList.h"
22 #include "llvm/Option/Option.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/FileSystem.h"
25 using namespace clang::driver;
26 using namespace clang;
27 using namespace llvm::opt;
30 return Args.getLastArg(options::OPT_mkernel, options::OPT_fapple_kext,
31 options::OPT_fno_rtti, options::OPT_frtti);
35 const llvm::Triple &Triple,
36 const Arg *CachedRTTIArg) {
39 if (CachedRTTIArg->getOption().matches(options::OPT_frtti))
46 if (!Triple.isPS4CPU())
51 Arg *Exceptions = Args.getLastArgNoClaim(
52 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
53 options::OPT_fexceptions, options::OPT_fno_exceptions);
55 (Exceptions->getOption().matches(options::OPT_fexceptions) ||
56 Exceptions->getOption().matches(options::OPT_fcxx_exceptions)))
66 if (Arg *A = Args.getLastArg(options::OPT_mthread_model))
68 D.
Diag(diag::err_drv_invalid_thread_model_for_target)
69 << A->getValue() << A->getAsString(Args);
80 return Args.hasFlag(options::OPT_fintegrated_as,
81 options::OPT_fno_integrated_as,
86 if (!SanitizerArguments.get())
88 return *SanitizerArguments.get();
96 switch (Triple.getArch()) {
97 case llvm::Triple::ppc:
99 case llvm::Triple::ppc64:
101 case llvm::Triple::ppc64le:
104 return Triple.getArchName();
112 Tool *ToolChain::getClang()
const {
123 llvm_unreachable(
"Linking is not supported by this toolchain");
126 Tool *ToolChain::getAssemble()
const {
129 return Assemble.get();
132 Tool *ToolChain::getClangAs()
const {
135 return Assemble.get();
138 Tool *ToolChain::getLink()
const {
147 return getAssemble();
159 llvm_unreachable(
"Invalid tool kind.");
171 llvm_unreachable(
"Invalid tool kind.");
175 if (
getDriver().ShouldUseClangCompiler(JA))
193 if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
194 StringRef Suffix = A->getValue();
198 if (Suffix.empty() || Suffix ==
"ld")
202 LinkerName.append(Suffix);
205 if (llvm::sys::fs::exists(LinkerPath))
208 getDriver().
Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
225 llvm::Triple HostTriple(LLVM_HOST_TRIPLE);
226 switch (HostTriple.getArch()) {
229 case llvm::Triple::arm:
230 case llvm::Triple::armeb:
231 case llvm::Triple::thumb:
232 case llvm::Triple::thumbeb:
233 return getArch() != llvm::Triple::arm &&
getArch() != llvm::Triple::thumb &&
234 getArch() != llvm::Triple::armeb &&
getArch() != llvm::Triple::thumbeb;
236 return HostTriple.getArch() !=
getArch();
246 if (Model ==
"single") {
248 return Triple.getArch() == llvm::Triple::arm ||
249 Triple.getArch() == llvm::Triple::armeb ||
250 Triple.getArch() == llvm::Triple::thumb ||
251 Triple.getArch() == llvm::Triple::thumbeb;
252 }
else if (Model ==
"posix")
264 case llvm::Triple::x86_64: {
266 if (!Triple.isOSBinFormatMachO())
269 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
272 StringRef MArch = A->getValue();
273 if (MArch ==
"x86_64h")
274 Triple.setArchName(MArch);
276 return Triple.getTriple();
278 case llvm::Triple::aarch64: {
280 if (!Triple.isOSBinFormatMachO())
286 Triple.setArchName(
"arm64");
287 return Triple.getTriple();
289 case llvm::Triple::arm:
290 case llvm::Triple::armeb:
291 case llvm::Triple::thumb:
292 case llvm::Triple::thumbeb: {
295 bool IsBigEndian =
getTriple().getArch() == llvm::Triple::armeb ||
296 getTriple().getArch() == llvm::Triple::thumbeb;
300 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
301 options::OPT_mbig_endian)) {
302 IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
308 StringRef MCPU, MArch;
309 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
310 MCPU = A->getValue();
311 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
312 MArch = A->getValue();
313 std::string CPU = Triple.isOSBinFormatMachO()
319 bool ThumbDefault = Suffix.startswith(
"v6m") || Suffix.startswith(
"v7m") ||
320 Suffix.startswith(
"v7em") ||
321 (Suffix.startswith(
"v7") &&
getTriple().isOSBinFormatMachO());
325 std::string ArchName;
332 if (InputType != types::TY_PP_Asm &&
333 Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault))
336 ArchName =
"thumbeb";
340 Triple.setArchName(ArchName + Suffix.str());
342 return Triple.getTriple();
353 ArgStringList &CC1Args)
const {
358 ArgStringList &CC1Args)
const {
364 const ArgList &Args)
const
366 if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
367 StringRef
Value = A->getValue();
368 if (Value ==
"compiler-rt")
370 if (Value ==
"libgcc")
373 << A->getAsString(Args);
380 if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
381 StringRef
Value = A->getValue();
382 if (Value ==
"libc++")
384 if (Value ==
"libstdc++")
387 << A->getAsString(Args);
395 ArgStringList &CC1Args,
397 CC1Args.push_back(
"-internal-isystem");
398 CC1Args.push_back(DriverArgs.MakeArgString(Path));
410 ArgStringList &CC1Args,
412 CC1Args.push_back(
"-internal-externc-isystem");
413 CC1Args.push_back(DriverArgs.MakeArgString(Path));
417 ArgStringList &CC1Args,
419 if (llvm::sys::fs::exists(Path))
425 ArgStringList &CC1Args,
429 CC1Args.push_back(
"-internal-isystem");
430 CC1Args.push_back(DriverArgs.MakeArgString(*I));
435 ArgStringList &CC1Args)
const {
445 DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
449 ArgStringList &CmdArgs)
const {
454 CmdArgs.push_back(
"-lc++");
458 CmdArgs.push_back(
"-lstdc++");
464 ArgStringList &CmdArgs)
const {
465 CmdArgs.push_back(
"-lcc_kext");
469 ArgStringList &CmdArgs)
const {
475 Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math,
476 options::OPT_funsafe_math_optimizations,
477 options::OPT_fno_unsafe_math_optimizations);
479 if (!A || A->getOption().getID() == options::OPT_fno_fast_math ||
480 A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations)
485 if (Path ==
"crtfastmath.o")
488 CmdArgs.push_back(Args.MakeArgString(Path));
495 using namespace SanitizerKind;
496 return (Undefined & ~Vptr & ~Function) | CFI | CFICastStrict |
497 UnsignedIntegerOverflow | LocalBounds;
ID lookupTypeForExtension(const char *Ext)
Represents a version number in the form major[.minor[.subminor[.build]]].
Defines types useful for describing an Objective-C runtime.
DiagnosticBuilder Diag(unsigned DiagID) const
ActionClass getKind() const
std::string GetFilePath(const char *Name, const ToolChain &TC) const
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
'gnustep' is the modern non-fragile GNUstep runtime.
std::string GetProgramPath(const char *Name, const ToolChain &TC) const
The basic abstraction for the target Objective-C runtime.