1 //===--- Tools.cpp - Tools Implementations --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "clang/Driver/Action.h"
13 #include "clang/Driver/Arg.h"
14 #include "clang/Driver/ArgList.h"
15 #include "clang/Driver/Driver.h"
16 #include "clang/Driver/DriverDiagnostic.h"
17 #include "clang/Driver/Compilation.h"
18 #include "clang/Driver/Job.h"
19 #include "clang/Driver/HostInfo.h"
20 #include "clang/Driver/ObjCRuntime.h"
21 #include "clang/Driver/Option.h"
22 #include "clang/Driver/Options.h"
23 #include "clang/Driver/ToolChain.h"
24 #include "clang/Driver/Util.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/StringSwitch.h"
28 #include "llvm/ADT/Twine.h"
29 #include "llvm/Support/FileSystem.h"
30 #include "llvm/Support/Format.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/Support/Host.h"
33 #include "llvm/Support/Process.h"
34 #include "llvm/Support/ErrorHandling.h"
36 #include "InputInfo.h"
37 #include "ToolChains.h"
40 #include <cygwin/version.h>
41 #if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007
46 using namespace clang::driver;
47 using namespace clang::driver::tools;
49 /// FindTargetProgramPath - Return path of the target specific version of
50 /// ProgName. If it doesn't exist, return path of ProgName itself.
51 static std::string FindTargetProgramPath(const ToolChain &TheToolChain,
52 const std::string TripleString,
53 const char *ProgName) {
54 std::string Executable(TripleString + "-" + ProgName);
55 std::string Path(TheToolChain.GetProgramPath(Executable.c_str()));
56 if (Path != Executable)
58 return TheToolChain.GetProgramPath(ProgName);
61 /// CheckPreprocessingOptions - Perform some validation of preprocessing
62 /// arguments that is shared with gcc.
63 static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) {
64 if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC))
65 if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP)
66 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
67 << A->getAsString(Args) << "-E";
70 /// CheckCodeGenerationOptions - Perform some validation of code generation
71 /// arguments that is shared with gcc.
72 static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) {
73 // In gcc, only ARM checks this, but it seems reasonable to check universally.
74 if (Args.hasArg(options::OPT_static))
75 if (const Arg *A = Args.getLastArg(options::OPT_dynamic,
76 options::OPT_mdynamic_no_pic))
77 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
78 << A->getAsString(Args) << "-static";
81 // Quote target names for inclusion in GNU Make dependency files.
82 // Only the characters '$', '#', ' ', '\t' are quoted.
83 static void QuoteTarget(llvm::StringRef Target,
84 llvm::SmallVectorImpl<char> &Res) {
85 for (unsigned i = 0, e = Target.size(); i != e; ++i) {
89 // Escape the preceding backslashes
90 for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
93 // Escape the space/tab
106 Res.push_back(Target[i]);
110 static void AddLinkerInputs(const ToolChain &TC,
111 const InputInfoList &Inputs, const ArgList &Args,
112 ArgStringList &CmdArgs) {
113 const Driver &D = TC.getDriver();
115 // Add extra linker input arguments which are not treated as inputs
116 // (constructed via -Xarch_).
117 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
119 for (InputInfoList::const_iterator
120 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
121 const InputInfo &II = *it;
123 if (!TC.HasNativeLLVMSupport()) {
124 // Don't try to pass LLVM inputs unless we have native support.
125 if (II.getType() == types::TY_LLVM_IR ||
126 II.getType() == types::TY_LTO_IR ||
127 II.getType() == types::TY_LLVM_BC ||
128 II.getType() == types::TY_LTO_BC)
129 D.Diag(clang::diag::err_drv_no_linker_llvm_support)
130 << TC.getTripleString();
133 // Add filenames immediately.
134 if (II.isFilename()) {
135 CmdArgs.push_back(II.getFilename());
139 // Otherwise, this is a linker input argument.
140 const Arg &A = II.getInputArg();
142 // Handle reserved library options.
143 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
144 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
145 } else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) {
146 TC.AddCCKextLibArgs(Args, CmdArgs);
148 A.renderAsInput(Args, CmdArgs);
152 /// \brief Determine whether Objective-C automated reference counting is
154 static bool isObjCAutoRefCount(const ArgList &Args) {
155 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false);
158 static void addProfileRT(const ToolChain &TC, const ArgList &Args,
159 ArgStringList &CmdArgs,
160 llvm::Triple Triple) {
161 if (!(Args.hasArg(options::OPT_fprofile_arcs) ||
162 Args.hasArg(options::OPT_fprofile_generate) ||
163 Args.hasArg(options::OPT_fcreate_profile) ||
164 Args.hasArg(options::OPT_coverage)))
167 // GCC links libgcov.a by adding -L<inst>/gcc/lib/gcc/<triple>/<ver> -lgcov to
168 // the link line. We cannot do the same thing because unlike gcov there is a
169 // libprofile_rt.so. We used to use the -l:libprofile_rt.a syntax, but that is
170 // not supported by old linkers.
171 llvm::Twine ProfileRT =
172 llvm::Twine(TC.getDriver().Dir) + "/../lib/" + "libprofile_rt.a";
174 if (Triple.getOS() == llvm::Triple::Darwin) {
175 // On Darwin, if the static library doesn't exist try the dylib.
177 if (llvm::sys::fs::exists(ProfileRT.str(), Exists) || !Exists)
179 llvm::Twine(TC.getDriver().Dir) + "/../lib/" + "libprofile_rt.dylib";
182 CmdArgs.push_back(Args.MakeArgString(ProfileRT));
185 void Clang::AddPreprocessingOptions(const Driver &D,
187 ArgStringList &CmdArgs,
188 const InputInfo &Output,
189 const InputInfoList &Inputs) const {
192 CheckPreprocessingOptions(D, Args);
194 Args.AddLastArg(CmdArgs, options::OPT_C);
195 Args.AddLastArg(CmdArgs, options::OPT_CC);
197 // Handle dependency file generation.
198 if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) ||
199 (A = Args.getLastArg(options::OPT_MD)) ||
200 (A = Args.getLastArg(options::OPT_MMD))) {
201 // Determine the output location.
203 if (Output.getType() == types::TY_Dependencies) {
204 DepFile = Output.getFilename();
205 } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
206 DepFile = MF->getValue(Args);
207 } else if (A->getOption().matches(options::OPT_M) ||
208 A->getOption().matches(options::OPT_MM)) {
211 DepFile = darwin::CC1::getDependencyFileName(Args, Inputs);
213 CmdArgs.push_back("-dependency-file");
214 CmdArgs.push_back(DepFile);
216 // Add a default target if one wasn't specified.
217 if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {
218 const char *DepTarget;
220 // If user provided -o, that is the dependency target, except
221 // when we are only generating a dependency file.
222 Arg *OutputOpt = Args.getLastArg(options::OPT_o);
223 if (OutputOpt && Output.getType() != types::TY_Dependencies) {
224 DepTarget = OutputOpt->getValue(Args);
226 // Otherwise derive from the base input.
228 // FIXME: This should use the computed output file location.
229 llvm::SmallString<128> P(Inputs[0].getBaseInput());
230 llvm::sys::path::replace_extension(P, "o");
231 DepTarget = Args.MakeArgString(llvm::sys::path::filename(P));
234 CmdArgs.push_back("-MT");
235 llvm::SmallString<128> Quoted;
236 QuoteTarget(DepTarget, Quoted);
237 CmdArgs.push_back(Args.MakeArgString(Quoted));
240 if (A->getOption().matches(options::OPT_M) ||
241 A->getOption().matches(options::OPT_MD))
242 CmdArgs.push_back("-sys-header-deps");
245 if (Args.hasArg(options::OPT_MG)) {
246 if (!A || A->getOption().matches(options::OPT_MD) ||
247 A->getOption().matches(options::OPT_MMD))
248 D.Diag(clang::diag::err_drv_mg_requires_m_or_mm);
249 CmdArgs.push_back("-MG");
252 Args.AddLastArg(CmdArgs, options::OPT_MP);
254 // Convert all -MQ <target> args to -MT <quoted target>
255 for (arg_iterator it = Args.filtered_begin(options::OPT_MT,
257 ie = Args.filtered_end(); it != ie; ++it) {
261 if (A->getOption().matches(options::OPT_MQ)) {
262 CmdArgs.push_back("-MT");
263 llvm::SmallString<128> Quoted;
264 QuoteTarget(A->getValue(Args), Quoted);
265 CmdArgs.push_back(Args.MakeArgString(Quoted));
267 // -MT flag - no change
269 A->render(Args, CmdArgs);
273 // Add -i* options, and automatically translate to
274 // -include-pch/-include-pth for transparent PCH support. It's
275 // wonky, but we include looking for .gch so we can support seamless
276 // replacement into a build system already set up to be generating
278 bool RenderedImplicitInclude = false;
279 for (arg_iterator it = Args.filtered_begin(options::OPT_clang_i_Group),
280 ie = Args.filtered_end(); it != ie; ++it) {
283 if (A->getOption().matches(options::OPT_include)) {
284 bool IsFirstImplicitInclude = !RenderedImplicitInclude;
285 RenderedImplicitInclude = true;
287 // Use PCH if the user requested it.
288 bool UsePCH = D.CCCUsePCH;
290 bool FoundPTH = false;
291 bool FoundPCH = false;
292 llvm::sys::Path P(A->getValue(Args));
295 P.appendSuffix("pch");
296 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
303 P.appendSuffix("pth");
304 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
310 if (!FoundPCH && !FoundPTH) {
311 P.appendSuffix("gch");
312 if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) {
320 if (FoundPCH || FoundPTH) {
321 if (IsFirstImplicitInclude) {
324 CmdArgs.push_back("-include-pch");
326 CmdArgs.push_back("-include-pth");
327 CmdArgs.push_back(Args.MakeArgString(P.str()));
330 // Ignore the PCH if not first on command line and emit warning.
331 D.Diag(clang::diag::warn_drv_pch_not_first_include)
332 << P.str() << A->getAsString(Args);
337 // Not translated, render as usual.
339 A->render(Args, CmdArgs);
342 Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
343 Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
345 // Add C++ include arguments, if needed.
346 types::ID InputType = Inputs[0].getType();
347 if (types::isCXX(InputType)) {
348 bool ObjCXXAutoRefCount
349 = types::isObjC(InputType) && isObjCAutoRefCount(Args);
350 getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs,
352 Args.AddAllArgs(CmdArgs, options::OPT_stdlib_EQ);
355 // Add -Wp, and -Xassembler if using the preprocessor.
357 // FIXME: There is a very unfortunate problem here, some troubled
358 // souls abuse -Wp, to pass preprocessor options in gcc syntax. To
359 // really support that we would have to parse and then translate
361 Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
362 options::OPT_Xpreprocessor);
364 // -I- is a deprecated GCC feature, reject it.
365 if (Arg *A = Args.getLastArg(options::OPT_I_))
366 D.Diag(clang::diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
368 // If we have a --sysroot, and don't have an explicit -isysroot flag, add an
369 // -isysroot to the CC1 invocation.
370 if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
371 if (!Args.hasArg(options::OPT_isysroot)) {
372 CmdArgs.push_back("-isysroot");
373 CmdArgs.push_back(A->getValue(Args));
378 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting.
380 // FIXME: tblgen this.
381 static const char *getARMTargetCPU(const ArgList &Args,
382 const llvm::Triple &Triple) {
383 // FIXME: Warn on inconsistent use of -mcpu and -march.
385 // If we have -mcpu=, use that.
386 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
387 return A->getValue(Args);
389 llvm::StringRef MArch;
390 if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
391 // Otherwise, if we have -march= choose the base CPU for that arch.
392 MArch = A->getValue(Args);
394 // Otherwise, use the Arch from the triple.
395 MArch = Triple.getArchName();
398 if (MArch == "armv2" || MArch == "armv2a")
400 if (MArch == "armv3")
402 if (MArch == "armv3m")
404 if (MArch == "armv4" || MArch == "armv4t")
406 if (MArch == "armv5" || MArch == "armv5t")
408 if (MArch == "armv5e" || MArch == "armv5te")
410 if (MArch == "armv5tej")
412 if (MArch == "armv6" || MArch == "armv6k")
413 return "arm1136jf-s";
414 if (MArch == "armv6j")
416 if (MArch == "armv6z" || MArch == "armv6zk")
417 return "arm1176jzf-s";
418 if (MArch == "armv6t2")
419 return "arm1156t2-s";
420 if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a")
422 if (MArch == "armv7r" || MArch == "armv7-r")
424 if (MArch == "armv7m" || MArch == "armv7-m")
426 if (MArch == "ep9312")
428 if (MArch == "iwmmxt")
430 if (MArch == "xscale")
432 if (MArch == "armv6m" || MArch == "armv6-m")
435 // If all else failed, return the most base CPU LLVM supports.
439 /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
442 // FIXME: This is redundant with -mcpu, why does LLVM use this.
443 // FIXME: tblgen this, or kill it!
444 static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU) {
445 if (CPU == "arm7tdmi" || CPU == "arm7tdmi-s" || CPU == "arm710t" ||
446 CPU == "arm720t" || CPU == "arm9" || CPU == "arm9tdmi" ||
447 CPU == "arm920" || CPU == "arm920t" || CPU == "arm922t" ||
448 CPU == "arm940t" || CPU == "ep9312")
451 if (CPU == "arm10tdmi" || CPU == "arm1020t")
454 if (CPU == "arm9e" || CPU == "arm926ej-s" || CPU == "arm946e-s" ||
455 CPU == "arm966e-s" || CPU == "arm968e-s" || CPU == "arm10e" ||
456 CPU == "arm1020e" || CPU == "arm1022e" || CPU == "xscale" ||
460 if (CPU == "arm1136j-s" || CPU == "arm1136jf-s" || CPU == "arm1176jz-s" ||
461 CPU == "arm1176jzf-s" || CPU == "mpcorenovfp" || CPU == "mpcore")
464 if (CPU == "arm1156t2-s" || CPU == "arm1156t2f-s")
467 if (CPU == "cortex-a8" || CPU == "cortex-a9")
473 // FIXME: Move to target hook.
474 static bool isSignedCharDefault(const llvm::Triple &Triple) {
475 switch (Triple.getArch()) {
479 case llvm::Triple::arm:
480 case llvm::Triple::ppc:
481 case llvm::Triple::ppc64:
482 if (Triple.getOS() == llvm::Triple::Darwin)
486 case llvm::Triple::systemz:
491 void Clang::AddARMTargetArgs(const ArgList &Args,
492 ArgStringList &CmdArgs,
493 bool KernelOrKext) const {
494 const Driver &D = getToolChain().getDriver();
495 llvm::Triple Triple = getToolChain().getTriple();
497 // Disable movt generation, if requested.
498 #ifdef DISABLE_ARM_DARWIN_USE_MOVT
499 CmdArgs.push_back("-backend-option");
500 CmdArgs.push_back("-arm-darwin-use-movt=0");
503 // Select the ABI to use.
505 // FIXME: Support -meabi.
506 const char *ABIName = 0;
507 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
508 ABIName = A->getValue(Args);
510 // Select the default based on the platform.
511 switch(Triple.getEnvironment()) {
512 case llvm::Triple::GNUEABI:
513 ABIName = "aapcs-linux";
515 case llvm::Triple::EABI:
519 ABIName = "apcs-gnu";
522 CmdArgs.push_back("-target-abi");
523 CmdArgs.push_back(ABIName);
525 // Set the CPU based on -march= and -mcpu=.
526 CmdArgs.push_back("-target-cpu");
527 CmdArgs.push_back(getARMTargetCPU(Args, Triple));
529 // Select the float ABI as determined by -msoft-float, -mhard-float, and
531 llvm::StringRef FloatABI;
532 if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
533 options::OPT_mhard_float,
534 options::OPT_mfloat_abi_EQ)) {
535 if (A->getOption().matches(options::OPT_msoft_float))
537 else if (A->getOption().matches(options::OPT_mhard_float))
540 FloatABI = A->getValue(Args);
541 if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") {
542 D.Diag(clang::diag::err_drv_invalid_mfloat_abi)
543 << A->getAsString(Args);
549 // If unspecified, choose the default based on the platform.
550 if (FloatABI.empty()) {
551 const llvm::Triple &Triple = getToolChain().getTriple();
552 switch (Triple.getOS()) {
553 case llvm::Triple::Darwin: {
554 // Darwin defaults to "softfp" for v6 and v7.
556 // FIXME: Factor out an ARM class so we can cache the arch somewhere.
557 llvm::StringRef ArchName =
558 getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple));
559 if (ArchName.startswith("v6") || ArchName.startswith("v7"))
566 case llvm::Triple::Linux: {
567 if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUEABI) {
575 switch(Triple.getEnvironment()) {
576 case llvm::Triple::GNUEABI:
579 case llvm::Triple::EABI:
580 // EABI is always AAPCS, and if it was not marked 'hard', it's softfp
584 // Assume "soft", but warn the user we are guessing.
586 D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
592 if (FloatABI == "soft") {
593 // Floating point operations and argument passing are soft.
595 // FIXME: This changes CPP defines, we need -target-soft-float.
596 CmdArgs.push_back("-msoft-float");
597 CmdArgs.push_back("-mfloat-abi");
598 CmdArgs.push_back("soft");
599 } else if (FloatABI == "softfp") {
600 // Floating point operations are hard, but argument passing is soft.
601 CmdArgs.push_back("-mfloat-abi");
602 CmdArgs.push_back("soft");
604 // Floating point operations and argument passing are hard.
605 assert(FloatABI == "hard" && "Invalid float abi!");
606 CmdArgs.push_back("-mfloat-abi");
607 CmdArgs.push_back("hard");
610 // Set appropriate target features for floating point mode.
612 // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
613 // yet (it uses the -mfloat-abi and -msoft-float options above), and it is
614 // stripped out by the ARM target.
616 // Use software floating point operations?
617 if (FloatABI == "soft") {
618 CmdArgs.push_back("-target-feature");
619 CmdArgs.push_back("+soft-float");
622 // Use software floating point argument passing?
623 if (FloatABI != "hard") {
624 CmdArgs.push_back("-target-feature");
625 CmdArgs.push_back("+soft-float-abi");
630 // FIXME: Centralize feature selection, defaulting shouldn't be also in the
632 if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
633 llvm::StringRef FPU = A->getValue(Args);
635 // Set the target features based on the FPU.
636 if (FPU == "fpa" || FPU == "fpe2" || FPU == "fpe3" || FPU == "maverick") {
637 // Disable any default FPU support.
638 CmdArgs.push_back("-target-feature");
639 CmdArgs.push_back("-vfp2");
640 CmdArgs.push_back("-target-feature");
641 CmdArgs.push_back("-vfp3");
642 CmdArgs.push_back("-target-feature");
643 CmdArgs.push_back("-neon");
644 } else if (FPU == "vfp") {
645 CmdArgs.push_back("-target-feature");
646 CmdArgs.push_back("+vfp2");
647 } else if (FPU == "vfp3") {
648 CmdArgs.push_back("-target-feature");
649 CmdArgs.push_back("+vfp3");
650 } else if (FPU == "neon") {
651 CmdArgs.push_back("-target-feature");
652 CmdArgs.push_back("+neon");
654 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
657 // Setting -msoft-float effectively disables NEON because of the GCC
658 // implementation, although the same isn't true of VFP or VFP3.
659 if (FloatABI == "soft") {
660 CmdArgs.push_back("-target-feature");
661 CmdArgs.push_back("-neon");
664 // Kernel code has more strict alignment requirements.
666 CmdArgs.push_back("-backend-option");
667 CmdArgs.push_back("-arm-long-calls");
669 CmdArgs.push_back("-backend-option");
670 CmdArgs.push_back("-arm-strict-align");
672 // The kext linker doesn't know how to deal with movw/movt.
673 #ifndef DISABLE_ARM_DARWIN_USE_MOVT
674 CmdArgs.push_back("-backend-option");
675 CmdArgs.push_back("-arm-darwin-use-movt=0");
680 void Clang::AddMIPSTargetArgs(const ArgList &Args,
681 ArgStringList &CmdArgs) const {
682 const Driver &D = getToolChain().getDriver();
684 // Select the ABI to use.
685 const char *ABIName = 0;
686 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
687 ABIName = A->getValue(Args);
692 CmdArgs.push_back("-target-abi");
693 CmdArgs.push_back(ABIName);
695 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
696 llvm::StringRef MArch = A->getValue(Args);
697 CmdArgs.push_back("-target-cpu");
699 if ((MArch == "r2000") || (MArch == "r3000"))
700 CmdArgs.push_back("mips1");
701 else if (MArch == "r6000")
702 CmdArgs.push_back("mips2");
704 CmdArgs.push_back(Args.MakeArgString(MArch));
707 // Select the float ABI as determined by -msoft-float, -mhard-float, and
708 llvm::StringRef FloatABI;
709 if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
710 options::OPT_mhard_float)) {
711 if (A->getOption().matches(options::OPT_msoft_float))
713 else if (A->getOption().matches(options::OPT_mhard_float))
717 // If unspecified, choose the default based on the platform.
718 if (FloatABI.empty()) {
719 // Assume "soft", but warn the user we are guessing.
721 D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
724 if (FloatABI == "soft") {
725 // Floating point operations and argument passing are soft.
727 // FIXME: This changes CPP defines, we need -target-soft-float.
728 CmdArgs.push_back("-msoft-float");
730 assert(FloatABI == "hard" && "Invalid float abi!");
731 CmdArgs.push_back("-mhard-float");
735 void Clang::AddSparcTargetArgs(const ArgList &Args,
736 ArgStringList &CmdArgs) const {
737 const Driver &D = getToolChain().getDriver();
739 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
740 llvm::StringRef MArch = A->getValue(Args);
741 CmdArgs.push_back("-target-cpu");
742 CmdArgs.push_back(MArch.str().c_str());
745 // Select the float ABI as determined by -msoft-float, -mhard-float, and
746 llvm::StringRef FloatABI;
747 if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
748 options::OPT_mhard_float)) {
749 if (A->getOption().matches(options::OPT_msoft_float))
751 else if (A->getOption().matches(options::OPT_mhard_float))
755 // If unspecified, choose the default based on the platform.
756 if (FloatABI.empty()) {
757 switch (getToolChain().getTriple().getOS()) {
759 // Assume "soft", but warn the user we are guessing.
761 D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft";
766 if (FloatABI == "soft") {
767 // Floating point operations and argument passing are soft.
769 // FIXME: This changes CPP defines, we need -target-soft-float.
770 CmdArgs.push_back("-msoft-float");
771 CmdArgs.push_back("-target-feature");
772 CmdArgs.push_back("+soft-float");
774 assert(FloatABI == "hard" && "Invalid float abi!");
775 CmdArgs.push_back("-mhard-float");
779 void Clang::AddX86TargetArgs(const ArgList &Args,
780 ArgStringList &CmdArgs) const {
781 if (!Args.hasFlag(options::OPT_mred_zone,
782 options::OPT_mno_red_zone,
784 Args.hasArg(options::OPT_mkernel) ||
785 Args.hasArg(options::OPT_fapple_kext))
786 CmdArgs.push_back("-disable-red-zone");
788 if (Args.hasFlag(options::OPT_msoft_float,
789 options::OPT_mno_soft_float,
791 CmdArgs.push_back("-no-implicit-float");
793 const char *CPUName = 0;
794 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
795 if (llvm::StringRef(A->getValue(Args)) == "native") {
796 // FIXME: Reject attempts to use -march=native unless the target matches
799 // FIXME: We should also incorporate the detected target features for use
801 std::string CPU = llvm::sys::getHostCPUName();
803 CPUName = Args.MakeArgString(CPU);
805 CPUName = A->getValue(Args);
808 // Select the default CPU if none was given (or detection failed).
810 // FIXME: Need target hooks.
811 if (getToolChain().getOS().startswith("darwin")) {
812 if (getToolChain().getArch() == llvm::Triple::x86_64)
814 else if (getToolChain().getArch() == llvm::Triple::x86)
816 } else if (getToolChain().getOS().startswith("haiku")) {
817 if (getToolChain().getArch() == llvm::Triple::x86_64)
819 else if (getToolChain().getArch() == llvm::Triple::x86)
821 } else if (getToolChain().getOS().startswith("openbsd")) {
822 if (getToolChain().getArch() == llvm::Triple::x86_64)
824 else if (getToolChain().getArch() == llvm::Triple::x86)
826 } else if (getToolChain().getOS().startswith("freebsd")) {
827 if (getToolChain().getArch() == llvm::Triple::x86_64)
829 else if (getToolChain().getArch() == llvm::Triple::x86)
831 } else if (getToolChain().getOS().startswith("netbsd")) {
832 if (getToolChain().getArch() == llvm::Triple::x86_64)
834 else if (getToolChain().getArch() == llvm::Triple::x86)
837 if (getToolChain().getArch() == llvm::Triple::x86_64)
839 else if (getToolChain().getArch() == llvm::Triple::x86)
840 CPUName = "pentium4";
845 CmdArgs.push_back("-target-cpu");
846 CmdArgs.push_back(CPUName);
849 // The required algorithm here is slightly strange: the options are applied
850 // in order (so -mno-sse -msse2 disables SSE3), but any option that gets
851 // directly overridden later is ignored (so "-mno-sse -msse2 -mno-sse2 -msse"
852 // is equivalent to "-mno-sse2 -msse"). The -cc1 handling deals with the
853 // former correctly, but not the latter; handle directly-overridden
855 llvm::StringMap<unsigned> PrevFeature;
856 std::vector<const char*> Features;
857 for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group),
858 ie = Args.filtered_end(); it != ie; ++it) {
859 llvm::StringRef Name = (*it)->getOption().getName();
863 assert(Name.startswith("-m") && "Invalid feature name.");
864 Name = Name.substr(2);
866 bool IsNegative = Name.startswith("no-");
868 Name = Name.substr(3);
870 unsigned& Prev = PrevFeature[Name];
872 Features[Prev - 1] = 0;
873 Prev = Features.size() + 1;
874 Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name));
876 for (unsigned i = 0; i < Features.size(); i++) {
878 CmdArgs.push_back("-target-feature");
879 CmdArgs.push_back(Features[i]);
885 shouldUseExceptionTablesForObjCExceptions(unsigned objcABIVersion,
886 const llvm::Triple &Triple) {
887 // We use the zero-cost exception tables for Objective-C if the non-fragile
888 // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and
891 if (objcABIVersion >= 2)
894 if (Triple.getOS() != llvm::Triple::Darwin)
897 return (!Triple.isMacOSXVersionLT(10,5) &&
898 (Triple.getArch() == llvm::Triple::x86_64 ||
899 Triple.getArch() == llvm::Triple::arm));
902 /// addExceptionArgs - Adds exception related arguments to the driver command
903 /// arguments. There's a master flag, -fexceptions and also language specific
904 /// flags to enable/disable C++ and Objective-C exceptions.
905 /// This makes it possible to for example disable C++ exceptions but enable
906 /// Objective-C exceptions.
907 static void addExceptionArgs(const ArgList &Args, types::ID InputType,
908 const llvm::Triple &Triple,
909 bool KernelOrKext, bool IsRewriter,
910 unsigned objcABIVersion,
911 ArgStringList &CmdArgs) {
915 // Exceptions are enabled by default.
916 bool ExceptionsEnabled = true;
918 // This keeps track of whether exceptions were explicitly turned on or off.
919 bool DidHaveExplicitExceptionFlag = false;
921 if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
922 options::OPT_fno_exceptions)) {
923 if (A->getOption().matches(options::OPT_fexceptions))
924 ExceptionsEnabled = true;
926 ExceptionsEnabled = false;
928 DidHaveExplicitExceptionFlag = true;
931 bool ShouldUseExceptionTables = false;
933 // Exception tables and cleanups can be enabled with -fexceptions even if the
934 // language itself doesn't support exceptions.
935 if (ExceptionsEnabled && DidHaveExplicitExceptionFlag)
936 ShouldUseExceptionTables = true;
938 // Obj-C exceptions are enabled by default, regardless of -fexceptions. This
939 // is not necessarily sensible, but follows GCC.
940 if (types::isObjC(InputType) &&
941 Args.hasFlag(options::OPT_fobjc_exceptions,
942 options::OPT_fno_objc_exceptions,
944 CmdArgs.push_back("-fobjc-exceptions");
946 ShouldUseExceptionTables |=
947 shouldUseExceptionTablesForObjCExceptions(objcABIVersion, Triple);
950 if (types::isCXX(InputType)) {
951 bool CXXExceptionsEnabled = ExceptionsEnabled;
953 if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions,
954 options::OPT_fno_cxx_exceptions,
955 options::OPT_fexceptions,
956 options::OPT_fno_exceptions)) {
957 if (A->getOption().matches(options::OPT_fcxx_exceptions))
958 CXXExceptionsEnabled = true;
959 else if (A->getOption().matches(options::OPT_fno_cxx_exceptions))
960 CXXExceptionsEnabled = false;
963 if (CXXExceptionsEnabled) {
964 CmdArgs.push_back("-fcxx-exceptions");
966 ShouldUseExceptionTables = true;
970 if (ShouldUseExceptionTables)
971 CmdArgs.push_back("-fexceptions");
974 static bool ShouldDisableCFI(const ArgList &Args,
975 const ToolChain &TC) {
976 if (TC.getTriple().getOS() == llvm::Triple::Darwin) {
977 // The native darwin assembler doesn't support cfi directives, so
978 // we disable them if we think the .s file will be passed to it.
980 // FIXME: Duplicated code with ToolChains.cpp
981 // FIXME: This doesn't belong here, but ideally we will support static soon
983 bool HasStatic = (Args.hasArg(options::OPT_mkernel) ||
984 Args.hasArg(options::OPT_static) ||
985 Args.hasArg(options::OPT_fapple_kext));
986 bool IsIADefault = TC.IsIntegratedAssemblerDefault() && !HasStatic;
987 bool UseIntegratedAs = Args.hasFlag(options::OPT_integrated_as,
988 options::OPT_no_integrated_as,
990 bool UseCFI = Args.hasFlag(options::OPT_fdwarf2_cfi_asm,
991 options::OPT_fno_dwarf2_cfi_asm,
996 // For now we assume that every other assembler support CFI.
1000 /// \brief Check whether the given input tree contains any compilation actions.
1001 static bool ContainsCompileAction(const Action *A) {
1002 if (isa<CompileJobAction>(A))
1005 for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it)
1006 if (ContainsCompileAction(*it))
1012 /// \brief Check if -relax-all should be passed to the internal assembler.
1013 /// This is done by default when compiling non-assembler source with -O0.
1014 static bool UseRelaxAll(Compilation &C, const ArgList &Args) {
1015 bool RelaxDefault = true;
1017 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
1018 RelaxDefault = A->getOption().matches(options::OPT_O0);
1021 RelaxDefault = false;
1022 for (ActionList::const_iterator it = C.getActions().begin(),
1023 ie = C.getActions().end(); it != ie; ++it) {
1024 if (ContainsCompileAction(*it)) {
1025 RelaxDefault = true;
1031 return Args.hasFlag(options::OPT_mrelax_all, options::OPT_mno_relax_all,
1035 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
1036 const InputInfo &Output,
1037 const InputInfoList &Inputs,
1038 const ArgList &Args,
1039 const char *LinkingOutput) const {
1040 bool KernelOrKext = Args.hasArg(options::OPT_mkernel,
1041 options::OPT_fapple_kext);
1042 const Driver &D = getToolChain().getDriver();
1043 ArgStringList CmdArgs;
1045 assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
1047 // Invoke ourselves in -cc1 mode.
1049 // FIXME: Implement custom jobs for internal actions.
1050 CmdArgs.push_back("-cc1");
1052 // Add the "effective" target triple.
1053 CmdArgs.push_back("-triple");
1054 std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
1055 CmdArgs.push_back(Args.MakeArgString(TripleStr));
1057 // Select the appropriate action.
1058 bool IsRewriter = false;
1059 if (isa<AnalyzeJobAction>(JA)) {
1060 assert(JA.getType() == types::TY_Plist && "Invalid output type.");
1061 CmdArgs.push_back("-analyze");
1062 } else if (isa<PreprocessJobAction>(JA)) {
1063 if (Output.getType() == types::TY_Dependencies)
1064 CmdArgs.push_back("-Eonly");
1066 CmdArgs.push_back("-E");
1067 } else if (isa<AssembleJobAction>(JA)) {
1068 CmdArgs.push_back("-emit-obj");
1070 if (UseRelaxAll(C, Args))
1071 CmdArgs.push_back("-mrelax-all");
1073 // When using an integrated assembler, translate -Wa, and -Xassembler
1075 for (arg_iterator it = Args.filtered_begin(options::OPT_Wa_COMMA,
1076 options::OPT_Xassembler),
1077 ie = Args.filtered_end(); it != ie; ++it) {
1081 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
1082 llvm::StringRef Value = A->getValue(Args, i);
1084 if (Value == "-force_cpusubtype_ALL") {
1085 // Do nothing, this is the default and we don't support anything else.
1086 } else if (Value == "-L") {
1087 CmdArgs.push_back("-msave-temp-labels");
1088 } else if (Value == "--fatal-warnings") {
1089 CmdArgs.push_back("-mllvm");
1090 CmdArgs.push_back("-fatal-assembler-warnings");
1091 } else if (Value == "--noexecstack") {
1092 CmdArgs.push_back("-mnoexecstack");
1094 D.Diag(clang::diag::err_drv_unsupported_option_argument)
1095 << A->getOption().getName() << Value;
1100 // Also ignore explicit -force_cpusubtype_ALL option.
1101 (void) Args.hasArg(options::OPT_force__cpusubtype__ALL);
1102 } else if (isa<PrecompileJobAction>(JA)) {
1103 // Use PCH if the user requested it.
1104 bool UsePCH = D.CCCUsePCH;
1107 CmdArgs.push_back("-emit-pch");
1109 CmdArgs.push_back("-emit-pth");
1111 assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool.");
1113 if (JA.getType() == types::TY_Nothing) {
1114 CmdArgs.push_back("-fsyntax-only");
1115 } else if (JA.getType() == types::TY_LLVM_IR ||
1116 JA.getType() == types::TY_LTO_IR) {
1117 CmdArgs.push_back("-emit-llvm");
1118 } else if (JA.getType() == types::TY_LLVM_BC ||
1119 JA.getType() == types::TY_LTO_BC) {
1120 CmdArgs.push_back("-emit-llvm-bc");
1121 } else if (JA.getType() == types::TY_PP_Asm) {
1122 CmdArgs.push_back("-S");
1123 } else if (JA.getType() == types::TY_AST) {
1124 CmdArgs.push_back("-emit-pch");
1125 } else if (JA.getType() == types::TY_RewrittenObjC) {
1126 CmdArgs.push_back("-rewrite-objc");
1129 assert(JA.getType() == types::TY_PP_Asm &&
1130 "Unexpected output type!");
1134 // The make clang go fast button.
1135 CmdArgs.push_back("-disable-free");
1137 // Disable the verification pass in -asserts builds.
1139 CmdArgs.push_back("-disable-llvm-verifier");
1142 // Set the main file name, so that debug info works even with
1144 CmdArgs.push_back("-main-file-name");
1145 CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs));
1147 // Some flags which affect the language (via preprocessor
1148 // defines). See darwin::CC1::AddCPPArgs.
1149 if (Args.hasArg(options::OPT_static))
1150 CmdArgs.push_back("-static-define");
1152 if (isa<AnalyzeJobAction>(JA)) {
1153 // Enable region store model by default.
1154 CmdArgs.push_back("-analyzer-store=region");
1156 // Treat blocks as analysis entry points.
1157 CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks");
1159 CmdArgs.push_back("-analyzer-eagerly-assume");
1161 // Add default argument set.
1162 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
1163 CmdArgs.push_back("-analyzer-checker=core");
1164 CmdArgs.push_back("-analyzer-checker=deadcode");
1165 CmdArgs.push_back("-analyzer-checker=security");
1167 if (getToolChain().getTriple().getOS() != llvm::Triple::Win32)
1168 CmdArgs.push_back("-analyzer-checker=unix");
1170 if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple)
1171 CmdArgs.push_back("-analyzer-checker=osx");
1174 // Set the output format. The default is plist, for (lame) historical
1176 CmdArgs.push_back("-analyzer-output");
1177 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
1178 CmdArgs.push_back(A->getValue(Args));
1180 CmdArgs.push_back("plist");
1182 // Disable the presentation of standard compiler warnings when
1183 // using --analyze. We only want to show static analyzer diagnostics
1184 // or frontend errors.
1185 CmdArgs.push_back("-w");
1187 // Add -Xanalyzer arguments when running as analyzer.
1188 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
1191 CheckCodeGenerationOptions(D, Args);
1193 // Perform argument translation for LLVM backend. This
1194 // takes some care in reconciling with llvm-gcc. The
1195 // issue is that llvm-gcc translates these options based on
1196 // the values in cc1, whereas we are processing based on
1197 // the driver arguments.
1199 // This comes from the default translation the driver + cc1
1200 // would do to enable flag_pic.
1202 // FIXME: Centralize this code.
1203 bool PICEnabled = (Args.hasArg(options::OPT_fPIC) ||
1204 Args.hasArg(options::OPT_fpic) ||
1205 Args.hasArg(options::OPT_fPIE) ||
1206 Args.hasArg(options::OPT_fpie));
1207 bool PICDisabled = (Args.hasArg(options::OPT_mkernel) ||
1208 Args.hasArg(options::OPT_static));
1209 const char *Model = getToolChain().GetForcedPicModel();
1211 if (Args.hasArg(options::OPT_mdynamic_no_pic))
1212 Model = "dynamic-no-pic";
1213 else if (PICDisabled)
1215 else if (PICEnabled)
1218 Model = getToolChain().GetDefaultRelocationModel();
1220 if (llvm::StringRef(Model) != "pic") {
1221 CmdArgs.push_back("-mrelocation-model");
1222 CmdArgs.push_back(Model);
1225 // Infer the __PIC__ value.
1227 // FIXME: This isn't quite right on Darwin, which always sets
1229 if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) {
1230 CmdArgs.push_back("-pic-level");
1231 CmdArgs.push_back(Args.hasArg(options::OPT_fPIC) ? "2" : "1");
1233 if (!Args.hasFlag(options::OPT_fmerge_all_constants,
1234 options::OPT_fno_merge_all_constants))
1235 CmdArgs.push_back("-fno-merge-all-constants");
1237 // LLVM Code Generator Options.
1239 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
1240 CmdArgs.push_back("-mregparm");
1241 CmdArgs.push_back(A->getValue(Args));
1244 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false))
1245 CmdArgs.push_back("-mrtd");
1247 // FIXME: Set --enable-unsafe-fp-math.
1248 if (Args.hasFlag(options::OPT_fno_omit_frame_pointer,
1249 options::OPT_fomit_frame_pointer))
1250 CmdArgs.push_back("-mdisable-fp-elim");
1251 if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
1252 options::OPT_fno_zero_initialized_in_bss))
1253 CmdArgs.push_back("-mno-zero-initialized-in-bss");
1254 if (!Args.hasFlag(options::OPT_fstrict_aliasing,
1255 options::OPT_fno_strict_aliasing,
1256 getToolChain().IsStrictAliasingDefault()))
1257 CmdArgs.push_back("-relaxed-aliasing");
1259 // Decide whether to use verbose asm. Verbose assembly is the default on
1260 // toolchains which have the integrated assembler on by default.
1261 bool IsVerboseAsmDefault = getToolChain().IsIntegratedAssemblerDefault();
1262 if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
1263 IsVerboseAsmDefault) ||
1264 Args.hasArg(options::OPT_dA))
1265 CmdArgs.push_back("-masm-verbose");
1267 if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
1268 CmdArgs.push_back("-mdebug-pass");
1269 CmdArgs.push_back("Structure");
1271 if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
1272 CmdArgs.push_back("-mdebug-pass");
1273 CmdArgs.push_back("Arguments");
1276 // Enable -mconstructor-aliases except on darwin, where we have to
1277 // work around a linker bug; see <rdar://problem/7651567>.
1278 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin)
1279 CmdArgs.push_back("-mconstructor-aliases");
1281 // Darwin's kernel doesn't support guard variables; just die if we
1284 getToolChain().getTriple().getOS() == llvm::Triple::Darwin)
1285 CmdArgs.push_back("-fforbid-guard-variables");
1287 if (Args.hasArg(options::OPT_mms_bitfields)) {
1288 CmdArgs.push_back("-mms-bitfields");
1291 // This is a coarse approximation of what llvm-gcc actually does, both
1292 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
1293 // complicated ways.
1294 bool AsynchronousUnwindTables =
1295 Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
1296 options::OPT_fno_asynchronous_unwind_tables,
1297 getToolChain().IsUnwindTablesDefault() &&
1299 if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
1300 AsynchronousUnwindTables))
1301 CmdArgs.push_back("-munwind-tables");
1303 if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
1304 CmdArgs.push_back("-mlimit-float-precision");
1305 CmdArgs.push_back(A->getValue(Args));
1308 // FIXME: Handle -mtune=.
1309 (void) Args.hasArg(options::OPT_mtune_EQ);
1311 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
1312 CmdArgs.push_back("-mcode-model");
1313 CmdArgs.push_back(A->getValue(Args));
1316 // Add target specific cpu and features flags.
1317 switch(getToolChain().getTriple().getArch()) {
1321 case llvm::Triple::arm:
1322 case llvm::Triple::thumb:
1323 AddARMTargetArgs(Args, CmdArgs, KernelOrKext);
1326 case llvm::Triple::mips:
1327 case llvm::Triple::mipsel:
1328 AddMIPSTargetArgs(Args, CmdArgs);
1331 case llvm::Triple::sparc:
1332 AddSparcTargetArgs(Args, CmdArgs);
1335 case llvm::Triple::x86:
1336 case llvm::Triple::x86_64:
1337 AddX86TargetArgs(Args, CmdArgs);
1341 // Pass the linker version in use.
1342 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
1343 CmdArgs.push_back("-target-linker-version");
1344 CmdArgs.push_back(A->getValue(Args));
1347 // -mno-omit-leaf-frame-pointer is the default on Darwin.
1348 if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
1349 options::OPT_mno_omit_leaf_frame_pointer,
1350 getToolChain().getTriple().getOS() != llvm::Triple::Darwin))
1351 CmdArgs.push_back("-momit-leaf-frame-pointer");
1353 // -fno-math-errno is default.
1354 if (Args.hasFlag(options::OPT_fmath_errno,
1355 options::OPT_fno_math_errno,
1357 CmdArgs.push_back("-fmath-errno");
1359 // Explicitly error on some things we know we don't support and can't just
1361 types::ID InputType = Inputs[0].getType();
1362 if (!Args.hasArg(options::OPT_fallow_unsupported)) {
1364 if ((Unsupported = Args.getLastArg(options::OPT_iframework)))
1365 D.Diag(clang::diag::err_drv_clang_unsupported)
1366 << Unsupported->getOption().getName();
1368 if (types::isCXX(InputType) &&
1369 getToolChain().getTriple().getOS() == llvm::Triple::Darwin &&
1370 getToolChain().getTriple().getArch() == llvm::Triple::x86) {
1371 if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)))
1372 D.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
1373 << Unsupported->getOption().getName();
1377 Args.AddAllArgs(CmdArgs, options::OPT_v);
1378 Args.AddLastArg(CmdArgs, options::OPT_H);
1379 if (D.CCPrintHeaders) {
1380 CmdArgs.push_back("-header-include-file");
1381 CmdArgs.push_back(D.CCPrintHeadersFilename ?
1382 D.CCPrintHeadersFilename : "-");
1384 Args.AddLastArg(CmdArgs, options::OPT_P);
1385 Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
1387 if (D.CCLogDiagnostics) {
1388 CmdArgs.push_back("-diagnostic-log-file");
1389 CmdArgs.push_back(D.CCLogDiagnosticsFilename ?
1390 D.CCLogDiagnosticsFilename : "-");
1393 // Special case debug options to only pass -g to clang. This is
1395 Args.ClaimAllArgs(options::OPT_g_Group);
1396 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
1397 if (!A->getOption().matches(options::OPT_g0))
1398 CmdArgs.push_back("-g");
1400 Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections);
1401 Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections);
1403 Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
1405 if (Args.hasArg(options::OPT_ftest_coverage) ||
1406 Args.hasArg(options::OPT_coverage))
1407 CmdArgs.push_back("-femit-coverage-notes");
1408 if (Args.hasArg(options::OPT_fprofile_arcs) ||
1409 Args.hasArg(options::OPT_coverage))
1410 CmdArgs.push_back("-femit-coverage-data");
1412 if (C.getArgs().hasArg(options::OPT_c) ||
1413 C.getArgs().hasArg(options::OPT_S)) {
1414 if (Output.isFilename()) {
1415 CmdArgs.push_back("-coverage-file");
1416 CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
1420 Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
1421 Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
1422 Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
1424 // Pass the path to compiler resource files.
1425 CmdArgs.push_back("-resource-dir");
1426 CmdArgs.push_back(D.ResourceDir.c_str());
1428 Args.AddLastArg(CmdArgs, options::OPT_working_directory);
1430 if (!Args.hasArg(options::OPT_fno_objc_arc)) {
1431 if (const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
1432 options::OPT_ccc_arcmt_modify,
1433 options::OPT_ccc_arcmt_migrate)) {
1434 switch (A->getOption().getID()) {
1436 llvm_unreachable("missed a case");
1437 case options::OPT_ccc_arcmt_check:
1438 CmdArgs.push_back("-arcmt-check");
1440 case options::OPT_ccc_arcmt_modify:
1441 CmdArgs.push_back("-arcmt-modify");
1443 case options::OPT_ccc_arcmt_migrate:
1444 CmdArgs.push_back("-arcmt-migrate");
1445 CmdArgs.push_back("-arcmt-migrate-directory");
1446 CmdArgs.push_back(A->getValue(Args));
1452 // Add preprocessing options like -I, -D, etc. if we are using the
1455 // FIXME: Support -fpreprocessed
1456 if (types::getPreprocessedType(InputType) != types::TY_INVALID)
1457 AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs);
1459 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1461 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
1462 if (A->getOption().matches(options::OPT_O4))
1463 CmdArgs.push_back("-O3");
1464 else if (A->getOption().matches(options::OPT_O) &&
1465 A->getValue(Args)[0] == '\0')
1466 CmdArgs.push_back("-O2");
1468 A->render(Args, CmdArgs);
1471 Args.AddAllArgs(CmdArgs, options::OPT_W_Group);
1472 Args.AddLastArg(CmdArgs, options::OPT_pedantic);
1473 Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
1474 Args.AddLastArg(CmdArgs, options::OPT_w);
1476 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1477 // (-ansi is equivalent to -std=c89).
1479 // If a std is supplied, only add -trigraphs if it follows the
1481 if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
1482 if (Std->getOption().matches(options::OPT_ansi))
1483 if (types::isCXX(InputType))
1484 CmdArgs.push_back("-std=c++98");
1486 CmdArgs.push_back("-std=c89");
1488 Std->render(Args, CmdArgs);
1490 if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
1491 options::OPT_trigraphs))
1493 A->render(Args, CmdArgs);
1495 // Honor -std-default.
1497 // FIXME: Clang doesn't correctly handle -std= when the input language
1498 // doesn't match. For the time being just ignore this for C++ inputs;
1499 // eventually we want to do all the standard defaulting here instead of
1500 // splitting it between the driver and clang -cc1.
1501 if (!types::isCXX(InputType))
1502 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
1503 "-std=", /*Joined=*/true);
1504 Args.AddLastArg(CmdArgs, options::OPT_trigraphs);
1507 // Map the bizarre '-Wwrite-strings' flag to a more sensible
1508 // '-fconst-strings'; this better indicates its actual behavior.
1509 if (Args.hasFlag(options::OPT_Wwrite_strings, options::OPT_Wno_write_strings,
1511 // For perfect compatibility with GCC, we do this even in the presence of
1512 // '-w'. This flag names something other than a warning for GCC.
1513 CmdArgs.push_back("-fconst-strings");
1516 // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active
1517 // during C++ compilation, which it is by default. GCC keeps this define even
1518 // in the presence of '-w', match this behavior bug-for-bug.
1519 if (types::isCXX(InputType) &&
1520 Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
1522 CmdArgs.push_back("-fdeprecated-macro");
1525 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1526 if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
1527 if (Asm->getOption().matches(options::OPT_fasm))
1528 CmdArgs.push_back("-fgnu-keywords");
1530 CmdArgs.push_back("-fno-gnu-keywords");
1533 if (ShouldDisableCFI(Args, getToolChain()))
1534 CmdArgs.push_back("-fno-dwarf2-cfi-asm");
1536 if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
1537 CmdArgs.push_back("-ftemplate-depth");
1538 CmdArgs.push_back(A->getValue(Args));
1541 if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
1542 options::OPT_Wlarge_by_value_copy_def)) {
1543 CmdArgs.push_back("-Wlarge-by-value-copy");
1544 if (A->getNumValues())
1545 CmdArgs.push_back(A->getValue(Args));
1547 CmdArgs.push_back("64"); // default value for -Wlarge-by-value-copy.
1550 if (Args.hasArg(options::OPT__relocatable_pch))
1551 CmdArgs.push_back("-relocatable-pch");
1553 if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
1554 CmdArgs.push_back("-fconstant-string-class");
1555 CmdArgs.push_back(A->getValue(Args));
1558 if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
1559 CmdArgs.push_back("-ftabstop");
1560 CmdArgs.push_back(A->getValue(Args));
1563 CmdArgs.push_back("-ferror-limit");
1564 if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
1565 CmdArgs.push_back(A->getValue(Args));
1567 CmdArgs.push_back("19");
1569 if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) {
1570 CmdArgs.push_back("-fmacro-backtrace-limit");
1571 CmdArgs.push_back(A->getValue(Args));
1574 if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) {
1575 CmdArgs.push_back("-ftemplate-backtrace-limit");
1576 CmdArgs.push_back(A->getValue(Args));
1579 // Pass -fmessage-length=.
1580 CmdArgs.push_back("-fmessage-length");
1581 if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
1582 CmdArgs.push_back(A->getValue(Args));
1584 // If -fmessage-length=N was not specified, determine whether this is a
1585 // terminal and, if so, implicitly define -fmessage-length appropriately.
1586 unsigned N = llvm::sys::Process::StandardErrColumns();
1587 CmdArgs.push_back(Args.MakeArgString(llvm::Twine(N)));
1590 if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ)) {
1591 CmdArgs.push_back("-fvisibility");
1592 CmdArgs.push_back(A->getValue(Args));
1595 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden);
1597 // -fhosted is default.
1598 if (KernelOrKext || Args.hasFlag(options::OPT_ffreestanding,
1599 options::OPT_fhosted,
1601 CmdArgs.push_back("-ffreestanding");
1603 // Forward -f (flag) options which we can pass directly.
1604 Args.AddLastArg(CmdArgs, options::OPT_fcatch_undefined_behavior);
1605 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
1606 Args.AddLastArg(CmdArgs, options::OPT_fformat_extensions);
1607 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
1608 Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info);
1609 if (getToolChain().SupportsProfiling())
1610 Args.AddLastArg(CmdArgs, options::OPT_pg);
1612 // -flax-vector-conversions is default.
1613 if (!Args.hasFlag(options::OPT_flax_vector_conversions,
1614 options::OPT_fno_lax_vector_conversions))
1615 CmdArgs.push_back("-fno-lax-vector-conversions");
1617 if (Args.getLastArg(options::OPT_fapple_kext))
1618 CmdArgs.push_back("-fapple-kext");
1620 Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
1621 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
1622 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
1623 Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
1624 Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
1626 if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
1627 CmdArgs.push_back("-ftrapv-handler");
1628 CmdArgs.push_back(A->getValue(Args));
1631 // Forward -ftrap_function= options to the backend.
1632 if (Arg *A = Args.getLastArg(options::OPT_ftrap_function_EQ)) {
1633 llvm::StringRef FuncName = A->getValue(Args);
1634 CmdArgs.push_back("-backend-option");
1635 CmdArgs.push_back(Args.MakeArgString("-trap-func=" + FuncName));
1638 // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
1639 // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
1640 if (Arg *A = Args.getLastArg(options::OPT_fwrapv,
1641 options::OPT_fno_wrapv)) {
1642 if (A->getOption().matches(options::OPT_fwrapv))
1643 CmdArgs.push_back("-fwrapv");
1644 } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
1645 options::OPT_fno_strict_overflow)) {
1646 if (A->getOption().matches(options::OPT_fno_strict_overflow))
1647 CmdArgs.push_back("-fwrapv");
1649 Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
1650 Args.AddLastArg(CmdArgs, options::OPT_funroll_loops);
1652 Args.AddLastArg(CmdArgs, options::OPT_pthread);
1654 // -stack-protector=0 is default.
1655 unsigned StackProtectorLevel = 0;
1656 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
1657 options::OPT_fstack_protector_all,
1658 options::OPT_fstack_protector)) {
1659 if (A->getOption().matches(options::OPT_fstack_protector))
1660 StackProtectorLevel = 1;
1661 else if (A->getOption().matches(options::OPT_fstack_protector_all))
1662 StackProtectorLevel = 2;
1664 StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel();
1665 if (StackProtectorLevel) {
1666 CmdArgs.push_back("-stack-protector");
1667 CmdArgs.push_back(Args.MakeArgString(llvm::Twine(StackProtectorLevel)));
1670 // Translate -mstackrealign
1671 if (Args.hasArg(options::OPT_mstackrealign)) {
1672 CmdArgs.push_back("-backend-option");
1673 CmdArgs.push_back("-force-align-stack");
1676 // Forward -f options with positive and negative forms; we translate
1679 if (Args.hasArg(options::OPT_mkernel)) {
1680 if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType))
1681 CmdArgs.push_back("-fapple-kext");
1682 if (!Args.hasArg(options::OPT_fbuiltin))
1683 CmdArgs.push_back("-fno-builtin");
1685 // -fbuiltin is default.
1686 else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
1687 CmdArgs.push_back("-fno-builtin");
1689 if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
1690 options::OPT_fno_assume_sane_operator_new))
1691 CmdArgs.push_back("-fno-assume-sane-operator-new");
1693 // -fblocks=0 is default.
1694 if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
1695 getToolChain().IsBlocksDefault()) ||
1696 (Args.hasArg(options::OPT_fgnu_runtime) &&
1697 Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
1698 !Args.hasArg(options::OPT_fno_blocks))) {
1699 CmdArgs.push_back("-fblocks");
1702 // -faccess-control is default.
1703 if (Args.hasFlag(options::OPT_fno_access_control,
1704 options::OPT_faccess_control,
1706 CmdArgs.push_back("-fno-access-control");
1708 // -felide-constructors is the default.
1709 if (Args.hasFlag(options::OPT_fno_elide_constructors,
1710 options::OPT_felide_constructors,
1712 CmdArgs.push_back("-fno-elide-constructors");
1714 // -frtti is default.
1716 !Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
1717 CmdArgs.push_back("-fno-rtti");
1719 // -fshort-enums=0 is default.
1720 // FIXME: Are there targers where -fshort-enums is on by default ?
1721 if (Args.hasFlag(options::OPT_fshort_enums,
1722 options::OPT_fno_short_enums, false))
1723 CmdArgs.push_back("-fshort-enums");
1725 // -fsigned-char is default.
1726 if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char,
1727 isSignedCharDefault(getToolChain().getTriple())))
1728 CmdArgs.push_back("-fno-signed-char");
1730 // -fthreadsafe-static is default.
1731 if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
1732 options::OPT_fno_threadsafe_statics))
1733 CmdArgs.push_back("-fno-threadsafe-statics");
1735 // -fuse-cxa-atexit is default.
1737 !Args.hasFlag(options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
1738 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin &&
1739 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32))
1740 CmdArgs.push_back("-fno-use-cxa-atexit");
1742 // -fms-extensions=0 is default.
1743 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
1744 getToolChain().getTriple().getOS() == llvm::Triple::Win32))
1745 CmdArgs.push_back("-fms-extensions");
1747 // -fmsc-version=1300 is default.
1748 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
1749 getToolChain().getTriple().getOS() == llvm::Triple::Win32) ||
1750 Args.hasArg(options::OPT_fmsc_version)) {
1751 llvm::StringRef msc_ver = Args.getLastArgValue(options::OPT_fmsc_version);
1752 if (msc_ver.empty())
1753 CmdArgs.push_back("-fmsc-version=1300");
1755 CmdArgs.push_back(Args.MakeArgString("-fmsc-version=" + msc_ver));
1759 // -fborland-extensions=0 is default.
1760 if (Args.hasFlag(options::OPT_fborland_extensions,
1761 options::OPT_fno_borland_extensions, false))
1762 CmdArgs.push_back("-fborland-extensions");
1764 // -fno-delayed-template-parsing is default.
1765 if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
1766 options::OPT_fno_delayed_template_parsing,
1768 CmdArgs.push_back("-fdelayed-template-parsing");
1770 // -fgnu-keywords default varies depending on language; only pass if
1772 if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords,
1773 options::OPT_fno_gnu_keywords))
1774 A->render(Args, CmdArgs);
1776 if (Args.hasFlag(options::OPT_fgnu89_inline,
1777 options::OPT_fno_gnu89_inline,
1779 CmdArgs.push_back("-fgnu89-inline");
1781 // -fobjc-nonfragile-abi=0 is default.
1782 ObjCRuntime objCRuntime;
1783 unsigned objcABIVersion = 0;
1784 if (types::isObjC(InputType)) {
1785 bool NeXTRuntimeIsDefault
1786 = (IsRewriter || getToolChain().getTriple().isOSDarwin());
1787 if (Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
1788 NeXTRuntimeIsDefault)) {
1789 objCRuntime.setKind(ObjCRuntime::NeXT);
1791 CmdArgs.push_back("-fgnu-runtime");
1792 objCRuntime.setKind(ObjCRuntime::GNU);
1794 getToolChain().configureObjCRuntime(objCRuntime);
1795 if (objCRuntime.HasARC)
1796 CmdArgs.push_back("-fobjc-runtime-has-arc");
1797 if (objCRuntime.HasWeak)
1798 CmdArgs.push_back("-fobjc-runtime-has-weak");
1799 if (objCRuntime.HasTerminate)
1800 CmdArgs.push_back("-fobjc-runtime-has-terminate");
1802 // Compute the Objective-C ABI "version" to use. Version numbers are
1803 // slightly confusing for historical reasons:
1804 // 1 - Traditional "fragile" ABI
1805 // 2 - Non-fragile ABI, version 1
1806 // 3 - Non-fragile ABI, version 2
1808 // If -fobjc-abi-version= is present, use that to set the version.
1809 if (Arg *A = Args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
1810 if (llvm::StringRef(A->getValue(Args)) == "1")
1812 else if (llvm::StringRef(A->getValue(Args)) == "2")
1814 else if (llvm::StringRef(A->getValue(Args)) == "3")
1817 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
1819 // Otherwise, determine if we are using the non-fragile ABI.
1820 if (Args.hasFlag(options::OPT_fobjc_nonfragile_abi,
1821 options::OPT_fno_objc_nonfragile_abi,
1822 getToolChain().IsObjCNonFragileABIDefault())) {
1823 // Determine the non-fragile ABI version to use.
1824 #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
1825 unsigned NonFragileABIVersion = 1;
1827 unsigned NonFragileABIVersion = 2;
1830 if (Arg *A = Args.getLastArg(
1831 options::OPT_fobjc_nonfragile_abi_version_EQ)) {
1832 if (llvm::StringRef(A->getValue(Args)) == "1")
1833 NonFragileABIVersion = 1;
1834 else if (llvm::StringRef(A->getValue(Args)) == "2")
1835 NonFragileABIVersion = 2;
1837 D.Diag(clang::diag::err_drv_clang_unsupported)
1838 << A->getAsString(Args);
1841 objcABIVersion = 1 + NonFragileABIVersion;
1847 if (objcABIVersion == 2 || objcABIVersion == 3) {
1848 CmdArgs.push_back("-fobjc-nonfragile-abi");
1850 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1851 // legacy is the default.
1852 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
1853 options::OPT_fno_objc_legacy_dispatch,
1854 getToolChain().IsObjCLegacyDispatchDefault())) {
1855 if (getToolChain().UseObjCMixedDispatch())
1856 CmdArgs.push_back("-fobjc-dispatch-method=mixed");
1858 CmdArgs.push_back("-fobjc-dispatch-method=non-legacy");
1862 // FIXME: Don't expose -fobjc-default-synthesize-properties as a top-level
1863 // driver flag yet. This feature is still under active development
1864 // and shouldn't be exposed as a user visible feature (which may change).
1865 // Clang still supports this as a -cc1 option for development and testing.
1867 // -fobjc-default-synthesize-properties=0 is default.
1868 if (Args.hasFlag(options::OPT_fobjc_default_synthesize_properties,
1869 options::OPT_fno_objc_default_synthesize_properties,
1870 getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
1871 CmdArgs.push_back("-fobjc-default-synthesize-properties");
1876 // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc.
1877 // NOTE: This logic is duplicated in ToolChains.cpp.
1878 bool ARC = isObjCAutoRefCount(Args);
1880 CmdArgs.push_back("-fobjc-arc");
1882 // Allow the user to enable full exceptions code emission.
1883 // We define off for Objective-CC, on for Objective-C++.
1884 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
1885 options::OPT_fno_objc_arc_exceptions,
1886 /*default*/ types::isCXX(InputType)))
1887 CmdArgs.push_back("-fobjc-arc-exceptions");
1890 // -fobjc-infer-related-result-type is the default, except in the Objective-C
1893 CmdArgs.push_back("-fno-objc-infer-related-result-type");
1895 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1896 // takes precedence.
1897 const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only);
1899 GCArg = Args.getLastArg(options::OPT_fobjc_gc);
1902 D.Diag(clang::diag::err_drv_objc_gc_arr)
1903 << GCArg->getAsString(Args);
1904 } else if (getToolChain().SupportsObjCGC()) {
1905 GCArg->render(Args, CmdArgs);
1907 // FIXME: We should move this to a hard error.
1908 D.Diag(clang::diag::warn_drv_objc_gc_unsupported)
1909 << GCArg->getAsString(Args);
1913 // Add exception args.
1914 addExceptionArgs(Args, InputType, getToolChain().getTriple(),
1915 KernelOrKext, IsRewriter, objcABIVersion, CmdArgs);
1917 if (getToolChain().UseSjLjExceptions())
1918 CmdArgs.push_back("-fsjlj-exceptions");
1920 // C++ "sane" operator new.
1921 if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
1922 options::OPT_fno_assume_sane_operator_new))
1923 CmdArgs.push_back("-fno-assume-sane-operator-new");
1925 // -fconstant-cfstrings is default, and may be subject to argument translation
1927 if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
1928 options::OPT_fno_constant_cfstrings) ||
1929 !Args.hasFlag(options::OPT_mconstant_cfstrings,
1930 options::OPT_mno_constant_cfstrings))
1931 CmdArgs.push_back("-fno-constant-cfstrings");
1933 // -fshort-wchar default varies depending on platform; only
1934 // pass if specified.
1935 if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar))
1936 A->render(Args, CmdArgs);
1938 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1939 // happened to translate to -mpascal-strings, we want to back translate here.
1941 // FIXME: This is gross; that translation should be pulled from the
1943 if (Args.hasFlag(options::OPT_fpascal_strings,
1944 options::OPT_fno_pascal_strings,
1946 Args.hasFlag(options::OPT_mpascal_strings,
1947 options::OPT_mno_pascal_strings,
1949 CmdArgs.push_back("-fpascal-strings");
1951 if (Args.hasArg(options::OPT_mkernel) ||
1952 Args.hasArg(options::OPT_fapple_kext)) {
1953 if (!Args.hasArg(options::OPT_fcommon))
1954 CmdArgs.push_back("-fno-common");
1956 // -fcommon is default, only pass non-default.
1957 else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
1958 CmdArgs.push_back("-fno-common");
1960 // -fsigned-bitfields is default, and clang doesn't yet support
1961 // -funsigned-bitfields.
1962 if (!Args.hasFlag(options::OPT_fsigned_bitfields,
1963 options::OPT_funsigned_bitfields))
1964 D.Diag(clang::diag::warn_drv_clang_unsupported)
1965 << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
1967 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1968 if (!Args.hasFlag(options::OPT_ffor_scope,
1969 options::OPT_fno_for_scope))
1970 D.Diag(clang::diag::err_drv_clang_unsupported)
1971 << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
1973 // -fcaret-diagnostics is default.
1974 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
1975 options::OPT_fno_caret_diagnostics, true))
1976 CmdArgs.push_back("-fno-caret-diagnostics");
1978 // -fdiagnostics-fixit-info is default, only pass non-default.
1979 if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info,
1980 options::OPT_fno_diagnostics_fixit_info))
1981 CmdArgs.push_back("-fno-diagnostics-fixit-info");
1983 // Enable -fdiagnostics-show-name by default.
1984 if (Args.hasFlag(options::OPT_fdiagnostics_show_name,
1985 options::OPT_fno_diagnostics_show_name, false))
1986 CmdArgs.push_back("-fdiagnostics-show-name");
1988 // Enable -fdiagnostics-show-option by default.
1989 if (Args.hasFlag(options::OPT_fdiagnostics_show_option,
1990 options::OPT_fno_diagnostics_show_option))
1991 CmdArgs.push_back("-fdiagnostics-show-option");
1994 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
1995 CmdArgs.push_back("-fdiagnostics-show-category");
1996 CmdArgs.push_back(A->getValue(Args));
2000 Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
2001 CmdArgs.push_back("-fdiagnostics-format");
2002 CmdArgs.push_back(A->getValue(Args));
2005 if (Arg *A = Args.getLastArg(
2006 options::OPT_fdiagnostics_show_note_include_stack,
2007 options::OPT_fno_diagnostics_show_note_include_stack)) {
2008 if (A->getOption().matches(
2009 options::OPT_fdiagnostics_show_note_include_stack))
2010 CmdArgs.push_back("-fdiagnostics-show-note-include-stack");
2012 CmdArgs.push_back("-fno-diagnostics-show-note-include-stack");
2015 // Color diagnostics are the default, unless the terminal doesn't support
2017 if (Args.hasFlag(options::OPT_fcolor_diagnostics,
2018 options::OPT_fno_color_diagnostics,
2019 llvm::sys::Process::StandardErrHasColors()))
2020 CmdArgs.push_back("-fcolor-diagnostics");
2022 if (!Args.hasFlag(options::OPT_fshow_source_location,
2023 options::OPT_fno_show_source_location))
2024 CmdArgs.push_back("-fno-show-source-location");
2026 if (!Args.hasFlag(options::OPT_fshow_column,
2027 options::OPT_fno_show_column,
2029 CmdArgs.push_back("-fno-show-column");
2031 if (!Args.hasFlag(options::OPT_fspell_checking,
2032 options::OPT_fno_spell_checking))
2033 CmdArgs.push_back("-fno-spell-checking");
2036 // Silently ignore -fasm-blocks for now.
2037 (void) Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks,
2040 if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ))
2041 A->render(Args, CmdArgs);
2043 // -fdollars-in-identifiers default varies depending on platform and
2044 // language; only pass if specified.
2045 if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
2046 options::OPT_fno_dollars_in_identifiers)) {
2047 if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
2048 CmdArgs.push_back("-fdollars-in-identifiers");
2050 CmdArgs.push_back("-fno-dollars-in-identifiers");
2053 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
2054 // practical purposes.
2055 if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time,
2056 options::OPT_fno_unit_at_a_time)) {
2057 if (A->getOption().matches(options::OPT_fno_unit_at_a_time))
2058 D.Diag(clang::diag::warn_drv_clang_unsupported) << A->getAsString(Args);
2061 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
2063 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
2065 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin &&
2066 (getToolChain().getTriple().getArch() == llvm::Triple::arm ||
2067 getToolChain().getTriple().getArch() == llvm::Triple::thumb)) {
2068 if (!Args.hasArg(options::OPT_fbuiltin_strcat))
2069 CmdArgs.push_back("-fno-builtin-strcat");
2070 if (!Args.hasArg(options::OPT_fbuiltin_strcpy))
2071 CmdArgs.push_back("-fno-builtin-strcpy");
2075 // Only allow -traditional or -traditional-cpp outside in preprocessing modes.
2076 if (Arg *A = Args.getLastArg(options::OPT_traditional,
2077 options::OPT_traditional_cpp)) {
2078 if (isa<PreprocessJobAction>(JA))
2079 CmdArgs.push_back("-traditional-cpp");
2081 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
2084 Args.AddLastArg(CmdArgs, options::OPT_dM);
2085 Args.AddLastArg(CmdArgs, options::OPT_dD);
2087 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
2089 Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
2090 for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm),
2091 ie = Args.filtered_end(); it != ie; ++it) {
2094 // We translate this by hand to the -cc1 argument, since nightly test uses
2095 // it and developers have been trained to spell it with -mllvm.
2096 if (llvm::StringRef((*it)->getValue(Args, 0)) == "-disable-llvm-optzns")
2097 CmdArgs.push_back("-disable-llvm-optzns");
2099 (*it)->render(Args, CmdArgs);
2102 if (Output.getType() == types::TY_Dependencies) {
2103 // Handled with other dependency code.
2104 } else if (Output.isFilename()) {
2105 CmdArgs.push_back("-o");
2106 CmdArgs.push_back(Output.getFilename());
2108 assert(Output.isNothing() && "Invalid output.");
2111 for (InputInfoList::const_iterator
2112 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
2113 const InputInfo &II = *it;
2114 CmdArgs.push_back("-x");
2115 CmdArgs.push_back(types::getTypeName(II.getType()));
2116 if (II.isFilename())
2117 CmdArgs.push_back(II.getFilename());
2119 II.getInputArg().renderAsInput(Args, CmdArgs);
2122 Args.AddAllArgs(CmdArgs, options::OPT_undef);
2124 const char *Exec = getToolChain().getDriver().getClangProgramPath();
2126 // Optionally embed the -cc1 level arguments into the debug info, for build
2128 if (getToolChain().UseDwarfDebugFlags()) {
2129 ArgStringList OriginalArgs;
2130 for (ArgList::const_iterator it = Args.begin(),
2131 ie = Args.end(); it != ie; ++it)
2132 (*it)->render(Args, OriginalArgs);
2134 llvm::SmallString<256> Flags;
2136 for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
2138 Flags += OriginalArgs[i];
2140 CmdArgs.push_back("-dwarf-debug-flags");
2141 CmdArgs.push_back(Args.MakeArgString(Flags.str()));
2144 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2146 if (Arg *A = Args.getLastArg(options::OPT_pg))
2147 if (Args.hasArg(options::OPT_fomit_frame_pointer))
2148 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
2149 << "-fomit-frame-pointer" << A->getAsString(Args);
2151 // Claim some arguments which clang supports automatically.
2153 // -fpch-preprocess is used with gcc to add a special marker in the output to
2154 // include the PCH file. Clang's PTH solution is completely transparent, so we
2155 // do not need to deal with it at all.
2156 Args.ClaimAllArgs(options::OPT_fpch_preprocess);
2158 // Claim some arguments which clang doesn't support, but we don't
2159 // care to warn the user about.
2160 Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
2161 Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
2163 // Disable warnings for clang -E -use-gold-plugin -emit-llvm foo.c
2164 Args.ClaimAllArgs(options::OPT_use_gold_plugin);
2165 Args.ClaimAllArgs(options::OPT_emit_llvm);
2168 void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
2169 const InputInfo &Output,
2170 const InputInfoList &Inputs,
2171 const ArgList &Args,
2172 const char *LinkingOutput) const {
2173 ArgStringList CmdArgs;
2175 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
2176 const InputInfo &Input = Inputs[0];
2178 // Don't warn about "clang -w -c foo.s"
2179 Args.ClaimAllArgs(options::OPT_w);
2180 // and "clang -emit-llvm -c foo.s"
2181 Args.ClaimAllArgs(options::OPT_emit_llvm);
2182 // and "clang -use-gold-plugin -c foo.s"
2183 Args.ClaimAllArgs(options::OPT_use_gold_plugin);
2185 // Invoke ourselves in -cc1as mode.
2187 // FIXME: Implement custom jobs for internal actions.
2188 CmdArgs.push_back("-cc1as");
2190 // Add the "effective" target triple.
2191 CmdArgs.push_back("-triple");
2192 std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
2193 CmdArgs.push_back(Args.MakeArgString(TripleStr));
2195 // Set the output mode, we currently only expect to be used as a real
2197 CmdArgs.push_back("-filetype");
2198 CmdArgs.push_back("obj");
2200 if (UseRelaxAll(C, Args))
2201 CmdArgs.push_back("-relax-all");
2203 // Ignore explicit -force_cpusubtype_ALL option.
2204 (void) Args.hasArg(options::OPT_force__cpusubtype__ALL);
2206 // FIXME: Add -g support, once we have it.
2208 // FIXME: Add -static support, once we have it.
2210 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
2211 options::OPT_Xassembler);
2212 Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
2214 assert(Output.isFilename() && "Unexpected lipo output.");
2215 CmdArgs.push_back("-o");
2216 CmdArgs.push_back(Output.getFilename());
2218 assert(Input.isFilename() && "Invalid input.");
2219 CmdArgs.push_back(Input.getFilename());
2221 const char *Exec = getToolChain().getDriver().getClangProgramPath();
2222 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2225 void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
2226 const InputInfo &Output,
2227 const InputInfoList &Inputs,
2228 const ArgList &Args,
2229 const char *LinkingOutput) const {
2230 const Driver &D = getToolChain().getDriver();
2231 ArgStringList CmdArgs;
2233 for (ArgList::const_iterator
2234 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
2236 if (A->getOption().hasForwardToGCC()) {
2237 // Don't forward any -g arguments to assembly steps.
2238 if (isa<AssembleJobAction>(JA) &&
2239 A->getOption().matches(options::OPT_g_Group))
2242 // It is unfortunate that we have to claim here, as this means
2243 // we will basically never report anything interesting for
2244 // platforms using a generic gcc, even if we are just using gcc
2245 // to get to the assembler.
2247 A->render(Args, CmdArgs);
2251 RenderExtraToolArgs(JA, CmdArgs);
2253 // If using a driver driver, force the arch.
2254 const std::string &Arch = getToolChain().getArchName();
2255 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin) {
2256 CmdArgs.push_back("-arch");
2258 // FIXME: Remove these special cases.
2259 if (Arch == "powerpc")
2260 CmdArgs.push_back("ppc");
2261 else if (Arch == "powerpc64")
2262 CmdArgs.push_back("ppc64");
2264 CmdArgs.push_back(Args.MakeArgString(Arch));
2267 // Try to force gcc to match the tool chain we want, if we recognize
2270 // FIXME: The triple class should directly provide the information we want
2272 if (Arch == "i386" || Arch == "powerpc")
2273 CmdArgs.push_back("-m32");
2274 else if (Arch == "x86_64" || Arch == "powerpc64")
2275 CmdArgs.push_back("-m64");
2277 if (Output.isFilename()) {
2278 CmdArgs.push_back("-o");
2279 CmdArgs.push_back(Output.getFilename());
2281 assert(Output.isNothing() && "Unexpected output");
2282 CmdArgs.push_back("-fsyntax-only");
2286 // Only pass -x if gcc will understand it; otherwise hope gcc
2287 // understands the suffix correctly. The main use case this would go
2288 // wrong in is for linker inputs if they happened to have an odd
2289 // suffix; really the only way to get this to happen is a command
2290 // like '-x foobar a.c' which will treat a.c like a linker input.
2292 // FIXME: For the linker case specifically, can we safely convert
2293 // inputs into '-Wl,' options?
2294 for (InputInfoList::const_iterator
2295 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
2296 const InputInfo &II = *it;
2298 // Don't try to pass LLVM or AST inputs to a generic gcc.
2299 if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
2300 II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC)
2301 D.Diag(clang::diag::err_drv_no_linker_llvm_support)
2302 << getToolChain().getTripleString();
2303 else if (II.getType() == types::TY_AST)
2304 D.Diag(clang::diag::err_drv_no_ast_support)
2305 << getToolChain().getTripleString();
2307 if (types::canTypeBeUserSpecified(II.getType())) {
2308 CmdArgs.push_back("-x");
2309 CmdArgs.push_back(types::getTypeName(II.getType()));
2312 if (II.isFilename())
2313 CmdArgs.push_back(II.getFilename());
2315 const Arg &A = II.getInputArg();
2317 // Reverse translate some rewritten options.
2318 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
2319 CmdArgs.push_back("-lstdc++");
2323 // Don't render as input, we need gcc to do the translations.
2324 A.render(Args, CmdArgs);
2328 const std::string customGCCName = D.getCCCGenericGCCName();
2329 const char *GCCName;
2330 if (!customGCCName.empty())
2331 GCCName = customGCCName.c_str();
2332 else if (D.CCCIsCXX) {
2334 // FIXME: Detect the version of Cygwin at runtime?
2343 Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
2344 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2347 void gcc::Preprocess::RenderExtraToolArgs(const JobAction &JA,
2348 ArgStringList &CmdArgs) const {
2349 CmdArgs.push_back("-E");
2352 void gcc::Precompile::RenderExtraToolArgs(const JobAction &JA,
2353 ArgStringList &CmdArgs) const {
2354 // The type is good enough.
2357 void gcc::Compile::RenderExtraToolArgs(const JobAction &JA,
2358 ArgStringList &CmdArgs) const {
2359 const Driver &D = getToolChain().getDriver();
2361 // If -flto, etc. are present then make sure not to force assembly output.
2362 if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR ||
2363 JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC)
2364 CmdArgs.push_back("-c");
2366 if (JA.getType() != types::TY_PP_Asm)
2367 D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
2368 << getTypeName(JA.getType());
2370 CmdArgs.push_back("-S");
2374 void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA,
2375 ArgStringList &CmdArgs) const {
2376 CmdArgs.push_back("-c");
2379 void gcc::Link::RenderExtraToolArgs(const JobAction &JA,
2380 ArgStringList &CmdArgs) const {
2381 // The types are (hopefully) good enough.
2384 const char *darwin::CC1::getCC1Name(types::ID Type) const {
2387 assert(0 && "Unexpected type for Darwin CC1 tool.");
2389 case types::TY_C: case types::TY_CHeader:
2390 case types::TY_PP_C: case types::TY_PP_CHeader:
2392 case types::TY_ObjC: case types::TY_ObjCHeader:
2393 case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader:
2395 case types::TY_CXX: case types::TY_CXXHeader:
2396 case types::TY_PP_CXX: case types::TY_PP_CXXHeader:
2398 case types::TY_ObjCXX: case types::TY_ObjCXXHeader:
2399 case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader:
2400 return "cc1objplus";
2404 const char *darwin::CC1::getBaseInputName(const ArgList &Args,
2405 const InputInfoList &Inputs) {
2406 return Args.MakeArgString(
2407 llvm::sys::path::filename(Inputs[0].getBaseInput()));
2410 const char *darwin::CC1::getBaseInputStem(const ArgList &Args,
2411 const InputInfoList &Inputs) {
2412 const char *Str = getBaseInputName(Args, Inputs);
2414 if (const char *End = strrchr(Str, '.'))
2415 return Args.MakeArgString(std::string(Str, End));
2421 darwin::CC1::getDependencyFileName(const ArgList &Args,
2422 const InputInfoList &Inputs) {
2423 // FIXME: Think about this more.
2426 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
2427 std::string Str(OutputOpt->getValue(Args));
2429 Res = Str.substr(0, Str.rfind('.'));
2431 Res = darwin::CC1::getBaseInputStem(Args, Inputs);
2433 return Args.MakeArgString(Res + ".d");
2436 void darwin::CC1::AddCC1Args(const ArgList &Args,
2437 ArgStringList &CmdArgs) const {
2438 const Driver &D = getToolChain().getDriver();
2440 CheckCodeGenerationOptions(D, Args);
2442 // Derived from cc1 spec.
2443 if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) &&
2444 !Args.hasArg(options::OPT_mdynamic_no_pic))
2445 CmdArgs.push_back("-fPIC");
2447 if (getToolChain().getTriple().getArch() == llvm::Triple::arm ||
2448 getToolChain().getTriple().getArch() == llvm::Triple::thumb) {
2449 if (!Args.hasArg(options::OPT_fbuiltin_strcat))
2450 CmdArgs.push_back("-fno-builtin-strcat");
2451 if (!Args.hasArg(options::OPT_fbuiltin_strcpy))
2452 CmdArgs.push_back("-fno-builtin-strcpy");
2455 if (Args.hasArg(options::OPT_g_Flag) &&
2456 !Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols))
2457 CmdArgs.push_back("-feliminate-unused-debug-symbols");
2460 void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
2461 const InputInfoList &Inputs,
2462 const ArgStringList &OutputArgs) const {
2463 const Driver &D = getToolChain().getDriver();
2465 // Derived from cc1_options spec.
2466 if (Args.hasArg(options::OPT_fast) ||
2467 Args.hasArg(options::OPT_fastf) ||
2468 Args.hasArg(options::OPT_fastcp))
2469 CmdArgs.push_back("-O3");
2471 if (Arg *A = Args.getLastArg(options::OPT_pg))
2472 if (Args.hasArg(options::OPT_fomit_frame_pointer))
2473 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
2474 << A->getAsString(Args) << "-fomit-frame-pointer";
2476 AddCC1Args(Args, CmdArgs);
2478 if (!Args.hasArg(options::OPT_Q))
2479 CmdArgs.push_back("-quiet");
2481 CmdArgs.push_back("-dumpbase");
2482 CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs));
2484 Args.AddAllArgs(CmdArgs, options::OPT_d_Group);
2486 Args.AddAllArgs(CmdArgs, options::OPT_m_Group);
2487 Args.AddAllArgs(CmdArgs, options::OPT_a_Group);
2489 // FIXME: The goal is to use the user provided -o if that is our
2490 // final output, otherwise to drive from the original input
2491 // name. Find a clean way to go about this.
2492 if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) &&
2493 Args.hasArg(options::OPT_o)) {
2494 Arg *OutputOpt = Args.getLastArg(options::OPT_o);
2495 CmdArgs.push_back("-auxbase-strip");
2496 CmdArgs.push_back(OutputOpt->getValue(Args));
2498 CmdArgs.push_back("-auxbase");
2499 CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs));
2502 Args.AddAllArgs(CmdArgs, options::OPT_g_Group);
2504 Args.AddAllArgs(CmdArgs, options::OPT_O);
2505 // FIXME: -Wall is getting some special treatment. Investigate.
2506 Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group);
2507 Args.AddLastArg(CmdArgs, options::OPT_w);
2508 Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
2509 options::OPT_trigraphs);
2510 if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
2511 // Honor -std-default.
2512 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
2513 "-std=", /*Joined=*/true);
2516 if (Args.hasArg(options::OPT_v))
2517 CmdArgs.push_back("-version");
2518 if (Args.hasArg(options::OPT_pg) &&
2519 getToolChain().SupportsProfiling())
2520 CmdArgs.push_back("-p");
2521 Args.AddLastArg(CmdArgs, options::OPT_p);
2523 // The driver treats -fsyntax-only specially.
2524 if (getToolChain().getTriple().getArch() == llvm::Triple::arm ||
2525 getToolChain().getTriple().getArch() == llvm::Triple::thumb) {
2526 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
2527 // used to inhibit the default -fno-builtin-str{cat,cpy}.
2529 // FIXME: Should we grow a better way to deal with "removing" args?
2530 for (arg_iterator it = Args.filtered_begin(options::OPT_f_Group,
2531 options::OPT_fsyntax_only),
2532 ie = Args.filtered_end(); it != ie; ++it) {
2533 if (!(*it)->getOption().matches(options::OPT_fbuiltin_strcat) &&
2534 !(*it)->getOption().matches(options::OPT_fbuiltin_strcpy)) {
2536 (*it)->render(Args, CmdArgs);
2540 Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only);
2542 // Claim Clang only -f options, they aren't worth warning about.
2543 Args.ClaimAllArgs(options::OPT_f_clang_Group);
2545 Args.AddAllArgs(CmdArgs, options::OPT_undef);
2546 if (Args.hasArg(options::OPT_Qn))
2547 CmdArgs.push_back("-fno-ident");
2549 // FIXME: This isn't correct.
2550 //Args.AddLastArg(CmdArgs, options::OPT__help)
2551 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
2553 CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
2555 // FIXME: Still don't get what is happening here. Investigate.
2556 Args.AddAllArgs(CmdArgs, options::OPT__param);
2558 if (Args.hasArg(options::OPT_fmudflap) ||
2559 Args.hasArg(options::OPT_fmudflapth)) {
2560 CmdArgs.push_back("-fno-builtin");
2561 CmdArgs.push_back("-fno-merge-constants");
2564 if (Args.hasArg(options::OPT_coverage)) {
2565 CmdArgs.push_back("-fprofile-arcs");
2566 CmdArgs.push_back("-ftest-coverage");
2569 if (types::isCXX(Inputs[0].getType()))
2570 CmdArgs.push_back("-D__private_extern__=extern");
2573 void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs,
2574 const InputInfoList &Inputs,
2575 const ArgStringList &OutputArgs) const {
2576 // Derived from cpp_options
2577 AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs);
2579 CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
2581 AddCC1Args(Args, CmdArgs);
2583 // NOTE: The code below has some commonality with cpp_options, but
2584 // in classic gcc style ends up sending things in different
2585 // orders. This may be a good merge candidate once we drop pedantic
2588 Args.AddAllArgs(CmdArgs, options::OPT_m_Group);
2589 Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
2590 options::OPT_trigraphs);
2591 if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
2592 // Honor -std-default.
2593 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
2594 "-std=", /*Joined=*/true);
2596 Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group);
2597 Args.AddLastArg(CmdArgs, options::OPT_w);
2599 // The driver treats -fsyntax-only specially.
2600 Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only);
2602 // Claim Clang only -f options, they aren't worth warning about.
2603 Args.ClaimAllArgs(options::OPT_f_clang_Group);
2605 if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) &&
2606 !Args.hasArg(options::OPT_fno_working_directory))
2607 CmdArgs.push_back("-fworking-directory");
2609 Args.AddAllArgs(CmdArgs, options::OPT_O);
2610 Args.AddAllArgs(CmdArgs, options::OPT_undef);
2611 if (Args.hasArg(options::OPT_save_temps))
2612 CmdArgs.push_back("-fpch-preprocess");
2615 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args,
2616 ArgStringList &CmdArgs,
2617 const InputInfoList &Inputs) const {
2618 const Driver &D = getToolChain().getDriver();
2620 CheckPreprocessingOptions(D, Args);
2622 // Derived from cpp_unique_options.
2623 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2624 Args.AddLastArg(CmdArgs, options::OPT_C);
2625 Args.AddLastArg(CmdArgs, options::OPT_CC);
2626 if (!Args.hasArg(options::OPT_Q))
2627 CmdArgs.push_back("-quiet");
2628 Args.AddAllArgs(CmdArgs, options::OPT_nostdinc);
2629 Args.AddAllArgs(CmdArgs, options::OPT_nostdincxx);
2630 Args.AddLastArg(CmdArgs, options::OPT_v);
2631 Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
2632 Args.AddLastArg(CmdArgs, options::OPT_P);
2634 // FIXME: Handle %I properly.
2635 if (getToolChain().getArchName() == "x86_64") {
2636 CmdArgs.push_back("-imultilib");
2637 CmdArgs.push_back("x86_64");
2640 if (Args.hasArg(options::OPT_MD)) {
2641 CmdArgs.push_back("-MD");
2642 CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs));
2645 if (Args.hasArg(options::OPT_MMD)) {
2646 CmdArgs.push_back("-MMD");
2647 CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs));
2650 Args.AddLastArg(CmdArgs, options::OPT_M);
2651 Args.AddLastArg(CmdArgs, options::OPT_MM);
2652 Args.AddAllArgs(CmdArgs, options::OPT_MF);
2653 Args.AddLastArg(CmdArgs, options::OPT_MG);
2654 Args.AddLastArg(CmdArgs, options::OPT_MP);
2655 Args.AddAllArgs(CmdArgs, options::OPT_MQ);
2656 Args.AddAllArgs(CmdArgs, options::OPT_MT);
2657 if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) &&
2658 (Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) {
2659 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
2660 CmdArgs.push_back("-MQ");
2661 CmdArgs.push_back(OutputOpt->getValue(Args));
2665 Args.AddLastArg(CmdArgs, options::OPT_remap);
2666 if (Args.hasArg(options::OPT_g3))
2667 CmdArgs.push_back("-dD");
2668 Args.AddLastArg(CmdArgs, options::OPT_H);
2670 AddCPPArgs(Args, CmdArgs);
2672 Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A);
2673 Args.AddAllArgs(CmdArgs, options::OPT_i_Group);
2675 for (InputInfoList::const_iterator
2676 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
2677 const InputInfo &II = *it;
2679 CmdArgs.push_back(II.getFilename());
2682 Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
2683 options::OPT_Xpreprocessor);
2685 if (Args.hasArg(options::OPT_fmudflap)) {
2686 CmdArgs.push_back("-D_MUDFLAP");
2687 CmdArgs.push_back("-include");
2688 CmdArgs.push_back("mf-runtime.h");
2691 if (Args.hasArg(options::OPT_fmudflapth)) {
2692 CmdArgs.push_back("-D_MUDFLAP");
2693 CmdArgs.push_back("-D_MUDFLAPTH");
2694 CmdArgs.push_back("-include");
2695 CmdArgs.push_back("mf-runtime.h");
2699 void darwin::CC1::AddCPPArgs(const ArgList &Args,
2700 ArgStringList &CmdArgs) const {
2701 // Derived from cpp spec.
2703 if (Args.hasArg(options::OPT_static)) {
2704 // The gcc spec is broken here, it refers to dynamic but
2705 // that has been translated. Start by being bug compatible.
2707 // if (!Args.hasArg(arglist.parser.dynamicOption))
2708 CmdArgs.push_back("-D__STATIC__");
2710 CmdArgs.push_back("-D__DYNAMIC__");
2712 if (Args.hasArg(options::OPT_pthread))
2713 CmdArgs.push_back("-D_REENTRANT");
2716 void darwin::Preprocess::ConstructJob(Compilation &C, const JobAction &JA,
2717 const InputInfo &Output,
2718 const InputInfoList &Inputs,
2719 const ArgList &Args,
2720 const char *LinkingOutput) const {
2721 ArgStringList CmdArgs;
2723 assert(Inputs.size() == 1 && "Unexpected number of inputs!");
2725 CmdArgs.push_back("-E");
2727 if (Args.hasArg(options::OPT_traditional) ||
2728 Args.hasArg(options::OPT_traditional_cpp))
2729 CmdArgs.push_back("-traditional-cpp");
2731 ArgStringList OutputArgs;
2732 assert(Output.isFilename() && "Unexpected CC1 output.");
2733 OutputArgs.push_back("-o");
2734 OutputArgs.push_back(Output.getFilename());
2736 if (Args.hasArg(options::OPT_E) || getToolChain().getDriver().CCCIsCPP) {
2737 AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
2739 AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
2740 CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
2743 Args.AddAllArgs(CmdArgs, options::OPT_d_Group);
2745 const char *CC1Name = getCC1Name(Inputs[0].getType());
2747 Args.MakeArgString(getToolChain().GetProgramPath(CC1Name));
2748 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2751 void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA,
2752 const InputInfo &Output,
2753 const InputInfoList &Inputs,
2754 const ArgList &Args,
2755 const char *LinkingOutput) const {
2756 const Driver &D = getToolChain().getDriver();
2757 ArgStringList CmdArgs;
2759 assert(Inputs.size() == 1 && "Unexpected number of inputs!");
2761 types::ID InputType = Inputs[0].getType();
2763 if ((A = Args.getLastArg(options::OPT_traditional)))
2764 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
2765 << A->getAsString(Args) << "-E";
2767 if (JA.getType() == types::TY_LLVM_IR ||
2768 JA.getType() == types::TY_LTO_IR)
2769 CmdArgs.push_back("-emit-llvm");
2770 else if (JA.getType() == types::TY_LLVM_BC ||
2771 JA.getType() == types::TY_LTO_BC)
2772 CmdArgs.push_back("-emit-llvm-bc");
2773 else if (Output.getType() == types::TY_AST)
2774 D.Diag(clang::diag::err_drv_no_ast_support)
2775 << getToolChain().getTripleString();
2776 else if (JA.getType() != types::TY_PP_Asm &&
2777 JA.getType() != types::TY_PCH)
2778 D.Diag(clang::diag::err_drv_invalid_gcc_output_type)
2779 << getTypeName(JA.getType());
2781 ArgStringList OutputArgs;
2782 if (Output.getType() != types::TY_PCH) {
2783 OutputArgs.push_back("-o");
2784 if (Output.isNothing())
2785 OutputArgs.push_back("/dev/null");
2787 OutputArgs.push_back(Output.getFilename());
2790 // There is no need for this level of compatibility, but it makes
2792 bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) ||
2793 Args.hasArg(options::OPT_S));
2795 if (types::getPreprocessedType(InputType) != types::TY_INVALID) {
2796 AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs);
2797 if (OutputArgsEarly) {
2798 AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
2800 AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
2801 CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
2804 CmdArgs.push_back("-fpreprocessed");
2806 for (InputInfoList::const_iterator
2807 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
2808 const InputInfo &II = *it;
2810 // Reject AST inputs.
2811 if (II.getType() == types::TY_AST) {
2812 D.Diag(clang::diag::err_drv_no_ast_support)
2813 << getToolChain().getTripleString();
2817 CmdArgs.push_back(II.getFilename());
2820 if (OutputArgsEarly) {
2821 AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs);
2823 AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList());
2824 CmdArgs.append(OutputArgs.begin(), OutputArgs.end());
2828 if (Output.getType() == types::TY_PCH) {
2829 assert(Output.isFilename() && "Invalid PCH output.");
2831 CmdArgs.push_back("-o");
2832 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2833 // to be a good reason.
2834 CmdArgs.push_back("/dev/null");
2836 CmdArgs.push_back("--output-pch=");
2837 CmdArgs.push_back(Output.getFilename());
2840 const char *CC1Name = getCC1Name(Inputs[0].getType());
2842 Args.MakeArgString(getToolChain().GetProgramPath(CC1Name));
2843 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2846 void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
2847 const InputInfo &Output,
2848 const InputInfoList &Inputs,
2849 const ArgList &Args,
2850 const char *LinkingOutput) const {
2851 ArgStringList CmdArgs;
2853 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
2854 const InputInfo &Input = Inputs[0];
2856 // Determine the original source input.
2857 const Action *SourceAction = &JA;
2858 while (SourceAction->getKind() != Action::InputClass) {
2859 assert(!SourceAction->getInputs().empty() && "unexpected root action!");
2860 SourceAction = SourceAction->getInputs()[0];
2863 // Forward -g, assuming we are dealing with an actual assembly file.
2864 if (SourceAction->getType() == types::TY_Asm ||
2865 SourceAction->getType() == types::TY_PP_Asm) {
2866 if (Args.hasArg(options::OPT_gstabs))
2867 CmdArgs.push_back("--gstabs");
2868 else if (Args.hasArg(options::OPT_g_Group))
2869 CmdArgs.push_back("--gdwarf2");
2872 // Derived from asm spec.
2873 AddDarwinArch(Args, CmdArgs);
2875 // Use -force_cpusubtype_ALL on x86 by default.
2876 if (getToolChain().getTriple().getArch() == llvm::Triple::x86 ||
2877 getToolChain().getTriple().getArch() == llvm::Triple::x86_64 ||
2878 Args.hasArg(options::OPT_force__cpusubtype__ALL))
2879 CmdArgs.push_back("-force_cpusubtype_ALL");
2881 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 &&
2882 (Args.hasArg(options::OPT_mkernel) ||
2883 Args.hasArg(options::OPT_static) ||
2884 Args.hasArg(options::OPT_fapple_kext)))
2885 CmdArgs.push_back("-static");
2887 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
2888 options::OPT_Xassembler);
2890 assert(Output.isFilename() && "Unexpected lipo output.");
2891 CmdArgs.push_back("-o");
2892 CmdArgs.push_back(Output.getFilename());
2894 assert(Input.isFilename() && "Invalid input.");
2895 CmdArgs.push_back(Input.getFilename());
2897 // asm_final spec is empty.
2900 Args.MakeArgString(getToolChain().GetProgramPath("as"));
2901 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
2904 void darwin::DarwinTool::AddDarwinArch(const ArgList &Args,
2905 ArgStringList &CmdArgs) const {
2906 llvm::StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args);
2908 // Derived from darwin_arch spec.
2909 CmdArgs.push_back("-arch");
2910 CmdArgs.push_back(Args.MakeArgString(ArchName));
2912 // FIXME: Is this needed anymore?
2913 if (ArchName == "arm")
2914 CmdArgs.push_back("-force_cpusubtype_ALL");
2917 void darwin::Link::AddLinkArgs(Compilation &C,
2918 const ArgList &Args,
2919 ArgStringList &CmdArgs) const {
2920 const Driver &D = getToolChain().getDriver();
2921 const toolchains::Darwin &DarwinTC = getDarwinToolChain();
2923 unsigned Version[3] = { 0, 0, 0 };
2924 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
2926 if (!Driver::GetReleaseVersion(A->getValue(Args), Version[0],
2927 Version[1], Version[2], HadExtra) ||
2929 D.Diag(clang::diag::err_drv_invalid_version_number)
2930 << A->getAsString(Args);
2933 // Newer linkers support -demangle, pass it if supported and not disabled by
2936 // FIXME: We temporarily avoid passing -demangle to any iOS linker, because
2937 // unfortunately we can't be guaranteed that the linker version used there
2938 // will match the linker version detected at configure time. We need the
2939 // universal driver.
2940 if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle) &&
2941 !DarwinTC.isTargetIPhoneOS()) {
2942 // Don't pass -demangle to ld_classic.
2944 // FIXME: This is a temporary workaround, ld should be handling this.
2945 bool UsesLdClassic = (getToolChain().getArch() == llvm::Triple::x86 &&
2946 Args.hasArg(options::OPT_static));
2947 if (getToolChain().getArch() == llvm::Triple::x86) {
2948 for (arg_iterator it = Args.filtered_begin(options::OPT_Xlinker,
2949 options::OPT_Wl_COMMA),
2950 ie = Args.filtered_end(); it != ie; ++it) {
2952 for (unsigned i = 0, e = A->getNumValues(); i != e; ++i)
2953 if (llvm::StringRef(A->getValue(Args, i)) == "-kext")
2954 UsesLdClassic = true;
2958 CmdArgs.push_back("-demangle");
2961 // If we are using LTO, then automatically create a temporary file path for
2962 // the linker to use, so that it's lifetime will extend past a possible
2964 if (Version[0] >= 116 && D.IsUsingLTO(Args)) {
2965 const char *TmpPath = C.getArgs().MakeArgString(
2966 D.GetTemporaryPath(types::getTypeTempSuffix(types::TY_Object)));
2967 C.addTempFile(TmpPath);
2968 CmdArgs.push_back("-object_path_lto");
2969 CmdArgs.push_back(TmpPath);
2972 // Derived from the "link" spec.
2973 Args.AddAllArgs(CmdArgs, options::OPT_static);
2974 if (!Args.hasArg(options::OPT_static))
2975 CmdArgs.push_back("-dynamic");
2976 if (Args.hasArg(options::OPT_fgnu_runtime)) {
2977 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2978 // here. How do we wish to handle such things?
2981 if (!Args.hasArg(options::OPT_dynamiclib)) {
2982 AddDarwinArch(Args, CmdArgs);
2983 // FIXME: Why do this only on this path?
2984 Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL);
2986 Args.AddLastArg(CmdArgs, options::OPT_bundle);
2987 Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader);
2988 Args.AddAllArgs(CmdArgs, options::OPT_client__name);
2991 if ((A = Args.getLastArg(options::OPT_compatibility__version)) ||
2992 (A = Args.getLastArg(options::OPT_current__version)) ||
2993 (A = Args.getLastArg(options::OPT_install__name)))
2994 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
2995 << A->getAsString(Args) << "-dynamiclib";
2997 Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace);
2998 Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs);
2999 Args.AddLastArg(CmdArgs, options::OPT_private__bundle);
3001 CmdArgs.push_back("-dylib");
3004 if ((A = Args.getLastArg(options::OPT_bundle)) ||
3005 (A = Args.getLastArg(options::OPT_bundle__loader)) ||
3006 (A = Args.getLastArg(options::OPT_client__name)) ||
3007 (A = Args.getLastArg(options::OPT_force__flat__namespace)) ||
3008 (A = Args.getLastArg(options::OPT_keep__private__externs)) ||
3009 (A = Args.getLastArg(options::OPT_private__bundle)))
3010 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
3011 << A->getAsString(Args) << "-dynamiclib";
3013 Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version,
3014 "-dylib_compatibility_version");
3015 Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version,
3016 "-dylib_current_version");
3018 AddDarwinArch(Args, CmdArgs);
3020 Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name,
3021 "-dylib_install_name");
3024 Args.AddLastArg(CmdArgs, options::OPT_all__load);
3025 Args.AddAllArgs(CmdArgs, options::OPT_allowable__client);
3026 Args.AddLastArg(CmdArgs, options::OPT_bind__at__load);
3027 if (DarwinTC.isTargetIPhoneOS())
3028 Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal);
3029 Args.AddLastArg(CmdArgs, options::OPT_dead__strip);
3030 Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms);
3031 Args.AddAllArgs(CmdArgs, options::OPT_dylib__file);
3032 Args.AddLastArg(CmdArgs, options::OPT_dynamic);
3033 Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list);
3034 Args.AddLastArg(CmdArgs, options::OPT_flat__namespace);
3035 Args.AddAllArgs(CmdArgs, options::OPT_force__load);
3036 Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names);
3037 Args.AddAllArgs(CmdArgs, options::OPT_image__base);
3038 Args.AddAllArgs(CmdArgs, options::OPT_init);
3040 // Add the deployment target.
3041 unsigned TargetVersion[3];
3042 DarwinTC.getTargetVersion(TargetVersion);
3044 // If we had an explicit -mios-simulator-version-min argument, honor that,
3045 // otherwise use the traditional deployment targets. We can't just check the
3046 // is-sim attribute because existing code follows this path, and the linker
3047 // may not handle the argument.
3049 // FIXME: We may be able to remove this, once we can verify no one depends on
3051 if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ))
3052 CmdArgs.push_back("-ios_simulator_version_min");
3053 else if (DarwinTC.isTargetIPhoneOS())
3054 CmdArgs.push_back("-iphoneos_version_min");
3056 CmdArgs.push_back("-macosx_version_min");
3057 CmdArgs.push_back(Args.MakeArgString(llvm::Twine(TargetVersion[0]) + "." +
3058 llvm::Twine(TargetVersion[1]) + "." +
3059 llvm::Twine(TargetVersion[2])));
3061 Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);
3062 Args.AddLastArg(CmdArgs, options::OPT_multi__module);
3063 Args.AddLastArg(CmdArgs, options::OPT_single__module);
3064 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined);
3065 Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused);
3067 if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE,
3068 options::OPT_fno_pie,
3069 options::OPT_fno_PIE)) {
3070 if (A->getOption().matches(options::OPT_fpie) ||
3071 A->getOption().matches(options::OPT_fPIE))
3072 CmdArgs.push_back("-pie");
3074 CmdArgs.push_back("-no_pie");
3077 Args.AddLastArg(CmdArgs, options::OPT_prebind);
3078 Args.AddLastArg(CmdArgs, options::OPT_noprebind);
3079 Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding);
3080 Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules);
3081 Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs);
3082 Args.AddAllArgs(CmdArgs, options::OPT_sectcreate);
3083 Args.AddAllArgs(CmdArgs, options::OPT_sectorder);
3084 Args.AddAllArgs(CmdArgs, options::OPT_seg1addr);
3085 Args.AddAllArgs(CmdArgs, options::OPT_segprot);
3086 Args.AddAllArgs(CmdArgs, options::OPT_segaddr);
3087 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr);
3088 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr);
3089 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table);
3090 Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename);
3091 Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
3092 Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
3094 // Give --sysroot= preference, over the Apple specific behavior to also use
3095 // --isysroot as the syslibroot.
3096 if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
3097 CmdArgs.push_back("-syslibroot");
3098 CmdArgs.push_back(A->getValue(Args));
3099 } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
3100 CmdArgs.push_back("-syslibroot");
3101 CmdArgs.push_back(A->getValue(Args));
3102 } else if (getDarwinToolChain().isTargetIPhoneOS()) {
3103 CmdArgs.push_back("-syslibroot");
3104 CmdArgs.push_back("/Developer/SDKs/Extra");
3107 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
3108 Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints);
3109 Args.AddAllArgs(CmdArgs, options::OPT_umbrella);
3110 Args.AddAllArgs(CmdArgs, options::OPT_undefined);
3111 Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list);
3112 Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches);
3113 Args.AddLastArg(CmdArgs, options::OPT_X_Flag);
3114 Args.AddAllArgs(CmdArgs, options::OPT_y);
3115 Args.AddLastArg(CmdArgs, options::OPT_w);
3116 Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size);
3117 Args.AddAllArgs(CmdArgs, options::OPT_segs__read__);
3118 Args.AddLastArg(CmdArgs, options::OPT_seglinkedit);
3119 Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit);
3120 Args.AddAllArgs(CmdArgs, options::OPT_sectalign);
3121 Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols);
3122 Args.AddAllArgs(CmdArgs, options::OPT_segcreate);
3123 Args.AddLastArg(CmdArgs, options::OPT_whyload);
3124 Args.AddLastArg(CmdArgs, options::OPT_whatsloaded);
3125 Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name);
3126 Args.AddLastArg(CmdArgs, options::OPT_dylinker);
3127 Args.AddLastArg(CmdArgs, options::OPT_Mach);
3130 void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
3131 const InputInfo &Output,
3132 const InputInfoList &Inputs,
3133 const ArgList &Args,
3134 const char *LinkingOutput) const {
3135 assert(Output.getType() == types::TY_Image && "Invalid linker output type.");
3137 // The logic here is derived from gcc's behavior; most of which
3138 // comes from specs (starting with link_command). Consult gcc for
3139 // more information.
3140 ArgStringList CmdArgs;
3142 // I'm not sure why this particular decomposition exists in gcc, but
3143 // we follow suite for ease of comparison.
3144 AddLinkArgs(C, Args, CmdArgs);
3146 Args.AddAllArgs(CmdArgs, options::OPT_d_Flag);
3147 Args.AddAllArgs(CmdArgs, options::OPT_s);
3148 Args.AddAllArgs(CmdArgs, options::OPT_t);
3149 Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
3150 Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
3151 Args.AddAllArgs(CmdArgs, options::OPT_A);
3152 Args.AddLastArg(CmdArgs, options::OPT_e);
3153 Args.AddAllArgs(CmdArgs, options::OPT_m_Separate);
3154 Args.AddAllArgs(CmdArgs, options::OPT_r);
3156 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
3157 // members of static archive libraries which implement Objective-C classes or
3159 if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX))
3160 CmdArgs.push_back("-ObjC");
3162 CmdArgs.push_back("-o");
3163 CmdArgs.push_back(Output.getFilename());
3165 if (!Args.hasArg(options::OPT_A) &&
3166 !Args.hasArg(options::OPT_nostdlib) &&
3167 !Args.hasArg(options::OPT_nostartfiles)) {
3168 // Derived from startfile spec.
3169 if (Args.hasArg(options::OPT_dynamiclib)) {
3170 // Derived from darwin_dylib1 spec.
3171 if (getDarwinToolChain().isTargetIOSSimulator()) {
3172 // The simulator doesn't have a versioned crt1 file.
3173 CmdArgs.push_back("-ldylib1.o");
3174 } else if (getDarwinToolChain().isTargetIPhoneOS()) {
3175 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
3176 CmdArgs.push_back("-ldylib1.o");
3178 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
3179 CmdArgs.push_back("-ldylib1.o");
3180 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
3181 CmdArgs.push_back("-ldylib1.10.5.o");
3184 if (Args.hasArg(options::OPT_bundle)) {
3185 if (!Args.hasArg(options::OPT_static)) {
3186 // Derived from darwin_bundle1 spec.
3187 if (getDarwinToolChain().isTargetIOSSimulator()) {
3188 // The simulator doesn't have a versioned crt1 file.
3189 CmdArgs.push_back("-lbundle1.o");
3190 } else if (getDarwinToolChain().isTargetIPhoneOS()) {
3191 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
3192 CmdArgs.push_back("-lbundle1.o");
3194 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
3195 CmdArgs.push_back("-lbundle1.o");
3199 if (Args.hasArg(options::OPT_pg) &&
3200 getToolChain().SupportsProfiling()) {
3201 if (Args.hasArg(options::OPT_static) ||
3202 Args.hasArg(options::OPT_object) ||
3203 Args.hasArg(options::OPT_preload)) {
3204 CmdArgs.push_back("-lgcrt0.o");
3206 CmdArgs.push_back("-lgcrt1.o");
3208 // darwin_crt2 spec is empty.
3211 if (Args.hasArg(options::OPT_static) ||
3212 Args.hasArg(options::OPT_object) ||
3213 Args.hasArg(options::OPT_preload)) {
3214 CmdArgs.push_back("-lcrt0.o");
3216 // Derived from darwin_crt1 spec.
3217 if (getDarwinToolChain().isTargetIOSSimulator()) {
3218 // The simulator doesn't have a versioned crt1 file.
3219 CmdArgs.push_back("-lcrt1.o");
3220 } else if (getDarwinToolChain().isTargetIPhoneOS()) {
3221 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
3222 CmdArgs.push_back("-lcrt1.o");
3224 CmdArgs.push_back("-lcrt1.3.1.o");
3226 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
3227 CmdArgs.push_back("-lcrt1.o");
3228 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
3229 CmdArgs.push_back("-lcrt1.10.5.o");
3231 CmdArgs.push_back("-lcrt1.10.6.o");
3233 // darwin_crt2 spec is empty.
3240 if (!getDarwinToolChain().isTargetIPhoneOS() &&
3241 Args.hasArg(options::OPT_shared_libgcc) &&
3242 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
3244 Args.MakeArgString(getToolChain().GetFilePath("crt3.o"));
3245 CmdArgs.push_back(Str);
3249 Args.AddAllArgs(CmdArgs, options::OPT_L);
3251 if (Args.hasArg(options::OPT_fopenmp))
3252 // This is more complicated in gcc...
3253 CmdArgs.push_back("-lgomp");
3255 getDarwinToolChain().AddLinkSearchPathArgs(Args, CmdArgs);
3257 // In ARC, if we don't have runtime support, link in the runtime
3258 // stubs. We have to do this *before* adding any of the normal
3259 // linker inputs so that its initializer gets run first.
3260 if (isObjCAutoRefCount(Args)) {
3261 ObjCRuntime runtime;
3262 getDarwinToolChain().configureObjCRuntime(runtime);
3263 if (!runtime.HasARC)
3264 getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs);
3267 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
3269 if (LinkingOutput) {
3270 CmdArgs.push_back("-arch_multiple");
3271 CmdArgs.push_back("-final_output");
3272 CmdArgs.push_back(LinkingOutput);
3275 if (Args.hasArg(options::OPT_fnested_functions))
3276 CmdArgs.push_back("-allow_stack_execute");
3278 if (!Args.hasArg(options::OPT_nostdlib) &&
3279 !Args.hasArg(options::OPT_nodefaultlibs)) {
3280 if (getToolChain().getDriver().CCCIsCXX)
3281 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
3283 // link_ssp spec is empty.
3285 // Let the tool chain choose which runtime library to link.
3286 getDarwinToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs);
3289 if (!Args.hasArg(options::OPT_A) &&
3290 !Args.hasArg(options::OPT_nostdlib) &&
3291 !Args.hasArg(options::OPT_nostartfiles)) {
3292 // endfile_spec is empty.
3295 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
3297 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
3298 Args.AddAllArgs(CmdArgs, options::OPT_F);
3301 Args.MakeArgString(getToolChain().GetProgramPath("ld"));
3302 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3305 void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
3306 const InputInfo &Output,
3307 const InputInfoList &Inputs,
3308 const ArgList &Args,
3309 const char *LinkingOutput) const {
3310 ArgStringList CmdArgs;
3312 CmdArgs.push_back("-create");
3313 assert(Output.isFilename() && "Unexpected lipo output.");
3315 CmdArgs.push_back("-output");
3316 CmdArgs.push_back(Output.getFilename());
3318 for (InputInfoList::const_iterator
3319 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3320 const InputInfo &II = *it;
3321 assert(II.isFilename() && "Unexpected lipo input.");
3322 CmdArgs.push_back(II.getFilename());
3325 Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
3326 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3329 void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
3330 const InputInfo &Output,
3331 const InputInfoList &Inputs,
3332 const ArgList &Args,
3333 const char *LinkingOutput) const {
3334 ArgStringList CmdArgs;
3336 CmdArgs.push_back("-o");
3337 CmdArgs.push_back(Output.getFilename());
3339 assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
3340 const InputInfo &Input = Inputs[0];
3341 assert(Input.isFilename() && "Unexpected dsymutil input.");
3342 CmdArgs.push_back(Input.getFilename());
3345 Args.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
3346 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3349 void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
3350 const InputInfo &Output,
3351 const InputInfoList &Inputs,
3352 const ArgList &Args,
3353 const char *LinkingOutput) const {
3354 ArgStringList CmdArgs;
3356 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
3357 options::OPT_Xassembler);
3359 CmdArgs.push_back("-o");
3360 CmdArgs.push_back(Output.getFilename());
3362 for (InputInfoList::const_iterator
3363 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3364 const InputInfo &II = *it;
3365 CmdArgs.push_back(II.getFilename());
3369 Args.MakeArgString(getToolChain().GetProgramPath("gas"));
3370 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3373 void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA,
3374 const InputInfo &Output,
3375 const InputInfoList &Inputs,
3376 const ArgList &Args,
3377 const char *LinkingOutput) const {
3378 ArgStringList CmdArgs;
3380 if ((!Args.hasArg(options::OPT_nostdlib)) &&
3381 (!Args.hasArg(options::OPT_shared))) {
3382 CmdArgs.push_back("-e");
3383 CmdArgs.push_back("_start");
3386 if (Args.hasArg(options::OPT_static)) {
3387 CmdArgs.push_back("-Bstatic");
3388 CmdArgs.push_back("-dn");
3390 // CmdArgs.push_back("--eh-frame-hdr");
3391 CmdArgs.push_back("-Bdynamic");
3392 if (Args.hasArg(options::OPT_shared)) {
3393 CmdArgs.push_back("-shared");
3395 CmdArgs.push_back("--dynamic-linker");
3396 CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
3400 if (Output.isFilename()) {
3401 CmdArgs.push_back("-o");
3402 CmdArgs.push_back(Output.getFilename());
3404 assert(Output.isNothing() && "Invalid output.");
3407 if (!Args.hasArg(options::OPT_nostdlib) &&
3408 !Args.hasArg(options::OPT_nostartfiles)) {
3409 if (!Args.hasArg(options::OPT_shared)) {
3410 CmdArgs.push_back(Args.MakeArgString(
3411 getToolChain().GetFilePath("crt1.o")));
3412 CmdArgs.push_back(Args.MakeArgString(
3413 getToolChain().GetFilePath("crti.o")));
3414 CmdArgs.push_back(Args.MakeArgString(
3415 getToolChain().GetFilePath("crtbegin.o")));
3417 CmdArgs.push_back(Args.MakeArgString(
3418 getToolChain().GetFilePath("crti.o")));
3420 CmdArgs.push_back(Args.MakeArgString(
3421 getToolChain().GetFilePath("crtn.o")));
3424 CmdArgs.push_back(Args.MakeArgString("-L/opt/gcc4/lib/gcc/"
3425 + getToolChain().getTripleString()
3428 Args.AddAllArgs(CmdArgs, options::OPT_L);
3429 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
3430 Args.AddAllArgs(CmdArgs, options::OPT_e);
3432 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
3434 if (!Args.hasArg(options::OPT_nostdlib) &&
3435 !Args.hasArg(options::OPT_nodefaultlibs)) {
3436 // FIXME: For some reason GCC passes -lgcc before adding
3437 // the default system libraries. Just mimic this for now.
3438 CmdArgs.push_back("-lgcc");
3440 if (Args.hasArg(options::OPT_pthread))
3441 CmdArgs.push_back("-pthread");
3442 if (!Args.hasArg(options::OPT_shared))
3443 CmdArgs.push_back("-lc");
3444 CmdArgs.push_back("-lgcc");
3447 if (!Args.hasArg(options::OPT_nostdlib) &&
3448 !Args.hasArg(options::OPT_nostartfiles)) {
3449 if (!Args.hasArg(options::OPT_shared))
3450 CmdArgs.push_back(Args.MakeArgString(
3451 getToolChain().GetFilePath("crtend.o")));
3454 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
3457 Args.MakeArgString(getToolChain().GetProgramPath("ld"));
3458 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3461 void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
3462 const InputInfo &Output,
3463 const InputInfoList &Inputs,
3464 const ArgList &Args,
3465 const char *LinkingOutput) const {
3466 ArgStringList CmdArgs;
3468 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
3469 options::OPT_Xassembler);
3471 CmdArgs.push_back("-o");
3472 CmdArgs.push_back(Output.getFilename());
3474 for (InputInfoList::const_iterator
3475 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3476 const InputInfo &II = *it;
3477 CmdArgs.push_back(II.getFilename());
3481 Args.MakeArgString(getToolChain().GetProgramPath("as"));
3482 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3485 void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
3486 const InputInfo &Output,
3487 const InputInfoList &Inputs,
3488 const ArgList &Args,
3489 const char *LinkingOutput) const {
3490 const Driver &D = getToolChain().getDriver();
3491 ArgStringList CmdArgs;
3493 if ((!Args.hasArg(options::OPT_nostdlib)) &&
3494 (!Args.hasArg(options::OPT_shared))) {
3495 CmdArgs.push_back("-e");
3496 CmdArgs.push_back("__start");
3499 if (Args.hasArg(options::OPT_static)) {
3500 CmdArgs.push_back("-Bstatic");
3502 if (Args.hasArg(options::OPT_rdynamic))
3503 CmdArgs.push_back("-export-dynamic");
3504 CmdArgs.push_back("--eh-frame-hdr");
3505 CmdArgs.push_back("-Bdynamic");
3506 if (Args.hasArg(options::OPT_shared)) {
3507 CmdArgs.push_back("-shared");
3509 CmdArgs.push_back("-dynamic-linker");
3510 CmdArgs.push_back("/usr/libexec/ld.so");
3514 if (Output.isFilename()) {
3515 CmdArgs.push_back("-o");
3516 CmdArgs.push_back(Output.getFilename());
3518 assert(Output.isNothing() && "Invalid output.");
3521 if (!Args.hasArg(options::OPT_nostdlib) &&
3522 !Args.hasArg(options::OPT_nostartfiles)) {
3523 if (!Args.hasArg(options::OPT_shared)) {
3524 CmdArgs.push_back(Args.MakeArgString(
3525 getToolChain().GetFilePath("crt0.o")));
3526 CmdArgs.push_back(Args.MakeArgString(
3527 getToolChain().GetFilePath("crtbegin.o")));
3529 CmdArgs.push_back(Args.MakeArgString(
3530 getToolChain().GetFilePath("crtbeginS.o")));
3534 std::string Triple = getToolChain().getTripleString();
3535 if (Triple.substr(0, 6) == "x86_64")
3536 Triple.replace(0, 6, "amd64");
3537 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple +
3540 Args.AddAllArgs(CmdArgs, options::OPT_L);
3541 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
3542 Args.AddAllArgs(CmdArgs, options::OPT_e);
3544 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
3546 if (!Args.hasArg(options::OPT_nostdlib) &&
3547 !Args.hasArg(options::OPT_nodefaultlibs)) {
3549 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
3550 CmdArgs.push_back("-lm");
3553 // FIXME: For some reason GCC passes -lgcc before adding
3554 // the default system libraries. Just mimic this for now.
3555 CmdArgs.push_back("-lgcc");
3557 if (Args.hasArg(options::OPT_pthread))
3558 CmdArgs.push_back("-lpthread");
3559 if (!Args.hasArg(options::OPT_shared))
3560 CmdArgs.push_back("-lc");
3561 CmdArgs.push_back("-lgcc");
3564 if (!Args.hasArg(options::OPT_nostdlib) &&
3565 !Args.hasArg(options::OPT_nostartfiles)) {
3566 if (!Args.hasArg(options::OPT_shared))
3567 CmdArgs.push_back(Args.MakeArgString(
3568 getToolChain().GetFilePath("crtend.o")));
3570 CmdArgs.push_back(Args.MakeArgString(
3571 getToolChain().GetFilePath("crtendS.o")));
3575 Args.MakeArgString(getToolChain().GetProgramPath("ld"));
3576 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3579 void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
3580 const InputInfo &Output,
3581 const InputInfoList &Inputs,
3582 const ArgList &Args,
3583 const char *LinkingOutput) const {
3584 ArgStringList CmdArgs;
3586 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3587 // instruct as in the base system to assemble 32-bit code.
3588 if (getToolChain().getArchName() == "i386")
3589 CmdArgs.push_back("--32");
3591 if (getToolChain().getArchName() == "powerpc")
3592 CmdArgs.push_back("-a32");
3594 // Set byte order explicitly
3595 if (getToolChain().getArchName() == "mips")
3596 CmdArgs.push_back("-EB");
3597 else if (getToolChain().getArchName() == "mipsel")
3598 CmdArgs.push_back("-EL");
3600 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
3601 options::OPT_Xassembler);
3603 CmdArgs.push_back("-o");
3604 CmdArgs.push_back(Output.getFilename());
3606 for (InputInfoList::const_iterator
3607 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3608 const InputInfo &II = *it;
3609 CmdArgs.push_back(II.getFilename());
3613 Args.MakeArgString(getToolChain().GetProgramPath("as"));
3614 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3617 void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
3618 const InputInfo &Output,
3619 const InputInfoList &Inputs,
3620 const ArgList &Args,
3621 const char *LinkingOutput) const {
3622 const Driver &D = getToolChain().getDriver();
3623 ArgStringList CmdArgs;
3625 if (!D.SysRoot.empty())
3626 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
3628 if (Args.hasArg(options::OPT_static)) {
3629 CmdArgs.push_back("-Bstatic");
3631 if (Args.hasArg(options::OPT_rdynamic))
3632 CmdArgs.push_back("-export-dynamic");
3633 CmdArgs.push_back("--eh-frame-hdr");
3634 if (Args.hasArg(options::OPT_shared)) {
3635 CmdArgs.push_back("-Bshareable");
3637 CmdArgs.push_back("-dynamic-linker");
3638 CmdArgs.push_back("/libexec/ld-elf.so.1");
3642 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3643 // instruct ld in the base system to link 32-bit code.
3644 if (getToolChain().getArchName() == "i386") {
3645 CmdArgs.push_back("-m");
3646 CmdArgs.push_back("elf_i386_fbsd");
3649 if (getToolChain().getArchName() == "powerpc") {
3650 CmdArgs.push_back("-m");
3651 CmdArgs.push_back("elf32ppc");
3654 if (Output.isFilename()) {
3655 CmdArgs.push_back("-o");
3656 CmdArgs.push_back(Output.getFilename());
3658 assert(Output.isNothing() && "Invalid output.");
3661 if (!Args.hasArg(options::OPT_nostdlib) &&
3662 !Args.hasArg(options::OPT_nostartfiles)) {
3663 if (!Args.hasArg(options::OPT_shared)) {
3664 if (Args.hasArg(options::OPT_pg))
3665 CmdArgs.push_back(Args.MakeArgString(
3666 getToolChain().GetFilePath("gcrt1.o")));
3668 CmdArgs.push_back(Args.MakeArgString(
3669 getToolChain().GetFilePath("crt1.o")));
3670 CmdArgs.push_back(Args.MakeArgString(
3671 getToolChain().GetFilePath("crti.o")));
3672 CmdArgs.push_back(Args.MakeArgString(
3673 getToolChain().GetFilePath("crtbegin.o")));
3675 CmdArgs.push_back(Args.MakeArgString(
3676 getToolChain().GetFilePath("crti.o")));
3677 CmdArgs.push_back(Args.MakeArgString(
3678 getToolChain().GetFilePath("crtbeginS.o")));
3682 Args.AddAllArgs(CmdArgs, options::OPT_L);
3683 const ToolChain::path_list Paths = getToolChain().getFilePaths();
3684 for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
3686 CmdArgs.push_back(Args.MakeArgString(llvm::StringRef("-L") + *i));
3687 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
3688 Args.AddAllArgs(CmdArgs, options::OPT_e);
3689 Args.AddAllArgs(CmdArgs, options::OPT_s);
3690 Args.AddAllArgs(CmdArgs, options::OPT_t);
3691 Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
3692 Args.AddAllArgs(CmdArgs, options::OPT_r);
3694 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
3696 if (!Args.hasArg(options::OPT_nostdlib) &&
3697 !Args.hasArg(options::OPT_nodefaultlibs)) {
3699 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
3700 if (Args.hasArg(options::OPT_pg))
3701 CmdArgs.push_back("-lm_p");
3703 CmdArgs.push_back("-lm");
3705 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3706 // the default system libraries. Just mimic this for now.
3707 if (Args.hasArg(options::OPT_pg))
3708 CmdArgs.push_back("-lgcc_p");
3710 CmdArgs.push_back("-lgcc");
3711 if (Args.hasArg(options::OPT_static)) {
3712 CmdArgs.push_back("-lgcc_eh");
3713 } else if (Args.hasArg(options::OPT_pg)) {
3714 CmdArgs.push_back("-lgcc_eh_p");
3716 CmdArgs.push_back("--as-needed");
3717 CmdArgs.push_back("-lgcc_s");
3718 CmdArgs.push_back("--no-as-needed");
3721 if (Args.hasArg(options::OPT_pthread)) {
3722 if (Args.hasArg(options::OPT_pg))
3723 CmdArgs.push_back("-lpthread_p");
3725 CmdArgs.push_back("-lpthread");
3728 if (Args.hasArg(options::OPT_pg)) {
3729 if (Args.hasArg(options::OPT_shared))
3730 CmdArgs.push_back("-lc");
3732 CmdArgs.push_back("-lc_p");
3733 CmdArgs.push_back("-lgcc_p");
3735 CmdArgs.push_back("-lc");
3736 CmdArgs.push_back("-lgcc");
3739 if (Args.hasArg(options::OPT_static)) {
3740 CmdArgs.push_back("-lgcc_eh");
3741 } else if (Args.hasArg(options::OPT_pg)) {
3742 CmdArgs.push_back("-lgcc_eh_p");
3744 CmdArgs.push_back("--as-needed");
3745 CmdArgs.push_back("-lgcc_s");
3746 CmdArgs.push_back("--no-as-needed");
3750 if (!Args.hasArg(options::OPT_nostdlib) &&
3751 !Args.hasArg(options::OPT_nostartfiles)) {
3752 if (!Args.hasArg(options::OPT_shared))
3753 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3756 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3758 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3762 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
3765 Args.MakeArgString(getToolChain().GetProgramPath("ld"));
3766 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3769 void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
3770 const InputInfo &Output,
3771 const InputInfoList &Inputs,
3772 const ArgList &Args,
3773 const char *LinkingOutput) const {
3774 ArgStringList CmdArgs;
3776 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3777 // instruct as in the base system to assemble 32-bit code.
3778 if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
3779 getToolChain().getArch() == llvm::Triple::x86)
3780 CmdArgs.push_back("--32");
3783 // Set byte order explicitly
3784 if (getToolChain().getArchName() == "mips")
3785 CmdArgs.push_back("-EB");
3786 else if (getToolChain().getArchName() == "mipsel")
3787 CmdArgs.push_back("-EL");
3789 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
3790 options::OPT_Xassembler);
3792 CmdArgs.push_back("-o");
3793 CmdArgs.push_back(Output.getFilename());
3795 for (InputInfoList::const_iterator
3796 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3797 const InputInfo &II = *it;
3798 CmdArgs.push_back(II.getFilename());
3801 const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
3802 ToolTriple.getTriple(),
3804 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3807 void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA,
3808 const InputInfo &Output,
3809 const InputInfoList &Inputs,
3810 const ArgList &Args,
3811 const char *LinkingOutput) const {
3812 const Driver &D = getToolChain().getDriver();
3813 ArgStringList CmdArgs;
3815 if (!D.SysRoot.empty())
3816 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
3818 if (Args.hasArg(options::OPT_static)) {
3819 CmdArgs.push_back("-Bstatic");
3821 if (Args.hasArg(options::OPT_rdynamic))
3822 CmdArgs.push_back("-export-dynamic");
3823 CmdArgs.push_back("--eh-frame-hdr");
3824 if (Args.hasArg(options::OPT_shared)) {
3825 CmdArgs.push_back("-Bshareable");
3827 CmdArgs.push_back("-dynamic-linker");
3828 CmdArgs.push_back("/libexec/ld.elf_so");
3832 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3833 // instruct ld in the base system to link 32-bit code.
3834 if (ToolTriple.getArch() == llvm::Triple::x86_64 &&
3835 getToolChain().getArch() == llvm::Triple::x86) {
3836 CmdArgs.push_back("-m");
3837 CmdArgs.push_back("elf_i386");
3840 if (Output.isFilename()) {
3841 CmdArgs.push_back("-o");
3842 CmdArgs.push_back(Output.getFilename());
3844 assert(Output.isNothing() && "Invalid output.");
3847 if (!Args.hasArg(options::OPT_nostdlib) &&
3848 !Args.hasArg(options::OPT_nostartfiles)) {
3849 if (!Args.hasArg(options::OPT_shared)) {
3850 CmdArgs.push_back(Args.MakeArgString(
3851 getToolChain().GetFilePath("crt0.o")));
3852 CmdArgs.push_back(Args.MakeArgString(
3853 getToolChain().GetFilePath("crti.o")));
3854 CmdArgs.push_back(Args.MakeArgString(
3855 getToolChain().GetFilePath("crtbegin.o")));
3857 CmdArgs.push_back(Args.MakeArgString(
3858 getToolChain().GetFilePath("crti.o")));
3859 CmdArgs.push_back(Args.MakeArgString(
3860 getToolChain().GetFilePath("crtbeginS.o")));
3864 Args.AddAllArgs(CmdArgs, options::OPT_L);
3865 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
3866 Args.AddAllArgs(CmdArgs, options::OPT_e);
3867 Args.AddAllArgs(CmdArgs, options::OPT_s);
3868 Args.AddAllArgs(CmdArgs, options::OPT_t);
3869 Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
3870 Args.AddAllArgs(CmdArgs, options::OPT_r);
3872 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
3874 if (!Args.hasArg(options::OPT_nostdlib) &&
3875 !Args.hasArg(options::OPT_nodefaultlibs)) {
3877 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
3878 CmdArgs.push_back("-lm");
3880 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3881 // the default system libraries. Just mimic this for now.
3882 if (Args.hasArg(options::OPT_static)) {
3883 CmdArgs.push_back("-lgcc_eh");
3885 CmdArgs.push_back("--as-needed");
3886 CmdArgs.push_back("-lgcc_s");
3887 CmdArgs.push_back("--no-as-needed");
3889 CmdArgs.push_back("-lgcc");
3891 if (Args.hasArg(options::OPT_pthread))
3892 CmdArgs.push_back("-lpthread");
3893 CmdArgs.push_back("-lc");
3895 CmdArgs.push_back("-lgcc");
3896 if (Args.hasArg(options::OPT_static)) {
3897 CmdArgs.push_back("-lgcc_eh");
3899 CmdArgs.push_back("--as-needed");
3900 CmdArgs.push_back("-lgcc_s");
3901 CmdArgs.push_back("--no-as-needed");
3905 if (!Args.hasArg(options::OPT_nostdlib) &&
3906 !Args.hasArg(options::OPT_nostartfiles)) {
3907 if (!Args.hasArg(options::OPT_shared))
3908 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3911 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3913 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
3917 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
3919 const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(),
3920 ToolTriple.getTriple(),
3922 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3925 void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
3926 const InputInfo &Output,
3927 const InputInfoList &Inputs,
3928 const ArgList &Args,
3929 const char *LinkingOutput) const {
3930 ArgStringList CmdArgs;
3932 // Add --32/--64 to make sure we get the format we want.
3933 // This is incomplete
3934 if (getToolChain().getArch() == llvm::Triple::x86) {
3935 CmdArgs.push_back("--32");
3936 } else if (getToolChain().getArch() == llvm::Triple::x86_64) {
3937 CmdArgs.push_back("--64");
3938 } else if (getToolChain().getArch() == llvm::Triple::arm) {
3939 llvm::StringRef MArch = getToolChain().getArchName();
3940 if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a")
3941 CmdArgs.push_back("-mfpu=neon");
3944 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
3945 options::OPT_Xassembler);
3947 CmdArgs.push_back("-o");
3948 CmdArgs.push_back(Output.getFilename());
3950 for (InputInfoList::const_iterator
3951 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
3952 const InputInfo &II = *it;
3953 CmdArgs.push_back(II.getFilename());
3957 Args.MakeArgString(getToolChain().GetProgramPath("as"));
3958 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
3961 void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
3962 const InputInfo &Output,
3963 const InputInfoList &Inputs,
3964 const ArgList &Args,
3965 const char *LinkingOutput) const {
3966 const toolchains::Linux& ToolChain =
3967 static_cast<const toolchains::Linux&>(getToolChain());
3968 const Driver &D = ToolChain.getDriver();
3969 ArgStringList CmdArgs;
3971 // Silence warning for "clang -g foo.o -o foo"
3972 Args.ClaimAllArgs(options::OPT_g_Group);
3973 // and "clang -emit-llvm foo.o -o foo"
3974 Args.ClaimAllArgs(options::OPT_emit_llvm);
3975 // and for "clang -g foo.o -o foo". Other warning options are already
3976 // handled somewhere else.
3977 Args.ClaimAllArgs(options::OPT_w);
3979 if (!D.SysRoot.empty())
3980 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
3982 if (Args.hasArg(options::OPT_pie))
3983 CmdArgs.push_back("-pie");
3985 if (Args.hasArg(options::OPT_rdynamic))
3986 CmdArgs.push_back("-export-dynamic");
3988 if (Args.hasArg(options::OPT_s))
3989 CmdArgs.push_back("-s");
3991 for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(),
3992 e = ToolChain.ExtraOpts.end();
3994 CmdArgs.push_back(i->c_str());
3996 if (!Args.hasArg(options::OPT_static)) {
3997 CmdArgs.push_back("--eh-frame-hdr");
4000 CmdArgs.push_back("-m");
4001 if (ToolChain.getArch() == llvm::Triple::x86)
4002 CmdArgs.push_back("elf_i386");
4003 else if (ToolChain.getArch() == llvm::Triple::arm
4004 || ToolChain.getArch() == llvm::Triple::thumb)
4005 CmdArgs.push_back("armelf_linux_eabi");
4006 else if (ToolChain.getArch() == llvm::Triple::ppc)
4007 CmdArgs.push_back("elf32ppclinux");
4008 else if (ToolChain.getArch() == llvm::Triple::ppc64)
4009 CmdArgs.push_back("elf64ppc");
4011 CmdArgs.push_back("elf_x86_64");
4013 if (Args.hasArg(options::OPT_static)) {
4014 if (ToolChain.getArch() == llvm::Triple::arm
4015 || ToolChain.getArch() == llvm::Triple::thumb)
4016 CmdArgs.push_back("-Bstatic");
4018 CmdArgs.push_back("-static");
4019 } else if (Args.hasArg(options::OPT_shared)) {
4020 CmdArgs.push_back("-shared");
4023 if (ToolChain.getArch() == llvm::Triple::arm ||
4024 ToolChain.getArch() == llvm::Triple::thumb ||
4025 (!Args.hasArg(options::OPT_static) &&
4026 !Args.hasArg(options::OPT_shared))) {
4027 CmdArgs.push_back("-dynamic-linker");
4028 if (ToolChain.getArch() == llvm::Triple::x86)
4029 CmdArgs.push_back("/lib/ld-linux.so.2");
4030 else if (ToolChain.getArch() == llvm::Triple::arm ||
4031 ToolChain.getArch() == llvm::Triple::thumb)
4032 CmdArgs.push_back("/lib/ld-linux.so.3");
4033 else if (ToolChain.getArch() == llvm::Triple::ppc)
4034 CmdArgs.push_back("/lib/ld.so.1");
4035 else if (ToolChain.getArch() == llvm::Triple::ppc64)
4036 CmdArgs.push_back("/lib64/ld64.so.1");
4038 CmdArgs.push_back("/lib64/ld-linux-x86-64.so.2");
4041 CmdArgs.push_back("-o");
4042 CmdArgs.push_back(Output.getFilename());
4044 if (!Args.hasArg(options::OPT_nostdlib) &&
4045 !Args.hasArg(options::OPT_nostartfiles)) {
4046 const char *crt1 = NULL;
4047 if (!Args.hasArg(options::OPT_shared)){
4048 if (Args.hasArg(options::OPT_pie))
4054 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
4056 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
4058 const char *crtbegin;
4059 if (Args.hasArg(options::OPT_static))
4060 crtbegin = "crtbeginT.o";
4061 else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
4062 crtbegin = "crtbeginS.o";
4064 crtbegin = "crtbegin.o";
4065 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
4068 Args.AddAllArgs(CmdArgs, options::OPT_L);
4070 const ToolChain::path_list Paths = ToolChain.getFilePaths();
4072 for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
4074 CmdArgs.push_back(Args.MakeArgString(llvm::StringRef("-L") + *i));
4076 AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
4078 if (D.CCCIsCXX && !Args.hasArg(options::OPT_nostdlib)) {
4079 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
4080 CmdArgs.push_back("-lm");
4083 if (!Args.hasArg(options::OPT_nostdlib)) {
4084 if (Args.hasArg(options::OPT_static))
4085 CmdArgs.push_back("--start-group");
4088 CmdArgs.push_back("-lgcc");
4090 if (Args.hasArg(options::OPT_static)) {
4092 CmdArgs.push_back("-lgcc");
4095 CmdArgs.push_back("--as-needed");
4096 CmdArgs.push_back("-lgcc_s");
4098 CmdArgs.push_back("--no-as-needed");
4101 if (Args.hasArg(options::OPT_static))
4102 CmdArgs.push_back("-lgcc_eh");
4103 else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
4104 CmdArgs.push_back("-lgcc");
4106 if (Args.hasArg(options::OPT_pthread) ||
4107 Args.hasArg(options::OPT_pthreads))
4108 CmdArgs.push_back("-lpthread");
4110 CmdArgs.push_back("-lc");
4112 if (Args.hasArg(options::OPT_static))
4113 CmdArgs.push_back("--end-group");
4116 CmdArgs.push_back("-lgcc");
4119 CmdArgs.push_back("--as-needed");
4120 CmdArgs.push_back("-lgcc_s");
4122 CmdArgs.push_back("--no-as-needed");
4124 if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
4125 CmdArgs.push_back("-lgcc");
4129 if (!Args.hasArg(options::OPT_nostartfiles)) {
4131 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
4132 crtend = "crtendS.o";
4134 crtend = "crtend.o";
4136 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend)));
4137 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
4141 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
4143 if (Args.hasArg(options::OPT_use_gold_plugin)) {
4144 CmdArgs.push_back("-plugin");
4145 std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so";
4146 CmdArgs.push_back(Args.MakeArgString(Plugin));
4149 C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs));
4152 void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
4153 const InputInfo &Output,
4154 const InputInfoList &Inputs,
4155 const ArgList &Args,
4156 const char *LinkingOutput) const {
4157 ArgStringList CmdArgs;
4159 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
4160 options::OPT_Xassembler);
4162 CmdArgs.push_back("-o");
4163 CmdArgs.push_back(Output.getFilename());
4165 for (InputInfoList::const_iterator
4166 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
4167 const InputInfo &II = *it;
4168 CmdArgs.push_back(II.getFilename());
4172 Args.MakeArgString(getToolChain().GetProgramPath("gas"));
4173 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
4176 void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
4177 const InputInfo &Output,
4178 const InputInfoList &Inputs,
4179 const ArgList &Args,
4180 const char *LinkingOutput) const {
4181 const Driver &D = getToolChain().getDriver();
4182 ArgStringList CmdArgs;
4184 if (Output.isFilename()) {
4185 CmdArgs.push_back("-o");
4186 CmdArgs.push_back(Output.getFilename());
4188 assert(Output.isNothing() && "Invalid output.");
4191 if (!Args.hasArg(options::OPT_nostdlib) &&
4192 !Args.hasArg(options::OPT_nostartfiles))
4193 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
4194 "/usr/gnu/lib/crtso.o")));
4196 Args.AddAllArgs(CmdArgs, options::OPT_L);
4197 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
4198 Args.AddAllArgs(CmdArgs, options::OPT_e);
4200 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
4202 if (!Args.hasArg(options::OPT_nostdlib) &&
4203 !Args.hasArg(options::OPT_nodefaultlibs)) {
4205 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
4206 CmdArgs.push_back("-lm");
4209 if (Args.hasArg(options::OPT_pthread))
4210 CmdArgs.push_back("-lpthread");
4211 CmdArgs.push_back("-lc");
4212 CmdArgs.push_back("-lgcc");
4213 CmdArgs.push_back("-L/usr/gnu/lib");
4214 // FIXME: fill in the correct search path for the final
4215 // support libraries.
4216 CmdArgs.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
4219 if (!Args.hasArg(options::OPT_nostdlib) &&
4220 !Args.hasArg(options::OPT_nostartfiles)) {
4221 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(
4222 "/usr/gnu/lib/libend.a")));
4225 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
4228 Args.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
4229 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
4234 // For now, DragonFly Assemble does just about the same as for
4235 // FreeBSD, but this may change soon.
4236 void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
4237 const InputInfo &Output,
4238 const InputInfoList &Inputs,
4239 const ArgList &Args,
4240 const char *LinkingOutput) const {
4241 ArgStringList CmdArgs;
4243 // When building 32-bit code on DragonFly/pc64, we have to explicitly
4244 // instruct as in the base system to assemble 32-bit code.
4245 if (getToolChain().getArchName() == "i386")
4246 CmdArgs.push_back("--32");
4248 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
4249 options::OPT_Xassembler);
4251 CmdArgs.push_back("-o");
4252 CmdArgs.push_back(Output.getFilename());
4254 for (InputInfoList::const_iterator
4255 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
4256 const InputInfo &II = *it;
4257 CmdArgs.push_back(II.getFilename());
4261 Args.MakeArgString(getToolChain().GetProgramPath("as"));
4262 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
4265 void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA,
4266 const InputInfo &Output,
4267 const InputInfoList &Inputs,
4268 const ArgList &Args,
4269 const char *LinkingOutput) const {
4270 const Driver &D = getToolChain().getDriver();
4271 ArgStringList CmdArgs;
4273 if (!D.SysRoot.empty())
4274 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
4276 if (Args.hasArg(options::OPT_static)) {
4277 CmdArgs.push_back("-Bstatic");
4279 if (Args.hasArg(options::OPT_shared))
4280 CmdArgs.push_back("-Bshareable");
4282 CmdArgs.push_back("-dynamic-linker");
4283 CmdArgs.push_back("/usr/libexec/ld-elf.so.2");
4287 // When building 32-bit code on DragonFly/pc64, we have to explicitly
4288 // instruct ld in the base system to link 32-bit code.
4289 if (getToolChain().getArchName() == "i386") {
4290 CmdArgs.push_back("-m");
4291 CmdArgs.push_back("elf_i386");
4294 if (Output.isFilename()) {
4295 CmdArgs.push_back("-o");
4296 CmdArgs.push_back(Output.getFilename());
4298 assert(Output.isNothing() && "Invalid output.");
4301 if (!Args.hasArg(options::OPT_nostdlib) &&
4302 !Args.hasArg(options::OPT_nostartfiles)) {
4303 if (!Args.hasArg(options::OPT_shared)) {
4305 Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
4307 Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
4309 Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
4312 Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
4314 Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
4318 Args.AddAllArgs(CmdArgs, options::OPT_L);
4319 Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
4320 Args.AddAllArgs(CmdArgs, options::OPT_e);
4322 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
4324 if (!Args.hasArg(options::OPT_nostdlib) &&
4325 !Args.hasArg(options::OPT_nodefaultlibs)) {
4326 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
4328 CmdArgs.push_back("-L/usr/lib/gcc41");
4330 if (!Args.hasArg(options::OPT_static)) {
4331 CmdArgs.push_back("-rpath");
4332 CmdArgs.push_back("/usr/lib/gcc41");
4334 CmdArgs.push_back("-rpath-link");
4335 CmdArgs.push_back("/usr/lib/gcc41");
4337 CmdArgs.push_back("-rpath");
4338 CmdArgs.push_back("/usr/lib");
4340 CmdArgs.push_back("-rpath-link");
4341 CmdArgs.push_back("/usr/lib");
4345 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
4346 CmdArgs.push_back("-lm");
4349 if (Args.hasArg(options::OPT_shared)) {
4350 CmdArgs.push_back("-lgcc_pic");
4352 CmdArgs.push_back("-lgcc");
4356 if (Args.hasArg(options::OPT_pthread))
4357 CmdArgs.push_back("-lpthread");
4359 if (!Args.hasArg(options::OPT_nolibc)) {
4360 CmdArgs.push_back("-lc");
4363 if (Args.hasArg(options::OPT_shared)) {
4364 CmdArgs.push_back("-lgcc_pic");
4366 CmdArgs.push_back("-lgcc");
4370 if (!Args.hasArg(options::OPT_nostdlib) &&
4371 !Args.hasArg(options::OPT_nostartfiles)) {
4372 if (!Args.hasArg(options::OPT_shared))
4373 CmdArgs.push_back(Args.MakeArgString(
4374 getToolChain().GetFilePath("crtend.o")));
4376 CmdArgs.push_back(Args.MakeArgString(
4377 getToolChain().GetFilePath("crtendS.o")));
4378 CmdArgs.push_back(Args.MakeArgString(
4379 getToolChain().GetFilePath("crtn.o")));
4382 addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
4385 Args.MakeArgString(getToolChain().GetProgramPath("ld"));
4386 C.addCommand(new Command(JA, *this, Exec, CmdArgs));
4389 void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
4390 const InputInfo &Output,
4391 const InputInfoList &Inputs,
4392 const ArgList &Args,
4393 const char *LinkingOutput) const {
4394 ArgStringList CmdArgs;
4396 if (Output.isFilename()) {
4397 CmdArgs.push_back(Args.MakeArgString(std::string("-out:") +
4398 Output.getFilename()));
4400 assert(Output.isNothing() && "Invalid output.");
4403 if (!Args.hasArg(options::OPT_nostdlib) &&
4404 !Args.hasArg(options::OPT_nostartfiles)) {
4405 CmdArgs.push_back("-defaultlib:libcmt");
4408 CmdArgs.push_back("-nologo");
4410 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
4413 Args.MakeArgString(getToolChain().GetProgramPath("link.exe"));
4414 C.addCommand(new Command(JA, *this, Exec, CmdArgs));