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/Option.h"
21 #include "clang/Driver/Options.h"
22 #include "clang/Driver/ToolChain.h"
23 #include "clang/Driver/Util.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/ADT/Twine.h"
28 #include "llvm/Support/Format.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/System/Host.h"
31 #include "llvm/System/Process.h"
33 #include "InputInfo.h"
34 #include "ToolChains.h"
36 using namespace clang::driver
;
37 using namespace clang::driver::tools
;
39 /// CheckPreprocessingOptions - Perform some validation of preprocessing
40 /// arguments that is shared with gcc.
41 static void CheckPreprocessingOptions(const Driver
&D
, const ArgList
&Args
) {
42 if (Arg
*A
= Args
.getLastArg(options::OPT_C
, options::OPT_CC
))
43 if (!Args
.hasArg(options::OPT_E
))
44 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
45 << A
->getAsString(Args
) << "-E";
48 /// CheckCodeGenerationOptions - Perform some validation of code generation
49 /// arguments that is shared with gcc.
50 static void CheckCodeGenerationOptions(const Driver
&D
, const ArgList
&Args
) {
51 // In gcc, only ARM checks this, but it seems reasonable to check universally.
52 if (Args
.hasArg(options::OPT_static
))
53 if (const Arg
*A
= Args
.getLastArg(options::OPT_dynamic
,
54 options::OPT_mdynamic_no_pic
))
55 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
56 << A
->getAsString(Args
) << "-static";
59 // Quote target names for inclusion in GNU Make dependency files.
60 // Only the characters '$', '#', ' ', '\t' are quoted.
61 static void QuoteTarget(llvm::StringRef Target
,
62 llvm::SmallVectorImpl
<char> &Res
) {
63 for (unsigned i
= 0, e
= Target
.size(); i
!= e
; ++i
) {
67 // Escape the preceding backslashes
68 for (int j
= i
- 1; j
>= 0 && Target
[j
] == '\\'; --j
)
71 // Escape the space/tab
84 Res
.push_back(Target
[i
]);
88 static void AddLinkerInputs(const ToolChain
&TC
,
89 const InputInfoList
&Inputs
, const ArgList
&Args
,
90 ArgStringList
&CmdArgs
) {
91 const Driver
&D
= TC
.getDriver();
93 for (InputInfoList::const_iterator
94 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
95 const InputInfo
&II
= *it
;
97 if (!TC
.HasNativeLLVMSupport()) {
98 // Don't try to pass LLVM inputs unless we have native support.
99 if (II
.getType() == types::TY_LLVM_IR
||
100 II
.getType() == types::TY_LTO_IR
||
101 II
.getType() == types::TY_LLVM_BC
||
102 II
.getType() == types::TY_LTO_BC
)
103 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
104 << TC
.getTripleString();
107 // Add filenames immediately.
108 if (II
.isFilename()) {
109 CmdArgs
.push_back(II
.getFilename());
113 // Otherwise, this is a linker input argument.
114 const Arg
&A
= II
.getInputArg();
116 // Handle reserved library options.
117 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
118 TC
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
119 } else if (A
.getOption().matches(options::OPT_Z_reserved_lib_cckext
)) {
120 TC
.AddCCKextLibArgs(Args
, CmdArgs
);
122 A
.renderAsInput(Args
, CmdArgs
);
126 void Clang::AddPreprocessingOptions(const Driver
&D
,
128 ArgStringList
&CmdArgs
,
129 const InputInfo
&Output
,
130 const InputInfoList
&Inputs
) const {
133 CheckPreprocessingOptions(D
, Args
);
135 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
136 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
138 // Handle dependency file generation.
139 if ((A
= Args
.getLastArg(options::OPT_M
)) ||
140 (A
= Args
.getLastArg(options::OPT_MM
)) ||
141 (A
= Args
.getLastArg(options::OPT_MD
)) ||
142 (A
= Args
.getLastArg(options::OPT_MMD
))) {
143 // Determine the output location.
145 if (Output
.getType() == types::TY_Dependencies
) {
146 DepFile
= Output
.getFilename();
147 } else if (Arg
*MF
= Args
.getLastArg(options::OPT_MF
)) {
148 DepFile
= MF
->getValue(Args
);
149 } else if (A
->getOption().matches(options::OPT_M
) ||
150 A
->getOption().matches(options::OPT_MM
)) {
153 DepFile
= darwin::CC1::getDependencyFileName(Args
, Inputs
);
155 CmdArgs
.push_back("-dependency-file");
156 CmdArgs
.push_back(DepFile
);
158 // Add a default target if one wasn't specified.
159 if (!Args
.hasArg(options::OPT_MT
) && !Args
.hasArg(options::OPT_MQ
)) {
160 const char *DepTarget
;
162 // If user provided -o, that is the dependency target, except
163 // when we are only generating a dependency file.
164 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
165 if (OutputOpt
&& Output
.getType() != types::TY_Dependencies
) {
166 DepTarget
= OutputOpt
->getValue(Args
);
168 // Otherwise derive from the base input.
170 // FIXME: This should use the computed output file location.
171 llvm::sys::Path
P(Inputs
[0].getBaseInput());
175 DepTarget
= Args
.MakeArgString(P
.getLast());
178 CmdArgs
.push_back("-MT");
179 llvm::SmallString
<128> Quoted
;
180 QuoteTarget(DepTarget
, Quoted
);
181 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
184 if (A
->getOption().matches(options::OPT_M
) ||
185 A
->getOption().matches(options::OPT_MD
))
186 CmdArgs
.push_back("-sys-header-deps");
189 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
191 // Convert all -MQ <target> args to -MT <quoted target>
192 for (arg_iterator it
= Args
.filtered_begin(options::OPT_MT
,
194 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
198 if (A
->getOption().matches(options::OPT_MQ
)) {
199 CmdArgs
.push_back("-MT");
200 llvm::SmallString
<128> Quoted
;
201 QuoteTarget(A
->getValue(Args
), Quoted
);
202 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
204 // -MT flag - no change
206 A
->render(Args
, CmdArgs
);
210 // Add -i* options, and automatically translate to
211 // -include-pch/-include-pth for transparent PCH support. It's
212 // wonky, but we include looking for .gch so we can support seamless
213 // replacement into a build system already set up to be generating
215 bool RenderedImplicitInclude
= false;
216 for (arg_iterator it
= Args
.filtered_begin(options::OPT_clang_i_Group
),
217 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
220 if (A
->getOption().matches(options::OPT_include
)) {
221 bool IsFirstImplicitInclude
= !RenderedImplicitInclude
;
222 RenderedImplicitInclude
= true;
224 // Use PCH if the user requested it.
225 bool UsePCH
= D
.CCCUsePCH
;
227 bool FoundPTH
= false;
228 bool FoundPCH
= false;
229 llvm::sys::Path
P(A
->getValue(Args
));
231 P
.appendSuffix("pch");
239 P
.appendSuffix("pth");
246 if (!FoundPCH
&& !FoundPTH
) {
247 P
.appendSuffix("gch");
256 if (FoundPCH
|| FoundPTH
) {
257 if (IsFirstImplicitInclude
) {
260 CmdArgs
.push_back("-include-pch");
262 CmdArgs
.push_back("-include-pth");
263 CmdArgs
.push_back(Args
.MakeArgString(P
.str()));
266 // Ignore the PCH if not first on command line and emit warning.
267 D
.Diag(clang::diag::warn_drv_pch_not_first_include
)
268 << P
.str() << A
->getAsString(Args
);
273 // Not translated, render as usual.
275 A
->render(Args
, CmdArgs
);
278 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
);
279 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
281 // Add C++ include arguments, if needed.
282 types::ID InputType
= Inputs
[0].getType();
283 if (types::isCXX(InputType
))
284 getToolChain().AddClangCXXStdlibIncludeArgs(Args
, CmdArgs
);
286 // Add -Wp, and -Xassembler if using the preprocessor.
288 // FIXME: There is a very unfortunate problem here, some troubled
289 // souls abuse -Wp, to pass preprocessor options in gcc syntax. To
290 // really support that we would have to parse and then translate
292 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
293 options::OPT_Xpreprocessor
);
295 // -I- is a deprecated GCC feature, reject it.
296 if (Arg
*A
= Args
.getLastArg(options::OPT_I_
))
297 D
.Diag(clang::diag::err_drv_I_dash_not_supported
) << A
->getAsString(Args
);
299 // If we have a --sysroot, and don't have an explicit -isysroot flag, add an
300 // -isysroot to the CC1 invocation.
301 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
302 if (!Args
.hasArg(options::OPT_isysroot
)) {
303 CmdArgs
.push_back("-isysroot");
304 CmdArgs
.push_back(A
->getValue(Args
));
309 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.
311 // FIXME: tblgen this.
312 static const char *getARMTargetCPU(const ArgList
&Args
,
313 const llvm::Triple
&Triple
) {
314 // FIXME: Warn on inconsistent use of -mcpu and -march.
316 // If we have -mcpu=, use that.
317 if (Arg
*A
= Args
.getLastArg(options::OPT_mcpu_EQ
))
318 return A
->getValue(Args
);
320 llvm::StringRef MArch
;
321 if (Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
322 // Otherwise, if we have -march= choose the base CPU for that arch.
323 MArch
= A
->getValue(Args
);
325 // Otherwise, use the Arch from the triple.
326 MArch
= Triple
.getArchName();
329 if (MArch
== "armv2" || MArch
== "armv2a")
331 if (MArch
== "armv3")
333 if (MArch
== "armv3m")
335 if (MArch
== "armv4" || MArch
== "armv4t")
337 if (MArch
== "armv5" || MArch
== "armv5t")
339 if (MArch
== "armv5e" || MArch
== "armv5te")
341 if (MArch
== "armv5tej")
343 if (MArch
== "armv6" || MArch
== "armv6k")
344 return "arm1136jf-s";
345 if (MArch
== "armv6j")
347 if (MArch
== "armv6z" || MArch
== "armv6zk")
348 return "arm1176jzf-s";
349 if (MArch
== "armv6t2")
350 return "arm1156t2-s";
351 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
353 if (MArch
== "armv7r" || MArch
== "armv7-r")
355 if (MArch
== "armv7m" || MArch
== "armv7-m")
357 if (MArch
== "ep9312")
359 if (MArch
== "iwmmxt")
361 if (MArch
== "xscale")
364 // If all else failed, return the most base CPU LLVM supports.
368 /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
371 // FIXME: This is redundant with -mcpu, why does LLVM use this.
372 // FIXME: tblgen this, or kill it!
373 static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU
) {
374 if (CPU
== "arm7tdmi" || CPU
== "arm7tdmi-s" || CPU
== "arm710t" ||
375 CPU
== "arm720t" || CPU
== "arm9" || CPU
== "arm9tdmi" ||
376 CPU
== "arm920" || CPU
== "arm920t" || CPU
== "arm922t" ||
377 CPU
== "arm940t" || CPU
== "ep9312")
380 if (CPU
== "arm10tdmi" || CPU
== "arm1020t")
383 if (CPU
== "arm9e" || CPU
== "arm926ej-s" || CPU
== "arm946e-s" ||
384 CPU
== "arm966e-s" || CPU
== "arm968e-s" || CPU
== "arm10e" ||
385 CPU
== "arm1020e" || CPU
== "arm1022e" || CPU
== "xscale" ||
389 if (CPU
== "arm1136j-s" || CPU
== "arm1136jf-s" || CPU
== "arm1176jz-s" ||
390 CPU
== "arm1176jzf-s" || CPU
== "mpcorenovfp" || CPU
== "mpcore")
393 if (CPU
== "arm1156t2-s" || CPU
== "arm1156t2f-s")
396 if (CPU
== "cortex-a8" || CPU
== "cortex-a9")
402 // FIXME: Move to target hook.
403 static bool isSignedCharDefault(const llvm::Triple
&Triple
) {
404 switch (Triple
.getArch()) {
408 case llvm::Triple::ppc
:
409 case llvm::Triple::ppc64
:
410 if (Triple
.getOS() == llvm::Triple::Darwin
)
414 case llvm::Triple::systemz
:
419 void Clang::AddARMTargetArgs(const ArgList
&Args
,
420 ArgStringList
&CmdArgs
) const {
421 const Driver
&D
= getToolChain().getDriver();
422 llvm::Triple Triple
= getToolChain().getTriple();
424 // Select the ABI to use.
426 // FIXME: Support -meabi.
427 const char *ABIName
= 0;
428 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
429 ABIName
= A
->getValue(Args
);
431 // Select the default based on the platform.
432 llvm::StringRef env
= Triple
.getEnvironmentName();
433 if (env
== "gnueabi")
434 ABIName
= "aapcs-linux";
435 else if (env
== "eabi")
438 ABIName
= "apcs-gnu";
440 CmdArgs
.push_back("-target-abi");
441 CmdArgs
.push_back(ABIName
);
443 // Set the CPU based on -march= and -mcpu=.
444 CmdArgs
.push_back("-target-cpu");
445 CmdArgs
.push_back(getARMTargetCPU(Args
, Triple
));
447 // Select the float ABI as determined by -msoft-float, -mhard-float, and
449 llvm::StringRef FloatABI
;
450 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
451 options::OPT_mhard_float
,
452 options::OPT_mfloat_abi_EQ
)) {
453 if (A
->getOption().matches(options::OPT_msoft_float
))
455 else if (A
->getOption().matches(options::OPT_mhard_float
))
458 FloatABI
= A
->getValue(Args
);
459 if (FloatABI
!= "soft" && FloatABI
!= "softfp" && FloatABI
!= "hard") {
460 D
.Diag(clang::diag::err_drv_invalid_mfloat_abi
)
461 << A
->getAsString(Args
);
467 // If unspecified, choose the default based on the platform.
468 if (FloatABI
.empty()) {
469 const llvm::Triple
&Triple
= getToolChain().getTriple();
470 switch (Triple
.getOS()) {
471 case llvm::Triple::Darwin
: {
472 // Darwin defaults to "softfp" for v6 and v7.
474 // FIXME: Factor out an ARM class so we can cache the arch somewhere.
475 llvm::StringRef ArchName
=
476 getLLVMArchSuffixForARM(getARMTargetCPU(Args
, Triple
));
477 if (ArchName
.startswith("v6") || ArchName
.startswith("v7"))
484 case llvm::Triple::Linux
: {
485 llvm::StringRef Env
= getToolChain().getTriple().getEnvironmentName();
486 if (Env
== "gnueabi") {
494 // Assume "soft", but warn the user we are guessing.
496 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
501 if (FloatABI
== "soft") {
502 // Floating point operations and argument passing are soft.
504 // FIXME: This changes CPP defines, we need -target-soft-float.
505 CmdArgs
.push_back("-msoft-float");
506 CmdArgs
.push_back("-mfloat-abi");
507 CmdArgs
.push_back("soft");
508 } else if (FloatABI
== "softfp") {
509 // Floating point operations are hard, but argument passing is soft.
510 CmdArgs
.push_back("-mfloat-abi");
511 CmdArgs
.push_back("soft");
513 // Floating point operations and argument passing are hard.
514 assert(FloatABI
== "hard" && "Invalid float abi!");
515 CmdArgs
.push_back("-mfloat-abi");
516 CmdArgs
.push_back("hard");
519 // Set appropriate target features for floating point mode.
521 // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
522 // yet (it uses the -mfloat-abi and -msoft-float options above), and it is
523 // stripped out by the ARM target.
525 // Use software floating point operations?
526 if (FloatABI
== "soft") {
527 CmdArgs
.push_back("-target-feature");
528 CmdArgs
.push_back("+soft-float");
531 // Use software floating point argument passing?
532 if (FloatABI
!= "hard") {
533 CmdArgs
.push_back("-target-feature");
534 CmdArgs
.push_back("+soft-float-abi");
539 // FIXME: Centralize feature selection, defaulting shouldn't be also in the
541 if (const Arg
*A
= Args
.getLastArg(options::OPT_mfpu_EQ
)) {
542 llvm::StringRef FPU
= A
->getValue(Args
);
544 // Set the target features based on the FPU.
545 if (FPU
== "fpa" || FPU
== "fpe2" || FPU
== "fpe3" || FPU
== "maverick") {
546 // Disable any default FPU support.
547 CmdArgs
.push_back("-target-feature");
548 CmdArgs
.push_back("-vfp2");
549 CmdArgs
.push_back("-target-feature");
550 CmdArgs
.push_back("-vfp3");
551 CmdArgs
.push_back("-target-feature");
552 CmdArgs
.push_back("-neon");
553 } else if (FPU
== "vfp") {
554 CmdArgs
.push_back("-target-feature");
555 CmdArgs
.push_back("+vfp2");
556 } else if (FPU
== "vfp3") {
557 CmdArgs
.push_back("-target-feature");
558 CmdArgs
.push_back("+vfp3");
559 } else if (FPU
== "neon") {
560 CmdArgs
.push_back("-target-feature");
561 CmdArgs
.push_back("+neon");
563 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
567 void Clang::AddMIPSTargetArgs(const ArgList
&Args
,
568 ArgStringList
&CmdArgs
) const {
569 const Driver
&D
= getToolChain().getDriver();
571 // Select the ABI to use.
572 const char *ABIName
= 0;
573 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
574 ABIName
= A
->getValue(Args
);
579 CmdArgs
.push_back("-target-abi");
580 CmdArgs
.push_back(ABIName
);
582 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
583 llvm::StringRef MArch
= A
->getValue(Args
);
584 CmdArgs
.push_back("-target-cpu");
586 if ((MArch
== "r2000") || (MArch
== "r3000"))
587 CmdArgs
.push_back("mips1");
588 else if (MArch
== "r6000")
589 CmdArgs
.push_back("mips2");
591 CmdArgs
.push_back(MArch
.str().c_str());
594 // Select the float ABI as determined by -msoft-float, -mhard-float, and
595 llvm::StringRef FloatABI
;
596 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
597 options::OPT_mhard_float
)) {
598 if (A
->getOption().matches(options::OPT_msoft_float
))
600 else if (A
->getOption().matches(options::OPT_mhard_float
))
604 // If unspecified, choose the default based on the platform.
605 if (FloatABI
.empty()) {
606 // Assume "soft", but warn the user we are guessing.
608 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
611 if (FloatABI
== "soft") {
612 // Floating point operations and argument passing are soft.
614 // FIXME: This changes CPP defines, we need -target-soft-float.
615 CmdArgs
.push_back("-msoft-float");
617 assert(FloatABI
== "hard" && "Invalid float abi!");
618 CmdArgs
.push_back("-mhard-float");
622 void Clang::AddX86TargetArgs(const ArgList
&Args
,
623 ArgStringList
&CmdArgs
) const {
624 if (!Args
.hasFlag(options::OPT_mred_zone
,
625 options::OPT_mno_red_zone
,
627 Args
.hasArg(options::OPT_mkernel
) ||
628 Args
.hasArg(options::OPT_fapple_kext
))
629 CmdArgs
.push_back("-disable-red-zone");
631 if (Args
.hasFlag(options::OPT_msoft_float
,
632 options::OPT_mno_soft_float
,
634 CmdArgs
.push_back("-no-implicit-float");
636 const char *CPUName
= 0;
637 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
638 if (llvm::StringRef(A
->getValue(Args
)) == "native") {
639 // FIXME: Reject attempts to use -march=native unless the target matches
642 // FIXME: We should also incorporate the detected target features for use
644 std::string CPU
= llvm::sys::getHostCPUName();
646 CPUName
= Args
.MakeArgString(CPU
);
648 CPUName
= A
->getValue(Args
);
651 // Select the default CPU if none was given (or detection failed).
653 // FIXME: Need target hooks.
654 if (getToolChain().getOS().startswith("darwin")) {
655 if (getToolChain().getArchName() == "x86_64")
657 else if (getToolChain().getArchName() == "i386")
659 } else if (getToolChain().getOS().startswith("haiku")) {
660 if (getToolChain().getArchName() == "x86_64")
662 else if (getToolChain().getArchName() == "i386")
664 } else if (getToolChain().getOS().startswith("openbsd")) {
665 if (getToolChain().getArchName() == "x86_64")
667 else if (getToolChain().getArchName() == "i386")
670 if (getToolChain().getArchName() == "x86_64")
672 else if (getToolChain().getArchName() == "i386")
673 CPUName
= "pentium4";
678 CmdArgs
.push_back("-target-cpu");
679 CmdArgs
.push_back(CPUName
);
682 for (arg_iterator it
= Args
.filtered_begin(options::OPT_m_x86_Features_Group
),
683 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
684 llvm::StringRef Name
= (*it
)->getOption().getName();
688 assert(Name
.startswith("-m") && "Invalid feature name.");
689 Name
= Name
.substr(2);
691 bool IsNegative
= Name
.startswith("no-");
693 Name
= Name
.substr(3);
695 CmdArgs
.push_back("-target-feature");
696 CmdArgs
.push_back(Args
.MakeArgString((IsNegative
? "-" : "+") + Name
));
700 static bool needsExceptions(const ArgList
&Args
, types::ID InputType
,
701 const llvm::Triple
&Triple
) {
702 // Handle -fno-exceptions.
703 if (Arg
*A
= Args
.getLastArg(options::OPT_fexceptions
,
704 options::OPT_fno_exceptions
)) {
705 if (A
->getOption().matches(options::OPT_fexceptions
))
711 // Otherwise, C++ inputs use exceptions.
712 if (types::isCXX(InputType
))
715 // As do Objective-C non-fragile ABI inputs and all Objective-C inputs on
716 // x86_64 and ARM after SnowLeopard.
717 if (types::isObjC(InputType
)) {
718 if (Args
.hasArg(options::OPT_fobjc_nonfragile_abi
))
720 if (Triple
.getOS() != llvm::Triple::Darwin
)
722 return (Triple
.getDarwinMajorNumber() >= 9 &&
723 (Triple
.getArch() == llvm::Triple::x86_64
||
724 Triple
.getArch() == llvm::Triple::arm
));
730 void Clang::ConstructJob(Compilation
&C
, const JobAction
&JA
,
731 const InputInfo
&Output
,
732 const InputInfoList
&Inputs
,
734 const char *LinkingOutput
) const {
735 bool KernelOrKext
= Args
.hasArg(options::OPT_mkernel
,
736 options::OPT_fapple_kext
);
737 const Driver
&D
= getToolChain().getDriver();
738 ArgStringList CmdArgs
;
740 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
742 // Invoke ourselves in -cc1 mode.
744 // FIXME: Implement custom jobs for internal actions.
745 CmdArgs
.push_back("-cc1");
747 // Add the "effective" target triple.
748 CmdArgs
.push_back("-triple");
749 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
750 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
752 // Select the appropriate action.
753 bool IsRewriter
= false;
754 if (isa
<AnalyzeJobAction
>(JA
)) {
755 assert(JA
.getType() == types::TY_Plist
&& "Invalid output type.");
756 CmdArgs
.push_back("-analyze");
757 } else if (isa
<PreprocessJobAction
>(JA
)) {
758 if (Output
.getType() == types::TY_Dependencies
)
759 CmdArgs
.push_back("-Eonly");
761 CmdArgs
.push_back("-E");
762 } else if (isa
<AssembleJobAction
>(JA
)) {
763 CmdArgs
.push_back("-emit-obj");
765 // At -O0, we use -mrelax-all by default.
767 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
768 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
769 if (Args
.hasFlag(options::OPT_mrelax_all
,
770 options::OPT_mno_relax_all
,
772 CmdArgs
.push_back("-mrelax-all");
774 // When using an integrated assembler, translate -Wa, and -Xassembler
776 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Wa_COMMA
,
777 options::OPT_Xassembler
),
778 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
782 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
) {
783 llvm::StringRef Value
= A
->getValue(Args
, i
);
785 if (Value
== "-force_cpusubtype_ALL") {
786 // Do nothing, this is the default and we don't support anything else.
787 } else if (Value
== "-L") {
788 // We don't support -L yet, but it isn't important enough to error
789 // on. No one should really be using it for a semantic change.
790 D
.Diag(clang::diag::warn_drv_unsupported_option_argument
)
791 << A
->getOption().getName() << Value
;
793 D
.Diag(clang::diag::err_drv_unsupported_option_argument
)
794 << A
->getOption().getName() << Value
;
798 } else if (isa
<PrecompileJobAction
>(JA
)) {
799 // Use PCH if the user requested it.
800 bool UsePCH
= D
.CCCUsePCH
;
803 CmdArgs
.push_back("-emit-pch");
805 CmdArgs
.push_back("-emit-pth");
807 assert(isa
<CompileJobAction
>(JA
) && "Invalid action for clang tool.");
809 if (JA
.getType() == types::TY_Nothing
) {
810 CmdArgs
.push_back("-fsyntax-only");
811 } else if (JA
.getType() == types::TY_LLVM_IR
||
812 JA
.getType() == types::TY_LTO_IR
) {
813 CmdArgs
.push_back("-emit-llvm");
814 } else if (JA
.getType() == types::TY_LLVM_BC
||
815 JA
.getType() == types::TY_LTO_BC
) {
816 CmdArgs
.push_back("-emit-llvm-bc");
817 } else if (JA
.getType() == types::TY_PP_Asm
) {
818 CmdArgs
.push_back("-S");
819 } else if (JA
.getType() == types::TY_AST
) {
820 CmdArgs
.push_back("-emit-pch");
821 } else if (JA
.getType() == types::TY_RewrittenObjC
) {
822 CmdArgs
.push_back("-rewrite-objc");
825 assert(JA
.getType() == types::TY_PP_Asm
&&
826 "Unexpected output type!");
830 // The make clang go fast button.
831 CmdArgs
.push_back("-disable-free");
833 // Disable the verification pass in -asserts builds.
835 CmdArgs
.push_back("-disable-llvm-verifier");
838 // Set the main file name, so that debug info works even with
840 CmdArgs
.push_back("-main-file-name");
841 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
843 // Some flags which affect the language (via preprocessor
844 // defines). See darwin::CC1::AddCPPArgs.
845 if (Args
.hasArg(options::OPT_static
))
846 CmdArgs
.push_back("-static-define");
848 if (isa
<AnalyzeJobAction
>(JA
)) {
849 // Enable region store model by default.
850 CmdArgs
.push_back("-analyzer-store=region");
852 // Treat blocks as analysis entry points.
853 CmdArgs
.push_back("-analyzer-opt-analyze-nested-blocks");
855 // Add default argument set.
856 if (!Args
.hasArg(options::OPT__analyzer_no_default_checks
)) {
857 CmdArgs
.push_back("-analyzer-check-dead-stores");
858 // Do not enable the security-syntatic check since it
859 // it needs to be refined (known issues).
860 // CmdArgs.push_back("-analyzer-check-security-syntactic");
861 CmdArgs
.push_back("-analyzer-check-objc-mem");
862 CmdArgs
.push_back("-analyzer-eagerly-assume");
863 CmdArgs
.push_back("-analyzer-check-objc-methodsigs");
864 // Do not enable the missing -dealloc check.
865 // '-analyzer-check-objc-missing-dealloc',
866 CmdArgs
.push_back("-analyzer-check-objc-unused-ivars");
867 CmdArgs
.push_back("-analyzer-check-idempotent-operations");
870 // Set the output format. The default is plist, for (lame) historical
872 CmdArgs
.push_back("-analyzer-output");
873 if (Arg
*A
= Args
.getLastArg(options::OPT__analyzer_output
))
874 CmdArgs
.push_back(A
->getValue(Args
));
876 CmdArgs
.push_back("plist");
878 // Disable the presentation of standard compiler warnings when
879 // using --analyze. We only want to show static analyzer diagnostics
880 // or frontend errors.
881 CmdArgs
.push_back("-w");
883 // Add -Xanalyzer arguments when running as analyzer.
884 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xanalyzer
);
887 CheckCodeGenerationOptions(D
, Args
);
889 // Perform argument translation for LLVM backend. This
890 // takes some care in reconciling with llvm-gcc. The
891 // issue is that llvm-gcc translates these options based on
892 // the values in cc1, whereas we are processing based on
893 // the driver arguments.
895 // This comes from the default translation the driver + cc1
896 // would do to enable flag_pic.
898 // FIXME: Centralize this code.
899 bool PICEnabled
= (Args
.hasArg(options::OPT_fPIC
) ||
900 Args
.hasArg(options::OPT_fpic
) ||
901 Args
.hasArg(options::OPT_fPIE
) ||
902 Args
.hasArg(options::OPT_fpie
));
903 bool PICDisabled
= (Args
.hasArg(options::OPT_mkernel
) ||
904 Args
.hasArg(options::OPT_static
));
905 const char *Model
= getToolChain().GetForcedPicModel();
907 if (Args
.hasArg(options::OPT_mdynamic_no_pic
))
908 Model
= "dynamic-no-pic";
909 else if (PICDisabled
)
914 Model
= getToolChain().GetDefaultRelocationModel();
916 if (llvm::StringRef(Model
) != "pic") {
917 CmdArgs
.push_back("-mrelocation-model");
918 CmdArgs
.push_back(Model
);
921 // Infer the __PIC__ value.
923 // FIXME: This isn't quite right on Darwin, which always sets
925 if (strcmp(Model
, "pic") == 0 || strcmp(Model
, "dynamic-no-pic") == 0) {
926 CmdArgs
.push_back("-pic-level");
927 CmdArgs
.push_back(Args
.hasArg(options::OPT_fPIC
) ? "2" : "1");
929 if (!Args
.hasFlag(options::OPT_fmerge_all_constants
,
930 options::OPT_fno_merge_all_constants
))
931 CmdArgs
.push_back("-no-merge-all-constants");
933 // LLVM Code Generator Options.
935 // FIXME: Set --enable-unsafe-fp-math.
936 if (Args
.hasFlag(options::OPT_fno_omit_frame_pointer
,
937 options::OPT_fomit_frame_pointer
))
938 CmdArgs
.push_back("-mdisable-fp-elim");
939 if (!Args
.hasFlag(options::OPT_fzero_initialized_in_bss
,
940 options::OPT_fno_zero_initialized_in_bss
))
941 CmdArgs
.push_back("-mno-zero-initialized-in-bss");
942 if (Args
.hasFlag(options::OPT_fno_strict_aliasing
,
943 options::OPT_fstrict_aliasing
,
945 CmdArgs
.push_back("-relaxed-aliasing");
947 // Decide whether to use verbose asm. Verbose assembly is the default on
948 // toolchains which have the integrated assembler on by default.
949 bool IsVerboseAsmDefault
= getToolChain().IsIntegratedAssemblerDefault();
950 if (Args
.hasFlag(options::OPT_fverbose_asm
, options::OPT_fno_verbose_asm
,
951 IsVerboseAsmDefault
) ||
952 Args
.hasArg(options::OPT_dA
))
953 CmdArgs
.push_back("-masm-verbose");
955 if (Args
.hasArg(options::OPT_fdebug_pass_structure
)) {
956 CmdArgs
.push_back("-mdebug-pass");
957 CmdArgs
.push_back("Structure");
959 if (Args
.hasArg(options::OPT_fdebug_pass_arguments
)) {
960 CmdArgs
.push_back("-mdebug-pass");
961 CmdArgs
.push_back("Arguments");
964 // Enable -mconstructor-aliases except on darwin, where we have to
965 // work around a linker bug; see <rdar://problem/7651567>.
966 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin
)
967 CmdArgs
.push_back("-mconstructor-aliases");
969 // This is a coarse approximation of what llvm-gcc actually does, both
970 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
972 bool AsynchronousUnwindTables
=
973 Args
.hasFlag(options::OPT_fasynchronous_unwind_tables
,
974 options::OPT_fno_asynchronous_unwind_tables
,
975 getToolChain().IsUnwindTablesDefault() &&
977 if (Args
.hasFlag(options::OPT_funwind_tables
, options::OPT_fno_unwind_tables
,
978 AsynchronousUnwindTables
))
979 CmdArgs
.push_back("-munwind-tables");
981 if (Arg
*A
= Args
.getLastArg(options::OPT_flimited_precision_EQ
)) {
982 CmdArgs
.push_back("-mlimit-float-precision");
983 CmdArgs
.push_back(A
->getValue(Args
));
986 // FIXME: Handle -mtune=.
987 (void) Args
.hasArg(options::OPT_mtune_EQ
);
989 if (Arg
*A
= Args
.getLastArg(options::OPT_mcmodel_EQ
)) {
990 CmdArgs
.push_back("-mcode-model");
991 CmdArgs
.push_back(A
->getValue(Args
));
994 // Add target specific cpu and features flags.
995 switch(getToolChain().getTriple().getArch()) {
999 case llvm::Triple::arm
:
1000 case llvm::Triple::thumb
:
1001 AddARMTargetArgs(Args
, CmdArgs
);
1004 case llvm::Triple::mips
:
1005 case llvm::Triple::mipsel
:
1006 AddMIPSTargetArgs(Args
, CmdArgs
);
1009 case llvm::Triple::x86
:
1010 case llvm::Triple::x86_64
:
1011 AddX86TargetArgs(Args
, CmdArgs
);
1015 // Pass the linker version in use.
1016 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
1017 CmdArgs
.push_back("-target-linker-version");
1018 CmdArgs
.push_back(A
->getValue(Args
));
1021 // -mno-omit-leaf-frame-pointer is default.
1022 if (Args
.hasFlag(options::OPT_momit_leaf_frame_pointer
,
1023 options::OPT_mno_omit_leaf_frame_pointer
, false))
1024 CmdArgs
.push_back("-momit-leaf-frame-pointer");
1026 // -fno-math-errno is default.
1027 if (Args
.hasFlag(options::OPT_fmath_errno
,
1028 options::OPT_fno_math_errno
,
1030 CmdArgs
.push_back("-fmath-errno");
1032 // Explicitly error on some things we know we don't support and can't just
1034 types::ID InputType
= Inputs
[0].getType();
1035 if (!Args
.hasArg(options::OPT_fallow_unsupported
)) {
1037 if ((Unsupported
= Args
.getLastArg(options::OPT_MG
)) ||
1038 (Unsupported
= Args
.getLastArg(options::OPT_iframework
)))
1039 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1040 << Unsupported
->getOption().getName();
1042 if (types::isCXX(InputType
) &&
1043 getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1044 getToolChain().getTriple().getArch() == llvm::Triple::x86
) {
1045 if ((Unsupported
= Args
.getLastArg(options::OPT_fapple_kext
)))
1046 D
.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386
)
1047 << Unsupported
->getOption().getName();
1051 Args
.AddAllArgs(CmdArgs
, options::OPT_v
);
1052 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
1053 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
1054 Args
.AddLastArg(CmdArgs
, options::OPT_print_ivar_layout
);
1056 // Special case debug options to only pass -g to clang. This is
1058 Args
.ClaimAllArgs(options::OPT_g_Group
);
1059 if (Arg
*A
= Args
.getLastArg(options::OPT_g_Group
))
1060 if (!A
->getOption().matches(options::OPT_g0
))
1061 CmdArgs
.push_back("-g");
1063 Args
.AddAllArgs(CmdArgs
, options::OPT_ffunction_sections
);
1064 Args
.AddAllArgs(CmdArgs
, options::OPT_fdata_sections
);
1066 Args
.AddAllArgs(CmdArgs
, options::OPT_finstrument_functions
);
1068 Args
.AddLastArg(CmdArgs
, options::OPT_nostdinc
);
1069 Args
.AddLastArg(CmdArgs
, options::OPT_nostdincxx
);
1070 Args
.AddLastArg(CmdArgs
, options::OPT_nobuiltininc
);
1072 // Pass the path to compiler resource files.
1073 CmdArgs
.push_back("-resource-dir");
1074 CmdArgs
.push_back(D
.ResourceDir
.c_str());
1076 Args
.AddLastArg(CmdArgs
, options::OPT_working_directory
);
1078 // Add preprocessing options like -I, -D, etc. if we are using the
1081 // FIXME: Support -fpreprocessed
1082 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
)
1083 AddPreprocessingOptions(D
, Args
, CmdArgs
, Output
, Inputs
);
1085 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1087 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
)) {
1088 if (A
->getOption().matches(options::OPT_O4
))
1089 CmdArgs
.push_back("-O3");
1090 else if (A
->getOption().matches(options::OPT_O
) &&
1091 A
->getValue(Args
)[0] == '\0')
1092 CmdArgs
.push_back("-O2");
1094 A
->render(Args
, CmdArgs
);
1097 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
);
1098 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic
);
1099 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic_errors
);
1100 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1102 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1103 // (-ansi is equivalent to -std=c89).
1105 // If a std is supplied, only add -trigraphs if it follows the
1107 if (Arg
*Std
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1108 if (Std
->getOption().matches(options::OPT_ansi
))
1109 if (types::isCXX(InputType
))
1110 CmdArgs
.push_back("-std=c++98");
1112 CmdArgs
.push_back("-std=c89");
1114 Std
->render(Args
, CmdArgs
);
1116 if (Arg
*A
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
,
1117 options::OPT_trigraphs
))
1119 A
->render(Args
, CmdArgs
);
1121 // Honor -std-default.
1123 // FIXME: Clang doesn't correctly handle -std= when the input language
1124 // doesn't match. For the time being just ignore this for C++ inputs;
1125 // eventually we want to do all the standard defaulting here instead of
1126 // splitting it between the driver and clang -cc1.
1127 if (!types::isCXX(InputType
))
1128 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1129 "-std=", /*Joined=*/true);
1130 Args
.AddLastArg(CmdArgs
, options::OPT_trigraphs
);
1133 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1134 if (Arg
*Asm
= Args
.getLastArg(options::OPT_fasm
, options::OPT_fno_asm
)) {
1135 if (Asm
->getOption().matches(options::OPT_fasm
))
1136 CmdArgs
.push_back("-fgnu-keywords");
1138 CmdArgs
.push_back("-fno-gnu-keywords");
1141 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_depth_
)) {
1142 CmdArgs
.push_back("-ftemplate-depth");
1143 CmdArgs
.push_back(A
->getValue(Args
));
1146 if (Args
.hasArg(options::OPT__relocatable_pch
))
1147 CmdArgs
.push_back("-relocatable-pch");
1149 if (Arg
*A
= Args
.getLastArg(options::OPT_fconstant_string_class_EQ
)) {
1150 CmdArgs
.push_back("-fconstant-string-class");
1151 CmdArgs
.push_back(A
->getValue(Args
));
1154 if (Arg
*A
= Args
.getLastArg(options::OPT_ftabstop_EQ
)) {
1155 CmdArgs
.push_back("-ftabstop");
1156 CmdArgs
.push_back(A
->getValue(Args
));
1159 CmdArgs
.push_back("-ferror-limit");
1160 if (Arg
*A
= Args
.getLastArg(options::OPT_ferror_limit_EQ
))
1161 CmdArgs
.push_back(A
->getValue(Args
));
1163 CmdArgs
.push_back("19");
1165 if (Arg
*A
= Args
.getLastArg(options::OPT_fmacro_backtrace_limit_EQ
)) {
1166 CmdArgs
.push_back("-fmacro-backtrace-limit");
1167 CmdArgs
.push_back(A
->getValue(Args
));
1170 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ
)) {
1171 CmdArgs
.push_back("-ftemplate-backtrace-limit");
1172 CmdArgs
.push_back(A
->getValue(Args
));
1175 // Pass -fmessage-length=.
1176 CmdArgs
.push_back("-fmessage-length");
1177 if (Arg
*A
= Args
.getLastArg(options::OPT_fmessage_length_EQ
)) {
1178 CmdArgs
.push_back(A
->getValue(Args
));
1180 // If -fmessage-length=N was not specified, determine whether this is a
1181 // terminal and, if so, implicitly define -fmessage-length appropriately.
1182 unsigned N
= llvm::sys::Process::StandardErrColumns();
1183 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(N
)));
1186 if (const Arg
*A
= Args
.getLastArg(options::OPT_fvisibility_EQ
)) {
1187 CmdArgs
.push_back("-fvisibility");
1188 CmdArgs
.push_back(A
->getValue(Args
));
1191 Args
.AddLastArg(CmdArgs
, options::OPT_fvisibility_inlines_hidden
);
1193 // -fhosted is default.
1194 if (KernelOrKext
|| Args
.hasFlag(options::OPT_ffreestanding
,
1195 options::OPT_fhosted
,
1197 CmdArgs
.push_back("-ffreestanding");
1199 // Forward -f (flag) options which we can pass directly.
1200 Args
.AddLastArg(CmdArgs
, options::OPT_fcatch_undefined_behavior
);
1201 Args
.AddLastArg(CmdArgs
, options::OPT_femit_all_decls
);
1202 Args
.AddLastArg(CmdArgs
, options::OPT_fheinous_gnu_extensions
);
1203 Args
.AddLastArg(CmdArgs
, options::OPT_flimit_debug_info
);
1205 // -flax-vector-conversions is default.
1206 if (!Args
.hasFlag(options::OPT_flax_vector_conversions
,
1207 options::OPT_fno_lax_vector_conversions
))
1208 CmdArgs
.push_back("-fno-lax-vector-conversions");
1210 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1211 // takes precedence.
1212 const Arg
*GCArg
= Args
.getLastArg(options::OPT_fobjc_gc_only
);
1214 GCArg
= Args
.getLastArg(options::OPT_fobjc_gc
);
1216 if (getToolChain().SupportsObjCGC()) {
1217 GCArg
->render(Args
, CmdArgs
);
1219 // FIXME: We should move this to a hard error.
1220 D
.Diag(clang::diag::warn_drv_objc_gc_unsupported
)
1221 << GCArg
->getAsString(Args
);
1225 Args
.AddLastArg(CmdArgs
, options::OPT_fno_show_column
);
1226 Args
.AddLastArg(CmdArgs
, options::OPT_fobjc_sender_dependent_dispatch
);
1227 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_print_source_range_info
);
1228 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_parseable_fixits
);
1229 Args
.AddLastArg(CmdArgs
, options::OPT_ftime_report
);
1230 Args
.AddLastArg(CmdArgs
, options::OPT_ftrapv
);
1232 if (Arg
*A
= Args
.getLastArg(options::OPT_ftrapv_handler_EQ
)) {
1233 CmdArgs
.push_back("-ftrapv-handler");
1234 CmdArgs
.push_back(A
->getValue(Args
));
1237 Args
.AddLastArg(CmdArgs
, options::OPT_fwrapv
);
1238 Args
.AddLastArg(CmdArgs
, options::OPT_fwritable_strings
);
1239 Args
.AddLastArg(CmdArgs
, options::OPT_funroll_loops
);
1241 Args
.AddLastArg(CmdArgs
, options::OPT_pthread
);
1243 // -stack-protector=0 is default.
1244 unsigned StackProtectorLevel
= 0;
1245 if (Arg
*A
= Args
.getLastArg(options::OPT_fno_stack_protector
,
1246 options::OPT_fstack_protector_all
,
1247 options::OPT_fstack_protector
)) {
1248 if (A
->getOption().matches(options::OPT_fstack_protector
))
1249 StackProtectorLevel
= 1;
1250 else if (A
->getOption().matches(options::OPT_fstack_protector_all
))
1251 StackProtectorLevel
= 2;
1253 StackProtectorLevel
= getToolChain().GetDefaultStackProtectorLevel();
1254 if (StackProtectorLevel
) {
1255 CmdArgs
.push_back("-stack-protector");
1256 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(StackProtectorLevel
)));
1259 // Forward -f options with positive and negative forms; we translate
1262 // -fbuiltin is default.
1263 if (!Args
.hasFlag(options::OPT_fbuiltin
, options::OPT_fno_builtin
))
1264 CmdArgs
.push_back("-fno-builtin");
1266 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1267 options::OPT_fno_assume_sane_operator_new
))
1268 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1270 // -fblocks=0 is default.
1271 if (Args
.hasFlag(options::OPT_fblocks
, options::OPT_fno_blocks
,
1272 getToolChain().IsBlocksDefault())) {
1273 CmdArgs
.push_back("-fblocks");
1276 // -faccess-control is default.
1277 if (Args
.hasFlag(options::OPT_fno_access_control
,
1278 options::OPT_faccess_control
,
1280 CmdArgs
.push_back("-fno-access-control");
1282 // -fexceptions=0 is default.
1283 if (!KernelOrKext
&&
1284 needsExceptions(Args
, InputType
, getToolChain().getTriple()))
1285 CmdArgs
.push_back("-fexceptions");
1287 if (getToolChain().UseSjLjExceptions())
1288 CmdArgs
.push_back("-fsjlj-exceptions");
1290 // -frtti is default.
1292 !Args
.hasFlag(options::OPT_frtti
, options::OPT_fno_rtti
))
1293 CmdArgs
.push_back("-fno-rtti");
1295 // -fshort-enums=0 is default.
1296 // FIXME: Are there targers where -fshort-enums is on by default ?
1297 if (Args
.hasFlag(options::OPT_fshort_enums
,
1298 options::OPT_fno_short_enums
, false))
1299 CmdArgs
.push_back("-fshort-enums");
1301 // -fsigned-char is default.
1302 if (!Args
.hasFlag(options::OPT_fsigned_char
, options::OPT_funsigned_char
,
1303 isSignedCharDefault(getToolChain().getTriple())))
1304 CmdArgs
.push_back("-fno-signed-char");
1306 // -fthreadsafe-static is default.
1307 if (!Args
.hasFlag(options::OPT_fthreadsafe_statics
,
1308 options::OPT_fno_threadsafe_statics
))
1309 CmdArgs
.push_back("-fno-threadsafe-statics");
1311 // -fuse-cxa-atexit is default.
1313 !Args
.hasFlag(options::OPT_fuse_cxa_atexit
, options::OPT_fno_use_cxa_atexit
,
1314 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin
&&
1315 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32
&&
1316 getToolChain().getTriple().getOS() != llvm::Triple::MinGW64
))
1317 CmdArgs
.push_back("-fno-use-cxa-atexit");
1319 // -fms-extensions=0 is default.
1320 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1321 getToolChain().getTriple().getOS() == llvm::Triple::Win32
))
1322 CmdArgs
.push_back("-fms-extensions");
1324 // -fmsc-version=1300 is default.
1325 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1326 getToolChain().getTriple().getOS() == llvm::Triple::Win32
) ||
1327 Args
.hasArg(options::OPT_fmsc_version
)) {
1328 llvm::StringRef msc_ver
= Args
.getLastArgValue(options::OPT_fmsc_version
);
1329 if (msc_ver
.empty())
1330 CmdArgs
.push_back("-fmsc-version=1300");
1332 CmdArgs
.push_back(Args
.MakeArgString("-fmsc-version=" + msc_ver
));
1336 // -fborland-extensions=0 is default.
1337 if (Args
.hasFlag(options::OPT_fborland_extensions
,
1338 options::OPT_fno_borland_extensions
, false))
1339 CmdArgs
.push_back("-fborland-extensions");
1341 // -fgnu-keywords default varies depending on language; only pass if
1343 if (Arg
*A
= Args
.getLastArg(options::OPT_fgnu_keywords
,
1344 options::OPT_fno_gnu_keywords
))
1345 A
->render(Args
, CmdArgs
);
1347 // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
1348 // -the -cc1 default.
1349 bool NeXTRuntimeIsDefault
=
1350 IsRewriter
|| getToolChain().getTriple().getOS() == llvm::Triple::Darwin
;
1351 if (!Args
.hasFlag(options::OPT_fnext_runtime
, options::OPT_fgnu_runtime
,
1352 NeXTRuntimeIsDefault
))
1353 CmdArgs
.push_back("-fgnu-runtime");
1355 // -fobjc-nonfragile-abi=0 is default.
1356 if (types::isObjC(InputType
)) {
1357 // Compute the Objective-C ABI "version" to use. Version numbers are
1358 // slightly confusing for historical reasons:
1359 // 1 - Traditional "fragile" ABI
1360 // 2 - Non-fragile ABI, version 1
1361 // 3 - Non-fragile ABI, version 2
1362 unsigned Version
= 1;
1363 // If -fobjc-abi-version= is present, use that to set the version.
1364 if (Arg
*A
= Args
.getLastArg(options::OPT_fobjc_abi_version_EQ
)) {
1365 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1367 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1369 else if (llvm::StringRef(A
->getValue(Args
)) == "3")
1372 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1374 // Otherwise, determine if we are using the non-fragile ABI.
1375 if (Args
.hasFlag(options::OPT_fobjc_nonfragile_abi
,
1376 options::OPT_fno_objc_nonfragile_abi
,
1377 getToolChain().IsObjCNonFragileABIDefault())) {
1378 // Determine the non-fragile ABI version to use.
1379 unsigned NonFragileABIVersion
= 2;
1381 if (Arg
*A
= Args
.getLastArg(
1382 options::OPT_fobjc_nonfragile_abi_version_EQ
)) {
1383 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1384 NonFragileABIVersion
= 1;
1385 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1386 NonFragileABIVersion
= 2;
1388 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1389 << A
->getAsString(Args
);
1392 Version
= 1 + NonFragileABIVersion
;
1398 if (Version
== 2 || Version
== 3) {
1400 CmdArgs
.push_back("-fobjc-nonfragile-abi");
1402 CmdArgs
.push_back("-fobjc-nonfragile-abi2");
1404 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1405 // legacy is the default.
1406 if (!Args
.hasFlag(options::OPT_fobjc_legacy_dispatch
,
1407 options::OPT_fno_objc_legacy_dispatch
,
1408 getToolChain().IsObjCLegacyDispatchDefault())) {
1409 if (getToolChain().UseObjCMixedDispatch())
1410 CmdArgs
.push_back("-fobjc-dispatch-method=mixed");
1412 CmdArgs
.push_back("-fobjc-dispatch-method=non-legacy");
1417 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1418 options::OPT_fno_assume_sane_operator_new
))
1419 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1421 // -fconstant-cfstrings is default, and may be subject to argument translation
1423 if (!Args
.hasFlag(options::OPT_fconstant_cfstrings
,
1424 options::OPT_fno_constant_cfstrings
) ||
1425 !Args
.hasFlag(options::OPT_mconstant_cfstrings
,
1426 options::OPT_mno_constant_cfstrings
))
1427 CmdArgs
.push_back("-fno-constant-cfstrings");
1429 // -fshort-wchar default varies depending on platform; only
1430 // pass if specified.
1431 if (Arg
*A
= Args
.getLastArg(options::OPT_fshort_wchar
))
1432 A
->render(Args
, CmdArgs
);
1434 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1435 // happened to translate to -mpascal-strings, we want to back translate here.
1437 // FIXME: This is gross; that translation should be pulled from the
1439 if (Args
.hasFlag(options::OPT_fpascal_strings
,
1440 options::OPT_fno_pascal_strings
,
1442 Args
.hasFlag(options::OPT_mpascal_strings
,
1443 options::OPT_mno_pascal_strings
,
1445 CmdArgs
.push_back("-fpascal-strings");
1447 // -fcommon is default, only pass non-default.
1448 if (!Args
.hasFlag(options::OPT_fcommon
, options::OPT_fno_common
))
1449 CmdArgs
.push_back("-fno-common");
1451 // -fsigned-bitfields is default, and clang doesn't yet support
1452 // -funsigned-bitfields.
1453 if (!Args
.hasFlag(options::OPT_fsigned_bitfields
,
1454 options::OPT_funsigned_bitfields
))
1455 D
.Diag(clang::diag::warn_drv_clang_unsupported
)
1456 << Args
.getLastArg(options::OPT_funsigned_bitfields
)->getAsString(Args
);
1458 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1459 if (!Args
.hasFlag(options::OPT_ffor_scope
,
1460 options::OPT_fno_for_scope
))
1461 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1462 << Args
.getLastArg(options::OPT_fno_for_scope
)->getAsString(Args
);
1464 // -fcaret-diagnostics is default.
1465 if (!Args
.hasFlag(options::OPT_fcaret_diagnostics
,
1466 options::OPT_fno_caret_diagnostics
, true))
1467 CmdArgs
.push_back("-fno-caret-diagnostics");
1469 // -fdiagnostics-fixit-info is default, only pass non-default.
1470 if (!Args
.hasFlag(options::OPT_fdiagnostics_fixit_info
,
1471 options::OPT_fno_diagnostics_fixit_info
))
1472 CmdArgs
.push_back("-fno-diagnostics-fixit-info");
1474 // Enable -fdiagnostics-show-option by default.
1475 if (Args
.hasFlag(options::OPT_fdiagnostics_show_option
,
1476 options::OPT_fno_diagnostics_show_option
))
1477 CmdArgs
.push_back("-fdiagnostics-show-option");
1480 Args
.getLastArg(options::OPT_fdiagnostics_show_category_EQ
)) {
1481 CmdArgs
.push_back("-fdiagnostics-show-category");
1482 CmdArgs
.push_back(A
->getValue(Args
));
1485 // Color diagnostics are the default, unless the terminal doesn't support
1487 if (Args
.hasFlag(options::OPT_fcolor_diagnostics
,
1488 options::OPT_fno_color_diagnostics
,
1489 llvm::sys::Process::StandardErrHasColors()))
1490 CmdArgs
.push_back("-fcolor-diagnostics");
1492 if (!Args
.hasFlag(options::OPT_fshow_source_location
,
1493 options::OPT_fno_show_source_location
))
1494 CmdArgs
.push_back("-fno-show-source-location");
1496 if (!Args
.hasFlag(options::OPT_fspell_checking
,
1497 options::OPT_fno_spell_checking
))
1498 CmdArgs
.push_back("-fno-spell-checking");
1501 // Silently ignore -fasm-blocks for now.
1502 (void) Args
.hasFlag(options::OPT_fasm_blocks
, options::OPT_fno_asm_blocks
,
1505 if (Arg
*A
= Args
.getLastArg(options::OPT_fshow_overloads_EQ
))
1506 A
->render(Args
, CmdArgs
);
1508 // -fdollars-in-identifiers default varies depending on platform and
1509 // language; only pass if specified.
1510 if (Arg
*A
= Args
.getLastArg(options::OPT_fdollars_in_identifiers
,
1511 options::OPT_fno_dollars_in_identifiers
)) {
1512 if (A
->getOption().matches(options::OPT_fdollars_in_identifiers
))
1513 CmdArgs
.push_back("-fdollars-in-identifiers");
1515 CmdArgs
.push_back("-fno-dollars-in-identifiers");
1518 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
1519 // practical purposes.
1520 if (Arg
*A
= Args
.getLastArg(options::OPT_funit_at_a_time
,
1521 options::OPT_fno_unit_at_a_time
)) {
1522 if (A
->getOption().matches(options::OPT_fno_unit_at_a_time
))
1523 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << A
->getAsString(Args
);
1526 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
1528 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
1530 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1531 (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1532 getToolChain().getTriple().getArch() == llvm::Triple::thumb
)) {
1533 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1534 CmdArgs
.push_back("-fno-builtin-strcat");
1535 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1536 CmdArgs
.push_back("-fno-builtin-strcpy");
1540 if (Arg
*A
= Args
.getLastArg(options::OPT_traditional
,
1541 options::OPT_traditional_cpp
))
1542 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1544 Args
.AddLastArg(CmdArgs
, options::OPT_dM
);
1545 Args
.AddLastArg(CmdArgs
, options::OPT_dD
);
1547 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
1549 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xclang
);
1550 for (arg_iterator it
= Args
.filtered_begin(options::OPT_mllvm
),
1551 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1554 // We translate this by hand to the -cc1 argument, since nightly test uses
1555 // it and developers have been trained to spell it with -mllvm.
1556 if (llvm::StringRef((*it
)->getValue(Args
, 0)) == "-disable-llvm-optzns")
1557 CmdArgs
.push_back("-disable-llvm-optzns");
1559 (*it
)->render(Args
, CmdArgs
);
1562 if (Output
.getType() == types::TY_Dependencies
) {
1563 // Handled with other dependency code.
1564 } else if (Output
.isFilename()) {
1565 CmdArgs
.push_back("-o");
1566 CmdArgs
.push_back(Output
.getFilename());
1568 assert(Output
.isNothing() && "Invalid output.");
1571 for (InputInfoList::const_iterator
1572 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1573 const InputInfo
&II
= *it
;
1574 CmdArgs
.push_back("-x");
1575 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1576 if (II
.isFilename())
1577 CmdArgs
.push_back(II
.getFilename());
1579 II
.getInputArg().renderAsInput(Args
, CmdArgs
);
1582 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1584 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1586 // Optionally embed the -cc1 level arguments into the debug info, for build
1588 if (getToolChain().UseDwarfDebugFlags()) {
1589 ArgStringList OriginalArgs
;
1590 for (ArgList::const_iterator it
= Args
.begin(),
1591 ie
= Args
.end(); it
!= ie
; ++it
)
1592 (*it
)->render(Args
, OriginalArgs
);
1594 llvm::SmallString
<256> Flags
;
1596 for (unsigned i
= 0, e
= OriginalArgs
.size(); i
!= e
; ++i
) {
1598 Flags
+= OriginalArgs
[i
];
1600 CmdArgs
.push_back("-dwarf-debug-flags");
1601 CmdArgs
.push_back(Args
.MakeArgString(Flags
.str()));
1604 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1606 // Explicitly warn that these options are unsupported, even though
1607 // we are allowing compilation to continue.
1608 for (arg_iterator it
= Args
.filtered_begin(options::OPT_pg
),
1609 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1611 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << (*it
)->getAsString(Args
);
1614 // Claim some arguments which clang supports automatically.
1616 // -fpch-preprocess is used with gcc to add a special marker in the output to
1617 // include the PCH file. Clang's PTH solution is completely transparent, so we
1618 // do not need to deal with it at all.
1619 Args
.ClaimAllArgs(options::OPT_fpch_preprocess
);
1621 // Claim some arguments which clang doesn't support, but we don't
1622 // care to warn the user about.
1623 Args
.ClaimAllArgs(options::OPT_clang_ignored_f_Group
);
1624 Args
.ClaimAllArgs(options::OPT_clang_ignored_m_Group
);
1627 void ClangAs::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1628 const InputInfo
&Output
,
1629 const InputInfoList
&Inputs
,
1630 const ArgList
&Args
,
1631 const char *LinkingOutput
) const {
1632 ArgStringList CmdArgs
;
1634 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
1635 const InputInfo
&Input
= Inputs
[0];
1637 // Invoke ourselves in -cc1as mode.
1639 // FIXME: Implement custom jobs for internal actions.
1640 CmdArgs
.push_back("-cc1as");
1642 // Add the "effective" target triple.
1643 CmdArgs
.push_back("-triple");
1644 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
1645 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
1647 // Set the output mode, we currently only expect to be used as a real
1649 CmdArgs
.push_back("-filetype");
1650 CmdArgs
.push_back("obj");
1652 // At -O0, we use -mrelax-all by default.
1654 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
1655 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
1656 if (Args
.hasFlag(options::OPT_mrelax_all
,
1657 options::OPT_mno_relax_all
,
1659 CmdArgs
.push_back("-relax-all");
1661 // FIXME: Add -force_cpusubtype_ALL support, once we have it.
1663 // FIXME: Add -g support, once we have it.
1665 // FIXME: Add -static support, once we have it.
1667 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
1668 options::OPT_Xassembler
);
1670 assert(Output
.isFilename() && "Unexpected lipo output.");
1671 CmdArgs
.push_back("-o");
1672 CmdArgs
.push_back(Output
.getFilename());
1674 assert(Input
.isFilename() && "Invalid input.");
1675 CmdArgs
.push_back(Input
.getFilename());
1677 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1678 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1681 void gcc::Common::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1682 const InputInfo
&Output
,
1683 const InputInfoList
&Inputs
,
1684 const ArgList
&Args
,
1685 const char *LinkingOutput
) const {
1686 const Driver
&D
= getToolChain().getDriver();
1687 ArgStringList CmdArgs
;
1689 for (ArgList::const_iterator
1690 it
= Args
.begin(), ie
= Args
.end(); it
!= ie
; ++it
) {
1692 if (A
->getOption().hasForwardToGCC()) {
1693 // Don't forward any -g arguments to assembly steps.
1694 if (isa
<AssembleJobAction
>(JA
) &&
1695 A
->getOption().matches(options::OPT_g_Group
))
1698 // It is unfortunate that we have to claim here, as this means
1699 // we will basically never report anything interesting for
1700 // platforms using a generic gcc, even if we are just using gcc
1701 // to get to the assembler.
1703 A
->render(Args
, CmdArgs
);
1707 RenderExtraToolArgs(JA
, CmdArgs
);
1709 // If using a driver driver, force the arch.
1710 const std::string
&Arch
= getToolChain().getArchName();
1711 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
) {
1712 CmdArgs
.push_back("-arch");
1714 // FIXME: Remove these special cases.
1715 if (Arch
== "powerpc")
1716 CmdArgs
.push_back("ppc");
1717 else if (Arch
== "powerpc64")
1718 CmdArgs
.push_back("ppc64");
1720 CmdArgs
.push_back(Args
.MakeArgString(Arch
));
1723 // Try to force gcc to match the tool chain we want, if we recognize
1726 // FIXME: The triple class should directly provide the information we want
1728 if (Arch
== "i386" || Arch
== "powerpc")
1729 CmdArgs
.push_back("-m32");
1730 else if (Arch
== "x86_64" || Arch
== "powerpc64")
1731 CmdArgs
.push_back("-m64");
1733 if (Output
.isFilename()) {
1734 CmdArgs
.push_back("-o");
1735 CmdArgs
.push_back(Output
.getFilename());
1737 assert(Output
.isNothing() && "Unexpected output");
1738 CmdArgs
.push_back("-fsyntax-only");
1742 // Only pass -x if gcc will understand it; otherwise hope gcc
1743 // understands the suffix correctly. The main use case this would go
1744 // wrong in is for linker inputs if they happened to have an odd
1745 // suffix; really the only way to get this to happen is a command
1746 // like '-x foobar a.c' which will treat a.c like a linker input.
1748 // FIXME: For the linker case specifically, can we safely convert
1749 // inputs into '-Wl,' options?
1750 for (InputInfoList::const_iterator
1751 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1752 const InputInfo
&II
= *it
;
1754 // Don't try to pass LLVM or AST inputs to a generic gcc.
1755 if (II
.getType() == types::TY_LLVM_IR
|| II
.getType() == types::TY_LTO_IR
||
1756 II
.getType() == types::TY_LLVM_BC
|| II
.getType() == types::TY_LTO_BC
)
1757 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
1758 << getToolChain().getTripleString();
1759 else if (II
.getType() == types::TY_AST
)
1760 D
.Diag(clang::diag::err_drv_no_ast_support
)
1761 << getToolChain().getTripleString();
1763 if (types::canTypeBeUserSpecified(II
.getType())) {
1764 CmdArgs
.push_back("-x");
1765 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1768 if (II
.isFilename())
1769 CmdArgs
.push_back(II
.getFilename());
1771 const Arg
&A
= II
.getInputArg();
1773 // Reverse translate some rewritten options.
1774 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
1775 CmdArgs
.push_back("-lstdc++");
1779 // Don't render as input, we need gcc to do the translations.
1780 A
.render(Args
, CmdArgs
);
1784 const char *GCCName
= getToolChain().getDriver().getCCCGenericGCCName().c_str();
1786 Args
.MakeArgString(getToolChain().GetProgramPath(GCCName
));
1787 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1790 void gcc::Preprocess::RenderExtraToolArgs(const JobAction
&JA
,
1791 ArgStringList
&CmdArgs
) const {
1792 CmdArgs
.push_back("-E");
1795 void gcc::Precompile::RenderExtraToolArgs(const JobAction
&JA
,
1796 ArgStringList
&CmdArgs
) const {
1797 // The type is good enough.
1800 void gcc::Compile::RenderExtraToolArgs(const JobAction
&JA
,
1801 ArgStringList
&CmdArgs
) const {
1802 const Driver
&D
= getToolChain().getDriver();
1804 // If -flto, etc. are present then make sure not to force assembly output.
1805 if (JA
.getType() == types::TY_LLVM_IR
|| JA
.getType() == types::TY_LTO_IR
||
1806 JA
.getType() == types::TY_LLVM_BC
|| JA
.getType() == types::TY_LTO_BC
)
1807 CmdArgs
.push_back("-c");
1809 if (JA
.getType() != types::TY_PP_Asm
)
1810 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
1811 << getTypeName(JA
.getType());
1813 CmdArgs
.push_back("-S");
1817 void gcc::Assemble::RenderExtraToolArgs(const JobAction
&JA
,
1818 ArgStringList
&CmdArgs
) const {
1819 CmdArgs
.push_back("-c");
1822 void gcc::Link::RenderExtraToolArgs(const JobAction
&JA
,
1823 ArgStringList
&CmdArgs
) const {
1824 // The types are (hopefully) good enough.
1827 const char *darwin::CC1::getCC1Name(types::ID Type
) const {
1830 assert(0 && "Unexpected type for Darwin CC1 tool.");
1832 case types::TY_C
: case types::TY_CHeader
:
1833 case types::TY_PP_C
: case types::TY_PP_CHeader
:
1835 case types::TY_ObjC
: case types::TY_ObjCHeader
:
1836 case types::TY_PP_ObjC
: case types::TY_PP_ObjCHeader
:
1838 case types::TY_CXX
: case types::TY_CXXHeader
:
1839 case types::TY_PP_CXX
: case types::TY_PP_CXXHeader
:
1841 case types::TY_ObjCXX
: case types::TY_ObjCXXHeader
:
1842 case types::TY_PP_ObjCXX
: case types::TY_PP_ObjCXXHeader
:
1843 return "cc1objplus";
1847 const char *darwin::CC1::getBaseInputName(const ArgList
&Args
,
1848 const InputInfoList
&Inputs
) {
1849 llvm::sys::Path
P(Inputs
[0].getBaseInput());
1850 return Args
.MakeArgString(P
.getLast());
1853 const char *darwin::CC1::getBaseInputStem(const ArgList
&Args
,
1854 const InputInfoList
&Inputs
) {
1855 const char *Str
= getBaseInputName(Args
, Inputs
);
1857 if (const char *End
= strchr(Str
, '.'))
1858 return Args
.MakeArgString(std::string(Str
, End
));
1864 darwin::CC1::getDependencyFileName(const ArgList
&Args
,
1865 const InputInfoList
&Inputs
) {
1866 // FIXME: Think about this more.
1869 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
1870 std::string
Str(OutputOpt
->getValue(Args
));
1872 Res
= Str
.substr(0, Str
.rfind('.'));
1874 Res
= darwin::CC1::getBaseInputStem(Args
, Inputs
);
1876 return Args
.MakeArgString(Res
+ ".d");
1879 void darwin::CC1::AddCC1Args(const ArgList
&Args
,
1880 ArgStringList
&CmdArgs
) const {
1881 const Driver
&D
= getToolChain().getDriver();
1883 CheckCodeGenerationOptions(D
, Args
);
1885 // Derived from cc1 spec.
1886 if (!Args
.hasArg(options::OPT_mkernel
) && !Args
.hasArg(options::OPT_static
) &&
1887 !Args
.hasArg(options::OPT_mdynamic_no_pic
))
1888 CmdArgs
.push_back("-fPIC");
1890 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1891 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
1892 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1893 CmdArgs
.push_back("-fno-builtin-strcat");
1894 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1895 CmdArgs
.push_back("-fno-builtin-strcpy");
1898 // gcc has some code here to deal with when no -mmacosx-version-min
1899 // and no -miphoneos-version-min is present, but this never happens
1900 // due to tool chain specific argument translation.
1902 if (Args
.hasArg(options::OPT_g_Flag
) &&
1903 !Args
.hasArg(options::OPT_fno_eliminate_unused_debug_symbols
))
1904 CmdArgs
.push_back("-feliminate-unused-debug-symbols");
1907 void darwin::CC1::AddCC1OptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
1908 const InputInfoList
&Inputs
,
1909 const ArgStringList
&OutputArgs
) const {
1910 const Driver
&D
= getToolChain().getDriver();
1912 // Derived from cc1_options spec.
1913 if (Args
.hasArg(options::OPT_fast
) ||
1914 Args
.hasArg(options::OPT_fastf
) ||
1915 Args
.hasArg(options::OPT_fastcp
))
1916 CmdArgs
.push_back("-O3");
1918 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
1919 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
1920 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
1921 << A
->getAsString(Args
) << "-fomit-frame-pointer";
1923 AddCC1Args(Args
, CmdArgs
);
1925 if (!Args
.hasArg(options::OPT_Q
))
1926 CmdArgs
.push_back("-quiet");
1928 CmdArgs
.push_back("-dumpbase");
1929 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
1931 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
1933 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
1934 Args
.AddAllArgs(CmdArgs
, options::OPT_a_Group
);
1936 // FIXME: The goal is to use the user provided -o if that is our
1937 // final output, otherwise to drive from the original input
1938 // name. Find a clean way to go about this.
1939 if ((Args
.hasArg(options::OPT_c
) || Args
.hasArg(options::OPT_S
)) &&
1940 Args
.hasArg(options::OPT_o
)) {
1941 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
1942 CmdArgs
.push_back("-auxbase-strip");
1943 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
1945 CmdArgs
.push_back("-auxbase");
1946 CmdArgs
.push_back(darwin::CC1::getBaseInputStem(Args
, Inputs
));
1949 Args
.AddAllArgs(CmdArgs
, options::OPT_g_Group
);
1951 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
1952 // FIXME: -Wall is getting some special treatment. Investigate.
1953 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
1954 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1955 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
1956 options::OPT_trigraphs
);
1957 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1958 // Honor -std-default.
1959 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1960 "-std=", /*Joined=*/true);
1963 if (Args
.hasArg(options::OPT_v
))
1964 CmdArgs
.push_back("-version");
1965 if (Args
.hasArg(options::OPT_pg
))
1966 CmdArgs
.push_back("-p");
1967 Args
.AddLastArg(CmdArgs
, options::OPT_p
);
1969 // The driver treats -fsyntax-only specially.
1970 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1971 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
1972 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
1973 // used to inhibit the default -fno-builtin-str{cat,cpy}.
1975 // FIXME: Should we grow a better way to deal with "removing" args?
1976 for (arg_iterator it
= Args
.filtered_begin(options::OPT_f_Group
,
1977 options::OPT_fsyntax_only
),
1978 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1979 if (!(*it
)->getOption().matches(options::OPT_fbuiltin_strcat
) &&
1980 !(*it
)->getOption().matches(options::OPT_fbuiltin_strcpy
)) {
1982 (*it
)->render(Args
, CmdArgs
);
1986 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
1988 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1989 if (Args
.hasArg(options::OPT_Qn
))
1990 CmdArgs
.push_back("-fno-ident");
1992 // FIXME: This isn't correct.
1993 //Args.AddLastArg(CmdArgs, options::OPT__help)
1994 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
1996 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
1998 // FIXME: Still don't get what is happening here. Investigate.
1999 Args
.AddAllArgs(CmdArgs
, options::OPT__param
);
2001 if (Args
.hasArg(options::OPT_fmudflap
) ||
2002 Args
.hasArg(options::OPT_fmudflapth
)) {
2003 CmdArgs
.push_back("-fno-builtin");
2004 CmdArgs
.push_back("-fno-merge-constants");
2007 if (Args
.hasArg(options::OPT_coverage
)) {
2008 CmdArgs
.push_back("-fprofile-arcs");
2009 CmdArgs
.push_back("-ftest-coverage");
2012 if (types::isCXX(Inputs
[0].getType()))
2013 CmdArgs
.push_back("-D__private_extern__=extern");
2016 void darwin::CC1::AddCPPOptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2017 const InputInfoList
&Inputs
,
2018 const ArgStringList
&OutputArgs
) const {
2019 // Derived from cpp_options
2020 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2022 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2024 AddCC1Args(Args
, CmdArgs
);
2026 // NOTE: The code below has some commonality with cpp_options, but
2027 // in classic gcc style ends up sending things in different
2028 // orders. This may be a good merge candidate once we drop pedantic
2031 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2032 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2033 options::OPT_trigraphs
);
2034 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2035 // Honor -std-default.
2036 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2037 "-std=", /*Joined=*/true);
2039 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2040 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2042 // The driver treats -fsyntax-only specially.
2043 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2045 if (Args
.hasArg(options::OPT_g_Group
) && !Args
.hasArg(options::OPT_g0
) &&
2046 !Args
.hasArg(options::OPT_fno_working_directory
))
2047 CmdArgs
.push_back("-fworking-directory");
2049 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2050 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2051 if (Args
.hasArg(options::OPT_save_temps
))
2052 CmdArgs
.push_back("-fpch-preprocess");
2055 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList
&Args
,
2056 ArgStringList
&CmdArgs
,
2057 const InputInfoList
&Inputs
) const {
2058 const Driver
&D
= getToolChain().getDriver();
2060 CheckPreprocessingOptions(D
, Args
);
2062 // Derived from cpp_unique_options.
2063 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2064 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
2065 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
2066 if (!Args
.hasArg(options::OPT_Q
))
2067 CmdArgs
.push_back("-quiet");
2068 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdinc
);
2069 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdincxx
);
2070 Args
.AddLastArg(CmdArgs
, options::OPT_v
);
2071 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
2072 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
2074 // FIXME: Handle %I properly.
2075 if (getToolChain().getArchName() == "x86_64") {
2076 CmdArgs
.push_back("-imultilib");
2077 CmdArgs
.push_back("x86_64");
2080 if (Args
.hasArg(options::OPT_MD
)) {
2081 CmdArgs
.push_back("-MD");
2082 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2085 if (Args
.hasArg(options::OPT_MMD
)) {
2086 CmdArgs
.push_back("-MMD");
2087 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2090 Args
.AddLastArg(CmdArgs
, options::OPT_M
);
2091 Args
.AddLastArg(CmdArgs
, options::OPT_MM
);
2092 Args
.AddAllArgs(CmdArgs
, options::OPT_MF
);
2093 Args
.AddLastArg(CmdArgs
, options::OPT_MG
);
2094 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
2095 Args
.AddAllArgs(CmdArgs
, options::OPT_MQ
);
2096 Args
.AddAllArgs(CmdArgs
, options::OPT_MT
);
2097 if (!Args
.hasArg(options::OPT_M
) && !Args
.hasArg(options::OPT_MM
) &&
2098 (Args
.hasArg(options::OPT_MD
) || Args
.hasArg(options::OPT_MMD
))) {
2099 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2100 CmdArgs
.push_back("-MQ");
2101 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2105 Args
.AddLastArg(CmdArgs
, options::OPT_remap
);
2106 if (Args
.hasArg(options::OPT_g3
))
2107 CmdArgs
.push_back("-dD");
2108 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
2110 AddCPPArgs(Args
, CmdArgs
);
2112 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
, options::OPT_A
);
2113 Args
.AddAllArgs(CmdArgs
, options::OPT_i_Group
);
2115 for (InputInfoList::const_iterator
2116 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2117 const InputInfo
&II
= *it
;
2119 CmdArgs
.push_back(II
.getFilename());
2122 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
2123 options::OPT_Xpreprocessor
);
2125 if (Args
.hasArg(options::OPT_fmudflap
)) {
2126 CmdArgs
.push_back("-D_MUDFLAP");
2127 CmdArgs
.push_back("-include");
2128 CmdArgs
.push_back("mf-runtime.h");
2131 if (Args
.hasArg(options::OPT_fmudflapth
)) {
2132 CmdArgs
.push_back("-D_MUDFLAP");
2133 CmdArgs
.push_back("-D_MUDFLAPTH");
2134 CmdArgs
.push_back("-include");
2135 CmdArgs
.push_back("mf-runtime.h");
2139 void darwin::CC1::AddCPPArgs(const ArgList
&Args
,
2140 ArgStringList
&CmdArgs
) const {
2141 // Derived from cpp spec.
2143 if (Args
.hasArg(options::OPT_static
)) {
2144 // The gcc spec is broken here, it refers to dynamic but
2145 // that has been translated. Start by being bug compatible.
2147 // if (!Args.hasArg(arglist.parser.dynamicOption))
2148 CmdArgs
.push_back("-D__STATIC__");
2150 CmdArgs
.push_back("-D__DYNAMIC__");
2152 if (Args
.hasArg(options::OPT_pthread
))
2153 CmdArgs
.push_back("-D_REENTRANT");
2156 void darwin::Preprocess::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2157 const InputInfo
&Output
,
2158 const InputInfoList
&Inputs
,
2159 const ArgList
&Args
,
2160 const char *LinkingOutput
) const {
2161 ArgStringList CmdArgs
;
2163 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2165 CmdArgs
.push_back("-E");
2167 if (Args
.hasArg(options::OPT_traditional
) ||
2168 Args
.hasArg(options::OPT_traditional_cpp
))
2169 CmdArgs
.push_back("-traditional-cpp");
2171 ArgStringList OutputArgs
;
2172 assert(Output
.isFilename() && "Unexpected CC1 output.");
2173 OutputArgs
.push_back("-o");
2174 OutputArgs
.push_back(Output
.getFilename());
2176 if (Args
.hasArg(options::OPT_E
)) {
2177 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2179 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2180 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2183 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2185 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2187 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2188 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2191 void darwin::Compile::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2192 const InputInfo
&Output
,
2193 const InputInfoList
&Inputs
,
2194 const ArgList
&Args
,
2195 const char *LinkingOutput
) const {
2196 const Driver
&D
= getToolChain().getDriver();
2197 ArgStringList CmdArgs
;
2199 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2201 types::ID InputType
= Inputs
[0].getType();
2203 if ((A
= Args
.getLastArg(options::OPT_traditional
)))
2204 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2205 << A
->getAsString(Args
) << "-E";
2207 if (JA
.getType() == types::TY_LLVM_IR
||
2208 JA
.getType() == types::TY_LTO_IR
)
2209 CmdArgs
.push_back("-emit-llvm");
2210 else if (JA
.getType() == types::TY_LLVM_BC
||
2211 JA
.getType() == types::TY_LTO_BC
)
2212 CmdArgs
.push_back("-emit-llvm-bc");
2213 else if (Output
.getType() == types::TY_AST
)
2214 D
.Diag(clang::diag::err_drv_no_ast_support
)
2215 << getToolChain().getTripleString();
2216 else if (JA
.getType() != types::TY_PP_Asm
&&
2217 JA
.getType() != types::TY_PCH
)
2218 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
2219 << getTypeName(JA
.getType());
2221 ArgStringList OutputArgs
;
2222 if (Output
.getType() != types::TY_PCH
) {
2223 OutputArgs
.push_back("-o");
2224 if (Output
.isNothing())
2225 OutputArgs
.push_back("/dev/null");
2227 OutputArgs
.push_back(Output
.getFilename());
2230 // There is no need for this level of compatibility, but it makes
2232 bool OutputArgsEarly
= (Args
.hasArg(options::OPT_fsyntax_only
) ||
2233 Args
.hasArg(options::OPT_S
));
2235 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
) {
2236 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2237 if (OutputArgsEarly
) {
2238 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2240 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2241 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2244 CmdArgs
.push_back("-fpreprocessed");
2246 for (InputInfoList::const_iterator
2247 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2248 const InputInfo
&II
= *it
;
2250 // Reject AST inputs.
2251 if (II
.getType() == types::TY_AST
) {
2252 D
.Diag(clang::diag::err_drv_no_ast_support
)
2253 << getToolChain().getTripleString();
2257 CmdArgs
.push_back(II
.getFilename());
2260 if (OutputArgsEarly
) {
2261 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2263 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2264 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2268 if (Output
.getType() == types::TY_PCH
) {
2269 assert(Output
.isFilename() && "Invalid PCH output.");
2271 CmdArgs
.push_back("-o");
2272 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2273 // to be a good reason.
2274 CmdArgs
.push_back("/dev/null");
2276 CmdArgs
.push_back("--output-pch=");
2277 CmdArgs
.push_back(Output
.getFilename());
2280 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2282 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2283 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2286 void darwin::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2287 const InputInfo
&Output
,
2288 const InputInfoList
&Inputs
,
2289 const ArgList
&Args
,
2290 const char *LinkingOutput
) const {
2291 ArgStringList CmdArgs
;
2293 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
2294 const InputInfo
&Input
= Inputs
[0];
2296 // Bit of a hack, this is only used for original inputs.
2298 // FIXME: This is broken for preprocessed .s inputs.
2299 if (Input
.isFilename() &&
2300 strcmp(Input
.getFilename(), Input
.getBaseInput()) == 0) {
2301 if (Args
.hasArg(options::OPT_gstabs
))
2302 CmdArgs
.push_back("--gstabs");
2303 else if (Args
.hasArg(options::OPT_g_Group
))
2304 CmdArgs
.push_back("--gdwarf2");
2307 // Derived from asm spec.
2308 AddDarwinArch(Args
, CmdArgs
);
2310 // Use -force_cpusubtype_ALL on x86 by default.
2311 if (getToolChain().getTriple().getArch() == llvm::Triple::x86
||
2312 getToolChain().getTriple().getArch() == llvm::Triple::x86_64
||
2313 Args
.hasArg(options::OPT_force__cpusubtype__ALL
))
2314 CmdArgs
.push_back("-force_cpusubtype_ALL");
2316 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64
&&
2317 (Args
.hasArg(options::OPT_mkernel
) ||
2318 Args
.hasArg(options::OPT_static
) ||
2319 Args
.hasArg(options::OPT_fapple_kext
)))
2320 CmdArgs
.push_back("-static");
2322 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2323 options::OPT_Xassembler
);
2325 assert(Output
.isFilename() && "Unexpected lipo output.");
2326 CmdArgs
.push_back("-o");
2327 CmdArgs
.push_back(Output
.getFilename());
2329 assert(Input
.isFilename() && "Invalid input.");
2330 CmdArgs
.push_back(Input
.getFilename());
2332 // asm_final spec is empty.
2335 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2336 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2339 void darwin::DarwinTool::AddDarwinArch(const ArgList
&Args
,
2340 ArgStringList
&CmdArgs
) const {
2341 llvm::StringRef ArchName
= getDarwinToolChain().getDarwinArchName(Args
);
2343 // Derived from darwin_arch spec.
2344 CmdArgs
.push_back("-arch");
2345 CmdArgs
.push_back(Args
.MakeArgString(ArchName
));
2347 // FIXME: Is this needed anymore?
2348 if (ArchName
== "arm")
2349 CmdArgs
.push_back("-force_cpusubtype_ALL");
2352 void darwin::Link::AddLinkArgs(Compilation
&C
,
2353 const ArgList
&Args
,
2354 ArgStringList
&CmdArgs
) const {
2355 const Driver
&D
= getToolChain().getDriver();
2357 unsigned Version
[3] = { 0, 0, 0 };
2358 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
2360 if (!Driver::GetReleaseVersion(A
->getValue(Args
), Version
[0],
2361 Version
[1], Version
[2], HadExtra
) ||
2363 D
.Diag(clang::diag::err_drv_invalid_version_number
)
2364 << A
->getAsString(Args
);
2367 // Newer linkers support -demangle, pass it if supported and not disabled by
2369 if (Version
[0] >= 100 && !Args
.hasArg(options::OPT_Z_Xlinker__no_demangle
)) {
2370 // Don't pass -demangle to ld_classic.
2372 // FIXME: This is a temporary workaround, ld should be handling this.
2373 bool UsesLdClassic
= (getToolChain().getArch() == llvm::Triple::x86
&&
2374 Args
.hasArg(options::OPT_static
));
2375 if (getToolChain().getArch() == llvm::Triple::x86
) {
2376 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Xlinker
,
2377 options::OPT_Wl_COMMA
),
2378 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2380 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
)
2381 if (llvm::StringRef(A
->getValue(Args
, i
)) == "-kext")
2382 UsesLdClassic
= true;
2386 CmdArgs
.push_back("-demangle");
2389 // Derived from the "link" spec.
2390 Args
.AddAllArgs(CmdArgs
, options::OPT_static
);
2391 if (!Args
.hasArg(options::OPT_static
))
2392 CmdArgs
.push_back("-dynamic");
2393 if (Args
.hasArg(options::OPT_fgnu_runtime
)) {
2394 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2395 // here. How do we wish to handle such things?
2398 if (!Args
.hasArg(options::OPT_dynamiclib
)) {
2399 AddDarwinArch(Args
, CmdArgs
);
2400 // FIXME: Why do this only on this path?
2401 Args
.AddLastArg(CmdArgs
, options::OPT_force__cpusubtype__ALL
);
2403 Args
.AddLastArg(CmdArgs
, options::OPT_bundle
);
2404 Args
.AddAllArgs(CmdArgs
, options::OPT_bundle__loader
);
2405 Args
.AddAllArgs(CmdArgs
, options::OPT_client__name
);
2408 if ((A
= Args
.getLastArg(options::OPT_compatibility__version
)) ||
2409 (A
= Args
.getLastArg(options::OPT_current__version
)) ||
2410 (A
= Args
.getLastArg(options::OPT_install__name
)))
2411 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2412 << A
->getAsString(Args
) << "-dynamiclib";
2414 Args
.AddLastArg(CmdArgs
, options::OPT_force__flat__namespace
);
2415 Args
.AddLastArg(CmdArgs
, options::OPT_keep__private__externs
);
2416 Args
.AddLastArg(CmdArgs
, options::OPT_private__bundle
);
2418 CmdArgs
.push_back("-dylib");
2421 if ((A
= Args
.getLastArg(options::OPT_bundle
)) ||
2422 (A
= Args
.getLastArg(options::OPT_bundle__loader
)) ||
2423 (A
= Args
.getLastArg(options::OPT_client__name
)) ||
2424 (A
= Args
.getLastArg(options::OPT_force__flat__namespace
)) ||
2425 (A
= Args
.getLastArg(options::OPT_keep__private__externs
)) ||
2426 (A
= Args
.getLastArg(options::OPT_private__bundle
)))
2427 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2428 << A
->getAsString(Args
) << "-dynamiclib";
2430 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_compatibility__version
,
2431 "-dylib_compatibility_version");
2432 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_current__version
,
2433 "-dylib_current_version");
2435 AddDarwinArch(Args
, CmdArgs
);
2437 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_install__name
,
2438 "-dylib_install_name");
2441 Args
.AddLastArg(CmdArgs
, options::OPT_all__load
);
2442 Args
.AddAllArgs(CmdArgs
, options::OPT_allowable__client
);
2443 Args
.AddLastArg(CmdArgs
, options::OPT_bind__at__load
);
2444 if (getDarwinToolChain().isTargetIPhoneOS())
2445 Args
.AddLastArg(CmdArgs
, options::OPT_arch__errors__fatal
);
2446 Args
.AddLastArg(CmdArgs
, options::OPT_dead__strip
);
2447 Args
.AddLastArg(CmdArgs
, options::OPT_no__dead__strip__inits__and__terms
);
2448 Args
.AddAllArgs(CmdArgs
, options::OPT_dylib__file
);
2449 Args
.AddLastArg(CmdArgs
, options::OPT_dynamic
);
2450 Args
.AddAllArgs(CmdArgs
, options::OPT_exported__symbols__list
);
2451 Args
.AddLastArg(CmdArgs
, options::OPT_flat__namespace
);
2452 Args
.AddAllArgs(CmdArgs
, options::OPT_headerpad__max__install__names
);
2453 Args
.AddAllArgs(CmdArgs
, options::OPT_image__base
);
2454 Args
.AddAllArgs(CmdArgs
, options::OPT_init
);
2456 // Adding all arguments doesn't make sense here but this is what gcc does. One
2457 // of this should always be present thanks to argument translation.
2458 assert((Args
.hasArg(options::OPT_mmacosx_version_min_EQ
) ||
2459 Args
.hasArg(options::OPT_miphoneos_version_min_EQ
)) &&
2460 "Missing version argument (lost in translation)?");
2461 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_mmacosx_version_min_EQ
,
2462 "-macosx_version_min");
2463 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_miphoneos_version_min_EQ
,
2464 "-iphoneos_version_min");
2465 Args
.AddLastArg(CmdArgs
, options::OPT_nomultidefs
);
2466 Args
.AddLastArg(CmdArgs
, options::OPT_multi__module
);
2467 Args
.AddLastArg(CmdArgs
, options::OPT_single__module
);
2468 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined
);
2469 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined__unused
);
2471 if (const Arg
*A
= Args
.getLastArg(options::OPT_fpie
, options::OPT_fPIE
,
2472 options::OPT_fno_pie
,
2473 options::OPT_fno_PIE
)) {
2474 if (A
->getOption().matches(options::OPT_fpie
) ||
2475 A
->getOption().matches(options::OPT_fPIE
))
2476 CmdArgs
.push_back("-pie");
2478 CmdArgs
.push_back("-no_pie");
2481 Args
.AddLastArg(CmdArgs
, options::OPT_prebind
);
2482 Args
.AddLastArg(CmdArgs
, options::OPT_noprebind
);
2483 Args
.AddLastArg(CmdArgs
, options::OPT_nofixprebinding
);
2484 Args
.AddLastArg(CmdArgs
, options::OPT_prebind__all__twolevel__modules
);
2485 Args
.AddLastArg(CmdArgs
, options::OPT_read__only__relocs
);
2486 Args
.AddAllArgs(CmdArgs
, options::OPT_sectcreate
);
2487 Args
.AddAllArgs(CmdArgs
, options::OPT_sectorder
);
2488 Args
.AddAllArgs(CmdArgs
, options::OPT_seg1addr
);
2489 Args
.AddAllArgs(CmdArgs
, options::OPT_segprot
);
2490 Args
.AddAllArgs(CmdArgs
, options::OPT_segaddr
);
2491 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__only__addr
);
2492 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__write__addr
);
2493 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table
);
2494 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table__filename
);
2495 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__library
);
2496 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__umbrella
);
2498 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_isysroot
, "-syslibroot");
2499 if (getDarwinToolChain().isTargetIPhoneOS()) {
2500 if (!Args
.hasArg(options::OPT_isysroot
)) {
2501 CmdArgs
.push_back("-syslibroot");
2502 CmdArgs
.push_back("/Developer/SDKs/Extra");
2506 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace
);
2507 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace__hints
);
2508 Args
.AddAllArgs(CmdArgs
, options::OPT_umbrella
);
2509 Args
.AddAllArgs(CmdArgs
, options::OPT_undefined
);
2510 Args
.AddAllArgs(CmdArgs
, options::OPT_unexported__symbols__list
);
2511 Args
.AddAllArgs(CmdArgs
, options::OPT_weak__reference__mismatches
);
2512 Args
.AddLastArg(CmdArgs
, options::OPT_X_Flag
);
2513 Args
.AddAllArgs(CmdArgs
, options::OPT_y
);
2514 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2515 Args
.AddAllArgs(CmdArgs
, options::OPT_pagezero__size
);
2516 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__
);
2517 Args
.AddLastArg(CmdArgs
, options::OPT_seglinkedit
);
2518 Args
.AddLastArg(CmdArgs
, options::OPT_noseglinkedit
);
2519 Args
.AddAllArgs(CmdArgs
, options::OPT_sectalign
);
2520 Args
.AddAllArgs(CmdArgs
, options::OPT_sectobjectsymbols
);
2521 Args
.AddAllArgs(CmdArgs
, options::OPT_segcreate
);
2522 Args
.AddLastArg(CmdArgs
, options::OPT_whyload
);
2523 Args
.AddLastArg(CmdArgs
, options::OPT_whatsloaded
);
2524 Args
.AddAllArgs(CmdArgs
, options::OPT_dylinker__install__name
);
2525 Args
.AddLastArg(CmdArgs
, options::OPT_dylinker
);
2526 Args
.AddLastArg(CmdArgs
, options::OPT_Mach
);
2529 void darwin::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2530 const InputInfo
&Output
,
2531 const InputInfoList
&Inputs
,
2532 const ArgList
&Args
,
2533 const char *LinkingOutput
) const {
2534 assert(Output
.getType() == types::TY_Image
&& "Invalid linker output type.");
2536 // The logic here is derived from gcc's behavior; most of which
2537 // comes from specs (starting with link_command). Consult gcc for
2538 // more information.
2539 ArgStringList CmdArgs
;
2541 // I'm not sure why this particular decomposition exists in gcc, but
2542 // we follow suite for ease of comparison.
2543 AddLinkArgs(C
, Args
, CmdArgs
);
2545 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Flag
);
2546 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
2547 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
2548 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
2549 Args
.AddAllArgs(CmdArgs
, options::OPT_u_Group
);
2550 Args
.AddAllArgs(CmdArgs
, options::OPT_A
);
2551 Args
.AddLastArg(CmdArgs
, options::OPT_e
);
2552 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Separate
);
2553 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
2555 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
2556 // members of static archive libraries which implement Objective-C classes or
2558 if (Args
.hasArg(options::OPT_ObjC
) || Args
.hasArg(options::OPT_ObjCXX
))
2559 CmdArgs
.push_back("-ObjC");
2561 CmdArgs
.push_back("-o");
2562 CmdArgs
.push_back(Output
.getFilename());
2564 if (!Args
.hasArg(options::OPT_A
) &&
2565 !Args
.hasArg(options::OPT_nostdlib
) &&
2566 !Args
.hasArg(options::OPT_nostartfiles
)) {
2567 // Derived from startfile spec.
2568 if (Args
.hasArg(options::OPT_dynamiclib
)) {
2569 // Derived from darwin_dylib1 spec.
2570 if (getDarwinToolChain().isTargetIPhoneOS()) {
2571 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2572 CmdArgs
.push_back("-ldylib1.o");
2574 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2575 CmdArgs
.push_back("-ldylib1.o");
2576 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2577 CmdArgs
.push_back("-ldylib1.10.5.o");
2580 if (Args
.hasArg(options::OPT_bundle
)) {
2581 if (!Args
.hasArg(options::OPT_static
)) {
2582 // Derived from darwin_bundle1 spec.
2583 if (getDarwinToolChain().isTargetIPhoneOS()) {
2584 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2585 CmdArgs
.push_back("-lbundle1.o");
2587 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2588 CmdArgs
.push_back("-lbundle1.o");
2592 if (Args
.hasArg(options::OPT_pg
)) {
2593 if (Args
.hasArg(options::OPT_static
) ||
2594 Args
.hasArg(options::OPT_object
) ||
2595 Args
.hasArg(options::OPT_preload
)) {
2596 CmdArgs
.push_back("-lgcrt0.o");
2598 CmdArgs
.push_back("-lgcrt1.o");
2600 // darwin_crt2 spec is empty.
2603 if (Args
.hasArg(options::OPT_static
) ||
2604 Args
.hasArg(options::OPT_object
) ||
2605 Args
.hasArg(options::OPT_preload
)) {
2606 CmdArgs
.push_back("-lcrt0.o");
2608 // Derived from darwin_crt1 spec.
2609 if (getDarwinToolChain().isTargetIPhoneOS()) {
2610 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2611 CmdArgs
.push_back("-lcrt1.o");
2613 CmdArgs
.push_back("-lcrt1.3.1.o");
2615 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2616 CmdArgs
.push_back("-lcrt1.o");
2617 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2618 CmdArgs
.push_back("-lcrt1.10.5.o");
2620 CmdArgs
.push_back("-lcrt1.10.6.o");
2622 // darwin_crt2 spec is empty.
2629 if (!getDarwinToolChain().isTargetIPhoneOS() &&
2630 Args
.hasArg(options::OPT_shared_libgcc
) &&
2631 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
2633 Args
.MakeArgString(getToolChain().GetFilePath("crt3.o"));
2634 CmdArgs
.push_back(Str
);
2638 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2640 if (Args
.hasArg(options::OPT_fopenmp
))
2641 // This is more complicated in gcc...
2642 CmdArgs
.push_back("-lgomp");
2644 getDarwinToolChain().AddLinkSearchPathArgs(Args
, CmdArgs
);
2646 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2648 if (LinkingOutput
) {
2649 CmdArgs
.push_back("-arch_multiple");
2650 CmdArgs
.push_back("-final_output");
2651 CmdArgs
.push_back(LinkingOutput
);
2654 if (Args
.hasArg(options::OPT_fprofile_arcs
) ||
2655 Args
.hasArg(options::OPT_fprofile_generate
) ||
2656 Args
.hasArg(options::OPT_fcreate_profile
) ||
2657 Args
.hasArg(options::OPT_coverage
))
2658 CmdArgs
.push_back("-lgcov");
2660 if (Args
.hasArg(options::OPT_fnested_functions
))
2661 CmdArgs
.push_back("-allow_stack_execute");
2663 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2664 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2665 if (getToolChain().getDriver().CCCIsCXX
)
2666 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2668 // link_ssp spec is empty.
2670 // Let the tool chain choose which runtime library to link.
2671 getDarwinToolChain().AddLinkRuntimeLibArgs(Args
, CmdArgs
);
2674 if (!Args
.hasArg(options::OPT_A
) &&
2675 !Args
.hasArg(options::OPT_nostdlib
) &&
2676 !Args
.hasArg(options::OPT_nostartfiles
)) {
2677 // endfile_spec is empty.
2680 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2681 Args
.AddAllArgs(CmdArgs
, options::OPT_F
);
2684 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2685 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2688 void darwin::Lipo::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2689 const InputInfo
&Output
,
2690 const InputInfoList
&Inputs
,
2691 const ArgList
&Args
,
2692 const char *LinkingOutput
) const {
2693 ArgStringList CmdArgs
;
2695 CmdArgs
.push_back("-create");
2696 assert(Output
.isFilename() && "Unexpected lipo output.");
2698 CmdArgs
.push_back("-output");
2699 CmdArgs
.push_back(Output
.getFilename());
2701 for (InputInfoList::const_iterator
2702 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2703 const InputInfo
&II
= *it
;
2704 assert(II
.isFilename() && "Unexpected lipo input.");
2705 CmdArgs
.push_back(II
.getFilename());
2708 Args
.MakeArgString(getToolChain().GetProgramPath("lipo"));
2709 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2712 void darwin::Dsymutil::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2713 const InputInfo
&Output
,
2714 const InputInfoList
&Inputs
,
2715 const ArgList
&Args
,
2716 const char *LinkingOutput
) const {
2717 ArgStringList CmdArgs
;
2719 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
2720 const InputInfo
&Input
= Inputs
[0];
2721 assert(Input
.isFilename() && "Unexpected dsymutil input.");
2722 CmdArgs
.push_back(Input
.getFilename());
2724 CmdArgs
.push_back("-o");
2725 CmdArgs
.push_back(Output
.getFilename());
2728 Args
.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
2729 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2732 void auroraux::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2733 const InputInfo
&Output
,
2734 const InputInfoList
&Inputs
,
2735 const ArgList
&Args
,
2736 const char *LinkingOutput
) const {
2737 ArgStringList CmdArgs
;
2739 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2740 options::OPT_Xassembler
);
2742 CmdArgs
.push_back("-o");
2743 CmdArgs
.push_back(Output
.getFilename());
2745 for (InputInfoList::const_iterator
2746 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2747 const InputInfo
&II
= *it
;
2748 CmdArgs
.push_back(II
.getFilename());
2752 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
2753 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2756 void auroraux::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2757 const InputInfo
&Output
,
2758 const InputInfoList
&Inputs
,
2759 const ArgList
&Args
,
2760 const char *LinkingOutput
) const {
2761 ArgStringList CmdArgs
;
2763 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2764 (!Args
.hasArg(options::OPT_shared
))) {
2765 CmdArgs
.push_back("-e");
2766 CmdArgs
.push_back("_start");
2769 if (Args
.hasArg(options::OPT_static
)) {
2770 CmdArgs
.push_back("-Bstatic");
2771 CmdArgs
.push_back("-dn");
2773 // CmdArgs.push_back("--eh-frame-hdr");
2774 CmdArgs
.push_back("-Bdynamic");
2775 if (Args
.hasArg(options::OPT_shared
)) {
2776 CmdArgs
.push_back("-shared");
2778 CmdArgs
.push_back("--dynamic-linker");
2779 CmdArgs
.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
2783 if (Output
.isFilename()) {
2784 CmdArgs
.push_back("-o");
2785 CmdArgs
.push_back(Output
.getFilename());
2787 assert(Output
.isNothing() && "Invalid output.");
2790 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2791 !Args
.hasArg(options::OPT_nostartfiles
)) {
2792 if (!Args
.hasArg(options::OPT_shared
)) {
2793 CmdArgs
.push_back(Args
.MakeArgString(
2794 getToolChain().GetFilePath("crt1.o")));
2795 CmdArgs
.push_back(Args
.MakeArgString(
2796 getToolChain().GetFilePath("crti.o")));
2797 CmdArgs
.push_back(Args
.MakeArgString(
2798 getToolChain().GetFilePath("crtbegin.o")));
2800 CmdArgs
.push_back(Args
.MakeArgString(
2801 getToolChain().GetFilePath("crti.o")));
2803 CmdArgs
.push_back(Args
.MakeArgString(
2804 getToolChain().GetFilePath("crtn.o")));
2807 CmdArgs
.push_back(Args
.MakeArgString("-L/opt/gcc4/lib/gcc/"
2808 + getToolChain().getTripleString()
2811 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2812 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2813 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2815 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2817 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2818 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2819 // FIXME: For some reason GCC passes -lgcc before adding
2820 // the default system libraries. Just mimic this for now.
2821 CmdArgs
.push_back("-lgcc");
2823 if (Args
.hasArg(options::OPT_pthread
))
2824 CmdArgs
.push_back("-pthread");
2825 if (!Args
.hasArg(options::OPT_shared
))
2826 CmdArgs
.push_back("-lc");
2827 CmdArgs
.push_back("-lgcc");
2830 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2831 !Args
.hasArg(options::OPT_nostartfiles
)) {
2832 if (!Args
.hasArg(options::OPT_shared
))
2833 CmdArgs
.push_back(Args
.MakeArgString(
2834 getToolChain().GetFilePath("crtend.o")));
2838 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2839 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2842 void openbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2843 const InputInfo
&Output
,
2844 const InputInfoList
&Inputs
,
2845 const ArgList
&Args
,
2846 const char *LinkingOutput
) const {
2847 ArgStringList CmdArgs
;
2849 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2850 options::OPT_Xassembler
);
2852 CmdArgs
.push_back("-o");
2853 CmdArgs
.push_back(Output
.getFilename());
2855 for (InputInfoList::const_iterator
2856 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2857 const InputInfo
&II
= *it
;
2858 CmdArgs
.push_back(II
.getFilename());
2862 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2863 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2866 void openbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2867 const InputInfo
&Output
,
2868 const InputInfoList
&Inputs
,
2869 const ArgList
&Args
,
2870 const char *LinkingOutput
) const {
2871 const Driver
&D
= getToolChain().getDriver();
2872 ArgStringList CmdArgs
;
2874 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2875 (!Args
.hasArg(options::OPT_shared
))) {
2876 CmdArgs
.push_back("-e");
2877 CmdArgs
.push_back("__start");
2880 if (Args
.hasArg(options::OPT_static
)) {
2881 CmdArgs
.push_back("-Bstatic");
2883 CmdArgs
.push_back("--eh-frame-hdr");
2884 CmdArgs
.push_back("-Bdynamic");
2885 if (Args
.hasArg(options::OPT_shared
)) {
2886 CmdArgs
.push_back("-shared");
2888 CmdArgs
.push_back("-dynamic-linker");
2889 CmdArgs
.push_back("/usr/libexec/ld.so");
2893 if (Output
.isFilename()) {
2894 CmdArgs
.push_back("-o");
2895 CmdArgs
.push_back(Output
.getFilename());
2897 assert(Output
.isNothing() && "Invalid output.");
2900 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2901 !Args
.hasArg(options::OPT_nostartfiles
)) {
2902 if (!Args
.hasArg(options::OPT_shared
)) {
2903 CmdArgs
.push_back(Args
.MakeArgString(
2904 getToolChain().GetFilePath("crt0.o")));
2905 CmdArgs
.push_back(Args
.MakeArgString(
2906 getToolChain().GetFilePath("crtbegin.o")));
2908 CmdArgs
.push_back(Args
.MakeArgString(
2909 getToolChain().GetFilePath("crtbeginS.o")));
2913 std::string Triple
= getToolChain().getTripleString();
2914 if (Triple
.substr(0, 6) == "x86_64")
2915 Triple
.replace(0, 6, "amd64");
2916 CmdArgs
.push_back(Args
.MakeArgString("-L/usr/lib/gcc-lib/" + Triple
+
2919 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2920 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2921 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2923 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2925 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2926 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2928 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2929 CmdArgs
.push_back("-lm");
2932 // FIXME: For some reason GCC passes -lgcc before adding
2933 // the default system libraries. Just mimic this for now.
2934 CmdArgs
.push_back("-lgcc");
2936 if (Args
.hasArg(options::OPT_pthread
))
2937 CmdArgs
.push_back("-pthread");
2938 if (!Args
.hasArg(options::OPT_shared
))
2939 CmdArgs
.push_back("-lc");
2940 CmdArgs
.push_back("-lgcc");
2943 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2944 !Args
.hasArg(options::OPT_nostartfiles
)) {
2945 if (!Args
.hasArg(options::OPT_shared
))
2946 CmdArgs
.push_back(Args
.MakeArgString(
2947 getToolChain().GetFilePath("crtend.o")));
2949 CmdArgs
.push_back(Args
.MakeArgString(
2950 getToolChain().GetFilePath("crtendS.o")));
2954 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2955 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2958 void freebsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2959 const InputInfo
&Output
,
2960 const InputInfoList
&Inputs
,
2961 const ArgList
&Args
,
2962 const char *LinkingOutput
) const {
2963 ArgStringList CmdArgs
;
2965 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
2966 // instruct as in the base system to assemble 32-bit code.
2967 if (getToolChain().getArchName() == "i386")
2968 CmdArgs
.push_back("--32");
2971 // Set byte order explicitly
2972 if (getToolChain().getArchName() == "mips")
2973 CmdArgs
.push_back("-EB");
2974 else if (getToolChain().getArchName() == "mipsel")
2975 CmdArgs
.push_back("-EL");
2977 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2978 options::OPT_Xassembler
);
2980 CmdArgs
.push_back("-o");
2981 CmdArgs
.push_back(Output
.getFilename());
2983 for (InputInfoList::const_iterator
2984 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2985 const InputInfo
&II
= *it
;
2986 CmdArgs
.push_back(II
.getFilename());
2990 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2991 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2994 void freebsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2995 const InputInfo
&Output
,
2996 const InputInfoList
&Inputs
,
2997 const ArgList
&Args
,
2998 const char *LinkingOutput
) const {
2999 const Driver
&D
= getToolChain().getDriver();
3000 ArgStringList CmdArgs
;
3002 if (Args
.hasArg(options::OPT_static
)) {
3003 CmdArgs
.push_back("-Bstatic");
3005 CmdArgs
.push_back("--eh-frame-hdr");
3006 if (Args
.hasArg(options::OPT_shared
)) {
3007 CmdArgs
.push_back("-Bshareable");
3009 CmdArgs
.push_back("-dynamic-linker");
3010 CmdArgs
.push_back("/libexec/ld-elf.so.1");
3014 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3015 // instruct ld in the base system to link 32-bit code.
3016 if (getToolChain().getArchName() == "i386") {
3017 CmdArgs
.push_back("-m");
3018 CmdArgs
.push_back("elf_i386_fbsd");
3021 if (Output
.isFilename()) {
3022 CmdArgs
.push_back("-o");
3023 CmdArgs
.push_back(Output
.getFilename());
3025 assert(Output
.isNothing() && "Invalid output.");
3028 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3029 !Args
.hasArg(options::OPT_nostartfiles
)) {
3030 if (!Args
.hasArg(options::OPT_shared
)) {
3031 CmdArgs
.push_back(Args
.MakeArgString(
3032 getToolChain().GetFilePath("crt1.o")));
3033 CmdArgs
.push_back(Args
.MakeArgString(
3034 getToolChain().GetFilePath("crti.o")));
3035 CmdArgs
.push_back(Args
.MakeArgString(
3036 getToolChain().GetFilePath("crtbegin.o")));
3038 CmdArgs
.push_back(Args
.MakeArgString(
3039 getToolChain().GetFilePath("crti.o")));
3040 CmdArgs
.push_back(Args
.MakeArgString(
3041 getToolChain().GetFilePath("crtbeginS.o")));
3045 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3046 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3047 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3048 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3049 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3050 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3051 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3053 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3055 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3056 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3058 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3059 CmdArgs
.push_back("-lm");
3061 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3062 // the default system libraries. Just mimic this for now.
3063 CmdArgs
.push_back("-lgcc");
3064 if (Args
.hasArg(options::OPT_static
)) {
3065 CmdArgs
.push_back("-lgcc_eh");
3067 CmdArgs
.push_back("--as-needed");
3068 CmdArgs
.push_back("-lgcc_s");
3069 CmdArgs
.push_back("--no-as-needed");
3072 if (Args
.hasArg(options::OPT_pthread
))
3073 CmdArgs
.push_back("-lpthread");
3074 CmdArgs
.push_back("-lc");
3076 CmdArgs
.push_back("-lgcc");
3077 if (Args
.hasArg(options::OPT_static
)) {
3078 CmdArgs
.push_back("-lgcc_eh");
3080 CmdArgs
.push_back("--as-needed");
3081 CmdArgs
.push_back("-lgcc_s");
3082 CmdArgs
.push_back("--no-as-needed");
3086 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3087 !Args
.hasArg(options::OPT_nostartfiles
)) {
3088 if (!Args
.hasArg(options::OPT_shared
))
3089 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3092 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3094 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3099 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3100 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3103 void linuxtools::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3104 const InputInfo
&Output
,
3105 const InputInfoList
&Inputs
,
3106 const ArgList
&Args
,
3107 const char *LinkingOutput
) const {
3108 ArgStringList CmdArgs
;
3110 // Add --32/--64 to make sure we get the format we want.
3111 // This is incomplete
3112 if (getToolChain().getArch() == llvm::Triple::x86
) {
3113 CmdArgs
.push_back("--32");
3114 } else if (getToolChain().getArch() == llvm::Triple::x86_64
) {
3115 CmdArgs
.push_back("--64");
3116 } else if (getToolChain().getArch() == llvm::Triple::arm
) {
3117 llvm::StringRef MArch
= getToolChain().getArchName();
3118 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
3119 CmdArgs
.push_back("-mfpu=neon");
3122 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3123 options::OPT_Xassembler
);
3125 CmdArgs
.push_back("-o");
3126 CmdArgs
.push_back(Output
.getFilename());
3128 for (InputInfoList::const_iterator
3129 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3130 const InputInfo
&II
= *it
;
3131 CmdArgs
.push_back(II
.getFilename());
3135 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3136 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3140 void minix::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3141 const InputInfo
&Output
,
3142 const InputInfoList
&Inputs
,
3143 const ArgList
&Args
,
3144 const char *LinkingOutput
) const {
3145 ArgStringList CmdArgs
;
3147 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3148 options::OPT_Xassembler
);
3150 CmdArgs
.push_back("-o");
3151 CmdArgs
.push_back(Output
.getFilename());
3153 for (InputInfoList::const_iterator
3154 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3155 const InputInfo
&II
= *it
;
3156 CmdArgs
.push_back(II
.getFilename());
3160 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
3161 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3164 void minix::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3165 const InputInfo
&Output
,
3166 const InputInfoList
&Inputs
,
3167 const ArgList
&Args
,
3168 const char *LinkingOutput
) const {
3169 const Driver
&D
= getToolChain().getDriver();
3170 ArgStringList CmdArgs
;
3172 if (Output
.isFilename()) {
3173 CmdArgs
.push_back("-o");
3174 CmdArgs
.push_back(Output
.getFilename());
3176 assert(Output
.isNothing() && "Invalid output.");
3179 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3180 !Args
.hasArg(options::OPT_nostartfiles
))
3181 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3182 "/usr/gnu/lib/crtso.o")));
3184 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3185 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3186 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3188 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3190 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3191 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3193 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3194 CmdArgs
.push_back("-lm");
3197 if (Args
.hasArg(options::OPT_pthread
))
3198 CmdArgs
.push_back("-lpthread");
3199 CmdArgs
.push_back("-lc");
3200 CmdArgs
.push_back("-lgcc");
3201 CmdArgs
.push_back("-L/usr/gnu/lib");
3202 // FIXME: fill in the correct search path for the final
3203 // support libraries.
3204 CmdArgs
.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
3207 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3208 !Args
.hasArg(options::OPT_nostartfiles
)) {
3209 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3210 "/usr/gnu/lib/libend.a")));
3214 Args
.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
3215 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3220 // For now, DragonFly Assemble does just about the same as for
3221 // FreeBSD, but this may change soon.
3222 void dragonfly::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3223 const InputInfo
&Output
,
3224 const InputInfoList
&Inputs
,
3225 const ArgList
&Args
,
3226 const char *LinkingOutput
) const {
3227 ArgStringList CmdArgs
;
3229 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3230 // instruct as in the base system to assemble 32-bit code.
3231 if (getToolChain().getArchName() == "i386")
3232 CmdArgs
.push_back("--32");
3234 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3235 options::OPT_Xassembler
);
3237 CmdArgs
.push_back("-o");
3238 CmdArgs
.push_back(Output
.getFilename());
3240 for (InputInfoList::const_iterator
3241 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3242 const InputInfo
&II
= *it
;
3243 CmdArgs
.push_back(II
.getFilename());
3247 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3248 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3251 void dragonfly::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3252 const InputInfo
&Output
,
3253 const InputInfoList
&Inputs
,
3254 const ArgList
&Args
,
3255 const char *LinkingOutput
) const {
3256 const Driver
&D
= getToolChain().getDriver();
3257 ArgStringList CmdArgs
;
3259 if (Args
.hasArg(options::OPT_static
)) {
3260 CmdArgs
.push_back("-Bstatic");
3262 if (Args
.hasArg(options::OPT_shared
))
3263 CmdArgs
.push_back("-Bshareable");
3265 CmdArgs
.push_back("-dynamic-linker");
3266 CmdArgs
.push_back("/usr/libexec/ld-elf.so.2");
3270 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3271 // instruct ld in the base system to link 32-bit code.
3272 if (getToolChain().getArchName() == "i386") {
3273 CmdArgs
.push_back("-m");
3274 CmdArgs
.push_back("elf_i386");
3277 if (Output
.isFilename()) {
3278 CmdArgs
.push_back("-o");
3279 CmdArgs
.push_back(Output
.getFilename());
3281 assert(Output
.isNothing() && "Invalid output.");
3284 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3285 !Args
.hasArg(options::OPT_nostartfiles
)) {
3286 if (!Args
.hasArg(options::OPT_shared
)) {
3288 Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
3290 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3292 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
3295 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3297 Args
.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
3301 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3302 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3303 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3305 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3307 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3308 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3309 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
3311 CmdArgs
.push_back("-L/usr/lib/gcc41");
3313 if (!Args
.hasArg(options::OPT_static
)) {
3314 CmdArgs
.push_back("-rpath");
3315 CmdArgs
.push_back("/usr/lib/gcc41");
3317 CmdArgs
.push_back("-rpath-link");
3318 CmdArgs
.push_back("/usr/lib/gcc41");
3320 CmdArgs
.push_back("-rpath");
3321 CmdArgs
.push_back("/usr/lib");
3323 CmdArgs
.push_back("-rpath-link");
3324 CmdArgs
.push_back("/usr/lib");
3328 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3329 CmdArgs
.push_back("-lm");
3332 if (Args
.hasArg(options::OPT_shared
)) {
3333 CmdArgs
.push_back("-lgcc_pic");
3335 CmdArgs
.push_back("-lgcc");
3339 if (Args
.hasArg(options::OPT_pthread
))
3340 CmdArgs
.push_back("-lpthread");
3342 if (!Args
.hasArg(options::OPT_nolibc
)) {
3343 CmdArgs
.push_back("-lc");
3346 if (Args
.hasArg(options::OPT_shared
)) {
3347 CmdArgs
.push_back("-lgcc_pic");
3349 CmdArgs
.push_back("-lgcc");
3353 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3354 !Args
.hasArg(options::OPT_nostartfiles
)) {
3355 if (!Args
.hasArg(options::OPT_shared
))
3356 CmdArgs
.push_back(Args
.MakeArgString(
3357 getToolChain().GetFilePath("crtend.o")));
3359 CmdArgs
.push_back(Args
.MakeArgString(
3360 getToolChain().GetFilePath("crtendS.o")));
3361 CmdArgs
.push_back(Args
.MakeArgString(
3362 getToolChain().GetFilePath("crtn.o")));
3366 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3367 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3370 void visualstudio::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3371 const InputInfo
&Output
,
3372 const InputInfoList
&Inputs
,
3373 const ArgList
&Args
,
3374 const char *LinkingOutput
) const {
3375 ArgStringList CmdArgs
;
3377 if (Output
.isFilename()) {
3378 CmdArgs
.push_back(Args
.MakeArgString(std::string("-out:") +
3379 Output
.getFilename()));
3381 assert(Output
.isNothing() && "Invalid output.");
3384 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3385 !Args
.hasArg(options::OPT_nostartfiles
)) {
3386 CmdArgs
.push_back("-defaultlib:libcmt");
3389 CmdArgs
.push_back("-nologo");
3391 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3394 Args
.MakeArgString(getToolChain().GetProgramPath("link.exe"));
3395 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));